@kamino-finance/klend-sdk
Version:
Typescript SDK for interacting with the Kamino Lending (klend) protocol
77 lines • 3.15 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAllObligationAccounts = getAllObligationAccounts;
exports.getAllReserveAccounts = getAllReserveAccounts;
exports.getAllLendingMarketAccounts = getAllLendingMarketAccounts;
const accounts_1 = require("../idl_codegen/accounts");
const programId_1 = require("../idl_codegen/programId");
const bs58_1 = __importDefault(require("bs58"));
async function* getAllObligationAccounts(connection) {
// Poor-man's paging...
for (let i = 0; i < 256; i++) {
const obligations = await connection.getProgramAccounts(programId_1.PROGRAM_ID, {
filters: [
{
dataSize: accounts_1.Obligation.layout.span + 8,
},
{
memcmp: {
offset: 0,
bytes: bs58_1.default.encode(accounts_1.Obligation.discriminator),
},
},
{
memcmp: {
offset: 64,
bytes: bs58_1.default.encode([i]), // ...via sharding by userId's first byte (just as a source of randomness)
},
},
],
});
for (const obligation of obligations) {
yield [obligation.pubkey, accounts_1.Obligation.decode(obligation.account.data)];
}
}
}
async function* getAllReserveAccounts(connection) {
// due to relatively low count of reserves, we technically don't really need a generator, but let's keep it consistent within this file
const reserves = await connection.getProgramAccounts(programId_1.PROGRAM_ID, {
filters: [
{
dataSize: accounts_1.Reserve.layout.span + 8,
},
{
memcmp: {
offset: 0,
bytes: bs58_1.default.encode(accounts_1.Reserve.discriminator),
},
},
],
});
for (const reserve of reserves) {
yield [reserve.pubkey, accounts_1.Reserve.decode(reserve.account.data), reserve.account];
}
}
async function* getAllLendingMarketAccounts(connection, programId = programId_1.PROGRAM_ID) {
// due to relatively very low count of lending markets, we technically don't really need a generator, but let's keep it consistent within this file
const lendingMarkets = await connection.getProgramAccounts(programId, {
filters: [
{
dataSize: accounts_1.LendingMarket.layout.span + 8,
},
{
memcmp: {
offset: 0,
bytes: bs58_1.default.encode(accounts_1.LendingMarket.discriminator),
},
},
],
});
for (const lendingMarket of lendingMarkets) {
yield [lendingMarket.pubkey, accounts_1.LendingMarket.decode(lendingMarket.account.data)];
}
}
//# sourceMappingURL=accountListing.js.map
;