Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Apr 4, 2024. It is now read-only.

Connect EVM with native tokens #392

yihuang started this conversation in Ideas
Discussion options

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.
  • 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)
}
You must be logged in to vote

Replies: 1 comment

Comment options

Orzelo

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /