Hooks
The erc20 module implements two transaction hooks from the EVM and Governance modules
# EVM Hooks
👉 Purpose: Allow for 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.
# Registered Coin: ERC20 to Coin
- User transfers ERC20 tokens to the
ModuleAccountaddress to escrow (lock) - Check if the ERC20 Token that was transferred from the sender is a native ERC20 or a native cosmos coin by looking at the ethereum Logs
- If the token contract address is corresponds to the ERC20 representation of a native Cosmos Coin
- Call
burn()ERC20 method from theModuleAccount- NOTE: 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() - NOTE: We don't need to mint because (1.1) escrows the coin
- NOTE: 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
- Transfer Cosmos Coin to the bech32 account address of the sender hex address (1.)
- Call
# Registered ERC20: ERC20 to Coin
- User transfers coins to the Module Account to escrow (lock)
- 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 (1.)
# Governance Hooks
👉 Purpose: speed up the approval process of a token pair registration by defining a custom VotingPeriod duration for the RegisterCoinProposal and RegisterERC20Proposal.
# Overwriting the Voting Period
By Implementing the GovHooks (opens new window) Interface from the Cosmos-SDK, the voting period for all proposals of the ERC20 module can be customized using the AfterProposalDeposit hook.
- Set the voting period on the erc20 module parameters at genesis or through governance
- Submit a new governance proposal, e.g.
RegisterERC20Proposal - The
AfterProposalDeposithook is automatically called and overrides the voting period for all proposals to the value defined on the erc20 module parameters.