GovernorSettings.sol 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts (last updated v4.9.0) (governance/extensions/GovernorSettings.sol)
  3. pragma solidity ^0.8.19;
  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(uint256 initialVotingDelay, uint256 initialVotingPeriod, uint256 initialProposalThreshold) {
  21. _setVotingDelay(initialVotingDelay);
  22. _setVotingPeriod(initialVotingPeriod);
  23. _setProposalThreshold(initialProposalThreshold);
  24. }
  25. /**
  26. * @dev See {IGovernor-votingDelay}.
  27. */
  28. function votingDelay() public view virtual override returns (uint256) {
  29. return _votingDelay;
  30. }
  31. /**
  32. * @dev See {IGovernor-votingPeriod}.
  33. */
  34. function votingPeriod() public view virtual override returns (uint256) {
  35. return _votingPeriod;
  36. }
  37. /**
  38. * @dev See {Governor-proposalThreshold}.
  39. */
  40. function proposalThreshold() public view virtual override returns (uint256) {
  41. return _proposalThreshold;
  42. }
  43. /**
  44. * @dev Update the voting delay. This operation can only be performed through a governance proposal.
  45. *
  46. * Emits a {VotingDelaySet} event.
  47. */
  48. function setVotingDelay(uint256 newVotingDelay) public virtual onlyGovernance {
  49. _setVotingDelay(newVotingDelay);
  50. }
  51. /**
  52. * @dev Update the voting period. This operation can only be performed through a governance proposal.
  53. *
  54. * Emits a {VotingPeriodSet} event.
  55. */
  56. function setVotingPeriod(uint256 newVotingPeriod) public virtual onlyGovernance {
  57. _setVotingPeriod(newVotingPeriod);
  58. }
  59. /**
  60. * @dev Update the proposal threshold. This operation can only be performed through a governance proposal.
  61. *
  62. * Emits a {ProposalThresholdSet} event.
  63. */
  64. function setProposalThreshold(uint256 newProposalThreshold) public virtual onlyGovernance {
  65. _setProposalThreshold(newProposalThreshold);
  66. }
  67. /**
  68. * @dev Internal setter for the voting delay.
  69. *
  70. * Emits a {VotingDelaySet} event.
  71. */
  72. function _setVotingDelay(uint256 newVotingDelay) internal virtual {
  73. emit VotingDelaySet(_votingDelay, newVotingDelay);
  74. _votingDelay = newVotingDelay;
  75. }
  76. /**
  77. * @dev Internal setter for the voting period.
  78. *
  79. * Emits a {VotingPeriodSet} event.
  80. */
  81. function _setVotingPeriod(uint256 newVotingPeriod) internal virtual {
  82. // voting period must be at least one block long
  83. if (newVotingPeriod == 0) {
  84. revert GovernorInvalidVotingPeriod(0);
  85. }
  86. emit VotingPeriodSet(_votingPeriod, newVotingPeriod);
  87. _votingPeriod = newVotingPeriod;
  88. }
  89. /**
  90. * @dev Internal setter for the proposal threshold.
  91. *
  92. * Emits a {ProposalThresholdSet} event.
  93. */
  94. function _setProposalThreshold(uint256 newProposalThreshold) internal virtual {
  95. emit ProposalThresholdSet(_proposalThreshold, newProposalThreshold);
  96. _proposalThreshold = newProposalThreshold;
  97. }
  98. }