Anchor
使用Anchor的Token2022

使用Anchor的Token2022

永久代理擴展

PermanentDelegate 擴展是一個鑄幣賬戶擴展,允許為該鑄幣的所有代幣設置一個永久代理,該代理能夠從任何代幣賬戶轉移或銷毀該鑄幣的任何代幣。

初始化鑄幣賬戶

要在 Mint 賬戶上初始化 PermanentDelegate 擴展,我們可以簡單地使用 Anchor 為我們創建的宏。

以下是如何使用永久代理擴展創建鑄幣的方法:

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::permanent_delegate::delegate = signer,
    )]
    pub mint: InterfaceAccount<'info, Mint>,
    pub system_program: Program<'info, System>,
    pub token_program: Interface<'info, TokenInterface>,
}

授權操作

與可以被撤銷的普通代理不同,該代理權限是永久且不可更改的。

這意味著每個普通操作,例如 transfer()burn()approve()freeze(),都可以在需要時直接由代理權限執行,而無需實際擁有者的簽名。

這意味著我們可以直接使用普通的 transferChecked()burnChecked() 等指令,並在 authority 欄位中傳入 PermanentDelegate 權限。

Blueshift © 2025Commit: e573eab