Gelato Network
Search…
⌃K

Smart Contract

Using Automate programatically
Tasks created via this route cannot be named
Smart Contracts can also create and cancel tasks on Gelato Automate.
You can find a list of example smart contracts here.

OpsTaskCreator functions

Here are the functions exposed by OpsTaskCreator which you can use when setting up your smart contract.

_createTask()

Interacts and creates a task on the Gelato Ops smart contract.
function _createTask(
address execAddress,
bytes memory execDataOrSelector,
ModuleData memory moduleData,
address feeToken
) internal returns (bytes32 taskId);
  • execAddress - Address of the contract which Gelato will call.
  • execDataOrSelector - Signature of function which Gelato will call / execution data (If Resolver Module is not used. More about modules below)
  • moduleData - Modules that are enabled for the task. (More about ModuleData below)
  • feeToken - Use address(0) if using Gelato balance. Use 0xeeeeee... for ETH or native tokens.

ModuleData

struct ModuleData {
Module[] modules;
bytes[] args;
}
Modules are conditions / specifications about your task. These are the current available Modules.
enum Module {
RESOLVER,
TIME,
PROXY,
SINGLE_EXEC
}
  • RESOLVER - Define dynamic conditions and execution data. Smart Contract Resolver
  • TIME - Repeated execution at a specific time and interval.
  • PROXY - Your function will be called by a dedicated msg.sender.Restricting msg.sender
  • SINGLE_EXEC - Task is cancelled after one execution.
Each Module would require additional arguments which is an encoded data.
You can use these helper functions to get the arguments for each Module.
function _resolverModuleArg(address _resolverAddress, bytes memory _resolverData)
function _timeModuleArg(uint256 _startTime, uint256 _interval)
function _proxyModuleArg()
function _singleExecModuleArg()
Crafting ModuleData will look like this if we want to create a task which utilise RESOLVER ,PROXY & SINGLE_EXEC Module.
ModuleData memory moduleData = ModuleData({
modules: new Module[](3),
args: new bytes[](3)
});
moduleData.modules[0] = Module.RESOLVER;
moduleData.modules[1] = Module.PROXY;
moduleData.modules[2] = Module.SINGLE_EXEC
moduleData.args[0] = _resolverModuleArg(
address(this),
abi.encodeCall(this.checker, ())
);
moduleData.args[1] = _proxyModuleArg();
moduleData.args[2] = _singleExecModuleArg();
Module[] must follow the order RESOLVER, TIME, PROXY, SINGLE_EXEC

_cancelTask()

Cancels a task owned by the smart contract.
function _cancelTask(bytes32 _taskId) internal

onlyDedicatedMsgSender

Function modifier to restrict msg.sender to only task executions created by taskCreator (defined in constructor). Restricting msg.sender
modifier onlyDedicatedMsgSender() {
require(msg.sender == dedicatedMsgSender, "Only dedicated msg.sender");
_;
}
PROXY module must be enabled. Or else the msg.sender will be the Ops smart contract in Contract Addresses

_depositFunds()

function _depositFunds(uint256 _amount, address _token) internal
Deposit funds into the contract's Gelato balance.

withdrawFunds()

function withdrawFunds(uint256 _amount, address _token) external
Withdraw funds from the contract's Gelato balance. Only fundsOwner defined in the constructor can call this function.