Skip to content

Commit

Permalink
updated ts sdk to incorporate changes to programs
Browse files Browse the repository at this point in the history
  • Loading branch information
anihamde committed Sep 11, 2024
1 parent ad20151 commit 531fa18
Show file tree
Hide file tree
Showing 10 changed files with 377 additions and 38 deletions.
2 changes: 1 addition & 1 deletion express_relay/sdk/js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ To generate the latest type declarations from the server openapi schema, run:
npm run generate-api-types
```

You can generate the Solana Typescript declaration files from the IDLs via:
You can generate the SVM Typescript declaration files from the IDLs via:

```bash
npm run generate-anchor-types
Expand Down
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-js",
"version": "0.9.0",
"version": "0.9.1",
"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
2 changes: 1 addition & 1 deletion express_relay/sdk/js/src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const OPPORTUNITY_ADAPTER_CONFIGS: Record<
};

export const SVM_CONSTANTS: Record<string, SvmConstantsConfig> = {
solana: {
"development-solana": {
relayerSigner: new PublicKey(
"3pR5W8qPTHKEdoD7mNMx1SwkaPE18aQZwoAKWYpnHozY"
),
Expand Down
118 changes: 117 additions & 1 deletion express_relay/sdk/js/src/examples/dummyTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type Dummy = {
address: "HYCgALnu6CM2gkQVopa1HGaNf8Vzbs9bomWRiKP267P3";
metadata: {
name: "dummy";
version: "0.1.0";
version: "0.2.0";
spec: "0.1.0";
description: "Created with Anchor";
};
Expand All @@ -26,6 +26,21 @@ export type Dummy = {
name: "expressRelay";
address: "GwEtasTAxdS9neVE4GPUpcwR7DB7AizntQSPcG36ubZM";
},
{
name: "expressRelayMetadata";
pda: {
seeds: [
{
kind: "const";
value: [109, 101, 116, 97, 100, 97, 116, 97];
}
];
program: {
kind: "account";
path: "expressRelay";
};
};
},
{
name: "sysvarInstructions";
address: "Sysvar1nstructions1111111111111111111111111";
Expand All @@ -35,9 +50,110 @@ export type Dummy = {
},
{
name: "router";
},
{
name: "configRouter";
pda: {
seeds: [
{
kind: "const";
value: [
99,
111,
110,
102,
105,
103,
95,
114,
111,
117,
116,
101,
114
];
},
{
kind: "account";
path: "router";
}
];
program: {
kind: "account";
path: "expressRelay";
};
};
},
{
name: "accounting";
writable: true;
pda: {
seeds: [
{
kind: "const";
value: [97, 99, 99, 111, 117, 110, 116, 105, 110, 103];
}
];
};
},
{
name: "systemProgram";
address: "11111111111111111111111111111111";
}
];
args: [];
}
];
accounts: [
{
name: "accounting";
discriminator: [1, 249, 15, 214, 81, 88, 40, 108];
},
{
name: "expressRelayMetadata";
discriminator: [204, 75, 133, 7, 175, 241, 130, 11];
}
];
types: [
{
name: "accounting";
type: {
kind: "struct";
fields: [
{
name: "totalFees";
type: "u64";
}
];
};
},
{
name: "expressRelayMetadata";
type: {
kind: "struct";
fields: [
{
name: "admin";
type: "pubkey";
},
{
name: "relayerSigner";
type: "pubkey";
},
{
name: "feeReceiverRelayer";
type: "pubkey";
},
{
name: "splitRouterDefault";
type: "u64";
},
{
name: "splitRelayer";
type: "u64";
}
];
};
}
];
};
106 changes: 105 additions & 1 deletion express_relay/sdk/js/src/examples/idl/idlDummy.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"address": "HYCgALnu6CM2gkQVopa1HGaNf8Vzbs9bomWRiKP267P3",
"metadata": {
"name": "dummy",
"version": "0.1.0",
"version": "0.2.0",
"spec": "0.1.0",
"description": "Created with Anchor"
},
Expand All @@ -20,6 +20,21 @@
"name": "express_relay",
"address": "GwEtasTAxdS9neVE4GPUpcwR7DB7AizntQSPcG36ubZM"
},
{
"name": "express_relay_metadata",
"pda": {
"seeds": [
{
"kind": "const",
"value": [109, 101, 116, 97, 100, 97, 116, 97]
}
],
"program": {
"kind": "account",
"path": "express_relay"
}
}
},
{
"name": "sysvar_instructions",
"address": "Sysvar1nstructions1111111111111111111111111"
Expand All @@ -29,9 +44,98 @@
},
{
"name": "router"
},
{
"name": "config_router",
"pda": {
"seeds": [
{
"kind": "const",
"value": [
99, 111, 110, 102, 105, 103, 95, 114, 111, 117, 116, 101, 114
]
},
{
"kind": "account",
"path": "router"
}
],
"program": {
"kind": "account",
"path": "express_relay"
}
}
},
{
"name": "accounting",
"writable": true,
"pda": {
"seeds": [
{
"kind": "const",
"value": [97, 99, 99, 111, 117, 110, 116, 105, 110, 103]
}
]
}
},
{
"name": "system_program",
"address": "11111111111111111111111111111111"
}
],
"args": []
}
],
"accounts": [
{
"name": "Accounting",
"discriminator": [1, 249, 15, 214, 81, 88, 40, 108]
},
{
"name": "ExpressRelayMetadata",
"discriminator": [204, 75, 133, 7, 175, 241, 130, 11]
}
],
"types": [
{
"name": "Accounting",
"type": {
"kind": "struct",
"fields": [
{
"name": "total_fees",
"type": "u64"
}
]
}
},
{
"name": "ExpressRelayMetadata",
"type": {
"kind": "struct",
"fields": [
{
"name": "admin",
"type": "pubkey"
},
{
"name": "relayer_signer",
"type": "pubkey"
},
{
"name": "fee_receiver_relayer",
"type": "pubkey"
},
{
"name": "split_router_default",
"type": "u64"
},
{
"name": "split_relayer",
"type": "u64"
}
]
}
}
]
}
19 changes: 17 additions & 2 deletions express_relay/sdk/js/src/examples/simpleSearcherSvm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ import { Program, AnchorProvider } from "@coral-xyz/anchor";
import { Keypair, PublicKey, Connection } from "@solana/web3.js";
import dummyIdl from "./idl/idlDummy.json";
import { Dummy } from "./dummyTypes";
import { getConfigRouterPda, getExpressRelayMetadataPda } from "../svmPda";

