orca_tx_sender/
fee_config.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2pub enum Percentile {
3 P25,
4 P50,
5 P75,
6 P95,
7 P99,
8}
9
10impl Percentile {
11 pub fn as_value(&self) -> u8 {
12 match self {
13 Self::P25 => 25,
14 Self::P50 => 50,
15 Self::P75 => 75,
16 Self::P95 => 95,
17 Self::P99 => 99,
18 }
19 }
20}
21
22#[derive(Debug, Clone, Copy, PartialEq, Eq)]
23pub enum JitoPercentile {
24 P25,
25 P50,
26 P50Ema, P75,
28 P95,
29 P99,
30}
31
32#[derive(Debug, Clone, PartialEq)]
33pub enum PriorityFeeStrategy {
34 Dynamic {
35 percentile: Percentile,
36 max_lamports: u64,
37 },
38 Exact(u64),
39 Disabled,
40}
41
42#[derive(Debug, Clone, PartialEq)]
43pub enum JitoFeeStrategy {
44 Dynamic {
45 percentile: JitoPercentile,
46 max_lamports: u64,
47 },
48 Exact(u64),
49 Disabled,
50}
51
52#[non_exhaustive]
57#[derive(Debug, Clone, PartialEq)]
58pub struct FeeConfig {
59 pub priority_fee: PriorityFeeStrategy,
60 pub jito: JitoFeeStrategy,
61 pub compute_unit_margin_multiplier: f64,
62 pub jito_block_engine_url: String,
63}
64
65impl FeeConfig {
66 pub fn with_priority_fee(mut self, priority_fee: PriorityFeeStrategy) -> Self {
67 self.priority_fee = priority_fee;
68 self
69 }
70
71 pub fn with_jito(mut self, jito: JitoFeeStrategy) -> Self {
72 self.jito = jito;
73 self
74 }
75
76 pub fn with_compute_unit_margin_multiplier(
77 mut self,
78 compute_unit_margin_multiplier: f64,
79 ) -> Self {
80 self.compute_unit_margin_multiplier = compute_unit_margin_multiplier;
81 self
82 }
83
84 pub fn with_jito_block_engine_url(mut self, jito_block_engine_url: impl Into<String>) -> Self {
85 self.jito_block_engine_url = jito_block_engine_url.into();
86 self
87 }
88}
89
90impl Default for FeeConfig {
91 fn default() -> Self {
92 Self {
93 priority_fee: PriorityFeeStrategy::Disabled,
94 jito: JitoFeeStrategy::Disabled,
95 compute_unit_margin_multiplier: 1.1,
96 jito_block_engine_url: "https://bundles.jito.wtf".to_string(),
97 }
98 }
99}
100
101#[cfg(test)]
102mod tests {
103 use super::*;
104
105 #[test]
106 fn builder_sets_fee_configuration() {
107 let config = FeeConfig::default()
108 .with_priority_fee(PriorityFeeStrategy::Exact(10))
109 .with_jito(JitoFeeStrategy::Exact(20))
110 .with_compute_unit_margin_multiplier(1.25)
111 .with_jito_block_engine_url("https://example.com");
112
113 assert_eq!(config.priority_fee, PriorityFeeStrategy::Exact(10));
114 assert_eq!(config.jito, JitoFeeStrategy::Exact(20));
115 assert_eq!(config.compute_unit_margin_multiplier, 1.25);
116 assert_eq!(config.jito_block_engine_url, "https://example.com");
117 }
118}