@gearbox-protocol/sdk 1.10.1 → 1.10.3

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.
@@ -16,8 +16,6 @@ export declare const PRICE_DECIMALS: BigNumber;
16
16
  export declare const SECONDS_PER_YEAR: number;
17
17
  export declare const PERCENTAGE_DECIMALS = 100;
18
18
  export declare const PERCENTAGE_FACTOR = 10000;
19
- export declare const LIQUIDATION_DISCOUNTED_SUM = 9500;
20
- export declare const UNDERLYING_TOKEN_LIQUIDATION_THRESHOLD = 9300;
21
19
  export declare const timeRanges: Record<string, number>;
22
20
  export declare const LEVERAGE_DECIMALS = 100;
23
21
  export declare const SLIPPAGE_DECIMALS = 100;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DUMB_ADDRESS4 = exports.DUMB_ADDRESS3 = exports.DUMB_ADDRESS2 = exports.DUMB_ADDRESS = exports.ADDRESS_0X0 = exports.SLIPPAGE_DECIMALS = exports.LEVERAGE_DECIMALS = exports.timeRanges = exports.UNDERLYING_TOKEN_LIQUIDATION_THRESHOLD = exports.LIQUIDATION_DISCOUNTED_SUM = exports.PERCENTAGE_FACTOR = exports.PERCENTAGE_DECIMALS = exports.SECONDS_PER_YEAR = exports.PRICE_DECIMALS = exports.PRICE_DECIMALS_POW = exports.WAD = exports.WAD_DECIMALS_POW = exports.halfRAY = exports.RAY = exports.RAY_DECIMALS_POW = exports.getNetworkType = exports.HARDHAT_NETWORK = exports.LOCAL_NETWORK = exports.GOERLI_NETWORK = exports.MAINNET_NETWORK = exports.MAX_INT = void 0;
3
+ exports.DUMB_ADDRESS4 = exports.DUMB_ADDRESS3 = exports.DUMB_ADDRESS2 = exports.DUMB_ADDRESS = exports.ADDRESS_0X0 = exports.SLIPPAGE_DECIMALS = exports.LEVERAGE_DECIMALS = exports.timeRanges = exports.PERCENTAGE_FACTOR = exports.PERCENTAGE_DECIMALS = exports.SECONDS_PER_YEAR = exports.PRICE_DECIMALS = exports.PRICE_DECIMALS_POW = exports.WAD = exports.WAD_DECIMALS_POW = exports.halfRAY = exports.RAY = exports.RAY_DECIMALS_POW = exports.getNetworkType = exports.HARDHAT_NETWORK = exports.LOCAL_NETWORK = exports.GOERLI_NETWORK = exports.MAINNET_NETWORK = exports.MAX_INT = void 0;
4
4
  var ethers_1 = require("ethers");
