-
Notifications
You must be signed in to change notification settings - Fork 585
-
Context
The cosmos native token ecosystem and EVM ecosystem are disconnected currently, connect these two can make many user cases possible:
- Wrap some ibc tokens in erc20 contract to participate in the evm DeFi applications.
- Move some erc20 tokens to native tokens to enjoy cosmos ecosystem, like, ibc transfer, gravity bridge, gravity dex, etc.
Scenario 1
Wrap an existing native token in an erc20 contract
Module Managed ERC20 Contract
ERC20 contract that is managed by native module:
-
Contract code is builtin and deployed by native module
-
Permissions of mint/burn are granted to the native module only, like this:
require(msg.sender == native_module_address)Security: normal clients can't sign transaction with the private key corresponds to the
native_module_address, only native module can execute transactions with that sender address.
With this, native module can deploy and manage erc20 tokens.
Wrap native token in EVM
The native module provide three types of message:
deploy(denom), native module deploy a standard erc20 contract for the native token, and record the relationship between the native token and the contract address.deposit(denom, amount), user locks some native tokens to the module account, and the module mint equivalent erc20 tokens in the contract.withdraw(denom, amount), the native module burns user's erc20 tokens in the contract, and release equivalent native tokens from module account to user.
Scenario 2
Move existing erc20 token to native token.
We can provide an api to evm smart contract to mint/burn native tokens of bank module.
-
How to ensure ownership?
- the native tokens can be named as
evm/contract_address, and the contract can only manage native tokens with it's own address.
- the native tokens can be named as
-
How is the api called?
-
Precompiled smart contract
- Problem: With current go-ethereum evm implementation, precompiled contract implementation can't access the caller's address.
-
Passing the message by emit a specific log, transaction post processing logic could recognize the log and do the action.
func post_processing(tx) { for log in tx.logs { if log.type == CosmosNativeMint { recipient, amount = abi_decode(log.data) mint(log.address, recipient, amount) } } }
-
The mint API could be like this:
func mint(caller string, amount *big.Int) {
denom := "evm/" + caller
coins := sdk.Coins{sdk.NewCoin(
denom,
sdk.NewIntFromBigInt(amount)
)}
bankKeeper.MintCoins(ctx, types.ModuleName, coins)
bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, msg.sender, coins)
}
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
Orzelo
Beta Was this translation helpful? Give feedback.