From 8c4edb80a440d0abde886763e0776b0d55fd494a Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Tue, 23 Jan 2024 16:53:29 +0400 Subject: [PATCH] refactor --- helpers/sendZRC20.ts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/helpers/sendZRC20.ts b/helpers/sendZRC20.ts index e43b9164..17b11db0 100644 --- a/helpers/sendZRC20.ts +++ b/helpers/sendZRC20.ts @@ -31,10 +31,6 @@ export const sendZRC20 = async ( }); let tx; if (network === "zeta_testnet") { - const ZRC20Address = getAddress("zrc20", destination as any); - const gasContract = new ethers.Contract(ZRC20Address, ZRC20.abi, signer); - const gasDecimals = await gasContract.decimals(); - const { zrc20_contract_address } = foreignCoins.find( (c: any) => parseInt(c.foreign_chain_id) === getChainId(destination) && @@ -46,18 +42,17 @@ export const sendZRC20 = async ( signer ); const targetDecimals = await targetContract.decimals(); - const targetValue = ethers.utils.parseUnits(amount, targetDecimals); - - const fees = await fetchFees(5000000); - const fee = fees.feesZEVM[destination].totalFee; const to = destination === "btc_testnet" ? ethers.utils.toUtf8Bytes(recipient) : signer.address; + + const [gasAddress, gasFee] = await targetContract.withdrawGasFee(); + const gasContract = new ethers.Contract(gasAddress, ZRC20.abi, signer); + + const targetValue = ethers.utils.parseUnits(amount, targetDecimals); await ( - await gasContract - .connect(signer) - .approve(ZRC20Address, ethers.utils.parseUnits(fee, gasDecimals)) + await gasContract.connect(signer).approve(gasAddress, gasFee) ).wait(); return await targetContract.connect(signer).withdraw(to, targetValue); } else if (destination === "zeta_testnet") {