5
5
  exports.MAX_INT = ethers_1.BigNumber.from("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
6
6
  exports.MAINNET_NETWORK = 1;
@@ -29,8 +29,8 @@ exports.PRICE_DECIMALS = ethers_1.BigNumber.from(10).pow(exports.PRICE_DECIMALS_
29
29
  exports.SECONDS_PER_YEAR = 365 * 24 * 3600;
30
30
  exports.PERCENTAGE_DECIMALS = 100;
31
31
  exports.PERCENTAGE_FACTOR = 1e4;
32
- exports.LIQUIDATION_DISCOUNTED_SUM = 9500;
33
- exports.UNDERLYING_TOKEN_LIQUIDATION_THRESHOLD = 9300;
32
+ // export const LIQUIDATION_DISCOUNTED_SUM = 9600;
33
+ // export const UNDERLYING_TOKEN_LIQUIDATION_THRESHOLD = 9400;
34
34
  exports.timeRanges = {
35
35
  // "1H": 3600,
36
36
  "1D": 3600 * 24,
@@ -32,6 +32,7 @@ export declare class CreditAccountData {
32
32
  balancesSorted(prices: Record<string, BigNumber>, tokens: Record<string, TokenData>): Array<Asset>;
33
33
  calcBorrowAmountPlusInterestRate(currentCumulativeIndex: BigNumber): BigNumber;
34
34
  updateHealthFactor(creditManager: CreditManagerData, currentCumulativeIndex: BigNumber, priceOracle: PriceOracleData): void;
35
+ calcMaxIncreaseBorrow(cm: CreditManagerData): BigNumber;
35
36
  get id(): string;
36
37
  hash(): string;
37
38
  static hash(creditManager: string, borrower: string): string;
@@ -76,6 +76,17 @@ var CreditAccountData = /** @class */ (function () {
76
76
  .div(this.calcBorrowAmountPlusInterestRate(currentCumulativeIndex))
77
77
  .toNumber();
78
78
  };
79
+ CreditAccountData.prototype.calcMaxIncreaseBorrow = function (cm) {
80
+ var underlyingTokenLT = cm.liquidationDiscount - cm.feeLiquidation;
81
+ var minHealthFactor = cm.maxLeverageFactor > 0
82
+ ? Math.floor((underlyingTokenLT * (cm.maxLeverageFactor + constants_1.LEVERAGE_DECIMALS)) /
83
+ cm.maxLeverageFactor)
84
+ : constants_1.PERCENTAGE_FACTOR;
85
+ var result = this.borrowedAmountPlusInterest
86
+ .mul(this.healthFactor - minHealthFactor)
87
+ .div(minHealthFactor - underlyingTokenLT);
88
+ return result.isNegative() ? ethers_1.BigNumber.from(0) : result;
89
+ };
79
90
  Object.defineProperty(CreditAccountData.prototype, "id", {
80
91
  get: function () {
81
92
  return this.creditManager;
@@ -56,7 +56,6 @@ export declare class CreditManagerStat extends CreditManagerData {
56
56
  readonly totalLosses: BigNumber;
57
57
  constructor(payload: CreditManagerStatPayload);
58
58
  }
59
- export declare function calcMaxIncreaseBorrow(healthFactor: number, borrowAmountPlusInterest: BigNumber, maxLeverageFactor: number): BigNumber;
60
59
  export interface CalcHealthFactorProps {
61
60
  assets: Array<Asset>;
62
61
  prices: Record<string, BigNumber>;
@@ -26,7 +26,7 @@ var __assign = (this && this.__assign) || function () {
26
26
  return __assign.apply(this, arguments);
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.calcHealthFactor = exports.calcMaxIncreaseBorrow = exports.CreditManagerStat = exports.CreditManagerData = void 0;
29
+ exports.calcHealthFactor = exports.CreditManagerStat = exports.CreditManagerData = void 0;
30
30
  var ethers_1 = require("ethers");
31
31
  var txParser_1 = require("../parsers/txParser");
32
32
  var decimals_1 = require("../tokens/decimals");
@@ -173,18 +173,6 @@ var CreditManagerStat = /** @class */ (function (_super) {
173
173
  return CreditManagerStat;
174
174
  }(CreditManagerData));
175
175
  exports.CreditManagerStat = CreditManagerStat;
176
- function calcMaxIncreaseBorrow(healthFactor, borrowAmountPlusInterest, maxLeverageFactor) {
177
- var minHealthFactor = maxLeverageFactor > 0
178
- ? Math.floor((constants_1.UNDERLYING_TOKEN_LIQUIDATION_THRESHOLD *
179
- (maxLeverageFactor + constants_1.LEVERAGE_DECIMALS)) /
180
- maxLeverageFactor)
181
- : 10000;
182
- var result = borrowAmountPlusInterest
183
- .mul(healthFactor - minHealthFactor)
184
- .div(minHealthFactor - constants_1.UNDERLYING_TOKEN_LIQUIDATION_THRESHOLD);
185
- return result.isNegative() ? ethers_1.BigNumber.from(0) : result;
186
- }
187
- exports.calcMaxIncreaseBorrow = calcMaxIncreaseBorrow;
188
176
  function calcHealthFactor(_a) {
189
177
  var assets = _a.assets, prices = _a.prices, liquidationThresholds = _a.liquidationThresholds, underlyingToken = _a.underlyingToken, borrowed = _a.borrowed;
190
178
  var assetLTMoney = assets.reduce(function (acc, _a) {
@@ -127,18 +127,34 @@ describe("CreditManager calcHealthFactor test", function () {
127
127
  (0, chai_1.expect)(result).to.be.eq(9444);
128
128
  });
129
129
  });
130
- describe("CreditManager calcMaxIncreaseBorrow test", function () {
131
- it("health max increase borrow is zero if hf < 1", function () {
132
- var result = (0, creditManager_1.calcMaxIncreaseBorrow)(9999, ethers_1.BigNumber.from("156522834253690396032546"), 0);
133
- (0, chai_1.expect)(result.toString()).to.be.eq(ethers_1.BigNumber.from(0).toString());
134
- });
135
- it("health max increase borrow is calculated correctly", function () {
136
- var result = (0, creditManager_1.calcMaxIncreaseBorrow)(defaultCA.healthFactor, ethers_1.BigNumber.from("156522834253690396032546"), 0);
137
- (0, chai_1.expect)(result.toString()).to.be.eq(ethers_1.BigNumber.from("54559387939857795188487").toString());
138
- });
139
- it("health max increase borrow is calculated correctly (low hf, high debt)", function () {
140
- var loweHf = 10244;
141
- var result = (0, creditManager_1.calcMaxIncreaseBorrow)(loweHf, ethers_1.BigNumber.from("54782991988791638611392"), 0);
142
- (0, chai_1.expect)(result.toString()).to.be.eq(ethers_1.BigNumber.from("19095785778950228315970").toString());
143
- });
144
- });
130
+ // describe("CreditManager calcMaxIncreaseBorrow test", () => {
131
+ // it("health max increase borrow is zero if hf < 1", () => {
132
+ // const result = calcMaxIncreaseBorrow(
133
+ // 9999,
134
+ // BigNumber.from("156522834253690396032546"),
135
+ // 0,
136
+ // );
137
+ // expect(result.toString()).to.be.eq(BigNumber.from(0).toString());
138
+ // });
139
+ // it("health max increase borrow is calculated correctly", () => {
140
+ // const result = calcMaxIncreaseBorrow(
141
+ // defaultCA.healthFactor,
142
+ // BigNumber.from("156522834253690396032546"),
143
+ // 0,
144
+ // );
145
+ // expect(result.toString()).to.be.eq(
146
+ // BigNumber.from("54559387939857795188487").toString(),
147
+ // );
148
+ // });
149
+ // it("health max increase borrow is calculated correctly (low hf, high debt)", () => {
150
+ // const loweHf = 10244;
151
+ // const result = calcMaxIncreaseBorrow(
152
+ // loweHf,
153
+ // BigNumber.from("54782991988791638611392"),
154
+ // 0,
155
+ // );
156
+ // expect(result.toString()).to.be.eq(
157
+ // BigNumber.from("19095785778950228315970").toString(),
158
+ // );
159
+ // });
160
+ // });
@@ -69,7 +69,7 @@ exports.tokenDataByNetwork = {
69
69
  cvxgusd3CRV: "0x15c2471ef46Fa721990730cfa526BcFb45574576",
70
70
  // CONVEX PHANTOM TOKEN ADDRESSES
71
71
  stkcvx3Crv: "0x2eD0f32d7C8b0f7EA7E40277C62Fb9C5DE092003",
72
- stkcvxcrvFRAX: "DEPLOY ME",
72
+ stkcvxcrvFRAX: "0xE36cbd724F500353C23297789A5f88fe3d920523",
73
73
  stkcvxsteCRV: "0x2210aa245Bf766eE99325c607807A08e636B5173",
74
74
  stkcvxFRAX3CRV: "0x2AF29502110080081FDF726dfBf61ABE3bA9Ef3C",
75
75
  stkcvxLUSD3CRV: "0x77e6290D1779B606235407fdf37A14D94D0DFB40",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "1.10.1",
3
+ "version": "1.10.3",
4
4
  "description": "Gearbox SDK",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",