starcoin-framework

Module 0x1::STC

STC is the token of Starcoin blockchain. It uses apis defined in the Token module.

use 0x1::ConsensusConfig;
use 0x1::CoreAddresses;
use 0x1::Dao;
use 0x1::ModifyDaoConfigProposal;
use 0x1::OnChainConfigDao;
use 0x1::PackageTxnManager;
use 0x1::RewardConfig;
use 0x1::Token;
use 0x1::TransactionPublishOption;
use 0x1::TransactionTimeoutConfig;
use 0x1::Treasury;
use 0x1::UpgradeModuleDaoProposal;
use 0x1::VMConfig;

Struct STC

STC token marker.

struct STC has copy, drop, store
Fields
dummy_field: bool

Resource SharedBurnCapability

Burn capability of STC.

struct SharedBurnCapability has store, key
Fields
cap: Token::BurnCapability<STC::STC>

Constants

precision of STC token.

const PRECISION: u8 = 9;

Function initialize

STC initialization.

public fun initialize(account: &signer, voting_delay: u64, voting_period: u64, voting_quorum_rate: u8, min_action_delay: u64)
Implementation
public fun initialize(
    account: &signer,
    voting_delay: u64,
    voting_period: u64,
    voting_quorum_rate: u8,
    min_action_delay: u64,
) {
    Token::register_token<STC>(account, PRECISION);
    let burn_cap = Token::remove_burn_capability<STC>(account);
    move_to(account, SharedBurnCapability { cap: burn_cap });
    Dao::plugin<STC>(
        account,
        voting_delay,
        voting_period,
        voting_quorum_rate,
        min_action_delay,
    );
    ModifyDaoConfigProposal::plugin<STC>(account);
    let upgrade_plan_cap = PackageTxnManager::extract_submit_upgrade_plan_cap(account);
    UpgradeModuleDaoProposal::plugin<STC>(
        account,
        upgrade_plan_cap,
    );
    // the following configurations are gov-ed by Dao.
    OnChainConfigDao::plugin<STC, TransactionPublishOption::TransactionPublishOption>(account);
    OnChainConfigDao::plugin<STC, VMConfig::VMConfig>(account);
    OnChainConfigDao::plugin<STC, ConsensusConfig::ConsensusConfig>(account);
    OnChainConfigDao::plugin<STC, RewardConfig::RewardConfig>(account);
    OnChainConfigDao::plugin<STC, TransactionTimeoutConfig::TransactionTimeoutConfig>(account);
}
Specification
include Token::RegisterTokenAbortsIf<STC>{precision: PRECISION};

Function upgrade_from_v1_to_v2

public fun upgrade_from_v1_to_v2(account: &signer, total_amount: u128): Treasury::WithdrawCapability<STC::STC>
Implementation
public fun upgrade_from_v1_to_v2(account: &signer,total_amount: u128,): Treasury::WithdrawCapability<STC> {
    CoreAddresses::assert_genesis_address(account);

    // Mint all stc, and destroy mint capability
    let total_stc = Token::mint<STC>(account, total_amount-Token::market_cap<STC>());
    let withdraw_cap = Treasury::initialize(account, total_stc);
    let mint_cap = Token::remove_mint_capability<STC>(account);
    Token::destroy_mint_capability(mint_cap);
    withdraw_cap
}
Specification
pragma verify = false;

Function initialize_v2

STC initialization.

public fun initialize_v2(account: &signer, total_amount: u128, voting_delay: u64, voting_period: u64, voting_quorum_rate: u8, min_action_delay: u64): Treasury::WithdrawCapability<STC::STC>
Implementation
public fun initialize_v2(
    account: &signer,
    total_amount: u128,
    voting_delay: u64,
    voting_period: u64,
    voting_quorum_rate: u8,
    min_action_delay: u64,
): Treasury::WithdrawCapability<STC> {
    Token::register_token<STC>(account, PRECISION);

    // Mint all stc, and destroy mint capability

    let total_stc = Token::mint<STC>(account, total_amount);
    let withdraw_cap = Treasury::initialize(account, total_stc);
    let mint_cap = Token::remove_mint_capability<STC>(account);
    Token::destroy_mint_capability(mint_cap);

    let burn_cap = Token::remove_burn_capability<STC>(account);
    move_to(account, SharedBurnCapability { cap: burn_cap });
    Dao::plugin<STC>(
        account,
        voting_delay,
        voting_period,
        voting_quorum_rate,
        min_action_delay,
    );
    ModifyDaoConfigProposal::plugin<STC>(account);
    let upgrade_plan_cap = PackageTxnManager::extract_submit_upgrade_plan_cap(account);
    UpgradeModuleDaoProposal::plugin<STC>(
        account,
        upgrade_plan_cap,
    );
    // the following configurations are gov-ed by Dao.
    OnChainConfigDao::plugin<STC, TransactionPublishOption::TransactionPublishOption>(account);
    OnChainConfigDao::plugin<STC, VMConfig::VMConfig>(account);
    OnChainConfigDao::plugin<STC, ConsensusConfig::ConsensusConfig>(account);
    OnChainConfigDao::plugin<STC, RewardConfig::RewardConfig>(account);
    OnChainConfigDao::plugin<STC, TransactionTimeoutConfig::TransactionTimeoutConfig>(account);
    withdraw_cap
}
Specification
include Token::RegisterTokenAbortsIf<STC>{precision: PRECISION};

Function is_stc

Returns true if TokenType is STC::STC

public fun is_stc<TokenType: store>(): bool
Implementation
public fun is_stc<TokenType: store>(): bool {
    Token::is_same_token<STC, TokenType>()
}
Specification

Function burn

Burn STC tokens. It can be called by anyone.

public fun burn(token: Token::Token<STC::STC>)
Implementation
public fun burn(token: Token<STC>) acquires SharedBurnCapability {
    let cap = borrow_global<SharedBurnCapability>(token_address());
    Token::burn_with_capability(&cap.cap, token);
}
Specification
aborts_if Token::spec_abstract_total_value<STC>() - token.value < 0;
aborts_if !exists<SharedBurnCapability>(Token::SPEC_TOKEN_TEST_ADDRESS());

Function token_address

Return STC token address.

public fun token_address(): address
Implementation
public fun token_address(): address {
    Token::token_address<STC>()
}
Specification

Module Specification

pragma verify = false;
pragma aborts_if_is_strict = true;