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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/dist/classes/action.d.ts +26 -24
  2. package/dist/classes/action.d.ts.map +1 -1
  3. package/dist/classes/action.js +270 -501
  4. package/dist/classes/action.js.map +1 -1
  5. package/dist/classes/manager.js +1 -1
  6. package/dist/classes/manager.js.map +1 -1
  7. package/dist/classes/obligation.d.ts +1 -1
  8. package/dist/classes/obligation.d.ts.map +1 -1
  9. package/dist/classes/obligation.js +1 -1
  10. package/dist/classes/obligation.js.map +1 -1
  11. package/dist/classes/vault.js +6 -6
  12. package/dist/classes/vault.js.map +1 -1
  13. package/dist/lending_operations/repay_with_collateral_calcs.d.ts.map +1 -1
  14. package/dist/lending_operations/repay_with_collateral_calcs.js +9 -5
  15. package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
  16. package/dist/lending_operations/repay_with_collateral_operations.d.ts +7 -3
  17. package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
  18. package/dist/lending_operations/repay_with_collateral_operations.js +27 -7
  19. package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
  20. package/dist/lending_operations/swap_collateral_operations.d.ts +0 -5
  21. package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
  22. package/dist/lending_operations/swap_collateral_operations.js +2 -4
  23. package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
  24. package/dist/leverage/operations.d.ts +8 -8
  25. package/dist/leverage/operations.d.ts.map +1 -1
  26. package/dist/leverage/operations.js +24 -27
  27. package/dist/leverage/operations.js.map +1 -1
  28. package/dist/leverage/types.d.ts +1 -4
  29. package/dist/leverage/types.d.ts.map +1 -1
  30. package/dist/utils/lookupTable.d.ts +27 -0
  31. package/dist/utils/lookupTable.d.ts.map +1 -1
  32. package/dist/utils/lookupTable.js +58 -0
  33. package/dist/utils/lookupTable.js.map +1 -1
  34. package/dist/utils/seeds.d.ts +9 -3
  35. package/dist/utils/seeds.d.ts.map +1 -1
  36. package/dist/utils/seeds.js +11 -5
  37. package/dist/utils/seeds.js.map +1 -1
  38. package/dist/utils/userMetadata.js +6 -6
  39. package/dist/utils/userMetadata.js.map +1 -1
  40. package/package.json +1 -4
  41. package/src/classes/action.ts +423 -662
  42. package/src/classes/manager.ts +1 -1
  43. package/src/classes/obligation.ts +1 -1
  44. package/src/classes/vault.ts +1 -1
  45. package/src/client.ts +3 -7
  46. package/src/lending_operations/repay_with_collateral_calcs.ts +14 -5
  47. package/src/lending_operations/repay_with_collateral_operations.ts +30 -14
  48. package/src/lending_operations/swap_collateral_operations.ts +0 -11
  49. package/src/leverage/operations.ts +11 -38
  50. package/src/leverage/types.ts +1 -4
  51. package/src/utils/lookupTable.ts +62 -0
  52. package/src/utils/seeds.ts +12 -7
  53. package/src/utils/userMetadata.ts +14 -14
  54. package/dist/classes/lut_utils.d.ts +0 -29
  55. package/dist/classes/lut_utils.d.ts.map +0 -1
  56. package/dist/classes/lut_utils.js +0 -62
  57. package/dist/classes/lut_utils.js.map +0 -1
  58. package/src/classes/lut_utils.ts +0 -63
@@ -21,12 +21,10 @@ import BN from 'bn.js';
21
21
  import Decimal from 'decimal.js';
