Skip to content

Commit 65cef16

Browse files
authored
feat(lazer/contracts/solana): add setup script (#2125)
1 parent 629f011 commit 65cef16

File tree

7 files changed

+850
-105
lines changed

7 files changed

+850
-105
lines changed

lazer/contracts/solana/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Pyth Lazer Solana Receiver
2+
3+
## Verifiable Build
4+
5+
To build the program in a verifiable way, use [Solana Verify CLI](https://github.com/Ellipsis-Labs/solana-verifiable-build). This tool builds the program in
6+
a docker container to ensure that the resulting binary is deterministic and verifiable. Run the following command to build the program:
7+
8+
```bash
9+
solana-verify build -- --features solana-program
10+
```
11+
12+
Once the build is complete, the program binary will be located in the `target/deploy` directory.
13+
14+
## Setting up the Pyth Lazer Solana Receiver
15+
16+
Run the following command to deploy the Pyth Lazer Solana Receiver program:
17+
18+
```bash
19+
solana -u <RPC_URL> program deploy target/deploy/pyth_lazer_solana_contract.so --program-id <PROGRAM_ID>
20+
```
21+
22+
Once deployed, run the following Anchor script to setup the program. This script initializes the program
23+
if it is uninitialized and updates one trusted signer of the program.
24+
25+
```bash
26+
pnpm run setup --url <RPC_URL> --keypair-path <PATH/TO/KEYPAIR> --trusted-signer <Pubkey> --expiry-time-seconds <UNIX_TIMESTAMP>
27+
```

lazer/contracts/solana/migrations/deploy.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

lazer/contracts/solana/package.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,23 @@
44
"fix:format": "prettier --write **/*.*",
55
"test:format": "prettier --check **/*.*",
66
"test:anchor": "CARGO_TARGET_DIR=\"$PWD/target\" anchor test",
7-
"test": "pnpm run test:format && pnpm run test:anchor"
7+
"test": "pnpm run test:format && pnpm run test:anchor",
8+
"setup": "anchor build && pnpm ts-node scripts/setup.ts"
89
},
910
"dependencies": {
1011
"@coral-xyz/anchor": "^0.30.1"
1112
},
1213
"devDependencies": {
13-
"chai": "^4.3.4",
14-
"mocha": "^9.0.3",
15-
"ts-mocha": "^10.0.0",
1614
"@types/bn.js": "^5.1.0",
1715
"@types/chai": "^4.3.0",
1816
"@types/mocha": "^9.0.0",
17+
"@types/yargs": "^17.0.33",
18+
"chai": "^4.3.4",
19+
"mocha": "^9.0.3",
20+
"prettier": "^2.6.2",
21+
"ts-mocha": "^10.0.0",
22+
"ts-node": "^10.9.2",
1923
"typescript": "^4.3.5",
20-
"prettier": "^2.6.2"
24+
"yargs": "^17.7.2"
2125
}
2226
}

lazer/contracts/solana/programs/pyth-lazer-solana-contract/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use {
66
declare_id!("pytd2yyk641x7ak7mkaasSJVXh6YYZnC7wTmtgAyxPt");
77

88
pub mod storage {
9-
use anchor_lang::declare_id;
9+
use anchor_lang::prelude::{pubkey, Pubkey};
1010

11-
declare_id!("3rdJbqfnagQ4yx9HXJViD4zc4xpiSqmFsKpPuSCQVyQL");
11+
pub const ID: Pubkey = pubkey!("3rdJbqfnagQ4yx9HXJViD4zc4xpiSqmFsKpPuSCQVyQL");
1212

1313
#[test]
1414
fn test_storage_id() {
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import * as anchor from "@coral-xyz/anchor";
2+
import { Program } from "@coral-xyz/anchor";
3+
import { PythLazerSolanaContract } from "../target/types/pyth_lazer_solana_contract";
4+
import * as pythLazerSolanaContractIdl from "../target/idl/pyth_lazer_solana_contract.json";
5+
import yargs from "yargs/yargs";
6+
import { readFileSync } from "fs";
7+
import NodeWallet from "@coral-xyz/anchor/dist/cjs/nodewallet";
8+
9+
// This script initializes the program and updates the trusted signer
10+
//
11+
// There are some assumptions made in this script:
12+
// 1. The program id is derived from the idl file (pytd...).
13+
// 2. The keypair provided is the top authority keypair
14+
async function main() {
15+
let argv = await yargs(process.argv.slice(2))
16+
.options({
17+
url: { type: "string", demandOption: true },
18+
"keypair-path": { type: "string", demandOption: true },
19+
"trusted-signer": { type: "string", demandOption: true },
20+
"expiry-time-seconds": { type: "number", demandOption: true },
21+
})
22+
.parse();
23+
24+
const keypair = anchor.web3.Keypair.fromSecretKey(
25+
new Uint8Array(JSON.parse(readFileSync(argv.keypairPath, "ascii")))
26+
);
27+
const wallet = new NodeWallet(keypair);
28+
const connection = new anchor.web3.Connection(argv.url, {
29+
commitment: "confirmed",
30+
});
31+
const provider = new anchor.AnchorProvider(connection, wallet);
32+
33+
const program: Program<PythLazerSolanaContract> = new Program(
34+
pythLazerSolanaContractIdl as PythLazerSolanaContract,
35+
provider
36+
);
37+
38+
const storage = await program.account.storage.all();
39+
if (storage.length === 0) {
40+
console.log("Initializing the program");
41+
await program.methods
42+
.initialize(keypair.publicKey)
43+
.accounts({
44+
payer: wallet.publicKey,
45+
})
46+
.rpc();
47+
}
48+
49+
console.log("Updating the trusted signer");
50+
await program.methods
51+
.update(
52+
new anchor.web3.PublicKey(argv.trustedSigner),
53+
new anchor.BN(argv.expiryTimeSeconds)
54+
)
55+
.accounts({})
56+
.rpc();
57+
}
58+
59+
main();

lazer/contracts/solana/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"lib": ["es2015"],
66
"module": "commonjs",
77
"target": "es6",
8-
"esModuleInterop": true
8+
"esModuleInterop": true,
9+
"resolveJsonModule": true
910
}
1011
}

0 commit comments

Comments
 (0)