diff --git a/lazer/Cargo.lock b/lazer/Cargo.lock index 3cdb3a4c03..cedf88bec3 100644 --- a/lazer/Cargo.lock +++ b/lazer/Cargo.lock @@ -3190,7 +3190,7 @@ dependencies = [ [[package]] name = "pyth-lazer-protocol" -version = "0.2.0" +version = "0.2.1" dependencies = [ "anyhow", "bincode", diff --git a/lazer/sdk/rust/protocol/Cargo.toml b/lazer/sdk/rust/protocol/Cargo.toml index c5b87095d6..39ba1ab369 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.0" +version = "0.2.1" edition = "2021" description = "Pyth Lazer SDK - protocol types." license = "Apache-2.0" diff --git a/lazer/sdk/rust/protocol/src/payload.rs b/lazer/sdk/rust/protocol/src/payload.rs index b474804b77..7e08cf465d 100644 --- a/lazer/sdk/rust/protocol/src/payload.rs +++ b/lazer/sdk/rust/protocol/src/payload.rs @@ -32,6 +32,7 @@ pub enum PayloadPropertyValue { Price(Option), BestBidPrice(Option), BestAskPrice(Option), + PublisherCount(Option), } #[derive(Debug, Clone, Default)] @@ -39,6 +40,7 @@ pub struct AggregatedPriceFeedData { pub price: Option, pub best_bid_price: Option, pub best_ask_price: Option, + pub publisher_count: Option, } pub const PAYLOAD_FORMAT_MAGIC: u32 = 2479346549; @@ -67,6 +69,9 @@ impl PayloadData { PriceFeedProperty::BestAskPrice => { PayloadPropertyValue::BestAskPrice(feed.best_ask_price) } + PriceFeedProperty::PublisherCount => { + PayloadPropertyValue::PublisherCount(feed.publisher_count) + } }) .collect(), }) @@ -96,6 +101,10 @@ impl PayloadData { writer.write_u8(PriceFeedProperty::BestAskPrice as u8)?; write_option_price::(&mut writer, *price)?; } + PayloadPropertyValue::PublisherCount(count) => { + writer.write_u8(PriceFeedProperty::PublisherCount as u8)?; + write_option_u16::(&mut writer, *count)?; + } } } } @@ -134,6 +143,8 @@ impl PayloadData { PayloadPropertyValue::BestBidPrice(read_option_price::(&mut reader)?) } else if property == PriceFeedProperty::BestAskPrice as u8 { PayloadPropertyValue::BestAskPrice(read_option_price::(&mut reader)?) + } else if property == PriceFeedProperty::PublisherCount as u8 { + PayloadPropertyValue::PublisherCount(read_option_u16::(&mut reader)?) } else { bail!("unknown property"); }; @@ -161,6 +172,18 @@ fn read_option_price(mut reader: impl Read) -> std::io::Result( + mut writer: impl Write, + value: Option, +) -> std::io::Result<()> { + writer.write_u16::(value.unwrap_or(0)) +} + +fn read_option_u16(mut reader: impl Read) -> std::io::Result> { + let value = reader.read_u16::()?; + Ok(Some(value)) +} + pub const BINARY_UPDATE_FORMAT_MAGIC: u32 = 1937213467; pub const PARSED_FORMAT_MAGIC: u32 = 2584795844; diff --git a/lazer/sdk/rust/protocol/src/router.rs b/lazer/sdk/rust/protocol/src/router.rs index f6559b0f28..75ef04fa04 100644 --- a/lazer/sdk/rust/protocol/src/router.rs +++ b/lazer/sdk/rust/protocol/src/router.rs @@ -131,6 +131,7 @@ pub enum PriceFeedProperty { Price, BestBidPrice, BestAskPrice, + PublisherCount, // More fields may be added later. } @@ -392,6 +393,9 @@ pub struct ParsedFeedPayload { #[serde(with = "crate::serde_str::option_price")] #[serde(default)] pub best_ask_price: Option, + #[serde(skip_serializing_if = "Option::is_none")] + #[serde(default)] + pub publisher_count: Option, // More fields may be added later. } @@ -406,6 +410,7 @@ impl ParsedFeedPayload { price: None, best_bid_price: None, best_ask_price: None, + publisher_count: None, }; for &property in properties { match property { @@ -418,6 +423,9 @@ impl ParsedFeedPayload { PriceFeedProperty::BestAskPrice => { output.best_ask_price = data.best_ask_price; } + PriceFeedProperty::PublisherCount => { + output.publisher_count = data.publisher_count; + } } } output @@ -429,6 +437,7 @@ impl ParsedFeedPayload { price: data.price, best_bid_price: data.best_bid_price, best_ask_price: data.best_ask_price, + publisher_count: data.publisher_count, } } }