-
Notifications
You must be signed in to change notification settings - Fork 19
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
chore(frontend): add TODO for ERC20 token conversion issue for approval #2637
Conversation
@@ -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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
This one was fixed with: |
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
approve
transaction for 10 USDT --> successfultransfer_from
transaction for 10 USDT --> failed (for whatever reason)approve
transaction for 20 USDT --> failed (the previous approved amount is still there)transfer_from
transaction for 20 USDT --> failed (not enough approved amount)approve
transaction for 7 USDT --> failed (the previous approved amount is still there)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