@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
@@ -139,7 +139,7 @@ export const tokenDataByNetwork: Record<
139
139
  yvCurve_stETH: "0xdCD90C7f6324cfa40d7169ef80b12031770B4325",
140
140
  yvCurve_FRAX: "0xB4AdA607B9d6b2c9Ee07A275e9616B84AC560139",
141
141
 
142
- //GEARBOX
142
+ // GEARBOX
143
143
  dDAI: "0x6CFaF95457d7688022FC53e7AbE052ef8DFBbdBA",
144
144
  dUSDC: "0xc411dB5f5Eb3f7d552F9B8454B2D74097ccdE6E3",
145
145
  dWBTC: "0xe753260F1955e8678DCeA8887759e07aa57E8c54",
@@ -217,7 +217,7 @@ export const tokenDataByNetwork: Record<
217
217
  stkcvxsteCRV: "0xd8bAbB7EfBF7F931a69B209f71b27421F8b18516",
218
218
  stkcvxcrvPlain3andSUSD: "0x6b45Cab756B41a7204973b71362ef5F73E67F6DA",
219
219
 
220
- //GEARBOX
220
+ // GEARBOX
221
221
  dDAI: "0x077a3Ce0D572b72436F6644793Fc7721353aF1f4",
222
222
  dUSDC: "0x8147e00456c8A3128182730bFFdFd9D1E6bbC048",
223
223
  dWBTC: "0x34D9B3c13B25632879B2DaabBde702F612902238",
@@ -229,6 +229,10 @@ export const tokenDataByNetwork: Record<
229
229
 
230
230
  export const tokenSymbolByAddress = objectEntries(tokenDataByNetwork).reduce<
231
231
  Record<string, SupportedToken>
232
- >((acc, [_, tokens]) => {
233
- return { ...acc, ...filterEmptyKeys(keyToLowercase(swapKeyValue(tokens))) };
234
- }, {});
232
+ >(
233
+ (acc, [, tokens]) => ({
234
+ ...acc,
235
+ ...filterEmptyKeys(keyToLowercase(swapKeyValue(tokens)))
236
+ }),
237
+ {}
238
+ );
@@ -4,22 +4,32 @@ import { STATIC_TOKEN } from "../config";
4
4
  import { NetworkType } from "../core/constants";
5
5
  import { SupportedToken, tokenDataByNetwork } from "./token";
6
6
 
