@kamino-finance/klend-sdk 7.3.10-beta.0 → 7.3.10-beta.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 (131) hide show
  1. package/dist/classes/action.d.ts +21 -91
  2. package/dist/classes/action.d.ts.map +1 -1
  3. package/dist/classes/action.js +152 -139
  4. package/dist/classes/action.js.map +1 -1
  5. package/dist/classes/actionTypes.d.ts +310 -0
  6. package/dist/classes/actionTypes.d.ts.map +1 -0
  7. package/dist/classes/actionTypes.js +3 -0
  8. package/dist/classes/actionTypes.js.map +1 -0
  9. package/dist/classes/configItems.d.ts +1 -6
  10. package/dist/classes/configItems.d.ts.map +1 -1
  11. package/dist/classes/configItems.js +1 -93
  12. package/dist/classes/configItems.js.map +1 -1
  13. package/dist/classes/farm_utils.d.ts +1 -1
  14. package/dist/classes/farm_utils.d.ts.map +1 -1
  15. package/dist/classes/farm_utils.js +3 -1
  16. package/dist/classes/farm_utils.js.map +1 -1
  17. package/dist/classes/market.d.ts +15 -10
  18. package/dist/classes/market.d.ts.map +1 -1
  19. package/dist/classes/market.js +51 -28
  20. package/dist/classes/market.js.map +1 -1
  21. package/dist/classes/obligation.d.ts +11 -11
  22. package/dist/classes/obligation.d.ts.map +1 -1
  23. package/dist/classes/obligation.js +56 -56
  24. package/dist/classes/obligation.js.map +1 -1
  25. package/dist/classes/obligationOrder.d.ts.map +1 -1
  26. package/dist/classes/obligationOrder.js +6 -3
  27. package/dist/classes/obligationOrder.js.map +1 -1
  28. package/dist/classes/reserve.d.ts +7 -3
  29. package/dist/classes/reserve.d.ts.map +1 -1
  30. package/dist/classes/reserve.js +31 -43
  31. package/dist/classes/reserve.js.map +1 -1
  32. package/dist/classes/shared.d.ts +3 -2
  33. package/dist/classes/shared.d.ts.map +1 -1
  34. package/dist/classes/vault.d.ts +28 -1
  35. package/dist/classes/vault.d.ts.map +1 -1
  36. package/dist/classes/vault.js +103 -6
  37. package/dist/classes/vault.js.map +1 -1
  38. package/dist/classes/vault_types.d.ts +2 -1
  39. package/dist/classes/vault_types.d.ts.map +1 -1
  40. package/dist/client/commands/borrow.d.ts +1 -1
  41. package/dist/client/commands/borrow.d.ts.map +1 -1
  42. package/dist/client/commands/borrow.js +11 -2
  43. package/dist/client/commands/borrow.js.map +1 -1
  44. package/dist/client/commands/deposit.d.ts +1 -1
  45. package/dist/client/commands/deposit.d.ts.map +1 -1
  46. package/dist/client/commands/deposit.js +11 -2
  47. package/dist/client/commands/deposit.js.map +1 -1
  48. package/dist/client/commands/printReserve.d.ts +1 -1
  49. package/dist/client/commands/printReserve.d.ts.map +1 -1
  50. package/dist/client/commands/printReserve.js +2 -4
  51. package/dist/client/commands/printReserve.js.map +1 -1
  52. package/dist/client/commands/repay.d.ts +1 -1
  53. package/dist/client/commands/repay.d.ts.map +1 -1
  54. package/dist/client/commands/repay.js +12 -2
  55. package/dist/client/commands/repay.js.map +1 -1
  56. package/dist/client/commands/withdraw.d.ts +1 -1
  57. package/dist/client/commands/withdraw.d.ts.map +1 -1
  58. package/dist/client/commands/withdraw.js +11 -2
  59. package/dist/client/commands/withdraw.js.map +1 -1
  60. package/dist/lending_operations/repay_with_collateral_calcs.d.ts +1 -1
  61. package/dist/lending_operations/repay_with_collateral_calcs.d.ts.map +1 -1
  62. package/dist/lending_operations/repay_with_collateral_calcs.js +2 -2
  63. package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
  64. package/dist/lending_operations/repay_with_collateral_operations.d.ts +4 -4
  65. package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
  66. package/dist/lending_operations/repay_with_collateral_operations.js +43 -10
  67. package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
  68. package/dist/lending_operations/swap_collateral_operations.d.ts +4 -4
  69. package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
  70. package/dist/lending_operations/swap_collateral_operations.js +40 -21
  71. package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
  72. package/dist/leverage/operations.d.ts +6 -6
  73. package/dist/leverage/operations.d.ts.map +1 -1
  74. package/dist/leverage/operations.js +167 -52
  75. package/dist/leverage/operations.js.map +1 -1
  76. package/dist/leverage/types.d.ts +2 -2
  77. package/dist/leverage/types.d.ts.map +1 -1
  78. package/dist/manager/client_kamino_manager.js +0 -2
  79. package/dist/manager/client_kamino_manager.js.map +1 -1
  80. package/dist/obligation_orders/price_based.js +5 -3
  81. package/dist/obligation_orders/price_based.js.map +1 -1
  82. package/dist/utils/Logger.d.ts +14 -0
  83. package/dist/utils/Logger.d.ts.map +1 -0
  84. package/dist/utils/Logger.js +12 -0
  85. package/dist/utils/Logger.js.map +1 -0
  86. package/dist/utils/ObligationType.d.ts +33 -1
  87. package/dist/utils/ObligationType.d.ts.map +1 -1
  88. package/dist/utils/ObligationType.js +81 -2
  89. package/dist/utils/ObligationType.js.map +1 -1
  90. package/dist/utils/api.d.ts +13 -4
  91. package/dist/utils/api.d.ts.map +1 -1
  92. package/dist/utils/api.js +33 -31
  93. package/dist/utils/api.js.map +1 -1
  94. package/dist/utils/userMetadata.d.ts +2 -2
  95. package/dist/utils/userMetadata.d.ts.map +1 -1
  96. package/dist/utils/userMetadata.js +49 -25
  97. package/dist/utils/userMetadata.js.map +1 -1
  98. package/dist/utils/validations.d.ts +1 -0
  99. package/dist/utils/validations.d.ts.map +1 -1
  100. package/dist/utils/validations.js +5 -0
  101. package/dist/utils/validations.js.map +1 -1
  102. package/package.json +1 -1
  103. package/src/classes/action.ts +346 -372
  104. package/src/classes/actionTypes.ts +295 -0
  105. package/src/classes/configItems.ts +1 -99
  106. package/src/classes/farm_utils.ts +5 -1
  107. package/src/classes/market.ts +76 -33
  108. package/src/classes/obligation.ts +62 -59
  109. package/src/classes/obligationOrder.ts +6 -3
  110. package/src/classes/reserve.ts +118 -122
  111. package/src/classes/shared.ts +4 -2
  112. package/src/classes/vault.ts +160 -7
  113. package/src/classes/vault_types.ts +2 -1
  114. package/src/client/client.ts +17 -18
  115. package/src/client/commands/borrow.ts +10 -9
  116. package/src/client/commands/deposit.ts +10 -9
  117. package/src/client/commands/printReserve.ts +2 -4
  118. package/src/client/commands/repay.ts +11 -10
  119. package/src/client/commands/withdraw.ts +15 -9
  120. package/src/lending_operations/repay_with_collateral_calcs.ts +3 -4
  121. package/src/lending_operations/repay_with_collateral_operations.ts +40 -38
  122. package/src/lending_operations/swap_collateral_operations.ts +47 -41
  123. package/src/leverage/operations.ts +168 -129
  124. package/src/leverage/types.ts +2 -2
  125. package/src/manager/client_kamino_manager.ts +0 -2
  126. package/src/obligation_orders/price_based.ts +7 -5
  127. package/src/utils/Logger.ts +14 -0
  128. package/src/utils/ObligationType.ts +92 -1
  129. package/src/utils/api.ts +56 -33
  130. package/src/utils/userMetadata.ts +64 -30
  131. package/src/utils/validations.ts +5 -0
