Bottom line: A 0.5% slippage constant is wrong in both directions — too loose on deep pools, guaranteed to revert on shallow ones. Compute the price impact from reserves and set the tolerance from that plus a small buffer.

Constant-product impact

For x·y = k, swapping dx moves the price by:

impact = dx / (x + dx)

On a 100,000 USDC / 50 WETH pool, a 2,000 USDC swap is 2000/102000 = 1.96%. The same swap on a 5M pool is 0.04%. One constant cannot serve both.

Compute before sending

1
2
3
4
5
def impact(dx, reserve_in):
return dx / (reserve_in + dx)

tol_bps = int(impact(dx, r_in) * 10_000) + 30 # 30 bps buffer
amount_out_min = quote * (1 - tol_bps / 10_000)

Read reserves with getReserves() on V2 or from the V3 state at the tick. Refresh immediately before sending — a stale reserve under-reports impact when someone else traded first.

Concentrated liquidity has a curve

On V3, impact is flat inside the current tick range and jumps at the boundary. A quote that crosses ticks is far worse than the linear estimate. Simulate with the router’s quoter contract instead of approximating when the swap exceeds roughly 10% of the in-range liquidity.

Reading the revert

INSUFFICIENT_OUTPUT_AMOUNT means the floor was missed. It is a pricing signal, not a knob: raise the tolerance by 20 bps, retry, and if it reverts again the pool moved under you — re-quote rather than widening further.

When to split

If computed impact exceeds 3%, split into tranches of about 1% impact each, spaced far enough apart to re-quote. Three tranches beat one 9%-impact swap by a wide margin on both price and revert rate.

What not to do

Setting 5% tolerance as insurance against reverts. On a $10k swap a 5% ceiling invites a sandwich worth up to 5% and you hand it over for free. Tight tolerance plus retry is strictly better than a loose ceiling.

Operating notes

Compute impact from reserves at send time, in the same code path as the broadcast, and refresh reserves immediately before signing. A quote older than one block under-reports impact exactly when it matters.

1
2
3
r_in, _ = pair.getReserves()
imp = dx / (r_in + dx)
tol = int(imp * 10_000) + 30

The 30 bps buffer absorbs integer rounding and one competing trade. Above 3% computed impact, split into tranches of about 1% each and re-quote between them.

Concentrated liquidity

Do not use the linear formula past roughly 10% of in-range liquidity on a V3 pool — impact is flat inside a tick and jumps at the boundary. Use the quoter contract for those sizes; it simulates the tick walk.

Revert handling

INSUFFICIENT_OUTPUT_AMOUNT is a price signal. Raise the tolerance by 20 bps and retry once; a second revert means the pool moved and the answer is a re-quote, not a wider ceiling. Two reverts in a row with a widening tolerance is how a 5% ceiling happens by accident.

Post-trade check

Compare realised output against the pre-trade quote. A gap consistently larger than the computed impact means someone front-ran the path and the private-mempool threshold needs revisiting.

FAQ

How do I calculate slippage from pool reserves?

For a constant-product pool, impact equals dx / (x + dx), where dx is the swap size and x is the input reserve. On a 100,000 USDC / 50 WETH pool, a 2,000 USDC swap gives 2000/102000 = 1.96%. Add a 30 bps buffer to that computed impact to get your tolerance.

Why is a fixed 0.5% slippage tolerance a problem?

One constant cannot serve both deep and shallow pools. The same 2,000 USDC swap is 1.96% impact on a 100,000 USDC pool but 0.04% on a 5M pool. A fixed tolerance is too loose on deep pools and guaranteed to revert on shallow ones.

What does INSUFFICIENT_OUTPUT_AMOUNT mean and how should I handle it?

It means the floor was missed — it is a pricing signal, not a knob. Raise the tolerance by 20 bps and retry once. If it reverts again, the pool moved under you, so re-quote rather than widening further.

When should I split a swap into tranches?

Split when computed impact exceeds 3%, into tranches of about 1% impact each, spaced far enough apart to re-quote. Three tranches beat one 9%-impact swap on both price and revert rate. Re-quote between tranches.

Why not just set a 5% tolerance to avoid reverts?

On a $10k swap a 5% ceiling invites a sandwich worth up to 5%, which you hand over for free. Tight tolerance plus retry is strictly better than a loose ceiling. Two reverts with a widening tolerance is how a 5% ceiling happens by accident.