diff --git a/assets/eip-6774/README.md b/assets/eip-6774/README.md index 252fd9ab167ad0..51157f7d330ee6 100644 --- a/assets/eip-6774/README.md +++ b/assets/eip-6774/README.md @@ -1,17 +1,17 @@ -# Reference implementations of ERC-N +# Reference implementations of ERC-6774 ## Contract -**ERC-N implementations:** +**ERC-6774 implementations:** -- [IERC_N.sol](./contracts/IERC_N.sol): interface of `ERC_N` -- [ERC_N.sol](./contracts/ERC_N.sol): a simple and minimal implementation for one-to-one barter type -- [ERC_NMultiBarter.sol](./contracts/extensions/ERC_NMultiBarter.sol): an extensions of `ERC_N.sol` for barter several token belonging to the same contract +- [IERC6774.sol](./contracts/IERC6774.sol): interface of `ERC6774` +- [ERC6774.sol](./contracts/ERC6774.sol): a simple and minimal implementation for one-to-one barter type +- [ERC6774MultiBarter.sol](./contracts/extensions/ERC6774MultiBarter.sol): an extensions of `ERC6774.sol` for barter several token belonging to the same contract **Mocks contracts:** -- [PermissionlessERC_N.sol](./contracts/mocks/PermissionlessERC_N.sol): an exemple of implementation of `ERC_N` -- [PermissionlessERC_NMultiBarter.sol](./contracts/mocks/PermissionlessERC_NMultiBarter.sol): an exemple of implementation of `ERC_NMultiBarter` +- [PermissionlessERC6774.sol](./contracts/mocks/PermissionlessERC6774.sol): an exemple of implementation of `ERC6774` +- [PermissionlessERC6774MultiBarter.sol](./contracts/mocks/PermissionlessERC6774MultiBarter.sol): an exemple of implementation of `ERC6774MultiBarter` _These contract are used in `test`_ diff --git a/assets/eip-6774/contracts/ERC_N.sol b/assets/eip-6774/contracts/ERC6774.sol similarity index 95% rename from assets/eip-6774/contracts/ERC_N.sol rename to assets/eip-6774/contracts/ERC6774.sol index 61ef86fb0e16a7..4f3401d54d6152 100644 --- a/assets/eip-6774/contracts/ERC_N.sol +++ b/assets/eip-6774/contracts/ERC6774.sol @@ -6,9 +6,9 @@ import {ERC721, IERC721} from "openzeppelin-contracts/contracts/token/ERC721/ERC import {EIP712} from "openzeppelin-contracts/contracts/utils/cryptography/EIP712.sol"; import {ECDSA} from "openzeppelin-contracts/contracts/utils/cryptography/ECDSA.sol"; -import {IERC_N} from "./IERC_N.sol"; +import {IERC6774} from "./IERC6774.sol"; -contract ERC_N is ERC721, EIP712, IERC_N { +contract ERC6774 is ERC721, EIP712, IERC6774 { using ECDSA for bytes32; error BarterNotEnabled(address tokenAddr); @@ -51,12 +51,12 @@ contract ERC_N is ERC721, EIP712, IERC_N { PUBLIC FUNCTIONS ////////////////////////////////////////////////////////////////////////////////////////////////*/ - /// @dev See {IERC_N-barter} + /// @dev See {IERC6774-barter} function barter( BarterTerms memory data, bytes memory signature ) external onlyExchangeable(data.bid.tokenAddr) { - IERC_N(data.bid.tokenAddr).transferFor(data, msg.sender, signature); + IERC6774(data.bid.tokenAddr).transferFor(data, msg.sender, signature); // transfer ask token if (!_isApprovedOrOwner(msg.sender, data.ask.tokenId)) @@ -64,7 +64,7 @@ contract ERC_N is ERC721, EIP712, IERC_N { _transfer(msg.sender, data.owner, data.ask.tokenId); } - /// @dev See {IERC_N-transferFor} + /// @dev See {IERC6774-transferFor} function transferFor( BarterTerms memory data, address to, @@ -88,12 +88,12 @@ contract ERC_N is ERC721, EIP712, IERC_N { GETTERS ////////////////////////////////////////////////////////////////////////////////////////////////*/ - /// @dev See {IERC_N-nonce} + /// @dev See {IERC6774-nonce} function nonce(address account) external view returns (uint256) { return _nonces[account]; } - /// @dev See {IERC_N-isBarterable} + /// @dev See {IERC6774-isBarterable} function isBarterable(address tokenAddr) external view returns (bool) { return _barterables[tokenAddr]; } diff --git a/assets/eip-6774/contracts/IERC_N.sol b/assets/eip-6774/contracts/IERC6774.sol similarity index 99% rename from assets/eip-6774/contracts/IERC_N.sol rename to assets/eip-6774/contracts/IERC6774.sol index b6e7b7eba15a89..5f5357551dfebe 100644 --- a/assets/eip-6774/contracts/IERC_N.sol +++ b/assets/eip-6774/contracts/IERC6774.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.13; -interface IERC_N { +interface IERC6774 { /** * @dev Emitted when a `tokenAddr` is settled as barterable (`barterable` == true) * or stopped from being barterable (`barterable` == false) diff --git a/assets/eip-6774/contracts/extensions/ERC_NMultiBarter.sol b/assets/eip-6774/contracts/extensions/ERC6774MultiBarter.sol similarity index 95% rename from assets/eip-6774/contracts/extensions/ERC_NMultiBarter.sol rename to assets/eip-6774/contracts/extensions/ERC6774MultiBarter.sol index 2a71a9fb3837d3..31fc9edc440829 100644 --- a/assets/eip-6774/contracts/extensions/ERC_NMultiBarter.sol +++ b/assets/eip-6774/contracts/extensions/ERC6774MultiBarter.sol @@ -2,9 +2,9 @@ pragma solidity ^0.8.13; -import {ERC_N, IERC_N} from "../ERC_N.sol"; +import {ERC6774, IERC6774} from "../ERC6774.sol"; -contract ERC_NMultiBarter is ERC_N { +contract ERC6774MultiBarter is ERC6774 { struct MultiComponant { address tokenAddr; uint256[] tokenIds; @@ -27,7 +27,7 @@ contract ERC_NMultiBarter is ERC_N { constructor( string memory _name, string memory _symbol - ) ERC_N(_name, _symbol) { + ) ERC6774(_name, _symbol) { MULTI_COMPONANT_TYPEHASH = keccak256( abi.encodePacked( "MultiComponant(address tokenAddr,uint256[] tokenIds)" @@ -48,7 +48,7 @@ contract ERC_NMultiBarter is ERC_N { MultiBarterTerms memory data, bytes memory signature ) external onlyExchangeable(data.bid.tokenAddr) { - ERC_NMultiBarter(data.bid.tokenAddr).transferFor( + ERC6774MultiBarter(data.bid.tokenAddr).transferFor( data, msg.sender, signature diff --git a/assets/eip-6774/contracts/mocks/PermissionlessERC_N.sol b/assets/eip-6774/contracts/mocks/PermissionlessERC6774.sol similarity index 87% rename from assets/eip-6774/contracts/mocks/PermissionlessERC_N.sol rename to assets/eip-6774/contracts/mocks/PermissionlessERC6774.sol index fd1047c5e7dbe4..d3d49d6ea69199 100644 --- a/assets/eip-6774/contracts/mocks/PermissionlessERC_N.sol +++ b/assets/eip-6774/contracts/mocks/PermissionlessERC6774.sol @@ -2,16 +2,16 @@ pragma solidity ^0.8.13; -import {ERC_N} from "../ERC_N.sol"; +import {ERC6774} from "../ERC6774.sol"; -contract PermissionlessERC_N is ERC_N { +contract PermissionlessERC6774 is ERC6774 { string internal ipfsHash; constructor( string memory _name, string memory _symbol, string memory _ipfsHash - ) ERC_N(_name, _symbol) { + ) ERC6774(_name, _symbol) { ipfsHash = _ipfsHash; } diff --git a/assets/eip-6774/contracts/mocks/PermissionlessERC_NMultiBarter.sol b/assets/eip-6774/contracts/mocks/PermissionlessERC6774MultiBarter.sol similarity index 81% rename from assets/eip-6774/contracts/mocks/PermissionlessERC_NMultiBarter.sol rename to assets/eip-6774/contracts/mocks/PermissionlessERC6774MultiBarter.sol index 00aba5042903eb..93c3234fde31e7 100644 --- a/assets/eip-6774/contracts/mocks/PermissionlessERC_NMultiBarter.sol +++ b/assets/eip-6774/contracts/mocks/PermissionlessERC6774MultiBarter.sol @@ -2,16 +2,16 @@ pragma solidity ^0.8.13; -import {ERC_NMultiBarter} from "../extensions/ERC_NMultiBarter.sol"; +import {ERC6774MultiBarter} from "../extensions/ERC6774MultiBarter.sol"; -contract PermissionlessERC_NMultiBarter is ERC_NMultiBarter { +contract PermissionlessERC6774MultiBarter is ERC6774MultiBarter { string internal ipfsHash; constructor( string memory _name, string memory _symbol, string memory _ipfsHash - ) ERC_NMultiBarter(_name, _symbol) { + ) ERC6774MultiBarter(_name, _symbol) { ipfsHash = _ipfsHash; } diff --git a/assets/eip-6774/test/ERCN.t.sol b/assets/eip-6774/test/ERC6774.t.sol similarity index 90% rename from assets/eip-6774/test/ERCN.t.sol rename to assets/eip-6774/test/ERC6774.t.sol index 70852723d019ba..c0d6fc7fed898d 100644 --- a/assets/eip-6774/test/ERCN.t.sol +++ b/assets/eip-6774/test/ERC6774.t.sol @@ -5,16 +5,16 @@ pragma solidity ^0.8.13; import "forge-std/Test.sol"; import {Utils} from "./Utils.t.sol"; -import {PermissionlessERC_NMultiBarter} from "../contracts/mocks/PermissionlessERC_NMultiBarter.sol"; -import {IERC_N} from "../contracts/IERC_N.sol"; +import {PermissionlessERC6774MultiBarter} from "../contracts/mocks/PermissionlessERC6774MultiBarter.sol"; +import {IERC6774} from "../contracts/IERC6774.sol"; -contract ERCN_test is Test, Utils { +contract ERC6774_test is Test, Utils { using stdStorage for StdStorage; // tokens - PermissionlessERC_NMultiBarter internal ticket; + PermissionlessERC6774MultiBarter internal ticket; address internal TICKET; - PermissionlessERC_NMultiBarter internal discount; + PermissionlessERC6774MultiBarter internal discount; address internal DISCOUNT; // users and their private keys @@ -29,9 +29,9 @@ contract ERCN_test is Test, Utils { function setUp() public { // deploy tokens - ticket = new PermissionlessERC_NMultiBarter("Ticket", "00", ""); + ticket = new PermissionlessERC6774MultiBarter("Ticket", "00", ""); TICKET = address(ticket); - discount = new PermissionlessERC_NMultiBarter("Discount", "01", ""); + discount = new PermissionlessERC6774MultiBarter("Discount", "01", ""); DISCOUNT = address(discount); // enable barters @@ -67,7 +67,7 @@ contract ERCN_test is Test, Utils { discount.mint(USER2, 12); ( - IERC_N.BarterTerms memory data, + IERC6774.BarterTerms memory data, bytes memory signature ) = workaround_User1Ask(DISCOUNT, 12); @@ -86,7 +86,7 @@ contract ERCN_test is Test, Utils { discount.mint(USER2, 12); ( - IERC_N.BarterTerms memory data, + IERC6774.BarterTerms memory data, bytes memory signature ) = workaround_User1Ask(DISCOUNT, 12); @@ -121,7 +121,7 @@ contract ERCN_test is Test, Utils { ticket.mint(USER2, 50); ( - IERC_N.BarterTerms memory data, + IERC6774.BarterTerms memory data, bytes memory signature ) = workaround_User1Ask(TICKET, 50); @@ -138,7 +138,7 @@ contract ERCN_test is Test, Utils { ticket.enableBarterWith(TICKET); ( - IERC_N.BarterTerms memory data, + IERC6774.BarterTerms memory data, bytes memory signature ) = workaround_User1Ask(TICKET, 50); @@ -154,7 +154,7 @@ contract ERCN_test is Test, Utils { discount.mint(USER2, 12); ( - IERC_N.BarterTerms memory data, + IERC6774.BarterTerms memory data, bytes memory signature ) = workaround_User1Ask(DISCOUNT, 12); @@ -189,7 +189,7 @@ contract ERCN_test is Test, Utils { function test_barter_CannotUseAnExpiredSignature() public { vm.warp(1000); ( - IERC_N.BarterTerms memory data, + IERC6774.BarterTerms memory data, bytes32 structHash ) = workaround_CreateBarterTerms({ bidTokenAddr: TICKET, @@ -232,7 +232,7 @@ contract ERCN_test is Test, Utils { discount.mint(USER4, 4); ( - PermissionlessERC_NMultiBarter.MultiBarterTerms memory data, + PermissionlessERC6774MultiBarter.MultiBarterTerms memory data, bytes memory signature ) = workaround_User3Ask(); @@ -269,7 +269,7 @@ contract ERCN_test is Test, Utils { discount.mint(USER4, 4); ( - PermissionlessERC_NMultiBarter.MultiBarterTerms memory data, + PermissionlessERC6774MultiBarter.MultiBarterTerms memory data, bytes memory signature ) = workaround_User4TryWithEmptyBid(); @@ -284,9 +284,9 @@ contract ERCN_test is Test, Utils { function workaround_User1Ask( address tokenAddr, uint256 tokenId - ) internal view returns (IERC_N.BarterTerms memory, bytes memory) { + ) internal view returns (IERC6774.BarterTerms memory, bytes memory) { ( - IERC_N.BarterTerms memory data, + IERC6774.BarterTerms memory data, bytes32 structHash ) = workaround_CreateBarterTerms({ bidTokenAddr: TICKET, @@ -315,7 +315,7 @@ contract ERCN_test is Test, Utils { internal view returns ( - PermissionlessERC_NMultiBarter.MultiBarterTerms memory data, + PermissionlessERC6774MultiBarter.MultiBarterTerms memory data, bytes memory ) { @@ -356,7 +356,7 @@ contract ERCN_test is Test, Utils { internal view returns ( - PermissionlessERC_NMultiBarter.MultiBarterTerms memory data, + PermissionlessERC6774MultiBarter.MultiBarterTerms memory data, bytes memory ) { diff --git a/assets/eip-6774/test/Utils.t.sol b/assets/eip-6774/test/Utils.t.sol index f167971459d8da..f13bddcc54a0f4 100644 --- a/assets/eip-6774/test/Utils.t.sol +++ b/assets/eip-6774/test/Utils.t.sol @@ -2,9 +2,9 @@ pragma solidity ^0.8.13; -import {PermissionlessERC_NMultiBarter} from "../contracts/mocks/PermissionlessERC_NMultiBarter.sol"; -import {IERC_N} from "../contracts/IERC_N.sol"; -import {ERC_NMultiBarter} from "../contracts/extensions/ERC_NMultiBarter.sol"; +import {PermissionlessERC6774MultiBarter} from "../contracts/mocks/PermissionlessERC6774MultiBarter.sol"; +import {IERC6774} from "../contracts/IERC6774.sol"; +import {ERC6774MultiBarter} from "../contracts/extensions/ERC6774MultiBarter.sol"; contract Utils { bytes32 internal constant EIP712_TYPEHASH = @@ -82,19 +82,15 @@ contract Utils { internal pure returns ( - PermissionlessERC_NMultiBarter.BarterTerms memory data, + PermissionlessERC6774MultiBarter.BarterTerms memory data, bytes32 structHash ) { - PermissionlessERC_NMultiBarter.Componant memory bid = IERC_N.Componant({ - tokenAddr: bidTokenAddr, - tokenId: bidTokenId - }); - PermissionlessERC_NMultiBarter.Componant memory ask = IERC_N.Componant({ - tokenAddr: askTokenAddr, - tokenId: askTokenId - }); - data = IERC_N.BarterTerms(bid, ask, nonce, owner, deadline); + PermissionlessERC6774MultiBarter.Componant memory bid = IERC6774 + .Componant({tokenAddr: bidTokenAddr, tokenId: bidTokenId}); + PermissionlessERC6774MultiBarter.Componant memory ask = IERC6774 + .Componant({tokenAddr: askTokenAddr, tokenId: askTokenId}); + data = IERC6774.BarterTerms(bid, ask, nonce, owner, deadline); bytes32 bidStructHash = keccak256( abi.encode(COMPONANT_TYPEHASH, bidTokenAddr, bidTokenId) @@ -126,21 +122,21 @@ contract Utils { internal pure returns ( - PermissionlessERC_NMultiBarter.MultiBarterTerms memory data, + PermissionlessERC6774MultiBarter.MultiBarterTerms memory data, bytes32 structHash ) { - PermissionlessERC_NMultiBarter.MultiComponant - memory bid = ERC_NMultiBarter.MultiComponant({ + PermissionlessERC6774MultiBarter.MultiComponant + memory bid = ERC6774MultiBarter.MultiComponant({ tokenAddr: bidTokenAddr, tokenIds: bidTokenIds }); - PermissionlessERC_NMultiBarter.MultiComponant - memory ask = ERC_NMultiBarter.MultiComponant({ + PermissionlessERC6774MultiBarter.MultiComponant + memory ask = ERC6774MultiBarter.MultiComponant({ tokenAddr: askTokenAddr, tokenIds: askTokenIds }); - data = ERC_NMultiBarter.MultiBarterTerms( + data = ERC6774MultiBarter.MultiBarterTerms( bid, ask, nonce,