1- use std:: sync:: LazyLock ;
2-
3- use crate :: jito:: TIP_STREAM_URL ;
1+ use crate :: jito:: { TipPercentileData , TIPS_PERCENTILE , TIP_STREAM_URL } ;
42use anyhow:: { Context , Result } ;
53use futures_util:: StreamExt ;
6- use serde:: Deserialize ;
7- use tokio:: sync:: RwLock ;
84use tokio_tungstenite:: { connect_async, tungstenite:: Message } ;
95use tracing:: { debug, error, info, warn} ;
106
11- pub static TIPS_PERCENTILE : LazyLock < RwLock < Option < TipPercentileData > > > =
12- LazyLock :: new ( || RwLock :: new ( None ) ) ;
13-
14- #[ derive( Debug , Deserialize , Clone ) ]
15- pub struct TipPercentileData {
16- pub time : String ,
17- pub landed_tips_25th_percentile : f64 ,
18- pub landed_tips_50th_percentile : f64 ,
19- pub landed_tips_75th_percentile : f64 ,
20- pub landed_tips_95th_percentile : f64 ,
21- pub landed_tips_99th_percentile : f64 ,
22- pub ema_landed_tips_50th_percentile : f64 ,
23- }
24-
257pub async fn tip_stream ( ) -> Result < ( ) > {
268 let ( ws_stream, _) = connect_async ( TIP_STREAM_URL . to_string ( ) )
279 . await
@@ -39,7 +21,7 @@ pub async fn tip_stream() -> Result<()> {
3921 match serde_json:: from_str :: < Vec < TipPercentileData > > ( & text) {
4022 Ok ( data) => {
4123 if !data. is_empty ( ) {
42- * TIPS_PERCENTILE . write ( ) . await = Some ( data[ 0 ] . clone ( ) ) ;
24+ * TIPS_PERCENTILE . write ( ) . await = data. first ( ) . cloned ( ) ;
4325 } else {
4426 warn ! ( "Received an empty data." )
4527 }
0 commit comments