@defisaver/automation-sdk 3.3.15-liq-prot-2-dev → 3.3.15-liq-prot-3-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/index.d.ts +1 -2
- package/cjs/index.js +0 -1
- package/cjs/services/strategiesService.js +10 -10
- package/cjs/services/strategySubService.d.ts +9 -15
- package/cjs/services/strategySubService.js +20 -30
- package/cjs/services/strategySubService.test.js +2 -40
- package/cjs/services/subDataService.d.ts +18 -23
- package/cjs/services/subDataService.js +23 -225
- package/cjs/services/subDataService.test.js +17 -134
- package/cjs/services/utils.d.ts +0 -1
- package/cjs/services/utils.js +1 -21
- package/cjs/services/utils.test.js +0 -25
- package/esm/index.d.ts +1 -2
- package/esm/index.js +1 -2
- package/esm/services/strategiesService.js +10 -10
- package/esm/services/strategySubService.d.ts +9 -15
- package/esm/services/strategySubService.js +19 -29
- package/esm/services/strategySubService.test.js +3 -38
- package/esm/services/subDataService.d.ts +18 -23
- package/esm/services/subDataService.js +22 -224
- package/esm/services/subDataService.test.js +18 -132
- package/esm/services/utils.d.ts +0 -1
- package/esm/services/utils.js +0 -19
- package/esm/services/utils.test.js +2 -27
- package/package.json +1 -1
- package/src/index.ts +0 -2
- package/src/services/strategiesService.ts +10 -10
- package/src/services/strategySubService.test.ts +2 -46
- package/src/services/strategySubService.ts +19 -36
- package/src/services/subDataService.test.ts +18 -142
- package/src/services/subDataService.ts +23 -294
- package/src/services/utils.test.ts +0 -31
- package/src/services/utils.ts +0 -17
|
@@ -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;
|
|
@@ -165,9 +145,7 @@ export const makerLeverageManagementSubData = {
|
|
|
165
145
|
},
|
|
166
146
|
};
|
|
167
147
|
|
|
168
|
-
|
|
169
|
-
// ! Double check before changing
|
|
170
|
-
export const makerLeverageManagementWithoutSubProxy = {
|
|
148
|
+
export const makerLeverageManagementSubData = {
|
|
171
149
|
encode(
|
|
172
150
|
vaultId: number,
|
|
173
151
|
targetRatio: number,
|
|
@@ -187,26 +165,7 @@ export const makerLeverageManagementWithoutSubProxy = {
|
|
|
187
165
|
},
|
|
188
166
|
};
|
|
189
167
|
|
|
190
|
-
export const makerLiquidationProtectionSubData =
|
|
191
|
-
encode(
|
|
192
|
-
vaultId: number,
|
|
193
|
-
targetRatio: number,
|
|
194
|
-
daiAddr?: EthereumAddress,
|
|
195
|
-
): SubData {
|
|
196
|
-
const encodedVaultId = AbiCoder.encodeParameter('uint256', vaultId);
|
|
197
|
-
const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
198
|
-
const encodedDaiAddr = AbiCoder.encodeParameter('address', daiAddr || getAssetInfo('DAI', 1).address);
|
|
199
|
-
|
|
200
|
-
return [encodedVaultId, encodedTargetRatio, encodedDaiAddr];
|
|
201
|
-
},
|
|
202
|
-
decode(subData: SubData): { vaultId: number, targetRatio: number, daiAddr: string } {
|
|
203
|
-
const vaultId = +AbiCoder.decodeParameter('uint256', subData[0])!.toString();
|
|
204
|
-
const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[1]) as any as string);
|
|
205
|
-
const daiAddr = AbiCoder.decodeParameter('address', subData[2])!.toString();
|
|
206
|
-
|
|
207
|
-
return { vaultId, targetRatio, daiAddr };
|
|
208
|
-
},
|
|
209
|
-
};
|
|
168
|
+
export const makerLiquidationProtectionSubData = makerLeverageManagementSubData;
|
|
210
169
|
|
|
211
170
|
|
|
212
171
|
/**
|
|
@@ -225,14 +184,14 @@ export const liquityRepayFromSavingsSubData = {
|
|
|
225
184
|
return { targetRatio };
|
|
226
185
|
},
|
|
227
186
|
};
|
|
228
|
-
export const
|
|
187
|
+
export const legacyLiquityLeverageManagementSubData = {
|
|
229
188
|
decode: (subData:SubData) => {
|
|
230
189
|
const weiRatio = AbiCoder.decodeParameter('uint256', subData[1]) as any as string;
|
|
231
190
|
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
232
191
|
return { targetRatio };
|
|
233
192
|
},
|
|
234
193
|
};
|
|
235
|
-
export const
|
|
194
|
+
export const liquityLeverageManagementSubData = {
|
|
236
195
|
encode(
|
|
237
196
|
targetRatio: number,
|
|
238
197
|
ratioState: RatioState,
|
|
@@ -535,23 +494,7 @@ export const liquityV2PaybackSubData = {
|
|
|
535
494
|
/ _____ \ / _____ \ \ / | |____ \ / / /_
|
|
536
495
|
/__/ \__\ /__/ \__\ \__/ |_______| \__/ |____|
|
|
537
496
|
*/
|
|
538
|
-
export const
|
|
539
|
-
encode(
|
|
540
|
-
triggerRepayRatio: number,
|
|
541
|
-
triggerBoostRatio: number,
|
|
542
|
-
targetBoostRatio: number,
|
|
543
|
-
targetRepayRatio: number,
|
|
544
|
-
boostEnabled: boolean,
|
|
545
|
-
): SubData {
|
|
546
|
-
return [
|
|
547
|
-
new Dec(triggerRepayRatio).mul(1e16).toString(),
|
|
548
|
-
new Dec(triggerBoostRatio).mul(1e16).toString(),
|
|
549
|
-
new Dec(targetBoostRatio).mul(1e16).toString(),
|
|
550
|
-
new Dec(targetRepayRatio).mul(1e16).toString(),
|
|
551
|
-
// @ts-ignore // TODO
|
|
552
|
-
boostEnabled,
|
|
553
|
-
];
|
|
554
|
-
},
|
|
497
|
+
export const legacyAaveV2LeverageManagementSubData = {
|
|
555
498
|
decode(subData: SubData): { targetRatio: number } {
|
|
556
499
|
const ratioWei = AbiCoder.decodeParameter('uint256', subData[1]) as any as string;
|
|
557
500
|
const targetRatio = weiToRatioPercentage(ratioWei);
|
|
@@ -559,7 +502,7 @@ export const aaveV2LeverageManagementSubData = {
|
|
|
559
502
|
return { targetRatio };
|
|
560
503
|
},
|
|
561
504
|
};
|
|
562
|
-
export const
|
|
505
|
+
export const aaveV2LeverageManagementSubData = {
|
|
563
506
|
encode(
|
|
564
507
|
market: EthereumAddress,
|
|
565
508
|
targetRatio: number,
|
|
@@ -595,7 +538,7 @@ export const aaveV2LeverageManagementSubDataWithoutSubProxy = {
|
|
|
595
538
|
/ _____ \ / _____ \ \ / | |____ \ / ___) |
|
|
596
539
|
/__/ \__\ /__/ \__\ \__/ |_______| \__/ |____/
|
|
597
540
|
*/
|
|
598
|
-
export const
|
|
541
|
+
export const legacyAaveV3LeverageManagementSubData = {
|
|
599
542
|
decode(subData: SubData): { targetRatio: number } {
|
|
600
543
|
const ratioWei = AbiCoder.decodeParameter('uint256', subData[0]) as any as string;
|
|
601
544
|
const targetRatio = weiToRatioPercentage(ratioWei);
|
|
@@ -604,9 +547,7 @@ export const aaveV3LeverageManagementSubData = {
|
|
|
604
547
|
},
|
|
605
548
|
};
|
|
606
549
|
|
|
607
|
-
|
|
608
|
-
// ! Double check before changing. Liquidation protection is using Generic encoding for both - EOA and SW
|
|
609
|
-
export const aaveV3LeverageManagementSubDataWithoutSubProxy = {
|
|
550
|
+
export const aaveV3LeverageManagementSubData = {
|
|
610
551
|
encode(
|
|
611
552
|
targetRatio: number,
|
|
612
553
|
ratioState: RatioState,
|
|
@@ -634,28 +575,7 @@ export const aaveV3LeverageManagementSubDataWithoutSubProxy = {
|
|
|
634
575
|
},
|
|
635
576
|
};
|
|
636
577
|
|
|
637
|
-
export const aaveV3LiquidationProtectionSubData =
|
|
638
|
-
encode(
|
|
639
|
-
targetRatio: number,
|
|
640
|
-
ratioState: RatioState,
|
|
641
|
-
market: EthereumAddress,
|
|
642
|
-
user: EthereumAddress,
|
|
643
|
-
): SubData {
|
|
644
|
-
const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
645
|
-
const encodedRatioState = AbiCoder.encodeParameter('uint8', ratioState);
|
|
646
|
-
const encodedMarket = AbiCoder.encodeParameter('address', market);
|
|
647
|
-
const encodedUser = AbiCoder.encodeParameter('address', user);
|
|
648
|
-
|
|
649
|
-
return [encodedTargetRatio, encodedRatioState, encodedMarket, encodedUser];
|
|
650
|
-
},
|
|
651
|
-
decode(subData: SubData): { targetRatio: number, ratioState: RatioState } {
|
|
652
|
-
const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[0]) as any as string);
|
|
653
|
-
const ratioState = AbiCoder.decodeParameter('uint8', subData[1]) as any as RatioState;
|
|
654
|
-
|
|
655
|
-
return { targetRatio, ratioState };
|
|
656
|
-
},
|
|
657
|
-
};
|
|
658
|
-
|
|
578
|
+
export const aaveV3LiquidationProtectionSubData = aaveV3LeverageManagementSubData;
|
|
659
579
|
|
|
660
580
|
export const aaveV3LeverageManagementOnPriceGeneric = {
|
|
661
581
|
encode(
|
|
@@ -904,8 +824,6 @@ export const aaveV3LeverageManagementOnPriceSubData = {
|
|
|
904
824
|
/__/ \__\ /__/ \__\ \__/ |_______| \__/ |_|
|
|
905
825
|
*/
|
|
906
826
|
|
|
907
|
-
// ! Any change here will PROBABLY require a change in aaveV4LiquidationProtectionSubData as well, since it is copy paste
|
|
908
|
-
// ! Double check before changing
|
|
909
827
|
export const aaveV4LeverageManagementSubData = {
|
|
910
828
|
encode: (
|
|
911
829
|
spoke: EthereumAddress,
|
|
@@ -938,37 +856,7 @@ export const aaveV4LeverageManagementSubData = {
|
|
|
938
856
|
},
|
|
939
857
|
};
|
|
940
858
|
|
|
941
|
-
export const aaveV4LiquidationProtectionSubData =
|
|
942
|
-
encode: (
|
|
943
|
-
spoke: EthereumAddress,
|
|
944
|
-
owner: EthereumAddress,
|
|
945
|
-
ratioState: RatioState,
|
|
946
|
-
targetRatio: number,
|
|
947
|
-
) => {
|
|
948
|
-
const spokeEncoded = AbiCoder.encodeParameter('address', spoke);
|
|
949
|
-
const ownerEncoded = AbiCoder.encodeParameter('address', owner);
|
|
950
|
-
const ratioStateEncoded = AbiCoder.encodeParameter('uint8', ratioState);
|
|
951
|
-
const targetRatioEncoded = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
952
|
-
// Add two empty slots for future addons (e.g tsi or slippage settings)
|
|
953
|
-
return [
|
|
954
|
-
spokeEncoded,
|
|
955
|
-
ownerEncoded,
|
|
956
|
-
ratioStateEncoded,
|
|
957
|
-
targetRatioEncoded,
|
|
958
|
-
EMPTY_SLOT,
|
|
959
|
-
EMPTY_SLOT,
|
|
960
|
-
];
|
|
961
|
-
},
|
|
962
|
-
decode: (subData: SubData) => {
|
|
963
|
-
const spoke = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
|
|
964
|
-
const owner = AbiCoder.decodeParameter('address', subData[1]) as unknown as EthereumAddress;
|
|
965
|
-
const ratioState = Number(AbiCoder.decodeParameter('uint8', subData[2])) as RatioState;
|
|
966
|
-
const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[3]) as any as string);
|
|
967
|
-
return {
|
|
968
|
-
spoke, owner, ratioState, targetRatio,
|
|
969
|
-
};
|
|
970
|
-
},
|
|
971
|
-
};
|
|
859
|
+
export const aaveV4LiquidationProtectionSubData = aaveV4LeverageManagementSubData;
|
|
972
860
|
|
|
973
861
|
export const aaveV4LeverageManagementOnPriceSubData = {
|
|
974
862
|
encode: (
|
|
@@ -1112,23 +1000,7 @@ export const aaveV4CollateralSwitchSubData = {
|
|
|
1112
1000
|
| `----.| `--' | | | | | | | \ / / /_
|
|
1113
1001
|
\______| \______/ |__| |__| | _| \__/ |____|
|
|
1114
1002
|
*/
|
|
1115
|
-
export const
|
|
1116
|
-
encode(
|
|
1117
|
-
triggerRepayRatio: number,
|
|
1118
|
-
triggerBoostRatio: number,
|
|
1119
|
-
targetBoostRatio: number,
|
|
1120
|
-
targetRepayRatio: number,
|
|
1121
|
-
boostEnabled: boolean,
|
|
1122
|
-
): SubData {
|
|
1123
|
-
return [
|
|
1124
|
-
new Dec(triggerRepayRatio).mul(1e16).toString(),
|
|
1125
|
-
new Dec(triggerBoostRatio).mul(1e16).toString(),
|
|
1126
|
-
new Dec(targetBoostRatio).mul(1e16).toString(),
|
|
1127
|
-
new Dec(targetRepayRatio).mul(1e16).toString(),
|
|
1128
|
-
// @ts-ignore // TODO
|
|
1129
|
-
boostEnabled,
|
|
1130
|
-
];
|
|
1131
|
-
},
|
|
1003
|
+
export const legacyCompoundV2LeverageManagementSubData = {
|
|
1132
1004
|
decode(subData: SubData): { targetRatio: number } {
|
|
1133
1005
|
const weiRatio = AbiCoder.decodeParameter('uint256', subData[0]) as any as string;
|
|
1134
1006
|
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
@@ -1136,7 +1008,7 @@ export const compoundV2LeverageManagementSubData = {
|
|
|
1136
1008
|
return { targetRatio };
|
|
1137
1009
|
},
|
|
1138
1010
|
};
|
|
1139
|
-
export const
|
|
1011
|
+
export const compoundV2LeverageManagementSubData = {
|
|
1140
1012
|
encode(
|
|
1141
1013
|
targetRatio: number,
|
|
1142
1014
|
ratioState: RatioState,
|
|
@@ -1170,9 +1042,7 @@ export const compoundV2LeverageManagementSubDataWithoutSubProxy = {
|
|
|
1170
1042
|
\______| \______/ |__| |__| | _| \__/ |____/
|
|
1171
1043
|
*/
|
|
1172
1044
|
|
|
1173
|
-
|
|
1174
|
-
// ! Double check before changing
|
|
1175
|
-
export const compoundV3LeverageManagementSubDataWithoutSubProxy = {
|
|
1045
|
+
export const compoundV3LeverageManagementSubData = {
|
|
1176
1046
|
encode(
|
|
1177
1047
|
market: EthereumAddress,
|
|
1178
1048
|
baseToken: EthereumAddress,
|
|
@@ -1197,30 +1067,7 @@ export const compoundV3LeverageManagementSubDataWithoutSubProxy = {
|
|
|
1197
1067
|
},
|
|
1198
1068
|
};
|
|
1199
1069
|
|
|
1200
|
-
export const
|
|
1201
|
-
encode(
|
|
1202
|
-
market: EthereumAddress,
|
|
1203
|
-
baseToken: EthereumAddress,
|
|
1204
|
-
targetRatio: number,
|
|
1205
|
-
ratioState: RatioState,
|
|
1206
|
-
): SubData {
|
|
1207
|
-
const encodedMarket = AbiCoder.encodeParameter('address', market);
|
|
1208
|
-
const encodedBaseToken = AbiCoder.encodeParameter('address', baseToken);
|
|
1209
|
-
const encodedRatioState = AbiCoder.encodeParameter('uint8', ratioState);
|
|
1210
|
-
const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
1211
|
-
return [encodedMarket, encodedBaseToken, encodedRatioState, encodedTargetRatio];
|
|
1212
|
-
},
|
|
1213
|
-
decode(subData: SubData): { market: EthereumAddress, baseToken: EthereumAddress, targetRatio: number, ratioState: RatioState } {
|
|
1214
|
-
const market = AbiCoder.decodeParameter('address', subData[0]) as any as EthereumAddress;
|
|
1215
|
-
const baseToken = AbiCoder.decodeParameter('address', subData[1]) as any as EthereumAddress;
|
|
1216
|
-
const ratioState = AbiCoder.decodeParameter('uint8', subData[2]) as any as RatioState;
|
|
1217
|
-
const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[3]) as any as string);
|
|
1218
|
-
|
|
1219
|
-
return {
|
|
1220
|
-
market, baseToken, targetRatio, ratioState,
|
|
1221
|
-
};
|
|
1222
|
-
},
|
|
1223
|
-
};
|
|
1070
|
+
export const compoundV3LiquidationProtectionSubData = compoundV3LeverageManagementSubData;
|
|
1224
1071
|
|
|
1225
1072
|
export const compoundV3LeverageManagementOnPriceSubData = {
|
|
1226
1073
|
encode(
|
|
@@ -1339,17 +1186,7 @@ export const exchangeDcaSubData = {
|
|
|
1339
1186
|
};
|
|
1340
1187
|
},
|
|
1341
1188
|
};
|
|
1342
|
-
export const
|
|
1343
|
-
encode(fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, targetPrice: string, goodUntil: string | number, orderType: OrderType) : SubData {
|
|
1344
|
-
return [
|
|
1345
|
-
fromToken,
|
|
1346
|
-
toToken,
|
|
1347
|
-
amount,
|
|
1348
|
-
targetPrice,
|
|
1349
|
-
new Dec(goodUntil).toString(),
|
|
1350
|
-
new Dec(orderType).toString(),
|
|
1351
|
-
];
|
|
1352
|
-
},
|
|
1189
|
+
export const legacyExchangeLimitOrderSubData = {
|
|
1353
1190
|
decode: (subData: SubData, chainId: ChainId) => {
|
|
1354
1191
|
const fromToken = AbiCoder.decodeParameter('address', subData[0])!.toString();
|
|
1355
1192
|
const toToken = AbiCoder.decodeParameter('address', subData[1])!.toString();
|
|
@@ -1357,7 +1194,7 @@ export const exchangeLimitOrderSubData = {
|
|
|
1357
1194
|
return { fromToken, toToken, amount };
|
|
1358
1195
|
},
|
|
1359
1196
|
};
|
|
1360
|
-
export const
|
|
1197
|
+
export const exchangeLimitOrderSubData = {
|
|
1361
1198
|
encode(fromToken: EthereumAddress, toToken: EthereumAddress, amount: string): SubData {
|
|
1362
1199
|
return [
|
|
1363
1200
|
AbiCoder.encodeParameter('address', fromToken),
|
|
@@ -1381,7 +1218,7 @@ export const exchangeLimitOrderSubDataWithoutSubProxy = {
|
|
|
1381
1218
|
.----) | | | / _____ \ | |\ \----.| . \
|
|
1382
1219
|
|_______/ | _| /__/ \__\ | _| `._____||__|\__\
|
|
1383
1220
|
*/
|
|
1384
|
-
export const
|
|
1221
|
+
export const legacySparkLeverageManagementSubData = {
|
|
1385
1222
|
decode(subData: SubData): { targetRatio: number } {
|
|
1386
1223
|
const ratioWei = AbiCoder.decodeParameter('uint256', subData[0]) as any as string;
|
|
1387
1224
|
const targetRatio = weiToRatioPercentage(ratioWei);
|
|
@@ -1390,9 +1227,7 @@ export const sparkLeverageManagementSubData = {
|
|
|
1390
1227
|
},
|
|
1391
1228
|
};
|
|
1392
1229
|
|
|
1393
|
-
|
|
1394
|
-
// ! Double check before changing
|
|
1395
|
-
export const sparkLeverageManagementSubDataWithoutSubProxy = {
|
|
1230
|
+
export const sparkLeverageManagementSubData = {
|
|
1396
1231
|
encode(
|
|
1397
1232
|
targetRatio: number,
|
|
1398
1233
|
ratioState: RatioState,
|
|
@@ -1412,25 +1247,7 @@ export const sparkLeverageManagementSubDataWithoutSubProxy = {
|
|
|
1412
1247
|
},
|
|
1413
1248
|
};
|
|
1414
1249
|
|
|
1415
|
-
export const sparkLiquidationProtectionSubData =
|
|
1416
|
-
encode(
|
|
1417
|
-
targetRatio: number,
|
|
1418
|
-
ratioState: RatioState,
|
|
1419
|
-
): SubData {
|
|
1420
|
-
const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
1421
|
-
const encodedRatioState = AbiCoder.encodeParameter('uint8', ratioState);
|
|
1422
|
-
const encodedUseDefaultMarket = AbiCoder.encodeParameter('bool', true);
|
|
1423
|
-
const encodedUseOnBehalf = AbiCoder.encodeParameter('bool', false);
|
|
1424
|
-
|
|
1425
|
-
return [encodedTargetRatio, encodedRatioState, encodedUseDefaultMarket, encodedUseOnBehalf];
|
|
1426
|
-
},
|
|
1427
|
-
decode(subData: SubData): { targetRatio: number, ratioState: RatioState } {
|
|
1428
|
-
const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[0]) as any as string);
|
|
1429
|
-
const ratioState = AbiCoder.decodeParameter('uint8', subData[1]) as any as RatioState;
|
|
1430
|
-
|
|
1431
|
-
return { targetRatio, ratioState };
|
|
1432
|
-
},
|
|
1433
|
-
};
|
|
1250
|
+
export const sparkLiquidationProtectionSubData = sparkLeverageManagementSubData;
|
|
1434
1251
|
|
|
1435
1252
|
|
|
1436
1253
|
export const sparkCloseGenericSubData = {
|
|
@@ -1648,8 +1465,6 @@ export const crvUSDPaybackSubData = {
|
|
|
1648
1465
|
|__| |__| \______/ | _| `._____|| _| |__| |__| \______/
|
|
1649
1466
|
*/
|
|
1650
1467
|
|
|
1651
|
-
// ! Any change here will PROBABLY require a change in morphoBlueLiquidationProtectionSubData as well, since it is copy paste
|
|
1652
|
-
// ! Double check before changing
|
|
1653
1468
|
export const morphoBlueLeverageManagementSubData = {
|
|
1654
1469
|
encode: (
|
|
1655
1470
|
loanToken: EthereumAddress,
|
|
@@ -1695,51 +1510,7 @@ export const morphoBlueLeverageManagementSubData = {
|
|
|
1695
1510
|
},
|
|
1696
1511
|
};
|
|
1697
1512
|
|
|
1698
|
-
export const morphoBlueLiquidationProtectionSubData =
|
|
1699
|
-
encode: (
|
|
1700
|
-
loanToken: EthereumAddress,
|
|
1701
|
-
collToken: EthereumAddress,
|
|
1702
|
-
oracle: EthereumAddress,
|
|
1703
|
-
irm: EthereumAddress,
|
|
1704
|
-
lltv: string,
|
|
1705
|
-
ratioState: RatioState,
|
|
1706
|
-
targetRatio: number,
|
|
1707
|
-
user: EthereumAddress,
|
|
1708
|
-
isEOA: boolean,
|
|
1709
|
-
) => {
|
|
1710
|
-
const loanTokenEncoded = AbiCoder.encodeParameter('address', loanToken);
|
|
1711
|
-
const collTokenEncoded = AbiCoder.encodeParameter('address', collToken);
|
|
1712
|
-
const oracleEncoded = AbiCoder.encodeParameter('address', oracle);
|
|
1713
|
-
const irmEncoded = AbiCoder.encodeParameter('address', irm);
|
|
1714
|
-
const lltvEncoded = AbiCoder.encodeParameter('uint256', lltv);
|
|
1715
|
-
const ratioStateEncoded = AbiCoder.encodeParameter('uint8', ratioState);
|
|
1716
|
-
const targetRatioEncoded = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
1717
|
-
const userEncoded = AbiCoder.encodeParameter('address', user);
|
|
1718
|
-
const isEOAEncoded = AbiCoder.encodeParameter('bool', isEOA);
|
|
1719
|
-
return [loanTokenEncoded, collTokenEncoded, oracleEncoded, irmEncoded, lltvEncoded, ratioStateEncoded, targetRatioEncoded, userEncoded, isEOAEncoded];
|
|
1720
|
-
},
|
|
1721
|
-
decode: (subData: SubData) => {
|
|
1722
|
-
const loanToken = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
|
|
1723
|
-
const collToken = AbiCoder.decodeParameter('address', subData[1]) as any as EthereumAddress;
|
|
1724
|
-
const oracle = AbiCoder.decodeParameter('address', subData[2]) as any as EthereumAddress;
|
|
1725
|
-
const irm = AbiCoder.decodeParameter('address', subData[3]) as any as EthereumAddress;
|
|
1726
|
-
const lltv = AbiCoder.decodeParameter('uint256', subData[4]) as any as EthereumAddress;
|
|
1727
|
-
const weiRatio = AbiCoder.decodeParameter('uint256', subData[6]) as any as EthereumAddress;
|
|
1728
|
-
const user = AbiCoder.decodeParameter('address', subData[7]) as any as EthereumAddress;
|
|
1729
|
-
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
1730
|
-
|
|
1731
|
-
return {
|
|
1732
|
-
loanToken,
|
|
1733
|
-
collToken,
|
|
1734
|
-
oracle,
|
|
1735
|
-
irm,
|
|
1736
|
-
lltv,
|
|
1737
|
-
user,
|
|
1738
|
-
targetRatio,
|
|
1739
|
-
};
|
|
1740
|
-
},
|
|
1741
|
-
};
|
|
1742
|
-
|
|
1513
|
+
export const morphoBlueLiquidationProtectionSubData = morphoBlueLeverageManagementSubData;
|
|
1743
1514
|
|
|
1744
1515
|
export const morphoBlueLeverageManagementOnPriceSubData = {
|
|
1745
1516
|
encode(
|
|
@@ -1829,8 +1600,6 @@ _______ __ __ __ __ _______
|
|
|
1829
1600
|
| | | `----.| `--' | | | | '--' |
|
|
1830
1601
|
|__| |_______| \______/ |__| |_______/
|
|
1831
1602
|
*/
|
|
1832
|
-
// ! Any change here will PROBABLY require a change in fluidLeverageManagementSubData as well, since it is copy paste
|
|
1833
|
-
// ! Double check before changing
|
|
1834
1603
|
export const fluidLeverageManagementSubData = {
|
|
1835
1604
|
encode: (
|
|
1836
1605
|
nftId: string,
|
|
@@ -1874,44 +1643,4 @@ export const fluidLeverageManagementSubData = {
|
|
|
1874
1643
|
},
|
|
1875
1644
|
};
|
|
1876
1645
|
|
|
1877
|
-
export const fluidLiquidationProtectionSubData =
|
|
1878
|
-
encode: (
|
|
1879
|
-
nftId: string,
|
|
1880
|
-
vault: EthereumAddress,
|
|
1881
|
-
ratioState: RatioState,
|
|
1882
|
-
targetRatio: number,
|
|
1883
|
-
) => {
|
|
1884
|
-
const nftIdEncoded = AbiCoder.encodeParameter('uint256', nftId);
|
|
1885
|
-
const vaultEncoded = AbiCoder.encodeParameter('address', vault);
|
|
1886
|
-
const ratioStateEncoded = AbiCoder.encodeParameter('uint8', ratioState);
|
|
1887
|
-
const targetRatioEncoded = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
1888
|
-
const wrapEthEncoded = AbiCoder.encodeParameter('bool', true);
|
|
1889
|
-
|
|
1890
|
-
const collActionType = CollActionType.WITHDRAW;
|
|
1891
|
-
const debtActionType = DebtActionType.PAYBACK;
|
|
1892
|
-
|
|
1893
|
-
const collActionTypeEncoded = AbiCoder.encodeParameter('uint8', collActionType);
|
|
1894
|
-
const debtActionTypeEncoded = AbiCoder.encodeParameter('uint8', debtActionType);
|
|
1895
|
-
|
|
1896
|
-
return [
|
|
1897
|
-
nftIdEncoded,
|
|
1898
|
-
vaultEncoded,
|
|
1899
|
-
ratioStateEncoded,
|
|
1900
|
-
targetRatioEncoded,
|
|
1901
|
-
wrapEthEncoded,
|
|
1902
|
-
collActionTypeEncoded,
|
|
1903
|
-
debtActionTypeEncoded,
|
|
1904
|
-
];
|
|
1905
|
-
},
|
|
1906
|
-
decode: (subData: SubData) => {
|
|
1907
|
-
const nftId = AbiCoder.decodeParameter('uint256', subData[0]) as any as string;
|
|
1908
|
-
const vault = AbiCoder.decodeParameter('address', subData[1]) as unknown as EthereumAddress;
|
|
1909
|
-
const ratioState = AbiCoder.decodeParameter('uint8', subData[2]) as any as RatioState;
|
|
1910
|
-
const weiRatio = AbiCoder.decodeParameter('uint256', subData[3]) as any as string;
|
|
1911
|
-
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
1912
|
-
|
|
1913
|
-
return {
|
|
1914
|
-
nftId, vault, ratioState, targetRatio,
|
|
1915
|
-
};
|
|
1916
|
-
},
|
|
1917
|
-
};
|
|
1646
|
+
export const fluidLiquidationProtectionSubData = fluidLeverageManagementSubData;
|
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
compareAddresses,
|
|
12
12
|
encodeSubId,
|
|
13
13
|
ethToWeth,
|
|
14
|
-
getCompoundV3LeverageManagementBundleId,
|
|
15
14
|
getRatioStateInfoForAaveCloseStrategy,
|
|
16
15
|
isAddress,
|
|
17
16
|
isDefined,
|
|
@@ -370,34 +369,4 @@ describe('Feature: utils.ts', () => {
|
|
|
370
369
|
});
|
|
371
370
|
});
|
|
372
371
|
});
|
|
373
|
-
|
|
374
|
-
describe('When testing utils.getCompoundV3LeverageManagementBundleId()', () => {
|
|
375
|
-
// Mainnet uses the V2 bundle ids; L2s use the original bundle ids.
|
|
376
|
-
const examples: Array<[number, [network: ChainId, isEOA: boolean, isBoost: boolean]]> = [
|
|
377
|
-
[Bundles.MainnetIds.COMP_V3_SW_REPAY_V2_BUNDLE, [ChainId.Ethereum, false, false]],
|
|
378
|
-
[Bundles.MainnetIds.COMP_V3_SW_BOOST_V2_BUNDLE, [ChainId.Ethereum, false, true]],
|
|
379
|
-
[Bundles.MainnetIds.COMP_V3_EOA_REPAY_V2_BUNDLE, [ChainId.Ethereum, true, false]],
|
|
380
|
-
[Bundles.MainnetIds.COMP_V3_EOA_BOOST_V2_BUNDLE, [ChainId.Ethereum, true, true]],
|
|
381
|
-
|
|
382
|
-
[Bundles.BaseIds.COMP_V3_SW_REPAY_BUNDLE, [ChainId.Base, false, false]],
|
|
383
|
-
[Bundles.BaseIds.COMP_V3_SW_BOOST_BUNDLE, [ChainId.Base, false, true]],
|
|
384
|
-
[Bundles.BaseIds.COMP_V3_EOA_REPAY, [ChainId.Base, true, false]],
|
|
385
|
-
[Bundles.BaseIds.COMP_V3_EOA_BOOST, [ChainId.Base, true, true]],
|
|
386
|
-
|
|
387
|
-
[Bundles.ArbitrumIds.COMP_V3_SW_REPAY_BUNDLE, [ChainId.Arbitrum, false, false]],
|
|
388
|
-
[Bundles.ArbitrumIds.COMP_V3_SW_BOOST_BUNDLE, [ChainId.Arbitrum, false, true]],
|
|
389
|
-
[Bundles.ArbitrumIds.COMP_V3_EOA_REPAY, [ChainId.Arbitrum, true, false]],
|
|
390
|
-
[Bundles.ArbitrumIds.COMP_V3_EOA_BOOST, [ChainId.Arbitrum, true, true]],
|
|
391
|
-
];
|
|
392
|
-
|
|
393
|
-
examples.forEach(([expected, actual]) => {
|
|
394
|
-
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
395
|
-
expect(getCompoundV3LeverageManagementBundleId(...actual)).to.equal(expected);
|
|
396
|
-
});
|
|
397
|
-
});
|
|
398
|
-
|
|
399
|
-
it(`Given ${ChainId.Optimism} (unsupported) should throw an error`, () => {
|
|
400
|
-
expect(() => getCompoundV3LeverageManagementBundleId(ChainId.Optimism, false, false)).to.throw(Error);
|
|
401
|
-
});
|
|
402
|
-
});
|
|
403
372
|
});
|
package/src/services/utils.ts
CHANGED
|
@@ -186,20 +186,3 @@ export function getBundleIdsByNetwork(network: ChainId) {
|
|
|
186
186
|
throw new Error(`Unsupported network ${network}`);
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
|
-
|
|
190
|
-
// Mainnet uses the V2 bundle ids; L2s use the original bundle ids.
|
|
191
|
-
export function getCompoundV3LeverageManagementBundleId(network: ChainId, isEOA: boolean, isBoost: boolean): number {
|
|
192
|
-
switch (Number(network)) {
|
|
193
|
-
case ChainId.Ethereum:
|
|
194
|
-
if (isEOA) return isBoost ? Bundles.MainnetIds.COMP_V3_EOA_BOOST_V2_BUNDLE : Bundles.MainnetIds.COMP_V3_EOA_REPAY_V2_BUNDLE;
|
|
195
|
-
return isBoost ? Bundles.MainnetIds.COMP_V3_SW_BOOST_V2_BUNDLE : Bundles.MainnetIds.COMP_V3_SW_REPAY_V2_BUNDLE;
|
|
196
|
-
case ChainId.Base:
|
|
197
|
-
if (isEOA) return isBoost ? Bundles.BaseIds.COMP_V3_EOA_BOOST : Bundles.BaseIds.COMP_V3_EOA_REPAY;
|
|
198
|
-
return isBoost ? Bundles.BaseIds.COMP_V3_SW_BOOST_BUNDLE : Bundles.BaseIds.COMP_V3_SW_REPAY_BUNDLE;
|
|
199
|
-
case ChainId.Arbitrum:
|
|
200
|
-
if (isEOA) return isBoost ? Bundles.ArbitrumIds.COMP_V3_EOA_BOOST : Bundles.ArbitrumIds.COMP_V3_EOA_REPAY;
|
|
201
|
-
return isBoost ? Bundles.ArbitrumIds.COMP_V3_SW_BOOST_BUNDLE : Bundles.ArbitrumIds.COMP_V3_SW_REPAY_BUNDLE;
|
|
202
|
-
default:
|
|
203
|
-
throw new Error(`Compound V3 leverage management is not supported on network ${network}`);
|
|
204
|
-
}
|
|
205
|
-
}
|