How to work with Automate7579

Overview how to enhance programmable smart accounts utilizing erc7579.

  1. Install the Automate7579 module on account abstraction using the installModule function.

function installModule(
    uint256 moduleTypeId,
    address module, 
    bytes calldata initData
) external;
Name
Description

moduleTypeId

Type of module to install. In our case, the value is 2.

module

The address of the contract that the module.

initData

  1. Add automation via the addWorkflow function. During the workflow addition process, you can initialize the checker. The request to the checker will be executed before the execution of the main action on the target contract. Initialization of checker is optional. If there is no need for checks, then the _inits array can be left empty.

function addWorkflow(
    Execution[] memory _inits,
    Execution[] memory _actions,
    uint256 _maxGasPrice,
    uint256 _maxGasLimit,
    uint88 _count
) external;
Name
Description

_inits

Data for calls that are made at the stage of adding Workflow.

_actions

Data for Workflow execution.

_maxGasPrice

The maximum gas price at which the Workflow will be executed, otherwise revert

_maxGasLimit

The maximum amount of gas that will be spent on Workflow execution.

_count

The number of times Workflow can be called. If 0 is passed, then the number of calls is unlimited.

  1. At the last stage, DittoEntryPoint makes a call to Automate7579. Now Automate7579 makes a call to account abstraction so that it makes a call to target contract.

The tests show an example of how the Automate7579 contract works, as well as installing the Automate7579 module on account abstraction as an executor.

Example Utilization - Limit Order

Combination of AA and Ditto Module enables the creation of statefull workflows such as limit order. By setting the desired amountOut (aka. price) for the swap the user can create an order for repetitive simulation for the execution of calldata that will be broadcasted by Ditto Execution Layer as soon as desired price is achieved.

uint256 amountForSwap = 0.5e18; // amountIn 
uint256 amountOut = 500e6; // desired amount out to fill the order
bytes memory callDataOnRouter = abi.encodeWithSelector(
    IV3SwapRouter.exactInputSingle.selector,
    IV3SwapRouter.ExactInputSingleParams({
        tokenIn: wethAddress,
        tokenOut: usdcAddress,
        fee: poolFee,
        recipient: address(kernelAccount),
        amountIn: amountForSwap,
        amountOutMinimum: amountOut,
        sqrtPriceLimitX96: 0
    })
);
actions[0] = Execution({ 
    target: address(checkerTime), 
    value: 0, 
    callData: checkTimeOnTarget }); // expiration for the order
    
actions[2] = Execution({ target: address(uniswapRouter), 
    value: 0, 
    callData: callDataOnRouter }); // the swap calldata with desired price
    
bytes memory executeData =
    abi.encodeWithSelector(moduleAutomate7579.addWorkflow.selector, 
    inits, // checker initialization
    actions, // the checker verification and swap execution
    maxGasPrice, maxGasLimit, 1); // 1 execution
    
bytes memory callData = encodeExecute(address(moduleAutomate7579), 0, executeData);
// calldata to register the automation and order continuous simulation and monitoring

Last updated