sol-trade-sdk 4.0.3

Rust SDK to interact with the dex trade Solana program.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
pub mod astralane;
pub mod astralane_quic;
pub mod blockrazor;
pub mod bloxroute;
pub mod common;
pub mod flashblock;
pub mod helius;
pub mod jito;
pub mod lightspeed;
pub mod nextblock;
pub mod node1;
pub mod node1_quic;
pub mod serialization;
pub mod solana_rpc;
pub mod soyas;
pub mod speedlanding;
pub mod stellium;
pub mod temporal;
pub mod zeroslot;

use std::sync::Arc;

use solana_commitment_config::CommitmentConfig;
use solana_sdk::transaction::VersionedTransaction;

use anyhow::Result;

use crate::{
    common::SolanaRpcClient,
    constants::swqos::{
        SWQOS_ENDPOINTS_ASTRALANE, SWQOS_ENDPOINTS_ASTRALANE_QUIC,
        SWQOS_ENDPOINTS_ASTRALANE_QUIC_MEV, SWQOS_ENDPOINTS_BLOCKRAZOR,
        SWQOS_ENDPOINTS_BLOCKRAZOR_GRPC, SWQOS_ENDPOINTS_BLOX, SWQOS_ENDPOINTS_FLASHBLOCK,
        SWQOS_ENDPOINTS_HELIUS, SWQOS_ENDPOINTS_JITO, SWQOS_ENDPOINTS_NEXTBLOCK,
        SWQOS_ENDPOINTS_NODE1, SWQOS_ENDPOINTS_NODE1_QUIC, SWQOS_ENDPOINTS_SOYAS,
        SWQOS_ENDPOINTS_SPEEDLANDING, SWQOS_ENDPOINTS_STELLIUM, SWQOS_ENDPOINTS_TEMPORAL,
        SWQOS_ENDPOINTS_ZERO_SLOT, SWQOS_MIN_TIP_ASTRALANE, SWQOS_MIN_TIP_BLOCKRAZOR,
        SWQOS_MIN_TIP_BLOXROUTE, SWQOS_MIN_TIP_DEFAULT, SWQOS_MIN_TIP_FLASHBLOCK,
        SWQOS_MIN_TIP_HELIUS, SWQOS_MIN_TIP_JITO, SWQOS_MIN_TIP_LIGHTSPEED,
        SWQOS_MIN_TIP_NEXTBLOCK, SWQOS_MIN_TIP_NODE1, SWQOS_MIN_TIP_SOYAS,
        SWQOS_MIN_TIP_SPEEDLANDING, SWQOS_MIN_TIP_STELLIUM, SWQOS_MIN_TIP_TEMPORAL,
        SWQOS_MIN_TIP_ZERO_SLOT,
    },
    swqos::{
        astralane::AstralaneClient, blockrazor::BlockRazorClient, bloxroute::BloxrouteClient,
        flashblock::FlashBlockClient, helius::HeliusClient, jito::JitoClient,
        lightspeed::LightspeedClient, nextblock::NextBlockClient, node1::Node1Client,
        node1_quic::Node1QuicClient, solana_rpc::SolRpcClient, soyas::SoyasClient,
        speedlanding::SpeedlandingClient, stellium::StelliumClient, temporal::TemporalClient,
        zeroslot::ZeroSlotClient,
    },
};

// Tip 账户:`SwqosClient::get_tip_account()` 在各实现里多为静态常量;同一批多路提交时,
// 在 `trading::core::async_executor::execute_parallel` 内用局部 `tip_cache`(按 client 指针)去重解析。

/// SWQOS provider blacklist configuration
/// Providers added here will be disabled even if configured by user
/// To enable a provider, remove it from this list
pub const SWQOS_BLACKLIST: &[SwqosType] = &[
    SwqosType::NextBlock, // NextBlock is disabled by default
];

