@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
@@ -1,233 +1,408 @@
1
1
  import { BigNumberish } from "ethers";
2
+ import {
3
+ contractParams,
4
+ contractsByNetwork,
5
+ ConvexPoolContract,
6
+ ConvexPoolParams
7
+ } from "../contracts/contracts";
8
+ import { NetworkType } from "../core/constants";
9
+ import { CreditManagerData } from "../core/creditManager";
10
+ import { ConvexPhantomTokenData } from "../tokens/convex";
11
+
12
+ import { supportedTokens, tokenDataByNetwork } from "../tokens/token";
13
+ import { CurveLPTokenData } from "../tokens/curveLP";
2
14
 
3
15
  import {
4
- ConvexV1BoosterAdapter__factory,
5
- ConvexV1BaseRewardPoolAdapter__factory,
6
- ConvexV1ClaimZapAdapter__factory
7
- } from "../types"
16
+ ConvexV1BoosterAdapter__factory,
17
+ ConvexV1BaseRewardPoolAdapter__factory,
18
+ ConvexV1ClaimZapAdapter__factory
19
+ } from "../types";
8
20
 
9
21
  import { MultiCallStruct } from "../types/contracts/interfaces/ICreditFacade.sol/ICreditFacade";
22
+ import { CurveStrategies } from "./curve";
23
+ import { UniswapV2Multicaller } from "./uniswapV2";
10
24
 
11
25
  export class ConvexBoosterCalls {
12
- public static deposit(pid: BigNumberish, amount: BigNumberish, stake: boolean) {
13
- return ConvexV1BoosterAdapter__factory.createInterface().encodeFunctionData(
14
- "deposit",
15
- [pid, amount, stake]
16
- );
17
- }
26
+ public static deposit(
27
+ pid: BigNumberish,
28
+ amount: BigNumberish,
29
+ stake: boolean
30
+ ) {
31
+ return ConvexV1BoosterAdapter__factory.createInterface().encodeFunctionData(
32
+ "deposit",
33
+ [pid, amount, stake]
34
+ );
35
+ }
18
36
 
19
- public static depositAll(pid: BigNumberish, stake: boolean) {
20
- return ConvexV1BoosterAdapter__factory.createInterface().encodeFunctionData(
21
- "depositAll",
22
- [pid, stake]
23
- );
24
- }
37
+ public static depositAll(pid: BigNumberish, stake: boolean) {
38
+ return ConvexV1BoosterAdapter__factory.createInterface().encodeFunctionData(
39
+ "depositAll",
40
+ [pid, stake]
41
+ );
42
+ }
25
43
 
26
- public static withdraw(pid: BigNumberish, amount: BigNumberish) {
27
- return ConvexV1BoosterAdapter__factory.createInterface().encodeFunctionData(
28
- "withdraw",
29
- [pid, amount]
30
- );
31
- }
44
+ public static withdraw(pid: BigNumberish, amount: BigNumberish) {
45
+ return ConvexV1BoosterAdapter__factory.createInterface().encodeFunctionData(
46
+ "withdraw",
47
+ [pid, amount]
48
+ );
49
+ }
32
50
 
33
- public static withdrawAll(pid: BigNumberish) {
34
- return ConvexV1BoosterAdapter__factory.createInterface().encodeFunctionData(
35
- "withdrawAll",
36
- [pid]
37
- );
38
- }
51
+ public static withdrawAll(pid: BigNumberish) {
52
+ return ConvexV1BoosterAdapter__factory.createInterface().encodeFunctionData(
53
+ "withdrawAll",
54
+ [pid]
55
+ );
56
+ }
39
57
  }
40
58
 
