-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Governor module for governance-settable parameters (#2904)
Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
- Loading branch information
Showing
19 changed files
with
647 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
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 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 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 onlyGovernance { | ||
_setProposalThreshold(newProposalThreshold); | ||
} | ||
|
||
/** | ||
* @dev Internal setter for the the voting delay. | ||
* | ||
* Emits a {VotingDelaySet} event. | ||
*/ | ||
function _setVotingDelay(uint256 newVotingDelay) internal virtual { | ||
emit VotingDelaySet(_votingDelay, newVotingDelay); | ||
_votingDelay = newVotingDelay; | ||
} | ||
|
||
/** | ||
* @dev Internal setter for the 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 the proposal threshold. | ||
* | ||
* Emits a {ProposalThresholdSet} event. | ||
*/ | ||
function _setProposalThreshold(uint256 newProposalThreshold) internal virtual { | ||
emit ProposalThresholdSet(_proposalThreshold, newProposalThreshold); | ||
_proposalThreshold = newProposalThreshold; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.