"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 func = function (hre) {
    return __awaiter(this, void 0, void 0, function* () {
        const { deployments, getNamedAccounts } = hre;
        const { deploy } = deployments;
        const { deployer } = yield getNamedAccounts();
        const acmDeployment = yield deploy("AccessControlManager", {
            from: deployer,
            args: [],
            log: true,
            autoMine: true,
            skipIfAlreadyDeployed: true,
        });
        const acm = yield hardhat_1.ethers.getContractAt("AccessControlManager", acmDeployment.address);
        if (hre.network.live) {
            const networkName = hre.network.name;
            const normalTimelock = yield hardhat_1.ethers.getContract("NormalTimelock");
            console.log(`Granting DEFAULT_ADMIN_ROLE to ${normalTimelock.address} for ${networkName} network`);
            yield acm.grantRole(acm.DEFAULT_ADMIN_ROLE(), normalTimelock.address);
            console.log(`Renouncing DEFAULT_ADMIN_ROLE from deployer (${deployer}) for ${hre.network.name} network`);
            yield acm.renounceRole(acm.DEFAULT_ADMIN_ROLE(), deployer);
        }
        else {
            const timelockAddress = (yield hardhat_1.ethers.getContract("NormalTimelock")).address;
            yield acm.grantRole(acm.DEFAULT_ADMIN_ROLE(), timelockAddress);
        }
    });
};
func.tags = ["AccessControl"];
exports.default = func;
//# sourceMappingURL=002-access-control.js.map