Skip to content

Commit

Permalink
feat(express-relay): Update bid status (#1574)
Browse files Browse the repository at this point in the history
  • Loading branch information
danimhr committed May 20, 2024
1 parent 51dc213 commit 954fea6
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 25 deletions.
2 changes: 1 addition & 1 deletion express_relay/sdk/js/package-lock.json

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

2 changes: 1 addition & 1 deletion express_relay/sdk/js/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
9 changes: 7 additions & 2 deletions express_relay/sdk/js/src/examples/simpleSearcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
22 changes: 17 additions & 5 deletions express_relay/sdk/js/src/serverTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@ export interface components {
/** @enum {string} */
type: "pending";
}
| {
/** @enum {string} */
type: "simulation_failed";
}
| {
/**
* Format: int32
Expand All @@ -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"];
Expand Down
21 changes: 12 additions & 9 deletions express_relay/sdk/python/express_relay/express_relay_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,19 @@ class Bid(BaseModel):


class BidStatus(Enum):
PENDING = "pending"
SUBMITTED = "submitted"
LOST = "lost"
PENDING = "pending"
SIMULATION_FAILED = "simulation_failed"
WON = "won"


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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,16 @@ async def bid_status_callback(self, bid_status_update: BidStatusUpdate):
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}"
)
Expand Down
2 changes: 1 addition & 1 deletion express_relay/sdk/python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

0 comments on commit 954fea6

Please sign in to comment.