Add SPL Token 2022 to the list of known token ids (#23067)
* Add SPL Token 2022 to the list of known token ids * Fix tests to accommodate #23729 * Test parsing of basic token-2022 instructsions Co-authored-by: Tyera Eulberg <tyera@solana.com>
This commit is contained in:
parent
255a6a729d
commit
413806684f
File diff suppressed because it is too large
Load Diff
|
@ -23,6 +23,7 @@ solana-config-program = { path = "../programs/config", version = "=1.11.0" }
|
||||||
solana-sdk = { path = "../sdk", version = "=1.11.0" }
|
solana-sdk = { path = "../sdk", version = "=1.11.0" }
|
||||||
solana-vote-program = { path = "../programs/vote", version = "=1.11.0" }
|
solana-vote-program = { path = "../programs/vote", version = "=1.11.0" }
|
||||||
spl-token = { version = "=3.2.0", features = ["no-entrypoint"] }
|
spl-token = { version = "=3.2.0", features = ["no-entrypoint"] }
|
||||||
|
spl-token-2022 = { version = "=0.1.0", features = ["no-entrypoint"] }
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
zstd = "0.11.1"
|
zstd = "0.11.1"
|
||||||
|
|
||||||
|
|
|
@ -19,14 +19,20 @@ fn spl_token_id() -> Pubkey {
|
||||||
Pubkey::new_from_array(spl_token::id().to_bytes())
|
Pubkey::new_from_array(spl_token::id().to_bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A helper function to convert spl_token_2022::id() as spl_sdk::pubkey::Pubkey to
|
||||||
|
// solana_sdk::pubkey::Pubkey
|
||||||
|
fn spl_token_2022_id() -> Pubkey {
|
||||||
|
Pubkey::new_from_array(spl_token_2022::id().to_bytes())
|
||||||
|
}
|
||||||
|
|
||||||
// Returns all known SPL Token program ids
|
// Returns all known SPL Token program ids
|
||||||
pub fn spl_token_ids() -> Vec<Pubkey> {
|
pub fn spl_token_ids() -> Vec<Pubkey> {
|
||||||
vec![spl_token_id()]
|
vec![spl_token_id(), spl_token_2022_id()]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the provided program id as a known SPL Token program id
|
// Check if the provided program id as a known SPL Token program id
|
||||||
pub fn is_known_spl_token_id(program_id: &Pubkey) -> bool {
|
pub fn is_known_spl_token_id(program_id: &Pubkey) -> bool {
|
||||||
*program_id == spl_token_id()
|
*program_id == spl_token_id() || *program_id == spl_token_2022_id()
|
||||||
}
|
}
|
||||||
|
|
||||||
// A helper function to convert spl_token::native_mint::id() as spl_sdk::pubkey::Pubkey to
|
// A helper function to convert spl_token::native_mint::id() as spl_sdk::pubkey::Pubkey to
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -28,6 +28,7 @@ solana-vote-program = { path = "../programs/vote", version = "=1.11.0" }
|
||||||
spl-associated-token-account = { version = "=1.0.3", features = ["no-entrypoint"] }
|
spl-associated-token-account = { version = "=1.0.3", features = ["no-entrypoint"] }
|
||||||
spl-memo = { version = "=3.0.1", features = ["no-entrypoint"] }
|
spl-memo = { version = "=3.0.1", features = ["no-entrypoint"] }
|
||||||
spl-token = { version = "=3.2.0", features = ["no-entrypoint"] }
|
spl-token = { version = "=3.2.0", features = ["no-entrypoint"] }
|
||||||
|
spl-token-2022 = { version = "=0.1.0", features = ["no-entrypoint"] }
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
|
|
|
@ -51,8 +51,9 @@ fn check_num_associated_token_accounts(
|
||||||
mod test {
|
mod test {
|
||||||
use {
|
use {
|
||||||
super::*,
|
super::*,
|
||||||
|
solana_account_decoder::parse_token::pubkey_from_spl_token,
|
||||||
spl_associated_token_account::{
|
spl_associated_token_account::{
|
||||||
create_associated_token_account,
|
create_associated_token_account, get_associated_token_address,
|
||||||
solana_program::{
|
solana_program::{
|
||||||
instruction::CompiledInstruction as SplAssociatedTokenCompiledInstruction,
|
instruction::CompiledInstruction as SplAssociatedTokenCompiledInstruction,
|
||||||
message::Message, pubkey::Pubkey as SplAssociatedTokenPubkey,
|
message::Message, pubkey::Pubkey as SplAssociatedTokenPubkey,
|
||||||
|
@ -74,33 +75,46 @@ mod test {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn convert_account_keys(message: &Message) -> Vec<Pubkey> {
|
||||||
|
message
|
||||||
|
.account_keys
|
||||||
|
.iter()
|
||||||
|
.map(pubkey_from_spl_token)
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_associated_token() {
|
fn test_parse_associated_token() {
|
||||||
let mut keys: Vec<Pubkey> = vec![];
|
let funder = Pubkey::new_unique();
|
||||||
for _ in 0..7 {
|
let wallet_address = Pubkey::new_unique();
|
||||||
keys.push(solana_sdk::pubkey::new_rand());
|
let mint = Pubkey::new_unique();
|
||||||
}
|
let associated_account_address =
|
||||||
|
get_associated_token_address(&convert_pubkey(wallet_address), &convert_pubkey(mint));
|
||||||
|
let rent_sysvar = solana_sdk::sysvar::rent::id();
|
||||||
|
|
||||||
let create_ix = create_associated_token_account(
|
let create_ix = create_associated_token_account(
|
||||||
&convert_pubkey(keys[0]),
|
&convert_pubkey(funder),
|
||||||
&convert_pubkey(keys[1]),
|
&convert_pubkey(wallet_address),
|
||||||
&convert_pubkey(keys[2]),
|
&convert_pubkey(mint),
|
||||||
);
|
);
|
||||||
let message = Message::new(&[create_ix], None);
|
let message = Message::new(&[create_ix], None);
|
||||||
let compiled_instruction = convert_compiled_instruction(&message.instructions[0]);
|
let compiled_instruction = convert_compiled_instruction(&message.instructions[0]);
|
||||||
let account_keys = AccountKeys::new(&keys, None);
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parse_associated_token(&compiled_instruction, &account_keys).unwrap(),
|
parse_associated_token(
|
||||||
|
&compiled_instruction,
|
||||||
|
&AccountKeys::new(&convert_account_keys(&message), None)
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
ParsedInstructionEnum {
|
ParsedInstructionEnum {
|
||||||
instruction_type: "create".to_string(),
|
instruction_type: "create".to_string(),
|
||||||
info: json!({
|
info: json!({
|
||||||
"source": keys[0].to_string(),
|
"source": funder.to_string(),
|
||||||
"account": keys[1].to_string(),
|
"account": associated_account_address.to_string(),
|
||||||
"wallet": keys[2].to_string(),
|
"wallet": wallet_address.to_string(),
|
||||||
"mint": keys[3].to_string(),
|
"mint": mint.to_string(),
|
||||||
"systemProgram": keys[4].to_string(),
|
"systemProgram": solana_sdk::system_program::id().to_string(),
|
||||||
"tokenProgram": keys[5].to_string(),
|
"tokenProgram": spl_token::id().to_string(),
|
||||||
"rentSysvar": keys[6].to_string(),
|
"rentSysvar": rent_sysvar.to_string(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue