Skip to content

feat(pyth-lazer) Add funding_rate_interval to feed properties #2923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 4, 2025
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
26 changes: 13 additions & 13 deletions 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.10.1"
version = "0.10.2"
edition = "2021"
description = "Pyth Lazer SDK - protocol types."
license = "Apache-2.0"
Expand Down
41 changes: 41 additions & 0 deletions lazer/sdk/rust/protocol/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub enum PayloadPropertyValue {
Confidence(Option<Price>),
FundingRate(Option<Rate>),
FundingTimestamp(Option<TimestampUs>),
FundingRateInterval(Option<DurationUs>),
}

#[derive(Debug, Clone, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
Expand Down Expand Up @@ -99,6 +100,11 @@ impl PayloadData {
PriceFeedProperty::FundingTimestamp => {
PayloadPropertyValue::FundingTimestamp(feed.funding_timestamp)
}
PriceFeedProperty::FundingRateInterval => {
PayloadPropertyValue::FundingRateInterval(
feed.funding_rate_interval,
)
}
})
.collect(),
})
Expand Down Expand Up @@ -148,6 +154,10 @@ impl PayloadData {
writer.write_u8(PriceFeedProperty::FundingTimestamp as u8)?;
write_option_timestamp::<BO>(&mut writer, *timestamp)?;
}
&PayloadPropertyValue::FundingRateInterval(interval) => {
writer.write_u8(PriceFeedProperty::FundingRateInterval as u8)?;
write_option_duration::<BO>(&mut writer, interval)?;
}
}
}
}
Expand Down Expand Up @@ -198,6 +208,10 @@ impl PayloadData {
PayloadPropertyValue::FundingTimestamp(read_option_timestamp::<BO>(
&mut reader,
)?)
} else if property == PriceFeedProperty::FundingRateInterval as u8 {
PayloadPropertyValue::FundingRateInterval(read_option_interval::<BO>(
&mut reader,
)?)
} else {
bail!("unknown property");
};
Expand Down Expand Up @@ -276,3 +290,30 @@ fn read_option_timestamp<BO: ByteOrder>(
Ok(None)
}
}

fn write_option_duration<BO: ByteOrder>(
mut writer: impl Write,
value: Option<DurationUs>,
) -> std::io::Result<()> {
match value {
Some(value) => {
writer.write_u8(1)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of this 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The write protocol for options uses the first byte to indicate presence of the field.

writer.write_u64::<BO>(value.as_micros())
}
None => {
writer.write_u8(0)?;
Ok(())
}
}
}

fn read_option_interval<BO: ByteOrder>(
mut reader: impl Read,
) -> std::io::Result<Option<DurationUs>> {
let present = reader.read_u8()? != 0;
if present {
Ok(Some(DurationUs::from_micros(reader.read_u64::<BO>()?)))
} else {
Ok(None)
}
}
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 @@ -175,6 +175,7 @@ pub enum PriceFeedProperty {
Confidence,
FundingRate,
FundingTimestamp,
FundingRateInterval,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put the comment under this?

// More fields may be added later.
}

Expand Down Expand Up @@ -525,6 +526,9 @@ pub struct ParsedFeedPayload {
#[serde(default)]
pub funding_timestamp: Option<TimestampUs>,
// More fields may be added later.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub funding_rate_interval: Option<DurationUs>,
}

impl ParsedFeedPayload {
Expand All @@ -544,6 +548,7 @@ impl ParsedFeedPayload {
confidence: None,
funding_rate: None,
funding_timestamp: None,
funding_rate_interval: None,
};
for &property in properties {
match property {
Expand Down Expand Up @@ -571,6 +576,9 @@ impl ParsedFeedPayload {
PriceFeedProperty::FundingTimestamp => {
output.funding_timestamp = data.funding_timestamp;
}
PriceFeedProperty::FundingRateInterval => {
output.funding_rate_interval = data.funding_rate_interval;
}
}
}
output
Expand All @@ -591,6 +599,7 @@ impl ParsedFeedPayload {
confidence: data.confidence,
funding_rate: data.funding_rate,
funding_timestamp: data.funding_timestamp,
funding_rate_interval: data.funding_rate_interval,
}
}
}