@kamino-finance/klend-sdk 5.13.1 → 5.13.4

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 (116) hide show
  1. package/dist/classes/action.d.ts +32 -31
  2. package/dist/classes/action.d.ts.map +1 -1
  3. package/dist/classes/action.js +126 -95
  4. package/dist/classes/action.js.map +1 -1
  5. package/dist/classes/index.d.ts +3 -2
  6. package/dist/classes/index.d.ts.map +1 -1
  7. package/dist/classes/index.js +3 -2
  8. package/dist/classes/index.js.map +1 -1
  9. package/dist/classes/manager.d.ts +15 -7
  10. package/dist/classes/manager.d.ts.map +1 -1
  11. package/dist/classes/manager.js +57 -46
  12. package/dist/classes/manager.js.map +1 -1
  13. package/dist/classes/obligationOrder.d.ts +1 -1
  14. package/dist/classes/obligationOrder.d.ts.map +1 -1
  15. package/dist/classes/reserve.d.ts +2 -2
  16. package/dist/classes/reserve.d.ts.map +1 -1
  17. package/dist/classes/reserve.js +70 -70
  18. package/dist/classes/reserve.js.map +1 -1
  19. package/dist/classes/shared.d.ts +13 -0
  20. package/dist/classes/shared.d.ts.map +1 -1
  21. package/dist/classes/utils.d.ts +1 -9
  22. package/dist/classes/utils.d.ts.map +1 -1
  23. package/dist/classes/utils.js +4 -51
  24. package/dist/classes/utils.js.map +1 -1
  25. package/dist/classes/vault.d.ts +22 -4
  26. package/dist/classes/vault.d.ts.map +1 -1
  27. package/dist/classes/vault.js +78 -43
  28. package/dist/classes/vault.js.map +1 -1
  29. package/dist/classes/{types.d.ts → vault_types.d.ts} +3 -15
  30. package/dist/classes/vault_types.d.ts.map +1 -0
  31. package/dist/classes/{types.js → vault_types.js} +1 -1
  32. package/dist/classes/vault_types.js.map +1 -0
  33. package/dist/client_kamino_manager.d.ts.map +1 -1
  34. package/dist/client_kamino_manager.js +44 -28
  35. package/dist/client_kamino_manager.js.map +1 -1
  36. package/dist/lending_operations/repay_with_collateral_operations.js +6 -6
  37. package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
  38. package/dist/lending_operations/swap_collateral_operations.d.ts +6 -6
  39. package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
  40. package/dist/lending_operations/swap_collateral_operations.js +61 -61
  41. package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
  42. package/dist/leverage/calcs.d.ts +0 -1
  43. package/dist/leverage/calcs.d.ts.map +1 -1
  44. package/dist/leverage/calcs.js +5 -8
  45. package/dist/leverage/calcs.js.map +1 -1
  46. package/dist/leverage/operations.d.ts +5 -5
  47. package/dist/leverage/operations.d.ts.map +1 -1
  48. package/dist/leverage/operations.js +73 -73
  49. package/dist/leverage/operations.js.map +1 -1
  50. package/dist/leverage/types.d.ts +1 -1
  51. package/dist/leverage/types.d.ts.map +1 -1
  52. package/dist/leverage/utils.d.ts +2 -2
  53. package/dist/leverage/utils.d.ts.map +1 -1
  54. package/dist/leverage/utils.js +5 -5
  55. package/dist/leverage/utils.js.map +1 -1
  56. package/dist/referrals/instructions.d.ts +3 -3
  57. package/dist/referrals/instructions.d.ts.map +1 -1
  58. package/dist/referrals/instructions.js +10 -10
  59. package/dist/referrals/instructions.js.map +1 -1
  60. package/dist/referrals/operations.js +6 -6
  61. package/dist/referrals/operations.js.map +1 -1
  62. package/dist/utils/ata.d.ts +3 -3
  63. package/dist/utils/ata.d.ts.map +1 -1
  64. package/dist/utils/ata.js +22 -22
  65. package/dist/utils/ata.js.map +1 -1
  66. package/dist/utils/instruction.d.ts +2 -2
  67. package/dist/utils/instruction.d.ts.map +1 -1
  68. package/dist/utils/instruction.js +12 -12
  69. package/dist/utils/instruction.js.map +1 -1
  70. package/dist/utils/lookupTable.js +6 -6
  71. package/dist/utils/lookupTable.js.map +1 -1
  72. package/dist/utils/metadata.d.ts +14 -0
  73. package/dist/utils/metadata.d.ts.map +1 -0
  74. package/dist/utils/metadata.js +78 -0
  75. package/dist/utils/metadata.js.map +1 -0
  76. package/dist/utils/seeds.d.ts +6 -0
  77. package/dist/utils/seeds.d.ts.map +1 -1
  78. package/dist/utils/seeds.js +10 -0
  79. package/dist/utils/seeds.js.map +1 -1
  80. package/dist/utils/userMetadata.d.ts +1 -1
  81. package/dist/utils/userMetadata.d.ts.map +1 -1
  82. package/dist/utils/userMetadata.js +3 -3
  83. package/dist/utils/userMetadata.js.map +1 -1
  84. package/package.json +1 -1
  85. package/src/classes/action.ts +143 -102
  86. package/src/classes/index.ts +5 -2
  87. package/src/classes/manager.ts +74 -51
  88. package/src/classes/obligationOrder.ts +1 -1
  89. package/src/classes/reserve.ts +126 -132
  90. package/src/classes/shared.ts +15 -0
  91. package/src/classes/utils.ts +3 -52
  92. package/src/classes/vault.ts +125 -44
  93. package/src/classes/{types.ts → vault_types.ts} +2 -16
  94. package/src/client.ts +16 -16
  95. package/src/client_kamino_manager.ts +59 -27
  96. package/src/lending_operations/repay_with_collateral_operations.ts +13 -13
  97. package/src/lending_operations/swap_collateral_operations.ts +85 -85
  98. package/src/leverage/calcs.ts +2 -6
  99. package/src/leverage/operations.ts +84 -84
  100. package/src/leverage/types.ts +1 -1
  101. package/src/leverage/utils.ts +5 -5
  102. package/src/referrals/instructions.ts +6 -6
  103. package/src/referrals/operations.ts +9 -9
  104. package/src/utils/ata.ts +18 -18
  105. package/src/utils/instruction.ts +10 -10
  106. package/src/utils/lookupTable.ts +6 -6
  107. package/src/utils/metadata.ts +115 -0
  108. package/src/utils/seeds.ts +13 -0
  109. package/src/utils/userMetadata.ts +1 -1
  110. package/dist/classes/types.d.ts.map +0 -1
  111. package/dist/classes/types.js.map +0 -1
  112. package/dist/classes/types_utils.d.ts +0 -14
  113. package/dist/classes/types_utils.d.ts.map +0 -1
  114. package/dist/classes/types_utils.js +0 -50
  115. package/dist/classes/types_utils.js.map +0 -1
  116. package/src/classes/types_utils.ts +0 -49
