@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
@@ -3,7 +3,7 @@ import { getAssetInfo, MAXUINT } from '@defisaver/tokens';
3
3
  import * as web3Utils from 'web3-utils';
4
4
  import { ChainId, OrderType, RatioState } from '../types/enums';
5
5
  import '../configuration';
6
- import { aaveV2RatioTrigger, aaveV3QuotePriceTrigger, aaveV3QuotePriceWithMaximumGasPriceTrigger, aaveV3RatioTrigger, cBondsRebondTrigger, chainlinkPriceTrigger, compoundV2RatioTrigger, compoundV3RatioTrigger, compoundV3PriceTrigger, curveUsdBorrowRateTrigger, curveUsdSoftLiquidationTrigger, exchangeOffchainPriceTrigger, exchangeTimestampTrigger, liquityDebtInFrontTrigger, makerRatioTrigger, morphoAaveV2RatioTrigger, sparkRatioTrigger, trailingStopTrigger, liquityDebtInFrontWithLimitTrigger, crvUSDRatioTrigger, morphoBlueRatioTrigger, crvUsdHealthRatioTrigger, liquityV2DebtInFrontTrigger, liquityV2AdjustTimeTrigger, compoundV3PriceRangeTrigger, aaveV3QuotePriceRangeTrigger, } from './triggerService';
6
+ import { aaveV2RatioTrigger, aaveV3QuotePriceTrigger, aaveV3QuotePriceWithMaximumGasPriceTrigger, aaveV3RatioTrigger, cBondsRebondTrigger, chainlinkPriceTrigger, compoundV2RatioTrigger, compoundV3RatioTrigger, compoundV3PriceTrigger, curveUsdBorrowRateTrigger, curveUsdSoftLiquidationTrigger, exchangeOffchainPriceTrigger, exchangeTimestampTrigger, liquityDebtInFrontTrigger, makerRatioTrigger, morphoAaveV2RatioTrigger, sparkRatioTrigger, trailingStopTrigger, liquityDebtInFrontWithLimitTrigger, crvUSDRatioTrigger, morphoBlueRatioTrigger, crvUsdHealthRatioTrigger, liquityV2DebtInFrontTrigger, liquityV2AdjustTimeTrigger, compoundV3PriceRangeTrigger, aaveV3QuotePriceRangeTrigger, morphoBluePriceRangeTrigger, } from './triggerService';
7
7
  describe('Feature: triggerService.ts', () => {
8
8
  describe('When testing triggerService.chainlinkPriceTrigger', () => {
9
9
  describe('encode()', () => {
@@ -1111,4 +1111,52 @@ describe('Feature: triggerService.ts', () => {
1111
1111
  });
1112
1112
  });
1113
1113
  });
1114
+ describe('When testing triggerService.morphoBluePriceRangeTrigger', () => {
1115
+ describe('encode()', () => {
1116
+ const examples = [
1117
+ [
1118
+ ['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
1119
+ [web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 1500, 4000]
1120
+ ],
1121
+ [
1122
+ ['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
1123
+ [web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 0, 5000]
1124
+ ],
1125
+ ];
1126
+ examples.forEach(([expected, actual]) => {
1127
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1128
+ expect(morphoBluePriceRangeTrigger.encode(...actual)).to.eql(expected);
1129
+ });
1130
+ });
1131
+ });
1132
+ describe('decode()', () => {
1133
+ const examples = [
1134
+ [
1135
+ {
1136
+ oracle: web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
1137
+ collateralToken: web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
1138
+ loanToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1139
+ lowerPrice: '1500',
1140
+ upperPrice: '4000',
1141
+ },
1142
+ ['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
1143
+ ],
1144
+ [
1145
+ {
1146
+ oracle: web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
1147
+ collateralToken: web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
1148
+ loanToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1149
+ lowerPrice: '0',
1150
+ upperPrice: '5000',
1151
+ },
1152
+ ['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8dA6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
1153
+ ],
1154
+ ];
1155
+ examples.forEach(([expected, actual]) => {
1156
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1157
+ expect(morphoBluePriceRangeTrigger.decode(actual)).to.eql(expected);
1158
+ });
1159
+ });
1160
+ });
1161
+ });
1114
1162
  });
