GovernorSettingsUpgradeable.sol 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts v4.4.1 (governance/extensions/GovernorSettings.sol)
  3. pragma solidity ^0.8.0;
  4. import "../GovernorUpgradeable.sol";
  5. import "../../proxy/utils/Initializable.sol";
  6. /**
  7. * @dev Extension of {Governor} for settings updatable through governance.
  8. *
  9. * _Available since v4.4._
  10. */
  11. abstract contract GovernorSettingsUpgradeable is Initializable, GovernorUpgradeable {
  12. uint256 private _votingDelay;
  13. uint256 private _votingPeriod;
  14. uint256 private _proposalThreshold;
  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. function __GovernorSettings_init(
  22. uint256 initialVotingDelay,
  23. uint256 initialVotingPeriod,
  24. uint256 initialProposalThreshold
  25. ) internal onlyInitializing {
  26. __GovernorSettings_init_unchained(initialVotingDelay, initialVotingPeriod, initialProposalThreshold);
  27. }
  28. function __GovernorSettings_init_unchained(
  29. uint256 initialVotingDelay,
  30. uint256 initialVotingPeriod,
  31. uint256 initialProposalThreshold
  32. ) internal onlyInitializing {
  33. _setVotingDelay(initialVotingDelay);
  34. _setVotingPeriod(initialVotingPeriod);
  35. _setProposalThreshold(initialProposalThreshold);
  36. }
  37. /**
  38. * @dev See {IGovernor-votingDelay}.
  39. */
  40. function votingDelay() public view virtual override returns (uint256) {
  41. return _votingDelay;
  42. }
  43. /**
  44. * @dev See {IGovernor-votingPeriod}.
  45. */
  46. function votingPeriod() public view virtual override returns (uint256) {
  47. return _votingPeriod;
  48. }
  49. /**
  50. * @dev See {Governor-proposalThreshold}.
  51. */
  52. function proposalThreshold() public view virtual override returns (uint256) {
  53. return _proposalThreshold;
  54. }
  55. /**
  56. * @dev Update the voting delay. This operation can only be performed through a governance proposal.
  57. *
  58. * Emits a {VotingDelaySet} event.
  59. */
  60. function setVotingDelay(uint256 newVotingDelay) public virtual onlyGovernance {
  61. _setVotingDelay(newVotingDelay);
  62. }
  63. /**
  64. * @dev Update the voting period. This operation can only be performed through a governance proposal.
  65. *
  66. * Emits a {VotingPeriodSet} event.
  67. */
  68. function setVotingPeriod(uint256 newVotingPeriod) public virtual onlyGovernance {
  69. _setVotingPeriod(newVotingPeriod);
  70. }
  71. /**
  72. * @dev Update the proposal threshold. This operation can only be performed through a governance proposal.
  73. *
  74. * Emits a {ProposalThresholdSet} event.
  75. */
  76. function setProposalThreshold(uint256 newProposalThreshold) public virtual onlyGovernance {
  77. _setProposalThreshold(newProposalThreshold);
  78. }
  79. /**
  80. * @dev Internal setter for the voting delay.
  81. *
  82. * Emits a {VotingDelaySet} event.
  83. */
  84. function _setVotingDelay(uint256 newVotingDelay) internal virtual {
  85. emit VotingDelaySet(_votingDelay, newVotingDelay);
  86. _votingDelay = newVotingDelay;
  87. }
  88. /**
  89. * @dev Internal setter for the voting period.
  90. *
  91. * Emits a {VotingPeriodSet} event.
  92. */
  93. function _setVotingPeriod(uint256 newVotingPeriod) internal virtual {
  94. // voting period must be at least one block long
  95. require(newVotingPeriod > 0, "GovernorSettings: voting period too low");
  96. emit VotingPeriodSet(_votingPeriod, newVotingPeriod);
  97. _votingPeriod = newVotingPeriod;
  98. }
  99. /**
  100. * @dev Internal setter for the proposal threshold.
  101. *
  102. * Emits a {ProposalThresholdSet} event.
  103. */
  104. function _setProposalThreshold(uint256 newProposalThreshold) internal virtual {
  105. emit ProposalThresholdSet(_proposalThreshold, newProposalThreshold);
  106. _proposalThreshold = newProposalThreshold;
  107. }
  108. /**
  109. * This empty reserved space is put in place to allow future versions to add new
  110. * variables without shifting down storage in the inheritance chain.
  111. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
  112. */
  113. uint256[47] private __gap;
  114. }