HL Mechanics

Limit Order + Pool Settlement

IDEX HL relies on smart contracts to manage both custody and trade settlement, enforcing the constraints of the AMM pricing curve and allowing users to maintain custody of their assets. The IDEX smart contract contains three settlement functions that are employed in various circumstances depending on the type of liquidity being matched.

  1. Pool

  2. Limit Order

  3. Hybrid (Pool + Limit Order)

Pool: this settlement occurs against liquidity entirely within the AMM liquidity pool. This happens when the order is fully satisfied by the AMM.

Limit Order: this settlement occurs against a specific limit order. This can occur if the trade is entirely satisfied by existing limit orders (i.e. they sit at the front of the order book/spread), or if there are multiple limit orders at the same price level.

Hybrid: this settlement takes pool liquidity from the current AMM price to the next limit order, as well as the limit order liquidity, up to the full liquidity of the first limit order at that price level (by price/time priority). Any additional limit orders at that price level are settled as limit only.

Orders that pass through multiple limit order price levels will result in multiple hybrid settlement transactions. Further visual examples below help clarify the interaction between pool and limit order liquidity.

Transforming Pool Liquidity

IIn order for pool liquidity to support central limit order book (CLOB) operations, the exchange adheres to an important constraint: the pool is purely a liquidity supplier (maker) and never takes liquidity from the CLOB.

Representing an AMM pool on an order book poses a clear challenge: the pricing curve of the pool is continuous, while order books operate at discrete price levels. The only price for a liquidity pool is the nominal price (Quote/Base, or in AMM terms y/x), the starting price of the pool prior to any trades.

Consider a pool with the following parameters:

The liquidity in this pool is visualized by the depth chart below. Note: IDEX HL currently utilizes the standard x*y = k AMM curve, though other curves may be added in the future.

The amount of liquidity available from the pool, based on its reserves, can be calculated for any arbitrary price level. IDEX HL picks synthetic price levels to display that are appropriate for the market and shows the available quantities. The example below has synthetic price levels in increments of 10 basis points from the nominal price. Importantly these are not actual orders, as HL will fill taker orders with pool liquidity at any price.

For example, if a user exchanges 4.99875062 quote units they will receive 0.04996253 base units in return, and the pool price will settle at 100.1.

Synthetic Order Definitions: Marginal Pricing

The order book is always centered around the nominal price of the pool. On either side are both user generated limit orders and synthetic price levels that represent the pooled liquidity as specific quantities at discrete prices. The depth chart above is displayed as follows:

Synthetic price levels in IDEX HL are priced using a concept known as marginal pricing. The marginal price of a pool is equal to Quote/Base (nominal price) after a trade, or where the pool “settles.” This is the slippage-driven price of the last unit exchanged in the trade. In the example, above the marginal price is 100.1.

The marginal price is not the same as the effective price that the user pays for the liquidity (total quote/total base)! This is expected as in this example the “slice” of liquidity between 100 and 100.1 has an effective price that is somewhere in the middle of the starting and ending nominal prices.

Note: resulting fills appear to be priced better than the price offered on the order book, as fills reflect the average price rather than the marginal price. This adheres to limit order execution rules but may be unexpected.

The orderbook for this particular scenario is as follows:

Pool + Limit Order Visualization

Order books contain additional limit orders that enhance the available liquidity. Consider the addition of a limit order ask for 0.05 base at a price of 100.1:

In the event that the limit order price is between synthetic price levels, the liquidity at the limit order price level includes both the limit order quantity and the pool liquidity from the previous synthetic price level to the limit order price.

The impact of this additional limit order is visualized as a step function increase in the available liquidity at that price level.

HL Settlement Examples

Pool Only

  • Send 4.99875062 quote; receive 0.04996253 base

  • The order is filled entirely using AMM pool liquidity


  • Send 10.0037506 quote; receive 0.09996253 base

  • The order is filled using the AMM pool liquidity up to the limit order at 100.1, and the full limit order at 100.1. This settlement occurs on-chain in one transaction.

Limit Only

  • The limit order liquidity at the 100.1 consists of two limit orders of 0.025 base each

  • Send 10.0037506 quote; receive 0.09996253 base

  • The settlement occurs in two transactions, a hybrid settlement receiving 0.07496253 base, and a limit only settlement receiving 0.025 base

Last updated