Skip to main content

jito_bundle/config/
network.rs

1use crate::constants::{JITO_BLOCK_ENGINE_URL, JITO_MAINNET_ENDPOINTS, JITO_TIPS_FLOOR_URL};
2
3/// Supported block-engine network configurations.
4#[derive(Debug, Clone)]
5pub enum Network {
6    /// Use default Jito mainnet endpoints.
7    Mainnet,
8    /// Use custom block-engine and tip-floor URLs.
9    Custom {
10        /// Custom block-engine base URL.
11        block_engine_url: String,
12        /// Custom tip-floor API URL.
13        tip_floor_url: String,
14    },
15}
16
17impl Network {
18    // --- Endpoint Accessors ---
19    /// Returns the block-engine URL for status/send JSON-RPC calls.
20    pub fn block_engine_url(&self) -> &str {
21        match self {
22            Network::Mainnet => JITO_BLOCK_ENGINE_URL,
23            Network::Custom {
24                block_engine_url, ..
25            } => block_engine_url,
26        }
27    }
28
29    /// Returns the tip-floor API URL for tip resolution.
30    pub fn tip_floor_url(&self) -> &str {
31        match self {
32            Network::Mainnet => JITO_TIPS_FLOOR_URL,
33            Network::Custom { tip_floor_url, .. } => tip_floor_url,
34        }
35    }
36
37    /// Returns true when using custom network endpoints.
38    pub fn is_custom(&self) -> bool {
39        matches!(self, Network::Custom { .. })
40    }
41
42    /// Returns ordered send endpoints used for retry strategy.
43    pub fn send_endpoints(&self) -> Vec<String> {
44        match self {
45            Network::Mainnet => JITO_MAINNET_ENDPOINTS
46                .iter()
47                .map(|ep| format!("{JITO_BLOCK_ENGINE_URL}?endpoint={ep}"))
48                .collect(),
49            Network::Custom {
50                block_engine_url, ..
51            } => vec![block_engine_url.clone()],
52        }
53    }
54}