From ac35de5aa7d544ca10b4132993b3970ee1691a92 Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 10 Jan 2024 15:53:28 -0600 Subject: [PATCH] token 2022: repair onchain helper --- Cargo.lock | 1 + token/program-2022-test/Cargo.toml | 1 + .../program-2022-test/tests/transfer_hook.rs | 27 ++++++++++++++++++- token/program-2022/src/onchain.rs | 16 ++++++----- 4 files changed, 38 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 64e2a3f1576..4416c984402 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7373,6 +7373,7 @@ dependencies = [ "spl-instruction-padding", "spl-memo 4.0.0", "spl-pod 0.1.0", + "spl-tlv-account-resolution 0.5.1", "spl-token-2022 1.0.0", "spl-token-client", "spl-token-group-interface", diff --git a/token/program-2022-test/Cargo.toml b/token/program-2022-test/Cargo.toml index 4e70388d25c..67321d78aef 100644 --- a/token/program-2022-test/Cargo.toml +++ b/token/program-2022-test/Cargo.toml @@ -27,6 +27,7 @@ spl-memo = { version = "4.0.0", path = "../../memo/program", features = ["no-ent spl-pod = { version = "0.1.0", path = "../../libraries/pod" } spl-token-2022 = { version = "1.0", path="../program-2022", features = ["no-entrypoint"] } spl-instruction-padding = { version = "0.1.0", path="../../instruction-padding/program", features = ["no-entrypoint"] } +spl-tlv-account-resolution = { version = "0.5.0", path = "../../libraries/tlv-account-resolution" } spl-token-client = { version = "0.8", path = "../client" } spl-token-group-interface = { version = "0.1", path = "../../token-group/interface" } spl-token-metadata-interface = { version = "0.2", path = "../../token-metadata/interface" } diff --git a/token/program-2022-test/tests/transfer_hook.rs b/token/program-2022-test/tests/transfer_hook.rs index 9a36b1f5b93..7d817577477 100644 --- a/token/program-2022-test/tests/transfer_hook.rs +++ b/token/program-2022-test/tests/transfer_hook.rs @@ -17,6 +17,7 @@ use { transaction::TransactionError, transport::TransportError, }, + spl_tlv_account_resolution::{account::ExtraAccountMeta, seeds::Seed}, spl_token_2022::{ error::TokenError, extension::{ @@ -27,7 +28,9 @@ use { processor::Processor, }, spl_token_client::token::{ExtensionInitializationParams, TokenError as TokenClientError}, - spl_transfer_hook_interface::{get_extra_account_metas_address, offchain::add_extra_account_metas_for_execute}, + spl_transfer_hook_interface::{ + get_extra_account_metas_address, offchain::add_extra_account_metas_for_execute, + }, std::{convert::TryInto, sync::Arc}, }; @@ -189,6 +192,28 @@ fn add_validation_account(program_test: &mut ProgramTest, mint: &Pubkey, program is_writable: false, } .into(), + ExtraAccountMeta::new_with_seeds( + &[ + Seed::AccountKey { index: 0 }, // source + Seed::AccountKey { index: 2 }, // destination + Seed::AccountKey { index: 4 }, // validation state + ], + false, + true, + ) + .unwrap(), + ExtraAccountMeta::new_with_seeds( + &[ + Seed::Literal { + bytes: vec![1, 2, 3, 4, 5, 6], + }, + Seed::AccountKey { index: 2 }, // destination + Seed::AccountKey { index: 5 }, // extra meta 1 + ], + false, + true, + ) + .unwrap(), ]; program_test.add_account( validation_address, diff --git a/token/program-2022/src/onchain.rs b/token/program-2022/src/onchain.rs index c6056ceae9b..edc3c06e057 100644 --- a/token/program-2022/src/onchain.rs +++ b/token/program-2022/src/onchain.rs @@ -11,6 +11,7 @@ use { account_info::AccountInfo, entrypoint::ProgramResult, instruction::AccountMeta, program::invoke_signed, pubkey::Pubkey, }, + spl_transfer_hook_interface::onchain::add_extra_accounts_for_execute_cpi, }; /// Helper to CPI into token-2022 on-chain, looking through the additional @@ -39,10 +40,10 @@ pub fn invoke_transfer_checked<'a>( )?; let mut cpi_account_infos = vec![ - source_info, + source_info.clone(), mint_info.clone(), - destination_info, - authority_info, + destination_info.clone(), + authority_info.clone(), ]; // if it's a signer, it might be a multisig signer, throw it in! @@ -61,12 +62,15 @@ pub fn invoke_transfer_checked<'a>( let mint_data = mint_info.try_borrow_data()?; let mint = StateWithExtensions::::unpack(&mint_data)?; if let Some(program_id) = transfer_hook::get_program_id(&mint) { - #[allow(deprecated)] - spl_transfer_hook_interface::onchain::add_cpi_accounts_for_execute( + add_extra_accounts_for_execute_cpi( &mut cpi_instruction, &mut cpi_account_infos, - mint_info.key, &program_id, + source_info.key, + mint_info.key, + destination_info.key, + authority_info.key, + amount, additional_accounts, )?; }