Real-time wash trading and token manipulation detection system for the XRP Ledger DEX.
XRP Watchdog is a sophisticated monitoring system that analyzes DEX activity on the XRP Ledger to detect potential wash trading, pump-and-dump schemes, and other market manipulation tactics. The system provides a comprehensive Grafana dashboard with risk scoring, pattern analysis, and investigative tools.
- Real-time Monitoring: Collects and analyzes DEX trades every 5 minutes with 100% ledger coverage
- Advanced Risk Scoring: Multi-component algorithm (0-100 scale) detecting manipulation patterns
- Burst Detection: Identifies suspicious high-frequency trading clusters and bot activity
- Token Whitelisting: Excludes known legitimate tokens from risk analysis
- Interactive Dashboard: Beautiful Grafana interface with educational content
- Account Tracking: Monitors suspicious accounts trading high-risk tokens
- Automated Analysis: Self-healing system with comprehensive logging
The dashboard provides real-time insights into token manipulation on the XRP Ledger DEX, featuring:
- Overview Stats: Token counts, average risk scores, and suspicious activity rates
- Activity Heatmap: 7-day visualization of suspicious trading patterns
- Trading Volume: Time-series analysis of XRP trading activity
- Top Suspicious Tokens: Ranked list with risk scores, burst detection, and trade metrics
- Interactive Methodology Guide: Educational content explaining detection algorithms
Required before installation:
- Docker - For running ClickHouse database (Install Docker)
- Docker Compose - Usually included with Docker Desktop
- Python 3.8+ - For collector and analyzer scripts
- pip3 - Python package manager (
sudo apt install python3-pipon Debian/Ubuntu) - XRP Ledger full history node - Access via RPC (Docker container or local rippled)
Optional (for visualization):
- Grafana 9.0+ - For dashboard visualization
Note: The install.sh script will check for these prerequisites and guide you through setup.
For a comprehensive list of all system dependencies, Python packages, Docker containers, and version requirements, see docs/DEPENDENCIES.md.
Option A: Automated Installation (Recommended)
# Clone the repository
git clone https://github.com/realgrapedrop/xrp-watchdog.git
cd xrp-watchdog
# Run interactive installer
./install.shThe installer will:
- ✅ Check all prerequisites (Docker, Python, etc.)
- ✅ Detect your rippled configuration automatically
- ✅ Start ClickHouse database via Docker Compose
- ✅ Create Python virtual environment and install dependencies
- ✅ Initialize database schema
- ✅ Optionally setup cron job for auto-collection
- ✅ Optionally run initial data collection
Option B: Manual Installation
# Clone the repository
git clone https://github.com/realgrapedrop/xrp-watchdog.git
cd xrp-watchdog
# Start ClickHouse
cd compose
docker compose up -d
cd ..
# Create virtual environment
python3 -m venv venv
source venv/bin/activate
# Install dependencies
pip install clickhouse-connect
# Initialize database
docker exec -i xrp-watchdog-clickhouse clickhouse-client --multiquery < sql/schema.sql-
Configure ClickHouse connection in collector and analyzer scripts:
CLICKHOUSE_HOST = "localhost" CLICKHOUSE_PORT = 8123 CLICKHOUSE_DB = "xrp_watchdog"
-
Set up cron job for automated collection (every 5 minutes):
crontab -e # Add: */5 * * * * /home/grapedrop/projects/xrp-watchdog/run_collection.sh >> /home/grapedrop/projects/xrp-watchdog/logs/auto_collection.log 2>&1
-
Configure Grafana:
- Add ClickHouse data source pointing to your ClickHouse instance
- Option A (Quick): Import complete dashboard
- Dashboards → Import → Upload JSON file
- Select
grafana/xrp-watchdog-dashboard.json - Choose your ClickHouse datasource
- Option B (Manual): Build dashboard from queries
- Use queries from
grafana/token_stats_queries.md - Create panels manually with custom layouts
- Use queries from
# Activate virtual environment
source venv/bin/activate
# Run collection (130 ledgers) with analysis
python collectors/collection_orchestrator.py 130 --analyze
# Run analyzer separately
python analyzers/token_analyzer.py┌───────────────────────────────────────────────────────────┐
│ XRP Ledger Node │
│ (Full History via RPC) │
└──────────────────────────┬────────────────────────────────┘
│
▼
┌───────────────────────────────────────────────────────────┐
│ Collection Orchestrator │
│ ┌────────────────────────────────────────────────────┐ │
│ │ • Fetches 130 ledgers every 5 minutes │ │
│ │ • Extracts executed trades (OfferCreate txs) │ │
│ │ • Processes payment transactions │ │
│ │ • Inserts into ClickHouse │ │
│ └────────────────────────────────────────────────────┘ │
└──────────────────────────┬────────────────────────────────┘
│
▼
┌───────────────────────────────────────────────────────────┐
│ ClickHouse Database │
│ ┌────────────────────────────────────────────────────┐ │
│ │ Tables: │ │
│ │ • executed_trades - Raw trade data │ │
│ │ • token_stats - Aggregated risk metrics │ │
│ │ • token_whitelist - Legitimate tokens │ │
│ └────────────────────────────────────────────────────┘ │
└──────────────────────────┬────────────────────────────────┘
│
▼
┌───────────────────────────────────────────────────────────┐
│ Token Analyzer │
│ ┌────────────────────────────────────────────────────┐ │
│ │ • Calculates risk scores (5 components) │ │
│ │ • Detects burst patterns │ │
│ │ • Applies whitelist exclusions │ │
│ │ • Updates token_stats table │ │
│ └────────────────────────────────────────────────────┘ │
└──────────────────────────┬────────────────────────────────┘
│
▼
┌───────────────────────────────────────────────────────────┐
│ Grafana Dashboard │
│ ┌────────────────────────────────────────────────────┐ │
│ │ • Risk Score Overview │ │
│ │ • Top Suspicious Tokens │ │
│ │ • Top Suspicious Accounts │ │
│ │ • Whitelisted Tokens │ │
│ │ • Methodology Guide (Educational) │ │
│ └────────────────────────────────────────────────────┘ │
└───────────────────────────────────────────────────────────┘
The system uses a 5-component algorithm (0-100 scale) to detect manipulation:
- Formula:
min(60, log10(volume_xrp / 1_000_000 + 1) × 15) - Purpose: Logarithmic scaling prevents extreme outliers from dominating scores
- Scaling Examples: 1K XRP ≈ 5pts, 10K ≈ 12pts, 100K ≈ 25pts, 1M ≈ 38pts
- Why: Large volumes can indicate manipulation, but linear scaling would be unfair
- Metric: Number of unique accounts trading the token
- Scoring:
- ≤2 takers: 30 pts (extreme concentration)
- 3-5 takers: 22 pts (high concentration)
- 6-10 takers: 15 pts (moderate concentration)
- 11-20 takers: 8 pts (low concentration)
- 20+ takers: 3 pts (normal distribution)
- Why: Manipulators typically use few accounts; real tokens have many traders
- Metric: Coefficient of variation in trade prices
- Why: Bots trade at precise prices; real markets have natural variance
- Threshold: <0.5% variance = maximum suspicion
- Metric: Trades per hour (temporal clustering)
- Scoring:
- ≥100/hr: 15 pts (extreme burst)
- ≥50/hr: 12 pts (high burst)
- ≥20/hr: 8 pts (moderate burst)
- Why: Catches pump-and-dump schemes and bot-driven campaigns
- Metric: Coefficient of variation in trade sizes
- Why: Bots trade uniform amounts; humans vary
- Threshold: <2% variance = robotic pattern
The v2.0 algorithm uses two time windows for comprehensive analysis:
-
24-hour window: Pattern detection metrics (burst score, price variance, trade uniformity)
- Captures short-term manipulation tactics
- Identifies rapid pump-and-dump schemes
- Detects bot-like precision in recent activity
-
7-day window: Impact assessment (total volume, unique traders)
- Measures sustained market impact
- Captures longer manipulation campaigns
- Provides context for overall token activity
This dual approach ensures both recent suspicious patterns AND their cumulative impact are considered in risk scoring.
-
Collection Phase (every 5 minutes):
- Fetch latest 130 ledgers from XRP Ledger node
- Extract OfferCreate transactions with executed trades
- Store raw trade data in
executed_tradestable - 280,000+ trades collected to date
-
Analysis Phase (after collection):
- Aggregate trades by token (currency code + issuer)
- Calculate statistical metrics (price variance, trade density, etc.)
- Compute risk scores using 5-component algorithm
- Update
token_statstable - Runtime: ~40ms for 500+ tokens
-
Visualization Phase (continuous):
- Grafana queries ClickHouse every 5 minutes
- Real-time dashboard updates
- Interactive exploration with XRPScan integration
Seven key metrics displayed:
- Tracked: Total tokens being monitored (currently 928)
- Active (1hr): Tokens with trades in last hour
- Suspicious Rate: Percentage of flagged accounts (currently 17.8%)
- Total Trades: Complete trade count (currently 282,735)
- Total Tokens: Non-whitelisted tokens analyzed (currently 502)
- Avg Risk Score: Market health indicator (currently 30.2)
- High Risk (≥60): Tokens with elevated risk scores (currently 16)
Table showing 20 highest-risk tokens with:
- Token: Currency code (hex decoded to ASCII when possible)
- Issuer: Account address (clickable link to XRPScan)
- Risk Score: 0-100 manipulation likelihood
- Trades: Total executed trades count
- XRP Volume (24h): Short-term trading activity
- XRP Volume (7d): Longer-term impact assessment
- Price Var %: Price consistency (low = bot precision)
- Trades/Hour: Activity density (high = burst)
- Burst: Temporal clustering score (0-100)
- Duration (min): How long the pattern lasted
Accounts actively trading high-risk tokens:
- Account address (clickable to XRPScan)
- Token being traded
- Trade count and volume
- First seen / last seen timestamps
Collapsible educational panel (collapsed by default) with three-column balanced layout:
Column 1: Detection Fundamentals
- What we're detecting and why
- Manipulation tactics (wash trading, layering, pump & dump, bot campaigns)
- Real-world impact on traders and markets
- Detection capabilities and coverage
- Table columns explained
Column 2: Risk Scoring Deep Dive
- 5-component algorithm breakdown
- Volume, token focus, price stability, burst detection, trade uniformity
- Detailed scoring thresholds and formulas
- Real example: LESS token (Risk: 72) with pattern analysis
Column 3: Practical Investigation
- Investigation workflow and XRPScan integration
- Risk tiers (CRITICAL, HIGH, MEDIUM, LOW)
- Red flags to watch for
- Volume scale for context
- Whitelist status explanation
xrp-watchdog/
├── analyzers/
│ └── token_analyzer.py # Risk scoring engine
├── collectors/
│ └── collection_orchestrator.py # Ledger data collector
├── grafana/
│ ├── xrp-watchdog-dashboard.json # Complete dashboard export (ready to import)
│ └── token_stats_queries.md # Dashboard query reference
├── logs/
│ ├── auto_collection.log # Automated collection log
│ └── cron.log # Cron execution log
├── scripts/
│ ├── prod_start.sh # Start production stack
│ ├── prod_stop.sh # Stop production stack
│ ├── prod_restart.sh # Restart production stack
│ ├── getMakerTaker.sh # Trade extraction helper
│ ├── manage_whitelist.py # Whitelist management tool
│ └── grafana/
│ └── provision-dev-to-prod.sh # Dashboard sync script
├── sql/
│ ├── schema.sql # Database schema
│ └── migrations/
│ ├── 001_add_risk_score_v2.sql
│ └── 002_rename_risk_score_column.sql
├── README.md # This file
├── requirements.txt # Python dependencies
├── run_analyzer.sh # Analyzer execution script
└── run_collection.sh # Collection execution script
- Collection Frequency: Every 5 minutes
- Ledger Coverage: 100% (130 ledgers per run)
- Analysis Speed: ~40ms for 500+ tokens
- Total Trades Collected: 282,735+ (as of November 2025)
- Tokens Analyzed: 502 active tokens
- Tokens Tracked: 928 total tokens in system
- Average Risk Score: 30.2 (healthy market)
- High Risk Tokens: 16 tokens with risk ≥60
- Database Size: Optimized with ReplacingMergeTree
- Query Performance: <100ms for dashboard queries
Add legitimate tokens to exclude from risk scoring:
INSERT INTO xrp_watchdog.token_whitelist VALUES
('USD', 'rhub8VRN55s94qWKDv6jmDy1pUykJzF3wq', 'stablecoin'),
('BTC', 'rcA8X3TVMST1n3CJeAdGk1RdRCHii7N2h', 'established');Categories:
stablecoin- USD/EUR pegged tokensestablished- Long-running legitimate projectsverified- Verified by community/exchanges
Problem: Collection fails to fetch ledgers
- Check: XRP Ledger node connectivity
- Solution: Verify RPC endpoint in collector script
Problem: Duplicate trades inserted
- Check: ClickHouse ReplacingMergeTree is working
- Solution: Run
OPTIMIZE TABLE executed_trades FINAL;
Problem: Risk scores not updating
- Check: Token analyzer execution in cron logs
- Solution: Manually run
python analyzers/token_analyzer.py
Problem: Whitelisted tokens showing risk scores
- Check: Token code and issuer match exactly in whitelist
- Solution: Verify case sensitivity and whitespace
Problem: Grafana shows no data
- Check: ClickHouse data source connection
- Solution: Test query in ClickHouse client first
Problem: Token names showing as hex
- Check: Query includes
unhex()andreplaceRegexpAll()functions - Solution: Use updated queries from
grafana/token_stats_queries.md
# Activate virtual environment
source venv/bin/activate
# Run collector in dry-run mode
python collectors/collection_orchestrator.py 10 --dry-run
# Run analyzer with verbose output
python analyzers/token_analyzer.py- Database Schema Changes: Create migration in
sql/migrations/ - Collector Enhancements: Modify
collection_orchestrator.py - Risk Algorithm Updates: Update
token_analyzer.pyand README.md - Dashboard Changes: Document queries in
grafana/token_stats_queries.md
XRP Watchdog uses a dev → prod workflow for safe dashboard updates.
Quick workflow:
- Edit dashboard in dev Grafana (
http://localhost:3000) - Run provisioning script:
./scripts/grafana/provision-dev-to-prod.sh - Changes go live at
https://xrp-watchdog.grapedrop.xyz
Features:
- ✅ Automatic production backups before changes
- ✅ Datasource UID validation
- ✅ Git versioning with auto-commit
- ✅ Interactive prompts for safety
- ✅ Rollback instructions provided
Full documentation: See docs/DEV-TO-PROD-SYNC.md for:
- Architecture overview (dev vs prod environments)
- Creating Grafana service accounts with correct permissions
- Synchronization requirements (datasource UIDs, dashboard UIDs)
- Step-by-step provisioning workflow
- Troubleshooting common issues
- Rollback procedures
- Python: PEP 8 compliant
- SQL: Uppercase keywords, 2-space indentation
- Documentation: Markdown with clear sections
- auto_collection.log: Collection status, trade counts, errors
- cron.log: Cron execution timestamps and exit codes
# Tail collection log
tail -f logs/auto_collection.log
# Check cron execution
tail -f logs/cron.log
# Verify cron schedule
crontab -l# Check recent trades
clickhouse-client --query "SELECT COUNT(*) FROM xrp_watchdog.executed_trades WHERE time > now() - INTERVAL 1 HOUR"
# Check token stats freshness
clickhouse-client --query "SELECT MAX(last_updated) FROM xrp_watchdog.token_stats"
# Check disk usage
clickhouse-client --query "SELECT formatReadableSize(sum(bytes)) as size FROM system.parts WHERE database = 'xrp_watchdog'"XRP Watchdog includes production stack management scripts for controlling all services.
Located in scripts/:
prod_start.sh- Start entire production stack with health checksprod_stop.sh- Gracefully stop all production servicesprod_restart.sh- Restart entire production stack
The production stack includes:
- ClickHouse Database - Data storage layer (
xrp-watchdog-clickhousecontainer) - Grafana Dashboard - Visualization layer (
grafana-prod-watchdogcontainer) - Cloudflare Tunnel - Public access layer (
cloudflared-xrp-watchdogsystemd service) - Cron Job - Automated data collection (runs every 5 minutes)
Start production stack:
./scripts/prod_start.shFeatures:
- Starts services in correct order (ClickHouse → Grafana → Tunnel)
- Waits for each service to become healthy before proceeding
- Runs comprehensive health checks
- Verifies tunnel connections (expects 4 active connections)
- Checks trade count in database
- Tests public URL accessibility
- Shows detailed status summary
Stop production stack:
./scripts/prod_stop.shFeatures:
- Stops services gracefully in reverse order
- Preserves all data (ClickHouse volumes remain intact)
- Cloudflare Tunnel stops accepting traffic
- Cron job continues running but will fail until restart
Restart production stack:
./scripts/prod_restart.shFeatures:
- Calls
prod_stop.shfollowed byprod_start.sh - Useful after configuration changes
- Full health verification on restart
- 3-second delay between stop and start
The start script provides detailed status:
Service Status:
✓ ClickHouse: 524,249 trades in database
✓ Grafana: ClickHouse datasource configured
✓ Public URL: Accessible
✓ Tunnel: 4 active connections
✓ Cron: RUNNING (every 5 minutes)
Endpoints:
• Public: https://xrp-watchdog.grapedrop.xyz
• Local: http://localhost:3002
Problem: Scripts fail with permission errors
- Solution: Ensure scripts are executable:
chmod +x scripts/prod_*.sh
Problem: Tunnel shows 0 connections after start
- Check:
systemctl status cloudflared-xrp-watchdog - Solution: Verify tunnel config at
~/.cloudflared/config-xrp-watchdog.yml
Problem: Grafana health check fails
- Check:
docker logs grafana-prod-watchdog - Solution: Verify port 3002 is not in use by another process
Problem: ClickHouse won't start
- Check:
docker logs xrp-watchdog-clickhouse - Solution: Verify Docker has sufficient resources and data volumes exist
- Production Dashboard: https://xrp-watchdog.grapedrop.xyz
- Local Grafana: http://localhost:3002
- ClickHouse HTTP: http://localhost:8123
- ClickHouse Native: localhost:9000
- Historical Data: System only analyzes trades from collection start date
- Cross-Chain Activity: Only monitors XRP Ledger DEX (not CEXs or other chains)
- False Positives: Legitimate low-liquidity tokens may score high
- Real-time Detection: 5-minute delay between trade execution and detection
- Burst Scoring: Requires multiple trades; single large trades not detected
- ✅ Basic trade collection from XRP Ledger
- ✅ Risk scoring algorithm v1.0 (linear scaling)
- ✅ Risk scoring algorithm v2.0 (logarithmic scaling + burst detection)
- ✅ Grafana dashboard with educational content
- ✅ Token whitelisting system
- ✅ Automated 5-minute collection
- ✅ Account-level tracking
- Historical risk score tracking (time series)
- Alert system (email/Slack notifications for high-risk tokens)
- Network graph visualization (account clustering)
- ML-based anomaly detection
- API for programmatic access
- Multi-chain support (Ethereum DEX, etc.)
- Advanced pattern recognition (coordinated trading across tokens)
This is currently a personal monitoring project. If you'd like to contribute:
- Fork the repository
- Create a feature branch
- Make your changes with clear commit messages
- Test thoroughly
- Submit a pull request
MIT License - see LICENSE file for details
- XRP Ledger Foundation - For excellent documentation and RPC infrastructure
- ClickHouse - For blazing-fast analytical database
- Grafana - For beautiful visualization capabilities
- XRPL Community - For insights into DEX manipulation patterns
For questions, issues, or suggestions, please open a GitHub issue.
Disclaimer: This tool is for educational and research purposes. It detects potential manipulation patterns and should not be used as the sole basis for trading decisions. Always conduct thorough research before trading any token.
