Skip to content

Commit 8f37547

Browse files
authored
Merge pull request #2132 from pyth-network/add-price-mult
feat(pyth-lazer): Add Multiplication for Price
2 parents 56dbe7a + f22cb5a commit 8f37547

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lazer/sdk/rust/protocol/src/router.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use {
88
serde::{de::Error, Deserialize, Serialize},
99
std::{
1010
num::NonZeroI64,
11-
ops::{Add, Deref, DerefMut, Div, Sub},
11+
ops::{Add, Deref, DerefMut, Div, Mul, Sub},
1212
time::{SystemTime, UNIX_EPOCH},
1313
},
1414
};
@@ -121,6 +121,21 @@ impl Div<i64> for Price {
121121
}
122122
}
123123

124+
impl Mul<Price> for Price {
125+
type Output = Option<Price>;
126+
fn mul(self, rhs: Price) -> Self::Output {
127+
let left_value = i128::from(self.0.get());
128+
let right_value = i128::from(rhs.0.get());
129+
130+
let value = left_value * right_value / 10i128.pow(Price::TMP_EXPONENT);
131+
let value = match value.try_into() {
132+
Ok(value) => value,
133+
Err(_) => return None,
134+
};
135+
NonZeroI64::new(value).map(Self)
136+
}
137+
}
138+
124139
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
125140
#[serde(rename_all = "camelCase")]
126141
pub enum PriceFeedProperty {

0 commit comments

Comments
 (0)