Skip to main content

Introduction

Example Orders

This section explains how to enable onchain capabilities for a Warden Agent created with the Warden Agent Kit.

The guides you'll find here cover an example we created for demonstration purposes. It implements OrdersSolidity smart contracts performing onchain Actions and utilizing AI-driven price predictions on any destination chain.

tip

In our example, Orders perform swaps on Uniswap, but you can make them send any transactions to any Ethereum-based and EVM L2 application. For example, your application can transfer ETH or call an arbitrary contract. You can implement custom logic by using Warden modules, Keychains, and other features. In particular, the x/async module and AVR Plugins allow you to create smart contracts utilizing outputs of AI models.

Order types

You'll learn how to build two types of Orders:

  • Automated Orders: the BasicOrder contract

    Basic automated Orders monitor prices and automatically execute token swaps on Uniswap when user-defined price thresholds are met. These Orders use the x/oracle module to fetch oracle prices and x/warden to sign transactions with Keychains.

  • Automated Orders with price prediction: the AdvancedOrder contract

    This is a more advanced version of automated Orders. These Orders fetch AI-driven price predictions using the x/async module and an AVR Plugin, compare the predicted and oracle prices, and perform token swaps based on user-defined comparison conditions.

    tip

    The price prediction model is just an example of what you can build with x/async and AVR Plugins. With this module, you can implement any logic combining offchain computation with onchain verification—limited only by your imagination.

Full code

Code

You can find the full code of the example on GitHub: orders

Architecture

The core logic of Orders is implemented in two smart contracts:

Both Order types share common infrastructure: data structures, utils, deployment scripts, and so on. AbstractOrderV0 abstracts the transaction signing logic using x/warden.

Order creation is handled by a set of factory contracts: OrderFactory, BasicOrderFactory, and AdvancedOrderFactory. Depending on the Order type selected by a user, OrderFactory invokes either BasicOrderFactory or AdvancedOrderFactory, which then deploy the corresponding BasicOrder or AdvancedOrder contracts.

Development path

To implement and understand our example, follow these steps:

  1. Implement the shared infrastructure used by both Order types.
  2. Build automated Orders to learn the core mechanics, including the Order lifecycle, price monitoring, and execution flow.
  3. Extend to automated Orders with price prediction by adding price prediction integration, time windows, and complex conditions.

Order types differ not just in functionality, but also in development complexity. Below is a high-level comparison of their state, integrations, and execution logic:

Automated Orders

contract BasicOrder {
// Simple state
bool private _executed;

// Single price source
ISlinky private immutable SLINKY_PRECOMPILE;

// Simple execution check
function canExecute() public view returns (bool) {
return priceResponse.price >= threshold;
}
}

Automated Orders with price prediction

contract AdvancedOrder {
// Complex state
uint64 public taskId;
uint256 private _validUntil;

// Multiple integrations
ISlinky private immutable SLINKY_PRECOMPILE;
IAsync private immutable ASYNC_PRECOMPILE;

// Advanced execution check
function canExecute() public view returns (bool) {
if (block.timestamp > _validUntil) return false;
taskByIdResponse memory task = ASYNC_PRECOMPILE.taskById(taskId);
return _checkPredictionAndPrice(task, getCurrentPrice());
}
}

Get started

You can get started in different ways, depending on your focus: