@gearbox-protocol/sdk 3.0.0-vfour.1 → 3.0.0-vfour.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.
@@ -0,0 +1,49 @@
1
+ 'use strict';
2
+
3
+ var sdk = require('../sdk');
4
+
5
+ // src/dev/calcLiquidatableLTs.ts
6
+ async function calcLiquidatableLTs(sdk$1, ca, factor = 9990n) {
7
+ const cm = sdk$1.marketRegister.findCreditManager(ca.creditManager);
8
+ const market = sdk$1.marketRegister.findByCreditManager(ca.creditManager);
9
+ const weightedBalances = ca.tokens.map((t) => {
10
+ const { token, balance } = t;
11
+ const balanceU = market.priceOracle.convertToUnderlying(token, balance);
12
+ const lt = BigInt(cm.collateralTokens[token]);
13
+ return {
14
+ token,
15
+ weightedBalance: balanceU * lt / sdk.PERCENTAGE_FACTOR,
16
+ lt
17
+ };
18
+ }).sort((a, b) => {
19
+ if (a.token === ca.underlying) return 1;
20
+ if (b.token === ca.underlying) return -1;
21
+ return b.weightedBalance > a.weightedBalance ? 1 : -1;
22
+ });
23
+ let divisor = 0n;
24
+ let dividend = factor * (ca.debt + ca.accruedInterest + ca.accruedFees) / sdk.PERCENTAGE_FACTOR;
25
+ for (const { token, weightedBalance } of weightedBalances) {
26
+ if (token === ca.underlying) {
27
+ dividend -= weightedBalance;
28
+ } else {
29
+ divisor += weightedBalance;
30
+ }
31
+ }
32
+ if (divisor === 0n) {
33
+ throw new Error("warning: assets have zero weighted value in underlying");
34
+ }
35
+ if (dividend <= 0n) {
36
+ throw new Error(`warning: account balance in underlying covers debt`);
37
+ }
38
+ const k = sdk.WAD * dividend / divisor;
39
+ const result = {};
40
+ for (const { token, lt: oldLT } of weightedBalances) {
41
+ if (token !== ca.underlying) {
42
+ const newLT = oldLT * k / sdk.WAD;
43
+ result[token] = [Number(oldLT), Number(newLT)];
44
+ }
45
+ }
46
+ return result;
47
+ }
48
+
49
+ exports.calcLiquidatableLTs = calcLiquidatableLTs;
@@ -0,0 +1,10 @@
1
+ import { Address } from 'viem';
2
+ import { GearboxSDK, CreditAccountData } from '../sdk';
3
+
4
+ /**
5
+ * Given credit accounts, calculates new liquidation thresholds that needs to be set to drop account health factor a bit to make it eligible for partial liquidation
6
+ * @param ca
7
+ */
8
+ declare function calcLiquidatableLTs(sdk: GearboxSDK, ca: CreditAccountData, factor?: bigint): Promise<Record<Address, [ltOld: number, ltNew: number]>>;
9
+
10
+ export { calcLiquidatableLTs };
@@ -0,0 +1 @@
1
+ {"type": "commonjs"}