"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
// This script queries the events of the spoke pool and prints them in a human readable format.
const anchor_1 = require("@coral-xyz/anchor");
const kit_1 = require("@solana/kit");
const web3_v1_1 = require("../../src/svm/web3-v1");
const svm_1 = require("../../src/svm");
const yargs_1 = __importDefault(require("yargs"));
const helpers_1 = require("yargs/helpers");
const svm_2 = require("../../src/svm");
// Set up the provider
const provider = anchor_1.AnchorProvider.env();
const argvPromise = (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
    .option("eventName", {
    type: "string",
    demandOption: false,
    describe: "Name of the event to query",
    choices: [
        "any",
        "FilledV3Relay",
        "V3FundsDeposited",
        "EnabledDepositRoute",
        "RelayedRootBundle",
        "ExecutedRelayerRefundRoot",
        "BridgedToHubPool",
        "PausedDeposits",
        "PausedFills",
        "SetXDomainAdmin",
        "EmergencyDeletedRootBundle",
        "RequestedV3SlowFill",
        "ClaimedRelayerRefund",
        "TokensBridged",
    ],
})
    .option("programId", {
    type: "string",
    demandOption: true,
    describe: "SvmSpokeProgram ID to query events from",
}).argv;
async function queryEvents() {
    const argv = await argvPromise;
    const eventName = argv.eventName || "any";
    const { programId } = argv;
    const { rpcEndpoint } = provider.connection;
    const rpc = (0, kit_1.createSolanaRpc)(rpcEndpoint);
    const rpcSubscriptions = (0, kit_1.createSolanaRpcSubscriptions)(rpcEndpoint.replace(/^http(s?):\/\//i, (_m, s) => `ws${s ?? ""}://`));
    const events = await (0, svm_2.readProgramEvents)({ rpc, rpcSubscriptions }, (0, kit_1.address)(programId), svm_1.SvmSpokeIdl, "confirmed");
    const filteredEvents = events.filter((e) => (eventName === "any" ? true : e.name === eventName));
    const formattedEvents = filteredEvents.map(web3_v1_1.stringifyCpiEvent);
    console.log(JSON.stringify(formattedEvents, null, 2));
}
// Run the queryEvents function
queryEvents();
