Skip to content
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

token 2022: repair onchain helper #6112

Merged
merged 1 commit into from
Jan 11, 2024
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions token/program-2022-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
23 changes: 23 additions & 0 deletions token/program-2022-test/tests/transfer_hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use {
transaction::TransactionError,
transport::TransportError,
},
spl_tlv_account_resolution::{account::ExtraAccountMeta, seeds::Seed},
spl_token_2022::{
error::TokenError,
extension::{
Expand Down Expand Up @@ -191,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,
Expand Down
16 changes: 10 additions & 6 deletions token/program-2022/src/onchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!
Expand All @@ -61,12 +62,15 @@ pub fn invoke_transfer_checked<'a>(
let mint_data = mint_info.try_borrow_data()?;
let mint = StateWithExtensions::<Mint>::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,
mint_info.clone(),
destination_info,
authority_info,
amount,
additional_accounts,
)?;
}
Expand Down