@defisaver/automation-sdk 3.3.16 → 3.3.17-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.
- package/cjs/constants/index.js +190 -0
- package/cjs/index.d.ts +2 -2
- package/cjs/index.js +5 -2
- package/cjs/services/strategiesService.js +169 -12
- package/cjs/services/strategySubService.d.ts +22 -17
- package/cjs/services/strategySubService.js +115 -38
- package/cjs/services/strategySubService.test.js +111 -41
- package/cjs/services/subDataService.d.ts +70 -20
- package/cjs/services/subDataService.js +23 -79
- package/cjs/services/subDataService.test.js +17 -202
- package/cjs/types/enums.d.ts +48 -6
- package/cjs/types/enums.js +42 -0
- package/esm/constants/index.js +190 -0
- package/esm/index.d.ts +2 -2
- package/esm/index.js +5 -2
- package/esm/services/strategiesService.js +169 -12
- package/esm/services/strategySubService.d.ts +22 -17
- package/esm/services/strategySubService.js +113 -37
- package/esm/services/strategySubService.test.js +112 -39
- package/esm/services/subDataService.d.ts +70 -20
- package/esm/services/subDataService.js +21 -77
- package/esm/services/subDataService.test.js +18 -200
- package/esm/types/enums.d.ts +48 -6
- package/esm/types/enums.js +42 -0
- package/package.json +1 -1
- package/src/constants/index.ts +192 -1
- package/src/index.ts +22 -6
- package/src/services/strategiesService.ts +234 -12
- package/src/services/strategySubService.test.ts +147 -47
- package/src/services/strategySubService.ts +246 -47
- package/src/services/subDataService.test.ts +18 -214
- package/src/services/subDataService.ts +42 -106
- package/src/services/utils.test.ts +1 -1
- package/src/services/utils.ts +3 -1
- package/src/types/enums.ts +42 -2
|
@@ -1,22 +1,25 @@
|
|
|
1
|
-
import Dec from 'decimal.js';
|
|
2
1
|
import { getAssetInfo } from '@defisaver/tokens';
|
|
2
|
+
import Dec from 'decimal.js';
|
|
3
3
|
|
|
4
|
-
import
|
|
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 {
|
|
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,
|
|
19
|
+
compareAddresses,
|
|
20
|
+
getCloseStrategyType,
|
|
21
|
+
requireAddress,
|
|
22
|
+
requireAddresses,
|
|
20
23
|
} from './utils';
|
|
21
24
|
|
|
22
25
|
export const makerEncode = {
|
|
@@ -81,7 +84,7 @@ export const makerEncode = {
|
|
|
81
84
|
|
|
82
85
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
83
86
|
},
|
|
84
|
-
|
|
87
|
+
leverageManagement(
|
|
85
88
|
vaultId: number,
|
|
86
89
|
triggerRatio: number,
|
|
87
90
|
targetRatio: number,
|
|
@@ -93,7 +96,27 @@ export const makerEncode = {
|
|
|
93
96
|
|
|
94
97
|
const triggerData = triggerService.makerRatioTrigger.encode(vaultId, triggerRatio, ratioState);
|
|
95
98
|
|
|
96
|
-
const subData = subDataService.
|
|
99
|
+
const subData = subDataService.makerLeverageManagementSubData.encode(vaultId, targetRatio, daiAddr);
|
|
100
|
+
|
|
101
|
+
return [
|
|
102
|
+
bundleId,
|
|
103
|
+
true,
|
|
104
|
+
triggerData,
|
|
105
|
+
subData,
|
|
106
|
+
];
|
|
107
|
+
},
|
|
108
|
+
|
|
109
|
+
liquidationProtection(
|
|
110
|
+
vaultId: number,
|
|
111
|
+
triggerRatio: number,
|
|
112
|
+
targetRatio: number,
|
|
113
|
+
ratioState: RatioState,
|
|
114
|
+
daiAddr?: EthereumAddress,
|
|
115
|
+
) {
|
|
116
|
+
const bundleId = Bundles.MainnetIds.MAKER_SW_LIQUIDATION_PROTECTION;
|
|
117
|
+
|
|
118
|
+
const triggerData = triggerService.makerRatioTrigger.encode(vaultId, triggerRatio, ratioState);
|
|
119
|
+
const subData = subDataService.makerLiquidationProtectionSubData.encode(vaultId, targetRatio, daiAddr);
|
|
97
120
|
|
|
98
121
|
return [
|
|
99
122
|
bundleId,
|
|
@@ -162,7 +185,7 @@ export const liquityEncode = {
|
|
|
162
185
|
|
|
163
186
|
return [strategyId, isBundle, triggerData, subData];
|
|
164
187
|
},
|
|
165
|
-
|
|
188
|
+
leverageManagement(
|
|
166
189
|
strategyOrBundleId: number,
|
|
167
190
|
user: EthereumAddress,
|
|
168
191
|
ratioState: RatioState,
|
|
@@ -171,7 +194,7 @@ export const liquityEncode = {
|
|
|
171
194
|
) {
|
|
172
195
|
const isBundle = true;
|
|
173
196
|
|
|
174
|
-
const subData = subDataService.
|
|
197
|
+
const subData = subDataService.liquityLeverageManagementSubData.encode(targetRatio, ratioState);
|
|
175
198
|
const triggerData = triggerService.liquityRatioTrigger.encode(user, triggerRatio, ratioState);
|
|
176
199
|
|
|
177
200
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
@@ -223,14 +246,8 @@ export const liquityEncode = {
|
|
|
223
246
|
},
|
|
224
247
|
};
|
|
225
248
|
|
|
226
|
-
export const chickenBondsEncode = {
|
|
227
|
-
rebond(bondId: number) {
|
|
228
|
-
return subDataService.cBondsRebondSubData.encode(bondId);
|
|
229
|
-
},
|
|
230
|
-
};
|
|
231
|
-
|
|
232
249
|
export const aaveV2Encode = {
|
|
233
|
-
|
|
250
|
+
leverageManagement(
|
|
234
251
|
strategyOrBundleId: number,
|
|
235
252
|
market: EthereumAddress,
|
|
236
253
|
user: EthereumAddress,
|
|
@@ -240,7 +257,7 @@ export const aaveV2Encode = {
|
|
|
240
257
|
) {
|
|
241
258
|
const isBundle = true;
|
|
242
259
|
|
|
243
|
-
const subData = subDataService.
|
|
260
|
+
const subData = subDataService.aaveV2LeverageManagementSubData.encode(market, targetRatio, ratioState);
|
|
244
261
|
const triggerData = triggerService.aaveV2RatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
245
262
|
|
|
246
263
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
@@ -314,7 +331,7 @@ export const aaveV3Encode = {
|
|
|
314
331
|
|
|
315
332
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
316
333
|
},
|
|
317
|
-
|
|
334
|
+
leverageManagement(
|
|
318
335
|
strategyOrBundleId: number,
|
|
319
336
|
market: EthereumAddress,
|
|
320
337
|
user: EthereumAddress,
|
|
@@ -325,7 +342,7 @@ export const aaveV3Encode = {
|
|
|
325
342
|
) {
|
|
326
343
|
const isBundle = true;
|
|
327
344
|
|
|
328
|
-
const subData = subDataService.
|
|
345
|
+
const subData = subDataService.aaveV3LeverageManagementSubData.encode(
|
|
329
346
|
targetRatio,
|
|
330
347
|
ratioState,
|
|
331
348
|
market,
|
|
@@ -337,6 +354,28 @@ export const aaveV3Encode = {
|
|
|
337
354
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
338
355
|
},
|
|
339
356
|
|
|
357
|
+
liquidationProtection(
|
|
358
|
+
strategyOrBundleId: number,
|
|
359
|
+
market: EthereumAddress,
|
|
360
|
+
user: EthereumAddress,
|
|
361
|
+
ratioState: RatioState,
|
|
362
|
+
targetRatio: number,
|
|
363
|
+
triggerRatio: number,
|
|
364
|
+
) {
|
|
365
|
+
const isBundle = true;
|
|
366
|
+
|
|
367
|
+
const subData = subDataService.aaveV3LiquidationProtectionSubData.encode(
|
|
368
|
+
targetRatio,
|
|
369
|
+
ratioState,
|
|
370
|
+
market,
|
|
371
|
+
user,
|
|
372
|
+
true, // isGeneric
|
|
373
|
+
);
|
|
374
|
+
const triggerData = triggerService.aaveV3RatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
375
|
+
|
|
376
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
377
|
+
},
|
|
378
|
+
|
|
340
379
|
leverageManagementOnPriceGeneric(
|
|
341
380
|
strategyOrBundleId: number,
|
|
342
381
|
price: number,
|
|
@@ -408,7 +447,7 @@ export const aaveV3Encode = {
|
|
|
408
447
|
};
|
|
409
448
|
|
|
410
449
|
export const compoundV2Encode = {
|
|
411
|
-
|
|
450
|
+
leverageManagement(
|
|
412
451
|
strategyOrBundleId: number,
|
|
413
452
|
user: EthereumAddress,
|
|
414
453
|
ratioState: RatioState,
|
|
@@ -417,7 +456,7 @@ export const compoundV2Encode = {
|
|
|
417
456
|
) {
|
|
418
457
|
const isBundle = true;
|
|
419
458
|
|
|
420
|
-
const subData = subDataService.
|
|
459
|
+
const subData = subDataService.compoundV2LeverageManagementSubData.encode(targetRatio, ratioState);
|
|
421
460
|
const triggerData = triggerService.compoundV2RatioTrigger.encode(user, triggerRatio, ratioState);
|
|
422
461
|
|
|
423
462
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
@@ -425,7 +464,24 @@ export const compoundV2Encode = {
|
|
|
425
464
|
};
|
|
426
465
|
|
|
427
466
|
export const compoundV3Encode = {
|
|
428
|
-
|
|
467
|
+
leverageManagement(
|
|
468
|
+
strategyOrBundleId: number,
|
|
469
|
+
market: EthereumAddress,
|
|
470
|
+
baseToken: EthereumAddress,
|
|
471
|
+
user: EthereumAddress,
|
|
472
|
+
ratioState: RatioState,
|
|
473
|
+
targetRatio: number,
|
|
474
|
+
triggerRatio: number,
|
|
475
|
+
) {
|
|
476
|
+
const isBundle = true;
|
|
477
|
+
|
|
478
|
+
const subData = subDataService.compoundV3LeverageManagementSubData.encode(market, baseToken, targetRatio, ratioState);
|
|
479
|
+
const triggerData = triggerService.compoundV3RatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
480
|
+
|
|
481
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
482
|
+
},
|
|
483
|
+
|
|
484
|
+
liquidationProtection(
|
|
429
485
|
strategyOrBundleId: number,
|
|
430
486
|
market: EthereumAddress,
|
|
431
487
|
baseToken: EthereumAddress,
|
|
@@ -436,11 +492,12 @@ export const compoundV3Encode = {
|
|
|
436
492
|
) {
|
|
437
493
|
const isBundle = true;
|
|
438
494
|
|
|
439
|
-
const subData = subDataService.
|
|
495
|
+
const subData = subDataService.compoundV3LiquidationProtectionSubData.encode(market, baseToken, targetRatio, ratioState);
|
|
440
496
|
const triggerData = triggerService.compoundV3RatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
441
497
|
|
|
442
498
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
443
499
|
},
|
|
500
|
+
|
|
444
501
|
leverageManagementOnPrice(
|
|
445
502
|
strategyOrBundleId: number,
|
|
446
503
|
market: EthereumAddress,
|
|
@@ -479,18 +536,6 @@ export const compoundV3Encode = {
|
|
|
479
536
|
},
|
|
480
537
|
};
|
|
481
538
|
|
|
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
539
|
export const exchangeEncode = {
|
|
495
540
|
dca(
|
|
496
541
|
fromToken: EthereumAddress,
|
|
@@ -508,7 +553,7 @@ export const exchangeEncode = {
|
|
|
508
553
|
|
|
509
554
|
return [strategyId, false, triggerData, subData];
|
|
510
555
|
},
|
|
511
|
-
|
|
556
|
+
limitOrder(
|
|
512
557
|
fromToken: EthereumAddress,
|
|
513
558
|
toToken: EthereumAddress,
|
|
514
559
|
amount: string,
|
|
@@ -520,7 +565,7 @@ export const exchangeEncode = {
|
|
|
520
565
|
network: ChainId,
|
|
521
566
|
) {
|
|
522
567
|
requireAddresses([fromToken, toToken]);
|
|
523
|
-
const subData = subDataService.
|
|
568
|
+
const subData = subDataService.exchangeLimitOrderSubData.encode(fromToken, toToken, amount);
|
|
524
569
|
const triggerData = triggerService.exchangeOffchainPriceTrigger.encode(targetPrice, Number(goodUntil), orderType, fromTokenDecimals, toTokenDecimals);
|
|
525
570
|
|
|
526
571
|
const strategyId = STRATEGY_IDS[network].EXCHANGE_LIMIT_ORDER;
|
|
@@ -573,7 +618,26 @@ export const sparkEncode = {
|
|
|
573
618
|
|
|
574
619
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
575
620
|
},
|
|
576
|
-
|
|
621
|
+
leverageManagement(
|
|
622
|
+
strategyOrBundleId: number,
|
|
623
|
+
market: EthereumAddress,
|
|
624
|
+
user: EthereumAddress,
|
|
625
|
+
ratioState: RatioState,
|
|
626
|
+
targetRatio: number,
|
|
627
|
+
triggerRatio: number,
|
|
628
|
+
) {
|
|
629
|
+
const isBundle = true;
|
|
630
|
+
|
|
631
|
+
const subData = subDataService.sparkLeverageManagementSubData.encode(
|
|
632
|
+
targetRatio,
|
|
633
|
+
ratioState,
|
|
634
|
+
);
|
|
635
|
+
const triggerData = triggerService.sparkRatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
636
|
+
|
|
637
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
638
|
+
},
|
|
639
|
+
|
|
640
|
+
liquidationProtection(
|
|
577
641
|
strategyOrBundleId: number,
|
|
578
642
|
market: EthereumAddress,
|
|
579
643
|
user: EthereumAddress,
|
|
@@ -583,7 +647,7 @@ export const sparkEncode = {
|
|
|
583
647
|
) {
|
|
584
648
|
const isBundle = true;
|
|
585
649
|
|
|
586
|
-
const subData = subDataService.
|
|
650
|
+
const subData = subDataService.sparkLiquidationProtectionSubData.encode(
|
|
587
651
|
targetRatio,
|
|
588
652
|
ratioState,
|
|
589
653
|
);
|
|
@@ -591,6 +655,7 @@ export const sparkEncode = {
|
|
|
591
655
|
|
|
592
656
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
593
657
|
},
|
|
658
|
+
|
|
594
659
|
collateralSwitch(
|
|
595
660
|
strategyOrBundleId: number,
|
|
596
661
|
fromAsset: EthereumAddress,
|
|
@@ -652,6 +717,46 @@ export const crvUSDEncode = {
|
|
|
652
717
|
},
|
|
653
718
|
};
|
|
654
719
|
|
|
720
|
+
export type MorphoBlueBundleStrategy = 'repay' | 'boost' | 'repayOnPrice' | 'boostOnPrice' | 'close' | 'liquidationProtection';
|
|
721
|
+
|
|
722
|
+
function getMorphoBlueBundlesIds(network: ChainId) {
|
|
723
|
+
switch (network) {
|
|
724
|
+
case ChainId.Ethereum:
|
|
725
|
+
return Bundles.MainnetIds;
|
|
726
|
+
case ChainId.Base:
|
|
727
|
+
return Bundles.BaseIds;
|
|
728
|
+
case ChainId.Arbitrum:
|
|
729
|
+
return Bundles.ArbitrumIds;
|
|
730
|
+
default:
|
|
731
|
+
throw new Error(`Morpho Blue strategies are not supported on chain ${network}`);
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
export function getMorphoBlueBundleId(
|
|
736
|
+
network: ChainId,
|
|
737
|
+
strategy: MorphoBlueBundleStrategy,
|
|
738
|
+
isEOA: boolean,
|
|
739
|
+
): number {
|
|
740
|
+
const bundlesIds = getMorphoBlueBundlesIds(network);
|
|
741
|
+
|
|
742
|
+
switch (strategy) {
|
|
743
|
+
case 'repay':
|
|
744
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_REPAY : bundlesIds.MORPHO_BLUE_REPAY;
|
|
745
|
+
case 'boost':
|
|
746
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_BOOST : bundlesIds.MORPHO_BLUE_BOOST;
|
|
747
|
+
case 'repayOnPrice':
|
|
748
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_REPAY_ON_PRICE : bundlesIds.MORPHO_BLUE_REPAY_ON_PRICE;
|
|
749
|
+
case 'boostOnPrice':
|
|
750
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_BOOST_ON_PRICE : bundlesIds.MORPHO_BLUE_BOOST_ON_PRICE;
|
|
751
|
+
case 'close':
|
|
752
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_CLOSE : bundlesIds.MORPHO_BLUE_CLOSE;
|
|
753
|
+
case 'liquidationProtection':
|
|
754
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_LIQUIDATION_PROTECTION : bundlesIds.MORPHO_BLUE_SW_LIQUIDATION_PROTECTION;
|
|
755
|
+
default:
|
|
756
|
+
throw new Error(`Unknown Morpho Blue strategy: ${strategy}`);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
|
|
655
760
|
export const morphoBlueEncode = {
|
|
656
761
|
leverageManagement(
|
|
657
762
|
marketId: string,
|
|
@@ -673,20 +778,36 @@ export const morphoBlueEncode = {
|
|
|
673
778
|
|
|
674
779
|
// over is boost, under is repay
|
|
675
780
|
const isBoost = ratioState === RatioState.OVER;
|
|
676
|
-
|
|
781
|
+
const bundleId = getMorphoBlueBundleId(network, isBoost ? 'boost' : 'repay', isEOA);
|
|
782
|
+
const isBundle = true;
|
|
783
|
+
|
|
784
|
+
return [bundleId, isBundle, triggerData, subData];
|
|
785
|
+
},
|
|
677
786
|
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
787
|
+
liquidationProtection(
|
|
788
|
+
marketId: string,
|
|
789
|
+
loanToken: EthereumAddress,
|
|
790
|
+
collToken: EthereumAddress,
|
|
791
|
+
oracle: EthereumAddress,
|
|
792
|
+
irm: EthereumAddress,
|
|
793
|
+
lltv: string,
|
|
794
|
+
ratioState: RatioState,
|
|
795
|
+
targetRatio: number,
|
|
796
|
+
triggerRatio: number,
|
|
797
|
+
user: EthereumAddress,
|
|
798
|
+
isEOA: boolean,
|
|
799
|
+
network: ChainId,
|
|
800
|
+
) {
|
|
801
|
+
const subData = subDataService.morphoBlueLiquidationProtectionSubData.encode(loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, user, isEOA);
|
|
681
802
|
|
|
682
|
-
const
|
|
803
|
+
const triggerData = triggerService.morphoBlueRatioTrigger.encode(marketId, user, triggerRatio, ratioState);
|
|
683
804
|
|
|
684
|
-
|
|
685
|
-
else strategyOrBundleId = isEOA ? bundlesIds.MORPHO_BLUE_EOA_REPAY : bundlesIds.MORPHO_BLUE_REPAY;
|
|
805
|
+
const bundleId = getMorphoBlueBundleId(network, 'liquidationProtection', isEOA);
|
|
686
806
|
const isBundle = true;
|
|
687
807
|
|
|
688
|
-
return [
|
|
808
|
+
return [bundleId, isBundle, triggerData, subData];
|
|
689
809
|
},
|
|
810
|
+
|
|
690
811
|
leverageManagementOnPrice(
|
|
691
812
|
strategyOrBundleId: number,
|
|
692
813
|
isBundle: boolean = true,
|
|
@@ -704,6 +825,28 @@ export const morphoBlueEncode = {
|
|
|
704
825
|
const triggerData = triggerService.morphoBluePriceTrigger.encode(oracle, collToken, loanToken, price, priceState);
|
|
705
826
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
706
827
|
},
|
|
828
|
+
leverageManagementOnPriceGeneric(
|
|
829
|
+
loanToken: EthereumAddress,
|
|
830
|
+
collToken: EthereumAddress,
|
|
831
|
+
oracle: EthereumAddress,
|
|
832
|
+
irm: EthereumAddress,
|
|
833
|
+
lltv: string,
|
|
834
|
+
user: EthereumAddress,
|
|
835
|
+
targetRatio: number,
|
|
836
|
+
price: number,
|
|
837
|
+
priceState: RatioState,
|
|
838
|
+
isBoost: boolean,
|
|
839
|
+
isEOA: boolean,
|
|
840
|
+
network: ChainId,
|
|
841
|
+
) {
|
|
842
|
+
const subData = subDataService.morphoBlueLeverageManagementOnPriceSubData.encode(loanToken, collToken, oracle, irm, lltv, targetRatio, user);
|
|
843
|
+
const triggerData = triggerService.morphoBluePriceTrigger.encode(oracle, collToken, loanToken, price, priceState);
|
|
844
|
+
|
|
845
|
+
const bundleId = getMorphoBlueBundleId(network, isBoost ? 'boostOnPrice' : 'repayOnPrice', isEOA);
|
|
846
|
+
const isBundle = true;
|
|
847
|
+
|
|
848
|
+
return [bundleId, isBundle, triggerData, subData];
|
|
849
|
+
},
|
|
707
850
|
closeOnPrice(
|
|
708
851
|
strategyOrBundleId: number,
|
|
709
852
|
loanToken: EthereumAddress,
|
|
@@ -725,6 +868,30 @@ export const morphoBlueEncode = {
|
|
|
725
868
|
|
|
726
869
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
727
870
|
},
|
|
871
|
+
closeOnPriceGeneric(
|
|
872
|
+
loanToken: EthereumAddress,
|
|
873
|
+
collToken: EthereumAddress,
|
|
874
|
+
oracle: EthereumAddress,
|
|
875
|
+
irm: EthereumAddress,
|
|
876
|
+
lltv: string,
|
|
877
|
+
user: EthereumAddress,
|
|
878
|
+
stopLossPrice: number = 0,
|
|
879
|
+
stopLossType: CloseToAssetType = CloseToAssetType.DEBT,
|
|
880
|
+
takeProfitPrice: number = 0,
|
|
881
|
+
takeProfitType: CloseToAssetType = CloseToAssetType.COLLATERAL,
|
|
882
|
+
isEOA: boolean,
|
|
883
|
+
network: ChainId,
|
|
884
|
+
) {
|
|
885
|
+
const isBundle = true;
|
|
886
|
+
const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
887
|
+
|
|
888
|
+
const subDataEncoded = subDataService.morphoBlueCloseOnPriceSubData.encode(loanToken, collToken, oracle, irm, lltv, user, closeType);
|
|
889
|
+
const triggerDataEncoded = triggerService.morphoBluePriceRangeTrigger.encode(oracle, collToken, loanToken, stopLossPrice, takeProfitPrice);
|
|
890
|
+
|
|
891
|
+
const bundleId = getMorphoBlueBundleId(network, 'close', isEOA);
|
|
892
|
+
|
|
893
|
+
return [bundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
894
|
+
},
|
|
728
895
|
};
|
|
729
896
|
|
|
730
897
|
export const liquityV2Encode = {
|
|
@@ -815,6 +982,22 @@ export const fluidEncode = {
|
|
|
815
982
|
|
|
816
983
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
817
984
|
},
|
|
985
|
+
|
|
986
|
+
liquidationProtection(
|
|
987
|
+
nftId: string,
|
|
988
|
+
vault: EthereumAddress,
|
|
989
|
+
ratioState: RatioState,
|
|
990
|
+
targetRatio: number,
|
|
991
|
+
triggerRatio: number,
|
|
992
|
+
strategyOrBundleId: number,
|
|
993
|
+
) {
|
|
994
|
+
const isBundle = true;
|
|
995
|
+
const subData = subDataService.fluidLiquidationProtectionSubData.encode(nftId, vault, ratioState, targetRatio);
|
|
996
|
+
const triggerData = triggerService.fluidRatioTrigger.encode(nftId, triggerRatio, ratioState);
|
|
997
|
+
|
|
998
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
999
|
+
},
|
|
1000
|
+
|
|
818
1001
|
};
|
|
819
1002
|
|
|
820
1003
|
export const aaveV4Encode = {
|
|
@@ -832,6 +1015,22 @@ export const aaveV4Encode = {
|
|
|
832
1015
|
|
|
833
1016
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
834
1017
|
},
|
|
1018
|
+
|
|
1019
|
+
liquidationProtection(
|
|
1020
|
+
strategyOrBundleId: number,
|
|
1021
|
+
owner: EthereumAddress,
|
|
1022
|
+
spoke: EthereumAddress,
|
|
1023
|
+
ratioState: RatioState,
|
|
1024
|
+
targetRatio: number,
|
|
1025
|
+
triggerRatio: number,
|
|
1026
|
+
) {
|
|
1027
|
+
const isBundle = true;
|
|
1028
|
+
const subData = subDataService.aaveV4LiquidationProtectionSubData.encode(spoke, owner, ratioState, targetRatio);
|
|
1029
|
+
const triggerData = triggerService.aaveV4RatioTrigger.encode(owner, spoke, triggerRatio, ratioState);
|
|
1030
|
+
|
|
1031
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
1032
|
+
},
|
|
1033
|
+
|
|
835
1034
|
leverageManagementOnPrice(
|
|
836
1035
|
strategyOrBundleId: number,
|
|
837
1036
|
owner: EthereumAddress,
|