123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- // SPDX-License-Identifier: MIT
- // OpenZeppelin Contracts v4.4.0-rc.1 (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 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 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;
- }
- }
|