Pump — the buyback
How every swap can trigger a buyback inside its own transaction, and why it can't be sandwiched.
Behind every swap — a buy and a sell — afterSwap makes the pot spend secondary on main inside the swapper's own transaction and hands what it bought to the recipient. The spend is the smallest of four ceilings, then an 80% haircut.
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 demand is the measured secondary the swap actually moved — a dust trade can only ever unlock a dust pump, and the pot follows real volume instead of emptying all at once.
A swap, step by step
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 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. The fee ceiling itself needs no cooldown and no reference; the 10-minute EMA and the volume-paced bucket (next chapter) are extra ceilings on top. This is proven at sizes from dust to pool-scale in the test campaign, 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 —
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:
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.
This bound governs sandwiching the pump itself. A third party sandwiching an unrelated victim's buy is economically different (bounded — the pot still buys its main at fair price). It is written up in full in Security & audit as finding GH-1. The volume bucket and reference gate (next chapter) close the remaining farming surfaces.
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.
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
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, behind every swap that moves secondary — a buy of MAIN or a sell of MAIN — in the same transaction. No schedule, no keeper, no button.
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.