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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/dist/classes/action.d.ts +22 -14
  2. package/dist/classes/action.d.ts.map +1 -1
  3. package/dist/classes/action.js +585 -132
  4. package/dist/classes/action.js.map +1 -1
  5. package/dist/classes/index.d.ts +0 -3
  6. package/dist/classes/index.d.ts.map +1 -1
  7. package/dist/classes/index.js +0 -3
  8. package/dist/classes/index.js.map +1 -1
  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 -6
  12. package/dist/classes/obligation.d.ts.map +1 -1
  13. package/dist/classes/obligation.js +2 -4
  14. package/dist/classes/obligation.js.map +1 -1
  15. package/dist/classes/types.d.ts +1 -13
  16. package/dist/classes/types.d.ts.map +1 -1
  17. package/dist/idl.json +71 -5
  18. package/dist/idl_codegen/accounts/Obligation.d.ts +6 -0
  19. package/dist/idl_codegen/accounts/Obligation.d.ts.map +1 -1
  20. package/dist/idl_codegen/accounts/Obligation.js +8 -1
  21. package/dist/idl_codegen/accounts/Obligation.js.map +1 -1
  22. package/dist/idl_codegen/errors/custom.d.ts +35 -3
  23. package/dist/idl_codegen/errors/custom.d.ts.map +1 -1
  24. package/dist/idl_codegen/errors/custom.js +61 -5
  25. package/dist/idl_codegen/errors/custom.js.map +1 -1
  26. package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.d.ts +9 -0
  27. package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.d.ts.map +1 -1
  28. package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.js +22 -1
  29. package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.js.map +1 -1
  30. package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js +1 -1
  31. package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js.map +1 -1
  32. package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.js +1 -1
  33. package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.js.map +1 -1
  34. package/dist/idl_codegen/zero_padding/ObligationZP.d.ts +2 -0
  35. package/dist/idl_codegen/zero_padding/ObligationZP.d.ts.map +1 -1
  36. package/dist/idl_codegen/zero_padding/ObligationZP.js +6 -1
  37. package/dist/idl_codegen/zero_padding/ObligationZP.js.map +1 -1
  38. package/dist/lending_operations/repay_with_collateral_operations.d.ts +3 -2
  39. package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
  40. package/dist/lending_operations/repay_with_collateral_operations.js +7 -6
  41. package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
  42. package/dist/lending_operations/swap_collateral_operations.d.ts +5 -0
  43. package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
  44. package/dist/lending_operations/swap_collateral_operations.js +4 -2
  45. package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
  46. package/dist/leverage/calcs.d.ts +1 -1
  47. package/dist/leverage/calcs.d.ts.map +1 -1
  48. package/dist/leverage/calcs.js +10 -12
  49. package/dist/leverage/calcs.js.map +1 -1
  50. package/dist/leverage/operations.d.ts +8 -8
  51. package/dist/leverage/operations.d.ts.map +1 -1
  52. package/dist/leverage/operations.js +27 -24
  53. package/dist/leverage/operations.js.map +1 -1
  54. package/dist/leverage/types.d.ts +4 -1
  55. package/dist/leverage/types.d.ts.map +1 -1
  56. package/dist/utils/seeds.d.ts +5 -0
  57. package/dist/utils/seeds.d.ts.map +1 -1
  58. package/dist/utils/seeds.js +10 -1
  59. package/dist/utils/seeds.js.map +1 -1
  60. package/dist/utils/userMetadata.d.ts.map +1 -1
  61. package/dist/utils/userMetadata.js +6 -9
  62. package/dist/utils/userMetadata.js.map +1 -1
  63. package/package.json +4 -4
  64. package/src/classes/action.ts +749 -146
  65. package/src/classes/index.ts +0 -3
  66. package/src/classes/manager.ts +1 -1
  67. package/src/classes/obligation.ts +4 -8
  68. package/src/classes/types.ts +1 -17
  69. package/src/client.ts +7 -3
  70. package/src/idl.json +71 -5
  71. package/src/idl_codegen/accounts/Obligation.ts +12 -1
  72. package/src/idl_codegen/errors/custom.ts +66 -4
  73. package/src/idl_codegen/instructions/repayAndWithdrawAndRedeem.ts +31 -1
  74. package/src/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.ts +1 -1
  75. package/src/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.ts +1 -1
  76. package/src/idl_codegen/zero_padding/ObligationZP.ts +6 -1
  77. package/src/lending_operations/repay_with_collateral_operations.ts +11 -3
  78. package/src/lending_operations/swap_collateral_operations.ts +11 -0
  79. package/src/leverage/calcs.ts +13 -16
  80. package/src/leverage/operations.ts +38 -11
  81. package/src/leverage/types.ts +4 -1
  82. package/src/utils/seeds.ts +13 -0
  83. package/src/utils/userMetadata.ts +19 -24
  84. package/dist/classes/stakePool.d.ts +0 -8
  85. package/dist/classes/stakePool.d.ts.map +0 -1
  86. package/dist/classes/stakePool.js +0 -18
  87. package/dist/classes/stakePool.js.map +0 -1
  88. package/dist/classes/standardStakePool.d.ts +0 -174
  89. package/dist/classes/standardStakePool.d.ts.map +0 -1
  90. package/dist/classes/standardStakePool.js +0 -275
  91. package/dist/classes/standardStakePool.js.map +0 -1
  92. package/dist/classes/unstakingPool.d.ts +0 -117
  93. package/dist/classes/unstakingPool.d.ts.map +0 -1
  94. package/dist/classes/unstakingPool.js +0 -448
  95. package/dist/classes/unstakingPool.js.map +0 -1
  96. package/dist/idl_codegen_unstaking_pool/accounts/PoolState.d.ts +0 -50
  97. package/dist/idl_codegen_unstaking_pool/accounts/PoolState.d.ts.map +0 -1
  98. package/dist/idl_codegen_unstaking_pool/accounts/PoolState.js +0 -156
  99. package/dist/idl_codegen_unstaking_pool/accounts/PoolState.js.map +0 -1
  100. package/dist/idl_codegen_unstaking_pool/accounts/index.d.ts +0 -3
  101. package/dist/idl_codegen_unstaking_pool/accounts/index.d.ts.map +0 -1
  102. package/dist/idl_codegen_unstaking_pool/accounts/index.js +0 -6
  103. package/dist/idl_codegen_unstaking_pool/accounts/index.js.map +0 -1
  104. package/dist/idl_codegen_unstaking_pool/errors/anchor.d.ts +0 -435
  105. package/dist/idl_codegen_unstaking_pool/errors/anchor.d.ts.map +0 -1
  106. package/dist/idl_codegen_unstaking_pool/errors/anchor.js +0 -767
  107. package/dist/idl_codegen_unstaking_pool/errors/anchor.js.map +0 -1
  108. package/dist/idl_codegen_unstaking_pool/errors/custom.d.ts +0 -163
  109. package/dist/idl_codegen_unstaking_pool/errors/custom.d.ts.map +0 -1
  110. package/dist/idl_codegen_unstaking_pool/errors/custom.js +0 -290
  111. package/dist/idl_codegen_unstaking_pool/errors/custom.js.map +0 -1
  112. package/dist/idl_codegen_unstaking_pool/errors/index.d.ts +0 -6
  113. package/dist/idl_codegen_unstaking_pool/errors/index.d.ts.map +0 -1
  114. package/dist/idl_codegen_unstaking_pool/errors/index.js +0 -75
  115. package/dist/idl_codegen_unstaking_pool/errors/index.js.map +0 -1
  116. package/dist/idl_codegen_unstaking_pool/instructions/burn.d.ts +0 -21
  117. package/dist/idl_codegen_unstaking_pool/instructions/burn.d.ts.map +0 -1
  118. package/dist/idl_codegen_unstaking_pool/instructions/burn.js +0 -73
  119. package/dist/idl_codegen_unstaking_pool/instructions/burn.js.map +0 -1
  120. package/dist/idl_codegen_unstaking_pool/instructions/collect.d.ts +0 -16
  121. package/dist/idl_codegen_unstaking_pool/instructions/collect.d.ts.map +0 -1
  122. package/dist/idl_codegen_unstaking_pool/instructions/collect.js +0 -29
  123. package/dist/idl_codegen_unstaking_pool/instructions/collect.js.map +0 -1
  124. package/dist/idl_codegen_unstaking_pool/instructions/index.d.ts +0 -11
  125. package/dist/idl_codegen_unstaking_pool/instructions/index.d.ts.map +0 -1
  126. package/dist/idl_codegen_unstaking_pool/instructions/index.js +0 -14
  127. package/dist/idl_codegen_unstaking_pool/instructions/index.js.map +0 -1
  128. package/dist/idl_codegen_unstaking_pool/instructions/initializePool.d.ts +0 -15
  129. package/dist/idl_codegen_unstaking_pool/instructions/initializePool.d.ts.map +0 -1
  130. package/dist/idl_codegen_unstaking_pool/instructions/initializePool.js +0 -28
  131. package/dist/idl_codegen_unstaking_pool/instructions/initializePool.js.map +0 -1
  132. package/dist/idl_codegen_unstaking_pool/instructions/mint.d.ts +0 -21
  133. package/dist/idl_codegen_unstaking_pool/instructions/mint.d.ts.map +0 -1
  134. package/dist/idl_codegen_unstaking_pool/instructions/mint.js +0 -77
  135. package/dist/idl_codegen_unstaking_pool/instructions/mint.js.map +0 -1
  136. package/dist/idl_codegen_unstaking_pool/instructions/updatePoolConfig.d.ts +0 -13
  137. package/dist/idl_codegen_unstaking_pool/instructions/updatePoolConfig.d.ts.map +0 -1
  138. package/dist/idl_codegen_unstaking_pool/instructions/updatePoolConfig.js +0 -58
  139. package/dist/idl_codegen_unstaking_pool/instructions/updatePoolConfig.js.map +0 -1
  140. package/dist/idl_codegen_unstaking_pool/programId.d.ts +0 -4
  141. package/dist/idl_codegen_unstaking_pool/programId.d.ts.map +0 -1
  142. package/dist/idl_codegen_unstaking_pool/programId.js +0 -9
  143. package/dist/idl_codegen_unstaking_pool/programId.js.map +0 -1
  144. package/dist/idl_codegen_unstaking_pool/types/PoolConfigField.d.ts +0 -32
  145. package/dist/idl_codegen_unstaking_pool/types/PoolConfigField.d.ts.map +0 -1
  146. package/dist/idl_codegen_unstaking_pool/types/PoolConfigField.js +0 -105
  147. package/dist/idl_codegen_unstaking_pool/types/PoolConfigField.js.map +0 -1
  148. package/dist/idl_codegen_unstaking_pool/types/index.d.ts +0 -5
  149. package/dist/idl_codegen_unstaking_pool/types/index.d.ts.map +0 -1
  150. package/dist/idl_codegen_unstaking_pool/types/index.js +0 -39
  151. package/dist/idl_codegen_unstaking_pool/types/index.js.map +0 -1
  152. package/src/classes/stakePool.ts +0 -21
  153. package/src/classes/standardStakePool.ts +0 -358
  154. package/src/classes/unstakingPool.ts +0 -577
  155. package/src/idl_codegen_unstaking_pool/accounts/PoolState.ts +0 -163
  156. package/src/idl_codegen_unstaking_pool/accounts/index.ts +0 -2
  157. package/src/idl_codegen_unstaking_pool/errors/anchor.ts +0 -764
  158. package/src/idl_codegen_unstaking_pool/errors/custom.ts +0 -288
  159. package/src/idl_codegen_unstaking_pool/errors/index.ts +0 -49
  160. package/src/idl_codegen_unstaking_pool/instructions/burn.ts +0 -60
  161. package/src/idl_codegen_unstaking_pool/instructions/collect.ts +0 -43
  162. package/src/idl_codegen_unstaking_pool/instructions/index.ts +0 -10
  163. package/src/idl_codegen_unstaking_pool/instructions/initializePool.ts +0 -41
  164. package/src/idl_codegen_unstaking_pool/instructions/mint.ts +0 -64
  165. package/src/idl_codegen_unstaking_pool/instructions/updatePoolConfig.ts +0 -40
  166. package/src/idl_codegen_unstaking_pool/programId.ts +0 -7
  167. package/src/idl_codegen_unstaking_pool/types/PoolConfigField.ts +0 -85
  168. package/src/idl_codegen_unstaking_pool/types/index.ts +0 -6
  169. package/src/idl_unstaking_pool.json +0 -456
