"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
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 = __importStar(require("@coral-xyz/anchor"));
const anchor_1 = require("@coral-xyz/anchor");
const yargs_1 = __importDefault(require("yargs"));
const helpers_1 = require("yargs/helpers");
const web3_v1_1 = require("../../src/svm/web3-v1");
// Set up the provider
const provider = anchor_1.AnchorProvider.env();
anchor.setProvider(provider);
const idl = require("../../target/idl/svm_spoke.json");
const program = new anchor_1.Program(idl, provider);
const programId = program.programId;
console.log("SVM-Spoke Program ID:", programId.toString());
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",
        "filledRelay",
        "fundsDeposited",
        "enabledDepositRoute",
        "relayedRootBundle",
        "executedRelayerRefundRoot",
        "bridgedToHubPool",
        "pausedDeposits",
        "pausedFills",
        "setXDomainAdmin",
        "emergencyDeletedRootBundle",
        "RequestedSlowFill",
        "claimedRelayerRefund",
        "tokensBridged",
    ],
}).argv;
async function queryEvents() {
    const argv = await argvPromise;
    const eventName = argv.eventName || "any";
    const events = await (0, web3_v1_1.readProgramEvents)(provider.connection, program, "confirmed");
    const filteredEvents = events.filter((event) => (eventName == "any" ? true : event.name == eventName));
    const formattedEvents = filteredEvents.map((event) => (0, web3_v1_1.stringifyCpiEvent)(event));
    console.log(JSON.stringify(formattedEvents, null, 2));
}
// Run the queryEvents function
queryEvents();
