var _a;
import { CHAIN_IDs, MAINNET_CHAIN_IDs as _MAINNET_CHAIN_IDs, PUBLIC_NETWORKS } from "../constants";
var SNOWFLAKES = (_a = {},
    _a[CHAIN_IDs.ARBITRUM] = "arbitrum-mainnet",
    _a[CHAIN_IDs.BSC] = "bsc",
    _a[CHAIN_IDs.POLYGON] = "matic",
    _a[CHAIN_IDs.OPTIMISM] = "optimism",
    _a[CHAIN_IDs.WORLD_CHAIN] = "worldchain-mainnet",
    _a[CHAIN_IDs.HYPEREVM] = "hype-mainnet",
    _a);
var SNOWFLAKE_CHAIN_IDs = Object.keys(SNOWFLAKES).map(Number);
var MAINNET_CHAIN_IDs = Object.values(_MAINNET_CHAIN_IDs).map(Number);
export function getURL(chainId, apiKey, transport) {
    var _a, _b, _c;
    var envVar = "RPC_PROVIDER_KEY_QUICKNODE_PREFIX";
    var prefix = (_a = process.env["".concat(envVar, "_").concat(chainId)]) !== null && _a !== void 0 ? _a : process.env[envVar];
    if (!prefix) {
        throw new Error("No API key prefix supplied for QuickNode (".concat(envVar, ")"));
    }
    var domain = "quiknode.pro"; // nb. quiknode, not quicknode
    /* Some chains are special snowflakes */
    if (chainId === CHAIN_IDs.MAINNET) {
        return "".concat(transport, "://").concat(prefix, ".").concat(domain, "/").concat(apiKey);
    }
    var chain = (_b = SNOWFLAKES[chainId]) !== null && _b !== void 0 ? _b : (_c = PUBLIC_NETWORKS[chainId]) === null || _c === void 0 ? void 0 : _c.name;
    if (!chain) {
        throw new Error("No known QuickNode provider for chainId ".concat(chainId));
    }
    if (MAINNET_CHAIN_IDs.includes(chainId) && !SNOWFLAKE_CHAIN_IDs.includes(chainId)) {
        chain += "-mainnet";
    }
    chain = chain.toLowerCase().replace(" ", "-");
    return "".concat(transport, "://").concat(prefix, ".").concat(chain, ".").concat(domain, "/").concat(apiKey);
}
//# sourceMappingURL=quicknode.js.map