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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/dist/classes/action.d.ts +24 -26
  2. package/dist/classes/action.d.ts.map +1 -1
  3. package/dist/classes/action.js +501 -270
  4. package/dist/classes/action.js.map +1 -1
  5. package/dist/classes/lut_utils.d.ts +29 -0
  6. package/dist/classes/lut_utils.d.ts.map +1 -0
  7. package/dist/classes/lut_utils.js +62 -0
  8. package/dist/classes/lut_utils.js.map +1 -0
  9. package/dist/classes/manager.js +1 -1
  10. package/dist/classes/manager.js.map +1 -1
  11. package/dist/classes/obligation.d.ts +1 -1
  12. package/dist/classes/obligation.d.ts.map +1 -1
  13. package/dist/classes/obligation.js +1 -1
  14. package/dist/classes/obligation.js.map +1 -1
  15. package/dist/classes/vault.js +6 -6
  16. package/dist/classes/vault.js.map +1 -1
  17. package/dist/lending_operations/repay_with_collateral_calcs.d.ts.map +1 -1
  18. package/dist/lending_operations/repay_with_collateral_calcs.js +5 -9
  19. package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
  20. package/dist/lending_operations/repay_with_collateral_operations.d.ts +3 -7
  21. package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
  22. package/dist/lending_operations/repay_with_collateral_operations.js +7 -27
  23. package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
  24. package/dist/lending_operations/swap_collateral_operations.d.ts +5 -0
  25. package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
  26. package/dist/lending_operations/swap_collateral_operations.js +4 -2
  27. package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
  28. package/dist/leverage/operations.d.ts +8 -8
  29. package/dist/leverage/operations.d.ts.map +1 -1
  30. package/dist/leverage/operations.js +27 -24
  31. package/dist/leverage/operations.js.map +1 -1
  32. package/dist/leverage/types.d.ts +4 -1
  33. package/dist/leverage/types.d.ts.map +1 -1
  34. package/dist/utils/lookupTable.d.ts +0 -27
  35. package/dist/utils/lookupTable.d.ts.map +1 -1
  36. package/dist/utils/lookupTable.js +0 -58
  37. package/dist/utils/lookupTable.js.map +1 -1
  38. package/dist/utils/seeds.d.ts +3 -9
  39. package/dist/utils/seeds.d.ts.map +1 -1
  40. package/dist/utils/seeds.js +5 -11
  41. package/dist/utils/seeds.js.map +1 -1
  42. package/dist/utils/userMetadata.js +6 -6
  43. package/dist/utils/userMetadata.js.map +1 -1
  44. package/package.json +4 -1
  45. package/src/classes/action.ts +643 -404
  46. package/src/classes/lut_utils.ts +63 -0
  47. package/src/classes/manager.ts +1 -1
  48. package/src/classes/obligation.ts +1 -1
  49. package/src/classes/vault.ts +1 -1
  50. package/src/client.ts +7 -3
  51. package/src/lending_operations/repay_with_collateral_calcs.ts +5 -14
  52. package/src/lending_operations/repay_with_collateral_operations.ts +14 -30
  53. package/src/lending_operations/swap_collateral_operations.ts +11 -0
  54. package/src/leverage/operations.ts +38 -11
  55. package/src/leverage/types.ts +4 -1
  56. package/src/utils/lookupTable.ts +0 -62
  57. package/src/utils/seeds.ts +7 -12
  58. package/src/utils/userMetadata.ts +14 -14
@@ -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, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
183
+ static async buildDepositTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, 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,8 +200,13 @@ 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, false, createLookupTable, undefined, overrideElevationGroupRequest);
204
- axn.addDepositIx();
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
+ }
205
210
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
206
211
  return axn;
207
212
  }
@@ -233,7 +238,7 @@ class KaminoAction {
233
238
  feed: feed,
234
239
  }, tokens));
235
240
  }
236
- static async buildBorrowTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
241
+ static async buildBorrowTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
237
242
  includeAtaIxns = true, // if true it includes create and close wsol and token atas,
238
243
  requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
