@defisaver/automation-sdk 3.3.15 → 3.3.16-liq-prot-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 +145 -0
  2. package/cjs/index.d.ts +2 -2
  3. package/cjs/index.js +5 -2
  4. package/cjs/services/strategiesService.js +158 -9
  5. package/cjs/services/strategySubService.d.ts +17 -16
  6. package/cjs/services/strategySubService.js +69 -28
  7. package/cjs/services/strategySubService.test.js +69 -40
  8. package/cjs/services/subDataService.d.ts +70 -20
  9. package/cjs/services/subDataService.js +23 -79
  10. package/cjs/services/subDataService.test.js +117 -202
  11. package/cjs/services/triggerService.test.js +60 -0
  12. package/cjs/services/utils.d.ts +2 -1
  13. package/cjs/services/utils.js +14 -1
  14. package/cjs/types/enums.d.ts +39 -6
  15. package/cjs/types/enums.js +33 -0
  16. package/esm/constants/index.js +145 -0
  17. package/esm/index.d.ts +2 -2
  18. package/esm/index.js +5 -2
  19. package/esm/services/strategiesService.js +158 -9
  20. package/esm/services/strategySubService.d.ts +17 -16
  21. package/esm/services/strategySubService.js +69 -28
  22. package/esm/services/strategySubService.test.js +70 -38
  23. package/esm/services/subDataService.d.ts +70 -20
  24. package/esm/services/subDataService.js +21 -77
  25. package/esm/services/subDataService.test.js +118 -200
  26. package/esm/services/triggerService.test.js +61 -1
  27. package/esm/services/utils.d.ts +2 -1
  28. package/esm/services/utils.js +13 -1
  29. package/esm/types/enums.d.ts +39 -6
  30. package/esm/types/enums.js +33 -0
  31. package/package.json +1 -1
  32. package/src/constants/index.ts +147 -1
  33. package/src/index.ts +22 -6
  34. package/src/services/strategiesService.ts +222 -9
  35. package/src/services/strategySubService.test.ts +86 -46
  36. package/src/services/strategySubService.ts +166 -39
  37. package/src/services/subDataService.test.ts +128 -214
  38. package/src/services/subDataService.ts +42 -106
  39. package/src/services/triggerService.test.ts +69 -0
  40. package/src/services/utils.test.ts +1 -1
  41. package/src/services/utils.ts +15 -1
  42. package/src/types/enums.ts +33 -2
@@ -1,5 +1,4 @@
1
1
  import { expect } from 'chai';
2
- import Dec from 'decimal.js';
3
2
  import { otherAddresses } from '@defisaver/sdk';
4
3
  import { getAssetInfo, MAXUINT } from '@defisaver/tokens';
5
4
  import * as web3Utils from 'web3-utils';
@@ -9,12 +8,10 @@ import type { EthereumAddress, StrategyOrBundleIds, SubData, TriggerData } from
9
8
 
10
9
  import '../configuration';
11
10
  import {
12
- chickenBondsEncode,
13
11
  liquityEncode,
14
12
  makerEncode,
15
13
  aaveV3Encode,
16
14
  compoundV3Encode,
17
- morphoAaveV2Encode,
18
15
  exchangeEncode,
19
16
  crvUSDEncode,
20
17
  morphoBlueEncode,
@@ -137,7 +134,7 @@ describe('Feature: strategySubService.ts', () => {
137
134
  });
138
135
  });
139
136
 
