"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 deploymentUtils_1 = require("../helpers/deploy/deploymentUtils");
const functionSignatures = {
    normal: [
        "setSendVersion(uint16)",
        "setReceiveVersion(uint16)",
        "setMaxDailyReceiveLimit(uint256)",
        "pause()",
        "setPrecrime(address)",
        "setMinDstGas(uint16,uint16,uint256)",
        "setPayloadSizeLimit(uint16,uint256)",
        "setConfig(uint16,uint16,uint256,bytes)",
        "addTimelocks(address[])",
        "setTrustedRemoteAddress(uint16,bytes)",
        "setTimelockPendingAdmin(address,uint8)",
        "retryMessage(uint16,bytes,uint64,bytes)",
        "setGuardian(address)",
        "setSrcChainId(uint16)",
        "transferBridgeOwnership(address)",
    ],
    fasttrack: [
        "setReceiveVersion(uint16)",
        "setMaxDailyReceiveLimit(uint256)",
        "pause()",
        "setConfig(uint16,uint16,uint256,bytes)",
        "addTimelocks(address[])",
        "retryMessage(uint16,bytes,uint64,bytes)",
    ],
    critical: [
        "setReceiveVersion(uint16)",
        "setMaxDailyReceiveLimit(uint256)",
        "pause()",
        "setConfig(uint16,uint16,uint256,bytes)",
        "addTimelocks(address[])",
        "retryMessage(uint16,bytes,uint64,bytes)",
    ],
    guardian: [
        "setReceiveVersion(uint16)",
        "forceResumeReceive(uint16,bytes)",
        "setMaxDailyReceiveLimit(uint256)",
        "pause()",
        "unpause()",
        "setConfig(uint16,uint16,uint256,bytes)",
        "addTimelocks(address[])",
        "setTrustedRemoteAddress(uint16,bytes)",
        "setTimelockPendingAdmin(address,uint8)",
        "retryMessage(uint16,bytes,uint64,bytes)",
        "setSrcChainId(uint16)",
        "transferBridgeOwnership(address)",
    ],
};
const grantPermissions = (OMNICHAIN_EXECUTOR_OWNER, functionSigs, account) => functionSigs.map(functionSig => ({
    contractAddress: OMNICHAIN_EXECUTOR_OWNER,
    functionSig: functionSig,
    account: account,
}));
const func = function () {
    var _a, _b;
    return __awaiter(this, void 0, void 0, function* () {
        const NORMAL_TIMELOCK = yield hardhat_1.ethers.getContract("NormalTimelock");
        const FASTTRACK_TIMELOCK = yield hardhat_1.ethers.getContract("FastTrackTimelock");
        const CRITICAL_TIMELOCK = yield hardhat_1.ethers.getContract("CriticalTimelock");
        const OMNICHAIN_EXECUTOR_OWNER = yield hardhat_1.ethers.getContract("OmnichainExecutorOwner");
        const GUARDIAN = yield (0, deploymentUtils_1.guardian)(hardhat_1.network.name);
        const acmCommandsAggregator = yield hardhat_1.ethers.getContract("ACMCommandsAggregator");
        const normalGrantPermissions = grantPermissions(OMNICHAIN_EXECUTOR_OWNER.address, functionSignatures.normal, NORMAL_TIMELOCK.address);
        const fasttrackGrantPermissions = grantPermissions(OMNICHAIN_EXECUTOR_OWNER.address, functionSignatures.fasttrack, FASTTRACK_TIMELOCK.address);
        const criticalGrantPermissions = grantPermissions(OMNICHAIN_EXECUTOR_OWNER.address, functionSignatures.critical, CRITICAL_TIMELOCK.address);
        const guardianGrantPermissions = grantPermissions(OMNICHAIN_EXECUTOR_OWNER.address, functionSignatures.guardian, GUARDIAN);
        const allGrantPermissions = [
            ...normalGrantPermissions,
            ...fasttrackGrantPermissions,
            ...criticalGrantPermissions,
            ...guardianGrantPermissions,
        ];
        try {
            const tx = yield acmCommandsAggregator.addGrantPermissions(allGrantPermissions);
            const receipt = yield tx.wait();
            const events = (_a = receipt.events) === null || _a === void 0 ? void 0 : _a.filter(event => event.event === "GrantPermissionsAdded");
            console.log(`Grant Permissions for ${hardhat_1.network.name} added with indexes: `, (_b = events === null || events === void 0 ? void 0 : events[0].args) === null || _b === void 0 ? void 0 : _b.index.toString());
        }
        catch (error) {
            console.error("Error adding grant permissions:", error);
        }
    });
};
func.tags = ["multichain-governance-permissions"];
func.skip = (hre) => __awaiter(void 0, void 0, void 0, function* () { return hre.network.name === "bsctestnet" || hre.network.name === "bscmainnet"; });
exports.default = func;
//# sourceMappingURL=009-initial-configuration-multichain-governance.js.map