Added token::transfer_checked wrapper to token (#2351)

This commit is contained in:
Barebox 2023-01-04 16:19:40 +00:00 committed by GitHub
parent 9ba0223c58
commit a068171aee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 35 additions and 0 deletions

View File

@ -33,6 +33,33 @@ pub fn transfer<'a, 'b, 'c, 'info>(
.map_err(Into::into)
}
pub fn transfer_checked<'a, 'b, 'c, 'info>(
ctx: CpiContext<'a, 'b, 'c, 'info, TransferChecked<'info>>,
amount: u64,
decimals: u8,
) -> Result<()> {
let ix = spl_token::instruction::transfer_checked(
&spl_token::ID,
ctx.accounts.from.key,
ctx.accounts.mint.key,
ctx.accounts.to.key,
ctx.accounts.authority.key,
&[],
amount,
decimals
)?;
solana_program::program::invoke_signed(
&ix, &[
ctx.accounts.from.clone(),
ctx.accounts.mint.clone(),
ctx.accounts.to.clone(),
ctx.accounts.authority.clone(),
],
ctx.signer_seeds
)
.map_err(Into::into)
}
pub fn mint_to<'a, 'b, 'c, 'info>(
ctx: CpiContext<'a, 'b, 'c, 'info, MintTo<'info>>,
amount: u64,
@ -307,6 +334,14 @@ pub struct Transfer<'info> {
pub authority: AccountInfo<'info>,
}
#[derive(Accounts)]
pub struct TransferChecked<'info> {
pub from: AccountInfo<'info>,
pub mint: AccountInfo<'info>,
pub to: AccountInfo<'info>,
pub authority: AccountInfo<'info>,
}
#[derive(Accounts)]
pub struct MintTo<'info> {
pub mint: AccountInfo<'info>,