22
22
  import {
23
23
  borrowObligationLiquidity,
24
- borrowObligationLiquidityV2,
24
+ depositAndWithdraw,
25
25
  depositObligationCollateral,
26
- depositObligationCollateralV2,
27
26
  depositReserveLiquidity,
28
27
  depositReserveLiquidityAndObligationCollateral,
29
- depositReserveLiquidityAndObligationCollateralV2,
30
28
  initObligation,
31
29
  initObligationFarmsForReserve,
32
30
  InitObligationFarmsForReserveAccounts,
@@ -34,20 +32,18 @@ import {
34
32
  initReferrerTokenState,
35
33
  initUserMetadata,
36
34
  liquidateObligationAndRedeemReserveCollateral,
37
- liquidateObligationAndRedeemReserveCollateralV2,
38
35
  redeemReserveCollateral,
39
36
  refreshObligation,
40
37
  refreshObligationFarmsForReserve,
41
38
  RefreshObligationFarmsForReserveAccounts,
42
39
  RefreshObligationFarmsForReserveArgs,
43
40
  refreshReserve,
41
+ repayAndWithdrawAndRedeem,
44
42
  repayObligationLiquidity,
45
- repayObligationLiquidityV2,
46
43
  requestElevationGroup,
47
44
  RequestElevationGroupAccounts,
48
45
  RequestElevationGroupArgs,
49
46
  withdrawObligationCollateralAndRedeemReserveCollateral,
50
- withdrawObligationCollateralAndRedeemReserveCollateralV2,
51
47
  withdrawReferrerFees,
52
48
  } from '../idl_codegen/instructions';
53
49
  import {
@@ -90,7 +86,9 @@ export type ActionType =
90
86
  | 'repayAndWithdraw'
91
87
  | 'refreshObligation'
92
88
  | 'requestElevationGroup'
93
- | 'withdrawReferrerFees';
89
+ | 'withdrawReferrerFees'
90
+ | 'repayAndWithdrawV2'
91
+ | 'depositAndWithdraw';
94
92
 
95
93
  export type AuxiliaryIx = 'setup' | 'inBetween' | 'cleanup';
96
94
 
@@ -410,7 +408,6 @@ export class KaminoAction {
410
408
  mint: PublicKey,
411
409
  owner: PublicKey,
412
410
  obligation: KaminoObligation | ObligationType,
413
- useV2Ixs: boolean,
414
411
  extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
415
412
  includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
416
413
  requestElevationGroup: boolean = false, // to be requested *before* the deposit
@@ -453,16 +450,12 @@ export class KaminoAction {
453
450
  requestElevationGroup,
454
451
  includeUserMetadata,
455
452
  addInitObligationForFarm,
456
- useV2Ixs,
453
+ false,
457
454
  createLookupTable,
458
455
  undefined,
459
456
  overrideElevationGroupRequest
460
457
  );
461
- if (useV2Ixs) {
462
- axn.addDepositIxV2();
463
- } else {
464
- axn.addDepositIx();
465
- }
458
+ axn.addDepositIx();
466
459
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
467
460
 
468
461
  return axn;
@@ -512,7 +505,6 @@ export class KaminoAction {
512
505
  mint: PublicKey,
513
506
  owner: PublicKey,
514
507
  obligation: KaminoObligation | ObligationType,
515
- useV2Ixs: boolean,
516
508
  extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
517
509
  includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
518
510
  requestElevationGroup: boolean = false,
@@ -555,16 +547,12 @@ export class KaminoAction {
555
547
  requestElevationGroup,
556
548
  includeUserMetadata,
557
549
  addInitObligationForFarm,
558
- useV2Ixs,
550
+ false,
559
551
  createLookupTable,
560
552
  undefined,
561
553
  overrideElevationGroupRequest
562
554
  );
563
- if (useV2Ixs) {
564
- axn.addBorrowIxV2();
565
- } else {
566
- axn.addBorrowIx();
567
- }
555
+ axn.addBorrowIx();
568
556
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
569
557
 
570
558
  return axn;
@@ -684,7 +672,6 @@ export class KaminoAction {
684
672
  mint: PublicKey,
685
673
  owner: PublicKey,
686
674
  obligation: KaminoObligation | ObligationType,
687
- useV2Ixs: boolean,
688
675
  extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
689
676
  includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas
690
677
  requestElevationGroup: boolean = false,
@@ -727,14 +714,10 @@ export class KaminoAction {
727
714
  requestElevationGroup,
728
715
  includeUserMetadata,
729
716
  addInitObligationForFarm,
730
- useV2Ixs,
717
+ false,
731
718
  createLookupTable
732
719
  );
733
- if (useV2Ixs) {
734
- axn.addDepositObligationCollateralIxV2();
735
- } else {
736
- axn.addDepositObligationCollateralIx();
737
- }
720
+ axn.addDepositObligationCollateralIx();
738
721
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
739
722
  return axn;
740
723
  }
@@ -747,7 +730,6 @@ export class KaminoAction {
747
730
  borrowMint: PublicKey,
748
731
  payer: PublicKey,
749
732
  obligation: KaminoObligation | ObligationType,
750
- useV2Ixs: boolean,
751
733
  extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
752
734
  includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
753
735
  requestElevationGroup: boolean = false,
@@ -796,27 +778,147 @@ export class KaminoAction {
796
778
  requestElevationGroup,
797
779
  includeUserMetadata,
798
780
  addInitObligationForFarmForDeposit,
799
- useV2Ixs,
781
+ false,
800
782
  createLookupTable,
801
783
  twoTokenAction
802
784
  );
803
-
804
- if (useV2Ixs) {
805
- await axn.addDepositAndBorrowIxV2();
806
- } else {
807
- await axn.addDepositAndBorrowIx();
808
- }
785
+ axn.addDepositAndBorrowIx();
809
786
  await axn.addInBetweenIxs(
810
787
  'depositAndBorrow',
811
788
  includeAtaIxns,
812
789
  requestElevationGroup,
813
- addInitObligationForFarmForBorrow,
814
- useV2Ixs
790
+ addInitObligationForFarmForBorrow
815
791
  );
816
792
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
817
793
  return axn;
818
794
  }
819
795
 
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
+
820
922
  static async buildRepayAndWithdrawTxns(
821
923
  kaminoMarket: KaminoMarket,
822
924
  repayAmount: string | BN,
@@ -826,7 +928,6 @@ export class KaminoAction {
826
928
  payer: PublicKey,
827
929
  currentSlot: number,
828
930
  obligation: KaminoObligation | ObligationType,
829
- useV2Ixs: boolean,
830
931
  extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
831
932
  includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
832
933
  requestElevationGroup: boolean = false,
@@ -873,24 +974,19 @@ export class KaminoAction {
873
974
  requestElevationGroup,
874
975
  includeUserMetadata,
875
976
  addInitObligationForFarmForRepay,
876
- useV2Ixs,
977
+ false,
877
978
  createLookupTable,
878
979
  twoTokenAction
879
980
  );
880
981
 
881
982
  const withdrawCollateralAmount = axn.getWithdrawCollateralAmount(axn.outflowReserve!, axn.outflowAmount!);
882
- if (useV2Ixs) {
883
- await axn.addRepayAndWithdrawIxsV2(withdrawCollateralAmount);
884
- } else {
885
- await axn.addRepayAndWithdrawIxs(withdrawCollateralAmount);
886
- }
887
983
 
984
+ await axn.addRepayAndWithdrawIxs(withdrawCollateralAmount);
888
985
  await axn.addInBetweenIxs(
889
986
  'repayAndWithdraw',
890
987
  includeAtaIxns,
891
988
  requestElevationGroup,
892
- addInitObligationForFarmForWithdraw,
893
- useV2Ixs
989
+ addInitObligationForFarmForWithdraw
894
990
  );
895
991
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
896
992
  return axn;
@@ -902,7 +998,6 @@ export class KaminoAction {
902
998
  mint: PublicKey,
903
999
  owner: PublicKey,
904
1000
  obligation: KaminoObligation | ObligationType,
905
- useV2Ixs: boolean,
906
1001
  extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
907
1002
  includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
908
1003
  requestElevationGroup: boolean = false, // to be requested *after* the withdraw
@@ -953,19 +1048,15 @@ export class KaminoAction {
953
1048
  requestElevationGroup,
954
1049
  includeUserMetadata,
955
1050
  addInitObligationForFarm,
956
- useV2Ixs,
1051
+ false,
957
1052
  createLookupTable,
958
1053
  false,
959
1054
  overrideElevationGroupRequest
960
1055
  );
961
1056
 
962
1057
  const collateralAmount = axn.getWithdrawCollateralAmount(axn.reserve, axn.amount);
963
- if (useV2Ixs) {
964
- await axn.addWithdrawIxV2(collateralAmount);
965
- } else {
966
- await axn.addWithdrawIx(collateralAmount);
967
- }
968
1058
 
1059
+ axn.addWithdrawIx(collateralAmount);
969
1060
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
970
1061
 
971
1062
  return axn;
@@ -992,7 +1083,6 @@ export class KaminoAction {
992
1083
  mint: PublicKey,
993
1084
  owner: PublicKey,
994
1085
  obligation: KaminoObligation | ObligationType,
995
- useV2Ixs: boolean,
996
1086
  currentSlot: number,
997
1087
  payer: PublicKey | undefined = undefined,
998
1088
  extraComputeBudget: number = 1_000_000,
@@ -1037,14 +1127,10 @@ export class KaminoAction {
1037
1127
  requestElevationGroup,
1038
1128
  includeUserMetadata,
1039
1129
  addInitObligationForFarm,
1040
- useV2Ixs,
1130
+ false,
1041
1131
  createLookupTable
1042
1132
  );
1043
- if (useV2Ixs) {
1044
- await axn.addRepayIxV2();
1045
- } else {
1046
- await axn.addRepayIx();
1047
- }
1133
+ axn.addRepayIx();
1048
1134
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
1049
1135
 
1050
1136
  return axn;
@@ -1059,7 +1145,6 @@ export class KaminoAction {
1059
1145
  liquidator: PublicKey,
1060
1146
  obligationOwner: PublicKey,
1061
1147
  obligation: KaminoObligation | ObligationType,
1062
- useV2Ixs: boolean,
1063
1148
  extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
1064
1149
  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
1065
1150
  requestElevationGroup: boolean = false,
@@ -1107,14 +1192,10 @@ export class KaminoAction {
1107
1192
  requestElevationGroup,
1108
1193
  includeUserMetadata,
1109
1194
  addInitObligationForFarm,
1110
- useV2Ixs,
1195
+ false,
1111
1196
  createLookupTable
1112
1197
  );
1113
- if (useV2Ixs) {
1114
- await axn.addLiquidateIxV2(maxAllowedLtvOverridePercent);
1115
- } else {
1116
- await axn.addLiquidateIx(maxAllowedLtvOverridePercent);
1117
- }
1198
+ axn.addLiquidateIx(maxAllowedLtvOverridePercent);
1118
1199
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
1119
1200
 
1120
1201
  return axn;
@@ -1240,23 +1321,25 @@ export class KaminoAction {
1240
1321
  return await sendTransaction(txn, this.kaminoMarket.getConnection());
1241
1322
  }
1242
1323
 
1243
- addDepositReserveLiquidityIx() {
1244
- this.lendingIxsLabels.push(`depositReserveLiquidity`);
1324
+ addDepositIx() {
1325
+ this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
1245
1326
  this.lendingIxs.push(
1246
- depositReserveLiquidity(
1327
+ depositReserveLiquidityAndObligationCollateral(
1247
1328
  {
1248
1329
  liquidityAmount: this.amount,
1249
1330
  },
1250
1331
  {
1251
1332
  owner: this.owner,
1333
+ obligation: this.getObligationPda(),
1252
1334
  lendingMarket: this.kaminoMarket.getAddress(),
1253
1335
  lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1254
1336
  reserve: this.reserve.address,
1255
1337
  reserveLiquidityMint: this.reserve.getLiquidityMint(),
1256
1338
  reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
1257
1339
  reserveCollateralMint: this.reserve.getCTokenMint(),
1340
+ reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
1258
1341
  userSourceLiquidity: this.userTokenAccountAddress,
1259
- userDestinationCollateral: this.userCollateralAccountAddress,
1342
+ placeholderUserDestinationCollateral: this.kaminoMarket.programId,
1260
1343
  collateralTokenProgram: TOKEN_PROGRAM_ID,
1261
1344
  liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
1262
1345
  instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
@@ -1266,12 +1349,12 @@ export class KaminoAction {
1266
1349
  );
1267
1350
  }
1268
1351
 
1269
- addRedeemReserveCollateralIx() {
1270
- this.lendingIxsLabels.push(`redeemReserveCollateral`);
1352
+ addDepositReserveLiquidityIx() {
1353
+ this.lendingIxsLabels.push(`depositReserveLiquidity`);
1271
1354
  this.lendingIxs.push(
1272
- redeemReserveCollateral(
1355
+ depositReserveLiquidity(
1273
1356
  {
1274
- collateralAmount: this.amount,
1357
+ liquidityAmount: this.amount,
1275
1358
  },
1276
1359
  {
1277
1360
  owner: this.owner,
@@ -1281,8 +1364,8 @@ export class KaminoAction {
1281
1364
  reserveLiquidityMint: this.reserve.getLiquidityMint(),
1282
1365
  reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
1283
1366
  reserveCollateralMint: this.reserve.getCTokenMint(),
1284
- userSourceCollateral: this.userCollateralAccountAddress,
1285
- userDestinationLiquidity: this.userTokenAccountAddress,
1367
+ userSourceLiquidity: this.userTokenAccountAddress,
1368
+ userDestinationCollateral: this.userCollateralAccountAddress,
1286
1369
  collateralTokenProgram: TOKEN_PROGRAM_ID,
1287
1370
  liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
1288
1371
  instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
@@ -1292,26 +1375,23 @@ export class KaminoAction {
1292
1375
  );
1293
1376
  }
1294
1377
 
1295
- // @deprecated -- use addDepositIxV2 instead
1296
- addDepositIx() {
1297
- this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
1378
+ addRedeemReserveCollateralIx() {
1379
+ this.lendingIxsLabels.push(`redeemReserveCollateral`);
1298
1380
  this.lendingIxs.push(
1299
- depositReserveLiquidityAndObligationCollateral(
1381
+ redeemReserveCollateral(
1300
1382
  {
1301
- liquidityAmount: this.amount,
1383
+ collateralAmount: this.amount,
1302
1384
  },
1303
1385
  {
1304
1386
  owner: this.owner,
1305
- obligation: this.getObligationPda(),
1306
1387
  lendingMarket: this.kaminoMarket.getAddress(),
1307
1388
  lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1308
1389
  reserve: this.reserve.address,
1309
1390
  reserveLiquidityMint: this.reserve.getLiquidityMint(),
1310
1391
  reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
1311
1392
  reserveCollateralMint: this.reserve.getCTokenMint(),
1312
- reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
1313
- userSourceLiquidity: this.userTokenAccountAddress,
1314
- placeholderUserDestinationCollateral: this.kaminoMarket.programId,
1393
+ userSourceCollateral: this.userCollateralAccountAddress,
1394
+ userDestinationLiquidity: this.userTokenAccountAddress,
1315
1395
  collateralTokenProgram: TOKEN_PROGRAM_ID,
1316
1396
  liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
1317
1397
  instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
@@ -1321,52 +1401,6 @@ export class KaminoAction {
1321
1401
  );
1322
1402
  }
1323
1403
 
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
1370
1404
  addDepositObligationCollateralIx() {
1371
1405
  this.lendingIxsLabels.push(`depositObligationCollateral`);
1372
1406
  this.lendingIxs.push(
@@ -1389,47 +1423,6 @@ export class KaminoAction {
1389
1423
  );
1390
1424
  }
1391
1425
 
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
1433
1426
  addBorrowIx() {
1434
1427
  this.lendingIxsLabels.push(`borrowObligationLiquidity`);
1435
1428
 
@@ -1466,220 +1459,7 @@ export class KaminoAction {
1466
1459
  this.lendingIxs.push(borrowIx);
1467
1460
  }
1468
1461
 
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() {
1462
+ addDepositAndBorrowIx() {
1683
1463
  this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
1684
1464
  this.lendingIxsLabels.push(`borrowObligationLiquidity`);
1685
1465
  this.lendingIxs.push(
@@ -1729,137 +1509,25 @@ export class KaminoAction {
1729
1509
 
1730
1510
  const borrowIx = borrowObligationLiquidity(
1731
1511
  {
1732
- liquidityAmount: this.outflowAmount,
1733
- },
1734
- {
1735
- owner: this.owner,
1736
- obligation: this.getObligationPda(),
1737
- lendingMarket: this.kaminoMarket.getAddress(),
1738
- lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1739
- borrowReserve: this.outflowReserve.address,
1740
- borrowReserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
1741
- reserveSourceLiquidity: this.outflowReserve.state.liquidity.supplyVault,
1742
- userDestinationLiquidity: this.additionalTokenAccountAddress,
1743
- borrowReserveLiquidityFeeReceiver: this.outflowReserve.state.liquidity.feeVault,
1744
- referrerTokenState: referrerTokenStatePda(
1745
- this.referrer,
1746
- this.outflowReserve.address,
1747
- this.kaminoMarket.programId
1748
- )[0],
1749
- tokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
1750
- instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1751
- },
1752
- this.kaminoMarket.programId
1753
- );
1754
-
1755
- borrowIx.keys = borrowIx.keys.concat([...depositReserveAccountMetas]);
1756
-
1757
- this.lendingIxs.push(borrowIx);
1758
- }
1759
-
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,
1512
+ liquidityAmount: this.outflowAmount,
1513
+ },
1514
+ {
1515
+ owner: this.owner,
1516
+ obligation: this.getObligationPda(),
1517
+ lendingMarket: this.kaminoMarket.getAddress(),
1518
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1519
+ borrowReserve: this.outflowReserve.address,
1520
+ borrowReserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
1521
+ reserveSourceLiquidity: this.outflowReserve.state.liquidity.supplyVault,
1522
+ userDestinationLiquidity: this.additionalTokenAccountAddress,
1523
+ borrowReserveLiquidityFeeReceiver: this.outflowReserve.state.liquidity.feeVault,
1524
+ referrerTokenState: referrerTokenStatePda(
1525
+ this.referrer,
1526
+ this.outflowReserve.address,
1527
+ this.kaminoMarket.programId
1528
+ )[0],
1529
+ tokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
1530
+ instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1863
1531
  },
1864
1532
  this.kaminoMarket.programId
1865
1533
  );
@@ -1869,7 +1537,7 @@ export class KaminoAction {
1869
1537
  this.lendingIxs.push(borrowIx);
1870
1538
  }
1871
1539
 
1872
- async addRepayAndWithdrawIxs(withdrawCollateralAmount: BN) {
1540
+ addRepayAndWithdrawIxs(withdrawCollateralAmount: BN) {
1873
1541
  this.lendingIxsLabels.push(
1874
1542
  `repayObligationLiquidity(reserve=${this.reserve!.address})(obligation=${this.getObligationPda()})`
1875
1543
  );
@@ -1939,31 +1607,61 @@ export class KaminoAction {
1939
1607
  );
1940
1608
  }
1941
1609
 
1942
- async addRepayAndWithdrawIxsV2(withdrawCollateralAmount: BN) {
1610
+ addRepayAndWithdrawV2Ixs(withdrawCollateralAmount: BN) {
1943
1611
  this.lendingIxsLabels.push(
1944
- `repayObligationLiquidityV2(reserve=${this.reserve!.address})(obligation=${this.getObligationPda()})`
1612
+ `repayAndWithdrawAndRedeem(repayReserve=${this.reserve!.address})(withdrawReserve=${
1613
+ this.outflowReserve!.address
1614
+ })(obligation=${this.getObligationPda()})`
1945
1615
  );
1946
- this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateralV2`);
1947
1616
 
1948
1617
  const depositReservesList = this.getAdditionalDepositReservesList();
1949
1618
 
1950
1619
  const depositReserveAccountMetas = depositReservesList.map((reserve) => {
1951
1620
  return { pubkey: reserve, isSigner: false, isWritable: true };
1952
1621
  });
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
+ };
1953
1650
 
1954
1651
  const debtFarmsAccounts = this.reserve.state.farmDebt.equals(PublicKey.default)
1955
1652
  ? {
1956
- obligationFarmUserState: PROGRAM_ID,
1957
- reserveFarmState: PROGRAM_ID,
1653
+ obligationFarmUserState: this.kaminoMarket.programId,
1654
+ reserveFarmState: this.kaminoMarket.programId,
1958
1655
  }
1959
1656
  : {
1960
- obligationFarmUserState: obligationFarmStatePda(this.getObligationPda(), this.reserve.state.farmDebt)[0],
1657
+ obligationFarmUserState: obligationFarmStatePda(this.reserve.state.farmDebt, this.getObligationPda()),
1961
1658
  reserveFarmState: this.reserve.state.farmDebt,
1962
1659
  };
1963
1660
 
1964
- const repayIx = repayObligationLiquidityV2(
1661
+ const repayAndWithdrawIx = repayAndWithdrawAndRedeem(
1965
1662
  {
1966
- liquidityAmount: this.amount,
1663
+ repayAmount: this.amount,
1664
+ withdrawCollateralAmount,
1967
1665
  },
1968
1666
  {
1969
1667
  repayAccounts: {
@@ -1977,16 +1675,57 @@ export class KaminoAction {
1977
1675
  tokenProgram: this.reserve.getLiquidityTokenProgram(),
1978
1676
  instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1979
1677
  },
1980
- lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1981
- farmsAccounts: debtFarmsAccounts,
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,
1982
1696
  farmsProgram: farmsId,
1983
1697
  },
1984
1698
  this.kaminoMarket.programId
1985
1699
  );
1986
1700
 
1987
- repayIx.keys = repayIx.keys.concat([...depositReserveAccountMetas]);
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
+ }
1988
1728
 
1989
- this.lendingIxs.push(repayIx);
1990
1729
  if (!this.outflowReserve) {
1991
1730
  throw new Error(`outflowReserve not set`);
1992
1731
  }
@@ -1995,54 +1734,145 @@ export class KaminoAction {
1995
1734
  throw new Error(`additionalTokenAccountAddress not set`);
1996
1735
  }
1997
1736
 
1998
- if (!this.outflowAmount) {
1999
- throw new Error(`outflowAmount not set`);
2000
- }
2001
-
2002
- const collateralFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(PublicKey.default)
1737
+ const depositFarmsAccounts = this.reserve.state.farmCollateral.equals(PublicKey.default)
2003
1738
  ? {
2004
- obligationFarmUserState: PROGRAM_ID,
2005
- reserveFarmState: PROGRAM_ID,
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)
1747
+ ? {
1748
+ obligationFarmUserState: this.kaminoMarket.programId,
1749
+ reserveFarmState: this.kaminoMarket.programId,
2006
1750
  }
2007
1751
  : {
2008
1752
  obligationFarmUserState: obligationFarmStatePda(
2009
- this.getObligationPda(),
2010
- this.outflowReserve.state.farmCollateral
2011
- )[0],
1753
+ this.outflowReserve.state.farmCollateral,
1754
+ this.getObligationPda()
1755
+ ),
2012
1756
  reserveFarmState: this.outflowReserve.state.farmCollateral,
2013
1757
  };
2014
1758
 
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`);
2015
1814
  this.lendingIxs.push(
2016
- withdrawObligationCollateralAndRedeemReserveCollateralV2(
1815
+ withdrawObligationCollateralAndRedeemReserveCollateral(
2017
1816
  {
2018
1817
  collateralAmount: withdrawCollateralAmount,
2019
1818
  },
2020
1819
  {
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,
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,
2039
1834
  },
2040
1835
  this.kaminoMarket.programId
2041
1836
  )
2042
1837
  );
2043
1838
  }
2044
1839
 
2045
- async addLiquidateIx(maxAllowedLtvOverridePercent: number = 0) {
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) {
2046
1876
  this.lendingIxsLabels.push(`liquidateObligationAndRedeemReserveCollateral`);
2047
1877
  if (!this.outflowReserve) {
2048
1878
  throw Error(`Withdraw reserve during liquidation is not defined`);
@@ -2094,97 +1924,16 @@ export class KaminoAction {
2094
1924
  this.lendingIxs.push(liquidateIx);
2095
1925
  }
2096
1926
 
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
-
2177
1927
  async addInBetweenIxs(
2178
1928
  action: ActionType,
2179
1929
  includeAtaIxns: boolean,
2180
1930
  requestElevationGroup: boolean,
2181
- addInitObligationForFarm: boolean,
2182
- useV2Ixs: boolean
1931
+ addInitObligationForFarm: boolean
2183
1932
  ) {
2184
1933
  await this.addSupportIxsWithoutInitObligation(
2185
1934
  action,
2186
1935
  includeAtaIxns,
2187
- useV2Ixs,
1936
+ false,
2188
1937
  'inBetween',
2189
1938
  requestElevationGroup,
2190
1939
  addInitObligationForFarm
@@ -2239,6 +1988,7 @@ export class KaminoAction {
2239
1988
  'repay',
2240
1989
  'depositAndBorrow',
2241
1990
  'repayAndWithdraw',
1991
+ 'repayAndWithdrawV2',
2242
1992
  'refreshObligation',
2243
1993
  ].includes(action)
2244
1994
  ) {
@@ -2257,12 +2007,17 @@ export class KaminoAction {
2257
2007
 
2258
2008
  let currentReserves: KaminoReserve[] = [];
2259
2009
 
2260
- if (action === 'liquidate' || action === 'depositAndBorrow' || action === 'repayAndWithdraw') {
2010
+ if (
2011
+ action === 'liquidate' ||
2012
+ action === 'depositAndBorrow' ||
2013
+ action === 'repayAndWithdraw' ||
2014
+ action === 'repayAndWithdrawV2'
2015
+ ) {
2261
2016
  if (!this.outflowReserve) {
2262
2017
  throw new Error('outflowReserve is undefined');
2263
2018
  }
2264
2019
 
2265
- if (action === 'depositAndBorrow' || action === 'repayAndWithdraw') {
2020
+ if (action === 'depositAndBorrow' || action === 'repayAndWithdraw' || action === 'repayAndWithdrawV2') {
2266
2021
  currentReserves = [this.reserve, this.outflowReserve];
2267
2022
  if (action === 'depositAndBorrow') {
2268
2023
  if (this.obligation) {
@@ -2307,7 +2062,12 @@ export class KaminoAction {
2307
2062
  if (this.outflowReserve) {
2308
2063
  await this.addInitObligationForFarm(this.outflowReserve, ReserveFarmKind.Debt, addAsSupportIx);
2309
2064
  }
2310
- } else if (action === 'repayAndWithdraw' || action === 'borrow' || action === 'repay') {
2065
+ } else if (
2066
+ action === 'repayAndWithdraw' ||
2067
+ action === 'borrow' ||
2068
+ action === 'repay' ||
2069
+ action === 'repayAndWithdrawV2'
2070
+ ) {
2311
2071
  // todo - probably don't need to add both debt and collateral for everything here
2312
2072
  await this.addInitObligationForFarm(this.reserve, ReserveFarmKind.Debt, addAsSupportIx);
2313
2073
  if (this.outflowReserve) {
@@ -2338,7 +2098,7 @@ export class KaminoAction {
2338
2098
  }
2339
2099
 
2340
2100
  if (requestElevationGroup) {
2341
- if (action === 'repay') {
2101
+ if (action === 'repay' || action === 'repayAndWithdrawV2') {
2342
2102
  const repayObligationLiquidity = this.obligation!.borrows.get(this.reserve.address);
2343
2103
 
2344
2104
  if (!repayObligationLiquidity) {
@@ -2527,7 +2287,7 @@ export class KaminoAction {
2527
2287
  if (action === 'deposit' && this.outflowReserve) {
2528
2288
  await this.addInitReferrerTokenStateIx(this.outflowReserve);
2529
2289
  }
2530
- await this.addInitObligationIxs();
2290
+ this.addInitObligationIxs();
2531
2291
  }
2532
2292
 
2533
2293
  await this.addSupportIxsWithoutInitObligation(
@@ -2759,7 +2519,7 @@ export class KaminoAction {
2759
2519
  farms.push([
2760
2520
  ReserveFarmKind.Collateral,
2761
2521
  kaminoReserve.state.farmCollateral,
2762
- obligationFarmStatePda(this.getObligationPda(), kaminoReserve.state.farmCollateral)[0],
2522
+ obligationFarmStatePda(kaminoReserve.state.farmCollateral, this.getObligationPda()),
2763
2523
  kaminoReserve,
2764
2524
  ]);
2765
2525
  }
@@ -2767,7 +2527,7 @@ export class KaminoAction {
2767
2527
  farms.push([
2768
2528
  ReserveFarmKind.Debt,
2769
2529
  kaminoReserve.state.farmDebt,
2770
- obligationFarmStatePda(this.getObligationPda(), kaminoReserve.state.farmDebt)[0],
2530
+ obligationFarmStatePda(kaminoReserve.state.farmDebt, this.getObligationPda()),
2771
2531
  kaminoReserve,
2772
2532
  ]);
2773
2533
  }
@@ -2851,18 +2611,18 @@ export class KaminoAction {
2851
2611
  const farms: [number, PublicKey, PublicKey][] = [];
2852
2612
 
2853
2613
  if (mode === ReserveFarmKind.Collateral && isNotNullPubkey(reserve.state.farmCollateral)) {
2854
- const userPda = obligationFarmStatePda(this.getObligationPda(), reserve.state.farmCollateral)[0];
2855
- const account = await this.kaminoMarket.getConnection().getAccountInfo(userPda);
2614
+ const pda = obligationFarmStatePda(reserve.state.farmCollateral, this.getObligationPda());
2615
+ const account = await this.kaminoMarket.getConnection().getAccountInfo(pda);
2856
2616
  if (!account) {
2857
- farms.push([ReserveFarmKind.Collateral.discriminator, reserve.state.farmCollateral, userPda]);
2617
+ farms.push([ReserveFarmKind.Collateral.discriminator, reserve.state.farmCollateral, pda]);
2858
2618
  }
2859
2619
  }
2860
2620
 
2861
2621
  if (mode === ReserveFarmKind.Debt && isNotNullPubkey(reserve.state.farmDebt)) {
2862
- const userPda = obligationFarmStatePda(this.getObligationPda(), reserve.state.farmDebt)[0];
2863
- const account = await this.kaminoMarket.getConnection().getAccountInfo(userPda);
2622
+ const pda = obligationFarmStatePda(reserve.state.farmDebt, this.getObligationPda());
2623
+ const account = await this.kaminoMarket.getConnection().getAccountInfo(pda);
2864
2624
  if (!account) {
2865
- farms.push([ReserveFarmKind.Debt.discriminator, reserve.state.farmDebt, userPda]);
2625
+ farms.push([ReserveFarmKind.Debt.discriminator, reserve.state.farmDebt, pda]);
2866
2626
  }
2867
2627
  }
2868
2628
 
@@ -2896,7 +2656,7 @@ export class KaminoAction {
2896
2656
  });
2897
2657
  }
2898
2658
 
2899
- private async addInitObligationIxs() {
2659
+ private addInitObligationIxs() {
2900
2660
  if (!this.obligation) {
2901
2661
  const obligationPda = this.getObligationPda();
2902
2662
  const [userMetadataAddress, _bump] = userMetadataPda(this.owner, this.kaminoMarket.programId);
@@ -3119,7 +2879,7 @@ export class KaminoAction {
3119
2879
 
3120
2880
  let safeRepay = new BN(this.amount);
3121
2881
 
3122
- if (this.obligation && action === 'repay' && this.amount.eq(new BN(U64_MAX))) {
2882
+ if (this.obligation && (action === 'repay' || action === 'repayAndWithdrawV2') && this.amount.eq(new BN(U64_MAX))) {
3123
2883
  const borrow = this.obligation.state.borrows.find(
3124
2884
  (borrow) => borrow.borrowReserve.toString() === this.reserve.address.toString()
3125
2885
  );
@@ -3133,7 +2893,7 @@ export class KaminoAction {
3133
2893
  this.currentSlot,
3134
2894
  this.kaminoMarket.state.referralFeeBps
3135
2895
  );
3136
- // TODO: shouldn't this calc be added to all other stuff as well?
2896
+
3137
2897
  safeRepay = new BN(
3138
2898
  Math.floor(
3139
2899
  KaminoObligation.getBorrowAmount(borrow)
@@ -3161,6 +2921,7 @@ export class KaminoAction {
3161
2921
  const sendAction =
3162
2922
  action === 'deposit' ||
3163
2923
  action === 'repay' ||
2924
+ action === 'repayAndWithdrawV2' ||
3164
2925
  action === 'mint' ||
3165
2926
  (action === 'liquidate' && this.secondaryMint?.equals(NATIVE_MINT)); // only sync WSOL amount if liquidator repays SOL which is secondaryMint
3166
2927
 
@@ -3270,7 +3031,7 @@ export class KaminoAction {
3270
3031
  additionalUserTokenAccountAddress = userOutflowTokenAccountAddress;
3271
3032
  primaryMint = inflowTokenMint;
3272
3033
  secondaryMint = outflowTokenMint;
3273
- } else if (action === 'repayAndWithdraw') {
3034
+ } else if (action === 'repayAndWithdraw' || action === 'repayAndWithdrawV2') {
3274
3035
  primaryMint = inflowTokenMint;
3275
3036
  secondaryMint = outflowTokenMint;
3276
3037
  userTokenAccountAddress = userInflowTokenAccountAddress;