Skip to main content

bank

Abstract

The x/bank module in Stable SDK only provides basic token management features. Every token can be transferred to any account without any restriction and users cannot delegate other account for transferring their tokens to other accounts. For these reasons, the bank precompiled contract offers additional authorization and delegation features on top of the existing x/bank module in Stable SDK.

Contents

  1. Concepts
  2. Configuration
  3. Methods
  4. Events

Concepts

This precompiled contract provides ERC20 standard methods - such as transfer and balanceOf for transfer and transferFrom, approve and allowance for delegation. These methods can be called directly without requiring the contract address to be registered.

However, mint and burn methods require the contract address to be whitelisted, registered by the x/precompile module.

func (p *Precompile) mint(
ctx sdk.Context,
contract *vm.Contract,
denom string,
method *abi.Method,
stateDB vm.StateDB,
args []interface{},
) ([]byte, error) {
// ...

// mint method is only allowed for the registered caller contract
if _, err := precompilecommon.CheckPermissions(ctx, p.precompileKeeper, contract.CallerAddress, CallerPermissions); err != nil {
return nil, err
}

Additional verification process can guarantee that token contract, calling this precompiled contract, is authorized.

Governance proposal is required to register token contract address and its denom to whitelist in x/precompile module.

Configuration

Contract address and gas cost is predefined.

Contract Address

  • "0x0000000000000000000000000000000000001000" for gas token
  • "0x0000000000000000000000000000000000001003" for governance token

Methods

mint

Mints requested amount of new tokens and transfer to the account. The amount of tokens to be minted must be greater than zero.

PrecompiledBankMint is emitted when the tokens are successfully minted and transferred to the account.

NOTE:

  • Minting governance token minting is prohibited.
  • Caller contracts calling mint method are must be registered in x/precompile module.

Inputs

NameTypeDescription
toaddressthe address to receive the minted tokens
amountuint256the amount of tokens to be minted

Outputs

NameTypeDescription
successbooltrue if the tokens are successfully minted and transferred to the account

burn

Burns requested amount of tokens from the account. The amount of tokens to be burned must be greater than zero.

PrecompiledBankBurn is emitted when the tokens are successfully burned.

NOTE:

  • Burning governance token is prohibited.
  • Caller contracts calling mint method are must be registered in x/precompile module.

Inputs

NameTypeDescription
fromaddressthe address to burn the tokens
amountuint256the amount of tokens to be burned

Outputs

NameTypeDescription
successbooltrue if the tokens are successfully burned

transfer

Transfers requested amount of tokens from sender to the recipient. Token must be set sendable. The amount of tokens to be transferred must be greater than zero.

PrecompiledBankTransfer is emitted when the tokens are successfully transferred.

Inputs

NameTypeDescription
toaddressthe address to receive the tokens
amountuint256the amount of tokens to be transferred

Outputs

NameTypeDescription
successbooltrue if the tokens are successfully transferred

transferFrom

Transfers requested amount of tokens from owner to recipient by authorized spender within the limits of the allowance. Token must be set sendable. The amount of tokens to be transferred must be greater than zero and less than or equal to the current allowance.

PrecompiledBankTransfer is emitted when the tokens are successfully transferred.

Inputs

NameTypeDescription
fromaddressthe address to transfer the tokens
toaddressthe address to receive the tokens
amountuint256the amount of tokens to be transferred

Outputs

NameTypeDescription
successbooltrue if the tokens are successfully transferred

multiTransfer

Transfers tokens from single account to multiple accounts. Token must be set sendable. The amount of tokens to be transferred to each recipient must be greater than zero.

PrecompiledBankTransfer is emitted per each recipient when the tokens are successfully transferred.

Inputs

NameTypeDescription
toaddress[]the addresses to receive the transferred tokens
amountuint256[]the amount of tokens to be transferred to each recipient

Outputs

NameTypeDescription
successbooltrue if the tokens are successfully transferred to each recipient

approve

Authorizes a spender to transfer tokens from the owner’s account. The amount of tokens to be authorized must be greater than zero.

PrecompiledBankApproval is emitted when the authorization is successfully set.

Inputs

NameTypeDescription
spenderaddressthe address to authorize
valueuint256the amount of tokens to be authorized

Outputs

NameTypeDescription
successbooltrue if the authorization is successfully set

revoke

Revokes the authorization of spender for transferring tokens from owner.

PrecompiledBankRevoke is emitted when the authorization is successfully revoked.

Inputs

NameTypeDescription
spenderaddressthe address to revoke

Outputs

NameTypeDescription
successbooltrue if the authorization is successfully revoked

balanceOf

Returns balance of tokens from the account.

Inputs

NameTypeDescription
accountaddressthe address to get the balance of tokens

Outputs

NameTypeDescription
balanceuint256the amount of tokens in the account

totalSupply

Returns total supply of tokens.

Inputs

none

Outputs

NameTypeDescription
totalSupplyuint256the total amount of tokens

allowance

Returns the amount which spender is still allowed to withdraw from owner.

Inputs

NameTypeDescription
owneraddressthe address of the owner
spenderaddressthe address of the spender

Outputs

NameTypeDescription
amountuint256the amount of tokens authorized

Events

All events emitted from this precompiled contract are prefixed with PrecompiledBank. To avoid ambiguity, token contract calling this precompiled contract should avoid using event names with the same prefix.

PrecompiledBankMint

NameTypeIndexedDescription
fromaddressYthe address that minted the tokens
toaddressYthe address to receive the minted tokens
amountuint256Nthe amount of tokens minted

PrecompiledBankBurn

NameTypeIndexedDescription
fromaddressYthe address that burned the tokens
toaddressYnot used in this method
amountuint256Nthe amount of tokens burned

PrecompiledBankTransfer

NameTypeIndexedDescription
fromaddressYthe address that transferred the tokens
toaddressYthe address to receive the transferred tokens
amountuint256Nthe amount of tokens transferred

PrecompiledBankApproval

NameTypeIndexedDescription
owneraddressYthe address that authorized the tokens
spenderaddressYthe address to authorize
valueuint256Nthe amount of tokens authorized

PrecompiledBankRevoke

NameTypeIndexedDescription
owneraddressYthe address that revoked the tokens
spenderaddressYthe address to revoke
valueuint256Nthe amount of tokens authorized