@defisaver/automation-sdk 3.3.15-liq-prot-dev → 3.3.15-liq-prot-1-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 +64 -29
- package/cjs/services/strategiesService.js +9 -12
- package/cjs/services/strategySubService.d.ts +1 -1
- package/cjs/services/strategySubService.js +10 -5
- package/cjs/services/subDataService.d.ts +5 -14
- package/cjs/services/subDataService.js +20 -68
- package/cjs/services/subDataService.test.js +0 -68
- package/cjs/services/utils.d.ts +1 -1
- package/cjs/services/utils.js +4 -4
- package/cjs/types/enums.d.ts +24 -17
- package/cjs/types/enums.js +22 -15
- package/esm/constants/index.js +64 -29
- package/esm/services/strategiesService.js +9 -12
- package/esm/services/strategySubService.d.ts +1 -1
- package/esm/services/strategySubService.js +10 -5
- package/esm/services/subDataService.d.ts +5 -14
- package/esm/services/subDataService.js +18 -66
- package/esm/services/subDataService.test.js +0 -68
- package/esm/services/utils.d.ts +1 -1
- package/esm/services/utils.js +4 -4
- package/esm/types/enums.d.ts +24 -17
- package/esm/types/enums.js +22 -15
- package/package.json +1 -1
- package/src/constants/index.ts +66 -31
- package/src/services/strategiesService.ts +11 -15
- package/src/services/strategySubService.ts +18 -11
- package/src/services/subDataService.test.ts +0 -72
- package/src/services/subDataService.ts +20 -93
- package/src/services/utils.ts +4 -4
- package/src/types/enums.ts +22 -17
|
@@ -734,78 +734,6 @@ describe('Feature: subDataService.ts', () => {
|
|
|
734
734
|
});
|
|
735
735
|
});
|
|
736
736
|
|
|
737
|
-
describe('When testing subDataService.compoundV3LeverageManagementSubData', () => {
|
|
738
|
-
describe('encode()', () => {
|
|
739
|
-
const examples: Array<[[EthereumAddress, EthereumAddress, string, string, string, string, boolean, boolean], [market: EthereumAddress, baseToken: EthereumAddress, triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean, isEOA: boolean]]> = [
|
|
740
|
-
[
|
|
741
|
-
[
|
|
742
|
-
web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
743
|
-
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
744
|
-
new Dec(160).mul(1e16).toString(),
|
|
745
|
-
new Dec(220).mul(1e16).toString(),
|
|
746
|
-
new Dec(180).mul(1e16).toString(),
|
|
747
|
-
new Dec(190).mul(1e16).toString(),
|
|
748
|
-
true, false,
|
|
749
|
-
],
|
|
750
|
-
[
|
|
751
|
-
web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
752
|
-
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
753
|
-
160, 220, 180, 190,
|
|
754
|
-
true, false,
|
|
755
|
-
]
|
|
756
|
-
],
|
|
757
|
-
[
|
|
758
|
-
[
|
|
759
|
-
web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
760
|
-
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
761
|
-
new Dec(160).mul(1e16).toString(),
|
|
762
|
-
new Dec(210).mul(1e16).toString(),
|
|
763
|
-
new Dec(180).mul(1e16).toString(),
|
|
764
|
-
new Dec(190).mul(1e16).toString(),
|
|
765
|
-
false, true,
|
|
766
|
-
],
|
|
767
|
-
[
|
|
768
|
-
web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
769
|
-
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
770
|
-
160, 210, 180, 190,
|
|
771
|
-
false, true,
|
|
772
|
-
]
|
|
773
|
-
],
|
|
774
|
-
];
|
|
775
|
-
|
|
776
|
-
examples.forEach(([expected, actual]) => {
|
|
777
|
-
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
778
|
-
expect(subDataService.compoundV3LeverageManagementSubData.encode(...actual)).to.eql(expected);
|
|
779
|
-
});
|
|
780
|
-
});
|
|
781
|
-
});
|
|
782
|
-
|
|
783
|
-
describe('decode()', () => {
|
|
784
|
-
const examples: Array<[{ targetRatio: number }, SubData]> = [
|
|
785
|
-
[
|
|
786
|
-
{ targetRatio: 123 },
|
|
787
|
-
[
|
|
788
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
789
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
|
|
790
|
-
],
|
|
791
|
-
],
|
|
792
|
-
[
|
|
793
|
-
{ targetRatio: 200 },
|
|
794
|
-
[
|
|
795
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
796
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
797
|
-
],
|
|
798
|
-
],
|
|
799
|
-
];
|
|
800
|
-
|
|
801
|
-
examples.forEach(([expected, actual]) => {
|
|
802
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
803
|
-
expect(subDataService.compoundV3LeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
804
|
-
});
|
|
805
|
-
});
|
|
806
|
-
});
|
|
807
|
-
});
|
|
808
|
-
|
|
809
737
|
describe('When testing subDataService.morphoAaveV2LeverageManagementSubData', () => {
|
|
810
738
|
describe('encode()', () => {
|
|
811
739
|
const examples: Array<[[string, string, string, string, boolean], [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean]]> = [
|
|
@@ -1170,39 +1170,7 @@ export const compoundV2LeverageManagementSubDataWithoutSubProxy = {
|
|
|
1170
1170
|
\______| \______/ |__| |__| | _| \__/ |____/
|
|
1171
1171
|
*/
|
|
1172
1172
|
|
|
1173
|
-
// ! Any change here will PROBABLY require a change in
|
|
1174
|
-
// ! Double check before changing
|
|
1175
|
-
export const compoundV3LeverageManagementSubData = {
|
|
1176
|
-
encode(
|
|
1177
|
-
market: EthereumAddress,
|
|
1178
|
-
baseToken: EthereumAddress,
|
|
1179
|
-
triggerRepayRatio: number,
|
|
1180
|
-
triggerBoostRatio: number,
|
|
1181
|
-
targetBoostRatio: number,
|
|
1182
|
-
targetRepayRatio: number,
|
|
1183
|
-
boostEnabled: boolean,
|
|
1184
|
-
isEOA: boolean,
|
|
1185
|
-
): SubData {
|
|
1186
|
-
return [
|
|
1187
|
-
market,
|
|
1188
|
-
baseToken,
|
|
1189
|
-
new Dec(triggerRepayRatio).mul(1e16).toString(),
|
|
1190
|
-
new Dec(triggerBoostRatio).mul(1e16).toString(),
|
|
1191
|
-
new Dec(targetBoostRatio).mul(1e16).toString(),
|
|
1192
|
-
new Dec(targetRepayRatio).mul(1e16).toString(),
|
|
1193
|
-
// @ts-ignore // TODO
|
|
1194
|
-
boostEnabled, isEOA,
|
|
1195
|
-
];
|
|
1196
|
-
},
|
|
1197
|
-
decode(subData: SubData): { targetRatio: number } {
|
|
1198
|
-
const weiRatio = AbiCoder.decodeParameter('uint256', subData[3]) as any as string;
|
|
1199
|
-
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
1200
|
-
|
|
1201
|
-
return { targetRatio };
|
|
1202
|
-
},
|
|
1203
|
-
};
|
|
1204
|
-
|
|
1205
|
-
// ! Any change here will PROBABLY require a change in compoundV3L2LiquidationProtectionSubData as well, since it is copy paste
|
|
1173
|
+
// ! Any change here will PROBABLY require a change in compoundV3LiquidationProtectionSubDataWithoutSubProxy as well, since it is copy paste
|
|
1206
1174
|
// ! Double check before changing
|
|
1207
1175
|
export const compoundV3LeverageManagementSubDataWithoutSubProxy = {
|
|
1208
1176
|
encode(
|
|
@@ -1229,70 +1197,28 @@ export const compoundV3LeverageManagementSubDataWithoutSubProxy = {
|
|
|
1229
1197
|
},
|
|
1230
1198
|
};
|
|
1231
1199
|
|
|
1232
|
-
export const
|
|
1200
|
+
export const compoundV3LiquidationProtectionSubDataWithoutSubProxy = {
|
|
1233
1201
|
encode(
|
|
1234
1202
|
market: EthereumAddress,
|
|
1235
1203
|
baseToken: EthereumAddress,
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
triggerBoostRatio: number,
|
|
1239
|
-
targetBoostRatio: number,
|
|
1240
|
-
targetRepayRatio: number,
|
|
1241
|
-
boostEnabled: boolean,
|
|
1242
|
-
isEOA: boolean,
|
|
1204
|
+
targetRatio: number,
|
|
1205
|
+
ratioState: RatioState,
|
|
1243
1206
|
): SubData {
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
new Dec(targetBoostRatio).mul(1e16).toString(),
|
|
1250
|
-
new Dec(targetRepayRatio).mul(1e16).toString(),
|
|
1251
|
-
// @ts-ignore // TODO
|
|
1252
|
-
boostEnabled, isEOA,
|
|
1253
|
-
];
|
|
1254
|
-
},
|
|
1255
|
-
decode(subData: SubData): { targetRatio: number } {
|
|
1256
|
-
const weiRatio = AbiCoder.decodeParameter('uint256', subData[3]) as any as string;
|
|
1257
|
-
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
1258
|
-
|
|
1259
|
-
return { targetRatio };
|
|
1260
|
-
},
|
|
1261
|
-
};
|
|
1262
|
-
export const compoundV3L2LiquidationProtectionSubData = {
|
|
1263
|
-
encode(
|
|
1264
|
-
market: EthereumAddress,
|
|
1265
|
-
baseToken: EthereumAddress,
|
|
1266
|
-
triggerRepayRatio: number,
|
|
1267
|
-
// TODO -> can remove boost stuff ? Not sure if want it to be compatible or not.
|
|
1268
|
-
triggerBoostRatio: number,
|
|
1269
|
-
targetBoostRatio: number,
|
|
1270
|
-
targetRepayRatio: number,
|
|
1271
|
-
boostEnabled: boolean,
|
|
1272
|
-
isEOA: boolean,
|
|
1273
|
-
): string {
|
|
1274
|
-
let subInput = '0x';
|
|
1275
|
-
|
|
1276
|
-
subInput = subInput.concat(market.slice(2));
|
|
1277
|
-
subInput = subInput.concat(baseToken.slice(2));
|
|
1278
|
-
subInput = subInput.concat(new Dec(triggerRepayRatio).mul(1e16).toHex().slice(2)
|
|
1279
|
-
.padStart(32, '0'));
|
|
1280
|
-
subInput = subInput.concat(new Dec(triggerBoostRatio).mul(1e16).toHex().slice(2)
|
|
1281
|
-
.padStart(32, '0'));
|
|
1282
|
-
subInput = subInput.concat(new Dec(targetBoostRatio).mul(1e16).toHex().slice(2)
|
|
1283
|
-
.padStart(32, '0'));
|
|
1284
|
-
subInput = subInput.concat(new Dec(targetRepayRatio).mul(1e16).toHex().slice(2)
|
|
1285
|
-
.padStart(32, '0'));
|
|
1286
|
-
subInput = subInput.concat(boostEnabled ? '01' : '00');
|
|
1287
|
-
subInput = subInput.concat(isEOA ? '01' : '00');
|
|
1288
|
-
|
|
1289
|
-
return subInput;
|
|
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];
|
|
1290
1212
|
},
|
|
1291
|
-
decode(subData: SubData): { targetRatio: number } {
|
|
1292
|
-
const
|
|
1293
|
-
const
|
|
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);
|
|
1294
1218
|
|
|
1295
|
-
return {
|
|
1219
|
+
return {
|
|
1220
|
+
market, baseToken, targetRatio, ratioState,
|
|
1221
|
+
};
|
|
1296
1222
|
},
|
|
1297
1223
|
};
|
|
1298
1224
|
|
|
@@ -1918,8 +1844,9 @@ export const fluidLeverageManagementSubData = {
|
|
|
1918
1844
|
const targetRatioEncoded = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
1919
1845
|
const wrapEthEncoded = AbiCoder.encodeParameter('bool', true);
|
|
1920
1846
|
|
|
1921
|
-
const
|
|
1922
|
-
const
|
|
1847
|
+
const isRepay = ratioState === RatioState.UNDER;
|
|
1848
|
+
const collActionType = isRepay ? CollActionType.WITHDRAW : CollActionType.SUPPLY;
|
|
1849
|
+
const debtActionType = isRepay ? DebtActionType.PAYBACK : DebtActionType.BORROW;
|
|
1923
1850
|
|
|
1924
1851
|
const collActionTypeEncoded = AbiCoder.encodeParameter('uint8', collActionType);
|
|
1925
1852
|
const debtActionTypeEncoded = AbiCoder.encodeParameter('uint8', debtActionType);
|
package/src/services/utils.ts
CHANGED
|
@@ -175,15 +175,15 @@ export function getStopLossAndTakeProfitTypeByCloseStrategyType(
|
|
|
175
175
|
}
|
|
176
176
|
|
|
177
177
|
export function getBundleIdsByNetwork(network: ChainId) {
|
|
178
|
-
switch (network) {
|
|
178
|
+
switch (Number(network)) {
|
|
179
|
+
case ChainId.Ethereum:
|
|
180
|
+
return Bundles.MainnetIds;
|
|
179
181
|
case ChainId.Arbitrum:
|
|
180
182
|
return Bundles.ArbitrumIds;
|
|
181
183
|
case ChainId.Base:
|
|
182
184
|
return Bundles.BaseIds;
|
|
183
|
-
case ChainId.Optimism:
|
|
184
|
-
return Bundles.OptimismIds;
|
|
185
185
|
default:
|
|
186
|
-
|
|
186
|
+
throw new Error(`Unsupported network ${network}`);
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
|
package/src/types/enums.ts
CHANGED
|
@@ -244,14 +244,17 @@ export namespace Bundles {
|
|
|
244
244
|
AAVE_V4_EOA_REPAY_ON_PRICE = 68,
|
|
245
245
|
AAVE_V4_EOA_BOOST_ON_PRICE = 69,
|
|
246
246
|
AAVE_V4_EOA_CLOSE = 70,
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
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,
|
|
255
258
|
}
|
|
256
259
|
|
|
257
260
|
export enum OptimismIds {
|
|
@@ -266,7 +269,8 @@ export namespace Bundles {
|
|
|
266
269
|
AAVE_V3_EOA_REPAY_ON_PRICE = 8,
|
|
267
270
|
AAVE_V3_EOA_BOOST_ON_PRICE = 9,
|
|
268
271
|
AAVE_V3_EOA_CLOSE = 10,
|
|
269
|
-
|
|
272
|
+
AAVE_V3_SW_LIQUIDATION_PROTECTION = 11,
|
|
273
|
+
AAVE_V3_EOA_LIQUIDATION_PROTECTION = 12,
|
|
270
274
|
}
|
|
271
275
|
|
|
272
276
|
export enum BaseIds {
|
|
@@ -297,11 +301,12 @@ export namespace Bundles {
|
|
|
297
301
|
AAVE_V3_EOA_BOOST_ON_PRICE = 26,
|
|
298
302
|
AAVE_V3_EOA_CLOSE = 27,
|
|
299
303
|
MORPHO_BLUE_CLOSE = 28,
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
MORPHO_BLUE_LIQUIDATION_PROTECTION = 31,
|
|
304
|
+
AAVE_V3_SW_LIQUIDATION_PROTECTION = 29,
|
|
305
|
+
FLUID_T1_SW_LIQUIDATION_PROTECTION = 30,
|
|
303
306
|
COMP_V3_SW_LIQUIDATION_PROTECTION = 32,
|
|
304
307
|
COMP_V3_EOA_LIQUIDATION_PROTECTION = 33,
|
|
308
|
+
AAVE_V3_EOA_LIQUIDATION_PROTECTION = 34,
|
|
309
|
+
MORPHO_BLUE_SW_LIQUIDATION_PROTECTION = 35,
|
|
305
310
|
}
|
|
306
311
|
|
|
307
312
|
export enum ArbitrumIds {
|
|
@@ -334,12 +339,12 @@ export namespace Bundles {
|
|
|
334
339
|
MORPHO_BLUE_EOA_REPAY = 26,
|
|
335
340
|
MORPHO_BLUE_EOA_BOOST = 27,
|
|
336
341
|
MORPHO_BLUE_CLOSE = 28,
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
342
|
+
AAVE_V3_SW_LIQUIDATION_PROTECTION = 29,
|
|
343
|
+
FLUID_T1_SW_LIQUIDATION_PROTECTION = 30,
|
|
344
|
+
MORPHO_BLUE_SW_LIQUIDATION_PROTECTION = 31,
|
|
340
345
|
COMP_V3_SW_LIQUIDATION_PROTECTION = 32,
|
|
341
346
|
COMP_V3_EOA_LIQUIDATION_PROTECTION = 33,
|
|
347
|
+
AAVE_V3_EOA_LIQUIDATION_PROTECTION = 34,
|
|
348
|
+
MORPHO_BLUE_EOA_LIQUIDATION_PROTECTION = 35,
|
|
342
349
|
}
|
|
343
350
|
}
|
|
344
|
-
|
|
345
|
-
|