@@ -70,7 +70,7 @@ import {
70
70
  obligationFarmStatePda,
71
71
  } from '../utils';
72
72
  import { getTokenIdsForScopeRefresh, KaminoMarket } from './market';
73
- import { KaminoObligation } from './obligation';
73
+ import { isKaminoObligation, KaminoObligation } from './obligation';
74
74
  import { KaminoReserve } from './reserve';
75
75
  import { ReserveFarmKind } from '../idl_codegen/types';
76
76
  import { farmsId } from '@kamino-finance/farms-sdk';
@@ -109,7 +109,7 @@ export class KaminoAction {
109
109
  owner: PublicKey;
110
110
  payer: PublicKey;
111
111
 
112
- obligation: KaminoObligation | null = null;
112
+ obligation: KaminoObligation | ObligationType;
113
113
 
114
114
  referrer: PublicKey;
115
115
 
@@ -155,7 +155,7 @@ export class KaminoAction {
155
155
  private constructor(
156
156
  kaminoMarket: KaminoMarket,
157
157
  owner: PublicKey,
158
- obligation: KaminoObligation | ObligationType | null,
158
+ obligation: KaminoObligation | ObligationType,
159
159
  mint: PublicKey,
160
160
  positions: number,
161
161
  amount: string | BN,
@@ -169,13 +169,8 @@ export class KaminoAction {
169
169
  referrer?: PublicKey,
170
170
  payer?: PublicKey
171
171
  ) {
172
- if (obligation instanceof KaminoObligation) {
173
- this.obligation = obligation;
174
- } else if (obligation !== null) {
175
- this.obligationType = obligation;
176
- }
177
-
178
172
  this.kaminoMarket = kaminoMarket;
173
+ this.obligation = obligation;
179
174
  this.owner = owner;
180
175
  this.payer = payer ?? owner;
181
176
  this.amount = new BN(amount);
@@ -314,7 +309,7 @@ export class KaminoAction {
314
309
  kaminoMarket: KaminoMarket,
315
310
  payer: PublicKey,
316
311
  obligation: KaminoObligation,
317
- extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
312
+ extraComputeBudget: number = 1_000_000, // if > 0 then adds the ix
318
313
  currentSlot: number = 0
319
314
  ) {
320
315
  // placeholder for action initialization
@@ -348,7 +343,7 @@ export class KaminoAction {
348
343
  payer: PublicKey,
349
344
  obligation: KaminoObligation,
350
345
  elevationGroup: number,
351
- extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
346
+ extraComputeBudget: number = 1_000_000, // if > 0 then adds the ix
352
347
  currentSlot: number = 0
353
348
  ) {
354
349
  const firstReserve = obligation.state.deposits.find(
@@ -387,8 +382,8 @@ export class KaminoAction {
387
382
  obligation: KaminoObligation | ObligationType,
388
383
  useV2Ixs: boolean,
389
384
  scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
390
- extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
391
- includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
385
+ extraComputeBudget: number = 1_000_000, // if > 0 then adds the ix
386
+ includeAtaIxs: boolean = true, // if true it includes create and close wsol and token atas,
392
387
  requestElevationGroup: boolean = false, // to be requested *before* the deposit
393
388
  initUserMetadata: { skipInitialization: boolean; skipLutCreation: boolean } = {
394
389
  skipInitialization: false,
@@ -416,7 +411,7 @@ export class KaminoAction {
416
411
 
417
412
  await axn.addSupportIxs(
418
413
  'deposit',
419
- includeAtaIxns,
414
+ includeAtaIxs,
420
415
  requestElevationGroup,
421
416
  addInitObligationForFarm,
422
417
  useV2Ixs,
@@ -455,8 +450,8 @@ export class KaminoAction {
455
450
  obligation: KaminoObligation | ObligationType,
456
451
  useV2Ixs: boolean,
457
452
  scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
458
- extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
459
- includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
453
+ extraComputeBudget: number = 1_000_000, // if > 0 then adds the ix
454
+ includeAtaIxs: boolean = true, // if true it includes create and close wsol and token atas,
460
455
  requestElevationGroup: boolean = false,
461
456
  initUserMetadata: { skipInitialization: boolean; skipLutCreation: boolean } = {
462
457
  skipInitialization: false,
@@ -495,7 +490,7 @@ export class KaminoAction {
495
490
 
496
491
  await axn.addSupportIxs(
497
492
  'borrow',
498
- includeAtaIxns,
493
+ includeAtaIxs,
499
494
  requestElevationGroup,
500
495
  addInitObligationForFarm,
501
496
  useV2Ixs,
@@ -521,8 +516,8 @@ export class KaminoAction {
521
516
  owner: PublicKey,
522
517
  obligation: KaminoObligation | ObligationType,
523
518
  scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
524
- extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
525
- includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas
519
+ extraComputeBudget: number = 1_000_000, // if > 0 then adds the ix
520
+ includeAtaIxs: boolean = true, // if true it includes create and close wsol and token atas
526
521
  requestElevationGroup: boolean = false,
527
522
  referrer: PublicKey = PublicKey.default,
528
523
  currentSlot: number = 0
@@ -545,7 +540,7 @@ export class KaminoAction {
545
540
 
546
541
  await axn.addSupportIxs(
547
542
  'mint',
548
- includeAtaIxns,
543
+ includeAtaIxs,
549
544
  requestElevationGroup,
550
545
  false,
551
546
  addInitObligationForFarm,
@@ -564,8 +559,8 @@ export class KaminoAction {
564
559
  owner: PublicKey,
565
560
  obligation: KaminoObligation | ObligationType,
566
561
  scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
567
- extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
568
- includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas
562
+ extraComputeBudget: number = 1_000_000, // if > 0 then adds the ix
563
+ includeAtaIxs: boolean = true, // if true it includes create and close wsol and token atas
569
564
  requestElevationGroup: boolean = false,
570
565
  referrer: PublicKey = PublicKey.default,
571
566
  currentSlot: number = 0
@@ -588,7 +583,7 @@ export class KaminoAction {
588
583
 
589
584
  await axn.addSupportIxs(
590
585
  'redeem',
591
- includeAtaIxns,
586
+ includeAtaIxs,
592
587
  requestElevationGroup,
593
588
  false,
594
589
  addInitObligationForFarm,
@@ -608,8 +603,8 @@ export class KaminoAction {
608
603
  obligation: KaminoObligation | ObligationType,
609
604
  useV2Ixs: boolean,
610
605
  scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
611
- extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
612
- includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas
606
+ extraComputeBudget: number = 1_000_000, // if > 0 then adds the ix
607
+ includeAtaIxs: boolean = true, // if true it includes create and close wsol and token atas
613
608
  requestElevationGroup: boolean = false,
614
609
  initUserMetadata: { skipInitialization: boolean; skipLutCreation: boolean } = {
615
610
  skipInitialization: false,
@@ -636,7 +631,7 @@ export class KaminoAction {
636
631
 
637
632
  await axn.addSupportIxs(
638
633
  'depositCollateral',
639
- includeAtaIxns,
634
+ includeAtaIxs,
640
635
  requestElevationGroup,
641
636
  addInitObligationForFarm,
642
637
  useV2Ixs,
@@ -662,8 +657,8 @@ export class KaminoAction {
662
657
  obligation: KaminoObligation | ObligationType,
663
658
  useV2Ixs: boolean,
664
659
  scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
665
- extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
666
- includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
660
+ extraComputeBudget: number = 1_000_000, // if > 0 then adds the ix
661
+ includeAtaIxs: boolean = true, // if true it includes create and close wsol and token atas,
667
662
  requestElevationGroup: boolean = false,
668
663
  initUserMetadata: { skipInitialization: boolean; skipLutCreation: boolean } = {
669
664
  skipInitialization: false,
@@ -706,7 +701,7 @@ export class KaminoAction {
706
701
  }
707
702
  await axn.addSupportIxs(
708
703
  'deposit',
709
- includeAtaIxns,
704
+ includeAtaIxs,
710
705
  requestElevationGroup,
711
706
  addInitObligationForFarmForDeposit,
712
707
  useV2Ixs,
@@ -722,14 +717,14 @@ export class KaminoAction {
722
717
  }
723
718
  await axn.addInBetweenIxs(
724
719
  'depositAndBorrow',
725
- includeAtaIxns,
720
+ includeAtaIxs,
726
721
  requestElevationGroup,
727
722
  addInitObligationForFarmForBorrow,
728
723
  useV2Ixs
729
724
  );
730
725
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
731
726
 
732
- // Create the scope refresh ixn in here to ensure it's the first ixn in the txn
727
+ // Create the scope refresh ix in here to ensure it's the first ix in the txn
733
728
  const allReserves = new PublicKeySet<PublicKey>([
734
729
  ...axn.depositReserves,
735
730
  ...axn.borrowReserves,
@@ -755,8 +750,8 @@ export class KaminoAction {
755
750
  currentSlot: number,
756
751
  obligation: KaminoObligation | ObligationType,
757
752
  scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
758
- extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
759
- includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
753
+ extraComputeBudget: number = 1_000_000, // if > 0 then adds the ix
754
+ includeAtaIxs: boolean = true, // if true it includes create and close wsol and token atas,
760
755
  requestElevationGroup: boolean = false,
761
756
  initUserMetadata: { skipInitialization: boolean; skipLutCreation: boolean } = {
762
757
  skipInitialization: false,
@@ -785,7 +780,7 @@ export class KaminoAction {
785
780
 
786
781
  await axn.addSupportIxs(
787
782
  'depositAndWithdraw',
788
- includeAtaIxns,
783
+ includeAtaIxs,
789
784
  requestElevationGroup,
790
785
  addInitObligationForFarm,
791
786
  true,
@@ -809,8 +804,8 @@ export class KaminoAction {
809
804
  currentSlot: number,
810
805
  obligation: KaminoObligation | ObligationType,
811
806
  scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
812
- extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
813
- includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
807
+ extraComputeBudget: number = 1_000_000, // if > 0 then adds the ix
808
+ includeAtaIxs: boolean = true, // if true it includes create and close wsol and token atas,
814
809
  requestElevationGroup: boolean = false,
815
810
  initUserMetadata: { skipInitialization: boolean; skipLutCreation: boolean } = {
816
811
  skipInitialization: false,
@@ -839,7 +834,7 @@ export class KaminoAction {
839
834
 
840
835
  await axn.addSupportIxs(
841
836
  'repayAndWithdrawV2',
842
- includeAtaIxns,
837
+ includeAtaIxs,
843
838
  requestElevationGroup,
844
839
  addInitObligationForFarm,
845
840
  true,
@@ -864,8 +859,8 @@ export class KaminoAction {
864
859
  obligation: KaminoObligation | ObligationType,
865
860
  useV2Ixs: boolean,
866
861
  scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
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,
862
+ extraComputeBudget: number = 1_000_000, // if > 0 then adds the ix
863
+ includeAtaIxs: boolean = true, // if true it includes create and close wsol and token atas,
869
864
  requestElevationGroup: boolean = false,
870
865
  initUserMetadata: { skipInitialization: boolean; skipLutCreation: boolean } = {
871
866
  skipInitialization: false,
@@ -895,7 +890,7 @@ export class KaminoAction {
895
890
 
896
891
  await axn.addSupportIxs(
897
892
  'repay',
898
- includeAtaIxns,
893
+ includeAtaIxs,
899
894
  requestElevationGroup,
900
895
  addInitObligationForFarmForRepay,
901
896
  useV2Ixs,
@@ -913,13 +908,13 @@ export class KaminoAction {
913
908
 
914
909
  await axn.addInBetweenIxs(
915
910
  'repayAndWithdraw',
916
- includeAtaIxns,
911
+ includeAtaIxs,
917
912
  requestElevationGroup,
918
913
  addInitObligationForFarmForWithdraw,
919
914
  useV2Ixs
920
915
  );
921
916
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
922
- // Create the scope refresh ixn in here to ensure it's the first ixn in the txn
917
+ // Create the scope refresh ix in here to ensure it's the first ix in the txn
923
918
  const allReserves = new PublicKeySet<PublicKey>([
924
919
  ...axn.depositReserves,
925
920
  ...axn.borrowReserves,
@@ -943,8 +938,8 @@ export class KaminoAction {
943
938
  obligation: KaminoObligation | ObligationType,
944
939
  useV2Ixs: boolean,
945
940
  scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
946
- extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
947
- includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
941
+ extraComputeBudget: number = 1_000_000, // if > 0 then adds the ix
942
+ includeAtaIxs: boolean = true, // if true it includes create and close wsol and token atas,
948
943
  requestElevationGroup: boolean = false, // to be requested *after* the withdraw
949
944
  initUserMetadata: { skipInitialization: boolean; skipLutCreation: boolean } = {
950
945
  skipInitialization: false,
@@ -953,7 +948,7 @@ export class KaminoAction {
953
948
  referrer: PublicKey = PublicKey.default,
954
949
  currentSlot: number = 0,
955
950
  overrideElevationGroupRequest?: number,
956
- // Optional customizations which may be needed if the obligation was mutated by some previous ixn.
951
+ // Optional customizations which may be needed if the obligation was mutated by some previous ix.
957
952
  obligationCustomizations?: {
958
953
  // Any newly-added deposit reserves.
959
954
  addedDepositReserves?: PublicKey[];
@@ -979,7 +974,7 @@ export class KaminoAction {
979
974
 
980
975
  await axn.addSupportIxs(
981
976
  'withdraw',
982
- includeAtaIxns,
977
+ includeAtaIxs,
983
978
  requestElevationGroup,
984
979
  addInitObligationForFarm,
985
980
  useV2Ixs,
@@ -1010,8 +1005,8 @@ export class KaminoAction {
1010
1005
  * @param obligation - obligation to repay or the PDA seeds
1011
1006
  * @param currentSlot
1012
1007
  * @param payer - if not set then owner is used
1013
- * @param extraComputeBudget - if > 0 then adds the ixn
1014
- * @param includeAtaIxns - if true it includes create and close wsol and token atas
1008
+ * @param extraComputeBudget - if > 0 then adds the ix
1009
+ * @param includeAtaIxs - if true it includes create and close wsol and token atas
1015
1010
  * @param requestElevationGroup
1016
1011
  * @param includeUserMetadata - if true it includes user metadata
1017
1012
  * @param referrer
@@ -1027,7 +1022,7 @@ export class KaminoAction {
1027
1022
  currentSlot: number,
1028
1023
  payer: PublicKey | undefined = undefined,
1029
1024
  extraComputeBudget: number = 1_000_000,
1030
- includeAtaIxns: boolean = true,
1025
+ includeAtaIxs: boolean = true,
1031
1026
  requestElevationGroup: boolean = false,
1032
1027
  initUserMetadata: { skipInitialization: boolean; skipLutCreation: boolean } = {
1033
1028
  skipInitialization: false,
@@ -1054,7 +1049,7 @@ export class KaminoAction {
1054
1049
 
1055
1050
  await axn.addSupportIxs(
1056
1051
  'repay',
1057
- includeAtaIxns,
1052
+ includeAtaIxs,
1058
1053
  requestElevationGroup,
1059
1054
  addInitObligationForFarm,
1060
1055
  useV2Ixs,
@@ -1082,8 +1077,8 @@ export class KaminoAction {
1082
1077
  obligation: KaminoObligation | ObligationType,
1083
1078
  useV2Ixs: boolean,
1084
1079
  scopeRefreshConfig: ScopePriceRefreshConfig | undefined = undefined,
1085
- extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
1086
- 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
1080
+ extraComputeBudget: number = 1_000_000, // if > 0 then adds the ix
1081
+ includeAtaIxs: boolean = true, // if true it includes create and close wsol and token atas, and creates all other token atas if they don't exist
1087
1082
  requestElevationGroup: boolean = false,
1088
1083
  initUserMetadata: { skipInitialization: boolean; skipLutCreation: boolean } = {
1089
1084
  skipInitialization: false,
@@ -1114,7 +1109,7 @@ export class KaminoAction {
1114
1109
 
1115
1110
  await axn.addSupportIxs(
1116
1111
  'liquidate',
1117
- includeAtaIxns,
1112
+ includeAtaIxs,
1118
1113
  requestElevationGroup,
1119
1114
  addInitObligationForFarm,
1120
1115
  useV2Ixs,
@@ -1471,7 +1466,8 @@ export class KaminoAction {
1471
1466
  this.kaminoMarket.programId
1472
1467
  );
1473
1468
  borrowIx.keys =
1474
- this.obligation!.state.elevationGroup > 0 || this.obligation!.refreshedStats.potentialElevationGroupUpdate > 0
1469
+ isKaminoObligation(this.obligation) &&
1470
+ (this.obligation.state.elevationGroup > 0 || this.obligation.refreshedStats.potentialElevationGroupUpdate > 0)
1475
1471
  ? borrowIx.keys.concat([...depositReserveAccountMetas])
1476
1472
  : borrowIx.keys;
1477
1473
  this.lendingIxs.push(borrowIx);
@@ -1525,7 +1521,8 @@ export class KaminoAction {
1525
1521
  this.kaminoMarket.programId
1526
1522
  );
1527
1523
  borrowIx.keys =
1528
- this.obligation!.state.elevationGroup > 0 || this.obligation!.refreshedStats.potentialElevationGroupUpdate > 0
1524
+ isKaminoObligation(this.obligation) &&
1525
+ (this.obligation.state.elevationGroup > 0 || this.obligation.refreshedStats.potentialElevationGroupUpdate > 0)
1529
1526
  ? borrowIx.keys.concat([...depositReserveAccountMetas])
1530
1527
  : borrowIx.keys;
1531
1528
  this.lendingIxs.push(borrowIx);
@@ -1633,7 +1630,9 @@ export class KaminoAction {
1633
1630
  );
1634
1631
 
1635
1632
  repayIx.keys =
1636
- this.obligation!.state.elevationGroup > 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
1633
+ isKaminoObligation(this.obligation) && this.obligation.state.elevationGroup > 0
1634
+ ? repayIx.keys.concat([...depositReserveAccountMetas])
1635
+ : repayIx.keys;
1637
1636
 
1638
1637
  this.lendingIxs.push(repayIx);
1639
1638
  }
@@ -1682,7 +1681,10 @@ export class KaminoAction {
1682
1681
  );
1683
1682
 
1684
1683
  repayIx.keys =
1685
- this.obligation!.state.elevationGroup > 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
1684
+ // TODO: potential elev group update?
1685
+ isKaminoObligation(this.obligation) && this.obligation.state.elevationGroup > 0
1686
+ ? repayIx.keys.concat([...depositReserveAccountMetas])
1687
+ : repayIx.keys;
1686
1688
 
1687
1689
  this.lendingIxs.push(repayIx);
1688
1690
  }
@@ -2129,6 +2131,10 @@ export class KaminoAction {
2129
2131
  );
2130
2132
  this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateralV2`);
2131
2133
 
2134
+ if (!isKaminoObligation(this.obligation)) {
2135
+ throw new Error(`obligation is not a KaminoObligation`);
2136
+ }
2137
+
2132
2138
  const depositReservesList = this.getAdditionalDepositReservesList();
2133
2139
 
2134
2140
  const depositReserveAccountMetas = depositReservesList.map((reserve) => {
@@ -2168,7 +2174,8 @@ export class KaminoAction {
2168
2174
  this.kaminoMarket.programId
2169
2175
  );
2170
2176
 
2171
- repayIx.keys = repayIx.keys.concat([...depositReserveAccountMetas]);
2177
+ repayIx.keys =
2178
+ this.obligation.state.elevationGroup > 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
2172
2179
 
2173
2180
  this.lendingIxs.push(repayIx);
2174
2181
  if (!this.outflowReserve) {
@@ -2228,6 +2235,10 @@ export class KaminoAction {
2228
2235
  throw Error(`Withdraw reserve during liquidation is not defined`);
2229
2236
  }
2230
2237
 
2238
+ if (!isKaminoObligation(this.obligation)) {
2239
+ throw new Error(`obligation is not a KaminoObligation`);
2240
+ }
2241
+
2231
2242
  const depositReservesList = this.getAdditionalDepositReservesList();
2232
2243
  const depositReserveAccountMetas = depositReservesList.map((reserve) => {
2233
2244
  return { pubkey: reserve, isSigner: false, isWritable: true };
@@ -2265,7 +2276,7 @@ export class KaminoAction {
2265
2276
  this.kaminoMarket.programId
2266
2277
  );
2267
2278
  liquidateIx.keys =
2268
- this.obligation!.state.elevationGroup > 0
2279
+ this.obligation.state.elevationGroup > 0
2269
2280
  ? liquidateIx.keys.concat([...depositReserveAccountMetas])
2270
2281
  : liquidateIx.keys;
2271
2282
  this.lendingIxs.push(liquidateIx);
@@ -2277,6 +2288,10 @@ export class KaminoAction {
2277
2288
  throw Error(`Withdraw reserve during liquidation is not defined`);
2278
2289
  }
2279
2290
 
2291
+ if (!isKaminoObligation(this.obligation)) {
2292
+ throw new Error(`obligation is not a KaminoObligation`);
2293
+ }
2294
+
2280
2295
  const depositReservesList = this.getAdditionalDepositReservesList();
2281
2296
  const depositReserveAccountMetas = depositReservesList.map((reserve) => {
2282
2297
  return { pubkey: reserve, isSigner: false, isWritable: true };
@@ -2350,14 +2365,14 @@ export class KaminoAction {
2350
2365
 
2351
2366
  async addInBetweenIxs(
2352
2367
  action: ActionType,
2353
- includeAtaIxns: boolean,
2368
+ includeAtaIxs: boolean,
2354
2369
  requestElevationGroup: boolean,
2355
2370
  addInitObligationForFarm: boolean,
2356
2371
  useV2Ixs: boolean
2357
2372
  ) {
2358
2373
  await this.addSupportIxsWithoutInitObligation(
2359
2374
  action,
2360
- includeAtaIxns,
2375
+ includeAtaIxs,
2361
2376
  useV2Ixs,
2362
2377
  'inBetween',
2363
2378
  requestElevationGroup,
@@ -2368,29 +2383,29 @@ export class KaminoAction {
2368
2383
  addRefreshObligation(crank: PublicKey) {
2369
2384
  const uniqueReserveAddresses = new PublicKeySet(this.depositReserves.concat(this.borrowReserves)).toArray();
2370
2385
 
2371
- const addAllToSetupIxns = 'setup';
2386
+ const addAllToSetupIxs = 'setup';
2372
2387
  // Union of addresses
2373
2388
  const allReservesExcludingCurrent = [...uniqueReserveAddresses];
2374
2389
 
2375
- this.addRefreshReserveIxs(allReservesExcludingCurrent, addAllToSetupIxns);
2390
+ this.addRefreshReserveIxs(allReservesExcludingCurrent, addAllToSetupIxs);
2376
2391
  this.addRefreshFarmsForReserve(
2377
2392
  this.depositReserves.map((r) => this.kaminoMarket.getReserveByAddress(r)!),
2378
- addAllToSetupIxns,
2393
+ addAllToSetupIxs,
2379
2394
  ReserveFarmKind.Collateral,
2380
2395
  crank
2381
2396
  );
2382
2397
  this.addRefreshFarmsForReserve(
2383
2398
  this.borrowReserves.map((r) => this.kaminoMarket.getReserveByAddress(r)!),
2384
- addAllToSetupIxns,
2399
+ addAllToSetupIxs,
2385
2400
  ReserveFarmKind.Debt,
2386
2401
  crank
2387
2402
  );
2388
- this.addRefreshObligationIx(addAllToSetupIxns);
2403
+ this.addRefreshObligationIx(addAllToSetupIxs);
2389
2404
  }
2390
2405
 
2391
2406
  async addSupportIxsWithoutInitObligation(
2392
2407
  action: ActionType,
2393
- includeAtaIxns: boolean,
2408
+ includeAtaIxs: boolean,
2394
2409
  useV2Ixs: boolean,
2395
2410
  addAsSupportIx: AuxiliaryIx = 'setup',
2396
2411
  requestElevationGroup: boolean = false,
@@ -2399,7 +2414,7 @@ export class KaminoAction {
2399
2414
  overrideElevationGroupRequest?: number
2400
2415
  ) {
2401
2416
  // TODO: why are we not doing this first?
2402
- if (includeAtaIxns) {
2417
+ if (includeAtaIxs) {
2403
2418
  await this.addAtaIxs(action);
2404
2419
  }
2405
2420
 
@@ -2418,18 +2433,18 @@ export class KaminoAction {
2418
2433
  'depositAndWithdraw',
2419
2434
  ].includes(action)
2420
2435
  ) {
2421
- // The support ixns in order are:
2422
- // 0. Init obligation ixn
2423
- // 0. Token Ata ixns
2436
+ // The support ixs in order are:
2437
+ // 0. Init obligation ix
2438
+ // 0. Token Ata ixs
2424
2439
  // 0. Init obligation for farm
2425
- // 1. Ixns to refresh the reserves of the obligation not related to the current action
2426
- // 2. Ixn to refresh the reserve of the current action
2427
- // 3. Ixn to refresh the obligation
2428
- // 4. Ixn to refresh the `debt` farm of the obligation
2429
- // 5. Ixn to refresh the `collateral` farm of the obligation
2440
+ // 1. Ixs to refresh the reserves of the obligation not related to the current action
2441
+ // 2. Ix to refresh the reserve of the current action
2442
+ // 3. Ix to refresh the obligation
2443
+ // 4. Ix to refresh the `debt` farm of the obligation
2444
+ // 5. Ix to refresh the `collateral` farm of the obligation
2430
2445
  // 6. The instruction itself
2431
- // 7. Ixn to refresh the `debt` farm of the obligation
2432
- // 8. Ixn to refresh the `collateral` farm of the obligation
2446
+ // 7. Ix to refresh the `debt` farm of the obligation
2447
+ // 8. Ix to refresh the `collateral` farm of the obligation
2433
2448
 
2434
2449
  let currentReserves: KaminoReserve[] = [];
2435
2450
 
@@ -2446,7 +2461,7 @@ export class KaminoAction {
2446
2461
  if (action === 'depositAndBorrow' || action === 'repayAndWithdraw' || action === 'repayAndWithdrawV2') {
2447
2462
  currentReserves = [this.reserve, this.outflowReserve];
2448
2463
  if (action === 'depositAndBorrow') {
2449
- if (this.obligation) {
2464
+ if (isKaminoObligation(this.obligation)) {
2450
2465
  const deposit = this.obligation.getDepositByReserve(this.reserve.address);
2451
2466
  if (!deposit) {
2452
2467
  this.preLoadedDepositReservesSameTx.push(this.reserve.address);
@@ -2512,7 +2527,10 @@ export class KaminoAction {
2512
2527
  this.addRefreshReserveIxs(currentReserveAddresses.toArray(), addAsSupportIx);
2513
2528
 
2514
2529
  if (action === 'repayAndWithdraw' && addAsSupportIx === 'inBetween') {
2515
- const repayObligationLiquidity = this.obligation!.getBorrowByReserve(this.reserve.address);
2530
+ if (!isKaminoObligation(this.obligation)) {
2531
+ throw new Error(`obligation is not a KaminoObligation`);
2532
+ }
2533
+ const repayObligationLiquidity = this.obligation.getBorrowByReserve(this.reserve.address);
2516
2534
  if (!repayObligationLiquidity) {
2517
2535
  throw new Error(`Could not find debt reserve ${this.reserve.address} in obligation`);
2518
2536
  }
@@ -2526,7 +2544,10 @@ export class KaminoAction {
2526
2544
 
2527
2545
  if (requestElevationGroup) {
2528
2546
  if (action === 'repay' || action === 'repayAndWithdrawV2') {
2529
- const repayObligationLiquidity = this.obligation!.borrows.get(this.reserve.address);
2547
+ if (!isKaminoObligation(this.obligation)) {
2548
+ throw new Error(`obligation is not a KaminoObligation`);
2549
+ }
2550
+ const repayObligationLiquidity = this.obligation.getBorrowByReserve(this.reserve.address);
2530
2551
 
2531
2552
  if (!repayObligationLiquidity) {
2532
2553
  throw new Error(`Could not find debt reserve ${this.reserve.address} in obligation`);
@@ -2534,8 +2555,8 @@ export class KaminoAction {
2534
2555
 
2535
2556
  if (
2536
2557
  repayObligationLiquidity.amount.lte(new Decimal(this.amount.toString())) &&
2537
- this.obligation!.borrows.size === 1 &&
2538
- this.obligation?.state.elevationGroup !== 0
2558
+ this.obligation.borrows.size === 1 &&
2559
+ this.obligation.state.elevationGroup !== 0
2539
2560
  ) {
2540
2561
  this.addRefreshReserveIxs(allReservesExcludingCurrent, 'cleanup');
2541
2562
  // Skip the borrow reserve, since we repay in the same tx
@@ -2558,7 +2579,10 @@ export class KaminoAction {
2558
2579
  debtReserve = this.outflowReserve!.address;
2559
2580
  addAsSupportIx = 'inBetween';
2560
2581
  } else if (action === 'borrow') {
2561
- const depositReserve = this.obligation!.state.deposits.find(
2582
+ if (!isKaminoObligation(this.obligation)) {
2583
+ throw new Error(`obligation is not a KaminoObligation`);
2584
+ }
2585
+ const depositReserve = this.obligation.state.deposits.find(
2562
2586
  (x) => !x.depositReserve.equals(PublicKey.default)
2563
2587
  )!.depositReserve;
2564
2588
  const collReserve = this.kaminoMarket.getReserveByAddress(depositReserve);
@@ -2592,27 +2616,36 @@ export class KaminoAction {
2592
2616
  const eModeGroup = groups.find((group) => group.id === eModeGroupWithMaxLtvAndDebtReserve)!.id;
2593
2617
  console.log('Setting eModeGroup to', eModeGroup);
2594
2618
 
2595
- if (eModeGroup !== 0 && eModeGroup !== this.obligation?.state.elevationGroup) {
2619
+ if (
2620
+ eModeGroup !== 0 &&
2621
+ eModeGroup !== (isKaminoObligation(this.obligation) ? this.obligation.state.elevationGroup : 0)
2622
+ ) {
2596
2623
  newElevationGroup = eModeGroup;
2597
2624
  }
2598
2625
  }
2599
2626
  }
2600
2627
 
2601
- console.log('newElevationGroup', newElevationGroup, addAsSupportIx);
2602
- if (newElevationGroup >= 0 && newElevationGroup !== this.obligation?.state.elevationGroup) {
2628
+ if (
2629
+ newElevationGroup >= 0 &&
2630
+ newElevationGroup !== (isKaminoObligation(this.obligation) ? this.obligation.state.elevationGroup : 0)
2631
+ ) {
2603
2632
  this.addRequestElevationIx(newElevationGroup, addAsSupportIx);
2604
2633
  this.addRefreshReserveIxs(allReservesExcludingCurrent, addAsSupportIx);
2605
2634
  this.addRefreshReserveIxs(currentReserveAddresses.toArray(), addAsSupportIx);
2606
2635
  this.addRefreshObligationIx(addAsSupportIx);
2607
2636
 
2608
2637
  if (action === 'borrow') {
2609
- this.obligation!.refreshedStats.potentialElevationGroupUpdate = newElevationGroup;
2638
+ if (!isKaminoObligation(this.obligation)) {
2639
+ throw new Error(`obligation is not a KaminoObligation`);
2640
+ }
2641
+ this.obligation.refreshedStats.potentialElevationGroupUpdate = newElevationGroup;
2610
2642
  }
2611
2643
  }
2612
2644
  } else if (
2613
2645
  action === 'deposit' &&
2614
2646
  overrideElevationGroupRequest !== undefined &&
2615
- overrideElevationGroupRequest !== this.obligation?.state.elevationGroup
2647
+ overrideElevationGroupRequest !==
2648
+ (isKaminoObligation(this.obligation) ? this.obligation.state.elevationGroup : 0)
2616
2649
  ) {
2617
2650
  const addAsSupportIx: AuxiliaryIx = 'setup';
2618
2651
  console.log('Deposit: Requesting elevation group', overrideElevationGroupRequest);
@@ -2635,7 +2668,7 @@ export class KaminoAction {
2635
2668
 
2636
2669
  if (!useV2Ixs) {
2637
2670
  if (addAsSupportIx === 'setup') {
2638
- // If this is an setup ixn (therefore not an in-between), it means it's either a one off action
2671
+ // If this is an setup ix (therefore not an in-between), it means it's either a one off action
2639
2672
  // or the first of a two-token-action
2640
2673
  if (action === 'liquidate') {
2641
2674
  this.addRefreshFarmsForReserve([this.outflowReserve!], addAsSupportIx, ReserveFarmKind.Collateral);
@@ -2667,7 +2700,7 @@ export class KaminoAction {
2667
2700
  } else {
2668
2701
  // If this is an inbetween, it means it's part of a two-token-action
2669
2702
  // so we skip the refresh farm obligation of the first reserve as that operation already happened
2670
- // add added to 'setup' ixns
2703
+ // add added to 'setup' ixs
2671
2704
  if (action === 'depositAndBorrow') {
2672
2705
  this.addRefreshFarmsForReserve([this.outflowReserve!], addAsSupportIx, ReserveFarmKind.Debt);
2673
2706
  } else if (action === 'repayAndWithdraw') {
@@ -2682,7 +2715,7 @@ export class KaminoAction {
2682
2715
 
2683
2716
  async addSupportIxs(
2684
2717
  action: ActionType,
2685
- includeAtaIxns: boolean,
2718
+ includeAtaIxs: boolean,
2686
2719
  requestElevationGroup: boolean,
2687
2720
  addInitObligationForFarm: boolean,
2688
2721
  useV2Ixs: boolean,
@@ -2712,7 +2745,7 @@ export class KaminoAction {
2712
2745
 
2713
2746
  await this.addSupportIxsWithoutInitObligation(
2714
2747
  action,
2715
- includeAtaIxns,
2748
+ includeAtaIxs,
2716
2749
  useV2Ixs,
2717
2750
  'setup',
2718
2751
  requestElevationGroup,
@@ -3062,7 +3095,7 @@ export class KaminoAction {
3062
3095
  farms.forEach((arg: [number, PublicKey, PublicKey]) => {
3063
3096
  const args: InitObligationFarmsForReserveArgs = { mode: arg[0] };
3064
3097
  const accounts: InitObligationFarmsForReserveAccounts = {
3065
- owner: this.obligation ? this.obligation.state.owner : this.owner,
3098
+ owner: isKaminoObligation(this.obligation) ? this.obligation.state.owner : this.owner,
3066
3099
  payer: this.owner,
3067
3100
  obligation: this.getObligationPda(),
3068
3101
  lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
@@ -3090,14 +3123,14 @@ export class KaminoAction {
3090
3123
  }
3091
3124
 
3092
3125
  private addInitObligationIxs() {
3093
- if (!this.obligation) {
3126
+ if (!isKaminoObligation(this.obligation)) {
3094
3127
  const obligationPda = this.getObligationPda();
3095
3128
  const [userMetadataAddress, _bump] = userMetadataPda(this.owner, this.kaminoMarket.programId);
3096
3129
  const initObligationIx = initObligation(
3097
3130
  {
3098
3131
  args: {
3099
- tag: this.obligationType!.toArgs().tag,
3100
- id: this.obligationType!.toArgs().id,
3132
+ tag: this.obligation.toArgs().tag,
3133
+ id: this.obligation.toArgs().id,
3101
3134
  },
3102
3135
  },
3103
3136
  {
@@ -3105,8 +3138,8 @@ export class KaminoAction {
3105
3138
  feePayer: this.payer,
3106
3139
  obligation: obligationPda,
3107
3140
  lendingMarket: this.kaminoMarket.getAddress(),
3108
- seed1Account: this.obligationType!.toArgs().seed1,
3109
- seed2Account: this.obligationType!.toArgs().seed2,
3141
+ seed1Account: this.obligation.toArgs().seed1,
3142
+ seed2Account: this.obligation.toArgs().seed2,
3110
3143
  ownerUserMetadata: userMetadataAddress,
3111
3144
  rent: SYSVAR_RENT_PUBKEY,
3112
3145
  systemProgram: SystemProgram.programId,
@@ -3301,7 +3334,11 @@ export class KaminoAction {
3301
3334
 
3302
3335
  let safeRepay = new BN(this.amount);
3303
3336
 
3304
- if (this.obligation && (action === 'repay' || action === 'repayAndWithdrawV2') && this.amount.eq(new BN(U64_MAX))) {
3337
+ if (
3338
+ isKaminoObligation(this.obligation) &&
3339
+ (action === 'repay' || action === 'repayAndWithdrawV2') &&
3340
+ this.amount.eq(new BN(U64_MAX))
3341
+ ) {
3305
3342
  const borrow = this.obligation.state.borrows.find(
3306
3343
  (borrow) => borrow.borrowReserve.toString() === this.reserve.address.toString()
3307
3344
  );
@@ -3512,9 +3549,13 @@ export class KaminoAction {
3512
3549
  }
3513
3550
 
3514
3551
  getObligationPda(): PublicKey {
3515
- return this.obligation
3552
+ return isKaminoObligation(this.obligation)
3516
3553
  ? this.obligation.obligationAddress
3517
- : this.obligationType!.toPda(this.kaminoMarket.getAddress(), this.owner);
3554
+ : this.obligation.toPda(this.kaminoMarket.getAddress(), this.owner);
3555
+ }
3556
+
3557
+ isObligationInitialized() {
3558
+ return this.obligation instanceof KaminoObligation;
3518
3559
  }
3519
3560
 
3520
3561
  getAdditionalDepositReservesList(): PublicKey[] {