Skip to content

Commit 7ef9aa2

Browse files
anihamdem30m
andauthored
Express Relay: directly submit Bids (#1747)
* SDKs now directly submitting to bid endpoint * bump versions * address comments * remove development configs * fix lint * Add mode + better error handling * Check chain ids before running simple searcher * Update constants and adjust a bit for mode --------- Co-authored-by: Amin Moghaddam <amin@pyth.network>
1 parent 07a7767 commit 7ef9aa2

File tree

11 files changed

+463
-266
lines changed

11 files changed

+463
-266
lines changed

express_relay/sdk/js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pythnetwork/express-relay-evm-js",
3-
"version": "0.7.1",
3+
"version": "0.8.0",
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",

express_relay/sdk/js/src/abi.ts

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
export const executeOpportunityAbi = {
2+
type: "function",
3+
name: "executeOpportunity",
4+
inputs: [
5+
{
6+
name: "params",
7+
type: "tuple",
8+
internalType: "struct ExecutionParams",
9+
components: [
10+
{
11+
name: "permit",
12+
type: "tuple",
13+
internalType: "struct ISignatureTransfer.PermitBatchTransferFrom",
14+
components: [
15+
{
16+
name: "permitted",
17+
type: "tuple[]",
18+
internalType: "struct ISignatureTransfer.TokenPermissions[]",
19+
components: [
20+
{
21+
name: "token",
22+
type: "address",
23+
internalType: "address",
24+
},
25+
{
26+
name: "amount",
27+
type: "uint256",
28+
internalType: "uint256",
29+
},
30+
],
31+
},
32+
{
33+
name: "nonce",
34+
type: "uint256",
35+
internalType: "uint256",
36+
},
37+
{
38+
name: "deadline",
39+
type: "uint256",
40+
internalType: "uint256",
41+
},
42+
],
43+
},
44+
{
45+
name: "witness",
46+
type: "tuple",
47+
internalType: "struct ExecutionWitness",
48+
components: [
49+
{
50+
name: "buyTokens",
51+
type: "tuple[]",
52+
internalType: "struct TokenAmount[]",
53+
components: [
54+
{
55+
name: "token",
56+
type: "address",
57+
internalType: "address",
58+
},
59+
{
60+
name: "amount",
61+
type: "uint256",
62+
internalType: "uint256",
63+
},
64+
],
65+
},
66+
{
67+
name: "executor",
68+
type: "address",
69+
internalType: "address",
70+
},
71+
{
72+
name: "targetContract",
73+
type: "address",
74+
internalType: "address",
75+
},
76+
{
77+
name: "targetCalldata",
78+
type: "bytes",
79+
internalType: "bytes",
80+
},
81+
{
82+
name: "targetCallValue",
83+
type: "uint256",
84+
internalType: "uint256",
85+
},
86+
{
87+
name: "bidAmount",
88+
type: "uint256",
89+
internalType: "uint256",
90+
},
91+
],
92+
},
93+
],
94+
},
95+
{
96+
name: "signature",
97+
type: "bytes",
98+
internalType: "bytes",
99+
},
100+
],
101+
outputs: [],
102+
stateMutability: "payable",
103+
};

express_relay/sdk/js/src/const.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { OpportunityAdapterConfig } from "./types";
2+
3+
export const OPPORTUNITY_ADAPTER_CONFIGS: Record<
4+
string,
5+
OpportunityAdapterConfig
6+
> = {
7+
op_sepolia: {
8+
chain_id: 11155420,
9+
opportunity_adapter_factory: "0xfA119693864b2F185742A409c66f04865c787754",
10+
opportunity_adapter_init_bytecode_hash:
11+
"0x3d71516d94b96a8fdca4e3a5825a6b41c9268a8e94610367e69a8462cc543533",
12+
permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3",
13+
weth: "0x74A4A85C611679B73F402B36c0F84A7D2CcdFDa3",
14+
},
15+
mode: {
16+
chain_id: 34443,
17+
opportunity_adapter_factory: "0x59F78DE21a0b05d96Ae00c547BA951a3B905602f",
18+
opportunity_adapter_init_bytecode_hash:
19+
"0xd53b8e32ab2ecba07c3e3a17c3c5e492c62e2f7051b89e5154f52e6bfeb0e38f",
20+
permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3",
21+
weth: "0x4200000000000000000000000000000000000006",
22+
},
23+
};

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { checkHex, Client } from "../index";
44
import { privateKeyToAccount } from "viem/accounts";
55
import { isHex } from "viem";
66
import { BidStatusUpdate, Opportunity } from "../types";
7+
import { OPPORTUNITY_ADAPTER_CONFIGS } from "../const";
78

89
const DAY_IN_SECONDS = 60 * 60 * 24;
910

@@ -47,25 +48,25 @@ class SimpleSearcher {
4748
}
4849

4950
async opportunityHandler(opportunity: Opportunity) {
50-
const bid = BigInt(argv.bid);
51+
const bidAmount = BigInt(argv.bid);
5152
// Bid info should be generated by evaluating the opportunity
5253
// here for simplicity we are using a constant bid and 24 hours of validity
5354
// TODO: generate nonce more intelligently, to reduce gas costs
5455
const nonce = BigInt(Math.floor(Math.random() * 2 ** 50));
5556
const bidParams = {
56-
amount: bid,
57+
amount: bidAmount,
5758
nonce: nonce,
5859
deadline: BigInt(Math.round(Date.now() / 1000 + DAY_IN_SECONDS)),
5960
};
60-
const opportunityBid = await this.client.signOpportunityBid(
61+
const bid = await this.client.signBid(
6162
opportunity,
6263
bidParams,
6364
checkHex(argv.privateKey)
6465
);
6566
try {
66-
const bidId = await this.client.submitOpportunityBid(opportunityBid);
67+
const bidId = await this.client.submitBid(bid);
6768
console.log(
68-
`Successful bid. Opportunity id ${opportunityBid.opportunityId} Bid id ${bidId}`
69+
`Successful bid. Opportunity id ${opportunity.opportunityId} Bid id ${bidId}`
6970
);
7071
} catch (error) {
7172
console.error(
@@ -102,7 +103,7 @@ const argv = yargs(hideBin(process.argv))
102103
.option("bid", {
103104
description: "Bid amount in wei",
104105
type: "string",
105-
default: "20000000000000000",
106+
default: "10000000000000000",
106107
})
107108
.option("private-key", {
108109
description:
@@ -132,6 +133,11 @@ async function run() {
132133
argv.privateKey,
133134
argv.apiKey
134135
);
136+
if (OPPORTUNITY_ADAPTER_CONFIGS[argv.chainId] === undefined) {
137+
throw new Error(
138+
`Opportunity adapter config not found for chain ${argv.chainId}`
139+
);
140+
}
135141
await searcher.start();
136142
}
137143

0 commit comments

Comments
 (0)