@kamino-finance/klend-sdk 5.13.1 → 5.13.4

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 (116) hide show
  1. package/dist/classes/action.d.ts +32 -31
  2. package/dist/classes/action.d.ts.map +1 -1
  3. package/dist/classes/action.js +126 -95
  4. package/dist/classes/action.js.map +1 -1
  5. package/dist/classes/index.d.ts +3 -2
  6. package/dist/classes/index.d.ts.map +1 -1
  7. package/dist/classes/index.js +3 -2
  8. package/dist/classes/index.js.map +1 -1
  9. package/dist/classes/manager.d.ts +15 -7
  10. package/dist/classes/manager.d.ts.map +1 -1
  11. package/dist/classes/manager.js +57 -46
  12. package/dist/classes/manager.js.map +1 -1
  13. package/dist/classes/obligationOrder.d.ts +1 -1
  14. package/dist/classes/obligationOrder.d.ts.map +1 -1
  15. package/dist/classes/reserve.d.ts +2 -2
  16. package/dist/classes/reserve.d.ts.map +1 -1
  17. package/dist/classes/reserve.js +70 -70
  18. package/dist/classes/reserve.js.map +1 -1
  19. package/dist/classes/shared.d.ts +13 -0
  20. package/dist/classes/shared.d.ts.map +1 -1
  21. package/dist/classes/utils.d.ts +1 -9
  22. package/dist/classes/utils.d.ts.map +1 -1
  23. package/dist/classes/utils.js +4 -51
  24. package/dist/classes/utils.js.map +1 -1
  25. package/dist/classes/vault.d.ts +22 -4
  26. package/dist/classes/vault.d.ts.map +1 -1
  27. package/dist/classes/vault.js +78 -43
  28. package/dist/classes/vault.js.map +1 -1
  29. package/dist/classes/{types.d.ts → vault_types.d.ts} +3 -15
  30. package/dist/classes/vault_types.d.ts.map +1 -0
  31. package/dist/classes/{types.js → vault_types.js} +1 -1
  32. package/dist/classes/vault_types.js.map +1 -0
  33. package/dist/client_kamino_manager.d.ts.map +1 -1
  34. package/dist/client_kamino_manager.js +44 -28
  35. package/dist/client_kamino_manager.js.map +1 -1
  36. package/dist/lending_operations/repay_with_collateral_operations.js +6 -6
  37. package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
  38. package/dist/lending_operations/swap_collateral_operations.d.ts +6 -6
  39. package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
  40. package/dist/lending_operations/swap_collateral_operations.js +61 -61
  41. package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
  42. package/dist/leverage/calcs.d.ts +0 -1
  43. package/dist/leverage/calcs.d.ts.map +1 -1
  44. package/dist/leverage/calcs.js +5 -8
  45. package/dist/leverage/calcs.js.map +1 -1
  46. package/dist/leverage/operations.d.ts +5 -5
  47. package/dist/leverage/operations.d.ts.map +1 -1
  48. package/dist/leverage/operations.js +73 -73
  49. package/dist/leverage/operations.js.map +1 -1
  50. package/dist/leverage/types.d.ts +1 -1
  51. package/dist/leverage/types.d.ts.map +1 -1
  52. package/dist/leverage/utils.d.ts +2 -2
  53. package/dist/leverage/utils.d.ts.map +1 -1
  54. package/dist/leverage/utils.js +5 -5
  55. package/dist/leverage/utils.js.map +1 -1
  56. package/dist/referrals/instructions.d.ts +3 -3
  57. package/dist/referrals/instructions.d.ts.map +1 -1
  58. package/dist/referrals/instructions.js +10 -10
  59. package/dist/referrals/instructions.js.map +1 -1
  60. package/dist/referrals/operations.js +6 -6
  61. package/dist/referrals/operations.js.map +1 -1
  62. package/dist/utils/ata.d.ts +3 -3
  63. package/dist/utils/ata.d.ts.map +1 -1
  64. package/dist/utils/ata.js +22 -22
  65. package/dist/utils/ata.js.map +1 -1
  66. package/dist/utils/instruction.d.ts +2 -2
  67. package/dist/utils/instruction.d.ts.map +1 -1
  68. package/dist/utils/instruction.js +12 -12
  69. package/dist/utils/instruction.js.map +1 -1
  70. package/dist/utils/lookupTable.js +6 -6
  71. package/dist/utils/lookupTable.js.map +1 -1
  72. package/dist/utils/metadata.d.ts +14 -0
  73. package/dist/utils/metadata.d.ts.map +1 -0
  74. package/dist/utils/metadata.js +78 -0
  75. package/dist/utils/metadata.js.map +1 -0
  76. package/dist/utils/seeds.d.ts +6 -0
  77. package/dist/utils/seeds.d.ts.map +1 -1
  78. package/dist/utils/seeds.js +10 -0
  79. package/dist/utils/seeds.js.map +1 -1
  80. package/dist/utils/userMetadata.d.ts +1 -1
  81. package/dist/utils/userMetadata.d.ts.map +1 -1
  82. package/dist/utils/userMetadata.js +3 -3
  83. package/dist/utils/userMetadata.js.map +1 -1
  84. package/package.json +1 -1
  85. package/src/classes/action.ts +143 -102
  86. package/src/classes/index.ts +5 -2
  87. package/src/classes/manager.ts +74 -51
  88. package/src/classes/obligationOrder.ts +1 -1
  89. package/src/classes/reserve.ts +126 -132
  90. package/src/classes/shared.ts +15 -0
  91. package/src/classes/utils.ts +3 -52
  92. package/src/classes/vault.ts +125 -44
  93. package/src/classes/{types.ts → vault_types.ts} +2 -16
  94. package/src/client.ts +16 -16
  95. package/src/client_kamino_manager.ts +59 -27
  96. package/src/lending_operations/repay_with_collateral_operations.ts +13 -13
  97. package/src/lending_operations/swap_collateral_operations.ts +85 -85
  98. package/src/leverage/calcs.ts +2 -6
  99. package/src/leverage/operations.ts +84 -84
  100. package/src/leverage/types.ts +1 -1
  101. package/src/leverage/utils.ts +5 -5
  102. package/src/referrals/instructions.ts +6 -6
  103. package/src/referrals/operations.ts +9 -9
  104. package/src/utils/ata.ts +18 -18
  105. package/src/utils/instruction.ts +10 -10
  106. package/src/utils/lookupTable.ts +6 -6
  107. package/src/utils/metadata.ts +115 -0
  108. package/src/utils/seeds.ts +13 -0
  109. package/src/utils/userMetadata.ts +1 -1
  110. package/dist/classes/types.d.ts.map +0 -1
  111. package/dist/classes/types.js.map +0 -1
  112. package/dist/classes/types_utils.d.ts +0 -14
  113. package/dist/classes/types_utils.d.ts.map +0 -1
  114. package/dist/classes/types_utils.js +0 -50
  115. package/dist/classes/types_utils.js.map +0 -1
  116. package/src/classes/types_utils.ts +0 -49
