From e763b721c37d7b36fa283d2f973bc8c76ca96abc Mon Sep 17 00:00:00 2001 From: suscd Date: Sat, 11 Sep 2021 17:35:21 -0700 Subject: [PATCH] spl: Add token `close_account` instruction (#714) --- spl/src/token.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/spl/src/token.rs b/spl/src/token.rs index 490843b95a..59f2468033 100644 --- a/spl/src/token.rs +++ b/spl/src/token.rs @@ -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, @@ -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>,