@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,8 +1,13 @@
1
1
  import { BigNumberish } from "ethers";
2
+ import { CreditManagerData } from "src/core/creditManager";
3
+ import { ADDRESS_0X0, NetworkType } from "src/core/constants";
2
4
 
5
+ import { contractsByNetwork } from "src/contracts/contracts";
6
+ import { tokenDataByNetwork } from "src/tokens/token";
3
7
  import { LidoV1Adapter__factory } from "../types";
4
8
 
5
9
  import { MultiCallStruct } from "../types/contracts/interfaces/ICreditFacade.sol/ICreditFacade";
10
+ import { UniswapV2Multicaller } from "./uniswapV2";
6
11
 
7
12
  export class LidoCalls {
8
13
  public static submit(amount: BigNumberish) {
@@ -26,6 +31,10 @@ export class LidoMulticaller {
26
31
  this._address = address;
27
32
  }
28
33
 
34
+ static connect(address: string) {
35
+ return new LidoMulticaller(address);
36
+ }
37
+
29
38
  submit(amount: BigNumberish): MultiCallStruct {
30
39
  return {
31
40
  target: this._address,
@@ -40,3 +49,36 @@ export class LidoMulticaller {
40
49
  };
41
50
  }
42
51
  }
52
+
53
+ export class LidoStrategies {
54
+ static mintSteth(
55
+ data: CreditManagerData,
56
+ network: NetworkType,
57
+ underlyingAmount: BigNumberish
58
+ ) {
59
+ const calls: Array<MultiCallStruct> = [];
60
+
61
+ // This should be a pathfinder call
62
+ if (!data.isWETH) {
63
+ calls.push(
64
+ UniswapV2Multicaller.connect(
65
+ data.adapters[contractsByNetwork[network].UNISWAP_V2_ROUTER]
66
+ ).swapExactTokensForTokens(
67
+ underlyingAmount,
68
+ 0,
69
+ [data.underlyingToken, tokenDataByNetwork[network].WETH],
70
+ ADDRESS_0X0,
71
+ Math.floor(new Date().getTime() / 1000) + 3600
72
+ )
73
+ );
74
+ }
75
+
76
+ calls.push(
77
+ LidoMulticaller.connect(
78
+ data.adapters[contractsByNetwork[network].LIDO_STETH_GATEWAY]
79
+ ).submitAll()
80
+ );
81
+
82
+ return calls;
83
+ }
84
+ }
@@ -50,6 +50,10 @@ export class UniswapV2Multicaller {
50
50
  this._address = address;
51
51
  }
52
52
 
53
+ static connect(address: string) {
54
+ return new UniswapV2Multicaller(address);
55
+ }
56
+
53
57
  swapExactTokensForTokens(
54
58
  amountIn: BigNumberish,
55
59
  amountOutMin: BigNumberish,
@@ -67,6 +67,10 @@ export class UniswapV3Multicaller {
67
67
  this._address = address;
68
68
  }
69
69
 
70
+ static connect(address: string) {
71
+ return new UniswapV3Multicaller(address);
72
+ }
73
+
70
74
  exactInputSingle(
71
75
  params: ISwapRouter.ExactInputSingleParamsStructOutput
72
76
  ): MultiCallStruct {
@@ -1,8 +1,21 @@
1
1
  import { BigNumberish } from "ethers";
2
+ import {
3
+ contractParams,
4
+ contractsByNetwork,
5
+ YearnParams,
6
+ YearnVaultContract
7
+ } from "src/contracts/contracts";
8
+ import { ADDRESS_0X0, NetworkType } from "src/core/constants";
9
+ import { CreditManagerData } from "src/core/creditManager";
10
+ import { CurveLPTokenData } from "src/tokens/curveLP";
11
+ import { supportedTokens, tokenDataByNetwork } from "src/tokens/token";
12
+ import { TokenType } from "src/tokens/tokenType";
2
13
 
3
14
  import { YearnV2Adapter__factory } from "../types";
4
15
 
5
16
  import { MultiCallStruct } from "../types/contracts/interfaces/ICreditFacade.sol/ICreditFacade";
17
+ import { CurveStrategies } from "./curve";
18
+ import { UniswapV2Multicaller } from "./uniswapV2";
6
19
 
7
20
  export class YearnV2Calls {
8
21
  public static deposit(amount?: BigNumberish, recipient?: string): string {
@@ -53,6 +66,10 @@ export class YearnV2Multicaller {
53
66
  this._address = address;
54
67
  }
55
68
 
69
+ static connect(address: string) {
70
+ return new YearnV2Multicaller(address);
71
+ }
72
+
56
73
  deposit(amount?: BigNumberish, recipient?: string): MultiCallStruct {
57
74
  return {
58
75
  target: this._address,
@@ -71,3 +88,117 @@ export class YearnV2Multicaller {
71
88
  };
72
89
  }
73
90
  }
91
+
92
+ export class YearnV2Strategies {
93
+ static underlyingToYearn(
94
+ data: CreditManagerData,
95
+ network: NetworkType,
96
+ yearnVault: YearnVaultContract,
97
+ underlyingAmount: BigNumberish
98
+ ) {
99
+ let calls: Array<MultiCallStruct> = [];
100
+ const vaultParams = contractParams[yearnVault] as YearnParams;
101
+ const yearnToken = vaultParams.shareToken;
102
+ const yearnParams = supportedTokens[yearnToken];
103
+
104
+ if (yearnParams.type === TokenType.YEARN_VAULT) {
105
+ if (
106
+ data.underlyingToken !==
107
+ tokenDataByNetwork[network][yearnParams.underlying]
108
+ ) {
109
+ // This should be a pathfinder call
110
+ calls.push(
111
+ UniswapV2Multicaller.connect(
112
+ data.adapters[contractsByNetwork[network].UNISWAP_V2_ROUTER]
113
+ ).swapExactTokensForTokens(
114
+ underlyingAmount,
115
+ 0,
116
+ [
117
+ data.underlyingToken,
118
+ tokenDataByNetwork[network][yearnParams.underlying]
119
+ ],
120
+ ADDRESS_0X0,
121
+ Math.floor(new Date().getTime() / 1000) + 3600
122
+ )
123
+ );
124
+ }
125
+ } else if (
126
+ yearnParams.type === TokenType.YEARN_VAULT_OF_CURVE_LP ||
127
+ yearnParams.type === TokenType.YEARN_VAULT_OF_META_CURVE_LP
128
+ ) {
129
+ const curveTokenParams = supportedTokens[
130
+ yearnParams.underlying
131
+ ] as CurveLPTokenData;
132
+ const curvePool = curveTokenParams.pool;
133
+
134
+ calls = CurveStrategies.underlyingToCurveLP(
135
+ data,
136
+ network,
137
+ curvePool,
138
+ underlyingAmount
139
+ );
140
+ } else {
141
+ throw new Error("Yearn vault type unknown");
142
+ }
143
+
144
+ calls.push(
145
+ YearnV2Multicaller.connect(
146
+ data.adapters[contractsByNetwork[network][yearnVault]]
147
+ ).deposit()
148
+ );
149
+ }
150
+
151
+ static yearnToUnderlying(
152
+ data: CreditManagerData,
153
+ network: NetworkType,
154
+ yearnVault: YearnVaultContract,
155
+ yearnSharesAmount: BigNumberish
156
+ ) {
157
+ let calls: Array<MultiCallStruct> = [];
158
+ const vaultParams = contractParams[yearnVault] as YearnParams;
159
+ const yearnToken = vaultParams.shareToken;
160
+ const yearnParams = supportedTokens[yearnToken];
161
+
162
+ calls.push(
163
+ YearnV2Multicaller.connect(
164
+ data.adapters[contractsByNetwork[network][yearnVault]]
165
+ ).withdraw(yearnSharesAmount)
166
+ );
167
+
168
+ if (yearnParams.type === TokenType.YEARN_VAULT) {
169
+ if (
170
+ data.underlyingToken !==
171
+ tokenDataByNetwork[network][yearnParams.underlying]
172
+ ) {
173
+ // This should be a pathfinder call
174
+ calls.push(
175
+ UniswapV2Multicaller.connect(
176
+ data.adapters[contractsByNetwork[network].UNISWAP_V2_ROUTER]
177
+ ).swapAllTokensForTokens(
178
+ 0,
179
+ [
180
+ tokenDataByNetwork[network][yearnParams.underlying],
181
+ data.underlyingToken
182
+ ],
183
+ Math.floor(new Date().getTime() / 1000) + 3600
184
+ )
185
+ );
186
+ }
187
+ } else if (
188
+ yearnParams.type === TokenType.YEARN_VAULT_OF_CURVE_LP ||
189
+ yearnParams.type === TokenType.YEARN_VAULT_OF_META_CURVE_LP
190
+ ) {
191
+ const curveTokenParams = supportedTokens[
192
+ yearnParams.underlying
193
+ ] as CurveLPTokenData;
194
+ const curvePool = curveTokenParams.pool;
195
+
196
+ calls = [
197
+ ...calls,
198
+ ...CurveStrategies.allCurveLPToUnderlying(data, network, curvePool)
199
+ ];
200
+ } else {
201
+ throw new Error("Yearn vault type unknown");
202
+ }
203
+ }
204
+ }
@@ -1,4 +1,5 @@
1
1
  import { BigNumber } from "ethers";
2
+ import type { CurvePoolContract } from "src/contracts/contracts";
2
3
  import { TradeAction, TradeType } from "../pathfinder/tradeTypes";
3
4
  import type { SupportedToken, TokenBase } from "./token";
4
5
  import { PartialRecord } from "../utils/types";
@@ -17,12 +18,16 @@ export type CurveLPTokenData = {
17
18
  type: TokenType.CURVE_LP;
18
19
  swapActions?: Array<TradeAction>;
19
20
  lpActions: Array<TradeAction>;
21
+ pool: CurvePoolContract;
22
+ wrapper?: CurvePoolContract;
20
23
  } & TokenBase;
21
24
 
22
25
  export type MetaCurveLPTokenData = {
23
26
  symbol: CurveLPToken;
24
27
  type: TokenType.META_CURVE_LP;
25
28
  lpActions: Array<TradeAction>;
29
+ pool: CurvePoolContract;
30
+ wrapper?: CurvePoolContract;
26
31
  } & TokenBase;
27
32
 
28
33
  export const Curve3CrvUnderlyingTokenIndex: PartialRecord<
@@ -42,9 +47,9 @@ export const curveTokens: Record<
42
47
  "3Crv": {
43
48
  name: "3Crv",
44
49
  decimals: 18,
45
-
46
50
  symbol: "3Crv",
47
51
  type: TokenType.CURVE_LP,
52
+ pool: "CURVE_3CRV_POOL",
48
53
  lpActions: [
49
54
  {
50
55
  type: TradeType.CurveWithdrawLP,
@@ -67,9 +72,9 @@ export const curveTokens: Record<
67
72
  steCRV: {
68
73
  name: "steCRV",
69
74
  decimals: 18,
70
-
71
75
  symbol: "steCRV",
72
76
  type: TokenType.CURVE_LP,
77
+ pool: "CURVE_STETH_GATEWAY",
73
78
  lpActions: [
74
79
  {
75
80
  type: TradeType.CurveWithdrawLP,
@@ -92,9 +97,10 @@ export const curveTokens: Record<
92
97
  crvPlain3andSUSD: {
93
98
  name: "crvPlain3andSUSD",
94
99
  decimals: 18,
95
-
96
100
  symbol: "crvPlain3andSUSD",
97
101
  type: TokenType.CURVE_LP,
102
+ pool: "CURVE_SUSD_POOL",
103
+ wrapper: "CURVE_SUSD_DEPOSIT",
98
104
  lpActions: [
99
105
  {
100
106
  type: TradeType.CurveWithdrawLP,
@@ -118,9 +124,9 @@ export const curveTokens: Record<
118
124
  FRAX3CRV: {
119
125
  name: "FRAX3CRV-f",
120
126
  decimals: 18,
121
-
122
127
  symbol: "FRAX3CRV",
123
128
  type: TokenType.META_CURVE_LP,
129
+ pool: "CURVE_FRAX_POOL",
124
130
  lpActions: [
125
131
  {
126
132
  type: TradeType.CurveWithdrawLP,
@@ -143,9 +149,9 @@ export const curveTokens: Record<
143
149
  LUSD3CRV: {
144
150
  name: "LUSD3CRV-f",
145
151
  decimals: 18,
146
-
147
152
  symbol: "LUSD3CRV",
148
153
  type: TokenType.META_CURVE_LP,
154
+ pool: "CURVE_LUSD_POOL",
149
155
  lpActions: [
150
156
  {
151
157
  type: TradeType.CurveWithdrawLP,
@@ -158,9 +164,9 @@ export const curveTokens: Record<
158
164
  gusd3CRV: {
159
165
  name: "gusd3CRV",
160
166
  decimals: 18,
161
-
162
167
  symbol: "gusd3CRV",
163
168
  type: TokenType.META_CURVE_LP,
169
+ pool: "CURVE_GUSD_POOL",
164
170
  lpActions: [
165
171
  {
166
172
  type: TradeType.CurveWithdrawLP,
@@ -1,7 +1,8 @@
1
+ import type { YearnVaultContract } from "src/contracts/contracts";
1
2
  import { TradeAction, TradeType } 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
 
7
8
  export type YearnLPToken =
@@ -17,6 +18,7 @@ export type YearnVaultTokenData = {
17
18
  type: TokenType.YEARN_VAULT;
18
19
  underlying: NormalToken;
19
20
  lpActions: Array<TradeAction>;
21
+ vault: YearnVaultContract;
20
22
  } & TokenBase;
21
23
 
22
24
  export type YearnVaultOfCurveLPTokenData = {
@@ -24,6 +26,7 @@ export type YearnVaultOfCurveLPTokenData = {
24
26
  type: TokenType.YEARN_VAULT_OF_CURVE_LP;
25
27
  underlying: CurveLPToken;
26
28
  lpActions: Array<TradeAction>;
29
+ vault: YearnVaultContract;
27
30
  } & TokenBase;
28
31
 
29
32
  export type YearnVaultOfMetaCurveLPTokenData = {
@@ -31,6 +34,7 @@ export type YearnVaultOfMetaCurveLPTokenData = {
31
34
  type: TokenType.YEARN_VAULT_OF_META_CURVE_LP;
32
35
  underlying: CurveLPToken;
33
36
  lpActions: Array<TradeAction>;
37
+ vault: YearnVaultContract;
34
38
  } & TokenBase;
35
39
 
36
40
  export const yearnTokens: Record<
@@ -43,10 +47,10 @@ export const yearnTokens: Record<
43
47
  yvDAI: {
44
48
  name: "yvDAI",
45
49
  decimals: 18,
46
-
47
50
  symbol: "yvDAI",
48
51
  type: TokenType.YEARN_VAULT,
49
52
  underlying: "DAI",
53
+ vault: "YEARN_DAI_VAULT",
50
54
  lpActions: [
51
55
  {
52
56
  type: TradeType.YearnWithdraw,
@@ -59,10 +63,10 @@ export const yearnTokens: Record<
59
63
  yvUSDC: {
60
64
  name: "yvUSDC",
61
65
  decimals: 6,
62
-
63
66
  symbol: "yvUSDC",
64
67
  type: TokenType.YEARN_VAULT,
65
68
  underlying: "USDC",
69
+ vault: "YEARN_USDC_VAULT",
66
70
  lpActions: [
67
71
  {
68
72
  type: TradeType.YearnWithdraw,
@@ -75,10 +79,10 @@ export const yearnTokens: Record<
75
79
  yvWETH: {
76
80
  name: "yvWETH",
77
81
  decimals: 18,
78
-
79
82
  symbol: "yvWETH",
80
83
  type: TokenType.YEARN_VAULT,
81
84
  underlying: "WETH",
85
+ vault: "YEARN_WETH_VAULT",
82
86
  lpActions: [
83
87
  {
84
88
  type: TradeType.YearnWithdraw,
@@ -91,10 +95,10 @@ export const yearnTokens: Record<
91
95
  yvWBTC: {
92
96
  name: "yvWBTC",
93
97
  decimals: 8,
94
-
95
98
  symbol: "yvWBTC",
96
99
  type: TokenType.YEARN_VAULT,
97
100
  underlying: "WBTC",
101
+ vault: "YEARN_WBTC_VAULT",
98
102
  lpActions: [
99
103
  {
100
104
  type: TradeType.YearnWithdraw,
@@ -108,10 +112,10 @@ export const yearnTokens: Record<
108
112
  yvCurve_stETH: {
109
113
  name: "yvCurve-stETH",
110
114
  decimals: 18,
111
-
112
115
  symbol: "yvCurve_stETH",
113
116
  type: TokenType.YEARN_VAULT_OF_CURVE_LP,
114
117
  underlying: "steCRV",
118
+ vault: "YEARN_CURVE_STETH_VAULT",
115
119
  lpActions: [
116
120
  {
117
121
  type: TradeType.YearnWithdraw,
@@ -124,10 +128,10 @@ export const yearnTokens: Record<
124
128
  yvCurve_FRAX: {
125
129
  name: "yvCurve-FRAX",
126
130
  decimals: 18,
127
-
128
131
  symbol: "yvCurve_FRAX",
129
132
  type: TokenType.YEARN_VAULT_OF_META_CURVE_LP,
130
133
  underlying: "FRAX3CRV",
134
+ vault: "YEARN_CURVE_FRAX_VAULT",
131
135
  lpActions: [
132
136
  {
133
137
  type: TradeType.YearnWithdraw,