Jump to content
Crypto Front Page

Crypto networks, markets and policy

DEX routing: How the best path wins

How DEX routing finds the best path across pools: it simulates routes, accounts for pool fees and gas, then picks the one with the highest net output.

The Crypto Front Page Desk4 min read

DEX routing: How the best path wins

A DEX router chooses the path that leaves you with the most tokens after pool fees and gas, by simulating candidate routes against current pool reserves. Because pools have different depth and pricing curves, the best route can change with the size of your swap. For how SyncSwap brings different pool types together, see SyncSwap; its official pool contracts expose reserves and swap-fee logic, while Ethereum’s explanation of rollup costs describes why L2 transaction costs differ from mainnet.

How does a DEX router compare paths?

A DEX router compares each candidate by estimating how much output its pools can return for the requested input. It starts with the token pair, trade amount and available pool reserves, then applies each pool’s pricing curve and fee in sequence. It also estimates the gas for executing the route.

Take a swap from token A to USDC. A direct pool may be thin: a large order shifts its price as the trade uses up more of the available liquidity. A route from A to ETH and then ETH to USDC adds a hop, but if both pools are deeper, less price impact can more than cover the two swap fees and extra gas. The router picks that two-hop path when its estimated net output is higher.

Each hop charges that pool’s swap fee on the amount passing through it. On a multi-hop route, the second pool receives what remains after the first pool’s fee and exchange, so fees compound along the way. More hops also mean more work in the transaction and therefore more gas. An extra hop is worthwhile only when its better pricing or deeper liquidity saves more than its fee and gas cost.

Think of the router as comparing checkout lanes: a longer line at one counter may be slower than passing through two quicker counters, but each extra stop has a cost. For a small trade, a direct route may win because its simpler transaction saves gas. For a larger trade, avoiding the sharp price movement in a shallow pool may matter more.

What is split routing on a DEX?

Split routing divides one order across multiple pools, so each pool handles a smaller portion and causes less price impact. Instead of sending the full A-to-USDC trade through one pool, a router can send portions through a direct pool and through A-to-ETH-to-USDC. It estimates the combined output, including the fees for every pool used and the gas for executing the split.

The gain is better pricing when one pool cannot absorb the whole order efficiently. The cost is extra pool fees and transaction complexity. A split makes sense when the reduced price impact outweighs those costs; for a small order or a shallow alternative route, keeping the trade on one path can be better.

Gas changes that balance. On an L2 such as zkSync Era, the cost of an extra hop can be low enough that a router chooses multi-hop and split routes at smaller trade sizes than it would on Ethereum mainnet. That does not make more hops automatically better: the pools still need to return enough extra output to cover their fees and the added gas. Traders comparing routes should weigh the estimated final output against the path length and transaction cost.

SyncSwap routes across Classic and Stable pools held in one Vault. A Stable Pool can suit a stablecoin leg, while Classic Pool hops can handle other token pairs; the router can compare those pool types as parts of a candidate route. For a trader, the useful question is whether the displayed path’s extra hops or split improve net output enough to justify their costs.

What is a multi-hop swap?

A multi-hop swap converts a token through one or more intermediate tokens before reaching the requested output. In the A-to-ETH-to-USDC case, ETH is the intermediate token: the route uses two pools, paying each pool’s fee, to potentially get a better result than the direct A-to-USDC pool.

Read a route by checking its intermediate tokens, the pools it uses, the estimated output and the gas cost. Then compare that result with a direct route and ask whether the gain comes from deeper liquidity or a better-fitting curve. The path with the most hops is not necessarily best; the one with the highest net output is. Once you see what changed the result, you can choose the route that fits your trade size and cost tolerance.