41
59
  export class ConvexPoolCalls {
42
- public static stake(amount: BigNumberish) {
43
- return ConvexV1BaseRewardPoolAdapter__factory.createInterface().encodeFunctionData(
44
- "stake",
45
- [amount]
46
- );
47
- }
60
+ public static stake(amount: BigNumberish) {
61
+ return ConvexV1BaseRewardPoolAdapter__factory.createInterface().encodeFunctionData(
62
+ "stake",
63
+ [amount]
64
+ );
65
+ }
48
66
 
49
- public static stakeAll() {
50
- return ConvexV1BaseRewardPoolAdapter__factory.createInterface().encodeFunctionData(
51
- "stakeAll"
52
- );
53
- }
67
+ public static stakeAll() {
68
+ return ConvexV1BaseRewardPoolAdapter__factory.createInterface().encodeFunctionData(
69
+ "stakeAll"
70
+ );
71
+ }
54
72
 
55
- public static withdraw(amount: BigNumberish, claim: boolean) {
56
- return ConvexV1BaseRewardPoolAdapter__factory.createInterface().encodeFunctionData(
57
- "withdraw",
58
- [amount, claim]
59
- );
60
- }
73
+ public static withdraw(amount: BigNumberish, claim: boolean) {
74
+ return ConvexV1BaseRewardPoolAdapter__factory.createInterface().encodeFunctionData(
75
+ "withdraw",
76
+ [amount, claim]
77
+ );
78
+ }
61
79
 
62
- public static withdrawAll(claim: boolean) {
63
- return ConvexV1BaseRewardPoolAdapter__factory.createInterface().encodeFunctionData(
64
- "withdrawAll",
65
- [claim]
66
- );
67
- }
80
+ public static withdrawAll(claim: boolean) {
81
+ return ConvexV1BaseRewardPoolAdapter__factory.createInterface().encodeFunctionData(
82
+ "withdrawAll",
83
+ [claim]
84
+ );
85
+ }
68
86
 
69
- public static withdrawAndUnwrap(amount: BigNumberish, claim: boolean) {
70
- return ConvexV1BaseRewardPoolAdapter__factory.createInterface().encodeFunctionData(
71
- "withdrawAndUnwrap",
72
- [amount, claim]
73
- );
74
- }
87
+ public static withdrawAndUnwrap(amount: BigNumberish, claim: boolean) {
88
+ return ConvexV1BaseRewardPoolAdapter__factory.createInterface().encodeFunctionData(
89
+ "withdrawAndUnwrap",
90
+ [amount, claim]
91
+ );
92
+ }
75
93
 
76
- public static withdrawAllAndUnwrap(claim: boolean) {
77
- return ConvexV1BaseRewardPoolAdapter__factory.createInterface().encodeFunctionData(
78
- "withdrawAllAndUnwrap",
79
- [claim]
80
- );
81
- }
94
+ public static withdrawAllAndUnwrap(claim: boolean) {
95
+ return ConvexV1BaseRewardPoolAdapter__factory.createInterface().encodeFunctionData(
96
+ "withdrawAllAndUnwrap",
97
+ [claim]
98
+ );
99
+ }
82
100
  }
83
101
 
84
-
85
102
  export class ConvexClaimZapCalls {
86
- public static claimRewards(
87
- rewardContracts: Array<string>,
88
- extraRewardContracts: Array<string>,
89
- tokenRewardContracts: Array<string>,
90
- tokenRewardTokens: Array<string>,
91
- depositCrvMaxAmount: BigNumberish,
92
- minAmountOut: BigNumberish,
93
- depositCvxMaxAmount: BigNumberish,
94
- spendCvxAmount: BigNumberish,
95
- options: BigNumberish
96
- ) {
97
- return ConvexV1ClaimZapAdapter__factory.createInterface().encodeFunctionData(
98
- "claimRewards",
99
- [
100
- rewardContracts,
101
- extraRewardContracts,
102
- tokenRewardContracts,
103
- tokenRewardTokens,
104
- depositCrvMaxAmount,
105
- minAmountOut,
106
- depositCvxMaxAmount,
107
- spendCvxAmount,
108
- options
109
- ]
110
- );
111
- }
103
+ public static claimRewards(
104
+ rewardContracts: Array<string>,
105
+ extraRewardContracts: Array<string>,
106
+ tokenRewardContracts: Array<string>,
107
+ tokenRewardTokens: Array<string>,
108
+ depositCrvMaxAmount: BigNumberish,
109
+ minAmountOut: BigNumberish,
110
+ depositCvxMaxAmount: BigNumberish,
111
+ spendCvxAmount: BigNumberish,
112
+ options: BigNumberish
113
+ ) {
114
+ return ConvexV1ClaimZapAdapter__factory.createInterface().encodeFunctionData(
115
+ "claimRewards",
116
+ [
117
+ rewardContracts,
118
+ extraRewardContracts,
119
+ tokenRewardContracts,
120
+ tokenRewardTokens,
121
+ depositCrvMaxAmount,
122
+ minAmountOut,
123
+ depositCvxMaxAmount,
124
+ spendCvxAmount,
125
+ options
126
+ ]
127
+ );
128
+ }
112
129
  }
113
130
 
