@defisaver/automation-sdk 3.3.8 → 3.3.10-aave-v4-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 (42) hide show
  1. package/cjs/constants/index.js +55 -0
  2. package/cjs/services/ethereumService.js +21 -14
  3. package/cjs/services/strategiesService.js +101 -0
  4. package/cjs/services/strategySubService.d.ts +8 -0
  5. package/cjs/services/strategySubService.js +47 -1
  6. package/cjs/services/strategySubService.test.js +143 -0
  7. package/cjs/services/subDataService.d.ts +302 -129
  8. package/cjs/services/subDataService.js +629 -372
  9. package/cjs/services/subDataService.test.js +213 -0
  10. package/cjs/services/triggerService.d.ts +29 -0
  11. package/cjs/services/triggerService.js +55 -1
  12. package/cjs/services/triggerService.test.js +84 -0
  13. package/cjs/types/enums.d.ts +14 -2
  14. package/cjs/types/enums.js +12 -0
  15. package/cjs/types/index.d.ts +22 -1
  16. package/esm/constants/index.js +55 -0
  17. package/esm/services/ethereumService.js +21 -14
  18. package/esm/services/strategiesService.js +102 -1
  19. package/esm/services/strategySubService.d.ts +8 -0
  20. package/esm/services/strategySubService.js +46 -0
  21. package/esm/services/strategySubService.test.js +144 -1
  22. package/esm/services/subDataService.d.ts +302 -129
  23. package/esm/services/subDataService.js +628 -371
  24. package/esm/services/subDataService.test.js +213 -0
  25. package/esm/services/triggerService.d.ts +29 -0
  26. package/esm/services/triggerService.js +54 -0
  27. package/esm/services/triggerService.test.js +85 -1
  28. package/esm/types/enums.d.ts +14 -2
  29. package/esm/types/enums.js +12 -0
  30. package/esm/types/index.d.ts +22 -1
  31. package/package.json +1 -1
  32. package/src/constants/index.ts +55 -0
  33. package/src/services/ethereumService.ts +23 -16
  34. package/src/services/strategiesService.ts +116 -1
  35. package/src/services/strategySubService.test.ts +180 -0
  36. package/src/services/strategySubService.ts +162 -2
  37. package/src/services/subDataService.test.ts +233 -0
  38. package/src/services/subDataService.ts +977 -703
  39. package/src/services/triggerService.test.ts +99 -0
  40. package/src/services/triggerService.ts +76 -1
  41. package/src/types/enums.ts +12 -0
  42. package/src/types/index.ts +27 -1
@@ -106,6 +106,11 @@ exports.MAINNET_STRATEGIES_INFO = {
106
106
  strategyId: enums_1.Strategies.Identifiers.CollateralSwitch,
107
107
  protocol: exports.PROTOCOLS.AaveV3,
108
108
  },
109
+ [enums_1.Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH]: {
110
+ strategyOrBundleId: enums_1.Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH,
111
+ strategyId: enums_1.Strategies.Identifiers.CollateralSwitch,
112
+ protocol: exports.PROTOCOLS.AaveV4,
113
+ },
109
114
  };
