BLOCKCHAIN / ADVANCED / +320 XP

Graph-based arbitrage is a search problem

Finding profitable cycles across heterogeneous AMMs is not finance. It is graph theory with money on the line.

Graph-based arbitrage is not finance. It is a search problem. The question is not "which token is undervalued" — it is "which cycle in this weighted directed graph has a negative total weight after fees." That framing changes everything about how you build the system.

In traditional markets, arbitrage is about information asymmetry. In DeFi, it is about graph traversal speed. The AMM pools are nodes. The swap pairs are edges. The edge weights are the exchange rates including slippage, gas costs, and protocol fees. Finding profitable arbitrage means finding negative cycles in this graph — and doing it faster than everyone else.

THE DEEP DIVE

The Graph Model

Every AMM pool is a node. Every possible swap is a directed edge. The weight of an edge is the effective exchange rate after all fees and slippage. A path from token A back to token A with negative total weight is a profitable arbitrage cycle.

The Bellman-Ford algorithm finds negative cycles in O(V*E) time. For a graph with 500 tokens and 2000 pools, that is 500 * 2000 = 1,000,000 operations per scan. At modern clock speeds, that is sub-millisecond. The bottleneck is not computation — it is data freshness.

// Simplified negative cycle detection
function findArbitrage(graph: TokenGraph): Cycle[] {
  const cycles: Cycle[] = [];
  const distances = new Map<string, number>();
  const predecessors = new Map<string, string>();

  // Initialize
  for (const node of graph.nodes) {
    distances.set(node, 0);
    predecessors.set(node, "");
  }

  // Bellman-Ford relaxation
  for (let i = 0; i < graph.nodes.length - 1; i++) {
    for (const edge of graph.edges) {
      const newDist = distances.get(edge.from)! + edge.weight;
      if (newDist < distances.get(edge.to)!) {
        distances.set(edge.to, newDist);
        predecessors.set(edge.to, edge.from);
      }
    }
  }

  // Detect negative cycles
  for (const edge of graph.edges) {
    const newDist = distances.get(edge.from)! + edge.weight;
    if (newDist < distances.get(edge.to)!) {
      cycles.push(reconstructCycle(edge, predecessors));
    }
  }

  return cycles;
}

The Freshness Problem

The graph is stale the moment you read it. By the time your transaction lands in the mempool, the edge weights have changed. Other arbitrageurs have already executed, MEV searchers have front-run your signals, and the gas price has shifted. Your scan result is a fossil.

This is why the most profitable arbitrage systems do not just find negative cycles — they predict which cycles will still be negative when the transaction executes. That requires modeling the rate at which other searchers close arbitrage opportunities.

PRINCIPLES

  1. The graph is always stale. Build for the graph you will have at execution time, not the one you read.
  2. Gas cost is an edge weight. A negative cycle that costs more in gas than it yields is not an arbitrage — it is a donation.
  3. MEV searchers compete on latency, not strategy. The same negative cycle found by ten searchers means the fastest nine lose money.
  4. Composite pools (triple-token, concentrated liquidity) create hyper-edges. Model them as multiple simple edges or your cycle detection will miss opportunities.
  5. The optimal strategy is not maximizing profit per cycle — it is maximizing profit per unit of gas spent.

IN PRACTICE

Stablecoin Triangle

USDC -> DAI -> USDT -> USDC through three Curve pools. Each leg has 0.04% fee. If the cumulative exchange rate yields more than 0.12% profit after gas, the cycle is profitable. In practice, these close within milliseconds of appearing.

Concentrated Liquidity Arbitrage

Uniswap V3 concentrated positions create micro-pools with extreme price sensitivity. A 0.5% price movement in a narrow range can create negative cycles that span only two pools. The gas cost is lower because the price impact is higher.

LIVE SIGNALS

These items surfaced from the intelligence pipeline at generation time.

ANTIPATTERNS

  • Scanning the full graph on every block. Pre-filter to pools with recent volume.
  • Ignoring gas price volatility. A profitable scan at 30 gwei is unprofitable at 100 gwei.
  • Assuming linear price impact. AMM curves are non-linear — model them correctly.
  • Running the scan sequentially. The graph is immutable during computation — parallelize.

CHECKLIST

  • Graph model represents all active pools with correct fee structures
  • Negative cycle detection handles multi-hop paths (3+ edges)
  • Gas cost is included in edge weight calculations
  • Execution transaction is atomic (all-or-nothing swap)
  • Fallback: if cycle closes before execution, transaction reverts safely

YOUR MOVE

Map the top 20 pools by TVL on Uniswap. Build the adjacency list. Run Bellman-Ford. Count the negative cycles. That is your starting point.