Trading Bots
Overview
The Risk Protocol Trading Bot is an autonomous arbitrage system that continuously monitors and executes profitable opportunities across Risk Protocol's token ecosystem. The bot operates 24/7, executing complex multi-step transactions involving flashloans, token swaps, and redemptions to capture price inefficiencies between Risk Protocol's 1:1 deposit/redemption mechanism and market prices on decentralized exchanges including our own.
Key Characteristics of the trading bot:
Autonomous Operation: Runs continuously with configurable check intervals
Multi-Strategy: Implements 6 distinct arbitrage routes
Capital Efficient: Utilizes flashloans to execute arbitrage without upfront capital
Performance Optimized: Sub-2-second cycle times with batched RPC calls and cached data
Production Hardened: Includes retry logic, monitoring, resource management, and failsafes
Users may fork the trading bot from our github: `[]`
System Architecture
High-Level Components
┌─────────────────────────────────────────────────────────────┐
│ Trading Bot (Node.js) │
│ ┌─────────────┐ ┌──────────────┐ ┌──────────────────┐ │
│ │ Bot.ts │─▶│ Helper.ts │─▶│ Strategies.sol │ │
│ │ (Orchestr.) │ │ (Route Logic)│ │ (Smart Contract) │ │
│ └─────────────┘ └──────────────┘ └──────────────────┘ │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ ┌──────────────────────────────────────────────────┐ │
│ │ Shared Data Layer (Cached) │ │
│ │ • Prices • Flashloan Data • Pool State │ │
│ └──────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
│
┌─────────────────┼─────────────────┐
▼ ▼ ▼
┌───────────┐ ┌────────────┐ ┌──────────┐
│ Ethereum │ │ Price │ │ BetterSt.│
│ RPC │ │ API │ │ Logging │
└───────────┘ └────────────┘ └──────────┘Arbitrage Strategies
The bot implements 6 distinct arbitrage routes or strategies, each exploiting different market inefficiencies. The six trading bot strategies are listed below:
Route 1: MONZA (Nested Flashloan Arbitrage)
Strategy: Exploit price discrepancy when market(rON) + market(rOFF) < underlying
Execution Flow:
Flashloan rON from Wrapper X
Nested flashloan rOFF from Wrapper Y
Redeem both tokens for underlying (1:1 ratio)
Swap underlying on TRP DEX for rOFF to repay Wrapper Y
Swap underlying for rON to repay Wrapper X
Retain profit in underlying tokens
Use Case: When the aggregate market price of both SMART Tokens trades at a discount to value of the underlying upon redemption.
Route 2: SUZUKA (Single Token Arbitrage)
Strategy: Borrow unwanted token, swap for wanted token
Execution Flow:
Flashloan unwanted token from wrapper
Swap on Balancer for wanted token
Repay flashloan with wanted token
Profit from price spread
Use Case: When the discount on the unwanted token in one of the wrappers is large enough to constitute a profitable arbitrage.
Route 3: MUGELLO (Unwanted Token Disposal)
Strategy: Nested flashloans with unwanted token disposal and underlying redemption
Execution Flow:
Flashloan rON from Wrapper X
Nested flashloan rOFF from Wrapper Y
Redeem equal amounts for underlying
Use underlying to acquire rOFF on Balancer
Repay Wrapper Y with rOFF
Repay Wrapper X with remaining rON
Retain profit
Use Case: Complex market conditions with asymmetric liquidity
Route 4: SPA (Premium Flashloan Strategy)
Strategy: Similar to Route 1 but with premium payment structure
Execution Flow:
Flashloan both rON and rOFF from wrappers with premiums
Redeem for underlying (1:1)
Execute Balancer swaps to acquire repayment tokens
Repay both flashloans with premiums
Retain profit after covering premium costs
Use Case: When arbitrage opportunity exceeds flashloan premium costs
Route 5: ASSEN (Aave Deposit-and-Swap)
Strategy: Arbitrage TRP 1:1 deposit rate vs Balancer market rates
Execution Flow:
Flashloan underlying from Aave V3 (0.09% premium)
Deposit underlying to Risk Protocol → receive rON + rOFF (1:1 ratio)
Swap rON to underlying on Balancer
Swap rOFF to underlying on Balancer
Repay Aave flashloan with premium
Retain profit from swap rates exceeding deposit cost
Use Case: When market is buying risk tokens below 1:1 underlying value
Route 6: PHILLIP ISLAND (Aave Buy-and-Redeem)
Strategy: Arbitrage Balancer market rates vs TRP 1:1 redemption rate
Execution Flow:
Flashloan underlying from Aave V3 (0.09% premium)
Calculate optimal spending for equal rON and rOFF quantities
Buy rON from Balancer using calculated amount
Buy rOFF from Balancer using calculated amount
Redeem equal amounts of rON + rOFF for underlying (1:1)
Repay Aave flashloan with premium
Retain profit from redemption value exceeding purchase cost
Use Case: When market is selling risk tokens above 1:1 underlying value
Bot Runtime
Runtime
Node.js v18+
Language
TypeScript 5.7+
Blockchain Library
ethers.js v6
Dependencies
Protocol Integrations:
@trp/core- Risk Protocol core contracts (SmartToken, WrappedSmartToken)@trp/esp- Elastic Supply Pool (Balancer-based)
External Protocols:
Aave V3 Pool (Routes 5 & 6)
Performance Metrics
Cycle Time
1.5-3.0 seconds (optimized)
Data Fetch
~300-500ms (batched API calls)
Route Execution
~1.2-2.5s (parallel execution)
Memory Usage
< 200MB steady state
RPC Batch Size
100 calls per batch
Deployment
Prerequisites
Smart Contract Deployment:
Deploy Strategy contract using Hardhat UUPS proxy
Configure contract with token addresses and pool addresses
Set Aave pool address for Routes 5 & 6 (optional)
Verify contract on block explorer
Bot Deployment:
Configure environment variables (RPC, private key, contract addresses)
Fund bot wallet with ETH for gas
Set API URL for price data endpoint
Bot Output Example
The Trading 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
