@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.
- package/.eslintignore +5 -0
- package/.eslintrc.js +52 -0
- package/.husky/pre-push +4 -0
- package/lib/apy/convexAPY.js +3 -5
- package/lib/apy/lidoAPY.js +8 -9
- package/lib/contracts/contracts.d.ts +5 -2
- package/lib/contracts/contracts.js +19 -18
- package/lib/core/constants.d.ts +1 -1
- package/lib/core/constants.js +2 -2
- package/lib/core/creditAccount.js +7 -5
- package/lib/core/creditManager.d.ts +1 -1
- package/lib/core/creditManager.js +1 -7
- package/lib/core/creditSession.js +14 -3
- package/lib/core/eventOrTx.d.ts +1 -1
- package/lib/core/events.d.ts +19 -19
- package/lib/core/events.js +23 -21
- package/lib/core/pool.d.ts +1 -1
- package/lib/core/pool.js +1 -7
- package/lib/core/price.js +6 -1
- package/lib/core/strategy.d.ts +1 -3
- package/lib/core/strategy.js +14 -13
- 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 -2
- package/lib/index.js +8 -1
- 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 +18 -15
- package/lib/strategies/convex.d.ts +12 -0
- package/lib/strategies/convex.js +74 -1
- package/lib/strategies/creditFacade.d.ts +1 -0
- package/lib/strategies/creditFacade.js +3 -0
- package/lib/strategies/curve.d.ts +15 -60
- package/lib/strategies/curve.js +74 -1
- package/lib/strategies/lido.d.ts +6 -0
- package/lib/strategies/lido.js +23 -1
- package/lib/strategies/uniswapV2.d.ts +1 -0
- package/lib/strategies/uniswapV2.js +6 -19
- package/lib/strategies/uniswapV3.d.ts +1 -0
- package/lib/strategies/uniswapV3.js +4 -1
- package/lib/strategies/yearn.d.ts +8 -0
- package/lib/strategies/yearn.js +92 -12
- package/lib/tokens/convex.d.ts +3 -3
- package/lib/tokens/curveLP.d.ts +7 -2
- package/lib/tokens/curveLP.js +8 -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 +4 -4
- package/lib/tokens/tokenData.d.ts +3 -1
- package/lib/tokens/tokenData.js +10 -8
- package/lib/tokens/yearn.d.ts +6 -2
- package/lib/tokens/yearn.js +6 -0
- package/lib/utils/errors.d.ts +6 -0
- package/lib/utils/errors.js +13 -0
- package/lib/utils/formatter.d.ts +1 -1
- package/lib/utils/formatter.js +17 -14
- package/lib/utils/loading.d.ts +2 -1
- package/lib/utils/loading.js +9 -13
- package/lib/utils/mappers.js +2 -2
- package/lib/utils/network.js +2 -2
- package/lib/utils/repeater.js +12 -24
- package/lib/utils/validate.js +1 -1
- package/package.json +24 -7
- package/src/apy/convexAPY.ts +6 -6
- package/src/apy/lidoAPY.ts +12 -11
- package/src/contracts/contracts.ts +27 -17
- package/src/core/constants.ts +1 -1
- package/src/core/creditAccount.ts +28 -5
- package/src/core/creditManager.ts +29 -4
- package/src/core/creditOperation.ts +7 -7
- package/src/core/creditSession.ts +25 -5
- package/src/core/errors.ts +1 -0
- package/src/core/eventOrTx.ts +8 -5
- package/src/core/events.ts +85 -24
- package/src/core/history.ts +46 -46
- package/src/core/operations.ts +6 -0
- package/src/core/pool.ts +16 -4
- package/src/core/price.ts +7 -3
- package/src/core/strategy.ts +27 -23
- package/src/core/tokenDistributor.ts +2 -2
- package/src/core/transactions.ts +427 -350
- package/src/index.ts +10 -3
- 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 +17 -9
- 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 +26 -11
- package/src/payload/token.ts +3 -3
- package/src/strategies/convex.ts +361 -186
- package/src/strategies/creditFacade.ts +74 -53
- package/src/strategies/curve.ts +400 -189
- package/src/strategies/lido.ts +70 -32
- package/src/strategies/uniswapV2.ts +93 -111
- package/src/strategies/uniswapV3.ts +118 -91
- package/src/strategies/yearn.ts +187 -60
- package/src/tokens/connectors.ts +6 -6
- package/src/tokens/convex.ts +297 -296
- package/src/tokens/curveLP.ts +176 -165
- package/src/tokens/gear.ts +47 -45
- package/src/tokens/normal.ts +801 -802
- package/src/tokens/token.ts +9 -5
- package/src/tokens/tokenData.ts +19 -9
- package/src/tokens/tokenType.ts +11 -11
- package/src/tokens/yearn.ts +130 -124
- package/src/utils/errors.ts +11 -0
- package/src/utils/formatter.ts +22 -18
- package/src/utils/loading.ts +14 -6
- package/src/utils/mappers.ts +8 -6
- package/src/utils/multicall.ts +2 -0
- package/src/utils/network.ts +21 -21
- package/src/utils/repeater.ts +2 -2
- package/src/utils/validate.ts +1 -1
- package/lib/utils/events.d.ts +0 -2
- package/lib/utils/events.js +0 -13
- package/src/utils/events.ts +0 -10
package/src/strategies/curve.ts
CHANGED
|
@@ -1,229 +1,440 @@
|
|
|
1
1
|
import { BigNumberish } from "ethers";
|
|
2
|
+
import {
|
|
3
|
+
contractParams,
|
|
4
|
+
contractsByNetwork,
|
|
5
|
+
CurveParams,
|
|
6
|
+
CurvePoolContract
|
|
7
|
+
} from "../contracts/contracts";
|
|
8
|
+
import { ADDRESS_0X0, NetworkType } from "../core/constants";
|
|
9
|
+
import { CreditManagerData } from "../core/creditManager";
|
|
10
|
+
import { tokenDataByNetwork } from "../tokens/token";
|
|
2
11
|
|
|
3
12
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
13
|
+
CurveV1AdapterBase__factory,
|
|
14
|
+
CurveV1Adapter2Assets__factory,
|
|
15
|
+
CurveV1Adapter3Assets__factory,
|
|
16
|
+
CurveV1Adapter4Assets__factory
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
23
|
+
public static exchange(
|
|
24
|
+
i: BigNumberish,
|
|
25
|
+
j: BigNumberish,
|
|
26
|
+
dx: BigNumberish,
|
|
27
|
+
min_dy: BigNumberish
|
|
28
|
+
) {
|
|
29
|
+
return CurveV1AdapterBase__factory.createInterface().encodeFunctionData(
|
|
30
|
+
"exchange",
|
|
31
|
+
[i, j, dx, min_dy]
|
|
32
|
+
);
|
|
33
|
+
}
|
|
19
34
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
35
|
+
public static exchange_all(
|
|
36
|
+
i: BigNumberish,
|
|
37
|
+
j: BigNumberish,
|
|
38
|
+
rateMinRAY: BigNumberish
|
|
39
|
+
) {
|
|
40
|
+
return CurveV1AdapterBase__factory.createInterface().encodeFunctionData(
|
|
41
|
+
"exchange_all",
|
|
42
|
+
[i, j, rateMinRAY]
|
|
43
|
+
);
|
|
44
|
+
}
|
|
26
45
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
46
|
+
public static exchange_underlying(
|
|
47
|
+
i: BigNumberish,
|
|
48
|
+
j: BigNumberish,
|
|
49
|
+
dx: BigNumberish,
|
|
50
|
+
min_dy: BigNumberish
|
|
51
|
+
) {
|
|
52
|
+
return CurveV1AdapterBase__factory.createInterface().encodeFunctionData(
|
|
53
|
+
"exchange_underlying",
|
|
54
|
+
[i, j, dx, min_dy]
|
|
55
|
+
);
|
|
56
|
+
}
|
|
33
57
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
58
|
+
public static exchange_all_underlying(
|
|
59
|
+
i: BigNumberish,
|
|
60
|
+
j: BigNumberish,
|
|
61
|
+
rateMinRAY: BigNumberish
|
|
62
|
+
) {
|
|
63
|
+
return CurveV1AdapterBase__factory.createInterface().encodeFunctionData(
|
|
64
|
+
"exchange_all_underlying",
|
|
65
|
+
[i, j, rateMinRAY]
|
|
66
|
+
);
|
|
67
|
+
}
|
|
40
68
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
69
|
+
public static add_all_liquidity_one_coin(
|
|
70
|
+
i: BigNumberish,
|
|
71
|
+
rateMinRAY: BigNumberish
|
|
72
|
+
) {
|
|
73
|
+
return CurveV1AdapterBase__factory.createInterface().encodeFunctionData(
|
|
74
|
+
"add_all_liquidity_one_coin",
|
|
75
|
+
[i, rateMinRAY]
|
|
76
|
+
);
|
|
77
|
+
}
|
|
47
78
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
79
|
+
public static remove_liquidity_one_coin(
|
|
80
|
+
token_amount: BigNumberish,
|
|
81
|
+
i: BigNumberish,
|
|
82
|
+
min_amount: BigNumberish
|
|
83
|
+
) {
|
|
84
|
+
return CurveV1AdapterBase__factory.createInterface().encodeFunctionData(
|
|
85
|
+
"remove_liquidity_one_coin",
|
|
86
|
+
[token_amount, i, min_amount]
|
|
87
|
+
);
|
|
88
|
+
}
|
|
54
89
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
90
|
+
public static remove_all_liquidity_one_coin(
|
|
91
|
+
i: BigNumberish,
|
|
92
|
+
minRateRAY: BigNumberish
|
|
93
|
+
) {
|
|
94
|
+
return CurveV1AdapterBase__factory.createInterface().encodeFunctionData(
|
|
95
|
+
"remove_all_liquidity_one_coin",
|
|
96
|
+
[i, minRateRAY]
|
|
97
|
+
);
|
|
98
|
+
}
|
|
61
99
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
100
|
+
public static add_liquidity(
|
|
101
|
+
amounts:
|
|
102
|
+
| [BigNumberish, BigNumberish]
|
|
103
|
+
| [BigNumberish, BigNumberish, BigNumberish]
|
|
104
|
+
| [BigNumberish, BigNumberish, BigNumberish, BigNumberish],
|
|
105
|
+
min_mint_amount: BigNumberish
|
|
106
|
+
): string {
|
|
107
|
+
switch (amounts.length) {
|
|
108
|
+
case 2:
|
|
109
|
+
return CurveV1Adapter2Assets__factory.createInterface().encodeFunctionData(
|
|
110
|
+
"add_liquidity",
|
|
111
|
+
[amounts, min_mint_amount]
|
|
112
|
+
);
|
|
113
|
+
case 3:
|
|
114
|
+
return CurveV1Adapter3Assets__factory.createInterface().encodeFunctionData(
|
|
115
|
+
"add_liquidity",
|
|
116
|
+
[amounts, min_mint_amount]
|
|
117
|
+
);
|
|
118
|
+
case 4:
|
|
119
|
+
return CurveV1Adapter4Assets__factory.createInterface().encodeFunctionData(
|
|
120
|
+
"add_liquidity",
|
|
121
|
+
[amounts, min_mint_amount]
|
|
122
|
+
);
|
|
123
|
+
default:
|
|
124
|
+
throw new Error("Wrong calls number: add_liquidity");
|
|
85
125
|
}
|
|
126
|
+
}
|
|
86
127
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
128
|
+
public static remove_liquidity(
|
|
129
|
+
amount: BigNumberish,
|
|
130
|
+
min_amounts:
|
|
131
|
+
| [BigNumberish, BigNumberish]
|
|
132
|
+
| [BigNumberish, BigNumberish, BigNumberish]
|
|
133
|
+
| [BigNumberish, BigNumberish, BigNumberish, BigNumberish]
|
|
134
|
+
) {
|
|
135
|
+
switch (min_amounts.length) {
|
|
136
|
+
case 2:
|
|
137
|
+
return CurveV1Adapter2Assets__factory.createInterface().encodeFunctionData(
|
|
138
|
+
"remove_liquidity",
|
|
139
|
+
[amount, min_amounts]
|
|
140
|
+
);
|
|
141
|
+
case 3:
|
|
142
|
+
return CurveV1Adapter3Assets__factory.createInterface().encodeFunctionData(
|
|
143
|
+
"remove_liquidity",
|
|
144
|
+
[amount, min_amounts]
|
|
145
|
+
);
|
|
146
|
+
case 4:
|
|
147
|
+
return CurveV1Adapter4Assets__factory.createInterface().encodeFunctionData(
|
|
148
|
+
"remove_liquidity",
|
|
149
|
+
[amount, min_amounts]
|
|
150
|
+
);
|
|
151
|
+
default:
|
|
152
|
+
throw new Error("Wrong calls number: remove_liquidity");
|
|
110
153
|
}
|
|
154
|
+
}
|
|
111
155
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
156
|
+
public static remove_liquidity_imbalance(
|
|
157
|
+
amounts:
|
|
158
|
+
| [BigNumberish, BigNumberish]
|
|
159
|
+
| [BigNumberish, BigNumberish, BigNumberish]
|
|
160
|
+
| [BigNumberish, BigNumberish, BigNumberish, BigNumberish],
|
|
161
|
+
max_burn_amount: BigNumberish
|
|
162
|
+
) {
|
|
163
|
+
switch (amounts.length) {
|
|
164
|
+
case 2:
|
|
165
|
+
return CurveV1Adapter2Assets__factory.createInterface().encodeFunctionData(
|
|
166
|
+
"remove_liquidity_imbalance",
|
|
167
|
+
[amounts, max_burn_amount]
|
|
168
|
+
);
|
|
169
|
+
case 3:
|
|
170
|
+
return CurveV1Adapter3Assets__factory.createInterface().encodeFunctionData(
|
|
171
|
+
"remove_liquidity_imbalance",
|
|
172
|
+
[amounts, max_burn_amount]
|
|
173
|
+
);
|
|
174
|
+
case 4:
|
|
175
|
+
return CurveV1Adapter4Assets__factory.createInterface().encodeFunctionData(
|
|
176
|
+
"remove_liquidity_imbalance",
|
|
177
|
+
[amounts, max_burn_amount]
|
|
178
|
+
);
|
|
179
|
+
default:
|
|
180
|
+
throw new Error("Wrong calls number: remove_liquidity_imbalance");
|
|
135
181
|
}
|
|
182
|
+
}
|
|
136
183
|
}
|
|
137
184
|
|
|
138
185
|
export class CurveMulticaller {
|
|
139
|
-
|
|
186
|
+
private readonly _address: string;
|
|
140
187
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
188
|
+
constructor(address: string) {
|
|
189
|
+
this._address = address;
|
|
190
|
+
}
|
|
144
191
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
callData: CurveCalls.exchange(i, j, dx, min_dy)
|
|
149
|
-
}
|
|
150
|
-
}
|
|
192
|
+
static connect(address: string) {
|
|
193
|
+
return new CurveMulticaller(address);
|
|
194
|
+
}
|
|
151
195
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
196
|
+
exchange(
|
|
197
|
+
i: BigNumberish,
|
|
198
|
+
j: BigNumberish,
|
|
199
|
+
dx: BigNumberish,
|
|
200
|
+
min_dy: BigNumberish
|
|
201
|
+
): MultiCallStruct {
|
|
202
|
+
return {
|
|
203
|
+
target: this._address,
|
|
204
|
+
callData: CurveCalls.exchange(i, j, dx, min_dy)
|
|
205
|
+
};
|
|
206
|
+
}
|
|
158
207
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
208
|
+
exchange_all(
|
|
209
|
+
i: BigNumberish,
|
|
210
|
+
j: BigNumberish,
|
|
211
|
+
rateMinRAY: BigNumberish
|
|
212
|
+
): MultiCallStruct {
|
|
213
|
+
return {
|
|
214
|
+
target: this._address,
|
|
215
|
+
callData: CurveCalls.exchange_all(i, j, rateMinRAY)
|
|
216
|
+
};
|
|
217
|
+
}
|
|
165
218
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
219
|
+
exchange_underlying(
|
|
220
|
+
i: BigNumberish,
|
|
221
|
+
j: BigNumberish,
|
|
222
|
+
dx: BigNumberish,
|
|
223
|
+
min_dy: BigNumberish
|
|
224
|
+
): MultiCallStruct {
|
|
225
|
+
return {
|
|
226
|
+
target: this._address,
|
|
227
|
+
callData: CurveCalls.exchange_underlying(i, j, dx, min_dy)
|
|
228
|
+
};
|
|
229
|
+
}
|
|
172
230
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
231
|
+
exchange_all_underlying(
|
|
232
|
+
i: BigNumberish,
|
|
233
|
+
j: BigNumberish,
|
|
234
|
+
rateMinRAY: BigNumberish
|
|
235
|
+
): MultiCallStruct {
|
|
236
|
+
return {
|
|
237
|
+
target: this._address,
|
|
238
|
+
callData: CurveCalls.exchange_all_underlying(i, j, rateMinRAY)
|
|
239
|
+
};
|
|
240
|
+
}
|
|
179
241
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
242
|
+
add_all_liquidity_one_coin(
|
|
243
|
+
i: BigNumberish,
|
|
244
|
+
rateMinRAY: BigNumberish
|
|
245
|
+
): MultiCallStruct {
|
|
246
|
+
return {
|
|
247
|
+
target: this._address,
|
|
248
|
+
callData: CurveCalls.add_all_liquidity_one_coin(i, rateMinRAY)
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
remove_liquidity_one_coin(
|
|
253
|
+
token_amount: BigNumberish,
|
|
254
|
+
i: BigNumberish,
|
|
255
|
+
min_amount: BigNumberish
|
|
256
|
+
) {
|
|
257
|
+
return {
|
|
258
|
+
target: this._address,
|
|
259
|
+
callData: CurveCalls.remove_liquidity_one_coin(
|
|
260
|
+
token_amount,
|
|
261
|
+
i,
|
|
262
|
+
min_amount
|
|
263
|
+
)
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
remove_all_liquidity_one_coin(i: BigNumberish, minRateRAY: BigNumberish) {
|
|
268
|
+
return {
|
|
269
|
+
target: this._address,
|
|
270
|
+
callData: CurveCalls.remove_all_liquidity_one_coin(i, minRateRAY)
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
add_liquidity(
|
|
275
|
+
amounts:
|
|
276
|
+
| [BigNumberish, BigNumberish]
|
|
277
|
+
| [BigNumberish, BigNumberish, BigNumberish]
|
|
278
|
+
| [BigNumberish, BigNumberish, BigNumberish, BigNumberish],
|
|
279
|
+
min_mint_amount: BigNumberish
|
|
280
|
+
): MultiCallStruct {
|
|
281
|
+
return {
|
|
282
|
+
target: this._address,
|
|
283
|
+
callData: CurveCalls.add_liquidity(amounts, min_mint_amount)
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
remove_liquidity(
|
|
288
|
+
amount: BigNumberish,
|
|
289
|
+
min_amounts:
|
|
290
|
+
| [BigNumberish, BigNumberish]
|
|
291
|
+
| [BigNumberish, BigNumberish, BigNumberish]
|
|
292
|
+
| [BigNumberish, BigNumberish, BigNumberish, BigNumberish]
|
|
293
|
+
): MultiCallStruct {
|
|
294
|
+
return {
|
|
295
|
+
target: this._address,
|
|
296
|
+
callData: CurveCalls.remove_liquidity(amount, min_amounts)
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
remove_liquidity_imbalance(
|
|
301
|
+
amounts:
|
|
302
|
+
| [BigNumberish, BigNumberish]
|
|
303
|
+
| [BigNumberish, BigNumberish, BigNumberish]
|
|
304
|
+
| [BigNumberish, BigNumberish, BigNumberish, BigNumberish],
|
|
305
|
+
max_burn_amount: BigNumberish
|
|
306
|
+
): MultiCallStruct {
|
|
307
|
+
return {
|
|
308
|
+
target: this._address,
|
|
309
|
+
callData: CurveCalls.remove_liquidity_imbalance(amounts, max_burn_amount)
|
|
310
|
+
};
|
|
311
|
+
}
|
|
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
|
+
);
|
|
185
337
|
}
|
|
186
338
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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]];
|
|
192
365
|
}
|
|
193
366
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
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
|
+
);
|
|
204
391
|
}
|
|
205
392
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
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]];
|
|
216
412
|
}
|
|
217
413
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
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
|
+
);
|
|
228
436
|
}
|
|
437
|
+
|
|
438
|
+
return calls;
|
|
439
|
+
}
|
|
229
440
|
}
|