@defisaver/automation-sdk 3.3.16 → 3.3.17

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.
@@ -255,29 +255,57 @@ export const crvUSDEncode = {
255
255
  return [strategyId, isBundle, triggerData, subData];
256
256
  },
257
257
  };
258
+ function getMorphoBlueBundlesIds(network) {
259
+ switch (network) {
260
+ case ChainId.Ethereum:
261
+ return Bundles.MainnetIds;
262
+ case ChainId.Base:
263
+ return Bundles.BaseIds;
264
+ case ChainId.Arbitrum:
265
+ return Bundles.ArbitrumIds;
266
+ default:
267
+ throw new Error(`Morpho Blue strategies are not supported on chain ${network}`);
268
+ }
269
+ }
270
+ export function getMorphoBlueBundleId(network, strategy, isEOA) {
271
+ const bundlesIds = getMorphoBlueBundlesIds(network);
272
+ switch (strategy) {
273
+ case 'repay':
274
+ return isEOA ? bundlesIds.MORPHO_BLUE_EOA_REPAY : bundlesIds.MORPHO_BLUE_REPAY;
275
+ case 'boost':
276
+ return isEOA ? bundlesIds.MORPHO_BLUE_EOA_BOOST : bundlesIds.MORPHO_BLUE_BOOST;
277
+ case 'repayOnPrice':
278
+ return isEOA ? bundlesIds.MORPHO_BLUE_EOA_REPAY_ON_PRICE : bundlesIds.MORPHO_BLUE_REPAY_ON_PRICE;
279
+ case 'boostOnPrice':
280
+ return isEOA ? bundlesIds.MORPHO_BLUE_EOA_BOOST_ON_PRICE : bundlesIds.MORPHO_BLUE_BOOST_ON_PRICE;
281
+ case 'close':
282
+ return isEOA ? bundlesIds.MORPHO_BLUE_EOA_CLOSE : bundlesIds.MORPHO_BLUE_CLOSE;
283
+ default:
284
+ throw new Error(`Unknown Morpho Blue strategy: ${strategy}`);
285
+ }
286
+ }
258
287
  export const morphoBlueEncode = {
259
288
  leverageManagement(marketId, loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, triggerRatio, user, isEOA, network) {
260
289
  const subData = subDataService.morphoBlueLeverageManagementSubData.encode(loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, user, isEOA);
261
290
  const triggerData = triggerService.morphoBlueRatioTrigger.encode(marketId, user, triggerRatio, ratioState);
262
291
  // over is boost, under is repay
263
292
  const isBoost = ratioState === RatioState.OVER;
264
- let strategyOrBundleId;
265
- if (network === ChainId.Base) {
266
- return [isBoost ? Bundles.BaseIds.MORPHO_BLUE_BOOST : Bundles.BaseIds.MORPHO_BLUE_REPAY, true, triggerData, subData];
267
- }
268
- const bundlesIds = network === ChainId.Arbitrum ? Bundles.ArbitrumIds : Bundles.MainnetIds;
269
- if (isBoost)
270
- strategyOrBundleId = isEOA ? bundlesIds.MORPHO_BLUE_EOA_BOOST : bundlesIds.MORPHO_BLUE_BOOST;
271
- else
272
- strategyOrBundleId = isEOA ? bundlesIds.MORPHO_BLUE_EOA_REPAY : bundlesIds.MORPHO_BLUE_REPAY;
293
+ const bundleId = getMorphoBlueBundleId(network, isBoost ? 'boost' : 'repay', isEOA);
273
294
  const isBundle = true;
274
- return [strategyOrBundleId, isBundle, triggerData, subData];
295
+ return [bundleId, isBundle, triggerData, subData];
275
296
  },
276
297
  leverageManagementOnPrice(strategyOrBundleId, isBundle = true, loanToken, collToken, oracle, irm, lltv, user, targetRatio, price, priceState) {
277
298
  const subData = subDataService.morphoBlueLeverageManagementOnPriceSubData.encode(loanToken, collToken, oracle, irm, lltv, targetRatio, user);
278
299
  const triggerData = triggerService.morphoBluePriceTrigger.encode(oracle, collToken, loanToken, price, priceState);
279
300
  return [strategyOrBundleId, isBundle, triggerData, subData];
280
301
  },
302
+ leverageManagementOnPriceGeneric(loanToken, collToken, oracle, irm, lltv, user, targetRatio, price, priceState, isBoost, isEOA, network) {
303
+ const subData = subDataService.morphoBlueLeverageManagementOnPriceSubData.encode(loanToken, collToken, oracle, irm, lltv, targetRatio, user);
304
+ const triggerData = triggerService.morphoBluePriceTrigger.encode(oracle, collToken, loanToken, price, priceState);
305
+ const bundleId = getMorphoBlueBundleId(network, isBoost ? 'boostOnPrice' : 'repayOnPrice', isEOA);
306
+ const isBundle = true;
307
+ return [bundleId, isBundle, triggerData, subData];
308
+ },
281
309
  closeOnPrice(strategyOrBundleId, loanToken, collToken, oracle, irm, lltv, user, stopLossPrice = 0, stopLossType = CloseToAssetType.DEBT, takeProfitPrice = 0, takeProfitType = CloseToAssetType.COLLATERAL) {
282
310
  const isBundle = true;
283
311
  const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
@@ -285,6 +313,14 @@ export const morphoBlueEncode = {
285
313
  const triggerDataEncoded = triggerService.morphoBluePriceRangeTrigger.encode(oracle, collToken, loanToken, stopLossPrice, takeProfitPrice);
286
314
  return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
287
315
  },
316
+ closeOnPriceGeneric(loanToken, collToken, oracle, irm, lltv, user, stopLossPrice = 0, stopLossType = CloseToAssetType.DEBT, takeProfitPrice = 0, takeProfitType = CloseToAssetType.COLLATERAL, isEOA, network) {
317
+ const isBundle = true;
318
+ const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
319
+ const subDataEncoded = subDataService.morphoBlueCloseOnPriceSubData.encode(loanToken, collToken, oracle, irm, lltv, user, closeType);
320
+ const triggerDataEncoded = triggerService.morphoBluePriceRangeTrigger.encode(oracle, collToken, loanToken, stopLossPrice, takeProfitPrice);
321
+ const bundleId = getMorphoBlueBundleId(network, 'close', isEOA);
322
+ return [bundleId, isBundle, triggerDataEncoded, subDataEncoded];
323
+ },
288
324
  };
289
325
  export const liquityV2Encode = {
290
326
  leverageManagement(market, troveId, collToken, boldToken, ratioState, targetRatio, triggerRatio, strategyOrBundleId) {
@@ -1264,6 +1264,75 @@ describe('Feature: strategySubService.ts', () => {
1264
1264
  });
1265
1265
  });
1266
1266
  });
