Skip to content

Commit 2abe3e0

Browse files
authored
feat(pyth-lazer) Add funding_rate_interval to feed properties (#2923)
1 parent b9ad8f2 commit 2abe3e0

File tree

4 files changed

+64
-14
lines changed

4 files changed

+64
-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: 41 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)]
@@ -99,6 +100,11 @@ impl PayloadData {
99100
PriceFeedProperty::FundingTimestamp => {
100101
PayloadPropertyValue::FundingTimestamp(feed.funding_timestamp)
101102
}
103+
PriceFeedProperty::FundingRateInterval => {
104+
PayloadPropertyValue::FundingRateInterval(
105+
feed.funding_rate_interval,
106+
)
107+
}
102108
})
103109
.collect(),
104110
})
@@ -148,6 +154,10 @@ impl PayloadData {
148154
writer.write_u8(PriceFeedProperty::FundingTimestamp as u8)?;
149155
write_option_timestamp::<BO>(&mut writer, *timestamp)?;
150156
}
157+
&PayloadPropertyValue::FundingRateInterval(interval) => {
158+
writer.write_u8(PriceFeedProperty::FundingRateInterval as u8)?;
159+
write_option_duration::<BO>(&mut writer, interval)?;
160+
}
151161
}
152162
}
153163
}
@@ -198,6 +208,10 @@ impl PayloadData {
198208
PayloadPropertyValue::FundingTimestamp(read_option_timestamp::<BO>(
199209
&mut reader,
200210
)?)
211+
} else if property == PriceFeedProperty::FundingRateInterval as u8 {
212+
PayloadPropertyValue::FundingRateInterval(read_option_interval::<BO>(
213+
&mut reader,
214+
)?)
201215
} else {
202216
bail!("unknown property");
203217
};
@@ -276,3 +290,30 @@ fn read_option_timestamp<BO: ByteOrder>(
276290
Ok(None)
277291
}
278292
}
293+
294+
fn write_option_duration<BO: ByteOrder>(
295+
mut writer: impl Write,
296+
value: Option<DurationUs>,
297+
) -> std::io::Result<()> {
298+
match value {
299+
Some(value) => {
300+
writer.write_u8(1)?;
301+
writer.write_u64::<BO>(value.as_micros())
302+
}
303+
None => {
304+
writer.write_u8(0)?;
305+
Ok(())
306+
}
307+
}
308+
}
309+
310+
fn read_option_interval<BO: ByteOrder>(
311+
mut reader: impl Read,
312+
) -> std::io::Result<Option<DurationUs>> {
313+
let present = reader.read_u8()? != 0;
314+
if present {
315+
Ok(Some(DurationUs::from_micros(reader.read_u64::<BO>()?)))
316+
} else {
317+
Ok(None)
318+
}
319+
}

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

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

@@ -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)