This is an exploratory project designed to test different approaches to arbitrage using flash loans.
The current version includes a FlashLoanArbitrage contract that obtains a flash loan from Balancer V2 and performs an ERC20 token swap using two Uniswap V2 forks: Uniswap V2 and SushiSwap V2.
The contract exposes a method called checkArbitrageProfitability
, which is used by the bot to determine whether an arbitrage opportunity is profitable. If it is, the bot calls executeArbitrage
to execute the trade using the borrowed ERC20 token. The contract initiates the loan, swaps tokens across both DEXes, repays the flash loan, and retains any profit.
For simplicity, the bot and the contract have been tested using Anvil and an Ethereum mainnet fork. During testing, the DEX reserves were manually modified to simulate a profitable arbitrage scenario.
Run the following commands in ./smart-contracts
:
Import foundry wallet. This wallet will be used for the bot too:
cast wallet import NAME --interactive
Copy and complete the following .env
file
cp .env.example .env
Install dependencies:
make install
Test with mainnet fork:
make test
Run anvil with mainnet fork:
make anvil-fork
Change reserves. This requires a few previous commands mentioned in the Makefile
make change-reserves
Deploys:
make deploy-anvil
make deploy-sepolia
make deploy-mainnet
Run the following commands in ./bot
:
Install dependencies:
pnpm install
Generate ABI:
pnpm update-abi
Start bot:
pnpm start