Minting and Burning

Minting Stablecoins

Minting is the process of creating new tokens and adding them to circulation. This operation should only be performed by designated roles within the system, known as minters.

  • Checks: The minter's authority, whether the stablecoin system is active (not paused), and if the recipient's account is not denylisted.
  • Operation: Creates new tokens and deposits them into the recipient's account.
  • Logging: Emits a Mint event with details about the transaction.

public entry fun mint(minter: &signer, to: address, amount: u64) acquires Management, Roles, State {
assert_is_minter(minter);
assert_not_denylisted(to);
let management = borrow_global<Management>(usdk_address());
let tokens = fungible_asset::mint(&management.mint_ref, amount);
deposit(primary_fungible_store::ensure_primary_store_exists(to, metadata()), tokens, &management.transfer_ref);
event::emit(Mint {
minter: signer::address_of(minter),
to,
amount,
});
}

Burning Stablecoins

Burning refers to the process of permanently removing tokens from circulation, effectively reducing the total supply. Again, this operation should only be performed by the designated minter role.

  • Checks: The caller must be a minter and the system should not be paused.
  • Operation: Withdraws tokens from a specified store and burns them.
  • Logging: Emits a Burn event with transaction details.

/// Burn tokens from the specified account. This checks that the caller is a minter and the stablecoin is not paused.
public entry fun burn(minter: &signer, from: address, amount: u64) acquires Management, Roles, State {
burn_from(minter, primary_fungible_store::ensure_primary_store_exists(from, metadata()), amount);
}
/// Burn tokens from the specified account's store. This checks that the caller is a minter and the stablecoin is
/// not paused.
public entry fun burn_from(
minter: &signer,
store: Object<FungibleStore>,
amount: u64,
) acquires Management, Roles, State {
assert_is_minter(minter);
let management = borrow_global<Management>(usdk_address());
let tokens = fungible_asset::withdraw_with_ref(
&management.transfer_ref,
store,
amount,
);
fungible_asset::burn(&management.burn_ref, tokens);
event::emit(Burn {
minter: signer::address_of(minter),
from: object::owner(store),
store,
amount,
});
}

Note that above we have 2 functions: burn and burn_from. burn will only burn FA units from the minter's primary fungible store. However, burn_from provides additional flexibility in that it allows burning from secondary stores as well.