const DAY_IN_SECONDS = 60 * 60 * 24;
const DUMMY_PIDS: Record<string, PublicKey> = {
solana: new PublicKey("HYCgALnu6CM2gkQVopa1HGaNf8Vzbs9bomWRiKP267P3"),
"development-solana": new PublicKey(
"HYCgALnu6CM2gkQVopa1HGaNf8Vzbs9bomWRiKP267P3"
),
};

class SimpleSearcherSvm {
Expand Down Expand Up @@ -69,22 +72,34 @@ class SimpleSearcherSvm {

const permission = PublicKey.default;
const router = Keypair.generate().publicKey;
const bidAmount = new anchor.BN(argv.bid);

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

const configRouter = getConfigRouterPda(this.chainId, router);
const expressRelayMetadata = getExpressRelayMetadataPda(this.chainId);
const accounting = PublicKey.findProgramAddressSync(
[anchor.utils.bytes.utf8.encode("accounting")],
dummyPid
)[0];

const bidAmount = new anchor.BN(argv.bid);

const ixDummy = await dummy.methods
.doNothing()
.accountsStrict({
payer: searcher.publicKey,
expressRelay: svmConstants.expressRelayProgram,
expressRelayMetadata,
sysvarInstructions: anchor.web3.SYSVAR_INSTRUCTIONS_PUBKEY,
permission,
router,
configRouter,
accounting,
systemProgram: anchor.web3.SystemProgram.programId,
})
.instruction();
ixDummy.programId = dummyPid;
Expand Down
Loading

0 comments on commit 531fa18

Please sign in to comment.