@defisaver/automation-sdk 3.3.7-dev.0 → 3.3.7-morpho-dev-1

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 (38) hide show
  1. package/cjs/automation/private/StrategiesAutomation.js +2 -0
  2. package/cjs/constants/index.js +15 -0
  3. package/cjs/services/strategiesService.js +30 -0
  4. package/cjs/services/strategySubService.d.ts +1 -0
  5. package/cjs/services/strategySubService.js +7 -0
  6. package/cjs/services/strategySubService.test.js +38 -0
  7. package/cjs/services/subDataService.d.ts +12 -0
  8. package/cjs/services/subDataService.js +31 -1
  9. package/cjs/services/subDataService.test.js +52 -0
  10. package/cjs/services/triggerService.d.ts +10 -0
  11. package/cjs/services/triggerService.js +21 -1
  12. package/cjs/services/triggerService.test.js +48 -0
  13. package/cjs/types/enums.d.ts +6 -3
  14. package/cjs/types/enums.js +3 -0
  15. package/esm/automation/private/StrategiesAutomation.js +2 -0
  16. package/esm/constants/index.js +15 -0
  17. package/esm/services/strategiesService.js +30 -0
  18. package/esm/services/strategySubService.d.ts +1 -0
  19. package/esm/services/strategySubService.js +7 -0
  20. package/esm/services/strategySubService.test.js +38 -0
  21. package/esm/services/subDataService.d.ts +12 -0
  22. package/esm/services/subDataService.js +30 -0
  23. package/esm/services/subDataService.test.js +52 -0
  24. package/esm/services/triggerService.d.ts +10 -0
  25. package/esm/services/triggerService.js +20 -0
  26. package/esm/services/triggerService.test.js +49 -1
  27. package/esm/types/enums.d.ts +6 -3
  28. package/esm/types/enums.js +3 -0
  29. package/package.json +2 -2
  30. package/src/constants/index.ts +15 -0
  31. package/src/services/strategiesService.ts +43 -0
  32. package/src/services/strategySubService.test.ts +55 -0
  33. package/src/services/strategySubService.ts +21 -0
  34. package/src/services/subDataService.test.ts +59 -0
  35. package/src/services/subDataService.ts +40 -0
  36. package/src/services/triggerService.test.ts +53 -0
  37. package/src/services/triggerService.ts +32 -0
  38. package/src/types/enums.ts +3 -0
