@gearbox-protocol/sdk 1.26.0 → 1.26.1

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.
@@ -54,7 +54,7 @@ export declare class CreditAccountData {
54
54
  isForbidden(token: string): boolean;
55
55
  updateHealthFactor(creditManager: CreditManagerData, currentCumulativeIndex: bigint, priceOracle: PriceOracleData): void;
56
56
  static isTokenEnabled(index: number, enabledTokenMask: bigint): boolean;
57
- static calcMaxIncreaseBorrow(healthFactor: number, borrowAmountPlusInterest: bigint, maxLeverageFactor: number, underlyingLT: number, minHf?: bigint): bigint;
57
+ static calcMaxDebtIncrease(healthFactor: number, borrowAmountPlusInterest: bigint, underlyingLT: number, minHf?: number): bigint;
58
58
  static calcOverallAPY({ caAssets, lpAPY, prices, totalValue, debt, borrowRate, underlyingToken, }: CalcOverallAPYProps): number | undefined;
59
59
  hash(): string;
60
60
  static hash(creditManager: string, borrower: string): string;
@@ -117,13 +117,9 @@ class CreditAccountData {
117
117
  static isTokenEnabled(index, enabledTokenMask) {
118
118
  return ((2n ** BigInt(index)) & enabledTokenMask) !== 0n;
119
119
  }
120
- static calcMaxIncreaseBorrow(healthFactor, borrowAmountPlusInterest, maxLeverageFactor, underlyingLT, minHf = constants_1.PERCENTAGE_FACTOR) {
121
- const minHealthFactor = maxLeverageFactor > 0
122
- ? Math.floor((underlyingLT * (maxLeverageFactor + Number(constants_1.LEVERAGE_DECIMALS))) /
123
- maxLeverageFactor)
124
- : Number(minHf);
125
- const result = (borrowAmountPlusInterest * BigInt(healthFactor - minHealthFactor)) /
126
- BigInt(minHealthFactor - underlyingLT);
120
+ static calcMaxDebtIncrease(healthFactor, borrowAmountPlusInterest, underlyingLT, minHf = Number(constants_1.PERCENTAGE_FACTOR)) {
121
+ const result = (borrowAmountPlusInterest * BigInt(healthFactor - minHf)) /
122
+ BigInt(minHf - underlyingLT);
127
123
  return result < 0 ? 0n : result;
128
124
  }
129
125
  static calcOverallAPY({ caAssets, lpAPY, prices, totalValue, debt, borrowRate, underlyingToken, }) {
@@ -122,16 +122,16 @@ describe("CreditAccount CreditAccountData.calcOverallAPY test", () => {
122
122
  });
123
123
  describe("CreditAccount calcMaxIncreaseBorrow test", () => {
124
124
  it("health max increase borrow is zero if hf < 1", () => {
125
- const result = creditAccount_1.CreditAccountData.calcMaxIncreaseBorrow(9999, BigInt("156522834253690396032546"), 0, 9300);
125
+ const result = creditAccount_1.CreditAccountData.calcMaxDebtIncrease(9999, BigInt("156522834253690396032546"), 9300);
126
126
  (0, chai_1.expect)(result.toString()).to.be.eq("0");
127
127
  });
128
128
  it("health max increase borrow is calculated correctly", () => {
129
- const result = creditAccount_1.CreditAccountData.calcMaxIncreaseBorrow(10244, BigInt("156522834253690396032546"), 0, 9300);
129
+ const result = creditAccount_1.CreditAccountData.calcMaxDebtIncrease(10244, BigInt("156522834253690396032546"), 9300);
130
130
  (0, chai_1.expect)(result.toString()).to.be.eq("54559387939857795188487");
131
131
  });
132
132
  it("health max increase borrow is calculated correctly (low hf, high debt)", () => {
133
133
  const loweHf = 10244;
134
- const result = creditAccount_1.CreditAccountData.calcMaxIncreaseBorrow(loweHf, BigInt("54782991988791638611392"), 0, 9300);
134
+ const result = creditAccount_1.CreditAccountData.calcMaxDebtIncrease(loweHf, BigInt("54782991988791638611392"), 9300);
135
135
  (0, chai_1.expect)(result.toString()).to.be.eq("19095785778950228315970");
136
136
  });
137
137
  });
@@ -43,6 +43,8 @@ export declare class CreditSession {
43
43
  readonly spotUserFunds: bigint;
44
44
  readonly cvxUnclaimedRewards: Array<AssetWithView>;
45
45
  readonly balances: Array<AssetWithView>;
46
+ readonly forbiddenTokens: Record<string, true>;
47
+ readonly disabledTokens: Record<string, true>;
46
48
  constructor(payload: CreditSessionPayload);
47
49
  }
48
50
  export declare class CreditSessionFiltered {
@@ -58,7 +58,9 @@ class CreditSession {
58
58
  spotTotalValue;
59
59
  spotUserFunds;
60
60
  cvxUnclaimedRewards;
61
- balances;
61
+ balances = [];
62
+ forbiddenTokens = {};
63
+ disabledTokens = {};
62
64
  constructor(payload) {
63
65
  this.id = (payload.id || "").toLowerCase();
64
66
  this.status = exports.CREDIT_SESSION_STATUS_BY_ID[payload.status || 0];
@@ -105,12 +107,19 @@ class CreditSession {
105
107
  balanceView: balance.f.toString(),
106
108
  };
107
109
  });
108
- this.balances = Object.entries(payload.balances || {}).map(([token, balance]) => {
109
- return {
110
+ Object.entries(payload.balances || {}).forEach(([t, b]) => {
111
+ const token = t.toLowerCase();
112
+ if (!b.isEnabled) {
113
+ this.disabledTokens[token] = true;
114
+ }
115
+ if (!b.isAllowed) {
116
+ this.forbiddenTokens[token] = true;
117
+ }
118
+ this.balances.push({
110
119
  token: token.toLowerCase(),
111
- balance: (0, formatter_1.toBigInt)(balance.BI || 0),
112
- balanceView: balance.F.toString(),
113
- };
120
+ balance: (0, formatter_1.toBigInt)(b.BI || 0),
121
+ balanceView: b.F.toString(),
122
+ });
114
123
  });
115
124
  }
116
125
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "1.26.0",
3
+ "version": "1.26.1",
4
4
  "description": "Gearbox SDK",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",