From 09ff15ccf2404a23bfcec4c31179b9ab729d44af Mon Sep 17 00:00:00 2001 From: Otniel Nicola Date: Mon, 27 Mar 2023 12:36:46 +0300 Subject: [PATCH] Add EIP-5678: Add new utilities extension for ERC-721 (#5678) --- EIPS/eip-5678.md | 202 +++++++++ assets/eip-5678/.gitignore | 6 + assets/eip-5678/LICENSE | 121 +++++ assets/eip-5678/README.MD | 30 ++ assets/eip-5678/abi/ERC5678.json | 475 ++++++++++++++++++++ assets/eip-5678/abi/IERC5678.json | 77 ++++ assets/eip-5678/contracts/ERC5678.sol | 45 ++ assets/eip-5678/contracts/IERC5678.sol | 27 ++ assets/eip-5678/hardhat.config.js | 22 + assets/eip-5678/package.json | 23 + assets/eip-5678/scripts/deploy_contracts.js | 18 + assets/eip-5678/test/ERC5678.test.js | 53 +++ 12 files changed, 1099 insertions(+) create mode 100644 EIPS/eip-5678.md create mode 100644 assets/eip-5678/.gitignore create mode 100644 assets/eip-5678/LICENSE create mode 100644 assets/eip-5678/README.MD create mode 100644 assets/eip-5678/abi/ERC5678.json create mode 100644 assets/eip-5678/abi/IERC5678.json create mode 100644 assets/eip-5678/contracts/ERC5678.sol create mode 100644 assets/eip-5678/contracts/IERC5678.sol create mode 100644 assets/eip-5678/hardhat.config.js create mode 100644 assets/eip-5678/package.json create mode 100644 assets/eip-5678/scripts/deploy_contracts.js create mode 100644 assets/eip-5678/test/ERC5678.test.js diff --git a/EIPS/eip-5678.md b/EIPS/eip-5678.md new file mode 100644 index 00000000000000..17442e3f872bc5 --- /dev/null +++ b/EIPS/eip-5678.md @@ -0,0 +1,202 @@ +--- +title: ERC-5678 - ERC-721 Utilities Extension +description: Easy access to utility information via functions and the NFT's metadata +author: Otniel Nicola (@OT-kthd), Bogdan Popa (@BogdanKTHD) +discussions-to: https://ethereum-magicians.org/t/eip-5678-erc-721-utilities-extension/13568 +status: Draft +type: Standards Track +category: ERC +created: 2023-03-27 +requires: 165, 721 +--- + +## Abstract + +This specification defines standard functions that outline what a utility entails for a specific NFT and how it may be +used. This specification is an optional extension of [EIP-721](./eip-721.md). + +## Motivation + +This specification aims to bring clarity what the utility associated with an NFT is and how to access this utility. +Relying on third-party platforms to obtain information regarding the utility of the NFT that one owns can lead to scams, +phishing or other forms of fraud. + +## Specification + +The keywords “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and +“OPTIONAL” in this document are to be interpreted as described in RFC 2119. + +Every contract compliant with EIP-5678 MUST implement the IERC5678 interface defined as follows: + +### Contract Interface + +```solidity +// @title NFT Utility description +/// Note: the EIP-165 identifier for this interface is 0xbcc08bd0 + +interface IERC5678 { + + // Logged when the utility description URL of an NFT is changed + /// @notice Emitted when the utilityURL of an NFT is changed + /// The empty string for `utilityUri` indicates that there is no utility associated + event UpdateUtility(uint256 indexed tokenId, string utilityUri); + + /// @notice set the new utilityUri - remember the date it was set on + /// @dev The empty string indicates there is no utility + /// Throws if `tokenId` is not valid NFT + /// @param utilityUri The new utility description of the NFT + /// 324a28b4 + function setUtilityUri(uint256 tokenId, string utilityUri) external; + + /// @notice Get the utilityUri of an NFT + /// @dev The empty string for `utilityUri` indicates that there is no utility associated + /// @param tokenId The NFT to get the user address for + /// @return The utility uri for this NFT + /// 438b8582 + function getUtilityUri(uint256 tokenId) external view returns (string memory); + + /// @notice Get the changes made to utilityUri + /// @param tokenId The NFT to get the user address for + /// @return The history of changes to `utilityUri` for this NFT + /// af5a3ae2 + function getUtilityHistory(uint256 tokenId) external view returns (string[] memory); +} +``` + +All functions defined as view MAY be implemented as pure or view + +Function `setUtilityUri` MAY be implemented as public or external + +The event `UpdateUtility` MUST be emitted when the setUtilityUri function is called + +The supportsInterface method MUST return true when called with `0xbcc08bd0` + +The original metadata SHOULD conform to the “ERC-5678 Metadata with utilities JSON Schema” which is a compatible +extension of the “ERC-721 Metadata JSON Schema” defined in `ERC-721`. + +“ERC-5678 Metadata with utilities JSON Schema” : + +```json +{ + "title": "Asset Metadata", + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "Identifies the asset to which this NFT represents" + }, + "description": { + "type": "string", + "description": "Describes the asset to which this NFT represents" + }, + "image": { + "type": "string", + "description": "A URI pointing to a resource with mime type image/* representing the asset to which this NFT represents. Consider making any images at a width between 320 and 1080 pixels and aspect ratio between 1.91:1 and 4:5 inclusive." + }, + "utilities": { + "type": "object", + "required": [ + "type", + "description", + "t&c" + ], + "properties": { + "type": { + "type": "string", + "description": "Describes what type of utility this is" + }, + "description": { + "type": "string", + "description": "A brief description of the utility" + }, + "properties": { + "type": "array", + "description": "An array of possible properties describing the utility, defined as key-value pairs", + "items": { + "type": "object" + } + }, + "expiry": { + "type": "number", + "description": "The period of time for the validity of the utility, since the minting of the NFT. Expressed in seconds" + }, + "t&c": { + "type": "string", + "description": "" + } + } + } + } +} +``` + +## Rationale + +Currently, utilities that are offered with NFTs, are not captured on-chain. We want the utility of an NFT to be part of +the metadata of an NFT, and thus immutable. The metadata information would include: a) type of utility, b) description +of utility, c) frequency and duration of utility, and d) expiration of utility. This will provide transparency as to the +utility terms, and greater accountability on the creator to honor these utilities. + +Instructions on how to access the utility should be available to the owner of an NFT, as it reduces the dependency on +third-party platforms and the possibility for fraud because the `utilityUri` containing the instructions can only come +from the entity that provides or facilitates the utility. Thus, the ability to set the `utilityUri` should be restricted +to the creator who's offering the utility. Since the `utilityUri` contains information that could be restricted to some +level and is dependent on a third party platform, the creator needs the ability to modify it in the event the platform +becomes unavailable or inaccessible. + +As the instructions on how to access a given utility may change over time, there should be a historical record of these +changes for transparency. + +For example, if a creator sells an NFT that gives holders a right to a video call with the creator, the metadata for +this utility NFT would read as follows: + +```json +{ + "name": "...", + "description": "...", + "image": "...", + "utilities": { + "type": "Video call", + "description": "I will enter a private video call with whoever owns the NFT", + "properties": [ + { + "sessions": 2 + }, + { + "duration": 30 + }, + { + "time_unit": "minutes" + } + ], + "expiry": 1.577e+7, + "t&c": "https://...." + } +} +``` + +In order to get access to the details needed to enter the video call, the owner would access the URI returned by +the `getUtilityUri` method for the NFT that they own. Additionally, access to the details could be conditioned by the +authentication with the wallet that owns the NFT. +The current status of the utility would also be included in the URI (eg: how many sessions are still available, etc.) + +## Backwards Compatibility + +This standard is compatible with current EIP-721 standard. There are no other standards that define similar methods for +NFTs and the method names are not used by other EIP-721 related standards. + +## Test Cases + +Test cases are available [here](../assets/eip-5678/test/ERC5678.test.js) + +## Reference Implementation + +The reference implementation can be found [here](../assets/eip-5678/contracts/ERC5678.sol). + +## Security Considerations + +There are no security considerations related directly to the implementation of this standard. + +## Copyright + +Copyright and related rights waived via [CC0](../assets/eip-5678/LICENSE). diff --git a/assets/eip-5678/.gitignore b/assets/eip-5678/.gitignore new file mode 100644 index 00000000000000..1ca7abfd3c8ddd --- /dev/null +++ b/assets/eip-5678/.gitignore @@ -0,0 +1,6 @@ +node_modules +package-lock.json + +#Hardhat files +cache +artifacts diff --git a/assets/eip-5678/LICENSE b/assets/eip-5678/LICENSE new file mode 100644 index 00000000000000..1625c179360799 --- /dev/null +++ b/assets/eip-5678/LICENSE @@ -0,0 +1,121 @@ +Creative Commons Legal Code + +CC0 1.0 Universal + + CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE + LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN + ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS + INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES + REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS + PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM + THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED + HEREUNDER. + +Statement of Purpose + +The laws of most jurisdictions throughout the world automatically confer +exclusive Copyright and Related Rights (defined below) upon the creator +and subsequent owner(s) (each and all, an "owner") of an original work of +authorship and/or a database (each, a "Work"). + +Certain owners wish to permanently relinquish those rights to a Work for +the purpose of contributing to a commons of creative, cultural and +scientific works ("Commons") that the public can reliably and without fear +of later claims of infringement build upon, modify, incorporate in other +works, reuse and redistribute as freely as possible in any form whatsoever +and for any purposes, including without limitation commercial purposes. +These owners may contribute to the Commons to promote the ideal of a free +culture and the further production of creative, cultural and scientific +works, or to gain reputation or greater distribution for their Work in +part through the use and efforts of others. + +For these and/or other purposes and motivations, and without any +expectation of additional consideration or compensation, the person +associating CC0 with a Work (the "Affirmer"), to the extent that he or she +is an owner of Copyright and Related Rights in the Work, voluntarily +elects to apply CC0 to the Work and publicly distribute the Work under its +terms, with knowledge of his or her Copyright and Related Rights in the +Work and the meaning and intended legal effect of CC0 on those rights. + +1. Copyright and Related Rights. A Work made available under CC0 may be +protected by copyright and related or neighboring rights ("Copyright and +Related Rights"). Copyright and Related Rights include, but are not +limited to, the following: + + i. the right to reproduce, adapt, distribute, perform, display, + communicate, and translate a Work; + ii. moral rights retained by the original author(s) and/or performer(s); +iii. publicity and privacy rights pertaining to a person's image or + likeness depicted in a Work; + iv. rights protecting against unfair competition in regards to a Work, + subject to the limitations in paragraph 4(a), below; + v. rights protecting the extraction, dissemination, use and reuse of data + in a Work; + vi. database rights (such as those arising under Directive 96/9/EC of the + European Parliament and of the Council of 11 March 1996 on the legal + protection of databases, and under any national implementation + thereof, including any amended or successor version of such + directive); and +vii. other similar, equivalent or corresponding rights throughout the + world based on applicable law or treaty, and any national + implementations thereof. + +2. Waiver. To the greatest extent permitted by, but not in contravention +of, applicable law, Affirmer hereby overtly, fully, permanently, +irrevocably and unconditionally waives, abandons, and surrenders all of +Affirmer's Copyright and Related Rights and associated claims and causes +of action, whether now known or unknown (including existing as well as +future claims and causes of action), in the Work (i) in all territories +worldwide, (ii) for the maximum duration provided by applicable law or +treaty (including future time extensions), (iii) in any current or future +medium and for any number of copies, and (iv) for any purpose whatsoever, +including without limitation commercial, advertising or promotional +purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each +member of the public at large and to the detriment of Affirmer's heirs and +successors, fully intending that such Waiver shall not be subject to +revocation, rescission, cancellation, termination, or any other legal or +equitable action to disrupt the quiet enjoyment of the Work by the public +as contemplated by Affirmer's express Statement of Purpose. + +3. Public License Fallback. Should any part of the Waiver for any reason +be judged legally invalid or ineffective under applicable law, then the +Waiver shall be preserved to the maximum extent permitted taking into +account Affirmer's express Statement of Purpose. In addition, to the +extent the Waiver is so judged Affirmer hereby grants to each affected +person a royalty-free, non transferable, non sublicensable, non exclusive, +irrevocable and unconditional license to exercise Affirmer's Copyright and +Related Rights in the Work (i) in all territories worldwide, (ii) for the +maximum duration provided by applicable law or treaty (including future +time extensions), (iii) in any current or future medium and for any number +of copies, and (iv) for any purpose whatsoever, including without +limitation commercial, advertising or promotional purposes (the +"License"). The License shall be deemed effective as of the date CC0 was +applied by Affirmer to the Work. Should any part of the License for any +reason be judged legally invalid or ineffective under applicable law, such +partial invalidity or ineffectiveness shall not invalidate the remainder +of the License, and in such case Affirmer hereby affirms that he or she +will not (i) exercise any of his or her remaining Copyright and Related +Rights in the Work or (ii) assert any associated claims and causes of +action with respect to the Work, in either case contrary to Affirmer's +express Statement of Purpose. + +4. Limitations and Disclaimers. + + a. No trademark or patent rights held by Affirmer are waived, abandoned, + surrendered, licensed or otherwise affected by this document. + b. Affirmer offers the Work as-is and makes no representations or + warranties of any kind concerning the Work, express, implied, + statutory or otherwise, including without limitation warranties of + title, merchantability, fitness for a particular purpose, non + infringement, or the absence of latent or other defects, accuracy, or + the present or absence of errors, whether or not discoverable, all to + the greatest extent permissible under applicable law. + c. Affirmer disclaims responsibility for clearing rights of other persons + that may apply to the Work or any use thereof, including without + limitation any person's Copyright and Related Rights in the Work. + Further, Affirmer disclaims responsibility for obtaining any necessary + consents, permissions or other rights required for any use of the + Work. + d. Affirmer understands and acknowledges that Creative Commons is not a + party to this document and has no duty or obligation with respect to + this CC0 or use of the Work. \ No newline at end of file diff --git a/assets/eip-5678/README.MD b/assets/eip-5678/README.MD new file mode 100644 index 00000000000000..57cde34b5f69ba --- /dev/null +++ b/assets/eip-5678/README.MD @@ -0,0 +1,30 @@ +
+ +# ERC-721 Utilities Extension + + +[![License: CC0-1.0](https://img.shields.io/badge/License-CC0-yellow.svg)](https://creativecommons.org/publicdomain/zero/1.0/) + +
+ +This project provides a reference implementation of the proposed `ERC-721 Utilities Extenstion` OPTIONAL extension. + +## Install + +In order to install the required dependencies you need to execute: +```shell +npm install +``` + +## Compile + +In order to compile the solidity contracts you need to execute: +```shell +npx hardhat compile +``` + +## Tests + +```shell +npx hardhat test +``` \ No newline at end of file diff --git a/assets/eip-5678/abi/ERC5678.json b/assets/eip-5678/abi/ERC5678.json new file mode 100644 index 00000000000000..a56187a7f989cc --- /dev/null +++ b/assets/eip-5678/abi/ERC5678.json @@ -0,0 +1,475 @@ +[ + { + "inputs": [ + { + "internalType": "string", + "name": "name_", + "type": "string" + }, + { + "internalType": "string", + "name": "symbol_", + "type": "string" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "approved", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "operator", + "type": "address" + }, + { + "indexed": false, + "internalType": "bool", + "name": "approved", + "type": "bool" + } + ], + "name": "ApprovalForAll", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "string", + "name": "utilityUri", + "type": "string" + } + ], + "name": "UpdateUtility", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "approve", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + } + ], + "name": "balanceOf", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "getApproved", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "getUtilityHistory", + "outputs": [ + { + "internalType": "string[]", + "name": "", + "type": "string[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "getUtilityUri", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "internalType": "address", + "name": "operator", + "type": "address" + } + ], + "name": "isApprovedForAll", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "name", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "ownerOf", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "safeTransferFrom", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "safeTransferFrom", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "operator", + "type": "address" + }, + { + "internalType": "bool", + "name": "approved", + "type": "bool" + } + ], + "name": "setApprovalForAll", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + }, + { + "internalType": "string", + "name": "utilityUri", + "type": "string" + } + ], + "name": "setUtilityUri", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes4", + "name": "interfaceId", + "type": "bytes4" + } + ], + "name": "supportsInterface", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "symbol", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "tokenURI", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "transferFrom", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/assets/eip-5678/abi/IERC5678.json b/assets/eip-5678/abi/IERC5678.json new file mode 100644 index 00000000000000..3ca1440ea40846 --- /dev/null +++ b/assets/eip-5678/abi/IERC5678.json @@ -0,0 +1,77 @@ +[ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "string", + "name": "utilityUri", + "type": "string" + } + ], + "name": "UpdateUtility", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "getUtilityHistory", + "outputs": [ + { + "internalType": "string[]", + "name": "", + "type": "string[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "getUtilityUri", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + }, + { + "internalType": "string", + "name": "utilityUri", + "type": "string" + } + ], + "name": "setUtilityUri", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/assets/eip-5678/contracts/ERC5678.sol b/assets/eip-5678/contracts/ERC5678.sol new file mode 100644 index 00000000000000..37b9564ee57249 --- /dev/null +++ b/assets/eip-5678/contracts/ERC5678.sol @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: CC0 +pragma solidity ^0.8.0; + +import "@openzeppelin/contracts/utils/introspection/ERC165.sol"; +import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "./IERC5678.sol"; + +contract ERC5678 is ERC721, Ownable, IERC5678 { + + /* + * bytes4(keccak256('setUtilityUri(uint256,string)')) = 0x4a048176 + * bytes4(keccak256('getUtility(uint256)')) = 0x0007c019 + * bytes4(keccak256('getUtilityHistory(uint256)')) = 0xf6c3cabf + * + * => 0x4a048176 ^ 0x0007c019 ^ 0xf6c3cabf == 0xbcc08bd0 + */ + bytes4 private constant _INTERFACE_ID_ERC5678 = 0xbcc08bd0; + + mapping(uint => string[]) private utilities; + + constructor(string memory name_, string memory symbol_) ERC721(name_, symbol_) {} + + /** + * @dev See {IERC165-supportsInterface}. + */ + function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { + return + interfaceId == type(IERC5678).interfaceId || super.supportsInterface(interfaceId); + } + + function setUtilityUri(uint256 tokenId, string calldata utilityUri) override external onlyOwner { + utilities[tokenId].push(utilityUri); + emit UpdateUtility(tokenId, utilityUri); + } + + function getUtilityUri(uint256 tokenId) override external view returns (string memory) { + uint last = utilities[tokenId].length - 1; + return utilities[tokenId][last]; + } + + function getUtilityHistory(uint256 tokenId) override external view returns (string[] memory){ + return utilities[tokenId]; + } +} diff --git a/assets/eip-5678/contracts/IERC5678.sol b/assets/eip-5678/contracts/IERC5678.sol new file mode 100644 index 00000000000000..b28139f27f7a97 --- /dev/null +++ b/assets/eip-5678/contracts/IERC5678.sol @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: CC0 +pragma solidity ^0.8.0; + +interface IERC5678 { + + // Logged when the utility description URL of an NFT is changed + /// @notice Emitted when the utilityURL of an NFT is changed + /// The empty string for `utilityUri` indicates that there is no utility associated + event UpdateUtility(uint256 indexed tokenId, string utilityUri); + + /// @notice set the new utilityUri - remember the date it was set on + /// @dev The empty string indicates there is no utility + /// Throws if `tokenId` is not valid NFT + /// @param utilityUri The new utility description of the NFT + function setUtilityUri(uint256 tokenId, string calldata utilityUri) external; + + /// @notice Get the utilityUri of an NFT + /// @dev The empty string for `utilityUri` indicates that there is no utility associated + /// @param tokenId The NFT to get the user address for + /// @return The utility uri for this NFT + function getUtilityUri(uint256 tokenId) external view returns (string memory); + + /// @notice Get the changes made to utilityUri + /// @param tokenId The NFT to get the user address for + /// @return The history of changes to `utilityUri` for this NFT + function getUtilityHistory(uint256 tokenId) external view returns(string[] memory); +} diff --git a/assets/eip-5678/hardhat.config.js b/assets/eip-5678/hardhat.config.js new file mode 100644 index 00000000000000..5b0f4d6556aa06 --- /dev/null +++ b/assets/eip-5678/hardhat.config.js @@ -0,0 +1,22 @@ +require("@nomicfoundation/hardhat-toolbox"); + +/** @type import('hardhat/config').HardhatUserConfig */ +module.exports = { + solidity: { + compilers: [ + { + version: "0.8.17" + } + ] + }, + networks: { + hardhat: { + forking: { + url: 'https://rpc-mumbai.maticvigil.com/', + }, + chainId: 80001, + gas: 'auto', + gasMultiplier: 1, + }, + } +}; diff --git a/assets/eip-5678/package.json b/assets/eip-5678/package.json new file mode 100644 index 00000000000000..0b9df160f50409 --- /dev/null +++ b/assets/eip-5678/package.json @@ -0,0 +1,23 @@ +{ + "name": "hardhat-project", + "devDependencies": { + "@ethersproject/abi": "^5.7.0", + "@ethersproject/providers": "^5.7.2", + "@nomicfoundation/hardhat-chai-matchers": "^1.0.4", + "@nomicfoundation/hardhat-network-helpers": "^1.0.6", + "@nomicfoundation/hardhat-toolbox": "^2.0.0", + "@nomiclabs/hardhat-ethers": "^2.2.1", + "@nomiclabs/hardhat-etherscan": "^3.1.2", + "@typechain/ethers-v5": "^10.1.1", + "@typechain/hardhat": "^6.1.4", + "chai": "^4.3.7", + "ethers": "^5.7.2", + "hardhat": "^2.12.2", + "hardhat-gas-reporter": "^1.0.9", + "solidity-coverage": "^0.8.2", + "typechain": "^8.1.1" + }, + "dependencies": { + "@openzeppelin/contracts": "^4.8.0" + } +} diff --git a/assets/eip-5678/scripts/deploy_contracts.js b/assets/eip-5678/scripts/deploy_contracts.js new file mode 100644 index 00000000000000..edb40d659bd20c --- /dev/null +++ b/assets/eip-5678/scripts/deploy_contracts.js @@ -0,0 +1,18 @@ +const {ethers} = require("hardhat"); + +deployContracts = async () => { + return await deployERC5678() +} + +deployERC5678 = async () => { + const utilityContractName = 'ERC5678' + const UtilityNFT = await ethers.getContractFactory(utilityContractName); + const royaltyDebtRegistry = await UtilityNFT.deploy('UNFT', 'UNFT'); + await royaltyDebtRegistry.deployed(); + + return royaltyDebtRegistry; +} + +module.exports = { + deployContracts +} diff --git a/assets/eip-5678/test/ERC5678.test.js b/assets/eip-5678/test/ERC5678.test.js new file mode 100644 index 00000000000000..0c4af5eb022dfd --- /dev/null +++ b/assets/eip-5678/test/ERC5678.test.js @@ -0,0 +1,53 @@ +const {deployContracts} = require("../scripts/deploy_contracts"); +const {expect} = require('chai'); + +describe("ERC5678", () => { + let erc5678; + const tokenId = 123; + const utilityUrl1 = 'https://utility.url'; + + beforeEach(async () => { + erc5678 = await deployContracts(); + }) + + it('should support ERC5678 interface', async () => { + await expect(await erc5678.supportsInterface("0xbcc08bd0")).to.be.true; + }) + + it('should allow setting first utility NFT', async () => { + await expect(erc5678.setUtilityUri( + tokenId, + utilityUrl1, + )).to.emit(erc5678, 'UpdateUtility').withArgs(tokenId, utilityUrl1); + }) + + it('should allow retrieving initial royalties amount for a NFT', async () => { + await expect(erc5678.setUtilityUri( + tokenId, + utilityUrl1, + )).to.emit(erc5678, 'UpdateUtility').withArgs(tokenId, utilityUrl1); + + await expect(await erc5678.getUtilityUri( + tokenId + )).to.equal(utilityUrl1); + }) + + it('should allow retrieving utility history for the NFT', async () => { + await expect(erc5678.setUtilityUri( + tokenId, + utilityUrl1, + )).to.emit(erc5678, 'UpdateUtility').withArgs(tokenId, utilityUrl1); + let utilityUrl2 = utilityUrl1 + '_2'; + await expect(erc5678.setUtilityUri( + tokenId, + utilityUrl2, + )).to.emit(erc5678, 'UpdateUtility').withArgs(tokenId, utilityUrl2); + + let history = await erc5678.getUtilityHistory( + tokenId + ) + await expect(history.length).to.equal(2); + await expect(history[0]).to.equal(utilityUrl1); + await expect(history[1]).to.equal(utilityUrl2); + }) +});