@kamino-finance/klend-sdk 5.10.35-beta.0 → 5.10.35-beta.1

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 +26 -24
  2. package/dist/classes/action.d.ts.map +1 -1
  3. package/dist/classes/action.js +270 -501
  4. package/dist/classes/action.js.map +1 -1
  5. package/dist/classes/manager.js +1 -1
  6. package/dist/classes/manager.js.map +1 -1
  7. package/dist/classes/obligation.d.ts +1 -1
  8. package/dist/classes/obligation.d.ts.map +1 -1
  9. package/dist/classes/obligation.js +1 -1
  10. package/dist/classes/obligation.js.map +1 -1
  11. package/dist/classes/vault.js +6 -6
  12. package/dist/classes/vault.js.map +1 -1
  13. package/dist/lending_operations/repay_with_collateral_calcs.d.ts.map +1 -1
  14. package/dist/lending_operations/repay_with_collateral_calcs.js +9 -5
  15. package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
  16. package/dist/lending_operations/repay_with_collateral_operations.d.ts +7 -3
  17. package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
  18. package/dist/lending_operations/repay_with_collateral_operations.js +27 -7
  19. package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
  20. package/dist/lending_operations/swap_collateral_operations.d.ts +0 -5
  21. package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
  22. package/dist/lending_operations/swap_collateral_operations.js +2 -4
  23. package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
  24. package/dist/leverage/operations.d.ts +8 -8
  25. package/dist/leverage/operations.d.ts.map +1 -1
  26. package/dist/leverage/operations.js +24 -27
  27. package/dist/leverage/operations.js.map +1 -1
  28. package/dist/leverage/types.d.ts +1 -4
  29. package/dist/leverage/types.d.ts.map +1 -1
  30. package/dist/utils/lookupTable.d.ts +27 -0
  31. package/dist/utils/lookupTable.d.ts.map +1 -1
  32. package/dist/utils/lookupTable.js +58 -0
  33. package/dist/utils/lookupTable.js.map +1 -1
  34. package/dist/utils/seeds.d.ts +9 -3
  35. package/dist/utils/seeds.d.ts.map +1 -1
  36. package/dist/utils/seeds.js +11 -5
  37. package/dist/utils/seeds.js.map +1 -1
  38. package/dist/utils/userMetadata.js +6 -6
  39. package/dist/utils/userMetadata.js.map +1 -1
  40. package/package.json +1 -4
  41. package/src/classes/action.ts +423 -662
  42. package/src/classes/manager.ts +1 -1
  43. package/src/classes/obligation.ts +1 -1
  44. package/src/classes/vault.ts +1 -1
  45. package/src/client.ts +3 -7
  46. package/src/lending_operations/repay_with_collateral_calcs.ts +14 -5
  47. package/src/lending_operations/repay_with_collateral_operations.ts +30 -14
  48. package/src/lending_operations/swap_collateral_operations.ts +0 -11
  49. package/src/leverage/operations.ts +11 -38
  50. package/src/leverage/types.ts +1 -4
  51. package/src/utils/lookupTable.ts +62 -0
  52. package/src/utils/seeds.ts +12 -7
  53. package/src/utils/userMetadata.ts +14 -14
  54. package/dist/classes/lut_utils.d.ts +0 -29
  55. package/dist/classes/lut_utils.d.ts.map +0 -1
  56. package/dist/classes/lut_utils.js +0 -62
  57. package/dist/classes/lut_utils.js.map +0 -1
  58. package/src/classes/lut_utils.ts +0 -63
@@ -180,7 +180,7 @@ class KaminoAction {
180
180
  axn.addRequestElevationIx(elevationGroup, 'setup');
181
181
  return axn;
182
182
  }
183
- static async buildDepositTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
183
+ static async buildDepositTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
184
184
  includeAtaIxns = true, // if true it includes create and close wsol and token atas,
185
185
  requestElevationGroup = false, // to be requested *before* the deposit
186
186
  includeUserMetadata = true, // if true it includes user metadata
@@ -200,13 +200,8 @@ class KaminoAction {
200
200
  if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
201
201
  await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
202
202
  }
203
- await axn.addSupportIxs('deposit', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, createLookupTable, undefined, overrideElevationGroupRequest);
204
- if (useV2Ixs) {
205
- axn.addDepositIxV2();
206
- }
207
- else {
208
- axn.addDepositIx();
209
- }
203
+ await axn.addSupportIxs('deposit', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, false, createLookupTable, undefined, overrideElevationGroupRequest);
204
+ axn.addDepositIx();
210
205
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
211
206
  return axn;
212
207
  }
@@ -238,7 +233,7 @@ class KaminoAction {
238
233
  feed: feed,
239
234
  }, tokens));
240
235
  }
241
- static async buildBorrowTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
236
+ static async buildBorrowTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
242
237
  includeAtaIxns = true, // if true it includes create and close wsol and token atas,
243
238
  requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
244
239
  createLookupTable = true, referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }, overrideElevationGroupRequest = undefined // if set, when an elevationgroup request is made, it will use this value
@@ -257,13 +252,8 @@ class KaminoAction {
257
252
  if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
258
253
  await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
259
254
  }
260
- await axn.addSupportIxs('borrow', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, createLookupTable, undefined, overrideElevationGroupRequest);
261
- if (useV2Ixs) {
262
- axn.addBorrowIxV2();
263
- }
264
- else {
265
- axn.addBorrowIx();
266
- }
255
+ await axn.addSupportIxs('borrow', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, false, createLookupTable, undefined, overrideElevationGroupRequest);
256
+ axn.addBorrowIx();
267
257
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
268
258
  return axn;
269
259
  }
@@ -311,7 +301,7 @@ class KaminoAction {
311
301
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
312
302
  return axn;
313
303
  }
314
- static async buildDepositObligationCollateralTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
304
+ static async buildDepositObligationCollateralTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
315
305
  includeAtaIxns = true, // if true it includes create and close wsol and token atas
316
306
  requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
317
307
  createLookupTable = true, referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
@@ -329,17 +319,12 @@ class KaminoAction {
329
319
  if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
330
320
  await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
331
321
  }
332
- await axn.addSupportIxs('depositCollateral', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, createLookupTable);
333
- if (useV2Ixs) {
334
- axn.addDepositObligationCollateralIxV2();
335
- }
336
- else {
337
- axn.addDepositObligationCollateralIx();
338
- }
322
+ await axn.addSupportIxs('depositCollateral', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, false, createLookupTable);
323
+ axn.addDepositObligationCollateralIx();
339
324
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
340
325
  return axn;
341
326
  }
