From ac3c9e061e31a323166de1de12606412bba62857 Mon Sep 17 00:00:00 2001 From: Bogdan Popa Date: Mon, 27 Mar 2023 13:11:38 +0300 Subject: [PATCH 1/2] Add ERC-5666: Add Royalty Debt Registry --- EIPS/eip-6786.md | 105 +++++++++++++++ assets/eip-6786/.gitignore | 4 + assets/eip-6786/LICENSE | 121 ++++++++++++++++++ assets/eip-6786/README.md | 29 +++++ assets/eip-6786/abi/ERC6786.json | 120 +++++++++++++++++ assets/eip-6786/abi/IERC6786.json | 69 ++++++++++ assets/eip-6786/contracts/ERC6786.sol | 67 ++++++++++ assets/eip-6786/contracts/IERC6786.sol | 21 +++ .../contracts/token/ERC721Royalty.sol | 33 +++++ assets/eip-6786/contracts/utils/IERC2981.sol | 14 ++ assets/eip-6786/hardhat.config.js | 22 ++++ assets/eip-6786/package.json | 23 ++++ assets/eip-6786/scripts/deploy_contracts.js | 44 +++++++ assets/eip-6786/test/ERC6786.test.js | 65 ++++++++++ 14 files changed, 737 insertions(+) create mode 100644 EIPS/eip-6786.md create mode 100644 assets/eip-6786/.gitignore create mode 100644 assets/eip-6786/LICENSE create mode 100644 assets/eip-6786/README.md create mode 100644 assets/eip-6786/abi/ERC6786.json create mode 100644 assets/eip-6786/abi/IERC6786.json create mode 100644 assets/eip-6786/contracts/ERC6786.sol create mode 100644 assets/eip-6786/contracts/IERC6786.sol create mode 100644 assets/eip-6786/contracts/token/ERC721Royalty.sol create mode 100644 assets/eip-6786/contracts/utils/IERC2981.sol create mode 100644 assets/eip-6786/hardhat.config.js create mode 100644 assets/eip-6786/package.json create mode 100644 assets/eip-6786/scripts/deploy_contracts.js create mode 100644 assets/eip-6786/test/ERC6786.test.js diff --git a/EIPS/eip-6786.md b/EIPS/eip-6786.md new file mode 100644 index 00000000000000..a9d3d5bc861c3c --- /dev/null +++ b/EIPS/eip-6786.md @@ -0,0 +1,105 @@ +--- +eip: 6786 +title: Registry for royalties payment for NFTs +description: A registry used for paying royalties for any NFT with information about the creator +author: Otniel Nicola (@OT-kthd), Bogdan Popa (@BogdanKTHD) +discussions-to: https://ethereum-magicians.org/t/eip-5666-royalty-debt-registry/13569 +status: Draft +type: Standards Track +category: ERC +created: 2023-03-27 +requires: 165, 2981 +--- + +## Abstract + +This standard allows anyone to pay royalties for a certain NFT and also to keep track of the royalties amount paid. It will cumulate the value each time a payment is executed through it and make the information public. + +## Motivation + +There are many marketplaces which do not enforce any royalty payment to the NFT creator every time the NFT is sold or re-sold and/or providing a way for doing it. There are some marketplaces which use specific system of royalties, however that system is applicable for the NFTs creates on their platform. + +In this context, there is a need of a way for paying royalties, as it is a strong incentive for creators to keep contributing to the NFTs ecosystem. + +Additionally, this standard will provide a way of computing the amount of royalties paid to a creator for a certain NFT. This could be useful in the context of categorising NFTs in terms of royalties. The term “debt“ is used because the standard aims to provide a way of knowing if there are any royalties left unpaid for the NFTs trades that took place in a marketplace that does not support them and, in that case, expose a way of paying them. + +Not only the owner of it, but anyone could pay royalties for a certain NFT. This could be a way of supporting a creator for his work. + +## 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 [ERC-6786](./eip-6786.md) MUST implement the interface defined as follows: + +### Contract Interface + +```solidity +// @title Royalty Debt Registry +/// Note: the ERC-165 identifier for this interface is 0x253b27b0 + +interface IERC6786 { + + // Logged when royalties were paid for a NFT + /// @notice Emitted when royalties are paid for the NFT with address tokenAddress and id tokenId + event RoyaltiesPaid(address indexed tokenAddress, uint256 indexed tokenId, uint256 amount); + + /// @notice sends msg.value to the creator of a NFT + /// @dev Throws if there are no on-chain informations about the creator + /// @param tokenAddress The address of NFT contract + /// @param tokenId The NFT id + function payRoyalties(address tokenAddress, uint256 tokenId) external payable; + + /// @notice Get the amount of royalties which was paid for a NFT + /// @dev + /// @param tokenAddress The address of NFT contract + /// @param tokenId The NFT id + /// @return The amount of royalties paid for the NFT + function getPaidRoyalties(address tokenAddress, uint256 tokenId) external view returns (uint256); +} +``` + +All functions defined as view MAY be implemented as pure or view + +Function payRoyalties MAY be implemented as public or external + +The event RoyaltiesPaid MUST be emitted when the payRoyalties function is called + +The supportsInterface method MUST return true when called with `0x253b27b0` + +## Rationale + +With a lot of places made for trading NFTs dropping down the royalty payment or having a centralised approach, we want to provide a way for anyone to pay royalties to the creators. + +The payment can be made in native coins, so it is easy to aggregate the amount of paid royalties. We want this information to be public, so anyone could tell if a creator received royalties in case of under the table trading or in case of marketplaces which don’t support royalties. + +The function used for payment can be called by anyone (not only the NFTs owner) to support the creator at any time. There is a way of seeing the amount of paid royalties in any token, also available for anyone. + +For fetching creator on-chain data we will use [ERC-2981](./eip-2981.md), but any other on-chain method of getting the creator address is accepted. + +## Backwards Compatibility + +This ERC is not introducing any backward incompatibilities. + +## Test Cases + +Tests are included in [`ERC6786.test.js`](../assets/eip-6786/test/ERC6786.test.js). + +To run them in terminal, you can use the following commands: + +``` +cd ../assets/eip-6786 +npm install +npx hardhat test +``` + +## Reference Implementation + +See [`ERC6786.sol`](../assets/eip-6786/contracts/ERC6786.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-6786/LICENSE). diff --git a/assets/eip-6786/.gitignore b/assets/eip-6786/.gitignore new file mode 100644 index 00000000000000..95dffaec3aa24d --- /dev/null +++ b/assets/eip-6786/.gitignore @@ -0,0 +1,4 @@ +node_modules +artifacts +cache +package-lock.json \ No newline at end of file diff --git a/assets/eip-6786/LICENSE b/assets/eip-6786/LICENSE new file mode 100644 index 00000000000000..1625c179360799 --- /dev/null +++ b/assets/eip-6786/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-6786/README.md b/assets/eip-6786/README.md new file mode 100644 index 00000000000000..4a04a18e8ccbd8 --- /dev/null +++ b/assets/eip-6786/README.md @@ -0,0 +1,29 @@ +
+ +# ERC6786 Royalty Debt Registry + +[![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-6786 Royalty Debt Registry`. + +## 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-6786/abi/ERC6786.json b/assets/eip-6786/abi/ERC6786.json new file mode 100644 index 00000000000000..075ed07ecff460 --- /dev/null +++ b/assets/eip-6786/abi/ERC6786.json @@ -0,0 +1,120 @@ +[ + { + "inputs": [ + { + "internalType": "address", + "name": "tokenAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "CreatorError", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "creator", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "PaymentError", + "type": "error" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "tokenAddress", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "RoyaltiesPaid", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "tokenAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "getPaidRoyalties", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "tokenAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "payRoyalties", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes4", + "name": "interfaceId", + "type": "bytes4" + } + ], + "name": "supportsInterface", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + } +] \ No newline at end of file diff --git a/assets/eip-6786/abi/IERC6786.json b/assets/eip-6786/abi/IERC6786.json new file mode 100644 index 00000000000000..50f0e37365f2f1 --- /dev/null +++ b/assets/eip-6786/abi/IERC6786.json @@ -0,0 +1,69 @@ +[ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "tokenAddress", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "RoyaltiesPaid", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "tokenAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "getPaidRoyalties", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "tokenAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "payRoyalties", + "outputs": [], + "stateMutability": "payable", + "type": "function" + } +] \ No newline at end of file diff --git a/assets/eip-6786/contracts/ERC6786.sol b/assets/eip-6786/contracts/ERC6786.sol new file mode 100644 index 00000000000000..e332f79887d6f3 --- /dev/null +++ b/assets/eip-6786/contracts/ERC6786.sol @@ -0,0 +1,67 @@ +// SPDX-License-Identifier: CC0 +pragma solidity ^0.8.0; + +import "@openzeppelin/contracts/utils/introspection/ERC165.sol"; +import "./IERC6786.sol"; +import "./utils/IERC2981.sol"; + +contract ERC6786 is IERC6786, ERC165 { + + //Mapping from token (address and id) to the amount of paid royalties + mapping(address => mapping(uint256 => uint256)) private _paidRoyalties; + + /* + * bytes4(keccak256('payRoyalties(address,uint256)')) == 0xf511f0e9 + * bytes4(keccak256('getPaidRoyalties(address,uint256)')) == 0xd02ad759 + * + * => 0xf511f0e9 ^ 0xd02ad759 == 0x253b27b0 + */ + bytes4 private constant _INTERFACE_ID_ERC6786 = 0x253b27b0; + + /* + * bytes4(keccak256('royaltyInfo(uint256,uint256)')) == 0x2a55205a + */ + bytes4 private constant _INTERFACE_ID_ERC2981 = 0x2a55205a; + + /// @notice This is thrown when there is no creator related information + /// @param tokenAddress -> the address of the contract + /// @param tokenId -> the id of the NFT + error CreatorError(address tokenAddress, uint256 tokenId); + + /// @notice This is thrown when the payment fails + /// @param creator -> the address of the creator + /// @param amount -> the amount to pay + error PaymentError(address creator, uint256 amount); + + function checkRoyalties(address _contract) internal view returns (bool) { + (bool success) = IERC165(_contract).supportsInterface(_INTERFACE_ID_ERC2981); + return success; + } + + /** + * @dev See {IERC165-supportsInterface}. + */ + function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { + return + interfaceId == type(IERC6786).interfaceId || + super.supportsInterface(interfaceId); + } + + function payRoyalties(address tokenAddress, uint256 tokenId) external override payable { + if (!checkRoyalties(tokenAddress)) { + revert CreatorError(tokenAddress, tokenId); + } + (address creator,) = IERC2981(tokenAddress).royaltyInfo(tokenId, 0); + (bool success,) = payable(creator).call{value : msg.value}(""); + if(!success) { + revert PaymentError(creator, msg.value); + } + _paidRoyalties[tokenAddress][tokenId] += msg.value; + + emit RoyaltiesPaid(tokenAddress, tokenId, msg.value); + } + + function getPaidRoyalties(address tokenAddress, uint256 tokenId) external view override returns (uint256) { + return _paidRoyalties[tokenAddress][tokenId]; + } +} diff --git a/assets/eip-6786/contracts/IERC6786.sol b/assets/eip-6786/contracts/IERC6786.sol new file mode 100644 index 00000000000000..2d7fcebbee7a35 --- /dev/null +++ b/assets/eip-6786/contracts/IERC6786.sol @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: CC0 +pragma solidity ^0.8.0; + +interface IERC6786 { + + /// @dev Logged when royalties were paid for a NFT + /// @notice Emitted when royalties are paid for the NFT with address tokenAddress and id tokenId + event RoyaltiesPaid(address indexed tokenAddress, uint256 indexed tokenId, uint256 amount); + + /// @notice sends msg.value to the creator for a NFT + /// @dev Throws if there is no on-chain information about the creator + /// @param tokenAddress The address of NFT contract + /// @param tokenId The NFT id + function payRoyalties(address tokenAddress, uint256 tokenId) external payable; + + /// @notice Get the amount of royalties which was paid for + /// @param tokenAddress The address of NFT contract + /// @param tokenId The NFT id + /// @return The amount of royalties paid for the NFT in paymentToken + function getPaidRoyalties(address tokenAddress, uint256 tokenId) external view returns (uint256); +} diff --git a/assets/eip-6786/contracts/token/ERC721Royalty.sol b/assets/eip-6786/contracts/token/ERC721Royalty.sol new file mode 100644 index 00000000000000..17bf60c792765c --- /dev/null +++ b/assets/eip-6786/contracts/token/ERC721Royalty.sol @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: CC0 +pragma solidity ^0.8.0; + +import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; +import "../utils/IERC2981.sol"; + +contract ERC721Royalty is ERC721, IERC2981 { + + address public constant DEFAULT_CREATOR_ADDRESS = 0x4fF5DDB196A32e3dC604abD5422805ecAD22c468; + + constructor(string memory name_, string memory symbol_) ERC721(name_, symbol_) {} + + /** + * @dev See {IERC165-supportsInterface}. + */ + function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721, IERC165) returns (bool) { + return + interfaceId == type(IERC721).interfaceId || + interfaceId == type(IERC2981).interfaceId || + super.supportsInterface(interfaceId); + } + + function royaltyInfo( + uint256 _tokenId, + uint256 _salePrice + ) external view override returns ( + address receiver, + uint256 royaltyAmount + ) { + receiver = DEFAULT_CREATOR_ADDRESS; + royaltyAmount = _salePrice / 10000; + } +} diff --git a/assets/eip-6786/contracts/utils/IERC2981.sol b/assets/eip-6786/contracts/utils/IERC2981.sol new file mode 100644 index 00000000000000..406d2a3ea1673e --- /dev/null +++ b/assets/eip-6786/contracts/utils/IERC2981.sol @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +import "@openzeppelin/contracts/utils/introspection/IERC165.sol"; + +interface IERC2981 is IERC165 { + function royaltyInfo( + uint256 _tokenId, + uint256 _salePrice + ) external view returns ( + address receiver, + uint256 royaltyAmount + ); +} diff --git a/assets/eip-6786/hardhat.config.js b/assets/eip-6786/hardhat.config.js new file mode 100644 index 00000000000000..5b0f4d6556aa06 --- /dev/null +++ b/assets/eip-6786/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-6786/package.json b/assets/eip-6786/package.json new file mode 100644 index 00000000000000..0b9df160f50409 --- /dev/null +++ b/assets/eip-6786/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-6786/scripts/deploy_contracts.js b/assets/eip-6786/scripts/deploy_contracts.js new file mode 100644 index 00000000000000..d3e346bf4c3185 --- /dev/null +++ b/assets/eip-6786/scripts/deploy_contracts.js @@ -0,0 +1,44 @@ +const {ethers} = require("hardhat"); + +deployContracts = async () => { + let erc721Royalty = await deployERC721Royalties(); + let erc721 = await deployERC721(); + let royaltyDebtRegistry = await deployERC5666(); + + return {erc721Royalty, erc721, royaltyDebtRegistry} +} + +deployERC5666 = async () => { + const royaltyContractName = 'ERC6786' + const RoyaltyDebtRegistry = await ethers.getContractFactory(royaltyContractName); + const royaltyDebtRegistry = await RoyaltyDebtRegistry.deploy(); + await royaltyDebtRegistry.deployed(); + + return royaltyDebtRegistry; +} + +deployERC721 = async () => { + const NFTContractName = 'ERC721' + const ERC721Name = 'NFT'; + const ERC721Symbol = 'NFT'; + const ERC721 = await ethers.getContractFactory(NFTContractName); + const erc721 = await ERC721.deploy(ERC721Name, ERC721Symbol); + await erc721.deployed(); + + return erc721; +} + +deployERC721Royalties = async () => { + const royaltyNFTContractName = 'ERC721Royalty'; + const royaltyERC721Name = 'RoyaltyNFT'; + const royaltyERC721Symbol = 'RNFT'; + const ERC721Royalty = await ethers.getContractFactory(royaltyNFTContractName); + const erc721Royalty = await ERC721Royalty.deploy(royaltyERC721Name, royaltyERC721Symbol); + await erc721Royalty.deployed(); + + return erc721Royalty; +} + +module.exports = { + deployContracts +} diff --git a/assets/eip-6786/test/ERC6786.test.js b/assets/eip-6786/test/ERC6786.test.js new file mode 100644 index 00000000000000..07a03e33bdb865 --- /dev/null +++ b/assets/eip-6786/test/ERC6786.test.js @@ -0,0 +1,65 @@ +const {deployContracts} = require("../scripts/deploy_contracts"); +const {expect} = require('chai'); + +describe("ERC6786", () => { + + let erc721Royalty; + let erc721; + let royaltyDebtRegistry; + const tokenId = 666; + + beforeEach(async () => { + const contracts = await deployContracts(); + erc721Royalty = contracts.erc721Royalty; + erc721 = contracts.erc721; + royaltyDebtRegistry = contracts.royaltyDebtRegistry; + }) + + it('should support ERC6786 interface', async () => { + await expect(await royaltyDebtRegistry.supportsInterface("0x253b27b0")).to.be.true; + }) + + it('should allow paying royalties for a ERC2981 NFT', async () => { + await expect(royaltyDebtRegistry.payRoyalties( + erc721Royalty.address, + tokenId, + {value: 1000} + )).to.emit(royaltyDebtRegistry, 'RoyaltiesPaid') + .withArgs(erc721Royalty.address, tokenId, 1000); + }) + + it('should not allow paying royalties for a non-ERC2981 NFT', async () => { + await expect(royaltyDebtRegistry.payRoyalties( + erc721.address, + tokenId, + {value: 1000} + )).to.be.revertedWithCustomError(royaltyDebtRegistry,'CreatorError') + .withArgs(erc721.address, tokenId); + }) + + it('should allow retrieving initial royalties amount for a NFT', async () => { + await expect(await royaltyDebtRegistry.getPaidRoyalties( + erc721Royalty.address, + tokenId + )).to.equal(0); + }) + + it('should allow retrieving royalties amount after payments for a NFT', async () => { + await royaltyDebtRegistry.payRoyalties( + erc721Royalty.address, + tokenId, + {value: 2000} + ); + + await royaltyDebtRegistry.payRoyalties( + erc721Royalty.address, + tokenId, + {value: 3666} + ) + + await expect(await royaltyDebtRegistry.getPaidRoyalties( + erc721Royalty.address, + tokenId + )).to.equal(5666); + }) +}); From 2a0064fddaab9fc29d5e126224ebe7f0d3ed196f Mon Sep 17 00:00:00 2001 From: Bogdan Popa Date: Wed, 17 May 2023 14:22:02 +0300 Subject: [PATCH 2/2] chore: changes after review --- assets/eip-6786/.gitignore | 4 - assets/eip-6786/LICENSE | 121 -------------------- assets/eip-6786/README.md | 2 - assets/eip-6786/abi/ERC6786.json | 120 ------------------- assets/eip-6786/abi/IERC6786.json | 69 ----------- assets/eip-6786/hardhat.config.js | 22 ---- assets/eip-6786/package.json | 23 ---- assets/eip-6786/scripts/deploy_contracts.js | 44 ------- 8 files changed, 405 deletions(-) delete mode 100644 assets/eip-6786/.gitignore delete mode 100644 assets/eip-6786/LICENSE delete mode 100644 assets/eip-6786/abi/ERC6786.json delete mode 100644 assets/eip-6786/abi/IERC6786.json delete mode 100644 assets/eip-6786/hardhat.config.js delete mode 100644 assets/eip-6786/package.json delete mode 100644 assets/eip-6786/scripts/deploy_contracts.js diff --git a/assets/eip-6786/.gitignore b/assets/eip-6786/.gitignore deleted file mode 100644 index 95dffaec3aa24d..00000000000000 --- a/assets/eip-6786/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -node_modules -artifacts -cache -package-lock.json \ No newline at end of file diff --git a/assets/eip-6786/LICENSE b/assets/eip-6786/LICENSE deleted file mode 100644 index 1625c179360799..00000000000000 --- a/assets/eip-6786/LICENSE +++ /dev/null @@ -1,121 +0,0 @@ -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-6786/README.md b/assets/eip-6786/README.md index 4a04a18e8ccbd8..cc3a5481a726d1 100644 --- a/assets/eip-6786/README.md +++ b/assets/eip-6786/README.md @@ -2,8 +2,6 @@ # ERC6786 Royalty Debt Registry -[![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-6786 Royalty Debt Registry`. diff --git a/assets/eip-6786/abi/ERC6786.json b/assets/eip-6786/abi/ERC6786.json deleted file mode 100644 index 075ed07ecff460..00000000000000 --- a/assets/eip-6786/abi/ERC6786.json +++ /dev/null @@ -1,120 +0,0 @@ -[ - { - "inputs": [ - { - "internalType": "address", - "name": "tokenAddress", - "type": "address" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "CreatorError", - "type": "error" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "creator", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "PaymentError", - "type": "error" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "tokenAddress", - "type": "address" - }, - { - "indexed": true, - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "RoyaltiesPaid", - "type": "event" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "tokenAddress", - "type": "address" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "getPaidRoyalties", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "tokenAddress", - "type": "address" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "payRoyalties", - "outputs": [], - "stateMutability": "payable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes4", - "name": "interfaceId", - "type": "bytes4" - } - ], - "name": "supportsInterface", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - } -] \ No newline at end of file diff --git a/assets/eip-6786/abi/IERC6786.json b/assets/eip-6786/abi/IERC6786.json deleted file mode 100644 index 50f0e37365f2f1..00000000000000 --- a/assets/eip-6786/abi/IERC6786.json +++ /dev/null @@ -1,69 +0,0 @@ -[ - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "tokenAddress", - "type": "address" - }, - { - "indexed": true, - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "RoyaltiesPaid", - "type": "event" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "tokenAddress", - "type": "address" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "getPaidRoyalties", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "tokenAddress", - "type": "address" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "payRoyalties", - "outputs": [], - "stateMutability": "payable", - "type": "function" - } -] \ No newline at end of file diff --git a/assets/eip-6786/hardhat.config.js b/assets/eip-6786/hardhat.config.js deleted file mode 100644 index 5b0f4d6556aa06..00000000000000 --- a/assets/eip-6786/hardhat.config.js +++ /dev/null @@ -1,22 +0,0 @@ -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-6786/package.json b/assets/eip-6786/package.json deleted file mode 100644 index 0b9df160f50409..00000000000000 --- a/assets/eip-6786/package.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "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-6786/scripts/deploy_contracts.js b/assets/eip-6786/scripts/deploy_contracts.js deleted file mode 100644 index d3e346bf4c3185..00000000000000 --- a/assets/eip-6786/scripts/deploy_contracts.js +++ /dev/null @@ -1,44 +0,0 @@ -const {ethers} = require("hardhat"); - -deployContracts = async () => { - let erc721Royalty = await deployERC721Royalties(); - let erc721 = await deployERC721(); - let royaltyDebtRegistry = await deployERC5666(); - - return {erc721Royalty, erc721, royaltyDebtRegistry} -} - -deployERC5666 = async () => { - const royaltyContractName = 'ERC6786' - const RoyaltyDebtRegistry = await ethers.getContractFactory(royaltyContractName); - const royaltyDebtRegistry = await RoyaltyDebtRegistry.deploy(); - await royaltyDebtRegistry.deployed(); - - return royaltyDebtRegistry; -} - -deployERC721 = async () => { - const NFTContractName = 'ERC721' - const ERC721Name = 'NFT'; - const ERC721Symbol = 'NFT'; - const ERC721 = await ethers.getContractFactory(NFTContractName); - const erc721 = await ERC721.deploy(ERC721Name, ERC721Symbol); - await erc721.deployed(); - - return erc721; -} - -deployERC721Royalties = async () => { - const royaltyNFTContractName = 'ERC721Royalty'; - const royaltyERC721Name = 'RoyaltyNFT'; - const royaltyERC721Symbol = 'RNFT'; - const ERC721Royalty = await ethers.getContractFactory(royaltyNFTContractName); - const erc721Royalty = await ERC721Royalty.deploy(royaltyERC721Name, royaltyERC721Symbol); - await erc721Royalty.deployed(); - - return erc721Royalty; -} - -module.exports = { - deployContracts -}