"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getURL = getURL;
const constants_1 = require("../constants");
const SNOWFLAKES = {
    [constants_1.CHAIN_IDs.ARBITRUM]: "arbitrum-mainnet",
    [constants_1.CHAIN_IDs.BSC]: "bsc",
    [constants_1.CHAIN_IDs.POLYGON]: "matic",
    [constants_1.CHAIN_IDs.OPTIMISM]: "optimism",
    [constants_1.CHAIN_IDs.WORLD_CHAIN]: "worldchain-mainnet",
    [constants_1.CHAIN_IDs.HYPEREVM]: "hype-mainnet",
};
const SNOWFLAKE_CHAIN_IDs = Object.keys(SNOWFLAKES).map(Number);
const MAINNET_CHAIN_IDs = Object.values(constants_1.MAINNET_CHAIN_IDs).map(Number);
function getURL(chainId, apiKey, transport) {
    const envVar = "RPC_PROVIDER_KEY_QUICKNODE_PREFIX";
    const prefix = process.env[`${envVar}_${chainId}`] ?? process.env[envVar];
    if (!prefix) {
        throw new Error(`No API key prefix supplied for QuickNode (${envVar})`);
    }
    const domain = "quiknode.pro";
    if (chainId === constants_1.CHAIN_IDs.MAINNET) {
        return `${transport}://${prefix}.${domain}/${apiKey}`;
    }
    let chain = SNOWFLAKES[chainId] ?? constants_1.PUBLIC_NETWORKS[chainId]?.name;
    if (!chain) {
        throw new Error(`No known QuickNode provider for chainId ${chainId}`);
    }
    if (MAINNET_CHAIN_IDs.includes(chainId) && !SNOWFLAKE_CHAIN_IDs.includes(chainId)) {
        chain += "-mainnet";
    }
    chain = chain.toLowerCase().replace(" ", "-");
    return `${transport}://${prefix}.${chain}.${domain}/${apiKey}`;
}
//# sourceMappingURL=quicknode.js.map