Skip to content

Commit 8e6c518

Browse files
authored
updated ts sdk to incorporate changes to programs (#1888)
1 parent ad20151 commit 8e6c518

File tree

10 files changed

+377
-38
lines changed

10 files changed

+377
-38
lines changed

express_relay/sdk/js/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ To generate the latest type declarations from the server openapi schema, run:
2424
npm run generate-api-types
2525
```
2626

27-
You can generate the Solana Typescript declaration files from the IDLs via:
27+
You can generate the SVM Typescript declaration files from the IDLs via:
2828

2929
```bash
3030
npm run generate-anchor-types

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-js",
3-
"version": "0.9.0",
3+
"version": "0.9.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",

express_relay/sdk/js/src/const.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const OPPORTUNITY_ADAPTER_CONFIGS: Record<
2424
};
2525

2626
export const SVM_CONSTANTS: Record<string, SvmConstantsConfig> = {
27-
solana: {
27+
"development-solana": {
2828
relayerSigner: new PublicKey(
2929
"3pR5W8qPTHKEdoD7mNMx1SwkaPE18aQZwoAKWYpnHozY"
3030
),

express_relay/sdk/js/src/examples/dummyTypes.d.ts

Lines changed: 117 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export type Dummy = {
88
address: "HYCgALnu6CM2gkQVopa1HGaNf8Vzbs9bomWRiKP267P3";
99
metadata: {
1010
name: "dummy";
11-
version: "0.1.0";
11+
version: "0.2.0";
1212
spec: "0.1.0";
1313
description: "Created with Anchor";
1414
};
@@ -26,6 +26,21 @@ export type Dummy = {
2626
name: "expressRelay";
2727
address: "GwEtasTAxdS9neVE4GPUpcwR7DB7AizntQSPcG36ubZM";
2828
},
29+
{
30+
name: "expressRelayMetadata";
31+
pda: {
32+
seeds: [
33+
{
34+
kind: "const";
35+
value: [109, 101, 116, 97, 100, 97, 116, 97];
36+
}
37+
];
38+
program: {
39+
kind: "account";
40+
path: "expressRelay";
41+
};
42+
};
43+
},
2944
{
3045
name: "sysvarInstructions";
3146
address: "Sysvar1nstructions1111111111111111111111111";
@@ -35,9 +50,110 @@ export type Dummy = {
3550
},
3651
{
3752
name: "router";
53+
},
54+
{
55+
name: "configRouter";
56+
pda: {
57+
seeds: [
58+
{
59+
kind: "const";
60+
value: [
61+
99,
62+
111,
63+
110,
64+
102,
65+
105,
66+
103,
67+
95,
68+
114,
69+
111,
70+
117,
71+
116,
72+
101,
73+
114
74+
];
75+
},
76+
{
77+
kind: "account";
78+
path: "router";
79+
}
80+
];
81+
program: {
82+
kind: "account";
83+
path: "expressRelay";
84+
};
85+
};
86+
},
87+
{
88+
name: "accounting";
89+
writable: true;
90+
pda: {
91+
seeds: [
92+
{
93+
kind: "const";
94+
value: [97, 99, 99, 111, 117, 110, 116, 105, 110, 103];
95+
}
96+
];
97+
};
98+
},
99+
{
100+
name: "systemProgram";
101+
address: "11111111111111111111111111111111";
38102
}
39103
];
40104
args: [];
41105
}
42106
];
107+
accounts: [
108+
{
109+
name: "accounting";
110+
discriminator: [1, 249, 15, 214, 81, 88, 40, 108];
111+
},
112+
{
113+
name: "expressRelayMetadata";
114+
discriminator: [204, 75, 133, 7, 175, 241, 130, 11];
115+
}
116+
];
117+
types: [
118+
{
119+
name: "accounting";
120+
type: {
121+
kind: "struct";
122+
fields: [
123+
{
124+
name: "totalFees";
125+
type: "u64";
126+
}
127+
];
128+
};
129+
},
130+
{
131+
name: "expressRelayMetadata";
132+
type: {
133+
kind: "struct";
134+
fields: [
135+
{
136+
name: "admin";
137+
type: "pubkey";
138+
},
139+
{
140+
name: "relayerSigner";
141+
type: "pubkey";
142+
},
143+
{
144+
name: "feeReceiverRelayer";
145+
type: "pubkey";
146+
},
147+
{
148+
name: "splitRouterDefault";
149+
type: "u64";
150+
},
151+
{
152+
name: "splitRelayer";
153+
type: "u64";
154+
}
155+
];
156+
};
157+
}
158+
];
43159
};

express_relay/sdk/js/src/examples/idl/idlDummy.json

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"address": "HYCgALnu6CM2gkQVopa1HGaNf8Vzbs9bomWRiKP267P3",
33
"metadata": {
44
"name": "dummy",
5-
"version": "0.1.0",
5+
"version": "0.2.0",
66
"spec": "0.1.0",
77
"description": "Created with Anchor"
88
},
@@ -20,6 +20,21 @@
2020
"name": "express_relay",
2121
"address": "GwEtasTAxdS9neVE4GPUpcwR7DB7AizntQSPcG36ubZM"
2222
},
23+
{
24+
"name": "express_relay_metadata",
25+
"pda": {
26+
"seeds": [
27+
{
28+
"kind": "const",
29+
"value": [109, 101, 116, 97, 100, 97, 116, 97]
30+
}
31+
],
32+
"program": {
33+
"kind": "account",
34+
"path": "express_relay"
35+
}
36+
}
37+
},
2338
{
2439
"name": "sysvar_instructions",
2540
"address": "Sysvar1nstructions1111111111111111111111111"
@@ -29,9 +44,98 @@
2944
},
3045
{
3146
"name": "router"
47+
},
48+
{
49+
"name": "config_router",
50+
"pda": {
51+
"seeds": [
52+
{
53+
"kind": "const",
54+
"value": [
55+
99, 111, 110, 102, 105, 103, 95, 114, 111, 117, 116, 101, 114
56+
]
57+
},
58+
{
59+
"kind": "account",
60+
"path": "router"
61+
}
62+
],
63+
"program": {
64+
"kind": "account",
65+
"path": "express_relay"
66+
}
67+
}
68+
},
69+
{
70+
"name": "accounting",
71+
"writable": true,
72+
"pda": {
73+
"seeds": [
74+
{
75+
"kind": "const",
76+
"value": [97, 99, 99, 111, 117, 110, 116, 105, 110, 103]
77+
}
78+
]
79+
}
80+
},
81+
{
82+
"name": "system_program",
83+
"address": "11111111111111111111111111111111"
3284
}
3385
],
3486
"args": []
3587
}
88+
],
89+
"accounts": [
90+
{
91+
"name": "Accounting",
92+
"discriminator": [1, 249, 15, 214, 81, 88, 40, 108]
93+
},
94+
{
95+
"name": "ExpressRelayMetadata",
96+
"discriminator": [204, 75, 133, 7, 175, 241, 130, 11]
97+
}
98+
],
99+
"types": [
100+
{
101+
"name": "Accounting",
102+
"type": {
103+
"kind": "struct",
104+
"fields": [
105+
{
106+
"name": "total_fees",
107+
"type": "u64"
108+
}
109+
]
110+
}
111+
},
112+
{
113+
"name": "ExpressRelayMetadata",
114+
"type": {
115+
"kind": "struct",
116+
"fields": [
117+
{
118+
"name": "admin",
119+
"type": "pubkey"
120+
},
121+
{
122+
"name": "relayer_signer",
123+
"type": "pubkey"
124+
},
125+
{
126+
"name": "fee_receiver_relayer",
127+
"type": "pubkey"
128+
},
129+
{
130+
"name": "split_router_default",
131+
"type": "u64"
132+
},
133+
{
134+
"name": "split_relayer",
135+
"type": "u64"
136+
}
137+
]
138+
}
139+
}
36140
]
37141
}

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ import { Program, AnchorProvider } from "@coral-xyz/anchor";
99
import { Keypair, PublicKey, Connection } from "@solana/web3.js";
1010
import dummyIdl from "./idl/idlDummy.json";
1111
import { Dummy } from "./dummyTypes";
12+
import { getConfigRouterPda, getExpressRelayMetadataPda } from "../svmPda";
1213

