-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lazer/contracts/solana): add setup script (#2125)
- Loading branch information
Showing
7 changed files
with
850 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
``` |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.