@@ -16,7 +16,8 @@ use pyth_sdk::{
1616 PriceIdentifier ,
1717 UnixTimestamp ,
1818} ;
19- use solana_program:: { pubkey:: Pubkey , clock:: Clock } ;
19+ use solana_program:: clock:: Clock ;
20+ use solana_program:: pubkey:: Pubkey ;
2021use std:: mem:: size_of;
2122
2223pub use pyth_sdk:: {
@@ -354,28 +355,27 @@ impl PriceAccount {
354355 }
355356 }
356357
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+ {
364364 return Some ( Price {
365365 conf : self . agg . conf ,
366366 expo : self . expo ,
367367 price : self . agg . price ,
368368 publish_time : self . timestamp ,
369- } )
369+ } ) ;
370370 }
371-
371+
372372 if self . prev_slot >= clock. slot - slot_threshold {
373373 return Some ( Price {
374374 conf : self . prev_conf ,
375375 expo : self . expo ,
376376 price : self . prev_price ,
377377 publish_time : self . prev_timestamp ,
378- } )
378+ } ) ;
379379 }
380380
381381 None
@@ -507,7 +507,8 @@ mod test {
507507 Price ,
508508 PriceFeed ,
509509 } ;
510- use solana_program:: { pubkey:: Pubkey , clock:: Clock } ;
510+ use solana_program:: clock:: Clock ;
511+ use solana_program:: pubkey:: Pubkey ;
511512
512513 use super :: {
513514 PriceAccount ,
@@ -639,9 +640,9 @@ mod test {
639640 assert_eq ! (
640641 price_account. get_price_no_older_than( & clock, 4 ) ,
641642 Some ( Price {
642- conf: 20 ,
643- expo: 5 ,
644- price: 10 ,
643+ conf: 20 ,
644+ expo: 5 ,
645+ price: 10 ,
645646 publish_time: 200 ,
646647 } )
647648 ) ;
@@ -674,9 +675,9 @@ mod test {
674675 assert_eq ! (
675676 price_account. get_price_no_older_than( & clock, 4 ) ,
676677 Some ( Price {
677- conf: 70 ,
678- expo: 5 ,
679- price: 60 ,
678+ conf: 70 ,
679+ expo: 5 ,
680+ price: 60 ,
680681 publish_time: 100 ,
681682 } )
682683 ) ;
@@ -707,10 +708,7 @@ mod test {
707708 } ;
708709
709710 // 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 ) ;
714712 }
715713
716714 #[ test]
@@ -737,9 +735,6 @@ mod test {
737735 ..Default :: default ( )
738736 } ;
739737
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 ) ;
744739 }
745740}
0 commit comments