"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());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.testConfig = void 0;
require("@keep-network/hardhat-helpers");
require("@keep-network/hardhat-local-networks-config");
require("@nomiclabs/hardhat-waffle");
require("@typechain/hardhat");
require("hardhat-deploy");
require("@tenderly/hardhat-tenderly");
require("hardhat-contract-sizer");
require("hardhat-dependency-compiler");
require("hardhat-gas-reporter");
require("./tasks");
var config_1 = require("hardhat/config");
var task_names_1 = require("hardhat/builtin-tasks/task-names");
var TASK_CHECK_ACCOUNTS_COUNT = "check-accounts-count";
var thresholdSolidityCompilerConfig = {
    version: "0.8.9",
    settings: {
        optimizer: {
            enabled: true,
            runs: 10,
        },
    },
};
// Configuration for testing environment.
exports.testConfig = {
    // How many accounts we expect to define for non-staking related signers, e.g.
    // deployer, thirdParty, governance.
    // It is used as an offset for getting accounts for operators and stakes registration.
    nonStakingAccountsCount: 10,
    // How many roles do we need to define for staking, i.e. stakeOwner, stakingProvider,
    // operator, beneficiary, authorizer.
    stakingRolesCount: 5,
    // Number of operators to register. Should be at least the same as group size.
    operatorsCount: 100,
};
var config = {
    solidity: {
        compilers: [
            {
                version: "0.8.9",
                settings: {
                    optimizer: {
                        enabled: true,
                        runs: 200,
                    },
                },
            },
        ],
        overrides: {
            "@threshold-network/solidity-contracts/contracts/staking/TokenStaking.sol": thresholdSolidityCompilerConfig,
        },
        settings: {
            outputSelection: {
                "*": {
                    "*": ["storageLayout"],
                },
            },
        },
    },
    paths: {
        artifacts: "./build",
    },
    networks: {
        hardhat: {
            forking: {
                // forking is enabled only if FORKING_URL env is provided
                enabled: !!process.env.FORKING_URL,
                // URL should point to a node with archival data (Alchemy recommended)
                url: process.env.FORKING_URL || "",
                // latest block is taken if FORKING_BLOCK env is not provided
                blockNumber: process.env.FORKING_BLOCK
                    ? parseInt(process.env.FORKING_BLOCK, 10)
                    : undefined,
            },
            accounts: {
                // Number of accounts that should be predefined on the testing environment.
                count: exports.testConfig.nonStakingAccountsCount +
                    exports.testConfig.stakingRolesCount * exports.testConfig.operatorsCount,
            },
            tags: ["local"],
            // we use higher gas price for tests to obtain more realistic results
            // for gas refund tests than when the default hardhat ~1 gwei gas price is
            // used
            gasPrice: 200000000000,
            // Ignore contract size on deployment to hardhat network, to be able to
            // deploy stub contracts in tests.
            allowUnlimitedContractSize: true,
        },
        development: {
            url: "http://localhost:8545",
            chainId: 1101,
            tags: ["local"],
        },
        ropsten: {
            url: process.env.CHAIN_API_URL || "",
            chainId: 3,
            accounts: process.env.CONTRACT_OWNER_ACCOUNT_PRIVATE_KEY
                ? [process.env.CONTRACT_OWNER_ACCOUNT_PRIVATE_KEY]
                : undefined,
            tags: ["tenderly"],
        },
    },
    // // Define local networks configuration file path to load networks from the file.
    // localNetworksConfig: "./.hardhat/networks.ts",
    tenderly: {
        username: "thesis",
        project: "",
    },
    namedAccounts: {
        deployer: {
            default: 1, // take the second account
            // mainnet: ""
        },
        governance: {
            default: 2,
            // mainnet: ""
        },
        esdm: {
            default: 3,
            // mainnet: ""
        },
    },
    external: {
        contracts: [
            {
                artifacts: "node_modules/@threshold-network/solidity-contracts/export/artifacts",
                deploy: "node_modules/@threshold-network/solidity-contracts/export/deploy",
            },
            {
                artifacts: "node_modules/@keep-network/random-beacon/export/artifacts",
                deploy: "node_modules/@keep-network/random-beacon/export/deploy",
            },
        ],
        // deployments: {
        //   // For hardhat environment we can fork the mainnet, so we need to point it
        //   // to the contract artifacts.
        //   hardhat: process.env.FORKING_URL ? ["./external/mainnet"] : [],
        //   // For development environment we expect the local dependencies to be linked
        //   // with `yarn link` command.
        //   development: ["node_modules/@keep-network/keep-core/artifacts"],
        //   ropsten: ["node_modules/@keep-network/keep-core/artifacts"],
        //   mainnet: ["./external/mainnet"],
        // },
    },
    dependencyCompiler: 
    // As a workaround for a slither issue https://github.com/crytic/slither/issues/1140
    // we disable compilation of dependencies when running slither.
    process.env.SKIP_DEPENDENCY_COMPILER === "true"
        ? undefined
        : {
            paths: [
                "@threshold-network/solidity-contracts/contracts/token/T.sol",
                "@threshold-network/solidity-contracts/contracts/staking/TokenStaking.sol",
                "@keep-network/random-beacon/contracts/api/IRandomBeacon.sol",
                "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol",
            ],
            keep: true,
        },
    contractSizer: {
        alphaSort: true,
        disambiguatePaths: false,
        runOnCompile: true,
        strict: true,
        except: ["contracts/test"],
    },
    mocha: {
        timeout: 60000,
    },
    typechain: {
        outDir: "typechain",
    },
};
(0, config_1.task)(task_names_1.TASK_TEST, "Runs mocha tests").setAction(function (args, hre, runSuper) { return __awaiter(void 0, void 0, void 0, function () {
    return __generator(this, function (_a) {
        switch (_a.label) {
            case 0: return [4 /*yield*/, hre.run(TASK_CHECK_ACCOUNTS_COUNT)];
            case 1:
                _a.sent();
                return [2 /*return*/, runSuper(args)];
        }
    });
}); });
(0, config_1.task)(TASK_CHECK_ACCOUNTS_COUNT, "Checks accounts count").setAction(function () { return __awaiter(void 0, void 0, void 0, function () {
    var constants;
    return __generator(this, function (_a) {
        constants = require("./test/fixtures").constants;
        if (exports.testConfig.operatorsCount < constants.groupSize) {
            throw new Error("not enough accounts predefined for configured group size: " +
                "expected group size: ".concat(constants.groupSize, " ") +
                "number of predefined accounts: ".concat(exports.testConfig.operatorsCount));
        }
        return [2 /*return*/];
    });
}); });
exports.default = config;
