The TBTC Token contract is a sophisticated token implementation built on the Sui blockchain. It provides a robust mechanism for managing a token with advanced access control, minting, burning, and pause functionality.
A one-time witness struct for the coin type, used during initialization.
A capability that grants administrative privileges to manage the token contract.
A certificate proving an address has minting permissions.
A certificate proving an address has guardian permissions.
A global state object tracking:
- List of authorized minters
- List of authorized guardians
- Current pause status of the contract
The contract is initialized with:
- Creation of a new currency (TBTC)
- Setting up token metadata
- Creating an initial
TokenState
- Transferring
AdminCap
to the contract deployer
Purpose: Add a new address with minting permissions
Parameters:
_: &AdminCap
: Administrative capabilitystate: &mut TokenState
: Global token stateminter: address
: Address to be granted minting rightsctx: &mut TxContext
: Transaction context
Behavior:
- Ensures the address is not already a minter
- Adds the address to the minters list
- Creates and transfers a
MinterCap
to the new minter - Emits a
MinterAdded
event
Purpose: Remove an existing minter's permissions
Parameters:
_: &AdminCap
: Administrative capabilitystate: &mut TokenState
: Global token stateminter: address
: Address to remove from minters_ctx: &mut TxContext
: Transaction context
Behavior:
- Verifies the address is currently a minter
- Removes the address from the minters list
- Emits a
MinterRemoved
event
Purpose: Add a new guardian address
Parameters:
_: &AdminCap
: Administrative capabilitystate: &mut TokenState
: Global token stateguardian: address
: Address to be granted guardian rightsctx: &mut TxContext
: Transaction context
Behavior:
- Ensures the address is not already a guardian
- Adds the address to the guardians list
- Creates and transfers a
GuardianCap
to the new guardian - Emits a
GuardianAdded
event
Purpose: Remove an existing guardian's permissions
Parameters:
_: &AdminCap
: Administrative capabilitystate: &mut TokenState
: Global token stateguardian: address
: Address to remove from guardians_ctx: &mut TxContext
: Transaction context
Behavior:
- Verifies the address is currently a guardian
- Removes the address from the guardians list
- Emits a
GuardianRemoved
event
Purpose: Unpause the token contract
Parameters:
_: &AdminCap
: Administrative capabilitystate: &mut TokenState
: Global token statectx: &mut TxContext
: Transaction context
Behavior:
- Ensures the contract is currently paused
- Sets the pause status to false
- Emits an
Unpaused
event
Purpose: Pause the token contract
Parameters:
_: &GuardianCap
: Guardian capabilitystate: &mut TokenState
: Global token statectx: &mut TxContext
: Transaction context
Behavior:
- Verifies the caller is a guardian
- Ensures the contract is not already paused
- Sets the pause status to true
- Emits a
Paused
event
Purpose: Mint new tokens to a specified address
Parameters:
_: &MinterCap
: Minter capabilitytreasury_cap: &mut TreasuryCap<TBTC>
: Treasury capabilitystate: &TokenState
: Global token stateamount: u64
: Amount of tokens to mintrecipient: address
: Address to receive minted tokensctx: &mut TxContext
: Transaction context
Behavior:
- Verifies the caller is a minter
- Ensures the contract is not paused
- Mints tokens to the specified recipient
- Emits a
TokensMinted
event
Purpose: Burn tokens
Parameters:
treasury_cap: &mut TreasuryCap<TBTC>
: Treasury capabilitystate: &TokenState
: Global token statecoin: Coin<TBTC>
: Coin to be burned
Behavior:
- Ensures the contract is not paused
- Burns the specified tokens
- Emits a
TokensBurned
event
Several helper methods provide utility functions:
is_minter
: Check if an address is a minteris_guardian
: Check if an address is a guardianget_minters
: Retrieve all minter addressesget_guardians
: Retrieve all guardian addressesis_paused
: Check if the contract is paused
The contract emits various events to track important actions:
MinterAdded
MinterRemoved
GuardianAdded
GuardianRemoved
Paused
Unpaused
TokensMinted
TokensBurned
- Requires administrative or specific capabilities for sensitive operations
- Supports pausing the entire token contract
- Granular access control through minters and guardians
- Prevents unauthorized minting and burning
sui client publish ./ --gas-budget 1000000
Use the contract's methods to add trusted minters, guardians, etc.
This contract is licensed under GPL-3.0-only.