342
- static async buildDepositAndBorrowTxns(kaminoMarket, depositAmount, depositMint, borrowAmount, borrowMint, payer, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
327
+ static async buildDepositAndBorrowTxns(kaminoMarket, depositAmount, depositMint, borrowAmount, borrowMint, payer, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
343
328
  includeAtaIxns = true, // if true it includes create and close wsol and token atas,
344
329
  requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata,
345
330
  createLookupTable = true, referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
@@ -360,18 +345,63 @@ class KaminoAction {
360
345
  if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
361
346
  await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
362
347
  }
363
- await axn.addSupportIxs('deposit', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarmForDeposit, useV2Ixs, createLookupTable, twoTokenAction);
364
- if (useV2Ixs) {
365
- await axn.addDepositAndBorrowIxV2();
348
+ await axn.addSupportIxs('deposit', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarmForDeposit, false, createLookupTable, twoTokenAction);
349
+ axn.addDepositAndBorrowIx();
350
+ await axn.addInBetweenIxs('depositAndBorrow', includeAtaIxns, requestElevationGroup, addInitObligationForFarmForBorrow);
351
+ axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
352
+ return axn;
353
+ }
354
+ static async buildDepositAndWithdrawV2Txns(kaminoMarket, depositAmount, depositMint, withdrawAmount, withdrawMint, payer, currentSlot, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
355
+ includeAtaIxns = true, // if true it includes create and close wsol and token atas,
356
+ requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata,
357
+ referrer = web3_js_1.PublicKey.default, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
358
+ const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'depositAndWithdraw', depositAmount, depositMint, withdrawMint, payer, payer, obligation, withdrawAmount, referrer, currentSlot);
359
+ const addInitObligationForFarm = true;
360
+ const twoTokenAction = true;
361
+ if (extraComputeBudget > 0) {
362
+ axn.addComputeBudgetIxn(extraComputeBudget);
366
363
  }
367
- else {
368
- await axn.addDepositAndBorrowIx();
364
+ const allReserves = new utils_1.PublicKeySet([
365
+ ...axn.depositReserves,
366
+ ...axn.borrowReserves,
367
+ axn.reserve.address,
368
+ axn.outflowReserve.address,
369
+ ]).toArray();
370
+ const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
371
+ if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
372
+ await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
369
373
  }
370
- await axn.addInBetweenIxs('depositAndBorrow', includeAtaIxns, requestElevationGroup, addInitObligationForFarmForBorrow, useV2Ixs);
371
- axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
374
+ await axn.addSupportIxs('depositAndWithdraw', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, true, twoTokenAction);
375
+ const withdrawCollateralAmount = axn.getWithdrawCollateralAmount(axn.outflowReserve, axn.outflowAmount);
376
+ axn.addDepositAndWithdrawV2Ixs(withdrawCollateralAmount);
372
377
  return axn;
373
378
  }
374
- static async buildRepayAndWithdrawTxns(kaminoMarket, repayAmount, repayMint, withdrawAmount, withdrawMint, payer, currentSlot, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
379
+ static async buildRepayAndWithdrawV2Txns(kaminoMarket, repayAmount, repayMint, withdrawAmount, withdrawMint, payer, currentSlot, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
380
+ includeAtaIxns = true, // if true it includes create and close wsol and token atas,
381
+ requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata,
382
+ createLookupTable = true, referrer = web3_js_1.PublicKey.default, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
383
+ const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'repayAndWithdrawV2', repayAmount, repayMint, withdrawMint, payer, payer, obligation, withdrawAmount, referrer, currentSlot);
384
+ const addInitObligationForFarm = true;
385
+ const twoTokenAction = true;
386
+ if (extraComputeBudget > 0) {
387
+ axn.addComputeBudgetIxn(extraComputeBudget);
388
+ }
389
+ const allReserves = new utils_1.PublicKeySet([
390
+ ...axn.depositReserves,
391
+ ...axn.borrowReserves,
392
+ axn.reserve.address,
393
+ axn.outflowReserve.address,
394
+ ]).toArray();
395
+ const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
396
+ if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
397
+ await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
398
+ }
399
+ await axn.addSupportIxs('repayAndWithdrawV2', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, true, createLookupTable, twoTokenAction);
400
+ const withdrawCollateralAmount = axn.getWithdrawCollateralAmount(axn.outflowReserve, axn.outflowAmount);
401
+ axn.addRepayAndWithdrawV2Ixs(withdrawCollateralAmount);
402
+ return axn;
403
+ }
404
+ static async buildRepayAndWithdrawTxns(kaminoMarket, repayAmount, repayMint, withdrawAmount, withdrawMint, payer, currentSlot, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
375
405
  includeAtaIxns = true, // if true it includes create and close wsol and token atas,
376
406
  requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata,
377
407
  createLookupTable = true, referrer = web3_js_1.PublicKey.default, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
@@ -392,19 +422,14 @@ class KaminoAction {
392
422
  if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
393
423
  await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
394
424
  }
395
- await axn.addSupportIxs('repay', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarmForRepay, useV2Ixs, createLookupTable, twoTokenAction);
425
+ await axn.addSupportIxs('repay', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarmForRepay, false, createLookupTable, twoTokenAction);
396
426
  const withdrawCollateralAmount = axn.getWithdrawCollateralAmount(axn.outflowReserve, axn.outflowAmount);
397
- if (useV2Ixs) {
398
- await axn.addRepayAndWithdrawIxsV2(withdrawCollateralAmount);
399
- }
400
- else {
401
- await axn.addRepayAndWithdrawIxs(withdrawCollateralAmount);
402
- }
403
- await axn.addInBetweenIxs('repayAndWithdraw', includeAtaIxns, requestElevationGroup, addInitObligationForFarmForWithdraw, useV2Ixs);
427
+ await axn.addRepayAndWithdrawIxs(withdrawCollateralAmount);
428
+ await axn.addInBetweenIxs('repayAndWithdraw', includeAtaIxns, requestElevationGroup, addInitObligationForFarmForWithdraw);
404
429
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
405
430
  return axn;
406
431
  }
407
- static async buildWithdrawTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
432
+ static async buildWithdrawTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
408
433
  includeAtaIxns = true, // if true it includes create and close wsol and token atas,
409
434
  requestElevationGroup = false, // to be requested *after* the withdraw
410
435
  includeUserMetadata = true, // if true it includes user metadata
@@ -426,14 +451,9 @@ class KaminoAction {
426
451
  if (tokenIds.length > 0 && scopeRefresh && scopeRefresh.includeScopeRefresh) {
427
452
  await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
428
453
  }
429
- await axn.addSupportIxs('withdraw', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, createLookupTable, false, overrideElevationGroupRequest);
454
+ await axn.addSupportIxs('withdraw', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, false, createLookupTable, false, overrideElevationGroupRequest);
430
455
  const collateralAmount = axn.getWithdrawCollateralAmount(axn.reserve, axn.amount);
431
- if (useV2Ixs) {
432
- await axn.addWithdrawIxV2(collateralAmount);
433
- }
434
- else {
435
- await axn.addWithdrawIx(collateralAmount);
436
- }
456
+ axn.addWithdrawIx(collateralAmount);
437
457
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
438
458
  return axn;
439
459
  }
