@defisaver/automation-sdk 3.3.7 → 3.3.8-lev-management-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 +15 -0
  2. package/cjs/services/ethereumService.test.js +1 -0
  3. package/cjs/services/strategiesService.js +30 -0
  4. package/cjs/services/strategiesService.test.js +1 -0
  5. package/cjs/services/strategySubService.d.ts +3 -0
  6. package/cjs/services/strategySubService.js +24 -0
  7. package/cjs/services/strategySubService.test.js +40 -2
  8. package/cjs/services/subDataService.d.ts +26 -0
  9. package/cjs/services/subDataService.js +58 -1
  10. package/cjs/services/subDataService.test.js +62 -10
  11. package/cjs/services/triggerService.d.ts +10 -0
  12. package/cjs/services/triggerService.js +21 -1
  13. package/cjs/services/triggerService.test.js +48 -0
  14. package/cjs/types/enums.d.ts +6 -3
  15. package/cjs/types/enums.js +3 -0
  16. package/esm/constants/index.js +15 -0
  17. package/esm/services/ethereumService.test.js +1 -0
  18. package/esm/services/strategiesService.js +30 -0
  19. package/esm/services/strategiesService.test.js +1 -0
  20. package/esm/services/strategySubService.d.ts +3 -0
  21. package/esm/services/strategySubService.js +24 -0
  22. package/esm/services/strategySubService.test.js +40 -2
  23. package/esm/services/subDataService.d.ts +26 -0
  24. package/esm/services/subDataService.js +57 -0
  25. package/esm/services/subDataService.test.js +62 -10
  26. package/esm/services/triggerService.d.ts +10 -0
  27. package/esm/services/triggerService.js +20 -0
  28. package/esm/services/triggerService.test.js +49 -1
  29. package/esm/types/enums.d.ts +6 -3
  30. package/esm/types/enums.js +3 -0
  31. package/package.json +2 -2
  32. package/src/constants/index.ts +15 -0
  33. package/src/services/ethereumService.test.ts +1 -0
  34. package/src/services/strategiesService.test.ts +1 -0
  35. package/src/services/strategiesService.ts +43 -0
  36. package/src/services/strategySubService.test.ts +57 -2
  37. package/src/services/strategySubService.ts +64 -2
  38. package/src/services/subDataService.test.ts +73 -14
  39. package/src/services/subDataService.ts +79 -0
  40. package/src/services/triggerService.test.ts +53 -0
  41. package/src/services/triggerService.ts +32 -0
  42. package/src/types/enums.ts +3 -0
@@ -206,7 +206,8 @@ export declare namespace Bundles {
206
206
  AAVE_V3_EOA_REPAY_ON_PRICE = 54,
207
207
  AAVE_V3_EOA_BOOST_ON_PRICE = 55,
208
208
  AAVE_V3_EOA_CLOSE = 56,
209
- SPARK_CLOSE = 57
209
+ SPARK_CLOSE = 57,
210
+ MORPHO_BLUE_CLOSE = 58
210
211
  }
211
212
  enum OptimismIds {
212
213
  AAVE_V3_REPAY = 0,
@@ -247,7 +248,8 @@ export declare namespace Bundles {
247
248
  AAVE_V3_EOA_BOOST = 24,
248
249
  AAVE_V3_EOA_REPAY_ON_PRICE = 25,
249
250
  AAVE_V3_EOA_BOOST_ON_PRICE = 26,
250
- AAVE_V3_EOA_CLOSE = 27
251
+ AAVE_V3_EOA_CLOSE = 27,
252
+ MORPHO_BLUE_CLOSE = 28
251
253
  }
252
254
  enum ArbitrumIds {
253
255
  AAVE_V3_REPAY = 0,
@@ -277,6 +279,7 @@ export declare namespace Bundles {
277
279
  MORPHO_BLUE_BOOST = 24,
278
280
  MORPHO_BLUE_BOOST_ON_PRICE = 25,
279
281
  MORPHO_BLUE_EOA_REPAY = 26,
280
- MORPHO_BLUE_EOA_BOOST = 27
282
+ MORPHO_BLUE_EOA_BOOST = 27,
283
+ MORPHO_BLUE_CLOSE = 28
281
284
  }
282
285
  }
@@ -230,6 +230,7 @@ var Bundles;
230
230
  MainnetIds[MainnetIds["AAVE_V3_EOA_BOOST_ON_PRICE"] = 55] = "AAVE_V3_EOA_BOOST_ON_PRICE";
231
231
  MainnetIds[MainnetIds["AAVE_V3_EOA_CLOSE"] = 56] = "AAVE_V3_EOA_CLOSE";
232
232
  MainnetIds[MainnetIds["SPARK_CLOSE"] = 57] = "SPARK_CLOSE";
233
+ MainnetIds[MainnetIds["MORPHO_BLUE_CLOSE"] = 58] = "MORPHO_BLUE_CLOSE";
233
234
  })(MainnetIds = Bundles.MainnetIds || (Bundles.MainnetIds = {}));
