Files
mev-beta/docs/monitoring.md
2025-09-14 06:21:10 -05:00

3.4 KiB

Monitoring System Documentation

This document explains how the MEV bot monitors the Arbitrum sequencer for potential swap transactions by reading L2 messages and parsing them to find opportunities.

Overview

The monitoring system connects to Arbitrum RPC and WebSocket endpoints to continuously monitor for new blocks and L2 messages. It identifies potential swap transactions from both sources and forwards them to the market pipeline for analysis.

Components

ArbitrumMonitor

The main monitoring component that handles:

  • Connecting to the Arbitrum sequencer and parsing L2 messages to find potential swap opportunities
  • Connecting to the Arbitrum WSS endpoint for real-time data, with RPC as redundant backup
  • Subscribing to new blocks and L2 message feeds for comprehensive coverage
  • Processing transactions with high frequency (every 250ms) for competitive advantage
  • Identifying potential swap transactions from both blocks and L2 messages

L2 Message Processing

Each L2 message is analyzed to determine if it represents a potential opportunity:

  1. Check if the message contains DEX interaction data
  2. Decode the message to extract swap parameters
  3. Extract token addresses and amounts
  4. Calculate potential price impact

Transaction Processing

Each transaction is analyzed to determine if it's a potential swap:

  1. Check if the transaction is calling a known DEX contract
  2. Decode the transaction data to extract swap parameters
  3. Extract token addresses and amounts
  4. Calculate potential price impact

Configuration

The monitoring system is configured through config/config.yaml:

  • arbitrum.rpc_endpoint: The RPC endpoint to connect to
  • arbitrum.ws_endpoint: The WebSocket endpoint for real-time data
  • bot.polling_interval: How often to check for new blocks (minimum 250ms)
  • arbitrum.chain_id: The chain ID to ensure we're on the correct network

Implementation Details

The monitor uses the go-ethereum library to interact with the Arbitrum network. It implements efficient polling and WebSocket subscriptions to minimize latency while ensuring comprehensive coverage of opportunities.

Key features:

  • Real-time L2 message processing via WebSocket
  • Graceful error handling and reconnection for both RPC and WebSocket
  • Configurable polling intervals with 250ms minimum for high-frequency processing
  • Transaction sender identification
  • Support for both RPC and WebSocket endpoints with automatic fallback
  • Processing of both blocks and L2 messages for complete opportunity coverage

L2 Message Parsing

The monitoring system specifically focuses on parsing L2 messages to identify opportunities before they are included in blocks:

Message Identification

  • Filters L2 messages for DEX-related activities
  • Identifies pool swaps and router swaps from message content
  • Extracts transaction parameters from message data

Early Opportunity Detection

  • Processes L2 messages with minimal delay
  • Calculates potential profitability from message data
  • Prioritizes high-value opportunities for immediate analysis
  • Provides competitive advantage by identifying opportunities before block inclusion

Data Integration

  • Combines data from L2 messages and blocks for comprehensive analysis
  • Uses message data to pre-analyze potential opportunities
  • Falls back to block data when message data is unavailable
  • Maintains consistency between message and block processing