-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathblox.rs
More file actions
104 lines (93 loc) · 3.46 KB
/
blox.rs
File metadata and controls
104 lines (93 loc) · 3.46 KB
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
use super::{
swqos_rpc::{SWQoSClientTrait, SWQoSRequest},
SWQoSTrait,
};
use crate::swqos::swqos_rpc::FormatBase64VersionedTransaction;
use rand::seq::IndexedRandom;
use solana_client::nonblocking::rpc_client::RpcClient;
use solana_sdk::{pubkey, pubkey::Pubkey, transaction::VersionedTransaction};
use std::sync::Arc;
pub const BLOX_TIP_ACCOUNTS: &[Pubkey] = &[
pubkey!("HWEoBxYs7ssKuudEjzjmpfJVX7Dvi7wescFsVx2L5yoY"),
pubkey!("95cfoy472fcQHaw4tPGBTKpn6ZQnfEPfBgDQx6gcRmRg"),
pubkey!("3UQUKjhMKaY2S6bjcQD6yHB7utcZt5bfarRCmctpRtUd"),
pubkey!("FogxVNs6Mm2w9rnGL1vkARSwJxvLE8mujTv3LK8RnUhF"),
];
pub const BLOX_ENDPOINT_FRA: &str = "https://germany.solana.dex.blxrbdn.com";
pub const BLOX_ENDPOINT_AMS: &str = "https://amsterdam.solana.dex.blxrbdn.com";
pub const BLOX_ENDPOINT_NY: &str = "https://ny.solana.dex.blxrbdn.com";
pub const BLOX_ENDPOINT_UK: &str = "https://uk.solana.dex.blxrbdn.com";
pub const BLOX_ENDPOINT_LA: &str = "https://la.solana.dex.blxrbdn.com";
pub const BLOX_ENDPOINT_TOKYO: &str = "https://tokyo.solana.dex.blxrbdn.com";
#[derive(Clone)]
pub struct BloxClient {
pub rpc_client: Arc<RpcClient>,
pub swqos_endpoint: String,
pub swqos_header: Option<(String, String)>,
pub swqos_client: Arc<reqwest::Client>,
}
#[async_trait::async_trait]
impl SWQoSTrait for BloxClient {
async fn send_transaction(&self, transaction: VersionedTransaction) -> anyhow::Result<()> {
let body = serde_json::json!({
"transaction": {
"content": transaction.to_base64_string(),
},
"frontRunningProtection": false,
"useStakedRPCs": true,
});
self.swqos_client
.swqos_json_post(
SWQoSRequest {
name: self.get_name().to_string(),
url: format!("{}/api/v2/submit", self.swqos_endpoint),
auth_header: self.swqos_header.clone(),
transactions: vec![transaction],
},
body,
)
.await
}
async fn send_transactions(&self, transactions: Vec<VersionedTransaction>) -> anyhow::Result<()> {
let body = serde_json::json!({
"entries": transactions
.iter()
.map(|tx| {
serde_json::json!({
"transaction": {
"content": tx.to_base64_string(),
},
})
})
.collect::<Vec<_>>(),
});
self.swqos_client
.swqos_json_post(
SWQoSRequest {
name: self.get_name().to_string(),
url: format!("{}/api/v2/submit-batch", self.swqos_endpoint),
auth_header: self.swqos_header.clone(),
transactions,
},
body,
)
.await
}
fn get_tip_account(&self) -> Option<Pubkey> {
Some(*BLOX_TIP_ACCOUNTS.choose(&mut rand::rng())?)
}
fn get_name(&self) -> &str {
"blox"
}
}
impl BloxClient {
pub fn new(rpc_client: Arc<RpcClient>, endpoint: String, auth_token: String) -> Self {
let swqos_client = reqwest::Client::new_swqos_client();
Self {
rpc_client,
swqos_endpoint: endpoint,
swqos_header: Some(("Authorization".to_string(), auth_token)),
swqos_client: Arc::new(swqos_client),
}
}
}