Module sui::coin
Defines the Coin type - platform wide representation of fungible tokens and coins. Coin can be described as a secure wrapper around Balance type.
- Struct Coin
- Struct CoinMetadata
- Struct RegulatedCoinMetadata
- Struct TreasuryCap
- Struct DenyCapV2
- Struct CurrencyCreated
- Struct DenyCap
- Constants
- Function total_supply
- Function treasury_into_supply
- Function supply_immut
- Function supply_mut
- Function value
- Function balance
- Function balance_mut
- Function from_balance
- Function into_balance
- Function take
- Function put
- Function redeem_funds
- Function send_funds
- Function join
- Function split
- Function divide_into_n
- Function zero
- Function destroy_zero
- Function create_currency
- Function create_regulated_currency_v2
- Function migrate_regulated_currency_to_v2
- Function mint
- Function mint_balance
- Function burn
- Function deny_list_v2_add
- Function deny_list_v2_remove
- Function deny_list_v2_contains_current_epoch
- Function deny_list_v2_contains_next_epoch
- Function deny_list_v2_enable_global_pause
- Function deny_list_v2_disable_global_pause
- Function deny_list_v2_is_global_pause_enabled_current_epoch
- Function deny_list_v2_is_global_pause_enabled_next_epoch
- Function mint_and_transfer
- Function update_name
- Function update_symbol
- Function update_description
- Function update_icon_url
- Function get_decimals
- Function get_name
- Function get_symbol
- Function get_description
- Function get_icon_url
- Function destroy_metadata
- Function deny_cap_id
- Function new_deny_cap_v2
- Function new_treasury_cap
- Function allow_global_pause
- Function new_coin_metadata
- Function update_coin_metadata
- Function supply
- Function create_regulated_currency
- Function deny_list_add
- Function deny_list_remove
- Function deny_list_contains
use std::address;
use std::ascii;
use std::bcs;
use std::internal;
use std::option;
use std::string;
use std::type_name;
use std::u128;
use std::vector;
use sui::accumulator;
use sui::accumulator_settlement;
use sui::address;
use sui::bag;
use sui::balance;
use sui::bcs;
use sui::config;
use sui::deny_list;
use sui::dynamic_field;
use sui::dynamic_object_field;
use sui::event;
use sui::funds_accumulator;
use sui::hash;
use sui::hex;
use sui::object;
use sui::party;
use sui::protocol_config;
use sui::table;
use sui::transfer;
use sui::tx_context;
use sui::types;
use sui::url;
use sui::vec_map;
use sui::vec_set;
Struct Coin
A coin of type T worth value. Transferable and storable
public struct Coin<phantom T> has key, store
Fields
Struct CoinMetadata
Each Coin type T created through create_currency function will have a
unique instance of CoinMetadata
public struct CoinMetadata<phantom T> has key, store
Fields
- id: sui::object::UID
- decimals: u8
-
Number of decimal places the coin uses.
A coin with value N and decimals D should be shown as N / 10^D.
E.g., a coin with value 7002 and decimals 3 should be displayed as 7.002.
This is metadata for display usage only. - name: std::string::String
- Name for the token
- symbol: std::ascii::String
- Symbol for the token
- description: std::string::String
- Description of the token
- icon_url: std::option::Option<sui::url::Url>
- URL for the token logo
Struct RegulatedCoinMetadata
Similar to CoinMetadata, but created only for regulated coins that use the DenyList.
This object is always immutable.
public struct RegulatedCoinMetadata<phantom T> has key
Fields
- id: sui::object::UID
- coin_metadata_object: sui::object::ID
- The ID of the coin's CoinMetadata object.
- deny_cap_object: sui::object::ID
- The ID of the coin's DenyCap object.
Struct TreasuryCap
Capability allowing the bearer to mint and burn coins of type T. Transferable
public struct TreasuryCap<phantom T> has key, store
Fields
Struct DenyCapV2
Capability allowing the bearer to deny addresses from using the currency's coins--
immediately preventing those addresses from interacting with the coin as an input to a
transaction and at the start of the next preventing them from receiving the coin.
If allow_global_pause is true, the bearer can enable a global pause that behaves as if
all addresses were added to the deny list.
public struct DenyCapV2<phantom T> has key, store
Fields
- id: sui::object::UID
- allow_global_pause: bool
Struct CurrencyCreated
public struct CurrencyCreated<phantom T> has copy, drop
Fields
- decimals: u8
Struct DenyCap
Capability allowing the bearer to freeze addresses, preventing those addresses from interacting with the coin as an input to a transaction.
public struct DenyCap<phantom T> has key, store
Fields
- id: sui::object::UID
Constants
A type passed to create_supply is not a one-time witness.
const EBadWitness: u64 = 0;
Invalid arguments are passed to a function.
const EInvalidArg: u64 = 1;
Trying to split a coin more times than its balance allows.
const ENotEnough: u64 = 2;
const EGlobalPauseNotAllowed: u64 = 3;
The index into the deny list vector for the sui::coin::Coin type.
const DENY_LIST_COIN_INDEX: u64 = 0;
Function total_supply
Return the total number of T's in circulation.
public fun total_supply<T>(cap: &sui::coin::TreasuryCap<T>): u64
Function treasury_into_supply
Unwrap TreasuryCap getting the Supply.
Operation is irreversible. Supply cannot be converted into a TreasuryCap due to different security guarantees (TreasuryCap can be created only once for a type)
public fun treasury_into_supply<T>(treasury: sui::coin::TreasuryCap<T>): sui::balance::Supply<T>
Function supply_immut
Get immutable reference to the treasury's Supply.
public fun supply_immut<T>(treasury: &sui::coin::TreasuryCap<T>): &sui::balance::Supply<T>
Function supply_mut
Get mutable reference to the treasury's Supply.
public fun supply_mut<T>(treasury: &mut sui::coin::TreasuryCap<T>): &mut sui::balance::Supply<T>
Function value
Public getter for the coin's value
public fun value<T>(self: &sui::coin::Coin<T>): u64
Function balance
Get immutable reference to the balance of a coin.
public fun balance<T>(coin: &sui::coin::Coin<T>): &sui::balance::Balance<T>
Function balance_mut
Get a mutable reference to the balance of a coin.
public fun balance_mut<T>(coin: &mut sui::coin::Coin<T>): &mut sui::balance::Balance<T>
Function from_balance
Wrap a balance into a Coin to make it transferable.
public fun from_balance<T>(balance: sui::balance::Balance<T>, ctx: &mut sui::tx_context::TxContext): sui::coin::Coin<T>
Function into_balance
Destruct a Coin wrapper and keep the balance.
public fun into_balance<T>(coin: sui::coin::Coin<T>): sui::balance::Balance<T>
Function take
Take a Coin worth of value from Balance.
Aborts if value > balance.value
public fun take<T>(balance: &mut sui::balance::Balance<T>, value: u64, ctx: &mut sui::tx_context::TxContext): sui::coin::Coin<T>