Skip to content
Lattice

TimelockControllerLib

Git Source

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

NameTypeDescription
$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

NameTypeDescription
minDelayuint256The initial minimum delay for operations.
proposersaddress[]The addresses that will be granted PROPOSER_ROLE and CANCELLER_ROLE.
executorsaddress[]The addresses that will be granted EXECUTOR_ROLE.
Pass address(0) to make execution open to everyone.
adminaddressThe 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

NameTypeDescription
idbytes32

Returns

NameTypeDescription
<none>bool

isOperationPending

Returns whether an operation is pending (Waiting or Ready, but not Done).

function isOperationPending(bytes32 id) internal view returns (bool);

Parameters

NameTypeDescription
idbytes32

Returns

NameTypeDescription
<none>bool

isOperationReady

Returns whether an operation is ready for execution.

function isOperationReady(bytes32 id) internal view returns (bool);

Parameters

NameTypeDescription
idbytes32

Returns

NameTypeDescription
<none>bool

isOperationDone

Returns whether an operation has been executed.

function isOperationDone(bytes32 id) internal view returns (bool);

Parameters

NameTypeDescription
idbytes32

Returns

NameTypeDescription
<none>bool

getOperationState

Returns the state of an operation.

function getOperationState(bytes32 id) internal view returns (ITimelockController.OperationState);

Parameters

NameTypeDescription
idbytes32

Returns

NameTypeDescription
<none>ITimelockController.OperationState

getTimestamp

Returns the timestamp at which an operation becomes ready.

function getTimestamp(bytes32 id) internal view returns (uint256);

Parameters

NameTypeDescription
idbytes32

Returns

NameTypeDescription
<none>uint256

getMinDelay

Returns the minimum delay for operations.

function getMinDelay() internal view returns (uint256);

Returns

NameTypeDescription
<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

NameTypeDescription
targetaddress
valueuint256
databytes
predecessorbytes32
saltbytes32

Returns

NameTypeDescription
<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

NameTypeDescription
targetsaddress[]
valuesuint256[]
payloadsbytes[]
predecessorbytes32
saltbytes32

Returns

NameTypeDescription
<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

NameTypeDescription
targetaddress
valueuint256
databytes
predecessorbytes32
saltbytes32
delayuint256

scheduleBatch

Schedule a batch operation.

function scheduleBatch(
        address[] memory targets,
        uint256[] memory values,
        bytes[] memory payloads,
        bytes32 predecessor,
        bytes32 salt,
        uint256 delay
    ) internal;

Parameters

NameTypeDescription
targetsaddress[]
valuesuint256[]
payloadsbytes[]
predecessorbytes32
saltbytes32
delayuint256

cancel

Cancel a pending operation.

function cancel(bytes32 id) internal;

Parameters

NameTypeDescription
idbytes32

execute

Execute a single-call operation.

function execute(address target, uint256 value, bytes memory payload, bytes32 predecessor, bytes32 salt) internal;

Parameters

NameTypeDescription
targetaddress
valueuint256
payloadbytes
predecessorbytes32
saltbytes32

executeBatch

Execute a batch operation.

function executeBatch(
        address[] memory targets,
        uint256[] memory values,
        bytes[] memory payloads,
        bytes32 predecessor,
        bytes32 salt
    ) internal;

Parameters

NameTypeDescription
targetsaddress[]
valuesuint256[]
payloadsbytes[]
predecessorbytes32
saltbytes32

updateDelay

Update the minimum delay.

Only callable from the timelock contract itself.

function updateDelay(uint256 newDelay) internal;

Parameters

NameTypeDescription
newDelayuint256

_schedule

Internal function to schedule a new operation.

function _schedule(bytes32 id, uint256 delay) internal;

Parameters

NameTypeDescription
idbytes32
delayuint256

_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

NameTypeDescription
idbytes32
predecessorbytes32

_afterCall

Mark operation as done. Reverts if the operation is no longer Ready (re-entrancy guard).

function _afterCall(bytes32 id) private;

Parameters

NameTypeDescription
idbytes32

_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

NameTypeDescription
idbytes32
indexuint256
targetaddress
valueuint256
databytes

_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

NameTypeDescription
rolebytes32

_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

NameTypeDescription
stateITimelockController.OperationState

Returns

NameTypeDescription
<none>bytes32