@gearbox-protocol/sdk 0.0.102 → 0.0.103

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 (119) hide show
  1. package/.eslintignore +4 -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 +3 -3
  7. package/lib/contracts/contracts.js +2 -2
  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 +1 -2
  26. package/lib/index.js +1 -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/curve.d.ts +6 -60
  39. package/lib/strategies/curve.js +6 -0
  40. package/lib/strategies/uniswapV2.js +3 -19
  41. package/lib/strategies/uniswapV3.js +1 -1
  42. package/lib/strategies/yearn.js +15 -11
  43. package/lib/tokens/convex.d.ts +3 -3
  44. package/lib/tokens/curveLP.d.ts +2 -2
  45. package/lib/tokens/curveLP.js +1 -1
  46. package/lib/tokens/gear.d.ts +2 -2
  47. package/lib/tokens/gear.js +1 -1
  48. package/lib/tokens/normal.d.ts +1 -1
  49. package/lib/tokens/token.js +4 -4
  50. package/lib/tokens/tokenData.d.ts +3 -1
  51. package/lib/tokens/tokenData.js +10 -8
  52. package/lib/tokens/yearn.d.ts +3 -3
  53. package/lib/utils/errors.d.ts +6 -0
  54. package/lib/utils/errors.js +13 -0
  55. package/lib/utils/formatter.d.ts +1 -1
  56. package/lib/utils/formatter.js +17 -14
  57. package/lib/utils/loading.d.ts +2 -1
  58. package/lib/utils/loading.js +9 -13
  59. package/lib/utils/mappers.js +2 -2
  60. package/lib/utils/network.js +2 -2
  61. package/lib/utils/repeater.js +12 -24
  62. package/lib/utils/validate.js +1 -1
  63. package/package.json +26 -8
  64. package/src/apy/convexAPY.ts +6 -6
  65. package/src/apy/lidoAPY.ts +12 -11
  66. package/src/contracts/contracts.ts +8 -7
  67. package/src/core/constants.ts +1 -1
  68. package/src/core/creditAccount.ts +28 -5
  69. package/src/core/creditManager.ts +29 -4
  70. package/src/core/creditOperation.ts +7 -7
  71. package/src/core/creditSession.ts +25 -5
  72. package/src/core/errors.ts +1 -0
  73. package/src/core/eventOrTx.ts +8 -5
  74. package/src/core/events.ts +85 -24
  75. package/src/core/history.ts +46 -46
  76. package/src/core/operations.ts +6 -0
  77. package/src/core/pool.ts +16 -4
  78. package/src/core/price.ts +7 -3
  79. package/src/core/strategy.ts +27 -23
  80. package/src/core/tokenDistributor.ts +2 -2
  81. package/src/core/transactions.ts +427 -350
  82. package/src/index.ts +1 -3
  83. package/src/oracles/priceFeeds.ts +523 -523
  84. package/src/pathfinder/contracts.ts +15 -13
  85. package/src/pathfinder/convexLP.ts +29 -25
  86. package/src/pathfinder/curveLP.ts +57 -53
  87. package/src/pathfinder/path.ts +17 -9
  88. package/src/pathfinder/priority.ts +11 -11
  89. package/src/pathfinder/trade.ts +84 -77
  90. package/src/pathfinder/tradeTypes.ts +98 -94
  91. package/src/pathfinder/yVault.ts +26 -11
  92. package/src/payload/token.ts +3 -3
  93. package/src/strategies/convex.ts +217 -210
  94. package/src/strategies/creditFacade.ts +70 -53
  95. package/src/strategies/curve.ts +263 -194
  96. package/src/strategies/lido.ts +33 -37
  97. package/src/strategies/uniswapV2.ts +90 -112
  98. package/src/strategies/uniswapV3.ts +114 -91
  99. package/src/strategies/yearn.ts +58 -62
  100. package/src/tokens/connectors.ts +6 -6
  101. package/src/tokens/convex.ts +297 -296
  102. package/src/tokens/curveLP.ts +170 -165
  103. package/src/tokens/gear.ts +47 -45
  104. package/src/tokens/normal.ts +801 -802
  105. package/src/tokens/token.ts +9 -5
  106. package/src/tokens/tokenData.ts +19 -9
  107. package/src/tokens/tokenType.ts +11 -11
  108. package/src/tokens/yearn.ts +126 -124
  109. package/src/utils/errors.ts +11 -0
  110. package/src/utils/formatter.ts +22 -18
  111. package/src/utils/loading.ts +14 -6
  112. package/src/utils/mappers.ts +8 -6
  113. package/src/utils/multicall.ts +2 -0
  114. package/src/utils/network.ts +21 -21
  115. package/src/utils/repeater.ts +2 -2
  116. package/src/utils/validate.ts +1 -1
  117. package/lib/utils/events.d.ts +0 -2
  118. package/lib/utils/events.js +0 -13
  119. package/src/utils/events.ts +0 -10
