"use strict";
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getURL = getURL;
var constants_1 = require("../constants");
var SNOWFLAKES = (_a = {},
    _a[constants_1.CHAIN_IDs.ARBITRUM] = "arbitrum-mainnet",
    _a[constants_1.CHAIN_IDs.BSC] = "bsc",
    _a[constants_1.CHAIN_IDs.POLYGON] = "matic",
    _a[constants_1.CHAIN_IDs.OPTIMISM] = "optimism",
    _a[constants_1.CHAIN_IDs.WORLD_CHAIN] = "worldchain-mainnet",
    _a[constants_1.CHAIN_IDs.HYPEREVM] = "hype-mainnet",
    _a);
var SNOWFLAKE_CHAIN_IDs = Object.keys(SNOWFLAKES).map(Number);
var MAINNET_CHAIN_IDs = Object.values(constants_1.MAINNET_CHAIN_IDs).map(Number);
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";
    if (chainId === constants_1.CHAIN_IDs.MAINNET) {
        return "".concat(transport, "://").concat(prefix, ".").concat(domain, "/").concat(apiKey);
    }
    var chain = (_b = SNOWFLAKES[chainId]) !== null && _b !== void 0 ? _b : (_c = constants_1.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