Triangular Arbitrage in DeFi: Exploiting AMM Price Slippage
Explain the constant product formula (x*y=k), show live examples of price deviations in Uniswap‑like pools, and provide a simple Python script for aut
Explain the constant product formula (x*y=k), show live examples of price deviations in Uniswap‑like pools, and provide a simple Python script for aut
Triangular Arbitrage in DeFi: Exploiting AMM Price Slippage
Published: June 2026
---
Table of Contents
1. [What Is Triangular Arbitrage in Decentralised Finance?](#what-is-triangular-arbitrage-in-defi)
2. [The Constant‑Product Formula (x · y = k)](#the-constant-product-formula)
3. [How Price Slippage Emerges in Uniswap‑Style Pools](#how-price-slippage-emerges)
4. [Designing a Triangular‑Arbitrage Loop](#designing-a-triangular-arbitrage-loop)
5. [Live Data Example: Spotting a Three‑Leg Opportunity](#live-data-example)
6. [Automating the Strategy with Python](#automating-with-python)
7. [Risk Management and Gas‑Cost Optimisation](#risk-management)
8. [Why Real‑Time Scanners Matter – Introducing ArbitrageRadar PRO](#why‑real‑time‑scanners‑matter)
9. [FAQ](#faq)
---
What Is Triangular Arbitrage in Decentralised Finance?
Triangular arbitrage is a price‑discrepancy exploitation technique that involves three trades across three separate markets in order to lock in a risk‑free profit. In the context of Decentralised Finance (DeFi), the markets are usually Automated Market Maker (AMM) pools that follow the constant‑product invariant (x · y = k).
Key definition: Triangular arbitrage refers to converting an asset A into asset B, then asset B into asset C, and finally asset C back into asset A, while the net conversion yields more of asset A than the starting amount.
Why does this happen? AMM pools on different chains, or even on the same chain but with varying liquidity, can quote slightly different exchange rates for the same pair of tokens. When these rates diverge beyond the transaction cost, a profitable loop arises.
In practice, traders monitor multiple pools—often on Ethereum, Binance Smart Chain, and Polygon—to locate arbitrage windows that last from a few seconds to a few minutes. The fleeting nature of these windows makes automated detection and execution essential.
---
The Constant‑Product Formula
Most modern DeFi exchanges, including Uniswap, SushiSwap, and PancakeSwap, rely on the constant‑product market maker model. The core equation is:
\[
x \times y = k
\]
- x – reserve amount of token X in the pool.
- y – reserve amount of token Y in the pool.
- k – invariant constant that the product of the reserves must maintain after each trade.
Deriving the Spot Price
The instantaneous spot price of token X relative to token Y is the ratio of reserves:
\[
P_{X/Y} = \frac{y}{x}
\]
When a trader swaps a small amount Δx of token X for token Y, the new reserves become x + Δx and y − Δy. The invariant forces:
\[
(x + Δx)(y - Δy) = k
\]
Solving for Δy yields the exact amount of token Y received:
\[
Δy = \frac{y \, Δx}{x + Δx}
\]
Slippage and the Price Impact Curve
The relationship is non‑linear. Larger swaps push the price further away from the current spot rate, creating price slippage. The effective price for a trade of size Δx is:
\[
P_{\text{effective}} = \frac{Δy}{Δx} = \frac{y}{x + Δx}
\]
Because Δx appears in the denominator, the price degrades as the trade size grows. This characteristic is the engine behind arbitrage opportunities: a small enough trade can exploit the differential between two pools while keeping slippage modest.
---
How Price Slippage Emerges in Uniswap‑Style Pools
Sources of Slippage
| Source | Description |
|--------|-------------|
| Liquidity depth | Shallow pools (low x and y) experience sharper price moves per unit of trade. |
| Cross‑chain latency | Tokens bridged between chains often have stale price information, leading to temporary misalignments. |
| External market pressure | Large institutional swaps on centralized exchanges can drive the on‑chain price away from the AMM equilibrium. |
| Arbitrage latency | When an arbitrageur executes a trade, the pool’s reserves update instantly, but other participants may not react until the next block. |
Quantifying Slippage
Assume a Uniswap V2 pool with 10,000 USDC and 50 ETH (x = 10,000, y = 50). The spot price is:
\[
P_{ETH/USDC} = \frac{10,000}{50} = 200 \text{ USDC/ETH}
\]
If a trader wishes to buy 1 ETH, the input Δx in USDC is:
\[
Δx = \frac{k}{y - Δy} - x
\]
Using the formula for Δy = 1:
\[
Δx = \frac{10,000 \times 50}{50 - 1} - 10,000 \approx 202.02 \text{ USDC}
\]
The effective price is:
\[
P_{\text{effective}} = \frac{202.02}{1} = 202.02 \text{ USDC/ETH}
\]
The slippage is 1.01 % ((202.02 – 200) / 200). When the same trade is executed on a deeper pool (e.g., 100,000 USDC and 500 ETH), the slippage drops to roughly 0.10 %.
These calculations illustrate why arbitrageurs target imbalanced pools: the greater the price distortion, the larger the arbitrage profit per unit of capital.
---
Designing a Triangular‑Arbitrage Loop
Step‑by‑Step Blueprint
1. Select three tokens that form a closed loop, e.g., USDC → ETH → DAI → USDC.
2. Identify three distinct pools offering each pair:
- Pool A: USDC/ETH (Ethereum mainnet)
- Pool B: ETH/DAI (Polygon)
- Pool C: DAI/USDC (Binance Smart Chain)
3. Retrieve real‑time reserves for each pool using an RPC endpoint or a blockchain data provider (e.g., The Graph).
4. Calculate the implied cross‑rate for each leg using P = y / x.
5. Compute the round‑trip conversion factor:
\[
\text{Factor} = P_{USDC/ETH} \times P_{ETH/DAI} \times P_{DAI/USDC}
\]
If Factor > 1 after accounting for gas and protocol fees, the loop is profitable.
6. Simulate trade sizes to verify that slippage on each leg does not erode the profit margin.
7. Create a single‑transaction bundle (e.g., using Flashbots or a custom smart contract) that executes the three swaps atomically.
Why Atomic Execution Is Critical
If any leg fails (e.g., due to insufficient gas), the remaining swaps may leave the trader holding an unwanted token, turning a theoretical profit into a realized loss. Atomic execution guarantees that either all three swaps occur or none do, preserving the risk‑free nature of triangular arbitrage.
Example Calculation
Assume the following spot rates (derived from live reserves):
| Pair | Spot Rate (tokenIn/tokenOut) |
|------|------------------------------|
| USDC/ETH | 0.0049 ETH per USDC (≈ 204 USDC/ETH) |
| ETH/DAI | 1,020 DAI per ETH |
| DAI/USDC | 0.998 USDC per DAI |
The cross‑rate factor is:
\[
\text{Factor} = \frac{1}{204} \times 1{,}020 \times 0.998 \approx 1.01
\]
A 1 % profit exists before costs. If the cumulative gas cost for three swaps is 0.003 ETH (≈ $6 USD at a 2,000 gwei gas price), a trader would need a capital allocation that yields more than $6 USD in profit to make the trade worthwhile.
---
Live Data Example: Spotting a Three‑Leg Opportunity
Below is a snapshot taken on June 5 2026, 14:32 UTC from three popular AMM pools. The data is fetched via the public eth_call interface and verified against The Graph.
| Pool | Token In | Token Out | Reserve In | Reserve Out | Spot Rate |
|------|----------|-----------|------------|------------|-----------|
| A (Ethereum) | USDC | ETH | 12,500,000 | 62,500 | 0.00498 ETH/USDC |
| B (Polygon) | ETH | DAI | 5,300,000 | 5,400,000 | 1.0189 DAI/ETH |
| C (BSC) | DAI | USDC | 8,000,000 | 7,975,000 | 0.9969 USDC/DAI |
Step 1 – Convert USDC → ETH:
If we trade 10,000 USDC in Pool A, the received ETH (Δy) is:
\[
Δy = \frac{62{,}500 \times 10{,}000}{12{,}500{,}000 + 10{,}000} \approx 49.93 \text{ ETH}
\]
Step 2 – Convert ETH → DAI:
Using Pool B, the DAI received for 49.93 ETH is:
\[
Δy_{DAI} = \frac{5{,}400{,}000 \times 49.93}{5{,}300{,}000 + 49.93} \approx 50{,}900 \text{ DAI}
\]
Step 3 – Convert DAI → USDC:
Pool C converts DAI back to USDC:
\[
Δy_{USDC} = \frac{7{,}975{,}000 \times 50{,}900}{8{,}000{,}000 + 50{,}900} \approx 10{,}072 \text{ USDC}
\]
Result: Starting with 10,000 USDC, the loop yields 10,072 USDC – a 0.72 % profit before fees.
Cost assessment:
- Ethereum gas for the first swap: ~0.0014 ETH
- Polygon gas for the second swap: ~0.0009 MATIC (≈ 0.001 ETH)
- BSC gas for the third swap: ~0.0011 BNB (≈ 0.001 ETH)
Total gas ≈ 0.0035 ETH (≈ $5.5 USD). Net profit after gas ≈ $23 USD.
This live example demonstrates how a modest price deviation—less than 1 %—can generate a meaningful arbitrage profit once execution is fully automated.
---
Automating the Strategy with Python
Below is a self‑contained Python script that:
1. Pulls reserve data from three pools (Ethereum, Polygon, BSC).
2. Calculates the triangular arbitrage factor.
3. Determines the optimal input amount that maximises profit while respecting a maximum slippage threshold.
4. Emits a JSON‑encoded transaction bundle ready for submission via Flashbots or a similar MEV‑relay.
`python
#!/usr/bin/env python3
-- coding: utf-8 --
import json
import time
from decimal import Decimal, getcontext
from web3 import Web3
from eth_abi import encode_abi
-------------------------------------------------
Configuration – replace with your own RPC URLs
-------------------------------------------------
RPC_ENDPOINTS = {
"ethereum": "https://mainnet.infura.io/v3/YOUR_INFURA_KEY",
"polygon": "https://polygon-rpc.com",
"bsc": "https://bsc-dataseed.binance.org/",
}
Pool addresses (UniswapV2/SushiSwap style)
POOLS = {
ArbitrageRadar PRO on the App Store · arbitrageradarpro.com
Related guides
- Automated Triangular Arbitrage Trading: Tools and Strategies
- Best Exchanges for Triangular Arbitrage in Crypto (2026)
- Best Triangular Arbitrage Calculators and Tools for 2026
- Best Triangular Arbitrage Calculators and Tools in 2026
- Best Triangular Arbitrage Calculators and Tools
- Build Your Own Crypto Triangular Arbitrage Tool with Python and Binance API
All guides · Coins · Exchanges