"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const hardhat_1 = require("hardhat");
const SUPPORTED_NETWORKS = [
    "bscmainnet",
    "ethereum",
    "sepolia",
    "arbitrumone",
    "arbitrumsepolia",
    "basemainnet",
    "basesepolia",
    "zksyncmainnet",
    "zksyncsepolia",
];
const func = function (hre) {
    return __awaiter(this, void 0, void 0, function* () {
        const { deployments, getNamedAccounts } = hre;
        const { deploy } = deployments;
        const { deployer } = yield getNamedAccounts();
        const acm = yield hardhat_1.ethers.getContract("AccessControlManager");
        const normalTimelockAddress = (yield hardhat_1.ethers.getContract("NormalTimelock")).address;
        const proxyOwnerAddress = hre.network.name === "hardhat" ? deployer : normalTimelockAddress;
        const defaultProxyAdmin = yield hre.artifacts.readArtifact("hardhat-deploy/solc_0.8/openzeppelin/proxy/transparent/ProxyAdmin.sol:ProxyAdmin");
        yield deploy("AuxiliaryCommandsAggregator", {
            contract: "AuxiliaryCommandsAggregator",
            from: deployer,
            args: [],
            log: true,
            autoMine: true,
            proxy: {
                owner: proxyOwnerAddress,
                proxyContract: "OptimizedTransparentUpgradeableProxy",
                execute: {
                    methodName: "initialize",
                    args: [acm.address],
                },
                viaAdminContract: {
                    name: "DefaultProxyAdmin",
                    artifact: defaultProxyAdmin,
                },
            },
            skipIfAlreadyDeployed: true,
        });
        const aggregator = yield hardhat_1.ethers.getContract("AuxiliaryCommandsAggregator");
        if ((yield aggregator.owner()) === deployer) {
            const tx = yield aggregator.transferOwnership(normalTimelockAddress);
            yield tx.wait();
            console.log(`AuxiliaryCommandsAggregator ownership transfer to ${normalTimelockAddress} initiated`);
        }
    });
};
func.tags = ["AuxiliaryCommandsAggregator"];
func.skip = (hre) => __awaiter(void 0, void 0, void 0, function* () { return !SUPPORTED_NETWORKS.includes(hre.network.name); });
exports.default = func;
//# sourceMappingURL=014-auxiliary-commands-aggregator.js.map