GatorSwap All articles
Security

Your Swap Has an Audience: Inside the Sandwich Bots That Eat the Middle

GatorSwap
Your Swap Has an Audience: Inside the Sandwich Bots That Eat the Middle

Photo: BalticServers.com, CC BY-SA 3.0, via Wikimedia Commons

You click swap. The quote says you'll get 4,180 of something. Nine seconds later you get 4,061. You shrug, assume the market moved, and go make coffee.

It may not have moved. It may have been moved. Around you. On purpose.

This is the part of DeFi that never shows up in a tutorial video: the ninety milliseconds between your signature and your settlement, where a small industry of bots reads the queue of pending transactions and decides what to do about yours.

The anatomy of a sandwich

A sandwich is three trades stacked in one block, in a fixed order:

  1. The front-run. A bot sees your pending swap — say, a buy of token X on a pool where X is thin. The bot buys X first, pushing the price up.
  2. Your swap. It executes at the worse price the bot just created. You paid more than the quote promised.
  3. The back-run. The bot sells the X it bought seconds ago into the price you just pushed higher, and pockets the difference.

Nobody stole your keys. Nobody hacked a contract. Every transaction was valid and signed. The loss is just the price difference, spread across thousands of trades, mostly small enough that each individual trader blames volatility.

That's the design. A wound small enough to be mistaken for weather.

Why your slippage setting is the invitation

Here's the piece most traders never connect: the bot only profits if your trade will execute inside your slippage tolerance. Your tolerance is the maximum price movement you told the protocol you'd accept. To a searcher, that number is a budget.

Set it high and you're advertising how much room there is to extract. Wallets that default to 2% or 3% 'to make sure it goes through' are quietly handing out a 2–3% tax on every trade in a pool where they can get away with it. They can't take more than that, but they will take nearly all of it.

Two things follow. First, tight slippage is a security control, not an annoyance — a failed transaction costs you gas, while a sandwiched one costs you gas plus the spread. Second, if your swap keeps reverting at tight slippage, that's information: the pool is too thin for your size, and you should be splitting the order or finding a deeper route rather than loosening the setting.

Sizing is the other half

A bot needs your trade to move the price enough to be worth the gas and the risk of getting sniped itself. Small trades on deep pools aren't worth the effort. Large trades on thin pools are the whole business model.

So the practical question before any sizable swap is: how much of this pool am I? If your order is 1% of the pool, you're a rounding error. If it's 8%, you're the main course. Split large orders across time, routes, or venues and you stop looking like a target.

Reading the ripples in your own fills

You can spot the pattern without any block explorer gymnastics. Watch for these:

One bad fill is noise. A pattern in your log is a signal.

The defenses that work in 2026

Private transaction relays. Submitting through a relay or protected RPC keeps your transaction out of the public pending pool until it's already ordered. Bots can't sandwich what they can't see. Coverage isn't perfect on every chain, but on major venues it closes the front door.

Favorable ordering or batch design. Some routing systems match trades against each other at a uniform clearing price instead of first-come, first-served. If your trade can't be reordered in front of, the sandwich has nothing to build on. Aggregators increasingly expose this as a routing preference — look for it.

Tighter slippage, as noted. Set it deliberately, based on pool depth, and accept the occasional revert as the cost of not being lunch.

Off-peak timing. Bot activity intensifies when chains are busy and spreads widen. The quiet hours are quieter for everyone, including the bots. You are also paying less gas, which is the same advice we gave about swapping patiently, arriving from a different direction.

Limit orders instead of market swaps. If your strategy allows a resting order, you stop broadcasting intent to the entire queue.

Chain awareness. Sequencing differs across networks. Some layer-2s order transactions first-come-first-served at the sequencer, which changes the extraction playbook — it doesn't eliminate it. Assume the risk exists everywhere and verify per chain rather than assuming 'this one's safe'.

After you've been bitten

You can't reverse a sandwich. You can restrict the damage going forward: raise your slippage hygiene, route through protected channels, split oversized trades, and log your quote-versus-fill gap so you notice the next one earlier.

And keep some perspective. The gator that gets eaten is rarely the slowest one. It's the one that waded into shallow water and announced exactly how much room it needed.

All Articles

Related Articles

The Unbonding Window: What Happens When Your Staked Tokens Can't Swim

The Unbonding Window: What Happens When Your Staked Tokens Can't Swim

Four Times a Year, Gators Shed Teeth: Your 10-Minute DeFi Wallet Audit

Four Times a Year, Gators Shed Teeth: Your 10-Minute DeFi Wallet Audit

Bury It Deep, Keep One Eye Open: A Practical Cold Storage Setup for DeFi Traders

Bury It Deep, Keep One Eye Open: A Practical Cold Storage Setup for DeFi Traders