@gearbox-protocol/sdk 0.0.101 → 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.
Files changed (139) 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 +7 -9
  5. package/lib/apy/lidoAPY.js +35 -29
  6. package/lib/contracts/contracts.d.ts +5 -2
  7. package/lib/contracts/contracts.js +19 -18
  8. package/lib/contracts/contractsRegister.js +13 -1
  9. package/lib/core/constants.d.ts +5 -3
  10. package/lib/core/constants.js +8 -6
  11. package/lib/core/creditAccount.d.ts +2 -2
  12. package/lib/core/creditAccount.js +12 -11
  13. package/lib/core/creditManager.d.ts +1 -1
  14. package/lib/core/creditManager.js +4 -10
  15. package/lib/core/creditSession.js +14 -3
  16. package/lib/core/eventOrTx.d.ts +1 -1
  17. package/lib/core/events.d.ts +19 -19
  18. package/lib/core/events.js +23 -21
  19. package/lib/core/pool.d.ts +1 -1
  20. package/lib/core/pool.js +1 -7
  21. package/lib/core/price.d.ts +1 -3
  22. package/lib/core/price.js +9 -7
  23. package/lib/core/strategy.d.ts +8 -6
  24. package/lib/core/strategy.js +25 -25
  25. package/lib/core/tokenDistributor.js +1 -1
  26. package/lib/core/transactions.d.ts +18 -3
  27. package/lib/core/transactions.js +39 -3
  28. package/lib/index.d.ts +8 -2
  29. package/lib/index.js +8 -1
  30. package/lib/oracles/priceFeeds.js +1 -1
  31. package/lib/pathfinder/convexLP.d.ts +1 -1
  32. package/lib/pathfinder/convexLP.js +26 -29
  33. package/lib/pathfinder/curveLP.d.ts +1 -1
  34. package/lib/pathfinder/curveLP.js +5 -7
  35. package/lib/pathfinder/path.d.ts +1 -1
  36. package/lib/pathfinder/path.js +38 -42
  37. package/lib/pathfinder/trade.d.ts +1 -2
  38. package/lib/pathfinder/tradeTypes.d.ts +5 -5
  39. package/lib/pathfinder/yVault.d.ts +2 -2
  40. package/lib/pathfinder/yVault.js +22 -22
  41. package/lib/payload/creditAccount.d.ts +4 -4
  42. package/lib/payload/creditManager.d.ts +3 -13
  43. package/lib/payload/pool.d.ts +2 -2
  44. package/lib/strategies/convex.d.ts +12 -0
  45. package/lib/strategies/convex.js +74 -1
  46. package/lib/strategies/creditFacade.d.ts +1 -0
  47. package/lib/strategies/creditFacade.js +3 -0
  48. package/lib/strategies/curve.d.ts +15 -60
  49. package/lib/strategies/curve.js +74 -1
  50. package/lib/strategies/lido.d.ts +6 -0
  51. package/lib/strategies/lido.js +23 -1
  52. package/lib/strategies/uniswapV2.d.ts +1 -0
  53. package/lib/strategies/uniswapV2.js +6 -19
  54. package/lib/strategies/uniswapV3.d.ts +1 -0
  55. package/lib/strategies/uniswapV3.js +4 -1
  56. package/lib/strategies/yearn.d.ts +8 -0
  57. package/lib/strategies/yearn.js +92 -12
  58. package/lib/tokens/convex.d.ts +3 -3
  59. package/lib/tokens/curveLP.d.ts +7 -2
  60. package/lib/tokens/curveLP.js +8 -1
  61. package/lib/tokens/gear.d.ts +2 -2
  62. package/lib/tokens/gear.js +1 -1
  63. package/lib/tokens/normal.d.ts +1 -1
  64. package/lib/tokens/token.js +8 -8
  65. package/lib/tokens/tokenData.d.ts +3 -1
  66. package/lib/tokens/tokenData.js +10 -8
  67. package/lib/tokens/yearn.d.ts +6 -2
  68. package/lib/tokens/yearn.js +6 -0
  69. package/lib/utils/errors.d.ts +6 -0
  70. package/lib/utils/errors.js +13 -0
  71. package/lib/utils/formatter.d.ts +1 -1
  72. package/lib/utils/formatter.js +17 -14
  73. package/lib/utils/loading.d.ts +2 -1
  74. package/lib/utils/loading.js +9 -13
  75. package/lib/utils/mappers.js +2 -2
  76. package/lib/utils/network.js +2 -2
  77. package/lib/utils/repeater.js +12 -24
  78. package/lib/utils/validate.js +1 -1
  79. package/package.json +24 -7
  80. package/src/apy/convexAPY.ts +13 -12
  81. package/src/apy/lidoAPY.ts +35 -27
  82. package/src/contracts/contracts.ts +27 -17
  83. package/src/contracts/contractsRegister.ts +16 -1
  84. package/src/core/constants.ts +8 -5
  85. package/src/core/creditAccount.ts +42 -16
  86. package/src/core/creditManager.ts +33 -7
  87. package/src/core/creditOperation.ts +7 -7
  88. package/src/core/creditSession.ts +25 -5
  89. package/src/core/errors.ts +1 -0
  90. package/src/core/eventOrTx.ts +8 -5
  91. package/src/core/events.ts +85 -24
  92. package/src/core/history.ts +46 -46
  93. package/src/core/operations.ts +6 -0
  94. package/src/core/pool.ts +16 -4
  95. package/src/core/price.ts +10 -13
  96. package/src/core/strategy.ts +54 -43
  97. package/src/core/tokenDistributor.ts +2 -2
  98. package/src/core/transactions.ts +427 -350
  99. package/src/index.ts +10 -3
  100. package/src/oracles/priceFeeds.ts +523 -523
  101. package/src/pathfinder/contracts.ts +15 -13
  102. package/src/pathfinder/convexLP.ts +29 -25
  103. package/src/pathfinder/curveLP.ts +57 -53
  104. package/src/pathfinder/path.ts +17 -9
  105. package/src/pathfinder/priority.ts +11 -11
  106. package/src/pathfinder/trade.ts +84 -77
  107. package/src/pathfinder/tradeTypes.ts +98 -94
  108. package/src/pathfinder/yVault.ts +32 -17
  109. package/src/payload/creditAccount.ts +4 -4
  110. package/src/payload/creditManager.ts +3 -13
  111. package/src/payload/pool.ts +2 -2
  112. package/src/payload/token.ts +3 -3
  113. package/src/strategies/convex.ts +360 -186
  114. package/src/strategies/creditFacade.ts +74 -53
  115. package/src/strategies/curve.ts +400 -189
  116. package/src/strategies/lido.ts +70 -32
  117. package/src/strategies/uniswapV2.ts +93 -111
  118. package/src/strategies/uniswapV3.ts +118 -91
  119. package/src/strategies/yearn.ts +187 -60
  120. package/src/tokens/connectors.ts +6 -6
  121. package/src/tokens/convex.ts +297 -296
  122. package/src/tokens/curveLP.ts +176 -165
  123. package/src/tokens/gear.ts +47 -45
  124. package/src/tokens/normal.ts +801 -802
  125. package/src/tokens/token.ts +13 -9
  126. package/src/tokens/tokenData.ts +19 -9
  127. package/src/tokens/tokenType.ts +11 -11
  128. package/src/tokens/yearn.ts +130 -124
  129. package/src/utils/errors.ts +11 -0
  130. package/src/utils/formatter.ts +22 -18
  131. package/src/utils/loading.ts +14 -6
  132. package/src/utils/mappers.ts +8 -6
  133. package/src/utils/multicall.ts +2 -0
  134. package/src/utils/network.ts +21 -21
  135. package/src/utils/repeater.ts +2 -2
  136. package/src/utils/validate.ts +1 -1
  137. package/lib/utils/events.d.ts +0 -2
  138. package/lib/utils/events.js +0 -13
  139. package/src/utils/events.ts +0 -10
