Skip to main content

Introduction

Automated Orders

This section explains how to implement basic automated Orders—smart contracts that monitor prices and execute token swaps on Uniswap based on simple price thresholds, signing transactions with Keychains. This Order type serves as a foundation for building more advanced Orders with price prediction.

You'll implement the core logic in the BasicOrder contract, implement the creation of Orders in BasicOrderFactory, and finally deploy an Order. To learn about the full architecture of this project, refer to the main introduction.

Full code

Please note that the articles in this section typically contain only fragments of code.
You can find the full code of the example on GitHub: /orders

Key features

Automated Orders provide the following key features:

  • Price threshold monitoring
  • Single price source integration
  • Direct Uniswap interactions
  • Basic execution security

User flow

A user can create and manage multiple automated Orders. The user flow includes the following steps:

  1. The user specifies the Order input with these details:
    • The price threshold and condition (greater/less than)
    • The token pair to monitor
    • Swap details such as amount, path, recipient, deadline
    • Transaction signing details
  2. The OrderFactory contract calls BasicOrderFactory, which deploys a new BasicOrder contract (Order) and registers it in the registry.
  3. The Order continuously monitors prices using Slinky.
  4. When the price threshold is met, the Order executes a swap:
    • Constructs a swap transaction
    • Sends the transaction to Warden for signing
    • Records the transaction in the registry
    • Executes the swap on Uniswap
  5. Transaction details are stored in the registry.

Get started

To get started with automated Orders, take the following steps:

  1. Build the infrastructure for Orders.
  2. Implement Orders.