@gearbox-protocol/sdk 0.0.102 → 0.0.105

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.
Files changed (129) hide show
  1. package/.eslintignore +5 -0
  2. package/.eslintrc.js +52 -0
  3. package/.husky/pre-push +4 -0
  4. package/lib/apy/convexAPY.js +3 -5
  5. package/lib/apy/lidoAPY.js +8 -9
  6. package/lib/contracts/contracts.d.ts +5 -2
  7. package/lib/contracts/contracts.js +19 -18
  8. package/lib/core/constants.d.ts +1 -1
  9. package/lib/core/constants.js +2 -2
  10. package/lib/core/creditAccount.js +7 -5
  11. package/lib/core/creditManager.d.ts +1 -1
  12. package/lib/core/creditManager.js +1 -7
  13. package/lib/core/creditSession.js +14 -3
  14. package/lib/core/eventOrTx.d.ts +1 -1
  15. package/lib/core/events.d.ts +19 -19
  16. package/lib/core/events.js +23 -21
  17. package/lib/core/pool.d.ts +1 -1
  18. package/lib/core/pool.js +1 -7
  19. package/lib/core/price.js +6 -1
  20. package/lib/core/strategy.d.ts +1 -3
  21. package/lib/core/strategy.js +14 -13
  22. package/lib/core/tokenDistributor.js +1 -1
  23. package/lib/core/transactions.d.ts +18 -3
  24. package/lib/core/transactions.js +39 -3
  25. package/lib/index.d.ts +8 -2
  26. package/lib/index.js +8 -1
  27. package/lib/oracles/priceFeeds.js +1 -1
  28. package/lib/pathfinder/convexLP.d.ts +1 -1
  29. package/lib/pathfinder/convexLP.js +26 -29
  30. package/lib/pathfinder/curveLP.d.ts +1 -1
  31. package/lib/pathfinder/curveLP.js +5 -7
  32. package/lib/pathfinder/path.d.ts +1 -1
  33. package/lib/pathfinder/path.js +38 -42
  34. package/lib/pathfinder/trade.d.ts +1 -2
  35. package/lib/pathfinder/tradeTypes.d.ts +5 -5
  36. package/lib/pathfinder/yVault.d.ts +2 -2
  37. package/lib/pathfinder/yVault.js +18 -15
  38. package/lib/strategies/convex.d.ts +12 -0
  39. package/lib/strategies/convex.js +74 -1
  40. package/lib/strategies/creditFacade.d.ts +1 -0
  41. package/lib/strategies/creditFacade.js +3 -0
  42. package/lib/strategies/curve.d.ts +15 -60
  43. package/lib/strategies/curve.js +74 -1
  44. package/lib/strategies/lido.d.ts +6 -0
  45. package/lib/strategies/lido.js +23 -1
  46. package/lib/strategies/uniswapV2.d.ts +1 -0
  47. package/lib/strategies/uniswapV2.js +6 -19
  48. package/lib/strategies/uniswapV3.d.ts +1 -0
  49. package/lib/strategies/uniswapV3.js +4 -1
  50. package/lib/strategies/yearn.d.ts +8 -0
  51. package/lib/strategies/yearn.js +92 -12
  52. package/lib/tokens/convex.d.ts +3 -3
  53. package/lib/tokens/curveLP.d.ts +7 -2
  54. package/lib/tokens/curveLP.js +8 -1
  55. package/lib/tokens/gear.d.ts +2 -2
  56. package/lib/tokens/gear.js +1 -1
  57. package/lib/tokens/normal.d.ts +1 -1
  58. package/lib/tokens/token.js +4 -4
  59. package/lib/tokens/tokenData.d.ts +3 -1
  60. package/lib/tokens/tokenData.js +10 -8
  61. package/lib/tokens/yearn.d.ts +6 -2
  62. package/lib/tokens/yearn.js +6 -0
  63. package/lib/utils/errors.d.ts +6 -0
  64. package/lib/utils/errors.js +13 -0
  65. package/lib/utils/formatter.d.ts +1 -1
  66. package/lib/utils/formatter.js +17 -14
  67. package/lib/utils/loading.d.ts +2 -1
  68. package/lib/utils/loading.js +9 -13
  69. package/lib/utils/mappers.js +2 -2
  70. package/lib/utils/network.js +2 -2
  71. package/lib/utils/repeater.js +12 -24
  72. package/lib/utils/validate.js +1 -1
  73. package/package.json +24 -7
  74. package/src/apy/convexAPY.ts +6 -6
  75. package/src/apy/lidoAPY.ts +12 -11
  76. package/src/contracts/contracts.ts +27 -17
  77. package/src/core/constants.ts +1 -1
  78. package/src/core/creditAccount.ts +28 -5
  79. package/src/core/creditManager.ts +29 -4
  80. package/src/core/creditOperation.ts +7 -7
  81. package/src/core/creditSession.ts +25 -5
  82. package/src/core/errors.ts +1 -0
  83. package/src/core/eventOrTx.ts +8 -5
  84. package/src/core/events.ts +85 -24
  85. package/src/core/history.ts +46 -46
  86. package/src/core/operations.ts +6 -0
  87. package/src/core/pool.ts +16 -4
  88. package/src/core/price.ts +7 -3
  89. package/src/core/strategy.ts +27 -23
  90. package/src/core/tokenDistributor.ts +2 -2
  91. package/src/core/transactions.ts +427 -350
  92. package/src/index.ts +10 -3
  93. package/src/oracles/priceFeeds.ts +523 -523
  94. package/src/pathfinder/contracts.ts +15 -13
  95. package/src/pathfinder/convexLP.ts +29 -25
  96. package/src/pathfinder/curveLP.ts +57 -53
  97. package/src/pathfinder/path.ts +17 -9
  98. package/src/pathfinder/priority.ts +11 -11
  99. package/src/pathfinder/trade.ts +84 -77
  100. package/src/pathfinder/tradeTypes.ts +98 -94
  101. package/src/pathfinder/yVault.ts +26 -11
  102. package/src/payload/token.ts +3 -3
  103. package/src/strategies/convex.ts +361 -186
  104. package/src/strategies/creditFacade.ts +74 -53
  105. package/src/strategies/curve.ts +400 -189
  106. package/src/strategies/lido.ts +70 -32
  107. package/src/strategies/uniswapV2.ts +93 -111
  108. package/src/strategies/uniswapV3.ts +118 -91
  109. package/src/strategies/yearn.ts +187 -60
  110. package/src/tokens/connectors.ts +6 -6
  111. package/src/tokens/convex.ts +297 -296
  112. package/src/tokens/curveLP.ts +176 -165
  113. package/src/tokens/gear.ts +47 -45
  114. package/src/tokens/normal.ts +801 -802
  115. package/src/tokens/token.ts +9 -5
  116. package/src/tokens/tokenData.ts +19 -9
  117. package/src/tokens/tokenType.ts +11 -11
  118. package/src/tokens/yearn.ts +130 -124
  119. package/src/utils/errors.ts +11 -0
  120. package/src/utils/formatter.ts +22 -18
  121. package/src/utils/loading.ts +14 -6
  122. package/src/utils/mappers.ts +8 -6
  123. package/src/utils/multicall.ts +2 -0
  124. package/src/utils/network.ts +21 -21
  125. package/src/utils/repeater.ts +2 -2
  126. package/src/utils/validate.ts +1 -1
  127. package/lib/utils/events.d.ts +0 -2
  128. package/lib/utils/events.js +0 -13
  129. package/src/utils/events.ts +0 -10
