@@ -25,13 +25,9 @@ pub use pyth_sdk::{
2525 PriceStatus ,
2626} ;
2727
28- #[ cfg( target_arch = "bpf" ) ]
29- use solana_program:: {
30- clock:: Clock ,
31- sysvar:: Sysvar ,
32- } ;
28+ use solana_program:: clock:: Clock ;
29+ use solana_program:: sysvar:: Sysvar ;
3330
34- #[ cfg( target_arch = "bpf" ) ]
3531use crate :: VALID_SLOT_PERIOD ;
3632
3733use crate :: PythError ;
@@ -348,14 +344,20 @@ unsafe impl Pod for PriceAccount {
348344
349345impl PriceAccount {
350346 pub fn to_price_feed ( & self , price_key : & Pubkey ) -> PriceFeed {
351- #[ allow( unused_mut) ]
352347 let mut status = self . agg . status ;
353-
354- #[ cfg( target_arch = "bpf" ) ]
355- if matches ! ( status, PriceStatus :: Trading )
356- && Clock :: get ( ) . unwrap ( ) . slot . saturating_sub ( self . agg . pub_slot ) > VALID_SLOT_PERIOD
357- {
358- status = PriceStatus :: Unknown ;
348+ let mut prev_price = self . prev_price ;
349+ let mut prev_conf = self . prev_conf ;
350+ let mut prev_publish_time = self . prev_timestamp ;
351+
352+ if let Ok ( clock) = Clock :: get ( ) {
353+ if matches ! ( status, PriceStatus :: Trading )
354+ && clock. slot . saturating_sub ( self . agg . pub_slot ) > VALID_SLOT_PERIOD
355+ {
356+ status = PriceStatus :: Unknown ;
357+ prev_price = self . agg . price ;
358+ prev_conf = self . agg . conf ;
359+ prev_publish_time = self . timestamp ;
360+ }
359361 }
360362
361363 PriceFeed :: new (
@@ -370,9 +372,9 @@ impl PriceAccount {
370372 self . agg . conf ,
371373 self . ema_price . val ,
372374 self . ema_conf . val as u64 ,
373- self . prev_price ,
374- self . prev_conf ,
375- self . prev_timestamp ,
375+ prev_price,
376+ prev_conf,
377+ prev_publish_time ,
376378 )
377379 }
378380}
0 commit comments