@@ -72,6 +72,9 @@ enum StorageKeys {
72
72
Prices ,
73
73
}
74
74
75
+ /// Alias to document time unit Pyth expects data to be in.
76
+ type Seconds = u64 ;
77
+
75
78
/// The `State` contains all persisted state for the contract. This includes runtime configuration.
76
79
///
77
80
/// There is no valid Default state for this contract, so we derive PanicOnDefault to force
@@ -461,7 +464,11 @@ impl Pyth {
461
464
462
465
/// Get the latest available price cached for the given price identifier, if that price is
463
466
/// no older than the given age.
464
- pub fn get_price_no_older_than ( & self , price_id : PriceIdentifier , age : u64 ) -> Option < Price > {
467
+ pub fn get_price_no_older_than (
468
+ & self ,
469
+ price_id : PriceIdentifier ,
470
+ age : Seconds ,
471
+ ) -> Option < Price > {
465
472
self . prices . get ( & price_id) . and_then ( |feed| {
466
473
let block_timestamp = env:: block_timestamp ( ) / 1_000_000_000 ;
467
474
let price_timestamp = feed. price . publish_time ;
@@ -491,10 +498,10 @@ impl Pyth {
491
498
pub fn get_ema_price_no_older_than (
492
499
& self ,
493
500
price_id : PriceIdentifier ,
494
- age : u64 ,
501
+ age : Seconds ,
495
502
) -> Option < Price > {
496
503
self . prices . get ( & price_id) . and_then ( |feed| {
497
- let block_timestamp = env:: block_timestamp ( ) ;
504
+ let block_timestamp = env:: block_timestamp ( ) / 1_000_000_000 ;
498
505
let price_timestamp = feed. ema_price . publish_time ;
499
506
500
507
// - If Price older than STALENESS_THRESHOLD, set status to Unknown.
0 commit comments