Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fetch addresses from chain #10

Merged
merged 31 commits into from
Feb 22, 2024
Merged

feat: fetch addresses from chain #10

merged 31 commits into from
Feb 22, 2024

Conversation

fadeev
Copy link
Member

@fadeev fadeev commented May 7, 2023

await fetchForeignCoinsData(chainObject);
await fetchAthensAddresses(chainObject, hre);

console.log(JSON.stringify(chainObject, null, 2));
Copy link
Collaborator

@andresaiello andresaiello May 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

those functions are great, but maybe should be in another file and exported alone, so you can use the task or import the function to use it programmatically

@fadeev fadeev requested a review from andresaiello June 13, 2023 17:00
@fadeev fadeev closed this Jun 15, 2023
@fadeev fadeev reopened this Jan 10, 2024
@fadeev fadeev marked this pull request as draft January 10, 2024 07:18
Copy link

socket-security bot commented Jan 10, 2024

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@zetachain/[email protected] Transitive: environment, filesystem +1 105 kB aaiello, gmaiolozeta, lucasjanon, ...2 more
npm/[email protected] network Transitive: environment, filesystem +8 2.18 MB jasonsaayman
npm/[email protected] network 0 29.4 kB rubenverborgh

🚮 Removed packages: npm/@zetachain/[email protected]

View full report↗︎

@fadeev
Copy link
Member Author

fadeev commented Jan 10, 2024

Updated the script. It now produces an array of addresses in an updated format:

