How to — UniSwap 3 WayArbitrage Bot

Saxon Heller
Web 3 Digitals
Published in
4 min readAug 8, 2023

--

In this tutorial we will create a simple bot that will scan Uniswap v2 for 3 way arbitrage opportunities on selected pairs.

The pairs we will be tracking are:

ETH / DAI

DAI / USDC

USDC / ETH

The arbitrage cycle we are creating is the following

  1. Swap 1 ETH to DAI
  2. Swap DAI to USDC
  3. Swap USDC to ETH

Before we implement the code these are the main points…

  1. Setup: Import required libraries (ethers)
  2. Contract & Provider: We define our router address in our case Uniswap v2 Router address & ABI’s and setup our provider URL (how we will connect to ETH mainnet).
  3. We define our swap amount (1 Eth) & define the token addresses and the path of the swaps we want to perform.
  4. Fetch swap quotes: The code fetches swap quotes for the given paths using the ‘router.getAmountsOut’ function. It then formats the results to human-readable values.
  5. Fees: Uniswap charges a 0.3% fee…

--

--