Skip to main content

Cron Service

Overview

The Cron Service is an advanced on-chain automation tool built on top of fisWasmVM to execute transactions on your behalf across all Planes. This service enables users to automate routine tasks, ensuring efficient and timely management of blockchain activities without manual intervention.

Problems

Retail users face several challenges managing daily on-chain tasks:

  1. Time-consuming daily tasks: Managing blockchain activities involves numerous daily tasks such as balance transfers, compound staking, portfolio balancing, and swapping. Each of these tasks can consume a significant amount of time, especially when handled manually. The repetitive nature of these activities can lead to inefficiencies, taking valuable time away from more strategic decision-making and innovation.

  2. Risk of Human Error: Human intervention in executing transactions carries inherent risks, such as mistakes in balance transfers, compound staking, portfolio balancing, and swapping. Even with meticulous attention, errors can lead to loss of funds, missed opportunities, suboptimal portfolio performance, and unfavorable trades.

  3. Consistency and Timing: Maintaining consistency and timing in executing transactions is challenging. Variability in human schedules and attention can lead to missed deadlines or delayed transactions, affecting the overall performance of investment strategies. Ensuring timely execution is crucial for tasks like compound staking and portfolio balancing, where delays can have significant financial implications.

  4. Cognitive Stress: The mental effort required to manage multiple transactions and ensure accuracy can be stressful and overwhelming, impacting overall productivity and well-being.

Solution

The Cron Service was designed to address these issues with the following key features:

  • Automated Transaction Management
  • Removal of Human Error Risks on daily tasks
  • Consistency and Timing
  • Multi-Plane Management
  • Smart Gas Fee Management
  • Stress and Cognitive Load Reduction
  • Advanced Automation with complex logic leveraging FIS and fisWasmVM.

Components

Since cron service is a strategy, it inherits all components from strategy except it is triggered base on timestamp interval instead of transaction. See Strategy components.

Those fields in Strategy metadata are specialized fields for Cron Service and can be updated anytime via MsgConfigStrategy transaction.

Field: cron_gas_price
Type: string
Description: This field specifies the gas price to prioritize cron service execution order in End Blocker. It ensures that the cron bots have the necessary gas to perform their tasks efficiently and is sorted into suitable slot for them in the queue.

Field: cron_input
Type: string
Description: This field allows users to provide specific inputs to control the behavior of the cron bots. It can be used to define parameters or commands that guide the cron bots in executing the desired tasks.

Field: cron_interval
Type: uint64
Description: This field sets the timestamp interval (in seconds) at which the cron bots should be triggered. It enables users to schedule the frequency of automated tasks, ensuring timely execution based on predefined intervals.

Workflow

Workflow of the Cron Service from initialization to transaction execution and state persistence:

  1. Chain Initialization: All cron services are loaded into a memory list.
  2. Begin Blocker: Prepare all registered FIS (Flux Instruction Set) queries that will be used by cron services later.
  3. Transaction Execution
  • When a new cron service is deployed, add the new cron service to the cron service list.
  • When an existing cron service is updated, update the cron service in the memory list.
  1. End Blocker:
  • Filter cron services based on their timestamp to indentify which cron services are due for execution.
  • Sort cron services by configured gas price to optimize the order of execution to manage gas fees effectively.
  • Execute cron services sequentially in the sorted order.
  • Persist state changes and emit events.

Deploy your 1st Cron Service

Compile example Cron Service

git clone https://github.com/FluxAstromeshLabs/nexus-bots
cd nexus-bots/examples/cron/bank-cron
make build-release

# verify output binary exists
ls target/wasm32-unknown-unknown/release/bank_cron.wasm

Deploy Cron Service

# clone sdk-go
git clone https://github.com/FluxAstromeshLabs/sdk-go
cd sdk-go

# copy over the strategy binary
cp ../nexus-bots/examples/strategy/plane_util/target/wasm32-unknown-unknown/release/plane_util.wasm examples/chain/26_MsgConfigCron/cron.wasm

# deploy
yes 12345678 | go run examples/chain/26_MsgConfigCron/example.go

# check if cron service is deployed
http://localhost:10337/flux/strategy/v1beta1/strategies/type/CRON

# check if receiver account balance is updated
http://localhost:10337/cosmos/bank/v1beta1/balances/lux158ucxjzr6ccrlpmz8z05wylu8tr5eueqcp2afu

Update deployed Cron Service

yes 12345678 | go run examples/chain/27_MsgUpdateCron/example.go

# check if cron service metadata is updated
http://localhost:10337/flux/strategy/v1beta1/strategies/type/CRON

# check if receiver account balance is updated
http://localhost:10337/cosmos/bank/v1beta1/balances/lux158ucxjzr6ccrlpmz8z05wylu8tr5eueqcp2afu

Build a Cron Service

See Build your first Cron Service