114
131
  export class ConvexBoosterMulticaller {
115
- private readonly _address: string;
132
+ private readonly _address: string;
116
133
 
117
- constructor(address: string) {
118
- this._address = address;
119
- }
134
+ constructor(address: string) {
135
+ this._address = address;
136
+ }
120
137
 
121
- deposit(pid: BigNumberish, amount: BigNumberish, stake: boolean): MultiCallStruct {
122
- return {
123
- target: this._address,
124
- callData: ConvexBoosterCalls.deposit(pid, amount, stake)
125
- }
126
- }
138
+ static connect(address: string) {
139
+ return new ConvexBoosterMulticaller(address);
140
+ }
127
141
 
128
- depositAll(pid: BigNumberish, stake: boolean): MultiCallStruct {
129
- return {
130
- target: this._address,
131
- callData: ConvexBoosterCalls.depositAll(pid, stake)
132
- }
133
- }
142
+ deposit(
143
+ pid: BigNumberish,
144
+ amount: BigNumberish,
145
+ stake: boolean
146
+ ): MultiCallStruct {
147
+ return {
148
+ target: this._address,
149
+ callData: ConvexBoosterCalls.deposit(pid, amount, stake)
150
+ };
151
+ }
134
152
 
135
- withdraw(pid: BigNumberish, amount: BigNumberish): MultiCallStruct {
136
- return {
137
- target: this._address,
138
- callData: ConvexBoosterCalls.withdraw(pid, amount)
139
- }
140
- }
153
+ depositAll(pid: BigNumberish, stake: boolean): MultiCallStruct {
154
+ return {
155
+ target: this._address,
156
+ callData: ConvexBoosterCalls.depositAll(pid, stake)
157
+ };
158
+ }
141
159
 
142
- withdrawAll(pid: BigNumberish): MultiCallStruct {
143
- return {
144
- target: this._address,
145
- callData: ConvexBoosterCalls.withdrawAll(pid)
146
- }
147
- }
160
+ withdraw(pid: BigNumberish, amount: BigNumberish): MultiCallStruct {
161
+ return {
162
+ target: this._address,
163
+ callData: ConvexBoosterCalls.withdraw(pid, amount)
164
+ };
165
+ }
166
+
167
+ withdrawAll(pid: BigNumberish): MultiCallStruct {
168
+ return {
169
+ target: this._address,
170
+ callData: ConvexBoosterCalls.withdrawAll(pid)
171
+ };
172
+ }
148
173
  }
149
174
 
150
175
  export class ConvexPoolMulticaller {
151
- private readonly _address: string;
176
+ private readonly _address: string;
152
177
 
153
- constructor(address: string) {
154
- this._address = address;
155
- }
178
+ constructor(address: string) {
179
+ this._address = address;
180
+ }
156
181
 
157
- stake(amount: BigNumberish): MultiCallStruct {
158
- return {
159
- target: this._address,
160
- callData: ConvexPoolCalls.stake(amount)
161
- }
162
- }
182
+ static connect(address: string) {
183
+ return new ConvexPoolMulticaller(address);
184
+ }
163
185
 
164
- stakeAll(): MultiCallStruct {
165
- return {
166
- target: this._address,
167
- callData: ConvexPoolCalls.stakeAll()
168
- }
169
- }
186
+ stake(amount: BigNumberish): MultiCallStruct {
187
+ return {
188
+ target: this._address,
189
+ callData: ConvexPoolCalls.stake(amount)
190
+ };
191
+ }
170
192
 
171
- withdraw(amount: BigNumberish, claim: boolean): MultiCallStruct {
172
- return {
173
- target: this._address,
174
- callData: ConvexPoolCalls.withdraw(amount, claim)
175
- }
176
- }
193
+ stakeAll(): MultiCallStruct {
194
+ return {
195
+ target: this._address,
196
+ callData: ConvexPoolCalls.stakeAll()
197
+ };
198
+ }
177
199
 
178
- withdrawAll(claim: boolean): MultiCallStruct {
179
- return {
180
- target: this._address,
181
- callData: ConvexPoolCalls.withdrawAll(claim)
182
- }
183
- }
200
+ withdraw(amount: BigNumberish, claim: boolean): MultiCallStruct {
201
+ return {
202
+ target: this._address,
203
+ callData: ConvexPoolCalls.withdraw(amount, claim)
204
+ };
205
+ }
184
206
 
185
- withdrawAndUnwrap(amount: BigNumberish, claim: boolean): MultiCallStruct {
186
- return {
187
- target: this._address,
188
- callData: ConvexPoolCalls.withdrawAndUnwrap(amount, claim)
189
- }
190
- }
207
+ withdrawAll(claim: boolean): MultiCallStruct {
208
+ return {
209
+ target: this._address,
210
+ callData: ConvexPoolCalls.withdrawAll(claim)
211
+ };
212
+ }
191
213
 
192
- withdrawAllAndUnwrap(claim: boolean) {
193
- return {
194
- target: this._address,
195
- callData: ConvexPoolCalls.withdrawAllAndUnwrap(claim)
196
- }
197
- }
214
+ withdrawAndUnwrap(amount: BigNumberish, claim: boolean): MultiCallStruct {
215
+ return {
216
+ target: this._address,
217
+ callData: ConvexPoolCalls.withdrawAndUnwrap(amount, claim)
218
+ };
219
+ }
220
+
221
+ withdrawAllAndUnwrap(claim: boolean) {
222
+ return {
223
+ target: this._address,
224
+ callData: ConvexPoolCalls.withdrawAllAndUnwrap(claim)
225
+ };
226
+ }
198
227
  }