@@ -8,36 +8,9 @@ export declare class CurveCalls {
8
8
  static add_all_liquidity_one_coin(i: BigNumberish, rateMinRAY: BigNumberish): string;
9
9
  static remove_liquidity_one_coin(token_amount: BigNumberish, i: BigNumberish, min_amount: BigNumberish): string;
10
10
  static remove_all_liquidity_one_coin(i: BigNumberish, minRateRAY: BigNumberish): string;
11
- static add_liquidity(amounts: [BigNumberish, BigNumberish] | [
12
- BigNumberish,
13
- BigNumberish,
14
- BigNumberish
15
- ] | [
16
- BigNumberish,
17
- BigNumberish,
18
- BigNumberish,
19
- BigNumberish
20
- ], min_mint_amount: BigNumberish): string;
21
- static remove_liquidity(amount: BigNumberish, min_amounts: [BigNumberish, BigNumberish] | [
22
- BigNumberish,
23
- BigNumberish,
24
- BigNumberish
25
- ] | [
26
- BigNumberish,
27
- BigNumberish,
28
- BigNumberish,
29
- BigNumberish
30
- ]): string;
31
- static remove_liquidity_imbalance(amounts: [BigNumberish, BigNumberish] | [
32
- BigNumberish,
33
- BigNumberish,
34
- BigNumberish
35
- ] | [
36
- BigNumberish,
37
- BigNumberish,
38
- BigNumberish,
39
- BigNumberish
40
- ], max_burn_amount: BigNumberish): string;
11
+ static add_liquidity(amounts: [BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish, BigNumberish], min_mint_amount: BigNumberish): string;
12
+ static remove_liquidity(amount: BigNumberish, min_amounts: [BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish, BigNumberish]): string;
13
+ static remove_liquidity_imbalance(amounts: [BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish, BigNumberish], max_burn_amount: BigNumberish): string;
41
14
  }
42
15
  export declare class CurveMulticaller {
43
16
  private readonly _address;
@@ -55,34 +28,7 @@ export declare class CurveMulticaller {
55
28
  target: string;
56
29
  callData: string;
57
30
  };
58
- add_liquidity(amounts: [BigNumberish, BigNumberish] | [
59
- BigNumberish,
60
- BigNumberish,
61
- BigNumberish
62
- ] | [
63
- BigNumberish,
64
- BigNumberish,
65
- BigNumberish,
66
- BigNumberish
67
- ], min_mint_amount: BigNumberish): MultiCallStruct;
68
- remove_liquidity(amount: BigNumberish, min_amounts: [BigNumberish, BigNumberish] | [
69
- BigNumberish,
70
- BigNumberish,
71
- BigNumberish
72
- ] | [
73
- BigNumberish,
74
- BigNumberish,
75
- BigNumberish,
76
- BigNumberish
77
- ]): MultiCallStruct;
78
- remove_liquidity_imbalance(amounts: [BigNumberish, BigNumberish] | [
79
- BigNumberish,
80
- BigNumberish,
81
- BigNumberish
82
- ] | [
83
- BigNumberish,
84
- BigNumberish,
85
- BigNumberish,
86
- BigNumberish
87
- ], max_burn_amount: BigNumberish): MultiCallStruct;
31
+ add_liquidity(amounts: [BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish, BigNumberish], min_mint_amount: BigNumberish): MultiCallStruct;
32
+ remove_liquidity(amount: BigNumberish, min_amounts: [BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish, BigNumberish]): MultiCallStruct;
33
+ remove_liquidity_imbalance(amounts: [BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish, BigNumberish], max_burn_amount: BigNumberish): MultiCallStruct;
88
34
  }
@@ -34,6 +34,8 @@ var CurveCalls = /** @class */ (function () {
34
34
  return types_1.CurveV1Adapter3Assets__factory.createInterface().encodeFunctionData("add_liquidity", [amounts, min_mint_amount]);
35
35
  case 4:
36
36
  return types_1.CurveV1Adapter4Assets__factory.createInterface().encodeFunctionData("add_liquidity", [amounts, min_mint_amount]);
37
+ default:
38
+ throw new Error("Wrong calls number: add_liquidity");
37
39
  }
38
40
  };
