Create your own
Lesson illustration

Routing, Arbitrage, and MEV in Swap Execution Quality

Welcome back. In the previous lesson, you examined how concentrated liquidity changes an LP’s exposure: liquidity can be deep near the current price, but it can disappear when many ranges go inactive. This lesson takes the trader’s perspective. A swap’s displayed quote is only the beginning; its execution quality depends on the route selected, the market’s current price alignment, transaction ordering, and the costs of getting the transaction included on-chain.

By the end, you should be able to evaluate whether a swap was executed well by separating route quality, ordinary price impact, arbitrage-driven price alignment, and MEV-related execution loss.


Execution quality: more than the token output

Suppose you swap USDC for ETH. A wallet might show:

  • expected output: 1.000 ETH;
  • price impact: 0.40%;
  • network fee: 8 USDC;
  • minimum received: 0.990 ETH.

These values describe different things.

MeasureWhat it tells youWhat it does not tell you
Quoted outputExpected tokens received if the route executes against the currently simulated pool stateWhether pool state will change before inclusion
Price impactHow much your own trade moves along the liquidity curve relative to a reference priceWhether the route is globally best or MEV-protected
Slippage toleranceThe worst output you authorize before the transaction should revertThe expected loss from the trade
Gas costThe network cost of submitting and executing the transactionThe token price paid within the route
Actual outputWhat you finally received on-chainWhether it was good without a benchmark

For an exact-input swap, a useful all-in measure is the output after converting gas into units of the output token:

Here, is the output received, is gas cost denominated in a common currency, and is the output token’s price in that currency. This is an approximation, but it prevents a common mistake: choosing a route that delivers slightly more tokens while costing substantially more to execute.

A good execution is therefore not necessarily the route with:

  • the fewest hops;
  • the lowest visible pool fee;
  • the highest gross output before gas; or
  • the smallest price impact reported by one pool.

It is the route that gives the best credible, executable, all-in outcome at that moment, while respecting the amount of execution risk you are willing to accept.

Price impact, slippage, and adverse execution

Keep three ideas distinct:

  1. Price impact is the mechanical effect of consuming liquidity. In a constant-product AMM, a larger trade moves farther along the curve and receives a worse average price.
  2. Slippage is the difference between an expected price and the price actually received. It can include your trade’s own impact, state changes while the transaction waits, and harmful ordering.
  3. Slippage tolerance is a limit you set. If the output falls below that limit, the transaction normally reverts rather than completing at an unacceptable price.

A very loose slippage tolerance does not “make execution more likely” for free. It gives more room for market movement and potentially for a sandwich attacker to extract value. Conversely, an extremely tight tolerance can cause a legitimate swap to revert during normal volatility. On many chains, a reverted transaction can still consume gas.


Routing: finding and combining usable liquidity

Liquidity is fragmented. The same ETH/USDC exposure might be available through:

  • a direct ETH/USDC pool;
  • a route through an intermediary asset such as WETH;
  • several pools with different fee tiers;
  • separate AMMs with different reserve balances; or
  • multiple paths used simultaneously.

A router or DEX aggregator searches this landscape and chooses a route. For a large trade, it may split the input between pools rather than send all of it through the apparently best single pool.

How DEX Aggregators are the Search Engines of DeFi Trading

Watch How DEX Aggregators are the Search Engines of DeFi Trading by The Defiant for a concise introduction to aggregators as route-finding systems across fragmented liquidity.

Watch the analogy for the comparison with a price-search tool, then watch liquidity aggregation to see why an order can be divided among venues. Finish with automated routing, focusing on why manually comparing a few pool prices is not enough in a rapidly changing market.

The flight-search comparison is useful, with an important qualification: a route quote is an estimate based on a specific blockchain state. It is not a permanent promise. Pool balances, gas conditions, and competing transactions can change before your transaction is executed.

Why splitting a trade can improve its price

AMM price impact is generally convex: as you push more volume through one pool, each additional unit tends to receive a worse marginal price. If two pools both offer useful liquidity, splitting an order can avoid pushing too far into either pool’s curve.

Imagine two pools that each have meaningful ETH/USDC depth. A single-route trade may exhaust the relatively favorable part of one pool’s curve. A split route can allocate part of the order to the first pool and part to the second, balancing marginal execution prices. The router need not split evenly; it should allocate more volume where the next increment of trade is cheaper after fees.