@@ -134,6 +134,7 @@ class StrategiesAutomation extends Automation_1.default {
134
134
  return __awaiter(this, void 0, void 0, function* () {
135
135
  const _options = Object.assign(Object.assign({}, (0, utils_1.addToObjectIf)((0, utils_1.isDefined)(options), options)), (0, utils_1.addToObjectIf)((0, utils_1.isDefined)(addresses), { filter: { proxy: addresses } }));
136
136
  let subscriptionEvents = yield this.getSubscriptionEventsFromSubStorage(_options);
137
+ console.log(subscriptionEvents);
137
138
  let subscriptions = [];
138
139
  if (subscriptionEvents) {
139
140
  let strategiesSubs = yield this.getStrategiesSubs(subscriptionEvents.map((e) => +e.returnValues.subId), _options.toBlock);
@@ -145,6 +146,7 @@ class StrategiesAutomation extends Automation_1.default {
145
146
  return sub === null || sub === void 0 ? void 0 : sub.isEnabled;
146
147
  });
147
148
  subscriptionEvents = filteredSubscriptionEvents;
149
+ console.log(filteredSubscriptionEvents);
148
150
  }
149
151
  const replaceSubWithUpdate = (index) => __awaiter(this, void 0, void 0, function* () {
150
152
  var _a;
@@ -468,6 +468,11 @@ exports.MAINNET_BUNDLES_INFO = {
468
468
  strategyId: enums_1.Strategies.Identifiers.CloseOnPrice,
469
469
  protocol: exports.PROTOCOLS.Spark,
470
470
  },
471
+ [enums_1.Bundles.MainnetIds.MORPHO_BLUE_CLOSE]: {
472
+ strategyOrBundleId: enums_1.Bundles.MainnetIds.MORPHO_BLUE_CLOSE,
473
+ strategyId: enums_1.Strategies.Identifiers.CloseOnPrice,
474
+ protocol: exports.PROTOCOLS.MorphoBlue,
475
+ },
471
476
  };
472
477
  exports.OPTIMISM_BUNDLES_INFO = {
473
478
  [enums_1.Bundles.OptimismIds.AAVE_V3_REPAY]: {
@@ -657,6 +662,11 @@ exports.BASE_BUNDLES_INFO = {
657
662
  strategyId: enums_1.Strategies.Identifiers.EoaCloseOnPrice,
658
663
  protocol: exports.PROTOCOLS.AaveV3,
659
664
  },
665
+ [enums_1.Bundles.BaseIds.MORPHO_BLUE_CLOSE]: {
666
+ strategyOrBundleId: enums_1.Bundles.BaseIds.MORPHO_BLUE_CLOSE,
667
+ strategyId: enums_1.Strategies.Identifiers.CloseOnPrice,
668
+ protocol: exports.PROTOCOLS.MorphoBlue,
669
+ },
660
670
  };
661
671
  exports.ARBITRUM_BUNDLES_INFO = {
662
672
  [enums_1.Bundles.ArbitrumIds.AAVE_V3_REPAY]: {
@@ -799,6 +809,11 @@ exports.ARBITRUM_BUNDLES_INFO = {
799
809
  strategyId: enums_1.Strategies.Identifiers.EoaBoost,
800
810
  protocol: exports.PROTOCOLS.MorphoBlue,
801
811
  },
812
+ [enums_1.Bundles.ArbitrumIds.MORPHO_BLUE_CLOSE]: {
813
+ strategyOrBundleId: enums_1.Bundles.ArbitrumIds.MORPHO_BLUE_CLOSE,
814
+ strategyId: enums_1.Strategies.Identifiers.CloseOnPrice,
815
+ protocol: exports.PROTOCOLS.MorphoBlue,
816
+ },
802
817
  };
803
818
  exports.BUNDLES_INFO = {
804
819
  [enums_1.ChainId.Ethereum]: exports.MAINNET_BUNDLES_INFO,
@@ -770,6 +770,35 @@ function parseMorphoBlueLeverageManagementOnPrice(position, parseData) {
770
770
  };
771
771
  return _position;
772
772
  }
773
+ function parseMorphoBlueCloseOnPrice(position, parseData) {
774
+ const _position = (0, lodash_1.cloneDeep)(position);
775
+ const { subStruct } = parseData.subscriptionEventData;
776
+ const triggerData = triggerService.morphoBluePriceRangeTrigger.decode(subStruct.triggerData);
777
+ const subData = subDataService.morphoBlueCloseOnPriceSubData.decode(subStruct.subData);
778
+ _position.strategyData.decoded.triggerData = triggerData;
779
+ _position.strategyData.decoded.subData = subData;
780
+ _position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, Math.random());
781
+ const marketIdEncodedData = web3.eth.abi.encodeParameters(['address', 'address', 'address', 'address', 'uint256'], [
782
+ subData.loanToken,
783
+ subData.collToken,
784
+ subData.oracle,
785
+ subData.irm,
786
+ subData.lltv,
787
+ ]);
788
+ const marketId = web3.utils.keccak256(marketIdEncodedData);
789
+ const { takeProfitType, stopLossType } = (0, utils_1.getStopLossAndTakeProfitTypeByCloseStrategyType)(+subData.closeType);
790
+ _position.specific = {
791
+ subHash: _position.subHash,
792
+ marketId,
793
+ collAsset: subData.collToken,
794
+ debtAsset: subData.loanToken,
795
+ stopLossPrice: triggerData.lowerPrice,
796
+ takeProfitPrice: triggerData.upperPrice,
797
+ stopLossType,
798
+ takeProfitType,
799
+ };
800
+ return _position;
801
+ }
773
802
  function parseLiquityV2CloseOnPrice(position, parseData) {
774
803
  const _position = (0, lodash_1.cloneDeep)(position);
775
804
  const { subStruct } = parseData.subscriptionEventData;
@@ -957,6 +986,7 @@ const parsingMethodsMapping = {
957
986
  [enums_1.Strategies.Identifiers.EoaRepay]: parseMorphoBlueLeverageManagement,
958
987
  [enums_1.Strategies.Identifiers.EoaBoost]: parseMorphoBlueLeverageManagement,
959
988
  [enums_1.Strategies.Identifiers.BoostOnPrice]: parseMorphoBlueLeverageManagementOnPrice,
989
+ [enums_1.Strategies.Identifiers.CloseOnPrice]: parseMorphoBlueCloseOnPrice,
960
990
  },
961
991
  [enums_1.ProtocolIdentifiers.StrategiesAutomation.FluidT1]: {
962
992
  [enums_1.Strategies.Identifiers.Repay]: parseFluidT1LeverageManagement,
@@ -94,6 +94,7 @@ export declare const crvUSDEncode: {
94
94
  export declare const morphoBlueEncode: {
95
95
  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
96
  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[])[];
97
+ 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
98
  };
98
99
  export declare const liquityV2Encode: {
99
100
  leverageManagement(market: EthereumAddress, troveId: string, collToken: EthereumAddress, boldToken: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, strategyOrBundleId: number): (number | boolean | string[])[];
@@ -309,6 +309,13 @@ exports.morphoBlueEncode = {
309
309
  const triggerData = triggerService.morphoBluePriceTrigger.encode(oracle, collToken, loanToken, price, priceState);
310
310
  return [strategyOrBundleId, isBundle, triggerData, subData];
311
311
  },
312
+ closeOnPrice(strategyOrBundleId, loanToken, collToken, oracle, irm, lltv, user, stopLossPrice = 0, stopLossType = enums_1.CloseToAssetType.DEBT, takeProfitPrice = 0, takeProfitType = enums_1.CloseToAssetType.COLLATERAL) {
313
+ const isBundle = true;
314
+ const closeType = (0, utils_1.getCloseStrategyType)(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
315
+ const subDataEncoded = subDataService.morphoBlueCloseOnPriceSubData.encode(loanToken, collToken, oracle, irm, lltv, user, closeType);
316
+ const triggerDataEncoded = triggerService.morphoBluePriceRangeTrigger.encode(oracle, collToken, loanToken, stopLossPrice, takeProfitPrice);
317
+ return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
318
+ },
312
319
  };
313
320
  exports.liquityV2Encode = {
314
321
  leverageManagement(market, troveId, collToken, boldToken, ratioState, targetRatio, triggerRatio, strategyOrBundleId) {
@@ -1364,6 +1364,44 @@ describe('Feature: strategySubService.ts', () => {
1364
1364
  });
1365
1365
  });
1366
1366
  });
1367
+ describe('closeOnPrice()', () => {
1368
+ const examples = [
1369
+ [
1370
+ [
1371
+ enums_1.Bundles.MainnetIds.MORPHO_BLUE_CLOSE,
1372
+ true,
1373
+ ['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
1374
+ [
1375
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1376
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1377
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1378
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1379
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1380
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1381
+ '0x0000000000000000000000000000000000000000000000000000000000000005',
1382
+ ],
1383
+ ],
1384
+ [
1385
+ enums_1.Bundles.MainnetIds.MORPHO_BLUE_CLOSE,
1386
+ web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
1387
+ web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
1388
+ web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
1389
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1390
+ '945000000000000000',
1391
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1392
+ 1500,
1393
+ enums_1.CloseToAssetType.DEBT,
1394
+ 4000,
1395
+ enums_1.CloseToAssetType.COLLATERAL
1396
+ ]
1397
+ ],
1398
+ ];
1399
+ examples.forEach(([expected, actual]) => {
1400
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1401
+ (0, chai_1.expect)(strategySubService_1.morphoBlueEncode.closeOnPrice(...actual)).to.eql(expected);
1402
+ });
1403
+ });
1404
+ });
1367
1405
  });
1368
1406
  describe('When testing strategySubService.compoundV3L2Encode', () => {
1369
1407
  describe('leverageManagement()', () => {
@@ -318,3 +318,15 @@ export declare const sparkCloseGenericSubData: {
318
318
  owner: EthereumAddress;
319
319
  };
320
320
  };
321
+ export declare const morphoBlueCloseOnPriceSubData: {
322
+ encode(loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, user: EthereumAddress, closeType: CloseStrategyType): string[];
323
+ decode(subData: string[]): {
324
+ loanToken: string;
325
+ collToken: string;
326
+ oracle: string;
327
+ irm: string;
328
+ lltv: string;
329
+ user: string;
330
+ closeType: CloseStrategyType;
331
+ };
332
+ };
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.sparkCloseGenericSubData = exports.compoundV3CloseSubData = exports.compoundV3LeverageManagementOnPriceSubData = exports.fluidLeverageManagementSubData = exports.liquityV2PaybackSubData = exports.morphoBlueLeverageManagementOnPriceSubData = exports.liquityV2LeverageManagementOnPriceSubData = exports.liquityV2CloseSubData = exports.liquityV2LeverageManagementSubData = exports.aaveV3LeverageManagementOnPriceSubData = exports.morphoBlueLeverageManagementSubData = exports.crvUSDPaybackSubData = exports.crvUSDLeverageManagementSubData = exports.liquityDebtInFrontRepaySubData = exports.liquityDsrSupplySubData = exports.liquityDsrPaybackSubData = exports.sparkLeverageManagementSubData = exports.exchangeLimitOrderSubData = exports.exchangeDcaSubData = exports.liquityPaybackUsingChickenBondSubData = exports.cBondsRebondSubData = exports.morphoAaveV2LeverageManagementSubData = exports.compoundV3L2LeverageManagementSubData = exports.compoundV3LeverageManagementSubData = exports.compoundV2LeverageManagementSubData = exports.aaveV3QuotePriceSubData = exports.aaveV3CollateralSwitchSubData = exports.aaveV3CloseGenericSubData = exports.aaveV3LeverageManagementOnPriceGeneric = exports.aaveV3LeverageManagementSubDataWithoutSubProxy = exports.aaveV3LeverageManagementSubData = exports.aaveV2LeverageManagementSubData = exports.liquityCloseSubData = exports.liquityLeverageManagementSubData = exports.makerLeverageManagementSubData = exports.makerCloseSubData = exports.liquityRepayFromSavingsSubData = exports.makerRepayFromSavingsSubData = void 0;
6
+ exports.morphoBlueCloseOnPriceSubData = exports.sparkCloseGenericSubData = exports.compoundV3CloseSubData = exports.compoundV3LeverageManagementOnPriceSubData = exports.fluidLeverageManagementSubData = exports.liquityV2PaybackSubData = exports.morphoBlueLeverageManagementOnPriceSubData = exports.liquityV2LeverageManagementOnPriceSubData = exports.liquityV2CloseSubData = exports.liquityV2LeverageManagementSubData = exports.aaveV3LeverageManagementOnPriceSubData = exports.morphoBlueLeverageManagementSubData = exports.crvUSDPaybackSubData = exports.crvUSDLeverageManagementSubData = exports.liquityDebtInFrontRepaySubData = exports.liquityDsrSupplySubData = exports.liquityDsrPaybackSubData = exports.sparkLeverageManagementSubData = exports.exchangeLimitOrderSubData = exports.exchangeDcaSubData = exports.liquityPaybackUsingChickenBondSubData = exports.cBondsRebondSubData = exports.morphoAaveV2LeverageManagementSubData = exports.compoundV3L2LeverageManagementSubData = exports.compoundV3LeverageManagementSubData = exports.compoundV2LeverageManagementSubData = exports.aaveV3QuotePriceSubData = exports.aaveV3CollateralSwitchSubData = exports.aaveV3CloseGenericSubData = exports.aaveV3LeverageManagementOnPriceGeneric = exports.aaveV3LeverageManagementSubDataWithoutSubProxy = exports.aaveV3LeverageManagementSubData = exports.aaveV2LeverageManagementSubData = exports.liquityCloseSubData = exports.liquityLeverageManagementSubData = exports.makerLeverageManagementSubData = exports.makerCloseSubData = exports.liquityRepayFromSavingsSubData = exports.makerRepayFromSavingsSubData = void 0;
7
7
  const decimal_js_1 = __importDefault(require("decimal.js"));
8
8
  const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
9
9
  const web3_utils_1 = require("web3-utils");
@@ -858,3 +858,33 @@ exports.sparkCloseGenericSubData = {
858
858
  };
859
859
  },
860
860
  };
861
+ exports.morphoBlueCloseOnPriceSubData = {
862
+ encode(loanToken, collToken, oracle, irm, lltv, user, closeType) {
863
+ const loanTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', loanToken);
864
+ const collTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', collToken);
865
+ const oracleEncoded = web3_eth_abi_1.default.encodeParameter('address', oracle);
866
+ const irmEncoded = web3_eth_abi_1.default.encodeParameter('address', irm);
867
+ const lltvEncoded = web3_eth_abi_1.default.encodeParameter('uint256', lltv);
868
+ const userEncoded = web3_eth_abi_1.default.encodeParameter('address', user);
869
+ const closeTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', closeType);
870
+ return [loanTokenEncoded, collTokenEncoded, oracleEncoded, irmEncoded, lltvEncoded, userEncoded, closeTypeEncoded];
871
+ },
872
+ decode(subData) {
873
+ const loanToken = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
874
+ const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
875
+ const oracle = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
876
+ const irm = web3_eth_abi_1.default.decodeParameter('address', subData[3]);
877
+ const lltv = web3_eth_abi_1.default.decodeParameter('uint256', subData[4]);
878
+ const user = web3_eth_abi_1.default.decodeParameter('address', subData[5]);
879
+ const closeType = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[6]));
880
+ return {
881
+ loanToken,
882
+ collToken,
883
+ oracle,
884
+ irm,
885
+ lltv,
886
+ user,
887
+ closeType,
888
+ };
889
+ },
890
+ };
@@ -1292,6 +1292,58 @@ describe('Feature: subDataService.ts', () => {
1292
1292
  });
1293
1293
  });
