Automated market makers: work out what a swap returns
An automated market maker uses a pricing rule and available liquidity to exchange assets. It does not promise the latest market price for every token in your order. Learn why a larger swap changes its own price and how to check the final quote.
Your task: calculate one simple swap, distinguish price impact from slippage, and check the minimum amount received.
A swap changes the pool you trade against
Before: 1,000 A + 1,000 B
In this imaginary fee-free constant-product pool, x × y = 1,000,000. The initial marginal price is 1 B per A. A and B are example tokens, not recommendations.
Trade: add 100 A
The A reserve rises to 1,100. To preserve the product, the B reserve becomes 1,000,000 ÷ 1,100 = 909.09. The trader receives the difference: about 90.91 B.
After: a different price
The average execution is 0.9091 B per A. The new marginal price is about 0.8264 B per A. Neither is the original 1-to-1 quote. Larger trades relative to depth move the price further.
Walkthrough: turn the model into a quote check
Identify the route
Check network, token contracts and the pools used by the router. One trade may cross several pools or split between routes. Not every DEX uses an AMM, and not every AMM uses this formula.
Read the actual costs
Compare the input, estimated output, pool fees, price impact and network cost. With a 0.3% input fee in our example, only 99.7 A enters the pricing calculation, returning about 90.66 B. Actual fees depend on the pool and version.
Set a meaningful boundary
Read minimum received and the transaction deadline where available. Slippage tolerance allows execution to differ from the quote; it does not remove the impact already in it. Check approval permissions separately and reject unexpected wallet requests.
Worked example: output is the change in reserves
For input Δx, the fee-free output is y − k ÷ (x + Δx). The 90.91 B result is about 9.09% below the 100 B a constant 1-to-1 price would suggest. This is price impact from the trade itself. Slippage is the difference between the quoted outcome and actual execution. k is a reserve-product constraint, not the pool’s dollar value; deposits, withdrawals and retained fees can change it.
Three shortcuts that give the wrong answer
Using total TVL as depth
Concentrated liquidity operates in price ranges: a large TVL may include inactive positions. Weighted and stable-asset pools use different curves. Use the current executable route quote, not this simplified formula for every pool.
Raising tolerance to fix a poor price
A wider tolerance permits a worse result; it does not improve liquidity. Compare another route or a smaller amount, including all fees. Splitting a trade through an unchanged pool does not magically eliminate its cumulative impact.
Assuming arbitrage guarantees fairness
Traders can move pool prices toward other markets by seeking price differences. That is an incentive, not a guarantee. Thin liquidity, fees, latency and transaction ordering can leave a quote unattractive or expose it to MEV.
Try it: increase the order size
Reset the fee-free pool to 1,000 A and 1,000 B. Swap 250 A. How much B comes out, what is the average B per A, and what minimum would a 1% tolerance give on that quote?
Reveal the reasoning
New B reserve: 1,000,000 ÷ 1,250 = 800. Output: 200 B. Average: 200 ÷ 250 = 0.8 B per A. A 1% tolerance gives 198 B minimum. The trade’s 20% shortfall against the initial spot price already exists before that tolerance is applied.



