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

Commit e988e6f

Browse files
author
Joe C
authored
token 2022: repair onchain helper
Continuing on from the new helper introduced in #6111. Here the onchain helper in Token2022 is updated to use the non-deprecated new onchain helper from SPL Transfer Hook interface. PDAs as extra meta configs are also added to the transfer hook test in `program-2022-test` for additional assurance.
1 parent 095bc48 commit e988e6f

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

token/program-2022-test/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ spl-memo = { version = "4.0.0", path = "../../memo/program", features = ["no-ent
2727
spl-pod = { version = "0.1.0", path = "../../libraries/pod" }
2828
spl-token-2022 = { version = "1.0", path="../program-2022", features = ["no-entrypoint"] }
2929
spl-instruction-padding = { version = "0.1.0", path="../../instruction-padding/program", features = ["no-entrypoint"] }
30+
spl-tlv-account-resolution = { version = "0.5.0", path = "../../libraries/tlv-account-resolution" }
3031
spl-token-client = { version = "0.8", path = "../client" }
3132
spl-token-group-interface = { version = "0.1", path = "../../token-group/interface" }
3233
spl-token-metadata-interface = { version = "0.2", path = "../../token-metadata/interface" }

token/program-2022-test/tests/transfer_hook.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use {
1717
transaction::TransactionError,
1818
transport::TransportError,
1919
},
20+
spl_tlv_account_resolution::{account::ExtraAccountMeta, seeds::Seed},
2021
spl_token_2022::{
2122
error::TokenError,
2223
extension::{
@@ -191,6 +192,28 @@ fn add_validation_account(program_test: &mut ProgramTest, mint: &Pubkey, program
191192
is_writable: false,
192193
}
193194
.into(),
195+
ExtraAccountMeta::new_with_seeds(
196+
&[
197+
Seed::AccountKey { index: 0 }, // source
198+
Seed::AccountKey { index: 2 }, // destination
199+
Seed::AccountKey { index: 4 }, // validation state
200+
],
201+
false,
202+
true,
203+
)
204+
.unwrap(),
205+
ExtraAccountMeta::new_with_seeds(
206+
&[
207+
Seed::Literal {
208+
bytes: vec![1, 2, 3, 4, 5, 6],
209+
},
210+
Seed::AccountKey { index: 2 }, // destination
211+
Seed::AccountKey { index: 5 }, // extra meta 1
212+
],
213+
false,
214+
true,
215+
)
216+
.unwrap(),
194217
];
195218
program_test.add_account(
196219
validation_address,

token/program-2022/src/onchain.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use {
1111
account_info::AccountInfo, entrypoint::ProgramResult, instruction::AccountMeta,
1212
program::invoke_signed, pubkey::Pubkey,
1313
},
14+
spl_transfer_hook_interface::onchain::add_extra_accounts_for_execute_cpi,
1415
};
1516

1617
/// Helper to CPI into token-2022 on-chain, looking through the additional
@@ -39,10 +40,10 @@ pub fn invoke_transfer_checked<'a>(
3940
)?;
4041

4142
let mut cpi_account_infos = vec![
42-
source_info,
43+
source_info.clone(),
4344
mint_info.clone(),
44-
destination_info,
45-
authority_info,
45+
destination_info.clone(),
46+
authority_info.clone(),
4647
];
4748

4849
// if it's a signer, it might be a multisig signer, throw it in!
@@ -61,12 +62,15 @@ pub fn invoke_transfer_checked<'a>(
6162
let mint_data = mint_info.try_borrow_data()?;
6263
let mint = StateWithExtensions::<Mint>::unpack(&mint_data)?;
6364
if let Some(program_id) = transfer_hook::get_program_id(&mint) {
64-
#[allow(deprecated)]
65-
spl_transfer_hook_interface::onchain::add_cpi_accounts_for_execute(
65+
add_extra_accounts_for_execute_cpi(
6666
&mut cpi_instruction,
6767
&mut cpi_account_infos,
68-
mint_info.key,
6968
&program_id,
69+
source_info,
70+
mint_info.clone(),
71+
destination_info,
72+
authority_info,
73+
amount,
7074
additional_accounts,
7175
)?;
7276
}

0 commit comments

Comments
 (0)