Skip to content

Commit 9d4fe91

Browse files
committed
relax zero price validation
1 parent 789af2f commit 9d4fe91

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

src/external/ekubo.cairo

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -226,22 +226,15 @@ pub mod ekubo {
226226
fn fetch_median_price(ref self: ContractState, yang: ContractAddress) -> Result<Wad, felt252> {
227227
let quotes = self.get_quotes(yang);
228228

229-
// if we receive what we consider a valid price from the oracle,
230-
// return it back, otherwise emit an event about the update being invalid
231-
let mut quotes_copy = quotes;
232-
loop {
233-
match quotes_copy.pop_front() {
234-
Option::Some(quote) => {
235-
if quote.is_zero() {
236-
self.emit(InvalidPriceUpdate { yang, quotes });
237-
break Result::Err('EKB: Invalid price update');
238-
}
239-
},
240-
Option::None => {
241-
let price: Wad = median_of_three(quotes);
242-
break Result::Ok(price);
243-
}
244-
};
229+
// As long as the median price is non-zero (i.e. at least two prices are non-zero),
230+
// it is treated as valid because liveness is prioritized for Ekubo's on-chain oracle.
231+
// Otherwise, emit an event about the update being invalid.
232+
let price: Wad = median_of_three(quotes);
233+
if price.is_zero() {
234+
self.emit(InvalidPriceUpdate { yang, quotes });
235+
Result::Err('EKB: Invalid price update')
236+
} else {
237+
Result::Ok(price)
245238
}
246239
}
247240
}

0 commit comments

Comments
 (0)