Burn Tokens & Close Accounts

Efficiently burn SPL tokens and close associated token accounts with the BurnManager class. This functionality is particularly useful for cleaning up unused accounts and managing token supplies.

Code Breakdown

1. Burn Tokens

Burns all tokens in a specified token account:

Copy

burn_instruction = burn(
    BurnParams(
        program_id=TOKEN_PROGRAM_ID,
        account=token_account_pubkey,
        mint=mint,
        owner=owner,
        amount=token_balance
    )
)
transaction.add(burn_instruction)
  • Token Balance Check: Fetches the account’s token balance before proceeding.

  • Mint Address: Identifies the token mint associated with the account.

2. Close Account

Closes the token account to reclaim rent-exempt lamports:

Copy

  • Destination: Remaining lamports are transferred to the owner.

3. Enhanced Compute Budget

Adjusts the compute budget to handle complex operations:

Copy

4. Transaction Execution

Signs and sends the transaction:

Copy

  • Ensures secure and authenticated processing.


Key Features

  1. Comprehensive Functionality

    • Handles both token burning and account closure within a single process.

  2. Batch Processing

    • The process_multiple_accounts method allows for the efficient processing of multiple accounts:

    Copy

  3. Error Handling

    • Captures errors during balance fetching, instruction preparation, and transaction execution:

    Copy

  4. Compute Budget Adjustment

    • Ensures successful execution of complex transactions by increasing compute unit limits.

Last updated