234
235
  let OptimismIds;
235
236
  (function (OptimismIds) {
@@ -273,6 +274,7 @@ var Bundles;
273
274
  BaseIds[BaseIds["AAVE_V3_EOA_REPAY_ON_PRICE"] = 25] = "AAVE_V3_EOA_REPAY_ON_PRICE";
274
275
  BaseIds[BaseIds["AAVE_V3_EOA_BOOST_ON_PRICE"] = 26] = "AAVE_V3_EOA_BOOST_ON_PRICE";
275
276
  BaseIds[BaseIds["AAVE_V3_EOA_CLOSE"] = 27] = "AAVE_V3_EOA_CLOSE";
277
+ BaseIds[BaseIds["MORPHO_BLUE_CLOSE"] = 28] = "MORPHO_BLUE_CLOSE";
276
278
  })(BaseIds = Bundles.BaseIds || (Bundles.BaseIds = {}));
277
279
  let ArbitrumIds;
278
280
  (function (ArbitrumIds) {
@@ -304,5 +306,6 @@ var Bundles;
304
306
  ArbitrumIds[ArbitrumIds["MORPHO_BLUE_BOOST_ON_PRICE"] = 25] = "MORPHO_BLUE_BOOST_ON_PRICE";
305
307
  ArbitrumIds[ArbitrumIds["MORPHO_BLUE_EOA_REPAY"] = 26] = "MORPHO_BLUE_EOA_REPAY";
306
308
  ArbitrumIds[ArbitrumIds["MORPHO_BLUE_EOA_BOOST"] = 27] = "MORPHO_BLUE_EOA_BOOST";
309
+ ArbitrumIds[ArbitrumIds["MORPHO_BLUE_CLOSE"] = 28] = "MORPHO_BLUE_CLOSE";
307
310
  })(ArbitrumIds = Bundles.ArbitrumIds || (Bundles.ArbitrumIds = {}));
308
311
  })(Bundles = exports.Bundles || (exports.Bundles = {}));
@@ -462,6 +462,11 @@ export const MAINNET_BUNDLES_INFO = {
462
462
  strategyId: Strategies.Identifiers.CloseOnPrice,
463
463
  protocol: PROTOCOLS.Spark,
464
464
  },
465
+ [Bundles.MainnetIds.MORPHO_BLUE_CLOSE]: {
466
+ strategyOrBundleId: Bundles.MainnetIds.MORPHO_BLUE_CLOSE,
467
+ strategyId: Strategies.Identifiers.CloseOnPrice,
468
+ protocol: PROTOCOLS.MorphoBlue,
469
+ },
465
470
  };
