import { CCTP_NO_DOMAIN, ChainFamily, CHAIN_IDs, MAINNET_CHAIN_IDs, OFT_NO_EID, PRODUCTION_NETWORKS, PUBLIC_NETWORKS, TESTNET_CHAIN_IDs, } from "../constants";
export const hreNetworks = {
    666: "Hardhat1",
    1342: "Hardhat2",
    31337: "HardhatNetwork",
};
/**
 * Resolves a network name from a network id.
 * @param networkId The network id to resolve the name for
 * @returns The network name for the network id. If the network id is not found, returns "unknown"
 */
export function getNetworkName(networkId) {
    networkId = Number(networkId);
    return PUBLIC_NETWORKS[networkId]?.name ?? hreNetworks[networkId] ?? `unknown (${networkId})`;
}
/**
 * Resolves a native token symbol from a chain id.
 * @param chainId The chain id to resolve the native token symbol for
 * @returns The native token symbol for the chain id. If the chain id is not found, returns "ETH"
 */
export function getNativeTokenSymbol(chainId) {
    return PUBLIC_NETWORKS[Number(chainId)]?.nativeToken ?? "ETH";
}
/**
 * Determines whether a chain ID is part of the production network.
 * @param chainId Chain ID to query.
 * @returns true if the chain ID is part of the production network, otherwise false.
 */
export function chainIsProd(chainId) {
    return Object.values(MAINNET_CHAIN_IDs).includes(chainId);
}
/**
 * Determines whether a chain ID is part of the production network.
 * @param chainId Chain ID to query.
 * @returns true if the chain ID is part of the production network, otherwise false.
 */
export function chainIsTestnet(chainId) {
    return Object.values(TESTNET_CHAIN_IDs).includes(chainId);
}
/**
 * Determines whether a chain ID is a Polygon implementation.
 * @param chainId Chain ID to evaluate.
 * @returns True if chainId is a Polygon chain (mainnet or testnet), otherwise false.
 */
export function chainIsMatic(chainId) {
    return [CHAIN_IDs.POLYGON, CHAIN_IDs.POLYGON_AMOY].includes(chainId);
}
/**
 * Determines whether a chain ID is an Optimism OP Stack implementation.
 * @param chainId Chain ID to evaluate.
 * @returns True if chainId is an OP stack, otherwise false.
 */
export function chainIsOPStack(chainId) {
    return PUBLIC_NETWORKS[chainId]?.family === ChainFamily.OP_STACK;
}
/**
 * Determines whether a chain ID is a ZkStack implementation.
 * @param chainId Chain ID to evaluate.
 * @returns True if chainId is a ZkStack chain, otherwise false.
 */
export function chainIsZkStack(chainId) {
    return PUBLIC_NETWORKS[chainId]?.family === ChainFamily.ZK_STACK;
}
/**
 * Determines whether a chain ID is an Arbitrum Orbit implementation.
 * @param chainId Chain ID to evaluate.
 * @returns True if chainId is an Orbit chain, otherwise false.
 */
export function chainIsOrbit(chainId) {
    return PUBLIC_NETWORKS[chainId]?.family === ChainFamily.ORBIT;
}
/**
 * Determines whether a chain ID is an Arbitrum implementation.
 * @param chainId Chain ID to evaluate.
 * @returns True if chainId is an Arbitrum chain, otherwise false.
 */
export function chainIsArbitrum(chainId) {
    return [CHAIN_IDs.ARBITRUM, CHAIN_IDs.ARBITRUM_SEPOLIA].includes(chainId);
}
/**
 * Determines whether a chain ID is a Linea implementation.
 * @param chainId Chain ID to evaluate.
 * @returns True if chainId is a Linea chain, otherwise false.
 */
export function chainIsLinea(chainId) {
    return [CHAIN_IDs.LINEA].includes(chainId);
}
/**
 * Determines whether a chain ID has a corresponding hub pool contract.
 * @param chainId Chain ID to evaluate.
 * @returns True if chain corresponding to chainId has a hub pool implementation.
 */
