Messages
In this section we describe the processing of theerc20 module messages and the corresponding updates to the state.
Create Token Pair: MsgCreateTokenPair
Creates an association between existing bank denom and new or existing ERC20 smart contract.
If ERC20 address is empty, new ERC20 smart contract will be instantiated. Not all bank denoms are supported.
Validation rules:
- for tokenfactory denoms, only the denom admin or the governance authority can create a token pair
- for peggy and IBC denoms, anyone can create a token pair, and the ERC20 address must be empty
- Validation checks:
- No token pair already exists for the bank denom or for the ERC20 address
- Provided bank denom exists and has nonzero supply, otherwise
ErrUnknownBankDenom - Sender has permission to create a token pair for this denom (for a tokenfactory denom, the denom admin or the governance authority)
- If an ERC20 address is provided:
- check that the account exists and holds contract code
- check that the derived
erc20:0x...denom has neither circulating supply nor bank metadata, otherwiseErrExistingERC20DenomSupply - check that the contract is an ERC20 by invoking its
symbol()method under a 300,000 gas cap
- Create the association depending on the bank denom type:
- tokenfactory denom:
- read the permissions namespace, if one exists, and check whether the MINT, BURN or SUPER_BURN policy is disabled
- if any of the three is disabled, instantiate a new
FixedSupplyBankERC20and reject any provided ERC20 address - otherwise, if no ERC20 address is provided, instantiate a new
MintBurnBankERC20owned by the message sender, or use the provided address - store the association
- IBC and peggy denoms:
- instantiate new
FixedSupplyBankERC20smart contract - store the association
- instantiate new
- tokenfactory denom:
The
ErrExistingERC20DenomSupply check covers supply or metadata, despite what the error name suggests. A custom contract whose constructor called setMetadata has already written erc20:0x... metadata and will be rejected even with zero supply. See
ERC20 Module for the full set of requirements on custom contracts.