7
+ type SymbolReplacements = Record<string, string>;
8
+ const defaultSymbolReplacement: SymbolReplacements = {
9
+ dWETH: "dETH",
10
+ WETH: "ETH"
11
+ };
12
+
7
13
  export class TokenData {
8
14
  public readonly id: string;
15
+
9
16
  // public readonly name: string;
10
17
  public readonly symbol: string;
18
+
11
19
  public readonly address: string;
20
+
12
21
  public readonly decimals: number;
22
+
13
23
  public readonly icon?: string;
14
24
 
15
- constructor(payload: TokenDataPayload) {
25
+ constructor(
26
+ payload: TokenDataPayload,
27
+ symbolReplacements: SymbolReplacements = defaultSymbolReplacement
28
+ ) {
16
29
  this.id = payload.addr;
17
30
  this.address = payload.addr;
18
31
  // this.name = payload.name;
19
- this.symbol = payload.symbol;
20
- if (this.symbol === "WETH" || this.symbol === "dWETH") {
21
- this.symbol = this.symbol.replace("WETH", "ETH");
22
- }
32
+ this.symbol = symbolReplacements[payload.symbol] || payload.symbol;
23
33
  this.decimals = payload.decimals;
24
34
  this.icon = `${STATIC_TOKEN}${payload.symbol?.toLowerCase()}.svg`;
25
35
  }
@@ -41,7 +51,7 @@ export interface TokenAllowance {
41
51
 
42
52
  export const WETHToken: Record<NetworkType, string> = {
43
53
  Mainnet: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
44
- Kovan: "0xd0a1e359811322d97991e03f863a0c30c2cf029c",
54
+ Kovan: "0xd0a1e359811322d97991e03f863a0c30c2cf029c"
45
55
  };
46
56
 
47
57
  export const connectors: Record<NetworkType, Array<SupportedToken>> = {
@@ -51,7 +61,7 @@ export const connectors: Record<NetworkType, Array<SupportedToken>> = {
51
61
  "DAI",
52
62
  "USDC",
53
63
  // "USDT",
54
- "WBTC",
64
+ "WBTC"
55
65
  // "stETH",
56
66
  // "PAX",
57
67
  // "TUSD",
@@ -59,11 +69,11 @@ export const connectors: Record<NetworkType, Array<SupportedToken>> = {
59
69
  // "BAL",
60
70
  // "sUSD",
61
71
  ],
62
- Kovan: ["WETH", "DAI", "USDC", "WBTC"],
72
+ Kovan: ["WETH", "DAI", "USDC", "WBTC"]
63
73
  };
64
74
 
65
75
  export function getConnectors(networkType: NetworkType) {
66
- return connectors[networkType].map((e) => {
76
+ return connectors[networkType].map(e => {
67
77
  const result =
68
78
  e === "WETH"
69
79
  ? WETHToken[networkType]
@@ -1,12 +1,12 @@
1
1
  export enum TokenType {
2
- CONNECTOR,
3
- NORMAL_TOKEN,
4
- CURVE_LP,
5
- META_CURVE_LP,
6
- YEARN_VAULT,
7
- YEARN_VAULT_OF_CURVE_LP,
8
- YEARN_VAULT_OF_META_CURVE_LP,
9
- CONVEX_LP_TOKEN,
10
- CONVEX_STAKED_PHANTOM_TOKEN,
11
- DIESEL_LP_TOKEN
12
- }
2
+ CONNECTOR,
3
+ NORMAL_TOKEN,
4
+ CURVE_LP,
5
+ META_CURVE_LP,
6
+ YEARN_VAULT,
7
+ YEARN_VAULT_OF_CURVE_LP,
8
+ YEARN_VAULT_OF_META_CURVE_LP,
9
+ CONVEX_LP_TOKEN,
10
+ CONVEX_STAKED_PHANTOM_TOKEN,
11
+ DIESEL_LP_TOKEN
12
+ }
@@ -1,137 +1,143 @@
1
- import {TradeAction, TradeType} from "../pathfinder/tradeTypes";
2
- import {TokenBase} from "./token";
3
- import {CurveLPToken} from "./curveLP";
4
- import {NormalToken} from "./normal";
5
- import {TokenType} from "./tokenType";
1
+ import type { YearnVaultContract } from "../contracts/contracts";
2
+ import { TradeAction, TradeType } from "../pathfinder/tradeTypes";
3
+ import type { TokenBase } from "./token";
4
+ import type { CurveLPToken } from "./curveLP";
5
+ import { NormalToken } from "./normal";
6
+ import { TokenType } from "./tokenType";
6
7
 
7
8
  export type YearnLPToken =
8
- | "yvDAI"
9
- | "yvUSDC"
10
- | "yvWETH"
11
- | "yvWBTC"
12
- | "yvCurve_stETH"
13
- | "yvCurve_FRAX";
9
+ | "yvDAI"
10
+ | "yvUSDC"
11
+ | "yvWETH"
12
+ | "yvWBTC"
13
+ | "yvCurve_stETH"
14
+ | "yvCurve_FRAX";
14
15
 
15
16
  export type YearnVaultTokenData = {
16
- symbol: YearnLPToken;
17
- type: TokenType.YEARN_VAULT;
18
- underlying: NormalToken;
19
- lpActions: Array<TradeAction>;
17
+ symbol: YearnLPToken;
18
+ type: TokenType.YEARN_VAULT;
19
+ underlying: NormalToken;
20
+ lpActions: Array<TradeAction>;
21
+ vault: YearnVaultContract;
20
22
  } & TokenBase;
21
23
 
22
24
  export type YearnVaultOfCurveLPTokenData = {
23
- symbol: YearnLPToken;
24
- type: TokenType.YEARN_VAULT_OF_CURVE_LP;
25
- underlying: CurveLPToken;
26
- lpActions: Array<TradeAction>;
25
+ symbol: YearnLPToken;
26
+ type: TokenType.YEARN_VAULT_OF_CURVE_LP;
27
+ underlying: CurveLPToken;
28
+ lpActions: Array<TradeAction>;
29
+ vault: YearnVaultContract;
27
30
  } & TokenBase;
28
31
 
29
32
  export type YearnVaultOfMetaCurveLPTokenData = {
30
- symbol: YearnLPToken;
31
- type: TokenType.YEARN_VAULT_OF_META_CURVE_LP;
32
- underlying: CurveLPToken;
33
- lpActions: Array<TradeAction>;
33
+ symbol: YearnLPToken;
34
+ type: TokenType.YEARN_VAULT_OF_META_CURVE_LP;
35
+ underlying: CurveLPToken;
36
+ lpActions: Array<TradeAction>;
37
+ vault: YearnVaultContract;
34
38
  } & TokenBase;
35
39
 
36
- export const yearnTokens: Record<YearnLPToken,
37
- | YearnVaultTokenData
38
- | YearnVaultOfCurveLPTokenData
39
- | YearnVaultOfMetaCurveLPTokenData> = {
40
- // YEARN TOKENS
41
- yvDAI: {
42
- name: "yvDAI",
43
- decimals: 18,
44
-
45
- symbol: "yvDAI",
46
- type: TokenType.YEARN_VAULT,
47
- underlying: "DAI",
48
- lpActions: [
49
- {
50
- type: TradeType.YearnWithdraw,
51
- contract: "YEARN_DAI_VAULT",
52
- tokenOut: "DAI"
53
- }
54
- ]
55
- },
56
-
57
- yvUSDC: {
58
- name: "yvUSDC",
59
- decimals: 6,
60
-
61
- symbol: "yvUSDC",
62
- type: TokenType.YEARN_VAULT,
63
- underlying: "USDC",
64
- lpActions: [
65
- {
66
- type: TradeType.YearnWithdraw,
67
- contract: "YEARN_USDC_VAULT",
68
- tokenOut: "USDC"
69
- }
70
- ]
71
- },
72
-
73
- yvWETH: {
74
- name: "yvWETH",
75
- decimals: 18,
76
-
77
- symbol: "yvWETH",
78
- type: TokenType.YEARN_VAULT,
79
- underlying: "WETH",
80
- lpActions: [
81
- {
82
- type: TradeType.YearnWithdraw,
83
- contract: "YEARN_WETH_VAULT",
84
- tokenOut: "WETH"
85
- }
86
- ]
87
- },
88
-
89
- yvWBTC: {
90
- name: "yvWBTC",
91
- decimals: 8,
92
-
93
- symbol: "yvWBTC",
94
- type: TokenType.YEARN_VAULT,
95
- underlying: "WBTC",
96
- lpActions: [
97
- {
98
- type: TradeType.YearnWithdraw,
99
- contract: "YEARN_WBTC_VAULT",
100
- tokenOut: "WBTC"
101
- }
102
- ]
103
- },
104
-
105
- // YEARN- CURVE TOKENS
106
- yvCurve_stETH: {
107
- name: "yvCurve-stETH",
108
- decimals: 18,
109
-
110
- symbol: "yvCurve_stETH",
111
- type: TokenType.YEARN_VAULT_OF_CURVE_LP,
112
- underlying: "steCRV",
113
- lpActions: [
114
- {
115
- type: TradeType.YearnWithdraw,
116
- contract: "YEARN_CURVE_STETH_VAULT",
117
- tokenOut: "steCRV"
118
- }
119
- ]
120
- },
121
-
122
- yvCurve_FRAX: {
123
- name: "yvCurve-FRAX",
124
- decimals: 18,
125
-
126
- symbol: "yvCurve_FRAX",
127
- type: TokenType.YEARN_VAULT_OF_META_CURVE_LP,
128
- underlying: "FRAX3CRV",
129
- lpActions: [
130
- {
131
- type: TradeType.YearnWithdraw,
132
- contract: "YEARN_CURVE_FRAX_VAULT",
133
- tokenOut: "FRAX3CRV"
134
- }
135
- ]
136
- }
40
+ export const yearnTokens: Record<
41
+ YearnLPToken,
42
+ | YearnVaultTokenData
43
+ | YearnVaultOfCurveLPTokenData
44
+ | YearnVaultOfMetaCurveLPTokenData
45
+ > = {
46
+ // YEARN TOKENS
47
+ yvDAI: {
48
+ name: "yvDAI",
49
+ decimals: 18,
50
+ symbol: "yvDAI",
51
+ type: TokenType.YEARN_VAULT,
52
+ underlying: "DAI",
53
+ vault: "YEARN_DAI_VAULT",
54
+ lpActions: [
55
+ {
56
+ type: TradeType.YearnWithdraw,
57
+ contract: "YEARN_DAI_VAULT",
58
+ tokenOut: "DAI"
59
+ }
60
+ ]
61
+ },
62
+
63
+ yvUSDC: {
64
+ name: "yvUSDC",
65
+ decimals: 6,
66
+ symbol: "yvUSDC",
67
+ type: TokenType.YEARN_VAULT,
68
+ underlying: "USDC",
69
+ vault: "YEARN_USDC_VAULT",
70
+ lpActions: [
71
+ {
72
+ type: TradeType.YearnWithdraw,
73
+ contract: "YEARN_USDC_VAULT",
74
+ tokenOut: "USDC"
75
+ }
76
+ ]
77
+ },
78
+
79
+ yvWETH: {
80
+ name: "yvWETH",
81
+ decimals: 18,
82
+ symbol: "yvWETH",
83
+ type: TokenType.YEARN_VAULT,
84
+ underlying: "WETH",
85
+ vault: "YEARN_WETH_VAULT",
86
+ lpActions: [
87
+ {
88
+ type: TradeType.YearnWithdraw,
89
+ contract: "YEARN_WETH_VAULT",
90
+ tokenOut: "WETH"
91
+ }
92
+ ]
93
+ },
94
+
95
+ yvWBTC: {
96
+ name: "yvWBTC",
97
+ decimals: 8,
98
+ symbol: "yvWBTC",
99
+ type: TokenType.YEARN_VAULT,
100
+ underlying: "WBTC",
101
+ vault: "YEARN_WBTC_VAULT",
102
+ lpActions: [
103
+ {
104
+ type: TradeType.YearnWithdraw,
105
+ contract: "YEARN_WBTC_VAULT",
106
+ tokenOut: "WBTC"
107
+ }
108
+ ]
109
+ },
110
+
111
+ // YEARN- CURVE TOKENS
112
+ yvCurve_stETH: {
113
+ name: "yvCurve-stETH",
114
+ decimals: 18,
115
+ symbol: "yvCurve_stETH",
116
+ type: TokenType.YEARN_VAULT_OF_CURVE_LP,
117
+ underlying: "steCRV",
118
+ vault: "YEARN_CURVE_STETH_VAULT",
119
+ lpActions: [
120
+ {
121
+ type: TradeType.YearnWithdraw,
122
+ contract: "YEARN_CURVE_STETH_VAULT",
123
+ tokenOut: "steCRV"
124
+ }
125
+ ]
126
+ },
127
+
128
+ yvCurve_FRAX: {
129
+ name: "yvCurve-FRAX",
130
+ decimals: 18,
131
+ symbol: "yvCurve_FRAX",
132
+ type: TokenType.YEARN_VAULT_OF_META_CURVE_LP,
133
+ underlying: "FRAX3CRV",
134
+ vault: "YEARN_CURVE_FRAX_VAULT",
135
+ lpActions: [
136
+ {
137
+ type: TradeType.YearnWithdraw,
138
+ contract: "YEARN_CURVE_FRAX_VAULT",
139
+ tokenOut: "FRAX3CRV"
140
+ }
141
+ ]
142
+ }
137
143
  };
@@ -0,0 +1,11 @@
1
+ interface IMetamaskError {
2
+ code: number;
3
+ message: string;
4
+ }
5
+
6
+ export const isMetamaskError = (e: any): e is IMetamaskError => {
7
+ if (!e) return false;
8
+ if (typeof e !== "object") return false;
9
+ if (typeof e.code !== "number" || typeof e.message !== "string") return false;
10
+ return true;
11
+ };
@@ -1,6 +1,6 @@
1
1
  import { BigNumber, BigNumberish } from "ethers";
2
- import { PERCENTAGE_FACTOR, RAY, LEVERAGE_DECIMALS } from "../core/constants";
3
2
  import Decimal from "decimal.js-light";
3
+ import { PERCENTAGE_FACTOR, RAY, LEVERAGE_DECIMALS } from "../core/constants";
4
4
 
5
5
  export function rayToNumber(num: BigNumberish): number {
6
6
  return (
@@ -13,10 +13,13 @@ export function formatRAY(num?: BigNumber): string {
13
13
  }
14
14
 
15
15
  export function formatBN(
16
- num: BigNumberish | undefined,
16
+ numArg: BigNumberish | undefined,
17
17
  decimals: number,
18
- precision?: number
18
+ precisionArg?: number
19
19
  ): string {
20
+ let num = numArg;
21
+ let precision = precisionArg;
22
+
20
23
  if (!num) return "-";
21
24
 
22
25
  // if (BigNumber.from(num).gt(BigNumber.from(10).pow(37))) {
@@ -64,23 +67,24 @@ export function formatBn4dig(num: BigNumber, precision: number = 2): string {
64
67
  let numStr = num.toString();
65
68
  if (numStr.length < 6) numStr = "0".repeat(6 - numStr.length) + numStr;
66
69
  return numStr.length <= 6
67
- ? "0." + numStr.slice(0, precision)
68
- : numStr.slice(0, numStr.length - 6) +
69
- "." +
70
- numStr.slice(numStr.length - 6, numStr.length - 6 + precision);
70
+ ? `0.${numStr.slice(0, precision)}`
71
+ : `${numStr.slice(0, numStr.length - 6)}.${numStr.slice(
72
+ numStr.length - 6,
73
+ numStr.length - 6 + precision
74
+ )}`;
71
75
  }
72
76
 
73
77
  export function toHumanFormat(num: BigNumber, precision: number = 2): string {
74
78
  if (num.gte(1e15)) {
75
- return formatBn4dig(num.div(1e9), precision) + "Bn";
79
+ return `${formatBn4dig(num.div(1e9), precision)}Bn`;
76
80
  }
77
81
 
78
82
  if (num.gte(1e12)) {
79
- return formatBn4dig(num.div(1e6), precision) + "M";
83
+ return `${formatBn4dig(num.div(1e6), precision)}M`;
80
84
  }
81
85
 
82
86
  if (num.gte(1e9)) {
83
- return formatBn4dig(num.div(1e3), precision) + "K";
87
+ return `${formatBn4dig(num.div(1e3), precision)}K`;
84
88
  }
85
89
 
86
90
  return formatBn4dig(num, precision);
@@ -112,23 +116,23 @@ export function shortHash(address?: string): string {
112
116
 
113
117
  export const formatRate = (rate: BigNumberish | undefined) =>
114
118
  rate
115
- ? (
119
+ ? `${(
116
120
  BigNumber.from(rate)
117
121
  .mul(PERCENTAGE_FACTOR)
118
122
  .mul(100)
119
123
  .div(RAY)
120
124
  .toNumber() / PERCENTAGE_FACTOR
121
- ).toFixed(2) + "%"
125
+ ).toFixed(2)}%`
122
126
  : "0.00%";
123
127
 
124
128
  export function formatDate(date: Date): string {
125
- var d = new Date(date),
126
- month = "" + (d.getMonth() + 1),
127
- day = "" + d.getDate(),
128
- year = d.getFullYear();
129
+ const d = new Date(date);
130
+ let month = `${d.getMonth() + 1}`;
131
+ let day = `${d.getDate()}`;
132
+ const year = d.getFullYear();
129
133
 
130
- if (month.length < 2) month = "0" + month;
131
- if (day.length < 2) day = "0" + day;
134
+ if (month.length < 2) month = `0${month}`;
135
+ if (day.length < 2) day = `0${day}`;
132
136
 
133
137
  return [year, month, day].join("-");
134
138
  }
@@ -1,9 +1,17 @@
1
- export function loadingProgress(...params: Array<unknown>): number {
2
- let isLoaded: number = 0;
1
+ const isLoaded = (v: unknown) => v !== undefined;
3
2
 
4
- for (const item of params) {
5
- if (item !== undefined) isLoaded++;
6
- }
3
+ export function allLoaded(itemsToLoad: Array<unknown>): boolean {
4
+ return itemsToLoad.reduce<boolean>(
5
+ (acc, item) => acc && isLoaded(item),
6
+ true
7
+ );
8
+ }
9
+
10
+ export function loadingProgress(itemsToLoad: Array<unknown>): number {
11
+ const loaded = itemsToLoad.reduce<number>(
12
+ (acc, item) => (isLoaded(item) ? acc + 1 : acc),
13
+ 0
14
+ );
7
15
 
8
- return Math.floor((isLoaded / params.length) * 100);
16
+ return Math.floor((loaded / itemsToLoad.length) * 100);
9
17
  }
@@ -7,9 +7,10 @@ const objectEntries = <K extends SupportedValue, T>(
7
7
  const swapKeyValue = <K extends SupportedValue, T extends SupportedValue>(
8
8
  o: Record<K, T>
9
9
  ): Record<T, K> =>
10
- objectEntries(o).reduce((acc, [key, value]) => {
11
- return { ...acc, [value]: key };
12
- }, {} as Record<T, K>);
10
+ objectEntries(o).reduce(
11
+ (acc, [key, value]) => ({ ...acc, [value]: key }),
12
+ {} as Record<T, K>
13
+ );
13
14
 
14
15
  const keyToLowercase = <K extends SupportedValue, T extends SupportedValue>(
15
16
  o: Record<K, T>
@@ -22,9 +23,10 @@ const keyToLowercase = <K extends SupportedValue, T extends SupportedValue>(
22
23
  const filterEmptyKeys = <K extends SupportedValue, T extends SupportedValue>(
23
24
  o: Record<K, T>
24
25
  ): Record<K, T> =>
25
- objectEntries(o).reduce((acc, [key, value]) => {
26
- return !!key ? { ...acc, [key]: value } : acc;
27
- }, {} as Record<K, T>);
26
+ objectEntries(o).reduce(
27
+ (acc, [key, value]) => (key ? { ...acc, [key]: value } : acc),
28
+ {} as Record<K, T>
29
+ );
28
30
 
29
31
  export type { SupportedValue };
30
32
  export { objectEntries, swapKeyValue, keyToLowercase, filterEmptyKeys };
@@ -36,7 +36,9 @@ export async function multicall<R extends Array<any>>(
36
36
 
37
37
  export class MultiCallContract<T extends ethers.utils.Interface> {
38
38
  private readonly _address: string;
39
+
39
40
  private readonly _interface: T;
41
+
40
42
  protected _multiCall: Multicall2;
41
43
 
42
44
  constructor(
@@ -1,28 +1,28 @@
1
- import {ethers} from "ethers";
2
- import {tokenDataByNetwork} from "../tokens/token";
3
- import {ERC20__factory} from "../types";
4
- import {ADDRESS_0x0, NetworkType} from "../core/constants";
1
+ import { ethers } from "ethers";
2
+ import { tokenDataByNetwork } from "../tokens/token";
3
+ import { ERC20__factory } from "../types";
4
+ import { ADDRESS_0X0, NetworkType } from "../core/constants";
5
5
 
6
6
  export async function detectNetwork(
7
- provider: ethers.providers.Provider
7
+ provider: ethers.providers.Provider
8
8
  ): Promise<NetworkType> {
9
+ try {
10
+ const usdcMainnet = ERC20__factory.connect(
11
+ tokenDataByNetwork.Mainnet.USDC,
12
+ provider
13
+ );
14
+ await usdcMainnet.balanceOf(ADDRESS_0X0);
15
+ return "Mainnet";
16
+ } catch {
9
17
  try {
10
- const usdcMainnet = ERC20__factory.connect(
11
- tokenDataByNetwork.Mainnet.USDC,
12
- provider
13
- );
14
- await usdcMainnet.balanceOf(ADDRESS_0x0);
15
- return "Mainnet";
18
+ const usdcMainnet = ERC20__factory.connect(
19
+ tokenDataByNetwork.Kovan.USDC,
20
+ provider
21
+ );
22
+ await usdcMainnet.balanceOf(ADDRESS_0X0);
23
+ return "Kovan";
16
24
  } catch {
17
- try {
18
- const usdcMainnet = ERC20__factory.connect(
19
- tokenDataByNetwork.Kovan.USDC,
20
- provider
21
- );
22
- await usdcMainnet.balanceOf(ADDRESS_0x0);
23
- return "Kovan";
24
- } catch {
25
- throw new Error("Unknown network");
26
- }
25
+ throw new Error("Unknown network");
27
26
  }
27
+ }
28
28
  }
@@ -4,9 +4,9 @@ export async function callRepeater<T>(
4
4
  call: () => Promise<T>,
5
5
  step: number = 0
6
6
  ): Promise<T> {
7
- return new Promise<T>(async (resolve, reject) => {
7
+ return new Promise<T>((resolve, reject) => {
8
8
  try {
9
- resolve(await call());
9
+ call().then(r => resolve(r));
10
10
  } catch (e) {
11
11
  console.error(`Error ${step}: ${e}`);
12
12
  if (step > 5 || (e as MetamaskError).code !== -32000) reject(e);
@@ -3,6 +3,6 @@ export function isPositiveFloat(val: string): boolean {
3
3
  if (!floatRegex.test(val)) return false;
4
4
 
5
5
  const valF = parseFloat(val);
6
- if (isNaN(valF)) return false;
6
+ if (Number.isNaN(valF)) return false;
7
7
  return true;
8
8
  }
@@ -1,2 +0,0 @@
1
- import { TypedEvent } from "../types/common";
2
- export declare const typedEventsComparator: (a: TypedEvent<any>, b: TypedEvent<any>) => 1 | -1;
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.typedEventsComparator = void 0;
4
- var typedEventsComparator = function (a, b) {
5
- return a.blockNumber === b.blockNumber
6
- ? a.logIndex > b.logIndex
7
- ? 1
8
- : -1
9
- : a.blockNumber > b.blockNumber
10
- ? 1
11
- : -1;
12
- };
13
- exports.typedEventsComparator = typedEventsComparator;
@@ -1,10 +0,0 @@
1
- import {TypedEvent} from "../types/common";
2
-
3
- export const typedEventsComparator = (a: TypedEvent<any>, b: TypedEvent<any>) =>
4
- a.blockNumber === b.blockNumber
5
- ? a.logIndex > b.logIndex
6
- ? 1
7
- : -1
8
- : a.blockNumber > b.blockNumber
9
- ? 1
10
- : -1;