This project implements a flash loan arbitrage bot that monitors and executes trading opportunities between Uniswap and SushiSwap on the Base network.
The system consists of two main components:
- A smart contract (
FlashLoanArbitrage.sol) that executes flash loans and arbitrage trades - A monitoring script (
monitor.js) that watches for profitable opportunities
- Flash loan integration with Aave V3
- Arbitrage execution between Uniswap and SushiSwap
- Safety features:
- Price impact checks (max 3%)
- Minimum/maximum borrow limits
- Gas price limits optimized for Base
- Reentrancy protection
- Owner-only execution
- Profit verification
- Real-time price monitoring across DEXes
- Detailed logging system with:
- Price differences
- Gas costs
- Execution results
- Profit tracking
- Configurable parameters:
- Profit thresholds
- Token pairs
- Retry delays
- Error handling and recovery
npm install- Copy
.env.exampleto.envand fill in your values:
cp .env.example .env- Update the following in
deploy.js:
- AAVE_LENDING_POOL_ADDRESS_PROVIDER
- Router addresses (if deploying to mainnet)
- Update token pairs in
monitor.jsif needed
For Base Testnet:
npx hardhat run scripts/deploy.js --network base-testnetFor Base Mainnet:
npx hardhat run scripts/deploy.js --network baseThe monitoring system (monitor.js) includes comprehensive logging:
- All activities are logged to daily files (
arbitrage_log_YYYY-MM-DD.txt) - Logs include:
- Price checks
- Profitable opportunities
- Trade execution results
- Gas prices
- Errors and issues
To start monitoring:
node monitor.jsThe monitoring script implements detailed logging through the logToFile method:
- Timestamp for every log entry
- Price comparisons between DEXes
- Gas price monitoring
- Trade execution details
- Profit/loss tracking
- Error logging
Logs are stored in the logs directory with daily rotation.
- Never commit your private keys or
.envfile - Test thoroughly on testnet first
- Monitor gas prices and adjust limits accordingly
- Start with small trade amounts
- Review price impact before execution
The system is configured for:
- Base Mainnet (
https://mainnet.base.org) - Base Testnet (
https://goerli.base.org)
To switch networks, update the provider URL in monitor.js and deployment configurations.
MIT
This is experimental software. Use at your own risk. Always test with small amounts first.