UNPKG

@kamino-finance/klend-sdk

Version:

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

57 lines 2.1 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 */ async function getMarketsFromApi(programId = lib_1.PROGRAM_ID, source = 'CDN') { let configs = {}; if (source === 'CDN') { configs = (await (0, exponential_backoff_1.backOff)(() => axios_1.default.get(utils_1.CDN_ENDPOINT), exports.KAMINO_CDN_RETRY)).data[programId.toString()]; } if (!configs || (0, classes_1.isEmptyObject)(configs)) { const API_ENDPOINT = (0, utils_1.getApiEndpoint)(programId); configs = (await (0, exponential_backoff_1.backOff)(() => axios_1.default.get(API_ENDPOINT), exports.KAMINO_API_RETRY)).data; } return configs; } 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