### Complete Client Setup and Event Subscription Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/configuration.md This snippet demonstrates a full client setup, including configuring connection parameters, defining supported protocols, and filtering for specific transaction and account events. It's useful for real-time monitoring of specific DEX activities on Solana. ```rust use solana_streamer_sdk::streaming::{ YellowstoneGrpc, StreamClientConfig, TransactionFilter, AccountFilter, event_parser::{DexEvent, Protocol}, event_parser::common::{EventTypeFilter, EventType}, event_parser::core::EventDispatcher, }; use solana_sdk::pubkey::Pubkey; #[tokio::main] async fn main() -> Result<(), Box> { // Setup configuration let mut config = StreamClientConfig::default(); config.enable_metrics = true; config.order_mode = solana_streamer_sdk::streaming::grpc::OrderMode::MicroBatch; config.order_timeout_ms = 100; config.micro_batch_us = 100; config.connection.connect_timeout = 30; config.connection.request_timeout = 120; // Create client let grpc = YellowstoneGrpc::new_with_config( "http://localhost:10000".to_string(), None, config, )?; // Define protocols let protocols = vec![ Protocol::PumpFun, Protocol::PumpSwap, Protocol::RaydiumCpmm, ]; // Build filters let program_ids = EventDispatcher::get_program_ids(&protocols) .into_iter() .map(|pk| pk.to_string()) .collect::>(); let tx_filter = TransactionFilter { account_include: program_ids.clone(), account_exclude: vec![], account_required: vec![], }; let account_filter = AccountFilter { account: vec![], owner: program_ids, filters: vec![], }; let event_filter = Some(EventTypeFilter::include_only(vec![ EventType::PumpFunBuy, EventType::PumpFunSell, EventType::PumpSwapBuy, EventType::PumpSwapSell, ])); // Subscribe and process events grpc.subscribe_events_immediate( protocols, None, vec![tx_filter], vec![account_filter], event_filter, None, |event: DexEvent| { println!("Event: {:?}", event.metadata().event_type); }, ).await?; Ok(()) } ``` -------------------------------- ### Complete Example Migration: v0.5.x Source: https://github.com/0xfnzero/solana-streamer/blob/main/MIGRATION.md A complete example demonstrating the usage of the Solana Streamer SDK with the older v0.5.x event system, including callback and event matching. ```rust use solana_streamer_sdk::{ match_event, streaming::{ event_parser::{ UnifiedEvent, protocols::{ pumpfun::{PumpFunTradeEvent, PumpFunCreateTokenEvent}, raydium_cpmm::RaydiumCpmmSwapEvent, }, }, YellowstoneGrpc, }, }; #[tokio::main] async fn main() -> Result<(), Box> { let grpc = YellowstoneGrpc::new( "grpc-endpoint".to_string(), Some("api-key".to_string()), )?; let callback = |event: Box| { println!( "Event type: {:?}, Signature: {}", event.event_type(), event.signature() ); match_event!(event, { PumpFunTradeEvent => |e: PumpFunTradeEvent| { println!("PumpFun trade: {} SOL", e.sol_amount); }, PumpFunCreateTokenEvent => |e: PumpFunCreateTokenEvent| { println!("New token: {}", e.name); }, RaydiumCpmmSwapEvent => |e: RaydiumCpmmSwapEvent| { println!("Raydium swap"); }, }); }; grpc.subscribe_events( protocols, event_filter, tx_filter, account_filter, callback, ).await?; Ok(()) } ``` -------------------------------- ### Complete Event Filtering Example in Rust Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/event-filtering.md This example demonstrates a comprehensive filtering setup for Solana Streamer. It includes protocol selection, gRPC transaction filtering by program IDs, account filtering by owner, and local event type filtering for specific buy/sell events. Use this when you need to subscribe to and process a specific subset of DEX events. ```rust use solana_streamer_sdk::streaming::{ YellowstoneGrpc, TransactionFilter, AccountFilter, event_parser::{DexEvent, Protocol}, event_parser::common::{EventTypeFilter, EventType}, event_parser::core::EventDispatcher, }; #[tokio::main] async fn main() -> Result<(), Box> { // Create client let grpc = YellowstoneGrpc::new( "http://localhost:10000".to_string(), None, )?; // Step 1: Protocol selection let protocols = vec![ Protocol::PumpFun, Protocol::PumpSwap, ]; // Step 2: gRPC transaction filtering let program_ids = EventDispatcher::get_program_ids(&protocols) .into_iter() .map(|pk| pk.to_string()) .collect::>(); let tx_filter = TransactionFilter { account_include: program_ids.clone(), account_exclude: vec!["SpamProgram...".to_string()], account_required: vec![], }; // Step 3: gRPC account filtering let account_filter = AccountFilter { account: vec![], owner: program_ids, filters: vec![], }; // Step 4: Local event type filtering let event_filter = Some(EventTypeFilter::include_only(vec![ EventType::PumpFunBuy, EventType::PumpFunSell, EventType::PumpSwapBuy, EventType::PumpSwapSell, ])); // Subscribe with all filters grpc.subscribe_events_immediate( protocols, None, vec![tx_filter], vec![account_filter], event_filter, None, |event: DexEvent| { match event { DexEvent::PumpFunBuyEvent(e) => { println!("PumpFun Buy: {:?}", e); } DexEvent::PumpSwapBuyEvent(e) => { println!("PumpSwap Buy: {:?}", e); } _ => {} } }, ).await?; Ok(()) } ``` -------------------------------- ### Get Configuration Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/main-entry-points.md Retrieve current client configuration. Returns the current client configuration object. ```APIDOC ## Get Configuration ### Description Retrieve current client configuration. ### Method `get_config` ### Endpoint None explicitly provided, assumed to be a method call on the client instance. ### Parameters None ### Response #### Success Response (200) - **StreamClientConfig** (&StreamClientConfig) - The current client configuration. #### Response Example None explicitly provided, returns a reference to `StreamClientConfig`. ``` -------------------------------- ### YellowstoneGrpc Configuration and Metrics Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/modules-and-exports.md Functions to get and update client configuration, and manage performance metrics. ```rust pub fn get_config(&self) -> &StreamClientConfig pub fn update_config(&mut self, config: StreamClientConfig) pub fn get_metrics(&self) -> PerformanceMetrics pub fn print_metrics(&self) pub fn set_enable_metrics(&mut self, enabled: bool) ``` -------------------------------- ### Example AccountFilter Usage Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/types.md Demonstrates how to create an AccountFilter to monitor accounts owned by a specific program. This filter is used with the Yellowstone gRPC stream. ```rust let filter = AccountFilter { account: vec![], owner: vec![ "PumpFunProgram111111111111111111111111111".to_string(), ], filters: vec![], }; ``` -------------------------------- ### Enable Metrics and Get Metrics Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/configuration.md This snippet shows how to enable metrics during client initialization and later retrieve them. Ensure the client is created with the desired configuration. ```rust let mut config = StreamClientConfig::default(); config.enable_metrics = true; let client = YellowstoneGrpc::new_with_config(endpoint, token, config)?; // Later: retrieve metrics let metrics = client.get_metrics(); println!("Event count: {}", metrics.total_events); println!("Avg latency: {}us", metrics.avg_latency_us); ``` -------------------------------- ### Example TransactionFilter Usage Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/types.md Demonstrates how to create a TransactionFilter to include specific accounts. This filter is used with the Yellowstone gRPC stream. ```rust let filter = TransactionFilter { account_include: vec![ "PumpFunProgram111111111111111111111111111".to_string(), ], account_exclude: vec![], account_required: vec![], }; ``` -------------------------------- ### Get Solana Streamer Configuration Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/main-entry-points.md Retrieve the current configuration settings for the Solana Streamer client. ```rust pub fn get_config(&self) -> &StreamClientConfig ``` -------------------------------- ### Building Account Filters Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/configuration.md Create account filters to monitor state changes for specific accounts or owners. This example monitors accounts owned by the previously determined program IDs. ```rust let account_filter = AccountFilter { account: vec![], owner: program_ids.clone(), filters: vec![], }; ``` -------------------------------- ### Update Callback Signature: v1.x.x Source: https://github.com/0xfnzero/solana-streamer/blob/main/MIGRATION.md Example of a callback function signature using the new enum-based event system. ```rust use solana_streamer_sdk::streaming::event_parser::DexEvent; let callback = |event: DexEvent| { println!("Received event: {:?}", event); }; ``` -------------------------------- ### Subscribe to Solana Streamer Events (v1.x.x) Source: https://github.com/0xfnzero/solana-streamer/blob/main/MIGRATION.md Example of subscribing to DEX events using YellowstoneGrpc in v1.x.x. Ensure all necessary filters and a callback function are provided. ```rust use solana_streamer_sdk::streaming::{ event_parser:: DexEvent, protocols::{ pumpfun::{PumpFunTradeEvent, PumpFunCreateTokenEvent}, raydium_cpmm::RaydiumCpmmSwapEvent, }, }, YellowstoneGrpc, }; #[tokio::main] async fn main() -> Result<(), Box> { let grpc = YellowstoneGrpc::new( "grpc-endpoint".to_string(), Some("api-key".to_string()), )?; let callback = |event: DexEvent| { println!( "Event type: {:?}, Signature: {}", event.metadata().event_type, event.metadata().signature ); match event { DexEvent::PumpFunTradeEvent(e) => { println!("PumpFun trade: {} SOL", e.sol_amount); } DexEvent::PumpFunCreateTokenEvent(e) => { println!("New token: {}", e.name); } DexEvent::RaydiumCpmmSwapEvent(e) => { println!("Raydium swap"); } _ => {} } }; grpc.subscribe_events( protocols, event_filter, tx_filter, account_filter, callback, ).await?; Ok(()) } ``` -------------------------------- ### Update Callback Signature: v0.5.x Source: https://github.com/0xfnzero/solana-streamer/blob/main/MIGRATION.md Example of a callback function signature using the older trait-based event system. ```rust use solana_streamer_sdk::streaming::event_parser::UnifiedEvent; let callback = |event: Box| { println!("Received event: {:?}", event); }; ``` -------------------------------- ### Subscribe to Minimal gRPC DEX Events Source: https://github.com/0xfnzero/solana-streamer/blob/main/README.md Subscribe to specific DEX events using filters for protocols, accounts, and event types. This example demonstrates filtering for various Pump.fun and Raydium events. ```rust use solana_streamer_sdk::streaming::{ event_parser::{ common::{filter::EventTypeFilter, EventType}, core::EventDispatcher, DexEvent, Protocol, }, yellowstone_grpc::{AccountFilter, TransactionFilter}, YellowstoneGrpc, }; let grpc = YellowstoneGrpc::new(endpoint, token)?; let protocols = vec![ Protocol::PumpFun, Protocol::PumpFees, Protocol::PumpSwap, Protocol::RaydiumLaunchpad, Protocol::RaydiumCpmm, Protocol::RaydiumClmm, Protocol::RaydiumAmmV4, Protocol::OrcaWhirlpool, Protocol::MeteoraPools, Protocol::MeteoraDammV2, Protocol::MeteoraDlmm, ]; let program_ids = EventDispatcher::get_program_ids(&protocols) .into_iter() .map(|pubkey| pubkey.to_string()) .collect::>(); let transaction_filter = TransactionFilter { account_include: program_ids.clone(), account_exclude: vec![], account_required: vec![], }; let account_filter = AccountFilter { account: vec![], owner: program_ids, filters: vec![] }; let event_type_filter = Some(EventTypeFilter::include_only(vec![ EventType::PumpFunBuy, EventType::PumpSwapBuy, EventType::BonkBuyExactIn, EventType::RaydiumCpmmSwapBaseInput, EventType::MeteoraDlmmSwap, ])); grpc.subscribe_events_immediate( protocols, None, vec![transaction_filter], vec![account_filter], event_type_filter, None, |event: DexEvent| { println!("{:?}", event.metadata().event_type); }, ) .await?; ``` -------------------------------- ### Combined Transaction Filtering Example Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/event-filtering.md Combines include, exclude, and required account filters for comprehensive transaction filtering. Follows a specific evaluation order: exclude, required, then include. ```rust let tx_filter = TransactionFilter { account_include: vec![ "PumpFun...".to_string(), "PumpSwap...".to_string(), ], account_exclude: vec![ "Spam...".to_string(), ], account_required: vec![ "MyBot...".to_string(), ], }; // Evaluation Order: // 1. Check `account_exclude`: if ANY account present, reject // 2. Check `account_required`: if ANY missing, reject // 3. Check `account_include`: if ANY present, accept ``` -------------------------------- ### Account Include Filter Example Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/event-filtering.md Subscribe to transactions involving any of the specified accounts. A transaction passes if ANY account in `account_include` appears in its accounts list. ```rust use solana_streamer_sdk::streaming::TransactionFilter; let tx_filter = TransactionFilter { account_include: vec![ "PumpFun2eDs3...".to_string(), "PumpSwap1...".to_string(), ], account_exclude: vec![], account_required: vec![], }; ``` -------------------------------- ### Parse Transactions with EventParser (v1.x.x) Source: https://github.com/0xfnzero/solana-streamer/blob/main/MIGRATION.md Example of parsing transactions using the new static method API in v1.x.x. The EventParser is now stateless, simplifying usage. ```rust EventParser::parse_encoded_confirmed_transaction_with_status_meta( &protocols, event_filter.as_ref(), signature, transaction, Arc::new(|event: &DexEvent| { println!("{:?}", event); }), ).await?; ``` -------------------------------- ### Match DexEvent Variants Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/types.md This example demonstrates how to match different DexEvent variants to access their specific data and metadata. It shows handling PumpFunBuyEvent and RaydiumClmmSwapEvent, with a fallback for other event types. ```rust match event { DexEvent::PumpFunBuyEvent(e) => { println!("Buy: {:?}", e.metadata()); } DexEvent::RaydiumClmmSwapEvent(e) => { println!("CLMM Swap: {:?}", e.metadata()); } _ => {} } ``` -------------------------------- ### Parse Transactions with EventParser (v0.5.x) Source: https://github.com/0xfnzero/solana-streamer/blob/main/MIGRATION.md Example of parsing transactions using the older EventParser API in v0.5.x, which required an instantiated parser object. ```rust let parser = Arc::new(EventParser::new(protocols, event_filter)); parser.parse_encoded_confirmed_transaction_with_status_meta( signature, transaction, Arc::new(|event: &Box| { println!("{:?}", event); }), ).await?; ``` -------------------------------- ### Create and Customize StreamClient Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/configuration.md Demonstrates how to create a new StreamClient using default settings and how to customize the configuration for specific needs, such as enabling metrics or adjusting timeouts. ```rust use solana_streamer_sdk::streaming::{ StreamClientConfig, YellowstoneGrpc, }; // Default configuration let client = YellowstoneGrpc::new(endpoint, token)?; // Custom configuration let mut config = StreamClientConfig::default(); config.enable_metrics = true; config.connection.connect_timeout = 30; config.connection.request_timeout = 120; config.order_mode = OrderMode::MicroBatch; config.order_timeout_ms = 100; config.micro_batch_us = 100; let client = YellowstoneGrpc::new_with_config(endpoint, token, config)?; ``` -------------------------------- ### Initialize YellowstoneGrpc Client with Custom Configuration Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/main-entry-points.md Create a YellowstoneGrpc client with custom configuration for performance tuning, including settings for connection, ordering, and metrics. Use this when default settings are not optimal. ```rust use solana_streamer_sdk::streaming::{YellowstoneGrpc, StreamClientConfig}; let mut config = StreamClientConfig::default(); config.enable_metrics = true; config.order_mode = OrderMode::MicroBatch; config.micro_batch_us = 100; let grpc = YellowstoneGrpc::new_with_config(endpoint, token, config)?; ``` -------------------------------- ### YellowstoneGrpc Client Initialization and Configuration Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/modules-and-exports.md Provides methods for creating and configuring the YellowstoneGrpc client. ```rust impl YellowstoneGrpc { pub fn new(endpoint: String, x_token: Option) -> AnyResult pub fn new_with_config(endpoint: String, x_token: Option, config: StreamClientConfig) -> AnyResult ``` -------------------------------- ### Customizing ConnectionConfig Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/configuration.md Demonstrates how to customize connection and request timeouts, and the maximum message size for unstable networks or high-volume subscriptions. ```rust let mut config = StreamClientConfig::default(); // Increase connection timeout for unstable networks config.connection.connect_timeout = 30; // Increase request timeout for high-volume subscriptions config.connection.request_timeout = 120; // Increase max message size if receiving large batches config.connection.max_decoding_message_size = 50 * 1024 * 1024; // 50 MB ``` -------------------------------- ### Get Program IDs Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/main-entry-points.md Retrieves all program IDs for a given list of protocols, which is useful for constructing gRPC filters. ```APIDOC ## Get Program IDs ### Description Retrieve all program IDs for a list of protocols. Useful for constructing gRPC filters. ### Method Rust Function ### Signature `pub fn get_program_ids(protocols: &[Protocol]) -> Vec` ### Parameters #### Function Parameters - **protocols** (&[Protocol]) - List of protocols ### Returns `Vec` - Deduplicated list of program IDs ### Example ```rust let program_ids = EventDispatcher::get_program_ids(&[ Protocol::PumpFun, Protocol::PumpSwap, Protocol::RaydiumCpmm, ]); ``` ``` -------------------------------- ### Configuring Order Modes Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/configuration.md Shows how to configure different transaction event output ordering strategies, including default, ordered, streaming ordered, and micro-batch modes. ```rust use solana_streamer_sdk::streaming::{ StreamClientConfig, grpc::types::OrderMode, }; let mut config = StreamClientConfig::default(); // Unordered (default) config.order_mode = OrderMode::Unordered; // Ordered with 100ms slot flush timeout config.order_mode = OrderMode::Ordered; config.order_timeout_ms = 100; // StreamingOrdered with 100ms timeout config.order_mode = OrderMode::StreamingOrdered; config.order_timeout_ms = 100; // MicroBatch with 100 microsecond window config.order_mode = OrderMode::MicroBatch; config.micro_batch_us = 100; ``` -------------------------------- ### Get Program IDs for Single Protocol Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/event-filtering.md Monitors only PumpFun trades by filtering events from a single specified protocol. ```rust use solana_streamer_sdk::streaming::{ YellowstoneGrpc, event_parser::Protocol, event_parser::core::EventDispatcher, }; let protocols = vec![Protocol::PumpFun]; let program_ids = EventDispatcher::get_program_ids(&protocols) .into_iter() .map(|pk| pk.to_string()) .collect::>(); ``` -------------------------------- ### Initialize YellowstoneGrpc Client Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/main-entry-points.md Create a new YellowstoneGrpc client with a specified endpoint and an optional authentication token. This is the basic constructor for establishing a connection. ```rust use solana_streamer_sdk::streaming::YellowstoneGrpc; let grpc = YellowstoneGrpc::new( "http://localhost:10000".to_string(), None )?; ``` -------------------------------- ### Import Complete Subscription Components in Rust Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/modules-and-exports.md Import all necessary components for a complete subscription, including YellowstoneGrpc, event parsers, and configuration types. ```rust use solana_streamer_sdk::streaming:: YellowstoneGrpc, event_parser::{DexEvent, Protocol}, event_parser::common::{EventTypeFilter, EventType}, event_parser::core::EventDispatcher, TransactionFilter, AccountFilter, StreamClientConfig, ; ``` -------------------------------- ### Get Metrics Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/main-entry-points.md Retrieve current performance metrics. Returns aggregated metrics across all events processed in the active subscription. ```APIDOC ## Get Metrics ### Description Retrieve current performance metrics. Returns aggregated metrics across all events processed in the active subscription. ### Method `get_metrics` ### Endpoint None explicitly provided, assumed to be a method call on the client instance. ### Parameters None ### Response #### Success Response (200) - **PerformanceMetrics** (PerformanceMetrics) - Object containing event count, latency, and throughput data. #### Response Example None explicitly provided, returns a `PerformanceMetrics` object. ``` -------------------------------- ### Get Program IDs for Multiple Protocols Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/event-filtering.md Monitors multiple DEX platforms by filtering events from a list of specified protocols. ```rust let protocols = vec![ Protocol::PumpFun, Protocol::PumpSwap, Protocol::RaydiumCpmm, Protocol::RaydiumClmm, Protocol::OrcaWhirlpool, Protocol::MeteoraDammV2, ]; let program_ids = EventDispatcher::get_program_ids(&protocols) .into_iter() .map(|pk| pk.to_string()) .collect::>(); ``` -------------------------------- ### Account Required Filter Example Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/event-filtering.md Ensure transactions involve ALL of the specified accounts. A transaction passes only if ALL accounts in `account_required` appear in its accounts list. ```rust let tx_filter = TransactionFilter { account_include: vec!["Program1...".to_string()], account_exclude: vec![], account_required: vec![ "MustBeHere1...".to_string(), "MustBeHere2...".to_string(), ], }; ``` -------------------------------- ### Account Exclude Filter Example Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/event-filtering.md Skip transactions involving specific accounts. A transaction is rejected if ANY account in `account_exclude` appears in its accounts list. ```rust let tx_filter = TransactionFilter { account_include: vec!["Program1...".to_string()], account_exclude: vec![ "SkipThisAccount...".to_string(), ], account_required: vec![], }; ``` -------------------------------- ### Using Match for Event Handling (Correct Pattern) Source: https://github.com/0xfnzero/solana-streamer/blob/main/MIGRATION.md Illustrates the correct pattern for matching DexEvents in v1.x.x, replacing the deprecated `match_event!` macro. ```rust match event { DexEvent::PumpFunTradeEvent(e) => { /* ... */ }, _ => {} } ``` -------------------------------- ### Deterministic Performance Mode Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/INDEX.md Configure the streamer for deterministic ordering, recommended for reproducibility. Includes order timeouts and enabled metrics. ```text OrderMode::StreamingOrdered Order timeout: 200ms Metrics: enabled ``` -------------------------------- ### Get Program IDs for Protocols Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/main-entry-points.md Retrieves a deduplicated list of program IDs for a given list of protocols. Useful for building gRPC filters. ```rust pub fn get_program_ids(protocols: &[Protocol]) -> Vec ``` ```rust let program_ids = EventDispatcher::get_program_ids(&[ Protocol::PumpFun, Protocol::PumpSwap, Protocol::RaydiumCpmm, ]); ``` -------------------------------- ### Customize YellowstoneGrpc Client Configuration Source: https://github.com/0xfnzero/solana-streamer/blob/main/README.md Use default configuration or create a custom configuration object to enable metrics, set timeouts, and specify order modes for the YellowstoneGrpc client. ```rust use solana_streamer_sdk::streaming::{ grpc::{ClientConfig, OrderMode}, YellowstoneGrpc, }; // Use default configuration let grpc = YellowstoneGrpc::new(endpoint, token)?; // Or create custom configuration let mut config = ClientConfig::default(); config.enable_metrics = true; // Enable performance monitoring config.connection.connect_timeout = 30; // 30 seconds config.connection.request_timeout = 120; // 120 seconds config.order_mode = OrderMode::MicroBatch; // Unordered / Ordered / StreamingOrdered / MicroBatch config.order_timeout_ms = 100; config.micro_batch_us = 100; let grpc = YellowstoneGrpc::new_with_config(endpoint, token, config)?; ``` -------------------------------- ### Handle Subscription Errors Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/README.md Shows how to handle potential errors that may occur during the gRPC subscription process. ```rust match grpc.subscribe_events_immediate(...).await { Ok(()) => { // Subscription active } Err(e) => { eprintln!("Subscription failed: {}", e); } } ``` -------------------------------- ### Filter Specific Event Types (Exclude Only) Source: https://github.com/0xfnzero/solana-streamer/blob/main/README.md Use `EventTypeFilter::exclude_only` to specify a list of event types to exclude. This example excludes BlockMeta events while receiving all others. ```rust use solana_streamer_sdk::streaming::event_parser::common::{filter::EventTypeFilter, EventType}; // Exclude noisy events while keeping everything else let event_type_filter = Some(EventTypeFilter::exclude_only(vec![EventType::BlockMeta])); ``` -------------------------------- ### Import SDK Bridge for Advanced Interoperability in Rust Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/modules-and-exports.md Import the SDK bridge module for adapting raw events in advanced interoperability scenarios. ```rust use solana_streamer_sdk::sdk_bridge; let adapted = sdk_bridge::adapt_event(raw_event, ...)?; ``` -------------------------------- ### Configure for High Throughput Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/README.md Enable micro-batching and metrics for increased throughput. Adjust micro-batch duration as needed. ```rust let mut config = StreamClientConfig::default(); config.order_mode = OrderMode::MicroBatch; config.micro_batch_us = 500; config.enable_metrics = true; ``` -------------------------------- ### Filter Specific Event Types (Include Only) Source: https://github.com/0xfnzero/solana-streamer/blob/main/README.md Use `EventTypeFilter::include_only` to specify a list of event types to receive. This example includes only PumpSwap buy and sell events. ```rust use solana_streamer_sdk::streaming::event_parser::common::{filter::EventTypeFilter, EventType}; // Filter specific event types - only receive PumpSwap buy/sell events let event_type_filter = Some(EventTypeFilter::include_only(vec![ EventType::PumpSwapBuy, EventType::PumpSwapSell, ])); ``` -------------------------------- ### Get Program IDs for Protocol Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/types.md Retrieves the program ID(s) associated with a specific Solana DEX protocol. This method is useful for interacting with the protocol's smart contracts. ```rust let protocol = Protocol::PumpFun; let program_ids = protocol.get_program_id(); ``` -------------------------------- ### YellowstoneGrpc Client Constructor Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/main-entry-points.md Initializes a new Yellowstone gRPC client with a specified endpoint and an optional authentication token. This is the primary way to establish a connection for streaming Solana DEX events. ```APIDOC ## YellowstoneGrpc Client Constructor ### Description Creates a gRPC client instance for subscribing to Yellowstone streaming events. It requires a gRPC endpoint URL and optionally accepts an authentication token. ### Method `new` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Constructor Signature ```rust pub fn new(endpoint: String, x_token: Option) -> AnyResult ``` ### Parameters - **endpoint** (String) - Required - gRPC endpoint URL (e.g., `"http://localhost:10000"`) - **x_token** (Option) - Optional - Authentication token for the endpoint ### Returns `AnyResult` - Result containing initialized client or error ### Example ```rust use solana_streamer_sdk::streaming::YellowstoneGrpc; let grpc = YellowstoneGrpc::new( "http://localhost:10000".to_string(), None )?; ``` ``` -------------------------------- ### Retrieve Client Metrics Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/configuration.md Fetch and display client metrics such as average latency and events per second. Regular monitoring of these metrics is crucial for detecting performance degradation. ```rust let metrics = client.get_metrics(); eprintln!("Latency: {}us, Throughput: {}/s", metrics.avg_latency_us, metrics.events_per_second); ``` -------------------------------- ### YellowstoneGrpc Client Constructor with Custom Config Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/main-entry-points.md Initializes a Yellowstone gRPC client with a specified endpoint, optional authentication token, and custom configuration for performance tuning. ```APIDOC ## YellowstoneGrpc Client Constructor with Custom Config ### Description Creates a gRPC client instance with custom configuration, allowing for performance tuning of connection, ordering, and metrics. ### Method `new_with_config` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Constructor Signature ```rust pub fn new_with_config( endpoint: String, x_token: Option, config: StreamClientConfig, ) -> AnyResult ``` ### Parameters - **endpoint** (String) - Required - gRPC endpoint URL - **x_token** (Option) - Optional - Authentication token - **config** (StreamClientConfig) - Required - Custom client configuration with connection, ordering, and metrics settings ### Returns `AnyResult` ### Example ```rust use solana_streamer_sdk::streaming::{YellowstoneGrpc, StreamClientConfig}; let mut config = StreamClientConfig::default(); config.enable_metrics = true; config.order_mode = OrderMode::MicroBatch; config.micro_batch_us = 100; let grpc = YellowstoneGrpc::new_with_config(endpoint, token, config)?; ``` ``` -------------------------------- ### Get Solana Streamer Performance Metrics Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/main-entry-points.md Retrieve current performance metrics, including event count, latency, and throughput, aggregated across all events processed by the active subscription. ```rust pub fn get_metrics(&self) -> PerformanceMetrics ``` -------------------------------- ### EventMetadata::new Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/types.md Constructs a new EventMetadata instance with the provided details. This is the primary way to create metadata for new events. ```APIDOC ## EventMetadata::new ### Description Construct new metadata. ### Signature ```rust pub fn new( signature: Signature, slot: u64, block_time: i64, block_time_ms: i64, protocol: ProtocolType, event_type: EventType, program_id: Pubkey, outer_index: i64, inner_index: Option, recv_us: i64, tx_index: Option, recent_blockhash: Option, ) -> Self ``` ``` -------------------------------- ### Building Transaction Filters Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/configuration.md Construct transaction filters to specify which protocols and program IDs to monitor. This requires importing TransactionFilter, AccountFilter, and Protocol. ```rust use solana_streamer_sdk::streaming::{TransactionFilter, AccountFilter}; use solana_streamer_sdk::streaming::event_parser::core::EventDispatcher; use solana_streamer_sdk::streaming::event_parser::Protocol; let protocols = vec![ Protocol::PumpFun, Protocol::PumpSwap, Protocol::RaydiumCpmm, ]; let program_ids = EventDispatcher::get_program_ids(&protocols) .into_iter() .map(|pk| pk.to_string()) .collect::>(); let tx_filter = TransactionFilter { account_include: program_ids.clone(), account_exclude: vec![], account_required: vec![], }; ``` -------------------------------- ### Configure Solana Streamer SDK with Zero-Copy Parser Source: https://github.com/0xfnzero/solana-streamer/blob/main/README.md Configure the Solana Streamer SDK to use the zero-copy parser backend for latency-sensitive bots. This disables default features. ```toml # Zero-copy parser backend for latency-sensitive bots solana-streamer-sdk = { version = "1.5.15", default-features = false, features = ["sdk-parse-zero-copy"] } ``` -------------------------------- ### Clone Solana Streamer Project Source: https://github.com/0xfnzero/solana-streamer/blob/main/README.md Clone the Solana Streamer project into your project's root directory. ```bash cd your_project_root_directory git clone https://github.com/0xfnzero/solana-streamer ``` -------------------------------- ### Handling All Event Variants (Correct Pattern) Source: https://github.com/0xfnzero/solana-streamer/blob/main/MIGRATION.md Demonstrates the correct way to use a match statement to handle all possible DexEvent variants, preventing runtime errors. ```rust match event { DexEvent::PumpFunTradeEvent(e) => { /* ... */ }, _ => {} // Handle or ignore other events } ``` -------------------------------- ### Default StreamClientConfig Implementation Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/configuration.md Provides the default configuration for the StreamClientConfig, setting initial values for connection, metrics, and ordering parameters. ```rust impl Default for StreamClientConfig { fn default() -> Self { Self { connection: ConnectionConfig::default(), enable_metrics: false, order_mode: OrderMode::Unordered, order_timeout_ms: 100, micro_batch_us: 100, } } } ``` -------------------------------- ### Update Client Configuration Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/configuration.md Modify client configuration settings like enabling metrics after the client has been initialized. This allows for dynamic adjustments without needing to recreate the client. ```rust let mut client = YellowstoneGrpc::new(endpoint, token)?; // Change configuration let mut new_config = StreamClientConfig::default(); new_config.enable_metrics = true; client.update_config(new_config); // Enable/disable metrics client.set_enable_metrics(true); ``` -------------------------------- ### Add Solana Streamer Dependency from Crates.io Source: https://github.com/0xfnzero/solana-streamer/blob/main/README.md Add the Solana Streamer SDK from crates.io as a dependency in your Cargo.toml file. ```toml # Add to your Cargo.toml solana-streamer-sdk = "1.5.15" ``` -------------------------------- ### Solana Streamer SDK Core Imports Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/README.md Imports for streaming clients, event types, filtering mechanisms, and configuration options within the Solana Streamer SDK. ```rust use solana_streamer_sdk::streaming::{ // Clients YellowstoneGrpc, ShredStreamGrpc, // Types TransactionFilter, AccountFilter, // Events & Filtering event_parser::{DexEvent, Protocol}, event_parser::common::{EventTypeFilter, EventType, EventMetadata}, event_parser::core::EventDispatcher, // Configuration StreamClientConfig, OrderMode, }; ``` -------------------------------- ### Subscribe to PumpFun Events with YellowstoneGrpc Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/README.md Connects to a gRPC stream and subscribes to PumpFun buy and sell events. Requires a running Solana RPC endpoint and the `tokio` runtime. ```rust use solana_streamer_sdk::streaming::{ YellowstoneGrpc, event_parser::{DexEvent, Protocol}, event_parser::common::{EventTypeFilter, EventType}, event_parser::core::EventDispatcher, TransactionFilter, AccountFilter, }; #[tokio::main] async fn main() -> Result<(), Box> { let grpc = YellowstoneGrpc::new( "http://localhost:10000".to_string(), None, )?; let protocols = vec![Protocol::PumpFun]; let program_ids = EventDispatcher::get_program_ids(&protocols) .into_iter() .map(|pk| pk.to_string()) .collect::>(); let tx_filter = TransactionFilter { account_include: program_ids.clone(), account_exclude: vec![], account_required: vec![], }; let account_filter = AccountFilter { account: vec![], owner: program_ids, filters: vec![], }; let event_filter = Some(EventTypeFilter::include_only(vec![ EventType::PumpFunBuy, EventType::PumpFunSell, ])); grpc.subscribe_events_immediate( protocols, None, vec![tx_filter], vec![account_filter], event_filter, None, |event: DexEvent| { println!("Event: {:?}", event.metadata().event_type); }, ).await?; Ok(()) } ``` -------------------------------- ### Print Metrics to Stdout Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/configuration.md Conveniently prints the current metrics to standard output. This is useful for quick monitoring without manually accessing the metrics structure. ```rust client.print_metrics(); ``` -------------------------------- ### Update Event Matching: v0.5.x Source: https://github.com/0xfnzero/solana-streamer/blob/main/MIGRATION.md Demonstrates event matching using the `match_event!` macro in the older version. ```rust use solana_streamer_sdk::match_event; match_event!(event, { PumpFunTradeEvent => |e: PumpFunTradeEvent| { println!("PumpFun trade: {:?}", e); }, RaydiumCpmmSwapEvent => |e: RaydiumCpmmSwapEvent| { println!("Raydium swap: {:?}", e); }, }); ``` -------------------------------- ### Low-Latency Configuration Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/configuration.md Use this configuration for time-sensitive applications like arbitrage bots or MEV detection. It disables metrics and uses unordered delivery for the fastest possible data. ```rust let mut config = StreamClientConfig::default(); config.enable_metrics = false; // Disable metrics overhead config.order_mode = OrderMode::Unordered; // Fastest delivery config.connection.connect_timeout = 10; config.connection.request_timeout = 60; ``` -------------------------------- ### ConnectionConfig Structure Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/types.md Configures gRPC connection tuning parameters. Adjust timeouts and message size limits for optimal performance. ```rust #[derive(Debug, Clone)] pub struct ConnectionConfig { pub connect_timeout: u64, pub request_timeout: u64, pub max_decoding_message_size: usize, } ``` -------------------------------- ### Configure Solana Streamer SDK with Default Parser Source: https://github.com/0xfnzero/solana-streamer/blob/main/README.md Configure the Solana Streamer SDK to use the default sol-parser-sdk parse-borsh backend. ```toml # Default: sol-parser-sdk parse-borsh backend solana-streamer-sdk = "1.5.15" ``` -------------------------------- ### Import Parser SDK for Direct Access in Rust Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/modules-and-exports.md Import the parser SDK for direct access to parsing functions, allowing the use of raw sol-parser-sdk types. ```rust use solana_streamer_sdk::parser_sdk; // Use raw sol-parser-sdk types let events = parser_sdk::parse_rpc_transaction(...)?; ``` -------------------------------- ### EventMetadata Constructor Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/types.md Constructs a new EventMetadata instance with essential event details. Ensure all required parameters are provided upon creation. ```rust pub fn new( signature: Signature, slot: u64, block_time: i64, block_time_ms: i64, protocol: ProtocolType, event_type: EventType, program_id: Pubkey, outer_index: i64, inner_index: Option, recv_us: i64, tx_index: Option, recent_blockhash: Option, ) -> Self ``` -------------------------------- ### Configure for Low Latency Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/README.md Disable metrics and use unordered processing for minimal latency. ```rust let mut config = StreamClientConfig::default(); config.enable_metrics = false; config.order_mode = OrderMode::Unordered; ``` -------------------------------- ### Subscribe to DEX Events Immediately Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/main-entry-points.md Subscribe to DEX events from specified protocols with flexible filtering options for transactions, accounts, and event types. This method is suitable for immediate, non-complex subscription scenarios. ```rust use solana_streamer_sdk::streaming::{ event_parser::{DexEvent, Protocol}, event_parser::common::{EventTypeFilter, EventType}, YellowstoneGrpc, TransactionFilter, AccountFilter, }; let grpc = YellowstoneGrpc::new(endpoint, token)?; let protocols = vec![Protocol::PumpFun, Protocol::PumpSwap]; let program_ids = EventDispatcher::get_program_ids(&protocols) .into_iter() .map(|pk| pk.to_string()) .collect::>(); let tx_filter = TransactionFilter { account_include: program_ids.clone(), account_exclude: vec![], account_required: vec![], }; let account_filter = AccountFilter { account: vec![], owner: program_ids, filters: vec![], }; let event_filter = Some(EventTypeFilter::include_only(vec![ EventType::PumpFunBuy, EventType::PumpSwapBuy, ])); grpc.subscribe_events_immediate( protocols, None, vec![tx_filter], vec![account_filter], event_filter, None, |event: DexEvent| { println!("Event: {:?}", event.metadata().event_type); }, ).await?; ``` -------------------------------- ### Enable Metrics in Configuration Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/configuration.md Set `enable_metrics` to `true` within the configuration object. This is recommended during development to help identify performance bottlenecks. ```rust config.enable_metrics = true; ``` -------------------------------- ### Accessing Event Metadata (Correct Pattern) Source: https://github.com/0xfnzero/solana-streamer/blob/main/MIGRATION.md Shows the correct way to access event metadata in v1.x.x, using the `.metadata()` method followed by the desired field. ```rust let sig = event.metadata().signature; ``` -------------------------------- ### Match All Swaps Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/protocol-events.md Use this pattern to match and handle all types of swap events from various DEX protocols. ```rust match event { DexEvent::PumpFunBuyEvent(_) | DexEvent::PumpFunSellEvent(_) | DexEvent::PumpSwapBuyEvent(_) | DexEvent::PumpSwapSellEvent(_) | DexEvent::RaydiumClmmSwapEvent(_) | DexEvent::RaydiumCpmmSwapEvent(_) => { // Handle all swaps } _ => {} } ``` -------------------------------- ### Add Local Solana Streamer Dependency Source: https://github.com/0xfnzero/solana-streamer/blob/main/README.md Add the local Solana Streamer SDK as a dependency in your Cargo.toml file. ```toml # Add to your Cargo.toml solana-streamer-sdk = { path = "./solana-streamer", version = "1.5.15" } ``` -------------------------------- ### Create Filter with Include and Exclude Lists Source: https://github.com/0xfnzero/solana-streamer/blob/main/_autodocs/main-entry-points.md Use `include_exclude` to create a filter that combines both inclusion and exclusion criteria. The exclusion list is processed first, followed by the inclusion list. ```rust pub fn include_exclude( include: impl Into>, exclude: impl Into>, ) -> Self ```