GovernorVotesUpgradeable.sol 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts (last updated v4.5.0-rc.0) (governance/extensions/GovernorVotes.sol)
  3. pragma solidity ^0.8.0;
  4. import "../GovernorUpgradeable.sol";
  5. import "../utils/IVotesUpgradeable.sol";
  6. import "../../proxy/utils/Initializable.sol";
  7. /**
  8. * @dev Extension of {Governor} for voting weight extraction from an {ERC20Votes} token, or since v4.5 an {ERC721Votes} token.
  9. *
  10. * _Available since v4.3._
  11. */
  12. abstract contract GovernorVotesUpgradeable is Initializable, GovernorUpgradeable {
  13. IVotesUpgradeable public token;
  14. function __GovernorVotes_init(IVotesUpgradeable tokenAddress) internal onlyInitializing {
  15. __Context_init_unchained();
  16. __ERC165_init_unchained();
  17. __IGovernor_init_unchained();
  18. __GovernorVotes_init_unchained(tokenAddress);
  19. }
  20. function __GovernorVotes_init_unchained(IVotesUpgradeable tokenAddress) internal onlyInitializing {
  21. token = tokenAddress;
  22. }
  23. /**
  24. * Read the voting weight from the token's built in snapshot mechanism (see {IGovernor-getVotes}).
  25. */
  26. function getVotes(address account, uint256 blockNumber) public view virtual override returns (uint256) {
  27. return token.getPastVotes(account, blockNumber);
  28. }
  29. uint256[50] private __gap;
  30. }