-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathqueryEventsV2.ts
54 lines (49 loc) · 1.76 KB
/
queryEventsV2.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// This script queries the events of the spoke pool and prints them in a human readable format.
import { AnchorProvider } from "@coral-xyz/anchor";
import { address, createSolanaRpc } from "@solana/kit";
import { stringifyCpiEvent } from "../../src/svm/web3-v1";
import { SvmSpokeIdl } from "../../src/svm";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { readProgramEvents } from "../../src/svm";
// Set up the provider
const provider = AnchorProvider.env();
const argvPromise = yargs(hideBin(process.argv))
.option("eventName", {
type: "string",
demandOption: false,
describe: "Name of the event to query",
choices: [
"any",
"FilledRelay",
"FundsDeposited",
"EnabledDepositRoute",
"RelayedRootBundle",
"ExecutedRelayerRefundRoot",
"BridgedToHubPool",
"PausedDeposits",
"PausedFills",
"SetXDomainAdmin",
"EmergencyDeletedRootBundle",
"RequestedSlowFill",
"ClaimedRelayerRefund",
"TokensBridged",
],
})
.option("programId", {
type: "string",
demandOption: true,
describe: "SvmSpokeProgram ID to query events from",
}).argv;
async function queryEvents(): Promise<void> {
const argv = await argvPromise;
const eventName = argv.eventName || "any";
const programId = argv.programId;
const rpc = createSolanaRpc(provider.connection.rpcEndpoint);
const events = await readProgramEvents(rpc, address(programId), SvmSpokeIdl, "confirmed");
const filteredEvents = events.filter((event: any) => (eventName == "any" ? true : event.name == eventName));
const formattedEvents = filteredEvents.map((event: any) => stringifyCpiEvent(event));
console.log(JSON.stringify(formattedEvents, null, 2));
}
// Run the queryEvents function
queryEvents();