@kamino-finance/klend-sdk 5.10.35-beta.1 → 5.11.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.
Files changed (58) hide show
  1. package/dist/classes/action.d.ts +24 -26
  2. package/dist/classes/action.d.ts.map +1 -1
  3. package/dist/classes/action.js +501 -270
  4. package/dist/classes/action.js.map +1 -1
  5. package/dist/classes/lut_utils.d.ts +29 -0
  6. package/dist/classes/lut_utils.d.ts.map +1 -0
  7. package/dist/classes/lut_utils.js +62 -0
  8. package/dist/classes/lut_utils.js.map +1 -0
  9. package/dist/classes/manager.js +1 -1
  10. package/dist/classes/manager.js.map +1 -1
  11. package/dist/classes/obligation.d.ts +1 -1
  12. package/dist/classes/obligation.d.ts.map +1 -1
  13. package/dist/classes/obligation.js +1 -1
  14. package/dist/classes/obligation.js.map +1 -1
  15. package/dist/classes/vault.js +6 -6
  16. package/dist/classes/vault.js.map +1 -1
  17. package/dist/lending_operations/repay_with_collateral_calcs.d.ts.map +1 -1
  18. package/dist/lending_operations/repay_with_collateral_calcs.js +5 -9
  19. package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
  20. package/dist/lending_operations/repay_with_collateral_operations.d.ts +3 -7
  21. package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
  22. package/dist/lending_operations/repay_with_collateral_operations.js +7 -27
  23. package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
  24. package/dist/lending_operations/swap_collateral_operations.d.ts +5 -0
  25. package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
  26. package/dist/lending_operations/swap_collateral_operations.js +4 -2
  27. package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
  28. package/dist/leverage/operations.d.ts +8 -8
  29. package/dist/leverage/operations.d.ts.map +1 -1
  30. package/dist/leverage/operations.js +27 -24
  31. package/dist/leverage/operations.js.map +1 -1
  32. package/dist/leverage/types.d.ts +4 -1
  33. package/dist/leverage/types.d.ts.map +1 -1
  34. package/dist/utils/lookupTable.d.ts +0 -27
  35. package/dist/utils/lookupTable.d.ts.map +1 -1
  36. package/dist/utils/lookupTable.js +0 -58
  37. package/dist/utils/lookupTable.js.map +1 -1
  38. package/dist/utils/seeds.d.ts +3 -9
  39. package/dist/utils/seeds.d.ts.map +1 -1
  40. package/dist/utils/seeds.js +5 -11
  41. package/dist/utils/seeds.js.map +1 -1
  42. package/dist/utils/userMetadata.js +6 -6
  43. package/dist/utils/userMetadata.js.map +1 -1
  44. package/package.json +4 -1
  45. package/src/classes/action.ts +643 -404
  46. package/src/classes/lut_utils.ts +63 -0
  47. package/src/classes/manager.ts +1 -1
  48. package/src/classes/obligation.ts +1 -1
  49. package/src/classes/vault.ts +1 -1
  50. package/src/client.ts +7 -3
  51. package/src/lending_operations/repay_with_collateral_calcs.ts +5 -14
  52. package/src/lending_operations/repay_with_collateral_operations.ts +14 -30
  53. package/src/lending_operations/swap_collateral_operations.ts +11 -0
  54. package/src/leverage/operations.ts +38 -11
  55. package/src/leverage/types.ts +4 -1
  56. package/src/utils/lookupTable.ts +0 -62
  57. package/src/utils/seeds.ts +7 -12
  58. package/src/utils/userMetadata.ts +14 -14
