@gearbox-protocol/sdk 1.15.18 → 1.15.19

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.
@@ -1,5 +1,4 @@
1
1
  import { BigNumber } from "ethers";
2
- import { Asset } from "./assets";
3
2
  import { CreditManagerData } from "./creditManager";
4
3
  export interface StrategyPayload {
5
4
  apy?: number;
@@ -15,7 +14,6 @@ interface PoolStats {
15
14
  }
16
15
  declare type PoolList = Record<string, PoolStats>;
17
16
  interface LiquidationPriceProps {
18
- assets: Array<Asset>;
19
17
  prices: Record<string, BigNumber>;
20
18
  liquidationThresholds: Record<string, BigNumber>;
21
19
  borrowed: BigNumber;
@@ -35,7 +33,7 @@ export declare class Strategy {
35
33
  static maxLeverage(lpToken: string, cms: Array<PartialCM>): number;
36
34
  maxAPY(maxLeverage: number, poolApy: PoolList): number;
37
35
  overallAPY(apy: number, leverage: number, depositCollateral: string, borrowAPY: number): number;
38
- liquidationPrice({ assets, prices, liquidationThresholds, borrowed, underlyingToken, lpAmount, lpToken, }: LiquidationPriceProps): BigNumber;
36
+ liquidationPrice({ prices, liquidationThresholds, borrowed, underlyingToken, lpAmount, lpToken, }: LiquidationPriceProps): BigNumber;
39
37
  protected farmLev(leverage: number, depositCollateral: string): number;
40
38
  protected inBaseAssets(depositCollateral: string): boolean;
41
39
  protected inLeveragableAssets(depositCollateral: string): boolean;
@@ -36,18 +36,7 @@ var Strategy = /** @class */ (function () {
36
36
  };
37
37
  // eslint-disable-next-line class-methods-use-this
38
38
  Strategy.prototype.liquidationPrice = function (_a) {
39
- var assets = _a.assets, prices = _a.prices, liquidationThresholds = _a.liquidationThresholds, borrowed = _a.borrowed, underlyingToken = _a.underlyingToken, lpAmount = _a.lpAmount, lpToken = _a.lpToken;
40
- var collateralLTMoney = assets.reduce(function (acc, _a) {
41
- var tokenAddress = _a.token, amount = _a.balance;
42
- var tokenAddressLC = tokenAddress.toLowerCase();
43
- var tokenSymbol = token_1.tokenSymbolByAddress[tokenAddressLC];
44
- var lt = liquidationThresholds[tokenAddressLC] || ethers_1.BigNumber.from(0);
45
- var price = prices[tokenAddressLC] || ethers_1.BigNumber.from(0);
46
- var tokenDecimals = decimals_1.decimals[tokenSymbol];
47
- var money = (0, price_1.calcTotalPrice)(price, amount, tokenDecimals);
48
- var ltMoney = money.mul(lt).div(constants_1.PERCENTAGE_FACTOR);
49
- return acc.add(ltMoney);
50
- }, ethers_1.BigNumber.from(0));
39
+ var prices = _a.prices, liquidationThresholds = _a.liquidationThresholds, borrowed = _a.borrowed, underlyingToken = _a.underlyingToken, lpAmount = _a.lpAmount, lpToken = _a.lpToken;
51
40
  var underlyingTokenAddressLC = underlyingToken.toLowerCase();
52
41
  var underlyingTokenSymbol = token_1.tokenSymbolByAddress[underlyingTokenAddressLC];
53
42
  var underlyingTokenDecimals = decimals_1.decimals[underlyingTokenSymbol];
@@ -56,13 +45,12 @@ var Strategy = /** @class */ (function () {
56
45
  var lpTokenAddressLC = lpToken.toLowerCase();
57
46
  var lpTokenSymbol = token_1.tokenSymbolByAddress[lpTokenAddressLC];
58
47
  var lpTokenDecimals = decimals_1.decimals[lpTokenSymbol];
48
+ var lpLT = liquidationThresholds[lpTokenAddressLC] || ethers_1.BigNumber.from(0);
59
49
  var lpPrice = prices[lpTokenAddressLC] || constants_1.PRICE_DECIMALS;
60
50
  var lpMoney = (0, price_1.calcTotalPrice)(lpPrice, lpAmount, lpTokenDecimals);
61
- if (lpMoney.gt(0)) {
62
- var lqPrice = borrowedMoney
63
- .sub(collateralLTMoney)
64
- .mul(constants_1.WAD)
65
- .div(lpMoney);
51
+ var lpLTMoney = lpMoney.mul(lpLT).div(constants_1.PERCENTAGE_FACTOR);
52
+ if (lpLTMoney.gt(0)) {
53
+ var lqPrice = borrowedMoney.mul(constants_1.WAD).div(lpLTMoney);
66
54
  return lqPrice.gte(0) ? lqPrice : ethers_1.BigNumber.from(0);
67
55
  }
68
56
  return ethers_1.BigNumber.from(0);
@@ -51,22 +51,16 @@ describe("Strategy test", function () {
51
51
  });
52
52
  it("liquidationPrice calculation is correct", function () {
53
53
  var result = lidoStrategy.liquidationPrice({
54
- assets: [
55
- {
56
- balance: (0, formatter_1.toBN)("30", decimals_1.decimals.WETH),
57
- token: token_1.tokenDataByNetwork.Mainnet.WETH,
58
- },
59
- ],
60
54
  liquidationThresholds: liquidationThresholds,
61
55
  prices: prices,
62
- borrowed: (0, formatter_1.toBN)("90", decimals_1.decimals.WETH),
56
+ borrowed: (0, formatter_1.toBN)("350", decimals_1.decimals.WETH),
63
57
  underlyingToken: token_1.tokenDataByNetwork.Mainnet.WETH,
64
- lpAmount: (0, formatter_1.toBN)("119.40", decimals_1.decimals.STETH),
58
+ lpAmount: (0, formatter_1.toBN)("400", decimals_1.decimals.STETH),
65
59
  lpToken: token_1.tokenDataByNetwork.Mainnet.STETH,
66
60
  });
67
- (0, chai_1.expect)(Number((0, formatter_1.toSignificant)(result, constants_1.WAD_DECIMALS_POW)).toFixed(3)).to.be.eq("0.551");
61
+ (0, chai_1.expect)(Number((0, formatter_1.toSignificant)(result, constants_1.WAD_DECIMALS_POW)).toFixed(3)).to.be.eq("0.992");
68
62
  });
69
- it("liquidationPrice maxLeverage is correct", function () {
63
+ it("maxLeverage is correct", function () {
70
64
  var result = strategy_1.Strategy.maxLeverage(token_1.tokenDataByNetwork.Mainnet.STETH, [
71
65
  { address: "0x1", liquidationThresholds: liquidationThresholds },
72
66
  ]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "1.15.18",
3
+ "version": "1.15.19",
4
4
  "description": "Gearbox SDK",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",