-
Notifications
You must be signed in to change notification settings - Fork 28
Add TimelockControllerEnumerable
#214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aviggiano
wants to merge
30
commits into
OpenZeppelin:master
Choose a base branch
from
aviggiano:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
91c8d32
Fix https://github.com/OpenZeppelin/openzeppelin-community-contracts/…
aviggiano d715512
Improve NatSpec
aviggiano a0144bf
Update tests
aviggiano f52ccdd
Update docs
aviggiano cc6c8ec
Update docs
aviggiano 4202f5b
Update contracts/governance/TimelockControllerEnumerable.sol
aviggiano 03ba004
Update contracts/governance/TimelockControllerEnumerable.sol
aviggiano 06db9b1
Update contracts/governance/TimelockControllerEnumerable.sol
aviggiano 1de67ee
Update contracts/governance/TimelockControllerEnumerable.sol
aviggiano 2c4c809
Update contracts/governance/TimelockControllerEnumerable.sol
aviggiano 31a68c9
Update contracts/governance/TimelockControllerEnumerable.sol
aviggiano d82ab45
Update contracts/governance/TimelockControllerEnumerable.sol
aviggiano 370e71f
Update contracts/governance/TimelockControllerEnumerable.sol
aviggiano 5e25a62
Update contracts/governance/TimelockControllerEnumerable.sol
aviggiano 4a2fa88
Update contracts/governance/TimelockControllerEnumerable.sol
aviggiano d8c165e
Update contracts/governance/TimelockControllerEnumerable.sol
aviggiano 79d5df3
Update contracts/governance/TimelockControllerEnumerable.sol
aviggiano 6bdb6a5
Update contracts/governance/TimelockControllerEnumerable.sol
aviggiano a77ba8e
Update contracts/governance/TimelockControllerEnumerable.sol
aviggiano a53e607
Update contracts/governance/TimelockControllerEnumerable.sol
aviggiano 9469bbb
Update contracts/governance/TimelockControllerEnumerable.sol
aviggiano ce6e936
Update contracts/governance/TimelockControllerEnumerable.sol
aviggiano 59cacbb
Update contracts/governance/TimelockControllerEnumerable.sol
aviggiano 6fe8afe
Update contracts/governance/TimelockControllerEnumerable.sol
aviggiano 9e373ca
Update contracts/governance/TimelockControllerEnumerable.sol
aviggiano 857c063
Merge branch 'master' of github.com:OpenZeppelin/openzeppelin-communi…
aviggiano 464e3f8
Merge branch 'master' of github.com:aviggiano/openzeppelin-community-…
aviggiano e47ba01
Add WARNING to operationsBatch
aviggiano 6f13062
Make TimelockControllerEnumerable abstract
aviggiano ede0719
Add range functions
aviggiano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
= Governance | ||
|
||
[.readme-notice] | ||
NOTE: This document is better viewed at https://docs.openzeppelin.com/contracts/api/governance | ||
|
||
This directory includes extensions and utilities for on-chain governance. | ||
|
||
* {TimelockControllerEnumerable}: Extension of OpenZeppelin's TimelockController with enumerable operations support. | ||
|
||
== Timelock | ||
|
||
{{TimelockControllerEnumerable}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import {TimelockController} from "@openzeppelin/contracts/governance/TimelockController.sol"; | ||
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; | ||
|
||
/// @dev Extends the TimelockController to allow for enumerable operations | ||
abstract contract TimelockControllerEnumerable is TimelockController { | ||
using EnumerableSet for EnumerableSet.Bytes32Set; | ||
|
||
/// @notice The operation struct | ||
struct Operation { | ||
address target; | ||
uint256 value; | ||
bytes data; | ||
bytes32 predecessor; | ||
bytes32 salt; | ||
uint256 delay; | ||
} | ||
|
||
/// @notice The operation batch struct | ||
struct OperationBatch { | ||
address[] targets; | ||
uint256[] values; | ||
bytes[] payloads; | ||
bytes32 predecessor; | ||
bytes32 salt; | ||
uint256 delay; | ||
} | ||
|
||
/// @dev The error when the operation index is not found | ||
error OperationIndexNotFound(uint256 index); | ||
/// @dev The error when the operation id is not found | ||
error OperationIdNotFound(bytes32 id); | ||
/// @dev The error when the operation batch index is not found | ||
error OperationBatchIndexNotFound(uint256 index); | ||
/// @dev The error when the operation batch id is not found | ||
error OperationBatchIdNotFound(bytes32 id); | ||
/// @dev The error when the index range is invalid | ||
error InvalidIndexRange(uint256 start, uint256 end); | ||
|
||
/// @notice The operations id set | ||
EnumerableSet.Bytes32Set private _operationsIdSet; | ||
/// @notice The operations map | ||
mapping(bytes32 id => Operation operation) private _operationsMap; | ||
|
||
/// @notice The operations batch id set | ||
EnumerableSet.Bytes32Set private _operationsBatchIdSet; | ||
/// @notice The operations batch map | ||
mapping(bytes32 id => OperationBatch operationBatch) private _operationsBatchMap; | ||
|
||
/// @inheritdoc TimelockController | ||
function schedule( | ||
address target, | ||
uint256 value, | ||
bytes calldata data, | ||
bytes32 predecessor, | ||
bytes32 salt, | ||
uint256 delay | ||
) public virtual override { | ||
super.schedule(target, value, data, predecessor, salt, delay); | ||
bytes32 id = hashOperation(target, value, data, predecessor, salt); | ||
_operationsIdSet.add(id); | ||
_operationsMap[id] = Operation({ | ||
target: target, | ||
value: value, | ||
data: data, | ||
predecessor: predecessor, | ||
salt: salt, | ||
delay: delay | ||
}); | ||
} | ||
|
||
/// @inheritdoc TimelockController | ||
function scheduleBatch( | ||
address[] calldata targets, | ||
uint256[] calldata values, | ||
bytes[] calldata payloads, | ||
bytes32 predecessor, | ||
bytes32 salt, | ||
uint256 delay | ||
) public virtual override { | ||
super.scheduleBatch(targets, values, payloads, predecessor, salt, delay); | ||
bytes32 id = hashOperationBatch(targets, values, payloads, predecessor, salt); | ||
_operationsBatchIdSet.add(id); | ||
_operationsBatchMap[id] = OperationBatch({ | ||
targets: targets, | ||
values: values, | ||
payloads: payloads, | ||
predecessor: predecessor, | ||
salt: salt, | ||
delay: delay | ||
}); | ||
} | ||
|
||
/// @inheritdoc TimelockController | ||
function cancel(bytes32 id) public virtual override { | ||
super.cancel(id); | ||
if (_operationsIdSet.contains(id)) { | ||
_operationsIdSet.remove(id); | ||
delete _operationsMap[id]; | ||
} | ||
if (_operationsBatchIdSet.contains(id)) { | ||
_operationsBatchIdSet.remove(id); | ||
delete _operationsBatchMap[id]; | ||
} | ||
} | ||
|
||
/// @dev Return all scheduled operations | ||
/// WARNING: This is designed for view accessors queried without gas fees. Using it in state-changing | ||
/// functions may become uncallable if the list grows too large. | ||
function operations() public view returns (Operation[] memory operations_) { | ||
aviggiano marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return operations(0, _operationsIdSet.length()); | ||
} | ||
|
||
/// @dev Return the operations in the given index range | ||
/// @param start The start index | ||
/// @param end The end index | ||
/// @return operations_ The operations | ||
/// WARNING: This is designed for view accessors queried without gas fees. Using it in state-changing | ||
/// functions may become uncallable if the list grows too large. | ||
function operations(uint256 start, uint256 end) public view returns (Operation[] memory operations_) { | ||
if (start > end || start >= _operationsIdSet.length()) { | ||
revert InvalidIndexRange(start, end); | ||
} | ||
operations_ = new Operation[](end - start); | ||
for (uint256 i = start; i < end; i++) { | ||
operations_[i] = _operationsMap[_operationsIdSet.at(i)]; | ||
} | ||
return operations_; | ||
} | ||
|
||
/// @dev Return the number of operations from the set | ||
function operationsCount() public view returns (uint256 operationsCount_) { | ||
operationsCount_ = _operationsIdSet.length(); | ||
return operationsCount_; | ||
} | ||
|
||
/// @dev Return the operation at the given index | ||
function operation(uint256 index) public view returns (Operation memory operation_) { | ||
if (index >= _operationsIdSet.length()) { | ||
revert OperationIndexNotFound(index); | ||
} | ||
operation_ = _operationsMap[_operationsIdSet.at(index)]; | ||
return operation_; | ||
} | ||
|
||
/// @dev Return the operation with the given id | ||
function operation(bytes32 id) public view returns (Operation memory operation_) { | ||
if (!_operationsIdSet.contains(id)) { | ||
revert OperationIdNotFound(id); | ||
} | ||
operation_ = _operationsMap[id]; | ||
return operation_; | ||
} | ||
|
||
/// @dev Return all scheduled operation batches | ||
/// WARNING: This is designed for view accessors queried without gas fees. Using it in state-changing | ||
/// functions may become uncallable if the list grows too large. | ||
function operationsBatch() public view returns (OperationBatch[] memory operationsBatch_) { | ||
aviggiano marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return operationsBatch(0, _operationsBatchIdSet.length()); | ||
} | ||
|
||
/// @dev Return the operationsBatch in the given index range | ||
/// @param start The start index | ||
/// @param end The end index | ||
/// @return operationsBatch_ The operationsBatch | ||
/// WARNING: This is designed for view accessors queried without gas fees. Using it in state-changing | ||
/// functions may become uncallable if the list grows too large. | ||
function operationsBatch( | ||
uint256 start, | ||
uint256 end | ||
) public view returns (OperationBatch[] memory operationsBatch_) { | ||
if (start > end || start >= _operationsBatchIdSet.length()) { | ||
revert InvalidIndexRange(start, end); | ||
} | ||
operationsBatch_ = new OperationBatch[](end - start); | ||
for (uint256 i = start; i < end; i++) { | ||
operationsBatch_[i] = _operationsBatchMap[_operationsBatchIdSet.at(i)]; | ||
} | ||
return operationsBatch_; | ||
} | ||
|
||
/// @dev Return the number of operationsBatch from the set | ||
function operationsBatchCount() public view returns (uint256 operationsBatchCount_) { | ||
operationsBatchCount_ = _operationsBatchIdSet.length(); | ||
return operationsBatchCount_; | ||
} | ||
|
||
/// @dev Return the operationsBatch at the given index | ||
function operationBatch(uint256 index) public view returns (OperationBatch memory operationBatch_) { | ||
if (index >= _operationsBatchIdSet.length()) { | ||
revert OperationBatchIndexNotFound(index); | ||
} | ||
operationBatch_ = _operationsBatchMap[_operationsBatchIdSet.at(index)]; | ||
return operationBatch_; | ||
} | ||
|
||
/// @dev Return the operationsBatch with the given id | ||
function operationBatch(bytes32 id) public view returns (OperationBatch memory operationBatch_) { | ||
if (!_operationsBatchIdSet.contains(id)) { | ||
revert OperationBatchIdNotFound(id); | ||
} | ||
operationBatch_ = _operationsBatchMap[id]; | ||
return operationBatch_; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"lib/@openzeppelin-contracts": { | ||
"branch": { | ||
"name": "master", | ||
"rev": "c3961a45380831135b37e55bc3ed441f678a4f5e" | ||
} | ||
}, | ||
"lib/@openzeppelin-contracts-upgradeable": { | ||
"branch": { | ||
"name": "master", | ||
"rev": "87e32858518950ff89c5492b6c81bb3d87cba9e3" | ||
} | ||
}, | ||
"lib/axelar-gmp-sdk-solidity": { | ||
"rev": "00682b6c3db0cc922ec0c4ea3791852c93d7ae31" | ||
}, | ||
"lib/email-tx-builder": { | ||
"rev": "895e1fe943e967b0faab6a476f3b82b37d14300d" | ||
}, | ||
"lib/forge-std": { | ||
"rev": "60acb7aaadcce2d68e52986a0a66fe79f07d138f" | ||
}, | ||
"lib/wormhole-solidity-sdk": { | ||
"rev": "575181b586a315d8f9813eab82e4cb98b45bc381" | ||
}, | ||
"lib/zk-email-verify": { | ||
"branch": { | ||
"name": "v6.3.2", | ||
"rev": "9ed3769dc3d96fb0d7c45f1f014dcd9bfb63675b" | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.