@defisaver/automation-sdk 3.1.10 → 3.1.14-spark-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/automation/private/StrategiesAutomation.d.ts +5 -3
- package/cjs/automation/private/StrategiesAutomation.js +27 -10
- package/cjs/automation/private/StrategiesAutomation.test.js +25 -0
- package/cjs/constants/index.d.ts +1 -0
- package/cjs/constants/index.js +352 -11
- package/cjs/index.d.ts +2 -1
- package/cjs/index.js +1 -1
- package/cjs/services/ethereumService.js +21 -14
- package/cjs/services/ethereumService.test.js +3 -0
- package/cjs/services/strategiesService.js +329 -54
- package/cjs/services/strategiesService.test.js +1 -0
- package/cjs/services/strategySubService.d.ts +24 -5
- package/cjs/services/strategySubService.js +116 -10
- package/cjs/services/strategySubService.test.js +1049 -173
- package/cjs/services/subDataService.d.ts +361 -88
- package/cjs/services/subDataService.js +799 -249
- package/cjs/services/subDataService.test.js +1287 -142
- package/cjs/services/triggerService.d.ts +100 -9
- package/cjs/services/triggerService.js +188 -19
- package/cjs/services/triggerService.test.js +437 -46
- package/cjs/services/utils.d.ts +1 -1
- package/cjs/services/utils.js +10 -2
- package/cjs/services/utils.test.js +0 -77
- package/cjs/types/enums.d.ts +88 -12
- package/cjs/types/enums.js +78 -2
- package/cjs/types/index.d.ts +59 -1
- package/esm/automation/private/StrategiesAutomation.d.ts +5 -3
- package/esm/automation/private/StrategiesAutomation.js +27 -10
- package/esm/automation/private/StrategiesAutomation.test.js +25 -0
- package/esm/constants/index.d.ts +1 -0
- package/esm/constants/index.js +351 -10
- package/esm/index.d.ts +2 -1
- package/esm/index.js +2 -2
- package/esm/services/ethereumService.js +21 -14
- package/esm/services/ethereumService.test.js +3 -0
- package/esm/services/strategiesService.js +330 -55
- package/esm/services/strategiesService.test.js +1 -0
- package/esm/services/strategySubService.d.ts +24 -5
- package/esm/services/strategySubService.js +115 -9
- package/esm/services/strategySubService.test.js +1052 -176
- package/esm/services/subDataService.d.ts +361 -88
- package/esm/services/subDataService.js +799 -249
- package/esm/services/subDataService.test.js +1288 -143
- package/esm/services/triggerService.d.ts +100 -9
- package/esm/services/triggerService.js +187 -18
- package/esm/services/triggerService.test.js +438 -47
- package/esm/services/utils.d.ts +1 -1
- package/esm/services/utils.js +10 -2
- package/esm/services/utils.test.js +1 -52
- package/esm/types/enums.d.ts +88 -12
- package/esm/types/enums.js +78 -2
- package/esm/types/index.d.ts +59 -1
- package/package.json +4 -5
- package/src/automation/private/StrategiesAutomation.test.ts +40 -0
- package/src/automation/private/StrategiesAutomation.ts +38 -15
- package/src/constants/index.ts +353 -11
- package/src/index.ts +4 -2
- package/src/services/ethereumService.test.ts +3 -0
- package/src/services/ethereumService.ts +23 -16
- package/src/services/strategiesService.test.ts +1 -0
- package/src/services/strategiesService.ts +387 -72
- package/src/services/strategySubService.test.ts +1330 -316
- package/src/services/strategySubService.ts +365 -12
- package/src/services/subDataService.test.ts +1413 -170
- package/src/services/subDataService.ts +1148 -431
- package/src/services/triggerService.test.ts +482 -52
- package/src/services/triggerService.ts +272 -27
- package/src/services/utils.test.ts +0 -59
- package/src/services/utils.ts +15 -4
- package/src/types/enums.ts +78 -2
- package/src/types/index.ts +74 -1
- package/umd/index.js +0 -34219
|
@@ -3,8 +3,11 @@ import { getAssetInfo } from '@defisaver/tokens';
|
|
|
3
3
|
|
|
4
4
|
import type { OrderType } from '../types/enums';
|
|
5
5
|
import {
|
|
6
|
-
|
|
7
|
-
Bundles,
|
|
6
|
+
CloseToAssetType,
|
|
7
|
+
Bundles,
|
|
8
|
+
ChainId,
|
|
9
|
+
RatioState,
|
|
10
|
+
Strategies,
|
|
8
11
|
} from '../types/enums';
|
|
9
12
|
import type { EthereumAddress, StrategyOrBundleIds } from '../types';
|
|
10
13
|
|
|
@@ -95,6 +98,27 @@ export const makerEncode = {
|
|
|
95
98
|
boostEnabled,
|
|
96
99
|
];
|
|
97
100
|
},
|
|
101
|
+
leverageManagementWithoutSubProxy(
|
|
102
|
+
vaultId: number,
|
|
103
|
+
triggerRatio: number,
|
|
104
|
+
targetRatio: number,
|
|
105
|
+
ratioState: RatioState,
|
|
106
|
+
isBoost: boolean,
|
|
107
|
+
daiAddr?: EthereumAddress,
|
|
108
|
+
) {
|
|
109
|
+
const bundleId = isBoost ? Bundles.MainnetIds.MAKER_BOOST : Bundles.MainnetIds.MAKER_REPAY;
|
|
110
|
+
|
|
111
|
+
const triggerData = triggerService.makerRatioTrigger.encode(vaultId, triggerRatio, ratioState);
|
|
112
|
+
|
|
113
|
+
const subData = subDataService.makerLeverageManagementWithoutSubProxy.encode(vaultId, targetRatio, daiAddr);
|
|
114
|
+
|
|
115
|
+
return [
|
|
116
|
+
bundleId,
|
|
117
|
+
true,
|
|
118
|
+
triggerData,
|
|
119
|
+
subData,
|
|
120
|
+
];
|
|
121
|
+
},
|
|
98
122
|
};
|
|
99
123
|
|
|
100
124
|
export const liquityEncode = {
|
|
@@ -321,6 +345,97 @@ export const aaveV3Encode = {
|
|
|
321
345
|
} = triggerData;
|
|
322
346
|
const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
|
|
323
347
|
|
|
348
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
349
|
+
},
|
|
350
|
+
leverageManagementWithoutSubProxy(
|
|
351
|
+
strategyOrBundleId: number,
|
|
352
|
+
market: EthereumAddress,
|
|
353
|
+
user: EthereumAddress,
|
|
354
|
+
ratioState: RatioState,
|
|
355
|
+
targetRatio: number,
|
|
356
|
+
triggerRatio: number,
|
|
357
|
+
isGeneric: boolean = false, // added later, isGeneric should be `false` for old strategies (if some are using this). For EOA should be `TRUE` !!! In the future, if we switch new SW subs to generic strategies too, then all new strategies should go with `isGeneric = true`. Old ones should stay the same
|
|
358
|
+
) {
|
|
359
|
+
const isBundle = true;
|
|
360
|
+
|
|
361
|
+
const subData = subDataService.aaveV3LeverageManagementSubDataWithoutSubProxy.encode(
|
|
362
|
+
targetRatio,
|
|
363
|
+
ratioState,
|
|
364
|
+
market,
|
|
365
|
+
user,
|
|
366
|
+
isGeneric,
|
|
367
|
+
);
|
|
368
|
+
const triggerData = triggerService.aaveV3RatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
369
|
+
|
|
370
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
371
|
+
},
|
|
372
|
+
|
|
373
|
+
leverageManagementOnPriceGeneric(
|
|
374
|
+
strategyOrBundleId: number,
|
|
375
|
+
price: number,
|
|
376
|
+
ratioState: RatioState,
|
|
377
|
+
collAsset: EthereumAddress,
|
|
378
|
+
collAssetId: number,
|
|
379
|
+
debtAsset: EthereumAddress,
|
|
380
|
+
debtAssetId: number,
|
|
381
|
+
marketAddr: EthereumAddress,
|
|
382
|
+
targetRatio: number,
|
|
383
|
+
user: EthereumAddress,
|
|
384
|
+
) {
|
|
385
|
+
const isBundle = true;
|
|
386
|
+
const subDataEncoded = subDataService.aaveV3LeverageManagementOnPriceGeneric.encode(
|
|
387
|
+
collAsset,
|
|
388
|
+
collAssetId,
|
|
389
|
+
debtAsset,
|
|
390
|
+
debtAssetId,
|
|
391
|
+
marketAddr,
|
|
392
|
+
targetRatio,
|
|
393
|
+
user,
|
|
394
|
+
);
|
|
395
|
+
const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(collAsset, debtAsset, price, ratioState);
|
|
396
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
397
|
+
},
|
|
398
|
+
|
|
399
|
+
closeOnPriceGeneric(
|
|
400
|
+
strategyOrBundleId: number,
|
|
401
|
+
collAsset: EthereumAddress,
|
|
402
|
+
collAssetId: number,
|
|
403
|
+
debtAsset: EthereumAddress,
|
|
404
|
+
debtAssetId: number,
|
|
405
|
+
marketAddr: EthereumAddress,
|
|
406
|
+
user: EthereumAddress,
|
|
407
|
+
stopLossPrice: number = 0,
|
|
408
|
+
stopLossType: CloseToAssetType = CloseToAssetType.DEBT,
|
|
409
|
+
takeProfitPrice: number = 0,
|
|
410
|
+
takeProfitType: CloseToAssetType = CloseToAssetType.COLLATERAL,
|
|
411
|
+
) {
|
|
412
|
+
const isBundle = true;
|
|
413
|
+
const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
414
|
+
|
|
415
|
+
const subDataEncoded = subDataService.aaveV3CloseGenericSubData.encode(collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, user);
|
|
416
|
+
const triggerDataEncoded = triggerService.aaveV3QuotePriceRangeTrigger.encode(collAsset, debtAsset, stopLossPrice, takeProfitPrice);
|
|
417
|
+
|
|
418
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
419
|
+
},
|
|
420
|
+
|
|
421
|
+
collateralSwitch(
|
|
422
|
+
strategyOrBundleId: number,
|
|
423
|
+
fromAsset: EthereumAddress,
|
|
424
|
+
fromAssetId: number,
|
|
425
|
+
toAsset: EthereumAddress,
|
|
426
|
+
toAssetId: number,
|
|
427
|
+
marketAddr: EthereumAddress,
|
|
428
|
+
amountToSwitch: string,
|
|
429
|
+
baseTokenAddress: EthereumAddress,
|
|
430
|
+
quoteTokenAddress: EthereumAddress,
|
|
431
|
+
price: number,
|
|
432
|
+
state: RatioState,
|
|
433
|
+
) {
|
|
434
|
+
const isBundle = false;
|
|
435
|
+
|
|
436
|
+
const subDataEncoded = subDataService.aaveV3CollateralSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch);
|
|
437
|
+
const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
|
|
438
|
+
|
|
324
439
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
325
440
|
},
|
|
326
441
|
};
|
|
@@ -350,6 +465,42 @@ export const compoundV3Encode = {
|
|
|
350
465
|
) {
|
|
351
466
|
return subDataService.compoundV3LeverageManagementSubData.encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled, isEOA);
|
|
352
467
|
},
|
|
468
|
+
leverageManagementOnPrice(
|
|
469
|
+
strategyOrBundleId: number,
|
|
470
|
+
market: EthereumAddress,
|
|
471
|
+
collToken: EthereumAddress,
|
|
472
|
+
baseToken: EthereumAddress,
|
|
473
|
+
targetRatio: number,
|
|
474
|
+
price: number,
|
|
475
|
+
priceState: RatioState,
|
|
476
|
+
ratioState: RatioState, // REPAY for repay on price, BOOST for boost on price
|
|
477
|
+
user: EthereumAddress,
|
|
478
|
+
) {
|
|
479
|
+
const isBundle = true;
|
|
480
|
+
const subDataEncoded = subDataService.compoundV3LeverageManagementOnPriceSubData.encode(market, collToken, baseToken, targetRatio, ratioState, user);
|
|
481
|
+
const triggerDataEncoded = triggerService.compoundV3PriceTrigger.encode(market, collToken, user, price, priceState);
|
|
482
|
+
|
|
483
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
484
|
+
},
|
|
485
|
+
closeOnPrice(
|
|
486
|
+
strategyOrBundleId: number,
|
|
487
|
+
market: EthereumAddress,
|
|
488
|
+
collToken: EthereumAddress,
|
|
489
|
+
baseToken: EthereumAddress,
|
|
490
|
+
stopLossPrice: number = 0,
|
|
491
|
+
stopLossType: CloseToAssetType = CloseToAssetType.DEBT,
|
|
492
|
+
takeProfitPrice: number = 0,
|
|
493
|
+
takeProfitType: CloseToAssetType = CloseToAssetType.COLLATERAL,
|
|
494
|
+
user: EthereumAddress,
|
|
495
|
+
) {
|
|
496
|
+
const isBundle = true;
|
|
497
|
+
const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
498
|
+
|
|
499
|
+
const subDataEncoded = subDataService.compoundV3CloseSubData.encode(market, collToken, baseToken, closeType, user);
|
|
500
|
+
const triggerDataEncoded = triggerService.compoundV3PriceRangeTrigger.encode(market, collToken, stopLossPrice, takeProfitPrice);
|
|
501
|
+
|
|
502
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
503
|
+
},
|
|
353
504
|
};
|
|
354
505
|
|
|
355
506
|
export const compoundV3L2Encode = {
|
|
@@ -361,8 +512,9 @@ export const compoundV3L2Encode = {
|
|
|
361
512
|
targetBoostRatio: number,
|
|
362
513
|
targetRepayRatio: number,
|
|
363
514
|
boostEnabled: boolean,
|
|
515
|
+
isEOA: boolean = false,
|
|
364
516
|
) {
|
|
365
|
-
return subDataService.compoundV3L2LeverageManagementSubData.encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled);
|
|
517
|
+
return subDataService.compoundV3L2LeverageManagementSubData.encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled, isEOA);
|
|
366
518
|
},
|
|
367
519
|
};
|
|
368
520
|
|
|
@@ -429,28 +581,88 @@ export const sparkEncode = {
|
|
|
429
581
|
|
|
430
582
|
return subInput;
|
|
431
583
|
},
|
|
432
|
-
|
|
584
|
+
leverageManagementOnPrice(
|
|
433
585
|
strategyOrBundleId: number,
|
|
434
586
|
isBundle: boolean = true,
|
|
435
587
|
triggerData: {
|
|
436
|
-
|
|
588
|
+
baseTokenAddr: EthereumAddress, quoteTokenAddr: EthereumAddress, price: number, ratioState: RatioState
|
|
437
589
|
},
|
|
438
590
|
subData: {
|
|
439
|
-
collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number,
|
|
591
|
+
collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number,
|
|
440
592
|
},
|
|
441
593
|
) {
|
|
442
594
|
const {
|
|
443
|
-
collAsset, collAssetId, debtAsset, debtAssetId,
|
|
595
|
+
collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio,
|
|
444
596
|
} = subData;
|
|
445
|
-
const subDataEncoded = subDataService.
|
|
597
|
+
const subDataEncoded = subDataService.sparkLeverageManagementOnPriceSubData.encode(collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio);
|
|
446
598
|
|
|
447
599
|
const {
|
|
448
|
-
|
|
600
|
+
baseTokenAddr, quoteTokenAddr, price, ratioState,
|
|
449
601
|
} = triggerData;
|
|
450
|
-
const triggerDataEncoded = triggerService.sparkQuotePriceTrigger.encode(
|
|
602
|
+
const triggerDataEncoded = triggerService.sparkQuotePriceTrigger.encode(baseTokenAddr, quoteTokenAddr, price, ratioState);
|
|
451
603
|
|
|
452
604
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
453
605
|
},
|
|
606
|
+
closeOnPriceGeneric(
|
|
607
|
+
strategyOrBundleId: number,
|
|
608
|
+
collAsset: EthereumAddress,
|
|
609
|
+
collAssetId: number,
|
|
610
|
+
debtAsset: EthereumAddress,
|
|
611
|
+
debtAssetId: number,
|
|
612
|
+
marketAddr: EthereumAddress,
|
|
613
|
+
user: EthereumAddress,
|
|
614
|
+
stopLossPrice: number = 0,
|
|
615
|
+
stopLossType: CloseToAssetType = CloseToAssetType.DEBT,
|
|
616
|
+
takeProfitPrice: number = 0,
|
|
617
|
+
takeProfitType: CloseToAssetType = CloseToAssetType.COLLATERAL,
|
|
618
|
+
) {
|
|
619
|
+
const isBundle = true;
|
|
620
|
+
const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
621
|
+
|
|
622
|
+
const subDataEncoded = subDataService.sparkCloseGenericSubData.encode(collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, user);
|
|
623
|
+
const triggerDataEncoded = triggerService.sparkQuotePriceRangeTrigger.encode(collAsset, debtAsset, stopLossPrice, takeProfitPrice);
|
|
624
|
+
|
|
625
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
626
|
+
},
|
|
627
|
+
leverageManagementWithoutSubProxy(
|
|
628
|
+
strategyOrBundleId: number,
|
|
629
|
+
market: EthereumAddress,
|
|
630
|
+
user: EthereumAddress,
|
|
631
|
+
ratioState: RatioState,
|
|
632
|
+
targetRatio: number,
|
|
633
|
+
triggerRatio: number,
|
|
634
|
+
) {
|
|
635
|
+
const isBundle = true;
|
|
636
|
+
|
|
637
|
+
const subData = subDataService.sparkLeverageManagementSubDataWithoutSubProxy.encode(
|
|
638
|
+
targetRatio,
|
|
639
|
+
ratioState,
|
|
640
|
+
);
|
|
641
|
+
const triggerData = triggerService.sparkRatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
642
|
+
|
|
643
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
644
|
+
},
|
|
645
|
+
collateralSwitch(
|
|
646
|
+
strategyOrBundleId: number,
|
|
647
|
+
fromAsset: EthereumAddress,
|
|
648
|
+
fromAssetId: number,
|
|
649
|
+
toAsset: EthereumAddress,
|
|
650
|
+
toAssetId: number,
|
|
651
|
+
marketAddr: EthereumAddress,
|
|
652
|
+
amountToSwitch: string,
|
|
653
|
+
baseTokenAddress: EthereumAddress,
|
|
654
|
+
quoteTokenAddress: EthereumAddress,
|
|
655
|
+
price: number,
|
|
656
|
+
state: RatioState,
|
|
657
|
+
) {
|
|
658
|
+
const isBundle = false;
|
|
659
|
+
|
|
660
|
+
const subDataEncoded = subDataService.sparkCollateralSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch);
|
|
661
|
+
const triggerDataEncoded = triggerService.sparkQuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
|
|
662
|
+
|
|
663
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
664
|
+
},
|
|
665
|
+
|
|
454
666
|
};
|
|
455
667
|
|
|
456
668
|
export const crvUSDEncode = {
|
|
@@ -518,8 +730,10 @@ export const morphoBlueEncode = {
|
|
|
518
730
|
return [isBoost ? Bundles.BaseIds.MORPHO_BLUE_BOOST : Bundles.BaseIds.MORPHO_BLUE_REPAY, true, triggerData, subData];
|
|
519
731
|
}
|
|
520
732
|
|
|
521
|
-
|
|
522
|
-
|
|
733
|
+
const bundlesIds = network === ChainId.Arbitrum ? Bundles.ArbitrumIds : Bundles.MainnetIds;
|
|
734
|
+
|
|
735
|
+
if (isBoost) strategyOrBundleId = isEOA ? bundlesIds.MORPHO_BLUE_EOA_BOOST : bundlesIds.MORPHO_BLUE_BOOST;
|
|
736
|
+
else strategyOrBundleId = isEOA ? bundlesIds.MORPHO_BLUE_EOA_REPAY : bundlesIds.MORPHO_BLUE_REPAY;
|
|
523
737
|
const isBundle = true;
|
|
524
738
|
|
|
525
739
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
@@ -541,6 +755,27 @@ export const morphoBlueEncode = {
|
|
|
541
755
|
const triggerData = triggerService.morphoBluePriceTrigger.encode(oracle, collToken, loanToken, price, priceState);
|
|
542
756
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
543
757
|
},
|
|
758
|
+
closeOnPrice(
|
|
759
|
+
strategyOrBundleId: number,
|
|
760
|
+
loanToken: EthereumAddress,
|
|
761
|
+
collToken: EthereumAddress,
|
|
762
|
+
oracle: EthereumAddress,
|
|
763
|
+
irm: EthereumAddress,
|
|
764
|
+
lltv: string,
|
|
765
|
+
user: EthereumAddress,
|
|
766
|
+
stopLossPrice: number = 0,
|
|
767
|
+
stopLossType: CloseToAssetType = CloseToAssetType.DEBT,
|
|
768
|
+
takeProfitPrice: number = 0,
|
|
769
|
+
takeProfitType: CloseToAssetType = CloseToAssetType.COLLATERAL,
|
|
770
|
+
) {
|
|
771
|
+
const isBundle = true;
|
|
772
|
+
const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
773
|
+
|
|
774
|
+
const subDataEncoded = subDataService.morphoBlueCloseOnPriceSubData.encode(loanToken, collToken, oracle, irm, lltv, user, closeType);
|
|
775
|
+
const triggerDataEncoded = triggerService.morphoBluePriceRangeTrigger.encode(oracle, collToken, loanToken, stopLossPrice, takeProfitPrice);
|
|
776
|
+
|
|
777
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
778
|
+
},
|
|
544
779
|
};
|
|
545
780
|
|
|
546
781
|
export const liquityV2Encode = {
|
|
@@ -632,3 +867,121 @@ export const fluidEncode = {
|
|
|
632
867
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
633
868
|
},
|
|
634
869
|
};
|
|
870
|
+
|
|
871
|
+
export const aaveV4Encode = {
|
|
872
|
+
leverageManagement(
|
|
873
|
+
strategyOrBundleId: number,
|
|
874
|
+
owner: EthereumAddress,
|
|
875
|
+
spoke: EthereumAddress,
|
|
876
|
+
ratioState: RatioState,
|
|
877
|
+
targetRatio: number,
|
|
878
|
+
triggerRatio: number,
|
|
879
|
+
) {
|
|
880
|
+
const isBundle = true;
|
|
881
|
+
const subData = subDataService.aaveV4LeverageManagementSubData.encode(spoke, owner, ratioState, targetRatio);
|
|
882
|
+
const triggerData = triggerService.aaveV4RatioTrigger.encode(owner, spoke, triggerRatio, ratioState);
|
|
883
|
+
|
|
884
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
885
|
+
},
|
|
886
|
+
leverageManagementOnPrice(
|
|
887
|
+
strategyOrBundleId: number,
|
|
888
|
+
owner: EthereumAddress,
|
|
889
|
+
spoke: EthereumAddress,
|
|
890
|
+
collAsset: EthereumAddress,
|
|
891
|
+
collAssetId: number,
|
|
892
|
+
debtAsset: EthereumAddress,
|
|
893
|
+
debtAssetId: number,
|
|
894
|
+
targetRatio: number,
|
|
895
|
+
price: string,
|
|
896
|
+
priceState: RatioState,
|
|
897
|
+
ratioState: RatioState, // UNDER for repay, OVER for boost
|
|
898
|
+
) {
|
|
899
|
+
const isBundle = true;
|
|
900
|
+
const subData = subDataService.aaveV4LeverageManagementOnPriceSubData.encode(
|
|
901
|
+
spoke,
|
|
902
|
+
owner,
|
|
903
|
+
collAsset,
|
|
904
|
+
collAssetId,
|
|
905
|
+
debtAsset,
|
|
906
|
+
debtAssetId,
|
|
907
|
+
ratioState,
|
|
908
|
+
targetRatio,
|
|
909
|
+
);
|
|
910
|
+
const triggerData = triggerService.aaveV4QuotePriceTrigger.encode(
|
|
911
|
+
spoke,
|
|
912
|
+
collAssetId,
|
|
913
|
+
debtAssetId,
|
|
914
|
+
price,
|
|
915
|
+
priceState,
|
|
916
|
+
);
|
|
917
|
+
|
|
918
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
919
|
+
},
|
|
920
|
+
closeOnPrice(
|
|
921
|
+
strategyOrBundleId: number,
|
|
922
|
+
owner: EthereumAddress,
|
|
923
|
+
spoke: EthereumAddress,
|
|
924
|
+
collAsset: EthereumAddress,
|
|
925
|
+
collAssetId: number,
|
|
926
|
+
debtAsset: EthereumAddress,
|
|
927
|
+
debtAssetId: number,
|
|
928
|
+
stopLossPrice: string = '0',
|
|
929
|
+
stopLossType: CloseToAssetType = CloseToAssetType.DEBT,
|
|
930
|
+
takeProfitPrice: string = '0',
|
|
931
|
+
takeProfitType: CloseToAssetType = CloseToAssetType.COLLATERAL,
|
|
932
|
+
) {
|
|
933
|
+
const isBundle = true;
|
|
934
|
+
const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
935
|
+
|
|
936
|
+
const subData = subDataService.aaveV4CloseSubData.encode(
|
|
937
|
+
spoke,
|
|
938
|
+
owner,
|
|
939
|
+
collAsset,
|
|
940
|
+
collAssetId,
|
|
941
|
+
debtAsset,
|
|
942
|
+
debtAssetId,
|
|
943
|
+
closeType,
|
|
944
|
+
);
|
|
945
|
+
const triggerData = triggerService.aaveV4QuotePriceRangeTrigger.encode(
|
|
946
|
+
spoke,
|
|
947
|
+
collAssetId,
|
|
948
|
+
debtAssetId,
|
|
949
|
+
stopLossPrice,
|
|
950
|
+
takeProfitPrice,
|
|
951
|
+
);
|
|
952
|
+
|
|
953
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
954
|
+
},
|
|
955
|
+
collateralSwitch(
|
|
956
|
+
strategyOrBundleId: number,
|
|
957
|
+
owner: EthereumAddress,
|
|
958
|
+
spoke: EthereumAddress,
|
|
959
|
+
fromAsset: EthereumAddress,
|
|
960
|
+
fromAssetId: number,
|
|
961
|
+
toAsset: EthereumAddress,
|
|
962
|
+
toAssetId: number,
|
|
963
|
+
amountToSwitch: string,
|
|
964
|
+
price: string,
|
|
965
|
+
ratioState: RatioState,
|
|
966
|
+
) {
|
|
967
|
+
const isBundle = false;
|
|
968
|
+
const subData = subDataService.aaveV4CollateralSwitchSubData.encode(
|
|
969
|
+
spoke,
|
|
970
|
+
owner,
|
|
971
|
+
fromAsset,
|
|
972
|
+
fromAssetId,
|
|
973
|
+
toAsset,
|
|
974
|
+
toAssetId,
|
|
975
|
+
amountToSwitch,
|
|
976
|
+
);
|
|
977
|
+
const triggerData = triggerService.aaveV4QuotePriceTrigger.encode(
|
|
978
|
+
spoke,
|
|
979
|
+
fromAssetId, // baseTokenId
|
|
980
|
+
toAssetId, // quoteTokenId
|
|
981
|
+
price,
|
|
982
|
+
ratioState,
|
|
983
|
+
);
|
|
984
|
+
|
|
985
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
986
|
+
},
|
|
987
|
+
};
|