@kamino-finance/klend-sdk 3.2.19 → 3.2.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/classes/action.d.ts +4 -4
- package/dist/classes/action.js +12 -10
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/market.d.ts +18 -2
- package/dist/classes/market.js +0 -32
- package/dist/classes/market.js.map +1 -1
- package/dist/classes/obligation.d.ts +8 -4
- package/dist/classes/obligation.js +138 -9
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/reserve.d.ts +5 -3
- package/dist/classes/reserve.js +72 -2
- package/dist/classes/reserve.js.map +1 -1
- package/dist/utils/instruction.d.ts +1 -1
- package/dist/utils/instruction.js +19 -13
- package/dist/utils/instruction.js.map +1 -1
- package/package.json +3 -3
package/dist/classes/reserve.js
CHANGED
|
@@ -123,13 +123,13 @@ class KaminoReserve {
|
|
|
123
123
|
return (0, utils_2.parseTokenSymbol)(this.state.config.tokenInfo.name);
|
|
124
124
|
}
|
|
125
125
|
/**
|
|
126
|
-
* @returns the total borrowed amount of the reserve
|
|
126
|
+
* @returns the total borrowed amount of the reserve in lamports
|
|
127
127
|
*/
|
|
128
128
|
getBorrowedAmount() {
|
|
129
129
|
return new fraction_1.Fraction(this.state.liquidity.borrowedAmountSf).toDecimal();
|
|
130
130
|
}
|
|
131
131
|
/**
|
|
132
|
-
* @returns the available liquidity amount of the reserve
|
|
132
|
+
* @returns the available liquidity amount of the reserve in lamports
|
|
133
133
|
*/
|
|
134
134
|
getLiquidityAvailableAmount() {
|
|
135
135
|
return new decimal_js_1.default(this.state.liquidity.availableAmount.toString());
|
|
@@ -760,6 +760,68 @@ class KaminoReserve {
|
|
|
760
760
|
const thirdTerm = basePow3.mul(exp).mul(expMinus1).mul(expMinus2).div(6);
|
|
761
761
|
return new decimal_js_1.default(1).add(firstTerm).add(secondTerm).add(thirdTerm);
|
|
762
762
|
}
|
|
763
|
+
getBorrowCapForReserve(market) {
|
|
764
|
+
// Utilization cap
|
|
765
|
+
const utilizationCap = this.state.config.utilizationLimitBlockBorrowingAbove;
|
|
766
|
+
const utilizationCurrentValue = this.calculateUtilizationRatio();
|
|
767
|
+
// Daily borrow cap
|
|
768
|
+
const withdrawalCap = this.state.config.debtWithdrawalCap;
|
|
769
|
+
// Debt against collaterals in elevation groups
|
|
770
|
+
const debtAgainstCollateralReserveCaps = market
|
|
771
|
+
.getMarketElevationGroupDescriptions()
|
|
772
|
+
.filter((x) => x.debtReserve === this.address.toString())
|
|
773
|
+
.map((elevationGroupDescription) => elevationGroupDescription.collateralReserves.map((collateralReserveAddress) => {
|
|
774
|
+
const collRes = market.reserves.get(new web3_js_1.PublicKey(collateralReserveAddress));
|
|
775
|
+
const debtLimitAgainstThisCollInGroup = collRes.state.config.borrowLimitAgainstThisCollateralInElevationGroup[elevationGroupDescription.elevationGroup - 1].toString();
|
|
776
|
+
const debtCounterAgainstThisCollInGroup = collRes.state.borrowedAmountsAgainstThisReserveInElevationGroups[elevationGroupDescription.elevationGroup - 1].toString();
|
|
777
|
+
return {
|
|
778
|
+
collateralReserve: collRes.address,
|
|
779
|
+
elevationGroup: elevationGroupDescription.elevationGroup,
|
|
780
|
+
maxDebt: new decimal_js_1.default(debtLimitAgainstThisCollInGroup),
|
|
781
|
+
currentValue: new decimal_js_1.default(debtCounterAgainstThisCollInGroup),
|
|
782
|
+
};
|
|
783
|
+
}))
|
|
784
|
+
.flat();
|
|
785
|
+
const caps = {
|
|
786
|
+
// Utilization cap
|
|
787
|
+
utilizationCap: new decimal_js_1.default(utilizationCap > 0 ? utilizationCap : 100),
|
|
788
|
+
utilizationCurrentValue: new decimal_js_1.default(utilizationCurrentValue),
|
|
789
|
+
// Daily borrow cap
|
|
790
|
+
netWithdrawalCap: new decimal_js_1.default(withdrawalCap.configCapacity.toString()),
|
|
791
|
+
netWithdrawalCurrentValue: new decimal_js_1.default(withdrawalCap.currentTotal.toString()),
|
|
792
|
+
netWithdrawalLastUpdateTs: new decimal_js_1.default(withdrawalCap.lastIntervalStartTimestamp.toString()),
|
|
793
|
+
netWithdrawalIntervalDurationSeconds: new decimal_js_1.default(withdrawalCap.configIntervalLengthSeconds.toString()),
|
|
794
|
+
// Global cap
|
|
795
|
+
globalDebtCap: new decimal_js_1.default(this.state.config.borrowLimit.toString()),
|
|
796
|
+
globalTotalBorrowed: this.getBorrowedAmount(),
|
|
797
|
+
// Debt outside emode cap
|
|
798
|
+
debtOutsideEmodeCap: new decimal_js_1.default(this.state.config.borrowLimitOutsideElevationGroup.toString()),
|
|
799
|
+
borrowedOutsideEmode: this.getBorrowedAmountOutsideElevationGroup(),
|
|
800
|
+
debtAgainstCollateralReserveCaps: debtAgainstCollateralReserveCaps,
|
|
801
|
+
};
|
|
802
|
+
return caps;
|
|
803
|
+
}
|
|
804
|
+
/* This takes into account all the caps */
|
|
805
|
+
getLiquidityAvailableForDebtReserveGivenCaps(market, elevationGroups) {
|
|
806
|
+
const caps = this.getBorrowCapForReserve(market);
|
|
807
|
+
const liquidityAvailable = this.getLiquidityAvailableAmount();
|
|
808
|
+
// Cap this to utilization cap first
|
|
809
|
+
const utilizationRatioLimit = caps.utilizationCap.div(100);
|
|
810
|
+
const currentUtilizationRatio = this.calculateUtilizationRatio();
|
|
811
|
+
const liquidityGivenUtilizationCap = this.getTotalSupply().mul(utilizationRatioLimit.minus(currentUtilizationRatio));
|
|
812
|
+
const remainingDailyCap = caps.netWithdrawalCap.minus(caps.netWithdrawalCurrentValue);
|
|
813
|
+
const remainingGlobalCap = caps.globalDebtCap.minus(caps.globalTotalBorrowed);
|
|
814
|
+
const remainingOutsideEmodeCap = caps.debtOutsideEmodeCap.minus(caps.borrowedOutsideEmode);
|
|
815
|
+
const availableInCrossMode = decimal_js_1.default.min(liquidityAvailable, liquidityGivenUtilizationCap, remainingDailyCap, remainingGlobalCap, remainingOutsideEmodeCap);
|
|
816
|
+
const availableInElevationGroups = elevationGroups
|
|
817
|
+
.filter((x) => x !== 0)
|
|
818
|
+
.map((elevationGroup) => {
|
|
819
|
+
const capsForElevationGroup = caps.debtAgainstCollateralReserveCaps.filter((x) => x.elevationGroup === elevationGroup);
|
|
820
|
+
const liquidityAvailableInElevationGroup = decimal_js_1.default.min(...capsForElevationGroup.map((x) => x.maxDebt.minus(x.currentValue)));
|
|
821
|
+
return decimal_js_1.default.min(liquidityAvailableInElevationGroup, remainingDailyCap, remainingGlobalCap, liquidityGivenUtilizationCap);
|
|
822
|
+
});
|
|
823
|
+
return [availableInCrossMode, ...availableInElevationGroups];
|
|
824
|
+
}
|
|
763
825
|
}
|
|
764
826
|
exports.KaminoReserve = KaminoReserve;
|
|
765
827
|
const truncateBorrowCurve = (points) => {
|
|
@@ -1386,6 +1448,7 @@ function updateReserveConfigEncodedValue(discriminator, value) {
|
|
|
1386
1448
|
case types_1.UpdateConfigMode.DeleveragingMarginCallPeriod.discriminator:
|
|
1387
1449
|
case types_1.UpdateConfigMode.UpdateBorrowFactor.discriminator:
|
|
1388
1450
|
case types_1.UpdateConfigMode.DeleveragingThresholdSlotsPerBps.discriminator:
|
|
1451
|
+
case types_1.UpdateConfigMode.UpdateBorrowLimitOutsideElevationGroup.discriminator:
|
|
1389
1452
|
value = value;
|
|
1390
1453
|
buffer = Buffer.alloc(8);
|
|
1391
1454
|
buffer.writeBigUint64LE(BigInt(value), 0);
|
|
@@ -1430,6 +1493,13 @@ function updateReserveConfigEncodedValue(discriminator, value) {
|
|
|
1430
1493
|
buffer.writeUIntLE(valueArray[i], i, 1);
|
|
1431
1494
|
}
|
|
1432
1495
|
break;
|
|
1496
|
+
case types_1.UpdateConfigMode.UpdateBorrowLimitsInElevationGroupAgainstThisReserve.discriminator:
|
|
1497
|
+
valueArray = value;
|
|
1498
|
+
buffer = Buffer.alloc(32 * 8);
|
|
1499
|
+
for (let i = 0; i < valueArray.length; i++) {
|
|
1500
|
+
buffer.writeBigUint64LE(BigInt(valueArray[i]), i * 8);
|
|
1501
|
+
}
|
|
1502
|
+
break;
|
|
1433
1503
|
default:
|
|
1434
1504
|
buffer = Buffer.alloc(0);
|
|
1435
1505
|
}
|