@@ -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 {
@@ -129,11 +130,17 @@ impl Miner {
129
130
)
130
131
} )
131
132
. ok_or_else ( || format ! ( "Failed to parse priority fee response: {:?}" , response) ) ,
132
- FeeStrategy :: Triton => response[ "result" ]
133
- . as_array ( )
134
- . and_then ( |arr| arr. last ( ) )
135
- . and_then ( |last| last[ "prioritizationFee" ] . as_u64 ( ) )
136
- . ok_or_else ( || format ! ( "Failed to parse priority fee response: {:?}" , response) ) ,
133
+ FeeStrategy :: Triton => {
134
+ serde_json:: from_value :: < Vec < RpcPrioritizationFee > > ( response[ "result" ] . clone ( ) )
135
+ . map ( |prioritization_fees| {
136
+ estimate_prioritization_fee_micro_lamports ( prioritization_fees)
137
+ } )
138
+ . ok_or_else ( |error : serde_json:: Error | {
139
+ Err ( format ! (
140
+ "Failed to parse priority fee. Response: {response:?}, error: {error}"
141
+ ) )
142
+ } )
143
+ }
137
144
} ;
138
145
139
146
// Check if the calculated fee is higher than max
@@ -149,3 +156,27 @@ impl Miner {
149
156
}
150
157
}
151
158
}
159
+
160
+ /// Our estimate is the average over the last 20 slots
161
+ pub fn estimate_prioritization_fee_micro_lamports (
162
+ prioritization_fees : Vec < RpcPrioritizationFee > ,
163
+ ) -> u64 {
164
+ let prioritization_fees = prioritization_fees
165
+ . into_iter ( )
166
+ . rev ( )
167
+ . take ( 20 )
168
+ . map (
169
+ |RpcPrioritizationFee {
170
+ prioritization_fee, ..
171
+ } | prioritization_fee,
172
+ )
173
+ . collect :: < Vec < _ > > ( ) ;
174
+ if prioritization_fees. is_empty ( ) {
175
+ panic ! ( "Response does not contain any prioritization fees" ) ;
176
+ }
177
+
178
+ let prioritization_fee =
179
+ prioritization_fees. iter ( ) . sum :: < u64 > ( ) / prioritization_fees. len ( ) as u64 ;
180
+
181
+ prioritization_fee
182
+ }
0 commit comments