Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions contracts/token/ERC20/utils/SafeERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ library SafeERC20 {
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
forceApprove(token, spender, oldAllowance + value);
}

/**
Expand All @@ -70,7 +70,7 @@ library SafeERC20 {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
forceApprove(token, spender, oldAllowance - value);
}
}

Expand Down
11 changes: 7 additions & 4 deletions test/token/ERC20/utils/SafeERC20.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,19 @@ contract('SafeERC20', function (accounts) {
await this.mock.$safeApprove(this.token.address, spender, 0);
});

it('safeApprove can increase approval', async function () {
await expectRevert(this.mock.$safeIncreaseAllowance(this.token.address, spender, 10), 'USDT approval failure');
it('safeIncreaseAllowance works', async function () {
this.mock.$safeIncreaseAllowance(this.token.address, spender, 10);
expect(this.token.allowance(this.mock.address, spender, 90));
});

it('safeApprove can decrease approval', async function () {
await expectRevert(this.mock.$safeDecreaseAllowance(this.token.address, spender, 10), 'USDT approval failure');
it('safeDecreaseAllowance works', async function () {
this.mock.$safeDecreaseAllowance(this.token.address, spender, 10);
expect(this.token.allowance(this.mock.address, spender, 110));
});

it('forceApprove works', async function () {
await this.mock.$forceApprove(this.token.address, spender, 200);
expect(this.token.allowance(this.mock.address, spender, 200));
});
});
});
Expand Down