fbonds-core
Version:
Banx protocol sdk
49 lines (48 loc) • 2.53 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SolendMarket = void 0;
const web3_js_1 = require("@solana/web3.js");
const axios_1 = __importDefault(require("axios"));
const solendReserv_1 = require("./solendReserv");
const API_ENDPOINT = "https://api.solend.fi";
class SolendMarket {
constructor(connection, config, reserves, programId) {
this.connection = connection;
this.reserves = reserves;
this.rewardsData = null;
this.config = config;
this.programId = programId;
}
static initialize(connection_1) {
return __awaiter(this, arguments, void 0, function* (connection, environment = "production", marketAddress) {
var _a, _b;
const config = (yield (yield axios_1.default.get(`${API_ENDPOINT}/v1/markets/configs?scope=all&deployment=${environment}`)).data);
let marketConfig;
if (marketAddress) {
marketConfig =
(_a = config.find((market) => market.address == marketAddress)) !== null && _a !== void 0 ? _a : null;
if (!marketConfig) {
throw `market address not found: ${marketAddress}`;
}
}
else {
marketConfig = (_b = config.find((market) => market.isPrimary)) !== null && _b !== void 0 ? _b : config[0];
}
const reserves = marketConfig.reserves.map((res) => new solendReserv_1.SolendReserve(res, connection));
return new SolendMarket(connection, marketConfig, reserves, new web3_js_1.PublicKey("So1endDq2YkqhipRh3WViPa8hdiSpxWy6z3Z6tMCpAo"));
});
}
}
exports.SolendMarket = SolendMarket;