@@ -452,7 +472,7 @@ class KaminoAction {
452
472
  * @param includeUserMetadata - if true it includes user metadata
453
473
  * @param referrer
454
474
  */
455
- static async buildRepayTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, currentSlot, payer = undefined, extraComputeBudget = 1_000_000, includeAtaIxns = true, requestElevationGroup = false, includeUserMetadata = true, createLookupTable = true, referrer = web3_js_1.PublicKey.default, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
475
+ static async buildRepayTxns(kaminoMarket, amount, mint, owner, obligation, currentSlot, payer = undefined, extraComputeBudget = 1_000_000, includeAtaIxns = true, requestElevationGroup = false, includeUserMetadata = true, createLookupTable = true, referrer = web3_js_1.PublicKey.default, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
456
476
  const axn = await KaminoAction.initialize('repay', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot, payer);
457
477
  const addInitObligationForFarm = true;
458
478
  if (extraComputeBudget > 0) {
@@ -467,17 +487,12 @@ class KaminoAction {
467
487
  if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
468
488
  await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
469
489
  }
470
- await axn.addSupportIxs('repay', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, createLookupTable);
471
- if (useV2Ixs) {
472
- await axn.addRepayIxV2();
473
- }
474
- else {
475
- await axn.addRepayIx();
476
- }
490
+ await axn.addSupportIxs('repay', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, false, createLookupTable);
491
+ axn.addRepayIx();
477
492
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
478
493
  return axn;
479
494
  }
480
- static async buildLiquidateTxns(kaminoMarket, amount, minCollateralReceiveAmount, repayTokenMint, withdrawTokenMint, liquidator, obligationOwner, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
495
+ static async buildLiquidateTxns(kaminoMarket, amount, minCollateralReceiveAmount, repayTokenMint, withdrawTokenMint, liquidator, obligationOwner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
481
496
  includeAtaIxns = true, // if true it includes create and close wsol and token atas, and creates all other token atas if they don't exist
482
497
  requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
483
498
  createLookupTable = true, referrer = web3_js_1.PublicKey.default, maxAllowedLtvOverridePercent = 0, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
@@ -496,13 +511,8 @@ class KaminoAction {
496
511
  if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
497
512
  await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
498
513
  }
499
- await axn.addSupportIxs('liquidate', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, createLookupTable);
500
- if (useV2Ixs) {
501
- await axn.addLiquidateIxV2(maxAllowedLtvOverridePercent);
502
- }
503
- else {
504
- await axn.addLiquidateIx(maxAllowedLtvOverridePercent);
505
- }
514
+ await axn.addSupportIxs('liquidate', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, false, createLookupTable);
515
+ axn.addLiquidateIx(maxAllowedLtvOverridePercent);
506
516
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
507
517
  return axn;
508
518
  }
@@ -572,29 +582,31 @@ class KaminoAction {
572
582
  return '';
573
583
  return await sendTransaction(txn, this.kaminoMarket.getConnection());
574
584
  }
575
- addDepositReserveLiquidityIx() {
576
- this.lendingIxsLabels.push(`depositReserveLiquidity`);
577
- this.lendingIxs.push((0, instructions_1.depositReserveLiquidity)({
585
+ addDepositIx() {
586
+ this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
587
+ this.lendingIxs.push((0, instructions_1.depositReserveLiquidityAndObligationCollateral)({
578
588
  liquidityAmount: this.amount,
579
589
  }, {
580
590
  owner: this.owner,
591
+ obligation: this.getObligationPda(),
581
592
  lendingMarket: this.kaminoMarket.getAddress(),
582
593
  lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
583
594
  reserve: this.reserve.address,
584
595
  reserveLiquidityMint: this.reserve.getLiquidityMint(),
585
596
  reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
586
597
  reserveCollateralMint: this.reserve.getCTokenMint(),
598
+ reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
587
599
  userSourceLiquidity: this.userTokenAccountAddress,
588
- userDestinationCollateral: this.userCollateralAccountAddress,
600
+ placeholderUserDestinationCollateral: this.kaminoMarket.programId,
589
601
  collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
590
602
  liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
591
603
  instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
592
604
  }, this.kaminoMarket.programId));
593
605
  }
594
- addRedeemReserveCollateralIx() {
595
- this.lendingIxsLabels.push(`redeemReserveCollateral`);
596
- this.lendingIxs.push((0, instructions_1.redeemReserveCollateral)({
597
- collateralAmount: this.amount,
606
+ addDepositReserveLiquidityIx() {
607
+ this.lendingIxsLabels.push(`depositReserveLiquidity`);
608
+ this.lendingIxs.push((0, instructions_1.depositReserveLiquidity)({
609
+ liquidityAmount: this.amount,
598
610
  }, {
599
611
  owner: this.owner,
600
612
  lendingMarket: this.kaminoMarket.getAddress(),
@@ -603,70 +615,32 @@ class KaminoAction {
603
615
  reserveLiquidityMint: this.reserve.getLiquidityMint(),
604
616
  reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
605
617
  reserveCollateralMint: this.reserve.getCTokenMint(),
606
- userSourceCollateral: this.userCollateralAccountAddress,
607
- userDestinationLiquidity: this.userTokenAccountAddress,
618
+ userSourceLiquidity: this.userTokenAccountAddress,
619
+ userDestinationCollateral: this.userCollateralAccountAddress,
608
620
  collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
609
621
  liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
610
622
  instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
611
623
  }, this.kaminoMarket.programId));
612
624
  }
613
- // @deprecated -- use addDepositIxV2 instead
614
- addDepositIx() {
615
- this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
616
- this.lendingIxs.push((0, instructions_1.depositReserveLiquidityAndObligationCollateral)({
617
- liquidityAmount: this.amount,
625
+ addRedeemReserveCollateralIx() {
626
+ this.lendingIxsLabels.push(`redeemReserveCollateral`);
627
+ this.lendingIxs.push((0, instructions_1.redeemReserveCollateral)({
628
+ collateralAmount: this.amount,
618
629
  }, {
619
630
  owner: this.owner,
620
- obligation: this.getObligationPda(),
621
631
  lendingMarket: this.kaminoMarket.getAddress(),
622
632
  lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
623
633
  reserve: this.reserve.address,
624
634
  reserveLiquidityMint: this.reserve.getLiquidityMint(),
625
635
  reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
626
636
  reserveCollateralMint: this.reserve.getCTokenMint(),
627
- reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
628
- userSourceLiquidity: this.userTokenAccountAddress,
629
- placeholderUserDestinationCollateral: this.kaminoMarket.programId,
637
+ userSourceCollateral: this.userCollateralAccountAddress,
638
+ userDestinationLiquidity: this.userTokenAccountAddress,
630
639
  collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
631
640
  liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
632
641
  instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
633
642
  }, this.kaminoMarket.programId));
634
643
  }
635
- addDepositIxV2() {
636
- const farmsAccounts = this.reserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
637
- ? {
638
- obligationFarmUserState: lib_1.PROGRAM_ID,
639
- reserveFarmState: lib_1.PROGRAM_ID,
640
- }
641
- : {
642
- obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmCollateral)[0],
643
- reserveFarmState: this.reserve.state.farmCollateral,
644
- };
645
- this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateralV2`);
646
- this.lendingIxs.push((0, instructions_1.depositReserveLiquidityAndObligationCollateralV2)({
647
- liquidityAmount: this.amount,
648
- }, {
649
- depositAccounts: {
650
- owner: this.owner,
651
- obligation: this.getObligationPda(),
652
- lendingMarket: this.kaminoMarket.getAddress(),
653
- lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
654
- reserve: this.reserve.address,
655
- reserveLiquidityMint: this.reserve.getLiquidityMint(),
656
- reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
657
- reserveCollateralMint: this.reserve.getCTokenMint(),
658
- reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
659
- userSourceLiquidity: this.userTokenAccountAddress,
660
- placeholderUserDestinationCollateral: this.kaminoMarket.programId,
661
- collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
662
- liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
663
- instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
664
- },
665
- farmsAccounts,
666
- farmsProgram: farms_sdk_1.farmsId,
667
- }, this.kaminoMarket.programId));
668
- }
669
- /// @deprecated -- use addDepositObligationCollateralIxV2 instead
670
644
  addDepositObligationCollateralIx() {
671
645
  this.lendingIxsLabels.push(`depositObligationCollateral`);
672
646
  this.lendingIxs.push((0, instructions_1.depositObligationCollateral)({
@@ -682,36 +656,6 @@ class KaminoAction {
682
656
  instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
683
657
  }, this.kaminoMarket.programId));
684
658
  }
685
- addDepositObligationCollateralIxV2() {
686
- const farmsAccounts = this.reserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
687
- ? {
688
- obligationFarmUserState: lib_1.PROGRAM_ID,
689
- reserveFarmState: lib_1.PROGRAM_ID,
690
- }
691
- : {
692
- obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmCollateral)[0],
693
- reserveFarmState: this.reserve.state.farmCollateral,
694
- };
695
- this.lendingIxsLabels.push(`depositObligationCollateralV2`);
696
- this.lendingIxs.push((0, instructions_1.depositObligationCollateralV2)({
697
- collateralAmount: this.amount,
698
- }, {
699
- depositAccounts: {
700
- owner: this.owner,
701
- obligation: this.getObligationPda(),
702
- lendingMarket: this.kaminoMarket.getAddress(),
703
- depositReserve: this.reserve.address,
704
- reserveDestinationCollateral: this.reserve.state.collateral.supplyVault,
705
- userSourceCollateral: this.userCollateralAccountAddress,
706
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
707
- instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
708
- },
709
- lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
710
- farmsAccounts,
711
- farmsProgram: farms_sdk_1.farmsId,
712
- }, this.kaminoMarket.programId));
713
- }
714
- /// @deprecated -- use addDepositObligationCollateralIxV2 instead
715
659
  addBorrowIx() {
716
660
  this.lendingIxsLabels.push(`borrowObligationLiquidity`);
717
661
  const depositReservesList = this.getAdditionalDepositReservesList();
@@ -740,165 +684,7 @@ class KaminoAction {
740
684
  : borrowIx.keys;
741
685
  this.lendingIxs.push(borrowIx);
742
686
  }
743
- addBorrowIxV2() {
744
- this.lendingIxsLabels.push(`borrowObligationLiquidityV2`);
745
- const depositReservesList = this.getAdditionalDepositReservesList();
746
- const depositReserveAccountMetas = depositReservesList.map((reserve) => {
747
- return { pubkey: reserve, isSigner: false, isWritable: true };
748
- });
749
- const farmsAccounts = this.reserve.state.farmDebt.equals(web3_js_1.PublicKey.default)
750
- ? {
751
- obligationFarmUserState: lib_1.PROGRAM_ID,
752
- reserveFarmState: lib_1.PROGRAM_ID,
753
- }
754
- : {
755
- obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmDebt)[0],
756
- reserveFarmState: this.reserve.state.farmDebt,
757
- };
758
- const borrowIx = (0, instructions_1.borrowObligationLiquidityV2)({
759
- liquidityAmount: this.amount,
760
- }, {
761
- borrowAccounts: {
762
- owner: this.owner,
763
- obligation: this.getObligationPda(),
764
- lendingMarket: this.kaminoMarket.getAddress(),
765
- lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
766
- borrowReserve: this.reserve.address,
767
- borrowReserveLiquidityMint: this.reserve.getLiquidityMint(),
768
- reserveSourceLiquidity: this.reserve.state.liquidity.supplyVault,
769
- userDestinationLiquidity: this.userTokenAccountAddress,
770
- borrowReserveLiquidityFeeReceiver: this.reserve.state.liquidity.feeVault,
771
- referrerTokenState: (0, utils_1.referrerTokenStatePda)(this.referrer, this.reserve.address, this.kaminoMarket.programId)[0],
772
- tokenProgram: this.reserve.getLiquidityTokenProgram(),
773
- instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
774
- },
775
- farmsAccounts,
776
- farmsProgram: farms_sdk_1.farmsId,
777
- }, this.kaminoMarket.programId);
778
- borrowIx.keys =
779
- this.obligation.state.elevationGroup > 0 || this.obligation.refreshedStats.potentialElevationGroupUpdate > 0
780
- ? borrowIx.keys.concat([...depositReserveAccountMetas])
781
- : borrowIx.keys;
782
- this.lendingIxs.push(borrowIx);
783
- }
784
- /// @deprecated -- use addWithdrawIxV2 instead
785
- async addWithdrawIx(collateralAmount) {
786
- this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateral`);
787
- this.lendingIxs.push((0, instructions_1.withdrawObligationCollateralAndRedeemReserveCollateral)({
788
- collateralAmount,
789
- }, {
790
- owner: this.owner,
791
- obligation: this.getObligationPda(),
792
- lendingMarket: this.kaminoMarket.getAddress(),
793
- lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
794
- withdrawReserve: this.reserve.address,
795
- reserveLiquidityMint: this.reserve.getLiquidityMint(),
796
- reserveCollateralMint: this.reserve.getCTokenMint(),
797
- reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
798
- reserveSourceCollateral: this.reserve.state.collateral.supplyVault,
799
- userDestinationLiquidity: this.userTokenAccountAddress,
800
- placeholderUserDestinationCollateral: this.kaminoMarket.programId,
801
- collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
802
- liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
803
- instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
804
- }, this.kaminoMarket.programId));
805
- }
806
- async addWithdrawIxV2(collateralAmount) {
807
- const farmsAccounts = this.reserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
808
- ? {
809
- obligationFarmUserState: lib_1.PROGRAM_ID,
810
- reserveFarmState: lib_1.PROGRAM_ID,
811
- }
812
- : {
813
- obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmCollateral)[0],
814
- reserveFarmState: this.reserve.state.farmCollateral,
815
- };
816
- this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateralV2`);
817
- this.lendingIxs.push((0, instructions_1.withdrawObligationCollateralAndRedeemReserveCollateralV2)({
818
- collateralAmount,
819
- }, {
820
- withdrawAccounts: {
821
- owner: this.owner,
822
- obligation: this.getObligationPda(),
823
- lendingMarket: this.kaminoMarket.getAddress(),
824
- lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
825
- withdrawReserve: this.reserve.address,
826
- reserveLiquidityMint: this.reserve.getLiquidityMint(),
827
- reserveCollateralMint: this.reserve.getCTokenMint(),
828
- reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
829
- reserveSourceCollateral: this.reserve.state.collateral.supplyVault,
830
- userDestinationLiquidity: this.userTokenAccountAddress,
831
- placeholderUserDestinationCollateral: this.kaminoMarket.programId,
832
- collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
833
- liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
834
- instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
835
- },
836
- farmsAccounts: farmsAccounts,
837
- farmsProgram: farms_sdk_1.farmsId,
838
- }, this.kaminoMarket.programId));
839
- }
840
- /// @deprecated -- use addRepayIxV2 instead
841
- async addRepayIx() {
842
- this.lendingIxsLabels.push(`repayObligationLiquidity(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`);
843
- const depositReservesList = this.getAdditionalDepositReservesList();
844
- const depositReserveAccountMetas = depositReservesList.map((reserve) => {
845
- return { pubkey: reserve, isSigner: false, isWritable: true };
846
- });
847
- const repayIx = (0, instructions_1.repayObligationLiquidity)({
848
- liquidityAmount: this.amount,
849
- }, {
850
- owner: this.payer,
851
- obligation: this.getObligationPda(),
852
- lendingMarket: this.kaminoMarket.getAddress(),
853
- repayReserve: this.reserve.address,
854
- reserveLiquidityMint: this.reserve.getLiquidityMint(),
855
- userSourceLiquidity: this.userTokenAccountAddress,
856
- reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
857
- tokenProgram: this.reserve.getLiquidityTokenProgram(),
858
- instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
859
- }, this.kaminoMarket.programId);
860
- repayIx.keys =
861
- this.obligation.state.elevationGroup > 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
862
- this.lendingIxs.push(repayIx);
863
- }
864
- async addRepayIxV2() {
865
- this.lendingIxsLabels.push(`repayObligationLiquidityV2(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`);
866
- const depositReservesList = this.getAdditionalDepositReservesList();
867
- const farmsAccounts = this.reserve.state.farmDebt.equals(web3_js_1.PublicKey.default)
868
- ? {
869
- obligationFarmUserState: lib_1.PROGRAM_ID,
870
- reserveFarmState: lib_1.PROGRAM_ID,
871
- }
872
- : {
873
- obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmDebt)[0],
874
- reserveFarmState: this.reserve.state.farmDebt,
875
- };
876
- const depositReserveAccountMetas = depositReservesList.map((reserve) => {
877
- return { pubkey: reserve, isSigner: false, isWritable: true };
878
- });
879
- const repayIx = (0, instructions_1.repayObligationLiquidityV2)({
880
- liquidityAmount: this.amount,
881
- }, {
882
- repayAccounts: {
883
- owner: this.payer,
884
- obligation: this.getObligationPda(),
885
- lendingMarket: this.kaminoMarket.getAddress(),
886
- repayReserve: this.reserve.address,
887
- reserveLiquidityMint: this.reserve.getLiquidityMint(),
888
- userSourceLiquidity: this.userTokenAccountAddress,
889
- reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
890
- tokenProgram: this.reserve.getLiquidityTokenProgram(),
891
- instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
892
- },
893
- lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
894
- farmsAccounts,
895
- farmsProgram: farms_sdk_1.farmsId,
896
- }, this.kaminoMarket.programId);
897
- repayIx.keys =
898
- this.obligation.state.elevationGroup > 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
899
- this.lendingIxs.push(repayIx);
900
- }
901
- async addDepositAndBorrowIx() {
687
+ addDepositAndBorrowIx() {
902
688
  this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
903
689
  this.lendingIxsLabels.push(`borrowObligationLiquidity`);
904
690
  this.lendingIxs.push((0, instructions_1.depositReserveLiquidityAndObligationCollateral)({
@@ -954,89 +740,7 @@ class KaminoAction {
954
740
  borrowIx.keys = borrowIx.keys.concat([...depositReserveAccountMetas]);
955
741
  this.lendingIxs.push(borrowIx);
956
742
  }
957
- async addDepositAndBorrowIxV2() {
958
- const collateralFarmsAccounts = this.reserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
959
- ? {
960
- obligationFarmUserState: lib_1.PROGRAM_ID,
961
- reserveFarmState: lib_1.PROGRAM_ID,
962
- }
963
- : {
964
- obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmCollateral)[0],
965
- reserveFarmState: this.reserve.state.farmCollateral,
966
- };
967
- this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateralV2`);
968
- this.lendingIxsLabels.push(`borrowObligationLiquidityV2`);
969
- this.lendingIxs.push((0, instructions_1.depositReserveLiquidityAndObligationCollateralV2)({
970
- liquidityAmount: this.amount,
971
- }, {
972
- depositAccounts: {
973
- owner: this.owner,
974
- obligation: this.getObligationPda(),
975
- lendingMarket: this.kaminoMarket.getAddress(),
976
- lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
977
- reserve: this.reserve.address,
978
- reserveLiquidityMint: this.reserve.getLiquidityMint(),
979
- reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
980
- reserveCollateralMint: this.reserve.getCTokenMint(),
981
- reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
982
- userSourceLiquidity: this.userTokenAccountAddress,
983
- placeholderUserDestinationCollateral: this.kaminoMarket.programId,
984
- collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
985
- liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
986
- instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
987
- },
988
- farmsAccounts: collateralFarmsAccounts,
989
- farmsProgram: farms_sdk_1.farmsId,
990
- }, this.kaminoMarket.programId));
991
- if (!this.outflowReserve) {
992
- throw new Error(`outflowReserve not set`);
993
- }
994
- if (!this.additionalTokenAccountAddress) {
995
- throw new Error(`additionalTokenAccountAddress not set`);
996
- }
997
- if (!this.outflowAmount) {
998
- throw new Error(`outflowAmount not set`);
999
- }
1000
- const depositReservesList = this.getAdditionalDepositReservesList();
1001
- if (depositReservesList.length === 0) {
1002
- depositReservesList.push(this.reserve.address);
1003
- }
1004
- const depositReserveAccountMetas = depositReservesList.map((reserve) => {
1005
- return { pubkey: reserve, isSigner: false, isWritable: true };
1006
- });
1007
- const debtFarmsAccounts = this.outflowReserve.state.farmDebt.equals(web3_js_1.PublicKey.default)
1008
- ? {
1009
- obligationFarmUserState: lib_1.PROGRAM_ID,
1010
- reserveFarmState: lib_1.PROGRAM_ID,
1011
- }
1012
- : {
1013
- obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.outflowReserve.state.farmDebt)[0],
1014
- reserveFarmState: this.outflowReserve.state.farmDebt,
1015
- };
1016
- const borrowIx = (0, instructions_1.borrowObligationLiquidityV2)({
1017
- liquidityAmount: this.outflowAmount,
1018
- }, {
1019
- borrowAccounts: {
1020
- owner: this.owner,
1021
- obligation: this.getObligationPda(),
1022
- lendingMarket: this.kaminoMarket.getAddress(),
1023
- lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1024
- borrowReserve: this.outflowReserve.address,
1025
- borrowReserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
1026
- reserveSourceLiquidity: this.outflowReserve.state.liquidity.supplyVault,
1027
- userDestinationLiquidity: this.additionalTokenAccountAddress,
1028
- borrowReserveLiquidityFeeReceiver: this.outflowReserve.state.liquidity.feeVault,
1029
- referrerTokenState: (0, utils_1.referrerTokenStatePda)(this.referrer, this.outflowReserve.address, this.kaminoMarket.programId)[0],
1030
- tokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
1031
- instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
1032
- },
1033
- farmsAccounts: debtFarmsAccounts,
1034
- farmsProgram: farms_sdk_1.farmsId,
1035
- }, this.kaminoMarket.programId);
1036
- borrowIx.keys = borrowIx.keys.concat([...depositReserveAccountMetas]);
1037
- this.lendingIxs.push(borrowIx);
1038
- }
1039
- async addRepayAndWithdrawIxs(withdrawCollateralAmount) {
743
+ addRepayAndWithdrawIxs(withdrawCollateralAmount) {
1040
744
  this.lendingIxsLabels.push(`repayObligationLiquidity(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`);
1041
745
  this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateral`);
1042
746
  const depositReservesList = this.getAdditionalDepositReservesList();
@@ -1086,24 +790,45 @@ class KaminoAction {
1086
790
  instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
1087
791
  }, this.kaminoMarket.programId));
1088
792
  }
1089
- async addRepayAndWithdrawIxsV2(withdrawCollateralAmount) {
1090
- this.lendingIxsLabels.push(`repayObligationLiquidityV2(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`);
1091
- this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateralV2`);
793
+ addRepayAndWithdrawV2Ixs(withdrawCollateralAmount) {
794
+ this.lendingIxsLabels.push(`repayAndWithdrawAndRedeem(repayReserve=${this.reserve.address})(withdrawReserve=${this.outflowReserve.address})(obligation=${this.getObligationPda()})`);
1092
795
  const depositReservesList = this.getAdditionalDepositReservesList();
1093
796
  const depositReserveAccountMetas = depositReservesList.map((reserve) => {
1094
797
  return { pubkey: reserve, isSigner: false, isWritable: true };
1095
798
  });
799
+ const borrowReserveAccountMetas = this.borrowReserves.map((reserve) => {
800
+ return { pubkey: reserve, isSigner: false, isWritable: true };
801
+ });
802
+ if (!this.outflowAmount) {
803
+ throw new Error(`outflowAmount not set`);
804
+ }
805
+ if (!this.outflowReserve) {
806
+ throw new Error(`outflowReserve not set`);
807
+ }
808
+ if (!this.additionalTokenAccountAddress) {
809
+ throw new Error(`additionalTokenAccountAddress not set`);
810
+ }
811
+ const collateralFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
812
+ ? {
813
+ obligationFarmUserState: this.kaminoMarket.programId,
814
+ reserveFarmState: this.kaminoMarket.programId,
815
+ }
816
+ : {
817
+ obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.outflowReserve.state.farmCollateral, this.getObligationPda()),
818
+ reserveFarmState: this.outflowReserve.state.farmCollateral,
819
+ };
1096
820
  const debtFarmsAccounts = this.reserve.state.farmDebt.equals(web3_js_1.PublicKey.default)
1097
821
  ? {
1098
- obligationFarmUserState: lib_1.PROGRAM_ID,
1099
- reserveFarmState: lib_1.PROGRAM_ID,
822
+ obligationFarmUserState: this.kaminoMarket.programId,
823
+ reserveFarmState: this.kaminoMarket.programId,
1100
824
  }
1101
825
  : {
1102
- obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmDebt)[0],
826
+ obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.reserve.state.farmDebt, this.getObligationPda()),
1103
827
  reserveFarmState: this.reserve.state.farmDebt,
1104
828
  };
1105
- const repayIx = (0, instructions_1.repayObligationLiquidityV2)({
1106
- liquidityAmount: this.amount,
829
+ const repayAndWithdrawIx = (0, instructions_1.repayAndWithdrawAndRedeem)({
830
+ repayAmount: this.amount,
831
+ withdrawCollateralAmount,
1107
832
  }, {
1108
833
  repayAccounts: {
1109
834
  owner: this.owner,
@@ -1116,33 +841,88 @@ class KaminoAction {
1116
841
  tokenProgram: this.reserve.getLiquidityTokenProgram(),
1117
842
  instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
1118
843
  },
1119
- lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1120
- farmsAccounts: debtFarmsAccounts,
844
+ withdrawAccounts: {
845
+ owner: this.owner,
846
+ obligation: this.getObligationPda(),
847
+ lendingMarket: this.kaminoMarket.getAddress(),
848
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
849
+ withdrawReserve: this.outflowReserve.address,
850
+ reserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
851
+ reserveCollateralMint: this.outflowReserve.getCTokenMint(),
852
+ reserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
853
+ reserveSourceCollateral: this.outflowReserve.state.collateral.supplyVault,
854
+ userDestinationLiquidity: this.additionalTokenAccountAddress,
855
+ placeholderUserDestinationCollateral: this.kaminoMarket.programId,
856
+ collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
857
+ liquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
858
+ instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
859
+ },
860
+ collateralFarmsAccounts,
861
+ debtFarmsAccounts,
1121
862
  farmsProgram: farms_sdk_1.farmsId,
1122
863
  }, this.kaminoMarket.programId);
1123
- repayIx.keys = repayIx.keys.concat([...depositReserveAccountMetas]);
1124
- this.lendingIxs.push(repayIx);
864
+ repayAndWithdrawIx.keys = repayAndWithdrawIx.keys.concat([
865
+ ...depositReserveAccountMetas,
866
+ ...borrowReserveAccountMetas,
867
+ ]);
868
+ this.lendingIxs.push(repayAndWithdrawIx);
869
+ }
870
+ addDepositAndWithdrawV2Ixs(withdrawCollateralAmount) {
871
+ this.lendingIxsLabels.push(`depositAndWithdrawV2(depositReserve=${this.reserve.address})(withdrawReserve=${this.outflowReserve.address})(obligation=${this.getObligationPda()})`);
872
+ const depositReservesList = this.getAdditionalDepositReservesList();
873
+ const depositReserveAccountMetas = depositReservesList.map((reserve) => {
874
+ return { pubkey: reserve, isSigner: false, isWritable: true };
875
+ });
876
+ const borrowReserveAccountMetas = this.borrowReserves.map((reserve) => {
877
+ return { pubkey: reserve, isSigner: false, isWritable: true };
878
+ });
879
+ if (!this.outflowAmount) {
880
+ throw new Error(`outflowAmount not set`);
881
+ }
1125
882
  if (!this.outflowReserve) {
1126
883
  throw new Error(`outflowReserve not set`);
1127
884
  }
1128
885
  if (!this.additionalTokenAccountAddress) {
1129
886
  throw new Error(`additionalTokenAccountAddress not set`);
1130
887
  }
1131
- if (!this.outflowAmount) {
1132
- throw new Error(`outflowAmount not set`);
1133
- }
1134
- const collateralFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
888
+ const depositFarmsAccounts = this.reserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
1135
889
  ? {
1136
- obligationFarmUserState: lib_1.PROGRAM_ID,
1137
- reserveFarmState: lib_1.PROGRAM_ID,
890
+ obligationFarmUserState: this.kaminoMarket.programId,
891
+ reserveFarmState: this.kaminoMarket.programId,
1138
892
  }
1139
893
  : {
1140
- obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.outflowReserve.state.farmCollateral)[0],
894
+ obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.reserve.state.farmDebt, this.getObligationPda()),
895
+ reserveFarmState: this.reserve.state.farmCollateral,
896
+ };
897
+ const withdrawFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
898
+ ? {
899
+ obligationFarmUserState: this.kaminoMarket.programId,
900
+ reserveFarmState: this.kaminoMarket.programId,
901
+ }
902
+ : {
903
+ obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.outflowReserve.state.farmCollateral, this.getObligationPda()),
1141
904
  reserveFarmState: this.outflowReserve.state.farmCollateral,
1142
905
  };
1143
- this.lendingIxs.push((0, instructions_1.withdrawObligationCollateralAndRedeemReserveCollateralV2)({
1144
- collateralAmount: withdrawCollateralAmount,
906
+ const depositAndWithdrawIx = (0, instructions_1.depositAndWithdraw)({
907
+ liquidityAmount: this.amount,
908
+ withdrawCollateralAmount,
1145
909
  }, {
910
+ depositAccounts: {
911
+ owner: this.owner,
912
+ obligation: this.getObligationPda(),
913
+ lendingMarket: this.kaminoMarket.getAddress(),
914
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
915
+ reserve: this.reserve.address,
916
+ reserveLiquidityMint: this.reserve.getLiquidityMint(),
917
+ reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
918
+ reserveCollateralMint: this.reserve.getCTokenMint(),
919
+ reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
920
+ userSourceLiquidity: this.userTokenAccountAddress,
921
+ placeholderUserDestinationCollateral: this.kaminoMarket.programId,
922
+ collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
923
+ liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
924
+ instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
925
+ },
1146
926
  withdrawAccounts: {
1147
927
  owner: this.owner,
1148
928
  obligation: this.getObligationPda(),
@@ -1159,11 +939,61 @@ class KaminoAction {
1159
939
  liquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
1160
940
  instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
1161
941
  },
1162
- farmsAccounts: collateralFarmsAccounts,
942
+ depositFarmsAccounts,
943
+ withdrawFarmsAccounts,
1163
944
  farmsProgram: farms_sdk_1.farmsId,
945
+ }, this.kaminoMarket.programId);
946
+ depositAndWithdrawIx.keys = depositAndWithdrawIx.keys.concat([
947
+ ...depositReserveAccountMetas,
948
+ ...borrowReserveAccountMetas,
949
+ ]);
950
+ this.lendingIxs.push(depositAndWithdrawIx);
951
+ }
952
+ addWithdrawIx(withdrawCollateralAmount) {
953
+ this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateral`);
954
+ this.lendingIxs.push((0, instructions_1.withdrawObligationCollateralAndRedeemReserveCollateral)({
955
+ collateralAmount: withdrawCollateralAmount,
956
+ }, {
957
+ owner: this.owner,
958
+ obligation: this.getObligationPda(),
959
+ lendingMarket: this.kaminoMarket.getAddress(),
960
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
961
+ withdrawReserve: this.reserve.address,
962
+ reserveLiquidityMint: this.reserve.getLiquidityMint(),
963
+ reserveCollateralMint: this.reserve.getCTokenMint(),
964
+ reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
965
+ reserveSourceCollateral: this.reserve.state.collateral.supplyVault,
966
+ userDestinationLiquidity: this.userTokenAccountAddress,
967
+ placeholderUserDestinationCollateral: this.kaminoMarket.programId,
968
+ collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
969
+ liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
970
+ instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
1164
971
  }, this.kaminoMarket.programId));
1165
972
  }
1166
- async addLiquidateIx(maxAllowedLtvOverridePercent = 0) {
973
+ addRepayIx() {
974
+ this.lendingIxsLabels.push(`repayObligationLiquidity(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`);
975
+ const depositReservesList = this.getAdditionalDepositReservesList();
976
+ const depositReserveAccountMetas = depositReservesList.map((reserve) => {
977
+ return { pubkey: reserve, isSigner: false, isWritable: true };
978
+ });
979
+ const repayIx = (0, instructions_1.repayObligationLiquidity)({
980
+ liquidityAmount: this.amount,
981
+ }, {
982
+ owner: this.payer,
983
+ obligation: this.getObligationPda(),
984
+ lendingMarket: this.kaminoMarket.getAddress(),
985
+ repayReserve: this.reserve.address,
986
+ reserveLiquidityMint: this.reserve.getLiquidityMint(),
987
+ userSourceLiquidity: this.userTokenAccountAddress,
988
+ reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
989
+ tokenProgram: this.reserve.getLiquidityTokenProgram(),
990
+ instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
991
+ }, this.kaminoMarket.programId);
992
+ repayIx.keys =
993
+ this.obligation.state.elevationGroup > 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
994
+ this.lendingIxs.push(repayIx);
995
+ }
996
+ addLiquidateIx(maxAllowedLtvOverridePercent = 0) {
1167
997
  this.lendingIxsLabels.push(`liquidateObligationAndRedeemReserveCollateral`);
1168
998
  if (!this.outflowReserve) {
1169
999
  throw Error(`Withdraw reserve during liquidation is not defined`);
@@ -1208,76 +1038,8 @@ class KaminoAction {
1208
1038
  : liquidateIx.keys;
1209
1039
  this.lendingIxs.push(liquidateIx);
1210
1040
  }
1211
- async addLiquidateIxV2(maxAllowedLtvOverridePercent = 0) {
1212
- this.lendingIxsLabels.push(`liquidateObligationAndRedeemReserveCollateralV2`);
1213
- if (!this.outflowReserve) {
1214
- throw Error(`Withdraw reserve during liquidation is not defined`);
1215
- }
1216
- if (!this.additionalTokenAccountAddress) {
1217
- throw Error(`Liquidating token account address is not defined`);
1218
- }
1219
- const depositReservesList = this.getAdditionalDepositReservesList();
1220
- const depositReserveAccountMetas = depositReservesList.map((reserve) => {
1221
- return { pubkey: reserve, isSigner: false, isWritable: true };
1222
- });
1223
- const collateralFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
1224
- ? {
1225
- obligationFarmUserState: lib_1.PROGRAM_ID,
1226
- reserveFarmState: lib_1.PROGRAM_ID,
1227
- }
1228
- : {
1229
- obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.outflowReserve.state.farmCollateral)[0],
1230
- reserveFarmState: this.outflowReserve.state.farmCollateral,
1231
- };
1232
- const debtFarmsAccounts = this.reserve.state.farmDebt.equals(web3_js_1.PublicKey.default)
1233
- ? {
1234
- obligationFarmUserState: lib_1.PROGRAM_ID,
1235
- reserveFarmState: lib_1.PROGRAM_ID,
1236
- }
1237
- : {
1238
- obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmDebt)[0],
1239
- reserveFarmState: this.reserve.state.farmDebt,
1240
- };
1241
- const liquidateIx = (0, instructions_1.liquidateObligationAndRedeemReserveCollateralV2)({
1242
- liquidityAmount: this.amount,
1243
- // TODO: Configure this when updating liquidator with new interface
1244
- minAcceptableReceivedLiquidityAmount: this.outflowAmount || new bn_js_1.default(0),
1245
- maxAllowedLtvOverridePercent: new bn_js_1.default(maxAllowedLtvOverridePercent),
1246
- }, {
1247
- liquidationAccounts: {
1248
- liquidator: this.owner,
1249
- obligation: this.getObligationPda(),
1250
- lendingMarket: this.kaminoMarket.getAddress(),
1251
- lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1252
- repayReserve: this.reserve.address,
1253
- repayReserveLiquidityMint: this.reserve.getLiquidityMint(),
1254
- repayReserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
1255
- withdrawReserve: this.outflowReserve.address,
1256
- withdrawReserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
1257
- withdrawReserveCollateralMint: this.outflowReserve.getCTokenMint(),
1258
- withdrawReserveCollateralSupply: this.outflowReserve.state.collateral.supplyVault,
1259
- withdrawReserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
1260
- userSourceLiquidity: this.additionalTokenAccountAddress,
1261
- userDestinationCollateral: this.userCollateralAccountAddress,
1262
- userDestinationLiquidity: this.userTokenAccountAddress,
1263
- withdrawReserveLiquidityFeeReceiver: this.outflowReserve.state.liquidity.feeVault,
1264
- collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
1265
- repayLiquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
1266
- withdrawLiquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
1267
- instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
1268
- },
1269
- debtFarmsAccounts,
1270
- collateralFarmsAccounts,
1271
- farmsProgram: farms_sdk_1.farmsId,
1272
- }, this.kaminoMarket.programId);
1273
- liquidateIx.keys =
1274
- this.obligation.state.elevationGroup > 0
1275
- ? liquidateIx.keys.concat([...depositReserveAccountMetas])
1276
- : liquidateIx.keys;
1277
- this.lendingIxs.push(liquidateIx);
1278
- }
1279
- async addInBetweenIxs(action, includeAtaIxns, requestElevationGroup, addInitObligationForFarm, useV2Ixs) {
1280
- await this.addSupportIxsWithoutInitObligation(action, includeAtaIxns, useV2Ixs, 'inBetween', requestElevationGroup, addInitObligationForFarm);
1041
+ async addInBetweenIxs(action, includeAtaIxns, requestElevationGroup, addInitObligationForFarm) {
1042
+ await this.addSupportIxsWithoutInitObligation(action, includeAtaIxns, false, 'inBetween', requestElevationGroup, addInitObligationForFarm);
1281
1043
  }
1282
1044
  addRefreshObligation(crank) {
1283
1045
  const uniqueReserveAddresses = new utils_1.PublicKeySet(this.depositReserves.concat(this.borrowReserves)).toArray();
@@ -1303,6 +1065,7 @@ class KaminoAction {
1303
1065
  'repay',
1304
1066
  'depositAndBorrow',
1305
1067
  'repayAndWithdraw',
1068
+ 'repayAndWithdrawV2',
1306
1069
  'refreshObligation',
1307
1070
  ].includes(action)) {
1308
1071
  // The support ixns in order are:
@@ -1318,11 +1081,14 @@ class KaminoAction {
1318
1081
  // 7. Ixn to refresh the `debt` farm of the obligation
1319
1082
  // 8. Ixn to refresh the `collateral` farm of the obligation
1320
1083
  let currentReserves = [];
1321
- if (action === 'liquidate' || action === 'depositAndBorrow' || action === 'repayAndWithdraw') {
1084
+ if (action === 'liquidate' ||
1085
+ action === 'depositAndBorrow' ||
1086
+ action === 'repayAndWithdraw' ||
1087
+ action === 'repayAndWithdrawV2') {
1322
1088
  if (!this.outflowReserve) {
1323
1089
  throw new Error('outflowReserve is undefined');
1324
1090
  }
1325
- if (action === 'depositAndBorrow' || action === 'repayAndWithdraw') {
1091
+ if (action === 'depositAndBorrow' || action === 'repayAndWithdraw' || action === 'repayAndWithdrawV2') {
1326
1092
  currentReserves = [this.reserve, this.outflowReserve];
1327
1093
  if (action === 'depositAndBorrow') {
1328
1094
  if (this.obligation) {
@@ -1366,7 +1132,10 @@ class KaminoAction {
1366
1132
  await this.addInitObligationForFarm(this.outflowReserve, types_1.ReserveFarmKind.Debt, addAsSupportIx);
1367
1133
  }
1368
1134
  }
1369
- else if (action === 'repayAndWithdraw' || action === 'borrow' || action === 'repay') {
1135
+ else if (action === 'repayAndWithdraw' ||
1136
+ action === 'borrow' ||
1137
+ action === 'repay' ||
1138
+ action === 'repayAndWithdrawV2') {
1370
1139
  // todo - probably don't need to add both debt and collateral for everything here
1371
1140
  await this.addInitObligationForFarm(this.reserve, types_1.ReserveFarmKind.Debt, addAsSupportIx);
1372
1141
  if (this.outflowReserve) {
@@ -1397,7 +1166,7 @@ class KaminoAction {
1397
1166
  this.addRefreshObligationIx(addAsSupportIx);
1398
1167
  }
1399
1168
  if (requestElevationGroup) {
1400
- if (action === 'repay') {
1169
+ if (action === 'repay' || action === 'repayAndWithdrawV2') {
1401
1170
  const repayObligationLiquidity = this.obligation.borrows.get(this.reserve.address);
1402
1171
  if (!repayObligationLiquidity) {
1403
1172
  throw new Error(`Could not find debt reserve ${this.reserve.address} in obligation`);
@@ -1541,7 +1310,7 @@ class KaminoAction {
1541
1310
  if (action === 'deposit' && this.outflowReserve) {
1542
1311
  await this.addInitReferrerTokenStateIx(this.outflowReserve);
1543
1312
  }
1544
- await this.addInitObligationIxs();
1313
+ this.addInitObligationIxs();
1545
1314
  }
1546
1315
  await this.addSupportIxsWithoutInitObligation(action, includeAtaIxns, useV2Ixs, 'setup', requestElevationGroup, addInitObligationForFarm, twoTokenAction, overrideElevationGroupRequest);
1547
1316
  }
@@ -1697,7 +1466,7 @@ class KaminoAction {
1697
1466
  farms.push([
1698
1467
  types_1.ReserveFarmKind.Collateral,
1699
1468
  kaminoReserve.state.farmCollateral,
1700
- (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), kaminoReserve.state.farmCollateral)[0],
1469
+ (0, utils_1.obligationFarmStatePda)(kaminoReserve.state.farmCollateral, this.getObligationPda()),
1701
1470
  kaminoReserve,
1702
1471
  ]);
1703
1472
  }
@@ -1705,7 +1474,7 @@ class KaminoAction {
1705
1474
  farms.push([
1706
1475
  types_1.ReserveFarmKind.Debt,
1707
1476
  kaminoReserve.state.farmDebt,
1708
- (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), kaminoReserve.state.farmDebt)[0],
1477
+ (0, utils_1.obligationFarmStatePda)(kaminoReserve.state.farmDebt, this.getObligationPda()),
1709
1478
  kaminoReserve,
1710
1479
  ]);
1711
1480
  }
@@ -1755,17 +1524,17 @@ class KaminoAction {
1755
1524
  async addInitObligationForFarm(reserve, mode, addAsSupportIx = 'setup') {
1756
1525
  const farms = [];
1757
1526
  if (mode === types_1.ReserveFarmKind.Collateral && (0, utils_1.isNotNullPubkey)(reserve.state.farmCollateral)) {
1758
- const userPda = (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), reserve.state.farmCollateral)[0];
1759
- const account = await this.kaminoMarket.getConnection().getAccountInfo(userPda);
1527
+ const pda = (0, utils_1.obligationFarmStatePda)(reserve.state.farmCollateral, this.getObligationPda());
1528
+ const account = await this.kaminoMarket.getConnection().getAccountInfo(pda);
1760
1529
  if (!account) {
1761
- farms.push([types_1.ReserveFarmKind.Collateral.discriminator, reserve.state.farmCollateral, userPda]);
1530
+ farms.push([types_1.ReserveFarmKind.Collateral.discriminator, reserve.state.farmCollateral, pda]);
1762
1531
  }
1763
1532
  }
1764
1533
  if (mode === types_1.ReserveFarmKind.Debt && (0, utils_1.isNotNullPubkey)(reserve.state.farmDebt)) {
1765
- const userPda = (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), reserve.state.farmDebt)[0];
1766
- const account = await this.kaminoMarket.getConnection().getAccountInfo(userPda);
1534
+ const pda = (0, utils_1.obligationFarmStatePda)(reserve.state.farmDebt, this.getObligationPda());
1535
+ const account = await this.kaminoMarket.getConnection().getAccountInfo(pda);
1767
1536
  if (!account) {
1768
- farms.push([types_1.ReserveFarmKind.Debt.discriminator, reserve.state.farmDebt, userPda]);
1537
+ farms.push([types_1.ReserveFarmKind.Debt.discriminator, reserve.state.farmDebt, pda]);
1769
1538
  }
1770
1539
  }
1771
1540
  farms.forEach((arg) => {
@@ -1794,7 +1563,7 @@ class KaminoAction {
1794
1563
  }
1795
1564
  });
1796
1565
  }
1797
- async addInitObligationIxs() {
1566
+ addInitObligationIxs() {
1798
1567
  if (!this.obligation) {
1799
1568
  const obligationPda = this.getObligationPda();
1800
1569
  const [userMetadataAddress, _bump] = (0, utils_1.userMetadataPda)(this.owner, this.kaminoMarket.programId);
@@ -1936,14 +1705,13 @@ class KaminoAction {
1936
1705
  return;
1937
1706
  }
1938
1707
  let safeRepay = new bn_js_1.default(this.amount);
1939
- if (this.obligation && action === 'repay' && this.amount.eq(new bn_js_1.default(utils_1.U64_MAX))) {
1708
+ if (this.obligation && (action === 'repay' || action === 'repayAndWithdrawV2') && this.amount.eq(new bn_js_1.default(utils_1.U64_MAX))) {
1940
1709
  const borrow = this.obligation.state.borrows.find((borrow) => borrow.borrowReserve.toString() === this.reserve.address.toString());
1941
1710
  if (!borrow) {
1942
1711
  throw Error(`Unable to find obligation borrow to repay for ${this.obligation.state.owner.toBase58()}`);
1943
1712
  }
1944
1713
  const cumulativeBorrowRateObligation = obligation_1.KaminoObligation.getCumulativeBorrowRate(borrow);
1945
1714
  const cumulativeBorrowRateReserve = this.reserve.getEstimatedCumulativeBorrowRate(this.currentSlot, this.kaminoMarket.state.referralFeeBps);
1946
- // TODO: shouldn't this calc be added to all other stuff as well?
1947
1715
  safeRepay = new bn_js_1.default(Math.floor(obligation_1.KaminoObligation.getBorrowAmount(borrow)
1948
1716
  .mul(cumulativeBorrowRateReserve)
1949
1717
  .div(cumulativeBorrowRateObligation)
@@ -1962,6 +1730,7 @@ class KaminoAction {
1962
1730
  // Add rent exemption lamports for WSOL accounts that need to be pre-funded for inflow/send transactions
1963
1731
  const sendAction = action === 'deposit' ||
1964
1732
  action === 'repay' ||
1733
+ action === 'repayAndWithdrawV2' ||
1965
1734
  action === 'mint' ||
1966
1735
  (action === 'liquidate' && this.secondaryMint?.equals(spl_token_1.NATIVE_MINT)); // only sync WSOL amount if liquidator repays SOL which is secondaryMint
1967
1736
  const transferLamportsIx = web3_js_1.SystemProgram.transfer({
@@ -2026,7 +1795,7 @@ class KaminoAction {
2026
1795
  primaryMint = inflowTokenMint;
2027
1796
  secondaryMint = outflowTokenMint;
2028
1797
  }
2029
- else if (action === 'repayAndWithdraw') {
1798
+ else if (action === 'repayAndWithdraw' || action === 'repayAndWithdrawV2') {
2030
1799
  primaryMint = inflowTokenMint;
2031
1800
  secondaryMint = outflowTokenMint;
2032
1801
  userTokenAccountAddress = userInflowTokenAccountAddress;