@gearbox-protocol/sdk 0.0.100 → 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.
- package/.eslintignore +4 -0
- package/.eslintrc.js +52 -0
- package/.husky/pre-push +4 -0
- package/lib/apy/convexAPY.d.ts +8 -0
- package/lib/apy/convexAPY.js +200 -0
- package/lib/apy/lidoAPY.d.ts +4 -0
- package/lib/apy/lidoAPY.js +103 -0
- package/lib/config.d.ts +1 -0
- package/lib/config.js +2 -1
- package/lib/contracts/contracts.d.ts +9 -4
- package/lib/contracts/contracts.js +52 -14
- package/lib/contracts/contractsRegister.js +16 -4
- package/lib/core/constants.d.ts +7 -1
- package/lib/core/constants.js +11 -5
- package/lib/core/creditAccount.d.ts +3 -1
- package/lib/core/creditAccount.js +33 -31
- package/lib/core/creditManager.d.ts +13 -2
- package/lib/core/creditManager.js +77 -33
- package/lib/core/creditSession.js +14 -3
- package/lib/core/errors.d.ts +10 -0
- package/lib/core/errors.js +16 -1
- package/lib/core/eventOrTx.d.ts +1 -1
- package/lib/core/events.d.ts +19 -19
- package/lib/core/events.js +32 -30
- package/lib/core/multicall.d.ts +1 -1
- package/lib/core/pool.d.ts +2 -2
- package/lib/core/pool.js +8 -12
- package/lib/core/price.d.ts +2 -0
- package/lib/core/price.js +14 -0
- package/lib/core/strategy.d.ts +36 -0
- package/lib/core/strategy.js +57 -0
- package/lib/core/tokenDistributor.js +1 -1
- package/lib/core/transactions.d.ts +18 -3
- package/lib/core/transactions.js +39 -3
- package/lib/index.d.ts +8 -3
- package/lib/index.js +9 -4
- package/lib/oracles/priceFeeds.js +1 -1
- package/lib/pathfinder/convexLP.d.ts +1 -1
- package/lib/pathfinder/convexLP.js +26 -29
- package/lib/pathfinder/curveLP.d.ts +1 -1
- package/lib/pathfinder/curveLP.js +5 -7
- package/lib/pathfinder/path.d.ts +1 -1
- package/lib/pathfinder/path.js +38 -42
- package/lib/pathfinder/trade.d.ts +1 -2
- package/lib/pathfinder/tradeTypes.d.ts +5 -5
- package/lib/pathfinder/yVault.d.ts +2 -2
- package/lib/pathfinder/yVault.js +22 -19
- package/lib/payload/creditAccount.d.ts +4 -26
- package/lib/payload/creditManager.d.ts +3 -25
- package/lib/payload/pool.d.ts +2 -17
- package/lib/payload/pool.js +0 -1
- package/lib/strategies/curve.d.ts +6 -60
- package/lib/strategies/curve.js +6 -0
- package/lib/strategies/uniswapV2.js +3 -19
- package/lib/strategies/uniswapV3.js +1 -1
- package/lib/strategies/yearn.js +15 -11
- package/lib/tokens/convex.d.ts +3 -3
- package/lib/tokens/curveLP.d.ts +2 -2
- package/lib/tokens/curveLP.js +1 -1
- package/lib/tokens/gear.d.ts +2 -2
- package/lib/tokens/gear.js +1 -1
- package/lib/tokens/normal.d.ts +1 -1
- package/lib/tokens/token.js +9 -9
- package/lib/tokens/tokenData.d.ts +3 -1
- package/lib/tokens/tokenData.js +10 -8
- package/lib/tokens/yearn.d.ts +3 -3
- package/lib/utils/errors.d.ts +6 -0
- package/lib/utils/errors.js +13 -0
- package/lib/utils/formatter.d.ts +2 -1
- package/lib/utils/formatter.js +23 -15
- package/lib/utils/loading.d.ts +2 -1
- package/lib/utils/loading.js +9 -13
- package/lib/utils/mappers.d.ts +2 -1
- package/lib/utils/mappers.js +13 -5
- package/lib/utils/multicall.js +4 -3
- package/lib/utils/network.js +2 -2
- package/lib/utils/repeater.js +12 -24
- package/lib/utils/types.d.ts +1 -0
- package/lib/utils/validate.js +1 -1
- package/package.json +26 -8
- package/src/apy/convexAPY.ts +250 -0
- package/src/apy/lidoAPY.ts +89 -0
- package/src/config.ts +2 -1
- package/src/contracts/contracts.ts +73 -19
- package/src/contracts/contractsRegister.ts +19 -4
- package/src/core/constants.ts +11 -4
- package/src/core/creditAccount.ts +69 -37
- package/src/core/creditManager.ts +256 -148
- package/src/core/creditOperation.ts +7 -7
- package/src/core/creditSession.ts +25 -5
- package/src/core/errors.ts +25 -0
- package/src/core/eventOrTx.ts +8 -5
- package/src/core/events.ts +978 -911
- package/src/core/history.ts +46 -46
- package/src/core/multicall.ts +1 -1
- package/src/core/operations.ts +6 -0
- package/src/core/pool.ts +75 -58
- package/src/core/price.ts +13 -0
- package/src/core/strategy.ts +134 -0
- package/src/core/tokenDistributor.ts +2 -2
- package/src/core/transactions.ts +427 -350
- package/src/index.ts +9 -4
- package/src/oracles/priceFeeds.ts +523 -523
- package/src/pathfinder/contracts.ts +15 -13
- package/src/pathfinder/convexLP.ts +29 -25
- package/src/pathfinder/curveLP.ts +57 -53
- package/src/pathfinder/path.ts +158 -150
- package/src/pathfinder/priority.ts +11 -11
- package/src/pathfinder/trade.ts +84 -77
- package/src/pathfinder/tradeTypes.ts +98 -94
- package/src/pathfinder/yVault.ts +79 -63
- package/src/payload/creditAccount.ts +4 -26
- package/src/payload/creditManager.ts +4 -26
- package/src/payload/pool.ts +2 -19
- package/src/payload/token.ts +3 -3
- package/src/strategies/convex.ts +217 -210
- package/src/strategies/creditFacade.ts +70 -53
- package/src/strategies/curve.ts +263 -194
- package/src/strategies/lido.ts +33 -37
- package/src/strategies/uniswapV2.ts +90 -112
- package/src/strategies/uniswapV3.ts +114 -91
- package/src/strategies/yearn.ts +58 -62
- package/src/tokens/connectors.ts +6 -6
- package/src/tokens/convex.ts +297 -296
- package/src/tokens/curveLP.ts +170 -165
- package/src/tokens/gear.ts +47 -45
- package/src/tokens/normal.ts +801 -802
- package/src/tokens/token.ts +19 -10
- package/src/tokens/tokenData.ts +19 -9
- package/src/tokens/tokenType.ts +11 -11
- package/src/tokens/yearn.ts +126 -124
- package/src/utils/errors.ts +11 -0
- package/src/utils/formatter.ts +26 -18
- package/src/utils/loading.ts +14 -6
- package/src/utils/mappers.ts +15 -6
- package/src/utils/multicall.ts +6 -9
- package/src/utils/network.ts +21 -21
- package/src/utils/repeater.ts +2 -2
- package/src/utils/types.ts +6 -2
- package/src/utils/validate.ts +1 -1
- package/lib/core/adapters.d.ts +0 -15
- package/lib/core/adapters.js +0 -19
- package/lib/core/contracts.d.ts +0 -67
- package/lib/core/contracts.js +0 -254
- package/lib/core/contractsRegister.d.ts +0 -2
- package/lib/core/contractsRegister.js +0 -58
- package/lib/core/creditCard.d.ts +0 -13
- package/lib/core/creditCard.js +0 -2
- package/lib/core/oracles.d.ts +0 -38
- package/lib/core/oracles.js +0 -12
- package/lib/core/priceFeeds.d.ts +0 -3
- package/lib/core/priceFeeds.js +0 -492
- package/lib/core/protocols.d.ts +0 -13
- package/lib/core/protocols.js +0 -39
- package/lib/core/swap.d.ts +0 -4
- package/lib/core/swap.js +0 -8
- package/lib/core/trade.d.ts +0 -35
- package/lib/core/trade.js +0 -62
- package/lib/core/tradeTypes.d.ts +0 -79
- package/lib/core/tradeTypes.js +0 -21
- package/lib/utils/events.d.ts +0 -2
- package/lib/utils/events.js +0 -13
- package/src/utils/events.ts +0 -10
package/src/tokens/token.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
keyToLowercase,
|
|
3
|
+
objectEntries,
|
|
4
|
+
swapKeyValue,
|
|
5
|
+
filterEmptyKeys
|
|
6
|
+
} from "../utils/mappers";
|
|
2
7
|
import { NetworkType } from "../core/constants";
|
|
3
8
|
import { NormalToken, NormalTokenData, normalTokens } from "./normal";
|
|
4
9
|
import {
|
|
@@ -134,7 +139,7 @@ export const tokenDataByNetwork: Record<
|
|
|
134
139
|
yvCurve_stETH: "0xdCD90C7f6324cfa40d7169ef80b12031770B4325",
|
|
135
140
|
yvCurve_FRAX: "0xB4AdA607B9d6b2c9Ee07A275e9616B84AC560139",
|
|
136
141
|
|
|
137
|
-
//GEARBOX
|
|
142
|
+
// GEARBOX
|
|
138
143
|
dDAI: "0x6CFaF95457d7688022FC53e7AbE052ef8DFBbdBA",
|
|
139
144
|
dUSDC: "0xc411dB5f5Eb3f7d552F9B8454B2D74097ccdE6E3",
|
|
140
145
|
dWBTC: "0xe753260F1955e8678DCeA8887759e07aa57E8c54",
|
|
@@ -212,11 +217,11 @@ export const tokenDataByNetwork: Record<
|
|
|
212
217
|
stkcvxsteCRV: "0xd8bAbB7EfBF7F931a69B209f71b27421F8b18516",
|
|
213
218
|
stkcvxcrvPlain3andSUSD: "0x6b45Cab756B41a7204973b71362ef5F73E67F6DA",
|
|
214
219
|
|
|
215
|
-
//GEARBOX
|
|
216
|
-
dDAI: "
|
|
217
|
-
dUSDC: "
|
|
218
|
-
dWBTC: "
|
|
219
|
-
dWETH: "
|
|
220
|
+
// GEARBOX
|
|
221
|
+
dDAI: "0x077a3Ce0D572b72436F6644793Fc7721353aF1f4",
|
|
222
|
+
dUSDC: "0x8147e00456c8A3128182730bFFdFd9D1E6bbC048",
|
|
223
|
+
dWBTC: "0x34D9B3c13B25632879B2DaabBde702F612902238",
|
|
224
|
+
dWETH: "0x19e4F905749D3b487CA4927b54e55b64625a1143",
|
|
220
225
|
|
|
221
226
|
GEAR: "0xe01c5d0297c56e992dab3886057a1441485ff7c7"
|
|
222
227
|
}
|
|
@@ -224,6 +229,10 @@ export const tokenDataByNetwork: Record<
|
|
|
224
229
|
|
|
225
230
|
export const tokenSymbolByAddress = objectEntries(tokenDataByNetwork).reduce<
|
|
226
231
|
Record<string, SupportedToken>
|
|
227
|
-
>(
|
|
228
|
-
|
|
229
|
-
|
|
232
|
+
>(
|
|
233
|
+
(acc, [, tokens]) => ({
|
|
234
|
+
...acc,
|
|
235
|
+
...filterEmptyKeys(keyToLowercase(swapKeyValue(tokens)))
|
|
236
|
+
}),
|
|
237
|
+
{}
|
|
238
|
+
);
|
package/src/tokens/tokenData.ts
CHANGED
|
@@ -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(
|
|
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(
|
|
76
|
+
return connectors[networkType].map(e => {
|
|
67
77
|
const result =
|
|
68
78
|
e === "WETH"
|
|
69
79
|
? WETHToken[networkType]
|
package/src/tokens/tokenType.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export enum TokenType {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
+
}
|
package/src/tokens/yearn.ts
CHANGED
|
@@ -1,137 +1,139 @@
|
|
|
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 { TradeAction, TradeType } from "../pathfinder/tradeTypes";
|
|
2
|
+
import type { TokenBase } from "./token";
|
|
3
|
+
import type { CurveLPToken } from "./curveLP";
|
|
4
|
+
import type { NormalToken } from "./normal";
|
|
5
|
+
import { TokenType } from "./tokenType";
|
|
6
6
|
|
|
7
7
|
export type YearnLPToken =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
| "yvDAI"
|
|
9
|
+
| "yvUSDC"
|
|
10
|
+
| "yvWETH"
|
|
11
|
+
| "yvWBTC"
|
|
12
|
+
| "yvCurve_stETH"
|
|
13
|
+
| "yvCurve_FRAX";
|
|
14
14
|
|
|
15
15
|
export type YearnVaultTokenData = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
symbol: YearnLPToken;
|
|
17
|
+
type: TokenType.YEARN_VAULT;
|
|
18
|
+
underlying: NormalToken;
|
|
19
|
+
lpActions: Array<TradeAction>;
|
|
20
20
|
} & TokenBase;
|
|
21
21
|
|
|
22
22
|
export type YearnVaultOfCurveLPTokenData = {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
symbol: YearnLPToken;
|
|
24
|
+
type: TokenType.YEARN_VAULT_OF_CURVE_LP;
|
|
25
|
+
underlying: CurveLPToken;
|
|
26
|
+
lpActions: Array<TradeAction>;
|
|
27
27
|
} & TokenBase;
|
|
28
28
|
|
|
29
29
|
export type YearnVaultOfMetaCurveLPTokenData = {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
symbol: YearnLPToken;
|
|
31
|
+
type: TokenType.YEARN_VAULT_OF_META_CURVE_LP;
|
|
32
|
+
underlying: CurveLPToken;
|
|
33
|
+
lpActions: Array<TradeAction>;
|
|
34
34
|
} & TokenBase;
|
|
35
35
|
|
|
36
|
-
export const yearnTokens: Record<
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
36
|
+
export const yearnTokens: Record<
|
|
37
|
+
YearnLPToken,
|
|
38
|
+
| YearnVaultTokenData
|
|
39
|
+
| YearnVaultOfCurveLPTokenData
|
|
40
|
+
| YearnVaultOfMetaCurveLPTokenData
|
|
41
|
+
> = {
|
|
42
|
+
// YEARN TOKENS
|
|
43
|
+
yvDAI: {
|
|
44
|
+
name: "yvDAI",
|
|
45
|
+
decimals: 18,
|
|
46
|
+
|
|
47
|
+
symbol: "yvDAI",
|
|
48
|
+
type: TokenType.YEARN_VAULT,
|
|
49
|
+
underlying: "DAI",
|
|
50
|
+
lpActions: [
|
|
51
|
+
{
|
|
52
|
+
type: TradeType.YearnWithdraw,
|
|
53
|
+
contract: "YEARN_DAI_VAULT",
|
|
54
|
+
tokenOut: "DAI"
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
yvUSDC: {
|
|
60
|
+
name: "yvUSDC",
|
|
61
|
+
decimals: 6,
|
|
62
|
+
|
|
63
|
+
symbol: "yvUSDC",
|
|
64
|
+
type: TokenType.YEARN_VAULT,
|
|
65
|
+
underlying: "USDC",
|
|
66
|
+
lpActions: [
|
|
67
|
+
{
|
|
68
|
+
type: TradeType.YearnWithdraw,
|
|
69
|
+
contract: "YEARN_USDC_VAULT",
|
|
70
|
+
tokenOut: "USDC"
|
|
71
|
+
}
|
|
72
|
+
]
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
yvWETH: {
|
|
76
|
+
name: "yvWETH",
|
|
77
|
+
decimals: 18,
|
|
78
|
+
|
|
79
|
+
symbol: "yvWETH",
|
|
80
|
+
type: TokenType.YEARN_VAULT,
|
|
81
|
+
underlying: "WETH",
|
|
82
|
+
lpActions: [
|
|
83
|
+
{
|
|
84
|
+
type: TradeType.YearnWithdraw,
|
|
85
|
+
contract: "YEARN_WETH_VAULT",
|
|
86
|
+
tokenOut: "WETH"
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
yvWBTC: {
|
|
92
|
+
name: "yvWBTC",
|
|
93
|
+
decimals: 8,
|
|
94
|
+
|
|
95
|
+
symbol: "yvWBTC",
|
|
96
|
+
type: TokenType.YEARN_VAULT,
|
|
97
|
+
underlying: "WBTC",
|
|
98
|
+
lpActions: [
|
|
99
|
+
{
|
|
100
|
+
type: TradeType.YearnWithdraw,
|
|
101
|
+
contract: "YEARN_WBTC_VAULT",
|
|
102
|
+
tokenOut: "WBTC"
|
|
103
|
+
}
|
|
104
|
+
]
|
|
105
|
+
},
|
|
106
|
+
|
|
107
|
+
// YEARN- CURVE TOKENS
|
|
108
|
+
yvCurve_stETH: {
|
|
109
|
+
name: "yvCurve-stETH",
|
|
110
|
+
decimals: 18,
|
|
111
|
+
|
|
112
|
+
symbol: "yvCurve_stETH",
|
|
113
|
+
type: TokenType.YEARN_VAULT_OF_CURVE_LP,
|
|
114
|
+
underlying: "steCRV",
|
|
115
|
+
lpActions: [
|
|
116
|
+
{
|
|
117
|
+
type: TradeType.YearnWithdraw,
|
|
118
|
+
contract: "YEARN_CURVE_STETH_VAULT",
|
|
119
|
+
tokenOut: "steCRV"
|
|
120
|
+
}
|
|
121
|
+
]
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
yvCurve_FRAX: {
|
|
125
|
+
name: "yvCurve-FRAX",
|
|
126
|
+
decimals: 18,
|
|
127
|
+
|
|
128
|
+
symbol: "yvCurve_FRAX",
|
|
129
|
+
type: TokenType.YEARN_VAULT_OF_META_CURVE_LP,
|
|
130
|
+
underlying: "FRAX3CRV",
|
|
131
|
+
lpActions: [
|
|
132
|
+
{
|
|
133
|
+
type: TradeType.YearnWithdraw,
|
|
134
|
+
contract: "YEARN_CURVE_FRAX_VAULT",
|
|
135
|
+
tokenOut: "FRAX3CRV"
|
|
136
|
+
}
|
|
137
|
+
]
|
|
138
|
+
}
|
|
137
139
|
};
|
|
@@ -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
|
+
};
|
package/src/utils/formatter.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BigNumber, BigNumberish } from "ethers";
|
|
2
|
-
import { PERCENTAGE_FACTOR, RAY } 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
|
-
|
|
16
|
+
numArg: BigNumberish | undefined,
|
|
17
17
|
decimals: number,
|
|
18
|
-
|
|
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
|
-
?
|
|
68
|
-
: numStr.slice(0, numStr.length - 6)
|
|
69
|
-
|
|
70
|
-
numStr.
|
|
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)
|
|
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)
|
|
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)
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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 =
|
|
131
|
-
if (day.length < 2) 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
|
}
|
|
@@ -136,3 +140,7 @@ export function formatDate(date: Date): string {
|
|
|
136
140
|
export function formatHf(healthFactor: number): string {
|
|
137
141
|
return (healthFactor / 10000).toFixed(2);
|
|
138
142
|
}
|
|
143
|
+
|
|
144
|
+
export function formatLeverage(leverage: number, decimals: number = 2) {
|
|
145
|
+
return (leverage / LEVERAGE_DECIMALS).toFixed(decimals);
|
|
146
|
+
}
|
package/src/utils/loading.ts
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
let isLoaded: number = 0;
|
|
1
|
+
const isLoaded = (v: unknown) => v !== undefined;
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
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((
|
|
16
|
+
return Math.floor((loaded / itemsToLoad.length) * 100);
|
|
9
17
|
}
|
package/src/utils/mappers.ts
CHANGED
|
@@ -7,17 +7,26 @@ 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(
|
|
11
|
-
|
|
12
|
-
|
|
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>
|
|
16
17
|
): Record<K, T> =>
|
|
17
|
-
objectEntries(o).reduce((
|
|
18
|
+
objectEntries(o).reduce((acc, [key, value]) => {
|
|
18
19
|
const keyTransformed = typeof key === "string" ? key.toLowerCase() : key;
|
|
19
|
-
return { ...
|
|
20
|
+
return { ...acc, [keyTransformed]: value };
|
|
20
21
|
}, {} as Record<K, T>);
|
|
21
22
|
|
|
23
|
+
const filterEmptyKeys = <K extends SupportedValue, T extends SupportedValue>(
|
|
24
|
+
o: Record<K, T>
|
|
25
|
+
): Record<K, T> =>
|
|
26
|
+
objectEntries(o).reduce(
|
|
27
|
+
(acc, [key, value]) => (key ? { ...acc, [key]: value } : acc),
|
|
28
|
+
{} as Record<K, T>
|
|
29
|
+
);
|
|
30
|
+
|
|
22
31
|
export type { SupportedValue };
|
|
23
|
-
export { objectEntries, swapKeyValue, keyToLowercase };
|
|
32
|
+
export { objectEntries, swapKeyValue, keyToLowercase, filterEmptyKeys };
|
package/src/utils/multicall.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ethers } from "ethers";
|
|
2
|
+
import { MULTICALL_ADDRESS } from "../config";
|
|
2
3
|
import { Multicall2, Multicall2__factory } from "../types";
|
|
3
4
|
|
|
4
5
|
export interface CallData<T extends ethers.utils.Interface> {
|
|
@@ -17,10 +18,7 @@ export async function multicall<R extends Array<any>>(
|
|
|
17
18
|
calls: Array<MCall<any>>,
|
|
18
19
|
p: ethers.providers.Provider
|
|
19
20
|
): Promise<R> {
|
|
20
|
-
const multiCallContract = Multicall2__factory.connect(
|
|
21
|
-
"0x5ba1e12693dc8f9c48aad8770482f4739beed696",
|
|
22
|
-
p
|
|
23
|
-
);
|
|
21
|
+
const multiCallContract = Multicall2__factory.connect(MULTICALL_ADDRESS, p);
|
|
24
22
|
|
|
25
23
|
const { returnData } = await multiCallContract.callStatic.aggregate(
|
|
26
24
|
calls.map(c => ({
|
|
@@ -33,12 +31,14 @@ export async function multicall<R extends Array<any>>(
|
|
|
33
31
|
.map((d, num) =>
|
|
34
32
|
calls[num].interface.decodeFunctionResult(calls[num].method as string, d)
|
|
35
33
|
)
|
|
36
|
-
.map(r => r[0]) as R;
|
|
34
|
+
.map(r => (Array.isArray(r) && r.length <= 1 ? r[0] : r)) as R;
|
|
37
35
|
}
|
|
38
36
|
|
|
39
37
|
export class MultiCallContract<T extends ethers.utils.Interface> {
|
|
40
38
|
private readonly _address: string;
|
|
39
|
+
|
|
41
40
|
private readonly _interface: T;
|
|
41
|
+
|
|
42
42
|
protected _multiCall: Multicall2;
|
|
43
43
|
|
|
44
44
|
constructor(
|
|
@@ -49,10 +49,7 @@ export class MultiCallContract<T extends ethers.utils.Interface> {
|
|
|
49
49
|
this._address = address;
|
|
50
50
|
this._interface = intrerface;
|
|
51
51
|
|
|
52
|
-
this._multiCall = Multicall2__factory.connect(
|
|
53
|
-
"0x5ba1e12693dc8f9c48aad8770482f4739beed696",
|
|
54
|
-
provider
|
|
55
|
-
);
|
|
52
|
+
this._multiCall = Multicall2__factory.connect(MULTICALL_ADDRESS, provider);
|
|
56
53
|
}
|
|
57
54
|
|
|
58
55
|
async call<R extends Array<any>>(data: Array<CallData<T>>): Promise<R> {
|
package/src/utils/network.ts
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import {ethers} from "ethers";
|
|
2
|
-
import {tokenDataByNetwork} from "../tokens/token";
|
|
3
|
-
import {ERC20__factory} from "../types";
|
|
4
|
-
import {
|
|
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
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
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
|
}
|