Foundations · Exchanges, DEX & DeFi
Swaps & Routing
A swap exchanges one token for another through liquidity pools. Routing chooses which pools to use, and slippage tolerance sets the worst result the trader accepts before the swap reverts.
Why it matters
A swap screen shows a handful of numbers: an expected amount, a price impact, a minimum received and a route. Each one describes a different way that the amount a trader ends up with can differ from the price on display. Reading them apart is the difference between understanding a swap and guessing at it.
How it works
- QuoteThe interface reads the pools and shows an expected amount.
- Set a floorSlippage tolerance fixes the minimum amount to receive.
- Sign and sendThe transaction waits to be included in a block.
- Settle or revertFloor met: the swap completes. Floor missed: it fails and gas is still paid.
A swap is a single transaction that sends one token into one or more liquidity pools and takes another token out. The interface first simulates the trade against the pools’ current balances and shows a quote.
The quote is not a promise. Other people’s transactions can be processed first and change the pools before this one arrives. So the transaction carries a floor: the smallest amount of the output token the trader is willing to accept. If the pools can no longer deliver that amount, the contract cancels the swap. The trader keeps the original tokens and still pays the gas.
Three numbers on a swap screen
| Number | What it describes | Known in advance? |
|---|---|---|
| Expected output | What the swap would return if nothing changes before it is processed | Estimate only |
| Price impact | How far the trader’s own order moves the pool price | Yes, from pool size and trade size |
| Minimum received | Expected output reduced by the slippage tolerance | Yes, it is enforced |
Price impact and slippage are often confused. Price impact is caused by the trade itself. Slippage is the change between the quote and the execution, caused by everything else that happens in between.
Slippage tolerance is the maximum such change the trader accepts, set as a percentage. A tolerance of 0.5% on a quote of 100 tokens gives a minimum received of 99.5.
In plain words
It works like telling a currency desk: “Change this for me, but only if I get at least 99.5. Otherwise hand my money back.” The desk keeps a small service charge either way.
Routing
SPLIT
One trade divided between several pools of the same pair.
- Less price impact in each pool
- More steps, so more gas
MULTI-HOP
A chain of swaps through an intermediate token.
- Used when no direct pool exists, or the direct pool is thin
- A fee and price impact at every hop
There are often several pools for the same pair, and many pairs have no direct pool at all. Routing is the search for the combination of pools that returns the most output. A DEX aggregator is a service that runs this search across many exchanges at once.
Splitting helps because price impact grows with trade size relative to each pool. Two half-sized trades in two pools each move their price less than one full-sized trade in one pool. Every extra step costs gas, so for a small swap the simplest route can still be the cheapest overall.
Going deeper
Transaction ordering. A swap that is waiting to be processed can often be seen by others. A third party can place one trade just before it, pushing the price up to the trader’s floor, and another just after, pocketing the difference. This is commonly called a sandwich. A wide slippage tolerance leaves more room for it. A very narrow one makes the swap more likely to fail.
Deadlines. Swap transactions usually carry an expiry time, so that a transaction stuck for hours is not executed at a stale price.
Awkward tokens. Some tokens deduct a charge on every transfer or restrict selling. Swaps involving them can fail at normal tolerance settings, which is also a warning sign described in rug pulls and honeypots.
Approvals. A router contract needs a token approval before it can move the input token.
Where the fee goes. The swap fee is paid mostly to the pool’s liquidity providers. For them it is a variable receipt that is not guaranteed, is often supplemented by a token whose price can fall, and comes with the risks of the pool.
A hypothetical swap with a fee and a floorHypothetical illustration
Made-up numbers. A pool holds 1,000 A and 100,000 B, so A is priced at 100 B and k = 100,000,000. The swap fee is 0.3%. A trader swaps in 1,000 B.
- Fee: 0.3% of 1,000 = 3 B. The remaining 997 B is priced by the curve.
- B balance used for pricing: 100,000 + 997 = 100,997.
- Required A balance: 100,000,000 / 100,997 = 990.128.
- Expected output: 1,000 - 990.128 = 9.872 A.
At the starting price, 1,000 B would be 10 A. The quote is about 1.3% lower: 0.3% from the fee and about 1% from price impact.
With a slippage tolerance of 0.5%, the minimum received is 9.872 × 0.995 = 9.823 A.
- If the pools change so that the swap would return 9.85 A, it completes, and the trader receives 9.85 A.
- If it would return 9.80 A, that is below 9.823, so the swap reverts. The trader keeps the 1,000 B and pays the gas.
What it does NOT mean
- The quote is not the amount you will receive. It is an estimate. Only the minimum received is enforced.
- Low price impact does not mean low cost. Fees and gas are charged on top of it.
- The “best route” is not the best possible price. It is the best one the router found among the pools it searched, at that moment.
- A higher slippage tolerance is not a harmless way to make a swap go through. It widens the range of prices at which the trade can be executed against the trader.
- A reverted swap is not free. The network fee is spent whether or not the swap completes.
Common misunderstandings
- Mixing up price impact and slippage. One comes from the size of the order, the other from changes before execution.
- Raising tolerance until the swap works. Repeated failures can point to a thin pool or a restricted token, not to a setting that is too tight.
- Ignoring gas on small swaps. A route that saves 0.2% is no saving if the extra gas costs more than that.
- Assuming routes are neutral. The interface or aggregator chooses the path and may add its own fee.
Risks and limits
- Each contract in a route is another piece of code that has to work. See smart contract risk.
- Thin pools along a multi-hop route can make the final price far worse than either token’s headline price suggests.
- Ordering by third parties can move execution to the edge of the tolerance.
- Network congestion can delay a swap until it reverts, or raise gas sharply.
- A confirmed swap cannot be undone.
Key takeaway
A swap quote is an estimate, shaped by fees, price impact and the route chosen. Slippage tolerance turns it into a floor: the contract either delivers at least that much or cancels the trade.
Sources and further reading
- Understanding Swaps on Uniswap (opens in a new tab), Uniswap Labs. Price impact, slippage tolerance and swap fees paid to liquidity providers
- Auto Router V2 (opens in a new tab), Uniswap Labs (2021). The router splits a trade across several pools and only adds splits when they improve the net rate after gas
- Ethereum gas and fees: technical overview (opens in a new tab), ethereum.org. Gas fees are paid in ether and are tied to the computation performed
- Maximal extractable value (MEV) (opens in a new tab), ethereum.org. Transaction ordering can be exploited through frontrunning and sandwich attacks on trades