-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Hadrien Croubois <[email protected]> Co-authored-by: ernestognw <[email protected]>
- Loading branch information
1 parent
a51f1e1
commit e5f02bc
Showing
21 changed files
with
1,227 additions
and
215 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'openzeppelin-solidity': minor | ||
--- | ||
|
||
`ERC1363`: Add implementation of the token payable standard allowing execution of contract code after transfers and approvals. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'openzeppelin-solidity': minor | ||
--- | ||
|
||
`SafeERC20`: Add "relaxed" function for interacting with ERC-1363 functions in a way that is compatible with EOAs. |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.20; | ||
|
||
import {IERC20} from "../../interfaces/IERC20.sol"; | ||
import {ERC20, ERC1363} from "../../token/ERC20/extensions/ERC1363.sol"; | ||
|
||
// contract that replicate USDT approval behavior in approveAndCall | ||
abstract contract ERC1363ForceApproveMock is ERC1363 { | ||
function approveAndCall(address spender, uint256 amount, bytes memory data) public virtual override returns (bool) { | ||
require(amount == 0 || allowance(msg.sender, spender) == 0, "USDT approval failure"); | ||
return super.approveAndCall(spender, amount, data); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.20; | ||
|
||
import {IERC20, ERC20} from "../../token/ERC20/ERC20.sol"; | ||
import {ERC1363} from "../../token/ERC20/extensions/ERC1363.sol"; | ||
|
||
abstract contract ERC1363NoReturnMock is ERC1363 { | ||
function transferAndCall(address to, uint256 value, bytes memory data) public override returns (bool) { | ||
super.transferAndCall(to, value, data); | ||
assembly { | ||
return(0, 0) | ||
} | ||
} | ||
|
||
function transferFromAndCall( | ||
address from, | ||
address to, | ||
uint256 value, | ||
bytes memory data | ||
) public override returns (bool) { | ||
super.transferFromAndCall(from, to, value, data); | ||
assembly { | ||
return(0, 0) | ||
} | ||
} | ||
|
||
function approveAndCall(address spender, uint256 value, bytes memory data) public override returns (bool) { | ||
super.approveAndCall(spender, value, data); | ||
assembly { | ||
return(0, 0) | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.20; | ||
|
||
import {IERC1363Receiver} from "../../interfaces/IERC1363Receiver.sol"; | ||
|
||
contract ERC1363ReceiverMock is IERC1363Receiver { | ||
enum RevertType { | ||
None, | ||
RevertWithoutMessage, | ||
RevertWithMessage, | ||
RevertWithCustomError, | ||
Panic | ||
} | ||
|
||
bytes4 private _retval; | ||
RevertType private _error; | ||
|
||
event Received(address operator, address from, uint256 value, bytes data); | ||
error CustomError(bytes4); | ||
|
||
constructor() { | ||
_retval = IERC1363Receiver.onTransferReceived.selector; | ||
_error = RevertType.None; | ||
} | ||
|
||
function setUp(bytes4 retval, RevertType error) public { | ||
_retval = retval; | ||
_error = error; | ||
} | ||
|
||
function onTransferReceived( | ||
address operator, | ||
address from, | ||
uint256 value, | ||
bytes calldata data | ||
) external override returns (bytes4) { | ||
if (_error == RevertType.RevertWithoutMessage) { | ||
revert(); | ||
} else if (_error == RevertType.RevertWithMessage) { | ||
revert("ERC1363ReceiverMock: reverting"); | ||
} else if (_error == RevertType.RevertWithCustomError) { | ||
revert CustomError(_retval); | ||
} else if (_error == RevertType.Panic) { | ||
uint256 a = uint256(0) / uint256(0); | ||
a; | ||
} | ||
|
||
emit Received(operator, from, value, data); | ||
return _retval; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.20; | ||
|
||
import {IERC20, ERC20} from "../../token/ERC20/ERC20.sol"; | ||
import {ERC1363} from "../../token/ERC20/extensions/ERC1363.sol"; | ||
|
||
abstract contract ERC1363ReturnFalseOnERC20Mock is ERC1363 { | ||
function transfer(address, uint256) public pure override(IERC20, ERC20) returns (bool) { | ||
return false; | ||
} | ||
|
||
function transferFrom(address, address, uint256) public pure override(IERC20, ERC20) returns (bool) { | ||
return false; | ||
} | ||
|
||
function approve(address, uint256) public pure override(IERC20, ERC20) returns (bool) { | ||
return false; | ||
} | ||
} | ||
|
||
abstract contract ERC1363ReturnFalseMock is ERC1363 { | ||
function transferAndCall(address, uint256, bytes memory) public pure override returns (bool) { | ||
return false; | ||
} | ||
|
||
function transferFromAndCall(address, address, uint256, bytes memory) public pure override returns (bool) { | ||
return false; | ||
} | ||
|
||
function approveAndCall(address, uint256, bytes memory) public pure override returns (bool) { | ||
return false; | ||
} | ||
} |
Oops, something went wrong.