Skip to content
Merged
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions lazer/publisher_sdk/proto/publisher_update.proto
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
syntax = "proto3";
package pyth_lazer;

import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";

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

// [optional] perpetual future funding rate
optional int64 rate = 2;

// [optional] funding rate update interval
optional google.protobuf.Duration funding_rate_interval = 3;
}
2 changes: 2 additions & 0 deletions lazer/publisher_sdk/proto/state.proto
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,6 @@ message FeedData {
optional int64 best_ask_price = 5;
// [optional] Funding rate. Can be absent if no data is available. Can only be present for funding rate feeds.
optional int64 funding_rate = 6;
// [optional] Funding rate interval. Can be absent if no data is available. Can only be present for funding rate feeds.
optional google.protobuf.Duration funding_rate_interval = 7;
}
2 changes: 1 addition & 1 deletion lazer/publisher_sdk/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pyth-lazer-publisher-sdk"
version = "0.2.1"
version = "0.3.0"
edition = "2021"
description = "Pyth Lazer Publisher SDK types."
license = "Apache-2.0"
Expand Down
34 changes: 20 additions & 14 deletions lazer/publisher_sdk/rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::publisher_update::feed_update::Update;
use crate::publisher_update::{FeedUpdate, FundingRateUpdate, PriceUpdate};
use crate::state::FeedState;
use ::protobuf::MessageField;
use pyth_lazer_protocol::jrpc::{FeedUpdateParams, UpdateParams};
use pyth_lazer_protocol::symbol_state::SymbolState;
use pyth_lazer_protocol::FeedKind;
Expand Down Expand Up @@ -60,13 +61,18 @@ impl From<UpdateParams> for Update {
best_ask_price: best_ask_price.map(|p| p.0.into()),
special_fields: Default::default(),
}),
UpdateParams::FundingRateUpdate { price, rate } => {
Update::FundingRateUpdate(FundingRateUpdate {
price: price.map(|p| p.0.into()),
rate: Some(rate.0),
special_fields: Default::default(),
})
}
UpdateParams::FundingRateUpdate {
price,
rate,
funding_rate_interval,
} => Update::FundingRateUpdate(FundingRateUpdate {
price: price.map(|p| p.0.into()),
rate: Some(rate.0),
funding_rate_interval: MessageField::from_option(
funding_rate_interval.map(|i| i.into()),
),
special_fields: Default::default(),
}),
}
}
}
Expand All @@ -91,20 +97,20 @@ impl From<SymbolState> for FeedState {
}
}

impl From<FeedKind> for protobuf::state::FeedKind {
impl From<FeedKind> for state::FeedKind {
fn from(value: FeedKind) -> Self {
match value {
FeedKind::Price => protobuf::state::FeedKind::PRICE,
FeedKind::FundingRate => protobuf::state::FeedKind::FUNDING_RATE,
FeedKind::Price => state::FeedKind::PRICE,
FeedKind::FundingRate => state::FeedKind::FUNDING_RATE,
}
}
}

impl From<protobuf::state::FeedKind> for FeedKind {
fn from(value: protobuf::state::FeedKind) -> Self {
impl From<state::FeedKind> for FeedKind {
fn from(value: state::FeedKind) -> Self {
match value {
protobuf::state::FeedKind::PRICE => FeedKind::Price,
protobuf::state::FeedKind::FUNDING_RATE => FeedKind::FundingRate,
state::FeedKind::PRICE => FeedKind::Price,
state::FeedKind::FUNDING_RATE => FeedKind::FundingRate,
}
}
}
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.0"
version = "0.10.1"
edition = "2021"
description = "Pyth Lazer SDK - protocol types."
license = "Apache-2.0"
Expand Down
16 changes: 14 additions & 2 deletions lazer/sdk/rust/protocol/src/jrpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,16 @@ pub enum UpdateParams {
best_ask_price: Option<Price>,
},
#[serde(rename = "funding_rate")]
FundingRateUpdate { price: Option<Price>, rate: Rate },
FundingRateUpdate {
price: Option<Price>,
rate: Rate,
#[serde(default = "default_funding_rate_interval", with = "humantime_serde")]
funding_rate_interval: Option<Duration>,
},
}

fn default_funding_rate_interval() -> Option<Duration> {
None
}

#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
Expand Down Expand Up @@ -273,7 +282,8 @@ mod tests {
"update": {
"type": "funding_rate",
"price": 1234567890,
"rate": 1234567891
"rate": 1234567891,
"funding_rate_interval": "8h"
}
},
"id": 1
Expand All @@ -288,6 +298,7 @@ mod tests {
update: UpdateParams::FundingRateUpdate {
price: Some(Price::from_integer(1234567890, 0).unwrap()),
rate: Rate::from_integer(1234567891, 0).unwrap(),
funding_rate_interval: Duration::from_secs(28800).into(),
},
}),
id: Some(1),
Expand Down Expand Up @@ -325,6 +336,7 @@ mod tests {
update: UpdateParams::FundingRateUpdate {
price: None,
rate: Rate::from_integer(1234567891, 0).unwrap(),
funding_rate_interval: None,
},
}),
id: Some(1),
Expand Down
2 changes: 2 additions & 0 deletions lazer/sdk/rust/protocol/src/payload.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Types representing binary encoding of signable payloads and signature envelopes.

use crate::time::DurationUs;
use {
super::router::{PriceFeedId, PriceFeedProperty},
crate::{
Expand Down Expand Up @@ -52,6 +53,7 @@ pub struct AggregatedPriceFeedData {
pub confidence: Option<Price>,
pub funding_rate: Option<Rate>,
pub funding_timestamp: Option<TimestampUs>,
pub funding_rate_interval: Option<DurationUs>,
}

/// First bytes of a payload's encoding
Expand Down