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: add external uniswap address to data file #101

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion data/addresses.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand All @@ -138,4 +145,4 @@
"uniswapv2Router02": "0x2ca7d64A7EFE2D62A725E2B35Cf7230D6677FfEe"
}
}
}
}
46 changes: 9 additions & 37 deletions lib/address.helpers.ts
Original file line number Diff line number Diff line change
@@ -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 <command>)"
);

export const ProtocolNetworkNetworkNameMap: Record<ZetaProtocolNetwork, NetworkName> = {
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}`);
};
19 changes: 16 additions & 3 deletions lib/address.tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,34 @@ export declare type ZetaZEVMAddress =
export declare type ZetaProtocolTestNetwork =
| "baobab_testnet"
| "bsc_testnet"
| "btc_testnet"
| "goerli_testnet"
| "mumbai_testnet"
| "zeta_testnet";

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"];
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 6 additions & 8 deletions scripts/deployments/core/deploy.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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()
Expand Down
11 changes: 8 additions & 3 deletions scripts/tools/test-zeta-send.ts
Original file line number Diff line number Diff line change
@@ -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.`);
Expand All @@ -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: [],
Expand Down
12 changes: 3 additions & 9 deletions test/ZetaTokenConsumer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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");

Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading