Skip to content

Intelligent Allowance Management #1

Description

@samarkun23

In Trade.tsx, our code currently calls approve() before every single trade.

Improvement :

  • Add a check to see if the current allowance is already greater than or equal to the amountIn. If it is, skip the approve transaction. This saves the user gas and time.
const currentAllowance = await tokenInContract.allowance(await signer.getAddress(), dex.address);
   if (currentAllowance < trade.amountIn) {
       const tx = await tokenInContract.approve(dex.address, amountInMax);
       await tx.wait();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions