@defisaver/automation-sdk 3.3.10 → 3.3.11-aave-v4-1-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.
Files changed (57) hide show
  1. package/cjs/automation/private/StrategiesAutomation.d.ts +2 -0
  2. package/cjs/automation/private/StrategiesAutomation.js +10 -1
  3. package/cjs/automation/private/StrategiesAutomation.test.js +25 -0
  4. package/cjs/constants/index.d.ts +1 -0
  5. package/cjs/constants/index.js +72 -1
  6. package/cjs/services/ethereumService.test.js +2 -0
  7. package/cjs/services/strategiesService.js +129 -0
  8. package/cjs/services/strategySubService.d.ts +19 -0
  9. package/cjs/services/strategySubService.js +37 -1
  10. package/cjs/services/strategySubService.test.js +229 -0
  11. package/cjs/services/subDataService.d.ts +298 -129
  12. package/cjs/services/subDataService.js +639 -369
  13. package/cjs/services/subDataService.test.js +214 -0
  14. package/cjs/services/triggerService.d.ts +38 -0
  15. package/cjs/services/triggerService.js +68 -1
  16. package/cjs/services/triggerService.test.js +130 -0
  17. package/cjs/services/utils.d.ts +1 -1
  18. package/cjs/services/utils.js +10 -2
  19. package/cjs/types/enums.d.ts +19 -3
  20. package/cjs/types/enums.js +16 -0
  21. package/cjs/types/index.d.ts +33 -1
  22. package/esm/automation/private/StrategiesAutomation.d.ts +2 -0
  23. package/esm/automation/private/StrategiesAutomation.js +10 -1
  24. package/esm/automation/private/StrategiesAutomation.test.js +25 -0
  25. package/esm/constants/index.d.ts +1 -0
  26. package/esm/constants/index.js +71 -0
  27. package/esm/services/ethereumService.test.js +2 -0
  28. package/esm/services/strategiesService.js +130 -1
  29. package/esm/services/strategySubService.d.ts +19 -0
  30. package/esm/services/strategySubService.js +36 -0
  31. package/esm/services/strategySubService.test.js +230 -1
  32. package/esm/services/subDataService.d.ts +298 -129
  33. package/esm/services/subDataService.js +639 -369
  34. package/esm/services/subDataService.test.js +214 -0
  35. package/esm/services/triggerService.d.ts +38 -0
  36. package/esm/services/triggerService.js +67 -0
  37. package/esm/services/triggerService.test.js +131 -1
  38. package/esm/services/utils.d.ts +1 -1
  39. package/esm/services/utils.js +10 -2
  40. package/esm/types/enums.d.ts +19 -3
  41. package/esm/types/enums.js +16 -0
  42. package/esm/types/index.d.ts +33 -1
  43. package/package.json +2 -2
  44. package/src/automation/private/StrategiesAutomation.test.ts +40 -0
  45. package/src/automation/private/StrategiesAutomation.ts +11 -0
  46. package/src/constants/index.ts +72 -0
  47. package/src/services/ethereumService.test.ts +2 -0
  48. package/src/services/strategiesService.ts +150 -2
  49. package/src/services/strategySubService.test.ts +286 -0
  50. package/src/services/strategySubService.ts +140 -0
  51. package/src/services/subDataService.test.ts +239 -0
  52. package/src/services/subDataService.ts +1072 -784
  53. package/src/services/triggerService.test.ts +148 -0
  54. package/src/services/triggerService.ts +97 -1
  55. package/src/services/utils.ts +15 -4
  56. package/src/types/enums.ts +16 -0
  57. package/src/types/index.ts +40 -1