@@ -95,9 +95,7 @@ var EventParser = /** @class */ (function () {
95
95
  }
96
96
  };
97
97
  EventParser.deserializeArray = function (data) {
98
- return data.map(function (e) {
99
- return EventParser.deserialize(e);
100
- });
98
+ return data.map(function (e) { return EventParser.deserialize(e); });
101
99
  };
102
100
  return EventParser;
103
101
  }());
@@ -218,7 +216,7 @@ var EventRepayCreditAccount = /** @class */ (function (_super) {
218
216
  _this.creditManager = opts.creditManager;
219
217
  return _this;
220
218
  }
221
- EventRepayCreditAccount.prototype.toString = function (_) {
219
+ EventRepayCreditAccount.prototype.toString = function () {
222
220
  return "Credit account ".concat((0, contractsRegister_1.getContractName)(this.creditManager), ": was repaid");
223
221
  };
224
222
  return EventRepayCreditAccount;
@@ -339,6 +337,8 @@ var EventTokenAllowed = /** @class */ (function (_super) {
339
337
  return "".concat(msg, ": ").concat(token.symbol, " is allowed now, liquidation threshold: ").concat(this.liquidityThreshold / constants_1.PERCENTAGE_DECIMALS, "%");
340
338
  case "LTUpdated":
341
339
  return "".concat(msg, ": ").concat(token.symbol, " liquidation threshold: ").concat((this.prevLiquidationThreshold || 0) / constants_1.PERCENTAGE_DECIMALS, " => ").concat(this.liquidityThreshold / constants_1.PERCENTAGE_DECIMALS, "%");
340
+ default:
341
+ return "Error: TokenAllowedProps";
342
342
  }
343
343
  };
344
344
  return EventTokenAllowed;
@@ -377,13 +377,15 @@ var EventContractAllowed = /** @class */ (function (_super) {
377
377
  _this.status = opts.status;
378
378
  return _this;
379
379
  }
380
- EventContractAllowed.prototype.toString = function (_) {
380
+ EventContractAllowed.prototype.toString = function () {
381
381
  var msg = "Credit manager ".concat((0, contractsRegister_1.getContractName)(this.creditManager), " updated");
382
382
  switch (this.status) {
383
383
  case "Connected":
384
384
  return "".concat(msg, " : ").concat((0, contractsRegister_1.getContractName)(this.protocol), " was connected. Adapter at: ").concat(this.adapter);
385
385
  case "AdapterUpdate":
386
386
  return "".concat(msg, " : ").concat((0, contractsRegister_1.getContractName)(this.protocol), " adapter was updated. New adapter: ").concat(this.adapter);
387
+ default:
388
+ return "Error: EventContractAllowed";
387
389
  }
388
390
  };
389
391
  return EventContractAllowed;
@@ -401,7 +403,7 @@ var EventContractForbidden = /** @class */ (function (_super) {
401
403
  _this.protocol = opts.protocol;
402
404
  return _this;
403
405
  }
404
- EventContractForbidden.prototype.toString = function (_) {
406
+ EventContractForbidden.prototype.toString = function () {
405
407
  return "Credit manager ".concat((0, contractsRegister_1.getContractName)(this.creditManager), " updated: ").concat((0, contractsRegister_1.getContractName)(this.protocol));
406
408
  };
407
409
  return EventContractForbidden;
@@ -422,7 +424,7 @@ var EventNewFastCheckParameters = /** @class */ (function (_super) {
422
424
  _this.prevFastCheckDelay = opts.prevFastCheckDelay;
423
425
  return _this;
424
426
  }
425
- EventNewFastCheckParameters.prototype.toString = function (_) {
427
+ EventNewFastCheckParameters.prototype.toString = function () {
426
428
  var msg = "Credit manager ".concat((0, contractsRegister_1.getContractName)(this.creditManager), " updated: ");
427
429
  if (this.chiThreshold !== this.prevChiThreshold) {
428
430
  msg += "Chi threshold: ".concat(this.prevChiThreshold, " => ").concat(this.chiThreshold, ", ");
@@ -447,7 +449,7 @@ var EventPriceOracleUpdated = /** @class */ (function (_super) {
447
449
  _this.priceOracle = opts.priceOracle;
448
450
  return _this;
449
451
  }
450
- EventPriceOracleUpdated.prototype.toString = function (_) {
452
+ EventPriceOracleUpdated.prototype.toString = function () {
451
453
  return "Credit manager ".concat((0, contractsRegister_1.getContractName)(this.creditManager), " updated: price oracle was updated. New price oracle ").concat((0, contractsRegister_1.getContractName)(this.priceOracle));
452
454
  };
453
455
  return EventPriceOracleUpdated;
@@ -466,7 +468,7 @@ var EventTransferPluginAllowed = /** @class */ (function (_super) {
466
468
  _this.state = opts.state;
467
469
  return _this;
468
470
  }
469
- EventTransferPluginAllowed.prototype.toString = function (_) {
471
+ EventTransferPluginAllowed.prototype.toString = function () {
470
472
  return "Credit manager ".concat((0, contractsRegister_1.getContractName)(this.creditManager), " updated: transfer plugin ").concat((0, contractsRegister_1.getContractName)(this.plugin), " was ").concat(this.state ? "allowed" : "forbidden");
471
473
  };
472
474
  return EventTransferPluginAllowed;
@@ -484,7 +486,7 @@ var EventNewInterestRateModel = /** @class */ (function (_super) {
484
486
  _this.newInterestRateModel = opts.newInterestRateModel;
485
487
  return _this;
486
488
  }
487
- EventNewInterestRateModel.prototype.toString = function (_) {
489
+ EventNewInterestRateModel.prototype.toString = function () {
488
490
  return "Pool ".concat((0, contractsRegister_1.getContractName)(this.pool), " updated: interest rate model was updated. New model: ").concat((0, contractsRegister_1.getContractName)(this.newInterestRateModel));
489
491
  };
490
492
  return EventNewInterestRateModel;
@@ -502,7 +504,7 @@ var EventNewCreditManagerConnected = /** @class */ (function (_super) {
502
504
  _this.creditManager = opts.creditManager;
503
505
  return _this;
504
506
  }
505
- EventNewCreditManagerConnected.prototype.toString = function (_) {
507
+ EventNewCreditManagerConnected.prototype.toString = function () {
506
508
  return "Pool ".concat((0, contractsRegister_1.getContractName)(this.pool), " updated: new credit manager ").concat((0, contractsRegister_1.getContractName)(this.creditManager), " was connected");
507
509
  };
508
510
  return EventNewCreditManagerConnected;
@@ -520,7 +522,7 @@ var EventBorrowForbidden = /** @class */ (function (_super) {
520
522
  _this.creditManager = opts.creditManager;
521
523
  return _this;
522
524
  }
523
- EventBorrowForbidden.prototype.toString = function (_) {
525
+ EventBorrowForbidden.prototype.toString = function () {
524
526
  return "Pool ".concat((0, contractsRegister_1.getContractName)(this.pool), " updated: credit manager ").concat((0, contractsRegister_1.getContractName)(this.creditManager), " was forbidden to borrow");
525
527
  };
526
528
  return EventBorrowForbidden;
@@ -563,7 +565,7 @@ var EventNewWithdrawFee = /** @class */ (function (_super) {
563
565
  _this.prevFee = Number(opts.oldFee);
564
566
  return _this;
565
567
  }
566
- EventNewWithdrawFee.prototype.toString = function (_) {
568
+ EventNewWithdrawFee.prototype.toString = function () {
567
569
  return this.prevFee === 0
568
570
  ? "Pool ".concat((0, contractsRegister_1.getContractName)(this.pool), " updated: withdraw fee was set to: ").concat(this.newFee / constants_1.PERCENTAGE_DECIMALS, "%")
569
571
  : "Pool ".concat((0, contractsRegister_1.getContractName)(this.pool), " updated: withdraw fee was ").concat(this.newFee > this.prevFee ? "increased" : "decreased", ": ").concat(this.prevFee / constants_1.PERCENTAGE_DECIMALS, "% => ").concat(this.newFee / constants_1.PERCENTAGE_DECIMALS, "%");
@@ -602,7 +604,7 @@ var EventTakeForever = /** @class */ (function (_super) {
602
604
  _this.to = opts.to;
603
605
  return _this;
604
606
  }
605
- EventTakeForever.prototype.toString = function (_) {
607
+ EventTakeForever.prototype.toString = function () {
606
608
  return "AccountFactory: account ".concat(this.creditAccount, " was taken forever and transferred to ").concat(this.to);
607
609
  };
608
610
  return EventTakeForever;
@@ -619,7 +621,7 @@ var EventPaused = /** @class */ (function (_super) {
619
621
  _this.contract = opts.contract;
620
622
  return _this;
621
623
  }
622
- EventPaused.prototype.toString = function (_) {
624
+ EventPaused.prototype.toString = function () {
623
625
  return "".concat((0, contractsRegister_1.getContractName)(this.contract), " was paused");
624
626
  };
625
627
  return EventPaused;
@@ -636,7 +638,7 @@ var EventUnPaused = /** @class */ (function (_super) {
636
638
  _this.contract = opts.contract;
637
639
  return _this;
638
640
  }
639
- EventUnPaused.prototype.toString = function (_) {
641
+ EventUnPaused.prototype.toString = function () {
640
642
  return "".concat((0, contractsRegister_1.getContractName)(this.contract), " was unpaused");
641
643
  };
642
644
  return EventUnPaused;
@@ -653,7 +655,7 @@ var EventPausableAdminAdded = /** @class */ (function (_super) {
653
655
  _this.admin = opts.admin;
654
656
  return _this;
655
657
  }
656
- EventPausableAdminAdded.prototype.toString = function (_) {
658
+ EventPausableAdminAdded.prototype.toString = function () {
657
659
  return "ACL: pausable admin ".concat(this.admin, " was added");
658
660
  };
659
661
  return EventPausableAdminAdded;
@@ -670,7 +672,7 @@ var EventPausableAdminRemoved = /** @class */ (function (_super) {
670
672
  _this.admin = opts.admin;
671
673
  return _this;
672
674
  }
673
- EventPausableAdminRemoved.prototype.toString = function (_) {
675
+ EventPausableAdminRemoved.prototype.toString = function () {
674
676
  return "ACL: pausable admin ".concat(this.admin, " was removed");
675
677
  };
676
678
  return EventPausableAdminRemoved;
@@ -687,7 +689,7 @@ var EventUnPausableAdminAdded = /** @class */ (function (_super) {
687
689
  _this.admin = opts.admin;
688
690
  return _this;
689
691
  }
690
- EventUnPausableAdminAdded.prototype.toString = function (_) {
692
+ EventUnPausableAdminAdded.prototype.toString = function () {
691
693
  return "ACL: unpausable admin ".concat(this.admin, " was added");
692
694
  };
693
695
  return EventUnPausableAdminAdded;
@@ -704,7 +706,7 @@ var EventUnPausableAdminRemoved = /** @class */ (function (_super) {
704
706
  _this.admin = opts.admin;
705
707
  return _this;
706
708
  }
707
- EventUnPausableAdminRemoved.prototype.toString = function (_) {
709
+ EventUnPausableAdminRemoved.prototype.toString = function () {
708
710
  return "ACL: unpausable admin ".concat(this.admin, " was removed");
709
711
  };
710
712
  return EventUnPausableAdminRemoved;
@@ -722,7 +724,7 @@ var EventTransferOwnership = /** @class */ (function (_super) {
722
724
  _this.newOwner = opts.admin;
723
725
  return _this;
724
726
  }
725
- EventTransferOwnership.prototype.toString = function (_) {
727
+ EventTransferOwnership.prototype.toString = function () {
726
728
  return "ACL: configurator was changed to ".concat(this.newOwner);
727
729
  };
728
730
  return EventTransferOwnership;
@@ -19,9 +19,9 @@ export declare class PoolData {
19
19
  readonly withdrawFee: number;
20
20
  readonly timestampLU: BigNumber;
21
21
  readonly cumulativeIndex_RAY: BigNumber;
22
+ readonly isPaused: boolean;
22
23
  constructor(payload: PoolDataPayload);
23
24
  getContractETH(signer: Signer): IPoolService;
24
- get isPaused(): boolean;
25
25
  }
26
26
  export interface PoolsStat {
27
27
  tvl: number;
package/lib/core/pool.js CHANGED
@@ -7,6 +7,7 @@ var types_1 = require("../types");
7
7
  var constants_1 = require("./constants");
8
8
  var PoolData = /** @class */ (function () {
9
9
  function PoolData(payload) {
10
+ this.isPaused = false;
10
11
  this.id = payload.addr;
11
12
  this.address = payload.addr;
12
13
  this.underlyingToken = payload.underlying || "";
@@ -29,13 +30,6 @@ var PoolData = /** @class */ (function () {
29
30
  PoolData.prototype.getContractETH = function (signer) {
30
31
  return types_1.IPoolService__factory.connect(this.address, signer);
31
32
  };
32
- Object.defineProperty(PoolData.prototype, "isPaused", {
33
- get: function () {
34
- return false;
35
- },
36
- enumerable: false,
37
- configurable: true
38
- });
39
33
  return PoolData;
40
34
  }());
41
35
  exports.PoolData = PoolData;
package/lib/core/price.js CHANGED
@@ -2,8 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.calcTotalPrice = void 0;
4
4
  var ethers_1 = require("ethers");
5
+ var constants_1 = require("./constants");
5
6
  var calcTotalPrice = function (price, amount, decimals) {
6
7
  if (decimals === void 0) { decimals = 18; }
7
- return amount.mul(price).div(ethers_1.BigNumber.from(10).pow(decimals));
8
+ return amount
9
+ .mul(constants_1.WAD)
10
+ .mul(price)
11
+ .div(ethers_1.BigNumber.from(10).pow(decimals))
12
+ .div(constants_1.PRICE_DECIMALS);
8
13
  };
9
14
  exports.calcTotalPrice = calcTotalPrice;
@@ -26,11 +26,9 @@ export declare class Strategy {
26
26
  leveragableCollateral: Array<string>;
27
27
  baseAssets: Array<string>;
28
28
  constructor(payload: StrategyPayload);
29
- maxAPY(apy: number, maxLeverage: number, poolApy: PoolList): number;
29
+ maxAPY(maxLeverage: number, poolApy: PoolList): number;
30
30
  overallAPY(apy: number, leverage: number, depositCollateral: string, borrowAPY: number): number;
31
31
  liquidationPrice(borrowed: TokenDescription, collateral: TokenDescription, lp: TokenDescription, ltCollateral: BigNumber): BigNumber;
32
- private roi;
33
- private minBorrowApy;
34
32
  private farmLev;
35
33
  private inBaseAssets;
36
34
  private inLeveragableAssets;
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Strategy = void 0;
4
4
  var ethers_1 = require("ethers");
5
- var constants_1 = require("../core/constants");
6
- var price_1 = require("../core/price");
5
+ var constants_1 = require("./constants");
6
+ var price_1 = require("./price");
7
7
  var Strategy = /** @class */ (function () {
8
8
  function Strategy(payload) {
9
9
  this.apy = payload.apy;
@@ -14,14 +14,15 @@ var Strategy = /** @class */ (function () {
14
14
  this.leveragableCollateral = payload.leveragableCollateral;
15
15
  this.baseAssets = payload.baseAssets;
16
16
  }
17
- Strategy.prototype.maxAPY = function (apy, maxLeverage, poolApy) {
18
- var minApy = this.minBorrowApy(poolApy);
19
- return this.roi(apy, maxLeverage, maxLeverage - constants_1.LEVERAGE_DECIMALS, minApy);
17
+ Strategy.prototype.maxAPY = function (maxLeverage, poolApy) {
18
+ var minApy = minBorrowApy(poolApy);
19
+ return roi(this.apy || 0, maxLeverage, maxLeverage - constants_1.LEVERAGE_DECIMALS, minApy);
20
20
  };
21
21
  Strategy.prototype.overallAPY = function (apy, leverage, depositCollateral, borrowAPY) {
22
22
  var farmLev = this.farmLev(leverage, depositCollateral);
23
- return this.roi(apy, farmLev, leverage - constants_1.LEVERAGE_DECIMALS, borrowAPY);
23
+ return roi(apy, farmLev, leverage - constants_1.LEVERAGE_DECIMALS, borrowAPY);
24
24
  };
25
+ // eslint-disable-next-line class-methods-use-this
25
26
  Strategy.prototype.liquidationPrice = function (borrowed, collateral, lp, ltCollateral) {
26
27
  var borrowedMoney = (0, price_1.calcTotalPrice)(borrowed.price, borrowed.amount, borrowed.decimals);
27
28
  var collateralMoney = (0, price_1.calcTotalPrice)(collateral.price, collateral.amount, collateral.decimals)
@@ -32,13 +33,6 @@ var Strategy = /** @class */ (function () {
32
33
  ? borrowedMoney.sub(collateralMoney).mul(constants_1.WAD).div(lpMoney)
33
34
  : ethers_1.BigNumber.from(0);
34
35
  };
35
- Strategy.prototype.roi = function (apy, farmLev, debtLev, borrowAPY) {
36
- return (apy * farmLev - borrowAPY * debtLev) / constants_1.LEVERAGE_DECIMALS;
37
- };
38
- Strategy.prototype.minBorrowApy = function (poolApy) {
39
- var apys = Object.values(poolApy).sort(function (a, b) { return a.borrowRate - b.borrowRate; });
40
- return apys.length > 0 ? apys[0].borrowRate : 0;
41
- };
42
36
  Strategy.prototype.farmLev = function (leverage, depositCollateral) {
43
37
  return this.inBaseAssets(depositCollateral) ||
44
38
  this.inLeveragableAssets(depositCollateral)
@@ -54,3 +48,10 @@ var Strategy = /** @class */ (function () {
54
48
  return Strategy;
55
49
  }());
56
50
  exports.Strategy = Strategy;
51
+ function roi(apy, farmLev, debtLev, borrowAPY) {
52
+ return (apy * farmLev - borrowAPY * debtLev) / constants_1.LEVERAGE_DECIMALS;
53
+ }
54
+ function minBorrowApy(poolApy) {
55
+ var apys = Object.values(poolApy).sort(function (a, b) { return a.borrowRate - b.borrowRate; });
56
+ return apys.length > 0 ? apys[0].borrowRate : 0;
57
+ }
@@ -5,5 +5,5 @@ var VotingPower;
5
5
  (function (VotingPower) {
6
6
  VotingPower[VotingPower["A"] = 0] = "A";
7
7
  VotingPower[VotingPower["B"] = 1] = "B";
8
- VotingPower[VotingPower["ZERO_VOTING_POWER"] = 2] = "ZERO_VOTING_POWER";
8
+ VotingPower[VotingPower["ZERO_VOTING_POWER"] = 2] = "ZERO_VOTING_POWER"; // zero voting power & B-type vesting parameters
9
9
  })(VotingPower = exports.VotingPower || (exports.VotingPower = {}));
@@ -2,7 +2,7 @@ import { BigNumber } from "ethers";
2
2
  import { TokenData } from "../tokens/tokenData";
3
3
  import { EVMTx, EVMTxProps } from "./eventOrTx";
4
4
  export interface TxSerialized {
5
- type: "TxAddLiquidity" | "TxRemoveLiquidity" | "TxSwap" | "TxAddCollateral" | "TxIncreaseBorrowAmount" | "TxOpenAccount" | "TxRepayAccount" | "TxCloseAccount" | "TxApprove";
5
+ type: "TxAddLiquidity" | "TxRemoveLiquidity" | "TxSwap" | "TxAddCollateral" | "TxIncreaseBorrowAmount" | "TxOpenAccount" | "TxRepayAccount" | "TxCloseAccount" | "TxApprove" | "TxOpenMultitokenAccount";
6
6
  content: string;
7
7
  }
8
8
  export declare class TxSerializer {
@@ -97,13 +97,28 @@ export declare class TxOpenAccount extends EVMTx {
97
97
  toString(tokenData: Record<string, TokenData>): string;
98
98
  serialize(): TxSerialized;
99
99
  }
100
+ interface TxOpenMultitokenAccountProps extends EVMTxProps {
101
+ borrowedAmount: BigNumber;
102
+ creditManager: string;
103
+ underlyingToken: string;
104
+ assets: Array<string>;
105
+ }
106
+ export declare class TxOpenMultitokenAccount extends EVMTx {
107
+ readonly borrowedAmount: BigNumber;
108
+ readonly creditManager: string;
109
+ readonly underlyingToken: string;
110
+ readonly assets: Array<string>;
111
+ constructor(opts: TxOpenMultitokenAccountProps);
112
+ toString(tokenData: Record<string, TokenData>): string;
113
+ serialize(): TxSerialized;
114
+ }
100
115
  interface RepayAccountProps extends EVMTxProps {
101
116
  creditManager: string;
102
117
  }
103
118
  export declare class TxRepayAccount extends EVMTx {
104
119
  readonly creditManager: string;
105
120
  constructor(opts: RepayAccountProps);
106
- toString(_: Record<string, TokenData>): string;
121
+ toString(): string;
107
122
  serialize(): TxSerialized;
108
123
  }
109
124
  interface CloseAccountProps extends EVMTxProps {
@@ -112,7 +127,7 @@ interface CloseAccountProps extends EVMTxProps {
112
127
  export declare class TxCloseAccount extends EVMTx {
113
128
  readonly creditManager: string;
114
129
  constructor(opts: CloseAccountProps);
115
- toString(_: Record<string, TokenData>): string;
130
+ toString(): string;
116
131
  serialize(): TxSerialized;
117
132
  }
118
133
  interface ApproveProps extends EVMTxProps {
@@ -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.TxOpenAccount = exports.TxIncreaseBorrowAmount = exports.TxAddCollateral = exports.TXSwap = exports.TxRemoveLiquidity = exports.TxAddLiquidity = exports.TxSerializer = void 0;
18
+ exports.TxApprove = exports.TxCloseAccount = exports.TxRepayAccount = 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 formatter_1 = require("../utils/formatter");
21
21
  var eventOrTx_1 = require("./eventOrTx");
@@ -49,6 +49,8 @@ var TxSerializer = /** @class */ (function () {
49
49
  return new TxCloseAccount(params);
50
50
  case "TxApprove":
51
51
  return new TxApprove(params);
52
+ case "TxOpenMultitokenAccount":
53
+ return new TxOpenMultitokenAccount(params);
52
54
  default:
53
55
  throw new Error("Unknown transaction for parsing");
54
56
  }
@@ -231,6 +233,40 @@ var TxOpenAccount = /** @class */ (function (_super) {
231
233
  return TxOpenAccount;
232
234
  }(eventOrTx_1.EVMTx));
233
235
  exports.TxOpenAccount = TxOpenAccount;
236
+ var TxOpenMultitokenAccount = /** @class */ (function (_super) {
237
+ __extends(TxOpenMultitokenAccount, _super);
238
+ function TxOpenMultitokenAccount(opts) {
239
+ var _this = _super.call(this, {
240
+ block: opts.block,
241
+ txHash: opts.txHash,
242
+ txStatus: opts.txStatus,
243
+ timestamp: opts.timestamp
244
+ }) || this;
245
+ _this.borrowedAmount = ethers_1.BigNumber.from(opts.borrowedAmount);
246
+ _this.underlyingToken = opts.underlyingToken;
247
+ _this.creditManager = opts.creditManager;
248
+ _this.assets = opts.assets;
249
+ return _this;
250
+ }
251
+ TxOpenMultitokenAccount.prototype.toString = function (tokenData) {
252
+ var underlyingToken = tokenData[this.underlyingToken.toLowerCase()];
253
+ var assetSymbols = this.assets.reduce(function (acc, assetAddress) {
254
+ var token = tokenData[assetAddress.toLowerCase()];
255
+ if (token)
256
+ acc.push(token.symbol);
257
+ return acc;
258
+ }, []);
259
+ return "Credit account ".concat((0, contractsRegister_1.getContractName)(this.creditManager), ": opening. Borrowed amount: ").concat((0, formatter_1.formatBN)(this.borrowedAmount, (underlyingToken === null || underlyingToken === void 0 ? void 0 : underlyingToken.decimals) || 18), " ").concat(underlyingToken === null || underlyingToken === void 0 ? void 0 : underlyingToken.symbol, "; assets: ").concat(assetSymbols.join(", "));
260
+ };
261
+ TxOpenMultitokenAccount.prototype.serialize = function () {
262
+ return {
263
+ type: "TxOpenMultitokenAccount",
264
+ content: JSON.stringify(this)
265
+ };
266
+ };
267
+ return TxOpenMultitokenAccount;
268
+ }(eventOrTx_1.EVMTx));
269
+ exports.TxOpenMultitokenAccount = TxOpenMultitokenAccount;
234
270
  var TxRepayAccount = /** @class */ (function (_super) {
235
271
  __extends(TxRepayAccount, _super);
236
272
  function TxRepayAccount(opts) {
@@ -243,7 +279,7 @@ var TxRepayAccount = /** @class */ (function (_super) {
243
279
  _this.creditManager = opts.creditManager;
244
280
  return _this;
245
281
  }
246
- TxRepayAccount.prototype.toString = function (_) {
282
+ TxRepayAccount.prototype.toString = function () {
247
283
  return "Credit account ".concat((0, contractsRegister_1.getContractName)(this.creditManager), ": Repaying account");
248
284
  };
249
285
  TxRepayAccount.prototype.serialize = function () {
@@ -267,7 +303,7 @@ var TxCloseAccount = /** @class */ (function (_super) {
267
303
  _this.creditManager = opts.creditManager;
268
304
  return _this;
269
305
  }
270
- TxCloseAccount.prototype.toString = function (_) {
306
+ TxCloseAccount.prototype.toString = function () {
271
307
  return "Credit account ".concat((0, contractsRegister_1.getContractName)(this.creditManager), ": Closing account");
272
308
  };
273
309
  TxCloseAccount.prototype.serialize = function () {
package/lib/index.d.ts CHANGED
@@ -23,12 +23,10 @@ export * from "./payload/token";
23
23
  export * from "./utils/formatter";
24
24
  export * from "./utils/loading";
25
25
  export * from "./utils/validate";
26
- export * from "./utils/events";
27
26
  export * from "./utils/math";
28
27
  export * from "./payload/graphPayload";
29
28
  export * from "./types/index";
30
29
  export * from "./core/strategy";
31
- export type { IDataCompressor, IWETHGateway } from "./types";
32
30
  export { TokenType } from "./tokens/tokenType";
33
31
  export * from "./tokens/token";
34
32
  export * from "./tokens/tokenData";
@@ -43,6 +41,14 @@ export * from "./apy/convexAPY";
43
41
  export * from "./core/history";
44
42
  export * from "./utils/multicall";
45
43
  export * from "./utils/types";
44
+ export * from "./utils/errors";
45
+ export * from "./strategies/convex";
46
+ export * from "./strategies/creditFacade";
47
+ export * from "./strategies/curve";
48
+ export * from "./strategies/lido";
49
+ export * from "./strategies/uniswapV2";
50
+ export * from "./strategies/uniswapV3";
51
+ export * from "./strategies/yearn";
46
52
  export { callRepeater } from "./utils/repeater";
47
53
  export { getContractName } from "./contracts/contractsRegister";
48
54
  export { AdapterInterface } from "./contracts/adapters";
package/lib/index.js CHANGED
@@ -40,7 +40,6 @@ __exportStar(require("./payload/token"), exports);
40
40
  __exportStar(require("./utils/formatter"), exports);
41
41
  __exportStar(require("./utils/loading"), exports);
42
42
  __exportStar(require("./utils/validate"), exports);
43
- __exportStar(require("./utils/events"), exports);
44
43
  __exportStar(require("./utils/math"), exports);
45
44
  __exportStar(require("./payload/graphPayload"), exports);
46
45
  __exportStar(require("./types/index"), exports);
@@ -61,6 +60,14 @@ __exportStar(require("./apy/convexAPY"), exports);
61
60
  __exportStar(require("./core/history"), exports);
62
61
  __exportStar(require("./utils/multicall"), exports);
63
62
  __exportStar(require("./utils/types"), exports);
63
+ __exportStar(require("./utils/errors"), exports);
64
+ __exportStar(require("./strategies/convex"), exports);
65
+ __exportStar(require("./strategies/creditFacade"), exports);
66
+ __exportStar(require("./strategies/curve"), exports);
67
+ __exportStar(require("./strategies/lido"), exports);
68
+ __exportStar(require("./strategies/uniswapV2"), exports);
69
+ __exportStar(require("./strategies/uniswapV3"), exports);
70
+ __exportStar(require("./strategies/yearn"), exports);
64
71
  var repeater_1 = require("./utils/repeater");
65
72
  Object.defineProperty(exports, "callRepeater", { enumerable: true, get: function () { return repeater_1.callRepeater; } });
66
73
  var contractsRegister_1 = require("./contracts/contractsRegister");
@@ -446,7 +446,7 @@ exports.priceFeedsByNetwork = {
446
446
  curveSymbol: "gusd3CRV"
447
447
  }
448
448
  },
449
- //GEARBOX
449
+ // GEARBOX
450
450
  dDAI: {
451
451
  priceFeedETH: {
452
452
  type: oracles_1.OracleType.CHAINLINK_ORACLE,
@@ -1,4 +1,4 @@
1
- import { LPWithdrawPathFinder, Path } from "./path";
1
+ import type { LPWithdrawPathFinder, Path } from "./path";
2
2
  export declare class ConvexLPPathFinder implements LPWithdrawPathFinder {
3
3
  findWithdrawPaths(p: Path): Promise<Array<Path>>;
4
4
  }
@@ -38,40 +38,37 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.ConvexLPPathFinder = void 0;
40
40
  var convex_1 = require("../tokens/convex");
41
+ var mappers_1 = require("../utils/mappers");
41
42
  var ConvexLPPathFinder = /** @class */ (function () {
42
43
  function ConvexLPPathFinder() {
43
44
  }
45
+ // eslint-disable-next-line class-methods-use-this
44
46
  ConvexLPPathFinder.prototype.findWithdrawPaths = function (p) {
45
47
  return __awaiter(this, void 0, void 0, function () {
46
- var pids, _i, _a, _b, cvxToken, tokenData, currentBalance;
47
- return __generator(this, function (_c) {
48
- switch (_c.label) {
49
- case 0:
50
- pids = new Set();
51
- for (_i = 0, _a = Object.entries(convex_1.convexTokens); _i < _a.length; _i++) {
52
- _b = _a[_i], cvxToken = _b[0], tokenData = _b[1];
53
- currentBalance = p.popBalance(cvxToken);
54
- if (currentBalance.gt(1)) {
55
- pids.add(tokenData.pid);
56
- }
57
- }
58
- return [4 /*yield*/, p.withdrawTokens()];
59
- case 1:
60
- // const convexPathFinder = ConvexPathFinder__factory.connect(
61
- // pathFindersByNetwork[p.networkType].CONVEX_PATH_FINDER,
62
- // p.provider
63
- // );
64
- // const tokenBalances = await convexPathFinder.calcRewards(
65
- // p.creditAccount.addr,
66
- // Array.from(pids)
67
- // );
68
- // for (let balance of tokenBalances) {
69
- // p.balances[balance.token] = p.balances[balance.token].add(
70
- // balance.balance
71
- // );
72
- // }
73
- return [2 /*return*/, _c.sent()];
74
- }
48
+ var pids;
49
+ return __generator(this, function (_a) {
50
+ pids = (0, mappers_1.objectEntries)(convex_1.convexTokens).reduce(function (acc, _a) {
51
+ var cvxToken = _a[0], tokenData = _a[1];
52
+ var currentBalance = p.popBalance(cvxToken);
53
+ if (currentBalance.gt(1)) {
54
+ pids.add(tokenData.pid);
55
+ }
56
+ return acc;
57
+ }, new Set());
58
+ // const convexPathFinder = ConvexPathFinder__factory.connect(
59
+ // pathFindersByNetwork[p.networkType].CONVEX_PATH_FINDER,
60
+ // p.provider
61
+ // );
62
+ // const tokenBalances = await convexPathFinder.calcRewards(
63
+ // p.creditAccount.addr,
64
+ // Array.from(pids)
65
+ // );
66
+ // for (let balance of tokenBalances) {
67
+ // p.balances[balance.token] = p.balances[balance.token].add(
68
+ // balance.balance
69
+ // );
70
+ // }
71
+ return [2 /*return*/, p.withdrawTokens()];
75
72
  });
76
73
  });
77
74
  };
@@ -1,4 +1,4 @@
1
- import { LPWithdrawPathFinder, Path } from "./path";
1
+ import type { LPWithdrawPathFinder, Path } from "./path";
2
2
  import { CurveLPToken } from "../tokens/curveLP";
3
3
  import { CurvePoolContract } from "../contracts/contracts";
4
4
  export declare class CurvePathFinder implements LPWithdrawPathFinder {
@@ -45,12 +45,11 @@ var types_1 = require("../types");
45
45
  var CurvePathFinder = /** @class */ (function () {
46
46
  function CurvePathFinder(token) {
47
47
  this.lpToken = token;
48
- var curvePools = curveLP_1.curveTokens[this.lpToken].lpActions.filter(function (a) { return a.type == tradeTypes_1.TradeType.CurveWithdrawLP; });
48
+ var curvePools = curveLP_1.curveTokens[this.lpToken].lpActions.filter(function (a) { return a.type === tradeTypes_1.TradeType.CurveWithdrawLP; });
49
49
  if (curvePools.length !== 1)
50
50
  throw new Error("Cant find Withdrawer");
51
51
  this.contract = curvePools[0].contract;
52
- var wrapper = contracts_1.contractParams[curvePools[0].contract]
53
- .wrapper;
52
+ var wrapper = contracts_1.contractParams[curvePools[0].contract].wrapper;
54
53
  if (wrapper) {
55
54
  this.contract = wrapper;
56
55
  }
@@ -66,9 +65,8 @@ var CurvePathFinder = /** @class */ (function () {
66
65
  lpBalance = p.popBalance(this.lpToken);
67
66
  multiCallContract = new multicall_1.MultiCallContract(contracts_1.contractsByAddress[this.contract], types_1.ICurvePool__factory.createInterface(), p.provider);
68
67
  data = [];
69
- for (i = 0; i < nCoins; i++) {
68
+ for (i = 0; i < nCoins; i += 1) {
70
69
  data.push({
71
- // @ts-ignore
72
70
  method: "calc_withdraw_one_coin(uint256,int128)",
73
71
  params: [lpBalance, i]
74
72
  });
@@ -76,9 +74,9 @@ var CurvePathFinder = /** @class */ (function () {
76
74
  return [4 /*yield*/, multiCallContract.call(data)];
77
75
  case 1:
78
76
  balances = _a.sent();
79
- console.log(balances);
77
+ console.debug(balances);
80
78
  paths = [];
81
- for (i = 0; i < nCoins; i++) {
79
+ for (i = 0; i < nCoins; i += 1) {
82
80
  newPath = p.clone();
83
81
  // newPath.balances[coins[i]] = newPath.balances[coins[i]].add(balances[i]);
84
82
  // newPath.calls.push({
@@ -24,7 +24,7 @@ export declare class Path {
24
24
  totalGasLimit: number;
25
25
  });
26
26
  popBalance(token: SupportedToken): BigNumber;
27
- private comparedByPriority;
27
+ private static comparedByPriority;
28
28
  static findBestPath(creditAccount: CreditAccountData, creditManager: CreditManagerData, provider: ethers.providers.Provider): Promise<void>;
29
29
  withdrawTokens(): Promise<Array<Path>>;
30
30
  clone(): Path;