Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lazer/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lazer/sdk/rust/protocol/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
1 change: 1 addition & 0 deletions lazer/sdk/rust/protocol/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ pub struct ReducePriceResponse {
#[serde(rename_all = "camelCase")]
pub struct LatestPrice {
pub id: PriceFeedId,
pub exponent: i16,
pub prices: AggregatedPriceFeedData,
}
14 changes: 12 additions & 2 deletions lazer/sdk/rust/protocol/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub enum PayloadPropertyValue {
BestBidPrice(Option<Price>),
BestAskPrice(Option<Price>),
PublisherCount(Option<u16>),
Exponent(i16),
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
Expand All @@ -50,15 +51,15 @@ impl PayloadData {
pub fn new(
timestamp_us: TimestampUs,
channel_id: ChannelId,
feeds: &[(PriceFeedId, AggregatedPriceFeedData)],
feeds: &[(PriceFeedId, i16, AggregatedPriceFeedData)],
requested_properties: &[PriceFeedProperty],
) -> Self {
Self {
timestamp_us,
channel_id,
feeds: feeds
.iter()
.map(|(feed_id, feed)| PayloadFeedData {
.map(|(feed_id, exponent, feed)| PayloadFeedData {
feed_id: *feed_id,
properties: requested_properties
.iter()
Expand All @@ -73,6 +74,9 @@ impl PayloadData {
PriceFeedProperty::PublisherCount => {
PayloadPropertyValue::PublisherCount(feed.publisher_count)
}
PriceFeedProperty::Exponent => {
PayloadPropertyValue::Exponent(*exponent)
}
})
.collect(),
})
Expand Down Expand Up @@ -106,6 +110,10 @@ impl PayloadData {
writer.write_u8(PriceFeedProperty::PublisherCount as u8)?;
write_option_u16::<BO>(&mut writer, *count)?;
}
PayloadPropertyValue::Exponent(exponent) => {
writer.write_u8(PriceFeedProperty::Exponent as u8)?;
writer.write_i16::<BO>(*exponent)?;
}
}
}
}
Expand Down Expand Up @@ -146,6 +154,8 @@ impl PayloadData {
PayloadPropertyValue::BestAskPrice(read_option_price::<BO>(&mut reader)?)
} else if property == PriceFeedProperty::PublisherCount as u8 {
PayloadPropertyValue::PublisherCount(read_option_u16::<BO>(&mut reader)?)
} else if property == PriceFeedProperty::Exponent as u8 {
PayloadPropertyValue::Exponent(reader.read_i16::<BO>()?)
} else {
bail!("unknown property");
};
Expand Down
16 changes: 15 additions & 1 deletion lazer/sdk/rust/protocol/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ pub enum PriceFeedProperty {
BestBidPrice,
BestAskPrice,
PublisherCount,
Exponent,
// More fields may be added later.
}

Expand Down Expand Up @@ -396,12 +397,16 @@ pub struct ParsedFeedPayload {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub publisher_count: Option<u16>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub exponent: Option<i16>,
// More fields may be added later.
}

impl ParsedFeedPayload {
pub fn new(
price_feed_id: PriceFeedId,
exponent: Option<i16>,
data: &AggregatedPriceFeedData,
properties: &[PriceFeedProperty],
) -> Self {
Expand All @@ -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 {
Expand All @@ -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<i16>,
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,
}
}
}
Loading