Skip to content

Commit

Permalink
update uniswap scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
andresaiello committed Nov 14, 2023
1 parent 07a0b9a commit c7df370
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 114 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { MaxUint256 } from "@ethersproject/constants";
import { formatUnits, parseUnits } from "@ethersproject/units";
import { parseUnits } from "@ethersproject/units";
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { getChainId } from "@zetachain/addresses";
import { NetworkName } from "@zetachain/addresses";
import { getAddress } from "@zetachain/addresses";
import { getGasSymbolByNetwork, getSystemContractAddress } from "@zetachain/addresses-tools";
import { getNonZetaAddress, isProtocolNetworkName, ZetaProtocolNetwork } from "@zetachain/protocol-contracts";
import { BigNumber } from "ethers";
import { ethers } from "hardhat";
import { ethers, network } from "hardhat";

import {
ERC20,
Expand All @@ -17,8 +14,11 @@ import {
SystemContract__factory,
UniswapV2Router02__factory
} from "../../typechain-types";
import { getChainId, getSystemContractAddress } from "../address.helpers";
import { getNow, printReserves, sortPair } from "./uniswap.helpers";

const networkName = network.name;

const SYSTEM_CONTRACT = getSystemContractAddress();

const BTC_TO_ADD = parseUnits("0", 8);
Expand Down Expand Up @@ -53,7 +53,6 @@ const addTokenEthLiquidity = async (
};

const estimateZetaForToken = async (
network: NetworkName,
WZETAAddress: string,
uniswapFactoryAddress: string,
tokenContract: ERC20,
Expand All @@ -79,7 +78,7 @@ const estimateZetaForToken = async (
};

async function addLiquidity(
network: NetworkName,
network: ZetaProtocolNetwork,
tokenAmountToAdd: BigNumber,
WZETAAddress: string,
uniswapFactoryAddress: string,
Expand All @@ -98,49 +97,31 @@ async function addLiquidity(

const zetaToAdd = initLiquidityPool
? ZETA_TO_ADD
: await estimateZetaForToken(
network,
WZETAAddress,
uniswapFactoryAddress,
tokenContract,
tokenAmountToAdd,
deployer
);
: await estimateZetaForToken(WZETAAddress, uniswapFactoryAddress, tokenContract, tokenAmountToAdd, deployer);

await printReserves(tokenContract, WZETAAddress, uniswapFactoryAddress, deployer);
// await addTokenEthLiquidity(tokenContract, tokenAmountToAdd, zetaToAdd, uniswapRouter, deployer);
await printReserves(tokenContract, WZETAAddress, uniswapFactoryAddress, deployer);
}
async function main() {
const WZETA_ADDRESS = getAddress({
address: "weth9",
networkName: "athens",
zetaNetwork: "athens"
});
if (!isProtocolNetworkName(networkName)) throw new Error("Invalid network name");
const WZETA_ADDRESS = getNonZetaAddress("weth9", networkName);

const UNISWAP_FACTORY_ADDRESS = getAddress({
address: "uniswapV2Factory",
networkName: "athens",
zetaNetwork: "athens"
});
const UNISWAP_FACTORY_ADDRESS = getNonZetaAddress("uniswapV2Factory", networkName);

const UNISWAP_ROUTER_ADDRESS = getAddress({
address: "uniswapV2Router02",
networkName: "athens",
zetaNetwork: "athens"
});
const UNISWAP_ROUTER_ADDRESS = getNonZetaAddress("uniswapV2Router02", networkName);

if (!ETH_TO_ADD.isZero()) {
await addLiquidity("goerli", ETH_TO_ADD, WZETA_ADDRESS, UNISWAP_FACTORY_ADDRESS, UNISWAP_ROUTER_ADDRESS);
await addLiquidity("goerli_testnet", ETH_TO_ADD, WZETA_ADDRESS, UNISWAP_FACTORY_ADDRESS, UNISWAP_ROUTER_ADDRESS);
}
if (!MATIC_TO_ADD.isZero()) {
await addLiquidity("polygon-mumbai", MATIC_TO_ADD, WZETA_ADDRESS, UNISWAP_FACTORY_ADDRESS, UNISWAP_ROUTER_ADDRESS);
await addLiquidity("mumbai_testnet", MATIC_TO_ADD, WZETA_ADDRESS, UNISWAP_FACTORY_ADDRESS, UNISWAP_ROUTER_ADDRESS);
}
if (!BNB_TO_ADD.isZero()) {
await addLiquidity("bsc-testnet", BNB_TO_ADD, WZETA_ADDRESS, UNISWAP_FACTORY_ADDRESS, UNISWAP_ROUTER_ADDRESS);
await addLiquidity("bsc_testnet", BNB_TO_ADD, WZETA_ADDRESS, UNISWAP_FACTORY_ADDRESS, UNISWAP_ROUTER_ADDRESS);
}
if (!BTC_TO_ADD.isZero()) {
await addLiquidity("bitcoin-test", BTC_TO_ADD, WZETA_ADDRESS, UNISWAP_FACTORY_ADDRESS, UNISWAP_ROUTER_ADDRESS);
await addLiquidity("btc_testnet", BTC_TO_ADD, WZETA_ADDRESS, UNISWAP_FACTORY_ADDRESS, UNISWAP_ROUTER_ADDRESS);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { MaxUint256 } from "@ethersproject/constants";
import { formatUnits } from "@ethersproject/units";
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { getChainId } from "@zetachain/addresses";
import { NetworkName } from "@zetachain/addresses";
import { getAddress } from "@zetachain/addresses";
import { getSystemContractAddress } from "@zetachain/addresses-tools";
import { getNonZetaAddress, isProtocolNetworkName, ZetaProtocolNetwork } from "@zetachain/protocol-contracts";
import { BigNumber } from "ethers";
import { ethers } from "hardhat";
import { ethers, network } from "hardhat";

import {
ERC20,
Expand All @@ -18,8 +15,10 @@ import {
SystemContract__factory,
UniswapV2Router02__factory
} from "../../typechain-types";
import { getChainId, getSystemContractAddress } from "../address.helpers";
import { getNow, printReserves, sortPair } from "./uniswap.helpers";

const networkName = network.name;
const SYSTEM_CONTRACT = getSystemContractAddress();

const removeTokenEthLiquidity = async (
Expand Down Expand Up @@ -47,7 +46,7 @@ const removeTokenEthLiquidity = async (
};

async function removeLiquidity(
network: NetworkName,
network: ZetaProtocolNetwork,
WZETAAddress: string,
uniswapFactoryAddress: string,
uniswapRouterAddress: string
Expand Down Expand Up @@ -78,28 +77,18 @@ async function removeLiquidity(
await printReserves(tokenContract, WZETAAddress, uniswapFactoryAddress, deployer);
}
async function main() {
const WZETA_ADDRESS = getAddress({
address: "weth9",
networkName: "athens",
zetaNetwork: "athens"
});
if (!isProtocolNetworkName(networkName)) throw new Error("Invalid network name");

const UNISWAP_FACTORY_ADDRESS = getAddress({
address: "uniswapV2Factory",
networkName: "athens",
zetaNetwork: "athens"
});
const WZETA_ADDRESS = getNonZetaAddress("weth9", networkName);

const UNISWAP_ROUTER_ADDRESS = getAddress({
address: "uniswapV2Router02",
networkName: "athens",
zetaNetwork: "athens"
});
const UNISWAP_FACTORY_ADDRESS = getNonZetaAddress("uniswapV2Factory", networkName);

const UNISWAP_ROUTER_ADDRESS = getNonZetaAddress("uniswapV2Router02", networkName);

await removeLiquidity("goerli", WZETA_ADDRESS, UNISWAP_FACTORY_ADDRESS, UNISWAP_ROUTER_ADDRESS);
await removeLiquidity("polygon-mumbai", WZETA_ADDRESS, UNISWAP_FACTORY_ADDRESS, UNISWAP_ROUTER_ADDRESS);
await removeLiquidity("bsc-testnet", WZETA_ADDRESS, UNISWAP_FACTORY_ADDRESS, UNISWAP_ROUTER_ADDRESS);
await removeLiquidity("bitcoin-test", WZETA_ADDRESS, UNISWAP_FACTORY_ADDRESS, UNISWAP_ROUTER_ADDRESS);
await removeLiquidity("goerli_testnet", WZETA_ADDRESS, UNISWAP_FACTORY_ADDRESS, UNISWAP_ROUTER_ADDRESS);
await removeLiquidity("mumbai_testnet", WZETA_ADDRESS, UNISWAP_FACTORY_ADDRESS, UNISWAP_ROUTER_ADDRESS);
await removeLiquidity("bsc_testnet", WZETA_ADDRESS, UNISWAP_FACTORY_ADDRESS, UNISWAP_ROUTER_ADDRESS);
await removeLiquidity("btc_testnet", WZETA_ADDRESS, UNISWAP_FACTORY_ADDRESS, UNISWAP_ROUTER_ADDRESS);
}

main()
Expand Down
41 changes: 15 additions & 26 deletions packages/zevm-app-contracts/scripts/uniswap/sell-token.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { MaxUint256 } from "@ethersproject/constants";
import { formatUnits, parseUnits } from "@ethersproject/units";
import { parseUnits } from "@ethersproject/units";
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { getChainId } from "@zetachain/addresses";
import { NetworkName } from "@zetachain/addresses";
import { getAddress } from "@zetachain/addresses";
import { getSystemContractAddress } from "@zetachain/addresses-tools";
import { getNonZetaAddress, isProtocolNetworkName, ZetaProtocolNetwork } from "@zetachain/protocol-contracts";
import { BigNumber } from "ethers";
import { ethers } from "hardhat";
import { ethers, network } from "hardhat";

import {
ERC20,
Expand All @@ -15,8 +12,10 @@ import {
SystemContract__factory,
UniswapV2Router02__factory
} from "../../typechain-types";
import { getChainId, getSystemContractAddress } from "../address.helpers";
import { getNow, printReserves } from "./uniswap.helpers";

const networkName = network.name;
const SYSTEM_CONTRACT = getSystemContractAddress();

const BTC_TO_SELL = parseUnits("0", 8);
Expand Down Expand Up @@ -50,7 +49,7 @@ const swapZeta = async (
};

async function sellToken(
network: NetworkName,
network: ZetaProtocolNetwork,
tokenAmountToSell: BigNumber,
WZETAAddress: string,
uniswapFactoryAddress: string,
Expand All @@ -71,35 +70,25 @@ async function sellToken(
await printReserves(tokenContract, WZETAAddress, uniswapFactoryAddress, deployer);
}
async function main() {
const WZETA_ADDRESS = getAddress({
address: "weth9",
networkName: "athens",
zetaNetwork: "athens"
});
if (!isProtocolNetworkName(networkName)) throw new Error("Invalid network name");

const UNISWAP_FACTORY_ADDRESS = getAddress({
address: "uniswapV2Factory",
networkName: "athens",
zetaNetwork: "athens"
});
const WZETA_ADDRESS = getNonZetaAddress("weth9", networkName);

const UNISWAP_ROUTER_ADDRESS = getAddress({
address: "uniswapV2Router02",
networkName: "athens",
zetaNetwork: "athens"
});
const UNISWAP_FACTORY_ADDRESS = getNonZetaAddress("uniswapV2Factory", networkName);

const UNISWAP_ROUTER_ADDRESS = getNonZetaAddress("uniswapV2Router02", networkName);

if (!ETH_TO_SELL.isZero()) {
await sellToken("goerli", ETH_TO_SELL, WZETA_ADDRESS, UNISWAP_FACTORY_ADDRESS, UNISWAP_ROUTER_ADDRESS);
await sellToken("goerli_testnet", ETH_TO_SELL, WZETA_ADDRESS, UNISWAP_FACTORY_ADDRESS, UNISWAP_ROUTER_ADDRESS);
}
if (!MATIC_TO_SELL.isZero()) {
await sellToken("polygon-mumbai", MATIC_TO_SELL, WZETA_ADDRESS, UNISWAP_FACTORY_ADDRESS, UNISWAP_ROUTER_ADDRESS);
await sellToken("mumbai_testnet", MATIC_TO_SELL, WZETA_ADDRESS, UNISWAP_FACTORY_ADDRESS, UNISWAP_ROUTER_ADDRESS);
}
if (!BNB_TO_SELL.isZero()) {
await sellToken("bsc-testnet", BNB_TO_SELL, WZETA_ADDRESS, UNISWAP_FACTORY_ADDRESS, UNISWAP_ROUTER_ADDRESS);
await sellToken("bsc_testnet", BNB_TO_SELL, WZETA_ADDRESS, UNISWAP_FACTORY_ADDRESS, UNISWAP_ROUTER_ADDRESS);
}
if (!BTC_TO_SELL.isZero()) {
await sellToken("bitcoin-test", BTC_TO_SELL, WZETA_ADDRESS, UNISWAP_FACTORY_ADDRESS, UNISWAP_ROUTER_ADDRESS);
await sellToken("btc_testnet", BTC_TO_SELL, WZETA_ADDRESS, UNISWAP_FACTORY_ADDRESS, UNISWAP_ROUTER_ADDRESS);
}
}

Expand Down
39 changes: 14 additions & 25 deletions packages/zevm-app-contracts/scripts/uniswap/sell-zeta.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { MaxUint256 } from "@ethersproject/constants";
import { formatUnits, parseUnits } from "@ethersproject/units";
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { getChainId } from "@zetachain/addresses";
import { NetworkName } from "@zetachain/addresses";
import { getAddress } from "@zetachain/addresses";
import { getSystemContractAddress } from "@zetachain/addresses-tools";
import { getNonZetaAddress, isProtocolNetworkName, ZetaProtocolNetwork } from "@zetachain/protocol-contracts";
import { BigNumber } from "ethers";
import { ethers } from "hardhat";
import { ethers, network } from "hardhat";

import {
ERC20,
Expand All @@ -15,8 +12,10 @@ import {
SystemContract__factory,
UniswapV2Router02__factory
} from "../../typechain-types";
import { getChainId, getSystemContractAddress } from "../address.helpers";
import { getNow, printReserves } from "./uniswap.helpers";

const networkName = network.name;
const SYSTEM_CONTRACT = getSystemContractAddress();

const ZETA_TO_SELL = parseUnits("0.001");
Expand All @@ -41,7 +40,7 @@ const swapZeta = async (
};

async function sellZeta(
network: NetworkName,
network: ZetaProtocolNetwork,
WZETAAddress: string,
uniswapFactoryAddress: string,
uniswapRouterAddress: string
Expand All @@ -61,28 +60,18 @@ async function sellZeta(
await printReserves(tokenContract, WZETAAddress, uniswapFactoryAddress, deployer);
}
async function main() {
const WZETA_ADDRESS = getAddress({
address: "weth9",
networkName: "athens",
zetaNetwork: "athens"
});
if (!isProtocolNetworkName(networkName)) throw new Error("Invalid network name");

const UNISWAP_FACTORY_ADDRESS = getAddress({
address: "uniswapV2Factory",
networkName: "athens",
zetaNetwork: "athens"
});
const WZETA_ADDRESS = getNonZetaAddress("weth9", networkName);

const UNISWAP_ROUTER_ADDRESS = getAddress({
address: "uniswapV2Router02",
networkName: "athens",
zetaNetwork: "athens"
});
const UNISWAP_FACTORY_ADDRESS = getNonZetaAddress("uniswapV2Factory", networkName);

const UNISWAP_ROUTER_ADDRESS = getNonZetaAddress("uniswapV2Router02", networkName);

await sellZeta("goerli", WZETA_ADDRESS, UNISWAP_FACTORY_ADDRESS, UNISWAP_ROUTER_ADDRESS);
await sellZeta("polygon-mumbai", WZETA_ADDRESS, UNISWAP_FACTORY_ADDRESS, UNISWAP_ROUTER_ADDRESS);
await sellZeta("bsc-testnet", WZETA_ADDRESS, UNISWAP_FACTORY_ADDRESS, UNISWAP_ROUTER_ADDRESS);
await sellZeta("bitcoin-test", WZETA_ADDRESS, UNISWAP_FACTORY_ADDRESS, UNISWAP_ROUTER_ADDRESS);
await sellZeta("goerli_testnet", WZETA_ADDRESS, UNISWAP_FACTORY_ADDRESS, UNISWAP_ROUTER_ADDRESS);
await sellZeta("mumbai_testnet", WZETA_ADDRESS, UNISWAP_FACTORY_ADDRESS, UNISWAP_ROUTER_ADDRESS);
await sellZeta("bsc_testnet", WZETA_ADDRESS, UNISWAP_FACTORY_ADDRESS, UNISWAP_ROUTER_ADDRESS);
await sellZeta("btc_testnet", WZETA_ADDRESS, UNISWAP_FACTORY_ADDRESS, UNISWAP_ROUTER_ADDRESS);
}

main()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const main = async () => {
const swappableNetwork: SwappableNetwork = network.name;

// @dev: bitcoin is invalid as destination
const invalidDestinations: SwappableNetwork[] = [swappableNetwork, "bitcoin-test"];
const invalidDestinations: SwappableNetwork[] = [swappableNetwork, "btc_testnet"];
const networks = Object.keys(ChainToZRC20).map(c => c as SwappableNetwork);

const destinationNetworks = networks.filter(e => !invalidDestinations.includes(e));
Expand Down
4 changes: 2 additions & 2 deletions packages/zevm-app-contracts/test/Swap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { getNonZetaAddress } from "@zetachain/protocol-contracts";
import { expect } from "chai";
import { ethers, network } from "hardhat";

import { getBitcoinTxMemoForTest, getSwapParams } from "../scripts/zeta-swap/helpers";
import {
MockSystemContract,
MockZRC20,
ZetaSwap,
ZetaSwap__factory,
ZetaSwapBtcInbound,
ZetaSwapBtcInbound__factory
} from "../../zevm-example-contracts/typechain-types";
import { getBitcoinTxMemoForTest, getSwapParams } from "../scripts/zeta-swap/helpers";
} from "../typechain-types";
import { evmSetup } from "./test.helpers";

describe("ZetaSwap tests", () => {
Expand Down

0 comments on commit c7df370

Please sign in to comment.