466
471
  export const OPTIMISM_BUNDLES_INFO = {
467
472
  [Bundles.OptimismIds.AAVE_V3_REPAY]: {
@@ -651,6 +656,11 @@ export const BASE_BUNDLES_INFO = {
651
656
  strategyId: Strategies.Identifiers.EoaCloseOnPrice,
652
657
  protocol: PROTOCOLS.AaveV3,
653
658
  },
659
+ [Bundles.BaseIds.MORPHO_BLUE_CLOSE]: {
660
+ strategyOrBundleId: Bundles.BaseIds.MORPHO_BLUE_CLOSE,
661
+ strategyId: Strategies.Identifiers.CloseOnPrice,
662
+ protocol: PROTOCOLS.MorphoBlue,
663
+ },
654
664
  };
655
665
  export const ARBITRUM_BUNDLES_INFO = {
656
666
  [Bundles.ArbitrumIds.AAVE_V3_REPAY]: {
@@ -793,6 +803,11 @@ export const ARBITRUM_BUNDLES_INFO = {
793
803
  strategyId: Strategies.Identifiers.EoaBoost,
794
804
  protocol: PROTOCOLS.MorphoBlue,
795
805
  },
806
+ [Bundles.ArbitrumIds.MORPHO_BLUE_CLOSE]: {
807
+ strategyOrBundleId: Bundles.ArbitrumIds.MORPHO_BLUE_CLOSE,
808
+ strategyId: Strategies.Identifiers.CloseOnPrice,
809
+ protocol: PROTOCOLS.MorphoBlue,
810
+ },
796
811
  };
797
812
  export const BUNDLES_INFO = {
798
813
  [ChainId.Ethereum]: MAINNET_BUNDLES_INFO,
@@ -96,6 +96,7 @@ describe('Feature: ethereumService.ts', () => {
96
96
  'address': '0x5f98805A4E8be255a32880FDeC7F6728C6568bA0',
97
97
  'blockHash': '0xb92cab2569456dbfbdb853d2c67d72c9a7580543dbcb55d483a77322b40755a4',
98
98
  'blockNumber': 15166163,
99
+ 'blockTimestamp': '0x62d53ad8',
99
100
  'event': 'Transfer',
100
101
  'id': 'log_e2258e3a',
101
102
  'logIndex': 385,
@@ -741,6 +741,35 @@ function parseMorphoBlueLeverageManagementOnPrice(position, parseData) {
741
741
  };
742
742
  return _position;
743
743
  }
744
+ function parseMorphoBlueCloseOnPrice(position, parseData) {
745
+ const _position = cloneDeep(position);
746
+ const { subStruct } = parseData.subscriptionEventData;
747
+ const triggerData = triggerService.morphoBluePriceRangeTrigger.decode(subStruct.triggerData);
748
+ const subData = subDataService.morphoBlueCloseOnPriceSubData.decode(subStruct.subData);
749
+ _position.strategyData.decoded.triggerData = triggerData;
750
+ _position.strategyData.decoded.subData = subData;
751
+ _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, Math.random());
752
+ const marketIdEncodedData = web3.eth.abi.encodeParameters(['address', 'address', 'address', 'address', 'uint256'], [
753
+ subData.loanToken,
754
+ subData.collToken,
755
+ subData.oracle,
756
+ subData.irm,
757
+ subData.lltv,
758
+ ]);
759
+ const marketId = web3.utils.keccak256(marketIdEncodedData);
760
+ const { takeProfitType, stopLossType } = getStopLossAndTakeProfitTypeByCloseStrategyType(+subData.closeType);
761
+ _position.specific = {
762
+ subHash: _position.subHash,
763
+ marketId,
764
+ collAsset: subData.collToken,
765
+ debtAsset: subData.loanToken,
766
+ stopLossPrice: triggerData.lowerPrice,
767
+ takeProfitPrice: triggerData.upperPrice,
768
+ stopLossType,
769
+ takeProfitType,
770
+ };
771
+ return _position;
772
+ }
744
773
  function parseLiquityV2CloseOnPrice(position, parseData) {
745
774
  const _position = cloneDeep(position);
746
775
  const { subStruct } = parseData.subscriptionEventData;
@@ -928,6 +957,7 @@ const parsingMethodsMapping = {
928
957
  [Strategies.Identifiers.EoaRepay]: parseMorphoBlueLeverageManagement,
929
958
  [Strategies.Identifiers.EoaBoost]: parseMorphoBlueLeverageManagement,
930
959
  [Strategies.Identifiers.BoostOnPrice]: parseMorphoBlueLeverageManagementOnPrice,
960
+ [Strategies.Identifiers.CloseOnPrice]: parseMorphoBlueCloseOnPrice,
931
961
  },
932
962
  [ProtocolIdentifiers.StrategiesAutomation.FluidT1]: {
933
963
  [Strategies.Identifiers.Repay]: parseFluidT1LeverageManagement,
@@ -71,6 +71,7 @@ describe('Feature: strategiesService.ts', () => {
71
71
  repayEnabled: true,
72
72
  subId1: 379,
73
73
  mergeWithId: Strategies.Identifiers.Boost,
74
+ subHashRepay: '0xafa4d200be62f171b57b1ae0f4e8348d1ac3f6d0812ad6da74a2adae8037dde1',
74
75
  }
75
76
  },
76
77
  {
@@ -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): (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)[];
@@ -94,6 +96,7 @@ export declare const crvUSDEncode: {
94
96
  export declare const morphoBlueEncode: {
95
97
  leverageManagement(marketId: string, loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, ratioState: RatioState, targetRatio: number, triggerRatio: number, user: EthereumAddress, isEOA: boolean, network: ChainId): (boolean | string[] | Bundles.BaseIds)[] | (boolean | string[] | Bundles.MainnetIds | Bundles.ArbitrumIds)[];
96
98
  leverageManagementOnPrice(strategyOrBundleId: number, isBundle: boolean | undefined, loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, user: EthereumAddress, targetRatio: number, price: number, priceState: RatioState): (number | boolean | string[])[];
99
+ closeOnPrice(strategyOrBundleId: number, loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, user: EthereumAddress, stopLossPrice?: number, stopLossType?: CloseToAssetType, takeProfitPrice?: number, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
97
100
  };
98
101
  export declare const liquityV2Encode: {
99
102
  leverageManagement(market: EthereumAddress, troveId: string, collToken: EthereumAddress, boldToken: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, strategyOrBundleId: number): (number | boolean | string[])[];
@@ -41,6 +41,17 @@ export const makerEncode = {
41
41
  boostEnabled,
42
42
  ];
43
43
  },
44
+ leverageManagementWithoutSubProxy(vaultId, triggerRatio, targetRatio, ratioState, isBoost) {
45
+ const bundleId = isBoost ? Bundles.MainnetIds.MAKER_BOOST : Bundles.MainnetIds.MAKER_REPAY;
46
+ const triggerData = triggerService.makerRatioTrigger.encode(vaultId, triggerRatio, ratioState);
47
+ const subData = subDataService.makerLeverageManagementWithoutSubProxy.encode(vaultId, targetRatio, ratioState);
48
+ return [
49
+ bundleId,
50
+ true,
51
+ triggerData,
52
+ subData,
53
+ ];
54
+ },
44
55
  };
45
56
  export const liquityEncode = {
46
57
  closeOnPrice(priceOverOrUnder, price, closeToAssetAddr, chainlinkCollAddress, chainId = ChainId.Ethereum, collAddr, debtAddr) {
@@ -239,6 +250,12 @@ export const sparkEncode = {
239
250
  const triggerDataEncoded = triggerService.sparkQuotePriceRangeTrigger.encode(collAsset, debtAsset, stopLossPrice, takeProfitPrice);
240
251
  return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
241
252
  },
253
+ leverageManagementWithoutSubProxy(strategyOrBundleId, market, user, ratioState, targetRatio, triggerRatio) {
254
+ const isBundle = true;
255
+ const subData = subDataService.sparkLeverageManagementSubDataWithoutSubProxy.encode(targetRatio, ratioState);
256
+ const triggerData = triggerService.sparkRatioTrigger.encode(user, market, triggerRatio, ratioState);
257
+ return [strategyOrBundleId, isBundle, triggerData, subData];
258
+ },
242
259
  };
243
260
  export const crvUSDEncode = {
244
261
  leverageManagement(owner, controllerAddr, ratioState, targetRatio, triggerRatio, collTokenAddr, crvUSDAddr) {
@@ -280,6 +297,13 @@ export const morphoBlueEncode = {
280
297
  const triggerData = triggerService.morphoBluePriceTrigger.encode(oracle, collToken, loanToken, price, priceState);
281
298
  return [strategyOrBundleId, isBundle, triggerData, subData];
282
299
  },
300
+ closeOnPrice(strategyOrBundleId, loanToken, collToken, oracle, irm, lltv, user, stopLossPrice = 0, stopLossType = CloseToAssetType.DEBT, takeProfitPrice = 0, takeProfitType = CloseToAssetType.COLLATERAL) {
301
+ const isBundle = true;
302
+ const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
303
+ const subDataEncoded = subDataService.morphoBlueCloseOnPriceSubData.encode(loanToken, collToken, oracle, irm, lltv, user, closeType);
304
+ const triggerDataEncoded = triggerService.morphoBluePriceRangeTrigger.encode(oracle, collToken, loanToken, stopLossPrice, takeProfitPrice);
305
+ return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
306
+ },
283
307
  };
284
308
  export const liquityV2Encode = {
285
309
  leverageManagement(market, troveId, collToken, boldToken, ratioState, targetRatio, triggerRatio, strategyOrBundleId) {
@@ -472,7 +472,7 @@ describe('Feature: strategySubService.ts', () => {
472
472
  [
473
473
  Bundles.MainnetIds.AAVE_V3_EOA_REPAY_ON_PRICE,
474
474
  true,
475
- ['0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000026e1f9c6000000000000000000000000000000000000000000000000000000000000000001'],
475
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000026e1f9c6000000000000000000000000000000000000000000000000000000000000000001'],
476
476
  [
477
477
  '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
478
478
  '0x0000000000000000000000000000000000000000000000000000000000000000',
@@ -500,7 +500,7 @@ describe('Feature: strategySubService.ts', () => {
500
500
  [
501
501
  Bundles.MainnetIds.AAVE_V3_EOA_BOOST_ON_PRICE,
502
502
  true,
503
- ['0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000002faf0800000000000000000000000000000000000000000000000000000000000000000'],
503
+ ['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000002faf0800000000000000000000000000000000000000000000000000000000000000000'],
504
504
  [
505
505
  '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
506
506
  '0x0000000000000000000000000000000000000000000000000000000000000002',
@@ -1336,6 +1336,44 @@ describe('Feature: strategySubService.ts', () => {
1336
1336
  });
1337
1337
  });
1338
1338
  });
1339
+ describe('closeOnPrice()', () => {
1340
+ const examples = [
1341
+ [
1342
+ [
1343
+ Bundles.MainnetIds.MORPHO_BLUE_CLOSE,
1344
+ true,
1345
+ ['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
1346
+ [
1347
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1348
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1349
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1350
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1351
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1352
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1353
+ '0x0000000000000000000000000000000000000000000000000000000000000005',
1354
+ ],
1355
+ ],
1356
+ [
1357
+ Bundles.MainnetIds.MORPHO_BLUE_CLOSE,
1358
+ web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
1359
+ web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
1360
+ web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
1361
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1362
+ '945000000000000000',
1363
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1364
+ 1500,
1365
+ CloseToAssetType.DEBT,
1366
+ 4000,
1367
+ CloseToAssetType.COLLATERAL
1368
+ ]
1369
+ ],
1370
+ ];
1371
+ examples.forEach(([expected, actual]) => {
1372
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1373
+ expect(morphoBlueEncode.closeOnPrice(...actual)).to.eql(expected);
1374
+ });
1375
+ });
1376
+ });
1339
1377
  });
1340
1378
  describe('When testing strategySubService.compoundV3L2Encode', () => {
1341
1379
  describe('leverageManagement()', () => {
@@ -28,6 +28,13 @@ export declare const makerLeverageManagementSubData: {
28
28
  targetRatio: number;
29
29
  };
30
30
  };
31
+ export declare const makerLeverageManagementWithoutSubProxy: {
32
+ encode(cdpId: number, targetRatio: number, ratioState: RatioState): string[];
33
+ decode(subData: string[]): {
34
+ targetRatio: number;
35
+ ratioState: RatioState;
36
+ };
37
+ };
31
38
  export declare const liquityLeverageManagementSubData: {
32
39
  decode: (subData: string[]) => {
33
40
  targetRatio: number;
@@ -166,6 +173,13 @@ export declare const sparkLeverageManagementSubData: {
166
173
  targetRatio: number;
167
174
  };
168
175
  };
176
+ export declare const sparkLeverageManagementSubDataWithoutSubProxy: {
177
+ encode(targetRatio: number, ratioState: RatioState): string[];
178
+ decode(subData: string[]): {
179
+ targetRatio: number;
180
+ ratioState: RatioState;
181
+ };
182
+ };
169
183
  export declare const liquityDsrPaybackSubData: {
170
184
  encode: (targetRatio: number) => string[];
171
185
  decode: (subData: string[]) => {
@@ -318,3 +332,15 @@ export declare const sparkCloseGenericSubData: {
318
332
  owner: EthereumAddress;
319
333
  };
320
334
  };
335
+ export declare const morphoBlueCloseOnPriceSubData: {
336
+ encode(loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, user: EthereumAddress, closeType: CloseStrategyType): string[];
337
+ decode(subData: string[]): {
338
+ loanToken: string;
339
+ collToken: string;
340
+ oracle: string;
341
+ irm: string;
342
+ lltv: string;
343
+ user: string;
344
+ closeType: CloseStrategyType;
345
+ };
346
+ };
@@ -70,6 +70,19 @@ export const makerLeverageManagementSubData = {
70
70
  return { vaultId, targetRatio };
71
71
  },
72
72
  };
73
+ export const makerLeverageManagementWithoutSubProxy = {
74
+ encode(cdpId, targetRatio, ratioState) {
75
+ const encodedCdpId = AbiCoder.encodeParameter('uint256', cdpId);
76
+ const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
77
+ const encodedRatioState = AbiCoder.encodeParameter('uint8', ratioState);
78
+ return [encodedTargetRatio, encodedRatioState, encodedCdpId];
79
+ },
80
+ decode(subData) {
81
+ const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[0]));
82
+ const ratioState = AbiCoder.decodeParameter('uint8', subData[1]);
83
+ return { targetRatio, ratioState };
84
+ },
85
+ };
73
86
  export const liquityLeverageManagementSubData = {
74
87
  decode: (subData) => {
75
88
  const weiRatio = AbiCoder.decodeParameter('uint256', subData[1]);
@@ -411,6 +424,20 @@ export const sparkLeverageManagementSubData = {
411
424
  return { targetRatio };
412
425
  },
413
426
  };
427
+ export const sparkLeverageManagementSubDataWithoutSubProxy = {
428
+ encode(targetRatio, ratioState) {
429
+ const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
430
+ const encodedRatioState = AbiCoder.encodeParameter('uint8', ratioState);
431
+ const encodedUseDefaultMarket = AbiCoder.encodeParameter('bool', true);
432
+ const encodedUseOnBehalf = AbiCoder.encodeParameter('bool', false);
433
+ return [encodedTargetRatio, encodedRatioState, encodedUseDefaultMarket, encodedUseOnBehalf];
434
+ },
435
+ decode(subData) {
436
+ const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[0]));
437
+ const ratioState = AbiCoder.decodeParameter('uint8', subData[1]);
438
+ return { targetRatio, ratioState };
439
+ },
440
+ };
414
441
  export const liquityDsrPaybackSubData = {
415
442
  encode: (targetRatio) => {
416
443
  const daiAddress = getAssetInfo('DAI').address;
@@ -852,3 +879,33 @@ export const sparkCloseGenericSubData = {
852
879
  };
853
880
  },
854
881
  };
882
+ export const morphoBlueCloseOnPriceSubData = {
883
+ encode(loanToken, collToken, oracle, irm, lltv, user, closeType) {
884
+ const loanTokenEncoded = AbiCoder.encodeParameter('address', loanToken);
885
+ const collTokenEncoded = AbiCoder.encodeParameter('address', collToken);
886
+ const oracleEncoded = AbiCoder.encodeParameter('address', oracle);
887
+ const irmEncoded = AbiCoder.encodeParameter('address', irm);
888
+ const lltvEncoded = AbiCoder.encodeParameter('uint256', lltv);
889
+ const userEncoded = AbiCoder.encodeParameter('address', user);
890
+ const closeTypeEncoded = AbiCoder.encodeParameter('uint8', closeType);
891
+ return [loanTokenEncoded, collTokenEncoded, oracleEncoded, irmEncoded, lltvEncoded, userEncoded, closeTypeEncoded];
892
+ },
893
+ decode(subData) {
894
+ const loanToken = AbiCoder.decodeParameter('address', subData[0]);
895
+ const collToken = AbiCoder.decodeParameter('address', subData[1]);
896
+ const oracle = AbiCoder.decodeParameter('address', subData[2]);
897
+ const irm = AbiCoder.decodeParameter('address', subData[3]);
898
+ const lltv = AbiCoder.decodeParameter('uint256', subData[4]);
899
+ const user = AbiCoder.decodeParameter('address', subData[5]);
900
+ const closeType = Number(AbiCoder.decodeParameter('uint8', subData[6]));
901
+ return {
902
+ loanToken,
903
+ collToken,
904
+ oracle,
905
+ irm,
906
+ lltv,
907
+ user,
908
+ closeType,
909
+ };
910
+ },
911
+ };
@@ -1264,6 +1264,58 @@ describe('Feature: subDataService.ts', () => {
1264
1264
  });
1265
1265
  });
1266
1266
  });
1267
+ describe('When testing subDataService.morphoBlueCloseOnPriceSubData', () => {
1268
+ describe('encode()', () => {
1269
+ const examples = [
1270
+ [
1271
+ [
1272
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1273
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1274
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1275
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1276
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1277
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1278
+ '0x0000000000000000000000000000000000000000000000000000000000000006',
1279
+ ],
1280
+ [web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'), '945000000000000000', web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT]
1281
+ ],
1282
+ ];
1283
+ examples.forEach(([expected, actual]) => {
1284
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1285
+ expect(subDataService.morphoBlueCloseOnPriceSubData.encode(...actual)).to.eql(expected);
1286
+ });
1287
+ });
1288
+ });
1289
+ describe('decode()', () => {
1290
+ const examples = [
1291
+ [
1292
+ {
1293
+ loanToken: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
1294
+ collToken: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0',
1295
+ oracle: '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
1296
+ irm: '0x0000000000000000000000000000000000000000',
1297
+ lltv: '945000000000000000',
1298
+ user: '0x1031d218133AFaB8C2B819B1366c7e434Ad91e9c',
1299
+ closeType: CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT,
1300
+ },
1301
+ [
1302
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1303
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1304
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1305
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1306
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1307
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1308
+ '0x0000000000000000000000000000000000000000000000000000000000000006',
1309
+ ],
1310
+ ],
1311
+ ];
1312
+ examples.forEach(([expected, actual]) => {
1313
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1314
+ expect(subDataService.morphoBlueCloseOnPriceSubData.decode(actual)).to.eql(expected);
1315
+ });
1316
+ });
1317
+ });
1318
+ });
1267
1319
  describe('When testing subDataService.aaveV3LeverageManagementOnPriceSubData', () => {
1268
1320
  describe('encode()', () => {
1269
1321
  const examples = [
@@ -1557,7 +1609,7 @@ describe('Feature: subDataService.ts', () => {
1557
1609
  debtAssetId: 1,
1558
1610
  marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1559
1611
  targetRatio: 200,
1560
- user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1612
+ owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1561
1613
  },
1562
1614
  [
1563
1615
  '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
@@ -1577,7 +1629,7 @@ describe('Feature: subDataService.ts', () => {
1577
1629
  debtAssetId: 1,
1578
1630
  marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1579
1631
  targetRatio: 200,
1580
- user: web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
1632
+ owner: web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
1581
1633
  },
1582
1634
  [
1583
1635
  '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
@@ -1786,7 +1838,7 @@ describe('Feature: subDataService.ts', () => {
1786
1838
  debtAssetId: 1,
1787
1839
  closeType: CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL,
1788
1840
  marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1789
- user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1841
+ owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1790
1842
  },
1791
1843
  [
1792
1844
  '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
@@ -1807,7 +1859,7 @@ describe('Feature: subDataService.ts', () => {
1807
1859
  debtAssetId: 1,
1808
1860
  closeType: CloseStrategyType.STOP_LOSS_IN_COLLATERAL,
1809
1861
  marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1810
- user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1862
+ owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1811
1863
  },
1812
1864
  [
1813
1865
  '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
@@ -1828,7 +1880,7 @@ describe('Feature: subDataService.ts', () => {
1828
1880
  debtAssetId: 1,
1829
1881
  closeType: CloseStrategyType.TAKE_PROFIT_IN_DEBT,
1830
1882
  marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1831
- user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1883
+ owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1832
1884
  },
1833
1885
  [
1834
1886
  '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
@@ -1849,7 +1901,7 @@ describe('Feature: subDataService.ts', () => {
1849
1901
  debtAssetId: 1,
1850
1902
  closeType: CloseStrategyType.STOP_LOSS_IN_DEBT,
1851
1903
  marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1852
- user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1904
+ owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1853
1905
  },
1854
1906
  [
1855
1907
  '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
@@ -1870,7 +1922,7 @@ describe('Feature: subDataService.ts', () => {
1870
1922
  debtAssetId: 1,
1871
1923
  closeType: CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL,
1872
1924
  marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1873
- user: web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
1925
+ owner: web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
1874
1926
  },
1875
1927
  [
1876
1928
  '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
@@ -1891,7 +1943,7 @@ describe('Feature: subDataService.ts', () => {
1891
1943
  debtAssetId: 1,
1892
1944
  closeType: CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT,
1893
1945
  marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1894
- user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1946
+ owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1895
1947
  },
1896
1948
  [
1897
1949
  '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
@@ -1912,7 +1964,7 @@ describe('Feature: subDataService.ts', () => {
1912
1964
  debtAssetId: 1,
1913
1965
  closeType: CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT,
1914
1966
  marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1915
- user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1967
+ owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1916
1968
  },
1917
1969
  [
1918
1970
  '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
@@ -1933,7 +1985,7 @@ describe('Feature: subDataService.ts', () => {
1933
1985
  debtAssetId: 1,
1934
1986
  closeType: CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL,
1935
1987
  marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1936
- user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1988
+ owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1937
1989
  },
1938
1990
  [
1939
1991
  '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
@@ -275,3 +275,13 @@ export declare const sparkQuotePriceRangeTrigger: {
275
275
  upperPrice: string;
276
276
  };
277
277
  };
278
+ export declare const morphoBluePriceRangeTrigger: {
279
+ encode(oracle: EthereumAddress, collateralToken: EthereumAddress, loanToken: EthereumAddress, lowerPrice: number, upperPrice: number): string[];
280
+ decode(triggerData: string[]): {
281
+ oracle: string;
282
+ collateralToken: string;
283
+ loanToken: string;
284
+ lowerPrice: string;
285
+ upperPrice: string;
286
+ };
287
+ };
@@ -498,3 +498,23 @@ export const sparkQuotePriceRangeTrigger = {
498
498
  };
499
499
  },
500
500
  };
501
+ export const morphoBluePriceRangeTrigger = {
502
+ encode(oracle, collateralToken, loanToken, lowerPrice, upperPrice) {
503
+ // Price is scaled to 1e8
504
+ const lowerPriceFormatted = new Dec(lowerPrice).mul(1e8).floor().toString();
505
+ const upperPriceFormatted = new Dec(upperPrice).mul(1e8).floor().toString();
506
+ return [
507
+ AbiCoder.encodeParameters(['address', 'address', 'address', 'uint256', 'uint256'], [oracle, collateralToken, loanToken, lowerPriceFormatted, upperPriceFormatted]),
508
+ ];
509
+ },
510
+ decode(triggerData) {
511
+ const decodedData = AbiCoder.decodeParameters(['address', 'address', 'address', 'uint256', 'uint256'], triggerData[0]);
512
+ return {
513
+ oracle: decodedData[0],
514
+ collateralToken: decodedData[1],
515
+ loanToken: decodedData[2],
516
+ lowerPrice: new Dec(decodedData[3]).div(1e8).toString(),
517
+ upperPrice: new Dec(decodedData[4]).div(1e8).toString(),
518
+ };
519
+ },
520
+ };