Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

v1.16: spl: Bump token-2022 and friends (backport of #33453) #33465

Merged
merged 5 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
346 changes: 258 additions & 88 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,13 @@ solana-vote-program = { path = "programs/vote", version = "=1.16.16" }
solana-zk-keygen = { path = "zk-keygen", version = "=1.16.16" }
solana-zk-token-proof-program = { path = "programs/zk-token-proof", version = "=1.16.16" }
solana-zk-token-sdk = { path = "zk-token-sdk", version = "=1.16.16" }
spl-associated-token-account = "=1.1.3"
spl-associated-token-account = "=2.2.0"
spl-instruction-padding = "0.1"
spl-memo = "=3.0.1"
spl-token = "=3.5.0"
spl-token-2022 = "=0.6.1"
spl-memo = "=4.0.0"
spl-pod = "=0.1.0"
spl-token = "=4.0.0"
spl-token-2022 = "=0.9.0"
spl-token-metadata-interface = "=0.2.0"
static_assertions = "1.1.0"
stream-cancel = "0.8.1"
strum = "0.24"
Expand Down Expand Up @@ -413,8 +415,10 @@ ntapi = { git = "https://github.com/solana-labs/ntapi", rev = "97ede981a1777883f
# * spl-associated-token-account
# * spl-instruction-padding
# * spl-memo
# * spl-pod
# * spl-token
# * spl-token-2022
# * spl-token-metadata-interface
#
# They, in turn, depend on a number of crates that we also include directly using `path`
# specifications. For example, `spl-token` depends on `solana-program`. And we explicitly specify
Expand Down
4 changes: 4 additions & 0 deletions account-decoder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ solana-config-program = { workspace = true }
solana-sdk = { workspace = true }
spl-token = { workspace = true, features = ["no-entrypoint"] }
spl-token-2022 = { workspace = true, features = ["no-entrypoint"] }
spl-token-metadata-interface = { workspace = true }
thiserror = { workspace = true }
zstd = { workspace = true }

[dev-dependencies]
spl-pod = { workspace = true }

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
18 changes: 9 additions & 9 deletions account-decoder/src/parse_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,10 @@ mod test {
use {
super::*,
crate::parse_token_extension::{UiMemoTransfer, UiMintCloseAuthority},
spl_token_2022::{
extension::{
immutable_owner::ImmutableOwner, memo_transfer::MemoTransfer,
mint_close_authority::MintCloseAuthority, ExtensionType, StateWithExtensionsMut,
},
pod::OptionalNonZeroPubkey,
spl_pod::optional_keys::OptionalNonZeroPubkey,
spl_token_2022::extension::{
immutable_owner::ImmutableOwner, memo_transfer::MemoTransfer,
mint_close_authority::MintCloseAuthority, ExtensionType, StateWithExtensionsMut,
},
};

Expand Down Expand Up @@ -506,10 +504,11 @@ mod test {
delegate: COption::None,
delegated_amount: 0,
};
let account_size = ExtensionType::get_account_len::<Account>(&[
let account_size = ExtensionType::try_calculate_account_len::<Account>(&[
ExtensionType::ImmutableOwner,
ExtensionType::MemoTransfer,
]);
])
.unwrap();
let mut account_data = vec![0; account_size];
let mut account_state =
StateWithExtensionsMut::<Account>::unpack_uninitialized(&mut account_data).unwrap();
Expand Down Expand Up @@ -586,7 +585,8 @@ mod test {
fn test_parse_token_mint_with_extensions() {
let owner_pubkey = SplTokenPubkey::new_from_array([3; 32]);
let mint_size =
ExtensionType::get_account_len::<Mint>(&[ExtensionType::MintCloseAuthority]);
ExtensionType::try_calculate_account_len::<Mint>(&[ExtensionType::MintCloseAuthority])
.unwrap();
let mint_base = Mint {
mint_authority: COption::Some(owner_pubkey),
supply: 42,
Expand Down
183 changes: 164 additions & 19 deletions account-decoder/src/parse_token_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use {
solana_program::pubkey::Pubkey,
solana_zk_token_sdk::zk_token_elgamal::pod::ElGamalPubkey,
},
spl_token_metadata_interface::state::TokenMetadata,
};

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
Expand All @@ -24,15 +25,21 @@ pub enum UiExtension {
InterestBearingConfig(UiInterestBearingConfig),
CpiGuard(UiCpiGuard),
PermanentDelegate(UiPermanentDelegate),
UnparseableExtension,
NonTransferableAccount,
ConfidentialTransferFeeConfig(UiConfidentialTransferFeeConfig),
ConfidentialTransferFeeAmount(UiConfidentialTransferFeeAmount),
TransferHook(UiTransferHook),
TransferHookAccount(UiTransferHookAccount),
MetadataPointer(UiMetadataPointer),
TokenMetadata(UiTokenMetadata),
UnparseableExtension,
}

pub fn parse_extension<S: BaseState>(
extension_type: &ExtensionType,
account: &StateWithExtensions<S>,
) -> UiExtension {
match &extension_type {
match extension_type {
ExtensionType::Uninitialized => UiExtension::Uninitialized,
ExtensionType::TransferFeeConfig => account
.get_extension::<extension::transfer_fee::TransferFeeConfig>()
Expand All @@ -50,10 +57,18 @@ pub fn parse_extension<S: BaseState>(
.get_extension::<extension::confidential_transfer::ConfidentialTransferMint>()
.map(|&extension| UiExtension::ConfidentialTransferMint(extension.into()))
.unwrap_or(UiExtension::UnparseableExtension),
ExtensionType::ConfidentialTransferFeeConfig => account
.get_extension::<extension::confidential_transfer_fee::ConfidentialTransferFeeConfig>()
.map(|&extension| UiExtension::ConfidentialTransferFeeConfig(extension.into()))
.unwrap_or(UiExtension::UnparseableExtension),
ExtensionType::ConfidentialTransferAccount => account
.get_extension::<extension::confidential_transfer::ConfidentialTransferAccount>()
.map(|&extension| UiExtension::ConfidentialTransferAccount(extension.into()))
.unwrap_or(UiExtension::UnparseableExtension),
ExtensionType::ConfidentialTransferFeeAmount => account
.get_extension::<extension::confidential_transfer_fee::ConfidentialTransferFeeAmount>()
.map(|&extension| UiExtension::ConfidentialTransferFeeAmount(extension.into()))
.unwrap_or(UiExtension::UnparseableExtension),
ExtensionType::DefaultAccountState => account
.get_extension::<extension::default_account_state::DefaultAccountState>()
.map(|&extension| UiExtension::DefaultAccountState(extension.into()))
Expand All @@ -77,6 +92,22 @@ pub fn parse_extension<S: BaseState>(
.map(|&extension| UiExtension::PermanentDelegate(extension.into()))
.unwrap_or(UiExtension::UnparseableExtension),
ExtensionType::NonTransferableAccount => UiExtension::NonTransferableAccount,
ExtensionType::MetadataPointer => account
.get_extension::<extension::metadata_pointer::MetadataPointer>()
.map(|&extension| UiExtension::MetadataPointer(extension.into()))
.unwrap_or(UiExtension::UnparseableExtension),
ExtensionType::TokenMetadata => account
.get_variable_len_extension::<TokenMetadata>()
.map(|extension| UiExtension::TokenMetadata(extension.into()))
.unwrap_or(UiExtension::UnparseableExtension),
ExtensionType::TransferHook => account
.get_extension::<extension::transfer_hook::TransferHook>()
.map(|&extension| UiExtension::TransferHook(extension.into()))
.unwrap_or(UiExtension::UnparseableExtension),
ExtensionType::TransferHookAccount => account
.get_extension::<extension::transfer_hook::TransferHookAccount>()
.map(|&extension| UiExtension::TransferHookAccount(extension.into()))
.unwrap_or(UiExtension::UnparseableExtension),
}
}

Expand Down Expand Up @@ -251,9 +282,7 @@ impl From<extension::permanent_delegate::PermanentDelegate> for UiPermanentDeleg
pub struct UiConfidentialTransferMint {
pub authority: Option<String>,
pub auto_approve_new_accounts: bool,
pub auditor_encryption_pubkey: Option<String>,
pub withdraw_withheld_authority_encryption_pubkey: Option<String>,
pub withheld_amount: String,
pub auditor_elgamal_pubkey: Option<String>,
}

impl From<extension::confidential_transfer::ConfidentialTransferMint>
Expand All @@ -263,19 +292,44 @@ impl From<extension::confidential_transfer::ConfidentialTransferMint>
confidential_transfer_mint: extension::confidential_transfer::ConfidentialTransferMint,
) -> Self {
let authority: Option<Pubkey> = confidential_transfer_mint.authority.into();
let auditor_encryption_pubkey: Option<ElGamalPubkey> =
confidential_transfer_mint.auditor_encryption_pubkey.into();
let withdraw_withheld_authority_encryption_pubkey: Option<ElGamalPubkey> =
confidential_transfer_mint
.withdraw_withheld_authority_encryption_pubkey
.into();
let auditor_elgamal_pubkey: Option<ElGamalPubkey> =
confidential_transfer_mint.auditor_elgamal_pubkey.into();
Self {
authority: authority.map(|pubkey| pubkey.to_string()),
auto_approve_new_accounts: confidential_transfer_mint.auto_approve_new_accounts.into(),
auditor_encryption_pubkey: auditor_encryption_pubkey.map(|pubkey| pubkey.to_string()),
withdraw_withheld_authority_encryption_pubkey:
withdraw_withheld_authority_encryption_pubkey.map(|pubkey| pubkey.to_string()),
withheld_amount: format!("{}", confidential_transfer_mint.withheld_amount),
auditor_elgamal_pubkey: auditor_elgamal_pubkey.map(|pubkey| pubkey.to_string()),
}
}
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct UiConfidentialTransferFeeConfig {
pub authority: Option<String>,
pub withdraw_withheld_authority_elgamal_pubkey: Option<String>,
pub harvest_to_mint_enabled: bool,
pub withheld_amount: String,
}

impl From<extension::confidential_transfer_fee::ConfidentialTransferFeeConfig>
for UiConfidentialTransferFeeConfig
{
fn from(
confidential_transfer_fee_config: extension::confidential_transfer_fee::ConfidentialTransferFeeConfig,
) -> Self {
let authority: Option<Pubkey> = confidential_transfer_fee_config.authority.into();
let withdraw_withheld_authority_elgamal_pubkey: Option<ElGamalPubkey> =
confidential_transfer_fee_config
.withdraw_withheld_authority_elgamal_pubkey
.into();
Self {
authority: authority.map(|pubkey| pubkey.to_string()),
withdraw_withheld_authority_elgamal_pubkey: withdraw_withheld_authority_elgamal_pubkey
.map(|pubkey| pubkey.to_string()),
harvest_to_mint_enabled: confidential_transfer_fee_config
.harvest_to_mint_enabled
.into(),
withheld_amount: format!("{}", confidential_transfer_fee_config.withheld_amount),
}
}
}
Expand All @@ -284,7 +338,7 @@ impl From<extension::confidential_transfer::ConfidentialTransferMint>
#[serde(rename_all = "camelCase")]
pub struct UiConfidentialTransferAccount {
pub approved: bool,
pub encryption_pubkey: String,
pub elgamal_pubkey: String,
pub pending_balance_lo: String,
pub pending_balance_hi: String,
pub available_balance: String,
Expand All @@ -295,7 +349,6 @@ pub struct UiConfidentialTransferAccount {
pub maximum_pending_balance_credit_counter: u64,
pub expected_pending_balance_credit_counter: u64,
pub actual_pending_balance_credit_counter: u64,
pub withheld_amount: String,
}

impl From<extension::confidential_transfer::ConfidentialTransferAccount>
Expand All @@ -306,7 +359,7 @@ impl From<extension::confidential_transfer::ConfidentialTransferAccount>
) -> Self {
Self {
approved: confidential_transfer_account.approved.into(),
encryption_pubkey: format!("{}", confidential_transfer_account.encryption_pubkey),
elgamal_pubkey: format!("{}", confidential_transfer_account.elgamal_pubkey),
pending_balance_lo: format!("{}", confidential_transfer_account.pending_balance_lo),
pending_balance_hi: format!("{}", confidential_transfer_account.pending_balance_hi),
available_balance: format!("{}", confidential_transfer_account.available_balance),
Expand All @@ -332,7 +385,99 @@ impl From<extension::confidential_transfer::ConfidentialTransferAccount>
actual_pending_balance_credit_counter: confidential_transfer_account
.actual_pending_balance_credit_counter
.into(),
withheld_amount: format!("{}", confidential_transfer_account.withheld_amount),
}
}
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct UiConfidentialTransferFeeAmount {
pub withheld_amount: String,
}

impl From<extension::confidential_transfer_fee::ConfidentialTransferFeeAmount>
for UiConfidentialTransferFeeAmount
{
fn from(
confidential_transfer_fee_amount: extension::confidential_transfer_fee::ConfidentialTransferFeeAmount,
) -> Self {
Self {
withheld_amount: format!("{}", confidential_transfer_fee_amount.withheld_amount),
}
}
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct UiMetadataPointer {
pub authority: Option<String>,
pub metadata_address: Option<String>,
}

impl From<extension::metadata_pointer::MetadataPointer> for UiMetadataPointer {
fn from(metadata_pointer: extension::metadata_pointer::MetadataPointer) -> Self {
let authority: Option<Pubkey> = metadata_pointer.authority.into();
let metadata_address: Option<Pubkey> = metadata_pointer.metadata_address.into();
Self {
authority: authority.map(|pubkey| pubkey.to_string()),
metadata_address: metadata_address.map(|pubkey| pubkey.to_string()),
}
}
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct UiTokenMetadata {
pub update_authority: Option<String>,
pub mint: String,
pub name: String,
pub symbol: String,
pub uri: String,
pub additional_metadata: Vec<(String, String)>,
}

impl From<TokenMetadata> for UiTokenMetadata {
fn from(token_metadata: TokenMetadata) -> Self {
let update_authority: Option<Pubkey> = token_metadata.update_authority.into();
Self {
update_authority: update_authority.map(|pubkey| pubkey.to_string()),
mint: token_metadata.mint.to_string(),
name: token_metadata.name,
symbol: token_metadata.symbol,
uri: token_metadata.uri,
additional_metadata: token_metadata.additional_metadata,
}
}
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct UiTransferHook {
pub authority: Option<String>,
pub program_id: Option<String>,
}

impl From<extension::transfer_hook::TransferHook> for UiTransferHook {
fn from(transfer_hook: extension::transfer_hook::TransferHook) -> Self {
let authority: Option<Pubkey> = transfer_hook.authority.into();
let program_id: Option<Pubkey> = transfer_hook.program_id.into();
Self {
authority: authority.map(|pubkey| pubkey.to_string()),
program_id: program_id.map(|pubkey| pubkey.to_string()),
}
}
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct UiTransferHookAccount {
pub transferring: bool,
}

impl From<extension::transfer_hook::TransferHookAccount> for UiTransferHookAccount {
fn from(transfer_hook: extension::transfer_hook::TransferHookAccount) -> Self {
Self {
transferring: transfer_hook.transferring.into(),
}
}
}
2 changes: 1 addition & 1 deletion fetch-spl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fetch_program() {
}

fetch_program token 3.5.0 TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA BPFLoader2111111111111111111111111111111111
fetch_program token-2022 0.6.0 TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb BPFLoaderUpgradeab1e11111111111111111111111
fetch_program token-2022 0.9.0 TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb BPFLoaderUpgradeab1e11111111111111111111111
fetch_program memo 1.0.0 Memo1UhkJRfHyvLMcVucJwxXeuD728EqVDDwQDxFMNo BPFLoader1111111111111111111111111111111111
fetch_program memo 3.0.0 MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr BPFLoader2111111111111111111111111111111111
fetch_program associated-token-account 1.1.2 ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL BPFLoader2111111111111111111111111111111111
Expand Down
1 change: 1 addition & 0 deletions ledger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ bs58 = { workspace = true }
matches = { workspace = true }
solana-account-decoder = { workspace = true }
solana-logger = { workspace = true }
spl-pod = { workspace = true }
test-case = { workspace = true }

[build-dependencies]
Expand Down
Loading