From 048d61a8ce4e3040e1625b3f2fb185954b6c4c34 Mon Sep 17 00:00:00 2001 From: Andres Aiello Date: Wed, 15 Nov 2023 12:05:24 -0300 Subject: [PATCH] feat: add external uniswap address to data file --- data/addresses.json | 9 +++++- lib/address.helpers.ts | 46 ++++++------------------------ lib/address.tools.ts | 19 ++++++++++-- package.json | 1 - scripts/deployments/core/deploy.ts | 14 ++++----- scripts/tools/test-zeta-send.ts | 11 +++++-- test/ZetaTokenConsumer.spec.ts | 12 ++------ yarn.lock | 5 ---- 8 files changed, 50 insertions(+), 67 deletions(-) diff --git a/data/addresses.json b/data/addresses.json index 0365fa5b..0a384f00 100644 --- a/data/addresses.json +++ b/data/addresses.json @@ -76,42 +76,49 @@ }, "non_zeta": { "baobab_testnet": { + "uniswapV2Factory": "", "uniswapV2Router02": "", "uniswapV3Factory": "", "uniswapV3Router": "", "weth9": "" }, "bsc_mainnet": { + "uniswapV2Factory": "", "uniswapV2Router02": "", "uniswapV3Factory": "", "uniswapV3Router": "", "weth9": "" }, "bsc_testnet": { + "uniswapV2Factory": "", "uniswapV2Router02": "0x9Ac64Cc6e4415144C455BD8E4837Fea55603e5c3", "uniswapV3Factory": "0x0BFbCF9fa4f9C56B0F40a671Ad40E0805A091865", "uniswapV3Router": "0x9a489505a00cE272eAa5e07Dba6491314CaE3796", "weth9": "0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd" }, "eth_mainnet": { + "uniswapV2Factory": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f", "uniswapV2Router02": "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D", "uniswapV3Factory": "0x1F98431c8aD98523631AE4a59f267346ea31F984", "uniswapV3Router": "0xE592427A0AEce92De3Edee1F18E0157C05861564", "weth9": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" }, "goerli_testnet": { + "uniswapV2Factory": "", "uniswapV2Router02": "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D", "uniswapV3Factory": "0x1F98431c8aD98523631AE4a59f267346ea31F984", "uniswapV3Router": "0xE592427A0AEce92De3Edee1F18E0157C05861564", "weth9": "0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6" }, "mumbai_testnet": { + "uniswapV2Factory": "", "uniswapV2Router02": "0x0000ecb8cdd25a18f12daa23f6422e07fbf8b9e1", "uniswapV3Factory": "0x1F98431c8aD98523631AE4a59f267346ea31F984", "uniswapV3Router": "0xE592427A0AEce92De3Edee1F18E0157C05861564", "weth9": "0xd886b7Af031F9a505310bA01951948BD1d673aF1" }, "zeta_testnet": { + "uniswapV2Factory": "", "uniswapV2Router02": "", "uniswapV3Factory": "", "uniswapV3Router": "", @@ -138,4 +145,4 @@ "uniswapv2Router02": "0x2ca7d64A7EFE2D62A725E2B35Cf7230D6677FfEe" } } -} +} \ No newline at end of file diff --git a/lib/address.helpers.ts b/lib/address.helpers.ts index 420f4011..3ddc8a33 100644 --- a/lib/address.helpers.ts +++ b/lib/address.helpers.ts @@ -1,42 +1,14 @@ -import { getAddress as getAddressLib, NetworkName, ZetaAddress, ZetaNetworkName } from "@zetachain/addresses"; -import { network } from "hardhat"; +import { ZetaProtocolNetwork } from "./address.tools"; -import { isProtocolNetworkName, ZetaProtocolNetwork } from "./address.tools"; +export declare type TestAddress = "dai" | "usdc"; -const MissingZetaNetworkError = new Error( - "ZETA_NETWORK is not defined, please set the environment variable (e.g.: ZETA_NETWORK=athens )" -); - -export const ProtocolNetworkNetworkNameMap: Record = { - baobab_testnet: "klaytn-baobab", - bsc_mainnet: "bsc-mainnet", - bsc_testnet: "bsc-testnet", - eth_mainnet: "eth-mainnet", - goerli_testnet: "goerli", - mumbai_testnet: "polygon-mumbai", - zeta_testnet: "athens", -}; - -export const getExternalAddress = ( - address: ZetaAddress, - { - customNetworkName, - customZetaNetwork, - }: { customNetworkName?: ZetaProtocolNetwork; customZetaNetwork?: ZetaNetworkName } = {} -): string => { - const { name: _networkName } = network; - - const protocolNetworkName = customNetworkName || _networkName; - - if (!isProtocolNetworkName(protocolNetworkName)) { - throw new Error(`network.name: ${protocolNetworkName} isn't supported.`); +export const getTestAddress = (address: TestAddress, networkName: ZetaProtocolNetwork): string => { + if (networkName !== "eth_mainnet") throw new Error("Invalid network name"); + if (address === "dai") { + return "0x6b175474e89094c44da98b954eedeac495271d0f"; + } else if (address === "usdc") { + return "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"; } - const networkName = ProtocolNetworkNetworkNameMap[protocolNetworkName]; - - const { ZETA_NETWORK: _ZETA_NETWORK } = process.env; - const zetaNetwork = customZetaNetwork || _ZETA_NETWORK; - - if (!zetaNetwork) throw MissingZetaNetworkError; - return getAddressLib({ address, networkName, zetaNetwork }); + throw new Error(`Unknown external address ${address} for network ${networkName}`); }; diff --git a/lib/address.tools.ts b/lib/address.tools.ts index 22b68d00..61348de8 100644 --- a/lib/address.tools.ts +++ b/lib/address.tools.ts @@ -33,6 +33,7 @@ export declare type ZetaZEVMAddress = export declare type ZetaProtocolTestNetwork = | "baobab_testnet" | "bsc_testnet" + | "btc_testnet" | "goerli_testnet" | "mumbai_testnet" | "zeta_testnet"; @@ -40,14 +41,26 @@ export declare type ZetaProtocolTestNetwork = export const zetaProtocolTestNetworks: ZetaProtocolTestNetwork[] = [ "baobab_testnet", "bsc_testnet", + "btc_testnet", "goerli_testnet", "mumbai_testnet", "zeta_testnet", ]; -export declare type NonZetaAddress = "uniswapV2Router02" | "uniswapV3Factory" | "uniswapV3Router" | "weth9"; - -export const nonZetaAddress: NonZetaAddress[] = ["uniswapV2Router02", "uniswapV3Router", "uniswapV3Factory", "weth9"]; +export declare type NonZetaAddress = + | "uniswapV2Factory" + | "uniswapV2Router02" + | "uniswapV3Factory" + | "uniswapV3Router" + | "weth9"; + +export const nonZetaAddress: NonZetaAddress[] = [ + "uniswapV2Factory", + "uniswapV2Router02", + "uniswapV3Router", + "uniswapV3Factory", + "weth9", +]; export declare type ZetaProtocolMainNetwork = "bsc_mainnet" | "eth_mainnet"; export const zetaProtocolMainNetworks: ZetaProtocolMainNetwork[] = ["eth_mainnet", "bsc_mainnet"]; diff --git a/package.json b/package.json index c26a08c9..9e7bde0a 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,6 @@ "@uniswap/v2-core": "^1.0.1", "@uniswap/v2-periphery": "^1.1.0-beta.0", "@uniswap/v3-periphery": "^1.4.3", - "@zetachain/addresses": "^0.0.13", "@zetachain/networks": "^2.4.3", "chai": "^4.3.6", "cpx": "^1.5.0", diff --git a/scripts/deployments/core/deploy.ts b/scripts/deployments/core/deploy.ts index 382bb509..c144016d 100644 --- a/scripts/deployments/core/deploy.ts +++ b/scripts/deployments/core/deploy.ts @@ -1,15 +1,15 @@ -import { isLocalNetworkName } from "@zetachain/addresses"; -import { ethers, network } from "hardhat"; +import { network } from "hardhat"; +import { isProtocolNetworkName } from "../../../lib/address.tools"; import { isEthNetworkName } from "../../../lib/contracts.helpers"; import { setZetaAddresses } from "../../tools/set-zeta-token-addresses"; import { deployZetaConnector } from "./deploy-zeta-connector"; import { deployZetaToken } from "./deploy-zeta-token"; +const networkName = network.name; + async function main() { - if (isLocalNetworkName(network.name)) { - const [owner] = await ethers.getSigners(); - } + if (!isProtocolNetworkName(networkName)) throw new Error("Invalid network name"); const zetaTokenAddress = await deployZetaToken(); const connectorAddress = await deployZetaConnector(); @@ -23,9 +23,7 @@ async function main() { * @description Avoid setting Zeta addresses for local network, * since it must be done after starting the local Zeta node */ - if (!isLocalNetworkName(network.name)) { - await setZetaAddresses(connectorAddress, zetaTokenAddress); - } + await setZetaAddresses(connectorAddress, zetaTokenAddress); } main() diff --git a/scripts/tools/test-zeta-send.ts b/scripts/tools/test-zeta-send.ts index 54453289..81de7738 100644 --- a/scripts/tools/test-zeta-send.ts +++ b/scripts/tools/test-zeta-send.ts @@ -1,12 +1,17 @@ -import { getChainId } from "@zetachain/addresses"; +import { networks } from "@zetachain/networks"; import { AbiCoder } from "ethers/lib/utils"; import { ethers, network } from "hardhat"; -import { getAddress, isProtocolNetworkName } from "lib"; +import { getAddress, isProtocolNetworkName, ZetaProtocolNetwork } from "../../lib/address.tools"; import { ZetaConnectorEth__factory as ZetaConnectorEthFactory } from "../../typechain-types"; const encoder = new AbiCoder(); +export const getChainId = (network: ZetaProtocolNetwork): number => { + //@ts-ignore + return networks[network].chain_id; +}; + async function main() { if (!isProtocolNetworkName(network.name)) { throw new Error(`network.name: ${network.name} isn't supported.`); @@ -23,7 +28,7 @@ async function main() { await ( await contract.send({ destinationAddress: encoder.encode(["address"], [accounts[0].address]), - destinationChainId: getChainId("bsc-testnet"), + destinationChainId: getChainId("bsc_testnet"), destinationGasLimit: 1_000_000, message: encoder.encode(["address"], [accounts[0].address]), zetaParams: [], diff --git a/test/ZetaTokenConsumer.spec.ts b/test/ZetaTokenConsumer.spec.ts index 1b592e4b..74e33016 100644 --- a/test/ZetaTokenConsumer.spec.ts +++ b/test/ZetaTokenConsumer.spec.ts @@ -14,7 +14,7 @@ import { BigNumber } from "ethers"; import { ethers } from "hardhat"; import { getNonZetaAddress } from "lib"; -import { getExternalAddress } from "../lib/address.helpers"; +import { getTestAddress } from "../lib/address.helpers"; import { deployZetaNonEth, getZetaTokenConsumerUniV2Strategy, @@ -62,15 +62,9 @@ describe("ZetaTokenConsumer tests", () => { args: [tssSigner.address, tssUpdater.address], }); - const DAI = getExternalAddress("dai", { - customNetworkName: "eth_mainnet", - customZetaNetwork: "mainnet", - }); + const DAI = getTestAddress("dai", "eth_mainnet"); - USDCAddr = getExternalAddress("usdc", { - customNetworkName: "eth_mainnet", - customZetaNetwork: "mainnet", - }); + USDCAddr = getTestAddress("usdc", "eth_mainnet"); uniswapV2RouterAddr = getNonZetaAddress("uniswapV2Router02", "eth_mainnet"); diff --git a/yarn.lock b/yarn.lock index ecb1b642..6a8cfffc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2076,11 +2076,6 @@ "@uniswap/v3-core" "1.0.0" base64-sol "1.0.1" -"@zetachain/addresses@^0.0.13": - version "0.0.13" - resolved "https://registry.yarnpkg.com/@zetachain/addresses/-/addresses-0.0.13.tgz#cbe56d3916e62d36e1d82e15a79404e84ed49176" - integrity sha512-hqCsEH+a3IqYR0cx9tlV0Rwk22i0MUpll81aLynxUkjoKQx5BaO3+5Mp/o62W8ZqYJICVbHPqb28DhmfoNQffg== - "@zetachain/networks@^2.4.3": version "2.4.3" resolved "https://registry.yarnpkg.com/@zetachain/networks/-/networks-2.4.3.tgz#870b2cda4b91f913be990246831378f60688d452"