@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.
Files changed (163) 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.d.ts +8 -0
  5. package/lib/apy/convexAPY.js +200 -0
  6. package/lib/apy/lidoAPY.d.ts +4 -0
  7. package/lib/apy/lidoAPY.js +103 -0
  8. package/lib/config.d.ts +1 -0
  9. package/lib/config.js +2 -1
  10. package/lib/contracts/contracts.d.ts +9 -4
  11. package/lib/contracts/contracts.js +52 -14
  12. package/lib/contracts/contractsRegister.js +16 -4
  13. package/lib/core/constants.d.ts +7 -1
  14. package/lib/core/constants.js +11 -5
  15. package/lib/core/creditAccount.d.ts +3 -1
  16. package/lib/core/creditAccount.js +33 -31
  17. package/lib/core/creditManager.d.ts +13 -2
  18. package/lib/core/creditManager.js +77 -33
  19. package/lib/core/creditSession.js +14 -3
  20. package/lib/core/errors.d.ts +10 -0
  21. package/lib/core/errors.js +16 -1
  22. package/lib/core/eventOrTx.d.ts +1 -1
  23. package/lib/core/events.d.ts +19 -19
  24. package/lib/core/events.js +32 -30
  25. package/lib/core/multicall.d.ts +1 -1
  26. package/lib/core/pool.d.ts +2 -2
  27. package/lib/core/pool.js +8 -12
  28. package/lib/core/price.d.ts +2 -0
  29. package/lib/core/price.js +14 -0
  30. package/lib/core/strategy.d.ts +36 -0
  31. package/lib/core/strategy.js +57 -0
  32. package/lib/core/tokenDistributor.js +1 -1
  33. package/lib/core/transactions.d.ts +18 -3
  34. package/lib/core/transactions.js +39 -3
  35. package/lib/index.d.ts +8 -3
  36. package/lib/index.js +9 -4
  37. package/lib/oracles/priceFeeds.js +1 -1
  38. package/lib/pathfinder/convexLP.d.ts +1 -1
  39. package/lib/pathfinder/convexLP.js +26 -29
  40. package/lib/pathfinder/curveLP.d.ts +1 -1
  41. package/lib/pathfinder/curveLP.js +5 -7
  42. package/lib/pathfinder/path.d.ts +1 -1
  43. package/lib/pathfinder/path.js +38 -42
  44. package/lib/pathfinder/trade.d.ts +1 -2
  45. package/lib/pathfinder/tradeTypes.d.ts +5 -5
  46. package/lib/pathfinder/yVault.d.ts +2 -2
  47. package/lib/pathfinder/yVault.js +22 -19
  48. package/lib/payload/creditAccount.d.ts +4 -26
  49. package/lib/payload/creditManager.d.ts +3 -25
  50. package/lib/payload/pool.d.ts +2 -17
  51. package/lib/payload/pool.js +0 -1
  52. package/lib/strategies/curve.d.ts +6 -60
  53. package/lib/strategies/curve.js +6 -0
  54. package/lib/strategies/uniswapV2.js +3 -19
  55. package/lib/strategies/uniswapV3.js +1 -1
  56. package/lib/strategies/yearn.js +15 -11
  57. package/lib/tokens/convex.d.ts +3 -3
  58. package/lib/tokens/curveLP.d.ts +2 -2
  59. package/lib/tokens/curveLP.js +1 -1
  60. package/lib/tokens/gear.d.ts +2 -2
  61. package/lib/tokens/gear.js +1 -1
  62. package/lib/tokens/normal.d.ts +1 -1
  63. package/lib/tokens/token.js +9 -9
  64. package/lib/tokens/tokenData.d.ts +3 -1
  65. package/lib/tokens/tokenData.js +10 -8
  66. package/lib/tokens/yearn.d.ts +3 -3
  67. package/lib/utils/errors.d.ts +6 -0
  68. package/lib/utils/errors.js +13 -0
  69. package/lib/utils/formatter.d.ts +2 -1
  70. package/lib/utils/formatter.js +23 -15
  71. package/lib/utils/loading.d.ts +2 -1
  72. package/lib/utils/loading.js +9 -13
  73. package/lib/utils/mappers.d.ts +2 -1
  74. package/lib/utils/mappers.js +13 -5
  75. package/lib/utils/multicall.js +4 -3
  76. package/lib/utils/network.js +2 -2
  77. package/lib/utils/repeater.js +12 -24
  78. package/lib/utils/types.d.ts +1 -0
  79. package/lib/utils/validate.js +1 -1
  80. package/package.json +26 -8
  81. package/src/apy/convexAPY.ts +250 -0
  82. package/src/apy/lidoAPY.ts +89 -0
  83. package/src/config.ts +2 -1
  84. package/src/contracts/contracts.ts +73 -19
  85. package/src/contracts/contractsRegister.ts +19 -4
  86. package/src/core/constants.ts +11 -4
  87. package/src/core/creditAccount.ts +69 -37
  88. package/src/core/creditManager.ts +256 -148
  89. package/src/core/creditOperation.ts +7 -7
  90. package/src/core/creditSession.ts +25 -5
  91. package/src/core/errors.ts +25 -0
  92. package/src/core/eventOrTx.ts +8 -5
  93. package/src/core/events.ts +978 -911
  94. package/src/core/history.ts +46 -46
  95. package/src/core/multicall.ts +1 -1
  96. package/src/core/operations.ts +6 -0
  97. package/src/core/pool.ts +75 -58
  98. package/src/core/price.ts +13 -0
  99. package/src/core/strategy.ts +134 -0
  100. package/src/core/tokenDistributor.ts +2 -2
  101. package/src/core/transactions.ts +427 -350
  102. package/src/index.ts +9 -4
  103. package/src/oracles/priceFeeds.ts +523 -523
  104. package/src/pathfinder/contracts.ts +15 -13
  105. package/src/pathfinder/convexLP.ts +29 -25
  106. package/src/pathfinder/curveLP.ts +57 -53
  107. package/src/pathfinder/path.ts +158 -150
  108. package/src/pathfinder/priority.ts +11 -11
  109. package/src/pathfinder/trade.ts +84 -77
  110. package/src/pathfinder/tradeTypes.ts +98 -94
  111. package/src/pathfinder/yVault.ts +79 -63
  112. package/src/payload/creditAccount.ts +4 -26
  113. package/src/payload/creditManager.ts +4 -26
  114. package/src/payload/pool.ts +2 -19
  115. package/src/payload/token.ts +3 -3
  116. package/src/strategies/convex.ts +217 -210
  117. package/src/strategies/creditFacade.ts +70 -53
  118. package/src/strategies/curve.ts +263 -194
  119. package/src/strategies/lido.ts +33 -37
  120. package/src/strategies/uniswapV2.ts +90 -112
  121. package/src/strategies/uniswapV3.ts +114 -91
  122. package/src/strategies/yearn.ts +58 -62
  123. package/src/tokens/connectors.ts +6 -6
  124. package/src/tokens/convex.ts +297 -296
  125. package/src/tokens/curveLP.ts +170 -165
  126. package/src/tokens/gear.ts +47 -45
  127. package/src/tokens/normal.ts +801 -802
  128. package/src/tokens/token.ts +19 -10
  129. package/src/tokens/tokenData.ts +19 -9
  130. package/src/tokens/tokenType.ts +11 -11
  131. package/src/tokens/yearn.ts +126 -124
  132. package/src/utils/errors.ts +11 -0
  133. package/src/utils/formatter.ts +26 -18
  134. package/src/utils/loading.ts +14 -6
  135. package/src/utils/mappers.ts +15 -6
  136. package/src/utils/multicall.ts +6 -9
  137. package/src/utils/network.ts +21 -21
  138. package/src/utils/repeater.ts +2 -2
  139. package/src/utils/types.ts +6 -2
  140. package/src/utils/validate.ts +1 -1
  141. package/lib/core/adapters.d.ts +0 -15
  142. package/lib/core/adapters.js +0 -19
  143. package/lib/core/contracts.d.ts +0 -67
  144. package/lib/core/contracts.js +0 -254
  145. package/lib/core/contractsRegister.d.ts +0 -2
  146. package/lib/core/contractsRegister.js +0 -58
  147. package/lib/core/creditCard.d.ts +0 -13
  148. package/lib/core/creditCard.js +0 -2
  149. package/lib/core/oracles.d.ts +0 -38
  150. package/lib/core/oracles.js +0 -12
  151. package/lib/core/priceFeeds.d.ts +0 -3
  152. package/lib/core/priceFeeds.js +0 -492
  153. package/lib/core/protocols.d.ts +0 -13
  154. package/lib/core/protocols.js +0 -39
  155. package/lib/core/swap.d.ts +0 -4
  156. package/lib/core/swap.js +0 -8
  157. package/lib/core/trade.d.ts +0 -35
  158. package/lib/core/trade.js +0 -62
  159. package/lib/core/tradeTypes.d.ts +0 -79
  160. package/lib/core/tradeTypes.js +0 -21
  161. package/lib/utils/events.d.ts +0 -2
  162. package/lib/utils/events.js +0 -13
  163. package/src/utils/events.ts +0 -10
