@defisaver/automation-sdk 3.2.0 → 3.2.1
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.js +5 -5
- package/cjs/constants/index.js +70 -0
- package/cjs/services/strategiesService.js +174 -0
- package/cjs/services/strategySubService.d.ts +11 -1
- package/cjs/services/strategySubService.js +42 -1
- package/cjs/services/subDataService.d.ts +63 -1
- package/cjs/services/subDataService.js +195 -1
- package/cjs/services/triggerService.d.ts +43 -0
- package/cjs/services/triggerService.js +81 -1
- package/cjs/services/utils.d.ts +6 -1
- package/cjs/services/utils.js +52 -1
- package/cjs/types/contracts/generated/SubStorage.d.ts +4 -0
- package/cjs/types/enums.d.ts +45 -5
- package/cjs/types/enums.js +45 -1
- package/cjs/types/index.d.ts +26 -2
- package/esm/automation/private/StrategiesAutomation.js +5 -5
- package/esm/constants/index.js +70 -0
- package/esm/services/strategiesService.js +172 -1
- package/esm/services/strategySubService.d.ts +11 -1
- package/esm/services/strategySubService.js +43 -2
- package/esm/services/subDataService.d.ts +63 -1
- package/esm/services/subDataService.js +195 -1
- package/esm/services/triggerService.d.ts +43 -0
- package/esm/services/triggerService.js +80 -0
- package/esm/services/utils.d.ts +6 -1
- package/esm/services/utils.js +50 -1
- package/esm/types/contracts/generated/SubStorage.d.ts +4 -0
- package/esm/types/enums.d.ts +45 -5
- package/esm/types/enums.js +44 -0
- package/esm/types/index.d.ts +26 -2
- package/package.json +3 -5
- package/src/automation/private/StrategiesAutomation.ts +5 -4
- package/src/constants/index.ts +70 -0
- package/src/services/strategiesService.ts +224 -1
- package/src/services/strategySubService.ts +111 -1
- package/src/services/subDataService.ts +271 -2
- package/src/services/triggerService.ts +125 -0
- package/src/services/utils.ts +60 -1
- package/src/types/enums.ts +44 -0
- package/src/types/index.ts +34 -1
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.aaveV3LeverageManagementOnPriceSubData = exports.morphoBlueLeverageManagementSubData = exports.crvUSDPaybackSubData = exports.crvUSDLeverageManagementSubData = exports.liquityDebtInFrontRepaySubData = exports.liquityDsrSupplySubData = exports.liquityDsrPaybackSubData = exports.sparkQuotePriceSubData = exports.sparkLeverageManagementSubData = exports.exchangeLimitOrderSubData = exports.exchangeDcaSubData = exports.liquityPaybackUsingChickenBondSubData = exports.cBondsRebondSubData = exports.morphoAaveV2LeverageManagementSubData = exports.compoundV3L2LeverageManagementSubData = exports.compoundV3LeverageManagementSubData = exports.compoundV2LeverageManagementSubData = exports.aaveV3QuotePriceSubData = exports.aaveV3LeverageManagementSubData = exports.aaveV2LeverageManagementSubData = exports.liquityCloseSubData = exports.liquityLeverageManagementSubData = exports.makerLeverageManagementSubData = exports.makerCloseSubData = exports.liquityRepayFromSavingsSubData = exports.makerRepayFromSavingsSubData = void 0;
|
|
6
|
+
exports.fluidLeverageManagementSubData = exports.liquityV2PaybackSubData = exports.morphoBlueLeverageManagementOnPriceSubData = exports.liquityV2LeverageManagementOnPriceSubData = exports.liquityV2CloseSubData = exports.liquityV2LeverageManagementSubData = exports.aaveV3LeverageManagementOnPriceSubData = exports.morphoBlueLeverageManagementSubData = exports.crvUSDPaybackSubData = exports.crvUSDLeverageManagementSubData = exports.liquityDebtInFrontRepaySubData = exports.liquityDsrSupplySubData = exports.liquityDsrPaybackSubData = exports.sparkQuotePriceSubData = exports.sparkLeverageManagementSubData = exports.exchangeLimitOrderSubData = exports.exchangeDcaSubData = exports.liquityPaybackUsingChickenBondSubData = exports.cBondsRebondSubData = exports.morphoAaveV2LeverageManagementSubData = exports.compoundV3L2LeverageManagementSubData = exports.compoundV3LeverageManagementSubData = exports.compoundV2LeverageManagementSubData = exports.aaveV3QuotePriceSubData = exports.aaveV3LeverageManagementSubData = exports.aaveV2LeverageManagementSubData = exports.liquityCloseSubData = exports.liquityLeverageManagementSubData = exports.makerLeverageManagementSubData = exports.makerCloseSubData = exports.liquityRepayFromSavingsSubData = exports.makerRepayFromSavingsSubData = void 0;
|
|
7
7
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
8
8
|
const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
|
|
9
9
|
const web3_utils_1 = require("web3-utils");
|
|
@@ -473,3 +473,197 @@ exports.aaveV3LeverageManagementOnPriceSubData = {
|
|
|
473
473
|
};
|
|
474
474
|
},
|
|
475
475
|
};
|
|
476
|
+
exports.liquityV2LeverageManagementSubData = {
|
|
477
|
+
encode: (market, troveId, collToken, boldToken, ratioState, targetRatio) => {
|
|
478
|
+
const marketEncoded = web3_eth_abi_1.default.encodeParameter('address', market);
|
|
479
|
+
const troveIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', troveId);
|
|
480
|
+
const collTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', collToken);
|
|
481
|
+
const boldTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', boldToken);
|
|
482
|
+
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
483
|
+
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
484
|
+
const isRepay = ratioState === enums_1.RatioState.UNDER;
|
|
485
|
+
const collActionType = isRepay ? enums_1.CollActionType.WITHDRAW : enums_1.CollActionType.SUPPLY;
|
|
486
|
+
const debtActionType = isRepay ? enums_1.DebtActionType.PAYBACK : enums_1.DebtActionType.BORROW;
|
|
487
|
+
const collActionTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', collActionType);
|
|
488
|
+
const debtActionTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', debtActionType);
|
|
489
|
+
return [
|
|
490
|
+
marketEncoded,
|
|
491
|
+
troveIdEncoded,
|
|
492
|
+
collTokenEncoded,
|
|
493
|
+
boldTokenEncoded,
|
|
494
|
+
ratioStateEncoded,
|
|
495
|
+
targetRatioEncoded,
|
|
496
|
+
collActionTypeEncoded,
|
|
497
|
+
debtActionTypeEncoded,
|
|
498
|
+
];
|
|
499
|
+
},
|
|
500
|
+
decode: (subData) => {
|
|
501
|
+
const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
502
|
+
const troveId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
503
|
+
const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
504
|
+
const boldToken = web3_eth_abi_1.default.decodeParameter('address', subData[3]);
|
|
505
|
+
const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[4]);
|
|
506
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[5]);
|
|
507
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
508
|
+
return {
|
|
509
|
+
market, troveId, collToken, boldToken, ratioState, targetRatio,
|
|
510
|
+
};
|
|
511
|
+
},
|
|
512
|
+
};
|
|
513
|
+
exports.liquityV2CloseSubData = {
|
|
514
|
+
encode(market, troveId, collToken, boldToken, closeType) {
|
|
515
|
+
const marketEncoded = web3_eth_abi_1.default.encodeParameter('address', market);
|
|
516
|
+
const troveIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', troveId);
|
|
517
|
+
const collAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', collToken);
|
|
518
|
+
const boldTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', boldToken);
|
|
519
|
+
const wethAddress = (0, tokens_1.getAssetInfo)('WETH').address;
|
|
520
|
+
const wethAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', wethAddress);
|
|
521
|
+
const gasCompensation = new decimal_js_1.default('0.0375').mul(1e18).toString();
|
|
522
|
+
const gasCompensationEncoded = web3_eth_abi_1.default.encodeParameter('uint256', gasCompensation);
|
|
523
|
+
const closeTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', closeType);
|
|
524
|
+
return [
|
|
525
|
+
marketEncoded,
|
|
526
|
+
troveIdEncoded,
|
|
527
|
+
collAddrEncoded,
|
|
528
|
+
boldTokenEncoded,
|
|
529
|
+
wethAddressEncoded,
|
|
530
|
+
gasCompensationEncoded,
|
|
531
|
+
closeTypeEncoded,
|
|
532
|
+
];
|
|
533
|
+
},
|
|
534
|
+
decode(subData) {
|
|
535
|
+
const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
536
|
+
const troveId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
537
|
+
const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
538
|
+
const boldToken = web3_eth_abi_1.default.decodeParameter('address', subData[3]);
|
|
539
|
+
// skip wethAddress and gasCompensation
|
|
540
|
+
const closeType = web3_eth_abi_1.default.decodeParameter('uint8', subData[6]);
|
|
541
|
+
return {
|
|
542
|
+
market, troveId, collToken, boldToken, closeType,
|
|
543
|
+
};
|
|
544
|
+
},
|
|
545
|
+
};
|
|
546
|
+
exports.liquityV2LeverageManagementOnPriceSubData = {
|
|
547
|
+
encode(market, troveId, collToken, boldToken, targetRatio, isRepayOnPrice) {
|
|
548
|
+
const encodedMarket = web3_eth_abi_1.default.encodeParameter('address', market);
|
|
549
|
+
const encodedTroveId = web3_eth_abi_1.default.encodeParameter('uint256', troveId);
|
|
550
|
+
const encodedCollToken = web3_eth_abi_1.default.encodeParameter('address', collToken);
|
|
551
|
+
const encodedBoldToken = web3_eth_abi_1.default.encodeParameter('address', boldToken);
|
|
552
|
+
const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
553
|
+
const collActionType = isRepayOnPrice ? enums_1.CollActionType.WITHDRAW : enums_1.CollActionType.SUPPLY;
|
|
554
|
+
const debtActionType = isRepayOnPrice ? enums_1.DebtActionType.PAYBACK : enums_1.DebtActionType.BORROW;
|
|
555
|
+
const encodedCollActionType = web3_eth_abi_1.default.encodeParameter('uint8', collActionType);
|
|
556
|
+
const encodedDebtActionType = web3_eth_abi_1.default.encodeParameter('uint8', debtActionType);
|
|
557
|
+
return [
|
|
558
|
+
encodedMarket,
|
|
559
|
+
encodedTroveId,
|
|
560
|
+
encodedCollToken,
|
|
561
|
+
encodedBoldToken,
|
|
562
|
+
encodedTargetRatio,
|
|
563
|
+
encodedCollActionType,
|
|
564
|
+
encodedDebtActionType,
|
|
565
|
+
];
|
|
566
|
+
},
|
|
567
|
+
decode(subData) {
|
|
568
|
+
const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
569
|
+
const troveId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
570
|
+
const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
571
|
+
const boldToken = web3_eth_abi_1.default.decodeParameter('address', subData[3]);
|
|
572
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[4]);
|
|
573
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
574
|
+
return {
|
|
575
|
+
market, troveId, collToken, boldToken, targetRatio,
|
|
576
|
+
};
|
|
577
|
+
},
|
|
578
|
+
};
|
|
579
|
+
exports.morphoBlueLeverageManagementOnPriceSubData = {
|
|
580
|
+
encode(loanToken, collToken, oracle, irm, lltv, targetRatio, user) {
|
|
581
|
+
const loanTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', loanToken);
|
|
582
|
+
const collTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', collToken);
|
|
583
|
+
const oracleEncoded = web3_eth_abi_1.default.encodeParameter('address', oracle);
|
|
584
|
+
const irmEncoded = web3_eth_abi_1.default.encodeParameter('address', irm);
|
|
585
|
+
const lltvEncoded = web3_eth_abi_1.default.encodeParameter('uint256', lltv);
|
|
586
|
+
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
587
|
+
const userEncoded = web3_eth_abi_1.default.encodeParameter('address', user);
|
|
588
|
+
return [loanTokenEncoded, collTokenEncoded, oracleEncoded, irmEncoded, lltvEncoded, targetRatioEncoded, userEncoded];
|
|
589
|
+
},
|
|
590
|
+
decode(subData) {
|
|
591
|
+
const loanToken = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
592
|
+
const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
|
|
593
|
+
const oracle = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
594
|
+
const irm = web3_eth_abi_1.default.decodeParameter('address', subData[3]);
|
|
595
|
+
const lltv = web3_eth_abi_1.default.decodeParameter('uint256', subData[4]);
|
|
596
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[5]);
|
|
597
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
598
|
+
const user = web3_eth_abi_1.default.decodeParameter('address', subData[6]);
|
|
599
|
+
return {
|
|
600
|
+
loanToken,
|
|
601
|
+
collToken,
|
|
602
|
+
oracle,
|
|
603
|
+
irm,
|
|
604
|
+
lltv,
|
|
605
|
+
targetRatio,
|
|
606
|
+
user,
|
|
607
|
+
};
|
|
608
|
+
},
|
|
609
|
+
};
|
|
610
|
+
exports.liquityV2PaybackSubData = {
|
|
611
|
+
encode: (market, troveId, boldToken, targetRatio, ratioState) => {
|
|
612
|
+
const marketEncoded = web3_eth_abi_1.default.encodeParameter('address', market);
|
|
613
|
+
const troveIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', troveId);
|
|
614
|
+
const boldTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', boldToken);
|
|
615
|
+
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
616
|
+
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
617
|
+
return [
|
|
618
|
+
marketEncoded,
|
|
619
|
+
troveIdEncoded,
|
|
620
|
+
boldTokenEncoded,
|
|
621
|
+
targetRatioEncoded,
|
|
622
|
+
ratioStateEncoded,
|
|
623
|
+
];
|
|
624
|
+
},
|
|
625
|
+
decode: (subData) => {
|
|
626
|
+
const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
627
|
+
const troveId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
628
|
+
const boldToken = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
629
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]);
|
|
630
|
+
const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[4]);
|
|
631
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
632
|
+
return {
|
|
633
|
+
market, troveId, boldToken, ratioState, targetRatio,
|
|
634
|
+
};
|
|
635
|
+
},
|
|
636
|
+
};
|
|
637
|
+
exports.fluidLeverageManagementSubData = {
|
|
638
|
+
encode: (nftId, vault, ratioState, targetRatio) => {
|
|
639
|
+
const nftIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', nftId);
|
|
640
|
+
const vaultEncoded = web3_eth_abi_1.default.encodeParameter('address', vault);
|
|
641
|
+
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
642
|
+
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
643
|
+
const wrapEthEncoded = web3_eth_abi_1.default.encodeParameter('bool', true);
|
|
644
|
+
const isRepay = ratioState === enums_1.RatioState.UNDER;
|
|
645
|
+
const collActionType = isRepay ? enums_1.CollActionType.WITHDRAW : enums_1.CollActionType.SUPPLY;
|
|
646
|
+
const debtActionType = isRepay ? enums_1.DebtActionType.PAYBACK : enums_1.DebtActionType.BORROW;
|
|
647
|
+
const collActionTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', collActionType);
|
|
648
|
+
const debtActionTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', debtActionType);
|
|
649
|
+
return [
|
|
650
|
+
nftIdEncoded,
|
|
651
|
+
vaultEncoded,
|
|
652
|
+
ratioStateEncoded,
|
|
653
|
+
targetRatioEncoded,
|
|
654
|
+
wrapEthEncoded,
|
|
655
|
+
collActionTypeEncoded,
|
|
656
|
+
debtActionTypeEncoded,
|
|
657
|
+
];
|
|
658
|
+
},
|
|
659
|
+
decode: (subData) => {
|
|
660
|
+
const nftId = web3_eth_abi_1.default.decodeParameter('uint256', subData[0]);
|
|
661
|
+
const vault = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
|
|
662
|
+
const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[2]);
|
|
663
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]);
|
|
664
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
665
|
+
return {
|
|
666
|
+
nftId, vault, ratioState, targetRatio,
|
|
667
|
+
};
|
|
668
|
+
},
|
|
669
|
+
};
|
|
@@ -189,3 +189,46 @@ export declare const morphoBlueRatioTrigger: {
|
|
|
189
189
|
ratioState: number;
|
|
190
190
|
};
|
|
191
191
|
};
|
|
192
|
+
export declare const liquityV2RatioTrigger: {
|
|
193
|
+
encode(market: EthereumAddress, troveId: string, ratioPercentage: number, ratioState: RatioState): string[];
|
|
194
|
+
decode(triggerData: string[]): {
|
|
195
|
+
market: string;
|
|
196
|
+
troveId: string;
|
|
197
|
+
ratio: number;
|
|
198
|
+
ratioState: number;
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
export declare const liquityV2QuotePriceTrigger: {
|
|
202
|
+
encode(market: EthereumAddress, price: number, ratioState: RatioState): string[];
|
|
203
|
+
decode(triggerData: string[]): {
|
|
204
|
+
market: string;
|
|
205
|
+
price: string;
|
|
206
|
+
ratioState: number;
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
export declare const closePriceTrigger: {
|
|
210
|
+
encode(tokenAddr: EthereumAddress, lowerPrice: number, upperPrice: number): string[];
|
|
211
|
+
decode(triggerData: string[]): {
|
|
212
|
+
tokenAddr: EthereumAddress;
|
|
213
|
+
lowerPrice: string;
|
|
214
|
+
upperPrice: string;
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
export declare const morphoBluePriceTrigger: {
|
|
218
|
+
encode(oracle: EthereumAddress, collateralToken: EthereumAddress, loanToken: EthereumAddress, price: number, priceState: RatioState): string[];
|
|
219
|
+
decode(triggerData: string[]): {
|
|
220
|
+
oracle: string;
|
|
221
|
+
collateralToken: string;
|
|
222
|
+
loanToken: string;
|
|
223
|
+
price: string;
|
|
224
|
+
priceState: number;
|
|
225
|
+
};
|
|
226
|
+
};
|
|
227
|
+
export declare const fluidRatioTrigger: {
|
|
228
|
+
encode(nftId: string, ratioPercentage: number, ratioState: RatioState): string[];
|
|
229
|
+
decode(triggerData: string[]): {
|
|
230
|
+
nftId: string;
|
|
231
|
+
ratio: number;
|
|
232
|
+
ratioState: number;
|
|
233
|
+
};
|
|
234
|
+
};
|
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.morphoBlueRatioTrigger = exports.crvUsdHealthRatioTrigger = exports.crvUSDRatioTrigger = exports.curveUsdSoftLiquidationTrigger = exports.curveUsdBorrowRateTrigger = exports.sparkQuotePriceTrigger = exports.sparkRatioTrigger = exports.exchangeOffchainPriceTrigger = exports.exchangeTimestampTrigger = exports.compoundV3RatioTrigger = exports.cBondsRebondTrigger = exports.aaveV2RatioTrigger = exports.liquityDebtInFrontWithLimitTrigger = exports.liquityDebtInFrontTrigger = exports.liquityRatioTrigger = exports.compoundV2RatioTrigger = exports.aaveV3QuotePriceWithMaximumGasPriceTrigger = exports.aaveV3QuotePriceTrigger = exports.morphoAaveV2RatioTrigger = exports.aaveV3RatioTrigger = exports.makerRatioTrigger = exports.trailingStopTrigger = exports.chainlinkPriceTrigger = void 0;
|
|
29
|
+
exports.fluidRatioTrigger = exports.morphoBluePriceTrigger = exports.closePriceTrigger = exports.liquityV2QuotePriceTrigger = exports.liquityV2RatioTrigger = exports.morphoBlueRatioTrigger = exports.crvUsdHealthRatioTrigger = exports.crvUSDRatioTrigger = exports.curveUsdSoftLiquidationTrigger = exports.curveUsdBorrowRateTrigger = exports.sparkQuotePriceTrigger = exports.sparkRatioTrigger = exports.exchangeOffchainPriceTrigger = exports.exchangeTimestampTrigger = exports.compoundV3RatioTrigger = exports.cBondsRebondTrigger = exports.aaveV2RatioTrigger = exports.liquityDebtInFrontWithLimitTrigger = exports.liquityDebtInFrontTrigger = exports.liquityRatioTrigger = exports.compoundV2RatioTrigger = exports.aaveV3QuotePriceWithMaximumGasPriceTrigger = exports.aaveV3QuotePriceTrigger = exports.morphoAaveV2RatioTrigger = exports.aaveV3RatioTrigger = exports.makerRatioTrigger = exports.trailingStopTrigger = exports.chainlinkPriceTrigger = void 0;
|
|
30
30
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
31
31
|
const tokens_1 = require("@defisaver/tokens");
|
|
32
32
|
const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
|
|
@@ -365,3 +365,83 @@ exports.morphoBlueRatioTrigger = {
|
|
|
365
365
|
};
|
|
366
366
|
},
|
|
367
367
|
};
|
|
368
|
+
exports.liquityV2RatioTrigger = {
|
|
369
|
+
encode(market, troveId, ratioPercentage, ratioState) {
|
|
370
|
+
const ratioWei = (0, utils_1.ratioPercentageToWei)(ratioPercentage);
|
|
371
|
+
return [web3_eth_abi_1.default.encodeParameters(['address', 'uint256', 'uint256', 'uint8'], [market, troveId, ratioWei, ratioState])];
|
|
372
|
+
},
|
|
373
|
+
decode(triggerData) {
|
|
374
|
+
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'uint256', 'uint256', 'uint8'], triggerData[0]);
|
|
375
|
+
return {
|
|
376
|
+
market: decodedData[0],
|
|
377
|
+
troveId: decodedData[1],
|
|
378
|
+
ratio: (0, utils_1.weiToRatioPercentage)(decodedData[2]),
|
|
379
|
+
ratioState: Number(decodedData[3]),
|
|
380
|
+
};
|
|
381
|
+
},
|
|
382
|
+
};
|
|
383
|
+
exports.liquityV2QuotePriceTrigger = {
|
|
384
|
+
encode(market, price, ratioState) {
|
|
385
|
+
// Price is always in 18 decimals
|
|
386
|
+
const _price = new decimal_js_1.default(price.toString()).mul(Math.pow(10, 18)).floor().toString();
|
|
387
|
+
return [web3_eth_abi_1.default.encodeParameters(['address', 'uint256', 'uint8'], [market, _price, ratioState])];
|
|
388
|
+
},
|
|
389
|
+
decode(triggerData) {
|
|
390
|
+
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'uint256', 'uint8'], triggerData[0]);
|
|
391
|
+
const price = new decimal_js_1.default(decodedData[1]).div(Math.pow(10, 18)).toDP(18).toString();
|
|
392
|
+
return {
|
|
393
|
+
market: decodedData[0],
|
|
394
|
+
price,
|
|
395
|
+
ratioState: Number(decodedData[2]),
|
|
396
|
+
};
|
|
397
|
+
},
|
|
398
|
+
};
|
|
399
|
+
exports.closePriceTrigger = {
|
|
400
|
+
encode(tokenAddr, lowerPrice, upperPrice) {
|
|
401
|
+
const lowerPriceFormatted = new decimal_js_1.default(lowerPrice).mul(1e8).floor().toString();
|
|
402
|
+
const upperPriceFormatted = new decimal_js_1.default(upperPrice).mul(1e8).floor().toString();
|
|
403
|
+
return [
|
|
404
|
+
web3_eth_abi_1.default.encodeParameters(['address', 'uint256', 'uint256'], [tokenAddr, lowerPriceFormatted, upperPriceFormatted]),
|
|
405
|
+
];
|
|
406
|
+
},
|
|
407
|
+
decode(triggerData) {
|
|
408
|
+
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'uint256', 'uint256'], triggerData[0]);
|
|
409
|
+
return {
|
|
410
|
+
tokenAddr: decodedData[0],
|
|
411
|
+
lowerPrice: new decimal_js_1.default(decodedData[1]).div(1e8).toString(),
|
|
412
|
+
upperPrice: new decimal_js_1.default(decodedData[2]).div(1e8).toString(),
|
|
413
|
+
};
|
|
414
|
+
},
|
|
415
|
+
};
|
|
416
|
+
exports.morphoBluePriceTrigger = {
|
|
417
|
+
encode(oracle, collateralToken, loanToken, price, priceState) {
|
|
418
|
+
const _price = new decimal_js_1.default(price.toString()).mul(1e8).floor().toString();
|
|
419
|
+
return [
|
|
420
|
+
web3_eth_abi_1.default.encodeParameters(['address', 'address', 'address', 'uint256', 'uint8'], [oracle, collateralToken, loanToken, _price, priceState]),
|
|
421
|
+
];
|
|
422
|
+
},
|
|
423
|
+
decode(triggerData) {
|
|
424
|
+
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'address', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
425
|
+
return {
|
|
426
|
+
oracle: decodedData[0],
|
|
427
|
+
collateralToken: decodedData[1],
|
|
428
|
+
loanToken: decodedData[2],
|
|
429
|
+
price: new decimal_js_1.default(decodedData[3]).div(1e8).toString(),
|
|
430
|
+
priceState: Number(decodedData[4]),
|
|
431
|
+
};
|
|
432
|
+
},
|
|
433
|
+
};
|
|
434
|
+
exports.fluidRatioTrigger = {
|
|
435
|
+
encode(nftId, ratioPercentage, ratioState) {
|
|
436
|
+
const ratioWei = (0, utils_1.ratioPercentageToWei)(ratioPercentage);
|
|
437
|
+
return [web3_eth_abi_1.default.encodeParameters(['uint256', 'uint256', 'uint8'], [nftId, ratioWei, ratioState])];
|
|
438
|
+
},
|
|
439
|
+
decode(triggerData) {
|
|
440
|
+
const decodedData = web3_eth_abi_1.default.decodeParameters(['uint256', 'uint256', 'uint8'], triggerData[0]);
|
|
441
|
+
return {
|
|
442
|
+
nftId: decodedData[0],
|
|
443
|
+
ratio: (0, utils_1.weiToRatioPercentage)(decodedData[1]),
|
|
444
|
+
ratioState: Number(decodedData[2]),
|
|
445
|
+
};
|
|
446
|
+
},
|
|
447
|
+
};
|
package/cjs/services/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EthereumAddress } from '../types';
|
|
2
|
-
import { ChainId, RatioState } from '../types/enums';
|
|
2
|
+
import { ChainId, CloseStrategyType, CloseToAssetType, RatioState } from '../types/enums';
|
|
3
3
|
export declare function isDefined<T>(value: T): value is NonNullable<T>;
|
|
4
4
|
export declare function isUndefined(value: unknown): boolean;
|
|
5
5
|
export declare function compareAddresses(firstAddress: EthereumAddress, secondAddress: EthereumAddress): boolean;
|
|
@@ -23,3 +23,8 @@ export declare function getRatioStateInfoForAaveCloseStrategy(currentRatioState:
|
|
|
23
23
|
ratioState: RatioState;
|
|
24
24
|
};
|
|
25
25
|
export declare function getPositionId(...args: (number | string)[]): string;
|
|
26
|
+
export declare function getCloseStrategyType(stopLossPrice: number, stopLossType: CloseToAssetType, takeProfitPrice: number, takeProfitType: CloseToAssetType): CloseStrategyType;
|
|
27
|
+
export declare function getStopLossAndTakeProfitTypeByCloseStrategyType(closeStrategyType: CloseStrategyType): {
|
|
28
|
+
stopLossType: CloseToAssetType | undefined;
|
|
29
|
+
takeProfitType: CloseToAssetType | undefined;
|
|
30
|
+
};
|
package/cjs/services/utils.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.getPositionId = exports.getRatioStateInfoForAaveCloseStrategy = exports.requireAddresses = exports.requireAddress = exports.isEmptyBytes = exports.isRatioStateUnder = exports.isRatioStateOver = exports.weiToRatioPercentage = exports.ratioPercentageToWei = exports.encodeSubId = exports.compareSubHashes = exports.wethToEthByAddress = exports.wethToEth = exports.ethToWeth = exports.addToObjectIf = exports.addToArrayIf = exports.isAddress = exports.compareAddresses = exports.isUndefined = exports.isDefined = void 0;
|
|
29
|
+
exports.getStopLossAndTakeProfitTypeByCloseStrategyType = exports.getCloseStrategyType = exports.getPositionId = exports.getRatioStateInfoForAaveCloseStrategy = exports.requireAddresses = exports.requireAddress = exports.isEmptyBytes = exports.isRatioStateUnder = exports.isRatioStateOver = exports.weiToRatioPercentage = exports.ratioPercentageToWei = exports.encodeSubId = exports.compareSubHashes = exports.wethToEthByAddress = exports.wethToEth = exports.ethToWeth = exports.addToObjectIf = exports.addToArrayIf = exports.isAddress = exports.compareAddresses = exports.isUndefined = exports.isDefined = void 0;
|
|
30
30
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
31
31
|
const web3Utils = __importStar(require("web3-utils"));
|
|
32
32
|
const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
|
|
@@ -129,3 +129,54 @@ function getPositionId(...args) {
|
|
|
129
129
|
return args.map(arg => arg.toString().toLowerCase().split(' ').join('_')).join('-');
|
|
130
130
|
}
|
|
131
131
|
exports.getPositionId = getPositionId;
|
|
132
|
+
function getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType) {
|
|
133
|
+
const isStopLoss = stopLossPrice > 0;
|
|
134
|
+
const isTakeProfit = takeProfitPrice > 0;
|
|
135
|
+
if (!isStopLoss && !isTakeProfit) {
|
|
136
|
+
throw new Error('CloseOnPrice: At least one price must be defined');
|
|
137
|
+
}
|
|
138
|
+
if (isStopLoss && isTakeProfit) {
|
|
139
|
+
if (stopLossType === enums_1.CloseToAssetType.COLLATERAL && takeProfitType === enums_1.CloseToAssetType.COLLATERAL) {
|
|
140
|
+
return enums_1.CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL;
|
|
141
|
+
}
|
|
142
|
+
if (stopLossType === enums_1.CloseToAssetType.COLLATERAL) {
|
|
143
|
+
return enums_1.CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL;
|
|
144
|
+
}
|
|
145
|
+
if (takeProfitType === enums_1.CloseToAssetType.COLLATERAL) {
|
|
146
|
+
return enums_1.CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT;
|
|
147
|
+
}
|
|
148
|
+
return enums_1.CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT;
|
|
149
|
+
}
|
|
150
|
+
if (isStopLoss) {
|
|
151
|
+
return stopLossType === enums_1.CloseToAssetType.COLLATERAL
|
|
152
|
+
? enums_1.CloseStrategyType.STOP_LOSS_IN_COLLATERAL
|
|
153
|
+
: enums_1.CloseStrategyType.STOP_LOSS_IN_DEBT;
|
|
154
|
+
}
|
|
155
|
+
return takeProfitType === enums_1.CloseToAssetType.COLLATERAL
|
|
156
|
+
? enums_1.CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL
|
|
157
|
+
: enums_1.CloseStrategyType.TAKE_PROFIT_IN_DEBT;
|
|
158
|
+
}
|
|
159
|
+
exports.getCloseStrategyType = getCloseStrategyType;
|
|
160
|
+
function getStopLossAndTakeProfitTypeByCloseStrategyType(closeStrategyType) {
|
|
161
|
+
switch (closeStrategyType) {
|
|
162
|
+
case enums_1.CloseStrategyType.STOP_LOSS_IN_COLLATERAL:
|
|
163
|
+
return { stopLossType: enums_1.CloseToAssetType.COLLATERAL, takeProfitType: undefined };
|
|
164
|
+
case enums_1.CloseStrategyType.STOP_LOSS_IN_DEBT:
|
|
165
|
+
return { stopLossType: enums_1.CloseToAssetType.DEBT, takeProfitType: undefined };
|
|
166
|
+
case enums_1.CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL:
|
|
167
|
+
return { stopLossType: undefined, takeProfitType: enums_1.CloseToAssetType.COLLATERAL };
|
|
168
|
+
case enums_1.CloseStrategyType.TAKE_PROFIT_IN_DEBT:
|
|
169
|
+
return { stopLossType: undefined, takeProfitType: enums_1.CloseToAssetType.DEBT };
|
|
170
|
+
case enums_1.CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT:
|
|
171
|
+
return { stopLossType: enums_1.CloseToAssetType.DEBT, takeProfitType: enums_1.CloseToAssetType.COLLATERAL };
|
|
172
|
+
case enums_1.CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL:
|
|
173
|
+
return { stopLossType: enums_1.CloseToAssetType.COLLATERAL, takeProfitType: enums_1.CloseToAssetType.DEBT };
|
|
174
|
+
case enums_1.CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT:
|
|
175
|
+
return { stopLossType: enums_1.CloseToAssetType.DEBT, takeProfitType: enums_1.CloseToAssetType.DEBT };
|
|
176
|
+
case enums_1.CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL:
|
|
177
|
+
return { stopLossType: enums_1.CloseToAssetType.COLLATERAL, takeProfitType: enums_1.CloseToAssetType.COLLATERAL };
|
|
178
|
+
default:
|
|
179
|
+
throw new Error('CloseStrategyType not supported');
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
exports.getStopLossAndTakeProfitTypeByCloseStrategyType = getStopLossAndTakeProfitTypeByCloseStrategyType;
|
|
@@ -55,6 +55,10 @@ export type Subscribe = ContractEventLog<{
|
|
|
55
55
|
proxy: string;
|
|
56
56
|
subHash: string;
|
|
57
57
|
subStruct: StrategyModel.StrategySubStructOutput;
|
|
58
|
+
0: string;
|
|
59
|
+
1: string;
|
|
60
|
+
2: string;
|
|
61
|
+
3: StrategyModel.StrategySubStructOutput;
|
|
58
62
|
}>;
|
|
59
63
|
export type UpdateData = ContractEventLog<{
|
|
60
64
|
subId: string;
|
package/cjs/types/enums.d.ts
CHANGED
|
@@ -17,6 +17,28 @@ export declare enum BundleProtocols {
|
|
|
17
17
|
Yearn = "yearn",
|
|
18
18
|
Rari = "rari"
|
|
19
19
|
}
|
|
20
|
+
export declare enum CollActionType {
|
|
21
|
+
SUPPLY = 0,
|
|
22
|
+
WITHDRAW = 1
|
|
23
|
+
}
|
|
24
|
+
export declare enum DebtActionType {
|
|
25
|
+
PAYBACK = 0,
|
|
26
|
+
BORROW = 1
|
|
27
|
+
}
|
|
28
|
+
export declare enum CloseStrategyType {
|
|
29
|
+
TAKE_PROFIT_IN_COLLATERAL = 0,
|
|
30
|
+
STOP_LOSS_IN_COLLATERAL = 1,
|
|
31
|
+
TAKE_PROFIT_IN_DEBT = 2,
|
|
32
|
+
STOP_LOSS_IN_DEBT = 3,
|
|
33
|
+
TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL = 4,
|
|
34
|
+
TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT = 5,
|
|
35
|
+
TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT = 6,
|
|
36
|
+
TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL = 7
|
|
37
|
+
}
|
|
38
|
+
export declare enum CloseToAssetType {
|
|
39
|
+
COLLATERAL = 0,
|
|
40
|
+
DEBT = 1
|
|
41
|
+
}
|
|
20
42
|
/**
|
|
21
43
|
* @dev Follow the naming convention:
|
|
22
44
|
* - Enum name consists of two parts, name and version
|
|
@@ -28,6 +50,7 @@ export declare namespace ProtocolIdentifiers {
|
|
|
28
50
|
enum StrategiesAutomation {
|
|
29
51
|
MakerDAO = "MakerDAO",
|
|
30
52
|
Liquity = "Liquity",
|
|
53
|
+
LiquityV2 = "Liquity__V2",
|
|
31
54
|
ChickenBonds = "Chicken Bonds",
|
|
32
55
|
CompoundV2 = "Compound__V2",
|
|
33
56
|
CompoundV3 = "Compound__V3",
|
|
@@ -37,7 +60,8 @@ export declare namespace ProtocolIdentifiers {
|
|
|
37
60
|
Exchange = "Exchange",
|
|
38
61
|
Spark = "Spark",
|
|
39
62
|
CrvUSD = "CurveUSD",
|
|
40
|
-
MorphoBlue = "MorphoBlue"
|
|
63
|
+
MorphoBlue = "MorphoBlue",
|
|
64
|
+
FluidT1 = "FluidT1"
|
|
41
65
|
}
|
|
42
66
|
enum LegacyAutomation {
|
|
43
67
|
MakerDAO = "MakerDAO",
|
|
@@ -60,7 +84,8 @@ export declare namespace Strategies {
|
|
|
60
84
|
LIQUITY_DSR_PAYBACK = 69,
|
|
61
85
|
LIQUITY_DSR_SUPPLY = 70,
|
|
62
86
|
LIQUITY_DEBT_IN_FRONT_REPAY = 75,
|
|
63
|
-
CURVEUSD_PAYBACK = 92
|
|
87
|
+
CURVEUSD_PAYBACK = 92,
|
|
88
|
+
LIQUITY_V2_PAYBACK = 113
|
|
64
89
|
}
|
|
65
90
|
enum OptimismIds {
|
|
66
91
|
EXCHANGE_DCA = 8,
|
|
@@ -88,6 +113,7 @@ export declare namespace Strategies {
|
|
|
88
113
|
CloseToCollateralWithGasPrice = "close-to-collateral-with-gas-price",
|
|
89
114
|
CloseOnPriceToDebt = "close-on-price-to-debt",
|
|
90
115
|
CloseOnPriceToColl = "close-on-price-to-collateral",
|
|
116
|
+
CloseOnPrice = "close-on-price",
|
|
91
117
|
TrailingStopToColl = "trailing-stop-to-collateral",
|
|
92
118
|
TrailingStopToDebt = "trailing-stop-to-debt",
|
|
93
119
|
Rebond = "rebond",
|
|
@@ -98,6 +124,7 @@ export declare namespace Strategies {
|
|
|
98
124
|
DebtInFrontRepay = "debt-in-front-repay",
|
|
99
125
|
OpenOrderFromCollateral = "open-order-from-collateral",
|
|
100
126
|
OpenOrderFromDebt = "open-order-from-debt",
|
|
127
|
+
BoostOnPrice = "boost-on-price",
|
|
101
128
|
RepayOnPrice = "repay-on-price"
|
|
102
129
|
}
|
|
103
130
|
enum IdOverrides {
|
|
@@ -151,7 +178,15 @@ export declare namespace Bundles {
|
|
|
151
178
|
MORPHO_BLUE_EOA_REPAY = 34,
|
|
152
179
|
MORPHO_BLUE_EOA_BOOST = 35,
|
|
153
180
|
AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 36,
|
|
154
|
-
AAVE_V3_REPAY_ON_PRICE = 37
|
|
181
|
+
AAVE_V3_REPAY_ON_PRICE = 37,
|
|
182
|
+
MORPHO_BLUE_BOOST_ON_PRICE = 38,
|
|
183
|
+
LIQUITY_V2_REPAY = 39,
|
|
184
|
+
LIQUITY_V2_BOOST = 40,
|
|
185
|
+
LIQUITY_V2_CLOSE = 41,
|
|
186
|
+
LIQUITY_V2_REPAY_ON_PRICE = 42,
|
|
187
|
+
LIQUITY_V2_BOOST_ON_PRICE = 43,
|
|
188
|
+
FLUID_T1_REPAY = 44,
|
|
189
|
+
FLUID_T1_BOOST = 45
|
|
155
190
|
}
|
|
156
191
|
enum OptimismIds {
|
|
157
192
|
AAVE_V3_REPAY = 0,
|
|
@@ -171,7 +206,10 @@ export declare namespace Bundles {
|
|
|
171
206
|
MORPHO_BLUE_REPAY = 8,
|
|
172
207
|
MORPHO_BLUE_BOOST = 9,
|
|
173
208
|
AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 10,
|
|
174
|
-
AAVE_V3_REPAY_ON_PRICE = 11
|
|
209
|
+
AAVE_V3_REPAY_ON_PRICE = 11,
|
|
210
|
+
MORPHO_BLUE_BOOST_ON_PRICE = 12,
|
|
211
|
+
FLUID_T1_REPAY = 13,
|
|
212
|
+
FLUID_T1_BOOST = 14
|
|
175
213
|
}
|
|
176
214
|
enum ArbitrumIds {
|
|
177
215
|
AAVE_V3_REPAY = 0,
|
|
@@ -181,6 +219,8 @@ export declare namespace Bundles {
|
|
|
181
219
|
COMP_V3_SW_REPAY_BUNDLE = 4,
|
|
182
220
|
COMP_V3_SW_BOOST_BUNDLE = 5,
|
|
183
221
|
AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 6,
|
|
184
|
-
AAVE_V3_REPAY_ON_PRICE = 7
|
|
222
|
+
AAVE_V3_REPAY_ON_PRICE = 7,
|
|
223
|
+
FLUID_T1_REPAY = 8,
|
|
224
|
+
FLUID_T1_BOOST = 9
|
|
185
225
|
}
|
|
186
226
|
}
|