GovernorSettings.sol 3.5 KB

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