diff --git a/Cargo.lock b/Cargo.lock index b1da1acf7e..92da28cdb6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5666,7 +5666,7 @@ dependencies = [ "futures-util", "hex", "libsecp256k1 0.7.2", - "pyth-lazer-protocol 0.10.0", + "pyth-lazer-protocol 0.10.1", "serde", "serde_json", "tokio", @@ -5696,7 +5696,7 @@ dependencies = [ [[package]] name = "pyth-lazer-protocol" -version = "0.10.0" +version = "0.10.1" dependencies = [ "alloy-primitives 0.8.25", "anyhow", @@ -5736,13 +5736,13 @@ dependencies = [ [[package]] name = "pyth-lazer-publisher-sdk" -version = "0.2.1" +version = "0.3.0" dependencies = [ "anyhow", "fs-err", "protobuf", "protobuf-codegen", - "pyth-lazer-protocol 0.10.0", + "pyth-lazer-protocol 0.10.1", "serde_json", ] diff --git a/lazer/publisher_sdk/proto/publisher_update.proto b/lazer/publisher_sdk/proto/publisher_update.proto index 6bf249ce8d..8c752c17aa 100644 --- a/lazer/publisher_sdk/proto/publisher_update.proto +++ b/lazer/publisher_sdk/proto/publisher_update.proto @@ -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 @@ -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; } diff --git a/lazer/publisher_sdk/proto/state.proto b/lazer/publisher_sdk/proto/state.proto index b13569e211..2cd512c749 100644 --- a/lazer/publisher_sdk/proto/state.proto +++ b/lazer/publisher_sdk/proto/state.proto @@ -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; } diff --git a/lazer/publisher_sdk/rust/Cargo.toml b/lazer/publisher_sdk/rust/Cargo.toml index 4d85f56c3b..a0d78ff311 100644 --- a/lazer/publisher_sdk/rust/Cargo.toml +++ b/lazer/publisher_sdk/rust/Cargo.toml @@ -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" diff --git a/lazer/publisher_sdk/rust/src/lib.rs b/lazer/publisher_sdk/rust/src/lib.rs index 81ac139ed0..ae98a79c39 100644 --- a/lazer/publisher_sdk/rust/src/lib.rs +++ b/lazer/publisher_sdk/rust/src/lib.rs @@ -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; @@ -60,13 +61,18 @@ impl From 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(), + }), } } } @@ -91,20 +97,20 @@ impl From for FeedState { } } -impl From for protobuf::state::FeedKind { +impl From 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 for FeedKind { - fn from(value: protobuf::state::FeedKind) -> Self { +impl From 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, } } } diff --git a/lazer/sdk/rust/protocol/Cargo.toml b/lazer/sdk/rust/protocol/Cargo.toml index 2ba075e1a6..52cce03af0 100644 --- a/lazer/sdk/rust/protocol/Cargo.toml +++ b/lazer/sdk/rust/protocol/Cargo.toml @@ -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" diff --git a/lazer/sdk/rust/protocol/src/jrpc.rs b/lazer/sdk/rust/protocol/src/jrpc.rs index ff01907535..ceb7704f22 100644 --- a/lazer/sdk/rust/protocol/src/jrpc.rs +++ b/lazer/sdk/rust/protocol/src/jrpc.rs @@ -37,7 +37,16 @@ pub enum UpdateParams { best_ask_price: Option, }, #[serde(rename = "funding_rate")] - FundingRateUpdate { price: Option, rate: Rate }, + FundingRateUpdate { + price: Option, + rate: Rate, + #[serde(default = "default_funding_rate_interval", with = "humantime_serde")] + funding_rate_interval: Option, + }, +} + +fn default_funding_rate_interval() -> Option { + None } #[derive(Serialize, Deserialize, Debug, Eq, PartialEq)] @@ -273,7 +282,8 @@ mod tests { "update": { "type": "funding_rate", "price": 1234567890, - "rate": 1234567891 + "rate": 1234567891, + "funding_rate_interval": "8h" } }, "id": 1 @@ -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), @@ -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), diff --git a/lazer/sdk/rust/protocol/src/payload.rs b/lazer/sdk/rust/protocol/src/payload.rs index fbe622b902..8506183995 100644 --- a/lazer/sdk/rust/protocol/src/payload.rs +++ b/lazer/sdk/rust/protocol/src/payload.rs @@ -1,5 +1,6 @@ //! Types representing binary encoding of signable payloads and signature envelopes. +use crate::time::DurationUs; use { super::router::{PriceFeedId, PriceFeedProperty}, crate::{ @@ -52,6 +53,7 @@ pub struct AggregatedPriceFeedData { pub confidence: Option, pub funding_rate: Option, pub funding_timestamp: Option, + pub funding_rate_interval: Option, } /// First bytes of a payload's encoding