Skip to content
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
10 changes: 5 additions & 5 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ no-log-ix-name = []
idl-build = ["anchor-lang/idl-build"]

[dependencies]
pyth-lazer-protocol = { path = "../../../../sdk/rust/protocol", version = "0.16.0" }
pyth-lazer-protocol = { path = "../../../../sdk/rust/protocol", version = "0.17.0" }

anchor-lang = "0.31.1"
bytemuck = { version = "1.20.0", features = ["derive"] }
Expand Down
4 changes: 2 additions & 2 deletions lazer/publisher_sdk/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "pyth-lazer-publisher-sdk"
version = "0.14.0"
version = "0.15.0"
edition = "2021"
description = "Pyth Lazer Publisher SDK types."
license = "Apache-2.0"
repository = "https://github.com/pyth-network/pyth-crosschain"

[dependencies]
pyth-lazer-protocol = { version = "0.16.0", path = "../../sdk/rust/protocol" }
pyth-lazer-protocol = { version = "0.17.0", path = "../../sdk/rust/protocol" }
anyhow = "1.0.98"
protobuf = "3.7.2"
serde_json = "1.0.140"
Expand Down
4 changes: 2 additions & 2 deletions lazer/sdk/rust/client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "pyth-lazer-client"
version = "8.2.2"
version = "8.3.0"
edition = "2021"
description = "A Rust client for Pyth Lazer"
license = "Apache-2.0"

[dependencies]
pyth-lazer-protocol = { path = "../protocol", version = "0.16.0" }
pyth-lazer-protocol = { path = "../protocol", version = "0.17.0" }
tokio = { version = "1", features = ["full"] }
tokio-tungstenite = { version = "0.20", features = ["native-tls"] }
futures-util = "0.3"
Expand Down
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.16.0"
version = "0.17.0"
edition = "2021"
description = "Pyth Lazer SDK - protocol types."
license = "Apache-2.0"
Expand Down
108 changes: 100 additions & 8 deletions lazer/sdk/rust/protocol/src/jrpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,22 @@ use crate::{api::Channel, price::Price};
use serde::{Deserialize, Serialize};
use std::time::Duration;

#[derive(Serialize, Deserialize, Debug, Default, Eq, PartialEq)]
#[serde(untagged)]
pub enum JrpcId {
String(String),
Int(i64),
#[default]
Null,
}

#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
pub struct PythLazerAgentJrpcV1 {
pub jsonrpc: JsonRpcVersion,
#[serde(flatten)]
pub params: JrpcCall,
pub id: Option<i64>,
#[serde(default)]
pub id: JrpcId,
}

#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
Expand Down Expand Up @@ -184,7 +194,89 @@ mod tests {
best_ask_price: Some(Price::from_integer(1234567892, 0).unwrap()),
},
}),
id: Some(1),
id: JrpcId::Int(1),
};

assert_eq!(
serde_json::from_str::<PythLazerAgentJrpcV1>(json).unwrap(),
expected
);
}

#[test]
fn test_push_update_price_string_id() {
let json = r#"
{
"jsonrpc": "2.0",
"method": "push_update",
"params": {
"feed_id": 1,
"source_timestamp": 124214124124,

"update": {
"type": "price",
"price": 1234567890,
"best_bid_price": 1234567891,
"best_ask_price": 1234567892
}
},
"id": "b6bb54a0-ea8d-439d-97a7-3b06befa0e76"
}
"#;

let expected = PythLazerAgentJrpcV1 {
jsonrpc: JsonRpcVersion::V2,
params: PushUpdate(FeedUpdateParams {
feed_id: PriceFeedId(1),
source_timestamp: TimestampUs::from_micros(124214124124),
update: UpdateParams::PriceUpdate {
price: Price::from_integer(1234567890, 0).unwrap(),
best_bid_price: Some(Price::from_integer(1234567891, 0).unwrap()),
best_ask_price: Some(Price::from_integer(1234567892, 0).unwrap()),
},
}),
id: JrpcId::String("b6bb54a0-ea8d-439d-97a7-3b06befa0e76".to_string()),
};

assert_eq!(
serde_json::from_str::<PythLazerAgentJrpcV1>(json).unwrap(),
expected
);
}

#[test]
fn test_push_update_price_null_id() {
let json = r#"
{
"jsonrpc": "2.0",
"method": "push_update",
"params": {
"feed_id": 1,
"source_timestamp": 124214124124,

"update": {
"type": "price",
"price": 1234567890,
"best_bid_price": 1234567891,
"best_ask_price": 1234567892
}
},
"id": null
}
"#;

let expected = PythLazerAgentJrpcV1 {
jsonrpc: JsonRpcVersion::V2,
params: PushUpdate(FeedUpdateParams {
feed_id: PriceFeedId(1),
source_timestamp: TimestampUs::from_micros(124214124124),
update: UpdateParams::PriceUpdate {
price: Price::from_integer(1234567890, 0).unwrap(),
best_bid_price: Some(Price::from_integer(1234567891, 0).unwrap()),
best_ask_price: Some(Price::from_integer(1234567892, 0).unwrap()),
},
}),
id: JrpcId::Null,
};

assert_eq!(
Expand Down Expand Up @@ -224,7 +316,7 @@ mod tests {
best_ask_price: Some(Price::from_integer(5432, 0).unwrap()),
},
}),
id: None,
id: JrpcId::Null,
};

assert_eq!(
Expand Down Expand Up @@ -263,7 +355,7 @@ mod tests {
best_ask_price: None,
},
}),
id: Some(1),
id: JrpcId::Int(1),
};

assert_eq!(
Expand Down Expand Up @@ -304,7 +396,7 @@ mod tests {
funding_rate_interval: Duration::from_secs(28800).into(),
},
}),
id: Some(1),
id: JrpcId::Int(1),
};

assert_eq!(
Expand Down Expand Up @@ -342,7 +434,7 @@ mod tests {
funding_rate_interval: None,
},
}),
id: Some(1),
id: JrpcId::Int(1),
};

assert_eq!(
Expand Down Expand Up @@ -371,7 +463,7 @@ mod tests {
names: Some(vec!["BTC/USD".to_string()]),
asset_types: Some(vec!["crypto".to_string()]),
}),
id: Some(1),
id: JrpcId::Int(1),
};

assert_eq!(
Expand All @@ -397,7 +489,7 @@ mod tests {
names: None,
asset_types: None,
}),
id: Some(1),
id: JrpcId::Int(1),
};

assert_eq!(
Expand Down