1294
1294
  });
1295
+ describe('When testing subDataService.morphoBlueCloseOnPriceSubData', () => {
1296
+ describe('encode()', () => {
1297
+ const examples = [
1298
+ [
1299
+ [
1300
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1301
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1302
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1303
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1304
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1305
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1306
+ '0x0000000000000000000000000000000000000000000000000000000000000006',
1307
+ ],
1308
+ [web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'), '945000000000000000', web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), enums_1.CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT]
1309
+ ],
1310
+ ];
1311
+ examples.forEach(([expected, actual]) => {
1312
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1313
+ (0, chai_1.expect)(subDataService.morphoBlueCloseOnPriceSubData.encode(...actual)).to.eql(expected);
1314
+ });
1315
+ });
1316
+ });
1317
+ describe('decode()', () => {
1318
+ const examples = [
1319
+ [
1320
+ {
1321
+ loanToken: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
1322
+ collToken: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0',
1323
+ oracle: '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
1324
+ irm: '0x0000000000000000000000000000000000000000',
1325
+ lltv: '945000000000000000',
1326
+ user: '0x1031d218133AFaB8C2B819B1366c7e434Ad91e9c',
1327
+ closeType: enums_1.CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT,
1328
+ },
1329
+ [
1330
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1331
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1332
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1333
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1334
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1335
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1336
+ '0x0000000000000000000000000000000000000000000000000000000000000006',
1337
+ ],
1338
+ ],
1339
+ ];
1340
+ examples.forEach(([expected, actual]) => {
1341
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1342
+ (0, chai_1.expect)(subDataService.morphoBlueCloseOnPriceSubData.decode(actual)).to.eql(expected);
1343
+ });
1344
+ });
1345
+ });
1346
+ });
1295
1347
  describe('When testing subDataService.aaveV3LeverageManagementOnPriceSubData', () => {
1296
1348
  describe('encode()', () => {
1297
1349
  const examples = [
@@ -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
+ };
@@ -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.sparkQuotePriceRangeTrigger = exports.aaveV3QuotePriceRangeTrigger = exports.compoundV3PriceRangeTrigger = exports.compoundV3PriceTrigger = exports.fluidRatioTrigger = exports.morphoBluePriceTrigger = exports.closePriceTrigger = exports.liquityV2QuotePriceTrigger = exports.liquityV2RatioTrigger = exports.morphoBlueRatioTrigger = exports.crvUsdHealthRatioTrigger = exports.crvUSDRatioTrigger = exports.curveUsdSoftLiquidationTrigger = exports.curveUsdBorrowRateTrigger = exports.sparkRatioTrigger = exports.exchangeOffchainPriceTrigger = exports.exchangeTimestampTrigger = exports.compoundV3RatioTrigger = exports.cBondsRebondTrigger = exports.aaveV2RatioTrigger = exports.liquityV2AdjustTimeTrigger = exports.liquityV2DebtInFrontTrigger = exports.liquityDebtInFrontWithLimitTrigger = exports.liquityDebtInFrontTrigger = exports.liquityRatioTrigger = exports.compoundV2RatioTrigger = exports.aaveV3QuotePriceWithMaximumGasPriceTrigger = exports.aaveV3QuotePriceTrigger = exports.morphoAaveV2RatioTrigger = exports.aaveV3RatioTrigger = exports.makerRatioTrigger = exports.trailingStopTrigger = exports.chainlinkPriceTrigger = void 0;
29
+ exports.morphoBluePriceRangeTrigger = exports.sparkQuotePriceRangeTrigger = exports.aaveV3QuotePriceRangeTrigger = exports.compoundV3PriceRangeTrigger = exports.compoundV3PriceTrigger = exports.fluidRatioTrigger = exports.morphoBluePriceTrigger = exports.closePriceTrigger = exports.liquityV2QuotePriceTrigger = exports.liquityV2RatioTrigger = exports.morphoBlueRatioTrigger = exports.crvUsdHealthRatioTrigger = exports.crvUSDRatioTrigger = exports.curveUsdSoftLiquidationTrigger = exports.curveUsdBorrowRateTrigger = exports.sparkRatioTrigger = exports.exchangeOffchainPriceTrigger = exports.exchangeTimestampTrigger = exports.compoundV3RatioTrigger = exports.cBondsRebondTrigger = exports.aaveV2RatioTrigger = exports.liquityV2AdjustTimeTrigger = exports.liquityV2DebtInFrontTrigger = exports.liquityDebtInFrontWithLimitTrigger = exports.liquityDebtInFrontTrigger = exports.liquityRatioTrigger = exports.compoundV2RatioTrigger = exports.aaveV3QuotePriceWithMaximumGasPriceTrigger = exports.aaveV3QuotePriceTrigger = exports.morphoAaveV2RatioTrigger = exports.aaveV3RatioTrigger = exports.makerRatioTrigger = exports.trailingStopTrigger = exports.chainlinkPriceTrigger = void 0;
30
30
  const decimal_js_1 = __importDefault(require("decimal.js"));
31
31
  const tokens_1 = require("@defisaver/tokens");
32
32
  const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
@@ -527,3 +527,23 @@ exports.sparkQuotePriceRangeTrigger = {
527
527
  };
528
528
  },
529
529
  };
530
+ exports.morphoBluePriceRangeTrigger = {
531
+ encode(oracle, collateralToken, loanToken, lowerPrice, upperPrice) {
532
+ // Price is scaled to 1e8
533
+ const lowerPriceFormatted = new decimal_js_1.default(lowerPrice).mul(1e8).floor().toString();
534
+ const upperPriceFormatted = new decimal_js_1.default(upperPrice).mul(1e8).floor().toString();
535
+ return [
536
+ web3_eth_abi_1.default.encodeParameters(['address', 'address', 'address', 'uint256', 'uint256'], [oracle, collateralToken, loanToken, lowerPriceFormatted, upperPriceFormatted]),
537
+ ];
538
+ },
539
+ decode(triggerData) {
540
+ const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'address', 'address', 'uint256', 'uint256'], triggerData[0]);
541
+ return {
542
+ oracle: decodedData[0],
543
+ collateralToken: decodedData[1],
544
+ loanToken: decodedData[2],
545
+ lowerPrice: new decimal_js_1.default(decodedData[3]).div(1e8).toString(),
546
+ upperPrice: new decimal_js_1.default(decodedData[4]).div(1e8).toString(),
547
+ };
548
+ },
549
+ };
@@ -1136,4 +1136,52 @@ describe('Feature: triggerService.ts', () => {
1136
1136
  });
