@gearbox-protocol/sdk 0.0.103 → 0.0.104

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  import { BigNumber } from "ethers";
2
+ import type { CurvePoolContract } from "src/contracts/contracts";
2
3
  import { TradeAction } from "../pathfinder/tradeTypes";
3
4
  import type { SupportedToken, TokenBase } from "./token";
4
5
  import { PartialRecord } from "../utils/types";
@@ -9,11 +10,15 @@ export declare type CurveLPTokenData = {
9
10
  type: TokenType.CURVE_LP;
10
11
  swapActions?: Array<TradeAction>;
11
12
  lpActions: Array<TradeAction>;
13
+ pool: CurvePoolContract;
14
+ wrapper?: CurvePoolContract;
12
15
  } & TokenBase;
13
16
  export declare type MetaCurveLPTokenData = {
14
17
  symbol: CurveLPToken;
15
18
  type: TokenType.META_CURVE_LP;
16
19
  lpActions: Array<TradeAction>;
20
+ pool: CurvePoolContract;
21
+ wrapper?: CurvePoolContract;
17
22
  } & TokenBase;
18
23
  export declare const Curve3CrvUnderlyingTokenIndex: PartialRecord<SupportedToken, BigNumber>;
19
24
  export declare const curveTokens: Record<CurveLPToken, CurveLPTokenData | MetaCurveLPTokenData>;
