Files
openzeppelin-contracts/contracts/governance/extensions/GovernorSuperQuorum.sol
github-actions[bot] d183d9b07a Merge release-v5.3 branch (#5632)
Signed-off-by: Hadrien Croubois <hadrien.croubois@gmail.com>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
Co-authored-by: Francisco Giordano <fg@frang.io>
Co-authored-by: Joseph Delong <joseph@delong.me>
Co-authored-by: Arr00 <13561405+arr00@users.noreply.github.com>
Co-authored-by: Renan Souza <renan.rodrigues.souza1@gmail.com>
Co-authored-by: Ernesto García <ernestognw@gmail.com>
Co-authored-by: Voronor <129545215+voronor@users.noreply.github.com>
Co-authored-by: StackOverflowExcept1on <109800286+StackOverflowExcept1on@users.noreply.github.com>
Co-authored-by: Michalis Kargakis <kargakis@protonmail.com>
Co-authored-by: Bilog WEB3 <155262265+Bilogweb3@users.noreply.github.com>
Co-authored-by: Fallengirl <155266340+Fallengirl@users.noreply.github.com>
Co-authored-by: XxAlex74xX <30472093+XxAlex74xX@users.noreply.github.com>
Co-authored-by: PixelPilot <161360836+PixelPil0t1@users.noreply.github.com>
Co-authored-by: kilavvy <140459108+kilavvy@users.noreply.github.com>
Co-authored-by: Devkuni <155117116+detrina@users.noreply.github.com>
Co-authored-by: Danbo <140512416+dannbbb1@users.noreply.github.com>
Co-authored-by: Ann Wagner <chant_77_swirly@icloud.com>
Co-authored-by: comfsrt <155266597+comfsrt@users.noreply.github.com>
Co-authored-by: Bob <158583129+bouchmann@users.noreply.github.com>
Co-authored-by: JohnBonny <158583902+JohnBonny@users.noreply.github.com>
Co-authored-by: moonman <155266991+moooonman@users.noreply.github.com>
Co-authored-by: kazak <alright-epsilon8h@icloud.com>
Co-authored-by: Wei <ybxerlvqtx@rambler.ru>
Co-authored-by: Maxim Evtush <154841002+maximevtush@users.noreply.github.com>
Co-authored-by: Vitalyr <158586577+Vitaliyr888@users.noreply.github.com>
Co-authored-by: pendrue <158588659+pendrue@users.noreply.github.com>
Co-authored-by: Tronica <wudmytrotest404@gmail.com>
Co-authored-by: emmmm <155267286+eeemmmmmm@users.noreply.github.com>
Co-authored-by: bigbear <155267841+aso20455@users.noreply.github.com>
Co-authored-by: Tomás Andróil <tomasandroil@gmail.com>
Co-authored-by: GooseMatrix <155266802+GooseMatrix@users.noreply.github.com>
Co-authored-by: jasmy <3776356370@qq.com>
Co-authored-by: SITADRITA1 <mrlime2018@gmail.com>
Co-authored-by: Ocenka <testoviydiman1@gmail.com>
2025-04-09 20:47:07 +02:00

61 lines
3.1 KiB
Solidity

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (governance/extensions/GovernorSuperQuorum.sol)
pragma solidity ^0.8.20;
import {Governor} from "../Governor.sol";
import {SafeCast} from "../../utils/math/SafeCast.sol";
import {Checkpoints} from "../../utils/structs/Checkpoints.sol";
/**
* @dev Extension of {Governor} with a super quorum. Proposals that meet the super quorum (and have a majority of for
* votes) advance to the `Succeeded` state before the proposal deadline. Counting modules that want to use this
* extension must implement {proposalVotes}.
*/
abstract contract GovernorSuperQuorum is Governor {
/**
* @dev Minimum number of cast votes required for a proposal to reach super quorum. Only FOR votes are counted
* towards the super quorum. Once the super quorum is reached, an active proposal can proceed to the next state
* without waiting for the proposal deadline.
*
* NOTE: The `timepoint` parameter corresponds to the snapshot used for counting the vote. This enables scaling of the
* quorum depending on values such as the `totalSupply` of a token at this timepoint (see {ERC20Votes}).
*
* NOTE: Make sure the value specified for the super quorum is greater than {quorum}, otherwise, it may be
* possible to pass a proposal with less votes than the default quorum.
*/
function superQuorum(uint256 timepoint) public view virtual returns (uint256);
/**
* @dev Accessor to the internal vote counts. This must be implemented by the counting module. Counting modules
* that don't implement this function are incompatible with this module
*/
function proposalVotes(
uint256 proposalId
) public view virtual returns (uint256 againstVotes, uint256 forVotes, uint256 abstainVotes);
/**
* @dev Overridden version of the {Governor-state} function that checks if the proposal has reached the super
* quorum.
*
* NOTE: If the proposal reaches super quorum but {_voteSucceeded} returns false, eg, assuming the super quorum
* has been set low enough that both FOR and AGAINST votes have exceeded it and AGAINST votes exceed FOR votes,
* the proposal continues to be active until {_voteSucceeded} returns true or the proposal deadline is reached.
* This means that with a low super quorum it is also possible that a vote can succeed prematurely before enough
* AGAINST voters have a chance to vote. Hence, it is recommended to set a high enough super quorum to avoid these
* types of scenarios.
*/
function state(uint256 proposalId) public view virtual override returns (ProposalState) {
ProposalState currentState = super.state(proposalId);
if (currentState != ProposalState.Active) return currentState;
(, uint256 forVotes, ) = proposalVotes(proposalId);
if (forVotes < superQuorum(proposalSnapshot(proposalId)) || !_voteSucceeded(proposalId)) {
return ProposalState.Active;
} else if (proposalEta(proposalId) == 0) {
return ProposalState.Succeeded;
} else {
return ProposalState.Queued;
}
}
}