ERC20VotesComp.sol 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/extensions/ERC20VotesComp.sol)
  3. pragma solidity ^0.8.0;
  4. import "./ERC20Votes.sol";
  5. /**
  6. * @dev Extension of ERC20 to support Compound's voting and delegation. This version exactly matches Compound's
  7. * interface, with the drawback of only supporting supply up to (2^96^ - 1).
  8. *
  9. * NOTE: You should use this contract if you need exact compatibility with COMP (for example in order to use your token
  10. * with Governor Alpha or Bravo) and if you are sure the supply cap of 2^96^ is enough for you. Otherwise, use the
  11. * {ERC20Votes} variant of this module.
  12. *
  13. * This extension keeps a history (checkpoints) of each account's vote power. Vote power can be delegated either
  14. * by calling the {delegate} function directly, or by providing a signature to be used with {delegateBySig}. Voting
  15. * power can be queried through the public accessors {getCurrentVotes} and {getPriorVotes}.
  16. *
  17. * By default, token balance does not account for voting power. This makes transfers cheaper. The downside is that it
  18. * requires users to delegate to themselves in order to activate checkpoints and have their voting power tracked.
  19. *
  20. * _Available since v4.2._
  21. */
  22. abstract contract ERC20VotesComp is ERC20Votes {
  23. /**
  24. * @dev Comp version of the {getVotes} accessor, with `uint96` return type.
  25. */
  26. function getCurrentVotes(address account) external view virtual returns (uint96) {
  27. return SafeCast.toUint96(getVotes(account));
  28. }
  29. /**
  30. * @dev Comp version of the {getPastVotes} accessor, with `uint96` return type.
  31. */
  32. function getPriorVotes(address account, uint256 blockNumber) external view virtual returns (uint96) {
  33. return SafeCast.toUint96(getPastVotes(account, blockNumber));
  34. }
  35. /**
  36. * @dev Maximum token supply. Reduced to `type(uint96).max` (2^96^ - 1) to fit COMP interface.
  37. */
  38. function _maxSupply() internal view virtual override returns (uint224) {
  39. return type(uint96).max;
  40. }
  41. }