Skip to content
Closed
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
19 changes: 19 additions & 0 deletions lazer/sdk/rust/protocol/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ pub struct PayloadFeedData {
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[repr(u8)]
pub enum PayloadPropertyValue {
Price(Option<Price>),
BestBidPrice(Option<Price>),
BestAskPrice(Option<Price>),
PublisherCount(Option<u16>),
Exponent(i16),
FeedUpdateTimestamp(Option<TimestampUs>) = 12,
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
Expand All @@ -43,6 +45,7 @@ pub struct AggregatedPriceFeedData {
pub best_bid_price: Option<Price>,
pub best_ask_price: Option<Price>,
pub publisher_count: Option<u16>,
pub feed_update_timestamp: Option<TimestampUs>,
}

pub const PAYLOAD_FORMAT_MAGIC: u32 = 2479346549;
Expand Down Expand Up @@ -77,6 +80,11 @@ impl PayloadData {
PriceFeedProperty::Exponent => {
PayloadPropertyValue::Exponent(*exponent)
}
PriceFeedProperty::FeedUpdateTimestamp => {
PayloadPropertyValue::FeedUpdateTimestamp(
feed.feed_update_timestamp,
)
}
})
.collect(),
})
Expand Down Expand Up @@ -114,6 +122,10 @@ impl PayloadData {
writer.write_u8(PriceFeedProperty::Exponent as u8)?;
writer.write_i16::<BO>(*exponent)?;
}
PayloadPropertyValue::FeedUpdateTimestamp(timestamp) => {
writer.write_u8(PriceFeedProperty::FeedUpdateTimestamp as u8)?;
write_option_timestamp_us::<BO>(&mut writer, *timestamp)?;
}
}
}
}
Expand Down Expand Up @@ -195,6 +207,13 @@ fn read_option_u16<BO: ByteOrder>(mut reader: impl Read) -> std::io::Result<Opti
Ok(Some(value))
}

fn write_option_timestamp_us<BO: ByteOrder>(
mut writer: impl Write,
value: Option<TimestampUs>,
) -> std::io::Result<()> {
writer.write_u64::<BO>(value.map_or(0, |v| v.0))
}

pub const BINARY_UPDATE_FORMAT_MAGIC: u32 = 1937213467;

pub const PARSED_FORMAT_MAGIC: u32 = 2584795844;
Expand Down
9 changes: 9 additions & 0 deletions lazer/sdk/rust/protocol/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ pub enum PriceFeedProperty {
BestAskPrice,
PublisherCount,
Exponent,
FeedUpdateTimestamp = 12,
// More fields may be added later.
}

Expand Down Expand Up @@ -400,6 +401,9 @@ pub struct ParsedFeedPayload {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub exponent: Option<i16>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub feed_update_timestamp: Option<TimestampUs>,
// More fields may be added later.
}

Expand All @@ -417,6 +421,7 @@ impl ParsedFeedPayload {
best_ask_price: None,
publisher_count: None,
exponent: None,
feed_update_timestamp: None,
};
for &property in properties {
match property {
Expand All @@ -435,6 +440,9 @@ impl ParsedFeedPayload {
PriceFeedProperty::Exponent => {
output.exponent = exponent;
}
PriceFeedProperty::FeedUpdateTimestamp => {
output.feed_update_timestamp = data.feed_update_timestamp;
}
}
}
output
Expand All @@ -452,6 +460,7 @@ impl ParsedFeedPayload {
best_ask_price: data.best_ask_price,
publisher_count: data.publisher_count,
exponent,
feed_update_timestamp: data.feed_update_timestamp,
}
}
}
2 changes: 1 addition & 1 deletion pythnet/pythnet_sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ libsecp256k1 = {version ="0.7.1", optional = true}
rand = {version = "0.8.5", optional = true}
solana-program = {version = ">=1.13.6", optional = true}
anchor-lang = {version = ">=0.28.0", optional = true}
proc-macro2 = {version = "=1.0.79", optional = true} # pinned to 1.0.79 to compilation errors with newer versions, remove this if it compiles fine without
proc-macro2 = {version = ">=1.0.79", optional = true} # pinned to 1.0.79 to compilation errors with newer versions, remove this if it compiles fine without

[dev-dependencies]
base64 = "0.21.0"
Expand Down
Loading