diff --git a/solana/programs/example-native-token-transfers/src/instructions/release_inbound.rs b/solana/programs/example-native-token-transfers/src/instructions/release_inbound.rs index 4d4d3d03e..e4fb201f8 100644 --- a/solana/programs/example-native-token-transfers/src/instructions/release_inbound.rs +++ b/solana/programs/example-native-token-transfers/src/instructions/release_inbound.rs @@ -1,6 +1,7 @@ use anchor_lang::prelude::*; use anchor_spl::token_interface; use ntt_messages::mode::Mode; +use spl_token_2022::onchain; use crate::{ config::*, @@ -119,8 +120,8 @@ pub struct ReleaseInboundUnlock<'info> { /// Setting this flag to `false` is useful when bundling this instruction /// together with [`crate::instructions::redeem`], so that the unlocking /// is attempted optimistically. -pub fn release_inbound_unlock( - ctx: Context, +pub fn release_inbound_unlock<'info>( + ctx: Context<'_, '_, '_, 'info, ReleaseInboundUnlock<'info>>, args: ReleaseInboundArgs, ) -> Result<()> { let inbox_item = &mut ctx.accounts.common.inbox_item; @@ -138,22 +139,22 @@ pub fn release_inbound_unlock( assert!(inbox_item.release_status == ReleaseStatus::Released); match ctx.accounts.common.config.mode { Mode::Burning => Err(NTTError::InvalidMode.into()), - Mode::Locking => token_interface::transfer_checked( - CpiContext::new_with_signer( - ctx.accounts.common.token_program.to_account_info(), - token_interface::TransferChecked { - from: ctx.accounts.custody.to_account_info(), - to: ctx.accounts.common.recipient.to_account_info(), - authority: ctx.accounts.common.token_authority.clone(), - mint: ctx.accounts.common.mint.to_account_info(), - }, + Mode::Locking => { + onchain::invoke_transfer_checked( + &ctx.accounts.common.token_program.key(), + ctx.accounts.custody.to_account_info(), + ctx.accounts.common.mint.to_account_info(), + ctx.accounts.common.recipient.to_account_info(), + ctx.accounts.common.token_authority.clone(), + ctx.remaining_accounts, + inbox_item.amount, + ctx.accounts.common.mint.decimals, &[&[ crate::TOKEN_AUTHORITY_SEED, &[ctx.bumps.common.token_authority], ]], - ), - inbox_item.amount, - ctx.accounts.common.mint.decimals, - ), + )?; + Ok(()) + } } } diff --git a/solana/programs/example-native-token-transfers/src/instructions/transfer.rs b/solana/programs/example-native-token-transfers/src/instructions/transfer.rs index 82891ad8d..aab502e7f 100644 --- a/solana/programs/example-native-token-transfers/src/instructions/transfer.rs +++ b/solana/programs/example-native-token-transfers/src/instructions/transfer.rs @@ -2,6 +2,7 @@ use anchor_lang::prelude::*; use anchor_spl::token_interface; use ntt_messages::{chain_id::ChainId, mode::Mode, trimmed_amount::TrimmedAmount}; +use spl_token_2022::onchain; use crate::{ bitmap::Bitmap, @@ -215,7 +216,10 @@ pub struct TransferLock<'info> { pub custody: InterfaceAccount<'info, token_interface::TokenAccount>, } -pub fn transfer_lock(ctx: Context, args: TransferArgs) -> Result<()> { +pub fn transfer_lock<'info>( + ctx: Context<'_, '_, '_, 'info, TransferLock<'info>>, + args: TransferArgs, +) -> Result<()> { require_eq!( ctx.accounts.common.config.mode, Mode::Locking, @@ -240,24 +244,21 @@ pub fn transfer_lock(ctx: Context, args: TransferArgs) -> Result<( let before = accs.custody.amount; - token_interface::transfer_checked( - CpiContext::new_with_signer( - accs.common.token_program.to_account_info(), - token_interface::TransferChecked { - from: accs.common.from.to_account_info(), - to: accs.custody.to_account_info(), - authority: accs.session_authority.to_account_info(), - mint: accs.common.mint.to_account_info(), - }, - &[&[ - crate::SESSION_AUTHORITY_SEED, - accs.common.from.owner.as_ref(), - args.keccak256().as_ref(), - &[ctx.bumps.session_authority], - ]], - ), + onchain::invoke_transfer_checked( + &accs.common.token_program.key(), + accs.common.from.to_account_info(), + accs.common.mint.to_account_info(), + accs.custody.to_account_info(), + accs.session_authority.to_account_info(), + ctx.remaining_accounts, amount, accs.common.mint.decimals, + &[&[ + crate::SESSION_AUTHORITY_SEED, + accs.common.from.owner.as_ref(), + args.keccak256().as_ref(), + &[ctx.bumps.session_authority], + ]], )?; accs.custody.reload()?; diff --git a/solana/programs/example-native-token-transfers/src/lib.rs b/solana/programs/example-native-token-transfers/src/lib.rs index 1d3ebc3bb..8a2704301 100644 --- a/solana/programs/example-native-token-transfers/src/lib.rs +++ b/solana/programs/example-native-token-transfers/src/lib.rs @@ -81,7 +81,10 @@ pub mod example_native_token_transfers { instructions::transfer_burn(ctx, args) } - pub fn transfer_lock(ctx: Context, args: TransferArgs) -> Result<()> { + pub fn transfer_lock<'info>( + ctx: Context<'_, '_, '_, 'info, TransferLock<'info>>, + args: TransferArgs, + ) -> Result<()> { instructions::transfer_lock(ctx, args) } @@ -96,8 +99,8 @@ pub mod example_native_token_transfers { instructions::release_inbound_mint(ctx, args) } - pub fn release_inbound_unlock( - ctx: Context, + pub fn release_inbound_unlock<'info>( + ctx: Context<'_, '_, '_, 'info, ReleaseInboundUnlock<'info>>, args: ReleaseInboundArgs, ) -> Result<()> { instructions::release_inbound_unlock(ctx, args)