@defisaver/automation-sdk 3.3.15 → 3.3.16-dev-13082-morpho-eoa-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 +70 -0
- package/cjs/services/strategiesService.js +4 -0
- package/cjs/services/strategySubService.d.ts +5 -1
- package/cjs/services/strategySubService.js +48 -11
- package/cjs/services/strategySubService.test.js +176 -1
- package/cjs/services/subDataService.test.js +100 -0
- package/cjs/services/triggerService.test.js +60 -0
- package/cjs/types/enums.d.ts +17 -3
- package/cjs/types/enums.js +14 -0
- package/esm/constants/index.js +70 -0
- package/esm/services/strategiesService.js +4 -0
- package/esm/services/strategySubService.d.ts +5 -1
- package/esm/services/strategySubService.js +46 -10
- package/esm/services/strategySubService.test.js +176 -1
- package/esm/services/subDataService.test.js +100 -0
- package/esm/services/triggerService.test.js +61 -1
- package/esm/types/enums.d.ts +17 -3
- package/esm/types/enums.js +14 -0
- package/package.json +1 -1
- package/src/constants/index.ts +70 -0
- package/src/services/strategiesService.ts +4 -0
- package/src/services/strategySubService.test.ts +229 -1
- package/src/services/strategySubService.ts +86 -11
- package/src/services/subDataService.test.ts +110 -0
- package/src/services/triggerService.test.ts +69 -0
- package/src/types/enums.ts +14 -0
package/cjs/types/enums.js
CHANGED
|
@@ -248,6 +248,10 @@ var Bundles;
|
|
|
248
248
|
MainnetIds[MainnetIds["AAVE_V4_EOA_REPAY_ON_PRICE"] = 68] = "AAVE_V4_EOA_REPAY_ON_PRICE";
|
|
249
249
|
MainnetIds[MainnetIds["AAVE_V4_EOA_BOOST_ON_PRICE"] = 69] = "AAVE_V4_EOA_BOOST_ON_PRICE";
|
|
250
250
|
MainnetIds[MainnetIds["AAVE_V4_EOA_CLOSE"] = 70] = "AAVE_V4_EOA_CLOSE";
|
|
251
|
+
MainnetIds[MainnetIds["MORPHO_BLUE_REPAY_ON_PRICE"] = 84] = "MORPHO_BLUE_REPAY_ON_PRICE";
|
|
252
|
+
MainnetIds[MainnetIds["MORPHO_BLUE_EOA_BOOST_ON_PRICE"] = 85] = "MORPHO_BLUE_EOA_BOOST_ON_PRICE";
|
|
253
|
+
MainnetIds[MainnetIds["MORPHO_BLUE_EOA_REPAY_ON_PRICE"] = 86] = "MORPHO_BLUE_EOA_REPAY_ON_PRICE";
|
|
254
|
+
MainnetIds[MainnetIds["MORPHO_BLUE_EOA_CLOSE"] = 87] = "MORPHO_BLUE_EOA_CLOSE";
|
|
251
255
|
})(MainnetIds = Bundles.MainnetIds || (Bundles.MainnetIds = {}));
|
|
252
256
|
let OptimismIds;
|
|
253
257
|
(function (OptimismIds) {
|
|
@@ -292,6 +296,12 @@ var Bundles;
|
|
|
292
296
|
BaseIds[BaseIds["AAVE_V3_EOA_BOOST_ON_PRICE"] = 26] = "AAVE_V3_EOA_BOOST_ON_PRICE";
|
|
293
297
|
BaseIds[BaseIds["AAVE_V3_EOA_CLOSE"] = 27] = "AAVE_V3_EOA_CLOSE";
|
|
294
298
|
BaseIds[BaseIds["MORPHO_BLUE_CLOSE"] = 28] = "MORPHO_BLUE_CLOSE";
|
|
299
|
+
BaseIds[BaseIds["MORPHO_BLUE_REPAY_ON_PRICE"] = 36] = "MORPHO_BLUE_REPAY_ON_PRICE";
|
|
300
|
+
BaseIds[BaseIds["MORPHO_BLUE_EOA_REPAY"] = 37] = "MORPHO_BLUE_EOA_REPAY";
|
|
301
|
+
BaseIds[BaseIds["MORPHO_BLUE_EOA_BOOST"] = 38] = "MORPHO_BLUE_EOA_BOOST";
|
|
302
|
+
BaseIds[BaseIds["MORPHO_BLUE_EOA_BOOST_ON_PRICE"] = 39] = "MORPHO_BLUE_EOA_BOOST_ON_PRICE";
|
|
303
|
+
BaseIds[BaseIds["MORPHO_BLUE_EOA_REPAY_ON_PRICE"] = 40] = "MORPHO_BLUE_EOA_REPAY_ON_PRICE";
|
|
304
|
+
BaseIds[BaseIds["MORPHO_BLUE_EOA_CLOSE"] = 41] = "MORPHO_BLUE_EOA_CLOSE";
|
|
295
305
|
})(BaseIds = Bundles.BaseIds || (Bundles.BaseIds = {}));
|
|
296
306
|
let ArbitrumIds;
|
|
297
307
|
(function (ArbitrumIds) {
|
|
@@ -324,5 +334,9 @@ var Bundles;
|
|
|
324
334
|
ArbitrumIds[ArbitrumIds["MORPHO_BLUE_EOA_REPAY"] = 26] = "MORPHO_BLUE_EOA_REPAY";
|
|
325
335
|
ArbitrumIds[ArbitrumIds["MORPHO_BLUE_EOA_BOOST"] = 27] = "MORPHO_BLUE_EOA_BOOST";
|
|
326
336
|
ArbitrumIds[ArbitrumIds["MORPHO_BLUE_CLOSE"] = 28] = "MORPHO_BLUE_CLOSE";
|
|
337
|
+
ArbitrumIds[ArbitrumIds["MORPHO_BLUE_REPAY_ON_PRICE"] = 36] = "MORPHO_BLUE_REPAY_ON_PRICE";
|
|
338
|
+
ArbitrumIds[ArbitrumIds["MORPHO_BLUE_EOA_BOOST_ON_PRICE"] = 37] = "MORPHO_BLUE_EOA_BOOST_ON_PRICE";
|
|
339
|
+
ArbitrumIds[ArbitrumIds["MORPHO_BLUE_EOA_REPAY_ON_PRICE"] = 38] = "MORPHO_BLUE_EOA_REPAY_ON_PRICE";
|
|
340
|
+
ArbitrumIds[ArbitrumIds["MORPHO_BLUE_EOA_CLOSE"] = 39] = "MORPHO_BLUE_EOA_CLOSE";
|
|
327
341
|
})(ArbitrumIds = Bundles.ArbitrumIds || (Bundles.ArbitrumIds = {}));
|
|
328
342
|
})(Bundles = exports.Bundles || (exports.Bundles = {}));
|
package/esm/constants/index.js
CHANGED
|
@@ -543,6 +543,26 @@ export const MAINNET_BUNDLES_INFO = {
|
|
|
543
543
|
strategyId: Strategies.Identifiers.EoaCloseOnPrice,
|
|
544
544
|
protocol: PROTOCOLS.AaveV4,
|
|
545
545
|
},
|
|
546
|
+
[Bundles.MainnetIds.MORPHO_BLUE_REPAY_ON_PRICE]: {
|
|
547
|
+
strategyOrBundleId: Bundles.MainnetIds.MORPHO_BLUE_REPAY_ON_PRICE,
|
|
548
|
+
strategyId: Strategies.Identifiers.RepayOnPrice,
|
|
549
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
550
|
+
},
|
|
551
|
+
[Bundles.MainnetIds.MORPHO_BLUE_EOA_BOOST_ON_PRICE]: {
|
|
552
|
+
strategyOrBundleId: Bundles.MainnetIds.MORPHO_BLUE_EOA_BOOST_ON_PRICE,
|
|
553
|
+
strategyId: Strategies.Identifiers.EoaBoostOnPrice,
|
|
554
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
555
|
+
},
|
|
556
|
+
[Bundles.MainnetIds.MORPHO_BLUE_EOA_REPAY_ON_PRICE]: {
|
|
557
|
+
strategyOrBundleId: Bundles.MainnetIds.MORPHO_BLUE_EOA_REPAY_ON_PRICE,
|
|
558
|
+
strategyId: Strategies.Identifiers.EoaRepayOnPrice,
|
|
559
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
560
|
+
},
|
|
561
|
+
[Bundles.MainnetIds.MORPHO_BLUE_EOA_CLOSE]: {
|
|
562
|
+
strategyOrBundleId: Bundles.MainnetIds.MORPHO_BLUE_EOA_CLOSE,
|
|
563
|
+
strategyId: Strategies.Identifiers.EoaCloseOnPrice,
|
|
564
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
565
|
+
},
|
|
546
566
|
};
|
|
547
567
|
export const OPTIMISM_BUNDLES_INFO = {
|
|
548
568
|
[Bundles.OptimismIds.AAVE_V3_REPAY]: {
|
|
@@ -737,6 +757,36 @@ export const BASE_BUNDLES_INFO = {
|
|
|
737
757
|
strategyId: Strategies.Identifiers.CloseOnPrice,
|
|
738
758
|
protocol: PROTOCOLS.MorphoBlue,
|
|
739
759
|
},
|
|
760
|
+
[Bundles.BaseIds.MORPHO_BLUE_REPAY_ON_PRICE]: {
|
|
761
|
+
strategyOrBundleId: Bundles.BaseIds.MORPHO_BLUE_REPAY_ON_PRICE,
|
|
762
|
+
strategyId: Strategies.Identifiers.RepayOnPrice,
|
|
763
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
764
|
+
},
|
|
765
|
+
[Bundles.BaseIds.MORPHO_BLUE_EOA_REPAY]: {
|
|
766
|
+
strategyOrBundleId: Bundles.BaseIds.MORPHO_BLUE_EOA_REPAY,
|
|
767
|
+
strategyId: Strategies.Identifiers.EoaRepay,
|
|
768
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
769
|
+
},
|
|
770
|
+
[Bundles.BaseIds.MORPHO_BLUE_EOA_BOOST]: {
|
|
771
|
+
strategyOrBundleId: Bundles.BaseIds.MORPHO_BLUE_EOA_BOOST,
|
|
772
|
+
strategyId: Strategies.Identifiers.EoaBoost,
|
|
773
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
774
|
+
},
|
|
775
|
+
[Bundles.BaseIds.MORPHO_BLUE_EOA_BOOST_ON_PRICE]: {
|
|
776
|
+
strategyOrBundleId: Bundles.BaseIds.MORPHO_BLUE_EOA_BOOST_ON_PRICE,
|
|
777
|
+
strategyId: Strategies.Identifiers.EoaBoostOnPrice,
|
|
778
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
779
|
+
},
|
|
780
|
+
[Bundles.BaseIds.MORPHO_BLUE_EOA_REPAY_ON_PRICE]: {
|
|
781
|
+
strategyOrBundleId: Bundles.BaseIds.MORPHO_BLUE_EOA_REPAY_ON_PRICE,
|
|
782
|
+
strategyId: Strategies.Identifiers.EoaRepayOnPrice,
|
|
783
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
784
|
+
},
|
|
785
|
+
[Bundles.BaseIds.MORPHO_BLUE_EOA_CLOSE]: {
|
|
786
|
+
strategyOrBundleId: Bundles.BaseIds.MORPHO_BLUE_EOA_CLOSE,
|
|
787
|
+
strategyId: Strategies.Identifiers.EoaCloseOnPrice,
|
|
788
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
789
|
+
},
|
|
740
790
|
};
|
|
741
791
|
export const ARBITRUM_BUNDLES_INFO = {
|
|
742
792
|
[Bundles.ArbitrumIds.AAVE_V3_REPAY]: {
|
|
@@ -884,6 +934,26 @@ export const ARBITRUM_BUNDLES_INFO = {
|
|
|
884
934
|
strategyId: Strategies.Identifiers.CloseOnPrice,
|
|
885
935
|
protocol: PROTOCOLS.MorphoBlue,
|
|
886
936
|
},
|
|
937
|
+
[Bundles.ArbitrumIds.MORPHO_BLUE_REPAY_ON_PRICE]: {
|
|
938
|
+
strategyOrBundleId: Bundles.ArbitrumIds.MORPHO_BLUE_REPAY_ON_PRICE,
|
|
939
|
+
strategyId: Strategies.Identifiers.RepayOnPrice,
|
|
940
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
941
|
+
},
|
|
942
|
+
[Bundles.ArbitrumIds.MORPHO_BLUE_EOA_BOOST_ON_PRICE]: {
|
|
943
|
+
strategyOrBundleId: Bundles.ArbitrumIds.MORPHO_BLUE_EOA_BOOST_ON_PRICE,
|
|
944
|
+
strategyId: Strategies.Identifiers.EoaBoostOnPrice,
|
|
945
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
946
|
+
},
|
|
947
|
+
[Bundles.ArbitrumIds.MORPHO_BLUE_EOA_REPAY_ON_PRICE]: {
|
|
948
|
+
strategyOrBundleId: Bundles.ArbitrumIds.MORPHO_BLUE_EOA_REPAY_ON_PRICE,
|
|
949
|
+
strategyId: Strategies.Identifiers.EoaRepayOnPrice,
|
|
950
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
951
|
+
},
|
|
952
|
+
[Bundles.ArbitrumIds.MORPHO_BLUE_EOA_CLOSE]: {
|
|
953
|
+
strategyOrBundleId: Bundles.ArbitrumIds.MORPHO_BLUE_EOA_CLOSE,
|
|
954
|
+
strategyId: Strategies.Identifiers.EoaCloseOnPrice,
|
|
955
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
956
|
+
},
|
|
887
957
|
};
|
|
888
958
|
export const BUNDLES_INFO = {
|
|
889
959
|
[ChainId.Ethereum]: MAINNET_BUNDLES_INFO,
|
|
@@ -1110,7 +1110,11 @@ const parsingMethodsMapping = {
|
|
|
1110
1110
|
[Strategies.Identifiers.EoaRepay]: parseMorphoBlueLeverageManagement,
|
|
1111
1111
|
[Strategies.Identifiers.EoaBoost]: parseMorphoBlueLeverageManagement,
|
|
1112
1112
|
[Strategies.Identifiers.BoostOnPrice]: parseMorphoBlueLeverageManagementOnPrice,
|
|
1113
|
+
[Strategies.Identifiers.RepayOnPrice]: parseMorphoBlueLeverageManagementOnPrice,
|
|
1114
|
+
[Strategies.Identifiers.EoaBoostOnPrice]: parseMorphoBlueLeverageManagementOnPrice,
|
|
1115
|
+
[Strategies.Identifiers.EoaRepayOnPrice]: parseMorphoBlueLeverageManagementOnPrice,
|
|
1113
1116
|
[Strategies.Identifiers.CloseOnPrice]: parseMorphoBlueCloseOnPrice,
|
|
1117
|
+
[Strategies.Identifiers.EoaCloseOnPrice]: parseMorphoBlueCloseOnPrice,
|
|
1114
1118
|
},
|
|
1115
1119
|
[ProtocolIdentifiers.StrategiesAutomation.FluidT1]: {
|
|
1116
1120
|
[Strategies.Identifiers.Repay]: parseFluidT1LeverageManagement,
|
|
@@ -101,10 +101,14 @@ export declare const crvUSDEncode: {
|
|
|
101
101
|
leverageManagement(owner: EthereumAddress, controllerAddr: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, collTokenAddr: EthereumAddress, crvUSDAddr: EthereumAddress): (boolean | string[] | Bundles.MainnetIds)[];
|
|
102
102
|
payback(proxyAddress: EthereumAddress, addressToPullTokensFrom: EthereumAddress, positionOwner: EthereumAddress, paybackAmount: string, crvUSDAddr: EthereumAddress, controllerAddr: EthereumAddress, minHealthRatio: number): (boolean | string[] | Strategies.MainnetIds)[];
|
|
103
103
|
};
|
|
104
|
+
export type MorphoBlueBundleStrategy = 'repay' | 'boost' | 'repayOnPrice' | 'boostOnPrice' | 'close';
|
|
105
|
+
export declare function getMorphoBlueBundleId(network: ChainId, strategy: MorphoBlueBundleStrategy, isEOA: boolean): number;
|
|
104
106
|
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): (
|
|
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[])[];
|
|
106
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[])[];
|
|
107
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[])[];
|
|
108
112
|
};
|
|
109
113
|
export declare const liquityV2Encode: {
|
|
110
114
|
leverageManagement(market: EthereumAddress, troveId: string, collToken: EthereumAddress, boldToken: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, strategyOrBundleId: number): (number | boolean | string[])[];
|
|
@@ -255,29 +255,57 @@ export const crvUSDEncode = {
|
|
|
255
255
|
return [strategyId, isBundle, triggerData, subData];
|
|
256
256
|
},
|
|
257
257
|
};
|
|
258
|
+
function getMorphoBlueBundlesIds(network) {
|
|
259
|
+
switch (network) {
|
|
260
|
+
case ChainId.Ethereum:
|
|
261
|
+
return Bundles.MainnetIds;
|
|
262
|
+
case ChainId.Base:
|
|
263
|
+
return Bundles.BaseIds;
|
|
264
|
+
case ChainId.Arbitrum:
|
|
265
|
+
return Bundles.ArbitrumIds;
|
|
266
|
+
default:
|
|
267
|
+
throw new Error(`Morpho Blue strategies are not supported on chain ${network}`);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
export function getMorphoBlueBundleId(network, strategy, isEOA) {
|
|
271
|
+
const bundlesIds = getMorphoBlueBundlesIds(network);
|
|
272
|
+
switch (strategy) {
|
|
273
|
+
case 'repay':
|
|
274
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_REPAY : bundlesIds.MORPHO_BLUE_REPAY;
|
|
275
|
+
case 'boost':
|
|
276
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_BOOST : bundlesIds.MORPHO_BLUE_BOOST;
|
|
277
|
+
case 'repayOnPrice':
|
|
278
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_REPAY_ON_PRICE : bundlesIds.MORPHO_BLUE_REPAY_ON_PRICE;
|
|
279
|
+
case 'boostOnPrice':
|
|
280
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_BOOST_ON_PRICE : bundlesIds.MORPHO_BLUE_BOOST_ON_PRICE;
|
|
281
|
+
case 'close':
|
|
282
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_CLOSE : bundlesIds.MORPHO_BLUE_CLOSE;
|
|
283
|
+
default:
|
|
284
|
+
throw new Error(`Unknown Morpho Blue strategy: ${strategy}`);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
258
287
|
export const morphoBlueEncode = {
|
|
259
288
|
leverageManagement(marketId, loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, triggerRatio, user, isEOA, network) {
|
|
260
289
|
const subData = subDataService.morphoBlueLeverageManagementSubData.encode(loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, user, isEOA);
|
|
261
290
|
const triggerData = triggerService.morphoBlueRatioTrigger.encode(marketId, user, triggerRatio, ratioState);
|
|
262
291
|
// over is boost, under is repay
|
|
263
292
|
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;
|
|
293
|
+
const bundleId = getMorphoBlueBundleId(network, isBoost ? 'boost' : 'repay', isEOA);
|
|
273
294
|
const isBundle = true;
|
|
274
|
-
return [
|
|
295
|
+
return [bundleId, isBundle, triggerData, subData];
|
|
275
296
|
},
|
|
276
297
|
leverageManagementOnPrice(strategyOrBundleId, isBundle = true, loanToken, collToken, oracle, irm, lltv, user, targetRatio, price, priceState) {
|
|
277
298
|
const subData = subDataService.morphoBlueLeverageManagementOnPriceSubData.encode(loanToken, collToken, oracle, irm, lltv, targetRatio, user);
|
|
278
299
|
const triggerData = triggerService.morphoBluePriceTrigger.encode(oracle, collToken, loanToken, price, priceState);
|
|
279
300
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
280
301
|
},
|
|
302
|
+
leverageManagementOnPriceGeneric(loanToken, collToken, oracle, irm, lltv, user, targetRatio, price, priceState, isBoost, isEOA, network) {
|
|
303
|
+
const subData = subDataService.morphoBlueLeverageManagementOnPriceSubData.encode(loanToken, collToken, oracle, irm, lltv, targetRatio, user);
|
|
304
|
+
const triggerData = triggerService.morphoBluePriceTrigger.encode(oracle, collToken, loanToken, price, priceState);
|
|
305
|
+
const bundleId = getMorphoBlueBundleId(network, isBoost ? 'boostOnPrice' : 'repayOnPrice', isEOA);
|
|
306
|
+
const isBundle = true;
|
|
307
|
+
return [bundleId, isBundle, triggerData, subData];
|
|
308
|
+
},
|
|
281
309
|
closeOnPrice(strategyOrBundleId, loanToken, collToken, oracle, irm, lltv, user, stopLossPrice = 0, stopLossType = CloseToAssetType.DEBT, takeProfitPrice = 0, takeProfitType = CloseToAssetType.COLLATERAL) {
|
|
282
310
|
const isBundle = true;
|
|
283
311
|
const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
@@ -285,6 +313,14 @@ export const morphoBlueEncode = {
|
|
|
285
313
|
const triggerDataEncoded = triggerService.morphoBluePriceRangeTrigger.encode(oracle, collToken, loanToken, stopLossPrice, takeProfitPrice);
|
|
286
314
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
287
315
|
},
|
|
316
|
+
closeOnPriceGeneric(loanToken, collToken, oracle, irm, lltv, user, stopLossPrice = 0, stopLossType = CloseToAssetType.DEBT, takeProfitPrice = 0, takeProfitType = CloseToAssetType.COLLATERAL, isEOA, network) {
|
|
317
|
+
const isBundle = true;
|
|
318
|
+
const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
319
|
+
const subDataEncoded = subDataService.morphoBlueCloseOnPriceSubData.encode(loanToken, collToken, oracle, irm, lltv, user, closeType);
|
|
320
|
+
const triggerDataEncoded = triggerService.morphoBluePriceRangeTrigger.encode(oracle, collToken, loanToken, stopLossPrice, takeProfitPrice);
|
|
321
|
+
const bundleId = getMorphoBlueBundleId(network, 'close', isEOA);
|
|
322
|
+
return [bundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
323
|
+
},
|
|
288
324
|
};
|
|
289
325
|
export const liquityV2Encode = {
|
|
290
326
|
leverageManagement(market, troveId, collToken, boldToken, ratioState, targetRatio, triggerRatio, strategyOrBundleId) {
|
|
@@ -1197,6 +1197,142 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1197
1197
|
});
|
|
1198
1198
|
});
|
|
1199
1199
|
});
|
|
1200
|
+
describe('leverageManagementOnPrice()', () => {
|
|
1201
|
+
const examples = [
|
|
1202
|
+
[
|
|
1203
|
+
[
|
|
1204
|
+
Bundles.MainnetIds.MORPHO_BLUE_REPAY_ON_PRICE,
|
|
1205
|
+
true,
|
|
1206
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1207
|
+
[
|
|
1208
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1209
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1210
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1211
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1212
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1213
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
1214
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1215
|
+
],
|
|
1216
|
+
],
|
|
1217
|
+
[
|
|
1218
|
+
Bundles.MainnetIds.MORPHO_BLUE_REPAY_ON_PRICE,
|
|
1219
|
+
true,
|
|
1220
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1221
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1222
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1223
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1224
|
+
'945000000000000000',
|
|
1225
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1226
|
+
200,
|
|
1227
|
+
2500,
|
|
1228
|
+
RatioState.UNDER,
|
|
1229
|
+
],
|
|
1230
|
+
],
|
|
1231
|
+
[
|
|
1232
|
+
[
|
|
1233
|
+
Bundles.MainnetIds.MORPHO_BLUE_BOOST_ON_PRICE,
|
|
1234
|
+
true,
|
|
1235
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000005d21dba0000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1236
|
+
[
|
|
1237
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1238
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1239
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1240
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1241
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1242
|
+
'0x00000000000000000000000000000000000000000000000016345785d8a00000',
|
|
1243
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1244
|
+
],
|
|
1245
|
+
],
|
|
1246
|
+
[
|
|
1247
|
+
Bundles.MainnetIds.MORPHO_BLUE_BOOST_ON_PRICE,
|
|
1248
|
+
true,
|
|
1249
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1250
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1251
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1252
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1253
|
+
'945000000000000000',
|
|
1254
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1255
|
+
160,
|
|
1256
|
+
4000,
|
|
1257
|
+
RatioState.OVER,
|
|
1258
|
+
],
|
|
1259
|
+
],
|
|
1260
|
+
];
|
|
1261
|
+
examples.forEach(([expected, actual]) => {
|
|
1262
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1263
|
+
expect(morphoBlueEncode.leverageManagementOnPrice(...actual)).to.eql(expected);
|
|
1264
|
+
});
|
|
1265
|
+
});
|
|
1266
|
+
});
|
|
1267
|
+
describe('leverageManagementOnPriceGeneric()', () => {
|
|
1268
|
+
const examples = [
|
|
1269
|
+
[
|
|
1270
|
+
[
|
|
1271
|
+
Bundles.MainnetIds.MORPHO_BLUE_REPAY_ON_PRICE,
|
|
1272
|
+
true,
|
|
1273
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1274
|
+
[
|
|
1275
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1276
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1277
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1278
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1279
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1280
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
1281
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1282
|
+
],
|
|
1283
|
+
],
|
|
1284
|
+
[
|
|
1285
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1286
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1287
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1288
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1289
|
+
'945000000000000000',
|
|
1290
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1291
|
+
200,
|
|
1292
|
+
2500,
|
|
1293
|
+
RatioState.UNDER,
|
|
1294
|
+
false,
|
|
1295
|
+
false,
|
|
1296
|
+
ChainId.Ethereum,
|
|
1297
|
+
],
|
|
1298
|
+
],
|
|
1299
|
+
[
|
|
1300
|
+
[
|
|
1301
|
+
Bundles.MainnetIds.MORPHO_BLUE_BOOST_ON_PRICE,
|
|
1302
|
+
true,
|
|
1303
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000005d21dba0000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1304
|
+
[
|
|
1305
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1306
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1307
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1308
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1309
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1310
|
+
'0x00000000000000000000000000000000000000000000000016345785d8a00000',
|
|
1311
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1312
|
+
],
|
|
1313
|
+
],
|
|
1314
|
+
[
|
|
1315
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1316
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1317
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1318
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1319
|
+
'945000000000000000',
|
|
1320
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1321
|
+
160,
|
|
1322
|
+
4000,
|
|
1323
|
+
RatioState.OVER,
|
|
1324
|
+
true,
|
|
1325
|
+
false,
|
|
1326
|
+
ChainId.Ethereum,
|
|
1327
|
+
],
|
|
1328
|
+
],
|
|
1329
|
+
];
|
|
1330
|
+
examples.forEach(([expected, actual]) => {
|
|
1331
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1332
|
+
expect(morphoBlueEncode.leverageManagementOnPriceGeneric(...actual)).to.eql(expected);
|
|
1333
|
+
});
|
|
1334
|
+
});
|
|
1335
|
+
});
|
|
1200
1336
|
describe('closeOnPrice()', () => {
|
|
1201
1337
|
const examples = [
|
|
1202
1338
|
[
|
|
@@ -1225,7 +1361,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1225
1361
|
1500,
|
|
1226
1362
|
CloseToAssetType.DEBT,
|
|
1227
1363
|
4000,
|
|
1228
|
-
CloseToAssetType.COLLATERAL
|
|
1364
|
+
CloseToAssetType.COLLATERAL,
|
|
1229
1365
|
]
|
|
1230
1366
|
],
|
|
1231
1367
|
];
|
|
@@ -1235,6 +1371,45 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1235
1371
|
});
|
|
1236
1372
|
});
|
|
1237
1373
|
});
|
|
1374
|
+
describe('closeOnPriceGeneric()', () => {
|
|
1375
|
+
const examples = [
|
|
1376
|
+
[
|
|
1377
|
+
[
|
|
1378
|
+
Bundles.MainnetIds.MORPHO_BLUE_CLOSE,
|
|
1379
|
+
true,
|
|
1380
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
1381
|
+
[
|
|
1382
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1383
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1384
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1385
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1386
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1387
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1388
|
+
'0x0000000000000000000000000000000000000000000000000000000000000005',
|
|
1389
|
+
],
|
|
1390
|
+
],
|
|
1391
|
+
[
|
|
1392
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1393
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1394
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1395
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1396
|
+
'945000000000000000',
|
|
1397
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1398
|
+
1500,
|
|
1399
|
+
CloseToAssetType.DEBT,
|
|
1400
|
+
4000,
|
|
1401
|
+
CloseToAssetType.COLLATERAL,
|
|
1402
|
+
false,
|
|
1403
|
+
ChainId.Ethereum,
|
|
1404
|
+
]
|
|
1405
|
+
],
|
|
1406
|
+
];
|
|
1407
|
+
examples.forEach(([expected, actual]) => {
|
|
1408
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1409
|
+
expect(morphoBlueEncode.closeOnPriceGeneric(...actual)).to.eql(expected);
|
|
1410
|
+
});
|
|
1411
|
+
});
|
|
1412
|
+
});
|
|
1238
1413
|
});
|
|
1239
1414
|
describe('When testing strategySubService.sparkEncode', () => {
|
|
1240
1415
|
describe('leverageManagementOnPrice()', () => {
|
|
@@ -1451,6 +1451,106 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1451
1451
|
});
|
|
1452
1452
|
});
|
|
1453
1453
|
});
|
|
1454
|
+
describe('When testing subDataService.morphoBlueLeverageManagementOnPriceSubData', () => {
|
|
1455
|
+
describe('encode()', () => {
|
|
1456
|
+
const examples = [
|
|
1457
|
+
[
|
|
1458
|
+
[
|
|
1459
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1460
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1461
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1462
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1463
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1464
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
1465
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1466
|
+
],
|
|
1467
|
+
[
|
|
1468
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1469
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1470
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1471
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1472
|
+
'945000000000000000',
|
|
1473
|
+
200,
|
|
1474
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1475
|
+
],
|
|
1476
|
+
],
|
|
1477
|
+
[
|
|
1478
|
+
[
|
|
1479
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1480
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1481
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1482
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1483
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1484
|
+
'0x00000000000000000000000000000000000000000000000016345785d8a00000',
|
|
1485
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1486
|
+
],
|
|
1487
|
+
[
|
|
1488
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1489
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1490
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1491
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1492
|
+
'945000000000000000',
|
|
1493
|
+
160,
|
|
1494
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1495
|
+
],
|
|
1496
|
+
],
|
|
1497
|
+
];
|
|
1498
|
+
examples.forEach(([expected, actual]) => {
|
|
1499
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1500
|
+
expect(subDataService.morphoBlueLeverageManagementOnPriceSubData.encode(...actual)).to.eql(expected);
|
|
1501
|
+
});
|
|
1502
|
+
});
|
|
1503
|
+
});
|
|
1504
|
+
describe('decode()', () => {
|
|
1505
|
+
const examples = [
|
|
1506
|
+
[
|
|
1507
|
+
{
|
|
1508
|
+
loanToken: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
|
|
1509
|
+
collToken: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0',
|
|
1510
|
+
oracle: '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
|
|
1511
|
+
irm: '0x0000000000000000000000000000000000000000',
|
|
1512
|
+
lltv: '945000000000000000',
|
|
1513
|
+
targetRatio: 200,
|
|
1514
|
+
user: '0x1031d218133AFaB8C2B819B1366c7e434Ad91e9c',
|
|
1515
|
+
},
|
|
1516
|
+
[
|
|
1517
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1518
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1519
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1520
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1521
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1522
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
1523
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1524
|
+
],
|
|
1525
|
+
],
|
|
1526
|
+
[
|
|
1527
|
+
{
|
|
1528
|
+
loanToken: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
|
|
1529
|
+
collToken: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0',
|
|
1530
|
+
oracle: '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
|
|
1531
|
+
irm: '0x0000000000000000000000000000000000000000',
|
|
1532
|
+
lltv: '945000000000000000',
|
|
1533
|
+
targetRatio: 160,
|
|
1534
|
+
user: '0x1031d218133AFaB8C2B819B1366c7e434Ad91e9c',
|
|
1535
|
+
},
|
|
1536
|
+
[
|
|
1537
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1538
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1539
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1540
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1541
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1542
|
+
'0x00000000000000000000000000000000000000000000000016345785d8a00000',
|
|
1543
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1544
|
+
],
|
|
1545
|
+
],
|
|
1546
|
+
];
|
|
1547
|
+
examples.forEach(([expected, actual]) => {
|
|
1548
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1549
|
+
expect(subDataService.morphoBlueLeverageManagementOnPriceSubData.decode(actual)).to.eql(expected);
|
|
1550
|
+
});
|
|
1551
|
+
});
|
|
1552
|
+
});
|
|
1553
|
+
});
|
|
1454
1554
|
describe('When testing subDataService.aaveV3LeverageManagementOnPriceSubData', () => {
|
|
1455
1555
|
describe('encode()', () => {
|
|
1456
1556
|
const examples = [
|
|
@@ -3,7 +3,7 @@ import { getAssetInfo, MAXUINT } from '@defisaver/tokens';
|
|
|
3
3
|
import * as web3Utils from 'web3-utils';
|
|
4
4
|
import { ChainId, OrderType, RatioState } from '../types/enums';
|
|
5
5
|
import '../configuration';
|
|
6
|
-
import { aaveV2RatioTrigger, aaveV3QuotePriceTrigger, aaveV3QuotePriceWithMaximumGasPriceTrigger, aaveV3RatioTrigger, cBondsRebondTrigger, chainlinkPriceTrigger, compoundV2RatioTrigger, compoundV3RatioTrigger, compoundV3PriceTrigger, curveUsdBorrowRateTrigger, curveUsdSoftLiquidationTrigger, exchangeOffchainPriceTrigger, exchangeTimestampTrigger, liquityDebtInFrontTrigger, makerRatioTrigger, morphoAaveV2RatioTrigger, sparkRatioTrigger, trailingStopTrigger, liquityDebtInFrontWithLimitTrigger, crvUSDRatioTrigger, morphoBlueRatioTrigger, crvUsdHealthRatioTrigger, liquityV2DebtInFrontTrigger, liquityV2AdjustTimeTrigger, compoundV3PriceRangeTrigger, aaveV3QuotePriceRangeTrigger, morphoBluePriceRangeTrigger, sparkQuotePriceTrigger, aaveV4RatioTrigger, aaveV4QuotePriceTrigger, aaveV4QuotePriceRangeTrigger, } from './triggerService';
|
|
6
|
+
import { aaveV2RatioTrigger, aaveV3QuotePriceTrigger, aaveV3QuotePriceWithMaximumGasPriceTrigger, aaveV3RatioTrigger, cBondsRebondTrigger, chainlinkPriceTrigger, compoundV2RatioTrigger, compoundV3RatioTrigger, compoundV3PriceTrigger, curveUsdBorrowRateTrigger, curveUsdSoftLiquidationTrigger, exchangeOffchainPriceTrigger, exchangeTimestampTrigger, liquityDebtInFrontTrigger, makerRatioTrigger, morphoAaveV2RatioTrigger, sparkRatioTrigger, trailingStopTrigger, liquityDebtInFrontWithLimitTrigger, crvUSDRatioTrigger, morphoBlueRatioTrigger, crvUsdHealthRatioTrigger, liquityV2DebtInFrontTrigger, liquityV2AdjustTimeTrigger, compoundV3PriceRangeTrigger, aaveV3QuotePriceRangeTrigger, morphoBluePriceRangeTrigger, morphoBluePriceTrigger, sparkQuotePriceTrigger, aaveV4RatioTrigger, aaveV4QuotePriceTrigger, aaveV4QuotePriceRangeTrigger, } from './triggerService';
|
|
7
7
|
describe('Feature: triggerService.ts', () => {
|
|
8
8
|
describe('When testing triggerService.chainlinkPriceTrigger', () => {
|
|
9
9
|
describe('encode()', () => {
|
|
@@ -1159,6 +1159,66 @@ describe('Feature: triggerService.ts', () => {
|
|
|
1159
1159
|
});
|
|
1160
1160
|
});
|
|
1161
1161
|
});
|
|
1162
|
+
describe('When testing triggerService.morphoBluePriceTrigger', () => {
|
|
1163
|
+
describe('encode()', () => {
|
|
1164
|
+
const examples = [
|
|
1165
|
+
[
|
|
1166
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1167
|
+
[
|
|
1168
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1169
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1170
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1171
|
+
2500,
|
|
1172
|
+
RatioState.UNDER,
|
|
1173
|
+
],
|
|
1174
|
+
],
|
|
1175
|
+
[
|
|
1176
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000005d21dba0000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1177
|
+
[
|
|
1178
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1179
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1180
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1181
|
+
4000,
|
|
1182
|
+
RatioState.OVER,
|
|
1183
|
+
],
|
|
1184
|
+
],
|
|
1185
|
+
];
|
|
1186
|
+
examples.forEach(([expected, actual]) => {
|
|
1187
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1188
|
+
expect(morphoBluePriceTrigger.encode(...actual)).to.eql(expected);
|
|
1189
|
+
});
|
|
1190
|
+
});
|
|
1191
|
+
});
|
|
1192
|
+
describe('decode()', () => {
|
|
1193
|
+
const examples = [
|
|
1194
|
+
[
|
|
1195
|
+
{
|
|
1196
|
+
oracle: web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1197
|
+
collateralToken: web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1198
|
+
loanToken: web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1199
|
+
price: '2500',
|
|
1200
|
+
priceState: RatioState.UNDER,
|
|
1201
|
+
},
|
|
1202
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1203
|
+
],
|
|
1204
|
+
[
|
|
1205
|
+
{
|
|
1206
|
+
oracle: web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1207
|
+
collateralToken: web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1208
|
+
loanToken: web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1209
|
+
price: '4000',
|
|
1210
|
+
priceState: RatioState.OVER,
|
|
1211
|
+
},
|
|
1212
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000005d21dba0000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1213
|
+
],
|
|
1214
|
+
];
|
|
1215
|
+
examples.forEach(([expected, actual]) => {
|
|
1216
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1217
|
+
expect(morphoBluePriceTrigger.decode(actual)).to.eql(expected);
|
|
1218
|
+
});
|
|
1219
|
+
});
|
|
1220
|
+
});
|
|
1221
|
+
});
|
|
1162
1222
|
describe('When testing triggerService.aaveV4RatioTrigger', () => {
|
|
1163
1223
|
describe('encode()', () => {
|
|
1164
1224
|
const examples = [
|