/// SWQOS 提交通道:HTTP、gRPC 或 QUIC(低延迟)。
/// BlockRazor 支持 gRPC 和 HTTP。
/// Astralane 和 Node1 支持 QUIC。
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum SwqosTransport {
    #[default]
    Http,
    Grpc,
    Quic,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum TradeType {
    Create,
    CreateAndBuy,
    Buy,
    Sell,
}

impl std::fmt::Display for TradeType {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let s = match self {
            TradeType::Create => "Create",
            TradeType::CreateAndBuy => "Create and Buy",
            TradeType::Buy => "Buy",
            TradeType::Sell => "Sell",
        };
        write!(f, "{}", s)
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum SwqosType {
    Jito,
    NextBlock,
    ZeroSlot,
    Temporal,
    Bloxroute,
    Node1,
    FlashBlock,
    BlockRazor,
    Astralane,
    Stellium,
    Lightspeed,
    Soyas,
    Speedlanding,
    Helius,
    Default,
}

impl SwqosType {
    /// Label for log alignment; same as Debug output (e.g. "Soyas", "Speedlanding").
    #[inline]
    pub fn as_str(self) -> &'static str {
        match self {
            Self::Jito => "Jito",
            Self::NextBlock => "NextBlock",
            Self::ZeroSlot => "ZeroSlot",
            Self::Temporal => "Temporal",
            Self::Bloxroute => "Bloxroute",
            Self::Node1 => "Node1",
            Self::FlashBlock => "FlashBlock",
            Self::BlockRazor => "BlockRazor",
            Self::Astralane => "Astralane",
            Self::Stellium => "Stellium",
            Self::Lightspeed => "Lightspeed",
            Self::Soyas => "Soyas",
            Self::Speedlanding => "Speedlanding",
            Self::Helius => "Helius",
            Self::Default => "Default",
        }
    }

    pub fn values() -> Vec<Self> {
        vec![
            Self::Jito,
            Self::NextBlock,
            Self::ZeroSlot,
            Self::Temporal,
            Self::Bloxroute,
            Self::Node1,
            Self::FlashBlock,
            Self::BlockRazor,
            Self::Astralane,
            Self::Stellium,
            Self::Lightspeed,
            Self::Soyas,
            Self::Speedlanding,
            Self::Helius,
            Self::Default,
        ]
    }
}

pub type SwqosClient = dyn SwqosClientTrait + Send + Sync + 'static;

#[async_trait::async_trait]
pub trait SwqosClientTrait {
    async fn send_transaction(
        &self,
        trade_type: TradeType,
        transaction: &VersionedTransaction,
        wait_confirmation: bool,
    ) -> Result<()>;
    async fn send_transactions(
        &self,
        trade_type: TradeType,
        transactions: &Vec<VersionedTransaction>,
        wait_confirmation: bool,
    ) -> Result<()>;
    fn get_tip_account(&self) -> Result<String>;
    fn get_swqos_type(&self) -> SwqosType;
    /// Minimum tip in SOL required by this provider. Helius returns lower value when swqos_only is true.
    #[inline]
    fn min_tip_sol(&self) -> f64 {
        match self.get_swqos_type() {
            SwqosType::Jito => SWQOS_MIN_TIP_JITO,
            SwqosType::NextBlock => SWQOS_MIN_TIP_NEXTBLOCK,
            SwqosType::ZeroSlot => SWQOS_MIN_TIP_ZERO_SLOT,
            SwqosType::Temporal => SWQOS_MIN_TIP_TEMPORAL,
            SwqosType::Bloxroute => SWQOS_MIN_TIP_BLOXROUTE,
            SwqosType::Node1 => SWQOS_MIN_TIP_NODE1,
            SwqosType::FlashBlock => SWQOS_MIN_TIP_FLASHBLOCK,
            SwqosType::BlockRazor => SWQOS_MIN_TIP_BLOCKRAZOR,
            SwqosType::Astralane => SWQOS_MIN_TIP_ASTRALANE,
            SwqosType::Stellium => SWQOS_MIN_TIP_STELLIUM,
            SwqosType::Lightspeed => SWQOS_MIN_TIP_LIGHTSPEED,
            SwqosType::Soyas => SWQOS_MIN_TIP_SOYAS,
            SwqosType::Speedlanding => SWQOS_MIN_TIP_SPEEDLANDING,
            SwqosType::Helius => SWQOS_MIN_TIP_HELIUS,
            SwqosType::Default => SWQOS_MIN_TIP_DEFAULT,
        }
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum SwqosRegion {
    NewYork,
    Frankfurt,
    Amsterdam,
    SLC,
    Tokyo,
    London,
    LosAngeles,
    Default,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum SwqosConfig {
    Default(String),
    /// Jito(uuid, region, custom_url)
    Jito(String, SwqosRegion, Option<String>),
    /// NextBlock(api_token, region, custom_url)
    NextBlock(String, SwqosRegion, Option<String>),
    /// Bloxroute(api_token, region, custom_url)
    Bloxroute(String, SwqosRegion, Option<String>),
    /// Temporal(api_token, region, custom_url)
    Temporal(String, SwqosRegion, Option<String>),
    /// ZeroSlot(api_token, region, custom_url)
    ZeroSlot(String, SwqosRegion, Option<String>),
    /// Node1(api_token, region, custom_url, transport). transport=None => HTTP; Some(Quic) => QUIC (port 16666, UUID auth).
    Node1(String, SwqosRegion, Option<String>, Option<SwqosTransport>),
    /// FlashBlock(api_token, region, custom_url)
    FlashBlock(String, SwqosRegion, Option<String>),
    /// BlockRazor(api_token, region, custom_url, transport). transport=None 或 Grpc => gRPC; Some(Http) => HTTP.
    BlockRazor(String, SwqosRegion, Option<String>, Option<SwqosTransport>),
    /// Astralane(api_token, region, custom_url, transport). transport=None 表示 Http。
    Astralane(String, SwqosRegion, Option<String>, Option<SwqosTransport>),
    /// Stellium(api_token, region, custom_url)
    Stellium(String, SwqosRegion, Option<String>),
    /// Lightspeed(api_key, region, custom_url) - Solana Vibe Station
    /// Endpoint format: https://<tier>.rpc.solanavibestation.com/lightspeed?api_key=<key>
    /// Minimum tip: 0.001 SOL
    Lightspeed(String, SwqosRegion, Option<String>),
    /// Soyas(api_token, region, custom_url)
    Soyas(String, SwqosRegion, Option<String>),
    /// To apply for an API key, please contact -> https://t.me/speedlanding_bot?start=0xzero
    /// Minimum tip: 0.001 SOL
    Speedlanding(String, SwqosRegion, Option<String>),
    /// Helius Sender: dual routing to validators and Jito. API key optional (custom TPS only).
    /// (api_key, region, custom_url, swqos_only). swqos_only: None => false (min tip 0.0002 SOL); Some(true) => SWQOS-only (min tip 0.000005 SOL, much lower).
    Helius(String, SwqosRegion, Option<String>, Option<bool>),
}

impl SwqosConfig {
    pub fn swqos_type(&self) -> SwqosType {
        match self {
            SwqosConfig::Default(_) => SwqosType::Default,
            SwqosConfig::Jito(_, _, _) => SwqosType::Jito,
            SwqosConfig::NextBlock(_, _, _) => SwqosType::NextBlock,
            SwqosConfig::Bloxroute(_, _, _) => SwqosType::Bloxroute,
            SwqosConfig::Temporal(_, _, _) => SwqosType::Temporal,
            SwqosConfig::ZeroSlot(_, _, _) => SwqosType::ZeroSlot,
            SwqosConfig::Node1(_, _, _, _) => SwqosType::Node1,
            SwqosConfig::FlashBlock(_, _, _) => SwqosType::FlashBlock,
            SwqosConfig::BlockRazor(_, _, _, _) => SwqosType::BlockRazor,
            SwqosConfig::Astralane(_, _, _, _) => SwqosType::Astralane,
            SwqosConfig::Stellium(_, _, _) => SwqosType::Stellium,
            SwqosConfig::Lightspeed(_, _, _) => SwqosType::Lightspeed,
            SwqosConfig::Soyas(_, _, _) => SwqosType::Soyas,
            SwqosConfig::Speedlanding(_, _, _) => SwqosType::Speedlanding,
            SwqosConfig::Helius(_, _, _, _) => SwqosType::Helius,
        }
    }

    /// Check if current config is in the blacklist
    pub fn is_blacklisted(&self) -> bool {
        SWQOS_BLACKLIST.contains(&self.swqos_type())
    }

    pub fn get_endpoint(swqos_type: SwqosType, region: SwqosRegion, url: Option<String>) -> String {
        if let Some(custom_url) = url {
            return custom_url;
        }

        match swqos_type {
            SwqosType::Jito => SWQOS_ENDPOINTS_JITO[region as usize].to_string(),
            SwqosType::NextBlock => SWQOS_ENDPOINTS_NEXTBLOCK[region as usize].to_string(),
            SwqosType::ZeroSlot => SWQOS_ENDPOINTS_ZERO_SLOT[region as usize].to_string(),
            SwqosType::Temporal => SWQOS_ENDPOINTS_TEMPORAL[region as usize].to_string(),
            SwqosType::Bloxroute => SWQOS_ENDPOINTS_BLOX[region as usize].to_string(),
            SwqosType::Node1 => SWQOS_ENDPOINTS_NODE1[region as usize].to_string(),
            SwqosType::FlashBlock => SWQOS_ENDPOINTS_FLASHBLOCK[region as usize].to_string(),
            SwqosType::BlockRazor => SWQOS_ENDPOINTS_BLOCKRAZOR[region as usize].to_string(),
            SwqosType::Astralane => SWQOS_ENDPOINTS_ASTRALANE[region as usize].to_string(),
            SwqosType::Stellium => SWQOS_ENDPOINTS_STELLIUM[region as usize].to_string(),
            SwqosType::Lightspeed => "".to_string(), // Lightspeed requires custom URL with api_key
            SwqosType::Soyas => SWQOS_ENDPOINTS_SOYAS[region as usize].to_string(),
            SwqosType::Speedlanding => SWQOS_ENDPOINTS_SPEEDLANDING[region as usize].to_string(),
            SwqosType::Helius => SWQOS_ENDPOINTS_HELIUS[region as usize].to_string(),
            SwqosType::Default => "".to_string(),
        }
    }

    pub fn get_endpoint_with_transport(
        swqos_type: SwqosType,
        region: SwqosRegion,
        url: Option<String>,
        transport: Option<SwqosTransport>,
        mev_protection: bool,
    ) -> String {
        if let Some(custom_url) = url {
            return custom_url;
        }

        match swqos_type {
            SwqosType::BlockRazor => {
                // transport=None 或 transport=Grpc => gRPC; transport=Http => HTTP
                let use_http = transport.map_or(false, |t| t == SwqosTransport::Http);
                if use_http {
                    SWQOS_ENDPOINTS_BLOCKRAZOR[region as usize].to_string()
                } else {
                    SWQOS_ENDPOINTS_BLOCKRAZOR_GRPC[region as usize].to_string()
                }
            }
            SwqosType::Node1 => {
                let use_quic = transport.map_or(false, |t| t == SwqosTransport::Quic);
                if use_quic {
                    SWQOS_ENDPOINTS_NODE1_QUIC[region as usize].to_string()
                } else {
                    SWQOS_ENDPOINTS_NODE1[region as usize].to_string()
                }
            }
            SwqosType::Astralane => {
                let use_quic = transport.map_or(false, |t| t == SwqosTransport::Quic);
                if use_quic {
                    // MEV protection: port 9000; standard: port 7000
                    if mev_protection {
                        SWQOS_ENDPOINTS_ASTRALANE_QUIC_MEV[region as usize].to_string()
                    } else {
                        SWQOS_ENDPOINTS_ASTRALANE_QUIC[region as usize].to_string()
                    }
                } else {
                    SWQOS_ENDPOINTS_ASTRALANE[region as usize].to_string()
                }
            }
            _ => Self::get_endpoint(swqos_type, region, None),
        }
    }

    pub async fn get_swqos_client(
        rpc_url: String,
        commitment: CommitmentConfig,
        swqos_config: SwqosConfig,
        mev_protection: bool,
    ) -> Result<Arc<SwqosClient>> {
        match swqos_config {
            SwqosConfig::Jito(auth_token, region, url) => {
                let endpoint = SwqosConfig::get_endpoint(SwqosType::Jito, region, url);
                let jito_client = JitoClient::new(rpc_url.clone(), endpoint, auth_token);
                Ok(Arc::new(jito_client))
            }
            SwqosConfig::NextBlock(auth_token, region, url) => {
                let endpoint = SwqosConfig::get_endpoint(SwqosType::NextBlock, region, url);
                let nextblock_client =
                    NextBlockClient::new(rpc_url.clone(), endpoint.to_string(), auth_token);
                Ok(Arc::new(nextblock_client))
            }
            SwqosConfig::ZeroSlot(auth_token, region, url) => {
                let endpoint = SwqosConfig::get_endpoint(SwqosType::ZeroSlot, region, url);
                let zeroslot_client =
                    ZeroSlotClient::new(rpc_url.clone(), endpoint.to_string(), auth_token);
                Ok(Arc::new(zeroslot_client))
            }
            SwqosConfig::Temporal(auth_token, region, url) => {
                let endpoint = SwqosConfig::get_endpoint(SwqosType::Temporal, region, url);
                let temporal_client =
                    TemporalClient::new(rpc_url.clone(), endpoint.to_string(), auth_token);
                Ok(Arc::new(temporal_client))
            }
            SwqosConfig::Bloxroute(auth_token, region, url) => {
                let endpoint = SwqosConfig::get_endpoint(SwqosType::Bloxroute, region, url);
                let bloxroute_client =
                    BloxrouteClient::new(rpc_url.clone(), endpoint.to_string(), auth_token);
                Ok(Arc::new(bloxroute_client))
            }
            SwqosConfig::Node1(auth_token, region, url, transport) => {
                let use_quic = transport.map_or(false, |t| t == SwqosTransport::Quic);
                if use_quic {
                    let quic_endpoint = url
                        .unwrap_or_else(|| SWQOS_ENDPOINTS_NODE1_QUIC[region as usize].to_string());
                    let node1_quic =
                        Node1QuicClient::connect(&quic_endpoint, &auth_token, rpc_url.clone())
                            .await?;
                    Ok(Arc::new(node1_quic))
                } else {
                    let endpoint = SwqosConfig::get_endpoint(SwqosType::Node1, region, url);
                    let node1_client =
                        Node1Client::new(rpc_url.clone(), endpoint.to_string(), auth_token);
                    Ok(Arc::new(node1_client))
                }
            }
            SwqosConfig::FlashBlock(auth_token, region, url) => {
                let endpoint = SwqosConfig::get_endpoint(SwqosType::FlashBlock, region, url);
                let flashblock_client =
                    FlashBlockClient::new(rpc_url.clone(), endpoint.to_string(), auth_token);
                Ok(Arc::new(flashblock_client))
            }
            SwqosConfig::BlockRazor(auth_token, region, url, transport) => {
                // BlockRazor: transport=None 或 transport=Grpc 时使用 gRPC,transport=Http 时使用 HTTP
                let use_http = transport.map_or(false, |t| t == SwqosTransport::Http);
                let endpoint = SwqosConfig::get_endpoint_with_transport(SwqosType::BlockRazor, region, url, transport, mev_protection);
                if use_http {
                    let blockrazor_client =
                        BlockRazorClient::new_http(rpc_url.clone(), endpoint.to_string(), auth_token, mev_protection);
                    Ok(Arc::new(blockrazor_client))
                } else {
                    // 使用 gRPC 模式(默认或用户明确指定了 gRPC)
                    let blockrazor_client =
                        BlockRazorClient::new_grpc(rpc_url.clone(), endpoint.to_string(), auth_token, mev_protection).await?;
                    Ok(Arc::new(blockrazor_client))
                }
            }
            SwqosConfig::Astralane(auth_token, region, url, transport) => {
                let use_quic = transport.map_or(false, |t| t == SwqosTransport::Quic);
                if use_quic {
                    let quic_endpoint = url.unwrap_or_else(|| {
                        // MEV protection: port 9000; standard: port 7000
                        if mev_protection {
                            SWQOS_ENDPOINTS_ASTRALANE_QUIC_MEV[region as usize].to_string()
                        } else {
                            SWQOS_ENDPOINTS_ASTRALANE_QUIC[region as usize].to_string()
                        }
                    });
                    let astralane_client =
                        AstralaneClient::new_quic(rpc_url.clone(), &quic_endpoint, auth_token)
                            .await?;
                    Ok(Arc::new(astralane_client))
                } else {
                    let endpoint = SwqosConfig::get_endpoint(SwqosType::Astralane, region, url);
                    let astralane_client =
                        AstralaneClient::new(rpc_url.clone(), endpoint.to_string(), auth_token);
                    Ok(Arc::new(astralane_client))
                }
            }
            SwqosConfig::Stellium(auth_token, region, url) => {
                let endpoint = SwqosConfig::get_endpoint(SwqosType::Stellium, region, url);
                let stellium_client =
                    StelliumClient::new(rpc_url.clone(), endpoint.to_string(), auth_token);
                Ok(Arc::new(stellium_client))
            }
            SwqosConfig::Lightspeed(auth_token, region, url) => {
                let endpoint = SwqosConfig::get_endpoint(SwqosType::Lightspeed, region, url);
                let lightspeed_client =
                    LightspeedClient::new(rpc_url.clone(), endpoint.to_string(), auth_token);
                Ok(Arc::new(lightspeed_client))
            }
            SwqosConfig::Soyas(auth_token, region, url) => {
                let endpoint = SwqosConfig::get_endpoint(SwqosType::Soyas, region, url);
                let soyas_client =
                    SoyasClient::new(rpc_url.clone(), endpoint.to_string(), auth_token).await?;
                Ok(Arc::new(soyas_client))
            }
            SwqosConfig::Speedlanding(auth_token, region, url) => {
                let endpoint = SwqosConfig::get_endpoint(SwqosType::Speedlanding, region, url);
                let speedlanding_client =
                    SpeedlandingClient::new(rpc_url.clone(), endpoint.to_string(), auth_token)
                        .await?;
                Ok(Arc::new(speedlanding_client))
            }
            SwqosConfig::Helius(api_key, region, url, swqos_only) => {
                let swqos_only = swqos_only.unwrap_or(false);
                let endpoint = SwqosConfig::get_endpoint(SwqosType::Helius, region, url.clone());
                let api_key_opt = if api_key.is_empty() { None } else { Some(api_key.clone()) };
                let helius_client =
                    HeliusClient::new(rpc_url.clone(), endpoint, api_key_opt, swqos_only);
                Ok(Arc::new(helius_client))
            }
            SwqosConfig::Default(endpoint) => {
                let rpc = SolanaRpcClient::new_with_commitment(endpoint, commitment);
                let rpc_client = SolRpcClient::new(Arc::new(rpc));
                Ok(Arc::new(rpc_client))
            }
        }
    }
}