add_ed25519_signer.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import * as anchor from "@coral-xyz/anchor";
  2. import { PYTH_LAZER_SOLANA_CONTRACT_IDL, type PythLazerSolanaContract } from "../src/index.js";
  3. import yargs from "yargs/yargs";
  4. import { readFileSync } from "fs";
  5. import NodeWallet from "@coral-xyz/anchor/dist/cjs/nodewallet.js";
  6. // Add a trusted signer or change its expiry time.
  7. //
  8. // Example:
  9. // pnpm ts-node scripts/add_ed25519_signer.ts --url 'https://api.testnet.solana.com' \
  10. // --keypair-path .../key.json --trusted-signer HaXscpSUcbCLSnPQB8Z7H6idyANxp1mZAXTbHeYpfrJJ \
  11. // --expiry-time-seconds 2057930841
  12. async function main() {
  13. let argv = await yargs(process.argv.slice(2))
  14. .options({
  15. url: { type: "string", demandOption: true },
  16. "keypair-path": { type: "string", demandOption: true },
  17. "trusted-signer": { type: "string", demandOption: true },
  18. "expiry-time-seconds": { type: "number", demandOption: true },
  19. })
  20. .parse();
  21. const keypair = anchor.web3.Keypair.fromSecretKey(
  22. new Uint8Array(JSON.parse(readFileSync(argv.keypairPath, "ascii"))),
  23. );
  24. const wallet = new NodeWallet(keypair);
  25. const connection = new anchor.web3.Connection(argv.url, {
  26. commitment: "confirmed",
  27. });
  28. const provider = new anchor.AnchorProvider(connection, wallet);
  29. const program: anchor.Program<PythLazerSolanaContract> = new anchor.Program(
  30. PYTH_LAZER_SOLANA_CONTRACT_IDL,
  31. provider,
  32. );
  33. await program.methods
  34. .update(
  35. new anchor.web3.PublicKey(argv.trustedSigner),
  36. new anchor.BN(argv.expiryTimeSeconds),
  37. )
  38. .accounts({})
  39. .rpc();
  40. console.log("signer updated");
  41. }
  42. main();