Prechádzať zdrojové kódy

feat(lazer): add ignoreInvalidFeedIds flag to SDK (#2529)

* feat(lazer): add ignoreInvalidFeeds flag to SDK

Co-Authored-By: Darun Seethammagari <darun@dourolabs.xyz>

* feat(lazer): update protocol types for ignore_invalid_feeds

Co-Authored-By: Darun Seethammagari <darun@dourolabs.xyz>

* fix: update example to include ignore_invalid_feeds field

Co-Authored-By: Darun Seethammagari <darun@dourolabs.xyz>

* refactor: rename ignore_invalid_feeds to ignore_invalid_feed_ids

Co-Authored-By: Darun Seethammagari <darun@dourolabs.xyz>

* refactor: rename FailedFeedsDetails to InvalidFeedSubscriptionDetails

Co-Authored-By: Darun Seethammagari <darun@dourolabs.xyz>

* refactor: rename comingSoon to unstable in InvalidFeedSubscriptionDetails

Co-Authored-By: Darun Seethammagari <darun@dourolabs.xyz>

* refactor: change successful_feeds type from Vec<u64> to Vec<u32>

Co-Authored-By: Darun Seethammagari <darun@dourolabs.xyz>

* refactor: add subscribedWithIgnoredFailures response type

Co-Authored-By: Darun Seethammagari <darun@dourolabs.xyz>

* refactor: rename subscribedWithIgnoredFailures to subscribedWithInvalidFeeds

Co-Authored-By: Darun Seethammagari <darun@dourolabs.xyz>

* refactor: rename subscribedWithInvalidFeeds to subscribedWithIgnoredInvalidFeedIds

Co-Authored-By: Darun Seethammagari <darun@dourolabs.xyz>

* refactor: rename response types to subscribedWithInvalidFeedIdsIgnored

Co-Authored-By: Darun Seethammagari <darun@dourolabs.xyz>

* refactor: rename fields to subscribedFeedIds and ignoredInvalidFeedIds

Co-Authored-By: Darun Seethammagari <darun@dourolabs.xyz>

* refactor: rename enum variant to SubscribedWithInvalidFeedIdsIgnored

Co-Authored-By: Darun Seethammagari <darun@dourolabs.xyz>

* refactor: move ignore_invalid_feed_ids to SubscriptionParamsRepr

Co-Authored-By: Darun Seethammagari <darun@dourolabs.xyz>

* refactor: change ignore_invalid_feed_ids from Option<bool> to bool

Co-Authored-By: Darun Seethammagari <darun@dourolabs.xyz>

* refactor: update InvalidFeedSubscriptionDetails to use proper types

Co-Authored-By: Darun Seethammagari <darun@dourolabs.xyz>

* refactor: use local SymbolState instead of external dependency

Co-Authored-By: Darun Seethammagari <darun@dourolabs.xyz>

* fix: update protocol.ts formatting to fix CI

Co-Authored-By: Darun Seethammagari <darun@dourolabs.xyz>

* Undo change ot returned ignored ids

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Darun Seethammagari <darun@dourolabs.xyz>
Co-authored-by: Darun Seethammagari <darunrs@gmail.com>
devin-ai-integration[bot] 7 mesiacov pred
rodič
commit
ba09a52afa

+ 1 - 1
lazer/Cargo.lock

@@ -3783,7 +3783,7 @@ dependencies = [
 
 [[package]]
 name = "pyth-lazer-protocol"
-version = "0.6.2"
+version = "0.7.0"
 dependencies = [
  "alloy-primitives",
  "anyhow",

+ 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.6.0" }
+pyth-lazer-protocol = { path = "../../../../sdk/rust/protocol", version = "0.7.0" }
 
 anchor-lang = "0.30.1"
 bytemuck = "1.20.0"

+ 1 - 1
lazer/sdk/js/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@pythnetwork/pyth-lazer-sdk",
-  "version": "0.4.0",
+  "version": "0.5.0",
   "description": "Pyth Lazer SDK",
   "publishConfig": {
     "access": "public"

+ 13 - 0
lazer/sdk/js/src/protocol.ts

@@ -20,6 +20,7 @@ export type Request =
       deliveryFormat?: DeliveryFormat;
       jsonBinaryEncoding?: JsonBinaryEncoding;
       parsed?: boolean;
+      ignoreInvalidFeedIds?: boolean;
       channel: Channel;
     }
   | {
@@ -47,6 +48,12 @@ export type JsonBinaryData = {
   data: string;
 };
 
+export type InvalidFeedSubscriptionDetails = {
+  unknownIds: number[];
+  unsupportedChannels: number[];
+  unstable: number[];
+};
+
 export type Response =
   | {
       type: "error";
@@ -56,6 +63,12 @@ export type Response =
       type: "subscribed";
       subscriptionId: number;
     }
+  | {
+      type: "subscribedWithInvalidFeedIdsIgnored";
+      subscriptionId: number;
+      subscribedFeedIds: number[];
+      ignoredInvalidFeedIds: InvalidFeedSubscriptionDetails;
+    }
   | {
       type: "unsubscribed";
       subscriptionId: number;

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

@@ -6,7 +6,7 @@ description = "A Rust client for Pyth Lazer"
 license = "Apache-2.0"
 
 [dependencies]
-pyth-lazer-protocol = { path = "../protocol", version = "0.6.0" }
+pyth-lazer-protocol = { path = "../protocol", version = "0.7.0" }
 tokio = { version = "1", features = ["full"] }
 tokio-tungstenite = { version = "0.20", features = ["native-tls"] }
 futures-util = "0.3"

+ 2 - 0
lazer/sdk/rust/client/examples/subscribe_price_feeds.rs

@@ -47,6 +47,7 @@ async fn main() -> anyhow::Result<()> {
                 channel: Channel::FixedRate(
                     FixedRate::from_ms(200).expect("unsupported update rate"),
                 ),
+                ignore_invalid_feed_ids: false,
             })
             .expect("invalid subscription params"),
         },
@@ -68,6 +69,7 @@ async fn main() -> anyhow::Result<()> {
                 channel: Channel::FixedRate(
                     FixedRate::from_ms(50).expect("unsupported update rate"),
                 ),
+                ignore_invalid_feed_ids: false,
             })
             .expect("invalid subscription params"),
         },

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

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

+ 1 - 0
lazer/sdk/rust/protocol/src/lib.rs

@@ -9,6 +9,7 @@ pub mod router;
 mod serde_price_as_i64;
 mod serde_str;
 pub mod subscription;
+pub mod symbol_state;
 
 #[test]
 fn magics_in_big_endian() {

+ 2 - 0
lazer/sdk/rust/protocol/src/router.rs

@@ -358,6 +358,8 @@ pub struct SubscriptionParamsRepr {
     #[serde(default = "default_parsed")]
     pub parsed: bool,
     pub channel: Channel,
+    #[serde(default)]
+    pub ignore_invalid_feed_ids: bool,
 }
 
 #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize)]

+ 18 - 1
lazer/sdk/rust/protocol/src/subscription.rs

@@ -2,7 +2,7 @@
 //! used across publishers, agents and routers.
 
 use {
-    crate::router::{JsonUpdate, SubscriptionParams},
+    crate::router::{JsonUpdate, PriceFeedId, SubscriptionParams},
     derive_more::From,
     serde::{Deserialize, Serialize},
 };
@@ -40,6 +40,7 @@ pub struct UnsubscribeRequest {
 pub enum Response {
     Error(ErrorResponse),
     Subscribed(SubscribedResponse),
+    SubscribedWithInvalidFeedIdsIgnored(SubscribedWithInvalidFeedIdsIgnoredResponse),
     Unsubscribed(UnsubscribedResponse),
     SubscriptionError(SubscriptionErrorResponse),
     StreamUpdated(StreamUpdatedResponse),
@@ -52,6 +53,22 @@ pub struct SubscribedResponse {
     pub subscription_id: SubscriptionId,
 }
 
+#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct InvalidFeedSubscriptionDetails {
+    pub unknown_ids: Vec<PriceFeedId>,
+    pub unsupported_channels: Vec<PriceFeedId>,
+    pub unstable: Vec<PriceFeedId>,
+}
+
+#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct SubscribedWithInvalidFeedIdsIgnoredResponse {
+    pub subscription_id: SubscriptionId,
+    pub subscribed_feed_ids: Vec<PriceFeedId>,
+    pub ignored_invalid_feed_ids: InvalidFeedSubscriptionDetails,
+}
+
 #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
 #[serde(rename_all = "camelCase")]
 pub struct UnsubscribedResponse {

+ 20 - 0
lazer/sdk/rust/protocol/src/symbol_state.rs

@@ -0,0 +1,20 @@
+use {
+    serde::{Deserialize, Serialize},
+    std::fmt::Display,
+};
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
+#[serde(rename_all = "snake_case")]
+pub enum SymbolState {
+    Stable,
+    ComingSoon,
+}
+
+impl Display for SymbolState {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        match self {
+            SymbolState::Stable => write!(f, "stable"),
+            SymbolState::ComingSoon => write!(f, "coming_soon"),
+        }
+    }
+}