triggr/instructions/
close_account.rs

1use anchor_lang::prelude::*;
2use anchor_lang::solana_program::pubkey;
3
4#[derive(Accounts)]
5pub struct CloseAccount<'info> {
6    #[account(mut, constraint = authority.key() == pubkey!("FtfyGT3iNnb2Eru5WE4gU8YZyicYZcLNzfywhx94UTFE"))]
7    authority: Signer<'info>,
8
9    /// CHECK: This is unsafe and should not be done in production
10    #[account(mut)]
11    account: UncheckedAccount<'info>,
12
13    system_program: Program<'info, System>,
14}
15
16pub fn handler(ctx: Context<CloseAccount>) -> Result<()> {
17    let amount = ctx.accounts.account.lamports();
18
19    **ctx.accounts.account.try_borrow_mut_lamports()? -= amount;
20    **ctx.accounts.authority.try_borrow_mut_lamports()? += amount;
21    Ok(())
22}