@kamino-finance/klend-sdk 5.13.0 → 5.13.2

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 +74 -49
  2. package/dist/classes/action.d.ts.map +1 -1
  3. package/dist/classes/action.js +167 -115
  4. package/dist/classes/action.js.map +1 -1
  5. package/dist/classes/fraction.d.ts +2 -0
  6. package/dist/classes/fraction.d.ts.map +1 -1
  7. package/dist/classes/fraction.js +6 -0
  8. package/dist/classes/fraction.js.map +1 -1
  9. package/dist/classes/index.d.ts +3 -2
  10. package/dist/classes/index.d.ts.map +1 -1
  11. package/dist/classes/index.js +3 -2
  12. package/dist/classes/index.js.map +1 -1
  13. package/dist/classes/manager.d.ts +7 -7
  14. package/dist/classes/manager.d.ts.map +1 -1
  15. package/dist/classes/manager.js +46 -46
  16. package/dist/classes/manager.js.map +1 -1
  17. package/dist/classes/obligation.d.ts.map +1 -1
  18. package/dist/classes/obligation.js +1 -6
  19. package/dist/classes/obligation.js.map +1 -1
  20. package/dist/classes/obligationOrder.d.ts +1 -1
  21. package/dist/classes/obligationOrder.d.ts.map +1 -1
  22. package/dist/classes/reserve.d.ts +2 -2
  23. package/dist/classes/reserve.d.ts.map +1 -1
  24. package/dist/classes/reserve.js +71 -74
  25. package/dist/classes/reserve.js.map +1 -1
  26. package/dist/classes/shared.d.ts +13 -0
  27. package/dist/classes/shared.d.ts.map +1 -1
  28. package/dist/classes/utils.d.ts +1 -9
  29. package/dist/classes/utils.d.ts.map +1 -1
  30. package/dist/classes/utils.js +4 -51
  31. package/dist/classes/utils.js.map +1 -1
  32. package/dist/classes/vault.d.ts +5 -3
  33. package/dist/classes/vault.d.ts.map +1 -1
  34. package/dist/classes/vault.js +53 -41
  35. package/dist/classes/vault.js.map +1 -1
  36. package/dist/classes/{types.d.ts → vault_types.d.ts} +2 -15
  37. package/dist/classes/vault_types.d.ts.map +1 -0
  38. package/dist/classes/{types.js → vault_types.js} +1 -1
  39. package/dist/classes/vault_types.js.map +1 -0
  40. package/dist/client_kamino_manager.d.ts.map +1 -1
  41. package/dist/client_kamino_manager.js +25 -26
  42. package/dist/client_kamino_manager.js.map +1 -1
  43. package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
  44. package/dist/lending_operations/repay_with_collateral_operations.js +8 -8
  45. package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
  46. package/dist/lending_operations/swap_collateral_operations.d.ts +6 -6
  47. package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
  48. package/dist/lending_operations/swap_collateral_operations.js +63 -65
  49. package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
  50. package/dist/leverage/calcs.d.ts +0 -1
  51. package/dist/leverage/calcs.d.ts.map +1 -1
  52. package/dist/leverage/calcs.js +5 -8
  53. package/dist/leverage/calcs.js.map +1 -1
  54. package/dist/leverage/operations.d.ts +5 -5
  55. package/dist/leverage/operations.d.ts.map +1 -1
  56. package/dist/leverage/operations.js +80 -87
  57. package/dist/leverage/operations.js.map +1 -1
  58. package/dist/leverage/types.d.ts +1 -1
  59. package/dist/leverage/types.d.ts.map +1 -1
  60. package/dist/leverage/utils.d.ts +2 -2
  61. package/dist/leverage/utils.d.ts.map +1 -1
  62. package/dist/leverage/utils.js +5 -5
  63. package/dist/leverage/utils.js.map +1 -1
  64. package/dist/referrals/instructions.d.ts +3 -3
  65. package/dist/referrals/instructions.d.ts.map +1 -1
  66. package/dist/referrals/instructions.js +10 -10
  67. package/dist/referrals/instructions.js.map +1 -1
  68. package/dist/referrals/operations.js +6 -6
  69. package/dist/referrals/operations.js.map +1 -1
  70. package/dist/utils/ata.d.ts +3 -3
  71. package/dist/utils/ata.d.ts.map +1 -1
  72. package/dist/utils/ata.js +22 -22
  73. package/dist/utils/ata.js.map +1 -1
  74. package/dist/utils/instruction.d.ts +2 -2
  75. package/dist/utils/instruction.d.ts.map +1 -1
  76. package/dist/utils/instruction.js +12 -12
  77. package/dist/utils/instruction.js.map +1 -1
  78. package/dist/utils/lookupTable.js +6 -6
  79. package/dist/utils/lookupTable.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 +198 -150
  86. package/src/classes/fraction.ts +7 -0
  87. package/src/classes/index.ts +5 -2
  88. package/src/classes/manager.ts +54 -51
  89. package/src/classes/obligation.ts +2 -7
  90. package/src/classes/obligationOrder.ts +1 -1
  91. package/src/classes/reserve.ts +128 -137
  92. package/src/classes/shared.ts +15 -0
  93. package/src/classes/utils.ts +3 -52
  94. package/src/classes/vault.ts +56 -42
  95. package/src/classes/{types.ts → vault_types.ts} +1 -16
  96. package/src/client.ts +16 -16
  97. package/src/client_kamino_manager.ts +25 -25
  98. package/src/lending_operations/repay_with_collateral_operations.ts +13 -15
  99. package/src/lending_operations/swap_collateral_operations.ts +87 -89
  100. package/src/leverage/calcs.ts +2 -6
  101. package/src/leverage/operations.ts +91 -97
  102. package/src/leverage/types.ts +1 -1
  103. package/src/leverage/utils.ts +5 -5
  104. package/src/referrals/instructions.ts +6 -6
  105. package/src/referrals/operations.ts +9 -9
  106. package/src/utils/ata.ts +18 -18
  107. package/src/utils/instruction.ts +10 -10
  108. package/src/utils/lookupTable.ts +6 -6
  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,11 +382,13 @@ 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