@@ -0,0 +1,63 @@
1
+ import { AddressLookupTableProgram, Connection, PublicKey, TransactionInstruction } from '@solana/web3.js';
2
+
3
+ /**
4
+ * This method retuns an instruction that creates a lookup table, alongside the pubkey of the lookup table
5
+ * @param payer - the owner of the lookup table
6
+ * @param slot - the current slot
7
+ * @returns - the instruction to create the lookup table and its address
8
+ */
9
+ export function initLookupTableIx(payer: PublicKey, slot: number): [TransactionInstruction, PublicKey] {
10
+ const [ixn, address] = AddressLookupTableProgram.createLookupTable({
11
+ authority: payer,
12
+ payer,
13
+ recentSlot: slot,
14
+ });
15
+
16
+ return [ixn, address];
17
+ }
18
+
19
+ /**
20
+ * This method retuns an instruction that deactivates a lookup table, which is needed to close it
21
+ * @param payer - the owner of the lookup table
22
+ * @param lookupTable - the lookup table to deactivate
23
+ * @returns - the instruction to deactivate the lookup table
24
+ */
25
+ export function deactivateLookupTableIx(payer: PublicKey, lookupTable: PublicKey): TransactionInstruction {
26
+ const ixn = AddressLookupTableProgram.deactivateLookupTable({
27
+ authority: payer,
28
+ lookupTable: lookupTable,
29
+ });
30
+
31
+ return ixn;
32
+ }
33
+
34
+ /**
35
+ * This method returns an instruction that closes a lookup table. That lookup table needs to be disabled at least 500 blocks before closing it.
36
+ * @param payer - the owner of the lookup table
37
+ * @param lookupTable - the lookup table to close
38
+ * @returns - the instruction to close the lookup table
39
+ */
40
+ /// this require the LUT to be deactivated at least 500 blocks before
41
+ export function closeLookupTableIx(payer: PublicKey, lookupTable: PublicKey): TransactionInstruction {
42
+ const ixn = AddressLookupTableProgram.closeLookupTable({
43
+ authority: payer,
44
+ recipient: payer,
45
+ lookupTable: lookupTable,
46
+ });
47
+
48
+ return ixn;
49
+ }
50
+
51
+ /**
52
+ * Returns the accounts in a lookup table
53
+ * @param lookupTable - lookup table to get the accounts from
54
+ * @returns - an array of accounts in the lookup table
55
+ */
56
+ export async function getAccountsInLUT(connection: Connection, lookupTable: PublicKey): Promise<PublicKey[]> {
57
+ const lutState = await connection.getAddressLookupTable(lookupTable);
58
+ if (!lutState || !lutState.value) {
59
+ throw new Error(`Lookup table ${lookupTable} not found`);
60
+ }
61
+
62
+ return lutState.value.state.addresses;
63
+ }
@@ -199,7 +199,7 @@ export class KaminoManager {
199
199
  reserveAccount.publicKey,
200
200
  params.assetConfig.getReserveConfig(),
201
201
  undefined,
202
- true
202
+ false
203
203
  );
204
204
 
205
205
  const txnIxns: TransactionInstruction[][] = [];