@@ -25,6 +25,8 @@ export default class StrategiesAutomation extends Automation {
25
25
  */
26
26
  protected removeExpiredSubscriptions(subscriptions: (Position.Automated | null)[]): (Position.Automated | null)[];
27
27
  private _mergeCheck;
28
+ /** Repay/boost leverage pairs must not merge across different Aave V4 spokes. */
29
+ private _aaveV4MergeSpokesMatch;
28
30
  protected mergeSubs(_subscriptions: (Position.Automated | null)[]): Position.Automated[];
29
31
  protected _getSubscriptions(addresses?: EthereumAddress[], options?: SubscriptionOptions): Promise<(Position.Automated | null)[]>;
30
32
  getSubscriptions(options?: SubscriptionOptions): Promise<(Position.Automated | null)[]>;
@@ -104,7 +104,16 @@ class StrategiesAutomation extends Automation_1.default {
104
104
  && (s.protocol.id !== enums_1.ProtocolIdentifiers.StrategiesAutomation.CrvUSD // merge only crvUSD leverage management for the same market
105
105
  || s.strategyData.decoded.subData.controller.toLowerCase() === current.strategyData.decoded.triggerData.controller.toLowerCase())
106
106
  && (s.protocol.id !== enums_1.ProtocolIdentifiers.StrategiesAutomation.MorphoBlue // merge morpho blue with the same marketId
107
- || s.strategyData.decoded.triggerData.marketId.toLowerCase() === current.strategyData.decoded.triggerData.marketId.toLowerCase());
107
+ || s.strategyData.decoded.triggerData.marketId.toLowerCase() === current.strategyData.decoded.triggerData.marketId.toLowerCase())
108
+ && (s.protocol.id !== enums_1.ProtocolIdentifiers.StrategiesAutomation.AaveV4
109
+ || this._aaveV4MergeSpokesMatch(s, current));
110
+ }
111
+ /** Repay/boost leverage pairs must not merge across different Aave V4 spokes. */
112
+ _aaveV4MergeSpokesMatch(s, current) {
113
+ var _a, _b, _c, _d, _e, _f;
114
+ const a = (_c = (_b = (_a = s.strategyData) === null || _a === void 0 ? void 0 : _a.decoded) === null || _b === void 0 ? void 0 : _b.triggerData) === null || _c === void 0 ? void 0 : _c.spoke;
115
+ const b = (_f = (_e = (_d = current.strategyData) === null || _d === void 0 ? void 0 : _d.decoded) === null || _e === void 0 ? void 0 : _e.triggerData) === null || _f === void 0 ? void 0 : _f.spoke;
116
+ return !!a && !!b && a.toLowerCase() === b.toLowerCase();
108
117
  }
109
118
  mergeSubs(_subscriptions) {
110
119
  const mergeBase = _subscriptions.filter(s => (0, utils_1.isDefined)(s) && (0, utils_1.isDefined)(s.specific.mergeWithId));
@@ -667,5 +667,30 @@ describe('Feature: StrategiesAutomation.ts', () => {
667
667
  (0, chai_1.expect)(JSON.stringify(actual)).to.equal(JSON.stringify(expected));
668
668
  }));
669
669
  });
670
+ it('Aave V4: pairs repay/boost merge only when trigger spoke matches (no cross-spoke merge)', () => {
671
+ var _a, _b, _c;
672
+ const spoke1 = '0x0000000000000000000000000000000000000a01';
673
+ const spoke2 = '0x0000000000000000000000000000000000000a02';
674
+ const base = {
675
+ isEnabled: true,
676
+ chainId: 1,
677
+ owner: '0x0000000000000000000000000000000000000b01',
678
+ protocol: { id: 'Aave__V4' },
679
+ strategy: { strategyId: 'leverage-management' },
680
+ blockNumber: 0,
681
+ subHash: '0x1',
682
+ positionId: 'test',
683
+ };
684
+ const boostSpoke1 = Object.assign(Object.assign({}, base), { subId: 1, strategyData: { decoded: { triggerData: { spoke: spoke1 }, subData: {} } }, specific: { mergeId: 'boost', subId2: 1 } });
685
+ const repaySpoke2 = Object.assign(Object.assign({}, base), { subId: 2, strategyData: { decoded: { triggerData: { spoke: spoke2 }, subData: {} } }, specific: { mergeWithId: 'boost', subId1: 2 } });
686
+ const boostSpoke2 = Object.assign(Object.assign({}, base), { subId: 3, strategyData: { decoded: { triggerData: { spoke: spoke2 }, subData: {} } }, specific: { mergeId: 'boost', subId2: 3 } });
687
+ // @ts-ignore — mergeSubs is protected; exercised here as in examples above
688
+ const merged = exampleStrategiesAutomation.mergeSubs([boostSpoke1, repaySpoke2, boostSpoke2]);
689
+ (0, chai_1.expect)(merged).to.have.length(2);
690
+ const mergedPair = merged.find((m) => { var _a; return ((_a = m.subIds) === null || _a === void 0 ? void 0 : _a.length) === 2; });
691
+ const loneBoost = merged.find((m) => { var _a; return ((_a = m.subIds) === null || _a === void 0 ? void 0 : _a.length) === 1; });
692
+ (0, chai_1.expect)((_c = (_b = (_a = mergedPair === null || mergedPair === void 0 ? void 0 : mergedPair.strategyData) === null || _a === void 0 ? void 0 : _a.decoded) === null || _b === void 0 ? void 0 : _b.triggerData) === null || _c === void 0 ? void 0 : _c.spoke).to.equal(spoke2);
693
+ (0, chai_1.expect)(loneBoost === null || loneBoost === void 0 ? void 0 : loneBoost.subId).to.equal(1);
694
+ });
670
695
  }));
