@@ -3,6 +3,7 @@ use crate::Miner;
3
3
use ore_api:: consts:: BUS_ADDRESSES ;
4
4
use reqwest:: Client ;
5
5
use serde_json:: { json, Value } ;
6
+ use solana_client:: rpc_response:: RpcPrioritizationFee ;
6
7
use url:: Url ;
7
8
8
9
enum FeeStrategy {
@@ -84,12 +85,16 @@ impl Miner {
84
85
. map ( |fee| fee as u64 )
85
86
. ok_or_else ( || format ! ( "Failed to parse priority fee. Response: {:?}" , response) )
86
87
. unwrap ( ) ,
87
- FeeStrategy :: Triton => response[ "result" ]
88
- . as_array ( )
89
- . and_then ( |arr| arr. last ( ) )
90
- . and_then ( |last| last[ "prioritizationFee" ] . as_u64 ( ) )
91
- . ok_or_else ( || format ! ( "Failed to parse priority fee. Response: {:?}" , response) )
92
- . unwrap ( ) ,
88
+ FeeStrategy :: Triton => {
89
+ serde_json:: from_value :: < Vec < RpcPrioritizationFee > > ( response[ "result" ] . clone ( ) )
90
+ . map ( |arr| estimate_prioritization_fee_micro_lamports ( & arr) )
91
+ . or_else ( |error| {
92
+ Err ( format ! (
93
+ "Failed to parse priority fee. Response: {response:?}, error: {error}"
94
+ ) )
95
+ } )
96
+ . unwrap ( )
97
+ }
93
98
} ;
94
99
95
100
// Check if the calculated fee is higher than max
@@ -100,3 +105,28 @@ impl Miner {
100
105
}
101
106
}
102
107
}
108
+
109
+ /// Our estimate is the average over the last 20 slots
110
+ /// Take last 20 slots and average
111
+ pub fn estimate_prioritization_fee_micro_lamports (
112
+ prioritization_fees : & [ RpcPrioritizationFee ] ,
113
+ ) -> u64 {
114
+ let prioritization_fees = prioritization_fees
115
+ . iter ( )
116
+ . rev ( )
117
+ . take ( 20 )
118
+ . map (
119
+ |RpcPrioritizationFee {
120
+ prioritization_fee, ..
121
+ } | * prioritization_fee,
122
+ )
123
+ . collect :: < Vec < _ > > ( ) ;
124
+ if prioritization_fees. is_empty ( ) {
125
+ panic ! ( "Response does not contain any prioritization fees" ) ;
126
+ }
127
+
128
+ let prioritization_fee =
129
+ prioritization_fees. iter ( ) . sum :: < u64 > ( ) / prioritization_fees. len ( ) as u64 ;
130
+
131
+ prioritization_fee
132
+ }
0 commit comments