1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Serialize)]
5pub struct JsonRpcRequest<T: Serialize> {
6 pub jsonrpc: &'static str,
8 pub id: u64,
10 pub method: &'static str,
12 pub params: T,
14}
15
16#[derive(Debug, Deserialize)]
18pub struct JsonRpcResponse<T> {
19 pub jsonrpc: String,
21 pub id: u64,
23 pub result: Option<T>,
25 pub error: Option<JsonRpcError>,
27}
28
29#[derive(Debug, Deserialize)]
31pub struct JsonRpcError {
32 pub code: i64,
34 pub message: String,
36}
37
38#[derive(Debug, Deserialize, Clone)]
40pub struct JitoTipFloorResponse {
41 pub time: String,
43 pub landed_tips_25th_percentile: f64,
45 pub landed_tips_50th_percentile: f64,
47 pub landed_tips_75th_percentile: f64,
49 pub landed_tips_95th_percentile: f64,
51 pub landed_tips_99th_percentile: f64,
53 pub ema_landed_tips_50th_percentile: f64,
55}
56
57#[derive(Clone)]
59pub enum BundleStatus {
60 Pending,
62 Landed { slot: Option<u64> },
64 Failed { error: Option<String> },
66 Unknown,
68}
69
70impl std::fmt::Debug for BundleStatus {
71 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
73 match self {
74 BundleStatus::Pending => write!(f, "Pending"),
75 BundleStatus::Landed { slot } => write!(f, "Landed(slot: {slot:?})"),
76 BundleStatus::Failed { error } => write!(f, "Failed(error: {error:?})"),
77 BundleStatus::Unknown => write!(f, "Unknown"),
78 }
79 }
80}
81
82#[derive(Debug)]
84pub struct BundleResult {
85 pub success: bool,
87 pub bundle_id: Option<String>,
89 pub error: Option<String>,
91 pub signatures: Vec<String>,
93 pub explorer_url: Option<String>,
95}
96
97#[derive(Debug, Serialize)]
99#[serde(rename_all = "camelCase")]
100pub struct SimulateBundleParams {
101 pub encoded_transactions: Vec<String>,
103}
104
105#[derive(Debug, Deserialize)]
107#[serde(rename_all = "camelCase")]
108pub struct SimulateBundleApiResult {
109 pub context: SimulateBundleContext,
111 pub value: SimulateBundleValue,
113}
114
115#[derive(Debug, Deserialize)]
117#[serde(rename_all = "camelCase")]
118pub struct SimulateBundleContext {
119 pub api_version: String,
121 pub slot: u64,
123}
124
125#[derive(Debug, Deserialize)]
127#[serde(rename_all = "camelCase")]
128pub struct SimulateBundleValue {
129 pub summary: SimulateBundleSummary,
131 pub transaction_results: Vec<TransactionSimulationResult>,
133}
134
135#[derive(Debug, Deserialize)]
137#[serde(rename_all = "camelCase")]
138pub enum SimulateBundleSummary {
139 Succeeded,
141 Failed(SimulateBundleFailure),
143}
144
145#[derive(Debug, Deserialize)]
147#[serde(rename_all = "camelCase")]
148pub struct SimulateBundleFailure {
149 pub error: serde_json::Value,
151 pub tx_signature: Option<String>,
153}
154
155impl SimulateBundleFailure {
156 pub fn error_message(&self) -> String {
158 if let Some(tx_failure) = self.error.get("TransactionFailure")
159 && let Some(arr) = tx_failure.as_array()
160 && let Some(msg) = arr.get(1).and_then(|v| v.as_str())
161 {
162 return msg.to_string();
163 }
164 self.error.to_string()
165 }
166}
167
168#[derive(Debug, Deserialize)]
170#[serde(rename_all = "camelCase")]
171pub struct TransactionSimulationResult {
172 pub err: Option<serde_json::Value>,
174 pub logs: Option<Vec<String>>,
176 pub units_consumed: Option<u64>,
178 pub return_data: Option<ReturnData>,
180 pub pre_execution_accounts: Option<Vec<AccountState>>,
182 pub post_execution_accounts: Option<Vec<AccountState>>,
184}
185
186#[derive(Debug, Deserialize)]
188#[serde(rename_all = "camelCase")]
189pub struct AccountState {
190 pub pubkey: String,
192 pub lamports: u64,
194 pub data: Vec<String>,
196 pub owner: String,
198 pub executable: bool,
200 pub rent_epoch: u64,
202}
203
204#[derive(Debug, Deserialize)]
206#[serde(rename_all = "camelCase")]
207pub struct ReturnData {
208 pub program_id: String,
210 pub data: Vec<String>,
212}