@defisaver/automation-sdk 3.3.13-strategies-refactor-dev → 3.3.14
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/services/strategiesService.js +17 -30
- package/cjs/services/strategySubService.d.ts +11 -5
- package/cjs/services/strategySubService.js +62 -27
- package/cjs/services/strategySubService.test.js +234 -0
- package/cjs/services/subDataService.d.ts +2 -35
- package/cjs/services/subDataService.js +20 -84
- package/cjs/services/subDataService.test.js +42 -0
- package/esm/services/strategiesService.js +17 -30
- package/esm/services/strategySubService.d.ts +11 -5
- package/esm/services/strategySubService.js +58 -26
- package/esm/services/strategySubService.test.js +236 -2
- package/esm/services/subDataService.d.ts +2 -35
- package/esm/services/subDataService.js +19 -82
- package/esm/services/subDataService.test.js +42 -0
- package/package.json +1 -1
- package/src/services/strategiesService.ts +17 -30
- package/src/services/strategySubService.test.ts +279 -0
- package/src/services/strategySubService.ts +111 -60
- package/src/services/subDataService.test.ts +48 -0
- package/src/services/subDataService.ts +28 -107
|
@@ -63,7 +63,7 @@ function parseMakerTrailingStop(position, parseData) {
|
|
|
63
63
|
}
|
|
64
64
|
function parseMakerLeverageManagement(position, parseData) {
|
|
65
65
|
const _position = cloneDeep(position);
|
|
66
|
-
const { subStruct, subId
|
|
66
|
+
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
67
67
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
68
68
|
const triggerData = triggerService.makerRatioTrigger.decode(subStruct.triggerData);
|
|
69
69
|
const subData = subDataService.makerLeverageManagementSubData.decode(subStruct.subData);
|
|
@@ -75,10 +75,9 @@ function parseMakerLeverageManagement(position, parseData) {
|
|
|
75
75
|
_position.specific = {
|
|
76
76
|
triggerRepayRatio: triggerData.ratio,
|
|
77
77
|
targetRepayRatio: subData.targetRatio,
|
|
78
|
-
repayEnabled:
|
|
78
|
+
repayEnabled: true,
|
|
79
79
|
subId1: Number(subId),
|
|
80
80
|
mergeWithId: Strategies.Identifiers.Boost,
|
|
81
|
-
subHashRepay: subHash,
|
|
82
81
|
};
|
|
83
82
|
}
|
|
84
83
|
else {
|
|
@@ -88,7 +87,6 @@ function parseMakerLeverageManagement(position, parseData) {
|
|
|
88
87
|
boostEnabled: isEnabled,
|
|
89
88
|
subId2: Number(subId),
|
|
90
89
|
mergeId: Strategies.Identifiers.Boost,
|
|
91
|
-
subHashBoost: subHash,
|
|
92
90
|
};
|
|
93
91
|
}
|
|
94
92
|
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
@@ -128,7 +126,7 @@ function parseLiquityTrailingStop(position, parseData) {
|
|
|
128
126
|
}
|
|
129
127
|
function parseAaveV2LeverageManagement(position, parseData) {
|
|
130
128
|
const _position = cloneDeep(position);
|
|
131
|
-
const { subStruct, subId
|
|
129
|
+
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
132
130
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
133
131
|
const triggerData = triggerService.aaveV2RatioTrigger.decode(subStruct.triggerData);
|
|
134
132
|
const subData = subDataService.aaveV2LeverageManagementSubData.decode(subStruct.subData);
|
|
@@ -140,10 +138,9 @@ function parseAaveV2LeverageManagement(position, parseData) {
|
|
|
140
138
|
_position.specific = {
|
|
141
139
|
triggerRepayRatio: triggerData.ratio,
|
|
142
140
|
targetRepayRatio: subData.targetRatio,
|
|
143
|
-
repayEnabled:
|
|
141
|
+
repayEnabled: true,
|
|
144
142
|
subId1: Number(subId),
|
|
145
143
|
mergeWithId: Strategies.Identifiers.Boost,
|
|
146
|
-
subHashRepay: subHash,
|
|
147
144
|
};
|
|
148
145
|
}
|
|
149
146
|
else {
|
|
@@ -153,7 +150,6 @@ function parseAaveV2LeverageManagement(position, parseData) {
|
|
|
153
150
|
boostEnabled: isEnabled,
|
|
154
151
|
subId2: Number(subId),
|
|
155
152
|
mergeId: Strategies.Identifiers.Boost,
|
|
156
|
-
subHashBoost: subHash,
|
|
157
153
|
};
|
|
158
154
|
}
|
|
159
155
|
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
@@ -391,7 +387,7 @@ function parseAaveV4CollateralSwitch(position, parseData) {
|
|
|
391
387
|
}
|
|
392
388
|
function parseMorphoAaveV2LeverageManagement(position, parseData) {
|
|
393
389
|
const _position = cloneDeep(position);
|
|
394
|
-
const { subStruct, subId
|
|
390
|
+
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
395
391
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
396
392
|
const triggerData = triggerService.morphoAaveV2RatioTrigger.decode(subStruct.triggerData);
|
|
397
393
|
const subData = subDataService.morphoAaveV2LeverageManagementSubData.decode(subStruct.subData);
|
|
@@ -403,10 +399,9 @@ function parseMorphoAaveV2LeverageManagement(position, parseData) {
|
|
|
403
399
|
_position.specific = {
|
|
404
400
|
triggerRepayRatio: triggerData.ratio,
|
|
405
401
|
targetRepayRatio: subData.targetRatio,
|
|
406
|
-
repayEnabled:
|
|
402
|
+
repayEnabled: true,
|
|
407
403
|
subId1: Number(subId),
|
|
408
404
|
mergeWithId: Strategies.Identifiers.Boost,
|
|
409
|
-
subHashRepay: subHash,
|
|
410
405
|
};
|
|
411
406
|
}
|
|
412
407
|
else {
|
|
@@ -416,7 +411,6 @@ function parseMorphoAaveV2LeverageManagement(position, parseData) {
|
|
|
416
411
|
boostEnabled: isEnabled,
|
|
417
412
|
subId2: Number(subId),
|
|
418
413
|
mergeId: Strategies.Identifiers.Boost,
|
|
419
|
-
subHashBoost: subHash,
|
|
420
414
|
};
|
|
421
415
|
}
|
|
422
416
|
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
@@ -449,7 +443,7 @@ function parseAaveV3CloseOnPriceWithMaximumGasPrice(position, parseData) {
|
|
|
449
443
|
}
|
|
450
444
|
function parseCompoundV2LeverageManagement(position, parseData) {
|
|
451
445
|
const _position = cloneDeep(position);
|
|
452
|
-
const { subStruct, subId
|
|
446
|
+
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
453
447
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
454
448
|
const triggerData = triggerService.compoundV2RatioTrigger.decode(subStruct.triggerData);
|
|
455
449
|
const subData = subDataService.compoundV2LeverageManagementSubData.decode(subStruct.subData);
|
|
@@ -462,10 +456,9 @@ function parseCompoundV2LeverageManagement(position, parseData) {
|
|
|
462
456
|
_position.specific = {
|
|
463
457
|
triggerRepayRatio: triggerData.ratio,
|
|
464
458
|
targetRepayRatio: subData.targetRatio,
|
|
465
|
-
repayEnabled:
|
|
459
|
+
repayEnabled: true,
|
|
466
460
|
subId1: Number(subId),
|
|
467
461
|
mergeWithId: Strategies.Identifiers.Boost,
|
|
468
|
-
subHashRepay: subHash,
|
|
469
462
|
};
|
|
470
463
|
}
|
|
471
464
|
else {
|
|
@@ -475,7 +468,6 @@ function parseCompoundV2LeverageManagement(position, parseData) {
|
|
|
475
468
|
boostEnabled: isEnabled,
|
|
476
469
|
subId2: Number(subId),
|
|
477
470
|
mergeId: Strategies.Identifiers.Boost,
|
|
478
|
-
subHashBoost: subHash,
|
|
479
471
|
};
|
|
480
472
|
}
|
|
481
473
|
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
@@ -484,9 +476,11 @@ function parseCompoundV2LeverageManagement(position, parseData) {
|
|
|
484
476
|
}
|
|
485
477
|
function parseCompoundV3LeverageManagement(position, parseData) {
|
|
486
478
|
const _position = cloneDeep(position);
|
|
487
|
-
const { subStruct, subId
|
|
479
|
+
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
488
480
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
489
|
-
const subDataDecoder =
|
|
481
|
+
const subDataDecoder = position.chainId !== 1
|
|
482
|
+
? subDataService.compoundV3L2LeverageManagementSubData
|
|
483
|
+
: subDataService.compoundV3LeverageManagementSubData;
|
|
490
484
|
const triggerData = triggerService.compoundV3RatioTrigger.decode(subStruct.triggerData);
|
|
491
485
|
const subData = subDataDecoder.decode(subStruct.subData);
|
|
492
486
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
@@ -498,10 +492,9 @@ function parseCompoundV3LeverageManagement(position, parseData) {
|
|
|
498
492
|
_position.specific = {
|
|
499
493
|
triggerRepayRatio: triggerData.ratio,
|
|
500
494
|
targetRepayRatio: subData.targetRatio,
|
|
501
|
-
repayEnabled:
|
|
495
|
+
repayEnabled: true,
|
|
502
496
|
subId1: Number(subId),
|
|
503
497
|
mergeWithId: isEOA ? Strategies.Identifiers.EoaBoost : Strategies.Identifiers.Boost,
|
|
504
|
-
subHashRepay: subHash,
|
|
505
498
|
};
|
|
506
499
|
}
|
|
507
500
|
else {
|
|
@@ -511,7 +504,6 @@ function parseCompoundV3LeverageManagement(position, parseData) {
|
|
|
511
504
|
boostEnabled: isEnabled,
|
|
512
505
|
subId2: Number(subId),
|
|
513
506
|
mergeId: isEOA ? Strategies.Identifiers.EoaBoost : Strategies.Identifiers.Boost,
|
|
514
|
-
subHashBoost: subHash,
|
|
515
507
|
};
|
|
516
508
|
}
|
|
517
509
|
_position.strategy.strategyId = isEOA ? Strategies.IdOverrides.EoaLeverageManagement : Strategies.IdOverrides.LeverageManagement;
|
|
@@ -599,7 +591,7 @@ function parseExchangeLimitOrder(position, parseData, chainId) {
|
|
|
599
591
|
}
|
|
600
592
|
function parseLiquityLeverageManagement(position, parseData) {
|
|
601
593
|
const _position = cloneDeep(position);
|
|
602
|
-
const { subStruct, subId
|
|
594
|
+
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
603
595
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
604
596
|
const triggerData = triggerService.liquityRatioTrigger.decode(subStruct.triggerData);
|
|
605
597
|
const subData = subDataService.liquityLeverageManagementSubData.decode(subStruct.subData);
|
|
@@ -611,10 +603,9 @@ function parseLiquityLeverageManagement(position, parseData) {
|
|
|
611
603
|
_position.specific = {
|
|
612
604
|
triggerRepayRatio: triggerData.ratio,
|
|
613
605
|
targetRepayRatio: subData.targetRatio,
|
|
614
|
-
repayEnabled:
|
|
606
|
+
repayEnabled: true,
|
|
615
607
|
subId1: Number(subId),
|
|
616
608
|
mergeWithId: Strategies.Identifiers.Boost,
|
|
617
|
-
subHashRepay: subHash,
|
|
618
609
|
};
|
|
619
610
|
}
|
|
620
611
|
else {
|
|
@@ -624,7 +615,6 @@ function parseLiquityLeverageManagement(position, parseData) {
|
|
|
624
615
|
boostEnabled: isEnabled,
|
|
625
616
|
subId2: Number(subId),
|
|
626
617
|
mergeId: Strategies.Identifiers.Boost,
|
|
627
|
-
subHashBoost: subHash,
|
|
628
618
|
};
|
|
629
619
|
}
|
|
630
620
|
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
@@ -665,7 +655,7 @@ function parseLiquityV2LeverageManagement(position, parseData) {
|
|
|
665
655
|
}
|
|
666
656
|
function parseSparkLeverageManagement(position, parseData) {
|
|
667
657
|
const _position = cloneDeep(position);
|
|
668
|
-
const { subStruct, subId
|
|
658
|
+
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
669
659
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
670
660
|
const triggerData = triggerService.sparkRatioTrigger.decode(subStruct.triggerData);
|
|
671
661
|
const subData = subDataService.sparkLeverageManagementSubData.decode(subStruct.subData);
|
|
@@ -677,10 +667,9 @@ function parseSparkLeverageManagement(position, parseData) {
|
|
|
677
667
|
_position.specific = {
|
|
678
668
|
triggerRepayRatio: triggerData.ratio,
|
|
679
669
|
targetRepayRatio: subData.targetRatio,
|
|
680
|
-
repayEnabled:
|
|
670
|
+
repayEnabled: true,
|
|
681
671
|
subId1: Number(subId),
|
|
682
672
|
mergeWithId: Strategies.Identifiers.Boost,
|
|
683
|
-
subHashRepay: subHash,
|
|
684
673
|
};
|
|
685
674
|
}
|
|
686
675
|
else {
|
|
@@ -690,7 +679,6 @@ function parseSparkLeverageManagement(position, parseData) {
|
|
|
690
679
|
boostEnabled: isEnabled,
|
|
691
680
|
subId2: Number(subId),
|
|
692
681
|
mergeId: Strategies.Identifiers.Boost,
|
|
693
|
-
subHashBoost: subHash,
|
|
694
682
|
};
|
|
695
683
|
}
|
|
696
684
|
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
@@ -873,7 +861,6 @@ function parseMorphoBlueLeverageManagementOnPrice(position, parseData) {
|
|
|
873
861
|
debtAsset: subData.loanToken,
|
|
874
862
|
price: triggerData.price,
|
|
875
863
|
ratio: subData.targetRatio,
|
|
876
|
-
ratioState: triggerData.priceState,
|
|
877
864
|
};
|
|
878
865
|
return _position;
|
|
879
866
|
}
|
|
@@ -5,13 +5,14 @@ export declare const makerEncode: {
|
|
|
5
5
|
repayFromSavings(bundleId: StrategyOrBundleIds, vaultId: number, triggerRepayRatio: number, targetRepayRatio: number, isBundle?: boolean, chainId?: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress): (boolean | string[] | Strategies.MainnetIds | Strategies.OptimismIds | Strategies.ArbitrumIds | Strategies.BaseIds | Bundles.MainnetIds | Bundles.OptimismIds | Bundles.ArbitrumIds | Bundles.BaseIds)[];
|
|
6
6
|
closeOnPrice(vaultId: number, ratioState: RatioState, price: string, closeToAssetAddr: EthereumAddress, chainlinkCollAddress: EthereumAddress, chainId?: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress): (boolean | string[] | Strategies.MainnetIds)[];
|
|
7
7
|
trailingStop(vaultId: number, triggerPercentage: number, closeToAssetAddr: EthereumAddress, chainlinkCollAddress: EthereumAddress, roundId: number, chainId?: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress): (boolean | string[] | Strategies.MainnetIds)[];
|
|
8
|
+
leverageManagement(vaultId: number, triggerRepayRatio: string, triggerBoostRatio: string, targetBoostRatio: string, targetRepayRatio: string, boostEnabled: boolean): (string | number | boolean)[];
|
|
8
9
|
leverageManagementWithoutSubProxy(vaultId: number, triggerRatio: number, targetRatio: number, ratioState: RatioState, isBoost: boolean, daiAddr?: EthereumAddress): (boolean | string[] | Bundles.MainnetIds)[];
|
|
9
10
|
};
|
|
10
11
|
export declare const liquityEncode: {
|
|
11
12
|
closeOnPrice(priceOverOrUnder: RatioState, price: string, closeToAssetAddr: EthereumAddress, chainlinkCollAddress: EthereumAddress, chainId?: ChainId, collAddr?: EthereumAddress, debtAddr?: EthereumAddress): (boolean | string[] | Strategies.MainnetIds)[];
|
|
12
13
|
trailingStop(triggerPercentage: number, closeToAssetAddr: EthereumAddress, chainlinkCollAddress: EthereumAddress, roundId: number, chainId?: ChainId, collAddr?: EthereumAddress, debtAddr?: EthereumAddress): (boolean | string[] | Strategies.MainnetIds)[];
|
|
13
14
|
paybackFromChickenBondStrategySub(proxyAddress: EthereumAddress, ratio: number, sourceId: string, sourceType: number, ratioState?: RatioState): (boolean | string[] | Bundles.MainnetIds)[];
|
|
14
|
-
|
|
15
|
+
leverageManagement(triggerRepayRatio: string, triggerBoostRatio: string, targetBoostRatio: string, targetRepayRatio: string, boostEnabled: boolean): (string | boolean)[];
|
|
15
16
|
dsrPayback(proxyAddress: EthereumAddress, triggerRatio: number, targetRatio: number): (boolean | string[] | Strategies.MainnetIds)[];
|
|
16
17
|
dsrSupply(proxyAddress: EthereumAddress, triggerRatio: number, targetRatio: number): (boolean | string[] | Strategies.MainnetIds)[];
|
|
17
18
|
debtInFrontRepay(proxyAddress: EthereumAddress, debtInFrontMin: string, targetRatioIncrease: number): (boolean | string[] | Strategies.MainnetIds)[];
|
|
@@ -20,9 +21,10 @@ export declare const chickenBondsEncode: {
|
|
|
20
21
|
rebond(bondId: number): string[];
|
|
21
22
|
};
|
|
22
23
|
export declare const aaveV2Encode: {
|
|
23
|
-
|
|
24
|
+
leverageManagement(triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean): string[];
|
|
24
25
|
};
|
|
25
26
|
export declare const aaveV3Encode: {
|
|
27
|
+
leverageManagement(triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean): string;
|
|
26
28
|
closeToAsset(strategyOrBundleId: number, isBundle: boolean | undefined, triggerData: {
|
|
27
29
|
baseTokenAddress: EthereumAddress;
|
|
28
30
|
quoteTokenAddress: EthereumAddress;
|
|
@@ -65,21 +67,25 @@ export declare const aaveV3Encode: {
|
|
|
65
67
|
collateralSwitch(strategyOrBundleId: number, fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, state: RatioState): (number | boolean | string[])[];
|
|
66
68
|
};
|
|
67
69
|
export declare const compoundV2Encode: {
|
|
68
|
-
|
|
70
|
+
leverageManagement(triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean): string[];
|
|
69
71
|
};
|
|
70
72
|
export declare const compoundV3Encode: {
|
|
71
|
-
|
|
73
|
+
leverageManagement(market: EthereumAddress, baseToken: EthereumAddress, triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean, isEOA: boolean): string[];
|
|
72
74
|
leverageManagementOnPrice(strategyOrBundleId: number, market: EthereumAddress, collToken: EthereumAddress, baseToken: EthereumAddress, targetRatio: number, price: number, priceState: RatioState, ratioState: RatioState, user: EthereumAddress): (number | boolean | string[])[];
|
|
73
75
|
closeOnPrice(strategyOrBundleId: number, market: EthereumAddress, collToken: EthereumAddress, baseToken: EthereumAddress, stopLossPrice: number | undefined, stopLossType: CloseToAssetType | undefined, takeProfitPrice: number | undefined, takeProfitType: CloseToAssetType | undefined, user: EthereumAddress): (number | boolean | string[])[];
|
|
74
76
|
};
|
|
77
|
+
export declare const compoundV3L2Encode: {
|
|
78
|
+
leverageManagement(market: EthereumAddress, baseToken: EthereumAddress, triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean, isEOA?: boolean): string;
|
|
79
|
+
};
|
|
75
80
|
export declare const morphoAaveV2Encode: {
|
|
76
81
|
leverageManagement(triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean): string[];
|
|
77
82
|
};
|
|
78
83
|
export declare const exchangeEncode: {
|
|
79
84
|
dca(fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, timestamp: number, interval: number, network: ChainId): (boolean | string[] | Strategies.MainnetIds | Strategies.OptimismIds | Strategies.ArbitrumIds | Strategies.BaseIds)[];
|
|
80
|
-
|
|
85
|
+
limitOrder(fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, targetPrice: string, goodUntil: string | number, orderType: OrderType): string[];
|
|
81
86
|
};
|
|
82
87
|
export declare const sparkEncode: {
|
|
88
|
+
leverageManagement(triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean): string;
|
|
83
89
|
leverageManagementOnPrice(strategyOrBundleId: number, isBundle: boolean | undefined, triggerData: {
|
|
84
90
|
baseTokenAddr: EthereumAddress;
|
|
85
91
|
quoteTokenAddr: EthereumAddress;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import Dec from 'decimal.js';
|
|
1
2
|
import { getAssetInfo } from '@defisaver/tokens';
|
|
2
3
|
import { CloseToAssetType, Bundles, ChainId, RatioState, Strategies, } from '../types/enums';
|
|
3
4
|
import { STRATEGY_IDS } from '../constants';
|
|
@@ -30,6 +31,16 @@ export const makerEncode = {
|
|
|
30
31
|
const isBundle = false;
|
|
31
32
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
32
33
|
},
|
|
34
|
+
leverageManagement(vaultId, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
35
|
+
return [
|
|
36
|
+
vaultId,
|
|
37
|
+
new Dec(triggerRepayRatio).mul(1e16).toString(),
|
|
38
|
+
new Dec(triggerBoostRatio).mul(1e16).toString(),
|
|
39
|
+
new Dec(targetBoostRatio).mul(1e16).toString(),
|
|
40
|
+
new Dec(targetRepayRatio).mul(1e16).toString(),
|
|
41
|
+
boostEnabled,
|
|
42
|
+
];
|
|
43
|
+
},
|
|
33
44
|
leverageManagementWithoutSubProxy(vaultId, triggerRatio, targetRatio, ratioState, isBoost, daiAddr) {
|
|
34
45
|
const bundleId = isBoost ? Bundles.MainnetIds.MAKER_BOOST : Bundles.MainnetIds.MAKER_REPAY;
|
|
35
46
|
const triggerData = triggerService.makerRatioTrigger.encode(vaultId, triggerRatio, ratioState);
|
|
@@ -67,11 +78,14 @@ export const liquityEncode = {
|
|
|
67
78
|
const isBundle = true;
|
|
68
79
|
return [strategyId, isBundle, triggerData, subData];
|
|
69
80
|
},
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
81
|
+
leverageManagement(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
82
|
+
return [
|
|
83
|
+
new Dec(triggerRepayRatio).mul(1e16).toString(),
|
|
84
|
+
new Dec(triggerBoostRatio).mul(1e16).toString(),
|
|
85
|
+
new Dec(targetBoostRatio).mul(1e16).toString(),
|
|
86
|
+
new Dec(targetRepayRatio).mul(1e16).toString(),
|
|
87
|
+
boostEnabled,
|
|
88
|
+
];
|
|
75
89
|
},
|
|
76
90
|
dsrPayback(proxyAddress, triggerRatio, targetRatio) {
|
|
77
91
|
requireAddress(proxyAddress);
|
|
@@ -104,14 +118,24 @@ export const chickenBondsEncode = {
|
|
|
104
118
|
},
|
|
105
119
|
};
|
|
106
120
|
export const aaveV2Encode = {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const subData = subDataService.aaveV2LeverageManagementSubDataWithoutSubProxy.encode(market, targetRatio, ratioState);
|
|
110
|
-
const triggerData = triggerService.aaveV2RatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
111
|
-
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
121
|
+
leverageManagement(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
122
|
+
return subDataService.aaveV2LeverageManagementSubData.encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled);
|
|
112
123
|
},
|
|
113
124
|
};
|
|
114
125
|
export const aaveV3Encode = {
|
|
126
|
+
leverageManagement(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
127
|
+
let subInput = '0x';
|
|
128
|
+
subInput = subInput.concat(new Dec(triggerRepayRatio).mul(1e16).toHex().slice(2)
|
|
129
|
+
.padStart(32, '0'));
|
|
130
|
+
subInput = subInput.concat(new Dec(triggerBoostRatio).mul(1e16).toHex().slice(2)
|
|
131
|
+
.padStart(32, '0'));
|
|
132
|
+
subInput = subInput.concat(new Dec(targetBoostRatio).mul(1e16).toHex().slice(2)
|
|
133
|
+
.padStart(32, '0'));
|
|
134
|
+
subInput = subInput.concat(new Dec(targetRepayRatio).mul(1e16).toHex().slice(2)
|
|
135
|
+
.padStart(32, '0'));
|
|
136
|
+
subInput = subInput.concat(boostEnabled ? '01' : '00');
|
|
137
|
+
return subInput;
|
|
138
|
+
},
|
|
115
139
|
closeToAsset(strategyOrBundleId, isBundle = true, triggerData, subData) {
|
|
116
140
|
const { collAsset, collAssetId, debtAsset, debtAssetId, } = subData;
|
|
117
141
|
const subDataEncoded = subDataService.aaveV3QuotePriceSubData.encode(collAsset, collAssetId, debtAsset, debtAssetId);
|
|
@@ -160,19 +184,13 @@ export const aaveV3Encode = {
|
|
|
160
184
|
},
|
|
161
185
|
};
|
|
162
186
|
export const compoundV2Encode = {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const subData = subDataService.compoundV2LeverageManagementSubDataWithoutSubProxy.encode(targetRatio, ratioState);
|
|
166
|
-
const triggerData = triggerService.compoundV2RatioTrigger.encode(user, triggerRatio, ratioState);
|
|
167
|
-
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
187
|
+
leverageManagement(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
188
|
+
return subDataService.compoundV2LeverageManagementSubData.encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled);
|
|
168
189
|
},
|
|
169
190
|
};
|
|
170
191
|
export const compoundV3Encode = {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
const subData = subDataService.compoundV3LeverageManagementSubDataWithoutSubProxy.encode(market, baseToken, targetRatio, ratioState);
|
|
174
|
-
const triggerData = triggerService.compoundV3RatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
175
|
-
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
192
|
+
leverageManagement(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled, isEOA) {
|
|
193
|
+
return subDataService.compoundV3LeverageManagementSubData.encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled, isEOA);
|
|
176
194
|
},
|
|
177
195
|
leverageManagementOnPrice(strategyOrBundleId, market, collToken, baseToken, targetRatio, price, priceState, ratioState, // REPAY for repay on price, BOOST for boost on price
|
|
178
196
|
user) {
|
|
@@ -189,6 +207,11 @@ export const compoundV3Encode = {
|
|
|
189
207
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
190
208
|
},
|
|
191
209
|
};
|
|
210
|
+
export const compoundV3L2Encode = {
|
|
211
|
+
leverageManagement(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled, isEOA = false) {
|
|
212
|
+
return subDataService.compoundV3L2LeverageManagementSubData.encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled, isEOA);
|
|
213
|
+
},
|
|
214
|
+
};
|
|
192
215
|
export const morphoAaveV2Encode = {
|
|
193
216
|
leverageManagement(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
194
217
|
return subDataService.morphoAaveV2LeverageManagementSubData.encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled);
|
|
@@ -202,15 +225,24 @@ export const exchangeEncode = {
|
|
|
202
225
|
const strategyId = STRATEGY_IDS[network].EXCHANGE_DCA;
|
|
203
226
|
return [strategyId, false, triggerData, subData];
|
|
204
227
|
},
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
const subData = subDataService.exchangeLimitOrderSubDataWithoutSubProxy.encode(fromToken, toToken, amount);
|
|
208
|
-
const triggerData = triggerService.exchangeOffchainPriceTrigger.encode(targetPrice, Number(goodUntil), orderType, fromTokenDecimals, toTokenDecimals);
|
|
209
|
-
const strategyId = STRATEGY_IDS[network].EXCHANGE_LIMIT_ORDER;
|
|
210
|
-
return [strategyId, false, triggerData, subData];
|
|
228
|
+
limitOrder(fromToken, toToken, amount, targetPrice, goodUntil, orderType) {
|
|
229
|
+
return subDataService.exchangeLimitOrderSubData.encode(fromToken, toToken, amount, targetPrice, goodUntil, orderType);
|
|
211
230
|
},
|
|
212
231
|
};
|
|
213
232
|
export const sparkEncode = {
|
|
233
|
+
leverageManagement(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
234
|
+
let subInput = '0x';
|
|
235
|
+
subInput = subInput.concat(new Dec(triggerRepayRatio).mul(1e16).toHex().slice(2)
|
|
236
|
+
.padStart(32, '0'));
|
|
237
|
+
subInput = subInput.concat(new Dec(triggerBoostRatio).mul(1e16).toHex().slice(2)
|
|
238
|
+
.padStart(32, '0'));
|
|
239
|
+
subInput = subInput.concat(new Dec(targetBoostRatio).mul(1e16).toHex().slice(2)
|
|
240
|
+
.padStart(32, '0'));
|
|
241
|
+
subInput = subInput.concat(new Dec(targetRepayRatio).mul(1e16).toHex().slice(2)
|
|
242
|
+
.padStart(32, '0'));
|
|
243
|
+
subInput = subInput.concat(boostEnabled ? '01' : '00');
|
|
244
|
+
return subInput;
|
|
245
|
+
},
|
|
214
246
|
leverageManagementOnPrice(strategyOrBundleId, isBundle = true, triggerData, subData) {
|
|
215
247
|
const { collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio, } = subData;
|
|
216
248
|
const subDataEncoded = subDataService.sparkLeverageManagementOnPriceSubData.encode(collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio);
|