"use strict";
// This script initializes a SVM spoke pool with initialization parameters.
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 });
const anchor = __importStar(require("@coral-xyz/anchor"));
const anchor_1 = require("@coral-xyz/anchor");
const web3_js_1 = require("@solana/web3.js");
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 program = (0, web3_v1_1.getSpokePoolProgram)(provider);
const programId = program.programId;
// Parse arguments
const argv = (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
    .option("seed", { type: "string", demandOption: true, describe: "Seed for the state account PDA" })
    .option("initNumbDeposits", { type: "string", demandOption: true, describe: "Init numb of deposits" })
    .option("chainId", { type: "string", demandOption: true, describe: "Chain ID" })
    .option("remoteDomain", { type: "number", demandOption: true, describe: "CCTP domain for Mainnet Ethereum" })
    .option("crossDomainAdmin", { type: "string", demandOption: true, describe: "HubPool on Mainnet Ethereum" })
    .option("depositQuoteTimeBuffer", {
    type: "number",
    demandOption: false,
    default: 3600,
    describe: "Deposit quote time buffer",
})
    .option("fillDeadlineBuffer", {
    type: "number",
    demandOption: false,
    default: 3600 * 4,
    describe: "Fill deadline buffer",
}).argv;
async function initialize() {
    const resolvedArgv = await argv;
    const seed = new anchor_1.BN(resolvedArgv.seed);
    const initialNumberOfDeposits = new anchor_1.BN(resolvedArgv.initNumbDeposits);
    const chainId = new anchor_1.BN(resolvedArgv.chainId);
    const remoteDomain = resolvedArgv.remoteDomain;
    const crossDomainAdmin = (0, web3_v1_1.evmAddressToPublicKey)(resolvedArgv.crossDomainAdmin); // Use the function to cast the value
    const depositQuoteTimeBuffer = resolvedArgv.depositQuoteTimeBuffer;
    const fillDeadlineBuffer = resolvedArgv.fillDeadlineBuffer;
    // Define the state account PDA
    console.log("Seed:", seed.toString());
    console.log("seed.toArrayLike(Buffer", new anchor_1.BN(seed).toArrayLike(Buffer, "le", 8));
    const [statePda, _] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("state"), new anchor_1.BN(seed).toArrayLike(Buffer, "le", 8)], programId);
    // Define the signer (replace with your actual signer)
    const signer = provider.wallet.publicKey;
    console.log("Initializing...");
    console.table([
        { Property: "seed", Value: seed.toString() },
        { Property: "initialNumberOfDeposits", Value: initialNumberOfDeposits.toString() },
        { Property: "programId", Value: programId.toString() },
        { Property: "providerPublicKey", Value: provider.wallet.publicKey.toString() },
        { Property: "statePda", Value: statePda.toString() },
        { Property: "chainId", Value: chainId.toString() },
        { Property: "remoteDomain", Value: remoteDomain.toString() },
        { Property: "crossDomainAdmin", Value: crossDomainAdmin.toString() },
        { Property: "depositQuoteTimeBuffer", Value: depositQuoteTimeBuffer.toString() },
        { Property: "fillDeadlineBuffer", Value: fillDeadlineBuffer.toString() },
    ]);
    const tx = await program.methods.initialize(seed, initialNumberOfDeposits.toNumber(), chainId, remoteDomain, crossDomainAdmin, depositQuoteTimeBuffer, fillDeadlineBuffer)
        .accounts({
        state: statePda,
        signer: signer,
        systemProgram: web3_js_1.SystemProgram.programId,
    })
        .rpc();
    console.log("Transaction signature:", tx);
}
// Run the initialize function
initialize();
