@@ -16,7 +16,8 @@ use pyth_sdk::{
16
16
PriceIdentifier ,
17
17
UnixTimestamp ,
18
18
} ;
19
- use solana_program:: { pubkey:: Pubkey , clock:: Clock } ;
19
+ use solana_program:: clock:: Clock ;
20
+ use solana_program:: pubkey:: Pubkey ;
20
21
use std:: mem:: size_of;
21
22
22
23
pub use pyth_sdk:: {
@@ -354,28 +355,27 @@ impl PriceAccount {
354
355
}
355
356
}
356
357
357
- /// Get the last valid price as long as it was updated within `slot_threshold` slots of the current slot.
358
- pub fn get_price_no_older_than (
359
- & self ,
360
- clock : & Clock ,
361
- slot_threshold : u64
362
- ) -> Option < Price > {
363
- if self . agg . status == PriceStatus :: Trading && self . agg . pub_slot >= clock. slot - slot_threshold {
358
+ /// Get the last valid price as long as it was updated within `slot_threshold` slots of the
359
+ /// current slot.
360
+ pub fn get_price_no_older_than ( & self , clock : & Clock , slot_threshold : u64 ) -> Option < Price > {
361
+ if self . agg . status == PriceStatus :: Trading
362
+ && self . agg . pub_slot >= clock. slot - slot_threshold
363
+ {
364
364
return Some ( Price {
365
365
conf : self . agg . conf ,
366
366
expo : self . expo ,
367
367
price : self . agg . price ,
368
368
publish_time : self . timestamp ,
369
- } )
369
+ } ) ;
370
370
}
371
-
371
+
372
372
if self . prev_slot >= clock. slot - slot_threshold {
373
373
return Some ( Price {
374
374
conf : self . prev_conf ,
375
375
expo : self . expo ,
376
376
price : self . prev_price ,
377
377
publish_time : self . prev_timestamp ,
378
- } )
378
+ } ) ;
379
379
}
380
380
381
381
None
@@ -507,7 +507,8 @@ mod test {
507
507
Price ,
508
508
PriceFeed ,
509
509
} ;
510
- use solana_program:: { pubkey:: Pubkey , clock:: Clock } ;
510
+ use solana_program:: clock:: Clock ;
511
+ use solana_program:: pubkey:: Pubkey ;
511
512
512
513
use super :: {
513
514
PriceAccount ,
@@ -639,9 +640,9 @@ mod test {
639
640
assert_eq ! (
640
641
price_account. get_price_no_older_than( & clock, 4 ) ,
641
642
Some ( Price {
642
- conf: 20 ,
643
- expo: 5 ,
644
- price: 10 ,
643
+ conf: 20 ,
644
+ expo: 5 ,
645
+ price: 10 ,
645
646
publish_time: 200 ,
646
647
} )
647
648
) ;
@@ -674,9 +675,9 @@ mod test {
674
675
assert_eq ! (
675
676
price_account. get_price_no_older_than( & clock, 4 ) ,
676
677
Some ( Price {
677
- conf: 70 ,
678
- expo: 5 ,
679
- price: 60 ,
678
+ conf: 70 ,
679
+ expo: 5 ,
680
+ price: 60 ,
680
681
publish_time: 100 ,
681
682
} )
682
683
) ;
@@ -707,10 +708,7 @@ mod test {
707
708
} ;
708
709
709
710
// current price is unknown, prev price is too stale
710
- assert_eq ! (
711
- price_account. get_price_no_older_than( & clock, 3 ) ,
712
- None
713
- ) ;
711
+ assert_eq ! ( price_account. get_price_no_older_than( & clock, 3 ) , None ) ;
714
712
}
715
713
716
714
#[ test]
@@ -737,9 +735,6 @@ mod test {
737
735
..Default :: default ( )
738
736
} ;
739
737
740
- assert_eq ! (
741
- price_account. get_price_no_older_than( & clock, 1 ) ,
742
- None
743
- ) ;
738
+ assert_eq ! ( price_account. get_price_no_older_than( & clock, 1 ) , None ) ;
744
739
}
745
740
}
0 commit comments