1314
const DAY_IN_SECONDS = 60 * 60 * 24;
1415
const DUMMY_PIDS: Record<string, PublicKey> = {
15-
solana: new PublicKey("HYCgALnu6CM2gkQVopa1HGaNf8Vzbs9bomWRiKP267P3"),
16+
"development-solana": new PublicKey(
17+
"HYCgALnu6CM2gkQVopa1HGaNf8Vzbs9bomWRiKP267P3"
18+
),
1619
};
1720

1821
class SimpleSearcherSvm {
@@ -69,22 +72,34 @@ class SimpleSearcherSvm {
6972

7073
const permission = PublicKey.default;
7174
const router = Keypair.generate().publicKey;
72-
const bidAmount = new anchor.BN(argv.bid);
7375

7476
const svmConstants = SVM_CONSTANTS[this.chainId];
7577
if (!(this.chainId in DUMMY_PIDS)) {
7678
throw new Error(`Dummy program id not found for chain ${this.chainId}`);
7779
}
7880
const dummyPid = DUMMY_PIDS[this.chainId];
7981

82+
const configRouter = getConfigRouterPda(this.chainId, router);
83+
const expressRelayMetadata = getExpressRelayMetadataPda(this.chainId);
84+
const accounting = PublicKey.findProgramAddressSync(
85+
[anchor.utils.bytes.utf8.encode("accounting")],
86+
dummyPid
87+
)[0];
88+
89+
const bidAmount = new anchor.BN(argv.bid);
90+
8091
const ixDummy = await dummy.methods
8192
.doNothing()
8293
.accountsStrict({
8394
payer: searcher.publicKey,
8495
expressRelay: svmConstants.expressRelayProgram,
96+
expressRelayMetadata,
8597
sysvarInstructions: anchor.web3.SYSVAR_INSTRUCTIONS_PUBKEY,
8698
permission,
8799
router,
100+
configRouter,
101+
accounting,
102+
systemProgram: anchor.web3.SystemProgram.programId,
88103
})
89104
.instruction();
90105
ixDummy.programId = dummyPid;

0 commit comments

Comments
 (0)