"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 Addresses_1 = require("../helpers/Addresses");
const permissions_1 = require("../helpers/permissions");
const getRedstoneOraclePermissionsRevokedPreviously = (redstoneOracle, guardian) => {
    return [
        [redstoneOracle, "setTokenConfig(TokenConfig)", guardian],
        [redstoneOracle, "setDirectPrice(address,uint256)", guardian],
    ];
};
const BSCMAINNET_REDSTONE_ORACLE = "0x8455EFA4D7Ff63b8BFD96AdD889483Ea7d39B70a";
const BSCTESTNET_REDSTONE_ORACLE = "0x0Af51d1504ac5B711A9EAFe2fAC11A51d32029Ad";
const BSCMAINNET_GUARDIAN = "0x3a3284dC0FaFfb0b5F0d074c4C704D14326C98cF";
const BSCTESTNET_GUARDIAN = "0xFEA1c651A47FE29dB9b1bf3cC1f224d8D9CFF68C";
const grantPermissions = {
    arbitrumone: [...getRedstoneOraclePermissionsRevokedPreviously(Addresses_1.ARBITRUMONE_REDSTONE_ORACLE, Addresses_1.ARBITRUMONE_GUARDIAN)],
    arbitrumsepolia: [
        ...getRedstoneOraclePermissionsRevokedPreviously(Addresses_1.ARBITRUMSEPOLIA_REDSTONE_ORACLE, Addresses_1.ARBITRUMSEPOLIA_GUARDIAN),
    ],
    ethereum: [...getRedstoneOraclePermissionsRevokedPreviously(Addresses_1.ETHEREUM_REDSTONE_ORACLE, Addresses_1.ETHEREUM_GUARDIAN)],
    sepolia: [...getRedstoneOraclePermissionsRevokedPreviously(Addresses_1.SEPOLIA_REDSTONE_ORACLE, Addresses_1.SEPOLIA_GUARDIAN)],
    bscmainnet: [...getRedstoneOraclePermissionsRevokedPreviously(BSCMAINNET_REDSTONE_ORACLE, BSCMAINNET_GUARDIAN)],
    bsctestnet: [...getRedstoneOraclePermissionsRevokedPreviously(BSCTESTNET_REDSTONE_ORACLE, BSCTESTNET_GUARDIAN)],
};
const revokePermissions = {
    arbitrumone: [...(0, permissions_1.getXVSVaultRevokePermissions)(Addresses_1.ARBITRUMONE_XVS_VAULT_PROXY, Addresses_1.ARBITRUMONE_GUARDIAN)],
    arbitrumsepolia: [...(0, permissions_1.getXVSVaultRevokePermissions)(Addresses_1.ARBITRUMSEPOLIA_XVS_VAULT_PROXY, Addresses_1.ARBITRUMSEPOLIA_GUARDIAN)],
    ethereum: [...(0, permissions_1.getXVSVaultRevokePermissions)(Addresses_1.ETHEREUM_XVS_VAULT_PROXY, Addresses_1.ETHEREUM_GUARDIAN)],
    sepolia: [...(0, permissions_1.getXVSVaultRevokePermissions)(Addresses_1.SEPOLIA_XVS_VAULT_PROXY, Addresses_1.SEPOLIA_GUARDIAN)],
    opbnbmainnet: [...(0, permissions_1.getXVSVaultRevokePermissions)(Addresses_1.OPBNBMAINNET_XVS_VAULT_PROXY, Addresses_1.OPBNBMAINNET_GUARDIAN)],
    opbnbtestnet: [...(0, permissions_1.getXVSVaultRevokePermissions)(Addresses_1.OPBNBTESTNET_XVS_VAULT_PROXY, Addresses_1.OPBNBTESTNET_GUARDIAN)],
};
const func = function (hre) {
    var _a, _b, _c, _d;
    return __awaiter(this, void 0, void 0, function* () {
        const acmCommandsAggregator = yield hardhat_1.ethers.getContract("ACMCommandsAggregator");
        const _grantPermissions = grantPermissions[hre.network.name].map(permission => ({
            contractAddress: permission[0],
            functionSig: permission[1],
            account: permission[2],
        }));
        const _revokePermissions = revokePermissions[hre.network.name].map(permission => ({
            contractAddress: permission[0],
            functionSig: permission[1],
            account: permission[2],
        }));
        try {
            let tx = yield acmCommandsAggregator.addGrantPermissions(_grantPermissions);
            let receipt = yield tx.wait();
            let events = (_a = receipt.events) === null || _a === void 0 ? void 0 : _a.filter(event => event.event === "GrantPermissionsAdded");
            console.log(`Grant Permissions for ${hre.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());
            tx = yield acmCommandsAggregator.addRevokePermissions(_revokePermissions);
            receipt = yield tx.wait();
            events = (_c = receipt.events) === null || _c === void 0 ? void 0 : _c.filter(event => event.event === "RevokePermissionsAdded");
            console.log(`Revoke Permissions for ${hre.network.name} added with indexes: `, (_d = events === null || events === void 0 ? void 0 : events[0].args) === null || _d === void 0 ? void 0 : _d.index.toString());
        }
        catch (error) {
            console.error("Error adding adding permissions:", error);
        }
    });
};
func.tags = ["redstone-vault-permissions"];
func.skip = (hre) => __awaiter(void 0, void 0, void 0, function* () { return hre.network.name === "hardhat"; });
exports.default = func;
//# sourceMappingURL=010-redstone-and-vault-permission.js.map