Quellcode durchsuchen

feat(express-relay): Update bid status (#1574)

Dani Mehrjerdi vor 1 Jahr
Ursprung
Commit
954fea65d6

+ 1 - 1
express_relay/sdk/js/package-lock.json

@@ -1,6 +1,6 @@
 {
   "name": "@pythnetwork/express-relay-evm-js",
-  "version": "0.4.1",
+  "version": "0.5.0",
   "lockfileVersion": 3,
   "requires": true,
   "packages": {

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

@@ -1,6 +1,6 @@
 {
   "name": "@pythnetwork/express-relay-evm-js",
-  "version": "0.4.1",
+  "version": "0.5.0",
   "description": "Utilities for interacting with the express relay protocol",
   "homepage": "https://github.com/pyth-network/pyth-crosschain/tree/main/express_relay/sdk/js",
   "author": "Douro Labs",

+ 7 - 2
express_relay/sdk/js/src/examples/simpleSearcher.ts

@@ -24,10 +24,15 @@ class SimpleSearcher {
 
   async bidStatusHandler(bidStatus: BidStatusUpdate) {
     let resultDetails = "";
-    if (bidStatus.type == "submitted") {
+    if (bidStatus.type == "submitted" || bidStatus.type == "won") {
       resultDetails = `, transaction ${bidStatus.result}, index ${bidStatus.index} of multicall`;
     } else if (bidStatus.type == "lost") {
-      resultDetails = `, transaction ${bidStatus.result}`;
+      if (bidStatus.result) {
+        resultDetails = `, transaction ${bidStatus.result}`;
+      }
+      if (bidStatus.index) {
+        resultDetails += `, index ${bidStatus.index} of multicall`;
+      }
     }
     console.log(
       `Bid status for bid ${bidStatus.id}: ${bidStatus.type.replaceAll(

+ 17 - 5
express_relay/sdk/js/src/serverTypes.d.ts

@@ -90,10 +90,6 @@ export interface components {
           /** @enum {string} */
           type: "pending";
         }
-      | {
-          /** @enum {string} */
-          type: "simulation_failed";
-        }
       | {
           /**
            * Format: int32
@@ -106,10 +102,26 @@ export interface components {
           type: "submitted";
         }
       | {
+          /**
+           * Format: int32
+           * @example 1
+           */
+          index?: number | null;
           /** @example 0x103d4fbd777a36311b5161f2062490f761f25b67406badb2bace62bb170aa4e3 */
-          result: string;
+          result?: string | null;
           /** @enum {string} */
           type: "lost";
+        }
+      | {
+          /**
+           * Format: int32
+           * @example 1
+           */
+          index: number;
+          /** @example 0x103d4fbd777a36311b5161f2062490f761f25b67406badb2bace62bb170aa4e3 */
+          result: string;
+          /** @enum {string} */
+          type: "won";
         };
     BidStatusWithId: {
       bid_status: components["schemas"]["BidStatus"];

+ 12 - 9
express_relay/sdk/python/express_relay/express_relay_types.py

@@ -102,10 +102,10 @@ class Bid(BaseModel):
 
 
 class BidStatus(Enum):
+    PENDING = "pending"
     SUBMITTED = "submitted"
     LOST = "lost"
-    PENDING = "pending"
-    SIMULATION_FAILED = "simulation_failed"
+    WON = "won"
 
 
 class BidStatusUpdate(BaseModel):
@@ -113,8 +113,8 @@ class BidStatusUpdate(BaseModel):
     Attributes:
         id: The ID of the bid.
         bid_status: The current status of the bid.
-        result: The result of the bid: a transaction hash if the status is SUBMITTED or LOST, else None.
-        index: The index of the bid in the submitted transaction; None if the status is not SUBMITTED.
+        result: The result of the bid: a transaction hash if the status is SUBMITTED or WON. The LOST status may have a result.
+        index: The index of the bid in the submitted transaction.
     """
 
     id: UUIDString
@@ -124,19 +124,22 @@ class BidStatusUpdate(BaseModel):
 
     @model_validator(mode="after")
     def check_result(self):
-        if self.bid_status in [
-            BidStatus("pending"),
-            BidStatus("simulation_failed"),
-        ]:
+        if self.bid_status == BidStatus("pending"):
             assert self.result is None, "result must be None"
+        elif self.bid_status == BidStatus("lost"):
+            pass
         else:
             assert self.result is not None, "result must be a valid 32-byte hash"
         return self
 
     @model_validator(mode="after")
     def check_index(self):
-        if self.bid_status == BidStatus("submitted"):
+        if self.bid_status == BidStatus("submitted") or self.bid_status == BidStatus(
+            "won"
+        ):
             assert self.index is not None, "index must be a valid integer"
+        elif self.bid_status == BidStatus("lost"):
+            pass
         else:
             assert self.index is None, "index must be None"
         return self

+ 7 - 5
express_relay/sdk/python/express_relay/searcher/examples/simple_searcher.py

@@ -75,14 +75,16 @@ class SimpleSearcher:
         id = bid_status_update.id
         bid_status = bid_status_update.bid_status
         result = bid_status_update.result
+        index = bid_status_update.index
 
         result_details = ""
-        if bid_status == BidStatus("submitted"):
-            result_details = (
-                f", transaction {result}, index {bid_status_update.index} of multicall"
-            )
+        if bid_status == BidStatus("submitted") or bid_status == BidStatus("won"):
+            result_details = f", transaction {result}, index {index} of multicall"
         elif bid_status == BidStatus("lost"):
-            result_details = f", transaction {result}"
+            if result:
+                result_details = f", transaction {result}"
+            if index:
+                result_details += f", index {index} of multicall"
         logger.error(
             f"Bid status for bid {id}: {bid_status.value.replace('_', ' ')}{result_details}"
         )

+ 1 - 1
express_relay/sdk/python/pyproject.toml

@@ -1,6 +1,6 @@
 [tool.poetry]
 name = "express-relay"
-version = "0.4.2"
+version = "0.5.0"
 description = "Utilities for searchers and protocols to interact with the Express Relay protocol."
 authors = ["dourolabs"]
 license = "Proprietary"

+ 1 - 1
package-lock.json

@@ -1753,7 +1753,7 @@
     },
     "express_relay/sdk/js": {
       "name": "@pythnetwork/express-relay-evm-js",
-      "version": "0.4.1",
+      "version": "0.5.0",
       "license": "Apache-2.0",
       "dependencies": {
         "isomorphic-ws": "^5.0.0",