@defisaver/automation-sdk 3.3.22-instant-twap-close-dev → 3.3.23
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/automation/private/StrategiesAutomation.d.ts +5 -1
- package/cjs/automation/private/StrategiesAutomation.js +12 -0
- package/cjs/automation/private/StrategiesAutomation.test.js +51 -0
- package/cjs/constants/index.js +40 -40
- package/cjs/services/apiSubscriptionsService.d.ts +7 -0
- package/cjs/services/apiSubscriptionsService.js +33 -0
- package/cjs/services/apiSubscriptionsService.test.d.ts +1 -0
- package/cjs/services/apiSubscriptionsService.test.js +67 -0
- package/cjs/services/strategiesService.js +8 -21
- package/cjs/services/strategiesService.test.js +0 -63
- package/cjs/services/strategySubService.d.ts +1 -1
- package/cjs/services/strategySubService.js +6 -7
- package/cjs/services/strategySubService.test.js +71 -111
- package/cjs/services/subDataService.d.ts +10 -12
- package/cjs/services/subDataService.js +30 -36
- package/cjs/services/subDataService.test.js +104 -70
- package/cjs/types/enums.d.ts +18 -18
- package/cjs/types/enums.js +10 -11
- package/cjs/types/index.d.ts +24 -2
- package/esm/automation/private/StrategiesAutomation.d.ts +5 -1
- package/esm/automation/private/StrategiesAutomation.js +12 -0
- package/esm/automation/private/StrategiesAutomation.test.js +51 -0
- package/esm/constants/index.js +40 -40
- package/esm/services/apiSubscriptionsService.d.ts +7 -0
- package/esm/services/apiSubscriptionsService.js +29 -0
- package/esm/services/apiSubscriptionsService.test.d.ts +1 -0
- package/esm/services/apiSubscriptionsService.test.js +65 -0
- package/esm/services/strategiesService.js +8 -21
- package/esm/services/strategiesService.test.js +1 -64
- package/esm/services/strategySubService.d.ts +1 -1
- package/esm/services/strategySubService.js +6 -7
- package/esm/services/strategySubService.test.js +71 -111
- package/esm/services/subDataService.d.ts +10 -12
- package/esm/services/subDataService.js +29 -35
- package/esm/services/subDataService.test.js +104 -70
- package/esm/types/enums.d.ts +18 -18
- package/esm/types/enums.js +10 -11
- package/esm/types/index.d.ts +24 -2
- package/package.json +1 -1
- package/src/automation/private/StrategiesAutomation.test.ts +65 -1
- package/src/automation/private/StrategiesAutomation.ts +17 -0
- package/src/constants/index.ts +40 -40
- package/src/services/apiSubscriptionsService.test.ts +73 -0
- package/src/services/apiSubscriptionsService.ts +33 -0
- package/src/services/strategiesService.test.ts +1 -79
- package/src/services/strategiesService.ts +8 -27
- package/src/services/strategySubService.test.ts +84 -125
- package/src/services/strategySubService.ts +16 -20
- package/src/services/subDataService.test.ts +108 -98
- package/src/services/subDataService.ts +40 -51
- package/src/types/enums.ts +10 -11
- package/src/types/index.ts +26 -2
|
@@ -887,137 +887,123 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
887
887
|
});
|
|
888
888
|
});
|
|
889
889
|
|
|
890
|
-
describe('
|
|
890
|
+
describe('collateralSwitch()', () => {
|
|
891
891
|
const examples: Array<[
|
|
892
892
|
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
893
893
|
[
|
|
894
894
|
strategyOrBundleId: number,
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
895
|
+
fromAsset: EthereumAddress,
|
|
896
|
+
fromAssetId: number,
|
|
897
|
+
toAsset: EthereumAddress,
|
|
898
|
+
toAssetId: number,
|
|
899
899
|
marketAddr: EthereumAddress,
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
takeProfitPrice: number,
|
|
906
|
-
takeProfitType: CloseToAssetType
|
|
900
|
+
amountToSwitch: string,
|
|
901
|
+
baseTokenAddress: EthereumAddress,
|
|
902
|
+
quoteTokenAddress: EthereumAddress,
|
|
903
|
+
price: number,
|
|
904
|
+
state: RatioState,
|
|
907
905
|
]
|
|
908
906
|
]> = [
|
|
909
|
-
//
|
|
907
|
+
// WETH -> USDC, price 100000, state UNDER
|
|
910
908
|
[
|
|
911
909
|
[
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
['
|
|
910
|
+
Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
911
|
+
false,
|
|
912
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000000000000000000000000000000009184e72a0000000000000000000000000000000000000000000000000000000000000000001'],
|
|
915
913
|
[
|
|
916
914
|
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
917
915
|
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
918
916
|
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
919
917
|
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
920
|
-
'
|
|
921
|
-
'
|
|
922
|
-
'
|
|
923
|
-
'0x0000000000000000000000000000000000000000000000000de0b6b3a7640000',
|
|
924
|
-
'0x000000000000000000000000000000000000000000000000002386f26fc10000',
|
|
918
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
919
|
+
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
920
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
925
921
|
],
|
|
926
922
|
],
|
|
927
923
|
[
|
|
928
|
-
|
|
924
|
+
Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
929
925
|
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
930
926
|
0,
|
|
931
927
|
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
932
928
|
1,
|
|
933
|
-
web3Utils.toChecksumAddress('
|
|
934
|
-
|
|
935
|
-
'
|
|
936
|
-
'
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
0, // takeProfitPrice
|
|
940
|
-
CloseToAssetType.COLLATERAL, // takeProfitType (not used since price is 0)
|
|
929
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
930
|
+
'10000000000000000000', // 10 WETH
|
|
931
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
932
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
933
|
+
100000,
|
|
934
|
+
RatioState.UNDER,
|
|
941
935
|
]
|
|
942
936
|
],
|
|
943
|
-
//
|
|
937
|
+
// USDC -> WETH, price 0.00001, state OVER
|
|
944
938
|
[
|
|
945
939
|
[
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
['
|
|
940
|
+
Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
941
|
+
false,
|
|
942
|
+
['0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000003e80000000000000000000000000000000000000000000000000000000000000000'],
|
|
949
943
|
[
|
|
950
|
-
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
951
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
952
944
|
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
953
945
|
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
946
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
954
947
|
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
955
|
-
'
|
|
956
|
-
'
|
|
957
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
948
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
949
|
+
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
958
950
|
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
959
951
|
],
|
|
960
952
|
],
|
|
961
953
|
[
|
|
962
|
-
|
|
954
|
+
Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
955
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
956
|
+
1,
|
|
963
957
|
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
964
958
|
0,
|
|
959
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
960
|
+
MAXUINT, // MaxUint256
|
|
965
961
|
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
'0', // tsi
|
|
970
|
-
'0', // slippage
|
|
971
|
-
0, // stopLossPrice
|
|
972
|
-
CloseToAssetType.DEBT, // stopLossType (not used since price is 0)
|
|
973
|
-
5000, // takeProfitPrice
|
|
974
|
-
CloseToAssetType.COLLATERAL, // takeProfitType
|
|
962
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
963
|
+
0.00001,
|
|
964
|
+
RatioState.OVER,
|
|
975
965
|
]
|
|
976
966
|
],
|
|
977
|
-
//
|
|
967
|
+
// WETH -> WBTC, price 1, state UNDER
|
|
978
968
|
[
|
|
979
969
|
[
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
['
|
|
970
|
+
Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
971
|
+
false,
|
|
972
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000005f5e1000000000000000000000000000000000000000000000000000000000000000001'],
|
|
983
973
|
[
|
|
984
974
|
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
985
975
|
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
986
|
-
'
|
|
987
|
-
'
|
|
988
|
-
'
|
|
989
|
-
'
|
|
990
|
-
'
|
|
991
|
-
'0x00000000000000000000000000000000000000000000000000b1a2bc2ec50000',
|
|
992
|
-
'0x0000000000000000000000000000000000000000000000000011c37937e08000',
|
|
976
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
977
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
978
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
979
|
+
'0x0000000000000000000000000000000000000000000000004563918244f40000',
|
|
980
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
993
981
|
],
|
|
994
982
|
],
|
|
995
983
|
[
|
|
996
|
-
|
|
984
|
+
Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
997
985
|
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
998
986
|
0,
|
|
999
|
-
web3Utils.toChecksumAddress(getAssetInfo('
|
|
987
|
+
web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
988
|
+
2,
|
|
989
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
990
|
+
'5000000000000000000', // 5 WETH
|
|
991
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
992
|
+
web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
1000
993
|
1,
|
|
1001
|
-
|
|
1002
|
-
web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
1003
|
-
'50000000000000000', // tsi
|
|
1004
|
-
'5000000000000000', // slippage
|
|
1005
|
-
1500, // stopLossPrice
|
|
1006
|
-
CloseToAssetType.COLLATERAL, // stopLossType
|
|
1007
|
-
4000, // takeProfitPrice
|
|
1008
|
-
CloseToAssetType.DEBT, // takeProfitType
|
|
994
|
+
RatioState.UNDER,
|
|
1009
995
|
]
|
|
1010
996
|
],
|
|
1011
997
|
];
|
|
1012
998
|
|
|
1013
999
|
examples.forEach(([expected, actual]) => {
|
|
1014
1000
|
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1015
|
-
expect(aaveV3Encode.
|
|
1001
|
+
expect(aaveV3Encode.collateralSwitch(...actual)).to.eql(expected);
|
|
1016
1002
|
});
|
|
1017
1003
|
});
|
|
1018
1004
|
});
|
|
1019
1005
|
|
|
1020
|
-
describe('
|
|
1006
|
+
describe('debtSwitch()', () => {
|
|
1021
1007
|
const examples: Array<[
|
|
1022
1008
|
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1023
1009
|
[
|
|
@@ -1028,107 +1014,80 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1028
1014
|
toAssetId: number,
|
|
1029
1015
|
marketAddr: EthereumAddress,
|
|
1030
1016
|
amountToSwitch: string,
|
|
1017
|
+
user: EthereumAddress,
|
|
1031
1018
|
baseTokenAddress: EthereumAddress,
|
|
1032
1019
|
quoteTokenAddress: EthereumAddress,
|
|
1033
1020
|
price: number,
|
|
1034
1021
|
state: RatioState,
|
|
1035
1022
|
]
|
|
1036
1023
|
]> = [
|
|
1037
|
-
//
|
|
1024
|
+
// USDC -> DAI, price 100000, state UNDER
|
|
1038
1025
|
[
|
|
1039
1026
|
[
|
|
1040
|
-
Strategies.MainnetIds.
|
|
1027
|
+
Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
|
|
1041
1028
|
false,
|
|
1042
|
-
['
|
|
1029
|
+
['0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000000000000009184e72a0000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1043
1030
|
[
|
|
1044
|
-
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1045
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1046
1031
|
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1047
1032
|
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1033
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
1034
|
+
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
1048
1035
|
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
1049
1036
|
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
1050
|
-
'
|
|
1037
|
+
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
1051
1038
|
],
|
|
1052
1039
|
],
|
|
1053
1040
|
[
|
|
1054
|
-
Strategies.MainnetIds.
|
|
1055
|
-
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1056
|
-
0,
|
|
1041
|
+
Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
|
|
1057
1042
|
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1058
1043
|
1,
|
|
1044
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1045
|
+
3,
|
|
1059
1046
|
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1060
|
-
'10000000000000000000', // 10
|
|
1061
|
-
web3Utils.toChecksumAddress(
|
|
1047
|
+
'10000000000000000000', // 10 tokens
|
|
1048
|
+
web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
1062
1049
|
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1050
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1063
1051
|
100000,
|
|
1064
1052
|
RatioState.UNDER,
|
|
1065
1053
|
]
|
|
1066
1054
|
],
|
|
1067
|
-
//
|
|
1055
|
+
// DAI -> USDC (MaxUint256), price 1, state OVER
|
|
1068
1056
|
[
|
|
1069
1057
|
[
|
|
1070
|
-
Strategies.MainnetIds.
|
|
1058
|
+
Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
|
|
1071
1059
|
false,
|
|
1072
|
-
['
|
|
1060
|
+
['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000005f5e1000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1073
1061
|
[
|
|
1062
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
1063
|
+
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
1074
1064
|
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1075
1065
|
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1076
|
-
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1077
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1078
1066
|
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
1079
1067
|
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
1080
|
-
'
|
|
1068
|
+
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
1081
1069
|
],
|
|
1082
1070
|
],
|
|
1083
1071
|
[
|
|
1084
|
-
Strategies.MainnetIds.
|
|
1072
|
+
Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
|
|
1073
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1074
|
+
3,
|
|
1085
1075
|
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1086
1076
|
1,
|
|
1087
|
-
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1088
|
-
0,
|
|
1089
1077
|
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1090
1078
|
MAXUINT, // MaxUint256
|
|
1079
|
+
web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
1080
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1091
1081
|
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1092
|
-
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1093
|
-
0.00001,
|
|
1094
|
-
RatioState.OVER,
|
|
1095
|
-
]
|
|
1096
|
-
],
|
|
1097
|
-
// WETH -> WBTC, price 1, state UNDER
|
|
1098
|
-
[
|
|
1099
|
-
[
|
|
1100
|
-
Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
1101
|
-
false,
|
|
1102
|
-
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000005f5e1000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1103
|
-
[
|
|
1104
|
-
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1105
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1106
|
-
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
1107
|
-
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
1108
|
-
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
1109
|
-
'0x0000000000000000000000000000000000000000000000004563918244f40000',
|
|
1110
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1111
|
-
],
|
|
1112
|
-
],
|
|
1113
|
-
[
|
|
1114
|
-
Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
1115
|
-
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1116
|
-
0,
|
|
1117
|
-
web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
1118
|
-
2,
|
|
1119
|
-
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1120
|
-
'5000000000000000000', // 5 WETH
|
|
1121
|
-
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1122
|
-
web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
1123
1082
|
1,
|
|
1124
|
-
RatioState.
|
|
1083
|
+
RatioState.OVER,
|
|
1125
1084
|
]
|
|
1126
1085
|
],
|
|
1127
1086
|
];
|
|
1128
1087
|
|
|
1129
1088
|
examples.forEach(([expected, actual]) => {
|
|
1130
1089
|
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1131
|
-
expect(aaveV3Encode.
|
|
1090
|
+
expect(aaveV3Encode.debtSwitch(...actual)).to.eql(expected);
|
|
1132
1091
|
});
|
|
1133
1092
|
});
|
|
1134
1093
|
});
|
|
@@ -424,33 +424,28 @@ export const aaveV3Encode = {
|
|
|
424
424
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
425
425
|
},
|
|
426
426
|
|
|
427
|
-
|
|
427
|
+
collateralSwitch(
|
|
428
428
|
strategyOrBundleId: number,
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
429
|
+
fromAsset: EthereumAddress,
|
|
430
|
+
fromAssetId: number,
|
|
431
|
+
toAsset: EthereumAddress,
|
|
432
|
+
toAssetId: number,
|
|
433
433
|
marketAddr: EthereumAddress,
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
takeProfitPrice: number = 0,
|
|
440
|
-
takeProfitType: CloseToAssetType = CloseToAssetType.COLLATERAL,
|
|
434
|
+
amountToSwitch: string,
|
|
435
|
+
baseTokenAddress: EthereumAddress,
|
|
436
|
+
quoteTokenAddress: EthereumAddress,
|
|
437
|
+
price: number,
|
|
438
|
+
state: RatioState,
|
|
441
439
|
) {
|
|
442
|
-
const isBundle =
|
|
443
|
-
const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
440
|
+
const isBundle = false;
|
|
444
441
|
|
|
445
|
-
const subDataEncoded = subDataService.
|
|
446
|
-
|
|
447
|
-
);
|
|
448
|
-
const triggerDataEncoded = triggerService.aaveV3QuotePriceRangeTrigger.encode(collAsset, debtAsset, stopLossPrice, takeProfitPrice);
|
|
442
|
+
const subDataEncoded = subDataService.aaveV3CollateralSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch);
|
|
443
|
+
const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
|
|
449
444
|
|
|
450
445
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
451
446
|
},
|
|
452
447
|
|
|
453
|
-
|
|
448
|
+
debtSwitch(
|
|
454
449
|
strategyOrBundleId: number,
|
|
455
450
|
fromAsset: EthereumAddress,
|
|
456
451
|
fromAssetId: number,
|
|
@@ -458,6 +453,7 @@ export const aaveV3Encode = {
|
|
|
458
453
|
toAssetId: number,
|
|
459
454
|
marketAddr: EthereumAddress,
|
|
460
455
|
amountToSwitch: string,
|
|
456
|
+
user: EthereumAddress,
|
|
461
457
|
baseTokenAddress: EthereumAddress,
|
|
462
458
|
quoteTokenAddress: EthereumAddress,
|
|
463
459
|
price: number,
|
|
@@ -465,7 +461,7 @@ export const aaveV3Encode = {
|
|
|
465
461
|
) {
|
|
466
462
|
const isBundle = false;
|
|
467
463
|
|
|
468
|
-
const subDataEncoded = subDataService.
|
|
464
|
+
const subDataEncoded = subDataService.aaveV3DebtSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user);
|
|
469
465
|
const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
|
|
470
466
|
|
|
471
467
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
@@ -549,6 +549,114 @@ describe('Feature: subDataService.ts', () => {
|
|
|
549
549
|
});
|
|
550
550
|
});
|
|
551
551
|
|
|
552
|
+
describe('When testing subDataService.aaveV3DebtSwitchSubData', () => {
|
|
553
|
+
describe('encode()', () => {
|
|
554
|
+
const examples: Array<[SubData, [fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, user: EthereumAddress]]> = [
|
|
555
|
+
// USDC -> DAI
|
|
556
|
+
[
|
|
557
|
+
[
|
|
558
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
559
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
560
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
561
|
+
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
562
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
563
|
+
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
564
|
+
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
565
|
+
],
|
|
566
|
+
[
|
|
567
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
568
|
+
1,
|
|
569
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
570
|
+
3,
|
|
571
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
572
|
+
'10000000000000000000', // 10 tokens
|
|
573
|
+
web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
574
|
+
]
|
|
575
|
+
],
|
|
576
|
+
// DAI -> USDC (MaxUint256)
|
|
577
|
+
[
|
|
578
|
+
[
|
|
579
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
580
|
+
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
581
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
582
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
583
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
584
|
+
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
585
|
+
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
586
|
+
],
|
|
587
|
+
[
|
|
588
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
589
|
+
3,
|
|
590
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
591
|
+
1,
|
|
592
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
593
|
+
MAXUINT, // MaxUint256
|
|
594
|
+
web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
595
|
+
]
|
|
596
|
+
],
|
|
597
|
+
];
|
|
598
|
+
|
|
599
|
+
examples.forEach(([expected, actual]) => {
|
|
600
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
601
|
+
expect(subDataService.aaveV3DebtSwitchSubData.encode(...actual)).to.eql(expected);
|
|
602
|
+
});
|
|
603
|
+
});
|
|
604
|
+
});
|
|
605
|
+
|
|
606
|
+
describe('decode()', () => {
|
|
607
|
+
const examples: Array<[{ fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, user: EthereumAddress }, SubData]> = [
|
|
608
|
+
// USDC -> DAI
|
|
609
|
+
[
|
|
610
|
+
{
|
|
611
|
+
fromAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
612
|
+
fromAssetId: 1,
|
|
613
|
+
toAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
614
|
+
toAssetId: 3,
|
|
615
|
+
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
616
|
+
amountToSwitch: '10000000000000000000',
|
|
617
|
+
user: web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
618
|
+
},
|
|
619
|
+
[
|
|
620
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
621
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
622
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
623
|
+
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
624
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
625
|
+
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
626
|
+
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
627
|
+
],
|
|
628
|
+
],
|
|
629
|
+
// DAI -> USDC (MaxUint256)
|
|
630
|
+
[
|
|
631
|
+
{
|
|
632
|
+
fromAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
633
|
+
fromAssetId: 3,
|
|
634
|
+
toAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
635
|
+
toAssetId: 1,
|
|
636
|
+
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
637
|
+
amountToSwitch: MAXUINT,
|
|
638
|
+
user: web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
639
|
+
},
|
|
640
|
+
[
|
|
641
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
642
|
+
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
643
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
644
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
645
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
646
|
+
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
647
|
+
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
648
|
+
],
|
|
649
|
+
],
|
|
650
|
+
];
|
|
651
|
+
|
|
652
|
+
examples.forEach(([expected, actual]) => {
|
|
653
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
654
|
+
expect(subDataService.aaveV3DebtSwitchSubData.decode(actual)).to.eql(expected);
|
|
655
|
+
});
|
|
656
|
+
});
|
|
657
|
+
});
|
|
658
|
+
});
|
|
659
|
+
|
|
552
660
|
describe('When testing subDataService.sparkCollateralSwitchSubData', () => {
|
|
553
661
|
describe('encode()', () => {
|
|
554
662
|
const examples: Array<[SubData, [fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, useOnBehalf?: boolean]]> = [
|
|
@@ -2495,104 +2603,6 @@ describe('Feature: subDataService.ts', () => {
|
|
|
2495
2603
|
});
|
|
2496
2604
|
});
|
|
2497
2605
|
});
|
|
2498
|
-
|
|
2499
|
-
describe("When testing subDataService.aaveV3InstantCloseGenericSubData", () => {
|
|
2500
|
-
const WETH = web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address);
|
|
2501
|
-
const USDC = web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address);
|
|
2502
|
-
const MARKET = web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39');
|
|
2503
|
-
const USER = web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890');
|
|
2504
|
-
|
|
2505
|
-
const examples: Array<
|
|
2506
|
-
[
|
|
2507
|
-
string[],
|
|
2508
|
-
[
|
|
2509
|
-
collAsset: EthereumAddress,
|
|
2510
|
-
collAssetId: number,
|
|
2511
|
-
debtAsset: EthereumAddress,
|
|
2512
|
-
debtAssetId: number,
|
|
2513
|
-
closeType: CloseStrategyType,
|
|
2514
|
-
marketAddr: EthereumAddress,
|
|
2515
|
-
user: EthereumAddress,
|
|
2516
|
-
tsi: string,
|
|
2517
|
-
slippage: string
|
|
2518
|
-
]
|
|
2519
|
-
]
|
|
2520
|
-
> = [
|
|
2521
|
-
// TAKE_PROFIT_IN_COLLATERAL, zero tsi and slippage
|
|
2522
|
-
[
|
|
2523
|
-
[
|
|
2524
|
-
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
2525
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
2526
|
-
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
2527
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
2528
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
2529
|
-
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
2530
|
-
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
2531
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
2532
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
2533
|
-
],
|
|
2534
|
-
[WETH, 0, USDC, 1, CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL, MARKET, USER, '0', '0'],
|
|
2535
|
-
],
|
|
2536
|
-
// STOP_LOSS_IN_DEBT
|
|
2537
|
-
[
|
|
2538
|
-
[
|
|
2539
|
-
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
2540
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
2541
|
-
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
2542
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
2543
|
-
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
2544
|
-
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
2545
|
-
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
2546
|
-
'0x0000000000000000000000000000000000000000000000000de0b6b3a7640000',
|
|
2547
|
-
'0x000000000000000000000000000000000000000000000000002386f26fc10000',
|
|
2548
|
-
],
|
|
2549
|
-
[WETH, 0, USDC, 1, CloseStrategyType.STOP_LOSS_IN_DEBT, MARKET, USER, '1000000000000000000', '10000000000000000'],
|
|
2550
|
-
],
|
|
2551
|
-
// TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL, asset ids above uint8 range
|
|
2552
|
-
[
|
|
2553
|
-
[
|
|
2554
|
-
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
2555
|
-
'0x000000000000000000000000000000000000000000000000000000000000012c',
|
|
2556
|
-
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
2557
|
-
'0x0000000000000000000000000000000000000000000000000000000000000190',
|
|
2558
|
-
'0x0000000000000000000000000000000000000000000000000000000000000007',
|
|
2559
|
-
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
2560
|
-
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
2561
|
-
'0x00000000000000000000000000000000000000000000000000b1a2bc2ec50000',
|
|
2562
|
-
'0x0000000000000000000000000000000000000000000000000011c37937e08000',
|
|
2563
|
-
],
|
|
2564
|
-
[WETH, 300, USDC, 400, CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL, MARKET, USER, '50000000000000000', '5000000000000000'],
|
|
2565
|
-
],
|
|
2566
|
-
];
|
|
2567
|
-
|
|
2568
|
-
describe("encode()", () => {
|
|
2569
|
-
examples.forEach(([expected, actual]) => {
|
|
2570
|
-
it(`Given ${JSON.stringify(
|
|
2571
|
-
actual
|
|
2572
|
-
)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
2573
|
-
expect(
|
|
2574
|
-
subDataService.aaveV3InstantCloseGenericSubData.encode(...actual)
|
|
2575
|
-
).to.eql(expected);
|
|
2576
|
-
});
|
|
2577
|
-
});
|
|
2578
|
-
});
|
|
2579
|
-
|
|
2580
|
-
describe("decode()", () => {
|
|
2581
|
-
examples.forEach(([encoded, [collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, user, tsi, slippage]]) => {
|
|
2582
|
-
const expected = {
|
|
2583
|
-
collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, owner: user, tsi, slippage,
|
|
2584
|
-
};
|
|
2585
|
-
|
|
2586
|
-
it(`Given ${JSON.stringify(
|
|
2587
|
-
encoded
|
|
2588
|
-
)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
2589
|
-
expect(
|
|
2590
|
-
subDataService.aaveV3InstantCloseGenericSubData.decode(encoded)
|
|
2591
|
-
).to.eql(expected);
|
|
2592
|
-
});
|
|
2593
|
-
});
|
|
2594
|
-
});
|
|
2595
|
-
});
|
|
2596
2606
|
describe('When testing subDataService.sparkLeverageManagementOnPriceSubData', () => {
|
|
2597
2607
|
describe('encode()', () => {
|
|
2598
2608
|
const examples: Array<[SubData, [collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number]] > =
|