671
696
  });
@@ -1,6 +1,7 @@
1
1
  import type { ArbitrumBundleInfo, ArbitrumStrategiesInfo, BundlesInfo, EthereumAddress, Interfaces, MainnetBundleInfo, MainnetStrategiesInfo, OptimismBundleInfo, OptimismStrategiesInfo, BaseBundleInfo, BaseStrategiesInfo, StrategiesInfo } from '../types';
2
2
  import { ProtocolIdentifiers, Strategies, Bundles } from '../types/enums';
3
3
  export declare const ZERO_ADDRESS: EthereumAddress;
4
+ export declare const EMPTY_SLOT: string;
4
5
  export declare const AAVE_V3_VARIABLE_BORROW_RATE = 2;
5
6
  export declare const PROTOCOLS: Record<keyof typeof ProtocolIdentifiers.StrategiesAutomation, Interfaces.Protocol>;
6
7
  export declare const LEGACY_PROTOCOLS: Record<keyof typeof ProtocolIdentifiers.LegacyAutomation, Interfaces.LegacyProtocol>;
@@ -3,12 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.BUNDLE_IDS = exports.BUNDLES_INFO = exports.ARBITRUM_BUNDLES_INFO = exports.BASE_BUNDLES_INFO = exports.OPTIMISM_BUNDLES_INFO = exports.MAINNET_BUNDLES_INFO = exports.STRATEGY_IDS = exports.STRATEGIES_INFO = exports.ARBITRUM_STRATEGIES_INFO = exports.BASE_STRATEGIES_INFO = exports.OPTIMISM_STRATEGIES_INFO = exports.MAINNET_STRATEGIES_INFO = exports.LEGACY_PROTOCOLS = exports.PROTOCOLS = exports.AAVE_V3_VARIABLE_BORROW_RATE = exports.ZERO_ADDRESS = void 0;
6
+ exports.BUNDLE_IDS = exports.BUNDLES_INFO = exports.ARBITRUM_BUNDLES_INFO = exports.BASE_BUNDLES_INFO = exports.OPTIMISM_BUNDLES_INFO = exports.MAINNET_BUNDLES_INFO = exports.STRATEGY_IDS = exports.STRATEGIES_INFO = exports.ARBITRUM_STRATEGIES_INFO = exports.BASE_STRATEGIES_INFO = exports.OPTIMISM_STRATEGIES_INFO = exports.MAINNET_STRATEGIES_INFO = exports.LEGACY_PROTOCOLS = exports.PROTOCOLS = exports.AAVE_V3_VARIABLE_BORROW_RATE = exports.EMPTY_SLOT = exports.ZERO_ADDRESS = void 0;
7
7
  const enums_1 = require("../types/enums");
8
8
  const Protocol_1 = __importDefault(require("../automation/private/Protocol"));
9
9
  const LegacyProtocol_1 = __importDefault(require("../automation/private/LegacyProtocol"));
10
10
  // General
11
11
  exports.ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
12
+ exports.EMPTY_SLOT = '0x0000000000000000000000000000000000000000000000000000000000000000';
12
13
  exports.AAVE_V3_VARIABLE_BORROW_RATE = 2;
