Skip to content

Commit 1135f00

Browse files
anihamdeaniani
authored
adapt sdks (#1434)
* adapt sdks * update the sdks to reflect bid status ups * some js changes * python hex fix * update gen types * bump versions * fix docs --------- Co-authored-by: ani <[email protected]> Co-authored-by: ani <[email protected]>
1 parent 7673097 commit 1135f00

File tree

8 files changed

+93
-36
lines changed

8 files changed

+93
-36
lines changed

express_relay/sdk/js/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pythnetwork/express-relay-evm-js",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"description": "Utilities for interacting with the express relay protocol",
55
"homepage": "https://github.com/pyth-network/pyth-crosschain/tree/main/express_relay/sdk/js",
66
"author": "Douro Labs",
@@ -42,10 +42,11 @@
4242
"ws": "^8.16.0"
4343
},
4444
"devDependencies": {
45+
"@pythnetwork/pyth-evm-js": "*",
46+
"@types/node": "^20.12.7",
4547
"@types/yargs": "^17.0.10",
4648
"@typescript-eslint/eslint-plugin": "^5.21.0",
4749
"@typescript-eslint/parser": "^5.21.0",
48-
"@pythnetwork/pyth-evm-js": "*",
4950
"eslint": "^8.56.0",
5051
"jest": "^27.5.1",
5152
"prettier": "^2.6.2",

express_relay/sdk/js/src/examples/simpleSearcher.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@ class SimpleSearcher {
2323
}
2424

2525
async bidStatusHandler(bidStatus: BidStatusUpdate) {
26+
let resultDetails = "";
27+
if (bidStatus.type == "submitted") {
28+
resultDetails = `, transaction ${bidStatus.result}, index ${bidStatus.index} of multicall`;
29+
} else if (bidStatus.type == "lost") {
30+
resultDetails = `, transaction ${bidStatus.result}`;
31+
}
2632
console.log(
27-
`Bid status for bid ${bidStatus.id}: ${bidStatus.status} ${
28-
bidStatus.status == "submitted" ? bidStatus.result : ""
29-
}`
33+
`Bid status for bid ${bidStatus.id}: ${bidStatus.type}${resultDetails}`
3034
);
3135
}
3236

express_relay/sdk/js/src/serverTypes.d.ts

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface paths {
1010
* @description Bid on a specific permission key for a specific chain.
1111
*
1212
* Your bid will be simulated and verified by the server. Depending on the outcome of the auction, a transaction
13-
* containing the targetContract call will be sent to the blockchain expecting the bid amount to be paid after the call.
13+
* containing the contract call will be sent to the blockchain expecting the bid amount to be paid after the call.
1414
*/
1515
post: operations["bid"];
1616
};
@@ -58,7 +58,7 @@ export interface components {
5858
amount: string;
5959
/**
6060
* @description The chain id to bid on.
61-
* @example sepolia
61+
* @example op_sepolia
6262
*/
6363
chain_id: string;
6464
/**
@@ -67,12 +67,12 @@ export interface components {
6767
*/
6868
permission_key: string;
6969
/**
70-
* @description Calldata for the targetContract call.
70+
* @description Calldata for the contract call.
7171
* @example 0xdeadbeef
7272
*/
7373
target_calldata: string;
7474
/**
75-
* @description The targetContract address to call.
75+
* @description The contract address to call.
7676
* @example 0xcA11bde05977b3631167028862bE2a173976CA11
7777
*/
7878
target_contract: string;
@@ -88,20 +88,24 @@ export interface components {
8888
BidStatus:
8989
| {
9090
/** @enum {string} */
91-
status: "pending";
91+
type: "pending";
9292
}
9393
| {
9494
/**
95-
* @description The bid won the auction and was submitted to the chain in a transaction with the given hash
96-
* @example 0x103d4fbd777a36311b5161f2062490f761f25b67406badb2bace62bb170aa4e3
95+
* Format: int32
96+
* @example 1
9797
*/
98+
index: number;
99+
/** @example 0x103d4fbd777a36311b5161f2062490f761f25b67406badb2bace62bb170aa4e3 */
98100
result: string;
99101
/** @enum {string} */
100-
status: "submitted";
102+
type: "submitted";
101103
}
102104
| {
105+
/** @example 0x103d4fbd777a36311b5161f2062490f761f25b67406badb2bace62bb170aa4e3 */
106+
result: string;
103107
/** @enum {string} */
104-
status: "lost";
108+
type: "lost";
105109
};
106110
BidStatusWithId: {
107111
bid_status: components["schemas"]["BidStatus"];
@@ -174,14 +178,14 @@ export interface components {
174178
/**
175179
* @description Opportunity parameters needed for on-chain execution
176180
* If a searcher signs the opportunity and have approved enough tokens to opportunity adapter,
177-
* by calling this target targetContract with the given target targetCalldata and structures, they will
181+
* by calling this target contract with the given target calldata and structures, they will
178182
* send the tokens specified in the sell_tokens field and receive the tokens specified in the buy_tokens field.
179183
*/
180184
OpportunityParamsV1: {
181185
buy_tokens: components["schemas"]["TokenAmount"][];
182186
/**
183187
* @description The chain id where the opportunity will be executed.
184-
* @example sepolia
188+
* @example op_sepolia
185189
*/
186190
chain_id: string;
187191
/**
@@ -191,17 +195,17 @@ export interface components {
191195
permission_key: string;
192196
sell_tokens: components["schemas"]["TokenAmount"][];
193197
/**
194-
* @description The targetCallValue to send with the targetContract call.
198+
* @description The value to send with the contract call.
195199
* @example 1
196200
*/
197201
target_call_value: string;
198202
/**
199-
* @description Calldata for the target targetContract call.
203+
* @description Calldata for the target contract call.
200204
* @example 0xdeadbeef
201205
*/
202206
target_calldata: string;
203207
/**
204-
* @description The targetContract address to call for execution of the opportunity.
208+
* @description The contract address to call for execution of the opportunity.
205209
* @example 0xcA11bde05977b3631167028862bE2a173976CA11
206210
*/
207211
target_contract: string;
@@ -212,9 +216,8 @@ export interface components {
212216
version: "v1";
213217
}) & {
214218
/**
215-
* Format: int64
216-
* @description Creation time of the opportunity
217-
* @example 1700000000
219+
* @description Creation time of the opportunity (in microseconds since the Unix epoch)
220+
* @example 1700000000000000
218221
*/
219222
creation_time: number;
220223
/**
@@ -260,7 +263,7 @@ export interface components {
260263
*/
261264
amount: string;
262265
/**
263-
* @description Token targetContract address
266+
* @description Token contract address
264267
* @example 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
265268
*/
266269
token: string;
@@ -295,9 +298,8 @@ export interface components {
295298
version: "v1";
296299
}) & {
297300
/**
298-
* Format: int64
299-
* @description Creation time of the opportunity
300-
* @example 1700000000
301+
* @description Creation time of the opportunity (in microseconds since the Unix epoch)
302+
* @example 1700000000000000
301303
*/
302304
creation_time: number;
303305
/**
@@ -325,7 +327,7 @@ export interface operations {
325327
* @description Bid on a specific permission key for a specific chain.
326328
*
327329
* Your bid will be simulated and verified by the server. Depending on the outcome of the auction, a transaction
328-
* containing the targetContract call will be sent to the blockchain expecting the bid amount to be paid after the call.
330+
* containing the contract call will be sent to the blockchain expecting the bid amount to be paid after the call.
329331
*/
330332
bid: {
331333
requestBody: {
@@ -383,7 +385,7 @@ export interface operations {
383385
get_opportunities: {
384386
parameters: {
385387
query?: {
386-
/** @example sepolia */
388+
/** @example op_sepolia */
387389
chain_id?: string | null;
388390
};
389391
};

express_relay/sdk/python/express_relay/client.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,14 @@ async def ws_handler(
322322
elif msg_json.get("type") == "bid_status_update":
323323
if bid_status_callback is not None:
324324
id = msg_json["status"]["id"]
325-
bid_status = msg_json["status"]["bid_status"]["status"]
325+
bid_status = msg_json["status"]["bid_status"]["type"]
326326
result = msg_json["status"]["bid_status"].get("result")
327+
index = msg_json["status"]["bid_status"].get("index")
327328
bid_status_update = BidStatusUpdate(
328-
id=id, bid_status=BidStatus(bid_status), result=result
329+
id=id,
330+
bid_status=BidStatus(bid_status),
331+
result=result,
332+
index=index,
329333
)
330334
asyncio.create_task(bid_status_callback(bid_status_update))
331335

express_relay/sdk/python/express_relay/searcher/examples/simple_searcher.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,13 @@ async def bid_status_callback(self, bid_status_update: BidStatusUpdate):
7777
result = bid_status_update.result
7878

7979
if bid_status == BidStatus("submitted"):
80-
logger.info(f"Bid {id} has been submitted in hash {result}")
80+
logger.info(
81+
f"Bid {id} has been submitted in transaction {result} at index {bid_status_update.index} of the multicall"
82+
)
8183
elif bid_status == BidStatus("lost"):
82-
logger.info(f"Bid {id} was unsuccessful")
84+
logger.info(
85+
f"Bid {id} was unsuccessful, not included in transaction {result}"
86+
)
8387
elif bid_status == BidStatus("pending"):
8488
logger.info(f"Bid {id} is pending")
8589
else:

express_relay/sdk/python/express_relay/types.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,29 @@ class BidStatusUpdate(BaseModel):
112112
Attributes:
113113
id: The ID of the bid.
114114
bid_status: The status enum, either SUBMITTED, LOST, or PENDING.
115-
result: The result of the bid: a transaction hash if the status is SUBMITTED, else None.
115+
result: The result of the bid: a transaction hash if the status is SUBMITTED or LOST, else None.
116+
index: The index of the bid in the submitted transaction; None if the status is not SUBMITTED.
116117
"""
117118

118119
id: UUIDString
119120
bid_status: BidStatus
120121
result: Bytes32 | None = Field(default=None)
122+
index: int | None = Field(default=None)
121123

122124
@model_validator(mode="after")
123125
def check_result(self):
124-
if self.bid_status == BidStatus("submitted"):
126+
if self.bid_status == BidStatus("pending"):
127+
assert self.result is None, "result must be None"
128+
else:
125129
assert self.result is not None, "result must be a valid 32-byte hash"
130+
return self
131+
132+
@model_validator(mode="after")
133+
def check_index(self):
134+
if self.bid_status == BidStatus("submitted"):
135+
assert self.index is not None, "index must be a valid integer"
126136
else:
127-
assert self.result is None, "result must be None"
137+
assert self.index is None, "index must be None"
128138
return self
129139

130140

express_relay/sdk/python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "express-relay"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
description = "Utilities for searchers and protocols to interact with the Express Relay protocol."
55
authors = ["dourolabs"]
66
license = "Proprietary"

package-lock.json

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)