@@ -0,0 +1,250 @@
1
+ import { BigNumber, providers } from "ethers";
2
+ import axios from "axios";
3
+ import {
4
+ ConvexPoolContract,
5
+ ConvexPoolParams,
6
+ contractsByNetwork,
7
+ contractParams,
8
+ CurvePoolContract
9
+ } from "../contracts/contracts";
10
+
11
+ import { tokenDataByNetwork, supportedTokens } from "../tokens/token";
12
+ import { CurveLPToken } from "../tokens/curveLP";
13
+ import { ConvexPhantomTokenData } from "../tokens/convex";
14
+
15
+ import {
16
+ IBaseRewardPool__factory,
17
+ IBaseRewardPool,
18
+ IConvexToken__factory,
19
+ IConvexToken,
20
+ CurveV1AdapterStETH,
21
+ CurveV1AdapterStETH__factory
22
+ } from "../types";
23
+
24
+ import { multicall, MCall } from "../utils/multicall";
25
+ import { toBN } from "../utils/formatter";
26
+ import { AwaitedRes } from "../utils/types";
27
+
28
+ import {
29
+ SECONDS_PER_YEAR,
30
+ WAD,
31
+ WAD_DECIMALS_POW,
32
+ NetworkType,
33
+ PRICE_DECIMALS
34
+ } from "../core/constants";
35
+
36
+ type SupportedPools = Extract<
37
+ ConvexPoolContract,
38
+ | "CONVEX_3CRV_POOL"
39
+ | "CONVEX_FRAX3CRV_POOL"
40
+ | "CONVEX_LUSD3CRV_POOL"
41
+ | "CONVEX_GUSD_POOL"
42
+ | "CONVEX_SUSD_POOL"
43
+ >;
44
+
45
+ type SupportedConvex = Extract<
46
+ CurvePoolContract,
47
+ | "CURVE_3CRV_POOL"
48
+ | "CURVE_FRAX_POOL"
49
+ | "CURVE_LUSD_POOL"
50
+ | "CURVE_GUSD_POOL"
51
+ | "CURVE_SUSD_POOL"
52
+ >;
53
+
54
+ const curveSwapByPool: Record<SupportedPools, SupportedConvex> = {
55
+ CONVEX_3CRV_POOL: "CURVE_3CRV_POOL",
56
+ CONVEX_FRAX3CRV_POOL: "CURVE_FRAX_POOL",
57
+ CONVEX_LUSD3CRV_POOL: "CURVE_LUSD_POOL",
58
+ CONVEX_GUSD_POOL: "CURVE_GUSD_POOL",
59
+ CONVEX_SUSD_POOL: "CURVE_SUSD_POOL"
60
+ };
61
+
62
+ export async function getConvexApy(
63
+ pool: SupportedPools,
64
+ provider: providers.Provider,
65
+ networkType: NetworkType,
66
+ getTokenPrice: (tokenAddress: string) => BigNumber
67
+ ) {
68
+ const tokenList = tokenDataByNetwork[networkType];
69
+ const contractsList = contractsByNetwork[networkType];
70
+
71
+ const poolParams = contractParams[pool] as ConvexPoolParams;
72
+ const stakedTokenParams = supportedTokens[
73
+ poolParams.stakedToken
74
+ ] as ConvexPhantomTokenData;
75
+
76
+ const { underlying } = stakedTokenParams;
77
+ const basePoolAddress = contractsList[pool];
78
+ const swapPoolAddress = contractsList[curveSwapByPool[pool]];
79
+ const cvxAddress = tokenList.CVX;
80
+
81
+ const extraPoolAddresses = poolParams.extraRewards.map(
82
+ d => d.poolAddress[networkType]
83
+ );
84
+
85
+ const [basePoolRate, basePoolSupply, vPrice, cvxSupply, ...extra] =
86
+ await getPoolData(
87
+ basePoolAddress,
88
+ swapPoolAddress,
89
+ cvxAddress,
90
+ extraPoolAddresses,
91
+ provider
92
+ );
93
+
94
+ const cvxPrice = getTokenPrice(tokenList.CVX);
95
+ const crvPrice = getTokenPrice(tokenList.CRV);
96
+
97
+ const crvPerSecond = basePoolRate;
98
+ const virtualSupply = basePoolSupply.mul(vPrice).div(WAD);
99
+ const crvPerUnderlying = crvPerSecond.mul(WAD).div(virtualSupply);
100
+
101
+ const crvPerYear = crvPerUnderlying.mul(SECONDS_PER_YEAR);
102
+ const cvxPerYear = getCVXMintAmount(crvPerYear, cvxSupply);
103
+
104
+ const crvAPY = crvPerYear.mul(cvxPrice).div(PRICE_DECIMALS);
105
+ const cvxAPY = cvxPerYear.mul(crvPrice).div(PRICE_DECIMALS);
106
+
107
+ const extraAPRs = await Promise.all(
108
+ extraPoolAddresses.map(async (_, index) => {
109
+ const extraRewardSymbol = poolParams.extraRewards[index].rewardToken;
110
+ const extraPoolRate = extra[index];
111
+
112
+ const perUnderlying = extraPoolRate.mul(WAD).div(virtualSupply);
113
+ const perYear = perUnderlying.mul(SECONDS_PER_YEAR);
114
+
115
+ const extraPrise = getTokenPrice(tokenList[extraRewardSymbol]);
116
+
117
+ const extraAPY = perYear.mul(extraPrise).div(PRICE_DECIMALS);
118
+
119
+ return extraAPY;
120
+ })
121
+ );
122
+
123
+ const extraAPYTotal = extraAPRs.reduce(
124
+ (acc, apy) => acc.add(apy),
125
+ BigNumber.from(0)
126
+ );
127
+
128
+ const baseApyRAY = await getCurveBaseApy(underlying);
129
+
130
+ return baseApyRAY.add(crvAPY).add(cvxAPY).add(extraAPYTotal);
131
+ }
132
+
133
+ const CVX_MAX_SUPPLY = WAD.mul(100000000);
134
+ const CVX_REDUCTION_PER_CLIFF = BigNumber.from(100000);
135
+ const CVX_TOTAL_CLIFFS = WAD.mul(1000);
136
+
137
+ function getCVXMintAmount(crvAmount: BigNumber, cvxSupply: BigNumber) {
138
+ const currentCliff = cvxSupply.div(CVX_REDUCTION_PER_CLIFF);
139
+
140
+ if (currentCliff.lt(CVX_TOTAL_CLIFFS)) {
141
+ const remainingCliffs = CVX_TOTAL_CLIFFS.sub(currentCliff);
142
+
143
+ const mintedAmount = crvAmount.mul(remainingCliffs).div(CVX_TOTAL_CLIFFS);
144
+
145
+ const amountTillMax = CVX_MAX_SUPPLY.sub(cvxSupply);
146
+
147
+ return mintedAmount.gt(amountTillMax) ? amountTillMax : mintedAmount;
148
+ }
149
+
150
+ return BigNumber.from(0);
151
+ }
152
+
153
+ type IBaseRewardPoolInterface = IBaseRewardPool["interface"];
154
+ type IConvexTokenInterface = IConvexToken["interface"];
155
+ type CurveV1AdapterStETHInterface = CurveV1AdapterStETH["interface"];
156
+
157
+ async function getPoolData(
158
+ basePoolAddress: string,
159
+ underlying: string,
160
+ cvxAddress: string,
161
+ extraPoolAddresses: string[],
162
+ provider: providers.Provider
163
+ ) {
164
+ const calls: [
165
+ MCall<IBaseRewardPoolInterface>,
166
+ MCall<IBaseRewardPoolInterface>,
167
+ MCall<CurveV1AdapterStETHInterface>,
168
+ MCall<IConvexTokenInterface>,
169
+ ...Array<MCall<IBaseRewardPoolInterface>>
170
+ ] = [
171
+ {
172
+ address: basePoolAddress,
173
+ interface: IBaseRewardPool__factory.createInterface(),
174
+ method: "rewardRate()"
175
+ },
176
+ {
177
+ address: basePoolAddress,
178
+ interface: IBaseRewardPool__factory.createInterface(),
179
+ method: "totalSupply()"
180
+ },
181
+ {
182
+ address: underlying,
183
+ interface: CurveV1AdapterStETH__factory.createInterface(),
184
+ method: "get_virtual_price()"
185
+ },
186
+ {
187
+ address: cvxAddress,
188
+ interface: IConvexToken__factory.createInterface(),
189
+ method: "totalSupply()"
190
+ },
191
+ ...extraPoolAddresses.map(
192
+ (extraPoolAddress): MCall<IBaseRewardPoolInterface> => ({
193
+ address: extraPoolAddress,
194
+ interface: IBaseRewardPool__factory.createInterface(),
195
+ method: "rewardRate()"
196
+ })
197
+ )
198
+ ];
199
+
200
+ return multicall<
201
+ [
202
+ AwaitedRes<IBaseRewardPool["rewardRate"]>,
203
+ AwaitedRes<IBaseRewardPool["totalSupply"]>,
204
+ AwaitedRes<CurveV1AdapterStETH["get_virtual_price"]>,
205
+ AwaitedRes<IConvexToken["totalSupply"]>,
206
+ ...Array<AwaitedRes<IBaseRewardPool["rewardRate"]>>
207
+ ]
208
+ >(calls, provider);
209
+ }
210
+
211
+ interface CurveAPRData {
212
+ baseApy: number;
213
+ crvApy: number;
214
+ crvBoost: number;
215
+ crvPrice: number;
216
+ }
217
+
218
+ interface APYResponse {
219
+ apys: Record<string, CurveAPRData>;
220
+ }
221
+
222
+ const curveLPTokenToPoolName: Record<CurveLPToken, string> = {
223
+ "3Crv": "3pool",
224
+ FRAX3CRV: "frax",
225
+ gusd3CRV: "gusd",
226
+ LUSD3CRV: "lusd",
227
+ crvPlain3andSUSD: "susdv2",
228
+ steCRV: "steth"
229
+ };
230
+
231
+ const RESPONSE_DECIMALS = 100;
232
+
233
+ // https://www.convexfinance.com/api/curve-apys
234
+
235
+ export async function getCurveBaseApy(
236
+ curveLPToken: CurveLPToken
237
+ ): Promise<BigNumber> {
238
+ const poolName = curveLPTokenToPoolName[curveLPToken];
239
+
240
+ try {
241
+ const url = "https://www.convexfinance.com/api/curve-apys";
242
+ const result = await axios.get<APYResponse>(url);
243
+
244
+ const { baseApy = 0 } = result.data.apys[poolName] || {};
245
+
246
+ return toBN((baseApy / RESPONSE_DECIMALS).toString(), WAD_DECIMALS_POW);
247
+ } catch (e) {
248
+ return BigNumber.from(0);
249
+ }
250
+ }
@@ -0,0 +1,89 @@
1
+ import { providers } from "ethers";
2
+
3
+ import { multicall, MCall } from "../utils/multicall";
4
+ import { contractParams, LidoParams } from "../contracts/contracts";
5
+ import { tokenDataByNetwork } from "../tokens/token";
6
+
7
+ import { WAD, SECONDS_PER_YEAR, NetworkType } from "../core/constants";
8
+
9
+ import {
10
+ ILidoOracle__factory,
11
+ ILidoOracle,
12
+ IstETH__factory,
13
+ IstETH
14
+ } from "../types";
15
+
16
+ type ILidoOracleInterface = ILidoOracle["interface"];
17
+
18
+ type IstETHInterface = IstETH["interface"];
19
+
20
+ const lidoOracles = (contractParams.LIDO_STETH_GATEWAY as LidoParams).oracle;
21
+
22
+ const lidoStEth: Record<NetworkType, string> = {
23
+ Mainnet: tokenDataByNetwork.Mainnet.STETH,
24
+ Kovan: tokenDataByNetwork.Kovan.STETH
25
+ };
26
+
27
+ export async function getLidoApy(
28
+ provider: providers.Provider,
29
+ networkType: NetworkType
30
+ ) {
31
+ if (!lidoOracles[networkType]) {
32
+ throw new Error(
33
+ `No Lido APR oracle found on current network: ${networkType}`
34
+ );
35
+ }
36
+ if (!lidoStEth[networkType]) {
37
+ throw new Error(`No Lido stETH found on current network: ${networkType}`);
38
+ }
39
+
40
+ const [{ postTotalPooledEther, preTotalPooledEther, timeElapsed }, fee] =
41
+ await geLidoData(
42
+ lidoOracles[networkType],
43
+ lidoStEth[networkType],
44
+ provider,
45
+ networkType
46
+ );
47
+
48
+ const lidoAPRRay = postTotalPooledEther
49
+ .sub(preTotalPooledEther)
50
+ .mul(SECONDS_PER_YEAR)
51
+ .mul(WAD)
52
+ .div(preTotalPooledEther.mul(timeElapsed));
53
+
54
+ return [lidoAPRRay, fee] as const;
55
+ }
56
+
57
+ export const LIDO_FEE_DECIMALS = 10000;
58
+
59
+ async function geLidoData(
60
+ lidoOracleAddress: string,
61
+ stETHAddress: string,
62
+ provider: providers.Provider,
63
+ network: NetworkType
64
+ ) {
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({
76
+ address: stETHAddress,
77
+ interface: IstETH__factory.createInterface(),
78
+ method: "getFee()"
79
+ });
80
+
81
+ const [stats, fee = Math.floor(LIDO_FEE_DECIMALS / 10)] = await multicall<
82
+ [
83
+ Awaited<ReturnType<ILidoOracle["getLastCompletedReportDelta"]>>,
84
+ Awaited<ReturnType<IstETH["getFee"]>>
85
+ ]
86
+ >(calls, provider);
87
+
88
+ return [stats, fee] as const;
89
+ }
package/src/config.ts CHANGED
@@ -1 +1,2 @@
1
- export const STATIC_TOKEN = "https://static.gearbox.fi/tokens/"
1
+ export const STATIC_TOKEN = "https://static.gearbox.fi/tokens/";
2
+ export const MULTICALL_ADDRESS = "0x5ba1e12693dc8f9c48aad8770482f4739beed696";
@@ -3,14 +3,19 @@
3
3
  * Gearbox. Generalized leverage protocol, which allows to take leverage and then use it across other DeFi protocols and platforms in a composable way.