@@ -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
  }
@@ -227,6 +227,7 @@ export var Bundles;
227
227
  MainnetIds[MainnetIds["AAVE_V3_EOA_BOOST_ON_PRICE"] = 55] = "AAVE_V3_EOA_BOOST_ON_PRICE";
228
228
  MainnetIds[MainnetIds["AAVE_V3_EOA_CLOSE"] = 56] = "AAVE_V3_EOA_CLOSE";
229
229
  MainnetIds[MainnetIds["SPARK_CLOSE"] = 57] = "SPARK_CLOSE";
230
+ MainnetIds[MainnetIds["MORPHO_BLUE_CLOSE"] = 58] = "MORPHO_BLUE_CLOSE";
230
231
  })(MainnetIds = Bundles.MainnetIds || (Bundles.MainnetIds = {}));
231
232
  let OptimismIds;
232
233
  (function (OptimismIds) {
@@ -270,6 +271,7 @@ export var Bundles;
270
271
  BaseIds[BaseIds["AAVE_V3_EOA_REPAY_ON_PRICE"] = 25] = "AAVE_V3_EOA_REPAY_ON_PRICE";
271
272
  BaseIds[BaseIds["AAVE_V3_EOA_BOOST_ON_PRICE"] = 26] = "AAVE_V3_EOA_BOOST_ON_PRICE";
272
273
  BaseIds[BaseIds["AAVE_V3_EOA_CLOSE"] = 27] = "AAVE_V3_EOA_CLOSE";
274
+ BaseIds[BaseIds["MORPHO_BLUE_CLOSE"] = 28] = "MORPHO_BLUE_CLOSE";
273
275
  })(BaseIds = Bundles.BaseIds || (Bundles.BaseIds = {}));
274
276
  let ArbitrumIds;
275
277
  (function (ArbitrumIds) {
@@ -301,5 +303,6 @@ export var Bundles;
301
303
  ArbitrumIds[ArbitrumIds["MORPHO_BLUE_BOOST_ON_PRICE"] = 25] = "MORPHO_BLUE_BOOST_ON_PRICE";
302
304
  ArbitrumIds[ArbitrumIds["MORPHO_BLUE_EOA_REPAY"] = 26] = "MORPHO_BLUE_EOA_REPAY";
303
305
  ArbitrumIds[ArbitrumIds["MORPHO_BLUE_EOA_BOOST"] = 27] = "MORPHO_BLUE_EOA_BOOST";
306
+ ArbitrumIds[ArbitrumIds["MORPHO_BLUE_CLOSE"] = 28] = "MORPHO_BLUE_CLOSE";
304
307
  })(ArbitrumIds = Bundles.ArbitrumIds || (Bundles.ArbitrumIds = {}));
