interface icon indicating copy to clipboard operation
interface copied to clipboard

Certain tokens dont allow approval if approve amount is not zero (USDT, CRV examples)

Open sirsoth opened this issue 2 years ago • 7 comments

Describe the bug Some tokens do not allow approve an amount when previous approval is not 0, due to this its possible to reach scenarios when its not possible to deposit, repay etc (actions that require approval) as the interface tries to approve again, but it fails due to this logic.

User just gets "cannot estimate gas; transaction may fail or may require manual gas limit (method="estimateGas" ..."

To Reproduce Steps to reproduce the behavior:

  1. Approve certain asset with this issue, for example USDT or CRV, lets say approve 1 USDT to deposit or repay.
  2. After that approval, go back to the main page and try to do again the process but for a higher amount, lets say 10 USDT
  3. Process fails and you get the error ""cannot estimate gas; transaction may fail or may require manual gas limit (method="estimateGas" ...""

Expected behavior In the optimal scenario, the UI would detect this problem, and suggest and approval to 0 for the user, for example approve 0 USDT, then after than approve 10 (or unlimited) USDT

But, this might be quite time consuming to adapt, and I have to say that "permit" function makes this error harder to be achieved.

Screenshots image

Specific logic in those tokens contracts: USDT image

CRV image

Additional context Please let me know if needed, I think its clear as it is but I can further elaborate if needed.

sirsoth avatar Apr 28 '22 10:04 sirsoth

Doesn't the aave ui always do Infinite approvals? Except for when using permit? @sendra

sakulstra avatar Apr 28 '22 12:04 sakulstra

Yes @sakulstra but its a common practice by many people to reduce the unlimited approval to a lower amount, for example I aim to deposit over the next weeks at max 50K USDT, I reduce the approval in metamask from unlimited to 50000 USDT

sirsoth avatar Apr 28 '22 12:04 sirsoth

@sirsoth thx for clarification, wasn't aware.

sakulstra avatar Apr 28 '22 12:04 sakulstra

In case it helps, what I would do is just:

for assets USDT & CRV (this can extend to any asset with same issue)

If approval != 0 & approval is needed (so current amount to interact > current approval)

Approval to 0 (Explain, this asset requires you to approve to 0 before a new approval)

Permit() (if possible) or Approval to amount (or infinite whatever is done currently)

sirsoth avatar May 10 '22 10:05 sirsoth

Note: This will require work both here in interface as well as aave-utilities.

drewcook avatar Jul 27 '22 21:07 drewcook

Link T-8890

defispartan avatar Mar 27 '23 13:03 defispartan

#1529 added a helper function which returns approved amount instead of a boolean, so this can now be detected on the frontend for supply.

Once a similar utility is added for repay, it can be handled there as well.

defispartan avatar Apr 24 '23 21:04 defispartan