@kamino-finance/klend-sdk 2.13.9 → 2.13.10

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.
@@ -622,7 +622,6 @@ class KaminoAction {
622
622
  }, this.kaminoMarket.programId));
623
623
  }
624
624
  addBorrowIx() {
625
- var _a;
626
625
  this.lendingIxsLabels.push(`borrowObligationLiquidity`);
627
626
  const depositReservesList = this.getAdditionalDepositReservesList();
628
627
  const depositReserveAccountMetas = depositReservesList.map((reserve) => {
@@ -644,9 +643,10 @@ class KaminoAction {
644
643
  tokenProgram: this.reserve.getLiquidityTokenProgram(),
645
644
  instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
646
645
  }, this.kaminoMarket.programId);
647
- borrowIx.keys = ((_a = this.obligation) === null || _a === void 0 ? void 0 : _a.state.elevationGroup)
648
- ? borrowIx.keys.concat([...depositReserveAccountMetas])
649
- : borrowIx.keys;
646
+ borrowIx.keys =
647
+ this.obligation.state.elevationGroup > 0 || this.obligation.refreshedStats.potentialElevationGroupUpdate > 0
648
+ ? borrowIx.keys.concat([...depositReserveAccountMetas])
649
+ : borrowIx.keys;
650
650
  this.lendingIxs.push(borrowIx);
651
651
  }
652
652
  addDepositAndBorrowIx() {
@@ -791,7 +791,6 @@ class KaminoAction {
791
791
  }
792
792
  addRepayIx() {
793
793
  return __awaiter(this, void 0, void 0, function* () {
794
- var _a;
795
794
  this.lendingIxsLabels.push(`repayObligationLiquidity(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`);
796
795
  const depositReservesList = this.getAdditionalDepositReservesList();
797
796
  const depositReserveAccountMetas = depositReservesList.map((reserve) => {
@@ -811,13 +810,12 @@ class KaminoAction {
811
810
  instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
812
811
  }, this.kaminoMarket.programId);
813
812
  repayIx.keys =
814
- ((_a = this.obligation) === null || _a === void 0 ? void 0 : _a.state.elevationGroup) !== 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
813
+ this.obligation.state.elevationGroup > 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
815
814
  this.lendingIxs.push(repayIx);
816
815
  });
817
816
  }
818
817
  addLiquidateIx() {
819
818
  return __awaiter(this, arguments, void 0, function* (maxAllowedLtvOverridePercent = 0) {
820
- var _a;
821
819
  this.lendingIxsLabels.push(`liquidateObligationAndRedeemReserveCollateral`);
822
820
  if (!this.outflowReserve) {
823
821
  throw Error(`Withdraw reserve during liquidation is not defined`);
@@ -857,7 +855,7 @@ class KaminoAction {
857
855
  instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
858
856
  }, this.kaminoMarket.programId);
859
857
  liquidateIx.keys =
860
- ((_a = this.obligation) === null || _a === void 0 ? void 0 : _a.state.elevationGroup) !== 0
858
+ this.obligation.state.elevationGroup > 0
861
859
  ? liquidateIx.keys.concat([...depositReserveAccountMetas])
862
860
  : liquidateIx.keys;
863
861
  this.lendingIxs.push(liquidateIx);
@@ -1033,12 +1031,22 @@ class KaminoAction {
1033
1031
  throw new Error(`Could not decide on refresh farm for action ${action}`);
1034
1032
  }
1035
1033
  }
1036
- if (action === 'depositAndBorrow' && requestElevationGroup) {
1037
- const groupsColl = this.reserve.state.config.elevationGroups;
1038
- const groupsDebt = this.outflowReserve.state.config.elevationGroups;
1034
+ if ((action === 'depositAndBorrow' || action === 'borrow') && requestElevationGroup) {
1035
+ let emodeGroupsDebt = this.reserve.state.config.elevationGroups;
1036
+ let emodeGroupsColl = this.reserve.state.config.elevationGroups;
1037
+ let debtReserve = this.reserve.address;
1038
+ if (action === 'depositAndBorrow') {
1039
+ emodeGroupsDebt = this.outflowReserve.state.config.elevationGroups;
1040
+ debtReserve = this.outflowReserve.address;
1041
+ }
1042
+ else if (action === 'borrow') {
1043
+ const depositReserve = this.obligation.state.deposits.find((x) => !x.depositReserve.equals(web3_js_1.PublicKey.default)).depositReserve;
1044
+ const collReserve = this.kaminoMarket.getReserveByAddress(depositReserve);
1045
+ emodeGroupsColl = collReserve.state.config.elevationGroups;
1046
+ }
1039
1047
  const groups = this.kaminoMarket.state.elevationGroups;
1040
- const commonElevationGroups = [...groupsColl].filter((item) => groupsDebt.includes(item) && item !== 0 && groups[item - 1].debtReserve.equals(this.outflowReserve.address));
1041
- console.log('Groups of coll reserve', groupsColl, 'Groups of debt reserve', groupsDebt, 'Common groups', commonElevationGroups);
1048
+ const commonElevationGroups = [...emodeGroupsColl].filter((item) => emodeGroupsDebt.includes(item) && item !== 0 && groups[item - 1].debtReserve.equals(debtReserve));
1049
+ console.log('Groups of coll reserve', emodeGroupsColl, 'Groups of debt reserve', emodeGroupsDebt, 'Common groups', commonElevationGroups);
1042
1050
  if (commonElevationGroups.length === 0) {
1043
1051
  console.log('No common elevation groups found, staying with default');
1044
1052
  }
@@ -1050,8 +1058,13 @@ class KaminoAction {
1050
1058
  });
1051
1059
  const eModeGroup = groups.find((group) => group.id === eModeGroupWithMaxLtvAndDebtReserve).id;
1052
1060
  console.log('Setting eModeGroup to', eModeGroup);
1061
+ let addToSetupIxs = false;
1053
1062
  if (eModeGroup !== 0 && eModeGroup !== ((_a = this.obligation) === null || _a === void 0 ? void 0 : _a.state.elevationGroup)) {
1054
- this.addRequestElevationIx(eModeGroup, false);
1063
+ if (action === 'borrow') {
1064
+ this.obligation.refreshedStats.potentialElevationGroupUpdate = eModeGroup;
1065
+ addToSetupIxs = true;
1066
+ }
1067
+ this.addRequestElevationIx(eModeGroup, addToSetupIxs);
1055
1068
  this.addRefreshReserveIxs(allReservesExcludingCurrent, addToSetupIxs);
1056
1069
  this.addRefreshReserveIxs(currentReserveAddresses.toArray(), addToSetupIxs);
1057
1070
  this.addRefreshObligationIx(addToSetupIxs);