Trading bots
Overview
The TRP Arbitrage Bot is an automated EVM trading bot that monitors and executes profitable arbitrage opportunities across 6 different strategies using flashloans, wrapper contracts, and custom Balancer pool swaps. The bot operates continuously, scanning for price discrepancies and executing trades when profitable conditions are detected.
Features
6 Arbitrage Strategies: Flashloans, simple wrapper swaps, Aave-based strategies
Automated Execution: Continuous monitoring with configurable intervals
Risk Management: Built-in slippage protection, gas cost analysis, and retry logic
Flexible Configuration: Easily configure routes, contracts, and trading parameters
Production Ready: Upgradeable contracts, comprehensive testing, and monitoring
Prerequisites
Before using the TRP Arbitrage Bot, ensure you have:
Node.js (v16 or higher)
Yarn or npm
Ethereum wallet with private key
RPC endpoint (Alchemy, Infura, or custom)
Deployed contracts (Strategy)
API endpoints for price data and flashloan parameters
Installation
1. Clone and Install
git clone <repository-url>
cd arbitrage-bot
yarn install
# or npm install
2. Compile Contracts
yarn compile
# or npm run compile
3. Run Tests (Optional)
yarn test
# or npm test
Configuration
Environment Variables
Create a .env
file in the root directory with the following configuration:
# Blockchain Connection
RPC_URL=https://eth-mainnet.alchemyapi.io/v2/your-api-key
SEPOLIA_RPC_URL=https://eth-sepolia.g.alchemy.com/v2/your-api-key # For testnet
PRIVATE_KEY=0xYourPrivateKeyHere
# Contract Addresses (use actual deployed addresses)
UNDERLYING_ADDRESS=0x... # e.g., USDC, DAI, WBTC
SMARTTOKENX_ADDRESS=0x... # riskON token contract
SMARTTOKENY_ADDRESS=0x... # riskOFF token contract
WRAPPED_X_ADDRESS=0x... # Wrapped riskON contract
WRAPPED_Y_ADDRESS=0x... # Wrapped riskOFF contract
STRATEGY_ADDRESS=0x... # Main strategy contract
BPOOL_ADDRESS=0x... # Balancer pool for X/Y/Underlying
# API Configuration
API_URL=https://api-demo.riskprotocol.io
AAVE_POOL_ADDRESS=0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2 # Optional: Mainnet Aave V3
# Bot Configuration
ROUTES=1,2,3,4,5,6 # Comma-separated routes to monitor
CHECK_INTERVAL_MS=15000 # Check every 15 seconds (default)
Contract Deployment
If you need to deploy contracts:
# Deploy to testnet (Sepolia)
yarn hardhat run scripts/deploy.ts --network sepolia
# Deploy to mainnet
yarn hardhat run scripts/deploy.ts --network mainnet
Usage
Starting the Bot
# Start the arbitrage bot
yarn start
# or npm start
The bot will:
Load configuration from environment variables
Connect to the blockchain using your RPC endpoint
Initialize contract connections
Begin monitoring all configured routes (default: 1,2,3,4,5,6)
Execute profitable arbitrage opportunities automatically
Check for opportunities every 15 seconds (configurable)
Bot Output Example
🚀 TRP Arbitrage Bot Starting...
✅ Connected to Ethereum Mainnet
✅ Loaded 6 arbitrage routes: 1,2,3,4,5,6
✅ Strategy contract: 0xABC123...
✅ Monitoring every 15 seconds
[2024-01-15 10:30:45] 🔍 Scanning routes...
[2024-01-15 10:30:46] Route 1: Complex Route: No arbitrage opportunity
[2024-01-15 10:30:47] Route 2: Simple Route: Profitable arbitrage route
[2024-01-15 10:30:48] 💰 Executed Route 2: Profit = 0.025 ETH ($45.50)
[2024-01-15 10:30:49] Route 3: Third Route: No arbitrage opportunity
[2024-01-15 10:30:50] Route 4: Forth Route: No arbitrage opportunity
[2024-01-15 10:30:51] Route 5: Route 5: No arbitrage opportunity
[2024-01-15 10:30:52] Route 6: Route 6: Huge arbitrage opportunity found! Profit ratio: 15%
[2024-01-15 10:30:53] 💰 Executed Route 6: Profit = 0.150 ETH ($273.00)
[2024-01-15 10:30:54] ✅ Cycle complete. Next check in 15 seconds...
Arbitrage Routes Explained
Route 1: Complex Nested Flashloans
Strategy: Borrow both rON and rOFF tokens, redeem for underlying, swap for repayment
Use Case: When both wrappers have unwanted token discounts
Capital: No upfront capital needed (flashloans)
Route 2: Simple Wrapper Arbitrage
Strategy: Borrow unwanted token from wrapper, swap for wanted token
Use Case: When one wrapper has significant unwanted token discount
Capital: No upfront capital needed (flashloans)
Route 3: Third Route Nested Strategy
Strategy: Borrow unwanted token, get wanted token loan, redeem optimally
Use Case: Complex scenarios with both wanted and unwanted token opportunities
Capital: No upfront capital needed (flashloans)
Route 4: Fourth Route Premium Strategy
Strategy: Flashloan both wanted tokens from wrappers, redeem and trade
Use Case: When both wrappers offer wanted tokens with favorable premiums
Capital: No upfront capital needed (flashloans)
Route 5: Aave Deposit-and-Swap
Strategy: Borrow underlying from Aave, deposit to get X+Y tokens, swap to underlying
Use Case: When TRP deposit rate (1:1) is better than Balancer market rates
Capital: No upfront capital needed (Aave flashloans)
Route 6: Aave Buy-and-Redeem
Strategy: Borrow underlying from Aave, buy X+Y tokens from Balancer, redeem
Use Case: When Balancer market rates are cheaper than TRP redemption rate (1:1)
Capital: No upfront capital needed (Aave flashloans)
Advanced Configuration
Route Selection
You can configure which routes to monitor:
# Monitor only Aave-based strategies
ROUTES=5,6
# Monitor only wrapper-based strategies
ROUTES=1,2,3,4
# Monitor specific routes
ROUTES=2,5
Advanced Configuration
The bot includes built-in gas management and profitability logic. Key configuration options:
# Timing Configuration
CHECK_INTERVAL_MS=15000 # How often to check for opportunities (milliseconds)
# Network Configuration
RPC_URL=your-mainnet-rpc # Use fast, reliable RPC for best performance
SEPOLIA_RPC_URL=your-testnet # For testing and development
# Route Selection
ROUTES=1,2,3,4,5,6 # Enable all routes
ROUTES=5,6 # Enable only Aave-based routes
ROUTES=2,3 # Enable only specific wrapper routes
Monitoring and Alerts
The bot currently logs all activity to the console. You can capture this output for monitoring:
# Run with output logging
yarn start > arbitrage.log 2>&1
# Run in background with nohup
nohup yarn start > arbitrage.log 2>&1 &
# View live logs
tail -f arbitrage.log
Safety and Risk Management
Built-in Safety Features
Gas Price Protection: Bot refuses to execute if gas prices exceed configured maximum
Slippage Protection: All trades include configurable slippage tolerance
Retry Logic: Failed transactions retry with reduced amounts
Profit Validation: All trades validated for profitability before execution
Contract Upgrades: Strategy contract is upgradeable for bug fixes and improvements
Recommended Practices
Start Small: Begin with conservative settings and smaller profit thresholds
Monitor Closely: Watch the first few hours of operation carefully
Test Environment: Always test on testnets before mainnet deployment
Backup Keys: Ensure private keys are securely backed up
Regular Updates: Keep the bot updated with latest improvements
Risk Considerations
Smart Contract Risk: Strategy contract could have bugs (mitigated by comprehensive testing)
Market Risk: Rapid price movements could cause unexpected losses
Gas Risk: High gas prices could eat into profits
Competition: Other arbitrage bots may front-run opportunities
Slippage Risk: Large trades may experience higher slippage than expected
Troubleshooting
Common Issues
Bot won't start:
# Check configuration
yarn hardhat run scripts/verify-config.ts
# Verify contract addresses
yarn hardhat run scripts/verify-contracts.ts
No profitable opportunities:
Check if routes are configured correctly in
ROUTES
environment variableVerify API endpoints are returning current price data
Ensure sufficient liquidity exists in Balancer pools
Market conditions may not currently favor arbitrage
High gas costs:
Bot includes built-in gas cost analysis and will skip unprofitable trades
Consider running during off-peak hours for better opportunities
Monitor gas prices at https://etherscan.io/gastracker
Transaction failures:
Check if wallet has sufficient ETH for gas
Verify all contract addresses are correct
Ensure contracts are properly deployed and initialized
Debug Mode
The bot includes detailed console logging by default. For additional debugging, you can:
Check individual route messages in the console output
Verify contract addresses are correct
Ensure API endpoints are responding correctly
Performance Optimization
Hardware Recommendations
VPS/Cloud: Recommended for 24/7 operation
Memory: Minimum 2GB RAM
Network: Low-latency connection to Ethereum RPC
Storage: SSD recommended for faster operations
Optimization Tips
Fast RPC: Use premium RPC providers (Alchemy, QuickNode)
Multiple Routes: Monitor multiple routes for better opportunities
Competitive Gas: Set appropriate gas prices for your strategy
Regular Monitoring: Check performance metrics regularly
Conclusion
The TRP Arbitrage Bot provides a powerful, automated solution for capitalizing on arbitrage opportunities in the TRP ecosystem. By following this guide and implementing proper risk management practices, users can operate the bot safely and profitably.
Remember to always:
Test thoroughly before production use
Monitor operations closely
Keep configurations updated
Maintain proper security practices
Stay informed about protocol updates
USE AT YOUR OWN RISK
Happy arbitraging! 🚀
Last updated