-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./balances"; | ||
export * from "./fees"; | ||
export * from "./tx"; | ||
export * from "./pools"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import UniswapV2Factory from "@uniswap/v2-core/build/UniswapV2Factory.json"; | ||
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 }; | ||
}); | ||
|
||
const pools = await Promise.all(poolPromises); | ||
return pools; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { task } from "hardhat/config"; | ||
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), | ||
ZETA: parseFloat(n.reservesZETA).toFixed(2), | ||
})) | ||
.sort((a: any, b: any) => { | ||
if (a.name > b.name) return -1; | ||
}); | ||
console.table(poolsFiltered); | ||
}; | ||
|
||
export const poolsTask = task("pools", "", main); |