Skip to content

Commit 5bb0fe1

Browse files
authored
Fix 'attempt to subtract with overflow' if publish_time from Pyth is > current block time. (#206)
1 parent 3c009f4 commit 5bb0fe1

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

contracts/oracle/osmosis/src/price_source.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -707,18 +707,17 @@ impl OsmosisPriceSourceChecked {
707707
let price_feed_response = query_price_feed(&deps.querier, contract_addr, price_feed_id)?;
708708
let price_feed = price_feed_response.price_feed;
709709

710-
// Get the current price and confidence interval from the price feed
711-
let current_price = price_feed.get_price_unchecked();
712-
713710
// Check if the current price is not too old
714-
if (current_time - current_price.publish_time as u64) > max_staleness {
711+
let current_price_opt =
712+
price_feed.get_price_no_older_than(current_time as i64, max_staleness);
713+
let Some(current_price) = current_price_opt else {
715714
return Err(InvalidPrice {
716715
reason: format!(
717716
"current price publish time is too old/stale. published: {}, now: {}",
718-
current_price.publish_time, current_time
717+
price_feed.get_price_unchecked().publish_time, current_time
719718
),
720719
});
721-
}
720+
};
722721

723722
// Check if the current price is > 0
724723
if current_price.price <= 0 {

0 commit comments

Comments
 (0)