ERC721Votes.sol 1.5 KB

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