@defisaver/automation-sdk 3.3.14 → 3.3.15-liq-prot-1-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 +130 -0
- package/cjs/index.d.ts +4 -3
- package/cjs/index.js +6 -2
- package/cjs/services/strategiesService.js +178 -17
- package/cjs/services/strategySubService.d.ts +14 -13
- package/cjs/services/strategySubService.js +79 -63
- package/cjs/services/strategySubService.test.js +0 -234
- package/cjs/services/subDataService.d.ts +92 -4
- package/cjs/services/subDataService.js +245 -35
- package/cjs/services/subDataService.test.js +0 -110
- package/cjs/services/utils.d.ts +3 -1
- package/cjs/services/utils.js +34 -1
- package/cjs/services/utils.test.js +25 -0
- package/cjs/types/enums.d.ts +36 -6
- package/cjs/types/enums.js +30 -0
- package/esm/constants/index.js +130 -0
- package/esm/index.d.ts +4 -3
- package/esm/index.js +7 -3
- package/esm/services/strategiesService.js +178 -17
- package/esm/services/strategySubService.d.ts +14 -13
- package/esm/services/strategySubService.js +79 -60
- package/esm/services/strategySubService.test.js +2 -236
- package/esm/services/subDataService.d.ts +92 -4
- package/esm/services/subDataService.js +243 -34
- package/esm/services/subDataService.test.js +0 -110
- package/esm/services/utils.d.ts +3 -1
- package/esm/services/utils.js +32 -1
- package/esm/services/utils.test.js +27 -2
- package/esm/types/enums.d.ts +36 -6
- package/esm/types/enums.js +30 -0
- package/package.json +1 -1
- package/src/constants/index.ts +132 -1
- package/src/index.ts +24 -6
- package/src/services/strategiesService.ts +242 -17
- package/src/services/strategySubService.test.ts +0 -279
- package/src/services/strategySubService.ts +209 -116
- package/src/services/subDataService.test.ts +0 -120
- package/src/services/subDataService.ts +335 -49
- package/src/services/utils.test.ts +32 -1
- package/src/services/utils.ts +32 -1
- package/src/types/enums.ts +30 -2
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import Dec from 'decimal.js';
|
|
2
1
|
import { getAssetInfo } from '@defisaver/tokens';
|
|
3
|
-
import { CloseToAssetType, Bundles, ChainId, RatioState, Strategies, } from '../types/enums';
|
|
4
2
|
import { STRATEGY_IDS } from '../constants';
|
|
3
|
+
import { Bundles, ChainId, CloseToAssetType, RatioState, Strategies, } from '../types/enums';
|
|
5
4
|
import * as subDataService from './subDataService';
|
|
6
5
|
import * as triggerService from './triggerService';
|
|
7
|
-
import { compareAddresses, getCloseStrategyType, requireAddress, requireAddresses, } from './utils';
|
|
6
|
+
import { compareAddresses, getBundleIdsByNetwork, getCloseStrategyType, requireAddress, requireAddresses, } from './utils';
|
|
8
7
|
export const makerEncode = {
|
|
9
8
|
repayFromSavings(bundleId, vaultId, triggerRepayRatio, targetRepayRatio, isBundle = true, chainId = ChainId.Ethereum, daiAddr, mcdCdpManagerAddr) {
|
|
10
9
|
const subData = subDataService.makerRepayFromSavingsSubData.encode(vaultId, targetRepayRatio, chainId, daiAddr, mcdCdpManagerAddr);
|
|
@@ -31,16 +30,6 @@ export const makerEncode = {
|
|
|
31
30
|
const isBundle = false;
|
|
32
31
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
33
32
|
},
|
|
34
|
-
leverageManagement(vaultId, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
35
|
-
return [
|
|
36
|
-
vaultId,
|
|
37
|
-
new Dec(triggerRepayRatio).mul(1e16).toString(),
|
|
38
|
-
new Dec(triggerBoostRatio).mul(1e16).toString(),
|
|
39
|
-
new Dec(targetBoostRatio).mul(1e16).toString(),
|
|
40
|
-
new Dec(targetRepayRatio).mul(1e16).toString(),
|
|
41
|
-
boostEnabled,
|
|
42
|
-
];
|
|
43
|
-
},
|
|
44
33
|
leverageManagementWithoutSubProxy(vaultId, triggerRatio, targetRatio, ratioState, isBoost, daiAddr) {
|
|
45
34
|
const bundleId = isBoost ? Bundles.MainnetIds.MAKER_BOOST : Bundles.MainnetIds.MAKER_REPAY;
|
|
46
35
|
const triggerData = triggerService.makerRatioTrigger.encode(vaultId, triggerRatio, ratioState);
|
|
@@ -52,6 +41,17 @@ export const makerEncode = {
|
|
|
52
41
|
subData,
|
|
53
42
|
];
|
|
54
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);
|
|
48
|
+
return [
|
|
49
|
+
bundleId,
|
|
50
|
+
true,
|
|
51
|
+
triggerData,
|
|
52
|
+
subData,
|
|
53
|
+
];
|
|
54
|
+
},
|
|
55
55
|
};
|
|
56
56
|
export const liquityEncode = {
|
|
57
57
|
closeOnPrice(priceOverOrUnder, price, closeToAssetAddr, chainlinkCollAddress, chainId = ChainId.Ethereum, collAddr, debtAddr) {
|
|
@@ -78,14 +78,11 @@ export const liquityEncode = {
|
|
|
78
78
|
const isBundle = true;
|
|
79
79
|
return [strategyId, isBundle, triggerData, subData];
|
|
80
80
|
},
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
new Dec(targetRepayRatio).mul(1e16).toString(),
|
|
87
|
-
boostEnabled,
|
|
88
|
-
];
|
|
81
|
+
leverageManagementWithoutSubProxy(strategyOrBundleId, user, ratioState, targetRatio, triggerRatio) {
|
|
82
|
+
const isBundle = true;
|
|
83
|
+
const subData = subDataService.liquityLeverageManagementSubDataWithoutSubProxy.encode(targetRatio, ratioState);
|
|
84
|
+
const triggerData = triggerService.liquityRatioTrigger.encode(user, triggerRatio, ratioState);
|
|
85
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
89
86
|
},
|
|
90
87
|
dsrPayback(proxyAddress, triggerRatio, targetRatio) {
|
|
91
88
|
requireAddress(proxyAddress);
|
|
@@ -118,24 +115,14 @@ export const chickenBondsEncode = {
|
|
|
118
115
|
},
|
|
119
116
|
};
|
|
120
117
|
export const aaveV2Encode = {
|
|
121
|
-
|
|
122
|
-
|
|
118
|
+
leverageManagementWithoutSubProxy(strategyOrBundleId, market, user, ratioState, targetRatio, triggerRatio) {
|
|
119
|
+
const isBundle = true;
|
|
120
|
+
const subData = subDataService.aaveV2LeverageManagementSubDataWithoutSubProxy.encode(market, targetRatio, ratioState);
|
|
121
|
+
const triggerData = triggerService.aaveV2RatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
122
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
123
123
|
},
|
|
124
124
|
};
|
|
125
125
|
export const aaveV3Encode = {
|
|
126
|
-
leverageManagement(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
127
|
-
let subInput = '0x';
|
|
128
|
-
subInput = subInput.concat(new Dec(triggerRepayRatio).mul(1e16).toHex().slice(2)
|
|
129
|
-
.padStart(32, '0'));
|
|
130
|
-
subInput = subInput.concat(new Dec(triggerBoostRatio).mul(1e16).toHex().slice(2)
|
|
131
|
-
.padStart(32, '0'));
|
|
132
|
-
subInput = subInput.concat(new Dec(targetBoostRatio).mul(1e16).toHex().slice(2)
|
|
133
|
-
.padStart(32, '0'));
|
|
134
|
-
subInput = subInput.concat(new Dec(targetRepayRatio).mul(1e16).toHex().slice(2)
|
|
135
|
-
.padStart(32, '0'));
|
|
136
|
-
subInput = subInput.concat(boostEnabled ? '01' : '00');
|
|
137
|
-
return subInput;
|
|
138
|
-
},
|
|
139
126
|
closeToAsset(strategyOrBundleId, isBundle = true, triggerData, subData) {
|
|
140
127
|
const { collAsset, collAssetId, debtAsset, debtAssetId, } = subData;
|
|
141
128
|
const subDataEncoded = subDataService.aaveV3QuotePriceSubData.encode(collAsset, collAssetId, debtAsset, debtAssetId);
|
|
@@ -163,6 +150,12 @@ export const aaveV3Encode = {
|
|
|
163
150
|
const triggerData = triggerService.aaveV3RatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
164
151
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
165
152
|
},
|
|
153
|
+
liquidationProtection(strategyOrBundleId, market, user, ratioState, targetRatio, triggerRatio) {
|
|
154
|
+
const isBundle = true;
|
|
155
|
+
const subData = subDataService.aaveV3LiquidationProtectionSubData.encode(targetRatio, ratioState, market, user);
|
|
156
|
+
const triggerData = triggerService.aaveV3RatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
157
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
158
|
+
},
|
|
166
159
|
leverageManagementOnPriceGeneric(strategyOrBundleId, price, ratioState, collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio, user) {
|
|
167
160
|
const isBundle = true;
|
|
168
161
|
const subDataEncoded = subDataService.aaveV3LeverageManagementOnPriceGeneric.encode(collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio, user);
|
|
@@ -184,13 +177,25 @@ export const aaveV3Encode = {
|
|
|
184
177
|
},
|
|
185
178
|
};
|
|
186
179
|
export const compoundV2Encode = {
|
|
187
|
-
|
|
188
|
-
|
|
180
|
+
leverageManagementWithoutSubProxy(strategyOrBundleId, user, ratioState, targetRatio, triggerRatio) {
|
|
181
|
+
const isBundle = true;
|
|
182
|
+
const subData = subDataService.compoundV2LeverageManagementSubDataWithoutSubProxy.encode(targetRatio, ratioState);
|
|
183
|
+
const triggerData = triggerService.compoundV2RatioTrigger.encode(user, triggerRatio, ratioState);
|
|
184
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
189
185
|
},
|
|
190
186
|
};
|
|
191
187
|
export const compoundV3Encode = {
|
|
192
|
-
|
|
193
|
-
|
|
188
|
+
leverageManagementWithoutSubProxy(strategyOrBundleId, market, baseToken, user, ratioState, targetRatio, triggerRatio) {
|
|
189
|
+
const isBundle = true;
|
|
190
|
+
const subData = subDataService.compoundV3LeverageManagementSubDataWithoutSubProxy.encode(market, baseToken, targetRatio, ratioState);
|
|
191
|
+
const triggerData = triggerService.compoundV3RatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
192
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
193
|
+
},
|
|
194
|
+
liquidationProtectionWithoutSubProxy(strategyOrBundleId, market, baseToken, user, ratioState, targetRatio, triggerRatio) {
|
|
195
|
+
const isBundle = true;
|
|
196
|
+
const subData = subDataService.compoundV3LiquidationProtectionSubDataWithoutSubProxy.encode(market, baseToken, targetRatio, ratioState);
|
|
197
|
+
const triggerData = triggerService.compoundV3RatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
198
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
194
199
|
},
|
|
195
200
|
leverageManagementOnPrice(strategyOrBundleId, market, collToken, baseToken, targetRatio, price, priceState, ratioState, // REPAY for repay on price, BOOST for boost on price
|
|
196
201
|
user) {
|
|
@@ -207,11 +212,6 @@ export const compoundV3Encode = {
|
|
|
207
212
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
208
213
|
},
|
|
209
214
|
};
|
|
210
|
-
export const compoundV3L2Encode = {
|
|
211
|
-
leverageManagement(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled, isEOA = false) {
|
|
212
|
-
return subDataService.compoundV3L2LeverageManagementSubData.encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled, isEOA);
|
|
213
|
-
},
|
|
214
|
-
};
|
|
215
215
|
export const morphoAaveV2Encode = {
|
|
216
216
|
leverageManagement(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
217
217
|
return subDataService.morphoAaveV2LeverageManagementSubData.encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled);
|
|
@@ -225,24 +225,15 @@ export const exchangeEncode = {
|
|
|
225
225
|
const strategyId = STRATEGY_IDS[network].EXCHANGE_DCA;
|
|
226
226
|
return [strategyId, false, triggerData, subData];
|
|
227
227
|
},
|
|
228
|
-
|
|
229
|
-
|
|
228
|
+
limitOrderWithoutSubProxy(fromToken, toToken, amount, targetPrice, goodUntil, orderType, fromTokenDecimals, toTokenDecimals, network) {
|
|
229
|
+
requireAddresses([fromToken, toToken]);
|
|
230
|
+
const subData = subDataService.exchangeLimitOrderSubDataWithoutSubProxy.encode(fromToken, toToken, amount);
|
|
231
|
+
const triggerData = triggerService.exchangeOffchainPriceTrigger.encode(targetPrice, Number(goodUntil), orderType, fromTokenDecimals, toTokenDecimals);
|
|
232
|
+
const strategyId = STRATEGY_IDS[network].EXCHANGE_LIMIT_ORDER;
|
|
233
|
+
return [strategyId, false, triggerData, subData];
|
|
230
234
|
},
|
|
231
235
|
};
|
|
232
236
|
export const sparkEncode = {
|
|
233
|
-
leverageManagement(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
234
|
-
let subInput = '0x';
|
|
235
|
-
subInput = subInput.concat(new Dec(triggerRepayRatio).mul(1e16).toHex().slice(2)
|
|
236
|
-
.padStart(32, '0'));
|
|
237
|
-
subInput = subInput.concat(new Dec(triggerBoostRatio).mul(1e16).toHex().slice(2)
|
|
238
|
-
.padStart(32, '0'));
|
|
239
|
-
subInput = subInput.concat(new Dec(targetBoostRatio).mul(1e16).toHex().slice(2)
|
|
240
|
-
.padStart(32, '0'));
|
|
241
|
-
subInput = subInput.concat(new Dec(targetRepayRatio).mul(1e16).toHex().slice(2)
|
|
242
|
-
.padStart(32, '0'));
|
|
243
|
-
subInput = subInput.concat(boostEnabled ? '01' : '00');
|
|
244
|
-
return subInput;
|
|
245
|
-
},
|
|
246
237
|
leverageManagementOnPrice(strategyOrBundleId, isBundle = true, triggerData, subData) {
|
|
247
238
|
const { collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio, } = subData;
|
|
248
239
|
const subDataEncoded = subDataService.sparkLeverageManagementOnPriceSubData.encode(collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio);
|
|
@@ -263,6 +254,12 @@ export const sparkEncode = {
|
|
|
263
254
|
const triggerData = triggerService.sparkRatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
264
255
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
265
256
|
},
|
|
257
|
+
liquidationProtection(strategyOrBundleId, market, user, ratioState, targetRatio, triggerRatio) {
|
|
258
|
+
const isBundle = true;
|
|
259
|
+
const subData = subDataService.sparkLiquidationProtectionSubData.encode(targetRatio, ratioState);
|
|
260
|
+
const triggerData = triggerService.sparkRatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
261
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
262
|
+
},
|
|
266
263
|
collateralSwitch(strategyOrBundleId, fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, baseTokenAddress, quoteTokenAddress, price, state) {
|
|
267
264
|
const isBundle = false;
|
|
268
265
|
const subDataEncoded = subDataService.sparkCollateralSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch);
|
|
@@ -305,6 +302,16 @@ export const morphoBlueEncode = {
|
|
|
305
302
|
const isBundle = true;
|
|
306
303
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
307
304
|
},
|
|
305
|
+
liquidationProtection(marketId, loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, triggerRatio, user, isEOA, network) {
|
|
306
|
+
const subData = subDataService.morphoBlueLiquidationProtectionSubData.encode(loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, user, isEOA);
|
|
307
|
+
const triggerData = triggerService.morphoBlueRatioTrigger.encode(marketId, user, triggerRatio, ratioState);
|
|
308
|
+
// Type casting because there is no MORPHO_BLUE_EOA_LIQUIDATION_PROTECTION for Base chain.
|
|
309
|
+
// That is fine because we will just always send isEOA == false for Base chain.
|
|
310
|
+
const bundleNetwork = getBundleIdsByNetwork(network);
|
|
311
|
+
const bundleId = isEOA ? bundleNetwork.MORPHO_BLUE_EOA_LIQUIDATION_PROTECTION : bundleNetwork.MORPHO_BLUE_SW_LIQUIDATION_PROTECTION;
|
|
312
|
+
const isBundle = true;
|
|
313
|
+
return [bundleId, isBundle, triggerData, subData];
|
|
314
|
+
},
|
|
308
315
|
leverageManagementOnPrice(strategyOrBundleId, isBundle = true, loanToken, collToken, oracle, irm, lltv, user, targetRatio, price, priceState) {
|
|
309
316
|
const subData = subDataService.morphoBlueLeverageManagementOnPriceSubData.encode(loanToken, collToken, oracle, irm, lltv, targetRatio, user);
|
|
310
317
|
const triggerData = triggerService.morphoBluePriceTrigger.encode(oracle, collToken, loanToken, price, priceState);
|
|
@@ -353,6 +360,12 @@ export const fluidEncode = {
|
|
|
353
360
|
const triggerData = triggerService.fluidRatioTrigger.encode(nftId, triggerRatio, ratioState);
|
|
354
361
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
355
362
|
},
|
|
363
|
+
liquidationProtection(nftId, vault, ratioState, targetRatio, triggerRatio, strategyOrBundleId) {
|
|
364
|
+
const isBundle = true;
|
|
365
|
+
const subData = subDataService.fluidLiquidationProtectionSubData.encode(nftId, vault, ratioState, targetRatio);
|
|
366
|
+
const triggerData = triggerService.fluidRatioTrigger.encode(nftId, triggerRatio, ratioState);
|
|
367
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
368
|
+
},
|
|
356
369
|
};
|
|
357
370
|
export const aaveV4Encode = {
|
|
358
371
|
leverageManagement(strategyOrBundleId, owner, spoke, ratioState, targetRatio, triggerRatio) {
|
|
@@ -361,6 +374,12 @@ export const aaveV4Encode = {
|
|
|
361
374
|
const triggerData = triggerService.aaveV4RatioTrigger.encode(owner, spoke, triggerRatio, ratioState);
|
|
362
375
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
363
376
|
},
|
|
377
|
+
liquidationProtection(strategyOrBundleId, owner, spoke, ratioState, targetRatio, triggerRatio) {
|
|
378
|
+
const isBundle = true;
|
|
379
|
+
const subData = subDataService.aaveV4LiquidationProtectionSubData.encode(spoke, owner, ratioState, targetRatio);
|
|
380
|
+
const triggerData = triggerService.aaveV4RatioTrigger.encode(owner, spoke, triggerRatio, ratioState);
|
|
381
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
382
|
+
},
|
|
364
383
|
leverageManagementOnPrice(strategyOrBundleId, owner, spoke, collAsset, collAssetId, debtAsset, debtAssetId, targetRatio, price, priceState, ratioState) {
|
|
365
384
|
const isBundle = true;
|
|
366
385
|
const subData = subDataService.aaveV4LeverageManagementOnPriceSubData.encode(spoke, owner, collAsset, collAssetId, debtAsset, debtAssetId, ratioState, targetRatio);
|
|
@@ -3,9 +3,9 @@ import Dec from 'decimal.js';
|
|
|
3
3
|
import { otherAddresses } from '@defisaver/sdk';
|
|
4
4
|
import { getAssetInfo, MAXUINT } from '@defisaver/tokens';
|
|
5
5
|
import * as web3Utils from 'web3-utils';
|
|
6
|
-
import { Bundles, ChainId, CloseToAssetType,
|
|
6
|
+
import { Bundles, ChainId, CloseToAssetType, RatioState, Strategies } from '../types/enums';
|
|
7
7
|
import '../configuration';
|
|
8
|
-
import {
|
|
8
|
+
import { chickenBondsEncode, liquityEncode, makerEncode, aaveV3Encode, compoundV3Encode, morphoAaveV2Encode, exchangeEncode, crvUSDEncode, morphoBlueEncode, sparkEncode, aaveV4Encode, } from './strategySubService';
|
|
9
9
|
describe('Feature: strategySubService.ts', () => {
|
|
10
10
|
describe('When testing strategySubService.makerEncode', () => {
|
|
11
11
|
// @ts-ignore // TODO - this requires change in @defisaver/tokens
|
|
@@ -96,28 +96,6 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
96
96
|
});
|
|
97
97
|
});
|
|
98
98
|
});
|
|
99
|
-
describe('leverageManagement()', () => {
|
|
100
|
-
const examples = [
|
|
101
|
-
[
|
|
102
|
-
[
|
|
103
|
-
5791,
|
|
104
|
-
new Dec('210').mul(1e16).toString(),
|
|
105
|
-
new Dec('290').mul(1e16).toString(),
|
|
106
|
-
new Dec('240').mul(1e16).toString(),
|
|
107
|
-
new Dec('240').mul(1e16).toString(),
|
|
108
|
-
true,
|
|
109
|
-
],
|
|
110
|
-
[
|
|
111
|
-
5791, '210', '290', '240', '240', true,
|
|
112
|
-
]
|
|
113
|
-
]
|
|
114
|
-
];
|
|
115
|
-
examples.forEach(([expected, actual]) => {
|
|
116
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
117
|
-
expect(makerEncode.leverageManagement(...actual)).to.eql(expected);
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
99
|
describe('leverageManagementWithoutSubProxy()', () => {
|
|
122
100
|
const examples = [
|
|
123
101
|
// Repay scenario (isBoost=false, RatioState.UNDER)
|
|
@@ -217,27 +195,6 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
217
195
|
});
|
|
218
196
|
});
|
|
219
197
|
});
|
|
220
|
-
describe('leverageManagement()', () => {
|
|
221
|
-
const examples = [
|
|
222
|
-
[
|
|
223
|
-
[
|
|
224
|
-
new Dec('210').mul(1e16).toString(),
|
|
225
|
-
new Dec('290').mul(1e16).toString(),
|
|
226
|
-
new Dec('240').mul(1e16).toString(),
|
|
227
|
-
new Dec('240').mul(1e16).toString(),
|
|
228
|
-
false,
|
|
229
|
-
],
|
|
230
|
-
[
|
|
231
|
-
'210', '290', '240', '240', false,
|
|
232
|
-
]
|
|
233
|
-
]
|
|
234
|
-
];
|
|
235
|
-
examples.forEach(([expected, actual]) => {
|
|
236
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
237
|
-
expect(liquityEncode.leverageManagement(...actual)).to.eql(expected);
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
});
|
|
241
198
|
describe('paybackFromChickenBondStrategySub()', () => {
|
|
242
199
|
const examples = [
|
|
243
200
|
[
|
|
@@ -324,43 +281,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
324
281
|
});
|
|
325
282
|
});
|
|
326
283
|
});
|
|
327
|
-
describe('When testing strategySubService.aaveV2Encode', () => {
|
|
328
|
-
describe('leverageManagement()', () => {
|
|
329
|
-
const examples = [
|
|
330
|
-
[
|
|
331
|
-
[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],
|
|
332
|
-
[160, 220, 180, 190, true]
|
|
333
|
-
],
|
|
334
|
-
[
|
|
335
|
-
[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],
|
|
336
|
-
[160, 200, 180, 190, false]
|
|
337
|
-
],
|
|
338
|
-
];
|
|
339
|
-
examples.forEach(([expected, actual]) => {
|
|
340
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
341
|
-
expect(aaveV2Encode.leverageManagement(...actual)).to.eql(expected);
|
|
342
|
-
});
|
|
343
|
-
});
|
|
344
|
-
});
|
|
345
|
-
});
|
|
346
284
|
describe('When testing strategySubService.aaveV3Encode', () => {
|
|
347
|
-
describe('leverageManagement()', () => {
|
|
348
|
-
const examples = [
|
|
349
|
-
[
|
|
350
|
-
'0x000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e000001',
|
|
351
|
-
[160, 220, 180, 190, true]
|
|
352
|
-
],
|
|
353
|
-
[
|
|
354
|
-
'0x000000000000000016345785d8a0000000000000000000001bc16d674ec80000000000000000000018fae27693b4000000000000000000001a5e27eef13e000000',
|
|
355
|
-
[160, 200, 180, 190, false]
|
|
356
|
-
],
|
|
357
|
-
];
|
|
358
|
-
examples.forEach(([expected, actual]) => {
|
|
359
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
360
|
-
expect(aaveV3Encode.leverageManagement(...actual)).to.eql(expected);
|
|
361
|
-
});
|
|
362
|
-
});
|
|
363
|
-
});
|
|
364
285
|
describe('closeToAsset()', () => {
|
|
365
286
|
const examples = [
|
|
366
287
|
[
|
|
@@ -927,69 +848,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
927
848
|
});
|
|
928
849
|
});
|
|
929
850
|
});
|
|
930
|
-
describe('When testing strategySubService.compoundV2Encode', () => {
|
|
931
|
-
describe('leverageManagement()', () => {
|
|
932
|
-
const examples = [
|
|
933
|
-
[
|
|
934
|
-
[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],
|
|
935
|
-
[160, 220, 180, 190, true]
|
|
936
|
-
],
|
|
937
|
-
[
|
|
938
|
-
[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],
|
|
939
|
-
[160, 200, 180, 190, false]
|
|
940
|
-
],
|
|
941
|
-
];
|
|
942
|
-
examples.forEach(([expected, actual]) => {
|
|
943
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
944
|
-
expect(compoundV2Encode.leverageManagement(...actual)).to.eql(expected);
|
|
945
|
-
});
|
|
946
|
-
});
|
|
947
|
-
});
|
|
948
|
-
});
|
|
949
851
|
describe('When testing strategySubService.compoundV3Encode', () => {
|
|
950
|
-
describe('leverageManagement()', () => {
|
|
951
|
-
const examples = [
|
|
952
|
-
[
|
|
953
|
-
[
|
|
954
|
-
web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
955
|
-
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
956
|
-
new Dec(160).mul(1e16).toString(),
|
|
957
|
-
new Dec(220).mul(1e16).toString(),
|
|
958
|
-
new Dec(180).mul(1e16).toString(),
|
|
959
|
-
new Dec(190).mul(1e16).toString(),
|
|
960
|
-
true, false,
|
|
961
|
-
],
|
|
962
|
-
[
|
|
963
|
-
web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
964
|
-
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
965
|
-
160, 220, 180, 190,
|
|
966
|
-
true, false,
|
|
967
|
-
]
|
|
968
|
-
],
|
|
969
|
-
[
|
|
970
|
-
[
|
|
971
|
-
web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
972
|
-
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
973
|
-
new Dec(160).mul(1e16).toString(),
|
|
974
|
-
new Dec(210).mul(1e16).toString(),
|
|
975
|
-
new Dec(180).mul(1e16).toString(),
|
|
976
|
-
new Dec(190).mul(1e16).toString(),
|
|
977
|
-
false, true,
|
|
978
|
-
],
|
|
979
|
-
[
|
|
980
|
-
web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
981
|
-
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
982
|
-
160, 210, 180, 190,
|
|
983
|
-
false, true,
|
|
984
|
-
]
|
|
985
|
-
],
|
|
986
|
-
];
|
|
987
|
-
examples.forEach(([expected, actual]) => {
|
|
988
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
989
|
-
expect(compoundV3Encode.leverageManagement(...actual)).to.eql(expected);
|
|
990
|
-
});
|
|
991
|
-
});
|
|
992
|
-
});
|
|
993
852
|
describe('leverageManagementOnPrice()', () => {
|
|
994
853
|
const examples = [
|
|
995
854
|
[
|
|
@@ -1164,51 +1023,6 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1164
1023
|
});
|
|
1165
1024
|
});
|
|
1166
1025
|
});
|
|
1167
|
-
describe('limitOrder()', () => {
|
|
1168
|
-
const examples = [
|
|
1169
|
-
[
|
|
1170
|
-
[
|
|
1171
|
-
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1172
|
-
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1173
|
-
'2131',
|
|
1174
|
-
'0.53123',
|
|
1175
|
-
'1696590921159',
|
|
1176
|
-
`${OrderType.STOP_LOSS}`
|
|
1177
|
-
],
|
|
1178
|
-
[
|
|
1179
|
-
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1180
|
-
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1181
|
-
'2131',
|
|
1182
|
-
'0.53123',
|
|
1183
|
-
1696590921159,
|
|
1184
|
-
OrderType.STOP_LOSS
|
|
1185
|
-
]
|
|
1186
|
-
],
|
|
1187
|
-
[
|
|
1188
|
-
[
|
|
1189
|
-
web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
|
|
1190
|
-
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
|
|
1191
|
-
'2131',
|
|
1192
|
-
'0.43123',
|
|
1193
|
-
'1646590921159',
|
|
1194
|
-
`${OrderType.TAKE_PROFIT}`
|
|
1195
|
-
],
|
|
1196
|
-
[
|
|
1197
|
-
web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
|
|
1198
|
-
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
|
|
1199
|
-
'2131',
|
|
1200
|
-
'0.43123',
|
|
1201
|
-
1646590921159,
|
|
1202
|
-
OrderType.TAKE_PROFIT
|
|
1203
|
-
]
|
|
1204
|
-
],
|
|
1205
|
-
];
|
|
1206
|
-
examples.forEach(([expected, actual]) => {
|
|
1207
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1208
|
-
expect(exchangeEncode.limitOrder(...actual)).to.eql(expected);
|
|
1209
|
-
});
|
|
1210
|
-
});
|
|
1211
|
-
});
|
|
1212
1026
|
});
|
|
1213
1027
|
describe('When testing strategySubService.crvUSDEncode', () => {
|
|
1214
1028
|
describe('leverageManagement()', () => {
|
|
@@ -1422,55 +1236,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1422
1236
|
});
|
|
1423
1237
|
});
|
|
1424
1238
|
});
|
|
1425
|
-
describe('When testing strategySubService.compoundV3L2Encode', () => {
|
|
1426
|
-
describe('leverageManagement()', () => {
|
|
1427
|
-
const examples = [
|
|
1428
|
-
[
|
|
1429
|
-
'0x0313D212133AFab8F2b829B1066c7e43caD94e2c0213D212133AfaB8F2b829B1066C7E43cAD94E2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e00000100',
|
|
1430
|
-
[
|
|
1431
|
-
web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'),
|
|
1432
|
-
web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'),
|
|
1433
|
-
160, 220, 180, 190,
|
|
1434
|
-
true,
|
|
1435
|
-
false,
|
|
1436
|
-
],
|
|
1437
|
-
],
|
|
1438
|
-
[
|
|
1439
|
-
'0x0313D212133AFab8F2b829B1066c7e43caD94e2c0413d212133afAb8F2B829b1066C7e43cAd94e2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000000f43fc2c04ee00000000',
|
|
1440
|
-
[
|
|
1441
|
-
web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'),
|
|
1442
|
-
web3Utils.toChecksumAddress('0x0413d212133AFaB8F2B829B1066c7E43cAd94E2c'),
|
|
1443
|
-
160, 220, 180, 110,
|
|
1444
|
-
false,
|
|
1445
|
-
false,
|
|
1446
|
-
],
|
|
1447
|
-
],
|
|
1448
|
-
];
|
|
1449
|
-
examples.forEach(([expected, actual]) => {
|
|
1450
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1451
|
-
expect(compoundV3L2Encode.leverageManagement(...actual)).to.eql(expected);
|
|
1452
|
-
});
|
|
1453
|
-
});
|
|
1454
|
-
});
|
|
1455
|
-
});
|
|
1456
1239
|
describe('When testing strategySubService.sparkEncode', () => {
|
|
1457
|
-
describe('leverageManagement()', () => {
|
|
1458
|
-
const examples = [
|
|
1459
|
-
[
|
|
1460
|
-
'0x0000000000000000136dcc951d8c00000000000000000000214e8348c4f0000000000000000000001d24b2dfac52000000000000000000001a5e27eef13e000001',
|
|
1461
|
-
[140, 240, 210, 190, true]
|
|
1462
|
-
],
|
|
1463
|
-
[
|
|
1464
|
-
'0x0000000000000000130337bdce49000000000000000000001988fe4052b800000000000000000000281b57b028e1000000000000000000002223acf76376000000',
|
|
1465
|
-
[137, 184, 289, 246, false]
|
|
1466
|
-
]
|
|
1467
|
-
];
|
|
1468
|
-
examples.forEach(([expected, actual]) => {
|
|
1469
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1470
|
-
expect(sparkEncode.leverageManagement(...actual)).to.eql(expected);
|
|
1471
|
-
});
|
|
1472
|
-
});
|
|
1473
|
-
});
|
|
1474
1240
|
describe('leverageManagementOnPrice()', () => {
|
|
1475
1241
|
const examples = [
|
|
1476
1242
|
[
|