add_ecdsa_signer.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import * as anchor from "@coral-xyz/anchor";
  2. import { PYTH_LAZER_SOLANA_CONTRACT_IDL, type PythLazerSolanaContract } from "../src";
  3. import yargs from "yargs/yargs";
  4. import { readFileSync } from "fs";
  5. import NodeWallet from "@coral-xyz/anchor/dist/cjs/nodewallet";
  6. // Add a trusted signer or change its expiry time.
  7. //
  8. // Example:
  9. // pnpm ts-node scripts/add_ecdsa_signer.ts --url 'https://api.testnet.solana.com' \
  10. // --keypair-path .../key.json --trusted-signer b8d50f0bae75bf6e03c104903d7c3afc4a6596da \
  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. .updateEcdsaSigner(
  35. [...Buffer.from(argv.trustedSigner, "hex")],
  36. new anchor.BN(argv.expiryTimeSeconds),
  37. )
  38. .accounts({
  39. payer: wallet.publicKey,
  40. })
  41. .rpc();
  42. console.log("signer updated");
  43. }
  44. main();