Skip to main content

  1. Burn permanently destroys tokens by reducing the balance in a token account.
  2. Burned tokens are removed from circulation and decreases the supply tracked on the mint account.
  3. Only the token account owner (or approved delegate) can burn tokens.
Compare to SPL:
1

Prerequisites

Cargo.toml
[dependencies]
light-compressed-token-sdk = "0.1"
light-client = "0.1"
light-token-types = "0.1"
solana-sdk = "2.2"
borsh = "0.10"
tokio = { version = "1.36", features = ["full"] }

[dev-dependencies]
light-program-test = "0.1"  # For in-memory tests with LiteSVM
Test with Lite-SVM (…)
# Initialize project
cargo init my-light-project
cd my-light-project

# Run tests
cargo test
use light_program_test::{LightProgramTest, ProgramTestConfig};
use solana_sdk::signer::Signer;

#[tokio::test]
async fn test_example() {
    // In-memory test environment 
    let mut rpc = LightProgramTest::new(ProgramTestConfig::default())
        .await
        .unwrap();

    let payer = rpc.get_payer().insecure_clone();
    println!("Payer: {}", payer.pubkey());
}
2

Burn light-tokens

View Source Code or find full examples with tests: examples-light-token.
mod shared;

use borsh::BorshDeserialize;
use light_client::rpc::Rpc;
use light_token_sdk::token::Burn;
use shared::SetupContext;
use solana_sdk::signer::Signer;

#[tokio::test(flavor = "multi_thread")]
async fn burn() {
    // Setup creates mint and ATA with tokens
    let SetupContext {
        mut rpc,
        payer,
        mint,
        ata,
        ..
    } = shared::setup().await;

    let initial_amount = 1_000_000u64;
    let burn_amount = 400_000u64;

    let burn_ix = Burn {
        source: ata,
        mint,
        amount: burn_amount,
        authority: payer.pubkey(),
        max_top_up: None,
    }
    .instruction()
    .unwrap();

    rpc.create_and_send_transaction(&[burn_ix], &payer.pubkey(), &[&payer])
        .await
        .unwrap();

    let ata_data = rpc.get_account(ata).await.unwrap().unwrap();
    let token = light_token_interface::state::Token::deserialize(&mut &ata_data.data[..]).unwrap();
    assert_eq!(token.amount, initial_amount - burn_amount);
}

Next Steps

Freeze and Thaw Light Token Accounts