@defisaver/automation-sdk 3.3.16 → 3.3.17-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 +190 -0
- package/cjs/index.d.ts +2 -2
- package/cjs/index.js +5 -2
- package/cjs/services/strategiesService.js +169 -12
- package/cjs/services/strategySubService.d.ts +22 -17
- package/cjs/services/strategySubService.js +115 -38
- package/cjs/services/strategySubService.test.js +111 -41
- package/cjs/services/subDataService.d.ts +70 -20
- package/cjs/services/subDataService.js +23 -79
- package/cjs/services/subDataService.test.js +17 -202
- package/cjs/types/enums.d.ts +48 -6
- package/cjs/types/enums.js +42 -0
- package/esm/constants/index.js +190 -0
- package/esm/index.d.ts +2 -2
- package/esm/index.js +5 -2
- package/esm/services/strategiesService.js +169 -12
- package/esm/services/strategySubService.d.ts +22 -17
- package/esm/services/strategySubService.js +113 -37
- package/esm/services/strategySubService.test.js +112 -39
- package/esm/services/subDataService.d.ts +70 -20
- package/esm/services/subDataService.js +21 -77
- package/esm/services/subDataService.test.js +18 -200
- package/esm/types/enums.d.ts +48 -6
- package/esm/types/enums.js +42 -0
- package/package.json +1 -1
- package/src/constants/index.ts +192 -1
- package/src/index.ts +22 -6
- package/src/services/strategiesService.ts +234 -12
- package/src/services/strategySubService.test.ts +147 -47
- package/src/services/strategySubService.ts +246 -47
- package/src/services/subDataService.test.ts +18 -214
- package/src/services/subDataService.ts +42 -106
- package/src/services/utils.test.ts +1 -1
- package/src/services/utils.ts +3 -1
- package/src/types/enums.ts +42 -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,17 +91,23 @@ 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: {
|
|
101
99
|
leverageManagement(owner: EthereumAddress, controllerAddr: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, collTokenAddr: EthereumAddress, crvUSDAddr: EthereumAddress): (boolean | string[] | Bundles.MainnetIds)[];
|
|
102
100
|
payback(proxyAddress: EthereumAddress, addressToPullTokensFrom: EthereumAddress, positionOwner: EthereumAddress, paybackAmount: string, crvUSDAddr: EthereumAddress, controllerAddr: EthereumAddress, minHealthRatio: number): (boolean | string[] | Strategies.MainnetIds)[];
|
|
103
101
|
};
|
|
102
|
+
export type MorphoBlueBundleStrategy = 'repay' | 'boost' | 'repayOnPrice' | 'boostOnPrice' | 'close' | 'liquidationProtection';
|
|
103
|
+
export declare function getMorphoBlueBundleId(network: ChainId, strategy: MorphoBlueBundleStrategy, isEOA: boolean): number;
|
|
104
104
|
export declare const morphoBlueEncode: {
|
|
105
|
-
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): (
|
|
105
|
+
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): (number | boolean | string[])[];
|
|
106
|
+
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): (number | boolean | string[])[];
|
|
106
107
|
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[])[];
|
|
108
|
+
leverageManagementOnPriceGeneric(loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, user: EthereumAddress, targetRatio: number, price: number, priceState: RatioState, isBoost: boolean, isEOA: boolean, network: ChainId): (number | boolean | string[])[];
|
|
107
109
|
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[])[];
|
|
110
|
+
closeOnPriceGeneric(loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, user: EthereumAddress, stopLossPrice: number | undefined, stopLossType: CloseToAssetType | undefined, takeProfitPrice: number | undefined, takeProfitType: CloseToAssetType | undefined, isEOA: boolean, network: ChainId): (number | boolean | string[])[];
|
|
108
111
|
};
|
|
109
112
|
export declare const liquityV2Encode: {
|
|
110
113
|
leverageManagement(market: EthereumAddress, troveId: string, collToken: EthereumAddress, boldToken: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, strategyOrBundleId: number): (number | boolean | string[])[];
|
|
@@ -114,9 +117,11 @@ export declare const liquityV2Encode: {
|
|
|
114
117
|
};
|
|
115
118
|
export declare const fluidEncode: {
|
|
116
119
|
leverageManagement(nftId: string, vault: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, strategyOrBundleId: number): (number | boolean | string[])[];
|
|
120
|
+
liquidationProtection(nftId: string, vault: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, strategyOrBundleId: number): (number | boolean | string[])[];
|
|
117
121
|
};
|
|
118
122
|
export declare const aaveV4Encode: {
|
|
119
123
|
leverageManagement(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
124
|
+
liquidationProtection(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
120
125
|
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
126
|
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
127
|
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,6 +1,6 @@
|
|
|
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
6
|
import { compareAddresses, getCloseStrategyType, requireAddress, requireAddresses, } from './utils';
|
|
@@ -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) {
|
|
242
|
+
const isBundle = true;
|
|
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) {
|
|
229
248
|
const isBundle = true;
|
|
230
|
-
const subData = subDataService.
|
|
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
|
},
|
|
@@ -255,29 +274,66 @@ export const crvUSDEncode = {
|
|
|
255
274
|
return [strategyId, isBundle, triggerData, subData];
|
|
256
275
|
},
|
|
257
276
|
};
|
|
277
|
+
function getMorphoBlueBundlesIds(network) {
|
|
278
|
+
switch (network) {
|
|
279
|
+
case ChainId.Ethereum:
|
|
280
|
+
return Bundles.MainnetIds;
|
|
281
|
+
case ChainId.Base:
|
|
282
|
+
return Bundles.BaseIds;
|
|
283
|
+
case ChainId.Arbitrum:
|
|
284
|
+
return Bundles.ArbitrumIds;
|
|
285
|
+
default:
|
|
286
|
+
throw new Error(`Morpho Blue strategies are not supported on chain ${network}`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
export function getMorphoBlueBundleId(network, strategy, isEOA) {
|
|
290
|
+
const bundlesIds = getMorphoBlueBundlesIds(network);
|
|
291
|
+
switch (strategy) {
|
|
292
|
+
case 'repay':
|
|
293
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_REPAY : bundlesIds.MORPHO_BLUE_REPAY;
|
|
294
|
+
case 'boost':
|
|
295
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_BOOST : bundlesIds.MORPHO_BLUE_BOOST;
|
|
296
|
+
case 'repayOnPrice':
|
|
297
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_REPAY_ON_PRICE : bundlesIds.MORPHO_BLUE_REPAY_ON_PRICE;
|
|
298
|
+
case 'boostOnPrice':
|
|
299
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_BOOST_ON_PRICE : bundlesIds.MORPHO_BLUE_BOOST_ON_PRICE;
|
|
300
|
+
case 'close':
|
|
301
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_CLOSE : bundlesIds.MORPHO_BLUE_CLOSE;
|
|
302
|
+
case 'liquidationProtection':
|
|
303
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_LIQUIDATION_PROTECTION : bundlesIds.MORPHO_BLUE_SW_LIQUIDATION_PROTECTION;
|
|
304
|
+
default:
|
|
305
|
+
throw new Error(`Unknown Morpho Blue strategy: ${strategy}`);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
258
308
|
export const morphoBlueEncode = {
|
|
259
309
|
leverageManagement(marketId, loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, triggerRatio, user, isEOA, network) {
|
|
260
310
|
const subData = subDataService.morphoBlueLeverageManagementSubData.encode(loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, user, isEOA);
|
|
261
311
|
const triggerData = triggerService.morphoBlueRatioTrigger.encode(marketId, user, triggerRatio, ratioState);
|
|
262
312
|
// over is boost, under is repay
|
|
263
313
|
const isBoost = ratioState === RatioState.OVER;
|
|
264
|
-
|
|
265
|
-
if (network === ChainId.Base) {
|
|
266
|
-
return [isBoost ? Bundles.BaseIds.MORPHO_BLUE_BOOST : Bundles.BaseIds.MORPHO_BLUE_REPAY, true, triggerData, subData];
|
|
267
|
-
}
|
|
268
|
-
const bundlesIds = network === ChainId.Arbitrum ? Bundles.ArbitrumIds : Bundles.MainnetIds;
|
|
269
|
-
if (isBoost)
|
|
270
|
-
strategyOrBundleId = isEOA ? bundlesIds.MORPHO_BLUE_EOA_BOOST : bundlesIds.MORPHO_BLUE_BOOST;
|
|
271
|
-
else
|
|
272
|
-
strategyOrBundleId = isEOA ? bundlesIds.MORPHO_BLUE_EOA_REPAY : bundlesIds.MORPHO_BLUE_REPAY;
|
|
314
|
+
const bundleId = getMorphoBlueBundleId(network, isBoost ? 'boost' : 'repay', isEOA);
|
|
273
315
|
const isBundle = true;
|
|
274
|
-
return [
|
|
316
|
+
return [bundleId, isBundle, triggerData, subData];
|
|
317
|
+
},
|
|
318
|
+
liquidationProtection(marketId, loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, triggerRatio, user, isEOA, network) {
|
|
319
|
+
const subData = subDataService.morphoBlueLiquidationProtectionSubData.encode(loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, user, isEOA);
|
|
320
|
+
const triggerData = triggerService.morphoBlueRatioTrigger.encode(marketId, user, triggerRatio, ratioState);
|
|
321
|
+
const bundleId = getMorphoBlueBundleId(network, 'liquidationProtection', isEOA);
|
|
322
|
+
const isBundle = true;
|
|
323
|
+
return [bundleId, isBundle, triggerData, subData];
|
|
275
324
|
},
|
|
276
325
|
leverageManagementOnPrice(strategyOrBundleId, isBundle = true, loanToken, collToken, oracle, irm, lltv, user, targetRatio, price, priceState) {
|
|
277
326
|
const subData = subDataService.morphoBlueLeverageManagementOnPriceSubData.encode(loanToken, collToken, oracle, irm, lltv, targetRatio, user);
|
|
278
327
|
const triggerData = triggerService.morphoBluePriceTrigger.encode(oracle, collToken, loanToken, price, priceState);
|
|
279
328
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
280
329
|
},
|
|
330
|
+
leverageManagementOnPriceGeneric(loanToken, collToken, oracle, irm, lltv, user, targetRatio, price, priceState, isBoost, isEOA, network) {
|
|
331
|
+
const subData = subDataService.morphoBlueLeverageManagementOnPriceSubData.encode(loanToken, collToken, oracle, irm, lltv, targetRatio, user);
|
|
332
|
+
const triggerData = triggerService.morphoBluePriceTrigger.encode(oracle, collToken, loanToken, price, priceState);
|
|
333
|
+
const bundleId = getMorphoBlueBundleId(network, isBoost ? 'boostOnPrice' : 'repayOnPrice', isEOA);
|
|
334
|
+
const isBundle = true;
|
|
335
|
+
return [bundleId, isBundle, triggerData, subData];
|
|
336
|
+
},
|
|
281
337
|
closeOnPrice(strategyOrBundleId, loanToken, collToken, oracle, irm, lltv, user, stopLossPrice = 0, stopLossType = CloseToAssetType.DEBT, takeProfitPrice = 0, takeProfitType = CloseToAssetType.COLLATERAL) {
|
|
282
338
|
const isBundle = true;
|
|
283
339
|
const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
@@ -285,6 +341,14 @@ export const morphoBlueEncode = {
|
|
|
285
341
|
const triggerDataEncoded = triggerService.morphoBluePriceRangeTrigger.encode(oracle, collToken, loanToken, stopLossPrice, takeProfitPrice);
|
|
286
342
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
287
343
|
},
|
|
344
|
+
closeOnPriceGeneric(loanToken, collToken, oracle, irm, lltv, user, stopLossPrice = 0, stopLossType = CloseToAssetType.DEBT, takeProfitPrice = 0, takeProfitType = CloseToAssetType.COLLATERAL, isEOA, network) {
|
|
345
|
+
const isBundle = true;
|
|
346
|
+
const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
347
|
+
const subDataEncoded = subDataService.morphoBlueCloseOnPriceSubData.encode(loanToken, collToken, oracle, irm, lltv, user, closeType);
|
|
348
|
+
const triggerDataEncoded = triggerService.morphoBluePriceRangeTrigger.encode(oracle, collToken, loanToken, stopLossPrice, takeProfitPrice);
|
|
349
|
+
const bundleId = getMorphoBlueBundleId(network, 'close', isEOA);
|
|
350
|
+
return [bundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
351
|
+
},
|
|
288
352
|
};
|
|
289
353
|
export const liquityV2Encode = {
|
|
290
354
|
leverageManagement(market, troveId, collToken, boldToken, ratioState, targetRatio, triggerRatio, strategyOrBundleId) {
|
|
@@ -321,6 +385,12 @@ export const fluidEncode = {
|
|
|
321
385
|
const triggerData = triggerService.fluidRatioTrigger.encode(nftId, triggerRatio, ratioState);
|
|
322
386
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
323
387
|
},
|
|
388
|
+
liquidationProtection(nftId, vault, ratioState, targetRatio, triggerRatio, strategyOrBundleId) {
|
|
389
|
+
const isBundle = true;
|
|
390
|
+
const subData = subDataService.fluidLiquidationProtectionSubData.encode(nftId, vault, ratioState, targetRatio);
|
|
391
|
+
const triggerData = triggerService.fluidRatioTrigger.encode(nftId, triggerRatio, ratioState);
|
|
392
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
393
|
+
},
|
|
324
394
|
};
|
|
325
395
|
export const aaveV4Encode = {
|
|
326
396
|
leverageManagement(strategyOrBundleId, owner, spoke, ratioState, targetRatio, triggerRatio) {
|
|
@@ -329,6 +399,12 @@ export const aaveV4Encode = {
|
|
|
329
399
|
const triggerData = triggerService.aaveV4RatioTrigger.encode(owner, spoke, triggerRatio, ratioState);
|
|
330
400
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
331
401
|
},
|
|
402
|
+
liquidationProtection(strategyOrBundleId, owner, spoke, ratioState, targetRatio, triggerRatio) {
|
|
403
|
+
const isBundle = true;
|
|
404
|
+
const subData = subDataService.aaveV4LiquidationProtectionSubData.encode(spoke, owner, ratioState, targetRatio);
|
|
405
|
+
const triggerData = triggerService.aaveV4RatioTrigger.encode(owner, spoke, triggerRatio, ratioState);
|
|
406
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
407
|
+
},
|
|
332
408
|
leverageManagementOnPrice(strategyOrBundleId, owner, spoke, collAsset, collAssetId, debtAsset, debtAssetId, targetRatio, price, priceState, ratioState) {
|
|
333
409
|
const isBundle = true;
|
|
334
410
|
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 = [
|
|
@@ -1264,6 +1229,75 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1264
1229
|
});
|
|
1265
1230
|
});
|
|
1266
1231
|
});
|
|
1232
|
+
describe('leverageManagementOnPriceGeneric()', () => {
|
|
1233
|
+
const examples = [
|
|
1234
|
+
[
|
|
1235
|
+
[
|
|
1236
|
+
Bundles.MainnetIds.MORPHO_BLUE_REPAY_ON_PRICE,
|
|
1237
|
+
true,
|
|
1238
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1239
|
+
[
|
|
1240
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1241
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1242
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1243
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1244
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1245
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
1246
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1247
|
+
],
|
|
1248
|
+
],
|
|
1249
|
+
[
|
|
1250
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1251
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1252
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1253
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1254
|
+
'945000000000000000',
|
|
1255
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1256
|
+
200,
|
|
1257
|
+
2500,
|
|
1258
|
+
RatioState.UNDER,
|
|
1259
|
+
false,
|
|
1260
|
+
false,
|
|
1261
|
+
ChainId.Ethereum,
|
|
1262
|
+
],
|
|
1263
|
+
],
|
|
1264
|
+
[
|
|
1265
|
+
[
|
|
1266
|
+
Bundles.MainnetIds.MORPHO_BLUE_BOOST_ON_PRICE,
|
|
1267
|
+
true,
|
|
1268
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000005d21dba0000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1269
|
+
[
|
|
1270
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1271
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1272
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1273
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1274
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1275
|
+
'0x00000000000000000000000000000000000000000000000016345785d8a00000',
|
|
1276
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1277
|
+
],
|
|
1278
|
+
],
|
|
1279
|
+
[
|
|
1280
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1281
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1282
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1283
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1284
|
+
'945000000000000000',
|
|
1285
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1286
|
+
160,
|
|
1287
|
+
4000,
|
|
1288
|
+
RatioState.OVER,
|
|
1289
|
+
true,
|
|
1290
|
+
false,
|
|
1291
|
+
ChainId.Ethereum,
|
|
1292
|
+
],
|
|
1293
|
+
],
|
|
1294
|
+
];
|
|
1295
|
+
examples.forEach(([expected, actual]) => {
|
|
1296
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1297
|
+
expect(morphoBlueEncode.leverageManagementOnPriceGeneric(...actual)).to.eql(expected);
|
|
1298
|
+
});
|
|
1299
|
+
});
|
|
1300
|
+
});
|
|
1267
1301
|
describe('closeOnPrice()', () => {
|
|
1268
1302
|
const examples = [
|
|
1269
1303
|
[
|
|
@@ -1292,7 +1326,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1292
1326
|
1500,
|
|
1293
1327
|
CloseToAssetType.DEBT,
|
|
1294
1328
|
4000,
|
|
1295
|
-
CloseToAssetType.COLLATERAL
|
|
1329
|
+
CloseToAssetType.COLLATERAL,
|
|
1296
1330
|
]
|
|
1297
1331
|
],
|
|
1298
1332
|
];
|
|
@@ -1302,6 +1336,45 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1302
1336
|
});
|
|
1303
1337
|
});
|
|
1304
1338
|
});
|
|
1339
|
+
describe('closeOnPriceGeneric()', () => {
|
|
1340
|
+
const examples = [
|
|
1341
|
+
[
|
|
1342
|
+
[
|
|
1343
|
+
Bundles.MainnetIds.MORPHO_BLUE_CLOSE,
|
|
1344
|
+
true,
|
|
1345
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
1346
|
+
[
|
|
1347
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1348
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1349
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1350
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1351
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1352
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1353
|
+
'0x0000000000000000000000000000000000000000000000000000000000000005',
|
|
1354
|
+
],
|
|
1355
|
+
],
|
|
1356
|
+
[
|
|
1357
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1358
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1359
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1360
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1361
|
+
'945000000000000000',
|
|
1362
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1363
|
+
1500,
|
|
1364
|
+
CloseToAssetType.DEBT,
|
|
1365
|
+
4000,
|
|
1366
|
+
CloseToAssetType.COLLATERAL,
|
|
1367
|
+
false,
|
|
1368
|
+
ChainId.Ethereum,
|
|
1369
|
+
]
|
|
1370
|
+
],
|
|
1371
|
+
];
|
|
1372
|
+
examples.forEach(([expected, actual]) => {
|
|
1373
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1374
|
+
expect(morphoBlueEncode.closeOnPriceGeneric(...actual)).to.eql(expected);
|
|
1375
|
+
});
|
|
1376
|
+
});
|
|
1377
|
+
});
|
|
1305
1378
|
});
|
|
1306
1379
|
describe('When testing strategySubService.sparkEncode', () => {
|
|
1307
1380
|
describe('leverageManagementOnPrice()', () => {
|