add_ecdsa_signer.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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_ecdsa_signer.ts --url 'https://api.testnet.solana.com' \
  12. // --keypair-path .../key.json --trusted-signer b8d50f0bae75bf6e03c104903d7c3afc4a6596da \
  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. .updateEcdsaSigner(
  37. [...Buffer.from(argv.trustedSigner, "hex")],
  38. new anchor.BN(argv.expiryTimeSeconds),
  39. )
  40. .accounts({
  41. payer: wallet.publicKey,
  42. })
  43. .rpc();
  44. console.log("signer updated");
  45. }
  46. main();