@@ -266,7 +266,7 @@ export class KaminoObligation {
266
266
  /**
267
267
  * @returns total borrow power of the obligation, relative to max LTV of each asset's reserve
268
268
  */
269
- getMaxAllowedBorrowValue(): Decimal {
269
+ getAllowedBorrowValue(): Decimal {
270
270
  return new Fraction(this.state.allowedBorrowValueSf).toDecimal();
271
271
  }
272
272
 
@@ -82,7 +82,7 @@ import {
82
82
  import { batchFetch, collToLamportsDecimal, ZERO } from '@kamino-finance/kliquidity-sdk';
83
83
  import { FullBPSDecimal } from '@kamino-finance/kliquidity-sdk/dist/utils/CreationParameters';
84
84
  import { FarmState } from '@kamino-finance/farms-sdk/dist';
85
- import { getAccountsInLUT, initLookupTableIx } from '../utils/lookupTable';
85
+ import { getAccountsInLUT, initLookupTableIx } from './lut_utils';
86
86
  import {
87
87
  getFarmStakeIxs,
88
88
  getFarmUnstakeAndWithdrawIxs,
package/src/client.ts CHANGED
@@ -308,7 +308,8 @@ async function deposit(connection: Connection, wallet: Keypair, token: string, d
308
308
  depositAmount,
309
309
  kaminoMarket.getReserveBySymbol(token)!.getLiquidityMint(),
310
310
  wallet.publicKey,
311
- new VanillaObligation(STAGING_LENDING_MARKET)
311
+ new VanillaObligation(STAGING_LENDING_MARKET),
312
+ true
312
313
  );
313
314
  console.log('User obligation', kaminoAction.obligation!.obligationAddress.toString());
314
315
 
@@ -328,7 +329,8 @@ async function withdraw(connection: Connection, wallet: Keypair, token: string,
328
329
  depositAmount,
329
330
  kaminoMarket.getReserveBySymbol(token)!.getLiquidityMint(),
330
331
  wallet.publicKey,
331
- new VanillaObligation(new PublicKey(STAGING_LENDING_MARKET))
332
+ new VanillaObligation(new PublicKey(STAGING_LENDING_MARKET)),
333
+ true
332
334
  );
333
335
  console.log('User obligation', kaminoAction.obligation!.obligationAddress.toString());
334
336
 
@@ -348,7 +350,8 @@ async function borrow(connection: Connection, wallet: Keypair, token: string, bo
348
350
  borrowAmount,
349
351
  kaminoMarket.getReserveBySymbol(token)!.getLiquidityMint(),
350
352
  wallet.publicKey,
351
- new VanillaObligation(new PublicKey(STAGING_LENDING_MARKET))
353
+ new VanillaObligation(new PublicKey(STAGING_LENDING_MARKET)),
354
+ true
352
355
  );
353
356
  console.log('User obligation', kaminoAction.obligation!.obligationAddress.toString());
354
357
 
@@ -369,6 +372,7 @@ async function repay(connection: Connection, wallet: Keypair, token: string, bor
369
372
  kaminoMarket.getReserveBySymbol(token)!.getLiquidityMint(),
370
373
  wallet.publicKey,
371
374
  new VanillaObligation(new PublicKey(STAGING_LENDING_MARKET)),
375
+ true,
372
376
  await connection.getSlot()
373
377
  );
374
378
  console.log('User obligation', kaminoAction.obligation!.obligationAddress.toString());
@@ -2,7 +2,6 @@ import Decimal from 'decimal.js';
2
2
  import { KaminoMarket, KaminoObligation, KaminoReserve, numberToLamportsDecimal } from '../classes';
3
3
  import { PublicKey } from '@solana/web3.js';
4
4
  import { lamportsToDecimal } from '../classes/utils';
5
- import { MaxWithdrawLtvCheck, getMaxWithdrawLtvCheck } from './repay_with_collateral_operations';
6
5
 
7
6
  export function calcRepayAmountWithSlippage(
8
7
  kaminoMarket: KaminoMarket,
@@ -103,7 +102,6 @@ export function calcMaxWithdrawCollateral(
103
102
  .filter((p) => !p.reserveAddress.equals(borrow.reserveAddress))
104
103
  .reduce((acc, b) => acc.add(b.marketValueRefreshed), new Decimal('0'));
105
104
  }
106
- const maxWithdrawLtvCheck = getMaxWithdrawLtvCheck(obligation);
107
105
 
108
106
  let remainingDepositsValueWithLtv = new Decimal('0');
109
107
  if (obligation.getDeposits().length > 1) {
@@ -111,13 +109,8 @@ export function calcMaxWithdrawCollateral(
111
109
  .getDeposits()
112
110
  .filter((p) => !p.reserveAddress.equals(deposit.reserveAddress))
113
111
  .reduce((acc, d) => {
114
- const { maxLtv, liquidationLtv } = obligation.getLtvForReserve(
115
- market,
116
- market.getReserveByAddress(d.reserveAddress)!
117
- );
118
- const maxWithdrawLtv =
119
- maxWithdrawLtvCheck === MaxWithdrawLtvCheck.LIQUIDATION_THRESHOLD ? liquidationLtv : maxLtv;
120
- return acc.add(d.marketValueRefreshed.mul(maxWithdrawLtv));
112
+ const { maxLtv } = obligation.getLtvForReserve(market, market.getReserveByAddress(d.reserveAddress)!);
113
+ return acc.add(d.marketValueRefreshed.mul(maxLtv));
121
114
  }, new Decimal('0'));
122
115
  }
123
116
 
@@ -130,18 +123,16 @@ export function calcMaxWithdrawCollateral(
130
123
  repayingAllDebt: repayAmountLamports.gte(borrow.amount),
131
124
  };
132
125
  } else {
133
- const { maxLtv: collMaxLtv, liquidationLtv: collLiquidationLtv } = obligation.getLtvForReserve(
126
+ const { maxLtv: collMaxLtv } = obligation.getLtvForReserve(
134
127
  market,
135
128
  market.getReserveByAddress(depositReserve.address)!
136
129
  );
137
- const maxWithdrawLtv =
138
- maxWithdrawLtvCheck === MaxWithdrawLtvCheck.LIQUIDATION_THRESHOLD ? collLiquidationLtv : collMaxLtv;
139
130
  const numerator = deposit.marketValueRefreshed
140
- .mul(maxWithdrawLtv)
131
+ .mul(collMaxLtv)
141
132
  .add(remainingDepositsValueWithLtv)
142
133
  .sub(remainingBorrowsValue);
143
134
 
144
- const denominator = depositReserve.getOracleMarketPrice().mul(maxWithdrawLtv);
135
+ const denominator = depositReserve.getOracleMarketPrice().mul(collMaxLtv);
145
136
  const maxCollWithdrawAmount = numerator.div(denominator);
146
137
  const withdrawableCollLamports = maxCollWithdrawAmount.mul(depositReserve.getMintFactor()).floor();
147
138
 
@@ -52,14 +52,10 @@ interface RepayWithCollSwapInputsProps<QuoteResponse> {
52
52
  isClosingPosition: boolean;
53
53
  budgetAndPriorityFeeIxs?: TransactionInstruction[];
54
54
  scopeRefresh?: ScopeRefresh;
55
+ useV2Ixs: boolean;
55
56
  quoter: SwapQuoteProvider<QuoteResponse>;
56
57
  }
57
58
 
58
- export enum MaxWithdrawLtvCheck {
59
- MAX_LTV,
60
- LIQUIDATION_THRESHOLD,
61
- }
62
-
63
59
  export async function getRepayWithCollSwapInputs<QuoteResponse>({
64
60
  collTokenMint,
65
61
  currentSlot,
@@ -72,6 +68,7 @@ export async function getRepayWithCollSwapInputs<QuoteResponse>({
72
68
  isClosingPosition,
73
69
  budgetAndPriorityFeeIxs,
74
70
  scopeRefresh,
71
+ useV2Ixs,
75
72
  }: RepayWithCollSwapInputsProps<QuoteResponse>): Promise<{
76
73
  swapInputs: SwapInputs;
77
74
  initialInputs: RepayWithCollInitialInputs<QuoteResponse>;
@@ -137,7 +134,8 @@ export async function getRepayWithCollSwapInputs<QuoteResponse>({
137
134
  },
138
135
  isClosingPosition,
139
136
  repayAmountLamports,
140
- inputAmountLamports
137
+ inputAmountLamports,
138
+ useV2Ixs
141
139
  );
142
140
  const uniqueKlendAccounts = uniqueAccounts(klendIxs);
143
141
 
@@ -194,6 +192,7 @@ export async function getRepayWithCollIxs<QuoteResponse>({
194
192
  swapper,
195
193
  referrer,
196
194
  scopeRefresh,
195
+ useV2Ixs,
197
196
  logger = console.log,
198
197
  }: RepayWithCollIxsProps<QuoteResponse>): Promise<RepayWithCollIxsResponse<QuoteResponse>> {
199
198
  const { swapInputs, initialInputs } = await getRepayWithCollSwapInputs({
@@ -208,21 +207,13 @@ export async function getRepayWithCollIxs<QuoteResponse>({
208
207
  isClosingPosition,
209
208
  budgetAndPriorityFeeIxs,
210
209
  scopeRefresh,
210
+ useV2Ixs,
211
211
  });
212
212
  const { debtRepayAmountLamports, flashRepayAmountLamports, maxCollateralWithdrawLamports, swapQuote } = initialInputs;
213
213
  const { inputAmountLamports: collSwapInLamports } = swapInputs;
214
214
 
215
- const collReserve = kaminoMarket.getReserveByMint(collTokenMint);
216
-
217
- if (!collReserve) {
218
- throw new Error(`Collateral reserve with mint ${collTokenMint} not found in market ${kaminoMarket.getAddress()}`);
219
- }
220
-
221
- const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint);
222
-
223
- if (!debtReserve) {
224
- throw new Error(`Debt reserve with mint ${debtTokenMint} not found in market ${kaminoMarket.getAddress()}`);
225
- }
215
+ const collReserve = kaminoMarket.getReserveByMint(collTokenMint)!;
216
+ const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint)!;
226
217
 
227
218
  // the client should use these values to prevent this input, but the tx may succeed, so we don't want to fail
228
219
  // there is also a chance that the tx will consume debt token from the user's ata which they would not expect
@@ -257,7 +248,8 @@ export async function getRepayWithCollIxs<QuoteResponse>({
257
248
  swapResponse,
258
249
  isClosingPosition,
259
250
  debtRepayAmountLamports,
260
- swapInputs.inputAmountLamports
251
+ swapInputs.inputAmountLamports,
252
+ useV2Ixs
261
253
  );
262
254
 
263
255
  return {
@@ -280,7 +272,8 @@ async function buildRepayWithCollateralIxs(
280
272
  swapQuoteIxs: SwapIxs,
281
273
  isClosingPosition: boolean,
282
274
  debtRepayAmountLamports: Decimal,
283
- collWithdrawLamports: Decimal
275
+ collWithdrawLamports: Decimal,
276
+ useV2Ixs: boolean
284
277
  ): Promise<TransactionInstruction[]> {
285
278
  // 1. Create atas & budget txns
286
279
  const budgetIxns = budgetAndPriorityFeeIxs || getComputeBudgetAndPriorityFeeIxns(1_400_000);
@@ -310,12 +303,8 @@ async function buildRepayWithCollateralIxs(
310
303
 
311
304
  const requestElevationGroup = !isClosingPosition && obligation.state.elevationGroup !== 0;
312
305
 
313
- const maxWithdrawLtvCheck = getMaxWithdrawLtvCheck(obligation);
314
-
315
306
  // 3. Repay using the flash borrowed funds & withdraw collateral to swap and pay the flash loan
316
- const repayAndWithdrawAction = await (maxWithdrawLtvCheck === MaxWithdrawLtvCheck.MAX_LTV
317
- ? KaminoAction.buildRepayAndWithdrawTxns
318
- : KaminoAction.buildRepayAndWithdrawV2Txns)(
307
+ const repayAndWithdrawAction = await KaminoAction.buildRepayAndWithdrawTxns(
319
308
  market,
320
309
  isClosingPosition ? U64_MAX : debtRepayAmountLamports.toString(),
321
310
  debtReserve.getLiquidityMint(),
@@ -324,6 +313,7 @@ async function buildRepayWithCollateralIxs(
324
313
  obligation.state.owner,
325
314
  currentSlot,
326
315
  obligation,
316
+ useV2Ixs,
327
317
  0,
328
318
  false,
329
319
  requestElevationGroup,
@@ -347,9 +337,3 @@ async function buildRepayWithCollateralIxs(
347
337
  flashRepayIxn,
348
338
  ];
349
339
  }
350
-
351
- export const getMaxWithdrawLtvCheck = (obligation: KaminoObligation) => {
352
- return obligation.refreshedStats.userTotalBorrowBorrowFactorAdjusted.gte(obligation.refreshedStats.borrowLimit)
353
- ? MaxWithdrawLtvCheck.LIQUIDATION_THRESHOLD
354
- : MaxWithdrawLtvCheck.MAX_LTV;
355
- };
@@ -62,6 +62,7 @@ export interface SwapCollIxnsInputs<QuoteResponse> {
62
62
  currentSlot: number;
63
63
  budgetAndPriorityFeeIxns?: TransactionInstruction[];
64
64
  scopeRefresh?: ScopeRefresh;
65
+ useV2Ixs: boolean;
65
66
  quoter: SwapQuoteProvider<QuoteResponse>;
66
67
  swapper: SwapIxsProvider<QuoteResponse>;
67
68
  logger?: (msg: string, ...extra: any[]) => void;
@@ -81,6 +82,11 @@ export interface SwapCollIxnsOutputs<QuoteResponse> {
81
82
  */
82
83
  lookupTables: AddressLookupTableAccount[];
83
84
 
85
+ /**
86
+ * Whether the swap is using V2 instructions.
87
+ */
88
+ useV2Ixs: boolean;
89
+
84
90
  /**
85
91
  * Informational-only details of the token amounts/fees/rates that were used during construction of `ixs`.
86
92
  */
@@ -167,6 +173,7 @@ export async function getSwapCollIxns<QuoteResponse>(
167
173
  return {
168
174
  ixs: listIxns(klendIxns, externalSwapIxns.ixns),
169
175
  lookupTables: externalSwapIxns.luts,
176
+ useV2Ixs: context.useV2Ixs,
170
177
  simulationDetails: {
171
178
  flashLoan: {
172
179
  targetCollFlashBorrowedAmount: klendIxns.simulationDetails.targetCollFlashBorrowedAmount,
@@ -197,6 +204,7 @@ type SwapCollContext<QuoteResponse> = {
197
204
  swapper: SwapIxsProvider<QuoteResponse>;
198
205
  referrer: PublicKey;
199
206
  currentSlot: number;
207
+ useV2Ixs: boolean;
200
208
  scopeRefresh: ScopeRefresh | undefined;
201
209
  logger: (msg: string, ...extra: any[]) => void;
202
210
  };
@@ -229,6 +237,7 @@ function extractArgsAndContext<QuoteResponse>(
229
237
  referrer: inputs.referrer,
230
238
  scopeRefresh: inputs.scopeRefresh,
231
239
  currentSlot: inputs.currentSlot,
240
+ useV2Ixs: inputs.useV2Ixs,
232
241
  },
233
242
  ];
234
243
  }
@@ -370,6 +379,7 @@ async function getDepositTargetCollIxns(
370
379
  context.targetCollReserve.getLiquidityMint(),
371
380
  context.obligation.state.owner,
372
381
  context.obligation,
382
+ context.useV2Ixs,
373
383
  0, // no extra compute budget
374
384
  false, // we do not need ATA ixns here (we construct and close them ourselves)
375
385
  removesElevationGroup, // we may need to (temporarily) remove the elevation group; the same or a different one will be set on withdraw, if requested
@@ -419,6 +429,7 @@ async function getWithdrawSourceCollIxns(
419
429
  context.sourceCollReserve.getLiquidityMint(),
420
430
  context.obligation.state.owner,
421
431
  context.obligation,
432
+ context.useV2Ixs,
422
433
  0, // no extra compute budget
423
434
  false, // we do not need ATA ixns here (we construct and close them ourselves)
424
435
  requestedElevationGroup !== undefined, // the `elevationGroupIdToRequestAfterWithdraw()` has already decided on this
@@ -53,7 +53,7 @@ import {
53
53
  DepositLeverageInitialInputs,
54
54
  DepositWithLeverageProps,
55
55
  DepositWithLeverageSwapInputsProps,
56
- DepsoitLeverageIxsResponse,
56
+ DepositLeverageIxsResponse,
57
57
  PriceAinBProvider,
58
58
  SwapInputs,
59
59
  SwapIxs,
@@ -86,6 +86,7 @@ export async function getDepositWithLeverageSwapInputs<QuoteResponse>({
86
86
  priceAinB,
87
87
  isKtoken,
88
88
  quoter,
89
+ useV2Ixs,
89
90
  elevationGroupOverride,
90
91
  }: DepositWithLeverageSwapInputsProps<QuoteResponse>): Promise<{
91
92
  swapInputs: SwapInputs;
@@ -151,6 +152,7 @@ export async function getDepositWithLeverageSwapInputs<QuoteResponse>({
151
152
  },
152
153
  strategy,
153
154
  collIsKtoken,
155
+ useV2Ixs,
154
156
  elevationGroupOverride
155
157
  );
156
158
 
@@ -315,7 +317,8 @@ export async function getDepositWithLeverageIxns<QuoteResponse>({
315
317
  quoter,
316
318
  swapper,
317
319
  elevationGroupOverride,
318
- }: DepositWithLeverageProps<QuoteResponse>): Promise<DepsoitLeverageIxsResponse<QuoteResponse>> {
320
+ useV2Ixs,
321
+ }: DepositWithLeverageProps<QuoteResponse>): Promise<DepositLeverageIxsResponse<QuoteResponse>> {
319
322
  const { swapInputs, initialInputs } = await getDepositWithLeverageSwapInputs({
320
323
  owner,
321
324
  kaminoMarket,
@@ -337,6 +340,7 @@ export async function getDepositWithLeverageIxns<QuoteResponse>({
337
340
  priceAinB,
338
341
  isKtoken,
339
342
  quoter,
343
+ useV2Ixs,
340
344
  });
341
345
 
342
346
  let depositSwapper: SwapIxsProvider<QuoteResponse>;
@@ -392,6 +396,7 @@ export async function getDepositWithLeverageIxns<QuoteResponse>({
392
396
  },
393
397
  initialInputs.strategy,
394
398
  initialInputs.collIsKtoken,
399
+ useV2Ixs,
395
400
  elevationGroupOverride
396
401
  );
397
402
 
@@ -418,6 +423,7 @@ async function buildDepositWithLeverageIxns(
418
423
  swapQuoteIxs: SwapIxs,
419
424
  strategy: StrategyWithAddress | undefined,
420
425
  collIsKtoken: boolean,
426
+ useV2Ixs: boolean,
421
427
  elevationGroupOverride?: number
422
428
  ): Promise<TransactionInstruction[]> {
423
429
  const budgetIxns = budgetAndPriorityFeeIxs || getComputeBudgetAndPriorityFeeIxns(3000000);
@@ -530,6 +536,7 @@ async function buildDepositWithLeverageIxns(
530
536
  debtTokenMint,
531
537
  owner,
532
538
  obligation!,
539
+ useV2Ixs,
533
540
  0,
534
541
  false,
535
542
  elevationGroupOverride === 0 ? false : true, // emode
@@ -592,6 +599,7 @@ export async function getWithdrawWithLeverageSwapInputs<QuoteResponse>({
592
599
  quoteBufferBps,
593
600
  isKtoken,
594
601
  quoter,
602
+ useV2Ixs,
595
603
  }: WithdrawWithLeverageSwapInputsProps<QuoteResponse>): Promise<{
596
604
  swapInputs: SwapInputs;
597
605
  initialInputs: WithdrawLeverageInitialInputs<QuoteResponse>;
@@ -642,7 +650,8 @@ export async function getWithdrawWithLeverageSwapInputs<QuoteResponse>({
642
650
  lookupTables: [],
643
651
  },
644
652
  strategy,
645
- collIsKtoken
653
+ collIsKtoken,
654
+ useV2Ixs
646
655
  );
647
656
 
648
657
  const uniqueKlendAccounts = uniqueAccounts(klendIxs);
@@ -725,6 +734,7 @@ export async function getWithdrawWithLeverageIxns<QuoteResponse>({
725
734
  isKtoken,
726
735
  quoter,
727
736
  swapper,
737
+ useV2Ixs,
728
738
  }: WithdrawWithLeverageProps<QuoteResponse>): Promise<WithdrawLeverageIxsResponse<QuoteResponse>> {
729
739
  const collReserve = kaminoMarket.getReserveByMint(collTokenMint);
730
740
  const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint);
@@ -752,6 +762,7 @@ export async function getWithdrawWithLeverageIxns<QuoteResponse>({
752
762
  quoteBufferBps,
753
763
  isKtoken,
754
764
  quoter,
765
+ useV2Ixs,
755
766
  });
756
767
 
757
768
  let withdrawSwapper: SwapIxsProvider<QuoteResponse>;
@@ -802,7 +813,8 @@ export async function getWithdrawWithLeverageIxns<QuoteResponse>({
802
813
  lookupTables,
803
814
  },
804
815
  initialInputs.strategy,
805
- initialInputs.collIsKtoken
816
+ initialInputs.collIsKtoken,
817
+ useV2Ixs
806
818
  );
807
819
 
808
820
  // Send ixns and lookup tables
@@ -829,7 +841,8 @@ export async function buildWithdrawWithLeverageIxns(
829
841
  budgetAndPriorityFeeIxs: TransactionInstruction[] | undefined,
830
842
  swapQuoteIxs: SwapIxs,
831
843
  strategy: StrategyWithAddress | undefined,
832
- collIsKtoken: boolean
844
+ collIsKtoken: boolean,
845
+ useV2Ixs: boolean
833
846
  ): Promise<TransactionInstruction[]> {
834
847
  const collTokenMint = collReserve.getLiquidityMint();
835
848
  const debtTokenMint = debtReserve.getLiquidityMint();
@@ -941,6 +954,7 @@ export async function buildWithdrawWithLeverageIxns(
941
954
  owner,
942
955
  currentSlot,
943
956
  obligation,
957
+ useV2Ixs,
944
958
  0,
945
959
  false,
946
960
  false, // to be checked and created in a setup tx in the UI (won't be the case for withdraw anyway as this would be created in deposit)
@@ -986,6 +1000,7 @@ export async function getAdjustLeverageSwapInputs<QuoteResponse>({
986
1000
  quoteBufferBps,
987
1001
  isKtoken,
988
1002
  quoter,
1003
+ useV2Ixs,
989
1004
  }: AdjustLeverageSwapInputsProps<QuoteResponse>): Promise<{
990
1005
  swapInputs: SwapInputs;
991
1006
  initialInputs: AdjustLeverageInitialInputs<QuoteResponse>;
@@ -1051,7 +1066,8 @@ export async function getAdjustLeverageSwapInputs<QuoteResponse>({
1051
1066
  swapIxs: [],
1052
1067
  lookupTables: [],
1053
1068
  },
1054
- budgetAndPriorityFeeIxs
1069
+ budgetAndPriorityFeeIxs,
1070
+ useV2Ixs
1055
1071
  );
1056
1072
 
1057
1073
  const uniqueKlendAccounts = uniqueAccounts(klendIxs);
@@ -1154,7 +1170,8 @@ export async function getAdjustLeverageSwapInputs<QuoteResponse>({
1154
1170
  swapIxs: [],
1155
1171
  lookupTables: [],
1156
1172
  },
1157
- budgetAndPriorityFeeIxs
1173
+ budgetAndPriorityFeeIxs,
1174
+ useV2Ixs
1158
1175
  );
1159
1176
 
1160
1177
  const uniqueKlendAccounts = uniqueAccounts(klendIxs);
@@ -1240,6 +1257,7 @@ export async function getAdjustLeverageIxns<QuoteResponse>({
1240
1257
  isKtoken,
1241
1258
  quoter,
1242
1259
  swapper,
1260
+ useV2Ixs,
1243
1261
  }: AdjustLeverageProps<QuoteResponse>): Promise<AdjustLeverageIxsResponse<QuoteResponse>> {
1244
1262
  const { swapInputs, initialInputs } = await getAdjustLeverageSwapInputs({
1245
1263
  owner,
@@ -1262,6 +1280,7 @@ export async function getAdjustLeverageIxns<QuoteResponse>({
1262
1280
  priceAinB,
1263
1281
  isKtoken,
1264
1282
  quoter,
1283
+ useV2Ixs,
1265
1284
  });
1266
1285
 
1267
1286
  // leverage increased so we need to deposit and borrow more
@@ -1309,7 +1328,8 @@ export async function getAdjustLeverageIxns<QuoteResponse>({
1309
1328
  swapIxs,
1310
1329
  lookupTables,
1311
1330
  },
1312
- budgetAndPriorityFeeIxs
1331
+ budgetAndPriorityFeeIxs,
1332
+ useV2Ixs
1313
1333
  );
1314
1334
  return {
1315
1335
  ixs,
@@ -1355,7 +1375,8 @@ export async function getAdjustLeverageIxns<QuoteResponse>({
1355
1375
  swapIxs,
1356
1376
  lookupTables,
1357
1377
  },
1358
- budgetAndPriorityFeeIxs
1378
+ budgetAndPriorityFeeIxs,
1379
+ useV2Ixs
1359
1380
  );
1360
1381
 
1361
1382
  return {
@@ -1383,7 +1404,8 @@ async function buildIncreaseLeverageIxns(
1383
1404
  scopeFeed: string | undefined,
1384
1405
  collIsKtoken: boolean,
1385
1406
  swapQuoteIxs: SwapIxs,
1386
- budgetAndPriorityFeeIxns: TransactionInstruction[] | undefined
1407
+ budgetAndPriorityFeeIxns: TransactionInstruction[] | undefined,
1408
+ useV2Ixs: boolean
1387
1409
  ): Promise<TransactionInstruction[]> {
1388
1410
  const collReserve = kaminoMarket.getReserveByMint(collTokenMint);
1389
1411
  const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint);
@@ -1475,6 +1497,7 @@ async function buildIncreaseLeverageIxns(
1475
1497
  collTokenMint,
1476
1498
  owner,
1477
1499
  obligation,
1500
+ useV2Ixs,
1478
1501
  0,
1479
1502
  false,
1480
1503
  false,
@@ -1492,6 +1515,7 @@ async function buildIncreaseLeverageIxns(
1492
1515
  debtTokenMint,
1493
1516
  owner,
1494
1517
  obligation,
1518
+ useV2Ixs,
1495
1519
  0,
1496
1520
  false,
1497
1521
  false,
@@ -1551,7 +1575,8 @@ async function buildDecreaseLeverageIxns(
1551
1575
  scopeFeed: string | undefined,
1552
1576
  collIsKtoken: boolean,
1553
1577
  swapQuoteIxs: SwapIxs,
1554
- budgetAndPriorityFeeIxns: TransactionInstruction[] | undefined
1578
+ budgetAndPriorityFeeIxns: TransactionInstruction[] | undefined,
1579
+ useV2Ixs: boolean
1555
1580
  ): Promise<TransactionInstruction[]> {
1556
1581
  const collReserve = kaminoMarket.getReserveByMint(collTokenMint);
1557
1582
  const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint);
@@ -1651,6 +1676,7 @@ async function buildDecreaseLeverageIxns(
1651
1676
  debtTokenMint,
1652
1677
  owner,
1653
1678
  obligation,
1679
+ useV2Ixs,
1654
1680
  currentSlot,
1655
1681
  undefined,
1656
1682
  0,
@@ -1669,6 +1695,7 @@ async function buildDecreaseLeverageIxns(
1669
1695
  collTokenMint,
1670
1696
  owner,
1671
1697
  obligation,
1698
+ useV2Ixs,
1672
1699
  0,
1673
1700
  false,
1674
1701
  false,
@@ -49,7 +49,7 @@ export type KaminoDepositSwapOverride = (
49
49
  amountDebtAtaBalance: Decimal
50
50
  ) => Promise<InstructionsWithLookupTables>;
51
51
 
52
- export type DepsoitLeverageIxsResponse<QuoteResponse> = {
52
+ export type DepositLeverageIxsResponse<QuoteResponse> = {
53
53
  ixs: TransactionInstruction[];
54
54
  lookupTables: AddressLookupTableAccount[];
55
55
  swapInputs: SwapInputs;
@@ -90,6 +90,7 @@ export interface DepositWithLeverageSwapInputsProps<QuoteResponse> {
90
90
  // currently only used to disable requesting elevation group when this value is 0
91
91
  // to be implemented properly in the future
92
92
  elevationGroupOverride?: number;
93
+ useV2Ixs: boolean;
93
94
  }
94
95
 
95
96
  export interface DepositWithLeverageProps<QuoteResponse> extends DepositWithLeverageSwapInputsProps<QuoteResponse> {
@@ -146,6 +147,7 @@ export interface WithdrawWithLeverageSwapInputsProps<QuoteResponse> {
146
147
  quoteBufferBps: Decimal;
147
148
  isKtoken: IsKtokenProvider;
148
149
  quoter: SwapQuoteProvider<QuoteResponse>;
150
+ useV2Ixs: boolean;
149
151
  }
150
152
 
151
153
  export interface WithdrawWithLeverageProps<QuoteResponse> extends WithdrawWithLeverageSwapInputsProps<QuoteResponse> {
@@ -199,6 +201,7 @@ export interface AdjustLeverageSwapInputsProps<QuoteResponse> {
199
201
  priceAinB: PriceAinBProvider;
200
202
  isKtoken: IsKtokenProvider;
201
203
  quoter: SwapQuoteProvider<QuoteResponse>;
204
+ useV2Ixs: boolean;
202
205
  }
203
206
 
204
207
  export interface AdjustLeverageProps<QuoteResponse> extends AdjustLeverageSwapInputsProps<QuoteResponse> {