Open nachomazzara opened 5 years ago
Alternative:
function safeApprove(IERC20 _token, address _spender, uint256 _value) internal returns (bool) {
uint256 prevAllowance = _token.allowance(address(this), _spender);
if (prevAllowance > 0 && _value > 0) {
// clear approve
address(_token).call(
abi.encodeWithSignature("approve(address,uint256)",_spender, 0)
);
}
address(_token).call(
abi.encodeWithSignature("approve(address,uint256)",_spender, _value)
);
if (_token.allowance(address(this), _spender) != _value) {
// Approve failed
return false;
}
return true;
}
We should update doc string
Some ERC20 tokens as MANA require to clear the approval before setting a new value
The idea is to support this behaviour cleaning the approval first and the set it the new one