Skip to content

Commit 438e1de

Browse files
authored
Add market session to lazer (#3197)
1 parent 35c90ab commit 438e1de

File tree

10 files changed

+87
-17
lines changed

10 files changed

+87
-17
lines changed

Cargo.lock

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

lazer/contracts/solana/programs/pyth-lazer-solana-contract/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ no-log-ix-name = []
1919
idl-build = ["anchor-lang/idl-build"]
2020

2121
[dependencies]
22-
pyth-lazer-protocol = { path = "../../../../sdk/rust/protocol", version = "0.22.0" }
22+
pyth-lazer-protocol = { path = "../../../../sdk/rust/protocol", version = "0.23.0" }
2323

2424
anchor-lang = "0.31.1"
2525
bytemuck = { version = "1.20.0", features = ["derive"] }

lazer/publisher_sdk/proto/governance_instruction.proto

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,15 @@ message AddFeed {
269269
optional Channel min_channel = 104;
270270
// [required]
271271
optional google.protobuf.Duration expiry_time = 105;
272-
// [required]
273-
optional string market_schedule = 106;
272+
// [optional]
273+
optional string market_schedule = 106 [deprecated = true];
274274
// [required]
275275
optional FeedState state = 107;
276276
// [required]
277277
optional FeedKind kind = 108;
278278
// [required]
279+
repeated FeedMarketSchedule market_schedules = 109;
280+
// [required]
279281
optional bool is_enabled_in_shard = 201;
280282

281283
// TODO: IDs of publishers enabled for this feed.
@@ -317,12 +319,16 @@ message UpdateFeedProperties {
317319
// [optional]
318320
optional google.protobuf.Duration expiry_time = 105;
319321
// [optional]
320-
optional string market_schedule = 106;
322+
optional string market_schedule = 106 [deprecated = true];
321323
// [optional]
322324
optional FeedState state = 107;
323325
// [required]
324326
optional FeedKind kind = 108;
325327
// [optional]
328+
// While proto does not allow distinguishing between "not set" and "set to empty",
329+
// an empty list here means to not update the market schedules.
330+
repeated FeedMarketSchedule market_schedules = 109;
331+
// [optional]
326332
optional bool is_enabled_in_shard = 201;
327333
}
328334

lazer/publisher_sdk/proto/state.proto

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,23 @@ enum FeedKind {
8787
FUNDING_RATE = 1;
8888
}
8989

90+
// Market session type
91+
enum MarketSession {
92+
REGULAR = 0;
93+
PRE_MARKET = 1;
94+
POST_MARKET = 2;
95+
OVER_NIGHT = 3;
96+
}
97+
98+
message FeedMarketSchedule {
99+
// [required] Which session this applies to
100+
optional MarketSession session = 1;
101+
// [optional] numeric value. If not set, minimum publishers from the feed level apply
102+
optional int32 min_publishers = 2;
103+
// [required] Future field — not required now, can be omitted
104+
optional string market_schedule = 3;
105+
}
106+
90107
// An item of the state describing a feed.
91108
message Feed {
92109
// [required] ID of the feed.
@@ -120,6 +137,9 @@ message Feed {
120137
optional FeedKind kind = 108;
121138
// [required] Current aggregated data of the feed.
122139
optional FeedAggregateData aggregated_data = 109;
140+
// [optional] List of Market schedules for different sessions
141+
// Overrides market_schedule field if set
142+
repeated FeedMarketSchedule market_schedules = 110;
123143

124144
// [required] Feed status in the current shard. Disabled feeds will not be visible in
125145
// the consumer API for the current shard. This setting should only be used
@@ -199,6 +219,8 @@ message FeedAggregateData {
199219
// Actual value is `mantissa * 10 ^ exponent`.
200220
// Restricted to int16.
201221
optional int32 exponent = 9;
222+
// [optional] Market session for the feed. Can be absent if no data is available.
223+
optional MarketSession market_session = 10;
202224
}
203225

204226
// An item of the state describing an asset.

lazer/publisher_sdk/rust/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[package]
22
name = "pyth-lazer-publisher-sdk"
3-
version = "0.22.0"
3+
version = "0.23.0"
44
edition = "2021"
55
description = "Pyth Lazer Publisher SDK types."
66
license = "Apache-2.0"
77
repository = "https://github.com/pyth-network/pyth-crosschain"
88

99
[dependencies]
10-
pyth-lazer-protocol = { version = "0.22.0", path = "../../sdk/rust/protocol" }
10+
pyth-lazer-protocol = { version = "0.23.0", path = "../../sdk/rust/protocol" }
1111
anyhow = "1.0.98"
1212
protobuf = "3.7.2"
1313
serde_json = "1.0.140"

lazer/publisher_sdk/rust/src/lib.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,29 @@ impl From<pyth_lazer_protocol::api::Channel> for state::Channel {
147147
result
148148
}
149149
}
150+
151+
impl From<pyth_lazer_protocol::api::MarketSession> for state::MarketSession {
152+
fn from(value: pyth_lazer_protocol::api::MarketSession) -> Self {
153+
match value {
154+
pyth_lazer_protocol::api::MarketSession::Regular => state::MarketSession::REGULAR,
155+
pyth_lazer_protocol::api::MarketSession::PreMarket => state::MarketSession::PRE_MARKET,
156+
pyth_lazer_protocol::api::MarketSession::PostMarket => {
157+
state::MarketSession::POST_MARKET
158+
}
159+
pyth_lazer_protocol::api::MarketSession::OverNight => state::MarketSession::OVER_NIGHT,
160+
}
161+
}
162+
}
163+
164+
impl From<state::MarketSession> for pyth_lazer_protocol::api::MarketSession {
165+
fn from(value: state::MarketSession) -> Self {
166+
match value {
167+
state::MarketSession::REGULAR => pyth_lazer_protocol::api::MarketSession::Regular,
168+
state::MarketSession::PRE_MARKET => pyth_lazer_protocol::api::MarketSession::PreMarket,
169+
state::MarketSession::POST_MARKET => {
170+
pyth_lazer_protocol::api::MarketSession::PostMarket
171+
}
172+
state::MarketSession::OVER_NIGHT => pyth_lazer_protocol::api::MarketSession::OverNight,
173+
}
174+
}
175+
}

lazer/sdk/rust/client/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[package]
22
name = "pyth-lazer-client"
3-
version = "11.0.0"
3+
version = "12.0.0"
44
edition = "2021"
55
description = "A Rust client for Pyth Lazer"
66
license = "Apache-2.0"
77

88
[dependencies]
9-
pyth-lazer-protocol = { path = "../protocol", version = "0.22.0" }
10-
pyth-lazer-publisher-sdk = { path = "../../../publisher_sdk/rust", version = "0.22.0" }
9+
pyth-lazer-protocol = { path = "../protocol", version = "0.23.0" }
10+
pyth-lazer-publisher-sdk = { path = "../../../publisher_sdk/rust", version = "0.23.0" }
1111

1212
tokio = { version = "1", features = ["full"] }
1313
tokio-stream = "0.1.17"

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

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,3 +650,16 @@ fn validate_formats(formats: &[Format]) -> Result<(), &'static str> {
650650
}
651651
Ok(())
652652
}
653+
654+
#[derive(
655+
Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash, From, ToSchema, Default,
656+
)]
657+
#[serde(rename_all = "camelCase")]
658+
#[schema(example = "regular")]
659+
pub enum MarketSession {
660+
#[default]
661+
Regular,
662+
PreMarket,
663+
PostMarket,
664+
OverNight,
665+
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::{
2+
api::MarketSession,
23
price::Price,
34
rate::Rate,
45
time::{DurationUs, TimestampUs},
@@ -54,10 +55,11 @@ pub struct AggregatedPriceFeedData {
5455
pub funding_rate: Option<Rate>,
5556
pub funding_timestamp: Option<TimestampUs>,
5657
pub funding_rate_interval: Option<DurationUs>,
58+
pub market_session: Option<MarketSession>,
5759
}
5860

5961
impl AggregatedPriceFeedData {
60-
pub fn empty(exponent: i16) -> Self {
62+
pub fn empty(exponent: i16, market_session: Option<MarketSession>) -> Self {
6163
Self {
6264
price: None,
6365
best_bid_price: None,
@@ -68,6 +70,7 @@ impl AggregatedPriceFeedData {
6870
funding_rate: None,
6971
funding_timestamp: None,
7072
funding_rate_interval: None,
73+
market_session,
7174
}
7275
}
7376
}

0 commit comments

Comments
 (0)