39
41
  CurveCalls.remove_liquidity = function (amount, min_amounts) {
@@ -44,6 +46,8 @@ var CurveCalls = /** @class */ (function () {
44
46
  return types_1.CurveV1Adapter3Assets__factory.createInterface().encodeFunctionData("remove_liquidity", [amount, min_amounts]);
45
47
  case 4:
46
48
  return types_1.CurveV1Adapter4Assets__factory.createInterface().encodeFunctionData("remove_liquidity", [amount, min_amounts]);
49
+ default:
50
+ throw new Error("Wrong calls number: remove_liquidity");
47
51
  }
48
52
  };
49
53
  CurveCalls.remove_liquidity_imbalance = function (amounts, max_burn_amount) {
@@ -54,6 +58,8 @@ var CurveCalls = /** @class */ (function () {
54
58
  return types_1.CurveV1Adapter3Assets__factory.createInterface().encodeFunctionData("remove_liquidity_imbalance", [amounts, max_burn_amount]);
55
59
  case 4:
56
60
  return types_1.CurveV1Adapter4Assets__factory.createInterface().encodeFunctionData("remove_liquidity_imbalance", [amounts, max_burn_amount]);
61
+ default:
62
+ throw new Error("Wrong calls number: remove_liquidity_imbalance");
57
63
  }
58
64
  };
59
65
  return CurveCalls;
@@ -6,29 +6,13 @@ var UniswapV2Calls = /** @class */ (function () {
6
6
  function UniswapV2Calls() {
7
7
  }
8
8
  UniswapV2Calls.swapExactTokensForTokens = function (amountIn, amountOutMin, path, to, deadline) {
9
- return types_1.UniswapV2Adapter__factory.createInterface().encodeFunctionData("swapExactTokensForTokens", [
10
- amountIn,
11
- amountOutMin,
12
- path,
13
- to,
14
- deadline
15
- ]);
9
+ return types_1.UniswapV2Adapter__factory.createInterface().encodeFunctionData("swapExactTokensForTokens", [amountIn, amountOutMin, path, to, deadline]);
16
10
  };
17
11
  UniswapV2Calls.swapTokensForExactTokens = function (amountOut, amountInMax, path, to, deadline) {
18
- return types_1.UniswapV2Adapter__factory.createInterface().encodeFunctionData("swapTokensForExactTokens", [
19
- amountOut,
20
- amountInMax,
21
- path,
22
- to,
23
- deadline
24
- ]);
12
+ return types_1.UniswapV2Adapter__factory.createInterface().encodeFunctionData("swapTokensForExactTokens", [amountOut, amountInMax, path, to, deadline]);
25
13
  };
26
14
  UniswapV2Calls.swapAllTokensForTokens = function (rateMinRAY, path, deadline) {
27
- return types_1.UniswapV2Adapter__factory.createInterface().encodeFunctionData("swapAllTokensForTokens", [
28
- rateMinRAY,
29
- path,
30
- deadline
31
- ]);
15
+ return types_1.UniswapV2Adapter__factory.createInterface().encodeFunctionData("swapAllTokensForTokens", [rateMinRAY, path, deadline]);
32
16
  };
33
17
  return UniswapV2Calls;
34
18
  }());
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- //import { BigNumberish } from "ethers";
2
+ // import { BigNumberish } from "ethers";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.UniswapV3Multicaller = exports.UniswapV3Calls = void 0;
5
5
  var types_1 = require("../types");
@@ -8,14 +8,15 @@ var YearnV2Calls = /** @class */ (function () {
8
8
  YearnV2Calls.deposit = function (amount, recipient) {
9
9
  var contractInterface = types_1.YearnV2Adapter__factory.createInterface();
10
10
  if (amount && recipient) {
11
- return contractInterface.encodeFunctionData("deposit(uint256,address)", [amount, recipient]);
11
+ return contractInterface.encodeFunctionData("deposit(uint256,address)", [
12
+ amount,
13
+ recipient
14
+ ]);
12
15
  }
13
- else if (amount) {
16
+ if (amount) {
14
17
  return contractInterface.encodeFunctionData("deposit(uint256)", [amount]);
15
18
  }
16
- else {
17
- return contractInterface.encodeFunctionData("deposit()");
18
- }
19
+ return contractInterface.encodeFunctionData("deposit()");
19
20
  };
20
21
  YearnV2Calls.withdraw = function (maxShares, recipient, maxLoss) {
21
22
  var contractInterface = types_1.YearnV2Adapter__factory.createInterface();
@@ -23,14 +24,17 @@ var YearnV2Calls = /** @class */ (function () {
23
24
  return contractInterface.encodeFunctionData("withdraw(uint256,address,uint256)", [maxShares, recipient, maxLoss]);
24
25
  }
25
26
  if (maxShares && recipient) {
26
- return contractInterface.encodeFunctionData("withdraw(uint256,address)", [maxShares, recipient]);
27
- }
28
- else if (maxShares) {
29
- return contractInterface.encodeFunctionData("withdraw(uint256)", [maxShares]);
27
+ return contractInterface.encodeFunctionData("withdraw(uint256,address)", [
28
+ maxShares,
29
+ recipient
30
+ ]);
30
31
  }
31
- else {
32
- return contractInterface.encodeFunctionData("withdraw()");
32
+ if (maxShares) {
33
+ return contractInterface.encodeFunctionData("withdraw(uint256)", [
34
+ maxShares
35
+ ]);
33
36
  }
37
+ return contractInterface.encodeFunctionData("withdraw()");
34
38
  };
35
39
  return YearnV2Calls;
36
40
  }());
@@ -1,7 +1,7 @@
1
1
  import { TradeAction } from "../pathfinder/tradeTypes";
2
- import { TokenBase } from "./token";
3
- import { ConvexPoolContract } from "../contracts/contracts";
4
- import { CurveLPToken } from "./curveLP";
2
+ import type { TokenBase } from "./token";
3
+ import type { ConvexPoolContract } from "../contracts/contracts";
4
+ import type { CurveLPToken } from "./curveLP";
5
5
  import { TokenType } from "./tokenType";
6
6
  export declare type ConvexLPToken = "cvx3Crv" | "cvxsteCRV" | "cvxFRAX3CRV" | "cvxLUSD3CRV" | "cvxcrvPlain3andSUSD" | "cvxgusd3CRV";
7
7
  export declare type ConvexStakedPhantomToken = "stkcvx3Crv" | "stkcvxsteCRV" | "stkcvxFRAX3CRV" | "stkcvxLUSD3CRV" | "stkcvxcrvPlain3andSUSD" | "stkcvxgusd3CRV";
@@ -1,7 +1,7 @@
1
+ import { BigNumber } from "ethers";
1
2
  import { TradeAction } from "../pathfinder/tradeTypes";
2
- import { SupportedToken, TokenBase } from "./token";
3
+ import type { SupportedToken, TokenBase } from "./token";
3
4
  import { PartialRecord } from "../utils/types";
4
- import { BigNumber } from "ethers";
5
5
  import { TokenType } from "./tokenType";
6
6
  export declare type CurveLPToken = "3Crv" | "steCRV" | "FRAX3CRV" | "LUSD3CRV" | "crvPlain3andSUSD" | "gusd3CRV";
7
7
  export declare type CurveLPTokenData = {
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.curveTokens = exports.Curve3CrvUnderlyingTokenIndex = void 0;
4
- var tradeTypes_1 = require("../pathfinder/tradeTypes");
5
4
  var ethers_1 = require("ethers");
5
+ var tradeTypes_1 = require("../pathfinder/tradeTypes");
6
6
  var tokenType_1 = require("./tokenType");
7
7
  exports.Curve3CrvUnderlyingTokenIndex = {
8
8
  DAI: ethers_1.BigNumber.from(0),
@@ -1,5 +1,5 @@
1
- import { TokenBase } from "./token";
2
- import { TradeAction } from "../pathfinder/tradeTypes";
1
+ import type { TokenBase } from "./token";
2
+ import type { TradeAction } from "../pathfinder/tradeTypes";
3
3
  import { TokenType } from "./tokenType";
4
4
  export declare type DieselTokenTypes = "dDAI" | "dUSDC" | "dWBTC" | "dWETH";
5
5
  export declare type GearboxToken = "GEAR";
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.gearTokens = void 0;
4
4
  var tokenType_1 = require("./tokenType");
5
5
  exports.gearTokens = {
6
- //GEARBOX
6
+ // GEARBOX
7
7
  dDAI: {
8
8
  name: "dDAI",
9
9
  decimals: 18,
@@ -1,5 +1,5 @@
1
1
  import { TradeAction } from "../pathfinder/tradeTypes";
2
- import { TokenBase } from "./token";
2
+ import type { TokenBase } from "./token";
3
3
  import { TokenType } from "./tokenType";
4
4
  export declare type NormalToken = "1INCH" | "AAVE" | "COMP" | "CRV" | "DPI" | "FEI" | "LINK" | "SNX" | "SUSHI" | "UNI" | "USDT" | "USDC" | "DAI" | "WETH" | "WBTC" | "YFI" | "STETH" | "FTM" | "CVX" | "FRAX" | "FXS" | "LDO" | "SPELL" | "LUSD" | "sUSD" | "GUSD" | "LUNA" | "LQTY";
5
5
  export declare type NormalTokenData = {
@@ -80,7 +80,7 @@ exports.tokenDataByNetwork = {
80
80
  yvWBTC: "0xA696a63cc78DfFa1a63E9E50587C197387FF6C7E",
81
81
  yvCurve_stETH: "0xdCD90C7f6324cfa40d7169ef80b12031770B4325",
82
82
  yvCurve_FRAX: "0xB4AdA607B9d6b2c9Ee07A275e9616B84AC560139",
83
- //GEARBOX
83
+ // GEARBOX
84
84
  dDAI: "0x6CFaF95457d7688022FC53e7AbE052ef8DFBbdBA",
85
85
  dUSDC: "0xc411dB5f5Eb3f7d552F9B8454B2D74097ccdE6E3",
86
86
  dWBTC: "0xe753260F1955e8678DCeA8887759e07aa57E8c54",
@@ -150,7 +150,7 @@ exports.tokenDataByNetwork = {
150
150
  stkcvxgusd3CRV: "0x9A74e8106f6c28b21b1B6a0F985cf1227BE05F04",
151
151
  stkcvxsteCRV: "0xd8bAbB7EfBF7F931a69B209f71b27421F8b18516",
152
152
  stkcvxcrvPlain3andSUSD: "0x6b45Cab756B41a7204973b71362ef5F73E67F6DA",
153
- //GEARBOX
153
+ // GEARBOX
154
154
  dDAI: "0x077a3Ce0D572b72436F6644793Fc7721353aF1f4",
155
155
  dUSDC: "0x8147e00456c8A3128182730bFFdFd9D1E6bbC048",
156
156
  dWBTC: "0x34D9B3c13B25632879B2DaabBde702F612902238",
@@ -159,6 +159,6 @@ exports.tokenDataByNetwork = {
159
159
  }
160
160
  };
161
161
  exports.tokenSymbolByAddress = (0, mappers_1.objectEntries)(exports.tokenDataByNetwork).reduce(function (acc, _a) {
162
- var _ = _a[0], tokens = _a[1];
163
- return __assign(__assign({}, acc), (0, mappers_1.filterEmptyKeys)((0, mappers_1.keyToLowercase)((0, mappers_1.swapKeyValue)(tokens))));
162
+ var tokens = _a[1];
163
+ return (__assign(__assign({}, acc), (0, mappers_1.filterEmptyKeys)((0, mappers_1.keyToLowercase)((0, mappers_1.swapKeyValue)(tokens)))));
164
164
  }, {});
@@ -2,13 +2,14 @@ import { BigNumber } from "ethers";
2
2
  import { TokenDataPayload } from "../payload/token";
3
3
  import { NetworkType } from "../core/constants";
4
4
  import { SupportedToken } from "./token";
5
+ declare type SymbolReplacements = Record<string, string>;
5
6
  export declare class TokenData {
6
7
  readonly id: string;
7
8
  readonly symbol: string;
8
9
  readonly address: string;
9
10
  readonly decimals: number;
10
11
  readonly icon?: string;
11
- constructor(payload: TokenDataPayload);
12
+ constructor(payload: TokenDataPayload, symbolReplacements?: SymbolReplacements);
12
13
  compareBySymbol(b: TokenData): number;
13
14
  }
14
15
  export interface TokenBalance {
@@ -22,3 +23,4 @@ export interface TokenAllowance {
22
23
  export declare const WETHToken: Record<NetworkType, string>;
23
24
  export declare const connectors: Record<NetworkType, Array<SupportedToken>>;
24
25
  export declare function getConnectors(networkType: NetworkType): string[];
26
+ export {};
@@ -3,16 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getConnectors = exports.connectors = exports.WETHToken = exports.TokenData = void 0;
4
4
  var config_1 = require("../config");
5
5
  var token_1 = require("./token");
6
+ var defaultSymbolReplacement = {
7
+ dWETH: "dETH",
8
+ WETH: "ETH"
9
+ };
6
10
  var TokenData = /** @class */ (function () {
7
- function TokenData(payload) {
11
+ function TokenData(payload, symbolReplacements) {
12
+ if (symbolReplacements === void 0) { symbolReplacements = defaultSymbolReplacement; }
8
13
  var _a;
9
14
  this.id = payload.addr;
10
15
  this.address = payload.addr;
11
16
  // this.name = payload.name;
12
- this.symbol = payload.symbol;
13
- if (this.symbol === "WETH" || this.symbol === "dWETH") {
14
- this.symbol = this.symbol.replace("WETH", "ETH");
15
- }
17
+ this.symbol = symbolReplacements[payload.symbol] || payload.symbol;
16
18
  this.decimals = payload.decimals;
17
19
  this.icon = "".concat(config_1.STATIC_TOKEN).concat((_a = payload.symbol) === null || _a === void 0 ? void 0 : _a.toLowerCase(), ".svg");
18
20
  }
@@ -24,7 +26,7 @@ var TokenData = /** @class */ (function () {
24
26
  exports.TokenData = TokenData;
25
27
  exports.WETHToken = {
26
28
  Mainnet: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
27
- Kovan: "0xd0a1e359811322d97991e03f863a0c30c2cf029c",
29
+ Kovan: "0xd0a1e359811322d97991e03f863a0c30c2cf029c"
28
30
  };
29
31
  exports.connectors = {
30
32
  Mainnet: [
@@ -33,7 +35,7 @@ exports.connectors = {
33
35
  "DAI",
34
36
  "USDC",
35
37
  // "USDT",
36
- "WBTC",
38
+ "WBTC"
37
39
  // "stETH",
38
40
  // "PAX",
39
41
  // "TUSD",
@@ -41,7 +43,7 @@ exports.connectors = {
41
43
  // "BAL",
42
44
  // "sUSD",
43
45
  ],
44
- Kovan: ["WETH", "DAI", "USDC", "WBTC"],
46
+ Kovan: ["WETH", "DAI", "USDC", "WBTC"]
45
47
  };
46
48
  function getConnectors(networkType) {
47
49
  return exports.connectors[networkType].map(function (e) {
@@ -1,7 +1,7 @@
1
1
  import { TradeAction } from "../pathfinder/tradeTypes";
2
- import { TokenBase } from "./token";
3
- import { CurveLPToken } from "./curveLP";
4
- import { NormalToken } from "./normal";
2
+ import type { TokenBase } from "./token";
3
+ import type { CurveLPToken } from "./curveLP";
4
+ import type { NormalToken } from "./normal";
5
5
  import { TokenType } from "./tokenType";
6
6
  export declare type YearnLPToken = "yvDAI" | "yvUSDC" | "yvWETH" | "yvWBTC" | "yvCurve_stETH" | "yvCurve_FRAX";
7
7
  export declare type YearnVaultTokenData = {
@@ -0,0 +1,6 @@
1
+ interface IMetamaskError {
2
+ code: number;
3
+ message: string;
4
+ }
5
+ export declare const isMetamaskError: (e: any) => e is IMetamaskError;
6
+ export {};
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isMetamaskError = void 0;
4
+ var isMetamaskError = function (e) {
5
+ if (!e)
6
+ return false;
7
+ if (typeof e !== "object")
8
+ return false;
9
+ if (typeof e.code !== "number" || typeof e.message !== "string")
10
+ return false;
11
+ return true;
12
+ };
13
+ exports.isMetamaskError = isMetamaskError;
@@ -1,7 +1,7 @@
1
1
  import { BigNumber, BigNumberish } from "ethers";
2
2
  export declare function rayToNumber(num: BigNumberish): number;
3
3
  export declare function formatRAY(num?: BigNumber): string;
4
- export declare function formatBN(num: BigNumberish | undefined, decimals: number, precision?: number): string;
4
+ export declare function formatBN(numArg: BigNumberish | undefined, decimals: number, precisionArg?: number): string;
5
5
  export declare function formatBn4dig(num: BigNumber, precision?: number): string;
6
6
  export declare function toHumanFormat(num: BigNumber, precision?: number): string;
7
7
  export declare function toSignificant(num: BigNumber, decimals: number): string;
@@ -5,8 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.formatLeverage = exports.formatHf = exports.formatDate = exports.formatRate = exports.shortHash = exports.shortAddress = exports.toBN = exports.toSignificant = exports.toHumanFormat = exports.formatBn4dig = exports.formatBN = exports.formatRAY = exports.rayToNumber = void 0;
7
7
  var ethers_1 = require("ethers");
8
- var constants_1 = require("../core/constants");
9
8
  var decimal_js_light_1 = __importDefault(require("decimal.js-light"));
9
+ var constants_1 = require("../core/constants");
10
10
  function rayToNumber(num) {
11
11
  return (ethers_1.BigNumber.from(num).div(ethers_1.BigNumber.from(10).pow(21)).toNumber() / 1000000);
12
12
  }
@@ -15,7 +15,9 @@ function formatRAY(num) {
15
15
  return toSignificant(num || ethers_1.BigNumber.from(0), 27);
16
16
  }
17
17
  exports.formatRAY = formatRAY;
18
- function formatBN(num, decimals, precision) {
18
+ function formatBN(numArg, decimals, precisionArg) {
19
+ var num = numArg;
20
+ var precision = precisionArg;
19
21
  if (!num)
20
22
  return "-";
21
23
  // if (BigNumber.from(num).gt(BigNumber.from(10).pow(37))) {
@@ -54,22 +56,20 @@ function formatBn4dig(num, precision) {
54
56
  if (numStr.length < 6)
55
57
  numStr = "0".repeat(6 - numStr.length) + numStr;
56
58
  return numStr.length <= 6
57
- ? "0." + numStr.slice(0, precision)
58
- : numStr.slice(0, numStr.length - 6) +
59
- "." +
60
- numStr.slice(numStr.length - 6, numStr.length - 6 + precision);
59
+ ? "0.".concat(numStr.slice(0, precision))
60
+ : "".concat(numStr.slice(0, numStr.length - 6), ".").concat(numStr.slice(numStr.length - 6, numStr.length - 6 + precision));
61
61
  }
62
62
  exports.formatBn4dig = formatBn4dig;
63
63
  function toHumanFormat(num, precision) {
64
64
  if (precision === void 0) { precision = 2; }
65
65
  if (num.gte(1e15)) {
66
- return formatBn4dig(num.div(1e9), precision) + "Bn";
66
+ return "".concat(formatBn4dig(num.div(1e9), precision), "Bn");
67
67
  }
68
68
  if (num.gte(1e12)) {
69
- return formatBn4dig(num.div(1e6), precision) + "M";
69
+ return "".concat(formatBn4dig(num.div(1e6), precision), "M");
70
70
  }
71
71
  if (num.gte(1e9)) {
72
- return formatBn4dig(num.div(1e3), precision) + "K";
72
+ return "".concat(formatBn4dig(num.div(1e3), precision), "K");
73
73
  }
74
74
  return formatBn4dig(num, precision);
75
75
  }
@@ -102,20 +102,23 @@ function shortHash(address) {
102
102
  exports.shortHash = shortHash;
103
103
  var formatRate = function (rate) {
104
104
  return rate
105
- ? (ethers_1.BigNumber.from(rate)
105
+ ? "".concat((ethers_1.BigNumber.from(rate)
106
106
  .mul(constants_1.PERCENTAGE_FACTOR)
107
107
  .mul(100)
108
108
  .div(constants_1.RAY)
109
- .toNumber() / constants_1.PERCENTAGE_FACTOR).toFixed(2) + "%"
109
+ .toNumber() / constants_1.PERCENTAGE_FACTOR).toFixed(2), "%")
110
110
  : "0.00%";
111
111
  };
112
112
  exports.formatRate = formatRate;
113
113
  function formatDate(date) {
114
- var d = new Date(date), month = "" + (d.getMonth() + 1), day = "" + d.getDate(), year = d.getFullYear();
114
+ var d = new Date(date);
115
+ var month = "".concat(d.getMonth() + 1);
116
+ var day = "".concat(d.getDate());
117
+ var year = d.getFullYear();
115
118
  if (month.length < 2)
116
- month = "0" + month;
119
+ month = "0".concat(month);
117
120
  if (day.length < 2)
118
- day = "0" + day;
121
+ day = "0".concat(day);
119
122
  return [year, month, day].join("-");
120
123
  }
121
124
  exports.formatDate = formatDate;
@@ -1 +1,2 @@
1
- export declare function loadingProgress(...params: Array<unknown>): number;
1
+ export declare function allLoaded(itemsToLoad: Array<unknown>): boolean;
2
+ export declare function loadingProgress(itemsToLoad: Array<unknown>): number;
@@ -1,17 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.loadingProgress = void 0;
4
- function loadingProgress() {
5
- var params = [];
6
- for (var _i = 0; _i < arguments.length; _i++) {
7
- params[_i] = arguments[_i];
8
- }
9
- var isLoaded = 0;
10
- for (var _a = 0, params_1 = params; _a < params_1.length; _a++) {
11
- var item = params_1[_a];
12
- if (item !== undefined)
13
- isLoaded++;
14
- }
15
- return Math.floor((isLoaded / params.length) * 100);
3
+ exports.loadingProgress = exports.allLoaded = void 0;
4
+ var isLoaded = function (v) { return v !== undefined; };
5
+ function allLoaded(itemsToLoad) {
6
+ return itemsToLoad.reduce(function (acc, item) { return acc && isLoaded(item); }, true);
7
+ }
8
+ exports.allLoaded = allLoaded;
9
+ function loadingProgress(itemsToLoad) {
10
+ var loaded = itemsToLoad.reduce(function (acc, item) { return (isLoaded(item) ? acc + 1 : acc); }, 0);
11
+ return Math.floor((loaded / itemsToLoad.length) * 100);
16
12
  }
17
13
  exports.loadingProgress = loadingProgress;
@@ -18,7 +18,7 @@ var swapKeyValue = function (o) {
18
18
  return objectEntries(o).reduce(function (acc, _a) {
19
19
  var _b;
20
20
  var key = _a[0], value = _a[1];
21
- return __assign(__assign({}, acc), (_b = {}, _b[value] = key, _b));
21
+ return (__assign(__assign({}, acc), (_b = {}, _b[value] = key, _b)));
22
22
  }, {});
23
23
  };
24
24
  exports.swapKeyValue = swapKeyValue;
@@ -35,7 +35,7 @@ var filterEmptyKeys = function (o) {
35
35
  return objectEntries(o).reduce(function (acc, _a) {
36
36
  var _b;
37
37
  var key = _a[0], value = _a[1];
38
- return !!key ? __assign(__assign({}, acc), (_b = {}, _b[key] = value, _b)) : acc;
38
+ return (key ? __assign(__assign({}, acc), (_b = {}, _b[key] = value, _b)) : acc);
39
39
  }, {});
40
40
  };
41
41
  exports.filterEmptyKeys = filterEmptyKeys;
@@ -48,7 +48,7 @@ function detectNetwork(provider) {
48
48
  case 0:
49
49
  _c.trys.push([0, 2, , 7]);
50
50
  usdcMainnet = types_1.ERC20__factory.connect(token_1.tokenDataByNetwork.Mainnet.USDC, provider);
51
- return [4 /*yield*/, usdcMainnet.balanceOf(constants_1.ADDRESS_0x0)];
51
+ return [4 /*yield*/, usdcMainnet.balanceOf(constants_1.ADDRESS_0X0)];
52
52
  case 1:
53
53
  _c.sent();
54
54
  return [2 /*return*/, "Mainnet"];
@@ -58,7 +58,7 @@ function detectNetwork(provider) {
58
58
  case 3:
59
59
  _c.trys.push([3, 5, , 6]);
60
60
  usdcMainnet = types_1.ERC20__factory.connect(token_1.tokenDataByNetwork.Kovan.USDC, provider);
61
- return [4 /*yield*/, usdcMainnet.balanceOf(constants_1.ADDRESS_0x0)];
61
+ return [4 /*yield*/, usdcMainnet.balanceOf(constants_1.ADDRESS_0X0)];
62
62
  case 4:
63
63
  _c.sent();
64
64
  return [2 /*return*/, "Kovan"];
@@ -40,32 +40,20 @@ exports.callRepeater = void 0;
40
40
  function callRepeater(call, step) {
41
41
  if (step === void 0) { step = 0; }
42
42
  return __awaiter(this, void 0, void 0, function () {
43
- var _this = this;
44
43
  return __generator(this, function (_a) {
45
- return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
46
- var _a, e_1;
47
- return __generator(this, function (_b) {
48
- switch (_b.label) {
49
- case 0:
50
- _b.trys.push([0, 2, , 3]);
51
- _a = resolve;
52
- return [4 /*yield*/, call()];
53
- case 1:
54
- _a.apply(void 0, [_b.sent()]);
55
- return [3 /*break*/, 3];
56
- case 2:
57
- e_1 = _b.sent();
58
- console.error("Error ".concat(step, ": ").concat(e_1));
59
- if (step > 5 || e_1.code !== -32000)
60
- reject(e_1);
61
- else {
62
- setTimeout(function () { return resolve(callRepeater(call, step + 1)); }, 200);
63
- }
64
- return [3 /*break*/, 3];
65
- case 3: return [2 /*return*/];
44
+ return [2 /*return*/, new Promise(function (resolve, reject) {
45
+ try {
46
+ call().then(function (r) { return resolve(r); });
47
+ }
48
+ catch (e) {
49
+ console.error("Error ".concat(step, ": ").concat(e));
50
+ if (step > 5 || e.code !== -32000)
51
+ reject(e);
52
+ else {
53
+ setTimeout(function () { return resolve(callRepeater(call, step + 1)); }, 200);
66
54
  }
67
- });
68
- }); })];
55
+ }
56
+ })];
69
57
  });
70
58
  });
71
59
  }
@@ -6,7 +6,7 @@ function isPositiveFloat(val) {
6
6
  if (!floatRegex.test(val))
7
7
  return false;
8
8
  var valF = parseFloat(val);
9
- if (isNaN(valF))
9
+ if (Number.isNaN(valF))
10
10
  return false;
11
11
  return true;
12
12
  }