Skip to main content

jito_bundle/bundler/bundle/
types.rs

1use crate::bundler::types::{BundleInstructionSlots, BundleSlotView, TipMode};
2use solana_pubkey::Pubkey;
3use solana_sdk::transaction::VersionedTransaction;
4
5/// Final bundle artifact ready for simulation and submission.
6pub struct BuiltBundle {
7    /// Fully compiled and signed versioned transactions.
8    pub transactions: Vec<VersionedTransaction>,
9    /// Chosen Jito tip account.
10    pub tip_account: Pubkey,
11    /// Effective tip amount in lamports.
12    pub tip_lamports: u64,
13    /// How the tip instruction was inserted.
14    pub tip_mode: TipMode,
15    /// Post-compaction instruction slots used to build the transactions.
16    pub instruction_slots: BundleInstructionSlots,
17}
18
19impl BuiltBundle {
20    // --- Construction ---
21    /// Creates a new built bundle value.
22    pub fn new(
23        transactions: Vec<VersionedTransaction>,
24        tip_account: Pubkey,
25        tip_lamports: u64,
26        tip_mode: TipMode,
27        instruction_slots: BundleInstructionSlots,
28    ) -> Self {
29        Self {
30            transactions,
31            tip_account,
32            tip_lamports,
33            tip_mode,
34            instruction_slots,
35        }
36    }
37
38    // --- Accessors ---
39    /// Returns the post-compaction instruction slots.
40    pub fn instruction_slots(&self) -> &BundleInstructionSlots {
41        &self.instruction_slots
42    }
43}
44
45impl BundleSlotView for BuiltBundle {
46    /// Returns the post-compaction instruction slots.
47    fn instruction_slots(&self) -> &BundleInstructionSlots {
48        &self.instruction_slots
49    }
50
51    /// Counts non-empty instruction slots.
52    fn populated_count(&self) -> usize {
53        self.instruction_slots.iter().flatten().count()
54    }
55
56    /// Returns the index of the last non-empty slot.
57    fn last_populated_index(&self) -> Option<usize> {
58        self.instruction_slots
59            .iter()
60            .rposition(|slot| slot.is_some())
61    }
62}