[
  {
    "chain_id": "18332",
    "chain_name": "btc_testnet",
    "type": "tss",
    "category": "omnichain",
    "address": "bcrt1qy9pqmk2pd9sv63g27jt8r657wy0d9uee4x2dt2"
  },
  {
    "chain_id": "80001",
    "chain_name": "mumbai_testnet",
    "type": "tss",
    "category": "omnichain",
    "address": "0x8531a5aB847ff5B22D855633C25ED1DA3255247e"
  },
  {
    "chain_id": "97",
    "chain_name": "bsc_testnet",
    "type": "tss",
    "category": "omnichain",
    "address": "0x8531a5aB847ff5B22D855633C25ED1DA3255247e"
  },
  {
    "chain_id": "5",
    "chain_name": "goerli_testnet",
    "type": "tss",
    "category": "omnichain",
    "address": "0x8531a5aB847ff5B22D855633C25ED1DA3255247e"
  },
  {
    "chain_id": 7001,
    "chain_name": "zeta_testnet",
    "type": "systemContract",
    "category": "omnichain",
    "address": "0xEdf1c3275d13489aCdC6cD6eD246E72458B8795B"
  },
  {
    "chain_id": 7001,
    "chain_name": "zeta_testnet",
    "type": "connectorZEVM",
    "category": "messaging",
    "address": "0x239e96c8f17C85c30100AC26F635Ea15f23E9c67"
  },
  {
    "chain_id": "5",
    "chain_name": "goerli_testnet",
    "coin_type": "ERC20",
    "address": "0x07865c6e87b9f70255377e024ace6630c1eaa37f",
    "symbol": "USDC",
    "zrc20": "0x0cbe0dF132a6c6B4a2974Fa1b7Fb953CF0Cc798a",
    "category": "omnichain",
    "decimals": 6
  },
  {
    "chain_id": 7001,
    "chain_name": "zeta_testnet",
    "coin_type": "ZRC20",
    "address": "0x0cbe0dF132a6c6B4a2974Fa1b7Fb953CF0Cc798a",
    "symbol": "USDC-goerli_testnet",
    "asset": "0x07865c6e87b9f70255377e024ace6630c1eaa37f",
    "category": "omnichain",
    "decimals": 18
  },
  {
    "chain_id": "5",
    "chain_name": "goerli_testnet",
    "coin_type": "Gas",
    "address": "",
    "symbol": "gETH",
    "zrc20": "0x13A0c5930C028511Dc02665E7285134B6d11A5f4",
    "category": "omnichain",
    "decimals": 18
  },
  {
    "chain_id": 7001,
    "chain_name": "zeta_testnet",
    "coin_type": "ZRC20",
    "address": "0x13A0c5930C028511Dc02665E7285134B6d11A5f4",
    "symbol": "ETH-goerli_testnet",
    "asset": "",
    "category": "omnichain",
    "decimals": 18
  },
  {
    "chain_id": "80001",
    "chain_name": "mumbai_testnet",
    "coin_type": "Gas",
    "address": "",
    "symbol": "tMATIC",
    "zrc20": "0x48f80608B672DC30DC7e3dbBd0343c5F02C738Eb",
    "category": "omnichain",
    "decimals": 18
  },
  {
    "chain_id": 7001,
    "chain_name": "zeta_testnet",
    "coin_type": "ZRC20",
    "address": "0x48f80608B672DC30DC7e3dbBd0343c5F02C738Eb",
    "symbol": "MATIC-mumbai_testnet",
    "asset": "",
    "category": "omnichain",
    "decimals": 18
  },
  {
    "chain_id": "18332",
    "chain_name": "btc_testnet",
    "coin_type": "Gas",
    "address": "",
    "symbol": "tBTC",
    "zrc20": "0x65a45c57636f9BcCeD4fe193A602008578BcA90b",
    "category": "omnichain",
    "decimals": 8
  },
  {
    "chain_id": 7001,
    "chain_name": "zeta_testnet",
    "coin_type": "ZRC20",
    "address": "0x65a45c57636f9BcCeD4fe193A602008578BcA90b",
    "symbol": "BTC-btc_testnet-btc_testnet",
    "asset": "",
    "category": "omnichain",
    "decimals": 18
  },
  {
    "chain_id": "97",
    "chain_name": "bsc_testnet",
    "coin_type": "ERC20",
    "address": "0x64544969ed7EBf5f083679233325356EbE738930",
    "symbol": "USDC",
    "zrc20": "0x7c8dDa80bbBE1254a7aACf3219EBe1481c6E01d7",
    "category": "omnichain",
    "decimals": 6
  },
  {
    "chain_id": 7001,
    "chain_name": "zeta_testnet",
    "coin_type": "ZRC20",
    "address": "0x7c8dDa80bbBE1254a7aACf3219EBe1481c6E01d7",
    "symbol": "USDC-bsc_testnet",
    "asset": "0x64544969ed7EBf5f083679233325356EbE738930",
    "category": "omnichain",
    "decimals": 18
  },
  {
    "chain_id": "80001",
    "chain_name": "mumbai_testnet",
    "coin_type": "ERC20",
    "address": "0x9999f7fea5938fd3b1e26a12c3f2fb024e194f97",
    "symbol": "USDC",
    "zrc20": "0x91d4F0D54090Df2D81e834c3c8CE71C6c865e79F",
    "category": "omnichain",
    "decimals": 6
  },
  {
    "chain_id": 7001,
    "chain_name": "zeta_testnet",
    "coin_type": "ZRC20",
    "address": "0x91d4F0D54090Df2D81e834c3c8CE71C6c865e79F",
    "symbol": "USDC-mumbai_testnet",
    "asset": "0x9999f7fea5938fd3b1e26a12c3f2fb024e194f97",
    "category": "omnichain",
    "decimals": 18
  },
  {
    "chain_id": "97",
    "chain_name": "bsc_testnet",
    "coin_type": "Gas",
    "address": "",
    "symbol": "tBNB",
    "zrc20": "0xd97B1de3619ed2c6BEb3860147E30cA8A7dC9891",
    "category": "omnichain",
    "decimals": 18
  },
  {
    "chain_id": 7001,
    "chain_name": "zeta_testnet",
    "coin_type": "ZRC20",
    "address": "0xd97B1de3619ed2c6BEb3860147E30cA8A7dC9891",
    "symbol": "BNB-bsc_testnet",
    "asset": "",
    "category": "omnichain",
    "decimals": 18
  },
  {
    "chain_id": 7001,
    "chain_name": "zeta_testnet",
    "category": "omnichain",
    "type": "uniswapv2FactoryAddress",
    "address": "0x9fd96203f7b22bCF72d9DCb40ff98302376cE09c"
  },
  {
    "chain_id": 7001,
    "chain_name": "zeta_testnet",
    "category": "omnichain",
    "type": "wZetaContractAddress",
    "address": "0x5F0b1a82749cb4E2278EC87F8BF6B618dC71a8bf"
  },
  {
    "chain_id": 7001,
    "chain_name": "zeta_testnet",
    "category": "omnichain",
    "type": "uniswapv2Router02Address",
    "address": "0x2ca7d64A7EFE2D62A725E2B35Cf7230D6677FfEe"
  },
  {
    "chain_id": 7001,
    "chain_name": "zeta_testnet",
    "category": "omnichain",
    "type": "zetaConnectorZEVMAddress",
    "address": "0x0000000000000000000000000000000000000000"
  },
  {
    "chain_id": 7001,
    "chain_name": "zeta_testnet",
    "category": "omnichain",
    "type": "fungibleModuleAddress",
    "address": "0x735b14BB79463307AAcBED86DAf3322B1e6226aB"
  },
  {
    "chain_id": "80001",
    "chain_name": "mumbai_testnet",
    "category": "messaging",
    "type": "zetaToken",
    "address": "0x0000c9ec4042283e8139c74f4c64bcd1e0b9b54f"
  },
  {
    "chain_id": "80001",
    "chain_name": "mumbai_testnet",
    "category": "messaging",
    "type": "connector",
    "address": "0x0000ecb8cdd25a18f12daa23f6422e07fbf8b9e1"
  },
  {
    "chain_id": "80001",
    "category": "omnichain",
    "chain_name": "mumbai_testnet",
    "type": "erc20Custody",
    "address": "0x0000a7db254145767262c6a81a7ee1650684258e"
  },
  {
    "chain_id": "5",
    "chain_name": "goerli_testnet",
    "category": "messaging",
    "type": "zetaToken",
    "address": "0x0000c304d2934c00db1d51995b9f6996affd17c0"
  },
  {
    "chain_id": "5",
    "chain_name": "goerli_testnet",
    "category": "messaging",
    "type": "connector",
    "address": "0x00005e3125aba53c5652f9f0ce1a4cf91d8b15ea"
  },
  {
    "chain_id": "5",
    "category": "omnichain",
    "chain_name": "goerli_testnet",
    "type": "erc20Custody",
    "address": "0x000047f11c6e42293f433c82473532e869ce4ec5"
  },
  {
    "chain_id": "97",
    "chain_name": "bsc_testnet",
    "category": "messaging",
    "type": "zetaToken",
    "address": "0x0000c9ec4042283e8139c74f4c64bcd1e0b9b54f"
  },
  {
    "chain_id": "97",
    "chain_name": "bsc_testnet",
    "category": "messaging",
    "type": "connector",
    "address": "0x0000ecb8cdd25a18f12daa23f6422e07fbf8b9e1"
  },
  {
    "chain_id": "97",
    "category": "omnichain",
    "chain_name": "bsc_testnet",
    "type": "erc20Custody",
    "address": "0x0000a7db254145767262c6a81a7ee1650684258e"
  },
  {
    "chain_id": "80001",
    "chain_name": "mumbai_testnet",
    "category": "omnichain",
    "type": "tssUpdater",
    "address": "0x55122f7590164Ac222504436943FAB17B62F5d7d"
  },
  {
    "chain_id": "5",
    "chain_name": "goerli_testnet",
    "category": "omnichain",
    "type": "tssUpdater",
    "address": "0x55122f7590164Ac222504436943FAB17B62F5d7d"
  },
  {
    "chain_id": "97",
    "chain_name": "bsc_testnet",
    "category": "omnichain",
    "type": "tssUpdater",
    "address": "0x55122f7590164Ac222504436943FAB17B62F5d7d"
  }
]

