@defisaver/automation-sdk 3.3.15-liq-prot-2-dev → 3.3.16
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 +9 -124
- package/cjs/index.d.ts +3 -4
- package/cjs/index.js +2 -6
- package/cjs/services/strategiesService.js +1 -148
- package/cjs/services/strategySubService.d.ts +2 -9
- package/cjs/services/strategySubService.js +1 -52
- package/cjs/services/strategySubService.test.js +67 -0
- package/cjs/services/subDataService.d.ts +3 -58
- package/cjs/services/subDataService.js +18 -164
- package/cjs/services/subDataService.test.js +168 -0
- package/cjs/services/triggerService.test.js +60 -0
- package/cjs/services/utils.d.ts +1 -3
- package/cjs/services/utils.js +1 -34
- package/cjs/services/utils.test.js +0 -25
- package/cjs/types/enums.d.ts +6 -33
- package/cjs/types/enums.js +3 -30
- package/esm/constants/index.js +9 -124
- package/esm/index.d.ts +3 -4
- package/esm/index.js +3 -7
- package/esm/services/strategiesService.js +1 -148
- package/esm/services/strategySubService.d.ts +2 -9
- package/esm/services/strategySubService.js +2 -53
- package/esm/services/strategySubService.test.js +67 -0
- package/esm/services/subDataService.d.ts +3 -58
- package/esm/services/subDataService.js +16 -162
- package/esm/services/subDataService.test.js +168 -0
- package/esm/services/triggerService.test.js +61 -1
- package/esm/services/utils.d.ts +1 -3
- package/esm/services/utils.js +1 -32
- package/esm/services/utils.test.js +2 -27
- package/esm/types/enums.d.ts +6 -33
- package/esm/types/enums.js +3 -30
- package/package.json +1 -1
- package/src/constants/index.ts +10 -126
- package/src/index.ts +6 -24
- package/src/services/strategiesService.ts +1 -212
- package/src/services/strategySubService.test.ts +84 -0
- package/src/services/strategySubService.ts +5 -149
- package/src/services/subDataService.test.ts +182 -0
- package/src/services/subDataService.ts +22 -229
- package/src/services/triggerService.test.ts +69 -0
- package/src/services/utils.test.ts +1 -32
- package/src/services/utils.ts +1 -32
- package/src/types/enums.ts +5 -30
|
@@ -125,8 +125,6 @@ export const makerLeverageManagementSubData = {
|
|
|
125
125
|
return { vaultId, targetRatio };
|
|
126
126
|
},
|
|
127
127
|
};
|
|
128
|
-
// ! Any change here will PROBABLY require a change in makerLiquidationProtectionSubData as well, since it is copy paste
|
|
129
|
-
// ! Double check before changing
|
|
130
128
|
export const makerLeverageManagementWithoutSubProxy = {
|
|
131
129
|
encode(vaultId, targetRatio, daiAddr) {
|
|
132
130
|
const encodedVaultId = AbiCoder.encodeParameter('uint256', vaultId);
|
|
@@ -141,20 +139,6 @@ export const makerLeverageManagementWithoutSubProxy = {
|
|
|
141
139
|
return { vaultId, targetRatio, daiAddr };
|
|
142
140
|
},
|
|
143
141
|
};
|
|
144
|
-
export const makerLiquidationProtectionSubData = {
|
|
145
|
-
encode(vaultId, targetRatio, daiAddr) {
|
|
146
|
-
const encodedVaultId = AbiCoder.encodeParameter('uint256', vaultId);
|
|
147
|
-
const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
148
|
-
const encodedDaiAddr = AbiCoder.encodeParameter('address', daiAddr || getAssetInfo('DAI', 1).address);
|
|
149
|
-
return [encodedVaultId, encodedTargetRatio, encodedDaiAddr];
|
|
150
|
-
},
|
|
151
|
-
decode(subData) {
|
|
152
|
-
const vaultId = +AbiCoder.decodeParameter('uint256', subData[0]).toString();
|
|
153
|
-
const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[1]));
|
|
154
|
-
const daiAddr = AbiCoder.decodeParameter('address', subData[2]).toString();
|
|
155
|
-
return { vaultId, targetRatio, daiAddr };
|
|
156
|
-
},
|
|
157
|
-
};
|
|
158
142
|
/**
|
|
159
143
|
__ __ ______ __ __ __ .___________.____ ____ ____ ____ __
|
|
160
144
|
| | | | / __ \ | | | | | | | |\ \ / / \ \ / / /_ |
|
|
@@ -459,8 +443,6 @@ export const aaveV3LeverageManagementSubData = {
|
|
|
459
443
|
return { targetRatio };
|
|
460
444
|
},
|
|
461
445
|
};
|
|
462
|
-
// ! Any change here will PROBABLY require a change in aaveV3LiquidationProtectionSubData as well
|
|
463
|
-
// ! Double check before changing. Liquidation protection is using Generic encoding for both - EOA and SW
|
|
464
446
|
export const aaveV3LeverageManagementSubDataWithoutSubProxy = {
|
|
465
447
|
encode(targetRatio, ratioState, market, user, isGeneric) {
|
|
466
448
|
const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
@@ -480,20 +462,6 @@ export const aaveV3LeverageManagementSubDataWithoutSubProxy = {
|
|
|
480
462
|
return { targetRatio, ratioState };
|
|
481
463
|
},
|
|
482
464
|
};
|
|
483
|
-
export const aaveV3LiquidationProtectionSubData = {
|
|
484
|
-
encode(targetRatio, ratioState, market, user) {
|
|
485
|
-
const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
486
|
-
const encodedRatioState = AbiCoder.encodeParameter('uint8', ratioState);
|
|
487
|
-
const encodedMarket = AbiCoder.encodeParameter('address', market);
|
|
488
|
-
const encodedUser = AbiCoder.encodeParameter('address', user);
|
|
489
|
-
return [encodedTargetRatio, encodedRatioState, encodedMarket, encodedUser];
|
|
490
|
-
},
|
|
491
|
-
decode(subData) {
|
|
492
|
-
const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[0]));
|
|
493
|
-
const ratioState = AbiCoder.decodeParameter('uint8', subData[1]);
|
|
494
|
-
return { targetRatio, ratioState };
|
|
495
|
-
},
|
|
496
|
-
};
|
|
497
465
|
export const aaveV3LeverageManagementOnPriceGeneric = {
|
|
498
466
|
encode(collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio, user) {
|
|
499
467
|
const encodedColl = AbiCoder.encodeParameter('address', collAsset);
|
|
@@ -655,8 +623,6 @@ export const aaveV3LeverageManagementOnPriceSubData = {
|
|
|
655
623
|
/ _____ \ / _____ \ \ / | |____ \ / | |
|
|
656
624
|
/__/ \__\ /__/ \__\ \__/ |_______| \__/ |_|
|
|
657
625
|
*/
|
|
658
|
-
// ! Any change here will PROBABLY require a change in aaveV4LiquidationProtectionSubData as well, since it is copy paste
|
|
659
|
-
// ! Double check before changing
|
|
660
626
|
export const aaveV4LeverageManagementSubData = {
|
|
661
627
|
encode: (spoke, owner, ratioState, targetRatio) => {
|
|
662
628
|
const spokeEncoded = AbiCoder.encodeParameter('address', spoke);
|
|
@@ -683,32 +649,6 @@ export const aaveV4LeverageManagementSubData = {
|
|
|
683
649
|
};
|
|
684
650
|
},
|
|
685
651
|
};
|
|
686
|
-
export const aaveV4LiquidationProtectionSubData = {
|
|
687
|
-
encode: (spoke, owner, ratioState, targetRatio) => {
|
|
688
|
-
const spokeEncoded = AbiCoder.encodeParameter('address', spoke);
|
|
689
|
-
const ownerEncoded = AbiCoder.encodeParameter('address', owner);
|
|
690
|
-
const ratioStateEncoded = AbiCoder.encodeParameter('uint8', ratioState);
|
|
691
|
-
const targetRatioEncoded = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
692
|
-
// Add two empty slots for future addons (e.g tsi or slippage settings)
|
|
693
|
-
return [
|
|
694
|
-
spokeEncoded,
|
|
695
|
-
ownerEncoded,
|
|
696
|
-
ratioStateEncoded,
|
|
697
|
-
targetRatioEncoded,
|
|
698
|
-
EMPTY_SLOT,
|
|
699
|
-
EMPTY_SLOT,
|
|
700
|
-
];
|
|
701
|
-
},
|
|
702
|
-
decode: (subData) => {
|
|
703
|
-
const spoke = AbiCoder.decodeParameter('address', subData[0]);
|
|
704
|
-
const owner = AbiCoder.decodeParameter('address', subData[1]);
|
|
705
|
-
const ratioState = Number(AbiCoder.decodeParameter('uint8', subData[2]));
|
|
706
|
-
const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[3]));
|
|
707
|
-
return {
|
|
708
|
-
spoke, owner, ratioState, targetRatio,
|
|
709
|
-
};
|
|
710
|
-
},
|
|
711
|
-
};
|
|
712
652
|
export const aaveV4LeverageManagementOnPriceSubData = {
|
|
713
653
|
encode: (spoke, owner, collAsset, collAssetId, debtAsset, debtAssetId, ratioState, targetRatio) => {
|
|
714
654
|
const spokeEncoded = AbiCoder.encodeParameter('address', spoke);
|
|
@@ -867,27 +807,26 @@ export const compoundV2LeverageManagementSubDataWithoutSubProxy = {
|
|
|
867
807
|
| `----.| `--' | | | | | | | \ / ___) |
|
|
868
808
|
\______| \______/ |__| |__| | _| \__/ |____/
|
|
869
809
|
*/
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
810
|
+
export const compoundV3LeverageManagementSubData = {
|
|
811
|
+
encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled, isEOA) {
|
|
812
|
+
return [
|
|
813
|
+
market,
|
|
814
|
+
baseToken,
|
|
815
|
+
new Dec(triggerRepayRatio).mul(1e16).toString(),
|
|
816
|
+
new Dec(triggerBoostRatio).mul(1e16).toString(),
|
|
817
|
+
new Dec(targetBoostRatio).mul(1e16).toString(),
|
|
818
|
+
new Dec(targetRepayRatio).mul(1e16).toString(),
|
|
819
|
+
// @ts-ignore // TODO
|
|
820
|
+
boostEnabled, isEOA,
|
|
821
|
+
];
|
|
879
822
|
},
|
|
880
823
|
decode(subData) {
|
|
881
|
-
const
|
|
882
|
-
const
|
|
883
|
-
|
|
884
|
-
const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[3]));
|
|
885
|
-
return {
|
|
886
|
-
market, baseToken, targetRatio, ratioState,
|
|
887
|
-
};
|
|
824
|
+
const weiRatio = AbiCoder.decodeParameter('uint256', subData[3]);
|
|
825
|
+
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
826
|
+
return { targetRatio };
|
|
888
827
|
},
|
|
889
828
|
};
|
|
890
|
-
export const
|
|
829
|
+
export const compoundV3LeverageManagementSubDataWithoutSubProxy = {
|
|
891
830
|
encode(market, baseToken, targetRatio, ratioState) {
|
|
892
831
|
const encodedMarket = AbiCoder.encodeParameter('address', market);
|
|
893
832
|
const encodedBaseToken = AbiCoder.encodeParameter('address', baseToken);
|
|
@@ -1038,8 +977,6 @@ export const sparkLeverageManagementSubData = {
|
|
|
1038
977
|
return { targetRatio };
|
|
1039
978
|
},
|
|
1040
979
|
};
|
|
1041
|
-
// ! Any change here will PROBABLY require a change in sparkLiquidationProtectionSubData as well, since it is copy paste
|
|
1042
|
-
// ! Double check before changing
|
|
1043
980
|
export const sparkLeverageManagementSubDataWithoutSubProxy = {
|
|
1044
981
|
encode(targetRatio, ratioState) {
|
|
1045
982
|
const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
@@ -1054,20 +991,6 @@ export const sparkLeverageManagementSubDataWithoutSubProxy = {
|
|
|
1054
991
|
return { targetRatio, ratioState };
|
|
1055
992
|
},
|
|
1056
993
|
};
|
|
1057
|
-
export const sparkLiquidationProtectionSubData = {
|
|
1058
|
-
encode(targetRatio, ratioState) {
|
|
1059
|
-
const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
1060
|
-
const encodedRatioState = AbiCoder.encodeParameter('uint8', ratioState);
|
|
1061
|
-
const encodedUseDefaultMarket = AbiCoder.encodeParameter('bool', true);
|
|
1062
|
-
const encodedUseOnBehalf = AbiCoder.encodeParameter('bool', false);
|
|
1063
|
-
return [encodedTargetRatio, encodedRatioState, encodedUseDefaultMarket, encodedUseOnBehalf];
|
|
1064
|
-
},
|
|
1065
|
-
decode(subData) {
|
|
1066
|
-
const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[0]));
|
|
1067
|
-
const ratioState = AbiCoder.decodeParameter('uint8', subData[1]);
|
|
1068
|
-
return { targetRatio, ratioState };
|
|
1069
|
-
},
|
|
1070
|
-
};
|
|
1071
994
|
export const sparkCloseGenericSubData = {
|
|
1072
995
|
encode(collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, user) {
|
|
1073
996
|
const encodedColl = AbiCoder.encodeParameter('address', collAsset);
|
|
@@ -1216,8 +1139,6 @@ export const crvUSDPaybackSubData = {
|
|
|
1216
1139
|
| | | | | `--' | | |\ \----.| | | | | | | `--' |
|
|
1217
1140
|
|__| |__| \______/ | _| `._____|| _| |__| |__| \______/
|
|
1218
1141
|
*/
|
|
1219
|
-
// ! Any change here will PROBABLY require a change in morphoBlueLiquidationProtectionSubData as well, since it is copy paste
|
|
1220
|
-
// ! Double check before changing
|
|
1221
1142
|
export const morphoBlueLeverageManagementSubData = {
|
|
1222
1143
|
encode: (loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, user, isEOA) => {
|
|
1223
1144
|
const loanTokenEncoded = AbiCoder.encodeParameter('address', loanToken);
|
|
@@ -1251,39 +1172,6 @@ export const morphoBlueLeverageManagementSubData = {
|
|
|
1251
1172
|
};
|
|
1252
1173
|
},
|
|
1253
1174
|
};
|
|
1254
|
-
export const morphoBlueLiquidationProtectionSubData = {
|
|
1255
|
-
encode: (loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, user, isEOA) => {
|
|
1256
|
-
const loanTokenEncoded = AbiCoder.encodeParameter('address', loanToken);
|
|
1257
|
-
const collTokenEncoded = AbiCoder.encodeParameter('address', collToken);
|
|
1258
|
-
const oracleEncoded = AbiCoder.encodeParameter('address', oracle);
|
|
1259
|
-
const irmEncoded = AbiCoder.encodeParameter('address', irm);
|
|
1260
|
-
const lltvEncoded = AbiCoder.encodeParameter('uint256', lltv);
|
|
1261
|
-
const ratioStateEncoded = AbiCoder.encodeParameter('uint8', ratioState);
|
|
1262
|
-
const targetRatioEncoded = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
1263
|
-
const userEncoded = AbiCoder.encodeParameter('address', user);
|
|
1264
|
-
const isEOAEncoded = AbiCoder.encodeParameter('bool', isEOA);
|
|
1265
|
-
return [loanTokenEncoded, collTokenEncoded, oracleEncoded, irmEncoded, lltvEncoded, ratioStateEncoded, targetRatioEncoded, userEncoded, isEOAEncoded];
|
|
1266
|
-
},
|
|
1267
|
-
decode: (subData) => {
|
|
1268
|
-
const loanToken = AbiCoder.decodeParameter('address', subData[0]);
|
|
1269
|
-
const collToken = AbiCoder.decodeParameter('address', subData[1]);
|
|
1270
|
-
const oracle = AbiCoder.decodeParameter('address', subData[2]);
|
|
1271
|
-
const irm = AbiCoder.decodeParameter('address', subData[3]);
|
|
1272
|
-
const lltv = AbiCoder.decodeParameter('uint256', subData[4]);
|
|
1273
|
-
const weiRatio = AbiCoder.decodeParameter('uint256', subData[6]);
|
|
1274
|
-
const user = AbiCoder.decodeParameter('address', subData[7]);
|
|
1275
|
-
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
1276
|
-
return {
|
|
1277
|
-
loanToken,
|
|
1278
|
-
collToken,
|
|
1279
|
-
oracle,
|
|
1280
|
-
irm,
|
|
1281
|
-
lltv,
|
|
1282
|
-
user,
|
|
1283
|
-
targetRatio,
|
|
1284
|
-
};
|
|
1285
|
-
},
|
|
1286
|
-
};
|
|
1287
1175
|
export const morphoBlueLeverageManagementOnPriceSubData = {
|
|
1288
1176
|
encode(loanToken, collToken, oracle, irm, lltv, targetRatio, user) {
|
|
1289
1177
|
const loanTokenEncoded = AbiCoder.encodeParameter('address', loanToken);
|
|
@@ -1353,8 +1241,6 @@ _______ __ __ __ __ _______
|
|
|
1353
1241
|
| | | `----.| `--' | | | | '--' |
|
|
1354
1242
|
|__| |_______| \______/ |__| |_______/
|
|
1355
1243
|
*/
|
|
1356
|
-
// ! Any change here will PROBABLY require a change in fluidLeverageManagementSubData as well, since it is copy paste
|
|
1357
|
-
// ! Double check before changing
|
|
1358
1244
|
export const fluidLeverageManagementSubData = {
|
|
1359
1245
|
encode: (nftId, vault, ratioState, targetRatio) => {
|
|
1360
1246
|
const nftIdEncoded = AbiCoder.encodeParameter('uint256', nftId);
|
|
@@ -1388,35 +1274,3 @@ export const fluidLeverageManagementSubData = {
|
|
|
1388
1274
|
};
|
|
1389
1275
|
},
|
|
1390
1276
|
};
|
|
1391
|
-
export const fluidLiquidationProtectionSubData = {
|
|
1392
|
-
encode: (nftId, vault, ratioState, targetRatio) => {
|
|
1393
|
-
const nftIdEncoded = AbiCoder.encodeParameter('uint256', nftId);
|
|
1394
|
-
const vaultEncoded = AbiCoder.encodeParameter('address', vault);
|
|
1395
|
-
const ratioStateEncoded = AbiCoder.encodeParameter('uint8', ratioState);
|
|
1396
|
-
const targetRatioEncoded = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
1397
|
-
const wrapEthEncoded = AbiCoder.encodeParameter('bool', true);
|
|
1398
|
-
const collActionType = CollActionType.WITHDRAW;
|
|
1399
|
-
const debtActionType = DebtActionType.PAYBACK;
|
|
1400
|
-
const collActionTypeEncoded = AbiCoder.encodeParameter('uint8', collActionType);
|
|
1401
|
-
const debtActionTypeEncoded = AbiCoder.encodeParameter('uint8', debtActionType);
|
|
1402
|
-
return [
|
|
1403
|
-
nftIdEncoded,
|
|
1404
|
-
vaultEncoded,
|
|
1405
|
-
ratioStateEncoded,
|
|
1406
|
-
targetRatioEncoded,
|
|
1407
|
-
wrapEthEncoded,
|
|
1408
|
-
collActionTypeEncoded,
|
|
1409
|
-
debtActionTypeEncoded,
|
|
1410
|
-
];
|
|
1411
|
-
},
|
|
1412
|
-
decode: (subData) => {
|
|
1413
|
-
const nftId = AbiCoder.decodeParameter('uint256', subData[0]);
|
|
1414
|
-
const vault = AbiCoder.decodeParameter('address', subData[1]);
|
|
1415
|
-
const ratioState = AbiCoder.decodeParameter('uint8', subData[2]);
|
|
1416
|
-
const weiRatio = AbiCoder.decodeParameter('uint256', subData[3]);
|
|
1417
|
-
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
1418
|
-
return {
|
|
1419
|
-
nftId, vault, ratioState, targetRatio,
|
|
1420
|
-
};
|
|
1421
|
-
},
|
|
1422
|
-
};
|
|
@@ -685,6 +685,74 @@ describe('Feature: subDataService.ts', () => {
|
|
|
685
685
|
});
|
|
686
686
|
});
|
|
687
687
|
});
|
|
688
|
+
describe('When testing subDataService.compoundV3LeverageManagementSubData', () => {
|
|
689
|
+
describe('encode()', () => {
|
|
690
|
+
const examples = [
|
|
691
|
+
[
|
|
692
|
+
[
|
|
693
|
+
web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
694
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
695
|
+
new Dec(160).mul(1e16).toString(),
|
|
696
|
+
new Dec(220).mul(1e16).toString(),
|
|
697
|
+
new Dec(180).mul(1e16).toString(),
|
|
698
|
+
new Dec(190).mul(1e16).toString(),
|
|
699
|
+
true, false,
|
|
700
|
+
],
|
|
701
|
+
[
|
|
702
|
+
web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
703
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
704
|
+
160, 220, 180, 190,
|
|
705
|
+
true, false,
|
|
706
|
+
]
|
|
707
|
+
],
|
|
708
|
+
[
|
|
709
|
+
[
|
|
710
|
+
web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
711
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
712
|
+
new Dec(160).mul(1e16).toString(),
|
|
713
|
+
new Dec(210).mul(1e16).toString(),
|
|
714
|
+
new Dec(180).mul(1e16).toString(),
|
|
715
|
+
new Dec(190).mul(1e16).toString(),
|
|
716
|
+
false, true,
|
|
717
|
+
],
|
|
718
|
+
[
|
|
719
|
+
web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
720
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
721
|
+
160, 210, 180, 190,
|
|
722
|
+
false, true,
|
|
723
|
+
]
|
|
724
|
+
],
|
|
725
|
+
];
|
|
726
|
+
examples.forEach(([expected, actual]) => {
|
|
727
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
728
|
+
expect(subDataService.compoundV3LeverageManagementSubData.encode(...actual)).to.eql(expected);
|
|
729
|
+
});
|
|
730
|
+
});
|
|
731
|
+
});
|
|
732
|
+
describe('decode()', () => {
|
|
733
|
+
const examples = [
|
|
734
|
+
[
|
|
735
|
+
{ targetRatio: 123 },
|
|
736
|
+
[
|
|
737
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
738
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
|
|
739
|
+
],
|
|
740
|
+
],
|
|
741
|
+
[
|
|
742
|
+
{ targetRatio: 200 },
|
|
743
|
+
[
|
|
744
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
745
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
746
|
+
],
|
|
747
|
+
],
|
|
748
|
+
];
|
|
749
|
+
examples.forEach(([expected, actual]) => {
|
|
750
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
751
|
+
expect(subDataService.compoundV3LeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
752
|
+
});
|
|
753
|
+
});
|
|
754
|
+
});
|
|
755
|
+
});
|
|
688
756
|
describe('When testing subDataService.morphoAaveV2LeverageManagementSubData', () => {
|
|
689
757
|
describe('encode()', () => {
|
|
690
758
|
const examples = [
|
|
@@ -1383,6 +1451,106 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1383
1451
|
});
|
|
1384
1452
|
});
|
|
1385
1453
|
});
|
|
1454
|
+
describe('When testing subDataService.morphoBlueLeverageManagementOnPriceSubData', () => {
|
|
1455
|
+
describe('encode()', () => {
|
|
1456
|
+
const examples = [
|
|
1457
|
+
[
|
|
1458
|
+
[
|
|
1459
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1460
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1461
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1462
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1463
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1464
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
1465
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1466
|
+
],
|
|
1467
|
+
[
|
|
1468
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1469
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1470
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1471
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1472
|
+
'945000000000000000',
|
|
1473
|
+
200,
|
|
1474
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1475
|
+
],
|
|
1476
|
+
],
|
|
1477
|
+
[
|
|
1478
|
+
[
|
|
1479
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1480
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1481
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1482
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1483
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1484
|
+
'0x00000000000000000000000000000000000000000000000016345785d8a00000',
|
|
1485
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1486
|
+
],
|
|
1487
|
+
[
|
|
1488
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1489
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1490
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1491
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1492
|
+
'945000000000000000',
|
|
1493
|
+
160,
|
|
1494
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1495
|
+
],
|
|
1496
|
+
],
|
|
1497
|
+
];
|
|
1498
|
+
examples.forEach(([expected, actual]) => {
|
|
1499
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1500
|
+
expect(subDataService.morphoBlueLeverageManagementOnPriceSubData.encode(...actual)).to.eql(expected);
|
|
1501
|
+
});
|
|
1502
|
+
});
|
|
1503
|
+
});
|
|
1504
|
+
describe('decode()', () => {
|
|
1505
|
+
const examples = [
|
|
1506
|
+
[
|
|
1507
|
+
{
|
|
1508
|
+
loanToken: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
|
|
1509
|
+
collToken: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0',
|
|
1510
|
+
oracle: '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
|
|
1511
|
+
irm: '0x0000000000000000000000000000000000000000',
|
|
1512
|
+
lltv: '945000000000000000',
|
|
1513
|
+
targetRatio: 200,
|
|
1514
|
+
user: '0x1031d218133AFaB8C2B819B1366c7e434Ad91e9c',
|
|
1515
|
+
},
|
|
1516
|
+
[
|
|
1517
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1518
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1519
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1520
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1521
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1522
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
1523
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1524
|
+
],
|
|
1525
|
+
],
|
|
1526
|
+
[
|
|
1527
|
+
{
|
|
1528
|
+
loanToken: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
|
|
1529
|
+
collToken: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0',
|
|
1530
|
+
oracle: '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
|
|
1531
|
+
irm: '0x0000000000000000000000000000000000000000',
|
|
1532
|
+
lltv: '945000000000000000',
|
|
1533
|
+
targetRatio: 160,
|
|
1534
|
+
user: '0x1031d218133AFaB8C2B819B1366c7e434Ad91e9c',
|
|
1535
|
+
},
|
|
1536
|
+
[
|
|
1537
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1538
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1539
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1540
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1541
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1542
|
+
'0x00000000000000000000000000000000000000000000000016345785d8a00000',
|
|
1543
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1544
|
+
],
|
|
1545
|
+
],
|
|
1546
|
+
];
|
|
1547
|
+
examples.forEach(([expected, actual]) => {
|
|
1548
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1549
|
+
expect(subDataService.morphoBlueLeverageManagementOnPriceSubData.decode(actual)).to.eql(expected);
|
|
1550
|
+
});
|
|
1551
|
+
});
|
|
1552
|
+
});
|
|
1553
|
+
});
|
|
1386
1554
|
describe('When testing subDataService.aaveV3LeverageManagementOnPriceSubData', () => {
|
|
1387
1555
|
describe('encode()', () => {
|
|
1388
1556
|
const examples = [
|
|
@@ -3,7 +3,7 @@ import { getAssetInfo, MAXUINT } from '@defisaver/tokens';
|
|
|
3
3
|
import * as web3Utils from 'web3-utils';
|
|
4
4
|
import { ChainId, OrderType, RatioState } from '../types/enums';
|
|
5
5
|
import '../configuration';
|
|
6
|
-
import { aaveV2RatioTrigger, aaveV3QuotePriceTrigger, aaveV3QuotePriceWithMaximumGasPriceTrigger, aaveV3RatioTrigger, cBondsRebondTrigger, chainlinkPriceTrigger, compoundV2RatioTrigger, compoundV3RatioTrigger, compoundV3PriceTrigger, curveUsdBorrowRateTrigger, curveUsdSoftLiquidationTrigger, exchangeOffchainPriceTrigger, exchangeTimestampTrigger, liquityDebtInFrontTrigger, makerRatioTrigger, morphoAaveV2RatioTrigger, sparkRatioTrigger, trailingStopTrigger, liquityDebtInFrontWithLimitTrigger, crvUSDRatioTrigger, morphoBlueRatioTrigger, crvUsdHealthRatioTrigger, liquityV2DebtInFrontTrigger, liquityV2AdjustTimeTrigger, compoundV3PriceRangeTrigger, aaveV3QuotePriceRangeTrigger, morphoBluePriceRangeTrigger, sparkQuotePriceTrigger, aaveV4RatioTrigger, aaveV4QuotePriceTrigger, aaveV4QuotePriceRangeTrigger, } from './triggerService';
|
|
6
|
+
import { aaveV2RatioTrigger, aaveV3QuotePriceTrigger, aaveV3QuotePriceWithMaximumGasPriceTrigger, aaveV3RatioTrigger, cBondsRebondTrigger, chainlinkPriceTrigger, compoundV2RatioTrigger, compoundV3RatioTrigger, compoundV3PriceTrigger, curveUsdBorrowRateTrigger, curveUsdSoftLiquidationTrigger, exchangeOffchainPriceTrigger, exchangeTimestampTrigger, liquityDebtInFrontTrigger, makerRatioTrigger, morphoAaveV2RatioTrigger, sparkRatioTrigger, trailingStopTrigger, liquityDebtInFrontWithLimitTrigger, crvUSDRatioTrigger, morphoBlueRatioTrigger, crvUsdHealthRatioTrigger, liquityV2DebtInFrontTrigger, liquityV2AdjustTimeTrigger, compoundV3PriceRangeTrigger, aaveV3QuotePriceRangeTrigger, morphoBluePriceRangeTrigger, morphoBluePriceTrigger, sparkQuotePriceTrigger, aaveV4RatioTrigger, aaveV4QuotePriceTrigger, aaveV4QuotePriceRangeTrigger, } from './triggerService';
|
|
7
7
|
describe('Feature: triggerService.ts', () => {
|
|
8
8
|
describe('When testing triggerService.chainlinkPriceTrigger', () => {
|
|
9
9
|
describe('encode()', () => {
|
|
@@ -1159,6 +1159,66 @@ describe('Feature: triggerService.ts', () => {
|
|
|
1159
1159
|
});
|
|
1160
1160
|
});
|
|
1161
1161
|
});
|
|
1162
|
+
describe('When testing triggerService.morphoBluePriceTrigger', () => {
|
|
1163
|
+
describe('encode()', () => {
|
|
1164
|
+
const examples = [
|
|
1165
|
+
[
|
|
1166
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1167
|
+
[
|
|
1168
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1169
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1170
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1171
|
+
2500,
|
|
1172
|
+
RatioState.UNDER,
|
|
1173
|
+
],
|
|
1174
|
+
],
|
|
1175
|
+
[
|
|
1176
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000005d21dba0000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1177
|
+
[
|
|
1178
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1179
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1180
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1181
|
+
4000,
|
|
1182
|
+
RatioState.OVER,
|
|
1183
|
+
],
|
|
1184
|
+
],
|
|
1185
|
+
];
|
|
1186
|
+
examples.forEach(([expected, actual]) => {
|
|
1187
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1188
|
+
expect(morphoBluePriceTrigger.encode(...actual)).to.eql(expected);
|
|
1189
|
+
});
|
|
1190
|
+
});
|
|
1191
|
+
});
|
|
1192
|
+
describe('decode()', () => {
|
|
1193
|
+
const examples = [
|
|
1194
|
+
[
|
|
1195
|
+
{
|
|
1196
|
+
oracle: web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1197
|
+
collateralToken: web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1198
|
+
loanToken: web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1199
|
+
price: '2500',
|
|
1200
|
+
priceState: RatioState.UNDER,
|
|
1201
|
+
},
|
|
1202
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1203
|
+
],
|
|
1204
|
+
[
|
|
1205
|
+
{
|
|
1206
|
+
oracle: web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1207
|
+
collateralToken: web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1208
|
+
loanToken: web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1209
|
+
price: '4000',
|
|
1210
|
+
priceState: RatioState.OVER,
|
|
1211
|
+
},
|
|
1212
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000005d21dba0000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1213
|
+
],
|
|
1214
|
+
];
|
|
1215
|
+
examples.forEach(([expected, actual]) => {
|
|
1216
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1217
|
+
expect(morphoBluePriceTrigger.decode(actual)).to.eql(expected);
|
|
1218
|
+
});
|
|
1219
|
+
});
|
|
1220
|
+
});
|
|
1221
|
+
});
|
|
1162
1222
|
describe('When testing triggerService.aaveV4RatioTrigger', () => {
|
|
1163
1223
|
describe('encode()', () => {
|
|
1164
1224
|
const examples = [
|
package/esm/services/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EthereumAddress } from '../types';
|
|
2
|
-
import {
|
|
2
|
+
import { ChainId, CloseStrategyType, CloseToAssetType, RatioState } from '../types/enums';
|
|
3
3
|
export declare function isDefined<T>(value: T): value is NonNullable<T>;
|
|
4
4
|
export declare function isUndefined(value: unknown): boolean;
|
|
5
5
|
export declare function compareAddresses(firstAddress: EthereumAddress, secondAddress: EthereumAddress): boolean;
|
|
@@ -28,5 +28,3 @@ export declare function getStopLossAndTakeProfitTypeByCloseStrategyType(closeStr
|
|
|
28
28
|
stopLossType: CloseToAssetType | undefined;
|
|
29
29
|
takeProfitType: CloseToAssetType | undefined;
|
|
30
30
|
};
|
|
31
|
-
export declare function getBundleIdsByNetwork(network: ChainId): typeof Bundles.MainnetIds | typeof Bundles.ArbitrumIds | typeof Bundles.BaseIds;
|
|
32
|
-
export declare function getCompoundV3LeverageManagementBundleId(network: ChainId, isEOA: boolean, isBoost: boolean): number;
|
package/esm/services/utils.js
CHANGED
|
@@ -2,7 +2,7 @@ import Dec from 'decimal.js';
|
|
|
2
2
|
import * as web3Utils from 'web3-utils';
|
|
3
3
|
import AbiCoder from 'web3-eth-abi';
|
|
4
4
|
import { getAssetInfo, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
5
|
-
import {
|
|
5
|
+
import { ChainId, CloseStrategyType, CloseToAssetType, RatioState, } from '../types/enums';
|
|
6
6
|
export function isDefined(value) {
|
|
7
7
|
return value !== undefined && value !== null;
|
|
8
8
|
}
|
|
@@ -137,34 +137,3 @@ export function getStopLossAndTakeProfitTypeByCloseStrategyType(closeStrategyTyp
|
|
|
137
137
|
throw new Error('CloseStrategyType not supported');
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
|
-
export function getBundleIdsByNetwork(network) {
|
|
141
|
-
switch (Number(network)) {
|
|
142
|
-
case ChainId.Ethereum:
|
|
143
|
-
return Bundles.MainnetIds;
|
|
144
|
-
case ChainId.Arbitrum:
|
|
145
|
-
return Bundles.ArbitrumIds;
|
|
146
|
-
case ChainId.Base:
|
|
147
|
-
return Bundles.BaseIds;
|
|
148
|
-
default:
|
|
149
|
-
throw new Error(`Unsupported network ${network}`);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
// Mainnet uses the V2 bundle ids; L2s use the original bundle ids.
|
|
153
|
-
export function getCompoundV3LeverageManagementBundleId(network, isEOA, isBoost) {
|
|
154
|
-
switch (Number(network)) {
|
|
155
|
-
case ChainId.Ethereum:
|
|
156
|
-
if (isEOA)
|
|
157
|
-
return isBoost ? Bundles.MainnetIds.COMP_V3_EOA_BOOST_V2_BUNDLE : Bundles.MainnetIds.COMP_V3_EOA_REPAY_V2_BUNDLE;
|
|
158
|
-
return isBoost ? Bundles.MainnetIds.COMP_V3_SW_BOOST_V2_BUNDLE : Bundles.MainnetIds.COMP_V3_SW_REPAY_V2_BUNDLE;
|
|
159
|
-
case ChainId.Base:
|
|
160
|
-
if (isEOA)
|
|
161
|
-
return isBoost ? Bundles.BaseIds.COMP_V3_EOA_BOOST : Bundles.BaseIds.COMP_V3_EOA_REPAY;
|
|
162
|
-
return isBoost ? Bundles.BaseIds.COMP_V3_SW_BOOST_BUNDLE : Bundles.BaseIds.COMP_V3_SW_REPAY_BUNDLE;
|
|
163
|
-
case ChainId.Arbitrum:
|
|
164
|
-
if (isEOA)
|
|
165
|
-
return isBoost ? Bundles.ArbitrumIds.COMP_V3_EOA_BOOST : Bundles.ArbitrumIds.COMP_V3_EOA_REPAY;
|
|
166
|
-
return isBoost ? Bundles.ArbitrumIds.COMP_V3_SW_BOOST_BUNDLE : Bundles.ArbitrumIds.COMP_V3_SW_REPAY_BUNDLE;
|
|
167
|
-
default:
|
|
168
|
-
throw new Error(`Compound V3 leverage management is not supported on network ${network}`);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { expect } from 'chai';
|
|
2
2
|
import { getAssetInfo } from '@defisaver/tokens';
|
|
3
|
-
import {
|
|
3
|
+
import { ChainId, ProtocolIdentifiers, RatioState } from '../types/enums';
|
|
4
4
|
import '../configuration';
|
|
5
|
-
import { addToArrayIf, addToObjectIf, compareAddresses, encodeSubId, ethToWeth,
|
|
5
|
+
import { addToArrayIf, addToObjectIf, compareAddresses, encodeSubId, ethToWeth, getRatioStateInfoForAaveCloseStrategy, isAddress, isDefined, isEmptyBytes, isRatioStateOver, isRatioStateUnder, isUndefined, ratioPercentageToWei, requireAddress, requireAddresses, weiToRatioPercentage, wethToEth, wethToEthByAddress, getPositionId, } from './utils';
|
|
6
6
|
describe('Feature: utils.ts', () => {
|
|
7
7
|
describe('When testing utils.isDefined()', () => {
|
|
8
8
|
const examples = [
|
|
@@ -294,29 +294,4 @@ describe('Feature: utils.ts', () => {
|
|
|
294
294
|
});
|
|
295
295
|
});
|
|
296
296
|
});
|
|
297
|
-
describe('When testing utils.getCompoundV3LeverageManagementBundleId()', () => {
|
|
298
|
-
// Mainnet uses the V2 bundle ids; L2s use the original bundle ids.
|
|
299
|
-
const examples = [
|
|
300
|
-
[Bundles.MainnetIds.COMP_V3_SW_REPAY_V2_BUNDLE, [ChainId.Ethereum, false, false]],
|
|
301
|
-
[Bundles.MainnetIds.COMP_V3_SW_BOOST_V2_BUNDLE, [ChainId.Ethereum, false, true]],
|
|
302
|
-
[Bundles.MainnetIds.COMP_V3_EOA_REPAY_V2_BUNDLE, [ChainId.Ethereum, true, false]],
|
|
303
|
-
[Bundles.MainnetIds.COMP_V3_EOA_BOOST_V2_BUNDLE, [ChainId.Ethereum, true, true]],
|
|
304
|
-
[Bundles.BaseIds.COMP_V3_SW_REPAY_BUNDLE, [ChainId.Base, false, false]],
|
|
305
|
-
[Bundles.BaseIds.COMP_V3_SW_BOOST_BUNDLE, [ChainId.Base, false, true]],
|
|
306
|
-
[Bundles.BaseIds.COMP_V3_EOA_REPAY, [ChainId.Base, true, false]],
|
|
307
|
-
[Bundles.BaseIds.COMP_V3_EOA_BOOST, [ChainId.Base, true, true]],
|
|
308
|
-
[Bundles.ArbitrumIds.COMP_V3_SW_REPAY_BUNDLE, [ChainId.Arbitrum, false, false]],
|
|
309
|
-
[Bundles.ArbitrumIds.COMP_V3_SW_BOOST_BUNDLE, [ChainId.Arbitrum, false, true]],
|
|
310
|
-
[Bundles.ArbitrumIds.COMP_V3_EOA_REPAY, [ChainId.Arbitrum, true, false]],
|
|
311
|
-
[Bundles.ArbitrumIds.COMP_V3_EOA_BOOST, [ChainId.Arbitrum, true, true]],
|
|
312
|
-
];
|
|
313
|
-
examples.forEach(([expected, actual]) => {
|
|
314
|
-
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
315
|
-
expect(getCompoundV3LeverageManagementBundleId(...actual)).to.equal(expected);
|
|
316
|
-
});
|
|
317
|
-
});
|
|
318
|
-
it(`Given ${ChainId.Optimism} (unsupported) should throw an error`, () => {
|
|
319
|
-
expect(() => getCompoundV3LeverageManagementBundleId(ChainId.Optimism, false, false)).to.throw(Error);
|
|
320
|
-
});
|
|
321
|
-
});
|
|
322
297
|
});
|