@kamino-finance/klend-sdk 5.11.5 → 5.11.6-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/dist/classes/action.d.ts +23 -23
  2. package/dist/classes/action.d.ts.map +1 -1
  3. package/dist/classes/action.js +195 -122
  4. package/dist/classes/action.js.map +1 -1
  5. package/dist/classes/index.d.ts +0 -1
  6. package/dist/classes/index.d.ts.map +1 -1
  7. package/dist/classes/index.js +0 -1
  8. package/dist/classes/index.js.map +1 -1
  9. package/dist/classes/manager.d.ts +1 -6
  10. package/dist/classes/manager.d.ts.map +1 -1
  11. package/dist/classes/manager.js +1 -16
  12. package/dist/classes/manager.js.map +1 -1
  13. package/dist/classes/market.d.ts +3 -3
  14. package/dist/classes/market.d.ts.map +1 -1
  15. package/dist/classes/market.js +16 -30
  16. package/dist/classes/market.js.map +1 -1
  17. package/dist/classes/obligation.d.ts +0 -2
  18. package/dist/classes/obligation.d.ts.map +1 -1
  19. package/dist/classes/obligation.js +0 -5
  20. package/dist/classes/obligation.js.map +1 -1
  21. package/dist/classes/types.d.ts.map +1 -1
  22. package/dist/classes/vault.d.ts +0 -1
  23. package/dist/classes/vault.d.ts.map +1 -1
  24. package/dist/classes/vault.js +18 -21
  25. package/dist/classes/vault.js.map +1 -1
  26. package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts +3 -6
  27. package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts.map +1 -1
  28. package/dist/idl_codegen_kamino_vault/accounts/VaultState.js +7 -13
  29. package/dist/idl_codegen_kamino_vault/accounts/VaultState.js.map +1 -1
  30. package/dist/idl_codegen_kamino_vault/errors/custom.d.ts +1 -25
  31. package/dist/idl_codegen_kamino_vault/errors/custom.d.ts.map +1 -1
  32. package/dist/idl_codegen_kamino_vault/errors/custom.js +1 -43
  33. package/dist/idl_codegen_kamino_vault/errors/custom.js.map +1 -1
  34. package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.d.ts +1 -1
  35. package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.d.ts.map +1 -1
  36. package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.js +1 -1
  37. package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.js.map +1 -1
  38. package/dist/idl_codegen_kamino_vault/instructions/initVault.d.ts +0 -1
  39. package/dist/idl_codegen_kamino_vault/instructions/initVault.d.ts.map +1 -1
  40. package/dist/idl_codegen_kamino_vault/instructions/initVault.js +0 -1
  41. package/dist/idl_codegen_kamino_vault/instructions/initVault.js.map +1 -1
  42. package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.d.ts +1 -1
  43. package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.d.ts.map +1 -1
  44. package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.js +1 -1
  45. package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.js.map +1 -1
  46. package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.d.ts +1 -1
  47. package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.d.ts.map +1 -1
  48. package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.js +1 -1
  49. package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.js.map +1 -1
  50. package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.d.ts +1 -1
  51. package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.d.ts.map +1 -1
  52. package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.js +1 -1
  53. package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.js.map +1 -1
  54. package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.d.ts +1 -1
  55. package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.d.ts.map +1 -1
  56. package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.js +1 -1
  57. package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.js.map +1 -1
  58. package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.d.ts +1 -1
  59. package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.d.ts.map +1 -1
  60. package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.js +1 -1
  61. package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.js.map +1 -1
  62. package/dist/idl_codegen_kamino_vault/types/VaultConfigField.d.ts +0 -13
  63. package/dist/idl_codegen_kamino_vault/types/VaultConfigField.d.ts.map +1 -1
  64. package/dist/idl_codegen_kamino_vault/types/VaultConfigField.js +1 -25
  65. package/dist/idl_codegen_kamino_vault/types/VaultConfigField.js.map +1 -1
  66. package/dist/idl_codegen_kamino_vault/types/index.d.ts +2 -2
  67. package/dist/idl_codegen_kamino_vault/types/index.d.ts.map +1 -1
  68. package/dist/idl_codegen_kamino_vault/types/index.js.map +1 -1
  69. package/dist/lending_operations/repay_with_collateral_operations.d.ts +4 -4
  70. package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
  71. package/dist/lending_operations/repay_with_collateral_operations.js +8 -10
  72. package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
  73. package/dist/lending_operations/swap_collateral_operations.d.ts +2 -2
  74. package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
  75. package/dist/lending_operations/swap_collateral_operations.js +6 -11
  76. package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
  77. package/dist/leverage/operations.d.ts +7 -9
  78. package/dist/leverage/operations.d.ts.map +1 -1
  79. package/dist/leverage/operations.js +66 -78
  80. package/dist/leverage/operations.js.map +1 -1
  81. package/dist/leverage/types.d.ts +4 -4
  82. package/dist/leverage/types.d.ts.map +1 -1
  83. package/dist/utils/ObligationType.d.ts +1 -1
  84. package/dist/utils/ObligationType.d.ts.map +1 -1
  85. package/dist/utils/constants.d.ts +0 -1
  86. package/dist/utils/constants.d.ts.map +1 -1
  87. package/dist/utils/constants.js +1 -2
  88. package/dist/utils/constants.js.map +1 -1
  89. package/dist/utils/managerTypes.d.ts.map +1 -1
  90. package/dist/utils/managerTypes.js +52 -7
  91. package/dist/utils/managerTypes.js.map +1 -1
  92. package/dist/utils/oracle.d.ts +3 -3
  93. package/dist/utils/oracle.d.ts.map +1 -1
  94. package/dist/utils/oracle.js +3 -4
  95. package/dist/utils/oracle.js.map +1 -1
  96. package/package.json +2 -2
  97. package/src/classes/action.ts +211 -143
  98. package/src/classes/index.ts +0 -1
  99. package/src/classes/manager.ts +1 -27
  100. package/src/classes/market.ts +25 -34
  101. package/src/classes/obligation.ts +0 -6
  102. package/src/classes/types.ts +1 -1
  103. package/src/classes/vault.ts +22 -23
  104. package/src/client.ts +3 -8
  105. package/src/idl_codegen_kamino_vault/accounts/VaultState.ts +9 -17
  106. package/src/idl_codegen_kamino_vault/errors/custom.ts +0 -42
  107. package/src/idl_codegen_kamino_vault/instructions/giveUpPendingFees.ts +2 -2
  108. package/src/idl_codegen_kamino_vault/instructions/initVault.ts +0 -2
  109. package/src/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.ts +2 -2
  110. package/src/idl_codegen_kamino_vault/instructions/updateReserveAllocation.ts +2 -2
  111. package/src/idl_codegen_kamino_vault/instructions/updateSharesMetadata.ts +2 -2
  112. package/src/idl_codegen_kamino_vault/instructions/updateVaultConfig.ts +2 -2
  113. package/src/idl_codegen_kamino_vault/instructions/withdrawPendingFees.ts +2 -2
  114. package/src/idl_codegen_kamino_vault/types/VaultConfigField.ts +0 -30
  115. package/src/idl_codegen_kamino_vault/types/index.ts +0 -2
  116. package/src/idl_kamino_vault.json +8 -35
  117. package/src/lending_operations/repay_with_collateral_operations.ts +11 -15
  118. package/src/lending_operations/swap_collateral_operations.ts +7 -19
  119. package/src/leverage/operations.ts +66 -114
  120. package/src/leverage/types.ts +4 -4
  121. package/src/utils/ObligationType.ts +1 -1
  122. package/src/utils/constants.ts +0 -1
  123. package/src/utils/managerTypes.ts +52 -10
  124. package/src/utils/oracle.ts +6 -7
