@defisaver/automation-sdk 3.3.1 → 3.3.2-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/cjs/constants/index.js +100 -0
  2. package/cjs/index.d.ts +2 -1
  3. package/cjs/index.js +1 -1
  4. package/cjs/services/strategiesService.js +28 -9
  5. package/cjs/services/strategySubService.d.ts +3 -1
  6. package/cjs/services/strategySubService.js +15 -2
  7. package/cjs/services/strategySubService.test.js +314 -0
  8. package/cjs/services/subDataService.d.ts +25 -1
  9. package/cjs/services/subDataService.js +78 -2
  10. package/cjs/services/subDataService.test.js +456 -0
  11. package/cjs/services/triggerService.d.ts +9 -0
  12. package/cjs/services/triggerService.js +20 -1
  13. package/cjs/services/triggerService.test.js +46 -0
  14. package/cjs/types/enums.d.ts +24 -4
  15. package/cjs/types/enums.js +21 -0
  16. package/esm/constants/index.js +100 -0
  17. package/esm/index.d.ts +2 -1
  18. package/esm/index.js +2 -2
  19. package/esm/services/strategiesService.js +28 -9
  20. package/esm/services/strategySubService.d.ts +3 -1
  21. package/esm/services/strategySubService.js +15 -2
  22. package/esm/services/strategySubService.test.js +314 -0
  23. package/esm/services/subDataService.d.ts +25 -1
  24. package/esm/services/subDataService.js +77 -1
  25. package/esm/services/subDataService.test.js +456 -0
  26. package/esm/services/triggerService.d.ts +9 -0
  27. package/esm/services/triggerService.js +19 -0
  28. package/esm/services/triggerService.test.js +47 -1
  29. package/esm/types/enums.d.ts +24 -4
  30. package/esm/types/enums.js +21 -0
  31. package/package.json +1 -1
  32. package/src/constants/index.ts +103 -0
  33. package/src/index.ts +4 -2
  34. package/src/services/strategiesService.ts +31 -10
  35. package/src/services/strategySubService.test.ts +347 -0
  36. package/src/services/strategySubService.ts +57 -1
  37. package/src/services/subDataService.test.ts +532 -0
  38. package/src/services/subDataService.ts +122 -2
  39. package/src/services/triggerService.test.ts +50 -0
  40. package/src/services/triggerService.ts +29 -0
  41. package/src/types/enums.ts +21 -0
  42. package/src/types/index.ts +20 -0
@@ -218,6 +218,12 @@ export var Bundles;
218
218
  MainnetIds[MainnetIds["COMP_V3_EOA_REPAY_ON_PRICE"] = 49] = "COMP_V3_EOA_REPAY_ON_PRICE";
219
219
  MainnetIds[MainnetIds["COMP_V3_EOA_BOOST_ON_PRICE"] = 50] = "COMP_V3_EOA_BOOST_ON_PRICE";
220
220
  MainnetIds[MainnetIds["COMP_V3_EOA_CLOSE"] = 51] = "COMP_V3_EOA_CLOSE";
221
+ // TODO -> Watch out for Liquity V2 Strategy deploy, should change IDs or here or there !!!
222
+ MainnetIds[MainnetIds["AAVE_V3_EOA_REPAY"] = 52] = "AAVE_V3_EOA_REPAY";
223
+ MainnetIds[MainnetIds["AAVE_V3_EOA_BOOST"] = 53] = "AAVE_V3_EOA_BOOST";
224
+ MainnetIds[MainnetIds["AAVE_V3_EOA_REPAY_ON_PRICE"] = 54] = "AAVE_V3_EOA_REPAY_ON_PRICE";
225
+ MainnetIds[MainnetIds["AAVE_V3_EOA_BOOST_ON_PRICE"] = 55] = "AAVE_V3_EOA_BOOST_ON_PRICE";
226
+ MainnetIds[MainnetIds["AAVE_V3_EOA_CLOSE"] = 56] = "AAVE_V3_EOA_CLOSE";
221
227
  })(MainnetIds = Bundles.MainnetIds || (Bundles.MainnetIds = {}));
222
228
  let OptimismIds;
