@kamino-finance/klend-sdk 5.10.13 → 5.10.15
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/README.md +32 -0
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +8 -6
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/manager.d.ts +6 -5
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +8 -17
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/obligation.js +1 -1
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/reserve.js +9 -9
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/types_utils.d.ts +2 -1
- package/dist/classes/types_utils.d.ts.map +1 -1
- package/dist/classes/types_utils.js +6 -3
- package/dist/classes/types_utils.js.map +1 -1
- package/dist/classes/vault.d.ts +18 -11
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +63 -27
- package/dist/classes/vault.js.map +1 -1
- package/dist/client_kamino_manager.js +2 -2
- package/dist/client_kamino_manager.js.map +1 -1
- package/dist/idl.json +1137 -132
- package/dist/idl_codegen/accounts/LendingMarket.d.ts +6 -6
- package/dist/idl_codegen/accounts/LendingMarket.d.ts.map +1 -1
- package/dist/idl_codegen/accounts/LendingMarket.js +7 -7
- package/dist/idl_codegen/accounts/LendingMarket.js.map +1 -1
- package/dist/idl_codegen/errors/custom.d.ts +15 -7
- package/dist/idl_codegen/errors/custom.d.ts.map +1 -1
- package/dist/idl_codegen/errors/custom.js +28 -14
- package/dist/idl_codegen/errors/custom.js.map +1 -1
- package/dist/idl_codegen/instructions/borrowObligationLiquidityV2.d.ts +29 -0
- package/dist/idl_codegen/instructions/borrowObligationLiquidityV2.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/borrowObligationLiquidityV2.js +125 -0
- package/dist/idl_codegen/instructions/borrowObligationLiquidityV2.js.map +1 -0
- package/dist/idl_codegen/instructions/depositObligationCollateralV2.d.ts +26 -0
- package/dist/idl_codegen/instructions/depositObligationCollateralV2.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/depositObligationCollateralV2.js +110 -0
- package/dist/idl_codegen/instructions/depositObligationCollateralV2.js.map +1 -0
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateralV2.d.ts +31 -0
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateralV2.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateralV2.js +135 -0
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateralV2.js.map +1 -0
- package/dist/idl_codegen/instructions/index.d.ts +18 -0
- package/dist/idl_codegen/instructions/index.d.ts.map +1 -1
- package/dist/idl_codegen/instructions/index.js +19 -1
- package/dist/idl_codegen/instructions/index.js.map +1 -1
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateralV2.d.ts +43 -0
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateralV2.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateralV2.js +181 -0
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateralV2.js.map +1 -0
- package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.d.ts +8 -6
- package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.d.ts.map +1 -1
- package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.js +23 -7
- package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeemV2.d.ts +49 -0
- package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeemV2.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeemV2.js +205 -0
- package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeemV2.js.map +1 -0
- package/dist/idl_codegen/instructions/repayObligationLiquidityV2.d.ts +27 -0
- package/dist/idl_codegen/instructions/repayObligationLiquidityV2.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/repayObligationLiquidityV2.js +111 -0
- package/dist/idl_codegen/instructions/repayObligationLiquidityV2.js.map +1 -0
- package/dist/idl_codegen/instructions/socializeLossV2.d.ts +23 -0
- package/dist/idl_codegen/instructions/socializeLossV2.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/socializeLossV2.js +95 -0
- package/dist/idl_codegen/instructions/socializeLossV2.js.map +1 -0
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.d.ts +31 -0
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.js +135 -0
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.js.map +1 -0
- package/dist/idl_codegen/instructions/withdrawObligationCollateralV2.d.ts +26 -0
- package/dist/idl_codegen/instructions/withdrawObligationCollateralV2.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/withdrawObligationCollateralV2.js +110 -0
- package/dist/idl_codegen/instructions/withdrawObligationCollateralV2.js.map +1 -0
- package/dist/idl_codegen/types/ReserveConfig.d.ts +8 -5
- package/dist/idl_codegen/types/ReserveConfig.d.ts.map +1 -1
- package/dist/idl_codegen/types/ReserveConfig.js +9 -8
- package/dist/idl_codegen/types/ReserveConfig.js.map +1 -1
- package/dist/idl_codegen/types/UpdateConfigMode.d.ts +7 -7
- package/dist/idl_codegen/types/UpdateConfigMode.d.ts.map +1 -1
- package/dist/idl_codegen/types/UpdateConfigMode.js +12 -12
- package/dist/idl_codegen/types/UpdateConfigMode.js.map +1 -1
- package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts +7 -7
- package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts.map +1 -1
- package/dist/idl_codegen/types/UpdateLendingMarketMode.js +12 -12
- package/dist/idl_codegen/types/UpdateLendingMarketMode.js.map +1 -1
- package/dist/idl_codegen/types/index.d.ts +4 -4
- package/dist/idl_codegen/types/index.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/accounts/Reserve.js +2 -2
- package/dist/idl_codegen_kamino_vault/accounts/Reserve.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.js +2 -2
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/errors/index.js +1 -1
- package/dist/idl_codegen_kamino_vault/errors/index.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/deposit.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/deposit.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/initVault.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/initVault.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/invest.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/invest.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateAdmin.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateAdmin.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/withdraw.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/withdraw.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/withdrawFromAvailable.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/withdrawFromAvailable.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/programId.d.ts +3 -2
- package/dist/idl_codegen_kamino_vault/programId.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/programId.js +7 -3
- package/dist/idl_codegen_kamino_vault/programId.js.map +1 -1
- package/dist/lib.d.ts +1 -0
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +1 -0
- package/dist/lib.js.map +1 -1
- package/dist/utils/ObligationType.d.ts.map +1 -1
- package/dist/utils/ObligationType.js.map +1 -1
- package/dist/utils/accountListing.d.ts +3 -1
- package/dist/utils/accountListing.d.ts.map +1 -1
- package/dist/utils/accountListing.js +40 -0
- package/dist/utils/accountListing.js.map +1 -1
- package/dist/utils/managerTypes.js +1 -1
- package/dist/utils/managerTypes.js.map +1 -1
- package/package.json +1 -1
- package/src/classes/action.ts +8 -6
- package/src/classes/manager.ts +9 -19
- package/src/classes/obligation.ts +1 -1
- package/src/classes/reserve.ts +11 -11
- package/src/classes/types_utils.ts +6 -3
- package/src/classes/vault.ts +81 -32
- package/src/client.ts +22 -0
- package/src/client_kamino_manager.ts +2 -2
- package/src/idl.json +1137 -132
- package/src/idl_codegen/accounts/LendingMarket.ts +11 -11
- package/src/idl_codegen/errors/custom.ts +26 -12
- package/src/idl_codegen/instructions/borrowObligationLiquidityV2.ts +124 -0
- package/src/idl_codegen/instructions/depositObligationCollateralV2.ts +106 -0
- package/src/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateralV2.ts +136 -0
- package/src/idl_codegen/instructions/index.ts +45 -0
- package/src/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateralV2.ts +195 -0
- package/src/idl_codegen/instructions/refreshObligationFarmsForReserve.ts +31 -13
- package/src/idl_codegen/instructions/repayAndWithdrawAndRedeemV2.ts +239 -0
- package/src/idl_codegen/instructions/repayObligationLiquidityV2.ts +108 -0
- package/src/idl_codegen/instructions/socializeLossV2.ts +88 -0
- package/src/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.ts +136 -0
- package/src/idl_codegen/instructions/withdrawObligationCollateralV2.ts +106 -0
- package/src/idl_codegen/types/ReserveConfig.ts +17 -14
- package/src/idl_codegen/types/UpdateConfigMode.ts +13 -13
- package/src/idl_codegen/types/UpdateLendingMarketMode.ts +13 -13
- package/src/idl_codegen/types/index.ts +4 -4
- package/src/idl_codegen_kamino_vault/accounts/Reserve.ts +1 -1
- package/src/idl_codegen_kamino_vault/accounts/VaultState.ts +1 -1
- package/src/idl_codegen_kamino_vault/errors/index.ts +1 -1
- package/src/idl_codegen_kamino_vault/instructions/deposit.ts +1 -1
- package/src/idl_codegen_kamino_vault/instructions/giveUpPendingFees.ts +1 -1
- package/src/idl_codegen_kamino_vault/instructions/initVault.ts +1 -1
- package/src/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.ts +1 -1
- package/src/idl_codegen_kamino_vault/instructions/invest.ts +1 -1
- package/src/idl_codegen_kamino_vault/instructions/updateAdmin.ts +1 -1
- package/src/idl_codegen_kamino_vault/instructions/updateReserveAllocation.ts +1 -1
- package/src/idl_codegen_kamino_vault/instructions/updateSharesMetadata.ts +1 -1
- package/src/idl_codegen_kamino_vault/instructions/updateVaultConfig.ts +1 -1
- package/src/idl_codegen_kamino_vault/instructions/withdraw.ts +1 -1
- package/src/idl_codegen_kamino_vault/instructions/withdrawFromAvailable.ts +1 -1
- package/src/idl_codegen_kamino_vault/instructions/withdrawPendingFees.ts +1 -1
- package/src/idl_codegen_kamino_vault/programId.ts +6 -2
- package/src/lib.ts +1 -0
- package/src/utils/ObligationType.ts +2 -10
- package/src/utils/accountListing.ts +43 -1
- package/src/utils/managerTypes.ts +1 -1
package/src/classes/reserve.ts
CHANGED
|
@@ -541,7 +541,7 @@ export class KaminoReserve {
|
|
|
541
541
|
|
|
542
542
|
maxBorrowAmount = maxBorrowAmount.sub(borrowFee);
|
|
543
543
|
|
|
544
|
-
const utilizationRatioLimit = this.state.config.
|
|
544
|
+
const utilizationRatioLimit = this.state.config.utilizationLimitBlockBorrowingAbovePct / 100;
|
|
545
545
|
const currentUtilizationRatio = this.calculateUtilizationRatio();
|
|
546
546
|
|
|
547
547
|
if (utilizationRatioLimit > 0 && currentUtilizationRatio > utilizationRatioLimit) {
|
|
@@ -988,7 +988,7 @@ export class KaminoReserve {
|
|
|
988
988
|
|
|
989
989
|
getBorrowCapForReserve(market: KaminoMarket): BorrowCapsAndCounters {
|
|
990
990
|
// Utilization cap
|
|
991
|
-
const utilizationCap = this.state.config.
|
|
991
|
+
const utilizationCap = this.state.config.utilizationLimitBlockBorrowingAbovePct;
|
|
992
992
|
const utilizationCurrentValue = this.calculateUtilizationRatio();
|
|
993
993
|
|
|
994
994
|
// Daily borrow cap
|
|
@@ -1458,23 +1458,23 @@ export function parseForChangesReserveConfigAndGetIxs(
|
|
|
1458
1458
|
),
|
|
1459
1459
|
});
|
|
1460
1460
|
}
|
|
1461
|
-
} else if (key === '
|
|
1461
|
+
} else if (key === 'utilizationLimitBlockBorrowingAbovePct') {
|
|
1462
1462
|
if (reserve === undefined) {
|
|
1463
1463
|
updateReserveIxnsArgs.push({
|
|
1464
|
-
mode: UpdateConfigMode.
|
|
1464
|
+
mode: UpdateConfigMode.UpdateBlockBorrowingAboveUtilizationPct.discriminator,
|
|
1465
1465
|
value: updateReserveConfigEncodedValue(
|
|
1466
|
-
UpdateConfigMode.
|
|
1467
|
-
reserveConfig.
|
|
1466
|
+
UpdateConfigMode.UpdateBlockBorrowingAboveUtilizationPct.discriminator,
|
|
1467
|
+
reserveConfig.utilizationLimitBlockBorrowingAbovePct
|
|
1468
1468
|
),
|
|
1469
1469
|
});
|
|
1470
1470
|
} else if (
|
|
1471
|
-
reserve.config.
|
|
1471
|
+
reserve.config.utilizationLimitBlockBorrowingAbovePct !== reserveConfig.utilizationLimitBlockBorrowingAbovePct
|
|
1472
1472
|
) {
|
|
1473
1473
|
updateReserveIxnsArgs.push({
|
|
1474
|
-
mode: UpdateConfigMode.
|
|
1474
|
+
mode: UpdateConfigMode.UpdateBlockBorrowingAboveUtilizationPct.discriminator,
|
|
1475
1475
|
value: updateReserveConfigEncodedValue(
|
|
1476
|
-
UpdateConfigMode.
|
|
1477
|
-
reserveConfig.
|
|
1476
|
+
UpdateConfigMode.UpdateBlockBorrowingAboveUtilizationPct.discriminator,
|
|
1477
|
+
reserveConfig.utilizationLimitBlockBorrowingAbovePct
|
|
1478
1478
|
),
|
|
1479
1479
|
});
|
|
1480
1480
|
}
|
|
@@ -1958,7 +1958,7 @@ export function updateReserveConfigEncodedValue(
|
|
|
1958
1958
|
case UpdateConfigMode.UpdateAssetTier.discriminator:
|
|
1959
1959
|
case UpdateConfigMode.UpdateReserveStatus.discriminator:
|
|
1960
1960
|
case UpdateConfigMode.UpdateDisableUsageAsCollateralOutsideEmode.discriminator:
|
|
1961
|
-
case UpdateConfigMode.
|
|
1961
|
+
case UpdateConfigMode.UpdateBlockBorrowingAboveUtilizationPct.discriminator:
|
|
1962
1962
|
case UpdateConfigMode.UpdateBlockPriceUsage.discriminator:
|
|
1963
1963
|
buffer = Buffer.alloc(1);
|
|
1964
1964
|
buffer.writeUIntLE(value as number, 0, 1);
|
|
@@ -5,8 +5,9 @@ export function holdingsToJson(holdings: VaultHoldings) {
|
|
|
5
5
|
return {
|
|
6
6
|
available: holdings.available.toString(),
|
|
7
7
|
invested: holdings.invested.toString(),
|
|
8
|
-
|
|
8
|
+
totalAUMIncludingFees: holdings.totalAUMIncludingFees.toString(),
|
|
9
9
|
investedInReserves: pubkeyHashMapToJson(holdings.investedInReserves),
|
|
10
|
+
pendingFees: holdings.pendingFees.toString(),
|
|
10
11
|
};
|
|
11
12
|
}
|
|
12
13
|
|
|
@@ -14,7 +15,8 @@ export function printHoldings(holdings: VaultHoldings) {
|
|
|
14
15
|
console.log('Holdings:');
|
|
15
16
|
console.log(' Available:', holdings.available.toString());
|
|
16
17
|
console.log(' Invested:', holdings.invested.toString());
|
|
17
|
-
console.log(' Total:', holdings.
|
|
18
|
+
console.log(' Total AUM including fees:', holdings.totalAUMIncludingFees.toString());
|
|
19
|
+
console.log(' Pending fees:', holdings.pendingFees.toString());
|
|
18
20
|
console.log(' Invested in reserves:', pubkeyHashMapToJson(holdings.investedInReserves));
|
|
19
21
|
}
|
|
20
22
|
|
|
@@ -22,7 +24,8 @@ export function printHoldingsWithUSDValue(holdings: VaultHoldingsWithUSDValue) {
|
|
|
22
24
|
console.log('Holdings with USD value:');
|
|
23
25
|
console.log(' Available:', holdings.availableUSD.toString());
|
|
24
26
|
console.log(' Invested:', holdings.investedUSD.toString());
|
|
25
|
-
console.log(' Total:', holdings.
|
|
27
|
+
console.log(' Total including pending fees:', holdings.totalUSDIncludingFees.toString());
|
|
28
|
+
console.log(' Pending fees:', holdings.pendingFeesUSD.toString());
|
|
26
29
|
console.log(' Invested in reserves:', pubkeyHashMapToJson(holdings.investedInReservesUSD));
|
|
27
30
|
}
|
|
28
31
|
|
package/src/classes/vault.ts
CHANGED
|
@@ -79,7 +79,7 @@ import {
|
|
|
79
79
|
UserSharesForVault,
|
|
80
80
|
WithdrawIxs,
|
|
81
81
|
} from './types';
|
|
82
|
-
import { collToLamportsDecimal } from '@kamino-finance/kliquidity-sdk';
|
|
82
|
+
import { collToLamportsDecimal, ZERO } from '@kamino-finance/kliquidity-sdk';
|
|
83
83
|
import { FullBPSDecimal } from '@kamino-finance/kliquidity-sdk/dist/utils/CreationParameters';
|
|
84
84
|
import { FarmState } from '@kamino-finance/farms-sdk/dist';
|
|
85
85
|
import { getAccountsInLUT, initLookupTableIx } from './lut_utils';
|
|
@@ -450,7 +450,7 @@ export class KaminoVaultClient {
|
|
|
450
450
|
* @param farm - the farm where the vault shares can be staked
|
|
451
451
|
* @param [errorOnOverride] - if true, the function will throw an error if the vault already has a farm. If false, it will override the farm
|
|
452
452
|
*/
|
|
453
|
-
async
|
|
453
|
+
async setVaultFarmIxs(
|
|
454
454
|
vault: KaminoVault,
|
|
455
455
|
farm: PublicKey,
|
|
456
456
|
errorOnOverride: boolean = true
|
|
@@ -648,7 +648,7 @@ export class KaminoVaultClient {
|
|
|
648
648
|
const reserveState = reserveStates[index]!;
|
|
649
649
|
const marketAddress = reserveState.lendingMarket;
|
|
650
650
|
|
|
651
|
-
return this.
|
|
651
|
+
return this.withdrawPendingFeesIx(
|
|
652
652
|
vault,
|
|
653
653
|
vaultState,
|
|
654
654
|
marketAddress,
|
|
@@ -884,7 +884,7 @@ export class KaminoVaultClient {
|
|
|
884
884
|
]);
|
|
885
885
|
|
|
886
886
|
const shareLamportsToWithdraw = collToLamportsDecimal(shareAmount, vaultState.sharesMintDecimals.toNumber());
|
|
887
|
-
const withdrawFromAvailableIxn = await this.
|
|
887
|
+
const withdrawFromAvailableIxn = await this.withdrawFromAvailableIx(
|
|
888
888
|
user,
|
|
889
889
|
kaminoVault,
|
|
890
890
|
vaultState,
|
|
@@ -980,7 +980,7 @@ export class KaminoVaultClient {
|
|
|
980
980
|
sharesToWithdraw = reserveWithTokens.shares;
|
|
981
981
|
}
|
|
982
982
|
|
|
983
|
-
const withdrawFromReserveIx = this.
|
|
983
|
+
const withdrawFromReserveIx = this.withdrawIx(
|
|
984
984
|
user,
|
|
985
985
|
vault,
|
|
986
986
|
vaultState,
|
|
@@ -1178,7 +1178,7 @@ export class KaminoVaultClient {
|
|
|
1178
1178
|
return decodeVaultName(token);
|
|
1179
1179
|
}
|
|
1180
1180
|
|
|
1181
|
-
private
|
|
1181
|
+
private withdrawIx(
|
|
1182
1182
|
user: PublicKey,
|
|
1183
1183
|
vault: KaminoVault,
|
|
1184
1184
|
vaultState: VaultState,
|
|
@@ -1248,7 +1248,7 @@ export class KaminoVaultClient {
|
|
|
1248
1248
|
return withdrawIxn;
|
|
1249
1249
|
}
|
|
1250
1250
|
|
|
1251
|
-
private async
|
|
1251
|
+
private async withdrawFromAvailableIx(
|
|
1252
1252
|
user: PublicKey,
|
|
1253
1253
|
vault: KaminoVault,
|
|
1254
1254
|
vaultState: VaultState,
|
|
@@ -1277,7 +1277,7 @@ export class KaminoVaultClient {
|
|
|
1277
1277
|
return withdrawFromAvailable(withdrawFromAvailableArgs, withdrawFromAvailableAccounts, this._kaminoVaultProgramId);
|
|
1278
1278
|
}
|
|
1279
1279
|
|
|
1280
|
-
private async
|
|
1280
|
+
private async withdrawPendingFeesIx(
|
|
1281
1281
|
vault: KaminoVault,
|
|
1282
1282
|
vaultState: VaultState,
|
|
1283
1283
|
marketAddress: PublicKey,
|
|
@@ -1496,7 +1496,7 @@ export class KaminoVaultClient {
|
|
|
1496
1496
|
});
|
|
1497
1497
|
const expectedHoldingsDistribution = new PubkeyHashMap<PublicKey, Decimal>();
|
|
1498
1498
|
|
|
1499
|
-
let totalLeftToInvest = holdings.
|
|
1499
|
+
let totalLeftToInvest = holdings.totalAUMIncludingFees.sub(holdings.pendingFees);
|
|
1500
1500
|
let currentAllocationSum = totalAllocation;
|
|
1501
1501
|
const ZERO = new Decimal(0);
|
|
1502
1502
|
while (totalLeftToInvest.gt(ZERO)) {
|
|
@@ -1671,8 +1671,9 @@ export class KaminoVaultClient {
|
|
|
1671
1671
|
);
|
|
1672
1672
|
|
|
1673
1673
|
const holdings = await this.getVaultHoldings(vaultState, slot, vaultReservesState);
|
|
1674
|
+
const netAUM = holdings.totalAUMIncludingFees.sub(holdings.pendingFees);
|
|
1674
1675
|
|
|
1675
|
-
return
|
|
1676
|
+
return netAUM.div(sharesDecimal);
|
|
1676
1677
|
}
|
|
1677
1678
|
|
|
1678
1679
|
/**
|
|
@@ -2001,20 +2002,24 @@ export class KaminoVaultClient {
|
|
|
2001
2002
|
* @param vault - the kamino vault to get available liquidity to withdraw for
|
|
2002
2003
|
* @param [slot] - the slot for which to calculate the holdings. Optional. If not provided the function will fetch the current slot
|
|
2003
2004
|
* @param [vaultReserves] - a hashmap from each reserve pubkey to the reserve state. Optional. If provided the function will be significantly faster as it will not have to fetch the reserves
|
|
2005
|
+
* @param [currentSlot] - the latest confirmed slot. Optional. If provided the function will be faster as it will not have to fetch the latest slot
|
|
2004
2006
|
* @returns an VaultHoldings object representing the amount available (uninvested) in vault, total amount invested in reseves and a breakdown of the amount invested in each reserve
|
|
2005
2007
|
*/
|
|
2006
2008
|
async getVaultHoldings(
|
|
2007
2009
|
vault: VaultState,
|
|
2008
2010
|
slot?: number,
|
|
2009
|
-
vaultReserves?: PubkeyHashMap<PublicKey, KaminoReserve
|
|
2011
|
+
vaultReserves?: PubkeyHashMap<PublicKey, KaminoReserve>,
|
|
2012
|
+
currentSlot?: number
|
|
2010
2013
|
): Promise<VaultHoldings> {
|
|
2011
2014
|
const vaultHoldings: VaultHoldings = {
|
|
2012
2015
|
available: new Decimal(vault.tokenAvailable.toString()),
|
|
2013
2016
|
invested: new Decimal(0),
|
|
2014
2017
|
investedInReserves: new PubkeyHashMap<PublicKey, Decimal>(),
|
|
2015
|
-
|
|
2018
|
+
totalAUMIncludingFees: new Decimal(0),
|
|
2019
|
+
pendingFees: new Decimal(0),
|
|
2016
2020
|
};
|
|
2017
2021
|
|
|
2022
|
+
const currentSlotToUse = currentSlot ? currentSlot : await this.getConnection().getSlot('confirmed');
|
|
2018
2023
|
const vaultReservesState = vaultReserves ? vaultReserves : await this.loadVaultReserves(vault);
|
|
2019
2024
|
const decimals = new Decimal(vault.tokenMintDecimals.toString());
|
|
2020
2025
|
|
|
@@ -2029,6 +2034,7 @@ export class KaminoVaultClient {
|
|
|
2029
2034
|
}
|
|
2030
2035
|
|
|
2031
2036
|
let reserveCollExchangeRate: Decimal;
|
|
2037
|
+
|
|
2032
2038
|
if (slot) {
|
|
2033
2039
|
reserveCollExchangeRate = reserve.getEstimatedCollateralExchangeRate(slot, 0);
|
|
2034
2040
|
} else {
|
|
@@ -2045,13 +2051,42 @@ export class KaminoVaultClient {
|
|
|
2045
2051
|
);
|
|
2046
2052
|
});
|
|
2047
2053
|
|
|
2054
|
+
const currentPendingFees = new Fraction(vault.pendingFeesSf).toDecimal();
|
|
2055
|
+
let totalPendingFees = currentPendingFees;
|
|
2056
|
+
|
|
2057
|
+
// if there is a slot passed and it is in the future we need to estimate the fees from current time until that moment
|
|
2058
|
+
if (slot && slot > currentSlotToUse) {
|
|
2059
|
+
const currentTimestampSec = new Date().getTime() / 1000;
|
|
2060
|
+
const timeAtPassedSlot = currentTimestampSec + (slot - currentSlotToUse) * this.recentSlotDurationMs;
|
|
2061
|
+
const timeUntilPassedSlot = timeAtPassedSlot - currentTimestampSec;
|
|
2062
|
+
|
|
2063
|
+
const managementFeeFactor = new Decimal(timeUntilPassedSlot)
|
|
2064
|
+
.mul(new Decimal(vault.managementFeeBps.toString()))
|
|
2065
|
+
.div(new Decimal(SECONDS_PER_YEAR))
|
|
2066
|
+
.div(FullBPSDecimal);
|
|
2067
|
+
const prevAUM = lamportsToDecimal(new Fraction(vault.prevAumSf).toDecimal(), vault.tokenMintDecimals.toNumber());
|
|
2068
|
+
const simulatedMgmtFee = prevAUM.mul(managementFeeFactor);
|
|
2069
|
+
totalPendingFees = totalPendingFees.add(simulatedMgmtFee);
|
|
2070
|
+
|
|
2071
|
+
const simulatedEarnedInterest = vaultHoldings.invested
|
|
2072
|
+
.add(vaultHoldings.available)
|
|
2073
|
+
.sub(prevAUM)
|
|
2074
|
+
.sub(simulatedMgmtFee);
|
|
2075
|
+
const simulatedPerformanceFee = simulatedEarnedInterest
|
|
2076
|
+
.mul(new Decimal(vault.performanceFeeBps.toString()))
|
|
2077
|
+
.div(FullBPSDecimal);
|
|
2078
|
+
totalPendingFees = totalPendingFees.add(simulatedPerformanceFee);
|
|
2079
|
+
}
|
|
2080
|
+
|
|
2048
2081
|
const totalAvailableDecimal = lamportsToDecimal(vaultHoldings.available, decimals);
|
|
2049
2082
|
const totalInvestedDecimal = lamportsToDecimal(vaultHoldings.invested, decimals);
|
|
2083
|
+
const pendingFees = lamportsToDecimal(totalPendingFees, decimals);
|
|
2050
2084
|
return {
|
|
2051
2085
|
available: totalAvailableDecimal,
|
|
2052
2086
|
invested: totalInvestedDecimal,
|
|
2053
2087
|
investedInReserves: vaultHoldings.investedInReserves,
|
|
2054
|
-
|
|
2088
|
+
totalAUMIncludingFees: totalAvailableDecimal.add(totalInvestedDecimal),
|
|
2089
|
+
pendingFees: pendingFees,
|
|
2055
2090
|
};
|
|
2056
2091
|
}
|
|
2057
2092
|
|
|
@@ -2081,7 +2116,8 @@ export class KaminoVaultClient {
|
|
|
2081
2116
|
availableUSD: holdings.available.mul(price),
|
|
2082
2117
|
investedUSD: holdings.invested.mul(price),
|
|
2083
2118
|
investedInReservesUSD: investedInReservesUSD,
|
|
2084
|
-
|
|
2119
|
+
totalUSDIncludingFees: holdings.totalAUMIncludingFees.mul(price),
|
|
2120
|
+
pendingFeesUSD: holdings.pendingFees.mul(price),
|
|
2085
2121
|
};
|
|
2086
2122
|
}
|
|
2087
2123
|
|
|
@@ -2202,8 +2238,6 @@ export class KaminoVaultClient {
|
|
|
2202
2238
|
utilizationRatio = totalBorrowed.div(totalInvested.add(totalAvailable));
|
|
2203
2239
|
}
|
|
2204
2240
|
|
|
2205
|
-
console.log('totalInvested', totalInvested.toString());
|
|
2206
|
-
console.log('totalBorrowed', totalBorrowed.toString());
|
|
2207
2241
|
return {
|
|
2208
2242
|
totalInvested: totalInvested,
|
|
2209
2243
|
totalBorrowed: totalBorrowed,
|
|
@@ -2288,17 +2322,26 @@ export class KaminoVaultClient {
|
|
|
2288
2322
|
if (totalWeights.isZero()) {
|
|
2289
2323
|
return new Decimal(0);
|
|
2290
2324
|
}
|
|
2291
|
-
|
|
2325
|
+
|
|
2326
|
+
const grossAPY = totalAPY.div(totalWeights);
|
|
2327
|
+
const netAPY = grossAPY
|
|
2328
|
+
.mul(new Decimal(1).sub(new Decimal(vault.performanceFeeBps.toString()).div(FullBPSDecimal)))
|
|
2329
|
+
.mul(new Decimal(1).sub(new Decimal(vault.managementFeeBps.toString()).div(FullBPSDecimal)));
|
|
2330
|
+
return netAPY;
|
|
2292
2331
|
}
|
|
2293
2332
|
|
|
2294
2333
|
/**
|
|
2295
|
-
* Retrive the total amount of interest earned by the vault since its inception, including what was charged as fees
|
|
2334
|
+
* Retrive the total amount of interest earned by the vault since its inception, up to the last interaction with the vault on chain, including what was charged as fees
|
|
2296
2335
|
* @param vaultState the kamino vault state to get total net yield for
|
|
2297
|
-
* @returns a Decimal representing the net number of tokens earned by the vault since its inception
|
|
2336
|
+
* @returns a struct containing a Decimal representing the net number of tokens earned by the vault since its inception and the timestamp of the last fee charge
|
|
2298
2337
|
*/
|
|
2299
|
-
async getVaultCumulativeInterest(vaultState: VaultState): Promise<
|
|
2338
|
+
async getVaultCumulativeInterest(vaultState: VaultState): Promise<VaultCumulativeInterestWithTimestamp> {
|
|
2300
2339
|
const netYieldLamports = new Fraction(vaultState.cumulativeEarnedInterestSf).toDecimal();
|
|
2301
|
-
|
|
2340
|
+
const cumulativeInterest = lamportsToDecimal(netYieldLamports, vaultState.tokenMintDecimals.toString());
|
|
2341
|
+
return {
|
|
2342
|
+
cumulativeInterest: cumulativeInterest,
|
|
2343
|
+
timestamp: vaultState.lastFeeChargeTimestamp.toNumber(),
|
|
2344
|
+
};
|
|
2302
2345
|
}
|
|
2303
2346
|
|
|
2304
2347
|
/**
|
|
@@ -2313,24 +2356,23 @@ export class KaminoVaultClient {
|
|
|
2313
2356
|
vaultState: VaultState,
|
|
2314
2357
|
vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>,
|
|
2315
2358
|
currentSlot?: number,
|
|
2316
|
-
|
|
2359
|
+
previousNetAUM?: Decimal
|
|
2317
2360
|
): Promise<SimulatedVaultHoldingsWithEarnedInterest> {
|
|
2318
2361
|
let prevAUM: Decimal;
|
|
2362
|
+
let pendingFees = ZERO;
|
|
2319
2363
|
|
|
2320
|
-
if (
|
|
2321
|
-
prevAUM =
|
|
2364
|
+
if (previousNetAUM) {
|
|
2365
|
+
prevAUM = previousNetAUM;
|
|
2322
2366
|
} else {
|
|
2323
|
-
const
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
const lastUpdateHoldings = await this.getVaultHoldings(vaultState, lastUpdateSlot, vaultReservesMap);
|
|
2327
|
-
prevAUM = lastUpdateHoldings.total;
|
|
2367
|
+
const tokenDecimals = vaultState.tokenMintDecimals.toNumber();
|
|
2368
|
+
prevAUM = lamportsToDecimal(new Fraction(vaultState.prevAumSf).toDecimal(), tokenDecimals);
|
|
2369
|
+
pendingFees = lamportsToDecimal(new Fraction(vaultState.pendingFeesSf).toDecimal(), tokenDecimals);
|
|
2328
2370
|
}
|
|
2329
2371
|
|
|
2330
2372
|
const slot = currentSlot ? currentSlot : await this.getConnection().getSlot('confirmed');
|
|
2331
2373
|
|
|
2332
2374
|
const currentHoldings = await this.getVaultHoldings(vaultState, slot, vaultReservesMap);
|
|
2333
|
-
const earnedInterest = currentHoldings.
|
|
2375
|
+
const earnedInterest = currentHoldings.totalAUMIncludingFees.sub(prevAUM).sub(pendingFees);
|
|
2334
2376
|
|
|
2335
2377
|
return {
|
|
2336
2378
|
holdings: currentHoldings,
|
|
@@ -2499,7 +2541,8 @@ export type VaultHoldings = {
|
|
|
2499
2541
|
available: Decimal;
|
|
2500
2542
|
invested: Decimal;
|
|
2501
2543
|
investedInReserves: PubkeyHashMap<PublicKey, Decimal>;
|
|
2502
|
-
|
|
2544
|
+
pendingFees: Decimal;
|
|
2545
|
+
totalAUMIncludingFees: Decimal;
|
|
2503
2546
|
};
|
|
2504
2547
|
|
|
2505
2548
|
/**
|
|
@@ -2515,7 +2558,8 @@ export type VaultHoldingsWithUSDValue = {
|
|
|
2515
2558
|
availableUSD: Decimal;
|
|
2516
2559
|
investedUSD: Decimal;
|
|
2517
2560
|
investedInReservesUSD: PubkeyHashMap<PublicKey, Decimal>;
|
|
2518
|
-
|
|
2561
|
+
totalUSDIncludingFees: Decimal;
|
|
2562
|
+
pendingFeesUSD: Decimal;
|
|
2519
2563
|
};
|
|
2520
2564
|
|
|
2521
2565
|
export type ReserveOverview = {
|
|
@@ -2565,3 +2609,8 @@ export type VaultFees = {
|
|
|
2565
2609
|
managementFee: Decimal;
|
|
2566
2610
|
performanceFee: Decimal;
|
|
2567
2611
|
};
|
|
2612
|
+
|
|
2613
|
+
export type VaultCumulativeInterestWithTimestamp = {
|
|
2614
|
+
cumulativeInterest: Decimal;
|
|
2615
|
+
timestamp: number;
|
|
2616
|
+
};
|
package/src/client.ts
CHANGED
|
@@ -10,6 +10,8 @@ import {
|
|
|
10
10
|
getProgramId,
|
|
11
11
|
toJson,
|
|
12
12
|
getAllObligationAccounts,
|
|
13
|
+
getAllReserveAccounts,
|
|
14
|
+
getAllLendingMarketAccounts,
|
|
13
15
|
} from './lib';
|
|
14
16
|
import * as fs from 'fs';
|
|
15
17
|
import { Connection, GetProgramAccountsFilter, Keypair, PublicKey } from '@solana/web3.js';
|
|
@@ -54,6 +56,16 @@ async function main() {
|
|
|
54
56
|
);
|
|
55
57
|
});
|
|
56
58
|
|
|
59
|
+
commands
|
|
60
|
+
.command('print-all-lending-market-accounts')
|
|
61
|
+
.option(`--rpc <string>`, 'The RPC URL')
|
|
62
|
+
.action(async ({ rpc }) => {
|
|
63
|
+
const connection = new Connection(rpc, {});
|
|
64
|
+
for await (const lendingMarketAccount of getAllLendingMarketAccounts(connection)) {
|
|
65
|
+
console.log(toJson(lendingMarketAccount.toJSON()));
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
57
69
|
commands
|
|
58
70
|
.command('print-obligation')
|
|
59
71
|
.option(`--rpc <string>`, 'The rpc url')
|
|
@@ -86,6 +98,16 @@ async function main() {
|
|
|
86
98
|
await printReserve(connection, reserve, symbol);
|
|
87
99
|
});
|
|
88
100
|
|
|
101
|
+
commands
|
|
102
|
+
.command('print-all-reserve-accounts')
|
|
103
|
+
.option(`--rpc <string>`, 'The RPC URL')
|
|
104
|
+
.action(async ({ rpc }) => {
|
|
105
|
+
const connection = new Connection(rpc, {});
|
|
106
|
+
for await (const reserveAccount of getAllReserveAccounts(connection)) {
|
|
107
|
+
console.log(toJson(reserveAccount.toJSON()));
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
89
111
|
commands
|
|
90
112
|
.command('deposit')
|
|
91
113
|
.option(`--url <string>`, 'Custom RPC URL')
|
|
@@ -1349,7 +1349,7 @@ function parseReserveConfigFromFile(farmConfigFromFile: any): ReserveConfig {
|
|
|
1349
1349
|
elevationGroups: farmConfigFromFile.elevationGroups,
|
|
1350
1350
|
deleveragingThresholdDecreaseBpsPerDay: new BN(farmConfigFromFile.deleveragingThresholdDecreaseBpsPerDay),
|
|
1351
1351
|
disableUsageAsCollOutsideEmode: farmConfigFromFile.disableUsageAsCollOutsideEmode,
|
|
1352
|
-
|
|
1352
|
+
utilizationLimitBlockBorrowingAbovePct: farmConfigFromFile.utilizationLimitBlockBorrowingAbovePct,
|
|
1353
1353
|
hostFixedInterestRateBps: farmConfigFromFile.hostFixedInterestRateBps,
|
|
1354
1354
|
autodeleverageEnabled: farmConfigFromFile.autodeleverageEnabled,
|
|
1355
1355
|
borrowLimitOutsideElevationGroup: new BN(farmConfigFromFile.borrowLimitOutsideElevationGroup),
|
|
@@ -1469,7 +1469,7 @@ function parseReserveConfigToFile(reserveConfig: ReserveConfig) {
|
|
|
1469
1469
|
elevationGroups: reserveConfig.elevationGroups,
|
|
1470
1470
|
deleveragingThresholdDecreaseBpsPerDay: reserveConfig.deleveragingThresholdDecreaseBpsPerDay.toString(),
|
|
1471
1471
|
disableUsageAsCollOutsideEmode: reserveConfig.disableUsageAsCollOutsideEmode,
|
|
1472
|
-
|
|
1472
|
+
utilizationLimitBlockBorrowingAbovePct: reserveConfig.utilizationLimitBlockBorrowingAbovePct,
|
|
1473
1473
|
hostFixedInterestRateBps: reserveConfig.hostFixedInterestRateBps,
|
|
1474
1474
|
autodeleverageEnabled: reserveConfig.autodeleverageEnabled,
|
|
1475
1475
|
borrowLimitOutsideElevationGroup: reserveConfig.borrowLimitOutsideElevationGroup.toString(),
|