1267
+ describe('leverageManagementOnPriceGeneric()', () => {
1268
+ const examples = [
1269
+ [
1270
+ [
1271
+ Bundles.MainnetIds.MORPHO_BLUE_REPAY_ON_PRICE,
1272
+ true,
1273
+ ['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
1274
+ [
1275
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1276
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1277
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1278
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1279
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1280
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1281
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1282
+ ],
1283
+ ],
1284
+ [
1285
+ web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
1286
+ web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
1287
+ web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
1288
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1289
+ '945000000000000000',
1290
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1291
+ 200,
1292
+ 2500,
1293
+ RatioState.UNDER,
1294
+ false,
1295
+ false,
1296
+ ChainId.Ethereum,
1297
+ ],
1298
+ ],
1299
+ [
1300
+ [
1301
+ Bundles.MainnetIds.MORPHO_BLUE_BOOST_ON_PRICE,
1302
+ true,
1303
+ ['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000005d21dba0000000000000000000000000000000000000000000000000000000000000000000'],
1304
+ [
1305
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1306
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1307
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1308
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1309
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1310
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
1311
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1312
+ ],
1313
+ ],
1314
+ [
1315
+ web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
1316
+ web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
1317
+ web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
1318
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1319
+ '945000000000000000',
1320
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1321
+ 160,
1322
+ 4000,
1323
+ RatioState.OVER,
1324
+ true,
1325
+ false,
1326
+ ChainId.Ethereum,
1327
+ ],
1328
+ ],
1329
+ ];
1330
+ examples.forEach(([expected, actual]) => {
1331
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1332
+ expect(morphoBlueEncode.leverageManagementOnPriceGeneric(...actual)).to.eql(expected);
1333
+ });
1334
+ });
1335
+ });
1267
1336
  describe('closeOnPrice()', () => {
1268
1337
  const examples = [
1269
1338
  [
@@ -1292,7 +1361,7 @@ describe('Feature: strategySubService.ts', () => {
1292
1361
  1500,
1293
1362
  CloseToAssetType.DEBT,
1294
1363
  4000,
1295
- CloseToAssetType.COLLATERAL
1364
+ CloseToAssetType.COLLATERAL,
1296
1365
  ]
1297
1366
  ],
1298
1367
  ];
@@ -1302,6 +1371,45 @@ describe('Feature: strategySubService.ts', () => {
1302
1371
  });
1303
1372
  });
1304
1373
  });