223
229
  (function (OptimismIds) {
@@ -227,6 +233,11 @@ export var Bundles;
227
233
  OptimismIds[OptimismIds["AAVE_V3_CLOSE_TO_COLLATERAL"] = 3] = "AAVE_V3_CLOSE_TO_COLLATERAL";
228
234
  OptimismIds[OptimismIds["AAVE_V3_OPEN_ORDER_FROM_COLLATERAL"] = 4] = "AAVE_V3_OPEN_ORDER_FROM_COLLATERAL";
229
235
  OptimismIds[OptimismIds["AAVE_V3_REPAY_ON_PRICE"] = 5] = "AAVE_V3_REPAY_ON_PRICE";
236
+ OptimismIds[OptimismIds["AAVE_V3_EOA_REPAY"] = 6] = "AAVE_V3_EOA_REPAY";
237
+ OptimismIds[OptimismIds["AAVE_V3_EOA_BOOST"] = 7] = "AAVE_V3_EOA_BOOST";
238
+ OptimismIds[OptimismIds["AAVE_V3_EOA_REPAY_ON_PRICE"] = 8] = "AAVE_V3_EOA_REPAY_ON_PRICE";
239
+ OptimismIds[OptimismIds["AAVE_V3_EOA_BOOST_ON_PRICE"] = 9] = "AAVE_V3_EOA_BOOST_ON_PRICE";
240
+ OptimismIds[OptimismIds["AAVE_V3_EOA_CLOSE"] = 10] = "AAVE_V3_EOA_CLOSE";
230
241
  })(OptimismIds = Bundles.OptimismIds || (Bundles.OptimismIds = {}));
231
242
  let BaseIds;
232
243
  (function (BaseIds) {
@@ -251,6 +262,11 @@ export var Bundles;
251
262
  BaseIds[BaseIds["COMP_V3_EOA_CLOSE"] = 20] = "COMP_V3_EOA_CLOSE";
252
263
  BaseIds[BaseIds["COMP_V3_EOA_REPAY"] = 21] = "COMP_V3_EOA_REPAY";
253
264
  BaseIds[BaseIds["COMP_V3_EOA_BOOST"] = 22] = "COMP_V3_EOA_BOOST";
265
+ BaseIds[BaseIds["AAVE_V3_EOA_REPAY"] = 23] = "AAVE_V3_EOA_REPAY";
266
+ BaseIds[BaseIds["AAVE_V3_EOA_BOOST"] = 24] = "AAVE_V3_EOA_BOOST";
267
+ BaseIds[BaseIds["AAVE_V3_EOA_REPAY_ON_PRICE"] = 25] = "AAVE_V3_EOA_REPAY_ON_PRICE";
268
+ BaseIds[BaseIds["AAVE_V3_EOA_BOOST_ON_PRICE"] = 26] = "AAVE_V3_EOA_BOOST_ON_PRICE";
269
+ BaseIds[BaseIds["AAVE_V3_EOA_CLOSE"] = 27] = "AAVE_V3_EOA_CLOSE";
254
270
  })(BaseIds = Bundles.BaseIds || (Bundles.BaseIds = {}));
255
271
  let ArbitrumIds;
256
272
  (function (ArbitrumIds) {
@@ -272,5 +288,10 @@ export var Bundles;
272
288
  ArbitrumIds[ArbitrumIds["COMP_V3_EOA_CLOSE"] = 15] = "COMP_V3_EOA_CLOSE";
273
289
  ArbitrumIds[ArbitrumIds["COMP_V3_EOA_REPAY"] = 16] = "COMP_V3_EOA_REPAY";
274
290
  ArbitrumIds[ArbitrumIds["COMP_V3_EOA_BOOST"] = 17] = "COMP_V3_EOA_BOOST";
291
+ ArbitrumIds[ArbitrumIds["AAVE_V3_EOA_REPAY"] = 18] = "AAVE_V3_EOA_REPAY";
292
+ ArbitrumIds[ArbitrumIds["AAVE_V3_EOA_BOOST"] = 19] = "AAVE_V3_EOA_BOOST";
293
+ ArbitrumIds[ArbitrumIds["AAVE_V3_EOA_REPAY_ON_PRICE"] = 20] = "AAVE_V3_EOA_REPAY_ON_PRICE";
294
+ ArbitrumIds[ArbitrumIds["AAVE_V3_EOA_BOOST_ON_PRICE"] = 21] = "AAVE_V3_EOA_BOOST_ON_PRICE";
295
+ ArbitrumIds[ArbitrumIds["AAVE_V3_EOA_CLOSE"] = 22] = "AAVE_V3_EOA_CLOSE";
275
296
  })(ArbitrumIds = Bundles.ArbitrumIds || (Bundles.ArbitrumIds = {}));
