@gearbox-protocol/sdk 3.0.0-next.96 → 3.0.0-next.97

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.
@@ -182,24 +182,26 @@ class CreditAccountData {
182
182
  static calcHealthFactor({ assets, quotas, quotasInfo, liquidationThresholds, underlyingToken, debt, prices, }) {
183
183
  const [, underlyingDecimals] = (0, sdk_gov_1.extractTokenData)(underlyingToken);
184
184
  const underlyingPrice = prices[underlyingToken] || 0n;
185
- const assetLTMoney = assets.reduce((acc, { token: tokenAddress, balance: amount }) => {
185
+ const assetMoney = assets.reduce((acc, { token: tokenAddress, balance: amount }) => {
186
186
  const [, tokenDecimals] = (0, sdk_gov_1.extractTokenData)(tokenAddress);
187
187
  const lt = liquidationThresholds[tokenAddress] || 0n;
188
188
  const price = prices[tokenAddress] || 0n;
189
189
  const tokenMoney = price_1.PriceUtils.calcTotalPrice(price, amount, tokenDecimals);
190
+ const tokenLtMoney = (tokenMoney * lt) / sdk_gov_1.PERCENTAGE_FACTOR;
190
191
  const { isActive = false } = quotasInfo?.[tokenAddress] || {};
191
192
  const quota = quotas[tokenAddress];
192
193
  const quotaBalance = isActive ? quota?.balance || 0n : 0n;
193
194
  const quotaMoney = price_1.PriceUtils.calcTotalPrice(underlyingPrice, quotaBalance, underlyingDecimals);
194
195
  // if quota is undefined, then it is not a quoted token
195
196
  const money = quota
196
- ? math_1.BigIntMath.min(quotaMoney, tokenMoney)
197
- : tokenMoney;
198
- const ltMoney = money * lt;
199
- return acc + ltMoney;
197
+ ? math_1.BigIntMath.min(quotaMoney, tokenLtMoney)
198
+ : tokenLtMoney;
199
+ return acc + money;
200
200
  }, 0n);
201
201
  const borrowedMoney = price_1.PriceUtils.calcTotalPrice(underlyingPrice || sdk_gov_1.PRICE_DECIMALS, debt, underlyingDecimals);
202
- const hfInPercent = borrowedMoney > 0n ? assetLTMoney / borrowedMoney : 0n;
202
+ const hfInPercent = borrowedMoney > 0n
203
+ ? (assetMoney * sdk_gov_1.PERCENTAGE_FACTOR) / borrowedMoney
204
+ : 0n;
203
205
  return Number(hfInPercent);
204
206
  }
205
207
  static calcQuotaUpdate({ quotas, initialQuotas, assetsAfterUpdate, allowedToSpend, allowedToObtain, quotaReserve, }) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "3.0.0-next.96",
3
+ "version": "3.0.0-next.97",
4
4
  "description": "Gearbox SDK",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",