check_trusted_signer.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import * as anchor from "@coral-xyz/anchor";
  2. import { PythLazerSolanaContract } from "../target/types/pyth_lazer_solana_contract";
  3. import * as pythLazerSolanaContractIdl from "../target/idl/pyth_lazer_solana_contract.json";
  4. import yargs from "yargs/yargs";
  5. import NodeWallet from "@coral-xyz/anchor/dist/cjs/nodewallet";
  6. const parser = yargs(process.argv.slice(2)).options({
  7. url: {
  8. type: "string",
  9. demandOption: true,
  10. desc: "RPC URL to use",
  11. },
  12. "storage-id": {
  13. type: "string",
  14. demandOption: true,
  15. desc: "Storage account ID to check",
  16. },
  17. });
  18. async function main() {
  19. const argv = await parser.argv;
  20. // Setup anchor provider
  21. const connection = new anchor.web3.Connection(argv.url);
  22. const provider = new anchor.AnchorProvider(
  23. connection,
  24. new NodeWallet(anchor.web3.Keypair.generate()), // Dummy wallet since we're only reading
  25. { commitment: "confirmed" },
  26. );
  27. anchor.setProvider(provider);
  28. const program: anchor.Program<PythLazerSolanaContract> = new anchor.Program(
  29. pythLazerSolanaContractIdl as PythLazerSolanaContract,
  30. provider,
  31. );
  32. // Fetch and decode storage account
  33. const storageId = new anchor.web3.PublicKey(argv["storage-id"]);
  34. const storage = await program.account.storage.fetch(storageId);
  35. // Print storage info
  36. console.log("Storage Account Info:");
  37. console.log("--------------------");
  38. console.log("Top Authority:", storage.topAuthority.toBase58());
  39. console.log("Treasury:", storage.treasury.toBase58());
  40. console.log("\nTrusted Signers:");
  41. console.log("----------------");
  42. const trustedSigners = storage.trustedSigners.slice(
  43. 0,
  44. storage.numTrustedSigners,
  45. );
  46. for (const signer of trustedSigners) {
  47. console.log(
  48. `\nPublic Key: ${(signer.pubkey as anchor.web3.PublicKey).toBase58()}`,
  49. );
  50. console.log(
  51. `Expires At: ${new Date(
  52. signer.expiresAt.toNumber() * 1000,
  53. ).toISOString()}`,
  54. );
  55. console.log(
  56. `Active: ${
  57. signer.expiresAt.toNumber() > Date.now() / 1000 ? "Yes" : "No"
  58. }`,
  59. );
  60. }
  61. console.log("\nTrusted ECDSA Signers:");
  62. console.log("----------------");
  63. const trustedEcdsaSigners = storage.trustedEcdsaSigners.slice(
  64. 0,
  65. storage.numTrustedEcdsaSigners,
  66. );
  67. for (const signer of trustedEcdsaSigners) {
  68. console.log(
  69. `\nPublic Address: ${Buffer.from(signer.pubkey as number[]).toString("hex")}`,
  70. );
  71. console.log(
  72. `Expires At: ${new Date(
  73. signer.expiresAt.toNumber() * 1000,
  74. ).toISOString()}`,
  75. );
  76. console.log(
  77. `Active: ${
  78. signer.expiresAt.toNumber() > Date.now() / 1000 ? "Yes" : "No"
  79. }`,
  80. );
  81. }
  82. }
  83. main().catch((err) => {
  84. console.error(err);
  85. process.exit(1);
  86. });