276
297
  })(Bundles || (Bundles = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/automation-sdk",
3
- "version": "3.3.1",
3
+ "version": "3.3.2-dev.0",
4
4
  "description": "",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -451,6 +451,32 @@ export const MAINNET_BUNDLES_INFO: MainnetBundleInfo = {
451
451
  strategyId: Strategies.Identifiers.EoaCloseOnPrice,
452
452
  protocol: PROTOCOLS.CompoundV3,
453
453
  },
454
+ [Bundles.MainnetIds.AAVE_V3_EOA_REPAY]: {
455
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V3_EOA_REPAY,
456
+ strategyId: Strategies.Identifiers.EoaRepay,
457
+ protocol: PROTOCOLS.AaveV3,
458
+ },
459
+ [Bundles.MainnetIds.AAVE_V3_EOA_BOOST]: {
460
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V3_EOA_BOOST,
461
+ strategyId: Strategies.Identifiers.EoaBoost,
462
+ protocol: PROTOCOLS.AaveV3,
463
+ },
464
+ [Bundles.MainnetIds.AAVE_V3_EOA_REPAY_ON_PRICE]: {
465
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V3_EOA_REPAY_ON_PRICE,
466
+ strategyId: Strategies.Identifiers.EoaRepayOnPrice,
467
+ protocol: PROTOCOLS.AaveV3,
468
+ },
469
+ [Bundles.MainnetIds.AAVE_V3_EOA_BOOST_ON_PRICE]: {
470
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V3_EOA_BOOST_ON_PRICE,
471
+ strategyId: Strategies.Identifiers.EoaBoostOnPrice,
472
+ protocol: PROTOCOLS.AaveV3,
473
+ },
474
+ [Bundles.MainnetIds.AAVE_V3_EOA_CLOSE]: {
475
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
476
+ strategyId: Strategies.Identifiers.EoaCloseOnPrice,
477
+ protocol: PROTOCOLS.AaveV3,
478
+ },
479
+
454
480
  };
455
481
 
456
482
  export const OPTIMISM_BUNDLES_INFO: OptimismBundleInfo = {
@@ -484,6 +510,32 @@ export const OPTIMISM_BUNDLES_INFO: OptimismBundleInfo = {
484
510
  strategyId: Strategies.Identifiers.RepayOnPrice,
485
511
  protocol: PROTOCOLS.AaveV3,
486
512
  },
513
+ [Bundles.OptimismIds.AAVE_V3_EOA_REPAY]: {
514
+ strategyOrBundleId: Bundles.OptimismIds.AAVE_V3_EOA_REPAY,
515
+ strategyId: Strategies.Identifiers.EoaRepay,
516
+ protocol: PROTOCOLS.AaveV3,
517
+ },
518
+ [Bundles.OptimismIds.AAVE_V3_EOA_BOOST]: {
519
+ strategyOrBundleId: Bundles.OptimismIds.AAVE_V3_EOA_BOOST,
520
+ strategyId: Strategies.Identifiers.EoaBoost,
521
+ protocol: PROTOCOLS.AaveV3,
522
+ },
523
+ [Bundles.OptimismIds.AAVE_V3_EOA_REPAY_ON_PRICE]: {
524
+ strategyOrBundleId: Bundles.OptimismIds.AAVE_V3_EOA_REPAY_ON_PRICE,
525
+ strategyId: Strategies.Identifiers.EoaRepayOnPrice,
526
+ protocol: PROTOCOLS.AaveV3,
527
+ },
528
+ [Bundles.OptimismIds.AAVE_V3_EOA_BOOST_ON_PRICE]: {
529
+ strategyOrBundleId: Bundles.OptimismIds.AAVE_V3_EOA_BOOST_ON_PRICE,
530
+ strategyId: Strategies.Identifiers.EoaBoostOnPrice,
531
+ protocol: PROTOCOLS.AaveV3,
532
+ },
533
+ [Bundles.OptimismIds.AAVE_V3_EOA_CLOSE]: {
534
+ strategyOrBundleId: Bundles.OptimismIds.AAVE_V3_EOA_CLOSE,
535
+ strategyId: Strategies.Identifiers.EoaCloseOnPrice,
536
+ protocol: PROTOCOLS.AaveV3,
537
+ },
538
+
487
539
  };
488
540
 
489
541
  export const BASE_BUNDLES_INFO: BaseBundleInfo = {
@@ -592,6 +644,32 @@ export const BASE_BUNDLES_INFO: BaseBundleInfo = {
592
644
  strategyId: Strategies.Identifiers.EoaBoost,
593
645
  protocol: PROTOCOLS.CompoundV3,
594
646
  },
647
+ [Bundles.BaseIds.AAVE_V3_EOA_REPAY]: {
648
+ strategyOrBundleId: Bundles.BaseIds.AAVE_V3_EOA_REPAY,
649
+ strategyId: Strategies.Identifiers.EoaRepay,
650
+ protocol: PROTOCOLS.AaveV3,
651
+ },
652
+ [Bundles.BaseIds.AAVE_V3_EOA_BOOST]: {
653
+ strategyOrBundleId: Bundles.BaseIds.AAVE_V3_EOA_BOOST,
654
+ strategyId: Strategies.Identifiers.EoaBoost,
655
+ protocol: PROTOCOLS.AaveV3,
656
+ },
657
+ [Bundles.BaseIds.AAVE_V3_EOA_REPAY_ON_PRICE]: {
658
+ strategyOrBundleId: Bundles.BaseIds.AAVE_V3_EOA_REPAY_ON_PRICE,
659
+ strategyId: Strategies.Identifiers.EoaRepayOnPrice,
660
+ protocol: PROTOCOLS.AaveV3,
661
+ },
662
+ [Bundles.BaseIds.AAVE_V3_EOA_BOOST_ON_PRICE]: {
663
+ strategyOrBundleId: Bundles.BaseIds.AAVE_V3_EOA_BOOST_ON_PRICE,
664
+ strategyId: Strategies.Identifiers.EoaBoostOnPrice,
665
+ protocol: PROTOCOLS.AaveV3,
666
+ },
667
+ [Bundles.BaseIds.AAVE_V3_EOA_CLOSE]: {
668
+ strategyOrBundleId: Bundles.BaseIds.AAVE_V3_EOA_CLOSE,
669
+ strategyId: Strategies.Identifiers.EoaCloseOnPrice,
670
+ protocol: PROTOCOLS.AaveV3,
671
+ },
672
+
595
673
  };
596
674
 
597
675
  export const ARBITRUM_BUNDLES_INFO: ArbitrumBundleInfo = {
@@ -685,6 +763,31 @@ export const ARBITRUM_BUNDLES_INFO: ArbitrumBundleInfo = {
685
763
  strategyId: Strategies.Identifiers.EoaBoost,
686
764
  protocol: PROTOCOLS.CompoundV3,
687
765
  },
766
+ [Bundles.ArbitrumIds.AAVE_V3_EOA_REPAY]: {
767
+ strategyOrBundleId: Bundles.ArbitrumIds.AAVE_V3_EOA_REPAY,
768
+ strategyId: Strategies.Identifiers.EoaRepay,
769
+ protocol: PROTOCOLS.AaveV3,
770
+ },
771
+ [Bundles.ArbitrumIds.AAVE_V3_EOA_BOOST]: {
772
+ strategyOrBundleId: Bundles.ArbitrumIds.AAVE_V3_EOA_BOOST,
773
+ strategyId: Strategies.Identifiers.EoaBoost,
774
+ protocol: PROTOCOLS.AaveV3,
775
+ },
776
+ [Bundles.ArbitrumIds.AAVE_V3_EOA_REPAY_ON_PRICE]: {
777
+ strategyOrBundleId: Bundles.ArbitrumIds.AAVE_V3_EOA_REPAY_ON_PRICE,
778
+ strategyId: Strategies.Identifiers.EoaRepayOnPrice,
779
+ protocol: PROTOCOLS.AaveV3,
780
+ },
781
+ [Bundles.ArbitrumIds.AAVE_V3_EOA_BOOST_ON_PRICE]: {
782
+ strategyOrBundleId: Bundles.ArbitrumIds.AAVE_V3_EOA_BOOST_ON_PRICE,
783
+ strategyId: Strategies.Identifiers.EoaBoostOnPrice,
784
+ protocol: PROTOCOLS.AaveV3,
785
+ },
786
+ [Bundles.ArbitrumIds.AAVE_V3_EOA_CLOSE]: {
787
+ strategyOrBundleId: Bundles.ArbitrumIds.AAVE_V3_EOA_CLOSE,
788
+ strategyId: Strategies.Identifiers.EoaCloseOnPrice,
789
+ protocol: PROTOCOLS.AaveV3,
790
+ },
688
791
  };
689
792
 
690
793
  export const BUNDLES_INFO: BundlesInfo = {
package/src/index.ts CHANGED
@@ -23,10 +23,12 @@ import * as constants from './constants';
23
23
  import * as enums from './types/enums';
24
24
  import type * as types from './types';
25
25
 
26
- import { getRatioStateInfoForAaveCloseStrategy, compareSubHashes, encodeSubId } from './services/utils';
26
+ import {
27
+ getRatioStateInfoForAaveCloseStrategy, compareSubHashes, encodeSubId, getCloseStrategyType,
28
+ } from './services/utils';
27
29
 
28
30
  const utils = {
29
- getRatioStateInfoForAaveCloseStrategy, compareSubHashes, encodeSubId,
31
+ getRatioStateInfoForAaveCloseStrategy, compareSubHashes, encodeSubId, getCloseStrategyType,
30
32
  };
31
33
 
32
34
  export {
@@ -231,7 +231,7 @@ function parseAaveV2LeverageManagement(position: Position.Automated, parseData:
231
231
  function parseAaveV3LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
232
232
  const _position = cloneDeep(position);
233
233
 
234
- const { subStruct, subId } = parseData.subscriptionEventData;
234
+ const { subStruct, subId, subHash } = parseData.subscriptionEventData;
235
235
  const { isEnabled } = parseData.strategiesSubsData;
236
236
 
237
237
  const triggerData = triggerService.aaveV3RatioTrigger.decode(subStruct.triggerData);
@@ -242,7 +242,11 @@ function parseAaveV3LeverageManagement(position: Position.Automated, parseData:
242
242
 
243
243
  _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.market);
244
244
 
245
- const isRepay = _position.strategy.strategyId === Strategies.Identifiers.Repay;
245
+ // TODO -> check if this change breaks something?
246
+ const isEOA = _position.strategy.strategyId.includes('eoa');
247
+
248
+ // TODO -> check if this change breaks something?
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 = {
@@ -250,7 +254,8 @@ function parseAaveV3LeverageManagement(position: Position.Automated, parseData:
250
254
  targetRepayRatio: subData.targetRatio,
251
255
  repayEnabled: true,
252
256
  subId1: Number(subId),
253
- mergeWithId: Strategies.Identifiers.Boost,
257
+ subHashRepay: subHash,
258
+ mergeWithId: isEOA ? Strategies.Identifiers.EoaBoost : Strategies.Identifiers.Boost,
254
259
  };
255
260
  } else {
256
261
  _position.specific = {
@@ -258,12 +263,12 @@ 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
+ subHashBoost: subHash,
267
+ mergeId: isEOA ? Strategies.Identifiers.EoaBoost : Strategies.Identifiers.Boost,
262
268
  };
263
269
  }
264
270
 
265
- _position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
266
-
271
+ _position.strategy.strategyId = isEOA ? Strategies.IdOverrides.EoaLeverageManagement : Strategies.IdOverrides.LeverageManagement;
267
272
  return _position;
268
273
  }
269
274
 
@@ -337,7 +342,13 @@ function parseAaveV3CloseOnPrice(position: Position.Automated, parseData: ParseD
337
342
  parseData.chainId,
338
343
  );
339
344
 
340
- _position.strategy.strategyId = isRatioStateOver(ratioState) ? Strategies.IdOverrides.TakeProfit : Strategies.IdOverrides.StopLoss;
345
+ // TODO -> Check if those changes break something?
346
+ const isEOA = _position.strategy.strategyId.includes('eoa');
347
+ _position.strategy.strategyId = isEOA
348
+ ? Strategies.Identifiers.EoaCloseOnPrice
349
+ : (_position.strategy.strategyId = isRatioStateOver(ratioState)
350
+ ? Strategies.IdOverrides.TakeProfit
351
+ : Strategies.IdOverrides.StopLoss);
341
352
 
342
353
  return _position;
343
354
  }
@@ -442,13 +453,15 @@ function parseCompoundV3LeverageManagement(position: Position.Automated, parseDa
442
453
 
443
454
  const isRepay = [Strategies.Identifiers.Repay, Strategies.Identifiers.EoaRepay].includes(_position.strategy.strategyId as Strategies.Identifiers);
444
455
 
456
+ const isEOA = _position.strategy.strategyId.includes('eoa');
457
+
445
458
  if (isRepay) {
446
459
  _position.specific = {
447
460
  triggerRepayRatio: triggerData.ratio,
448
461
  targetRepayRatio: subData.targetRatio,
449
462
  repayEnabled: true,
450
463
  subId1: Number(subId),
451
- mergeWithId: Strategies.Identifiers.Boost,
464
+ mergeWithId: isEOA ? Strategies.Identifiers.EoaBoost : Strategies.Identifiers.Boost,
452
465
  };
453
466
  } else {
454
467
  _position.specific = {
@@ -456,11 +469,10 @@ function parseCompoundV3LeverageManagement(position: Position.Automated, parseDa
456
469
  targetBoostRatio: subData.targetRatio,
457
470
  boostEnabled: isEnabled,
458
471
  subId2: Number(subId),
459
- mergeId: Strategies.Identifiers.Boost,
472
+ mergeId: isEOA ? Strategies.Identifiers.EoaBoost : Strategies.Identifiers.Boost,
460
473
  };
461
474
  }
462
475
 
463
- const isEOA = _position.strategy.strategyId.includes('eoa');
464
476
  _position.strategy.strategyId = isEOA ? Strategies.IdOverrides.EoaLeverageManagement : Strategies.IdOverrides.LeverageManagement;
465
477
 
466
478
  return _position;
@@ -938,6 +950,10 @@ function parseAaveV3LeverageManagementOnPrice(position: Position.Automated, pars
938
950
  ratio: subData.targetRatio,
939
951
  };
940
952
 
953
+ // TODO -> check if this change breaks something?
954
+ const isEOA = _position.strategy.strategyId.includes('eoa');
955
+ _position.strategy.strategyId = isEOA ? Strategies.IdOverrides.EoaLeverageManagementOnPrice : Strategies.IdOverrides.LeverageManagementOnPrice;
956
+
941
957
  return _position;
942
958
  }
943
959
 
@@ -1109,6 +1125,11 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
1109
1125
  [Strategies.Identifiers.CloseToCollateralWithGasPrice]: parseAaveV3CloseOnPriceWithMaximumGasPrice,
1110
1126
  [Strategies.Identifiers.OpenOrderFromCollateral]: parseAaveV3LeverageManagementOnPrice,
1111
1127
  [Strategies.Identifiers.RepayOnPrice]: parseAaveV3LeverageManagementOnPrice,
1128
+ [Strategies.Identifiers.EoaRepay]: parseAaveV3LeverageManagement,
1129
+ [Strategies.Identifiers.EoaBoost]: parseAaveV3LeverageManagement,
1130
+ [Strategies.Identifiers.EoaRepayOnPrice]: parseAaveV3LeverageManagementOnPrice,
1131
+ [Strategies.Identifiers.EoaBoostOnPrice]: parseAaveV3LeverageManagementOnPrice,
1132
+ [Strategies.Identifiers.EoaCloseOnPrice]: parseAaveV3CloseOnPrice,
1112
1133
  },
1113
1134
  [ProtocolIdentifiers.StrategiesAutomation.CompoundV2]: {
1114
1135
  [Strategies.Identifiers.Repay]: parseCompoundV2LeverageManagement,
@@ -618,6 +618,353 @@ describe('Feature: strategySubService.ts', () => {
618
618
  });
619
619
  });
620
620
  });