@@ -1,229 +1,440 @@
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
- CurveV1AdapterBase__factory,
5
- CurveV1Adapter2Assets__factory,
6
- CurveV1Adapter3Assets__factory,
7
- CurveV1Adapter4Assets__factory
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
- public static exchange(i: BigNumberish, j: BigNumberish, dx: BigNumberish, min_dy: BigNumberish) {
14
- return CurveV1AdapterBase__factory.createInterface().encodeFunctionData(
15
- "exchange",
16
- [i, j, dx, min_dy]
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
- public static exchange_all(i: BigNumberish, j: BigNumberish, rateMinRAY: BigNumberish) {
21
- return CurveV1AdapterBase__factory.createInterface().encodeFunctionData(
22
- "exchange_all",
23
- [i, j, rateMinRAY]
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
- public static exchange_underlying(i: BigNumberish, j: BigNumberish, dx: BigNumberish, min_dy: BigNumberish) {
28
- return CurveV1AdapterBase__factory.createInterface().encodeFunctionData(
29
- "exchange_underlying",
30
- [i, j, dx, min_dy]
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
- public static exchange_all_underlying(i: BigNumberish, j: BigNumberish, rateMinRAY: BigNumberish) {
35
- return CurveV1AdapterBase__factory.createInterface().encodeFunctionData(
36
- "exchange_all_underlying",
37
- [i, j, rateMinRAY]
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
- public static add_all_liquidity_one_coin(i: BigNumberish, rateMinRAY: BigNumberish) {
42
- return CurveV1AdapterBase__factory.createInterface().encodeFunctionData(
43
- "add_all_liquidity_one_coin",
44
- [i, rateMinRAY]
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
- public static remove_liquidity_one_coin(token_amount: BigNumberish, i: BigNumberish, min_amount: BigNumberish) {
49
- return CurveV1AdapterBase__factory.createInterface().encodeFunctionData(
50
- "remove_liquidity_one_coin",
51
- [token_amount, i, min_amount]
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
- public static remove_all_liquidity_one_coin(i: BigNumberish, minRateRAY: BigNumberish) {
56
- return CurveV1AdapterBase__factory.createInterface().encodeFunctionData(
57
- "remove_all_liquidity_one_coin",
58
- [i, minRateRAY]
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
- public static add_liquidity(
63
- amounts: [BigNumberish, BigNumberish] |
64
- [BigNumberish, BigNumberish, BigNumberish] |
65
- [BigNumberish, BigNumberish, BigNumberish, BigNumberish],
66
- min_mint_amount: BigNumberish
67
- ): string {
68
- switch (amounts.length) {
69
- case 2:
70
- return CurveV1Adapter2Assets__factory.createInterface().encodeFunctionData(
71
- "add_liquidity",
72
- [amounts, min_mint_amount]
73
- );
74
- case 3:
75
- return CurveV1Adapter3Assets__factory.createInterface().encodeFunctionData(
76
- "add_liquidity",
77
- [amounts, min_mint_amount]
78
- );
79
- case 4:
80
- return CurveV1Adapter4Assets__factory.createInterface().encodeFunctionData(
81
- "add_liquidity",
82
- [amounts, min_mint_amount]
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
- public static remove_liquidity(
88
- amount: BigNumberish,
89
- min_amounts: [BigNumberish, BigNumberish] |
90
- [BigNumberish, BigNumberish, BigNumberish] |
91
- [BigNumberish, BigNumberish, BigNumberish, BigNumberish]
92
- ) {
93
- switch (min_amounts.length) {
94
- case 2:
95
- return CurveV1Adapter2Assets__factory.createInterface().encodeFunctionData(
96
- "remove_liquidity",
97
- [amount, min_amounts]
98
- );
99
- case 3:
100
- return CurveV1Adapter3Assets__factory.createInterface().encodeFunctionData(
101
- "remove_liquidity",
102
- [amount, min_amounts]
103
- );
104
- case 4:
105
- return CurveV1Adapter4Assets__factory.createInterface().encodeFunctionData(
106
- "remove_liquidity",
107
- [amount, min_amounts]
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
- public static remove_liquidity_imbalance(
113
- amounts: [BigNumberish, BigNumberish] |
114
- [BigNumberish, BigNumberish, BigNumberish] |
115
- [BigNumberish, BigNumberish, BigNumberish, BigNumberish],
116
- max_burn_amount: BigNumberish
117
- ) {
118
- switch (amounts.length) {
119
- case 2:
120
- return CurveV1Adapter2Assets__factory.createInterface().encodeFunctionData(
121
- "remove_liquidity_imbalance",
122
- [amounts, max_burn_amount]
123
- );
124
- case 3:
125
- return CurveV1Adapter3Assets__factory.createInterface().encodeFunctionData(
126
- "remove_liquidity_imbalance",
127
- [amounts, max_burn_amount]
128
- );
129
- case 4:
130
- return CurveV1Adapter4Assets__factory.createInterface().encodeFunctionData(
131
- "remove_liquidity_imbalance",
132
- [amounts, max_burn_amount]
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
- private readonly _address: string;
186
+ private readonly _address: string;
140
187
 
141
- constructor(address: string) {
142
- this._address = address;
143
- }
188
+ constructor(address: string) {
189
+ this._address = address;
190
+ }
144
191
 
145
- exchange(i: BigNumberish, j: BigNumberish, dx: BigNumberish, min_dy: BigNumberish): MultiCallStruct {
146
- return {
147
- target: this._address,
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
- exchange_all(i: BigNumberish, j: BigNumberish, rateMinRAY: BigNumberish): MultiCallStruct {
153
- return {
154
- target: this._address,
155
- callData: CurveCalls.exchange_all(i, j, rateMinRAY)
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
- exchange_underlying(i: BigNumberish, j: BigNumberish, dx: BigNumberish, min_dy: BigNumberish): MultiCallStruct {
160
- return {
161
- target: this._address,
162
- callData: CurveCalls.exchange_underlying(i, j, dx, min_dy)
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
- exchange_all_underlying(i: BigNumberish, j: BigNumberish, rateMinRAY: BigNumberish): MultiCallStruct {
167
- return {
168
- target: this._address,
169
- callData: CurveCalls.exchange_all_underlying(i, j, rateMinRAY)
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
- add_all_liquidity_one_coin(i: BigNumberish, rateMinRAY: BigNumberish): MultiCallStruct {
174
- return {
175
- target: this._address,
176
- callData: CurveCalls.add_all_liquidity_one_coin(i, rateMinRAY)
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
- remove_liquidity_one_coin(token_amount: BigNumberish, i: BigNumberish, min_amount: BigNumberish) {
181
- return {
182
- target: this._address,
183
- callData: CurveCalls.remove_liquidity_one_coin(token_amount, i, min_amount)
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
- remove_all_liquidity_one_coin(i: BigNumberish, minRateRAY: BigNumberish) {
188
- return {
189
- target: this._address,
190
- callData: CurveCalls.remove_all_liquidity_one_coin(i, minRateRAY)
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
- add_liquidity(
195
- amounts: [BigNumberish, BigNumberish] |
196
- [BigNumberish, BigNumberish, BigNumberish] |
197
- [BigNumberish, BigNumberish, BigNumberish, BigNumberish],
198
- min_mint_amount: BigNumberish
199
- ): MultiCallStruct {
200
- return {
201
- target: this._address,
202
- callData: CurveCalls.add_liquidity(amounts, min_mint_amount)
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
- remove_liquidity(
207
- amount: BigNumberish,
208
- min_amounts: [BigNumberish, BigNumberish] |
209
- [BigNumberish, BigNumberish, BigNumberish] |
210
- [BigNumberish, BigNumberish, BigNumberish, BigNumberish]
211
- ): MultiCallStruct {
212
- return {
213
- target: this._address,
214
- callData: CurveCalls.remove_liquidity(amount, min_amounts)
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
- remove_liquidity_imbalance(
219
- amounts: [BigNumberish, BigNumberish] |
220
- [BigNumberish, BigNumberish, BigNumberish] |
221
- [BigNumberish, BigNumberish, BigNumberish, BigNumberish],
222
- max_burn_amount: BigNumberish
223
- ): MultiCallStruct {
224
- return {
225
- target: this._address,
226
- callData: CurveCalls.remove_liquidity_imbalance(amounts, max_burn_amount)
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
  }