ERC20VotesComp.sol 2.1 KB

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