// SPDX-License-Identifier: MIT // OpenZeppelin Tron Contracts (last updated v5.4.0) (governance/extensions/GovernorSettings.sol) pragma solidity ^0.8.24; import {IGovernor} from "@openzeppelin/tron-contracts/governance/IGovernor.sol"; import {GovernorUpgradeable} from "../GovernorUpgradeable.sol"; import {Initializable} from "@openzeppelin/tron-contracts/proxy/utils/Initializable.sol"; /** * @dev Extension of {Governor} for settings updatable through governance. */ abstract contract GovernorSettingsUpgradeable is Initializable, GovernorUpgradeable { /// @custom:storage-location erc7201:openzeppelin.storage.GovernorSettings struct GovernorSettingsStorage { // amount of token uint256 _proposalThreshold; // timepoint: limited to uint48 in core (same as clock() type) uint48 _votingDelay; // duration: limited to uint32 in core uint32 _votingPeriod; } // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.GovernorSettings")) - 1)) & ~bytes32(uint256(0xff)) bytes32 private constant GovernorSettingsStorageLocation = 0x00d7616c8fe29c6c2fbe1d0c5bc8f2faa4c35b43746e70b24b4d532752affd00; function _getGovernorSettingsStorage() private pure returns (GovernorSettingsStorage storage $) { assembly { $.slot := GovernorSettingsStorageLocation } } event VotingDelaySet(uint256 oldVotingDelay, uint256 newVotingDelay); event VotingPeriodSet(uint256 oldVotingPeriod, uint256 newVotingPeriod); event ProposalThresholdSet(uint256 oldProposalThreshold, uint256 newProposalThreshold); /** * @dev Initialize the governance parameters. */ function __GovernorSettings_init( uint48 initialVotingDelay, uint32 initialVotingPeriod, uint256 initialProposalThreshold ) internal onlyInitializing { __GovernorSettings_init_unchained(initialVotingDelay, initialVotingPeriod, initialProposalThreshold); } function __GovernorSettings_init_unchained( uint48 initialVotingDelay, uint32 initialVotingPeriod, uint256 initialProposalThreshold ) internal onlyInitializing { _setVotingDelay(initialVotingDelay); _setVotingPeriod(initialVotingPeriod); _setProposalThreshold(initialProposalThreshold); } /// @inheritdoc IGovernor function votingDelay() public view virtual override returns (uint256) { GovernorSettingsStorage storage $ = _getGovernorSettingsStorage(); return $._votingDelay; } /// @inheritdoc IGovernor function votingPeriod() public view virtual override returns (uint256) { GovernorSettingsStorage storage $ = _getGovernorSettingsStorage(); return $._votingPeriod; } /// @inheritdoc GovernorUpgradeable function proposalThreshold() public view virtual override returns (uint256) { GovernorSettingsStorage storage $ = _getGovernorSettingsStorage(); return $._proposalThreshold; } /** * @dev Update the voting delay. This operation can only be performed through a governance proposal. * * Emits a {VotingDelaySet} event. */ function setVotingDelay(uint48 newVotingDelay) public virtual onlyGovernance { _setVotingDelay(newVotingDelay); } /** * @dev Update the voting period. This operation can only be performed through a governance proposal. * * Emits a {VotingPeriodSet} event. */ function setVotingPeriod(uint32 newVotingPeriod) public virtual onlyGovernance { _setVotingPeriod(newVotingPeriod); } /** * @dev Update the proposal threshold. This operation can only be performed through a governance proposal. * * Emits a {ProposalThresholdSet} event. */ function setProposalThreshold(uint256 newProposalThreshold) public virtual onlyGovernance { _setProposalThreshold(newProposalThreshold); } /** * @dev Internal setter for the voting delay. * * Emits a {VotingDelaySet} event. */ function _setVotingDelay(uint48 newVotingDelay) internal virtual { GovernorSettingsStorage storage $ = _getGovernorSettingsStorage(); emit VotingDelaySet($._votingDelay, newVotingDelay); $._votingDelay = newVotingDelay; } /** * @dev Internal setter for the voting period. * * Emits a {VotingPeriodSet} event. */ function _setVotingPeriod(uint32 newVotingPeriod) internal virtual { GovernorSettingsStorage storage $ = _getGovernorSettingsStorage(); if (newVotingPeriod == 0) { revert GovernorInvalidVotingPeriod(0); } emit VotingPeriodSet($._votingPeriod, newVotingPeriod); $._votingPeriod = newVotingPeriod; } /** * @dev Internal setter for the proposal threshold. * * Emits a {ProposalThresholdSet} event. */ function _setProposalThreshold(uint256 newProposalThreshold) internal virtual { GovernorSettingsStorage storage $ = _getGovernorSettingsStorage(); emit ProposalThresholdSet($._proposalThreshold, newProposalThreshold); $._proposalThreshold = newProposalThreshold; } }