@@ -16,6 +16,7 @@ exports.curveTokens = {
16
16
  decimals: 18,
17
17
  symbol: "3Crv",
18
18
  type: tokenType_1.TokenType.CURVE_LP,
19
+ pool: "CURVE_3CRV_POOL",
19
20
  lpActions: [
20
21
  {
21
22
  type: tradeTypes_1.TradeType.CurveWithdrawLP,
@@ -39,6 +40,7 @@ exports.curveTokens = {
39
40
  decimals: 18,
40
41
  symbol: "steCRV",
41
42
  type: tokenType_1.TokenType.CURVE_LP,
43
+ pool: "CURVE_STETH_GATEWAY",
42
44
  lpActions: [
43
45
  {
44
46
  type: tradeTypes_1.TradeType.CurveWithdrawLP,
@@ -62,6 +64,8 @@ exports.curveTokens = {
62
64
  decimals: 18,
63
65
  symbol: "crvPlain3andSUSD",
64
66
  type: tokenType_1.TokenType.CURVE_LP,
67
+ pool: "CURVE_SUSD_POOL",
68
+ wrapper: "CURVE_SUSD_DEPOSIT",
65
69
  lpActions: [
66
70
  {
67
71
  type: tradeTypes_1.TradeType.CurveWithdrawLP,
@@ -86,6 +90,7 @@ exports.curveTokens = {
86
90
  decimals: 18,
87
91
  symbol: "FRAX3CRV",
88
92
  type: tokenType_1.TokenType.META_CURVE_LP,
93
+ pool: "CURVE_FRAX_POOL",
89
94
  lpActions: [
90
95
  {
91
96
  type: tradeTypes_1.TradeType.CurveWithdrawLP,
@@ -109,6 +114,7 @@ exports.curveTokens = {
109
114
  decimals: 18,
110
115
  symbol: "LUSD3CRV",
111
116
  type: tokenType_1.TokenType.META_CURVE_LP,
117
+ pool: "CURVE_LUSD_POOL",
112
118
  lpActions: [
113
119
  {
114
120
  type: tradeTypes_1.TradeType.CurveWithdrawLP,
@@ -122,6 +128,7 @@ exports.curveTokens = {
122
128
  decimals: 18,
123
129
  symbol: "gusd3CRV",
124
130
  type: tokenType_1.TokenType.META_CURVE_LP,
131
+ pool: "CURVE_GUSD_POOL",
125
132
  lpActions: [
126
133
  {
127
134
  type: tradeTypes_1.TradeType.CurveWithdrawLP,
@@ -1,7 +1,8 @@
1
+ import type { YearnVaultContract } from "src/contracts/contracts";
1
2
  import { TradeAction } from "../pathfinder/tradeTypes";
2
3
  import type { TokenBase } from "./token";
3
4
  import type { CurveLPToken } from "./curveLP";
4
- import type { NormalToken } from "./normal";
5
+ import { NormalToken } from "./normal";
5
6
  import { TokenType } from "./tokenType";
6
7
  export declare type YearnLPToken = "yvDAI" | "yvUSDC" | "yvWETH" | "yvWBTC" | "yvCurve_stETH" | "yvCurve_FRAX";
7
8
  export declare type YearnVaultTokenData = {
@@ -9,17 +10,20 @@ export declare type YearnVaultTokenData = {
9
10
  type: TokenType.YEARN_VAULT;
10
11
  underlying: NormalToken;
11
12
  lpActions: Array<TradeAction>;
13
+ vault: YearnVaultContract;
12
14
  } & TokenBase;
13
15
  export declare type YearnVaultOfCurveLPTokenData = {
14
16
  symbol: YearnLPToken;
15
17
  type: TokenType.YEARN_VAULT_OF_CURVE_LP;
16
18
  underlying: CurveLPToken;
17
19
  lpActions: Array<TradeAction>;
20
+ vault: YearnVaultContract;
18
21
  } & TokenBase;
19
22
  export declare type YearnVaultOfMetaCurveLPTokenData = {
20
23
  symbol: YearnLPToken;
21
24
  type: TokenType.YEARN_VAULT_OF_META_CURVE_LP;
22
25
  underlying: CurveLPToken;
23
26
  lpActions: Array<TradeAction>;
27
+ vault: YearnVaultContract;
24
28
  } & TokenBase;
25
29
  export declare const yearnTokens: Record<YearnLPToken, YearnVaultTokenData | YearnVaultOfCurveLPTokenData | YearnVaultOfMetaCurveLPTokenData>;
@@ -11,6 +11,7 @@ exports.yearnTokens = {
11
11
  symbol: "yvDAI",
12
12
  type: tokenType_1.TokenType.YEARN_VAULT,
13
13
  underlying: "DAI",
14
+ vault: "YEARN_DAI_VAULT",
14
15
  lpActions: [
15
16
  {
16
17
  type: tradeTypes_1.TradeType.YearnWithdraw,
@@ -25,6 +26,7 @@ exports.yearnTokens = {
25
26
  symbol: "yvUSDC",
26
27
  type: tokenType_1.TokenType.YEARN_VAULT,
27
28
  underlying: "USDC",
29
+ vault: "YEARN_USDC_VAULT",
28
30
  lpActions: [
29
31
  {
30
32
  type: tradeTypes_1.TradeType.YearnWithdraw,
@@ -39,6 +41,7 @@ exports.yearnTokens = {
39
41
  symbol: "yvWETH",
40
42
  type: tokenType_1.TokenType.YEARN_VAULT,
41
43
  underlying: "WETH",
44
+ vault: "YEARN_WETH_VAULT",
42
45
  lpActions: [
43
46
  {
44
47
  type: tradeTypes_1.TradeType.YearnWithdraw,
@@ -53,6 +56,7 @@ exports.yearnTokens = {
53
56
  symbol: "yvWBTC",
54
57
  type: tokenType_1.TokenType.YEARN_VAULT,
55
58
  underlying: "WBTC",
59
+ vault: "YEARN_WBTC_VAULT",
56
60
  lpActions: [
57
61
  {
58
62
  type: tradeTypes_1.TradeType.YearnWithdraw,
@@ -68,6 +72,7 @@ exports.yearnTokens = {
68
72
  symbol: "yvCurve_stETH",
69
73
  type: tokenType_1.TokenType.YEARN_VAULT_OF_CURVE_LP,
70
74
  underlying: "steCRV",
75
+ vault: "YEARN_CURVE_STETH_VAULT",
71
76
  lpActions: [
72
77
  {
73
78
  type: tradeTypes_1.TradeType.YearnWithdraw,
@@ -82,6 +87,7 @@ exports.yearnTokens = {
82
87
  symbol: "yvCurve_FRAX",
83
88
  type: tokenType_1.TokenType.YEARN_VAULT_OF_META_CURVE_LP,
84
89
  underlying: "FRAX3CRV",
90
+ vault: "YEARN_CURVE_FRAX_VAULT",
85
91
  lpActions: [
86
92
  {
87
93
  type: tradeTypes_1.TradeType.YearnWithdraw,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "0.0.103",
3
+ "version": "0.0.104",
4
4
  "description": "Gearbox SDK",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -16,8 +16,7 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "decimal.js-light": "^2.5.1",
19
- "moment": "^2.29.1",
20
- "prettier": "^2.7.1"
19
+ "moment": "^2.29.1"
21
20
  },
22
21
  "devDependencies": {
23
22
  "@types/jest": "^26.0.15",
@@ -3,6 +3,7 @@
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 type { YearnLPToken } from "src/tokens/yearn";
6
7
  import {
7
8
  keyToLowercase,
8
9
  objectEntries,
@@ -13,9 +14,9 @@ import { AdapterInterface } from "./adapters";
13
14
  import { NetworkType } from "../core/constants";
14
15
  import { Protocols } from "./protocols";
15
16
  import { tokenDataByNetwork } from "../tokens/token";
16
- import type { ConvexStakedPhantomToken } from "../tokens/convex";
17
+ import { ConvexStakedPhantomToken } from "../tokens/convex";
17
18
  import type { CurveLPToken } from "../tokens/curveLP";
18
- import type { NormalToken } from "../tokens/normal";
19
+ import { NormalToken } from "../tokens/normal";
19
20
 
20
21
  export type UniswapV2Contract = "UNISWAP_V2_ROUTER" | "SUSHISWAP_ROUTER";
21
22
 
@@ -169,12 +170,14 @@ export type CurveSteCRVPoolParams = {
169
170
  protocol: Protocols.Curve;
170
171
  type: AdapterInterface.CURVE_V1_STECRV_POOL;
171
172
  pool: Record<NetworkType, string>;
173
+ tokens: ["WETH", "STETH"];
172
174
  lpToken: "steCRV";
173
175
  } & BaseContractParams;
174
176
 
175
- type YearnParams = {
177
+ export type YearnParams = {
176
178
  protocol: Protocols.Yearn;
177
179
  type: AdapterInterface.YEARN_V2;
180
+ shareToken: YearnLPToken;
178
181
  } & BaseContractParams;
179
182
 
180
183
  type ConvexParams = {
@@ -247,6 +250,7 @@ export const contractParams: Record<SupportedContract, ContractParams> = {
247
250
  Mainnet: "0xDC24316b9AE028F1497c275EB9192a3Ea0f67022",
248
251
  Kovan: "0xF5C73b58B70709e89aA1D322d48b0D0C71123cB4"
249
252
  },
253
+ tokens: ["WETH", "STETH"],
250
254
  lpToken: "steCRV"
251
255
  },
252
256
  CURVE_FRAX_POOL: {
@@ -254,14 +258,14 @@ export const contractParams: Record<SupportedContract, ContractParams> = {
254
258
  protocol: Protocols.Curve,
255
259
  type: AdapterInterface.CURVE_V1_2ASSETS,
256
260
  lpToken: "FRAX3CRV",
257
- tokens: ["3Crv", "FRAX"]
261
+ tokens: ["FRAX", "3Crv"]
258
262
  },
259
263
  CURVE_LUSD_POOL: {
260
264
  name: "Curve LUSD",
261
265
  protocol: Protocols.Curve,
262
266
  type: AdapterInterface.CURVE_V1_2ASSETS,
263
267
  lpToken: "LUSD3CRV",
264
- tokens: ["3Crv", "LUSD"]
268
+ tokens: ["LUSD", "3Crv"]
265
269
  },
266
270
  CURVE_SUSD_POOL: {
267
271
  name: "Curve SUSD",
@@ -277,8 +281,7 @@ export const contractParams: Record<SupportedContract, ContractParams> = {
277
281
  protocol: Protocols.Curve,
278
282
  type: AdapterInterface.CURVE_V1_WRAPPER,
279
283
  lpToken: "crvPlain3andSUSD",
280
- tokens: ["DAI", "USDC", "USDT", "sUSD"],
281
- wrapper: "CURVE_SUSD_DEPOSIT"
284
+ tokens: ["DAI", "USDC", "USDT", "sUSD"]
282
285
  },
283
286
 
284
287
  CURVE_GUSD_POOL: {
@@ -286,38 +289,44 @@ export const contractParams: Record<SupportedContract, ContractParams> = {
286
289
  protocol: Protocols.Curve,
287
290
  type: AdapterInterface.CURVE_V1_2ASSETS,
288
291
  lpToken: "gusd3CRV",
289
- tokens: ["3Crv", "FRAX"]
292
+ tokens: ["GUSD", "3Crv"]
290
293
  },
291
294
 
292
295
  YEARN_DAI_VAULT: {
293
296
  name: "Yearn DAI",
294
297
  protocol: Protocols.Yearn,
295
- type: AdapterInterface.YEARN_V2
298
+ type: AdapterInterface.YEARN_V2,
299
+ shareToken: "yvDAI"
296
300
  },
297
301
  YEARN_USDC_VAULT: {
298
302
  name: "Yearn USDC",
299
303
  protocol: Protocols.Yearn,
300
- type: AdapterInterface.YEARN_V2
304
+ type: AdapterInterface.YEARN_V2,
305
+ shareToken: "yvUSDC"
301
306
  },
302
307
  YEARN_WETH_VAULT: {
303
308
  name: "Yearn WETH",
304
309
  protocol: Protocols.Yearn,
305
- type: AdapterInterface.YEARN_V2
310
+ type: AdapterInterface.YEARN_V2,
311
+ shareToken: "yvWETH"
306
312
  },
307
313
  YEARN_WBTC_VAULT: {
308
314
  name: "Yearn WBTC",
309
315
  protocol: Protocols.Yearn,
310
- type: AdapterInterface.YEARN_V2
316
+ type: AdapterInterface.YEARN_V2,
317
+ shareToken: "yvWBTC"
311
318
  },
312
319
  YEARN_CURVE_FRAX_VAULT: {
313
320
  name: "Yearn Curve FRAX",
314
321
  protocol: Protocols.Yearn,
315
- type: AdapterInterface.YEARN_V2
322
+ type: AdapterInterface.YEARN_V2,
323
+ shareToken: "yvCurve_FRAX"
316
324
  },
317
325
  YEARN_CURVE_STETH_VAULT: {
318
326
  name: "Yearn Curve STETH",
319
327
  protocol: Protocols.Yearn,
320
- type: AdapterInterface.YEARN_V2
328
+ type: AdapterInterface.YEARN_V2,
329
+ shareToken: "yvCurve_stETH"
321
330
  },
322
331
 
323
332
  CONVEX_BOOSTER: {
package/src/index.ts CHANGED
@@ -47,6 +47,15 @@ export * from "./core/history";
47
47
  export * from "./utils/multicall";
48
48
  export * from "./utils/types";
49
49
  export * from "./utils/errors";
50
+
51
+ export * from "./strategies/convex";
52
+ export * from "./strategies/creditFacade";
53
+ export * from "./strategies/curve";
54
+ export * from "./strategies/lido";
55
+ export * from "./strategies/uniswapV2";
56
+ export * from "./strategies/uniswapV3";
57
+ export * from "./strategies/yearn";
58
+
50
59
  export { callRepeater } from "./utils/repeater";
51
60
  export { getContractName } from "./contracts/contractsRegister";
52
61
  export { AdapterInterface } from "./contracts/adapters";
@@ -1,4 +1,15 @@
1
1
  import { BigNumberish } from "ethers";
2
+ import {
3
+ contractParams,
4
+ contractsByNetwork,
5
+ ConvexPoolContract,
6
+ ConvexPoolParams
7
+ } from "src/contracts/contracts";
8
+ import { NetworkType } from "src/core/constants";
9
+ import { CreditManagerData } from "src/core/creditManager";
10
+ import { ConvexPhantomTokenData } from "src/tokens/convex";
11
+ import { CurveLPTokenData } from "src/tokens/curveLP";
12
+ import { supportedTokens, tokenDataByNetwork } from "src/tokens/token";
2
13
 
3
14
  import {
4
15
  ConvexV1BoosterAdapter__factory,
@@ -7,6 +18,8 @@ import {
7
18
  } from "../types";
8
19
 
9
20
  import { MultiCallStruct } from "../types/contracts/interfaces/ICreditFacade.sol/ICreditFacade";
21
+ import { CurveStrategies } from "./curve";
22
+ import { UniswapV2Multicaller } from "./uniswapV2";
10
23
 
11
24
  export class ConvexBoosterCalls {
12
25
  public static deposit(
@@ -121,6 +134,10 @@ export class ConvexBoosterMulticaller {
121
134
  this._address = address;
122
135
  }
123
136
 
137
+ static connect(address: string) {
138
+ return new ConvexBoosterMulticaller(address);
139
+ }
140
+
124
141
  deposit(
125
142
  pid: BigNumberish,
126
143
  amount: BigNumberish,
@@ -161,6 +178,10 @@ export class ConvexPoolMulticaller {
161
178
  this._address = address;
162
179
  }
163
180
 
181
+ static connect(address: string) {
182
+ return new ConvexPoolMulticaller(address);
183
+ }
184
+
164
185
  stake(amount: BigNumberish): MultiCallStruct {
165
186
  return {
166
187
  target: this._address,
@@ -211,6 +232,10 @@ export class ConvexClaimZapMulticaller {
211
232
  this._address = address;
212
233
  }
213
234
 
235
+ static connect(address: string) {
236
+ return new ConvexClaimZapMulticaller(address);
237
+ }
238
+
214
239
  claimRewards(
215
240
  rewardContracts: Array<string>,
216
241
  extraRewardContracts: Array<string>,
@@ -238,3 +263,145 @@ export class ConvexClaimZapMulticaller {
238
263
  };
239
264
  }
240
265
  }
266
+
267
+ export class ConvexStrategies {
268
+ static underlyingToStakedConvex(
269
+ data: CreditManagerData,
270
+ network: NetworkType,
271
+ convexPool: ConvexPoolContract,
272
+ underlyingAmount: BigNumberish
273
+ ) {
274
+ let calls: Array<MultiCallStruct> = [];
275
+ const convexParams = contractParams[convexPool] as ConvexPoolParams;
276
+ const { stakedToken } = convexParams;
277
+ const stakedTokenParams = supportedTokens[
278
+ stakedToken
279
+ ] as ConvexPhantomTokenData;
280
+ const curveLpToken = stakedTokenParams.underlying;
281
+ const curveLpTokenData = supportedTokens[curveLpToken] as CurveLPTokenData;
282
+ const curvePool = curveLpTokenData.pool;
283
+
284
+ calls = CurveStrategies.underlyingToCurveLP(
285
+ data,
286
+ network,
287
+ curvePool,
288
+ underlyingAmount
289
+ );
290
+
291
+ calls.push(
292
+ ConvexBoosterMulticaller.connect(
293
+ data.adapters[contractsByNetwork[network].CONVEX_BOOSTER]
294
+ ).depositAll(stakedTokenParams.pid, true)
295
+ );
296
+
297
+ return calls;
298
+ }
299
+
300
+ static stakedConvexToUnderlying(
301
+ data: CreditManagerData,
302
+ network: NetworkType,
303
+ convexPool: ConvexPoolContract,
304
+ convexLpAmount: BigNumberish,
305
+ sellRewards: boolean
306
+ ) {
307
+ const calls: Array<MultiCallStruct> = [];
308
+ const convexParams = contractParams[convexPool] as ConvexPoolParams;
309
+ const { stakedToken } = convexParams;
310
+ const stakedTokenParams = supportedTokens[
311
+ stakedToken
312
+ ] as ConvexPhantomTokenData;
313
+ const curveLpToken = stakedTokenParams.underlying;
314
+ const curveLpTokenData = supportedTokens[curveLpToken] as CurveLPTokenData;
315
+ const curvePool = curveLpTokenData.pool;
316
+
317
+ calls.push(
318
+ ConvexPoolMulticaller.connect(
319
+ data.adapters[contractsByNetwork[network][convexPool]]
320
+ ).withdrawAndUnwrap(convexLpAmount, true)
321
+ );
322
+
323
+ calls.push(
324
+ ...CurveStrategies.allCurveLPToUnderlying(data, network, curvePool)
325
+ );
326
+
327
+ if (sellRewards) {
328
+ calls.push(...ConvexStrategies.sellRewards(data, network, convexPool));
329
+ }
330
+
331
+ return calls;
332
+ }
333
+
334
+ static allStakedConvexToUnderlying(
335
+ data: CreditManagerData,
336
+ network: NetworkType,
337
+ convexPool: ConvexPoolContract,
338
+ sellRewards: boolean
339
+ ) {
340
+ const calls: Array<MultiCallStruct> = [];
341
+ const convexParams = contractParams[convexPool] as ConvexPoolParams;
342
+ const { stakedToken } = convexParams;
343
+ const stakedTokenParams = supportedTokens[
344
+ stakedToken
345
+ ] as ConvexPhantomTokenData;
346
+ const curveLpToken = stakedTokenParams.underlying;
347
+ const curveLpTokenData = supportedTokens[curveLpToken] as CurveLPTokenData;
348
+ const curvePool = curveLpTokenData.pool;
349
+
350
+ calls.push(
351
+ ConvexPoolMulticaller.connect(
352
+ data.adapters[contractsByNetwork[network][convexPool]]
353
+ ).withdrawAllAndUnwrap(true)
354
+ );
355
+
356
+ calls.push(
357
+ ...CurveStrategies.allCurveLPToUnderlying(data, network, curvePool)
358
+ );
359
+
360
+ if (sellRewards) {
361
+ calls.push(...ConvexStrategies.sellRewards(data, network, convexPool));
362
+ }
363
+
364
+ return calls;
365
+ }
366
+
367
+ static sellRewards(
368
+ data: CreditManagerData,
369
+ network: NetworkType,
370
+ convexPool: ConvexPoolContract
371
+ ) {
372
+ const calls: Array<MultiCallStruct> = [];
373
+ const convexParams = contractParams[convexPool] as ConvexPoolParams;
374
+
375
+ calls.push(
376
+ UniswapV2Multicaller.connect(
377
+ data.adapters[contractsByNetwork[network].UNISWAP_V2_ROUTER]
378
+ ).swapAllTokensForTokens(
379
+ 0,
380
+ [tokenDataByNetwork[network].CRV, data.underlyingToken],
381
+ Math.floor(new Date().getTime() / 1000) + 3600
382
+ ),
383
+ UniswapV2Multicaller.connect(
384
+ data.adapters[contractsByNetwork[network].UNISWAP_V2_ROUTER]
385
+ ).swapAllTokensForTokens(
386
+ 0,
387
+ [tokenDataByNetwork[network].CVX, data.underlyingToken],
388
+ Math.floor(new Date().getTime() / 1000) + 3600
389
+ )
390
+ );
391
+
392
+ convexParams.extraRewards.forEach(extraReward => {
393
+ UniswapV2Multicaller.connect(
394
+ data.adapters[contractsByNetwork[network].UNISWAP_V2_ROUTER]
395
+ ).swapAllTokensForTokens(
396
+ 0,
397
+ [
398
+ tokenDataByNetwork[network][extraReward.rewardToken],
399
+ data.underlyingToken
400
+ ],
401
+ Math.floor(new Date().getTime() / 1000) + 3600
402
+ );
403
+ });
404
+
405
+ return calls;
406
+ }
407
+ }
@@ -50,6 +50,10 @@ export class CreditFacadeMulticaller {
50
50
  this._address = address;
51
51
  }
52
52
 
53
+ static connect(address: string) {
54
+ return new CreditFacadeMulticaller(address);
55
+ }
56
+
53
57
  addCollateral(
54
58
  onBehalfOf: string,
55
59
  token: string,
@@ -1,4 +1,13 @@
1
1
  import { BigNumberish } from "ethers";
2
+ import {
3
+ contractParams,
4
+ contractsByNetwork,
5
+ CurveParams,
6
+ CurvePoolContract
7
+ } from "src/contracts/contracts";
8
+ import { ADDRESS_0X0, NetworkType } from "src/core/constants";
9
+ import { CreditManagerData } from "src/core/creditManager";
10
+ import { tokenDataByNetwork } from "src/tokens/token";
2
11
 
3
12
  import {
4
13
  CurveV1AdapterBase__factory,
@@ -8,6 +17,7 @@ import {
8
17
  } from "../types";
9
18
 
10
19
  import { MultiCallStruct } from "../types/contracts/interfaces/ICreditFacade.sol/ICreditFacade";
20
+ import { UniswapV2Multicaller } from "./uniswapV2";
11
21
 
12
22
  export class CurveCalls {
13
23
  public static exchange(
@@ -179,6 +189,10 @@ export class CurveMulticaller {
179
189
  this._address = address;
180
190
  }
181
191
 
192
+ static connect(address: string) {
193
+ return new CurveMulticaller(address);
194
+ }
195
+
182
196
  exchange(
183
197
  i: BigNumberish,
184
198
  j: BigNumberish,
@@ -296,3 +310,131 @@ export class CurveMulticaller {
296
310
  };
297
311
  }
298
312
  }
313
+
314
+ export class CurveStrategies {
315
+ static underlyingToCurveLP(
316
+ data: CreditManagerData,
317
+ network: NetworkType,
318
+ curvePool: CurvePoolContract,
319
+ underlyingAmount: BigNumberish
320
+ ) {
321
+ const calls: Array<MultiCallStruct> = [];
322
+ const curveParams = contractParams[curvePool] as CurveParams;
323
+ const tokenToDeposit = curveParams.tokens[0];
324
+
325
+ if (data.underlyingToken !== tokenDataByNetwork[network][tokenToDeposit]) {
326
+ calls.push(
327
+ UniswapV2Multicaller.connect(
328
+ data.adapters[contractsByNetwork[network].UNISWAP_V2_ROUTER]
329
+ ).swapExactTokensForTokens(
330
+ underlyingAmount,
331
+ 0,
332
+ [data.underlyingToken, tokenDataByNetwork[network][tokenToDeposit]],
333
+ ADDRESS_0X0,
334
+ Math.floor(new Date().getTime() / 1000) + 3600
335
+ )
336
+ );
337
+ }
338
+
339
+ calls.push(
340
+ CurveMulticaller.connect(
341
+ data.adapters[contractsByNetwork[network][curvePool]]
342
+ ).add_all_liquidity_one_coin(0, 0)
343
+ );
344
+
345
+ return calls;
346
+ }
347
+
348
+ static curveLPToUnderlying(
349
+ data: CreditManagerData,
350
+ network: NetworkType,
351
+ curvePool: CurvePoolContract,
352
+ curveLPAmount: BigNumberish
353
+ ) {
354
+ const calls: Array<MultiCallStruct> = [];
355
+ const curveParams = contractParams[curvePool] as CurveParams;
356
+
357
+ let curveContractAddress;
358
+
359
+ if (curveParams.wrapper) {
360
+ curveContractAddress =
361
+ data.adapters[contractsByNetwork[network][curveParams.wrapper]];
362
+ } else {
363
+ curveContractAddress =
364
+ data.adapters[contractsByNetwork[network][curvePool]];
365
+ }
366
+
367
+ calls.push(
368
+ CurveMulticaller.connect(curveContractAddress).remove_liquidity_one_coin(
369
+ curveLPAmount,
370
+ 0,
371
+ 0
372
+ )
373
+ );
374
+
375
+ if (
376
+ tokenDataByNetwork[network][curveParams.tokens[0]] !==
377
+ data.underlyingToken
378
+ ) {
379
+ calls.push(
380
+ UniswapV2Multicaller.connect(
381
+ data.adapters[contractsByNetwork[network].UNISWAP_V2_ROUTER]
382
+ ).swapAllTokensForTokens(
383
+ 0,
384
+ [
385
+ tokenDataByNetwork[network][curveParams.tokens[0]],
386
+ data.underlyingToken
387
+ ],
388
+ Math.floor(new Date().getTime() / 1000) + 3600
389
+ )
390
+ );
391
+ }
392
+
393
+ return calls;
394
+ }
395
+
396
+ static allCurveLPToUnderlying(
397
+ data: CreditManagerData,
398
+ network: NetworkType,
399
+ curvePool: CurvePoolContract
400
+ ) {
401
+ const calls: Array<MultiCallStruct> = [];
402
+ const curveParams = contractParams[curvePool] as CurveParams;
403
+
404
+ let curveContractAddress;
405
+
406
+ if (curveParams.wrapper) {
407
+ curveContractAddress =
408
+ data.adapters[contractsByNetwork[network][curveParams.wrapper]];
409
+ } else {
410
+ curveContractAddress =
411
+ data.adapters[contractsByNetwork[network][curvePool]];
412
+ }
413
+
414
+ calls.push(
415
+ CurveMulticaller.connect(
416
+ curveContractAddress
417
+ ).remove_all_liquidity_one_coin(0, 0)
418
+ );
419
+
420
+ if (
421
+ tokenDataByNetwork[network][curveParams.tokens[0]] !==
422
+ data.underlyingToken
423
+ ) {
424
+ calls.push(
425
+ UniswapV2Multicaller.connect(
426
+ data.adapters[contractsByNetwork[network].UNISWAP_V2_ROUTER]
427
+ ).swapAllTokensForTokens(
428
+ 0,
429
+ [
430
+ tokenDataByNetwork[network][curveParams.tokens[0]],
431
+ data.underlyingToken
432
+ ],
433
+ Math.floor(new Date().getTime() / 1000) + 3600
434
+ )
435
+ );
436
+ }
437
+
438
+ return calls;
439
+ }
440
+ }