A Uniswap illustration of the same 1,822 COMP swap executed through one route versus two split routes. The split route distributes input across pools with different fee tiers and shows a larger USDC output with lower reported price impact.

The illustration demonstrates the principle, not a result you should expect to reproduce. Its numbers were a historical example and depend on the available liquidity, fees, and gas conditions at that moment.

Introducing the Auto Router

Read Uniswap Labs’ Introducing the Auto Router to connect the routing principle to a practical smart-order-routing design. It emphasizes split routes, deeper route search for large trades, and the need to account for gas rather than optimizing token output alone.

In the “Split Routes” section, read the split-route example. Then continue through “More powerful algorithm” and “Gas Cost Awareness.” Focus on the distinction between reducing AMM price impact and improving the effective result after extra route complexity and gas are included.

Routing trade-offs

More routes are not automatically better. Each additional pool or hop may introduce:

  • another trading fee;
  • more gas consumption;
  • a less reliable quote if the path is complex;
  • dependency on intermediary-token liquidity;
  • greater exposure to a route becoming unprofitable before execution.

For a small trade, the gas required to access another pool may exceed the price improvement. For a large trade, the opposite can be true: a more complex split route may save far more in price impact than it costs in gas.

This is why an execution-quality evaluation should ask:

Did the router maximize gross output, or did it maximize the estimated output net of fees and gas?

Those are different objectives.


Arbitrage: why AMM prices return toward the market

An AMM does not independently know the “correct” price of ETH. Its price comes from its reserves. If trading elsewhere moves ETH from 2,000 USDC to 2,050 USDC while an AMM still prices ETH near 2,000 USDC, the AMM is temporarily cheap.

An arbitrageur can buy ETH from the cheap AMM and sell it in the higher-priced market. The AMM purchase changes its reserves and pushes its quoted ETH price upward. Arbitrage continues until the remaining price difference is too small to cover swap fees, gas, and the arbitrageur’s execution costs.

The result is a practical no-arbitrage band rather than a perfect equality:

This makes arbitrage beneficial to ordinary traders over time. It aligns the pool’s price with the broader market, so a trader arriving after arbitrage is less likely to trade against a badly stale pool price.

But it also changes who captures the opportunity. If the AMM is stale and favorable for your intended trade, the arbitrageur who acts first captures much of that favorable discrepancy. Your later trade may look worse compared with the old AMM quote, yet it may be more accurately priced against the current market.

This distinction matters:

  • A worse price than a stale pool quote is not automatically poor execution.
  • A worse price than the best contemporaneous executable market price is evidence of poor execution.

Arbitrage also connects directly to the LP lesson. The trades that restore an AMM’s price alter LP inventory. When the external market rises, arbitrageurs buy the appreciating asset from the pool; when it falls, they sell the declining asset into the pool. LP fees are meant to compensate for providing that liquidity, but fee income is not guaranteed to exceed the cost of this adverse inventory change.


MEV: transaction ordering becomes part of the price

Maximal extractable value, usually abbreviated MEV, is value that can be extracted by deciding how transactions are included, excluded, or ordered within a block. Searchers identify opportunities; block builders and validators control or influence inclusion and ordering through the block-production process.

For a swapper, the most important distinction is between two forms of MEV:

  • Arbitrage, which usually helps keep pool prices aligned with broader markets.
  • Sandwich trading, which directly worsens a targeted user’s execution.

Maximal extractable value (MEV) | ethereum.org

Read ethereum.org’s Maximal Extractable Value (MEV) for the mechanics of searchers, DEX arbitrage, sandwich trades, and the mixed effects of MEV on DeFi users.

Begin in “MEV extraction” and read the explanation of searchers and transaction competition. In “DEX arbitrage” and “Sandwich trading,” study the sandwich example. Finally, read the “Effects of MEV” discussion, especially the contrast between useful arbitrage and harmful execution loss.

The sandwich trade

Suppose your public transaction will buy a token from an AMM. A searcher sees it waiting in the public transaction pool and determines that your allowed slippage leaves room for profit.

The searcher may arrange three trades in the same block:

  1. The searcher buys the token before your transaction, raising the AMM price.
  2. Your transaction executes against this less favorable reserve state.
  3. The searcher sells after your transaction, benefiting from the price increase that your trade helped create.

Your swap can still satisfy its minimum-output condition. That is what makes sandwiching subtle: the trade does not need to fail for you to receive a materially worse price.

