chapters· Pump
07 · Buy back

Pump — the buyback

How buys trigger buybacks inside their own transaction, and why it can't be sandwiched.

On a SECONDARY → MAIN buy, afterSwap makes the pot buy more main inside the buyer's own transaction and hands it to the recipient. The sizing rule is one line — and that one line is the entire anti-sandwich model.

the sizing rule
// the slice this buy unlocks unlocked = min(pot, fee·depth, the secondary this buy actually paid) // the safety haircut keeps the spend strictly // inside the sandwich break-even spend = unlocked · 80%

Nothing in that line is hardcoded to a pool shape: fee·depth is computed live as the pool's current swap fee times its tangent reserve at the live price — so a deeper pool or a fatter fee tier earns a proportionally larger pump, automatically. And userIn is the measured secondary leg of the buyer's own swap delta, not a re-quote — a dust buy can only ever unlock a dust pump, and the pot follows real demand instead of emptying all at once.

A buy, step by step

user swaps SECONDARY → MAIN
pool executes the user's swap· user pays the pool fee
afterSwap: pot spends ≤ 80% of the unlocked slice
pot's MAIN → recipient (or the burn cascade)

Why it can't be sandwiched — the actual math

The sandwich shape: an attacker opens with a buy of size X to summon the pump, the pump of size V lands behind it, and the attacker closes by dumping the bag into the price bump they financed. Model the pool as depth R (the tangent reserve at the live price) with fee f. To leading order:

the break-even, derived
// gross price-impact profit of bracketing a pump of size V profit ≈ 2·X·V / R // the attacker pays the pool's fee on BOTH legs fees ≈ 2·f·X // profitable ⟺ 2·X·V/R > 2·f·X ⟺ V > f·R // the attacker's own size X cancels out entirely

The attacker's size cancels out of the inequality — so one single bound on the pump's spend closes the attack for every attacker size, pot depth and price at once. The hook caps the pump at f·R and then takes only 80% of it, putting the realised spend at 0.8·f·R — strictly inside the break-even. No cooldown, no per-swap state, no reference price. This is proven at sizes from dust to pool-scale in the test campaign (test_A2), and it is exactly why a zero-fee pool never pumps: with f = 0 the ceiling is zero, and the design refuses to host a sandwichable buyback.

Intuition for the same thing: forcing a bigger pump requires a bigger real buy, which pays the pool's fee and impact twice — and the haircut means the pump moves the price by less than the attacker paid to trigger it. The "attack" is self-financing a donation to the pool's LPs, while the pot gets its tokens at market price either way.

The 80-cent theorem

Push the derivation one step further and the haircut turns into a statement you can quote: substitute the hook's actual spend V = 0.8 · min(f·R, X) into the profit formula and divide by the fee bill —

the attacker's recapture ratio, both regimes
// big attacker (X ≥ f·R): the cap binds profit/fees = (2X · 0.8fR/R) / (2fX) = 0.80 // small attacker (X < f·R): their own size binds profit/fees = (2X · 0.8X/R) / (2fX) = 0.8·X/(f·R) < 0.80

Every sandwich round-trip against the pump recovers at most 80 cents of every fee dollar it pays — a guaranteed loss of at least 20% of the fee bill, at every attacker size, every pot depth, every price, before gas. There is no size to optimize toward: the ratio is flat at 0.8 for everyone big enough to hit the cap, and strictly worse below it.

Worked numbers & the impact ceiling

R is the tangent reserve: the reserve an equivalent constant-product pool would show at the pool's live price and liquidity (L·√P on the secondary side). With it, everything above becomes concrete:

a 0.30% pool with 500 ETH of tangent depth
cap = f·R = 0.003 · 500 = 1.5 ETH max spend = 0.8·f·R = 1.2 ETH per buy max impact ≈ 2V/R = 2·1.2/500 = 0.48% // in general: 2V/R ≤ 2·(0.8·f·R)/R = 1.6·f // the pump can NEVER move the price by more than 1.6× the pool's fee

That last line is the second theorem hiding in the sizing rule: on any pool, the pump's price move is bounded by 1.6× the fee tier — 0.48% on a 0.30% pool, 1.6% on a 1% pool — per buy, no matter how large the pot is. The pot expresses itself as a steady stream of small, fee-bounded buybacks riding real demand, not as one visible candle a bot can hunt.

the adjacent surfaces, honestly

This bound governs sandwiching the pump itself. Two adjacent surfaces — a third party sandwiching an unrelated victim's buy, and a self-sandwicher dumping through a partially-absorbing shield — are economically different (bounded, and in every posture the pot still buys its main at fair price). They are written up in full in Security & audit as finding GH-1.

two more properties, free

The buyer pays the pump's gas — executing inline in afterSwap means there is no separate transaction to front-run. And the pump runs through a try/catch self-call, so a pool state that would revert the buyback skips the pump instead of reverting the buyer.

zero-fee pools never pump

A fee-less pool makes round trips free, which breaks the sandwich arithmetic above. The hook refuses to pump on them by design — pick any non-zero fee tier.

Quoting a pump

// what would the pot do alongside a 1-ETH buy, right now? (uint256 spend, uint256 minOut) = hook.quotePump(key, 1 ether);

quotePump mirrors the live decision against current pool state — a UI, a bot or a test can preview the machine without executing a swap. The live pump enforces minOut on itself: if execution would deliver less, it abandons the round (QuoteMismatch semantics) rather than overpay.

FAQ

When does a pump fire?+

In afterSwap, inside a buy of MAIN, in the same transaction. No schedule, no keeper, no button — the buy itself is the trigger.

Why can't the pump be sandwiched?+

The spend is proportional to the carrying buy and capped, so a dust buy only unlocks a dust pump. Front-running it means pushing the price up before your own tiny unlock — the attacker pays more than they can extract.

What price does the pump pay?+

The pool's own execution price at that moment, fees and tick impact included. There is no oracle to manipulate — the pot trades against the same curve as everyone else.

Where does the bought MAIN go?+

Through the buyback split: a configurable share is compounded into the LP program's liquidity, a share is burned through the cascade, and the exact rest is delivered to the pot's recipient (0x0 = burn it all).

Can a pump ever make my swap fail?+

No. The pump body is wrapped so any internal failure is swallowed and the carrying swap lands normally — the machine can only ever add to a trade, never block one.