- includeUserMetadata: boolean = true, // if true it includes user metadata
394
- createLookupTable: boolean = true,
388
+ initUserMetadata: { skipInitialization: boolean; skipLutCreation: boolean } = {
389
+ skipInitialization: false,
390
+ skipLutCreation: false,
391
+ },
395
392
  referrer: PublicKey = PublicKey.default,
396
393
  currentSlot: number = 0,
397
394
  overrideElevationGroupRequest: number | undefined = undefined // if set, when an elevationgroup request is made, it will use this value
@@ -414,13 +411,12 @@ export class KaminoAction {
414
411
 
415
412
  await axn.addSupportIxs(
416
413
  'deposit',
417
- includeAtaIxns,
414
+ includeAtaIxs,
418
415
  requestElevationGroup,
419
- includeUserMetadata,
420
416
  addInitObligationForFarm,
421
417
  useV2Ixs,
422
418
  scopeRefreshConfig,
423
- createLookupTable,
419
+ initUserMetadata,
424
420
  undefined,
425
421
  overrideElevationGroupRequest
426
422
  );
@@ -454,11 +450,13 @@ export class KaminoAction {
454
450
  obligation: KaminoObligation | ObligationType,
455
451
  useV2Ixs: boolean,
456
452
  scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
457
- extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
458
- 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,
459
455
  requestElevationGroup: boolean = false,
460
- includeUserMetadata: boolean = true, // if true it includes user metadata
461
- createLookupTable: boolean = true,
456
+ initUserMetadata: { skipInitialization: boolean; skipLutCreation: boolean } = {
457
+ skipInitialization: false,
458
+ skipLutCreation: false,
459
+ },
462
460
  referrer: PublicKey = PublicKey.default,
463
461
  currentSlot: number = 0,
464
462
  overrideElevationGroupRequest: number | undefined = undefined // if set, when an elevationgroup request is made, it will use this value
@@ -492,13 +490,12 @@ export class KaminoAction {
492
490
 
493
491
  await axn.addSupportIxs(
494
492
  'borrow',
495
- includeAtaIxns,
493
+ includeAtaIxs,
496
494
  requestElevationGroup,
497
- includeUserMetadata,
498
495
  addInitObligationForFarm,
499
496
  useV2Ixs,
500
497
  scopeRefreshConfig,
501
- createLookupTable,
498
+ initUserMetadata,
502
499
  undefined,
503
500
  overrideElevationGroupRequest
504
501
  );
@@ -519,8 +516,8 @@ export class KaminoAction {
519
516
  owner: PublicKey,
520
517
  obligation: KaminoObligation | ObligationType,
521
518
  scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
522
- extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
523
- 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
524
521
  requestElevationGroup: boolean = false,
525
522
  referrer: PublicKey = PublicKey.default,
526
523
  currentSlot: number = 0
@@ -543,13 +540,12 @@ export class KaminoAction {
543
540
 
544
541
  await axn.addSupportIxs(
545
542
  'mint',
546
- includeAtaIxns,
543
+ includeAtaIxs,
547
544
  requestElevationGroup,
548
545
  false,
549
546
  addInitObligationForFarm,
550
- false,
551
547
  scopeRefreshConfig,
552
- false
548
+ { skipInitialization: true, skipLutCreation: true }
553
549
  );
554
550
  axn.addDepositReserveLiquidityIx();
555
551
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
@@ -563,8 +559,8 @@ export class KaminoAction {
563
559
  owner: PublicKey,
564
560
  obligation: KaminoObligation | ObligationType,
565
561
  scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
566
- extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
567
- 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
568
564
  requestElevationGroup: boolean = false,
569
565
  referrer: PublicKey = PublicKey.default,
570
566
  currentSlot: number = 0
@@ -587,13 +583,12 @@ export class KaminoAction {
587
583
 
588
584
  await axn.addSupportIxs(
589
585
  'redeem',
590
- includeAtaIxns,
586
+ includeAtaIxs,
591
587
  requestElevationGroup,
592
588
  false,
593
589
  addInitObligationForFarm,
594
- false,
595
590
  scopeRefreshConfig,
596
- false
591
+ { skipInitialization: true, skipLutCreation: true }
597
592
  );
598
593
  axn.addRedeemReserveCollateralIx();
599
594
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
@@ -608,11 +603,13 @@ 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
- includeUserMetadata: boolean = true, // if true it includes user metadata
615
- createLookupTable: boolean = true,
609
+ initUserMetadata: { skipInitialization: boolean; skipLutCreation: boolean } = {
610
+ skipInitialization: false,
611
+ skipLutCreation: false,
612
+ },
616
613
  referrer: PublicKey = PublicKey.default,
617
614
  currentSlot: number = 0
618
615
  ) {
@@ -634,13 +631,12 @@ export class KaminoAction {
634
631
 
635
632
  await axn.addSupportIxs(
636
633
  'depositCollateral',
637
- includeAtaIxns,
634
+ includeAtaIxs,
638
635
  requestElevationGroup,
639
- includeUserMetadata,
640
636
  addInitObligationForFarm,
641
637
  useV2Ixs,
642
638
  scopeRefreshConfig,
643
- createLookupTable
639
+ initUserMetadata
644
640
  );
645
641
  if (useV2Ixs) {
646
642
  axn.addDepositObligationCollateralIxV2();
@@ -661,11 +657,13 @@ export class KaminoAction {
661
657
  obligation: KaminoObligation | ObligationType,
662
658
  useV2Ixs: boolean,
663
659
  scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
664
- extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
665
- 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,
666
662
  requestElevationGroup: boolean = false,
667
- includeUserMetadata: boolean = true, // if true it includes user metadata,
668
- createLookupTable: boolean = true,
663
+ initUserMetadata: { skipInitialization: boolean; skipLutCreation: boolean } = {
664
+ skipInitialization: false,
665
+ skipLutCreation: false,
666
+ },
669
667
  referrer: PublicKey = PublicKey.default,
670
668
  currentSlot: number = 0
671
669
  ) {
@@ -703,13 +701,12 @@ export class KaminoAction {
703
701
  }
704
702
  await axn.addSupportIxs(
705
703
  'deposit',
706
- includeAtaIxns,
704
+ includeAtaIxs,
707
705
  requestElevationGroup,
708
- includeUserMetadata,
709
706
  addInitObligationForFarmForDeposit,
710
707
  useV2Ixs,
711
708
  undefined,
712
- createLookupTable,
709
+ initUserMetadata,
713
710
  twoTokenAction
714
711
  );
715
712
 
@@ -720,14 +717,14 @@ export class KaminoAction {
720
717
  }
721
718
  await axn.addInBetweenIxs(
722
719
  'depositAndBorrow',
723
- includeAtaIxns,
720
+ includeAtaIxs,
724
721
  requestElevationGroup,
725
722
  addInitObligationForFarmForBorrow,
726
723
  useV2Ixs
727
724
  );
728
725
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
729
726
 
730
- // 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
731
728
  const allReserves = new PublicKeySet<PublicKey>([
732
729
  ...axn.depositReserves,
733
730
  ...axn.borrowReserves,
@@ -753,11 +750,13 @@ export class KaminoAction {
753
750
  currentSlot: number,
754
751
  obligation: KaminoObligation | ObligationType,
755
752
  scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
756
- extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
757
- 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,
758
755
  requestElevationGroup: boolean = false,
759
- includeUserMetadata: boolean = true, // if true it includes user metadata,
760
- createLookupTable: boolean = true,
756
+ initUserMetadata: { skipInitialization: boolean; skipLutCreation: boolean } = {
757
+ skipInitialization: false,
758
+ skipLutCreation: false,
759
+ },
761
760
  referrer: PublicKey = PublicKey.default
762
761
  ) {
763
762
  const axn = await KaminoAction.initializeMultiTokenAction(
@@ -781,13 +780,12 @@ export class KaminoAction {
781
780
 
782
781
  await axn.addSupportIxs(
783
782
  'depositAndWithdraw',
784
- includeAtaIxns,
783
+ includeAtaIxs,
785
784
  requestElevationGroup,
786
- includeUserMetadata,
787
785
  addInitObligationForFarm,
788
786
  true,
789
787
  scopeRefreshConfig,
790
- createLookupTable,
788
+ initUserMetadata,
791
789
  twoTokenAction
792
790
  );
793
791
  const withdrawCollateralAmount = axn.getWithdrawCollateralAmount(axn.outflowReserve!, axn.outflowAmount!);
@@ -806,11 +804,13 @@ export class KaminoAction {
806
804
  currentSlot: number,
807
805
  obligation: KaminoObligation | ObligationType,
808
806
  scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
809
- extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
810
- 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,
811
809
  requestElevationGroup: boolean = false,
812
- includeUserMetadata: boolean = true, // if true it includes user metadata,
813
- createLookupTable: boolean = true,
810
+ initUserMetadata: { skipInitialization: boolean; skipLutCreation: boolean } = {
811
+ skipInitialization: false,
812
+ skipLutCreation: false,
813
+ },
814
814
  referrer: PublicKey = PublicKey.default
815
815
  ) {
816
816
  const axn = await KaminoAction.initializeMultiTokenAction(
@@ -834,13 +834,12 @@ export class KaminoAction {
834
834
 
835
835
  await axn.addSupportIxs(
836
836
  'repayAndWithdrawV2',
837
- includeAtaIxns,
837
+ includeAtaIxs,
838
838
  requestElevationGroup,
839
- includeUserMetadata,
840
839
  addInitObligationForFarm,
841
840
  true,
842
841
  scopeRefreshConfig,
843
- createLookupTable,
842
+ initUserMetadata,
844
843
  twoTokenAction
845
844
  );
846
845
  const withdrawCollateralAmount = axn.getWithdrawCollateralAmount(axn.outflowReserve!, axn.outflowAmount!);
@@ -860,11 +859,13 @@ export class KaminoAction {
860
859
  obligation: KaminoObligation | ObligationType,
861
860
  useV2Ixs: boolean,
862
861
  scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
863
- extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
864
- 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,
865
864
  requestElevationGroup: boolean = false,
866
- includeUserMetadata: boolean = true, // if true it includes user metadata,
867
- createLookupTable: boolean = true,
865
+ initUserMetadata: { skipInitialization: boolean; skipLutCreation: boolean } = {
866
+ skipInitialization: false,
867
+ skipLutCreation: false,
868
+ },
868
869
  referrer: PublicKey = PublicKey.default
869
870
  ) {
870
871
  const axn = await KaminoAction.initializeMultiTokenAction(
@@ -889,13 +890,12 @@ export class KaminoAction {
889
890
 
890
891
  await axn.addSupportIxs(
891
892
  'repay',
892
- includeAtaIxns,
893
+ includeAtaIxs,
893
894
  requestElevationGroup,
894
- includeUserMetadata,
895
895
  addInitObligationForFarmForRepay,
896
896
  useV2Ixs,
897
897
  undefined,
898
- createLookupTable,
898
+ initUserMetadata,
899
899
  twoTokenAction
900
900
  );
901
901
 
@@ -908,13 +908,13 @@ export class KaminoAction {
908
908
 
909
909
  await axn.addInBetweenIxs(
910
910
  'repayAndWithdraw',
911
- includeAtaIxns,
911
+ includeAtaIxs,
912
912
  requestElevationGroup,
913
913
  addInitObligationForFarmForWithdraw,
914
914
  useV2Ixs
915
915
  );
916
916
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
917
- // 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
918
918
  const allReserves = new PublicKeySet<PublicKey>([
919
919
  ...axn.depositReserves,
920
920
  ...axn.borrowReserves,
@@ -938,15 +938,17 @@ export class KaminoAction {
938
938
  obligation: KaminoObligation | ObligationType,
939
939
  useV2Ixs: boolean,
940
940
  scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
941
- extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
942
- 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,
943
943
  requestElevationGroup: boolean = false, // to be requested *after* the withdraw
944
- includeUserMetadata: boolean = true, // if true it includes user metadata
945
- createLookupTable: boolean = true,
944
+ initUserMetadata: { skipInitialization: boolean; skipLutCreation: boolean } = {
945
+ skipInitialization: false,
946
+ skipLutCreation: false,
947
+ },
946
948
  referrer: PublicKey = PublicKey.default,
947
949
  currentSlot: number = 0,
948
950
  overrideElevationGroupRequest?: number,
949
- // 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.
950
952
  obligationCustomizations?: {
951
953
  // Any newly-added deposit reserves.
952
954
  addedDepositReserves?: PublicKey[];
@@ -972,13 +974,12 @@ export class KaminoAction {
972
974
 
973
975
  await axn.addSupportIxs(
974
976
  'withdraw',
975
- includeAtaIxns,
977
+ includeAtaIxs,
976
978
  requestElevationGroup,
977
- includeUserMetadata,
978
979
  addInitObligationForFarm,
979
980
  useV2Ixs,
980
981
  scopeRefreshConfig,
981
- createLookupTable,
982
+ initUserMetadata,
982
983
  false,
983
984
  overrideElevationGroupRequest
984
985
  );
@@ -1004,8 +1005,8 @@ export class KaminoAction {
1004
1005
  * @param obligation - obligation to repay or the PDA seeds
1005
1006
  * @param currentSlot
1006
1007
  * @param payer - if not set then owner is used
1007
- * @param extraComputeBudget - if > 0 then adds the ixn
1008
- * @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
1009
1010
  * @param requestElevationGroup
1010
1011
  * @param includeUserMetadata - if true it includes user metadata
1011
1012
  * @param referrer
@@ -1021,10 +1022,12 @@ export class KaminoAction {
1021
1022
  currentSlot: number,
1022
1023
  payer: PublicKey | undefined = undefined,
1023
1024
  extraComputeBudget: number = 1_000_000,
1024
- includeAtaIxns: boolean = true,
1025
+ includeAtaIxs: boolean = true,
1025
1026
  requestElevationGroup: boolean = false,
1026
- includeUserMetadata: boolean = true,
1027
- createLookupTable: boolean = true,
1027
+ initUserMetadata: { skipInitialization: boolean; skipLutCreation: boolean } = {
1028
+ skipInitialization: false,
1029
+ skipLutCreation: false,
1030
+ },
1028
1031
  referrer: PublicKey = PublicKey.default
1029
1032
  ) {
1030
1033
  const axn = await KaminoAction.initialize(
@@ -1046,13 +1049,12 @@ export class KaminoAction {
1046
1049
 
1047
1050
  await axn.addSupportIxs(
1048
1051
  'repay',
1049
- includeAtaIxns,
1052
+ includeAtaIxs,
1050
1053
  requestElevationGroup,
1051
- includeUserMetadata,
1052
1054
  addInitObligationForFarm,
1053
1055
  useV2Ixs,
1054
1056
  scopeRefreshConfig,
1055
- createLookupTable
1057
+ initUserMetadata
1056
1058
  );
1057
1059
  if (useV2Ixs) {
1058
1060
  await axn.addRepayIxV2();
@@ -1075,11 +1077,13 @@ export class KaminoAction {
1075
1077
  obligation: KaminoObligation | ObligationType,
1076
1078
  useV2Ixs: boolean,
1077
1079
  scopeRefreshConfig: ScopePriceRefreshConfig | undefined = undefined,
1078
- extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
1079
- 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
1080
1082
  requestElevationGroup: boolean = false,
1081
- includeUserMetadata: boolean = true, // if true it includes user metadata
1082
- createLookupTable: boolean = true,
1083
+ initUserMetadata: { skipInitialization: boolean; skipLutCreation: boolean } = {
1084
+ skipInitialization: false,
1085
+ skipLutCreation: false,
1086
+ },
1083
1087
  referrer: PublicKey = PublicKey.default,
1084
1088
  maxAllowedLtvOverridePercent: number = 0,
1085
1089
  currentSlot: number = 0
@@ -1105,13 +1109,12 @@ export class KaminoAction {
1105
1109
 
1106
1110
  await axn.addSupportIxs(
1107
1111
  'liquidate',
1108
- includeAtaIxns,
1112
+ includeAtaIxs,
1109
1113
  requestElevationGroup,
1110
- includeUserMetadata,
1111
1114
  addInitObligationForFarm,
1112
1115
  useV2Ixs,
1113
1116
  scopeRefreshConfig,
1114
- createLookupTable
1117
+ initUserMetadata
1115
1118
  );
1116
1119
  if (useV2Ixs) {
1117
1120
  await axn.addLiquidateIxV2(maxAllowedLtvOverridePercent);
@@ -1463,7 +1466,8 @@ export class KaminoAction {
1463
1466
  this.kaminoMarket.programId
1464
1467
  );
1465
1468
  borrowIx.keys =
1466
- 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)
1467
1471
  ? borrowIx.keys.concat([...depositReserveAccountMetas])
1468
1472
  : borrowIx.keys;
1469
1473
  this.lendingIxs.push(borrowIx);
@@ -1517,7 +1521,8 @@ export class KaminoAction {
1517
1521
  this.kaminoMarket.programId
1518
1522
  );
1519
1523
  borrowIx.keys =
1520
- 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)
1521
1526
  ? borrowIx.keys.concat([...depositReserveAccountMetas])
1522
1527
  : borrowIx.keys;
1523
1528
  this.lendingIxs.push(borrowIx);
@@ -1625,7 +1630,9 @@ export class KaminoAction {
1625
1630
  );
1626
1631
 
1627
1632
  repayIx.keys =
1628
- 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;
1629
1636
 
1630
1637
  this.lendingIxs.push(repayIx);
1631
1638
  }
@@ -1674,7 +1681,10 @@ export class KaminoAction {
1674
1681
  );
1675
1682
 
1676
1683
  repayIx.keys =
1677
- 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;
1678
1688
 
1679
1689
  this.lendingIxs.push(repayIx);
1680
1690
  }
@@ -2121,6 +2131,10 @@ export class KaminoAction {
2121
2131
  );
2122
2132
  this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateralV2`);
2123
2133
 
2134
+ if (!isKaminoObligation(this.obligation)) {
2135
+ throw new Error(`obligation is not a KaminoObligation`);
2136
+ }
2137
+
2124
2138
  const depositReservesList = this.getAdditionalDepositReservesList();
2125
2139
 
2126
2140
  const depositReserveAccountMetas = depositReservesList.map((reserve) => {
@@ -2160,7 +2174,8 @@ export class KaminoAction {
2160
2174
  this.kaminoMarket.programId
2161
2175
  );
2162
2176
 
2163
- repayIx.keys = repayIx.keys.concat([...depositReserveAccountMetas]);
2177
+ repayIx.keys =
2178
+ this.obligation.state.elevationGroup > 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
2164
2179
 
2165
2180
  this.lendingIxs.push(repayIx);
2166
2181
  if (!this.outflowReserve) {
@@ -2220,6 +2235,10 @@ export class KaminoAction {
2220
2235
  throw Error(`Withdraw reserve during liquidation is not defined`);
2221
2236
  }
2222
2237
 
2238
+ if (!isKaminoObligation(this.obligation)) {
2239
+ throw new Error(`obligation is not a KaminoObligation`);
2240
+ }
2241
+
2223
2242
  const depositReservesList = this.getAdditionalDepositReservesList();
2224
2243
  const depositReserveAccountMetas = depositReservesList.map((reserve) => {
2225
2244
  return { pubkey: reserve, isSigner: false, isWritable: true };
@@ -2257,7 +2276,7 @@ export class KaminoAction {
2257
2276
  this.kaminoMarket.programId
2258
2277
  );
2259
2278
  liquidateIx.keys =
2260
- this.obligation!.state.elevationGroup > 0
2279
+ this.obligation.state.elevationGroup > 0
2261
2280
  ? liquidateIx.keys.concat([...depositReserveAccountMetas])
2262
2281
  : liquidateIx.keys;
2263
2282
  this.lendingIxs.push(liquidateIx);
@@ -2269,6 +2288,10 @@ export class KaminoAction {
2269
2288
  throw Error(`Withdraw reserve during liquidation is not defined`);
2270
2289
  }
2271
2290
 
2291
+ if (!isKaminoObligation(this.obligation)) {
2292
+ throw new Error(`obligation is not a KaminoObligation`);
2293
+ }
2294
+
2272
2295
  const depositReservesList = this.getAdditionalDepositReservesList();
2273
2296
  const depositReserveAccountMetas = depositReservesList.map((reserve) => {
2274
2297
  return { pubkey: reserve, isSigner: false, isWritable: true };
@@ -2342,14 +2365,14 @@ export class KaminoAction {
2342
2365
 
2343
2366
  async addInBetweenIxs(
2344
2367
  action: ActionType,
2345
- includeAtaIxns: boolean,
2368
+ includeAtaIxs: boolean,
2346
2369
  requestElevationGroup: boolean,
2347
2370
  addInitObligationForFarm: boolean,
2348
2371
  useV2Ixs: boolean
2349
2372
  ) {
2350
2373
  await this.addSupportIxsWithoutInitObligation(
2351
2374
  action,
2352
- includeAtaIxns,
2375
+ includeAtaIxs,
2353
2376
  useV2Ixs,
2354
2377
  'inBetween',
2355
2378
  requestElevationGroup,
@@ -2360,29 +2383,29 @@ export class KaminoAction {
2360
2383
  addRefreshObligation(crank: PublicKey) {
2361
2384
  const uniqueReserveAddresses = new PublicKeySet(this.depositReserves.concat(this.borrowReserves)).toArray();
2362
2385
 
2363
- const addAllToSetupIxns = 'setup';
2386
+ const addAllToSetupIxs = 'setup';
2364
2387
  // Union of addresses
2365
2388
  const allReservesExcludingCurrent = [...uniqueReserveAddresses];
2366
2389
 
2367
- this.addRefreshReserveIxs(allReservesExcludingCurrent, addAllToSetupIxns);
2390
+ this.addRefreshReserveIxs(allReservesExcludingCurrent, addAllToSetupIxs);
2368
2391
  this.addRefreshFarmsForReserve(
2369
2392
  this.depositReserves.map((r) => this.kaminoMarket.getReserveByAddress(r)!),
2370
- addAllToSetupIxns,
2393
+ addAllToSetupIxs,
2371
2394
  ReserveFarmKind.Collateral,
2372
2395
  crank
2373
2396
  );
2374
2397
  this.addRefreshFarmsForReserve(
2375
2398
  this.borrowReserves.map((r) => this.kaminoMarket.getReserveByAddress(r)!),
2376
- addAllToSetupIxns,
2399
+ addAllToSetupIxs,
2377
2400
  ReserveFarmKind.Debt,
2378
2401
  crank
2379
2402
  );
2380
- this.addRefreshObligationIx(addAllToSetupIxns);
2403
+ this.addRefreshObligationIx(addAllToSetupIxs);
2381
2404
  }
2382
2405
 
2383
2406
  async addSupportIxsWithoutInitObligation(
2384
2407
  action: ActionType,
2385
- includeAtaIxns: boolean,
2408
+ includeAtaIxs: boolean,
2386
2409
  useV2Ixs: boolean,
2387
2410
  addAsSupportIx: AuxiliaryIx = 'setup',
2388
2411
  requestElevationGroup: boolean = false,
@@ -2391,7 +2414,7 @@ export class KaminoAction {
2391
2414
  overrideElevationGroupRequest?: number
2392
2415
  ) {
2393
2416
  // TODO: why are we not doing this first?
2394
- if (includeAtaIxns) {
2417
+ if (includeAtaIxs) {
2395
2418
  await this.addAtaIxs(action);
2396
2419
  }
2397
2420
 
@@ -2410,18 +2433,18 @@ export class KaminoAction {
2410
2433
  'depositAndWithdraw',
2411
2434
  ].includes(action)
2412
2435
  ) {
2413
- // The support ixns in order are:
2414
- // 0. Init obligation ixn
2415
- // 0. Token Ata ixns
2436
+ // The support ixs in order are:
2437
+ // 0. Init obligation ix
2438
+ // 0. Token Ata ixs
2416
2439
  // 0. Init obligation for farm
2417
- // 1. Ixns to refresh the reserves of the obligation not related to the current action
2418
- // 2. Ixn to refresh the reserve of the current action
2419
- // 3. Ixn to refresh the obligation
2420
- // 4. Ixn to refresh the `debt` farm of the obligation
2421
- // 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
2422
2445
  // 6. The instruction itself
2423
- // 7. Ixn to refresh the `debt` farm of the obligation
2424
- // 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
2425
2448
 
2426
2449
  let currentReserves: KaminoReserve[] = [];
2427
2450
 
@@ -2438,7 +2461,7 @@ export class KaminoAction {
2438
2461
  if (action === 'depositAndBorrow' || action === 'repayAndWithdraw' || action === 'repayAndWithdrawV2') {
2439
2462
  currentReserves = [this.reserve, this.outflowReserve];
2440
2463
  if (action === 'depositAndBorrow') {
2441
- if (this.obligation) {
2464
+ if (isKaminoObligation(this.obligation)) {
2442
2465
  const deposit = this.obligation.getDepositByReserve(this.reserve.address);
2443
2466
  if (!deposit) {
2444
2467
  this.preLoadedDepositReservesSameTx.push(this.reserve.address);
@@ -2504,7 +2527,10 @@ export class KaminoAction {
2504
2527
  this.addRefreshReserveIxs(currentReserveAddresses.toArray(), addAsSupportIx);
2505
2528
 
2506
2529
  if (action === 'repayAndWithdraw' && addAsSupportIx === 'inBetween') {
2507
- 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);
2508
2534
  if (!repayObligationLiquidity) {
2509
2535
  throw new Error(`Could not find debt reserve ${this.reserve.address} in obligation`);
2510
2536
  }
@@ -2518,7 +2544,10 @@ export class KaminoAction {
2518
2544
 
2519
2545
  if (requestElevationGroup) {
2520
2546
  if (action === 'repay' || action === 'repayAndWithdrawV2') {
2521
- 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);
2522
2551
 
2523
2552
  if (!repayObligationLiquidity) {
2524
2553
  throw new Error(`Could not find debt reserve ${this.reserve.address} in obligation`);
@@ -2526,8 +2555,8 @@ export class KaminoAction {
2526
2555
 
2527
2556
  if (
2528
2557
  repayObligationLiquidity.amount.lte(new Decimal(this.amount.toString())) &&
2529
- this.obligation!.borrows.size === 1 &&
2530
- this.obligation?.state.elevationGroup !== 0
2558
+ this.obligation.borrows.size === 1 &&
2559
+ this.obligation.state.elevationGroup !== 0
2531
2560
  ) {
2532
2561
  this.addRefreshReserveIxs(allReservesExcludingCurrent, 'cleanup');
2533
2562
  // Skip the borrow reserve, since we repay in the same tx
@@ -2550,7 +2579,10 @@ export class KaminoAction {
2550
2579
  debtReserve = this.outflowReserve!.address;
2551
2580
  addAsSupportIx = 'inBetween';
2552
2581
  } else if (action === 'borrow') {
2553
- 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(
2554
2586
  (x) => !x.depositReserve.equals(PublicKey.default)
2555
2587
  )!.depositReserve;
2556
2588
  const collReserve = this.kaminoMarket.getReserveByAddress(depositReserve);
@@ -2584,27 +2616,36 @@ export class KaminoAction {
2584
2616
  const eModeGroup = groups.find((group) => group.id === eModeGroupWithMaxLtvAndDebtReserve)!.id;
2585
2617
  console.log('Setting eModeGroup to', eModeGroup);
2586
2618
 
2587
- if (eModeGroup !== 0 && eModeGroup !== this.obligation?.state.elevationGroup) {
2619
+ if (
2620
+ eModeGroup !== 0 &&
2621
+ eModeGroup !== (isKaminoObligation(this.obligation) ? this.obligation.state.elevationGroup : 0)
2622
+ ) {
2588
2623
  newElevationGroup = eModeGroup;
2589
2624
  }
2590
2625
  }
2591
2626
  }
2592
2627
 
2593
- console.log('newElevationGroup', newElevationGroup, addAsSupportIx);
2594
- if (newElevationGroup >= 0 && newElevationGroup !== this.obligation?.state.elevationGroup) {
2628
+ if (
2629
+ newElevationGroup >= 0 &&
2630
+ newElevationGroup !== (isKaminoObligation(this.obligation) ? this.obligation.state.elevationGroup : 0)
2631
+ ) {
2595
2632
  this.addRequestElevationIx(newElevationGroup, addAsSupportIx);
2596
2633
  this.addRefreshReserveIxs(allReservesExcludingCurrent, addAsSupportIx);
2597
2634
  this.addRefreshReserveIxs(currentReserveAddresses.toArray(), addAsSupportIx);
2598
2635
  this.addRefreshObligationIx(addAsSupportIx);
2599
2636
 
2600
2637
  if (action === 'borrow') {
2601
- 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;
2602
2642
  }
2603
2643
  }
2604
2644
  } else if (
2605
2645
  action === 'deposit' &&
2606
2646
  overrideElevationGroupRequest !== undefined &&
2607
- overrideElevationGroupRequest !== this.obligation?.state.elevationGroup
2647
+ overrideElevationGroupRequest !==
2648
+ (isKaminoObligation(this.obligation) ? this.obligation.state.elevationGroup : 0)
2608
2649
  ) {
2609
2650
  const addAsSupportIx: AuxiliaryIx = 'setup';
2610
2651
  console.log('Deposit: Requesting elevation group', overrideElevationGroupRequest);
@@ -2627,7 +2668,7 @@ export class KaminoAction {
2627
2668
 
2628
2669
  if (!useV2Ixs) {
2629
2670
  if (addAsSupportIx === 'setup') {
2630
- // 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
2631
2672
  // or the first of a two-token-action
2632
2673
  if (action === 'liquidate') {
2633
2674
  this.addRefreshFarmsForReserve([this.outflowReserve!], addAsSupportIx, ReserveFarmKind.Collateral);
@@ -2659,7 +2700,7 @@ export class KaminoAction {
2659
2700
  } else {
2660
2701
  // If this is an inbetween, it means it's part of a two-token-action
2661
2702
  // so we skip the refresh farm obligation of the first reserve as that operation already happened
2662
- // add added to 'setup' ixns
2703
+ // add added to 'setup' ixs
2663
2704
  if (action === 'depositAndBorrow') {
2664
2705
  this.addRefreshFarmsForReserve([this.outflowReserve!], addAsSupportIx, ReserveFarmKind.Debt);
2665
2706
  } else if (action === 'repayAndWithdraw') {
@@ -2674,21 +2715,20 @@ export class KaminoAction {
2674
2715
 
2675
2716
  async addSupportIxs(
2676
2717
  action: ActionType,
2677
- includeAtaIxns: boolean,
2718
+ includeAtaIxs: boolean,
2678
2719
  requestElevationGroup: boolean,
2679
- includeUserMetadata: boolean,
2680
2720
  addInitObligationForFarm: boolean,
2681
2721
  useV2Ixs: boolean,
2682
2722
  scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
2683
- createLookupTable: boolean,
2723
+ initUserMetadata: { skipInitialization: boolean; skipLutCreation: boolean },
2684
2724
  twoTokenAction: boolean = false,
2685
2725
  overrideElevationGroupRequest?: number
2686
2726
  ) {
2687
2727
  if (!['mint', 'redeem'].includes(action)) {
2688
2728
  const [, ownerUserMetadata] = await this.kaminoMarket.getUserMetadata(this.owner);
2689
- if (!ownerUserMetadata && includeUserMetadata) {
2729
+ if (!ownerUserMetadata && !initUserMetadata.skipInitialization) {
2690
2730
  let lookupTable: PublicKey = PublicKey.default;
2691
- if (createLookupTable) {
2731
+ if (!initUserMetadata.skipLutCreation) {
2692
2732
  const [createLutIx, lookupTableAddress] = await createLookupTableIx(
2693
2733
  this.kaminoMarket.getConnection(),
2694
2734
  this.owner
@@ -2705,7 +2745,7 @@ export class KaminoAction {
2705
2745
 
2706
2746
  await this.addSupportIxsWithoutInitObligation(
2707
2747
  action,
2708
- includeAtaIxns,
2748
+ includeAtaIxs,
2709
2749
  useV2Ixs,
2710
2750
  'setup',
2711
2751
  requestElevationGroup,
@@ -3055,7 +3095,7 @@ export class KaminoAction {
3055
3095
  farms.forEach((arg: [number, PublicKey, PublicKey]) => {
3056
3096
  const args: InitObligationFarmsForReserveArgs = { mode: arg[0] };
3057
3097
  const accounts: InitObligationFarmsForReserveAccounts = {
3058
- owner: this.obligation ? this.obligation.state.owner : this.owner,
3098
+ owner: isKaminoObligation(this.obligation) ? this.obligation.state.owner : this.owner,
3059
3099
  payer: this.owner,
3060
3100
  obligation: this.getObligationPda(),
3061
3101
  lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
@@ -3083,14 +3123,14 @@ export class KaminoAction {
3083
3123
  }
3084
3124
 
3085
3125
  private addInitObligationIxs() {
3086
- if (!this.obligation) {
3126
+ if (!isKaminoObligation(this.obligation)) {
3087
3127
  const obligationPda = this.getObligationPda();
3088
3128
  const [userMetadataAddress, _bump] = userMetadataPda(this.owner, this.kaminoMarket.programId);
3089
3129
  const initObligationIx = initObligation(
3090
3130
  {
3091
3131
  args: {
3092
- tag: this.obligationType!.toArgs().tag,
3093
- id: this.obligationType!.toArgs().id,
3132
+ tag: this.obligation.toArgs().tag,
3133
+ id: this.obligation.toArgs().id,
3094
3134
  },
3095
3135
  },
3096
3136
  {
@@ -3098,8 +3138,8 @@ export class KaminoAction {
3098
3138
  feePayer: this.payer,
3099
3139
  obligation: obligationPda,
3100
3140
  lendingMarket: this.kaminoMarket.getAddress(),
3101
- seed1Account: this.obligationType!.toArgs().seed1,
3102
- seed2Account: this.obligationType!.toArgs().seed2,
3141
+ seed1Account: this.obligation.toArgs().seed1,
3142
+ seed2Account: this.obligation.toArgs().seed2,
3103
3143
  ownerUserMetadata: userMetadataAddress,
3104
3144
  rent: SYSVAR_RENT_PUBKEY,
3105
3145
  systemProgram: SystemProgram.programId,
@@ -3294,7 +3334,11 @@ export class KaminoAction {
3294
3334
 
3295
3335
  let safeRepay = new BN(this.amount);
3296
3336
 
3297
- 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
+ ) {
3298
3342
  const borrow = this.obligation.state.borrows.find(
3299
3343
  (borrow) => borrow.borrowReserve.toString() === this.reserve.address.toString()
3300
3344
  );
@@ -3505,9 +3549,13 @@ export class KaminoAction {
3505
3549
  }
3506
3550
 
3507
3551
  getObligationPda(): PublicKey {
3508
- return this.obligation
3552
+ return isKaminoObligation(this.obligation)
3509
3553
  ? this.obligation.obligationAddress
3510
- : 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;
3511
3559
  }
3512
3560
 
3513
3561
  getAdditionalDepositReservesList(): PublicKey[] {