diff --git a/lazer/sdk/rust/protocol/src/payload.rs b/lazer/sdk/rust/protocol/src/payload.rs index 4cf95f9c76..1bffbf3729 100644 --- a/lazer/sdk/rust/protocol/src/payload.rs +++ b/lazer/sdk/rust/protocol/src/payload.rs @@ -29,12 +29,14 @@ pub struct PayloadFeedData { } #[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[repr(u8)] pub enum PayloadPropertyValue { Price(Option), BestBidPrice(Option), BestAskPrice(Option), PublisherCount(Option), Exponent(i16), + FeedUpdateTimestamp(Option) = 12, } #[derive(Debug, Clone, Default, Serialize, Deserialize)] @@ -43,6 +45,7 @@ pub struct AggregatedPriceFeedData { pub best_bid_price: Option, pub best_ask_price: Option, pub publisher_count: Option, + pub feed_update_timestamp: Option, } pub const PAYLOAD_FORMAT_MAGIC: u32 = 2479346549; @@ -77,6 +80,11 @@ impl PayloadData { PriceFeedProperty::Exponent => { PayloadPropertyValue::Exponent(*exponent) } + PriceFeedProperty::FeedUpdateTimestamp => { + PayloadPropertyValue::FeedUpdateTimestamp( + feed.feed_update_timestamp, + ) + } }) .collect(), }) @@ -114,6 +122,10 @@ impl PayloadData { writer.write_u8(PriceFeedProperty::Exponent as u8)?; writer.write_i16::(*exponent)?; } + PayloadPropertyValue::FeedUpdateTimestamp(timestamp) => { + writer.write_u8(PriceFeedProperty::FeedUpdateTimestamp as u8)?; + write_option_timestamp_us::(&mut writer, *timestamp)?; + } } } } @@ -195,6 +207,13 @@ fn read_option_u16(mut reader: impl Read) -> std::io::Result( + mut writer: impl Write, + value: Option, +) -> std::io::Result<()> { + writer.write_u64::(value.map_or(0, |v| v.0)) +} + 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 58ae808899..d5dd6f1af6 100644 --- a/lazer/sdk/rust/protocol/src/router.rs +++ b/lazer/sdk/rust/protocol/src/router.rs @@ -133,6 +133,7 @@ pub enum PriceFeedProperty { BestAskPrice, PublisherCount, Exponent, + FeedUpdateTimestamp = 12, // More fields may be added later. } @@ -400,6 +401,9 @@ pub struct ParsedFeedPayload { #[serde(skip_serializing_if = "Option::is_none")] #[serde(default)] pub exponent: Option, + #[serde(skip_serializing_if = "Option::is_none")] + #[serde(default)] + pub feed_update_timestamp: Option, // More fields may be added later. } @@ -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 { @@ -435,6 +440,9 @@ impl ParsedFeedPayload { PriceFeedProperty::Exponent => { output.exponent = exponent; } + PriceFeedProperty::FeedUpdateTimestamp => { + output.feed_update_timestamp = data.feed_update_timestamp; + } } } output @@ -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, } } } diff --git a/pythnet/pythnet_sdk/Cargo.toml b/pythnet/pythnet_sdk/Cargo.toml index 99cb254675..6b6104268a 100644 --- a/pythnet/pythnet_sdk/Cargo.toml +++ b/pythnet/pythnet_sdk/Cargo.toml @@ -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"