diff --git a/lazer/Cargo.lock b/lazer/Cargo.lock index f1221c6527..5e54c91b2e 100644 --- a/lazer/Cargo.lock +++ b/lazer/Cargo.lock @@ -3783,7 +3783,7 @@ dependencies = [ [[package]] name = "pyth-lazer-protocol" -version = "0.6.1" +version = "0.6.2" dependencies = [ "alloy-primitives", "anyhow", diff --git a/lazer/sdk/rust/protocol/Cargo.toml b/lazer/sdk/rust/protocol/Cargo.toml index 912fbda9b7..e77407373d 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.6.1" +version = "0.6.2" edition = "2021" description = "Pyth Lazer SDK - protocol types." license = "Apache-2.0" diff --git a/lazer/sdk/rust/protocol/src/api.rs b/lazer/sdk/rust/protocol/src/api.rs index 8e65924863..0a451f7b20 100644 --- a/lazer/sdk/rust/protocol/src/api.rs +++ b/lazer/sdk/rust/protocol/src/api.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Serialize}; use crate::router::{ - Channel, Format, JsonBinaryEncoding, JsonUpdate, PriceFeedId, PriceFeedProperty, + Channel, Format, JsonBinaryEncoding, JsonUpdate, PriceFeedId, PriceFeedProperty, TimestampUs, }; #[derive(Debug, Clone, Serialize, Deserialize)] @@ -21,6 +21,22 @@ pub struct LatestPriceRequest { pub channel: Channel, } +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct PriceRequest { + pub timestamp: TimestampUs, + pub price_feed_ids: Vec, + pub properties: Vec, + pub formats: Vec, + #[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)] #[serde(rename_all = "camelCase")] pub struct ReducePriceRequest { @@ -30,6 +46,7 @@ pub struct ReducePriceRequest { pub type LatestPriceResponse = JsonUpdate; pub type ReducePriceResponse = JsonUpdate; +pub type PriceResponse = JsonUpdate; pub fn default_parsed() -> bool { true diff --git a/lazer/sdk/rust/protocol/src/router.rs b/lazer/sdk/rust/protocol/src/router.rs index f8e7491734..0985ebda4c 100644 --- a/lazer/sdk/rust/protocol/src/router.rs +++ b/lazer/sdk/rust/protocol/src/router.rs @@ -7,6 +7,7 @@ use { rust_decimal::{prelude::FromPrimitive, Decimal}, serde::{de::Error, Deserialize, Serialize}, std::{ + fmt::Display, num::NonZeroI64, ops::{Add, Deref, DerefMut, Div, Sub}, time::{SystemTime, UNIX_EPOCH}, @@ -66,6 +67,12 @@ impl Rate { let value: i64 = value.try_into().context("overflow")?; Ok(Self(value)) } + + pub fn from_integer(value: i64, exponent: u32) -> anyhow::Result { + let coef = 10i64.checked_pow(exponent).context("overflow")?; + let value = value.checked_mul(coef).context("overflow")?; + Ok(Self(value)) + } } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)] @@ -236,6 +243,17 @@ mod channel_ids { pub const FIXED_RATE_200: ChannelId = ChannelId(3); } +impl Display for Channel { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Channel::FixedRate(fixed_rate) => match *fixed_rate { + FixedRate::MIN => write!(f, "real_time"), + rate => write!(f, "fixed_rate@{}ms", rate.value_ms()), + }, + } + } +} + impl Channel { pub fn id(&self) -> ChannelId { match self {