"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 () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
const logger_1 = require("../../../ts/logger");
const constants_1 = require("../../helpers/constants");
const ContractStorage_1 = require("../../helpers/ContractStorage");
const Deployment_1 = require("../../helpers/Deployment");
const types_1 = require("../../helpers/types");
const deployment = Deployment_1.Deployment.getInstance();
const storage = ContractStorage_1.ContractStorage.getInstance();
/**
 * Deploy step registration and task itself
 */
deployment
    .deployTask(constants_1.EDeploySteps.InitialVoiceCreditProxyFactory, "Deploy initial voice credit proxy factory")
    .then((task) => task.setAction(async ({ incremental }, hre) => {
    deployment.setHre(hre);
    const deployer = await deployment.getDeployer();
    const { deployConstantInitialVoiceCreditProxyFactory, deployERC20VotesInitialVoiceCreditProxyFactory } = await Promise.resolve().then(() => __importStar(require("../../../ts/deploy")));
    const voiceCreditProxyType = deployment.getDeployConfigField(types_1.EContracts.Poll, "initialVoiceCreditProxy");
    const needDeploy = deployment.getDeployConfigField(voiceCreditProxyType, "deploy");
    if (needDeploy === false) {
        return;
    }
    const skipDeployConstantInitialVoiceCreditProxy = voiceCreditProxyType !== types_1.EInitialVoiceCreditProxies.Constant;
    const skipDeployERC20VotesInitialVoiceCreditProxy = voiceCreditProxyType !== types_1.EInitialVoiceCreditProxies.ERC20Votes;
    if (!skipDeployConstantInitialVoiceCreditProxy) {
        const constantInitialVoiceCreditProxyFactoryAddress = storage.getAddress(types_1.EInitialVoiceCreditProxiesFactories.Constant, hre.network.name);
        if (incremental && constantInitialVoiceCreditProxyFactoryAddress) {
            (0, logger_1.logGreen)({
                text: (0, logger_1.info)(`Skipping deployment of the ${types_1.EInitialVoiceCreditProxiesFactories.Constant} contract`),
            });
            return;
        }
        const constantProxyFactoryAddress = storage.getAddress(types_1.EInitialVoiceCreditProxiesFactories.Constant, hre.network.name);
        const constantInitialVoiceCreditProxyContractFactory = constantProxyFactoryAddress
            ? await deployment.getContract({
                name: types_1.EContracts.ConstantInitialVoiceCreditProxyFactory,
                address: constantProxyFactoryAddress,
                signer: deployer,
            })
            : await deployConstantInitialVoiceCreditProxyFactory(deployer, true);
        await storage.register({
            id: types_1.EInitialVoiceCreditProxiesFactories.Constant,
            contract: constantInitialVoiceCreditProxyContractFactory,
            args: [],
            network: hre.network.name,
        });
    }
    if (!skipDeployERC20VotesInitialVoiceCreditProxy) {
        const erc20VotesInitialVoiceCreditProxyFactoryAddress = storage.getAddress(types_1.EInitialVoiceCreditProxiesFactories.ERC20Votes, hre.network.name);
        if (incremental && erc20VotesInitialVoiceCreditProxyFactoryAddress) {
            (0, logger_1.logGreen)({
                text: (0, logger_1.info)(`Skipping deployment of the ${types_1.EContracts.ERC20VotesInitialVoiceCreditProxyFactory} contract`),
            });
            return;
        }
        const erc20VotesProxyFactoryAddress = storage.getAddress(types_1.EInitialVoiceCreditProxiesFactories.ERC20Votes, hre.network.name);
        const erc20VotesInitialVoiceCreditProxyContractFactory = erc20VotesProxyFactoryAddress
            ? await deployment.getContract({
                name: types_1.EContracts.ERC20VotesInitialVoiceCreditProxyFactory,
                address: erc20VotesProxyFactoryAddress,
                signer: deployer,
            })
            : await deployERC20VotesInitialVoiceCreditProxyFactory(deployer, true);
        await storage.register({
            id: types_1.EInitialVoiceCreditProxiesFactories.ERC20Votes,
            contract: erc20VotesInitialVoiceCreditProxyContractFactory,
            args: [],
            network: hre.network.name,
        });
    }
}));
//# sourceMappingURL=09-voiceCreditProxyFactory.js.map