Skip to content

Commit

Permalink
Make ERC721Votes no longer a Draft (#3699)
Browse files Browse the repository at this point in the history
(cherry picked from commit 7a14f6c)
  • Loading branch information
frangio committed Sep 17, 2022
1 parent 7deed7a commit a615329
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 53 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/ERC721ConsecutiveMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/ERC721VotesMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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") {}
Expand Down
54 changes: 54 additions & 0 deletions contracts/token/ERC721/extensions/ERC721Votes.sol
Original file line number Diff line number Diff line change
@@ -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);
}
}
53 changes: 3 additions & 50 deletions contracts/token/ERC721/extensions/draft-ERC721Votes.sol
Original file line number Diff line number Diff line change
@@ -1,55 +1,8 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0-rc.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";
2 changes: 1 addition & 1 deletion scripts/migrate-imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
File renamed without changes.

0 comments on commit a615329

Please sign in to comment.