Skip to content

Commit 080feba

Browse files
authored
feat(lazer-protocol): Add exponent to payload (#2235)
1 parent bcd51dc commit 080feba

File tree

5 files changed

+30
-5
lines changed

5 files changed

+30
-5
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.5"
3+
version = "0.2.6"
44
edition = "2021"
55
description = "Pyth Lazer SDK - protocol types."
66
license = "Apache-2.0"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ pub struct ReducePriceResponse {
3434
#[serde(rename_all = "camelCase")]
3535
pub struct LatestPrice {
3636
pub id: PriceFeedId,
37+
pub exponent: i16,
3738
pub prices: AggregatedPriceFeedData,
3839
}

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub enum PayloadPropertyValue {
3434
BestBidPrice(Option<Price>),
3535
BestAskPrice(Option<Price>),
3636
PublisherCount(Option<u16>),
37+
Exponent(i16),
3738
}
3839

3940
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
@@ -50,15 +51,15 @@ impl PayloadData {
5051
pub fn new(
5152
timestamp_us: TimestampUs,
5253
channel_id: ChannelId,
53-
feeds: &[(PriceFeedId, AggregatedPriceFeedData)],
54+
feeds: &[(PriceFeedId, i16, AggregatedPriceFeedData)],
5455
requested_properties: &[PriceFeedProperty],
5556
) -> Self {
5657
Self {
5758
timestamp_us,
5859
channel_id,
5960
feeds: feeds
6061
.iter()
61-
.map(|(feed_id, feed)| PayloadFeedData {
62+
.map(|(feed_id, exponent, feed)| PayloadFeedData {
6263
feed_id: *feed_id,
6364
properties: requested_properties
6465
.iter()
@@ -73,6 +74,9 @@ impl PayloadData {
7374
PriceFeedProperty::PublisherCount => {
7475
PayloadPropertyValue::PublisherCount(feed.publisher_count)
7576
}
77+
PriceFeedProperty::Exponent => {
78+
PayloadPropertyValue::Exponent(*exponent)
79+
}
7680
})
7781
.collect(),
7882
})
@@ -106,6 +110,10 @@ impl PayloadData {
106110
writer.write_u8(PriceFeedProperty::PublisherCount as u8)?;
107111
write_option_u16::<BO>(&mut writer, *count)?;
108112
}
113+
PayloadPropertyValue::Exponent(exponent) => {
114+
writer.write_u8(PriceFeedProperty::Exponent as u8)?;
115+
writer.write_i16::<BO>(*exponent)?;
116+
}
109117
}
110118
}
111119
}
@@ -146,6 +154,8 @@ impl PayloadData {
146154
PayloadPropertyValue::BestAskPrice(read_option_price::<BO>(&mut reader)?)
147155
} else if property == PriceFeedProperty::PublisherCount as u8 {
148156
PayloadPropertyValue::PublisherCount(read_option_u16::<BO>(&mut reader)?)
157+
} else if property == PriceFeedProperty::Exponent as u8 {
158+
PayloadPropertyValue::Exponent(reader.read_i16::<BO>()?)
149159
} else {
150160
bail!("unknown property");
151161
};

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ pub enum PriceFeedProperty {
132132
BestBidPrice,
133133
BestAskPrice,
134134
PublisherCount,
135+
Exponent,
135136
// More fields may be added later.
136137
}
137138

@@ -396,12 +397,16 @@ pub struct ParsedFeedPayload {
396397
#[serde(skip_serializing_if = "Option::is_none")]
397398
#[serde(default)]
398399
pub publisher_count: Option<u16>,
400+
#[serde(skip_serializing_if = "Option::is_none")]
401+
#[serde(default)]
402+
pub exponent: Option<i16>,
399403
// More fields may be added later.
400404
}
401405

402406
impl ParsedFeedPayload {
403407
pub fn new(
404408
price_feed_id: PriceFeedId,
409+
exponent: Option<i16>,
405410
data: &AggregatedPriceFeedData,
406411
properties: &[PriceFeedProperty],
407412
) -> Self {
@@ -411,6 +416,7 @@ impl ParsedFeedPayload {
411416
best_bid_price: None,
412417
best_ask_price: None,
413418
publisher_count: None,
419+
exponent: None,
414420
};
415421
for &property in properties {
416422
match property {
@@ -426,18 +432,26 @@ impl ParsedFeedPayload {
426432
PriceFeedProperty::PublisherCount => {
427433
output.publisher_count = data.publisher_count;
428434
}
435+
PriceFeedProperty::Exponent => {
436+
output.exponent = exponent;
437+
}
429438
}
430439
}
431440
output
432441
}
433442

434-
pub fn new_full(price_feed_id: PriceFeedId, data: &AggregatedPriceFeedData) -> Self {
443+
pub fn new_full(
444+
price_feed_id: PriceFeedId,
445+
exponent: Option<i16>,
446+
data: &AggregatedPriceFeedData,
447+
) -> Self {
435448
Self {
436449
price_feed_id,
437450
price: data.price,
438451
best_bid_price: data.best_bid_price,
439452
best_ask_price: data.best_ask_price,
440453
publisher_count: data.publisher_count,
454+
exponent,
441455
}
442456
}
443457
}

0 commit comments

Comments
 (0)