Skip to content
Finance Lessons

On-chain Arbitrage & Cross-DEX MEV

Atomic Bundles & Flash Loans

Packaging every leg of an arbitrage into one all-or-nothing transaction, and borrowing the entire stake inside that transaction so capital stops being the barrier — plus what atomicity does and does not protect you from.

10 min Updated Jun 18, 2026

You found a 0.5% loop across three pools. Now comes the terrifying middle: you’ve bought the first leg, you’re holding inventory, and the price could move against you before you close the trade. On a normal exchange that gap is where dreams go to die. On-chain, there’s a trick that makes the gap literally impossible — and a second trick that means you don’t even need the money to do it. This lesson is about both.

The bundle: one transaction, all legs

Before you read — take a guess

You buy ETH on pool A, then plan to sell it on pool B one block later. What's the danger in that one-block gap?

Think of a relay race where the runners are handcuffed together: either the whole team crosses the line or none of them move at all. There’s no scenario where one runner finishes and the rest are left stranded mid-track. That’s atomic execution.

An atomic bundle packs every leg of your arbitrage — buy on A, sell on B, and any extra hops in between — into a single transaction that the EVM runs as one indivisible unit. The contract executes the legs in order, then checks: did I end up with more than I started? If yes, the transaction commits and you keep the profit. If no, the transaction reverts — every state change is undone as if nothing happened.

The sequence inside one atomic transaction looks like this:

  1. Buy ETH on pool A (cheap).
  2. Sell that ETH on pool B (dear) — and any intermediate hops if it’s a triangular loop.
  3. Check the final balance: is profit greater than zero (after costs)?
  4. If yes, commit. If no, revert() — the buy on A is unwound too, and you never held the inventory.

The magic is step 4. Because the whole thing reverts on a failed profit check, you can never get stuck having done leg one but not leg two. The searcher never holds inventory between blocks, never wakes up to a position that moved against them. The risk that haunts every off-chain trader — “I bought, then the market ran away before I could sell” — is engineered out of existence.

Info:

Revert is a feature, not a failure

Off-chain, a half-finished trade is a real, money-losing event you have to clean up. On-chain, a half-finished bundle simply doesn’t exist — the EVM rewinds the tape. “It reverted” means “it cost gas and nothing else happened,” which is a wildly better failure mode than “I’m now long ETH I didn’t want.”

Fill in how atomicity protects the searcher.

Choose the correct option for each blank and check.

An atomic bundle runs all legs as one transaction. If the final profit check fails, the whole thing , so the searcher never ends up between legs.

When it matters

Atomicity is what turns a fragile multi-step arbitrage into a single safe bet. It’s why on-chain searchers can chase razor-thin spreads that no off-chain trader would touch: the downside of a missed leg isn’t a loss, it’s a wasted gas fee. Every strategy in the rest of this course assumes the legs are bundled — it’s the bedrock.

Flash loans: rent the whole stake for one block

Before you read — take a guess

A profitable arbitrage needs 100,000 USDC of capital you don't have. On a normal exchange you're stuck. What does a flash loan let you do?

Imagine a bank that hands you a million dollars at the door, on the condition that you walk a loop through the building and hand it all back — plus a small tip — before you reach the exit. If you can’t return it by the exit, the security cameras rewind and it’s as if you never walked in. No collateral, no credit check, because the bank physically cannot lose: the door won’t open until you’ve repaid.

A flash loan is exactly that. You borrow a large sum with no collateral, on the sole condition that it’s repaid before the same transaction ends. If repayment fails, the entire transaction reverts — the loan, your trades, all of it — as if it never happened. Because repayment is enforced atomically (same trick as the bundle), the lender takes on zero default risk and can lend to a complete stranger.

The economic consequence is enormous: capital stops being the barrier to entry. You no longer need a war chest to run a big arbitrage. You borrow the entire stake for the duration of one block, run your atomic loop, repay the loan out of the proceeds, and keep whatever’s left. What decides the winner is no longer how much money you have — it’s speed and search quality: who spots the opportunity and lands the bundle first.

Lenders don’t do this for free. A typical flash-loan fee is 0.05% — that’s 5 basis points — charged on the borrowed amount and paid back alongside the principal inside the same transaction.

Match each flash-loan property to what it means.

Pick a term, then click its definition.

When it matters

Flash loans democratized MEV. A teenager with a clever bot and a laptop can deploy the same capital as a hedge fund — for the length of one transaction. That’s why on-chain arbitrage competition is brutal and margins are thin: the moat that protected the well-capitalized everywhere else simply doesn’t exist here.

Worked: capital-free arbitrage

Before you read — take a guess

You borrow 100,000 USDC via flash loan and run a loop that returns 0.5% gross. Roughly how much gross profit does the loop produce, before the loan fee?

