@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
@@ -21,10 +21,12 @@ import BN from 'bn.js';
21
21
  import Decimal from 'decimal.js';
22
22
  import {
23
23
  borrowObligationLiquidity,
24
- depositAndWithdraw,
24
+ borrowObligationLiquidityV2,
25
25
  depositObligationCollateral,
26
+ depositObligationCollateralV2,
26
27
  depositReserveLiquidity,
27
28
  depositReserveLiquidityAndObligationCollateral,
29
+ depositReserveLiquidityAndObligationCollateralV2,
28
30
  initObligation,
29
31
  initObligationFarmsForReserve,
30
32
  InitObligationFarmsForReserveAccounts,
@@ -32,18 +34,20 @@ import {
32
34
  initReferrerTokenState,
33
35
  initUserMetadata,
34
36
  liquidateObligationAndRedeemReserveCollateral,
37
+ liquidateObligationAndRedeemReserveCollateralV2,
35
38
  redeemReserveCollateral,
36
39
  refreshObligation,
37
40
  refreshObligationFarmsForReserve,
38
41
  RefreshObligationFarmsForReserveAccounts,
39
42
  RefreshObligationFarmsForReserveArgs,
40
43
  refreshReserve,
41
- repayAndWithdrawAndRedeem,
42
44
  repayObligationLiquidity,
45
+ repayObligationLiquidityV2,
43
46
  requestElevationGroup,
44
47
  RequestElevationGroupAccounts,
45
48
  RequestElevationGroupArgs,
46
49
  withdrawObligationCollateralAndRedeemReserveCollateral,
50
+ withdrawObligationCollateralAndRedeemReserveCollateralV2,
47
51
  withdrawReferrerFees,
48
52
  } from '../idl_codegen/instructions';
49
53
  import {
@@ -86,9 +90,7 @@ export type ActionType =
86
90
  | 'repayAndWithdraw'
87
91
  | 'refreshObligation'
88
92
  | 'requestElevationGroup'
89
- | 'withdrawReferrerFees'
90
- | 'repayAndWithdrawV2'
91
- | 'depositAndWithdraw';
93
+ | 'withdrawReferrerFees';
92
94
 
93
95
  export type AuxiliaryIx = 'setup' | 'inBetween' | 'cleanup';
94
96
 
@@ -408,6 +410,7 @@ export class KaminoAction {
408
410
  mint: PublicKey,
409
411
  owner: PublicKey,
410
412
  obligation: KaminoObligation | ObligationType,
413
+ useV2Ixs: boolean,
411
414
  extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
412
415
  includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
413
416
  requestElevationGroup: boolean = false, // to be requested *before* the deposit
@@ -450,12 +453,16 @@ export class KaminoAction {
450
453
  requestElevationGroup,
451
454
  includeUserMetadata,
452
455
  addInitObligationForFarm,
453
- false,
456
+ useV2Ixs,
454
457
  createLookupTable,
455
458
  undefined,
456
459
  overrideElevationGroupRequest
457
460
  );
458
- axn.addDepositIx();
461
+ if (useV2Ixs) {
462
+ axn.addDepositIxV2();
463
+ } else {
464
+ axn.addDepositIx();
465
+ }
459
466
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
460
467
 
461
468
  return axn;
@@ -505,6 +512,7 @@ export class KaminoAction {
505
512
  mint: PublicKey,
506
513
  owner: PublicKey,
507
514
  obligation: KaminoObligation | ObligationType,
515
+ useV2Ixs: boolean,
508
516
  extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
509
517
  includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
510
518
  requestElevationGroup: boolean = false,
@@ -547,12 +555,16 @@ export class KaminoAction {
547
555
  requestElevationGroup,
548
556
  includeUserMetadata,
549
557
  addInitObligationForFarm,
550
- false,
558
+ useV2Ixs,
551
559
  createLookupTable,
552
560
  undefined,
553
561
  overrideElevationGroupRequest
554
562
  );
555
- axn.addBorrowIx();
563
+ if (useV2Ixs) {
564
+ axn.addBorrowIxV2();
565
+ } else {
566
+ axn.addBorrowIx();
567
+ }
556
568
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
557
569
 
558
570
  return axn;
@@ -672,6 +684,7 @@ export class KaminoAction {
672
684
  mint: PublicKey,
673
685
  owner: PublicKey,
674
686
  obligation: KaminoObligation | ObligationType,
687
+ useV2Ixs: boolean,
675
688
  extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
676
689
  includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas
677
690
  requestElevationGroup: boolean = false,
@@ -714,10 +727,14 @@ export class KaminoAction {
714
727
  requestElevationGroup,
715
728
  includeUserMetadata,
716
729
  addInitObligationForFarm,
717
- false,
730
+ useV2Ixs,
718
731
  createLookupTable
719
732
  );
720
- axn.addDepositObligationCollateralIx();
733
+ if (useV2Ixs) {
734
+ axn.addDepositObligationCollateralIxV2();
735
+ } else {
736
+ axn.addDepositObligationCollateralIx();
737
+ }
721
738
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
722
739
  return axn;
723
740
  }
@@ -730,6 +747,7 @@ export class KaminoAction {
730
747
  borrowMint: PublicKey,
731
748
  payer: PublicKey,
732
749
  obligation: KaminoObligation | ObligationType,
750
+ useV2Ixs: boolean,
733
751
  extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
734
752
  includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
735
753
  requestElevationGroup: boolean = false,
@@ -778,147 +796,27 @@ export class KaminoAction {
778
796
  requestElevationGroup,
779
797
  includeUserMetadata,
780
798
  addInitObligationForFarmForDeposit,
781
- false,
799
+ useV2Ixs,
782
800
  createLookupTable,
783
801
  twoTokenAction
784
802
  );
785
- axn.addDepositAndBorrowIx();
803
+
804
+ if (useV2Ixs) {
805
+ await axn.addDepositAndBorrowIxV2();
806
+ } else {
807
+ await axn.addDepositAndBorrowIx();
808
+ }
786
809
  await axn.addInBetweenIxs(
787
810
  'depositAndBorrow',
788
811
  includeAtaIxns,
789
812
  requestElevationGroup,
790
- addInitObligationForFarmForBorrow
813
+ addInitObligationForFarmForBorrow,
814
+ useV2Ixs
791
815
  );
792
816
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
793
817
  return axn;
794
818
  }
795
819
 
796
- static async buildDepositAndWithdrawV2Txns(
797
- kaminoMarket: KaminoMarket,
798
- depositAmount: string | BN,
799
- depositMint: PublicKey,
800
- withdrawAmount: string | BN,
801
- withdrawMint: PublicKey,
802
- payer: PublicKey,
803
- currentSlot: number,
804
- obligation: KaminoObligation | ObligationType,
805
- extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
806
- includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
807
- requestElevationGroup: boolean = false,
808
- includeUserMetadata: boolean = true, // if true it includes user metadata,
809
- referrer: PublicKey = PublicKey.default,
810
- scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }
811
- ) {
812
- const axn = await KaminoAction.initializeMultiTokenAction(
813
- kaminoMarket,
814
- 'depositAndWithdraw',
815
- depositAmount,
816
- depositMint,
817
- withdrawMint,
818
- payer,
819
- payer,
820
- obligation,
821
- withdrawAmount,
822
- referrer,
823
- currentSlot
824
- );
825
- const addInitObligationForFarm = true;
826
- const twoTokenAction = true;
827
- if (extraComputeBudget > 0) {
828
- axn.addComputeBudgetIxn(extraComputeBudget);
829
- }
830
-
831
- const allReserves = new PublicKeySet<PublicKey>([
832
- ...axn.depositReserves,
833
- ...axn.borrowReserves,
834
- axn.reserve.address,
835
- axn.outflowReserve!.address,
836
- ]).toArray();
837
- const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
838
-
839
- if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
840
- await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
841
- }
842
-
843
- await axn.addSupportIxs(
844
- 'depositAndWithdraw',
845
- includeAtaIxns,
846
- requestElevationGroup,
847
- includeUserMetadata,
848
- addInitObligationForFarm,
849
- true,
850
- twoTokenAction
851
- );
852
- const withdrawCollateralAmount = axn.getWithdrawCollateralAmount(axn.outflowReserve!, axn.outflowAmount!);
853
- axn.addDepositAndWithdrawV2Ixs(withdrawCollateralAmount);
854
-
855
- return axn;
856
- }
857
-
858
- static async buildRepayAndWithdrawV2Txns(
859
- kaminoMarket: KaminoMarket,
860
- repayAmount: string | BN,
861
- repayMint: PublicKey,
862
- withdrawAmount: string | BN,
863
- withdrawMint: PublicKey,
864
- payer: PublicKey,
865
- currentSlot: number,
866
- obligation: KaminoObligation | ObligationType,
867
- extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
868
- includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
869
- requestElevationGroup: boolean = false,
870
- includeUserMetadata: boolean = true, // if true it includes user metadata,
871
- createLookupTable: boolean = true,
872
- referrer: PublicKey = PublicKey.default,
873
- scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }
874
- ) {
875
- const axn = await KaminoAction.initializeMultiTokenAction(
876
- kaminoMarket,
877
- 'repayAndWithdrawV2',
878
- repayAmount,
879
- repayMint,
880
- withdrawMint,
881
- payer,
882
- payer,
883
- obligation,
884
- withdrawAmount,
885
- referrer,
886
- currentSlot
887
- );
888
- const addInitObligationForFarm = true;
889
- const twoTokenAction = true;
890
- if (extraComputeBudget > 0) {
891
- axn.addComputeBudgetIxn(extraComputeBudget);
892
- }
893
-
894
- const allReserves = new PublicKeySet<PublicKey>([
895
- ...axn.depositReserves,
896
- ...axn.borrowReserves,
897
- axn.reserve.address,
898
- axn.outflowReserve!.address,
899
- ]).toArray();
900
- const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
901
-
902
- if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
903
- await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
904
- }
905
-
906
- await axn.addSupportIxs(
907
- 'repayAndWithdrawV2',
908
- includeAtaIxns,
909
- requestElevationGroup,
910
- includeUserMetadata,
911
- addInitObligationForFarm,
912
- true,
913
- createLookupTable,
914
- twoTokenAction
915
- );
916
- const withdrawCollateralAmount = axn.getWithdrawCollateralAmount(axn.outflowReserve!, axn.outflowAmount!);
917
- axn.addRepayAndWithdrawV2Ixs(withdrawCollateralAmount);
918
-
919
- return axn;
920
- }
921
-
922
820
  static async buildRepayAndWithdrawTxns(
923
821
  kaminoMarket: KaminoMarket,
924
822
  repayAmount: string | BN,
@@ -928,6 +826,7 @@ export class KaminoAction {
928
826
  payer: PublicKey,
929
827
  currentSlot: number,
930
828
  obligation: KaminoObligation | ObligationType,
829
+ useV2Ixs: boolean,
931
830
  extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
932
831
  includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
933
832
  requestElevationGroup: boolean = false,
@@ -974,19 +873,24 @@ export class KaminoAction {
974
873
  requestElevationGroup,
975
874
  includeUserMetadata,
976
875
  addInitObligationForFarmForRepay,
977
- false,
876
+ useV2Ixs,
978
877
  createLookupTable,
979
878
  twoTokenAction
980
879
  );
981
880
 
982
881
  const withdrawCollateralAmount = axn.getWithdrawCollateralAmount(axn.outflowReserve!, axn.outflowAmount!);
882
+ if (useV2Ixs) {
883
+ await axn.addRepayAndWithdrawIxsV2(withdrawCollateralAmount);
884
+ } else {
885
+ await axn.addRepayAndWithdrawIxs(withdrawCollateralAmount);
886
+ }
983
887
 
984
- await axn.addRepayAndWithdrawIxs(withdrawCollateralAmount);
985
888
  await axn.addInBetweenIxs(
986
889
  'repayAndWithdraw',
987
890
  includeAtaIxns,
988
891
  requestElevationGroup,
989
- addInitObligationForFarmForWithdraw
892
+ addInitObligationForFarmForWithdraw,
893
+ useV2Ixs
990
894
  );
991
895
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
992
896
  return axn;
@@ -998,6 +902,7 @@ export class KaminoAction {
998
902
  mint: PublicKey,
999
903
  owner: PublicKey,
1000
904
  obligation: KaminoObligation | ObligationType,
905
+ useV2Ixs: boolean,
1001
906
  extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
1002
907
  includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
1003
908
  requestElevationGroup: boolean = false, // to be requested *after* the withdraw
@@ -1048,15 +953,19 @@ export class KaminoAction {
1048
953
  requestElevationGroup,
1049
954
  includeUserMetadata,
1050
955
  addInitObligationForFarm,
1051
- false,
956
+ useV2Ixs,
1052
957
  createLookupTable,
1053
958
  false,
1054
959
  overrideElevationGroupRequest
1055
960
  );
1056
961
 
1057
962
  const collateralAmount = axn.getWithdrawCollateralAmount(axn.reserve, axn.amount);
963
+ if (useV2Ixs) {
964
+ await axn.addWithdrawIxV2(collateralAmount);
965
+ } else {
966
+ await axn.addWithdrawIx(collateralAmount);
967
+ }
1058
968
 
1059
- axn.addWithdrawIx(collateralAmount);
1060
969
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
1061
970
 
1062
971
  return axn;
@@ -1083,6 +992,7 @@ export class KaminoAction {
1083
992
  mint: PublicKey,
1084
993
  owner: PublicKey,
1085
994
  obligation: KaminoObligation | ObligationType,
995
+ useV2Ixs: boolean,
1086
996
  currentSlot: number,
1087
997
  payer: PublicKey | undefined = undefined,
1088
998
  extraComputeBudget: number = 1_000_000,
@@ -1127,10 +1037,14 @@ export class KaminoAction {
1127
1037
  requestElevationGroup,
1128
1038
  includeUserMetadata,
1129
1039
  addInitObligationForFarm,
1130
- false,
1040
+ useV2Ixs,
1131
1041
  createLookupTable
1132
1042
  );
1133
- axn.addRepayIx();
1043
+ if (useV2Ixs) {
1044
+ await axn.addRepayIxV2();
1045
+ } else {
1046
+ await axn.addRepayIx();
1047
+ }
1134
1048
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
1135
1049
 
1136
1050
  return axn;
@@ -1145,6 +1059,7 @@ export class KaminoAction {
1145
1059
  liquidator: PublicKey,
1146
1060
  obligationOwner: PublicKey,
1147
1061
  obligation: KaminoObligation | ObligationType,
1062
+ useV2Ixs: boolean,
1148
1063
  extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
1149
1064
  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
1150
1065
  requestElevationGroup: boolean = false,
@@ -1192,10 +1107,14 @@ export class KaminoAction {
1192
1107
  requestElevationGroup,
1193
1108
  includeUserMetadata,
1194
1109
  addInitObligationForFarm,
1195
- false,
1110
+ useV2Ixs,
1196
1111
  createLookupTable
1197
1112
  );
1198
- axn.addLiquidateIx(maxAllowedLtvOverridePercent);
1113
+ if (useV2Ixs) {
1114
+ await axn.addLiquidateIxV2(maxAllowedLtvOverridePercent);
1115
+ } else {
1116
+ await axn.addLiquidateIx(maxAllowedLtvOverridePercent);
1117
+ }
1199
1118
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
1200
1119
 
1201
1120
  return axn;
@@ -1321,25 +1240,23 @@ export class KaminoAction {
1321
1240
  return await sendTransaction(txn, this.kaminoMarket.getConnection());
1322
1241
  }
1323
1242
 
1324
- addDepositIx() {
1325
- this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
1243
+ addDepositReserveLiquidityIx() {
1244
+ this.lendingIxsLabels.push(`depositReserveLiquidity`);
1326
1245
  this.lendingIxs.push(
1327
- depositReserveLiquidityAndObligationCollateral(
1246
+ depositReserveLiquidity(
1328
1247
  {
1329
1248
  liquidityAmount: this.amount,
1330
1249
  },
1331
1250
  {
1332
1251
  owner: this.owner,
1333
- obligation: this.getObligationPda(),
1334
1252
  lendingMarket: this.kaminoMarket.getAddress(),
1335
1253
  lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1336
1254
  reserve: this.reserve.address,
1337
1255
  reserveLiquidityMint: this.reserve.getLiquidityMint(),
1338
1256
  reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
1339
1257
  reserveCollateralMint: this.reserve.getCTokenMint(),
1340
- reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
1341
1258
  userSourceLiquidity: this.userTokenAccountAddress,
1342
- placeholderUserDestinationCollateral: this.kaminoMarket.programId,
1259
+ userDestinationCollateral: this.userCollateralAccountAddress,
1343
1260
  collateralTokenProgram: TOKEN_PROGRAM_ID,
1344
1261
  liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
1345
1262
  instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
@@ -1349,12 +1266,12 @@ export class KaminoAction {
1349
1266
  );
1350
1267
  }
1351
1268
 
1352
- addDepositReserveLiquidityIx() {
1353
- this.lendingIxsLabels.push(`depositReserveLiquidity`);
1269
+ addRedeemReserveCollateralIx() {
1270
+ this.lendingIxsLabels.push(`redeemReserveCollateral`);
1354
1271
  this.lendingIxs.push(
1355
- depositReserveLiquidity(
1272
+ redeemReserveCollateral(
1356
1273
  {
1357
- liquidityAmount: this.amount,
1274
+ collateralAmount: this.amount,
1358
1275
  },
1359
1276
  {
1360
1277
  owner: this.owner,
@@ -1364,8 +1281,8 @@ export class KaminoAction {
1364
1281
  reserveLiquidityMint: this.reserve.getLiquidityMint(),
1365
1282
  reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
1366
1283
  reserveCollateralMint: this.reserve.getCTokenMint(),
1367
- userSourceLiquidity: this.userTokenAccountAddress,
1368
- userDestinationCollateral: this.userCollateralAccountAddress,
1284
+ userSourceCollateral: this.userCollateralAccountAddress,
1285
+ userDestinationLiquidity: this.userTokenAccountAddress,
1369
1286
  collateralTokenProgram: TOKEN_PROGRAM_ID,
1370
1287
  liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
1371
1288
  instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
@@ -1375,23 +1292,26 @@ export class KaminoAction {
1375
1292
  );
1376
1293
  }
1377
1294
 
1378
- addRedeemReserveCollateralIx() {
1379
- this.lendingIxsLabels.push(`redeemReserveCollateral`);
1295
+ // @deprecated -- use addDepositIxV2 instead
1296
+ addDepositIx() {
1297
+ this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
1380
1298
  this.lendingIxs.push(
1381
- redeemReserveCollateral(
1299
+ depositReserveLiquidityAndObligationCollateral(
1382
1300
  {
1383
- collateralAmount: this.amount,
1301
+ liquidityAmount: this.amount,
1384
1302
  },
1385
1303
  {
1386
1304
  owner: this.owner,
1305
+ obligation: this.getObligationPda(),
1387
1306
  lendingMarket: this.kaminoMarket.getAddress(),
1388
1307
  lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1389
1308
  reserve: this.reserve.address,
1390
1309
  reserveLiquidityMint: this.reserve.getLiquidityMint(),
1391
1310
  reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
1392
1311
  reserveCollateralMint: this.reserve.getCTokenMint(),
1393
- userSourceCollateral: this.userCollateralAccountAddress,
1394
- userDestinationLiquidity: this.userTokenAccountAddress,
1312
+ reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
1313
+ userSourceLiquidity: this.userTokenAccountAddress,
1314
+ placeholderUserDestinationCollateral: this.kaminoMarket.programId,
1395
1315
  collateralTokenProgram: TOKEN_PROGRAM_ID,
1396
1316
  liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
1397
1317
  instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
@@ -1401,6 +1321,52 @@ export class KaminoAction {
1401
1321
  );
1402
1322
  }
1403
1323
 
1324
+ addDepositIxV2() {
1325
+ const farmsAccounts = this.reserve.state.farmCollateral.equals(PublicKey.default)
1326
+ ? {
1327
+ obligationFarmUserState: PROGRAM_ID,
1328
+ reserveFarmState: PROGRAM_ID,
1329
+ }
1330
+ : {
1331
+ obligationFarmUserState: obligationFarmStatePda(
1332
+ this.getObligationPda(),
1333
+ this.reserve.state.farmCollateral
1334
+ )[0],
1335
+ reserveFarmState: this.reserve.state.farmCollateral,
1336
+ };
1337
+
1338
+ this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateralV2`);
1339
+ this.lendingIxs.push(
1340
+ depositReserveLiquidityAndObligationCollateralV2(
1341
+ {
1342
+ liquidityAmount: this.amount,
1343
+ },
1344
+ {
1345
+ depositAccounts: {
1346
+ owner: this.owner,
1347
+ obligation: this.getObligationPda(),
1348
+ lendingMarket: this.kaminoMarket.getAddress(),
1349
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1350
+ reserve: this.reserve.address,
1351
+ reserveLiquidityMint: this.reserve.getLiquidityMint(),
1352
+ reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
1353
+ reserveCollateralMint: this.reserve.getCTokenMint(),
1354
+ reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
1355
+ userSourceLiquidity: this.userTokenAccountAddress,
1356
+ placeholderUserDestinationCollateral: this.kaminoMarket.programId,
1357
+ collateralTokenProgram: TOKEN_PROGRAM_ID,
1358
+ liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
1359
+ instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1360
+ },
1361
+ farmsAccounts,
1362
+ farmsProgram: farmsId,
1363
+ },
1364
+ this.kaminoMarket.programId
1365
+ )
1366
+ );
1367
+ }
1368
+
1369
+ /// @deprecated -- use addDepositObligationCollateralIxV2 instead
1404
1370
  addDepositObligationCollateralIx() {
1405
1371
  this.lendingIxsLabels.push(`depositObligationCollateral`);
1406
1372
  this.lendingIxs.push(
@@ -1423,6 +1389,47 @@ export class KaminoAction {
1423
1389
  );
1424
1390
  }
1425
1391
 
1392
+ addDepositObligationCollateralIxV2() {
1393
+ const farmsAccounts = this.reserve.state.farmCollateral.equals(PublicKey.default)
1394
+ ? {
1395
+ obligationFarmUserState: PROGRAM_ID,
1396
+ reserveFarmState: PROGRAM_ID,
1397
+ }
1398
+ : {
1399
+ obligationFarmUserState: obligationFarmStatePda(
1400
+ this.getObligationPda(),
1401
+ this.reserve.state.farmCollateral
1402
+ )[0],
1403
+ reserveFarmState: this.reserve.state.farmCollateral,
1404
+ };
1405
+
1406
+ this.lendingIxsLabels.push(`depositObligationCollateralV2`);
1407
+ this.lendingIxs.push(
1408
+ depositObligationCollateralV2(
1409
+ {
1410
+ collateralAmount: this.amount,
1411
+ },
1412
+ {
1413
+ depositAccounts: {
1414
+ owner: this.owner,
1415
+ obligation: this.getObligationPda(),
1416
+ lendingMarket: this.kaminoMarket.getAddress(),
1417
+ depositReserve: this.reserve.address,
1418
+ reserveDestinationCollateral: this.reserve.state.collateral.supplyVault,
1419
+ userSourceCollateral: this.userCollateralAccountAddress,
1420
+ tokenProgram: TOKEN_PROGRAM_ID,
1421
+ instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1422
+ },
1423
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1424
+ farmsAccounts,
1425
+ farmsProgram: farmsId,
1426
+ },
1427
+ this.kaminoMarket.programId
1428
+ )
1429
+ );
1430
+ }
1431
+
1432
+ /// @deprecated -- use addDepositObligationCollateralIxV2 instead
1426
1433
  addBorrowIx() {
1427
1434
  this.lendingIxsLabels.push(`borrowObligationLiquidity`);
1428
1435
 
@@ -1459,7 +1466,220 @@ export class KaminoAction {
1459
1466
  this.lendingIxs.push(borrowIx);
1460
1467
  }
1461
1468
 
1462
- addDepositAndBorrowIx() {
1469
+ addBorrowIxV2() {
1470
+ this.lendingIxsLabels.push(`borrowObligationLiquidityV2`);
1471
+
1472
+ const depositReservesList = this.getAdditionalDepositReservesList();
1473
+
1474
+ const depositReserveAccountMetas = depositReservesList.map((reserve) => {
1475
+ return { pubkey: reserve, isSigner: false, isWritable: true };
1476
+ });
1477
+
1478
+ const farmsAccounts = this.reserve.state.farmDebt.equals(PublicKey.default)
1479
+ ? {
1480
+ obligationFarmUserState: PROGRAM_ID,
1481
+ reserveFarmState: PROGRAM_ID,
1482
+ }
1483
+ : {
1484
+ obligationFarmUserState: obligationFarmStatePda(this.getObligationPda(), this.reserve.state.farmDebt)[0],
1485
+ reserveFarmState: this.reserve.state.farmDebt,
1486
+ };
1487
+
1488
+ const borrowIx = borrowObligationLiquidityV2(
1489
+ {
1490
+ liquidityAmount: this.amount,
1491
+ },
1492
+ {
1493
+ borrowAccounts: {
1494
+ owner: this.owner,
1495
+ obligation: this.getObligationPda(),
1496
+ lendingMarket: this.kaminoMarket.getAddress(),
1497
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1498
+ borrowReserve: this.reserve.address,
1499
+ borrowReserveLiquidityMint: this.reserve.getLiquidityMint(),
1500
+ reserveSourceLiquidity: this.reserve.state.liquidity.supplyVault,
1501
+ userDestinationLiquidity: this.userTokenAccountAddress,
1502
+ borrowReserveLiquidityFeeReceiver: this.reserve.state.liquidity.feeVault,
1503
+ referrerTokenState: referrerTokenStatePda(
1504
+ this.referrer,
1505
+ this.reserve.address,
1506
+ this.kaminoMarket.programId
1507
+ )[0],
1508
+ tokenProgram: this.reserve.getLiquidityTokenProgram(),
1509
+ instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1510
+ },
1511
+ farmsAccounts,
1512
+ farmsProgram: farmsId,
1513
+ },
1514
+ this.kaminoMarket.programId
1515
+ );
1516
+ borrowIx.keys =
1517
+ this.obligation!.state.elevationGroup > 0 || this.obligation!.refreshedStats.potentialElevationGroupUpdate > 0
1518
+ ? borrowIx.keys.concat([...depositReserveAccountMetas])
1519
+ : borrowIx.keys;
1520
+ this.lendingIxs.push(borrowIx);
1521
+ }
1522
+
1523
+ /// @deprecated -- use addWithdrawIxV2 instead
1524
+ async addWithdrawIx(collateralAmount: BN) {
1525
+ this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateral`);
1526
+ this.lendingIxs.push(
1527
+ withdrawObligationCollateralAndRedeemReserveCollateral(
1528
+ {
1529
+ collateralAmount,
1530
+ },
1531
+ {
1532
+ owner: this.owner,
1533
+ obligation: this.getObligationPda(),
1534
+ lendingMarket: this.kaminoMarket.getAddress(),
1535
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1536
+ withdrawReserve: this.reserve.address,
1537
+ reserveLiquidityMint: this.reserve.getLiquidityMint(),
1538
+ reserveCollateralMint: this.reserve.getCTokenMint(),
1539
+ reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
1540
+ reserveSourceCollateral: this.reserve.state.collateral.supplyVault,
1541
+ userDestinationLiquidity: this.userTokenAccountAddress,
1542
+ placeholderUserDestinationCollateral: this.kaminoMarket.programId,
1543
+ collateralTokenProgram: TOKEN_PROGRAM_ID,
1544
+ liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
1545
+ instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1546
+ },
1547
+ this.kaminoMarket.programId
1548
+ )
1549
+ );
1550
+ }
1551
+
1552
+ async addWithdrawIxV2(collateralAmount: BN) {
1553
+ const farmsAccounts = this.reserve.state.farmCollateral.equals(PublicKey.default)
1554
+ ? {
1555
+ obligationFarmUserState: PROGRAM_ID,
1556
+ reserveFarmState: PROGRAM_ID,
1557
+ }
1558
+ : {
1559
+ obligationFarmUserState: obligationFarmStatePda(
1560
+ this.getObligationPda(),
1561
+ this.reserve.state.farmCollateral
1562
+ )[0],
1563
+ reserveFarmState: this.reserve.state.farmCollateral,
1564
+ };
1565
+
1566
+ this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateralV2`);
1567
+ this.lendingIxs.push(
1568
+ withdrawObligationCollateralAndRedeemReserveCollateralV2(
1569
+ {
1570
+ collateralAmount,
1571
+ },
1572
+ {
1573
+ withdrawAccounts: {
1574
+ owner: this.owner,
1575
+ obligation: this.getObligationPda(),
1576
+ lendingMarket: this.kaminoMarket.getAddress(),
1577
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1578
+ withdrawReserve: this.reserve.address,
1579
+ reserveLiquidityMint: this.reserve.getLiquidityMint(),
1580
+ reserveCollateralMint: this.reserve.getCTokenMint(),
1581
+ reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
1582
+ reserveSourceCollateral: this.reserve.state.collateral.supplyVault,
1583
+ userDestinationLiquidity: this.userTokenAccountAddress,
1584
+ placeholderUserDestinationCollateral: this.kaminoMarket.programId,
1585
+ collateralTokenProgram: TOKEN_PROGRAM_ID,
1586
+ liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
1587
+ instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1588
+ },
1589
+ farmsAccounts: farmsAccounts,
1590
+ farmsProgram: farmsId,
1591
+ },
1592
+ this.kaminoMarket.programId
1593
+ )
1594
+ );
1595
+ }
1596
+
1597
+ /// @deprecated -- use addRepayIxV2 instead
1598
+ async addRepayIx() {
1599
+ this.lendingIxsLabels.push(
1600
+ `repayObligationLiquidity(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`
1601
+ );
1602
+
1603
+ const depositReservesList = this.getAdditionalDepositReservesList();
1604
+
1605
+ const depositReserveAccountMetas = depositReservesList.map((reserve) => {
1606
+ return { pubkey: reserve, isSigner: false, isWritable: true };
1607
+ });
1608
+
1609
+ const repayIx = repayObligationLiquidity(
1610
+ {
1611
+ liquidityAmount: this.amount,
1612
+ },
1613
+ {
1614
+ owner: this.payer,
1615
+ obligation: this.getObligationPda(),
1616
+ lendingMarket: this.kaminoMarket.getAddress(),
1617
+ repayReserve: this.reserve.address,
1618
+ reserveLiquidityMint: this.reserve.getLiquidityMint(),
1619
+ userSourceLiquidity: this.userTokenAccountAddress,
1620
+ reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
1621
+ tokenProgram: this.reserve.getLiquidityTokenProgram(),
1622
+ instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1623
+ },
1624
+ this.kaminoMarket.programId
1625
+ );
1626
+
1627
+ repayIx.keys =
1628
+ this.obligation!.state.elevationGroup > 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
1629
+
1630
+ this.lendingIxs.push(repayIx);
1631
+ }
1632
+
1633
+ async addRepayIxV2() {
1634
+ this.lendingIxsLabels.push(
1635
+ `repayObligationLiquidityV2(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`
1636
+ );
1637
+
1638
+ const depositReservesList = this.getAdditionalDepositReservesList();
1639
+
1640
+ const farmsAccounts = this.reserve.state.farmDebt.equals(PublicKey.default)
1641
+ ? {
1642
+ obligationFarmUserState: PROGRAM_ID,
1643
+ reserveFarmState: PROGRAM_ID,
1644
+ }
1645
+ : {
1646
+ obligationFarmUserState: obligationFarmStatePda(this.getObligationPda(), this.reserve.state.farmDebt)[0],
1647
+ reserveFarmState: this.reserve.state.farmDebt,
1648
+ };
1649
+ const depositReserveAccountMetas = depositReservesList.map((reserve) => {
1650
+ return { pubkey: reserve, isSigner: false, isWritable: true };
1651
+ });
1652
+
1653
+ const repayIx = repayObligationLiquidityV2(
1654
+ {
1655
+ liquidityAmount: this.amount,
1656
+ },
1657
+ {
1658
+ repayAccounts: {
1659
+ owner: this.payer,
1660
+ obligation: this.getObligationPda(),
1661
+ lendingMarket: this.kaminoMarket.getAddress(),
1662
+ repayReserve: this.reserve.address,
1663
+ reserveLiquidityMint: this.reserve.getLiquidityMint(),
1664
+ userSourceLiquidity: this.userTokenAccountAddress,
1665
+ reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
1666
+ tokenProgram: this.reserve.getLiquidityTokenProgram(),
1667
+ instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1668
+ },
1669
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1670
+ farmsAccounts,
1671
+ farmsProgram: farmsId,
1672
+ },
1673
+ this.kaminoMarket.programId
1674
+ );
1675
+
1676
+ repayIx.keys =
1677
+ this.obligation!.state.elevationGroup > 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
1678
+
1679
+ this.lendingIxs.push(repayIx);
1680
+ }
1681
+
1682
+ async addDepositAndBorrowIx() {
1463
1683
  this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
1464
1684
  this.lendingIxsLabels.push(`borrowObligationLiquidity`);
1465
1685
  this.lendingIxs.push(
@@ -1537,7 +1757,119 @@ export class KaminoAction {
1537
1757
  this.lendingIxs.push(borrowIx);
1538
1758
  }
1539
1759
 
1540
- addRepayAndWithdrawIxs(withdrawCollateralAmount: BN) {
1760
+ async addDepositAndBorrowIxV2() {
1761
+ const collateralFarmsAccounts = this.reserve.state.farmCollateral.equals(PublicKey.default)
1762
+ ? {
1763
+ obligationFarmUserState: PROGRAM_ID,
1764
+ reserveFarmState: PROGRAM_ID,
1765
+ }
1766
+ : {
1767
+ obligationFarmUserState: obligationFarmStatePda(
1768
+ this.getObligationPda(),
1769
+ this.reserve.state.farmCollateral
1770
+ )[0],
1771
+ reserveFarmState: this.reserve.state.farmCollateral,
1772
+ };
1773
+
1774
+ this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateralV2`);
1775
+ this.lendingIxsLabels.push(`borrowObligationLiquidityV2`);
1776
+ this.lendingIxs.push(
1777
+ depositReserveLiquidityAndObligationCollateralV2(
1778
+ {
1779
+ liquidityAmount: this.amount,
1780
+ },
1781
+ {
1782
+ depositAccounts: {
1783
+ owner: this.owner,
1784
+ obligation: this.getObligationPda(),
1785
+ lendingMarket: this.kaminoMarket.getAddress(),
1786
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1787
+ reserve: this.reserve.address,
1788
+ reserveLiquidityMint: this.reserve.getLiquidityMint(),
1789
+ reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
1790
+ reserveCollateralMint: this.reserve.getCTokenMint(),
1791
+ reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
1792
+ userSourceLiquidity: this.userTokenAccountAddress,
1793
+ placeholderUserDestinationCollateral: this.kaminoMarket.programId,
1794
+ collateralTokenProgram: TOKEN_PROGRAM_ID,
1795
+ liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
1796
+ instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1797
+ },
1798
+ farmsAccounts: collateralFarmsAccounts,
1799
+ farmsProgram: farmsId,
1800
+ },
1801
+ this.kaminoMarket.programId
1802
+ )
1803
+ );
1804
+
1805
+ if (!this.outflowReserve) {
1806
+ throw new Error(`outflowReserve not set`);
1807
+ }
1808
+
1809
+ if (!this.additionalTokenAccountAddress) {
1810
+ throw new Error(`additionalTokenAccountAddress not set`);
1811
+ }
1812
+
1813
+ if (!this.outflowAmount) {
1814
+ throw new Error(`outflowAmount not set`);
1815
+ }
1816
+
1817
+ const depositReservesList = this.getAdditionalDepositReservesList();
1818
+ if (depositReservesList.length === 0) {
1819
+ depositReservesList.push(this.reserve.address);
1820
+ }
1821
+ const depositReserveAccountMetas = depositReservesList.map((reserve) => {
1822
+ return { pubkey: reserve, isSigner: false, isWritable: true };
1823
+ });
1824
+
1825
+ const debtFarmsAccounts = this.outflowReserve.state.farmDebt.equals(PublicKey.default)
1826
+ ? {
1827
+ obligationFarmUserState: PROGRAM_ID,
1828
+ reserveFarmState: PROGRAM_ID,
1829
+ }
1830
+ : {
1831
+ obligationFarmUserState: obligationFarmStatePda(
1832
+ this.getObligationPda(),
1833
+ this.outflowReserve.state.farmDebt!
1834
+ )[0],
1835
+ reserveFarmState: this.outflowReserve.state.farmDebt,
1836
+ };
1837
+
1838
+ const borrowIx = borrowObligationLiquidityV2(
1839
+ {
1840
+ liquidityAmount: this.outflowAmount,
1841
+ },
1842
+ {
1843
+ borrowAccounts: {
1844
+ owner: this.owner,
1845
+ obligation: this.getObligationPda(),
1846
+ lendingMarket: this.kaminoMarket.getAddress(),
1847
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1848
+ borrowReserve: this.outflowReserve.address,
1849
+ borrowReserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
1850
+ reserveSourceLiquidity: this.outflowReserve.state.liquidity.supplyVault,
1851
+ userDestinationLiquidity: this.additionalTokenAccountAddress,
1852
+ borrowReserveLiquidityFeeReceiver: this.outflowReserve.state.liquidity.feeVault,
1853
+ referrerTokenState: referrerTokenStatePda(
1854
+ this.referrer,
1855
+ this.outflowReserve.address,
1856
+ this.kaminoMarket.programId
1857
+ )[0],
1858
+ tokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
1859
+ instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1860
+ },
1861
+ farmsAccounts: debtFarmsAccounts,
1862
+ farmsProgram: farmsId,
1863
+ },
1864
+ this.kaminoMarket.programId
1865
+ );
1866
+
1867
+ borrowIx.keys = borrowIx.keys.concat([...depositReserveAccountMetas]);
1868
+
1869
+ this.lendingIxs.push(borrowIx);
1870
+ }
1871
+
1872
+ async addRepayAndWithdrawIxs(withdrawCollateralAmount: BN) {
1541
1873
  this.lendingIxsLabels.push(
1542
1874
  `repayObligationLiquidity(reserve=${this.reserve!.address})(obligation=${this.getObligationPda()})`
1543
1875
  );
@@ -1607,61 +1939,31 @@ export class KaminoAction {
1607
1939
  );
1608
1940
  }
1609
1941
 
1610
- addRepayAndWithdrawV2Ixs(withdrawCollateralAmount: BN) {
1942
+ async addRepayAndWithdrawIxsV2(withdrawCollateralAmount: BN) {
1611
1943
  this.lendingIxsLabels.push(
1612
- `repayAndWithdrawAndRedeem(repayReserve=${this.reserve!.address})(withdrawReserve=${
1613
- this.outflowReserve!.address
1614
- })(obligation=${this.getObligationPda()})`
1944
+ `repayObligationLiquidityV2(reserve=${this.reserve!.address})(obligation=${this.getObligationPda()})`
1615
1945
  );
1946
+ this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateralV2`);
1616
1947
 
1617
1948
  const depositReservesList = this.getAdditionalDepositReservesList();
1618
1949
 
1619
1950
  const depositReserveAccountMetas = depositReservesList.map((reserve) => {
1620
1951
  return { pubkey: reserve, isSigner: false, isWritable: true };
1621
1952
  });
1622
- const borrowReserveAccountMetas = this.borrowReserves.map((reserve) => {
1623
- return { pubkey: reserve, isSigner: false, isWritable: true };
1624
- });
1625
-
1626
- if (!this.outflowAmount) {
1627
- throw new Error(`outflowAmount not set`);
1628
- }
1629
-
1630
- if (!this.outflowReserve) {
1631
- throw new Error(`outflowReserve not set`);
1632
- }
1633
-
1634
- if (!this.additionalTokenAccountAddress) {
1635
- throw new Error(`additionalTokenAccountAddress not set`);
1636
- }
1637
-
1638
- const collateralFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(PublicKey.default)
1639
- ? {
1640
- obligationFarmUserState: this.kaminoMarket.programId,
1641
- reserveFarmState: this.kaminoMarket.programId,
1642
- }
1643
- : {
1644
- obligationFarmUserState: obligationFarmStatePda(
1645
- this.outflowReserve.state.farmCollateral,
1646
- this.getObligationPda()
1647
- ),
1648
- reserveFarmState: this.outflowReserve.state.farmCollateral,
1649
- };
1650
1953
 
1651
1954
  const debtFarmsAccounts = this.reserve.state.farmDebt.equals(PublicKey.default)
1652
1955
  ? {
1653
- obligationFarmUserState: this.kaminoMarket.programId,
1654
- reserveFarmState: this.kaminoMarket.programId,
1956
+ obligationFarmUserState: PROGRAM_ID,
1957
+ reserveFarmState: PROGRAM_ID,
1655
1958
  }
1656
1959
  : {
1657
- obligationFarmUserState: obligationFarmStatePda(this.reserve.state.farmDebt, this.getObligationPda()),
1960
+ obligationFarmUserState: obligationFarmStatePda(this.getObligationPda(), this.reserve.state.farmDebt)[0],
1658
1961
  reserveFarmState: this.reserve.state.farmDebt,
1659
1962
  };
1660
1963
 
1661
- const repayAndWithdrawIx = repayAndWithdrawAndRedeem(
1964
+ const repayIx = repayObligationLiquidityV2(
1662
1965
  {
1663
- repayAmount: this.amount,
1664
- withdrawCollateralAmount,
1966
+ liquidityAmount: this.amount,
1665
1967
  },
1666
1968
  {
1667
1969
  repayAccounts: {
@@ -1675,57 +1977,16 @@ export class KaminoAction {
1675
1977
  tokenProgram: this.reserve.getLiquidityTokenProgram(),
1676
1978
  instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1677
1979
  },
1678
- withdrawAccounts: {
1679
- owner: this.owner,
1680
- obligation: this.getObligationPda(),
1681
- lendingMarket: this.kaminoMarket.getAddress(),
1682
- lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1683
- withdrawReserve: this.outflowReserve.address,
1684
- reserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
1685
- reserveCollateralMint: this.outflowReserve.getCTokenMint(),
1686
- reserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
1687
- reserveSourceCollateral: this.outflowReserve.state.collateral.supplyVault,
1688
- userDestinationLiquidity: this.additionalTokenAccountAddress,
1689
- placeholderUserDestinationCollateral: this.kaminoMarket.programId,
1690
- collateralTokenProgram: TOKEN_PROGRAM_ID,
1691
- liquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
1692
- instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1693
- },
1694
- collateralFarmsAccounts,
1695
- debtFarmsAccounts,
1980
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1981
+ farmsAccounts: debtFarmsAccounts,
1696
1982
  farmsProgram: farmsId,
1697
1983
  },
1698
1984
  this.kaminoMarket.programId
1699
1985
  );
1700
1986
 
1701
- repayAndWithdrawIx.keys = repayAndWithdrawIx.keys.concat([
1702
- ...depositReserveAccountMetas,
1703
- ...borrowReserveAccountMetas,
1704
- ]);
1705
-
1706
- this.lendingIxs.push(repayAndWithdrawIx);
1707
- }
1708
-
1709
- addDepositAndWithdrawV2Ixs(withdrawCollateralAmount: BN) {
1710
- this.lendingIxsLabels.push(
1711
- `depositAndWithdrawV2(depositReserve=${this.reserve!.address})(withdrawReserve=${
1712
- this.outflowReserve!.address
1713
- })(obligation=${this.getObligationPda()})`
1714
- );
1715
-
1716
- const depositReservesList = this.getAdditionalDepositReservesList();
1717
-
1718
- const depositReserveAccountMetas = depositReservesList.map((reserve) => {
1719
- return { pubkey: reserve, isSigner: false, isWritable: true };
1720
- });
1721
- const borrowReserveAccountMetas = this.borrowReserves.map((reserve) => {
1722
- return { pubkey: reserve, isSigner: false, isWritable: true };
1723
- });
1724
-
1725
- if (!this.outflowAmount) {
1726
- throw new Error(`outflowAmount not set`);
1727
- }
1987
+ repayIx.keys = repayIx.keys.concat([...depositReserveAccountMetas]);
1728
1988
 
1989
+ this.lendingIxs.push(repayIx);
1729
1990
  if (!this.outflowReserve) {
1730
1991
  throw new Error(`outflowReserve not set`);
1731
1992
  }
@@ -1734,145 +1995,54 @@ export class KaminoAction {
1734
1995
  throw new Error(`additionalTokenAccountAddress not set`);
1735
1996
  }
1736
1997
 
1737
- const depositFarmsAccounts = this.reserve.state.farmCollateral.equals(PublicKey.default)
1738
- ? {
1739
- obligationFarmUserState: this.kaminoMarket.programId,
1740
- reserveFarmState: this.kaminoMarket.programId,
1741
- }
1742
- : {
1743
- obligationFarmUserState: obligationFarmStatePda(this.reserve.state.farmDebt, this.getObligationPda()),
1744
- reserveFarmState: this.reserve.state.farmCollateral,
1745
- };
1746
- const withdrawFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(PublicKey.default)
1998
+ if (!this.outflowAmount) {
1999
+ throw new Error(`outflowAmount not set`);
2000
+ }
2001
+
2002
+ const collateralFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(PublicKey.default)
1747
2003
  ? {
1748
- obligationFarmUserState: this.kaminoMarket.programId,
1749
- reserveFarmState: this.kaminoMarket.programId,
2004
+ obligationFarmUserState: PROGRAM_ID,
2005
+ reserveFarmState: PROGRAM_ID,
1750
2006
  }
1751
2007
  : {
1752
2008
  obligationFarmUserState: obligationFarmStatePda(
1753
- this.outflowReserve.state.farmCollateral,
1754
- this.getObligationPda()
1755
- ),
2009
+ this.getObligationPda(),
2010
+ this.outflowReserve.state.farmCollateral
2011
+ )[0],
1756
2012
  reserveFarmState: this.outflowReserve.state.farmCollateral,
1757
2013
  };
1758
2014
 
1759
- const depositAndWithdrawIx = depositAndWithdraw(
1760
- {
1761
- liquidityAmount: this.amount,
1762
- withdrawCollateralAmount,
1763
- },
1764
- {
1765
- depositAccounts: {
1766
- owner: this.owner,
1767
- obligation: this.getObligationPda(),
1768
- lendingMarket: this.kaminoMarket.getAddress(),
1769
- lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1770
- reserve: this.reserve.address,
1771
- reserveLiquidityMint: this.reserve.getLiquidityMint(),
1772
- reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
1773
- reserveCollateralMint: this.reserve.getCTokenMint(),
1774
- reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
1775
- userSourceLiquidity: this.userTokenAccountAddress,
1776
- placeholderUserDestinationCollateral: this.kaminoMarket.programId,
1777
- collateralTokenProgram: TOKEN_PROGRAM_ID,
1778
- liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
1779
- instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1780
- },
1781
- withdrawAccounts: {
1782
- owner: this.owner,
1783
- obligation: this.getObligationPda(),
1784
- lendingMarket: this.kaminoMarket.getAddress(),
1785
- lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1786
- withdrawReserve: this.outflowReserve.address,
1787
- reserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
1788
- reserveCollateralMint: this.outflowReserve.getCTokenMint(),
1789
- reserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
1790
- reserveSourceCollateral: this.outflowReserve.state.collateral.supplyVault,
1791
- userDestinationLiquidity: this.additionalTokenAccountAddress,
1792
- placeholderUserDestinationCollateral: this.kaminoMarket.programId,
1793
- collateralTokenProgram: TOKEN_PROGRAM_ID,
1794
- liquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
1795
- instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1796
- },
1797
- depositFarmsAccounts,
1798
- withdrawFarmsAccounts,
1799
- farmsProgram: farmsId,
1800
- },
1801
- this.kaminoMarket.programId
1802
- );
1803
-
1804
- depositAndWithdrawIx.keys = depositAndWithdrawIx.keys.concat([
1805
- ...depositReserveAccountMetas,
1806
- ...borrowReserveAccountMetas,
1807
- ]);
1808
-
1809
- this.lendingIxs.push(depositAndWithdrawIx);
1810
- }
1811
-
1812
- addWithdrawIx(withdrawCollateralAmount: BN) {
1813
- this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateral`);
1814
2015
  this.lendingIxs.push(
1815
- withdrawObligationCollateralAndRedeemReserveCollateral(
2016
+ withdrawObligationCollateralAndRedeemReserveCollateralV2(
1816
2017
  {
1817
2018
  collateralAmount: withdrawCollateralAmount,
1818
2019
  },
1819
2020
  {
1820
- owner: this.owner,
1821
- obligation: this.getObligationPda(),
1822
- lendingMarket: this.kaminoMarket.getAddress(),
1823
- lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1824
- withdrawReserve: this.reserve.address,
1825
- reserveLiquidityMint: this.reserve.getLiquidityMint(),
1826
- reserveCollateralMint: this.reserve.getCTokenMint(),
1827
- reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
1828
- reserveSourceCollateral: this.reserve.state.collateral.supplyVault,
1829
- userDestinationLiquidity: this.userTokenAccountAddress,
1830
- placeholderUserDestinationCollateral: this.kaminoMarket.programId,
1831
- collateralTokenProgram: TOKEN_PROGRAM_ID,
1832
- liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
1833
- instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
2021
+ withdrawAccounts: {
2022
+ owner: this.owner,
2023
+ obligation: this.getObligationPda(),
2024
+ lendingMarket: this.kaminoMarket.getAddress(),
2025
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
2026
+ withdrawReserve: this.outflowReserve.address,
2027
+ reserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
2028
+ reserveCollateralMint: this.outflowReserve.getCTokenMint(),
2029
+ reserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
2030
+ reserveSourceCollateral: this.outflowReserve.state.collateral.supplyVault,
2031
+ userDestinationLiquidity: this.additionalTokenAccountAddress,
2032
+ placeholderUserDestinationCollateral: this.kaminoMarket.programId,
2033
+ collateralTokenProgram: TOKEN_PROGRAM_ID,
2034
+ liquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
2035
+ instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
2036
+ },
2037
+ farmsAccounts: collateralFarmsAccounts,
2038
+ farmsProgram: farmsId,
1834
2039
  },
1835
2040
  this.kaminoMarket.programId
1836
2041
  )
1837
2042
  );
1838
2043
  }
1839
2044
 
1840
- addRepayIx() {
1841
- this.lendingIxsLabels.push(
1842
- `repayObligationLiquidity(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`
1843
- );
1844
-
1845
- const depositReservesList = this.getAdditionalDepositReservesList();
1846
-
1847
- const depositReserveAccountMetas = depositReservesList.map((reserve) => {
1848
- return { pubkey: reserve, isSigner: false, isWritable: true };
1849
- });
1850
-
1851
- const repayIx = repayObligationLiquidity(
1852
- {
1853
- liquidityAmount: this.amount,
1854
- },
1855
- {
1856
- owner: this.payer,
1857
- obligation: this.getObligationPda(),
1858
- lendingMarket: this.kaminoMarket.getAddress(),
1859
- repayReserve: this.reserve.address,
1860
- reserveLiquidityMint: this.reserve.getLiquidityMint(),
1861
- userSourceLiquidity: this.userTokenAccountAddress,
1862
- reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
1863
- tokenProgram: this.reserve.getLiquidityTokenProgram(),
1864
- instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1865
- },
1866
- this.kaminoMarket.programId
1867
- );
1868
-
1869
- repayIx.keys =
1870
- this.obligation!.state.elevationGroup > 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
1871
-
1872
- this.lendingIxs.push(repayIx);
1873
- }
1874
-
1875
- addLiquidateIx(maxAllowedLtvOverridePercent: number = 0) {
2045
+ async addLiquidateIx(maxAllowedLtvOverridePercent: number = 0) {
1876
2046
  this.lendingIxsLabels.push(`liquidateObligationAndRedeemReserveCollateral`);
1877
2047
  if (!this.outflowReserve) {
1878
2048
  throw Error(`Withdraw reserve during liquidation is not defined`);
@@ -1924,16 +2094,97 @@ export class KaminoAction {
1924
2094
  this.lendingIxs.push(liquidateIx);
1925
2095
  }
1926
2096
 
2097
+ async addLiquidateIxV2(maxAllowedLtvOverridePercent: number = 0) {
2098
+ this.lendingIxsLabels.push(`liquidateObligationAndRedeemReserveCollateralV2`);
2099
+ if (!this.outflowReserve) {
2100
+ throw Error(`Withdraw reserve during liquidation is not defined`);
2101
+ }
2102
+ if (!this.additionalTokenAccountAddress) {
2103
+ throw Error(`Liquidating token account address is not defined`);
2104
+ }
2105
+
2106
+ const depositReservesList = this.getAdditionalDepositReservesList();
2107
+ const depositReserveAccountMetas = depositReservesList.map((reserve) => {
2108
+ return { pubkey: reserve, isSigner: false, isWritable: true };
2109
+ });
2110
+
2111
+ const collateralFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(PublicKey.default)
2112
+ ? {
2113
+ obligationFarmUserState: PROGRAM_ID,
2114
+ reserveFarmState: PROGRAM_ID,
2115
+ }
2116
+ : {
2117
+ obligationFarmUserState: obligationFarmStatePda(
2118
+ this.getObligationPda(),
2119
+ this.outflowReserve.state.farmCollateral
2120
+ )[0],
2121
+ reserveFarmState: this.outflowReserve.state.farmCollateral,
2122
+ };
2123
+
2124
+ const debtFarmsAccounts = this.reserve.state.farmDebt.equals(PublicKey.default)
2125
+ ? {
2126
+ obligationFarmUserState: PROGRAM_ID,
2127
+ reserveFarmState: PROGRAM_ID,
2128
+ }
2129
+ : {
2130
+ obligationFarmUserState: obligationFarmStatePda(this.getObligationPda(), this.reserve.state.farmDebt)[0],
2131
+ reserveFarmState: this.reserve.state.farmDebt,
2132
+ };
2133
+
2134
+ const liquidateIx = liquidateObligationAndRedeemReserveCollateralV2(
2135
+ {
2136
+ liquidityAmount: this.amount,
2137
+ // TODO: Configure this when updating liquidator with new interface
2138
+ minAcceptableReceivedLiquidityAmount: this.outflowAmount || new BN(0),
2139
+ maxAllowedLtvOverridePercent: new BN(maxAllowedLtvOverridePercent),
2140
+ },
2141
+ {
2142
+ liquidationAccounts: {
2143
+ liquidator: this.owner,
2144
+ obligation: this.getObligationPda(),
2145
+ lendingMarket: this.kaminoMarket.getAddress(),
2146
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
2147
+ repayReserve: this.reserve.address,
2148
+ repayReserveLiquidityMint: this.reserve.getLiquidityMint(),
2149
+ repayReserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
2150
+ withdrawReserve: this.outflowReserve.address,
2151
+ withdrawReserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
2152
+ withdrawReserveCollateralMint: this.outflowReserve.getCTokenMint(),
2153
+ withdrawReserveCollateralSupply: this.outflowReserve.state.collateral.supplyVault,
2154
+ withdrawReserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
2155
+ userSourceLiquidity: this.additionalTokenAccountAddress,
2156
+ userDestinationCollateral: this.userCollateralAccountAddress,
2157
+ userDestinationLiquidity: this.userTokenAccountAddress,
2158
+ withdrawReserveLiquidityFeeReceiver: this.outflowReserve.state.liquidity.feeVault,
2159
+ collateralTokenProgram: TOKEN_PROGRAM_ID,
2160
+ repayLiquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
2161
+ withdrawLiquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
2162
+ instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
2163
+ },
2164
+ debtFarmsAccounts,
2165
+ collateralFarmsAccounts,
2166
+ farmsProgram: farmsId,
2167
+ },
2168
+ this.kaminoMarket.programId
2169
+ );
2170
+ liquidateIx.keys =
2171
+ this.obligation!.state.elevationGroup > 0
2172
+ ? liquidateIx.keys.concat([...depositReserveAccountMetas])
2173
+ : liquidateIx.keys;
2174
+ this.lendingIxs.push(liquidateIx);
2175
+ }
2176
+
1927
2177
  async addInBetweenIxs(
1928
2178
  action: ActionType,
1929
2179
  includeAtaIxns: boolean,
1930
2180
  requestElevationGroup: boolean,
1931
- addInitObligationForFarm: boolean
2181
+ addInitObligationForFarm: boolean,
2182
+ useV2Ixs: boolean
1932
2183
  ) {
1933
2184
  await this.addSupportIxsWithoutInitObligation(
1934
2185
  action,
1935
2186
  includeAtaIxns,
1936
- false,
2187
+ useV2Ixs,
1937
2188
  'inBetween',
1938
2189
  requestElevationGroup,
1939
2190
  addInitObligationForFarm
@@ -1988,7 +2239,6 @@ export class KaminoAction {
1988
2239
  'repay',
1989
2240
  'depositAndBorrow',
1990
2241
  'repayAndWithdraw',
1991
- 'repayAndWithdrawV2',
1992
2242
  'refreshObligation',
1993
2243
  ].includes(action)
1994
2244
  ) {
@@ -2007,17 +2257,12 @@ export class KaminoAction {
2007
2257
 
2008
2258
  let currentReserves: KaminoReserve[] = [];
2009
2259
 
2010
- if (
2011
- action === 'liquidate' ||
2012
- action === 'depositAndBorrow' ||
2013
- action === 'repayAndWithdraw' ||
2014
- action === 'repayAndWithdrawV2'
2015
- ) {
2260
+ if (action === 'liquidate' || action === 'depositAndBorrow' || action === 'repayAndWithdraw') {
2016
2261
  if (!this.outflowReserve) {
2017
2262
  throw new Error('outflowReserve is undefined');
2018
2263
  }
2019
2264
 
2020
- if (action === 'depositAndBorrow' || action === 'repayAndWithdraw' || action === 'repayAndWithdrawV2') {
2265
+ if (action === 'depositAndBorrow' || action === 'repayAndWithdraw') {
2021
2266
  currentReserves = [this.reserve, this.outflowReserve];
2022
2267
  if (action === 'depositAndBorrow') {
2023
2268
  if (this.obligation) {
@@ -2062,12 +2307,7 @@ export class KaminoAction {
2062
2307
  if (this.outflowReserve) {
2063
2308
  await this.addInitObligationForFarm(this.outflowReserve, ReserveFarmKind.Debt, addAsSupportIx);
2064
2309
  }
2065
- } else if (
2066
- action === 'repayAndWithdraw' ||
2067
- action === 'borrow' ||
2068
- action === 'repay' ||
2069
- action === 'repayAndWithdrawV2'
2070
- ) {
2310
+ } else if (action === 'repayAndWithdraw' || action === 'borrow' || action === 'repay') {
2071
2311
  // todo - probably don't need to add both debt and collateral for everything here
2072
2312
  await this.addInitObligationForFarm(this.reserve, ReserveFarmKind.Debt, addAsSupportIx);
2073
2313
  if (this.outflowReserve) {
@@ -2098,7 +2338,7 @@ export class KaminoAction {
2098
2338
  }
2099
2339
 
2100
2340
  if (requestElevationGroup) {
2101
- if (action === 'repay' || action === 'repayAndWithdrawV2') {
2341
+ if (action === 'repay') {
2102
2342
  const repayObligationLiquidity = this.obligation!.borrows.get(this.reserve.address);
2103
2343
 
2104
2344
  if (!repayObligationLiquidity) {
@@ -2287,7 +2527,7 @@ export class KaminoAction {
2287
2527
  if (action === 'deposit' && this.outflowReserve) {
2288
2528
  await this.addInitReferrerTokenStateIx(this.outflowReserve);
2289
2529
  }
2290
- this.addInitObligationIxs();
2530
+ await this.addInitObligationIxs();
2291
2531
  }
2292
2532
 
2293
2533
  await this.addSupportIxsWithoutInitObligation(
@@ -2519,7 +2759,7 @@ export class KaminoAction {
2519
2759
  farms.push([
2520
2760
  ReserveFarmKind.Collateral,
2521
2761
  kaminoReserve.state.farmCollateral,
2522
- obligationFarmStatePda(kaminoReserve.state.farmCollateral, this.getObligationPda()),
2762
+ obligationFarmStatePda(this.getObligationPda(), kaminoReserve.state.farmCollateral)[0],
2523
2763
  kaminoReserve,
2524
2764
  ]);
2525
2765
  }
@@ -2527,7 +2767,7 @@ export class KaminoAction {
2527
2767
  farms.push([
2528
2768
  ReserveFarmKind.Debt,
2529
2769
  kaminoReserve.state.farmDebt,
2530
- obligationFarmStatePda(kaminoReserve.state.farmDebt, this.getObligationPda()),
2770
+ obligationFarmStatePda(this.getObligationPda(), kaminoReserve.state.farmDebt)[0],
2531
2771
  kaminoReserve,
2532
2772
  ]);
2533
2773
  }
@@ -2611,18 +2851,18 @@ export class KaminoAction {
2611
2851
  const farms: [number, PublicKey, PublicKey][] = [];
2612
2852
 
2613
2853
  if (mode === ReserveFarmKind.Collateral && isNotNullPubkey(reserve.state.farmCollateral)) {
2614
- const pda = obligationFarmStatePda(reserve.state.farmCollateral, this.getObligationPda());
2615
- const account = await this.kaminoMarket.getConnection().getAccountInfo(pda);
2854
+ const userPda = obligationFarmStatePda(this.getObligationPda(), reserve.state.farmCollateral)[0];
2855
+ const account = await this.kaminoMarket.getConnection().getAccountInfo(userPda);
2616
2856
  if (!account) {
2617
- farms.push([ReserveFarmKind.Collateral.discriminator, reserve.state.farmCollateral, pda]);
2857
+ farms.push([ReserveFarmKind.Collateral.discriminator, reserve.state.farmCollateral, userPda]);
2618
2858
  }
2619
2859
  }
2620
2860
 
2621
2861
  if (mode === ReserveFarmKind.Debt && isNotNullPubkey(reserve.state.farmDebt)) {
2622
- const pda = obligationFarmStatePda(reserve.state.farmDebt, this.getObligationPda());
2623
- const account = await this.kaminoMarket.getConnection().getAccountInfo(pda);
2862
+ const userPda = obligationFarmStatePda(this.getObligationPda(), reserve.state.farmDebt)[0];
2863
+ const account = await this.kaminoMarket.getConnection().getAccountInfo(userPda);
2624
2864
  if (!account) {
2625
- farms.push([ReserveFarmKind.Debt.discriminator, reserve.state.farmDebt, pda]);
2865
+ farms.push([ReserveFarmKind.Debt.discriminator, reserve.state.farmDebt, userPda]);
2626
2866
  }
2627
2867
  }
2628
2868
 
@@ -2656,7 +2896,7 @@ export class KaminoAction {
2656
2896
  });
2657
2897
  }
2658
2898
 
2659
- private addInitObligationIxs() {
2899
+ private async addInitObligationIxs() {
2660
2900
  if (!this.obligation) {
2661
2901
  const obligationPda = this.getObligationPda();
2662
2902
  const [userMetadataAddress, _bump] = userMetadataPda(this.owner, this.kaminoMarket.programId);
@@ -2879,7 +3119,7 @@ export class KaminoAction {
2879
3119
 
2880
3120
  let safeRepay = new BN(this.amount);
2881
3121
 
2882
- if (this.obligation && (action === 'repay' || action === 'repayAndWithdrawV2') && this.amount.eq(new BN(U64_MAX))) {
3122
+ if (this.obligation && action === 'repay' && this.amount.eq(new BN(U64_MAX))) {
2883
3123
  const borrow = this.obligation.state.borrows.find(
2884
3124
  (borrow) => borrow.borrowReserve.toString() === this.reserve.address.toString()
2885
3125
  );
@@ -2893,7 +3133,7 @@ export class KaminoAction {
2893
3133
  this.currentSlot,
2894
3134
  this.kaminoMarket.state.referralFeeBps
2895
3135
  );
2896
-
3136
+ // TODO: shouldn't this calc be added to all other stuff as well?
2897
3137
  safeRepay = new BN(
2898
3138
  Math.floor(
2899
3139
  KaminoObligation.getBorrowAmount(borrow)
@@ -2921,7 +3161,6 @@ export class KaminoAction {
2921
3161
  const sendAction =
2922
3162
  action === 'deposit' ||
2923
3163
  action === 'repay' ||
2924
- action === 'repayAndWithdrawV2' ||
2925
3164
  action === 'mint' ||
2926
3165
  (action === 'liquidate' && this.secondaryMint?.equals(NATIVE_MINT)); // only sync WSOL amount if liquidator repays SOL which is secondaryMint
2927
3166
 
@@ -3031,7 +3270,7 @@ export class KaminoAction {
3031
3270
  additionalUserTokenAccountAddress = userOutflowTokenAccountAddress;
3032
3271
  primaryMint = inflowTokenMint;
3033
3272
  secondaryMint = outflowTokenMint;
3034
- } else if (action === 'repayAndWithdraw' || action === 'repayAndWithdrawV2') {
3273
+ } else if (action === 'repayAndWithdraw') {
3035
3274
  primaryMint = inflowTokenMint;
3036
3275
  secondaryMint = outflowTokenMint;
3037
3276
  userTokenAccountAddress = userInflowTokenAccountAddress;