GovernorVotes.sol 879 B

12345678910111213141516171819202122232425262728293031
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts (last updated v4.6.0) (governance/extensions/GovernorVotes.sol)
  3. pragma solidity ^0.8.0;
  4. import "../Governor.sol";
  5. import "../utils/IVotes.sol";
  6. /**
  7. * @dev Extension of {Governor} for voting weight extraction from an {ERC20Votes} token, or since v4.5 an {ERC721Votes} token.
  8. *
  9. * _Available since v4.3._
  10. */
  11. abstract contract GovernorVotes is Governor {
  12. IVotes public immutable token;
  13. constructor(IVotes tokenAddress) {
  14. token = tokenAddress;
  15. }
  16. /**
  17. * Read the voting weight from the token's built in snapshot mechanism (see {Governor-_getVotes}).
  18. */
  19. function _getVotes(
  20. address account,
  21. uint256 blockNumber,
  22. bytes memory /*params*/
  23. ) internal view virtual override returns (uint256) {
  24. return token.getPastVotes(account, blockNumber);
  25. }
  26. }