@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
|
@@ -102,7 +102,7 @@ function parseMakerTrailingStop(position: Position.Automated, parseData: ParseDa
|
|
|
102
102
|
function parseMakerLeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
103
103
|
const _position = cloneDeep(position);
|
|
104
104
|
|
|
105
|
-
const { subStruct, subId
|
|
105
|
+
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
106
106
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
107
107
|
|
|
108
108
|
const triggerData = triggerService.makerRatioTrigger.decode(subStruct.triggerData);
|
|
@@ -119,10 +119,9 @@ function parseMakerLeverageManagement(position: Position.Automated, parseData: P
|
|
|
119
119
|
_position.specific = {
|
|
120
120
|
triggerRepayRatio: triggerData.ratio,
|
|
121
121
|
targetRepayRatio: subData.targetRatio,
|
|
122
|
-
repayEnabled:
|
|
122
|
+
repayEnabled: true,
|
|
123
123
|
subId1: Number(subId),
|
|
124
124
|
mergeWithId: Strategies.Identifiers.Boost,
|
|
125
|
-
subHashRepay: subHash,
|
|
126
125
|
};
|
|
127
126
|
} else {
|
|
128
127
|
_position.specific = {
|
|
@@ -131,7 +130,6 @@ function parseMakerLeverageManagement(position: Position.Automated, parseData: P
|
|
|
131
130
|
boostEnabled: isEnabled,
|
|
132
131
|
subId2: Number(subId),
|
|
133
132
|
mergeId: Strategies.Identifiers.Boost,
|
|
134
|
-
subHashBoost: subHash,
|
|
135
133
|
};
|
|
136
134
|
}
|
|
137
135
|
|
|
@@ -192,7 +190,7 @@ function parseLiquityTrailingStop(position: Position.Automated, parseData: Parse
|
|
|
192
190
|
function parseAaveV2LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
193
191
|
const _position = cloneDeep(position);
|
|
194
192
|
|
|
195
|
-
const { subStruct, subId
|
|
193
|
+
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
196
194
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
197
195
|
|
|
198
196
|
const triggerData = triggerService.aaveV2RatioTrigger.decode(subStruct.triggerData);
|
|
@@ -209,10 +207,9 @@ function parseAaveV2LeverageManagement(position: Position.Automated, parseData:
|
|
|
209
207
|
_position.specific = {
|
|
210
208
|
triggerRepayRatio: triggerData.ratio,
|
|
211
209
|
targetRepayRatio: subData.targetRatio,
|
|
212
|
-
repayEnabled:
|
|
210
|
+
repayEnabled: true,
|
|
213
211
|
subId1: Number(subId),
|
|
214
212
|
mergeWithId: Strategies.Identifiers.Boost,
|
|
215
|
-
subHashRepay: subHash,
|
|
216
213
|
};
|
|
217
214
|
} else {
|
|
218
215
|
_position.specific = {
|
|
@@ -221,7 +218,6 @@ function parseAaveV2LeverageManagement(position: Position.Automated, parseData:
|
|
|
221
218
|
boostEnabled: isEnabled,
|
|
222
219
|
subId2: Number(subId),
|
|
223
220
|
mergeId: Strategies.Identifiers.Boost,
|
|
224
|
-
subHashBoost: subHash,
|
|
225
221
|
};
|
|
226
222
|
}
|
|
227
223
|
|
|
@@ -505,7 +501,7 @@ function parseAaveV4CollateralSwitch(position: Position.Automated, parseData: Pa
|
|
|
505
501
|
function parseMorphoAaveV2LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
506
502
|
const _position = cloneDeep(position);
|
|
507
503
|
|
|
508
|
-
const { subStruct, subId
|
|
504
|
+
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
509
505
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
510
506
|
|
|
511
507
|
const triggerData = triggerService.morphoAaveV2RatioTrigger.decode(subStruct.triggerData);
|
|
@@ -522,10 +518,9 @@ function parseMorphoAaveV2LeverageManagement(position: Position.Automated, parse
|
|
|
522
518
|
_position.specific = {
|
|
523
519
|
triggerRepayRatio: triggerData.ratio,
|
|
524
520
|
targetRepayRatio: subData.targetRatio,
|
|
525
|
-
repayEnabled:
|
|
521
|
+
repayEnabled: true,
|
|
526
522
|
subId1: Number(subId),
|
|
527
523
|
mergeWithId: Strategies.Identifiers.Boost,
|
|
528
|
-
subHashRepay: subHash,
|
|
529
524
|
};
|
|
530
525
|
} else {
|
|
531
526
|
_position.specific = {
|
|
@@ -534,7 +529,6 @@ function parseMorphoAaveV2LeverageManagement(position: Position.Automated, parse
|
|
|
534
529
|
boostEnabled: isEnabled,
|
|
535
530
|
subId2: Number(subId),
|
|
536
531
|
mergeId: Strategies.Identifiers.Boost,
|
|
537
|
-
subHashBoost: subHash,
|
|
538
532
|
};
|
|
539
533
|
}
|
|
540
534
|
|
|
@@ -585,7 +579,7 @@ function parseAaveV3CloseOnPriceWithMaximumGasPrice(position: Position.Automated
|
|
|
585
579
|
function parseCompoundV2LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
586
580
|
const _position = cloneDeep(position);
|
|
587
581
|
|
|
588
|
-
const { subStruct, subId
|
|
582
|
+
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
589
583
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
590
584
|
|
|
591
585
|
const triggerData = triggerService.compoundV2RatioTrigger.decode(subStruct.triggerData);
|
|
@@ -603,10 +597,9 @@ function parseCompoundV2LeverageManagement(position: Position.Automated, parseDa
|
|
|
603
597
|
_position.specific = {
|
|
604
598
|
triggerRepayRatio: triggerData.ratio,
|
|
605
599
|
targetRepayRatio: subData.targetRatio,
|
|
606
|
-
repayEnabled:
|
|
600
|
+
repayEnabled: true,
|
|
607
601
|
subId1: Number(subId),
|
|
608
602
|
mergeWithId: Strategies.Identifiers.Boost,
|
|
609
|
-
subHashRepay: subHash,
|
|
610
603
|
};
|
|
611
604
|
} else {
|
|
612
605
|
_position.specific = {
|
|
@@ -615,7 +608,6 @@ function parseCompoundV2LeverageManagement(position: Position.Automated, parseDa
|
|
|
615
608
|
boostEnabled: isEnabled,
|
|
616
609
|
subId2: Number(subId),
|
|
617
610
|
mergeId: Strategies.Identifiers.Boost,
|
|
618
|
-
subHashBoost: subHash,
|
|
619
611
|
};
|
|
620
612
|
}
|
|
621
613
|
|
|
@@ -628,10 +620,12 @@ function parseCompoundV2LeverageManagement(position: Position.Automated, parseDa
|
|
|
628
620
|
function parseCompoundV3LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
629
621
|
const _position = cloneDeep(position);
|
|
630
622
|
|
|
631
|
-
const { subStruct, subId
|
|
623
|
+
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
632
624
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
633
625
|
|
|
634
|
-
const subDataDecoder =
|
|
626
|
+
const subDataDecoder = position.chainId !== 1
|
|
627
|
+
? subDataService.compoundV3L2LeverageManagementSubData
|
|
628
|
+
: subDataService.compoundV3LeverageManagementSubData;
|
|
635
629
|
|
|
636
630
|
const triggerData = triggerService.compoundV3RatioTrigger.decode(subStruct.triggerData);
|
|
637
631
|
const subData = subDataDecoder.decode(subStruct.subData);
|
|
@@ -649,10 +643,9 @@ function parseCompoundV3LeverageManagement(position: Position.Automated, parseDa
|
|
|
649
643
|
_position.specific = {
|
|
650
644
|
triggerRepayRatio: triggerData.ratio,
|
|
651
645
|
targetRepayRatio: subData.targetRatio,
|
|
652
|
-
repayEnabled:
|
|
646
|
+
repayEnabled: true,
|
|
653
647
|
subId1: Number(subId),
|
|
654
648
|
mergeWithId: isEOA ? Strategies.Identifiers.EoaBoost : Strategies.Identifiers.Boost,
|
|
655
|
-
subHashRepay: subHash,
|
|
656
649
|
};
|
|
657
650
|
} else {
|
|
658
651
|
_position.specific = {
|
|
@@ -661,7 +654,6 @@ function parseCompoundV3LeverageManagement(position: Position.Automated, parseDa
|
|
|
661
654
|
boostEnabled: isEnabled,
|
|
662
655
|
subId2: Number(subId),
|
|
663
656
|
mergeId: isEOA ? Strategies.Identifiers.EoaBoost : Strategies.Identifiers.Boost,
|
|
664
|
-
subHashBoost: subHash,
|
|
665
657
|
};
|
|
666
658
|
}
|
|
667
659
|
|
|
@@ -787,7 +779,7 @@ function parseExchangeLimitOrder(position: Position.Automated, parseData: ParseD
|
|
|
787
779
|
function parseLiquityLeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
788
780
|
const _position = cloneDeep(position);
|
|
789
781
|
|
|
790
|
-
const { subStruct, subId
|
|
782
|
+
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
791
783
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
792
784
|
|
|
793
785
|
const triggerData = triggerService.liquityRatioTrigger.decode(subStruct.triggerData);
|
|
@@ -804,10 +796,9 @@ function parseLiquityLeverageManagement(position: Position.Automated, parseData:
|
|
|
804
796
|
_position.specific = {
|
|
805
797
|
triggerRepayRatio: triggerData.ratio,
|
|
806
798
|
targetRepayRatio: subData.targetRatio,
|
|
807
|
-
repayEnabled:
|
|
799
|
+
repayEnabled: true,
|
|
808
800
|
subId1: Number(subId),
|
|
809
801
|
mergeWithId: Strategies.Identifiers.Boost,
|
|
810
|
-
subHashRepay: subHash,
|
|
811
802
|
};
|
|
812
803
|
} else {
|
|
813
804
|
_position.specific = {
|
|
@@ -816,7 +807,6 @@ function parseLiquityLeverageManagement(position: Position.Automated, parseData:
|
|
|
816
807
|
boostEnabled: isEnabled,
|
|
817
808
|
subId2: Number(subId),
|
|
818
809
|
mergeId: Strategies.Identifiers.Boost,
|
|
819
|
-
subHashBoost: subHash,
|
|
820
810
|
};
|
|
821
811
|
}
|
|
822
812
|
|
|
@@ -871,7 +861,7 @@ function parseLiquityV2LeverageManagement(position: Position.Automated, parseDat
|
|
|
871
861
|
function parseSparkLeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
872
862
|
const _position = cloneDeep(position);
|
|
873
863
|
|
|
874
|
-
const { subStruct, subId
|
|
864
|
+
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
875
865
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
876
866
|
|
|
877
867
|
const triggerData = triggerService.sparkRatioTrigger.decode(subStruct.triggerData);
|
|
@@ -888,10 +878,9 @@ function parseSparkLeverageManagement(position: Position.Automated, parseData: P
|
|
|
888
878
|
_position.specific = {
|
|
889
879
|
triggerRepayRatio: triggerData.ratio,
|
|
890
880
|
targetRepayRatio: subData.targetRatio,
|
|
891
|
-
repayEnabled:
|
|
881
|
+
repayEnabled: true,
|
|
892
882
|
subId1: Number(subId),
|
|
893
883
|
mergeWithId: Strategies.Identifiers.Boost,
|
|
894
|
-
subHashRepay: subHash,
|
|
895
884
|
};
|
|
896
885
|
} else {
|
|
897
886
|
_position.specific = {
|
|
@@ -900,7 +889,6 @@ function parseSparkLeverageManagement(position: Position.Automated, parseData: P
|
|
|
900
889
|
boostEnabled: isEnabled,
|
|
901
890
|
subId2: Number(subId),
|
|
902
891
|
mergeId: Strategies.Identifiers.Boost,
|
|
903
|
-
subHashBoost: subHash,
|
|
904
892
|
};
|
|
905
893
|
}
|
|
906
894
|
|
|
@@ -1140,7 +1128,6 @@ function parseMorphoBlueLeverageManagementOnPrice(position: Position.Automated,
|
|
|
1140
1128
|
debtAsset: subData.loanToken,
|
|
1141
1129
|
price: triggerData.price,
|
|
1142
1130
|
ratio: subData.targetRatio,
|
|
1143
|
-
ratioState: triggerData.priceState,
|
|
1144
1131
|
};
|
|
1145
1132
|
|
|
1146
1133
|
return _position;
|
|
@@ -9,14 +9,17 @@ import type { EthereumAddress, StrategyOrBundleIds, SubData, TriggerData } from
|
|
|
9
9
|
|
|
10
10
|
import '../configuration';
|
|
11
11
|
import {
|
|
12
|
+
aaveV2Encode,
|
|
12
13
|
chickenBondsEncode,
|
|
13
14
|
liquityEncode,
|
|
14
15
|
makerEncode,
|
|
15
16
|
aaveV3Encode,
|
|
17
|
+
compoundV2Encode,
|
|
16
18
|
compoundV3Encode,
|
|
17
19
|
morphoAaveV2Encode,
|
|
18
20
|
exchangeEncode,
|
|
19
21
|
crvUSDEncode,
|
|
22
|
+
compoundV3L2Encode,
|
|
20
23
|
morphoBlueEncode,
|
|
21
24
|
sparkEncode,
|
|
22
25
|
aaveV4Encode,
|
|
@@ -137,6 +140,39 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
137
140
|
});
|
|
138
141
|
});
|
|
139
142
|
|
|
143
|
+
describe('leverageManagement()', () => {
|
|
144
|
+
const examples: Array<[
|
|
145
|
+
[
|
|
146
|
+
vaultId: number, triggerRepayRatio: string, triggerBoostRatio: string, targetBoostRatio: string,
|
|
147
|
+
targetRepayRatio: string, boostEnabled: boolean,
|
|
148
|
+
],
|
|
149
|
+
[
|
|
150
|
+
vaultId: number, triggerRepayRatio: string, triggerBoostRatio: string, targetBoostRatio: string,
|
|
151
|
+
targetRepayRatio: string, boostEnabled: boolean,
|
|
152
|
+
]
|
|
153
|
+
]> = [
|
|
154
|
+
[
|
|
155
|
+
[
|
|
156
|
+
5791,
|
|
157
|
+
new Dec('210').mul(1e16).toString(),
|
|
158
|
+
new Dec('290').mul(1e16).toString(),
|
|
159
|
+
new Dec('240').mul(1e16).toString(),
|
|
160
|
+
new Dec('240').mul(1e16).toString(),
|
|
161
|
+
true,
|
|
162
|
+
],
|
|
163
|
+
[
|
|
164
|
+
5791, '210', '290', '240', '240', true,
|
|
165
|
+
]
|
|
166
|
+
]
|
|
167
|
+
];
|
|
168
|
+
|
|
169
|
+
examples.forEach(([expected, actual]) => {
|
|
170
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
171
|
+
expect(makerEncode.leverageManagement(...actual)).to.eql(expected);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
|
|
140
176
|
describe('leverageManagementWithoutSubProxy()', () => {
|
|
141
177
|
const examples: Array<[
|
|
142
178
|
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
@@ -260,6 +296,38 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
260
296
|
});
|
|
261
297
|
});
|
|
262
298
|
|
|
299
|
+
describe('leverageManagement()', () => {
|
|
300
|
+
const examples: Array<[
|
|
301
|
+
[
|
|
302
|
+
triggerRepayRatio: string, triggerBoostRatio: string, targetBoostRatio: string,
|
|
303
|
+
targetRepayRatio: string, boostEnabled: boolean,
|
|
304
|
+
],
|
|
305
|
+
[
|
|
306
|
+
triggerRepayRatio: string, triggerBoostRatio: string, targetBoostRatio: string,
|
|
307
|
+
targetRepayRatio: string, boostEnabled: boolean,
|
|
308
|
+
]
|
|
309
|
+
]> = [
|
|
310
|
+
[
|
|
311
|
+
[
|
|
312
|
+
new Dec('210').mul(1e16).toString(),
|
|
313
|
+
new Dec('290').mul(1e16).toString(),
|
|
314
|
+
new Dec('240').mul(1e16).toString(),
|
|
315
|
+
new Dec('240').mul(1e16).toString(),
|
|
316
|
+
false,
|
|
317
|
+
],
|
|
318
|
+
[
|
|
319
|
+
'210', '290', '240', '240', false,
|
|
320
|
+
]
|
|
321
|
+
]
|
|
322
|
+
];
|
|
323
|
+
|
|
324
|
+
examples.forEach(([expected, actual]) => {
|
|
325
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
326
|
+
expect(liquityEncode.leverageManagement(...actual)).to.eql(expected);
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
});
|
|
330
|
+
|
|
263
331
|
describe('paybackFromChickenBondStrategySub()', () => {
|
|
264
332
|
const examples: Array<[
|
|
265
333
|
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
@@ -368,7 +436,53 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
368
436
|
});
|
|
369
437
|
});
|
|
370
438
|
|
|
439
|
+
describe('When testing strategySubService.aaveV2Encode', () => {
|
|
440
|
+
describe('leverageManagement()', () => {
|
|
441
|
+
const examples: Array<[
|
|
442
|
+
[string, string, string, string, boolean],
|
|
443
|
+
[triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean],
|
|
444
|
+
]> = [
|
|
445
|
+
[
|
|
446
|
+
[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],
|
|
447
|
+
[160, 220, 180, 190, true]
|
|
448
|
+
],
|
|
449
|
+
[
|
|
450
|
+
[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],
|
|
451
|
+
[160, 200, 180, 190, false]
|
|
452
|
+
],
|
|
453
|
+
];
|
|
454
|
+
|
|
455
|
+
examples.forEach(([expected, actual]) => {
|
|
456
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
457
|
+
expect(aaveV2Encode.leverageManagement(...actual)).to.eql(expected);
|
|
458
|
+
});
|
|
459
|
+
});
|
|
460
|
+
});
|
|
461
|
+
});
|
|
462
|
+
|
|
371
463
|
describe('When testing strategySubService.aaveV3Encode', () => {
|
|
464
|
+
describe('leverageManagement()', () => {
|
|
465
|
+
const examples: Array<[
|
|
466
|
+
string,
|
|
467
|
+
[triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean],
|
|
468
|
+
]> = [
|
|
469
|
+
[
|
|
470
|
+
'0x000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e000001',
|
|
471
|
+
[160, 220, 180, 190, true]
|
|
472
|
+
],
|
|
473
|
+
[
|
|
474
|
+
'0x000000000000000016345785d8a0000000000000000000001bc16d674ec80000000000000000000018fae27693b4000000000000000000001a5e27eef13e000000',
|
|
475
|
+
[160, 200, 180, 190, false]
|
|
476
|
+
],
|
|
477
|
+
];
|
|
478
|
+
|
|
479
|
+
examples.forEach(([expected, actual]) => {
|
|
480
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
481
|
+
expect(aaveV3Encode.leverageManagement(...actual)).to.eql(expected);
|
|
482
|
+
});
|
|
483
|
+
});
|
|
484
|
+
});
|
|
485
|
+
|
|
372
486
|
describe('closeToAsset()', () => {
|
|
373
487
|
const examples: Array<[
|
|
374
488
|
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
@@ -1027,7 +1141,74 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1027
1141
|
});
|
|
1028
1142
|
});
|
|
1029
1143
|
|
|
1144
|
+
describe('When testing strategySubService.compoundV2Encode', () => {
|
|
1145
|
+
describe('leverageManagement()', () => {
|
|
1146
|
+
const examples: Array<[
|
|
1147
|
+
[string, string, string, string, boolean],
|
|
1148
|
+
[triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean],
|
|
1149
|
+
]> = [
|
|
1150
|
+
[
|
|
1151
|
+
[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],
|
|
1152
|
+
[160, 220, 180, 190, true]
|
|
1153
|
+
],
|
|
1154
|
+
[
|
|
1155
|
+
[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],
|
|
1156
|
+
[160, 200, 180, 190, false]
|
|
1157
|
+
],
|
|
1158
|
+
];
|
|
1159
|
+
|
|
1160
|
+
examples.forEach(([expected, actual]) => {
|
|
1161
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1162
|
+
expect(compoundV2Encode.leverageManagement(...actual)).to.eql(expected);
|
|
1163
|
+
});
|
|
1164
|
+
});
|
|
1165
|
+
});
|
|
1166
|
+
});
|
|
1167
|
+
|
|
1030
1168
|
describe('When testing strategySubService.compoundV3Encode', () => {
|
|
1169
|
+
describe('leverageManagement()', () => {
|
|
1170
|
+
const examples: Array<[[EthereumAddress, EthereumAddress, string, string, string, string, boolean, boolean], [market: EthereumAddress, baseToken: EthereumAddress, triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean, isEOA: boolean]]> = [
|
|
1171
|
+
[
|
|
1172
|
+
[
|
|
1173
|
+
web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
1174
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1175
|
+
new Dec(160).mul(1e16).toString(),
|
|
1176
|
+
new Dec(220).mul(1e16).toString(),
|
|
1177
|
+
new Dec(180).mul(1e16).toString(),
|
|
1178
|
+
new Dec(190).mul(1e16).toString(),
|
|
1179
|
+
true, false,
|
|
1180
|
+
],
|
|
1181
|
+
[
|
|
1182
|
+
web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
1183
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1184
|
+
160, 220, 180, 190,
|
|
1185
|
+
true, false,
|
|
1186
|
+
]
|
|
1187
|
+
],
|
|
1188
|
+
[
|
|
1189
|
+
[
|
|
1190
|
+
web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
1191
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1192
|
+
new Dec(160).mul(1e16).toString(),
|
|
1193
|
+
new Dec(210).mul(1e16).toString(),
|
|
1194
|
+
new Dec(180).mul(1e16).toString(),
|
|
1195
|
+
new Dec(190).mul(1e16).toString(),
|
|
1196
|
+
false, true,
|
|
1197
|
+
],
|
|
1198
|
+
[
|
|
1199
|
+
web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
1200
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1201
|
+
160, 210, 180, 190,
|
|
1202
|
+
false, true,
|
|
1203
|
+
]
|
|
1204
|
+
],
|
|
1205
|
+
];
|
|
1206
|
+
examples.forEach(([expected, actual]) => {
|
|
1207
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1208
|
+
expect(compoundV3Encode.leverageManagement(...actual)).to.eql(expected);
|
|
1209
|
+
});
|
|
1210
|
+
});
|
|
1211
|
+
});
|
|
1031
1212
|
describe('leverageManagementOnPrice()', () => {
|
|
1032
1213
|
const examples: Array<[
|
|
1033
1214
|
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
@@ -1215,6 +1396,53 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1215
1396
|
});
|
|
1216
1397
|
});
|
|
1217
1398
|
});
|
|
1399
|
+
|
|
1400
|
+
describe('limitOrder()', () => {
|
|
1401
|
+
const examples: Array<[[EthereumAddress, EthereumAddress, string, string, string, string], [fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, targetPrice: string, goodUntil: string | number, orderType: OrderType]]> = [
|
|
1402
|
+
[
|
|
1403
|
+
[
|
|
1404
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1405
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1406
|
+
'2131',
|
|
1407
|
+
'0.53123',
|
|
1408
|
+
'1696590921159',
|
|
1409
|
+
`${OrderType.STOP_LOSS}`
|
|
1410
|
+
],
|
|
1411
|
+
[
|
|
1412
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1413
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1414
|
+
'2131',
|
|
1415
|
+
'0.53123',
|
|
1416
|
+
1696590921159,
|
|
1417
|
+
OrderType.STOP_LOSS
|
|
1418
|
+
]
|
|
1419
|
+
],
|
|
1420
|
+
[
|
|
1421
|
+
[
|
|
1422
|
+
web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
|
|
1423
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
|
|
1424
|
+
'2131',
|
|
1425
|
+
'0.43123',
|
|
1426
|
+
'1646590921159',
|
|
1427
|
+
`${OrderType.TAKE_PROFIT}`
|
|
1428
|
+
],
|
|
1429
|
+
[
|
|
1430
|
+
web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
|
|
1431
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
|
|
1432
|
+
'2131',
|
|
1433
|
+
'0.43123',
|
|
1434
|
+
1646590921159,
|
|
1435
|
+
OrderType.TAKE_PROFIT
|
|
1436
|
+
]
|
|
1437
|
+
],
|
|
1438
|
+
];
|
|
1439
|
+
|
|
1440
|
+
examples.forEach(([expected, actual]) => {
|
|
1441
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1442
|
+
expect(exchangeEncode.limitOrder(...actual)).to.eql(expected);
|
|
1443
|
+
});
|
|
1444
|
+
});
|
|
1445
|
+
});
|
|
1218
1446
|
});
|
|
1219
1447
|
|
|
1220
1448
|
describe('When testing strategySubService.crvUSDEncode', () => {
|
|
@@ -1473,7 +1701,58 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1473
1701
|
});
|
|
1474
1702
|
});
|
|
1475
1703
|
|
|
1704
|
+
describe('When testing strategySubService.compoundV3L2Encode', () => {
|
|
1705
|
+
describe('leverageManagement()', () => {
|
|
1706
|
+
const examples: Array<[string, [EthereumAddress, EthereumAddress, number, number, number, number, boolean, boolean]]> = [
|
|
1707
|
+
[
|
|
1708
|
+
'0x0313D212133AFab8F2b829B1066c7e43caD94e2c0213D212133AfaB8F2b829B1066C7E43cAD94E2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e00000100',
|
|
1709
|
+
[
|
|
1710
|
+
web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'),
|
|
1711
|
+
web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'),
|
|
1712
|
+
160, 220, 180, 190,
|
|
1713
|
+
true,
|
|
1714
|
+
false,
|
|
1715
|
+
],
|
|
1716
|
+
],
|
|
1717
|
+
[
|
|
1718
|
+
'0x0313D212133AFab8F2b829B1066c7e43caD94e2c0413d212133afAb8F2B829b1066C7e43cAd94e2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000000f43fc2c04ee00000000',
|
|
1719
|
+
[
|
|
1720
|
+
web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'),
|
|
1721
|
+
web3Utils.toChecksumAddress('0x0413d212133AFaB8F2B829B1066c7E43cAd94E2c'),
|
|
1722
|
+
160, 220, 180, 110,
|
|
1723
|
+
false,
|
|
1724
|
+
false,
|
|
1725
|
+
],
|
|
1726
|
+
],
|
|
1727
|
+
];
|
|
1728
|
+
examples.forEach(([expected, actual]) => {
|
|
1729
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1730
|
+
expect(compoundV3L2Encode.leverageManagement(...actual)).to.eql(expected);
|
|
1731
|
+
});
|
|
1732
|
+
});
|
|
1733
|
+
});
|
|
1734
|
+
});
|
|
1735
|
+
|
|
1476
1736
|
describe('When testing strategySubService.sparkEncode', () => {
|
|
1737
|
+
describe('leverageManagement()', () => {
|
|
1738
|
+
const examples: Array<[string, [number, number, number, number, boolean]]> = [
|
|
1739
|
+
[
|
|
1740
|
+
'0x0000000000000000136dcc951d8c00000000000000000000214e8348c4f0000000000000000000001d24b2dfac52000000000000000000001a5e27eef13e000001',
|
|
1741
|
+
[140,240,210,190,true]
|
|
1742
|
+
],
|
|
1743
|
+
[
|
|
1744
|
+
'0x0000000000000000130337bdce49000000000000000000001988fe4052b800000000000000000000281b57b028e1000000000000000000002223acf76376000000',
|
|
1745
|
+
[137, 184, 289, 246, false]
|
|
1746
|
+
]
|
|
1747
|
+
];
|
|
1748
|
+
|
|
1749
|
+
examples.forEach(([expected, actual]) => {
|
|
1750
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1751
|
+
expect(sparkEncode.leverageManagement(...actual)).to.eql(expected);
|
|
1752
|
+
});
|
|
1753
|
+
});
|
|
1754
|
+
});
|
|
1755
|
+
|
|
1477
1756
|
describe('leverageManagementOnPrice()', () => {
|
|
1478
1757
|
const examples: Array<[[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1479
1758
|
[
|