Let’s run the numbers from the triangular-arbitrage loop you priced earlier, now financed entirely with borrowed money. You bring almost none of your own capital to the table.

StepAmount
Flash-loan principal borrowed$100,000
Gross return from the 0.5% loop+$500
Flash-loan fee at 0.05% (5 bps) on $100,000−$50
Profit before gas≈ $450

Walk it through: you borrow $100,000 of USDC with no money down. You run the atomic loop and it returns 0.5%, which is $500 gross. You repay the principal plus the 0.05% fee — that fee is $50 on a $100,000 loan. What’s left in your pocket, before paying gas, is about $450.

The headline isn’t the $450 — it’s whose $450 it is. You captured a $450 edge having staked almost none of your own capital. The flash loan supplied the entire $100,000; your only out-of-pocket cost is the gas to submit the transaction. That is the whole reason on-chain arbitrage looks nothing like its off-chain cousin: the capital requirement collapsed to roughly zero.

Warning:

The fee scales with the loan, the edge with the spread

Notice the fee ($50) is fixed by the loan size, while the gross profit ($500) is fixed by the spread. Borrow more than your loop can profitably deploy and the 0.05% fee starts eating a thin edge alive. The flash loan is free leverage, not free money — size it to the opportunity, not to the lender’s limit.

Sort each line of the worked example by what it represents.

Place each item in the right group.

  • The 500 USDC return from the 0.5% loop
  • The 50 USDC flash-loan fee
  • Gas paid to submit the transaction
  • The 0.5% edge captured across the pools

When it matters

This is the math that explains why MEV is a high-volume, low-margin grind. When capital is free, everyone can chase the same $450, so the edge gets bid down to the thinnest sliver that still beats gas and the loan fee. The winner isn’t the richest — it’s the one whose bundle is cheapest to run and fastest to land.

What atomicity does NOT protect you from

Before you read — take a guess

If your bundle reverts because a profit check failed, what did it still cost you?

Here’s where overconfidence kills accounts. It’s tempting to read “atomic = the whole thing reverts if it’s not profitable” as “atomic = risk-free.” That’s only half true, and the missing half is where searchers actually lose money. Atomicity is a fortress against exactly one danger — inventory risk — and offers nothing against the others.

Three risks survive atomicity entirely:

  1. Gas on a reverted attempt. Revert refunds your trades, not your gas. Every failed bundle still burns the gas spent computing it. Fire a hundred speculative attempts that all revert and you’ve paid a hundred gas bills for zero profit.
  2. Outbid or not included. A block builder chooses which bundles go in and in what order. A competitor offering a juicier payment can outbid you, or the builder may simply leave your bundle out. Atomicity guarantees your bundle is correct, not that it’s chosen.
  3. The opportunity vanishes. If a competitor’s transaction lands first and changes the pool state, the gap you targeted may be gone by the time your bundle runs. Your profit check then fails — correctly — and you revert, having paid gas to discover the edge evaporated.

So atomicity kills inventory risk stone dead. It does nothing about competition risk or gas-on-failure. Confusing “my trade can’t get stuck half-done” with “my trade can’t lose” is the classic rookie error.

Warning:

'Atomic' means safe inventory, not guaranteed profit

A reverted bundle is not a free undo. You still pay gas, you can still be outbid or excluded by the builder, and the opportunity can vanish before your transaction lands. Atomicity removes the risk of holding a half-finished position — it does not remove the risk of competition or the cost of trying. Budget for failed attempts, because there will be many.

A searcher submits 50 bundles in an hour. 45 revert because faster competitors changed the pool state first; 5 succeed. What's the most accurate description of the 45 reverts?

When it matters

This is the line between a searcher who survives and one who quietly goes broke. The survivor prices in gas-on-failure and competition, simulates aggressively before submitting to avoid doomed bundles, and only fires when the expected win clears the expected cost of trying. “It’s atomic, so I can’t lose” is the epitaph on a lot of dead bots.

Recap

Big picture

Atomic bundles and flash loans, in one map

  • Atomic arbitrage
    • The bundle
      • All legs in one transaction
      • Runs as an indivisible unit
      • Failed profit check reverts all
      • Never stuck holding inventory
    • Flash loans
      • Borrow large sum no collateral
      • Repay before transaction ends
      • Typical fee 5 basis points
      • Capital stops being the barrier
    • Worked example
      • Borrow 100000 USDC
      • Gross 500 from the loop
      • Pay 50 loan fee
      • About 450 before gas
    • What it does not stop
      • Gas on a reverted attempt
      • Outbid or excluded by builder
      • Opportunity vanishing first
From all-or-nothing execution to what it can and cannot protect.

Atomic bundles & flash loans — final check

Question 1 of 60 correct

What does packaging every leg of an arbitrage into one atomic transaction guarantee?

Check your answer to continue.

Mark lesson as complete