@defisaver/automation-sdk 3.3.12 → 3.3.13-strategies-refactor-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 +5 -0
- package/cjs/services/strategiesService.js +41 -17
- package/cjs/services/strategySubService.d.ts +6 -11
- package/cjs/services/strategySubService.js +33 -62
- package/cjs/services/strategySubService.test.js +99 -234
- package/cjs/services/subDataService.d.ts +46 -2
- package/cjs/services/subDataService.js +115 -20
- package/cjs/services/subDataService.test.js +121 -42
- package/cjs/types/enums.d.ts +2 -1
- package/cjs/types/enums.js +1 -0
- package/esm/constants/index.js +5 -0
- package/esm/services/strategiesService.js +41 -17
- package/esm/services/strategySubService.d.ts +6 -11
- package/esm/services/strategySubService.js +32 -58
- package/esm/services/strategySubService.test.js +101 -236
- package/esm/services/subDataService.d.ts +46 -2
- package/esm/services/subDataService.js +113 -19
- package/esm/services/subDataService.test.js +121 -42
- package/esm/types/enums.d.ts +2 -1
- package/esm/types/enums.js +1 -0
- package/package.json +1 -1
- package/src/constants/index.ts +5 -0
- package/src/services/strategiesService.ts +42 -17
- package/src/services/strategySubService.test.ts +117 -279
- package/src/services/strategySubService.ts +81 -111
- package/src/services/subDataService.test.ts +125 -48
- package/src/services/subDataService.ts +156 -28
- package/src/types/enums.ts +1 -0
|
@@ -161,6 +161,23 @@ export const liquityLeverageManagementSubData = {
|
|
|
161
161
|
return { targetRatio };
|
|
162
162
|
},
|
|
163
163
|
};
|
|
164
|
+
export const liquityLeverageManagementSubDataWithoutSubProxy = {
|
|
165
|
+
encode(targetRatio, ratioState) {
|
|
166
|
+
const encodedRatioState = AbiCoder.encodeParameter('uint8', ratioState);
|
|
167
|
+
const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
168
|
+
const isRepay = ratioState === RatioState.UNDER;
|
|
169
|
+
const collActionType = isRepay ? CollActionType.WITHDRAW : CollActionType.SUPPLY;
|
|
170
|
+
const debtActionType = isRepay ? DebtActionType.PAYBACK : DebtActionType.BORROW;
|
|
171
|
+
const collActionTypeEncoded = AbiCoder.encodeParameter('uint8', collActionType);
|
|
172
|
+
const debtActionTypeEncoded = AbiCoder.encodeParameter('uint8', debtActionType);
|
|
173
|
+
return [encodedRatioState, encodedTargetRatio, collActionTypeEncoded, debtActionTypeEncoded];
|
|
174
|
+
},
|
|
175
|
+
decode(subData) {
|
|
176
|
+
const ratioState = AbiCoder.decodeParameter('uint8', subData[0]);
|
|
177
|
+
const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[1]));
|
|
178
|
+
return { targetRatio, ratioState };
|
|
179
|
+
},
|
|
180
|
+
};
|
|
164
181
|
export const liquityCloseSubData = {
|
|
165
182
|
encode(closeToAssetAddr, chainId = ChainId.Ethereum, collAddr, debtAddr) {
|
|
166
183
|
const _collAddr = collAddr || getAssetInfo('WETH', chainId).address;
|
|
@@ -392,6 +409,25 @@ export const aaveV2LeverageManagementSubData = {
|
|
|
392
409
|
return { targetRatio };
|
|
393
410
|
},
|
|
394
411
|
};
|
|
412
|
+
export const aaveV2LeverageManagementSubDataWithoutSubProxy = {
|
|
413
|
+
encode(market, targetRatio, ratioState) {
|
|
414
|
+
const encodedMarket = AbiCoder.encodeParameter('address', market);
|
|
415
|
+
const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
416
|
+
const encodedRatioState = AbiCoder.encodeParameter('uint8', ratioState);
|
|
417
|
+
const isBoost = ratioState === RatioState.OVER;
|
|
418
|
+
if (isBoost) {
|
|
419
|
+
const enableAsCollEncoded = AbiCoder.encodeParameter('uint256', 1);
|
|
420
|
+
return [encodedMarket, encodedTargetRatio, encodedRatioState, enableAsCollEncoded];
|
|
421
|
+
}
|
|
422
|
+
return [encodedMarket, encodedTargetRatio, encodedRatioState];
|
|
423
|
+
},
|
|
424
|
+
decode(subData) {
|
|
425
|
+
const market = AbiCoder.decodeParameter('address', subData[0]);
|
|
426
|
+
const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[1]));
|
|
427
|
+
const ratioState = AbiCoder.decodeParameter('uint8', subData[2]);
|
|
428
|
+
return { market, targetRatio, ratioState };
|
|
429
|
+
},
|
|
430
|
+
};
|
|
395
431
|
/**
|
|
396
432
|
___ ___ ____ ____ _______ ____ ____ ____
|
|
397
433
|
/ \ / \ \ \ / / | ____| \ \ / / |___ \
|
|
@@ -746,6 +782,23 @@ export const compoundV2LeverageManagementSubData = {
|
|
|
746
782
|
return { targetRatio };
|
|
747
783
|
},
|
|
748
784
|
};
|
|
785
|
+
export const compoundV2LeverageManagementSubDataWithoutSubProxy = {
|
|
786
|
+
encode(targetRatio, ratioState) {
|
|
787
|
+
const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
788
|
+
const encodedRatioState = AbiCoder.encodeParameter('uint8', ratioState);
|
|
789
|
+
const isBoost = ratioState === RatioState.OVER;
|
|
790
|
+
if (isBoost) {
|
|
791
|
+
const enableAsCollEncoded = AbiCoder.encodeParameter('uint256', 1);
|
|
792
|
+
return [encodedTargetRatio, encodedRatioState, enableAsCollEncoded];
|
|
793
|
+
}
|
|
794
|
+
return [encodedTargetRatio, encodedRatioState];
|
|
795
|
+
},
|
|
796
|
+
decode(subData) {
|
|
797
|
+
const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[0]));
|
|
798
|
+
const ratioState = AbiCoder.decodeParameter('uint8', subData[1]);
|
|
799
|
+
return { targetRatio, ratioState };
|
|
800
|
+
},
|
|
801
|
+
};
|
|
749
802
|
/**
|
|
750
803
|
______ ______ .___ ___. .______ ____ ____ ____
|
|
751
804
|
/ | / __ \ | \/ | | _ \ \ \ / / |___ \
|
|
@@ -773,27 +826,22 @@ export const compoundV3LeverageManagementSubData = {
|
|
|
773
826
|
return { targetRatio };
|
|
774
827
|
},
|
|
775
828
|
};
|
|
776
|
-
export const
|
|
777
|
-
encode(market, baseToken,
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
subInput = subInput.concat(new Dec(triggerBoostRatio).mul(1e16).toHex().slice(2)
|
|
784
|
-
.padStart(32, '0'));
|
|
785
|
-
subInput = subInput.concat(new Dec(targetBoostRatio).mul(1e16).toHex().slice(2)
|
|
786
|
-
.padStart(32, '0'));
|
|
787
|
-
subInput = subInput.concat(new Dec(targetRepayRatio).mul(1e16).toHex().slice(2)
|
|
788
|
-
.padStart(32, '0'));
|
|
789
|
-
subInput = subInput.concat(boostEnabled ? '01' : '00');
|
|
790
|
-
subInput = subInput.concat(isEOA ? '01' : '00');
|
|
791
|
-
return subInput;
|
|
829
|
+
export const compoundV3LeverageManagementSubDataWithoutSubProxy = {
|
|
830
|
+
encode(market, baseToken, targetRatio, ratioState) {
|
|
831
|
+
const encodedMarket = AbiCoder.encodeParameter('address', market);
|
|
832
|
+
const encodedBaseToken = AbiCoder.encodeParameter('address', baseToken);
|
|
833
|
+
const encodedRatioState = AbiCoder.encodeParameter('uint8', ratioState);
|
|
834
|
+
const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
835
|
+
return [encodedMarket, encodedBaseToken, encodedRatioState, encodedTargetRatio];
|
|
792
836
|
},
|
|
793
837
|
decode(subData) {
|
|
794
|
-
const
|
|
795
|
-
const
|
|
796
|
-
|
|
838
|
+
const market = AbiCoder.decodeParameter('address', subData[0]);
|
|
839
|
+
const baseToken = AbiCoder.decodeParameter('address', subData[1]);
|
|
840
|
+
const ratioState = AbiCoder.decodeParameter('uint8', subData[2]);
|
|
841
|
+
const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[3]));
|
|
842
|
+
return {
|
|
843
|
+
market, baseToken, targetRatio, ratioState,
|
|
844
|
+
};
|
|
797
845
|
},
|
|
798
846
|
};
|
|
799
847
|
export const compoundV3LeverageManagementOnPriceSubData = {
|
|
@@ -899,6 +947,21 @@ export const exchangeLimitOrderSubData = {
|
|
|
899
947
|
return { fromToken, toToken, amount };
|
|
900
948
|
},
|
|
901
949
|
};
|
|
950
|
+
export const exchangeLimitOrderSubDataWithoutSubProxy = {
|
|
951
|
+
encode(fromToken, toToken, amount) {
|
|
952
|
+
return [
|
|
953
|
+
AbiCoder.encodeParameter('address', fromToken),
|
|
954
|
+
AbiCoder.encodeParameter('address', toToken),
|
|
955
|
+
AbiCoder.encodeParameter('uint256', amount),
|
|
956
|
+
];
|
|
957
|
+
},
|
|
958
|
+
decode: (subData, chainId) => {
|
|
959
|
+
const fromToken = AbiCoder.decodeParameter('address', subData[0]).toString();
|
|
960
|
+
const toToken = AbiCoder.decodeParameter('address', subData[1]).toString();
|
|
961
|
+
const amount = assetAmountInEth(AbiCoder.decodeParameter('uint256', subData[2]).toString(), getAssetInfoByAddress(fromToken, chainId).symbol);
|
|
962
|
+
return { fromToken, toToken, amount };
|
|
963
|
+
},
|
|
964
|
+
};
|
|
902
965
|
/**
|
|
903
966
|
_______..______ ___ .______ __ ___
|
|
904
967
|
/ || _ \ / \ | _ \ | |/ /
|
|
@@ -984,6 +1047,37 @@ export const sparkLeverageManagementOnPriceSubData = {
|
|
|
984
1047
|
};
|
|
985
1048
|
},
|
|
986
1049
|
};
|
|
1050
|
+
export const sparkCollateralSwitchSubData = {
|
|
1051
|
+
encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, useOnBehalf = false) {
|
|
1052
|
+
const encodedFromAsset = AbiCoder.encodeParameter('address', fromAsset);
|
|
1053
|
+
const encodedFromAssetId = AbiCoder.encodeParameter('uint8', fromAssetId);
|
|
1054
|
+
const encodedToAsset = AbiCoder.encodeParameter('address', toAsset);
|
|
1055
|
+
const encodedToAssetId = AbiCoder.encodeParameter('uint8', toAssetId);
|
|
1056
|
+
const encodedMarketAddr = AbiCoder.encodeParameter('address', marketAddr);
|
|
1057
|
+
const encodedAmountToSwitch = AbiCoder.encodeParameter('uint256', amountToSwitch);
|
|
1058
|
+
const encodedUseOnBehalf = AbiCoder.encodeParameter('bool', useOnBehalf);
|
|
1059
|
+
return [
|
|
1060
|
+
encodedFromAsset,
|
|
1061
|
+
encodedFromAssetId,
|
|
1062
|
+
encodedToAsset,
|
|
1063
|
+
encodedToAssetId,
|
|
1064
|
+
encodedMarketAddr,
|
|
1065
|
+
encodedAmountToSwitch,
|
|
1066
|
+
encodedUseOnBehalf,
|
|
1067
|
+
];
|
|
1068
|
+
},
|
|
1069
|
+
decode(subData) {
|
|
1070
|
+
const fromAsset = AbiCoder.decodeParameter('address', subData[0]);
|
|
1071
|
+
const fromAssetId = Number(AbiCoder.decodeParameter('uint8', subData[1]));
|
|
1072
|
+
const toAsset = AbiCoder.decodeParameter('address', subData[2]);
|
|
1073
|
+
const toAssetId = Number(AbiCoder.decodeParameter('uint8', subData[3]));
|
|
1074
|
+
const marketAddr = AbiCoder.decodeParameter('address', subData[4]);
|
|
1075
|
+
const amountToSwitch = AbiCoder.decodeParameter('uint256', subData[5]);
|
|
1076
|
+
return {
|
|
1077
|
+
fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch,
|
|
1078
|
+
};
|
|
1079
|
+
},
|
|
1080
|
+
};
|
|
987
1081
|
/**
|
|
988
1082
|
______ .______ ____ ____ __ __ _______. _______
|
|
989
1083
|
/ || _ \ \ \ / / | | | | / || \
|
|
@@ -528,6 +528,127 @@ describe('Feature: subDataService.ts', () => {
|
|
|
528
528
|
});
|
|
529
529
|
});
|
|
530
530
|
});
|
|
531
|
+
describe('When testing subDataService.sparkCollateralSwitchSubData', () => {
|
|
532
|
+
describe('encode()', () => {
|
|
533
|
+
const examples = [
|
|
534
|
+
// WETH -> cbBTC
|
|
535
|
+
[
|
|
536
|
+
[
|
|
537
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
538
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
539
|
+
'0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
|
|
540
|
+
'0x0000000000000000000000000000000000000000000000000000000000000007',
|
|
541
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
542
|
+
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
543
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
544
|
+
],
|
|
545
|
+
[
|
|
546
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
547
|
+
0,
|
|
548
|
+
web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
|
|
549
|
+
7,
|
|
550
|
+
web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
551
|
+
'10000000000000000000',
|
|
552
|
+
false,
|
|
553
|
+
]
|
|
554
|
+
],
|
|
555
|
+
// cbBTC -> WETH (MaxUint256)
|
|
556
|
+
[
|
|
557
|
+
[
|
|
558
|
+
'0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
|
|
559
|
+
'0x0000000000000000000000000000000000000000000000000000000000000007',
|
|
560
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
561
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
562
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
563
|
+
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
564
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
565
|
+
],
|
|
566
|
+
[
|
|
567
|
+
web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
|
|
568
|
+
7,
|
|
569
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
570
|
+
0,
|
|
571
|
+
web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
572
|
+
MAXUINT,
|
|
573
|
+
]
|
|
574
|
+
],
|
|
575
|
+
// WETH -> cbBTC (5 WETH)
|
|
576
|
+
[
|
|
577
|
+
[
|
|
578
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
579
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
580
|
+
'0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
|
|
581
|
+
'0x0000000000000000000000000000000000000000000000000000000000000007',
|
|
582
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
583
|
+
'0x0000000000000000000000000000000000000000000000004563918244f40000',
|
|
584
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
585
|
+
],
|
|
586
|
+
[
|
|
587
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
588
|
+
0,
|
|
589
|
+
web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
|
|
590
|
+
7,
|
|
591
|
+
web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
592
|
+
'5000000000000000000', // 5 WETH
|
|
593
|
+
]
|
|
594
|
+
],
|
|
595
|
+
];
|
|
596
|
+
examples.forEach(([expected, actual]) => {
|
|
597
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
598
|
+
expect(subDataService.sparkCollateralSwitchSubData.encode(...actual)).to.eql(expected);
|
|
599
|
+
});
|
|
600
|
+
});
|
|
601
|
+
});
|
|
602
|
+
describe('decode()', () => {
|
|
603
|
+
const examples = [
|
|
604
|
+
// WETH -> cbBTC
|
|
605
|
+
[
|
|
606
|
+
{
|
|
607
|
+
fromAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
608
|
+
fromAssetId: 0,
|
|
609
|
+
toAsset: web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
|
|
610
|
+
toAssetId: 7,
|
|
611
|
+
marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
612
|
+
amountToSwitch: '10000000000000000000',
|
|
613
|
+
},
|
|
614
|
+
[
|
|
615
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
616
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
617
|
+
'0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
|
|
618
|
+
'0x0000000000000000000000000000000000000000000000000000000000000007',
|
|
619
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
620
|
+
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
621
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
622
|
+
],
|
|
623
|
+
],
|
|
624
|
+
// cbBTC -> WETH (MaxUint256)
|
|
625
|
+
[
|
|
626
|
+
{
|
|
627
|
+
fromAsset: web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
|
|
628
|
+
fromAssetId: 7,
|
|
629
|
+
toAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
630
|
+
toAssetId: 0,
|
|
631
|
+
marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
632
|
+
amountToSwitch: MAXUINT,
|
|
633
|
+
},
|
|
634
|
+
[
|
|
635
|
+
'0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
|
|
636
|
+
'0x0000000000000000000000000000000000000000000000000000000000000007',
|
|
637
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
638
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
639
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
640
|
+
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
641
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
642
|
+
],
|
|
643
|
+
],
|
|
644
|
+
];
|
|
645
|
+
examples.forEach(([expected, actual]) => {
|
|
646
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
647
|
+
expect(subDataService.sparkCollateralSwitchSubData.decode(actual)).to.eql(expected);
|
|
648
|
+
});
|
|
649
|
+
});
|
|
650
|
+
});
|
|
651
|
+
});
|
|
531
652
|
describe('When testing subDataService.compoundV2LeverageManagementSubData', () => {
|
|
532
653
|
describe('encode()', () => {
|
|
533
654
|
const examples = [
|
|
@@ -1188,48 +1309,6 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1188
1309
|
});
|
|
1189
1310
|
});
|
|
1190
1311
|
});
|
|
1191
|
-
describe('When testing subDataService.compoundV3L2LeverageManagementSubData', () => {
|
|
1192
|
-
describe('encode()', () => {
|
|
1193
|
-
const examples = [
|
|
1194
|
-
[
|
|
1195
|
-
'0x0313D212133AFab8F2b829B1066c7e43caD94e2c0213D212133AfaB8F2b829B1066C7E43cAD94E2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e00000100',
|
|
1196
|
-
[web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'), web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'), 160, 220, 180, 190, true, false]
|
|
1197
|
-
],
|
|
1198
|
-
[
|
|
1199
|
-
'0x0313D212133AFab8F2b829B1066c7e43caD94e2c0413d212133afAb8F2B829b1066C7e43cAd94e2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000000f43fc2c04ee00000000',
|
|
1200
|
-
[web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'), web3Utils.toChecksumAddress('0x0413d212133AFaB8F2B829B1066c7E43cAd94E2c'), 160, 220, 180, 110, false, false]
|
|
1201
|
-
],
|
|
1202
|
-
];
|
|
1203
|
-
examples.forEach(([expected, actual]) => {
|
|
1204
|
-
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1205
|
-
expect(subDataService.compoundV3L2LeverageManagementSubData.encode(...actual)).to.eql(expected);
|
|
1206
|
-
});
|
|
1207
|
-
});
|
|
1208
|
-
});
|
|
1209
|
-
describe('decode()', () => {
|
|
1210
|
-
const examples = [
|
|
1211
|
-
[
|
|
1212
|
-
{ targetRatio: 200 },
|
|
1213
|
-
[
|
|
1214
|
-
'0x0000000000000000000000000313d212133AFaB8F2B829B1066c7E43cAd94E2c', '0x0000000000000000000000000213d212133AFaB8F2B829B1066c7E43cAd94E2c',
|
|
1215
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
1216
|
-
],
|
|
1217
|
-
],
|
|
1218
|
-
[
|
|
1219
|
-
{ targetRatio: 123 },
|
|
1220
|
-
[
|
|
1221
|
-
'0x0000000000000000000000000313d212133AFaB8F2B829B1066c7E43cAd94E2c', '0x0000000000000000000000000413d212133AFaB8F2B829B1066c7E43cAd94E2c',
|
|
1222
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
|
|
1223
|
-
],
|
|
1224
|
-
],
|
|
1225
|
-
];
|
|
1226
|
-
examples.forEach(([expected, actual]) => {
|
|
1227
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1228
|
-
expect(subDataService.compoundV3L2LeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
1229
|
-
});
|
|
1230
|
-
});
|
|
1231
|
-
});
|
|
1232
|
-
});
|
|
1233
1312
|
describe('When testing subDataService.morphoBlueLeverageManagementSubData', () => {
|
|
1234
1313
|
describe('encode()', () => {
|
|
1235
1314
|
const examples = [
|
package/esm/types/enums.d.ts
CHANGED
|
@@ -89,7 +89,8 @@ export declare namespace Strategies {
|
|
|
89
89
|
LIQUITY_V2_PAYBACK = 113,
|
|
90
90
|
AAVE_V3_COLLATERAL_SWITCH = 135,
|
|
91
91
|
AAVE_V4_COLLATERAL_SWITCH = 154,
|
|
92
|
-
AAVE_V4_COLLATERAL_SWITCH_EOA = 155
|
|
92
|
+
AAVE_V4_COLLATERAL_SWITCH_EOA = 155,
|
|
93
|
+
SPARK_COLLATERAL_SWITCH = 156
|
|
93
94
|
}
|
|
94
95
|
enum OptimismIds {
|
|
95
96
|
EXCHANGE_DCA = 8,
|
package/esm/types/enums.js
CHANGED
|
@@ -103,6 +103,7 @@ export var Strategies;
|
|
|
103
103
|
MainnetIds[MainnetIds["AAVE_V3_COLLATERAL_SWITCH"] = 135] = "AAVE_V3_COLLATERAL_SWITCH";
|
|
104
104
|
MainnetIds[MainnetIds["AAVE_V4_COLLATERAL_SWITCH"] = 154] = "AAVE_V4_COLLATERAL_SWITCH";
|
|
105
105
|
MainnetIds[MainnetIds["AAVE_V4_COLLATERAL_SWITCH_EOA"] = 155] = "AAVE_V4_COLLATERAL_SWITCH_EOA";
|
|
106
|
+
MainnetIds[MainnetIds["SPARK_COLLATERAL_SWITCH"] = 156] = "SPARK_COLLATERAL_SWITCH";
|
|
106
107
|
})(MainnetIds = Strategies.MainnetIds || (Strategies.MainnetIds = {}));
|
|
107
108
|
let OptimismIds;
|
|
108
109
|
(function (OptimismIds) {
|
package/package.json
CHANGED
package/src/constants/index.ts
CHANGED
|
@@ -135,6 +135,11 @@ export const MAINNET_STRATEGIES_INFO: MainnetStrategiesInfo = {
|
|
|
135
135
|
strategyId: Strategies.Identifiers.EoaCollateralSwitch,
|
|
136
136
|
protocol: PROTOCOLS.AaveV4,
|
|
137
137
|
},
|
|
138
|
+
[Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH]: {
|
|
139
|
+
strategyOrBundleId: Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
|
|
140
|
+
strategyId: Strategies.Identifiers.CollateralSwitch,
|
|
141
|
+
protocol: PROTOCOLS.Spark,
|
|
142
|
+
},
|
|
138
143
|
};
|
|
139
144
|
|
|
140
145
|
export const OPTIMISM_STRATEGIES_INFO: OptimismStrategiesInfo = {
|
|
@@ -102,7 +102,7 @@ function parseMakerTrailingStop(position: Position.Automated, parseData: ParseDa
|
|
|
102
102
|
function parseMakerLeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
103
103
|
const _position = cloneDeep(position);
|
|
104
104
|
|
|
105
|
-
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
105
|
+
const { subStruct, subId, subHash } = parseData.subscriptionEventData;
|
|
106
106
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
107
107
|
|
|
108
108
|
const triggerData = triggerService.makerRatioTrigger.decode(subStruct.triggerData);
|
|
@@ -119,9 +119,10 @@ function parseMakerLeverageManagement(position: Position.Automated, parseData: P
|
|
|
119
119
|
_position.specific = {
|
|
120
120
|
triggerRepayRatio: triggerData.ratio,
|
|
121
121
|
targetRepayRatio: subData.targetRatio,
|
|
122
|
-
repayEnabled:
|
|
122
|
+
repayEnabled: isEnabled,
|
|
123
123
|
subId1: Number(subId),
|
|
124
124
|
mergeWithId: Strategies.Identifiers.Boost,
|
|
125
|
+
subHashRepay: subHash,
|
|
125
126
|
};
|
|
126
127
|
} else {
|
|
127
128
|
_position.specific = {
|
|
@@ -130,6 +131,7 @@ function parseMakerLeverageManagement(position: Position.Automated, parseData: P
|
|
|
130
131
|
boostEnabled: isEnabled,
|
|
131
132
|
subId2: Number(subId),
|
|
132
133
|
mergeId: Strategies.Identifiers.Boost,
|
|
134
|
+
subHashBoost: subHash,
|
|
133
135
|
};
|
|
134
136
|
}
|
|
135
137
|
|
|
@@ -190,7 +192,7 @@ function parseLiquityTrailingStop(position: Position.Automated, parseData: Parse
|
|
|
190
192
|
function parseAaveV2LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
191
193
|
const _position = cloneDeep(position);
|
|
192
194
|
|
|
193
|
-
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
195
|
+
const { subStruct, subId, subHash } = parseData.subscriptionEventData;
|
|
194
196
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
195
197
|
|
|
196
198
|
const triggerData = triggerService.aaveV2RatioTrigger.decode(subStruct.triggerData);
|
|
@@ -207,9 +209,10 @@ function parseAaveV2LeverageManagement(position: Position.Automated, parseData:
|
|
|
207
209
|
_position.specific = {
|
|
208
210
|
triggerRepayRatio: triggerData.ratio,
|
|
209
211
|
targetRepayRatio: subData.targetRatio,
|
|
210
|
-
repayEnabled:
|
|
212
|
+
repayEnabled: isEnabled,
|
|
211
213
|
subId1: Number(subId),
|
|
212
214
|
mergeWithId: Strategies.Identifiers.Boost,
|
|
215
|
+
subHashRepay: subHash,
|
|
213
216
|
};
|
|
214
217
|
} else {
|
|
215
218
|
_position.specific = {
|
|
@@ -218,6 +221,7 @@ function parseAaveV2LeverageManagement(position: Position.Automated, parseData:
|
|
|
218
221
|
boostEnabled: isEnabled,
|
|
219
222
|
subId2: Number(subId),
|
|
220
223
|
mergeId: Strategies.Identifiers.Boost,
|
|
224
|
+
subHashBoost: subHash,
|
|
221
225
|
};
|
|
222
226
|
}
|
|
223
227
|
|
|
@@ -385,6 +389,17 @@ function parseAaveV3CollateralSwitch(position: Position.Automated, parseData: Pa
|
|
|
385
389
|
return _position;
|
|
386
390
|
}
|
|
387
391
|
|
|
392
|
+
function parseSparkCollateralSwitch(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
393
|
+
const _position = cloneDeep(position);
|
|
394
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
395
|
+
const triggerData = triggerService.sparkQuotePriceTrigger.decode(subStruct.triggerData);
|
|
396
|
+
const subData = subDataService.sparkCollateralSwitchSubData.decode(subStruct.subData);
|
|
397
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
398
|
+
_position.strategyData.decoded.subData = subData;
|
|
399
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
|
|
400
|
+
return _position;
|
|
401
|
+
}
|
|
402
|
+
|
|
388
403
|
function parseAaveV4LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
389
404
|
const _position = cloneDeep(position);
|
|
390
405
|
const { subStruct, subId, subHash } = parseData.subscriptionEventData;
|
|
@@ -490,7 +505,7 @@ function parseAaveV4CollateralSwitch(position: Position.Automated, parseData: Pa
|
|
|
490
505
|
function parseMorphoAaveV2LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
491
506
|
const _position = cloneDeep(position);
|
|
492
507
|
|
|
493
|
-
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
508
|
+
const { subStruct, subId, subHash } = parseData.subscriptionEventData;
|
|
494
509
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
495
510
|
|
|
496
511
|
const triggerData = triggerService.morphoAaveV2RatioTrigger.decode(subStruct.triggerData);
|
|
@@ -507,9 +522,10 @@ function parseMorphoAaveV2LeverageManagement(position: Position.Automated, parse
|
|
|
507
522
|
_position.specific = {
|
|
508
523
|
triggerRepayRatio: triggerData.ratio,
|
|
509
524
|
targetRepayRatio: subData.targetRatio,
|
|
510
|
-
repayEnabled:
|
|
525
|
+
repayEnabled: isEnabled,
|
|
511
526
|
subId1: Number(subId),
|
|
512
527
|
mergeWithId: Strategies.Identifiers.Boost,
|
|
528
|
+
subHashRepay: subHash,
|
|
513
529
|
};
|
|
514
530
|
} else {
|
|
515
531
|
_position.specific = {
|
|
@@ -518,6 +534,7 @@ function parseMorphoAaveV2LeverageManagement(position: Position.Automated, parse
|
|
|
518
534
|
boostEnabled: isEnabled,
|
|
519
535
|
subId2: Number(subId),
|
|
520
536
|
mergeId: Strategies.Identifiers.Boost,
|
|
537
|
+
subHashBoost: subHash,
|
|
521
538
|
};
|
|
522
539
|
}
|
|
523
540
|
|
|
@@ -568,7 +585,7 @@ function parseAaveV3CloseOnPriceWithMaximumGasPrice(position: Position.Automated
|
|
|
568
585
|
function parseCompoundV2LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
569
586
|
const _position = cloneDeep(position);
|
|
570
587
|
|
|
571
|
-
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
588
|
+
const { subStruct, subId, subHash } = parseData.subscriptionEventData;
|
|
572
589
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
573
590
|
|
|
574
591
|
const triggerData = triggerService.compoundV2RatioTrigger.decode(subStruct.triggerData);
|
|
@@ -586,9 +603,10 @@ function parseCompoundV2LeverageManagement(position: Position.Automated, parseDa
|
|
|
586
603
|
_position.specific = {
|
|
587
604
|
triggerRepayRatio: triggerData.ratio,
|
|
588
605
|
targetRepayRatio: subData.targetRatio,
|
|
589
|
-
repayEnabled:
|
|
606
|
+
repayEnabled: isEnabled,
|
|
590
607
|
subId1: Number(subId),
|
|
591
608
|
mergeWithId: Strategies.Identifiers.Boost,
|
|
609
|
+
subHashRepay: subHash,
|
|
592
610
|
};
|
|
593
611
|
} else {
|
|
594
612
|
_position.specific = {
|
|
@@ -597,6 +615,7 @@ function parseCompoundV2LeverageManagement(position: Position.Automated, parseDa
|
|
|
597
615
|
boostEnabled: isEnabled,
|
|
598
616
|
subId2: Number(subId),
|
|
599
617
|
mergeId: Strategies.Identifiers.Boost,
|
|
618
|
+
subHashBoost: subHash,
|
|
600
619
|
};
|
|
601
620
|
}
|
|
602
621
|
|
|
@@ -609,12 +628,10 @@ function parseCompoundV2LeverageManagement(position: Position.Automated, parseDa
|
|
|
609
628
|
function parseCompoundV3LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
610
629
|
const _position = cloneDeep(position);
|
|
611
630
|
|
|
612
|
-
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
631
|
+
const { subStruct, subId, subHash } = parseData.subscriptionEventData;
|
|
613
632
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
614
633
|
|
|
615
|
-
const subDataDecoder =
|
|
616
|
-
? subDataService.compoundV3L2LeverageManagementSubData
|
|
617
|
-
: subDataService.compoundV3LeverageManagementSubData;
|
|
634
|
+
const subDataDecoder = subDataService.compoundV3LeverageManagementSubDataWithoutSubProxy;
|
|
618
635
|
|
|
619
636
|
const triggerData = triggerService.compoundV3RatioTrigger.decode(subStruct.triggerData);
|
|
620
637
|
const subData = subDataDecoder.decode(subStruct.subData);
|
|
@@ -632,9 +649,10 @@ function parseCompoundV3LeverageManagement(position: Position.Automated, parseDa
|
|
|
632
649
|
_position.specific = {
|
|
633
650
|
triggerRepayRatio: triggerData.ratio,
|
|
634
651
|
targetRepayRatio: subData.targetRatio,
|
|
635
|
-
repayEnabled:
|
|
652
|
+
repayEnabled: isEnabled,
|
|
636
653
|
subId1: Number(subId),
|
|
637
654
|
mergeWithId: isEOA ? Strategies.Identifiers.EoaBoost : Strategies.Identifiers.Boost,
|
|
655
|
+
subHashRepay: subHash,
|
|
638
656
|
};
|
|
639
657
|
} else {
|
|
640
658
|
_position.specific = {
|
|
@@ -643,6 +661,7 @@ function parseCompoundV3LeverageManagement(position: Position.Automated, parseDa
|
|
|
643
661
|
boostEnabled: isEnabled,
|
|
644
662
|
subId2: Number(subId),
|
|
645
663
|
mergeId: isEOA ? Strategies.Identifiers.EoaBoost : Strategies.Identifiers.Boost,
|
|
664
|
+
subHashBoost: subHash,
|
|
646
665
|
};
|
|
647
666
|
}
|
|
648
667
|
|
|
@@ -768,7 +787,7 @@ function parseExchangeLimitOrder(position: Position.Automated, parseData: ParseD
|
|
|
768
787
|
function parseLiquityLeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
769
788
|
const _position = cloneDeep(position);
|
|
770
789
|
|
|
771
|
-
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
790
|
+
const { subStruct, subId, subHash } = parseData.subscriptionEventData;
|
|
772
791
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
773
792
|
|
|
774
793
|
const triggerData = triggerService.liquityRatioTrigger.decode(subStruct.triggerData);
|
|
@@ -785,9 +804,10 @@ function parseLiquityLeverageManagement(position: Position.Automated, parseData:
|
|
|
785
804
|
_position.specific = {
|
|
786
805
|
triggerRepayRatio: triggerData.ratio,
|
|
787
806
|
targetRepayRatio: subData.targetRatio,
|
|
788
|
-
repayEnabled:
|
|
807
|
+
repayEnabled: isEnabled,
|
|
789
808
|
subId1: Number(subId),
|
|
790
809
|
mergeWithId: Strategies.Identifiers.Boost,
|
|
810
|
+
subHashRepay: subHash,
|
|
791
811
|
};
|
|
792
812
|
} else {
|
|
793
813
|
_position.specific = {
|
|
@@ -796,6 +816,7 @@ function parseLiquityLeverageManagement(position: Position.Automated, parseData:
|
|
|
796
816
|
boostEnabled: isEnabled,
|
|
797
817
|
subId2: Number(subId),
|
|
798
818
|
mergeId: Strategies.Identifiers.Boost,
|
|
819
|
+
subHashBoost: subHash,
|
|
799
820
|
};
|
|
800
821
|
}
|
|
801
822
|
|
|
@@ -850,7 +871,7 @@ function parseLiquityV2LeverageManagement(position: Position.Automated, parseDat
|
|
|
850
871
|
function parseSparkLeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
851
872
|
const _position = cloneDeep(position);
|
|
852
873
|
|
|
853
|
-
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
874
|
+
const { subStruct, subId, subHash } = parseData.subscriptionEventData;
|
|
854
875
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
855
876
|
|
|
856
877
|
const triggerData = triggerService.sparkRatioTrigger.decode(subStruct.triggerData);
|
|
@@ -867,9 +888,10 @@ function parseSparkLeverageManagement(position: Position.Automated, parseData: P
|
|
|
867
888
|
_position.specific = {
|
|
868
889
|
triggerRepayRatio: triggerData.ratio,
|
|
869
890
|
targetRepayRatio: subData.targetRatio,
|
|
870
|
-
repayEnabled:
|
|
891
|
+
repayEnabled: isEnabled,
|
|
871
892
|
subId1: Number(subId),
|
|
872
893
|
mergeWithId: Strategies.Identifiers.Boost,
|
|
894
|
+
subHashRepay: subHash,
|
|
873
895
|
};
|
|
874
896
|
} else {
|
|
875
897
|
_position.specific = {
|
|
@@ -878,6 +900,7 @@ function parseSparkLeverageManagement(position: Position.Automated, parseData: P
|
|
|
878
900
|
boostEnabled: isEnabled,
|
|
879
901
|
subId2: Number(subId),
|
|
880
902
|
mergeId: Strategies.Identifiers.Boost,
|
|
903
|
+
subHashBoost: subHash,
|
|
881
904
|
};
|
|
882
905
|
}
|
|
883
906
|
|
|
@@ -1117,6 +1140,7 @@ function parseMorphoBlueLeverageManagementOnPrice(position: Position.Automated,
|
|
|
1117
1140
|
debtAsset: subData.loanToken,
|
|
1118
1141
|
price: triggerData.price,
|
|
1119
1142
|
ratio: subData.targetRatio,
|
|
1143
|
+
ratioState: triggerData.priceState,
|
|
1120
1144
|
};
|
|
1121
1145
|
|
|
1122
1146
|
return _position;
|
|
@@ -1386,6 +1410,7 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
|
|
|
1386
1410
|
[Strategies.Identifiers.RepayOnPrice]: parseSparkLeverageManagementOnPrice,
|
|
1387
1411
|
[Strategies.Identifiers.BoostOnPrice]: parseSparkLeverageManagementOnPrice,
|
|
1388
1412
|
[Strategies.Identifiers.CloseOnPrice]: parseSparkCloseOnPrice,
|
|
1413
|
+
[Strategies.Identifiers.CollateralSwitch]: parseSparkCollateralSwitch,
|
|
1389
1414
|
},
|
|
1390
1415
|
[ProtocolIdentifiers.StrategiesAutomation.CrvUSD]: {
|
|
1391
1416
|
[Strategies.Identifiers.Repay]: parseCrvUSDLeverageManagement,
|