Add SafeERC20.forceApprove() (#4067)
This commit is contained in:
13
contracts/mocks/token/ERC20ForceApproveMock.sol
Normal file
13
contracts/mocks/token/ERC20ForceApproveMock.sol
Normal file
@ -0,0 +1,13 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "../../token/ERC20/ERC20.sol";
|
||||
|
||||
// contract that replicate USDT (0xdac17f958d2ee523a2206206994597c13d831ec7) approval beavior
|
||||
abstract contract ERC20ForceApproveMock is ERC20 {
|
||||
function approve(address spender, uint256 amount) public virtual override returns (bool) {
|
||||
require(amount == 0 || allowance(msg.sender, spender) == 0, "USDT approval failure");
|
||||
return super.approve(spender, amount);
|
||||
}
|
||||
}
|
||||
@ -2,20 +2,27 @@
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
contract ERC20NoReturnMock {
|
||||
mapping(address => uint256) private _allowances;
|
||||
import "../../token/ERC20/ERC20.sol";
|
||||
|
||||
function transfer(address, uint256) public {}
|
||||
|
||||
function transferFrom(address, address, uint256) public {}
|
||||
|
||||
function approve(address, uint256) public {}
|
||||
|
||||
function setAllowance(address account, uint256 allowance_) public {
|
||||
_allowances[account] = allowance_;
|
||||
abstract contract ERC20NoReturnMock is ERC20 {
|
||||
function transfer(address to, uint256 amount) public override returns (bool) {
|
||||
super.transfer(to, amount);
|
||||
assembly {
|
||||
return(0, 0)
|
||||
}
|
||||
}
|
||||
|
||||
function allowance(address owner, address) public view returns (uint256) {
|
||||
return _allowances[owner];
|
||||
function transferFrom(address from, address to, uint256 amount) public override returns (bool) {
|
||||
super.transferFrom(from, to, amount);
|
||||
assembly {
|
||||
return(0, 0)
|
||||
}
|
||||
}
|
||||
|
||||
function approve(address spender, uint256 amount) public override returns (bool) {
|
||||
super.approve(spender, amount);
|
||||
assembly {
|
||||
return(0, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,9 +5,7 @@ pragma solidity ^0.8.0;
|
||||
import "../../token/ERC20/ERC20.sol";
|
||||
import "../../token/ERC20/extensions/draft-ERC20Permit.sol";
|
||||
|
||||
contract ERC20PermitNoRevertMock is ERC20, ERC20Permit {
|
||||
constructor() ERC20("ERC20PermitNoRevertMock", "ERC20PermitNoRevertMock") ERC20Permit("ERC20PermitNoRevertMock") {}
|
||||
|
||||
abstract contract ERC20PermitNoRevertMock is ERC20Permit {
|
||||
function permitThatMayRevert(
|
||||
address owner,
|
||||
address spender,
|
||||
|
||||
@ -2,26 +2,18 @@
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
contract ERC20ReturnFalseMock {
|
||||
mapping(address => uint256) private _allowances;
|
||||
import "../../token/ERC20/ERC20.sol";
|
||||
|
||||
function transfer(address, uint256) public pure returns (bool) {
|
||||
abstract contract ERC20ReturnFalseMock is ERC20 {
|
||||
function transfer(address, uint256) public pure override returns (bool) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function transferFrom(address, address, uint256) public pure returns (bool) {
|
||||
function transferFrom(address, address, uint256) public pure override returns (bool) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function approve(address, uint256) public pure returns (bool) {
|
||||
function approve(address, uint256) public pure override returns (bool) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function setAllowance(address account, uint256 allowance_) public {
|
||||
_allowances[account] = allowance_;
|
||||
}
|
||||
|
||||
function allowance(address owner, address) public view returns (uint256) {
|
||||
return _allowances[owner];
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,27 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
contract ERC20ReturnTrueMock {
|
||||
mapping(address => uint256) private _allowances;
|
||||
|
||||
function transfer(address, uint256) public pure returns (bool) {
|
||||
return true;
|
||||
}
|
||||
|
||||
function transferFrom(address, address, uint256) public pure returns (bool) {
|
||||
return true;
|
||||
}
|
||||
|
||||
function approve(address, uint256) public pure returns (bool) {
|
||||
return true;
|
||||
}
|
||||
|
||||
function setAllowance(address account, uint256 allowance_) public {
|
||||
_allowances[account] = allowance_;
|
||||
}
|
||||
|
||||
function allowance(address owner, address) public view returns (uint256) {
|
||||
return _allowances[owner];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user