@@ -424,6 +424,14 @@ module pyth::pyth {
424
424
get_price_no_older_than (price_identifier, state::get_stale_price_threshold_secs ())
425
425
}
426
426
427
+ /// A view function version of get_price(...) that's available in offchain programming environments
428
+ /// including aptos fullnode api, aptos cli, and aptos ts sdk.
429
+ #[view]
430
+ public fun get_price_by_feed_id (feed_id: vector <u8 >): Price {
431
+ let price_identifier = price_identifier::from_byte_vec (feed_id);
432
+ get_price (price_identifier)
433
+ }
434
+
427
435
/// Get the latest available price cached for the given price identifier, if that price is
428
436
/// no older than the given age.
429
437
public fun get_price_no_older_than (price_identifier: PriceIdentifier , max_age_secs: u64 ): Price {
@@ -433,6 +441,12 @@ module pyth::pyth {
433
441
price
434
442
}
435
443
444
+ #[view]
445
+ public fun get_price_no_older_than_by_feed_id (feed_id: vector <u8 >, max_age_secs: u64 ): Price {
446
+ let price_identifier = price_identifier::from_byte_vec (feed_id);
447
+ get_price_no_older_than (price_identifier, max_age_secs)
448
+ }
449
+
436
450
/// Get the latest available price cached for the given price identifier.
437
451
///
438
452
/// WARNING: the returned price can be from arbitrarily far in the past.
@@ -446,6 +460,12 @@ module pyth::pyth {
446
460
price_info::get_price_feed (&state::get_latest_price_info (price_identifier)))
447
461
}
448
462
463
+ #[view]
464
+ public fun get_price_unsafe_by_feed_id (feed_id: vector <u8 >): Price {
465
+ let price_identifier = price_identifier::from_byte_vec (feed_id);
466
+ get_price_unsafe (price_identifier)
467
+ }
468
+
449
469
fun abs_diff (x: u64 , y: u64 ): u64 {
450
470
if (x > y) {
451
471
return x - y
0 commit comments