@@ -17,7 +17,7 @@ import {
17
17
  createAtasIdempotent,
18
18
  DEFAULT_MAX_COMPUTE_UNITS,
19
19
  getAssociatedTokenAddress,
20
- getComputeBudgetAndPriorityFeeIxns,
20
+ getComputeBudgetAndPriorityFeeIxs,
21
21
  PublicKeySet,
22
22
  ScopePriceRefreshConfig,
23
23
  U64_MAX,
@@ -28,9 +28,9 @@ import Decimal from 'decimal.js';
28
28
  import { createCloseAccountInstruction, NATIVE_MINT, TOKEN_PROGRAM_ID } from '@solana/spl-token';
29
29
 
30
30
  /**
31
- * Inputs to the `getSwapCollIxns()` operation.
31
+ * Inputs to the `getSwapCollIxs()` operation.
32
32
  */
33
- export interface SwapCollIxnsInputs<QuoteResponse> {
33
+ export interface SwapCollIxsInputs<QuoteResponse> {
34
34
  /**
35
35
  * The amount of source collateral to be swapped-in for the target collateral.
36
36
  * This value will be treated exactly (i.e. slippage is not applied here) and thus must not exceed the collateral's
@@ -66,7 +66,7 @@ export interface SwapCollIxnsInputs<QuoteResponse> {
66
66
  obligation: KaminoObligation;
67
67
  referrer: PublicKey;
68
68
  currentSlot: number;
69
- budgetAndPriorityFeeIxns?: TransactionInstruction[];
69
+ budgetAndPriorityFeeIxs?: TransactionInstruction[];
70
70
  scopeRefreshConfig?: ScopePriceRefreshConfig;
71
71
  useV2Ixs: boolean;
72
72
  quoter: SwapQuoteProvider<QuoteResponse>;
@@ -75,9 +75,9 @@ export interface SwapCollIxnsInputs<QuoteResponse> {
75
75
  }
76
76
 
77
77
  /**
78
- * Outputs from the `getSwapCollIxns()` operation.
78
+ * Outputs from the `getSwapCollIxs()` operation.
79
79
  */
80
- export interface SwapCollIxnsOutputs<QuoteResponse> {
80
+ export interface SwapCollIxsOutputs<QuoteResponse> {
81
81
  /**
82
82
  * Instructions for on-chain execution.
83
83
  */
@@ -143,12 +143,12 @@ export interface SwapCollIxnsOutputs<QuoteResponse> {
143
143
  /**
144
144
  * Constructs instructions needed to partially/fully swap the given source collateral for some other collateral type.
145
145
  */
146
- export async function getSwapCollIxns<QuoteResponse>(
147
- inputs: SwapCollIxnsInputs<QuoteResponse>
148
- ): Promise<SwapCollIxnsOutputs<QuoteResponse>> {
146
+ export async function getSwapCollIxs<QuoteResponse>(
147
+ inputs: SwapCollIxsInputs<QuoteResponse>
148
+ ): Promise<SwapCollIxsOutputs<QuoteResponse>> {
149
149
  const [args, context] = extractArgsAndContext(inputs);
150
150
 
151
- // Conceptually, we need to construct the following ixns:
151
+ // Conceptually, we need to construct the following ixs:
152
152
  // 0. any set-up, like budgeting and ATAs
153
153
  // 1. `flash-borrowed target coll = targetCollReserve.flashBorrow()`
154
154
  // 2. `targetCollReserve.deposit(flash-borrowed target coll)`
@@ -157,38 +157,38 @@ export async function getSwapCollIxns<QuoteResponse>(
157
157
  // 5. `flashRepay(externally-swapped target coll)`
158
158
  // However, there is a cyclic dependency:
159
159
  // - To construct 4. (specifically, to query the external swap quote), we need to know all accounts used by Kamino's
160
- // own ixns.
160
+ // own ixs.
161
161
  // - To construct 1. (i.e. flash-borrow), we need to know the target collateral swap-out from 4.
162
162
 
163
- // Construct the Klend's own ixns with a fake swap-out (only to learn the klend accounts used):
164
- const fakeKlendIxns = await getKlendIxns(args, FAKE_TARGET_COLL_SWAP_OUT_AMOUNT, context);
165
- const klendAccounts = uniqueAccountsWithProgramIds(listIxns(fakeKlendIxns));
163
+ // Construct the Klend's own ixs with a fake swap-out (only to learn the klend accounts used):
164
+ const fakeKlendIxs = await getKlendIxs(args, FAKE_TARGET_COLL_SWAP_OUT_AMOUNT, context);
165
+ const klendAccounts = uniqueAccountsWithProgramIds(listIxs(fakeKlendIxs));
166
166
 
167
- // Construct the external swap ixns (and learn the actual swap-out amount):
168
- const externalSwapIxns = await getExternalSwapIxns(args, klendAccounts, context);
167
+ // Construct the external swap ixs (and learn the actual swap-out amount):
168
+ const externalSwapIxs = await getExternalSwapIxs(args, klendAccounts, context);
169
169
 
170
170
  // We now have the full information needed to simulate the end-state, so let's check that the operation is legal:
171
171
  context.logger(
172
- `Expected to swap ${args.sourceCollSwapAmount} ${context.sourceCollReserve.symbol} collateral into ${externalSwapIxns.swapOutAmount} ${context.targetCollReserve.symbol} collateral`
172
+ `Expected to swap ${args.sourceCollSwapAmount} ${context.sourceCollReserve.symbol} collateral into ${externalSwapIxs.swapOutAmount} ${context.targetCollReserve.symbol} collateral`
173
173
  );
174
- checkResultingObligationValid(args, externalSwapIxns.swapOutAmount, context);
174
+ checkResultingObligationValid(args, externalSwapIxs.swapOutAmount, context);
175
175
 
176
- // Construct the Klend's own ixns with an actual swap-out amount:
177
- const klendIxns = await getKlendIxns(args, externalSwapIxns.swapOutAmount, context);
176
+ // Construct the Klend's own ixs with an actual swap-out amount:
177
+ const klendIxs = await getKlendIxs(args, externalSwapIxs.swapOutAmount, context);
178
178
 
179
179
  return {
180
- ixs: listIxns(klendIxns, externalSwapIxns.ixns),
181
- lookupTables: externalSwapIxns.luts,
180
+ ixs: listIxs(klendIxs, externalSwapIxs.ixs),
181
+ lookupTables: externalSwapIxs.luts,
182
182
  useV2Ixs: context.useV2Ixs,
183
183
  simulationDetails: {
184
184
  flashLoan: {
185
- targetCollFlashBorrowedAmount: klendIxns.simulationDetails.targetCollFlashBorrowedAmount,
186
- targetCollFlashRepaidAmount: externalSwapIxns.swapOutAmount,
185
+ targetCollFlashBorrowedAmount: klendIxs.simulationDetails.targetCollFlashBorrowedAmount,
186
+ targetCollFlashRepaidAmount: externalSwapIxs.swapOutAmount,
187
187
  },
188
188
  externalSwap: {
189
189
  sourceCollSwapInAmount: args.sourceCollSwapAmount, // repeated `/inputs.sourceCollSwapAmount`, only for clarity
190
- targetCollSwapOutAmount: externalSwapIxns.swapOutAmount, // repeated `../flashLoan.targetCollFlashRepaidAmount`, only for clarity
191
- quoteResponse: externalSwapIxns.simulationDetails.quoteResponse,
190
+ targetCollSwapOutAmount: externalSwapIxs.swapOutAmount, // repeated `../flashLoan.targetCollFlashRepaidAmount`, only for clarity
191
+ quoteResponse: externalSwapIxs.simulationDetails.quoteResponse,
192
192
  },
193
193
  },
194
194
  };
@@ -201,7 +201,7 @@ type SwapCollArgs = {
201
201
  };
202
202
 
203
203
  type SwapCollContext<QuoteResponse> = {
204
- budgetAndPriorityFeeIxns: TransactionInstruction[];
204
+ budgetAndPriorityFeeIxs: TransactionInstruction[];
205
205
  market: KaminoMarket;
206
206
  sourceCollReserve: KaminoReserve;
207
207
  targetCollReserve: KaminoReserve;
@@ -216,7 +216,7 @@ type SwapCollContext<QuoteResponse> = {
216
216
  };
217
217
 
218
218
  function extractArgsAndContext<QuoteResponse>(
219
- inputs: SwapCollIxnsInputs<QuoteResponse>
219
+ inputs: SwapCollIxsInputs<QuoteResponse>
220
220
  ): [SwapCollArgs, SwapCollContext<QuoteResponse>] {
221
221
  if (inputs.sourceCollTokenMint.equals(inputs.targetCollTokenMint)) {
222
222
  throw new Error(`Cannot swap from/to the same collateral`);
@@ -231,8 +231,8 @@ function extractArgsAndContext<QuoteResponse>(
231
231
  newElevationGroup: inputs.market.getExistingElevationGroup(inputs.newElevationGroup, 'Newly-requested'),
232
232
  },
233
233
  {
234
- budgetAndPriorityFeeIxns:
235
- inputs.budgetAndPriorityFeeIxns || getComputeBudgetAndPriorityFeeIxns(DEFAULT_MAX_COMPUTE_UNITS),
234
+ budgetAndPriorityFeeIxs:
235
+ inputs.budgetAndPriorityFeeIxs || getComputeBudgetAndPriorityFeeIxs(DEFAULT_MAX_COMPUTE_UNITS),
236
236
  sourceCollReserve: inputs.market.getExistingReserveByMint(inputs.sourceCollTokenMint, 'Current collateral'),
237
237
  targetCollReserve: inputs.market.getExistingReserveByMint(inputs.targetCollTokenMint, 'Target collateral'),
238
238
  logger: console.log,
@@ -248,28 +248,28 @@ function extractArgsAndContext<QuoteResponse>(
248
248
  ];
249
249
  }
250
250
 
251
- const FAKE_TARGET_COLL_SWAP_OUT_AMOUNT = new Decimal(1); // see the lengthy `getSwapCollIxns()` impl comment
251
+ const FAKE_TARGET_COLL_SWAP_OUT_AMOUNT = new Decimal(1); // see the lengthy `getSwapCollIxs()` impl comment
252
252
 
253
- type SwapCollKlendIxns = {
254
- setupIxns: TransactionInstruction[];
253
+ type SwapCollKlendIxs = {
254
+ setupIxs: TransactionInstruction[];
255
255
  targetCollFlashBorrowIxn: TransactionInstruction;
256
- depositTargetCollIxns: TransactionInstruction[];
257
- withdrawSourceCollIxns: TransactionInstruction[];
256
+ depositTargetCollIxs: TransactionInstruction[];
257
+ withdrawSourceCollIxs: TransactionInstruction[];
258
258
  targetCollFlashRepayIxn: TransactionInstruction;
259
- cleanupIxns: TransactionInstruction[];
259
+ cleanupIxs: TransactionInstruction[];
260
260
  flashLoanInfo: FlashLoanInfo;
261
261
  simulationDetails: {
262
262
  targetCollFlashBorrowedAmount: Decimal;
263
263
  };
264
264
  };
265
265
 
266
- async function getKlendIxns(
266
+ async function getKlendIxs(
267
267
  args: SwapCollArgs,
268
268
  targetCollSwapOutAmount: Decimal,
269
269
  context: SwapCollContext<any>
270
- ): Promise<SwapCollKlendIxns> {
271
- const { ataCreationIxns, targetCollAta } = getAtaCreationIxns(context);
272
- const setupIxns = [...context.budgetAndPriorityFeeIxns, ...ataCreationIxns];
270
+ ): Promise<SwapCollKlendIxs> {
271
+ const { ataCreationIxs, targetCollAta } = getAtaCreationIxs(context);
272
+ const setupIxs = [...context.budgetAndPriorityFeeIxs, ...ataCreationIxs];
273
273
 
274
274
  const scopeRefreshIxn = await getScopeRefreshIx(
275
275
  context.market,
@@ -280,37 +280,37 @@ async function getKlendIxns(
280
280
  );
281
281
 
282
282
  if (scopeRefreshIxn) {
283
- setupIxns.unshift(...scopeRefreshIxn);
283
+ setupIxs.unshift(...scopeRefreshIxn);
284
284
  }
285
285
 
286
286
  const targetCollFlashBorrowedAmount = calculateTargetCollFlashBorrowedAmount(targetCollSwapOutAmount, context);
287
- const { targetCollFlashBorrowIxn, targetCollFlashRepayIxn } = getTargetCollFlashLoanIxns(
287
+ const { targetCollFlashBorrowIxn, targetCollFlashRepayIxn } = getTargetCollFlashLoanIxs(
288
288
  targetCollFlashBorrowedAmount,
289
- setupIxns.length,
289
+ setupIxs.length,
290
290
  targetCollAta,
291
291
  context
292
292
  );
293
293
 
294
- const depositTargetCollIxns = await getDepositTargetCollIxns(targetCollFlashBorrowedAmount, context);
295
- const withdrawSourceCollIxns = await getWithdrawSourceCollIxns(
294
+ const depositTargetCollIxs = await getDepositTargetCollIxs(targetCollFlashBorrowedAmount, context);
295
+ const withdrawSourceCollIxs = await getWithdrawSourceCollIxs(
296
296
  args,
297
- depositTargetCollIxns.removesElevationGroup,
297
+ depositTargetCollIxs.removesElevationGroup,
298
298
  context
299
299
  );
300
300
 
301
- const cleanupIxns = getAtaCloseIxns(context);
301
+ const cleanupIxs = getAtaCloseIxs(context);
302
302
 
303
303
  return {
304
- setupIxns,
304
+ setupIxs,
305
305
  flashLoanInfo: {
306
306
  flashBorrowReserve: context.targetCollReserve.address,
307
307
  flashLoanFee: context.targetCollReserve.getFlashLoanFee(),
308
308
  },
309
309
  targetCollFlashBorrowIxn,
310
- depositTargetCollIxns: depositTargetCollIxns.ixns,
311
- withdrawSourceCollIxns,
310
+ depositTargetCollIxs: depositTargetCollIxs.ixs,
311
+ withdrawSourceCollIxs,
312
312
  targetCollFlashRepayIxn,
313
- cleanupIxns,
313
+ cleanupIxs,
314
314
  simulationDetails: {
315
315
  targetCollFlashBorrowedAmount,
316
316
  },
@@ -332,8 +332,8 @@ function calculateTargetCollFlashBorrowedAmount(
332
332
  return targetCollFlashRepaidAmount.sub(targetCollFlashLoanFee);
333
333
  }
334
334
 
335
- function getAtaCreationIxns(context: SwapCollContext<any>) {
336
- const atasAndAtaCreationIxns = createAtasIdempotent(context.obligation.state.owner, [
335
+ function getAtaCreationIxs(context: SwapCollContext<any>) {
336
+ const atasAndAtaCreationIxs = createAtasIdempotent(context.obligation.state.owner, [
337
337
  {
338
338
  mint: context.sourceCollReserve.getLiquidityMint(),
339
339
  tokenProgram: context.sourceCollReserve.getLiquidityTokenProgram(),
@@ -344,25 +344,25 @@ function getAtaCreationIxns(context: SwapCollContext<any>) {
344
344
  },
345
345
  ]);
346
346
  return {
347
- ataCreationIxns: atasAndAtaCreationIxns.map((tuple) => tuple.createAtaIx),
348
- targetCollAta: atasAndAtaCreationIxns[1].ata,
347
+ ataCreationIxs: atasAndAtaCreationIxs.map((tuple) => tuple.createAtaIx),
348
+ targetCollAta: atasAndAtaCreationIxs[1].ata,
349
349
  };
350
350
  }
351
351
 
352
- function getAtaCloseIxns(context: SwapCollContext<any>) {
353
- const ataCloseIxns: TransactionInstruction[] = [];
352
+ function getAtaCloseIxs(context: SwapCollContext<any>) {
353
+ const ataCloseIxs: TransactionInstruction[] = [];
354
354
  if (
355
355
  context.sourceCollReserve.getLiquidityMint().equals(NATIVE_MINT) ||
356
356
  context.targetCollReserve.getLiquidityMint().equals(NATIVE_MINT)
357
357
  ) {
358
358
  const owner = context.obligation.state.owner;
359
359
  const wsolAta = getAssociatedTokenAddress(NATIVE_MINT, owner, false);
360
- ataCloseIxns.push(createCloseAccountInstruction(wsolAta, owner, owner, [], TOKEN_PROGRAM_ID));
360
+ ataCloseIxs.push(createCloseAccountInstruction(wsolAta, owner, owner, [], TOKEN_PROGRAM_ID));
361
361
  }
362
- return ataCloseIxns;
362
+ return ataCloseIxs;
363
363
  }
364
364
 
365
- function getTargetCollFlashLoanIxns(
365
+ function getTargetCollFlashLoanIxs(
366
366
  targetCollAmount: Decimal,
367
367
  flashBorrowIxnIndex: number,
368
368
  destinationAta: PublicKey,
@@ -386,15 +386,15 @@ function getTargetCollFlashLoanIxns(
386
386
  return { targetCollFlashBorrowIxn, targetCollFlashRepayIxn };
387
387
  }
388
388
 
389
- type DepositTargetCollIxns = {
389
+ type DepositTargetCollIxs = {
390
390
  removesElevationGroup: boolean;
391
- ixns: TransactionInstruction[];
391
+ ixs: TransactionInstruction[];
392
392
  };
393
393
 
394
- async function getDepositTargetCollIxns(
394
+ async function getDepositTargetCollIxs(
395
395
  targetCollAmount: Decimal,
396
396
  context: SwapCollContext<any>
397
- ): Promise<DepositTargetCollIxns> {
397
+ ): Promise<DepositTargetCollIxs> {
398
398
  const removesElevationGroup = mustRemoveElevationGroupBeforeDeposit(context);
399
399
  const depositCollAction = await KaminoAction.buildDepositTxns(
400
400
  context.market,
@@ -403,9 +403,9 @@ async function getDepositTargetCollIxns(
403
403
  context.obligation.state.owner,
404
404
  context.obligation,
405
405
  context.useV2Ixs,
406
- undefined, // we create the scope refresh ixn outside of KaminoAction
406
+ undefined, // we create the scope refresh ix outside of KaminoAction
407
407
  0, // no extra compute budget
408
- false, // we do not need ATA ixns here (we construct and close them ourselves)
408
+ false, // we do not need ATA ixs here (we construct and close them ourselves)
409
409
  removesElevationGroup, // we may need to (temporarily) remove the elevation group; the same or a different one will be set on withdraw, if requested
410
410
  { skipInitialization: true, skipLutCreation: true }, // we are dealing with an existing obligation, no need to create user metadata
411
411
  context.referrer,
@@ -413,7 +413,7 @@ async function getDepositTargetCollIxns(
413
413
  removesElevationGroup ? 0 : undefined // only applicable when removing the group
414
414
  );
415
415
  return {
416
- ixns: KaminoAction.actionToIxs(depositCollAction),
416
+ ixs: KaminoAction.actionToIxs(depositCollAction),
417
417
  removesElevationGroup,
418
418
  };
419
419
  }
@@ -436,7 +436,7 @@ function mustRemoveElevationGroupBeforeDeposit(context: SwapCollContext<any>): b
436
436
  return false; // the obligation has some elevation group and the new collateral can be added to it
437
437
  }
438
438
 
439
- async function getWithdrawSourceCollIxns(
439
+ async function getWithdrawSourceCollIxs(
440
440
  args: SwapCollArgs,
441
441
  depositRemovedElevationGroup: boolean,
442
442
  context: SwapCollContext<any>
@@ -452,9 +452,9 @@ async function getWithdrawSourceCollIxns(
452
452
  context.obligation.state.owner,
453
453
  context.obligation,
454
454
  context.useV2Ixs,
455
- undefined, // we create the scope refresh ixn outside of KaminoAction
455
+ undefined, // we create the scope refresh ix outside of KaminoAction
456
456
  0, // no extra compute budget
457
- false, // we do not need ATA ixns here (we construct and close them ourselves)
457
+ false, // we do not need ATA ixs here (we construct and close them ourselves)
458
458
  requestedElevationGroup !== undefined, // the `elevationGroupIdToRequestAfterWithdraw()` has already decided on this
459
459
  { skipInitialization: true, skipLutCreation: true }, // we are dealing with an existing obligation, no need to create user metadata
460
460
  context.referrer,
@@ -497,20 +497,20 @@ function elevationGroupIdToRequestAfterWithdraw(
497
497
  }
498
498
  }
499
499
 
500
- type ExternalSwapIxns<QuoteResponse> = {
500
+ type ExternalSwapIxs<QuoteResponse> = {
501
501
  swapOutAmount: Decimal;
502
- ixns: TransactionInstruction[];
502
+ ixs: TransactionInstruction[];
503
503
  luts: AddressLookupTableAccount[];
504
504
  simulationDetails: {
505
505
  quoteResponse?: QuoteResponse;
506
506
  };
507
507
  };
508
508
 
509
- async function getExternalSwapIxns<QuoteResponse>(
509
+ async function getExternalSwapIxs<QuoteResponse>(
510
510
  args: SwapCollArgs,
511
511
  klendAccounts: PublicKey[],
512
512
  context: SwapCollContext<QuoteResponse>
513
- ): Promise<ExternalSwapIxns<QuoteResponse>> {
513
+ ): Promise<ExternalSwapIxs<QuoteResponse>> {
514
514
  const externalSwapInputs = {
515
515
  inputAmountLamports: args.sourceCollSwapAmount.mul(context.sourceCollReserve.getMintFactor()),
516
516
  inputMint: context.sourceCollReserve.getLiquidityMint(),
@@ -519,12 +519,12 @@ async function getExternalSwapIxns<QuoteResponse>(
519
519
  };
520
520
  const externalSwapQuote = await context.quoter(externalSwapInputs, klendAccounts);
521
521
  const swapOutAmount = externalSwapQuote.priceAInB.mul(args.sourceCollSwapAmount);
522
- const externalSwapIxnsAndLuts = await context.swapper(externalSwapInputs, klendAccounts, externalSwapQuote);
522
+ const externalSwapIxsAndLuts = await context.swapper(externalSwapInputs, klendAccounts, externalSwapQuote);
523
523
  // Note: we can ignore the returned `preActionIxs` field - we do not request any of them from the swapper.
524
524
  return {
525
525
  swapOutAmount,
526
- ixns: externalSwapIxnsAndLuts.swapIxs,
527
- luts: externalSwapIxnsAndLuts.lookupTables,
526
+ ixs: externalSwapIxsAndLuts.swapIxs,
527
+ luts: externalSwapIxsAndLuts.lookupTables,
528
528
  simulationDetails: {
529
529
  quoteResponse: externalSwapQuote.quoteResponse,
530
530
  },
@@ -606,14 +606,14 @@ function checkResultingObligationValid(
606
606
  }
607
607
  }
608
608
 
609
- function listIxns(klendIxns: SwapCollKlendIxns, externalSwapIxns?: TransactionInstruction[]): TransactionInstruction[] {
609
+ function listIxs(klendIxs: SwapCollKlendIxs, externalSwapIxs?: TransactionInstruction[]): TransactionInstruction[] {
610
610
  return [
611
- ...klendIxns.setupIxns,
612
- klendIxns.targetCollFlashBorrowIxn,
613
- ...klendIxns.depositTargetCollIxns,
614
- ...klendIxns.withdrawSourceCollIxns,
615
- ...(externalSwapIxns || []),
616
- klendIxns.targetCollFlashRepayIxn,
617
- ...klendIxns.cleanupIxns,
611
+ ...klendIxs.setupIxs,
612
+ klendIxs.targetCollFlashBorrowIxn,
613
+ ...klendIxs.depositTargetCollIxs,
614
+ ...klendIxs.withdrawSourceCollIxs,
615
+ ...(externalSwapIxs || []),
616
+ klendIxs.targetCollFlashRepayIxn,
617
+ ...klendIxs.cleanupIxs,
618
618
  ];
619
619
  }
@@ -1,7 +1,7 @@
1
1
  import { PublicKey } from '@solana/web3.js';
2
2
  import Decimal from 'decimal.js';
3
3
  import { collToLamportsDecimal, Kamino, StrategyWithAddress, TokenAmounts } from '@kamino-finance/kliquidity-sdk';
4
- import { KaminoMarket, KaminoObligation, KaminoReserve } from '../classes';
4
+ import { KaminoMarket, KaminoObligation, KaminoReserve, toJson } from '../classes';
5
5
  import { getExpectedTokenBalanceAfterBorrow } from './utils';
6
6
  import {
7
7
  AdjustLeverageCalcsResult,
@@ -11,10 +11,6 @@ import {
11
11
  } from './types';
12
12
  import { fuzzyEqual } from '../utils';
13
13
 
14
- export const toJson = (object: any): string => {
15
- return JSON.stringify(object, null, 2);
16
- };
17
-
18
14
  const closingPositionDiffTolerance = 0.0001;
19
15
 
20
16
  export enum FormTabs {
@@ -683,7 +679,7 @@ export function withdrawLeverageCalcs(
683
679
  .mul(irSlippageBpsForDebt.add('0.1').div('10_000').add('1'))
684
680
  .toDecimalPlaces(debtReserve?.state.liquidity.mintDecimals.toNumber()!, Decimal.ROUND_CEIL);
685
681
 
686
- // 6. Get swap ixns
682
+ // 6. Get swap ixs
687
683
  // 5. Get swap estimations to understand how much we need to borrow from borrow reserve
688
684
  // prevent withdrawing more then deposited if we close position
689
685
  const depositTokenWithdrawAmount = !isClosingPosition