Skip to main content

TimelockQueue

Git Source

Inherits: ITimelockQueue

Title: TimelockQueue

Reusable queue implementation for timelocked actions.

This contract owns the standard queue lifecycle:

  • _queueAction validates queue authorization via _validateQueue, stores action metadata, and emits TimelockActionQueued.
  • executeQueuedAction validates standard executable state, delegates implementation-specific execution authorization to _validateExecution, runs _executeAction, clears the payload, and emits TimelockActionExecuted.
  • cancelQueuedAction validates standard cancellable state, delegates implementation-specific cancellation authorization to _validateCancellation, clears the payload, and emits TimelockActionCancelled. Child contracts must implement the virtual hooks by reverting on failure. Hooks should not return booleans; a successful return means the hook accepted the operation.

State Variables

timelockDelay

Current timelock delay in seconds.

uint48 public timelockDelay

nextActionId

Next queued action ID.

uint64 public nextActionId

_queuedActions

Queued timelock actions.

mapping(uint64 => ITimelockQueue.QueuedAction) internal _queuedActions

Functions

constructor

Initialize the timelock queue.

Calls _validateTimelockDelay. Child implementations should ensure that override does not depend on child constructor-initialized storage.

constructor(uint48 initialTimelockDelay_) ;

Parameters

NameTypeDescription
initialTimelockDelay_uint48Initial timelock delay in seconds.

getQueuedAction

Get a queued action.

Reverts if:

  • The action does not exist
function getQueuedAction(uint64 actionId_) external view returns (ITimelockQueue.QueuedAction memory action_);

Parameters

NameTypeDescription
actionId_uint64The queued action ID.

Returns

NameTypeDescription
action_ITimelockQueue.QueuedActionThe queued action.

executeQueuedAction

Execute a queued action after its timelock has elapsed.

Reverts if:

  • The action does not exist
  • The action has already been executed
  • The action has been cancelled
  • The action is still timelocked
  • The action has expired
  • _validateExecution reverts
  • _executeAction reverts
function executeQueuedAction(uint64 actionId_) external;

Parameters

NameTypeDescription
actionId_uint64The queued action ID.

cancelQueuedAction

Cancel a queued action.

Reverts if:

  • The action does not exist
  • The action has already been executed
  • The action has been cancelled
  • _validateCancellation reverts
function cancelQueuedAction(uint64 actionId_) external;

Parameters

NameTypeDescription
actionId_uint64The queued action ID.

_queueAction

Queue a timelocked action.

Calls _validateQueue internally so child contracts cannot use this helper without passing their implementation-specific queue authorization and payload checks.

function _queueAction(address target_, bytes4 selector_, bytes memory payload_)
internal
returns (uint64 actionId_);

Parameters

NameTypeDescription
target_addressThe contract expected to receive the queued action.
selector_bytes4The function selector for the queued action.
payload_bytesEncoded parameters for the action.

Returns

NameTypeDescription
actionId_uint64The queued action ID.

_setTimelockDelay

Set the timelock delay.

Reverts if _validateTimelockDelay rejects the new delay.

function _setTimelockDelay(uint48 delay_) internal;

Parameters

NameTypeDescription
delay_uint48The new timelock delay in seconds.

_validateExecutableState

Validate standard executable state for a queued action.

Reverts on failure.

function _validateExecutableState(uint64 actionId_, ITimelockQueue.QueuedAction storage action_) internal view;

Parameters

NameTypeDescription
actionId_uint64The queued action ID.
action_ITimelockQueue.QueuedActionThe queued action storage reference.

_validateCancellableState

Validate standard cancellable state for a queued action.

Reverts on failure.

function _validateCancellableState(uint64 actionId_, ITimelockQueue.QueuedAction storage action_) internal view;

Parameters

NameTypeDescription
actionId_uint64The queued action ID.
action_ITimelockQueue.QueuedActionThe queued action storage reference.

_validateQueue

Validate whether an action can be queued.

Child contracts must revert on failure. The caller is passed explicitly for clarity and to support child contracts that centralize authorization around actor params.

function _validateQueue(address caller_, address target_, bytes4 selector_, bytes memory payload_)
internal
view
virtual;

Parameters

NameTypeDescription
caller_addressThe account queueing the action.
target_addressThe contract expected to receive the queued action.
selector_bytes4The function selector for the queued action.
payload_bytesEncoded parameters for the action.

_validateExecution

Validate implementation-specific execution rules.

Child contracts must revert on failure. Standard queued-action state and timestamp checks have already passed when this hook is called.

function _validateExecution(address caller_, uint64 actionId_, ITimelockQueue.QueuedAction memory action_)
internal
view
virtual;

Parameters

NameTypeDescription
caller_addressThe account executing the action.
actionId_uint64The queued action ID.
action_ITimelockQueue.QueuedActionA memory copy of the queued action.

_validateCancellation

Validate implementation-specific cancellation rules.

Child contracts must revert on failure. Standard queued-action state checks have already passed when this hook is called.

function _validateCancellation(address caller_, uint64 actionId_, ITimelockQueue.QueuedAction memory action_)
internal
view
virtual;

Parameters

NameTypeDescription
caller_addressThe account cancelling the action.
actionId_uint64The queued action ID.
action_ITimelockQueue.QueuedActionA memory copy of the queued action.

_executeAction

Execute an implementation-specific queued action.

Child contracts must revert on failure. The queued action has already been marked executed before this hook is called; a revert rolls back that state change.

function _executeAction(uint64 actionId_, ITimelockQueue.QueuedAction memory action_) internal virtual;

Parameters

NameTypeDescription
actionId_uint64The queued action ID.
action_ITimelockQueue.QueuedActionA memory copy of the queued action.

_validateTimelockDelay

Validate a timelock delay.

Child contracts must revert on failure.

function _validateTimelockDelay(uint48 delay_) internal view virtual;

Parameters

NameTypeDescription
delay_uint48The delay to validate.

_executionWindow

Return the execution window for queued actions.

function _executionWindow() internal view virtual returns (uint48 executionWindow_);

Returns

NameTypeDescription
executionWindow_uint48The execution window in seconds.

supportsInterface

Query if a contract implements an interface.

Does not revert.

function supportsInterface(bytes4 interfaceId_) public view virtual returns (bool);

Parameters

NameTypeDescription
interfaceId_bytes4The interface identifier, as specified in ERC-165.

Returns

NameTypeDescription
<none>boolbool True if the contract implements interfaceId_.