Skip to main content

Task Manager Interface

The ITaskManager interface provides the core functionality for scheduling and managing automated task execution on the Monad blockchain.

Functions

scheduleTask

function scheduleTask(
address implementation,
uint256 taskGasLimit,
uint64 targetBlock,
uint256 maxPayment,
bytes calldata taskCallData
) external payable returns (bool scheduled, uint256 executionCost, bytes32 taskId);

Schedule a task for future execution. Requires sufficient shMONAD bonded to cover execution costs.

Parameters

NameTypeDescription
implementationaddressThe contract address that is delegatecalled
taskGasLimituint256The gas limit of the task's execution
targetBlockuint64The desired block number for task execution
maxPaymentuint256Maximum payment willing to pay for execution
taskCallDatabytesThe encoded function call data for the task

Return Values

NameTypeDescription
scheduledboolWhether the task was successfully scheduled
executionCostuint256The estimated cost of the task
taskIdbytes32Unique identifier for tracking the scheduled task

rescheduleTask

function rescheduleTask(
uint64 targetBlock,
uint256 maxPayment
) external payable returns (bool rescheduled, uint256 executionCost, bytes32 taskId);

Reschedule the currently executing task.

Parameters

NameTypeDescription
targetBlockuint64The block to reschedule to
maxPaymentuint256Maximum payment willing to pay for execution

Return Values

NameTypeDescription
rescheduledboolWhether the task was successfully rescheduled
executionCostuint256The new estimated cost
taskIdbytes32ID of the rescheduled task

executeTasks

function executeTasks(
address payoutAddress,
uint256 targetGasReserve
) external returns (uint256 feesEarned);

Execute queued tasks up to the target gas reserve.

Parameters

NameTypeDescription
payoutAddressaddressThe beneficiary of any payouts
targetGasReserveuint256Amount of gas to reserve for after execution

Return Value

TypeDescription
uint256Amount of fees earned from execution

cancelTask

function cancelTask(bytes32 taskId) external;

Cancel a scheduled task.

Parameters

NameTypeDescription
taskIdbytes32The id of the task to cancel

Task Status Functions

function isTaskCancelled(bytes32 taskId) external view returns (bool cancelled);
function isTaskExecuted(bytes32 taskId) external view returns (bool executed);

Query task status.

Parameters

NameTypeDescription
taskIdbytes32The id of the task to query

Return Value

TypeDescription
boolStatus of the task (cancelled/executed)

estimateCost

function estimateCost(
uint64 targetBlock,
uint256 taskGasLimit
) external view returns (uint256 cost);

Estimate the cost of executing a task.

Parameters

NameTypeDescription
targetBlockuint64The block to schedule the task for
taskGasLimituint256The gas limit of the task's execution

Return Value

TypeDescription
uint256The estimated cost of the task

getTaskMetadata

function getTaskMetadata(
bytes32 taskId
) external view returns (TaskMetadata memory);

Get metadata about a task.

Parameters

NameTypeDescription
taskIdbytes32ID of the task to query

Return Value

TypeDescription
TaskMetadataTask metadata including owner and status information

Authorization Management Functions

function addTaskCanceller(bytes32 taskId, address canceller) external;
function removeTaskCanceller(bytes32 taskId, address canceller) external;
function addEnvironmentCanceller(bytes32 taskId, address canceller) external;
function removeEnvironmentCanceller(bytes32 taskId, address canceller) external;

Manage task and environment cancellation authorizations.

Parameters

NameTypeDescription
taskIdbytes32The task ID for authorization
cancelleraddressThe address to authorize/deauthorize

Task Management

cancelTask

Cancel a scheduled task.

function cancelTask(bytes32 taskId) external;

Parameters:

  • taskId: The id of the task to cancel

Task Status Queries

function isTaskCancelled(bytes32 taskId) external view returns (bool cancelled);
function isTaskExecuted(bytes32 taskId) external view returns (bool executed);

These functions check the status of a task:

  • isTaskCancelled: Returns whether a task has been cancelled
  • isTaskExecuted: Returns whether a task has been executed

Cost Estimation

function estimateCost(
uint64 targetBlock,
uint256 taskGasLimit
) external view returns (uint256 cost);

Parameters:

  • targetBlock: The block to schedule the task for
  • taskGasLimit: The gas limit of the task's execution

Returns:

  • cost: The estimated cost of the task

Task Metadata

getTaskMetadata

Get metadata about a task.

function getTaskMetadata(
bytes32 taskId
) external view returns (TaskMetadata memory);

Parameters:

  • taskId: ID of the task to query

Returns:

  • Task metadata including owner and status information

Block Range Query

function getNextExecutionBlockInRange(
uint64 startBlock,
uint64 endBlock
) external view returns (uint64);

Parameters:

  • startBlock: Start block (inclusive)
  • endBlock: End block (inclusive)

Returns:

  • The earliest block number with tasks, or 0 if none found

Authorization Management

Task-Specific Authorization

function addTaskCanceller(bytes32 taskId, address canceller) external;
function removeTaskCanceller(bytes32 taskId, address canceller) external;

Manage addresses authorized to cancel specific tasks:

  • addTaskCanceller: Add a canceller for a specific task
  • removeTaskCanceller: Remove a canceller from a specific task

Environment-Wide Authorization

function addEnvironmentCanceller(bytes32 taskId, address canceller) external;
function removeEnvironmentCanceller(bytes32 taskId, address canceller) external;

Manage addresses authorized to cancel all tasks for an environment:

  • addEnvironmentCanceller: Add a canceller for all tasks in an environment
  • removeEnvironmentCanceller: Remove a canceller from an environment

Notes:

  • The taskId parameter is used to verify ownership and identify the environment
  • Only the task owner can manage cancellers