Ordering and slippage
How transaction ordering affects a pool trade, and how slippage limits keep every trade in bounds.
The problem#
The producer sees every pending pool intent, including its public minimum out. It can place its own trades right before and after yours without risk, paying the pool fee like anyone else.
The sandwich#
The producer buys first, includes your buy, then sells. It can push you down to exactly your minimum out. In the worked cases in the engineering analysis:
- If your minimum out equals the exact quote, no sandwich fits, but any other trade landing first makes your trade fail.
- With any tolerance, a sandwich is profitable exactly when your input exceeds the pool fee rate times the pool's effective quote reserve. Below that, the fee on the front-run costs more than can be taken.
- When it is profitable, you lose the whole tolerance: the gap between the quote and your minimum. Your loss never exceeds that gap. That bound is the only protection, and your wallet sets it.
- A sell is the mirror image; the producer needs token inventory.
That is why the wallet's default tolerance is low (0.5%) and why you should keep it low.
Other things that are possible#
- Griefing. Anyone, not only the producer, can move the price just past your bound so your trade is refused, then trade back. In the analysed example (1% fee, 0.5% tolerance) this cost the attacker a round-trip loss of about 2% of the front-run size. You lose a proof's time, not funds. The intent stays valid until it expires, so it can still succeed if the price returns.
- Launch sniping. Whoever is ordered first at a new pool gets the launch price. In the analysed example, a larger buy placed first left the creator's buy with 29% fewer tokens.
- Holding and censoring. A producer can hold your intent and include it only when later trades make that favourable (limited by your intent's lifetime), reorder in favour of its own or a paying trader's intent, or refuse a pool or a transaction.
What is not possible#
Changing an intent's input, side, pool or recipient; paying you less than the formula gives at the state it is applied; applying an intent twice.