110
115
  exports.OPTIMISM_STRATEGIES_INFO = {
111
116
  [enums_1.Strategies.OptimismIds.EXCHANGE_DCA]: {
@@ -473,6 +478,56 @@ exports.MAINNET_BUNDLES_INFO = {
473
478
  strategyId: enums_1.Strategies.Identifiers.CloseOnPrice,
474
479
  protocol: exports.PROTOCOLS.MorphoBlue,
475
480
  },
481
+ [enums_1.Bundles.MainnetIds.AAVE_V4_REPAY]: {
482
+ strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_REPAY,
483
+ strategyId: enums_1.Strategies.Identifiers.Repay,
484
+ protocol: exports.PROTOCOLS.AaveV4,
485
+ },
486
+ [enums_1.Bundles.MainnetIds.AAVE_V4_BOOST]: {
487
+ strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_BOOST,
488
+ strategyId: enums_1.Strategies.Identifiers.Boost,
489
+ protocol: exports.PROTOCOLS.AaveV4,
490
+ },
491
+ [enums_1.Bundles.MainnetIds.AAVE_V4_REPAY_ON_PRICE]: {
492
+ strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_REPAY_ON_PRICE,
493
+ strategyId: enums_1.Strategies.Identifiers.RepayOnPrice,
494
+ protocol: exports.PROTOCOLS.AaveV4,
495
+ },
496
+ [enums_1.Bundles.MainnetIds.AAVE_V4_BOOST_ON_PRICE]: {
497
+ strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_BOOST_ON_PRICE,
498
+ strategyId: enums_1.Strategies.Identifiers.BoostOnPrice,
499
+ protocol: exports.PROTOCOLS.AaveV4,
500
+ },
501
+ [enums_1.Bundles.MainnetIds.AAVE_V4_CLOSE]: {
502
+ strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_CLOSE,
503
+ strategyId: enums_1.Strategies.Identifiers.CloseOnPrice,
504
+ protocol: exports.PROTOCOLS.AaveV4,
505
+ },
506
+ [enums_1.Bundles.MainnetIds.AAVE_V4_EOA_REPAY]: {
507
+ strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_EOA_REPAY,
508
+ strategyId: enums_1.Strategies.Identifiers.EoaRepay,
509
+ protocol: exports.PROTOCOLS.AaveV4,
510
+ },
511
+ [enums_1.Bundles.MainnetIds.AAVE_V4_EOA_BOOST]: {
512
+ strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_EOA_BOOST,
513
+ strategyId: enums_1.Strategies.Identifiers.EoaBoost,
514
+ protocol: exports.PROTOCOLS.AaveV4,
515
+ },
516
+ [enums_1.Bundles.MainnetIds.AAVE_V4_EOA_REPAY_ON_PRICE]: {
517
+ strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_EOA_REPAY_ON_PRICE,
518
+ strategyId: enums_1.Strategies.Identifiers.EoaRepayOnPrice,
519
+ protocol: exports.PROTOCOLS.AaveV4,
520
+ },
521
+ [enums_1.Bundles.MainnetIds.AAVE_V4_EOA_BOOST_ON_PRICE]: {
522
+ strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_EOA_BOOST_ON_PRICE,
523
+ strategyId: enums_1.Strategies.Identifiers.EoaBoostOnPrice,
524
+ protocol: exports.PROTOCOLS.AaveV4,
525
+ },
526
+ [enums_1.Bundles.MainnetIds.AAVE_V4_EOA_CLOSE]: {
527
+ strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_EOA_CLOSE,
528
+ strategyId: enums_1.Strategies.Identifiers.EoaCloseOnPrice,
529
+ protocol: exports.PROTOCOLS.AaveV4,
530
+ },
476
531
  };
477
532
  exports.OPTIMISM_BUNDLES_INFO = {
478
533
  [enums_1.Bundles.OptimismIds.AAVE_V3_REPAY]: {
@@ -19,20 +19,27 @@ const utils_1 = require("./utils");
19
19
  function multicall(web3, chainId, calls, block = 'latest') {
20
20
  return __awaiter(this, void 0, void 0, function* () {
21
21
  const multicallContract = (0, contractService_1.makeUniMulticallContract)(web3, chainId).contract;
22
- const formattedCalls = calls.map((call) => ({
23
- callData: web3_eth_abi_1.default.encodeFunctionCall(call.abiItem, call.params),
24
- target: call.target || '0x0',
25
- gasLimit: call.gasLimit || 1e6,
26
- }));
27
- const callResult = yield multicallContract.methods.multicall(formattedCalls.filter(item => item.target !== '0x0')).call({}, block);
28
- let formattedResult = [];
29
- callResult.returnData.forEach(([success, gasUsed, result], i) => {
30
- const formattedRes = (result !== '0x'
31
- ? web3_eth_abi_1.default.decodeParameters(calls[i].abiItem.outputs, result)
32
- : undefined);
33
- formattedResult = [...formattedResult, formattedRes];
34
- });
35
- return formattedResult;
22
+ const MAX_CALLS_PER_BATCH = 1000;
23
+ const allResults = [];
24
+ // Process each chunk
25
+ for (let i = 0; i < calls.length; i += MAX_CALLS_PER_BATCH) {
26
+ const chunk = calls.slice(i, i + MAX_CALLS_PER_BATCH);
27
+ const formattedCalls = chunk.map((call) => ({
28
+ callData: web3_eth_abi_1.default.encodeFunctionCall(call.abiItem, call.params),
29
+ target: call.target || '0x0',
30
+ gasLimit: call.gasLimit || 1e6,
31
+ }));
32
+ const callResult = yield multicallContract.methods.multicall(formattedCalls).call({}, block);
33
+ let formattedResult = [];
34
+ callResult.returnData.forEach(([success, , result], j) => {
35
+ const formattedRes = (success && result !== '0x'
36
+ ? web3_eth_abi_1.default.decodeParameters(chunk[j].abiItem.outputs, result)
37
+ : undefined);
38
+ formattedResult = [...formattedResult, formattedRes];
39
+ });
40
+ allResults.push(...formattedResult);
41
+ }
42
+ return allResults;
36
43
  });
37
44
  }
38
45
  exports.multicall = multicall;
@@ -314,6 +314,94 @@ 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
+ _position.strategyData.decoded.triggerData = triggerData;
401
+ _position.strategyData.decoded.subData = subData;
402
+ _position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, triggerData.spoke);
403
+ return _position;
404
+ }
317
405
  function parseMorphoAaveV2LeverageManagement(position, parseData) {
318
406
  const _position = (0, lodash_1.cloneDeep)(position);
319
407
  const { subStruct, subId } = parseData.subscriptionEventData;
@@ -943,6 +1031,19 @@ const parsingMethodsMapping = {
943
1031
  [enums_1.Strategies.Identifiers.EoaCloseOnPrice]: parseAaveV3CloseOnPrice,
944
1032
  [enums_1.Strategies.Identifiers.CollateralSwitch]: parseAaveV3CollateralSwitch,
945
1033
  },
1034
+ [enums_1.ProtocolIdentifiers.StrategiesAutomation.AaveV4]: {
1035
+ [enums_1.Strategies.Identifiers.Repay]: parseAaveV4LeverageManagement,
1036
+ [enums_1.Strategies.Identifiers.Boost]: parseAaveV4LeverageManagement,
1037
+ [enums_1.Strategies.Identifiers.RepayOnPrice]: parseAaveV4LeverageManagementOnPrice,
1038
+ [enums_1.Strategies.Identifiers.BoostOnPrice]: parseAaveV4LeverageManagementOnPrice,
1039
+ [enums_1.Strategies.Identifiers.CloseOnPrice]: parseAaveV4CloseOnPrice,
1040
+ [enums_1.Strategies.Identifiers.EoaRepay]: parseAaveV4LeverageManagement,
1041
+ [enums_1.Strategies.Identifiers.EoaBoost]: parseAaveV4LeverageManagement,
1042
+ [enums_1.Strategies.Identifiers.EoaRepayOnPrice]: parseAaveV4LeverageManagementOnPrice,
1043
+ [enums_1.Strategies.Identifiers.EoaBoostOnPrice]: parseAaveV4LeverageManagementOnPrice,
1044
+ [enums_1.Strategies.Identifiers.EoaCloseOnPrice]: parseAaveV4CloseOnPrice,
1045
+ [enums_1.Strategies.Identifiers.CollateralSwitch]: parseAaveV4CollateralSwitch,
1046
+ },
946
1047
  [enums_1.ProtocolIdentifiers.StrategiesAutomation.CompoundV2]: {
947
1048
  [enums_1.Strategies.Identifiers.Repay]: parseCompoundV2LeverageManagement,
948
1049
  [enums_1.Strategies.Identifiers.Boost]: parseCompoundV2LeverageManagement,
@@ -6,6 +6,7 @@ export declare const makerEncode: {
6
6
  closeOnPrice(vaultId: number, ratioState: RatioState, price: string, closeToAssetAddr: EthereumAddress, chainlinkCollAddress: EthereumAddress, chainId?: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress): (boolean | string[] | Strategies.MainnetIds)[];
7
7
  trailingStop(vaultId: number, triggerPercentage: number, closeToAssetAddr: EthereumAddress, chainlinkCollAddress: EthereumAddress, roundId: number, chainId?: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress): (boolean | string[] | Strategies.MainnetIds)[];
8
8
  leverageManagement(vaultId: number, triggerRepayRatio: string, triggerBoostRatio: string, targetBoostRatio: string, targetRepayRatio: string, boostEnabled: boolean): (string | number | boolean)[];
9
+ leverageManagementWithoutSubProxy(vaultId: number, triggerRatio: number, targetRatio: number, ratioState: RatioState, isBoost: boolean, daiAddr?: EthereumAddress): (boolean | string[] | Bundles.MainnetIds)[];
9
10
  };
10
11
  export declare const liquityEncode: {
11
12
  closeOnPrice(priceOverOrUnder: RatioState, price: string, closeToAssetAddr: EthereumAddress, chainlinkCollAddress: EthereumAddress, chainId?: ChainId, collAddr?: EthereumAddress, debtAddr?: EthereumAddress): (boolean | string[] | Strategies.MainnetIds)[];
@@ -86,6 +87,7 @@ export declare const exchangeEncode: {
86
87
  export declare const sparkEncode: {
87
88
  leverageManagement(triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean): string;
88
89
  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
+ leverageManagementWithoutSubProxy(strategyOrBundleId: number, market: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
89
91
  };
90
92
  export declare const crvUSDEncode: {
91
93
  leverageManagement(owner: EthereumAddress, controllerAddr: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, collTokenAddr: EthereumAddress, crvUSDAddr: EthereumAddress): (boolean | string[] | Bundles.MainnetIds)[];
@@ -105,3 +107,9 @@ export declare const liquityV2Encode: {
105
107
  export declare const fluidEncode: {
106
108
  leverageManagement(nftId: string, vault: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, strategyOrBundleId: number): (number | boolean | string[])[];
107
109
  };
110
+ export declare const aaveV4Encode: {
111
+ leverageManagement(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
112
+ leverageManagementOnPrice(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, targetRatio: number, price: number, priceState: RatioState, ratioState: RatioState): (number | boolean | string[])[];
113
+ closeOnPrice(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, stopLossPrice?: number, stopLossType?: CloseToAssetType, takeProfitPrice?: number, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
114
+ collateralSwitch(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, amountToSwitch: string, price: number, ratioState: RatioState): (number | boolean | string[])[];
115
+ };
@@ -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");
@@ -70,6 +70,17 @@ exports.makerEncode = {
70
70
  boostEnabled,
71
71
  ];
72
72
  },
73
+ leverageManagementWithoutSubProxy(vaultId, triggerRatio, targetRatio, ratioState, isBoost, daiAddr) {
74
+ const bundleId = isBoost ? enums_1.Bundles.MainnetIds.MAKER_BOOST : enums_1.Bundles.MainnetIds.MAKER_REPAY;
75
+ const triggerData = triggerService.makerRatioTrigger.encode(vaultId, triggerRatio, ratioState);
76
+ const subData = subDataService.makerLeverageManagementWithoutSubProxy.encode(vaultId, targetRatio, daiAddr);
77
+ return [
78
+ bundleId,
79
+ true,
80
+ triggerData,
81
+ subData,
82
+ ];
83
+ },
73
84
  };
74
85
  exports.liquityEncode = {
75
86
  closeOnPrice(priceOverOrUnder, price, closeToAssetAddr, chainlinkCollAddress, chainId = enums_1.ChainId.Ethereum, collAddr, debtAddr) {
@@ -268,6 +279,12 @@ exports.sparkEncode = {
268
279
  const triggerDataEncoded = triggerService.sparkQuotePriceRangeTrigger.encode(collAsset, debtAsset, stopLossPrice, takeProfitPrice);
269
280
  return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
270
281
  },
282
+ leverageManagementWithoutSubProxy(strategyOrBundleId, market, user, ratioState, targetRatio, triggerRatio) {
283
+ const isBundle = true;
284
+ const subData = subDataService.sparkLeverageManagementSubDataWithoutSubProxy.encode(targetRatio, ratioState);
285
+ const triggerData = triggerService.sparkRatioTrigger.encode(user, market, triggerRatio, ratioState);
286
+ return [strategyOrBundleId, isBundle, triggerData, subData];
287
+ },
271
288
  };
272
289
  exports.crvUSDEncode = {
273
290
  leverageManagement(owner, controllerAddr, ratioState, targetRatio, triggerRatio, collTokenAddr, crvUSDAddr) {
@@ -353,3 +370,32 @@ exports.fluidEncode = {
353
370
  return [strategyOrBundleId, isBundle, triggerData, subData];
354
371
  },
355
372
  };
373
+ exports.aaveV4Encode = {
374
+ leverageManagement(strategyOrBundleId, owner, spoke, ratioState, targetRatio, triggerRatio) {
375
+ const isBundle = true;
376
+ const subData = subDataService.aaveV4LeverageManagementSubData.encode(spoke, owner, ratioState, targetRatio);
377
+ const triggerData = triggerService.aaveV4RatioTrigger.encode(owner, spoke, triggerRatio, ratioState);
378
+ return [strategyOrBundleId, isBundle, triggerData, subData];
379
+ },
380
+ leverageManagementOnPrice(strategyOrBundleId, owner, spoke, collAsset, collAssetId, debtAsset, debtAssetId, targetRatio, price, priceState, ratioState) {
381
+ const isBundle = true;
382
+ const subData = subDataService.aaveV4LeverageManagementOnPriceSubData.encode(spoke, owner, collAsset, collAssetId, debtAsset, debtAssetId, ratioState, targetRatio);
383
+ const triggerData = triggerService.aaveV4QuotePriceTrigger.encode(spoke, collAssetId, debtAssetId, price, priceState);
384
+ return [strategyOrBundleId, isBundle, triggerData, subData];
385
+ },
386
+ closeOnPrice(strategyOrBundleId, owner, spoke, collAsset, collAssetId, debtAsset, debtAssetId, stopLossPrice = 0, stopLossType = enums_1.CloseToAssetType.DEBT, takeProfitPrice = 0, takeProfitType = enums_1.CloseToAssetType.COLLATERAL) {
387
+ const isBundle = true;
388
+ const closeType = (0, utils_1.getCloseStrategyType)(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
389
+ const subData = subDataService.aaveV4CloseSubData.encode(spoke, owner, collAsset, collAssetId, debtAsset, debtAssetId, closeType);
390
+ const triggerData = triggerService.aaveV4QuotePriceRangeTrigger.encode(spoke, collAssetId, debtAssetId, stopLossPrice, takeProfitPrice);
391
+ return [strategyOrBundleId, isBundle, triggerData, subData];
392
+ },
393
+ collateralSwitch(strategyOrBundleId, owner, spoke, fromAsset, fromAssetId, toAsset, toAssetId, amountToSwitch, price, ratioState) {
394
+ const isBundle = false;
395
+ const subData = subDataService.aaveV4CollateralSwitchSubData.encode(spoke, owner, fromAsset, fromAssetId, toAsset, toAssetId, amountToSwitch);
396
+ const triggerData = triggerService.aaveV4QuotePriceTrigger.encode(spoke, fromAssetId, // baseTokenId
397
+ toAssetId, // quoteTokenId
398
+ price, ratioState);
399
+ return [strategyOrBundleId, isBundle, triggerData, subData];
400
+ },
401
+ };
@@ -146,6 +146,53 @@ describe('Feature: strategySubService.ts', () => {
146
146
  });
147
147
  });
148
148
  });
149
+ describe('leverageManagementWithoutSubProxy()', () => {
150
+ const examples = [
151
+ // Repay scenario (isBoost=false, RatioState.UNDER)
152
+ [
153
+ [
154
+ enums_1.Bundles.MainnetIds.MAKER_REPAY,
155
+ true,
156
+ ['0x00000000000000000000000000000000000000000000000000000000000000de000000000000000000000000000000000000000000000000136dcc951d8c00000000000000000000000000000000000000000000000000000000000000000001'],
157
+ [
158
+ '0x00000000000000000000000000000000000000000000000000000000000000de', '0x00000000000000000000000000000000000000000000000018fae27693b40000',
159
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
160
+ ],
161
+ ],
162
+ [
163
+ 222,
164
+ 140,
165
+ 180,
166
+ enums_1.RatioState.UNDER,
167
+ false, // isBoost
168
+ ]
169
+ ],
170
+ // Boost scenario (isBoost=true, RatioState.OVER)
171
+ [
172
+ [
173
+ enums_1.Bundles.MainnetIds.MAKER_BOOST,
174
+ true,
175
+ ['0x000000000000000000000000000000000000000000000000000000000000014d00000000000000000000000000000000000000000000000026db992a3b1800000000000000000000000000000000000000000000000000000000000000000000'],
176
+ [
177
+ '0x000000000000000000000000000000000000000000000000000000000000014d', '0x00000000000000000000000000000000000000000000000022b1c8c1227a0000',
178
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
179
+ ],
180
+ ],
181
+ [
182
+ 333,
183
+ 280,
184
+ 250,
185
+ enums_1.RatioState.OVER,
186
+ true, // isBoost
187
+ ]
188
+ ],
189
+ ];
190
+ examples.forEach(([expected, actual]) => {
191
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
192
+ (0, chai_1.expect)(strategySubService_1.makerEncode.leverageManagementWithoutSubProxy(...actual)).to.eql(expected);
193
+ });
194
+ });
195
+ });
149
196
  });
150
197
  describe('When testing strategySubService.liquityEncode', () => {
151
198
  describe('closeOnPrice()', () => {
@@ -1434,4 +1481,100 @@ describe('Feature: strategySubService.ts', () => {
1434
1481
  });
1435
1482
  });
1436
1483
  });
1484
+ describe('When testing strategySubService.aaveV4Encode', () => {
1485
+ describe('leverageManagement()', () => {
1486
+ const examples = [
1487
+ [
1488
+ [1, true, ["0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x00000000000000000000000000000000000000000000000014d1120d7b160000"]],
1489
+ [
1490
+ 1,
1491
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1492
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
1493
+ enums_1.RatioState.UNDER,
1494
+ 150,
1495
+ 120,
1496
+ ]
1497
+ ]
1498
+ ];
1499
+ examples.forEach(([expected, actual]) => {
1500
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1501
+ (0, chai_1.expect)(strategySubService_1.aaveV4Encode.leverageManagement(...actual)).to.eql(expected);
1502
+ });
1503
+ });
1504
+ });
1505
+ describe('leverageManagementOnPrice()', () => {
1506
+ const examples = [
1507
+ [
1508
+ [2, true, ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000000000000000"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x00000000000000000000000000000000000000000000000016345785d8a00000"]],
1509
+ [
1510
+ 2,
1511
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1512
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
1513
+ web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1514
+ 10,
1515
+ web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
1516
+ 20,
1517
+ 160,
1518
+ 1500,
1519
+ enums_1.RatioState.OVER,
1520
+ enums_1.RatioState.OVER, // ratioState - UNDER for repay, OVER for boost
1521
+ ]
1522
+ ]
1523
+ ];
1524
+ examples.forEach(([expected, actual]) => {
1525
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1526
+ (0, chai_1.expect)(strategySubService_1.aaveV4Encode.leverageManagementOnPrice(...actual)).to.eql(expected);
1527
+ });
1528
+ });
1529
+ });
1530
+ describe('closeOnPrice()', () => {
1531
+ const examples = [
1532
+ [
1533
+ [3, true, ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000002098a678000000000000000000000000000000000000000000000000000000000000000000"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000003"]],
1534
+ [
1535
+ 3,
1536
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1537
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
1538
+ web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1539
+ 10,
1540
+ web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
1541
+ 20,
1542
+ 1400,
1543
+ enums_1.CloseToAssetType.DEBT,
1544
+ 0,
1545
+ enums_1.CloseToAssetType.COLLATERAL
1546
+ ]
1547
+ ]
1548
+ ];
1549
+ examples.forEach(([expected, actual]) => {
1550
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1551
+ (0, chai_1.expect)(strategySubService_1.aaveV4Encode.closeOnPrice(...actual)).to.eql(expected);
1552
+ });
1553
+ });
1554
+ });
1555
+ describe('collateralSwitch()', () => {
1556
+ const examples = [
1557
+ [
1558
+ [4, false, ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000000000000001"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000"]],
1559
+ [
1560
+ 4,
1561
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1562
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
1563
+ web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1564
+ 10,
1565
+ web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
1566
+ 20,
1567
+ '1000000000000000000',
1568
+ 1500,
1569
+ enums_1.RatioState.UNDER,
1570
+ ]
1571
+ ]
1572
+ ];
1573
+ examples.forEach(([expected, actual]) => {
1574
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1575
+ (0, chai_1.expect)(strategySubService_1.aaveV4Encode.collateralSwitch(...actual)).to.eql(expected);
1576
+ });
1577
+ });
1578
+ });
1579
+ });
1437
1580
  });