DEX Arbitrage Bot Development

We design and develop full-cycle blockchain solutions: from smart contract architecture to launching DeFi protocols, NFT marketplaces and crypto exchanges. Security audits, tokenomics, integration with existing infrastructure.
Showing 1 of 1 servicesAll 1306 services
DEX Arbitrage Bot Development
Complex
~1-2 weeks
FAQ
Blockchain Development Services
Blockchain Development Stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1214
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    852
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_logo-advance_0.png
    B2B Advance company logo design
    561
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    823

Development of DEX arbitrage bot

On Uniswap V3 ETH/USDC costs $3,201.50. On SushiSwap the same pool — $3,199.80. Difference $1.70 on ETH. To make this profitable you must account for: gas 21,000 + 150,000 (two swaps) ≈ 170,000 gas × 30 gwei × $3,200 / 1e9 ETH = ~$16 in gas. So to break even on a $1,000 trade, the spread must be at least 1.6%. On $100,000 0.016% is enough. This is why DEX arbitrage only works with sufficient position size or price spread — and flash loans make this business accessible without your own capital.

Why most arbitrage bots don't profit

Mempool competition and MEV

The hardest enemy of DEX arbitrageur — not competitors, but MEV-bots with direct block builder access. Through Flashbots eth_sendBundle your transaction goes straight to builder, bypassing public mempool. This means frontrunner doesn't see it before block inclusion.

If your bot sends transactions to public mempool — you're in losing position. Normal gas auction means other bots see your transaction, assess profitability and bid higher gas. Either your transaction doesn't get included (lost gas), or it includes after theirs which already executed arbitrage.

Solution: send all transactions through Flashbots or MEV Blocker (aggregator of multiple private relays). Plus — you can bundle multiple transactions in one with atomic execution.

Slippage and real price calculation

Problem with most beginner implementations: calculating arbitrage opportunity by spot pool price without price impact. You take ETH/USDC on Uniswap V3 — sqrtPriceX96 gives current price, but not price after your $50,000 swap.

Real price after swap depends on:

  • Current liquidity in active range (Uniswap V3)
  • Size of your transaction
  • Spread through several tick ranges (if position large)

For V3 correct calculation requires swap simulation through Quoter contract or off-chain through @uniswap/v3-sdk. Difference between spot price and real execution price on $100k swap on medium-liquidity pool — 0.3-1.5%. Without accounting for this, profitability calculation will be wrong.

Gas optimization: difference between profit and loss

On mainnet Ethereum arbitrage only works with optimized gas usage. Typical mistake: two separate ERC-20 approve + swap = +43,000 gas overhead. Solution — use permit (EIP-2612) for tokens supporting it, or pre-approve maximum amount and don't re-approve.

Even more savings from atomic arbitrage through flash loan in one contract: no multiple transfer between EOA and DEX, no separate transactions. Whole arbitrage — one transaction: flash loan → swap A → swap B → repay loan → profit. Gas for such transaction: 200,000 - 400,000 depending on protocols.

How we build DEX arbitrage bot

Architecture: on-chain contract + off-chain executor

System consists of two parts:

On-chain contract — executes deal atomically. Implements flash loan callback (Aave IFlashLoanReceiver or Uniswap V3 IUniswapV3FlashCallback), executes swaps, checks profit at end of transaction and reverts if profit < minimum threshold.

function executeArbitrage(
    address tokenIn,
    uint256 amountIn,
    SwapPath[] calldata path,
    uint256 minProfit
) external {
    // Flash loan from Aave
    // Execute swaps along path
    // Assert profit >= minProfit, else revert
    // Repay flash loan
    // Transfer profit to owner
}

Revert on insufficient profit — key protection: if market changed while transaction in mempool, contract reverts spending only base gas (~21,000), not full swap execution gas.

Off-chain executor (Node.js/Rust) — continuously monitors pool states, calculates arbitrage opportunities, forms and sends transactions through Flashbots.

Price data sources

Method Latency Cost Application
WebSocket subscribe to node (eth_subscribe) ~10-50ms High (own node) Mainnet production
Alchemy/Infura WebSocket ~100-300ms Medium Development, testing
The Graph (GraphQL) ~500ms-2s Low Not suitable for arbitrage
Uniswap V3 Subgraph ~1-5s Free Not suitable

For production arbitrage — own Ethereum node or dedicated endpoint. Public RPC on Alchemy free tier with rate limiting will kill any serious bot.

Alternative to own node: Fiber (bloXroute), Eden Network — paid services with direct mempool access and accelerated transaction propagation.

Finding optimal path: Bellman-Ford

For multi-hop arbitrage (A→B→C→A) the task of finding profitable path — is task of finding negative cycle in price graph. Classic algorithm — Bellman-Ford on graph where nodes = tokens, edges = pools, weights = log(exchange_rate).

In practice for 5-10 DEXs and 50-100 tokens graph is small, Bellman-Ford calculates in milliseconds. With more pairs switch to heuristics or limit search depth to 3-hop.

Cross-chain arbitrage via bridges

Arbitrage between Ethereum mainnet and Arbitrum/Optimism is technically possible but loses in most cases: bridge latency 10 minutes to 7 days makes atomicity impossible. By time bridge completes market price equalizes. Exception — fast bridges (Hop, Connext) with latency 5-30 minutes and hedging possibility through perp position.

Monitoring and risk management

Arbitrage bot in production requires monitoring several metrics:

  • Transaction win rate: if > 30% transactions revert from price change — too slow executor or too low minProfit threshold
  • Gas efficiency: ratio of real profit to spent gas
  • Capital utilization: if flash loan limits in Aave exhausted — available position size decreases
  • Competitive environment: rising average base fee in peak hours lowers profitability

Grafana + Prometheus for metrics, alerts via Telegram bot on win rate drop or balance changes.

Development process

Analytics (2-3 days). Determine target DEXs, networks, token pairs. Analyze competitive environment — how many bots already working in chosen segment.

Contract development (1 week). Flash loan integration, multi-hop swap logic, profit assertion. Tests on mainnet fork through Foundry.

Executor development (1-2 weeks). WebSocket pool monitoring, Bellman-Ford / path finding, Flashbots bundle sending.

Optimization and deployment (3-5 days). Gas profiling, fine-tuning minProfit thresholds, production deployment.

Timeline estimates

Basic bot (2 DEXs, one network, flash loan) — 1-2 weeks. Multi-DEX, multi-path with Flashbots integration — 2-4 weeks. Cross-chain or advanced MEV strategies — from 6 weeks. Cost calculated individually.