Hi all, using safeErc20 library for increase decreasing allowance. But what about tokens which do not support increaseAllowance method. Like USDT. What would be safest approach in solidity to have compatibility for approvals for full erc20 tokens and those which do not support increaseAllowance. How to detect tokens which do not support increaseAllowance in the solidity code and how to properly increase allowance for tokens which do not support increaseAllowance.
The SafeERC20 library functions
safeDecreaseAllowance do not rely on the target ERC20 contract implementing functions
Instead, they simply execute
approve(0), followed by
Ok, but why then safeIncreaseAllowance is not working on some tokens (0x6c3F90f043a72FA612cbac8115EE7e52BDe6E490)?, rather I need to do safeApprove(0): safeApprove(amount), which is deprecated and I would like to have a generic code to support both tokens which safeIncreaseAllowance is not working for, so I can fallback. How to tokens for which safeIncreaseAllowance is failing. It doesn't return nothing so I cannot do if then
Please share the relevant details, namely (by the least):
- Which OZ version you are using
- Which tokens
safeIncreaseAllowanceis not working for
token is 0x6c3F90f043a72FA612cbac8115EE7e52BDe6E490. It is curve LP token.
safeERC20.sol is // OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol)
So i upgraded to 4.9.3 still same problem, safeIncreaseAllowance doesn't work
note that forceApprove works. So should I just use forceApprove on all tokens?
What does work is I used code on your master branch for safeERC20, where safeIncreaseAllowance calls forceApprove. That does the trick universal. But this isn't released yet by you officially.
4.9.3 and below: safeIncreaseAllowance, only calls approve with the increase amount
master safeIncreaseAllowance: always calls forceApprove which first sets the approve to 0 and then then calls approve with previously approved amount + increase amount (don't use master branch in your projects)
If you want the same behavior's in the current release then you'll have to call forceApprove as you mentioned. "safe" is a bit misleading in this case.
Same with the safeTransfer function on ERC721 tokens, definitely NOT safe
so to summarise , if I am using current release ,to make sure I get support for all the tokens (or at least big majority) I should use just forceApprove on all, from the compatibility side fits more the safeIncreaseAllowance
yes, if you want the "best" support with the current 4.x release then use the forceapprove