Skip to main content

Task Manager Interface (ITaskManager)

The ITaskManager interface provides the core functionality for scheduling, managing, and executing automated tasks on the Monad blockchain. Developers interact primarily with this interface to schedule tasks, while Executors use it to execute pending tasks.

Security Note

The Task Manager implementation utilizes non-reentrancy guards (withLock modifier) on critical state-changing functions like scheduleTask and executeTasks to prevent potential exploits involving nested or overlapping calls.

Core Functions

scheduleTask

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

Schedules a task for execution at a future targetBlock, paying the execution cost with native MON sent in msg.value.

  • The implementation address is the contract containing the task logic. The Task Manager deploys a task-specific proxy (mimic) which will delegatecall this implementation.
  • Requires sufficient msg.value (MON) to cover the returned executionCost.
NameTypeDescription
implementationaddressThe contract address containing the task logic. A task-specific proxy deployed by the Task Manager will delegatecall this contract's code during execution.
taskGasLimituint256The gas limit allocated for the task's execution logic within the implementation. Determines the task size category (Small, Medium, Large).
targetBlockuint64The desired block number for task execution. Must be in the future but within a reasonable window (MAX_SCHEDULE_DISTANCE).
maxPaymentuint256Maximum payment (in MON equivalent) the scheduler is willing to offer for execution. Influences executor incentives. msg.value must cover the calculated executionCost.
taskCallDatabytesThe encoded function call data intended for the implementation contract (will be passed through the task proxy via delegatecall).

scheduleWithBond

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

Schedules a task for execution at a future targetBlock, paying the execution cost using the caller's bonded shMONAD. This function is not payable.

  • The implementation address is the contract containing the task logic. The Task Manager deploys a task-specific proxy (mimic) which will delegatecall this implementation.
  • Requires the caller to have sufficient bonded shMONAD (under the Task Manager's POLICY_ID) to cover the returned executionCost. The contract will attempt to transfer the required bond amount.
NameTypeDescription
implementationaddressThe contract address containing the task logic. A task-specific proxy deployed by the Task Manager will delegatecall this contract's code during execution.
taskGasLimituint256The gas limit allocated for the task's execution logic within the implementation. Determines the task size category (Small, Medium, Large).
targetBlockuint64The desired block number for task execution. Must be in the future but within a reasonable window (MAX_SCHEDULE_DISTANCE).
maxPaymentuint256Maximum payment (in MON equivalent) the scheduler is willing to offer for execution. Influences executor incentives. Required bond must cover the calculated executionCost.
taskCallDatabytesThe encoded function call data intended for the implementation contract (will be passed through the task proxy via delegatecall).

executeTasks

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

Executes queued tasks up to the target gas reserve. This function is typically called by automated Executors who scan for pending tasks and perform their execution to earn fees.

NameTypeDescription
payoutAddressaddressThe beneficiary address that will receive the fees earned from executing tasks. Can be the caller or any other valid address.
targetGasReserveuint256Amount of gas to reserve after execution. The executor should provide a value ensuring sufficient gas for the function to complete safely.

rescheduleTask

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

Intended to be called by the task-specific proxy/mimic address (environment) during task execution. Allows a task's logic (running via delegatecall from the proxy) to reschedule itself for a future block.

NameTypeDescription
targetBlockuint64The desired future block number for the rescheduled task execution. Must be in the future but within a reasonable window (MAX_SCHEDULE_DISTANCE).
maxPaymentuint256Maximum payment (in MON equivalent) the scheduler is willing to offer for execution. Influences executor incentives. Either msg.value or bonded shMONAD must cover the executionCost.

cancelTask

function cancelTask(bytes32 taskId) external;

Cancels a scheduled task. This prevents the task from being executed and releases any associated bonds or payments.

NameTypeDescription
taskIdbytes32The identifier of the task to cancel.

Task Status and Information

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:

NameTypeDescription
taskIdbytes32The identifier of the task to query.

estimateCost

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

Estimates the cost (in MON or equivalent bonded shMONAD) required to schedule a task.

NameTypeDescription
targetBlockuint64The block number for which to estimate execution costs. Congested blocks may have higher execution costs.
taskGasLimituint256The gas limit for task execution. Determines the task size category (Small, Medium, Large).

getTaskMetadata

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

Retrieves metadata associated with a specific task. The metadata (owner, nonce, size) is stored keyed by the task's unique environment (proxy/mimic) address, which is derived from the taskId.

NameTypeDescription
taskIdbytes32The identifier of the task to query. The environment address is derived from this ID.

getNextExecutionBlockInRange

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

Finds the earliest block with scheduled tasks in the specified range.

NameTypeDescription
startBlockuint64Start of the block range (inclusive).
endBlockuint64End of the block range (inclusive).

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.

NameTypeDescription
taskIdbytes32The identifier of the task for which to add/remove cancellation rights.
cancelleraddressThe address to grant or revoke cancellation rights.

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.

NameTypeDescription
taskIdbytes32A task identifier used to determine the environment. All tasks using this environment will be affected.
cancelleraddressThe address to grant or revoke environment-wide cancellation rights.

See Also