@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
|
@@ -28,18 +28,14 @@ import {
|
|
|
28
28
|
removeBudgetIxs,
|
|
29
29
|
uniqueAccountsWithProgramIds,
|
|
30
30
|
WRAPPED_SOL_MINT,
|
|
31
|
-
DEFAULT_PUBLIC_KEY,
|
|
32
31
|
} from '../utils';
|
|
33
32
|
import {
|
|
34
33
|
adjustDepositLeverageCalcs,
|
|
35
34
|
adjustWithdrawLeverageCalcs,
|
|
36
35
|
calcAdjustAmounts,
|
|
37
36
|
depositLeverageCalcs,
|
|
38
|
-
depositLeverageKtokenCalcs,
|
|
39
37
|
withdrawLeverageCalcs,
|
|
40
38
|
} from './calcs';
|
|
41
|
-
import { Kamino, StrategyWithAddress } from '@kamino-finance/kliquidity-sdk';
|
|
42
|
-
import { getExpectedTokenBalanceAfterBorrow, getKtokenToTokenSwapper, getTokenToKtokenSwapper } from './utils';
|
|
43
39
|
import { FullBPS } from '@kamino-finance/kliquidity-sdk/dist/utils/CreationParameters';
|
|
44
40
|
import {
|
|
45
41
|
AdjustLeverageCalcsResult,
|
|
@@ -52,7 +48,6 @@ import {
|
|
|
52
48
|
DepositWithLeverageProps,
|
|
53
49
|
DepositWithLeverageSwapInputsProps,
|
|
54
50
|
DepositLeverageIxsResponse,
|
|
55
|
-
PriceAinBProvider,
|
|
56
51
|
SwapInputs,
|
|
57
52
|
SwapIxs,
|
|
58
53
|
SwapIxsProvider,
|
|
@@ -67,7 +62,6 @@ import {
|
|
|
67
62
|
import { TOKEN_PROGRAM_ADDRESS } from '@solana-program/token';
|
|
68
63
|
import { findAssociatedTokenPda, getCloseAccountInstruction } from '@solana-program/token-2022';
|
|
69
64
|
import { LAMPORTS_PER_SOL } from '../utils/consts';
|
|
70
|
-
import { fetchAddressLookupTable } from '@solana-program/address-lookup-table';
|
|
71
65
|
|
|
72
66
|
export const WITHDRAW_SLOT_OFFSET = 150; // Offset for the withdraw slot to underestimate the exchange rate
|
|
73
67
|
|
|
@@ -84,13 +78,10 @@ export async function getDepositWithLeverageSwapInputs<QuoteResponse>({
|
|
|
84
78
|
currentSlot,
|
|
85
79
|
targetLeverage,
|
|
86
80
|
selectedTokenMint,
|
|
87
|
-
kamino,
|
|
88
81
|
obligationTypeTagOverride,
|
|
89
82
|
scopeRefreshConfig,
|
|
90
83
|
budgetAndPriorityFeeIxs,
|
|
91
84
|
quoteBufferBps,
|
|
92
|
-
priceAinB,
|
|
93
|
-
isKtoken,
|
|
94
85
|
quoter,
|
|
95
86
|
useV2Ixs,
|
|
96
87
|
elevationGroupOverride,
|
|
@@ -107,24 +98,15 @@ export async function getDepositWithLeverageSwapInputs<QuoteResponse>({
|
|
|
107
98
|
const selectedTokenIsCollToken = selectedTokenMint === collTokenMint;
|
|
108
99
|
const depositTokenIsSol = !solTokenReserve ? false : selectedTokenMint === solTokenReserve!.getLiquidityMint();
|
|
109
100
|
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const calcs = await getDepositWithLeverageCalcs(
|
|
114
|
-
depositAmount,
|
|
115
|
-
selectedTokenIsCollToken,
|
|
116
|
-
collIsKtoken,
|
|
101
|
+
const calcs = depositLeverageCalcs({
|
|
102
|
+
depositAmount: depositAmount,
|
|
103
|
+
depositTokenIsCollToken: selectedTokenIsCollToken,
|
|
117
104
|
depositTokenIsSol,
|
|
118
105
|
priceDebtToColl,
|
|
119
106
|
targetLeverage,
|
|
120
107
|
slippagePct,
|
|
121
108
|
flashLoanFee,
|
|
122
|
-
|
|
123
|
-
strategy,
|
|
124
|
-
debtTokenMint,
|
|
125
|
-
priceAinB,
|
|
126
|
-
debtReserve!
|
|
127
|
-
);
|
|
109
|
+
});
|
|
128
110
|
|
|
129
111
|
console.log('Ops Calcs', toJson(calcs));
|
|
130
112
|
|
|
@@ -155,8 +137,6 @@ export async function getDepositWithLeverageSwapInputs<QuoteResponse>({
|
|
|
155
137
|
},
|
|
156
138
|
},
|
|
157
139
|
],
|
|
158
|
-
strategy,
|
|
159
|
-
collIsKtoken,
|
|
160
140
|
useV2Ixs,
|
|
161
141
|
elevationGroupOverride
|
|
162
142
|
)
|
|
@@ -164,143 +144,46 @@ export async function getDepositWithLeverageSwapInputs<QuoteResponse>({
|
|
|
164
144
|
|
|
165
145
|
const uniqueKlendAccounts = uniqueAccountsWithProgramIds(klendIxs.instructions);
|
|
166
146
|
|
|
167
|
-
const swapInputAmount = toLamports(
|
|
168
|
-
!collIsKtoken ? calcs.swapDebtTokenIn : calcs.singleSidedDepositKtokenOnly,
|
|
169
|
-
debtReserve.stats.decimals
|
|
170
|
-
).ceil();
|
|
147
|
+
const swapInputAmount = toLamports(calcs.swapDebtTokenIn, debtReserve.stats.decimals).ceil();
|
|
171
148
|
|
|
172
149
|
const swapInputsForQuote: SwapInputs = {
|
|
173
150
|
inputAmountLamports: swapInputAmount.mul(new Decimal(1).add(quoteBufferBps.div(FullBPS))),
|
|
174
151
|
inputMint: debtTokenMint,
|
|
175
152
|
outputMint: collTokenMint,
|
|
176
|
-
amountDebtAtaBalance: new Decimal(0), // Only needed for ktokens swaps
|
|
177
153
|
};
|
|
178
154
|
|
|
179
155
|
const swapQuote = await quoter(swapInputsForQuote, uniqueKlendAccounts);
|
|
180
156
|
|
|
181
|
-
const quotePriceCalcs =
|
|
182
|
-
depositAmount,
|
|
183
|
-
selectedTokenIsCollToken,
|
|
184
|
-
collIsKtoken,
|
|
157
|
+
const quotePriceCalcs = depositLeverageCalcs({
|
|
158
|
+
depositAmount: depositAmount,
|
|
159
|
+
depositTokenIsCollToken: selectedTokenIsCollToken,
|
|
185
160
|
depositTokenIsSol,
|
|
186
|
-
swapQuote.priceAInB,
|
|
161
|
+
priceDebtToColl: swapQuote.priceAInB,
|
|
187
162
|
targetLeverage,
|
|
188
163
|
slippagePct,
|
|
189
164
|
flashLoanFee,
|
|
190
|
-
|
|
191
|
-
strategy,
|
|
192
|
-
debtTokenMint,
|
|
193
|
-
priceAinB,
|
|
194
|
-
debtReserve!
|
|
195
|
-
);
|
|
196
|
-
|
|
197
|
-
const swapInputAmountQuotePrice = toLamports(
|
|
198
|
-
!collIsKtoken ? quotePriceCalcs.swapDebtTokenIn : quotePriceCalcs.singleSidedDepositKtokenOnly,
|
|
199
|
-
debtReserve.stats.decimals
|
|
200
|
-
).ceil();
|
|
201
|
-
|
|
202
|
-
let expectedDebtTokenAtaBalance = new Decimal(0);
|
|
165
|
+
});
|
|
203
166
|
|
|
204
|
-
|
|
205
|
-
let futureBalanceInAta = new Decimal(0);
|
|
206
|
-
if (debtTokenMint === WRAPPED_SOL_MINT) {
|
|
207
|
-
futureBalanceInAta = futureBalanceInAta.add(
|
|
208
|
-
!collIsKtoken ? quotePriceCalcs.initDepositInSol : quotePriceCalcs.initDepositInSol
|
|
209
|
-
);
|
|
210
|
-
}
|
|
211
|
-
futureBalanceInAta = futureBalanceInAta.add(
|
|
212
|
-
!collIsKtoken ? quotePriceCalcs.debtTokenToBorrow : quotePriceCalcs.flashBorrowInDebtTokenKtokenOnly
|
|
213
|
-
);
|
|
214
|
-
expectedDebtTokenAtaBalance = await getExpectedTokenBalanceAfterBorrow(
|
|
215
|
-
kaminoMarket.getRpc(),
|
|
216
|
-
debtTokenMint,
|
|
217
|
-
owner.address,
|
|
218
|
-
toLamports(futureBalanceInAta.toDecimalPlaces(debtReserve.stats.decimals), debtReserve.stats.decimals),
|
|
219
|
-
debtReserve.state.liquidity.mintDecimals.toNumber()
|
|
220
|
-
);
|
|
221
|
-
}
|
|
167
|
+
const swapInputAmountQuotePrice = toLamports(quotePriceCalcs.swapDebtTokenIn, debtReserve.stats.decimals).ceil();
|
|
222
168
|
|
|
223
169
|
return {
|
|
224
170
|
swapInputs: {
|
|
225
171
|
inputAmountLamports: swapInputAmountQuotePrice,
|
|
226
|
-
minOutAmountLamports: toLamports(
|
|
227
|
-
!collIsKtoken ? quotePriceCalcs.flashBorrowInCollToken : quotePriceCalcs.flashBorrowInDebtTokenKtokenOnly,
|
|
228
|
-
!collIsKtoken ? collReserve.stats.decimals : debtReserve.stats.decimals
|
|
229
|
-
),
|
|
172
|
+
minOutAmountLamports: toLamports(quotePriceCalcs.flashBorrowInCollToken, collReserve.stats.decimals),
|
|
230
173
|
inputMint: debtTokenMint,
|
|
231
174
|
outputMint: collTokenMint,
|
|
232
|
-
amountDebtAtaBalance: expectedDebtTokenAtaBalance,
|
|
233
175
|
},
|
|
234
176
|
flashLoanInfo: klendIxs.flashLoanInfo,
|
|
235
177
|
initialInputs: {
|
|
236
178
|
calcs: quotePriceCalcs,
|
|
237
179
|
swapQuote,
|
|
238
180
|
currentSlot,
|
|
239
|
-
collIsKtoken,
|
|
240
|
-
strategy,
|
|
241
181
|
obligation: obligation ? obligation : obligationType,
|
|
242
182
|
klendAccounts: uniqueKlendAccounts,
|
|
243
183
|
},
|
|
244
184
|
};
|
|
245
185
|
}
|
|
246
186
|
|
|
247
|
-
async function getDepositWithLeverageCalcs(
|
|
248
|
-
depositAmount: Decimal,
|
|
249
|
-
selectedTokenIsCollToken: boolean,
|
|
250
|
-
collIsKtoken: boolean,
|
|
251
|
-
depositTokenIsSol: boolean,
|
|
252
|
-
priceDebtToColl: Decimal,
|
|
253
|
-
targetLeverage: Decimal,
|
|
254
|
-
slippagePct: Decimal,
|
|
255
|
-
flashLoanFee: Decimal,
|
|
256
|
-
kamino: Kamino | undefined,
|
|
257
|
-
strategy: StrategyWithAddress | undefined,
|
|
258
|
-
debtTokenMint: Address,
|
|
259
|
-
priceAinB: PriceAinBProvider,
|
|
260
|
-
debtReserve: KaminoReserve
|
|
261
|
-
): Promise<DepositLeverageCalcsResult> {
|
|
262
|
-
let calcs: DepositLeverageCalcsResult;
|
|
263
|
-
if (!collIsKtoken) {
|
|
264
|
-
calcs = depositLeverageCalcs({
|
|
265
|
-
depositAmount: depositAmount,
|
|
266
|
-
depositTokenIsCollToken: selectedTokenIsCollToken,
|
|
267
|
-
depositTokenIsSol,
|
|
268
|
-
priceDebtToColl,
|
|
269
|
-
targetLeverage,
|
|
270
|
-
slippagePct,
|
|
271
|
-
flashLoanFee,
|
|
272
|
-
});
|
|
273
|
-
} else {
|
|
274
|
-
calcs = await depositLeverageKtokenCalcs({
|
|
275
|
-
kamino: kamino!,
|
|
276
|
-
strategy: strategy!,
|
|
277
|
-
debtTokenMint,
|
|
278
|
-
depositAmount: depositAmount,
|
|
279
|
-
depositTokenIsCollToken: selectedTokenIsCollToken,
|
|
280
|
-
depositTokenIsSol,
|
|
281
|
-
priceDebtToColl,
|
|
282
|
-
targetLeverage,
|
|
283
|
-
slippagePct,
|
|
284
|
-
flashLoanFee,
|
|
285
|
-
priceAinB,
|
|
286
|
-
});
|
|
287
|
-
// Rounding to exact number of decimals so this value is passed through in all calcs without rounding inconsistencies
|
|
288
|
-
calcs.flashBorrowInDebtTokenKtokenOnly = calcs.flashBorrowInDebtTokenKtokenOnly.toDecimalPlaces(
|
|
289
|
-
debtReserve!.state.liquidity.mintDecimals.toNumber()!,
|
|
290
|
-
Decimal.ROUND_CEIL
|
|
291
|
-
);
|
|
292
|
-
calcs.debtTokenToBorrow = calcs.debtTokenToBorrow.toDecimalPlaces(
|
|
293
|
-
debtReserve!.state.liquidity.mintDecimals.toNumber()!,
|
|
294
|
-
Decimal.ROUND_CEIL
|
|
295
|
-
);
|
|
296
|
-
calcs.singleSidedDepositKtokenOnly = calcs.singleSidedDepositKtokenOnly.toDecimalPlaces(
|
|
297
|
-
debtReserve!.state.liquidity.mintDecimals.toNumber()!,
|
|
298
|
-
Decimal.ROUND_CEIL
|
|
299
|
-
);
|
|
300
|
-
}
|
|
301
|
-
return calcs;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
187
|
export async function getDepositWithLeverageIxs<QuoteResponse>({
|
|
305
188
|
owner,
|
|
306
189
|
kaminoMarket,
|
|
@@ -314,13 +197,10 @@ export async function getDepositWithLeverageIxs<QuoteResponse>({
|
|
|
314
197
|
currentSlot,
|
|
315
198
|
targetLeverage,
|
|
316
199
|
selectedTokenMint,
|
|
317
|
-
kamino,
|
|
318
200
|
obligationTypeTagOverride,
|
|
319
201
|
scopeRefreshConfig,
|
|
320
202
|
budgetAndPriorityFeeIxs,
|
|
321
203
|
quoteBufferBps,
|
|
322
|
-
priceAinB,
|
|
323
|
-
isKtoken,
|
|
324
204
|
quoter,
|
|
325
205
|
swapper,
|
|
326
206
|
elevationGroupOverride,
|
|
@@ -339,43 +219,19 @@ export async function getDepositWithLeverageIxs<QuoteResponse>({
|
|
|
339
219
|
currentSlot,
|
|
340
220
|
targetLeverage,
|
|
341
221
|
selectedTokenMint,
|
|
342
|
-
kamino,
|
|
343
222
|
obligationTypeTagOverride,
|
|
344
223
|
scopeRefreshConfig,
|
|
345
224
|
budgetAndPriorityFeeIxs,
|
|
346
225
|
quoteBufferBps,
|
|
347
|
-
priceAinB,
|
|
348
|
-
isKtoken,
|
|
349
226
|
quoter,
|
|
350
227
|
useV2Ixs,
|
|
351
228
|
});
|
|
352
229
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
if (!initialInputs.collIsKtoken) {
|
|
356
|
-
depositSwapper = swapper;
|
|
357
|
-
} else {
|
|
358
|
-
if (kamino === undefined) {
|
|
359
|
-
throw Error('Ktoken use as collateral for leverage without Kamino instance');
|
|
360
|
-
}
|
|
361
|
-
depositSwapper = await getTokenToKtokenSwapper(kaminoMarket, kamino, owner, slippagePct, swapper, priceAinB, false);
|
|
362
|
-
}
|
|
230
|
+
const depositSwapper: SwapIxsProvider<QuoteResponse> = swapper;
|
|
363
231
|
|
|
364
232
|
const swapsArray = await depositSwapper(swapInputs, initialInputs.klendAccounts, initialInputs.swapQuote);
|
|
365
233
|
|
|
366
|
-
|
|
367
|
-
if (initialInputs.strategy && initialInputs.strategy.strategy.strategyLookupTable !== DEFAULT_PUBLIC_KEY) {
|
|
368
|
-
const strategyLut = await fetchAddressLookupTable(
|
|
369
|
-
kaminoMarket.getRpc(),
|
|
370
|
-
initialInputs.strategy.strategy.strategyLookupTable
|
|
371
|
-
);
|
|
372
|
-
swapsArray.forEach((swap) => {
|
|
373
|
-
swap.lookupTables.push(strategyLut);
|
|
374
|
-
});
|
|
375
|
-
} else {
|
|
376
|
-
console.log('Strategy lookup table not found');
|
|
377
|
-
}
|
|
378
|
-
}
|
|
234
|
+
// Strategy lookup table logic removed
|
|
379
235
|
|
|
380
236
|
const collReserve = kaminoMarket.getReserveByMint(collTokenMint);
|
|
381
237
|
const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint);
|
|
@@ -402,8 +258,6 @@ export async function getDepositWithLeverageIxs<QuoteResponse>({
|
|
|
402
258
|
quote: swap.quote,
|
|
403
259
|
};
|
|
404
260
|
}),
|
|
405
|
-
initialInputs.strategy,
|
|
406
|
-
initialInputs.collIsKtoken,
|
|
407
261
|
useV2Ixs,
|
|
408
262
|
elevationGroupOverride
|
|
409
263
|
);
|
|
@@ -433,24 +287,17 @@ async function buildDepositWithLeverageIxs<QuoteResponse>(
|
|
|
433
287
|
calcs: DepositLeverageCalcsResult,
|
|
434
288
|
budgetAndPriorityFeeIxs: Instruction[] | undefined,
|
|
435
289
|
swapQuoteIxsArray: SwapIxs<QuoteResponse>[],
|
|
436
|
-
strategy: StrategyWithAddress | undefined,
|
|
437
|
-
collIsKtoken: boolean,
|
|
438
290
|
useV2Ixs: boolean,
|
|
439
291
|
elevationGroupOverride?: number
|
|
440
292
|
): Promise<LeverageIxsOutput[]> {
|
|
441
293
|
const collTokenMint = collReserve.getLiquidityMint();
|
|
442
294
|
const debtTokenMint = debtReserve.getLiquidityMint();
|
|
443
|
-
const [[collTokenAta]
|
|
295
|
+
const [[collTokenAta]] = await Promise.all([
|
|
444
296
|
findAssociatedTokenPda({
|
|
445
297
|
owner: owner.address,
|
|
446
298
|
mint: collTokenMint,
|
|
447
299
|
tokenProgram: collReserve.getLiquidityTokenProgram(),
|
|
448
300
|
}),
|
|
449
|
-
findAssociatedTokenPda({
|
|
450
|
-
owner: owner.address,
|
|
451
|
-
mint: debtTokenMint,
|
|
452
|
-
tokenProgram: debtReserve.getLiquidityTokenProgram(),
|
|
453
|
-
}),
|
|
454
301
|
]);
|
|
455
302
|
|
|
456
303
|
// 1. Create atas & budget ixs
|
|
@@ -460,10 +307,8 @@ async function buildDepositWithLeverageIxs<QuoteResponse>(
|
|
|
460
307
|
obligation,
|
|
461
308
|
collTokenMint,
|
|
462
309
|
collReserve,
|
|
463
|
-
collIsKtoken,
|
|
464
310
|
debtTokenMint,
|
|
465
311
|
debtReserve,
|
|
466
|
-
strategy,
|
|
467
312
|
scopeRefreshConfig,
|
|
468
313
|
budgetAndPriorityFeeIxs
|
|
469
314
|
);
|
|
@@ -487,12 +332,9 @@ async function buildDepositWithLeverageIxs<QuoteResponse>(
|
|
|
487
332
|
userTransferAuthority: owner,
|
|
488
333
|
lendingMarketAuthority: await market.getLendingMarketAuthority(),
|
|
489
334
|
lendingMarketAddress: market.getAddress(),
|
|
490
|
-
reserve:
|
|
491
|
-
amountLamports: toLamports(
|
|
492
|
-
|
|
493
|
-
!collIsKtoken ? collReserve.stats.decimals : debtReserve.stats.decimals
|
|
494
|
-
),
|
|
495
|
-
destinationAta: !collIsKtoken ? collTokenAta : debtTokenAta,
|
|
335
|
+
reserve: collReserve,
|
|
336
|
+
amountLamports: toLamports(calcs.flashBorrowInCollToken, collReserve.stats.decimals),
|
|
337
|
+
destinationAta: collTokenAta,
|
|
496
338
|
// TODO(referrals): once we support referrals, we will have to replace the placeholder args below:
|
|
497
339
|
referrerAccount: none(),
|
|
498
340
|
referrerTokenState: none(),
|
|
@@ -502,13 +344,9 @@ async function buildDepositWithLeverageIxs<QuoteResponse>(
|
|
|
502
344
|
// 3. Deposit initial tokens + borrowed tokens into reserve
|
|
503
345
|
const kaminoDepositAndBorrowAction = await KaminoAction.buildDepositAndBorrowTxns(
|
|
504
346
|
market,
|
|
505
|
-
toLamports(
|
|
506
|
-
.floor()
|
|
507
|
-
.toString(),
|
|
347
|
+
toLamports(calcs.collTokenToDeposit, collReserve.stats.decimals).floor().toString(),
|
|
508
348
|
collTokenMint,
|
|
509
|
-
toLamports(
|
|
510
|
-
.ceil()
|
|
511
|
-
.toString(),
|
|
349
|
+
toLamports(calcs.debtTokenToBorrow, debtReserve.stats.decimals).ceil().toString(),
|
|
512
350
|
debtTokenMint,
|
|
513
351
|
owner,
|
|
514
352
|
obligation!,
|
|
@@ -526,7 +364,7 @@ async function buildDepositWithLeverageIxs<QuoteResponse>(
|
|
|
526
364
|
// 4. Swap
|
|
527
365
|
const { swapIxs } = swapQuoteIxs;
|
|
528
366
|
const swapInstructions = removeBudgetIxs(swapIxs);
|
|
529
|
-
const flashBorrowReserve =
|
|
367
|
+
const flashBorrowReserve = collReserve;
|
|
530
368
|
const flashLoanInfo = {
|
|
531
369
|
flashBorrowReserve: flashBorrowReserve.address,
|
|
532
370
|
flashLoanFee: flashBorrowReserve.getFlashLoanFee(),
|
|
@@ -540,9 +378,8 @@ async function buildDepositWithLeverageIxs<QuoteResponse>(
|
|
|
540
378
|
...createAtasIxs,
|
|
541
379
|
...fillWsolAtaIxs,
|
|
542
380
|
...[flashBorrowIx],
|
|
543
|
-
...(collIsKtoken ? swapInstructions : []),
|
|
544
381
|
...KaminoAction.actionToIxs(kaminoDepositAndBorrowAction),
|
|
545
|
-
...
|
|
382
|
+
...swapInstructions,
|
|
546
383
|
...[flashRepayIx],
|
|
547
384
|
],
|
|
548
385
|
};
|
|
@@ -565,10 +402,8 @@ export async function getWithdrawWithLeverageSwapInputs<QuoteResponse>({
|
|
|
565
402
|
isClosingPosition,
|
|
566
403
|
selectedTokenMint,
|
|
567
404
|
budgetAndPriorityFeeIxs,
|
|
568
|
-
kamino,
|
|
569
405
|
scopeRefreshConfig,
|
|
570
406
|
quoteBufferBps,
|
|
571
|
-
isKtoken,
|
|
572
407
|
quoter,
|
|
573
408
|
useV2Ixs,
|
|
574
409
|
}: WithdrawWithLeverageSwapInputsProps<QuoteResponse>): Promise<{
|
|
@@ -580,8 +415,6 @@ export async function getWithdrawWithLeverageSwapInputs<QuoteResponse>({
|
|
|
580
415
|
const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint);
|
|
581
416
|
const flashLoanFee = debtReserve!.getFlashLoanFee() || new Decimal(0);
|
|
582
417
|
const selectedTokenIsCollToken = selectedTokenMint === collTokenMint;
|
|
583
|
-
const collIsKtoken = await isKtoken(collTokenMint);
|
|
584
|
-
const strategy = collIsKtoken ? (await kamino!.getStrategyByKTokenMint(collTokenMint))! : undefined;
|
|
585
418
|
|
|
586
419
|
const inputTokenIsSol = selectedTokenMint === WRAPPED_SOL_MINT;
|
|
587
420
|
|
|
@@ -627,8 +460,6 @@ export async function getWithdrawWithLeverageSwapInputs<QuoteResponse>({
|
|
|
627
460
|
},
|
|
628
461
|
},
|
|
629
462
|
],
|
|
630
|
-
strategy,
|
|
631
|
-
collIsKtoken,
|
|
632
463
|
useV2Ixs
|
|
633
464
|
)
|
|
634
465
|
)[0];
|
|
@@ -641,7 +472,6 @@ export async function getWithdrawWithLeverageSwapInputs<QuoteResponse>({
|
|
|
641
472
|
inputAmountLamports: swapInputAmount.mul(new Decimal(1).add(quoteBufferBps.div(FullBPS))),
|
|
642
473
|
inputMint: collTokenMint,
|
|
643
474
|
outputMint: debtTokenMint,
|
|
644
|
-
amountDebtAtaBalance: undefined, // Only needed for ktokens deposits
|
|
645
475
|
};
|
|
646
476
|
|
|
647
477
|
const swapQuote = await quoter(swapInputsForQuote, uniqueKlendAccounts);
|
|
@@ -650,7 +480,7 @@ export async function getWithdrawWithLeverageSwapInputs<QuoteResponse>({
|
|
|
650
480
|
kaminoMarket,
|
|
651
481
|
collReserve!,
|
|
652
482
|
debtReserve!,
|
|
653
|
-
|
|
483
|
+
swapQuote.priceAInB,
|
|
654
484
|
withdrawAmount,
|
|
655
485
|
deposited,
|
|
656
486
|
borrowed,
|
|
@@ -671,15 +501,12 @@ export async function getWithdrawWithLeverageSwapInputs<QuoteResponse>({
|
|
|
671
501
|
minOutAmountLamports: calcsQuotePrice.repayAmount,
|
|
672
502
|
inputMint: collTokenMint,
|
|
673
503
|
outputMint: debtTokenMint,
|
|
674
|
-
amountDebtAtaBalance: new Decimal(0), // Only needed for ktokens deposits
|
|
675
504
|
},
|
|
676
505
|
flashLoanInfo: klendIxs.flashLoanInfo,
|
|
677
506
|
initialInputs: {
|
|
678
507
|
calcs: calcsQuotePrice,
|
|
679
508
|
swapQuote,
|
|
680
509
|
currentSlot,
|
|
681
|
-
collIsKtoken,
|
|
682
|
-
strategy,
|
|
683
510
|
obligation,
|
|
684
511
|
klendAccounts: uniqueKlendAccounts,
|
|
685
512
|
},
|
|
@@ -702,10 +529,8 @@ export async function getWithdrawWithLeverageIxs<QuoteResponse>({
|
|
|
702
529
|
isClosingPosition,
|
|
703
530
|
selectedTokenMint,
|
|
704
531
|
budgetAndPriorityFeeIxs,
|
|
705
|
-
kamino,
|
|
706
532
|
scopeRefreshConfig,
|
|
707
533
|
quoteBufferBps,
|
|
708
|
-
isKtoken,
|
|
709
534
|
quoter,
|
|
710
535
|
swapper,
|
|
711
536
|
useV2Ixs,
|
|
@@ -730,40 +555,17 @@ export async function getWithdrawWithLeverageIxs<QuoteResponse>({
|
|
|
730
555
|
isClosingPosition,
|
|
731
556
|
selectedTokenMint,
|
|
732
557
|
budgetAndPriorityFeeIxs,
|
|
733
|
-
kamino,
|
|
734
558
|
scopeRefreshConfig,
|
|
735
559
|
quoteBufferBps,
|
|
736
|
-
isKtoken,
|
|
737
560
|
quoter,
|
|
738
561
|
useV2Ixs,
|
|
739
562
|
});
|
|
740
563
|
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
if (initialInputs.collIsKtoken) {
|
|
744
|
-
if (kamino === undefined) {
|
|
745
|
-
throw Error('Ktoken use as collateral for leverage without Kamino instance');
|
|
746
|
-
}
|
|
747
|
-
withdrawSwapper = await getKtokenToTokenSwapper(kaminoMarket, kamino, owner, swapper);
|
|
748
|
-
} else {
|
|
749
|
-
withdrawSwapper = swapper;
|
|
750
|
-
}
|
|
564
|
+
const withdrawSwapper: SwapIxsProvider<QuoteResponse> = swapper;
|
|
751
565
|
|
|
752
566
|
const swapsArray = await withdrawSwapper(swapInputs, initialInputs.klendAccounts, initialInputs.swapQuote);
|
|
753
567
|
|
|
754
|
-
|
|
755
|
-
if (initialInputs.strategy?.strategy.strategyLookupTable) {
|
|
756
|
-
const strategyLut = await fetchAddressLookupTable(
|
|
757
|
-
kaminoMarket.getRpc(),
|
|
758
|
-
initialInputs.strategy.strategy.strategyLookupTable
|
|
759
|
-
);
|
|
760
|
-
swapsArray.forEach((swap) => {
|
|
761
|
-
swap.lookupTables.push(strategyLut);
|
|
762
|
-
});
|
|
763
|
-
} else {
|
|
764
|
-
console.log('Strategy lookup table not found');
|
|
765
|
-
}
|
|
766
|
-
}
|
|
568
|
+
// Strategy lookup table logic removed
|
|
767
569
|
|
|
768
570
|
const withdrawWithLeverageIxs = await buildWithdrawWithLeverageIxs<QuoteResponse>(
|
|
769
571
|
kaminoMarket,
|
|
@@ -786,8 +588,6 @@ export async function getWithdrawWithLeverageIxs<QuoteResponse>({
|
|
|
786
588
|
quote: swap.quote,
|
|
787
589
|
};
|
|
788
590
|
}),
|
|
789
|
-
initialInputs.strategy,
|
|
790
|
-
initialInputs.collIsKtoken,
|
|
791
591
|
useV2Ixs
|
|
792
592
|
);
|
|
793
593
|
|
|
@@ -818,8 +618,6 @@ export async function buildWithdrawWithLeverageIxs<QuoteResponse>(
|
|
|
818
618
|
calcs: WithdrawLeverageCalcsResult,
|
|
819
619
|
budgetAndPriorityFeeIxs: Instruction[] | undefined,
|
|
820
620
|
swapQuoteIxsArray: SwapIxs<QuoteResponse>[],
|
|
821
|
-
strategy: StrategyWithAddress | undefined,
|
|
822
|
-
collIsKtoken: boolean,
|
|
823
621
|
useV2Ixs: boolean
|
|
824
622
|
): Promise<LeverageIxsOutput[]> {
|
|
825
623
|
const collTokenMint = collReserve.getLiquidityMint();
|
|
@@ -837,10 +635,8 @@ export async function buildWithdrawWithLeverageIxs<QuoteResponse>(
|
|
|
837
635
|
obligation,
|
|
838
636
|
collTokenMint,
|
|
839
637
|
collReserve,
|
|
840
|
-
collIsKtoken,
|
|
841
638
|
debtTokenMint,
|
|
842
639
|
debtReserve,
|
|
843
|
-
strategy,
|
|
844
640
|
scopeRefreshConfig,
|
|
845
641
|
budgetAndPriorityFeeIxs
|
|
846
642
|
);
|
|
@@ -953,10 +749,8 @@ export async function getAdjustLeverageSwapInputs<QuoteResponse>({
|
|
|
953
749
|
priceDebtToColl,
|
|
954
750
|
slippagePct,
|
|
955
751
|
budgetAndPriorityFeeIxs,
|
|
956
|
-
kamino,
|
|
957
752
|
scopeRefreshConfig,
|
|
958
753
|
quoteBufferBps,
|
|
959
|
-
isKtoken,
|
|
960
754
|
quoter,
|
|
961
755
|
useV2Ixs,
|
|
962
756
|
withdrawSlotOffset,
|
|
@@ -969,8 +763,6 @@ export async function getAdjustLeverageSwapInputs<QuoteResponse>({
|
|
|
969
763
|
const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint)!;
|
|
970
764
|
const deposited = fromLamports(depositedLamports, collReserve.stats.decimals);
|
|
971
765
|
const borrowed = fromLamports(borrowedLamports, debtReserve.stats.decimals);
|
|
972
|
-
const collIsKtoken = await isKtoken(collTokenMint);
|
|
973
|
-
const strategy = collIsKtoken ? (await kamino!.getStrategyByKTokenMint(collTokenMint))! : undefined;
|
|
974
766
|
|
|
975
767
|
// Getting current flash loan fee
|
|
976
768
|
const currentLeverage = obligation.refreshedStats.leverage;
|
|
@@ -997,15 +789,12 @@ export async function getAdjustLeverageSwapInputs<QuoteResponse>({
|
|
|
997
789
|
|
|
998
790
|
if (isDeposit) {
|
|
999
791
|
const calcs = await adjustDepositLeverageCalcs(
|
|
1000
|
-
kaminoMarket,
|
|
1001
|
-
owner.address,
|
|
1002
792
|
debtReserve!,
|
|
1003
793
|
adjustDepositPosition,
|
|
1004
794
|
adjustBorrowPosition,
|
|
1005
795
|
priceDebtToColl,
|
|
1006
796
|
flashLoanFee,
|
|
1007
|
-
slippagePct
|
|
1008
|
-
collIsKtoken
|
|
797
|
+
slippagePct
|
|
1009
798
|
);
|
|
1010
799
|
|
|
1011
800
|
// Build the repay & withdraw collateral tx to get the number of accounts
|
|
@@ -1019,9 +808,7 @@ export async function getAdjustLeverageSwapInputs<QuoteResponse>({
|
|
|
1019
808
|
referrer,
|
|
1020
809
|
currentSlot,
|
|
1021
810
|
calcs,
|
|
1022
|
-
strategy,
|
|
1023
811
|
scopeRefreshConfig,
|
|
1024
|
-
collIsKtoken,
|
|
1025
812
|
[
|
|
1026
813
|
{
|
|
1027
814
|
preActionIxs: [],
|
|
@@ -1040,16 +827,12 @@ export async function getAdjustLeverageSwapInputs<QuoteResponse>({
|
|
|
1040
827
|
|
|
1041
828
|
const uniqueKlendAccounts = uniqueAccountsWithProgramIds(klendIxs.instructions);
|
|
1042
829
|
|
|
1043
|
-
const swapInputAmount = toLamports(
|
|
1044
|
-
!collIsKtoken ? calcs.borrowAmount : calcs.amountToFlashBorrowDebt,
|
|
1045
|
-
debtReserve.stats.decimals
|
|
1046
|
-
).ceil();
|
|
830
|
+
const swapInputAmount = toLamports(calcs.borrowAmount, debtReserve.stats.decimals).ceil();
|
|
1047
831
|
|
|
1048
832
|
const swapInputsForQuote: SwapInputs = {
|
|
1049
833
|
inputAmountLamports: swapInputAmount.mul(new Decimal(1).add(quoteBufferBps.div(FullBPS))),
|
|
1050
834
|
inputMint: debtTokenMint,
|
|
1051
835
|
outputMint: collTokenMint,
|
|
1052
|
-
amountDebtAtaBalance: new Decimal(0), // Only needed for ktokens swaps
|
|
1053
836
|
};
|
|
1054
837
|
|
|
1055
838
|
const swapQuote = await quoter(swapInputsForQuote, uniqueKlendAccounts);
|
|
@@ -1066,54 +849,28 @@ export async function getAdjustLeverageSwapInputs<QuoteResponse>({
|
|
|
1066
849
|
});
|
|
1067
850
|
|
|
1068
851
|
const calcsQuotePrice = await adjustDepositLeverageCalcs(
|
|
1069
|
-
kaminoMarket,
|
|
1070
|
-
owner.address,
|
|
1071
852
|
debtReserve,
|
|
1072
853
|
adjustDepositPositionQuotePrice,
|
|
1073
854
|
adjustBorrowPositionQuotePrice,
|
|
1074
855
|
swapQuote.priceAInB,
|
|
1075
856
|
flashLoanFee,
|
|
1076
|
-
slippagePct
|
|
1077
|
-
collIsKtoken
|
|
857
|
+
slippagePct
|
|
1078
858
|
);
|
|
1079
859
|
|
|
1080
|
-
const swapInputAmountQuotePrice = toLamports(
|
|
1081
|
-
!collIsKtoken ? calcsQuotePrice.borrowAmount : calcsQuotePrice.amountToFlashBorrowDebt,
|
|
1082
|
-
debtReserve.getMintDecimals()
|
|
1083
|
-
).ceil();
|
|
1084
|
-
|
|
1085
|
-
let expectedDebtTokenAtaBalance = new Decimal(0);
|
|
1086
|
-
if (collIsKtoken) {
|
|
1087
|
-
expectedDebtTokenAtaBalance = await getExpectedTokenBalanceAfterBorrow(
|
|
1088
|
-
kaminoMarket.getRpc(),
|
|
1089
|
-
debtTokenMint,
|
|
1090
|
-
owner.address,
|
|
1091
|
-
toLamports(
|
|
1092
|
-
!collIsKtoken ? calcsQuotePrice.borrowAmount : calcsQuotePrice.amountToFlashBorrowDebt,
|
|
1093
|
-
debtReserve.stats.decimals
|
|
1094
|
-
).floor(),
|
|
1095
|
-
debtReserve.getMintDecimals()
|
|
1096
|
-
);
|
|
1097
|
-
}
|
|
860
|
+
const swapInputAmountQuotePrice = toLamports(calcsQuotePrice.borrowAmount, debtReserve.getMintDecimals()).ceil();
|
|
1098
861
|
|
|
1099
862
|
return {
|
|
1100
863
|
swapInputs: {
|
|
1101
864
|
inputAmountLamports: swapInputAmountQuotePrice,
|
|
1102
|
-
minOutAmountLamports: toLamports(
|
|
1103
|
-
!collIsKtoken ? calcsQuotePrice.adjustDepositPosition : calcsQuotePrice.amountToFlashBorrowDebt,
|
|
1104
|
-
!collIsKtoken ? collReserve.stats.decimals : debtReserve!.stats.decimals
|
|
1105
|
-
),
|
|
865
|
+
minOutAmountLamports: toLamports(calcsQuotePrice.adjustDepositPosition, collReserve.stats.decimals),
|
|
1106
866
|
inputMint: debtTokenMint,
|
|
1107
867
|
outputMint: collTokenMint,
|
|
1108
|
-
amountDebtAtaBalance: expectedDebtTokenAtaBalance,
|
|
1109
868
|
},
|
|
1110
869
|
flashLoanInfo: klendIxs.flashLoanInfo,
|
|
1111
870
|
initialInputs: {
|
|
1112
871
|
calcs: calcsQuotePrice,
|
|
1113
872
|
swapQuote,
|
|
1114
873
|
currentSlot,
|
|
1115
|
-
collIsKtoken,
|
|
1116
|
-
strategy,
|
|
1117
874
|
obligation: obligation,
|
|
1118
875
|
klendAccounts: uniqueKlendAccounts,
|
|
1119
876
|
isDeposit: isDeposit,
|
|
@@ -1132,9 +889,7 @@ export async function getAdjustLeverageSwapInputs<QuoteResponse>({
|
|
|
1132
889
|
referrer,
|
|
1133
890
|
currentSlot,
|
|
1134
891
|
calcs,
|
|
1135
|
-
strategy,
|
|
1136
892
|
scopeRefreshConfig,
|
|
1137
|
-
collIsKtoken,
|
|
1138
893
|
[
|
|
1139
894
|
{
|
|
1140
895
|
preActionIxs: [],
|
|
@@ -1163,7 +918,6 @@ export async function getAdjustLeverageSwapInputs<QuoteResponse>({
|
|
|
1163
918
|
inputAmountLamports: swapInputAmount.mul(new Decimal(1).add(quoteBufferBps.div(FullBPS))),
|
|
1164
919
|
inputMint: collTokenMint,
|
|
1165
920
|
outputMint: debtTokenMint,
|
|
1166
|
-
amountDebtAtaBalance: undefined, // Only needed for ktokens deposits
|
|
1167
921
|
};
|
|
1168
922
|
|
|
1169
923
|
const swapQuote = await quoter(swapInputsForQuote, uniqueKlendAccounts);
|
|
@@ -1197,15 +951,12 @@ export async function getAdjustLeverageSwapInputs<QuoteResponse>({
|
|
|
1197
951
|
minOutAmountLamports: toLamports(calcsQuotePrice.adjustBorrowPosition.abs(), debtReserve.stats.decimals),
|
|
1198
952
|
inputMint: collTokenMint,
|
|
1199
953
|
outputMint: debtTokenMint,
|
|
1200
|
-
amountDebtAtaBalance: undefined, // Only needed for ktokens deposits
|
|
1201
954
|
},
|
|
1202
955
|
flashLoanInfo: klendIxs.flashLoanInfo,
|
|
1203
956
|
initialInputs: {
|
|
1204
957
|
calcs: calcsQuotePrice,
|
|
1205
958
|
swapQuote,
|
|
1206
959
|
currentSlot,
|
|
1207
|
-
collIsKtoken,
|
|
1208
|
-
strategy,
|
|
1209
960
|
obligation,
|
|
1210
961
|
klendAccounts: uniqueKlendAccounts,
|
|
1211
962
|
isDeposit,
|
|
@@ -1229,11 +980,8 @@ export async function getAdjustLeverageIxs<QuoteResponse>({
|
|
|
1229
980
|
priceDebtToColl,
|
|
1230
981
|
slippagePct,
|
|
1231
982
|
budgetAndPriorityFeeIxs,
|
|
1232
|
-
kamino,
|
|
1233
983
|
scopeRefreshConfig,
|
|
1234
984
|
quoteBufferBps,
|
|
1235
|
-
priceAinB,
|
|
1236
|
-
isKtoken,
|
|
1237
985
|
quoter,
|
|
1238
986
|
swapper,
|
|
1239
987
|
useV2Ixs,
|
|
@@ -1254,35 +1002,15 @@ export async function getAdjustLeverageIxs<QuoteResponse>({
|
|
|
1254
1002
|
priceDebtToColl,
|
|
1255
1003
|
slippagePct,
|
|
1256
1004
|
budgetAndPriorityFeeIxs,
|
|
1257
|
-
kamino,
|
|
1258
1005
|
scopeRefreshConfig,
|
|
1259
1006
|
quoteBufferBps,
|
|
1260
|
-
priceAinB,
|
|
1261
|
-
isKtoken,
|
|
1262
1007
|
quoter,
|
|
1263
1008
|
useV2Ixs,
|
|
1264
1009
|
});
|
|
1265
1010
|
|
|
1266
1011
|
// leverage increased so we need to deposit and borrow more
|
|
1267
1012
|
if (initialInputs.isDeposit) {
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
if (initialInputs.collIsKtoken) {
|
|
1271
|
-
if (kamino === undefined) {
|
|
1272
|
-
throw Error('Ktoken use as collateral for leverage without Kamino instance');
|
|
1273
|
-
}
|
|
1274
|
-
depositSwapper = await getTokenToKtokenSwapper(
|
|
1275
|
-
kaminoMarket,
|
|
1276
|
-
kamino,
|
|
1277
|
-
owner,
|
|
1278
|
-
slippagePct,
|
|
1279
|
-
swapper,
|
|
1280
|
-
priceAinB,
|
|
1281
|
-
false
|
|
1282
|
-
);
|
|
1283
|
-
} else {
|
|
1284
|
-
depositSwapper = swapper;
|
|
1285
|
-
}
|
|
1013
|
+
const depositSwapper: SwapIxsProvider<QuoteResponse> = swapper;
|
|
1286
1014
|
|
|
1287
1015
|
const swapsArray = await depositSwapper(swapInputs, initialInputs.klendAccounts, initialInputs.swapQuote);
|
|
1288
1016
|
|
|
@@ -1295,9 +1023,7 @@ export async function getAdjustLeverageIxs<QuoteResponse>({
|
|
|
1295
1023
|
referrer,
|
|
1296
1024
|
currentSlot,
|
|
1297
1025
|
initialInputs.calcs,
|
|
1298
|
-
initialInputs.strategy,
|
|
1299
1026
|
scopeRefreshConfig,
|
|
1300
|
-
initialInputs.collIsKtoken,
|
|
1301
1027
|
swapsArray.map((swap) => {
|
|
1302
1028
|
return {
|
|
1303
1029
|
preActionIxs: [],
|
|
@@ -1322,16 +1048,7 @@ export async function getAdjustLeverageIxs<QuoteResponse>({
|
|
|
1322
1048
|
} else {
|
|
1323
1049
|
console.log('Decreasing leverage');
|
|
1324
1050
|
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
if (initialInputs.collIsKtoken) {
|
|
1328
|
-
if (kamino === undefined) {
|
|
1329
|
-
throw Error('Ktoken use as collateral for leverage without Kamino instance');
|
|
1330
|
-
}
|
|
1331
|
-
withdrawSwapper = await getKtokenToTokenSwapper(kaminoMarket, kamino, owner, swapper);
|
|
1332
|
-
} else {
|
|
1333
|
-
withdrawSwapper = swapper;
|
|
1334
|
-
}
|
|
1051
|
+
const withdrawSwapper: SwapIxsProvider<QuoteResponse> = swapper;
|
|
1335
1052
|
|
|
1336
1053
|
// 5. Get swap ixs
|
|
1337
1054
|
const swapsArray = await withdrawSwapper(swapInputs, initialInputs.klendAccounts, initialInputs.swapQuote);
|
|
@@ -1345,9 +1062,7 @@ export async function getAdjustLeverageIxs<QuoteResponse>({
|
|
|
1345
1062
|
referrer,
|
|
1346
1063
|
currentSlot,
|
|
1347
1064
|
initialInputs.calcs,
|
|
1348
|
-
initialInputs.strategy,
|
|
1349
1065
|
scopeRefreshConfig,
|
|
1350
|
-
initialInputs.collIsKtoken,
|
|
1351
1066
|
swapsArray.map((swap) => {
|
|
1352
1067
|
return {
|
|
1353
1068
|
preActionIxs: [],
|
|
@@ -1386,19 +1101,18 @@ async function buildIncreaseLeverageIxs<QuoteResponse>(
|
|
|
1386
1101
|
referrer: Option<Address>,
|
|
1387
1102
|
currentSlot: Slot,
|
|
1388
1103
|
calcs: AdjustLeverageCalcsResult,
|
|
1389
|
-
strategy: StrategyWithAddress | undefined,
|
|
1390
1104
|
scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
|
|
1391
|
-
collIsKtoken: boolean,
|
|
1392
1105
|
swapQuoteIxsArray: SwapIxs<QuoteResponse>[],
|
|
1393
1106
|
budgetAndPriorityFeeIxs: Instruction[] | undefined,
|
|
1394
1107
|
useV2Ixs: boolean
|
|
1395
1108
|
): Promise<LeverageIxsOutput[]> {
|
|
1396
1109
|
const collReserve = kaminoMarket.getExistingReserveByMint(collTokenMint);
|
|
1397
1110
|
const debtReserve = kaminoMarket.getExistingReserveByMint(debtTokenMint);
|
|
1398
|
-
const
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1111
|
+
const collTokenAta = await getAssociatedTokenAddress(
|
|
1112
|
+
collTokenMint,
|
|
1113
|
+
owner.address,
|
|
1114
|
+
collReserve.getLiquidityTokenProgram()
|
|
1115
|
+
);
|
|
1402
1116
|
|
|
1403
1117
|
// 1. Create atas & budget txns
|
|
1404
1118
|
const { budgetIxs, createAtasIxs, scopeRefreshIx } = await getSetupIxs(
|
|
@@ -1407,10 +1121,8 @@ async function buildIncreaseLeverageIxs<QuoteResponse>(
|
|
|
1407
1121
|
obligation,
|
|
1408
1122
|
collTokenMint,
|
|
1409
1123
|
collReserve,
|
|
1410
|
-
collIsKtoken,
|
|
1411
1124
|
debtTokenMint,
|
|
1412
1125
|
debtReserve,
|
|
1413
|
-
strategy,
|
|
1414
1126
|
scopeRefreshConfig,
|
|
1415
1127
|
budgetAndPriorityFeeIxs
|
|
1416
1128
|
);
|
|
@@ -1421,12 +1133,9 @@ async function buildIncreaseLeverageIxs<QuoteResponse>(
|
|
|
1421
1133
|
userTransferAuthority: owner,
|
|
1422
1134
|
lendingMarketAuthority: await kaminoMarket.getLendingMarketAuthority(),
|
|
1423
1135
|
lendingMarketAddress: kaminoMarket.getAddress(),
|
|
1424
|
-
reserve:
|
|
1425
|
-
amountLamports: toLamports(
|
|
1426
|
-
|
|
1427
|
-
!collIsKtoken ? collReserve!.stats.decimals : debtReserve!.stats.decimals
|
|
1428
|
-
),
|
|
1429
|
-
destinationAta: !collIsKtoken ? collTokenAta : debtTokenAta,
|
|
1136
|
+
reserve: collReserve!,
|
|
1137
|
+
amountLamports: toLamports(calcs.adjustDepositPosition, collReserve!.stats.decimals),
|
|
1138
|
+
destinationAta: collTokenAta,
|
|
1430
1139
|
// TODO(referrals): once we support referrals, we will have to replace the placeholder args below:
|
|
1431
1140
|
referrerAccount: none(),
|
|
1432
1141
|
referrerTokenState: none(),
|
|
@@ -1474,14 +1183,13 @@ async function buildIncreaseLeverageIxs<QuoteResponse>(
|
|
|
1474
1183
|
...budgetIxs,
|
|
1475
1184
|
...createAtasIxs,
|
|
1476
1185
|
...[flashBorrowIx],
|
|
1477
|
-
...(collIsKtoken ? swapInstructions : []),
|
|
1478
1186
|
...KaminoAction.actionToIxs(depositAction),
|
|
1479
1187
|
...KaminoAction.actionToIxs(borrowAction),
|
|
1480
|
-
...
|
|
1188
|
+
...swapInstructions,
|
|
1481
1189
|
...[flashRepayIx],
|
|
1482
1190
|
];
|
|
1483
1191
|
|
|
1484
|
-
const flashBorrowReserve =
|
|
1192
|
+
const flashBorrowReserve = collReserve!;
|
|
1485
1193
|
const res: LeverageIxsOutput = {
|
|
1486
1194
|
flashLoanInfo: {
|
|
1487
1195
|
flashBorrowReserve: flashBorrowReserve.address,
|
|
@@ -1506,9 +1214,7 @@ async function buildDecreaseLeverageIxs<QuoteResponse>(
|
|
|
1506
1214
|
referrer: Option<Address>,
|
|
1507
1215
|
currentSlot: Slot,
|
|
1508
1216
|
calcs: AdjustLeverageCalcsResult,
|
|
1509
|
-
strategy: StrategyWithAddress | undefined,
|
|
1510
1217
|
scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
|
|
1511
|
-
collIsKtoken: boolean,
|
|
1512
1218
|
swapQuoteIxsArray: SwapIxs<QuoteResponse>[],
|
|
1513
1219
|
budgetAndPriorityFeeIxs: Instruction[] | undefined,
|
|
1514
1220
|
useV2Ixs: boolean,
|
|
@@ -1529,10 +1235,8 @@ async function buildDecreaseLeverageIxs<QuoteResponse>(
|
|
|
1529
1235
|
obligation,
|
|
1530
1236
|
collTokenMint,
|
|
1531
1237
|
collReserve,
|
|
1532
|
-
collIsKtoken,
|
|
1533
1238
|
debtTokenMint,
|
|
1534
1239
|
debtReserve,
|
|
1535
|
-
strategy,
|
|
1536
1240
|
scopeRefreshConfig,
|
|
1537
1241
|
budgetAndPriorityFeeIxs
|
|
1538
1242
|
);
|
|
@@ -1655,23 +1359,14 @@ export const getSetupIxs = async (
|
|
|
1655
1359
|
obligation: KaminoObligation | ObligationType | undefined,
|
|
1656
1360
|
collTokenMint: Address,
|
|
1657
1361
|
collReserve: KaminoReserve,
|
|
1658
|
-
collIsKtoken: boolean,
|
|
1659
1362
|
debtTokenMint: Address,
|
|
1660
1363
|
debtReserve: KaminoReserve,
|
|
1661
|
-
strategy: StrategyWithAddress | undefined,
|
|
1662
1364
|
scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
|
|
1663
1365
|
budgetAndPriorityFeeIxs: Instruction[] | undefined
|
|
1664
1366
|
) => {
|
|
1665
1367
|
const budgetIxs = budgetAndPriorityFeeIxs || getComputeBudgetAndPriorityFeeIxs(3000000);
|
|
1666
1368
|
|
|
1667
|
-
const mintsWithTokenPrograms = getTokenMintsWithTokenPrograms(
|
|
1668
|
-
collTokenMint,
|
|
1669
|
-
collReserve,
|
|
1670
|
-
debtTokenMint,
|
|
1671
|
-
debtReserve,
|
|
1672
|
-
collIsKtoken,
|
|
1673
|
-
strategy
|
|
1674
|
-
);
|
|
1369
|
+
const mintsWithTokenPrograms = getTokenMintsWithTokenPrograms(collTokenMint, collReserve, debtTokenMint, debtReserve);
|
|
1675
1370
|
|
|
1676
1371
|
const createAtasIxs = (await createAtasIdempotent(owner, mintsWithTokenPrograms)).map((x) => x.createAtaIx);
|
|
1677
1372
|
|
|
@@ -1756,11 +1451,9 @@ const getTokenMintsWithTokenPrograms = (
|
|
|
1756
1451
|
collTokenMint: Address,
|
|
1757
1452
|
collReserve: KaminoReserve,
|
|
1758
1453
|
debtTokenMint: Address,
|
|
1759
|
-
debtReserve: KaminoReserve
|
|
1760
|
-
collIsKtoken: boolean,
|
|
1761
|
-
strategy: StrategyWithAddress | undefined
|
|
1454
|
+
debtReserve: KaminoReserve
|
|
1762
1455
|
): Array<MintWithTokenProgram> => {
|
|
1763
|
-
|
|
1456
|
+
return [
|
|
1764
1457
|
{
|
|
1765
1458
|
mint: collTokenMint,
|
|
1766
1459
|
tokenProgram: collReserve.getLiquidityTokenProgram(),
|
|
@@ -1774,29 +1467,4 @@ const getTokenMintsWithTokenPrograms = (
|
|
|
1774
1467
|
tokenProgram: TOKEN_PROGRAM_ADDRESS,
|
|
1775
1468
|
},
|
|
1776
1469
|
];
|
|
1777
|
-
|
|
1778
|
-
if (collIsKtoken) {
|
|
1779
|
-
let kTokenAta: Address;
|
|
1780
|
-
let kTokenTokenProgram: Address;
|
|
1781
|
-
if (strategy!.strategy.tokenAMint === debtTokenMint) {
|
|
1782
|
-
kTokenAta = strategy!.strategy.tokenBMint;
|
|
1783
|
-
kTokenTokenProgram =
|
|
1784
|
-
strategy!.strategy.tokenBTokenProgram === DEFAULT_PUBLIC_KEY
|
|
1785
|
-
? TOKEN_PROGRAM_ADDRESS
|
|
1786
|
-
: strategy!.strategy.tokenBTokenProgram;
|
|
1787
|
-
} else {
|
|
1788
|
-
kTokenAta = strategy!.strategy.tokenAMint;
|
|
1789
|
-
kTokenTokenProgram =
|
|
1790
|
-
strategy!.strategy.tokenATokenProgram === DEFAULT_PUBLIC_KEY
|
|
1791
|
-
? TOKEN_PROGRAM_ADDRESS
|
|
1792
|
-
: strategy!.strategy.tokenATokenProgram;
|
|
1793
|
-
}
|
|
1794
|
-
|
|
1795
|
-
mintsWithTokenPrograms.push({
|
|
1796
|
-
mint: kTokenAta,
|
|
1797
|
-
tokenProgram: kTokenTokenProgram,
|
|
1798
|
-
});
|
|
1799
|
-
}
|
|
1800
|
-
|
|
1801
|
-
return mintsWithTokenPrograms;
|
|
1802
1470
|
};
|