GovernorSettings.sol 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts v4.4.0-rc.0 (governance/extensions/GovernorSettings.sol)
  3. pragma solidity ^0.8.0;
  4. import "../Governor.sol";
  5. /**
  6. * @dev Extension of {Governor} for settings updatable through governance.
  7. *
  8. * _Available since v4.4._
  9. */
  10. abstract contract GovernorSettings is Governor {
  11. uint256 private _votingDelay;
  12. uint256 private _votingPeriod;
  13. uint256 private _proposalThreshold;
  14. event VotingDelaySet(uint256 oldVotingDelay, uint256 newVotingDelay);
  15. event VotingPeriodSet(uint256 oldVotingPeriod, uint256 newVotingPeriod);
  16. event ProposalThresholdSet(uint256 oldProposalThreshold, uint256 newProposalThreshold);
  17. /**
  18. * @dev Initialize the governance parameters.
  19. */
  20. constructor(
  21. uint256 initialVotingDelay,
  22. uint256 initialVotingPeriod,
  23. uint256 initialProposalThreshold
  24. ) {
  25. _setVotingDelay(initialVotingDelay);
  26. _setVotingPeriod(initialVotingPeriod);
  27. _setProposalThreshold(initialProposalThreshold);
  28. }
  29. /**
  30. * @dev See {IGovernor-votingDelay}.
  31. */
  32. function votingDelay() public view virtual override returns (uint256) {
  33. return _votingDelay;
  34. }
  35. /**
  36. * @dev See {IGovernor-votingPeriod}.
  37. */
  38. function votingPeriod() public view virtual override returns (uint256) {
  39. return _votingPeriod;
  40. }
  41. /**
  42. * @dev See {Governor-proposalThreshold}.
  43. */
  44. function proposalThreshold() public view virtual override returns (uint256) {
  45. return _proposalThreshold;
  46. }
  47. /**
  48. * @dev Update the voting delay. This operation can only be performed through a governance proposal.
  49. *
  50. * Emits a {VotingDelaySet} event.
  51. */
  52. function setVotingDelay(uint256 newVotingDelay) public onlyGovernance {
  53. _setVotingDelay(newVotingDelay);
  54. }
  55. /**
  56. * @dev Update the voting period. This operation can only be performed through a governance proposal.
  57. *
  58. * Emits a {VotingPeriodSet} event.
  59. */
  60. function setVotingPeriod(uint256 newVotingPeriod) public onlyGovernance {
  61. _setVotingPeriod(newVotingPeriod);
  62. }
  63. /**
  64. * @dev Update the proposal threshold. This operation can only be performed through a governance proposal.
  65. *
  66. * Emits a {ProposalThresholdSet} event.
  67. */
  68. function setProposalThreshold(uint256 newProposalThreshold) public onlyGovernance {
  69. _setProposalThreshold(newProposalThreshold);
  70. }
  71. /**
  72. * @dev Internal setter for the the voting delay.
  73. *
  74. * Emits a {VotingDelaySet} event.
  75. */
  76. function _setVotingDelay(uint256 newVotingDelay) internal virtual {
  77. emit VotingDelaySet(_votingDelay, newVotingDelay);
  78. _votingDelay = newVotingDelay;
  79. }
  80. /**
  81. * @dev Internal setter for the the voting period.
  82. *
  83. * Emits a {VotingPeriodSet} event.
  84. */
  85. function _setVotingPeriod(uint256 newVotingPeriod) internal virtual {
  86. // voting period must be at least one block long
  87. require(newVotingPeriod > 0, "GovernorSettings: voting period too low");
  88. emit VotingPeriodSet(_votingPeriod, newVotingPeriod);
  89. _votingPeriod = newVotingPeriod;
  90. }
  91. /**
  92. * @dev Internal setter for the the proposal threshold.
  93. *
  94. * Emits a {ProposalThresholdSet} event.
  95. */
  96. function _setProposalThreshold(uint256 newProposalThreshold) internal virtual {
  97. emit ProposalThresholdSet(_proposalThreshold, newProposalThreshold);
  98. _proposalThreshold = newProposalThreshold;
  99. }
  100. }