k256_sdk/types/fees.rs
1//! Priority fees types.
2
3use serde::{Deserialize, Serialize};
4
5/// Network congestion state.
6#[repr(u8)]
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
8pub enum NetworkState {
9 /// Low congestion - minimal fees needed
10 Low = 0,
11 /// Normal congestion
12 Normal = 1,
13 /// High congestion - higher fees recommended
14 High = 2,
15 /// Extreme congestion - maximum fees recommended
16 Extreme = 3,
17}
18
19impl TryFrom<u8> for NetworkState {
20 type Error = u8;
21
22 fn try_from(value: u8) -> Result<Self, Self::Error> {
23 match value {
24 0 => Ok(Self::Low),
25 1 => Ok(Self::Normal),
26 2 => Ok(Self::High),
27 3 => Ok(Self::Extreme),
28 other => Err(other),
29 }
30 }
31}
32
33/// Priority fee recommendations from K256.
34#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
35pub struct PriorityFees {
36 /// Current Solana slot
37 pub slot: u64,
38 /// Unix timestamp in milliseconds
39 pub timestamp_ms: u64,
40 /// Recommended fee in microlamports per CU
41 pub recommended: u64,
42 /// Network congestion state
43 pub state: NetworkState,
44 /// Whether data may be stale
45 pub is_stale: bool,
46 /// 50th percentile swap fee (≥50K CU txns)
47 pub swap_p50: u64,
48 /// 75th percentile swap fee
49 pub swap_p75: u64,
50 /// 90th percentile swap fee
51 pub swap_p90: u64,
52 /// 99th percentile swap fee
53 pub swap_p99: u64,
54 /// Number of samples used
55 pub swap_samples: u32,
56 /// Fee to land with 50% probability
57 pub landing_p50_fee: u64,
58 /// Fee to land with 75% probability
59 pub landing_p75_fee: u64,
60 /// Fee to land with 90% probability
61 pub landing_p90_fee: u64,
62 /// Fee to land with 99% probability
63 pub landing_p99_fee: u64,
64 /// Fee at top 10% tier
65 pub top_10_fee: u64,
66 /// Fee at top 25% tier
67 pub top_25_fee: u64,
68 /// True if fee spike detected
69 pub spike_detected: bool,
70 /// Fee during spike condition
71 pub spike_fee: u64,
72}