How to — UniSwap 3 WayArbitrage Bot
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
- Swap 1 ETH to DAI
- Swap DAI to USDC
- Swap USDC to ETH
Before we implement the code these are the main points…
- Setup: Import required libraries (ethers)
- 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).
- We define our swap amount (1 Eth) & define the token addresses and the path of the swaps we want to perform.
- 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.
- Fees: Uniswap charges a 0.3% fee…