impermax-sdk 1.1.72 → 1.1.74

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.
@@ -94,7 +94,7 @@ class OnchainAccountBorrowable extends onchainAccountPoolToken_1.default {
94
94
  let bestAmount = 0;
95
95
  for (let i = 0; i < 1000; i++) {
96
96
  const jump = Math.abs(borrowAmount - borrowAmountPrev) / 2;
97
- if (jump / availableCash < 0.001)
97
+ if (jump / availableCash < 1e-9)
98
98
  break;
99
99
  borrowAmountPrev = borrowAmount;
100
100
  const changeCollateral = 0;
@@ -108,6 +108,7 @@ class OnchainAccountBorrowable extends onchainAccountPoolToken_1.default {
108
108
  bestAmount = borrowAmount;
109
109
  borrowAmount += jump;
110
110
  }
111
+ console.log("getMaxBorrowable", liqPriceA, twapPrice, liqPriceB, bestAmount, borrowAmount);
111
112
  }
112
113
  return bestAmount / this.getDust();
113
114
  });
@@ -86,7 +86,7 @@ class OnchainAccountCollateral extends onchainAccountPoolToken_1.default {
86
86
  if (jump / collateralAmount < 0.001)
87
87
  break;
88
88
  withdrawAmountPrev = withdrawAmount;
89
- const changeCollateral = -1 * withdrawAmount * this.getUiMargin();
89
+ const changeCollateral = -1 * Math.max(withdrawAmount * this.getUiMargin(), collateralAmount);
90
90
  const changeBorrowedA = 0;
91
91
  const changeBorrowedB = 0;
92
92
  const changes = { changeCollateral, changeBorrowedA, changeBorrowedB };
@@ -96,6 +96,9 @@ class OnchainAccountCollateral extends onchainAccountPoolToken_1.default {
96
96
  else {
97
97
  bestAmount = withdrawAmount;
98
98
  withdrawAmount += jump;
99
+ if (withdrawAmount > collateralAmount)
100
+ break;
101
+ 1;
99
102
  }
100
103
  }
101
104
  return bestAmount / this.getDust();
@@ -191,9 +191,9 @@ class OnchainAccountLendingPool {
191
191
  return __awaiter(this, void 0, void 0, function* () {
192
192
  if (!changes)
193
193
  changes = onchainTypes_1.NO_CHANGES;
194
- const collateralAmount = (yield this.getCollateral().getDeposited()) + changes.changeCollateral;
195
- const debtA = (yield this.getBorrowableA().getBorrowed()) + changes.changeBorrowedA;
196
- const debtB = (yield this.getBorrowableB().getBorrowed()) + changes.changeBorrowedB;
194
+ const collateralAmount = Math.max((yield this.getCollateral().getDeposited()) + changes.changeCollateral, 0);
195
+ const debtA = Math.max((yield this.getBorrowableA().getBorrowed()) + changes.changeBorrowedA, 0);
196
+ const debtB = Math.max((yield this.getBorrowableB().getBorrowed()) + changes.changeBorrowedB, 0);
197
197
  const safetyMargin = yield this.getSafetyMargin();
198
198
  const liquidationPenalty = yield this.getLiquidationPenalty();
199
199
  const actualCollateral = collateralAmount / liquidationPenalty;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "1.1.72",
3
+ "version": "1.1.74",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",