Skip to main content

Limit Orders

QsnDEX implements a fully on-chain limit order system through the QsnLimitOrder contract. Orders are stored on-chain and executed by an automated keeper when market conditions meet the specified price target.

How It Works

Order Placement

  1. The user deposits the input token (tokenIn) into the QsnLimitOrder contract.
  2. The user specifies the minimum acceptable output amount (minAmountOut) and a deadline timestamp.
  3. The order is recorded on-chain and becomes eligible for execution.

Keeper Execution

A backend keeper service monitors all active limit orders:

  • The keeper checks prices every 15 seconds by calling the router's getAmountsOut() function for each active order.
  • When the router reports that the available output meets or exceeds the order's minAmountOut, the keeper submits an execution transaction.
  • The keeper receives a 0.1% reward (KEEPER_REWARD_BPS = 10) from the output amount as compensation for gas costs and monitoring.

Order Expiration

If an order reaches its deadline without being executed, it can be reclaimed by anyone. The deposited tokenIn is returned to the original order creator. This ensures that funds are never permanently locked in the contract.

Key Properties

PropertyValue
Matching engineFully on-chain, no centralized order book
Keeper check interval15 seconds
Keeper reward0.1% of output (10 bps)
ExpirationUser-defined deadline
ReclaimAvailable to anyone after deadline

Viewing Orders

The MyOrders panel in the trading interface displays:

  • Active orders -- Orders that are currently open and awaiting execution.
  • Past orders -- Completed, expired, or cancelled orders with their execution details.

Design Principles

The limit order system is designed to be fully decentralized at the contract level. While the keeper service automates execution for convenience, the contract itself does not depend on any centralized component. Any address can call the execution function if the price condition is met, and any address can reclaim expired orders on behalf of the creator.