mirror of
https://github.com/th30d4y/OpenLearnX.git
synced 2026-05-26 19:26:33 +00:00
Fix .gitignore: stop tracking ignored files
This commit is contained in:
+100
@@ -0,0 +1,100 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v4.9.0) (governance/extensions/GovernorCountingSimple.sol)
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "../Governor.sol";
|
||||
|
||||
/**
|
||||
* @dev Extension of {Governor} for simple, 3 options, vote counting.
|
||||
*
|
||||
* _Available since v4.3._
|
||||
*/
|
||||
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 => bool) hasVoted;
|
||||
}
|
||||
|
||||
mapping(uint256 => ProposalVote) private _proposalVotes;
|
||||
|
||||
/**
|
||||
* @dev See {IGovernor-COUNTING_MODE}.
|
||||
*/
|
||||
// solhint-disable-next-line func-name-mixedcase
|
||||
function COUNTING_MODE() public pure virtual override returns (string memory) {
|
||||
return "support=bravo&quorum=for,abstain";
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {IGovernor-hasVoted}.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {Governor-_quorumReached}.
|
||||
*/
|
||||
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 weight,
|
||||
bytes memory // params
|
||||
) internal virtual override {
|
||||
ProposalVote storage proposalVote = _proposalVotes[proposalId];
|
||||
|
||||
require(!proposalVote.hasVoted[account], "GovernorVotingSimple: vote already cast");
|
||||
proposalVote.hasVoted[account] = true;
|
||||
|
||||
if (support == uint8(VoteType.Against)) {
|
||||
proposalVote.againstVotes += weight;
|
||||
} else if (support == uint8(VoteType.For)) {
|
||||
proposalVote.forVotes += weight;
|
||||
} else if (support == uint8(VoteType.Abstain)) {
|
||||
proposalVote.abstainVotes += weight;
|
||||
} else {
|
||||
revert("GovernorVotingSimple: invalid value for enum VoteType");
|
||||
}
|
||||
}
|
||||
}
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v4.9.0) (governance/extensions/GovernorPreventLateQuorum.sol)
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "../Governor.sol";
|
||||
import "../../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.
|
||||
*
|
||||
* _Available since v4.5._
|
||||
*/
|
||||
abstract contract GovernorPreventLateQuorum is Governor {
|
||||
uint64 private _voteExtension;
|
||||
|
||||
/// @custom:oz-retyped-from mapping(uint256 => Timers.BlockNumber)
|
||||
mapping(uint256 => uint64) 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(uint64 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 Casts a vote and detects if it caused quorum to be reached, potentially extending the voting period. See
|
||||
* {Governor-_castVote}.
|
||||
*
|
||||
* May emit a {ProposalExtended} event.
|
||||
*/
|
||||
function _castVote(
|
||||
uint256 proposalId,
|
||||
address account,
|
||||
uint8 support,
|
||||
string memory reason,
|
||||
bytes memory params
|
||||
) internal virtual override returns (uint256) {
|
||||
uint256 result = super._castVote(proposalId, account, support, reason, params);
|
||||
|
||||
if (_extendedDeadlines[proposalId] == 0 && _quorumReached(proposalId)) {
|
||||
uint64 extendedDeadline = clock() + lateQuorumVoteExtension();
|
||||
|
||||
if (extendedDeadline > proposalDeadline(proposalId)) {
|
||||
emit ProposalExtended(proposalId, extendedDeadline);
|
||||
}
|
||||
|
||||
_extendedDeadlines[proposalId] = extendedDeadline;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 (uint64) {
|
||||
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(uint64 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(uint64 newVoteExtension) internal virtual {
|
||||
emit LateQuorumVoteExtensionSet(_voteExtension, newVoteExtension);
|
||||
_voteExtension = newVoteExtension;
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts v4.4.1 (governance/extensions/GovernorProposalThreshold.sol)
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "../Governor.sol";
|
||||
|
||||
/**
|
||||
* @dev Extension of {Governor} for proposal restriction to token holders with a minimum balance.
|
||||
*
|
||||
* _Available since v4.3._
|
||||
* _Deprecated since v4.4._
|
||||
*/
|
||||
abstract contract GovernorProposalThreshold is Governor {
|
||||
function propose(
|
||||
address[] memory targets,
|
||||
uint256[] memory values,
|
||||
bytes[] memory calldatas,
|
||||
string memory description
|
||||
) public virtual override returns (uint256) {
|
||||
return super.propose(targets, values, calldatas, description);
|
||||
}
|
||||
}
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v4.9.0) (governance/extensions/GovernorSettings.sol)
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "../Governor.sol";
|
||||
|
||||
/**
|
||||
* @dev Extension of {Governor} for settings updatable through governance.
|
||||
*
|
||||
* _Available since v4.4._
|
||||
*/
|
||||
abstract contract GovernorSettings is Governor {
|
||||
uint256 private _votingDelay;
|
||||
uint256 private _votingPeriod;
|
||||
uint256 private _proposalThreshold;
|
||||
|
||||
event VotingDelaySet(uint256 oldVotingDelay, uint256 newVotingDelay);
|
||||
event VotingPeriodSet(uint256 oldVotingPeriod, uint256 newVotingPeriod);
|
||||
event ProposalThresholdSet(uint256 oldProposalThreshold, uint256 newProposalThreshold);
|
||||
|
||||
/**
|
||||
* @dev Initialize the governance parameters.
|
||||
*/
|
||||
constructor(uint256 initialVotingDelay, uint256 initialVotingPeriod, uint256 initialProposalThreshold) {
|
||||
_setVotingDelay(initialVotingDelay);
|
||||
_setVotingPeriod(initialVotingPeriod);
|
||||
_setProposalThreshold(initialProposalThreshold);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {IGovernor-votingDelay}.
|
||||
*/
|
||||
function votingDelay() public view virtual override returns (uint256) {
|
||||
return _votingDelay;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {IGovernor-votingPeriod}.
|
||||
*/
|
||||
function votingPeriod() public view virtual override returns (uint256) {
|
||||
return _votingPeriod;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {Governor-proposalThreshold}.
|
||||
*/
|
||||
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(uint256 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(uint256 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(uint256 newVotingDelay) internal virtual {
|
||||
emit VotingDelaySet(_votingDelay, newVotingDelay);
|
||||
_votingDelay = newVotingDelay;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Internal setter for the voting period.
|
||||
*
|
||||
* Emits a {VotingPeriodSet} event.
|
||||
*/
|
||||
function _setVotingPeriod(uint256 newVotingPeriod) internal virtual {
|
||||
// voting period must be at least one block long
|
||||
require(newVotingPeriod > 0, "GovernorSettings: voting period too low");
|
||||
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;
|
||||
}
|
||||
}
|
||||
+190
@@ -0,0 +1,190 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v4.9.0) (governance/extensions/GovernorTimelockCompound.sol)
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "./IGovernorTimelock.sol";
|
||||
import "../Governor.sol";
|
||||
import "../../utils/math/SafeCast.sol";
|
||||
import "../../vendor/compound/ICompoundTimelock.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 proposal (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.
|
||||
*
|
||||
* _Available since v4.3._
|
||||
*/
|
||||
abstract contract GovernorTimelockCompound is IGovernorTimelock, Governor {
|
||||
ICompoundTimelock private _timelock;
|
||||
|
||||
/// @custom:oz-retyped-from mapping(uint256 => GovernorTimelockCompound.ProposalTimelock)
|
||||
mapping(uint256 => uint64) private _proposalTimelocks;
|
||||
|
||||
/**
|
||||
* @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 See {IERC165-supportsInterface}.
|
||||
*/
|
||||
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, Governor) returns (bool) {
|
||||
return interfaceId == type(IGovernorTimelock).interfaceId || super.supportsInterface(interfaceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Overridden version of the {Governor-state} function with added support for the `Queued` and `Expired` state.
|
||||
*/
|
||||
function state(uint256 proposalId) public view virtual override(IGovernor, Governor) returns (ProposalState) {
|
||||
ProposalState currentState = super.state(proposalId);
|
||||
|
||||
if (currentState != ProposalState.Succeeded) {
|
||||
return currentState;
|
||||
}
|
||||
|
||||
uint256 eta = proposalEta(proposalId);
|
||||
if (eta == 0) {
|
||||
return currentState;
|
||||
} else if (block.timestamp >= eta + _timelock.GRACE_PERIOD()) {
|
||||
return ProposalState.Expired;
|
||||
} else {
|
||||
return ProposalState.Queued;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Public accessor to check the address of the timelock
|
||||
*/
|
||||
function timelock() public view virtual override returns (address) {
|
||||
return address(_timelock);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Public accessor to check the eta of a queued proposal
|
||||
*/
|
||||
function proposalEta(uint256 proposalId) public view virtual override returns (uint256) {
|
||||
return _proposalTimelocks[proposalId];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Function to queue a proposal to the timelock.
|
||||
*/
|
||||
function queue(
|
||||
address[] memory targets,
|
||||
uint256[] memory values,
|
||||
bytes[] memory calldatas,
|
||||
bytes32 descriptionHash
|
||||
) public virtual override returns (uint256) {
|
||||
uint256 proposalId = hashProposal(targets, values, calldatas, descriptionHash);
|
||||
|
||||
require(state(proposalId) == ProposalState.Succeeded, "Governor: proposal not successful");
|
||||
|
||||
uint256 eta = block.timestamp + _timelock.delay();
|
||||
_proposalTimelocks[proposalId] = SafeCast.toUint64(eta);
|
||||
|
||||
for (uint256 i = 0; i < targets.length; ++i) {
|
||||
require(
|
||||
!_timelock.queuedTransactions(keccak256(abi.encode(targets[i], values[i], "", calldatas[i], eta))),
|
||||
"GovernorTimelockCompound: identical proposal action already queued"
|
||||
);
|
||||
_timelock.queueTransaction(targets[i], values[i], "", calldatas[i], eta);
|
||||
}
|
||||
|
||||
emit ProposalQueued(proposalId, eta);
|
||||
|
||||
return proposalId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Overridden execute function that run the already queued proposal through the timelock.
|
||||
*/
|
||||
function _execute(
|
||||
uint256 proposalId,
|
||||
address[] memory targets,
|
||||
uint256[] memory values,
|
||||
bytes[] memory calldatas,
|
||||
bytes32 /*descriptionHash*/
|
||||
) internal virtual override {
|
||||
uint256 eta = proposalEta(proposalId);
|
||||
require(eta > 0, "GovernorTimelockCompound: proposal not yet queued");
|
||||
Address.sendValue(payable(_timelock), msg.value);
|
||||
for (uint256 i = 0; i < targets.length; ++i) {
|
||||
_timelock.executeTransaction(targets[i], values[i], "", calldatas[i], eta);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Overridden version of the {Governor-_cancel} function to cancel the timelocked proposal if it as 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 eta = proposalEta(proposalId);
|
||||
if (eta > 0) {
|
||||
// update state first
|
||||
delete _proposalTimelocks[proposalId];
|
||||
// do external call later
|
||||
for (uint256 i = 0; i < targets.length; ++i) {
|
||||
_timelock.cancelTransaction(targets[i], values[i], "", calldatas[i], eta);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
+166
@@ -0,0 +1,166 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v4.9.0) (governance/extensions/GovernorTimelockControl.sol)
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "./IGovernorTimelock.sol";
|
||||
import "../Governor.sol";
|
||||
import "../TimelockController.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) 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.
|
||||
*
|
||||
* WARNING: Setting up the TimelockController to have additional proposers besides the governor is very risky, as it
|
||||
* grants them powers that they must be trusted or known not to use: 1) {onlyGovernance} functions like {relay} are
|
||||
* available to them through the timelock, and 2) approved governance proposals can be blocked by them, effectively
|
||||
* executing a Denial of Service attack. This risk will be mitigated in a future release.
|
||||
*
|
||||
* _Available since v4.3._
|
||||
*/
|
||||
abstract contract GovernorTimelockControl is IGovernorTimelock, Governor {
|
||||
TimelockController private _timelock;
|
||||
mapping(uint256 => 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 See {IERC165-supportsInterface}.
|
||||
*/
|
||||
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, Governor) returns (bool) {
|
||||
return interfaceId == type(IGovernorTimelock).interfaceId || super.supportsInterface(interfaceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Overridden version of the {Governor-state} function with added support for the `Queued` state.
|
||||
*/
|
||||
function state(uint256 proposalId) public view virtual override(IGovernor, Governor) returns (ProposalState) {
|
||||
ProposalState currentState = super.state(proposalId);
|
||||
|
||||
if (currentState != ProposalState.Succeeded) {
|
||||
return currentState;
|
||||
}
|
||||
|
||||
// core tracks execution, so we just have to check if successful proposal have been queued.
|
||||
bytes32 queueid = _timelockIds[proposalId];
|
||||
if (queueid == bytes32(0)) {
|
||||
return currentState;
|
||||
} else if (_timelock.isOperationDone(queueid)) {
|
||||
return ProposalState.Executed;
|
||||
} else if (_timelock.isOperationPending(queueid)) {
|
||||
return ProposalState.Queued;
|
||||
} else {
|
||||
return ProposalState.Canceled;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Public accessor to check the address of the timelock
|
||||
*/
|
||||
function timelock() public view virtual override returns (address) {
|
||||
return address(_timelock);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Public accessor to check the eta of a queued proposal
|
||||
*/
|
||||
function proposalEta(uint256 proposalId) public view virtual override returns (uint256) {
|
||||
uint256 eta = _timelock.getTimestamp(_timelockIds[proposalId]);
|
||||
return eta == 1 ? 0 : eta; // _DONE_TIMESTAMP (1) should be replaced with a 0 value
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Function to queue a proposal to the timelock.
|
||||
*/
|
||||
function queue(
|
||||
address[] memory targets,
|
||||
uint256[] memory values,
|
||||
bytes[] memory calldatas,
|
||||
bytes32 descriptionHash
|
||||
) public virtual override returns (uint256) {
|
||||
uint256 proposalId = hashProposal(targets, values, calldatas, descriptionHash);
|
||||
|
||||
require(state(proposalId) == ProposalState.Succeeded, "Governor: proposal not successful");
|
||||
|
||||
uint256 delay = _timelock.getMinDelay();
|
||||
_timelockIds[proposalId] = _timelock.hashOperationBatch(targets, values, calldatas, 0, descriptionHash);
|
||||
_timelock.scheduleBatch(targets, values, calldatas, 0, descriptionHash, delay);
|
||||
|
||||
emit ProposalQueued(proposalId, block.timestamp + delay);
|
||||
|
||||
return proposalId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Overridden execute function that run the already queued proposal through the timelock.
|
||||
*/
|
||||
function _execute(
|
||||
uint256 /* proposalId */,
|
||||
address[] memory targets,
|
||||
uint256[] memory values,
|
||||
bytes[] memory calldatas,
|
||||
bytes32 descriptionHash
|
||||
) internal virtual override {
|
||||
_timelock.executeBatch{value: msg.value}(targets, values, calldatas, 0, descriptionHash);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Overridden version of the {Governor-_cancel} function to cancel the timelocked proposal if it as 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);
|
||||
|
||||
if (_timelockIds[proposalId] != 0) {
|
||||
_timelock.cancel(_timelockIds[proposalId]);
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v4.9.0) (governance/extensions/GovernorVotes.sol)
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "../Governor.sol";
|
||||
import "../../interfaces/IERC5805.sol";
|
||||
|
||||
/**
|
||||
* @dev Extension of {Governor} for voting weight extraction from an {ERC20Votes} token, or since v4.5 an {ERC721Votes} token.
|
||||
*
|
||||
* _Available since v4.3._
|
||||
*/
|
||||
abstract contract GovernorVotes is Governor {
|
||||
IERC5805 public immutable token;
|
||||
|
||||
constructor(IVotes tokenAddress) {
|
||||
token = IERC5805(address(tokenAddress));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Clock (as specified in EIP-6372) is set to match the token's clock. Fallback to block numbers if the token
|
||||
* does not implement EIP-6372.
|
||||
*/
|
||||
function clock() public view virtual override returns (uint48) {
|
||||
try token.clock() returns (uint48 timepoint) {
|
||||
return timepoint;
|
||||
} catch {
|
||||
return SafeCast.toUint48(block.number);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Machine-readable description of the clock as specified in EIP-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);
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v4.9.0) (governance/extensions/GovernorVotesComp.sol)
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "../Governor.sol";
|
||||
import "../../token/ERC20/extensions/ERC20VotesComp.sol";
|
||||
|
||||
/**
|
||||
* @dev Extension of {Governor} for voting weight extraction from a Comp token.
|
||||
*
|
||||
* _Available since v4.3._
|
||||
*/
|
||||
abstract contract GovernorVotesComp is Governor {
|
||||
ERC20VotesComp public immutable token;
|
||||
|
||||
constructor(ERC20VotesComp token_) {
|
||||
token = token_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Clock (as specified in EIP-6372) is set to match the token's clock. Fallback to block numbers if the token
|
||||
* does not implement EIP-6372.
|
||||
*/
|
||||
function clock() public view virtual override returns (uint48) {
|
||||
try token.clock() returns (uint48 timepoint) {
|
||||
return timepoint;
|
||||
} catch {
|
||||
return SafeCast.toUint48(block.number);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Machine-readable description of the clock as specified in EIP-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.getPriorVotes(account, timepoint);
|
||||
}
|
||||
}
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v4.9.0) (governance/extensions/GovernorVotesQuorumFraction.sol)
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "./GovernorVotes.sol";
|
||||
import "../../utils/Checkpoints.sol";
|
||||
import "../../utils/math/SafeCast.sol";
|
||||
|
||||
/**
|
||||
* @dev Extension of {Governor} for voting weight extraction from an {ERC20Votes} token and a quorum expressed as a
|
||||
* fraction of the total supply.
|
||||
*
|
||||
* _Available since v4.3._
|
||||
*/
|
||||
abstract contract GovernorVotesQuorumFraction is GovernorVotes {
|
||||
using Checkpoints for Checkpoints.Trace224;
|
||||
|
||||
uint256 private _quorumNumerator; // DEPRECATED in favor of _quorumNumeratorHistory
|
||||
|
||||
/// @custom:oz-retyped-from Checkpoints.History
|
||||
Checkpoints.Trace224 private _quorumNumeratorHistory;
|
||||
|
||||
event QuorumNumeratorUpdated(uint256 oldQuorumNumerator, uint256 newQuorumNumerator);
|
||||
|
||||
/**
|
||||
* @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._checkpoints.length == 0 ? _quorumNumerator : _quorumNumeratorHistory.latest();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the quorum numerator at a specific timepoint. See {quorumDenominator}.
|
||||
*/
|
||||
function quorumNumerator(uint256 timepoint) public view virtual returns (uint256) {
|
||||
// If history is empty, fallback to old storage
|
||||
uint256 length = _quorumNumeratorHistory._checkpoints.length;
|
||||
if (length == 0) {
|
||||
return _quorumNumerator;
|
||||
}
|
||||
|
||||
// Optimistic search, check the latest checkpoint
|
||||
Checkpoints.Checkpoint224 memory latest = _quorumNumeratorHistory._checkpoints[length - 1];
|
||||
if (latest._key <= timepoint) {
|
||||
return latest._value;
|
||||
}
|
||||
|
||||
// Otherwise, do the binary search
|
||||
return _quorumNumeratorHistory.upperLookupRecent(SafeCast.toUint32(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 (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 {
|
||||
require(
|
||||
newQuorumNumerator <= quorumDenominator(),
|
||||
"GovernorVotesQuorumFraction: quorumNumerator over quorumDenominator"
|
||||
);
|
||||
|
||||
uint256 oldQuorumNumerator = quorumNumerator();
|
||||
|
||||
// Make sure we keep track of the original numerator in contracts upgraded from a version without checkpoints.
|
||||
if (oldQuorumNumerator != 0 && _quorumNumeratorHistory._checkpoints.length == 0) {
|
||||
_quorumNumeratorHistory._checkpoints.push(
|
||||
Checkpoints.Checkpoint224({_key: 0, _value: SafeCast.toUint224(oldQuorumNumerator)})
|
||||
);
|
||||
}
|
||||
|
||||
// Set new quorum for future proposals
|
||||
_quorumNumeratorHistory.push(SafeCast.toUint32(clock()), SafeCast.toUint224(newQuorumNumerator));
|
||||
|
||||
emit QuorumNumeratorUpdated(oldQuorumNumerator, newQuorumNumerator);
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts v4.4.1 (governance/extensions/IGovernorTimelock.sol)
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "../IGovernor.sol";
|
||||
|
||||
/**
|
||||
* @dev Extension of the {IGovernor} for timelock supporting modules.
|
||||
*
|
||||
* _Available since v4.3._
|
||||
*/
|
||||
abstract contract IGovernorTimelock is IGovernor {
|
||||
event ProposalQueued(uint256 proposalId, uint256 eta);
|
||||
|
||||
function timelock() public view virtual returns (address);
|
||||
|
||||
function proposalEta(uint256 proposalId) public view virtual returns (uint256);
|
||||
|
||||
function queue(
|
||||
address[] memory targets,
|
||||
uint256[] memory values,
|
||||
bytes[] memory calldatas,
|
||||
bytes32 descriptionHash
|
||||
) public virtual returns (uint256 proposalId);
|
||||
}
|
||||
Reference in New Issue
Block a user