1137
1137
  });
1138
1138
  });
1139
+ describe('When testing triggerService.morphoBluePriceRangeTrigger', () => {
1140
+ describe('encode()', () => {
1141
+ const examples = [
1142
+ [
1143
+ ['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
1144
+ [web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 1500, 4000]
1145
+ ],
1146
+ [
1147
+ ['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
1148
+ [web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 0, 5000]
1149
+ ],
1150
+ ];
1151
+ examples.forEach(([expected, actual]) => {
1152
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1153
+ (0, chai_1.expect)(triggerService_1.morphoBluePriceRangeTrigger.encode(...actual)).to.eql(expected);
1154
+ });
1155
+ });
1156
+ });
1157
+ describe('decode()', () => {
1158
+ const examples = [
1159
+ [
1160
+ {
1161
+ oracle: web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
1162
+ collateralToken: web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
1163
+ loanToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1164
+ lowerPrice: '1500',
1165
+ upperPrice: '4000',
1166
+ },
1167
+ ['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
1168
+ ],
1169
+ [
1170
+ {
1171
+ oracle: web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
1172
+ collateralToken: web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
1173
+ loanToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1174
+ lowerPrice: '0',
1175
+ upperPrice: '5000',
1176
+ },
1177
+ ['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8dA6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
1178
+ ],
1179
+ ];
1180
+ examples.forEach(([expected, actual]) => {
1181
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1182
+ (0, chai_1.expect)(triggerService_1.morphoBluePriceRangeTrigger.decode(actual)).to.eql(expected);
1183
+ });
1184
+ });
1185
+ });
1186
+ });
1139
1187
  });
