@defisaver/automation-sdk 3.2.0 → 3.2.2
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/.env +4 -5
- package/cjs/automation/private/StrategiesAutomation.js +5 -6
- 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 -6
- 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 -5
- 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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EthereumAddress } from '../types';
|
|
2
|
-
import type { OrderType } from '../types/enums';
|
|
2
|
+
import type { CloseStrategyType, OrderType } from '../types/enums';
|
|
3
3
|
import { ChainId, RatioState } from '../types/enums';
|
|
4
4
|
export declare const makerRepayFromSavingsSubData: {
|
|
5
5
|
encode(vaultId: number, targetRatioPercentage: number, chainId: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress): string[];
|
|
@@ -190,3 +190,65 @@ export declare const aaveV3LeverageManagementOnPriceSubData: {
|
|
|
190
190
|
targetRatio: number;
|
|
191
191
|
};
|
|
192
192
|
};
|
|
193
|
+
export declare const liquityV2LeverageManagementSubData: {
|
|
194
|
+
encode: (market: EthereumAddress, troveId: string, collToken: EthereumAddress, boldToken: EthereumAddress, ratioState: RatioState, targetRatio: number) => string[];
|
|
195
|
+
decode: (subData: string[]) => {
|
|
196
|
+
market: string;
|
|
197
|
+
troveId: string;
|
|
198
|
+
collToken: string;
|
|
199
|
+
boldToken: string;
|
|
200
|
+
ratioState: RatioState;
|
|
201
|
+
targetRatio: number;
|
|
202
|
+
};
|
|
203
|
+
};
|
|
204
|
+
export declare const liquityV2CloseSubData: {
|
|
205
|
+
encode(market: EthereumAddress, troveId: string, collToken: EthereumAddress, boldToken: EthereumAddress, closeType: CloseStrategyType): string[];
|
|
206
|
+
decode(subData: string[]): {
|
|
207
|
+
market: EthereumAddress;
|
|
208
|
+
troveId: string;
|
|
209
|
+
collToken: EthereumAddress;
|
|
210
|
+
boldToken: EthereumAddress;
|
|
211
|
+
closeType: CloseStrategyType;
|
|
212
|
+
};
|
|
213
|
+
};
|
|
214
|
+
export declare const liquityV2LeverageManagementOnPriceSubData: {
|
|
215
|
+
encode(market: EthereumAddress, troveId: string, collToken: EthereumAddress, boldToken: EthereumAddress, targetRatio: number, isRepayOnPrice: boolean): string[];
|
|
216
|
+
decode(subData: string[]): {
|
|
217
|
+
market: EthereumAddress;
|
|
218
|
+
troveId: string;
|
|
219
|
+
collToken: EthereumAddress;
|
|
220
|
+
boldToken: EthereumAddress;
|
|
221
|
+
targetRatio: number;
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
export declare const morphoBlueLeverageManagementOnPriceSubData: {
|
|
225
|
+
encode(loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, targetRatio: number, user: EthereumAddress): string[];
|
|
226
|
+
decode(subData: string[]): {
|
|
227
|
+
loanToken: string;
|
|
228
|
+
collToken: string;
|
|
229
|
+
oracle: string;
|
|
230
|
+
irm: string;
|
|
231
|
+
lltv: string;
|
|
232
|
+
targetRatio: number;
|
|
233
|
+
user: string;
|
|
234
|
+
};
|
|
235
|
+
};
|
|
236
|
+
export declare const liquityV2PaybackSubData: {
|
|
237
|
+
encode: (market: EthereumAddress, troveId: string, boldToken: EthereumAddress, targetRatio: number, ratioState: RatioState) => string[];
|
|
238
|
+
decode: (subData: string[]) => {
|
|
239
|
+
market: string;
|
|
240
|
+
troveId: string;
|
|
241
|
+
boldToken: string;
|
|
242
|
+
ratioState: RatioState;
|
|
243
|
+
targetRatio: number;
|
|
244
|
+
};
|
|
245
|
+
};
|
|
246
|
+
export declare const fluidLeverageManagementSubData: {
|
|
247
|
+
encode: (nftId: string, vault: EthereumAddress, ratioState: RatioState, targetRatio: number) => string[];
|
|
248
|
+
decode: (subData: string[]) => {
|
|
249
|
+
nftId: string;
|
|
250
|
+
vault: string;
|
|
251
|
+
ratioState: RatioState;
|
|
252
|
+
targetRatio: number;
|
|
253
|
+
};
|
|
254
|
+
};
|
|
@@ -3,7 +3,7 @@ import AbiCoder from 'web3-eth-abi';
|
|
|
3
3
|
import { fromWei, toWei } from 'web3-utils';
|
|
4
4
|
import { assetAmountInEth, getAssetInfo, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
5
5
|
import { otherAddresses } from '@defisaver/sdk';
|
|
6
|
-
import { ChainId, RatioState } from '../types/enums';
|
|
6
|
+
import { ChainId, CollActionType, DebtActionType, RatioState, } from '../types/enums';
|
|
7
7
|
import { ZERO_ADDRESS } from '../constants';
|
|
8
8
|
import { compareAddresses, ratioPercentageToWei, weiToRatioPercentage } from './utils';
|
|
9
9
|
export const makerRepayFromSavingsSubData = {
|
|
@@ -467,3 +467,197 @@ export const aaveV3LeverageManagementOnPriceSubData = {
|
|
|
467
467
|
};
|
|
468
468
|
},
|
|
469
469
|
};
|
|
470
|
+
export const liquityV2LeverageManagementSubData = {
|
|
471
|
+
encode: (market, troveId, collToken, boldToken, ratioState, targetRatio) => {
|
|
472
|
+
const marketEncoded = AbiCoder.encodeParameter('address', market);
|
|
473
|
+
const troveIdEncoded = AbiCoder.encodeParameter('uint256', troveId);
|
|
474
|
+
const collTokenEncoded = AbiCoder.encodeParameter('address', collToken);
|
|
475
|
+
const boldTokenEncoded = AbiCoder.encodeParameter('address', boldToken);
|
|
476
|
+
const ratioStateEncoded = AbiCoder.encodeParameter('uint8', ratioState);
|
|
477
|
+
const targetRatioEncoded = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
478
|
+
const isRepay = ratioState === RatioState.UNDER;
|
|
479
|
+
const collActionType = isRepay ? CollActionType.WITHDRAW : CollActionType.SUPPLY;
|
|
480
|
+
const debtActionType = isRepay ? DebtActionType.PAYBACK : DebtActionType.BORROW;
|
|
481
|
+
const collActionTypeEncoded = AbiCoder.encodeParameter('uint8', collActionType);
|
|
482
|
+
const debtActionTypeEncoded = AbiCoder.encodeParameter('uint8', debtActionType);
|
|
483
|
+
return [
|
|
484
|
+
marketEncoded,
|
|
485
|
+
troveIdEncoded,
|
|
486
|
+
collTokenEncoded,
|
|
487
|
+
boldTokenEncoded,
|
|
488
|
+
ratioStateEncoded,
|
|
489
|
+
targetRatioEncoded,
|
|
490
|
+
collActionTypeEncoded,
|
|
491
|
+
debtActionTypeEncoded,
|
|
492
|
+
];
|
|
493
|
+
},
|
|
494
|
+
decode: (subData) => {
|
|
495
|
+
const market = AbiCoder.decodeParameter('address', subData[0]);
|
|
496
|
+
const troveId = AbiCoder.decodeParameter('uint256', subData[1]);
|
|
497
|
+
const collToken = AbiCoder.decodeParameter('address', subData[2]);
|
|
498
|
+
const boldToken = AbiCoder.decodeParameter('address', subData[3]);
|
|
499
|
+
const ratioState = AbiCoder.decodeParameter('uint8', subData[4]);
|
|
500
|
+
const weiRatio = AbiCoder.decodeParameter('uint256', subData[5]);
|
|
501
|
+
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
502
|
+
return {
|
|
503
|
+
market, troveId, collToken, boldToken, ratioState, targetRatio,
|
|
504
|
+
};
|
|
505
|
+
},
|
|
506
|
+
};
|
|
507
|
+
export const liquityV2CloseSubData = {
|
|
508
|
+
encode(market, troveId, collToken, boldToken, closeType) {
|
|
509
|
+
const marketEncoded = AbiCoder.encodeParameter('address', market);
|
|
510
|
+
const troveIdEncoded = AbiCoder.encodeParameter('uint256', troveId);
|
|
511
|
+
const collAddrEncoded = AbiCoder.encodeParameter('address', collToken);
|
|
512
|
+
const boldTokenEncoded = AbiCoder.encodeParameter('address', boldToken);
|
|
513
|
+
const wethAddress = getAssetInfo('WETH').address;
|
|
514
|
+
const wethAddressEncoded = AbiCoder.encodeParameter('address', wethAddress);
|
|
515
|
+
const gasCompensation = new Dec('0.0375').mul(1e18).toString();
|
|
516
|
+
const gasCompensationEncoded = AbiCoder.encodeParameter('uint256', gasCompensation);
|
|
517
|
+
const closeTypeEncoded = AbiCoder.encodeParameter('uint8', closeType);
|
|
518
|
+
return [
|
|
519
|
+
marketEncoded,
|
|
520
|
+
troveIdEncoded,
|
|
521
|
+
collAddrEncoded,
|
|
522
|
+
boldTokenEncoded,
|
|
523
|
+
wethAddressEncoded,
|
|
524
|
+
gasCompensationEncoded,
|
|
525
|
+
closeTypeEncoded,
|
|
526
|
+
];
|
|
527
|
+
},
|
|
528
|
+
decode(subData) {
|
|
529
|
+
const market = AbiCoder.decodeParameter('address', subData[0]);
|
|
530
|
+
const troveId = AbiCoder.decodeParameter('uint256', subData[1]);
|
|
531
|
+
const collToken = AbiCoder.decodeParameter('address', subData[2]);
|
|
532
|
+
const boldToken = AbiCoder.decodeParameter('address', subData[3]);
|
|
533
|
+
// skip wethAddress and gasCompensation
|
|
534
|
+
const closeType = AbiCoder.decodeParameter('uint8', subData[6]);
|
|
535
|
+
return {
|
|
536
|
+
market, troveId, collToken, boldToken, closeType,
|
|
537
|
+
};
|
|
538
|
+
},
|
|
539
|
+
};
|
|
540
|
+
export const liquityV2LeverageManagementOnPriceSubData = {
|
|
541
|
+
encode(market, troveId, collToken, boldToken, targetRatio, isRepayOnPrice) {
|
|
542
|
+
const encodedMarket = AbiCoder.encodeParameter('address', market);
|
|
543
|
+
const encodedTroveId = AbiCoder.encodeParameter('uint256', troveId);
|
|
544
|
+
const encodedCollToken = AbiCoder.encodeParameter('address', collToken);
|
|
545
|
+
const encodedBoldToken = AbiCoder.encodeParameter('address', boldToken);
|
|
546
|
+
const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
547
|
+
const collActionType = isRepayOnPrice ? CollActionType.WITHDRAW : CollActionType.SUPPLY;
|
|
548
|
+
const debtActionType = isRepayOnPrice ? DebtActionType.PAYBACK : DebtActionType.BORROW;
|
|
549
|
+
const encodedCollActionType = AbiCoder.encodeParameter('uint8', collActionType);
|
|
550
|
+
const encodedDebtActionType = AbiCoder.encodeParameter('uint8', debtActionType);
|
|
551
|
+
return [
|
|
552
|
+
encodedMarket,
|
|
553
|
+
encodedTroveId,
|
|
554
|
+
encodedCollToken,
|
|
555
|
+
encodedBoldToken,
|
|
556
|
+
encodedTargetRatio,
|
|
557
|
+
encodedCollActionType,
|
|
558
|
+
encodedDebtActionType,
|
|
559
|
+
];
|
|
560
|
+
},
|
|
561
|
+
decode(subData) {
|
|
562
|
+
const market = AbiCoder.decodeParameter('address', subData[0]);
|
|
563
|
+
const troveId = AbiCoder.decodeParameter('uint256', subData[1]);
|
|
564
|
+
const collToken = AbiCoder.decodeParameter('address', subData[2]);
|
|
565
|
+
const boldToken = AbiCoder.decodeParameter('address', subData[3]);
|
|
566
|
+
const weiRatio = AbiCoder.decodeParameter('uint256', subData[4]);
|
|
567
|
+
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
568
|
+
return {
|
|
569
|
+
market, troveId, collToken, boldToken, targetRatio,
|
|
570
|
+
};
|
|
571
|
+
},
|
|
572
|
+
};
|
|
573
|
+
export const morphoBlueLeverageManagementOnPriceSubData = {
|
|
574
|
+
encode(loanToken, collToken, oracle, irm, lltv, targetRatio, user) {
|
|
575
|
+
const loanTokenEncoded = AbiCoder.encodeParameter('address', loanToken);
|
|
576
|
+
const collTokenEncoded = AbiCoder.encodeParameter('address', collToken);
|
|
577
|
+
const oracleEncoded = AbiCoder.encodeParameter('address', oracle);
|
|
578
|
+
const irmEncoded = AbiCoder.encodeParameter('address', irm);
|
|
579
|
+
const lltvEncoded = AbiCoder.encodeParameter('uint256', lltv);
|
|
580
|
+
const targetRatioEncoded = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
581
|
+
const userEncoded = AbiCoder.encodeParameter('address', user);
|
|
582
|
+
return [loanTokenEncoded, collTokenEncoded, oracleEncoded, irmEncoded, lltvEncoded, targetRatioEncoded, userEncoded];
|
|
583
|
+
},
|
|
584
|
+
decode(subData) {
|
|
585
|
+
const loanToken = AbiCoder.decodeParameter('address', subData[0]);
|
|
586
|
+
const collToken = AbiCoder.decodeParameter('address', subData[1]);
|
|
587
|
+
const oracle = AbiCoder.decodeParameter('address', subData[2]);
|
|
588
|
+
const irm = AbiCoder.decodeParameter('address', subData[3]);
|
|
589
|
+
const lltv = AbiCoder.decodeParameter('uint256', subData[4]);
|
|
590
|
+
const weiRatio = AbiCoder.decodeParameter('uint256', subData[5]);
|
|
591
|
+
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
592
|
+
const user = AbiCoder.decodeParameter('address', subData[6]);
|
|
593
|
+
return {
|
|
594
|
+
loanToken,
|
|
595
|
+
collToken,
|
|
596
|
+
oracle,
|
|
597
|
+
irm,
|
|
598
|
+
lltv,
|
|
599
|
+
targetRatio,
|
|
600
|
+
user,
|
|
601
|
+
};
|
|
602
|
+
},
|
|
603
|
+
};
|
|
604
|
+
export const liquityV2PaybackSubData = {
|
|
605
|
+
encode: (market, troveId, boldToken, targetRatio, ratioState) => {
|
|
606
|
+
const marketEncoded = AbiCoder.encodeParameter('address', market);
|
|
607
|
+
const troveIdEncoded = AbiCoder.encodeParameter('uint256', troveId);
|
|
608
|
+
const boldTokenEncoded = AbiCoder.encodeParameter('address', boldToken);
|
|
609
|
+
const targetRatioEncoded = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
610
|
+
const ratioStateEncoded = AbiCoder.encodeParameter('uint8', ratioState);
|
|
611
|
+
return [
|
|
612
|
+
marketEncoded,
|
|
613
|
+
troveIdEncoded,
|
|
614
|
+
boldTokenEncoded,
|
|
615
|
+
targetRatioEncoded,
|
|
616
|
+
ratioStateEncoded,
|
|
617
|
+
];
|
|
618
|
+
},
|
|
619
|
+
decode: (subData) => {
|
|
620
|
+
const market = AbiCoder.decodeParameter('address', subData[0]);
|
|
621
|
+
const troveId = AbiCoder.decodeParameter('uint256', subData[1]);
|
|
622
|
+
const boldToken = AbiCoder.decodeParameter('address', subData[2]);
|
|
623
|
+
const weiRatio = AbiCoder.decodeParameter('uint256', subData[3]);
|
|
624
|
+
const ratioState = AbiCoder.decodeParameter('uint8', subData[4]);
|
|
625
|
+
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
626
|
+
return {
|
|
627
|
+
market, troveId, boldToken, ratioState, targetRatio,
|
|
628
|
+
};
|
|
629
|
+
},
|
|
630
|
+
};
|
|
631
|
+
export const fluidLeverageManagementSubData = {
|
|
632
|
+
encode: (nftId, vault, ratioState, targetRatio) => {
|
|
633
|
+
const nftIdEncoded = AbiCoder.encodeParameter('uint256', nftId);
|
|
634
|
+
const vaultEncoded = AbiCoder.encodeParameter('address', vault);
|
|
635
|
+
const ratioStateEncoded = AbiCoder.encodeParameter('uint8', ratioState);
|
|
636
|
+
const targetRatioEncoded = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
637
|
+
const wrapEthEncoded = AbiCoder.encodeParameter('bool', true);
|
|
638
|
+
const isRepay = ratioState === RatioState.UNDER;
|
|
639
|
+
const collActionType = isRepay ? CollActionType.WITHDRAW : CollActionType.SUPPLY;
|
|
640
|
+
const debtActionType = isRepay ? DebtActionType.PAYBACK : DebtActionType.BORROW;
|
|
641
|
+
const collActionTypeEncoded = AbiCoder.encodeParameter('uint8', collActionType);
|
|
642
|
+
const debtActionTypeEncoded = AbiCoder.encodeParameter('uint8', debtActionType);
|
|
643
|
+
return [
|
|
644
|
+
nftIdEncoded,
|
|
645
|
+
vaultEncoded,
|
|
646
|
+
ratioStateEncoded,
|
|
647
|
+
targetRatioEncoded,
|
|
648
|
+
wrapEthEncoded,
|
|
649
|
+
collActionTypeEncoded,
|
|
650
|
+
debtActionTypeEncoded,
|
|
651
|
+
];
|
|
652
|
+
},
|
|
653
|
+
decode: (subData) => {
|
|
654
|
+
const nftId = AbiCoder.decodeParameter('uint256', subData[0]);
|
|
655
|
+
const vault = AbiCoder.decodeParameter('address', subData[1]);
|
|
656
|
+
const ratioState = AbiCoder.decodeParameter('uint8', subData[2]);
|
|
657
|
+
const weiRatio = AbiCoder.decodeParameter('uint256', subData[3]);
|
|
658
|
+
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
659
|
+
return {
|
|
660
|
+
nftId, vault, ratioState, targetRatio,
|
|
661
|
+
};
|
|
662
|
+
},
|
|
663
|
+
};
|
|
@@ -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
|
+
};
|
|
@@ -336,3 +336,83 @@ export const morphoBlueRatioTrigger = {
|
|
|
336
336
|
};
|
|
337
337
|
},
|
|
338
338
|
};
|
|
339
|
+
export const liquityV2RatioTrigger = {
|
|
340
|
+
encode(market, troveId, ratioPercentage, ratioState) {
|
|
341
|
+
const ratioWei = ratioPercentageToWei(ratioPercentage);
|
|
342
|
+
return [AbiCoder.encodeParameters(['address', 'uint256', 'uint256', 'uint8'], [market, troveId, ratioWei, ratioState])];
|
|
343
|
+
},
|
|
344
|
+
decode(triggerData) {
|
|
345
|
+
const decodedData = AbiCoder.decodeParameters(['address', 'uint256', 'uint256', 'uint8'], triggerData[0]);
|
|
346
|
+
return {
|
|
347
|
+
market: decodedData[0],
|
|
348
|
+
troveId: decodedData[1],
|
|
349
|
+
ratio: weiToRatioPercentage(decodedData[2]),
|
|
350
|
+
ratioState: Number(decodedData[3]),
|
|
351
|
+
};
|
|
352
|
+
},
|
|
353
|
+
};
|
|
354
|
+
export const liquityV2QuotePriceTrigger = {
|
|
355
|
+
encode(market, price, ratioState) {
|
|
356
|
+
// Price is always in 18 decimals
|
|
357
|
+
const _price = new Dec(price.toString()).mul(Math.pow(10, 18)).floor().toString();
|
|
358
|
+
return [AbiCoder.encodeParameters(['address', 'uint256', 'uint8'], [market, _price, ratioState])];
|
|
359
|
+
},
|
|
360
|
+
decode(triggerData) {
|
|
361
|
+
const decodedData = AbiCoder.decodeParameters(['address', 'uint256', 'uint8'], triggerData[0]);
|
|
362
|
+
const price = new Dec(decodedData[1]).div(Math.pow(10, 18)).toDP(18).toString();
|
|
363
|
+
return {
|
|
364
|
+
market: decodedData[0],
|
|
365
|
+
price,
|
|
366
|
+
ratioState: Number(decodedData[2]),
|
|
367
|
+
};
|
|
368
|
+
},
|
|
369
|
+
};
|
|
370
|
+
export const closePriceTrigger = {
|
|
371
|
+
encode(tokenAddr, lowerPrice, upperPrice) {
|
|
372
|
+
const lowerPriceFormatted = new Dec(lowerPrice).mul(1e8).floor().toString();
|
|
373
|
+
const upperPriceFormatted = new Dec(upperPrice).mul(1e8).floor().toString();
|
|
374
|
+
return [
|
|
375
|
+
AbiCoder.encodeParameters(['address', 'uint256', 'uint256'], [tokenAddr, lowerPriceFormatted, upperPriceFormatted]),
|
|
376
|
+
];
|
|
377
|
+
},
|
|
378
|
+
decode(triggerData) {
|
|
379
|
+
const decodedData = AbiCoder.decodeParameters(['address', 'uint256', 'uint256'], triggerData[0]);
|
|
380
|
+
return {
|
|
381
|
+
tokenAddr: decodedData[0],
|
|
382
|
+
lowerPrice: new Dec(decodedData[1]).div(1e8).toString(),
|
|
383
|
+
upperPrice: new Dec(decodedData[2]).div(1e8).toString(),
|
|
384
|
+
};
|
|
385
|
+
},
|
|
386
|
+
};
|
|
387
|
+
export const morphoBluePriceTrigger = {
|
|
388
|
+
encode(oracle, collateralToken, loanToken, price, priceState) {
|
|
389
|
+
const _price = new Dec(price.toString()).mul(1e8).floor().toString();
|
|
390
|
+
return [
|
|
391
|
+
AbiCoder.encodeParameters(['address', 'address', 'address', 'uint256', 'uint8'], [oracle, collateralToken, loanToken, _price, priceState]),
|
|
392
|
+
];
|
|
393
|
+
},
|
|
394
|
+
decode(triggerData) {
|
|
395
|
+
const decodedData = AbiCoder.decodeParameters(['address', 'address', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
396
|
+
return {
|
|
397
|
+
oracle: decodedData[0],
|
|
398
|
+
collateralToken: decodedData[1],
|
|
399
|
+
loanToken: decodedData[2],
|
|
400
|
+
price: new Dec(decodedData[3]).div(1e8).toString(),
|
|
401
|
+
priceState: Number(decodedData[4]),
|
|
402
|
+
};
|
|
403
|
+
},
|
|
404
|
+
};
|
|
405
|
+
export const fluidRatioTrigger = {
|
|
406
|
+
encode(nftId, ratioPercentage, ratioState) {
|
|
407
|
+
const ratioWei = ratioPercentageToWei(ratioPercentage);
|
|
408
|
+
return [AbiCoder.encodeParameters(['uint256', 'uint256', 'uint8'], [nftId, ratioWei, ratioState])];
|
|
409
|
+
},
|
|
410
|
+
decode(triggerData) {
|
|
411
|
+
const decodedData = AbiCoder.decodeParameters(['uint256', 'uint256', 'uint8'], triggerData[0]);
|
|
412
|
+
return {
|
|
413
|
+
nftId: decodedData[0],
|
|
414
|
+
ratio: weiToRatioPercentage(decodedData[1]),
|
|
415
|
+
ratioState: Number(decodedData[2]),
|
|
416
|
+
};
|
|
417
|
+
},
|
|
418
|
+
};
|
package/esm/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/esm/services/utils.js
CHANGED
|
@@ -2,7 +2,7 @@ import Dec from 'decimal.js';
|
|
|
2
2
|
import * as web3Utils from 'web3-utils';
|
|
3
3
|
import AbiCoder from 'web3-eth-abi';
|
|
4
4
|
import { getAssetInfo, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
5
|
-
import { ChainId, RatioState } from '../types/enums';
|
|
5
|
+
import { ChainId, CloseStrategyType, CloseToAssetType, RatioState, } from '../types/enums';
|
|
6
6
|
export function isDefined(value) {
|
|
7
7
|
return value !== undefined && value !== null;
|
|
8
8
|
}
|
|
@@ -80,3 +80,52 @@ export function getRatioStateInfoForAaveCloseStrategy(currentRatioState, collAss
|
|
|
80
80
|
export function getPositionId(...args) {
|
|
81
81
|
return args.map(arg => arg.toString().toLowerCase().split(' ').join('_')).join('-');
|
|
82
82
|
}
|
|
83
|
+
export function getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType) {
|
|
84
|
+
const isStopLoss = stopLossPrice > 0;
|
|
85
|
+
const isTakeProfit = takeProfitPrice > 0;
|
|
86
|
+
if (!isStopLoss && !isTakeProfit) {
|
|
87
|
+
throw new Error('CloseOnPrice: At least one price must be defined');
|
|
88
|
+
}
|
|
89
|
+
if (isStopLoss && isTakeProfit) {
|
|
90
|
+
if (stopLossType === CloseToAssetType.COLLATERAL && takeProfitType === CloseToAssetType.COLLATERAL) {
|
|
91
|
+
return CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL;
|
|
92
|
+
}
|
|
93
|
+
if (stopLossType === CloseToAssetType.COLLATERAL) {
|
|
94
|
+
return CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL;
|
|
95
|
+
}
|
|
96
|
+
if (takeProfitType === CloseToAssetType.COLLATERAL) {
|
|
97
|
+
return CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT;
|
|
98
|
+
}
|
|
99
|
+
return CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT;
|
|
100
|
+
}
|
|
101
|
+
if (isStopLoss) {
|
|
102
|
+
return stopLossType === CloseToAssetType.COLLATERAL
|
|
103
|
+
? CloseStrategyType.STOP_LOSS_IN_COLLATERAL
|
|
104
|
+
: CloseStrategyType.STOP_LOSS_IN_DEBT;
|
|
105
|
+
}
|
|
106
|
+
return takeProfitType === CloseToAssetType.COLLATERAL
|
|
107
|
+
? CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL
|
|
108
|
+
: CloseStrategyType.TAKE_PROFIT_IN_DEBT;
|
|
109
|
+
}
|
|
110
|
+
export function getStopLossAndTakeProfitTypeByCloseStrategyType(closeStrategyType) {
|
|
111
|
+
switch (closeStrategyType) {
|
|
112
|
+
case CloseStrategyType.STOP_LOSS_IN_COLLATERAL:
|
|
113
|
+
return { stopLossType: CloseToAssetType.COLLATERAL, takeProfitType: undefined };
|
|
114
|
+
case CloseStrategyType.STOP_LOSS_IN_DEBT:
|
|
115
|
+
return { stopLossType: CloseToAssetType.DEBT, takeProfitType: undefined };
|
|
116
|
+
case CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL:
|
|
117
|
+
return { stopLossType: undefined, takeProfitType: CloseToAssetType.COLLATERAL };
|
|
118
|
+
case CloseStrategyType.TAKE_PROFIT_IN_DEBT:
|
|
119
|
+
return { stopLossType: undefined, takeProfitType: CloseToAssetType.DEBT };
|
|
120
|
+
case CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT:
|
|
121
|
+
return { stopLossType: CloseToAssetType.DEBT, takeProfitType: CloseToAssetType.COLLATERAL };
|
|
122
|
+
case CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL:
|
|
123
|
+
return { stopLossType: CloseToAssetType.COLLATERAL, takeProfitType: CloseToAssetType.DEBT };
|
|
124
|
+
case CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT:
|
|
125
|
+
return { stopLossType: CloseToAssetType.DEBT, takeProfitType: CloseToAssetType.DEBT };
|
|
126
|
+
case CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL:
|
|
127
|
+
return { stopLossType: CloseToAssetType.COLLATERAL, takeProfitType: CloseToAssetType.COLLATERAL };
|
|
128
|
+
default:
|
|
129
|
+
throw new Error('CloseStrategyType not supported');
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -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/esm/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
|
}
|