A TypeScript-based arbitrage bot that monitors price differences between DEX exchanges and executes profitable trades automatically.
- Real-time price monitoring via WebSocket feeds
- Automatic arbitrage opportunity detection
- Transaction building and submission
- Configurable profit thresholds and risk parameters
- Dry-run mode for testing
arb-bot/
├── src/
│ ├── index.ts # Entry point
│ ├── config/
│ │ └── env.ts # Constants, thresholds
│ ├── state/
│ │ └── market.ts # In-memory prices/liquidity
│ ├── feeds/
│ │ └── dexWs.ts # DEX websocket feed
│ ├── strategy/
│ │ └── arbitrage.ts # Arbitrage opportunity detection logic
│ ├── tx/
│ │ ├── builder.ts # Prebuilt tx calldata
│ │ └── submit.ts # Tx submission
│ ├── utils/
│ │ └── math.ts # Tiny math helpers
│ └── types.ts
├── package.json
├── tsconfig.json
└── README.md
- Install dependencies:
npm install- Configure environment variables (create a
.envfile or set them in your environment):
# Required
PRIVATE_KEY=your_private_key_here
RPC_URL=https://eth.llamarpc.com
DEX_WS_URL=wss://your-dex-websocket-url
DEX_ROUTER_ADDRESS=0x...
# Optional
CHAIN_ID=1
MIN_PROFIT_THRESHOLD_WEI=1000000000000000 # 0.001 ETH
MIN_PROFIT_PERCENT=0.5 # 0.5%
MAX_SLIPPAGE_PERCENT=1.0 # 1%
MAX_GAS_PRICE_GWEI=100
ENABLE_DRY_RUN=true # Set to false for live trading
# Supported tokens (comma-separated addresses)
SUPPORTED_TOKENS=0x...,0x...- Build the project:
npm run build- Run the bot:
npm startOr run in development mode:
npm run devKey configuration parameters in src/config/env.ts:
- MIN_PROFIT_THRESHOLD_WEI: Minimum absolute profit in wei to execute a trade
- MIN_PROFIT_PERCENT: Minimum profit percentage threshold
- MAX_SLIPPAGE_PERCENT: Maximum acceptable slippage
- MAX_GAS_PRICE_GWEI: Maximum gas price to pay for transactions
- ENABLE_DRY_RUN: If true, simulates trades without submitting them
Modify src/feeds/dexWs.ts to match your DEX's WebSocket API:
- Update
subscribe()method with your subscription format - Update
handleMessage()to parse your DEX's message format
Implement arbitrage detection in src/strategy/arbitrage.ts:
- Price difference detection between DEX pools
- Profit calculation
- Opportunity validation
Update src/tx/builder.ts to match your DEX router's interface:
- Adjust the ABI in
encodeSwapCall()for your router contract - Modify swap function parameters as needed
- Never commit your private key - use environment variables
- Start with
ENABLE_DRY_RUN=trueto test without real transactions - Test thoroughly on testnets before mainnet deployment
- Monitor gas prices and set appropriate limits
- Consider implementing additional safety checks (max trade size, cooldown periods, etc.)
- TypeScript strict mode enabled
- Source maps for debugging
- Watch mode:
npm run watch
MIT