@@ -337,31 +337,33 @@ export class KaminoObligation {
337
337
  return this.deposits.get(reserve);
338
338
  }
339
339
 
340
- getBorrowByMint(mint: Address): Position | undefined {
340
+ getBorrowsByMint(mint: Address): Position[] {
341
+ const positions: Position[] = [];
341
342
  for (const value of this.borrows.values()) {
342
343
  if (value.mintAddress === mint) {
343
- return value;
344
+ positions.push(value);
344
345
  }
345
346
  }
346
- return undefined;
347
+ return positions;
347
348
  }
348
349
 
349
350
  getBorrowAmountByReserve(reserve: KaminoReserve): Decimal {
350
- const amountLamports = this.getBorrowByMint(reserve.getLiquidityMint())?.amount ?? new Decimal(0);
351
+ const amountLamports = this.getBorrowByReserve(reserve.address)?.amount ?? new Decimal(0);
351
352
  return amountLamports.div(reserve.getMintFactor());
352
353
  }
353
354
 
354
- getDepositByMint(mint: Address): Position | undefined {
355
+ getDepositsByMint(mint: Address): Position[] {
356
+ const positions: Position[] = [];
355
357
  for (const value of this.deposits.values()) {
356
358
  if (value.mintAddress === mint) {
357
- return value;
359
+ positions.push(value);
358
360
  }
359
361
  }
360
- return undefined;
362
+ return positions;
361
363
  }
362
364
 
363
365
  getDepositAmountByReserve(reserve: KaminoReserve): Decimal {
364
- const amountLamports = this.getDepositByMint(reserve.getLiquidityMint())?.amount ?? new Decimal(0);
366
+ const amountLamports = this.getDepositByReserve(reserve.address)?.amount ?? new Decimal(0);
365
367
  return amountLamports.div(reserve.getMintFactor());
366
368
  }
367
369
 
@@ -595,8 +597,8 @@ export class KaminoObligation {
595
597
  amountCollateral?: Decimal;
596
598
  amountDebt?: Decimal;
597
599
  action: ActionType;
598
- mintCollateral?: Address;
599
- mintDebt?: Address;
600
+ collateralReserveAddress?: Address;
601
+ debtReserveAddress?: Address;
600
602
  market: KaminoMarket;
601
603
  reserves: Map<Address, KaminoReserve>;
602
604
  slot: Slot;
@@ -606,18 +608,15 @@ export class KaminoObligation {
606
608
  deposits: Map<Address, Position>;
607
609
  borrows: Map<Address, Position>;
608
610
  } {
609
- const { amountCollateral, amountDebt, action, mintCollateral, mintDebt, market } = params;
611
+ const { amountCollateral, amountDebt, action, collateralReserveAddress, debtReserveAddress, market } = params;
610
612
  let newStats = { ...this.refreshedStats };
611
613
 
612
- const collateralReservePk = mintCollateral ? market.getReserveByMint(mintCollateral)!.address : undefined;
613
- const debtReservePk = mintDebt ? market.getReserveByMint(mintDebt)!.address : undefined;
614
-
615
614
  const additionalReserves: Address[] = [];
616
- if (collateralReservePk !== undefined) {
617
- additionalReserves.push(collateralReservePk);
615
+ if (collateralReserveAddress !== undefined) {
616
+ additionalReserves.push(collateralReserveAddress);
618
617
  }
619
- if (debtReservePk !== undefined) {
620
- additionalReserves.push(debtReservePk);
618
+ if (debtReserveAddress !== undefined) {
619
+ additionalReserves.push(debtReserveAddress);
621
620
  }
622
621
 
623
622
  const { collateralExchangeRates } = KaminoObligation.getRatesForObligation(
@@ -636,8 +635,8 @@ export class KaminoObligation {
636
635
  // so we have to recalculate the entire position, not just an updated deposit or borrow
637
636
  // as both LTVs and borrow factors can change, affecting all calcs
638
637
 
639
- const debtReserveCumulativeBorrowRate = mintDebt
640
- ? market.getReserveByMint(mintDebt)!.getCumulativeBorrowRate()
638
+ const debtReserveCumulativeBorrowRate = debtReserveAddress
639
+ ? market.getExistingReserveByAddress(debtReserveAddress).getCumulativeBorrowRate()
641
640
  : undefined;
642
641
 
643
642
  let newObligationDeposits = this.state.deposits;
@@ -645,13 +644,13 @@ export class KaminoObligation {
645
644
 
646
645
  switch (action) {
647
646
  case 'deposit': {
648
- if (amountCollateral === undefined || mintCollateral === undefined) {
649
- throw Error('amountCollateral & mintCollateral are required for deposit action');
647
+ if (amountCollateral === undefined || collateralReserveAddress === undefined) {
648
+ throw Error('amountCollateral & collateralReserveAddress are required for deposit action');
650
649
  }
651
650
  newObligationDeposits = this.simulateDepositChange(
652
651
  this.state.deposits,
653
652
  {
654
- reserveAddress: collateralReservePk!,
653
+ reserveAddress: collateralReserveAddress,
655
654
  amountChangeLamports: amountCollateral,
656
655
  },
657
656
  collateralExchangeRates
@@ -659,14 +658,14 @@ export class KaminoObligation {
659
658
  break;
660
659
  }
661
660
  case 'borrow': {
662
- if (amountDebt === undefined || mintDebt === undefined) {
663
- throw Error('amountDebt & mintDebt are required for borrow action');
661
+ if (amountDebt === undefined || debtReserveAddress === undefined) {
662
+ throw Error('amountDebt & debtReserveAddress are required for borrow action');
664
663
  }
665
664
 
666
665
  newObligationBorrows = this.simulateBorrowChange(
667
666
  this.state.borrows,
668
667
  {
669
- reserveAddress: debtReservePk!,
668
+ reserveAddress: debtReserveAddress,
670
669
  amountChangeLamports: amountDebt,
671
670
  },
672
671
  debtReserveCumulativeBorrowRate!
@@ -674,14 +673,14 @@ export class KaminoObligation {
674
673
  break;
675
674
  }
676
675
  case 'repay': {
677
- if (amountDebt === undefined || mintDebt === undefined) {
678
- throw Error('amountDebt & mintDebt are required for repay action');
676
+ if (amountDebt === undefined || debtReserveAddress === undefined) {
677
+ throw Error('amountDebt & debtReserveAddress are required for repay action');
679
678
  }
680
679
 
681
680
  newObligationBorrows = this.simulateBorrowChange(
682
681
  this.state.borrows,
683
682
  {
684
- reserveAddress: debtReservePk!,
683
+ reserveAddress: debtReserveAddress,
685
684
  amountChangeLamports: amountDebt.neg(),
686
685
  },
687
686
  debtReserveCumulativeBorrowRate!
@@ -691,13 +690,13 @@ export class KaminoObligation {
691
690
  }
692
691
 
693
692
  case 'withdraw': {
694
- if (amountCollateral === undefined || mintCollateral === undefined) {
695
- throw Error('amountCollateral & mintCollateral are required for withdraw action');
693
+ if (amountCollateral === undefined || collateralReserveAddress === undefined) {
694
+ throw Error('amountCollateral & collateralReserveAddress are required for withdraw action');
696
695
  }
697
696
  newObligationDeposits = this.simulateDepositChange(
698
697
  this.state.deposits,
699
698
  {
700
- reserveAddress: collateralReservePk!,
699
+ reserveAddress: collateralReserveAddress,
701
700
  amountChangeLamports: amountCollateral.neg(),
702
701
  },
703
702
  collateralExchangeRates
@@ -708,15 +707,17 @@ export class KaminoObligation {
708
707
  if (
709
708
  amountCollateral === undefined ||
710
709
  amountDebt === undefined ||
711
- mintCollateral === undefined ||
712
- mintDebt === undefined
710
+ collateralReserveAddress === undefined ||
711
+ debtReserveAddress === undefined
713
712
  ) {
714
- throw Error('amountColl & amountDebt & mintCollateral & mintDebt are required for depositAndBorrow action');
713
+ throw Error(
714
+ 'amountColl & amountDebt & collateralReserveAddress & debtReserveAddress are required for depositAndBorrow action'
715
+ );
715
716
  }
716
717
  newObligationDeposits = this.simulateDepositChange(
717
718
  this.state.deposits,
718
719
  {
719
- reserveAddress: collateralReservePk!,
720
+ reserveAddress: collateralReserveAddress,
720
721
  amountChangeLamports: amountCollateral,
721
722
  },
722
723
  collateralExchangeRates
@@ -725,7 +726,7 @@ export class KaminoObligation {
725
726
  newObligationBorrows = this.simulateBorrowChange(
726
727
  this.state.borrows,
727
728
  {
728
- reserveAddress: debtReservePk!,
729
+ reserveAddress: debtReserveAddress,
729
730
  amountChangeLamports: amountDebt,
730
731
  },
731
732
  debtReserveCumulativeBorrowRate!
@@ -736,15 +737,17 @@ export class KaminoObligation {
736
737
  if (
737
738
  amountCollateral === undefined ||
738
739
  amountDebt === undefined ||
739
- mintCollateral === undefined ||
740
- mintDebt === undefined
740
+ collateralReserveAddress === undefined ||
741
+ debtReserveAddress === undefined
741
742
  ) {
742
- throw Error('amountColl & amountDebt & mintCollateral & mintDebt are required for repayAndWithdraw action');
743
+ throw Error(
744
+ 'amountColl & amountDebt & collateralReserveAddress & debtReserveAddress are required for repayAndWithdraw action'
745
+ );
743
746
  }
744
747
  newObligationDeposits = this.simulateDepositChange(
745
748
  this.state.deposits,
746
749
  {
747
- reserveAddress: collateralReservePk!,
750
+ reserveAddress: collateralReserveAddress,
748
751
  amountChangeLamports: amountCollateral.neg(),
749
752
  },
750
753
  collateralExchangeRates
@@ -752,7 +755,7 @@ export class KaminoObligation {
752
755
  newObligationBorrows = this.simulateBorrowChange(
753
756
  this.state.borrows,
754
757
  {
755
- reserveAddress: debtReservePk!,
758
+ reserveAddress: debtReserveAddress,
756
759
  amountChangeLamports: amountDebt.neg(),
757
760
  },
758
761
  debtReserveCumulativeBorrowRate!
@@ -1186,7 +1189,7 @@ export class KaminoObligation {
1186
1189
  not a reserve-specific, caps-specific, liquidity-specific function.
1187
1190
 
1188
1191
  * @param market - The KaminoMarket instance.
1189
- * @param liquidityMint - The liquidity mint Address.
1192
+ * @param liquidityReserveAddress - The liquidity reserve Address.
1190
1193
  * @param slot - The slot number.
1191
1194
  * @param elevationGroup - The elevation group number (default: this.state.elevationGroup).
1192
1195
  * @returns The borrow power as a Decimal.
@@ -1194,11 +1197,11 @@ export class KaminoObligation {
1194
1197
  */
1195
1198
  getBorrowPower(
1196
1199
  market: KaminoMarket,
1197
- liquidityMint: Address,
1200
+ liquidityReserveAddress: Address,
1198
1201
  slot: Slot,
1199
1202
  elevationGroup: number = this.state.elevationGroup
1200
1203
  ): Decimal {
1201
- const reserve = market.getReserveByMint(liquidityMint);
1204
+ const reserve = market.getReserveByAddress(liquidityReserveAddress);
1202
1205
  if (!reserve) {
1203
1206
  throw new Error('Reserve not found');
1204
1207
  }
@@ -1265,7 +1268,7 @@ export class KaminoObligation {
1265
1268
  and a specific reserve, until it hits max LTV and given available liquidity and caps.
1266
1269
 
1267
1270
  * @param market - The KaminoMarket instance.
1268
- * @param liquidityMint - The liquidity mint Address.
1271
+ * @param liquidityReserveAddress - The liquidity reserve Address.
1269
1272
  * @param slot - The slot number.
1270
1273
  * @param elevationGroup - The elevation group number (default: this.state.elevationGroup).
1271
1274
  * @returns The maximum borrow amount as a Decimal.
@@ -1273,11 +1276,11 @@ export class KaminoObligation {
1273
1276
  */
1274
1277
  getMaxBorrowAmountV2(
1275
1278
  market: KaminoMarket,
1276
- liquidityMint: Address,
1279
+ liquidityReserveAddress: Address,
1277
1280
  slot: Slot,
1278
1281
  elevationGroup: number = this.state.elevationGroup
1279
1282
  ): Decimal {
1280
- const reserve = market.getReserveByMint(liquidityMint);
1283
+ const reserve = market.getReserveByAddress(liquidityReserveAddress);
1281
1284
  if (!reserve) {
1282
1285
  throw new Error('Reserve not found');
1283
1286
  }
@@ -1287,7 +1290,7 @@ export class KaminoObligation {
1287
1290
  [elevationGroup],
1288
1291
  Array.from(this.deposits.keys())
1289
1292
  )[0];
1290
- const maxBorrowAmount = this.getBorrowPower(market, liquidityMint, slot, elevationGroup);
1293
+ const maxBorrowAmount = this.getBorrowPower(market, liquidityReserveAddress, slot, elevationGroup);
1291
1294
 
1292
1295
  if (elevationGroup === this.state.elevationGroup) {
1293
1296
  return Decimal.min(maxBorrowAmount, liquidityAvailable);
@@ -1304,7 +1307,7 @@ export class KaminoObligation {
1304
1307
  the new borrow power after the deposit, without overriding the obligation itself.
1305
1308
 
1306
1309
  * @param market - The KaminoMarket instance.
1307
- * @param liquidityMint - The liquidity mint Address.
1310
+ * @param liquidityReserveAddress - The liquidity reserve Address.
1308
1311
  * @param slot - The slot number.
1309
1312
  * @param elevationGroup - The elevation group number (default: this.state.elevationGroup).
1310
1313
  * @returns The maximum borrow amount as a Decimal.
@@ -1312,7 +1315,7 @@ export class KaminoObligation {
1312
1315
  */
1313
1316
  getMaxBorrowAmountV2WithDeposit(
1314
1317
  market: KaminoMarket,
1315
- liquidityMint: Address,
1318
+ liquidityReserveAddress: Address,
1316
1319
  slot: Slot,
1317
1320
  elevationGroup: number = this.state.elevationGroup,
1318
1321
  depositAmountLamports: Decimal,
@@ -1326,7 +1329,7 @@ export class KaminoObligation {
1326
1329
  ];
1327
1330
  const obligationWithDeposit = this.withPositionChanges(market, slot, depositChanges);
1328
1331
 
1329
- return obligationWithDeposit.getMaxBorrowAmountV2(market, liquidityMint, slot, elevationGroup);
1332
+ return obligationWithDeposit.getMaxBorrowAmountV2(market, liquidityReserveAddress, slot, elevationGroup);
1330
1333
  }
1331
1334
 
1332
1335
  /*
@@ -1406,11 +1409,11 @@ export class KaminoObligation {
1406
1409
  /* Deprecated function, also broken */
1407
1410
  getMaxBorrowAmount(
1408
1411
  market: KaminoMarket,
1409
- liquidityMint: Address,
1412
+ liquidityReserveAddress: Address,
1410
1413
  slot: Slot,
1411
1414
  requestElevationGroup: boolean
1412
1415
  ): Decimal {
1413
- const reserve = market.getReserveByMint(liquidityMint);
1416
+ const reserve = market.getReserveByAddress(liquidityReserveAddress);
1414
1417
 
1415
1418
  if (!reserve) {
1416
1419
  throw new Error('Reserve not found');
@@ -1525,8 +1528,8 @@ export class KaminoObligation {
1525
1528
  return Decimal.max(new Decimal(0), maxBorrowAmount);
1526
1529
  }
1527
1530
 
1528
- getMaxWithdrawAmount(market: KaminoMarket, tokenMint: Address, slot: Slot): Decimal {
1529
- const depositReserve = market.getReserveByMint(tokenMint);
1531
+ getMaxWithdrawAmount(market: KaminoMarket, depositReserveAddress: Address, slot: Slot): Decimal {
1532
+ const depositReserve = market.getReserveByAddress(depositReserveAddress);
1530
1533
 
1531
1534
  if (!depositReserve) {
1532
1535
  throw new Error('Reserve not found');
@@ -1585,7 +1588,7 @@ export class KaminoObligation {
1585
1588
  * the new withdraw power after the repay, without overriding the obligation itself.
1586
1589
  *
1587
1590
  * @param market - The KaminoMarket instance.
1588
- * @param tokenMint - The liquidity mint Address.
1591
+ * @param depositReserveAddress - The liquidity (deposit) reserve Address.
1589
1592
  * @param slot - The slot number.
1590
1593
  * @param repayAmountLamports - The amount to repay in lamports (use U64_MAX for full repay).
1591
1594
  * @param repayReserveAddress - The reserve address of the borrow being repaid.
@@ -1594,7 +1597,7 @@ export class KaminoObligation {
1594
1597
  */
1595
1598
  getMaxWithdrawAmountWithRepay(
1596
1599
  market: KaminoMarket,
1597
- tokenMint: Address,
1600
+ depositReserveAddress: Address,
1598
1601
  slot: Slot,
1599
1602
  repayAmountLamports: Decimal,
1600
1603
  repayReserveAddress: Address
@@ -1615,7 +1618,7 @@ export class KaminoObligation {
1615
1618
  ];
1616
1619
  const obligationWithRepay = this.withPositionChanges(market, slot, undefined, borrowChanges);
1617
1620
 
1618
- return obligationWithRepay.getMaxWithdrawAmount(market, tokenMint, slot);
1621
+ return obligationWithRepay.getMaxWithdrawAmount(market, depositReserveAddress, slot);
1619
1622
  }
1620
1623
 
1621
1624
  getObligationLiquidityByReserve(reserveAddress: Address): ObligationLiquidity {
@@ -169,6 +169,7 @@ export class DeleverageDebtAmount implements OrderOpportunity {
169
169
  return {
170
170
  mint: singleBorrow.mintAddress,
171
171
  amount: Decimal.min(singleBorrow.amount, this.amount),
172
+ reserveAddress: singleBorrow.reserveAddress,
172
173
  };
173
174
  }
174
175
  }
@@ -204,6 +205,7 @@ export class DeleverageAllDebt implements OrderOpportunity {
204
205
  return {
205
206
  mint: highestValueBorrow.mintAddress,
206
207
  amount: highestValueBorrow.amount,
208
+ reserveAddress: highestValueBorrow.reserveAddress,
207
209
  };
208
210
  }
209
211
  }
@@ -310,7 +312,7 @@ export class KaminoObligationOrder {
310
312
  return undefined; // condition not met - cannot execute
311
313
  }
312
314
  const maxRepay = this.opportunity.getMaxRepay(obligation.getBorrows());
313
- const repayBorrow = obligation.getBorrowByMint(maxRepay.mint)!;
315
+ const repayBorrow = obligation.getBorrowByReserve(maxRepay.reserveAddress)!;
314
316
  const maxRepayValue = tokenAmountToValue(maxRepay, repayBorrow);
315
317
  const executionBonusRate = this.calculateExecutionBonusRate(conditionHit, obligation);
316
318
  const executionBonusFactor = new Decimal(1).add(executionBonusRate);
@@ -342,7 +344,7 @@ export class KaminoObligationOrder {
342
344
  return valueComparison;
343
345
  }
344
346
  // Just for deterministic selection in case of multiple equally-good deposits: pick the one with lower mint pubkey (mostly for test stability purposes)
345
- return leftDeposit.mintAddress.localeCompare(rightDeposit.mintAddress);
347
+ return leftDeposit.reserveAddress.localeCompare(rightDeposit.reserveAddress);
346
348
  })
347
349
  .at(-1)!;
348
350
  const actualRepayValue = actualWithdrawValue.div(executionBonusFactor);
@@ -505,7 +507,7 @@ export type AvailableOrderExecution = {
505
507
  // Internal calculation functions:
506
508
 
507
509
  function tokenAmountToValue(tokenAmount: TokenAmount, position: Position): Decimal {
508
- if (tokenAmount.mint !== position.mintAddress) {
510
+ if (tokenAmount.reserveAddress !== position.reserveAddress) {
509
511
  throw new Error(`Value of token amount ${tokenAmount} cannot be computed using data from ${position}`);
510
512
  }
511
513
  return tokenAmount.amount.mul(position.marketValueRefreshed).div(position.amount);
@@ -516,6 +518,7 @@ function valueToTokenAmount(value: Decimal, position: Position): TokenAmount {
516
518
  return {
517
519
  amount: roundNearest(fractionalAmount),
518
520
  mint: position.mintAddress,
521
+ reserveAddress: position.reserveAddress,
519
522
  };
520
523
  }
521
524