zeta-chain / protocol-contracts

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

Refactor `addresses.json` to account for ZRC-20 of ERC-20s #89

Closed fadeev closed 4 months ago

fadeev commented 1 year ago

Currently we have only 1 ZRC-20 per chain:

https://github.com/zeta-chain/protocol-contracts/blob/6005f2247c787ead18857f81717b844c086c9af4/data/addresses.json#L121-L137

On chain "foreign coins":

{
  "foreignCoins": [
    {
      "zrc20_contract_address": "0x0cbe0dF132a6c6B4a2974Fa1b7Fb953CF0Cc798a",
      "asset": "0x07865c6e87b9f70255377e024ace6630c1eaa37f",
      "foreign_chain_id": "5",
      "decimals": 6,
      "name": "USDC-goerli_testnet",
      "symbol": "USDC",
      "coin_type": "ERC20",
      "gas_limit": "100000",
      "paused": false
    },
    {
      "zrc20_contract_address": "0x13A0c5930C028511Dc02665E7285134B6d11A5f4",
      "asset": "",
      "foreign_chain_id": "5",
      "decimals": 18,
      "name": "ETH-goerli_testnet",
      "symbol": "gETH",
      "coin_type": "Gas",
      "gas_limit": "21000",
      "paused": false
    },
    {
      "zrc20_contract_address": "0x48f80608B672DC30DC7e3dbBd0343c5F02C738Eb",
      "asset": "",
      "foreign_chain_id": "80001",
      "decimals": 18,
      "name": "MATIC-mumbai_testnet",
      "symbol": "tMATIC",
      "coin_type": "Gas",
      "gas_limit": "21000",
      "paused": false
    },
    {
      "zrc20_contract_address": "0x65a45c57636f9BcCeD4fe193A602008578BcA90b",
      "asset": "",
      "foreign_chain_id": "18332",
      "decimals": 8,
      "name": "BTC-btc_testnet-btc_testnet",
      "symbol": "tBTC",
      "coin_type": "Gas",
      "gas_limit": "100",
      "paused": false
    },
    {
      "zrc20_contract_address": "0x7c8dDa80bbBE1254a7aACf3219EBe1481c6E01d7",
      "asset": "0x64544969ed7EBf5f083679233325356EbE738930",
      "foreign_chain_id": "97",
      "decimals": 6,
      "name": "USDC-bsc_testnet",
      "symbol": "USDC",
      "coin_type": "ERC20",
      "gas_limit": "100000",
      "paused": false
    },
    {
      "zrc20_contract_address": "0x91d4F0D54090Df2D81e834c3c8CE71C6c865e79F",
      "asset": "0x9999f7fea5938fd3b1e26a12c3f2fb024e194f97",
      "foreign_chain_id": "80001",
      "decimals": 6,
      "name": "USDC-mumbai_testnet",
      "symbol": "USDC",
      "coin_type": "ERC20",
      "gas_limit": "100000",
      "paused": false
    },
    {
      "zrc20_contract_address": "0xd97B1de3619ed2c6BEb3860147E30cA8A7dC9891",
      "asset": "",
      "foreign_chain_id": "97",
      "decimals": 18,
      "name": "BNB-bsc_testnet",
      "symbol": "tBNB",
      "coin_type": "Gas",
      "gas_limit": "21000",
      "paused": false
    }
  ],
  "pagination": {
    "next_key": null,
    "total": "7"
  }
}

Source: https://zetachain-athens.blockpi.network/lcd/v1/public/zeta-chain/zetacore/fungible/foreign_coins

cc @lucas-janon @andresaiello

fadeev commented 1 year ago

We also probably need a convention to label tokens from different chains. For example, when using the swap example you want swap USDC for gETH on Goerli:

px hardhat interact --contract ADDRESS --amount 0.05 --denom usdc --target-token eth --network goerli_testnet --recipient ADDRESS --destination mumbai_testnet

If there is no denom (usdc) we can default to native gas token.

fadeev commented 1 year ago

