refactor: move brother_node development artifact to dev/test-nodes subdirectory
Development Artifact Cleanup: ✅ BROTHER_NODE REORGANIZATION: Moved development test node to appropriate location - dev/test-nodes/brother_node/: Moved from root directory for better organization - Contains development configuration, test logs, and test chain data - No impact on production systems - purely development/testing artifact ✅ DEVELOPMENT ARTIFACTS IDENTIFIED: - Chain ID: aitbc-brother-chain (test/development chain) - Ports: 8010 (P2P) and 8011 (RPC) - different from production - Environment: .env file with test configuration - Logs: rpc.log and node.log from development testing session (March 15, 2026) ✅ ROOT DIRECTORY CLEANUP: Removed development clutter from production directory - brother_node/ moved to dev/test-nodes/brother_node/ - Root directory now contains only production-ready components - Development artifacts properly organized in dev/ subdirectory DIRECTORY STRUCTURE IMPROVEMENT: 📁 dev/test-nodes/: Development and testing node configurations 🏗️ Root Directory: Clean production structure with only essential components 🧪 Development Isolation: Test environments separated from production BENEFITS: ✅ Clean Production Directory: No development artifacts in root ✅ Better Organization: Development nodes grouped in dev/ subdirectory ✅ Clear Separation: Production vs development environments clearly distinguished ✅ Maintainability: Easier to identify and manage development components RESULT: Successfully moved brother_node development artifact to dev/test-nodes/ subdirectory, cleaning up the root directory while preserving development testing environment for future use.
This commit is contained in:
190
dev/env/node_modules/@openzeppelin/contracts/governance/extensions/GovernorCountingFractional.sol
generated
vendored
Executable file
190
dev/env/node_modules/@openzeppelin/contracts/governance/extensions/GovernorCountingFractional.sol
generated
vendored
Executable file
@@ -0,0 +1,190 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v5.4.0) (governance/extensions/GovernorCountingFractional.sol)
|
||||
|
||||
pragma solidity ^0.8.24;
|
||||
|
||||
import {IGovernor, Governor} from "../Governor.sol";
|
||||
import {GovernorCountingSimple} from "./GovernorCountingSimple.sol";
|
||||
import {Math} from "../../utils/math/Math.sol";
|
||||
|
||||
/**
|
||||
* @dev Extension of {Governor} for fractional voting.
|
||||
*
|
||||
* Similar to {GovernorCountingSimple}, this contract is a votes counting module for {Governor} that supports 3 options:
|
||||
* Against, For, Abstain. Additionally, it includes a fourth option: Fractional, which allows voters to split their voting
|
||||
* power amongst the other 3 options.
|
||||
*
|
||||
* Votes cast with the Fractional support must be accompanied by a `params` argument that is three packed `uint128` values
|
||||
* representing the weight the delegate assigns to Against, For, and Abstain respectively. For those votes cast for the other
|
||||
* 3 options, the `params` argument must be empty.
|
||||
*
|
||||
* This is mostly useful when the delegate is a contract that implements its own rules for voting. These delegate-contracts
|
||||
* can cast fractional votes according to the preferences of multiple entities delegating their voting power.
|
||||
*
|
||||
* Some example use cases include:
|
||||
*
|
||||
* * Voting from tokens that are held by a DeFi pool
|
||||
* * Voting from an L2 with tokens held by a bridge
|
||||
* * Voting privately from a shielded pool using zero knowledge proofs.
|
||||
*
|
||||
* Based on ScopeLift's https://github.com/ScopeLift/flexible-voting/blob/e5de2efd1368387b840931f19f3c184c85842761/src/GovernorCountingFractional.sol[`GovernorCountingFractional`]
|
||||
*
|
||||
* _Available since v5.1._
|
||||
*/
|
||||
abstract contract GovernorCountingFractional is Governor {
|
||||
using Math for *;
|
||||
|
||||
uint8 internal constant VOTE_TYPE_FRACTIONAL = 255;
|
||||
|
||||
struct ProposalVote {
|
||||
uint256 againstVotes;
|
||||
uint256 forVotes;
|
||||
uint256 abstainVotes;
|
||||
mapping(address voter => uint256) usedVotes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Mapping from proposal ID to vote tallies for that proposal.
|
||||
*/
|
||||
mapping(uint256 proposalId => ProposalVote) private _proposalVotes;
|
||||
|
||||
/**
|
||||
* @dev A fractional vote params uses more votes than are available for that user.
|
||||
*/
|
||||
error GovernorExceedRemainingWeight(address voter, uint256 usedVotes, uint256 remainingWeight);
|
||||
|
||||
/// @inheritdoc IGovernor
|
||||
// solhint-disable-next-line func-name-mixedcase
|
||||
function COUNTING_MODE() public pure virtual override returns (string memory) {
|
||||
return "support=bravo,fractional&quorum=for,abstain¶ms=fractional";
|
||||
}
|
||||
|
||||
/// @inheritdoc IGovernor
|
||||
function hasVoted(uint256 proposalId, address account) public view virtual override returns (bool) {
|
||||
return usedVotes(proposalId, account) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Get the number of votes already cast by `account` for a proposal with `proposalId`. Useful for
|
||||
* integrations that allow delegates to cast rolling, partial votes.
|
||||
*/
|
||||
function usedVotes(uint256 proposalId, address account) public view virtual returns (uint256) {
|
||||
return _proposalVotes[proposalId].usedVotes[account];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Get current distribution of votes for a given proposal.
|
||||
*/
|
||||
function proposalVotes(
|
||||
uint256 proposalId
|
||||
) public view virtual returns (uint256 againstVotes, uint256 forVotes, uint256 abstainVotes) {
|
||||
ProposalVote storage proposalVote = _proposalVotes[proposalId];
|
||||
return (proposalVote.againstVotes, proposalVote.forVotes, proposalVote.abstainVotes);
|
||||
}
|
||||
|
||||
/// @inheritdoc Governor
|
||||
function _quorumReached(uint256 proposalId) internal view virtual override returns (bool) {
|
||||
ProposalVote storage proposalVote = _proposalVotes[proposalId];
|
||||
return quorum(proposalSnapshot(proposalId)) <= proposalVote.forVotes + proposalVote.abstainVotes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {Governor-_voteSucceeded}. In this module, forVotes must be > againstVotes.
|
||||
*/
|
||||
function _voteSucceeded(uint256 proposalId) internal view virtual override returns (bool) {
|
||||
ProposalVote storage proposalVote = _proposalVotes[proposalId];
|
||||
return proposalVote.forVotes > proposalVote.againstVotes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {Governor-_countVote}. Function that records the delegate's votes.
|
||||
*
|
||||
* Executing this function consumes (part of) the delegate's weight on the proposal. This weight can be
|
||||
* distributed amongst the 3 options (Against, For, Abstain) by specifying a fractional `support`.
|
||||
*
|
||||
* This counting module supports two vote casting modes: nominal and fractional.
|
||||
*
|
||||
* - Nominal: A nominal vote is cast by setting `support` to one of the 3 bravo options (Against, For, Abstain).
|
||||
* - Fractional: A fractional vote is cast by setting `support` to `type(uint8).max` (255).
|
||||
*
|
||||
* Casting a nominal vote requires `params` to be empty and consumes the delegate's full remaining weight on the
|
||||
* proposal for the specified `support` option. This is similar to the {GovernorCountingSimple} module and follows
|
||||
* the `VoteType` enum from Governor Bravo. As a consequence, no vote weight remains unspent so no further voting
|
||||
* is possible (for this `proposalId` and this `account`).
|
||||
*
|
||||
* Casting a fractional vote consumes a fraction of the delegate's remaining weight on the proposal according to the
|
||||
* weights the delegate assigns to each support option (Against, For, Abstain respectively). The sum total of the
|
||||
* three decoded vote weights _must_ be less than or equal to the delegate's remaining weight on the proposal (i.e.
|
||||
* their checkpointed total weight minus votes already cast on the proposal). This format can be produced using:
|
||||
*
|
||||
* `abi.encodePacked(uint128(againstVotes), uint128(forVotes), uint128(abstainVotes))`
|
||||
*
|
||||
* NOTE: Consider that fractional voting restricts the number of casted votes (in each category) to 128 bits.
|
||||
* Depending on how many decimals the underlying token has, a single voter may require to split their vote into
|
||||
* multiple vote operations. For precision higher than ~30 decimals, large token holders may require a
|
||||
* potentially large number of calls to cast all their votes. The voter has the possibility to cast all the
|
||||
* remaining votes in a single operation using the traditional "bravo" vote.
|
||||
*/
|
||||
// slither-disable-next-line cyclomatic-complexity
|
||||
function _countVote(
|
||||
uint256 proposalId,
|
||||
address account,
|
||||
uint8 support,
|
||||
uint256 totalWeight,
|
||||
bytes memory params
|
||||
) internal virtual override returns (uint256) {
|
||||
// Compute number of remaining votes. Returns 0 on overflow.
|
||||
(, uint256 remainingWeight) = totalWeight.trySub(usedVotes(proposalId, account));
|
||||
if (remainingWeight == 0) {
|
||||
revert GovernorAlreadyCastVote(account);
|
||||
}
|
||||
|
||||
uint256 againstVotes = 0;
|
||||
uint256 forVotes = 0;
|
||||
uint256 abstainVotes = 0;
|
||||
uint256 usedWeight = 0;
|
||||
|
||||
// For clarity of event indexing, fractional voting must be clearly advertised in the "support" field.
|
||||
//
|
||||
// Supported `support` value must be:
|
||||
// - "Full" voting: `support = 0` (Against), `1` (For) or `2` (Abstain), with empty params.
|
||||
// - "Fractional" voting: `support = 255`, with 48 bytes params.
|
||||
if (support == uint8(GovernorCountingSimple.VoteType.Against)) {
|
||||
if (params.length != 0) revert GovernorInvalidVoteParams();
|
||||
usedWeight = againstVotes = remainingWeight;
|
||||
} else if (support == uint8(GovernorCountingSimple.VoteType.For)) {
|
||||
if (params.length != 0) revert GovernorInvalidVoteParams();
|
||||
usedWeight = forVotes = remainingWeight;
|
||||
} else if (support == uint8(GovernorCountingSimple.VoteType.Abstain)) {
|
||||
if (params.length != 0) revert GovernorInvalidVoteParams();
|
||||
usedWeight = abstainVotes = remainingWeight;
|
||||
} else if (support == VOTE_TYPE_FRACTIONAL) {
|
||||
// The `params` argument is expected to be three packed `uint128`:
|
||||
// `abi.encodePacked(uint128(againstVotes), uint128(forVotes), uint128(abstainVotes))`
|
||||
if (params.length != 0x30) revert GovernorInvalidVoteParams();
|
||||
|
||||
assembly ("memory-safe") {
|
||||
againstVotes := shr(128, mload(add(params, 0x20)))
|
||||
forVotes := shr(128, mload(add(params, 0x30)))
|
||||
abstainVotes := shr(128, mload(add(params, 0x40)))
|
||||
usedWeight := add(add(againstVotes, forVotes), abstainVotes) // inputs are uint128: cannot overflow
|
||||
}
|
||||
|
||||
// check parsed arguments are valid
|
||||
if (usedWeight > remainingWeight) {
|
||||
revert GovernorExceedRemainingWeight(account, usedWeight, remainingWeight);
|
||||
}
|
||||
} else {
|
||||
revert GovernorInvalidVoteType();
|
||||
}
|
||||
|
||||
// update votes tracking
|
||||
ProposalVote storage details = _proposalVotes[proposalId];
|
||||
if (againstVotes > 0) details.againstVotes += againstVotes;
|
||||
if (forVotes > 0) details.forVotes += forVotes;
|
||||
if (abstainVotes > 0) details.abstainVotes += abstainVotes;
|
||||
details.usedVotes[account] += usedWeight;
|
||||
|
||||
return usedWeight;
|
||||
}
|
||||
}
|
||||
222
dev/env/node_modules/@openzeppelin/contracts/governance/extensions/GovernorCountingOverridable.sol
generated
vendored
Executable file
222
dev/env/node_modules/@openzeppelin/contracts/governance/extensions/GovernorCountingOverridable.sol
generated
vendored
Executable file
@@ -0,0 +1,222 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v5.4.0) (governance/extensions/GovernorCountingOverridable.sol)
|
||||
|
||||
pragma solidity ^0.8.24;
|
||||
|
||||
import {SignatureChecker} from "../../utils/cryptography/SignatureChecker.sol";
|
||||
import {SafeCast} from "../../utils/math/SafeCast.sol";
|
||||
import {VotesExtended} from "../utils/VotesExtended.sol";
|
||||
import {GovernorVotes} from "./GovernorVotes.sol";
|
||||
import {IGovernor, Governor} from "../Governor.sol";
|
||||
|
||||
/**
|
||||
* @dev Extension of {Governor} which enables delegators to override the vote of their delegates. This module requires a
|
||||
* token that inherits {VotesExtended}.
|
||||
*/
|
||||
abstract contract GovernorCountingOverridable is GovernorVotes {
|
||||
bytes32 public constant OVERRIDE_BALLOT_TYPEHASH =
|
||||
keccak256("OverrideBallot(uint256 proposalId,uint8 support,address voter,uint256 nonce,string reason)");
|
||||
|
||||
/**
|
||||
* @dev Supported vote types. Matches Governor Bravo ordering.
|
||||
*/
|
||||
enum VoteType {
|
||||
Against,
|
||||
For,
|
||||
Abstain
|
||||
}
|
||||
|
||||
struct VoteReceipt {
|
||||
uint8 casted; // 0 if vote was not casted. Otherwise: support + 1
|
||||
bool hasOverridden;
|
||||
uint208 overriddenWeight;
|
||||
}
|
||||
|
||||
struct ProposalVote {
|
||||
uint256[3] votes;
|
||||
mapping(address voter => VoteReceipt) voteReceipt;
|
||||
}
|
||||
|
||||
/// @dev The votes casted by `delegate` were reduced by `weight` after an override vote was casted by the original token holder
|
||||
event VoteReduced(address indexed delegate, uint256 proposalId, uint8 support, uint256 weight);
|
||||
|
||||
/// @dev A delegated vote on `proposalId` was overridden by `weight`
|
||||
event OverrideVoteCast(address indexed voter, uint256 proposalId, uint8 support, uint256 weight, string reason);
|
||||
|
||||
error GovernorAlreadyOverriddenVote(address account);
|
||||
|
||||
mapping(uint256 proposalId => ProposalVote) private _proposalVotes;
|
||||
|
||||
/// @inheritdoc IGovernor
|
||||
// solhint-disable-next-line func-name-mixedcase
|
||||
function COUNTING_MODE() public pure virtual override returns (string memory) {
|
||||
return "support=bravo,override&quorum=for,abstain&overridable=true";
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {IGovernor-hasVoted}.
|
||||
*
|
||||
* NOTE: Calling {castVote} (or similar) casts a vote using the voting power that is delegated to the voter.
|
||||
* Conversely, calling {castOverrideVote} (or similar) uses the voting power of the account itself, from its asset
|
||||
* balances. Casting an "override vote" does not count as voting and won't be reflected by this getter. Consider
|
||||
* using {hasVotedOverride} to check if an account has casted an "override vote" for a given proposal id.
|
||||
*/
|
||||
function hasVoted(uint256 proposalId, address account) public view virtual override returns (bool) {
|
||||
return _proposalVotes[proposalId].voteReceipt[account].casted != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Check if an `account` has overridden their delegate for a proposal.
|
||||
*/
|
||||
function hasVotedOverride(uint256 proposalId, address account) public view virtual returns (bool) {
|
||||
return _proposalVotes[proposalId].voteReceipt[account].hasOverridden;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Accessor to the internal vote counts.
|
||||
*/
|
||||
function proposalVotes(
|
||||
uint256 proposalId
|
||||
) public view virtual returns (uint256 againstVotes, uint256 forVotes, uint256 abstainVotes) {
|
||||
uint256[3] storage votes = _proposalVotes[proposalId].votes;
|
||||
return (votes[uint8(VoteType.Against)], votes[uint8(VoteType.For)], votes[uint8(VoteType.Abstain)]);
|
||||
}
|
||||
|
||||
/// @inheritdoc Governor
|
||||
function _quorumReached(uint256 proposalId) internal view virtual override returns (bool) {
|
||||
uint256[3] storage votes = _proposalVotes[proposalId].votes;
|
||||
return quorum(proposalSnapshot(proposalId)) <= votes[uint8(VoteType.For)] + votes[uint8(VoteType.Abstain)];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {Governor-_voteSucceeded}. In this module, the forVotes must be strictly over the againstVotes.
|
||||
*/
|
||||
function _voteSucceeded(uint256 proposalId) internal view virtual override returns (bool) {
|
||||
uint256[3] storage votes = _proposalVotes[proposalId].votes;
|
||||
return votes[uint8(VoteType.For)] > votes[uint8(VoteType.Against)];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {Governor-_countVote}. In this module, the support follows the `VoteType` enum (from Governor Bravo).
|
||||
*
|
||||
* NOTE: called by {Governor-_castVote} which emits the {IGovernor-VoteCast} (or {IGovernor-VoteCastWithParams})
|
||||
* event.
|
||||
*/
|
||||
function _countVote(
|
||||
uint256 proposalId,
|
||||
address account,
|
||||
uint8 support,
|
||||
uint256 totalWeight,
|
||||
bytes memory /*params*/
|
||||
) internal virtual override returns (uint256) {
|
||||
ProposalVote storage proposalVote = _proposalVotes[proposalId];
|
||||
|
||||
if (support > uint8(VoteType.Abstain)) {
|
||||
revert GovernorInvalidVoteType();
|
||||
}
|
||||
|
||||
if (proposalVote.voteReceipt[account].casted != 0) {
|
||||
revert GovernorAlreadyCastVote(account);
|
||||
}
|
||||
|
||||
totalWeight -= proposalVote.voteReceipt[account].overriddenWeight;
|
||||
proposalVote.votes[support] += totalWeight;
|
||||
proposalVote.voteReceipt[account].casted = support + 1;
|
||||
|
||||
return totalWeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Variant of {Governor-_countVote} that deals with vote overrides.
|
||||
*
|
||||
* NOTE: See {hasVoted} for more details about the difference between {castVote} and {castOverrideVote}.
|
||||
*/
|
||||
function _countOverride(uint256 proposalId, address account, uint8 support) internal virtual returns (uint256) {
|
||||
ProposalVote storage proposalVote = _proposalVotes[proposalId];
|
||||
|
||||
if (support > uint8(VoteType.Abstain)) {
|
||||
revert GovernorInvalidVoteType();
|
||||
}
|
||||
|
||||
if (proposalVote.voteReceipt[account].hasOverridden) {
|
||||
revert GovernorAlreadyOverriddenVote(account);
|
||||
}
|
||||
|
||||
uint256 snapshot = proposalSnapshot(proposalId);
|
||||
uint256 overriddenWeight = VotesExtended(address(token())).getPastBalanceOf(account, snapshot);
|
||||
address delegate = VotesExtended(address(token())).getPastDelegate(account, snapshot);
|
||||
uint8 delegateCasted = proposalVote.voteReceipt[delegate].casted;
|
||||
|
||||
proposalVote.voteReceipt[account].hasOverridden = true;
|
||||
proposalVote.votes[support] += overriddenWeight;
|
||||
if (delegateCasted == 0) {
|
||||
proposalVote.voteReceipt[delegate].overriddenWeight += SafeCast.toUint208(overriddenWeight);
|
||||
} else {
|
||||
uint8 delegateSupport = delegateCasted - 1;
|
||||
proposalVote.votes[delegateSupport] -= overriddenWeight;
|
||||
emit VoteReduced(delegate, proposalId, delegateSupport, overriddenWeight);
|
||||
}
|
||||
|
||||
return overriddenWeight;
|
||||
}
|
||||
|
||||
/// @dev Variant of {Governor-_castVote} that deals with vote overrides. Returns the overridden weight.
|
||||
function _castOverride(
|
||||
uint256 proposalId,
|
||||
address account,
|
||||
uint8 support,
|
||||
string calldata reason
|
||||
) internal virtual returns (uint256) {
|
||||
_validateStateBitmap(proposalId, _encodeStateBitmap(ProposalState.Active));
|
||||
|
||||
uint256 overriddenWeight = _countOverride(proposalId, account, support);
|
||||
|
||||
emit OverrideVoteCast(account, proposalId, support, overriddenWeight, reason);
|
||||
|
||||
_tallyUpdated(proposalId);
|
||||
|
||||
return overriddenWeight;
|
||||
}
|
||||
|
||||
/// @dev Public function for casting an override vote. Returns the overridden weight.
|
||||
function castOverrideVote(
|
||||
uint256 proposalId,
|
||||
uint8 support,
|
||||
string calldata reason
|
||||
) public virtual returns (uint256) {
|
||||
address voter = _msgSender();
|
||||
return _castOverride(proposalId, voter, support, reason);
|
||||
}
|
||||
|
||||
/// @dev Public function for casting an override vote using a voter's signature. Returns the overridden weight.
|
||||
function castOverrideVoteBySig(
|
||||
uint256 proposalId,
|
||||
uint8 support,
|
||||
address voter,
|
||||
string calldata reason,
|
||||
bytes calldata signature
|
||||
) public virtual returns (uint256) {
|
||||
bool valid = SignatureChecker.isValidSignatureNow(
|
||||
voter,
|
||||
_hashTypedDataV4(
|
||||
keccak256(
|
||||
abi.encode(
|
||||
OVERRIDE_BALLOT_TYPEHASH,
|
||||
proposalId,
|
||||
support,
|
||||
voter,
|
||||
_useNonce(voter),
|
||||
keccak256(bytes(reason))
|
||||
)
|
||||
)
|
||||
),
|
||||
signature
|
||||
);
|
||||
|
||||
if (!valid) {
|
||||
revert GovernorInvalidSignature(voter);
|
||||
}
|
||||
|
||||
return _castOverride(proposalId, voter, support, reason);
|
||||
}
|
||||
}
|
||||
96
dev/env/node_modules/@openzeppelin/contracts/governance/extensions/GovernorCountingSimple.sol
generated
vendored
Executable file
96
dev/env/node_modules/@openzeppelin/contracts/governance/extensions/GovernorCountingSimple.sol
generated
vendored
Executable file
@@ -0,0 +1,96 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v5.4.0) (governance/extensions/GovernorCountingSimple.sol)
|
||||
|
||||
pragma solidity ^0.8.24;
|
||||
|
||||
import {IGovernor, Governor} from "../Governor.sol";
|
||||
|
||||
/**
|
||||
* @dev Extension of {Governor} for simple, 3 options, vote counting.
|
||||
*/
|
||||
abstract contract GovernorCountingSimple is Governor {
|
||||
/**
|
||||
* @dev Supported vote types. Matches Governor Bravo ordering.
|
||||
*/
|
||||
enum VoteType {
|
||||
Against,
|
||||
For,
|
||||
Abstain
|
||||
}
|
||||
|
||||
struct ProposalVote {
|
||||
uint256 againstVotes;
|
||||
uint256 forVotes;
|
||||
uint256 abstainVotes;
|
||||
mapping(address voter => bool) hasVoted;
|
||||
}
|
||||
|
||||
mapping(uint256 proposalId => ProposalVote) private _proposalVotes;
|
||||
|
||||
/// @inheritdoc IGovernor
|
||||
// solhint-disable-next-line func-name-mixedcase
|
||||
function COUNTING_MODE() public pure virtual override returns (string memory) {
|
||||
return "support=bravo&quorum=for,abstain";
|
||||
}
|
||||
|
||||
/// @inheritdoc IGovernor
|
||||
function hasVoted(uint256 proposalId, address account) public view virtual override returns (bool) {
|
||||
return _proposalVotes[proposalId].hasVoted[account];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Accessor to the internal vote counts.
|
||||
*/
|
||||
function proposalVotes(
|
||||
uint256 proposalId
|
||||
) public view virtual returns (uint256 againstVotes, uint256 forVotes, uint256 abstainVotes) {
|
||||
ProposalVote storage proposalVote = _proposalVotes[proposalId];
|
||||
return (proposalVote.againstVotes, proposalVote.forVotes, proposalVote.abstainVotes);
|
||||
}
|
||||
|
||||
/// @inheritdoc Governor
|
||||
function _quorumReached(uint256 proposalId) internal view virtual override returns (bool) {
|
||||
ProposalVote storage proposalVote = _proposalVotes[proposalId];
|
||||
|
||||
return quorum(proposalSnapshot(proposalId)) <= proposalVote.forVotes + proposalVote.abstainVotes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {Governor-_voteSucceeded}. In this module, the forVotes must be strictly over the againstVotes.
|
||||
*/
|
||||
function _voteSucceeded(uint256 proposalId) internal view virtual override returns (bool) {
|
||||
ProposalVote storage proposalVote = _proposalVotes[proposalId];
|
||||
|
||||
return proposalVote.forVotes > proposalVote.againstVotes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {Governor-_countVote}. In this module, the support follows the `VoteType` enum (from Governor Bravo).
|
||||
*/
|
||||
function _countVote(
|
||||
uint256 proposalId,
|
||||
address account,
|
||||
uint8 support,
|
||||
uint256 totalWeight,
|
||||
bytes memory // params
|
||||
) internal virtual override returns (uint256) {
|
||||
ProposalVote storage proposalVote = _proposalVotes[proposalId];
|
||||
|
||||
if (proposalVote.hasVoted[account]) {
|
||||
revert GovernorAlreadyCastVote(account);
|
||||
}
|
||||
proposalVote.hasVoted[account] = true;
|
||||
|
||||
if (support == uint8(VoteType.Against)) {
|
||||
proposalVote.againstVotes += totalWeight;
|
||||
} else if (support == uint8(VoteType.For)) {
|
||||
proposalVote.forVotes += totalWeight;
|
||||
} else if (support == uint8(VoteType.Abstain)) {
|
||||
proposalVote.abstainVotes += totalWeight;
|
||||
} else {
|
||||
revert GovernorInvalidVoteType();
|
||||
}
|
||||
|
||||
return totalWeight;
|
||||
}
|
||||
}
|
||||
91
dev/env/node_modules/@openzeppelin/contracts/governance/extensions/GovernorNoncesKeyed.sol
generated
vendored
Executable file
91
dev/env/node_modules/@openzeppelin/contracts/governance/extensions/GovernorNoncesKeyed.sol
generated
vendored
Executable file
@@ -0,0 +1,91 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v5.4.0) (governance/extensions/GovernorNoncesKeyed.sol)
|
||||
|
||||
pragma solidity ^0.8.24;
|
||||
|
||||
import {Governor} from "../Governor.sol";
|
||||
import {Nonces} from "../../utils/Nonces.sol";
|
||||
import {NoncesKeyed} from "../../utils/NoncesKeyed.sol";
|
||||
import {SignatureChecker} from "../../utils/cryptography/SignatureChecker.sol";
|
||||
|
||||
/**
|
||||
* @dev An extension of {Governor} that extends existing nonce management to use {NoncesKeyed}, where the key is the low-order 192 bits of the `proposalId`.
|
||||
* This is useful for voting by signature while maintaining separate sequences of nonces for each proposal.
|
||||
*
|
||||
* NOTE: Traditional (un-keyed) nonces are still supported and can continue to be used as if this extension was not present.
|
||||
*/
|
||||
abstract contract GovernorNoncesKeyed is Governor, NoncesKeyed {
|
||||
function _useCheckedNonce(address owner, uint256 nonce) internal virtual override(Nonces, NoncesKeyed) {
|
||||
super._useCheckedNonce(owner, nonce);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Check the signature against keyed nonce and falls back to the traditional nonce.
|
||||
*
|
||||
* NOTE: This function won't call `super._validateVoteSig` if the keyed nonce is valid.
|
||||
* Side effects may be skipped depending on the linearization of the function.
|
||||
*/
|
||||
function _validateVoteSig(
|
||||
uint256 proposalId,
|
||||
uint8 support,
|
||||
address voter,
|
||||
bytes memory signature
|
||||
) internal virtual override returns (bool) {
|
||||
if (
|
||||
SignatureChecker.isValidSignatureNow(
|
||||
voter,
|
||||
_hashTypedDataV4(
|
||||
keccak256(
|
||||
abi.encode(BALLOT_TYPEHASH, proposalId, support, voter, nonces(voter, uint192(proposalId)))
|
||||
)
|
||||
),
|
||||
signature
|
||||
)
|
||||
) {
|
||||
_useNonce(voter, uint192(proposalId));
|
||||
return true;
|
||||
} else {
|
||||
return super._validateVoteSig(proposalId, support, voter, signature);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Check the signature against keyed nonce and falls back to the traditional nonce.
|
||||
*
|
||||
* NOTE: This function won't call `super._validateExtendedVoteSig` if the keyed nonce is valid.
|
||||
* Side effects may be skipped depending on the linearization of the function.
|
||||
*/
|
||||
function _validateExtendedVoteSig(
|
||||
uint256 proposalId,
|
||||
uint8 support,
|
||||
address voter,
|
||||
string memory reason,
|
||||
bytes memory params,
|
||||
bytes memory signature
|
||||
) internal virtual override returns (bool) {
|
||||
if (
|
||||
SignatureChecker.isValidSignatureNow(
|
||||
voter,
|
||||
_hashTypedDataV4(
|
||||
keccak256(
|
||||
abi.encode(
|
||||
EXTENDED_BALLOT_TYPEHASH,
|
||||
proposalId,
|
||||
support,
|
||||
voter,
|
||||
nonces(voter, uint192(proposalId)),
|
||||
keccak256(bytes(reason)),
|
||||
keccak256(params)
|
||||
)
|
||||
)
|
||||
),
|
||||
signature
|
||||
)
|
||||
) {
|
||||
_useNonce(voter, uint192(proposalId));
|
||||
return true;
|
||||
} else {
|
||||
return super._validateExtendedVoteSig(proposalId, support, voter, reason, params, signature);
|
||||
}
|
||||
}
|
||||
}
|
||||
92
dev/env/node_modules/@openzeppelin/contracts/governance/extensions/GovernorPreventLateQuorum.sol
generated
vendored
Executable file
92
dev/env/node_modules/@openzeppelin/contracts/governance/extensions/GovernorPreventLateQuorum.sol
generated
vendored
Executable file
@@ -0,0 +1,92 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v5.4.0) (governance/extensions/GovernorPreventLateQuorum.sol)
|
||||
|
||||
pragma solidity ^0.8.24;
|
||||
|
||||
import {Governor} from "../Governor.sol";
|
||||
import {Math} from "../../utils/math/Math.sol";
|
||||
|
||||
/**
|
||||
* @dev A module that ensures there is a minimum voting period after quorum is reached. This prevents a large voter from
|
||||
* swaying a vote and triggering quorum at the last minute, by ensuring there is always time for other voters to react
|
||||
* and try to oppose the decision.
|
||||
*
|
||||
* If a vote causes quorum to be reached, the proposal's voting period may be extended so that it does not end before at
|
||||
* least a specified time has passed (the "vote extension" parameter). This parameter can be set through a governance
|
||||
* proposal.
|
||||
*/
|
||||
abstract contract GovernorPreventLateQuorum is Governor {
|
||||
uint48 private _voteExtension;
|
||||
|
||||
mapping(uint256 proposalId => uint48) private _extendedDeadlines;
|
||||
|
||||
/// @dev Emitted when a proposal deadline is pushed back due to reaching quorum late in its voting period.
|
||||
event ProposalExtended(uint256 indexed proposalId, uint64 extendedDeadline);
|
||||
|
||||
/// @dev Emitted when the {lateQuorumVoteExtension} parameter is changed.
|
||||
event LateQuorumVoteExtensionSet(uint64 oldVoteExtension, uint64 newVoteExtension);
|
||||
|
||||
/**
|
||||
* @dev Initializes the vote extension parameter: the time in either number of blocks or seconds (depending on the
|
||||
* governor clock mode) that is required to pass since the moment a proposal reaches quorum until its voting period
|
||||
* ends. If necessary the voting period will be extended beyond the one set during proposal creation.
|
||||
*/
|
||||
constructor(uint48 initialVoteExtension) {
|
||||
_setLateQuorumVoteExtension(initialVoteExtension);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the proposal deadline, which may have been extended beyond that set at proposal creation, if the
|
||||
* proposal reached quorum late in the voting period. See {Governor-proposalDeadline}.
|
||||
*/
|
||||
function proposalDeadline(uint256 proposalId) public view virtual override returns (uint256) {
|
||||
return Math.max(super.proposalDeadline(proposalId), _extendedDeadlines[proposalId]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Vote tally updated and detects if it caused quorum to be reached, potentially extending the voting period.
|
||||
*
|
||||
* May emit a {ProposalExtended} event.
|
||||
*/
|
||||
function _tallyUpdated(uint256 proposalId) internal virtual override {
|
||||
super._tallyUpdated(proposalId);
|
||||
if (_extendedDeadlines[proposalId] == 0 && _quorumReached(proposalId)) {
|
||||
uint48 extendedDeadline = clock() + lateQuorumVoteExtension();
|
||||
|
||||
if (extendedDeadline > proposalDeadline(proposalId)) {
|
||||
emit ProposalExtended(proposalId, extendedDeadline);
|
||||
}
|
||||
|
||||
_extendedDeadlines[proposalId] = extendedDeadline;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the current value of the vote extension parameter: the number of blocks that are required to pass
|
||||
* from the time a proposal reaches quorum until its voting period ends.
|
||||
*/
|
||||
function lateQuorumVoteExtension() public view virtual returns (uint48) {
|
||||
return _voteExtension;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Changes the {lateQuorumVoteExtension}. This operation can only be performed by the governance executor,
|
||||
* generally through a governance proposal.
|
||||
*
|
||||
* Emits a {LateQuorumVoteExtensionSet} event.
|
||||
*/
|
||||
function setLateQuorumVoteExtension(uint48 newVoteExtension) public virtual onlyGovernance {
|
||||
_setLateQuorumVoteExtension(newVoteExtension);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Changes the {lateQuorumVoteExtension}. This is an internal function that can be exposed in a public function
|
||||
* like {setLateQuorumVoteExtension} if another access control mechanism is needed.
|
||||
*
|
||||
* Emits a {LateQuorumVoteExtensionSet} event.
|
||||
*/
|
||||
function _setLateQuorumVoteExtension(uint48 newVoteExtension) internal virtual {
|
||||
emit LateQuorumVoteExtensionSet(_voteExtension, newVoteExtension);
|
||||
_voteExtension = newVoteExtension;
|
||||
}
|
||||
}
|
||||
58
dev/env/node_modules/@openzeppelin/contracts/governance/extensions/GovernorProposalGuardian.sol
generated
vendored
Executable file
58
dev/env/node_modules/@openzeppelin/contracts/governance/extensions/GovernorProposalGuardian.sol
generated
vendored
Executable file
@@ -0,0 +1,58 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v5.4.0) (governance/extensions/GovernorProposalGuardian.sol)
|
||||
pragma solidity ^0.8.24;
|
||||
|
||||
import {Governor} from "../Governor.sol";
|
||||
|
||||
/**
|
||||
* @dev Extension of {Governor} which adds a proposal guardian that can cancel proposals at any stage in the proposal's lifecycle.
|
||||
*
|
||||
* NOTE: if the proposal guardian is not configured, then proposers take this role for their proposals.
|
||||
*/
|
||||
abstract contract GovernorProposalGuardian is Governor {
|
||||
address private _proposalGuardian;
|
||||
|
||||
event ProposalGuardianSet(address oldProposalGuardian, address newProposalGuardian);
|
||||
|
||||
/**
|
||||
* @dev Getter that returns the address of the proposal guardian.
|
||||
*/
|
||||
function proposalGuardian() public view virtual returns (address) {
|
||||
return _proposalGuardian;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Update the proposal guardian's address. This operation can only be performed through a governance proposal.
|
||||
*
|
||||
* Emits a {ProposalGuardianSet} event.
|
||||
*/
|
||||
function setProposalGuardian(address newProposalGuardian) public virtual onlyGovernance {
|
||||
_setProposalGuardian(newProposalGuardian);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Internal setter for the proposal guardian.
|
||||
*
|
||||
* Emits a {ProposalGuardianSet} event.
|
||||
*/
|
||||
function _setProposalGuardian(address newProposalGuardian) internal virtual {
|
||||
emit ProposalGuardianSet(_proposalGuardian, newProposalGuardian);
|
||||
_proposalGuardian = newProposalGuardian;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Override {Governor-_validateCancel} to implement the extended cancellation logic.
|
||||
*
|
||||
* * The {proposalGuardian} can cancel any proposal at any point.
|
||||
* * If no proposal guardian is set, the {IGovernor-proposalProposer} can cancel their proposals at any point.
|
||||
* * In any case, permissions defined in {Governor-_validateCancel} (or another override) remains valid.
|
||||
*/
|
||||
function _validateCancel(uint256 proposalId, address caller) internal view virtual override returns (bool) {
|
||||
address guardian = proposalGuardian();
|
||||
|
||||
return
|
||||
guardian == caller ||
|
||||
(guardian == address(0) && caller == proposalProposer(proposalId)) ||
|
||||
super._validateCancel(proposalId, caller);
|
||||
}
|
||||
}
|
||||
75
dev/env/node_modules/@openzeppelin/contracts/governance/extensions/GovernorSequentialProposalId.sol
generated
vendored
Executable file
75
dev/env/node_modules/@openzeppelin/contracts/governance/extensions/GovernorSequentialProposalId.sol
generated
vendored
Executable file
@@ -0,0 +1,75 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v5.4.0) (governance/extensions/GovernorSequentialProposalId.sol)
|
||||
|
||||
pragma solidity ^0.8.24;
|
||||
|
||||
import {IGovernor, Governor} from "../Governor.sol";
|
||||
|
||||
/**
|
||||
* @dev Extension of {Governor} that changes the numbering of proposal ids from the default hash-based approach to
|
||||
* sequential ids.
|
||||
*/
|
||||
abstract contract GovernorSequentialProposalId is Governor {
|
||||
uint256 private _latestProposalId;
|
||||
mapping(uint256 proposalHash => uint256 proposalId) private _proposalIds;
|
||||
|
||||
/**
|
||||
* @dev The {latestProposalId} may only be initialized if it hasn't been set yet
|
||||
* (through initialization or the creation of a proposal).
|
||||
*/
|
||||
error GovernorAlreadyInitializedLatestProposalId();
|
||||
|
||||
/// @inheritdoc IGovernor
|
||||
function getProposalId(
|
||||
address[] memory targets,
|
||||
uint256[] memory values,
|
||||
bytes[] memory calldatas,
|
||||
bytes32 descriptionHash
|
||||
) public view virtual override returns (uint256) {
|
||||
uint256 proposalHash = hashProposal(targets, values, calldatas, descriptionHash);
|
||||
uint256 storedProposalId = _proposalIds[proposalHash];
|
||||
if (storedProposalId == 0) {
|
||||
revert GovernorNonexistentProposal(0);
|
||||
}
|
||||
return storedProposalId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the latest proposal id. A return value of 0 means no proposals have been created yet.
|
||||
*/
|
||||
function latestProposalId() public view virtual returns (uint256) {
|
||||
return _latestProposalId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {IGovernor-_propose}.
|
||||
* Hook into the proposing mechanism to increment proposal count.
|
||||
*/
|
||||
function _propose(
|
||||
address[] memory targets,
|
||||
uint256[] memory values,
|
||||
bytes[] memory calldatas,
|
||||
string memory description,
|
||||
address proposer
|
||||
) internal virtual override returns (uint256) {
|
||||
uint256 proposalHash = hashProposal(targets, values, calldatas, keccak256(bytes(description)));
|
||||
uint256 storedProposalId = _proposalIds[proposalHash];
|
||||
if (storedProposalId == 0) {
|
||||
_proposalIds[proposalHash] = ++_latestProposalId;
|
||||
}
|
||||
return super._propose(targets, values, calldatas, description, proposer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Internal function to set the {latestProposalId}. This function is helpful when transitioning
|
||||
* from another governance system. The next proposal id will be `newLatestProposalId` + 1.
|
||||
*
|
||||
* May only call this function if the current value of {latestProposalId} is 0.
|
||||
*/
|
||||
function _initializeLatestProposalId(uint256 newLatestProposalId) internal virtual {
|
||||
if (_latestProposalId != 0) {
|
||||
revert GovernorAlreadyInitializedLatestProposalId();
|
||||
}
|
||||
_latestProposalId = newLatestProposalId;
|
||||
}
|
||||
}
|
||||
106
dev/env/node_modules/@openzeppelin/contracts/governance/extensions/GovernorSettings.sol
generated
vendored
Executable file
106
dev/env/node_modules/@openzeppelin/contracts/governance/extensions/GovernorSettings.sol
generated
vendored
Executable file
@@ -0,0 +1,106 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v5.4.0) (governance/extensions/GovernorSettings.sol)
|
||||
|
||||
pragma solidity ^0.8.24;
|
||||
|
||||
import {IGovernor, Governor} from "../Governor.sol";
|
||||
|
||||
/**
|
||||
* @dev Extension of {Governor} for settings updatable through governance.
|
||||
*/
|
||||
abstract contract GovernorSettings is Governor {
|
||||
// amount of token
|
||||
uint256 private _proposalThreshold;
|
||||
// timepoint: limited to uint48 in core (same as clock() type)
|
||||
uint48 private _votingDelay;
|
||||
// duration: limited to uint32 in core
|
||||
uint32 private _votingPeriod;
|
||||
|
||||
event VotingDelaySet(uint256 oldVotingDelay, uint256 newVotingDelay);
|
||||
event VotingPeriodSet(uint256 oldVotingPeriod, uint256 newVotingPeriod);
|
||||
event ProposalThresholdSet(uint256 oldProposalThreshold, uint256 newProposalThreshold);
|
||||
|
||||
/**
|
||||
* @dev Initialize the governance parameters.
|
||||
*/
|
||||
constructor(uint48 initialVotingDelay, uint32 initialVotingPeriod, uint256 initialProposalThreshold) {
|
||||
_setVotingDelay(initialVotingDelay);
|
||||
_setVotingPeriod(initialVotingPeriod);
|
||||
_setProposalThreshold(initialProposalThreshold);
|
||||
}
|
||||
|
||||
/// @inheritdoc IGovernor
|
||||
function votingDelay() public view virtual override returns (uint256) {
|
||||
return _votingDelay;
|
||||
}
|
||||
|
||||
/// @inheritdoc IGovernor
|
||||
function votingPeriod() public view virtual override returns (uint256) {
|
||||
return _votingPeriod;
|
||||
}
|
||||
|
||||
/// @inheritdoc Governor
|
||||
function proposalThreshold() public view virtual override returns (uint256) {
|
||||
return _proposalThreshold;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Update the voting delay. This operation can only be performed through a governance proposal.
|
||||
*
|
||||
* Emits a {VotingDelaySet} event.
|
||||
*/
|
||||
function setVotingDelay(uint48 newVotingDelay) public virtual onlyGovernance {
|
||||
_setVotingDelay(newVotingDelay);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Update the voting period. This operation can only be performed through a governance proposal.
|
||||
*
|
||||
* Emits a {VotingPeriodSet} event.
|
||||
*/
|
||||
function setVotingPeriod(uint32 newVotingPeriod) public virtual onlyGovernance {
|
||||
_setVotingPeriod(newVotingPeriod);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Update the proposal threshold. This operation can only be performed through a governance proposal.
|
||||
*
|
||||
* Emits a {ProposalThresholdSet} event.
|
||||
*/
|
||||
function setProposalThreshold(uint256 newProposalThreshold) public virtual onlyGovernance {
|
||||
_setProposalThreshold(newProposalThreshold);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Internal setter for the voting delay.
|
||||
*
|
||||
* Emits a {VotingDelaySet} event.
|
||||
*/
|
||||
function _setVotingDelay(uint48 newVotingDelay) internal virtual {
|
||||
emit VotingDelaySet(_votingDelay, newVotingDelay);
|
||||
_votingDelay = newVotingDelay;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Internal setter for the voting period.
|
||||
*
|
||||
* Emits a {VotingPeriodSet} event.
|
||||
*/
|
||||
function _setVotingPeriod(uint32 newVotingPeriod) internal virtual {
|
||||
if (newVotingPeriod == 0) {
|
||||
revert GovernorInvalidVotingPeriod(0);
|
||||
}
|
||||
emit VotingPeriodSet(_votingPeriod, newVotingPeriod);
|
||||
_votingPeriod = newVotingPeriod;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Internal setter for the proposal threshold.
|
||||
*
|
||||
* Emits a {ProposalThresholdSet} event.
|
||||
*/
|
||||
function _setProposalThreshold(uint256 newProposalThreshold) internal virtual {
|
||||
emit ProposalThresholdSet(_proposalThreshold, newProposalThreshold);
|
||||
_proposalThreshold = newProposalThreshold;
|
||||
}
|
||||
}
|
||||
125
dev/env/node_modules/@openzeppelin/contracts/governance/extensions/GovernorStorage.sol
generated
vendored
Executable file
125
dev/env/node_modules/@openzeppelin/contracts/governance/extensions/GovernorStorage.sol
generated
vendored
Executable file
@@ -0,0 +1,125 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v5.4.0) (governance/extensions/GovernorStorage.sol)
|
||||
|
||||
pragma solidity ^0.8.24;
|
||||
|
||||
import {Governor} from "../Governor.sol";
|
||||
|
||||
/**
|
||||
* @dev Extension of {Governor} that implements storage of proposal details. This modules also provides primitives for
|
||||
* the enumerability of proposals.
|
||||
*
|
||||
* Use cases for this module include:
|
||||
* - UIs that explore the proposal state without relying on event indexing.
|
||||
* - Using only the proposalId as an argument in the {Governor-queue} and {Governor-execute} functions for L2 chains
|
||||
* where storage is cheap compared to calldata.
|
||||
*/
|
||||
abstract contract GovernorStorage is Governor {
|
||||
struct ProposalDetails {
|
||||
address[] targets;
|
||||
uint256[] values;
|
||||
bytes[] calldatas;
|
||||
bytes32 descriptionHash;
|
||||
}
|
||||
|
||||
uint256[] private _proposalIds;
|
||||
mapping(uint256 proposalId => ProposalDetails) private _proposalDetails;
|
||||
|
||||
/**
|
||||
* @dev Hook into the proposing mechanism
|
||||
*/
|
||||
function _propose(
|
||||
address[] memory targets,
|
||||
uint256[] memory values,
|
||||
bytes[] memory calldatas,
|
||||
string memory description,
|
||||
address proposer
|
||||
) internal virtual override returns (uint256) {
|
||||
uint256 proposalId = super._propose(targets, values, calldatas, description, proposer);
|
||||
|
||||
// store
|
||||
_proposalIds.push(proposalId);
|
||||
_proposalDetails[proposalId] = ProposalDetails({
|
||||
targets: targets,
|
||||
values: values,
|
||||
calldatas: calldatas,
|
||||
descriptionHash: keccak256(bytes(description))
|
||||
});
|
||||
|
||||
return proposalId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Version of {IGovernor-queue} with only `proposalId` as an argument.
|
||||
*/
|
||||
function queue(uint256 proposalId) public virtual {
|
||||
// here, using storage is more efficient than memory
|
||||
ProposalDetails storage details = _proposalDetails[proposalId];
|
||||
queue(details.targets, details.values, details.calldatas, details.descriptionHash);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Version of {IGovernor-execute} with only `proposalId` as an argument.
|
||||
*/
|
||||
function execute(uint256 proposalId) public payable virtual {
|
||||
// here, using storage is more efficient than memory
|
||||
ProposalDetails storage details = _proposalDetails[proposalId];
|
||||
execute(details.targets, details.values, details.calldatas, details.descriptionHash);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev ProposalId version of {IGovernor-cancel}.
|
||||
*/
|
||||
function cancel(uint256 proposalId) public virtual {
|
||||
// here, using storage is more efficient than memory
|
||||
ProposalDetails storage details = _proposalDetails[proposalId];
|
||||
cancel(details.targets, details.values, details.calldatas, details.descriptionHash);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the number of stored proposals.
|
||||
*/
|
||||
function proposalCount() public view virtual returns (uint256) {
|
||||
return _proposalIds.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the details of a proposalId. Reverts if `proposalId` is not a known proposal.
|
||||
*/
|
||||
function proposalDetails(
|
||||
uint256 proposalId
|
||||
)
|
||||
public
|
||||
view
|
||||
virtual
|
||||
returns (address[] memory targets, uint256[] memory values, bytes[] memory calldatas, bytes32 descriptionHash)
|
||||
{
|
||||
// here, using memory is more efficient than storage
|
||||
ProposalDetails memory details = _proposalDetails[proposalId];
|
||||
if (details.descriptionHash == 0) {
|
||||
revert GovernorNonexistentProposal(proposalId);
|
||||
}
|
||||
return (details.targets, details.values, details.calldatas, details.descriptionHash);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the details (including the proposalId) of a proposal given its sequential index.
|
||||
*/
|
||||
function proposalDetailsAt(
|
||||
uint256 index
|
||||
)
|
||||
public
|
||||
view
|
||||
virtual
|
||||
returns (
|
||||
uint256 proposalId,
|
||||
address[] memory targets,
|
||||
uint256[] memory values,
|
||||
bytes[] memory calldatas,
|
||||
bytes32 descriptionHash
|
||||
)
|
||||
{
|
||||
proposalId = _proposalIds[index];
|
||||
(targets, values, calldatas, descriptionHash) = proposalDetails(proposalId);
|
||||
}
|
||||
}
|
||||
58
dev/env/node_modules/@openzeppelin/contracts/governance/extensions/GovernorSuperQuorum.sol
generated
vendored
Executable file
58
dev/env/node_modules/@openzeppelin/contracts/governance/extensions/GovernorSuperQuorum.sol
generated
vendored
Executable file
@@ -0,0 +1,58 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v5.4.0) (governance/extensions/GovernorSuperQuorum.sol)
|
||||
pragma solidity ^0.8.24;
|
||||
|
||||
import {Governor} from "../Governor.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
346
dev/env/node_modules/@openzeppelin/contracts/governance/extensions/GovernorTimelockAccess.sol
generated
vendored
Executable file
346
dev/env/node_modules/@openzeppelin/contracts/governance/extensions/GovernorTimelockAccess.sol
generated
vendored
Executable file
@@ -0,0 +1,346 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v5.4.0) (governance/extensions/GovernorTimelockAccess.sol)
|
||||
|
||||
pragma solidity ^0.8.24;
|
||||
|
||||
import {IGovernor, Governor} from "../Governor.sol";
|
||||
import {AuthorityUtils} from "../../access/manager/AuthorityUtils.sol";
|
||||
import {IAccessManager} from "../../access/manager/IAccessManager.sol";
|
||||
import {Address} from "../../utils/Address.sol";
|
||||
import {Math} from "../../utils/math/Math.sol";
|
||||
import {SafeCast} from "../../utils/math/SafeCast.sol";
|
||||
import {Time} from "../../utils/types/Time.sol";
|
||||
|
||||
/**
|
||||
* @dev This module connects a {Governor} instance to an {AccessManager} instance, allowing the governor to make calls
|
||||
* that are delay-restricted by the manager using the normal {queue} workflow. An optional base delay is applied to
|
||||
* operations that are not delayed externally by the manager. Execution of a proposal will be delayed as much as
|
||||
* necessary to meet the required delays of all of its operations.
|
||||
*
|
||||
* This extension allows the governor to hold and use its own assets and permissions, unlike {GovernorTimelockControl}
|
||||
* and {GovernorTimelockCompound}, where the timelock is a separate contract that must be the one to hold assets and
|
||||
* permissions. Operations that are delay-restricted by the manager, however, will be executed through the
|
||||
* {AccessManager-execute} function.
|
||||
*
|
||||
* ==== Security Considerations
|
||||
*
|
||||
* Some operations may be cancelable in the `AccessManager` by the admin or a set of guardians, depending on the
|
||||
* restricted function being invoked. Since proposals are atomic, the cancellation by a guardian of a single operation
|
||||
* in a proposal will cause all of the proposal to become unable to execute. Consider proposing cancellable operations
|
||||
* separately.
|
||||
*
|
||||
* By default, function calls will be routed through the associated `AccessManager` whenever it claims the target
|
||||
* function to be restricted by it. However, admins may configure the manager to make that claim for functions that a
|
||||
* governor would want to call directly (e.g., token transfers) in an attempt to deny it access to those functions. To
|
||||
* mitigate this attack vector, the governor is able to ignore the restrictions claimed by the `AccessManager` using
|
||||
* {setAccessManagerIgnored}. While permanent denial of service is mitigated, temporary DoS may still be technically
|
||||
* possible. All of the governor's own functions (e.g., {setBaseDelaySeconds}) ignore the `AccessManager` by default.
|
||||
*
|
||||
* NOTE: `AccessManager` does not support scheduling more than one operation with the same target and calldata at
|
||||
* the same time. See {AccessManager-schedule} for a workaround.
|
||||
*/
|
||||
abstract contract GovernorTimelockAccess is Governor {
|
||||
// An execution plan is produced at the moment a proposal is created, in order to fix at that point the exact
|
||||
// execution semantics of the proposal, namely whether a call will go through {AccessManager-execute}.
|
||||
struct ExecutionPlan {
|
||||
uint16 length;
|
||||
uint32 delay;
|
||||
// We use mappings instead of arrays because it allows us to pack values in storage more tightly without
|
||||
// storing the length redundantly.
|
||||
// We pack 8 operations' data in each bucket. Each uint32 value is set to 1 upon proposal creation if it has
|
||||
// to be scheduled and executed through the manager. Upon queuing, the value is set to nonce + 2, where the
|
||||
// nonce is received from the manager when scheduling the operation.
|
||||
mapping(uint256 operationBucket => uint32[8]) managerData;
|
||||
}
|
||||
|
||||
// The meaning of the "toggle" set to true depends on the target contract.
|
||||
// If target == address(this), the manager is ignored by default, and a true toggle means it won't be ignored.
|
||||
// For all other target contracts, the manager is used by default, and a true toggle means it will be ignored.
|
||||
mapping(address target => mapping(bytes4 selector => bool)) private _ignoreToggle;
|
||||
|
||||
mapping(uint256 proposalId => ExecutionPlan) private _executionPlan;
|
||||
|
||||
uint32 private _baseDelay;
|
||||
|
||||
IAccessManager private immutable _manager;
|
||||
|
||||
error GovernorUnmetDelay(uint256 proposalId, uint256 neededTimestamp);
|
||||
error GovernorMismatchedNonce(uint256 proposalId, uint256 expectedNonce, uint256 actualNonce);
|
||||
error GovernorLockedIgnore();
|
||||
|
||||
event BaseDelaySet(uint32 oldBaseDelaySeconds, uint32 newBaseDelaySeconds);
|
||||
event AccessManagerIgnoredSet(address target, bytes4 selector, bool ignored);
|
||||
|
||||
/**
|
||||
* @dev Initialize the governor with an {AccessManager} and initial base delay.
|
||||
*/
|
||||
constructor(address manager, uint32 initialBaseDelay) {
|
||||
_manager = IAccessManager(manager);
|
||||
_setBaseDelaySeconds(initialBaseDelay);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the {AccessManager} instance associated to this governor.
|
||||
*/
|
||||
function accessManager() public view virtual returns (IAccessManager) {
|
||||
return _manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Base delay that will be applied to all function calls. Some may be further delayed by their associated
|
||||
* `AccessManager` authority; in this case the final delay will be the maximum of the base delay and the one
|
||||
* demanded by the authority.
|
||||
*
|
||||
* NOTE: Execution delays are processed by the `AccessManager` contracts, and according to that contract are
|
||||
* expressed in seconds. Therefore, the base delay is also in seconds, regardless of the governor's clock mode.
|
||||
*/
|
||||
function baseDelaySeconds() public view virtual returns (uint32) {
|
||||
return _baseDelay;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Change the value of {baseDelaySeconds}. This operation can only be invoked through a governance proposal.
|
||||
*/
|
||||
function setBaseDelaySeconds(uint32 newBaseDelay) public virtual onlyGovernance {
|
||||
_setBaseDelaySeconds(newBaseDelay);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Change the value of {baseDelaySeconds}. Internal function without access control.
|
||||
*/
|
||||
function _setBaseDelaySeconds(uint32 newBaseDelay) internal virtual {
|
||||
emit BaseDelaySet(_baseDelay, newBaseDelay);
|
||||
_baseDelay = newBaseDelay;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Check if restrictions from the associated {AccessManager} are ignored for a target function. Returns true
|
||||
* when the target function will be invoked directly regardless of `AccessManager` settings for the function.
|
||||
* See {setAccessManagerIgnored} and Security Considerations above.
|
||||
*/
|
||||
function isAccessManagerIgnored(address target, bytes4 selector) public view virtual returns (bool) {
|
||||
bool isGovernor = target == address(this);
|
||||
return _ignoreToggle[target][selector] != isGovernor; // equivalent to: isGovernor ? !toggle : toggle
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Configure whether restrictions from the associated {AccessManager} are ignored for a target function.
|
||||
* See Security Considerations above.
|
||||
*/
|
||||
function setAccessManagerIgnored(
|
||||
address target,
|
||||
bytes4[] calldata selectors,
|
||||
bool ignored
|
||||
) public virtual onlyGovernance {
|
||||
for (uint256 i = 0; i < selectors.length; ++i) {
|
||||
_setAccessManagerIgnored(target, selectors[i], ignored);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Internal version of {setAccessManagerIgnored} without access restriction.
|
||||
*/
|
||||
function _setAccessManagerIgnored(address target, bytes4 selector, bool ignored) internal virtual {
|
||||
bool isGovernor = target == address(this);
|
||||
if (isGovernor && selector == this.setAccessManagerIgnored.selector) {
|
||||
revert GovernorLockedIgnore();
|
||||
}
|
||||
_ignoreToggle[target][selector] = ignored != isGovernor; // equivalent to: isGovernor ? !ignored : ignored
|
||||
emit AccessManagerIgnoredSet(target, selector, ignored);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Public accessor to check the execution plan, including the number of seconds that the proposal will be
|
||||
* delayed since queuing, an array indicating which of the proposal actions will be executed indirectly through
|
||||
* the associated {AccessManager}, and another indicating which will be scheduled in {queue}. Note that
|
||||
* those that must be scheduled are cancellable by `AccessManager` guardians.
|
||||
*/
|
||||
function proposalExecutionPlan(
|
||||
uint256 proposalId
|
||||
) public view returns (uint32 delay, bool[] memory indirect, bool[] memory withDelay) {
|
||||
ExecutionPlan storage plan = _executionPlan[proposalId];
|
||||
|
||||
uint32 length = plan.length;
|
||||
delay = plan.delay;
|
||||
indirect = new bool[](length);
|
||||
withDelay = new bool[](length);
|
||||
for (uint256 i = 0; i < length; ++i) {
|
||||
(indirect[i], withDelay[i], ) = _getManagerData(plan, i);
|
||||
}
|
||||
|
||||
return (delay, indirect, withDelay);
|
||||
}
|
||||
|
||||
/// @inheritdoc IGovernor
|
||||
function proposalNeedsQueuing(uint256 proposalId) public view virtual override returns (bool) {
|
||||
return _executionPlan[proposalId].delay > 0;
|
||||
}
|
||||
|
||||
/// @inheritdoc IGovernor
|
||||
function propose(
|
||||
address[] memory targets,
|
||||
uint256[] memory values,
|
||||
bytes[] memory calldatas,
|
||||
string memory description
|
||||
) public virtual override returns (uint256) {
|
||||
uint256 proposalId = super.propose(targets, values, calldatas, description);
|
||||
|
||||
uint32 neededDelay = baseDelaySeconds();
|
||||
|
||||
ExecutionPlan storage plan = _executionPlan[proposalId];
|
||||
plan.length = SafeCast.toUint16(targets.length);
|
||||
|
||||
for (uint256 i = 0; i < targets.length; ++i) {
|
||||
if (calldatas[i].length < 4) {
|
||||
continue;
|
||||
}
|
||||
address target = targets[i];
|
||||
bytes4 selector = bytes4(calldatas[i]);
|
||||
(bool immediate, uint32 delay) = AuthorityUtils.canCallWithDelay(
|
||||
address(_manager),
|
||||
address(this),
|
||||
target,
|
||||
selector
|
||||
);
|
||||
if ((immediate || delay > 0) && !isAccessManagerIgnored(target, selector)) {
|
||||
_setManagerData(plan, i, !immediate, 0);
|
||||
// downcast is safe because both arguments are uint32
|
||||
neededDelay = uint32(Math.max(delay, neededDelay));
|
||||
}
|
||||
}
|
||||
|
||||
plan.delay = neededDelay;
|
||||
|
||||
return proposalId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Mechanism to queue a proposal, potentially scheduling some of its operations in the AccessManager.
|
||||
*
|
||||
* NOTE: The execution delay is chosen based on the delay information retrieved in {propose}. This value may be
|
||||
* off if the delay was updated since proposal creation. In this case, the proposal needs to be recreated.
|
||||
*/
|
||||
function _queueOperations(
|
||||
uint256 proposalId,
|
||||
address[] memory targets,
|
||||
uint256[] memory /* values */,
|
||||
bytes[] memory calldatas,
|
||||
bytes32 /* descriptionHash */
|
||||
) internal virtual override returns (uint48) {
|
||||
ExecutionPlan storage plan = _executionPlan[proposalId];
|
||||
uint48 etaSeconds = Time.timestamp() + plan.delay;
|
||||
|
||||
for (uint256 i = 0; i < targets.length; ++i) {
|
||||
(, bool withDelay, ) = _getManagerData(plan, i);
|
||||
if (withDelay) {
|
||||
// This function can reenter when calling `_manager.schedule` before performing state updates in `_setManagerData`.
|
||||
// However, the `manager` is a trusted contract in the current context's security model (e.g. an `AccessManager`).
|
||||
// slither-disable-next-line reentrancy-no-eth
|
||||
(, uint32 nonce) = _manager.schedule(targets[i], calldatas[i], etaSeconds);
|
||||
_setManagerData(plan, i, true, nonce);
|
||||
}
|
||||
}
|
||||
|
||||
return etaSeconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Mechanism to execute a proposal, potentially going through {AccessManager-execute} for delayed operations.
|
||||
*/
|
||||
function _executeOperations(
|
||||
uint256 proposalId,
|
||||
address[] memory targets,
|
||||
uint256[] memory values,
|
||||
bytes[] memory calldatas,
|
||||
bytes32 /* descriptionHash */
|
||||
) internal virtual override {
|
||||
uint48 etaSeconds = SafeCast.toUint48(proposalEta(proposalId));
|
||||
if (block.timestamp < etaSeconds) {
|
||||
revert GovernorUnmetDelay(proposalId, etaSeconds);
|
||||
}
|
||||
|
||||
ExecutionPlan storage plan = _executionPlan[proposalId];
|
||||
|
||||
for (uint256 i = 0; i < targets.length; ++i) {
|
||||
(bool controlled, bool withDelay, uint32 nonce) = _getManagerData(plan, i);
|
||||
if (controlled) {
|
||||
uint32 executedNonce = _manager.execute{value: values[i]}(targets[i], calldatas[i]);
|
||||
if (withDelay && executedNonce != nonce) {
|
||||
revert GovernorMismatchedNonce(proposalId, nonce, executedNonce);
|
||||
}
|
||||
} else {
|
||||
(bool success, bytes memory returndata) = targets[i].call{value: values[i]}(calldatas[i]);
|
||||
Address.verifyCallResult(success, returndata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// @inheritdoc Governor
|
||||
function _cancel(
|
||||
address[] memory targets,
|
||||
uint256[] memory values,
|
||||
bytes[] memory calldatas,
|
||||
bytes32 descriptionHash
|
||||
) internal virtual override returns (uint256) {
|
||||
uint256 proposalId = super._cancel(targets, values, calldatas, descriptionHash);
|
||||
|
||||
uint48 etaSeconds = SafeCast.toUint48(proposalEta(proposalId));
|
||||
|
||||
ExecutionPlan storage plan = _executionPlan[proposalId];
|
||||
|
||||
// If the proposal has been scheduled it will have an ETA and we may have to externally cancel
|
||||
if (etaSeconds != 0) {
|
||||
for (uint256 i = 0; i < targets.length; ++i) {
|
||||
(, bool withDelay, uint32 nonce) = _getManagerData(plan, i);
|
||||
// Only attempt to cancel if the execution plan included a delay
|
||||
if (withDelay) {
|
||||
bytes32 operationId = _manager.hashOperation(address(this), targets[i], calldatas[i]);
|
||||
// Check first if the current operation nonce is the one that we observed previously. It could
|
||||
// already have been cancelled and rescheduled. We don't want to cancel unless it is exactly the
|
||||
// instance that we previously scheduled.
|
||||
if (nonce == _manager.getNonce(operationId)) {
|
||||
// It is important that all calls have an opportunity to be cancelled. We chose to ignore
|
||||
// potential failures of some of the cancel operations to give the other operations a chance to
|
||||
// be properly cancelled. In particular cancel might fail if the operation was already cancelled
|
||||
// by guardians previously. We don't match on the revert reason to avoid encoding assumptions
|
||||
// about specific errors.
|
||||
try _manager.cancel(address(this), targets[i], calldatas[i]) {} catch {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return proposalId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns whether the operation at an index is delayed by the manager, and its scheduling nonce once queued.
|
||||
*/
|
||||
function _getManagerData(
|
||||
ExecutionPlan storage plan,
|
||||
uint256 index
|
||||
) private view returns (bool controlled, bool withDelay, uint32 nonce) {
|
||||
(uint256 bucket, uint256 subindex) = _getManagerDataIndices(index);
|
||||
uint32 value = plan.managerData[bucket][subindex];
|
||||
unchecked {
|
||||
return (value > 0, value > 1, value > 1 ? value - 2 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Marks an operation at an index as permissioned by the manager, potentially delayed, and
|
||||
* when delayed sets its scheduling nonce.
|
||||
*/
|
||||
function _setManagerData(ExecutionPlan storage plan, uint256 index, bool withDelay, uint32 nonce) private {
|
||||
(uint256 bucket, uint256 subindex) = _getManagerDataIndices(index);
|
||||
plan.managerData[bucket][subindex] = withDelay ? nonce + 2 : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns bucket and subindex for reading manager data from the packed array mapping.
|
||||
*/
|
||||
function _getManagerDataIndices(uint256 index) private pure returns (uint256 bucket, uint256 subindex) {
|
||||
bucket = index >> 3; // index / 8
|
||||
subindex = index & 7; // index % 8
|
||||
}
|
||||
}
|
||||
165
dev/env/node_modules/@openzeppelin/contracts/governance/extensions/GovernorTimelockCompound.sol
generated
vendored
Executable file
165
dev/env/node_modules/@openzeppelin/contracts/governance/extensions/GovernorTimelockCompound.sol
generated
vendored
Executable file
@@ -0,0 +1,165 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v5.4.0) (governance/extensions/GovernorTimelockCompound.sol)
|
||||
|
||||
pragma solidity ^0.8.24;
|
||||
|
||||
import {IGovernor, Governor} from "../Governor.sol";
|
||||
import {ICompoundTimelock} from "../../vendor/compound/ICompoundTimelock.sol";
|
||||
import {Address} from "../../utils/Address.sol";
|
||||
import {SafeCast} from "../../utils/math/SafeCast.sol";
|
||||
|
||||
/**
|
||||
* @dev Extension of {Governor} that binds the execution process to a Compound Timelock. This adds a delay, enforced by
|
||||
* the external timelock to all successful proposals (in addition to the voting duration). The {Governor} needs to be
|
||||
* the admin of the timelock for any operation to be performed. A public, unrestricted,
|
||||
* {GovernorTimelockCompound-__acceptAdmin} is available to accept ownership of the timelock.
|
||||
*
|
||||
* Using this model means the proposal will be operated by the {TimelockController} and not by the {Governor}. Thus,
|
||||
* the assets and permissions must be attached to the {TimelockController}. Any asset sent to the {Governor} will be
|
||||
* inaccessible from a proposal, unless executed via {Governor-relay}.
|
||||
*/
|
||||
abstract contract GovernorTimelockCompound is Governor {
|
||||
ICompoundTimelock private _timelock;
|
||||
|
||||
/**
|
||||
* @dev Emitted when the timelock controller used for proposal execution is modified.
|
||||
*/
|
||||
event TimelockChange(address oldTimelock, address newTimelock);
|
||||
|
||||
/**
|
||||
* @dev Set the timelock.
|
||||
*/
|
||||
constructor(ICompoundTimelock timelockAddress) {
|
||||
_updateTimelock(timelockAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Overridden version of the {Governor-state} function with added support for the `Expired` state.
|
||||
*/
|
||||
function state(uint256 proposalId) public view virtual override returns (ProposalState) {
|
||||
ProposalState currentState = super.state(proposalId);
|
||||
|
||||
return
|
||||
(currentState == ProposalState.Queued &&
|
||||
block.timestamp >= proposalEta(proposalId) + _timelock.GRACE_PERIOD())
|
||||
? ProposalState.Expired
|
||||
: currentState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Public accessor to check the address of the timelock
|
||||
*/
|
||||
function timelock() public view virtual returns (address) {
|
||||
return address(_timelock);
|
||||
}
|
||||
|
||||
/// @inheritdoc IGovernor
|
||||
function proposalNeedsQueuing(uint256) public view virtual override returns (bool) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Function to queue a proposal to the timelock.
|
||||
*/
|
||||
function _queueOperations(
|
||||
uint256 proposalId,
|
||||
address[] memory targets,
|
||||
uint256[] memory values,
|
||||
bytes[] memory calldatas,
|
||||
bytes32 /*descriptionHash*/
|
||||
) internal virtual override returns (uint48) {
|
||||
uint48 etaSeconds = SafeCast.toUint48(block.timestamp + _timelock.delay());
|
||||
|
||||
for (uint256 i = 0; i < targets.length; ++i) {
|
||||
if (
|
||||
_timelock.queuedTransactions(keccak256(abi.encode(targets[i], values[i], "", calldatas[i], etaSeconds)))
|
||||
) {
|
||||
revert GovernorAlreadyQueuedProposal(proposalId);
|
||||
}
|
||||
_timelock.queueTransaction(targets[i], values[i], "", calldatas[i], etaSeconds);
|
||||
}
|
||||
|
||||
return etaSeconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Overridden version of the {Governor-_executeOperations} function that run the already queued proposal
|
||||
* through the timelock.
|
||||
*/
|
||||
function _executeOperations(
|
||||
uint256 proposalId,
|
||||
address[] memory targets,
|
||||
uint256[] memory values,
|
||||
bytes[] memory calldatas,
|
||||
bytes32 /*descriptionHash*/
|
||||
) internal virtual override {
|
||||
uint256 etaSeconds = proposalEta(proposalId);
|
||||
if (etaSeconds == 0) {
|
||||
revert GovernorNotQueuedProposal(proposalId);
|
||||
}
|
||||
Address.sendValue(payable(_timelock), msg.value);
|
||||
for (uint256 i = 0; i < targets.length; ++i) {
|
||||
_timelock.executeTransaction(targets[i], values[i], "", calldatas[i], etaSeconds);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Overridden version of the {Governor-_cancel} function to cancel the timelocked proposal if it has already
|
||||
* been queued.
|
||||
*/
|
||||
function _cancel(
|
||||
address[] memory targets,
|
||||
uint256[] memory values,
|
||||
bytes[] memory calldatas,
|
||||
bytes32 descriptionHash
|
||||
) internal virtual override returns (uint256) {
|
||||
uint256 proposalId = super._cancel(targets, values, calldatas, descriptionHash);
|
||||
|
||||
uint256 etaSeconds = proposalEta(proposalId);
|
||||
if (etaSeconds > 0) {
|
||||
// do external call later
|
||||
for (uint256 i = 0; i < targets.length; ++i) {
|
||||
_timelock.cancelTransaction(targets[i], values[i], "", calldatas[i], etaSeconds);
|
||||
}
|
||||
}
|
||||
|
||||
return proposalId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Address through which the governor executes action. In this case, the timelock.
|
||||
*/
|
||||
function _executor() internal view virtual override returns (address) {
|
||||
return address(_timelock);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Accept admin right over the timelock.
|
||||
*/
|
||||
// solhint-disable-next-line private-vars-leading-underscore
|
||||
function __acceptAdmin() public {
|
||||
_timelock.acceptAdmin();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Public endpoint to update the underlying timelock instance. Restricted to the timelock itself, so updates
|
||||
* must be proposed, scheduled, and executed through governance proposals.
|
||||
*
|
||||
* For security reasons, the timelock must be handed over to another admin before setting up a new one. The two
|
||||
* operations (hand over the timelock) and do the update can be batched in a single proposal.
|
||||
*
|
||||
* Note that if the timelock admin has been handed over in a previous operation, we refuse updates made through the
|
||||
* timelock if admin of the timelock has already been accepted and the operation is executed outside the scope of
|
||||
* governance.
|
||||
|
||||
* CAUTION: It is not recommended to change the timelock while there are other queued governance proposals.
|
||||
*/
|
||||
function updateTimelock(ICompoundTimelock newTimelock) external virtual onlyGovernance {
|
||||
_updateTimelock(newTimelock);
|
||||
}
|
||||
|
||||
function _updateTimelock(ICompoundTimelock newTimelock) private {
|
||||
emit TimelockChange(address(_timelock), address(newTimelock));
|
||||
_timelock = newTimelock;
|
||||
}
|
||||
}
|
||||
167
dev/env/node_modules/@openzeppelin/contracts/governance/extensions/GovernorTimelockControl.sol
generated
vendored
Executable file
167
dev/env/node_modules/@openzeppelin/contracts/governance/extensions/GovernorTimelockControl.sol
generated
vendored
Executable file
@@ -0,0 +1,167 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v5.4.0) (governance/extensions/GovernorTimelockControl.sol)
|
||||
|
||||
pragma solidity ^0.8.24;
|
||||
|
||||
import {IGovernor, Governor} from "../Governor.sol";
|
||||
import {TimelockController} from "../TimelockController.sol";
|
||||
import {SafeCast} from "../../utils/math/SafeCast.sol";
|
||||
|
||||
/**
|
||||
* @dev Extension of {Governor} that binds the execution process to an instance of {TimelockController}. This adds a
|
||||
* delay, enforced by the {TimelockController} to all successful proposal (in addition to the voting duration). The
|
||||
* {Governor} needs the proposer (and ideally the executor and canceller) roles for the {Governor} to work properly.
|
||||
*
|
||||
* Using this model means the proposal will be operated by the {TimelockController} and not by the {Governor}. Thus,
|
||||
* the assets and permissions must be attached to the {TimelockController}. Any asset sent to the {Governor} will be
|
||||
* inaccessible from a proposal, unless executed via {Governor-relay}.
|
||||
*
|
||||
* WARNING: Setting up the TimelockController to have additional proposers or cancelers besides the governor is very
|
||||
* risky, as it grants them the ability to: 1) execute operations as the timelock, and thus possibly performing
|
||||
* operations or accessing funds that are expected to only be accessible through a vote, and 2) block governance
|
||||
* proposals that have been approved by the voters, effectively executing a Denial of Service attack.
|
||||
*/
|
||||
abstract contract GovernorTimelockControl is Governor {
|
||||
TimelockController private _timelock;
|
||||
mapping(uint256 proposalId => bytes32) private _timelockIds;
|
||||
|
||||
/**
|
||||
* @dev Emitted when the timelock controller used for proposal execution is modified.
|
||||
*/
|
||||
event TimelockChange(address oldTimelock, address newTimelock);
|
||||
|
||||
/**
|
||||
* @dev Set the timelock.
|
||||
*/
|
||||
constructor(TimelockController timelockAddress) {
|
||||
_updateTimelock(timelockAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Overridden version of the {Governor-state} function that considers the status reported by the timelock.
|
||||
*/
|
||||
function state(uint256 proposalId) public view virtual override returns (ProposalState) {
|
||||
ProposalState currentState = super.state(proposalId);
|
||||
|
||||
if (currentState != ProposalState.Queued) {
|
||||
return currentState;
|
||||
}
|
||||
|
||||
bytes32 queueid = _timelockIds[proposalId];
|
||||
if (_timelock.isOperationPending(queueid)) {
|
||||
return ProposalState.Queued;
|
||||
} else if (_timelock.isOperationDone(queueid)) {
|
||||
// This can happen if the proposal is executed directly on the timelock.
|
||||
return ProposalState.Executed;
|
||||
} else {
|
||||
// This can happen if the proposal is canceled directly on the timelock.
|
||||
return ProposalState.Canceled;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Public accessor to check the address of the timelock
|
||||
*/
|
||||
function timelock() public view virtual returns (address) {
|
||||
return address(_timelock);
|
||||
}
|
||||
|
||||
/// @inheritdoc IGovernor
|
||||
function proposalNeedsQueuing(uint256) public view virtual override returns (bool) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Function to queue a proposal to the timelock.
|
||||
*/
|
||||
function _queueOperations(
|
||||
uint256 proposalId,
|
||||
address[] memory targets,
|
||||
uint256[] memory values,
|
||||
bytes[] memory calldatas,
|
||||
bytes32 descriptionHash
|
||||
) internal virtual override returns (uint48) {
|
||||
uint256 delay = _timelock.getMinDelay();
|
||||
|
||||
bytes32 salt = _timelockSalt(descriptionHash);
|
||||
_timelockIds[proposalId] = _timelock.hashOperationBatch(targets, values, calldatas, 0, salt);
|
||||
_timelock.scheduleBatch(targets, values, calldatas, 0, salt, delay);
|
||||
|
||||
return SafeCast.toUint48(block.timestamp + delay);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Overridden version of the {Governor-_executeOperations} function that runs the already queued proposal
|
||||
* through the timelock.
|
||||
*/
|
||||
function _executeOperations(
|
||||
uint256 proposalId,
|
||||
address[] memory targets,
|
||||
uint256[] memory values,
|
||||
bytes[] memory calldatas,
|
||||
bytes32 descriptionHash
|
||||
) internal virtual override {
|
||||
// execute
|
||||
_timelock.executeBatch{value: msg.value}(targets, values, calldatas, 0, _timelockSalt(descriptionHash));
|
||||
// cleanup for refund
|
||||
delete _timelockIds[proposalId];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Overridden version of the {Governor-_cancel} function to cancel the timelocked proposal if it has already
|
||||
* been queued.
|
||||
*/
|
||||
// This function can reenter through the external call to the timelock, but we assume the timelock is trusted and
|
||||
// well behaved (according to TimelockController) and this will not happen.
|
||||
// slither-disable-next-line reentrancy-no-eth
|
||||
function _cancel(
|
||||
address[] memory targets,
|
||||
uint256[] memory values,
|
||||
bytes[] memory calldatas,
|
||||
bytes32 descriptionHash
|
||||
) internal virtual override returns (uint256) {
|
||||
uint256 proposalId = super._cancel(targets, values, calldatas, descriptionHash);
|
||||
|
||||
bytes32 timelockId = _timelockIds[proposalId];
|
||||
if (timelockId != 0) {
|
||||
// cancel
|
||||
_timelock.cancel(timelockId);
|
||||
// cleanup
|
||||
delete _timelockIds[proposalId];
|
||||
}
|
||||
|
||||
return proposalId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Address through which the governor executes action. In this case, the timelock.
|
||||
*/
|
||||
function _executor() internal view virtual override returns (address) {
|
||||
return address(_timelock);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Public endpoint to update the underlying timelock instance. Restricted to the timelock itself, so updates
|
||||
* must be proposed, scheduled, and executed through governance proposals.
|
||||
*
|
||||
* CAUTION: It is not recommended to change the timelock while there are other queued governance proposals.
|
||||
*/
|
||||
function updateTimelock(TimelockController newTimelock) external virtual onlyGovernance {
|
||||
_updateTimelock(newTimelock);
|
||||
}
|
||||
|
||||
function _updateTimelock(TimelockController newTimelock) private {
|
||||
emit TimelockChange(address(_timelock), address(newTimelock));
|
||||
_timelock = newTimelock;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Computes the {TimelockController} operation salt.
|
||||
*
|
||||
* It is computed with the governor address itself to avoid collisions across governor instances using the
|
||||
* same timelock.
|
||||
*/
|
||||
function _timelockSalt(bytes32 descriptionHash) private view returns (bytes32) {
|
||||
return bytes20(address(this)) ^ descriptionHash;
|
||||
}
|
||||
}
|
||||
63
dev/env/node_modules/@openzeppelin/contracts/governance/extensions/GovernorVotes.sol
generated
vendored
Executable file
63
dev/env/node_modules/@openzeppelin/contracts/governance/extensions/GovernorVotes.sol
generated
vendored
Executable file
@@ -0,0 +1,63 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v5.4.0) (governance/extensions/GovernorVotes.sol)
|
||||
|
||||
pragma solidity ^0.8.24;
|
||||
|
||||
import {Governor} from "../Governor.sol";
|
||||
import {IVotes} from "../utils/IVotes.sol";
|
||||
import {IERC5805} from "../../interfaces/IERC5805.sol";
|
||||
import {Time} from "../../utils/types/Time.sol";
|
||||
|
||||
/**
|
||||
* @dev Extension of {Governor} for voting weight extraction from an {ERC20Votes} token, or since v4.5 an {ERC721Votes}
|
||||
* token.
|
||||
*/
|
||||
abstract contract GovernorVotes is Governor {
|
||||
IERC5805 private immutable _token;
|
||||
|
||||
constructor(IVotes tokenAddress) {
|
||||
_token = IERC5805(address(tokenAddress));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev The token that voting power is sourced from.
|
||||
*/
|
||||
function token() public view virtual returns (IERC5805) {
|
||||
return _token;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Clock (as specified in ERC-6372) is set to match the token's clock. Fallback to block numbers if the token
|
||||
* does not implement ERC-6372.
|
||||
*/
|
||||
function clock() public view virtual override returns (uint48) {
|
||||
try token().clock() returns (uint48 timepoint) {
|
||||
return timepoint;
|
||||
} catch {
|
||||
return Time.blockNumber();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Machine-readable description of the clock as specified in ERC-6372.
|
||||
*/
|
||||
// solhint-disable-next-line func-name-mixedcase
|
||||
function CLOCK_MODE() public view virtual override returns (string memory) {
|
||||
try token().CLOCK_MODE() returns (string memory clockmode) {
|
||||
return clockmode;
|
||||
} catch {
|
||||
return "mode=blocknumber&from=default";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the voting weight from the token's built in snapshot mechanism (see {Governor-_getVotes}).
|
||||
*/
|
||||
function _getVotes(
|
||||
address account,
|
||||
uint256 timepoint,
|
||||
bytes memory /*params*/
|
||||
) internal view virtual override returns (uint256) {
|
||||
return token().getPastVotes(account, timepoint);
|
||||
}
|
||||
}
|
||||
113
dev/env/node_modules/@openzeppelin/contracts/governance/extensions/GovernorVotesQuorumFraction.sol
generated
vendored
Executable file
113
dev/env/node_modules/@openzeppelin/contracts/governance/extensions/GovernorVotesQuorumFraction.sol
generated
vendored
Executable file
@@ -0,0 +1,113 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v5.4.0) (governance/extensions/GovernorVotesQuorumFraction.sol)
|
||||
|
||||
pragma solidity ^0.8.24;
|
||||
|
||||
import {GovernorVotes} from "./GovernorVotes.sol";
|
||||
import {Math} from "../../utils/math/Math.sol";
|
||||
import {SafeCast} from "../../utils/math/SafeCast.sol";
|
||||
import {Checkpoints} from "../../utils/structs/Checkpoints.sol";
|
||||
|
||||
/**
|
||||
* @dev Extension of {Governor} for voting weight extraction from an {ERC20Votes} token and a quorum expressed as a
|
||||
* fraction of the total supply.
|
||||
*/
|
||||
abstract contract GovernorVotesQuorumFraction is GovernorVotes {
|
||||
using Checkpoints for Checkpoints.Trace208;
|
||||
|
||||
Checkpoints.Trace208 private _quorumNumeratorHistory;
|
||||
|
||||
event QuorumNumeratorUpdated(uint256 oldQuorumNumerator, uint256 newQuorumNumerator);
|
||||
|
||||
/**
|
||||
* @dev The quorum set is not a valid fraction.
|
||||
*/
|
||||
error GovernorInvalidQuorumFraction(uint256 quorumNumerator, uint256 quorumDenominator);
|
||||
|
||||
/**
|
||||
* @dev Initialize quorum as a fraction of the token's total supply.
|
||||
*
|
||||
* The fraction is specified as `numerator / denominator`. By default the denominator is 100, so quorum is
|
||||
* specified as a percent: a numerator of 10 corresponds to quorum being 10% of total supply. The denominator can be
|
||||
* customized by overriding {quorumDenominator}.
|
||||
*/
|
||||
constructor(uint256 quorumNumeratorValue) {
|
||||
_updateQuorumNumerator(quorumNumeratorValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the current quorum numerator. See {quorumDenominator}.
|
||||
*/
|
||||
function quorumNumerator() public view virtual returns (uint256) {
|
||||
return _quorumNumeratorHistory.latest();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the quorum numerator at a specific timepoint. See {quorumDenominator}.
|
||||
*/
|
||||
function quorumNumerator(uint256 timepoint) public view virtual returns (uint256) {
|
||||
return _optimisticUpperLookupRecent(_quorumNumeratorHistory, timepoint);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the quorum denominator. Defaults to 100, but may be overridden.
|
||||
*/
|
||||
function quorumDenominator() public view virtual returns (uint256) {
|
||||
return 100;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the quorum for a timepoint, in terms of number of votes: `supply * numerator / denominator`.
|
||||
*/
|
||||
function quorum(uint256 timepoint) public view virtual override returns (uint256) {
|
||||
return Math.mulDiv(token().getPastTotalSupply(timepoint), quorumNumerator(timepoint), quorumDenominator());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Changes the quorum numerator.
|
||||
*
|
||||
* Emits a {QuorumNumeratorUpdated} event.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - Must be called through a governance proposal.
|
||||
* - New numerator must be smaller or equal to the denominator.
|
||||
*/
|
||||
function updateQuorumNumerator(uint256 newQuorumNumerator) external virtual onlyGovernance {
|
||||
_updateQuorumNumerator(newQuorumNumerator);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Changes the quorum numerator.
|
||||
*
|
||||
* Emits a {QuorumNumeratorUpdated} event.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - New numerator must be smaller or equal to the denominator.
|
||||
*/
|
||||
function _updateQuorumNumerator(uint256 newQuorumNumerator) internal virtual {
|
||||
uint256 denominator = quorumDenominator();
|
||||
if (newQuorumNumerator > denominator) {
|
||||
revert GovernorInvalidQuorumFraction(newQuorumNumerator, denominator);
|
||||
}
|
||||
|
||||
uint256 oldQuorumNumerator = quorumNumerator();
|
||||
_quorumNumeratorHistory.push(clock(), SafeCast.toUint208(newQuorumNumerator));
|
||||
|
||||
emit QuorumNumeratorUpdated(oldQuorumNumerator, newQuorumNumerator);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the numerator at a specific timepoint.
|
||||
*/
|
||||
function _optimisticUpperLookupRecent(
|
||||
Checkpoints.Trace208 storage ckpts,
|
||||
uint256 timepoint
|
||||
) internal view returns (uint256) {
|
||||
// If trace is empty, key and value are both equal to 0.
|
||||
// In that case `key <= timepoint` is true, and it is ok to return 0.
|
||||
(, uint48 key, uint208 value) = ckpts.latestCheckpoint();
|
||||
return key <= timepoint ? value : ckpts.upperLookupRecent(SafeCast.toUint48(timepoint));
|
||||
}
|
||||
}
|
||||
134
dev/env/node_modules/@openzeppelin/contracts/governance/extensions/GovernorVotesSuperQuorumFraction.sol
generated
vendored
Executable file
134
dev/env/node_modules/@openzeppelin/contracts/governance/extensions/GovernorVotesSuperQuorumFraction.sol
generated
vendored
Executable file
@@ -0,0 +1,134 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v5.4.0) (governance/extensions/GovernorVotesSuperQuorumFraction.sol)
|
||||
pragma solidity ^0.8.24;
|
||||
|
||||
import {Governor} from "../Governor.sol";
|
||||
import {GovernorSuperQuorum} from "./GovernorSuperQuorum.sol";
|
||||
import {GovernorVotesQuorumFraction} from "./GovernorVotesQuorumFraction.sol";
|
||||
import {Math} from "../../utils/math/Math.sol";
|
||||
import {SafeCast} from "../../utils/math/SafeCast.sol";
|
||||
import {Checkpoints} from "../../utils/structs/Checkpoints.sol";
|
||||
|
||||
/**
|
||||
* @dev Extension of {GovernorVotesQuorumFraction} with a super quorum expressed as a
|
||||
* fraction of the total supply. Proposals that meet the super quorum (and have a majority of for votes) advance to
|
||||
* the `Succeeded` state before the proposal deadline.
|
||||
*/
|
||||
abstract contract GovernorVotesSuperQuorumFraction is GovernorVotesQuorumFraction, GovernorSuperQuorum {
|
||||
using Checkpoints for Checkpoints.Trace208;
|
||||
|
||||
Checkpoints.Trace208 private _superQuorumNumeratorHistory;
|
||||
|
||||
event SuperQuorumNumeratorUpdated(uint256 oldSuperQuorumNumerator, uint256 newSuperQuorumNumerator);
|
||||
|
||||
/**
|
||||
* @dev The super quorum set is not valid as it exceeds the quorum denominator.
|
||||
*/
|
||||
error GovernorInvalidSuperQuorumFraction(uint256 superQuorumNumerator, uint256 denominator);
|
||||
|
||||
/**
|
||||
* @dev The super quorum set is not valid as it is smaller or equal to the quorum.
|
||||
*/
|
||||
error GovernorInvalidSuperQuorumTooSmall(uint256 superQuorumNumerator, uint256 quorumNumerator);
|
||||
|
||||
/**
|
||||
* @dev The quorum set is not valid as it exceeds the super quorum.
|
||||
*/
|
||||
error GovernorInvalidQuorumTooLarge(uint256 quorumNumerator, uint256 superQuorumNumerator);
|
||||
|
||||
/**
|
||||
* @dev Initialize super quorum as a fraction of the token's total supply.
|
||||
*
|
||||
* The super quorum is specified as a fraction of the token's total supply and has to
|
||||
* be greater than the quorum.
|
||||
*/
|
||||
constructor(uint256 superQuorumNumeratorValue) {
|
||||
_updateSuperQuorumNumerator(superQuorumNumeratorValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the current super quorum numerator.
|
||||
*/
|
||||
function superQuorumNumerator() public view virtual returns (uint256) {
|
||||
return _superQuorumNumeratorHistory.latest();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the super quorum numerator at a specific `timepoint`.
|
||||
*/
|
||||
function superQuorumNumerator(uint256 timepoint) public view virtual returns (uint256) {
|
||||
return _optimisticUpperLookupRecent(_superQuorumNumeratorHistory, timepoint);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the super quorum for a `timepoint`, in terms of number of votes: `supply * numerator / denominator`.
|
||||
* See {GovernorSuperQuorum-superQuorum} for more details.
|
||||
*/
|
||||
function superQuorum(uint256 timepoint) public view virtual override returns (uint256) {
|
||||
return Math.mulDiv(token().getPastTotalSupply(timepoint), superQuorumNumerator(timepoint), quorumDenominator());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Changes the super quorum numerator.
|
||||
*
|
||||
* Emits a {SuperQuorumNumeratorUpdated} event.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - Must be called through a governance proposal.
|
||||
* - New super quorum numerator must be smaller or equal to the denominator.
|
||||
* - New super quorum numerator must be greater than or equal to the quorum numerator.
|
||||
*/
|
||||
function updateSuperQuorumNumerator(uint256 newSuperQuorumNumerator) public virtual onlyGovernance {
|
||||
_updateSuperQuorumNumerator(newSuperQuorumNumerator);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Changes the super quorum numerator.
|
||||
*
|
||||
* Emits a {SuperQuorumNumeratorUpdated} event.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - New super quorum numerator must be smaller or equal to the denominator.
|
||||
* - New super quorum numerator must be greater than or equal to the quorum numerator.
|
||||
*/
|
||||
function _updateSuperQuorumNumerator(uint256 newSuperQuorumNumerator) internal virtual {
|
||||
uint256 denominator = quorumDenominator();
|
||||
if (newSuperQuorumNumerator > denominator) {
|
||||
revert GovernorInvalidSuperQuorumFraction(newSuperQuorumNumerator, denominator);
|
||||
}
|
||||
|
||||
uint256 quorumNumerator = quorumNumerator();
|
||||
if (newSuperQuorumNumerator < quorumNumerator) {
|
||||
revert GovernorInvalidSuperQuorumTooSmall(newSuperQuorumNumerator, quorumNumerator);
|
||||
}
|
||||
|
||||
uint256 oldSuperQuorumNumerator = _superQuorumNumeratorHistory.latest();
|
||||
_superQuorumNumeratorHistory.push(clock(), SafeCast.toUint208(newSuperQuorumNumerator));
|
||||
|
||||
emit SuperQuorumNumeratorUpdated(oldSuperQuorumNumerator, newSuperQuorumNumerator);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Overrides {GovernorVotesQuorumFraction-_updateQuorumNumerator} to ensure the super
|
||||
* quorum numerator is greater than or equal to the quorum numerator.
|
||||
*/
|
||||
function _updateQuorumNumerator(uint256 newQuorumNumerator) internal virtual override {
|
||||
// Ignoring check when the superQuorum was never set (construction sets quorum before superQuorum)
|
||||
if (_superQuorumNumeratorHistory.length() > 0) {
|
||||
uint256 superQuorumNumerator_ = superQuorumNumerator();
|
||||
if (newQuorumNumerator > superQuorumNumerator_) {
|
||||
revert GovernorInvalidQuorumTooLarge(newQuorumNumerator, superQuorumNumerator_);
|
||||
}
|
||||
}
|
||||
super._updateQuorumNumerator(newQuorumNumerator);
|
||||
}
|
||||
|
||||
/// @inheritdoc GovernorSuperQuorum
|
||||
function state(
|
||||
uint256 proposalId
|
||||
) public view virtual override(Governor, GovernorSuperQuorum) returns (ProposalState) {
|
||||
return super.state(proposalId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user