GovernorVotesUpgradeable.sol 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. __GovernorVotes_init_unchained(tokenAddress);
  16. }
  17. function __GovernorVotes_init_unchained(IVotesUpgradeable tokenAddress) internal onlyInitializing {
  18. token = tokenAddress;
  19. }
  20. /**
  21. * Read the voting weight from the token's built in snapshot mechanism (see {IGovernor-getVotes}).
  22. */
  23. function getVotes(address account, uint256 blockNumber) public view virtual override returns (uint256) {
  24. return token.getPastVotes(account, blockNumber);
  25. }
  26. /**
  27. * This empty reserved space is put in place to allow future versions to add new
  28. * variables without shifting down storage in the inheritance chain.
  29. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
  30. */
  31. uint256[50] private __gap;
  32. }