A comprehensive blockchain indexer for the Omnipair protocol on Solana, built with a modern hybrid architecture combining Rust performance with TypeScript flexibility.
This project uses a hybrid Rust/TypeScript architecture that leverages the strengths of both languages:
- Rust Indexer Daemon: High-performance data ingestion and processing using the Carbon framework
- TypeScript API Server: Flexible REST API for client applications using modern web technologies
- Shared Database Layer: PostgreSQL with TimescaleDB for optimal time-series data storage
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Solana RPC β β WebSocket β β Client Apps β
β & WebSocket β β Real-time β β & Frontends β
βββββββββββ¬ββββββββ βββββββββββ¬ββββββββ βββββββββββ¬ββββββββ
β β β
ββββββββββββββββββββββββΌβββββββββββββββββββββββ
β β
βββββββββββββββββββββββββββββββΌββββββββββββββββββββββΌβββββββ
β β
β βββββββββββββββββββββββ βββββββββββββββββββββββββββ β
β β Rust Indexer β β TypeScript API β β
β β (Carbon-based) β β (Bun + Drizzle) β β
β β β β β β
β β β’ Event Processing β β β’ REST Endpoints β β
β β β’ Account Decoding β β β’ Query Optimization β β
β β β’ Real-time Sync β β β’ Response Caching β β
β β β’ Backfilling β β β’ Rate Limiting β β
β βββββββββββββββββββββββ βββββββββββββββββββββββββββ β
β β β β
βββββββββββββββββββββββΌβββββββββββββββββββββββΌββββββββββββββ
β β
βΌ βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β PostgreSQL + TimescaleDB β
β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββββββ β
β β Pairs β β Positions β β Transactions β β
β β Config β β & Health β β (Hypertable) β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββββββ β
β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββββββ β
β β Aggregates β β Price Feeds β β Analytics β β
β β (1m, 1h) β β & Charts β β & Metrics β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- Real-time Transaction Monitoring: Live processing of Omnipair protocol events
- Historical Backfilling: Complete historical data processing with gap detection
- High Performance: Built with Rust and the Carbon framework for maximum throughput
- Account Tracking: Real-time monitoring of pairs, positions, and protocol state
- Robust Error Handling: Automatic retry logic and comprehensive error recovery
- RESTful API: Clean, well-documented REST endpoints for all data access
- Type Safety: Full TypeScript types with Drizzle ORM integration
- Performance Optimized: Efficient database queries with caching strategies
- Rate Limiting: Built-in protection against API abuse
- Health Monitoring: Comprehensive health checks and system status endpoints
- TimescaleDB Integration: Optimized for time-series queries and analytics
- Automatic Aggregation: Continuous aggregates for price feeds and analytics
- Data Retention: Intelligent data lifecycle management with compression
- Migration System: Version-controlled schema evolution with Drizzle
omnipair-indexer/
βββ indexer/ # π¦ Rust indexer daemon
β βββ src/main.rs # Main indexer application
β βββ crates/ # Carbon framework components
β βββ decoders/ # Omnipair protocol decoders
β βββ datasources/ # RPC and WebSocket data sources
β βββ metrics/ # Performance monitoring
β βββ README.md # Indexer-specific documentation
β
βββ api/ # π‘ TypeScript API server
β βββ src/ # API server source code
β β βββ routes/ # REST endpoint handlers
β β βββ services/ # Business logic layer
β β βββ middleware/ # Express middleware
β βββ README.md # API-specific documentation
β
βββ database/ # ποΈ Shared database layer
β βββ lib/schema.ts # Database schema definitions
β βββ migrations/ # Database migration files
β βββ sql/ # Custom SQL scripts
β βββ README.md # Database documentation
β
βββ docs/ # π Additional documentation
βββ Cargo.toml # Rust workspace configuration
βββ package.json # Node.js workspace configuration
βββ README.md # This file
- Rust 1.82+: Install from rustup.rs
- Bun 1.0+: Install from bun.sh
- PostgreSQL 14+: With TimescaleDB extension
- Git: For repository management
# Clone the repository
git clone <repository-url>
cd omnipair-indexer
# Install dependencies
bun install # For TypeScript components# Create database
createdb omnipair_indexer
# Enable TimescaleDB extension
psql omnipair_indexer -c "CREATE EXTENSION IF NOT EXISTS timescaledb;"
# Run database migrations
cd database
bun run migrate
psql omnipair_indexer -f sql/setup-timescaledb.sql
cd ..Create .env files in the appropriate directories:
# Root .env (shared configuration)
DATABASE_URL=postgresql://username:password@localhost:5432/omnipair_indexer
SOLANA_RPC_URL=https://api.mainnet-beta.solana.com
SOLANA_WS_URL=wss://api.mainnet-beta.solana.com
# Indexer-specific (indexer/.env)
RPC_URL=https://api.mainnet-beta.solana.com
RPC_WS_URL=wss://api.mainnet-beta.solana.com
RUST_LOG=info
# API-specific (api/.env)
PORT=3000
NODE_ENV=development
LOG_LEVEL=info# Terminal 1: Start the indexer daemon
cd indexer
cargo run --release
# Terminal 2: Start the API server
cd api
bun run dev
# Or use workspace commands from root
cargo run -p omnipair-carbon-indexer # Indexer
bun run api:dev # API Server# Check API health
curl http://localhost:3000/health
# Check indexer logs
tail -f indexer/logs/indexer.log# Build indexer
cargo build -p omnipair-carbon-indexer
# Run with debug logging
RUST_LOG=debug cargo run -p omnipair-carbon-indexer
# Run tests
cargo test
# Watch for changes
cargo install cargo-watch
cargo watch -x "run -p omnipair-carbon-indexer"# Start development server
cd api
bun run dev
# Run tests
bun test
# Type checking
bun run type-check
# Linting
bun run lint# Generate new migration
cd database
bun run migrate:create
# Apply migrations
bun run migrate
# Run custom SQL
bun run sql path/to/script.sqlThis project is optimized for Railway deployment with multi-service configuration:
- Database Service: PostgreSQL with TimescaleDB
- Indexer Service: Rust daemon (points to
indexer/) - API Service: TypeScript server (points to
api/)
Each service has its own railway.toml configuration file.
# Shared across services
DATABASE_URL=${{Postgres.DATABASE_URL}}
SOLANA_RPC_URL=https://your-premium-rpc.com
SOLANA_WS_URL=wss://your-premium-ws.com
# Indexer-specific
RUST_LOG=info
# API-specific
NODE_ENV=production
PORT=3000# Build all services
docker-compose build
# Start all services
docker-compose up -d
# View logs
docker-compose logs -f- Indexer Health: Internal health monitoring with structured logging
- API Health:
GET /healthendpoint with database connectivity checks - Database Health: TimescaleDB-specific monitoring queries
- Indexer Metrics: Transaction processing rate, RPC call frequency, error rates
- API Metrics: Request rate, response times, error rates
- Database Metrics: Query performance, storage utilization, compression ratios
- Structured Logging: JSON-formatted logs across all services
- Log Levels: Configurable log levels for development and production
- Log Aggregation: Ready for centralized logging systems
# Environment variables
RPC_URL=https://api.mainnet-beta.solana.com
RPC_WS_URL=wss://api.mainnet-beta.solana.com
DATABASE_URL=postgresql://user:pass@host/db
RUST_LOG=info# Server settings
PORT=3000
NODE_ENV=production
# Database
DATABASE_URL=postgresql://user:pass@host/db
# Rate limiting
RATE_LIMIT_WINDOW_MS=60000
RATE_LIMIT_MAX_REQUESTS=100
# CORS
ALLOWED_ORIGINS=https://yourdomain.com- Indexer Documentation: Rust daemon architecture and development
- API Documentation: TypeScript API server and endpoints
- Database Documentation: Schema, migrations, and TimescaleDB setup
- Quick Start Guide: Get up and running in 5 minutes
- Setup Guide: Detailed installation and configuration
- Development Guide: Development practices and architecture details
GET /health- System health checkGET /pairs- List all trading pairsGET /pairs/:address- Get pair detailsGET /users/:address/positions- Get user positionsGET /transactions- Query transaction historyGET /analytics/overview- Protocol analytics
- WebSocket API: Real-time data streaming
- GraphQL API: Flexible query interface
- Authentication: API key and JWT-based auth
- Advanced Analytics: Custom metrics and reporting
- Alerting System: Real-time notifications
# Test database connectivity
psql $DATABASE_URL -c "SELECT version();"
# Check TimescaleDB extension
psql $DATABASE_URL -c "SELECT * FROM pg_extension WHERE extname = 'timescaledb';"# Test Solana RPC
curl -X POST -H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"getHealth"}' \
$SOLANA_RPC_URL# Check indexer logs
tail -f indexer/logs/indexer.log
# Check API health
curl http://localhost:3000/health- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Add tests for new functionality
- Update documentation
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Rust Code: Follow Rust best practices, use
cargo fmtandcargo clippy - TypeScript Code: Use strict TypeScript, follow ESLint rules
- Database Changes: Always create migrations for schema changes
- Documentation: Update relevant documentation for any changes
- Testing: Add tests for new features and bug fixes
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- Issues: Create an issue in the GitHub repository
- Documentation: Check the component-specific README files
- Logs: Review application logs for error details
- Community: Join our Discord/Telegram for community support
Note: This indexer is specifically designed for the Omnipair protocol on Solana. Ensure you're using the correct program ID and connecting to the appropriate Solana network.