@kamino-finance/klend-sdk
Version:
Typescript SDK for interacting with the Kamino Lending (klend) protocol
355 lines • 18.9 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.ReserveConfig = void 0;
const bn_js_1 = __importDefault(require("bn.js")); // eslint-disable-line @typescript-eslint/no-unused-vars
const types = __importStar(require("../types")); // eslint-disable-line @typescript-eslint/no-unused-vars
const borsh = __importStar(require("@coral-xyz/borsh"));
/** Reserve configuration values */
class ReserveConfig {
/** Status of the reserve Active/Obsolete/Hidden */
status;
/** Asset tier -> 0 - regular (collateral & debt), 1 - isolated collateral, 2 - isolated debt */
assetTier;
/** Flat rate that goes to the host */
hostFixedInterestRateBps;
/**
* [DEPRECATED] Space that used to hold 2 fields:
* - Boost for side (debt or collateral)
* - Reward points multiplier per obligation type
* Can be re-used after making sure all underlying production account data is zeroed.
*/
reserved2;
/** Cut of the order execution bonus that the protocol receives, as a percentage */
protocolOrderExecutionFeePct;
/** Protocol take rate is the amount borrowed interest protocol receives, as a percentage */
protocolTakeRatePct;
/** Cut of the liquidation bonus that the protocol receives, as a percentage */
protocolLiquidationFeePct;
/**
* Target ratio of the value of borrows to deposits, as a percentage
* 0 if use as collateral is disabled
*/
loanToValuePct;
/** Loan to value ratio at which an obligation can be liquidated, as percentage */
liquidationThresholdPct;
/** Minimum bonus a liquidator receives when repaying part of an unhealthy obligation, as bps */
minLiquidationBonusBps;
/** Maximum bonus a liquidator receives when repaying part of an unhealthy obligation, as bps */
maxLiquidationBonusBps;
/** Bad debt liquidation bonus for an undercollateralized obligation, as bps */
badDebtLiquidationBonusBps;
/**
* Time in seconds that must pass before redemptions are enabled after the deposit limit is
* crossed.
* Only relevant when `autodeleverage_enabled == 1`, and must not be 0 in such case.
*/
deleveragingMarginCallPeriodSecs;
/**
* The rate at which the deleveraging threshold decreases, in bps per day.
* Only relevant when `autodeleverage_enabled == 1`, and must not be 0 in such case.
*/
deleveragingThresholdDecreaseBpsPerDay;
/** Program owner fees assessed, separate from gains due to interest accrual */
fees;
/** Borrow rate curve based on utilization */
borrowRateCurve;
/** Borrow factor in percentage - used for risk adjustment */
borrowFactorPct;
/** Maximum deposit limit of liquidity in native units, u64::MAX for inf */
depositLimit;
/** Maximum amount borrowed, u64::MAX for inf, 0 to disable borrows (protected deposits) */
borrowLimit;
/** Token id from TokenInfos struct */
tokenInfo;
/** Deposit withdrawal caps - deposit & redeem */
depositWithdrawalCap;
/** Debt withdrawal caps - borrow & repay */
debtWithdrawalCap;
elevationGroups;
disableUsageAsCollOutsideEmode;
/** Utilization (in percentage) above which borrowing is blocked. 0 to disable. */
utilizationLimitBlockBorrowingAbovePct;
/**
* Whether this reserve should be subject to auto-deleveraging after deposit or borrow limit is
* crossed.
* Besides this flag, the lending market's flag also needs to be enabled (logical `AND`).
* **NOTE:** the manual "target LTV" deleveraging (enabled by the risk council for individual
* obligations) is NOT affected by this flag.
*/
autodeleverageEnabled;
reserved1;
/**
* Maximum amount liquidity of this reserve borrowed outside all elevation groups
* - u64::MAX for inf
* - 0 to disable borrows outside elevation groups
*/
borrowLimitOutsideElevationGroup;
/**
* Defines the maximum amount (in lamports of elevation group debt asset)
* that can be borrowed when this reserve is used as collateral.
* - u64::MAX for inf
* - 0 to disable borrows in this elevation group (expected value for the debt asset)
*/
borrowLimitAgainstThisCollateralInElevationGroup;
/**
* The rate at which the deleveraging-related liquidation bonus increases, in bps per day.
* Only relevant when `autodeleverage_enabled == 1`, and must not be 0 in such case.
*/
deleveragingBonusIncreaseBpsPerDay;
constructor(fields) {
this.status = fields.status;
this.assetTier = fields.assetTier;
this.hostFixedInterestRateBps = fields.hostFixedInterestRateBps;
this.reserved2 = fields.reserved2;
this.protocolOrderExecutionFeePct = fields.protocolOrderExecutionFeePct;
this.protocolTakeRatePct = fields.protocolTakeRatePct;
this.protocolLiquidationFeePct = fields.protocolLiquidationFeePct;
this.loanToValuePct = fields.loanToValuePct;
this.liquidationThresholdPct = fields.liquidationThresholdPct;
this.minLiquidationBonusBps = fields.minLiquidationBonusBps;
this.maxLiquidationBonusBps = fields.maxLiquidationBonusBps;
this.badDebtLiquidationBonusBps = fields.badDebtLiquidationBonusBps;
this.deleveragingMarginCallPeriodSecs =
fields.deleveragingMarginCallPeriodSecs;
this.deleveragingThresholdDecreaseBpsPerDay =
fields.deleveragingThresholdDecreaseBpsPerDay;
this.fees = new types.ReserveFees({ ...fields.fees });
this.borrowRateCurve = new types.BorrowRateCurve({
...fields.borrowRateCurve,
});
this.borrowFactorPct = fields.borrowFactorPct;
this.depositLimit = fields.depositLimit;
this.borrowLimit = fields.borrowLimit;
this.tokenInfo = new types.TokenInfo({ ...fields.tokenInfo });
this.depositWithdrawalCap = new types.WithdrawalCaps({
...fields.depositWithdrawalCap,
});
this.debtWithdrawalCap = new types.WithdrawalCaps({
...fields.debtWithdrawalCap,
});
this.elevationGroups = fields.elevationGroups;
this.disableUsageAsCollOutsideEmode = fields.disableUsageAsCollOutsideEmode;
this.utilizationLimitBlockBorrowingAbovePct =
fields.utilizationLimitBlockBorrowingAbovePct;
this.autodeleverageEnabled = fields.autodeleverageEnabled;
this.reserved1 = fields.reserved1;
this.borrowLimitOutsideElevationGroup =
fields.borrowLimitOutsideElevationGroup;
this.borrowLimitAgainstThisCollateralInElevationGroup =
fields.borrowLimitAgainstThisCollateralInElevationGroup;
this.deleveragingBonusIncreaseBpsPerDay =
fields.deleveragingBonusIncreaseBpsPerDay;
}
static layout(property) {
return borsh.struct([
borsh.u8("status"),
borsh.u8("assetTier"),
borsh.u16("hostFixedInterestRateBps"),
borsh.array(borsh.u8(), 9, "reserved2"),
borsh.u8("protocolOrderExecutionFeePct"),
borsh.u8("protocolTakeRatePct"),
borsh.u8("protocolLiquidationFeePct"),
borsh.u8("loanToValuePct"),
borsh.u8("liquidationThresholdPct"),
borsh.u16("minLiquidationBonusBps"),
borsh.u16("maxLiquidationBonusBps"),
borsh.u16("badDebtLiquidationBonusBps"),
borsh.u64("deleveragingMarginCallPeriodSecs"),
borsh.u64("deleveragingThresholdDecreaseBpsPerDay"),
types.ReserveFees.layout("fees"),
types.BorrowRateCurve.layout("borrowRateCurve"),
borsh.u64("borrowFactorPct"),
borsh.u64("depositLimit"),
borsh.u64("borrowLimit"),
types.TokenInfo.layout("tokenInfo"),
types.WithdrawalCaps.layout("depositWithdrawalCap"),
types.WithdrawalCaps.layout("debtWithdrawalCap"),
borsh.array(borsh.u8(), 20, "elevationGroups"),
borsh.u8("disableUsageAsCollOutsideEmode"),
borsh.u8("utilizationLimitBlockBorrowingAbovePct"),
borsh.u8("autodeleverageEnabled"),
borsh.array(borsh.u8(), 1, "reserved1"),
borsh.u64("borrowLimitOutsideElevationGroup"),
borsh.array(borsh.u64(), 32, "borrowLimitAgainstThisCollateralInElevationGroup"),
borsh.u64("deleveragingBonusIncreaseBpsPerDay"),
], property);
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
static fromDecoded(obj) {
return new ReserveConfig({
status: obj.status,
assetTier: obj.assetTier,
hostFixedInterestRateBps: obj.hostFixedInterestRateBps,
reserved2: obj.reserved2,
protocolOrderExecutionFeePct: obj.protocolOrderExecutionFeePct,
protocolTakeRatePct: obj.protocolTakeRatePct,
protocolLiquidationFeePct: obj.protocolLiquidationFeePct,
loanToValuePct: obj.loanToValuePct,
liquidationThresholdPct: obj.liquidationThresholdPct,
minLiquidationBonusBps: obj.minLiquidationBonusBps,
maxLiquidationBonusBps: obj.maxLiquidationBonusBps,
badDebtLiquidationBonusBps: obj.badDebtLiquidationBonusBps,
deleveragingMarginCallPeriodSecs: obj.deleveragingMarginCallPeriodSecs,
deleveragingThresholdDecreaseBpsPerDay: obj.deleveragingThresholdDecreaseBpsPerDay,
fees: types.ReserveFees.fromDecoded(obj.fees),
borrowRateCurve: types.BorrowRateCurve.fromDecoded(obj.borrowRateCurve),
borrowFactorPct: obj.borrowFactorPct,
depositLimit: obj.depositLimit,
borrowLimit: obj.borrowLimit,
tokenInfo: types.TokenInfo.fromDecoded(obj.tokenInfo),
depositWithdrawalCap: types.WithdrawalCaps.fromDecoded(obj.depositWithdrawalCap),
debtWithdrawalCap: types.WithdrawalCaps.fromDecoded(obj.debtWithdrawalCap),
elevationGroups: obj.elevationGroups,
disableUsageAsCollOutsideEmode: obj.disableUsageAsCollOutsideEmode,
utilizationLimitBlockBorrowingAbovePct: obj.utilizationLimitBlockBorrowingAbovePct,
autodeleverageEnabled: obj.autodeleverageEnabled,
reserved1: obj.reserved1,
borrowLimitOutsideElevationGroup: obj.borrowLimitOutsideElevationGroup,
borrowLimitAgainstThisCollateralInElevationGroup: obj.borrowLimitAgainstThisCollateralInElevationGroup,
deleveragingBonusIncreaseBpsPerDay: obj.deleveragingBonusIncreaseBpsPerDay,
});
}
static toEncodable(fields) {
return {
status: fields.status,
assetTier: fields.assetTier,
hostFixedInterestRateBps: fields.hostFixedInterestRateBps,
reserved2: fields.reserved2,
protocolOrderExecutionFeePct: fields.protocolOrderExecutionFeePct,
protocolTakeRatePct: fields.protocolTakeRatePct,
protocolLiquidationFeePct: fields.protocolLiquidationFeePct,
loanToValuePct: fields.loanToValuePct,
liquidationThresholdPct: fields.liquidationThresholdPct,
minLiquidationBonusBps: fields.minLiquidationBonusBps,
maxLiquidationBonusBps: fields.maxLiquidationBonusBps,
badDebtLiquidationBonusBps: fields.badDebtLiquidationBonusBps,
deleveragingMarginCallPeriodSecs: fields.deleveragingMarginCallPeriodSecs,
deleveragingThresholdDecreaseBpsPerDay: fields.deleveragingThresholdDecreaseBpsPerDay,
fees: types.ReserveFees.toEncodable(fields.fees),
borrowRateCurve: types.BorrowRateCurve.toEncodable(fields.borrowRateCurve),
borrowFactorPct: fields.borrowFactorPct,
depositLimit: fields.depositLimit,
borrowLimit: fields.borrowLimit,
tokenInfo: types.TokenInfo.toEncodable(fields.tokenInfo),
depositWithdrawalCap: types.WithdrawalCaps.toEncodable(fields.depositWithdrawalCap),
debtWithdrawalCap: types.WithdrawalCaps.toEncodable(fields.debtWithdrawalCap),
elevationGroups: fields.elevationGroups,
disableUsageAsCollOutsideEmode: fields.disableUsageAsCollOutsideEmode,
utilizationLimitBlockBorrowingAbovePct: fields.utilizationLimitBlockBorrowingAbovePct,
autodeleverageEnabled: fields.autodeleverageEnabled,
reserved1: fields.reserved1,
borrowLimitOutsideElevationGroup: fields.borrowLimitOutsideElevationGroup,
borrowLimitAgainstThisCollateralInElevationGroup: fields.borrowLimitAgainstThisCollateralInElevationGroup,
deleveragingBonusIncreaseBpsPerDay: fields.deleveragingBonusIncreaseBpsPerDay,
};
}
toJSON() {
return {
status: this.status,
assetTier: this.assetTier,
hostFixedInterestRateBps: this.hostFixedInterestRateBps,
reserved2: this.reserved2,
protocolOrderExecutionFeePct: this.protocolOrderExecutionFeePct,
protocolTakeRatePct: this.protocolTakeRatePct,
protocolLiquidationFeePct: this.protocolLiquidationFeePct,
loanToValuePct: this.loanToValuePct,
liquidationThresholdPct: this.liquidationThresholdPct,
minLiquidationBonusBps: this.minLiquidationBonusBps,
maxLiquidationBonusBps: this.maxLiquidationBonusBps,
badDebtLiquidationBonusBps: this.badDebtLiquidationBonusBps,
deleveragingMarginCallPeriodSecs: this.deleveragingMarginCallPeriodSecs.toString(),
deleveragingThresholdDecreaseBpsPerDay: this.deleveragingThresholdDecreaseBpsPerDay.toString(),
fees: this.fees.toJSON(),
borrowRateCurve: this.borrowRateCurve.toJSON(),
borrowFactorPct: this.borrowFactorPct.toString(),
depositLimit: this.depositLimit.toString(),
borrowLimit: this.borrowLimit.toString(),
tokenInfo: this.tokenInfo.toJSON(),
depositWithdrawalCap: this.depositWithdrawalCap.toJSON(),
debtWithdrawalCap: this.debtWithdrawalCap.toJSON(),
elevationGroups: this.elevationGroups,
disableUsageAsCollOutsideEmode: this.disableUsageAsCollOutsideEmode,
utilizationLimitBlockBorrowingAbovePct: this.utilizationLimitBlockBorrowingAbovePct,
autodeleverageEnabled: this.autodeleverageEnabled,
reserved1: this.reserved1,
borrowLimitOutsideElevationGroup: this.borrowLimitOutsideElevationGroup.toString(),
borrowLimitAgainstThisCollateralInElevationGroup: this.borrowLimitAgainstThisCollateralInElevationGroup.map((item) => item.toString()),
deleveragingBonusIncreaseBpsPerDay: this.deleveragingBonusIncreaseBpsPerDay.toString(),
};
}
static fromJSON(obj) {
return new ReserveConfig({
status: obj.status,
assetTier: obj.assetTier,
hostFixedInterestRateBps: obj.hostFixedInterestRateBps,
reserved2: obj.reserved2,
protocolOrderExecutionFeePct: obj.protocolOrderExecutionFeePct,
protocolTakeRatePct: obj.protocolTakeRatePct,
protocolLiquidationFeePct: obj.protocolLiquidationFeePct,
loanToValuePct: obj.loanToValuePct,
liquidationThresholdPct: obj.liquidationThresholdPct,
minLiquidationBonusBps: obj.minLiquidationBonusBps,
maxLiquidationBonusBps: obj.maxLiquidationBonusBps,
badDebtLiquidationBonusBps: obj.badDebtLiquidationBonusBps,
deleveragingMarginCallPeriodSecs: new bn_js_1.default(obj.deleveragingMarginCallPeriodSecs),
deleveragingThresholdDecreaseBpsPerDay: new bn_js_1.default(obj.deleveragingThresholdDecreaseBpsPerDay),
fees: types.ReserveFees.fromJSON(obj.fees),
borrowRateCurve: types.BorrowRateCurve.fromJSON(obj.borrowRateCurve),
borrowFactorPct: new bn_js_1.default(obj.borrowFactorPct),
depositLimit: new bn_js_1.default(obj.depositLimit),
borrowLimit: new bn_js_1.default(obj.borrowLimit),
tokenInfo: types.TokenInfo.fromJSON(obj.tokenInfo),
depositWithdrawalCap: types.WithdrawalCaps.fromJSON(obj.depositWithdrawalCap),
debtWithdrawalCap: types.WithdrawalCaps.fromJSON(obj.debtWithdrawalCap),
elevationGroups: obj.elevationGroups,
disableUsageAsCollOutsideEmode: obj.disableUsageAsCollOutsideEmode,
utilizationLimitBlockBorrowingAbovePct: obj.utilizationLimitBlockBorrowingAbovePct,
autodeleverageEnabled: obj.autodeleverageEnabled,
reserved1: obj.reserved1,
borrowLimitOutsideElevationGroup: new bn_js_1.default(obj.borrowLimitOutsideElevationGroup),
borrowLimitAgainstThisCollateralInElevationGroup: obj.borrowLimitAgainstThisCollateralInElevationGroup.map((item) => new bn_js_1.default(item)),
deleveragingBonusIncreaseBpsPerDay: new bn_js_1.default(obj.deleveragingBonusIncreaseBpsPerDay),
});
}
toEncodable() {
return ReserveConfig.toEncodable(this);
}
}
exports.ReserveConfig = ReserveConfig;
//# sourceMappingURL=ReserveConfig.js.map