@defisaver/automation-sdk 3.2.3 → 3.2.4-dev-1
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 +90 -0
- package/cjs/services/strategiesService.js +48 -1
- package/cjs/services/strategySubService.d.ts +2 -0
- package/cjs/services/strategySubService.js +13 -0
- package/cjs/services/strategySubService.test.js +108 -0
- package/cjs/services/subDataService.d.ts +18 -0
- package/cjs/services/subDataService.js +48 -1
- package/cjs/services/subDataService.test.js +124 -48
- package/cjs/services/triggerService.d.ts +33 -0
- package/cjs/services/triggerService.js +62 -1
- package/cjs/services/triggerService.test.js +211 -0
- package/cjs/types/enums.d.ts +28 -5
- package/cjs/types/enums.js +23 -0
- package/cjs/types/index.d.ts +17 -1
- package/esm/constants/index.js +90 -0
- package/esm/services/strategiesService.js +48 -1
- package/esm/services/strategySubService.d.ts +2 -0
- package/esm/services/strategySubService.js +13 -0
- package/esm/services/strategySubService.test.js +109 -1
- package/esm/services/subDataService.d.ts +18 -0
- package/esm/services/subDataService.js +47 -0
- package/esm/services/subDataService.test.js +124 -48
- package/esm/services/triggerService.d.ts +33 -0
- package/esm/services/triggerService.js +61 -0
- package/esm/services/triggerService.test.js +212 -1
- package/esm/types/enums.d.ts +28 -5
- package/esm/types/enums.js +23 -0
- package/esm/types/index.d.ts +17 -1
- package/package.json +2 -2
- package/src/constants/index.ts +90 -1
- package/src/services/strategiesService.ts +62 -1
- package/src/services/strategySubService.test.ts +115 -1
- package/src/services/strategySubService.ts +33 -0
- package/src/services/subDataService.test.ts +128 -73
- package/src/services/subDataService.ts +73 -0
- package/src/services/triggerService.test.ts +229 -1
- package/src/services/triggerService.ts +83 -0
- package/src/types/enums.ts +23 -0
- package/src/types/index.ts +22 -1
package/cjs/constants/index.js
CHANGED
|
@@ -398,6 +398,36 @@ exports.MAINNET_BUNDLES_INFO = {
|
|
|
398
398
|
strategyId: enums_1.Strategies.Identifiers.Boost,
|
|
399
399
|
protocol: exports.PROTOCOLS.FluidT1,
|
|
400
400
|
},
|
|
401
|
+
[enums_1.Bundles.MainnetIds.COMP_V3_SW_REPAY_ON_PRICE]: {
|
|
402
|
+
strategyOrBundleId: enums_1.Bundles.MainnetIds.COMP_V3_SW_REPAY_ON_PRICE,
|
|
403
|
+
strategyId: enums_1.Strategies.Identifiers.RepayOnPrice,
|
|
404
|
+
protocol: exports.PROTOCOLS.CompoundV3,
|
|
405
|
+
},
|
|
406
|
+
[enums_1.Bundles.MainnetIds.COMP_V3_SW_BOOST_ON_PRICE]: {
|
|
407
|
+
strategyOrBundleId: enums_1.Bundles.MainnetIds.COMP_V3_SW_BOOST_ON_PRICE,
|
|
408
|
+
strategyId: enums_1.Strategies.Identifiers.BoostOnPrice,
|
|
409
|
+
protocol: exports.PROTOCOLS.CompoundV3,
|
|
410
|
+
},
|
|
411
|
+
[enums_1.Bundles.MainnetIds.COMP_V3_SW_CLOSE]: {
|
|
412
|
+
strategyOrBundleId: enums_1.Bundles.MainnetIds.COMP_V3_SW_CLOSE,
|
|
413
|
+
strategyId: enums_1.Strategies.Identifiers.CloseOnPrice,
|
|
414
|
+
protocol: exports.PROTOCOLS.CompoundV3,
|
|
415
|
+
},
|
|
416
|
+
[enums_1.Bundles.MainnetIds.COMP_V3_EOA_REPAY_ON_PRICE]: {
|
|
417
|
+
strategyOrBundleId: enums_1.Bundles.MainnetIds.COMP_V3_EOA_REPAY_ON_PRICE,
|
|
418
|
+
strategyId: enums_1.Strategies.Identifiers.EoaRepayOnPrice,
|
|
419
|
+
protocol: exports.PROTOCOLS.CompoundV3,
|
|
420
|
+
},
|
|
421
|
+
[enums_1.Bundles.MainnetIds.COMP_V3_EOA_BOOST_ON_PRICE]: {
|
|
422
|
+
strategyOrBundleId: enums_1.Bundles.MainnetIds.COMP_V3_EOA_BOOST_ON_PRICE,
|
|
423
|
+
strategyId: enums_1.Strategies.Identifiers.EoaBoostOnPrice,
|
|
424
|
+
protocol: exports.PROTOCOLS.CompoundV3,
|
|
425
|
+
},
|
|
426
|
+
[enums_1.Bundles.MainnetIds.COMP_V3_EOA_CLOSE]: {
|
|
427
|
+
strategyOrBundleId: enums_1.Bundles.MainnetIds.COMP_V3_EOA_CLOSE,
|
|
428
|
+
strategyId: enums_1.Strategies.Identifiers.EoaCloseOnPrice,
|
|
429
|
+
protocol: exports.PROTOCOLS.CompoundV3,
|
|
430
|
+
},
|
|
401
431
|
};
|
|
402
432
|
exports.OPTIMISM_BUNDLES_INFO = {
|
|
403
433
|
[enums_1.Bundles.OptimismIds.AAVE_V3_REPAY]: {
|
|
@@ -497,6 +527,36 @@ exports.BASE_BUNDLES_INFO = {
|
|
|
497
527
|
strategyId: enums_1.Strategies.Identifiers.Boost,
|
|
498
528
|
protocol: exports.PROTOCOLS.FluidT1,
|
|
499
529
|
},
|
|
530
|
+
[enums_1.Bundles.BaseIds.COMP_V3_SW_REPAY_ON_PRICE]: {
|
|
531
|
+
strategyOrBundleId: enums_1.Bundles.BaseIds.COMP_V3_SW_REPAY_ON_PRICE,
|
|
532
|
+
strategyId: enums_1.Strategies.Identifiers.RepayOnPrice,
|
|
533
|
+
protocol: exports.PROTOCOLS.CompoundV3,
|
|
534
|
+
},
|
|
535
|
+
[enums_1.Bundles.BaseIds.COMP_V3_SW_BOOST_ON_PRICE]: {
|
|
536
|
+
strategyOrBundleId: enums_1.Bundles.BaseIds.COMP_V3_SW_BOOST_ON_PRICE,
|
|
537
|
+
strategyId: enums_1.Strategies.Identifiers.BoostOnPrice,
|
|
538
|
+
protocol: exports.PROTOCOLS.CompoundV3,
|
|
539
|
+
},
|
|
540
|
+
[enums_1.Bundles.BaseIds.COMP_V3_SW_CLOSE]: {
|
|
541
|
+
strategyOrBundleId: enums_1.Bundles.BaseIds.COMP_V3_SW_CLOSE,
|
|
542
|
+
strategyId: enums_1.Strategies.Identifiers.CloseOnPrice,
|
|
543
|
+
protocol: exports.PROTOCOLS.CompoundV3,
|
|
544
|
+
},
|
|
545
|
+
[enums_1.Bundles.BaseIds.COMP_V3_EOA_REPAY_ON_PRICE]: {
|
|
546
|
+
strategyOrBundleId: enums_1.Bundles.BaseIds.COMP_V3_EOA_REPAY_ON_PRICE,
|
|
547
|
+
strategyId: enums_1.Strategies.Identifiers.EoaRepayOnPrice,
|
|
548
|
+
protocol: exports.PROTOCOLS.CompoundV3,
|
|
549
|
+
},
|
|
550
|
+
[enums_1.Bundles.BaseIds.COMP_V3_EOA_BOOST_ON_PRICE]: {
|
|
551
|
+
strategyOrBundleId: enums_1.Bundles.BaseIds.COMP_V3_EOA_BOOST_ON_PRICE,
|
|
552
|
+
strategyId: enums_1.Strategies.Identifiers.EoaBoostOnPrice,
|
|
553
|
+
protocol: exports.PROTOCOLS.CompoundV3,
|
|
554
|
+
},
|
|
555
|
+
[enums_1.Bundles.BaseIds.COMP_V3_EOA_CLOSE]: {
|
|
556
|
+
strategyOrBundleId: enums_1.Bundles.BaseIds.COMP_V3_EOA_CLOSE,
|
|
557
|
+
strategyId: enums_1.Strategies.Identifiers.EoaCloseOnPrice,
|
|
558
|
+
protocol: exports.PROTOCOLS.CompoundV3,
|
|
559
|
+
},
|
|
500
560
|
};
|
|
501
561
|
exports.ARBITRUM_BUNDLES_INFO = {
|
|
502
562
|
[enums_1.Bundles.ArbitrumIds.AAVE_V3_REPAY]: {
|
|
@@ -549,6 +609,36 @@ exports.ARBITRUM_BUNDLES_INFO = {
|
|
|
549
609
|
strategyId: enums_1.Strategies.Identifiers.Boost,
|
|
550
610
|
protocol: exports.PROTOCOLS.FluidT1,
|
|
551
611
|
},
|
|
612
|
+
[enums_1.Bundles.ArbitrumIds.COMP_V3_SW_REPAY_ON_PRICE]: {
|
|
613
|
+
strategyOrBundleId: enums_1.Bundles.ArbitrumIds.COMP_V3_SW_REPAY_ON_PRICE,
|
|
614
|
+
strategyId: enums_1.Strategies.Identifiers.RepayOnPrice,
|
|
615
|
+
protocol: exports.PROTOCOLS.CompoundV3,
|
|
616
|
+
},
|
|
617
|
+
[enums_1.Bundles.ArbitrumIds.COMP_V3_SW_BOOST_ON_PRICE]: {
|
|
618
|
+
strategyOrBundleId: enums_1.Bundles.ArbitrumIds.COMP_V3_SW_BOOST_ON_PRICE,
|
|
619
|
+
strategyId: enums_1.Strategies.Identifiers.BoostOnPrice,
|
|
620
|
+
protocol: exports.PROTOCOLS.CompoundV3,
|
|
621
|
+
},
|
|
622
|
+
[enums_1.Bundles.ArbitrumIds.COMP_V3_SW_CLOSE]: {
|
|
623
|
+
strategyOrBundleId: enums_1.Bundles.ArbitrumIds.COMP_V3_SW_CLOSE,
|
|
624
|
+
strategyId: enums_1.Strategies.Identifiers.CloseOnPrice,
|
|
625
|
+
protocol: exports.PROTOCOLS.CompoundV3,
|
|
626
|
+
},
|
|
627
|
+
[enums_1.Bundles.ArbitrumIds.COMP_V3_EOA_REPAY_ON_PRICE]: {
|
|
628
|
+
strategyOrBundleId: enums_1.Bundles.ArbitrumIds.COMP_V3_EOA_REPAY_ON_PRICE,
|
|
629
|
+
strategyId: enums_1.Strategies.Identifiers.EoaRepayOnPrice,
|
|
630
|
+
protocol: exports.PROTOCOLS.CompoundV3,
|
|
631
|
+
},
|
|
632
|
+
[enums_1.Bundles.ArbitrumIds.COMP_V3_EOA_BOOST_ON_PRICE]: {
|
|
633
|
+
strategyOrBundleId: enums_1.Bundles.ArbitrumIds.COMP_V3_EOA_BOOST_ON_PRICE,
|
|
634
|
+
strategyId: enums_1.Strategies.Identifiers.EoaBoostOnPrice,
|
|
635
|
+
protocol: exports.PROTOCOLS.CompoundV3,
|
|
636
|
+
},
|
|
637
|
+
[enums_1.Bundles.ArbitrumIds.COMP_V3_EOA_CLOSE]: {
|
|
638
|
+
strategyOrBundleId: enums_1.Bundles.ArbitrumIds.COMP_V3_EOA_CLOSE,
|
|
639
|
+
strategyId: enums_1.Strategies.Identifiers.EoaCloseOnPrice,
|
|
640
|
+
protocol: exports.PROTOCOLS.CompoundV3,
|
|
641
|
+
},
|
|
552
642
|
};
|
|
553
643
|
exports.BUNDLES_INFO = {
|
|
554
644
|
[enums_1.ChainId.Ethereum]: exports.MAINNET_BUNDLES_INFO,
|
|
@@ -363,6 +363,48 @@ function parseCompoundV3LeverageManagement(position, parseData) {
|
|
|
363
363
|
_position.strategy.strategyId = isEOA ? enums_1.Strategies.IdOverrides.EoaLeverageManagement : enums_1.Strategies.IdOverrides.LeverageManagement;
|
|
364
364
|
return _position;
|
|
365
365
|
}
|
|
366
|
+
function parseCompoundV3LeverageManagementOnPrice(position, parseData) {
|
|
367
|
+
const _position = (0, lodash_1.cloneDeep)(position);
|
|
368
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
369
|
+
const triggerData = triggerService.compoundV3PriceTrigger.decode(subStruct.triggerData);
|
|
370
|
+
const subData = subDataService.compoundV3LeverageManagementOnPriceSubData.decode(subStruct.subData);
|
|
371
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
372
|
+
_position.strategyData.decoded.subData = subData;
|
|
373
|
+
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, triggerData.market, Math.random());
|
|
374
|
+
_position.specific = {
|
|
375
|
+
market: subData.market,
|
|
376
|
+
collToken: subData.collToken,
|
|
377
|
+
baseToken: subData.baseToken,
|
|
378
|
+
ratio: subData.targetRatio,
|
|
379
|
+
price: triggerData.price,
|
|
380
|
+
priceState: triggerData.priceState,
|
|
381
|
+
};
|
|
382
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
383
|
+
_position.strategy.strategyId = isEOA ? enums_1.Strategies.IdOverrides.EoaLeverageManagementOnPrice : enums_1.Strategies.IdOverrides.LeverageManagementOnPrice;
|
|
384
|
+
return _position;
|
|
385
|
+
}
|
|
386
|
+
function parseCompoundV3CloseOnPrice(position, parseData) {
|
|
387
|
+
const _position = (0, lodash_1.cloneDeep)(position);
|
|
388
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
389
|
+
const triggerData = triggerService.compoundV3PriceRangeTrigger.decode(subStruct.triggerData);
|
|
390
|
+
const subData = subDataService.compoundV3CloseSubData.decode(subStruct.subData);
|
|
391
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
392
|
+
_position.strategyData.decoded.subData = subData;
|
|
393
|
+
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, triggerData.market, Math.random());
|
|
394
|
+
const { takeProfitType, stopLossType } = (0, utils_1.getStopLossAndTakeProfitTypeByCloseStrategyType)(+subData.closeType);
|
|
395
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
396
|
+
_position.strategy.strategyId = isEOA ? enums_1.Strategies.Identifiers.EoaCloseOnPrice : enums_1.Strategies.Identifiers.CloseOnPrice;
|
|
397
|
+
_position.specific = {
|
|
398
|
+
market: subData.market,
|
|
399
|
+
collToken: subData.collToken,
|
|
400
|
+
baseToken: subData.baseToken,
|
|
401
|
+
stopLossPrice: triggerData.lowerPrice,
|
|
402
|
+
takeProfitPrice: triggerData.upperPrice,
|
|
403
|
+
takeProfitType,
|
|
404
|
+
stopLossType,
|
|
405
|
+
};
|
|
406
|
+
return _position;
|
|
407
|
+
}
|
|
366
408
|
function parseChickenBondsRebond(position, parseData) {
|
|
367
409
|
const _position = (0, lodash_1.cloneDeep)(position);
|
|
368
410
|
const { subStruct } = parseData.subscriptionEventData;
|
|
@@ -688,7 +730,6 @@ function parseLiquityV2CloseOnPrice(position, parseData) {
|
|
|
688
730
|
// - Only TakeProfit
|
|
689
731
|
// - Only StopLoss
|
|
690
732
|
// - Both
|
|
691
|
-
// TODO: see on frontend what specific data we need here because stop-loss and take-profit is one bundle now
|
|
692
733
|
_position.strategy.strategyId = enums_1.Strategies.Identifiers.CloseOnPrice;
|
|
693
734
|
_position.specific = {
|
|
694
735
|
market: subData.market,
|
|
@@ -823,6 +864,12 @@ const parsingMethodsMapping = {
|
|
|
823
864
|
[enums_1.Strategies.Identifiers.Boost]: parseCompoundV3LeverageManagement,
|
|
824
865
|
[enums_1.Strategies.Identifiers.EoaRepay]: parseCompoundV3LeverageManagement,
|
|
825
866
|
[enums_1.Strategies.Identifiers.EoaBoost]: parseCompoundV3LeverageManagement,
|
|
867
|
+
[enums_1.Strategies.Identifiers.RepayOnPrice]: parseCompoundV3LeverageManagementOnPrice,
|
|
868
|
+
[enums_1.Strategies.Identifiers.BoostOnPrice]: parseCompoundV3LeverageManagementOnPrice,
|
|
869
|
+
[enums_1.Strategies.Identifiers.EoaRepayOnPrice]: parseCompoundV3LeverageManagementOnPrice,
|
|
870
|
+
[enums_1.Strategies.Identifiers.EoaBoostOnPrice]: parseCompoundV3LeverageManagementOnPrice,
|
|
871
|
+
[enums_1.Strategies.Identifiers.CloseOnPrice]: parseCompoundV3CloseOnPrice,
|
|
872
|
+
[enums_1.Strategies.Identifiers.EoaCloseOnPrice]: parseCompoundV3CloseOnPrice,
|
|
826
873
|
},
|
|
827
874
|
[enums_1.ProtocolIdentifiers.StrategiesAutomation.ChickenBonds]: {
|
|
828
875
|
[enums_1.Strategies.Identifiers.Rebond]: parseChickenBondsRebond,
|
|
@@ -66,6 +66,8 @@ export declare const compoundV2Encode: {
|
|
|
66
66
|
};
|
|
67
67
|
export declare const compoundV3Encode: {
|
|
68
68
|
leverageManagement(market: EthereumAddress, baseToken: EthereumAddress, triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean, isEOA: boolean): string[];
|
|
69
|
+
leverageManagementOnPrice(strategyOrBundleId: number, market: EthereumAddress, collToken: EthereumAddress, baseToken: EthereumAddress, targetRatio: number, price: number, priceState: RatioState): (number | boolean | string[])[];
|
|
70
|
+
closeOnPrice(strategyOrBundleId: number, market: EthereumAddress, collToken: EthereumAddress, baseToken: EthereumAddress, stopLossPrice?: number, stopLossType?: CloseToAssetType, takeProfitPrice?: number, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
|
|
69
71
|
};
|
|
70
72
|
export declare const compoundV3L2Encode: {
|
|
71
73
|
leverageManagement(market: EthereumAddress, baseToken: EthereumAddress, triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean): string;
|
|
@@ -185,6 +185,19 @@ exports.compoundV3Encode = {
|
|
|
185
185
|
leverageManagement(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled, isEOA) {
|
|
186
186
|
return subDataService.compoundV3LeverageManagementSubData.encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled, isEOA);
|
|
187
187
|
},
|
|
188
|
+
leverageManagementOnPrice(strategyOrBundleId, market, collToken, baseToken, targetRatio, price, priceState) {
|
|
189
|
+
const isBundle = true;
|
|
190
|
+
const subDataEncoded = subDataService.compoundV3LeverageManagementOnPriceSubData.encode(market, collToken, baseToken, targetRatio);
|
|
191
|
+
const triggerDataEncoded = triggerService.compoundV3PriceTrigger.encode(market, collToken, price, priceState);
|
|
192
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
193
|
+
},
|
|
194
|
+
closeOnPrice(strategyOrBundleId, market, collToken, baseToken, stopLossPrice = 0, stopLossType = enums_1.CloseToAssetType.DEBT, takeProfitPrice = 0, takeProfitType = enums_1.CloseToAssetType.COLLATERAL) {
|
|
195
|
+
const isBundle = true;
|
|
196
|
+
const closeType = (0, utils_1.getCloseStrategyType)(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
197
|
+
const subDataEncoded = subDataService.compoundV3CloseSubData.encode(market, collToken, baseToken, closeType);
|
|
198
|
+
const triggerDataEncoded = triggerService.compoundV3PriceRangeTrigger.encode(market, collToken, stopLossPrice, takeProfitPrice);
|
|
199
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
200
|
+
},
|
|
188
201
|
};
|
|
189
202
|
exports.compoundV3L2Encode = {
|
|
190
203
|
leverageManagement(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
@@ -558,6 +558,114 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
558
558
|
});
|
|
559
559
|
});
|
|
560
560
|
});
|
|
561
|
+
describe('leverageManagementOnPrice()', () => {
|
|
562
|
+
const examples = [
|
|
563
|
+
[
|
|
564
|
+
[
|
|
565
|
+
enums_1.Bundles.MainnetIds.COMP_V3_SW_REPAY_ON_PRICE,
|
|
566
|
+
true,
|
|
567
|
+
['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000002e90edd0000000000000000000000000000000000000000000000000000000000000000001'],
|
|
568
|
+
[
|
|
569
|
+
'0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
|
|
570
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
571
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
572
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000'
|
|
573
|
+
],
|
|
574
|
+
],
|
|
575
|
+
[
|
|
576
|
+
enums_1.Bundles.MainnetIds.COMP_V3_SW_REPAY_ON_PRICE,
|
|
577
|
+
web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
|
|
578
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
|
|
579
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
|
|
580
|
+
200,
|
|
581
|
+
2000,
|
|
582
|
+
enums_1.RatioState.UNDER,
|
|
583
|
+
],
|
|
584
|
+
],
|
|
585
|
+
[
|
|
586
|
+
[
|
|
587
|
+
enums_1.Bundles.MainnetIds.COMP_V3_SW_BOOST_ON_PRICE,
|
|
588
|
+
true,
|
|
589
|
+
['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000045d964b8000000000000000000000000000000000000000000000000000000000000000000'],
|
|
590
|
+
[
|
|
591
|
+
'0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
|
|
592
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
593
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
594
|
+
'0x0000000000000000000000000000000000000000000000001a5e27eef13e0000'
|
|
595
|
+
],
|
|
596
|
+
],
|
|
597
|
+
[
|
|
598
|
+
enums_1.Bundles.MainnetIds.COMP_V3_SW_BOOST_ON_PRICE,
|
|
599
|
+
web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
|
|
600
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
|
|
601
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
|
|
602
|
+
190,
|
|
603
|
+
3000,
|
|
604
|
+
enums_1.RatioState.OVER,
|
|
605
|
+
],
|
|
606
|
+
]
|
|
607
|
+
];
|
|
608
|
+
examples.forEach(([expected, actual]) => {
|
|
609
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
610
|
+
(0, chai_1.expect)(strategySubService_1.compoundV3Encode.leverageManagementOnPrice(...actual)).to.eql(expected);
|
|
611
|
+
});
|
|
612
|
+
});
|
|
613
|
+
});
|
|
614
|
+
describe('closeOnPrice()', () => {
|
|
615
|
+
const examples = [
|
|
616
|
+
[
|
|
617
|
+
[
|
|
618
|
+
enums_1.Bundles.MainnetIds.COMP_V3_SW_CLOSE,
|
|
619
|
+
true,
|
|
620
|
+
['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
621
|
+
[
|
|
622
|
+
'0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
|
|
623
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
624
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
625
|
+
'0x0000000000000000000000000000000000000000000000000000000000000006'
|
|
626
|
+
],
|
|
627
|
+
],
|
|
628
|
+
[
|
|
629
|
+
enums_1.Bundles.MainnetIds.COMP_V3_SW_CLOSE,
|
|
630
|
+
web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
|
|
631
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
|
|
632
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
|
|
633
|
+
1500,
|
|
634
|
+
enums_1.CloseToAssetType.DEBT,
|
|
635
|
+
4000,
|
|
636
|
+
enums_1.CloseToAssetType.DEBT,
|
|
637
|
+
],
|
|
638
|
+
],
|
|
639
|
+
[
|
|
640
|
+
[
|
|
641
|
+
enums_1.Bundles.MainnetIds.COMP_V3_EOA_CLOSE,
|
|
642
|
+
true,
|
|
643
|
+
['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
|
|
644
|
+
[
|
|
645
|
+
'0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
|
|
646
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
647
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
648
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000'
|
|
649
|
+
],
|
|
650
|
+
],
|
|
651
|
+
[
|
|
652
|
+
enums_1.Bundles.MainnetIds.COMP_V3_EOA_CLOSE,
|
|
653
|
+
web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
|
|
654
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
|
|
655
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
|
|
656
|
+
0,
|
|
657
|
+
enums_1.CloseToAssetType.DEBT,
|
|
658
|
+
5000,
|
|
659
|
+
enums_1.CloseToAssetType.COLLATERAL,
|
|
660
|
+
],
|
|
661
|
+
]
|
|
662
|
+
];
|
|
663
|
+
examples.forEach(([expected, actual]) => {
|
|
664
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
665
|
+
(0, chai_1.expect)(strategySubService_1.compoundV3Encode.closeOnPrice(...actual)).to.eql(expected);
|
|
666
|
+
});
|
|
667
|
+
});
|
|
668
|
+
});
|
|
561
669
|
});
|
|
562
670
|
describe('When testing strategySubService.morphoAaveV2Encode', () => {
|
|
563
671
|
describe('leverageManagement()', () => {
|
|
@@ -252,3 +252,21 @@ export declare const fluidLeverageManagementSubData: {
|
|
|
252
252
|
targetRatio: number;
|
|
253
253
|
};
|
|
254
254
|
};
|
|
255
|
+
export declare const compoundV3LeverageManagementOnPriceSubData: {
|
|
256
|
+
encode(market: EthereumAddress, collToken: EthereumAddress, baseToken: EthereumAddress, targetRatio: number): string[];
|
|
257
|
+
decode(subData: string[]): {
|
|
258
|
+
market: EthereumAddress;
|
|
259
|
+
collToken: EthereumAddress;
|
|
260
|
+
baseToken: EthereumAddress;
|
|
261
|
+
targetRatio: number;
|
|
262
|
+
};
|
|
263
|
+
};
|
|
264
|
+
export declare const compoundV3CloseSubData: {
|
|
265
|
+
encode(market: EthereumAddress, collToken: EthereumAddress, baseToken: EthereumAddress, closeType: CloseStrategyType): string[];
|
|
266
|
+
decode(subData: string[]): {
|
|
267
|
+
market: EthereumAddress;
|
|
268
|
+
collToken: EthereumAddress;
|
|
269
|
+
baseToken: EthereumAddress;
|
|
270
|
+
closeType: CloseStrategyType;
|
|
271
|
+
};
|
|
272
|
+
};
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.fluidLeverageManagementSubData = exports.liquityV2PaybackSubData = exports.morphoBlueLeverageManagementOnPriceSubData = exports.liquityV2LeverageManagementOnPriceSubData = exports.liquityV2CloseSubData = exports.liquityV2LeverageManagementSubData = exports.aaveV3LeverageManagementOnPriceSubData = exports.morphoBlueLeverageManagementSubData = exports.crvUSDPaybackSubData = exports.crvUSDLeverageManagementSubData = exports.liquityDebtInFrontRepaySubData = exports.liquityDsrSupplySubData = exports.liquityDsrPaybackSubData = exports.sparkQuotePriceSubData = exports.sparkLeverageManagementSubData = exports.exchangeLimitOrderSubData = exports.exchangeDcaSubData = exports.liquityPaybackUsingChickenBondSubData = exports.cBondsRebondSubData = exports.morphoAaveV2LeverageManagementSubData = exports.compoundV3L2LeverageManagementSubData = exports.compoundV3LeverageManagementSubData = exports.compoundV2LeverageManagementSubData = exports.aaveV3QuotePriceSubData = exports.aaveV3LeverageManagementSubData = exports.aaveV2LeverageManagementSubData = exports.liquityCloseSubData = exports.liquityLeverageManagementSubData = exports.makerLeverageManagementSubData = exports.makerCloseSubData = exports.liquityRepayFromSavingsSubData = exports.makerRepayFromSavingsSubData = void 0;
|
|
6
|
+
exports.compoundV3CloseSubData = exports.compoundV3LeverageManagementOnPriceSubData = exports.fluidLeverageManagementSubData = exports.liquityV2PaybackSubData = exports.morphoBlueLeverageManagementOnPriceSubData = exports.liquityV2LeverageManagementOnPriceSubData = exports.liquityV2CloseSubData = exports.liquityV2LeverageManagementSubData = exports.aaveV3LeverageManagementOnPriceSubData = exports.morphoBlueLeverageManagementSubData = exports.crvUSDPaybackSubData = exports.crvUSDLeverageManagementSubData = exports.liquityDebtInFrontRepaySubData = exports.liquityDsrSupplySubData = exports.liquityDsrPaybackSubData = exports.sparkQuotePriceSubData = exports.sparkLeverageManagementSubData = exports.exchangeLimitOrderSubData = exports.exchangeDcaSubData = exports.liquityPaybackUsingChickenBondSubData = exports.cBondsRebondSubData = exports.morphoAaveV2LeverageManagementSubData = exports.compoundV3L2LeverageManagementSubData = exports.compoundV3LeverageManagementSubData = exports.compoundV2LeverageManagementSubData = exports.aaveV3QuotePriceSubData = exports.aaveV3LeverageManagementSubData = exports.aaveV2LeverageManagementSubData = exports.liquityCloseSubData = exports.liquityLeverageManagementSubData = exports.makerLeverageManagementSubData = exports.makerCloseSubData = exports.liquityRepayFromSavingsSubData = exports.makerRepayFromSavingsSubData = void 0;
|
|
7
7
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
8
8
|
const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
|
|
9
9
|
const web3_utils_1 = require("web3-utils");
|
|
@@ -667,3 +667,50 @@ exports.fluidLeverageManagementSubData = {
|
|
|
667
667
|
};
|
|
668
668
|
},
|
|
669
669
|
};
|
|
670
|
+
exports.compoundV3LeverageManagementOnPriceSubData = {
|
|
671
|
+
encode(market, collToken, baseToken, targetRatio) {
|
|
672
|
+
const marketEncoded = web3_eth_abi_1.default.encodeParameter('address', market);
|
|
673
|
+
const collTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', collToken);
|
|
674
|
+
const baseTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', baseToken);
|
|
675
|
+
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
676
|
+
return [
|
|
677
|
+
marketEncoded,
|
|
678
|
+
collTokenEncoded,
|
|
679
|
+
baseTokenEncoded,
|
|
680
|
+
targetRatioEncoded,
|
|
681
|
+
];
|
|
682
|
+
},
|
|
683
|
+
decode(subData) {
|
|
684
|
+
const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
685
|
+
const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
|
|
686
|
+
const baseToken = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
687
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]);
|
|
688
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
689
|
+
return {
|
|
690
|
+
market, collToken, baseToken, targetRatio,
|
|
691
|
+
};
|
|
692
|
+
},
|
|
693
|
+
};
|
|
694
|
+
exports.compoundV3CloseSubData = {
|
|
695
|
+
encode(market, collToken, baseToken, closeType) {
|
|
696
|
+
const marketEncoded = web3_eth_abi_1.default.encodeParameter('address', market);
|
|
697
|
+
const collTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', collToken);
|
|
698
|
+
const baseTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', baseToken);
|
|
699
|
+
const closeTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', closeType);
|
|
700
|
+
return [
|
|
701
|
+
marketEncoded,
|
|
702
|
+
collTokenEncoded,
|
|
703
|
+
baseTokenEncoded,
|
|
704
|
+
closeTypeEncoded,
|
|
705
|
+
];
|
|
706
|
+
},
|
|
707
|
+
decode(subData) {
|
|
708
|
+
const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
709
|
+
const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
|
|
710
|
+
const baseToken = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
711
|
+
const closeType = web3_eth_abi_1.default.decodeParameter('uint8', subData[3]);
|
|
712
|
+
return {
|
|
713
|
+
market, collToken, baseToken, closeType,
|
|
714
|
+
};
|
|
715
|
+
},
|
|
716
|
+
};
|