A comprehensive shared infrastructure library for Solana trading bots, providing common components, utilities, and services that can be used across multiple bot implementations.
- Jito Client: Unified Jito bundle submission and confirmation
- Monitoring Service: Prometheus metrics and structured logging
- Configuration Management: Centralized configuration handling
- Common Types: Shared data structures and enums
- Utility Functions: Common helper functions and utilities
- Error Handling: Standardized error types and handling
- Performance Optimization: Optimized common operations
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Jito Client β β Monitoring β β Configuration β
β Service β β Service β β Manager β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Common Types β β Utility β β Error β
β & Structs β β Functions β β Handling β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
- Rust 1.70+
- Solana CLI tools
- Jito bundle access
cd shared-infrastructure
cargo build --release
The shared infrastructure uses a centralized configuration system:
[rpc]
mainnet = "https://api.mainnet-beta.solana.com"
devnet = "https://api.devnet.solana.com"
[jito]
endpoint = "https://mainnet.block-engine.jito.wtf"
bundle_endpoint = "https://mainnet.block-engine.jito.wtf/api/v1/bundles"
tip_account = "96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5"
[monitoring]
prometheus_port = 9090
log_level = "info"
metrics_enabled = true
[performance]
max_concurrent_requests = 100
request_timeout = 30
retry_attempts = 3
Add to your Cargo.toml
:
[dependencies]
shared-infrastructure = { path = "../shared-infrastructure" }
use shared_infrastructure::{
JitoClient, MonitoringService, Config, Error,
};
// Initialize shared components
let config = Config::load("config.toml")?;
let jito_client = JitoClient::new(&config.jito)?;
let monitoring = MonitoringService::new(&config.monitoring)?;
// Use in your bot
let bundle_result = jito_client.submit_bundle(transactions).await?;
monitoring.record_transaction("arbitrage", bundle_result.profit);
Unified interface for Jito bundle operations:
use shared_infrastructure::JitoClient;
let client = JitoClient::new(&config.jito)?;
// Submit bundle
let result = client.submit_bundle(transactions).await?;
// Confirm bundle
let confirmation = client.confirm_bundle(&result.bundle_id).await?;
Comprehensive monitoring and metrics:
use shared_infrastructure::MonitoringService;
let monitoring = MonitoringService::new(&config.monitoring)?;
// Record metrics
monitoring.record_transaction("strategy_name", profit);
monitoring.record_error("error_type", error_count);
// Get metrics
let metrics = monitoring.get_metrics().await?;
Centralized configuration handling:
use shared_infrastructure::Config;
let config = Config::load("config.toml")?;
let rpc_url = config.rpc.mainnet;
let jito_config = &config.jito;
Shared data structures:
use shared_infrastructure::{
TransactionResult, BundleResult, MevOpportunity,
ArbitrageOpportunity, CopyTradeSignal
};
let opportunity = ArbitrageOpportunity {
dex_a: "raydium".to_string(),
dex_b: "orca".to_string(),
token_pair: "SOL/USDC".to_string(),
price_difference: 0.02,
estimated_profit: 100.0,
};
impl JitoClient {
pub fn new(config: &JitoConfig) -> Result<Self, Error>;
pub async fn submit_bundle(&self, transactions: Vec<Transaction>) -> Result<BundleResult, Error>;
pub async fn confirm_bundle(&self, bundle_id: &str) -> Result<ConfirmationResult, Error>;
pub async fn get_bundle_status(&self, bundle_id: &str) -> Result<BundleStatus, Error>;
}
impl MonitoringService {
pub fn new(config: &MonitoringConfig) -> Result<Self, Error>;
pub fn record_transaction(&self, strategy: &str, profit: f64);
pub fn record_error(&self, error_type: &str, count: u64);
pub async fn get_metrics(&self) -> Result<Metrics, Error>;
pub fn start_server(&self) -> Result<(), Error>;
}
impl Config {
pub fn load(path: &str) -> Result<Self, Error>;
pub fn validate(&self) -> Result<(), Error>;
pub fn get_rpc_url(&self, network: &str) -> Option<&String>;
}
- Private Key Protection: Secure key handling and storage
- Transaction Validation: Comprehensive transaction verification
- Rate Limiting: Protection against API abuse
- Error Handling: Robust error recovery mechanisms
- Optimized Operations: High-performance common functions
- Connection Pooling: Efficient resource management
- Async Operations: Non-blocking I/O operations
- Memory Efficient: Minimal memory footprint
Run the test suite:
cargo test
Run with coverage:
cargo test --features coverage
use shared_infrastructure::{
JitoClient, MonitoringService, Config
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = Config::load("config.toml")?;
let jito_client = JitoClient::new(&config.jito)?;
let monitoring = MonitoringService::new(&config.monitoring)?;
// Your bot logic here
Ok(())
}
use shared_infrastructure::{
JitoClient, MonitoringService, Config, Error
};
async fn execute_strategy(
jito_client: &JitoClient,
monitoring: &MonitoringService,
transactions: Vec<Transaction>
) -> Result<f64, Error> {
let start_time = std::time::Instant::now();
let bundle_result = jito_client.submit_bundle(transactions).await?;
let confirmation = jito_client.confirm_bundle(&bundle_result.bundle_id).await?;
let execution_time = start_time.elapsed();
monitoring.record_transaction("strategy_name", bundle_result.profit);
monitoring.record_execution_time("strategy_name", execution_time);
Ok(bundle_result.profit)
}
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
For issues and questions:
- Open an issue on GitHub
- Check the documentation
- Review the examples