@kamino-finance/klend-sdk 7.1.2 → 7.1.4-beta.0
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/klend/accounts/LendingMarket.d.ts +144 -3
- package/dist/@codegen/klend/accounts/LendingMarket.d.ts.map +1 -1
- package/dist/@codegen/klend/accounts/LendingMarket.js +105 -3
- package/dist/@codegen/klend/accounts/LendingMarket.js.map +1 -1
- package/dist/@codegen/klend/accounts/Obligation.d.ts +30 -15
- package/dist/@codegen/klend/accounts/Obligation.d.ts.map +1 -1
- package/dist/@codegen/klend/accounts/Obligation.js +31 -21
- package/dist/@codegen/klend/accounts/Obligation.js.map +1 -1
- package/dist/@codegen/klend/accounts/PoolState.d.ts +53 -0
- package/dist/@codegen/klend/accounts/PoolState.d.ts.map +1 -0
- package/dist/@codegen/klend/accounts/PoolState.js +167 -0
- package/dist/@codegen/klend/accounts/PoolState.js.map +1 -0
- package/dist/@codegen/klend/accounts/Reserve.d.ts +6 -0
- package/dist/@codegen/klend/accounts/Reserve.d.ts.map +1 -1
- package/dist/@codegen/klend/accounts/Reserve.js +9 -2
- package/dist/@codegen/klend/accounts/Reserve.js.map +1 -1
- package/dist/@codegen/klend/accounts/UnstakeTicket.d.ts +41 -0
- package/dist/@codegen/klend/accounts/UnstakeTicket.d.ts.map +1 -0
- package/dist/@codegen/klend/accounts/UnstakeTicket.js +143 -0
- package/dist/@codegen/klend/accounts/UnstakeTicket.js.map +1 -0
- package/dist/@codegen/klend/accounts/UserState.d.ts +0 -75
- package/dist/@codegen/klend/accounts/UserState.d.ts.map +1 -1
- package/dist/@codegen/klend/accounts/UserState.js +0 -25
- package/dist/@codegen/klend/accounts/UserState.js.map +1 -1
- package/dist/@codegen/klend/accounts/WithdrawTicket.d.ts +132 -0
- package/dist/@codegen/klend/accounts/WithdrawTicket.d.ts.map +1 -0
- package/dist/@codegen/klend/accounts/WithdrawTicket.js +191 -0
- package/dist/@codegen/klend/accounts/WithdrawTicket.js.map +1 -0
- package/dist/@codegen/klend/accounts/index.d.ts +6 -0
- package/dist/@codegen/klend/accounts/index.d.ts.map +1 -1
- package/dist/@codegen/klend/accounts/index.js +7 -1
- package/dist/@codegen/klend/accounts/index.js.map +1 -1
- package/dist/@codegen/klend/errors/custom.d.ts +226 -2
- package/dist/@codegen/klend/errors/custom.d.ts.map +1 -1
- package/dist/@codegen/klend/errors/custom.js +396 -3
- package/dist/@codegen/klend/errors/custom.js.map +1 -1
- package/dist/@codegen/klend/instructions/enqueueToWithdraw.d.ts +39 -0
- package/dist/@codegen/klend/instructions/enqueueToWithdraw.d.ts.map +1 -0
- package/dist/@codegen/klend/instructions/enqueueToWithdraw.js +67 -0
- package/dist/@codegen/klend/instructions/enqueueToWithdraw.js.map +1 -0
- package/dist/@codegen/klend/instructions/fillBorrowOrder.d.ts +36 -0
- package/dist/@codegen/klend/instructions/fillBorrowOrder.d.ts.map +1 -0
- package/dist/@codegen/klend/instructions/fillBorrowOrder.js +49 -0
- package/dist/@codegen/klend/instructions/fillBorrowOrder.js.map +1 -0
- package/dist/@codegen/klend/instructions/idlMissingTypes.d.ts +1 -2
- package/dist/@codegen/klend/instructions/idlMissingTypes.d.ts.map +1 -1
- package/dist/@codegen/klend/instructions/idlMissingTypes.js +6 -2
- package/dist/@codegen/klend/instructions/idlMissingTypes.js.map +1 -1
- package/dist/@codegen/klend/instructions/index.d.ts +16 -0
- package/dist/@codegen/klend/instructions/index.d.ts.map +1 -1
- package/dist/@codegen/klend/instructions/index.js +18 -1
- package/dist/@codegen/klend/instructions/index.js.map +1 -1
- package/dist/@codegen/klend/instructions/initReserve.d.ts +1 -1
- package/dist/@codegen/klend/instructions/initReserve.d.ts.map +1 -1
- package/dist/@codegen/klend/instructions/initReserve.js +1 -5
- package/dist/@codegen/klend/instructions/initReserve.js.map +1 -1
- package/dist/@codegen/klend/instructions/liquidateObligationAndRedeemReserveCollateral.js +1 -1
- package/dist/@codegen/klend/instructions/recoverInvalidTicketCollateral.d.ts +47 -0
- package/dist/@codegen/klend/instructions/recoverInvalidTicketCollateral.d.ts.map +1 -0
- package/dist/@codegen/klend/instructions/recoverInvalidTicketCollateral.js +66 -0
- package/dist/@codegen/klend/instructions/recoverInvalidTicketCollateral.js.map +1 -0
- package/dist/@codegen/klend/instructions/setBorrowOrder.d.ts +31 -0
- package/dist/@codegen/klend/instructions/setBorrowOrder.d.ts.map +1 -0
- package/dist/@codegen/klend/instructions/setBorrowOrder.js +64 -0
- package/dist/@codegen/klend/instructions/setBorrowOrder.js.map +1 -0
- package/dist/@codegen/klend/instructions/unstakeLstCollateralEnd.d.ts +53 -0
- package/dist/@codegen/klend/instructions/unstakeLstCollateralEnd.d.ts.map +1 -0
- package/dist/@codegen/klend/instructions/unstakeLstCollateralEnd.js +190 -0
- package/dist/@codegen/klend/instructions/unstakeLstCollateralEnd.js.map +1 -0
- package/dist/@codegen/klend/instructions/unstakeLstCollateralStart.d.ts +70 -0
- package/dist/@codegen/klend/instructions/unstakeLstCollateralStart.d.ts.map +1 -0
- package/dist/@codegen/klend/instructions/unstakeLstCollateralStart.js +261 -0
- package/dist/@codegen/klend/instructions/unstakeLstCollateralStart.js.map +1 -0
- package/dist/@codegen/klend/instructions/updateGlobalConfig.d.ts +1 -1
- package/dist/@codegen/klend/instructions/updateGlobalConfig.d.ts.map +1 -1
- package/dist/@codegen/klend/instructions/updateGlobalConfig.js +1 -0
- package/dist/@codegen/klend/instructions/updateGlobalConfig.js.map +1 -1
- package/dist/@codegen/klend/instructions/updateReserveConfig.d.ts +1 -1
- package/dist/@codegen/klend/instructions/updateReserveConfig.d.ts.map +1 -1
- package/dist/@codegen/klend/instructions/updateReserveConfig.js +1 -0
- package/dist/@codegen/klend/instructions/updateReserveConfig.js.map +1 -1
- package/dist/@codegen/klend/instructions/withdrawObligationCollateral.js +1 -1
- package/dist/@codegen/klend/instructions/withdrawObligationCollateralV2.js +1 -1
- package/dist/@codegen/klend/instructions/withdrawObligationUsol.d.ts +41 -0
- package/dist/@codegen/klend/instructions/withdrawObligationUsol.d.ts.map +1 -0
- package/dist/@codegen/klend/instructions/withdrawObligationUsol.js +135 -0
- package/dist/@codegen/klend/instructions/withdrawObligationUsol.js.map +1 -0
- package/dist/@codegen/klend/instructions/withdrawQueuedLiquidity.d.ts +51 -0
- package/dist/@codegen/klend/instructions/withdrawQueuedLiquidity.d.ts.map +1 -0
- package/dist/@codegen/klend/instructions/withdrawQueuedLiquidity.js +28 -0
- package/dist/@codegen/klend/instructions/withdrawQueuedLiquidity.js.map +1 -0
- package/dist/@codegen/klend/types/BorrowOrder.d.ts +192 -0
- package/dist/@codegen/klend/types/BorrowOrder.d.ts.map +1 -0
- package/dist/@codegen/klend/types/BorrowOrder.js +194 -0
- package/dist/@codegen/klend/types/BorrowOrder.js.map +1 -0
- package/dist/@codegen/klend/types/BorrowOrderConfigArgs.d.ts +39 -0
- package/dist/@codegen/klend/types/BorrowOrderConfigArgs.d.ts.map +1 -0
- package/dist/@codegen/klend/types/BorrowOrderConfigArgs.js +100 -0
- package/dist/@codegen/klend/types/BorrowOrderConfigArgs.js.map +1 -0
- package/dist/@codegen/klend/types/ObligationLiquidity.d.ts +35 -5
- package/dist/@codegen/klend/types/ObligationLiquidity.d.ts.map +1 -1
- package/dist/@codegen/klend/types/ObligationLiquidity.js +17 -7
- package/dist/@codegen/klend/types/ObligationLiquidity.js.map +1 -1
- package/dist/@codegen/klend/types/ObligationOrder.d.ts +4 -4
- package/dist/@codegen/klend/types/ObligationOrder.js +2 -2
- package/dist/@codegen/klend/types/ReserveConfig.d.ts +141 -29
- package/dist/@codegen/klend/types/ReserveConfig.d.ts.map +1 -1
- package/dist/@codegen/klend/types/ReserveConfig.js +89 -25
- package/dist/@codegen/klend/types/ReserveConfig.js.map +1 -1
- package/dist/@codegen/klend/types/ReserveFees.d.ts +8 -8
- package/dist/@codegen/klend/types/ReserveFees.d.ts.map +1 -1
- package/dist/@codegen/klend/types/ReserveFees.js +8 -8
- package/dist/@codegen/klend/types/ReserveFees.js.map +1 -1
- package/dist/@codegen/klend/types/ReserveLiquidity.d.ts +26 -8
- package/dist/@codegen/klend/types/ReserveLiquidity.d.ts.map +1 -1
- package/dist/@codegen/klend/types/ReserveLiquidity.js +14 -8
- package/dist/@codegen/klend/types/ReserveLiquidity.js.map +1 -1
- package/dist/@codegen/klend/types/UpdateConfigMode.d.ts +92 -14
- package/dist/@codegen/klend/types/UpdateConfigMode.d.ts.map +1 -1
- package/dist/@codegen/klend/types/UpdateConfigMode.js +168 -23
- package/dist/@codegen/klend/types/UpdateConfigMode.js.map +1 -1
- package/dist/@codegen/klend/types/UpdateLendingMarketMode.d.ts +130 -0
- package/dist/@codegen/klend/types/UpdateLendingMarketMode.d.ts.map +1 -1
- package/dist/@codegen/klend/types/UpdateLendingMarketMode.js +241 -1
- package/dist/@codegen/klend/types/UpdateLendingMarketMode.js.map +1 -1
- package/dist/@codegen/klend/types/WithdrawQueue.d.ts +64 -0
- package/dist/@codegen/klend/types/WithdrawQueue.d.ts.map +1 -0
- package/dist/@codegen/klend/types/WithdrawQueue.js +104 -0
- package/dist/@codegen/klend/types/WithdrawQueue.js.map +1 -0
- package/dist/@codegen/klend/types/index.d.ts +10 -8
- package/dist/@codegen/klend/types/index.d.ts.map +1 -1
- package/dist/@codegen/klend/types/index.js +7 -3
- package/dist/@codegen/klend/types/index.js.map +1 -1
- package/dist/@codegen/klend/zero_padding/ObligationZP.d.ts +9 -4
- package/dist/@codegen/klend/zero_padding/ObligationZP.d.ts.map +1 -1
- package/dist/@codegen/klend/zero_padding/ObligationZP.js +22 -13
- package/dist/@codegen/klend/zero_padding/ObligationZP.js.map +1 -1
- package/dist/classes/action.d.ts +30 -3
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +364 -10
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +10 -0
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/market.d.ts +6 -2
- package/dist/classes/market.d.ts.map +1 -1
- package/dist/classes/market.js +26 -6
- package/dist/classes/market.js.map +1 -1
- package/dist/classes/obligation.js +1 -1
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/reserve.d.ts.map +1 -1
- package/dist/classes/reserve.js +13 -7
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/unstakingPool.d.ts +20 -3
- package/dist/classes/unstakingPool.d.ts.map +1 -1
- package/dist/classes/unstakingPool.js +62 -8
- package/dist/classes/unstakingPool.js.map +1 -1
- package/dist/idl/klend.json +2125 -232
- package/dist/lending_operations/index.d.ts +1 -0
- package/dist/lending_operations/index.d.ts.map +1 -1
- package/dist/lending_operations/index.js +1 -0
- package/dist/lending_operations/index.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js +0 -2
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.js +0 -1
- package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
- package/dist/lending_operations/unstake_lst_collateral.d.ts +12 -0
- package/dist/lending_operations/unstake_lst_collateral.d.ts.map +1 -0
- package/dist/lending_operations/unstake_lst_collateral.js +104 -0
- package/dist/lending_operations/unstake_lst_collateral.js.map +1 -0
- package/dist/leverage/calcs.d.ts +2 -27
- package/dist/leverage/calcs.d.ts.map +1 -1
- package/dist/leverage/calcs.js +6 -136
- package/dist/leverage/calcs.js.map +1 -1
- package/dist/leverage/operations.d.ts +8 -9
- package/dist/leverage/operations.d.ts.map +1 -1
- package/dist/leverage/operations.js +72 -228
- package/dist/leverage/operations.js.map +1 -1
- package/dist/leverage/types.d.ts +0 -19
- package/dist/leverage/types.d.ts.map +1 -1
- package/dist/leverage/utils.d.ts +2 -19
- package/dist/leverage/utils.d.ts.map +1 -1
- package/dist/leverage/utils.js +0 -164
- package/dist/leverage/utils.js.map +1 -1
- package/dist/manager/client_kamino_manager.js +11 -8
- package/dist/manager/client_kamino_manager.js.map +1 -1
- package/dist/utils/managerTypes.d.ts.map +1 -1
- package/dist/utils/managerTypes.js +9 -4
- package/dist/utils/managerTypes.js.map +1 -1
- package/dist/utils/seeds.d.ts +10 -14
- package/dist/utils/seeds.d.ts.map +1 -1
- package/dist/utils/seeds.js +25 -22
- package/dist/utils/seeds.js.map +1 -1
- package/package.json +2 -2
- package/src/@codegen/klend/accounts/LendingMarket.ts +210 -5
- package/src/@codegen/klend/accounts/Obligation.ts +53 -31
- package/src/@codegen/klend/accounts/PoolState.ts +192 -0
- package/src/@codegen/klend/accounts/Reserve.ts +13 -2
- package/src/@codegen/klend/accounts/UnstakeTicket.ts +160 -0
- package/src/@codegen/klend/accounts/UserState.ts +0 -75
- package/src/@codegen/klend/accounts/WithdrawTicket.ts +256 -0
- package/src/@codegen/klend/accounts/index.ts +6 -0
- package/src/@codegen/klend/errors/custom.ts +427 -2
- package/src/@codegen/klend/instructions/enqueueToWithdraw.ts +89 -0
- package/src/@codegen/klend/instructions/fillBorrowOrder.ts +96 -0
- package/src/@codegen/klend/instructions/idlMissingTypes.ts +7 -4
- package/src/@codegen/klend/instructions/index.ts +34 -0
- package/src/@codegen/klend/instructions/initReserve.ts +2 -6
- package/src/@codegen/klend/instructions/liquidateObligationAndRedeemReserveCollateral.ts +1 -1
- package/src/@codegen/klend/instructions/recoverInvalidTicketCollateral.ts +96 -0
- package/src/@codegen/klend/instructions/setBorrowOrder.ts +77 -0
- package/src/@codegen/klend/instructions/unstakeLstCollateralEnd.ts +251 -0
- package/src/@codegen/klend/instructions/unstakeLstCollateralStart.ts +353 -0
- package/src/@codegen/klend/instructions/updateGlobalConfig.ts +2 -1
- package/src/@codegen/klend/instructions/updateReserveConfig.ts +2 -1
- package/src/@codegen/klend/instructions/withdrawObligationCollateral.ts +1 -1
- package/src/@codegen/klend/instructions/withdrawObligationCollateralV2.ts +1 -1
- package/src/@codegen/klend/instructions/withdrawObligationUsol.ts +168 -0
- package/src/@codegen/klend/instructions/withdrawQueuedLiquidity.ts +92 -0
- package/src/@codegen/klend/types/BorrowOrder.ts +267 -0
- package/src/@codegen/klend/types/BorrowOrderConfigArgs.ts +87 -0
- package/src/@codegen/klend/types/ObligationLiquidity.ts +39 -9
- package/src/@codegen/klend/types/ObligationOrder.ts +4 -4
- package/src/@codegen/klend/types/ReserveConfig.ts +171 -39
- package/src/@codegen/klend/types/ReserveFees.ts +12 -12
- package/src/@codegen/klend/types/ReserveLiquidity.ts +30 -12
- package/src/@codegen/klend/types/UpdateConfigMode.ts +206 -26
- package/src/@codegen/klend/types/UpdateLendingMarketMode.ts +300 -0
- package/src/@codegen/klend/types/WithdrawQueue.ts +117 -0
- package/src/@codegen/klend/types/index.ts +45 -16
- package/src/@codegen/klend/zero_padding/ObligationZP.ts +22 -13
- package/src/classes/action.ts +577 -8
- package/src/classes/manager.ts +11 -0
- package/src/classes/market.ts +36 -5
- package/src/classes/obligation.ts +1 -1
- package/src/classes/reserve.ts +13 -8
- package/src/classes/unstakingPool.ts +83 -6
- package/src/idl/klend.json +2126 -233
- package/src/lending_operations/index.ts +1 -0
- package/src/lending_operations/repay_with_collateral_operations.ts +0 -2
- package/src/lending_operations/swap_collateral_operations.ts +0 -1
- package/src/lending_operations/unstake_lst_collateral.ts +174 -0
- package/src/leverage/calcs.ts +2 -201
- package/src/leverage/operations.ts +45 -377
- package/src/leverage/types.ts +0 -20
- package/src/leverage/utils.ts +3 -320
- package/src/manager/client_kamino_manager.ts +11 -8
- package/src/utils/managerTypes.ts +9 -4
- package/src/utils/seeds.ts +28 -26
- package/dist/@codegen/klend/types/AssetTier.d.ts +0 -45
- package/dist/@codegen/klend/types/AssetTier.d.ts.map +0 -1
- package/dist/@codegen/klend/types/AssetTier.js +0 -132
- package/dist/@codegen/klend/types/AssetTier.js.map +0 -1
- package/src/@codegen/klend/types/AssetTier.ts +0 -119
|
@@ -151,7 +151,6 @@ export async function getRepayWithCollSwapInputs<QuoteResponse>({
|
|
|
151
151
|
inputAmountLamports,
|
|
152
152
|
inputMint: collTokenMint,
|
|
153
153
|
outputMint: debtTokenMint,
|
|
154
|
-
amountDebtAtaBalance: undefined, // only used for kTokens
|
|
155
154
|
};
|
|
156
155
|
|
|
157
156
|
const swapQuote = await quoter(swapQuoteInputs, uniqueKlendAccounts);
|
|
@@ -169,7 +168,6 @@ export async function getRepayWithCollSwapInputs<QuoteResponse>({
|
|
|
169
168
|
minOutAmountLamports: flashRepayAmountLamports,
|
|
170
169
|
inputMint: collTokenMint,
|
|
171
170
|
outputMint: debtTokenMint,
|
|
172
|
-
amountDebtAtaBalance: undefined, // only used for kTokens
|
|
173
171
|
},
|
|
174
172
|
flashLoanInfo: klendIxs.flashLoanInfo,
|
|
175
173
|
initialInputs: {
|
|
@@ -529,7 +529,6 @@ async function getExternalSwapIxs<QuoteResponse>(
|
|
|
529
529
|
inputAmountLamports: args.sourceCollSwapAmount.mul(context.sourceCollReserve.getMintFactor()),
|
|
530
530
|
inputMint: context.sourceCollReserve.getLiquidityMint(),
|
|
531
531
|
outputMint: context.targetCollReserve.getLiquidityMint(),
|
|
532
|
-
amountDebtAtaBalance: undefined, // only used for kTokens
|
|
533
532
|
};
|
|
534
533
|
const externalSwapQuote = await context.quoter(externalSwapInputs, klendAccounts);
|
|
535
534
|
const externalSwapIxsAndLuts = await context.swapper(externalSwapInputs, klendAccounts, externalSwapQuote);
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Fraction,
|
|
3
|
+
getStandardPoolMintRemainingAccounts,
|
|
4
|
+
KaminoAction,
|
|
5
|
+
KaminoMarket,
|
|
6
|
+
KaminoObligation,
|
|
7
|
+
KaminoReserve,
|
|
8
|
+
maybeGetStakedPoolByMint,
|
|
9
|
+
} from '../classes';
|
|
10
|
+
import { getFlashLoanInstructions, getScopeRefreshIx } from '../leverage';
|
|
11
|
+
import {
|
|
12
|
+
createAtasIdempotent,
|
|
13
|
+
getComputeBudgetAndPriorityFeeIxs,
|
|
14
|
+
ScopePriceRefreshConfig,
|
|
15
|
+
SLOTS_PER_DAY,
|
|
16
|
+
} from '../utils';
|
|
17
|
+
import Decimal from 'decimal.js';
|
|
18
|
+
import BN from 'bn.js';
|
|
19
|
+
import { Address, IInstruction, none, Option, Slot, TransactionSigner } from '@solana/kit';
|
|
20
|
+
|
|
21
|
+
const LST_CONVERSION_MARGIN_BPS = new Decimal(100);
|
|
22
|
+
const FULL_BPS = new Decimal(10_000);
|
|
23
|
+
|
|
24
|
+
export async function buildUnstakeLstCollateralStartIxs(
|
|
25
|
+
market: KaminoMarket,
|
|
26
|
+
obligation: KaminoObligation,
|
|
27
|
+
owner: TransactionSigner,
|
|
28
|
+
lstMint: Address,
|
|
29
|
+
referrer: Option<Address>,
|
|
30
|
+
currentSlot: Slot,
|
|
31
|
+
budgetAndPriorityFeeIxs: IInstruction[] | undefined,
|
|
32
|
+
scopeRefreshConfig: ScopePriceRefreshConfig | undefined
|
|
33
|
+
): Promise<{ instructions: IInstruction[]; remainingSigners: TransactionSigner[] }> {
|
|
34
|
+
// Get reserves based on obligation
|
|
35
|
+
const usolMint = await market.getUsolPoolMint();
|
|
36
|
+
const usolReserve = market.getReserveByMint(usolMint);
|
|
37
|
+
const lstReserve = market.getReserveByMint(lstMint);
|
|
38
|
+
const debtReserve = market.reserves.get(obligation.state.borrows[0].borrowReserve);
|
|
39
|
+
if (!usolReserve) {
|
|
40
|
+
throw new Error(`Cannot fetch usol reserve for mint ${usolMint}`);
|
|
41
|
+
}
|
|
42
|
+
if (!lstReserve) {
|
|
43
|
+
throw new Error(`Cannot fetch lst reserve for mint ${obligation.state.deposits[0].depositReserve}`);
|
|
44
|
+
}
|
|
45
|
+
if (!debtReserve) {
|
|
46
|
+
throw new Error(`Cannot fetch debt reserve for mint ${obligation.state.borrows[0].borrowReserve}`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// 0. Compute sol to repay + lst to flash borrow + additional accounts
|
|
50
|
+
const stakePool = await maybeGetStakedPoolByMint(market.getRpc(), lstReserve.getLiquidityMint());
|
|
51
|
+
if (!stakePool) {
|
|
52
|
+
throw new Error(`Cannot fetch stake pool for mint ${lstReserve.getLiquidityMint()}`);
|
|
53
|
+
}
|
|
54
|
+
const { lstToConvert } = getUnstakeLstCollateralApproximateInputs(
|
|
55
|
+
market,
|
|
56
|
+
debtReserve,
|
|
57
|
+
lstReserve,
|
|
58
|
+
obligation,
|
|
59
|
+
currentSlot
|
|
60
|
+
);
|
|
61
|
+
const [depositStakedSolRemainingAccounts, remainingSigners] = await getStandardPoolMintRemainingAccounts(
|
|
62
|
+
market.getRpc(),
|
|
63
|
+
stakePool[0],
|
|
64
|
+
stakePool[1],
|
|
65
|
+
new BN(lstToConvert.toString())
|
|
66
|
+
);
|
|
67
|
+
// 1. Create atas & budget txns
|
|
68
|
+
const budgetIxs = budgetAndPriorityFeeIxs || getComputeBudgetAndPriorityFeeIxs(1_400_000);
|
|
69
|
+
|
|
70
|
+
const atas = [
|
|
71
|
+
{ mint: usolReserve.getLiquidityMint(), tokenProgram: usolReserve.getLiquidityTokenProgram() },
|
|
72
|
+
{ mint: lstReserve.getLiquidityMint(), tokenProgram: lstReserve.getLiquidityTokenProgram() },
|
|
73
|
+
];
|
|
74
|
+
|
|
75
|
+
const atasAndIxs = await createAtasIdempotent(owner, atas);
|
|
76
|
+
const [, { ata: lstAta }] = atasAndIxs;
|
|
77
|
+
const scopeRefreshIx = await getScopeRefreshIx(market, lstReserve, debtReserve, obligation, scopeRefreshConfig);
|
|
78
|
+
|
|
79
|
+
// 2. Flash borrow & repay the debt to repay amount needed
|
|
80
|
+
const { flashBorrowIx, flashRepayIx } = getFlashLoanInstructions({
|
|
81
|
+
borrowIxIndex: budgetIxs.length + atasAndIxs.length + (scopeRefreshIx.length > 0 ? 1 : 0),
|
|
82
|
+
userTransferAuthority: owner,
|
|
83
|
+
lendingMarketAuthority: await market.getLendingMarketAuthority(),
|
|
84
|
+
lendingMarketAddress: market.getAddress(),
|
|
85
|
+
reserve: lstReserve,
|
|
86
|
+
amountLamports: lstToConvert,
|
|
87
|
+
destinationAta: lstAta,
|
|
88
|
+
// TODO(referrals): once we support referrals, we will have to replace the placeholder args below:
|
|
89
|
+
referrerAccount: none(),
|
|
90
|
+
referrerTokenState: none(),
|
|
91
|
+
programId: market.programId,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// 3. Repay using the flash borrowed funds & withdraw collateral to swap and pay the flash loan
|
|
95
|
+
const unstakeLstCollateralStartAction = await KaminoAction.buildUnstakeLstCollateralStartTxns(
|
|
96
|
+
market,
|
|
97
|
+
lstToConvert.toString(),
|
|
98
|
+
usolReserve.getLiquidityMint(),
|
|
99
|
+
lstReserve.getLiquidityMint(),
|
|
100
|
+
owner,
|
|
101
|
+
currentSlot,
|
|
102
|
+
obligation,
|
|
103
|
+
depositStakedSolRemainingAccounts,
|
|
104
|
+
undefined,
|
|
105
|
+
0,
|
|
106
|
+
false,
|
|
107
|
+
undefined,
|
|
108
|
+
referrer
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
const instructions = [
|
|
112
|
+
...scopeRefreshIx,
|
|
113
|
+
...budgetIxs,
|
|
114
|
+
...atasAndIxs.map((x) => x.createAtaIx),
|
|
115
|
+
flashBorrowIx,
|
|
116
|
+
...KaminoAction.actionToIxs(unstakeLstCollateralStartAction),
|
|
117
|
+
flashRepayIx,
|
|
118
|
+
];
|
|
119
|
+
return {
|
|
120
|
+
instructions,
|
|
121
|
+
remainingSigners,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function getUnstakeLstCollateralApproximateInputs(
|
|
126
|
+
market: KaminoMarket,
|
|
127
|
+
debtReserve: KaminoReserve,
|
|
128
|
+
lstReserve: KaminoReserve,
|
|
129
|
+
obligation: KaminoObligation,
|
|
130
|
+
currentSlot: Slot
|
|
131
|
+
): {
|
|
132
|
+
lstToConvert: Decimal;
|
|
133
|
+
} {
|
|
134
|
+
// Compute the interest rate / curve after 4 days (~2 epochs)
|
|
135
|
+
const laterSlot = currentSlot + BigInt(SLOTS_PER_DAY * 4);
|
|
136
|
+
const borrow = obligation.state.borrows.find(
|
|
137
|
+
(borrow) => borrow.borrowReserve.toString() === debtReserve.address.toString()
|
|
138
|
+
);
|
|
139
|
+
const lstDeposit = obligation.state.deposits.find(
|
|
140
|
+
(deposit) => deposit.depositReserve.toString() === lstReserve.address.toString()
|
|
141
|
+
);
|
|
142
|
+
if (!borrow) {
|
|
143
|
+
throw new Error(
|
|
144
|
+
`Could not find borrow ${debtReserve.address.toString()} in obligation ${obligation.obligationAddress.toString()}`
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
if (!lstDeposit) {
|
|
148
|
+
throw new Error(
|
|
149
|
+
`Could not find deposit ${lstReserve.address.toString()} in obligation ${obligation.obligationAddress.toString()}`
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
const newInterestRate = obligation.estimateObligationInterestRate(market, debtReserve, borrow, laterSlot);
|
|
153
|
+
const debtToRepay = new Fraction(borrow.borrowedAmountSf).toDecimal().mul(newInterestRate);
|
|
154
|
+
|
|
155
|
+
// To compute the staked sol to convert we convert the sol to repay
|
|
156
|
+
// using the pool ratio, but we cap it at the total amount of deposited
|
|
157
|
+
// staked sol in the obligation (converted from collateral -> liquidity)
|
|
158
|
+
const lstPrice = lstReserve.getOracleMarketPrice();
|
|
159
|
+
const debtPrice = debtReserve.getOracleMarketPrice();
|
|
160
|
+
const equivalentLst = debtToRepay.mul(debtPrice).div(lstPrice);
|
|
161
|
+
const equivalentLstWithMargin = equivalentLst.mul(FULL_BPS.add(LST_CONVERSION_MARGIN_BPS)).div(FULL_BPS);
|
|
162
|
+
|
|
163
|
+
const newCollateralExchangeRate = debtReserve.getEstimatedCollateralExchangeRate(
|
|
164
|
+
laterSlot,
|
|
165
|
+
market.state.referralFeeBps
|
|
166
|
+
);
|
|
167
|
+
const lstCollateralAmount = new Decimal(equivalentLstWithMargin.toString()).mul(newCollateralExchangeRate);
|
|
168
|
+
const lstCollateralToConvert = Decimal.min(new Decimal(lstDeposit.depositedAmount.toString()), lstCollateralAmount);
|
|
169
|
+
|
|
170
|
+
const lstToConvert = lstCollateralToConvert.div(newCollateralExchangeRate).ceil();
|
|
171
|
+
return {
|
|
172
|
+
lstToConvert,
|
|
173
|
+
};
|
|
174
|
+
}
|
package/src/leverage/calcs.ts
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import { Address, Slot } from '@solana/kit';
|
|
2
2
|
import Decimal from 'decimal.js';
|
|
3
|
-
import { collToLamportsDecimal, Kamino, StrategyWithAddress, TokenAmounts } from '@kamino-finance/kliquidity-sdk';
|
|
4
3
|
import { KaminoMarket, KaminoObligation, KaminoReserve, toJson } from '../classes';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
AdjustLeverageCalcsResult,
|
|
8
|
-
DepositLeverageCalcsResult,
|
|
9
|
-
PriceAinBProvider,
|
|
10
|
-
WithdrawLeverageCalcsResult,
|
|
11
|
-
} from './types';
|
|
4
|
+
import { AdjustLeverageCalcsResult, DepositLeverageCalcsResult, WithdrawLeverageCalcsResult } from './types';
|
|
12
5
|
import { fuzzyEqual } from '../utils';
|
|
13
6
|
|
|
14
7
|
const closingPositionDiffTolerance = 0.0001;
|
|
@@ -404,73 +397,6 @@ export const estimateDepositMode = ({
|
|
|
404
397
|
};
|
|
405
398
|
};
|
|
406
399
|
|
|
407
|
-
/**
|
|
408
|
-
* Given an amount of ktokens, returns the estimated amount of token A and token B that need to be deposited
|
|
409
|
-
* The amount of A and B may result in less ktokens being minted, the actual amount of ktokens minted is returned as well
|
|
410
|
-
* @param kamino
|
|
411
|
-
* @param strategy
|
|
412
|
-
* @param mintAmount - desired amount of ktokens to mint
|
|
413
|
-
* @param strategyHoldings - optional strategy holdings, if not provided will be fetched from the blockchain
|
|
414
|
-
* @returns [tokenA, tokenB, actualMintAmount]
|
|
415
|
-
*/
|
|
416
|
-
export async function simulateMintKToken(
|
|
417
|
-
kamino: Kamino,
|
|
418
|
-
strategy: StrategyWithAddress,
|
|
419
|
-
mintAmount: Decimal,
|
|
420
|
-
strategyHoldings?: TokenAmounts
|
|
421
|
-
): Promise<[Decimal, Decimal, Decimal]> {
|
|
422
|
-
let holdings = strategyHoldings;
|
|
423
|
-
if (!holdings) {
|
|
424
|
-
holdings = await kamino.getStrategyTokensHoldings(strategy, 'DEPOSIT');
|
|
425
|
-
}
|
|
426
|
-
const sharesIssuedDecimal = new Decimal(strategy.strategy.sharesIssued.toString()).div(
|
|
427
|
-
10 ** strategy.strategy.sharesMintDecimals.toNumber()
|
|
428
|
-
);
|
|
429
|
-
|
|
430
|
-
// Add 1 because the sdk doesn't round up where the SC will
|
|
431
|
-
const strategyA = holdings.a.div(10 ** strategy.strategy.tokenAMintDecimals.toNumber());
|
|
432
|
-
const strategyB = holdings.b.div(10 ** strategy.strategy.tokenBMintDecimals.toNumber());
|
|
433
|
-
const aPerShare = strategyA.div(sharesIssuedDecimal);
|
|
434
|
-
const bPerShare = strategyB.div(sharesIssuedDecimal);
|
|
435
|
-
|
|
436
|
-
const requiredA = aPerShare.mul(mintAmount);
|
|
437
|
-
const requiredB = bPerShare.mul(mintAmount);
|
|
438
|
-
const pxAInB = strategyB.div(strategyA);
|
|
439
|
-
|
|
440
|
-
console.info(
|
|
441
|
-
`Estimating kToken mint of ${mintAmount} ktokens on strategy ${strategy.address.toString()} requires: estimated A: ${requiredA}, estimated B: ${requiredB}. Current pool state:\n${toJson(
|
|
442
|
-
{ ...holdings, sharesIssued: sharesIssuedDecimal, poolPxAInB: pxAInB }
|
|
443
|
-
)}`
|
|
444
|
-
);
|
|
445
|
-
|
|
446
|
-
// If we deposited with this exact ratio - how many ktokens do we actually get from the program?
|
|
447
|
-
const RustDecimal = Decimal.clone({ precision: 18, rounding: Decimal.ROUND_FLOOR });
|
|
448
|
-
|
|
449
|
-
const usA = new RustDecimal(holdings.a);
|
|
450
|
-
const usB = new RustDecimal(holdings.b);
|
|
451
|
-
const uA = new RustDecimal(requiredA.mul(10 ** strategy.strategy.tokenAMintDecimals.toNumber()).ceil());
|
|
452
|
-
const uB = new RustDecimal(requiredB.mul(10 ** strategy.strategy.tokenBMintDecimals.toNumber()).ceil());
|
|
453
|
-
|
|
454
|
-
const ratio = usA.div(usB);
|
|
455
|
-
const depositableB = uA.div(ratio).floor();
|
|
456
|
-
let actualA, actualB;
|
|
457
|
-
if (depositableB.lte(uB)) {
|
|
458
|
-
actualA = depositableB.mul(ratio).floor();
|
|
459
|
-
actualB = uB;
|
|
460
|
-
} else {
|
|
461
|
-
actualA = uB.mul(ratio).floor();
|
|
462
|
-
actualB = actualA.div(ratio).floor();
|
|
463
|
-
}
|
|
464
|
-
const actualMintFromA = actualA.mul(strategy.strategy.sharesIssued.toString()).div(holdings.a).floor();
|
|
465
|
-
const actualMintFromB = actualB.mul(strategy.strategy.sharesIssued.toString()).div(holdings.b).floor();
|
|
466
|
-
const actualMint = Decimal.min(actualMintFromA, actualMintFromB).div(
|
|
467
|
-
10 ** strategy.strategy.sharesMintDecimals.toNumber()
|
|
468
|
-
);
|
|
469
|
-
console.log(`Actual deposit amounts: A: ${actualA}, B: ${actualB}, kTokens to mint: ${actualMint}`);
|
|
470
|
-
|
|
471
|
-
return [requiredA, requiredB, actualMint];
|
|
472
|
-
}
|
|
473
|
-
|
|
474
400
|
export const depositLeverageCalcs = (props: {
|
|
475
401
|
depositAmount: Decimal;
|
|
476
402
|
depositTokenIsCollToken: boolean;
|
|
@@ -509,9 +435,6 @@ export const depositLeverageCalcs = (props: {
|
|
|
509
435
|
collTokenToDeposit: finalColl,
|
|
510
436
|
swapDebtTokenIn: debt,
|
|
511
437
|
swapCollTokenExpectedOut: finalColl.sub(depositAmount),
|
|
512
|
-
flashBorrowInDebtTokenKtokenOnly: new Decimal(0),
|
|
513
|
-
singleSidedDepositKtokenOnly: new Decimal(0),
|
|
514
|
-
requiredCollateralKtokenOnly: new Decimal(0),
|
|
515
438
|
};
|
|
516
439
|
} else {
|
|
517
440
|
const y = targetLeverage.mul(priceDebtToColl);
|
|
@@ -527,113 +450,6 @@ export const depositLeverageCalcs = (props: {
|
|
|
527
450
|
collTokenToDeposit: finalColl,
|
|
528
451
|
swapDebtTokenIn: debt.add(depositAmount),
|
|
529
452
|
swapCollTokenExpectedOut: finalColl,
|
|
530
|
-
flashBorrowInDebtTokenKtokenOnly: new Decimal(0),
|
|
531
|
-
singleSidedDepositKtokenOnly: new Decimal(0),
|
|
532
|
-
requiredCollateralKtokenOnly: new Decimal(0),
|
|
533
|
-
};
|
|
534
|
-
}
|
|
535
|
-
};
|
|
536
|
-
|
|
537
|
-
export const depositLeverageKtokenCalcs = async (props: {
|
|
538
|
-
kamino: Kamino;
|
|
539
|
-
strategy: StrategyWithAddress;
|
|
540
|
-
debtTokenMint: Address;
|
|
541
|
-
depositAmount: Decimal;
|
|
542
|
-
depositTokenIsCollToken: boolean;
|
|
543
|
-
depositTokenIsSol: boolean;
|
|
544
|
-
priceDebtToColl: Decimal;
|
|
545
|
-
targetLeverage: Decimal;
|
|
546
|
-
slippagePct: Decimal;
|
|
547
|
-
flashLoanFee: Decimal;
|
|
548
|
-
priceAinB: PriceAinBProvider;
|
|
549
|
-
strategyHoldings?: TokenAmounts;
|
|
550
|
-
}): Promise<DepositLeverageCalcsResult> => {
|
|
551
|
-
const {
|
|
552
|
-
kamino,
|
|
553
|
-
strategy,
|
|
554
|
-
debtTokenMint,
|
|
555
|
-
depositAmount,
|
|
556
|
-
depositTokenIsCollToken,
|
|
557
|
-
depositTokenIsSol,
|
|
558
|
-
priceDebtToColl,
|
|
559
|
-
targetLeverage,
|
|
560
|
-
slippagePct,
|
|
561
|
-
flashLoanFee,
|
|
562
|
-
priceAinB,
|
|
563
|
-
strategyHoldings,
|
|
564
|
-
} = props;
|
|
565
|
-
const initDepositInSol = depositTokenIsSol ? depositAmount : new Decimal(0);
|
|
566
|
-
const slippage = slippagePct.div('100');
|
|
567
|
-
|
|
568
|
-
let flashBorrowInDebtToken: Decimal;
|
|
569
|
-
let collTokenToDeposit: Decimal;
|
|
570
|
-
let debtTokenToBorrow: Decimal;
|
|
571
|
-
|
|
572
|
-
if (depositTokenIsCollToken) {
|
|
573
|
-
const x = slippage.add('1').div(priceDebtToColl);
|
|
574
|
-
const y = flashLoanFee.add('1').mul(priceDebtToColl);
|
|
575
|
-
const z = targetLeverage.mul(y).div(targetLeverage.sub(1));
|
|
576
|
-
flashBorrowInDebtToken = depositAmount.div(z.minus(new Decimal(1).div(x)));
|
|
577
|
-
collTokenToDeposit = depositAmount.add(flashBorrowInDebtToken.div(x));
|
|
578
|
-
debtTokenToBorrow = flashBorrowInDebtToken.mul(new Decimal(1).add(flashLoanFee));
|
|
579
|
-
|
|
580
|
-
return {
|
|
581
|
-
flashBorrowInCollToken: new Decimal(0),
|
|
582
|
-
initDepositInSol,
|
|
583
|
-
collTokenToDeposit,
|
|
584
|
-
debtTokenToBorrow,
|
|
585
|
-
swapDebtTokenIn: new Decimal(0),
|
|
586
|
-
swapCollTokenExpectedOut: new Decimal(0),
|
|
587
|
-
flashBorrowInDebtTokenKtokenOnly: flashBorrowInDebtToken,
|
|
588
|
-
requiredCollateralKtokenOnly: collTokenToDeposit.sub(depositAmount), // Assuming netValue is requiredCollateral, adjust as needed
|
|
589
|
-
singleSidedDepositKtokenOnly: flashBorrowInDebtToken,
|
|
590
|
-
};
|
|
591
|
-
} else {
|
|
592
|
-
const y = targetLeverage.mul(priceDebtToColl);
|
|
593
|
-
// although we will only swap ~half of the debt token, we account for the slippage on the entire amount as we are working backwards from the minimum collateral and do not know the exact swap proportion in advance
|
|
594
|
-
// This also allows for some variation in the pool ratios between calculation + submitting the tx
|
|
595
|
-
const x = flashLoanFee.add('1').mul(slippage.add('1')).div(priceDebtToColl);
|
|
596
|
-
// Calculate the amount of collateral tokens we will deposit in order to achieve the desired leverage after swapping a portion of the debt token and flash loan fees
|
|
597
|
-
const finalColl = depositAmount.div(x.sub(targetLeverage.sub('1').div(y)));
|
|
598
|
-
// Calculate how many A and B tokens we will need to actually mint the desired amount of ktoken collateral
|
|
599
|
-
// The actual amount of ktokens received may be less than the finalColl due to smart proportional contract logic
|
|
600
|
-
// So we use the actualColl as the amount we will deposit
|
|
601
|
-
const [estimatedA, estimatedB, actualColl] = await simulateMintKToken(
|
|
602
|
-
kamino!,
|
|
603
|
-
strategy,
|
|
604
|
-
finalColl,
|
|
605
|
-
strategyHoldings
|
|
606
|
-
);
|
|
607
|
-
const { tokenAMint, tokenBMint } = strategy.strategy;
|
|
608
|
-
const pxAinB = await priceAinB(tokenAMint, tokenBMint);
|
|
609
|
-
const isTokenADeposit = tokenAMint === debtTokenMint;
|
|
610
|
-
// Calculate the amount we need to flash borrow by combining value of A and B into the debt token
|
|
611
|
-
const singleSidedDepositAmount = isTokenADeposit
|
|
612
|
-
? estimatedA.add(estimatedB.div(pxAinB))
|
|
613
|
-
: estimatedB.add(estimatedA.mul(pxAinB));
|
|
614
|
-
|
|
615
|
-
// Add slippage to the entire amount, add flash loan fee to part we will flash borrow
|
|
616
|
-
flashBorrowInDebtToken = singleSidedDepositAmount
|
|
617
|
-
.div(new Decimal('1').sub(slippage))
|
|
618
|
-
.sub(depositAmount)
|
|
619
|
-
.div(new Decimal('1').sub(flashLoanFee));
|
|
620
|
-
// Deposit the min ktoken amount we calculated at the beginning
|
|
621
|
-
// Any slippage will be left in the user's wallet as ktokens
|
|
622
|
-
collTokenToDeposit = actualColl;
|
|
623
|
-
debtTokenToBorrow = flashBorrowInDebtToken.div(new Decimal('1').sub(flashLoanFee));
|
|
624
|
-
// Add slippage to ensure we try to swap/deposit as much as possible after flash loan fees
|
|
625
|
-
const singleSidedDeposit = singleSidedDepositAmount.div(new Decimal('1').sub(slippage));
|
|
626
|
-
|
|
627
|
-
return {
|
|
628
|
-
flashBorrowInCollToken: new Decimal(0),
|
|
629
|
-
initDepositInSol,
|
|
630
|
-
collTokenToDeposit,
|
|
631
|
-
debtTokenToBorrow,
|
|
632
|
-
swapDebtTokenIn: new Decimal(0),
|
|
633
|
-
swapCollTokenExpectedOut: new Decimal(0),
|
|
634
|
-
flashBorrowInDebtTokenKtokenOnly: flashBorrowInDebtToken,
|
|
635
|
-
singleSidedDepositKtokenOnly: singleSidedDeposit,
|
|
636
|
-
requiredCollateralKtokenOnly: collTokenToDeposit, // Assuming collTokenToDeposit is requiredCollateral, adjust as needed
|
|
637
453
|
};
|
|
638
454
|
}
|
|
639
455
|
};
|
|
@@ -710,17 +526,13 @@ export function withdrawLeverageCalcs(
|
|
|
710
526
|
}
|
|
711
527
|
|
|
712
528
|
export async function adjustDepositLeverageCalcs(
|
|
713
|
-
market: KaminoMarket,
|
|
714
|
-
owner: Address,
|
|
715
529
|
debtReserve: KaminoReserve,
|
|
716
530
|
adjustDepositPosition: Decimal,
|
|
717
531
|
adjustBorrowPosition: Decimal,
|
|
718
532
|
priceDebtToColl: Decimal,
|
|
719
533
|
flashLoanFee: Decimal,
|
|
720
|
-
slippagePct: Decimal
|
|
721
|
-
collIsKtoken: boolean
|
|
534
|
+
slippagePct: Decimal
|
|
722
535
|
): Promise<AdjustLeverageCalcsResult> {
|
|
723
|
-
// used if coll is Ktoken and we borrow debt token instead
|
|
724
536
|
const amountToFlashBorrowDebt = adjustDepositPosition
|
|
725
537
|
.div(priceDebtToColl)
|
|
726
538
|
.mul(new Decimal(new Decimal(1).add(slippagePct.div(100))))
|
|
@@ -731,20 +543,11 @@ export async function adjustDepositLeverageCalcs(
|
|
|
731
543
|
.mul(new Decimal(new Decimal(1).add(slippagePct.div(100))))
|
|
732
544
|
.div(priceDebtToColl);
|
|
733
545
|
|
|
734
|
-
const expectedDebtTokenAtaBalance = await getExpectedTokenBalanceAfterBorrow(
|
|
735
|
-
market.getRpc(),
|
|
736
|
-
debtReserve.getLiquidityMint(),
|
|
737
|
-
owner,
|
|
738
|
-
collToLamportsDecimal(!collIsKtoken ? borrowAmount : amountToFlashBorrowDebt, debtReserve!.stats.decimals).floor(),
|
|
739
|
-
debtReserve!.state.liquidity.mintDecimals.toNumber()
|
|
740
|
-
);
|
|
741
|
-
|
|
742
546
|
return {
|
|
743
547
|
adjustDepositPosition,
|
|
744
548
|
adjustBorrowPosition,
|
|
745
549
|
amountToFlashBorrowDebt,
|
|
746
550
|
borrowAmount,
|
|
747
|
-
expectedDebtTokenAtaBalance,
|
|
748
551
|
withdrawAmountWithSlippageAndFlashLoanFee: new Decimal(0),
|
|
749
552
|
};
|
|
750
553
|
}
|
|
@@ -755,7 +558,6 @@ export function adjustWithdrawLeverageCalcs(
|
|
|
755
558
|
flashLoanFee: Decimal,
|
|
756
559
|
slippagePct: Decimal
|
|
757
560
|
): AdjustLeverageCalcsResult {
|
|
758
|
-
// used if coll is Ktoken and we borrow debt token instead
|
|
759
561
|
const withdrawAmountWithSlippageAndFlashLoanFee = Decimal.abs(adjustDepositPosition)
|
|
760
562
|
.mul(new Decimal(1).plus(flashLoanFee))
|
|
761
563
|
.mul(new Decimal(1).add(slippagePct.div(100)));
|
|
@@ -765,7 +567,6 @@ export function adjustWithdrawLeverageCalcs(
|
|
|
765
567
|
adjustBorrowPosition,
|
|
766
568
|
amountToFlashBorrowDebt: new Decimal(0),
|
|
767
569
|
borrowAmount: new Decimal(0),
|
|
768
|
-
expectedDebtTokenAtaBalance: new Decimal(0),
|
|
769
570
|
withdrawAmountWithSlippageAndFlashLoanFee,
|
|
770
571
|
};
|
|
771
572
|
}
|