@defisaver/automation-sdk 3.3.16-liq-prot-dev → 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.
- package/cjs/constants/index.js +42 -117
- package/cjs/index.d.ts +2 -2
- package/cjs/index.js +2 -5
- package/cjs/services/strategiesService.js +21 -160
- package/cjs/services/strategySubService.d.ts +21 -18
- package/cjs/services/strategySubService.js +74 -78
- package/cjs/services/strategySubService.test.js +149 -3
- package/cjs/services/subDataService.d.ts +20 -70
- package/cjs/services/subDataService.js +79 -23
- package/cjs/services/subDataService.test.js +202 -17
- package/cjs/services/utils.d.ts +1 -2
- package/cjs/services/utils.js +1 -14
- package/cjs/types/enums.d.ts +17 -36
- package/cjs/types/enums.js +11 -30
- package/esm/constants/index.js +42 -117
- package/esm/index.d.ts +2 -2
- package/esm/index.js +2 -5
- package/esm/services/strategiesService.js +21 -160
- package/esm/services/strategySubService.d.ts +21 -18
- package/esm/services/strategySubService.js +73 -78
- package/esm/services/strategySubService.test.js +147 -4
- package/esm/services/subDataService.d.ts +20 -70
- package/esm/services/subDataService.js +77 -21
- package/esm/services/subDataService.test.js +200 -18
- package/esm/services/utils.d.ts +1 -2
- package/esm/services/utils.js +1 -13
- package/esm/types/enums.d.ts +17 -36
- package/esm/types/enums.js +11 -30
- package/package.json +1 -1
- package/src/constants/index.ts +43 -119
- package/src/index.ts +6 -22
- package/src/services/strategiesService.ts +23 -225
- package/src/services/strategySubService.test.ts +191 -3
- package/src/services/strategySubService.ts +121 -173
- package/src/services/subDataService.test.ts +214 -18
- package/src/services/subDataService.ts +106 -42
- package/src/services/utils.test.ts +1 -1
- package/src/services/utils.ts +1 -15
- package/src/types/enums.ts +13 -30
|
@@ -1,26 +1,22 @@
|
|
|
1
|
-
import { getAssetInfo } from '@defisaver/tokens';
|
|
2
1
|
import Dec from 'decimal.js';
|
|
2
|
+
import { getAssetInfo } from '@defisaver/tokens';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import type { OrderType } from '../types/enums';
|
|
5
5
|
import {
|
|
6
|
+
CloseToAssetType,
|
|
6
7
|
Bundles,
|
|
7
8
|
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 { STRATEGY_IDS } from '../constants';
|
|
15
15
|
|
|
16
16
|
import * as subDataService from './subDataService';
|
|
17
17
|
import * as triggerService from './triggerService';
|
|
18
18
|
import {
|
|
19
|
-
compareAddresses,
|
|
20
|
-
getBundleIdsByNetwork,
|
|
21
|
-
getCloseStrategyType,
|
|
22
|
-
requireAddress,
|
|
23
|
-
requireAddresses,
|
|
19
|
+
compareAddresses, getCloseStrategyType, requireAddress, requireAddresses,
|
|
24
20
|
} from './utils';
|
|
25
21
|
|
|
26
22
|
export const makerEncode = {
|
|
@@ -85,7 +81,7 @@ export const makerEncode = {
|
|
|
85
81
|
|
|
86
82
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
87
83
|
},
|
|
88
|
-
|
|
84
|
+
leverageManagementWithoutSubProxy(
|
|
89
85
|
vaultId: number,
|
|
90
86
|
triggerRatio: number,
|
|
91
87
|
targetRatio: number,
|
|
@@ -97,27 +93,7 @@ export const makerEncode = {
|
|
|
97
93
|
|
|
98
94
|
const triggerData = triggerService.makerRatioTrigger.encode(vaultId, triggerRatio, ratioState);
|
|
99
95
|
|
|
100
|
-
const subData = subDataService.
|
|
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);
|
|
96
|
+
const subData = subDataService.makerLeverageManagementWithoutSubProxy.encode(vaultId, targetRatio, daiAddr);
|
|
121
97
|
|
|
122
98
|
return [
|
|
123
99
|
bundleId,
|
|
@@ -186,7 +162,7 @@ export const liquityEncode = {
|
|
|
186
162
|
|
|
187
163
|
return [strategyId, isBundle, triggerData, subData];
|
|
188
164
|
},
|
|
189
|
-
|
|
165
|
+
leverageManagementWithoutSubProxy(
|
|
190
166
|
strategyOrBundleId: number,
|
|
191
167
|
user: EthereumAddress,
|
|
192
168
|
ratioState: RatioState,
|
|
@@ -195,7 +171,7 @@ export const liquityEncode = {
|
|
|
195
171
|
) {
|
|
196
172
|
const isBundle = true;
|
|
197
173
|
|
|
198
|
-
const subData = subDataService.
|
|
174
|
+
const subData = subDataService.liquityLeverageManagementSubDataWithoutSubProxy.encode(targetRatio, ratioState);
|
|
199
175
|
const triggerData = triggerService.liquityRatioTrigger.encode(user, triggerRatio, ratioState);
|
|
200
176
|
|
|
201
177
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
@@ -247,8 +223,14 @@ export const liquityEncode = {
|
|
|
247
223
|
},
|
|
248
224
|
};
|
|
249
225
|
|
|
226
|
+
export const chickenBondsEncode = {
|
|
227
|
+
rebond(bondId: number) {
|
|
228
|
+
return subDataService.cBondsRebondSubData.encode(bondId);
|
|
229
|
+
},
|
|
230
|
+
};
|
|
231
|
+
|
|
250
232
|
export const aaveV2Encode = {
|
|
251
|
-
|
|
233
|
+
leverageManagementWithoutSubProxy(
|
|
252
234
|
strategyOrBundleId: number,
|
|
253
235
|
market: EthereumAddress,
|
|
254
236
|
user: EthereumAddress,
|
|
@@ -258,7 +240,7 @@ export const aaveV2Encode = {
|
|
|
258
240
|
) {
|
|
259
241
|
const isBundle = true;
|
|
260
242
|
|
|
261
|
-
const subData = subDataService.
|
|
243
|
+
const subData = subDataService.aaveV2LeverageManagementSubDataWithoutSubProxy.encode(market, targetRatio, ratioState);
|
|
262
244
|
const triggerData = triggerService.aaveV2RatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
263
245
|
|
|
264
246
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
@@ -332,7 +314,7 @@ export const aaveV3Encode = {
|
|
|
332
314
|
|
|
333
315
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
334
316
|
},
|
|
335
|
-
|
|
317
|
+
leverageManagementWithoutSubProxy(
|
|
336
318
|
strategyOrBundleId: number,
|
|
337
319
|
market: EthereumAddress,
|
|
338
320
|
user: EthereumAddress,
|
|
@@ -343,7 +325,7 @@ export const aaveV3Encode = {
|
|
|
343
325
|
) {
|
|
344
326
|
const isBundle = true;
|
|
345
327
|
|
|
346
|
-
const subData = subDataService.
|
|
328
|
+
const subData = subDataService.aaveV3LeverageManagementSubDataWithoutSubProxy.encode(
|
|
347
329
|
targetRatio,
|
|
348
330
|
ratioState,
|
|
349
331
|
market,
|
|
@@ -355,28 +337,6 @@ export const aaveV3Encode = {
|
|
|
355
337
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
356
338
|
},
|
|
357
339
|
|
|
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
|
-
|
|
380
340
|
leverageManagementOnPriceGeneric(
|
|
381
341
|
strategyOrBundleId: number,
|
|
382
342
|
price: number,
|
|
@@ -448,7 +408,7 @@ export const aaveV3Encode = {
|
|
|
448
408
|
};
|
|
449
409
|
|
|
450
410
|
export const compoundV2Encode = {
|
|
451
|
-
|
|
411
|
+
leverageManagementWithoutSubProxy(
|
|
452
412
|
strategyOrBundleId: number,
|
|
453
413
|
user: EthereumAddress,
|
|
454
414
|
ratioState: RatioState,
|
|
@@ -457,7 +417,7 @@ export const compoundV2Encode = {
|
|
|
457
417
|
) {
|
|
458
418
|
const isBundle = true;
|
|
459
419
|
|
|
460
|
-
const subData = subDataService.
|
|
420
|
+
const subData = subDataService.compoundV2LeverageManagementSubDataWithoutSubProxy.encode(targetRatio, ratioState);
|
|
461
421
|
const triggerData = triggerService.compoundV2RatioTrigger.encode(user, triggerRatio, ratioState);
|
|
462
422
|
|
|
463
423
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
@@ -465,24 +425,7 @@ export const compoundV2Encode = {
|
|
|
465
425
|
};
|
|
466
426
|
|
|
467
427
|
export const compoundV3Encode = {
|
|
468
|
-
|
|
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(
|
|
428
|
+
leverageManagementWithoutSubProxy(
|
|
486
429
|
strategyOrBundleId: number,
|
|
487
430
|
market: EthereumAddress,
|
|
488
431
|
baseToken: EthereumAddress,
|
|
@@ -493,12 +436,11 @@ export const compoundV3Encode = {
|
|
|
493
436
|
) {
|
|
494
437
|
const isBundle = true;
|
|
495
438
|
|
|
496
|
-
const subData = subDataService.
|
|
439
|
+
const subData = subDataService.compoundV3LeverageManagementSubDataWithoutSubProxy.encode(market, baseToken, targetRatio, ratioState);
|
|
497
440
|
const triggerData = triggerService.compoundV3RatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
498
441
|
|
|
499
442
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
500
443
|
},
|
|
501
|
-
|
|
502
444
|
leverageManagementOnPrice(
|
|
503
445
|
strategyOrBundleId: number,
|
|
504
446
|
market: EthereumAddress,
|
|
@@ -537,6 +479,18 @@ export const compoundV3Encode = {
|
|
|
537
479
|
},
|
|
538
480
|
};
|
|
539
481
|
|
|
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
|
+
|
|
540
494
|
export const exchangeEncode = {
|
|
541
495
|
dca(
|
|
542
496
|
fromToken: EthereumAddress,
|
|
@@ -554,7 +508,7 @@ export const exchangeEncode = {
|
|
|
554
508
|
|
|
555
509
|
return [strategyId, false, triggerData, subData];
|
|
556
510
|
},
|
|
557
|
-
|
|
511
|
+
limitOrderWithoutSubProxy(
|
|
558
512
|
fromToken: EthereumAddress,
|
|
559
513
|
toToken: EthereumAddress,
|
|
560
514
|
amount: string,
|
|
@@ -566,7 +520,7 @@ export const exchangeEncode = {
|
|
|
566
520
|
network: ChainId,
|
|
567
521
|
) {
|
|
568
522
|
requireAddresses([fromToken, toToken]);
|
|
569
|
-
const subData = subDataService.
|
|
523
|
+
const subData = subDataService.exchangeLimitOrderSubDataWithoutSubProxy.encode(fromToken, toToken, amount);
|
|
570
524
|
const triggerData = triggerService.exchangeOffchainPriceTrigger.encode(targetPrice, Number(goodUntil), orderType, fromTokenDecimals, toTokenDecimals);
|
|
571
525
|
|
|
572
526
|
const strategyId = STRATEGY_IDS[network].EXCHANGE_LIMIT_ORDER;
|
|
@@ -619,26 +573,7 @@ export const sparkEncode = {
|
|
|
619
573
|
|
|
620
574
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
621
575
|
},
|
|
622
|
-
|
|
623
|
-
strategyOrBundleId: number,
|
|
624
|
-
market: EthereumAddress,
|
|
625
|
-
user: EthereumAddress,
|
|
626
|
-
ratioState: RatioState,
|
|
627
|
-
targetRatio: number,
|
|
628
|
-
triggerRatio: number,
|
|
629
|
-
) {
|
|
630
|
-
const isBundle = true;
|
|
631
|
-
|
|
632
|
-
const subData = subDataService.sparkLeverageManagementSubData.encode(
|
|
633
|
-
targetRatio,
|
|
634
|
-
ratioState,
|
|
635
|
-
);
|
|
636
|
-
const triggerData = triggerService.sparkRatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
637
|
-
|
|
638
|
-
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
639
|
-
},
|
|
640
|
-
|
|
641
|
-
liquidationProtection(
|
|
576
|
+
leverageManagementWithoutSubProxy(
|
|
642
577
|
strategyOrBundleId: number,
|
|
643
578
|
market: EthereumAddress,
|
|
644
579
|
user: EthereumAddress,
|
|
@@ -648,7 +583,7 @@ export const sparkEncode = {
|
|
|
648
583
|
) {
|
|
649
584
|
const isBundle = true;
|
|
650
585
|
|
|
651
|
-
const subData = subDataService.
|
|
586
|
+
const subData = subDataService.sparkLeverageManagementSubDataWithoutSubProxy.encode(
|
|
652
587
|
targetRatio,
|
|
653
588
|
ratioState,
|
|
654
589
|
);
|
|
@@ -656,7 +591,6 @@ export const sparkEncode = {
|
|
|
656
591
|
|
|
657
592
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
658
593
|
},
|
|
659
|
-
|
|
660
594
|
collateralSwitch(
|
|
661
595
|
strategyOrBundleId: number,
|
|
662
596
|
fromAsset: EthereumAddress,
|
|
@@ -718,6 +652,44 @@ export const crvUSDEncode = {
|
|
|
718
652
|
},
|
|
719
653
|
};
|
|
720
654
|
|
|
655
|
+
export type MorphoBlueBundleStrategy = 'repay' | 'boost' | 'repayOnPrice' | 'boostOnPrice' | 'close';
|
|
656
|
+
|
|
657
|
+
function getMorphoBlueBundlesIds(network: ChainId) {
|
|
658
|
+
switch (network) {
|
|
659
|
+
case ChainId.Ethereum:
|
|
660
|
+
return Bundles.MainnetIds;
|
|
661
|
+
case ChainId.Base:
|
|
662
|
+
return Bundles.BaseIds;
|
|
663
|
+
case ChainId.Arbitrum:
|
|
664
|
+
return Bundles.ArbitrumIds;
|
|
665
|
+
default:
|
|
666
|
+
throw new Error(`Morpho Blue strategies are not supported on chain ${network}`);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
export function getMorphoBlueBundleId(
|
|
671
|
+
network: ChainId,
|
|
672
|
+
strategy: MorphoBlueBundleStrategy,
|
|
673
|
+
isEOA: boolean,
|
|
674
|
+
): number {
|
|
675
|
+
const bundlesIds = getMorphoBlueBundlesIds(network);
|
|
676
|
+
|
|
677
|
+
switch (strategy) {
|
|
678
|
+
case 'repay':
|
|
679
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_REPAY : bundlesIds.MORPHO_BLUE_REPAY;
|
|
680
|
+
case 'boost':
|
|
681
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_BOOST : bundlesIds.MORPHO_BLUE_BOOST;
|
|
682
|
+
case 'repayOnPrice':
|
|
683
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_REPAY_ON_PRICE : bundlesIds.MORPHO_BLUE_REPAY_ON_PRICE;
|
|
684
|
+
case 'boostOnPrice':
|
|
685
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_BOOST_ON_PRICE : bundlesIds.MORPHO_BLUE_BOOST_ON_PRICE;
|
|
686
|
+
case 'close':
|
|
687
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_CLOSE : bundlesIds.MORPHO_BLUE_CLOSE;
|
|
688
|
+
default:
|
|
689
|
+
throw new Error(`Unknown Morpho Blue strategy: ${strategy}`);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
|
|
721
693
|
export const morphoBlueEncode = {
|
|
722
694
|
leverageManagement(
|
|
723
695
|
marketId: string,
|
|
@@ -739,52 +711,29 @@ export const morphoBlueEncode = {
|
|
|
739
711
|
|
|
740
712
|
// over is boost, under is repay
|
|
741
713
|
const isBoost = ratioState === RatioState.OVER;
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
if (network === ChainId.Base) {
|
|
745
|
-
return [isBoost ? Bundles.BaseIds.MORPHO_BLUE_BOOST : Bundles.BaseIds.MORPHO_BLUE_REPAY, true, triggerData, subData];
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
const bundlesIds = network === ChainId.Arbitrum ? Bundles.ArbitrumIds : Bundles.MainnetIds;
|
|
749
|
-
|
|
750
|
-
if (isBoost) strategyOrBundleId = isEOA ? bundlesIds.MORPHO_BLUE_EOA_BOOST : bundlesIds.MORPHO_BLUE_BOOST;
|
|
751
|
-
else strategyOrBundleId = isEOA ? bundlesIds.MORPHO_BLUE_EOA_REPAY : bundlesIds.MORPHO_BLUE_REPAY;
|
|
714
|
+
const bundleId = getMorphoBlueBundleId(network, isBoost ? 'boost' : 'repay', isEOA);
|
|
752
715
|
const isBundle = true;
|
|
753
716
|
|
|
754
|
-
return [
|
|
717
|
+
return [bundleId, isBundle, triggerData, subData];
|
|
755
718
|
},
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
719
|
+
leverageManagementOnPrice(
|
|
720
|
+
strategyOrBundleId: number,
|
|
721
|
+
isBundle: boolean = true,
|
|
759
722
|
loanToken: EthereumAddress,
|
|
760
723
|
collToken: EthereumAddress,
|
|
761
724
|
oracle: EthereumAddress,
|
|
762
725
|
irm: EthereumAddress,
|
|
763
726
|
lltv: string,
|
|
764
|
-
ratioState: RatioState,
|
|
765
|
-
targetRatio: number,
|
|
766
|
-
triggerRatio: number,
|
|
767
727
|
user: EthereumAddress,
|
|
768
|
-
|
|
769
|
-
|
|
728
|
+
targetRatio: number,
|
|
729
|
+
price: number,
|
|
730
|
+
priceState: RatioState,
|
|
770
731
|
) {
|
|
771
|
-
const subData = subDataService.
|
|
772
|
-
|
|
773
|
-
|
|
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];
|
|
732
|
+
const subData = subDataService.morphoBlueLeverageManagementOnPriceSubData.encode(loanToken, collToken, oracle, irm, lltv, targetRatio, user);
|
|
733
|
+
const triggerData = triggerService.morphoBluePriceTrigger.encode(oracle, collToken, loanToken, price, priceState);
|
|
734
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
783
735
|
},
|
|
784
|
-
|
|
785
|
-
leverageManagementOnPrice(
|
|
786
|
-
strategyOrBundleId: number,
|
|
787
|
-
isBundle: boolean = true,
|
|
736
|
+
leverageManagementOnPriceGeneric(
|
|
788
737
|
loanToken: EthereumAddress,
|
|
789
738
|
collToken: EthereumAddress,
|
|
790
739
|
oracle: EthereumAddress,
|
|
@@ -794,10 +743,17 @@ export const morphoBlueEncode = {
|
|
|
794
743
|
targetRatio: number,
|
|
795
744
|
price: number,
|
|
796
745
|
priceState: RatioState,
|
|
746
|
+
isBoost: boolean,
|
|
747
|
+
isEOA: boolean,
|
|
748
|
+
network: ChainId,
|
|
797
749
|
) {
|
|
798
750
|
const subData = subDataService.morphoBlueLeverageManagementOnPriceSubData.encode(loanToken, collToken, oracle, irm, lltv, targetRatio, user);
|
|
799
751
|
const triggerData = triggerService.morphoBluePriceTrigger.encode(oracle, collToken, loanToken, price, priceState);
|
|
800
|
-
|
|
752
|
+
|
|
753
|
+
const bundleId = getMorphoBlueBundleId(network, isBoost ? 'boostOnPrice' : 'repayOnPrice', isEOA);
|
|
754
|
+
const isBundle = true;
|
|
755
|
+
|
|
756
|
+
return [bundleId, isBundle, triggerData, subData];
|
|
801
757
|
},
|
|
802
758
|
closeOnPrice(
|
|
803
759
|
strategyOrBundleId: number,
|
|
@@ -820,6 +776,30 @@ export const morphoBlueEncode = {
|
|
|
820
776
|
|
|
821
777
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
822
778
|
},
|
|
779
|
+
closeOnPriceGeneric(
|
|
780
|
+
loanToken: EthereumAddress,
|
|
781
|
+
collToken: EthereumAddress,
|
|
782
|
+
oracle: EthereumAddress,
|
|
783
|
+
irm: EthereumAddress,
|
|
784
|
+
lltv: string,
|
|
785
|
+
user: EthereumAddress,
|
|
786
|
+
stopLossPrice: number = 0,
|
|
787
|
+
stopLossType: CloseToAssetType = CloseToAssetType.DEBT,
|
|
788
|
+
takeProfitPrice: number = 0,
|
|
789
|
+
takeProfitType: CloseToAssetType = CloseToAssetType.COLLATERAL,
|
|
790
|
+
isEOA: boolean,
|
|
791
|
+
network: ChainId,
|
|
792
|
+
) {
|
|
793
|
+
const isBundle = true;
|
|
794
|
+
const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
795
|
+
|
|
796
|
+
const subDataEncoded = subDataService.morphoBlueCloseOnPriceSubData.encode(loanToken, collToken, oracle, irm, lltv, user, closeType);
|
|
797
|
+
const triggerDataEncoded = triggerService.morphoBluePriceRangeTrigger.encode(oracle, collToken, loanToken, stopLossPrice, takeProfitPrice);
|
|
798
|
+
|
|
799
|
+
const bundleId = getMorphoBlueBundleId(network, 'close', isEOA);
|
|
800
|
+
|
|
801
|
+
return [bundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
802
|
+
},
|
|
823
803
|
};
|
|
824
804
|
|
|
825
805
|
export const liquityV2Encode = {
|
|
@@ -910,22 +890,6 @@ export const fluidEncode = {
|
|
|
910
890
|
|
|
911
891
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
912
892
|
},
|
|
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
|
-
|
|
929
893
|
};
|
|
930
894
|
|
|
931
895
|
export const aaveV4Encode = {
|
|
@@ -943,22 +907,6 @@ export const aaveV4Encode = {
|
|
|
943
907
|
|
|
944
908
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
945
909
|
},
|
|
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
|
-
|
|
962
910
|
leverageManagementOnPrice(
|
|
963
911
|
strategyOrBundleId: number,
|
|
964
912
|
owner: EthereumAddress,
|