@kamino-finance/klend-sdk
Version:
Typescript SDK for interacting with the Kamino Lending (klend) protocol
309 lines • 14.7 kB
JavaScript
"use strict";
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 () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.VaultState = void 0;
const web3_js_1 = require("@solana/web3.js");
const bn_js_1 = __importDefault(require("bn.js")); // eslint-disable-line @typescript-eslint/no-unused-vars
const borsh = __importStar(require("@coral-xyz/borsh")); // eslint-disable-line @typescript-eslint/no-unused-vars
const types = __importStar(require("../types")); // eslint-disable-line @typescript-eslint/no-unused-vars
const programId_1 = require("../programId");
class VaultState {
vaultAdminAuthority;
baseVaultAuthority;
baseVaultAuthorityBump;
tokenMint;
tokenMintDecimals;
tokenVault;
tokenProgram;
sharesMint;
sharesMintDecimals;
tokenAvailable;
sharesIssued;
availableCrankFunds;
padding0;
performanceFeeBps;
managementFeeBps;
lastFeeChargeTimestamp;
prevAumSf;
pendingFeesSf;
vaultAllocationStrategy;
padding1;
minDepositAmount;
minWithdrawAmount;
minInvestAmount;
minInvestDelaySlots;
crankFundFeePerReserve;
pendingAdmin;
cumulativeEarnedInterestSf;
cumulativeMgmtFeesSf;
cumulativePerfFeesSf;
name;
vaultLookupTable;
vaultFarm;
creationTimestamp;
padding2;
allocationAdmin;
padding3;
static discriminator = Buffer.from([
228, 196, 82, 165, 98, 210, 235, 152,
]);
static layout = borsh.struct([
borsh.publicKey("vaultAdminAuthority"),
borsh.publicKey("baseVaultAuthority"),
borsh.u64("baseVaultAuthorityBump"),
borsh.publicKey("tokenMint"),
borsh.u64("tokenMintDecimals"),
borsh.publicKey("tokenVault"),
borsh.publicKey("tokenProgram"),
borsh.publicKey("sharesMint"),
borsh.u64("sharesMintDecimals"),
borsh.u64("tokenAvailable"),
borsh.u64("sharesIssued"),
borsh.u64("availableCrankFunds"),
borsh.u64("padding0"),
borsh.u64("performanceFeeBps"),
borsh.u64("managementFeeBps"),
borsh.u64("lastFeeChargeTimestamp"),
borsh.u128("prevAumSf"),
borsh.u128("pendingFeesSf"),
borsh.array(types.VaultAllocation.layout(), 25, "vaultAllocationStrategy"),
borsh.array(borsh.u128(), 256, "padding1"),
borsh.u64("minDepositAmount"),
borsh.u64("minWithdrawAmount"),
borsh.u64("minInvestAmount"),
borsh.u64("minInvestDelaySlots"),
borsh.u64("crankFundFeePerReserve"),
borsh.publicKey("pendingAdmin"),
borsh.u128("cumulativeEarnedInterestSf"),
borsh.u128("cumulativeMgmtFeesSf"),
borsh.u128("cumulativePerfFeesSf"),
borsh.array(borsh.u8(), 40, "name"),
borsh.publicKey("vaultLookupTable"),
borsh.publicKey("vaultFarm"),
borsh.u64("creationTimestamp"),
borsh.u64("padding2"),
borsh.publicKey("allocationAdmin"),
borsh.array(borsh.u128(), 242, "padding3"),
]);
constructor(fields) {
this.vaultAdminAuthority = fields.vaultAdminAuthority;
this.baseVaultAuthority = fields.baseVaultAuthority;
this.baseVaultAuthorityBump = fields.baseVaultAuthorityBump;
this.tokenMint = fields.tokenMint;
this.tokenMintDecimals = fields.tokenMintDecimals;
this.tokenVault = fields.tokenVault;
this.tokenProgram = fields.tokenProgram;
this.sharesMint = fields.sharesMint;
this.sharesMintDecimals = fields.sharesMintDecimals;
this.tokenAvailable = fields.tokenAvailable;
this.sharesIssued = fields.sharesIssued;
this.availableCrankFunds = fields.availableCrankFunds;
this.padding0 = fields.padding0;
this.performanceFeeBps = fields.performanceFeeBps;
this.managementFeeBps = fields.managementFeeBps;
this.lastFeeChargeTimestamp = fields.lastFeeChargeTimestamp;
this.prevAumSf = fields.prevAumSf;
this.pendingFeesSf = fields.pendingFeesSf;
this.vaultAllocationStrategy = fields.vaultAllocationStrategy.map((item) => new types.VaultAllocation({ ...item }));
this.padding1 = fields.padding1;
this.minDepositAmount = fields.minDepositAmount;
this.minWithdrawAmount = fields.minWithdrawAmount;
this.minInvestAmount = fields.minInvestAmount;
this.minInvestDelaySlots = fields.minInvestDelaySlots;
this.crankFundFeePerReserve = fields.crankFundFeePerReserve;
this.pendingAdmin = fields.pendingAdmin;
this.cumulativeEarnedInterestSf = fields.cumulativeEarnedInterestSf;
this.cumulativeMgmtFeesSf = fields.cumulativeMgmtFeesSf;
this.cumulativePerfFeesSf = fields.cumulativePerfFeesSf;
this.name = fields.name;
this.vaultLookupTable = fields.vaultLookupTable;
this.vaultFarm = fields.vaultFarm;
this.creationTimestamp = fields.creationTimestamp;
this.padding2 = fields.padding2;
this.allocationAdmin = fields.allocationAdmin;
this.padding3 = fields.padding3;
}
static async fetch(c, address, programId = programId_1.PROGRAM_ID) {
const info = await c.getAccountInfo(address);
if (info === null) {
return null;
}
if (!info.owner.equals(programId)) {
throw new Error("account doesn't belong to this program");
}
return this.decode(info.data);
}
static async fetchMultiple(c, addresses, programId = programId_1.PROGRAM_ID) {
const infos = await c.getMultipleAccountsInfo(addresses);
return infos.map((info) => {
if (info === null) {
return null;
}
if (!info.owner.equals(programId)) {
throw new Error("account doesn't belong to this program");
}
return this.decode(info.data);
});
}
static decode(data) {
if (!VaultState.discriminator.equals(data.slice(0, 8))) {
throw new Error("invalid account discriminator");
}
const dec = VaultState.layout.decode(data.slice(8));
return new VaultState({
vaultAdminAuthority: dec.vaultAdminAuthority,
baseVaultAuthority: dec.baseVaultAuthority,
baseVaultAuthorityBump: dec.baseVaultAuthorityBump,
tokenMint: dec.tokenMint,
tokenMintDecimals: dec.tokenMintDecimals,
tokenVault: dec.tokenVault,
tokenProgram: dec.tokenProgram,
sharesMint: dec.sharesMint,
sharesMintDecimals: dec.sharesMintDecimals,
tokenAvailable: dec.tokenAvailable,
sharesIssued: dec.sharesIssued,
availableCrankFunds: dec.availableCrankFunds,
padding0: dec.padding0,
performanceFeeBps: dec.performanceFeeBps,
managementFeeBps: dec.managementFeeBps,
lastFeeChargeTimestamp: dec.lastFeeChargeTimestamp,
prevAumSf: dec.prevAumSf,
pendingFeesSf: dec.pendingFeesSf,
vaultAllocationStrategy: dec.vaultAllocationStrategy.map((item /* eslint-disable-line @typescript-eslint/no-explicit-any */) => types.VaultAllocation.fromDecoded(item)),
padding1: dec.padding1,
minDepositAmount: dec.minDepositAmount,
minWithdrawAmount: dec.minWithdrawAmount,
minInvestAmount: dec.minInvestAmount,
minInvestDelaySlots: dec.minInvestDelaySlots,
crankFundFeePerReserve: dec.crankFundFeePerReserve,
pendingAdmin: dec.pendingAdmin,
cumulativeEarnedInterestSf: dec.cumulativeEarnedInterestSf,
cumulativeMgmtFeesSf: dec.cumulativeMgmtFeesSf,
cumulativePerfFeesSf: dec.cumulativePerfFeesSf,
name: dec.name,
vaultLookupTable: dec.vaultLookupTable,
vaultFarm: dec.vaultFarm,
creationTimestamp: dec.creationTimestamp,
padding2: dec.padding2,
allocationAdmin: dec.allocationAdmin,
padding3: dec.padding3,
});
}
toJSON() {
return {
vaultAdminAuthority: this.vaultAdminAuthority.toString(),
baseVaultAuthority: this.baseVaultAuthority.toString(),
baseVaultAuthorityBump: this.baseVaultAuthorityBump.toString(),
tokenMint: this.tokenMint.toString(),
tokenMintDecimals: this.tokenMintDecimals.toString(),
tokenVault: this.tokenVault.toString(),
tokenProgram: this.tokenProgram.toString(),
sharesMint: this.sharesMint.toString(),
sharesMintDecimals: this.sharesMintDecimals.toString(),
tokenAvailable: this.tokenAvailable.toString(),
sharesIssued: this.sharesIssued.toString(),
availableCrankFunds: this.availableCrankFunds.toString(),
padding0: this.padding0.toString(),
performanceFeeBps: this.performanceFeeBps.toString(),
managementFeeBps: this.managementFeeBps.toString(),
lastFeeChargeTimestamp: this.lastFeeChargeTimestamp.toString(),
prevAumSf: this.prevAumSf.toString(),
pendingFeesSf: this.pendingFeesSf.toString(),
vaultAllocationStrategy: this.vaultAllocationStrategy.map((item) => item.toJSON()),
padding1: this.padding1.map((item) => item.toString()),
minDepositAmount: this.minDepositAmount.toString(),
minWithdrawAmount: this.minWithdrawAmount.toString(),
minInvestAmount: this.minInvestAmount.toString(),
minInvestDelaySlots: this.minInvestDelaySlots.toString(),
crankFundFeePerReserve: this.crankFundFeePerReserve.toString(),
pendingAdmin: this.pendingAdmin.toString(),
cumulativeEarnedInterestSf: this.cumulativeEarnedInterestSf.toString(),
cumulativeMgmtFeesSf: this.cumulativeMgmtFeesSf.toString(),
cumulativePerfFeesSf: this.cumulativePerfFeesSf.toString(),
name: this.name,
vaultLookupTable: this.vaultLookupTable.toString(),
vaultFarm: this.vaultFarm.toString(),
creationTimestamp: this.creationTimestamp.toString(),
padding2: this.padding2.toString(),
allocationAdmin: this.allocationAdmin.toString(),
padding3: this.padding3.map((item) => item.toString()),
};
}
static fromJSON(obj) {
return new VaultState({
vaultAdminAuthority: new web3_js_1.PublicKey(obj.vaultAdminAuthority),
baseVaultAuthority: new web3_js_1.PublicKey(obj.baseVaultAuthority),
baseVaultAuthorityBump: new bn_js_1.default(obj.baseVaultAuthorityBump),
tokenMint: new web3_js_1.PublicKey(obj.tokenMint),
tokenMintDecimals: new bn_js_1.default(obj.tokenMintDecimals),
tokenVault: new web3_js_1.PublicKey(obj.tokenVault),
tokenProgram: new web3_js_1.PublicKey(obj.tokenProgram),
sharesMint: new web3_js_1.PublicKey(obj.sharesMint),
sharesMintDecimals: new bn_js_1.default(obj.sharesMintDecimals),
tokenAvailable: new bn_js_1.default(obj.tokenAvailable),
sharesIssued: new bn_js_1.default(obj.sharesIssued),
availableCrankFunds: new bn_js_1.default(obj.availableCrankFunds),
padding0: new bn_js_1.default(obj.padding0),
performanceFeeBps: new bn_js_1.default(obj.performanceFeeBps),
managementFeeBps: new bn_js_1.default(obj.managementFeeBps),
lastFeeChargeTimestamp: new bn_js_1.default(obj.lastFeeChargeTimestamp),
prevAumSf: new bn_js_1.default(obj.prevAumSf),
pendingFeesSf: new bn_js_1.default(obj.pendingFeesSf),
vaultAllocationStrategy: obj.vaultAllocationStrategy.map((item) => types.VaultAllocation.fromJSON(item)),
padding1: obj.padding1.map((item) => new bn_js_1.default(item)),
minDepositAmount: new bn_js_1.default(obj.minDepositAmount),
minWithdrawAmount: new bn_js_1.default(obj.minWithdrawAmount),
minInvestAmount: new bn_js_1.default(obj.minInvestAmount),
minInvestDelaySlots: new bn_js_1.default(obj.minInvestDelaySlots),
crankFundFeePerReserve: new bn_js_1.default(obj.crankFundFeePerReserve),
pendingAdmin: new web3_js_1.PublicKey(obj.pendingAdmin),
cumulativeEarnedInterestSf: new bn_js_1.default(obj.cumulativeEarnedInterestSf),
cumulativeMgmtFeesSf: new bn_js_1.default(obj.cumulativeMgmtFeesSf),
cumulativePerfFeesSf: new bn_js_1.default(obj.cumulativePerfFeesSf),
name: obj.name,
vaultLookupTable: new web3_js_1.PublicKey(obj.vaultLookupTable),
vaultFarm: new web3_js_1.PublicKey(obj.vaultFarm),
creationTimestamp: new bn_js_1.default(obj.creationTimestamp),
padding2: new bn_js_1.default(obj.padding2),
allocationAdmin: new web3_js_1.PublicKey(obj.allocationAdmin),
padding3: obj.padding3.map((item) => new bn_js_1.default(item)),
});
}
}
exports.VaultState = VaultState;
//# sourceMappingURL=VaultState.js.map