Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(frontend): add TODO for ERC20 token conversion issue for approval #2637

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/frontend/src/eth/services/send.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,14 @@ export const send = async ({

const nonce = await getTransactionCount(from);

// TODO: We may need to add an approve transaction that resets the approved amount to zero, in case of conversion from ERC20.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of resetting, couldn't we potentially know if the spender is already entitled to spend the amount and skip the approval if it's the case?

I guess this has been discussed with cross-chain team?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, correct, we could query the allowance endpoint of the ERC20 to check. For example:

Case 1:

  • query allowance
  • no amount approved --> ask for approval

Case 2:

  • query allowance
  • old amount approved --> reset amount
  • ask for new approval

That what you mean?

Copy link
Member

@peterpeterparker peterpeterparker Oct 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I mean:

Case 3:

  • query allowance
  • is allowance still valid?
  • yes, do stuffs
  • no, ask for new approval, do stuffs

Would that be possible ? I really don't know, just a question.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah! understood! well, it is possible only if the allowance is greater or equal that the current amount that the user requested;

we can check that, and if it is still ok, we can use that for sure, yes; otherwise we reset

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. Can you extend the TODO accordingly if this is a potential solution too?

// CONTEXT:
// It may happen that after the approval transaction is done, the transfer transaction may fail for whatever reasons.
// In this case, the next approval transaction will be rejected, since there is already an approved amount.
// So, the next transfer transaction will work only if the amount is below the one already approved.
// Otherwise, the user is blocked until it consumes all the approved amount.
// We had a practical example with USDT. Please check the sender wallet transaction history backwards from this one: https://etherscan.io/tx/0x084432404a919c1ee720c906bb5c7a565b6e1fdcd5bb9da32049dddfa21ad23f

const { transactionApproved } = await approve({ progress, sourceNetwork, nonce, token, ...rest });

// If we approved a transaction - as for example in Erc20 -> ckErc20 flow - then we increment the nonce for the next transaction. Otherwise, we can use the nonce we obtained.
Expand Down