Burn and Close Account

The Burn and Close Account tool is part of AgentiPy, allowing users to burn remaining SPL tokens in an account and then close the token account itself on the Solana blockchain. This is useful for cleaning up token accounts that are no longer needed and reclaiming the SOL locked for rent.

Functionality

This tool is primarily implemented in the BurnManager class.

Key Methods:

  • burn_and_close_account(agent: SolanaAgentKit, token_account: str):

    • Checks the balance of the specified token_account.

    • If the balance is greater than zero, it creates and adds a burn instruction to a transaction.

    • It then adds a close_account instruction to the transaction.

    • The transaction also includes compute unit adjustments.

    • Finally, it signs and sends the transaction.

  • process_multiple_accounts(agent: SolanaAgentKit, token_accounts: list):

    • Iterates through a list of token_accounts (strings).

    • Calls burn_and_close_account for each account to process them individually.

Note: This tool directly interacts with the Solana blockchain and modifies account states. It requires the agent's wallet to be the owner of the token account or have the necessary authority. Always test thoroughly on a devnet or testnet before using on mainnet.

Source Code

You can find the source code for this tool on GitHub: https://github.com/niceberginc/agentipy/blob/main/agentipy/tools/burn_and_close_account.py

Last updated