A TypeScript-based arbitrage trading bot for Solana that identifies and executes profitable trading opportunities across various decentralized exchanges.
- Triangle Arbitrage: Identifies price discrepancies across DEXes for triangular arbitrage opportunities (A → B → C → A)
- Paper Trading Mode: Test strategies without risking real funds
- Mempool Monitoring: Detect large pending swaps that might create temporary arbitrage opportunities
- Jupiter Integration: Leverages Jupiter Aggregator for optimal swap routes
- Customizable Configuration: Adjust profit thresholds, trading size, token pairs, and more
- Performance Tracking: Records trade history, success rates, and profitability metrics
- Bun runtime (latest version)
- TypeScript
- Solana CLI (optional, for wallet setup)
- Helius RPC API key for enhanced Solana RPC access
-
Clone the repository:
git clone https://github.com/yourusername/solana-arbitrage-bot.git cd solana-arbitrage-bot
-
Install dependencies:
bun install
-
Configure your environment:
- Create a
.env
file based on.env.example
- Obtain a Helius RPC API key and add it to your
.env
file - Generate a Solana wallet (or use an existing one) for trading
- Create a
-
Compile TypeScript (if needed):
bun run build
Configure the bot by editing config.ts
or setting environment variables. Key settings include:
- RPC Connection: URLs for Helius RPC and WebSocket connections
- Wallet Settings: Path to wallet key file and gas buffer amount
- Arbitrage Parameters: Minimum profit threshold, max trade size, route timeout, etc.
- Token Settings: Base pairs to use and tokens to exclude
- Paper Trading: Initial balances, slippage simulation, etc.
Example .env
file:
HELIUS_RPC_URL=https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY
HELIUS_WS_URL=wss://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY
PRIVATE_KEY_PATH=./wallet-key.json
PAPER_TRADING=true
MIN_PROFIT_THRESHOLD=0.008
MAX_TRADE_SIZE=10
MONITORING_INTERVAL=5000
LOG_LEVEL=info
bun run start -- start --paper-trading
bun run start -- start
bun run start -- start --mempool
bun run start -- start --debug
bun run start -- start --paper-trading --mempool --debug
bun main.ts start --paper-trading
-
Route Generation: The bot generates potential arbitrage routes involving major tokens (SOL, USDC, USDT) and other tokens with good liquidity.
-
Opportunity Scanning: For each route, the bot simulates trades using Jupiter to compute potential profits.
-
Execution: When a profitable opportunity exceeding the minimum threshold is found, the bot:
- In paper trading mode: Simulates the execution with configured success rate and slippage
- In production mode: Executes the trades on actual DEXes via Jupiter
-
Mempool Monitoring (if enabled): Watches for large pending swaps and quickly checks if they create arbitrage opportunities when executed.
-
Analysis: Tracks performance metrics and generates reports on profitability.
Paper trading mode simulates trading without using real funds. It features:
- Configurable initial token balances
- Simulated slippage and network latency
- Success rate simulation (to account for failed transactions in real trading)
- Detailed trade records and performance reports
- Gas fee estimation
To view reports:
bun run start -- paper-trading-report
Or directly:
bun main.ts paper-trading-report
- Private Key Safety: Store your wallet key securely, preferably in a hardware wallet
- Start Small: Begin with small trade sizes and increase gradually as you verify profitability
- Risks: Be aware of potential risks including slippage, failed transactions, and market volatility
- Gas Costs: Ensure your wallet has sufficient SOL for transaction fees