Skip to content

Instantly share code, notes, and snippets.

@bartubozkurt
Created February 2, 2023 11:19
Show Gist options
  • Save bartubozkurt/9d5eae4e0497787d951415d1e495906f to your computer and use it in GitHub Desktop.
Save bartubozkurt/9d5eae4e0497787d951415d1e495906f to your computer and use it in GitHub Desktop.
/* 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