---
title: Atomic Arbitrage in DeFi
url: https://www.emergentmind.com/topics/atomic-arbitrage-aa
type: topic
---

# Atomic Arbitrage in DeFi

Searching arXiv for the cited Atomic Arbitrage literature and related papers.
arxiv_search(query="Atomic Arbitrage AMM closed-form solutions generic N-token arbitrage 2402.06731", max_results=5)
arxiv_search(query="Closed-form solutions for generic N-token AMM arbitrage", max_results=10)
{"query":"Closed-form solutions for generic N-token AMM arbitrage", "max_results": 10}
Atomic Arbitrage (AA) most commonly denotes a multi-leg arbitrage whose entire execution is bundled into a single blockchain transaction, so that either every leg settles and the profit condition holds, or the transaction reverts. In decentralized-exchange and automated-market-maker research, this notion covers cyclic arbitrage across pools, price-convergence trades between AMMs and external venues, and basket trades in multi-asset CFMMs [2105.02784][2403.16083][2402.06731]. A distinct usage in mathematical finance studies “atomic arbitrage” created by insider information taking values on finitely many atoms; that usage is conceptually separate from blockchain execution semantics, even though the terminology overlaps [1608.02068].

## 1. Definition and terminological scope

In recent blockchain studies, AA is usually formalized as a transaction-level property. An on-chain transaction \(T\) is classified as atomic arbitrage if and only if three conditions hold: it executes at least two swaps, the net balance change is non-negative for every asset in the route, and the transaction’s net profit after protocol fees \(\tau\) and priority bids \(\beta\) is strictly positive. In compact form,
\[
\mathrm{AA}\Longleftrightarrow (N\ge 2)\wedge \bigl[\forall A,\;\Delta(A)\ge 0\bigr]\wedge \Bigl[\sum_A \Delta(A)P(A)-\tau-\beta>0\Bigr].
\]
This criterion is used in large-scale Polygon analyses to detect AA in block data [2508.21473][2604.27979].

Within DEX theory, AA is often a cyclic arbitrage: a multi-step trade that starts and ends in the same token and exploits price discrepancies around a cycle of liquidity pools. For tokens \(A_1,\dots,A_n\), the cycle
\[
A_1 \xrightarrow{\delta_1} A_2,\quad
A_2 \xrightarrow{\delta_2} A_3,\;\dots,\;
A_n \xrightarrow{\delta_n} A_1'
\]
is profitable when the final amount exceeds the initial amount [2105.02784]. In A2MM, the term is specialized further to a two-step cycle across two AMMs: swap \(\Delta_x\) of asset \(X\) for \(\Delta_y\) of \(Y\) on one AMM, then immediately swap \(\Delta_y\) back to \(\Delta_x'\) on another, with \(\Delta_x'-\Delta_x>0\) [2106.07371].

The older mathematical-finance usage differs materially. There, the “atomic” object is not a transaction but an atom of information \(G\in\{g_1,\dots,g_n\}\) known to an insider at time zero. In a complete market, the insider can super-hedge \(1_{\{G=g_i\}}\) for an initial capital strictly less than \(1\), yielding strong arbitrage on that atom while NUPBR can still hold [1608.02068]. This suggests that the phrase “atomic arbitrage” is polysemous: in DeFi it denotes all-or-nothing execution, whereas in enlargement-of-filtration theory it denotes arbitrage tied to atomic information.

## 2. Atomicity as an execution primitive

The core operational property of AA on-chain is all-or-nothing execution. In cyclic DEX arbitrage, packaging all swaps into one transaction eliminates partial-fill risk: if the final condition \( \mathrm{profit}\ge 0 \) is not met, the EVM reverts the entire transaction, so no intermediate leg settles except for gas expenditure [2105.02784]. This rollback property is the main reason AA is modeled as safer than sequential multi-leg execution.

