@defisaver/automation-sdk 3.3.15 → 3.3.16-liq-prot-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/constants/index.js +145 -0
- package/cjs/index.d.ts +2 -2
- package/cjs/index.js +5 -2
- package/cjs/services/strategiesService.js +158 -9
- package/cjs/services/strategySubService.d.ts +17 -16
- package/cjs/services/strategySubService.js +69 -28
- package/cjs/services/strategySubService.test.js +69 -40
- package/cjs/services/subDataService.d.ts +70 -20
- package/cjs/services/subDataService.js +23 -79
- package/cjs/services/subDataService.test.js +117 -202
- package/cjs/services/triggerService.test.js +60 -0
- package/cjs/services/utils.d.ts +2 -1
- package/cjs/services/utils.js +14 -1
- package/cjs/types/enums.d.ts +39 -6
- package/cjs/types/enums.js +33 -0
- package/esm/constants/index.js +145 -0
- package/esm/index.d.ts +2 -2
- package/esm/index.js +5 -2
- package/esm/services/strategiesService.js +158 -9
- package/esm/services/strategySubService.d.ts +17 -16
- package/esm/services/strategySubService.js +69 -28
- package/esm/services/strategySubService.test.js +70 -38
- package/esm/services/subDataService.d.ts +70 -20
- package/esm/services/subDataService.js +21 -77
- package/esm/services/subDataService.test.js +118 -200
- package/esm/services/triggerService.test.js +61 -1
- package/esm/services/utils.d.ts +2 -1
- package/esm/services/utils.js +13 -1
- package/esm/types/enums.d.ts +39 -6
- package/esm/types/enums.js +33 -0
- package/package.json +1 -1
- package/src/constants/index.ts +147 -1
- package/src/index.ts +22 -6
- package/src/services/strategiesService.ts +222 -9
- package/src/services/strategySubService.test.ts +86 -46
- package/src/services/strategySubService.ts +166 -39
- package/src/services/subDataService.test.ts +128 -214
- package/src/services/subDataService.ts +42 -106
- package/src/services/triggerService.test.ts +69 -0
- package/src/services/utils.test.ts +1 -1
- package/src/services/utils.ts +15 -1
- package/src/types/enums.ts +33 -2
|
@@ -1,26 +1,24 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { CloseToAssetType, Bundles, ChainId, RatioState, Strategies } from '../types/enums';
|
|
1
|
+
import { Bundles, ChainId, CloseToAssetType, RatioState, Strategies } from '../types/enums';
|
|
3
2
|
import type { EthereumAddress, StrategyOrBundleIds } from '../types';
|
|
3
|
+
import type { OrderType } from '../types/enums';
|
|
4
4
|
export declare const makerEncode: {
|
|
5
5
|
repayFromSavings(bundleId: StrategyOrBundleIds, vaultId: number, triggerRepayRatio: number, targetRepayRatio: number, isBundle?: boolean, chainId?: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress): (boolean | string[] | Strategies.MainnetIds | Strategies.OptimismIds | Strategies.ArbitrumIds | Strategies.BaseIds | Bundles.MainnetIds | Bundles.OptimismIds | Bundles.ArbitrumIds | Bundles.BaseIds)[];
|
|
6
6
|
closeOnPrice(vaultId: number, ratioState: RatioState, price: string, closeToAssetAddr: EthereumAddress, chainlinkCollAddress: EthereumAddress, chainId?: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress): (boolean | string[] | Strategies.MainnetIds)[];
|
|
7
7
|
trailingStop(vaultId: number, triggerPercentage: number, closeToAssetAddr: EthereumAddress, chainlinkCollAddress: EthereumAddress, roundId: number, chainId?: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress): (boolean | string[] | Strategies.MainnetIds)[];
|
|
8
|
-
|
|
8
|
+
leverageManagement(vaultId: number, triggerRatio: number, targetRatio: number, ratioState: RatioState, isBoost: boolean, daiAddr?: EthereumAddress): (boolean | string[] | Bundles.MainnetIds)[];
|
|
9
|
+
liquidationProtection(vaultId: number, triggerRatio: number, targetRatio: number, ratioState: RatioState, daiAddr?: EthereumAddress): (boolean | string[] | Bundles.MainnetIds)[];
|
|
9
10
|
};
|
|
10
11
|
export declare const liquityEncode: {
|
|
11
12
|
closeOnPrice(priceOverOrUnder: RatioState, price: string, closeToAssetAddr: EthereumAddress, chainlinkCollAddress: EthereumAddress, chainId?: ChainId, collAddr?: EthereumAddress, debtAddr?: EthereumAddress): (boolean | string[] | Strategies.MainnetIds)[];
|
|
12
13
|
trailingStop(triggerPercentage: number, closeToAssetAddr: EthereumAddress, chainlinkCollAddress: EthereumAddress, roundId: number, chainId?: ChainId, collAddr?: EthereumAddress, debtAddr?: EthereumAddress): (boolean | string[] | Strategies.MainnetIds)[];
|
|
13
14
|
paybackFromChickenBondStrategySub(proxyAddress: EthereumAddress, ratio: number, sourceId: string, sourceType: number, ratioState?: RatioState): (boolean | string[] | Bundles.MainnetIds)[];
|
|
14
|
-
|
|
15
|
+
leverageManagement(strategyOrBundleId: number, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
15
16
|
dsrPayback(proxyAddress: EthereumAddress, triggerRatio: number, targetRatio: number): (boolean | string[] | Strategies.MainnetIds)[];
|
|
16
17
|
dsrSupply(proxyAddress: EthereumAddress, triggerRatio: number, targetRatio: number): (boolean | string[] | Strategies.MainnetIds)[];
|
|
17
18
|
debtInFrontRepay(proxyAddress: EthereumAddress, debtInFrontMin: string, targetRatioIncrease: number): (boolean | string[] | Strategies.MainnetIds)[];
|
|
18
19
|
};
|
|
19
|
-
export declare const chickenBondsEncode: {
|
|
20
|
-
rebond(bondId: number): string[];
|
|
21
|
-
};
|
|
22
20
|
export declare const aaveV2Encode: {
|
|
23
|
-
|
|
21
|
+
leverageManagement(strategyOrBundleId: number, market: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
24
22
|
};
|
|
25
23
|
export declare const aaveV3Encode: {
|
|
26
24
|
closeToAsset(strategyOrBundleId: number, isBundle: boolean | undefined, triggerData: {
|
|
@@ -59,25 +57,24 @@ export declare const aaveV3Encode: {
|
|
|
59
57
|
marketAddr: EthereumAddress;
|
|
60
58
|
targetRatio: number;
|
|
61
59
|
}): (number | boolean | string[])[];
|
|
62
|
-
|
|
60
|
+
leverageManagement(strategyOrBundleId: number, market: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, isGeneric?: boolean): (number | boolean | string[])[];
|
|
61
|
+
liquidationProtection(strategyOrBundleId: number, market: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
63
62
|
leverageManagementOnPriceGeneric(strategyOrBundleId: number, price: number, ratioState: RatioState, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number, user: EthereumAddress): (number | boolean | string[])[];
|
|
64
63
|
closeOnPriceGeneric(strategyOrBundleId: number, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, user: EthereumAddress, stopLossPrice?: number, stopLossType?: CloseToAssetType, takeProfitPrice?: number, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
|
|
65
64
|
collateralSwitch(strategyOrBundleId: number, fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, state: RatioState): (number | boolean | string[])[];
|
|
66
65
|
};
|
|
67
66
|
export declare const compoundV2Encode: {
|
|
68
|
-
|
|
67
|
+
leverageManagement(strategyOrBundleId: number, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
69
68
|
};
|
|
70
69
|
export declare const compoundV3Encode: {
|
|
71
|
-
|
|
70
|
+
leverageManagement(strategyOrBundleId: number, market: EthereumAddress, baseToken: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
71
|
+
liquidationProtection(strategyOrBundleId: number, market: EthereumAddress, baseToken: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
72
72
|
leverageManagementOnPrice(strategyOrBundleId: number, market: EthereumAddress, collToken: EthereumAddress, baseToken: EthereumAddress, targetRatio: number, price: number, priceState: RatioState, ratioState: RatioState, user: EthereumAddress): (number | boolean | string[])[];
|
|
73
73
|
closeOnPrice(strategyOrBundleId: number, market: EthereumAddress, collToken: EthereumAddress, baseToken: EthereumAddress, stopLossPrice: number | undefined, stopLossType: CloseToAssetType | undefined, takeProfitPrice: number | undefined, takeProfitType: CloseToAssetType | undefined, user: EthereumAddress): (number | boolean | string[])[];
|
|
74
74
|
};
|
|
75
|
-
export declare const morphoAaveV2Encode: {
|
|
76
|
-
leverageManagement(triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean): string[];
|
|
77
|
-
};
|
|
78
75
|
export declare const exchangeEncode: {
|
|
79
76
|
dca(fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, timestamp: number, interval: number, network: ChainId): (boolean | string[] | Strategies.MainnetIds | Strategies.OptimismIds | Strategies.ArbitrumIds | Strategies.BaseIds)[];
|
|
80
|
-
|
|
77
|
+
limitOrder(fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, targetPrice: string, goodUntil: string | number, orderType: OrderType, fromTokenDecimals: number, toTokenDecimals: number, network: ChainId): (boolean | string[] | Strategies.MainnetIds | Strategies.OptimismIds | Strategies.ArbitrumIds | Strategies.BaseIds)[];
|
|
81
78
|
};
|
|
82
79
|
export declare const sparkEncode: {
|
|
83
80
|
leverageManagementOnPrice(strategyOrBundleId: number, isBundle: boolean | undefined, triggerData: {
|
|
@@ -94,7 +91,8 @@ export declare const sparkEncode: {
|
|
|
94
91
|
targetRatio: number;
|
|
95
92
|
}): (number | boolean | string[])[];
|
|
96
93
|
closeOnPriceGeneric(strategyOrBundleId: number, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, user: EthereumAddress, stopLossPrice?: number, stopLossType?: CloseToAssetType, takeProfitPrice?: number, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
|
|
97
|
-
|
|
94
|
+
leverageManagement(strategyOrBundleId: number, market: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
95
|
+
liquidationProtection(strategyOrBundleId: number, market: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
98
96
|
collateralSwitch(strategyOrBundleId: number, fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, state: RatioState): (number | boolean | string[])[];
|
|
99
97
|
};
|
|
100
98
|
export declare const crvUSDEncode: {
|
|
@@ -103,6 +101,7 @@ export declare const crvUSDEncode: {
|
|
|
103
101
|
};
|
|
104
102
|
export declare const morphoBlueEncode: {
|
|
105
103
|
leverageManagement(marketId: string, loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, ratioState: RatioState, targetRatio: number, triggerRatio: number, user: EthereumAddress, isEOA: boolean, network: ChainId): (boolean | string[] | Bundles.BaseIds)[] | (boolean | string[] | Bundles.MainnetIds | Bundles.ArbitrumIds)[];
|
|
104
|
+
liquidationProtection(marketId: string, loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, ratioState: RatioState, targetRatio: number, triggerRatio: number, user: EthereumAddress, isEOA: boolean, network: ChainId): (boolean | string[] | Bundles.MainnetIds)[];
|
|
106
105
|
leverageManagementOnPrice(strategyOrBundleId: number, isBundle: boolean | undefined, loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, user: EthereumAddress, targetRatio: number, price: number, priceState: RatioState): (number | boolean | string[])[];
|
|
107
106
|
closeOnPrice(strategyOrBundleId: number, loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, user: EthereumAddress, stopLossPrice?: number, stopLossType?: CloseToAssetType, takeProfitPrice?: number, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
|
|
108
107
|
};
|
|
@@ -114,9 +113,11 @@ export declare const liquityV2Encode: {
|
|
|
114
113
|
};
|
|
115
114
|
export declare const fluidEncode: {
|
|
116
115
|
leverageManagement(nftId: string, vault: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, strategyOrBundleId: number): (number | boolean | string[])[];
|
|
116
|
+
liquidationProtection(nftId: string, vault: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, strategyOrBundleId: number): (number | boolean | string[])[];
|
|
117
117
|
};
|
|
118
118
|
export declare const aaveV4Encode: {
|
|
119
119
|
leverageManagement(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
120
|
+
liquidationProtection(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
120
121
|
leverageManagementOnPrice(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, targetRatio: number, price: string, priceState: RatioState, ratioState: RatioState): (number | boolean | string[])[];
|
|
121
122
|
closeOnPrice(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, stopLossPrice?: string, stopLossType?: CloseToAssetType, takeProfitPrice?: string, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
|
|
122
123
|
collateralSwitch(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, amountToSwitch: string, price: string, ratioState: RatioState): (number | boolean | string[])[];
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { getAssetInfo } from '@defisaver/tokens';
|
|
2
|
-
import { CloseToAssetType, Bundles, ChainId, RatioState, Strategies, } from '../types/enums';
|
|
3
2
|
import { STRATEGY_IDS } from '../constants';
|
|
3
|
+
import { Bundles, ChainId, CloseToAssetType, RatioState, Strategies, } from '../types/enums';
|
|
4
4
|
import * as subDataService from './subDataService';
|
|
5
5
|
import * as triggerService from './triggerService';
|
|
6
|
-
import { compareAddresses, getCloseStrategyType, requireAddress, requireAddresses, } from './utils';
|
|
6
|
+
import { compareAddresses, getBundleIdsByNetwork, getCloseStrategyType, requireAddress, requireAddresses, } from './utils';
|
|
7
7
|
export const makerEncode = {
|
|
8
8
|
repayFromSavings(bundleId, vaultId, triggerRepayRatio, targetRepayRatio, isBundle = true, chainId = ChainId.Ethereum, daiAddr, mcdCdpManagerAddr) {
|
|
9
9
|
const subData = subDataService.makerRepayFromSavingsSubData.encode(vaultId, targetRepayRatio, chainId, daiAddr, mcdCdpManagerAddr);
|
|
@@ -30,10 +30,21 @@ export const makerEncode = {
|
|
|
30
30
|
const isBundle = false;
|
|
31
31
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
32
32
|
},
|
|
33
|
-
|
|
33
|
+
leverageManagement(vaultId, triggerRatio, targetRatio, ratioState, isBoost, daiAddr) {
|
|
34
34
|
const bundleId = isBoost ? Bundles.MainnetIds.MAKER_BOOST : Bundles.MainnetIds.MAKER_REPAY;
|
|
35
35
|
const triggerData = triggerService.makerRatioTrigger.encode(vaultId, triggerRatio, ratioState);
|
|
36
|
-
const subData = subDataService.
|
|
36
|
+
const subData = subDataService.makerLeverageManagementSubData.encode(vaultId, targetRatio, daiAddr);
|
|
37
|
+
return [
|
|
38
|
+
bundleId,
|
|
39
|
+
true,
|
|
40
|
+
triggerData,
|
|
41
|
+
subData,
|
|
42
|
+
];
|
|
43
|
+
},
|
|
44
|
+
liquidationProtection(vaultId, triggerRatio, targetRatio, ratioState, daiAddr) {
|
|
45
|
+
const bundleId = Bundles.MainnetIds.MAKER_SW_LIQUIDATION_PROTECTION;
|
|
46
|
+
const triggerData = triggerService.makerRatioTrigger.encode(vaultId, triggerRatio, ratioState);
|
|
47
|
+
const subData = subDataService.makerLiquidationProtectionSubData.encode(vaultId, targetRatio, daiAddr);
|
|
37
48
|
return [
|
|
38
49
|
bundleId,
|
|
39
50
|
true,
|
|
@@ -67,9 +78,9 @@ export const liquityEncode = {
|
|
|
67
78
|
const isBundle = true;
|
|
68
79
|
return [strategyId, isBundle, triggerData, subData];
|
|
69
80
|
},
|
|
70
|
-
|
|
81
|
+
leverageManagement(strategyOrBundleId, user, ratioState, targetRatio, triggerRatio) {
|
|
71
82
|
const isBundle = true;
|
|
72
|
-
const subData = subDataService.
|
|
83
|
+
const subData = subDataService.liquityLeverageManagementSubData.encode(targetRatio, ratioState);
|
|
73
84
|
const triggerData = triggerService.liquityRatioTrigger.encode(user, triggerRatio, ratioState);
|
|
74
85
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
75
86
|
},
|
|
@@ -98,15 +109,10 @@ export const liquityEncode = {
|
|
|
98
109
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
99
110
|
},
|
|
100
111
|
};
|
|
101
|
-
export const chickenBondsEncode = {
|
|
102
|
-
rebond(bondId) {
|
|
103
|
-
return subDataService.cBondsRebondSubData.encode(bondId);
|
|
104
|
-
},
|
|
105
|
-
};
|
|
106
112
|
export const aaveV2Encode = {
|
|
107
|
-
|
|
113
|
+
leverageManagement(strategyOrBundleId, market, user, ratioState, targetRatio, triggerRatio) {
|
|
108
114
|
const isBundle = true;
|
|
109
|
-
const subData = subDataService.
|
|
115
|
+
const subData = subDataService.aaveV2LeverageManagementSubData.encode(market, targetRatio, ratioState);
|
|
110
116
|
const triggerData = triggerService.aaveV2RatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
111
117
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
112
118
|
},
|
|
@@ -133,9 +139,15 @@ export const aaveV3Encode = {
|
|
|
133
139
|
const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
|
|
134
140
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
135
141
|
},
|
|
136
|
-
|
|
142
|
+
leverageManagement(strategyOrBundleId, market, user, ratioState, targetRatio, triggerRatio, isGeneric = false) {
|
|
143
|
+
const isBundle = true;
|
|
144
|
+
const subData = subDataService.aaveV3LeverageManagementSubData.encode(targetRatio, ratioState, market, user, isGeneric);
|
|
145
|
+
const triggerData = triggerService.aaveV3RatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
146
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
147
|
+
},
|
|
148
|
+
liquidationProtection(strategyOrBundleId, market, user, ratioState, targetRatio, triggerRatio) {
|
|
137
149
|
const isBundle = true;
|
|
138
|
-
const subData = subDataService.
|
|
150
|
+
const subData = subDataService.aaveV3LiquidationProtectionSubData.encode(targetRatio, ratioState, market, user, true);
|
|
139
151
|
const triggerData = triggerService.aaveV3RatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
140
152
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
141
153
|
},
|
|
@@ -160,17 +172,23 @@ export const aaveV3Encode = {
|
|
|
160
172
|
},
|
|
161
173
|
};
|
|
162
174
|
export const compoundV2Encode = {
|
|
163
|
-
|
|
175
|
+
leverageManagement(strategyOrBundleId, user, ratioState, targetRatio, triggerRatio) {
|
|
164
176
|
const isBundle = true;
|
|
165
|
-
const subData = subDataService.
|
|
177
|
+
const subData = subDataService.compoundV2LeverageManagementSubData.encode(targetRatio, ratioState);
|
|
166
178
|
const triggerData = triggerService.compoundV2RatioTrigger.encode(user, triggerRatio, ratioState);
|
|
167
179
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
168
180
|
},
|
|
169
181
|
};
|
|
170
182
|
export const compoundV3Encode = {
|
|
171
|
-
|
|
183
|
+
leverageManagement(strategyOrBundleId, market, baseToken, user, ratioState, targetRatio, triggerRatio) {
|
|
184
|
+
const isBundle = true;
|
|
185
|
+
const subData = subDataService.compoundV3LeverageManagementSubData.encode(market, baseToken, targetRatio, ratioState);
|
|
186
|
+
const triggerData = triggerService.compoundV3RatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
187
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
188
|
+
},
|
|
189
|
+
liquidationProtection(strategyOrBundleId, market, baseToken, user, ratioState, targetRatio, triggerRatio) {
|
|
172
190
|
const isBundle = true;
|
|
173
|
-
const subData = subDataService.
|
|
191
|
+
const subData = subDataService.compoundV3LiquidationProtectionSubData.encode(market, baseToken, targetRatio, ratioState);
|
|
174
192
|
const triggerData = triggerService.compoundV3RatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
175
193
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
176
194
|
},
|
|
@@ -189,11 +207,6 @@ export const compoundV3Encode = {
|
|
|
189
207
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
190
208
|
},
|
|
191
209
|
};
|
|
192
|
-
export const morphoAaveV2Encode = {
|
|
193
|
-
leverageManagement(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
194
|
-
return subDataService.morphoAaveV2LeverageManagementSubData.encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled);
|
|
195
|
-
},
|
|
196
|
-
};
|
|
197
210
|
export const exchangeEncode = {
|
|
198
211
|
dca(fromToken, toToken, amount, timestamp, interval, network) {
|
|
199
212
|
requireAddresses([fromToken, toToken]);
|
|
@@ -202,9 +215,9 @@ export const exchangeEncode = {
|
|
|
202
215
|
const strategyId = STRATEGY_IDS[network].EXCHANGE_DCA;
|
|
203
216
|
return [strategyId, false, triggerData, subData];
|
|
204
217
|
},
|
|
205
|
-
|
|
218
|
+
limitOrder(fromToken, toToken, amount, targetPrice, goodUntil, orderType, fromTokenDecimals, toTokenDecimals, network) {
|
|
206
219
|
requireAddresses([fromToken, toToken]);
|
|
207
|
-
const subData = subDataService.
|
|
220
|
+
const subData = subDataService.exchangeLimitOrderSubData.encode(fromToken, toToken, amount);
|
|
208
221
|
const triggerData = triggerService.exchangeOffchainPriceTrigger.encode(targetPrice, Number(goodUntil), orderType, fromTokenDecimals, toTokenDecimals);
|
|
209
222
|
const strategyId = STRATEGY_IDS[network].EXCHANGE_LIMIT_ORDER;
|
|
210
223
|
return [strategyId, false, triggerData, subData];
|
|
@@ -225,9 +238,15 @@ export const sparkEncode = {
|
|
|
225
238
|
const triggerDataEncoded = triggerService.sparkQuotePriceRangeTrigger.encode(collAsset, debtAsset, stopLossPrice, takeProfitPrice);
|
|
226
239
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
227
240
|
},
|
|
228
|
-
|
|
241
|
+
leverageManagement(strategyOrBundleId, market, user, ratioState, targetRatio, triggerRatio) {
|
|
229
242
|
const isBundle = true;
|
|
230
|
-
const subData = subDataService.
|
|
243
|
+
const subData = subDataService.sparkLeverageManagementSubData.encode(targetRatio, ratioState);
|
|
244
|
+
const triggerData = triggerService.sparkRatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
245
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
246
|
+
},
|
|
247
|
+
liquidationProtection(strategyOrBundleId, market, user, ratioState, targetRatio, triggerRatio) {
|
|
248
|
+
const isBundle = true;
|
|
249
|
+
const subData = subDataService.sparkLiquidationProtectionSubData.encode(targetRatio, ratioState);
|
|
231
250
|
const triggerData = triggerService.sparkRatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
232
251
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
233
252
|
},
|
|
@@ -273,6 +292,16 @@ export const morphoBlueEncode = {
|
|
|
273
292
|
const isBundle = true;
|
|
274
293
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
275
294
|
},
|
|
295
|
+
liquidationProtection(marketId, loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, triggerRatio, user, isEOA, network) {
|
|
296
|
+
const subData = subDataService.morphoBlueLiquidationProtectionSubData.encode(loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, user, isEOA);
|
|
297
|
+
const triggerData = triggerService.morphoBlueRatioTrigger.encode(marketId, user, triggerRatio, ratioState);
|
|
298
|
+
// Type casting because there is no MORPHO_BLUE_EOA_LIQUIDATION_PROTECTION for Base chain.
|
|
299
|
+
// That is fine because we will just always send isEOA == false for Base chain.
|
|
300
|
+
const bundleNetwork = getBundleIdsByNetwork(network);
|
|
301
|
+
const bundleId = isEOA ? bundleNetwork.MORPHO_BLUE_EOA_LIQUIDATION_PROTECTION : bundleNetwork.MORPHO_BLUE_SW_LIQUIDATION_PROTECTION;
|
|
302
|
+
const isBundle = true;
|
|
303
|
+
return [bundleId, isBundle, triggerData, subData];
|
|
304
|
+
},
|
|
276
305
|
leverageManagementOnPrice(strategyOrBundleId, isBundle = true, loanToken, collToken, oracle, irm, lltv, user, targetRatio, price, priceState) {
|
|
277
306
|
const subData = subDataService.morphoBlueLeverageManagementOnPriceSubData.encode(loanToken, collToken, oracle, irm, lltv, targetRatio, user);
|
|
278
307
|
const triggerData = triggerService.morphoBluePriceTrigger.encode(oracle, collToken, loanToken, price, priceState);
|
|
@@ -321,6 +350,12 @@ export const fluidEncode = {
|
|
|
321
350
|
const triggerData = triggerService.fluidRatioTrigger.encode(nftId, triggerRatio, ratioState);
|
|
322
351
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
323
352
|
},
|
|
353
|
+
liquidationProtection(nftId, vault, ratioState, targetRatio, triggerRatio, strategyOrBundleId) {
|
|
354
|
+
const isBundle = true;
|
|
355
|
+
const subData = subDataService.fluidLiquidationProtectionSubData.encode(nftId, vault, ratioState, targetRatio);
|
|
356
|
+
const triggerData = triggerService.fluidRatioTrigger.encode(nftId, triggerRatio, ratioState);
|
|
357
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
358
|
+
},
|
|
324
359
|
};
|
|
325
360
|
export const aaveV4Encode = {
|
|
326
361
|
leverageManagement(strategyOrBundleId, owner, spoke, ratioState, targetRatio, triggerRatio) {
|
|
@@ -329,6 +364,12 @@ export const aaveV4Encode = {
|
|
|
329
364
|
const triggerData = triggerService.aaveV4RatioTrigger.encode(owner, spoke, triggerRatio, ratioState);
|
|
330
365
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
331
366
|
},
|
|
367
|
+
liquidationProtection(strategyOrBundleId, owner, spoke, ratioState, targetRatio, triggerRatio) {
|
|
368
|
+
const isBundle = true;
|
|
369
|
+
const subData = subDataService.aaveV4LiquidationProtectionSubData.encode(spoke, owner, ratioState, targetRatio);
|
|
370
|
+
const triggerData = triggerService.aaveV4RatioTrigger.encode(owner, spoke, triggerRatio, ratioState);
|
|
371
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
372
|
+
},
|
|
332
373
|
leverageManagementOnPrice(strategyOrBundleId, owner, spoke, collAsset, collAssetId, debtAsset, debtAssetId, targetRatio, price, priceState, ratioState) {
|
|
333
374
|
const isBundle = true;
|
|
334
375
|
const subData = subDataService.aaveV4LeverageManagementOnPriceSubData.encode(spoke, owner, collAsset, collAssetId, debtAsset, debtAssetId, ratioState, targetRatio);
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { expect } from 'chai';
|
|
2
|
-
import Dec from 'decimal.js';
|
|
3
2
|
import { otherAddresses } from '@defisaver/sdk';
|
|
4
3
|
import { getAssetInfo, MAXUINT } from '@defisaver/tokens';
|
|
5
4
|
import * as web3Utils from 'web3-utils';
|
|
6
5
|
import { Bundles, ChainId, CloseToAssetType, RatioState, Strategies } from '../types/enums';
|
|
7
6
|
import '../configuration';
|
|
8
|
-
import {
|
|
7
|
+
import { liquityEncode, makerEncode, aaveV3Encode, compoundV3Encode, exchangeEncode, crvUSDEncode, morphoBlueEncode, sparkEncode, aaveV4Encode, } from './strategySubService';
|
|
9
8
|
describe('Feature: strategySubService.ts', () => {
|
|
10
9
|
describe('When testing strategySubService.makerEncode', () => {
|
|
11
10
|
// @ts-ignore // TODO - this requires change in @defisaver/tokens
|
|
@@ -96,7 +95,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
96
95
|
});
|
|
97
96
|
});
|
|
98
97
|
});
|
|
99
|
-
describe('
|
|
98
|
+
describe('leverageManagement()', () => {
|
|
100
99
|
const examples = [
|
|
101
100
|
// Repay scenario (isBoost=false, RatioState.UNDER)
|
|
102
101
|
[
|
|
@@ -139,7 +138,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
139
138
|
];
|
|
140
139
|
examples.forEach(([expected, actual]) => {
|
|
141
140
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
142
|
-
expect(makerEncode.
|
|
141
|
+
expect(makerEncode.leverageManagement(...actual)).to.eql(expected);
|
|
143
142
|
});
|
|
144
143
|
});
|
|
145
144
|
});
|
|
@@ -266,21 +265,6 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
266
265
|
});
|
|
267
266
|
});
|
|
268
267
|
});
|
|
269
|
-
describe('When testing strategySubService.chickenBondsEncode', () => {
|
|
270
|
-
describe('rebond()', () => {
|
|
271
|
-
const examples = [
|
|
272
|
-
[
|
|
273
|
-
['0x00000000000000000000000000000000000000000000000000000000000005e3'],
|
|
274
|
-
[1507]
|
|
275
|
-
]
|
|
276
|
-
];
|
|
277
|
-
examples.forEach(([expected, actual]) => {
|
|
278
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
279
|
-
expect(chickenBondsEncode.rebond(...actual)).to.eql(expected);
|
|
280
|
-
});
|
|
281
|
-
});
|
|
282
|
-
});
|
|
283
|
-
});
|
|
284
268
|
describe('When testing strategySubService.aaveV3Encode', () => {
|
|
285
269
|
describe('closeToAsset()', () => {
|
|
286
270
|
const examples = [
|
|
@@ -970,25 +954,6 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
970
954
|
});
|
|
971
955
|
});
|
|
972
956
|
});
|
|
973
|
-
describe('When testing strategySubService.morphoAaveV2Encode', () => {
|
|
974
|
-
describe('leverageManagement()', () => {
|
|
975
|
-
const examples = [
|
|
976
|
-
[
|
|
977
|
-
[new Dec(160).mul(1e16).toString(), new Dec(220).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), true],
|
|
978
|
-
[160, 220, 180, 190, true]
|
|
979
|
-
],
|
|
980
|
-
[
|
|
981
|
-
[new Dec(160).mul(1e16).toString(), new Dec(200).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), false],
|
|
982
|
-
[160, 200, 180, 190, false]
|
|
983
|
-
],
|
|
984
|
-
];
|
|
985
|
-
examples.forEach(([expected, actual]) => {
|
|
986
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
987
|
-
expect(morphoAaveV2Encode.leverageManagement(...actual)).to.eql(expected);
|
|
988
|
-
});
|
|
989
|
-
});
|
|
990
|
-
});
|
|
991
|
-
});
|
|
992
957
|
describe('When testing strategySubService.exchangeEncode', () => {
|
|
993
958
|
describe('dca()', () => {
|
|
994
959
|
const examples = [
|
|
@@ -1197,6 +1162,73 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1197
1162
|
});
|
|
1198
1163
|
});
|
|
1199
1164
|
});
|
|
1165
|
+
describe('leverageManagementOnPrice()', () => {
|
|
1166
|
+
const examples = [
|
|
1167
|
+
[
|
|
1168
|
+
[
|
|
1169
|
+
Bundles.MainnetIds.MORPHO_BLUE_REPAY_ON_PRICE,
|
|
1170
|
+
true,
|
|
1171
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1172
|
+
[
|
|
1173
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1174
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1175
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1176
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1177
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1178
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
1179
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1180
|
+
],
|
|
1181
|
+
],
|
|
1182
|
+
[
|
|
1183
|
+
Bundles.MainnetIds.MORPHO_BLUE_REPAY_ON_PRICE,
|
|
1184
|
+
true,
|
|
1185
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1186
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1187
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1188
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1189
|
+
'945000000000000000',
|
|
1190
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1191
|
+
200,
|
|
1192
|
+
2500,
|
|
1193
|
+
RatioState.UNDER,
|
|
1194
|
+
],
|
|
1195
|
+
],
|
|
1196
|
+
[
|
|
1197
|
+
[
|
|
1198
|
+
Bundles.MainnetIds.MORPHO_BLUE_BOOST_ON_PRICE,
|
|
1199
|
+
true,
|
|
1200
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000005d21dba0000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1201
|
+
[
|
|
1202
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1203
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1204
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1205
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1206
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1207
|
+
'0x00000000000000000000000000000000000000000000000016345785d8a00000',
|
|
1208
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1209
|
+
],
|
|
1210
|
+
],
|
|
1211
|
+
[
|
|
1212
|
+
Bundles.MainnetIds.MORPHO_BLUE_BOOST_ON_PRICE,
|
|
1213
|
+
true,
|
|
1214
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1215
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1216
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1217
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1218
|
+
'945000000000000000',
|
|
1219
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1220
|
+
160,
|
|
1221
|
+
4000,
|
|
1222
|
+
RatioState.OVER,
|
|
1223
|
+
],
|
|
1224
|
+
],
|
|
1225
|
+
];
|
|
1226
|
+
examples.forEach(([expected, actual]) => {
|
|
1227
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1228
|
+
expect(morphoBlueEncode.leverageManagementOnPrice(...actual)).to.eql(expected);
|
|
1229
|
+
});
|
|
1230
|
+
});
|
|
1231
|
+
});
|
|
1200
1232
|
describe('closeOnPrice()', () => {
|
|
1201
1233
|
const examples = [
|
|
1202
1234
|
[
|