draft-ERC721VotesUpgradeable.sol 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts (last updated v4.5.0-rc.0) (token/ERC721/extensions/draft-ERC721Votes.sol)
  3. pragma solidity ^0.8.0;
  4. import "../ERC721Upgradeable.sol";
  5. import "../../../governance/utils/VotesUpgradeable.sol";
  6. import "../../../proxy/utils/Initializable.sol";
  7. /**
  8. * @dev Extension of ERC721 to support voting and delegation as implemented by {Votes}, where each individual NFT counts
  9. * as 1 vote unit.
  10. *
  11. * Tokens do not count as votes until they are delegated, because votes must be tracked which incurs an additional cost
  12. * on every transfer. Token holders can either delegate to a trusted representative who will decide how to make use of
  13. * the votes in governance decisions, or they can delegate to themselves to be their own representative.
  14. *
  15. * _Available since v4.5._
  16. */
  17. abstract contract ERC721VotesUpgradeable is Initializable, ERC721Upgradeable, VotesUpgradeable {
  18. function __ERC721Votes_init() internal onlyInitializing {
  19. }
  20. function __ERC721Votes_init_unchained() internal onlyInitializing {
  21. }
  22. /**
  23. * @dev Adjusts votes when tokens are transferred.
  24. *
  25. * Emits a {Votes-DelegateVotesChanged} event.
  26. */
  27. function _afterTokenTransfer(
  28. address from,
  29. address to,
  30. uint256 tokenId
  31. ) internal virtual override {
  32. _transferVotingUnits(from, to, 1);
  33. super._afterTokenTransfer(from, to, tokenId);
  34. }
  35. /**
  36. * @dev Returns the balance of `account`.
  37. */
  38. function _getVotingUnits(address account) internal virtual override returns (uint256) {
  39. return balanceOf(account);
  40. }
  41. /**
  42. * This empty reserved space is put in place to allow future versions to add new
  43. * variables without shifting down storage in the inheritance chain.
  44. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
  45. */
  46. uint256[50] private __gap;
  47. }