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, Clone)]
84pub struct BundleResult {
85 pub bundle_id: String,
87 pub signatures: Vec<String>,
89 pub explorer_url: String,
91}
92
93#[derive(Debug, Serialize)]
95#[serde(rename_all = "camelCase")]
96pub struct SimulateBundleParams {
97 pub encoded_transactions: Vec<String>,
99}
100
101#[derive(Debug, Deserialize)]
103#[serde(rename_all = "camelCase")]
104pub struct SimulateBundleApiResult {
105 pub context: SimulateBundleContext,
107 pub value: SimulateBundleValue,
109}
110
111#[derive(Debug, Deserialize)]
113#[serde(rename_all = "camelCase")]
114pub struct SimulateBundleContext {
115 pub api_version: String,
117 pub slot: u64,
119}
120
121#[derive(Debug, Deserialize)]
123#[serde(rename_all = "camelCase")]
124pub struct SimulateBundleValue {
125 pub summary: SimulateBundleSummary,
127 pub transaction_results: Vec<TransactionSimulationResult>,
129}
130
131#[derive(Debug, Deserialize)]
133#[serde(rename_all = "camelCase")]
134pub enum SimulateBundleSummary {
135 Succeeded,
137 Failed(SimulateBundleFailure),
139}
140
141#[derive(Debug, Deserialize)]
143#[serde(rename_all = "camelCase")]
144pub struct SimulateBundleFailure {
145 pub error: serde_json::Value,
147 pub tx_signature: Option<String>,
149}
150
151impl SimulateBundleFailure {
152 pub fn error_message(&self) -> String {
154 if let Some(tx_failure) = self.error.get("TransactionFailure")
155 && let Some(arr) = tx_failure.as_array()
156 && let Some(msg) = arr.get(1).and_then(|v| v.as_str())
157 {
158 return msg.to_string();
159 }
160 self.error.to_string()
161 }
162}
163
164#[derive(Debug, Deserialize)]
166#[serde(rename_all = "camelCase")]
167pub struct TransactionSimulationResult {
168 pub err: Option<serde_json::Value>,
170 pub logs: Option<Vec<String>>,
172 pub units_consumed: Option<u64>,
174 pub return_data: Option<ReturnData>,
176 pub pre_execution_accounts: Option<Vec<AccountState>>,
178 pub post_execution_accounts: Option<Vec<AccountState>>,
180}
181
182#[derive(Debug, Deserialize)]
184#[serde(rename_all = "camelCase")]
185pub struct AccountState {
186 pub pubkey: String,
188 pub lamports: u64,
190 pub data: Vec<String>,
192 pub owner: String,
194 pub executable: bool,
196 pub rent_epoch: u64,
198}
199
200#[derive(Debug, Deserialize)]
202#[serde(rename_all = "camelCase")]
203pub struct ReturnData {
204 pub program_id: String,
206 pub data: Vec<String>,
208}