pub fn _burn(
    total_supply_key: StorageKey<StorageMap<AssetId, u64>>,
    sub_id: SubId,
    amount: u64,
) 
Expand description

Burns assets with the given sub_id.

Additional Information

Warning This function burns assets unequivocally. It does not check that assets are sent to the calling contract.
Warning This function reduces the total supply by the number of coins burned. Using this value when minting may cause unintended consequences.

Arguments

  • total_assets_key: [StorageKey] - The location in storage that the u64 which represents the total assets is stored.
  • sub_id: [SubId] - The sub-identifier of the asset to burn.
  • amount: [u64] - The quantity of coins to burn.

Reverts

  • When the calling contract does not have enough assets.
  • When amount is zero.

Number of Storage Accesses

  • Reads: 1
  • Writes: 1

Examples

use sway_libs::asset::supply::_burn;
use std::{call_frames::contract_id, context::balance_of};

storage {
    total_supply: StorageMap<AssetId, u64> = StorageMap {},
}

fn foo(asset_id: AssetId) {
    assert(balance_of(contract_id(), asset_id) == 100);
    _burn(storage.total_supply, SubId::zero(), 100);
    assert(balance_of(contract_id(), asset_id) == 0);
}