"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)("connector-send", "Call `Connector.send()` to distribute outbound root")
    .addOptionalParam("data", "Encoded Data (bytes)")
    .addOptionalParam("env", "Environment of contracts")
    .addOptionalParam("networkType", "Type of network of contracts")
    .setAction(async ({ data: _data, env: _env, networkType: _networkType }, { deployments, ethers }) => {
    let { deployer } = await ethers.getNamedSigners();
    if (!deployer) {
        [deployer] = await ethers.getUnnamedSigners();
    }
    const env = (0, utils_1.mustGetEnv)(_env);
    const networkType = _networkType ?? utils_1.ProtocolNetwork.TESTNET;
    console.log("networkType: ", networkType);
    console.log("env:", env);
    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 data = _data ?? "0x";
    const tx = await connector.send(data);
    console.log("connector send tx: ", tx);
    const receipt = await tx.wait();
    console.log("connector send tx mined: ", receipt.transactionHash);
});
//# sourceMappingURL=send.js.map