From 5cc1ea0a390d18490d99922242d3633a6b43653a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ernesto=20Garc=C3=ADa?= Date: Wed, 14 Jun 2023 13:01:33 -0600 Subject: [PATCH] Add `GUIDELINES.md` for marking `abstract` contracts (#4010) Co-authored-by: Hadrien Croubois Co-authored-by: Francisco Giordano --- GUIDELINES.md | 7 +++++++ contracts/token/ERC1155/ERC1155.sol | 2 +- contracts/token/ERC1155/utils/ERC1155Holder.sol | 2 +- contracts/token/ERC20/ERC20.sol | 2 +- contracts/token/ERC721/ERC721.sol | 2 +- contracts/token/ERC721/utils/ERC721Holder.sol | 2 +- test/token/ERC1155/utils/ERC1155Holder.test.js | 2 +- test/token/ERC721/utils/ERC721Holder.test.js | 2 +- 8 files changed, 14 insertions(+), 7 deletions(-) diff --git a/GUIDELINES.md b/GUIDELINES.md index 1dd606ddd..71f166405 100644 --- a/GUIDELINES.md +++ b/GUIDELINES.md @@ -114,6 +114,13 @@ In addition to the official Solidity Style Guide we have a number of other conve interface IERC777 { ``` +* Contracts not intended to be used standalone should be marked abstract + so they are required to be inherited to other contracts. + + ```solidity + abstract contract AccessControl is ..., { + ``` + * Unchecked arithmetic blocks should contain comments explaining why overflow is guaranteed not to happen. If the reason is immediately apparent from the line above the unchecked block, the comment may be omitted. * Custom errors should be declared following the [EIP-6093](https://eips.ethereum.org/EIPS/eip-6093) rationale whenever reasonable. Also, consider the following: diff --git a/contracts/token/ERC1155/ERC1155.sol b/contracts/token/ERC1155/ERC1155.sol index 05bcc3fa1..610868489 100644 --- a/contracts/token/ERC1155/ERC1155.sol +++ b/contracts/token/ERC1155/ERC1155.sol @@ -17,7 +17,7 @@ import "../../interfaces/draft-IERC6093.sol"; * * _Available since v3.1._ */ -contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI, IERC1155Errors { +abstract contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI, IERC1155Errors { // Mapping from token ID to account balances mapping(uint256 => mapping(address => uint256)) private _balances; diff --git a/contracts/token/ERC1155/utils/ERC1155Holder.sol b/contracts/token/ERC1155/utils/ERC1155Holder.sol index b06a37f18..d24a1a53a 100644 --- a/contracts/token/ERC1155/utils/ERC1155Holder.sol +++ b/contracts/token/ERC1155/utils/ERC1155Holder.sol @@ -13,7 +13,7 @@ import "./ERC1155Receiver.sol"; * * @dev _Available since v3.1._ */ -contract ERC1155Holder is ERC1155Receiver { +abstract contract ERC1155Holder is ERC1155Receiver { function onERC1155Received( address, address, diff --git a/contracts/token/ERC20/ERC20.sol b/contracts/token/ERC20/ERC20.sol index dd46c15dd..aacfe79b7 100644 --- a/contracts/token/ERC20/ERC20.sol +++ b/contracts/token/ERC20/ERC20.sol @@ -35,7 +35,7 @@ import "../../interfaces/draft-IERC6093.sol"; * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ -contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors { +abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; diff --git a/contracts/token/ERC721/ERC721.sol b/contracts/token/ERC721/ERC721.sol index 08f660a29..a26255c7c 100644 --- a/contracts/token/ERC721/ERC721.sol +++ b/contracts/token/ERC721/ERC721.sol @@ -16,7 +16,7 @@ import "../../interfaces/draft-IERC6093.sol"; * the Metadata extension, but not including the Enumerable extension, which is available separately as * {ERC721Enumerable}. */ -contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Errors { +abstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Errors { using Strings for uint256; // Token name diff --git a/contracts/token/ERC721/utils/ERC721Holder.sol b/contracts/token/ERC721/utils/ERC721Holder.sol index 9f5b2e9f9..a3ee8b5f0 100644 --- a/contracts/token/ERC721/utils/ERC721Holder.sol +++ b/contracts/token/ERC721/utils/ERC721Holder.sol @@ -11,7 +11,7 @@ import "../IERC721Receiver.sol"; * Accepts all token transfers. * Make sure the contract is able to use its token with {IERC721-safeTransferFrom}, {IERC721-approve} or {IERC721-setApprovalForAll}. */ -contract ERC721Holder is IERC721Receiver { +abstract contract ERC721Holder is IERC721Receiver { /** * @dev See {IERC721Receiver-onERC721Received}. * diff --git a/test/token/ERC1155/utils/ERC1155Holder.test.js b/test/token/ERC1155/utils/ERC1155Holder.test.js index 864e89b50..8d8541640 100644 --- a/test/token/ERC1155/utils/ERC1155Holder.test.js +++ b/test/token/ERC1155/utils/ERC1155Holder.test.js @@ -1,6 +1,6 @@ const { BN } = require('@openzeppelin/test-helpers'); -const ERC1155Holder = artifacts.require('ERC1155Holder'); +const ERC1155Holder = artifacts.require('$ERC1155Holder'); const ERC1155 = artifacts.require('$ERC1155'); const { expect } = require('chai'); diff --git a/test/token/ERC721/utils/ERC721Holder.test.js b/test/token/ERC721/utils/ERC721Holder.test.js index 0fd822280..4aa2b7948 100644 --- a/test/token/ERC721/utils/ERC721Holder.test.js +++ b/test/token/ERC721/utils/ERC721Holder.test.js @@ -1,6 +1,6 @@ const { expect } = require('chai'); -const ERC721Holder = artifacts.require('ERC721Holder'); +const ERC721Holder = artifacts.require('$ERC721Holder'); const ERC721 = artifacts.require('$ERC721'); contract('ERC721Holder', function (accounts) {