140
- describe('leverageManagementWithoutSubProxy()', () => {
137
+ describe('leverageManagement()', () => {
141
138
  const examples: Array<[
142
139
  [StrategyOrBundleIds, boolean, TriggerData, SubData],
143
140
  [
@@ -187,7 +184,7 @@ describe('Feature: strategySubService.ts', () => {
187
184
 
188
185
  examples.forEach(([expected, actual]) => {
189
186
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
190
- expect(makerEncode.leverageManagementWithoutSubProxy(...actual)).to.eql(expected);
187
+ expect(makerEncode.leverageManagement(...actual)).to.eql(expected);
191
188
  });
192
189
  });
193
190
  });
@@ -348,26 +345,6 @@ describe('Feature: strategySubService.ts', () => {
348
345
  });
349
346
  });
350
347
 
351
- describe('When testing strategySubService.chickenBondsEncode', () => {
352
- describe('rebond()', () => {
353
- const examples: Array<[
354
- SubData,
355
- [bondId: number],
356
- ]> = [
357
- [
358
- ['0x00000000000000000000000000000000000000000000000000000000000005e3'],
359
- [1507]
360
- ]
361
- ];
362
-
363
- examples.forEach(([expected, actual]) => {
364
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
365
- expect(chickenBondsEncode.rebond(...actual)).to.eql(expected);
366
- });
367
- });
368
- });
369
- });
370
-
371
348
  describe('When testing strategySubService.aaveV3Encode', () => {
372
349
  describe('closeToAsset()', () => {
373
350
  const examples: Array<[
@@ -1156,27 +1133,6 @@ describe('Feature: strategySubService.ts', () => {
1156
1133
  });
1157
1134
  });
1158
1135
 
1159
- describe('When testing strategySubService.morphoAaveV2Encode', () => {
1160
- describe('leverageManagement()', () => {
1161
- const examples: Array<[[string, string, string, string, boolean], [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean]]> = [
1162
- [
1163
- [new Dec(160).mul(1e16).toString(), new Dec(220).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), true],
1164
- [160, 220, 180, 190, true]
1165
- ],
1166
- [
1167
- [new Dec(160).mul(1e16).toString(), new Dec(200).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), false],
1168
- [160, 200, 180, 190, false]
1169
- ],
1170
- ];
1171
-
1172
- examples.forEach(([expected, actual]) => {
1173
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1174
- expect(morphoAaveV2Encode.leverageManagement(...actual)).to.eql(expected);
1175
- });
1176
- });
1177
- });
1178
- });
1179
-
1180
1136
  describe('When testing strategySubService.exchangeEncode', () => {
1181
1137
  describe('dca()', () => {
1182
1138
  const examples: Array<[
@@ -1417,6 +1373,90 @@ describe('Feature: strategySubService.ts', () => {
1417
1373
  });
1418
1374
  });
1419
1375
 
1376
+ describe('leverageManagementOnPrice()', () => {
1377
+ const examples: Array<[
1378
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
1379
+ [
1380
+ strategyOrBundleId: number,
1381
+ isBundle: boolean,
1382
+ loanToken: EthereumAddress,
1383
+ collToken: EthereumAddress,
1384
+ oracle: EthereumAddress,
1385
+ irm: EthereumAddress,
1386
+ lltv: string,
1387
+ user: EthereumAddress,
1388
+ targetRatio: number,
1389
+ price: number,
1390
+ priceState: RatioState,
1391
+ ]
1392
+ ]> = [
1393
+ [
1394
+ [
1395
+ Bundles.MainnetIds.MORPHO_BLUE_REPAY_ON_PRICE,
1396
+ true,
1397
+ ['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
1398
+ [
1399
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1400
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1401
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1402
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1403
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1404
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1405
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1406
+ ],
1407
+ ],
1408
+ [
1409
+ Bundles.MainnetIds.MORPHO_BLUE_REPAY_ON_PRICE,
1410
+ true,
1411
+ web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
1412
+ web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
1413
+ web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
1414
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1415
+ '945000000000000000',
1416
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1417
+ 200,
1418
+ 2500,
1419
+ RatioState.UNDER,
1420
+ ],
1421
+ ],
1422
+ [
1423
+ [
1424
+ Bundles.MainnetIds.MORPHO_BLUE_BOOST_ON_PRICE,
1425
+ true,
1426
+ ['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000005d21dba0000000000000000000000000000000000000000000000000000000000000000000'],
1427
+ [
1428
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1429
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1430
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1431
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1432
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1433
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
1434
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1435
+ ],
1436
+ ],
1437
+ [
1438
+ Bundles.MainnetIds.MORPHO_BLUE_BOOST_ON_PRICE,
1439
+ true,
1440
+ web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
1441
+ web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
1442
+ web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
1443
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1444
+ '945000000000000000',
1445
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1446
+ 160,
1447
+ 4000,
1448
+ RatioState.OVER,
1449
+ ],
1450
+ ],
1451
+ ];
1452
+
1453
+ examples.forEach(([expected, actual]) => {
1454
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1455
+ expect(morphoBlueEncode.leverageManagementOnPrice(...actual)).to.eql(expected);
1456
+ });
1457
+ });
1458
+ });
1459
+
1420
1460
  describe('closeOnPrice()', () => {
1421
1461
  const examples: Array<[
1422
1462
  [StrategyOrBundleIds, boolean, TriggerData, SubData],
@@ -1,22 +1,26 @@
1
- import Dec from 'decimal.js';
2
1
  import { getAssetInfo } from '@defisaver/tokens';
2
+ import Dec from 'decimal.js';
3
3
 
4
- import type { OrderType } from '../types/enums';
4
+ import { STRATEGY_IDS } from '../constants';
5
5
  import {
6
- CloseToAssetType,
7
6
  Bundles,
8
7
  ChainId,
8
+ CloseToAssetType,
9
9
  RatioState,
10
10
  Strategies,
11
11
  } from '../types/enums';
12
12
  import type { EthereumAddress, StrategyOrBundleIds } from '../types';
13
13
 
14
- import { STRATEGY_IDS } from '../constants';
14
+ import type { OrderType } from '../types/enums';
15
15
 
16
16
  import * as subDataService from './subDataService';
17
17
  import * as triggerService from './triggerService';
18
18
  import {
19
- compareAddresses, getCloseStrategyType, requireAddress, requireAddresses,
19
+ compareAddresses,
20
+ getBundleIdsByNetwork,
21
+ getCloseStrategyType,
22
+ requireAddress,
23
+ requireAddresses,
20
24
  } from './utils';
21
25
 
22
26
  export const makerEncode = {
@@ -81,7 +85,7 @@ export const makerEncode = {
81
85
 
82
86
  return [strategyOrBundleId, isBundle, triggerData, subData];
83
87
  },
84
- leverageManagementWithoutSubProxy(
88
+ leverageManagement(
85
89
  vaultId: number,
86
90
  triggerRatio: number,
87
91
  targetRatio: number,
@@ -93,7 +97,27 @@ export const makerEncode = {
93
97
 
94
98
  const triggerData = triggerService.makerRatioTrigger.encode(vaultId, triggerRatio, ratioState);
95
99
 
96
- const subData = subDataService.makerLeverageManagementWithoutSubProxy.encode(vaultId, targetRatio, daiAddr);
100
+ const subData = subDataService.makerLeverageManagementSubData.encode(vaultId, targetRatio, daiAddr);
101
+
102
+ return [
103
+ bundleId,
104
+ true,
105
+ triggerData,
106
+ subData,
107
+ ];
108
+ },
109
+
110
+ liquidationProtection(
111
+ vaultId: number,
112
+ triggerRatio: number,
113
+ targetRatio: number,
114
+ ratioState: RatioState,
115
+ daiAddr?: EthereumAddress,
116
+ ) {
117
+ const bundleId = Bundles.MainnetIds.MAKER_SW_LIQUIDATION_PROTECTION;
118
+
119
+ const triggerData = triggerService.makerRatioTrigger.encode(vaultId, triggerRatio, ratioState);
120
+ const subData = subDataService.makerLiquidationProtectionSubData.encode(vaultId, targetRatio, daiAddr);
97
121
 
98
122
  return [
99
123
  bundleId,
@@ -162,7 +186,7 @@ export const liquityEncode = {
162
186
 
163
187
  return [strategyId, isBundle, triggerData, subData];
164
188
  },
165
- leverageManagementWithoutSubProxy(
189
+ leverageManagement(
166
190
  strategyOrBundleId: number,
167
191
  user: EthereumAddress,
168
192
  ratioState: RatioState,
@@ -171,7 +195,7 @@ export const liquityEncode = {
171
195
  ) {
172
196
  const isBundle = true;
173
197
 
174
- const subData = subDataService.liquityLeverageManagementSubDataWithoutSubProxy.encode(targetRatio, ratioState);
198
+ const subData = subDataService.liquityLeverageManagementSubData.encode(targetRatio, ratioState);
175
199
  const triggerData = triggerService.liquityRatioTrigger.encode(user, triggerRatio, ratioState);
176
200
 
177
201
  return [strategyOrBundleId, isBundle, triggerData, subData];
@@ -223,14 +247,8 @@ export const liquityEncode = {
223
247
  },
224
248
  };
225
249
 
226
- export const chickenBondsEncode = {
227
- rebond(bondId: number) {
228
- return subDataService.cBondsRebondSubData.encode(bondId);
229
- },
230
- };
231
-
232
250
  export const aaveV2Encode = {
233
- leverageManagementWithoutSubProxy(
251
+ leverageManagement(
234
252
  strategyOrBundleId: number,
235
253
  market: EthereumAddress,
236
254
  user: EthereumAddress,
@@ -240,7 +258,7 @@ export const aaveV2Encode = {
240
258
  ) {
241
259
  const isBundle = true;
242
260
 
243
- const subData = subDataService.aaveV2LeverageManagementSubDataWithoutSubProxy.encode(market, targetRatio, ratioState);
261
+ const subData = subDataService.aaveV2LeverageManagementSubData.encode(market, targetRatio, ratioState);
244
262
  const triggerData = triggerService.aaveV2RatioTrigger.encode(user, market, triggerRatio, ratioState);
245
263
 
246
264
  return [strategyOrBundleId, isBundle, triggerData, subData];
@@ -314,7 +332,7 @@ export const aaveV3Encode = {
314
332
 
315
333
  return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
316
334
  },
317
- leverageManagementWithoutSubProxy(
335
+ leverageManagement(
318
336
  strategyOrBundleId: number,
319
337
  market: EthereumAddress,
320
338
  user: EthereumAddress,
@@ -325,7 +343,7 @@ export const aaveV3Encode = {
325
343
  ) {
326
344
  const isBundle = true;
327
345
 
328
- const subData = subDataService.aaveV3LeverageManagementSubDataWithoutSubProxy.encode(
346
+ const subData = subDataService.aaveV3LeverageManagementSubData.encode(
329
347
  targetRatio,
330
348
  ratioState,
331
349
  market,
@@ -337,6 +355,28 @@ export const aaveV3Encode = {
337
355
  return [strategyOrBundleId, isBundle, triggerData, subData];
338
356
  },
339
357
 
358
+ liquidationProtection(
359
+ strategyOrBundleId: number,
360
+ market: EthereumAddress,
361
+ user: EthereumAddress,
362
+ ratioState: RatioState,
363
+ targetRatio: number,
364
+ triggerRatio: number,
365
+ ) {
366
+ const isBundle = true;
367
+
368
+ const subData = subDataService.aaveV3LiquidationProtectionSubData.encode(
369
+ targetRatio,
370
+ ratioState,
371
+ market,
372
+ user,
373
+ true, // isGeneric
374
+ );
375
+ const triggerData = triggerService.aaveV3RatioTrigger.encode(user, market, triggerRatio, ratioState);
376
+
377
+ return [strategyOrBundleId, isBundle, triggerData, subData];
378
+ },
379
+
340
380
  leverageManagementOnPriceGeneric(
341
381
  strategyOrBundleId: number,
342
382
  price: number,
@@ -408,7 +448,7 @@ export const aaveV3Encode = {
408
448
  };
409
449
 
410
450
  export const compoundV2Encode = {
411
- leverageManagementWithoutSubProxy(
451
+ leverageManagement(
412
452
  strategyOrBundleId: number,
413
453
  user: EthereumAddress,
414
454
  ratioState: RatioState,
@@ -417,7 +457,7 @@ export const compoundV2Encode = {
417
457
  ) {
418
458
  const isBundle = true;
419
459
 
420
- const subData = subDataService.compoundV2LeverageManagementSubDataWithoutSubProxy.encode(targetRatio, ratioState);
460
+ const subData = subDataService.compoundV2LeverageManagementSubData.encode(targetRatio, ratioState);
421
461
  const triggerData = triggerService.compoundV2RatioTrigger.encode(user, triggerRatio, ratioState);
422
462
 
423
463
  return [strategyOrBundleId, isBundle, triggerData, subData];
@@ -425,7 +465,24 @@ export const compoundV2Encode = {
425
465
  };
426
466
 
427
467
  export const compoundV3Encode = {
428
- leverageManagementWithoutSubProxy(
468
+ leverageManagement(
469
+ strategyOrBundleId: number,
470
+ market: EthereumAddress,
471
+ baseToken: EthereumAddress,
472
+ user: EthereumAddress,
473
+ ratioState: RatioState,
474
+ targetRatio: number,
475
+ triggerRatio: number,
476
+ ) {
477
+ const isBundle = true;
478
+
479
+ const subData = subDataService.compoundV3LeverageManagementSubData.encode(market, baseToken, targetRatio, ratioState);
480
+ const triggerData = triggerService.compoundV3RatioTrigger.encode(user, market, triggerRatio, ratioState);
481
+
482
+ return [strategyOrBundleId, isBundle, triggerData, subData];
483
+ },
484
+
485
+ liquidationProtection(
429
486
  strategyOrBundleId: number,
430
487
  market: EthereumAddress,
431
488
  baseToken: EthereumAddress,
@@ -436,11 +493,12 @@ export const compoundV3Encode = {
436
493
  ) {
437
494
  const isBundle = true;
438
495
 
439
- const subData = subDataService.compoundV3LeverageManagementSubDataWithoutSubProxy.encode(market, baseToken, targetRatio, ratioState);
496
+ const subData = subDataService.compoundV3LiquidationProtectionSubData.encode(market, baseToken, targetRatio, ratioState);
440
497
  const triggerData = triggerService.compoundV3RatioTrigger.encode(user, market, triggerRatio, ratioState);
441
498
 
442
499
  return [strategyOrBundleId, isBundle, triggerData, subData];
443
500
  },
501
+
444
502
  leverageManagementOnPrice(
445
503
  strategyOrBundleId: number,
446
504
  market: EthereumAddress,
@@ -479,18 +537,6 @@ export const compoundV3Encode = {
479
537
  },
480
538
  };
481
539
 
482
- export const morphoAaveV2Encode = {
483
- leverageManagement(
484
- triggerRepayRatio: number,
485
- triggerBoostRatio: number,
486
- targetBoostRatio: number,
487
- targetRepayRatio: number,
488
- boostEnabled: boolean,
489
- ) {
490
- return subDataService.morphoAaveV2LeverageManagementSubData.encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled);
491
- },
492
- };
493
-
494
540
  export const exchangeEncode = {
495
541
  dca(
496
542
  fromToken: EthereumAddress,
@@ -508,7 +554,7 @@ export const exchangeEncode = {
508
554
 
509
555
  return [strategyId, false, triggerData, subData];
510
556
  },
511
- limitOrderWithoutSubProxy(
557
+ limitOrder(
512
558
  fromToken: EthereumAddress,
513
559
  toToken: EthereumAddress,
514
560
  amount: string,
@@ -520,7 +566,7 @@ export const exchangeEncode = {
520
566
  network: ChainId,
521
567
  ) {
522
568
  requireAddresses([fromToken, toToken]);
523
- const subData = subDataService.exchangeLimitOrderSubDataWithoutSubProxy.encode(fromToken, toToken, amount);
569
+ const subData = subDataService.exchangeLimitOrderSubData.encode(fromToken, toToken, amount);
524
570
  const triggerData = triggerService.exchangeOffchainPriceTrigger.encode(targetPrice, Number(goodUntil), orderType, fromTokenDecimals, toTokenDecimals);
525
571
 
526
572
  const strategyId = STRATEGY_IDS[network].EXCHANGE_LIMIT_ORDER;
@@ -573,7 +619,7 @@ export const sparkEncode = {
573
619
 
574
620
  return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
575
621
  },
576
- leverageManagementWithoutSubProxy(
622
+ leverageManagement(
577
623
  strategyOrBundleId: number,
578
624
  market: EthereumAddress,
579
625
  user: EthereumAddress,
@@ -583,7 +629,7 @@ export const sparkEncode = {
583
629
  ) {
584
630
  const isBundle = true;
585
631
 
586
- const subData = subDataService.sparkLeverageManagementSubDataWithoutSubProxy.encode(
632
+ const subData = subDataService.sparkLeverageManagementSubData.encode(
587
633
  targetRatio,
588
634
  ratioState,
589
635
  );
@@ -591,6 +637,26 @@ export const sparkEncode = {
591
637
 
592
638
  return [strategyOrBundleId, isBundle, triggerData, subData];
593
639
  },
640
+
641
+ liquidationProtection(
642
+ strategyOrBundleId: number,
643
+ market: EthereumAddress,
644
+ user: EthereumAddress,
645
+ ratioState: RatioState,
646
+ targetRatio: number,
647
+ triggerRatio: number,
648
+ ) {
649
+ const isBundle = true;
650
+
651
+ const subData = subDataService.sparkLiquidationProtectionSubData.encode(
652
+ targetRatio,
653
+ ratioState,
654
+ );
655
+ const triggerData = triggerService.sparkRatioTrigger.encode(user, market, triggerRatio, ratioState);
656
+
657
+ return [strategyOrBundleId, isBundle, triggerData, subData];
658
+ },
659
+
594
660
  collateralSwitch(
595
661
  strategyOrBundleId: number,
596
662
  fromAsset: EthereumAddress,
@@ -687,6 +753,35 @@ export const morphoBlueEncode = {
687
753
 
688
754
  return [strategyOrBundleId, isBundle, triggerData, subData];
689
755
  },
756
+
757
+ liquidationProtection(
758
+ marketId: string,
759
+ loanToken: EthereumAddress,
760
+ collToken: EthereumAddress,
761
+ oracle: EthereumAddress,
762
+ irm: EthereumAddress,
763
+ lltv: string,
764
+ ratioState: RatioState,
765
+ targetRatio: number,
766
+ triggerRatio: number,
767
+ user: EthereumAddress,
768
+ isEOA: boolean,
769
+ network: ChainId,
770
+ ) {
771
+ const subData = subDataService.morphoBlueLiquidationProtectionSubData.encode(loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, user, isEOA);
772
+
773
+ const triggerData = triggerService.morphoBlueRatioTrigger.encode(marketId, user, triggerRatio, ratioState);
774
+
775
+
776
+ // Type casting because there is no MORPHO_BLUE_EOA_LIQUIDATION_PROTECTION for Base chain.
777
+ // That is fine because we will just always send isEOA == false for Base chain.
778
+ const bundleNetwork = getBundleIdsByNetwork(network) as typeof Bundles.MainnetIds;
779
+ const bundleId = isEOA ? bundleNetwork.MORPHO_BLUE_EOA_LIQUIDATION_PROTECTION : bundleNetwork.MORPHO_BLUE_SW_LIQUIDATION_PROTECTION;
780
+ const isBundle = true;
781
+
782
+ return [bundleId, isBundle, triggerData, subData];
783
+ },
784
+
690
785
  leverageManagementOnPrice(
691
786
  strategyOrBundleId: number,
692
787
  isBundle: boolean = true,
@@ -815,6 +910,22 @@ export const fluidEncode = {
815
910
 
816
911
  return [strategyOrBundleId, isBundle, triggerData, subData];
817
912
  },
913
+
914
+ liquidationProtection(
915
+ nftId: string,
916
+ vault: EthereumAddress,
917
+ ratioState: RatioState,
918
+ targetRatio: number,
919
+ triggerRatio: number,
920
+ strategyOrBundleId: number,
921
+ ) {
922
+ const isBundle = true;
923
+ const subData = subDataService.fluidLiquidationProtectionSubData.encode(nftId, vault, ratioState, targetRatio);
924
+ const triggerData = triggerService.fluidRatioTrigger.encode(nftId, triggerRatio, ratioState);
925
+
926
+ return [strategyOrBundleId, isBundle, triggerData, subData];
927
+ },
928
+
818
929
  };
819
930
 
820
931
  export const aaveV4Encode = {
@@ -832,6 +943,22 @@ export const aaveV4Encode = {
832
943
 
833
944
  return [strategyOrBundleId, isBundle, triggerData, subData];
834
945
  },
946
+
947
+ liquidationProtection(
948
+ strategyOrBundleId: number,
949
+ owner: EthereumAddress,
950
+ spoke: EthereumAddress,
951
+ ratioState: RatioState,
952
+ targetRatio: number,
953
+ triggerRatio: number,
954
+ ) {
955
+ const isBundle = true;
956
+ const subData = subDataService.aaveV4LiquidationProtectionSubData.encode(spoke, owner, ratioState, targetRatio);
957
+ const triggerData = triggerService.aaveV4RatioTrigger.encode(owner, spoke, triggerRatio, ratioState);
958
+
959
+ return [strategyOrBundleId, isBundle, triggerData, subData];
960
+ },
961
+
835
962
  leverageManagementOnPrice(
836
963
  strategyOrBundleId: number,
837
964
  owner: EthereumAddress,