@gearbox-protocol/sdk 1.15.23 → 1.15.25

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.
@@ -9,10 +9,6 @@ export interface StrategyPayload {
9
9
  leveragableCollateral: Array<string>;
10
10
  baseAssets: Array<string>;
11
11
  }
12
- interface PoolStats {
13
- borrowRate: number;
14
- }
15
- declare type PoolList = Record<string, PoolStats>;
16
12
  interface LiquidationPriceProps {
17
13
  prices: Record<string, BigNumber>;
18
14
  liquidationThresholds: Record<string, BigNumber>;
@@ -31,7 +27,7 @@ export declare class Strategy {
31
27
  baseAssets: Array<string>;
32
28
  constructor(payload: StrategyPayload);
33
29
  static maxLeverage(lpToken: string, cms: Array<PartialCM>): number;
34
- maxAPY(maxLeverage: number, poolApy: PoolList): number;
30
+ maxAPY(baseAPY: number, maxLeverage: number, borrowAPY: number): number;
35
31
  overallAPY(apy: number, leverage: number, depositCollateral: string, borrowAPY: number): number;
36
32
  liquidationPrice({ prices, liquidationThresholds, borrowed, underlyingToken, lpAmount, lpToken, }: LiquidationPriceProps): BigNumber;
37
33
  protected farmLev(leverage: number, depositCollateral: string): number;
@@ -26,9 +26,10 @@ var Strategy = /** @class */ (function () {
26
26
  var maxLeverage = ONE.mul(constants_1.LEVERAGE_DECIMALS).div(ONE.sub(maxThreshold));
27
27
  return maxLeverage.sub(constants_1.LEVERAGE_DECIMALS).toNumber();
28
28
  };
29
- Strategy.prototype.maxAPY = function (maxLeverage, poolApy) {
30
- var minApy = minBorrowApy(poolApy);
31
- return roi(this.apy || 0, maxLeverage, maxLeverage - constants_1.LEVERAGE_DECIMALS, minApy);
29
+ Strategy.prototype.maxAPY = function (baseAPY, maxLeverage, borrowAPY) {
30
+ return (baseAPY +
31
+ ((baseAPY - borrowAPY) * (maxLeverage - constants_1.LEVERAGE_DECIMALS)) /
32
+ constants_1.LEVERAGE_DECIMALS);
32
33
  };
33
34
  Strategy.prototype.overallAPY = function (apy, leverage, depositCollateral, borrowAPY) {
34
35
  var farmLev = this.farmLev(leverage, depositCollateral);
@@ -73,10 +74,6 @@ exports.Strategy = Strategy;
73
74
  function roi(apy, farmLev, debtLev, borrowAPY) {
74
75
  return (apy * farmLev - borrowAPY * debtLev) / constants_1.LEVERAGE_DECIMALS;
75
76
  }
76
- function minBorrowApy(poolApy) {
77
- var apys = Object.values(poolApy).sort(function (a, b) { return a.borrowRate - b.borrowRate; });
78
- return apys.length > 0 ? apys[0].borrowRate : 0;
79
- }
80
77
  function maxLeverageThreshold(lpToken, cms) {
81
78
  var lpTokenLC = lpToken.toLowerCase();
82
79
  var ltByCM = cms.map(function (cm) {
@@ -24,7 +24,7 @@ var lidoPayload = {
24
24
  var lidoStrategy = new strategy_1.Strategy(lidoPayload);
25
25
  var pools = {
26
26
  "0x1": {
27
- borrowRate: 7712,
27
+ borrowRate: 27543,
28
28
  },
29
29
  "0x2": {
30
30
  borrowRate: 5736,
@@ -42,8 +42,8 @@ var liquidationThresholds = (_b = {},
42
42
  _b);
43
43
  describe("Strategy test", function () {
44
44
  it("maxAPY calculation is correct", function () {
45
- var result = lidoStrategy.maxAPY(10 * constants_1.LEVERAGE_DECIMALS, pools);
46
- (0, chai_1.expect)(result).to.be.eq(332716);
45
+ var result = lidoStrategy.maxAPY(53203, 10 * constants_1.LEVERAGE_DECIMALS, pools["0x1"].borrowRate);
46
+ (0, chai_1.expect)(result).to.be.eq(284143);
47
47
  });
48
48
  it("overallAPY calculation is correct", function () {
49
49
  var result = lidoStrategy.overallAPY(lidoStrategy.apy || 0, 10 * constants_1.LEVERAGE_DECIMALS, token_1.tokenDataByNetwork.Mainnet.WETH, pools["0x2"].borrowRate);
@@ -2,7 +2,7 @@ import { BigNumber } from "ethers";
2
2
  import { SupportedContract } from "../contracts/contracts";
3
3
  import { EVMTx, EVMTxProps } from "./eventOrTx";
4
4
  export interface TxSerialized {
5
- type: "TxAddLiquidity" | "TxRemoveLiquidity" | "TxSwap" | "TxAddCollateral" | "TxIncreaseBorrowAmount" | "TxOpenAccount" | "TxRepayAccount" | "TxCloseAccount" | "TxApprove" | "TxOpenMultitokenAccount" | "TxClaimReward";
5
+ type: "TxAddLiquidity" | "TxRemoveLiquidity" | "TxSwap" | "TxAddCollateral" | "TxIncreaseBorrowAmount" | "TxOpenAccount" | "TxRepayAccount" | "TxCloseAccount" | "TxApprove" | "TxOpenMultitokenAccount" | "TxClaimReward" | "TxClaimNFT";
6
6
  content: string;
7
7
  }
8
8
  export declare class TxSerializer {
@@ -121,6 +121,12 @@ export declare class TxClaimReward extends EVMTx {
121
121
  toString(): string;
122
122
  serialize(): TxSerialized;
123
123
  }
124
+ declare type TxClaimNFTProps = EVMTxProps;
125
+ export declare class TxClaimNFT extends EVMTx {
126
+ constructor(opts: TxClaimNFTProps);
127
+ toString(): string;
128
+ serialize(): TxSerialized;
129
+ }
124
130
  interface RepayAccountProps extends EVMTxProps {
125
131
  creditManager: string;
126
132
  }
@@ -15,7 +15,7 @@ var __extends = (this && this.__extends) || (function () {
15
15
  };
16
16
  })();
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.TxApprove = exports.TxCloseAccount = exports.TxRepayAccount = exports.TxClaimReward = exports.TxOpenMultitokenAccount = exports.TxOpenAccount = exports.TxIncreaseBorrowAmount = exports.TxAddCollateral = exports.TXSwap = exports.TxRemoveLiquidity = exports.TxAddLiquidity = exports.TxSerializer = void 0;
18
+ exports.TxApprove = exports.TxCloseAccount = exports.TxRepayAccount = exports.TxClaimNFT = exports.TxClaimReward = exports.TxOpenMultitokenAccount = exports.TxOpenAccount = exports.TxIncreaseBorrowAmount = exports.TxAddCollateral = exports.TXSwap = exports.TxRemoveLiquidity = exports.TxAddLiquidity = exports.TxSerializer = void 0;
19
19
  var ethers_1 = require("ethers");
20
20
  var contracts_1 = require("../contracts/contracts");
21
21
  var contractsRegister_1 = require("../contracts/contractsRegister");
@@ -55,6 +55,8 @@ var TxSerializer = /** @class */ (function () {
55
55
  return new TxOpenMultitokenAccount(params);
56
56
  case "TxClaimReward":
57
57
  return new TxClaimReward(params);
58
+ case "TxClaimNFT":
59
+ return new TxClaimNFT(params);
58
60
  default:
59
61
  throw new Error("Unknown transaction for parsing: ".concat(e.type));
60
62
  }
@@ -299,6 +301,28 @@ var TxClaimReward = /** @class */ (function (_super) {
299
301
  return TxClaimReward;
300
302
  }(eventOrTx_1.EVMTx));
301
303
  exports.TxClaimReward = TxClaimReward;
304
+ var TxClaimNFT = /** @class */ (function (_super) {
305
+ __extends(TxClaimNFT, _super);
306
+ function TxClaimNFT(opts) {
307
+ return _super.call(this, {
308
+ block: opts.block,
309
+ txHash: opts.txHash,
310
+ txStatus: opts.txStatus,
311
+ timestamp: opts.timestamp,
312
+ }) || this;
313
+ }
314
+ TxClaimNFT.prototype.toString = function () {
315
+ return "NFT claimed";
316
+ };
317
+ TxClaimNFT.prototype.serialize = function () {
318
+ return {
319
+ type: "TxClaimNFT",
320
+ content: JSON.stringify(this),
321
+ };
322
+ };
323
+ return TxClaimNFT;
324
+ }(eventOrTx_1.EVMTx));
325
+ exports.TxClaimNFT = TxClaimNFT;
302
326
  var TxRepayAccount = /** @class */ (function (_super) {
303
327
  __extends(TxRepayAccount, _super);
304
328
  function TxRepayAccount(opts) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "1.15.23",
3
+ "version": "1.15.25",
4
4
  "description": "Gearbox SDK",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",