13
14
  exports.PROTOCOLS = (() => {
14
15
  const protocolsMapping = {};
@@ -106,6 +107,16 @@ exports.MAINNET_STRATEGIES_INFO = {
106
107
  strategyId: enums_1.Strategies.Identifiers.CollateralSwitch,
107
108
  protocol: exports.PROTOCOLS.AaveV3,
108
109
  },
110
+ [enums_1.Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH]: {
111
+ strategyOrBundleId: enums_1.Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH,
112
+ strategyId: enums_1.Strategies.Identifiers.CollateralSwitch,
113
+ protocol: exports.PROTOCOLS.AaveV4,
114
+ },
115
+ [enums_1.Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH_EOA]: {
116
+ strategyOrBundleId: enums_1.Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH_EOA,
117
+ strategyId: enums_1.Strategies.Identifiers.EoaCollateralSwitch,
118
+ protocol: exports.PROTOCOLS.AaveV4,
119
+ },
109
120
  };
110
121
  exports.OPTIMISM_STRATEGIES_INFO = {
111
122
  [enums_1.Strategies.OptimismIds.EXCHANGE_DCA]: {
@@ -473,6 +484,66 @@ exports.MAINNET_BUNDLES_INFO = {
473
484
  strategyId: enums_1.Strategies.Identifiers.CloseOnPrice,
474
485
  protocol: exports.PROTOCOLS.MorphoBlue,
475
486
  },
487
+ [enums_1.Bundles.MainnetIds.SPARK_REPAY_ON_PRICE]: {
488
+ strategyOrBundleId: enums_1.Bundles.MainnetIds.SPARK_REPAY_ON_PRICE,
489
+ strategyId: enums_1.Strategies.Identifiers.RepayOnPrice,
490
+ protocol: exports.PROTOCOLS.Spark,
491
+ },
492
+ [enums_1.Bundles.MainnetIds.SPARK_BOOST_ON_PRICE]: {
493
+ strategyOrBundleId: enums_1.Bundles.MainnetIds.SPARK_BOOST_ON_PRICE,
494
+ strategyId: enums_1.Strategies.Identifiers.BoostOnPrice,
495
+ protocol: exports.PROTOCOLS.Spark,
496
+ },
497
+ [enums_1.Bundles.MainnetIds.AAVE_V4_REPAY]: {
498
+ strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_REPAY,
499
+ strategyId: enums_1.Strategies.Identifiers.Repay,
500
+ protocol: exports.PROTOCOLS.AaveV4,
501
+ },
502
+ [enums_1.Bundles.MainnetIds.AAVE_V4_BOOST]: {
503
+ strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_BOOST,
504
+ strategyId: enums_1.Strategies.Identifiers.Boost,
505
+ protocol: exports.PROTOCOLS.AaveV4,
506
+ },
507
+ [enums_1.Bundles.MainnetIds.AAVE_V4_REPAY_ON_PRICE]: {
508
+ strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_REPAY_ON_PRICE,
509
+ strategyId: enums_1.Strategies.Identifiers.RepayOnPrice,
510
+ protocol: exports.PROTOCOLS.AaveV4,
511
+ },
512
+ [enums_1.Bundles.MainnetIds.AAVE_V4_BOOST_ON_PRICE]: {
513
+ strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_BOOST_ON_PRICE,
514
+ strategyId: enums_1.Strategies.Identifiers.BoostOnPrice,
515
+ protocol: exports.PROTOCOLS.AaveV4,
516
+ },
517
+ [enums_1.Bundles.MainnetIds.AAVE_V4_CLOSE]: {
518
+ strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_CLOSE,
519
+ strategyId: enums_1.Strategies.Identifiers.CloseOnPrice,
520
+ protocol: exports.PROTOCOLS.AaveV4,
521
+ },
522
+ [enums_1.Bundles.MainnetIds.AAVE_V4_EOA_REPAY]: {
523
+ strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_EOA_REPAY,
524
+ strategyId: enums_1.Strategies.Identifiers.EoaRepay,
525
+ protocol: exports.PROTOCOLS.AaveV4,
526
+ },
527
+ [enums_1.Bundles.MainnetIds.AAVE_V4_EOA_BOOST]: {
528
+ strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_EOA_BOOST,
529
+ strategyId: enums_1.Strategies.Identifiers.EoaBoost,
530
+ protocol: exports.PROTOCOLS.AaveV4,
531
+ },
532
+ [enums_1.Bundles.MainnetIds.AAVE_V4_EOA_REPAY_ON_PRICE]: {
533
+ strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_EOA_REPAY_ON_PRICE,
534
+ strategyId: enums_1.Strategies.Identifiers.EoaRepayOnPrice,
535
+ protocol: exports.PROTOCOLS.AaveV4,
536
+ },
537
+ [enums_1.Bundles.MainnetIds.AAVE_V4_EOA_BOOST_ON_PRICE]: {
538
+ strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_EOA_BOOST_ON_PRICE,
539
+ strategyId: enums_1.Strategies.Identifiers.EoaBoostOnPrice,
540
+ protocol: exports.PROTOCOLS.AaveV4,
541
+ },
542
+ [enums_1.Bundles.MainnetIds.AAVE_V4_EOA_CLOSE]: {
543
+ strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_EOA_CLOSE,
544
+ strategyId: enums_1.Strategies.Identifiers.EoaCloseOnPrice,
545
+ protocol: exports.PROTOCOLS.AaveV4,
546
+ },
476
547
  };
477
548
  exports.OPTIMISM_BUNDLES_INFO = {
478
549
  [enums_1.Bundles.OptimismIds.AAVE_V3_REPAY]: {
@@ -147,6 +147,7 @@ describe('Feature: ethereumService.ts', () => {
147
147
  'address': '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1',
148
148
  'blockHash': '0xacb0213af63b4c17c436f084a96d1ac385641a59a9a4cf014ae3337cbe545aa7',
149
149
  'blockNumber': 5353002,
150
+ 'blockTimestamp': '0x624c1a5b',
150
151
  'event': 'Transfer',
151
152
  'id': 'log_f49645b8',
152
153
  'logIndex': 1,
@@ -192,6 +193,7 @@ describe('Feature: ethereumService.ts', () => {
192
193
  'address': '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1',
193
194
  'blockHash': '0xacb0213af63b4c17c436f084a96d1ac385641a59a9a4cf014ae3337cbe545aa7',
194
195
  'blockNumber': 5353002,
196
+ 'blockTimestamp': '0x624c1a5b',
195
197
  'event': 'Transfer',
196
198
  'id': 'log_f49645b8',
197
199
  'logIndex': 1,
@@ -314,6 +314,96 @@ function parseAaveV3CollateralSwitch(position, parseData) {
314
314
  _position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
315
315
  return _position;
316
316
  }
317
+ function parseAaveV4LeverageManagement(position, parseData) {
318
+ const _position = (0, lodash_1.cloneDeep)(position);
319
+ const { subStruct, subId, subHash } = parseData.subscriptionEventData;
320
+ const { isEnabled } = parseData.strategiesSubsData;
321
+ const triggerData = triggerService.aaveV4RatioTrigger.decode(subStruct.triggerData);
322
+ const subData = subDataService.aaveV4LeverageManagementSubData.decode(subStruct.subData);
323
+ const isEOA = _position.strategy.strategyId.includes('eoa');
324
+ const isRepay = [enums_1.Strategies.Identifiers.Repay, enums_1.Strategies.Identifiers.EoaRepay].includes(_position.strategy.strategyId);
325
+ _position.strategyData.decoded.triggerData = triggerData;
326
+ _position.strategyData.decoded.subData = subData;
327
+ _position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, triggerData.spoke);
328
+ _position.strategy.strategyId = isEOA ? enums_1.Strategies.IdOverrides.EoaLeverageManagement : enums_1.Strategies.IdOverrides.LeverageManagement;
329
+ if (isRepay) {
330
+ _position.specific = {
331
+ triggerRepayRatio: triggerData.ratio,
332
+ targetRepayRatio: subData.targetRatio,
333
+ repayEnabled: isEnabled,
334
+ subId1: Number(subId),
335
+ mergeWithId: isEOA ? enums_1.Strategies.Identifiers.EoaBoost : enums_1.Strategies.Identifiers.Boost,
336
+ subHashRepay: subHash,
337
+ };
338
+ }
339
+ else {
340
+ _position.specific = {
341
+ triggerBoostRatio: triggerData.ratio,
342
+ targetBoostRatio: subData.targetRatio,
343
+ boostEnabled: isEnabled,
344
+ subId2: Number(subId),
345
+ mergeId: isEOA ? enums_1.Strategies.Identifiers.EoaBoost : enums_1.Strategies.Identifiers.Boost,
346
+ subHashBoost: subHash,
347
+ };
348
+ }
349
+ return _position;
350
+ }
351
+ function parseAaveV4LeverageManagementOnPrice(position, parseData) {
352
+ const _position = (0, lodash_1.cloneDeep)(position);
353
+ const { subStruct } = parseData.subscriptionEventData;
354
+ const triggerData = triggerService.aaveV4QuotePriceTrigger.decode(subStruct.triggerData);
355
+ const subData = subDataService.aaveV4LeverageManagementOnPriceSubData.decode(subStruct.subData);
356
+ const isEOA = _position.strategy.strategyId.includes('eoa');
357
+ _position.strategyData.decoded.triggerData = triggerData;
358
+ _position.strategyData.decoded.subData = subData;
359
+ _position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, triggerData.spoke);
360
+ _position.strategy.strategyId = isEOA ? enums_1.Strategies.IdOverrides.EoaLeverageManagementOnPrice : enums_1.Strategies.IdOverrides.LeverageManagementOnPrice;
361
+ _position.specific = {
362
+ collAsset: subData.collAsset,
363
+ collAssetId: subData.collAssetId,
364
+ debtAsset: subData.debtAsset,
365
+ debtAssetId: subData.debtAssetId,
366
+ price: triggerData.price,
367
+ ratioState: triggerData.ratioState,
368
+ ratio: subData.targetRatio,
369
+ };
370
+ return _position;
371
+ }
372
+ function parseAaveV4CloseOnPrice(position, parseData) {
373
+ const _position = (0, lodash_1.cloneDeep)(position);
374
+ const { subStruct } = parseData.subscriptionEventData;
375
+ const triggerData = triggerService.aaveV4QuotePriceRangeTrigger.decode(subStruct.triggerData);
376
+ const subData = subDataService.aaveV4CloseSubData.decode(subStruct.subData);
377
+ const { takeProfitType, stopLossType } = (0, utils_1.getStopLossAndTakeProfitTypeByCloseStrategyType)(+subData.closeType);
378
+ const isEOA = _position.strategy.strategyId.includes('eoa');
379
+ _position.strategyData.decoded.triggerData = triggerData;
380
+ _position.strategyData.decoded.subData = subData;
381
+ _position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, triggerData.spoke);
382
+ _position.strategy.strategyId = isEOA ? enums_1.Strategies.Identifiers.EoaCloseOnPrice : enums_1.Strategies.Identifiers.CloseOnPrice;
383
+ _position.specific = {
384
+ collAsset: subData.collAsset,
385
+ collAssetId: subData.collAssetId,
386
+ debtAsset: subData.debtAsset,
387
+ debtAssetId: subData.debtAssetId,
388
+ stopLossPrice: triggerData.lowerPrice,
389
+ takeProfitPrice: triggerData.upperPrice,
390
+ stopLossType,
391
+ takeProfitType,
392
+ };
393
+ return _position;
394
+ }
395
+ function parseAaveV4CollateralSwitch(position, parseData) {
396
+ const _position = (0, lodash_1.cloneDeep)(position);
397
+ const { subStruct } = parseData.subscriptionEventData;
398
+ const triggerData = triggerService.aaveV4QuotePriceTrigger.decode(subStruct.triggerData);
399
+ const subData = subDataService.aaveV4CollateralSwitchSubData.decode(subStruct.subData);
400
+ const isEOA = _position.strategy.strategyId.includes('eoa');
401
+ _position.strategyData.decoded.triggerData = triggerData;
402
+ _position.strategyData.decoded.subData = subData;
403
+ _position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, triggerData.spoke);
404
+ _position.strategy.strategyId = isEOA ? enums_1.Strategies.Identifiers.EoaCollateralSwitch : enums_1.Strategies.Identifiers.CollateralSwitch;
405
+ return _position;
406
+ }
317
407
  function parseMorphoAaveV2LeverageManagement(position, parseData) {
318
408
  const _position = (0, lodash_1.cloneDeep)(position);
319
409
  const { subStruct, subId } = parseData.subscriptionEventData;
@@ -613,6 +703,29 @@ function parseSparkLeverageManagement(position, parseData) {
613
703
  _position.strategy.strategyId = enums_1.Strategies.IdOverrides.LeverageManagement;
614
704
  return _position;
615
705
  }
706
+ function parseSparkLeverageManagementOnPrice(position, parseData) {
707
+ const _position = (0, lodash_1.cloneDeep)(position);
708
+ const { subStruct } = parseData.subscriptionEventData;
709
+ const triggerData = triggerService.sparkQuotePriceTrigger.decode(subStruct.triggerData);
710
+ const subData = subDataService.sparkLeverageManagementOnPriceSubData.decode(subStruct.subData);
711
+ _position.strategyData.decoded.triggerData = triggerData;
712
+ _position.strategyData.decoded.subData = subData;
713
+ _position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
714
+ _position.specific = {
715
+ // subData
716
+ collAsset: subData.collAsset,
717
+ collAssetId: subData.collAssetId,
718
+ debtAsset: subData.debtAsset,
719
+ debtAssetId: subData.debtAssetId,
720
+ ratio: subData.targetRatio,
721
+ // triggerData
722
+ baseToken: triggerData.baseTokenAddr,
723
+ quoteToken: triggerData.quoteTokenAddr,
724
+ price: triggerData.price,
725
+ ratioState: triggerData.ratioState,
726
+ };
727
+ return _position;
728
+ }
616
729
  function parseSparkCloseOnPrice(position, parseData) {
617
730
  const _position = (0, lodash_1.cloneDeep)(position);
618
731
  const { subStruct } = parseData.subscriptionEventData;
@@ -943,6 +1056,20 @@ const parsingMethodsMapping = {
943
1056
  [enums_1.Strategies.Identifiers.EoaCloseOnPrice]: parseAaveV3CloseOnPrice,
944
1057
  [enums_1.Strategies.Identifiers.CollateralSwitch]: parseAaveV3CollateralSwitch,
945
1058
  },
1059
+ [enums_1.ProtocolIdentifiers.StrategiesAutomation.AaveV4]: {
1060
+ [enums_1.Strategies.Identifiers.Repay]: parseAaveV4LeverageManagement,
1061
+ [enums_1.Strategies.Identifiers.Boost]: parseAaveV4LeverageManagement,
1062
+ [enums_1.Strategies.Identifiers.RepayOnPrice]: parseAaveV4LeverageManagementOnPrice,
1063
+ [enums_1.Strategies.Identifiers.BoostOnPrice]: parseAaveV4LeverageManagementOnPrice,
1064
+ [enums_1.Strategies.Identifiers.CloseOnPrice]: parseAaveV4CloseOnPrice,
1065
+ [enums_1.Strategies.Identifiers.EoaRepay]: parseAaveV4LeverageManagement,
1066
+ [enums_1.Strategies.Identifiers.EoaBoost]: parseAaveV4LeverageManagement,
1067
+ [enums_1.Strategies.Identifiers.EoaRepayOnPrice]: parseAaveV4LeverageManagementOnPrice,
1068
+ [enums_1.Strategies.Identifiers.EoaBoostOnPrice]: parseAaveV4LeverageManagementOnPrice,
1069
+ [enums_1.Strategies.Identifiers.EoaCloseOnPrice]: parseAaveV4CloseOnPrice,
1070
+ [enums_1.Strategies.Identifiers.CollateralSwitch]: parseAaveV4CollateralSwitch,
1071
+ [enums_1.Strategies.Identifiers.EoaCollateralSwitch]: parseAaveV4CollateralSwitch,
1072
+ },
946
1073
  [enums_1.ProtocolIdentifiers.StrategiesAutomation.CompoundV2]: {
947
1074
  [enums_1.Strategies.Identifiers.Repay]: parseCompoundV2LeverageManagement,
948
1075
  [enums_1.Strategies.Identifiers.Boost]: parseCompoundV2LeverageManagement,
@@ -973,6 +1100,8 @@ const parsingMethodsMapping = {
973
1100
  [enums_1.ProtocolIdentifiers.StrategiesAutomation.Spark]: {
974
1101
  [enums_1.Strategies.Identifiers.Repay]: parseSparkLeverageManagement,
975
1102
  [enums_1.Strategies.Identifiers.Boost]: parseSparkLeverageManagement,
1103
+ [enums_1.Strategies.Identifiers.RepayOnPrice]: parseSparkLeverageManagementOnPrice,
1104
+ [enums_1.Strategies.Identifiers.BoostOnPrice]: parseSparkLeverageManagementOnPrice,
976
1105
  [enums_1.Strategies.Identifiers.CloseOnPrice]: parseSparkCloseOnPrice,
977
1106
  },
978
1107
  [enums_1.ProtocolIdentifiers.StrategiesAutomation.CrvUSD]: {
@@ -86,6 +86,19 @@ export declare const exchangeEncode: {
86
86
  };
87
87
  export declare const sparkEncode: {
88
88
  leverageManagement(triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean): string;
89
+ leverageManagementOnPrice(strategyOrBundleId: number, isBundle: boolean | undefined, triggerData: {
90
+ baseTokenAddr: EthereumAddress;
91
+ quoteTokenAddr: EthereumAddress;
92
+ price: number;
93
+ ratioState: RatioState;
94
+ }, subData: {
95
+ collAsset: EthereumAddress;
96
+ collAssetId: number;
97
+ debtAsset: EthereumAddress;
98
+ debtAssetId: number;
99
+ marketAddr: EthereumAddress;
100
+ targetRatio: number;
101
+ }): (number | boolean | string[])[];
89
102
  closeOnPriceGeneric(strategyOrBundleId: number, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, user: EthereumAddress, stopLossPrice?: number, stopLossType?: CloseToAssetType, takeProfitPrice?: number, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
90
103
  leverageManagementWithoutSubProxy(strategyOrBundleId: number, market: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
91
104
  };
@@ -107,3 +120,9 @@ export declare const liquityV2Encode: {
107
120
  export declare const fluidEncode: {
108
121
  leverageManagement(nftId: string, vault: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, strategyOrBundleId: number): (number | boolean | string[])[];
109
122
  };
123
+ export declare const aaveV4Encode: {
124
+ leverageManagement(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
125
+ leverageManagementOnPrice(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, targetRatio: number, price: string, priceState: RatioState, ratioState: RatioState): (number | boolean | string[])[];
126
+ closeOnPrice(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, stopLossPrice?: string, stopLossType?: CloseToAssetType, takeProfitPrice?: string, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
127
+ collateralSwitch(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, amountToSwitch: string, price: string, ratioState: RatioState): (number | boolean | string[])[];
128
+ };
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.fluidEncode = exports.liquityV2Encode = exports.morphoBlueEncode = exports.crvUSDEncode = exports.sparkEncode = exports.exchangeEncode = exports.morphoAaveV2Encode = exports.compoundV3L2Encode = exports.compoundV3Encode = exports.compoundV2Encode = exports.aaveV3Encode = exports.aaveV2Encode = exports.chickenBondsEncode = exports.liquityEncode = exports.makerEncode = void 0;
29
+ exports.aaveV4Encode = exports.fluidEncode = exports.liquityV2Encode = exports.morphoBlueEncode = exports.crvUSDEncode = exports.sparkEncode = exports.exchangeEncode = exports.morphoAaveV2Encode = exports.compoundV3L2Encode = exports.compoundV3Encode = exports.compoundV2Encode = exports.aaveV3Encode = exports.aaveV2Encode = exports.chickenBondsEncode = exports.liquityEncode = exports.makerEncode = void 0;
30
30
  const decimal_js_1 = __importDefault(require("decimal.js"));
31
31
  const tokens_1 = require("@defisaver/tokens");
32
32
  const enums_1 = require("../types/enums");
@@ -272,6 +272,13 @@ exports.sparkEncode = {
272
272
  subInput = subInput.concat(boostEnabled ? '01' : '00');
273
273
  return subInput;
274
274
  },
275
+ leverageManagementOnPrice(strategyOrBundleId, isBundle = true, triggerData, subData) {
276
+ const { collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio, } = subData;
277
+ const subDataEncoded = subDataService.sparkLeverageManagementOnPriceSubData.encode(collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio);
278
+ const { baseTokenAddr, quoteTokenAddr, price, ratioState, } = triggerData;
279
+ const triggerDataEncoded = triggerService.sparkQuotePriceTrigger.encode(baseTokenAddr, quoteTokenAddr, price, ratioState);
280
+ return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
281
+ },
275
282
  closeOnPriceGeneric(strategyOrBundleId, collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, user, stopLossPrice = 0, stopLossType = enums_1.CloseToAssetType.DEBT, takeProfitPrice = 0, takeProfitType = enums_1.CloseToAssetType.COLLATERAL) {
276
283
  const isBundle = true;
277
284
  const closeType = (0, utils_1.getCloseStrategyType)(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
@@ -370,3 +377,32 @@ exports.fluidEncode = {
370
377
  return [strategyOrBundleId, isBundle, triggerData, subData];
371
378
  },
372
379
  };
380
+ exports.aaveV4Encode = {
381
+ leverageManagement(strategyOrBundleId, owner, spoke, ratioState, targetRatio, triggerRatio) {
382
+ const isBundle = true;
383
+ const subData = subDataService.aaveV4LeverageManagementSubData.encode(spoke, owner, ratioState, targetRatio);
384
+ const triggerData = triggerService.aaveV4RatioTrigger.encode(owner, spoke, triggerRatio, ratioState);
385
+ return [strategyOrBundleId, isBundle, triggerData, subData];
386
+ },
387
+ leverageManagementOnPrice(strategyOrBundleId, owner, spoke, collAsset, collAssetId, debtAsset, debtAssetId, targetRatio, price, priceState, ratioState) {
388
+ const isBundle = true;
389
+ const subData = subDataService.aaveV4LeverageManagementOnPriceSubData.encode(spoke, owner, collAsset, collAssetId, debtAsset, debtAssetId, ratioState, targetRatio);
390
+ const triggerData = triggerService.aaveV4QuotePriceTrigger.encode(spoke, collAssetId, debtAssetId, price, priceState);
391
+ return [strategyOrBundleId, isBundle, triggerData, subData];
392
+ },
393
+ closeOnPrice(strategyOrBundleId, owner, spoke, collAsset, collAssetId, debtAsset, debtAssetId, stopLossPrice = '0', stopLossType = enums_1.CloseToAssetType.DEBT, takeProfitPrice = '0', takeProfitType = enums_1.CloseToAssetType.COLLATERAL) {
394
+ const isBundle = true;
395
+ const closeType = (0, utils_1.getCloseStrategyType)(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
396
+ const subData = subDataService.aaveV4CloseSubData.encode(spoke, owner, collAsset, collAssetId, debtAsset, debtAssetId, closeType);
397
+ const triggerData = triggerService.aaveV4QuotePriceRangeTrigger.encode(spoke, collAssetId, debtAssetId, stopLossPrice, takeProfitPrice);
398
+ return [strategyOrBundleId, isBundle, triggerData, subData];
399
+ },
400
+ collateralSwitch(strategyOrBundleId, owner, spoke, fromAsset, fromAssetId, toAsset, toAssetId, amountToSwitch, price, ratioState) {
401
+ const isBundle = false;
402
+ const subData = subDataService.aaveV4CollateralSwitchSubData.encode(spoke, owner, fromAsset, fromAssetId, toAsset, toAssetId, amountToSwitch);
403
+ const triggerData = triggerService.aaveV4QuotePriceTrigger.encode(spoke, fromAssetId, // baseTokenId
404
+ toAssetId, // quoteTokenId
405
+ price, ratioState);
406
+ return [strategyOrBundleId, isBundle, triggerData, subData];
407
+ },
408
+ };