-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add solana token 2022 support #3968
Changes from 2 commits
bc1e68f
82f8e67
b084e7a
014085e
b99e544
0343d23
b02486d
10beb99
6de1499
b5235fd
0d363af
44ce8fa
0e71704
3ce2733
83b6959
96fb730
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,18 +81,21 @@ impl CompiledKeys { | |
(meta.is_signer == is_signer && meta.is_writable == is_writable).then_some(*account) | ||
}; | ||
|
||
let writable_signer_keys: Vec<SolanaAddress> = ordered_keys | ||
let mut writable_signer_keys: Vec<SolanaAddress> = ordered_keys | ||
.iter() | ||
.filter_map(|key| filter(key, true, true)) | ||
.collect(); | ||
let readonly_signer_keys: Vec<SolanaAddress> = ordered_keys | ||
writable_signer_keys.sort(); | ||
let mut readonly_signer_keys: Vec<SolanaAddress> = ordered_keys | ||
.iter() | ||
.filter_map(|key| filter(key, true, false)) | ||
.collect(); | ||
let writable_non_signer_keys: Vec<SolanaAddress> = ordered_keys | ||
readonly_signer_keys.sort(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
let mut writable_non_signer_keys: Vec<SolanaAddress> = ordered_keys | ||
.iter() | ||
.filter_map(|key| filter(key, false, true)) | ||
.collect(); | ||
writable_non_signer_keys.sort(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
let readonly_non_signer_keys: Vec<SolanaAddress> = ordered_keys | ||
.iter() | ||
.filter_map(|key| filter(key, false, false)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -392,6 +392,7 @@ fn test_solana_sign_create_token_account() { | |
main_address: "B1iGmDJdvmxyUiYM8UEo2Uw2D58EmUrw4KyLYMmrhf8V".into(), | ||
token_mint_address: "SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt".into(), | ||
token_address: "EDNd1ycsydWYwVmrYZvqYazFqwk1QjBgAUKFjBoz1jKP".into(), | ||
is_token_2022: false | ||
}; | ||
let input = Proto::SigningInput { | ||
private_key: b58("9YtuoD4sH4h88CVM8DSnkfoAaLY7YeGC2TarDJ8eyMS5"), | ||
|
@@ -413,6 +414,7 @@ fn test_solana_sign_create_token_account_5ktpn1() { | |
main_address: "Eg5jqooyG6ySaXKbQUu4Lpvu2SqUPZrNkM4zXs9iUDLJ".into(), | ||
token_mint_address: "SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt".into(), | ||
token_address: "ANVCrmRw7Ww7rTFfMbrjApSPXEEcZpBa6YEiBdf98pAf".into(), | ||
is_token_2022: false | ||
}; | ||
let input = Proto::SigningInput { | ||
private_key: "4b9d6f57d28b06cbfa1d4cc710953e62d653caf853415c56ffd9d150acdeb7f7" | ||
|
@@ -438,6 +440,7 @@ fn test_solana_sign_create_token_account_for_other_3e6ufv() { | |
main_address: "3xJ3MoUVFPNFEHfWdtNFa8ajXUHsJPzXcBSWMKLd76ft".into(), | ||
token_mint_address: "SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt".into(), | ||
token_address: "67BrwFYt7qUnbAcYBVx7sQ4jeD2KWN1ohP6bMikmmQV3".into(), | ||
is_token_2022: false | ||
}; | ||
let input = Proto::SigningInput { | ||
private_key: "4b9d6f57d28b06cbfa1d4cc710953e62d653caf853415c56ffd9d150acdeb7f7" | ||
|
@@ -469,6 +472,7 @@ fn test_solana_sign_create_token_account_with_priority_fee_price() { | |
// WBTC | ||
token_mint_address: "3NZ9JMVBmGAqocybic2c7LQCJScmgsAZ6vQqTDzcqmJh".into(), | ||
token_address: "94JfTH8qCeBQDBatvULREG43msjSQscT7oHnqx7jppX".into(), | ||
is_token_2022: false | ||
}; | ||
|
||
let input = Proto::SigningInput { | ||
|
@@ -496,6 +500,7 @@ fn test_solana_sign_token_transfer() { | |
// 0.004 | ||
amount: 4000, | ||
decimals: 6, | ||
is_token_2022: false, | ||
..Proto::TokenTransfer::default() | ||
}; | ||
let input = Proto::SigningInput { | ||
|
@@ -522,6 +527,7 @@ fn test_solana_sign_token_transfer_2pmvzp() { | |
// 0.0061 | ||
amount: 6100, | ||
decimals: 6, | ||
is_token_2022: false, | ||
..Proto::TokenTransfer::default() | ||
}; | ||
let input = Proto::SigningInput { | ||
|
@@ -549,6 +555,7 @@ fn test_solana_sign_create_and_transfer_token() { | |
// 0.0029 | ||
amount: 2900, | ||
decimals: 6, | ||
is_token_2022: false, | ||
..Proto::CreateAndTransferToken::default() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can ignore |
||
}; | ||
let input = Proto::SigningInput { | ||
|
@@ -578,6 +585,7 @@ fn test_solana_sign_create_and_transfer_token_2() { | |
// 0.004 | ||
amount: 4000, | ||
decimals: 6, | ||
is_token_2022: false, | ||
..Proto::CreateAndTransferToken::default() | ||
}; | ||
let input = Proto::SigningInput { | ||
|
@@ -611,6 +619,7 @@ fn test_solana_sign_create_and_transfer_token_with_memo_and_references() { | |
"CuieVDEDtLo7FypA9SbLM9saXFdb1dsshEkyErMqkRQq".into(), | ||
"tFpP7tZUt6zb7YZPpQ11kXNmsc5YzpMXmahGMvCHhqS".into(), | ||
], | ||
is_token_2022: false | ||
}; | ||
let input = Proto::SigningInput { | ||
private_key: b58("66ApBuKpo2uSzpjGBraHq7HP8UZMUJzp3um8FdEjkC9c"), | ||
|
@@ -638,6 +647,7 @@ fn test_solana_sign_create_and_transfer_token_with_durable_nonce() { | |
// 0.004 | ||
amount: 4000, | ||
decimals: 6, | ||
is_token_2022: false, | ||
..Proto::CreateAndTransferToken::default() | ||
}; | ||
let input = Proto::SigningInput { | ||
|
@@ -918,3 +928,30 @@ fn test_solana_sign_raw_message_v0() { | |
// Successfully broadcasted: https://explorer.solana.com/tx/4ffBzXxLPYEEdCYpQGETkCTCCsH6iTdmKzwUZXZZgFemdhRpxQwboguFFoKCeGF3SsZPzuwwE7LbRwLgJbsyRqyP?cluster=testnet | ||
assert_eq!(output.encoded, "6NijVxwQoDjqt6A41HXCK9kXwNDp48uLgvRyE8uz6NY5dEzaEDLzjzuMnc5TGatHZZUXehKrzUGzbg9jPSdn6pVsMc9TXNH6JGe5RJLmHwWey3MC1p8Hs2zhjw5P439P57NToatraDX9ZwvBtK4EzZzRjWbyGdicheTPjeYKCzvPCLxDkTFtPCM9VZGGXSN2Bne92NLDvf6ntNm5pxsPkZGxPe4w9Eq26gkE83hZyrYXKaiDh8TbqbHatSkw"); | ||
} | ||
|
||
#[test] | ||
fn test_solana_sign_create_and_transfer_token_2022() { | ||
let create_transfer_token: Proto::CreateAndTransferToken = Proto::CreateAndTransferToken { | ||
recipient_main_address: "EbHdsfVpWzeQV4TceYQ2xENS8meBHyztyTKVSFtgHPUw".into(), | ||
token_mint_address: "BSQCmMAFB9itonyVSLsUxX92Ne1rgBZFqothBk3q91k6".into(), | ||
recipient_token_address: "FzsLNpzsLMBbm1LWpM6P3W4tKrCkd8KqnMmADNvArW5d".into(), | ||
sender_token_address: "EQxRyhzjyhRX4TJXt7FmQ3HfFdRcu49krjxHMszidQYS".into(), | ||
amount: 1000000000, | ||
decimals: 9, | ||
is_token_2022: true, | ||
..Proto::CreateAndTransferToken::default() | ||
}; | ||
let input = Proto::SigningInput { | ||
private_key: b58("MCyXa2gTJELxTPemyVi5ydDcQ3vVgFyddQYXj6UM3tw"), | ||
recent_blockhash: "9S1R94w4KzF15EYP5iP7gTigvyPd4JRfEkcUdhsirxgA".into(), | ||
transaction_type: TransactionType::create_and_transfer_token_transaction( | ||
create_transfer_token, | ||
), | ||
..Proto::SigningInput::default() | ||
}; | ||
let mut signer = AnySignerHelper::<Proto::SigningOutput>::default(); | ||
let output = signer.sign(CoinType::Solana, input); | ||
assert_eq!(output.error, SigningError::OK); | ||
assert_eq!(output.encoded, "2hBQNSnumbABqKWgpeAFnCEYqb27FMMiZBn4BHrfv2CeYvzyhhrWhPm2uVHRjiJ4CwUFrFZgoTBKDhHqqDYkFVCnU82DAvsEjAQCcKGET16CGr14wNbmhL34KZv9qwvpiyRRBwDN8DJy9kLcRdYXKr8Vx5Emm5iaUu33BMbqLpcETN7HB4wFWrxrDyYgP6jbaC8v3g1wyp3xp7Q3LJ9NXki4ATmjV2T1MrpSzTjJAgQvhsx7mb2BARU7Bdrp92qgNrNWkpwr6vru2CF5UVJRySjYHaJo8YdKKMwFR8ZuwUfhbk9FFdSVGhxqX8pfj6NmUU55KMrxTtupjgifKuFZng7avzsRmysHZuBNeywrip7Gw66MaBsbsYons5jFarqUpboXyHiF4R1RQX4eQYqfmDPksv7Dh68M2wCcmiUcu3AdMMs4VHwWmkks3WfAGKKL1cN54f7SN5yP1FoGAMRbtLSCS5GCFt2pnQfkMmwqrNBtDT2pYB4f3iuGfXdHJ7APcoFtyBfUfwShUnYPq5KX3bgwAB73C38R1Hrh9e7mJJCG8i5d1CtLH12N4"); | ||
// https://explorer.solana.com/tx/Lg1xWzsC9GatQMu1ZXv23t7snC92RRvbKJe22bsS76GUb8C8a9q3HPkiUnFoK6AWKSoNSsmko1EBnvKkCnL8b7w?cluster=devnet | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please revert the keys sorting? Even though, they're sorted in official Solana lib, but in WalletCore I disabled it explicitly to save backward compatibility to have the same transaction signature after the Rust transition.
Please note that the keys are not required to be sorted to be valid transaction