Skip to main content

Limit Orders

Limit Orders

Tenor's IR-AMM natively supports limit orders. Unlike liquidity, which can be traded in both directions, limit orders can only be traded in one direction.

For example, a limit order to swap Loan Tokens for Fixed Tokens (e.g., 100 USDC for 108 Fixed-USDC) at 8% can only be executed as a one-way trade from Loan Tokens to Fixed Tokens.

The execution time of a limit order is non-deterministic and depends on when a swapper trades against the limit order.

Lend and borrow limit orders are subject to the following restrictions:

  • When adding a limit order in Loan Tokens to a tick, the protocol ensures that users do not add them below the pool's highest tick with Fixed Tokens.
  • Similarly, when adding a limit order in Fixed Tokens to a tick, the protocol ensures that users do not add them above the pool's lowest tick with Loan Tokens.

Note that lend and borrow limit orders can be placed concurrently at the spot tick.

To track limit orders, the protocol creates ticks with unique batch IDs. The protocol maintains limit order states separately from liquidity ticks. At any given tick interest rate (e.g., 8%), there can be up to three different structures holding tradable liquidity:

  • Liquidity Tick (always assigned batch ID 0)
  • Partially Filled Limit Tick (unique batch ID)
  • Unfilled Limit Tick (unique batch ID)

At most, two active limit order batch IDs can exist per tick: partially-filled and unfilled. To ensure this property, the IR-AMM swap function prioritizes filling partially filled ticks first, followed by unfilled limit ticks, and finally liquidity ticks.

Placing Limit Orders

Placing limit orders is done through the swap function. More details in the swap section.

Note that the protocol groups unfilled orders placed at the same tick in the same batchId.

Withdrawing Limit Orders

Users can cancel or partially withdraw their limit orders. The returned amounts correspond proportionally to the withdrawn shares in Fixed and Loan Tokens.