4
4
  * (c) Gearbox.fi, 2021
5
5
  */
6
- import { keyToLowercase, objectEntries, swapKeyValue } from "../utils/mappers";
6
+ import {
7
+ keyToLowercase,
8
+ objectEntries,
9
+ swapKeyValue,
10
+ filterEmptyKeys
11
+ } from "../utils/mappers";
7
12
  import { AdapterInterface } from "./adapters";
8
13
  import { NetworkType } from "../core/constants";
9
14
  import { Protocols } from "./protocols";
10
15
  import { tokenDataByNetwork } from "../tokens/token";
11
- import { ConvexStakedPhantomToken } from "../tokens/convex";
12
- import { CurveLPToken } from "../tokens/curveLP";
13
- import { NormalToken } from "../tokens/normal";
16
+ import type { ConvexStakedPhantomToken } from "../tokens/convex";
17
+ import type { CurveLPToken } from "../tokens/curveLP";
18
+ import type { NormalToken } from "../tokens/normal";
14
19
 
15
20
  export type UniswapV2Contract = "UNISWAP_V2_ROUTER" | "SUSHISWAP_ROUTER";
16
21
 
@@ -179,10 +184,16 @@ type ConvexParams = {
179
184
  | AdapterInterface.CONVEX_V1_CLAIM_ZAP;
180
185
  } & BaseContractParams;
