Browse Source

refactor(lazer): add exponent to AggregatedPriceFeedData (#3193)

Pavel Strakhov 1 week ago
parent
commit
1709d523d5

+ 5 - 5
Cargo.lock

@@ -5760,8 +5760,8 @@ dependencies = [
  "humantime-serde",
  "libsecp256k1 0.7.2",
  "protobuf-json-mapping",
- "pyth-lazer-protocol 0.20.2",
- "pyth-lazer-publisher-sdk 0.20.1",
+ "pyth-lazer-protocol 0.21.0",
+ "pyth-lazer-publisher-sdk 0.21.0",
  "reqwest 0.12.23",
  "serde",
  "serde_json",
@@ -5798,7 +5798,7 @@ dependencies = [
 
 [[package]]
 name = "pyth-lazer-protocol"
-version = "0.20.2"
+version = "0.21.0"
 dependencies = [
  "alloy-primitives 0.8.25",
  "anyhow",
@@ -5839,13 +5839,13 @@ dependencies = [
 
 [[package]]
 name = "pyth-lazer-publisher-sdk"
-version = "0.20.1"
+version = "0.21.0"
 dependencies = [
  "anyhow",
  "fs-err",
  "protobuf",
  "protobuf-codegen",
- "pyth-lazer-protocol 0.20.2",
+ "pyth-lazer-protocol 0.21.0",
  "serde_json",
 ]
 

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

@@ -19,7 +19,7 @@ no-log-ix-name = []
 idl-build = ["anchor-lang/idl-build"]
 
 [dependencies]
-pyth-lazer-protocol = { path = "../../../../sdk/rust/protocol", version = "0.20.0" }
+pyth-lazer-protocol = { path = "../../../../sdk/rust/protocol", version = "0.21.0" }
 
 anchor-lang = "0.31.1"
 bytemuck = { version = "1.20.0", features = ["derive"] }

+ 4 - 0
lazer/publisher_sdk/proto/state.proto

@@ -195,6 +195,10 @@ message FeedAggregateData {
     // [optional] Confidence interval for the `price` field. Can be absent if no data is available.
     // Never present for funding rate feeds.
     optional int64 confidence = 8;
+    // [required] Exponent applied to all price and rate values for this feed.
+    // Actual value is `mantissa * 10 ^ exponent`.
+    // Restricted to int16.
+    optional int32 exponent = 9;
 }
 
 // An item of the state describing an asset.

+ 2 - 2
lazer/publisher_sdk/rust/Cargo.toml

@@ -1,13 +1,13 @@
 [package]
 name = "pyth-lazer-publisher-sdk"
-version = "0.20.1"
+version = "0.21.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.20.1", path = "../../sdk/rust/protocol" }
+pyth-lazer-protocol = { version = "0.21.0", path = "../../sdk/rust/protocol" }
 anyhow = "1.0.98"
 protobuf = "3.7.2"
 serde_json = "1.0.140"

+ 2 - 2
lazer/sdk/rust/client/Cargo.toml

@@ -6,8 +6,8 @@ description = "A Rust client for Pyth Lazer"
 license = "Apache-2.0"
 
 [dependencies]
-pyth-lazer-protocol = { path = "../protocol", version = "0.20.1" }
-pyth-lazer-publisher-sdk = { path = "../../../publisher_sdk/rust", version = "0.20.1" }
+pyth-lazer-protocol = { path = "../protocol", version = "0.21.0" }
+pyth-lazer-publisher-sdk = { path = "../../../publisher_sdk/rust", version = "0.21.0" }
 
 tokio = { version = "1", features = ["full"] }
 tokio-stream = "0.1.17"

+ 1 - 1
lazer/sdk/rust/protocol/Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "pyth-lazer-protocol"
-version = "0.20.2"
+version = "0.21.0"
 edition = "2021"
 description = "Pyth Lazer SDK - protocol types."
 license = "Apache-2.0"

+ 1 - 2
lazer/sdk/rust/protocol/src/api.rs

@@ -434,7 +434,6 @@ pub struct ParsedFeedPayload {
 impl ParsedFeedPayload {
     pub fn new(
         price_feed_id: PriceFeedId,
-        exponent: Option<i16>,
         data: &AggregatedPriceFeedData,
         properties: &[PriceFeedProperty],
     ) -> Self {
@@ -465,7 +464,7 @@ impl ParsedFeedPayload {
                     output.publisher_count = Some(data.publisher_count);
                 }
                 PriceFeedProperty::Exponent => {
-                    output.exponent = exponent;
+                    output.exponent = Some(data.exponent);
                 }
                 PriceFeedProperty::Confidence => {
                     output.confidence = data.confidence;

+ 4 - 3
lazer/sdk/rust/protocol/src/payload.rs

@@ -49,6 +49,7 @@ pub struct AggregatedPriceFeedData {
     pub best_bid_price: Option<Price>,
     pub best_ask_price: Option<Price>,
     pub publisher_count: u16,
+    pub exponent: i16,
     pub confidence: Option<Price>,
     pub funding_rate: Option<Rate>,
     pub funding_timestamp: Option<TimestampUs>,
@@ -63,7 +64,7 @@ impl PayloadData {
     pub fn new(
         timestamp_us: TimestampUs,
         channel_id: ChannelId,
-        feeds: &[(PriceFeedId, i16, AggregatedPriceFeedData)],
+        feeds: &[(PriceFeedId, AggregatedPriceFeedData)],
         requested_properties: &[PriceFeedProperty],
     ) -> Self {
         Self {
@@ -71,7 +72,7 @@ impl PayloadData {
             channel_id,
             feeds: feeds
                 .iter()
-                .map(|(feed_id, exponent, feed)| PayloadFeedData {
+                .map(|(feed_id, feed)| PayloadFeedData {
                     feed_id: *feed_id,
                     properties: requested_properties
                         .iter()
@@ -87,7 +88,7 @@ impl PayloadData {
                                 PayloadPropertyValue::PublisherCount(feed.publisher_count)
                             }
                             PriceFeedProperty::Exponent => {
-                                PayloadPropertyValue::Exponent(*exponent)
+                                PayloadPropertyValue::Exponent(feed.exponent)
                             }
                             PriceFeedProperty::Confidence => {
                                 PayloadPropertyValue::Confidence(feed.confidence)