A canonical implementation is a custom smart contract that computes the route, checks profitability, and then executes the swap sequence. One documented pattern is:
```solidity
function atomicArb(
    uint256 amountIn,
    address[] memory path
) external {
    uint256[] memory amounts = router.getAmountsOut(amountIn, path);
    require(amounts[path.length-1] > amountIn, "No profit");
    for (uint i = 0; i < path.length-1; i++) {
        IPair(pairFor(path[i], path[i+1]))
          .swap(
              i==0 ? amounts[1] : 0,
              i>0 ? amounts[i] : 0,
              address(this),
              new bytes(0)
            );
    }
}
```
This design captures the minimal AA logic for cyclic arbitrage on Uniswap-style pools [2105.02784].

In multi-asset G3M pools, AA is generalized from a path of pairwise swaps to a single basket trade. The trade is represented by a net vector \(\Phi=\Delta-\Lambda\), and all token legs are packaged into one CFMM `swap` call. Because the closed-form solution enforces the pool invariant with equality, the transaction crosses the CFMM boundary once and leaves pool and market prices in perfect equilibrium, with no residual arbitrage kink [2402.06731]. The documented router flow is: transfer inbound tokens \(\{i\mid \Phi_i>0\}\), call `swapExactTokensForTokens` with a custom multi-asset path encoding \(\Phi^*\), and receive outbound tokens \(\{j\mid \Phi_j<0\}\) in the same transaction [2402.06731].

Atomicity becomes more subtle when one leg is off-chain. For AMM–CEX arbitrage, the theoretical model treats the trade as if both legs are wrapped into one atomic arbitrage call, but the same work explicitly notes that off-chain CEX execution cannot literally be in the same EVM transaction; in practice, traders pre-fund CEX accounts or use pegged derivatives [2403.16083]. A common misconception is therefore that “atomic” always means cross-venue simultaneity in a literal execution sense. In cross-domain settings, atomicity is often an economic abstraction rather than a strict settlement fact.

## 3. Mathematical models and optimal trade sizing