@@ -6,8 +6,6 @@ import {
6
6
  KaminoObligation,
7
7
  KaminoReserve,
8
8
  lamportsToNumberDecimal as fromLamports,
9
- getTokenIdsForScopeRefresh,
10
- isKaminoObligation,
11
9
  } from '../classes';
12
10
  import { getFlashLoanInstructions } from './instructions';
13
11
 
@@ -17,9 +15,7 @@ import {
17
15
  MultiplyObligation,
18
16
  ObligationType,
19
17
  ObligationTypeTag,
20
- PublicKeySet,
21
18
  SOL_DECIMALS,
22
- ScopePriceRefreshConfig,
23
19
  U64_MAX,
24
20
  createAtasIdempotent,
25
21
  getAssociatedTokenAddress,
@@ -84,7 +80,7 @@ export async function getDepositWithLeverageSwapInputs<QuoteResponse>({
84
80
  selectedTokenMint,
85
81
  kamino,
86
82
  obligationTypeTagOverride,
87
- scopeRefreshConfig,
83
+ scopeFeed,
88
84
  budgetAndPriorityFeeIxs,
89
85
  quoteBufferBps,
90
86
  priceAinB,
@@ -146,7 +142,7 @@ export async function getDepositWithLeverageSwapInputs<QuoteResponse>({
146
142
  referrer,
147
143
  currentSlot,
148
144
  depositTokenIsSol,
149
- scopeRefreshConfig,
145
+ scopeFeed,
150
146
  calcs,
151
147
  budgetAndPriorityFeeIxs,
152
148
  {
@@ -313,7 +309,7 @@ export async function getDepositWithLeverageIxns<QuoteResponse>({
313
309
  selectedTokenMint,
314
310
  kamino,
315
311
  obligationTypeTagOverride,
316
- scopeRefreshConfig,
312
+ scopeFeed,
317
313
  budgetAndPriorityFeeIxs,
318
314
  quoteBufferBps,
319
315
  priceAinB,
@@ -338,7 +334,7 @@ export async function getDepositWithLeverageIxns<QuoteResponse>({
338
334
  selectedTokenMint,
339
335
  kamino,
340
336
  obligationTypeTagOverride,
341
- scopeRefreshConfig,
337
+ scopeFeed,
342
338
  budgetAndPriorityFeeIxs,
343
339
  quoteBufferBps,
344
340
  priceAinB,
@@ -390,7 +386,7 @@ export async function getDepositWithLeverageIxns<QuoteResponse>({
390
386
  referrer,
391
387
  currentSlot,
392
388
  depositTokenIsSol,
393
- scopeRefreshConfig,
389
+ scopeFeed,
394
390
  initialInputs.calcs,
395
391
  budgetAndPriorityFeeIxs,
396
392
  {
@@ -421,7 +417,7 @@ async function buildDepositWithLeverageIxns(
421
417
  referrer: PublicKey,
422
418
  currentSlot: number,
423
419
  depositTokenIsSol: boolean,
424
- scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
420
+ scopeFeed: string | undefined,
425
421
  calcs: DepositLeverageCalcsResult,
426
422
  budgetAndPriorityFeeIxs: TransactionInstruction[] | undefined,
427
423
  swapQuoteIxs: SwapIxs,
@@ -446,7 +442,7 @@ async function buildDepositWithLeverageIxns(
446
442
  debtReserve.getLiquidityTokenProgram()
447
443
  );
448
444
 
449
- // 1. Create atas & budget ixns
445
+ // 1. Create atas & budget txns
450
446
  let mintsToCreateAtas: Array<{ mint: PublicKey; tokenProgram: PublicKey }>;
451
447
  if (collIsKtoken) {
452
448
  const secondTokenAta = strategy!.strategy.tokenAMint.equals(debtTokenMint)
@@ -507,13 +503,10 @@ async function buildDepositWithLeverageIxns(
507
503
  );
508
504
  }
509
505
 
510
- const scopeRefreshIxn = await getScopeRefreshIx(market, collReserve, debtReserve, obligation, scopeRefreshConfig);
511
-
512
506
  // 2. Flash borrow & repay the collateral amount needed for given leverage
513
507
  // if user deposits coll, then we borrow the diff, else we borrow the entire amount
514
508
  const { flashBorrowIxn, flashRepayIxn } = getFlashLoanInstructions({
515
- borrowIxnIndex:
516
- budgetIxns.length + atasAndCreateIxns.length + fillWsolAtaIxns.length + (scopeRefreshIxn.length > 0 ? 1 : 0),
509
+ borrowIxnIndex: budgetIxns.length + atasAndCreateIxns.length + fillWsolAtaIxns.length,
517
510
  walletPublicKey: owner,
518
511
  lendingMarketAuthority: market.getLendingMarketAuthority(),
519
512
  lendingMarketAddress: market.getAddress(),
@@ -530,6 +523,7 @@ async function buildDepositWithLeverageIxns(
530
523
  });
531
524
 
532
525
  // 3. Deposit initial tokens + borrowed tokens into reserve
526
+ const scopeRefresh = scopeFeed ? { includeScopeRefresh: true, scopeFeed: scopeFeed } : undefined;
533
527
  const kaminoDepositAndBorrowAction = await KaminoAction.buildDepositAndBorrowTxns(
534
528
  market,
535
529
  toLamports(!collIsKtoken ? calcs.collTokenToDeposit : calcs.collTokenToDeposit, collReserve.stats.decimals)
@@ -543,14 +537,14 @@ async function buildDepositWithLeverageIxns(
543
537
  owner,
544
538
  obligation!,
545
539
  useV2Ixs,
546
- undefined,
547
540
  0,
548
541
  false,
549
542
  elevationGroupOverride === 0 ? false : true, // emode
550
543
  false, // to be checked and created in a setup tx in the UI
551
544
  false, // to be checked and created in a setup tx in the UI
552
545
  referrer,
553
- currentSlot
546
+ currentSlot,
547
+ scopeRefresh
554
548
  );
555
549
 
556
550
  // 4. Swap
@@ -559,18 +553,18 @@ async function buildDepositWithLeverageIxns(
559
553
 
560
554
  if (!collIsKtoken) {
561
555
  return [
562
- ...scopeRefreshIxn,
563
556
  ...budgetIxns,
564
557
  ...atasAndCreateIxns.map((x) => x.createAtaIx),
565
558
  ...fillWsolAtaIxns,
566
559
  ...[flashBorrowIxn],
567
- ...KaminoAction.actionToIxs(kaminoDepositAndBorrowAction),
560
+ ...kaminoDepositAndBorrowAction.setupIxs,
561
+ ...KaminoAction.actionToLendingIxs(kaminoDepositAndBorrowAction),
562
+ ...kaminoDepositAndBorrowAction.cleanupIxs,
568
563
  ...swapInstructions,
569
564
  ...[flashRepayIxn],
570
565
  ];
571
566
  } else {
572
567
  return [
573
- ...scopeRefreshIxn,
574
568
  ...budgetIxns,
575
569
  ...atasAndCreateIxns.map((x) => x.createAtaIx),
576
570
  ...fillWsolAtaIxns,
@@ -601,7 +595,7 @@ export async function getWithdrawWithLeverageSwapInputs<QuoteResponse>({
601
595
  selectedTokenMint,
602
596
  budgetAndPriorityFeeIxs,
603
597
  kamino,
604
- scopeRefreshConfig,
598
+ scopeFeed,
605
599
  quoteBufferBps,
606
600
  isKtoken,
607
601
  quoter,
@@ -647,7 +641,7 @@ export async function getWithdrawWithLeverageSwapInputs<QuoteResponse>({
647
641
  currentSlot,
648
642
  isClosingPosition,
649
643
  depositTokenIsSol,
650
- scopeRefreshConfig,
644
+ scopeFeed,
651
645
  calcs,
652
646
  budgetAndPriorityFeeIxs,
653
647
  {
@@ -735,7 +729,7 @@ export async function getWithdrawWithLeverageIxns<QuoteResponse>({
735
729
  selectedTokenMint,
736
730
  budgetAndPriorityFeeIxs,
737
731
  kamino,
738
- scopeRefreshConfig,
732
+ scopeFeed,
739
733
  quoteBufferBps,
740
734
  isKtoken,
741
735
  quoter,
@@ -764,7 +758,7 @@ export async function getWithdrawWithLeverageIxns<QuoteResponse>({
764
758
  selectedTokenMint,
765
759
  budgetAndPriorityFeeIxs,
766
760
  kamino,
767
- scopeRefreshConfig,
761
+ scopeFeed,
768
762
  quoteBufferBps,
769
763
  isKtoken,
770
764
  quoter,
@@ -810,7 +804,7 @@ export async function getWithdrawWithLeverageIxns<QuoteResponse>({
810
804
  currentSlot,
811
805
  isClosingPosition,
812
806
  depositTokenIsSol,
813
- scopeRefreshConfig,
807
+ scopeFeed,
814
808
  initialInputs.calcs,
815
809
  budgetAndPriorityFeeIxs,
816
810
  {
@@ -842,7 +836,7 @@ export async function buildWithdrawWithLeverageIxns(
842
836
  currentSlot: number,
843
837
  isClosingPosition: boolean,
844
838
  depositTokenIsSol: boolean,
845
- scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
839
+ scopeFeed: string | undefined,
846
840
  calcs: WithdrawLeverageCalcsResult,
847
841
  budgetAndPriorityFeeIxs: TransactionInstruction[] | undefined,
848
842
  swapQuoteIxs: SwapIxs,
@@ -916,7 +910,7 @@ export async function buildWithdrawWithLeverageIxns(
916
910
 
917
911
  const budgetIxns = budgetAndPriorityFeeIxs || getComputeBudgetAndPriorityFeeIxns(3000000);
918
912
 
919
- // TODO: Mihai/Marius check if we can improve this logic and not convert any SOL
913
+ // TODO: Might be worth removing as it's only needed for Ktokens
920
914
  // This is here so that we have enough wsol to repay in case the kAB swapped to sol after estimates is not enough
921
915
  const fillWsolAtaIxns: TransactionInstruction[] = [];
922
916
  if (debtTokenMint.equals(NATIVE_MINT)) {
@@ -931,14 +925,11 @@ export async function buildWithdrawWithLeverageIxns(
931
925
  );
932
926
  }
933
927
 
934
- const scopeRefreshIxn = await getScopeRefreshIx(market, collReserve, debtReserve, obligation, scopeRefreshConfig);
935
-
936
928
  // 2. Prepare the flash borrow and flash repay amounts and ixns
937
929
  // We borrow exactly how much we need to repay
938
930
  // and repay that + flash amount fee
939
931
  const { flashBorrowIxn, flashRepayIxn } = getFlashLoanInstructions({
940
- borrowIxnIndex:
941
- budgetIxns.length + atasAndCreateIxns.length + fillWsolAtaIxns.length + (scopeRefreshIxn.length > 0 ? 1 : 0),
932
+ borrowIxnIndex: budgetIxns.length + atasAndCreateIxns.length + fillWsolAtaIxns.length,
942
933
  walletPublicKey: owner,
943
934
  lendingMarketAuthority: market.getLendingMarketAuthority(),
944
935
  lendingMarketAddress: market.getAddress(),
@@ -951,7 +942,7 @@ export async function buildWithdrawWithLeverageIxns(
951
942
  programId: market.programId,
952
943
  });
953
944
 
954
- // 3. Repay borrowed tokens and Withdraw tokens from reserve that will be swapped to repay flash loan
945
+ // 6. Repay borrowed tokens and Withdraw tokens from reserve that will be swapped to repay flash loan
955
946
  const repayAndWithdrawAction = await KaminoAction.buildRepayAndWithdrawTxns(
956
947
  market,
957
948
  isClosingPosition ? U64_MAX : toLamports(calcs.repayAmount, debtReserve!.stats.decimals).floor().toString(),
@@ -964,24 +955,25 @@ export async function buildWithdrawWithLeverageIxns(
964
955
  currentSlot,
965
956
  obligation,
966
957
  useV2Ixs,
967
- undefined,
968
958
  0,
969
959
  false,
970
960
  false, // to be checked and created in a setup tx in the UI (won't be the case for withdraw anyway as this would be created in deposit)
971
961
  false, // to be checked and created in a setup tx in the UI (won't be the case for withdraw anyway as this would be created in deposit)
972
962
  isClosingPosition,
973
- referrer
963
+ referrer,
964
+ { includeScopeRefresh: true, scopeFeed: scopeFeed! }
974
965
  );
975
966
 
976
967
  const swapInstructions = removeBudgetAndAtaIxns(swapQuoteIxs.swapIxs, []);
977
968
 
978
969
  return [
979
- ...scopeRefreshIxn,
980
970
  ...budgetIxns,
981
971
  ...atasAndCreateIxns.map((x) => x.createAtaIx),
982
972
  ...fillWsolAtaIxns,
983
973
  ...[flashBorrowIxn],
984
- ...KaminoAction.actionToIxs(repayAndWithdrawAction),
974
+ ...repayAndWithdrawAction.setupIxs,
975
+ ...KaminoAction.actionToLendingIxs(repayAndWithdrawAction),
976
+ ...repayAndWithdrawAction.cleanupIxs,
985
977
  ...swapInstructions,
986
978
  ...[flashRepayIxn],
987
979
  ...closeWsolAtaIxns,
@@ -1004,7 +996,7 @@ export async function getAdjustLeverageSwapInputs<QuoteResponse>({
1004
996
  slippagePct,
1005
997
  budgetAndPriorityFeeIxs,
1006
998
  kamino,
1007
- scopeRefreshConfig,
999
+ scopeFeed,
1008
1000
  quoteBufferBps,
1009
1001
  isKtoken,
1010
1002
  quoter,
@@ -1067,7 +1059,7 @@ export async function getAdjustLeverageSwapInputs<QuoteResponse>({
1067
1059
  currentSlot,
1068
1060
  calcs,
1069
1061
  strategy,
1070
- scopeRefreshConfig,
1062
+ scopeFeed,
1071
1063
  collIsKtoken,
1072
1064
  {
1073
1065
  preActionIxs: [],
@@ -1171,7 +1163,7 @@ export async function getAdjustLeverageSwapInputs<QuoteResponse>({
1171
1163
  currentSlot,
1172
1164
  calcs,
1173
1165
  strategy,
1174
- scopeRefreshConfig,
1166
+ scopeFeed,
1175
1167
  collIsKtoken,
1176
1168
  {
1177
1169
  preActionIxs: [],
@@ -1259,7 +1251,7 @@ export async function getAdjustLeverageIxns<QuoteResponse>({
1259
1251
  slippagePct,
1260
1252
  budgetAndPriorityFeeIxs,
1261
1253
  kamino,
1262
- scopeRefreshConfig,
1254
+ scopeFeed,
1263
1255
  quoteBufferBps,
1264
1256
  priceAinB,
1265
1257
  isKtoken,
@@ -1283,7 +1275,7 @@ export async function getAdjustLeverageIxns<QuoteResponse>({
1283
1275
  slippagePct,
1284
1276
  budgetAndPriorityFeeIxs,
1285
1277
  kamino,
1286
- scopeRefreshConfig,
1278
+ scopeFeed,
1287
1279
  quoteBufferBps,
1288
1280
  priceAinB,
1289
1281
  isKtoken,
@@ -1329,7 +1321,7 @@ export async function getAdjustLeverageIxns<QuoteResponse>({
1329
1321
  currentSlot,
1330
1322
  initialInputs.calcs,
1331
1323
  initialInputs.strategy,
1332
- scopeRefreshConfig,
1324
+ scopeFeed,
1333
1325
  initialInputs.collIsKtoken,
1334
1326
  {
1335
1327
  preActionIxs: [],
@@ -1376,7 +1368,7 @@ export async function getAdjustLeverageIxns<QuoteResponse>({
1376
1368
  currentSlot,
1377
1369
  initialInputs.calcs,
1378
1370
  initialInputs.strategy,
1379
- scopeRefreshConfig,
1371
+ scopeFeed,
1380
1372
  initialInputs.collIsKtoken,
1381
1373
  {
1382
1374
  preActionIxs: [],
@@ -1409,7 +1401,7 @@ async function buildIncreaseLeverageIxns(
1409
1401
  currentSlot: number,
1410
1402
  calcs: AdjustLeverageCalcsResult,
1411
1403
  strategy: StrategyWithAddress | undefined,
1412
- scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
1404
+ scopeFeed: string | undefined,
1413
1405
  collIsKtoken: boolean,
1414
1406
  swapQuoteIxs: SwapIxs,
1415
1407
  budgetAndPriorityFeeIxns: TransactionInstruction[] | undefined,
@@ -1481,17 +1473,9 @@ async function buildIncreaseLeverageIxns(
1481
1473
 
1482
1474
  const atasAndCreateIxns = createAtasIdempotent(owner, mintsToCreateAtas);
1483
1475
 
1484
- const scopeRefreshIxn = await getScopeRefreshIx(
1485
- kaminoMarket,
1486
- collReserve!,
1487
- debtReserve!,
1488
- obligation,
1489
- scopeRefreshConfig
1490
- );
1491
-
1492
1476
  // 2. Create borrow flash loan instruction
1493
1477
  const { flashBorrowIxn, flashRepayIxn } = getFlashLoanInstructions({
1494
- borrowIxnIndex: budgetIxns.length + atasAndCreateIxns.length + (scopeRefreshIxn.length > 0 ? 1 : 0), // TODO: how about user metadata ixns
1478
+ borrowIxnIndex: budgetIxns.length + atasAndCreateIxns.length, // TODO: how about user metadata ixns
1495
1479
  walletPublicKey: owner,
1496
1480
  lendingMarketAuthority: kaminoMarket.getLendingMarketAuthority(),
1497
1481
  lendingMarketAddress: kaminoMarket.getAddress(),
@@ -1514,14 +1498,14 @@ async function buildIncreaseLeverageIxns(
1514
1498
  owner,
1515
1499
  obligation,
1516
1500
  useV2Ixs,
1517
- undefined,
1518
1501
  0,
1519
1502
  false,
1520
1503
  false,
1521
1504
  false, // to be checked and create in a setup tx in the UI (won't be the case for adjust anyway as this would be created in deposit)
1522
1505
  false, // to be checked and create in a setup tx in the UI (won't be the case for adjust anyway as this would be created in deposit)
1523
1506
  referrer,
1524
- currentSlot
1507
+ currentSlot,
1508
+ { includeScopeRefresh: true, scopeFeed: scopeFeed! }
1525
1509
  );
1526
1510
 
1527
1511
  // 4. Borrow tokens in borrow token reserve that will be swapped to repay flash loan
@@ -1532,37 +1516,43 @@ async function buildIncreaseLeverageIxns(
1532
1516
  owner,
1533
1517
  obligation,
1534
1518
  useV2Ixs,
1535
- undefined,
1536
1519
  0,
1537
1520
  false,
1538
1521
  false,
1539
1522
  false, // to be checked and create in a setup tx in the UI (won't be the case for adjust anyway as this would be created in deposit)
1540
1523
  false, // to be checked and create in a setup tx in the UI (won't be the case for adjust anyway as this would be created in deposit)
1541
1524
  referrer,
1542
- currentSlot
1525
+ currentSlot,
1526
+ { includeScopeRefresh: true, scopeFeed: scopeFeed! }
1543
1527
  );
1544
1528
 
1545
1529
  const swapInstructions = removeBudgetAndAtaIxns(swapQuoteIxs.swapIxs, []);
1546
1530
 
1547
1531
  const ixs = !collIsKtoken
1548
1532
  ? [
1549
- ...scopeRefreshIxn,
1550
1533
  ...budgetIxns,
1551
1534
  ...atasAndCreateIxns.map((x) => x.createAtaIx),
1552
1535
  ...[flashBorrowIxn],
1553
- ...KaminoAction.actionToIxs(depositAction),
1554
- ...KaminoAction.actionToIxs(borrowAction),
1536
+ ...depositAction.setupIxs,
1537
+ ...depositAction.lendingIxs,
1538
+ ...depositAction.cleanupIxs,
1539
+ ...borrowAction.setupIxs,
1540
+ ...borrowAction.lendingIxs,
1541
+ ...borrowAction.cleanupIxs,
1555
1542
  ...swapInstructions,
1556
1543
  ...[flashRepayIxn],
1557
1544
  ]
1558
1545
  : [
1559
- ...scopeRefreshIxn,
1560
1546
  ...budgetIxns,
1561
1547
  ...atasAndCreateIxns.map((x) => x.createAtaIx),
1562
1548
  ...[flashBorrowIxn],
1563
1549
  ...swapInstructions,
1564
- ...KaminoAction.actionToIxs(depositAction),
1565
- ...KaminoAction.actionToIxs(borrowAction),
1550
+ ...depositAction.setupIxs,
1551
+ ...depositAction.lendingIxs,
1552
+ ...depositAction.cleanupIxs,
1553
+ ...borrowAction.setupIxs,
1554
+ ...borrowAction.lendingIxs,
1555
+ ...borrowAction.cleanupIxs,
1566
1556
  ...[flashRepayIxn],
1567
1557
  ];
1568
1558
 
@@ -1582,7 +1572,7 @@ async function buildDecreaseLeverageIxns(
1582
1572
  currentSlot: number,
1583
1573
  calcs: AdjustLeverageCalcsResult,
1584
1574
  strategy: StrategyWithAddress | undefined,
1585
- scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
1575
+ scopeFeed: string | undefined,
1586
1576
  collIsKtoken: boolean,
1587
1577
  swapQuoteIxs: SwapIxs,
1588
1578
  budgetAndPriorityFeeIxns: TransactionInstruction[] | undefined,
@@ -1663,18 +1653,9 @@ async function buildDecreaseLeverageIxns(
1663
1653
  );
1664
1654
  }
1665
1655
 
1666
- const scopeRefreshIxn = await getScopeRefreshIx(
1667
- kaminoMarket,
1668
- collReserve!,
1669
- debtReserve!,
1670
- obligation,
1671
- scopeRefreshConfig
1672
- );
1673
-
1674
1656
  // 3. Flash borrow & repay amount to repay (debt)
1675
1657
  const { flashBorrowIxn, flashRepayIxn } = getFlashLoanInstructions({
1676
- borrowIxnIndex:
1677
- budgetIxns.length + atasAndCreateIxns.length + fillWsolAtaIxns.length + (scopeRefreshIxn.length > 0 ? 1 : 0),
1658
+ borrowIxnIndex: budgetIxns.length + atasAndCreateIxns.length + fillWsolAtaIxns.length,
1678
1659
  walletPublicKey: owner,
1679
1660
  lendingMarketAuthority: kaminoMarket.getLendingMarketAuthority(),
1680
1661
  lendingMarketAddress: kaminoMarket.getAddress(),
@@ -1688,6 +1669,7 @@ async function buildDecreaseLeverageIxns(
1688
1669
  });
1689
1670
 
1690
1671
  // 4. Actually do the repay of the flash borrowed amounts
1672
+ const scopeRefresh = scopeFeed ? { includeScopeRefresh: true, scopeFeed: scopeFeed } : undefined;
1691
1673
  const repayAction = await KaminoAction.buildRepayTxns(
1692
1674
  kaminoMarket,
1693
1675
  toLamports(Decimal.abs(calcs.adjustBorrowPosition), debtReserve!.stats.decimals).floor().toString(),
@@ -1695,7 +1677,6 @@ async function buildDecreaseLeverageIxns(
1695
1677
  owner,
1696
1678
  obligation,
1697
1679
  useV2Ixs,
1698
- undefined,
1699
1680
  currentSlot,
1700
1681
  undefined,
1701
1682
  0,
@@ -1703,7 +1684,8 @@ async function buildDecreaseLeverageIxns(
1703
1684
  false,
1704
1685
  false, // to be checked and create in a setup tx in the UI (won't be the case for adjust anyway as this would be created in deposit)
1705
1686
  false, // to be checked and create in a setup tx in the UI (won't be the case for adjust anyway as this would be created in deposit)
1706
- referrer
1687
+ referrer,
1688
+ scopeRefresh
1707
1689
  );
1708
1690
 
1709
1691
  // 6. Withdraw collateral (a little bit more to be able to pay for the slippage on swap)
@@ -1714,26 +1696,29 @@ async function buildDecreaseLeverageIxns(
1714
1696
  owner,
1715
1697
  obligation,
1716
1698
  useV2Ixs,
1717
- undefined,
1718
1699
  0,
1719
1700
  false,
1720
1701
  false,
1721
1702
  false, // to be checked and create in a setup tx in the UI (won't be the case for adjust anyway as this would be created in deposit)
1722
1703
  false, // to be checked and create in a setup tx in the UI (won't be the case for adjust anyway as this would be created in deposit)
1723
1704
  referrer,
1724
- currentSlot
1705
+ currentSlot,
1706
+ { includeScopeRefresh: true, scopeFeed: scopeFeed! }
1725
1707
  );
1726
1708
 
1727
1709
  const swapInstructions = removeBudgetAndAtaIxns(swapQuoteIxs.swapIxs, []);
1728
1710
 
1729
1711
  const ixns = [
1730
- ...scopeRefreshIxn,
1731
1712
  ...budgetIxns,
1732
1713
  ...atasAndCreateIxns.map((x) => x.createAtaIx),
1733
1714
  ...fillWsolAtaIxns,
1734
1715
  ...[flashBorrowIxn],
1735
- ...KaminoAction.actionToIxs(repayAction),
1736
- ...KaminoAction.actionToIxs(withdrawAction),
1716
+ ...repayAction.setupIxs,
1717
+ ...repayAction.lendingIxs,
1718
+ ...repayAction.cleanupIxs,
1719
+ ...withdrawAction.setupIxs,
1720
+ ...withdrawAction.lendingIxs,
1721
+ ...withdrawAction.cleanupIxs,
1737
1722
  ...swapInstructions,
1738
1723
  ...[flashRepayIxn],
1739
1724
  ...closeWsolAtaIxns,
@@ -1741,36 +1726,3 @@ async function buildDecreaseLeverageIxns(
1741
1726
 
1742
1727
  return ixns;
1743
1728
  }
1744
-
1745
- export const getScopeRefreshIx = async (
1746
- market: KaminoMarket,
1747
- collReserve: KaminoReserve,
1748
- debtReserve: KaminoReserve,
1749
- obligation: KaminoObligation | ObligationType | undefined,
1750
- scopeRefreshConfig: ScopePriceRefreshConfig | undefined
1751
- ): Promise<TransactionInstruction[]> => {
1752
- const allReserves =
1753
- obligation && isKaminoObligation(obligation)
1754
- ? new PublicKeySet<PublicKey>([
1755
- ...obligation.getDeposits().map((x) => x.reserveAddress),
1756
- ...obligation.getBorrows().map((x) => x.reserveAddress),
1757
- collReserve.address,
1758
- debtReserve.address,
1759
- ]).toArray()
1760
- : new PublicKeySet<PublicKey>([collReserve.address, debtReserve.address]).toArray();
1761
- const tokenIds = getTokenIdsForScopeRefresh(market, allReserves);
1762
-
1763
- const scopeRefreshIxns: TransactionInstruction[] = [];
1764
- if (tokenIds.length > 0 && scopeRefreshConfig) {
1765
- scopeRefreshIxns.push(
1766
- await scopeRefreshConfig.scope.refreshPriceListIx(
1767
- {
1768
- feed: scopeRefreshConfig.scopeFeed,
1769
- },
1770
- tokenIds
1771
- )
1772
- );
1773
- }
1774
-
1775
- return scopeRefreshIxns;
1776
- };
@@ -2,7 +2,7 @@ import { AddressLookupTableAccount, PublicKey, TransactionInstruction } from '@s
2
2
  import Decimal from 'decimal.js';
3
3
  import { KaminoMarket, KaminoObligation } from '../classes';
4
4
  import { InstructionsWithLookupTables, Kamino, StrategyWithAddress } from '@kamino-finance/kliquidity-sdk';
5
- import { ObligationType, ObligationTypeTag, ScopePriceRefreshConfig } from '../utils';
5
+ import { ObligationType, ObligationTypeTag } from '../utils';
6
6
 
7
7
  export type SwapQuoteProvider<QuoteResponse> = (
8
8
  inputs: SwapInputs,
@@ -82,7 +82,7 @@ export interface DepositWithLeverageSwapInputsProps<QuoteResponse> {
82
82
  selectedTokenMint: PublicKey;
83
83
  budgetAndPriorityFeeIxs?: TransactionInstruction[];
84
84
  kamino: Kamino | undefined;
85
- scopeRefreshConfig?: ScopePriceRefreshConfig;
85
+ scopeFeed: string | undefined;
86
86
  quoteBufferBps: Decimal;
87
87
  priceAinB: PriceAinBProvider;
88
88
  isKtoken: IsKtokenProvider;
@@ -143,7 +143,7 @@ export interface WithdrawWithLeverageSwapInputsProps<QuoteResponse> {
143
143
  selectedTokenMint: PublicKey;
144
144
  budgetAndPriorityFeeIxs?: TransactionInstruction[];
145
145
  kamino: Kamino | undefined;
146
- scopeRefreshConfig?: ScopePriceRefreshConfig;
146
+ scopeFeed: string | undefined;
147
147
  quoteBufferBps: Decimal;
148
148
  isKtoken: IsKtokenProvider;
149
149
  quoter: SwapQuoteProvider<QuoteResponse>;
@@ -196,7 +196,7 @@ export interface AdjustLeverageSwapInputsProps<QuoteResponse> {
196
196
  slippagePct: Decimal;
197
197
  budgetAndPriorityFeeIxs?: TransactionInstruction[];
198
198
  kamino: Kamino | undefined;
199
- scopeRefreshConfig?: ScopePriceRefreshConfig;
199
+ scopeFeed: string | undefined;
200
200
  quoteBufferBps: Decimal;
201
201
  priceAinB: PriceAinBProvider;
202
202
  isKtoken: IsKtokenProvider;
@@ -1,7 +1,7 @@
1
1
  import { PublicKey } from '@solana/web3.js';
2
2
  import { KaminoMarket, KaminoObligation } from '../classes';
3
3
 
4
- export type ObligationType = VanillaObligation | MultiplyObligation | LendingObligation | LeverageObligation;
4
+ export type ObligationType = VanillaObligation | MultiplyObligation | LendingObligation;
5
5
 
6
6
  export enum ObligationTypeTag {
7
7
  Vanilla = 0,
@@ -85,4 +85,3 @@ export const DEFAULT_MAX_COMPUTE_UNITS = 1_400_000;
85
85
  * Minimum initial deposit required for the initialization of a reserve
86
86
  */
87
87
  export const MIN_INITIAL_DEPOSIT = 100_000;
88
- export const MIN_VAULT_INITIAL_DEPOSIT = 1_000_000_000;
@@ -397,17 +397,59 @@ export function getReserveOracleConfigs(priceFeed: PriceFeed | null): {
397
397
  };
398
398
  }
399
399
 
400
- const ORACLE_TYPE_MAP = Object.fromEntries(
401
- Object.values(OracleType)
402
- // Filter for oracle types that have a discriminator property
403
- // This ensures we only include actual oracle implementations in the mapping
404
- // Pyth is used as a type assertion here but actually any oracle type with a discriminator will pass
405
- .filter((T): T is typeof OracleType.Pyth => 'discriminator' in T)
406
- .map((T) => [T.discriminator, T.name])
407
- );
408
-
409
400
  export function parseOracleType(type: number): string {
410
- return ORACLE_TYPE_MAP[type] || 'Unknown';
401
+ switch (type) {
402
+ case new OracleType.Pyth().discriminator:
403
+ return 'Pyth';
404
+ case new OracleType.SwitchboardV2().discriminator:
405
+ return 'SwitchboardV2';
406
+ case new OracleType.CToken().discriminator:
407
+ return 'CToken';
408
+ case new OracleType.KToken().discriminator:
409
+ return 'KToken';
410
+ case new OracleType.SplStake().discriminator:
411
+ return 'SplStake';
412
+ case new OracleType.PythEMA().discriminator:
413
+ return 'PythEMA';
414
+ case new OracleType.DeprecatedPlaceholder1().discriminator:
415
+ return 'DeprecatedPlaceholder1';
416
+ case new OracleType.DeprecatedPlaceholder2().discriminator:
417
+ return 'DeprecatedPlaceholder2';
418
+ case new OracleType.MsolStake().discriminator:
419
+ return 'MsolStake';
420
+ case new OracleType.KTokenToTokenA().discriminator:
421
+ return 'KTokenToTokenA';
422
+ case new OracleType.KTokenToTokenB().discriminator:
423
+ return 'KTokenToTokenB';
424
+ case new OracleType.JupiterLpFetch().discriminator:
425
+ return 'JupiterLpFetch';
426
+ case new OracleType.ScopeTwap().discriminator:
427
+ return 'ScopeTwap';
428
+ case new OracleType.OrcaWhirlpoolAtoB().discriminator:
429
+ return 'OrcaWhirlpoolAtoB';
430
+ case new OracleType.OrcaWhirlpoolBtoA().discriminator:
431
+ return 'OrcaWhirlpoolBtoA';
432
+ case new OracleType.RaydiumAmmV3AtoB().discriminator:
433
+ return 'RaydiumAmmV3AtoB';
434
+ case new OracleType.RaydiumAmmV3BtoA().discriminator:
435
+ return 'RaydiumAmmV3BtoA';
436
+ case new OracleType.JupiterLpCompute().discriminator:
437
+ return 'JupiterLpCompute';
438
+ case new OracleType.MeteoraDlmmAtoB().discriminator:
439
+ return 'MeteoraDlmmAtoB';
440
+ case new OracleType.MeteoraDlmmBtoA().discriminator:
441
+ return 'MeteoraDlmmBtoA';
442
+ case new OracleType.JupiterLpScope().discriminator:
443
+ return 'JupiterLpScope';
444
+ case new OracleType.PythPullBased().discriminator:
445
+ return 'PythPullBased';
446
+ case new OracleType.PythPullBasedEMA().discriminator:
447
+ return 'PythPullBasedEMA';
448
+ case new OracleType.FixedPrice().discriminator:
449
+ return 'FixedPrice';
450
+ default:
451
+ return 'Unknown';
452
+ }
411
453
  }
412
454
 
413
455
  export type MarketWithAddress = {
@@ -35,8 +35,8 @@ export type CandidatePrice = {
35
35
  valid: boolean;
36
36
  };
37
37
 
38
- export type ScopePriceRefreshConfig = {
39
- scope: Scope;
38
+ export type ScopeRefresh = {
39
+ includeScopeRefresh: boolean;
40
40
  scopeFeed: string;
41
41
  };
42
42
 
@@ -170,11 +170,10 @@ export function cacheOrGetPythPrices(
170
170
  const { price, exponent, conf: confidence, publishTime: timestamp, emaPrice } = priceMessage;
171
171
  if (price) {
172
172
  const px = new Decimal(price.toString()).div(10 ** Math.abs(exponent));
173
- const conf = new Decimal(confidence.toString());
174
173
  prices.spot = {
175
174
  price: px,
176
175
  timestamp: BigInt(timestamp.toString()),
177
- valid: validatePythPx(px, conf),
176
+ valid: validatePythPx(px, confidence.toNumber()),
178
177
  };
179
178
  }
180
179
  if (emaPrice !== undefined && emaPrice !== null) {
@@ -298,9 +297,9 @@ function isBetterPrice(current: CandidatePrice | undefined, next: CandidatePrice
298
297
  return next.timestamp > current.timestamp;
299
298
  }
300
299
 
301
- function validatePythPx(price: Decimal, confidence: Decimal): boolean {
302
- const conf50x = confidence.mul(CONFIDENCE_FACTOR);
303
- return !price.isZero() && price.gt(conf50x);
300
+ function validatePythPx(price: Decimal, confidence: number | undefined): boolean {
301
+ const conf50x = new Decimal(confidence || 0).mul(CONFIDENCE_FACTOR);
302
+ return price.gt(conf50x);
304
303
  }
305
304
 
306
305
  function validateSwitchboardV2Px(agg: any): boolean {