If we ever need to specify both a chain and a token, we can do something like goerli_testnet:usdc.

fadeev commented 1 year ago

Should we do something like:

"zevm": {
  "goerli_testnet": {
    "zrc20": [
      {
        "symbol": "gETH",
        "zrc20_contract_address": "0x13A0c5930C028511Dc02665E7285134B6d11A5f4"
      },
      {
        "symbol": "USDC",
        "zrc20_contract_address": "0x0cbe0dF132a6c6B4a2974Fa1b7Fb953CF0Cc798a"
      }
    ]
  },
}

Using the structure from the foreign coins API for consistency.

fadeev commented 10 months ago

@andresaiello @lucas-janon I really think we should start thinking about a new structure for addresses.json. USDC addresses are currently missing from the JSON and this forces people to get addresses directly from chain's API.

fadeev commented 10 months ago

How about simplifying the structure:

[
  {
    "chain": "goerli_testnet",
    "type": "zetaToken",
    "address": "0x5b1869D9A4C187F2EAa108f3062412ecf0526b24",
    "category": "messaging"
  },
  {
    "chain": "goerli_testnet",
    "type": "tss",
    "address": "0x5b1869D9A4C187F2EAa108f3062412ecf0526b24",
    "category": "omnichain"
  },
  {
    "chain": "zeta_testnet",
    "type": "zrc20",
    "symbol": "USDC",
    "address": "0x5b1869D9A4C187F2EAa108f3062412ecf0526b24",
    "category": "omnichain"
  },
  {
    "chain": "zeta_testnet",
    "type": "zrc20",
    "symbol": "gETH",
    "address": "0x5b1869D9A4C187F2EAa108f3062412ecf0526b24",
    "category": "omnichain"
  }
]

A flat array structure will let us add more metadata to addresses if needed.

getAddress(chain, type, symbol = null)

Symbol is optional, this way the function is backwards compatible.

getAddress("mumbai_tesnet", "tss")
getAddress("zeta_tesnet", "zrc20", "usdc")

The following will throw an error and we can make the error very discriptive by listing all valid options calculated automatically from the JSON:

getAddress("zeta_tesnet", "zrc20")
Error: please, specify symbol (for example, "usdc", "geth", "tmatic", "tbnb", "tbsc")

We can also run a script to validate the JSON and generate the types from it as well.

fadeev commented 9 months ago

@lucas-janon @andresaiello please, provide feedback on this! We still don't have USDC in our JSON ‼️

andresaiello commented 9 months ago

I think we can have two models, tokens and non tokens. For tokens I like

{
      "zrc20_contract_address": "0x91d4F0D54090Df2D81e834c3c8CE71C6c865e79F",
      "asset": "0x9999f7fea5938fd3b1e26a12c3f2fb024e194f97",
      "foreign_chain_id": "80001",
      "decimals": 6,
      "name": "USDC-mumbai_testnet",
      "symbol": "USDC",
      "coin_type": "ERC20",
      "gas_limit": "100000",
      "paused": false
    },

but for non tokens has a lot of extra info that will be always empty (like for tss etc) and for those we can use the simplify model

fadeev commented 9 months ago

@andresaiello but they will still be in a single array like so, right?

  {
    "chain": "goerli_testnet",
    "type": "tss",
    "address": "0x5b1869D9A4C187F2EAa108f3062412ecf0526b24",
    "category": "omnichain"
  },
  {
    "zrc20_contract_address": "0x91d4F0D54090Df2D81e834c3c8CE71C6c865e79F",
    "asset": "0x9999f7fea5938fd3b1e26a12c3f2fb024e194f97",
    "foreign_chain_id": "80001",
    "decimals": 6,
    "name": "USDC-mumbai_testnet",
    "symbol": "USDC",
    "coin_type": "ERC20",
    "gas_limit": "100000",
    "paused": false
  },
fadeev commented 9 months ago

I've updated the script and now it generates addresses in the updated format:

https://github.com/zeta-chain/protocol-contracts/pull/10#issuecomment-1884748662