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 Orders—Solidity smart contracts performing onchain Actions and utilizing AI-driven price predictions on any destination chain.
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
contractBasic 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 andx/warden
to sign transactions with Keychains. -
Automated Orders with price prediction: the
AdvancedOrder
contractThis 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.tipThe 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
You can find the full code of the example on GitHub: orders
Architecture
The core logic of Orders is implemented in two smart contracts:
BasicOrder
: Implements Automated Orders usingx/oracle
to fetch prices.AdvancedOrder
: Implements Orders with price prediction usingx/oracle
andx/async
to fetch prices and predictions.
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:
- Implement the shared infrastructure used by both Order types.
- Build automated Orders to learn the core mechanics, including the Order lifecycle, price monitoring, and execution flow.
- 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:
- To test the creation of Orders with price prediction, run Demo: Create an Order.
- To start implementing Orders, meet the prerequisites and build the infrastructure.
- To dive into the core logic, explore the
BasicOrder
andAdvancedOrder
contracts.