@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/esm/types/enums.d.ts
CHANGED
|
@@ -224,7 +224,11 @@ export declare namespace Bundles {
|
|
|
224
224
|
AAVE_V4_EOA_BOOST = 67,
|
|
225
225
|
AAVE_V4_EOA_REPAY_ON_PRICE = 68,
|
|
226
226
|
AAVE_V4_EOA_BOOST_ON_PRICE = 69,
|
|
227
|
-
AAVE_V4_EOA_CLOSE = 70
|
|
227
|
+
AAVE_V4_EOA_CLOSE = 70,
|
|
228
|
+
MORPHO_BLUE_REPAY_ON_PRICE = 84,
|
|
229
|
+
MORPHO_BLUE_EOA_BOOST_ON_PRICE = 85,
|
|
230
|
+
MORPHO_BLUE_EOA_REPAY_ON_PRICE = 86,
|
|
231
|
+
MORPHO_BLUE_EOA_CLOSE = 87
|
|
228
232
|
}
|
|
229
233
|
enum OptimismIds {
|
|
230
234
|
AAVE_V3_REPAY = 0,
|
|
@@ -266,7 +270,13 @@ export declare namespace Bundles {
|
|
|
266
270
|
AAVE_V3_EOA_REPAY_ON_PRICE = 25,
|
|
267
271
|
AAVE_V3_EOA_BOOST_ON_PRICE = 26,
|
|
268
272
|
AAVE_V3_EOA_CLOSE = 27,
|
|
269
|
-
MORPHO_BLUE_CLOSE = 28
|
|
273
|
+
MORPHO_BLUE_CLOSE = 28,
|
|
274
|
+
MORPHO_BLUE_REPAY_ON_PRICE = 36,
|
|
275
|
+
MORPHO_BLUE_EOA_REPAY = 37,
|
|
276
|
+
MORPHO_BLUE_EOA_BOOST = 38,
|
|
277
|
+
MORPHO_BLUE_EOA_BOOST_ON_PRICE = 39,
|
|
278
|
+
MORPHO_BLUE_EOA_REPAY_ON_PRICE = 40,
|
|
279
|
+
MORPHO_BLUE_EOA_CLOSE = 41
|
|
270
280
|
}
|
|
271
281
|
enum ArbitrumIds {
|
|
272
282
|
AAVE_V3_REPAY = 0,
|
|
@@ -297,6 +307,10 @@ export declare namespace Bundles {
|
|
|
297
307
|
MORPHO_BLUE_BOOST_ON_PRICE = 25,
|
|
298
308
|
MORPHO_BLUE_EOA_REPAY = 26,
|
|
299
309
|
MORPHO_BLUE_EOA_BOOST = 27,
|
|
300
|
-
MORPHO_BLUE_CLOSE = 28
|
|
310
|
+
MORPHO_BLUE_CLOSE = 28,
|
|
311
|
+
MORPHO_BLUE_REPAY_ON_PRICE = 36,
|
|
312
|
+
MORPHO_BLUE_EOA_BOOST_ON_PRICE = 37,
|
|
313
|
+
MORPHO_BLUE_EOA_REPAY_ON_PRICE = 38,
|
|
314
|
+
MORPHO_BLUE_EOA_CLOSE = 39
|
|
301
315
|
}
|
|
302
316
|
}
|
package/esm/types/enums.js
CHANGED
|
@@ -245,6 +245,10 @@ export var Bundles;
|
|
|
245
245
|
MainnetIds[MainnetIds["AAVE_V4_EOA_REPAY_ON_PRICE"] = 68] = "AAVE_V4_EOA_REPAY_ON_PRICE";
|
|
246
246
|
MainnetIds[MainnetIds["AAVE_V4_EOA_BOOST_ON_PRICE"] = 69] = "AAVE_V4_EOA_BOOST_ON_PRICE";
|
|
247
247
|
MainnetIds[MainnetIds["AAVE_V4_EOA_CLOSE"] = 70] = "AAVE_V4_EOA_CLOSE";
|
|
248
|
+
MainnetIds[MainnetIds["MORPHO_BLUE_REPAY_ON_PRICE"] = 84] = "MORPHO_BLUE_REPAY_ON_PRICE";
|
|
249
|
+
MainnetIds[MainnetIds["MORPHO_BLUE_EOA_BOOST_ON_PRICE"] = 85] = "MORPHO_BLUE_EOA_BOOST_ON_PRICE";
|
|
250
|
+
MainnetIds[MainnetIds["MORPHO_BLUE_EOA_REPAY_ON_PRICE"] = 86] = "MORPHO_BLUE_EOA_REPAY_ON_PRICE";
|
|
251
|
+
MainnetIds[MainnetIds["MORPHO_BLUE_EOA_CLOSE"] = 87] = "MORPHO_BLUE_EOA_CLOSE";
|
|
248
252
|
})(MainnetIds = Bundles.MainnetIds || (Bundles.MainnetIds = {}));
|
|
249
253
|
let OptimismIds;
|
|
250
254
|
(function (OptimismIds) {
|
|
@@ -289,6 +293,12 @@ export var Bundles;
|
|
|
289
293
|
BaseIds[BaseIds["AAVE_V3_EOA_BOOST_ON_PRICE"] = 26] = "AAVE_V3_EOA_BOOST_ON_PRICE";
|
|
290
294
|
BaseIds[BaseIds["AAVE_V3_EOA_CLOSE"] = 27] = "AAVE_V3_EOA_CLOSE";
|
|
291
295
|
BaseIds[BaseIds["MORPHO_BLUE_CLOSE"] = 28] = "MORPHO_BLUE_CLOSE";
|
|
296
|
+
BaseIds[BaseIds["MORPHO_BLUE_REPAY_ON_PRICE"] = 36] = "MORPHO_BLUE_REPAY_ON_PRICE";
|
|
297
|
+
BaseIds[BaseIds["MORPHO_BLUE_EOA_REPAY"] = 37] = "MORPHO_BLUE_EOA_REPAY";
|
|
298
|
+
BaseIds[BaseIds["MORPHO_BLUE_EOA_BOOST"] = 38] = "MORPHO_BLUE_EOA_BOOST";
|
|
299
|
+
BaseIds[BaseIds["MORPHO_BLUE_EOA_BOOST_ON_PRICE"] = 39] = "MORPHO_BLUE_EOA_BOOST_ON_PRICE";
|
|
300
|
+
BaseIds[BaseIds["MORPHO_BLUE_EOA_REPAY_ON_PRICE"] = 40] = "MORPHO_BLUE_EOA_REPAY_ON_PRICE";
|
|
301
|
+
BaseIds[BaseIds["MORPHO_BLUE_EOA_CLOSE"] = 41] = "MORPHO_BLUE_EOA_CLOSE";
|
|
292
302
|
})(BaseIds = Bundles.BaseIds || (Bundles.BaseIds = {}));
|
|
293
303
|
let ArbitrumIds;
|
|
294
304
|
(function (ArbitrumIds) {
|
|
@@ -321,5 +331,9 @@ export var Bundles;
|
|
|
321
331
|
ArbitrumIds[ArbitrumIds["MORPHO_BLUE_EOA_REPAY"] = 26] = "MORPHO_BLUE_EOA_REPAY";
|
|
322
332
|
ArbitrumIds[ArbitrumIds["MORPHO_BLUE_EOA_BOOST"] = 27] = "MORPHO_BLUE_EOA_BOOST";
|
|
323
333
|
ArbitrumIds[ArbitrumIds["MORPHO_BLUE_CLOSE"] = 28] = "MORPHO_BLUE_CLOSE";
|
|
334
|
+
ArbitrumIds[ArbitrumIds["MORPHO_BLUE_REPAY_ON_PRICE"] = 36] = "MORPHO_BLUE_REPAY_ON_PRICE";
|
|
335
|
+
ArbitrumIds[ArbitrumIds["MORPHO_BLUE_EOA_BOOST_ON_PRICE"] = 37] = "MORPHO_BLUE_EOA_BOOST_ON_PRICE";
|
|
336
|
+
ArbitrumIds[ArbitrumIds["MORPHO_BLUE_EOA_REPAY_ON_PRICE"] = 38] = "MORPHO_BLUE_EOA_REPAY_ON_PRICE";
|
|
337
|
+
ArbitrumIds[ArbitrumIds["MORPHO_BLUE_EOA_CLOSE"] = 39] = "MORPHO_BLUE_EOA_CLOSE";
|
|
324
338
|
})(ArbitrumIds = Bundles.ArbitrumIds || (Bundles.ArbitrumIds = {}));
|
|
325
339
|
})(Bundles || (Bundles = {}));
|
package/package.json
CHANGED
package/src/constants/index.ts
CHANGED
|
@@ -573,6 +573,26 @@ export const MAINNET_BUNDLES_INFO: MainnetBundleInfo = {
|
|
|
573
573
|
strategyId: Strategies.Identifiers.EoaCloseOnPrice,
|
|
574
574
|
protocol: PROTOCOLS.AaveV4,
|
|
575
575
|
},
|
|
576
|
+
[Bundles.MainnetIds.MORPHO_BLUE_REPAY_ON_PRICE]: {
|
|
577
|
+
strategyOrBundleId: Bundles.MainnetIds.MORPHO_BLUE_REPAY_ON_PRICE,
|
|
578
|
+
strategyId: Strategies.Identifiers.RepayOnPrice,
|
|
579
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
580
|
+
},
|
|
581
|
+
[Bundles.MainnetIds.MORPHO_BLUE_EOA_BOOST_ON_PRICE]: {
|
|
582
|
+
strategyOrBundleId: Bundles.MainnetIds.MORPHO_BLUE_EOA_BOOST_ON_PRICE,
|
|
583
|
+
strategyId: Strategies.Identifiers.EoaBoostOnPrice,
|
|
584
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
585
|
+
},
|
|
586
|
+
[Bundles.MainnetIds.MORPHO_BLUE_EOA_REPAY_ON_PRICE]: {
|
|
587
|
+
strategyOrBundleId: Bundles.MainnetIds.MORPHO_BLUE_EOA_REPAY_ON_PRICE,
|
|
588
|
+
strategyId: Strategies.Identifiers.EoaRepayOnPrice,
|
|
589
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
590
|
+
},
|
|
591
|
+
[Bundles.MainnetIds.MORPHO_BLUE_EOA_CLOSE]: {
|
|
592
|
+
strategyOrBundleId: Bundles.MainnetIds.MORPHO_BLUE_EOA_CLOSE,
|
|
593
|
+
strategyId: Strategies.Identifiers.EoaCloseOnPrice,
|
|
594
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
595
|
+
},
|
|
576
596
|
};
|
|
577
597
|
|
|
578
598
|
export const OPTIMISM_BUNDLES_INFO: OptimismBundleInfo = {
|
|
@@ -770,6 +790,36 @@ export const BASE_BUNDLES_INFO: BaseBundleInfo = {
|
|
|
770
790
|
strategyId: Strategies.Identifiers.CloseOnPrice,
|
|
771
791
|
protocol: PROTOCOLS.MorphoBlue,
|
|
772
792
|
},
|
|
793
|
+
[Bundles.BaseIds.MORPHO_BLUE_REPAY_ON_PRICE]: {
|
|
794
|
+
strategyOrBundleId: Bundles.BaseIds.MORPHO_BLUE_REPAY_ON_PRICE,
|
|
795
|
+
strategyId: Strategies.Identifiers.RepayOnPrice,
|
|
796
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
797
|
+
},
|
|
798
|
+
[Bundles.BaseIds.MORPHO_BLUE_EOA_REPAY]: {
|
|
799
|
+
strategyOrBundleId: Bundles.BaseIds.MORPHO_BLUE_EOA_REPAY,
|
|
800
|
+
strategyId: Strategies.Identifiers.EoaRepay,
|
|
801
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
802
|
+
},
|
|
803
|
+
[Bundles.BaseIds.MORPHO_BLUE_EOA_BOOST]: {
|
|
804
|
+
strategyOrBundleId: Bundles.BaseIds.MORPHO_BLUE_EOA_BOOST,
|
|
805
|
+
strategyId: Strategies.Identifiers.EoaBoost,
|
|
806
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
807
|
+
},
|
|
808
|
+
[Bundles.BaseIds.MORPHO_BLUE_EOA_BOOST_ON_PRICE]: {
|
|
809
|
+
strategyOrBundleId: Bundles.BaseIds.MORPHO_BLUE_EOA_BOOST_ON_PRICE,
|
|
810
|
+
strategyId: Strategies.Identifiers.EoaBoostOnPrice,
|
|
811
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
812
|
+
},
|
|
813
|
+
[Bundles.BaseIds.MORPHO_BLUE_EOA_REPAY_ON_PRICE]: {
|
|
814
|
+
strategyOrBundleId: Bundles.BaseIds.MORPHO_BLUE_EOA_REPAY_ON_PRICE,
|
|
815
|
+
strategyId: Strategies.Identifiers.EoaRepayOnPrice,
|
|
816
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
817
|
+
},
|
|
818
|
+
[Bundles.BaseIds.MORPHO_BLUE_EOA_CLOSE]: {
|
|
819
|
+
strategyOrBundleId: Bundles.BaseIds.MORPHO_BLUE_EOA_CLOSE,
|
|
820
|
+
strategyId: Strategies.Identifiers.EoaCloseOnPrice,
|
|
821
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
822
|
+
},
|
|
773
823
|
};
|
|
774
824
|
|
|
775
825
|
export const ARBITRUM_BUNDLES_INFO: ArbitrumBundleInfo = {
|
|
@@ -918,6 +968,26 @@ export const ARBITRUM_BUNDLES_INFO: ArbitrumBundleInfo = {
|
|
|
918
968
|
strategyId: Strategies.Identifiers.CloseOnPrice,
|
|
919
969
|
protocol: PROTOCOLS.MorphoBlue,
|
|
920
970
|
},
|
|
971
|
+
[Bundles.ArbitrumIds.MORPHO_BLUE_REPAY_ON_PRICE]: {
|
|
972
|
+
strategyOrBundleId: Bundles.ArbitrumIds.MORPHO_BLUE_REPAY_ON_PRICE,
|
|
973
|
+
strategyId: Strategies.Identifiers.RepayOnPrice,
|
|
974
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
975
|
+
},
|
|
976
|
+
[Bundles.ArbitrumIds.MORPHO_BLUE_EOA_BOOST_ON_PRICE]: {
|
|
977
|
+
strategyOrBundleId: Bundles.ArbitrumIds.MORPHO_BLUE_EOA_BOOST_ON_PRICE,
|
|
978
|
+
strategyId: Strategies.Identifiers.EoaBoostOnPrice,
|
|
979
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
980
|
+
},
|
|
981
|
+
[Bundles.ArbitrumIds.MORPHO_BLUE_EOA_REPAY_ON_PRICE]: {
|
|
982
|
+
strategyOrBundleId: Bundles.ArbitrumIds.MORPHO_BLUE_EOA_REPAY_ON_PRICE,
|
|
983
|
+
strategyId: Strategies.Identifiers.EoaRepayOnPrice,
|
|
984
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
985
|
+
},
|
|
986
|
+
[Bundles.ArbitrumIds.MORPHO_BLUE_EOA_CLOSE]: {
|
|
987
|
+
strategyOrBundleId: Bundles.ArbitrumIds.MORPHO_BLUE_EOA_CLOSE,
|
|
988
|
+
strategyId: Strategies.Identifiers.EoaCloseOnPrice,
|
|
989
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
990
|
+
},
|
|
921
991
|
};
|
|
922
992
|
|
|
923
993
|
export const BUNDLES_INFO: BundlesInfo = {
|
|
@@ -1423,7 +1423,11 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
|
|
|
1423
1423
|
[Strategies.Identifiers.EoaRepay]: parseMorphoBlueLeverageManagement,
|
|
1424
1424
|
[Strategies.Identifiers.EoaBoost]: parseMorphoBlueLeverageManagement,
|
|
1425
1425
|
[Strategies.Identifiers.BoostOnPrice]: parseMorphoBlueLeverageManagementOnPrice,
|
|
1426
|
+
[Strategies.Identifiers.RepayOnPrice]: parseMorphoBlueLeverageManagementOnPrice,
|
|
1427
|
+
[Strategies.Identifiers.EoaBoostOnPrice]: parseMorphoBlueLeverageManagementOnPrice,
|
|
1428
|
+
[Strategies.Identifiers.EoaRepayOnPrice]: parseMorphoBlueLeverageManagementOnPrice,
|
|
1426
1429
|
[Strategies.Identifiers.CloseOnPrice]: parseMorphoBlueCloseOnPrice,
|
|
1430
|
+
[Strategies.Identifiers.EoaCloseOnPrice]: parseMorphoBlueCloseOnPrice,
|
|
1427
1431
|
},
|
|
1428
1432
|
[ProtocolIdentifiers.StrategiesAutomation.FluidT1]: {
|
|
1429
1433
|
[Strategies.Identifiers.Repay]: parseFluidT1LeverageManagement,
|
|
@@ -1417,6 +1417,177 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1417
1417
|
});
|
|
1418
1418
|
});
|
|
1419
1419
|
|
|
1420
|
+
describe('leverageManagementOnPrice()', () => {
|
|
1421
|
+
const examples: Array<[
|
|
1422
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1423
|
+
[
|
|
1424
|
+
strategyOrBundleId: number,
|
|
1425
|
+
isBundle: boolean,
|
|
1426
|
+
loanToken: EthereumAddress,
|
|
1427
|
+
collToken: EthereumAddress,
|
|
1428
|
+
oracle: EthereumAddress,
|
|
1429
|
+
irm: EthereumAddress,
|
|
1430
|
+
lltv: string,
|
|
1431
|
+
user: EthereumAddress,
|
|
1432
|
+
targetRatio: number,
|
|
1433
|
+
price: number,
|
|
1434
|
+
priceState: RatioState,
|
|
1435
|
+
]
|
|
1436
|
+
]> = [
|
|
1437
|
+
[
|
|
1438
|
+
[
|
|
1439
|
+
Bundles.MainnetIds.MORPHO_BLUE_REPAY_ON_PRICE,
|
|
1440
|
+
true,
|
|
1441
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1442
|
+
[
|
|
1443
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1444
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1445
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1446
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1447
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1448
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
1449
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1450
|
+
],
|
|
1451
|
+
],
|
|
1452
|
+
[
|
|
1453
|
+
Bundles.MainnetIds.MORPHO_BLUE_REPAY_ON_PRICE,
|
|
1454
|
+
true,
|
|
1455
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1456
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1457
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1458
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1459
|
+
'945000000000000000',
|
|
1460
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1461
|
+
200,
|
|
1462
|
+
2500,
|
|
1463
|
+
RatioState.UNDER,
|
|
1464
|
+
],
|
|
1465
|
+
],
|
|
1466
|
+
[
|
|
1467
|
+
[
|
|
1468
|
+
Bundles.MainnetIds.MORPHO_BLUE_BOOST_ON_PRICE,
|
|
1469
|
+
true,
|
|
1470
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000005d21dba0000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1471
|
+
[
|
|
1472
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1473
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1474
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1475
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1476
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1477
|
+
'0x00000000000000000000000000000000000000000000000016345785d8a00000',
|
|
1478
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1479
|
+
],
|
|
1480
|
+
],
|
|
1481
|
+
[
|
|
1482
|
+
Bundles.MainnetIds.MORPHO_BLUE_BOOST_ON_PRICE,
|
|
1483
|
+
true,
|
|
1484
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1485
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1486
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1487
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1488
|
+
'945000000000000000',
|
|
1489
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1490
|
+
160,
|
|
1491
|
+
4000,
|
|
1492
|
+
RatioState.OVER,
|
|
1493
|
+
],
|
|
1494
|
+
],
|
|
1495
|
+
];
|
|
1496
|
+
|
|
1497
|
+
examples.forEach(([expected, actual]) => {
|
|
1498
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1499
|
+
expect(morphoBlueEncode.leverageManagementOnPrice(...actual)).to.eql(expected);
|
|
1500
|
+
});
|
|
1501
|
+
});
|
|
1502
|
+
});
|
|
1503
|
+
|
|
1504
|
+
describe('leverageManagementOnPriceGeneric()', () => {
|
|
1505
|
+
const examples: Array<[
|
|
1506
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1507
|
+
[
|
|
1508
|
+
loanToken: EthereumAddress,
|
|
1509
|
+
collToken: EthereumAddress,
|
|
1510
|
+
oracle: EthereumAddress,
|
|
1511
|
+
irm: EthereumAddress,
|
|
1512
|
+
lltv: string,
|
|
1513
|
+
user: EthereumAddress,
|
|
1514
|
+
targetRatio: number,
|
|
1515
|
+
price: number,
|
|
1516
|
+
priceState: RatioState,
|
|
1517
|
+
isBoost: boolean,
|
|
1518
|
+
isEOA: boolean,
|
|
1519
|
+
network: ChainId,
|
|
1520
|
+
]
|
|
1521
|
+
]> = [
|
|
1522
|
+
[
|
|
1523
|
+
[
|
|
1524
|
+
Bundles.MainnetIds.MORPHO_BLUE_REPAY_ON_PRICE,
|
|
1525
|
+
true,
|
|
1526
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1527
|
+
[
|
|
1528
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1529
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1530
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1531
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1532
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1533
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
1534
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1535
|
+
],
|
|
1536
|
+
],
|
|
1537
|
+
[
|
|
1538
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1539
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1540
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1541
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1542
|
+
'945000000000000000',
|
|
1543
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1544
|
+
200,
|
|
1545
|
+
2500,
|
|
1546
|
+
RatioState.UNDER,
|
|
1547
|
+
false,
|
|
1548
|
+
false,
|
|
1549
|
+
ChainId.Ethereum,
|
|
1550
|
+
],
|
|
1551
|
+
],
|
|
1552
|
+
[
|
|
1553
|
+
[
|
|
1554
|
+
Bundles.MainnetIds.MORPHO_BLUE_BOOST_ON_PRICE,
|
|
1555
|
+
true,
|
|
1556
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000005d21dba0000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1557
|
+
[
|
|
1558
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1559
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1560
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1561
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1562
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1563
|
+
'0x00000000000000000000000000000000000000000000000016345785d8a00000',
|
|
1564
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1565
|
+
],
|
|
1566
|
+
],
|
|
1567
|
+
[
|
|
1568
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1569
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1570
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1571
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1572
|
+
'945000000000000000',
|
|
1573
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1574
|
+
160,
|
|
1575
|
+
4000,
|
|
1576
|
+
RatioState.OVER,
|
|
1577
|
+
true,
|
|
1578
|
+
false,
|
|
1579
|
+
ChainId.Ethereum,
|
|
1580
|
+
],
|
|
1581
|
+
],
|
|
1582
|
+
];
|
|
1583
|
+
|
|
1584
|
+
examples.forEach(([expected, actual]) => {
|
|
1585
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1586
|
+
expect(morphoBlueEncode.leverageManagementOnPriceGeneric(...actual)).to.eql(expected);
|
|
1587
|
+
});
|
|
1588
|
+
});
|
|
1589
|
+
});
|
|
1590
|
+
|
|
1420
1591
|
describe('closeOnPrice()', () => {
|
|
1421
1592
|
const examples: Array<[
|
|
1422
1593
|
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
@@ -1460,7 +1631,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1460
1631
|
1500,
|
|
1461
1632
|
CloseToAssetType.DEBT,
|
|
1462
1633
|
4000,
|
|
1463
|
-
CloseToAssetType.COLLATERAL
|
|
1634
|
+
CloseToAssetType.COLLATERAL,
|
|
1464
1635
|
]
|
|
1465
1636
|
],
|
|
1466
1637
|
];
|
|
@@ -1471,6 +1642,63 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1471
1642
|
});
|
|
1472
1643
|
});
|
|
1473
1644
|
});
|
|
1645
|
+
|
|
1646
|
+
describe('closeOnPriceGeneric()', () => {
|
|
1647
|
+
const examples: Array<[
|
|
1648
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1649
|
+
[
|
|
1650
|
+
loanToken: EthereumAddress,
|
|
1651
|
+
collToken: EthereumAddress,
|
|
1652
|
+
oracle: EthereumAddress,
|
|
1653
|
+
irm: EthereumAddress,
|
|
1654
|
+
lltv: string,
|
|
1655
|
+
user: EthereumAddress,
|
|
1656
|
+
stopLossPrice: number,
|
|
1657
|
+
stopLossType: CloseToAssetType,
|
|
1658
|
+
takeProfitPrice: number,
|
|
1659
|
+
takeProfitType: CloseToAssetType,
|
|
1660
|
+
isEOA: boolean,
|
|
1661
|
+
network: ChainId,
|
|
1662
|
+
]
|
|
1663
|
+
]> = [
|
|
1664
|
+
[
|
|
1665
|
+
[
|
|
1666
|
+
Bundles.MainnetIds.MORPHO_BLUE_CLOSE,
|
|
1667
|
+
true,
|
|
1668
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
1669
|
+
[
|
|
1670
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1671
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1672
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1673
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1674
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1675
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1676
|
+
'0x0000000000000000000000000000000000000000000000000000000000000005',
|
|
1677
|
+
],
|
|
1678
|
+
],
|
|
1679
|
+
[
|
|
1680
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1681
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1682
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1683
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1684
|
+
'945000000000000000',
|
|
1685
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1686
|
+
1500,
|
|
1687
|
+
CloseToAssetType.DEBT,
|
|
1688
|
+
4000,
|
|
1689
|
+
CloseToAssetType.COLLATERAL,
|
|
1690
|
+
false,
|
|
1691
|
+
ChainId.Ethereum,
|
|
1692
|
+
]
|
|
1693
|
+
],
|
|
1694
|
+
];
|
|
1695
|
+
|
|
1696
|
+
examples.forEach(([expected, actual]) => {
|
|
1697
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1698
|
+
expect(morphoBlueEncode.closeOnPriceGeneric(...actual)).to.eql(expected);
|
|
1699
|
+
});
|
|
1700
|
+
});
|
|
1701
|
+
});
|
|
1474
1702
|
});
|
|
1475
1703
|
|
|
1476
1704
|
describe('When testing strategySubService.sparkEncode', () => {
|
|
@@ -652,6 +652,44 @@ export const crvUSDEncode = {
|
|
|
652
652
|
},
|
|
653
653
|
};
|
|
654
654
|
|
|
655
|
+
export type MorphoBlueBundleStrategy = 'repay' | 'boost' | 'repayOnPrice' | 'boostOnPrice' | 'close';
|
|
656
|
+
|
|
657
|
+
function getMorphoBlueBundlesIds(network: ChainId) {
|
|
658
|
+
switch (network) {
|
|
659
|
+
case ChainId.Ethereum:
|
|
660
|
+
return Bundles.MainnetIds;
|
|
661
|
+
case ChainId.Base:
|
|
662
|
+
return Bundles.BaseIds;
|
|
663
|
+
case ChainId.Arbitrum:
|
|
664
|
+
return Bundles.ArbitrumIds;
|
|
665
|
+
default:
|
|
666
|
+
throw new Error(`Morpho Blue strategies are not supported on chain ${network}`);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
export function getMorphoBlueBundleId(
|
|
671
|
+
network: ChainId,
|
|
672
|
+
strategy: MorphoBlueBundleStrategy,
|
|
673
|
+
isEOA: boolean,
|
|
674
|
+
): number {
|
|
675
|
+
const bundlesIds = getMorphoBlueBundlesIds(network);
|
|
676
|
+
|
|
677
|
+
switch (strategy) {
|
|
678
|
+
case 'repay':
|
|
679
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_REPAY : bundlesIds.MORPHO_BLUE_REPAY;
|
|
680
|
+
case 'boost':
|
|
681
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_BOOST : bundlesIds.MORPHO_BLUE_BOOST;
|
|
682
|
+
case 'repayOnPrice':
|
|
683
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_REPAY_ON_PRICE : bundlesIds.MORPHO_BLUE_REPAY_ON_PRICE;
|
|
684
|
+
case 'boostOnPrice':
|
|
685
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_BOOST_ON_PRICE : bundlesIds.MORPHO_BLUE_BOOST_ON_PRICE;
|
|
686
|
+
case 'close':
|
|
687
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_CLOSE : bundlesIds.MORPHO_BLUE_CLOSE;
|
|
688
|
+
default:
|
|
689
|
+
throw new Error(`Unknown Morpho Blue strategy: ${strategy}`);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
|
|
655
693
|
export const morphoBlueEncode = {
|
|
656
694
|
leverageManagement(
|
|
657
695
|
marketId: string,
|
|
@@ -673,19 +711,10 @@ export const morphoBlueEncode = {
|
|
|
673
711
|
|
|
674
712
|
// over is boost, under is repay
|
|
675
713
|
const isBoost = ratioState === RatioState.OVER;
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
if (network === ChainId.Base) {
|
|
679
|
-
return [isBoost ? Bundles.BaseIds.MORPHO_BLUE_BOOST : Bundles.BaseIds.MORPHO_BLUE_REPAY, true, triggerData, subData];
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
const bundlesIds = network === ChainId.Arbitrum ? Bundles.ArbitrumIds : Bundles.MainnetIds;
|
|
683
|
-
|
|
684
|
-
if (isBoost) strategyOrBundleId = isEOA ? bundlesIds.MORPHO_BLUE_EOA_BOOST : bundlesIds.MORPHO_BLUE_BOOST;
|
|
685
|
-
else strategyOrBundleId = isEOA ? bundlesIds.MORPHO_BLUE_EOA_REPAY : bundlesIds.MORPHO_BLUE_REPAY;
|
|
714
|
+
const bundleId = getMorphoBlueBundleId(network, isBoost ? 'boost' : 'repay', isEOA);
|
|
686
715
|
const isBundle = true;
|
|
687
716
|
|
|
688
|
-
return [
|
|
717
|
+
return [bundleId, isBundle, triggerData, subData];
|
|
689
718
|
},
|
|
690
719
|
leverageManagementOnPrice(
|
|
691
720
|
strategyOrBundleId: number,
|
|
@@ -704,6 +733,28 @@ export const morphoBlueEncode = {
|
|
|
704
733
|
const triggerData = triggerService.morphoBluePriceTrigger.encode(oracle, collToken, loanToken, price, priceState);
|
|
705
734
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
706
735
|
},
|
|
736
|
+
leverageManagementOnPriceGeneric(
|
|
737
|
+
loanToken: EthereumAddress,
|
|
738
|
+
collToken: EthereumAddress,
|
|
739
|
+
oracle: EthereumAddress,
|
|
740
|
+
irm: EthereumAddress,
|
|
741
|
+
lltv: string,
|
|
742
|
+
user: EthereumAddress,
|
|
743
|
+
targetRatio: number,
|
|
744
|
+
price: number,
|
|
745
|
+
priceState: RatioState,
|
|
746
|
+
isBoost: boolean,
|
|
747
|
+
isEOA: boolean,
|
|
748
|
+
network: ChainId,
|
|
749
|
+
) {
|
|
750
|
+
const subData = subDataService.morphoBlueLeverageManagementOnPriceSubData.encode(loanToken, collToken, oracle, irm, lltv, targetRatio, user);
|
|
751
|
+
const triggerData = triggerService.morphoBluePriceTrigger.encode(oracle, collToken, loanToken, price, priceState);
|
|
752
|
+
|
|
753
|
+
const bundleId = getMorphoBlueBundleId(network, isBoost ? 'boostOnPrice' : 'repayOnPrice', isEOA);
|
|
754
|
+
const isBundle = true;
|
|
755
|
+
|
|
756
|
+
return [bundleId, isBundle, triggerData, subData];
|
|
757
|
+
},
|
|
707
758
|
closeOnPrice(
|
|
708
759
|
strategyOrBundleId: number,
|
|
709
760
|
loanToken: EthereumAddress,
|
|
@@ -725,6 +776,30 @@ export const morphoBlueEncode = {
|
|
|
725
776
|
|
|
726
777
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
727
778
|
},
|
|
779
|
+
closeOnPriceGeneric(
|
|
780
|
+
loanToken: EthereumAddress,
|
|
781
|
+
collToken: EthereumAddress,
|
|
782
|
+
oracle: EthereumAddress,
|
|
783
|
+
irm: EthereumAddress,
|
|
784
|
+
lltv: string,
|
|
785
|
+
user: EthereumAddress,
|
|
786
|
+
stopLossPrice: number = 0,
|
|
787
|
+
stopLossType: CloseToAssetType = CloseToAssetType.DEBT,
|
|
788
|
+
takeProfitPrice: number = 0,
|
|
789
|
+
takeProfitType: CloseToAssetType = CloseToAssetType.COLLATERAL,
|
|
790
|
+
isEOA: boolean,
|
|
791
|
+
network: ChainId,
|
|
792
|
+
) {
|
|
793
|
+
const isBundle = true;
|
|
794
|
+
const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
795
|
+
|
|
796
|
+
const subDataEncoded = subDataService.morphoBlueCloseOnPriceSubData.encode(loanToken, collToken, oracle, irm, lltv, user, closeType);
|
|
797
|
+
const triggerDataEncoded = triggerService.morphoBluePriceRangeTrigger.encode(oracle, collToken, loanToken, stopLossPrice, takeProfitPrice);
|
|
798
|
+
|
|
799
|
+
const bundleId = getMorphoBlueBundleId(network, 'close', isEOA);
|
|
800
|
+
|
|
801
|
+
return [bundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
802
|
+
},
|
|
728
803
|
};
|
|
729
804
|
|
|
730
805
|
export const liquityV2Encode = {
|