@defisaver/automation-sdk 3.3.16-liq-prot-dev → 3.3.17
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 +42 -117
- package/cjs/index.d.ts +2 -2
- package/cjs/index.js +2 -5
- package/cjs/services/strategiesService.js +21 -160
- package/cjs/services/strategySubService.d.ts +21 -18
- package/cjs/services/strategySubService.js +74 -78
- package/cjs/services/strategySubService.test.js +149 -3
- package/cjs/services/subDataService.d.ts +20 -70
- package/cjs/services/subDataService.js +79 -23
- package/cjs/services/subDataService.test.js +202 -17
- package/cjs/services/utils.d.ts +1 -2
- package/cjs/services/utils.js +1 -14
- package/cjs/types/enums.d.ts +17 -36
- package/cjs/types/enums.js +11 -30
- package/esm/constants/index.js +42 -117
- package/esm/index.d.ts +2 -2
- package/esm/index.js +2 -5
- package/esm/services/strategiesService.js +21 -160
- package/esm/services/strategySubService.d.ts +21 -18
- package/esm/services/strategySubService.js +73 -78
- package/esm/services/strategySubService.test.js +147 -4
- package/esm/services/subDataService.d.ts +20 -70
- package/esm/services/subDataService.js +77 -21
- package/esm/services/subDataService.test.js +200 -18
- package/esm/services/utils.d.ts +1 -2
- package/esm/services/utils.js +1 -13
- package/esm/types/enums.d.ts +17 -36
- package/esm/types/enums.js +11 -30
- package/package.json +1 -1
- package/src/constants/index.ts +43 -119
- package/src/index.ts +6 -22
- package/src/services/strategiesService.ts +23 -225
- package/src/services/strategySubService.test.ts +191 -3
- package/src/services/strategySubService.ts +121 -173
- package/src/services/subDataService.test.ts +214 -18
- package/src/services/subDataService.ts +106 -42
- package/src/services/utils.test.ts +1 -1
- package/src/services/utils.ts +1 -15
- package/src/types/enums.ts +13 -30
|
@@ -1,24 +1,26 @@
|
|
|
1
|
-
import { Bundles, ChainId, CloseToAssetType, RatioState, Strategies } from '../types/enums';
|
|
2
|
-
import type { EthereumAddress, StrategyOrBundleIds } from '../types';
|
|
3
1
|
import type { OrderType } from '../types/enums';
|
|
2
|
+
import { CloseToAssetType, Bundles, ChainId, RatioState, Strategies } from '../types/enums';
|
|
3
|
+
import type { EthereumAddress, StrategyOrBundleIds } from '../types';
|
|
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
|
-
|
|
9
|
-
liquidationProtection(vaultId: number, triggerRatio: number, targetRatio: number, ratioState: RatioState, daiAddr?: EthereumAddress): (boolean | string[] | Bundles.MainnetIds)[];
|
|
8
|
+
leverageManagementWithoutSubProxy(vaultId: number, triggerRatio: number, targetRatio: number, ratioState: RatioState, isBoost: boolean, daiAddr?: EthereumAddress): (boolean | string[] | Bundles.MainnetIds)[];
|
|
10
9
|
};
|
|
11
10
|
export declare const liquityEncode: {
|
|
12
11
|
closeOnPrice(priceOverOrUnder: RatioState, price: string, closeToAssetAddr: EthereumAddress, chainlinkCollAddress: EthereumAddress, chainId?: ChainId, collAddr?: EthereumAddress, debtAddr?: EthereumAddress): (boolean | string[] | Strategies.MainnetIds)[];
|
|
13
12
|
trailingStop(triggerPercentage: number, closeToAssetAddr: EthereumAddress, chainlinkCollAddress: EthereumAddress, roundId: number, chainId?: ChainId, collAddr?: EthereumAddress, debtAddr?: EthereumAddress): (boolean | string[] | Strategies.MainnetIds)[];
|
|
14
13
|
paybackFromChickenBondStrategySub(proxyAddress: EthereumAddress, ratio: number, sourceId: string, sourceType: number, ratioState?: RatioState): (boolean | string[] | Bundles.MainnetIds)[];
|
|
15
|
-
|
|
14
|
+
leverageManagementWithoutSubProxy(strategyOrBundleId: number, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
16
15
|
dsrPayback(proxyAddress: EthereumAddress, triggerRatio: number, targetRatio: number): (boolean | string[] | Strategies.MainnetIds)[];
|
|
17
16
|
dsrSupply(proxyAddress: EthereumAddress, triggerRatio: number, targetRatio: number): (boolean | string[] | Strategies.MainnetIds)[];
|
|
18
17
|
debtInFrontRepay(proxyAddress: EthereumAddress, debtInFrontMin: string, targetRatioIncrease: number): (boolean | string[] | Strategies.MainnetIds)[];
|
|
19
18
|
};
|
|
19
|
+
export declare const chickenBondsEncode: {
|
|
20
|
+
rebond(bondId: number): string[];
|
|
21
|
+
};
|
|
20
22
|
export declare const aaveV2Encode: {
|
|
21
|
-
|
|
23
|
+
leverageManagementWithoutSubProxy(strategyOrBundleId: number, market: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
22
24
|
};
|
|
23
25
|
export declare const aaveV3Encode: {
|
|
24
26
|
closeToAsset(strategyOrBundleId: number, isBundle: boolean | undefined, triggerData: {
|
|
@@ -57,24 +59,25 @@ export declare const aaveV3Encode: {
|
|
|
57
59
|
marketAddr: EthereumAddress;
|
|
58
60
|
targetRatio: number;
|
|
59
61
|
}): (number | boolean | string[])[];
|
|
60
|
-
|
|
61
|
-
liquidationProtection(strategyOrBundleId: number, market: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
62
|
+
leverageManagementWithoutSubProxy(strategyOrBundleId: number, market: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, isGeneric?: boolean): (number | boolean | string[])[];
|
|
62
63
|
leverageManagementOnPriceGeneric(strategyOrBundleId: number, price: number, ratioState: RatioState, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number, user: EthereumAddress): (number | boolean | string[])[];
|
|
63
64
|
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[])[];
|
|
64
65
|
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[])[];
|
|
65
66
|
};
|
|
66
67
|
export declare const compoundV2Encode: {
|
|
67
|
-
|
|
68
|
+
leverageManagementWithoutSubProxy(strategyOrBundleId: number, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
68
69
|
};
|
|
69
70
|
export declare const compoundV3Encode: {
|
|
70
|
-
|
|
71
|
-
liquidationProtection(strategyOrBundleId: number, market: EthereumAddress, baseToken: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
71
|
+
leverageManagementWithoutSubProxy(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
|
+
};
|
|
75
78
|
export declare const exchangeEncode: {
|
|
76
79
|
dca(fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, timestamp: number, interval: number, network: ChainId): (boolean | string[] | Strategies.MainnetIds | Strategies.OptimismIds | Strategies.ArbitrumIds | Strategies.BaseIds)[];
|
|
77
|
-
|
|
80
|
+
limitOrderWithoutSubProxy(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)[];
|
|
78
81
|
};
|
|
79
82
|
export declare const sparkEncode: {
|
|
80
83
|
leverageManagementOnPrice(strategyOrBundleId: number, isBundle: boolean | undefined, triggerData: {
|
|
@@ -91,19 +94,21 @@ export declare const sparkEncode: {
|
|
|
91
94
|
targetRatio: number;
|
|
92
95
|
}): (number | boolean | string[])[];
|
|
93
96
|
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[])[];
|
|
94
|
-
|
|
95
|
-
liquidationProtection(strategyOrBundleId: number, market: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
97
|
+
leverageManagementWithoutSubProxy(strategyOrBundleId: number, market: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
96
98
|
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[])[];
|
|
97
99
|
};
|
|
98
100
|
export declare const crvUSDEncode: {
|
|
99
101
|
leverageManagement(owner: EthereumAddress, controllerAddr: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, collTokenAddr: EthereumAddress, crvUSDAddr: EthereumAddress): (boolean | string[] | Bundles.MainnetIds)[];
|
|
100
102
|
payback(proxyAddress: EthereumAddress, addressToPullTokensFrom: EthereumAddress, positionOwner: EthereumAddress, paybackAmount: string, crvUSDAddr: EthereumAddress, controllerAddr: EthereumAddress, minHealthRatio: number): (boolean | string[] | Strategies.MainnetIds)[];
|
|
101
103
|
};
|
|
104
|
+
export type MorphoBlueBundleStrategy = 'repay' | 'boost' | 'repayOnPrice' | 'boostOnPrice' | 'close';
|
|
105
|
+
export declare function getMorphoBlueBundleId(network: ChainId, strategy: MorphoBlueBundleStrategy, isEOA: boolean): number;
|
|
102
106
|
export declare const morphoBlueEncode: {
|
|
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): (
|
|
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)[];
|
|
107
|
+
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[])[];
|
|
105
108
|
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[])[];
|
|
109
|
+
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[])[];
|
|
106
110
|
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[])[];
|
|
111
|
+
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[])[];
|
|
107
112
|
};
|
|
108
113
|
export declare const liquityV2Encode: {
|
|
109
114
|
leverageManagement(market: EthereumAddress, troveId: string, collToken: EthereumAddress, boldToken: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, strategyOrBundleId: number): (number | boolean | string[])[];
|
|
@@ -113,11 +118,9 @@ export declare const liquityV2Encode: {
|
|
|
113
118
|
};
|
|
114
119
|
export declare const fluidEncode: {
|
|
115
120
|
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
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[])[];
|
|
120
|
-
liquidationProtection(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
121
124
|
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[])[];
|
|
122
125
|
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[])[];
|
|
123
126
|
collateralSwitch(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, amountToSwitch: string, price: string, ratioState: RatioState): (number | boolean | string[])[];
|
|
@@ -23,10 +23,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.aaveV4Encode = exports.fluidEncode = exports.liquityV2Encode = exports.morphoBlueEncode = exports.crvUSDEncode = exports.sparkEncode = exports.exchangeEncode = exports.compoundV3Encode = exports.compoundV2Encode = exports.aaveV3Encode = exports.aaveV2Encode = exports.liquityEncode = exports.makerEncode = void 0;
|
|
26
|
+
exports.aaveV4Encode = exports.fluidEncode = exports.liquityV2Encode = exports.morphoBlueEncode = exports.getMorphoBlueBundleId = exports.crvUSDEncode = exports.sparkEncode = exports.exchangeEncode = exports.morphoAaveV2Encode = exports.compoundV3Encode = exports.compoundV2Encode = exports.aaveV3Encode = exports.aaveV2Encode = exports.chickenBondsEncode = exports.liquityEncode = exports.makerEncode = void 0;
|
|
27
27
|
const tokens_1 = require("@defisaver/tokens");
|
|
28
|
-
const constants_1 = require("../constants");
|
|
29
28
|
const enums_1 = require("../types/enums");
|
|
29
|
+
const constants_1 = require("../constants");
|
|
30
30
|
const subDataService = __importStar(require("./subDataService"));
|
|
31
31
|
const triggerService = __importStar(require("./triggerService"));
|
|
32
32
|
const utils_1 = require("./utils");
|
|
@@ -56,21 +56,10 @@ exports.makerEncode = {
|
|
|
56
56
|
const isBundle = false;
|
|
57
57
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
58
58
|
},
|
|
59
|
-
|
|
59
|
+
leverageManagementWithoutSubProxy(vaultId, triggerRatio, targetRatio, ratioState, isBoost, daiAddr) {
|
|
60
60
|
const bundleId = isBoost ? enums_1.Bundles.MainnetIds.MAKER_BOOST : enums_1.Bundles.MainnetIds.MAKER_REPAY;
|
|
61
61
|
const triggerData = triggerService.makerRatioTrigger.encode(vaultId, triggerRatio, ratioState);
|
|
62
|
-
const subData = subDataService.
|
|
63
|
-
return [
|
|
64
|
-
bundleId,
|
|
65
|
-
true,
|
|
66
|
-
triggerData,
|
|
67
|
-
subData,
|
|
68
|
-
];
|
|
69
|
-
},
|
|
70
|
-
liquidationProtection(vaultId, triggerRatio, targetRatio, ratioState, daiAddr) {
|
|
71
|
-
const bundleId = enums_1.Bundles.MainnetIds.MAKER_SW_LIQUIDATION_PROTECTION;
|
|
72
|
-
const triggerData = triggerService.makerRatioTrigger.encode(vaultId, triggerRatio, ratioState);
|
|
73
|
-
const subData = subDataService.makerLiquidationProtectionSubData.encode(vaultId, targetRatio, daiAddr);
|
|
62
|
+
const subData = subDataService.makerLeverageManagementWithoutSubProxy.encode(vaultId, targetRatio, daiAddr);
|
|
74
63
|
return [
|
|
75
64
|
bundleId,
|
|
76
65
|
true,
|
|
@@ -104,9 +93,9 @@ exports.liquityEncode = {
|
|
|
104
93
|
const isBundle = true;
|
|
105
94
|
return [strategyId, isBundle, triggerData, subData];
|
|
106
95
|
},
|
|
107
|
-
|
|
96
|
+
leverageManagementWithoutSubProxy(strategyOrBundleId, user, ratioState, targetRatio, triggerRatio) {
|
|
108
97
|
const isBundle = true;
|
|
109
|
-
const subData = subDataService.
|
|
98
|
+
const subData = subDataService.liquityLeverageManagementSubDataWithoutSubProxy.encode(targetRatio, ratioState);
|
|
110
99
|
const triggerData = triggerService.liquityRatioTrigger.encode(user, triggerRatio, ratioState);
|
|
111
100
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
112
101
|
},
|
|
@@ -135,10 +124,15 @@ exports.liquityEncode = {
|
|
|
135
124
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
136
125
|
},
|
|
137
126
|
};
|
|
127
|
+
exports.chickenBondsEncode = {
|
|
128
|
+
rebond(bondId) {
|
|
129
|
+
return subDataService.cBondsRebondSubData.encode(bondId);
|
|
130
|
+
},
|
|
131
|
+
};
|
|
138
132
|
exports.aaveV2Encode = {
|
|
139
|
-
|
|
133
|
+
leverageManagementWithoutSubProxy(strategyOrBundleId, market, user, ratioState, targetRatio, triggerRatio) {
|
|
140
134
|
const isBundle = true;
|
|
141
|
-
const subData = subDataService.
|
|
135
|
+
const subData = subDataService.aaveV2LeverageManagementSubDataWithoutSubProxy.encode(market, targetRatio, ratioState);
|
|
142
136
|
const triggerData = triggerService.aaveV2RatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
143
137
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
144
138
|
},
|
|
@@ -165,15 +159,9 @@ exports.aaveV3Encode = {
|
|
|
165
159
|
const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
|
|
166
160
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
167
161
|
},
|
|
168
|
-
|
|
162
|
+
leverageManagementWithoutSubProxy(strategyOrBundleId, market, user, ratioState, targetRatio, triggerRatio, isGeneric = false) {
|
|
169
163
|
const isBundle = true;
|
|
170
|
-
const subData = subDataService.
|
|
171
|
-
const triggerData = triggerService.aaveV3RatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
172
|
-
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
173
|
-
},
|
|
174
|
-
liquidationProtection(strategyOrBundleId, market, user, ratioState, targetRatio, triggerRatio) {
|
|
175
|
-
const isBundle = true;
|
|
176
|
-
const subData = subDataService.aaveV3LiquidationProtectionSubData.encode(targetRatio, ratioState, market, user, true);
|
|
164
|
+
const subData = subDataService.aaveV3LeverageManagementSubDataWithoutSubProxy.encode(targetRatio, ratioState, market, user, isGeneric);
|
|
177
165
|
const triggerData = triggerService.aaveV3RatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
178
166
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
179
167
|
},
|
|
@@ -198,23 +186,17 @@ exports.aaveV3Encode = {
|
|
|
198
186
|
},
|
|
199
187
|
};
|
|
200
188
|
exports.compoundV2Encode = {
|
|
201
|
-
|
|
189
|
+
leverageManagementWithoutSubProxy(strategyOrBundleId, user, ratioState, targetRatio, triggerRatio) {
|
|
202
190
|
const isBundle = true;
|
|
203
|
-
const subData = subDataService.
|
|
191
|
+
const subData = subDataService.compoundV2LeverageManagementSubDataWithoutSubProxy.encode(targetRatio, ratioState);
|
|
204
192
|
const triggerData = triggerService.compoundV2RatioTrigger.encode(user, triggerRatio, ratioState);
|
|
205
193
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
206
194
|
},
|
|
207
195
|
};
|
|
208
196
|
exports.compoundV3Encode = {
|
|
209
|
-
|
|
210
|
-
const isBundle = true;
|
|
211
|
-
const subData = subDataService.compoundV3LeverageManagementSubData.encode(market, baseToken, targetRatio, ratioState);
|
|
212
|
-
const triggerData = triggerService.compoundV3RatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
213
|
-
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
214
|
-
},
|
|
215
|
-
liquidationProtection(strategyOrBundleId, market, baseToken, user, ratioState, targetRatio, triggerRatio) {
|
|
197
|
+
leverageManagementWithoutSubProxy(strategyOrBundleId, market, baseToken, user, ratioState, targetRatio, triggerRatio) {
|
|
216
198
|
const isBundle = true;
|
|
217
|
-
const subData = subDataService.
|
|
199
|
+
const subData = subDataService.compoundV3LeverageManagementSubDataWithoutSubProxy.encode(market, baseToken, targetRatio, ratioState);
|
|
218
200
|
const triggerData = triggerService.compoundV3RatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
219
201
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
220
202
|
},
|
|
@@ -233,6 +215,11 @@ exports.compoundV3Encode = {
|
|
|
233
215
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
234
216
|
},
|
|
235
217
|
};
|
|
218
|
+
exports.morphoAaveV2Encode = {
|
|
219
|
+
leverageManagement(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
220
|
+
return subDataService.morphoAaveV2LeverageManagementSubData.encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled);
|
|
221
|
+
},
|
|
222
|
+
};
|
|
236
223
|
exports.exchangeEncode = {
|
|
237
224
|
dca(fromToken, toToken, amount, timestamp, interval, network) {
|
|
238
225
|
(0, utils_1.requireAddresses)([fromToken, toToken]);
|
|
@@ -241,9 +228,9 @@ exports.exchangeEncode = {
|
|
|
241
228
|
const strategyId = constants_1.STRATEGY_IDS[network].EXCHANGE_DCA;
|
|
242
229
|
return [strategyId, false, triggerData, subData];
|
|
243
230
|
},
|
|
244
|
-
|
|
231
|
+
limitOrderWithoutSubProxy(fromToken, toToken, amount, targetPrice, goodUntil, orderType, fromTokenDecimals, toTokenDecimals, network) {
|
|
245
232
|
(0, utils_1.requireAddresses)([fromToken, toToken]);
|
|
246
|
-
const subData = subDataService.
|
|
233
|
+
const subData = subDataService.exchangeLimitOrderSubDataWithoutSubProxy.encode(fromToken, toToken, amount);
|
|
247
234
|
const triggerData = triggerService.exchangeOffchainPriceTrigger.encode(targetPrice, Number(goodUntil), orderType, fromTokenDecimals, toTokenDecimals);
|
|
248
235
|
const strategyId = constants_1.STRATEGY_IDS[network].EXCHANGE_LIMIT_ORDER;
|
|
249
236
|
return [strategyId, false, triggerData, subData];
|
|
@@ -264,15 +251,9 @@ exports.sparkEncode = {
|
|
|
264
251
|
const triggerDataEncoded = triggerService.sparkQuotePriceRangeTrigger.encode(collAsset, debtAsset, stopLossPrice, takeProfitPrice);
|
|
265
252
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
266
253
|
},
|
|
267
|
-
|
|
268
|
-
const isBundle = true;
|
|
269
|
-
const subData = subDataService.sparkLeverageManagementSubData.encode(targetRatio, ratioState);
|
|
270
|
-
const triggerData = triggerService.sparkRatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
271
|
-
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
272
|
-
},
|
|
273
|
-
liquidationProtection(strategyOrBundleId, market, user, ratioState, targetRatio, triggerRatio) {
|
|
254
|
+
leverageManagementWithoutSubProxy(strategyOrBundleId, market, user, ratioState, targetRatio, triggerRatio) {
|
|
274
255
|
const isBundle = true;
|
|
275
|
-
const subData = subDataService.
|
|
256
|
+
const subData = subDataService.sparkLeverageManagementSubDataWithoutSubProxy.encode(targetRatio, ratioState);
|
|
276
257
|
const triggerData = triggerService.sparkRatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
277
258
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
278
259
|
},
|
|
@@ -300,31 +281,43 @@ exports.crvUSDEncode = {
|
|
|
300
281
|
return [strategyId, isBundle, triggerData, subData];
|
|
301
282
|
},
|
|
302
283
|
};
|
|
284
|
+
function getMorphoBlueBundlesIds(network) {
|
|
285
|
+
switch (network) {
|
|
286
|
+
case enums_1.ChainId.Ethereum:
|
|
287
|
+
return enums_1.Bundles.MainnetIds;
|
|
288
|
+
case enums_1.ChainId.Base:
|
|
289
|
+
return enums_1.Bundles.BaseIds;
|
|
290
|
+
case enums_1.ChainId.Arbitrum:
|
|
291
|
+
return enums_1.Bundles.ArbitrumIds;
|
|
292
|
+
default:
|
|
293
|
+
throw new Error(`Morpho Blue strategies are not supported on chain ${network}`);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
function getMorphoBlueBundleId(network, strategy, isEOA) {
|
|
297
|
+
const bundlesIds = getMorphoBlueBundlesIds(network);
|
|
298
|
+
switch (strategy) {
|
|
299
|
+
case 'repay':
|
|
300
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_REPAY : bundlesIds.MORPHO_BLUE_REPAY;
|
|
301
|
+
case 'boost':
|
|
302
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_BOOST : bundlesIds.MORPHO_BLUE_BOOST;
|
|
303
|
+
case 'repayOnPrice':
|
|
304
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_REPAY_ON_PRICE : bundlesIds.MORPHO_BLUE_REPAY_ON_PRICE;
|
|
305
|
+
case 'boostOnPrice':
|
|
306
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_BOOST_ON_PRICE : bundlesIds.MORPHO_BLUE_BOOST_ON_PRICE;
|
|
307
|
+
case 'close':
|
|
308
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_CLOSE : bundlesIds.MORPHO_BLUE_CLOSE;
|
|
309
|
+
default:
|
|
310
|
+
throw new Error(`Unknown Morpho Blue strategy: ${strategy}`);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
exports.getMorphoBlueBundleId = getMorphoBlueBundleId;
|
|
303
314
|
exports.morphoBlueEncode = {
|
|
304
315
|
leverageManagement(marketId, loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, triggerRatio, user, isEOA, network) {
|
|
305
316
|
const subData = subDataService.morphoBlueLeverageManagementSubData.encode(loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, user, isEOA);
|
|
306
317
|
const triggerData = triggerService.morphoBlueRatioTrigger.encode(marketId, user, triggerRatio, ratioState);
|
|
307
318
|
// over is boost, under is repay
|
|
308
319
|
const isBoost = ratioState === enums_1.RatioState.OVER;
|
|
309
|
-
|
|
310
|
-
if (network === enums_1.ChainId.Base) {
|
|
311
|
-
return [isBoost ? enums_1.Bundles.BaseIds.MORPHO_BLUE_BOOST : enums_1.Bundles.BaseIds.MORPHO_BLUE_REPAY, true, triggerData, subData];
|
|
312
|
-
}
|
|
313
|
-
const bundlesIds = network === enums_1.ChainId.Arbitrum ? enums_1.Bundles.ArbitrumIds : enums_1.Bundles.MainnetIds;
|
|
314
|
-
if (isBoost)
|
|
315
|
-
strategyOrBundleId = isEOA ? bundlesIds.MORPHO_BLUE_EOA_BOOST : bundlesIds.MORPHO_BLUE_BOOST;
|
|
316
|
-
else
|
|
317
|
-
strategyOrBundleId = isEOA ? bundlesIds.MORPHO_BLUE_EOA_REPAY : bundlesIds.MORPHO_BLUE_REPAY;
|
|
318
|
-
const isBundle = true;
|
|
319
|
-
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
320
|
-
},
|
|
321
|
-
liquidationProtection(marketId, loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, triggerRatio, user, isEOA, network) {
|
|
322
|
-
const subData = subDataService.morphoBlueLiquidationProtectionSubData.encode(loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, user, isEOA);
|
|
323
|
-
const triggerData = triggerService.morphoBlueRatioTrigger.encode(marketId, user, triggerRatio, ratioState);
|
|
324
|
-
// Type casting because there is no MORPHO_BLUE_EOA_LIQUIDATION_PROTECTION for Base chain.
|
|
325
|
-
// That is fine because we will just always send isEOA == false for Base chain.
|
|
326
|
-
const bundleNetwork = (0, utils_1.getBundleIdsByNetwork)(network);
|
|
327
|
-
const bundleId = isEOA ? bundleNetwork.MORPHO_BLUE_EOA_LIQUIDATION_PROTECTION : bundleNetwork.MORPHO_BLUE_SW_LIQUIDATION_PROTECTION;
|
|
320
|
+
const bundleId = getMorphoBlueBundleId(network, isBoost ? 'boost' : 'repay', isEOA);
|
|
328
321
|
const isBundle = true;
|
|
329
322
|
return [bundleId, isBundle, triggerData, subData];
|
|
330
323
|
},
|
|
@@ -333,6 +326,13 @@ exports.morphoBlueEncode = {
|
|
|
333
326
|
const triggerData = triggerService.morphoBluePriceTrigger.encode(oracle, collToken, loanToken, price, priceState);
|
|
334
327
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
335
328
|
},
|
|
329
|
+
leverageManagementOnPriceGeneric(loanToken, collToken, oracle, irm, lltv, user, targetRatio, price, priceState, isBoost, isEOA, network) {
|
|
330
|
+
const subData = subDataService.morphoBlueLeverageManagementOnPriceSubData.encode(loanToken, collToken, oracle, irm, lltv, targetRatio, user);
|
|
331
|
+
const triggerData = triggerService.morphoBluePriceTrigger.encode(oracle, collToken, loanToken, price, priceState);
|
|
332
|
+
const bundleId = getMorphoBlueBundleId(network, isBoost ? 'boostOnPrice' : 'repayOnPrice', isEOA);
|
|
333
|
+
const isBundle = true;
|
|
334
|
+
return [bundleId, isBundle, triggerData, subData];
|
|
335
|
+
},
|
|
336
336
|
closeOnPrice(strategyOrBundleId, loanToken, collToken, oracle, irm, lltv, user, stopLossPrice = 0, stopLossType = enums_1.CloseToAssetType.DEBT, takeProfitPrice = 0, takeProfitType = enums_1.CloseToAssetType.COLLATERAL) {
|
|
337
337
|
const isBundle = true;
|
|
338
338
|
const closeType = (0, utils_1.getCloseStrategyType)(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
@@ -340,6 +340,14 @@ exports.morphoBlueEncode = {
|
|
|
340
340
|
const triggerDataEncoded = triggerService.morphoBluePriceRangeTrigger.encode(oracle, collToken, loanToken, stopLossPrice, takeProfitPrice);
|
|
341
341
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
342
342
|
},
|
|
343
|
+
closeOnPriceGeneric(loanToken, collToken, oracle, irm, lltv, user, stopLossPrice = 0, stopLossType = enums_1.CloseToAssetType.DEBT, takeProfitPrice = 0, takeProfitType = enums_1.CloseToAssetType.COLLATERAL, isEOA, network) {
|
|
344
|
+
const isBundle = true;
|
|
345
|
+
const closeType = (0, utils_1.getCloseStrategyType)(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
346
|
+
const subDataEncoded = subDataService.morphoBlueCloseOnPriceSubData.encode(loanToken, collToken, oracle, irm, lltv, user, closeType);
|
|
347
|
+
const triggerDataEncoded = triggerService.morphoBluePriceRangeTrigger.encode(oracle, collToken, loanToken, stopLossPrice, takeProfitPrice);
|
|
348
|
+
const bundleId = getMorphoBlueBundleId(network, 'close', isEOA);
|
|
349
|
+
return [bundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
350
|
+
},
|
|
343
351
|
};
|
|
344
352
|
exports.liquityV2Encode = {
|
|
345
353
|
leverageManagement(market, troveId, collToken, boldToken, ratioState, targetRatio, triggerRatio, strategyOrBundleId) {
|
|
@@ -376,12 +384,6 @@ exports.fluidEncode = {
|
|
|
376
384
|
const triggerData = triggerService.fluidRatioTrigger.encode(nftId, triggerRatio, ratioState);
|
|
377
385
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
378
386
|
},
|
|
379
|
-
liquidationProtection(nftId, vault, ratioState, targetRatio, triggerRatio, strategyOrBundleId) {
|
|
380
|
-
const isBundle = true;
|
|
381
|
-
const subData = subDataService.fluidLiquidationProtectionSubData.encode(nftId, vault, ratioState, targetRatio);
|
|
382
|
-
const triggerData = triggerService.fluidRatioTrigger.encode(nftId, triggerRatio, ratioState);
|
|
383
|
-
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
384
|
-
},
|
|
385
387
|
};
|
|
386
388
|
exports.aaveV4Encode = {
|
|
387
389
|
leverageManagement(strategyOrBundleId, owner, spoke, ratioState, targetRatio, triggerRatio) {
|
|
@@ -390,12 +392,6 @@ exports.aaveV4Encode = {
|
|
|
390
392
|
const triggerData = triggerService.aaveV4RatioTrigger.encode(owner, spoke, triggerRatio, ratioState);
|
|
391
393
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
392
394
|
},
|
|
393
|
-
liquidationProtection(strategyOrBundleId, owner, spoke, ratioState, targetRatio, triggerRatio) {
|
|
394
|
-
const isBundle = true;
|
|
395
|
-
const subData = subDataService.aaveV4LiquidationProtectionSubData.encode(spoke, owner, ratioState, targetRatio);
|
|
396
|
-
const triggerData = triggerService.aaveV4RatioTrigger.encode(owner, spoke, triggerRatio, ratioState);
|
|
397
|
-
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
398
|
-
},
|
|
399
395
|
leverageManagementOnPrice(strategyOrBundleId, owner, spoke, collAsset, collAssetId, debtAsset, debtAssetId, targetRatio, price, priceState, ratioState) {
|
|
400
396
|
const isBundle = true;
|
|
401
397
|
const subData = subDataService.aaveV4LeverageManagementOnPriceSubData.encode(spoke, owner, collAsset, collAssetId, debtAsset, debtAssetId, ratioState, targetRatio);
|
|
@@ -22,8 +22,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
25
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
29
|
const chai_1 = require("chai");
|
|
30
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
27
31
|
const sdk_1 = require("@defisaver/sdk");
|
|
28
32
|
const tokens_1 = require("@defisaver/tokens");
|
|
29
33
|
const web3Utils = __importStar(require("web3-utils"));
|
|
@@ -120,7 +124,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
120
124
|
});
|
|
121
125
|
});
|
|
122
126
|
});
|
|
123
|
-
describe('
|
|
127
|
+
describe('leverageManagementWithoutSubProxy()', () => {
|
|
124
128
|
const examples = [
|
|
125
129
|
// Repay scenario (isBoost=false, RatioState.UNDER)
|
|
126
130
|
[
|
|
@@ -163,7 +167,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
163
167
|
];
|
|
164
168
|
examples.forEach(([expected, actual]) => {
|
|
165
169
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
166
|
-
(0, chai_1.expect)(strategySubService_1.makerEncode.
|
|
170
|
+
(0, chai_1.expect)(strategySubService_1.makerEncode.leverageManagementWithoutSubProxy(...actual)).to.eql(expected);
|
|
167
171
|
});
|
|
168
172
|
});
|
|
169
173
|
});
|
|
@@ -290,6 +294,21 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
290
294
|
});
|
|
291
295
|
});
|
|
292
296
|
});
|
|
297
|
+
describe('When testing strategySubService.chickenBondsEncode', () => {
|
|
298
|
+
describe('rebond()', () => {
|
|
299
|
+
const examples = [
|
|
300
|
+
[
|
|
301
|
+
['0x00000000000000000000000000000000000000000000000000000000000005e3'],
|
|
302
|
+
[1507]
|
|
303
|
+
]
|
|
304
|
+
];
|
|
305
|
+
examples.forEach(([expected, actual]) => {
|
|
306
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
307
|
+
(0, chai_1.expect)(strategySubService_1.chickenBondsEncode.rebond(...actual)).to.eql(expected);
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
});
|
|
293
312
|
describe('When testing strategySubService.aaveV3Encode', () => {
|
|
294
313
|
describe('closeToAsset()', () => {
|
|
295
314
|
const examples = [
|
|
@@ -979,6 +998,25 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
979
998
|
});
|
|
980
999
|
});
|
|
981
1000
|
});
|
|
1001
|
+
describe('When testing strategySubService.morphoAaveV2Encode', () => {
|
|
1002
|
+
describe('leverageManagement()', () => {
|
|
1003
|
+
const examples = [
|
|
1004
|
+
[
|
|
1005
|
+
[new decimal_js_1.default(160).mul(1e16).toString(), new decimal_js_1.default(220).mul(1e16).toString(), new decimal_js_1.default(180).mul(1e16).toString(), new decimal_js_1.default(190).mul(1e16).toString(), true],
|
|
1006
|
+
[160, 220, 180, 190, true]
|
|
1007
|
+
],
|
|
1008
|
+
[
|
|
1009
|
+
[new decimal_js_1.default(160).mul(1e16).toString(), new decimal_js_1.default(200).mul(1e16).toString(), new decimal_js_1.default(180).mul(1e16).toString(), new decimal_js_1.default(190).mul(1e16).toString(), false],
|
|
1010
|
+
[160, 200, 180, 190, false]
|
|
1011
|
+
],
|
|
1012
|
+
];
|
|
1013
|
+
examples.forEach(([expected, actual]) => {
|
|
1014
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1015
|
+
(0, chai_1.expect)(strategySubService_1.morphoAaveV2Encode.leverageManagement(...actual)).to.eql(expected);
|
|
1016
|
+
});
|
|
1017
|
+
});
|
|
1018
|
+
});
|
|
1019
|
+
});
|
|
982
1020
|
describe('When testing strategySubService.exchangeEncode', () => {
|
|
983
1021
|
describe('dca()', () => {
|
|
984
1022
|
const examples = [
|
|
@@ -1254,6 +1292,75 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1254
1292
|
});
|
|
1255
1293
|
});
|
|
1256
1294
|
});
|
|
1295
|
+
describe('leverageManagementOnPriceGeneric()', () => {
|
|
1296
|
+
const examples = [
|
|
1297
|
+
[
|
|
1298
|
+
[
|
|
1299
|
+
enums_1.Bundles.MainnetIds.MORPHO_BLUE_REPAY_ON_PRICE,
|
|
1300
|
+
true,
|
|
1301
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1302
|
+
[
|
|
1303
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1304
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1305
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1306
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1307
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1308
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
1309
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1310
|
+
],
|
|
1311
|
+
],
|
|
1312
|
+
[
|
|
1313
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1314
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1315
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1316
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1317
|
+
'945000000000000000',
|
|
1318
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1319
|
+
200,
|
|
1320
|
+
2500,
|
|
1321
|
+
enums_1.RatioState.UNDER,
|
|
1322
|
+
false,
|
|
1323
|
+
false,
|
|
1324
|
+
enums_1.ChainId.Ethereum,
|
|
1325
|
+
],
|
|
1326
|
+
],
|
|
1327
|
+
[
|
|
1328
|
+
[
|
|
1329
|
+
enums_1.Bundles.MainnetIds.MORPHO_BLUE_BOOST_ON_PRICE,
|
|
1330
|
+
true,
|
|
1331
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000005d21dba0000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1332
|
+
[
|
|
1333
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1334
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1335
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1336
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1337
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1338
|
+
'0x00000000000000000000000000000000000000000000000016345785d8a00000',
|
|
1339
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1340
|
+
],
|
|
1341
|
+
],
|
|
1342
|
+
[
|
|
1343
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1344
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1345
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1346
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1347
|
+
'945000000000000000',
|
|
1348
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1349
|
+
160,
|
|
1350
|
+
4000,
|
|
1351
|
+
enums_1.RatioState.OVER,
|
|
1352
|
+
true,
|
|
1353
|
+
false,
|
|
1354
|
+
enums_1.ChainId.Ethereum,
|
|
1355
|
+
],
|
|
1356
|
+
],
|
|
1357
|
+
];
|
|
1358
|
+
examples.forEach(([expected, actual]) => {
|
|
1359
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1360
|
+
(0, chai_1.expect)(strategySubService_1.morphoBlueEncode.leverageManagementOnPriceGeneric(...actual)).to.eql(expected);
|
|
1361
|
+
});
|
|
1362
|
+
});
|
|
1363
|
+
});
|
|
1257
1364
|
describe('closeOnPrice()', () => {
|
|
1258
1365
|
const examples = [
|
|
1259
1366
|
[
|
|
@@ -1282,7 +1389,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1282
1389
|
1500,
|
|
1283
1390
|
enums_1.CloseToAssetType.DEBT,
|
|
1284
1391
|
4000,
|
|
1285
|
-
enums_1.CloseToAssetType.COLLATERAL
|
|
1392
|
+
enums_1.CloseToAssetType.COLLATERAL,
|
|
1286
1393
|
]
|
|
1287
1394
|
],
|
|
1288
1395
|
];
|
|
@@ -1292,6 +1399,45 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1292
1399
|
});
|
|
1293
1400
|
});
|
|
1294
1401
|
});
|
|
1402
|
+
describe('closeOnPriceGeneric()', () => {
|
|
1403
|
+
const examples = [
|
|
1404
|
+
[
|
|
1405
|
+
[
|
|
1406
|
+
enums_1.Bundles.MainnetIds.MORPHO_BLUE_CLOSE,
|
|
1407
|
+
true,
|
|
1408
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
1409
|
+
[
|
|
1410
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1411
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1412
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1413
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1414
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1415
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1416
|
+
'0x0000000000000000000000000000000000000000000000000000000000000005',
|
|
1417
|
+
],
|
|
1418
|
+
],
|
|
1419
|
+
[
|
|
1420
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1421
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1422
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1423
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1424
|
+
'945000000000000000',
|
|
1425
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1426
|
+
1500,
|
|
1427
|
+
enums_1.CloseToAssetType.DEBT,
|
|
1428
|
+
4000,
|
|
1429
|
+
enums_1.CloseToAssetType.COLLATERAL,
|
|
1430
|
+
false,
|
|
1431
|
+
enums_1.ChainId.Ethereum,
|
|
1432
|
+
]
|
|
1433
|
+
],
|
|
1434
|
+
];
|
|
1435
|
+
examples.forEach(([expected, actual]) => {
|
|
1436
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1437
|
+
(0, chai_1.expect)(strategySubService_1.morphoBlueEncode.closeOnPriceGeneric(...actual)).to.eql(expected);
|
|
1438
|
+
});
|
|
1439
|
+
});
|
|
1440
|
+
});
|
|
1295
1441
|
});
|
|
1296
1442
|
describe('When testing strategySubService.sparkEncode', () => {
|
|
1297
1443
|
describe('leverageManagementOnPrice()', () => {
|