starcoin-framework

Module 0x1::MintDaoProposal

MintDaoProposal is a dao proposal for mint extra tokens.

use 0x1::Account;
use 0x1::Dao;
use 0x1::Errors;
use 0x1::Signer;
use 0x1::Token;

Resource WrappedMintCapability

A wrapper of Token MintCapability.

struct WrappedMintCapability<TokenType> has key
Fields
cap: Token::MintCapability<TokenType>

Struct MintToken

MintToken request.

struct MintToken has copy, drop, store
Fields
receiver: address
the receiver of minted tokens.
amount: u128
how many tokens to mint.

Constants

const ERR_NOT_AUTHORIZED: u64 = 401;

Function plugin

Plugin method of the module. Should be called by token issuer.

public fun plugin<TokenT: store>(signer: &signer)
Implementation
public fun plugin<TokenT: store>(signer: &signer) {
    let token_issuer = Token::token_address<TokenT>();
    assert!(Signer::address_of(signer) == token_issuer, Errors::requires_address(ERR_NOT_AUTHORIZED));
    let mint_cap = Token::remove_mint_capability<TokenT>(signer);
    move_to(signer, WrappedMintCapability { cap: mint_cap });
}
Specification
pragma aborts_if_is_partial = false;
let sender = Signer::address_of(signer);
aborts_if sender != Token::SPEC_TOKEN_TEST_ADDRESS();
aborts_if !exists<Token::MintCapability<TokenT>>(sender);
aborts_if exists<WrappedMintCapability<TokenT>>(sender);
ensures !exists<Token::MintCapability<TokenT>>(sender);
ensures exists<WrappedMintCapability<TokenT>>(sender);

Function propose_mint_to

Entrypoint for the proposal.

public fun propose_mint_to<TokenT: copy, drop, store>(signer: &signer, receiver: address, amount: u128, exec_delay: u64)
Implementation
public fun propose_mint_to<TokenT: copy + drop + store>(signer: &signer, receiver: address, amount: u128, exec_delay: u64) {
    Dao::propose<TokenT, MintToken>(
        signer,
        MintToken { receiver, amount },
        exec_delay,
    );
}
Specification
pragma aborts_if_is_partial = false;
include Dao::AbortIfDaoConfigNotExist<TokenT>;
include Dao::AbortIfDaoInfoNotExist<TokenT>;
aborts_if !exists<Timestamp::CurrentTimeMilliseconds>(CoreAddresses::SPEC_GENESIS_ADDRESS());
aborts_if exec_delay > 0 && exec_delay < Dao::spec_dao_config<TokenT>().min_action_delay;
include Dao::CheckQuorumVotes<TokenT>;
let sender = Signer::address_of(signer);
aborts_if exists<Dao::Proposal<TokenT, MintToken>>(sender);

Function execute_mint_proposal

Once the proposal is agreed, anyone can call the method to make the proposal happen.

public fun execute_mint_proposal<TokenT: copy, drop, store>(proposer_address: address, proposal_id: u64)
Implementation
public fun execute_mint_proposal<TokenT: copy + drop + store>(
    proposer_address: address,
    proposal_id: u64,
) acquires WrappedMintCapability {
    let MintToken { receiver, amount } = Dao::extract_proposal_action<TokenT, MintToken>(
        proposer_address,
        proposal_id,
    );
    let cap = borrow_global<WrappedMintCapability<TokenT>>(Token::token_address<TokenT>());
    let tokens = Token::mint_with_capability<TokenT>(&cap.cap, amount);
    Account::deposit(receiver, tokens);
}
Specification
pragma aborts_if_is_partial = true;
let expected_states = vec<u8>(6);
include Dao::CheckProposalStates<TokenT, MintToken>{expected_states};
let proposal = global<Dao::Proposal<TokenT, MintToken>>(proposer_address);
aborts_if Option::is_none(proposal.action);
aborts_if !exists<WrappedMintCapability<TokenT>>(Token::SPEC_TOKEN_TEST_ADDRESS());

Module Specification

pragma verify = false;
pragma aborts_if_is_strict;
pragma aborts_if_is_partial;