The Permanent Delegate Extension
The PermanentDelegate
extension is a Mint account extension that allows a permanent delegate for all tokens of the mint that is capable of transferring or burning any token of that mint, from any token account.
Initializing the Mint Account
To initialie the PermanentDelegate
extension on a Mint
account we're going to need the initializePermanentDelegate()
function.
Here's how to create a mint with the Mint Close extension:
import {
Keypair,
SystemProgram,
Transaction,
sendAndConfirmTransaction,
} from '@solana/web3.js';
import {
createInitializeMintInstruction,
createInitializePermanentDelegateInstruction,
getMintLen,
ExtensionType,
TOKEN_2022_PROGRAM_ID,
} from '@solana/spl-token';
const mint = Keypair.generate();
// Calculate the size needed for a Mint account with Transfer Fee extension
const mintLen = getMintLen([ExtensionType.MintCloseAuthority]);
// Calculate minimum lamports required for rent exemption
const lamports = await connection.getMinimumBalanceForRentExemption(mintLen);
// Create the account with the correct size and owner
const createAccountInstruction = SystemProgram.createAccount({
fromPubkey: keypair.publicKey,
newAccountPubkey: mint.publicKey,
space: mintLen,
lamports,
programId: TOKEN_2022_PROGRAM_ID,
});
// Initialize the Permanent Delegate extension
const initializePermanentDelegate = createInitializePermanentDelegateInstruction(
mint.publicKey,
keypair.publicKey,
TOKEN_2022_PROGRAM_ID,
);
// Initialize the mint itself
const initializeMintInstruction = createInitializeMintInstruction(
mint.publicKey,
6,
keypair.publicKey,
null,
TOKEN_2022_PROGRAM_ID,
);
// Combine all instructions in the correct order
const transaction = new Transaction().add(
createAccountInstruction,
initializePermanentDelegate,
initializeMintInstruction,
);
const signature = await sendAndConfirmTransaction(connection, transaction, [keypair, mint]);
console.log(`Mint created! Check out your TX here: https://explorer.solana.com/tx/${signature}?cluster=devnet`);
Closing the Mint Account
If a Mint
account has a supply of zero, the CloseMint Authority
can reclaim the rent on that account by usingin the closeAccount
instruction like so:
const closeMintInstruction = createCloseAccountInstruction(
mint.publicKey,
keypair.publicKey,
keypair.publicKey,
[],
TOKEN_2022_PROGRAM_ID,
);
const transaction = new Transaction().add(closeMintInstruction);
const signature = await sendAndConfirmTransaction(connection, transaction, [keypair], {skipPreflight: false});
console.log(`Mint closed! Check out your TX here: https://explorer.solana.com/tx/${signature}?cluster=devnet`);
Permissioned Actions
Unlike regular delegates which can be revoked, this delegate authority is permanent and immutable.
This means that every normal action like transfer()
, burn()
, approve()
and freeze()
can be executed whenever needed directly by the authority without needing the signature of the actual owner.
This means that we can just use the normal transferChecked()
, burnChecked()
, ... instructions and pass in the PermanetDelegate
authority in the authority
field.