@0x/contracts-erc20: Switch LibERC20Token.approveIfBelowMax() to LibERC20Token.approveIfBelow().

`@0x/contracts-asset-proxy`: Use `LibERC20Token.approveIfBelow()` for bridge approvals.
This commit is contained in:
Lawrence Forman
2020-03-04 21:32:47 -05:00
parent 3f51b9322f
commit c3d4c13936
7 changed files with 30 additions and 16 deletions

View File

@@ -3,7 +3,7 @@
"version": "3.2.0",
"changes": [
{
"note": "Add `LibERC20Token.approveIfBelowMax()`",
"note": "Add `LibERC20Token.approveIfBelow()`",
"pr": 2512
}
]

View File

@@ -48,18 +48,20 @@ library LibERC20Token {
}
/// @dev Calls `IERC20Token(token).approve()` and sets the allowance to the
/// maximum if the current approval is not already set to the maximum.
/// maximum if the current approval is not already >= an amount.
/// Reverts if `false` is returned or if the return
/// data length is nonzero and not 32 bytes.
/// @param token The address of the token contract.
/// @param spender The address that receives an allowance.
function approveIfBelowMax(
/// @param amount The minimum allowance needed.
function approveIfBelow(
address token,
address spender
address spender,
uint256 amount
)
internal
{
if (IERC20Token(token).allowance(address(this), spender) != uint256(-1)) {
if (IERC20Token(token).allowance(address(this), spender) < amount) {
approve(token, spender, uint256(-1));
}
}