@gearbox-protocol/sdk 0.0.101 → 0.0.104

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 (139) 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 +7 -9
  5. package/lib/apy/lidoAPY.js +35 -29
  6. package/lib/contracts/contracts.d.ts +5 -2
  7. package/lib/contracts/contracts.js +19 -18
  8. package/lib/contracts/contractsRegister.js +13 -1
  9. package/lib/core/constants.d.ts +5 -3
  10. package/lib/core/constants.js +8 -6
  11. package/lib/core/creditAccount.d.ts +2 -2
  12. package/lib/core/creditAccount.js +12 -11
  13. package/lib/core/creditManager.d.ts +1 -1
  14. package/lib/core/creditManager.js +4 -10
  15. package/lib/core/creditSession.js +14 -3
  16. package/lib/core/eventOrTx.d.ts +1 -1
  17. package/lib/core/events.d.ts +19 -19
  18. package/lib/core/events.js +23 -21
  19. package/lib/core/pool.d.ts +1 -1
  20. package/lib/core/pool.js +1 -7
  21. package/lib/core/price.d.ts +1 -3
  22. package/lib/core/price.js +9 -7
  23. package/lib/core/strategy.d.ts +8 -6
  24. package/lib/core/strategy.js +25 -25
  25. package/lib/core/tokenDistributor.js +1 -1
  26. package/lib/core/transactions.d.ts +18 -3
  27. package/lib/core/transactions.js +39 -3
  28. package/lib/index.d.ts +8 -2
  29. package/lib/index.js +8 -1
  30. package/lib/oracles/priceFeeds.js +1 -1
  31. package/lib/pathfinder/convexLP.d.ts +1 -1
  32. package/lib/pathfinder/convexLP.js +26 -29
  33. package/lib/pathfinder/curveLP.d.ts +1 -1
  34. package/lib/pathfinder/curveLP.js +5 -7
  35. package/lib/pathfinder/path.d.ts +1 -1
  36. package/lib/pathfinder/path.js +38 -42
  37. package/lib/pathfinder/trade.d.ts +1 -2
  38. package/lib/pathfinder/tradeTypes.d.ts +5 -5
  39. package/lib/pathfinder/yVault.d.ts +2 -2
  40. package/lib/pathfinder/yVault.js +22 -22
  41. package/lib/payload/creditAccount.d.ts +4 -4
  42. package/lib/payload/creditManager.d.ts +3 -13
  43. package/lib/payload/pool.d.ts +2 -2
  44. package/lib/strategies/convex.d.ts +12 -0
  45. package/lib/strategies/convex.js +74 -1
  46. package/lib/strategies/creditFacade.d.ts +1 -0
  47. package/lib/strategies/creditFacade.js +3 -0
  48. package/lib/strategies/curve.d.ts +15 -60
  49. package/lib/strategies/curve.js +74 -1
  50. package/lib/strategies/lido.d.ts +6 -0
  51. package/lib/strategies/lido.js +23 -1
  52. package/lib/strategies/uniswapV2.d.ts +1 -0
  53. package/lib/strategies/uniswapV2.js +6 -19
  54. package/lib/strategies/uniswapV3.d.ts +1 -0
  55. package/lib/strategies/uniswapV3.js +4 -1
  56. package/lib/strategies/yearn.d.ts +8 -0
  57. package/lib/strategies/yearn.js +92 -12
  58. package/lib/tokens/convex.d.ts +3 -3
  59. package/lib/tokens/curveLP.d.ts +7 -2
  60. package/lib/tokens/curveLP.js +8 -1
  61. package/lib/tokens/gear.d.ts +2 -2
  62. package/lib/tokens/gear.js +1 -1
  63. package/lib/tokens/normal.d.ts +1 -1
  64. package/lib/tokens/token.js +8 -8
  65. package/lib/tokens/tokenData.d.ts +3 -1
  66. package/lib/tokens/tokenData.js +10 -8
  67. package/lib/tokens/yearn.d.ts +6 -2
  68. package/lib/tokens/yearn.js +6 -0
  69. package/lib/utils/errors.d.ts +6 -0
  70. package/lib/utils/errors.js +13 -0
  71. package/lib/utils/formatter.d.ts +1 -1
  72. package/lib/utils/formatter.js +17 -14
  73. package/lib/utils/loading.d.ts +2 -1
  74. package/lib/utils/loading.js +9 -13
  75. package/lib/utils/mappers.js +2 -2
  76. package/lib/utils/network.js +2 -2
  77. package/lib/utils/repeater.js +12 -24
  78. package/lib/utils/validate.js +1 -1
  79. package/package.json +24 -7
  80. package/src/apy/convexAPY.ts +13 -12
  81. package/src/apy/lidoAPY.ts +35 -27
  82. package/src/contracts/contracts.ts +27 -17
  83. package/src/contracts/contractsRegister.ts +16 -1
  84. package/src/core/constants.ts +8 -5
  85. package/src/core/creditAccount.ts +42 -16
  86. package/src/core/creditManager.ts +33 -7
  87. package/src/core/creditOperation.ts +7 -7
  88. package/src/core/creditSession.ts +25 -5
  89. package/src/core/errors.ts +1 -0
  90. package/src/core/eventOrTx.ts +8 -5
  91. package/src/core/events.ts +85 -24
  92. package/src/core/history.ts +46 -46
  93. package/src/core/operations.ts +6 -0
  94. package/src/core/pool.ts +16 -4
  95. package/src/core/price.ts +10 -13
  96. package/src/core/strategy.ts +54 -43
  97. package/src/core/tokenDistributor.ts +2 -2
  98. package/src/core/transactions.ts +427 -350
  99. package/src/index.ts +10 -3
  100. package/src/oracles/priceFeeds.ts +523 -523
  101. package/src/pathfinder/contracts.ts +15 -13
  102. package/src/pathfinder/convexLP.ts +29 -25
  103. package/src/pathfinder/curveLP.ts +57 -53
  104. package/src/pathfinder/path.ts +17 -9
  105. package/src/pathfinder/priority.ts +11 -11
  106. package/src/pathfinder/trade.ts +84 -77
  107. package/src/pathfinder/tradeTypes.ts +98 -94
  108. package/src/pathfinder/yVault.ts +32 -17
  109. package/src/payload/creditAccount.ts +4 -4
  110. package/src/payload/creditManager.ts +3 -13
  111. package/src/payload/pool.ts +2 -2
  112. package/src/payload/token.ts +3 -3
  113. package/src/strategies/convex.ts +360 -186
  114. package/src/strategies/creditFacade.ts +74 -53
  115. package/src/strategies/curve.ts +400 -189
  116. package/src/strategies/lido.ts +70 -32
  117. package/src/strategies/uniswapV2.ts +93 -111
  118. package/src/strategies/uniswapV3.ts +118 -91
  119. package/src/strategies/yearn.ts +187 -60
  120. package/src/tokens/connectors.ts +6 -6
  121. package/src/tokens/convex.ts +297 -296
  122. package/src/tokens/curveLP.ts +176 -165
  123. package/src/tokens/gear.ts +47 -45
  124. package/src/tokens/normal.ts +801 -802
  125. package/src/tokens/token.ts +13 -9
  126. package/src/tokens/tokenData.ts +19 -9
  127. package/src/tokens/tokenType.ts +11 -11
  128. package/src/tokens/yearn.ts +130 -124
  129. package/src/utils/errors.ts +11 -0
  130. package/src/utils/formatter.ts +22 -18
  131. package/src/utils/loading.ts +14 -6
  132. package/src/utils/mappers.ts +8 -6
  133. package/src/utils/multicall.ts +2 -0
  134. package/src/utils/network.ts +21 -21
  135. package/src/utils/repeater.ts +2 -2
  136. package/src/utils/validate.ts +1 -1
  137. package/lib/utils/events.d.ts +0 -2
  138. package/lib/utils/events.js +0 -13
  139. package/src/utils/events.ts +0 -10
