Skip to main content

jito_bundle/
types.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Serialize)]
4pub struct JsonRpcRequest<T: Serialize> {
5    pub jsonrpc: &'static str,
6    pub id: u64,
7    pub method: &'static str,
8    pub params: T,
9}
10
11#[derive(Debug, Deserialize)]
12pub struct JsonRpcResponse<T> {
13    pub jsonrpc: String,
14    pub id: u64,
15    pub result: Option<T>,
16    pub error: Option<JsonRpcError>,
17}
18
19#[derive(Debug, Deserialize)]
20pub struct JsonRpcError {
21    pub code: i64,
22    pub message: String,
23}
24
25#[derive(Debug, Deserialize, Clone)]
26pub struct JitoTipFloorResponse {
27    pub time: String,
28    pub landed_tips_25th_percentile: f64,
29    pub landed_tips_50th_percentile: f64,
30    pub landed_tips_75th_percentile: f64,
31    pub landed_tips_95th_percentile: f64,
32    pub landed_tips_99th_percentile: f64,
33    pub ema_landed_tips_50th_percentile: f64,
34}
35
36#[derive(Clone)]
37pub enum BundleStatus {
38    Pending,
39    Landed { slot: Option<u64> },
40    Failed { error: Option<String> },
41    Unknown,
42}
43
44impl std::fmt::Debug for BundleStatus {
45    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
46        match self {
47            BundleStatus::Pending => write!(f, "Pending"),
48            BundleStatus::Landed { slot } => write!(f, "Landed(slot: {slot:?})"),
49            BundleStatus::Failed { error } => write!(f, "Failed(error: {error:?})"),
50            BundleStatus::Unknown => write!(f, "Unknown"),
51        }
52    }
53}
54
55#[derive(Debug)]
56pub struct BundleResult {
57    pub success: bool,
58    pub bundle_id: Option<String>,
59    pub error: Option<String>,
60    pub signatures: Vec<String>,
61    pub explorer_url: Option<String>,
62}
63
64#[derive(Debug, Serialize)]
65#[serde(rename_all = "camelCase")]
66pub struct SimulateBundleParams {
67    pub encoded_transactions: Vec<String>,
68}
69
70#[derive(Debug, Deserialize)]
71#[serde(rename_all = "camelCase")]
72pub struct SimulateBundleApiResult {
73    pub context: SimulateBundleContext,
74    pub value: SimulateBundleValue,
75}
76
77#[derive(Debug, Deserialize)]
78#[serde(rename_all = "camelCase")]
79pub struct SimulateBundleContext {
80    pub api_version: String,
81    pub slot: u64,
82}
83
84#[derive(Debug, Deserialize)]
85#[serde(rename_all = "camelCase")]
86pub struct SimulateBundleValue {
87    pub summary: SimulateBundleSummary,
88    pub transaction_results: Vec<TransactionSimulationResult>,
89}
90
91#[derive(Debug, Deserialize)]
92#[serde(rename_all = "camelCase")]
93pub enum SimulateBundleSummary {
94    Succeeded,
95    Failed(SimulateBundleFailure),
96}
97
98#[derive(Debug, Deserialize)]
99#[serde(rename_all = "camelCase")]
100pub struct SimulateBundleFailure {
101    pub error: serde_json::Value,
102    pub tx_signature: Option<String>,
103}
104
105impl SimulateBundleFailure {
106    pub fn error_message(&self) -> String {
107        if let Some(tx_failure) = self.error.get("TransactionFailure")
108            && let Some(arr) = tx_failure.as_array()
109            && let Some(msg) = arr.get(1).and_then(|v| v.as_str())
110        {
111            return msg.to_string();
112        }
113        self.error.to_string()
114    }
115}
116
117#[derive(Debug, Deserialize)]
118#[serde(rename_all = "camelCase")]
119pub struct TransactionSimulationResult {
120    pub err: Option<serde_json::Value>,
121    pub logs: Option<Vec<String>>,
122    pub units_consumed: Option<u64>,
123    pub return_data: Option<ReturnData>,
124    pub pre_execution_accounts: Option<Vec<AccountState>>,
125    pub post_execution_accounts: Option<Vec<AccountState>>,
126}
127
128#[derive(Debug, Deserialize)]
129#[serde(rename_all = "camelCase")]
130pub struct AccountState {
131    pub pubkey: String,
132    pub lamports: u64,
133    pub data: Vec<String>,
134    pub owner: String,
135    pub executable: bool,
136    pub rent_epoch: u64,
137}
138
139#[derive(Debug, Deserialize)]
140#[serde(rename_all = "camelCase")]
141pub struct ReturnData {
142    pub program_id: String,
143    pub data: Vec<String>,
144}