TimelockControllerLib
Title: TimelockController Library
Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/governance/TimelockController.sol)
A library for scheduling and executing governance actions after a minimum delay.
Implements the OZ v5 TimelockController pattern as a stateless library with ERC-7201 storage. All authentication is performed via AccessControlLib roles that are expected to reside in AccessControlLib's own storage slot.
Constants
PROPOSER_ROLE
Role for proposers — keccak256("PROPOSER_ROLE").
bytes32 internal constant PROPOSER_ROLE = keccak256("PROPOSER_ROLE");EXECUTOR_ROLE
Role for executors — keccak256("EXECUTOR_ROLE").
bytes32 internal constant EXECUTOR_ROLE = keccak256("EXECUTOR_ROLE");CANCELLER_ROLE
Role for cancellers — keccak256("CANCELLER_ROLE").
bytes32 internal constant CANCELLER_ROLE = keccak256("CANCELLER_ROLE");_DONE_TIMESTAMP
Sentinel timestamp value for executed operations.
uint256 internal constant _DONE_TIMESTAMP = 1;Functions
timelockControllerStorage
function timelockControllerStorage() internal pure returns (TimelockControllerStorage storage $);Returns
| Name | Type | Description |
|---|---|---|
| $ | TimelockControllerStorage |
registerInterface
Registers support for the ITimelockController interface via ERC-165.
function registerInterface() internal;__TimelockController_init
Initializes the TimelockController module.
Must be called inside the preInitializer/postInitializer window. AccessControl must already be initialized before calling this function.
function __TimelockController_init(
uint256 minDelay,
address[] memory proposers,
address[] memory executors,
address admin
) internal;Parameters
| Name | Type | Description |
|---|---|---|
| minDelay | uint256 | The initial minimum delay for operations. |
| proposers | address[] | The addresses that will be granted PROPOSER_ROLE and CANCELLER_ROLE. |
| executors | address[] | The addresses that will be granted EXECUTOR_ROLE. Pass address(0) to make execution open to everyone. |
| admin | address | The address to grant DEFAULT_ADMIN_ROLE to. If zero, no admin is set. |
isOperation
Returns whether an id corresponds to a registered operation.
function isOperation(bytes32 id) internal view returns (bool);Parameters
| Name | Type | Description |
|---|---|---|
| id | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool |
isOperationPending
Returns whether an operation is pending (Waiting or Ready, but not Done).
function isOperationPending(bytes32 id) internal view returns (bool);Parameters
| Name | Type | Description |
|---|---|---|
| id | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool |
isOperationReady
Returns whether an operation is ready for execution.
function isOperationReady(bytes32 id) internal view returns (bool);Parameters
| Name | Type | Description |
|---|---|---|
| id | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool |
isOperationDone
Returns whether an operation has been executed.
function isOperationDone(bytes32 id) internal view returns (bool);Parameters
| Name | Type | Description |
|---|---|---|
| id | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool |
getOperationState
Returns the state of an operation.
function getOperationState(bytes32 id) internal view returns (ITimelockController.OperationState);Parameters
| Name | Type | Description |
|---|---|---|
| id | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | ITimelockController.OperationState |
getTimestamp
Returns the timestamp at which an operation becomes ready.
function getTimestamp(bytes32 id) internal view returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| id | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
getMinDelay
Returns the minimum delay for operations.
function getMinDelay() internal view returns (uint256);Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
hashOperation
Returns the operation id for a single-call operation.
function hashOperation(address target, uint256 value, bytes memory data, bytes32 predecessor, bytes32 salt)
internal
pure
returns (bytes32);Parameters
| Name | Type | Description |
|---|---|---|
| target | address | |
| value | uint256 | |
| data | bytes | |
| predecessor | bytes32 | |
| salt | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bytes32 |
hashOperationBatch
Returns the operation id for a batch operation.
function hashOperationBatch(
address[] memory targets,
uint256[] memory values,
bytes[] memory payloads,
bytes32 predecessor,
bytes32 salt
) internal pure returns (bytes32);Parameters
| Name | Type | Description |
|---|---|---|
| targets | address[] | |
| values | uint256[] | |
| payloads | bytes[] | |
| predecessor | bytes32 | |
| salt | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bytes32 |
schedule
Schedule a single-call operation.
function schedule(
address target,
uint256 value,
bytes memory data,
bytes32 predecessor,
bytes32 salt,
uint256 delay
) internal;Parameters
| Name | Type | Description |
|---|---|---|
| target | address | |
| value | uint256 | |
| data | bytes | |
| predecessor | bytes32 | |
| salt | bytes32 | |
| delay | uint256 |
scheduleBatch
Schedule a batch operation.
function scheduleBatch(
address[] memory targets,
uint256[] memory values,
bytes[] memory payloads,
bytes32 predecessor,
bytes32 salt,
uint256 delay
) internal;Parameters
| Name | Type | Description |
|---|---|---|
| targets | address[] | |
| values | uint256[] | |
| payloads | bytes[] | |
| predecessor | bytes32 | |
| salt | bytes32 | |
| delay | uint256 |
cancel
Cancel a pending operation.
function cancel(bytes32 id) internal;Parameters
| Name | Type | Description |
|---|---|---|
| id | bytes32 |
execute
Execute a single-call operation.
function execute(address target, uint256 value, bytes memory payload, bytes32 predecessor, bytes32 salt) internal;Parameters
| Name | Type | Description |
|---|---|---|
| target | address | |
| value | uint256 | |
| payload | bytes | |
| predecessor | bytes32 | |
| salt | bytes32 |
executeBatch
Execute a batch operation.
function executeBatch(
address[] memory targets,
uint256[] memory values,
bytes[] memory payloads,
bytes32 predecessor,
bytes32 salt
) internal;Parameters
| Name | Type | Description |
|---|---|---|
| targets | address[] | |
| values | uint256[] | |
| payloads | bytes[] | |
| predecessor | bytes32 | |
| salt | bytes32 |
updateDelay
Update the minimum delay.
Only callable from the timelock contract itself.
function updateDelay(uint256 newDelay) internal;Parameters
| Name | Type | Description |
|---|---|---|
| newDelay | uint256 |
_schedule
Internal function to schedule a new operation.
function _schedule(bytes32 id, uint256 delay) internal;Parameters
| Name | Type | Description |
|---|---|---|
| id | bytes32 | |
| delay | uint256 |
_beforeCall
Check that id is ready, is not the operation of an Expired proposal queued by a Governor in the same diamond, and that its predecessor (if any) is done. Reverts otherwise.
function _beforeCall(bytes32 id, bytes32 predecessor) private view;Parameters
| Name | Type | Description |
|---|---|---|
| id | bytes32 | |
| predecessor | bytes32 |
_afterCall
Mark operation as done. Reverts if the operation is no longer Ready (re-entrancy guard).
function _afterCall(bytes32 id) private;Parameters
| Name | Type | Description |
|---|---|---|
| id | bytes32 |
_executeCall
Execute a single low-level call and emit CallExecuted. Reverts on failure.
function _executeCall(bytes32 id, uint256 index, address target, uint256 value, bytes memory data) internal;Parameters
| Name | Type | Description |
|---|---|---|
| id | bytes32 | |
| index | uint256 | |
| target | address | |
| value | uint256 | |
| data | bytes |
_onlyRoleOrOpenRole
Allow access if caller has the role OR if the role is granted to address(0) (open role).
function _onlyRoleOrOpenRole(bytes32 role) internal view;Parameters
| Name | Type | Description |
|---|---|---|
| role | bytes32 |
_encodeStateBitmap
Encode a single OperationState as a single-bit bitmap for use in error reporting.
function _encodeStateBitmap(ITimelockController.OperationState state) internal pure returns (bytes32);Parameters
| Name | Type | Description |
|---|---|---|
| state | ITimelockController.OperationState |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bytes32 |