GovernorSuperQuorum.sol 3.0 KB

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