add_ed25519_signer.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. // Add a trusted signer or change its expiry time.
  9. //
  10. // Example:
  11. // pnpm tsx scripts/add_ed25519_signer.ts --url 'https://api.testnet.solana.com' \
  12. // --keypair-path .../key.json --trusted-signer HaXscpSUcbCLSnPQB8Z7H6idyANxp1mZAXTbHeYpfrJJ \
  13. // --expiry-time-seconds 2057930841
  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. const keypair = anchor.web3.Keypair.fromSecretKey(
  24. new Uint8Array(JSON.parse(readFileSync(argv.keypairPath, "ascii"))),
  25. );
  26. const wallet = new NodeWallet(keypair);
  27. const connection = new anchor.web3.Connection(argv.url, {
  28. commitment: "confirmed",
  29. });
  30. const provider = new anchor.AnchorProvider(connection, wallet);
  31. const program: Program<PythLazerSolanaContract> = new Program(
  32. pythLazerSolanaContractIdl as PythLazerSolanaContract,
  33. provider,
  34. );
  35. await program.methods
  36. .update(
  37. new anchor.web3.PublicKey(argv.trustedSigner),
  38. new anchor.BN(argv.expiryTimeSeconds),
  39. )
  40. .accounts({})
  41. .rpc();
  42. console.log("signer updated");
  43. }
  44. main();