@kamino-finance/klend-sdk 7.4.0-beta.0 → 7.4.0-beta.2
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/@codegen/kvault/accounts/LendingMarket.d.ts +480 -0
- package/dist/@codegen/kvault/accounts/LendingMarket.d.ts.map +1 -0
- package/dist/@codegen/kvault/accounts/LendingMarket.js +480 -0
- package/dist/@codegen/kvault/accounts/LendingMarket.js.map +1 -0
- package/dist/@codegen/kvault/accounts/Obligation.d.ts +208 -0
- package/dist/@codegen/kvault/accounts/Obligation.d.ts.map +1 -0
- package/dist/@codegen/kvault/accounts/Obligation.js +298 -0
- package/dist/@codegen/kvault/accounts/Obligation.js.map +1 -0
- package/dist/@codegen/kvault/accounts/ReferrerTokenState.d.ts +51 -0
- package/dist/@codegen/kvault/accounts/ReferrerTokenState.d.ts.map +1 -0
- package/dist/@codegen/kvault/accounts/ReferrerTokenState.js +137 -0
- package/dist/@codegen/kvault/accounts/ReferrerTokenState.js.map +1 -0
- package/dist/@codegen/kvault/accounts/Reserve.d.ts +6 -0
- package/dist/@codegen/kvault/accounts/Reserve.d.ts.map +1 -1
- package/dist/@codegen/kvault/accounts/Reserve.js +9 -2
- package/dist/@codegen/kvault/accounts/Reserve.js.map +1 -1
- package/dist/@codegen/kvault/accounts/VaultState.d.ts +45 -3
- package/dist/@codegen/kvault/accounts/VaultState.d.ts.map +1 -1
- package/dist/@codegen/kvault/accounts/VaultState.js +28 -4
- package/dist/@codegen/kvault/accounts/VaultState.js.map +1 -1
- package/dist/@codegen/kvault/accounts/WithdrawTicket.d.ts +144 -0
- package/dist/@codegen/kvault/accounts/WithdrawTicket.d.ts.map +1 -0
- package/dist/@codegen/kvault/accounts/WithdrawTicket.js +205 -0
- package/dist/@codegen/kvault/accounts/WithdrawTicket.js.map +1 -0
- package/dist/@codegen/kvault/accounts/index.d.ts +8 -0
- package/dist/@codegen/kvault/accounts/index.d.ts.map +1 -1
- package/dist/@codegen/kvault/accounts/index.js +9 -1
- package/dist/@codegen/kvault/accounts/index.js.map +1 -1
- package/dist/@codegen/kvault/errors/custom.d.ts +81 -1
- package/dist/@codegen/kvault/errors/custom.d.ts.map +1 -1
- package/dist/@codegen/kvault/errors/custom.js +141 -1
- package/dist/@codegen/kvault/errors/custom.js.map +1 -1
- package/dist/@codegen/kvault/instructions/index.d.ts +4 -0
- package/dist/@codegen/kvault/instructions/index.d.ts.map +1 -1
- package/dist/@codegen/kvault/instructions/index.js +5 -1
- package/dist/@codegen/kvault/instructions/index.js.map +1 -1
- package/dist/@codegen/kvault/instructions/invest.d.ts +9 -0
- package/dist/@codegen/kvault/instructions/invest.d.ts.map +1 -1
- package/dist/@codegen/kvault/instructions/invest.js +7 -0
- package/dist/@codegen/kvault/instructions/invest.js.map +1 -1
- package/dist/@codegen/kvault/instructions/investInVirtualReserveAndFillOrder.d.ts +51 -0
- package/dist/@codegen/kvault/instructions/investInVirtualReserveAndFillOrder.d.ts.map +1 -0
- package/dist/@codegen/kvault/instructions/investInVirtualReserveAndFillOrder.js +154 -0
- package/dist/@codegen/kvault/instructions/investInVirtualReserveAndFillOrder.js.map +1 -0
- package/dist/@codegen/kvault/instructions/investInVirtualReserveAndFillWithdrawalTicket.d.ts +54 -0
- package/dist/@codegen/kvault/instructions/investInVirtualReserveAndFillWithdrawalTicket.d.ts.map +1 -0
- package/dist/@codegen/kvault/instructions/investInVirtualReserveAndFillWithdrawalTicket.js +166 -0
- package/dist/@codegen/kvault/instructions/investInVirtualReserveAndFillWithdrawalTicket.js.map +1 -0
- package/dist/@codegen/kvault/instructions/updateKlendQueueAccounting.d.ts +1 -0
- package/dist/@codegen/kvault/instructions/updateKlendQueueAccounting.d.ts.map +1 -0
- package/dist/@codegen/kvault/instructions/updateKlendQueueAccounting.js +72 -0
- package/dist/@codegen/kvault/instructions/updateKlendQueueAccounting.js.map +1 -0
- package/dist/@codegen/kvault/instructions/updateReserveAllocation.d.ts +3 -1
- package/dist/@codegen/kvault/instructions/updateReserveAllocation.d.ts.map +1 -1
- package/dist/@codegen/kvault/instructions/updateReserveAllocation.js +3 -0
- package/dist/@codegen/kvault/instructions/updateReserveAllocation.js.map +1 -1
- package/dist/@codegen/kvault/types/BorrowOrder.d.ts +192 -0
- package/dist/@codegen/kvault/types/BorrowOrder.d.ts.map +1 -0
- package/dist/@codegen/kvault/types/BorrowOrder.js +194 -0
- package/dist/@codegen/kvault/types/BorrowOrder.js.map +1 -0
- package/dist/@codegen/kvault/types/ElevationGroup.d.ts +67 -0
- package/dist/@codegen/kvault/types/ElevationGroup.d.ts.map +1 -0
- package/dist/@codegen/kvault/types/ElevationGroup.js +137 -0
- package/dist/@codegen/kvault/types/ElevationGroup.js.map +1 -0
- package/dist/@codegen/kvault/types/FixedTermBorrowRolloverConfig.d.ts +145 -0
- package/dist/@codegen/kvault/types/FixedTermBorrowRolloverConfig.d.ts.map +1 -0
- package/dist/@codegen/kvault/types/FixedTermBorrowRolloverConfig.js +144 -0
- package/dist/@codegen/kvault/types/FixedTermBorrowRolloverConfig.js.map +1 -0
- package/dist/@codegen/kvault/types/ObligationCollateral.d.ts +72 -0
- package/dist/@codegen/kvault/types/ObligationCollateral.d.ts.map +1 -0
- package/dist/@codegen/kvault/types/ObligationCollateral.js +119 -0
- package/dist/@codegen/kvault/types/ObligationCollateral.js.map +1 -0
- package/dist/@codegen/kvault/types/ObligationLiquidity.d.ts +143 -0
- package/dist/@codegen/kvault/types/ObligationLiquidity.d.ts.map +1 -0
- package/dist/@codegen/kvault/types/ObligationLiquidity.js +165 -0
- package/dist/@codegen/kvault/types/ObligationLiquidity.js.map +1 -0
- package/dist/@codegen/kvault/types/ObligationOrder.d.ts +284 -0
- package/dist/@codegen/kvault/types/ObligationOrder.d.ts.map +1 -0
- package/dist/@codegen/kvault/types/ObligationOrder.js +205 -0
- package/dist/@codegen/kvault/types/ObligationOrder.js.map +1 -0
- package/dist/@codegen/kvault/types/ReserveConfig.d.ts +60 -5
- package/dist/@codegen/kvault/types/ReserveConfig.d.ts.map +1 -1
- package/dist/@codegen/kvault/types/ReserveConfig.js +36 -7
- package/dist/@codegen/kvault/types/ReserveConfig.js.map +1 -1
- package/dist/@codegen/kvault/types/ReserveLiquidity.d.ts +26 -8
- package/dist/@codegen/kvault/types/ReserveLiquidity.d.ts.map +1 -1
- package/dist/@codegen/kvault/types/ReserveLiquidity.js +14 -8
- package/dist/@codegen/kvault/types/ReserveLiquidity.js.map +1 -1
- package/dist/@codegen/kvault/types/ReserveType.d.ts +32 -0
- package/dist/@codegen/kvault/types/ReserveType.d.ts.map +1 -0
- package/dist/@codegen/kvault/types/ReserveType.js +108 -0
- package/dist/@codegen/kvault/types/ReserveType.js.map +1 -0
- package/dist/@codegen/kvault/types/VaultAllocation.d.ts +60 -0
- package/dist/@codegen/kvault/types/VaultAllocation.d.ts.map +1 -1
- package/dist/@codegen/kvault/types/VaultAllocation.js +38 -2
- package/dist/@codegen/kvault/types/VaultAllocation.js.map +1 -1
- package/dist/@codegen/kvault/types/WithdrawQueue.d.ts +64 -0
- package/dist/@codegen/kvault/types/WithdrawQueue.d.ts.map +1 -0
- package/dist/@codegen/kvault/types/WithdrawQueue.js +104 -0
- package/dist/@codegen/kvault/types/WithdrawQueue.js.map +1 -0
- package/dist/@codegen/kvault/types/WithdrawTicketProgressEvent.d.ts +19 -0
- package/dist/@codegen/kvault/types/WithdrawTicketProgressEvent.d.ts.map +1 -0
- package/dist/@codegen/kvault/types/WithdrawTicketProgressEvent.js +82 -0
- package/dist/@codegen/kvault/types/WithdrawTicketProgressEvent.js.map +1 -0
- package/dist/@codegen/kvault/types/index.d.ts +34 -0
- package/dist/@codegen/kvault/types/index.d.ts.map +1 -1
- package/dist/@codegen/kvault/types/index.js +19 -1
- package/dist/@codegen/kvault/types/index.js.map +1 -1
- package/dist/classes/action.d.ts +21 -91
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +141 -119
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/actionTypes.d.ts +310 -0
- package/dist/classes/actionTypes.d.ts.map +1 -0
- package/dist/classes/actionTypes.js +3 -0
- package/dist/classes/actionTypes.js.map +1 -0
- package/dist/classes/market.d.ts +109 -15
- package/dist/classes/market.d.ts.map +1 -1
- package/dist/classes/market.js +186 -26
- package/dist/classes/market.js.map +1 -1
- package/dist/classes/obligation.d.ts +11 -11
- package/dist/classes/obligation.d.ts.map +1 -1
- package/dist/classes/obligation.js +56 -56
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/obligationOrder.d.ts.map +1 -1
- package/dist/classes/obligationOrder.js +6 -3
- package/dist/classes/obligationOrder.js.map +1 -1
- package/dist/classes/reserve.d.ts +9 -1
- package/dist/classes/reserve.d.ts.map +1 -1
- package/dist/classes/reserve.js +20 -0
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/shared.d.ts +1 -0
- package/dist/classes/shared.d.ts.map +1 -1
- package/dist/classes/utils.d.ts +2 -0
- package/dist/classes/utils.d.ts.map +1 -1
- package/dist/classes/utils.js +12 -1
- package/dist/classes/utils.js.map +1 -1
- package/dist/classes/vault.d.ts +4 -2
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +12 -2
- package/dist/classes/vault.js.map +1 -1
- package/dist/client/commands/borrow.d.ts +1 -1
- package/dist/client/commands/borrow.d.ts.map +1 -1
- package/dist/client/commands/borrow.js +11 -2
- package/dist/client/commands/borrow.js.map +1 -1
- package/dist/client/commands/deposit.d.ts +1 -1
- package/dist/client/commands/deposit.d.ts.map +1 -1
- package/dist/client/commands/deposit.js +11 -2
- package/dist/client/commands/deposit.js.map +1 -1
- package/dist/client/commands/printReserve.d.ts +1 -1
- package/dist/client/commands/printReserve.d.ts.map +1 -1
- package/dist/client/commands/printReserve.js +2 -4
- package/dist/client/commands/printReserve.js.map +1 -1
- package/dist/client/commands/repay.d.ts +1 -1
- package/dist/client/commands/repay.d.ts.map +1 -1
- package/dist/client/commands/repay.js +12 -2
- package/dist/client/commands/repay.js.map +1 -1
- package/dist/client/commands/withdraw.d.ts +1 -1
- package/dist/client/commands/withdraw.d.ts.map +1 -1
- package/dist/client/commands/withdraw.js +11 -2
- package/dist/client/commands/withdraw.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.d.ts +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.js +2 -2
- package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.d.ts +4 -4
- package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js +43 -10
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.d.ts +4 -4
- package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.js +40 -21
- package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
- package/dist/leverage/operations.d.ts +6 -6
- package/dist/leverage/operations.d.ts.map +1 -1
- package/dist/leverage/operations.js +167 -52
- package/dist/leverage/operations.js.map +1 -1
- package/dist/leverage/types.d.ts +2 -2
- package/dist/leverage/types.d.ts.map +1 -1
- package/dist/manager/client_kamino_manager.js +0 -2
- package/dist/manager/client_kamino_manager.js.map +1 -1
- package/dist/obligation_orders/price_based.js +5 -3
- package/dist/obligation_orders/price_based.js.map +1 -1
- package/dist/utils/ObligationType.d.ts +33 -1
- package/dist/utils/ObligationType.d.ts.map +1 -1
- package/dist/utils/ObligationType.js +81 -2
- package/dist/utils/ObligationType.js.map +1 -1
- package/dist/utils/ReserveKind.d.ts +57 -0
- package/dist/utils/ReserveKind.d.ts.map +1 -0
- package/dist/utils/ReserveKind.js +76 -0
- package/dist/utils/ReserveKind.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/userMetadata.d.ts +2 -2
- package/dist/utils/userMetadata.d.ts.map +1 -1
- package/dist/utils/userMetadata.js +49 -25
- package/dist/utils/userMetadata.js.map +1 -1
- package/dist/utils/validations.d.ts +1 -0
- package/dist/utils/validations.d.ts.map +1 -1
- package/dist/utils/validations.js +5 -0
- package/dist/utils/validations.js.map +1 -1
- package/dist/utils/vault.d.ts.map +1 -1
- package/dist/utils/vault.js +2 -0
- package/dist/utils/vault.js.map +1 -1
- package/package.json +1 -1
- package/src/@codegen/kvault/accounts/LendingMarket.ts +837 -0
- package/src/@codegen/kvault/accounts/Obligation.ts +459 -0
- package/src/@codegen/kvault/accounts/ReferrerTokenState.ts +160 -0
- package/src/@codegen/kvault/accounts/Reserve.ts +13 -2
- package/src/@codegen/kvault/accounts/VaultState.ts +59 -7
- package/src/@codegen/kvault/accounts/WithdrawTicket.ts +280 -0
- package/src/@codegen/kvault/accounts/index.ts +11 -0
- package/src/@codegen/kvault/errors/custom.ts +152 -0
- package/src/@codegen/kvault/instructions/index.ts +10 -0
- package/src/@codegen/kvault/instructions/invest.ts +16 -0
- package/src/@codegen/kvault/instructions/investInVirtualReserveAndFillOrder.ts +189 -0
- package/src/@codegen/kvault/instructions/investInVirtualReserveAndFillWithdrawalTicket.ts +205 -0
- package/src/@codegen/kvault/instructions/updateKlendQueueAccounting.ts +76 -0
- package/src/@codegen/kvault/instructions/updateReserveAllocation.ts +4 -1
- package/src/@codegen/kvault/types/BorrowOrder.ts +267 -0
- package/src/@codegen/kvault/types/ElevationGroup.ts +134 -0
- package/src/@codegen/kvault/types/FixedTermBorrowRolloverConfig.ts +199 -0
- package/src/@codegen/kvault/types/ObligationCollateral.ts +129 -0
- package/src/@codegen/kvault/types/ObligationLiquidity.ts +226 -0
- package/src/@codegen/kvault/types/ObligationOrder.ts +348 -0
- package/src/@codegen/kvault/types/ReserveConfig.ts +72 -9
- package/src/@codegen/kvault/types/ReserveLiquidity.ts +30 -12
- package/src/@codegen/kvault/types/ReserveType.ts +89 -0
- package/src/@codegen/kvault/types/VaultAllocation.ts +74 -2
- package/src/@codegen/kvault/types/WithdrawQueue.ts +117 -0
- package/src/@codegen/kvault/types/WithdrawTicketProgressEvent.ts +59 -0
- package/src/@codegen/kvault/types/index.ts +52 -0
- package/src/classes/action.ts +321 -347
- package/src/classes/actionTypes.ts +295 -0
- package/src/classes/manager.ts +1 -1
- package/src/classes/market.ts +232 -30
- package/src/classes/obligation.ts +62 -59
- package/src/classes/obligationOrder.ts +6 -3
- package/src/classes/reserve.ts +24 -0
- package/src/classes/shared.ts +2 -0
- package/src/classes/utils.ts +8 -0
- package/src/classes/vault.ts +35 -4
- package/src/client/client.ts +17 -18
- package/src/client/commands/borrow.ts +10 -9
- package/src/client/commands/deposit.ts +10 -9
- package/src/client/commands/printReserve.ts +2 -4
- package/src/client/commands/repay.ts +11 -10
- package/src/client/commands/withdraw.ts +15 -9
- package/src/idl/kvault.json +2336 -299
- package/src/lending_operations/repay_with_collateral_calcs.ts +3 -4
- package/src/lending_operations/repay_with_collateral_operations.ts +40 -38
- package/src/lending_operations/swap_collateral_operations.ts +47 -41
- package/src/leverage/operations.ts +168 -129
- package/src/leverage/types.ts +2 -2
- package/src/manager/client_kamino_manager.ts +0 -2
- package/src/obligation_orders/price_based.ts +7 -5
- package/src/utils/ObligationType.ts +92 -1
- package/src/utils/ReserveKind.ts +94 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/userMetadata.ts +64 -30
- package/src/utils/validations.ts +5 -0
- package/src/utils/vault.ts +2 -0
|
@@ -337,31 +337,33 @@ export class KaminoObligation {
|
|
|
337
337
|
return this.deposits.get(reserve);
|
|
338
338
|
}
|
|
339
339
|
|
|
340
|
-
|
|
340
|
+
getBorrowsByMint(mint: Address): Position[] {
|
|
341
|
+
const positions: Position[] = [];
|
|
341
342
|
for (const value of this.borrows.values()) {
|
|
342
343
|
if (value.mintAddress === mint) {
|
|
343
|
-
|
|
344
|
+
positions.push(value);
|
|
344
345
|
}
|
|
345
346
|
}
|
|
346
|
-
return
|
|
347
|
+
return positions;
|
|
347
348
|
}
|
|
348
349
|
|
|
349
350
|
getBorrowAmountByReserve(reserve: KaminoReserve): Decimal {
|
|
350
|
-
const amountLamports = this.
|
|
351
|
+
const amountLamports = this.getBorrowByReserve(reserve.address)?.amount ?? new Decimal(0);
|
|
351
352
|
return amountLamports.div(reserve.getMintFactor());
|
|
352
353
|
}
|
|
353
354
|
|
|
354
|
-
|
|
355
|
+
getDepositsByMint(mint: Address): Position[] {
|
|
356
|
+
const positions: Position[] = [];
|
|
355
357
|
for (const value of this.deposits.values()) {
|
|
356
358
|
if (value.mintAddress === mint) {
|
|
357
|
-
|
|
359
|
+
positions.push(value);
|
|
358
360
|
}
|
|
359
361
|
}
|
|
360
|
-
return
|
|
362
|
+
return positions;
|
|
361
363
|
}
|
|
362
364
|
|
|
363
365
|
getDepositAmountByReserve(reserve: KaminoReserve): Decimal {
|
|
364
|
-
const amountLamports = this.
|
|
366
|
+
const amountLamports = this.getDepositByReserve(reserve.address)?.amount ?? new Decimal(0);
|
|
365
367
|
return amountLamports.div(reserve.getMintFactor());
|
|
366
368
|
}
|
|
367
369
|
|
|
@@ -595,8 +597,8 @@ export class KaminoObligation {
|
|
|
595
597
|
amountCollateral?: Decimal;
|
|
596
598
|
amountDebt?: Decimal;
|
|
597
599
|
action: ActionType;
|
|
598
|
-
|
|
599
|
-
|
|
600
|
+
collateralReserveAddress?: Address;
|
|
601
|
+
debtReserveAddress?: Address;
|
|
600
602
|
market: KaminoMarket;
|
|
601
603
|
reserves: Map<Address, KaminoReserve>;
|
|
602
604
|
slot: Slot;
|
|
@@ -606,18 +608,15 @@ export class KaminoObligation {
|
|
|
606
608
|
deposits: Map<Address, Position>;
|
|
607
609
|
borrows: Map<Address, Position>;
|
|
608
610
|
} {
|
|
609
|
-
const { amountCollateral, amountDebt, action,
|
|
611
|
+
const { amountCollateral, amountDebt, action, collateralReserveAddress, debtReserveAddress, market } = params;
|
|
610
612
|
let newStats = { ...this.refreshedStats };
|
|
611
613
|
|
|
612
|
-
const collateralReservePk = mintCollateral ? market.getReserveByMint(mintCollateral)!.address : undefined;
|
|
613
|
-
const debtReservePk = mintDebt ? market.getReserveByMint(mintDebt)!.address : undefined;
|
|
614
|
-
|
|
615
614
|
const additionalReserves: Address[] = [];
|
|
616
|
-
if (
|
|
617
|
-
additionalReserves.push(
|
|
615
|
+
if (collateralReserveAddress !== undefined) {
|
|
616
|
+
additionalReserves.push(collateralReserveAddress);
|
|
618
617
|
}
|
|
619
|
-
if (
|
|
620
|
-
additionalReserves.push(
|
|
618
|
+
if (debtReserveAddress !== undefined) {
|
|
619
|
+
additionalReserves.push(debtReserveAddress);
|
|
621
620
|
}
|
|
622
621
|
|
|
623
622
|
const { collateralExchangeRates } = KaminoObligation.getRatesForObligation(
|
|
@@ -636,8 +635,8 @@ export class KaminoObligation {
|
|
|
636
635
|
// so we have to recalculate the entire position, not just an updated deposit or borrow
|
|
637
636
|
// as both LTVs and borrow factors can change, affecting all calcs
|
|
638
637
|
|
|
639
|
-
const debtReserveCumulativeBorrowRate =
|
|
640
|
-
? market.
|
|
638
|
+
const debtReserveCumulativeBorrowRate = debtReserveAddress
|
|
639
|
+
? market.getExistingReserveByAddress(debtReserveAddress).getCumulativeBorrowRate()
|
|
641
640
|
: undefined;
|
|
642
641
|
|
|
643
642
|
let newObligationDeposits = this.state.deposits;
|
|
@@ -645,13 +644,13 @@ export class KaminoObligation {
|
|
|
645
644
|
|
|
646
645
|
switch (action) {
|
|
647
646
|
case 'deposit': {
|
|
648
|
-
if (amountCollateral === undefined ||
|
|
649
|
-
throw Error('amountCollateral &
|
|
647
|
+
if (amountCollateral === undefined || collateralReserveAddress === undefined) {
|
|
648
|
+
throw Error('amountCollateral & collateralReserveAddress are required for deposit action');
|
|
650
649
|
}
|
|
651
650
|
newObligationDeposits = this.simulateDepositChange(
|
|
652
651
|
this.state.deposits,
|
|
653
652
|
{
|
|
654
|
-
reserveAddress:
|
|
653
|
+
reserveAddress: collateralReserveAddress,
|
|
655
654
|
amountChangeLamports: amountCollateral,
|
|
656
655
|
},
|
|
657
656
|
collateralExchangeRates
|
|
@@ -659,14 +658,14 @@ export class KaminoObligation {
|
|
|
659
658
|
break;
|
|
660
659
|
}
|
|
661
660
|
case 'borrow': {
|
|
662
|
-
if (amountDebt === undefined ||
|
|
663
|
-
throw Error('amountDebt &
|
|
661
|
+
if (amountDebt === undefined || debtReserveAddress === undefined) {
|
|
662
|
+
throw Error('amountDebt & debtReserveAddress are required for borrow action');
|
|
664
663
|
}
|
|
665
664
|
|
|
666
665
|
newObligationBorrows = this.simulateBorrowChange(
|
|
667
666
|
this.state.borrows,
|
|
668
667
|
{
|
|
669
|
-
reserveAddress:
|
|
668
|
+
reserveAddress: debtReserveAddress,
|
|
670
669
|
amountChangeLamports: amountDebt,
|
|
671
670
|
},
|
|
672
671
|
debtReserveCumulativeBorrowRate!
|
|
@@ -674,14 +673,14 @@ export class KaminoObligation {
|
|
|
674
673
|
break;
|
|
675
674
|
}
|
|
676
675
|
case 'repay': {
|
|
677
|
-
if (amountDebt === undefined ||
|
|
678
|
-
throw Error('amountDebt &
|
|
676
|
+
if (amountDebt === undefined || debtReserveAddress === undefined) {
|
|
677
|
+
throw Error('amountDebt & debtReserveAddress are required for repay action');
|
|
679
678
|
}
|
|
680
679
|
|
|
681
680
|
newObligationBorrows = this.simulateBorrowChange(
|
|
682
681
|
this.state.borrows,
|
|
683
682
|
{
|
|
684
|
-
reserveAddress:
|
|
683
|
+
reserveAddress: debtReserveAddress,
|
|
685
684
|
amountChangeLamports: amountDebt.neg(),
|
|
686
685
|
},
|
|
687
686
|
debtReserveCumulativeBorrowRate!
|
|
@@ -691,13 +690,13 @@ export class KaminoObligation {
|
|
|
691
690
|
}
|
|
692
691
|
|
|
693
692
|
case 'withdraw': {
|
|
694
|
-
if (amountCollateral === undefined ||
|
|
695
|
-
throw Error('amountCollateral &
|
|
693
|
+
if (amountCollateral === undefined || collateralReserveAddress === undefined) {
|
|
694
|
+
throw Error('amountCollateral & collateralReserveAddress are required for withdraw action');
|
|
696
695
|
}
|
|
697
696
|
newObligationDeposits = this.simulateDepositChange(
|
|
698
697
|
this.state.deposits,
|
|
699
698
|
{
|
|
700
|
-
reserveAddress:
|
|
699
|
+
reserveAddress: collateralReserveAddress,
|
|
701
700
|
amountChangeLamports: amountCollateral.neg(),
|
|
702
701
|
},
|
|
703
702
|
collateralExchangeRates
|
|
@@ -708,15 +707,17 @@ export class KaminoObligation {
|
|
|
708
707
|
if (
|
|
709
708
|
amountCollateral === undefined ||
|
|
710
709
|
amountDebt === undefined ||
|
|
711
|
-
|
|
712
|
-
|
|
710
|
+
collateralReserveAddress === undefined ||
|
|
711
|
+
debtReserveAddress === undefined
|
|
713
712
|
) {
|
|
714
|
-
throw Error(
|
|
713
|
+
throw Error(
|
|
714
|
+
'amountColl & amountDebt & collateralReserveAddress & debtReserveAddress are required for depositAndBorrow action'
|
|
715
|
+
);
|
|
715
716
|
}
|
|
716
717
|
newObligationDeposits = this.simulateDepositChange(
|
|
717
718
|
this.state.deposits,
|
|
718
719
|
{
|
|
719
|
-
reserveAddress:
|
|
720
|
+
reserveAddress: collateralReserveAddress,
|
|
720
721
|
amountChangeLamports: amountCollateral,
|
|
721
722
|
},
|
|
722
723
|
collateralExchangeRates
|
|
@@ -725,7 +726,7 @@ export class KaminoObligation {
|
|
|
725
726
|
newObligationBorrows = this.simulateBorrowChange(
|
|
726
727
|
this.state.borrows,
|
|
727
728
|
{
|
|
728
|
-
reserveAddress:
|
|
729
|
+
reserveAddress: debtReserveAddress,
|
|
729
730
|
amountChangeLamports: amountDebt,
|
|
730
731
|
},
|
|
731
732
|
debtReserveCumulativeBorrowRate!
|
|
@@ -736,15 +737,17 @@ export class KaminoObligation {
|
|
|
736
737
|
if (
|
|
737
738
|
amountCollateral === undefined ||
|
|
738
739
|
amountDebt === undefined ||
|
|
739
|
-
|
|
740
|
-
|
|
740
|
+
collateralReserveAddress === undefined ||
|
|
741
|
+
debtReserveAddress === undefined
|
|
741
742
|
) {
|
|
742
|
-
throw Error(
|
|
743
|
+
throw Error(
|
|
744
|
+
'amountColl & amountDebt & collateralReserveAddress & debtReserveAddress are required for repayAndWithdraw action'
|
|
745
|
+
);
|
|
743
746
|
}
|
|
744
747
|
newObligationDeposits = this.simulateDepositChange(
|
|
745
748
|
this.state.deposits,
|
|
746
749
|
{
|
|
747
|
-
reserveAddress:
|
|
750
|
+
reserveAddress: collateralReserveAddress,
|
|
748
751
|
amountChangeLamports: amountCollateral.neg(),
|
|
749
752
|
},
|
|
750
753
|
collateralExchangeRates
|
|
@@ -752,7 +755,7 @@ export class KaminoObligation {
|
|
|
752
755
|
newObligationBorrows = this.simulateBorrowChange(
|
|
753
756
|
this.state.borrows,
|
|
754
757
|
{
|
|
755
|
-
reserveAddress:
|
|
758
|
+
reserveAddress: debtReserveAddress,
|
|
756
759
|
amountChangeLamports: amountDebt.neg(),
|
|
757
760
|
},
|
|
758
761
|
debtReserveCumulativeBorrowRate!
|
|
@@ -1186,7 +1189,7 @@ export class KaminoObligation {
|
|
|
1186
1189
|
not a reserve-specific, caps-specific, liquidity-specific function.
|
|
1187
1190
|
|
|
1188
1191
|
* @param market - The KaminoMarket instance.
|
|
1189
|
-
* @param
|
|
1192
|
+
* @param liquidityReserveAddress - The liquidity reserve Address.
|
|
1190
1193
|
* @param slot - The slot number.
|
|
1191
1194
|
* @param elevationGroup - The elevation group number (default: this.state.elevationGroup).
|
|
1192
1195
|
* @returns The borrow power as a Decimal.
|
|
@@ -1194,11 +1197,11 @@ export class KaminoObligation {
|
|
|
1194
1197
|
*/
|
|
1195
1198
|
getBorrowPower(
|
|
1196
1199
|
market: KaminoMarket,
|
|
1197
|
-
|
|
1200
|
+
liquidityReserveAddress: Address,
|
|
1198
1201
|
slot: Slot,
|
|
1199
1202
|
elevationGroup: number = this.state.elevationGroup
|
|
1200
1203
|
): Decimal {
|
|
1201
|
-
const reserve = market.
|
|
1204
|
+
const reserve = market.getReserveByAddress(liquidityReserveAddress);
|
|
1202
1205
|
if (!reserve) {
|
|
1203
1206
|
throw new Error('Reserve not found');
|
|
1204
1207
|
}
|
|
@@ -1265,7 +1268,7 @@ export class KaminoObligation {
|
|
|
1265
1268
|
and a specific reserve, until it hits max LTV and given available liquidity and caps.
|
|
1266
1269
|
|
|
1267
1270
|
* @param market - The KaminoMarket instance.
|
|
1268
|
-
* @param
|
|
1271
|
+
* @param liquidityReserveAddress - The liquidity reserve Address.
|
|
1269
1272
|
* @param slot - The slot number.
|
|
1270
1273
|
* @param elevationGroup - The elevation group number (default: this.state.elevationGroup).
|
|
1271
1274
|
* @returns The maximum borrow amount as a Decimal.
|
|
@@ -1273,11 +1276,11 @@ export class KaminoObligation {
|
|
|
1273
1276
|
*/
|
|
1274
1277
|
getMaxBorrowAmountV2(
|
|
1275
1278
|
market: KaminoMarket,
|
|
1276
|
-
|
|
1279
|
+
liquidityReserveAddress: Address,
|
|
1277
1280
|
slot: Slot,
|
|
1278
1281
|
elevationGroup: number = this.state.elevationGroup
|
|
1279
1282
|
): Decimal {
|
|
1280
|
-
const reserve = market.
|
|
1283
|
+
const reserve = market.getReserveByAddress(liquidityReserveAddress);
|
|
1281
1284
|
if (!reserve) {
|
|
1282
1285
|
throw new Error('Reserve not found');
|
|
1283
1286
|
}
|
|
@@ -1287,7 +1290,7 @@ export class KaminoObligation {
|
|
|
1287
1290
|
[elevationGroup],
|
|
1288
1291
|
Array.from(this.deposits.keys())
|
|
1289
1292
|
)[0];
|
|
1290
|
-
const maxBorrowAmount = this.getBorrowPower(market,
|
|
1293
|
+
const maxBorrowAmount = this.getBorrowPower(market, liquidityReserveAddress, slot, elevationGroup);
|
|
1291
1294
|
|
|
1292
1295
|
if (elevationGroup === this.state.elevationGroup) {
|
|
1293
1296
|
return Decimal.min(maxBorrowAmount, liquidityAvailable);
|
|
@@ -1304,7 +1307,7 @@ export class KaminoObligation {
|
|
|
1304
1307
|
the new borrow power after the deposit, without overriding the obligation itself.
|
|
1305
1308
|
|
|
1306
1309
|
* @param market - The KaminoMarket instance.
|
|
1307
|
-
* @param
|
|
1310
|
+
* @param liquidityReserveAddress - The liquidity reserve Address.
|
|
1308
1311
|
* @param slot - The slot number.
|
|
1309
1312
|
* @param elevationGroup - The elevation group number (default: this.state.elevationGroup).
|
|
1310
1313
|
* @returns The maximum borrow amount as a Decimal.
|
|
@@ -1312,7 +1315,7 @@ export class KaminoObligation {
|
|
|
1312
1315
|
*/
|
|
1313
1316
|
getMaxBorrowAmountV2WithDeposit(
|
|
1314
1317
|
market: KaminoMarket,
|
|
1315
|
-
|
|
1318
|
+
liquidityReserveAddress: Address,
|
|
1316
1319
|
slot: Slot,
|
|
1317
1320
|
elevationGroup: number = this.state.elevationGroup,
|
|
1318
1321
|
depositAmountLamports: Decimal,
|
|
@@ -1326,7 +1329,7 @@ export class KaminoObligation {
|
|
|
1326
1329
|
];
|
|
1327
1330
|
const obligationWithDeposit = this.withPositionChanges(market, slot, depositChanges);
|
|
1328
1331
|
|
|
1329
|
-
return obligationWithDeposit.getMaxBorrowAmountV2(market,
|
|
1332
|
+
return obligationWithDeposit.getMaxBorrowAmountV2(market, liquidityReserveAddress, slot, elevationGroup);
|
|
1330
1333
|
}
|
|
1331
1334
|
|
|
1332
1335
|
/*
|
|
@@ -1406,11 +1409,11 @@ export class KaminoObligation {
|
|
|
1406
1409
|
/* Deprecated function, also broken */
|
|
1407
1410
|
getMaxBorrowAmount(
|
|
1408
1411
|
market: KaminoMarket,
|
|
1409
|
-
|
|
1412
|
+
liquidityReserveAddress: Address,
|
|
1410
1413
|
slot: Slot,
|
|
1411
1414
|
requestElevationGroup: boolean
|
|
1412
1415
|
): Decimal {
|
|
1413
|
-
const reserve = market.
|
|
1416
|
+
const reserve = market.getReserveByAddress(liquidityReserveAddress);
|
|
1414
1417
|
|
|
1415
1418
|
if (!reserve) {
|
|
1416
1419
|
throw new Error('Reserve not found');
|
|
@@ -1525,8 +1528,8 @@ export class KaminoObligation {
|
|
|
1525
1528
|
return Decimal.max(new Decimal(0), maxBorrowAmount);
|
|
1526
1529
|
}
|
|
1527
1530
|
|
|
1528
|
-
getMaxWithdrawAmount(market: KaminoMarket,
|
|
1529
|
-
const depositReserve = market.
|
|
1531
|
+
getMaxWithdrawAmount(market: KaminoMarket, depositReserveAddress: Address, slot: Slot): Decimal {
|
|
1532
|
+
const depositReserve = market.getReserveByAddress(depositReserveAddress);
|
|
1530
1533
|
|
|
1531
1534
|
if (!depositReserve) {
|
|
1532
1535
|
throw new Error('Reserve not found');
|
|
@@ -1585,7 +1588,7 @@ export class KaminoObligation {
|
|
|
1585
1588
|
* the new withdraw power after the repay, without overriding the obligation itself.
|
|
1586
1589
|
*
|
|
1587
1590
|
* @param market - The KaminoMarket instance.
|
|
1588
|
-
* @param
|
|
1591
|
+
* @param depositReserveAddress - The liquidity (deposit) reserve Address.
|
|
1589
1592
|
* @param slot - The slot number.
|
|
1590
1593
|
* @param repayAmountLamports - The amount to repay in lamports (use U64_MAX for full repay).
|
|
1591
1594
|
* @param repayReserveAddress - The reserve address of the borrow being repaid.
|
|
@@ -1594,7 +1597,7 @@ export class KaminoObligation {
|
|
|
1594
1597
|
*/
|
|
1595
1598
|
getMaxWithdrawAmountWithRepay(
|
|
1596
1599
|
market: KaminoMarket,
|
|
1597
|
-
|
|
1600
|
+
depositReserveAddress: Address,
|
|
1598
1601
|
slot: Slot,
|
|
1599
1602
|
repayAmountLamports: Decimal,
|
|
1600
1603
|
repayReserveAddress: Address
|
|
@@ -1615,7 +1618,7 @@ export class KaminoObligation {
|
|
|
1615
1618
|
];
|
|
1616
1619
|
const obligationWithRepay = this.withPositionChanges(market, slot, undefined, borrowChanges);
|
|
1617
1620
|
|
|
1618
|
-
return obligationWithRepay.getMaxWithdrawAmount(market,
|
|
1621
|
+
return obligationWithRepay.getMaxWithdrawAmount(market, depositReserveAddress, slot);
|
|
1619
1622
|
}
|
|
1620
1623
|
|
|
1621
1624
|
getObligationLiquidityByReserve(reserveAddress: Address): ObligationLiquidity {
|
|
@@ -169,6 +169,7 @@ export class DeleverageDebtAmount implements OrderOpportunity {
|
|
|
169
169
|
return {
|
|
170
170
|
mint: singleBorrow.mintAddress,
|
|
171
171
|
amount: Decimal.min(singleBorrow.amount, this.amount),
|
|
172
|
+
reserveAddress: singleBorrow.reserveAddress,
|
|
172
173
|
};
|
|
173
174
|
}
|
|
174
175
|
}
|
|
@@ -204,6 +205,7 @@ export class DeleverageAllDebt implements OrderOpportunity {
|
|
|
204
205
|
return {
|
|
205
206
|
mint: highestValueBorrow.mintAddress,
|
|
206
207
|
amount: highestValueBorrow.amount,
|
|
208
|
+
reserveAddress: highestValueBorrow.reserveAddress,
|
|
207
209
|
};
|
|
208
210
|
}
|
|
209
211
|
}
|
|
@@ -310,7 +312,7 @@ export class KaminoObligationOrder {
|
|
|
310
312
|
return undefined; // condition not met - cannot execute
|
|
311
313
|
}
|
|
312
314
|
const maxRepay = this.opportunity.getMaxRepay(obligation.getBorrows());
|
|
313
|
-
const repayBorrow = obligation.
|
|
315
|
+
const repayBorrow = obligation.getBorrowByReserve(maxRepay.reserveAddress)!;
|
|
314
316
|
const maxRepayValue = tokenAmountToValue(maxRepay, repayBorrow);
|
|
315
317
|
const executionBonusRate = this.calculateExecutionBonusRate(conditionHit, obligation);
|
|
316
318
|
const executionBonusFactor = new Decimal(1).add(executionBonusRate);
|
|
@@ -342,7 +344,7 @@ export class KaminoObligationOrder {
|
|
|
342
344
|
return valueComparison;
|
|
343
345
|
}
|
|
344
346
|
// Just for deterministic selection in case of multiple equally-good deposits: pick the one with lower mint pubkey (mostly for test stability purposes)
|
|
345
|
-
return leftDeposit.
|
|
347
|
+
return leftDeposit.reserveAddress.localeCompare(rightDeposit.reserveAddress);
|
|
346
348
|
})
|
|
347
349
|
.at(-1)!;
|
|
348
350
|
const actualRepayValue = actualWithdrawValue.div(executionBonusFactor);
|
|
@@ -505,7 +507,7 @@ export type AvailableOrderExecution = {
|
|
|
505
507
|
// Internal calculation functions:
|
|
506
508
|
|
|
507
509
|
function tokenAmountToValue(tokenAmount: TokenAmount, position: Position): Decimal {
|
|
508
|
-
if (tokenAmount.
|
|
510
|
+
if (tokenAmount.reserveAddress !== position.reserveAddress) {
|
|
509
511
|
throw new Error(`Value of token amount ${tokenAmount} cannot be computed using data from ${position}`);
|
|
510
512
|
}
|
|
511
513
|
return tokenAmount.amount.mul(position.marketValueRefreshed).div(position.amount);
|
|
@@ -516,6 +518,7 @@ function valueToTokenAmount(value: Decimal, position: Position): TokenAmount {
|
|
|
516
518
|
return {
|
|
517
519
|
amount: roundNearest(fractionalAmount),
|
|
518
520
|
mint: position.mintAddress,
|
|
521
|
+
reserveAddress: position.reserveAddress,
|
|
519
522
|
};
|
|
520
523
|
}
|
|
521
524
|
|
package/src/classes/reserve.ts
CHANGED
|
@@ -19,6 +19,7 @@ import Decimal from 'decimal.js';
|
|
|
19
19
|
import {
|
|
20
20
|
AllOracleAccounts,
|
|
21
21
|
DEFAULT_PUBLIC_KEY,
|
|
22
|
+
FixedRateReserveKind,
|
|
22
23
|
getTokenOracleData,
|
|
23
24
|
globalConfigPda,
|
|
24
25
|
INITIAL_COLLATERAL_RATE,
|
|
@@ -26,7 +27,9 @@ import {
|
|
|
26
27
|
MarketWithAddress,
|
|
27
28
|
MIN_INITIAL_DEPOSIT,
|
|
28
29
|
ONE_HUNDRED_PCT_IN_BPS,
|
|
30
|
+
FloatRateReserveKind,
|
|
29
31
|
reservePdas,
|
|
32
|
+
ReserveKind,
|
|
30
33
|
SLOTS_PER_DAY,
|
|
31
34
|
SLOTS_PER_SECOND,
|
|
32
35
|
SLOTS_PER_YEAR,
|
|
@@ -76,6 +79,7 @@ export class KaminoReserve {
|
|
|
76
79
|
private readonly recentSlotDurationMs: number;
|
|
77
80
|
|
|
78
81
|
private metadata?: ScopeEntryMetadata[];
|
|
82
|
+
private reserveKind: ReserveKind;
|
|
79
83
|
|
|
80
84
|
constructor(
|
|
81
85
|
state: Reserve,
|
|
@@ -91,6 +95,7 @@ export class KaminoReserve {
|
|
|
91
95
|
this.rpc = connection;
|
|
92
96
|
this.symbol = parseTokenSymbol(state.config.tokenInfo.name);
|
|
93
97
|
this.recentSlotDurationMs = recentSlotDurationMs;
|
|
98
|
+
this.reserveKind = KaminoReserve.createReserveKind(state);
|
|
94
99
|
}
|
|
95
100
|
|
|
96
101
|
static initialize(
|
|
@@ -130,6 +135,16 @@ export class KaminoReserve {
|
|
|
130
135
|
return new KaminoReserve(reserve, address, tokenOracleData, rpc, recentSlotDurationMs);
|
|
131
136
|
}
|
|
132
137
|
|
|
138
|
+
static createReserveKind(state: Reserve): ReserveKind {
|
|
139
|
+
const debtTermSeconds = state.config.debtTermSeconds;
|
|
140
|
+
if (debtTermSeconds.eqn(0)) {
|
|
141
|
+
return new FloatRateReserveKind();
|
|
142
|
+
} else {
|
|
143
|
+
const borrowRateBps = state.config.borrowRateCurve.points[0]?.borrowRateBps || 0;
|
|
144
|
+
return new FixedRateReserveKind(debtTermSeconds, borrowRateBps);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
133
148
|
/// GETTERS
|
|
134
149
|
|
|
135
150
|
/**
|
|
@@ -733,6 +748,15 @@ export class KaminoReserve {
|
|
|
733
748
|
return this.state.collateral.mintPubkey;
|
|
734
749
|
}
|
|
735
750
|
|
|
751
|
+
/**
|
|
752
|
+
* Returns the reserve kind (FloatRateReserveKind or FixedRateReserveKind) for this reserve.
|
|
753
|
+
*
|
|
754
|
+
* @returns The reserve kind instance
|
|
755
|
+
*/
|
|
756
|
+
getKind(): ReserveKind {
|
|
757
|
+
return this.reserveKind;
|
|
758
|
+
}
|
|
759
|
+
|
|
736
760
|
calculateFees(
|
|
737
761
|
amountLamports: Decimal,
|
|
738
762
|
borrowFeeRate: Decimal,
|
package/src/classes/shared.ts
CHANGED
package/src/classes/utils.ts
CHANGED
|
@@ -3,6 +3,7 @@ import Decimal from 'decimal.js';
|
|
|
3
3
|
import { Account, Address } from '@solana/kit';
|
|
4
4
|
import axios from 'axios';
|
|
5
5
|
import { Token } from '@solana-program/token-2022';
|
|
6
|
+
import { ReserveType, ReserveTypeKind } from '../@codegen/kvault/types';
|
|
6
7
|
|
|
7
8
|
type ObligationFarmScoreType = {
|
|
8
9
|
obligationId: string;
|
|
@@ -310,3 +311,10 @@ export async function getMedianSlotDurationInMsFromLastEpochs() {
|
|
|
310
311
|
const response = await axios.get<{ recentSlotDurationInMs: number }>('https://api.kamino.finance/slots/duration');
|
|
311
312
|
return response.data.recentSlotDurationInMs;
|
|
312
313
|
}
|
|
314
|
+
|
|
315
|
+
export const toReserveTypeKind = (rt: number | ReserveTypeKind): ReserveTypeKind => {
|
|
316
|
+
if (typeof rt !== 'number') return rt;
|
|
317
|
+
if (rt === ReserveType.Standard.discriminator) return new ReserveType.Standard();
|
|
318
|
+
if (rt === ReserveType.Virtual.discriminator) return new ReserveType.Virtual();
|
|
319
|
+
throw new Error(`Invalid reserve type: ${rt}`);
|
|
320
|
+
};
|
package/src/classes/vault.ts
CHANGED
|
@@ -82,10 +82,23 @@ import {
|
|
|
82
82
|
withdrawPendingFees,
|
|
83
83
|
WithdrawPendingFeesAccounts,
|
|
84
84
|
} from '../@codegen/kvault/instructions';
|
|
85
|
-
import {
|
|
85
|
+
import {
|
|
86
|
+
ReserveType,
|
|
87
|
+
ReserveTypeKind,
|
|
88
|
+
UpdateReserveWhitelistModeKind,
|
|
89
|
+
VaultConfigField,
|
|
90
|
+
VaultConfigFieldKind,
|
|
91
|
+
} from '../@codegen/kvault/types';
|
|
86
92
|
import { VaultState } from '../@codegen/kvault/accounts';
|
|
87
93
|
import Decimal from 'decimal.js';
|
|
88
|
-
import {
|
|
94
|
+
import {
|
|
95
|
+
bpsToPct,
|
|
96
|
+
decodeVaultName,
|
|
97
|
+
numberToLamportsDecimal,
|
|
98
|
+
parseTokenSymbol,
|
|
99
|
+
pubkeyHashMapToJson,
|
|
100
|
+
toReserveTypeKind,
|
|
101
|
+
} from './utils';
|
|
89
102
|
import { PROGRAM_ID } from '../@codegen/klend/programId';
|
|
90
103
|
import { ReserveWithAddress } from './reserve';
|
|
91
104
|
import { Fraction } from './fraction';
|
|
@@ -552,6 +565,7 @@ export class KaminoVaultClient {
|
|
|
552
565
|
const updateReserveAllocationArgs: UpdateReserveAllocationArgs = {
|
|
553
566
|
weight: new BN(reserveAllocationConfig.targetAllocationWeight),
|
|
554
567
|
cap: new BN(reserveAllocationConfig.getAllocationCapLamports().floor().toString()),
|
|
568
|
+
reserveType: reserveAllocationConfig.getAllocationReserveType(),
|
|
555
569
|
};
|
|
556
570
|
|
|
557
571
|
const updateReserveAllocationIx = updateReserveAllocation(
|
|
@@ -706,7 +720,10 @@ export class KaminoVaultClient {
|
|
|
706
720
|
address: reserve,
|
|
707
721
|
state: vaultReservesMap.get(reserve)!.state,
|
|
708
722
|
};
|
|
709
|
-
const
|
|
723
|
+
const reserveType = vaultState.vaultAllocationStrategy.find(
|
|
724
|
+
(allocation) => allocation.reserve === reserve
|
|
725
|
+
)!.reserveType;
|
|
726
|
+
const reserveAllocationConfig = new ReserveAllocationConfig(reserveWithAddress, 0, new Decimal(0), reserveType);
|
|
710
727
|
|
|
711
728
|
// update allocation to have 0 weight and 0 cap
|
|
712
729
|
const updateAllocIxs = await this.updateReserveAllocationIxs(vault, reserveAllocationConfig, payer);
|
|
@@ -1918,6 +1935,9 @@ export class KaminoVaultClient {
|
|
|
1918
1935
|
payerTokenAccount: payerTokenAta,
|
|
1919
1936
|
tokenMint: vaultState.tokenMint,
|
|
1920
1937
|
reserveCollateralTokenProgram: TOKEN_PROGRAM_ADDRESS,
|
|
1938
|
+
reserveWithdrawTicket: none(), // todo (silviu): impl this properly
|
|
1939
|
+
ownerQueuedCollateralVault: none(), // todo (silviu): impl this properly
|
|
1940
|
+
systemProgram: SYSTEM_PROGRAM_ADDRESS,
|
|
1921
1941
|
};
|
|
1922
1942
|
|
|
1923
1943
|
let investIx = invest(investAccounts, undefined, this._kaminoVaultProgramId);
|
|
@@ -4513,11 +4533,18 @@ export class ReserveAllocationConfig {
|
|
|
4513
4533
|
readonly reserve: ReserveWithAddress;
|
|
4514
4534
|
readonly targetAllocationWeight: number;
|
|
4515
4535
|
readonly allocationCapDecimal: Decimal;
|
|
4536
|
+
readonly allocationReserveType: ReserveTypeKind;
|
|
4516
4537
|
|
|
4517
|
-
constructor(
|
|
4538
|
+
constructor(
|
|
4539
|
+
reserve: ReserveWithAddress,
|
|
4540
|
+
targetAllocationWeight: number,
|
|
4541
|
+
allocationCapDecimal: Decimal,
|
|
4542
|
+
reserveType: number | ReserveTypeKind = new ReserveType.Standard()
|
|
4543
|
+
) {
|
|
4518
4544
|
this.reserve = reserve;
|
|
4519
4545
|
this.targetAllocationWeight = targetAllocationWeight;
|
|
4520
4546
|
this.allocationCapDecimal = allocationCapDecimal;
|
|
4547
|
+
this.allocationReserveType = toReserveTypeKind(reserveType);
|
|
4521
4548
|
}
|
|
4522
4549
|
|
|
4523
4550
|
getAllocationCapLamports(): Decimal {
|
|
@@ -4531,6 +4558,10 @@ export class ReserveAllocationConfig {
|
|
|
4531
4558
|
getReserveAddress(): Address {
|
|
4532
4559
|
return this.reserve.address;
|
|
4533
4560
|
}
|
|
4561
|
+
|
|
4562
|
+
getAllocationReserveType(): ReserveTypeKind {
|
|
4563
|
+
return this.allocationReserveType;
|
|
4564
|
+
}
|
|
4534
4565
|
}
|
|
4535
4566
|
|
|
4536
4567
|
export async function getCTokenVaultPda(
|
package/src/client/client.ts
CHANGED
|
@@ -32,15 +32,15 @@ async function main() {
|
|
|
32
32
|
commands
|
|
33
33
|
.command('print-borrow-rate')
|
|
34
34
|
.option(`--url <string>`, 'The admin keypair file')
|
|
35
|
-
.option(`--
|
|
35
|
+
.option(`--reserveAddress <string>`, 'The token symbol')
|
|
36
36
|
.option(`--cluster <string>`, 'staging or mainnet-beta')
|
|
37
|
-
.action(async ({ url,
|
|
37
|
+
.action(async ({ url, reserveAddress, cluster }) => {
|
|
38
38
|
const env = await initEnv(url);
|
|
39
39
|
|
|
40
40
|
const programId = getProgramId(cluster);
|
|
41
41
|
const kaminoMarket = await getMarket(env.c.rpc, programId);
|
|
42
42
|
|
|
43
|
-
const reserve = kaminoMarket.
|
|
43
|
+
const reserve = kaminoMarket.getReserveByAddress(reserveAddress);
|
|
44
44
|
|
|
45
45
|
const slot = await env.c.rpc.getSlot().send();
|
|
46
46
|
|
|
@@ -130,10 +130,9 @@ async function main() {
|
|
|
130
130
|
.command('print-reserve')
|
|
131
131
|
.option(`--url <string>`, 'The admin keypair file')
|
|
132
132
|
.option(`--reserve <string>`, 'Reserve address')
|
|
133
|
-
.
|
|
134
|
-
.action(async ({ url, reserve, symbol }) => {
|
|
133
|
+
.action(async ({ url, reserve }) => {
|
|
135
134
|
const env = await initEnv(url);
|
|
136
|
-
await printReserve(env.c.rpc, reserve
|
|
135
|
+
await printReserve(env.c.rpc, reserve);
|
|
137
136
|
});
|
|
138
137
|
|
|
139
138
|
commands
|
|
@@ -148,48 +147,48 @@ async function main() {
|
|
|
148
147
|
.command('deposit')
|
|
149
148
|
.option(`--url <string>`, 'Custom RPC URL')
|
|
150
149
|
.option(`--owner <string>`, 'Custom RPC URL')
|
|
151
|
-
.option(`--
|
|
150
|
+
.option(`--reserveAddress <string>`, 'Custom RPC URL')
|
|
152
151
|
.option(`--amount <string>`, 'Custom RPC URL')
|
|
153
|
-
.action(async ({ url, owner,
|
|
152
|
+
.action(async ({ url, owner, reserveAddress, amount }) => {
|
|
154
153
|
const depositAmount = new BN(amount);
|
|
155
154
|
const env = await initEnv(url, owner);
|
|
156
|
-
await deposit(env, 'execute',
|
|
155
|
+
await deposit(env, 'execute', reserveAddress, depositAmount);
|
|
157
156
|
});
|
|
158
157
|
|
|
159
158
|
commands
|
|
160
159
|
.command('withdraw')
|
|
161
160
|
.option(`--url <string>`, 'Custom RPC URL')
|
|
162
161
|
.option(`--owner <string>`, 'Custom RPC URL')
|
|
163
|
-
.option(`--
|
|
162
|
+
.option(`--reserveAddress <string>`, 'Custom RPC URL')
|
|
164
163
|
.option(`--amount <string>`, 'Custom RPC URL')
|
|
165
|
-
.action(async ({ url, owner,
|
|
164
|
+
.action(async ({ url, owner, reserveAddress, amount }) => {
|
|
166
165
|
const withdrawAmount = new BN(amount);
|
|
167
166
|
const env = await initEnv(url, owner);
|
|
168
|
-
await withdraw(env, 'execute',
|
|
167
|
+
await withdraw(env, 'execute', reserveAddress, withdrawAmount);
|
|
169
168
|
});
|
|
170
169
|
|
|
171
170
|
commands
|
|
172
171
|
.command('borrow')
|
|
173
172
|
.option(`--url <string>`, 'Custom RPC URL')
|
|
174
173
|
.option(`--owner <string>`, 'Custom RPC URL')
|
|
175
|
-
.option(`--
|
|
174
|
+
.option(`--reserveAddress <string>`, 'Custom RPC URL')
|
|
176
175
|
.option(`--amount <string>`, 'Custom RPC URL')
|
|
177
|
-
.action(async ({ url, owner,
|
|
176
|
+
.action(async ({ url, owner, reserveAddress, amount }) => {
|
|
178
177
|
const borrowAmount = new BN(amount);
|
|
179
178
|
const env = await initEnv(url, owner);
|
|
180
|
-
await borrow(env, 'execute',
|
|
179
|
+
await borrow(env, 'execute', reserveAddress, borrowAmount);
|
|
181
180
|
});
|
|
182
181
|
|
|
183
182
|
commands
|
|
184
183
|
.command('repay')
|
|
185
184
|
.option(`--url <string>`, 'Custom RPC URL')
|
|
186
185
|
.option(`--owner <string>`, 'Custom RPC URL')
|
|
187
|
-
.option(`--
|
|
186
|
+
.option(`--reserveAddress <string>`, 'Custom RPC URL')
|
|
188
187
|
.option(`--amount <string>`, 'Custom RPC URL')
|
|
189
|
-
.action(async ({ url, owner,
|
|
188
|
+
.action(async ({ url, owner, reserveAddress, amount }) => {
|
|
190
189
|
const repayAmount = new BN(amount);
|
|
191
190
|
const env = await initEnv(url, owner);
|
|
192
|
-
await repay(env, 'execute',
|
|
191
|
+
await repay(env, 'execute', reserveAddress, repayAmount);
|
|
193
192
|
});
|
|
194
193
|
|
|
195
194
|
commands
|