-
Notifications
You must be signed in to change notification settings - Fork 12.4k
Add ERC1363 implementation #4631
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
96 commits
Select commit
Hold shift + click to select a range
84fe15d
Add ERC1363 contracts
vittominacori 67d6fcd
Add ERC1363 tests
vittominacori 4cbb703
Add changeset
vittominacori fdd322b
Improve documentation
vittominacori f8bd003
Add ERC1363Holder
vittominacori 381387c
Update changeset
vittominacori 83baa53
Merge branch 'master' of https://github.com/OpenZeppelin/openzeppelin…
vittominacori a07c77c
Move mint out of test behavior and rename const to avoid confusion
vittominacori cf3c377
migrate Ownable tests to ethers
Amxx 673ff79
fix lint
Amxx c9b4e8d
Update hardhat.config.js
Amxx c46a45e
add Ownable2Step
Amxx 328a344
remove deploy helper
Amxx 7c12232
add deprecation notices
Amxx 517ad87
up
Amxx 9002e5f
up
Amxx 16731a9
Merge branch 'master' of https://github.com/OpenZeppelin/openzeppelin…
vittominacori 89ab4c9
Rename wrong file
vittominacori 74558f8
remove .address when doing ethers call that support addressable
Amxx 0e6e84c
Update pragma to 0.8.20
vittominacori 9ea2db1
Fix flaky test in ERC2981.behavior
ernestognw fd7100a
Update test/access/Ownable.test.js
Amxx 1a9a046
Update test/access/Ownable.test.js
Amxx b569ca8
Fix lint
ernestognw b24fec4
Fix upgradeable tests
ernestognw 5e96021
redesign signers/fixture
Amxx f382329
Fix vanilla tests by overriding require and readArtifact with sync an…
ernestognw 95be46d
Revert "redesign signers/fixture"
Amxx 55b0406
Optimize ethers.getSigners call by passing a promise to use within fi…
ernestognw e45e482
Slice ethers accounts
ernestognw b391c2f
rename
Amxx 74bab81
override hre.ethers.getSigners
Amxx 98e5ecd
unify coding style/naming between env-contracts.js and env-artifacts.js
Amxx 4db1800
Attempt to fix tests by avoid overriding `this` in Truffle require
ernestognw 0a8a69d
Revert "Attempt to fix tests by avoid overriding `this` in Truffle re…
Amxx ec3bfc5
Merge branch 'master' into test/migration/ownable
Amxx 5d5a150
Force compile on upgradeable and coverage workflows
Amxx 300fa1e
use cached getSigners() in fixtures
Amxx ae4381e
use describe instead of contract for ethers test that don't need the …
Amxx b02770e
add enviornment sanity check
Amxx 4e6a1ca
skip signer slice when running coverage
Amxx 69b91a0
up
Amxx 5162e98
Move non standardized error definition to the implementation file
Amxx 2668934
Add "relaxed" helpers for ERC1363 in SafeERC20
Amxx 5b84827
Merge branch 'test/migration/ownable' into feat/eip1363-v5.x
Amxx da0d4ff
Merge branch 'master' of https://github.com/OpenZeppelin/openzeppelin…
vittominacori f269fa7
rewrite tests using ethers
Amxx 8a4cae5
Merge branch 'master' into feat/eip1363-v5.x
Amxx 46858a7
Remove ERC1363 Spender and Receiver interface from introspection test
vittominacori c07c414
addapt erc165 verification to ethers
Amxx 24e8e89
Add a test to check that events are emitted
vittominacori f781db4
minor fixes
Amxx 17b697b
Merge branch 'feat/eip1363-v5.x' of https://github.com/vittominacori/…
Amxx 80930e8
migrate ERC1363Holder test to ethers + lint:fix
Amxx a844207
improve SupportInterface.behavior.js
Amxx 178ff7d
codespell
Amxx 34a7a8d
test SafeERC20 relaxed functions
Amxx 7fde72d
fix lint
Amxx 5ec39cb
Apply suggestions from code review
Amxx eb0fb78
remove ERC1363Holder
Amxx b893eec
add changeset
Amxx e137121
Fix documentation reference
vittominacori 07bdbfd
Use external instead of public in mock (as it is in interface)
vittominacori 4440345
Typo
vittominacori 3dff6e2
Update contracts/interfaces/IERC1363Spender.sol
vittominacori c2f27c8
Merge branch 'master' of https://github.com/OpenZeppelin/openzeppelin…
vittominacori 81d191f
Apply suggestions from code review
Amxx c3fa314
test coverage
Amxx 09049d3
lint
Amxx 0ac39e4
Merge branch 'master' of https://github.com/OpenZeppelin/openzeppelin…
vittominacori 341a687
Merge branch 'master' of https://github.com/OpenZeppelin/openzeppelin…
vittominacori 938a92b
Merge branch 'master' into feat/eip1363-v5.x
Amxx 924b50d
re-enable shouldBehaveLikeERC20 + minor test cleanup
Amxx 7d5e66e
document the 1363 functions not passing the standardized tests
Amxx f0d3a17
fix lint
Amxx 7629147
Merge branch 'master' into feat/eip1363-v5.x
Amxx 8f7c2bf
fix merge
Amxx feb824e
fix lint
Amxx af285c6
add notices
Amxx 08c8eff
Merge branch 'master' into feat/eip1363-v5.x
Amxx d9cba07
forge update
Amxx ed594f0
Update .changeset/friendly-nails-push.md
Amxx 72b0271
Merge branch 'master' into feat/eip1363-v5.x
ernestognw ab19eff
Optionally evaluate return value when calling ERC1363 using `transfer…
ernestognw 5efabe6
Apply review comments
ernestognw 07f1e4d
Update test/token/ERC20/utils/SafeERC20.test.js
Amxx fb78a86
Update test/token/ERC20/utils/SafeERC20.test.js
Amxx 8639885
check values
Amxx 10f4d1d
test SafeERC20 against non compliant ERC1363 tokens
Amxx 327aca5
lint
Amxx cba6a94
Nits
ernestognw 6747cb8
Add note for usdt-like approval requirements in approveAndCallRelaxed
ernestognw 96551b0
Moar nits
ernestognw 54f06e7
Improve ERC1363 tests
ernestognw 12e2952
Fix codespell
ernestognw 2c85474
final cleanup (minimize changes)
Amxx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Add ERC1363 contracts
- Loading branch information
commit 84fe15d948c1c20aed4660b79deb08a51a782383
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,33 @@ | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| pragma solidity ^0.8.20; | ||
|
|
||
| /** | ||
| * @title IERC1363Errors | ||
| * @dev Interface of the ERC1363 custom errors following the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] rationale. | ||
| */ | ||
| interface IERC1363Errors { | ||
| /** | ||
| * @dev Indicates a failure with the token `receiver` as it can't be an EOA. Used in transfers. | ||
| * @param receiver Address to which tokens are being transferred. | ||
| */ | ||
| error ERC1363EOAReceiver(address receiver); | ||
|
|
||
| /** | ||
| * @dev Indicates a failure with the token `spender` as it can't be an EOA. Used in approvals. | ||
| * @param spender Address that may be allowed to operate on tokens without being their owner. | ||
| */ | ||
| error ERC1363EOASpender(address spender); | ||
|
|
||
| /** | ||
| * @dev Indicates a failure with the token `receiver`. Used in transfers. | ||
| * @param receiver Address to which tokens are being transferred. | ||
| */ | ||
| error ERC1363InvalidReceiver(address receiver); | ||
|
|
||
| /** | ||
| * @dev Indicates a failure with the token `spender`. Used in approvals. | ||
| * @param spender Address that may be allowed to operate on tokens without being their owner. | ||
| */ | ||
| error ERC1363InvalidSpender(address spender); | ||
| } |
This file contains hidden or 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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,32 +4,29 @@ | |||||||||
| pragma solidity ^0.8.20; | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * @dev Interface for any contract that wants to support {IERC1363-transferAndCall} | ||||||||||
| * or {IERC1363-transferFromAndCall} from {ERC1363} token contracts. | ||||||||||
| * @title IERC1363Receiver | ||||||||||
| * @dev Interface for any contract that wants to support `transferAndCall` or `transferFromAndCall` | ||||||||||
| * from ERC1363 token contracts. | ||||||||||
|
||||||||||
| * @dev Interface for any contract that wants to support `transferAndCall` or `transferFromAndCall` | |
| * from ERC1363 token contracts. | |
| * @dev Interface for any contract that wants to support {IERC1363-transferAndCall} or {IERC1363-transferFromAndCall} | |
| * from {IERC1363} token contracts. |
Outdated
Member
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested change
| * @dev Whenever ERC1363 tokens are transferred to this contract via `transferAndCall` or `transferFromAndCall` | |
| * by `operator` from `from`, this function is called. | |
| * @dev Handle receipt of ERC1363 tokens after an {IERC1363-transferAndCall} or {IERC1363-transferFromAndCall} invocation. |
This file contains hidden or 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 | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,26 +4,23 @@ | |||||||
| pragma solidity ^0.8.20; | ||||||||
|
|
||||||||
| /** | ||||||||
| * @dev Interface for any contract that wants to support {IERC1363-approveAndCall} | ||||||||
| * from {ERC1363} token contracts. | ||||||||
| * @title ERC1363Spender | ||||||||
| * @dev Interface for any contract that wants to support `approveAndCall` | ||||||||
| * from ERC1363 token contracts. | ||||||||
| */ | ||||||||
| interface IERC1363Spender { | ||||||||
| /* | ||||||||
| * Note: the ERC-165 identifier for this interface is 0x7b04a2d0. | ||||||||
| * 0x7b04a2d0 === bytes4(keccak256("onApprovalReceived(address,uint256,bytes)")) | ||||||||
| */ | ||||||||
|
|
||||||||
| /** | ||||||||
| * @notice Handle the approval of ERC1363 tokens | ||||||||
| * @dev Any ERC1363 smart contract calls this function on the recipient | ||||||||
| * after an `approve`. This function MAY throw to revert and reject the | ||||||||
| * approval. Return of other than the magic value MUST result in the | ||||||||
| * transaction being reverted. | ||||||||
| * Note: the token contract address is always the message sender. | ||||||||
| * @param owner address The address which called `approveAndCall` function | ||||||||
| * @param amount uint256 The amount of tokens to be spent | ||||||||
| * @param data bytes Additional data with no specified format | ||||||||
| * @return `bytes4(keccak256("onApprovalReceived(address,uint256,bytes)"))`unless throwing | ||||||||
| * @dev Whenever an ERC1363 tokens `owner` approved this contract via `approveAndCall` | ||||||||
| * to spent their tokens, this function is called. | ||||||||
|
||||||||
| * @dev Whenever an ERC1363 tokens `owner` approved this contract via `approveAndCall` | |
| * to spent their tokens, this function is called. | |
| * @dev Handle approval receipt of ERC1363 tokens after an {IERC1363-approveAndCall} invocation. |
This file contains hidden or 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,140 @@ | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| pragma solidity ^0.8.0; | ||
|
|
||
| import {ERC20} from "../ERC20.sol"; | ||
| import {IERC165, ERC165} from "../../../utils/introspection/ERC165.sol"; | ||
|
|
||
| import {IERC1363} from "../../../interfaces/IERC1363.sol"; | ||
| import {IERC1363Errors} from "../../../interfaces/IERC1363Errors.sol"; | ||
| import {IERC1363Receiver} from "../../../interfaces/IERC1363Receiver.sol"; | ||
| import {IERC1363Spender} from "../../../interfaces/IERC1363Spender.sol"; | ||
|
|
||
| /** | ||
| * @title ERC1363 | ||
| * @dev Implementation of the ERC1363 interface. | ||
Amxx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| abstract contract ERC1363 is ERC20, ERC165, IERC1363, IERC1363Errors { | ||
| /** | ||
| * @inheritdoc IERC165 | ||
| */ | ||
| function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { | ||
| return interfaceId == type(IERC1363).interfaceId || super.supportsInterface(interfaceId); | ||
| } | ||
|
|
||
| /** | ||
| * @inheritdoc IERC1363 | ||
Amxx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| function transferAndCall(address to, uint256 value) public virtual returns (bool) { | ||
ernestognw marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return transferAndCall(to, value, ""); | ||
| } | ||
|
|
||
| /** | ||
| * @inheritdoc IERC1363 | ||
| */ | ||
| function transferAndCall(address to, uint256 value, bytes memory data) public virtual returns (bool) { | ||
| transfer(to, value); | ||
ernestognw marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| _checkOnTransferReceived(_msgSender(), to, value, data); | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * @inheritdoc IERC1363 | ||
| */ | ||
| function transferFromAndCall(address from, address to, uint256 value) public virtual returns (bool) { | ||
ernestognw marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return transferFromAndCall(from, to, value, ""); | ||
| } | ||
|
|
||
| /** | ||
| * @inheritdoc IERC1363 | ||
| */ | ||
| function transferFromAndCall( | ||
| address from, | ||
| address to, | ||
| uint256 value, | ||
| bytes memory data | ||
| ) public virtual returns (bool) { | ||
| transferFrom(from, to, value); | ||
| _checkOnTransferReceived(from, to, value, data); | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * @inheritdoc IERC1363 | ||
| */ | ||
| function approveAndCall(address spender, uint256 value) public virtual returns (bool) { | ||
ernestognw marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return approveAndCall(spender, value, ""); | ||
| } | ||
|
|
||
| /** | ||
| * @inheritdoc IERC1363 | ||
| */ | ||
| function approveAndCall(address spender, uint256 value, bytes memory data) public virtual returns (bool) { | ||
| approve(spender, value); | ||
| _checkOnApprovalReceived(spender, value, data); | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * @dev Private function to invoke `onTransferReceived` on a target address. | ||
Amxx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * This will revert if the target doesn't implement the `IERC1363Receiver` interface or | ||
Amxx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * if the target doesn't accept the token transfer or | ||
| * if the target address is not a contract. | ||
| * | ||
| * @param from Address representing the previous owner of the given token amount. | ||
| * @param to Target address that will receive the tokens. | ||
| * @param value The amount of tokens to be transferred. | ||
| * @param data Optional data to send along with the call. | ||
Amxx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| function _checkOnTransferReceived(address from, address to, uint256 value, bytes memory data) private { | ||
| if (to.code.length == 0) { | ||
| revert ERC1363EOAReceiver(to); | ||
| } | ||
|
|
||
| try IERC1363Receiver(to).onTransferReceived(_msgSender(), from, value, data) returns (bytes4 retval) { | ||
| if (retval != IERC1363Receiver.onTransferReceived.selector) { | ||
| revert ERC1363InvalidReceiver(to); | ||
| } | ||
| } catch (bytes memory reason) { | ||
| if (reason.length == 0) { | ||
| revert ERC1363InvalidReceiver(to); | ||
| } else { | ||
| /// @solidity memory-safe-assembly | ||
| assembly { | ||
| revert(add(32, reason), mload(reason)) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @dev Private function to invoke `onApprovalReceived` on a target address. | ||
Amxx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * This will revert if the target doesn't implement the `IERC1363Spender` interface or | ||
Amxx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * if the target doesn't accept the token approval or | ||
| * if the target address is not a contract. | ||
| * | ||
| * @param spender The address which will spend the funds. | ||
| * @param value The amount of tokens to be spent. | ||
| * @param data Optional data to send along with the call. | ||
Amxx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| function _checkOnApprovalReceived(address spender, uint256 value, bytes memory data) private { | ||
| if (spender.code.length == 0) { | ||
| revert ERC1363EOASpender(spender); | ||
| } | ||
|
|
||
| try IERC1363Spender(spender).onApprovalReceived(_msgSender(), value, data) returns (bytes4 retval) { | ||
| if (retval != IERC1363Spender.onApprovalReceived.selector) { | ||
| revert ERC1363InvalidSpender(spender); | ||
| } | ||
| } catch (bytes memory reason) { | ||
| if (reason.length == 0) { | ||
| revert ERC1363InvalidSpender(spender); | ||
| } else { | ||
| /// @solidity memory-safe-assembly | ||
| assembly { | ||
| revert(add(32, reason), mload(reason)) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.