Created
February 2, 2023 11:19
-
-
Save bartubozkurt/9d5eae4e0497787d951415d1e495906f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Bad */ | |
function approve(address _spender, uint256 _value) public returns (bool success) { | |
_allowances[msg.sender][_spender] = _value | |
} | |
/* Better */ | |
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | |
SafeERC20 for IERC20; | |
IERC20 token; | |
function addAllowance(IERC20 _token,address _spender, uint256 _value) public returns (bool success) { | |
token.safeIncreaseAllowance(_token, _spender, _value); | |
} | |
function decreaseAllowance(address _spender, uint256 _value) public returns (bool success) { | |
token.safeDecreaseAllowance(_token, _spender, _value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment