DEX Swap Routes, Ranked by Net Output
How does a DEX aggregator calculate the best swap route? It simulates paths and splits, subtracts estimated gas, then returns the route with the highest net output.
Crypto Bulletin Newsroom 3 min read
A DEX aggregator calculates the best swap route by simulating candidate paths and splits against current liquidity, subtracting estimated gas, and selecting the highest net output. The result depends on the amount being traded because each pool has its own pricing curve and depth.
Say you want to swap TOKEN for USDC. A direct TOKEN/USDC pool might look simplest, but the aggregator may find better prices through TOKEN→WETH→USDC if those two pools have more usable liquidity. Matcha swap brings that route search together across liquidity sources; its matcha supported chains background helps establish where that search can apply.
What does the aggregator compare?
The aggregator compares possible sources and paths, then prices the whole trade rather than judging each pool by its displayed price. The 0x Swap API documentation describes liquidity from AMMs and RFQ market makers, and says the API returns a route with a gas estimate.
- AMM pools, each with its own pricing curve
- RFQ quotes from market makers
- Multi-hop paths through tokens such as WETH
- Splits that divide an order across sources
For the TOKEN-to-USDC swap, it can compare one trade through a TOKEN/USDC pool with a two-hop trade through WETH. It can also test sending part of the order through each path. It estimates the output of each candidate, values gas in the buy token, and ranks the choices by what the trader is estimated to receive after that cost.
A quote also includes a minimum received amount based on the chosen slippage tolerance, alongside the route and transaction calldata. Slippage sets how much the execution output may vary before the transaction fails; it does not change which candidate had the best simulated net output.
Why can a large swap change the winning route?
A large swap can move through a pool’s pricing curve and receive progressively less output per token. That matters especially in Uniswap v3, where liquidity is concentrated in tick ranges rather than spread evenly across all prices.
The Uniswap v3 Core whitepaper describes this tick-based liquidity model. To price a trade, the router accounts for the active liquidity and steps through the ticks the trade crosses. A pool with substantial liquidity near its current price can still offer less total output once a large order moves beyond that active range.
So a deep-looking v3 pool may win for a small TOKEN sale but lose to a smaller pool—or a split across pools—when the order is larger. The route breakdown reflects those simulated pool outputs and the estimated gas cost, which is why the selected path can include several hops or sources instead of the most obvious direct pair. Matcha swap gives the trader an aggregated route to compare against the swap’s expected net output.