Skip to content

Commit

Permalink
refactor fees
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Oct 13, 2023
1 parent fbc3845 commit bedf70a
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 195 deletions.
109 changes: 0 additions & 109 deletions helpers/evm.ts

This file was deleted.

12 changes: 6 additions & 6 deletions helpers/fees.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getEndpoints } from "@zetachain/networks";
import { getHardhatConfigNetworks } from "@zetachain/networks";
import { getEndpoints } from "@zetachain/networks/dist/src/getEndpoints";
import networks from "@zetachain/networks/dist/src/networks";
import { getAddress } from "@zetachain/protocol-contracts";
import ZRC20 from "@zetachain/protocol-contracts/abi/zevm/ZRC20.sol/ZRC20.json";
import axios from "axios";
Expand All @@ -9,7 +9,7 @@ import { formatEther } from "ethers/lib/utils";
const formatTo18Decimals = (n: any) => parseFloat(formatEther(n)).toFixed(18);

export const fetchZEVMFees = async (network: string) => {
const { url } = getHardhatConfigNetworks()["zeta_testnet"] as any;
const url = getEndpoints("evm", "zeta_testnet")[0].url;

const provider = new ethers.providers.JsonRpcProvider(url);
const btcZRC20 = "0x65a45c57636f9BcCeD4fe193A602008578BcA90b"; // TODO: use getAddress("zrc20", "btc_testnet") when available
Expand Down Expand Up @@ -37,7 +37,7 @@ export const fetchCCMFees = async (network: string, gas: Number = 500000) => {
throw new Error("getEndpoints: API endpoint not found");
}

const chainID = getHardhatConfigNetworks()[network].chainId;
const chainID = networks[network as keyof typeof networks]?.chain_id;

const url = `${API}/zeta-chain/crosschain/convertGasToZeta?chainId=${chainID}&gasLimit=${gas}`;
const { data } = await axios.get(url);
Expand All @@ -59,10 +59,10 @@ export const fetchFees = async (gas: Number) => {
feesZEVM: {} as Record<string, any>,
};

const networks = [...Object.keys(getHardhatConfigNetworks()), "btc_testnet"];
const networkList = [...Object.keys(networks), "btc_testnet"];

await Promise.all(
networks.map(async (n) => {
networkList.map(async (n) => {
try {
const zevmFees = await fetchZEVMFees(n);
if (zevmFees) fees.feesZEVM[n] = zevmFees;
Expand Down
76 changes: 0 additions & 76 deletions helpers/helpers.ts

This file was deleted.

3 changes: 1 addition & 2 deletions helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from "./evm";
export * from "./balances";
export * from "./fees";
export * from "./helpers";
export * from "./tx";
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"./tasks": "./dist/tasks/index.js",
"./helpers": "./dist/helpers/index.js",
"./helpers/fees": "./dist/helpers/fees.js",
"./helpers/evm": "./dist/helpers/evm.js",
"./helpers/balances": "./dist/helpers/balances.js"
},
"scripts": {
Expand Down Expand Up @@ -95,4 +94,4 @@
"tiny-secp256k1": "^2.2.3",
"ws": "^8.13.0"
}
}
}

0 comments on commit bedf70a

Please sign in to comment.