The only thing that's missing is zeta token consumer.

@fadeev
Copy link
Member Author

fadeev commented Jan 10, 2024

If we're ok with this format, I can modify it to generate types as well. And of course getters. We can probably write getters manually, because the ones we could generate (get by category, get by coin type, are not really needed, it's just an array, one can just use find or filter).

@fadeev fadeev marked this pull request as draft February 5, 2024 14:19
@fadeev
Copy link
Member Author

fadeev commented Feb 5, 2024

Protocol contract addresses are now generated with the following command:

yarn generate

On each PR yarn generate is executed to check that the contracts are up-to-date.

Addresses can be fetched either manually with find:

import { mainnet, testnet } from "@zetachain/protocol-contracts";

mainnet.find(
  (a: any) => a.type === "connector" && a.chain_name === "zeta_mainnet"
)?.address; // => 0x239e96c8f17C85c30100AC26F635Ea15f23E9c67

Or by using getAddress:

import { getAddress } from "@zetachain/protocol-contracts";

getAddress("connector", "zeta_mainnet") // => 0x239e96c8f17C85c30100AC26F635Ea15f23E9c67

More examples:

getAddress("connector", "eth_mainnet") // => 0x000007Cf399229b2f5A4D043F20E90C9C98B7C6a

getAddress("erc20Custody", "mumbai_testnet") // => 0x0000a7db254145767262c6a81a7ee1650684258e

