@defisaver/automation-sdk 3.3.15 → 3.3.16-liq-prot-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 +145 -0
- package/cjs/index.d.ts +2 -2
- package/cjs/index.js +5 -2
- package/cjs/services/strategiesService.js +158 -9
- package/cjs/services/strategySubService.d.ts +17 -16
- package/cjs/services/strategySubService.js +69 -28
- package/cjs/services/strategySubService.test.js +69 -40
- package/cjs/services/subDataService.d.ts +70 -20
- package/cjs/services/subDataService.js +23 -79
- package/cjs/services/subDataService.test.js +117 -202
- package/cjs/services/triggerService.test.js +60 -0
- package/cjs/services/utils.d.ts +2 -1
- package/cjs/services/utils.js +14 -1
- package/cjs/types/enums.d.ts +39 -6
- package/cjs/types/enums.js +33 -0
- package/esm/constants/index.js +145 -0
- package/esm/index.d.ts +2 -2
- package/esm/index.js +5 -2
- package/esm/services/strategiesService.js +158 -9
- package/esm/services/strategySubService.d.ts +17 -16
- package/esm/services/strategySubService.js +69 -28
- package/esm/services/strategySubService.test.js +70 -38
- package/esm/services/subDataService.d.ts +70 -20
- package/esm/services/subDataService.js +21 -77
- package/esm/services/subDataService.test.js +118 -200
- package/esm/services/triggerService.test.js +61 -1
- package/esm/services/utils.d.ts +2 -1
- package/esm/services/utils.js +13 -1
- package/esm/types/enums.d.ts +39 -6
- package/esm/types/enums.js +33 -0
- package/package.json +1 -1
- package/src/constants/index.ts +147 -1
- package/src/index.ts +22 -6
- package/src/services/strategiesService.ts +222 -9
- package/src/services/strategySubService.test.ts +86 -46
- package/src/services/strategySubService.ts +166 -39
- package/src/services/subDataService.test.ts +128 -214
- package/src/services/subDataService.ts +42 -106
- package/src/services/triggerService.test.ts +69 -0
- package/src/services/utils.test.ts +1 -1
- package/src/services/utils.ts +15 -1
- package/src/types/enums.ts +33 -2
|
@@ -6,7 +6,7 @@ import { assetAmountInEth, getAssetInfo, getAssetInfoByAddress } from '@defisave
|
|
|
6
6
|
import { otherAddresses } from '@defisaver/sdk';
|
|
7
7
|
|
|
8
8
|
import type { SubData, EthereumAddress } from '../types';
|
|
9
|
-
import type { CloseStrategyType
|
|
9
|
+
import type { CloseStrategyType } from '../types/enums';
|
|
10
10
|
import {
|
|
11
11
|
ChainId, CollActionType, DebtActionType, RatioState,
|
|
12
12
|
} from '../types/enums';
|
|
@@ -24,22 +24,6 @@ import { compareAddresses, ratioPercentageToWei, weiToRatioPercentage } from './
|
|
|
24
24
|
|_______/ |_______|| _| | _| `._____||_______| \______/__/ \__\ |__| |_______||_______/
|
|
25
25
|
*/
|
|
26
26
|
export const morphoAaveV2LeverageManagementSubData = {
|
|
27
|
-
encode(
|
|
28
|
-
triggerRepayRatio: number,
|
|
29
|
-
triggerBoostRatio: number,
|
|
30
|
-
targetBoostRatio: number,
|
|
31
|
-
targetRepayRatio: number,
|
|
32
|
-
boostEnabled: boolean,
|
|
33
|
-
): SubData {
|
|
34
|
-
return [
|
|
35
|
-
ratioPercentageToWei(triggerRepayRatio),
|
|
36
|
-
ratioPercentageToWei(triggerBoostRatio),
|
|
37
|
-
ratioPercentageToWei(targetBoostRatio),
|
|
38
|
-
ratioPercentageToWei(targetRepayRatio),
|
|
39
|
-
// @ts-ignore
|
|
40
|
-
boostEnabled,
|
|
41
|
-
];
|
|
42
|
-
},
|
|
43
27
|
decode(subData: SubData): { targetRatio: number } {
|
|
44
28
|
const ratioWei = AbiCoder.decodeParameter('uint128', subData[1]) as any as string;
|
|
45
29
|
const targetRatio = weiToRatioPercentage(ratioWei);
|
|
@@ -48,10 +32,6 @@ export const morphoAaveV2LeverageManagementSubData = {
|
|
|
48
32
|
},
|
|
49
33
|
};
|
|
50
34
|
export const cBondsRebondSubData = {
|
|
51
|
-
encode(bondId: number | string): SubData {
|
|
52
|
-
const bondIdEncoded = AbiCoder.encodeParameter('uint256', bondId);
|
|
53
|
-
return [bondIdEncoded];
|
|
54
|
-
},
|
|
55
35
|
decode(subData: SubData): { bondId: string } {
|
|
56
36
|
const bondId = AbiCoder.decodeParameter('uint256', subData[1])!.toString();
|
|
57
37
|
return { bondId };
|
|
@@ -156,7 +136,7 @@ export const makerCloseSubData = {
|
|
|
156
136
|
};
|
|
157
137
|
},
|
|
158
138
|
};
|
|
159
|
-
export const
|
|
139
|
+
export const legacyMakerLeverageManagementSubData = {
|
|
160
140
|
decode: (subData:SubData) => {
|
|
161
141
|
const vaultId = +AbiCoder.decodeParameter('uint256', subData[0])!.toString();
|
|
162
142
|
const weiRatio = AbiCoder.decodeParameter('uint256', subData[1]) as any as string;
|
|
@@ -164,7 +144,8 @@ export const makerLeverageManagementSubData = {
|
|
|
164
144
|
return { vaultId, targetRatio };
|
|
165
145
|
},
|
|
166
146
|
};
|
|
167
|
-
|
|
147
|
+
|
|
148
|
+
export const makerLeverageManagementSubData = {
|
|
168
149
|
encode(
|
|
169
150
|
vaultId: number,
|
|
170
151
|
targetRatio: number,
|
|
@@ -184,6 +165,9 @@ export const makerLeverageManagementWithoutSubProxy = {
|
|
|
184
165
|
},
|
|
185
166
|
};
|
|
186
167
|
|
|
168
|
+
export const makerLiquidationProtectionSubData = makerLeverageManagementSubData;
|
|
169
|
+
|
|
170
|
+
|
|
187
171
|
/**
|
|
188
172
|
__ __ ______ __ __ __ .___________.____ ____ ____ ____ __
|
|
189
173
|
| | | | / __ \ | | | | | | | |\ \ / / \ \ / / /_ |
|
|
@@ -200,14 +184,14 @@ export const liquityRepayFromSavingsSubData = {
|
|
|
200
184
|
return { targetRatio };
|
|
201
185
|
},
|
|
202
186
|
};
|
|
203
|
-
export const
|
|
187
|
+
export const legacyLiquityLeverageManagementSubData = {
|
|
204
188
|
decode: (subData:SubData) => {
|
|
205
189
|
const weiRatio = AbiCoder.decodeParameter('uint256', subData[1]) as any as string;
|
|
206
190
|
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
207
191
|
return { targetRatio };
|
|
208
192
|
},
|
|
209
193
|
};
|
|
210
|
-
export const
|
|
194
|
+
export const liquityLeverageManagementSubData = {
|
|
211
195
|
encode(
|
|
212
196
|
targetRatio: number,
|
|
213
197
|
ratioState: RatioState,
|
|
@@ -510,23 +494,7 @@ export const liquityV2PaybackSubData = {
|
|
|
510
494
|
/ _____ \ / _____ \ \ / | |____ \ / / /_
|
|
511
495
|
/__/ \__\ /__/ \__\ \__/ |_______| \__/ |____|
|
|
512
496
|
*/
|
|
513
|
-
export const
|
|
514
|
-
encode(
|
|
515
|
-
triggerRepayRatio: number,
|
|
516
|
-
triggerBoostRatio: number,
|
|
517
|
-
targetBoostRatio: number,
|
|
518
|
-
targetRepayRatio: number,
|
|
519
|
-
boostEnabled: boolean,
|
|
520
|
-
): SubData {
|
|
521
|
-
return [
|
|
522
|
-
new Dec(triggerRepayRatio).mul(1e16).toString(),
|
|
523
|
-
new Dec(triggerBoostRatio).mul(1e16).toString(),
|
|
524
|
-
new Dec(targetBoostRatio).mul(1e16).toString(),
|
|
525
|
-
new Dec(targetRepayRatio).mul(1e16).toString(),
|
|
526
|
-
// @ts-ignore // TODO
|
|
527
|
-
boostEnabled,
|
|
528
|
-
];
|
|
529
|
-
},
|
|
497
|
+
export const legacyAaveV2LeverageManagementSubData = {
|
|
530
498
|
decode(subData: SubData): { targetRatio: number } {
|
|
531
499
|
const ratioWei = AbiCoder.decodeParameter('uint256', subData[1]) as any as string;
|
|
532
500
|
const targetRatio = weiToRatioPercentage(ratioWei);
|
|
@@ -534,7 +502,7 @@ export const aaveV2LeverageManagementSubData = {
|
|
|
534
502
|
return { targetRatio };
|
|
535
503
|
},
|
|
536
504
|
};
|
|
537
|
-
export const
|
|
505
|
+
export const aaveV2LeverageManagementSubData = {
|
|
538
506
|
encode(
|
|
539
507
|
market: EthereumAddress,
|
|
540
508
|
targetRatio: number,
|
|
@@ -570,7 +538,7 @@ export const aaveV2LeverageManagementSubDataWithoutSubProxy = {
|
|
|
570
538
|
/ _____ \ / _____ \ \ / | |____ \ / ___) |
|
|
571
539
|
/__/ \__\ /__/ \__\ \__/ |_______| \__/ |____/
|
|
572
540
|
*/
|
|
573
|
-
export const
|
|
541
|
+
export const legacyAaveV3LeverageManagementSubData = {
|
|
574
542
|
decode(subData: SubData): { targetRatio: number } {
|
|
575
543
|
const ratioWei = AbiCoder.decodeParameter('uint256', subData[0]) as any as string;
|
|
576
544
|
const targetRatio = weiToRatioPercentage(ratioWei);
|
|
@@ -578,7 +546,8 @@ export const aaveV3LeverageManagementSubData = {
|
|
|
578
546
|
return { targetRatio };
|
|
579
547
|
},
|
|
580
548
|
};
|
|
581
|
-
|
|
549
|
+
|
|
550
|
+
export const aaveV3LeverageManagementSubData = {
|
|
582
551
|
encode(
|
|
583
552
|
targetRatio: number,
|
|
584
553
|
ratioState: RatioState,
|
|
@@ -605,6 +574,9 @@ export const aaveV3LeverageManagementSubDataWithoutSubProxy = {
|
|
|
605
574
|
return { targetRatio, ratioState };
|
|
606
575
|
},
|
|
607
576
|
};
|
|
577
|
+
|
|
578
|
+
export const aaveV3LiquidationProtectionSubData = aaveV3LeverageManagementSubData;
|
|
579
|
+
|
|
608
580
|
export const aaveV3LeverageManagementOnPriceGeneric = {
|
|
609
581
|
encode(
|
|
610
582
|
collAsset: EthereumAddress,
|
|
@@ -851,6 +823,7 @@ export const aaveV3LeverageManagementOnPriceSubData = {
|
|
|
851
823
|
/ _____ \ / _____ \ \ / | |____ \ / | |
|
|
852
824
|
/__/ \__\ /__/ \__\ \__/ |_______| \__/ |_|
|
|
853
825
|
*/
|
|
826
|
+
|
|
854
827
|
export const aaveV4LeverageManagementSubData = {
|
|
855
828
|
encode: (
|
|
856
829
|
spoke: EthereumAddress,
|
|
@@ -882,6 +855,9 @@ export const aaveV4LeverageManagementSubData = {
|
|
|
882
855
|
};
|
|
883
856
|
},
|
|
884
857
|
};
|
|
858
|
+
|
|
859
|
+
export const aaveV4LiquidationProtectionSubData = aaveV4LeverageManagementSubData;
|
|
860
|
+
|
|
885
861
|
export const aaveV4LeverageManagementOnPriceSubData = {
|
|
886
862
|
encode: (
|
|
887
863
|
spoke: EthereumAddress,
|
|
@@ -1024,23 +1000,7 @@ export const aaveV4CollateralSwitchSubData = {
|
|
|
1024
1000
|
| `----.| `--' | | | | | | | \ / / /_
|
|
1025
1001
|
\______| \______/ |__| |__| | _| \__/ |____|
|
|
1026
1002
|
*/
|
|
1027
|
-
export const
|
|
1028
|
-
encode(
|
|
1029
|
-
triggerRepayRatio: number,
|
|
1030
|
-
triggerBoostRatio: number,
|
|
1031
|
-
targetBoostRatio: number,
|
|
1032
|
-
targetRepayRatio: number,
|
|
1033
|
-
boostEnabled: boolean,
|
|
1034
|
-
): SubData {
|
|
1035
|
-
return [
|
|
1036
|
-
new Dec(triggerRepayRatio).mul(1e16).toString(),
|
|
1037
|
-
new Dec(triggerBoostRatio).mul(1e16).toString(),
|
|
1038
|
-
new Dec(targetBoostRatio).mul(1e16).toString(),
|
|
1039
|
-
new Dec(targetRepayRatio).mul(1e16).toString(),
|
|
1040
|
-
// @ts-ignore // TODO
|
|
1041
|
-
boostEnabled,
|
|
1042
|
-
];
|
|
1043
|
-
},
|
|
1003
|
+
export const legacyCompoundV2LeverageManagementSubData = {
|
|
1044
1004
|
decode(subData: SubData): { targetRatio: number } {
|
|
1045
1005
|
const weiRatio = AbiCoder.decodeParameter('uint256', subData[0]) as any as string;
|
|
1046
1006
|
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
@@ -1048,7 +1008,7 @@ export const compoundV2LeverageManagementSubData = {
|
|
|
1048
1008
|
return { targetRatio };
|
|
1049
1009
|
},
|
|
1050
1010
|
};
|
|
1051
|
-
export const
|
|
1011
|
+
export const compoundV2LeverageManagementSubData = {
|
|
1052
1012
|
encode(
|
|
1053
1013
|
targetRatio: number,
|
|
1054
1014
|
ratioState: RatioState,
|
|
@@ -1081,36 +1041,8 @@ export const compoundV2LeverageManagementSubDataWithoutSubProxy = {
|
|
|
1081
1041
|
| `----.| `--' | | | | | | | \ / ___) |
|
|
1082
1042
|
\______| \______/ |__| |__| | _| \__/ |____/
|
|
1083
1043
|
*/
|
|
1084
|
-
export const compoundV3LeverageManagementSubData = {
|
|
1085
|
-
encode(
|
|
1086
|
-
market: EthereumAddress,
|
|
1087
|
-
baseToken: EthereumAddress,
|
|
1088
|
-
triggerRepayRatio: number,
|
|
1089
|
-
triggerBoostRatio: number,
|
|
1090
|
-
targetBoostRatio: number,
|
|
1091
|
-
targetRepayRatio: number,
|
|
1092
|
-
boostEnabled: boolean,
|
|
1093
|
-
isEOA: boolean,
|
|
1094
|
-
): SubData {
|
|
1095
|
-
return [
|
|
1096
|
-
market,
|
|
1097
|
-
baseToken,
|
|
1098
|
-
new Dec(triggerRepayRatio).mul(1e16).toString(),
|
|
1099
|
-
new Dec(triggerBoostRatio).mul(1e16).toString(),
|
|
1100
|
-
new Dec(targetBoostRatio).mul(1e16).toString(),
|
|
1101
|
-
new Dec(targetRepayRatio).mul(1e16).toString(),
|
|
1102
|
-
// @ts-ignore // TODO
|
|
1103
|
-
boostEnabled, isEOA,
|
|
1104
|
-
];
|
|
1105
|
-
},
|
|
1106
|
-
decode(subData: SubData): { targetRatio: number } {
|
|
1107
|
-
const weiRatio = AbiCoder.decodeParameter('uint256', subData[3]) as any as string;
|
|
1108
|
-
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
1109
1044
|
|
|
1110
|
-
|
|
1111
|
-
},
|
|
1112
|
-
};
|
|
1113
|
-
export const compoundV3LeverageManagementSubDataWithoutSubProxy = {
|
|
1045
|
+
export const compoundV3LeverageManagementSubData = {
|
|
1114
1046
|
encode(
|
|
1115
1047
|
market: EthereumAddress,
|
|
1116
1048
|
baseToken: EthereumAddress,
|
|
@@ -1134,6 +1066,9 @@ export const compoundV3LeverageManagementSubDataWithoutSubProxy = {
|
|
|
1134
1066
|
};
|
|
1135
1067
|
},
|
|
1136
1068
|
};
|
|
1069
|
+
|
|
1070
|
+
export const compoundV3LiquidationProtectionSubData = compoundV3LeverageManagementSubData;
|
|
1071
|
+
|
|
1137
1072
|
export const compoundV3LeverageManagementOnPriceSubData = {
|
|
1138
1073
|
encode(
|
|
1139
1074
|
market: EthereumAddress,
|
|
@@ -1251,17 +1186,7 @@ export const exchangeDcaSubData = {
|
|
|
1251
1186
|
};
|
|
1252
1187
|
},
|
|
1253
1188
|
};
|
|
1254
|
-
export const
|
|
1255
|
-
encode(fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, targetPrice: string, goodUntil: string | number, orderType: OrderType) : SubData {
|
|
1256
|
-
return [
|
|
1257
|
-
fromToken,
|
|
1258
|
-
toToken,
|
|
1259
|
-
amount,
|
|
1260
|
-
targetPrice,
|
|
1261
|
-
new Dec(goodUntil).toString(),
|
|
1262
|
-
new Dec(orderType).toString(),
|
|
1263
|
-
];
|
|
1264
|
-
},
|
|
1189
|
+
export const legacyExchangeLimitOrderSubData = {
|
|
1265
1190
|
decode: (subData: SubData, chainId: ChainId) => {
|
|
1266
1191
|
const fromToken = AbiCoder.decodeParameter('address', subData[0])!.toString();
|
|
1267
1192
|
const toToken = AbiCoder.decodeParameter('address', subData[1])!.toString();
|
|
@@ -1269,7 +1194,7 @@ export const exchangeLimitOrderSubData = {
|
|
|
1269
1194
|
return { fromToken, toToken, amount };
|
|
1270
1195
|
},
|
|
1271
1196
|
};
|
|
1272
|
-
export const
|
|
1197
|
+
export const exchangeLimitOrderSubData = {
|
|
1273
1198
|
encode(fromToken: EthereumAddress, toToken: EthereumAddress, amount: string): SubData {
|
|
1274
1199
|
return [
|
|
1275
1200
|
AbiCoder.encodeParameter('address', fromToken),
|
|
@@ -1293,7 +1218,7 @@ export const exchangeLimitOrderSubDataWithoutSubProxy = {
|
|
|
1293
1218
|
.----) | | | / _____ \ | |\ \----.| . \
|
|
1294
1219
|
|_______/ | _| /__/ \__\ | _| `._____||__|\__\
|
|
1295
1220
|
*/
|
|
1296
|
-
export const
|
|
1221
|
+
export const legacySparkLeverageManagementSubData = {
|
|
1297
1222
|
decode(subData: SubData): { targetRatio: number } {
|
|
1298
1223
|
const ratioWei = AbiCoder.decodeParameter('uint256', subData[0]) as any as string;
|
|
1299
1224
|
const targetRatio = weiToRatioPercentage(ratioWei);
|
|
@@ -1301,7 +1226,8 @@ export const sparkLeverageManagementSubData = {
|
|
|
1301
1226
|
return { targetRatio };
|
|
1302
1227
|
},
|
|
1303
1228
|
};
|
|
1304
|
-
|
|
1229
|
+
|
|
1230
|
+
export const sparkLeverageManagementSubData = {
|
|
1305
1231
|
encode(
|
|
1306
1232
|
targetRatio: number,
|
|
1307
1233
|
ratioState: RatioState,
|
|
@@ -1320,6 +1246,10 @@ export const sparkLeverageManagementSubDataWithoutSubProxy = {
|
|
|
1320
1246
|
return { targetRatio, ratioState };
|
|
1321
1247
|
},
|
|
1322
1248
|
};
|
|
1249
|
+
|
|
1250
|
+
export const sparkLiquidationProtectionSubData = sparkLeverageManagementSubData;
|
|
1251
|
+
|
|
1252
|
+
|
|
1323
1253
|
export const sparkCloseGenericSubData = {
|
|
1324
1254
|
encode(
|
|
1325
1255
|
collAsset: EthereumAddress,
|
|
@@ -1534,6 +1464,7 @@ export const crvUSDPaybackSubData = {
|
|
|
1534
1464
|
| | | | | `--' | | |\ \----.| | | | | | | `--' |
|
|
1535
1465
|
|__| |__| \______/ | _| `._____|| _| |__| |__| \______/
|
|
1536
1466
|
*/
|
|
1467
|
+
|
|
1537
1468
|
export const morphoBlueLeverageManagementSubData = {
|
|
1538
1469
|
encode: (
|
|
1539
1470
|
loanToken: EthereumAddress,
|
|
@@ -1578,6 +1509,9 @@ export const morphoBlueLeverageManagementSubData = {
|
|
|
1578
1509
|
};
|
|
1579
1510
|
},
|
|
1580
1511
|
};
|
|
1512
|
+
|
|
1513
|
+
export const morphoBlueLiquidationProtectionSubData = morphoBlueLeverageManagementSubData;
|
|
1514
|
+
|
|
1581
1515
|
export const morphoBlueLeverageManagementOnPriceSubData = {
|
|
1582
1516
|
encode(
|
|
1583
1517
|
loanToken: EthereumAddress,
|
|
@@ -1708,3 +1642,5 @@ export const fluidLeverageManagementSubData = {
|
|
|
1708
1642
|
};
|
|
1709
1643
|
},
|
|
1710
1644
|
};
|
|
1645
|
+
|
|
1646
|
+
export const fluidLiquidationProtectionSubData = fluidLeverageManagementSubData;
|
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
compoundV3PriceRangeTrigger,
|
|
33
33
|
aaveV3QuotePriceRangeTrigger,
|
|
34
34
|
morphoBluePriceRangeTrigger,
|
|
35
|
+
morphoBluePriceTrigger,
|
|
35
36
|
sparkQuotePriceTrigger,
|
|
36
37
|
aaveV4RatioTrigger,
|
|
37
38
|
aaveV4QuotePriceTrigger,
|
|
@@ -1287,6 +1288,74 @@ describe('Feature: triggerService.ts', () => {
|
|
|
1287
1288
|
});
|
|
1288
1289
|
});
|
|
1289
1290
|
});
|
|
1291
|
+
|
|
1292
|
+
describe('When testing triggerService.morphoBluePriceTrigger', () => {
|
|
1293
|
+
describe('encode()', () => {
|
|
1294
|
+
const examples: Array<[[string], [oracle: EthereumAddress, collateralToken: EthereumAddress, loanToken: EthereumAddress, price: number, priceState: RatioState]]> = [
|
|
1295
|
+
[
|
|
1296
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1297
|
+
[
|
|
1298
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1299
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1300
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1301
|
+
2500,
|
|
1302
|
+
RatioState.UNDER,
|
|
1303
|
+
],
|
|
1304
|
+
],
|
|
1305
|
+
[
|
|
1306
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000005d21dba0000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1307
|
+
[
|
|
1308
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1309
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1310
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1311
|
+
4000,
|
|
1312
|
+
RatioState.OVER,
|
|
1313
|
+
],
|
|
1314
|
+
],
|
|
1315
|
+
];
|
|
1316
|
+
|
|
1317
|
+
examples.forEach(([expected, actual]) => {
|
|
1318
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1319
|
+
expect(morphoBluePriceTrigger.encode(...actual)).to.eql(expected);
|
|
1320
|
+
});
|
|
1321
|
+
});
|
|
1322
|
+
});
|
|
1323
|
+
|
|
1324
|
+
describe('decode()', () => {
|
|
1325
|
+
const examples: Array<[
|
|
1326
|
+
{ oracle: EthereumAddress, collateralToken: EthereumAddress, loanToken: EthereumAddress, price: string, priceState: RatioState },
|
|
1327
|
+
TriggerData,
|
|
1328
|
+
]> = [
|
|
1329
|
+
[
|
|
1330
|
+
{
|
|
1331
|
+
oracle: web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1332
|
+
collateralToken: web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1333
|
+
loanToken: web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1334
|
+
price: '2500',
|
|
1335
|
+
priceState: RatioState.UNDER,
|
|
1336
|
+
},
|
|
1337
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1338
|
+
],
|
|
1339
|
+
[
|
|
1340
|
+
{
|
|
1341
|
+
oracle: web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1342
|
+
collateralToken: web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1343
|
+
loanToken: web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1344
|
+
price: '4000',
|
|
1345
|
+
priceState: RatioState.OVER,
|
|
1346
|
+
},
|
|
1347
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000005d21dba0000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1348
|
+
],
|
|
1349
|
+
];
|
|
1350
|
+
|
|
1351
|
+
examples.forEach(([expected, actual]) => {
|
|
1352
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1353
|
+
expect(morphoBluePriceTrigger.decode(actual)).to.eql(expected);
|
|
1354
|
+
});
|
|
1355
|
+
});
|
|
1356
|
+
});
|
|
1357
|
+
});
|
|
1358
|
+
|
|
1290
1359
|
describe('When testing triggerService.aaveV4RatioTrigger', () => {
|
|
1291
1360
|
describe('encode()', () => {
|
|
1292
1361
|
const examples: Array<[[string], [owner: EthereumAddress, spoke: EthereumAddress, ratioPercentage: number, ratioState: RatioState]]> = [
|
|
@@ -2,7 +2,7 @@ import { expect } from 'chai';
|
|
|
2
2
|
import { getAssetInfo } from '@defisaver/tokens';
|
|
3
3
|
|
|
4
4
|
import type { EthereumAddress } from '../types';
|
|
5
|
-
import { ChainId, ProtocolIdentifiers, RatioState } from '../types/enums';
|
|
5
|
+
import { Bundles, ChainId, ProtocolIdentifiers, RatioState } from '../types/enums';
|
|
6
6
|
|
|
7
7
|
import '../configuration';
|
|
8
8
|
import {
|
package/src/services/utils.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { getAssetInfo, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
|
5
5
|
|
|
6
6
|
import type { EthereumAddress } from '../types';
|
|
7
7
|
import {
|
|
8
|
+
Bundles,
|
|
8
9
|
ChainId, CloseStrategyType, CloseToAssetType, RatioState,
|
|
9
10
|
} from '../types/enums';
|
|
10
11
|
|
|
@@ -171,4 +172,17 @@ export function getStopLossAndTakeProfitTypeByCloseStrategyType(
|
|
|
171
172
|
default:
|
|
172
173
|
throw new Error('CloseStrategyType not supported');
|
|
173
174
|
}
|
|
174
|
-
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export function getBundleIdsByNetwork(network: ChainId) {
|
|
178
|
+
switch (Number(network)) {
|
|
179
|
+
case ChainId.Ethereum:
|
|
180
|
+
return Bundles.MainnetIds;
|
|
181
|
+
case ChainId.Arbitrum:
|
|
182
|
+
return Bundles.ArbitrumIds;
|
|
183
|
+
case ChainId.Base:
|
|
184
|
+
return Bundles.BaseIds;
|
|
185
|
+
default:
|
|
186
|
+
throw new Error(`Unsupported network ${network}`);
|
|
187
|
+
}
|
|
188
|
+
}
|
package/src/types/enums.ts
CHANGED
|
@@ -153,6 +153,8 @@ export namespace Strategies {
|
|
|
153
153
|
EoaRepayOnPrice = 'eoa-repay-on-price',
|
|
154
154
|
CollateralSwitch = 'collateral-switch',
|
|
155
155
|
EoaCollateralSwitch = 'eoa-collateral-switch',
|
|
156
|
+
LiquidationProtection = 'liquidation-protection',
|
|
157
|
+
EoaLiquidationProtection = 'liquidation-protection-eoa',
|
|
156
158
|
}
|
|
157
159
|
export enum IdOverrides {
|
|
158
160
|
TakeProfit = 'take-profit',
|
|
@@ -164,6 +166,8 @@ export namespace Strategies {
|
|
|
164
166
|
EoaLeverageManagement = 'leverage-management-eoa',
|
|
165
167
|
LeverageManagementOnPrice = 'leverage-management-on-price',
|
|
166
168
|
EoaLeverageManagementOnPrice = 'leverage-management-on-price-eoa',
|
|
169
|
+
LiquidationProtection = 'liquidation-protection',
|
|
170
|
+
EoaLiquidationProtection = 'liquidation-protection-eoa',
|
|
167
171
|
}
|
|
168
172
|
}
|
|
169
173
|
|
|
@@ -240,6 +244,18 @@ export namespace Bundles {
|
|
|
240
244
|
AAVE_V4_EOA_REPAY_ON_PRICE = 68,
|
|
241
245
|
AAVE_V4_EOA_BOOST_ON_PRICE = 69,
|
|
242
246
|
AAVE_V4_EOA_CLOSE = 70,
|
|
247
|
+
AAVE_V3_SW_LIQUIDATION_PROTECTION = 71,
|
|
248
|
+
SPARK_SW_LIQUIDATION_PROTECTION = 72,
|
|
249
|
+
MAKER_SW_LIQUIDATION_PROTECTION = 75,
|
|
250
|
+
FLUID_T1_SW_LIQUIDATION_PROTECTION = 76,
|
|
251
|
+
AAVE_V4_SW_LIQUIDATION_PROTECTION = 77,
|
|
252
|
+
MORPHO_BLUE_SW_LIQUIDATION_PROTECTION = 78,
|
|
253
|
+
AAVE_V3_EOA_LIQUIDATION_PROTECTION = 79,
|
|
254
|
+
AAVE_V4_EOA_LIQUIDATION_PROTECTION = 80,
|
|
255
|
+
MORPHO_BLUE_EOA_LIQUIDATION_PROTECTION = 81,
|
|
256
|
+
COMP_V3_SW_LIQUIDATION_PROTECTION = 82,
|
|
257
|
+
COMP_V3_EOA_LIQUIDATION_PROTECTION = 83,
|
|
258
|
+
MORPHO_BLUE_REPAY_ON_PRICE = 84,
|
|
243
259
|
}
|
|
244
260
|
|
|
245
261
|
export enum OptimismIds {
|
|
@@ -254,6 +270,8 @@ export namespace Bundles {
|
|
|
254
270
|
AAVE_V3_EOA_REPAY_ON_PRICE = 8,
|
|
255
271
|
AAVE_V3_EOA_BOOST_ON_PRICE = 9,
|
|
256
272
|
AAVE_V3_EOA_CLOSE = 10,
|
|
273
|
+
AAVE_V3_SW_LIQUIDATION_PROTECTION = 11,
|
|
274
|
+
AAVE_V3_EOA_LIQUIDATION_PROTECTION = 12,
|
|
257
275
|
}
|
|
258
276
|
|
|
259
277
|
export enum BaseIds {
|
|
@@ -284,6 +302,13 @@ export namespace Bundles {
|
|
|
284
302
|
AAVE_V3_EOA_BOOST_ON_PRICE = 26,
|
|
285
303
|
AAVE_V3_EOA_CLOSE = 27,
|
|
286
304
|
MORPHO_BLUE_CLOSE = 28,
|
|
305
|
+
AAVE_V3_SW_LIQUIDATION_PROTECTION = 29,
|
|
306
|
+
FLUID_T1_SW_LIQUIDATION_PROTECTION = 30,
|
|
307
|
+
COMP_V3_SW_LIQUIDATION_PROTECTION = 32,
|
|
308
|
+
COMP_V3_EOA_LIQUIDATION_PROTECTION = 33,
|
|
309
|
+
AAVE_V3_EOA_LIQUIDATION_PROTECTION = 34,
|
|
310
|
+
MORPHO_BLUE_SW_LIQUIDATION_PROTECTION = 35,
|
|
311
|
+
MORPHO_BLUE_REPAY_ON_PRICE = 36,
|
|
287
312
|
}
|
|
288
313
|
|
|
289
314
|
export enum ArbitrumIds {
|
|
@@ -316,7 +341,13 @@ export namespace Bundles {
|
|
|
316
341
|
MORPHO_BLUE_EOA_REPAY = 26,
|
|
317
342
|
MORPHO_BLUE_EOA_BOOST = 27,
|
|
318
343
|
MORPHO_BLUE_CLOSE = 28,
|
|
344
|
+
AAVE_V3_SW_LIQUIDATION_PROTECTION = 29,
|
|
345
|
+
FLUID_T1_SW_LIQUIDATION_PROTECTION = 30,
|
|
346
|
+
MORPHO_BLUE_SW_LIQUIDATION_PROTECTION = 31,
|
|
347
|
+
COMP_V3_SW_LIQUIDATION_PROTECTION = 32,
|
|
348
|
+
COMP_V3_EOA_LIQUIDATION_PROTECTION = 33,
|
|
349
|
+
AAVE_V3_EOA_LIQUIDATION_PROTECTION = 34,
|
|
350
|
+
MORPHO_BLUE_EOA_LIQUIDATION_PROTECTION = 35,
|
|
351
|
+
MORPHO_BLUE_REPAY_ON_PRICE = 36,
|
|
319
352
|
}
|
|
320
353
|
}
|
|
321
|
-
|
|
322
|
-
|