For the complete documentation index, see llms.txt. This page is also available as Markdown.

Clearing Algorithm (APEX)

APEX is Turbine's batch clearing algorithm. Each batch, APEX finds a single exchange rate for every token that maximizes settled volume. APEX draws on all open orders, market maker quotes, Turbine LP pools, and every DEX pool indexed by Tycho. Every order in the batch clears at that rate minus the platform fee.

APEX is Turbine's Rust implementation of SPEEDEX, a batch clearing algorithm originally developed at Stanford.

How APEX solves a batch

APEX solves each batch in two steps.

Price search. Starting from current market prices, APEX adjusts token prices iteratively until it finds a set where supply and demand balance across the full orderbook. At each step it checks how orders respond to a price change and keeps adjusting until it minimizes the imbalance.

Volume maximization. With prices fixed, APEX runs a linear program that maximizes total trade volume, subject to every order filling at or better than its limit price. Orders that match peer-to-peer settle without touching DEX liquidity. Remaining imbalances route to on-chain pools.

Ring-CoWs: multi-party circular trades

APEX solves the entire batch as one problem across all token pairs. This lets it find ring-CoWs: circular multi-party trades where Alice sells ETH for USDC, Bob sells USDC for WBTC, and Carol sells WBTC for ETH, all netting out at zero price impact without any DEX interaction.

Solvers that work one pair at a time miss these. APEX finds them because it sees the whole batch.

Uniform clearing prices

All orders for the same token pair in the same batch clear at one price. If APEX sets a clearing rate of 3800 USDC/ETH, every order in that batch gets exactly 3800, whether the limit was 3800 or 3750. There is no queue advantage: the first order to arrive gets the same price as the last.

DEX liquidity

APEX routes through all DEX pools indexed by Tycho, including Uniswap v2, v3, and v4, Curve, Balancer, and others. When peer-to-peer matching is not enough, remaining volume settles at the best available on-chain rate.

Last updated

Was this helpful?