UNPKG

@kamino-finance/klend-sdk

Version:

Typescript SDK for interacting with the Kamino Lending (klend) protocol

63 lines 2.41 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.KAMINO_API_RETRY = exports.KAMINO_CDN_RETRY = void 0; exports.getMarketsFromApi = getMarketsFromApi; const axios_1 = __importDefault(require("axios")); const classes_1 = require("../classes"); const utils_1 = require("../utils"); const exponential_backoff_1 = require("exponential-backoff"); const lib_1 = require("../lib"); /** * Fetch config from the API * A good place to start to find active klend markets without expensive RPC calls * * @param programId - The program id to retrieve config for * @param source - CDN is a json file hosted in the cloud, API is a webserver * @param filterOptions - Config options to filter markets by */ async function getMarketsFromApi(programId = lib_1.PROGRAM_ID, source = 'CDN', filterOptions = {}) { let unfilteredConfigs = {}; if (source === 'CDN') { unfilteredConfigs = (await (0, exponential_backoff_1.backOff)(() => axios_1.default.get(utils_1.CDN_ENDPOINT), exports.KAMINO_CDN_RETRY)).data[programId.toString()]; } if (!unfilteredConfigs || (0, classes_1.isEmptyObject)(unfilteredConfigs)) { const API_ENDPOINT = (0, utils_1.getApiEndpoint)(programId); unfilteredConfigs = (await (0, exponential_backoff_1.backOff)(() => axios_1.default.get(API_ENDPOINT), exports.KAMINO_API_RETRY)).data; } return unfilteredConfigs.filter((c) => { if (filterOptions.isCurated !== undefined) { return c.isCurated === filterOptions.isCurated; } return true; }); } exports.KAMINO_CDN_RETRY = { maxDelay: 1000, numOfAttempts: 3, startingDelay: 10, retry: (e, attemptNumber) => { console.warn(e); console.warn({ attemptNumber, message: 'kamino CDN call failed, retrying with exponential backoff...', }); return true; }, }; exports.KAMINO_API_RETRY = { maxDelay: 1000, numOfAttempts: 3, startingDelay: 10, retry: (e, attemptNumber) => { console.warn(e); console.warn({ attemptNumber, message: 'api.kamino.finance call failed, retrying with exponential backoff...', }); return true; }, }; //# sourceMappingURL=api.js.map