239
244
  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
@@ -252,8 +257,13 @@ class KaminoAction {
252
257
  if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
253
258
  await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
254
259
  }
255
- await axn.addSupportIxs('borrow', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, false, createLookupTable, undefined, overrideElevationGroupRequest);
256
- axn.addBorrowIx();
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
+ }
257
267
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
258
268
  return axn;
259
269
  }
@@ -301,7 +311,7 @@ class KaminoAction {
301
311
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
302
312
  return axn;
303
313
  }
304
- static async buildDepositObligationCollateralTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
314
+ static async buildDepositObligationCollateralTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
305
315
  includeAtaIxns = true, // if true it includes create and close wsol and token atas
306
316
  requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
307
317
  createLookupTable = true, referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
@@ -319,12 +329,17 @@ class KaminoAction {
319
329
  if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
320
330
  await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
321
331
  }
322
- await axn.addSupportIxs('depositCollateral', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, false, createLookupTable);
323
- axn.addDepositObligationCollateralIx();
332
+ await axn.addSupportIxs('depositCollateral', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, createLookupTable);
333
+ if (useV2Ixs) {
334
+ axn.addDepositObligationCollateralIxV2();
335
+ }
336
+ else {
337
+ axn.addDepositObligationCollateralIx();
338
+ }
324
339
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
325
340
  return axn;
326
341
  }
327
- static async buildDepositAndBorrowTxns(kaminoMarket, depositAmount, depositMint, borrowAmount, borrowMint, payer, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
342
+ static async buildDepositAndBorrowTxns(kaminoMarket, depositAmount, depositMint, borrowAmount, borrowMint, payer, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
328
343
  includeAtaIxns = true, // if true it includes create and close wsol and token atas,
329
344
  requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata,
330
345
  createLookupTable = true, referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
@@ -345,63 +360,18 @@ class KaminoAction {
345
360
  if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
346
361
  await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
347
362
  }
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);
363
+ await axn.addSupportIxs('deposit', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarmForDeposit, useV2Ixs, createLookupTable, twoTokenAction);
364
+ if (useV2Ixs) {
365
+ await axn.addDepositAndBorrowIxV2();
363
366
  }
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);
373
- }
374
- await axn.addSupportIxs('depositAndWithdraw', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, true, twoTokenAction);
375
- const withdrawCollateralAmount = axn.getWithdrawCollateralAmount(axn.outflowReserve, axn.outflowAmount);
376
- axn.addDepositAndWithdrawV2Ixs(withdrawCollateralAmount);
377
- return axn;
378
- }
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);
367
+ else {
368
+ await axn.addDepositAndBorrowIx();
398
369
  }
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);
370
+ await axn.addInBetweenIxs('depositAndBorrow', includeAtaIxns, requestElevationGroup, addInitObligationForFarmForBorrow, useV2Ixs);
371
+ axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
402
372
  return axn;
403
373
  }
404
- static async buildRepayAndWithdrawTxns(kaminoMarket, repayAmount, repayMint, withdrawAmount, withdrawMint, payer, currentSlot, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
374
+ static async buildRepayAndWithdrawTxns(kaminoMarket, repayAmount, repayMint, withdrawAmount, withdrawMint, payer, currentSlot, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
405
375
  includeAtaIxns = true, // if true it includes create and close wsol and token atas,
406
376
  requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata,
407
377
  createLookupTable = true, referrer = web3_js_1.PublicKey.default, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
@@ -422,14 +392,19 @@ class KaminoAction {
422
392
  if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
423
393
  await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
424
394
  }
425
- await axn.addSupportIxs('repay', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarmForRepay, false, createLookupTable, twoTokenAction);
395
+ await axn.addSupportIxs('repay', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarmForRepay, useV2Ixs, createLookupTable, twoTokenAction);
426
396
  const withdrawCollateralAmount = axn.getWithdrawCollateralAmount(axn.outflowReserve, axn.outflowAmount);
427
- await axn.addRepayAndWithdrawIxs(withdrawCollateralAmount);
428
- await axn.addInBetweenIxs('repayAndWithdraw', includeAtaIxns, requestElevationGroup, addInitObligationForFarmForWithdraw);
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);
429
404
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
430
405
  return axn;
431
406
  }
