Skip to content

Commit

Permalink
refactor!(lazer): update api protocol (#2237)
Browse files Browse the repository at this point in the history
* refactor!(lazer): update api protocol

our apis should be similar to each other as much as possible.

* fix: add json binary encoding
  • Loading branch information
ali-bahjati authored Jan 10, 2025
1 parent 080feba commit 74e976f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lazer/Cargo.lock

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

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.2.6"
version = "0.3.0"
edition = "2021"
description = "Pyth Lazer SDK - protocol types."
license = "Apache-2.0"
Expand Down
35 changes: 15 additions & 20 deletions lazer/sdk/rust/protocol/src/api.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
use serde::{Deserialize, Serialize};

use crate::{
payload::AggregatedPriceFeedData,
router::{JsonUpdate, PriceFeedId},
use crate::router::{
Chain, Channel, JsonBinaryEncoding, JsonUpdate, PriceFeedId, PriceFeedProperty,
};

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct LatestPriceRequest {
pub price_feed_ids: Vec<PriceFeedId>,
pub properties: Vec<PriceFeedProperty>,
pub chains: Vec<Chain>,
#[serde(default)]
pub json_binary_encoding: JsonBinaryEncoding,
/// If `true`, the stream update will contain a JSON object containing
/// all data of the update.
#[serde(default = "default_parsed")]
pub parsed: bool,
pub channel: Channel,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand All @@ -18,22 +26,9 @@ pub struct ReducePriceRequest {
pub price_feed_ids: Vec<PriceFeedId>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct LatestPriceResponse {
pub latest_prices: Vec<LatestPrice>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ReducePriceResponse {
pub payload: JsonUpdate,
}
pub type LatestPriceResponse = JsonUpdate;
pub type ReducePriceResponse = JsonUpdate;

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct LatestPrice {
pub id: PriceFeedId,
pub exponent: i16,
pub prices: AggregatedPriceFeedData,
pub fn default_parsed() -> bool {
true
}

0 comments on commit 74e976f

Please sign in to comment.