The simplest AA model in AMMs is the cyclic constant-product framework. For each pool \(j\) swapping \(A_j\to A_{j+1}\), reserves are \((R_j,R_j')\), the fee factor is \(f\in(0,1)\), and the swap function is
\[
\Delta y
= S_j(\Delta x)
= \frac{f\,\Delta x \, R_j'}{R_j + f\,\Delta x}.
\]
If the cycle output is \(\Delta x_n\), profit is
\[
U(\Delta x_0)=\Delta x_n-\Delta x_0.
\]
A small-input cyclic arbitrage exists if and only if
\[
\prod_{j=1}^n \frac{R_j'}{R_j} > f^{-n},
\]
equivalently \(U'(0)>0\). The optimal input \(\Delta x_0^*\) is unique and can be written in terms of equivalent reserves \(a,a'\) as
\[
\Delta x_0^*=\frac{1}{f}\Bigl(\sqrt{f^n a a'}-a\Bigr).
\]
This framework formalizes classical triangular and higher-order DEX cycles [2105.02784].

A more general formulation appears for \(N\)-token geometric-mean market makers. Let reserves be \(R=(R_1,\dots,R_N)\in\mathbb{R}_+^N\), weights \(w=(w_1,\dots,w_N)\) with \(w_i>0\) and \(\sum_i w_i=1\), invariant
\[
k=\prod_{i=1}^N R_i^{w_i},
\]
and fee credit fraction \(\gamma\in(0,1)\). A trade \((\Delta,\Lambda)\) is accepted iff
\[
\prod_{i=1}^N (R_i+\gamma \Delta_i-\Lambda_i)^{w_i}\ge k.
\]
Writing the net trade as \(\Phi:=\Delta-\Lambda\) and \(d_i=1\) if \(\Phi_i>0\) else \(0\), the equality frontier is
\[
\prod_{i=1}^N \left(1+\gamma^{d_i}\Phi_i/R_i\right)^{w_i}=1.
\]
For an active set \(A=\{i\mid s_i\neq 0\}\), normalized weights \(\hat w_i=w_i/\sum_{j\in A}w_j\), and
\[
K=\prod_{\ell\in A} R_\ell^{\hat w_\ell},
\]
Appendix A yields the closed-form optimal trade
\[
\Phi_i
=
\gamma^{-d_i}\left[
K\cdot (\hat w_i\gamma^{d_i}m_{p,i})^{1-\hat w_i}
\cdot
\prod_{j\in A,\;j\neq i}
\left(\frac{m_{p,j}}{\hat w_j\gamma^{d_j}}\right)^{\hat w_j}
-
R_i
\right].
\]
This converts AA from a numerical optimization problem into signature enumeration plus direct evaluation [2402.06731].

For AMM–CEX arbitrage, a CPMM with reserves \(x,y\) and invariant \(x\cdot y=L\) yields instantaneous AMM price \(P_{AMM}=x/y\). If the CEX has price \(P_{CEX}\), the optimal amount of token \(Y\) sold into the AMM is
\[
V_{\max}=\Delta y^*=\frac{y(P_{AMM}-P_{CEX})}{2P_{AMM}},
\]
and the corresponding Maximal Arbitrage Value is
\[
MAV=\frac{y(P_{AMM}-P_{CEX})^2}{4P_{AMM}}.
\]
For concentrated liquidity, the analogous quantity is computed per tick and summed:
\[
MAV_{v3}=\sum_i MAV_i.
\]
This formulation explicitly links trade size, liquidity depth, and price divergence [2403.16083].

A2MM analyzes the two-pool case with constant-product AMMs and 0.3% fee. If pools \(1\) and \(2\) have reserves \((x_1,y_1)\) and \((x_2,y_2)\), the arbitrageur chooses \(\Delta_x\) to maximize
\[
\Pi(\Delta_x)=p_2^{Y\to X}\bigl(x_2,y_2,p_1^{X\to Y}(x_1,y_1,\Delta_x)\cdot \Delta_x\bigr)-\Delta_x.
\]
Equation 16 gives a closed-form approximate optimizer,
\[
\Delta_x^* \approx
\frac{1.003\bigl(-1000x_1y_2+997\sqrt{x_1x_2y_1y_2}\bigr)}
{997y_1+1000y_2},
\]
with a necessary profitability condition \(y_2/x_2<0.994\cdot (y_1/x_1)\) [2106.07371].

## 4. Detection, attribution, and measurement at scale

Large-scale empirical work operationalizes AA by scanning blocks, parsing swaps, aggregating per-asset net flows, and computing net profit after fees and prioritization bids. A documented detection loop over 23 million Polygon blocks uses a full Polygon archive node, PolygonScan API, and web3py: for each transaction, parse swaps, discard \(N<2\), compute \(\Delta(A)=\sum \delta_{n,A}\), reject any transaction with \(\Delta(A)<0\), then classify as AA when \(\mathrm{Profit}(tx)=\sum_A \Delta(A)\cdot P(A)-\tau(tx)-\beta(tx)>0\) [2508.21473].

Once AA events are identified, a separate question is causal attribution: which earlier transaction created the arbitrage opportunity. One framework defines the candidate set
\[
C=\{\,T_i\mid i<\mathrm{pos}(T_{arb})\ \wedge\ T_i\text{ interacts with pools in }T_{arb}\},
\]
and compares four attribution methods for atomic arbitrage on EVM-compatible networks [2604.27979].

| Method | Mean cost | Coverage / accuracy |
|---|---:|---:|
| Coefficient | 0.8 ms | 88.4% / 77.2% |
| Bot-data | 8 ms | 38.4% / 94.2% |
| Simulation | 12.3 ms | 99.1% / 91.7% |
| Shapley MC | 2.1 s | 98.1% / 100% |
| Shapley exact | ~5 min | 98.1% / 100% |

The simulation-based method replays the block with and without candidate transactions, searching backwards up to \(D=100\) blocks for an edge transaction where profit drops below \(5\%\) of original \(\Pi\), then computes
\[
\mathrm{Imp}_i=F(S_{i+1})-F(S_i)
\]
and selects the source maximizing \(\mathrm{Imp}_i\) [2604.27979]. The coefficient-based method instead tracks a price-multiplier coefficient \(k\) along the arbitrage cycle and attributes to the transaction maximizing \(\delta_{k_i}=k_i-k_{i-1}\); it is lightweight but omits slippage and depth [2604.27979]. Shapley-based attribution models candidate transactions as players in a cooperative game with value function \(V(S)=\mathcal M(\Sigma(S),T_{arb})\) and assigns marginal contributions
\[
\phi_i
=\sum_{S\subseteq C\setminus\{T_i\}}
\frac{|S|!(|C|-|S|-1)!}{|C|!}
\bigl[V(S\cup\{T_i\})-V(S)\bigr].
\]
This is theoretically ideal for multi-source attribution but computationally costly [2604.27979].

A plausible implication is that AA research has bifurcated into two layers: optimization of the arbitrage transaction itself, and retrospective attribution of the opportunity’s causal origin. The first asks how to execute the trade; the second asks who created the state from which the trade became profitable.

## 5. Empirical regularities across chains and market designs

A systematic study of Uniswap V2 from May 2020 to April 2021 recorded 292,606 executed cyclic arbitrages over eleven months, with total gross revenue of approximately \(34{,}429\) ETH, gas costs of approximately \(8{,}458\) ETH, and average net profit of approximately \(0.1\) ETH per cycle. The same study reports more than \(138\) million USD in revenue and observes persistently unexploited opportunities above \(1\) ETH per block, indicating that DEX markets may not be efficient enough [2105.02784].

Polygon measurements emphasize the distinction between Spam-based and Auction-based backrunning. Over Jan 2023 to Oct 2024, a 23 million-block study estimates total AA MEV at approximately \(12\) million USD. Spam-based AA accounts for approximately \(87\%\) of AA MEV volume and approximately \(95\%\) of AA transaction counts, whereas Auction-based AA via FastLane accounts for approximately \(13\%\) of AA MEV volume and approximately \(5\%\) of AA transaction counts. Average profit per transaction is approximately \(45\) MATIC for Spam-based AA and approximately \(150\) MATIC for Auction-based AA; the study also reports that FastLane’s private relay and bid auction reduce network congestion by approximately \(80\%\) fewer failed/duplicated transactions, and that observed efficiency satisfies \(\eta_{auction}\approx 3\times \eta_{spam}\) over the study period [2508.21473].

The same Polygon work reports token concentration: WMATIC appears in approximately \(95\%\) of AA, followed by WETH at \(35\%\) and WBTC at \(5\%\), reflecting deep liquidity [2508.21473]. A separate March 2026 attribution study on Polygon analyzes 360,026 atomic arbitrage events with total extracted value of \$334,799 and finds highly concentrated opportunity creation: the top \(1\%\) of opportunity-creating transactions account for \(80\%\) of extracted value, the top \(5\%\) of protocols generate \(73\%\) of total MEV creation, and \(96.7\%\) of arbitrage events attribute more than \(70\%\) of positive Shapley value to a single transaction [2604.27979]. Among 220,262 identified opportunity creators in February 2026, participation rates are \(58.0\%\) for Uniswap V3, \(29.6\%\) for Algebra, \(28.9\%\) for Uniswap V4, \(23.2\%\) for Uniswap V2, and \(8.2\%\) for DODO, with protocol overlap because a single swap may touch multiple pools [2604.27979].

On zkSync Era, arbitrage between SyncSwap and Binance from July to September 2023 yields cumulative MAV of \$104.96k on the USDC–ETH pool, equal to approximately \(0.2349\%\) of \$43.73M traded volume. Daily MAV peaks near \$8k on high-misalignment days, while price misalignments typically decay within a few minutes, with block time \(2\) s and median decay approximately \(100\)–\(120\) s [2403.16083]. This suggests that AA opportunities on rollups can be persistent enough to measure but short-lived enough to require low-latency execution.

For multi-asset G3M pools, simulation and backtest results indicate that closed-form AA can outperform convex solvers. Synthetic trials over 120,000 random perturbations of an \(N\)-token pool starting at equilibrium show strictly greater or equal profit in at least \(98\%\) of cases versus CVXPY, with \(0.2\) ms versus \(2\) ms on CPU for \(N=4\). A historical backtest from June 2021 to July 2022 on a 3-token ETH/BTC/DAI pool with \(w_i=1/3\), \(\gamma=0.003\), and initial TVL \(=1\) M USD finds that, in dueling mode where convex arb gets priority, the closed-form method still captures \(15\%\) more cumulative profit [2402.06731].

## 6. Infrastructure, security, and open limits

AA is not only a trading strategy but also a source of network externalities. A2MM argues that when arbitrage and routing are internalized inside a smart contract, competitive MEV exploitation is reduced. In a 185-day replay on Uniswap and Sushiswap data, A2MM reports total on-chain arbitrage revenue of \(32.7\) K ETH, average revenue per AA call of approximately \(0.02\) ETH, block-space savings of \(32.8\%\) fewer total gas consumed versus separate AMM plus arbitrage transactions, and approximately \(10\times\) fewer mempool spam messages per AA. Under realistic block sizes and latencies, effective miner bandwidth improves by up to approximately \(0.5\) Mbit/s, translating into approximately \(0.5\%\) lower stale-block rate on Ethereum; in expectation, A2MM revenue allows swap fees to be reduced by \(90\%\) [2106.07371].

On-chain integration details matter for whether AA is practically realizable. In the \(N\)-token G3M setting, closed-form evaluation loops over at most approximately \(3^N\) trade signatures with \(O(N)\) arithmetic per signature; for \(N\le 7\), even single-thread CPU evaluation is reported as less than \(0.5\) ms, and signature checks are embarrassingly parallel, allowing one thread per signature on GPU. The same work states that a CUDA kernel can complete the full pass in less than or equal to \(0.1\) ms for \(N=10\), and that end-to-end arb latencies from price feed to on-chain transaction can be driven below \(5\) ms [2402.06731]. It also notes that multi-asset `swap` gas scales roughly linearly in \(|A|\), with typical marginal cost approximately \(4{,}000\) gas per extra token leg, and recommends private relays or Flashbots to mitigate front-running and sandwich risk [2402.06731].

Atomicity, however, is not sufficient in every execution environment. A shared-sequencer model over two constant-product pools shows that the expected profit under atomic execution,
\[
\mathbb{E}[\Delta\Pi_{\rm atomic}] = p_A p_B \bigl(\delta y_A(x)-x\bigr),
\]
can be lower than expected profit under non-atomic execution when one-sided swap success is itself valuable. In the symmetric case \(p_A=p_B\),
\[
\Delta = p_A(1-p_A)\bigl[x-\delta x_B P_{\rm ext}\bigr],
\]
and the model states that this quantity is negative. The paper concludes that switching to atomic execution does not always improve profits, and that shared sequencers may need guaranteed execution features beyond atomic swap bundling to attract arbitrage flow [2410.11552]. This directly qualifies the common claim that atomicity is always profit-enhancing.

Several open problems recur across the literature. For large \(N\), signature enumeration in closed-form G3M arbitrage grows as \(3^N\), so heuristics or branch-and-bound pruning become essential for very large \(N\) [2402.06731]. Temporally varying weights in TFMMs require differentiating through the swap, and extension to stableswap, Uniswap v3’s piecewise-linear pool, cross-pool routing, and cross-chain arbitrage remains open [2402.06731]. At the ordering layer, Polygon studies point to auction-based consensus, time-based fairness, content-agnostic ordering, and application-layer solver models as directions for reducing AA leakage and its adverse externalities [2508.21473]. A plausible implication is that future AA research will remain split between execution efficiency, causal attribution, and protocol design aimed at reducing the very opportunities that AA exploits.

Source: https://www.emergentmind.com/topics/atomic-arbitrage-aa