432
- static async buildWithdrawTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
407
+ static async buildWithdrawTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
433
408
  includeAtaIxns = true, // if true it includes create and close wsol and token atas,
434
409
  requestElevationGroup = false, // to be requested *after* the withdraw
435
410
  includeUserMetadata = true, // if true it includes user metadata
@@ -451,9 +426,14 @@ class KaminoAction {
451
426
  if (tokenIds.length > 0 && scopeRefresh && scopeRefresh.includeScopeRefresh) {
452
427
  await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
453
428
  }
454
- await axn.addSupportIxs('withdraw', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, false, createLookupTable, false, overrideElevationGroupRequest);
429
+ await axn.addSupportIxs('withdraw', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, createLookupTable, false, overrideElevationGroupRequest);
455
430
  const collateralAmount = axn.getWithdrawCollateralAmount(axn.reserve, axn.amount);
456
- axn.addWithdrawIx(collateralAmount);
431
+ if (useV2Ixs) {
432
+ await axn.addWithdrawIxV2(collateralAmount);
433
+ }
434
+ else {
435
+ await axn.addWithdrawIx(collateralAmount);
436
+ }
457
437
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
458
438
  return axn;
459
439
  }
@@ -472,7 +452,7 @@ class KaminoAction {
472
452
  * @param includeUserMetadata - if true it includes user metadata
473
453
  * @param referrer
474
454
  */
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' }) {
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' }) {
476
456
  const axn = await KaminoAction.initialize('repay', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot, payer);
477
457
  const addInitObligationForFarm = true;
478
458
  if (extraComputeBudget > 0) {
@@ -487,12 +467,17 @@ class KaminoAction {
487
467
  if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
488
468
  await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
489
469
  }
490
- await axn.addSupportIxs('repay', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, false, createLookupTable);
491
- axn.addRepayIx();
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
+ }
492
477
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
493
478
  return axn;
494
479
  }
495
- static async buildLiquidateTxns(kaminoMarket, amount, minCollateralReceiveAmount, repayTokenMint, withdrawTokenMint, liquidator, obligationOwner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
480
+ static async buildLiquidateTxns(kaminoMarket, amount, minCollateralReceiveAmount, repayTokenMint, withdrawTokenMint, liquidator, obligationOwner, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
496
481
  includeAtaIxns = true, // if true it includes create and close wsol and token atas, and creates all other token atas if they don't exist
497
482
  requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
498
483
  createLookupTable = true, referrer = web3_js_1.PublicKey.default, maxAllowedLtvOverridePercent = 0, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
@@ -511,8 +496,13 @@ class KaminoAction {
511
496
  if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
512
497
  await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
513
498
  }
514
- await axn.addSupportIxs('liquidate', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, false, createLookupTable);
515
- axn.addLiquidateIx(maxAllowedLtvOverridePercent);
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
+ }
516
506
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
517
507
  return axn;
518
508
  }
@@ -582,31 +572,29 @@ class KaminoAction {
582
572
  return '';
583
573
  return await sendTransaction(txn, this.kaminoMarket.getConnection());
584
574
  }