181
186
 
182
- type ConvexPoolParams = {
187
+ type ConvexExtraPoolParams = {
188
+ rewardToken: NormalToken;
189
+ poolAddress: Record<NetworkType, string>;
190
+ };
191
+
192
+ export type ConvexPoolParams = {
183
193
  protocol: Protocols.Convex;
184
194
  type: AdapterInterface.CONVEX_V1_BASE_REWARD_POOL;
185
195
  stakedToken: ConvexStakedPhantomToken;
196
+ extraRewards: Array<ConvexExtraPoolParams>;
186
197
  } & BaseContractParams;
187
198
 
188
199
  export type LidoParams = {
@@ -314,46 +325,85 @@ export const contractParams: Record<SupportedContract, ContractParams> = {
314
325
  protocol: Protocols.Convex,
315
326
  type: AdapterInterface.CONVEX_V1_BOOSTER
316
327
  },
328
+ CONVEX_CLAIM_ZAP: {
329
+ name: "Convex ZAP",
330
+ protocol: Protocols.Convex,
331
+ type: AdapterInterface.CONVEX_V1_CLAIM_ZAP
332
+ },
333
+
317
334
  CONVEX_3CRV_POOL: {
318
335
  name: "Convex 3crv",
319
336
  protocol: Protocols.Convex,
320
337
  type: AdapterInterface.CONVEX_V1_BASE_REWARD_POOL,
321
- stakedToken: "stkcvx3Crv"
338
+ stakedToken: "stkcvx3Crv",
339
+ extraRewards: []
322
340
  },
323
341
  CONVEX_GUSD_POOL: {
324
342
  name: "Convex GUSD",
325
343
  protocol: Protocols.Convex,
326
344
  type: AdapterInterface.CONVEX_V1_BASE_REWARD_POOL,
327
- stakedToken: "stkcvxgusd3CRV"
345
+ stakedToken: "stkcvxgusd3CRV",
346
+ extraRewards: []
328
347
  },
329
348
  CONVEX_SUSD_POOL: {
330
349
  name: "Convex SUSD",
331
350
  protocol: Protocols.Convex,
332
351
  type: AdapterInterface.CONVEX_V1_BASE_REWARD_POOL,
333
- stakedToken: "stkcvxcrvPlain3andSUSD"
352
+ stakedToken: "stkcvxcrvPlain3andSUSD",
353
+ extraRewards: [
354
+ {
355
+ rewardToken: "SNX",
356
+ poolAddress: {
357
+ Mainnet: "0x81fCe3E10D12Da6c7266a1A169c4C96813435263",
358
+ Kovan: "0x26a535146557FA58FA37e3078FEAc523b554939C"
359
+ }
360
+ }
361
+ ]
334
362
  },
335
363
  CONVEX_STECRV_POOL: {
336
364
  name: "Convex STECRV",
337
365
  protocol: Protocols.Convex,
338
366
  type: AdapterInterface.CONVEX_V1_BASE_REWARD_POOL,
339
- stakedToken: "stkcvxsteCRV"
367
+ stakedToken: "stkcvxsteCRV",
368
+ extraRewards: [
369
+ {
370
+ rewardToken: "LDO",
371
+ poolAddress: {
372
+ Mainnet: "0x008aEa5036b819B4FEAEd10b2190FBb3954981E8",
373
+ Kovan: "0xd0B1CC3B4839363b1eC92F35eF45794CB07B1183"
374
+ }
375
+ }
376
+ ]
340
377
  },
341
378
  CONVEX_FRAX3CRV_POOL: {
342
379
  name: "Convex FRAX3CRV",
343
380
  protocol: Protocols.Convex,
344
381
  type: AdapterInterface.CONVEX_V1_BASE_REWARD_POOL,
345
- stakedToken: "stkcvxFRAX3CRV"
382
+ stakedToken: "stkcvxFRAX3CRV",
383
+ extraRewards: [
384
+ {
385
+ rewardToken: "FXS",
386
+ poolAddress: {
387
+ Mainnet: "0xcDEC6714eB482f28f4889A0c122868450CDBF0b0",
388
+ Kovan: "0x89869c2e79FC6EFf51e714F1239D53702B5CDFCD"
389
+ }
390
+ }
391
+ ]
346
392
  },
347
393
  CONVEX_LUSD3CRV_POOL: {
348
394
  name: "Convex LUSD3CRV",
349
395
  protocol: Protocols.Convex,
350
396
  type: AdapterInterface.CONVEX_V1_BASE_REWARD_POOL,
351
- stakedToken: "stkcvxLUSD3CRV"
352
- },
353
- CONVEX_CLAIM_ZAP: {
354
- name: "Convex ZAP",
355
- protocol: Protocols.Convex,
356
- type: AdapterInterface.CONVEX_V1_CLAIM_ZAP
397
+ stakedToken: "stkcvxLUSD3CRV",
398
+ extraRewards: [
399
+ {
400
+ rewardToken: "LQTY",
401
+ poolAddress: {
402
+ Mainnet: "0x55d59b791f06dc519B176791c4E037E8Cf2f6361",
403
+ Kovan: ""
404
+ }
405
+ }
406
+ ]
357
407
  },
358
408
 
359
409
  LIDO_STETH_GATEWAY: {
@@ -370,6 +420,10 @@ export const contractParams: Record<SupportedContract, ContractParams> = {
370
420
 
371
421
  export const contractsByAddress = objectEntries(contractsByNetwork).reduce<
372
422
  Record<string, SupportedContract>
373
- >((sum, [_, contracts]) => {
374
- return { ...sum, ...keyToLowercase(swapKeyValue(contracts)) };
375
- }, {});
423
+ >(
424
+ (acc, [, contracts]) => ({
425
+ ...acc,
426
+ ...filterEmptyKeys(keyToLowercase(swapKeyValue(contracts)))
427
+ }),
428
+ {}
429
+ );
@@ -27,19 +27,34 @@ export const deployedContracts: Record<string, string> = {
27
27
  "0xe04b4db67127d1930D36f16B51653120C4285708": "WBTC",
28
28
  "0x600073357c29d169aAF3E543A4519749830553F1": "WETH",
29
29
  "0xdBAd1361d9A03B81Be8D3a54Ef0dc9e39a1bA5b3": "USDC",
30
- "0x50d1fA47b0D88BA0D108148B8481b4A762eFB99e": "DAI"
30
+ "0x50d1fA47b0D88BA0D108148B8481b4A762eFB99e": "DAI",
31
31
  // [YEARN_DAI_VAULT_KOVAN_MOCK]: "Yearn DAI",
32
32
  // [YEARN_USDC_VAULT_KOVAN_MOCK]: "Yearn USDC",
33
33
  // [SUSHISWAP_KOVAN]: "Sushiswap"
34
+
35
+ "0x94cd5F09727ae04d7D6fd36A9c9DD96D0d54646B": "DAI",
36
+ "0x53B4a7389EA369a9299DfF524f916EC3cB77ffF4": "USDC",
37
+ "0xE6631f7b18744651A385a02ea2C89634d20D7819": "WETH",
38
+ "0x4d2cBA0E43Ad3B3E1C3B1922fe6E8e910b8C3ae0": "WBTC",
39
+
40
+ "0x6Ae9Ed829AF469Df9526FA7443E876bfaBC79eff": "DAI V2",
41
+ "0x8E0a874E3475de1C16490E386b7E2904CdC03086": "USDC V2",
42
+ "0x816a74B75D60839247C848518545fb17cedDC460": "WETH V2",
43
+
44
+ // pools
45
+ "0xA7b1C8f322596C40A04dBd3DffaE37a0849B8b59": "DAI",
46
+ "0xb8ecDB926F07FCbd870eafE72d116413A0BEb236": "USDC",
47
+ "0xAda6b2747295b2ba6ba52ce2d0D5e681D25D63D8": "WETH",
48
+ "0x85c54CCCf27466eEa1C74a73F75CbE385C271EE4": "WBTC"
34
49
  };
35
50
 
36
51
  const contractNames = Object.entries(contractsByAddress).reduce<
37
52
  Record<string, string>
38
- >((sum, [addr, cSymbol]) => {
53
+ >((acc, [addr, cSymbol]) => {
39
54
  const params = contractParams[cSymbol];
40
- if (!params) return sum;
55
+ if (!params) return acc;
41
56
 
42
- return { ...sum, [addr]: params.name };
57
+ return { ...acc, [addr]: params.name };
43
58
  }, {});
44
59
 
45
60
  const contractsFullList = {
@@ -22,12 +22,18 @@ export const getNetworkType = (chainId: number): NetworkType => {
22
22
  }
23
23
  };
24
24
 
25
- export const RAY = BigNumber.from(10).pow(27);
25
+ export const RAY_DECIMALS_POW = 27;
26
+ export const RAY = BigNumber.from(10).pow(RAY_DECIMALS_POW);
26
27
  export const halfRAY = RAY.div(2);
27
- export const WAD = BigNumber.from(10).pow(18);
28
+ export const WAD_DECIMALS_POW = 18;
29
+ export const WAD = BigNumber.from(10).pow(WAD_DECIMALS_POW);
30
+
31
+ export const PRICE_DECIMALS_POW = 8;
32
+ export const PRICE_DECIMALS = BigNumber.from(10).pow(PRICE_DECIMALS_POW);
28
33
 
29
34
  export const SECONDS_PER_YEAR = 365 * 24 * 3600;
30
35
 
36
+ export const PERCENTAGE_DECIMALS = 100;
31
37
  export const PERCENTAGE_FACTOR = 1e4;
32
38
  export const LIQUIDATION_DISCOUNTED_SUM = 9500;
33
39
  export const UNDERLYING_TOKEN_LIQUIDATION_THRESHOLD = 9300;
@@ -37,8 +43,9 @@ export const timeRanges: Record<string, number> = {
37
43
  "1D": 3600 * 24,
38
44
  "1W": 3600 * 24 * 7,
39
45
  "1M": 3600 * 24 * 30,
40
- "1Y": 3600 * 24 * 365,
46
+ "1Y": 3600 * 24 * 365
41
47
  };
42
48
 
43
49
  export const LEVERAGE_DECIMALS = 100;
44
- export const ADDRESS_0x0 = "0x0000000000000000000000000000000000000000";
50
+ export const SLIPPAGE_DECIMALS = 100;
51
+ export const ADDRESS_0X0 = "0x0000000000000000000000000000000000000000";