ERC721Votes.sol 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.0;
  3. import "../ERC721.sol";
  4. import "../../../governance/utils/Votes.sol";
  5. /**
  6. * @dev Extension of ERC721 to support voting and delegation as implemented by {Votes}, where each individual NFT counts
  7. * as 1 vote unit.
  8. *
  9. * Tokens do not count as votes until they are delegated, because votes must be tracked which incurs an additional cost
  10. * on every transfer. Token holders can either delegate to a trusted representative who will decide how to make use of
  11. * the votes in governance decisions, or they can delegate to themselves to be their own representative.
  12. *
  13. * _Available since v4.5._
  14. */
  15. abstract contract ERC721Votes is ERC721, Votes {
  16. /**
  17. * @dev Adjusts votes when tokens are transferred.
  18. *
  19. * Emits a {Votes-DelegateVotesChanged} event.
  20. */
  21. function _afterTokenTransfer(
  22. address from,
  23. address to,
  24. uint256 tokenId
  25. ) internal virtual override {
  26. _transferVotingUnits(from, to, 1);
  27. super._afterTokenTransfer(from, to, tokenId);
  28. }
  29. /**
  30. * @dev Adjusts votes when a batch of tokens is transferred.
  31. *
  32. * Emits a {Votes-DelegateVotesChanged} event.
  33. */
  34. function _afterConsecutiveTokenTransfer(
  35. address from,
  36. address to,
  37. uint256 first,
  38. uint96 size
  39. ) internal virtual override {
  40. _transferVotingUnits(from, to, size);
  41. super._afterConsecutiveTokenTransfer(from, to, first, size);
  42. }
  43. /**
  44. * @dev Returns the balance of `account`.
  45. */
  46. function _getVotingUnits(address account) internal view virtual override returns (uint256) {
  47. return balanceOf(account);
  48. }
  49. }