Routing & execution

How quote sampling estimates an AMM's output curve

Understand amount samples, allocation grids and the limits of approximating a nonlinear swap-output curve.

Route sampling evaluates candidate sources at several amounts so an optimizer can estimate how useful different allocations would be. It captures more information than one spot rate, but its accuracy depends on the model and sampling design.

Why one observation is insufficient

Suppose a hypothetical path returns 9.9 B for 10 A. That observation does not establish its return for 100 A. The curve may bend, cross a liquidity boundary or reach a dealer's size limit.

A router can evaluate several candidate sizes to compare possible allocations. Uniswap's route configuration describes an allocation-percentage grid. This is one concrete discretization approach; other optimizers can use analytical models or numerical methods.

Interpolation is an assumption

Drawing a straight line between two samples estimates intermediate outcomes. For a nonlinear curve, the estimate can differ from the true amount. A discontinuity in eligibility or a change in active liquidity requires particular care.

Consider samples at 50 A and 100 A where a concentrated pool changes active liquidity at an intermediate price. The curve between those points need not behave like a single constant-rate segment. More samples around the transition, or a correct analytical model, can improve the estimate.

Sampling and execution are separate

Even an accurate curve at one snapshot does not freeze future state. Once an allocation is selected, the final quoted route should reflect the relevant current data and actual execution rules.

The engineering tradeoff is between exploration cost, latency and approximation quality. More samples can reveal useful allocations but require additional work. A service's practical result depends on how it balances those factors.

For readers comparing algorithms, ask which amounts were evaluated and whether final execution was checked against the exact selected allocation. “We sampled the pools” is not enough to establish how close the result is to the best feasible route.

Sources & verification (3)

Source-check date is recorded in the article details. URLs are provided for manual verification. Use Copy to keep this page open.

  1. Uniswap smart-order-router: alpha-router.ts

    Candidate-pool selection and configurable hop and split limits.

    https://github.com/Uniswap/smart-order-router/blob/main/src/routers/alpha-router/alpha-router.ts
  2. An Efficient Algorithm for Optimal Routing Through Constant Function Market Makers

    Network routing, utility objectives and optimization under CFMM constraints.

    https://arxiv.org/html/2302.04938v1
  3. Concentrated Liquidity

    Active range liquidity, tick boundaries and liquidity changes.

    https://developers.uniswap.org/docs/get-started/concepts/liquidity-providers/concentrated-liquidity

Continue reading

How a maximum-hop rule changes routing How to read route percentages What a route breakdown tells you and what it leaves unknown