For zrc20 the function accepts an optional third argument that specifies the symbol:

getAddress("zrc20", "zeta_mainnet", "USDT.ETH") // => 0x7c8dDa80bbBE1254a7aACf3219EBe1481c6E01d7

The function throws an error when the type is not zrc20, but the symbol is provided:

getAddress("connector", "zeta_mainnet", "USDT.ETH")
// Error: Symbol is only supported when ParamType is zrc20

This preserves some backwards-compatibility:

getAddress("zrc20", "bsc_testnet") // => 0xd97B1de3619ed2c6BEb3860147E30cA8A7dC9891

getAddress("zrc20", "zeta_testnet", "tBNB") // => 0xd97B1de3619ed2c6BEb3860147E30cA8A7dC9891

Argument types are generated automatically as well:

Screenshot 2024-02-05 at 18 02 18

@fadeev fadeev marked this pull request as ready for review February 5, 2024 14:49
andresaiello
andresaiello previously approved these changes Feb 5, 2024
@fadeev
Copy link
Member Author

fadeev commented Feb 6, 2024

fwiw this address is not Uniswap, but a ZetaChain connector:

"uniswapV2Router02": "0x0000ecb8cdd25a18f12daa23f6422e07fbf8b9e1",

This just proves again that we need to automate this.

@fadeev
Copy link
Member Author

fadeev commented Feb 6, 2024

  • Added addresses JSONs in the tasks/ directory, they contain addresses such as ZETA token consumer and uniswap routers which we cannot get from existing contract addresses. If you know how to not have these addresses hard-coded, please, let me know.
  • We're now using uniswap router addresses to get WETH and factory addresses. This additionally validates router addresses (wrong router addresses will not have WETH and factory getters) and allows us to not have WETH and factory hard-coded.

andresaiello
andresaiello previously approved these changes Feb 6, 2024
[
{
"address": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
"category": "messaging",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uniswap pool can be used for omnichain smart contract call as well if a ERC20 deposit reverts.

I think we should have a category: general/misc/common

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean if a smart contract on a connected chain deposits an ERC-20 token to ZetaChain, this reverts, the contract can then use the Uniswap address to swap the token and return it to the user?

@fadeev fadeev merged commit bee7a6b into main Feb 22, 2024
9 checks passed
@fadeev fadeev deleted the feat/addresses branch February 22, 2024 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants