Skip to content

Commit 807b934

Browse files
authored
feat(pyth-lazer) Add support for FundingRateInterval in lazer protos (#2891)
1 parent 305309c commit 807b934

File tree

8 files changed

+48
-22
lines changed

8 files changed

+48
-22
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lazer/publisher_sdk/proto/publisher_update.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
syntax = "proto3";
22
package pyth_lazer;
33

4+
import "google/protobuf/duration.proto";
45
import "google/protobuf/timestamp.proto";
56

67
// if any fields marked as [required] are missing, feed/publisher update will be rejected
@@ -59,4 +60,7 @@ message FundingRateUpdate {
5960

6061
// [optional] perpetual future funding rate
6162
optional int64 rate = 2;
63+
64+
// [optional] funding rate update interval
65+
optional google.protobuf.Duration funding_rate_interval = 3;
6266
}

lazer/publisher_sdk/proto/state.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,6 @@ message FeedData {
152152
optional int64 best_ask_price = 5;
153153
// [optional] Funding rate. Can be absent if no data is available. Can only be present for funding rate feeds.
154154
optional int64 funding_rate = 6;
155+
// [optional] Funding rate interval. Can be absent if no data is available. Can only be present for funding rate feeds.
156+
optional google.protobuf.Duration funding_rate_interval = 7;
155157
}

lazer/publisher_sdk/rust/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-publisher-sdk"
3-
version = "0.2.1"
3+
version = "0.3.0"
44
edition = "2021"
55
description = "Pyth Lazer Publisher SDK types."
66
license = "Apache-2.0"

lazer/publisher_sdk/rust/src/lib.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::publisher_update::feed_update::Update;
22
use crate::publisher_update::{FeedUpdate, FundingRateUpdate, PriceUpdate};
33
use crate::state::FeedState;
4+
use ::protobuf::MessageField;
45
use pyth_lazer_protocol::jrpc::{FeedUpdateParams, UpdateParams};
56
use pyth_lazer_protocol::symbol_state::SymbolState;
67
use pyth_lazer_protocol::FeedKind;
@@ -60,13 +61,18 @@ impl From<UpdateParams> for Update {
6061
best_ask_price: best_ask_price.map(|p| p.0.into()),
6162
special_fields: Default::default(),
6263
}),
63-
UpdateParams::FundingRateUpdate { price, rate } => {
64-
Update::FundingRateUpdate(FundingRateUpdate {
65-
price: price.map(|p| p.0.into()),
66-
rate: Some(rate.0),
67-
special_fields: Default::default(),
68-
})
69-
}
64+
UpdateParams::FundingRateUpdate {
65+
price,
66+
rate,
67+
funding_rate_interval,
68+
} => Update::FundingRateUpdate(FundingRateUpdate {
69+
price: price.map(|p| p.0.into()),
70+
rate: Some(rate.0),
71+
funding_rate_interval: MessageField::from_option(
72+
funding_rate_interval.map(|i| i.into()),
73+
),
74+
special_fields: Default::default(),
75+
}),
7076
}
7177
}
7278
}
@@ -91,20 +97,20 @@ impl From<SymbolState> for FeedState {
9197
}
9298
}
9399

94-
impl From<FeedKind> for protobuf::state::FeedKind {
100+
impl From<FeedKind> for state::FeedKind {
95101
fn from(value: FeedKind) -> Self {
96102
match value {
97-
FeedKind::Price => protobuf::state::FeedKind::PRICE,
98-
FeedKind::FundingRate => protobuf::state::FeedKind::FUNDING_RATE,
103+
FeedKind::Price => state::FeedKind::PRICE,
104+
FeedKind::FundingRate => state::FeedKind::FUNDING_RATE,
99105
}
100106
}
101107
}
102108

103-
impl From<protobuf::state::FeedKind> for FeedKind {
104-
fn from(value: protobuf::state::FeedKind) -> Self {
109+
impl From<state::FeedKind> for FeedKind {
110+
fn from(value: state::FeedKind) -> Self {
105111
match value {
106-
protobuf::state::FeedKind::PRICE => FeedKind::Price,
107-
protobuf::state::FeedKind::FUNDING_RATE => FeedKind::FundingRate,
112+
state::FeedKind::PRICE => FeedKind::Price,
113+
state::FeedKind::FUNDING_RATE => FeedKind::FundingRate,
108114
}
109115
}
110116
}

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.0"
3+
version = "0.10.1"
44
edition = "2021"
55
description = "Pyth Lazer SDK - protocol types."
66
license = "Apache-2.0"

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,16 @@ pub enum UpdateParams {
3737
best_ask_price: Option<Price>,
3838
},
3939
#[serde(rename = "funding_rate")]
40-
FundingRateUpdate { price: Option<Price>, rate: Rate },
40+
FundingRateUpdate {
41+
price: Option<Price>,
42+
rate: Rate,
43+
#[serde(default = "default_funding_rate_interval", with = "humantime_serde")]
44+
funding_rate_interval: Option<Duration>,
45+
},
46+
}
47+
48+
fn default_funding_rate_interval() -> Option<Duration> {
49+
None
4150
}
4251

4352
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
@@ -273,7 +282,8 @@ mod tests {
273282
"update": {
274283
"type": "funding_rate",
275284
"price": 1234567890,
276-
"rate": 1234567891
285+
"rate": 1234567891,
286+
"funding_rate_interval": "8h"
277287
}
278288
},
279289
"id": 1
@@ -288,6 +298,7 @@ mod tests {
288298
update: UpdateParams::FundingRateUpdate {
289299
price: Some(Price::from_integer(1234567890, 0).unwrap()),
290300
rate: Rate::from_integer(1234567891, 0).unwrap(),
301+
funding_rate_interval: Duration::from_secs(28800).into(),
291302
},
292303
}),
293304
id: Some(1),
@@ -325,6 +336,7 @@ mod tests {
325336
update: UpdateParams::FundingRateUpdate {
326337
price: None,
327338
rate: Rate::from_integer(1234567891, 0).unwrap(),
339+
funding_rate_interval: None,
328340
},
329341
}),
330342
id: Some(1),

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Types representing binary encoding of signable payloads and signature envelopes.
22
3+
use crate::time::DurationUs;
34
use {
45
super::router::{PriceFeedId, PriceFeedProperty},
56
crate::{
@@ -52,6 +53,7 @@ pub struct AggregatedPriceFeedData {
5253
pub confidence: Option<Price>,
5354
pub funding_rate: Option<Rate>,
5455
pub funding_timestamp: Option<TimestampUs>,
56+
pub funding_rate_interval: Option<DurationUs>,
5557
}
5658

5759
/// First bytes of a payload's encoding

0 commit comments

Comments
 (0)