diff --git a/lazer/Cargo.lock b/lazer/Cargo.lock index f0e0d53e9e..a1160837af 100644 --- a/lazer/Cargo.lock +++ b/lazer/Cargo.lock @@ -3190,7 +3190,7 @@ dependencies = [ [[package]] name = "pyth-lazer-protocol" -version = "0.2.5" +version = "0.2.6" dependencies = [ "anyhow", "bincode", diff --git a/lazer/sdk/rust/protocol/Cargo.toml b/lazer/sdk/rust/protocol/Cargo.toml index 977c4c620f..32b1cc8aab 100644 --- a/lazer/sdk/rust/protocol/Cargo.toml +++ b/lazer/sdk/rust/protocol/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pyth-lazer-protocol" -version = "0.2.5" +version = "0.2.6" edition = "2021" description = "Pyth Lazer SDK - protocol types." license = "Apache-2.0" diff --git a/lazer/sdk/rust/protocol/src/api.rs b/lazer/sdk/rust/protocol/src/api.rs index 082a02391f..778392072f 100644 --- a/lazer/sdk/rust/protocol/src/api.rs +++ b/lazer/sdk/rust/protocol/src/api.rs @@ -34,5 +34,6 @@ pub struct ReducePriceResponse { #[serde(rename_all = "camelCase")] pub struct LatestPrice { pub id: PriceFeedId, + pub exponent: i16, pub prices: AggregatedPriceFeedData, } diff --git a/lazer/sdk/rust/protocol/src/payload.rs b/lazer/sdk/rust/protocol/src/payload.rs index 1e56bfede4..4cf95f9c76 100644 --- a/lazer/sdk/rust/protocol/src/payload.rs +++ b/lazer/sdk/rust/protocol/src/payload.rs @@ -34,6 +34,7 @@ pub enum PayloadPropertyValue { BestBidPrice(Option), BestAskPrice(Option), PublisherCount(Option), + Exponent(i16), } #[derive(Debug, Clone, Default, Serialize, Deserialize)] @@ -50,7 +51,7 @@ impl PayloadData { pub fn new( timestamp_us: TimestampUs, channel_id: ChannelId, - feeds: &[(PriceFeedId, AggregatedPriceFeedData)], + feeds: &[(PriceFeedId, i16, AggregatedPriceFeedData)], requested_properties: &[PriceFeedProperty], ) -> Self { Self { @@ -58,7 +59,7 @@ impl PayloadData { channel_id, feeds: feeds .iter() - .map(|(feed_id, feed)| PayloadFeedData { + .map(|(feed_id, exponent, feed)| PayloadFeedData { feed_id: *feed_id, properties: requested_properties .iter() @@ -73,6 +74,9 @@ impl PayloadData { PriceFeedProperty::PublisherCount => { PayloadPropertyValue::PublisherCount(feed.publisher_count) } + PriceFeedProperty::Exponent => { + PayloadPropertyValue::Exponent(*exponent) + } }) .collect(), }) @@ -106,6 +110,10 @@ impl PayloadData { writer.write_u8(PriceFeedProperty::PublisherCount as u8)?; write_option_u16::(&mut writer, *count)?; } + PayloadPropertyValue::Exponent(exponent) => { + writer.write_u8(PriceFeedProperty::Exponent as u8)?; + writer.write_i16::(*exponent)?; + } } } } @@ -146,6 +154,8 @@ impl PayloadData { PayloadPropertyValue::BestAskPrice(read_option_price::(&mut reader)?) } else if property == PriceFeedProperty::PublisherCount as u8 { PayloadPropertyValue::PublisherCount(read_option_u16::(&mut reader)?) + } else if property == PriceFeedProperty::Exponent as u8 { + PayloadPropertyValue::Exponent(reader.read_i16::()?) } else { bail!("unknown property"); }; diff --git a/lazer/sdk/rust/protocol/src/router.rs b/lazer/sdk/rust/protocol/src/router.rs index 75ef04fa04..58ae808899 100644 --- a/lazer/sdk/rust/protocol/src/router.rs +++ b/lazer/sdk/rust/protocol/src/router.rs @@ -132,6 +132,7 @@ pub enum PriceFeedProperty { BestBidPrice, BestAskPrice, PublisherCount, + Exponent, // More fields may be added later. } @@ -396,12 +397,16 @@ pub struct ParsedFeedPayload { #[serde(skip_serializing_if = "Option::is_none")] #[serde(default)] pub publisher_count: Option, + #[serde(skip_serializing_if = "Option::is_none")] + #[serde(default)] + pub exponent: Option, // More fields may be added later. } impl ParsedFeedPayload { pub fn new( price_feed_id: PriceFeedId, + exponent: Option, data: &AggregatedPriceFeedData, properties: &[PriceFeedProperty], ) -> Self { @@ -411,6 +416,7 @@ impl ParsedFeedPayload { best_bid_price: None, best_ask_price: None, publisher_count: None, + exponent: None, }; for &property in properties { match property { @@ -426,18 +432,26 @@ impl ParsedFeedPayload { PriceFeedProperty::PublisherCount => { output.publisher_count = data.publisher_count; } + PriceFeedProperty::Exponent => { + output.exponent = exponent; + } } } output } - pub fn new_full(price_feed_id: PriceFeedId, data: &AggregatedPriceFeedData) -> Self { + pub fn new_full( + price_feed_id: PriceFeedId, + exponent: Option, + data: &AggregatedPriceFeedData, + ) -> Self { Self { price_feed_id, price: data.price, best_bid_price: data.best_bid_price, best_ask_price: data.best_ask_price, publisher_count: data.publisher_count, + exponent, } } }