Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lazer/contracts/solana): add setup script #2125

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions lazer/contracts/solana/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Pyth Lazer Solana Receiver

## Verifiable Build

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
a docker container to ensure that the resulting binary is deterministic and verifiable. Run the following command to build the program:

```bash
solana-verify build -- --features solana-program
```

Once the build is complete, the program binary will be located in the `target/deploy` directory.

## Setting up the Pyth Lazer Solana Receiver

Run the following command to deploy the Pyth Lazer Solana Receiver program:

```bash
solana -u <RPC_URL> program deploy target/deploy/pyth_lazer_solana_contract.so --program-id <PROGRAM_ID>
```

Once deployed, run the following Anchor script to setup the program. This script initializes the program
if it is uninitialized and updates one trusted signer of the program.

```bash
pnpm run setup --url <RPC_URL> --keypair-path <PATH/TO/KEYPAIR> --trusted-signer <Pubkey> --expiry-time-seconds <UNIX_TIMESTAMP>
```
12 changes: 0 additions & 12 deletions lazer/contracts/solana/migrations/deploy.ts

This file was deleted.

14 changes: 9 additions & 5 deletions lazer/contracts/solana/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@
"fix:format": "prettier --write **/*.*",
"test:format": "prettier --check **/*.*",
"test:anchor": "CARGO_TARGET_DIR=\"$PWD/target\" anchor test",
"test": "pnpm run test:format && pnpm run test:anchor"
"test": "pnpm run test:format && pnpm run test:anchor",
"setup": "anchor build && pnpm ts-node scripts/setup.ts"
},
"dependencies": {
"@coral-xyz/anchor": "^0.30.1"
},
"devDependencies": {
"chai": "^4.3.4",
"mocha": "^9.0.3",
"ts-mocha": "^10.0.0",
"@types/bn.js": "^5.1.0",
"@types/chai": "^4.3.0",
"@types/mocha": "^9.0.0",
"@types/yargs": "^17.0.33",
"chai": "^4.3.4",
"mocha": "^9.0.3",
"prettier": "^2.6.2",
"ts-mocha": "^10.0.0",
"ts-node": "^10.9.2",
"typescript": "^4.3.5",
"prettier": "^2.6.2"
"yargs": "^17.7.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use {
declare_id!("pytd2yyk641x7ak7mkaasSJVXh6YYZnC7wTmtgAyxPt");

pub mod storage {
use anchor_lang::declare_id;
use anchor_lang::prelude::{pubkey, Pubkey};

declare_id!("3rdJbqfnagQ4yx9HXJViD4zc4xpiSqmFsKpPuSCQVyQL");
pub const ID: Pubkey = pubkey!("3rdJbqfnagQ4yx9HXJViD4zc4xpiSqmFsKpPuSCQVyQL");

#[test]
fn test_storage_id() {
Expand Down
59 changes: 59 additions & 0 deletions lazer/contracts/solana/scripts/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import * as anchor from "@coral-xyz/anchor";
import { Program } from "@coral-xyz/anchor";
import { PythLazerSolanaContract } from "../target/types/pyth_lazer_solana_contract";
import * as pythLazerSolanaContractIdl from "../target/idl/pyth_lazer_solana_contract.json";
import yargs from "yargs/yargs";
import { readFileSync } from "fs";
import NodeWallet from "@coral-xyz/anchor/dist/cjs/nodewallet";

// This script initializes the program and updates the trusted signer
//
// There are some assumptions made in this script:
// 1. The program id is derived from the idl file (pytd...).
// 2. The keypair provided is the top authority keypair
async function main() {
let argv = await yargs(process.argv.slice(2))
.options({
url: { type: "string", demandOption: true },
"keypair-path": { type: "string", demandOption: true },
"trusted-signer": { type: "string", demandOption: true },
"expiry-time-seconds": { type: "number", demandOption: true },
})
.parse();

const keypair = anchor.web3.Keypair.fromSecretKey(
new Uint8Array(JSON.parse(readFileSync(argv.keypairPath, "ascii")))
);
const wallet = new NodeWallet(keypair);
const connection = new anchor.web3.Connection(argv.url, {
commitment: "confirmed",
});
const provider = new anchor.AnchorProvider(connection, wallet);

const program: Program<PythLazerSolanaContract> = new Program(
pythLazerSolanaContractIdl as PythLazerSolanaContract,
provider
);

const storage = await program.account.storage.all();
if (storage.length === 0) {
console.log("Initializing the program");
await program.methods
.initialize(keypair.publicKey)
.accounts({
payer: wallet.publicKey,
})
.rpc();
}

console.log("Updating the trusted signer");
await program.methods
.update(
new anchor.web3.PublicKey(argv.trustedSigner),
new anchor.BN(argv.expiryTimeSeconds)
)
.accounts({})
.rpc();
}

main();
3 changes: 2 additions & 1 deletion lazer/contracts/solana/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"lib": ["es2015"],
"module": "commonjs",
"target": "es6",
"esModuleInterop": true
"esModuleInterop": true,
"resolveJsonModule": true
}
}
Loading
Loading