Skip to content

Commit

Permalink
Merge pull request #124 from mrgnlabs/123-assert-oracle-parameter-bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
jkbpvsc authored Aug 1, 2023
2 parents 4feff86 + ded7ec3 commit fea5317
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions programs/marginfi/src/state/price.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,17 @@ impl PriceAdapter for PythEmaPriceFeed {
}

fn get_confidence_interval(&self) -> MarginfiResult<I80F48> {
Ok(
let conf_interval =
pyth_price_components_to_i80f48(I80F48::from_num(self.price.conf), self.price.expo)?
.checked_mul(CONF_INTERVAL_MULTIPLE)
.ok_or_else(math_error!())?,
)
.ok_or_else(math_error!())?;

assert!(
conf_interval >= I80F48::ZERO,
"Negative confidence interval"
);

Ok(conf_interval)
}

fn get_price_range(&self) -> MarginfiResult<(I80F48, I80F48)> {
Expand Down Expand Up @@ -217,9 +223,16 @@ impl PriceAdapter for SwitchboardV2PriceFeed {
let std_div = swithcboard_decimal_to_i80f48(std_div)
.ok_or(MarginfiError::InvalidSwitchboardDecimalConversion)?;

Ok(std_div
let conf_interval = std_div
.checked_mul(CONF_INTERVAL_MULTIPLE)
.ok_or_else(math_error!())?)
.ok_or_else(math_error!())?;

assert!(
conf_interval >= I80F48::ZERO,
"Negative confidence interval"
);

Ok(conf_interval)
}

fn get_price_range(&self) -> MarginfiResult<(I80F48, I80F48)> {
Expand Down

0 comments on commit fea5317

Please sign in to comment.