Skip to content

xnotok-ops/rpc-optimizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ RPC Optimizer

High-performance RPC optimization for EVM (Ethereum/Base) & Solana β€” with both Node.js and Rust implementations.

Node.js Rust License


⚑ Performance

Metric Node.js Rust
Batch 5 RPC calls 188ms 53ms
Binary size ~200MB ~3MB
Cold start ~500ms Instant

Rust is 3.5x faster for latency-critical operations like minting & arbitrage.


✨ Features

Feature Node.js Rust Description
Benchmark RPCs βœ… βœ… Auto-find fastest RPC endpoint
Multi-RPC Failover βœ… βœ… Auto-switch on failures
Request Batching βœ… βœ… Combine calls into 1 HTTP request
Nonce Caching βœ… βœ… Pre-fetch for fast tx building
Retry + Backoff βœ… βœ… Exponential/Fibonacci strategies
Rate Limiter βœ… βœ… Token bucket algorithm
Circuit Breaker βœ… βœ… Prevent cascade failures
WebSocket βœ… - Real-time subscriptions
EVM Client βœ… - High-level ETH/Base API
Solana Client βœ… - High-level Solana API

πŸ”— Supported Chains

Chain RPCs Included
Ethereum Llama, PublicNode, dRPC, MEVBlocker
Base Base Official, Llama, PublicNode, dRPC
Solana Solana Official, PublicNode, dRPC

πŸ“¦ Installation

Node.js

cd node
npm install
npm run example

Rust

cd rust
cargo build --release
cargo run --release

πŸš€ Quick Start

Node.js

import { createEVMClient, createSolanaClient } from './src/index.js';

// Create client
const eth = createEVMClient('ethereum');

// Auto-select fastest RPC
await eth.warmup(['0xYourWallet...']);

// Use it
const block = await eth.getBlockNumber();
const balance = await eth.getBalance('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045');

console.log('Block:', block);
console.log('Balance:', balance, 'ETH');

Rust

use rpc_optimizer::*;

#[tokio::main]
async fn main() {
    // Benchmark and find fastest
    let config = default_config();
    let mut benchmark = create_benchmark();
    
    if let Some(eth_config) = config.get("ethereum") {
        benchmark.benchmark_chain("ethereum", eth_config, 3).await;
        benchmark.print_results("ethereum");
    }

    // Batch requests
    let result = batch("https://eth.drpc.org")
        .get_balance("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", "latest")
        .block_number()
        .gas_price()
        .execute()
        .await;

    println!("Batch completed in {}ms", result.latency_ms);
}

πŸ“Š Benchmark Example

πŸ” Benchmarking Ethereum Mainnet (3 rounds each)...

  Testing Llama          ... βœ… avg: 212.8ms | p95: 212.8ms
  Testing PublicNode     ... βœ… avg: 214.7ms | p95: 263.8ms
  Testing dRPC           ... βœ… avg: 50.6ms  | p95: 73.9ms
  Testing MEVBlocker     ... βœ… avg: 706.6ms | p95: 997.9ms

πŸ“Š Results for ETHEREUM
──────────────────────────────────────────────────────────────────
Rank β”‚ Name            β”‚ Avg (ms) β”‚ P95 (ms) β”‚ Min (ms) β”‚ Success
──────────────────────────────────────────────────────────────────
   1 β”‚ dRPC            β”‚     50.6 β”‚     73.9 β”‚     33.9 β”‚ 100%
   2 β”‚ PublicNode      β”‚    214.7 β”‚    263.8 β”‚    180.6 β”‚ 100%
   3 β”‚ Llama           β”‚    212.8 β”‚    212.8 β”‚    212.8 β”‚ 33%
   4 β”‚ MEVBlocker      β”‚    706.6 β”‚    997.9 β”‚    555.8 β”‚ 100%
──────────────────────────────────────────────────────────────────

βœ… Fastest: dRPC (50.6ms avg)

πŸ”§ Use Cases

Use Case Recommended
FCFS NFT Minting Rust (microseconds matter)
Arbitrage Bot Rust (latency critical)
MEV Bot Rust (racing other bots)
Monitoring/Alerts Node.js (easier to build)
Dashboard/API Node.js (rich ecosystem)
Prototyping Node.js (fast iteration)

πŸ“ Project Structure

rpc-optimizer/
β”œβ”€β”€ node/                   # Node.js implementation
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ index.js        # Main exports
β”‚   β”‚   β”œβ”€β”€ config.js       # RPC configuration
β”‚   β”‚   β”œβ”€β”€ benchmark.js    # Latency testing
β”‚   β”‚   β”œβ”€β”€ failover.js     # Multi-RPC failover
β”‚   β”‚   β”œβ”€β”€ batch.js        # Request batching
β”‚   β”‚   β”œβ”€β”€ nonce.js        # Nonce caching
β”‚   β”‚   β”œβ”€β”€ retry.js        # Retry strategies
β”‚   β”‚   β”œβ”€β”€ websocket.js    # WebSocket support
β”‚   β”‚   └── chains/
β”‚   β”‚       β”œβ”€β”€ evm.js      # ETH/Base client
β”‚   β”‚       └── solana.js   # Solana client
β”‚   β”œβ”€β”€ config/
β”‚   β”‚   └── rpcs.json       # RPC endpoints
β”‚   β”œβ”€β”€ examples/
β”‚   β”‚   └── usage.js        # Example usage
β”‚   └── package.json
β”‚
└── rust/                   # Rust implementation
    β”œβ”€β”€ src/
    β”‚   β”œβ”€β”€ lib.rs          # Library exports
    β”‚   β”œβ”€β”€ main.rs         # Example runner
    β”‚   β”œβ”€β”€ config.rs       # RPC configuration
    β”‚   β”œβ”€β”€ benchmark.rs    # Latency testing
    β”‚   β”œβ”€β”€ failover.rs     # Multi-RPC failover
    β”‚   β”œβ”€β”€ batch.rs        # Request batching
    β”‚   β”œβ”€β”€ nonce.rs        # Nonce caching
    β”‚   └── retry.rs        # Retry strategies
    └── Cargo.toml

🀝 Contributing

  1. Fork the repo
  2. Create feature branch (git checkout -b feature/amazing)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing)
  5. Open a Pull Request

πŸ“„ License

MIT License - feel free to use in your projects!


πŸ”— Related Projects


Built with ⚑ by @xnotok

About

πŸš€ High-performance RPC optimization for EVM (ETH/Base) & Solana β€” connection pooling, multi-RPC failover, latency benchmarking, request batching, nonce caching

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors