"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-disable no-console */
const ethers_1 = require("ethers");
const config_1 = require("hardhat/config");
const logger_1 = require("../../ts/logger");
const Deployment_1 = require("../helpers/Deployment");
const TreeMerger_1 = require("../helpers/TreeMerger");
const types_1 = require("../helpers/types");
/**
 * Command to merge signups of a MACI contract
 */
(0, config_1.task)("merge", "Merge signups")
    .addParam("poll", "The poll id", undefined, config_1.types.string)
    .setAction(async ({ poll }, hre) => {
    const deployment = Deployment_1.Deployment.getInstance({ hre });
    deployment.setHre(hre);
    const deployer = await deployment.getDeployer();
    const maciContract = await deployment.getContract({ name: types_1.EContracts.MACI });
    const pollContracts = await maciContract.polls(poll);
    if (pollContracts.poll === ethers_1.ZeroAddress) {
        throw new Error(`No poll ${poll} found`);
    }
    const pollContract = await deployment.getContract({
        name: types_1.EContracts.Poll,
        address: pollContracts.poll,
    });
    const treeMerger = new TreeMerger_1.TreeMerger({
        deployer,
        pollContract,
    });
    const startBalance = await deployer.provider.getBalance(deployer);
    (0, logger_1.logMagenta)({ text: (0, logger_1.info)(`Start balance: ${Number(startBalance / 10n ** 12n) / 1e6}`) });
    await treeMerger.checkPollDuration();
    await treeMerger.mergeSignups();
    const endBalance = await deployer.provider.getBalance(deployer);
    (0, logger_1.logMagenta)({ text: (0, logger_1.info)(`End balance: ${Number(endBalance / 10n ** 12n) / 1e6}`) });
    (0, logger_1.logMagenta)({ text: (0, logger_1.info)(`Merge expenses: ${Number((startBalance - endBalance) / 10n ** 12n) / 1e6}`) });
});
//# sourceMappingURL=merge.js.map