Skip to content

Commit 38c1df0

Browse files
committed
feat(pyth-lazer) Add funding_rate_interval to feed properties
1 parent b9ad8f2 commit 38c1df0

File tree

4 files changed

+62
-14
lines changed

4 files changed

+62
-14
lines changed

Cargo.lock

Lines changed: 13 additions & 13 deletions
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.10.1"
3+
version = "0.10.2"
44
edition = "2021"
55
description = "Pyth Lazer SDK - protocol types."
66
license = "Apache-2.0"

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub enum PayloadPropertyValue {
4242
Confidence(Option<Price>),
4343
FundingRate(Option<Rate>),
4444
FundingTimestamp(Option<TimestampUs>),
45+
FundingRateInterval(Option<DurationUs>),
4546
}
4647

4748
#[derive(Debug, Clone, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
@@ -98,6 +99,9 @@ impl PayloadData {
9899
}
99100
PriceFeedProperty::FundingTimestamp => {
100101
PayloadPropertyValue::FundingTimestamp(feed.funding_timestamp)
102+
},
103+
PriceFeedProperty::FundingRateInterval => {
104+
PayloadPropertyValue::FundingRateInterval(feed.funding_rate_interval)
101105
}
102106
})
103107
.collect(),
@@ -147,6 +151,11 @@ impl PayloadData {
147151
PayloadPropertyValue::FundingTimestamp(timestamp) => {
148152
writer.write_u8(PriceFeedProperty::FundingTimestamp as u8)?;
149153
write_option_timestamp::<BO>(&mut writer, *timestamp)?;
154+
},
155+
&PayloadPropertyValue::FundingRateInterval(interval) => {
156+
writer.write_u8(PriceFeedProperty::FundingRateInterval as u8)?;
157+
write_option_duration::<BO>(&mut writer, interval)?;
158+
150159
}
151160
}
152161
}
@@ -198,6 +207,9 @@ impl PayloadData {
198207
PayloadPropertyValue::FundingTimestamp(read_option_timestamp::<BO>(
199208
&mut reader,
200209
)?)
210+
} else if property == PriceFeedProperty::FundingRateInterval as u8 {
211+
PayloadPropertyValue::FundingRateInterval(read_option_interval::<BO>(
212+
&mut reader, )?)
201213
} else {
202214
bail!("unknown property");
203215
};
@@ -276,3 +288,30 @@ fn read_option_timestamp<BO: ByteOrder>(
276288
Ok(None)
277289
}
278290
}
291+
292+
fn write_option_duration<BO: ByteOrder>(
293+
mut writer: impl Write,
294+
value: Option<DurationUs>,
295+
) -> std::io::Result<()> {
296+
match value {
297+
Some(value) => {
298+
writer.write_u8(1)?;
299+
writer.write_u64::<BO>(value.as_micros())
300+
}
301+
None => {
302+
writer.write_u8(0)?;
303+
Ok(())
304+
}
305+
}
306+
}
307+
308+
fn read_option_interval<BO: ByteOrder>(
309+
mut reader: impl Read,
310+
) -> std::io::Result<Option<DurationUs>> {
311+
let present = reader.read_u8()? != 0;
312+
if present {
313+
Ok(Some(DurationUs::from_micros(reader.read_u64::<BO>()?)))
314+
} else {
315+
Ok(None)
316+
}
317+
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ pub enum PriceFeedProperty {
176176
FundingRate,
177177
FundingTimestamp,
178178
// More fields may be added later.
179+
FundingRateInterval,
179180
}
180181

181182
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
@@ -525,6 +526,9 @@ pub struct ParsedFeedPayload {
525526
#[serde(default)]
526527
pub funding_timestamp: Option<TimestampUs>,
527528
// More fields may be added later.
529+
#[serde(skip_serializing_if = "Option::is_none")]
530+
#[serde(default)]
531+
pub funding_rate_interval: Option<DurationUs>,
528532
}
529533

530534
impl ParsedFeedPayload {
@@ -544,6 +548,7 @@ impl ParsedFeedPayload {
544548
confidence: None,
545549
funding_rate: None,
546550
funding_timestamp: None,
551+
funding_rate_interval: None
547552
};
548553
for &property in properties {
549554
match property {
@@ -571,6 +576,9 @@ impl ParsedFeedPayload {
571576
PriceFeedProperty::FundingTimestamp => {
572577
output.funding_timestamp = data.funding_timestamp;
573578
}
579+
PriceFeedProperty::FundingRateInterval => {
580+
output.funding_rate_interval = data.funding_rate_interval;
581+
}
574582
}
575583
}
576584
output
@@ -591,6 +599,7 @@ impl ParsedFeedPayload {
591599
confidence: data.confidence,
592600
funding_rate: data.funding_rate,
593601
funding_timestamp: data.funding_timestamp,
602+
funding_rate_interval: data.funding_rate_interval,
594603
}
595604
}
596605
}

0 commit comments

Comments
 (0)