export function chainIsL1(chainId) {
    return [CHAIN_IDs.MAINNET, CHAIN_IDs.SEPOLIA].includes(chainId);
}
/**
 * Determines whether a chain ID runs on an EVM-like execution layer.
 * @param chainId Chain ID to evaluate.
 * @returns True if chain corresponding to chainId has an EVM-like execution layer.
 */
export function chainIsEvm(chainId) {
    // TODO: Update when additional execution layers beyond EVM and SVM are supported.
    return PUBLIC_NETWORKS[chainId]?.family !== ChainFamily.SVM;
}
/**
 * Determines whether a chain ID runs on an SVM-like execution layer.
 * @param chainId Chain ID to evaluate.
 * @returns True if chain corresponding to chainId has an SVM-like execution layer.
 */
export function chainIsSvm(chainId) {
    return PUBLIC_NETWORKS[chainId]?.family === ChainFamily.SVM;
}
/**
 * Determines whether a chain ID runs on a TVM-like execution layer (e.g. TRON).
 * @param chainId Chain ID to evaluate.
 * @returns True if chain corresponding to chainId has a TVM-like execution layer.
 */
export function chainIsTvm(chainId) {
    return PUBLIC_NETWORKS[chainId]?.family === ChainFamily.TVM;
}
/**
 * Determines whether a chain ID has a native gas token.
 * @param chainId Chain ID to evaluate.
 * @returns True if the chain corresponding to chainId has a native gas token.
 */
export function chainHasNativeToken(chainId) {
    return ![CHAIN_IDs.TEMPO].includes(chainId);
}
/**
 * Determines whether a chain ID has the capacity for having its USDC bridged via CCTP.
 * @param chainId Chain ID to evaluate.
 * @returns True if chainId is a CCTP-bridging enabled chain, otherwise false.
 */
export function chainIsCCTPEnabled(chainId) {
    // Add chainIds to cctpExceptions to administratively disable CCTP on a chain.
    // This is useful if constants has been updated to specify a CCTP domain in advance of it being activated.
    const cctpExceptions = [];
    return PRODUCTION_NETWORKS[chainId]?.cctpDomain !== CCTP_NO_DOMAIN && !cctpExceptions.includes(chainId);
}
/**
 * Determines whether a chain ID has the capacity for bridging via OFT. Must be evaluated in conjunction
 * with a specific token.
 * @param chainId Chain ID to evaluate.
 * @returns True if chainId is an OFT-bridging enabled chain, otherwise false.
 */
export function chainIsOFTEnabled(chainId) {
    // Add chainIds to oftEnabled as they are supported by the protocol.
    // This is backwards vs. CCTP logic because Across support for OFTs is limited vs. OFT deployments.
    const oftEnabled = [
        CHAIN_IDs.ARBITRUM,
        CHAIN_IDs.HYPEREVM,
        CHAIN_IDs.INK,
        CHAIN_IDs.MEGAETH,
        CHAIN_IDs.MONAD,
        CHAIN_IDs.PLASMA,
        CHAIN_IDs.POLYGON,
        CHAIN_IDs.TRON, // tbd!!!
        CHAIN_IDs.UNICHAIN,
    ];
    return oftEnabled.includes(chainId) && PRODUCTION_NETWORKS[chainId]?.oftEid !== OFT_NO_EID;
}
/**
 * Determines if a chain ID requires a manual L1 -> L2 finalization step.
 * @param chainId Chain ID to evaluate.
 * @returns True if chainId requires manual L1 -> L2 finalization, otherwise false.
 */
export function chainRequiresL1ToL2Finalization(chainId) {
    return chainIsCCTPEnabled(chainId) || chainIsLinea(chainId);
}
/**
 * Returns the origin of a URL.
 * @param url A URL.
 * @returns The origin of the URL, or "UNKNOWN" if the URL is invalid.
 */
export function getOriginFromURL(url) {
    try {
        return new URL(url).origin;
    }
    catch {
        return "UNKNOWN";
    }
}
//# sourceMappingURL=NetworkUtils.js.map