From eefec3a0de9458aaa89a6fcb30e827e7c3f57180 Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Fri, 31 May 2024 19:41:38 +0300 Subject: [PATCH] feat: compare amount and refund fee before depositing --- packages/tasks/src/deposit.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/packages/tasks/src/deposit.ts b/packages/tasks/src/deposit.ts index 5e7cc4d4..b6c9fa14 100644 --- a/packages/tasks/src/deposit.ts +++ b/packages/tasks/src/deposit.ts @@ -18,6 +18,25 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => { const { amount, erc20 } = args; + let inputToken = args.erc20 + ? await client.getZRC20FromERC20(erc20) + : await client.getZRC20GasToken(hre.network.name); + + const refundFee = await client.getRefundFee(inputToken); + const refundFeeAmount = ethers.utils.formatUnits( + refundFee.amount, + refundFee.decimals + ); + + let decimals = 18; + + if (erc20) { + const contract = new ethers.Contract(erc20, ERC20_ABI.abi, signer); + decimals = await contract.decimals(); + } + + const value = ethers.utils.parseUnits(amount, decimals); + let message; if (args.message) { try { @@ -100,6 +119,13 @@ Recipient: ${args.recipient || signer.address}`); if (message) { console.log(`Message: ${args.message}`); } + if (value.lt(refundFee.amount)) { + console.log(` +WARNING! Amount ${amount} is less than refund fee ${refundFeeAmount}. +This means if this transaction fails, you will not be able to get +the refund of deposited tokens. Consider increasing the amount. +`); + } try { await confirm( {