@@ -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,15 +150,15 @@ exports.tokenDataByNetwork = {
150
150
  stkcvxgusd3CRV: "0x9A74e8106f6c28b21b1B6a0F985cf1227BE05F04",
151
151
  stkcvxsteCRV: "0xd8bAbB7EfBF7F931a69B209f71b27421F8b18516",
152
152
  stkcvxcrvPlain3andSUSD: "0x6b45Cab756B41a7204973b71362ef5F73E67F6DA",
153
- //GEARBOX
154
- dDAI: "0x0d06D2e31781A0585feE334F63beF43543496e5d",
155
- dUSDC: "0xcCc83353856A79c94EaDa39Df76B9c7C4c762dBF",
156
- dWBTC: "0x4cCb374472C8c73b067c8c40b9420a221Ef014ca",
157
- dWETH: "0x3B1e0Db6C960b32beEDf82af9db2da63F15Ba01E",
153
+ // GEARBOX
154
+ dDAI: "0x077a3Ce0D572b72436F6644793Fc7721353aF1f4",
155
+ dUSDC: "0x8147e00456c8A3128182730bFFdFd9D1E6bbC048",
156
+ dWBTC: "0x34D9B3c13B25632879B2DaabBde702F612902238",
157
+ dWETH: "0x19e4F905749D3b487CA4927b54e55b64625a1143",
158
158
  GEAR: "0xe01c5d0297c56e992dab3886057a1441485ff7c7"
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,6 +1,7 @@
1
+ import type { YearnVaultContract } from "src/contracts/contracts";
1
2
  import { TradeAction } from "../pathfinder/tradeTypes";
2
- import { TokenBase } from "./token";
3
- import { CurveLPToken } from "./curveLP";
3
+ import type { TokenBase } from "./token";
4
+ import type { CurveLPToken } from "./curveLP";
4
5
  import { NormalToken } from "./normal";
5
6
  import { TokenType } from "./tokenType";
6
7
  export declare type YearnLPToken = "yvDAI" | "yvUSDC" | "yvWETH" | "yvWBTC" | "yvCurve_stETH" | "yvCurve_FRAX";
@@ -9,17 +10,20 @@ export declare type YearnVaultTokenData = {
9
10
  type: TokenType.YEARN_VAULT;
10
11
  underlying: NormalToken;
11
12
  lpActions: Array<TradeAction>;
13
+ vault: YearnVaultContract;
12
14
  } & TokenBase;
13
15
  export declare type YearnVaultOfCurveLPTokenData = {
14
16
  symbol: YearnLPToken;
15
17
  type: TokenType.YEARN_VAULT_OF_CURVE_LP;
16
18
  underlying: CurveLPToken;
17
19
  lpActions: Array<TradeAction>;
20
+ vault: YearnVaultContract;
18
21
  } & TokenBase;
19
22
  export declare type YearnVaultOfMetaCurveLPTokenData = {
20
23
  symbol: YearnLPToken;
21
24
  type: TokenType.YEARN_VAULT_OF_META_CURVE_LP;
22
25
  underlying: CurveLPToken;
23
26
  lpActions: Array<TradeAction>;
27
+ vault: YearnVaultContract;
24
28
  } & TokenBase;
25
29
  export declare const yearnTokens: Record<YearnLPToken, YearnVaultTokenData | YearnVaultOfCurveLPTokenData | YearnVaultOfMetaCurveLPTokenData>;
@@ -11,6 +11,7 @@ exports.yearnTokens = {
11
11
  symbol: "yvDAI",
12
12
  type: tokenType_1.TokenType.YEARN_VAULT,
13
13
  underlying: "DAI",
14
+ vault: "YEARN_DAI_VAULT",
14
15
  lpActions: [
15
16
  {
16
17
  type: tradeTypes_1.TradeType.YearnWithdraw,
@@ -25,6 +26,7 @@ exports.yearnTokens = {
25
26
  symbol: "yvUSDC",
26
27
  type: tokenType_1.TokenType.YEARN_VAULT,
27
28
  underlying: "USDC",
29
+ vault: "YEARN_USDC_VAULT",
28
30
  lpActions: [
29
31
  {
30
32
  type: tradeTypes_1.TradeType.YearnWithdraw,
@@ -39,6 +41,7 @@ exports.yearnTokens = {
39
41
  symbol: "yvWETH",
40
42
  type: tokenType_1.TokenType.YEARN_VAULT,
41
43
  underlying: "WETH",
44
+ vault: "YEARN_WETH_VAULT",
42
45
  lpActions: [
43
46
  {
44
47
  type: tradeTypes_1.TradeType.YearnWithdraw,
@@ -53,6 +56,7 @@ exports.yearnTokens = {
53
56
  symbol: "yvWBTC",
54
57
  type: tokenType_1.TokenType.YEARN_VAULT,
55
58
  underlying: "WBTC",
59
+ vault: "YEARN_WBTC_VAULT",
56
60
  lpActions: [
57
61
  {
58
62
  type: tradeTypes_1.TradeType.YearnWithdraw,
@@ -68,6 +72,7 @@ exports.yearnTokens = {
68
72
  symbol: "yvCurve_stETH",
69
73
  type: tokenType_1.TokenType.YEARN_VAULT_OF_CURVE_LP,
70
74
  underlying: "steCRV",
75
+ vault: "YEARN_CURVE_STETH_VAULT",
71
76
  lpActions: [
72
77
  {
73
78
  type: tradeTypes_1.TradeType.YearnWithdraw,
@@ -82,6 +87,7 @@ exports.yearnTokens = {
82
87
  symbol: "yvCurve_FRAX",
83
88
  type: tokenType_1.TokenType.YEARN_VAULT_OF_META_CURVE_LP,
84
89
  underlying: "FRAX3CRV",
90
+ vault: "YEARN_CURVE_FRAX_VAULT",
85
91
  lpActions: [
86
92
  {
87
93
  type: tradeTypes_1.TradeType.YearnWithdraw,
@@ -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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "0.0.101",
3
+ "version": "0.0.104",
4
4
  "description": "Gearbox SDK",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -9,22 +9,39 @@
9
9
  "scripts": {
10
10
  "build": "tsc",
11
11
  "dev": "tsc -w",
12
- "pub": "rm -rf ./src/types/hardhat.ts && cp ./src/types/*.d.ts ./lib/types && tsc && yarn publish"
12
+ "pub": "rm -rf ./src/types/hardhat.ts && cp ./src/types/*.d.ts ./lib/types && tsc && yarn publish",
13
+ "lint": "eslint . --ext .tsx,.ts --fix",
14
+ "prepush": "yarn lint --max-warnings=0",
15
+ "prepare": "husky install"
13
16
  },
14
17
  "dependencies": {
15
18
  "decimal.js-light": "^2.5.1",
16
19
  "moment": "^2.29.1"
17
20
  },
18
21
  "devDependencies": {
19
- "@types/jest": "^26.0.4",
20
- "@types/node": "^14.0.23",
22
+ "@types/jest": "^26.0.15",
23
+ "@types/node": "^17.0.41",
24
+ "@typescript-eslint/eslint-plugin": "^5.7.0",
25
+ "@typescript-eslint/parser": "^5.7.0",
21
26
  "axios": "^0.27.2",
22
27
  "dotenv": "^16.0.1",
23
- "ethers": "^5.6.5",
28
+ "eslint": "^7.11.0",
29
+ "eslint-config-airbnb": "^19.0.2",
30
+ "eslint-config-airbnb-typescript": "^16.1.0",
31
+ "eslint-config-prettier": "^8.3.0",
32
+ "eslint-import-resolver-typescript": "^2.5.0",
33
+ "eslint-plugin-import": "^2.22.1",
34
+ "eslint-plugin-jsx-a11y": "^6.5.1",
35
+ "eslint-plugin-prettier": "^4.0.0",
36
+ "eslint-plugin-react": "^7.27.1",
37
+ "eslint-plugin-react-hooks": "^4.3.0",
38
+ "ethers": "5.6.9",
39
+ "husky": "^8.0.0",
40
+ "husky-init": "^8.0.0",
24
41
  "jest": "^26.1.0",
25
- "prettier": "^2.3.0",
42
+ "prettier": "^2.7.1",
26
43
  "ts-node": "^10.1.0",
27
44
  "tslog": "^3.3.3",
28
- "typescript": "^4.2.4"
45
+ "typescript": "^4.7.3"
29
46
  }
30
47
  }
@@ -28,8 +28,9 @@ import { AwaitedRes } from "../utils/types";
28
28
  import {
29
29
  SECONDS_PER_YEAR,
30
30
  WAD,
31
- WAD_DECIMALS,
32
- NetworkType
31
+ WAD_DECIMALS_POW,
32
+ NetworkType,
33
+ PRICE_DECIMALS
33
34
  } from "../core/constants";
34
35
 
35
36
  type SupportedPools = Extract<
@@ -72,14 +73,14 @@ export async function getConvexApy(
72
73
  poolParams.stakedToken
73
74
  ] as ConvexPhantomTokenData;
74
75
 
75
- const underlying = stakedTokenParams.underlying;
76
+ const { underlying } = stakedTokenParams;
76
77
  const basePoolAddress = contractsList[pool];
77
78
  const swapPoolAddress = contractsList[curveSwapByPool[pool]];
78
79
  const cvxAddress = tokenList.CVX;
79
80
 
80
- const extraPoolAddresses = poolParams.extraRewards.map(d => {
81
- return d.poolAddress[networkType];
82
- });
81
+ const extraPoolAddresses = poolParams.extraRewards.map(
82
+ d => d.poolAddress[networkType]
83
+ );
83
84
 
84
85
  const [basePoolRate, basePoolSupply, vPrice, cvxSupply, ...extra] =
85
86
  await getPoolData(
@@ -90,8 +91,8 @@ export async function getConvexApy(
90
91
  provider
91
92
  );
92
93
 
93
- const cvxPrice = getTokenPrice(tokenList["CVX"]);
94
- const crvPrice = getTokenPrice(tokenList["CRV"]);
94
+ const cvxPrice = getTokenPrice(tokenList.CVX);
95
+ const crvPrice = getTokenPrice(tokenList.CRV);
95
96
 
96
97
  const crvPerSecond = basePoolRate;
97
98
  const virtualSupply = basePoolSupply.mul(vPrice).div(WAD);
@@ -100,8 +101,8 @@ export async function getConvexApy(
100
101
  const crvPerYear = crvPerUnderlying.mul(SECONDS_PER_YEAR);
101
102
  const cvxPerYear = getCVXMintAmount(crvPerYear, cvxSupply);
102
103
 
103
- const crvAPY = crvPerYear.mul(cvxPrice).div(WAD);
104
- const cvxAPY = cvxPerYear.mul(crvPrice).div(WAD);
104
+ const crvAPY = crvPerYear.mul(cvxPrice).div(PRICE_DECIMALS);
105
+ const cvxAPY = cvxPerYear.mul(crvPrice).div(PRICE_DECIMALS);
105
106
 
106
107
  const extraAPRs = await Promise.all(
107
108
  extraPoolAddresses.map(async (_, index) => {
@@ -113,7 +114,7 @@ export async function getConvexApy(
113
114
 
114
115
  const extraPrise = getTokenPrice(tokenList[extraRewardSymbol]);
115
116
 
116
- const extraAPY = perYear.mul(extraPrise).div(WAD);
117
+ const extraAPY = perYear.mul(extraPrise).div(PRICE_DECIMALS);
117
118
 
118
119
  return extraAPY;
119
120
  })
@@ -242,7 +243,7 @@ export async function getCurveBaseApy(
242
243
 
243
244
  const { baseApy = 0 } = result.data.apys[poolName] || {};
244
245
 
245
- return toBN((baseApy / RESPONSE_DECIMALS).toString(), WAD_DECIMALS);
246
+ return toBN((baseApy / RESPONSE_DECIMALS).toString(), WAD_DECIMALS_POW);
246
247
  } catch (e) {
247
248
  return BigNumber.from(0);
248
249
  }
@@ -1,6 +1,8 @@
1
1
  import { providers } from "ethers";
2
2
 
3
3
  import { multicall, MCall } from "../utils/multicall";
4
+ import { contractParams, LidoParams } from "../contracts/contracts";
5
+ import { tokenDataByNetwork } from "../tokens/token";
4
6
 
5
7
  import { WAD, SECONDS_PER_YEAR, NetworkType } from "../core/constants";
6
8
 
@@ -15,32 +17,32 @@ type ILidoOracleInterface = ILidoOracle["interface"];
15
17
 
16
18
  type IstETHInterface = IstETH["interface"];
17
19
 
18
- const lidoOracleAddress: Record<NetworkType, string> = {
19
- Mainnet: "0x442af784A788A5bd6F42A01Ebe9F287a871243fb",
20
- Kovan: ""
21
- };
20
+ const lidoOracles = (contractParams.LIDO_STETH_GATEWAY as LidoParams).oracle;
22
21
 
23
- const lidoStEthAddress: Record<NetworkType, string> = {
24
- Mainnet: "0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84",
25
- Kovan: ""
22
+ const lidoStEth: Record<NetworkType, string> = {
23
+ Mainnet: tokenDataByNetwork.Mainnet.STETH,
24
+ Kovan: tokenDataByNetwork.Kovan.STETH
26
25
  };
27
26
 
28
27
  export async function getLidoApy(
29
28
  provider: providers.Provider,
30
29
  networkType: NetworkType
31
30
  ) {
32
- if (!lidoOracleAddress[networkType]) {
33
- throw `No Lido APR oracle found on current network: ${networkType}`;
31
+ if (!lidoOracles[networkType]) {
32
+ throw new Error(
33
+ `No Lido APR oracle found on current network: ${networkType}`
34
+ );
34
35
  }
35
- if (!lidoStEthAddress[networkType]) {
36
- throw `No Lido stETH found on current network: ${networkType}`;
36
+ if (!lidoStEth[networkType]) {
37
+ throw new Error(`No Lido stETH found on current network: ${networkType}`);
37
38
  }
38
39
 
39
40
  const [{ postTotalPooledEther, preTotalPooledEther, timeElapsed }, fee] =
40
41
  await geLidoData(
41
- lidoOracleAddress[networkType],
42
- lidoStEthAddress[networkType],
43
- provider
42
+ lidoOracles[networkType],
43
+ lidoStEth[networkType],
44
+ provider,
45
+ networkType
44
46
  );
45
47
 
46
48
  const lidoAPRRay = postTotalPooledEther
@@ -52,30 +54,36 @@ export async function getLidoApy(
52
54
  return [lidoAPRRay, fee] as const;
53
55
  }
54
56
 
57
+ export const LIDO_FEE_DECIMALS = 10000;
58
+
55
59
  async function geLidoData(
56
60
  lidoOracleAddress: string,
57
61
  stETHAddress: string,
58
- provider: providers.Provider
62
+ provider: providers.Provider,
63
+ network: NetworkType
59
64
  ) {
60
- const calls: [MCall<ILidoOracleInterface>, MCall<IstETHInterface>] = [
61
- {
62
- address: lidoOracleAddress,
63
- interface: ILidoOracle__factory.createInterface(),
64
- method: "getLastCompletedReportDelta()"
65
- },
66
- {
65
+ const calls: [MCall<ILidoOracleInterface>, ...Array<MCall<IstETHInterface>>] =
66
+ [
67
+ {
68
+ address: lidoOracleAddress,
69
+ interface: ILidoOracle__factory.createInterface(),
70
+ method: "getLastCompletedReportDelta()"
71
+ }
72
+ ];
73
+
74
+ if (network !== "Kovan")
75
+ calls.push({
67
76
  address: stETHAddress,
68
77
  interface: IstETH__factory.createInterface(),
69
78
  method: "getFee()"
70
- }
71
- ];
79
+ });
72
80
 
73
- return multicall<
81
+ const [stats, fee = Math.floor(LIDO_FEE_DECIMALS / 10)] = await multicall<
74
82
  [
75
83
  Awaited<ReturnType<ILidoOracle["getLastCompletedReportDelta"]>>,
76
84
  Awaited<ReturnType<IstETH["getFee"]>>
77
85
  ]
78
86
  >(calls, provider);
79
- }
80
87
 
81
- export const LIDO_FEE_DECIMALS = 10000;
88
+ return [stats, fee] as const;
89
+ }