@bitriel/governance
Version:
On-chain DAO governance for Bitriel Protocol
34 lines • 10.9 MB
JSON
{
"id": "d374dbbdc8d1c1a04649dde03da43402",
"_format": "hh-sol-build-info-1",
"solcVersion": "0.8.7",
"solcLongVersion": "0.8.7+commit.e28d00a7",
"input": {
"language": "Solidity",
"sources": {
"contracts/BitrielGovernance.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.4;\n\nimport \"@openzeppelin/contracts/governance/Governor.sol\";\nimport \"@openzeppelin/contracts/governance/extensions/GovernorSettings.sol\";\nimport \"@openzeppelin/contracts/governance/compatibility/GovernorCompatibilityBravo.sol\";\nimport \"@openzeppelin/contracts/governance/extensions/GovernorVotes.sol\";\nimport \"@openzeppelin/contracts/governance/extensions/GovernorVotesQuorumFraction.sol\";\nimport \"@openzeppelin/contracts/governance/extensions/GovernorTimelockControl.sol\";\n\ncontract BitrielGovernor is Governor, GovernorSettings, GovernorCompatibilityBravo, GovernorVotes, GovernorVotesQuorumFraction, GovernorTimelockControl {\n constructor(IVotes _token, TimelockController _timelock)\n Governor(\"BitrielGovernor\")\n GovernorSettings(1 /* 1 block */, 25200 /* 1 week */, 0)\n GovernorVotes(_token)\n GovernorVotesQuorumFraction(4)\n GovernorTimelockControl(_timelock)\n {}\n\n /// @notice The total number of proposals\n uint public proposalCount;\n\n /// @notice The latest proposal for each proposer\n mapping (address => uint) public latestProposalIds;\n\n // The following functions are overrides required by Solidity.\n\n function votingDelay()\n public\n view\n override(IGovernor, GovernorSettings)\n returns (uint256)\n {\n return super.votingDelay();\n }\n\n function votingPeriod()\n public\n view\n override(IGovernor, GovernorSettings)\n returns (uint256)\n {\n return super.votingPeriod();\n }\n\n function quorum(uint256 blockNumber)\n public\n view\n override(IGovernor, GovernorVotesQuorumFraction)\n returns (uint256)\n {\n return super.quorum(blockNumber);\n }\n\n function getVotes(address account, uint256 blockNumber)\n public\n view\n override(IGovernor, GovernorVotes)\n returns (uint256)\n {\n return super.getVotes(account, blockNumber);\n }\n\n function state(uint256 proposalId)\n public\n view\n override(Governor, IGovernor, GovernorTimelockControl)\n returns (ProposalState)\n {\n return super.state(proposalId);\n }\n\n function propose(address[] memory targets, uint256[] memory values, bytes[] memory calldatas, string memory description)\n public\n override(Governor, GovernorCompatibilityBravo, IGovernor)\n returns (uint256)\n {\n proposalCount++;\n latestProposalIds[msg.sender] = proposalCount;\n return super.propose(targets, values, calldatas, description);\n }\n\n function proposalThreshold()\n public\n view\n override(Governor, GovernorSettings)\n returns (uint256)\n {\n return super.proposalThreshold();\n }\n\n function _execute(uint256 proposalId, address[] memory targets, uint256[] memory values, bytes[] memory calldatas, bytes32 descriptionHash)\n internal\n override(Governor, GovernorTimelockControl)\n {\n super._execute(proposalId, targets, values, calldatas, descriptionHash);\n }\n\n function _cancel(address[] memory targets, uint256[] memory values, bytes[] memory calldatas, bytes32 descriptionHash)\n internal\n override(Governor, GovernorTimelockControl)\n returns (uint256)\n {\n return super._cancel(targets, values, calldatas, descriptionHash);\n }\n\n function _executor()\n internal\n view\n override(Governor, GovernorTimelockControl)\n returns (address)\n {\n return super._executor();\n }\n\n function supportsInterface(bytes4 interfaceId)\n public\n view\n override(Governor, IERC165, GovernorTimelockControl)\n returns (bool)\n {\n return super.supportsInterface(interfaceId);\n }\n}\n"
},
"@openzeppelin/contracts/governance/extensions/GovernorTimelockControl.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (governance/extensions/GovernorTimelockControl.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IGovernorTimelock.sol\";\nimport \"../Governor.sol\";\nimport \"../TimelockController.sol\";\n\n/**\n * @dev Extension of {Governor} that binds the execution process to an instance of {TimelockController}. This adds a\n * delay, enforced by the {TimelockController} to all successful proposal (in addition to the voting duration). The\n * {Governor} needs the proposer (and ideally the executor) roles for the {Governor} to work properly.\n *\n * Using this model means the proposal will be operated by the {TimelockController} and not by the {Governor}. Thus,\n * the assets and permissions must be attached to the {TimelockController}. Any asset sent to the {Governor} will be\n * inaccessible.\n *\n * WARNING: Setting up the TimelockController to have additional proposers besides the governor is very risky, as it\n * grants them powers that they must be trusted or known not to use: 1) {onlyGovernance} functions like {relay} are\n * available to them through the timelock, and 2) approved governance proposals can be blocked by them, effectively\n * executing a Denial of Service attack. This risk will be mitigated in a future release.\n *\n * _Available since v4.3._\n */\nabstract contract GovernorTimelockControl is IGovernorTimelock, Governor {\n TimelockController private _timelock;\n mapping(uint256 => bytes32) private _timelockIds;\n\n /**\n * @dev Emitted when the timelock controller used for proposal execution is modified.\n */\n event TimelockChange(address oldTimelock, address newTimelock);\n\n /**\n * @dev Set the timelock.\n */\n constructor(TimelockController timelockAddress) {\n _updateTimelock(timelockAddress);\n }\n\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, Governor) returns (bool) {\n return interfaceId == type(IGovernorTimelock).interfaceId || super.supportsInterface(interfaceId);\n }\n\n /**\n * @dev Overriden version of the {Governor-state} function with added support for the `Queued` status.\n */\n function state(uint256 proposalId) public view virtual override(IGovernor, Governor) returns (ProposalState) {\n ProposalState status = super.state(proposalId);\n\n if (status != ProposalState.Succeeded) {\n return status;\n }\n\n // core tracks execution, so we just have to check if successful proposal have been queued.\n bytes32 queueid = _timelockIds[proposalId];\n if (queueid == bytes32(0)) {\n return status;\n } else if (_timelock.isOperationDone(queueid)) {\n return ProposalState.Executed;\n } else if (_timelock.isOperationPending(queueid)) {\n return ProposalState.Queued;\n } else {\n return ProposalState.Canceled;\n }\n }\n\n /**\n * @dev Public accessor to check the address of the timelock\n */\n function timelock() public view virtual override returns (address) {\n return address(_timelock);\n }\n\n /**\n * @dev Public accessor to check the eta of a queued proposal\n */\n function proposalEta(uint256 proposalId) public view virtual override returns (uint256) {\n uint256 eta = _timelock.getTimestamp(_timelockIds[proposalId]);\n return eta == 1 ? 0 : eta; // _DONE_TIMESTAMP (1) should be replaced with a 0 value\n }\n\n /**\n * @dev Function to queue a proposal to the timelock.\n */\n function queue(\n address[] memory targets,\n uint256[] memory values,\n bytes[] memory calldatas,\n bytes32 descriptionHash\n ) public virtual override returns (uint256) {\n uint256 proposalId = hashProposal(targets, values, calldatas, descriptionHash);\n\n require(state(proposalId) == ProposalState.Succeeded, \"Governor: proposal not successful\");\n\n uint256 delay = _timelock.getMinDelay();\n _timelockIds[proposalId] = _timelock.hashOperationBatch(targets, values, calldatas, 0, descriptionHash);\n _timelock.scheduleBatch(targets, values, calldatas, 0, descriptionHash, delay);\n\n emit ProposalQueued(proposalId, block.timestamp + delay);\n\n return proposalId;\n }\n\n /**\n * @dev Overriden execute function that run the already queued proposal through the timelock.\n */\n function _execute(\n uint256, /* proposalId */\n address[] memory targets,\n uint256[] memory values,\n bytes[] memory calldatas,\n bytes32 descriptionHash\n ) internal virtual override {\n _timelock.executeBatch{value: msg.value}(targets, values, calldatas, 0, descriptionHash);\n }\n\n /**\n * @dev Overriden version of the {Governor-_cancel} function to cancel the timelocked proposal if it as already\n * been queued.\n */\n function _cancel(\n address[] memory targets,\n uint256[] memory values,\n bytes[] memory calldatas,\n bytes32 descriptionHash\n ) internal virtual override returns (uint256) {\n uint256 proposalId = super._cancel(targets, values, calldatas, descriptionHash);\n\n if (_timelockIds[proposalId] != 0) {\n _timelock.cancel(_timelockIds[proposalId]);\n delete _timelockIds[proposalId];\n }\n\n return proposalId;\n }\n\n /**\n * @dev Address through which the governor executes action. In this case, the timelock.\n */\n function _executor() internal view virtual override returns (address) {\n return address(_timelock);\n }\n\n /**\n * @dev Public endpoint to update the underlying timelock instance. Restricted to the timelock itself, so updates\n * must be proposed, scheduled, and executed through governance proposals.\n *\n * CAUTION: It is not recommended to change the timelock while there are other queued governance proposals.\n */\n function updateTimelock(TimelockController newTimelock) external virtual onlyGovernance {\n _updateTimelock(newTimelock);\n }\n\n function _updateTimelock(TimelockController newTimelock) private {\n emit TimelockChange(address(_timelock), address(newTimelock));\n _timelock = newTimelock;\n }\n}\n"
},
"@openzeppelin/contracts/governance/extensions/GovernorVotesQuorumFraction.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (governance/extensions/GovernorVotesQuorumFraction.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./GovernorVotes.sol\";\n\n/**\n * @dev Extension of {Governor} for voting weight extraction from an {ERC20Votes} token and a quorum expressed as a\n * fraction of the total supply.\n *\n * _Available since v4.3._\n */\nabstract contract GovernorVotesQuorumFraction is GovernorVotes {\n uint256 private _quorumNumerator;\n\n event QuorumNumeratorUpdated(uint256 oldQuorumNumerator, uint256 newQuorumNumerator);\n\n /**\n * @dev Initialize quorum as a fraction of the token's total supply.\n *\n * The fraction is specified as `numerator / denominator`. By default the denominator is 100, so quorum is\n * specified as a percent: a numerator of 10 corresponds to quorum being 10% of total supply. The denominator can be\n * customized by overriding {quorumDenominator}.\n */\n constructor(uint256 quorumNumeratorValue) {\n _updateQuorumNumerator(quorumNumeratorValue);\n }\n\n /**\n * @dev Returns the current quorum numerator. See {quorumDenominator}.\n */\n function quorumNumerator() public view virtual returns (uint256) {\n return _quorumNumerator;\n }\n\n /**\n * @dev Returns the quorum denominator. Defaults to 100, but may be overridden.\n */\n function quorumDenominator() public view virtual returns (uint256) {\n return 100;\n }\n\n /**\n * @dev Returns the quorum for a block number, in terms of number of votes: `supply * numerator / denominator`.\n */\n function quorum(uint256 blockNumber) public view virtual override returns (uint256) {\n return (token.getPastTotalSupply(blockNumber) * quorumNumerator()) / quorumDenominator();\n }\n\n /**\n * @dev Changes the quorum numerator.\n *\n * Emits a {QuorumNumeratorUpdated} event.\n *\n * Requirements:\n *\n * - Must be called through a governance proposal.\n * - New numerator must be smaller or equal to the denominator.\n */\n function updateQuorumNumerator(uint256 newQuorumNumerator) external virtual onlyGovernance {\n _updateQuorumNumerator(newQuorumNumerator);\n }\n\n /**\n * @dev Changes the quorum numerator.\n *\n * Emits a {QuorumNumeratorUpdated} event.\n *\n * Requirements:\n *\n * - New numerator must be smaller or equal to the denominator.\n */\n function _updateQuorumNumerator(uint256 newQuorumNumerator) internal virtual {\n require(\n newQuorumNumerator <= quorumDenominator(),\n \"GovernorVotesQuorumFraction: quorumNumerator over quorumDenominator\"\n );\n\n uint256 oldQuorumNumerator = _quorumNumerator;\n _quorumNumerator = newQuorumNumerator;\n\n emit QuorumNumeratorUpdated(oldQuorumNumerator, newQuorumNumerator);\n }\n}\n"
},
"@openzeppelin/contracts/governance/extensions/GovernorVotes.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (governance/extensions/GovernorVotes.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../Governor.sol\";\nimport \"../utils/IVotes.sol\";\n\n/**\n * @dev Extension of {Governor} for voting weight extraction from an {ERC20Votes} token, or since v4.5 an {ERC721Votes} token.\n *\n * _Available since v4.3._\n */\nabstract contract GovernorVotes is Governor {\n IVotes public immutable token;\n\n constructor(IVotes tokenAddress) {\n token = tokenAddress;\n }\n\n /**\n * Read the voting weight from the token's built in snapshot mechanism (see {IGovernor-getVotes}).\n */\n function getVotes(address account, uint256 blockNumber) public view virtual override returns (uint256) {\n return token.getPastVotes(account, blockNumber);\n }\n}\n"
},
"@openzeppelin/contracts/governance/compatibility/GovernorCompatibilityBravo.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (governance/compatibility/GovernorCompatibilityBravo.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../../utils/Counters.sol\";\nimport \"../../utils/math/SafeCast.sol\";\nimport \"../extensions/IGovernorTimelock.sol\";\nimport \"../Governor.sol\";\nimport \"./IGovernorCompatibilityBravo.sol\";\n\n/**\n * @dev Compatibility layer that implements GovernorBravo compatibility on to of {Governor}.\n *\n * This compatibility layer includes a voting system and requires a {IGovernorTimelock} compatible module to be added\n * through inheritance. It does not include token bindings, not does it include any variable upgrade patterns.\n *\n * NOTE: When using this module, you may need to enable the Solidity optimizer to avoid hitting the contract size limit.\n *\n * _Available since v4.3._\n */\nabstract contract GovernorCompatibilityBravo is IGovernorTimelock, IGovernorCompatibilityBravo, Governor {\n using Counters for Counters.Counter;\n using Timers for Timers.BlockNumber;\n\n enum VoteType {\n Against,\n For,\n Abstain\n }\n\n struct ProposalDetails {\n address proposer;\n address[] targets;\n uint256[] values;\n string[] signatures;\n bytes[] calldatas;\n uint256 forVotes;\n uint256 againstVotes;\n uint256 abstainVotes;\n mapping(address => Receipt) receipts;\n bytes32 descriptionHash;\n }\n\n mapping(uint256 => ProposalDetails) private _proposalDetails;\n\n // solhint-disable-next-line func-name-mixedcase\n function COUNTING_MODE() public pure virtual override returns (string memory) {\n return \"support=bravo&quorum=bravo\";\n }\n\n // ============================================== Proposal lifecycle ==============================================\n /**\n * @dev See {IGovernor-propose}.\n */\n function propose(\n address[] memory targets,\n uint256[] memory values,\n bytes[] memory calldatas,\n string memory description\n ) public virtual override(IGovernor, Governor) returns (uint256) {\n _storeProposal(_msgSender(), targets, values, new string[](calldatas.length), calldatas, description);\n return super.propose(targets, values, calldatas, description);\n }\n\n /**\n * @dev See {IGovernorCompatibilityBravo-propose}.\n */\n function propose(\n address[] memory targets,\n uint256[] memory values,\n string[] memory signatures,\n bytes[] memory calldatas,\n string memory description\n ) public virtual override returns (uint256) {\n _storeProposal(_msgSender(), targets, values, signatures, calldatas, description);\n return propose(targets, values, _encodeCalldata(signatures, calldatas), description);\n }\n\n /**\n * @dev See {IGovernorCompatibilityBravo-queue}.\n */\n function queue(uint256 proposalId) public virtual override {\n ProposalDetails storage details = _proposalDetails[proposalId];\n queue(\n details.targets,\n details.values,\n _encodeCalldata(details.signatures, details.calldatas),\n details.descriptionHash\n );\n }\n\n /**\n * @dev See {IGovernorCompatibilityBravo-execute}.\n */\n function execute(uint256 proposalId) public payable virtual override {\n ProposalDetails storage details = _proposalDetails[proposalId];\n execute(\n details.targets,\n details.values,\n _encodeCalldata(details.signatures, details.calldatas),\n details.descriptionHash\n );\n }\n\n function cancel(uint256 proposalId) public virtual override {\n ProposalDetails storage details = _proposalDetails[proposalId];\n\n require(\n _msgSender() == details.proposer || getVotes(details.proposer, block.number - 1) < proposalThreshold(),\n \"GovernorBravo: proposer above threshold\"\n );\n\n _cancel(\n details.targets,\n details.values,\n _encodeCalldata(details.signatures, details.calldatas),\n details.descriptionHash\n );\n }\n\n /**\n * @dev Encodes calldatas with optional function signature.\n */\n function _encodeCalldata(string[] memory signatures, bytes[] memory calldatas)\n private\n pure\n returns (bytes[] memory)\n {\n bytes[] memory fullcalldatas = new bytes[](calldatas.length);\n\n for (uint256 i = 0; i < signatures.length; ++i) {\n fullcalldatas[i] = bytes(signatures[i]).length == 0\n ? calldatas[i]\n : abi.encodePacked(bytes4(keccak256(bytes(signatures[i]))), calldatas[i]);\n }\n\n return fullcalldatas;\n }\n\n /**\n * @dev Store proposal metadata for later lookup\n */\n function _storeProposal(\n address proposer,\n address[] memory targets,\n uint256[] memory values,\n string[] memory signatures,\n bytes[] memory calldatas,\n string memory description\n ) private {\n bytes32 descriptionHash = keccak256(bytes(description));\n uint256 proposalId = hashProposal(targets, values, _encodeCalldata(signatures, calldatas), descriptionHash);\n\n ProposalDetails storage details = _proposalDetails[proposalId];\n if (details.descriptionHash == bytes32(0)) {\n details.proposer = proposer;\n details.targets = targets;\n details.values = values;\n details.signatures = signatures;\n details.calldatas = calldatas;\n details.descriptionHash = descriptionHash;\n }\n }\n\n // ==================================================== Views =====================================================\n /**\n * @dev See {IGovernorCompatibilityBravo-proposals}.\n */\n function proposals(uint256 proposalId)\n public\n view\n virtual\n override\n returns (\n uint256 id,\n address proposer,\n uint256 eta,\n uint256 startBlock,\n uint256 endBlock,\n uint256 forVotes,\n uint256 againstVotes,\n uint256 abstainVotes,\n bool canceled,\n bool executed\n )\n {\n id = proposalId;\n eta = proposalEta(proposalId);\n startBlock = proposalSnapshot(proposalId);\n endBlock = proposalDeadline(proposalId);\n\n ProposalDetails storage details = _proposalDetails[proposalId];\n proposer = details.proposer;\n forVotes = details.forVotes;\n againstVotes = details.againstVotes;\n abstainVotes = details.abstainVotes;\n\n ProposalState status = state(proposalId);\n canceled = status == ProposalState.Canceled;\n executed = status == ProposalState.Executed;\n }\n\n /**\n * @dev See {IGovernorCompatibilityBravo-getActions}.\n */\n function getActions(uint256 proposalId)\n public\n view\n virtual\n override\n returns (\n address[] memory targets,\n uint256[] memory values,\n string[] memory signatures,\n bytes[] memory calldatas\n )\n {\n ProposalDetails storage details = _proposalDetails[proposalId];\n return (details.targets, details.values, details.signatures, details.calldatas);\n }\n\n /**\n * @dev See {IGovernorCompatibilityBravo-getReceipt}.\n */\n function getReceipt(uint256 proposalId, address voter) public view virtual override returns (Receipt memory) {\n return _proposalDetails[proposalId].receipts[voter];\n }\n\n /**\n * @dev See {IGovernorCompatibilityBravo-quorumVotes}.\n */\n function quorumVotes() public view virtual override returns (uint256) {\n return quorum(block.number - 1);\n }\n\n // ==================================================== Voting ====================================================\n /**\n * @dev See {IGovernor-hasVoted}.\n */\n function hasVoted(uint256 proposalId, address account) public view virtual override returns (bool) {\n return _proposalDetails[proposalId].receipts[account].hasVoted;\n }\n\n /**\n * @dev See {Governor-_quorumReached}. In this module, only forVotes count toward the quorum.\n */\n function _quorumReached(uint256 proposalId) internal view virtual override returns (bool) {\n ProposalDetails storage details = _proposalDetails[proposalId];\n return quorum(proposalSnapshot(proposalId)) <= details.forVotes;\n }\n\n /**\n * @dev See {Governor-_voteSucceeded}. In this module, the forVotes must be scritly over the againstVotes.\n */\n function _voteSucceeded(uint256 proposalId) internal view virtual override returns (bool) {\n ProposalDetails storage details = _proposalDetails[proposalId];\n return details.forVotes > details.againstVotes;\n }\n\n /**\n * @dev See {Governor-_countVote}. In this module, the support follows Governor Bravo.\n */\n function _countVote(\n uint256 proposalId,\n address account,\n uint8 support,\n uint256 weight\n ) internal virtual override {\n ProposalDetails storage details = _proposalDetails[proposalId];\n Receipt storage receipt = details.receipts[account];\n\n require(!receipt.hasVoted, \"GovernorCompatibilityBravo: vote already cast\");\n receipt.hasVoted = true;\n receipt.support = support;\n receipt.votes = SafeCast.toUint96(weight);\n\n if (support == uint8(VoteType.Against)) {\n details.againstVotes += weight;\n } else if (support == uint8(VoteType.For)) {\n details.forVotes += weight;\n } else if (support == uint8(VoteType.Abstain)) {\n details.abstainVotes += weight;\n } else {\n revert(\"GovernorCompatibilityBravo: invalid vote type\");\n }\n }\n}\n"
},
"@openzeppelin/contracts/governance/extensions/GovernorSettings.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (governance/extensions/GovernorSettings.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../Governor.sol\";\n\n/**\n * @dev Extension of {Governor} for settings updatable through governance.\n *\n * _Available since v4.4._\n */\nabstract contract GovernorSettings is Governor {\n uint256 private _votingDelay;\n uint256 private _votingPeriod;\n uint256 private _proposalThreshold;\n\n event VotingDelaySet(uint256 oldVotingDelay, uint256 newVotingDelay);\n event VotingPeriodSet(uint256 oldVotingPeriod, uint256 newVotingPeriod);\n event ProposalThresholdSet(uint256 oldProposalThreshold, uint256 newProposalThreshold);\n\n /**\n * @dev Initialize the governance parameters.\n */\n constructor(\n uint256 initialVotingDelay,\n uint256 initialVotingPeriod,\n uint256 initialProposalThreshold\n ) {\n _setVotingDelay(initialVotingDelay);\n _setVotingPeriod(initialVotingPeriod);\n _setProposalThreshold(initialProposalThreshold);\n }\n\n /**\n * @dev See {IGovernor-votingDelay}.\n */\n function votingDelay() public view virtual override returns (uint256) {\n return _votingDelay;\n }\n\n /**\n * @dev See {IGovernor-votingPeriod}.\n */\n function votingPeriod() public view virtual override returns (uint256) {\n return _votingPeriod;\n }\n\n /**\n * @dev See {Governor-proposalThreshold}.\n */\n function proposalThreshold() public view virtual override returns (uint256) {\n return _proposalThreshold;\n }\n\n /**\n * @dev Update the voting delay. This operation can only be performed through a governance proposal.\n *\n * Emits a {VotingDelaySet} event.\n */\n function setVotingDelay(uint256 newVotingDelay) public virtual onlyGovernance {\n _setVotingDelay(newVotingDelay);\n }\n\n /**\n * @dev Update the voting period. This operation can only be performed through a governance proposal.\n *\n * Emits a {VotingPeriodSet} event.\n */\n function setVotingPeriod(uint256 newVotingPeriod) public virtual onlyGovernance {\n _setVotingPeriod(newVotingPeriod);\n }\n\n /**\n * @dev Update the proposal threshold. This operation can only be performed through a governance proposal.\n *\n * Emits a {ProposalThresholdSet} event.\n */\n function setProposalThreshold(uint256 newProposalThreshold) public virtual onlyGovernance {\n _setProposalThreshold(newProposalThreshold);\n }\n\n /**\n * @dev Internal setter for the voting delay.\n *\n * Emits a {VotingDelaySet} event.\n */\n function _setVotingDelay(uint256 newVotingDelay) internal virtual {\n emit VotingDelaySet(_votingDelay, newVotingDelay);\n _votingDelay = newVotingDelay;\n }\n\n /**\n * @dev Internal setter for the voting period.\n *\n * Emits a {VotingPeriodSet} event.\n */\n function _setVotingPeriod(uint256 newVotingPeriod) internal virtual {\n // voting period must be at least one block long\n require(newVotingPeriod > 0, \"GovernorSettings: voting period too low\");\n emit VotingPeriodSet(_votingPeriod, newVotingPeriod);\n _votingPeriod = newVotingPeriod;\n }\n\n /**\n * @dev Internal setter for the proposal threshold.\n *\n * Emits a {ProposalThresholdSet} event.\n */\n function _setProposalThreshold(uint256 newProposalThreshold) internal virtual {\n emit ProposalThresholdSet(_proposalThreshold, newProposalThreshold);\n _proposalThreshold = newProposalThreshold;\n }\n}\n"
},
"@openzeppelin/contracts/governance/Governor.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (governance/Governor.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/cryptography/ECDSA.sol\";\nimport \"../utils/cryptography/draft-EIP712.sol\";\nimport \"../utils/introspection/ERC165.sol\";\nimport \"../utils/math/SafeCast.sol\";\nimport \"../utils/Address.sol\";\nimport \"../utils/Context.sol\";\nimport \"../utils/Timers.sol\";\nimport \"./IGovernor.sol\";\n\n/**\n * @dev Core of the governance system, designed to be extended though various modules.\n *\n * This contract is abstract and requires several function to be implemented in various modules:\n *\n * - A counting module must implement {quorum}, {_quorumReached}, {_voteSucceeded} and {_countVote}\n * - A voting module must implement {getVotes}\n * - Additionanly, the {votingPeriod} must also be implemented\n *\n * _Available since v4.3._\n */\nabstract contract Governor is Context, ERC165, EIP712, IGovernor {\n using SafeCast for uint256;\n using Timers for Timers.BlockNumber;\n\n bytes32 public constant BALLOT_TYPEHASH = keccak256(\"Ballot(uint256 proposalId,uint8 support)\");\n\n struct ProposalCore {\n Timers.BlockNumber voteStart;\n Timers.BlockNumber voteEnd;\n bool executed;\n bool canceled;\n }\n\n string private _name;\n\n mapping(uint256 => ProposalCore) private _proposals;\n\n /**\n * @dev Restrict access of functions to the governance executor, which may be the Governor itself or a timelock\n * contract, as specified by {_executor}. This generally means that function with this modifier must be voted on and\n * executed through the governance protocol.\n */\n modifier onlyGovernance() {\n require(_msgSender() == _executor(), \"Governor: onlyGovernance\");\n _;\n }\n\n /**\n * @dev Sets the value for {name} and {version}\n */\n constructor(string memory name_) EIP712(name_, version()) {\n _name = name_;\n }\n\n /**\n * @dev Function to receive ETH that will be handled by the governor (disabled if executor is a third party contract)\n */\n receive() external payable virtual {\n require(_executor() == address(this));\n }\n\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC165) returns (bool) {\n return interfaceId == type(IGovernor).interfaceId || super.supportsInterface(interfaceId);\n }\n\n /**\n * @dev See {IGovernor-name}.\n */\n function name() public view virtual override returns (string memory) {\n return _name;\n }\n\n /**\n * @dev See {IGovernor-version}.\n */\n function version() public view virtual override returns (string memory) {\n return \"1\";\n }\n\n /**\n * @dev See {IGovernor-hashProposal}.\n *\n * The proposal id is produced by hashing the RLC encoded `targets` array, the `values` array, the `calldatas` array\n * and the descriptionHash (bytes32 which itself is the keccak256 hash of the description string). This proposal id\n * can be produced from the proposal data which is part of the {ProposalCreated} event. It can even be computed in\n * advance, before the proposal is submitted.\n *\n * Note that the chainId and the governor address are not part of the proposal id computation. Consequently, the\n * same proposal (with same operation and same description) will have the same id if submitted on multiple governors\n * accross multiple networks. This also means that in order to execute the same operation twice (on the same\n * governor) the proposer will have to change the description in order to avoid proposal id conflicts.\n */\n function hashProposal(\n address[] memory targets,\n uint256[] memory values,\n bytes[] memory calldatas,\n bytes32 descriptionHash\n ) public pure virtual override returns (uint256) {\n return uint256(keccak256(abi.encode(targets, values, calldatas, descriptionHash)));\n }\n\n /**\n * @dev See {IGovernor-state}.\n */\n function state(uint256 proposalId) public view virtual override returns (ProposalState) {\n ProposalCore storage proposal = _proposals[proposalId];\n\n if (proposal.executed) {\n return ProposalState.Executed;\n }\n\n if (proposal.canceled) {\n return ProposalState.Canceled;\n }\n\n uint256 snapshot = proposalSnapshot(proposalId);\n\n if (snapshot == 0) {\n revert(\"Governor: unknown proposal id\");\n }\n\n if (snapshot >= block.number) {\n return ProposalState.Pending;\n }\n\n uint256 deadline = proposalDeadline(proposalId);\n\n if (deadline >= block.number) {\n return ProposalState.Active;\n }\n\n if (_quorumReached(proposalId) && _voteSucceeded(proposalId)) {\n return ProposalState.Succeeded;\n } else {\n return ProposalState.Defeated;\n }\n }\n\n /**\n * @dev See {IGovernor-proposalSnapshot}.\n */\n function proposalSnapshot(uint256 proposalId) public view virtual override returns (uint256) {\n return _proposals[proposalId].voteStart.getDeadline();\n }\n\n /**\n * @dev See {IGovernor-proposalDeadline}.\n */\n function proposalDeadline(uint256 proposalId) public view virtual override returns (uint256) {\n return _proposals[proposalId].voteEnd.getDeadline();\n }\n\n /**\n * @dev Part of the Governor Bravo's interface: _\"The number of votes required in order for a voter to become a proposer\"_.\n */\n function proposalThreshold() public view virtual returns (uint256) {\n return 0;\n }\n\n /**\n * @dev Amount of votes already cast passes the threshold limit.\n */\n function _quorumReached(uint256 proposalId) internal view virtual returns (bool);\n\n /**\n * @dev Is the proposal successful or not.\n */\n function _voteSucceeded(uint256 proposalId) internal view virtual returns (bool);\n\n /**\n * @dev Register a vote with a given support and voting weight.\n *\n * Note: Support is generic and can represent various things depending on the voting system used.\n */\n function _countVote(\n uint256 proposalId,\n address account,\n uint8 support,\n uint256 weight\n ) internal virtual;\n\n /**\n * @dev See {IGovernor-propose}.\n */\n function propose(\n address[] memory targets,\n uint256[] memory values,\n bytes[] memory calldatas,\n string memory description\n ) public virtual override returns (uint256) {\n require(\n getVotes(msg.sender, block.number - 1) >= proposalThreshold(),\n \"GovernorCompatibilityBravo: proposer votes below proposal threshold\"\n );\n\n uint256 proposalId = hashProposal(targets, values, calldatas, keccak256(bytes(description)));\n\n require(targets.length == values.length, \"Governor: invalid proposal length\");\n require(targets.length == calldatas.length, \"Governor: invalid proposal length\");\n require(targets.length > 0, \"Governor: empty proposal\");\n\n ProposalCore storage proposal = _proposals[proposalId];\n require(proposal.voteStart.isUnset(), \"Governor: proposal already exists\");\n\n uint64 snapshot = block.number.toUint64() + votingDelay().toUint64();\n uint64 deadline = snapshot + votingPeriod().toUint64();\n\n proposal.voteStart.setDeadline(snapshot);\n proposal.voteEnd.setDeadline(deadline);\n\n emit ProposalCreated(\n proposalId,\n _msgSender(),\n targets,\n values,\n new string[](targets.length),\n calldatas,\n snapshot,\n deadline,\n description\n );\n\n return proposalId;\n }\n\n /**\n * @dev See {IGovernor-execute}.\n */\n function execute(\n address[] memory targets,\n uint256[] memory values,\n bytes[] memory calldatas,\n bytes32 descriptionHash\n ) public payable virtual override returns (uint256) {\n uint256 proposalId = hashProposal(targets, values, calldatas, descriptionHash);\n\n ProposalState status = state(proposalId);\n require(\n status == ProposalState.Succeeded || status == ProposalState.Queued,\n \"Governor: proposal not successful\"\n );\n _proposals[proposalId].executed = true;\n\n emit ProposalExecuted(proposalId);\n\n _execute(proposalId, targets, values, calldatas, descriptionHash);\n\n return proposalId;\n }\n\n /**\n * @dev Internal execution mechanism. Can be overriden to implement different execution mechanism\n */\n function _execute(\n uint256, /* proposalId */\n address[] memory targets,\n uint256[] memory values,\n bytes[] memory calldatas,\n bytes32 /*descriptionHash*/\n ) internal virtual {\n string memory errorMessage = \"Governor: call reverted without message\";\n for (uint256 i = 0; i < targets.length; ++i) {\n (bool success, bytes memory returndata) = targets[i].call{value: values[i]}(calldatas[i]);\n Address.verifyCallResult(success, returndata, errorMessage);\n }\n }\n\n /**\n * @dev Internal cancel mechanism: locks up the proposal timer, preventing it from being re-submitted. Marks it as\n * canceled to allow distinguishing it from executed proposals.\n *\n * Emits a {IGovernor-ProposalCanceled} event.\n */\n function _cancel(\n address[] memory targets,\n uint256[] memory values,\n bytes[] memory calldatas,\n bytes32 descriptionHash\n ) internal virtual returns (uint256) {\n uint256 proposalId = hashProposal(targets, values, calldatas, descriptionHash);\n ProposalState status = state(proposalId);\n\n require(\n status != ProposalState.Canceled && status != ProposalState.Expired && status != ProposalState.Executed,\n \"Governor: proposal not active\"\n );\n _proposals[proposalId].canceled = true;\n\n emit ProposalCanceled(proposalId);\n\n return proposalId;\n }\n\n /**\n * @dev See {IGovernor-castVote}.\n */\n function castVote(uint256 proposalId, uint8 support) public virtual override returns (uint256) {\n address voter = _msgSender();\n return _castVote(proposalId, voter, support, \"\");\n }\n\n /**\n * @dev See {IGovernor-castVoteWithReason}.\n */\n function castVoteWithReason(\n uint256 proposalId,\n uint8 support,\n string calldata reason\n ) public virtual override returns (uint256) {\n address voter = _msgSender();\n return _castVote(proposalId, voter, support, reason);\n }\n\n /**\n * @dev See {IGovernor-castVoteBySig}.\n */\n function castVoteBySig(\n uint256 proposalId,\n uint8 support,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) public virtual override returns (uint256) {\n address voter = ECDSA.recover(\n _hashTypedDataV4(keccak256(abi.encode(BALLOT_TYPEHASH, proposalId, support))),\n v,\n r,\n s\n );\n return _castVote(proposalId, voter, support, \"\");\n }\n\n /**\n * @dev Internal vote casting mechanism: Check that the vote is pending, that it has not been cast yet, retrieve\n * voting weight using {IGovernor-getVotes} and call the {_countVote} internal function.\n *\n * Emits a {IGovernor-VoteCast} event.\n */\n function _castVote(\n uint256 proposalId,\n address account,\n uint8 support,\n string memory reason\n ) internal virtual returns (uint256) {\n ProposalCore storage proposal = _proposals[proposalId];\n require(state(proposalId) == ProposalState.Active, \"Governor: vote not currently active\");\n\n uint256 weight = getVotes(account, proposal.voteStart.getDeadline());\n _countVote(proposalId, account, support, weight);\n\n emit VoteCast(account, proposalId, support, weight, reason);\n\n return weight;\n }\n\n /**\n * @dev Relays a transaction or function call to an arbitrary target. In cases where the governance executor\n * is some contract other than the governor itself, like when using a timelock, this function can be invoked\n * in a governance proposal to recover tokens or Ether that was sent to the governor contract by mistake.\n * Note that if the executor is simply the governor itself, use of `relay` is redundant.\n */\n function relay(\n address target,\n uint256 value,\n bytes calldata data\n ) external virtual onlyGovernance {\n Address.functionCallWithValue(target, data, value);\n }\n\n /**\n * @dev Address through which the governor executes action. Will be overloaded by module that execute actions\n * through another contract such as a timelock.\n */\n function _executor() internal view virtual returns (address) {\n return address(this);\n }\n}\n"
},
"@openzeppelin/contracts/governance/utils/IVotes.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (governance/utils/IVotes.sol)\npragma solidity ^0.8.0;\n\n/**\n * @dev Common interface for {ERC20Votes}, {ERC721Votes}, and other {Votes}-enabled contracts.\n *\n * _Available since v4.5._\n */\ninterface IVotes {\n /**\n * @dev Emitted when an account changes their delegate.\n */\n event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);\n\n /**\n * @dev Emitted when a token transfer or delegate change results in changes to a delegate's number of votes.\n */\n event DelegateVotesChanged(address indexed delegate, uint256 previousBalance, uint256 newBalance);\n\n /**\n * @dev Returns the current amount of votes that `account` has.\n */\n function getVotes(address account) external view returns (uint256);\n\n /**\n * @dev Returns the amount of votes that `account` had at the end of a past block (`blockNumber`).\n */\n function getPastVotes(address account, uint256 blockNumber) external view returns (uint256);\n\n /**\n * @dev Returns the total supply of votes available at the end of a past block (`blockNumber`).\n *\n * NOTE: This value is the sum of all available votes, which is not necessarily the sum of all delegated votes.\n * Votes that have not been delegated are still part of total supply, even though they would not participate in a\n * vote.\n */\n function getPastTotalSupply(uint256 blockNumber) external view returns (uint256);\n\n /**\n * @dev Returns the delegate that `account` has chosen.\n */\n function delegates(address account) external view returns (address);\n\n /**\n * @dev Delegates votes from the sender to `delegatee`.\n */\n function delegate(address delegatee) external;\n\n /**\n * @dev Delegates votes from signer to `delegatee`.\n */\n function delegateBySig(\n address delegatee,\n uint256 nonce,\n uint256 expiry,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external;\n}\n"
},
"@openzeppelin/contracts/governance/TimelockController.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (governance/TimelockController.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../access/AccessControl.sol\";\n\n/**\n * @dev Contract module which acts as a timelocked controller. When set as the\n * owner of an `Ownable` smart contract, it enforces a timelock on all\n * `onlyOwner` maintenance operations. This gives time for users of the\n * controlled contract to exit before a potentially dangerous maintenance\n * operation is applied.\n *\n * By default, this contract is self administered, meaning administration tasks\n * have to go through the timelock process. The proposer (resp executor) role\n * is in charge of proposing (resp executing) operations. A common use case is\n * to position this {TimelockController} as the owner of a smart contract, with\n * a multisig or a DAO as the sole proposer.\n *\n * _Available since v3.3._\n */\ncontract TimelockController is AccessControl {\n bytes32 public constant TIMELOCK_ADMIN_ROLE = keccak256(\"TIMELOCK_ADMIN_ROLE\");\n bytes32 public constant PROPOSER_ROLE = keccak256(\"PROPOSER_ROLE\");\n bytes32 public constant EXECUTOR_ROLE = keccak256(\"EXECUTOR_ROLE\");\n uint256 internal constant _DONE_TIMESTAMP = uint256(1);\n\n mapping(bytes32 => uint256) private _timestamps;\n uint256 private _minDelay;\n\n /**\n * @dev Emitted when a call is scheduled as part of operation `id`.\n */\n event CallScheduled(\n bytes32 indexed id,\n uint256 indexed index,\n address target,\n uint256 value,\n bytes data,\n bytes32 predecessor,\n uint256 delay\n );\n\n /**\n * @dev Emitted when a call is performed as part of operation `id`.\n */\n event CallExecuted(bytes32 indexed id, uint256 indexed index, address target, uint256 value, bytes data);\n\n /**\n * @dev Emitted when operation `id` is cancelled.\n */\n event Cancelled(bytes32 indexed id);\n\n /**\n * @dev Emitted when the minimum delay for future operations is modified.\n */\n event MinDelayChange(uint256 oldDuration, uint256 newDuration);\n\n /**\n * @dev Initializes the contract with a given `minDelay`.\n */\n constructor(\n uint256 minDelay,\n address[] memory proposers,\n address[] memory executors\n ) {\n _setRoleAdmin(TIMELOCK_ADMIN_ROLE, TIMELOCK_ADMIN_ROLE);\n _setRoleAdmin(PROPOSER_ROLE, TIMELOCK_ADMIN_ROLE);\n _setRoleAdmin(EXECUTOR_ROLE, TIMELOCK_ADMIN_ROLE);\n\n // deployer + self administration\n _setupRole(TIMELOCK_ADMIN_ROLE, _msgSender());\n _setupRole(TIMELOCK_ADMIN_ROLE, address(this));\n\n // register proposers\n for (uint256 i = 0; i < proposers.length; ++i) {\n _setupRole(PROPOSER_ROLE, proposers[i]);\n }\n\n // register executors\n for (uint256 i = 0; i < executors.length; ++i) {\n _setupRole(EXECUTOR_ROLE, executors[i]);\n }\n\n _minDelay = minDelay;\n emit MinDelayChange(0, minDelay);\n }\n\n /**\n * @dev Modifier to make a function callable only by a certain role. In\n * addition to checking the sender's role, `address(0)` 's role is also\n * considered. Granting a role to `address(0)` is equivalent to enabling\n * this role for everyone.\n */\n modifier onlyRoleOrOpenRole(bytes32 role) {\n if (!hasRole(role, address(0))) {\n _checkRole(role, _msgSender());\n }\n _;\n }\n\n /**\n * @dev Contract might receive/hold ETH as part of the maintenance process.\n */\n receive() external payable {}\n\n /**\n * @dev Returns whether an id correspond to a registered operation. This\n * includes both Pending, Ready and Done operations.\n */\n function isOperation(bytes32 id) public view virtual returns (bool pending) {\n return getTimestamp(id) > 0;\n }\n\n /**\n * @dev Returns whether an operation is pending or not.\n */\n function isOperationPending(bytes32 id) public view virtual returns (bool pending) {\n return getTimestamp(id) > _DONE_TIMESTAMP;\n }\n\n /**\n * @dev Returns whether an operation is ready or not.\n */\n function isOperationReady(bytes32 id) public view virtual returns (bool ready) {\n uint256 timestamp = getTimestamp(id);\n return timestamp > _DONE_TIMESTAMP && timestamp <= block.timestamp;\n }\n\n /**\n * @dev Returns whether an operation is done or not.\n */\n function isOperationDone(bytes32 id) public view virtual returns (bool done) {\n return getTimestamp(id) == _DONE_TIMESTAMP;\n }\n\n /**\n * @dev Returns the timestamp at with an operation becomes ready (0 for\n * unset operations, 1 for done operations).\n */\n function getTimestamp(bytes32 id) public view virtual returns (uint256 timestamp) {\n return _timestamps[id];\n }\n\n /**\n * @dev Returns the minimum delay for an operation to become valid.\n *\n * This value can be changed by executing an operation that calls `updateDelay`.\n */\n function getMinDelay() public view v