Signed-off-by: Hadrien Croubois <hadrien.croubois@gmail.com> Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com> Co-authored-by: Francisco Giordano <fg@frang.io> Co-authored-by: Joseph Delong <joseph@delong.me> Co-authored-by: Arr00 <13561405+arr00@users.noreply.github.com> Co-authored-by: Renan Souza <renan.rodrigues.souza1@gmail.com> Co-authored-by: Ernesto García <ernestognw@gmail.com> Co-authored-by: Voronor <129545215+voronor@users.noreply.github.com> Co-authored-by: StackOverflowExcept1on <109800286+StackOverflowExcept1on@users.noreply.github.com> Co-authored-by: Michalis Kargakis <kargakis@protonmail.com> Co-authored-by: Bilog WEB3 <155262265+Bilogweb3@users.noreply.github.com> Co-authored-by: Fallengirl <155266340+Fallengirl@users.noreply.github.com> Co-authored-by: XxAlex74xX <30472093+XxAlex74xX@users.noreply.github.com> Co-authored-by: PixelPilot <161360836+PixelPil0t1@users.noreply.github.com> Co-authored-by: kilavvy <140459108+kilavvy@users.noreply.github.com> Co-authored-by: Devkuni <155117116+detrina@users.noreply.github.com> Co-authored-by: Danbo <140512416+dannbbb1@users.noreply.github.com> Co-authored-by: Ann Wagner <chant_77_swirly@icloud.com> Co-authored-by: comfsrt <155266597+comfsrt@users.noreply.github.com> Co-authored-by: Bob <158583129+bouchmann@users.noreply.github.com> Co-authored-by: JohnBonny <158583902+JohnBonny@users.noreply.github.com> Co-authored-by: moonman <155266991+moooonman@users.noreply.github.com> Co-authored-by: kazak <alright-epsilon8h@icloud.com> Co-authored-by: Wei <ybxerlvqtx@rambler.ru> Co-authored-by: Maxim Evtush <154841002+maximevtush@users.noreply.github.com> Co-authored-by: Vitalyr <158586577+Vitaliyr888@users.noreply.github.com> Co-authored-by: pendrue <158588659+pendrue@users.noreply.github.com> Co-authored-by: Tronica <wudmytrotest404@gmail.com> Co-authored-by: emmmm <155267286+eeemmmmmm@users.noreply.github.com> Co-authored-by: bigbear <155267841+aso20455@users.noreply.github.com> Co-authored-by: Tomás Andróil <tomasandroil@gmail.com> Co-authored-by: GooseMatrix <155266802+GooseMatrix@users.noreply.github.com> Co-authored-by: jasmy <3776356370@qq.com> Co-authored-by: SITADRITA1 <mrlime2018@gmail.com> Co-authored-by: Ocenka <testoviydiman1@gmail.com>
126 lines
4.1 KiB
Solidity
126 lines
4.1 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
// OpenZeppelin Contracts (last updated v5.3.0) (governance/extensions/GovernorStorage.sol)
|
|
|
|
pragma solidity ^0.8.20;
|
|
|
|
import {Governor} from "../Governor.sol";
|
|
|
|
/**
|
|
* @dev Extension of {Governor} that implements storage of proposal details. This modules also provides primitives for
|
|
* the enumerability of proposals.
|
|
*
|
|
* Use cases for this module include:
|
|
* - UIs that explore the proposal state without relying on event indexing.
|
|
* - Using only the proposalId as an argument in the {Governor-queue} and {Governor-execute} functions for L2 chains
|
|
* where storage is cheap compared to calldata.
|
|
*/
|
|
abstract contract GovernorStorage is Governor {
|
|
struct ProposalDetails {
|
|
address[] targets;
|
|
uint256[] values;
|
|
bytes[] calldatas;
|
|
bytes32 descriptionHash;
|
|
}
|
|
|
|
uint256[] private _proposalIds;
|
|
mapping(uint256 proposalId => ProposalDetails) private _proposalDetails;
|
|
|
|
/**
|
|
* @dev Hook into the proposing mechanism
|
|
*/
|
|
function _propose(
|
|
address[] memory targets,
|
|
uint256[] memory values,
|
|
bytes[] memory calldatas,
|
|
string memory description,
|
|
address proposer
|
|
) internal virtual override returns (uint256) {
|
|
uint256 proposalId = super._propose(targets, values, calldatas, description, proposer);
|
|
|
|
// store
|
|
_proposalIds.push(proposalId);
|
|
_proposalDetails[proposalId] = ProposalDetails({
|
|
targets: targets,
|
|
values: values,
|
|
calldatas: calldatas,
|
|
descriptionHash: keccak256(bytes(description))
|
|
});
|
|
|
|
return proposalId;
|
|
}
|
|
|
|
/**
|
|
* @dev Version of {IGovernor-queue} with only `proposalId` as an argument.
|
|
*/
|
|
function queue(uint256 proposalId) public virtual {
|
|
// here, using storage is more efficient than memory
|
|
ProposalDetails storage details = _proposalDetails[proposalId];
|
|
queue(details.targets, details.values, details.calldatas, details.descriptionHash);
|
|
}
|
|
|
|
/**
|
|
* @dev Version of {IGovernor-execute} with only `proposalId` as an argument.
|
|
*/
|
|
function execute(uint256 proposalId) public payable virtual {
|
|
// here, using storage is more efficient than memory
|
|
ProposalDetails storage details = _proposalDetails[proposalId];
|
|
execute(details.targets, details.values, details.calldatas, details.descriptionHash);
|
|
}
|
|
|
|
/**
|
|
* @dev ProposalId version of {IGovernor-cancel}.
|
|
*/
|
|
function cancel(uint256 proposalId) public virtual {
|
|
// here, using storage is more efficient than memory
|
|
ProposalDetails storage details = _proposalDetails[proposalId];
|
|
cancel(details.targets, details.values, details.calldatas, details.descriptionHash);
|
|
}
|
|
|
|
/**
|
|
* @dev Returns the number of stored proposals.
|
|
*/
|
|
function proposalCount() public view virtual returns (uint256) {
|
|
return _proposalIds.length;
|
|
}
|
|
|
|
/**
|
|
* @dev Returns the details of a proposalId. Reverts if `proposalId` is not a known proposal.
|
|
*/
|
|
function proposalDetails(
|
|
uint256 proposalId
|
|
)
|
|
public
|
|
view
|
|
virtual
|
|
returns (address[] memory targets, uint256[] memory values, bytes[] memory calldatas, bytes32 descriptionHash)
|
|
{
|
|
// here, using memory is more efficient than storage
|
|
ProposalDetails memory details = _proposalDetails[proposalId];
|
|
if (details.descriptionHash == 0) {
|
|
revert GovernorNonexistentProposal(proposalId);
|
|
}
|
|
return (details.targets, details.values, details.calldatas, details.descriptionHash);
|
|
}
|
|
|
|
/**
|
|
* @dev Returns the details (including the proposalId) of a proposal given its sequential index.
|
|
*/
|
|
function proposalDetailsAt(
|
|
uint256 index
|
|
)
|
|
public
|
|
view
|
|
virtual
|
|
returns (
|
|
uint256 proposalId,
|
|
address[] memory targets,
|
|
uint256[] memory values,
|
|
bytes[] memory calldatas,
|
|
bytes32 descriptionHash
|
|
)
|
|
{
|
|
proposalId = _proposalIds[index];
|
|
(targets, values, calldatas, descriptionHash) = proposalDetails(proposalId);
|
|
}
|
|
}
|