621
+
622
+ describe('leverageManagementOnPriceGeneric()', () => {
623
+ const examples: Array<[
624
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
625
+ [
626
+ strategyOrBundleId: number,
627
+ price: number,
628
+ ratioState: RatioState,
629
+ collAsset: EthereumAddress,
630
+ collAssetId: number,
631
+ debtAsset: EthereumAddress,
632
+ debtAssetId: number,
633
+ marketAddr: EthereumAddress,
634
+ targetRatio: number,
635
+ user: EthereumAddress
636
+ ]
637
+ ]> = [
638
+ [
639
+ [
640
+ Bundles.MainnetIds.AAVE_V3_EOA_REPAY_ON_PRICE,
641
+ true,
642
+ ['0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000026e1f9c6000000000000000000000000000000000000000000000000000000000000000001'],
643
+ [
644
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
645
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
646
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
647
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
648
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
649
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
650
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
651
+ ],
652
+ ],
653
+ [
654
+ Bundles.MainnetIds.AAVE_V3_EOA_REPAY_ON_PRICE,
655
+ 1670,
656
+ RatioState.UNDER,
657
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
658
+ 0,
659
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
660
+ 1,
661
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
662
+ 200,
663
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
664
+ ]
665
+ ],
666
+ [
667
+ [
668
+ Bundles.MainnetIds.AAVE_V3_EOA_BOOST_ON_PRICE,
669
+ true,
670
+ ['0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000002faf0800000000000000000000000000000000000000000000000000000000000000000'],
671
+ [
672
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
673
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
674
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
675
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
676
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
677
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
678
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
679
+ ],
680
+ ],
681
+ [
682
+ Bundles.MainnetIds.AAVE_V3_EOA_BOOST_ON_PRICE,
683
+ 0.5,
684
+ RatioState.OVER,
685
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
686
+ 2,
687
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
688
+ 1,
689
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
690
+ 200,
691
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
692
+ ]
693
+ ],
694
+ ];
695
+
696
+ examples.forEach(([expected, actual]) => {
697
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
698
+ expect(aaveV3Encode.leverageManagementOnPriceGeneric(...actual)).to.eql(expected);
699
+ });
700
+ });
701
+ });
702
+
703
+ describe('closeOnPriceGeneric()', () => {
704
+ const examples: Array<[
705
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
706
+ [
707
+ strategyOrBundleId: number,
708
+ collAsset: EthereumAddress,
709
+ collAssetId: number,
710
+ debtAsset: EthereumAddress,
711
+ debtAssetId: number,
712
+ marketAddr: EthereumAddress,
713
+ user: EthereumAddress,
714
+ stopLossPrice: number,
715
+ stopLossType: CloseToAssetType,
716
+ takeProfitPrice: number,
717
+ takeProfitType: CloseToAssetType
718
+ ]
719
+ ]> = [
720
+ // Stop loss only (to debt)
721
+ [
722
+ [
723
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
724
+ true,
725
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000000000000000'],
726
+ [
727
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
728
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
729
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
730
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
731
+ '0x0000000000000000000000000000000000000000000000000000000000000003',
732
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
733
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
734
+ ],
735
+ ],
736
+ [
737
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
738
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
739
+ 0,
740
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
741
+ 1,
742
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
743
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
744
+ 1500, // stopLossPrice
745
+ CloseToAssetType.DEBT, // stopLossType
746
+ 0, // takeProfitPrice
747
+ CloseToAssetType.COLLATERAL, // takeProfitType (not used since price is 0)
748
+ ]
749
+ ],
750
+ // Take profit only (to collateral)
751
+ [
752
+ [
753
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
754
+ true,
755
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
756
+ [
757
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
758
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
759
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
760
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
761
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
762
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
763
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
764
+ ],
765
+ ],
766
+ [
767
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
768
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
769
+ 0,
770
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
771
+ 1,
772
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
773
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
774
+ 0, // stopLossPrice
775
+ CloseToAssetType.DEBT, // stopLossType (not used since price is 0)
776
+ 5000, // takeProfitPrice
777
+ CloseToAssetType.COLLATERAL, // takeProfitType
778
+ ]
779
+ ],
780
+ // Both stop loss and take profit with useOnBehalf
781
+ [
782
+ [
783
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
784
+ true,
785
+ ['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
786
+ [
787
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
788
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
789
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
790
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
791
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
792
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
793
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
794
+ ],
795
+ ],
796
+ [
797
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
798
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
799
+ 2,
800
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
801
+ 1,
802
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
803
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
804
+ 1500, // stopLossPrice
805
+ CloseToAssetType.COLLATERAL, // stopLossType
806
+ 4000, // takeProfitPrice
807
+ CloseToAssetType.COLLATERAL, // takeProfitType
808
+ ]
809
+ ],
810
+ // Stop loss only (to collateral) - CloseStrategyType.STOP_LOSS_IN_COLLATERAL
811
+ [
812
+ [
813
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
814
+ true,
815
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000000000000000'],
816
+ [
817
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
818
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
819
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
820
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
821
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
822
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
823
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
824
+ ],
825
+ ],
826
+ [
827
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
828
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
829
+ 0,
830
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
831
+ 1,
832
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
833
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
834
+ 1500, // stopLossPrice
835
+ CloseToAssetType.COLLATERAL, // stopLossType
836
+ 0, // takeProfitPrice
837
+ CloseToAssetType.DEBT, // takeProfitType (not used since price is 0)
838
+ ]
839
+ ],
840
+ // Take profit only (to debt) - CloseStrategyType.TAKE_PROFIT_IN_DEBT
841
+ [
842
+ [
843
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
844
+ true,
845
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
846
+ [
847
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
848
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
849
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
850
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
851
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
852
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
853
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
854
+ ],
855
+ ],
856
+ [
857
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
858
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
859
+ 0,
860
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
861
+ 1,
862
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
863
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
864
+ 0, // stopLossPrice
865
+ CloseToAssetType.COLLATERAL, // stopLossType (not used since price is 0)
866
+ 5000, // takeProfitPrice
867
+ CloseToAssetType.DEBT, // takeProfitType
868
+ ]
869
+ ],
870
+ // Take profit in collateral and stop loss in debt - CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT
871
+ [
872
+ [
873
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
874
+ true,
875
+ ['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
876
+ [
877
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
878
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
879
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
880
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
881
+ '0x0000000000000000000000000000000000000000000000000000000000000005',
882
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
883
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
884
+ ],
885
+ ],
886
+ [
887
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
888
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
889
+ 2,
890
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
891
+ 1,
892
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
893
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
894
+ 1500, // stopLossPrice
895
+ CloseToAssetType.DEBT, // stopLossType
896
+ 4000, // takeProfitPrice
897
+ CloseToAssetType.COLLATERAL, // takeProfitType
898
+ ]
899
+ ],
900
+ // Both stop loss and take profit in debt - CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT
901
+ [
902
+ [
903
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
904
+ true,
905
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
906
+ [
907
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
908
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
909
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
910
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
911
+ '0x0000000000000000000000000000000000000000000000000000000000000006',
912
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
913
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
914
+ ],
915
+ ],
916
+ [
917
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
918
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
919
+ 0,
920
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
921
+ 1,
922
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
923
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
924
+ 1500, // stopLossPrice
925
+ CloseToAssetType.DEBT, // stopLossType
926
+ 4000, // takeProfitPrice
927
+ CloseToAssetType.DEBT, // takeProfitType
928
+ ]
929
+ ],
930
+ // Take profit in debt and stop loss in collateral - CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL
931
+ [
932
+ [
933
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
934
+ true,
935
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
936
+ [
937
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
938
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
939
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
940
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
941
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
942
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
943
+ '0x0000000000000000000000009876543210987654321098765432109876543210',
944
+ ],
945
+ ],
946
+ [
947
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
948
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
949
+ 0,
950
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
951
+ 1,
952
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
953
+ web3Utils.toChecksumAddress('0x9876543210987654321098765432109876543210'),
954
+ 1500, // stopLossPrice
955
+ CloseToAssetType.COLLATERAL, // stopLossType
956
+ 4000, // takeProfitPrice
957
+ CloseToAssetType.DEBT, // takeProfitType
958
+ ]
959
+ ],
960
+ ];
961
+
962
+ examples.forEach(([expected, actual]) => {
963
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
964
+ expect(aaveV3Encode.closeOnPriceGeneric(...actual)).to.eql(expected);
965
+ });
966
+ });
967
+ });
621
968
  });
622
969
 
623
970
  describe('When testing strategySubService.compoundV2Encode', () => {