1374
+ describe('closeOnPriceGeneric()', () => {
1375
+ const examples = [
1376
+ [
1377
+ [
1378
+ Bundles.MainnetIds.MORPHO_BLUE_CLOSE,
1379
+ true,
1380
+ ['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
1381
+ [
1382
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1383
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1384
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1385
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1386
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1387
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1388
+ '0x0000000000000000000000000000000000000000000000000000000000000005',
1389
+ ],
1390
+ ],
1391
+ [
1392
+ web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
1393
+ web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
1394
+ web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
1395
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1396
+ '945000000000000000',
1397
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1398
+ 1500,
1399
+ CloseToAssetType.DEBT,
1400
+ 4000,
1401
+ CloseToAssetType.COLLATERAL,
1402
+ false,
1403
+ ChainId.Ethereum,
1404
+ ]
1405
+ ],
1406
+ ];
1407
+ examples.forEach(([expected, actual]) => {
1408
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1409
+ expect(morphoBlueEncode.closeOnPriceGeneric(...actual)).to.eql(expected);
1410
+ });
1411
+ });
1412
+ });
1305
1413
  });
1306
1414
  describe('When testing strategySubService.sparkEncode', () => {
1307
1415
  describe('leverageManagementOnPrice()', () => {
@@ -225,7 +225,10 @@ export declare namespace Bundles {
225
225
  AAVE_V4_EOA_REPAY_ON_PRICE = 68,
226
226
  AAVE_V4_EOA_BOOST_ON_PRICE = 69,
227
227
  AAVE_V4_EOA_CLOSE = 70,
228
- MORPHO_BLUE_REPAY_ON_PRICE = 84
228
+ MORPHO_BLUE_REPAY_ON_PRICE = 84,
229
+ MORPHO_BLUE_EOA_BOOST_ON_PRICE = 85,
230
+ MORPHO_BLUE_EOA_REPAY_ON_PRICE = 86,
231
+ MORPHO_BLUE_EOA_CLOSE = 87
229
232
  }
230
233
  enum OptimismIds {
231
234
  AAVE_V3_REPAY = 0,
@@ -268,7 +271,12 @@ export declare namespace Bundles {
268
271
  AAVE_V3_EOA_BOOST_ON_PRICE = 26,
269
272
  AAVE_V3_EOA_CLOSE = 27,
270
273
  MORPHO_BLUE_CLOSE = 28,
271
- MORPHO_BLUE_REPAY_ON_PRICE = 36
274
+ MORPHO_BLUE_REPAY_ON_PRICE = 36,
275
+ MORPHO_BLUE_EOA_REPAY = 37,
276
+ MORPHO_BLUE_EOA_BOOST = 38,
277
+ MORPHO_BLUE_EOA_BOOST_ON_PRICE = 39,
278
+ MORPHO_BLUE_EOA_REPAY_ON_PRICE = 40,
279
+ MORPHO_BLUE_EOA_CLOSE = 41
272
280
  }
273
281
  enum ArbitrumIds {
274
282
  AAVE_V3_REPAY = 0,
@@ -300,6 +308,9 @@ export declare namespace Bundles {
300
308
  MORPHO_BLUE_EOA_REPAY = 26,
301
309
  MORPHO_BLUE_EOA_BOOST = 27,
302
310
  MORPHO_BLUE_CLOSE = 28,
303
- MORPHO_BLUE_REPAY_ON_PRICE = 36
311
+ MORPHO_BLUE_REPAY_ON_PRICE = 36,
312
+ MORPHO_BLUE_EOA_BOOST_ON_PRICE = 37,
313
+ MORPHO_BLUE_EOA_REPAY_ON_PRICE = 38,
314
+ MORPHO_BLUE_EOA_CLOSE = 39
304
315
  }
305
316
  }
@@ -246,6 +246,9 @@ export var Bundles;
246
246
  MainnetIds[MainnetIds["AAVE_V4_EOA_BOOST_ON_PRICE"] = 69] = "AAVE_V4_EOA_BOOST_ON_PRICE";
247
247
  MainnetIds[MainnetIds["AAVE_V4_EOA_CLOSE"] = 70] = "AAVE_V4_EOA_CLOSE";
248
248
  MainnetIds[MainnetIds["MORPHO_BLUE_REPAY_ON_PRICE"] = 84] = "MORPHO_BLUE_REPAY_ON_PRICE";
249
+ MainnetIds[MainnetIds["MORPHO_BLUE_EOA_BOOST_ON_PRICE"] = 85] = "MORPHO_BLUE_EOA_BOOST_ON_PRICE";
250
+ MainnetIds[MainnetIds["MORPHO_BLUE_EOA_REPAY_ON_PRICE"] = 86] = "MORPHO_BLUE_EOA_REPAY_ON_PRICE";
251
+ MainnetIds[MainnetIds["MORPHO_BLUE_EOA_CLOSE"] = 87] = "MORPHO_BLUE_EOA_CLOSE";
249
252
  })(MainnetIds = Bundles.MainnetIds || (Bundles.MainnetIds = {}));
250
253
  let OptimismIds;
251
254
  (function (OptimismIds) {
@@ -291,6 +294,11 @@ export var Bundles;
291
294
  BaseIds[BaseIds["AAVE_V3_EOA_CLOSE"] = 27] = "AAVE_V3_EOA_CLOSE";
292
295
  BaseIds[BaseIds["MORPHO_BLUE_CLOSE"] = 28] = "MORPHO_BLUE_CLOSE";
293
296
  BaseIds[BaseIds["MORPHO_BLUE_REPAY_ON_PRICE"] = 36] = "MORPHO_BLUE_REPAY_ON_PRICE";
297
+ BaseIds[BaseIds["MORPHO_BLUE_EOA_REPAY"] = 37] = "MORPHO_BLUE_EOA_REPAY";
298
+ BaseIds[BaseIds["MORPHO_BLUE_EOA_BOOST"] = 38] = "MORPHO_BLUE_EOA_BOOST";
299
+ BaseIds[BaseIds["MORPHO_BLUE_EOA_BOOST_ON_PRICE"] = 39] = "MORPHO_BLUE_EOA_BOOST_ON_PRICE";
300
+ BaseIds[BaseIds["MORPHO_BLUE_EOA_REPAY_ON_PRICE"] = 40] = "MORPHO_BLUE_EOA_REPAY_ON_PRICE";
301
+ BaseIds[BaseIds["MORPHO_BLUE_EOA_CLOSE"] = 41] = "MORPHO_BLUE_EOA_CLOSE";
294
302
  })(BaseIds = Bundles.BaseIds || (Bundles.BaseIds = {}));
295
303
  let ArbitrumIds;
296
304
  (function (ArbitrumIds) {
@@ -324,5 +332,8 @@ export var Bundles;
324
332
  ArbitrumIds[ArbitrumIds["MORPHO_BLUE_EOA_BOOST"] = 27] = "MORPHO_BLUE_EOA_BOOST";
325
333
  ArbitrumIds[ArbitrumIds["MORPHO_BLUE_CLOSE"] = 28] = "MORPHO_BLUE_CLOSE";
326
334
  ArbitrumIds[ArbitrumIds["MORPHO_BLUE_REPAY_ON_PRICE"] = 36] = "MORPHO_BLUE_REPAY_ON_PRICE";
335
+ ArbitrumIds[ArbitrumIds["MORPHO_BLUE_EOA_BOOST_ON_PRICE"] = 37] = "MORPHO_BLUE_EOA_BOOST_ON_PRICE";
336
+ ArbitrumIds[ArbitrumIds["MORPHO_BLUE_EOA_REPAY_ON_PRICE"] = 38] = "MORPHO_BLUE_EOA_REPAY_ON_PRICE";
337
+ ArbitrumIds[ArbitrumIds["MORPHO_BLUE_EOA_CLOSE"] = 39] = "MORPHO_BLUE_EOA_CLOSE";
327
338
  })(ArbitrumIds = Bundles.ArbitrumIds || (Bundles.ArbitrumIds = {}));
328
339
  })(Bundles || (Bundles = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/automation-sdk",
3
- "version": "3.3.16",
3
+ "version": "3.3.17",
4
4
  "description": "",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -578,6 +578,21 @@ export const MAINNET_BUNDLES_INFO: MainnetBundleInfo = {
578
578
  strategyId: Strategies.Identifiers.RepayOnPrice,
579
579
  protocol: PROTOCOLS.MorphoBlue,
580
580
  },
581
+ [Bundles.MainnetIds.MORPHO_BLUE_EOA_BOOST_ON_PRICE]: {
582
+ strategyOrBundleId: Bundles.MainnetIds.MORPHO_BLUE_EOA_BOOST_ON_PRICE,
583
+ strategyId: Strategies.Identifiers.EoaBoostOnPrice,
584
+ protocol: PROTOCOLS.MorphoBlue,
585
+ },
586
+ [Bundles.MainnetIds.MORPHO_BLUE_EOA_REPAY_ON_PRICE]: {
587
+ strategyOrBundleId: Bundles.MainnetIds.MORPHO_BLUE_EOA_REPAY_ON_PRICE,
588
+ strategyId: Strategies.Identifiers.EoaRepayOnPrice,
589
+ protocol: PROTOCOLS.MorphoBlue,
590
+ },
591
+ [Bundles.MainnetIds.MORPHO_BLUE_EOA_CLOSE]: {
592
+ strategyOrBundleId: Bundles.MainnetIds.MORPHO_BLUE_EOA_CLOSE,
593
+ strategyId: Strategies.Identifiers.EoaCloseOnPrice,
594
+ protocol: PROTOCOLS.MorphoBlue,
595
+ },
581
596
  };
582
597
 
583
598
  export const OPTIMISM_BUNDLES_INFO: OptimismBundleInfo = {
@@ -780,6 +795,31 @@ export const BASE_BUNDLES_INFO: BaseBundleInfo = {
780
795
  strategyId: Strategies.Identifiers.RepayOnPrice,
781
796
  protocol: PROTOCOLS.MorphoBlue,
782
797
  },
798
+ [Bundles.BaseIds.MORPHO_BLUE_EOA_REPAY]: {
799
+ strategyOrBundleId: Bundles.BaseIds.MORPHO_BLUE_EOA_REPAY,
800
+ strategyId: Strategies.Identifiers.EoaRepay,
801
+ protocol: PROTOCOLS.MorphoBlue,
802
+ },
803
+ [Bundles.BaseIds.MORPHO_BLUE_EOA_BOOST]: {
804
+ strategyOrBundleId: Bundles.BaseIds.MORPHO_BLUE_EOA_BOOST,
805
+ strategyId: Strategies.Identifiers.EoaBoost,
806
+ protocol: PROTOCOLS.MorphoBlue,
807
+ },
808
+ [Bundles.BaseIds.MORPHO_BLUE_EOA_BOOST_ON_PRICE]: {
809
+ strategyOrBundleId: Bundles.BaseIds.MORPHO_BLUE_EOA_BOOST_ON_PRICE,
810
+ strategyId: Strategies.Identifiers.EoaBoostOnPrice,
811
+ protocol: PROTOCOLS.MorphoBlue,
812
+ },
813
+ [Bundles.BaseIds.MORPHO_BLUE_EOA_REPAY_ON_PRICE]: {
814
+ strategyOrBundleId: Bundles.BaseIds.MORPHO_BLUE_EOA_REPAY_ON_PRICE,
815
+ strategyId: Strategies.Identifiers.EoaRepayOnPrice,
816
+ protocol: PROTOCOLS.MorphoBlue,
817
+ },
818
+ [Bundles.BaseIds.MORPHO_BLUE_EOA_CLOSE]: {
819
+ strategyOrBundleId: Bundles.BaseIds.MORPHO_BLUE_EOA_CLOSE,
820
+ strategyId: Strategies.Identifiers.EoaCloseOnPrice,
821
+ protocol: PROTOCOLS.MorphoBlue,
822
+ },
783
823
  };
784
824
 
785
825
  export const ARBITRUM_BUNDLES_INFO: ArbitrumBundleInfo = {
@@ -933,6 +973,21 @@ export const ARBITRUM_BUNDLES_INFO: ArbitrumBundleInfo = {
933
973
  strategyId: Strategies.Identifiers.RepayOnPrice,
934
974
  protocol: PROTOCOLS.MorphoBlue,
935
975
  },
976
+ [Bundles.ArbitrumIds.MORPHO_BLUE_EOA_BOOST_ON_PRICE]: {
977
+ strategyOrBundleId: Bundles.ArbitrumIds.MORPHO_BLUE_EOA_BOOST_ON_PRICE,
978
+ strategyId: Strategies.Identifiers.EoaBoostOnPrice,
979
+ protocol: PROTOCOLS.MorphoBlue,
980
+ },
981
+ [Bundles.ArbitrumIds.MORPHO_BLUE_EOA_REPAY_ON_PRICE]: {
982
+ strategyOrBundleId: Bundles.ArbitrumIds.MORPHO_BLUE_EOA_REPAY_ON_PRICE,
983
+ strategyId: Strategies.Identifiers.EoaRepayOnPrice,
984
+ protocol: PROTOCOLS.MorphoBlue,
985
+ },
986
+ [Bundles.ArbitrumIds.MORPHO_BLUE_EOA_CLOSE]: {
987
+ strategyOrBundleId: Bundles.ArbitrumIds.MORPHO_BLUE_EOA_CLOSE,
988
+ strategyId: Strategies.Identifiers.EoaCloseOnPrice,
989
+ protocol: PROTOCOLS.MorphoBlue,
990
+ },
936
991
  };
937
992
 
938
993
  export const BUNDLES_INFO: BundlesInfo = {
@@ -1072,6 +1072,7 @@ function parseMorphoBlueLeverageManagement(position: Position.Automated, parseDa
1072
1072
 
1073
1073
  const { subStruct, subId, subHash } = parseData.subscriptionEventData;
1074
1074
  const { isEnabled } = parseData.strategiesSubsData;
1075
+ const isEOA = _position.strategy.strategyId.includes('eoa');
1075
1076
  const triggerData = triggerService.morphoBlueRatioTrigger.decode(subStruct.triggerData);
1076
1077
  const subData = subDataService.morphoBlueLeverageManagementSubData.decode(subStruct.subData);
1077
1078
 
@@ -1089,7 +1090,7 @@ function parseMorphoBlueLeverageManagement(position: Position.Automated, parseDa
1089
1090
  repayEnabled: isEnabled,
1090
1091
  subId1: Number(subId),
1091
1092
  subHashRepay: subHash,
1092
- mergeWithId: Strategies.Identifiers.Boost,
1093
+ mergeWithId: isEOA ? Strategies.Identifiers.EoaBoost : Strategies.Identifiers.Boost,
1093
1094
  };
1094
1095
  } else {
1095
1096
  _position.specific = {
@@ -1098,14 +1099,12 @@ function parseMorphoBlueLeverageManagement(position: Position.Automated, parseDa
1098
1099
  boostEnabled: isEnabled,
1099
1100
  subId2: Number(subId),
1100
1101
  subHashBoost: subHash,
1101
- mergeId: Strategies.Identifiers.Boost,
1102
+ mergeId: isEOA ? Strategies.Identifiers.EoaBoost : Strategies.Identifiers.Boost,
1102
1103
  };
1103
1104
  }
1104
1105
 
1105
- const isEOA = _position.strategy.strategyId.includes('eoa');
1106
1106
  _position.strategy.strategyId = isEOA ? Strategies.IdOverrides.EoaLeverageManagement : Strategies.IdOverrides.LeverageManagement;
1107
1107
 
1108
-
1109
1108
  return _position;
1110
1109
  }
1111
1110
 
@@ -1113,6 +1112,7 @@ function parseMorphoBlueLeverageManagementOnPrice(position: Position.Automated,
1113
1112
  const _position = cloneDeep(position);
1114
1113
 
1115
1114
  const { subStruct } = parseData.subscriptionEventData;
1115
+ const isEOA = _position.strategy.strategyId.includes('eoa');
1116
1116
  const triggerData = triggerService.morphoBluePriceTrigger.decode(subStruct.triggerData);
1117
1117
  const subData = subDataService.morphoBlueLeverageManagementOnPriceSubData.decode(subStruct.subData);
1118
1118
 
@@ -1143,6 +1143,10 @@ function parseMorphoBlueLeverageManagementOnPrice(position: Position.Automated,
1143
1143
  ratioState: triggerData.priceState,
1144
1144
  };
1145
1145
 
1146
+ _position.strategy.strategyId = isEOA
1147
+ ? Strategies.IdOverrides.EoaLeverageManagementOnPrice
1148
+ : Strategies.IdOverrides.LeverageManagementOnPrice;
1149
+
1146
1150
  return _position;
1147
1151
  }
1148
1152
 
@@ -1150,6 +1154,7 @@ function parseMorphoBlueCloseOnPrice(position: Position.Automated, parseData: Pa
1150
1154
  const _position = cloneDeep(position);
1151
1155
 
1152
1156
  const { subStruct } = parseData.subscriptionEventData;
1157
+ const isEOA = _position.strategy.strategyId.includes('eoa');
1153
1158
 
1154
1159
  const triggerData = triggerService.morphoBluePriceRangeTrigger.decode(subStruct.triggerData);
1155
1160
  const subData = subDataService.morphoBlueCloseOnPriceSubData.decode(subStruct.subData);
@@ -1174,6 +1179,8 @@ function parseMorphoBlueCloseOnPrice(position: Position.Automated, parseData: Pa
1174
1179
 
1175
1180
  const { takeProfitType, stopLossType } = getStopLossAndTakeProfitTypeByCloseStrategyType(+subData.closeType);
1176
1181
 
1182
+ _position.strategy.strategyId = isEOA ? Strategies.Identifiers.EoaCloseOnPrice : Strategies.Identifiers.CloseOnPrice;
1183
+
1177
1184
  _position.specific = {
1178
1185
  subHash: _position.subHash,
1179
1186
  marketId,
@@ -1424,7 +1431,10 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
1424
1431
  [Strategies.Identifiers.EoaBoost]: parseMorphoBlueLeverageManagement,
1425
1432
  [Strategies.Identifiers.BoostOnPrice]: parseMorphoBlueLeverageManagementOnPrice,
1426
1433
  [Strategies.Identifiers.RepayOnPrice]: parseMorphoBlueLeverageManagementOnPrice,
1434
+ [Strategies.Identifiers.EoaBoostOnPrice]: parseMorphoBlueLeverageManagementOnPrice,
1435
+ [Strategies.Identifiers.EoaRepayOnPrice]: parseMorphoBlueLeverageManagementOnPrice,
1427
1436
  [Strategies.Identifiers.CloseOnPrice]: parseMorphoBlueCloseOnPrice,
1437
+ [Strategies.Identifiers.EoaCloseOnPrice]: parseMorphoBlueCloseOnPrice,
1428
1438
  },
1429
1439
  [ProtocolIdentifiers.StrategiesAutomation.FluidT1]: {
1430
1440
  [Strategies.Identifiers.Repay]: parseFluidT1LeverageManagement,
@@ -1501,6 +1501,93 @@ describe('Feature: strategySubService.ts', () => {
1501
1501
  });
1502
1502
  });
1503
1503
 
1504
+ describe('leverageManagementOnPriceGeneric()', () => {
1505
+ const examples: Array<[
1506
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
1507
+ [
1508
+ loanToken: EthereumAddress,
1509
+ collToken: EthereumAddress,
1510
+ oracle: EthereumAddress,
1511
+ irm: EthereumAddress,
1512
+ lltv: string,
1513
+ user: EthereumAddress,
1514
+ targetRatio: number,
1515
+ price: number,
1516
+ priceState: RatioState,
1517
+ isBoost: boolean,
1518
+ isEOA: boolean,
1519
+ network: ChainId,
1520
+ ]
1521
+ ]> = [
1522
+ [
1523
+ [
1524
+ Bundles.MainnetIds.MORPHO_BLUE_REPAY_ON_PRICE,
1525
+ true,
1526
+ ['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
1527
+ [
1528
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1529
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1530
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1531
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1532
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1533
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1534
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1535
+ ],
1536
+ ],
1537
+ [
1538
+ web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
1539
+ web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
1540
+ web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
1541
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1542
+ '945000000000000000',
1543
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1544
+ 200,
1545
+ 2500,
1546
+ RatioState.UNDER,
1547
+ false,
1548
+ false,
1549
+ ChainId.Ethereum,
1550
+ ],
1551
+ ],
1552
+ [
1553
+ [
1554
+ Bundles.MainnetIds.MORPHO_BLUE_BOOST_ON_PRICE,
1555
+ true,
1556
+ ['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000005d21dba0000000000000000000000000000000000000000000000000000000000000000000'],
1557
+ [
1558
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1559
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1560
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1561
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1562
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1563
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
1564
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1565
+ ],
1566
+ ],
1567
+ [
1568
+ web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
1569
+ web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
1570
+ web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
1571
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1572
+ '945000000000000000',
1573
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1574
+ 160,
1575
+ 4000,
1576
+ RatioState.OVER,
1577
+ true,
1578
+ false,
1579
+ ChainId.Ethereum,
1580
+ ],
1581
+ ],
1582
+ ];
1583
+
1584
+ examples.forEach(([expected, actual]) => {
1585
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1586
+ expect(morphoBlueEncode.leverageManagementOnPriceGeneric(...actual)).to.eql(expected);
1587
+ });
1588
+ });
1589
+ });
1590
+
1504
1591
  describe('closeOnPrice()', () => {
1505
1592
  const examples: Array<[
1506
1593
  [StrategyOrBundleIds, boolean, TriggerData, SubData],
@@ -1544,7 +1631,7 @@ describe('Feature: strategySubService.ts', () => {
1544
1631
  1500,
1545
1632
  CloseToAssetType.DEBT,
1546
1633
  4000,
1547
- CloseToAssetType.COLLATERAL
1634
+ CloseToAssetType.COLLATERAL,
1548
1635
  ]
1549
1636
  ],
1550
1637
  ];
@@ -1555,6 +1642,63 @@ describe('Feature: strategySubService.ts', () => {
1555
1642
  });
1556
1643
  });
1557
1644
  });
1645
+
1646
+ describe('closeOnPriceGeneric()', () => {
1647
+ const examples: Array<[
1648
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
1649
+ [
1650
+ loanToken: EthereumAddress,
1651
+ collToken: EthereumAddress,
1652
+ oracle: EthereumAddress,
1653
+ irm: EthereumAddress,
1654
+ lltv: string,
1655
+ user: EthereumAddress,
1656
+ stopLossPrice: number,
1657
+ stopLossType: CloseToAssetType,
1658
+ takeProfitPrice: number,
1659
+ takeProfitType: CloseToAssetType,
1660
+ isEOA: boolean,
1661
+ network: ChainId,
1662
+ ]
1663
+ ]> = [
1664
+ [
1665
+ [
1666
+ Bundles.MainnetIds.MORPHO_BLUE_CLOSE,
1667
+ true,
1668
+ ['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
1669
+ [
1670
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1671
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1672
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1673
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1674
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1675
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1676
+ '0x0000000000000000000000000000000000000000000000000000000000000005',
1677
+ ],
1678
+ ],
1679
+ [
1680
+ web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
1681
+ web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
1682
+ web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
1683
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1684
+ '945000000000000000',
1685
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1686
+ 1500,
1687
+ CloseToAssetType.DEBT,
1688
+ 4000,
1689
+ CloseToAssetType.COLLATERAL,
1690
+ false,
1691
+ ChainId.Ethereum,
1692
+ ]
1693
+ ],
1694
+ ];
1695
+
1696
+ examples.forEach(([expected, actual]) => {
1697
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1698
+ expect(morphoBlueEncode.closeOnPriceGeneric(...actual)).to.eql(expected);
1699
+ });
1700
+ });
1701
+ });
1558
1702
  });
1559
1703
 
1560
1704
  describe('When testing strategySubService.sparkEncode', () => {