diff --git a/CHANGELOG.md b/CHANGELOG.md index 93107ee59e5..ecc6f02d7b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,13 @@ ```diff -import "@openzeppelin/contracts/utils/cryptography/draft-EIP712.sol"; +import "@openzeppelin/contracts/utils/cryptography/EIP712.sol"; +``` + + * `ERC721Votes`: Added the file `ERC721Votes.sol` and deprecated `draft-ERC721Votes.sol` since it no longer depends on a Draft EIP (EIP-712). Developers are encouraged to update their imports. ([#3621](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3699)) + +```diff +-import "@openzeppelin/contracts/token/ERC721/extensions/draft-ERC721Votes.sol"; ++import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Votes.sol"; ``` ### ERC-721 Compatibility Note diff --git a/contracts/mocks/ERC721ConsecutiveMock.sol b/contracts/mocks/ERC721ConsecutiveMock.sol index 11c93d188fb..c4965aa85bf 100644 --- a/contracts/mocks/ERC721ConsecutiveMock.sol +++ b/contracts/mocks/ERC721ConsecutiveMock.sol @@ -6,7 +6,7 @@ import "../token/ERC721/extensions/ERC721Burnable.sol"; import "../token/ERC721/extensions/ERC721Consecutive.sol"; import "../token/ERC721/extensions/ERC721Enumerable.sol"; import "../token/ERC721/extensions/ERC721Pausable.sol"; -import "../token/ERC721/extensions/draft-ERC721Votes.sol"; +import "../token/ERC721/extensions/ERC721Votes.sol"; /** * @title ERC721ConsecutiveMock diff --git a/contracts/mocks/ERC721VotesMock.sol b/contracts/mocks/ERC721VotesMock.sol index 0755ace66ce..acb51ebfbe1 100644 --- a/contracts/mocks/ERC721VotesMock.sol +++ b/contracts/mocks/ERC721VotesMock.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.0; -import "../token/ERC721/extensions/draft-ERC721Votes.sol"; +import "../token/ERC721/extensions/ERC721Votes.sol"; contract ERC721VotesMock is ERC721Votes { constructor(string memory name, string memory symbol) ERC721(name, symbol) EIP712(name, "1") {} diff --git a/contracts/token/ERC721/extensions/ERC721Votes.sol b/contracts/token/ERC721/extensions/ERC721Votes.sol new file mode 100644 index 00000000000..ddcb15607ad --- /dev/null +++ b/contracts/token/ERC721/extensions/ERC721Votes.sol @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.0; + +import "../ERC721.sol"; +import "../../../governance/utils/Votes.sol"; + +/** + * @dev Extension of ERC721 to support voting and delegation as implemented by {Votes}, where each individual NFT counts + * as 1 vote unit. + * + * Tokens do not count as votes until they are delegated, because votes must be tracked which incurs an additional cost + * on every transfer. Token holders can either delegate to a trusted representative who will decide how to make use of + * the votes in governance decisions, or they can delegate to themselves to be their own representative. + * + * _Available since v4.5._ + */ +abstract contract ERC721Votes is ERC721, Votes { + /** + * @dev Adjusts votes when tokens are transferred. + * + * Emits a {Votes-DelegateVotesChanged} event. + */ + function _afterTokenTransfer( + address from, + address to, + uint256 tokenId + ) internal virtual override { + _transferVotingUnits(from, to, 1); + super._afterTokenTransfer(from, to, tokenId); + } + + /** + * @dev Adjusts votes when a batch of tokens is transferred. + * + * Emits a {Votes-DelegateVotesChanged} event. + */ + function _afterConsecutiveTokenTransfer( + address from, + address to, + uint256 first, + uint96 size + ) internal virtual override { + _transferVotingUnits(from, to, size); + super._afterConsecutiveTokenTransfer(from, to, first, size); + } + + /** + * @dev Returns the balance of `account`. + */ + function _getVotingUnits(address account) internal view virtual override returns (uint256) { + return balanceOf(account); + } +} diff --git a/contracts/token/ERC721/extensions/draft-ERC721Votes.sol b/contracts/token/ERC721/extensions/draft-ERC721Votes.sol index 1d23c78549d..ea9227ab015 100644 --- a/contracts/token/ERC721/extensions/draft-ERC721Votes.sol +++ b/contracts/token/ERC721/extensions/draft-ERC721Votes.sol @@ -1,55 +1,8 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/extensions/draft-ERC721Votes.sol) pragma solidity ^0.8.0; -import "../ERC721.sol"; -import "../../../governance/utils/Votes.sol"; +// ERC721Votes was marked as draft due to the EIP-712 dependency. +// EIP-712 is Final as of 2022-08-11. This file is deprecated. -/** - * @dev Extension of ERC721 to support voting and delegation as implemented by {Votes}, where each individual NFT counts - * as 1 vote unit. - * - * Tokens do not count as votes until they are delegated, because votes must be tracked which incurs an additional cost - * on every transfer. Token holders can either delegate to a trusted representative who will decide how to make use of - * the votes in governance decisions, or they can delegate to themselves to be their own representative. - * - * _Available since v4.5._ - */ -abstract contract ERC721Votes is ERC721, Votes { - /** - * @dev Adjusts votes when tokens are transferred. - * - * Emits a {Votes-DelegateVotesChanged} event. - */ - function _afterTokenTransfer( - address from, - address to, - uint256 tokenId - ) internal virtual override { - _transferVotingUnits(from, to, 1); - super._afterTokenTransfer(from, to, tokenId); - } - - /** - * @dev Adjusts votes when a batch of tokens is transferred. - * - * Emits a {Votes-DelegateVotesChanged} event. - */ - function _afterConsecutiveTokenTransfer( - address from, - address to, - uint256 first, - uint96 size - ) internal virtual override { - _transferVotingUnits(from, to, size); - super._afterConsecutiveTokenTransfer(from, to, first, size); - } - - /** - * @dev Returns the balance of `account`. - */ - function _getVotingUnits(address account) internal view virtual override returns (uint256) { - return balanceOf(account); - } -} +import "./ERC721Votes.sol"; diff --git a/scripts/migrate-imports.js b/scripts/migrate-imports.js index bc35253daf8..352de1408ab 100755 --- a/scripts/migrate-imports.js +++ b/scripts/migrate-imports.js @@ -9,7 +9,7 @@ const pathUpdates = { 'access/TimelockController.sol': 'governance/TimelockController.sol', 'cryptography/ECDSA.sol': 'utils/cryptography/ECDSA.sol', 'cryptography/MerkleProof.sol': 'utils/cryptography/MerkleProof.sol', - 'drafts/EIP712.sol': 'utils/cryptography/draft-EIP712.sol', + 'drafts/EIP712.sol': 'utils/cryptography/EIP712.sol', 'drafts/ERC20Permit.sol': 'token/ERC20/extensions/draft-ERC20Permit.sol', 'drafts/IERC20Permit.sol': 'token/ERC20/extensions/draft-IERC20Permit.sol', 'GSN/Context.sol': 'utils/Context.sol', diff --git a/test/utils/cryptography/draft-EIP712.test.js b/test/utils/cryptography/EIP712.test.js similarity index 100% rename from test/utils/cryptography/draft-EIP712.test.js rename to test/utils/cryptography/EIP712.test.js