Skip to content

Revert "feat(lazer): improve protocol types and modules" #2947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 12, 2025
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
18 changes: 5 additions & 13 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
@@ -1,6 +1,6 @@
[package]
name = "pyth-lazer-solana-contract"
version = "0.6.0"
version = "0.5.0"
edition = "2021"
description = "Pyth Lazer Solana contract and SDK."
license = "Apache-2.0"
Expand All @@ -19,7 +19,7 @@ no-log-ix-name = []
idl-build = ["anchor-lang/idl-build"]

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

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.6.0"
version = "0.5.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.11.0", path = "../../sdk/rust/protocol" }
pyth-lazer-protocol = { version = "0.10.2", path = "../../sdk/rust/protocol" }
anyhow = "1.0.98"
protobuf = "3.7.2"
serde_json = "1.0.140"
Expand Down
12 changes: 6 additions & 6 deletions lazer/publisher_sdk/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ 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;
use pyth_lazer_protocol::SymbolState;

pub mod transaction_envelope {
pub use crate::protobuf::transaction_envelope::*;
Expand Down Expand Up @@ -56,18 +56,18 @@ impl From<UpdateParams> for Update {
best_bid_price,
best_ask_price,
} => Update::PriceUpdate(PriceUpdate {
price: Some(price.mantissa_i64()),
best_bid_price: best_bid_price.map(|p| p.mantissa_i64()),
best_ask_price: best_ask_price.map(|p| p.mantissa_i64()),
price: Some(price.0.into()),
best_bid_price: best_bid_price.map(|p| p.0.into()),
best_ask_price: best_ask_price.map(|p| p.0.into()),
special_fields: Default::default(),
}),
UpdateParams::FundingRateUpdate {
price,
rate,
funding_rate_interval,
} => Update::FundingRateUpdate(FundingRateUpdate {
price: price.map(|p| p.mantissa_i64()),
rate: Some(rate.mantissa()),
price: price.map(|p| p.0.into()),
rate: Some(rate.0),
funding_rate_interval: MessageField::from_option(
funding_rate_interval.map(|i| i.into()),
),
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 = "3.0.0"
version = "2.0.1"
edition = "2021"
description = "A Rust client for Pyth Lazer"
license = "Apache-2.0"

[dependencies]
pyth-lazer-protocol = { path = "../protocol", version = "0.11.0" }
pyth-lazer-protocol = { path = "../protocol", version = "0.10.2" }
tokio = { version = "1", features = ["full"] }
tokio-tungstenite = { version = "0.20", features = ["native-tls"] }
futures-util = "0.3"
Expand Down
13 changes: 6 additions & 7 deletions lazer/sdk/rust/client/examples/subscribe_price_feeds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ use base64::Engine;
use pyth_lazer_client::backoff::PythLazerExponentialBackoffBuilder;
use pyth_lazer_client::client::PythLazerClientBuilder;
use pyth_lazer_client::ws_connection::AnyResponse;
use pyth_lazer_protocol::api::{
Channel, DeliveryFormat, Format, JsonBinaryEncoding, SubscriptionParams, SubscriptionParamsRepr,
};
use pyth_lazer_protocol::api::{SubscribeRequest, SubscriptionId, WsResponse};
use pyth_lazer_protocol::message::{
EvmMessage, LeEcdsaMessage, LeUnsignedMessage, Message, SolanaMessage,
};
use pyth_lazer_protocol::payload::PayloadData;
use pyth_lazer_protocol::time::FixedRate;
use pyth_lazer_protocol::{PriceFeedId, PriceFeedProperty};
use pyth_lazer_protocol::router::{
Channel, DeliveryFormat, FixedRate, Format, JsonBinaryEncoding, PriceFeedId, PriceFeedProperty,
SubscriptionParams, SubscriptionParamsRepr,
};
use pyth_lazer_protocol::subscription::{Response, SubscribeRequest, SubscriptionId};
use tokio::pin;
use tracing::level_filters::LevelFilter;
use tracing_subscriber::EnvFilter;
Expand Down Expand Up @@ -110,7 +109,7 @@ async fn main() -> anyhow::Result<()> {
// The stream gives us base64-encoded binary messages. We need to decode, parse, and verify them.
match msg {
AnyResponse::Json(msg) => match msg {
WsResponse::StreamUpdated(update) => {
Response::StreamUpdated(update) => {
println!("Received a JSON update for {:?}", update.subscription_id);
if let Some(evm_data) = update.payload.evm {
// Decode binary data
Expand Down
2 changes: 1 addition & 1 deletion lazer/sdk/rust/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use crate::{
};
use anyhow::{bail, Result};
use backoff::ExponentialBackoff;
use pyth_lazer_protocol::api::{SubscribeRequest, SubscriptionId};
use pyth_lazer_protocol::subscription::{SubscribeRequest, SubscriptionId};
use tokio::sync::mpsc::{self, error::TrySendError};
use tracing::{error, warn};
use ttl_cache::TtlCache;
Expand Down
22 changes: 11 additions & 11 deletions lazer/sdk/rust/client/src/resilient_ws_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use std::time::Duration;

use backoff::{backoff::Backoff, ExponentialBackoff};
use futures_util::StreamExt;
use pyth_lazer_protocol::api::{SubscribeRequest, SubscriptionId, UnsubscribeRequest, WsRequest};
use pyth_lazer_protocol::subscription::{
Request, SubscribeRequest, SubscriptionId, UnsubscribeRequest,
};
use tokio::{pin, select, sync::mpsc, time::Instant};
use tracing::{error, info, warn};
use url::Url;
Expand All @@ -16,7 +18,7 @@ use anyhow::{bail, Context, Result};
const BACKOFF_RESET_DURATION: Duration = Duration::from_secs(10);

pub struct PythLazerResilientWSConnection {
request_sender: mpsc::Sender<WsRequest>,
request_sender: mpsc::Sender<Request>,
}

impl PythLazerResilientWSConnection {
Expand Down Expand Up @@ -51,17 +53,15 @@ impl PythLazerResilientWSConnection {

pub async fn subscribe(&mut self, request: SubscribeRequest) -> Result<()> {
self.request_sender
.send(WsRequest::Subscribe(request))
.send(Request::Subscribe(request))
.await
.context("Failed to send subscribe request")?;
Ok(())
}

pub async fn unsubscribe(&mut self, subscription_id: SubscriptionId) -> Result<()> {
self.request_sender
.send(WsRequest::Unsubscribe(UnsubscribeRequest {
subscription_id,
}))
.send(Request::Unsubscribe(UnsubscribeRequest { subscription_id }))
.await
.context("Failed to send unsubscribe request")?;
Ok(())
Expand Down Expand Up @@ -95,7 +95,7 @@ impl PythLazerResilientWSConnectionTask {
pub async fn run(
&mut self,
response_sender: mpsc::Sender<AnyResponse>,
request_receiver: &mut mpsc::Receiver<WsRequest>,
request_receiver: &mut mpsc::Receiver<Request>,
) -> Result<()> {
loop {
let start_time = Instant::now();
Expand Down Expand Up @@ -128,7 +128,7 @@ impl PythLazerResilientWSConnectionTask {
pub async fn start(
&mut self,
sender: mpsc::Sender<AnyResponse>,
request_receiver: &mut mpsc::Receiver<WsRequest>,
request_receiver: &mut mpsc::Receiver<Request>,
) -> Result<()> {
let mut ws_connection =
PythLazerWSConnection::new(self.endpoint.clone(), self.access_token.clone())?;
Expand All @@ -137,7 +137,7 @@ impl PythLazerResilientWSConnectionTask {

for subscription in self.subscriptions.clone() {
ws_connection
.send_request(WsRequest::Subscribe(subscription))
.send_request(Request::Subscribe(subscription))
.await?;
}
loop {
Expand Down Expand Up @@ -167,10 +167,10 @@ impl PythLazerResilientWSConnectionTask {
}
Some(request) = request_receiver.recv() => {
match request {
WsRequest::Subscribe(request) => {
Request::Subscribe(request) => {
self.subscribe(&mut ws_connection, request).await?;
}
WsRequest::Unsubscribe(request) => {
Request::Unsubscribe(request) => {
self.unsubscribe(&mut ws_connection, request).await?;
}
}
Expand Down
14 changes: 7 additions & 7 deletions lazer/sdk/rust/client/src/ws_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use anyhow::Result;
use derive_more::From;
use futures_util::{SinkExt, StreamExt, TryStreamExt};
use pyth_lazer_protocol::{
api::{ErrorResponse, SubscribeRequest, UnsubscribeRequest, WsRequest, WsResponse},
binary_update::BinaryWsUpdate,
subscription::{ErrorResponse, Request, Response, SubscribeRequest, UnsubscribeRequest},
};
use tokio_tungstenite::{connect_async, tungstenite::Message};
use url::Url;
Expand All @@ -32,7 +32,7 @@ pub struct PythLazerWSConnection {

#[derive(Debug, Clone, PartialEq, Eq, Hash, From)]
pub enum AnyResponse {
Json(WsResponse),
Json(Response),
Binary(BinaryWsUpdate),
}

Expand Down Expand Up @@ -84,13 +84,13 @@ impl PythLazerWSConnection {
.try_filter_map(|msg| async {
let r: Result<Option<AnyResponse>> = match msg {
Message::Text(text) => {
Ok(Some(serde_json::from_str::<WsResponse>(&text)?.into()))
Ok(Some(serde_json::from_str::<Response>(&text)?.into()))
}
Message::Binary(data) => {
Ok(Some(BinaryWsUpdate::deserialize_slice(&data)?.into()))
}
Message::Close(_) => Ok(Some(
WsResponse::Error(ErrorResponse {
Response::Error(ErrorResponse {
error: "WebSocket connection closed".to_string(),
})
.into(),
Expand All @@ -103,7 +103,7 @@ impl PythLazerWSConnection {
Ok(response_stream)
}

pub async fn send_request(&mut self, request: WsRequest) -> Result<()> {
pub async fn send_request(&mut self, request: Request) -> Result<()> {
if let Some(sender) = &mut self.ws_sender {
let msg = serde_json::to_string(&request)?;
sender.send(Message::Text(msg)).await?;
Expand All @@ -118,7 +118,7 @@ impl PythLazerWSConnection {
/// # Arguments
/// * `request` - A subscription request containing feed IDs and parameters
pub async fn subscribe(&mut self, request: SubscribeRequest) -> Result<()> {
let request = WsRequest::Subscribe(request);
let request = Request::Subscribe(request);
self.send_request(request).await
}

Expand All @@ -127,7 +127,7 @@ impl PythLazerWSConnection {
/// # Arguments
/// * `subscription_id` - The ID of the subscription to cancel
pub async fn unsubscribe(&mut self, request: UnsubscribeRequest) -> Result<()> {
let request = WsRequest::Unsubscribe(request);
let request = Request::Unsubscribe(request);
self.send_request(request).await
}

Expand Down
4 changes: 1 addition & 3 deletions 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.11.0"
version = "0.10.2"
edition = "2021"
description = "Pyth Lazer SDK - protocol types."
license = "Apache-2.0"
Expand All @@ -20,7 +20,6 @@ mry = { version = "0.13.0", features = ["serde"], optional = true }
chrono = "0.4.41"
humantime = "2.2.0"
hex = "0.4.3"
thiserror = "2.0.12"

[dev-dependencies]
bincode = "1.3.3"
Expand All @@ -29,4 +28,3 @@ hex = "0.4.3"
libsecp256k1 = "0.7.1"
bs58 = "0.5.1"
alloy-primitives = "0.8.19"
assert_float_eq = "1.1.4"
Loading