@@ -21,9 +21,12 @@ import BN from 'bn.js';
21
21
  import Decimal from 'decimal.js';
22
22
  import {
23
23
  borrowObligationLiquidity,
24
+ borrowObligationLiquidityV2,
24
25
  depositObligationCollateral,
26
+ depositObligationCollateralV2,
25
27
  depositReserveLiquidity,
26
28
  depositReserveLiquidityAndObligationCollateral,
29
+ depositReserveLiquidityAndObligationCollateralV2,
27
30
  initObligation,
28
31
  initObligationFarmsForReserve,
29
32
  InitObligationFarmsForReserveAccounts,
@@ -31,6 +34,7 @@ import {
31
34
  initReferrerTokenState,
32
35
  initUserMetadata,
33
36
  liquidateObligationAndRedeemReserveCollateral,
37
+ liquidateObligationAndRedeemReserveCollateralV2,
34
38
  redeemReserveCollateral,
35
39
  refreshObligation,
36
40
  refreshObligationFarmsForReserve,
@@ -38,10 +42,12 @@ import {
38
42
  RefreshObligationFarmsForReserveArgs,
39
43
  refreshReserve,
40
44
  repayObligationLiquidity,
45
+ repayObligationLiquidityV2,
41
46
  requestElevationGroup,
42
47
  RequestElevationGroupAccounts,
43
48
  RequestElevationGroupArgs,
44
49
  withdrawObligationCollateralAndRedeemReserveCollateral,
50
+ withdrawObligationCollateralAndRedeemReserveCollateralV2,
45
51
  withdrawReferrerFees,
46
52
  } from '../idl_codegen/instructions';
47
53
  import {
@@ -59,6 +65,7 @@ import {
59
65
  ScopeRefresh,
60
66
  createAtasIdempotent,
61
67
  POSITION_LIMIT,
68
+ obligationFarmStatePda,
62
69
  } from '../utils';
63
70
  import { KaminoMarket } from './market';
64
71
  import { KaminoObligation } from './obligation';
@@ -409,6 +416,7 @@ export class KaminoAction {
409
416
  mint: PublicKey,
410
417
  owner: PublicKey,
411
418
  obligation: KaminoObligation | ObligationType,
419
+ useV2Ixs: boolean,
412
420
  extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
413
421
  includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
414
422
  requestElevationGroup: boolean = false, // to be requested *before* the deposit
@@ -450,10 +458,15 @@ export class KaminoAction {
450
458
  requestElevationGroup,
451
459
  includeUserMetadata,
452
460
  addInitObligationForFarm,
461
+ useV2Ixs,
453
462
  undefined,
454
463
  overrideElevationGroupRequest
455
464
  );
456
- axn.addDepositIx();
465
+ if (useV2Ixs) {
466
+ axn.addDepositIxV2();
467
+ } else {
468
+ axn.addDepositIx();
469
+ }
457
470
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
458
471
 
459
472
  return axn;
@@ -503,6 +516,7 @@ export class KaminoAction {
503
516
  mint: PublicKey,
504
517
  owner: PublicKey,
505
518
  obligation: KaminoObligation | ObligationType,
519
+ useV2Ixs: boolean,
506
520
  extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
507
521
  includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
508
522
  requestElevationGroup: boolean = false,
@@ -544,10 +558,15 @@ export class KaminoAction {
544
558
  requestElevationGroup,
545
559
  includeUserMetadata,
546
560
  addInitObligationForFarm,
561
+ useV2Ixs,
547
562
  undefined,
548
563
  overrideElevationGroupRequest
549
564
  );
550
- axn.addBorrowIx();
565
+ if (useV2Ixs) {
566
+ axn.addBorrowIxV2();
567
+ } else {
568
+ axn.addBorrowIx();
569
+ }
551
570
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
552
571
 
553
572
  return axn;
@@ -599,7 +618,8 @@ export class KaminoAction {
599
618
  includeAtaIxns,
600
619
  requestElevationGroup,
601
620
  includeUserMetadata,
602
- addInitObligationForFarm
621
+ addInitObligationForFarm,
622
+ false
603
623
  );
604
624
  axn.addDepositReserveLiquidityIx();
605
625
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
@@ -652,7 +672,8 @@ export class KaminoAction {
652
672
  includeAtaIxns,
653
673
  requestElevationGroup,
654
674
  includeUserMetadata,
655
- addInitObligationForFarm
675
+ addInitObligationForFarm,
676
+ false
656
677
  );
657
678
  axn.addRedeemReserveCollateralIx();
658
679
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
@@ -665,6 +686,7 @@ export class KaminoAction {
665
686
  mint: PublicKey,
666
687
  owner: PublicKey,
667
688
  obligation: KaminoObligation | ObligationType,
689
+ useV2Ixs: boolean,
668
690
  extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
669
691
  includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas
670
692
  requestElevationGroup: boolean = false,
@@ -705,9 +727,14 @@ export class KaminoAction {
705
727
  includeAtaIxns,
706
728
  requestElevationGroup,
707
729
  includeUserMetadata,
708
- addInitObligationForFarm
730
+ addInitObligationForFarm,
731
+ useV2Ixs
709
732
  );
710
- axn.addDepositObligationCollateralIx();
733
+ if (useV2Ixs) {
734
+ axn.addDepositObligationCollateralIxV2();
735
+ } else {
736
+ axn.addDepositObligationCollateralIx();
737
+ }
711
738
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
712
739
  return axn;
713
740
  }
@@ -720,6 +747,7 @@ export class KaminoAction {
720
747
  borrowMint: PublicKey,
721
748
  payer: PublicKey,
722
749
  obligation: KaminoObligation | ObligationType,
750
+ useV2Ixs: boolean,
723
751
  extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
724
752
  includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
725
753
  requestElevationGroup: boolean = false,
@@ -767,14 +795,21 @@ export class KaminoAction {
767
795
  requestElevationGroup,
768
796
  includeUserMetadata,
769
797
  addInitObligationForFarmForDeposit,
798
+ useV2Ixs,
770
799
  twoTokenAction
771
800
  );
772
- await axn.addDepositAndBorrowIx();
801
+
802
+ if (useV2Ixs) {
803
+ await axn.addDepositAndBorrowIxV2();
804
+ } else {
805
+ await axn.addDepositAndBorrowIx();
806
+ }
773
807
  await axn.addInBetweenIxs(
774
808
  'depositAndBorrow',
775
809
  includeAtaIxns,
776
810
  requestElevationGroup,
777
- addInitObligationForFarmForBorrow
811
+ addInitObligationForFarmForBorrow,
812
+ useV2Ixs
778
813
  );
779
814
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
780
815
  return axn;
@@ -789,6 +824,7 @@ export class KaminoAction {
789
824
  payer: PublicKey,
790
825
  currentSlot: number,
791
826
  obligation: KaminoObligation | ObligationType,
827
+ useV2Ixs: boolean,
792
828
  extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
793
829
  includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
794
830
  requestElevationGroup: boolean = false,
@@ -834,14 +870,20 @@ export class KaminoAction {
834
870
  requestElevationGroup,
835
871
  includeUserMetadata,
836
872
  addInitObligationForFarmForRepay,
873
+ useV2Ixs,
837
874
  twoTokenAction
838
875
  );
839
- await axn.addRepayAndWithdrawIxs();
876
+ if (useV2Ixs) {
877
+ await axn.addRepayAndWithdrawIxsV2();
878
+ } else {
879
+ await axn.addRepayAndWithdrawIxs();
880
+ }
840
881
  await axn.addInBetweenIxs(
841
882
  'repayAndWithdraw',
842
883
  includeAtaIxns,
843
884
  requestElevationGroup,
844
- addInitObligationForFarmForWithdraw
885
+ addInitObligationForFarmForWithdraw,
886
+ useV2Ixs
845
887
  );
846
888
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
847
889
  return axn;
@@ -853,6 +895,7 @@ export class KaminoAction {
853
895
  mint: PublicKey,
854
896
  owner: PublicKey,
855
897
  obligation: KaminoObligation | ObligationType,
898
+ useV2Ixs: boolean,
856
899
  extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
857
900
  includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
858
901
  requestElevationGroup: boolean = false, // to be requested *after* the withdraw
@@ -902,10 +945,15 @@ export class KaminoAction {
902
945
  requestElevationGroup,
903
946
  includeUserMetadata,
904
947
  addInitObligationForFarm,
948
+ useV2Ixs,
905
949
  false,
906
950
  overrideElevationGroupRequest
907
951
  );
908
- await axn.addWithdrawIx();
952
+ if (useV2Ixs) {
953
+ await axn.addWithdrawIxV2();
954
+ } else {
955
+ await axn.addWithdrawIx();
956
+ }
909
957
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
910
958
 
911
959
  return axn;
@@ -932,6 +980,7 @@ export class KaminoAction {
932
980
  mint: PublicKey,
933
981
  owner: PublicKey,
934
982
  obligation: KaminoObligation | ObligationType,
983
+ useV2Ixs: boolean,
935
984
  currentSlot: number,
936
985
  payer: PublicKey | undefined = undefined,
937
986
  extraComputeBudget: number = 1_000_000,
@@ -974,9 +1023,14 @@ export class KaminoAction {
974
1023
  includeAtaIxns,
975
1024
  requestElevationGroup,
976
1025
  includeUserMetadata,
977
- addInitObligationForFarm
1026
+ addInitObligationForFarm,
1027
+ useV2Ixs
978
1028
  );
979
- await axn.addRepayIx();
1029
+ if (useV2Ixs) {
1030
+ await axn.addRepayIxV2();
1031
+ } else {
1032
+ await axn.addRepayIx();
1033
+ }
980
1034
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
981
1035
 
982
1036
  return axn;
@@ -991,6 +1045,7 @@ export class KaminoAction {
991
1045
  liquidator: PublicKey,
992
1046
  obligationOwner: PublicKey,
993
1047
  obligation: KaminoObligation | ObligationType,
1048
+ useV2Ixs: boolean,
994
1049
  extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
995
1050
  includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas, and creates all other token atas if they don't exist
996
1051
  requestElevationGroup: boolean = false,
@@ -1036,9 +1091,14 @@ export class KaminoAction {
1036
1091
  includeAtaIxns,
1037
1092
  requestElevationGroup,
1038
1093
  includeUserMetadata,
1039
- addInitObligationForFarm
1094
+ addInitObligationForFarm,
1095
+ useV2Ixs
1040
1096
  );
1041
- await axn.addLiquidateIx(maxAllowedLtvOverridePercent);
1097
+ if (useV2Ixs) {
1098
+ await axn.addLiquidateIxV2(maxAllowedLtvOverridePercent);
1099
+ } else {
1100
+ await axn.addLiquidateIx(maxAllowedLtvOverridePercent);
1101
+ }
1042
1102
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
1043
1103
 
1044
1104
  return axn;
@@ -1164,25 +1224,23 @@ export class KaminoAction {
1164
1224
  return await sendTransaction(txn, this.kaminoMarket.getConnection());
1165
1225
  }
1166
1226
 
1167
- addDepositIx() {
1168
- this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
1227
+ addDepositReserveLiquidityIx() {
1228
+ this.lendingIxsLabels.push(`depositReserveLiquidity`);
1169
1229
  this.lendingIxs.push(
1170
- depositReserveLiquidityAndObligationCollateral(
1230
+ depositReserveLiquidity(
1171
1231
  {
1172
1232
  liquidityAmount: this.amount,
1173
1233
  },
1174
1234
  {
1175
1235
  owner: this.owner,
1176
- obligation: this.getObligationPda(),
1177
1236
  lendingMarket: this.kaminoMarket.getAddress(),
1178
1237
  lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1179
1238
  reserve: this.reserve.address,
1180
1239
  reserveLiquidityMint: this.reserve.getLiquidityMint(),
1181
1240
  reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
1182
1241
  reserveCollateralMint: this.reserve.getCTokenMint(),
1183
- reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
1184
1242
  userSourceLiquidity: this.userTokenAccountAddress,
1185
- placeholderUserDestinationCollateral: this.kaminoMarket.programId,
1243
+ userDestinationCollateral: this.userCollateralAccountAddress,
1186
1244
  collateralTokenProgram: TOKEN_PROGRAM_ID,
1187
1245
  liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
1188
1246
  instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
@@ -1192,12 +1250,12 @@ export class KaminoAction {
1192
1250
  );
1193
1251
  }
1194
1252
 
1195
- addDepositReserveLiquidityIx() {
1196
- this.lendingIxsLabels.push(`depositReserveLiquidity`);
1253
+ addRedeemReserveCollateralIx() {
1254
+ this.lendingIxsLabels.push(`redeemReserveCollateral`);
1197
1255
  this.lendingIxs.push(
1198
- depositReserveLiquidity(
1256
+ redeemReserveCollateral(
1199
1257
  {
1200
- liquidityAmount: this.amount,
1258
+ collateralAmount: this.amount,
1201
1259
  },
1202
1260
  {
1203
1261
  owner: this.owner,
@@ -1207,8 +1265,8 @@ export class KaminoAction {
1207
1265
  reserveLiquidityMint: this.reserve.getLiquidityMint(),
1208
1266
  reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
1209
1267
  reserveCollateralMint: this.reserve.getCTokenMint(),
1210
- userSourceLiquidity: this.userTokenAccountAddress,
1211
- userDestinationCollateral: this.userCollateralAccountAddress,
1268
+ userSourceCollateral: this.userCollateralAccountAddress,
1269
+ userDestinationLiquidity: this.userTokenAccountAddress,
1212
1270
  collateralTokenProgram: TOKEN_PROGRAM_ID,
1213
1271
  liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
1214
1272
  instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
@@ -1218,23 +1276,26 @@ export class KaminoAction {
1218
1276
  );
1219
1277
  }
1220
1278
 
1221
- addRedeemReserveCollateralIx() {
1222
- this.lendingIxsLabels.push(`redeemReserveCollateral`);
1279
+ // @deprecated -- use addDepositIxV2 instead
1280
+ addDepositIx() {
1281
+ this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
1223
1282
  this.lendingIxs.push(
1224
- redeemReserveCollateral(
1283
+ depositReserveLiquidityAndObligationCollateral(
1225
1284
  {
1226
- collateralAmount: this.amount,
1285
+ liquidityAmount: this.amount,
1227
1286
  },
1228
1287
  {
1229
1288
  owner: this.owner,
1289
+ obligation: this.getObligationPda(),
1230
1290
  lendingMarket: this.kaminoMarket.getAddress(),
1231
1291
  lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1232
1292
  reserve: this.reserve.address,
1233
1293
  reserveLiquidityMint: this.reserve.getLiquidityMint(),
1234
1294
  reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
1235
1295
  reserveCollateralMint: this.reserve.getCTokenMint(),
1236
- userSourceCollateral: this.userCollateralAccountAddress,
1237
- userDestinationLiquidity: this.userTokenAccountAddress,
1296
+ reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
1297
+ userSourceLiquidity: this.userTokenAccountAddress,
1298
+ placeholderUserDestinationCollateral: this.kaminoMarket.programId,
1238
1299
  collateralTokenProgram: TOKEN_PROGRAM_ID,
1239
1300
  liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
1240
1301
  instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
@@ -1244,6 +1305,52 @@ export class KaminoAction {
1244
1305
  );
1245
1306
  }
1246
1307
 
1308
+ addDepositIxV2() {
1309
+ const farmsAccounts = this.reserve.state.farmCollateral.equals(PublicKey.default)
1310
+ ? {
1311
+ obligationFarmUserState: PROGRAM_ID,
1312
+ reserveFarmState: PROGRAM_ID,
1313
+ }
1314
+ : {
1315
+ obligationFarmUserState: obligationFarmStatePda(
1316
+ this.getObligationPda(),
1317
+ this.reserve.state.farmCollateral
1318
+ )[0],
1319
+ reserveFarmState: this.reserve.state.farmCollateral,
1320
+ };
1321
+
1322
+ this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateralV2`);
1323
+ this.lendingIxs.push(
1324
+ depositReserveLiquidityAndObligationCollateralV2(
1325
+ {
1326
+ liquidityAmount: this.amount,
1327
+ },
1328
+ {
1329
+ depositAccounts: {
1330
+ owner: this.owner,
1331
+ obligation: this.getObligationPda(),
1332
+ lendingMarket: this.kaminoMarket.getAddress(),
1333
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1334
+ reserve: this.reserve.address,
1335
+ reserveLiquidityMint: this.reserve.getLiquidityMint(),
1336
+ reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
1337
+ reserveCollateralMint: this.reserve.getCTokenMint(),
1338
+ reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
1339
+ userSourceLiquidity: this.userTokenAccountAddress,
1340
+ placeholderUserDestinationCollateral: this.kaminoMarket.programId,
1341
+ collateralTokenProgram: TOKEN_PROGRAM_ID,
1342
+ liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
1343
+ instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1344
+ },
1345
+ farmsAccounts,
1346
+ farmsProgram: farmsId,
1347
+ },
1348
+ this.kaminoMarket.programId
1349
+ )
1350
+ );
1351
+ }
1352
+
1353
+ /// @deprecated -- use addDepositObligationCollateralIxV2 instead
1247
1354
  addDepositObligationCollateralIx() {
1248
1355
  this.lendingIxsLabels.push(`depositObligationCollateral`);
1249
1356
  this.lendingIxs.push(
@@ -1266,6 +1373,47 @@ export class KaminoAction {
1266
1373
  );
1267
1374
  }
1268
1375
 
1376
+ addDepositObligationCollateralIxV2() {
1377
+ const farmsAccounts = this.reserve.state.farmCollateral.equals(PublicKey.default)
1378
+ ? {
1379
+ obligationFarmUserState: PROGRAM_ID,
1380
+ reserveFarmState: PROGRAM_ID,
1381
+ }
1382
+ : {
1383
+ obligationFarmUserState: obligationFarmStatePda(
1384
+ this.getObligationPda(),
1385
+ this.reserve.state.farmCollateral
1386
+ )[0],
1387
+ reserveFarmState: this.reserve.state.farmCollateral,
1388
+ };
1389
+
1390
+ this.lendingIxsLabels.push(`depositObligationCollateralV2`);
1391
+ this.lendingIxs.push(
1392
+ depositObligationCollateralV2(
1393
+ {
1394
+ collateralAmount: this.amount,
1395
+ },
1396
+ {
1397
+ depositAccounts: {
1398
+ owner: this.owner,
1399
+ obligation: this.getObligationPda(),
1400
+ lendingMarket: this.kaminoMarket.getAddress(),
1401
+ depositReserve: this.reserve.address,
1402
+ reserveDestinationCollateral: this.reserve.state.collateral.supplyVault,
1403
+ userSourceCollateral: this.userCollateralAccountAddress,
1404
+ tokenProgram: TOKEN_PROGRAM_ID,
1405
+ instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1406
+ },
1407
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1408
+ farmsAccounts,
1409
+ farmsProgram: farmsId,
1410
+ },
1411
+ this.kaminoMarket.programId
1412
+ )
1413
+ );
1414
+ }
1415
+
1416
+ /// @deprecated -- use addDepositObligationCollateralIxV2 instead
1269
1417
  addBorrowIx() {
1270
1418
  this.lendingIxsLabels.push(`borrowObligationLiquidity`);
1271
1419
 
@@ -1302,6 +1450,238 @@ export class KaminoAction {
1302
1450
  this.lendingIxs.push(borrowIx);
1303
1451
  }
1304
1452
 
1453
+ addBorrowIxV2() {
1454
+ this.lendingIxsLabels.push(`borrowObligationLiquidityV2`);
1455
+
1456
+ const depositReservesList = this.getAdditionalDepositReservesList();
1457
+
1458
+ const depositReserveAccountMetas = depositReservesList.map((reserve) => {
1459
+ return { pubkey: reserve, isSigner: false, isWritable: true };
1460
+ });
1461
+
1462
+ const farmsAccounts = this.reserve.state.farmDebt.equals(PublicKey.default)
1463
+ ? {
1464
+ obligationFarmUserState: PROGRAM_ID,
1465
+ reserveFarmState: PROGRAM_ID,
1466
+ }
1467
+ : {
1468
+ obligationFarmUserState: obligationFarmStatePda(this.getObligationPda(), this.reserve.state.farmDebt)[0],
1469
+ reserveFarmState: this.reserve.state.farmDebt,
1470
+ };
1471
+
1472
+ const borrowIx = borrowObligationLiquidityV2(
1473
+ {
1474
+ liquidityAmount: this.amount,
1475
+ },
1476
+ {
1477
+ borrowAccounts: {
1478
+ owner: this.owner,
1479
+ obligation: this.getObligationPda(),
1480
+ lendingMarket: this.kaminoMarket.getAddress(),
1481
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1482
+ borrowReserve: this.reserve.address,
1483
+ borrowReserveLiquidityMint: this.reserve.getLiquidityMint(),
1484
+ reserveSourceLiquidity: this.reserve.state.liquidity.supplyVault,
1485
+ userDestinationLiquidity: this.userTokenAccountAddress,
1486
+ borrowReserveLiquidityFeeReceiver: this.reserve.state.liquidity.feeVault,
1487
+ referrerTokenState: referrerTokenStatePda(
1488
+ this.referrer,
1489
+ this.reserve.address,
1490
+ this.kaminoMarket.programId
1491
+ )[0],
1492
+ tokenProgram: this.reserve.getLiquidityTokenProgram(),
1493
+ instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1494
+ },
1495
+ farmsAccounts,
1496
+ farmsProgram: farmsId,
1497
+ },
1498
+ this.kaminoMarket.programId
1499
+ );
1500
+ borrowIx.keys =
1501
+ this.obligation!.state.elevationGroup > 0 || this.obligation!.refreshedStats.potentialElevationGroupUpdate > 0
1502
+ ? borrowIx.keys.concat([...depositReserveAccountMetas])
1503
+ : borrowIx.keys;
1504
+ this.lendingIxs.push(borrowIx);
1505
+ }
1506
+
1507
+ /// @deprecated -- use addWithdrawIxV2 instead
1508
+ async addWithdrawIx() {
1509
+ const collateralExchangeRate = this.reserve.getEstimatedCollateralExchangeRate(
1510
+ this.currentSlot,
1511
+ this.kaminoMarket.state.referralFeeBps
1512
+ );
1513
+
1514
+ const collateralAmount = this.amount.eq(new BN(U64_MAX))
1515
+ ? this.amount
1516
+ : new BN(new Decimal(this.amount.toString()).mul(collateralExchangeRate).ceil().toString());
1517
+
1518
+ this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateral`);
1519
+ this.lendingIxs.push(
1520
+ withdrawObligationCollateralAndRedeemReserveCollateral(
1521
+ {
1522
+ collateralAmount,
1523
+ },
1524
+ {
1525
+ owner: this.owner,
1526
+ obligation: this.getObligationPda(),
1527
+ lendingMarket: this.kaminoMarket.getAddress(),
1528
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1529
+ withdrawReserve: this.reserve.address,
1530
+ reserveLiquidityMint: this.reserve.getLiquidityMint(),
1531
+ reserveCollateralMint: this.reserve.getCTokenMint(),
1532
+ reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
1533
+ reserveSourceCollateral: this.reserve.state.collateral.supplyVault,
1534
+ userDestinationLiquidity: this.userTokenAccountAddress,
1535
+ placeholderUserDestinationCollateral: this.kaminoMarket.programId,
1536
+ collateralTokenProgram: TOKEN_PROGRAM_ID,
1537
+ liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
1538
+ instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1539
+ },
1540
+ this.kaminoMarket.programId
1541
+ )
1542
+ );
1543
+ }
1544
+
1545
+ async addWithdrawIxV2() {
1546
+ const collateralExchangeRate = this.reserve.getEstimatedCollateralExchangeRate(
1547
+ this.currentSlot,
1548
+ this.kaminoMarket.state.referralFeeBps
1549
+ );
1550
+
1551
+ // TODO: Move this side effect from here...
1552
+ const collateralAmount = this.amount.eq(new BN(U64_MAX))
1553
+ ? this.amount
1554
+ : new BN(new Decimal(this.amount.toString()).mul(collateralExchangeRate).ceil().toString());
1555
+
1556
+ const farmsAccounts = this.reserve.state.farmCollateral.equals(PublicKey.default)
1557
+ ? {
1558
+ obligationFarmUserState: PROGRAM_ID,
1559
+ reserveFarmState: PROGRAM_ID,
1560
+ }
1561
+ : {
1562
+ obligationFarmUserState: obligationFarmStatePda(
1563
+ this.getObligationPda(),
1564
+ this.reserve.state.farmCollateral
1565
+ )[0],
1566
+ reserveFarmState: this.reserve.state.farmCollateral,
1567
+ };
1568
+
1569
+ this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateralV2`);
1570
+ this.lendingIxs.push(
1571
+ withdrawObligationCollateralAndRedeemReserveCollateralV2(
1572
+ {
1573
+ collateralAmount,
1574
+ },
1575
+ {
1576
+ withdrawAccounts: {
1577
+ owner: this.owner,
1578
+ obligation: this.getObligationPda(),
1579
+ lendingMarket: this.kaminoMarket.getAddress(),
1580
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1581
+ withdrawReserve: this.reserve.address,
1582
+ reserveLiquidityMint: this.reserve.getLiquidityMint(),
1583
+ reserveCollateralMint: this.reserve.getCTokenMint(),
1584
+ reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
1585
+ reserveSourceCollateral: this.reserve.state.collateral.supplyVault,
1586
+ userDestinationLiquidity: this.userTokenAccountAddress,
1587
+ placeholderUserDestinationCollateral: this.kaminoMarket.programId,
1588
+ collateralTokenProgram: TOKEN_PROGRAM_ID,
1589
+ liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
1590
+ instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1591
+ },
1592
+ farmsAccounts: farmsAccounts,
1593
+ farmsProgram: farmsId,
1594
+ },
1595
+ this.kaminoMarket.programId
1596
+ )
1597
+ );
1598
+ }
1599
+
1600
+ /// @deprecated -- use addRepayIxV2 instead
1601
+ async addRepayIx() {
1602
+ this.lendingIxsLabels.push(
1603
+ `repayObligationLiquidity(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`
1604
+ );
1605
+
1606
+ const depositReservesList = this.getAdditionalDepositReservesList();
1607
+
1608
+ const depositReserveAccountMetas = depositReservesList.map((reserve) => {
1609
+ return { pubkey: reserve, isSigner: false, isWritable: true };
1610
+ });
1611
+
1612
+ const repayIx = repayObligationLiquidity(
1613
+ {
1614
+ liquidityAmount: this.amount,
1615
+ },
1616
+ {
1617
+ owner: this.payer,
1618
+ obligation: this.getObligationPda(),
1619
+ lendingMarket: this.kaminoMarket.getAddress(),
1620
+ repayReserve: this.reserve.address,
1621
+ reserveLiquidityMint: this.reserve.getLiquidityMint(),
1622
+ userSourceLiquidity: this.userTokenAccountAddress,
1623
+ reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
1624
+ tokenProgram: this.reserve.getLiquidityTokenProgram(),
1625
+ instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1626
+ },
1627
+ this.kaminoMarket.programId
1628
+ );
1629
+
1630
+ repayIx.keys =
1631
+ this.obligation!.state.elevationGroup > 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
1632
+
1633
+ this.lendingIxs.push(repayIx);
1634
+ }
1635
+
1636
+ async addRepayIxV2() {
1637
+ this.lendingIxsLabels.push(
1638
+ `repayObligationLiquidityV2(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`
1639
+ );
1640
+
1641
+ const depositReservesList = this.getAdditionalDepositReservesList();
1642
+
1643
+ const farmsAccounts = this.reserve.state.farmDebt.equals(PublicKey.default)
1644
+ ? {
1645
+ obligationFarmUserState: PROGRAM_ID,
1646
+ reserveFarmState: PROGRAM_ID,
1647
+ }
1648
+ : {
1649
+ obligationFarmUserState: obligationFarmStatePda(this.getObligationPda(), this.reserve.state.farmDebt)[0],
1650
+ reserveFarmState: this.reserve.state.farmDebt,
1651
+ };
1652
+ const depositReserveAccountMetas = depositReservesList.map((reserve) => {
1653
+ return { pubkey: reserve, isSigner: false, isWritable: true };
1654
+ });
1655
+
1656
+ const repayIx = repayObligationLiquidityV2(
1657
+ {
1658
+ liquidityAmount: this.amount,
1659
+ },
1660
+ {
1661
+ repayAccounts: {
1662
+ owner: this.payer,
1663
+ obligation: this.getObligationPda(),
1664
+ lendingMarket: this.kaminoMarket.getAddress(),
1665
+ repayReserve: this.reserve.address,
1666
+ reserveLiquidityMint: this.reserve.getLiquidityMint(),
1667
+ userSourceLiquidity: this.userTokenAccountAddress,
1668
+ reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
1669
+ tokenProgram: this.reserve.getLiquidityTokenProgram(),
1670
+ instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1671
+ },
1672
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1673
+ farmsAccounts,
1674
+ farmsProgram: farmsId,
1675
+ },
1676
+ this.kaminoMarket.programId
1677
+ );
1678
+
1679
+ repayIx.keys =
1680
+ this.obligation!.state.elevationGroup > 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
1681
+
1682
+ this.lendingIxs.push(repayIx);
1683
+ }
1684
+
1305
1685
  async addDepositAndBorrowIx() {
1306
1686
  this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
1307
1687
  this.lendingIxsLabels.push(`borrowObligationLiquidity`);
@@ -1380,6 +1760,118 @@ export class KaminoAction {
1380
1760
  this.lendingIxs.push(borrowIx);
1381
1761
  }
1382
1762
 
1763
+ async addDepositAndBorrowIxV2() {
1764
+ const collateralFarmsAccounts = this.reserve.state.farmCollateral.equals(PublicKey.default)
1765
+ ? {
1766
+ obligationFarmUserState: PROGRAM_ID,
1767
+ reserveFarmState: PROGRAM_ID,
1768
+ }
1769
+ : {
1770
+ obligationFarmUserState: obligationFarmStatePda(
1771
+ this.getObligationPda(),
1772
+ this.reserve.state.farmCollateral
1773
+ )[0],
1774
+ reserveFarmState: this.reserve.state.farmCollateral,
1775
+ };
1776
+
1777
+ this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateralV2`);
1778
+ this.lendingIxsLabels.push(`borrowObligationLiquidityV2`);
1779
+ this.lendingIxs.push(
1780
+ depositReserveLiquidityAndObligationCollateralV2(
1781
+ {
1782
+ liquidityAmount: this.amount,
1783
+ },
1784
+ {
1785
+ depositAccounts: {
1786
+ owner: this.owner,
1787
+ obligation: this.getObligationPda(),
1788
+ lendingMarket: this.kaminoMarket.getAddress(),
1789
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1790
+ reserve: this.reserve.address,
1791
+ reserveLiquidityMint: this.reserve.getLiquidityMint(),
1792
+ reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
1793
+ reserveCollateralMint: this.reserve.getCTokenMint(),
1794
+ reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
1795
+ userSourceLiquidity: this.userTokenAccountAddress,
1796
+ placeholderUserDestinationCollateral: this.kaminoMarket.programId,
1797
+ collateralTokenProgram: TOKEN_PROGRAM_ID,
1798
+ liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
1799
+ instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1800
+ },
1801
+ farmsAccounts: collateralFarmsAccounts,
1802
+ farmsProgram: farmsId,
1803
+ },
1804
+ this.kaminoMarket.programId
1805
+ )
1806
+ );
1807
+
1808
+ if (!this.outflowReserve) {
1809
+ throw new Error(`outflowReserve not set`);
1810
+ }
1811
+
1812
+ if (!this.additionalTokenAccountAddress) {
1813
+ throw new Error(`additionalTokenAccountAddress not set`);
1814
+ }
1815
+
1816
+ if (!this.outflowAmount) {
1817
+ throw new Error(`outflowAmount not set`);
1818
+ }
1819
+
1820
+ const depositReservesList = this.getAdditionalDepositReservesList();
1821
+ if (depositReservesList.length === 0) {
1822
+ depositReservesList.push(this.reserve.address);
1823
+ }
1824
+ const depositReserveAccountMetas = depositReservesList.map((reserve) => {
1825
+ return { pubkey: reserve, isSigner: false, isWritable: true };
1826
+ });
1827
+
1828
+ const debtFarmsAccounts = this.outflowReserve.state.farmDebt.equals(PublicKey.default)
1829
+ ? {
1830
+ obligationFarmUserState: PROGRAM_ID,
1831
+ reserveFarmState: PROGRAM_ID,
1832
+ }
1833
+ : {
1834
+ obligationFarmUserState: obligationFarmStatePda(
1835
+ this.getObligationPda(),
1836
+ this.outflowReserve.state.farmDebt!
1837
+ )[0],
1838
+ reserveFarmState: this.outflowReserve.state.farmDebt,
1839
+ };
1840
+
1841
+ const borrowIx = borrowObligationLiquidityV2(
1842
+ {
1843
+ liquidityAmount: this.outflowAmount,
1844
+ },
1845
+ {
1846
+ borrowAccounts: {
1847
+ owner: this.owner,
1848
+ obligation: this.getObligationPda(),
1849
+ lendingMarket: this.kaminoMarket.getAddress(),
1850
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1851
+ borrowReserve: this.outflowReserve.address,
1852
+ borrowReserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
1853
+ reserveSourceLiquidity: this.outflowReserve.state.liquidity.supplyVault,
1854
+ userDestinationLiquidity: this.additionalTokenAccountAddress,
1855
+ borrowReserveLiquidityFeeReceiver: this.outflowReserve.state.liquidity.feeVault,
1856
+ referrerTokenState: referrerTokenStatePda(
1857
+ this.referrer,
1858
+ this.outflowReserve.address,
1859
+ this.kaminoMarket.programId
1860
+ )[0],
1861
+ tokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
1862
+ instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1863
+ },
1864
+ farmsAccounts: debtFarmsAccounts,
1865
+ farmsProgram: farmsId,
1866
+ },
1867
+ this.kaminoMarket.programId
1868
+ );
1869
+
1870
+ borrowIx.keys = borrowIx.keys.concat([...depositReserveAccountMetas]);
1871
+
1872
+ this.lendingIxs.push(borrowIx);
1873
+ }
1874
+
1383
1875
  async addRepayAndWithdrawIxs() {
1384
1876
  this.lendingIxsLabels.push(
1385
1877
  `repayObligationLiquidity(reserve=${this.reserve!.address})(obligation=${this.getObligationPda()})`
@@ -1457,47 +1949,11 @@ export class KaminoAction {
1457
1949
  );
1458
1950
  }
1459
1951
 
1460
- async addWithdrawIx() {
1461
- const collateralExchangeRate = this.reserve.getEstimatedCollateralExchangeRate(
1462
- this.currentSlot,
1463
- this.kaminoMarket.state.referralFeeBps
1464
- );
1465
-
1466
- const collateralAmount = this.amount.eq(new BN(U64_MAX))
1467
- ? this.amount
1468
- : new BN(new Decimal(this.amount.toString()).mul(collateralExchangeRate).ceil().toString());
1469
-
1470
- this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateral`);
1471
- this.lendingIxs.push(
1472
- withdrawObligationCollateralAndRedeemReserveCollateral(
1473
- {
1474
- collateralAmount,
1475
- },
1476
- {
1477
- owner: this.owner,
1478
- obligation: this.getObligationPda(),
1479
- lendingMarket: this.kaminoMarket.getAddress(),
1480
- lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1481
- withdrawReserve: this.reserve.address,
1482
- reserveLiquidityMint: this.reserve.getLiquidityMint(),
1483
- reserveCollateralMint: this.reserve.getCTokenMint(),
1484
- reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
1485
- reserveSourceCollateral: this.reserve.state.collateral.supplyVault,
1486
- userDestinationLiquidity: this.userTokenAccountAddress,
1487
- placeholderUserDestinationCollateral: this.kaminoMarket.programId,
1488
- collateralTokenProgram: TOKEN_PROGRAM_ID,
1489
- liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
1490
- instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1491
- },
1492
- this.kaminoMarket.programId
1493
- )
1494
- );
1495
- }
1496
-
1497
- async addRepayIx() {
1952
+ async addRepayAndWithdrawIxsV2() {
1498
1953
  this.lendingIxsLabels.push(
1499
- `repayObligationLiquidity(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`
1954
+ `repayObligationLiquidityV2(reserve=${this.reserve!.address})(obligation=${this.getObligationPda()})`
1500
1955
  );
1956
+ this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateralV2`);
1501
1957
 
1502
1958
  const depositReservesList = this.getAdditionalDepositReservesList();
1503
1959
 
@@ -1505,28 +1961,102 @@ export class KaminoAction {
1505
1961
  return { pubkey: reserve, isSigner: false, isWritable: true };
1506
1962
  });
1507
1963
 
1508
- const repayIx = repayObligationLiquidity(
1964
+ const debtFarmsAccounts = this.reserve.state.farmDebt.equals(PublicKey.default)
1965
+ ? {
1966
+ obligationFarmUserState: PROGRAM_ID,
1967
+ reserveFarmState: PROGRAM_ID,
1968
+ }
1969
+ : {
1970
+ obligationFarmUserState: obligationFarmStatePda(this.getObligationPda(), this.reserve.state.farmDebt)[0],
1971
+ reserveFarmState: this.reserve.state.farmDebt,
1972
+ };
1973
+
1974
+ const repayIx = repayObligationLiquidityV2(
1509
1975
  {
1510
1976
  liquidityAmount: this.amount,
1511
1977
  },
1512
1978
  {
1513
- owner: this.payer,
1514
- obligation: this.getObligationPda(),
1515
- lendingMarket: this.kaminoMarket.getAddress(),
1516
- repayReserve: this.reserve.address,
1517
- reserveLiquidityMint: this.reserve.getLiquidityMint(),
1518
- userSourceLiquidity: this.userTokenAccountAddress,
1519
- reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
1520
- tokenProgram: this.reserve.getLiquidityTokenProgram(),
1521
- instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1979
+ repayAccounts: {
1980
+ owner: this.owner,
1981
+ obligation: this.getObligationPda(),
1982
+ lendingMarket: this.kaminoMarket.getAddress(),
1983
+ repayReserve: this.reserve!.address,
1984
+ reserveLiquidityMint: this.reserve.getLiquidityMint(),
1985
+ userSourceLiquidity: this.userTokenAccountAddress,
1986
+ reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
1987
+ tokenProgram: this.reserve.getLiquidityTokenProgram(),
1988
+ instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1989
+ },
1990
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1991
+ farmsAccounts: debtFarmsAccounts,
1992
+ farmsProgram: farmsId,
1522
1993
  },
1523
1994
  this.kaminoMarket.programId
1524
1995
  );
1525
1996
 
1526
- repayIx.keys =
1527
- this.obligation!.state.elevationGroup > 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
1997
+ repayIx.keys = repayIx.keys.concat([...depositReserveAccountMetas]);
1528
1998
 
1529
1999
  this.lendingIxs.push(repayIx);
2000
+ if (!this.outflowReserve) {
2001
+ throw new Error(`outflowReserve not set`);
2002
+ }
2003
+
2004
+ if (!this.additionalTokenAccountAddress) {
2005
+ throw new Error(`additionalTokenAccountAddress not set`);
2006
+ }
2007
+
2008
+ if (!this.outflowAmount) {
2009
+ throw new Error(`outflowAmount not set`);
2010
+ }
2011
+
2012
+ const collateralExchangeRate = this.outflowReserve.getEstimatedCollateralExchangeRate(
2013
+ this.currentSlot,
2014
+ this.kaminoMarket.state.referralFeeBps
2015
+ );
2016
+
2017
+ const collateralFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(PublicKey.default)
2018
+ ? {
2019
+ obligationFarmUserState: PROGRAM_ID,
2020
+ reserveFarmState: PROGRAM_ID,
2021
+ }
2022
+ : {
2023
+ obligationFarmUserState: obligationFarmStatePda(
2024
+ this.getObligationPda(),
2025
+ this.outflowReserve.state.farmCollateral
2026
+ )[0],
2027
+ reserveFarmState: this.outflowReserve.state.farmCollateral,
2028
+ };
2029
+
2030
+ this.lendingIxs.push(
2031
+ withdrawObligationCollateralAndRedeemReserveCollateralV2(
2032
+ {
2033
+ collateralAmount: this.outflowAmount.eq(new BN(U64_MAX))
2034
+ ? this.outflowAmount
2035
+ : new BN(new Decimal(this.outflowAmount.toString()).mul(collateralExchangeRate).ceil().toString()),
2036
+ },
2037
+ {
2038
+ withdrawAccounts: {
2039
+ owner: this.owner,
2040
+ obligation: this.getObligationPda(),
2041
+ lendingMarket: this.kaminoMarket.getAddress(),
2042
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
2043
+ withdrawReserve: this.outflowReserve.address,
2044
+ reserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
2045
+ reserveCollateralMint: this.outflowReserve.getCTokenMint(),
2046
+ reserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
2047
+ reserveSourceCollateral: this.outflowReserve.state.collateral.supplyVault,
2048
+ userDestinationLiquidity: this.additionalTokenAccountAddress,
2049
+ placeholderUserDestinationCollateral: this.kaminoMarket.programId,
2050
+ collateralTokenProgram: TOKEN_PROGRAM_ID,
2051
+ liquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
2052
+ instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
2053
+ },
2054
+ farmsAccounts: collateralFarmsAccounts,
2055
+ farmsProgram: farmsId,
2056
+ },
2057
+ this.kaminoMarket.programId
2058
+ )
2059
+ );
1530
2060
  }
1531
2061
 
1532
2062
  async addLiquidateIx(maxAllowedLtvOverridePercent: number = 0) {
@@ -1581,15 +2111,97 @@ export class KaminoAction {
1581
2111
  this.lendingIxs.push(liquidateIx);
1582
2112
  }
1583
2113
 
2114
+ async addLiquidateIxV2(maxAllowedLtvOverridePercent: number = 0) {
2115
+ this.lendingIxsLabels.push(`liquidateObligationAndRedeemReserveCollateralV2`);
2116
+ if (!this.outflowReserve) {
2117
+ throw Error(`Withdraw reserve during liquidation is not defined`);
2118
+ }
2119
+ if (!this.additionalTokenAccountAddress) {
2120
+ throw Error(`Liquidating token account address is not defined`);
2121
+ }
2122
+
2123
+ const depositReservesList = this.getAdditionalDepositReservesList();
2124
+ const depositReserveAccountMetas = depositReservesList.map((reserve) => {
2125
+ return { pubkey: reserve, isSigner: false, isWritable: true };
2126
+ });
2127
+
2128
+ const collateralFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(PublicKey.default)
2129
+ ? {
2130
+ obligationFarmUserState: PROGRAM_ID,
2131
+ reserveFarmState: PROGRAM_ID,
2132
+ }
2133
+ : {
2134
+ obligationFarmUserState: obligationFarmStatePda(
2135
+ this.getObligationPda(),
2136
+ this.outflowReserve.state.farmCollateral
2137
+ )[0],
2138
+ reserveFarmState: this.outflowReserve.state.farmCollateral,
2139
+ };
2140
+
2141
+ const debtFarmsAccounts = this.reserve.state.farmDebt.equals(PublicKey.default)
2142
+ ? {
2143
+ obligationFarmUserState: PROGRAM_ID,
2144
+ reserveFarmState: PROGRAM_ID,
2145
+ }
2146
+ : {
2147
+ obligationFarmUserState: obligationFarmStatePda(this.getObligationPda(), this.reserve.state.farmDebt)[0],
2148
+ reserveFarmState: this.reserve.state.farmDebt,
2149
+ };
2150
+
2151
+ const liquidateIx = liquidateObligationAndRedeemReserveCollateralV2(
2152
+ {
2153
+ liquidityAmount: this.amount,
2154
+ // TODO: Configure this when updating liquidator with new interface
2155
+ minAcceptableReceivedLiquidityAmount: this.outflowAmount || new BN(0),
2156
+ maxAllowedLtvOverridePercent: new BN(maxAllowedLtvOverridePercent),
2157
+ },
2158
+ {
2159
+ liquidationAccounts: {
2160
+ liquidator: this.owner,
2161
+ obligation: this.getObligationPda(),
2162
+ lendingMarket: this.kaminoMarket.getAddress(),
2163
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
2164
+ repayReserve: this.reserve.address,
2165
+ repayReserveLiquidityMint: this.reserve.getLiquidityMint(),
2166
+ repayReserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
2167
+ withdrawReserve: this.outflowReserve.address,
2168
+ withdrawReserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
2169
+ withdrawReserveCollateralMint: this.outflowReserve.getCTokenMint(),
2170
+ withdrawReserveCollateralSupply: this.outflowReserve.state.collateral.supplyVault,
2171
+ withdrawReserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
2172
+ userSourceLiquidity: this.additionalTokenAccountAddress,
2173
+ userDestinationCollateral: this.userCollateralAccountAddress,
2174
+ userDestinationLiquidity: this.userTokenAccountAddress,
2175
+ withdrawReserveLiquidityFeeReceiver: this.outflowReserve.state.liquidity.feeVault,
2176
+ collateralTokenProgram: TOKEN_PROGRAM_ID,
2177
+ repayLiquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
2178
+ withdrawLiquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
2179
+ instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
2180
+ },
2181
+ debtFarmsAccounts,
2182
+ collateralFarmsAccounts,
2183
+ farmsProgram: farmsId,
2184
+ },
2185
+ this.kaminoMarket.programId
2186
+ );
2187
+ liquidateIx.keys =
2188
+ this.obligation!.state.elevationGroup > 0
2189
+ ? liquidateIx.keys.concat([...depositReserveAccountMetas])
2190
+ : liquidateIx.keys;
2191
+ this.lendingIxs.push(liquidateIx);
2192
+ }
2193
+
1584
2194
  async addInBetweenIxs(
1585
2195
  action: ActionType,
1586
2196
  includeAtaIxns: boolean,
1587
2197
  requestElevationGroup: boolean,
1588
- addInitObligationForFarm: boolean
2198
+ addInitObligationForFarm: boolean,
2199
+ useV2Ixs: boolean
1589
2200
  ) {
1590
2201
  await this.addSupportIxsWithoutInitObligation(
1591
2202
  action,
1592
2203
  includeAtaIxns,
2204
+ useV2Ixs,
1593
2205
  'inBetween',
1594
2206
  requestElevationGroup,
1595
2207
  addInitObligationForFarm
@@ -1622,6 +2234,7 @@ export class KaminoAction {
1622
2234
  async addSupportIxsWithoutInitObligation(
1623
2235
  action: ActionType,
1624
2236
  includeAtaIxns: boolean,
2237
+ useV2Ixs: boolean,
1625
2238
  addAsSupportIx: AuxiliaryIx = 'setup',
1626
2239
  requestElevationGroup: boolean = false,
1627
2240
  addInitObligationForFarm: boolean = false,
@@ -1850,46 +2463,48 @@ export class KaminoAction {
1850
2463
  }
1851
2464
  }
1852
2465
 
1853
- if (addAsSupportIx === 'setup') {
1854
- // If this is an setup ixn (therefore not an in-between), it means it's either a one off action
1855
- // or the first of a two-token-action
1856
- if (action === 'liquidate') {
1857
- this.addRefreshFarmsForReserve([this.outflowReserve!], addAsSupportIx, ReserveFarmKind.Collateral);
1858
- this.addRefreshFarmsForReserve([this.reserve], addAsSupportIx, ReserveFarmKind.Debt);
1859
- } else if (
1860
- action === 'depositAndBorrow' ||
1861
- action === 'depositCollateral' ||
1862
- action === 'withdraw' ||
1863
- action === 'deposit'
1864
- ) {
1865
- this.addRefreshFarmsForReserve(
1866
- currentReserves,
1867
- addAsSupportIx,
1868
- ReserveFarmKind.Collateral,
1869
- undefined,
1870
- twoTokenAction
1871
- );
1872
- } else if (action === 'repayAndWithdraw' || action === 'borrow' || action === 'repay') {
1873
- this.addRefreshFarmsForReserve(
1874
- currentReserves,
1875
- addAsSupportIx,
1876
- ReserveFarmKind.Debt,
1877
- undefined,
1878
- twoTokenAction
1879
- );
1880
- } else {
1881
- throw new Error(`Could not decide on refresh farm for action ${action}`);
1882
- }
1883
- } else {
1884
- // If this is an inbetween, it means it's part of a two-token-action
1885
- // so we skip the refresh farm obligation of the first reserve as that operation already happened
1886
- // add added to 'setup' ixns
1887
- if (action === 'depositAndBorrow') {
1888
- this.addRefreshFarmsForReserve([this.outflowReserve!], addAsSupportIx, ReserveFarmKind.Debt);
1889
- } else if (action === 'repayAndWithdraw') {
1890
- this.addRefreshFarmsForReserve([this.outflowReserve!], addAsSupportIx, ReserveFarmKind.Collateral);
2466
+ if (!useV2Ixs) {
2467
+ if (addAsSupportIx === 'setup') {
2468
+ // If this is an setup ixn (therefore not an in-between), it means it's either a one off action
2469
+ // or the first of a two-token-action
2470
+ if (action === 'liquidate') {
2471
+ this.addRefreshFarmsForReserve([this.outflowReserve!], addAsSupportIx, ReserveFarmKind.Collateral);
2472
+ this.addRefreshFarmsForReserve([this.reserve], addAsSupportIx, ReserveFarmKind.Debt);
2473
+ } else if (
2474
+ action === 'depositAndBorrow' ||
2475
+ action === 'depositCollateral' ||
2476
+ action === 'withdraw' ||
2477
+ action === 'deposit'
2478
+ ) {
2479
+ this.addRefreshFarmsForReserve(
2480
+ currentReserves,
2481
+ addAsSupportIx,
2482
+ ReserveFarmKind.Collateral,
2483
+ undefined,
2484
+ twoTokenAction
2485
+ );
2486
+ } else if (action === 'repayAndWithdraw' || action === 'borrow' || action === 'repay') {
2487
+ this.addRefreshFarmsForReserve(
2488
+ currentReserves,
2489
+ addAsSupportIx,
2490
+ ReserveFarmKind.Debt,
2491
+ undefined,
2492
+ twoTokenAction
2493
+ );
2494
+ } else {
2495
+ throw new Error(`Could not decide on refresh farm for action ${action}`);
2496
+ }
1891
2497
  } else {
1892
- throw new Error(`Could not decide on refresh farm for action ${action}`);
2498
+ // If this is an inbetween, it means it's part of a two-token-action
2499
+ // so we skip the refresh farm obligation of the first reserve as that operation already happened
2500
+ // add added to 'setup' ixns
2501
+ if (action === 'depositAndBorrow') {
2502
+ this.addRefreshFarmsForReserve([this.outflowReserve!], addAsSupportIx, ReserveFarmKind.Debt);
2503
+ } else if (action === 'repayAndWithdraw') {
2504
+ this.addRefreshFarmsForReserve([this.outflowReserve!], addAsSupportIx, ReserveFarmKind.Collateral);
2505
+ } else {
2506
+ throw new Error(`Could not decide on refresh farm for action ${action}`);
2507
+ }
1893
2508
  }
1894
2509
  }
1895
2510
  }
@@ -1901,6 +2516,7 @@ export class KaminoAction {
1901
2516
  requestElevationGroup: boolean,
1902
2517
  includeUserMetadata: boolean,
1903
2518
  addInitObligationForFarm: boolean,
2519
+ useV2Ixs: boolean,
1904
2520
  twoTokenAction: boolean = false,
1905
2521
  overrideElevationGroupRequest?: number
1906
2522
  ) {
@@ -1923,6 +2539,7 @@ export class KaminoAction {
1923
2539
  await this.addSupportIxsWithoutInitObligation(
1924
2540
  action,
1925
2541
  includeAtaIxns,
2542
+ useV2Ixs,
1926
2543
  'setup',
1927
2544
  requestElevationGroup,
1928
2545
  addInitObligationForFarm,
@@ -2136,13 +2753,6 @@ export class KaminoAction {
2136
2753
  crank: PublicKey = this.payer,
2137
2754
  twoTokenAction: boolean = false
2138
2755
  ) {
2139
- const BASE_SEED_USER_STATE = Buffer.from('user');
2140
- const getPda = (farm: PublicKey) =>
2141
- PublicKey.findProgramAddressSync(
2142
- [BASE_SEED_USER_STATE, farm.toBytes(), this.getObligationPda().toBytes()],
2143
- farmsId
2144
- )[0];
2145
-
2146
2756
  const farms: [
2147
2757
  typeof ReserveFarmKind.Collateral | typeof ReserveFarmKind.Debt,
2148
2758
  PublicKey,
@@ -2155,7 +2765,7 @@ export class KaminoAction {
2155
2765
  farms.push([
2156
2766
  ReserveFarmKind.Collateral,
2157
2767
  kaminoReserve.state.farmCollateral,
2158
- getPda(kaminoReserve.state.farmCollateral),
2768
+ obligationFarmStatePda(this.getObligationPda(), kaminoReserve.state.farmCollateral)[0],
2159
2769
  kaminoReserve,
2160
2770
  ]);
2161
2771
  }
@@ -2163,7 +2773,7 @@ export class KaminoAction {
2163
2773
  farms.push([
2164
2774
  ReserveFarmKind.Debt,
2165
2775
  kaminoReserve.state.farmDebt,
2166
- getPda(kaminoReserve.state.farmDebt),
2776
+ obligationFarmStatePda(this.getObligationPda(), kaminoReserve.state.farmDebt)[0],
2167
2777
  kaminoReserve,
2168
2778
  ]);
2169
2779
  }
@@ -2244,28 +2854,21 @@ export class KaminoAction {
2244
2854
  mode: typeof ReserveFarmKind.Collateral | typeof ReserveFarmKind.Debt,
2245
2855
  addAsSupportIx: AuxiliaryIx = 'setup'
2246
2856
  ): Promise<void> {
2247
- const BASE_SEED_USER_STATE = Buffer.from('user');
2248
- const getPda = (farm: PublicKey) =>
2249
- PublicKey.findProgramAddressSync(
2250
- [BASE_SEED_USER_STATE, farm.toBytes(), this.getObligationPda().toBytes()],
2251
- farmsId
2252
- )[0];
2253
-
2254
2857
  const farms: [number, PublicKey, PublicKey][] = [];
2255
2858
 
2256
2859
  if (mode === ReserveFarmKind.Collateral && isNotNullPubkey(reserve.state.farmCollateral)) {
2257
- const pda = getPda(reserve.state.farmCollateral);
2258
- const account = await this.kaminoMarket.getConnection().getAccountInfo(pda);
2860
+ const userPda = obligationFarmStatePda(this.getObligationPda(), reserve.state.farmCollateral)[0];
2861
+ const account = await this.kaminoMarket.getConnection().getAccountInfo(userPda);
2259
2862
  if (!account) {
2260
- farms.push([ReserveFarmKind.Collateral.discriminator, reserve.state.farmCollateral, pda]);
2863
+ farms.push([ReserveFarmKind.Collateral.discriminator, reserve.state.farmCollateral, userPda]);
2261
2864
  }
2262
2865
  }
2263
2866
 
2264
2867
  if (mode === ReserveFarmKind.Debt && isNotNullPubkey(reserve.state.farmDebt)) {
2265
- const pda = getPda(reserve.state.farmDebt);
2266
- const account = await this.kaminoMarket.getConnection().getAccountInfo(pda);
2868
+ const userPda = obligationFarmStatePda(this.getObligationPda(), reserve.state.farmDebt)[0];
2869
+ const account = await this.kaminoMarket.getConnection().getAccountInfo(userPda);
2267
2870
  if (!account) {
2268
- farms.push([ReserveFarmKind.Debt.discriminator, reserve.state.farmDebt, getPda(reserve.state.farmDebt)]);
2871
+ farms.push([ReserveFarmKind.Debt.discriminator, reserve.state.farmDebt, userPda]);
2269
2872
  }
2270
2873
  }
2271
2874