GovernorSettings.sol 3.4 KB

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