305
308
  })(Bundles || (Bundles = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/automation-sdk",
3
- "version": "3.3.7",
3
+ "version": "3.3.8-lev-management-dev",
4
4
  "description": "",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -23,7 +23,7 @@
23
23
  "repository": "https://github.com/defisaver/automation-sdk",
24
24
  "license": "ISC",
25
25
  "dependencies": {
26
- "@defisaver/sdk": "^1.3.11",
26
+ "@defisaver/sdk": "^1.3.15",
27
27
  "@defisaver/tokens": "^1.6.19",
28
28
  "@ethersproject/address": "^5.0.10",
29
29
  "@ethersproject/solidity": "^5.0.9",
@@ -491,6 +491,11 @@ export const MAINNET_BUNDLES_INFO: MainnetBundleInfo = {
491
491
  strategyId: Strategies.Identifiers.CloseOnPrice,
492
492
  protocol: PROTOCOLS.Spark,
493
493
  },
494
+ [Bundles.MainnetIds.MORPHO_BLUE_CLOSE]: {
495
+ strategyOrBundleId: Bundles.MainnetIds.MORPHO_BLUE_CLOSE,
496
+ strategyId: Strategies.Identifiers.CloseOnPrice,
497
+ protocol: PROTOCOLS.MorphoBlue,
498
+ },
494
499
  };
495
500
 
496
501
  export const OPTIMISM_BUNDLES_INFO: OptimismBundleInfo = {
@@ -683,6 +688,11 @@ export const BASE_BUNDLES_INFO: BaseBundleInfo = {
683
688
  strategyId: Strategies.Identifiers.EoaCloseOnPrice,
684
689
  protocol: PROTOCOLS.AaveV3,
685
690
  },
691
+ [Bundles.BaseIds.MORPHO_BLUE_CLOSE]: {
692
+ strategyOrBundleId: Bundles.BaseIds.MORPHO_BLUE_CLOSE,
693
+ strategyId: Strategies.Identifiers.CloseOnPrice,
694
+ protocol: PROTOCOLS.MorphoBlue,
695
+ },
686
696
  };
687
697
 
688
698
  export const ARBITRUM_BUNDLES_INFO: ArbitrumBundleInfo = {
@@ -826,6 +836,11 @@ export const ARBITRUM_BUNDLES_INFO: ArbitrumBundleInfo = {
826
836
  strategyId: Strategies.Identifiers.EoaBoost,
827
837
  protocol: PROTOCOLS.MorphoBlue,
828
838
  },
839
+ [Bundles.ArbitrumIds.MORPHO_BLUE_CLOSE]: {
840
+ strategyOrBundleId: Bundles.ArbitrumIds.MORPHO_BLUE_CLOSE,
841
+ strategyId: Strategies.Identifiers.CloseOnPrice,
842
+ protocol: PROTOCOLS.MorphoBlue,
843
+ },
829
844
  };
830
845
 
831
846
  export const BUNDLES_INFO: BundlesInfo = {
@@ -115,6 +115,7 @@ describe('Feature: ethereumService.ts', () => {
115
115
  'address': '0x5f98805A4E8be255a32880FDeC7F6728C6568bA0',
116
116
  'blockHash': '0xb92cab2569456dbfbdb853d2c67d72c9a7580543dbcb55d483a77322b40755a4',
117
117
  'blockNumber': 15166163,
118
+ 'blockTimestamp': '0x62d53ad8',
118
119
  'event': 'Transfer',
119
120
  'id': 'log_e2258e3a',
120
121
  'logIndex': 385,
@@ -66,6 +66,7 @@ describe('Feature: strategiesService.ts', () => {
66
66
  repayEnabled: true,
67
67
  subId1: 379,
68
68
  mergeWithId: Strategies.Identifiers.Boost,
69
+ subHashRepay: '0xafa4d200be62f171b57b1ae0f4e8348d1ac3f6d0812ad6da74a2adae8037dde1',
69
70
  }
70
71
  },
71
72
  {
@@ -990,6 +990,48 @@ function parseMorphoBlueLeverageManagementOnPrice(position: Position.Automated,
990
990
  return _position;
991
991
  }
992
992
 
993
+ function parseMorphoBlueCloseOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
994
+ const _position = cloneDeep(position);
995
+
996
+ const { subStruct } = parseData.subscriptionEventData;
997
+
998
+ const triggerData = triggerService.morphoBluePriceRangeTrigger.decode(subStruct.triggerData);
999
+ const subData = subDataService.morphoBlueCloseOnPriceSubData.decode(subStruct.subData);
1000
+
1001
+ _position.strategyData.decoded.triggerData = triggerData;
1002
+ _position.strategyData.decoded.subData = subData;
1003
+
1004
+ _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, Math.random());
1005
+
1006
+ const marketIdEncodedData = web3.eth.abi.encodeParameters(
1007
+ ['address', 'address', 'address', 'address', 'uint256'],
1008
+ [
1009
+ subData.loanToken,
1010
+ subData.collToken,
1011
+ subData.oracle,
1012
+ subData.irm,
1013
+ subData.lltv,
1014
+ ],
1015
+ );
1016
+
1017
+ const marketId = web3.utils.keccak256(marketIdEncodedData);
1018
+
1019
+ const { takeProfitType, stopLossType } = getStopLossAndTakeProfitTypeByCloseStrategyType(+subData.closeType);
1020
+
1021
+ _position.specific = {
1022
+ subHash: _position.subHash,
1023
+ marketId,
1024
+ collAsset: subData.collToken,
1025
+ debtAsset: subData.loanToken,
1026
+ stopLossPrice: triggerData.lowerPrice,
1027
+ takeProfitPrice: triggerData.upperPrice,
1028
+ stopLossType,
1029
+ takeProfitType,
1030
+ };
1031
+
1032
+ return _position;
1033
+ }
1034
+
993
1035
  function parseLiquityV2CloseOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
994
1036
  const _position = cloneDeep(position);
995
1037
 
@@ -1208,6 +1250,7 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
1208
1250
  [Strategies.Identifiers.EoaRepay]: parseMorphoBlueLeverageManagement,
1209
1251
  [Strategies.Identifiers.EoaBoost]: parseMorphoBlueLeverageManagement,
1210
1252
  [Strategies.Identifiers.BoostOnPrice]: parseMorphoBlueLeverageManagementOnPrice,
1253
+ [Strategies.Identifiers.CloseOnPrice]: parseMorphoBlueCloseOnPrice,
1211
1254
  },
1212
1255
  [ProtocolIdentifiers.StrategiesAutomation.FluidT1]: {
1213
1256
  [Strategies.Identifiers.Repay]: parseFluidT1LeverageManagement,
@@ -640,7 +640,7 @@ describe('Feature: strategySubService.ts', () => {
640
640
  [
641
641
  Bundles.MainnetIds.AAVE_V3_EOA_REPAY_ON_PRICE,
642
642
  true,
643
- ['0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000026e1f9c6000000000000000000000000000000000000000000000000000000000000000001'],
643
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000026e1f9c6000000000000000000000000000000000000000000000000000000000000000001'],
644
644
  [
645
645
  '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
646
646
  '0x0000000000000000000000000000000000000000000000000000000000000000',
@@ -668,7 +668,7 @@ describe('Feature: strategySubService.ts', () => {
668
668
  [
669
669
  Bundles.MainnetIds.AAVE_V3_EOA_BOOST_ON_PRICE,
670
670
  true,
671
- ['0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000002faf0800000000000000000000000000000000000000000000000000000000000000000'],
671
+ ['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000002faf0800000000000000000000000000000000000000000000000000000000000000000'],
672
672
  [
673
673
  '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
674
674
  '0x0000000000000000000000000000000000000000000000000000000000000002',
@@ -1587,6 +1587,61 @@ describe('Feature: strategySubService.ts', () => {
1587
1587
  });
1588
1588
  });
1589
1589
  });
1590
+
1591
+ describe('closeOnPrice()', () => {
1592
+ const examples: Array<[
1593
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
1594
+ [
1595
+ strategyOrBundleId: number,
1596
+ loanToken: EthereumAddress,
1597
+ collToken: EthereumAddress,
1598
+ oracle: EthereumAddress,
1599
+ irm: EthereumAddress,
1600
+ lltv: string,
1601
+ user: EthereumAddress,
1602
+ stopLossPrice: number,
1603
+ stopLossType: CloseToAssetType,
1604
+ takeProfitPrice: number,
1605
+ takeProfitType: CloseToAssetType,
1606
+ ]
1607
+ ]> = [
1608
+ [
1609
+ [
1610
+ Bundles.MainnetIds.MORPHO_BLUE_CLOSE,
1611
+ true,
1612
+ ['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
1613
+ [
1614
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1615
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1616
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1617
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1618
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1619
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1620
+ '0x0000000000000000000000000000000000000000000000000000000000000005',
1621
+ ],
1622
+ ],
1623
+ [
1624
+ Bundles.MainnetIds.MORPHO_BLUE_CLOSE,
1625
+ web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
1626
+ web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
1627
+ web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
1628
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1629
+ '945000000000000000',
1630
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1631
+ 1500,
1632
+ CloseToAssetType.DEBT,
1633
+ 4000,
1634
+ CloseToAssetType.COLLATERAL
1635
+ ]
1636
+ ],
1637
+ ];
1638
+
1639
+ examples.forEach(([expected, actual]) => {
1640
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1641
+ expect(morphoBlueEncode.closeOnPrice(...actual)).to.eql(expected);
1642
+ });
1643
+ });
1644
+ });
1590
1645
  });
1591
1646
 
1592
1647
  describe('When testing strategySubService.compoundV3L2Encode', () => {
@@ -3,8 +3,11 @@ import { getAssetInfo } from '@defisaver/tokens';
3
3
 
4
4
  import type { OrderType } from '../types/enums';
5
5
  import {
6
- CloseStrategyType, CloseToAssetType,
7
- Bundles, ChainId, RatioState, Strategies,
6
+ CloseToAssetType,
7
+ Bundles,
8
+ ChainId,
9
+ RatioState,
10
+ Strategies,
8
11
  } from '../types/enums';
9
12
  import type { EthereumAddress, StrategyOrBundleIds } from '../types';
10
13
 
@@ -95,6 +98,26 @@ export const makerEncode = {
95
98
  boostEnabled,
96
99
  ];
97
100
  },
101
+ leverageManagementWithoutSubProxy(
102
+ vaultId: number,
103
+ triggerRatio: number,
104
+ targetRatio: number,
105
+ ratioState: RatioState,
106
+ isBoost: boolean,
107
+ ) {
108
+ const bundleId = isBoost ? Bundles.MainnetIds.MAKER_BOOST : Bundles.MainnetIds.MAKER_REPAY;
109
+
110
+ const triggerData = triggerService.makerRatioTrigger.encode(vaultId, triggerRatio, ratioState);
111
+
112
+ const subData = subDataService.makerLeverageManagementWithoutSubProxy.encode(vaultId, targetRatio, ratioState);
113
+
114
+ return [
115
+ bundleId,
116
+ true,
117
+ triggerData,
118
+ subData,
119
+ ];
120
+ },
98
121
  };
99
122
 
100
123
  export const liquityEncode = {
@@ -578,6 +601,24 @@ export const sparkEncode = {
578
601
 
579
602
  return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
580
603
  },
604
+ leverageManagementWithoutSubProxy(
605
+ strategyOrBundleId: number,
606
+ market: EthereumAddress,
607
+ user: EthereumAddress,
608
+ ratioState: RatioState,
609
+ targetRatio: number,
610
+ triggerRatio: number,
611
+ ) {
612
+ const isBundle = true;
613
+
614
+ const subData = subDataService.sparkLeverageManagementSubDataWithoutSubProxy.encode(
615
+ targetRatio,
616
+ ratioState,
617
+ );
618
+ const triggerData = triggerService.sparkRatioTrigger.encode(user, market, triggerRatio, ratioState);
619
+
620
+ return [strategyOrBundleId, isBundle, triggerData, subData];
621
+ },
581
622
  };
582
623
 
583
624
  export const crvUSDEncode = {
@@ -670,6 +711,27 @@ export const morphoBlueEncode = {
670
711
  const triggerData = triggerService.morphoBluePriceTrigger.encode(oracle, collToken, loanToken, price, priceState);
671
712
  return [strategyOrBundleId, isBundle, triggerData, subData];
672
713
  },
714
+ closeOnPrice(
715
+ strategyOrBundleId: number,
716
+ loanToken: EthereumAddress,
717
+ collToken: EthereumAddress,
718
+ oracle: EthereumAddress,
719
+ irm: EthereumAddress,
720
+ lltv: string,
721
+ user: EthereumAddress,
722
+ stopLossPrice: number = 0,
723
+ stopLossType: CloseToAssetType = CloseToAssetType.DEBT,
724
+ takeProfitPrice: number = 0,
725
+ takeProfitType: CloseToAssetType = CloseToAssetType.COLLATERAL,
726
+ ) {
727
+ const isBundle = true;
728
+ const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
729
+
730
+ const subDataEncoded = subDataService.morphoBlueCloseOnPriceSubData.encode(loanToken, collToken, oracle, irm, lltv, user, closeType);
731
+ const triggerDataEncoded = triggerService.morphoBluePriceRangeTrigger.encode(oracle, collToken, loanToken, stopLossPrice, takeProfitPrice);
732
+
733
+ return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
734
+ },
673
735
  };
674
736
 
675
737
  export const liquityV2Encode = {
@@ -1368,6 +1368,65 @@ describe('Feature: subDataService.ts', () => {
1368
1368
  });
1369
1369
  });
1370
1370
 
1371
+ describe('When testing subDataService.morphoBlueCloseOnPriceSubData', () => {
1372
+ describe('encode()', () => {
1373
+ const examples: Array<[
1374
+ SubData,
1375
+ [loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, user: EthereumAddress, closeType: CloseStrategyType],
1376
+ ]> = [
1377
+ [
1378
+ [
1379
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1380
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1381
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1382
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1383
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1384
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1385
+ '0x0000000000000000000000000000000000000000000000000000000000000006',
1386
+ ],
1387
+ [web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'), '945000000000000000', web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT]
1388
+ ],
1389
+ ];
1390
+
1391
+ examples.forEach(([expected, actual]) => {
1392
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1393
+ expect(subDataService.morphoBlueCloseOnPriceSubData.encode(...actual)).to.eql(expected);
1394
+ });
1395
+ });
1396
+ });
1397
+
1398
+ describe('decode()', () => {
1399
+ const examples: Array<[{ loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, user: EthereumAddress, closeType: CloseStrategyType }, SubData]> = [
1400
+ [
1401
+ {
1402
+ loanToken: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
1403
+ collToken: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0',
1404
+ oracle: '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
1405
+ irm: '0x0000000000000000000000000000000000000000',
1406
+ lltv: '945000000000000000',
1407
+ user: '0x1031d218133AFaB8C2B819B1366c7e434Ad91e9c',
1408
+ closeType: CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT,
1409
+ },
1410
+ [
1411
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1412
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1413
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1414
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1415
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1416
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1417
+ '0x0000000000000000000000000000000000000000000000000000000000000006',
1418
+ ],
1419
+ ],
1420
+ ];
1421
+
1422
+ examples.forEach(([expected, actual]) => {
1423
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1424
+ expect(subDataService.morphoBlueCloseOnPriceSubData.decode(actual)).to.eql(expected);
1425
+ });
1426
+ });
1427
+ });
1428
+ });
1429
+
1371
1430
  describe('When testing subDataService.aaveV3LeverageManagementOnPriceSubData', () => {
1372
1431
  describe('encode()', () => {
1373
1432
  const examples: Array<[SubData, [collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number]]> = [
@@ -1625,7 +1684,7 @@ describe('Feature: subDataService.ts', () => {
1625
1684
  debtAssetId: number,
1626
1685
  marketAddr: EthereumAddress,
1627
1686
  targetRatio: number,
1628
- user: EthereumAddress
1687
+ owner: EthereumAddress
1629
1688
  ]
1630
1689
  ]
1631
1690
  > = [
@@ -1692,7 +1751,7 @@ describe('Feature: subDataService.ts', () => {
1692
1751
  debtAssetId: number,
1693
1752
  marketAddr: EthereumAddress,
1694
1753
  targetRatio: number,
1695
- user: EthereumAddress,
1754
+ owner: EthereumAddress,
1696
1755
  },
1697
1756
  string[]
1698
1757
  ]
@@ -1705,7 +1764,7 @@ describe('Feature: subDataService.ts', () => {
1705
1764
  debtAssetId: 1,
1706
1765
  marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1707
1766
  targetRatio: 200,
1708
- user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1767
+ owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1709
1768
  },
1710
1769
  [
1711
1770
  '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
@@ -1725,7 +1784,7 @@ describe('Feature: subDataService.ts', () => {
1725
1784
  debtAssetId: 1,
1726
1785
  marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1727
1786
  targetRatio: 200,
1728
- user: web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
1787
+ owner: web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
1729
1788
  },
1730
1789
  [
1731
1790
  '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
@@ -1763,7 +1822,7 @@ describe('Feature: subDataService.ts', () => {
1763
1822
  debtAssetId: number,
1764
1823
  closeType: CloseStrategyType,
1765
1824
  marketAddr: EthereumAddress,
1766
- user: EthereumAddress
1825
+ owner: EthereumAddress
1767
1826
  ]
1768
1827
  ]
1769
1828
  > = [
@@ -1958,7 +2017,7 @@ describe('Feature: subDataService.ts', () => {
1958
2017
  debtAssetId: number,
1959
2018
  closeType: CloseStrategyType,
1960
2019
  marketAddr: EthereumAddress,
1961
- user: EthereumAddress,
2020
+ owner: EthereumAddress,
1962
2021
  },
1963
2022
  string[]
1964
2023
  ]
@@ -1972,7 +2031,7 @@ describe('Feature: subDataService.ts', () => {
1972
2031
  debtAssetId: 1,
1973
2032
  closeType: CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL,
1974
2033
  marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1975
- user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
2034
+ owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1976
2035
  },
1977
2036
  [
1978
2037
  '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
@@ -1993,7 +2052,7 @@ describe('Feature: subDataService.ts', () => {
1993
2052
  debtAssetId: 1,
1994
2053
  closeType: CloseStrategyType.STOP_LOSS_IN_COLLATERAL,
1995
2054
  marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1996
- user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
2055
+ owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1997
2056
  },
1998
2057
  [
1999
2058
  '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
@@ -2014,7 +2073,7 @@ describe('Feature: subDataService.ts', () => {
2014
2073
  debtAssetId: 1,
2015
2074
  closeType: CloseStrategyType.TAKE_PROFIT_IN_DEBT,
2016
2075
  marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
2017
- user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
2076
+ owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
2018
2077
  },
2019
2078
  [
2020
2079
  '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
@@ -2035,7 +2094,7 @@ describe('Feature: subDataService.ts', () => {
2035
2094
  debtAssetId: 1,
2036
2095
  closeType: CloseStrategyType.STOP_LOSS_IN_DEBT,
2037
2096
  marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
2038
- user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
2097
+ owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
2039
2098
  },
2040
2099
  [
2041
2100
  '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
@@ -2056,7 +2115,7 @@ describe('Feature: subDataService.ts', () => {
2056
2115
  debtAssetId: 1,
2057
2116
  closeType: CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL,
2058
2117
  marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
2059
- user: web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
2118
+ owner: web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
2060
2119
  },
2061
2120
  [
2062
2121
  '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
@@ -2077,7 +2136,7 @@ describe('Feature: subDataService.ts', () => {
2077
2136
  debtAssetId: 1,
2078
2137
  closeType: CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT,
2079
2138
  marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
2080
- user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
2139
+ owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
2081
2140
  },
2082
2141
  [
2083
2142
  '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
@@ -2098,7 +2157,7 @@ describe('Feature: subDataService.ts', () => {
2098
2157
  debtAssetId: 1,
2099
2158
  closeType: CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT,
2100
2159
  marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
2101
- user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
2160
+ owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
2102
2161
  },
2103
2162
  [
2104
2163
  '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
@@ -2119,7 +2178,7 @@ describe('Feature: subDataService.ts', () => {
2119
2178
  debtAssetId: 1,
2120
2179
  closeType: CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL,
2121
2180
  marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
2122
- user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
2181
+ owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
2123
2182
  },
2124
2183
  [
2125
2184
  '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',