Skip to main content

allenhark_slipstream/
lib.rs

1//! # allenhark-slipstream - Rust SDK for Slipstream
2//!
3//! Slipstream is a sender-agnostic Solana transaction relay system with
4//! leader-proximity-aware routing.
5//!
6//! ## Quick Start
7//!
8//! ```rust,no_run
9//! use allenhark_slipstream::{Config, SlipstreamClient};
10//!
11//! #[tokio::main]
12//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
13//!     // Create configuration
14//!     let config = Config::builder()
15//!         .api_key("sk_test_12345678")
16//!         .region("us-west")
17//!         .build()?;
18//!
19//!     // Connect to Slipstream
20//!     let client = SlipstreamClient::connect(config).await?;
21//!
22//!     // Submit a transaction
23//!     let tx_bytes = vec![/* signed transaction bytes */];
24//!     let result = client.submit_transaction(&tx_bytes).await?;
25//!     println!("Transaction signature: {:?}", result.signature);
26//!
27//!     Ok(())
28//! }
29//! ```
30//!
31//! ## Streaming
32//!
33//! The SDK supports real-time streaming of leader hints, tip instructions,
34//! and priority fees:
35//!
36//! ```rust,no_run
37//! use allenhark_slipstream::{Config, SlipstreamClient};
38//!
39//! #[tokio::main]
40//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
41//!     let config = Config::builder()
42//!         .api_key("sk_test_12345678")
43//!         .leader_hints(true)
44//!         .build()?;
45//!
46//!     let client = SlipstreamClient::connect(config).await?;
47//!
48//!     // Subscribe to leader hints
49//!     let mut hints = client.subscribe_leader_hints().await?;
50//!     while let Some(hint) = hints.recv().await {
51//!         println!("Preferred region: {} (confidence: {})",
52//!             hint.preferred_region, hint.confidence);
53//!     }
54//!
55//!     Ok(())
56//! }
57//! ```
58//!
59//! ## Protocol Fallback
60//!
61//! The SDK automatically falls back through protocols if the preferred one
62//! is unavailable:
63//!
64//! 1. **QUIC** (2s timeout) - Primary high-performance protocol
65//! 2. **gRPC** (3s timeout) - Streaming fallback
66//! 3. **WebSocket** (3s timeout) - Browser-compatible streaming
67//! 4. **HTTP** (5s timeout) - Polling fallback
68//!
69//! ## Features
70//!
71//! - **Persistent connections** - Single connection reused for all operations
72//! - **Auto-reconnect** - Automatic reconnection on connection loss
73//! - **Leader hints** - Real-time region recommendations
74//! - **Tip instructions** - Dynamic tip wallet selection
75//! - **Priority fees** - Compute unit price recommendations
76
77pub mod client;
78pub mod config;
79pub mod connection;
80pub mod discovery;
81pub mod error;
82pub mod multi_region;
83pub mod types;
84
85// Re-export main types for convenience
86pub use client::SlipstreamClient;
87pub use config::{BackoffStrategy, Config, ConfigBuilder, PriorityFeeConfig, Protocol, ProtocolTimeouts};
88pub use error::{Result, SdkError};
89pub use multi_region::MultiRegionClient;
90pub use types::{
91    AlternativeSender, Balance, BundleResult, ConnectionInfo, ConnectionState, ConnectionStatus,
92    FallbackStrategy, FreeTierUsage, Geolocation, LandingRateOptions, LandingRatePeriod,
93    LandingRateStats, LatestBlockhash, LatestSlot, LeaderHint, LeaderHintMetadata,
94    MultiRegionConfig, PerformanceMetrics, PriorityFee, PriorityFeeSpeed, RateLimitInfo,
95    RegionInfo, RegionLandingRate, RegionStatus, RegisterWebhookRequest, RetryOptions,
96    RoutingInfo, RoutingRecommendation,
97    RpcError, RpcResponse, SenderInfo, SenderLandingRate, SimulationResult, SubmitOptions, TipInstruction, TipTier,
98    TopUpInfo, TransactionBuilder, TransactionError, TransactionResult, TransactionStatus,
99    UsageEntry, UsageHistoryOptions, WebhookConfig, WebhookEvent, WebhookNotificationLevel,
100    WorkerEndpoint,
101};
102
103/// SDK version
104pub const VERSION: &str = env!("CARGO_PKG_VERSION");
105
106#[cfg(test)]
107mod tests {
108    use super::*;
109
110    #[test]
111    fn test_version() {
112        assert!(!VERSION.is_empty());
113    }
114
115    #[test]
116    fn test_config_builder_accessible() {
117        let builder = Config::builder();
118        assert!(builder.api_key("sk_test_12345678").build().is_ok());
119    }
120}