Skip to content

Commit

Permalink
getPools
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Oct 16, 2023
1 parent f61dbec commit ebd599c
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 0 deletions.
1 change: 1 addition & 0 deletions helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./balances";

Check failure on line 1 in helpers/index.ts

View workflow job for this annotation

GitHub Actions / build

Run autofix to sort these exports!
export * from "./fees";
export * from "./tx";
export * from "./pools";
54 changes: 54 additions & 0 deletions helpers/pools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import UniswapV2Factory from "@uniswap/v2-core/build/UniswapV2Factory.json";

Check failure on line 1 in helpers/pools.ts

View workflow job for this annotation

GitHub Actions / build

Run autofix to sort these imports!
import UniswapV2Pair from "@uniswap/v2-core/build/UniswapV2Pair.json";
import { getAddress } from "@zetachain/protocol-contracts";
import { ethers } from "ethers";
import { getEndpoints } from "@zetachain/networks/dist/src/getEndpoints";
import fetch from "isomorphic-fetch";

export const getPools = async () => {
const api = getEndpoints("cosmos-http", "zeta_testnet")[0]?.url;
const endpoint = `${api}/zeta-chain/zetacore/fungible/foreign_coins`;
const response = await fetch(endpoint);
const data = await response.json();

const rpc = getEndpoints("evm", "zeta_testnet")[0]?.url;
const provider = new ethers.providers.JsonRpcProvider(rpc);

const uniswapV2FactoryAddress = getAddress(
"uniswapv2Factory",
"zeta_testnet"
);
const zetaTokenAddress = getAddress("zetaToken", "zeta_testnet");

const UniswapV2FactoryContract = new ethers.Contract(
uniswapV2FactoryAddress,
UniswapV2Factory.abi,
provider
);

const poolPromises = data.foreignCoins.map(async (token: any) => {
const zrc20Address = token.zrc20_contract_address;
const pair = await UniswapV2FactoryContract.getPair(
zrc20Address,
zetaTokenAddress
);

let reservesZRC20 = "0";
let reservesZETA = "0";

if (pair !== ethers.constants.AddressZero) {
const uniswapPairContract = new ethers.Contract(
pair,
UniswapV2Pair.abi,
provider
);
const reserves = await uniswapPairContract.getReserves();
reservesZRC20 = ethers.utils.formatEther(reserves[0]);
reservesZETA = ethers.utils.formatEther(reserves[1]);
}
return { ...token, reservesZRC20, reservesZETA };

Check failure on line 49 in helpers/pools.ts

View workflow job for this annotation

GitHub Actions / build

Expected object keys to be in ascending order. 'reservesZETA' should be before 'reservesZRC20'
});

const pools = await Promise.all(poolPromises);
return pools;
};
1 change: 1 addition & 0 deletions helpers/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { getEndpoints } from "@zetachain/networks/dist/src/getEndpoints";
import networks from "@zetachain/networks/dist/src/networks";
import axios from "axios";
import { ethers } from "ethers";
import fetch from "isomorphic-fetch";

const getEndpoint = (key: any): string => {
const endpoint = getEndpoints(key, "zeta_testnet")[0]?.url;
Expand Down
1 change: 1 addition & 0 deletions tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export { sendBTCTask } from "./sendBTC";
export { sendZETATask } from "./sendZETA";
export { sendZRC20Task } from "./sendZRC20";
export { verifyTask } from "./verify";
export { poolsTask } from "./pools";
19 changes: 19 additions & 0 deletions tasks/pools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { task } from "hardhat/config";

Check failure on line 1 in tasks/pools.ts

View workflow job for this annotation

GitHub Actions / build

Run autofix to sort these imports!
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { getPools } from "../helpers/pools";

const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
const pools = await getPools();
const poolsFiltered = pools
.map((n: any) => ({
name: n.asset ? n.name : n.symbol,
"ZRC-20": parseFloat(n.reservesZRC20).toFixed(2),

Check failure on line 10 in tasks/pools.ts

View workflow job for this annotation

GitHub Actions / build

Expected object keys to be in ascending order. 'ZRC-20' should be before 'name'
ZETA: parseFloat(n.reservesZETA).toFixed(2),

Check failure on line 11 in tasks/pools.ts

View workflow job for this annotation

GitHub Actions / build

Expected object keys to be in ascending order. 'ZETA' should be before 'ZRC-20'
}))
.sort((a: any, b: any) => {
if (a.name > b.name) return -1;
});
console.table(poolsFiltered);
};

export const poolsTask = task("pools", "", main);

0 comments on commit ebd599c

Please sign in to comment.