diff --git a/token/client/src/token.rs b/token/client/src/token.rs index d09ca78a8b7..1f41aa31b80 100644 --- a/token/client/src/token.rs +++ b/token/client/src/token.rs @@ -913,17 +913,41 @@ where let signing_pubkeys = signing_keypairs.pubkeys(); let multisig_signers = self.get_multisig_signers(authority, &signing_pubkeys); - let mut instruction = if let Some(decimals) = self.decimals { - instruction::transfer_checked( - &self.program_id, - source, - &self.pubkey, - destination, - authority, - &multisig_signers, - amount, - decimals, - )? + let fetch_account_data_fn = |address| { + self.client + .get_account(address) + .map_ok(|opt| opt.map(|acc| acc.data)) + }; + + let instruction = if let Some(decimals) = self.decimals { + if let Some(transfer_hook_accounts) = &self.transfer_hook_accounts { + let mut instruction = instruction::transfer_checked( + &self.program_id, + source, + self.get_address(), + destination, + authority, + &multisig_signers, + amount, + decimals, + )?; + instruction.accounts.extend(transfer_hook_accounts.clone()); + instruction + } else { + offchain::create_transfer_checked_instruction_with_extra_metas( + &self.program_id, + source, + self.get_address(), + destination, + authority, + &multisig_signers, + amount, + decimals, + fetch_account_data_fn, + ) + .await + .map_err(|_| TokenError::AccountNotFound)? + } } else { #[allow(deprecated)] instruction::transfer( @@ -935,22 +959,6 @@ where amount, )? }; - if let Some(transfer_hook_accounts) = &self.transfer_hook_accounts { - instruction.accounts.extend(transfer_hook_accounts.clone()); - } else { - #[allow(deprecated)] - offchain::resolve_extra_transfer_account_metas( - &mut instruction, - |address| { - self.client - .get_account(address) - .map_ok(|opt| opt.map(|acc| acc.data)) - }, - self.get_address(), - ) - .await - .map_err(|_| TokenError::AccountNotFound)?; - }; self.process_ixs(&[instruction], signing_keypairs).await }