@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
|
@@ -101,6 +101,7 @@ describe('Feature: ethereumService.ts', () => {
|
|
|
101
101
|
'address': '0x5f98805A4E8be255a32880FDeC7F6728C6568bA0',
|
|
102
102
|
'blockHash': '0xb92cab2569456dbfbdb853d2c67d72c9a7580543dbcb55d483a77322b40755a4',
|
|
103
103
|
'blockNumber': 15166163,
|
|
104
|
+
'blockTimestamp': '0x62d53ad8',
|
|
104
105
|
'event': 'Transfer',
|
|
105
106
|
'id': 'log_e2258e3a',
|
|
106
107
|
'logIndex': 385,
|
|
@@ -146,6 +147,7 @@ describe('Feature: ethereumService.ts', () => {
|
|
|
146
147
|
'address': '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1',
|
|
147
148
|
'blockHash': '0xacb0213af63b4c17c436f084a96d1ac385641a59a9a4cf014ae3337cbe545aa7',
|
|
148
149
|
'blockNumber': 5353002,
|
|
150
|
+
'blockTimestamp': '0x624c1a5b',
|
|
149
151
|
'event': 'Transfer',
|
|
150
152
|
'id': 'log_f49645b8',
|
|
151
153
|
'logIndex': 1,
|
|
@@ -191,6 +193,7 @@ describe('Feature: ethereumService.ts', () => {
|
|
|
191
193
|
'address': '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1',
|
|
192
194
|
'blockHash': '0xacb0213af63b4c17c436f084a96d1ac385641a59a9a4cf014ae3337cbe545aa7',
|
|
193
195
|
'blockNumber': 5353002,
|
|
196
|
+
'blockTimestamp': '0x624c1a5b',
|
|
194
197
|
'event': 'Transfer',
|
|
195
198
|
'id': 'log_f49645b8',
|
|
196
199
|
'logIndex': 1,
|
|
@@ -36,9 +36,6 @@ const utils_1 = require("./utils");
|
|
|
36
36
|
const subDataService = __importStar(require("./subDataService"));
|
|
37
37
|
const triggerService = __importStar(require("./triggerService"));
|
|
38
38
|
const web3 = new web3_1.default();
|
|
39
|
-
const SPARK_MARKET_ADDRESSES = {
|
|
40
|
-
[enums_1.ChainId.Ethereum]: '0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE',
|
|
41
|
-
};
|
|
42
39
|
const AAVE_V3_MARKET_ADDRESSES = {
|
|
43
40
|
[enums_1.ChainId.Ethereum]: '0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e',
|
|
44
41
|
[enums_1.ChainId.Optimism]: '0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb',
|
|
@@ -189,21 +186,29 @@ function parseAaveV2LeverageManagement(position, parseData) {
|
|
|
189
186
|
}
|
|
190
187
|
function parseAaveV3LeverageManagement(position, parseData) {
|
|
191
188
|
const _position = (0, lodash_1.cloneDeep)(position);
|
|
192
|
-
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
189
|
+
const { subStruct, subId, subHash } = parseData.subscriptionEventData;
|
|
193
190
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
194
191
|
const triggerData = triggerService.aaveV3RatioTrigger.decode(subStruct.triggerData);
|
|
195
|
-
const
|
|
192
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
193
|
+
let subData;
|
|
194
|
+
if (isEOA) {
|
|
195
|
+
subData = subDataService.aaveV3LeverageManagementSubDataWithoutSubProxy.decode(subStruct.subData);
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
subData = subDataService.aaveV3LeverageManagementSubData.decode(subStruct.subData);
|
|
199
|
+
}
|
|
196
200
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
197
201
|
_position.strategyData.decoded.subData = subData;
|
|
198
202
|
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, triggerData.market);
|
|
199
|
-
const isRepay =
|
|
203
|
+
const isRepay = [enums_1.Strategies.Identifiers.Repay, enums_1.Strategies.Identifiers.EoaRepay].includes(_position.strategy.strategyId);
|
|
200
204
|
if (isRepay) {
|
|
201
205
|
_position.specific = {
|
|
202
206
|
triggerRepayRatio: triggerData.ratio,
|
|
203
207
|
targetRepayRatio: subData.targetRatio,
|
|
204
|
-
repayEnabled:
|
|
208
|
+
repayEnabled: isEnabled,
|
|
205
209
|
subId1: Number(subId),
|
|
206
|
-
mergeWithId: enums_1.Strategies.Identifiers.Boost,
|
|
210
|
+
mergeWithId: isEOA ? enums_1.Strategies.Identifiers.EoaBoost : enums_1.Strategies.Identifiers.Boost,
|
|
211
|
+
subHashRepay: subHash,
|
|
207
212
|
};
|
|
208
213
|
}
|
|
209
214
|
else {
|
|
@@ -212,29 +217,133 @@ function parseAaveV3LeverageManagement(position, parseData) {
|
|
|
212
217
|
targetBoostRatio: subData.targetRatio,
|
|
213
218
|
boostEnabled: isEnabled,
|
|
214
219
|
subId2: Number(subId),
|
|
215
|
-
mergeId: enums_1.Strategies.Identifiers.Boost,
|
|
220
|
+
mergeId: isEOA ? enums_1.Strategies.Identifiers.EoaBoost : enums_1.Strategies.Identifiers.Boost,
|
|
221
|
+
subHashBoost: subHash,
|
|
216
222
|
};
|
|
217
223
|
}
|
|
218
|
-
|
|
224
|
+
if (!isEOA) {
|
|
225
|
+
_position.strategy.strategyId = enums_1.Strategies.IdOverrides.LeverageManagement;
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
_position.strategy.strategyId = enums_1.Strategies.IdOverrides.EoaLeverageManagement;
|
|
229
|
+
}
|
|
219
230
|
return _position;
|
|
220
231
|
}
|
|
221
|
-
function
|
|
232
|
+
function parseAaveV3LeverageManagementOnPrice(position, parseData) {
|
|
222
233
|
const _position = (0, lodash_1.cloneDeep)(position);
|
|
223
|
-
const { subStruct
|
|
234
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
235
|
+
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
236
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
237
|
+
let subData;
|
|
238
|
+
if (isEOA) {
|
|
239
|
+
subData = subDataService.aaveV3LeverageManagementOnPriceGeneric.decode(subStruct.subData);
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
subData = subDataService.aaveV3LeverageManagementOnPriceSubData.decode(subStruct.subData);
|
|
243
|
+
}
|
|
244
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
245
|
+
_position.strategyData.decoded.subData = subData;
|
|
246
|
+
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, Math.random());
|
|
247
|
+
_position.specific = {
|
|
248
|
+
collAsset: subData.collAsset,
|
|
249
|
+
debtAsset: subData.debtAsset,
|
|
250
|
+
baseToken: triggerData.baseTokenAddress,
|
|
251
|
+
quoteToken: triggerData.quoteTokenAddress,
|
|
252
|
+
price: triggerData.price,
|
|
253
|
+
ratioState: triggerData.ratioState,
|
|
254
|
+
debtAssetId: subData.debtAssetId,
|
|
255
|
+
collAssetId: subData.collAssetId,
|
|
256
|
+
ratio: subData.targetRatio,
|
|
257
|
+
};
|
|
258
|
+
return _position;
|
|
259
|
+
}
|
|
260
|
+
function parseAaveV3CloseOnPrice(position, parseData) {
|
|
261
|
+
const _position = (0, lodash_1.cloneDeep)(position);
|
|
262
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
263
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
264
|
+
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, AAVE_V3_MARKET_ADDRESSES[_position.chainId]);
|
|
265
|
+
if (isEOA) {
|
|
266
|
+
const triggerData = triggerService.aaveV3QuotePriceRangeTrigger.decode(subStruct.triggerData);
|
|
267
|
+
const subData = subDataService.aaveV3CloseGenericSubData.decode(subStruct.subData);
|
|
268
|
+
const { takeProfitType, stopLossType } = (0, utils_1.getStopLossAndTakeProfitTypeByCloseStrategyType)(+subData.closeType);
|
|
269
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
270
|
+
_position.strategyData.decoded.subData = subData;
|
|
271
|
+
_position.specific = {
|
|
272
|
+
collAsset: subData.collAsset,
|
|
273
|
+
collAssetId: subData.collAssetId,
|
|
274
|
+
debtAsset: subData.debtAsset,
|
|
275
|
+
debtAssetId: subData.debtAssetId,
|
|
276
|
+
baseToken: triggerData.collToken,
|
|
277
|
+
quoteToken: triggerData.debtToken,
|
|
278
|
+
stopLossPrice: triggerData.lowerPrice,
|
|
279
|
+
takeProfitPrice: triggerData.upperPrice,
|
|
280
|
+
stopLossType,
|
|
281
|
+
takeProfitType,
|
|
282
|
+
};
|
|
283
|
+
_position.strategy.strategyId = enums_1.Strategies.Identifiers.EoaCloseOnPrice;
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
287
|
+
const subData = subDataService.aaveV3QuotePriceSubData.decode(subStruct.subData);
|
|
288
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
289
|
+
_position.strategyData.decoded.subData = subData;
|
|
290
|
+
_position.specific = {
|
|
291
|
+
collAsset: subData.collAsset,
|
|
292
|
+
collAssetId: subData.collAssetId,
|
|
293
|
+
debtAsset: subData.debtAsset,
|
|
294
|
+
debtAssetId: subData.debtAssetId,
|
|
295
|
+
baseToken: triggerData.baseTokenAddress,
|
|
296
|
+
quoteToken: triggerData.quoteTokenAddress,
|
|
297
|
+
price: triggerData.price,
|
|
298
|
+
ratioState: triggerData.ratioState,
|
|
299
|
+
};
|
|
300
|
+
const { ratioState } = (0, utils_1.getRatioStateInfoForAaveCloseStrategy)(_position.specific.ratioState, (0, utils_1.wethToEthByAddress)(_position.specific.collAsset, parseData.chainId), (0, utils_1.wethToEthByAddress)(_position.specific.debtAsset, parseData.chainId), parseData.chainId);
|
|
301
|
+
_position.strategy.strategyId = (0, utils_1.isRatioStateOver)(ratioState)
|
|
302
|
+
? enums_1.Strategies.IdOverrides.TakeProfit
|
|
303
|
+
: enums_1.Strategies.IdOverrides.StopLoss;
|
|
304
|
+
}
|
|
305
|
+
return _position;
|
|
306
|
+
}
|
|
307
|
+
function parseAaveV3CollateralSwitch(position, parseData) {
|
|
308
|
+
const _position = (0, lodash_1.cloneDeep)(position);
|
|
309
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
310
|
+
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
311
|
+
const subData = subDataService.aaveV3CollateralSwitchSubData.decode(subStruct.subData);
|
|
312
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
313
|
+
_position.strategyData.decoded.subData = subData;
|
|
314
|
+
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
|
|
315
|
+
return _position;
|
|
316
|
+
}
|
|
317
|
+
function parseSparkCollateralSwitch(position, parseData) {
|
|
318
|
+
const _position = (0, lodash_1.cloneDeep)(position);
|
|
319
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
320
|
+
const triggerData = triggerService.sparkQuotePriceTrigger.decode(subStruct.triggerData);
|
|
321
|
+
const subData = subDataService.sparkCollateralSwitchSubData.decode(subStruct.subData);
|
|
322
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
323
|
+
_position.strategyData.decoded.subData = subData;
|
|
324
|
+
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
|
|
325
|
+
return _position;
|
|
326
|
+
}
|
|
327
|
+
function parseAaveV4LeverageManagement(position, parseData) {
|
|
328
|
+
const _position = (0, lodash_1.cloneDeep)(position);
|
|
329
|
+
const { subStruct, subId, subHash } = parseData.subscriptionEventData;
|
|
224
330
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
225
|
-
const triggerData = triggerService.
|
|
226
|
-
const subData = subDataService.
|
|
331
|
+
const triggerData = triggerService.aaveV4RatioTrigger.decode(subStruct.triggerData);
|
|
332
|
+
const subData = subDataService.aaveV4LeverageManagementSubData.decode(subStruct.subData);
|
|
333
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
334
|
+
const isRepay = [enums_1.Strategies.Identifiers.Repay, enums_1.Strategies.Identifiers.EoaRepay].includes(_position.strategy.strategyId);
|
|
227
335
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
228
336
|
_position.strategyData.decoded.subData = subData;
|
|
229
|
-
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner);
|
|
230
|
-
|
|
337
|
+
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, triggerData.spoke);
|
|
338
|
+
_position.strategy.strategyId = isEOA ? enums_1.Strategies.IdOverrides.EoaLeverageManagement : enums_1.Strategies.IdOverrides.LeverageManagement;
|
|
231
339
|
if (isRepay) {
|
|
232
340
|
_position.specific = {
|
|
233
341
|
triggerRepayRatio: triggerData.ratio,
|
|
234
342
|
targetRepayRatio: subData.targetRatio,
|
|
235
|
-
repayEnabled:
|
|
343
|
+
repayEnabled: isEnabled,
|
|
236
344
|
subId1: Number(subId),
|
|
237
|
-
mergeWithId: enums_1.Strategies.Identifiers.Boost,
|
|
345
|
+
mergeWithId: isEOA ? enums_1.Strategies.Identifiers.EoaBoost : enums_1.Strategies.Identifiers.Boost,
|
|
346
|
+
subHashRepay: subHash,
|
|
238
347
|
};
|
|
239
348
|
}
|
|
240
349
|
else {
|
|
@@ -243,32 +352,97 @@ function parseMorphoAaveV2LeverageManagement(position, parseData) {
|
|
|
243
352
|
targetBoostRatio: subData.targetRatio,
|
|
244
353
|
boostEnabled: isEnabled,
|
|
245
354
|
subId2: Number(subId),
|
|
246
|
-
mergeId: enums_1.Strategies.Identifiers.Boost,
|
|
355
|
+
mergeId: isEOA ? enums_1.Strategies.Identifiers.EoaBoost : enums_1.Strategies.Identifiers.Boost,
|
|
356
|
+
subHashBoost: subHash,
|
|
247
357
|
};
|
|
248
358
|
}
|
|
249
|
-
_position.strategy.strategyId = enums_1.Strategies.IdOverrides.LeverageManagement;
|
|
250
359
|
return _position;
|
|
251
360
|
}
|
|
252
|
-
function
|
|
361
|
+
function parseAaveV4LeverageManagementOnPrice(position, parseData) {
|
|
253
362
|
const _position = (0, lodash_1.cloneDeep)(position);
|
|
254
363
|
const { subStruct } = parseData.subscriptionEventData;
|
|
255
|
-
const triggerData = triggerService.
|
|
256
|
-
const subData = subDataService.
|
|
364
|
+
const triggerData = triggerService.aaveV4QuotePriceTrigger.decode(subStruct.triggerData);
|
|
365
|
+
const subData = subDataService.aaveV4LeverageManagementOnPriceSubData.decode(subStruct.subData);
|
|
366
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
257
367
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
258
368
|
_position.strategyData.decoded.subData = subData;
|
|
259
|
-
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner,
|
|
369
|
+
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, triggerData.spoke);
|
|
370
|
+
_position.strategy.strategyId = isEOA ? enums_1.Strategies.IdOverrides.EoaLeverageManagementOnPrice : enums_1.Strategies.IdOverrides.LeverageManagementOnPrice;
|
|
260
371
|
_position.specific = {
|
|
261
372
|
collAsset: subData.collAsset,
|
|
262
373
|
collAssetId: subData.collAssetId,
|
|
263
374
|
debtAsset: subData.debtAsset,
|
|
264
375
|
debtAssetId: subData.debtAssetId,
|
|
265
|
-
baseToken: triggerData.baseTokenAddress,
|
|
266
|
-
quoteToken: triggerData.quoteTokenAddress,
|
|
267
376
|
price: triggerData.price,
|
|
268
377
|
ratioState: triggerData.ratioState,
|
|
378
|
+
ratio: subData.targetRatio,
|
|
269
379
|
};
|
|
270
|
-
|
|
271
|
-
|
|
380
|
+
return _position;
|
|
381
|
+
}
|
|
382
|
+
function parseAaveV4CloseOnPrice(position, parseData) {
|
|
383
|
+
const _position = (0, lodash_1.cloneDeep)(position);
|
|
384
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
385
|
+
const triggerData = triggerService.aaveV4QuotePriceRangeTrigger.decode(subStruct.triggerData);
|
|
386
|
+
const subData = subDataService.aaveV4CloseSubData.decode(subStruct.subData);
|
|
387
|
+
const { takeProfitType, stopLossType } = (0, utils_1.getStopLossAndTakeProfitTypeByCloseStrategyType)(+subData.closeType);
|
|
388
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
389
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
390
|
+
_position.strategyData.decoded.subData = subData;
|
|
391
|
+
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, triggerData.spoke);
|
|
392
|
+
_position.strategy.strategyId = isEOA ? enums_1.Strategies.Identifiers.EoaCloseOnPrice : enums_1.Strategies.Identifiers.CloseOnPrice;
|
|
393
|
+
_position.specific = {
|
|
394
|
+
collAsset: subData.collAsset,
|
|
395
|
+
collAssetId: subData.collAssetId,
|
|
396
|
+
debtAsset: subData.debtAsset,
|
|
397
|
+
debtAssetId: subData.debtAssetId,
|
|
398
|
+
stopLossPrice: triggerData.lowerPrice,
|
|
399
|
+
takeProfitPrice: triggerData.upperPrice,
|
|
400
|
+
stopLossType,
|
|
401
|
+
takeProfitType,
|
|
402
|
+
};
|
|
403
|
+
return _position;
|
|
404
|
+
}
|
|
405
|
+
function parseAaveV4CollateralSwitch(position, parseData) {
|
|
406
|
+
const _position = (0, lodash_1.cloneDeep)(position);
|
|
407
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
408
|
+
const triggerData = triggerService.aaveV4QuotePriceTrigger.decode(subStruct.triggerData);
|
|
409
|
+
const subData = subDataService.aaveV4CollateralSwitchSubData.decode(subStruct.subData);
|
|
410
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
411
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
412
|
+
_position.strategyData.decoded.subData = subData;
|
|
413
|
+
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, triggerData.spoke);
|
|
414
|
+
_position.strategy.strategyId = isEOA ? enums_1.Strategies.Identifiers.EoaCollateralSwitch : enums_1.Strategies.Identifiers.CollateralSwitch;
|
|
415
|
+
return _position;
|
|
416
|
+
}
|
|
417
|
+
function parseMorphoAaveV2LeverageManagement(position, parseData) {
|
|
418
|
+
const _position = (0, lodash_1.cloneDeep)(position);
|
|
419
|
+
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
420
|
+
const { isEnabled } = parseData.strategiesSubsData;
|
|
421
|
+
const triggerData = triggerService.morphoAaveV2RatioTrigger.decode(subStruct.triggerData);
|
|
422
|
+
const subData = subDataService.morphoAaveV2LeverageManagementSubData.decode(subStruct.subData);
|
|
423
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
424
|
+
_position.strategyData.decoded.subData = subData;
|
|
425
|
+
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner);
|
|
426
|
+
const isRepay = _position.strategy.strategyId === enums_1.Strategies.Identifiers.Repay;
|
|
427
|
+
if (isRepay) {
|
|
428
|
+
_position.specific = {
|
|
429
|
+
triggerRepayRatio: triggerData.ratio,
|
|
430
|
+
targetRepayRatio: subData.targetRatio,
|
|
431
|
+
repayEnabled: true,
|
|
432
|
+
subId1: Number(subId),
|
|
433
|
+
mergeWithId: enums_1.Strategies.Identifiers.Boost,
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
else {
|
|
437
|
+
_position.specific = {
|
|
438
|
+
triggerBoostRatio: triggerData.ratio,
|
|
439
|
+
targetBoostRatio: subData.targetRatio,
|
|
440
|
+
boostEnabled: isEnabled,
|
|
441
|
+
subId2: Number(subId),
|
|
442
|
+
mergeId: enums_1.Strategies.Identifiers.Boost,
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
_position.strategy.strategyId = enums_1.Strategies.IdOverrides.LeverageManagement;
|
|
272
446
|
return _position;
|
|
273
447
|
}
|
|
274
448
|
function parseAaveV3CloseOnPriceWithMaximumGasPrice(position, parseData) {
|
|
@@ -325,7 +499,8 @@ function parseCompoundV2LeverageManagement(position, parseData) {
|
|
|
325
499
|
mergeId: enums_1.Strategies.Identifiers.Boost,
|
|
326
500
|
};
|
|
327
501
|
}
|
|
328
|
-
_position.strategy.strategyId
|
|
502
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
503
|
+
_position.strategy.strategyId = isEOA ? enums_1.Strategies.IdOverrides.EoaLeverageManagement : enums_1.Strategies.IdOverrides.LeverageManagement;
|
|
329
504
|
return _position;
|
|
330
505
|
}
|
|
331
506
|
function parseCompoundV3LeverageManagement(position, parseData) {
|
|
@@ -341,13 +516,14 @@ function parseCompoundV3LeverageManagement(position, parseData) {
|
|
|
341
516
|
_position.strategyData.decoded.subData = subData;
|
|
342
517
|
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, triggerData.owner.toLowerCase(), triggerData.market);
|
|
343
518
|
const isRepay = [enums_1.Strategies.Identifiers.Repay, enums_1.Strategies.Identifiers.EoaRepay].includes(_position.strategy.strategyId);
|
|
519
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
344
520
|
if (isRepay) {
|
|
345
521
|
_position.specific = {
|
|
346
522
|
triggerRepayRatio: triggerData.ratio,
|
|
347
523
|
targetRepayRatio: subData.targetRatio,
|
|
348
524
|
repayEnabled: true,
|
|
349
525
|
subId1: Number(subId),
|
|
350
|
-
mergeWithId: enums_1.Strategies.Identifiers.Boost,
|
|
526
|
+
mergeWithId: isEOA ? enums_1.Strategies.Identifiers.EoaBoost : enums_1.Strategies.Identifiers.Boost,
|
|
351
527
|
};
|
|
352
528
|
}
|
|
353
529
|
else {
|
|
@@ -356,13 +532,52 @@ function parseCompoundV3LeverageManagement(position, parseData) {
|
|
|
356
532
|
targetBoostRatio: subData.targetRatio,
|
|
357
533
|
boostEnabled: isEnabled,
|
|
358
534
|
subId2: Number(subId),
|
|
359
|
-
mergeId: enums_1.Strategies.Identifiers.Boost,
|
|
535
|
+
mergeId: isEOA ? enums_1.Strategies.Identifiers.EoaBoost : enums_1.Strategies.Identifiers.Boost,
|
|
360
536
|
};
|
|
361
537
|
}
|
|
362
|
-
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
363
538
|
_position.strategy.strategyId = isEOA ? enums_1.Strategies.IdOverrides.EoaLeverageManagement : enums_1.Strategies.IdOverrides.LeverageManagement;
|
|
364
539
|
return _position;
|
|
365
540
|
}
|
|
541
|
+
function parseCompoundV3LeverageManagementOnPrice(position, parseData) {
|
|
542
|
+
const _position = (0, lodash_1.cloneDeep)(position);
|
|
543
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
544
|
+
const triggerData = triggerService.compoundV3PriceTrigger.decode(subStruct.triggerData);
|
|
545
|
+
const subData = subDataService.compoundV3LeverageManagementOnPriceSubData.decode(subStruct.subData);
|
|
546
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
547
|
+
_position.strategyData.decoded.subData = subData;
|
|
548
|
+
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, triggerData.market, triggerData.user, Math.random());
|
|
549
|
+
_position.specific = {
|
|
550
|
+
market: subData.market,
|
|
551
|
+
collToken: subData.collToken,
|
|
552
|
+
baseToken: subData.baseToken,
|
|
553
|
+
ratio: subData.targetRatio,
|
|
554
|
+
price: triggerData.price,
|
|
555
|
+
priceState: triggerData.priceState,
|
|
556
|
+
};
|
|
557
|
+
return _position;
|
|
558
|
+
}
|
|
559
|
+
function parseCompoundV3CloseOnPrice(position, parseData) {
|
|
560
|
+
const _position = (0, lodash_1.cloneDeep)(position);
|
|
561
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
562
|
+
const triggerData = triggerService.compoundV3PriceRangeTrigger.decode(subStruct.triggerData);
|
|
563
|
+
const subData = subDataService.compoundV3CloseSubData.decode(subStruct.subData);
|
|
564
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
565
|
+
_position.strategyData.decoded.subData = subData;
|
|
566
|
+
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, triggerData.market, Math.random());
|
|
567
|
+
const { takeProfitType, stopLossType } = (0, utils_1.getStopLossAndTakeProfitTypeByCloseStrategyType)(+subData.closeType);
|
|
568
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
569
|
+
_position.strategy.strategyId = isEOA ? enums_1.Strategies.Identifiers.EoaCloseOnPrice : enums_1.Strategies.Identifiers.CloseOnPrice;
|
|
570
|
+
_position.specific = {
|
|
571
|
+
market: subData.market,
|
|
572
|
+
collToken: subData.collToken,
|
|
573
|
+
baseToken: subData.baseToken,
|
|
574
|
+
stopLossPrice: triggerData.lowerPrice,
|
|
575
|
+
takeProfitPrice: triggerData.upperPrice,
|
|
576
|
+
takeProfitType,
|
|
577
|
+
stopLossType,
|
|
578
|
+
};
|
|
579
|
+
return _position;
|
|
580
|
+
}
|
|
366
581
|
function parseChickenBondsRebond(position, parseData) {
|
|
367
582
|
const _position = (0, lodash_1.cloneDeep)(position);
|
|
368
583
|
const { subStruct } = parseData.subscriptionEventData;
|
|
@@ -498,26 +713,50 @@ function parseSparkLeverageManagement(position, parseData) {
|
|
|
498
713
|
_position.strategy.strategyId = enums_1.Strategies.IdOverrides.LeverageManagement;
|
|
499
714
|
return _position;
|
|
500
715
|
}
|
|
501
|
-
function
|
|
716
|
+
function parseSparkLeverageManagementOnPrice(position, parseData) {
|
|
502
717
|
const _position = (0, lodash_1.cloneDeep)(position);
|
|
503
718
|
const { subStruct } = parseData.subscriptionEventData;
|
|
504
719
|
const triggerData = triggerService.sparkQuotePriceTrigger.decode(subStruct.triggerData);
|
|
505
|
-
const subData = subDataService.
|
|
720
|
+
const subData = subDataService.sparkLeverageManagementOnPriceSubData.decode(subStruct.subData);
|
|
506
721
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
507
722
|
_position.strategyData.decoded.subData = subData;
|
|
508
|
-
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner,
|
|
723
|
+
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
|
|
509
724
|
_position.specific = {
|
|
725
|
+
// subData
|
|
510
726
|
collAsset: subData.collAsset,
|
|
511
727
|
collAssetId: subData.collAssetId,
|
|
512
728
|
debtAsset: subData.debtAsset,
|
|
513
729
|
debtAssetId: subData.debtAssetId,
|
|
514
|
-
|
|
515
|
-
|
|
730
|
+
ratio: subData.targetRatio,
|
|
731
|
+
// triggerData
|
|
732
|
+
baseToken: triggerData.baseTokenAddr,
|
|
733
|
+
quoteToken: triggerData.quoteTokenAddr,
|
|
516
734
|
price: triggerData.price,
|
|
517
735
|
ratioState: triggerData.ratioState,
|
|
518
736
|
};
|
|
519
|
-
|
|
520
|
-
|
|
737
|
+
return _position;
|
|
738
|
+
}
|
|
739
|
+
function parseSparkCloseOnPrice(position, parseData) {
|
|
740
|
+
const _position = (0, lodash_1.cloneDeep)(position);
|
|
741
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
742
|
+
const triggerData = triggerService.sparkQuotePriceRangeTrigger.decode(subStruct.triggerData);
|
|
743
|
+
const subData = subDataService.sparkCloseGenericSubData.decode(subStruct.subData);
|
|
744
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
745
|
+
_position.strategyData.decoded.subData = subData;
|
|
746
|
+
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
|
|
747
|
+
const { takeProfitType, stopLossType } = (0, utils_1.getStopLossAndTakeProfitTypeByCloseStrategyType)(+subData.closeType);
|
|
748
|
+
_position.specific = {
|
|
749
|
+
collAsset: subData.collAsset,
|
|
750
|
+
collAssetId: subData.collAssetId,
|
|
751
|
+
debtAsset: subData.debtAsset,
|
|
752
|
+
debtAssetId: subData.debtAssetId,
|
|
753
|
+
baseToken: triggerData.collToken,
|
|
754
|
+
quoteToken: triggerData.debtToken,
|
|
755
|
+
stopLossPrice: triggerData.lowerPrice,
|
|
756
|
+
takeProfitPrice: triggerData.upperPrice,
|
|
757
|
+
stopLossType,
|
|
758
|
+
takeProfitType,
|
|
759
|
+
};
|
|
521
760
|
return _position;
|
|
522
761
|
}
|
|
523
762
|
function parseLiquitySavingsLiqProtection(position, parseData) {
|
|
@@ -654,24 +893,32 @@ function parseMorphoBlueLeverageManagementOnPrice(position, parseData) {
|
|
|
654
893
|
};
|
|
655
894
|
return _position;
|
|
656
895
|
}
|
|
657
|
-
function
|
|
896
|
+
function parseMorphoBlueCloseOnPrice(position, parseData) {
|
|
658
897
|
const _position = (0, lodash_1.cloneDeep)(position);
|
|
659
898
|
const { subStruct } = parseData.subscriptionEventData;
|
|
660
|
-
const triggerData = triggerService.
|
|
661
|
-
const subData = subDataService.
|
|
899
|
+
const triggerData = triggerService.morphoBluePriceRangeTrigger.decode(subStruct.triggerData);
|
|
900
|
+
const subData = subDataService.morphoBlueCloseOnPriceSubData.decode(subStruct.subData);
|
|
662
901
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
663
902
|
_position.strategyData.decoded.subData = subData;
|
|
664
903
|
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, Math.random());
|
|
904
|
+
const marketIdEncodedData = web3.eth.abi.encodeParameters(['address', 'address', 'address', 'address', 'uint256'], [
|
|
905
|
+
subData.loanToken,
|
|
906
|
+
subData.collToken,
|
|
907
|
+
subData.oracle,
|
|
908
|
+
subData.irm,
|
|
909
|
+
subData.lltv,
|
|
910
|
+
]);
|
|
911
|
+
const marketId = web3.utils.keccak256(marketIdEncodedData);
|
|
912
|
+
const { takeProfitType, stopLossType } = (0, utils_1.getStopLossAndTakeProfitTypeByCloseStrategyType)(+subData.closeType);
|
|
665
913
|
_position.specific = {
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
ratio: subData.targetRatio,
|
|
914
|
+
subHash: _position.subHash,
|
|
915
|
+
marketId,
|
|
916
|
+
collAsset: subData.collToken,
|
|
917
|
+
debtAsset: subData.loanToken,
|
|
918
|
+
stopLossPrice: triggerData.lowerPrice,
|
|
919
|
+
takeProfitPrice: triggerData.upperPrice,
|
|
920
|
+
stopLossType,
|
|
921
|
+
takeProfitType,
|
|
675
922
|
};
|
|
676
923
|
return _position;
|
|
677
924
|
}
|
|
@@ -688,7 +935,6 @@ function parseLiquityV2CloseOnPrice(position, parseData) {
|
|
|
688
935
|
// - Only TakeProfit
|
|
689
936
|
// - Only StopLoss
|
|
690
937
|
// - Both
|
|
691
|
-
// TODO: see on frontend what specific data we need here because stop-loss and take-profit is one bundle now
|
|
692
938
|
_position.strategy.strategyId = enums_1.Strategies.Identifiers.CloseOnPrice;
|
|
693
939
|
_position.specific = {
|
|
694
940
|
market: subData.market,
|
|
@@ -813,6 +1059,26 @@ const parsingMethodsMapping = {
|
|
|
813
1059
|
[enums_1.Strategies.Identifiers.CloseToCollateralWithGasPrice]: parseAaveV3CloseOnPriceWithMaximumGasPrice,
|
|
814
1060
|
[enums_1.Strategies.Identifiers.OpenOrderFromCollateral]: parseAaveV3LeverageManagementOnPrice,
|
|
815
1061
|
[enums_1.Strategies.Identifiers.RepayOnPrice]: parseAaveV3LeverageManagementOnPrice,
|
|
1062
|
+
[enums_1.Strategies.Identifiers.EoaRepay]: parseAaveV3LeverageManagement,
|
|
1063
|
+
[enums_1.Strategies.Identifiers.EoaBoost]: parseAaveV3LeverageManagement,
|
|
1064
|
+
[enums_1.Strategies.Identifiers.EoaRepayOnPrice]: parseAaveV3LeverageManagementOnPrice,
|
|
1065
|
+
[enums_1.Strategies.Identifiers.EoaBoostOnPrice]: parseAaveV3LeverageManagementOnPrice,
|
|
1066
|
+
[enums_1.Strategies.Identifiers.EoaCloseOnPrice]: parseAaveV3CloseOnPrice,
|
|
1067
|
+
[enums_1.Strategies.Identifiers.CollateralSwitch]: parseAaveV3CollateralSwitch,
|
|
1068
|
+
},
|
|
1069
|
+
[enums_1.ProtocolIdentifiers.StrategiesAutomation.AaveV4]: {
|
|
1070
|
+
[enums_1.Strategies.Identifiers.Repay]: parseAaveV4LeverageManagement,
|
|
1071
|
+
[enums_1.Strategies.Identifiers.Boost]: parseAaveV4LeverageManagement,
|
|
1072
|
+
[enums_1.Strategies.Identifiers.RepayOnPrice]: parseAaveV4LeverageManagementOnPrice,
|
|
1073
|
+
[enums_1.Strategies.Identifiers.BoostOnPrice]: parseAaveV4LeverageManagementOnPrice,
|
|
1074
|
+
[enums_1.Strategies.Identifiers.CloseOnPrice]: parseAaveV4CloseOnPrice,
|
|
1075
|
+
[enums_1.Strategies.Identifiers.EoaRepay]: parseAaveV4LeverageManagement,
|
|
1076
|
+
[enums_1.Strategies.Identifiers.EoaBoost]: parseAaveV4LeverageManagement,
|
|
1077
|
+
[enums_1.Strategies.Identifiers.EoaRepayOnPrice]: parseAaveV4LeverageManagementOnPrice,
|
|
1078
|
+
[enums_1.Strategies.Identifiers.EoaBoostOnPrice]: parseAaveV4LeverageManagementOnPrice,
|
|
1079
|
+
[enums_1.Strategies.Identifiers.EoaCloseOnPrice]: parseAaveV4CloseOnPrice,
|
|
1080
|
+
[enums_1.Strategies.Identifiers.CollateralSwitch]: parseAaveV4CollateralSwitch,
|
|
1081
|
+
[enums_1.Strategies.Identifiers.EoaCollateralSwitch]: parseAaveV4CollateralSwitch,
|
|
816
1082
|
},
|
|
817
1083
|
[enums_1.ProtocolIdentifiers.StrategiesAutomation.CompoundV2]: {
|
|
818
1084
|
[enums_1.Strategies.Identifiers.Repay]: parseCompoundV2LeverageManagement,
|
|
@@ -823,6 +1089,12 @@ const parsingMethodsMapping = {
|
|
|
823
1089
|
[enums_1.Strategies.Identifiers.Boost]: parseCompoundV3LeverageManagement,
|
|
824
1090
|
[enums_1.Strategies.Identifiers.EoaRepay]: parseCompoundV3LeverageManagement,
|
|
825
1091
|
[enums_1.Strategies.Identifiers.EoaBoost]: parseCompoundV3LeverageManagement,
|
|
1092
|
+
[enums_1.Strategies.Identifiers.RepayOnPrice]: parseCompoundV3LeverageManagementOnPrice,
|
|
1093
|
+
[enums_1.Strategies.Identifiers.BoostOnPrice]: parseCompoundV3LeverageManagementOnPrice,
|
|
1094
|
+
[enums_1.Strategies.Identifiers.EoaRepayOnPrice]: parseCompoundV3LeverageManagementOnPrice,
|
|
1095
|
+
[enums_1.Strategies.Identifiers.EoaBoostOnPrice]: parseCompoundV3LeverageManagementOnPrice,
|
|
1096
|
+
[enums_1.Strategies.Identifiers.CloseOnPrice]: parseCompoundV3CloseOnPrice,
|
|
1097
|
+
[enums_1.Strategies.Identifiers.EoaCloseOnPrice]: parseCompoundV3CloseOnPrice,
|
|
826
1098
|
},
|
|
827
1099
|
[enums_1.ProtocolIdentifiers.StrategiesAutomation.ChickenBonds]: {
|
|
828
1100
|
[enums_1.Strategies.Identifiers.Rebond]: parseChickenBondsRebond,
|
|
@@ -838,8 +1110,10 @@ const parsingMethodsMapping = {
|
|
|
838
1110
|
[enums_1.ProtocolIdentifiers.StrategiesAutomation.Spark]: {
|
|
839
1111
|
[enums_1.Strategies.Identifiers.Repay]: parseSparkLeverageManagement,
|
|
840
1112
|
[enums_1.Strategies.Identifiers.Boost]: parseSparkLeverageManagement,
|
|
841
|
-
[enums_1.Strategies.Identifiers.
|
|
842
|
-
[enums_1.Strategies.Identifiers.
|
|
1113
|
+
[enums_1.Strategies.Identifiers.RepayOnPrice]: parseSparkLeverageManagementOnPrice,
|
|
1114
|
+
[enums_1.Strategies.Identifiers.BoostOnPrice]: parseSparkLeverageManagementOnPrice,
|
|
1115
|
+
[enums_1.Strategies.Identifiers.CloseOnPrice]: parseSparkCloseOnPrice,
|
|
1116
|
+
[enums_1.Strategies.Identifiers.CollateralSwitch]: parseSparkCollateralSwitch,
|
|
843
1117
|
},
|
|
844
1118
|
[enums_1.ProtocolIdentifiers.StrategiesAutomation.CrvUSD]: {
|
|
845
1119
|
[enums_1.Strategies.Identifiers.Repay]: parseCrvUSDLeverageManagement,
|
|
@@ -852,6 +1126,7 @@ const parsingMethodsMapping = {
|
|
|
852
1126
|
[enums_1.Strategies.Identifiers.EoaRepay]: parseMorphoBlueLeverageManagement,
|
|
853
1127
|
[enums_1.Strategies.Identifiers.EoaBoost]: parseMorphoBlueLeverageManagement,
|
|
854
1128
|
[enums_1.Strategies.Identifiers.BoostOnPrice]: parseMorphoBlueLeverageManagementOnPrice,
|
|
1129
|
+
[enums_1.Strategies.Identifiers.CloseOnPrice]: parseMorphoBlueCloseOnPrice,
|
|
855
1130
|
},
|
|
856
1131
|
[enums_1.ProtocolIdentifiers.StrategiesAutomation.FluidT1]: {
|
|
857
1132
|
[enums_1.Strategies.Identifiers.Repay]: parseFluidT1LeverageManagement,
|