199
228
 
200
229
  export class ConvexClaimZapMulticaller {
201
- private readonly _address: string;
230
+ private readonly _address: string;
231
+
232
+ constructor(address: string) {
233
+ this._address = address;
234
+ }
235
+
236
+ static connect(address: string) {
237
+ return new ConvexClaimZapMulticaller(address);
238
+ }
239
+
240
+ claimRewards(
241
+ rewardContracts: Array<string>,
242
+ extraRewardContracts: Array<string>,
243
+ tokenRewardContracts: Array<string>,
244
+ tokenRewardTokens: Array<string>,
245
+ depositCrvMaxAmount: BigNumberish,
246
+ minAmountOut: BigNumberish,
247
+ depositCvxMaxAmount: BigNumberish,
248
+ spendCvxAmount: BigNumberish,
249
+ options: BigNumberish
250
+ ): MultiCallStruct {
251
+ return {
252
+ target: this._address,
253
+ callData: ConvexClaimZapCalls.claimRewards(
254
+ rewardContracts,
255
+ extraRewardContracts,
256
+ tokenRewardContracts,
257
+ tokenRewardTokens,
258
+ depositCrvMaxAmount,
259
+ minAmountOut,
260
+ depositCvxMaxAmount,
261
+ spendCvxAmount,
262
+ options
263
+ )
264
+ };
265
+ }
266
+ }
267
+
268
+ export class ConvexStrategies {
269
+ static underlyingToStakedConvex(
270
+ data: CreditManagerData,
271
+ network: NetworkType,
272
+ convexPool: ConvexPoolContract,
273
+ underlyingAmount: BigNumberish
274
+ ) {
275
+ let calls: Array<MultiCallStruct> = [];
276
+ const convexParams = contractParams[convexPool] as ConvexPoolParams;
277
+ const { stakedToken } = convexParams;
278
+ const stakedTokenParams = supportedTokens[
279
+ stakedToken
280
+ ] as ConvexPhantomTokenData;
281
+ const curveLpToken = stakedTokenParams.underlying;
282
+ const curveLpTokenData = supportedTokens[curveLpToken] as CurveLPTokenData;
283
+ const curvePool = curveLpTokenData.pool;
284
+
285
+ calls = CurveStrategies.underlyingToCurveLP(
286
+ data,
287
+ network,
288
+ curvePool,
289
+ underlyingAmount
290
+ );
291
+
292
+ calls.push(
293
+ ConvexBoosterMulticaller.connect(
294
+ data.adapters[contractsByNetwork[network].CONVEX_BOOSTER]
295
+ ).depositAll(stakedTokenParams.pid, true)
296
+ );
297
+
298
+ return calls;
299
+ }
202
300
 
203
- constructor(address: string) {
204
- this._address = address;
301
+ static stakedConvexToUnderlying(
302
+ data: CreditManagerData,
303
+ network: NetworkType,
304
+ convexPool: ConvexPoolContract,
305
+ convexLpAmount: BigNumberish,
306
+ sellRewards: boolean
307
+ ) {
308
+ const calls: Array<MultiCallStruct> = [];
309
+ const convexParams = contractParams[convexPool] as ConvexPoolParams;
310
+ const { stakedToken } = convexParams;
311
+ const stakedTokenParams = supportedTokens[
312
+ stakedToken
313
+ ] as ConvexPhantomTokenData;
314
+ const curveLpToken = stakedTokenParams.underlying;
315
+ const curveLpTokenData = supportedTokens[curveLpToken] as CurveLPTokenData;
316
+ const curvePool = curveLpTokenData.pool;
317
+
318
+ calls.push(
319
+ ConvexPoolMulticaller.connect(
320
+ data.adapters[contractsByNetwork[network][convexPool]]
321
+ ).withdrawAndUnwrap(convexLpAmount, true)
322
+ );
323
+
324
+ calls.push(
325
+ ...CurveStrategies.allCurveLPToUnderlying(data, network, curvePool)
326
+ );
327
+
328
+ if (sellRewards) {
329
+ calls.push(...ConvexStrategies.sellRewards(data, network, convexPool));
205
330
  }
206
331
 
207
- claimRewards(
208
- rewardContracts: Array<string>,
209
- extraRewardContracts: Array<string>,
210
- tokenRewardContracts: Array<string>,
211
- tokenRewardTokens: Array<string>,
212
- depositCrvMaxAmount: BigNumberish,
213
- minAmountOut: BigNumberish,
214
- depositCvxMaxAmount: BigNumberish,
215
- spendCvxAmount: BigNumberish,
216
- options: BigNumberish
217
- ): MultiCallStruct {
218
- return {
219
- target: this._address,
220
- callData: ConvexClaimZapCalls.claimRewards(
221
- rewardContracts,
222
- extraRewardContracts,
223
- tokenRewardContracts,
224
- tokenRewardTokens,
225
- depositCrvMaxAmount,
226
- minAmountOut,
227
- depositCvxMaxAmount,
228
- spendCvxAmount,
229
- options
230
- )
231
- }
332
+ return calls;
333
+ }
334
+
335
+ static allStakedConvexToUnderlying(
336
+ data: CreditManagerData,
337
+ network: NetworkType,
338
+ convexPool: ConvexPoolContract,
339
+ sellRewards: boolean
340
+ ) {
341
+ const calls: Array<MultiCallStruct> = [];
342
+ const convexParams = contractParams[convexPool] as ConvexPoolParams;
343
+ const { stakedToken } = convexParams;
344
+ const stakedTokenParams = supportedTokens[
345
+ stakedToken
346
+ ] as ConvexPhantomTokenData;
347
+ const curveLpToken = stakedTokenParams.underlying;
348
+ const curveLpTokenData = supportedTokens[curveLpToken] as CurveLPTokenData;
349
+ const curvePool = curveLpTokenData.pool;
350
+
351
+ calls.push(
352
+ ConvexPoolMulticaller.connect(
353
+ data.adapters[contractsByNetwork[network][convexPool]]
354
+ ).withdrawAllAndUnwrap(true)
355
+ );
356
+
357
+ calls.push(
358
+ ...CurveStrategies.allCurveLPToUnderlying(data, network, curvePool)
359
+ );
360
+
361
+ if (sellRewards) {
362
+ calls.push(...ConvexStrategies.sellRewards(data, network, convexPool));
232
363
  }
364
+
365
+ return calls;
366
+ }
367
+
368
+ static sellRewards(
369
+ data: CreditManagerData,
370
+ network: NetworkType,
371
+ convexPool: ConvexPoolContract
372
+ ) {
373
+ const calls: Array<MultiCallStruct> = [];
374
+ const convexParams = contractParams[convexPool] as ConvexPoolParams;
375
+
376
+ calls.push(
377
+ UniswapV2Multicaller.connect(
378
+ data.adapters[contractsByNetwork[network].UNISWAP_V2_ROUTER]
379
+ ).swapAllTokensForTokens(
380
+ 0,
381
+ [tokenDataByNetwork[network].CRV, data.underlyingToken],
382
+ Math.floor(new Date().getTime() / 1000) + 3600
383
+ ),
384
+ UniswapV2Multicaller.connect(
385
+ data.adapters[contractsByNetwork[network].UNISWAP_V2_ROUTER]
386
+ ).swapAllTokensForTokens(
387
+ 0,
388
+ [tokenDataByNetwork[network].CVX, data.underlyingToken],
389
+ Math.floor(new Date().getTime() / 1000) + 3600
390
+ )
391
+ );
392
+
393
+ convexParams.extraRewards.forEach(extraReward => {
394
+ UniswapV2Multicaller.connect(
395
+ data.adapters[contractsByNetwork[network].UNISWAP_V2_ROUTER]
396
+ ).swapAllTokensForTokens(
397
+ 0,
398
+ [
399
+ tokenDataByNetwork[network][extraReward.rewardToken],
400
+ data.underlyingToken
401
+ ],
402
+ Math.floor(new Date().getTime() / 1000) + 3600
403
+ );
404
+ });
405
+
406
+ return calls;
407
+ }
233
408
  }