Anchor
Token2022 з Anchor

Token2022 з Anchor

Розширення Mint Close Authority

Розширення MintCloseAuthority є розширенням Mint, яке дозволяє власнику закрити та отримати орендну плату з рахунку Mint, який має поточний запас 0.

Це розширення корисне для очищення невикористаних мінтів та повернення SOL, який був використаний для оплати звільнення рахунку від оренди. Мінт можна закрити лише тоді, коли в обігу немає токенів.

Ініціалізація рахунку Mint

Щоб ініціалізувати розширення MintCloseAuthority на рахунку Mint, ми можемо просто використати макрос, який створив для нас Anchor.

Ось як створити мінт з розширенням Mint Close:

rust
#[derive(Accounts)]
pub struct CreateMint<'info> {
    #[account(mut)]
    pub signer: Signer<'info>,
    #[account(
        init,
        payer = signer,
        mint::decimals = 6,
        mint::authority = signer.key(),
        mint::token_program = token_program
        extensions::close_authority::authority = signer,
    )]
    pub mint: InterfaceAccount<'info, Mint>,
    pub system_program: Program<'info, System>,
    pub token_program: Interface<'info, TokenInterface>,
}

Закриття рахунку Mint

Якщо рахунок Mint має запас нуль, CloseMint Authority може повернути орендну плату за цей рахунок, використовуючи інструкцію close_account() таким чином:

rust
use anchor_lang::prelude::*;
use anchor_lang::system_program::{create_account, CreateAccount};
use anchor_spl::{
    token_2022::{close_account, CloseAccount},
    token_interface::{
        spl_token_2022::{
            extension::{
                mint_close_authority::MintCloseAuthority
            },
        },
        Mint, Token2022,
    },
};
 
#[derive(Accounts)]
pub struct Close<'info> {
    #[account(mut)]
    pub authority: Signer<'info>,
 
    #[account(
        mut,
        extensions::close_authority::authority = authority,
    )]
    pub mint_account: InterfaceAccount<'info, Mint>,
    pub token_program: Program<'info, Token2022>,
}
 
pub fn close(ctx: Context<Close>) -> Result<()> {
    // cpi to token extensions programs to close mint account
    // alternatively, this can also be done in the client
    close_account(CpiContext::new(
        ctx.accounts.token_program.to_account_info(),
        CloseAccount {
            account: ctx.accounts.mint_account.to_account_info(),
            destination: ctx.accounts.authority.to_account_info(),
            authority: ctx.accounts.authority.to_account_info(),
        },
    ))?;
    Ok(())
}
Blueshift © 2025Commit: 6d01265
Blueshift | Token2022 з Anchor | Розширення повноважень закриття емісії