"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ethers_1 = require("ethers");
const config_1 = require("hardhat/config");
const utils_1 = require("../../src/utils");
exports.default = (0, config_1.task)("prove-and-process", "Call `Connector.proveAndProcess()` to process message")
    .addParam("message", "Message body to prove")
    .addOptionalParam("env", "Environment of contracts")
    .addOptionalParam("networkType", "Type of network of contracts")
    .setAction(async ({ env: _env, message, networkType: _networkType }, { deployments, ethers }) => {
    let { deployer } = await ethers.getNamedSigners();
    if (!deployer) {
        [deployer] = await ethers.getUnnamedSigners();
    }
    console.log("message:", message);
    const env = (0, utils_1.mustGetEnv)(_env);
    console.log("env:", env);
    const networkType = _networkType ?? utils_1.ProtocolNetwork.TESTNET;
    console.log("networkType: ", networkType);
    const network = await ethers.provider.getNetwork();
    const protocolConfig = (0, utils_1.getMessagingProtocolConfig)(networkType);
    const deploymentName = (0, utils_1.getDeploymentName)((0, utils_1.getConnectorName)(protocolConfig, +network.chainId), env);
    const deployment = await deployments.get(deploymentName);
    const address = deployment.address;
    console.log(deploymentName, "connector:", address);
    const connector = new ethers_1.Contract(address, deployment.abi, deployer);
    const { _proofs: proofs, _aggregateRoot: aggregateRoot, _aggregatePath: aggregatePath, _aggregateIndex: aggregateIndex, } = connector.interface.decodeFunctionData("proveAndProcess", message);
    // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
    const tx = await connector.proveAndProcess(proofs, aggregateRoot, aggregatePath, aggregateIndex);
    console.log("connector proveAndProcess tx: ", tx);
    const receipt = await tx.wait();
    console.log("connector proveAndProcess tx mined: ", receipt.transactionHash);
});
//# sourceMappingURL=proveAndProcess.js.map