Skip to content

Commit

Permalink
Merge pull request #2132 from pyth-network/add-price-mult
Browse files Browse the repository at this point in the history
feat(pyth-lazer): Add Multiplication for Price
  • Loading branch information
darunrs authored Nov 19, 2024
2 parents 56dbe7a + f22cb5a commit 8f37547
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lazer/sdk/rust/protocol/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use {
serde::{de::Error, Deserialize, Serialize},
std::{
num::NonZeroI64,
ops::{Add, Deref, DerefMut, Div, Sub},
ops::{Add, Deref, DerefMut, Div, Mul, Sub},
time::{SystemTime, UNIX_EPOCH},
},
};
Expand Down Expand Up @@ -121,6 +121,21 @@ impl Div<i64> for Price {
}
}

impl Mul<Price> for Price {
type Output = Option<Price>;
fn mul(self, rhs: Price) -> Self::Output {
let left_value = i128::from(self.0.get());
let right_value = i128::from(rhs.0.get());

let value = left_value * right_value / 10i128.pow(Price::TMP_EXPONENT);
let value = match value.try_into() {
Ok(value) => value,
Err(_) => return None,
};
NonZeroI64::new(value).map(Self)
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum PriceFeedProperty {
Expand Down

0 comments on commit 8f37547

Please sign in to comment.