@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
|
@@ -7,7 +7,9 @@ import type {
|
|
|
7
7
|
Position, ParseData, StrategiesToProtocolVersionMapping, BundleOrStrategy, StrategyOrBundleIds,
|
|
8
8
|
BundleInfoUnion, StrategyInfoUnion,
|
|
9
9
|
} from '../types';
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
ChainId, ProtocolIdentifiers, RatioState, Strategies,
|
|
12
|
+
} from '../types/enums';
|
|
11
13
|
|
|
12
14
|
import {
|
|
13
15
|
getPositionId, getRatioStateInfoForAaveCloseStrategy, getStopLossAndTakeProfitTypeByCloseStrategyType, isRatioStateOver, wethToEthByAddress,
|
|
@@ -17,10 +19,6 @@ import * as triggerService from './triggerService';
|
|
|
17
19
|
|
|
18
20
|
const web3 = new Web3();
|
|
19
21
|
|
|
20
|
-
const SPARK_MARKET_ADDRESSES = {
|
|
21
|
-
[ChainId.Ethereum]: '0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE',
|
|
22
|
-
};
|
|
23
|
-
|
|
24
22
|
const AAVE_V3_MARKET_ADDRESSES = {
|
|
25
23
|
[ChainId.Ethereum]: '0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e',
|
|
26
24
|
[ChainId.Optimism]: '0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb',
|
|
@@ -231,26 +229,33 @@ function parseAaveV2LeverageManagement(position: Position.Automated, parseData:
|
|
|
231
229
|
function parseAaveV3LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
232
230
|
const _position = cloneDeep(position);
|
|
233
231
|
|
|
234
|
-
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
232
|
+
const { subStruct, subId, subHash } = parseData.subscriptionEventData;
|
|
235
233
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
236
234
|
|
|
237
235
|
const triggerData = triggerService.aaveV3RatioTrigger.decode(subStruct.triggerData);
|
|
238
|
-
const
|
|
236
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
237
|
+
let subData;
|
|
238
|
+
if (isEOA) {
|
|
239
|
+
subData = subDataService.aaveV3LeverageManagementSubDataWithoutSubProxy.decode(subStruct.subData);
|
|
240
|
+
} else {
|
|
241
|
+
subData = subDataService.aaveV3LeverageManagementSubData.decode(subStruct.subData);
|
|
242
|
+
}
|
|
239
243
|
|
|
240
244
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
241
245
|
_position.strategyData.decoded.subData = subData;
|
|
242
246
|
|
|
243
247
|
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.market);
|
|
244
248
|
|
|
245
|
-
const isRepay = _position.strategy.strategyId
|
|
249
|
+
const isRepay = [Strategies.Identifiers.Repay, Strategies.Identifiers.EoaRepay].includes(_position.strategy.strategyId as Strategies.Identifiers);
|
|
246
250
|
|
|
247
251
|
if (isRepay) {
|
|
248
252
|
_position.specific = {
|
|
249
253
|
triggerRepayRatio: triggerData.ratio,
|
|
250
254
|
targetRepayRatio: subData.targetRatio,
|
|
251
|
-
repayEnabled:
|
|
255
|
+
repayEnabled: isEnabled,
|
|
252
256
|
subId1: Number(subId),
|
|
253
|
-
mergeWithId: Strategies.Identifiers.Boost,
|
|
257
|
+
mergeWithId: isEOA ? Strategies.Identifiers.EoaBoost : Strategies.Identifiers.Boost,
|
|
258
|
+
subHashRepay: subHash,
|
|
254
259
|
};
|
|
255
260
|
} else {
|
|
256
261
|
_position.specific = {
|
|
@@ -258,38 +263,161 @@ function parseAaveV3LeverageManagement(position: Position.Automated, parseData:
|
|
|
258
263
|
targetBoostRatio: subData.targetRatio,
|
|
259
264
|
boostEnabled: isEnabled,
|
|
260
265
|
subId2: Number(subId),
|
|
261
|
-
mergeId: Strategies.Identifiers.Boost,
|
|
266
|
+
mergeId: isEOA ? Strategies.Identifiers.EoaBoost : Strategies.Identifiers.Boost,
|
|
267
|
+
subHashBoost: subHash,
|
|
262
268
|
};
|
|
263
269
|
}
|
|
270
|
+
if (!isEOA) {
|
|
271
|
+
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
272
|
+
} else {
|
|
273
|
+
_position.strategy.strategyId = Strategies.IdOverrides.EoaLeverageManagement;
|
|
274
|
+
}
|
|
264
275
|
|
|
265
|
-
_position
|
|
276
|
+
return _position;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function parseAaveV3LeverageManagementOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
280
|
+
const _position = cloneDeep(position);
|
|
281
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
282
|
+
|
|
283
|
+
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
284
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
285
|
+
let subData;
|
|
286
|
+
if (isEOA) {
|
|
287
|
+
subData = subDataService.aaveV3LeverageManagementOnPriceGeneric.decode(subStruct.subData);
|
|
288
|
+
} else {
|
|
289
|
+
subData = subDataService.aaveV3LeverageManagementOnPriceSubData.decode(subStruct.subData);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
293
|
+
_position.strategyData.decoded.subData = subData;
|
|
294
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, Math.random());
|
|
295
|
+
|
|
296
|
+
_position.specific = {
|
|
297
|
+
collAsset: subData.collAsset,
|
|
298
|
+
debtAsset: subData.debtAsset,
|
|
299
|
+
baseToken: triggerData.baseTokenAddress,
|
|
300
|
+
quoteToken: triggerData.quoteTokenAddress,
|
|
301
|
+
price: triggerData.price,
|
|
302
|
+
ratioState: triggerData.ratioState,
|
|
303
|
+
debtAssetId: subData.debtAssetId,
|
|
304
|
+
collAssetId: subData.collAssetId,
|
|
305
|
+
ratio: subData.targetRatio,
|
|
306
|
+
};
|
|
266
307
|
|
|
267
308
|
return _position;
|
|
268
309
|
}
|
|
269
310
|
|
|
270
|
-
function
|
|
311
|
+
function parseAaveV3CloseOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
271
312
|
const _position = cloneDeep(position);
|
|
272
313
|
|
|
273
|
-
const { subStruct
|
|
274
|
-
const { isEnabled } = parseData.strategiesSubsData;
|
|
314
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
275
315
|
|
|
276
|
-
const
|
|
277
|
-
|
|
316
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
317
|
+
|
|
318
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, AAVE_V3_MARKET_ADDRESSES[_position.chainId]);
|
|
319
|
+
|
|
320
|
+
if (isEOA) {
|
|
321
|
+
const triggerData = triggerService.aaveV3QuotePriceRangeTrigger.decode(subStruct.triggerData);
|
|
322
|
+
const subData = subDataService.aaveV3CloseGenericSubData.decode(subStruct.subData);
|
|
323
|
+
|
|
324
|
+
const { takeProfitType, stopLossType } = getStopLossAndTakeProfitTypeByCloseStrategyType(+subData.closeType);
|
|
278
325
|
|
|
326
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
327
|
+
_position.strategyData.decoded.subData = subData;
|
|
328
|
+
|
|
329
|
+
_position.specific = {
|
|
330
|
+
collAsset: subData.collAsset,
|
|
331
|
+
collAssetId: subData.collAssetId,
|
|
332
|
+
debtAsset: subData.debtAsset,
|
|
333
|
+
debtAssetId: subData.debtAssetId,
|
|
334
|
+
baseToken: triggerData.collToken,
|
|
335
|
+
quoteToken: triggerData.debtToken,
|
|
336
|
+
stopLossPrice: triggerData.lowerPrice,
|
|
337
|
+
takeProfitPrice: triggerData.upperPrice,
|
|
338
|
+
stopLossType,
|
|
339
|
+
takeProfitType,
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
_position.strategy.strategyId = Strategies.Identifiers.EoaCloseOnPrice;
|
|
343
|
+
} else {
|
|
344
|
+
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
345
|
+
const subData = subDataService.aaveV3QuotePriceSubData.decode(subStruct.subData);
|
|
346
|
+
|
|
347
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
348
|
+
_position.strategyData.decoded.subData = subData;
|
|
349
|
+
|
|
350
|
+
_position.specific = {
|
|
351
|
+
collAsset: subData.collAsset,
|
|
352
|
+
collAssetId: subData.collAssetId,
|
|
353
|
+
debtAsset: subData.debtAsset,
|
|
354
|
+
debtAssetId: subData.debtAssetId,
|
|
355
|
+
baseToken: triggerData.baseTokenAddress,
|
|
356
|
+
quoteToken: triggerData.quoteTokenAddress,
|
|
357
|
+
price: triggerData.price,
|
|
358
|
+
ratioState: triggerData.ratioState,
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
const { ratioState } = getRatioStateInfoForAaveCloseStrategy(
|
|
362
|
+
_position.specific.ratioState,
|
|
363
|
+
wethToEthByAddress(_position.specific.collAsset, parseData.chainId),
|
|
364
|
+
wethToEthByAddress(_position.specific.debtAsset, parseData.chainId),
|
|
365
|
+
parseData.chainId,
|
|
366
|
+
);
|
|
367
|
+
|
|
368
|
+
_position.strategy.strategyId = isRatioStateOver(ratioState)
|
|
369
|
+
? Strategies.IdOverrides.TakeProfit
|
|
370
|
+
: Strategies.IdOverrides.StopLoss;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
return _position;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function parseAaveV3CollateralSwitch(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
377
|
+
const _position = cloneDeep(position);
|
|
378
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
379
|
+
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
380
|
+
const subData = subDataService.aaveV3CollateralSwitchSubData.decode(subStruct.subData);
|
|
279
381
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
280
382
|
_position.strategyData.decoded.subData = subData;
|
|
383
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
|
|
281
384
|
|
|
282
|
-
|
|
385
|
+
return _position;
|
|
386
|
+
}
|
|
283
387
|
|
|
284
|
-
|
|
388
|
+
function parseSparkCollateralSwitch(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
389
|
+
const _position = cloneDeep(position);
|
|
390
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
391
|
+
const triggerData = triggerService.sparkQuotePriceTrigger.decode(subStruct.triggerData);
|
|
392
|
+
const subData = subDataService.sparkCollateralSwitchSubData.decode(subStruct.subData);
|
|
393
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
394
|
+
_position.strategyData.decoded.subData = subData;
|
|
395
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
|
|
396
|
+
return _position;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
function parseAaveV4LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
400
|
+
const _position = cloneDeep(position);
|
|
401
|
+
const { subStruct, subId, subHash } = parseData.subscriptionEventData;
|
|
402
|
+
const { isEnabled } = parseData.strategiesSubsData;
|
|
403
|
+
const triggerData = triggerService.aaveV4RatioTrigger.decode(subStruct.triggerData);
|
|
404
|
+
const subData = subDataService.aaveV4LeverageManagementSubData.decode(subStruct.subData);
|
|
405
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
406
|
+
const isRepay = [Strategies.Identifiers.Repay, Strategies.Identifiers.EoaRepay].includes(_position.strategy.strategyId as Strategies.Identifiers);
|
|
407
|
+
|
|
408
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
409
|
+
_position.strategyData.decoded.subData = subData;
|
|
410
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.spoke);
|
|
411
|
+
_position.strategy.strategyId = isEOA ? Strategies.IdOverrides.EoaLeverageManagement : Strategies.IdOverrides.LeverageManagement;
|
|
285
412
|
|
|
286
413
|
if (isRepay) {
|
|
287
414
|
_position.specific = {
|
|
288
415
|
triggerRepayRatio: triggerData.ratio,
|
|
289
416
|
targetRepayRatio: subData.targetRatio,
|
|
290
|
-
repayEnabled:
|
|
417
|
+
repayEnabled: isEnabled,
|
|
291
418
|
subId1: Number(subId),
|
|
292
|
-
mergeWithId: Strategies.Identifiers.Boost,
|
|
419
|
+
mergeWithId: isEOA ? Strategies.Identifiers.EoaBoost : Strategies.Identifiers.Boost,
|
|
420
|
+
subHashRepay: subHash,
|
|
293
421
|
};
|
|
294
422
|
} else {
|
|
295
423
|
_position.specific = {
|
|
@@ -297,47 +425,114 @@ function parseMorphoAaveV2LeverageManagement(position: Position.Automated, parse
|
|
|
297
425
|
targetBoostRatio: subData.targetRatio,
|
|
298
426
|
boostEnabled: isEnabled,
|
|
299
427
|
subId2: Number(subId),
|
|
300
|
-
mergeId: Strategies.Identifiers.Boost,
|
|
428
|
+
mergeId: isEOA ? Strategies.Identifiers.EoaBoost : Strategies.Identifiers.Boost,
|
|
429
|
+
subHashBoost: subHash,
|
|
301
430
|
};
|
|
302
431
|
}
|
|
303
432
|
|
|
304
|
-
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
305
|
-
|
|
306
433
|
return _position;
|
|
307
434
|
}
|
|
308
435
|
|
|
309
|
-
function
|
|
436
|
+
function parseAaveV4LeverageManagementOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
310
437
|
const _position = cloneDeep(position);
|
|
311
|
-
|
|
312
438
|
const { subStruct } = parseData.subscriptionEventData;
|
|
313
|
-
|
|
314
|
-
const
|
|
315
|
-
const
|
|
439
|
+
const triggerData = triggerService.aaveV4QuotePriceTrigger.decode(subStruct.triggerData);
|
|
440
|
+
const subData = subDataService.aaveV4LeverageManagementOnPriceSubData.decode(subStruct.subData);
|
|
441
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
316
442
|
|
|
317
443
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
318
444
|
_position.strategyData.decoded.subData = subData;
|
|
319
|
-
|
|
320
|
-
_position.
|
|
445
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.spoke);
|
|
446
|
+
_position.strategy.strategyId = isEOA ? Strategies.IdOverrides.EoaLeverageManagementOnPrice : Strategies.IdOverrides.LeverageManagementOnPrice;
|
|
321
447
|
|
|
322
448
|
_position.specific = {
|
|
323
449
|
collAsset: subData.collAsset,
|
|
324
450
|
collAssetId: subData.collAssetId,
|
|
325
451
|
debtAsset: subData.debtAsset,
|
|
326
452
|
debtAssetId: subData.debtAssetId,
|
|
327
|
-
baseToken: triggerData.baseTokenAddress,
|
|
328
|
-
quoteToken: triggerData.quoteTokenAddress,
|
|
329
453
|
price: triggerData.price,
|
|
330
454
|
ratioState: triggerData.ratioState,
|
|
455
|
+
ratio: subData.targetRatio,
|
|
331
456
|
};
|
|
332
457
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
458
|
+
return _position;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
function parseAaveV4CloseOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
462
|
+
const _position = cloneDeep(position);
|
|
463
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
464
|
+
const triggerData = triggerService.aaveV4QuotePriceRangeTrigger.decode(subStruct.triggerData);
|
|
465
|
+
const subData = subDataService.aaveV4CloseSubData.decode(subStruct.subData);
|
|
466
|
+
const { takeProfitType, stopLossType } = getStopLossAndTakeProfitTypeByCloseStrategyType(+subData.closeType);
|
|
467
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
468
|
+
|
|
469
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
470
|
+
_position.strategyData.decoded.subData = subData;
|
|
471
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.spoke);
|
|
472
|
+
_position.strategy.strategyId = isEOA ? Strategies.Identifiers.EoaCloseOnPrice : Strategies.Identifiers.CloseOnPrice;
|
|
473
|
+
|
|
474
|
+
_position.specific = {
|
|
475
|
+
collAsset: subData.collAsset,
|
|
476
|
+
collAssetId: subData.collAssetId,
|
|
477
|
+
debtAsset: subData.debtAsset,
|
|
478
|
+
debtAssetId: subData.debtAssetId,
|
|
479
|
+
stopLossPrice: triggerData.lowerPrice,
|
|
480
|
+
takeProfitPrice: triggerData.upperPrice,
|
|
481
|
+
stopLossType,
|
|
482
|
+
takeProfitType,
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
return _position;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
function parseAaveV4CollateralSwitch(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
489
|
+
const _position = cloneDeep(position);
|
|
490
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
491
|
+
const triggerData = triggerService.aaveV4QuotePriceTrigger.decode(subStruct.triggerData);
|
|
492
|
+
const subData = subDataService.aaveV4CollateralSwitchSubData.decode(subStruct.subData);
|
|
493
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
494
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
495
|
+
_position.strategyData.decoded.subData = subData;
|
|
496
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.spoke);
|
|
497
|
+
_position.strategy.strategyId = isEOA ? Strategies.Identifiers.EoaCollateralSwitch : Strategies.Identifiers.CollateralSwitch;
|
|
498
|
+
return _position;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
function parseMorphoAaveV2LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
502
|
+
const _position = cloneDeep(position);
|
|
503
|
+
|
|
504
|
+
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
505
|
+
const { isEnabled } = parseData.strategiesSubsData;
|
|
506
|
+
|
|
507
|
+
const triggerData = triggerService.morphoAaveV2RatioTrigger.decode(subStruct.triggerData);
|
|
508
|
+
const subData = subDataService.morphoAaveV2LeverageManagementSubData.decode(subStruct.subData);
|
|
509
|
+
|
|
510
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
511
|
+
_position.strategyData.decoded.subData = subData;
|
|
512
|
+
|
|
513
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner);
|
|
339
514
|
|
|
340
|
-
_position.strategy.strategyId
|
|
515
|
+
const isRepay = _position.strategy.strategyId === Strategies.Identifiers.Repay;
|
|
516
|
+
|
|
517
|
+
if (isRepay) {
|
|
518
|
+
_position.specific = {
|
|
519
|
+
triggerRepayRatio: triggerData.ratio,
|
|
520
|
+
targetRepayRatio: subData.targetRatio,
|
|
521
|
+
repayEnabled: true,
|
|
522
|
+
subId1: Number(subId),
|
|
523
|
+
mergeWithId: Strategies.Identifiers.Boost,
|
|
524
|
+
};
|
|
525
|
+
} else {
|
|
526
|
+
_position.specific = {
|
|
527
|
+
triggerBoostRatio: triggerData.ratio,
|
|
528
|
+
targetBoostRatio: subData.targetRatio,
|
|
529
|
+
boostEnabled: isEnabled,
|
|
530
|
+
subId2: Number(subId),
|
|
531
|
+
mergeId: Strategies.Identifiers.Boost,
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
341
536
|
|
|
342
537
|
return _position;
|
|
343
538
|
}
|
|
@@ -416,7 +611,8 @@ function parseCompoundV2LeverageManagement(position: Position.Automated, parseDa
|
|
|
416
611
|
};
|
|
417
612
|
}
|
|
418
613
|
|
|
419
|
-
_position.strategy.strategyId
|
|
614
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
615
|
+
_position.strategy.strategyId = isEOA ? Strategies.IdOverrides.EoaLeverageManagement : Strategies.IdOverrides.LeverageManagement;
|
|
420
616
|
|
|
421
617
|
return _position;
|
|
422
618
|
}
|
|
@@ -441,13 +637,15 @@ function parseCompoundV3LeverageManagement(position: Position.Automated, parseDa
|
|
|
441
637
|
|
|
442
638
|
const isRepay = [Strategies.Identifiers.Repay, Strategies.Identifiers.EoaRepay].includes(_position.strategy.strategyId as Strategies.Identifiers);
|
|
443
639
|
|
|
640
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
641
|
+
|
|
444
642
|
if (isRepay) {
|
|
445
643
|
_position.specific = {
|
|
446
644
|
triggerRepayRatio: triggerData.ratio,
|
|
447
645
|
targetRepayRatio: subData.targetRatio,
|
|
448
646
|
repayEnabled: true,
|
|
449
647
|
subId1: Number(subId),
|
|
450
|
-
mergeWithId: Strategies.Identifiers.Boost,
|
|
648
|
+
mergeWithId: isEOA ? Strategies.Identifiers.EoaBoost : Strategies.Identifiers.Boost,
|
|
451
649
|
};
|
|
452
650
|
} else {
|
|
453
651
|
_position.specific = {
|
|
@@ -455,13 +653,64 @@ function parseCompoundV3LeverageManagement(position: Position.Automated, parseDa
|
|
|
455
653
|
targetBoostRatio: subData.targetRatio,
|
|
456
654
|
boostEnabled: isEnabled,
|
|
457
655
|
subId2: Number(subId),
|
|
458
|
-
mergeId: Strategies.Identifiers.Boost,
|
|
656
|
+
mergeId: isEOA ? Strategies.Identifiers.EoaBoost : Strategies.Identifiers.Boost,
|
|
459
657
|
};
|
|
460
658
|
}
|
|
461
659
|
|
|
462
|
-
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
463
660
|
_position.strategy.strategyId = isEOA ? Strategies.IdOverrides.EoaLeverageManagement : Strategies.IdOverrides.LeverageManagement;
|
|
464
661
|
|
|
662
|
+
return _position;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
function parseCompoundV3LeverageManagementOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
666
|
+
const _position = cloneDeep(position);
|
|
667
|
+
|
|
668
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
669
|
+
|
|
670
|
+
const triggerData = triggerService.compoundV3PriceTrigger.decode(subStruct.triggerData);
|
|
671
|
+
const subData = subDataService.compoundV3LeverageManagementOnPriceSubData.decode(subStruct.subData);
|
|
672
|
+
|
|
673
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
674
|
+
_position.strategyData.decoded.subData = subData;
|
|
675
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, triggerData.market, triggerData.user, Math.random());
|
|
676
|
+
|
|
677
|
+
_position.specific = {
|
|
678
|
+
market: subData.market,
|
|
679
|
+
collToken: subData.collToken,
|
|
680
|
+
baseToken: subData.baseToken,
|
|
681
|
+
ratio: subData.targetRatio,
|
|
682
|
+
price: triggerData.price,
|
|
683
|
+
priceState: triggerData.priceState,
|
|
684
|
+
};
|
|
685
|
+
|
|
686
|
+
return _position;
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
function parseCompoundV3CloseOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
690
|
+
const _position = cloneDeep(position);
|
|
691
|
+
|
|
692
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
693
|
+
|
|
694
|
+
const triggerData = triggerService.compoundV3PriceRangeTrigger.decode(subStruct.triggerData);
|
|
695
|
+
const subData = subDataService.compoundV3CloseSubData.decode(subStruct.subData);
|
|
696
|
+
|
|
697
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
698
|
+
_position.strategyData.decoded.subData = subData;
|
|
699
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, triggerData.market, Math.random());
|
|
700
|
+
|
|
701
|
+
const { takeProfitType, stopLossType } = getStopLossAndTakeProfitTypeByCloseStrategyType(+subData.closeType);
|
|
702
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
703
|
+
_position.strategy.strategyId = isEOA ? Strategies.Identifiers.EoaCloseOnPrice : Strategies.Identifiers.CloseOnPrice;
|
|
704
|
+
|
|
705
|
+
_position.specific = {
|
|
706
|
+
market: subData.market,
|
|
707
|
+
collToken: subData.collToken,
|
|
708
|
+
baseToken: subData.baseToken,
|
|
709
|
+
stopLossPrice: triggerData.lowerPrice,
|
|
710
|
+
takeProfitPrice: triggerData.upperPrice,
|
|
711
|
+
takeProfitType,
|
|
712
|
+
stopLossType,
|
|
713
|
+
};
|
|
465
714
|
|
|
466
715
|
return _position;
|
|
467
716
|
}
|
|
@@ -648,38 +897,61 @@ function parseSparkLeverageManagement(position: Position.Automated, parseData: P
|
|
|
648
897
|
return _position;
|
|
649
898
|
}
|
|
650
899
|
|
|
651
|
-
function
|
|
900
|
+
function parseSparkLeverageManagementOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
652
901
|
const _position = cloneDeep(position);
|
|
653
|
-
|
|
654
902
|
const { subStruct } = parseData.subscriptionEventData;
|
|
655
903
|
|
|
656
904
|
const triggerData = triggerService.sparkQuotePriceTrigger.decode(subStruct.triggerData);
|
|
657
|
-
const subData = subDataService.
|
|
905
|
+
const subData = subDataService.sparkLeverageManagementOnPriceSubData.decode(subStruct.subData);
|
|
658
906
|
|
|
659
907
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
660
908
|
_position.strategyData.decoded.subData = subData;
|
|
661
909
|
|
|
662
|
-
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner,
|
|
910
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
|
|
663
911
|
|
|
664
912
|
_position.specific = {
|
|
913
|
+
// subData
|
|
665
914
|
collAsset: subData.collAsset,
|
|
666
915
|
collAssetId: subData.collAssetId,
|
|
667
916
|
debtAsset: subData.debtAsset,
|
|
668
917
|
debtAssetId: subData.debtAssetId,
|
|
669
|
-
|
|
670
|
-
|
|
918
|
+
ratio: subData.targetRatio,
|
|
919
|
+
// triggerData
|
|
920
|
+
baseToken: triggerData.baseTokenAddr,
|
|
921
|
+
quoteToken: triggerData.quoteTokenAddr,
|
|
671
922
|
price: triggerData.price,
|
|
672
923
|
ratioState: triggerData.ratioState,
|
|
673
924
|
};
|
|
674
925
|
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
wethToEthByAddress(_position.specific.collAsset, parseData.chainId),
|
|
678
|
-
wethToEthByAddress(_position.specific.debtAsset, parseData.chainId),
|
|
679
|
-
parseData.chainId,
|
|
680
|
-
);
|
|
926
|
+
return _position;
|
|
927
|
+
}
|
|
681
928
|
|
|
682
|
-
|
|
929
|
+
function parseSparkCloseOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
930
|
+
const _position = cloneDeep(position);
|
|
931
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
932
|
+
|
|
933
|
+
const triggerData = triggerService.sparkQuotePriceRangeTrigger.decode(subStruct.triggerData);
|
|
934
|
+
const subData = subDataService.sparkCloseGenericSubData.decode(subStruct.subData);
|
|
935
|
+
|
|
936
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
937
|
+
_position.strategyData.decoded.subData = subData;
|
|
938
|
+
|
|
939
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
|
|
940
|
+
|
|
941
|
+
const { takeProfitType, stopLossType } = getStopLossAndTakeProfitTypeByCloseStrategyType(+subData.closeType);
|
|
942
|
+
|
|
943
|
+
_position.specific = {
|
|
944
|
+
collAsset: subData.collAsset,
|
|
945
|
+
collAssetId: subData.collAssetId,
|
|
946
|
+
debtAsset: subData.debtAsset,
|
|
947
|
+
debtAssetId: subData.debtAssetId,
|
|
948
|
+
baseToken: triggerData.collToken,
|
|
949
|
+
quoteToken: triggerData.debtToken,
|
|
950
|
+
stopLossPrice: triggerData.lowerPrice,
|
|
951
|
+
takeProfitPrice: triggerData.upperPrice,
|
|
952
|
+
stopLossType,
|
|
953
|
+
takeProfitType,
|
|
954
|
+
};
|
|
683
955
|
|
|
684
956
|
return _position;
|
|
685
957
|
}
|
|
@@ -861,28 +1133,43 @@ function parseMorphoBlueLeverageManagementOnPrice(position: Position.Automated,
|
|
|
861
1133
|
return _position;
|
|
862
1134
|
}
|
|
863
1135
|
|
|
864
|
-
function
|
|
1136
|
+
function parseMorphoBlueCloseOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
865
1137
|
const _position = cloneDeep(position);
|
|
866
1138
|
|
|
867
1139
|
const { subStruct } = parseData.subscriptionEventData;
|
|
868
1140
|
|
|
869
|
-
const triggerData = triggerService.
|
|
870
|
-
const subData = subDataService.
|
|
1141
|
+
const triggerData = triggerService.morphoBluePriceRangeTrigger.decode(subStruct.triggerData);
|
|
1142
|
+
const subData = subDataService.morphoBlueCloseOnPriceSubData.decode(subStruct.subData);
|
|
871
1143
|
|
|
872
1144
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
873
1145
|
_position.strategyData.decoded.subData = subData;
|
|
1146
|
+
|
|
874
1147
|
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, Math.random());
|
|
875
1148
|
|
|
1149
|
+
const marketIdEncodedData = web3.eth.abi.encodeParameters(
|
|
1150
|
+
['address', 'address', 'address', 'address', 'uint256'],
|
|
1151
|
+
[
|
|
1152
|
+
subData.loanToken,
|
|
1153
|
+
subData.collToken,
|
|
1154
|
+
subData.oracle,
|
|
1155
|
+
subData.irm,
|
|
1156
|
+
subData.lltv,
|
|
1157
|
+
],
|
|
1158
|
+
);
|
|
1159
|
+
|
|
1160
|
+
const marketId = web3.utils.keccak256(marketIdEncodedData);
|
|
1161
|
+
|
|
1162
|
+
const { takeProfitType, stopLossType } = getStopLossAndTakeProfitTypeByCloseStrategyType(+subData.closeType);
|
|
1163
|
+
|
|
876
1164
|
_position.specific = {
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
ratio: subData.targetRatio,
|
|
1165
|
+
subHash: _position.subHash,
|
|
1166
|
+
marketId,
|
|
1167
|
+
collAsset: subData.collToken,
|
|
1168
|
+
debtAsset: subData.loanToken,
|
|
1169
|
+
stopLossPrice: triggerData.lowerPrice,
|
|
1170
|
+
takeProfitPrice: triggerData.upperPrice,
|
|
1171
|
+
stopLossType,
|
|
1172
|
+
takeProfitType,
|
|
886
1173
|
};
|
|
887
1174
|
|
|
888
1175
|
return _position;
|
|
@@ -909,7 +1196,6 @@ function parseLiquityV2CloseOnPrice(position: Position.Automated, parseData: Par
|
|
|
909
1196
|
// - Only TakeProfit
|
|
910
1197
|
// - Only StopLoss
|
|
911
1198
|
// - Both
|
|
912
|
-
// TODO: see on frontend what specific data we need here because stop-loss and take-profit is one bundle now
|
|
913
1199
|
_position.strategy.strategyId = Strategies.Identifiers.CloseOnPrice;
|
|
914
1200
|
_position.specific = {
|
|
915
1201
|
market: subData.market,
|
|
@@ -1057,6 +1343,26 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
|
|
|
1057
1343
|
[Strategies.Identifiers.CloseToCollateralWithGasPrice]: parseAaveV3CloseOnPriceWithMaximumGasPrice,
|
|
1058
1344
|
[Strategies.Identifiers.OpenOrderFromCollateral]: parseAaveV3LeverageManagementOnPrice,
|
|
1059
1345
|
[Strategies.Identifiers.RepayOnPrice]: parseAaveV3LeverageManagementOnPrice,
|
|
1346
|
+
[Strategies.Identifiers.EoaRepay]: parseAaveV3LeverageManagement,
|
|
1347
|
+
[Strategies.Identifiers.EoaBoost]: parseAaveV3LeverageManagement,
|
|
1348
|
+
[Strategies.Identifiers.EoaRepayOnPrice]: parseAaveV3LeverageManagementOnPrice,
|
|
1349
|
+
[Strategies.Identifiers.EoaBoostOnPrice]: parseAaveV3LeverageManagementOnPrice,
|
|
1350
|
+
[Strategies.Identifiers.EoaCloseOnPrice]: parseAaveV3CloseOnPrice,
|
|
1351
|
+
[Strategies.Identifiers.CollateralSwitch]: parseAaveV3CollateralSwitch,
|
|
1352
|
+
},
|
|
1353
|
+
[ProtocolIdentifiers.StrategiesAutomation.AaveV4]: {
|
|
1354
|
+
[Strategies.Identifiers.Repay]: parseAaveV4LeverageManagement,
|
|
1355
|
+
[Strategies.Identifiers.Boost]: parseAaveV4LeverageManagement,
|
|
1356
|
+
[Strategies.Identifiers.RepayOnPrice]: parseAaveV4LeverageManagementOnPrice,
|
|
1357
|
+
[Strategies.Identifiers.BoostOnPrice]: parseAaveV4LeverageManagementOnPrice,
|
|
1358
|
+
[Strategies.Identifiers.CloseOnPrice]: parseAaveV4CloseOnPrice,
|
|
1359
|
+
[Strategies.Identifiers.EoaRepay]: parseAaveV4LeverageManagement,
|
|
1360
|
+
[Strategies.Identifiers.EoaBoost]: parseAaveV4LeverageManagement,
|
|
1361
|
+
[Strategies.Identifiers.EoaRepayOnPrice]: parseAaveV4LeverageManagementOnPrice,
|
|
1362
|
+
[Strategies.Identifiers.EoaBoostOnPrice]: parseAaveV4LeverageManagementOnPrice,
|
|
1363
|
+
[Strategies.Identifiers.EoaCloseOnPrice]: parseAaveV4CloseOnPrice,
|
|
1364
|
+
[Strategies.Identifiers.CollateralSwitch]: parseAaveV4CollateralSwitch,
|
|
1365
|
+
[Strategies.Identifiers.EoaCollateralSwitch]: parseAaveV4CollateralSwitch,
|
|
1060
1366
|
},
|
|
1061
1367
|
[ProtocolIdentifiers.StrategiesAutomation.CompoundV2]: {
|
|
1062
1368
|
[Strategies.Identifiers.Repay]: parseCompoundV2LeverageManagement,
|
|
@@ -1067,6 +1373,12 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
|
|
|
1067
1373
|
[Strategies.Identifiers.Boost]: parseCompoundV3LeverageManagement,
|
|
1068
1374
|
[Strategies.Identifiers.EoaRepay]: parseCompoundV3LeverageManagement,
|
|
1069
1375
|
[Strategies.Identifiers.EoaBoost]: parseCompoundV3LeverageManagement,
|
|
1376
|
+
[Strategies.Identifiers.RepayOnPrice]: parseCompoundV3LeverageManagementOnPrice,
|
|
1377
|
+
[Strategies.Identifiers.BoostOnPrice]: parseCompoundV3LeverageManagementOnPrice,
|
|
1378
|
+
[Strategies.Identifiers.EoaRepayOnPrice]: parseCompoundV3LeverageManagementOnPrice,
|
|
1379
|
+
[Strategies.Identifiers.EoaBoostOnPrice]: parseCompoundV3LeverageManagementOnPrice,
|
|
1380
|
+
[Strategies.Identifiers.CloseOnPrice]: parseCompoundV3CloseOnPrice,
|
|
1381
|
+
[Strategies.Identifiers.EoaCloseOnPrice]: parseCompoundV3CloseOnPrice,
|
|
1070
1382
|
},
|
|
1071
1383
|
[ProtocolIdentifiers.StrategiesAutomation.ChickenBonds]: {
|
|
1072
1384
|
[Strategies.Identifiers.Rebond]: parseChickenBondsRebond,
|
|
@@ -1082,8 +1394,10 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
|
|
|
1082
1394
|
[ProtocolIdentifiers.StrategiesAutomation.Spark]: {
|
|
1083
1395
|
[Strategies.Identifiers.Repay]: parseSparkLeverageManagement,
|
|
1084
1396
|
[Strategies.Identifiers.Boost]: parseSparkLeverageManagement,
|
|
1085
|
-
[Strategies.Identifiers.
|
|
1086
|
-
[Strategies.Identifiers.
|
|
1397
|
+
[Strategies.Identifiers.RepayOnPrice]: parseSparkLeverageManagementOnPrice,
|
|
1398
|
+
[Strategies.Identifiers.BoostOnPrice]: parseSparkLeverageManagementOnPrice,
|
|
1399
|
+
[Strategies.Identifiers.CloseOnPrice]: parseSparkCloseOnPrice,
|
|
1400
|
+
[Strategies.Identifiers.CollateralSwitch]: parseSparkCollateralSwitch,
|
|
1087
1401
|
},
|
|
1088
1402
|
[ProtocolIdentifiers.StrategiesAutomation.CrvUSD]: {
|
|
1089
1403
|
[Strategies.Identifiers.Repay]: parseCrvUSDLeverageManagement,
|
|
@@ -1096,6 +1410,7 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
|
|
|
1096
1410
|
[Strategies.Identifiers.EoaRepay]: parseMorphoBlueLeverageManagement,
|
|
1097
1411
|
[Strategies.Identifiers.EoaBoost]: parseMorphoBlueLeverageManagement,
|
|
1098
1412
|
[Strategies.Identifiers.BoostOnPrice]: parseMorphoBlueLeverageManagementOnPrice,
|
|
1413
|
+
[Strategies.Identifiers.CloseOnPrice]: parseMorphoBlueCloseOnPrice,
|
|
1099
1414
|
},
|
|
1100
1415
|
[ProtocolIdentifiers.StrategiesAutomation.FluidT1]: {
|
|
1101
1416
|
[Strategies.Identifiers.Repay]: parseFluidT1LeverageManagement,
|