@hubbleprotocol/farms-sdk
Version:
95 lines • 5.13 kB
JavaScript
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
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 __asyncValues = (this && this.__asyncValues) || function (o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.downloadAllUserObligationsForReserve = downloadAllUserObligationsForReserve;
const klend_sdk_1 = require("@kamino-finance/klend-sdk");
const web3_js_1 = require("@solana/web3.js");
const utils_1 = require("./utils");
const utils_2 = require("../utils");
const fs = __importStar(require("fs"));
function downloadAllUserObligationsForReserve(market, reservePk) {
return __awaiter(this, void 0, void 0, function* () {
var _a, e_1, _b, _c;
const admin = process.env.ADMIN;
const rpc = process.env.RPC;
const klendProgramId = new web3_js_1.PublicKey(process.env.KLEND_PROGRAM_ID || "");
const env = (0, utils_1.initializeClient)(rpc, admin, (0, utils_2.getFarmsProgramId)(rpc), false);
const c = env.provider.connection;
const lendingMarket = new web3_js_1.PublicKey(market);
const reserve = new web3_js_1.PublicKey(reservePk);
const kaminoMarket = yield klend_sdk_1.KaminoMarket.load(c, lendingMarket, 450, klendProgramId);
if (!kaminoMarket) {
throw new Error("Kamino market not found");
}
let obligationsGenerator = kaminoMarket.batchGetAllObligationsForMarket();
const writeStream = fs.createWriteStream(`./obligations-${reserve.toString()}.json`);
writeStream.write("[\n");
let sep = "";
try {
for (var _d = true, obligationsGenerator_1 = __asyncValues(obligationsGenerator), obligationsGenerator_1_1; obligationsGenerator_1_1 = yield obligationsGenerator_1.next(), _a = obligationsGenerator_1_1.done, !_a; _d = true) {
_c = obligationsGenerator_1_1.value;
_d = false;
const obligations = _c;
for (const obligation of obligations) {
for (const deposit of obligation.state.deposits) {
if (deposit.depositReserve.equals(reserve)) {
writeStream.write(`${sep}"${obligation.obligationAddress.toString()}"`);
if (!sep) {
sep = ",\n";
}
}
}
}
continue;
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (!_d && !_a && (_b = obligationsGenerator_1.return)) yield _b.call(obligationsGenerator_1);
}
finally { if (e_1) throw e_1.error; }
}
writeStream.write("\n]");
return;
});
}
//# sourceMappingURL=download_all_klend_user_obligation_farms.js.map
;