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

Conversation

AntonioVentilii-DFINITY
Copy link
Collaborator

@AntonioVentilii-DFINITY AntonioVentilii-DFINITY commented Oct 3, 2024

Context

A partner encountered an issue not specific to Oisy, but somehow can be food for thought for improvement.

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.

Example

  1. The user wants to convert 10 USDT to ckUSDT:
    1. approve transaction for 10 USDT --> successful
    2. transfer_from transaction for 10 USDT --> failed (for whatever reason)
  2. The user wants to convert 20 USDT to ckUSDT:
    1. approve transaction for 20 USDT --> failed (the previous approved amount is still there)
    2. transfer_from transaction for 20 USDT --> failed (not enough approved amount)
  3. The user wants to convert 7 USDT to ckUSDT:
    1. approve transaction for 7 USDT --> failed (the previous approved amount is still there)
    2. transfer_from transaction for 7 USDT --> successful (remaining approved amount is 3 USDT)

Practical example

We had a practical example with USDT. Please check the sender wallet transaction history backwards from this one: https://etherscan.io/tx/0x084432404a919c1ee720c906bb5c7a565b6e1fdcd5bb9da32049dddfa21ad23f

@AntonioVentilii-DFINITY AntonioVentilii-DFINITY requested a review from a team as a code owner October 3, 2024 17:49
@@ -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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants