-
Notifications
You must be signed in to change notification settings - Fork 11.8k
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
Add SafeERC20.tryApprove implementation #3046
Conversation
Can you share more detail about in what contexts this function is useful? |
@frangio when I need my contract to set specific approve before calling receiving contract which will later call transferFrom. What I was usually doing is safeApprove(0) + safeApprove(amount). What I need is to “set approve” not to be reverted by amount/allowance check. |
Yesterday I met the same approach in other project: https://github.com/Gearbox-protocol/gearbox-contracts/blob/8fcac6f6fd6fdb60661a5e5cec96bd0c81e7fae2/contracts/credit/CreditAccount.sol#L91-L92 |
Maybe method could be name forceApprove or sudoApprove or ensureApprove… |
@k06a Setting approval to 0, and then to the actual value should only required for EOA which cannot bundle transactions. Its basically done to avoid the new approval being frontrun by someone that would use the old approval and still get the new one. In that case it is recommended to:
If you are writing a smart contract that, as part of its internal logic, does approval + call to third party that triggers a transfer from ... then you should not need this double approval. |
@Amxx I agree but I can’t call raw approve because implementation can not return bool. Calling safeApprove twice have double allowance call overhead. |
So the purpose of this function is not to implement the double approve as a security measure, but as a workaround for tokens that have this requirement. And it was implemented in this way to avoid the double overhead for most cases? "Force approve" does sound like a better name if we decide to merge this. Can you share a few examples of tokens that have this behavior in approve? |
@frangio that’s true and I agree about naming. Will provide examples. |
USDT token is the most famous for such behavior. Here are top contracts by usage:
|
Superceded by |
Hi, consider adding this useful function implementation.
PR Checklist