GovernorSuperQuorum.sol 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.20;
  3. import {Governor} from "../Governor.sol";
  4. import {SafeCast} from "../../utils/math/SafeCast.sol";
  5. import {Checkpoints} from "../../utils/structs/Checkpoints.sol";
  6. /**
  7. * @dev Extension of {Governor} with a super quorum. Proposals that meet the super quorum (and have a majority of for
  8. * votes) advance to the `Succeeded` state before the proposal deadline. Counting modules that want to use this
  9. * extension must implement {proposalVotes}.
  10. */
  11. abstract contract GovernorSuperQuorum is Governor {
  12. /**
  13. * @dev Minimum number of cast votes required for a proposal to reach super quorum. Only FOR votes are counted
  14. * towards the super quorum. Once the super quorum is reached, an active proposal can proceed to the next state
  15. * without waiting for the proposal deadline.
  16. *
  17. * NOTE: The `timepoint` parameter corresponds to the snapshot used for counting the vote. This enables scaling of the
  18. * quorum depending on values such as the `totalSupply` of a token at this timepoint (see {ERC20Votes}).
  19. *
  20. * NOTE: Make sure the value specified for the super quorum is greater than {quorum}, otherwise, it may be
  21. * possible to pass a proposal with less votes than the default quorum.
  22. */
  23. function superQuorum(uint256 timepoint) public view virtual returns (uint256);
  24. /**
  25. * @dev Accessor to the internal vote counts. This must be implemented by the counting module. Counting modules
  26. * that don't implement this function are incompatible with this module
  27. */
  28. function proposalVotes(
  29. uint256 proposalId
  30. ) public view virtual returns (uint256 againstVotes, uint256 forVotes, uint256 abstainVotes);
  31. /**
  32. * @dev Overridden version of the {Governor-state} function that checks if the proposal has reached the super
  33. * quorum.
  34. *
  35. * NOTE: If the proposal reaches super quorum but {_voteSucceeded} returns false, eg, assuming the super quorum
  36. * has been set low enough that both FOR and AGAINST votes have exceeded it and AGAINST votes exceed FOR votes,
  37. * the proposal continues to be active until {_voteSucceeded} returns true or the proposal deadline is reached.
  38. * This means that with a low super quorum it is also possible that a vote can succeed prematurely before enough
  39. * AGAINST voters have a chance to vote. Hence, it is recommended to set a high enough super quorum to avoid these
  40. * types of scenarios.
  41. */
  42. function state(uint256 proposalId) public view virtual override returns (ProposalState) {
  43. ProposalState currentState = super.state(proposalId);
  44. if (currentState != ProposalState.Active) return currentState;
  45. (, uint256 forVotes, ) = proposalVotes(proposalId);
  46. if (forVotes < superQuorum(proposalSnapshot(proposalId)) || !_voteSucceeded(proposalId)) {
  47. return ProposalState.Active;
  48. } else if (proposalEta(proposalId) == 0) {
  49. return ProposalState.Succeeded;
  50. } else {
  51. return ProposalState.Queued;
  52. }
  53. }
  54. }