For example, assume your wallet initially quotes 1,000 tokens and you set a 2% tolerance, allowing execution down to 980 tokens. If intervening trades reduce your output to 985 tokens, the transaction succeeds. You receive 15 fewer tokens than the original quote, and the sandwich searcher may capture part of that loss.

This is not ordinary price impact. Your own trade may have been expected to move the AMM price even in an empty block. The extra loss caused by a strategically inserted trade is an ordering cost.

MEV is not one thing

It is tempting to label all MEV as theft or all arbitrage as beneficial. Both simplifications fail.

MechanismTypical effect on a swapperBroader protocol effect
Cross-venue arbitrageRestores a stale pool toward market priceImproves price consistency, while shifting inventory through LP positions
Competitive transaction inclusionMay increase gas and delay executionRewards validators or builders through transaction fees
Sandwich tradingWorsens the victim’s fill within their permitted rangeExtracts value from individual traders and degrades trust in execution
Fast liquidationsNot directly about swapsCan protect lending-market solvency, while rewarding the liquidator

The correct question is not “Was MEV present?” Transaction ordering is inherent to blockchains. Ask instead:

Which participant captured value from ordering, and did that ordering improve market pricing or worsen a specific user’s fill?


A practical framework for evaluating any swap

Before submitting a meaningful trade, evaluate the execution plan in four layers.

1. Establish a real benchmark

Use a recent, credible market reference. For liquid assets, this may be a broad market price or the best available executable quote across major liquidity sources. For an illiquid or newly issued token, there may be no clean external benchmark; then comparison across routes becomes especially important.

Do not benchmark against a pool’s old spot price. A spot price is merely the price of an infinitesimal trade at a particular reserve state.

2. Compare the route, not merely the destination

Inspect:

  • the route’s pools and intermediary tokens;
  • quoted output;
  • estimated price impact;
  • every pool fee;
  • estimated gas;
  • whether the order is split across sources;
  • the minimum received.

A direct route may be excellent if it accesses deep, low-fee liquidity. A multi-hop or split route may be better if it reduces price impact by enough to justify additional fees and gas.

3. Treat the slippage setting as a risk limit

Set the tolerance based on the asset’s volatility, the size of the trade relative to liquidity, and the cost of retrying if it reverts. Avoid treating a high tolerance as a convenience setting.

A high tolerance can be reasonable for a volatile asset when rapid execution is essential, but it means explicitly accepting a wider range of outcomes. It should not be used to compensate for a clearly poor quote or inadequate liquidity.

4. Consider the execution environment

Execution quality depends on whether your transaction is exposed to public ordering competition. Publicly visible, large, price-moving swaps are more attractive sandwich targets. The risk may be lower when an interface uses protected transaction submission or another execution method that does not reveal the order openly before inclusion, but protections vary by chain, wallet, and route.

For a completed transaction, compare the original quote, final output, gas paid, and contemporaneous market price. If the final output is worse than expected, classify the likely cause:

ObservationLikely explanation
Output is lower, but the market moved broadly in the same directionNormal market movement before inclusion
Output is lower and your trade was large relative to pool depthOrdinary price impact or an inferior route
The route’s gross output was high but gas was unusually largeNet execution was weakened by route complexity or network conditions
A price-moving trade appears immediately before and an offsetting trade immediately after yoursPossible sandwich pattern
AMM price was stale, then moved toward external markets before your tradeArbitrage restored alignment; the former pool quote was not a sound benchmark

Key takeaways

Routing, arbitrage, and MEV affect different parts of a swap’s execution:

  • Routing seeks the best use of fragmented liquidity. Split routes can reduce price impact, but extra hops and pools are worthwhile only when their improvement exceeds added fees and gas.
  • Arbitrage helps AMMs converge toward wider market prices. It can make an old favorable pool quote disappear, but that is not necessarily bad execution.
  • MEV concerns transaction ordering. Some forms support market function; sandwiching is directly harmful because it intentionally worsens a trader’s fill within their authorized slippage range.
  • A swap should be judged against a credible contemporaneous benchmark and its all-in result, not only the token output displayed before submission.
  • Slippage tolerance is a protection boundary, not a forecast and not a substitute for good routing.

Next, you will compare AMMs with on-chain order books and request-for-quote exchanges, using execution quality, liquidity, transparency, and trust assumptions as common criteria.

Concentrated Liquidity: Capital Efficiency and LP Risk
Comparing AMM, Order-Book, and RFQ Exchange Designs

Can't find a good explanation? Sign up and we'll make it for you

Sign up