GovernorSettings.sol 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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} from "../Governor.sol";
  5. /**
  6. * @dev Extension of {Governor} for settings updatable through governance.
  7. */
  8. abstract contract GovernorSettings is Governor {
  9. // amount of token
  10. uint256 private _proposalThreshold;
  11. // timepoint: limited to uint48 in core (same as clock() type)
  12. uint48 private _votingDelay;
  13. // duration: limited to uint32 in core
  14. uint32 private _votingPeriod;
  15. event VotingDelaySet(uint256 oldVotingDelay, uint256 newVotingDelay);
  16. event VotingPeriodSet(uint256 oldVotingPeriod, uint256 newVotingPeriod);
  17. event ProposalThresholdSet(uint256 oldProposalThreshold, uint256 newProposalThreshold);
  18. /**
  19. * @dev Initialize the governance parameters.
  20. */
  21. constructor(uint48 initialVotingDelay, uint32 initialVotingPeriod, uint256 initialProposalThreshold) {
  22. _setVotingDelay(initialVotingDelay);
  23. _setVotingPeriod(initialVotingPeriod);
  24. _setProposalThreshold(initialProposalThreshold);
  25. }
  26. /**
  27. * @dev See {IGovernor-votingDelay}.
  28. */
  29. function votingDelay() public view virtual override returns (uint256) {
  30. return _votingDelay;
  31. }
  32. /**
  33. * @dev See {IGovernor-votingPeriod}.
  34. */
  35. function votingPeriod() public view virtual override returns (uint256) {
  36. return _votingPeriod;
  37. }
  38. /**
  39. * @dev See {Governor-proposalThreshold}.
  40. */
  41. function proposalThreshold() public view virtual override returns (uint256) {
  42. return _proposalThreshold;
  43. }
  44. /**
  45. * @dev Update the voting delay. This operation can only be performed through a governance proposal.
  46. *
  47. * Emits a {VotingDelaySet} event.
  48. */
  49. function setVotingDelay(uint48 newVotingDelay) public virtual onlyGovernance {
  50. _setVotingDelay(newVotingDelay);
  51. }
  52. /**
  53. * @dev Update the voting period. This operation can only be performed through a governance proposal.
  54. *
  55. * Emits a {VotingPeriodSet} event.
  56. */
  57. function setVotingPeriod(uint32 newVotingPeriod) public virtual onlyGovernance {
  58. _setVotingPeriod(newVotingPeriod);
  59. }
  60. /**
  61. * @dev Update the proposal threshold. This operation can only be performed through a governance proposal.
  62. *
  63. * Emits a {ProposalThresholdSet} event.
  64. */
  65. function setProposalThreshold(uint256 newProposalThreshold) public virtual onlyGovernance {
  66. _setProposalThreshold(newProposalThreshold);
  67. }
  68. /**
  69. * @dev Internal setter for the voting delay.
  70. *
  71. * Emits a {VotingDelaySet} event.
  72. */
  73. function _setVotingDelay(uint48 newVotingDelay) internal virtual {
  74. emit VotingDelaySet(_votingDelay, newVotingDelay);
  75. _votingDelay = newVotingDelay;
  76. }
  77. /**
  78. * @dev Internal setter for the voting period.
  79. *
  80. * Emits a {VotingPeriodSet} event.
  81. */
  82. function _setVotingPeriod(uint32 newVotingPeriod) internal virtual {
  83. // voting period must be at least one block long
  84. if (newVotingPeriod == 0) {
  85. revert GovernorInvalidVotingPeriod(0);
  86. }
  87. emit VotingPeriodSet(_votingPeriod, newVotingPeriod);
  88. _votingPeriod = newVotingPeriod;
  89. }
  90. /**
  91. * @dev Internal setter for the proposal threshold.
  92. *
  93. * Emits a {ProposalThresholdSet} event.
  94. */
  95. function _setProposalThreshold(uint256 newProposalThreshold) internal virtual {
  96. emit ProposalThresholdSet(_proposalThreshold, newProposalThreshold);
  97. _proposalThreshold = newProposalThreshold;
  98. }
  99. }