The erc20 module implements transaction hooks from the EVM in order to trigger token pair conversion.
The EVM hooks allows users to convert ERC20s to Cosmos Coins by sending an Ethereum tx transfer to the module account address. This enables native conversion of tokens via Metamask and EVM-enabled wallets for both token pairs that have been registered through a native Cosmos coin or an ERC20 token.
Note that additional coin/token balance checks for sender and receiver to prevent malicious contract behaviour (as performed in the ConvertERC20
msg) cannot be done here, as the balance prior to the transaction is not avaialble in the hook.
User transfers ERC20 tokens to the ModuleAccount
address to escrow them
Check if the ERC20 Token that was transferred from the sender is a native ERC20 or a native Cosmos Coin by looking at the
If the token contract address corresponds to the ERC20 representation of a native Cosmos Coin
Call burn()
ERC20 method from the ModuleAccount
. Note that this is the same as 1.2, but since the tokens are already on the ModuleAccount balance, we burn the tokens from the module address instead of calling burnFrom()
. Also note that we don't need to mint because 1.1 coin to erc20 escrows the coin
Transfer Cosmos Coin to the bech32 account address of the sender hex address
User transfers coins to theModuleAccount
to escrow them
Check if the ERC20 Token that was transferred is a native ERC20 or a native cosmos coin
If the token contract address is a native ERC20 token
Mint Cosmos Coin
Transfer Cosmos Coin to the bech32 account address of the sender hex