Skip to content

Commit 72d6b5f

Browse files
authored
feat(lazer-protocol): Record publisher count for aggregated price feeds (#2225)
* Add publisher count to aggregated price feed data * Add publisher count to parsed payloads * Change count to u16 * Bump version and change count to option of u16
1 parent dae4af5 commit 72d6b5f

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

lazer/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lazer/sdk/rust/protocol/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pyth-lazer-protocol"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
edition = "2021"
55
description = "Pyth Lazer SDK - protocol types."
66
license = "Apache-2.0"

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ pub enum PayloadPropertyValue {
3232
Price(Option<Price>),
3333
BestBidPrice(Option<Price>),
3434
BestAskPrice(Option<Price>),
35+
PublisherCount(Option<u16>),
3536
}
3637

3738
#[derive(Debug, Clone, Default)]
3839
pub struct AggregatedPriceFeedData {
3940
pub price: Option<Price>,
4041
pub best_bid_price: Option<Price>,
4142
pub best_ask_price: Option<Price>,
43+
pub publisher_count: Option<u16>,
4244
}
4345

4446
pub const PAYLOAD_FORMAT_MAGIC: u32 = 2479346549;
@@ -67,6 +69,9 @@ impl PayloadData {
6769
PriceFeedProperty::BestAskPrice => {
6870
PayloadPropertyValue::BestAskPrice(feed.best_ask_price)
6971
}
72+
PriceFeedProperty::PublisherCount => {
73+
PayloadPropertyValue::PublisherCount(feed.publisher_count)
74+
}
7075
})
7176
.collect(),
7277
})
@@ -96,6 +101,10 @@ impl PayloadData {
96101
writer.write_u8(PriceFeedProperty::BestAskPrice as u8)?;
97102
write_option_price::<BO>(&mut writer, *price)?;
98103
}
104+
PayloadPropertyValue::PublisherCount(count) => {
105+
writer.write_u8(PriceFeedProperty::PublisherCount as u8)?;
106+
write_option_u16::<BO>(&mut writer, *count)?;
107+
}
99108
}
100109
}
101110
}
@@ -134,6 +143,8 @@ impl PayloadData {
134143
PayloadPropertyValue::BestBidPrice(read_option_price::<BO>(&mut reader)?)
135144
} else if property == PriceFeedProperty::BestAskPrice as u8 {
136145
PayloadPropertyValue::BestAskPrice(read_option_price::<BO>(&mut reader)?)
146+
} else if property == PriceFeedProperty::PublisherCount as u8 {
147+
PayloadPropertyValue::PublisherCount(read_option_u16::<BO>(&mut reader)?)
137148
} else {
138149
bail!("unknown property");
139150
};
@@ -161,6 +172,18 @@ fn read_option_price<BO: ByteOrder>(mut reader: impl Read) -> std::io::Result<Op
161172
Ok(value.map(Price))
162173
}
163174

175+
fn write_option_u16<BO: ByteOrder>(
176+
mut writer: impl Write,
177+
value: Option<u16>,
178+
) -> std::io::Result<()> {
179+
writer.write_u16::<BO>(value.unwrap_or(0))
180+
}
181+
182+
fn read_option_u16<BO: ByteOrder>(mut reader: impl Read) -> std::io::Result<Option<u16>> {
183+
let value = reader.read_u16::<BO>()?;
184+
Ok(Some(value))
185+
}
186+
164187
pub const BINARY_UPDATE_FORMAT_MAGIC: u32 = 1937213467;
165188

166189
pub const PARSED_FORMAT_MAGIC: u32 = 2584795844;

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ pub enum PriceFeedProperty {
131131
Price,
132132
BestBidPrice,
133133
BestAskPrice,
134+
PublisherCount,
134135
// More fields may be added later.
135136
}
136137

@@ -392,6 +393,9 @@ pub struct ParsedFeedPayload {
392393
#[serde(with = "crate::serde_str::option_price")]
393394
#[serde(default)]
394395
pub best_ask_price: Option<Price>,
396+
#[serde(skip_serializing_if = "Option::is_none")]
397+
#[serde(default)]
398+
pub publisher_count: Option<u16>,
395399
// More fields may be added later.
396400
}
397401

@@ -406,6 +410,7 @@ impl ParsedFeedPayload {
406410
price: None,
407411
best_bid_price: None,
408412
best_ask_price: None,
413+
publisher_count: None,
409414
};
410415
for &property in properties {
411416
match property {
@@ -418,6 +423,9 @@ impl ParsedFeedPayload {
418423
PriceFeedProperty::BestAskPrice => {
419424
output.best_ask_price = data.best_ask_price;
420425
}
426+
PriceFeedProperty::PublisherCount => {
427+
output.publisher_count = data.publisher_count;
428+
}
421429
}
422430
}
423431
output
@@ -429,6 +437,7 @@ impl ParsedFeedPayload {
429437
price: data.price,
430438
best_bid_price: data.best_bid_price,
431439
best_ask_price: data.best_ask_price,
440+
publisher_count: data.publisher_count,
432441
}
433442
}
434443
}

0 commit comments

Comments
 (0)