interface
interface copied to clipboard
Certain tokens dont allow approval if approve amount is not zero (USDT, CRV examples)
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:
- Approve certain asset with this issue, for example USDT or CRV, lets say approve 1 USDT to deposit or repay.
- 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
- 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
Specific logic in those tokens contracts:
USDT
CRV
Additional context Please let me know if needed, I think its clear as it is but I can further elaborate if needed.
Doesn't the aave ui always do Infinite approvals? Except for when using permit? @sendra
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 thx for clarification, wasn't aware.
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)
Note: This will require work both here in interface
as well as aave-utilities
.
Link T-8890
#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.