"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const { subtask } = require("hardhat/config");
const { TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS } = require("hardhat/builtin-tasks/task-names");
const isTest = process.env.IS_TEST === "true" || process.env.CI === "true";
subtask(TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS).setAction(async (_, __, runSuper) => {
    const paths = await runSuper();
    // Filter out files that cause problems when using "paris" hardfork (currently used to compile everything when IS_TEST=true)
    // Reference: https://github.com/NomicFoundation/hardhat/issues/2306#issuecomment-1039452928
    if (isTest) {
        return paths.filter((p) => {
            return (!p.includes("contracts/periphery/mintburn") &&
                !p.includes("contracts/external/libraries/BytesLib.sol") &&
                !p.includes("contracts/libraries/SponsoredCCTPQuoteLib.sol") &&
                !p.includes("contracts/external/libraries/MinimalLZOptions.sol"));
        });
    }
    return paths;
});
const dotenv = __importStar(require("dotenv"));
dotenv.config();
const constants_1 = require("./utils/constants");
const utils_1 = require("./utils");
require("@nomicfoundation/hardhat-verify"); // Must be above hardhat-upgrades
require("@nomiclabs/hardhat-waffle");
require("@matterlabs/hardhat-zksync-solc");
require("@matterlabs/hardhat-zksync-verify");
require("@matterlabs/hardhat-zksync-upgradable");
require("hardhat-gas-reporter");
require("solidity-coverage");
require("hardhat-deploy");
require("@openzeppelin/hardhat-upgrades");
const getMnemonic = () => {
    // Publicly-disclosed mnemonic. This is required for hre deployments in test.
    const PUBLIC_MNEMONIC = "candy maple cake sugar pudding cream honey rich smooth crumble sweet treat";
    const { MNEMONIC = PUBLIC_MNEMONIC } = process.env;
    return MNEMONIC;
};
const mnemonic = getMnemonic();
const getDefaultHardhatConfig = (chainId, isTestnet = false) => {
    return {
        chainId,
        url: (0, utils_1.getNodeUrl)(chainId),
        accounts: { mnemonic },
        saveDeployments: true,
        companionNetworks: { l1: isTestnet ? "sepolia" : "mainnet" },
    };
};
// Custom tasks to add to HRE.
const tasks = [
    "enableL1TokenAcrossEcosystem",
    "finalizeScrollClaims",
    "rescueStuckScrollTxn",
    "verifySpokePool",
    "verifyBytecode",
    "evmRelayMessageWithdrawal",
    "testChainAdapter",
    "upgradeSpokePool",
];
// eslint-disable-next-line node/no-missing-require
tasks.forEach((task) => require(`./tasks/${task}`));
// To compile with zksolc, `hardhat` must be the default network and its `zksync` property must be true.
// So we allow the caller to set this environment variable to toggle compiling zk contracts or not.
// TODO: Figure out way to only compile specific contracts intended to be deployed on ZkSync (e.g. ZkSync_SpokePool) if
// the following config is true.
const compileZk = process.env.COMPILE_ZK === "true";
const solcVersion = "0.8.30";
// Hardhat 2.14.0 doesn't support prague yet, so we use paris instead (need to upgrade to v3 to use prague)
const evmVersion = isTest ? "paris" : "prague";
const revertStrings = isTest ? "debug" : "strip";
// Compilation settings are overridden for large contracts to allow them to compile without going over the bytecode
// limit.
const LARGE_CONTRACT_COMPILER_SETTINGS = {
    version: solcVersion,
    settings: {
        optimizer: { enabled: true, runs: 800 },
        viaIR: true,
        evmVersion,
        debug: { revertStrings },
    },
};
const DEFAULT_CONTRACT_COMPILER_SETTINGS = {
    version: solcVersion,
    settings: {
        optimizer: { enabled: true, runs: 1000000 },
        viaIR: true,
        evmVersion,
        // Only strip revert strings if not testing or in ci.
        debug: { revertStrings },
    },
};
// This is only used by Blast_SpokePool for now, as it's the largest bytecode-wise
const LARGEST_CONTRACT_COMPILER_SETTINGS = {
    version: solcVersion,
    settings: {
        optimizer: { enabled: true, runs: 50 },
        viaIR: true,
        evmVersion,
        debug: { revertStrings },
    },
};
const config = {
    solidity: {
        compilers: [DEFAULT_CONTRACT_COMPILER_SETTINGS],
        overrides: {
            "contracts/HubPool.sol": LARGE_CONTRACT_COMPILER_SETTINGS,
            "contracts/Linea_SpokePool.sol": LARGE_CONTRACT_COMPILER_SETTINGS,
            "contracts/Universal_SpokePool.sol": LARGE_CONTRACT_COMPILER_SETTINGS,
            "contracts/Arbitrum_SpokePool.sol": LARGE_CONTRACT_COMPILER_SETTINGS,
            "contracts/Scroll_SpokePool.sol": LARGE_CONTRACT_COMPILER_SETTINGS,
            "contracts/Lisk_SpokePool.sol": LARGE_CONTRACT_COMPILER_SETTINGS,
            "contracts/OP_SpokePool.sol": LARGE_CONTRACT_COMPILER_SETTINGS,
            "contracts/Optimism_SpokePool.sol": LARGE_CONTRACT_COMPILER_SETTINGS,
            "contracts/WorldChain_SpokePool.sol": LARGE_CONTRACT_COMPILER_SETTINGS,
            "contracts/Ink_SpokePool.sol": LARGE_CONTRACT_COMPILER_SETTINGS,
            "contracts/Cher_SpokePool.sol": LARGE_CONTRACT_COMPILER_SETTINGS,
            "contracts/Blast_SpokePool.sol": LARGEST_CONTRACT_COMPILER_SETTINGS,
            "contracts/Tatara_SpokePool.sol": LARGE_CONTRACT_COMPILER_SETTINGS,
            "contracts/periphery/mintburn/HyperCoreFlowExecutor.sol": LARGE_CONTRACT_COMPILER_SETTINGS,
        },
    },
    zksolc: {
        version: "1.5.7",
        settings: {
            optimizer: {
                enabled: true,
            },
            suppressedErrors: ["sendtransfer"],
            contractsToCompile: [
                "SpokePoolPeriphery",
                "MulticallHandler",
                "SpokePoolVerifier",
                "ZkSync_SpokePool",
                "Lens_SpokePool",
                "AcrossEventEmitter",
            ],
        },
    },
    networks: {
        hardhat: {
            accounts: { accountsBalance: "1000000000000000000000000" },
            zksync: compileZk,
            allowUnlimitedContractSize: true,
        },
        mainnet: getDefaultHardhatConfig(constants_1.CHAIN_IDs.MAINNET),
        zksync: {
            chainId: constants_1.CHAIN_IDs.ZK_SYNC,
            url: (0, utils_1.getNodeUrl)(constants_1.CHAIN_IDs.ZK_SYNC),
            saveDeployments: true,
            accounts: { mnemonic },
            ethNetwork: "mainnet",
            companionNetworks: { l1: "mainnet" },
            zksync: true,
            verifyURL: "https://zksync2-mainnet-explorer.zksync.io/contract_verification",
        },
        optimism: getDefaultHardhatConfig(constants_1.CHAIN_IDs.OPTIMISM),
        "optimism-sepolia": getDefaultHardhatConfig(constants_1.CHAIN_IDs.OPTIMISM_SEPOLIA, true),
        arbitrum: getDefaultHardhatConfig(constants_1.CHAIN_IDs.ARBITRUM),
        "arbitrum-sepolia": getDefaultHardhatConfig(constants_1.CHAIN_IDs.ARBITRUM_SEPOLIA, true),
        sepolia: getDefaultHardhatConfig(constants_1.CHAIN_IDs.SEPOLIA, true),
        polygon: getDefaultHardhatConfig(constants_1.CHAIN_IDs.POLYGON),
        bsc: {
            ...getDefaultHardhatConfig(constants_1.CHAIN_IDs.BSC),
            gas: "auto",
            gasPrice: 3e8, // 0.3 GWEI
            gasMultiplier: 4.0,
        },
        hyperevm: getDefaultHardhatConfig(constants_1.CHAIN_IDs.HYPEREVM),
        "hyperevm-testnet": getDefaultHardhatConfig(constants_1.CHAIN_IDs.HYPEREVM_TESTNET, true),
        monad: getDefaultHardhatConfig(constants_1.CHAIN_IDs.MONAD),
        "polygon-amoy": getDefaultHardhatConfig(constants_1.CHAIN_IDs.POLYGON_AMOY),
        base: getDefaultHardhatConfig(constants_1.CHAIN_IDs.BASE),
        "base-sepolia": getDefaultHardhatConfig(constants_1.CHAIN_IDs.BASE_SEPOLIA, true),
        ink: getDefaultHardhatConfig(constants_1.CHAIN_IDs.INK),
        linea: getDefaultHardhatConfig(constants_1.CHAIN_IDs.LINEA),
        plasma: getDefaultHardhatConfig(constants_1.CHAIN_IDs.PLASMA),
        scroll: getDefaultHardhatConfig(constants_1.CHAIN_IDs.SCROLL),
        "scroll-sepolia": getDefaultHardhatConfig(constants_1.CHAIN_IDs.SCROLL_SEPOLIA, true),
        "polygon-zk-evm": {
            chainId: 1101,
            url: "https://zkevm-rpc.com",
            saveDeployments: true,
            accounts: { mnemonic },
            companionNetworks: { l1: "mainnet" },
        },
        "polygon-zk-evm-testnet": {
            chainId: 1442,
            url: "https://rpc.public.zkevm-test.net",
            saveDeployments: true,
            accounts: { mnemonic },
            companionNetworks: { l1: "goerli" },
        },
        mode: getDefaultHardhatConfig(constants_1.CHAIN_IDs.MODE),
        "mode-sepolia": getDefaultHardhatConfig(constants_1.CHAIN_IDs.MODE_SEPOLIA, true),
        tatara: {
            chainId: constants_1.CHAIN_IDs.TATARA,
            url: (0, utils_1.getNodeUrl)(constants_1.CHAIN_IDs.TATARA),
            saveDeployments: true,
            accounts: { mnemonic },
            companionNetworks: { l1: "sepolia" },
            ethNetwork: "sepolia",
        },
        lens: {
            chainId: constants_1.CHAIN_IDs.LENS,
            url: (0, utils_1.getNodeUrl)(constants_1.CHAIN_IDs.LENS),
            saveDeployments: true,
            accounts: { mnemonic },
            companionNetworks: { l1: "mainnet" },
            ethNetwork: "mainnet",
            verifyURL: "https://verify.lens.xyz/contract_verification",
            zksync: true,
        },
        "lens-sepolia": {
            chainId: constants_1.CHAIN_IDs.LENS_SEPOLIA,
            url: (0, utils_1.getNodeUrl)(constants_1.CHAIN_IDs.LENS_SEPOLIA),
            saveDeployments: true,
            accounts: { mnemonic },
            companionNetworks: { l1: "sepolia" },
            ethNetwork: "sepolia",
            verifyURL: "https://block-explorer-verify.testnet.lens.dev/contract_verification",
            zksync: true,
        },
        lisk: getDefaultHardhatConfig(constants_1.CHAIN_IDs.LISK),
        "lisk-sepolia": getDefaultHardhatConfig(constants_1.CHAIN_IDs.LISK_SEPOLIA, true),
        redstone: getDefaultHardhatConfig(constants_1.CHAIN_IDs.REDSTONE),
        blast: getDefaultHardhatConfig(constants_1.CHAIN_IDs.BLAST),
        "blast-sepolia": getDefaultHardhatConfig(constants_1.CHAIN_IDs.BLAST_SEPOLIA, true),
        worldchain: getDefaultHardhatConfig(constants_1.CHAIN_IDs.WORLD_CHAIN),
        zora: getDefaultHardhatConfig(constants_1.CHAIN_IDs.ZORA),
        soneium: getDefaultHardhatConfig(constants_1.CHAIN_IDs.SONEIUM),
        unichain: getDefaultHardhatConfig(constants_1.CHAIN_IDs.UNICHAIN),
        "unichain-sepolia": getDefaultHardhatConfig(constants_1.CHAIN_IDs.UNICHAIN_SEPOLIA, true),
        "bob-sepolia": getDefaultHardhatConfig(constants_1.CHAIN_IDs.BOB_SEPOLIA, true),
    },
    gasReporter: { enabled: process.env.REPORT_GAS !== undefined, currency: "USD" },
    etherscan: {
        apiKey: process.env.ETHERSCAN_API_KEY,
        customChains: [
            {
                network: "blast",
                chainId: constants_1.CHAIN_IDs.BLAST,
                urls: {
                    apiURL: "https://blastscan.io/api",
                    browserURL: "https://blastscan.io",
                },
            },
            {
                network: "hyperevm",
                chainId: constants_1.CHAIN_IDs.HYPEREVM,
                urls: {
                    apiURL: "https://hyperevmscan.io/api",
                    browserURL: "https://hyperevmscan.io",
                },
            },
            {
                network: "linea",
                chainId: constants_1.CHAIN_IDs.LINEA,
                urls: {
                    apiURL: "https://lineascan.build/api",
                    browserURL: "https://lineascan.build",
                },
            },
            {
                network: "scroll",
                chainId: constants_1.CHAIN_IDs.SCROLL,
                urls: {
                    apiURL: "https://api.scrollscan.com/api",
                    browserURL: "https://scrollscan.com",
                },
            },
            {
                network: "unichain",
                chainId: constants_1.CHAIN_IDs.UNICHAIN,
                urls: {
                    apiURL: "https://api.uniscan.xyz/api",
                    browserURL: "https://uniscan.xyz",
                },
            },
            {
                network: "zksync",
                chainId: constants_1.CHAIN_IDs.ZK_SYNC,
                urls: {
                    apiURL: "https://zksync2-mainnet-explorer.zksync.io/contract_verification",
                    browserURL: "https://era.zksync.network/",
                },
            },
            {
                network: "lens",
                chainId: constants_1.CHAIN_IDs.LENS,
                urls: {
                    apiURL: "https://verify.lens.xyz/contract_verification",
                    browserURL: "https://explorer.lens.xyz/",
                },
            },
        ],
    },
    blockscout: {
        enabled: true,
        customChains: [
            {
                network: "bob-sepolia",
                chainId: constants_1.CHAIN_IDs.BOB_SEPOLIA,
                urls: {
                    apiURL: "https://bob-sepolia.explorer.gobob.xyz/api",
                    browserURL: "https://bob-sepolia.explorer.gobob.xyz",
                },
            },
            {
                network: "ink",
                chainId: constants_1.CHAIN_IDs.INK,
                urls: {
                    apiURL: "https://explorer.inkonchain.com/api",
                    browserURL: "https://explorer.inkonchain.com",
                },
            },
            {
                network: "lisk",
                chainId: constants_1.CHAIN_IDs.LISK,
                urls: {
                    apiURL: "https://blockscout.lisk.com/api",
                    browserURL: "https://blockscout.lisk.com",
                },
            },
            {
                network: "lisk-sepolia",
                chainId: constants_1.CHAIN_IDs.LISK_SEPOLIA,
                urls: {
                    apiURL: "https://sepolia-blockscout.lisk.com/api",
                    browserURL: "https://sepolia-blockscout.lisk.com",
                },
            },
            {
                network: "mode",
                chainId: constants_1.CHAIN_IDs.MODE,
                urls: {
                    apiURL: "https://explorer.mode.network/api",
                    browserURL: "https://explorer.mode.network/",
                },
            },
            {
                network: "mode-sepolia",
                chainId: constants_1.CHAIN_IDs.MODE_SEPOLIA,
                urls: {
                    apiURL: "https://api.routescan.io/v2/network/testnet/evm/919/etherscan",
                    browserURL: "https://testnet.modescan.io",
                },
            },
            {
                network: "redstone",
                chainId: constants_1.CHAIN_IDs.REDSTONE,
                urls: {
                    apiURL: "https://explorer.redstone.xyz/api",
                    browserURL: "https://explorer.redstone.xyz",
                },
            },
            {
                network: "plasma",
                chainId: 9745,
                urls: {
                    apiURL: "https://api.routescan.io/v2/network/mainnet/evm/9745/etherscan",
                    browserURL: "https://plasmascan.to",
                },
            },
            {
                network: "soneium",
                chainId: constants_1.CHAIN_IDs.SONEIUM,
                urls: {
                    apiURL: "https://soneium.blockscout.com/api",
                    browserURL: "https://soneium.blockscout.com",
                },
            },
            {
                network: "tatara",
                chainId: constants_1.CHAIN_IDs.TATARA,
                urls: {
                    apiURL: "https://explorer.tatara.katana.network/api",
                    browserURL: "https://explorer.tatara.katana.network",
                },
            },
        ],
    },
    namedAccounts: { deployer: 0 },
    paths: {
        tests: "./test/evm/hardhat",
    },
};
exports.default = config;
