Explorar o código

Make ERC721Votes no longer a Draft (#3699)

Francisco %!s(int64=3) %!d(string=hai) anos
pai
achega
7a14f6c595

+ 7 - 0
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

+ 1 - 1
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

+ 1 - 1
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") {}

+ 54 - 0
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);
+    }
+}

+ 3 - 50
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";

+ 1 - 1
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',

+ 0 - 0
test/utils/cryptography/draft-EIP712.test.js → test/utils/cryptography/EIP712.test.js