@@ -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 = {}));
@@ -129,6 +129,7 @@ export default class StrategiesAutomation extends Automation {
129
129
  return __awaiter(this, void 0, void 0, function* () {
130
130
  const _options = Object.assign(Object.assign({}, addToObjectIf(isDefined(options), options)), addToObjectIf(isDefined(addresses), { filter: { proxy: addresses } }));
131
131
  let subscriptionEvents = yield this.getSubscriptionEventsFromSubStorage(_options);
132
+ console.log(subscriptionEvents);
132
133
  let subscriptions = [];
133
134
  if (subscriptionEvents) {
134
135
  let strategiesSubs = yield this.getStrategiesSubs(subscriptionEvents.map((e) => +e.returnValues.subId), _options.toBlock);
@@ -140,6 +141,7 @@ export default class StrategiesAutomation extends Automation {
140
141
  return sub === null || sub === void 0 ? void 0 : sub.isEnabled;
141
142
  });
142
143
  subscriptionEvents = filteredSubscriptionEvents;
144
+ console.log(filteredSubscriptionEvents);
143
145
  }
144
146
  const replaceSubWithUpdate = (index) => __awaiter(this, void 0, void 0, function* () {
145
147
  var _a;
@@ -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,
@@ -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,
@@ -94,6 +94,7 @@ export declare const crvUSDEncode: {
94
94
  export declare const morphoBlueEncode: {
95
95
  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
96
  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[])[];
97
+ 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
98
  };
98
99
  export declare const liquityV2Encode: {
99
100
  leverageManagement(market: EthereumAddress, troveId: string, collToken: EthereumAddress, boldToken: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, strategyOrBundleId: number): (number | boolean | string[])[];
@@ -280,6 +280,13 @@ export const morphoBlueEncode = {
280
280
  const triggerData = triggerService.morphoBluePriceTrigger.encode(oracle, collToken, loanToken, price, priceState);
281
281
  return [strategyOrBundleId, isBundle, triggerData, subData];
282
282
  },
283
+ closeOnPrice(strategyOrBundleId, loanToken, collToken, oracle, irm, lltv, user, stopLossPrice = 0, stopLossType = CloseToAssetType.DEBT, takeProfitPrice = 0, takeProfitType = CloseToAssetType.COLLATERAL) {
284
+ const isBundle = true;
285
+ const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
286
+ const subDataEncoded = subDataService.morphoBlueCloseOnPriceSubData.encode(loanToken, collToken, oracle, irm, lltv, user, closeType);
287
+ const triggerDataEncoded = triggerService.morphoBluePriceRangeTrigger.encode(oracle, collToken, loanToken, stopLossPrice, takeProfitPrice);
288
+ return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
289
+ },
283
290
  };
284
291
  export const liquityV2Encode = {
285
292
  leverageManagement(market, troveId, collToken, boldToken, ratioState, targetRatio, triggerRatio, strategyOrBundleId) {
@@ -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()', () => {
@@ -318,3 +318,15 @@ export declare const sparkCloseGenericSubData: {
318
318
  owner: EthereumAddress;
319
319
  };
320
320
  };
321
+ export declare const morphoBlueCloseOnPriceSubData: {
322
+ encode(loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, user: EthereumAddress, closeType: CloseStrategyType): string[];
323
+ decode(subData: string[]): {
324
+ loanToken: string;
325
+ collToken: string;
326
+ oracle: string;
327
+ irm: string;
328
+ lltv: string;
329
+ user: string;
330
+ closeType: CloseStrategyType;
331
+ };
332
+ };