@defisaver/automation-sdk 3.1.10 → 3.1.14-spark-dev
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/cjs/automation/private/StrategiesAutomation.d.ts +5 -3
- package/cjs/automation/private/StrategiesAutomation.js +27 -10
- package/cjs/automation/private/StrategiesAutomation.test.js +25 -0
- package/cjs/constants/index.d.ts +1 -0
- package/cjs/constants/index.js +352 -11
- package/cjs/index.d.ts +2 -1
- package/cjs/index.js +1 -1
- package/cjs/services/ethereumService.js +21 -14
- package/cjs/services/ethereumService.test.js +3 -0
- package/cjs/services/strategiesService.js +329 -54
- package/cjs/services/strategiesService.test.js +1 -0
- package/cjs/services/strategySubService.d.ts +24 -5
- package/cjs/services/strategySubService.js +116 -10
- package/cjs/services/strategySubService.test.js +1049 -173
- package/cjs/services/subDataService.d.ts +361 -88
- package/cjs/services/subDataService.js +799 -249
- package/cjs/services/subDataService.test.js +1287 -142
- package/cjs/services/triggerService.d.ts +100 -9
- package/cjs/services/triggerService.js +188 -19
- package/cjs/services/triggerService.test.js +437 -46
- package/cjs/services/utils.d.ts +1 -1
- package/cjs/services/utils.js +10 -2
- package/cjs/services/utils.test.js +0 -77
- package/cjs/types/enums.d.ts +88 -12
- package/cjs/types/enums.js +78 -2
- package/cjs/types/index.d.ts +59 -1
- package/esm/automation/private/StrategiesAutomation.d.ts +5 -3
- package/esm/automation/private/StrategiesAutomation.js +27 -10
- package/esm/automation/private/StrategiesAutomation.test.js +25 -0
- package/esm/constants/index.d.ts +1 -0
- package/esm/constants/index.js +351 -10
- package/esm/index.d.ts +2 -1
- package/esm/index.js +2 -2
- package/esm/services/ethereumService.js +21 -14
- package/esm/services/ethereumService.test.js +3 -0
- package/esm/services/strategiesService.js +330 -55
- package/esm/services/strategiesService.test.js +1 -0
- package/esm/services/strategySubService.d.ts +24 -5
- package/esm/services/strategySubService.js +115 -9
- package/esm/services/strategySubService.test.js +1052 -176
- package/esm/services/subDataService.d.ts +361 -88
- package/esm/services/subDataService.js +799 -249
- package/esm/services/subDataService.test.js +1288 -143
- package/esm/services/triggerService.d.ts +100 -9
- package/esm/services/triggerService.js +187 -18
- package/esm/services/triggerService.test.js +438 -47
- package/esm/services/utils.d.ts +1 -1
- package/esm/services/utils.js +10 -2
- package/esm/services/utils.test.js +1 -52
- package/esm/types/enums.d.ts +88 -12
- package/esm/types/enums.js +78 -2
- package/esm/types/index.d.ts +59 -1
- package/package.json +4 -5
- package/src/automation/private/StrategiesAutomation.test.ts +40 -0
- package/src/automation/private/StrategiesAutomation.ts +38 -15
- package/src/constants/index.ts +353 -11
- package/src/index.ts +4 -2
- package/src/services/ethereumService.test.ts +3 -0
- package/src/services/ethereumService.ts +23 -16
- package/src/services/strategiesService.test.ts +1 -0
- package/src/services/strategiesService.ts +387 -72
- package/src/services/strategySubService.test.ts +1330 -316
- package/src/services/strategySubService.ts +365 -12
- package/src/services/subDataService.test.ts +1413 -170
- package/src/services/subDataService.ts +1148 -431
- package/src/services/triggerService.test.ts +482 -52
- package/src/services/triggerService.ts +272 -27
- package/src/services/utils.test.ts +0 -59
- package/src/services/utils.ts +15 -4
- package/src/types/enums.ts +78 -2
- package/src/types/index.ts +74 -1
- package/umd/index.js +0 -34219
package/esm/types/enums.d.ts
CHANGED
|
@@ -56,6 +56,7 @@ export declare namespace ProtocolIdentifiers {
|
|
|
56
56
|
CompoundV3 = "Compound__V3",
|
|
57
57
|
AaveV2 = "Aave__V2",
|
|
58
58
|
AaveV3 = "Aave__V3",
|
|
59
|
+
AaveV4 = "Aave__V4",
|
|
59
60
|
MorphoAaveV2 = "Morpho-Aave__V2",
|
|
60
61
|
Exchange = "Exchange",
|
|
61
62
|
Spark = "Spark",
|
|
@@ -85,19 +86,26 @@ export declare namespace Strategies {
|
|
|
85
86
|
LIQUITY_DSR_SUPPLY = 70,
|
|
86
87
|
LIQUITY_DEBT_IN_FRONT_REPAY = 75,
|
|
87
88
|
CURVEUSD_PAYBACK = 92,
|
|
88
|
-
LIQUITY_V2_PAYBACK = 113
|
|
89
|
+
LIQUITY_V2_PAYBACK = 113,
|
|
90
|
+
AAVE_V3_COLLATERAL_SWITCH = 135,
|
|
91
|
+
AAVE_V4_COLLATERAL_SWITCH = 154,
|
|
92
|
+
AAVE_V4_COLLATERAL_SWITCH_EOA = 155,
|
|
93
|
+
SPARK_COLLATERAL_SWITCH = 156
|
|
89
94
|
}
|
|
90
95
|
enum OptimismIds {
|
|
91
96
|
EXCHANGE_DCA = 8,
|
|
92
|
-
EXCHANGE_LIMIT_ORDER = 9
|
|
97
|
+
EXCHANGE_LIMIT_ORDER = 9,
|
|
98
|
+
AAVE_V3_COLLATERAL_SWITCH = 24
|
|
93
99
|
}
|
|
94
100
|
enum BaseIds {
|
|
95
101
|
EXCHANGE_DCA = 8,
|
|
96
|
-
EXCHANGE_LIMIT_ORDER = 9
|
|
102
|
+
EXCHANGE_LIMIT_ORDER = 9,
|
|
103
|
+
AAVE_V3_COLLATERAL_SWITCH = 56
|
|
97
104
|
}
|
|
98
105
|
enum ArbitrumIds {
|
|
99
106
|
EXCHANGE_DCA = 8,
|
|
100
|
-
EXCHANGE_LIMIT_ORDER = 9
|
|
107
|
+
EXCHANGE_LIMIT_ORDER = 9,
|
|
108
|
+
AAVE_V3_COLLATERAL_SWITCH = 50
|
|
101
109
|
}
|
|
102
110
|
enum Identifiers {
|
|
103
111
|
SavingsLiqProtection = "smart-savings-liquidation-protection",
|
|
@@ -114,6 +122,7 @@ export declare namespace Strategies {
|
|
|
114
122
|
CloseOnPriceToDebt = "close-on-price-to-debt",
|
|
115
123
|
CloseOnPriceToColl = "close-on-price-to-collateral",
|
|
116
124
|
CloseOnPrice = "close-on-price",
|
|
125
|
+
EoaCloseOnPrice = "eoa-close-on-price",
|
|
117
126
|
TrailingStopToColl = "trailing-stop-to-collateral",
|
|
118
127
|
TrailingStopToDebt = "trailing-stop-to-debt",
|
|
119
128
|
Rebond = "rebond",
|
|
@@ -125,7 +134,11 @@ export declare namespace Strategies {
|
|
|
125
134
|
OpenOrderFromCollateral = "open-order-from-collateral",
|
|
126
135
|
OpenOrderFromDebt = "open-order-from-debt",
|
|
127
136
|
BoostOnPrice = "boost-on-price",
|
|
128
|
-
RepayOnPrice = "repay-on-price"
|
|
137
|
+
RepayOnPrice = "repay-on-price",
|
|
138
|
+
EoaBoostOnPrice = "eoa-boost-on-price",
|
|
139
|
+
EoaRepayOnPrice = "eoa-repay-on-price",
|
|
140
|
+
CollateralSwitch = "collateral-switch",
|
|
141
|
+
EoaCollateralSwitch = "eoa-collateral-switch"
|
|
129
142
|
}
|
|
130
143
|
enum IdOverrides {
|
|
131
144
|
TakeProfit = "take-profit",
|
|
@@ -134,7 +147,9 @@ export declare namespace Strategies {
|
|
|
134
147
|
StopLossWithGasPrice = "stop-loss-with-gas-price",
|
|
135
148
|
TrailingStop = "trailing-stop",
|
|
136
149
|
LeverageManagement = "leverage-management",
|
|
137
|
-
EoaLeverageManagement = "leverage-management-eoa"
|
|
150
|
+
EoaLeverageManagement = "leverage-management-eoa",
|
|
151
|
+
LeverageManagementOnPrice = "leverage-management-on-price",
|
|
152
|
+
EoaLeverageManagementOnPrice = "leverage-management-on-price-eoa"
|
|
138
153
|
}
|
|
139
154
|
}
|
|
140
155
|
export declare namespace Bundles {
|
|
@@ -161,8 +176,6 @@ export declare namespace Bundles {
|
|
|
161
176
|
LIQUITY_BOOST = 17,
|
|
162
177
|
SPARK_REPAY = 18,
|
|
163
178
|
SPARK_BOOST = 19,
|
|
164
|
-
SPARK_CLOSE_TO_DEBT = -21231230,
|
|
165
|
-
SPARK_CLOSE_TO_COLLATERAL = -21231231,
|
|
166
179
|
AAVE_V2_REPAY = 22,
|
|
167
180
|
AAVE_V2_BOOST = 23,
|
|
168
181
|
COMP_V2_REPAY = 20,
|
|
@@ -186,7 +199,32 @@ export declare namespace Bundles {
|
|
|
186
199
|
LIQUITY_V2_REPAY_ON_PRICE = 42,
|
|
187
200
|
LIQUITY_V2_BOOST_ON_PRICE = 43,
|
|
188
201
|
FLUID_T1_REPAY = 44,
|
|
189
|
-
FLUID_T1_BOOST = 45
|
|
202
|
+
FLUID_T1_BOOST = 45,
|
|
203
|
+
COMP_V3_SW_REPAY_ON_PRICE = 46,
|
|
204
|
+
COMP_V3_SW_BOOST_ON_PRICE = 47,
|
|
205
|
+
COMP_V3_SW_CLOSE = 48,
|
|
206
|
+
COMP_V3_EOA_REPAY_ON_PRICE = 49,
|
|
207
|
+
COMP_V3_EOA_BOOST_ON_PRICE = 50,
|
|
208
|
+
COMP_V3_EOA_CLOSE = 51,
|
|
209
|
+
AAVE_V3_EOA_REPAY = 52,
|
|
210
|
+
AAVE_V3_EOA_BOOST = 53,
|
|
211
|
+
AAVE_V3_EOA_REPAY_ON_PRICE = 54,
|
|
212
|
+
AAVE_V3_EOA_BOOST_ON_PRICE = 55,
|
|
213
|
+
AAVE_V3_EOA_CLOSE = 56,
|
|
214
|
+
SPARK_CLOSE = 57,
|
|
215
|
+
MORPHO_BLUE_CLOSE = 58,
|
|
216
|
+
SPARK_REPAY_ON_PRICE = 59,
|
|
217
|
+
SPARK_BOOST_ON_PRICE = 60,
|
|
218
|
+
AAVE_V4_REPAY = 61,
|
|
219
|
+
AAVE_V4_BOOST = 62,
|
|
220
|
+
AAVE_V4_REPAY_ON_PRICE = 63,
|
|
221
|
+
AAVE_V4_BOOST_ON_PRICE = 64,
|
|
222
|
+
AAVE_V4_CLOSE = 65,
|
|
223
|
+
AAVE_V4_EOA_REPAY = 66,
|
|
224
|
+
AAVE_V4_EOA_BOOST = 67,
|
|
225
|
+
AAVE_V4_EOA_REPAY_ON_PRICE = 68,
|
|
226
|
+
AAVE_V4_EOA_BOOST_ON_PRICE = 69,
|
|
227
|
+
AAVE_V4_EOA_CLOSE = 70
|
|
190
228
|
}
|
|
191
229
|
enum OptimismIds {
|
|
192
230
|
AAVE_V3_REPAY = 0,
|
|
@@ -194,7 +232,12 @@ export declare namespace Bundles {
|
|
|
194
232
|
AAVE_V3_CLOSE_TO_DEBT = 2,
|
|
195
233
|
AAVE_V3_CLOSE_TO_COLLATERAL = 3,
|
|
196
234
|
AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 4,
|
|
197
|
-
AAVE_V3_REPAY_ON_PRICE = 5
|
|
235
|
+
AAVE_V3_REPAY_ON_PRICE = 5,
|
|
236
|
+
AAVE_V3_EOA_REPAY = 6,
|
|
237
|
+
AAVE_V3_EOA_BOOST = 7,
|
|
238
|
+
AAVE_V3_EOA_REPAY_ON_PRICE = 8,
|
|
239
|
+
AAVE_V3_EOA_BOOST_ON_PRICE = 9,
|
|
240
|
+
AAVE_V3_EOA_CLOSE = 10
|
|
198
241
|
}
|
|
199
242
|
enum BaseIds {
|
|
200
243
|
AAVE_V3_REPAY = 0,
|
|
@@ -209,7 +252,21 @@ export declare namespace Bundles {
|
|
|
209
252
|
AAVE_V3_REPAY_ON_PRICE = 11,
|
|
210
253
|
MORPHO_BLUE_BOOST_ON_PRICE = 12,
|
|
211
254
|
FLUID_T1_REPAY = 13,
|
|
212
|
-
FLUID_T1_BOOST = 14
|
|
255
|
+
FLUID_T1_BOOST = 14,
|
|
256
|
+
COMP_V3_SW_REPAY_ON_PRICE = 15,
|
|
257
|
+
COMP_V3_SW_BOOST_ON_PRICE = 16,
|
|
258
|
+
COMP_V3_SW_CLOSE = 17,
|
|
259
|
+
COMP_V3_EOA_REPAY_ON_PRICE = 18,
|
|
260
|
+
COMP_V3_EOA_BOOST_ON_PRICE = 19,
|
|
261
|
+
COMP_V3_EOA_CLOSE = 20,
|
|
262
|
+
COMP_V3_EOA_REPAY = 21,
|
|
263
|
+
COMP_V3_EOA_BOOST = 22,
|
|
264
|
+
AAVE_V3_EOA_REPAY = 23,
|
|
265
|
+
AAVE_V3_EOA_BOOST = 24,
|
|
266
|
+
AAVE_V3_EOA_REPAY_ON_PRICE = 25,
|
|
267
|
+
AAVE_V3_EOA_BOOST_ON_PRICE = 26,
|
|
268
|
+
AAVE_V3_EOA_CLOSE = 27,
|
|
269
|
+
MORPHO_BLUE_CLOSE = 28
|
|
213
270
|
}
|
|
214
271
|
enum ArbitrumIds {
|
|
215
272
|
AAVE_V3_REPAY = 0,
|
|
@@ -221,6 +278,25 @@ export declare namespace Bundles {
|
|
|
221
278
|
AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 6,
|
|
222
279
|
AAVE_V3_REPAY_ON_PRICE = 7,
|
|
223
280
|
FLUID_T1_REPAY = 8,
|
|
224
|
-
FLUID_T1_BOOST = 9
|
|
281
|
+
FLUID_T1_BOOST = 9,
|
|
282
|
+
COMP_V3_SW_REPAY_ON_PRICE = 10,
|
|
283
|
+
COMP_V3_SW_BOOST_ON_PRICE = 11,
|
|
284
|
+
COMP_V3_SW_CLOSE = 12,
|
|
285
|
+
COMP_V3_EOA_REPAY_ON_PRICE = 13,
|
|
286
|
+
COMP_V3_EOA_BOOST_ON_PRICE = 14,
|
|
287
|
+
COMP_V3_EOA_CLOSE = 15,
|
|
288
|
+
COMP_V3_EOA_REPAY = 16,
|
|
289
|
+
COMP_V3_EOA_BOOST = 17,
|
|
290
|
+
AAVE_V3_EOA_REPAY = 18,
|
|
291
|
+
AAVE_V3_EOA_BOOST = 19,
|
|
292
|
+
AAVE_V3_EOA_REPAY_ON_PRICE = 20,
|
|
293
|
+
AAVE_V3_EOA_BOOST_ON_PRICE = 21,
|
|
294
|
+
AAVE_V3_EOA_CLOSE = 22,
|
|
295
|
+
MORPHO_BLUE_REPAY = 23,
|
|
296
|
+
MORPHO_BLUE_BOOST = 24,
|
|
297
|
+
MORPHO_BLUE_BOOST_ON_PRICE = 25,
|
|
298
|
+
MORPHO_BLUE_EOA_REPAY = 26,
|
|
299
|
+
MORPHO_BLUE_EOA_BOOST = 27,
|
|
300
|
+
MORPHO_BLUE_CLOSE = 28
|
|
225
301
|
}
|
|
226
302
|
}
|
package/esm/types/enums.js
CHANGED
|
@@ -66,6 +66,7 @@ export var ProtocolIdentifiers;
|
|
|
66
66
|
StrategiesAutomation["CompoundV3"] = "Compound__V3";
|
|
67
67
|
StrategiesAutomation["AaveV2"] = "Aave__V2";
|
|
68
68
|
StrategiesAutomation["AaveV3"] = "Aave__V3";
|
|
69
|
+
StrategiesAutomation["AaveV4"] = "Aave__V4";
|
|
69
70
|
StrategiesAutomation["MorphoAaveV2"] = "Morpho-Aave__V2";
|
|
70
71
|
StrategiesAutomation["Exchange"] = "Exchange";
|
|
71
72
|
StrategiesAutomation["Spark"] = "Spark";
|
|
@@ -99,21 +100,28 @@ export var Strategies;
|
|
|
99
100
|
MainnetIds[MainnetIds["LIQUITY_DEBT_IN_FRONT_REPAY"] = 75] = "LIQUITY_DEBT_IN_FRONT_REPAY";
|
|
100
101
|
MainnetIds[MainnetIds["CURVEUSD_PAYBACK"] = 92] = "CURVEUSD_PAYBACK";
|
|
101
102
|
MainnetIds[MainnetIds["LIQUITY_V2_PAYBACK"] = 113] = "LIQUITY_V2_PAYBACK";
|
|
103
|
+
MainnetIds[MainnetIds["AAVE_V3_COLLATERAL_SWITCH"] = 135] = "AAVE_V3_COLLATERAL_SWITCH";
|
|
104
|
+
MainnetIds[MainnetIds["AAVE_V4_COLLATERAL_SWITCH"] = 154] = "AAVE_V4_COLLATERAL_SWITCH";
|
|
105
|
+
MainnetIds[MainnetIds["AAVE_V4_COLLATERAL_SWITCH_EOA"] = 155] = "AAVE_V4_COLLATERAL_SWITCH_EOA";
|
|
106
|
+
MainnetIds[MainnetIds["SPARK_COLLATERAL_SWITCH"] = 156] = "SPARK_COLLATERAL_SWITCH";
|
|
102
107
|
})(MainnetIds = Strategies.MainnetIds || (Strategies.MainnetIds = {}));
|
|
103
108
|
let OptimismIds;
|
|
104
109
|
(function (OptimismIds) {
|
|
105
110
|
OptimismIds[OptimismIds["EXCHANGE_DCA"] = 8] = "EXCHANGE_DCA";
|
|
106
111
|
OptimismIds[OptimismIds["EXCHANGE_LIMIT_ORDER"] = 9] = "EXCHANGE_LIMIT_ORDER";
|
|
112
|
+
OptimismIds[OptimismIds["AAVE_V3_COLLATERAL_SWITCH"] = 24] = "AAVE_V3_COLLATERAL_SWITCH";
|
|
107
113
|
})(OptimismIds = Strategies.OptimismIds || (Strategies.OptimismIds = {}));
|
|
108
114
|
let BaseIds;
|
|
109
115
|
(function (BaseIds) {
|
|
110
116
|
BaseIds[BaseIds["EXCHANGE_DCA"] = 8] = "EXCHANGE_DCA";
|
|
111
117
|
BaseIds[BaseIds["EXCHANGE_LIMIT_ORDER"] = 9] = "EXCHANGE_LIMIT_ORDER";
|
|
118
|
+
BaseIds[BaseIds["AAVE_V3_COLLATERAL_SWITCH"] = 56] = "AAVE_V3_COLLATERAL_SWITCH";
|
|
112
119
|
})(BaseIds = Strategies.BaseIds || (Strategies.BaseIds = {}));
|
|
113
120
|
let ArbitrumIds;
|
|
114
121
|
(function (ArbitrumIds) {
|
|
115
122
|
ArbitrumIds[ArbitrumIds["EXCHANGE_DCA"] = 8] = "EXCHANGE_DCA";
|
|
116
123
|
ArbitrumIds[ArbitrumIds["EXCHANGE_LIMIT_ORDER"] = 9] = "EXCHANGE_LIMIT_ORDER";
|
|
124
|
+
ArbitrumIds[ArbitrumIds["AAVE_V3_COLLATERAL_SWITCH"] = 50] = "AAVE_V3_COLLATERAL_SWITCH";
|
|
117
125
|
})(ArbitrumIds = Strategies.ArbitrumIds || (Strategies.ArbitrumIds = {}));
|
|
118
126
|
let Identifiers;
|
|
119
127
|
(function (Identifiers) {
|
|
@@ -131,6 +139,7 @@ export var Strategies;
|
|
|
131
139
|
Identifiers["CloseOnPriceToDebt"] = "close-on-price-to-debt";
|
|
132
140
|
Identifiers["CloseOnPriceToColl"] = "close-on-price-to-collateral";
|
|
133
141
|
Identifiers["CloseOnPrice"] = "close-on-price";
|
|
142
|
+
Identifiers["EoaCloseOnPrice"] = "eoa-close-on-price";
|
|
134
143
|
Identifiers["TrailingStopToColl"] = "trailing-stop-to-collateral";
|
|
135
144
|
Identifiers["TrailingStopToDebt"] = "trailing-stop-to-debt";
|
|
136
145
|
Identifiers["Rebond"] = "rebond";
|
|
@@ -143,6 +152,10 @@ export var Strategies;
|
|
|
143
152
|
Identifiers["OpenOrderFromDebt"] = "open-order-from-debt";
|
|
144
153
|
Identifiers["BoostOnPrice"] = "boost-on-price";
|
|
145
154
|
Identifiers["RepayOnPrice"] = "repay-on-price";
|
|
155
|
+
Identifiers["EoaBoostOnPrice"] = "eoa-boost-on-price";
|
|
156
|
+
Identifiers["EoaRepayOnPrice"] = "eoa-repay-on-price";
|
|
157
|
+
Identifiers["CollateralSwitch"] = "collateral-switch";
|
|
158
|
+
Identifiers["EoaCollateralSwitch"] = "eoa-collateral-switch";
|
|
146
159
|
})(Identifiers = Strategies.Identifiers || (Strategies.Identifiers = {}));
|
|
147
160
|
let IdOverrides;
|
|
148
161
|
(function (IdOverrides) {
|
|
@@ -153,6 +166,8 @@ export var Strategies;
|
|
|
153
166
|
IdOverrides["TrailingStop"] = "trailing-stop";
|
|
154
167
|
IdOverrides["LeverageManagement"] = "leverage-management";
|
|
155
168
|
IdOverrides["EoaLeverageManagement"] = "leverage-management-eoa";
|
|
169
|
+
IdOverrides["LeverageManagementOnPrice"] = "leverage-management-on-price";
|
|
170
|
+
IdOverrides["EoaLeverageManagementOnPrice"] = "leverage-management-on-price-eoa";
|
|
156
171
|
})(IdOverrides = Strategies.IdOverrides || (Strategies.IdOverrides = {}));
|
|
157
172
|
})(Strategies || (Strategies = {}));
|
|
158
173
|
export var Bundles;
|
|
@@ -181,8 +196,6 @@ export var Bundles;
|
|
|
181
196
|
MainnetIds[MainnetIds["LIQUITY_BOOST"] = 17] = "LIQUITY_BOOST";
|
|
182
197
|
MainnetIds[MainnetIds["SPARK_REPAY"] = 18] = "SPARK_REPAY";
|
|
183
198
|
MainnetIds[MainnetIds["SPARK_BOOST"] = 19] = "SPARK_BOOST";
|
|
184
|
-
MainnetIds[MainnetIds["SPARK_CLOSE_TO_DEBT"] = -21231230] = "SPARK_CLOSE_TO_DEBT";
|
|
185
|
-
MainnetIds[MainnetIds["SPARK_CLOSE_TO_COLLATERAL"] = -21231231] = "SPARK_CLOSE_TO_COLLATERAL";
|
|
186
199
|
MainnetIds[MainnetIds["AAVE_V2_REPAY"] = 22] = "AAVE_V2_REPAY";
|
|
187
200
|
MainnetIds[MainnetIds["AAVE_V2_BOOST"] = 23] = "AAVE_V2_BOOST";
|
|
188
201
|
MainnetIds[MainnetIds["COMP_V2_REPAY"] = 20] = "COMP_V2_REPAY";
|
|
@@ -207,6 +220,31 @@ export var Bundles;
|
|
|
207
220
|
MainnetIds[MainnetIds["LIQUITY_V2_BOOST_ON_PRICE"] = 43] = "LIQUITY_V2_BOOST_ON_PRICE";
|
|
208
221
|
MainnetIds[MainnetIds["FLUID_T1_REPAY"] = 44] = "FLUID_T1_REPAY";
|
|
209
222
|
MainnetIds[MainnetIds["FLUID_T1_BOOST"] = 45] = "FLUID_T1_BOOST";
|
|
223
|
+
MainnetIds[MainnetIds["COMP_V3_SW_REPAY_ON_PRICE"] = 46] = "COMP_V3_SW_REPAY_ON_PRICE";
|
|
224
|
+
MainnetIds[MainnetIds["COMP_V3_SW_BOOST_ON_PRICE"] = 47] = "COMP_V3_SW_BOOST_ON_PRICE";
|
|
225
|
+
MainnetIds[MainnetIds["COMP_V3_SW_CLOSE"] = 48] = "COMP_V3_SW_CLOSE";
|
|
226
|
+
MainnetIds[MainnetIds["COMP_V3_EOA_REPAY_ON_PRICE"] = 49] = "COMP_V3_EOA_REPAY_ON_PRICE";
|
|
227
|
+
MainnetIds[MainnetIds["COMP_V3_EOA_BOOST_ON_PRICE"] = 50] = "COMP_V3_EOA_BOOST_ON_PRICE";
|
|
228
|
+
MainnetIds[MainnetIds["COMP_V3_EOA_CLOSE"] = 51] = "COMP_V3_EOA_CLOSE";
|
|
229
|
+
MainnetIds[MainnetIds["AAVE_V3_EOA_REPAY"] = 52] = "AAVE_V3_EOA_REPAY";
|
|
230
|
+
MainnetIds[MainnetIds["AAVE_V3_EOA_BOOST"] = 53] = "AAVE_V3_EOA_BOOST";
|
|
231
|
+
MainnetIds[MainnetIds["AAVE_V3_EOA_REPAY_ON_PRICE"] = 54] = "AAVE_V3_EOA_REPAY_ON_PRICE";
|
|
232
|
+
MainnetIds[MainnetIds["AAVE_V3_EOA_BOOST_ON_PRICE"] = 55] = "AAVE_V3_EOA_BOOST_ON_PRICE";
|
|
233
|
+
MainnetIds[MainnetIds["AAVE_V3_EOA_CLOSE"] = 56] = "AAVE_V3_EOA_CLOSE";
|
|
234
|
+
MainnetIds[MainnetIds["SPARK_CLOSE"] = 57] = "SPARK_CLOSE";
|
|
235
|
+
MainnetIds[MainnetIds["MORPHO_BLUE_CLOSE"] = 58] = "MORPHO_BLUE_CLOSE";
|
|
236
|
+
MainnetIds[MainnetIds["SPARK_REPAY_ON_PRICE"] = 59] = "SPARK_REPAY_ON_PRICE";
|
|
237
|
+
MainnetIds[MainnetIds["SPARK_BOOST_ON_PRICE"] = 60] = "SPARK_BOOST_ON_PRICE";
|
|
238
|
+
MainnetIds[MainnetIds["AAVE_V4_REPAY"] = 61] = "AAVE_V4_REPAY";
|
|
239
|
+
MainnetIds[MainnetIds["AAVE_V4_BOOST"] = 62] = "AAVE_V4_BOOST";
|
|
240
|
+
MainnetIds[MainnetIds["AAVE_V4_REPAY_ON_PRICE"] = 63] = "AAVE_V4_REPAY_ON_PRICE";
|
|
241
|
+
MainnetIds[MainnetIds["AAVE_V4_BOOST_ON_PRICE"] = 64] = "AAVE_V4_BOOST_ON_PRICE";
|
|
242
|
+
MainnetIds[MainnetIds["AAVE_V4_CLOSE"] = 65] = "AAVE_V4_CLOSE";
|
|
243
|
+
MainnetIds[MainnetIds["AAVE_V4_EOA_REPAY"] = 66] = "AAVE_V4_EOA_REPAY";
|
|
244
|
+
MainnetIds[MainnetIds["AAVE_V4_EOA_BOOST"] = 67] = "AAVE_V4_EOA_BOOST";
|
|
245
|
+
MainnetIds[MainnetIds["AAVE_V4_EOA_REPAY_ON_PRICE"] = 68] = "AAVE_V4_EOA_REPAY_ON_PRICE";
|
|
246
|
+
MainnetIds[MainnetIds["AAVE_V4_EOA_BOOST_ON_PRICE"] = 69] = "AAVE_V4_EOA_BOOST_ON_PRICE";
|
|
247
|
+
MainnetIds[MainnetIds["AAVE_V4_EOA_CLOSE"] = 70] = "AAVE_V4_EOA_CLOSE";
|
|
210
248
|
})(MainnetIds = Bundles.MainnetIds || (Bundles.MainnetIds = {}));
|
|
211
249
|
let OptimismIds;
|
|
212
250
|
(function (OptimismIds) {
|
|
@@ -216,6 +254,11 @@ export var Bundles;
|
|
|
216
254
|
OptimismIds[OptimismIds["AAVE_V3_CLOSE_TO_COLLATERAL"] = 3] = "AAVE_V3_CLOSE_TO_COLLATERAL";
|
|
217
255
|
OptimismIds[OptimismIds["AAVE_V3_OPEN_ORDER_FROM_COLLATERAL"] = 4] = "AAVE_V3_OPEN_ORDER_FROM_COLLATERAL";
|
|
218
256
|
OptimismIds[OptimismIds["AAVE_V3_REPAY_ON_PRICE"] = 5] = "AAVE_V3_REPAY_ON_PRICE";
|
|
257
|
+
OptimismIds[OptimismIds["AAVE_V3_EOA_REPAY"] = 6] = "AAVE_V3_EOA_REPAY";
|
|
258
|
+
OptimismIds[OptimismIds["AAVE_V3_EOA_BOOST"] = 7] = "AAVE_V3_EOA_BOOST";
|
|
259
|
+
OptimismIds[OptimismIds["AAVE_V3_EOA_REPAY_ON_PRICE"] = 8] = "AAVE_V3_EOA_REPAY_ON_PRICE";
|
|
260
|
+
OptimismIds[OptimismIds["AAVE_V3_EOA_BOOST_ON_PRICE"] = 9] = "AAVE_V3_EOA_BOOST_ON_PRICE";
|
|
261
|
+
OptimismIds[OptimismIds["AAVE_V3_EOA_CLOSE"] = 10] = "AAVE_V3_EOA_CLOSE";
|
|
219
262
|
})(OptimismIds = Bundles.OptimismIds || (Bundles.OptimismIds = {}));
|
|
220
263
|
let BaseIds;
|
|
221
264
|
(function (BaseIds) {
|
|
@@ -232,6 +275,20 @@ export var Bundles;
|
|
|
232
275
|
BaseIds[BaseIds["MORPHO_BLUE_BOOST_ON_PRICE"] = 12] = "MORPHO_BLUE_BOOST_ON_PRICE";
|
|
233
276
|
BaseIds[BaseIds["FLUID_T1_REPAY"] = 13] = "FLUID_T1_REPAY";
|
|
234
277
|
BaseIds[BaseIds["FLUID_T1_BOOST"] = 14] = "FLUID_T1_BOOST";
|
|
278
|
+
BaseIds[BaseIds["COMP_V3_SW_REPAY_ON_PRICE"] = 15] = "COMP_V3_SW_REPAY_ON_PRICE";
|
|
279
|
+
BaseIds[BaseIds["COMP_V3_SW_BOOST_ON_PRICE"] = 16] = "COMP_V3_SW_BOOST_ON_PRICE";
|
|
280
|
+
BaseIds[BaseIds["COMP_V3_SW_CLOSE"] = 17] = "COMP_V3_SW_CLOSE";
|
|
281
|
+
BaseIds[BaseIds["COMP_V3_EOA_REPAY_ON_PRICE"] = 18] = "COMP_V3_EOA_REPAY_ON_PRICE";
|
|
282
|
+
BaseIds[BaseIds["COMP_V3_EOA_BOOST_ON_PRICE"] = 19] = "COMP_V3_EOA_BOOST_ON_PRICE";
|
|
283
|
+
BaseIds[BaseIds["COMP_V3_EOA_CLOSE"] = 20] = "COMP_V3_EOA_CLOSE";
|
|
284
|
+
BaseIds[BaseIds["COMP_V3_EOA_REPAY"] = 21] = "COMP_V3_EOA_REPAY";
|
|
285
|
+
BaseIds[BaseIds["COMP_V3_EOA_BOOST"] = 22] = "COMP_V3_EOA_BOOST";
|
|
286
|
+
BaseIds[BaseIds["AAVE_V3_EOA_REPAY"] = 23] = "AAVE_V3_EOA_REPAY";
|
|
287
|
+
BaseIds[BaseIds["AAVE_V3_EOA_BOOST"] = 24] = "AAVE_V3_EOA_BOOST";
|
|
288
|
+
BaseIds[BaseIds["AAVE_V3_EOA_REPAY_ON_PRICE"] = 25] = "AAVE_V3_EOA_REPAY_ON_PRICE";
|
|
289
|
+
BaseIds[BaseIds["AAVE_V3_EOA_BOOST_ON_PRICE"] = 26] = "AAVE_V3_EOA_BOOST_ON_PRICE";
|
|
290
|
+
BaseIds[BaseIds["AAVE_V3_EOA_CLOSE"] = 27] = "AAVE_V3_EOA_CLOSE";
|
|
291
|
+
BaseIds[BaseIds["MORPHO_BLUE_CLOSE"] = 28] = "MORPHO_BLUE_CLOSE";
|
|
235
292
|
})(BaseIds = Bundles.BaseIds || (Bundles.BaseIds = {}));
|
|
236
293
|
let ArbitrumIds;
|
|
237
294
|
(function (ArbitrumIds) {
|
|
@@ -245,5 +302,24 @@ export var Bundles;
|
|
|
245
302
|
ArbitrumIds[ArbitrumIds["AAVE_V3_REPAY_ON_PRICE"] = 7] = "AAVE_V3_REPAY_ON_PRICE";
|
|
246
303
|
ArbitrumIds[ArbitrumIds["FLUID_T1_REPAY"] = 8] = "FLUID_T1_REPAY";
|
|
247
304
|
ArbitrumIds[ArbitrumIds["FLUID_T1_BOOST"] = 9] = "FLUID_T1_BOOST";
|
|
305
|
+
ArbitrumIds[ArbitrumIds["COMP_V3_SW_REPAY_ON_PRICE"] = 10] = "COMP_V3_SW_REPAY_ON_PRICE";
|
|
306
|
+
ArbitrumIds[ArbitrumIds["COMP_V3_SW_BOOST_ON_PRICE"] = 11] = "COMP_V3_SW_BOOST_ON_PRICE";
|
|
307
|
+
ArbitrumIds[ArbitrumIds["COMP_V3_SW_CLOSE"] = 12] = "COMP_V3_SW_CLOSE";
|
|
308
|
+
ArbitrumIds[ArbitrumIds["COMP_V3_EOA_REPAY_ON_PRICE"] = 13] = "COMP_V3_EOA_REPAY_ON_PRICE";
|
|
309
|
+
ArbitrumIds[ArbitrumIds["COMP_V3_EOA_BOOST_ON_PRICE"] = 14] = "COMP_V3_EOA_BOOST_ON_PRICE";
|
|
310
|
+
ArbitrumIds[ArbitrumIds["COMP_V3_EOA_CLOSE"] = 15] = "COMP_V3_EOA_CLOSE";
|
|
311
|
+
ArbitrumIds[ArbitrumIds["COMP_V3_EOA_REPAY"] = 16] = "COMP_V3_EOA_REPAY";
|
|
312
|
+
ArbitrumIds[ArbitrumIds["COMP_V3_EOA_BOOST"] = 17] = "COMP_V3_EOA_BOOST";
|
|
313
|
+
ArbitrumIds[ArbitrumIds["AAVE_V3_EOA_REPAY"] = 18] = "AAVE_V3_EOA_REPAY";
|
|
314
|
+
ArbitrumIds[ArbitrumIds["AAVE_V3_EOA_BOOST"] = 19] = "AAVE_V3_EOA_BOOST";
|
|
315
|
+
ArbitrumIds[ArbitrumIds["AAVE_V3_EOA_REPAY_ON_PRICE"] = 20] = "AAVE_V3_EOA_REPAY_ON_PRICE";
|
|
316
|
+
ArbitrumIds[ArbitrumIds["AAVE_V3_EOA_BOOST_ON_PRICE"] = 21] = "AAVE_V3_EOA_BOOST_ON_PRICE";
|
|
317
|
+
ArbitrumIds[ArbitrumIds["AAVE_V3_EOA_CLOSE"] = 22] = "AAVE_V3_EOA_CLOSE";
|
|
318
|
+
ArbitrumIds[ArbitrumIds["MORPHO_BLUE_REPAY"] = 23] = "MORPHO_BLUE_REPAY";
|
|
319
|
+
ArbitrumIds[ArbitrumIds["MORPHO_BLUE_BOOST"] = 24] = "MORPHO_BLUE_BOOST";
|
|
320
|
+
ArbitrumIds[ArbitrumIds["MORPHO_BLUE_BOOST_ON_PRICE"] = 25] = "MORPHO_BLUE_BOOST_ON_PRICE";
|
|
321
|
+
ArbitrumIds[ArbitrumIds["MORPHO_BLUE_EOA_REPAY"] = 26] = "MORPHO_BLUE_EOA_REPAY";
|
|
322
|
+
ArbitrumIds[ArbitrumIds["MORPHO_BLUE_EOA_BOOST"] = 27] = "MORPHO_BLUE_EOA_BOOST";
|
|
323
|
+
ArbitrumIds[ArbitrumIds["MORPHO_BLUE_CLOSE"] = 28] = "MORPHO_BLUE_CLOSE";
|
|
248
324
|
})(ArbitrumIds = Bundles.ArbitrumIds || (Bundles.ArbitrumIds = {}));
|
|
249
325
|
})(Bundles || (Bundles = {}));
|
package/esm/types/index.d.ts
CHANGED
|
@@ -120,6 +120,16 @@ export declare namespace Position {
|
|
|
120
120
|
price: string;
|
|
121
121
|
ratioState: RatioState;
|
|
122
122
|
}
|
|
123
|
+
interface AaveV3CloseOnPriceGeneric extends Base {
|
|
124
|
+
collAsset: EthereumAddress;
|
|
125
|
+
collAssetId: number;
|
|
126
|
+
debtAsset: EthereumAddress;
|
|
127
|
+
debtAssetId: number;
|
|
128
|
+
baseToken: EthereumAddress;
|
|
129
|
+
quoteToken: EthereumAddress;
|
|
130
|
+
stopLossPrice: string;
|
|
131
|
+
takeProfitPrice: string;
|
|
132
|
+
}
|
|
123
133
|
interface BoostOnPriceAave extends CloseOnPriceAave {
|
|
124
134
|
ratio: number;
|
|
125
135
|
}
|
|
@@ -171,8 +181,56 @@ export declare namespace Position {
|
|
|
171
181
|
subHashBoost?: string;
|
|
172
182
|
subHashRepay?: string;
|
|
173
183
|
}
|
|
184
|
+
interface CompoundV3Base extends Base {
|
|
185
|
+
market: EthereumAddress;
|
|
186
|
+
collToken: EthereumAddress;
|
|
187
|
+
baseToken: EthereumAddress;
|
|
188
|
+
}
|
|
189
|
+
interface CompoundV3LeverageManagementOnPrice extends CompoundV3Base {
|
|
190
|
+
ratio: number;
|
|
191
|
+
price: string;
|
|
192
|
+
priceState: RatioState;
|
|
193
|
+
}
|
|
194
|
+
interface CompoundV3CloseOnPrice extends CompoundV3Base {
|
|
195
|
+
stopLossPrice: string;
|
|
196
|
+
takeProfitPrice: string;
|
|
197
|
+
stopLossType: CloseToAssetType | undefined;
|
|
198
|
+
takeProfitType: CloseToAssetType | undefined;
|
|
199
|
+
}
|
|
200
|
+
interface SparkOnPrice extends Base {
|
|
201
|
+
collAsset: EthereumAddress;
|
|
202
|
+
collAssetId: number;
|
|
203
|
+
debtAsset: EthereumAddress;
|
|
204
|
+
debtAssetId: number;
|
|
205
|
+
baseToken: EthereumAddress;
|
|
206
|
+
quoteToken: EthereumAddress;
|
|
207
|
+
price: string;
|
|
208
|
+
ratioState: RatioState;
|
|
209
|
+
ratio: number;
|
|
210
|
+
}
|
|
211
|
+
interface CloseBase extends Base {
|
|
212
|
+
stopLossPrice: string;
|
|
213
|
+
takeProfitPrice: string;
|
|
214
|
+
stopLossType: CloseToAssetType | undefined;
|
|
215
|
+
takeProfitType: CloseToAssetType | undefined;
|
|
216
|
+
}
|
|
217
|
+
interface AaveV4LeverageManagementOnPrice extends Base {
|
|
218
|
+
collAsset: EthereumAddress;
|
|
219
|
+
collAssetId: number;
|
|
220
|
+
debtAsset: EthereumAddress;
|
|
221
|
+
debtAssetId: number;
|
|
222
|
+
price: string;
|
|
223
|
+
ratioState: number;
|
|
224
|
+
ratio: number;
|
|
225
|
+
}
|
|
226
|
+
interface AaveV4CloseOnPrice extends CloseBase {
|
|
227
|
+
collAsset: EthereumAddress;
|
|
228
|
+
collAssetId: number;
|
|
229
|
+
debtAsset: EthereumAddress;
|
|
230
|
+
debtAssetId: number;
|
|
231
|
+
}
|
|
174
232
|
}
|
|
175
|
-
type SpecificAny = Specific.CloseOnPrice | Specific.TrailingStop | Specific.RatioProtection | Specific.CloseOnPriceAave | Specific.BoostOnPriceAave | Specific.CloseOnPriceWithMaximumGasPriceAave | Specific.DebtInFrontRepay | Specific.LeverageManagementCrvUSD | Specific.CloseOnPriceLiquityV2 | Specific.BoostOnPriceMorpho | Specific.BoostOnPriceLiquityV2 | Specific.PaybackLiquityV2;
|
|
233
|
+
type SpecificAny = Specific.CloseOnPrice | Specific.TrailingStop | Specific.RatioProtection | Specific.CloseOnPriceAave | Specific.BoostOnPriceAave | Specific.CloseOnPriceWithMaximumGasPriceAave | Specific.DebtInFrontRepay | Specific.LeverageManagementCrvUSD | Specific.CloseOnPriceLiquityV2 | Specific.BoostOnPriceMorpho | Specific.BoostOnPriceLiquityV2 | Specific.PaybackLiquityV2 | Specific.CompoundV3LeverageManagementOnPrice | Specific.CompoundV3CloseOnPrice | Specific.AaveV3CloseOnPriceGeneric | Specific.AaveV4LeverageManagementOnPrice | Specific.AaveV4CloseOnPrice | Specific.SparkOnPrice;
|
|
176
234
|
interface Automated {
|
|
177
235
|
chainId: ChainId;
|
|
178
236
|
positionId: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defisaver/automation-sdk",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.14-spark-dev",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./cjs/index.js",
|
|
6
6
|
"module": "./esm/index.js",
|
|
@@ -23,12 +23,12 @@
|
|
|
23
23
|
"repository": "https://github.com/defisaver/automation-sdk",
|
|
24
24
|
"license": "ISC",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@defisaver/
|
|
27
|
-
"@defisaver/
|
|
28
|
-
"@defisaver/tokens": "^1.5.54",
|
|
26
|
+
"@defisaver/sdk": "^1.3.22",
|
|
27
|
+
"@defisaver/tokens": "^1.6.19",
|
|
29
28
|
"@ethersproject/address": "^5.0.10",
|
|
30
29
|
"@ethersproject/solidity": "^5.0.9",
|
|
31
30
|
"decimal.js": "^10.4.3",
|
|
31
|
+
"es6-promise-pool": "^2.5.0",
|
|
32
32
|
"lodash": "^4.17.21",
|
|
33
33
|
"web3-eth-abi": "^1.10.2",
|
|
34
34
|
"web3-utils": "^1.10.2"
|
|
@@ -46,7 +46,6 @@
|
|
|
46
46
|
"husky": "^8.0.0",
|
|
47
47
|
"jsdoc-to-markdown": "^6.0.1",
|
|
48
48
|
"mocha": "^10.2.0",
|
|
49
|
-
"react": "^18.2.0",
|
|
50
49
|
"ts-node": "^10.9.1",
|
|
51
50
|
"typechain": "^8.1.0",
|
|
52
51
|
"typechain-target-web3-v1-3mihai3": "^6.0.1",
|
|
@@ -659,5 +659,45 @@ describe('Feature: StrategiesAutomation.ts', () => {
|
|
|
659
659
|
expect(JSON.stringify(actual)).to.equal(JSON.stringify(expected));
|
|
660
660
|
});
|
|
661
661
|
});
|
|
662
|
+
|
|
663
|
+
it('Aave V4: pairs repay/boost merge only when trigger spoke matches (no cross-spoke merge)', () => {
|
|
664
|
+
const spoke1 = '0x0000000000000000000000000000000000000a01';
|
|
665
|
+
const spoke2 = '0x0000000000000000000000000000000000000a02';
|
|
666
|
+
const base = {
|
|
667
|
+
isEnabled: true,
|
|
668
|
+
chainId: 1,
|
|
669
|
+
owner: '0x0000000000000000000000000000000000000b01',
|
|
670
|
+
protocol: { id: 'Aave__V4' },
|
|
671
|
+
strategy: { strategyId: 'leverage-management' },
|
|
672
|
+
blockNumber: 0,
|
|
673
|
+
subHash: '0x1',
|
|
674
|
+
positionId: 'test',
|
|
675
|
+
};
|
|
676
|
+
const boostSpoke1 = {
|
|
677
|
+
...base,
|
|
678
|
+
subId: 1,
|
|
679
|
+
strategyData: { decoded: { triggerData: { spoke: spoke1 }, subData: {} } },
|
|
680
|
+
specific: { mergeId: 'boost', subId2: 1 },
|
|
681
|
+
};
|
|
682
|
+
const repaySpoke2 = {
|
|
683
|
+
...base,
|
|
684
|
+
subId: 2,
|
|
685
|
+
strategyData: { decoded: { triggerData: { spoke: spoke2 }, subData: {} } },
|
|
686
|
+
specific: { mergeWithId: 'boost', subId1: 2 },
|
|
687
|
+
};
|
|
688
|
+
const boostSpoke2 = {
|
|
689
|
+
...base,
|
|
690
|
+
subId: 3,
|
|
691
|
+
strategyData: { decoded: { triggerData: { spoke: spoke2 }, subData: {} } },
|
|
692
|
+
specific: { mergeId: 'boost', subId2: 3 },
|
|
693
|
+
};
|
|
694
|
+
// @ts-ignore — mergeSubs is protected; exercised here as in examples above
|
|
695
|
+
const merged = exampleStrategiesAutomation.mergeSubs([boostSpoke1, repaySpoke2, boostSpoke2]);
|
|
696
|
+
expect(merged).to.have.length(2);
|
|
697
|
+
const mergedPair = merged.find((m: { subIds?: number[] }) => m.subIds?.length === 2);
|
|
698
|
+
const loneBoost = merged.find((m: { subIds?: number[] }) => m.subIds?.length === 1);
|
|
699
|
+
expect(mergedPair?.strategyData?.decoded?.triggerData?.spoke).to.equal(spoke2);
|
|
700
|
+
expect(loneBoost?.subId).to.equal(1);
|
|
701
|
+
});
|
|
662
702
|
});
|
|
663
703
|
});
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import Dec from 'decimal.js';
|
|
2
2
|
import type Web3 from 'web3';
|
|
3
3
|
import type { PastEventOptions } from 'web3-eth-contract';
|
|
4
|
+
import PromisePool from 'es6-promise-pool';
|
|
4
5
|
import type {
|
|
5
6
|
Position, Interfaces, EthereumAddress, SubscriptionOptions, Contract, ParseData, PlaceholderType, BlockNumber,
|
|
6
7
|
} from '../../types';
|
|
7
8
|
import type {
|
|
8
|
-
StrategyModel, SubStorage,
|
|
9
|
+
StrategyModel, Subscribe, SubStorage, UpdateData,
|
|
9
10
|
} from '../../types/contracts/generated/SubStorage';
|
|
10
11
|
import type { ChainId } from '../../types/enums';
|
|
11
12
|
import { Strategies, ProtocolIdentifiers } from '../../types/enums';
|
|
@@ -77,13 +78,13 @@ export default class StrategiesAutomation extends Automation {
|
|
|
77
78
|
}
|
|
78
79
|
|
|
79
80
|
protected async getSubscriptionEventsFromSubStorage(options?: PastEventOptions) {
|
|
80
|
-
return this.getEventFromSubStorage('Subscribe', options)
|
|
81
|
+
return this.getEventFromSubStorage('Subscribe', options) as Promise<Subscribe[]>;
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
protected async getUpdateDataEventsFromSubStorage(options?: PastEventOptions) {
|
|
84
85
|
const events = await this.getEventFromSubStorage('UpdateData', options);
|
|
85
86
|
/** @dev - Some RPCs sort events differently */
|
|
86
|
-
return events.sort((a, b) => a.blockNumber - b.blockNumber);
|
|
87
|
+
return events.sort((a, b) => a.blockNumber - b.blockNumber) as UpdateData[];
|
|
87
88
|
}
|
|
88
89
|
|
|
89
90
|
protected getParsedSubscriptions(parseData: ParseData) {
|
|
@@ -128,9 +129,20 @@ export default class StrategiesAutomation extends Automation {
|
|
|
128
129
|
&& (
|
|
129
130
|
s.protocol.id !== ProtocolIdentifiers.StrategiesAutomation.MorphoBlue // merge morpho blue with the same marketId
|
|
130
131
|
|| s.strategyData.decoded.triggerData.marketId.toLowerCase() === current.strategyData.decoded.triggerData.marketId.toLowerCase()
|
|
132
|
+
)
|
|
133
|
+
&& (
|
|
134
|
+
s.protocol.id !== ProtocolIdentifiers.StrategiesAutomation.AaveV4
|
|
135
|
+
|| this._aaveV4MergeSpokesMatch(s, current)
|
|
131
136
|
);
|
|
132
137
|
}
|
|
133
138
|
|
|
139
|
+
/** Repay/boost leverage pairs must not merge across different Aave V4 spokes. */
|
|
140
|
+
private _aaveV4MergeSpokesMatch(s: Position.Automated, current: Position.Automated): boolean {
|
|
141
|
+
const a = s.strategyData?.decoded?.triggerData?.spoke as EthereumAddress | undefined;
|
|
142
|
+
const b = current.strategyData?.decoded?.triggerData?.spoke as EthereumAddress | undefined;
|
|
143
|
+
return !!a && !!b && a.toLowerCase() === b.toLowerCase();
|
|
144
|
+
}
|
|
145
|
+
|
|
134
146
|
protected mergeSubs(_subscriptions:(Position.Automated | null)[]) {
|
|
135
147
|
const mergeBase = _subscriptions.filter(s => isDefined(s) && isDefined(s.specific.mergeWithId)) as Position.Automated[];
|
|
136
148
|
const mergeExtension = _subscriptions.filter(s => isDefined(s) && isDefined(s.specific.mergeId)) as Position.Automated[];
|
|
@@ -168,7 +180,6 @@ export default class StrategiesAutomation extends Automation {
|
|
|
168
180
|
}
|
|
169
181
|
});
|
|
170
182
|
if (mergeExtension.length > 0) {
|
|
171
|
-
console.error('Not all merge-able extensions were used', mergeExtension);
|
|
172
183
|
subscriptions = [...subscriptions, ...mergeExtension.map((s) => ({
|
|
173
184
|
...s,
|
|
174
185
|
subIds: [s.subId],
|
|
@@ -183,13 +194,13 @@ export default class StrategiesAutomation extends Automation {
|
|
|
183
194
|
...addToObjectIf(isDefined(addresses), { filter: { proxy: addresses } }),
|
|
184
195
|
} as SubscriptionOptions & PastEventOptions;
|
|
185
196
|
|
|
186
|
-
let subscriptionEvents =
|
|
197
|
+
let subscriptionEvents = await this.getSubscriptionEventsFromSubStorage(_options);
|
|
187
198
|
|
|
188
199
|
let subscriptions: (Position.Automated | null)[] = [];
|
|
189
200
|
|
|
190
201
|
if (subscriptionEvents) {
|
|
191
202
|
let strategiesSubs = await this.getStrategiesSubs(
|
|
192
|
-
subscriptionEvents.map((e
|
|
203
|
+
subscriptionEvents.map((e) => +e.returnValues.subId), _options.toBlock,
|
|
193
204
|
);
|
|
194
205
|
|
|
195
206
|
if (_options.enabledOnly) {
|
|
@@ -203,8 +214,9 @@ export default class StrategiesAutomation extends Automation {
|
|
|
203
214
|
subscriptionEvents = filteredSubscriptionEvents;
|
|
204
215
|
}
|
|
205
216
|
|
|
206
|
-
|
|
207
|
-
|
|
217
|
+
const replaceSubWithUpdate = async (index: number) => {
|
|
218
|
+
const sub = strategiesSubs[index];
|
|
219
|
+
let latestUpdate = { ...subscriptionEvents[index].returnValues };
|
|
208
220
|
|
|
209
221
|
if (latestUpdate.subHash !== sub?.strategySubHash) {
|
|
210
222
|
const updates = await this.getUpdateDataEventsFromSubStorage({
|
|
@@ -214,15 +226,26 @@ export default class StrategiesAutomation extends Automation {
|
|
|
214
226
|
latestUpdate = {
|
|
215
227
|
...latestUpdate, // Update is missing proxy, hence this
|
|
216
228
|
...updates?.[updates.length - 1]?.returnValues,
|
|
229
|
+
2: latestUpdate[2], // type issue
|
|
217
230
|
};
|
|
218
231
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
232
|
+
subscriptions.push(
|
|
233
|
+
this.getParsedSubscriptions({
|
|
234
|
+
chainId: this.chainId,
|
|
235
|
+
blockNumber: subscriptionEvents[index].blockNumber,
|
|
236
|
+
subscriptionEventData: latestUpdate,
|
|
237
|
+
strategiesSubsData: sub,
|
|
238
|
+
}),
|
|
239
|
+
);
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
// eslint-disable-next-line func-names
|
|
243
|
+
const pool = new PromisePool(function* () {
|
|
244
|
+
for (let index = 0; index < strategiesSubs.length; index++) {
|
|
245
|
+
yield replaceSubWithUpdate(index);
|
|
246
|
+
}
|
|
247
|
+
} as any, 50);
|
|
248
|
+
await pool.start();
|
|
226
249
|
|
|
227
250
|
if (options?.mergeSubs) {
|
|
228
251
|
subscriptions = this.mergeSubs(subscriptions);
|