Hooks
The erc20 module implements transaction hooks from the EVM in order to trigger token pair conversion.
EVM Hooks
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.
Registered Coin: ERC20 to Coin
User transfers ERC20 tokens to the
ModuleAccount
address to escrow themCheck if the ERC20 Token that was transferred from the sender is a native ERC20 or a native Cosmos Coin by looking at the Ethereum event logs
If the token contract address corresponds to the ERC20 representation of a native Cosmos Coin
Call
burn()
ERC20 method from theModuleAccount
. 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 callingburnFrom()
. Also note that we don't need to mint because 1.1 coin to erc20 escrows the coinTransfer Cosmos Coin to the bech32 account address of the sender hex address
Registered ERC20: ERC20 to Coin
User transfers coins to the
ModuleAccount
to escrow themCheck 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