585
- addDepositIx() {
586
- this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
587
- this.lendingIxs.push((0, instructions_1.depositReserveLiquidityAndObligationCollateral)({
575
+ addDepositReserveLiquidityIx() {
576
+ this.lendingIxsLabels.push(`depositReserveLiquidity`);
577
+ this.lendingIxs.push((0, instructions_1.depositReserveLiquidity)({
588
578
  liquidityAmount: this.amount,
589
579
  }, {
590
580
  owner: this.owner,
591
- obligation: this.getObligationPda(),
592
581
  lendingMarket: this.kaminoMarket.getAddress(),
593
582
  lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
594
583
  reserve: this.reserve.address,
595
584
  reserveLiquidityMint: this.reserve.getLiquidityMint(),
596
585
  reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
597
586
  reserveCollateralMint: this.reserve.getCTokenMint(),
598
- reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
599
587
  userSourceLiquidity: this.userTokenAccountAddress,
600
- placeholderUserDestinationCollateral: this.kaminoMarket.programId,
588
+ userDestinationCollateral: this.userCollateralAccountAddress,
601
589
  collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
602
590
  liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
603
591
  instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
604
592
  }, this.kaminoMarket.programId));
605
593
  }
606
- addDepositReserveLiquidityIx() {
607
- this.lendingIxsLabels.push(`depositReserveLiquidity`);
608
- this.lendingIxs.push((0, instructions_1.depositReserveLiquidity)({
609
- liquidityAmount: this.amount,
594
+ addRedeemReserveCollateralIx() {
595
+ this.lendingIxsLabels.push(`redeemReserveCollateral`);
596
+ this.lendingIxs.push((0, instructions_1.redeemReserveCollateral)({
597
+ collateralAmount: this.amount,
610
598
  }, {
611
599
  owner: this.owner,
612
600
  lendingMarket: this.kaminoMarket.getAddress(),
@@ -615,32 +603,70 @@ class KaminoAction {
615
603
  reserveLiquidityMint: this.reserve.getLiquidityMint(),
616
604
  reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
617
605
  reserveCollateralMint: this.reserve.getCTokenMint(),
618
- userSourceLiquidity: this.userTokenAccountAddress,
619
- userDestinationCollateral: this.userCollateralAccountAddress,
606
+ userSourceCollateral: this.userCollateralAccountAddress,
607
+ userDestinationLiquidity: this.userTokenAccountAddress,
620
608
  collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
621
609
  liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
622
610
  instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
623
611
  }, this.kaminoMarket.programId));
624
612
  }
625
- addRedeemReserveCollateralIx() {
626
- this.lendingIxsLabels.push(`redeemReserveCollateral`);
627
- this.lendingIxs.push((0, instructions_1.redeemReserveCollateral)({
628
- collateralAmount: this.amount,
613
+ // @deprecated -- use addDepositIxV2 instead
614
+ addDepositIx() {
615
+ this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
616
+ this.lendingIxs.push((0, instructions_1.depositReserveLiquidityAndObligationCollateral)({
617
+ liquidityAmount: this.amount,
629
618
  }, {
630
619
  owner: this.owner,
620
+ obligation: this.getObligationPda(),
631
621
  lendingMarket: this.kaminoMarket.getAddress(),
632
622
  lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
633
623
  reserve: this.reserve.address,
634
624
  reserveLiquidityMint: this.reserve.getLiquidityMint(),
635
625
  reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
636
626
  reserveCollateralMint: this.reserve.getCTokenMint(),
637
- userSourceCollateral: this.userCollateralAccountAddress,
638
- userDestinationLiquidity: this.userTokenAccountAddress,
627
+ reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
628
+ userSourceLiquidity: this.userTokenAccountAddress,
629
+ placeholderUserDestinationCollateral: this.kaminoMarket.programId,
639
630
  collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
640
631
  liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
641
632
  instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
642
633
  }, this.kaminoMarket.programId));
643
634
  }
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
644
670
  addDepositObligationCollateralIx() {
645
671
  this.lendingIxsLabels.push(`depositObligationCollateral`);
646
672
  this.lendingIxs.push((0, instructions_1.depositObligationCollateral)({
@@ -656,6 +682,36 @@ class KaminoAction {
656
682
  instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
657
683
  }, this.kaminoMarket.programId));
658
684
  }
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
659
715
  addBorrowIx() {
660
716
  this.lendingIxsLabels.push(`borrowObligationLiquidity`);
661
717
  const depositReservesList = this.getAdditionalDepositReservesList();
@@ -684,7 +740,165 @@ class KaminoAction {
684
740
  : borrowIx.keys;
685
741
  this.lendingIxs.push(borrowIx);
686
742
  }
687
- addDepositAndBorrowIx() {
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() {
688
902
  this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
689
903
  this.lendingIxsLabels.push(`borrowObligationLiquidity`);
690
904
  this.lendingIxs.push((0, instructions_1.depositReserveLiquidityAndObligationCollateral)({
@@ -740,7 +954,89 @@ class KaminoAction {
740
954
  borrowIx.keys = borrowIx.keys.concat([...depositReserveAccountMetas]);
741
955
  this.lendingIxs.push(borrowIx);
742
956
  }
743
- addRepayAndWithdrawIxs(withdrawCollateralAmount) {
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) {
744
1040
  this.lendingIxsLabels.push(`repayObligationLiquidity(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`);
745
1041
  this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateral`);
746
1042
  const depositReservesList = this.getAdditionalDepositReservesList();
@@ -790,45 +1086,24 @@ class KaminoAction {
790
1086
  instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
791
1087
  }, this.kaminoMarket.programId));
792
1088
  }
793
- addRepayAndWithdrawV2Ixs(withdrawCollateralAmount) {
794
- this.lendingIxsLabels.push(`repayAndWithdrawAndRedeem(repayReserve=${this.reserve.address})(withdrawReserve=${this.outflowReserve.address})(obligation=${this.getObligationPda()})`);
1089
+ async addRepayAndWithdrawIxsV2(withdrawCollateralAmount) {
1090
+ this.lendingIxsLabels.push(`repayObligationLiquidityV2(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`);
1091
+ this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateralV2`);
795
1092
  const depositReservesList = this.getAdditionalDepositReservesList();
796
1093
  const depositReserveAccountMetas = depositReservesList.map((reserve) => {
797
1094
  return { pubkey: reserve, isSigner: false, isWritable: true };
798
1095
  });
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
- };
820
1096
  const debtFarmsAccounts = this.reserve.state.farmDebt.equals(web3_js_1.PublicKey.default)
821
1097
  ? {
822
- obligationFarmUserState: this.kaminoMarket.programId,
823
- reserveFarmState: this.kaminoMarket.programId,
1098
+ obligationFarmUserState: lib_1.PROGRAM_ID,
1099
+ reserveFarmState: lib_1.PROGRAM_ID,
824
1100
  }
825
1101
  : {
826
- obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.reserve.state.farmDebt, this.getObligationPda()),
1102
+ obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmDebt)[0],
827
1103
  reserveFarmState: this.reserve.state.farmDebt,
828
1104
  };
829
- const repayAndWithdrawIx = (0, instructions_1.repayAndWithdrawAndRedeem)({
830
- repayAmount: this.amount,
831
- withdrawCollateralAmount,
1105
+ const repayIx = (0, instructions_1.repayObligationLiquidityV2)({
1106
+ liquidityAmount: this.amount,
832
1107
  }, {
833
1108
  repayAccounts: {
834
1109
  owner: this.owner,
@@ -841,88 +1116,33 @@ class KaminoAction {
841
1116
  tokenProgram: this.reserve.getLiquidityTokenProgram(),
842
1117
  instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
843
1118
  },
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,
1119
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1120
+ farmsAccounts: debtFarmsAccounts,
862
1121
  farmsProgram: farms_sdk_1.farmsId,
863
1122
  }, this.kaminoMarket.programId);
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
- }
1123
+ repayIx.keys = repayIx.keys.concat([...depositReserveAccountMetas]);
1124
+ this.lendingIxs.push(repayIx);
882
1125
  if (!this.outflowReserve) {
883
1126
  throw new Error(`outflowReserve not set`);
884
1127
  }
885
1128
  if (!this.additionalTokenAccountAddress) {
886
1129
  throw new Error(`additionalTokenAccountAddress not set`);
887
1130
  }
888
- const depositFarmsAccounts = this.reserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
889
- ? {
890
- obligationFarmUserState: this.kaminoMarket.programId,
891
- reserveFarmState: this.kaminoMarket.programId,
892
- }
893
- : {
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)
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)
898
1135
  ? {
899
- obligationFarmUserState: this.kaminoMarket.programId,
900
- reserveFarmState: this.kaminoMarket.programId,
1136
+ obligationFarmUserState: lib_1.PROGRAM_ID,
1137
+ reserveFarmState: lib_1.PROGRAM_ID,
901
1138
  }
902
1139
  : {
903
- obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.outflowReserve.state.farmCollateral, this.getObligationPda()),
1140
+ obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.outflowReserve.state.farmCollateral)[0],
904
1141
  reserveFarmState: this.outflowReserve.state.farmCollateral,
905
1142
  };
906
- const depositAndWithdrawIx = (0, instructions_1.depositAndWithdraw)({
907
- liquidityAmount: this.amount,
908
- withdrawCollateralAmount,
1143
+ this.lendingIxs.push((0, instructions_1.withdrawObligationCollateralAndRedeemReserveCollateralV2)({
1144
+ collateralAmount: withdrawCollateralAmount,
909
1145
  }, {
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
- },
926
1146
  withdrawAccounts: {
927
1147
  owner: this.owner,
928
1148
  obligation: this.getObligationPda(),
@@ -939,61 +1159,11 @@ class KaminoAction {
939
1159
  liquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
940
1160
  instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
941
1161
  },
942
- depositFarmsAccounts,
943
- withdrawFarmsAccounts,
1162
+ farmsAccounts: collateralFarmsAccounts,
944
1163
  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,
971
1164
  }, this.kaminoMarket.programId));
972
1165
  }
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) {
1166
+ async addLiquidateIx(maxAllowedLtvOverridePercent = 0) {
997
1167
  this.lendingIxsLabels.push(`liquidateObligationAndRedeemReserveCollateral`);
998
1168
  if (!this.outflowReserve) {
999
1169
  throw Error(`Withdraw reserve during liquidation is not defined`);
@@ -1038,8 +1208,76 @@ class KaminoAction {
1038
1208
  : liquidateIx.keys;
1039
1209
  this.lendingIxs.push(liquidateIx);
1040
1210
  }
1041
- async addInBetweenIxs(action, includeAtaIxns, requestElevationGroup, addInitObligationForFarm) {
1042
- await this.addSupportIxsWithoutInitObligation(action, includeAtaIxns, false, 'inBetween', requestElevationGroup, addInitObligationForFarm);
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);
1043
1281
  }
1044
1282
  addRefreshObligation(crank) {
1045
1283
  const uniqueReserveAddresses = new utils_1.PublicKeySet(this.depositReserves.concat(this.borrowReserves)).toArray();
@@ -1065,7 +1303,6 @@ class KaminoAction {
1065
1303
  'repay',
1066
1304
  'depositAndBorrow',
1067
1305
  'repayAndWithdraw',
1068
- 'repayAndWithdrawV2',
1069
1306
  'refreshObligation',
1070
1307
  ].includes(action)) {
1071
1308
  // The support ixns in order are:
@@ -1081,14 +1318,11 @@ class KaminoAction {
1081
1318
  // 7. Ixn to refresh the `debt` farm of the obligation
1082
1319
  // 8. Ixn to refresh the `collateral` farm of the obligation
1083
1320
  let currentReserves = [];
1084
- if (action === 'liquidate' ||
1085
- action === 'depositAndBorrow' ||
1086
- action === 'repayAndWithdraw' ||
1087
- action === 'repayAndWithdrawV2') {
1321
+ if (action === 'liquidate' || action === 'depositAndBorrow' || action === 'repayAndWithdraw') {
1088
1322
  if (!this.outflowReserve) {
1089
1323
  throw new Error('outflowReserve is undefined');
1090
1324
  }
1091
- if (action === 'depositAndBorrow' || action === 'repayAndWithdraw' || action === 'repayAndWithdrawV2') {
1325
+ if (action === 'depositAndBorrow' || action === 'repayAndWithdraw') {
1092
1326
  currentReserves = [this.reserve, this.outflowReserve];
1093
1327
  if (action === 'depositAndBorrow') {
1094
1328
  if (this.obligation) {
@@ -1132,10 +1366,7 @@ class KaminoAction {
1132
1366
  await this.addInitObligationForFarm(this.outflowReserve, types_1.ReserveFarmKind.Debt, addAsSupportIx);
1133
1367
  }
1134
1368
  }
1135
- else if (action === 'repayAndWithdraw' ||
1136
- action === 'borrow' ||
1137
- action === 'repay' ||
1138
- action === 'repayAndWithdrawV2') {
1369
+ else if (action === 'repayAndWithdraw' || action === 'borrow' || action === 'repay') {
1139
1370
  // todo - probably don't need to add both debt and collateral for everything here
1140
1371
  await this.addInitObligationForFarm(this.reserve, types_1.ReserveFarmKind.Debt, addAsSupportIx);
1141
1372
  if (this.outflowReserve) {
@@ -1166,7 +1397,7 @@ class KaminoAction {
1166
1397
  this.addRefreshObligationIx(addAsSupportIx);
1167
1398
  }
1168
1399
  if (requestElevationGroup) {
1169
- if (action === 'repay' || action === 'repayAndWithdrawV2') {
1400
+ if (action === 'repay') {
1170
1401
  const repayObligationLiquidity = this.obligation.borrows.get(this.reserve.address);
1171
1402
  if (!repayObligationLiquidity) {
1172
1403
  throw new Error(`Could not find debt reserve ${this.reserve.address} in obligation`);
@@ -1310,7 +1541,7 @@ class KaminoAction {
1310
1541
  if (action === 'deposit' && this.outflowReserve) {
1311
1542
  await this.addInitReferrerTokenStateIx(this.outflowReserve);
1312
1543
  }
1313
- this.addInitObligationIxs();
1544
+ await this.addInitObligationIxs();
1314
1545
  }
1315
1546
  await this.addSupportIxsWithoutInitObligation(action, includeAtaIxns, useV2Ixs, 'setup', requestElevationGroup, addInitObligationForFarm, twoTokenAction, overrideElevationGroupRequest);
1316
1547
  }
@@ -1466,7 +1697,7 @@ class KaminoAction {
1466
1697
  farms.push([
1467
1698
  types_1.ReserveFarmKind.Collateral,
1468
1699
  kaminoReserve.state.farmCollateral,
1469
- (0, utils_1.obligationFarmStatePda)(kaminoReserve.state.farmCollateral, this.getObligationPda()),
1700
+ (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), kaminoReserve.state.farmCollateral)[0],
1470
1701
  kaminoReserve,
1471
1702
  ]);
1472
1703
  }
@@ -1474,7 +1705,7 @@ class KaminoAction {
1474
1705
  farms.push([
1475
1706
  types_1.ReserveFarmKind.Debt,
1476
1707
  kaminoReserve.state.farmDebt,
1477
- (0, utils_1.obligationFarmStatePda)(kaminoReserve.state.farmDebt, this.getObligationPda()),
1708
+ (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), kaminoReserve.state.farmDebt)[0],
1478
1709
  kaminoReserve,
1479
1710
  ]);
1480
1711
  }
@@ -1524,17 +1755,17 @@ class KaminoAction {
1524
1755
  async addInitObligationForFarm(reserve, mode, addAsSupportIx = 'setup') {
1525
1756
  const farms = [];
1526
1757
  if (mode === types_1.ReserveFarmKind.Collateral && (0, utils_1.isNotNullPubkey)(reserve.state.farmCollateral)) {
1527
- const pda = (0, utils_1.obligationFarmStatePda)(reserve.state.farmCollateral, this.getObligationPda());
1528
- const account = await this.kaminoMarket.getConnection().getAccountInfo(pda);
1758
+ const userPda = (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), reserve.state.farmCollateral)[0];
1759
+ const account = await this.kaminoMarket.getConnection().getAccountInfo(userPda);
1529
1760
  if (!account) {
1530
- farms.push([types_1.ReserveFarmKind.Collateral.discriminator, reserve.state.farmCollateral, pda]);
1761
+ farms.push([types_1.ReserveFarmKind.Collateral.discriminator, reserve.state.farmCollateral, userPda]);
1531
1762
  }
1532
1763
  }
1533
1764
  if (mode === types_1.ReserveFarmKind.Debt && (0, utils_1.isNotNullPubkey)(reserve.state.farmDebt)) {
1534
- const pda = (0, utils_1.obligationFarmStatePda)(reserve.state.farmDebt, this.getObligationPda());
1535
- const account = await this.kaminoMarket.getConnection().getAccountInfo(pda);
1765
+ const userPda = (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), reserve.state.farmDebt)[0];
1766
+ const account = await this.kaminoMarket.getConnection().getAccountInfo(userPda);
1536
1767
  if (!account) {
1537
- farms.push([types_1.ReserveFarmKind.Debt.discriminator, reserve.state.farmDebt, pda]);
1768
+ farms.push([types_1.ReserveFarmKind.Debt.discriminator, reserve.state.farmDebt, userPda]);
1538
1769
  }
1539
1770
  }
1540
1771
  farms.forEach((arg) => {
@@ -1563,7 +1794,7 @@ class KaminoAction {
1563
1794
  }
1564
1795
  });
1565
1796
  }
1566
- addInitObligationIxs() {
1797
+ async addInitObligationIxs() {
1567
1798
  if (!this.obligation) {
1568
1799
  const obligationPda = this.getObligationPda();
1569
1800
  const [userMetadataAddress, _bump] = (0, utils_1.userMetadataPda)(this.owner, this.kaminoMarket.programId);
@@ -1705,13 +1936,14 @@ class KaminoAction {
1705
1936
  return;
1706
1937
  }
1707
1938
  let safeRepay = new bn_js_1.default(this.amount);
1708
- if (this.obligation && (action === 'repay' || action === 'repayAndWithdrawV2') && this.amount.eq(new bn_js_1.default(utils_1.U64_MAX))) {
1939
+ if (this.obligation && action === 'repay' && this.amount.eq(new bn_js_1.default(utils_1.U64_MAX))) {
1709
1940
  const borrow = this.obligation.state.borrows.find((borrow) => borrow.borrowReserve.toString() === this.reserve.address.toString());
1710
1941
  if (!borrow) {
1711
1942
  throw Error(`Unable to find obligation borrow to repay for ${this.obligation.state.owner.toBase58()}`);
1712
1943
  }
1713
1944
  const cumulativeBorrowRateObligation = obligation_1.KaminoObligation.getCumulativeBorrowRate(borrow);
1714
1945
  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?
1715
1947
  safeRepay = new bn_js_1.default(Math.floor(obligation_1.KaminoObligation.getBorrowAmount(borrow)
1716
1948
  .mul(cumulativeBorrowRateReserve)
1717
1949
  .div(cumulativeBorrowRateObligation)
@@ -1730,7 +1962,6 @@ class KaminoAction {
1730
1962
  // Add rent exemption lamports for WSOL accounts that need to be pre-funded for inflow/send transactions
1731
1963
  const sendAction = action === 'deposit' ||
1732
1964
  action === 'repay' ||
1733
- action === 'repayAndWithdrawV2' ||
1734
1965
  action === 'mint' ||
1735
1966
  (action === 'liquidate' && this.secondaryMint?.equals(spl_token_1.NATIVE_MINT)); // only sync WSOL amount if liquidator repays SOL which is secondaryMint
1736
1967
  const transferLamportsIx = web3_js_1.SystemProgram.transfer({
@@ -1795,7 +2026,7 @@ class KaminoAction {
1795
2026
  primaryMint = inflowTokenMint;
1796
2027
  secondaryMint = outflowTokenMint;
1797
2028
  }
1798
- else if (action === 'repayAndWithdraw' || action === 'repayAndWithdrawV2') {
2029
+ else if (action === 'repayAndWithdraw') {
1799
2030
  primaryMint = inflowTokenMint;
1800
2031
  secondaryMint = outflowTokenMint;
1801
2032
  userTokenAccountAddress = userInflowTokenAccountAddress;