From be15f54225f7fa8e7b4779aeaa67aed60c11f1a2 Mon Sep 17 00:00:00 2001 From: microwavedcola1 <89031858+microwavedcola1@users.noreply.github.com> Date: Tue, 17 Jan 2023 14:48:06 +0100 Subject: [PATCH] agg pub slot was recent even if price was not updated, switch to last slot which seems more relevant (#393) Signed-off-by: microwavedcola1 Signed-off-by: microwavedcola1 --- programs/mango-v4/src/state/oracle.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/programs/mango-v4/src/state/oracle.rs b/programs/mango-v4/src/state/oracle.rs index 92621229c..c3e80e1d2 100644 --- a/programs/mango-v4/src/state/oracle.rs +++ b/programs/mango-v4/src/state/oracle.rs @@ -167,22 +167,19 @@ pub fn oracle_price( return Err(MangoError::OracleConfidence.into()); } - // The aggregation pub slot is the time that the aggregate was computed from published data - // that was at most 25 slots old. That means it underestimates the actual staleness, potentially - // significantly. - let agg_pub_slot = price_account.agg.pub_slot; + // The last_slot is when the price was actually updated + let last_slot = price_account.last_slot; if config.max_staleness_slots >= 0 && price_account - .agg - .pub_slot + .last_slot .saturating_add(config.max_staleness_slots as u64) < staleness_slot { msg!( - "Pyth price too stale; pubkey {} price: {} pub slot: {}", + "Pyth price too stale; pubkey {} price: {} last slot: {}", acc_info.key(), price.to_num::(), - agg_pub_slot, + last_slot, ); return Err(MangoError::OracleStale.into());