Skip to content

Commit

Permalink
feat: compare amount and refund fee before depositing
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed May 31, 2024
1 parent 8cf5f61 commit eefec3a
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/tasks/src/deposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(
{
Expand Down

0 comments on commit eefec3a

Please sign in to comment.