This project is a flash loan arbitrage bot designed to exploit price differences between decentralized exchanges (DEXs) using flash loans. The bot monitors price discrepancies and executes arbitrage opportunities by borrowing funds without collateral, conducting trades, and repaying the loan within the same transaction block.
flash-loan-arbitrage-bot/
|— contracts/
|— Dex.sol
|— Flashloan.sol
|— FlashloanArbitrage.sol
|— src/
|— python/
|— getbalance.py
|— withdraw.py
|— approve.py
|— allowance.py
|— flashloan.py
|— flashloanarbitrage.py
|— monitor.py
|— javascript/
|— getbalance.js
|— withdraw.js
|— approve.js
|— allowance.js
|— flashloan.js
|— flashloanarbitrage.js
|— monitor.js
|— mainnet_integration/
|— ethereumpools.json
|— .gitignore
|— README.md
- Dex.sol: A simple DEX contract with 2 different reserves for the same contract. This is what we are going to exploit.
- Flashloan.sol: Takes a simple flash loan and repays it, plus the 0.09% fee.
- FlashloanArbitrage.sol: Contains the arbitrage logic, including the functions to execute the trades and repay the loan.
- getbalance.py: Retrieves the balance of specified tokens.
- withdraw.py: Withdraws tokens from the contract.
- approve.py: Approves a specified amount of tokens for trading.
- allowance.py: Checks the allowance of tokens.
- flashloan.py: Executes a flash loan.
- flashloanarbitrage.py: Conducts the arbitrage operation.
- monitor.py: Monitors price differences across DEXs.
- getbalance.js: Retrieves the balance of specified tokens.
- withdraw.js: Withdraws tokens from the contract.
- approve.js: Approves a specified amount of tokens for trading.
- allowance.js: Checks the allowance of tokens.
- flashloan.js: Executes a flash loan.
- flashloanarbitrage.js: Conducts the flashloan arbitrage operation.
- monitor.js: Monitors price differences across DEXs.
- ethereumpools.json: Contains information about Ethereum liquidity pools for flash loans. To integrate the flashloan arbitrage logic to the mainnet, make sure you will monitor official pools from popular DEXes.
- Node.js and npm installed
- Python installed
- Solidity development environment (e.g., Hardhat, Truffle) (Or for simplicity deploy using Remix)
-
Deploy the contracts
-
Fund the contracts with some Sepolia USDT and Sepolia DAI (or any other coins you can get flash loan on and perform trades).
-
Call the approve functions (approve.js or approve.py) to approve the DEX contract to spend funds from your FlashloanArbitrage contract.
node src/javascript/approve.js- Check if the approvals succeeded with (allowance.js or allowance.py).
node src/javascript/allowance.js-
Fund the DEX with SepoliaUSDT and SepoliaDAI to simulate liquidity.
-
Use getbalance.js or getbalance.py to check the balance of a token in a smart contract (both DEX and FlashloanArbitrage).
node src/javascript/getbalance.js- Run monitor.js or monitor.py. This will start monitoring real time mainnet prices accross different DEXes.
node src/javascript/monitor.js-
After a specified threshold price, the bot will run FlashloanArbitrage.js (or FlashloanArbitrage.py accordingly) ON THE SEPOLIA TESTNET, NOT ON MAINNET. THE ARBITRAGE OPERATION WILL BE PERFORMED ON THE DEX.SOL BUT BASED ON REAL TIME PRICE DATA.
-
Withdraw the funds using withdraw.py or withdraw.js
node src/javascript/withdraw.jsThis project is licensed under the MIT License - see the LICENSE file for details.