Skip to content

Commit

Permalink
spl: Add token close_account instruction (#714)
Browse files Browse the repository at this point in the history
  • Loading branch information
suscd authored Sep 12, 2021
1 parent 374009b commit e763b72
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions spl/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,27 @@ pub fn initialize_account<'a, 'b, 'c, 'info>(
)
}

pub fn close_account<'a, 'b, 'c, 'info>(
ctx: CpiContext<'a, 'b, 'c, 'info, CloseAccount<'info>>,
) -> ProgramResult {
let ix = spl_token::instruction::close_account(
&spl_token::ID,
ctx.accounts.account.key,
ctx.accounts.destination.key,
ctx.accounts.authority.key,
&[], // TODO: support multisig
)?;
solana_program::program::invoke_signed(
&ix,
&[
ctx.accounts.account.clone(),
ctx.accounts.destination.clone(),
ctx.accounts.authority.clone(),
],
ctx.signer_seeds,
)
}

pub fn initialize_mint<'a, 'b, 'c, 'info>(
ctx: CpiContext<'a, 'b, 'c, 'info, InitializeMint<'info>>,
decimals: u8,
Expand Down Expand Up @@ -217,6 +238,13 @@ pub struct InitializeAccount<'info> {
pub rent: AccountInfo<'info>,
}

#[derive(Accounts)]
pub struct CloseAccount<'info> {
pub account: AccountInfo<'info>,
pub destination: AccountInfo<'info>,
pub authority: AccountInfo<'info>,
}

#[derive(Accounts)]
pub struct InitializeMint<'info> {
pub mint: AccountInfo<'info>,
Expand Down

0 comments on commit e763b72

Please sign in to comment.