Skip to content

Commit

Permalink
add script to check trusted signer
Browse files Browse the repository at this point in the history
  • Loading branch information
cctdaniel committed Jan 14, 2025
1 parent 5e08204 commit 288268a
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lazer/contracts/solana/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"test:anchor": "CARGO_TARGET_DIR=\"$PWD/target\" anchor test",
"test": "pnpm run test:format && pnpm run test:anchor",
"setup": "anchor build && pnpm ts-node scripts/setup.ts",
"migrate_from_0_1_0": "pnpm ts-node scripts/migrate_from_0_1_0.ts"
"migrate_from_0_1_0": "pnpm ts-node scripts/migrate_from_0_1_0.ts",
"check_trusted_signer": "pnpm ts-node scripts/check_trusted_signer.ts"
},
"dependencies": {
"@coral-xyz/anchor": "^0.30.1"
Expand Down
68 changes: 68 additions & 0 deletions lazer/contracts/solana/scripts/check_trusted_signer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import * as anchor from "@coral-xyz/anchor";
import { PythLazerSolanaContract } from "../target/types/pyth_lazer_solana_contract";
import * as pythLazerSolanaContractIdl from "../target/idl/pyth_lazer_solana_contract.json";
import yargs from "yargs/yargs";
import NodeWallet from "@coral-xyz/anchor/dist/cjs/nodewallet";

const parser = yargs(process.argv.slice(2)).options({
url: {
type: "string",
demandOption: true,
desc: "RPC URL to use",
},
"storage-id": {
type: "string",
demandOption: true,
desc: "Storage account ID to check",
},
});

async function main() {
const argv = await parser.argv;

// Setup anchor provider
const connection = new anchor.web3.Connection(argv.url);
const provider = new anchor.AnchorProvider(
connection,
new NodeWallet(anchor.web3.Keypair.generate()), // Dummy wallet since we're only reading
{ commitment: "confirmed" }
);
anchor.setProvider(provider);

const program: anchor.Program<PythLazerSolanaContract> = new anchor.Program(
pythLazerSolanaContractIdl as PythLazerSolanaContract,
provider
);

// Fetch and decode storage account
const storageId = new anchor.web3.PublicKey(argv["storage-id"]);
const storage = await program.account.storage.fetch(storageId);

// Print storage info
console.log("Storage Account Info:");
console.log("--------------------");
console.log("Top Authority:", storage.topAuthority.toBase58());
console.log("Treasury:", storage.treasury.toBase58());
console.log("\nTrusted Signers:");
console.log("----------------");

for (const signer of storage.trustedSigners) {
if (signer.pubkey.equals(anchor.web3.PublicKey.default)) continue;
console.log(`\nPublic Key: ${signer.pubkey.toBase58()}`);
console.log(
`Expires At: ${new Date(
signer.expiresAt.toNumber() * 1000
).toISOString()}`
);
console.log(
`Active: ${
signer.expiresAt.toNumber() > Date.now() / 1000 ? "Yes" : "No"
}`
);
}
}

main().catch((err) => {
console.error(err);
process.exit(1);
});

0 comments on commit 288268a

Please sign in to comment.