zeta-chain / protocol-contracts

Protocol contracts implementing the core logic of the protocol, deployed on ZetaChain and on connected chains
MIT License
70 stars 58 forks source link

Extend Zrc-20 to different connected chain. #110

Closed magj2006 closed 11 months ago

magj2006 commented 11 months ago

A request likes that I want to transfer ETH from goerli to BSC, it's can't as far now. but I think these requests are very common, vast. current design is a zrc-20 remapping to gas coin, as a zrc-20 A remapping to ETH on goerli, and a zrc-20 B remapping to Matic on Mumbai. but A isn't on Mumbai. so I can transfer A only between goerli and zetaChain. this is not good. is it possible to create zrc-20 A on all connected chain? if do this, user can transfer zrc-20 among all connected chain, no need to swap.

fadeev commented 11 months ago

That's not exactly how ZRC-20 works. By design ZRC-20 only exists on ZetaChain as a wrapped representation of assets from connected chains.

What you're saying (transferring ETH from Goerli to BSC, for example) can be accomplished by whitelisting an ERC-20 token on BSC that will represent ETH. BSC already has a canonical ETH token, so we can use that.

Once whitelisted, users will be able to move ETH from Goerli to BSC. The process will be the same as it is right now: ETH is deposited as ZRC-20 to ZetaChain, Goerli ETH ZRC-20 is swapped for BSC ETH ZRC-20, then BSC ETH is withdrawn to BSC as this canonical ETH ERC-20 token that is meant to represent the actual ETH.

magj2006 commented 11 months ago

That's not exactly how ZRC-20 works. By design ZRC-20 only exists on ZetaChain as a wrapped representation of assets from connected chains.

What you're saying (transferring ETH from Goerli to BSC, for example) can be accomplished by whitelisting an ERC-20 token on BSC that will represent ETH. BSC already has a canonical ETH token, so we can use that.

Once whitelisted, users will be able to move ETH from Goerli to BSC. The process will be the same as it is right now: ETH is deposited as ZRC-20 to ZetaChain, Goerli ETH ZRC-20 is swapped for BSC ETH ZRC-20, then BSC ETH is withdrawn to BSC as this canonical ETH ERC-20 token that is meant to represent the actual ETH.

Thank you for your explanation. I was wrong to understand zrc-20. as you said how do I withdraw BSC ETH zrc-20 if I deposit Goerli ETH. Is there an example?

fadeev commented 11 months ago

There is a whole tutorial dedicated to that:

https://www.zetachain.com/docs/developers/omnichain/tutorials/swap/

magj2006 commented 11 months ago

There is a whole tutorial dedicated to that:

https://www.zetachain.com/docs/developers/omnichain/tutorials/swap/

Yeah, I already practiced this tutorial, It does not satisfy my requirement. I mean if transfer same one asset among all connected chain, it should not be swapped, otherwise there will be slippage.

fadeev commented 11 months ago

Oh, you mean deposit Goerli ETH and withdraw wrapped ETH to BSC. Currently, not possible, because "wrapped ETH" is not one of the whitelisted tokens. You can find whitelisted tokens here: https://www.zetachain.com/docs/developers/omnichain/zrc-20/

Also, even if you want gETH -> wETH there will be a swap between ZRC-20 versions of these assets on ZetaChain. You can't put it one asset and withdraw another one (even if it's a wrapped version of the same asset) without swapping.

magj2006 commented 11 months ago

Oh, you mean deposit Goerli ETH and withdraw wrapped ETH to BSC. Currently, not possible, because "wrapped ETH" is not one of the whitelisted tokens. You can find whitelisted tokens here: https://www.zetachain.com/docs/developers/omnichain/zrc-20/

Also, even if you want gETH -> wETH there will be a swap between ZRC-20 versions of these assets on ZetaChain. You can't put it one asset and withdraw another one (even if it's a wrapped version of the same asset) without swapping.

What are your considerations for this design? If swap is necessary in this way, there will definitely be slippage here. I think if the zrc-20 to same one asset be unique, then there no need to swap when transfer to each other, and using 1:1 to move. the whitelist as below show: { ...

   {

        "asset": "",
        "coin_type": "Gas",
        "decimals": 18,
        "foreign_chain_id": "5",
        "gas_limit": "21000",
        "liquidity_cap": "0",
        "name": "ETH-goerli_testnet",
        "paused": false,
        "symbol": "gETH",
        "zrc20_contract_address": "0x13A0c5930C028511Dc02665E7285134B6d11A5f4"
    },

   {
        "asset": "0xabcd....",
        "coin_type": "ERC20",
        "decimals": 18,
        "foreign_chain_id": "97",
        "gas_limit": "21000",
        "liquidity_cap": "0",
        "name": "ETH-bsc_testnet",
        "paused": false,
        "symbol": "wETH",
        "zrc20_contract_address": "0x13A0c5930C028511Dc02665E7285134B6d11A5f4"
    },

... }

fadeev commented 11 months ago

Amount of each ZRC-20 corresponds to the amount of tokens locked in a TSS address/ERC-20 custody contract on the corresponding chain. This guarantees that at any point in time it's possible to withdraw all ZRC-20 tokens.

Let's say 100 gETH and 100 BSC wETH are deposited in total and are represented as the same ZRC-20 token. Now a user wants to withdraw 200 ZRC-20 ETH. They can't withdraw to Goerli the whole amount, because there is only 100 gETH locked in the TSS address.

fadeev commented 11 months ago

Also, even though we might consider ETH and BSC wETH to be the same token, they really are not. They are secured by different chains. Let's say if chain Foo launches and it also has wETH, do we also consider to be equal to Ethereum's ETH, probably, not.

magj2006 commented 11 months ago

Also, even though we might consider ETH and BSC wETH to be the same token, they really are not. They are secured by different chains. Let's say if chain Foo launches and it also has wETH, do we also consider to be equal to Ethereum's ETH, probably, not.

you are right. Have we considered adding only a small number of assets, especially gasCoin, which can be transferred smoothly on connected chains, just like we are doing with USDC now.

fadeev commented 11 months ago

@magj2006 I don't really see the problem provided that there is enough liqudity in the pools.

magj2006 commented 11 months ago

thank you.