ERC20VotesCompUpgradeable.sol 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts (last updated v4.5.0-rc.0) (token/ERC20/extensions/ERC20VotesComp.sol)
  3. pragma solidity ^0.8.0;
  4. import "./ERC20VotesUpgradeable.sol";
  5. import "../../../proxy/utils/Initializable.sol";
  6. /**
  7. * @dev Extension of ERC20 to support Compound's voting and delegation. This version exactly matches Compound's
  8. * interface, with the drawback of only supporting supply up to (2^96^ - 1).
  9. *
  10. * NOTE: You should use this contract if you need exact compatibility with COMP (for example in order to use your token
  11. * with Governor Alpha or Bravo) and if you are sure the supply cap of 2^96^ is enough for you. Otherwise, use the
  12. * {ERC20Votes} variant of this module.
  13. *
  14. * This extension keeps a history (checkpoints) of each account's vote power. Vote power can be delegated either
  15. * by calling the {delegate} function directly, or by providing a signature to be used with {delegateBySig}. Voting
  16. * power can be queried through the public accessors {getCurrentVotes} and {getPriorVotes}.
  17. *
  18. * By default, token balance does not account for voting power. This makes transfers cheaper. The downside is that it
  19. * requires users to delegate to themselves in order to activate checkpoints and have their voting power tracked.
  20. *
  21. * _Available since v4.2._
  22. */
  23. abstract contract ERC20VotesCompUpgradeable is Initializable, ERC20VotesUpgradeable {
  24. function __ERC20VotesComp_init() internal onlyInitializing {
  25. }
  26. function __ERC20VotesComp_init_unchained() internal onlyInitializing {
  27. }
  28. /**
  29. * @dev Comp version of the {getVotes} accessor, with `uint96` return type.
  30. */
  31. function getCurrentVotes(address account) external view virtual returns (uint96) {
  32. return SafeCastUpgradeable.toUint96(getVotes(account));
  33. }
  34. /**
  35. * @dev Comp version of the {getPastVotes} accessor, with `uint96` return type.
  36. */
  37. function getPriorVotes(address account, uint256 blockNumber) external view virtual returns (uint96) {
  38. return SafeCastUpgradeable.toUint96(getPastVotes(account, blockNumber));
  39. }
  40. /**
  41. * @dev Maximum token supply. Reduced to `type(uint96).max` (2^96^ - 1) to fit COMP interface.
  42. */
  43. function _maxSupply() internal view virtual override returns (uint224) {
  44. return type(uint96).max;
  45. }
  46. /**
  47. * This empty reserved space is put in place to allow future versions to add new
  48. * variables without shifting down storage in the inheritance chain.
  49. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
  50. */
  51. uint256[50] private __gap;
  52. }