@superfluid-finance/sdk-core
Version:
SDK Core for building with Superfluid Protocol
60 lines • 2.54 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getNetworkName = exports.getSubgraphQueriesEndpoint = exports.validateFrameworkConstructorOptions = void 0;
const SFError_1 = require("./SFError");
const constants_1 = require("./constants");
const utils_1 = require("./utils");
const validateFrameworkConstructorOptions = (options) => {
if (!options.chainId) {
throw new SFError_1.SFError({
type: "FRAMEWORK_INITIALIZATION",
message: "You must input chainId.",
});
}
if (!options.provider) {
throw new SFError_1.SFError({
type: "FRAMEWORK_INITIALIZATION",
message: "You must pass in a provider, an injected web3.js or ethers.js instance when initializing the framework.",
});
}
// if the user inputs a chainId that isn't part of the resolver
// that is, an unsupported network/chain
if (options.chainId != null && !constants_1.chainIds.includes(options.chainId)) {
if ((0, utils_1.isNullOrEmpty)(options.resolverAddress)) {
throw new SFError_1.SFError({
type: "FRAMEWORK_INITIALIZATION",
message: "You must input your own resolver address if you use an unsupported network.",
});
}
}
};
exports.validateFrameworkConstructorOptions = validateFrameworkConstructorOptions;
/**
* Subgraph Query endpoint is empty string and will break at runtime if this is not handled.
* @param options
* @returns SubgraphQueriesEndpoint which is a custom endpoint or based on selected network
*/
const getSubgraphQueriesEndpoint = (options) => {
const resolverData = options.chainId
? constants_1.chainIdToResolverDataMap.get(options.chainId)
: null;
if (resolverData) {
return resolverData.subgraphAPIEndpoint;
}
return ""; // return empty string
};
exports.getSubgraphQueriesEndpoint = getSubgraphQueriesEndpoint;
/**
* We check that the user has input a networkName or chainId and that they are both supported.
* @param options.chainId the chainId of the desired network
* @param options.networkName the name of the desired network
* @returns the network name
*/
const getNetworkName = (options) => {
var _a;
return ((options.chainId
? (_a = constants_1.chainIdToResolverDataMap.get(options.chainId)) === null || _a === void 0 ? void 0 : _a.networkName
: undefined) || "custom");
};
exports.getNetworkName = getNetworkName;
//# sourceMappingURL=frameworkHelpers.js.map
;