@defisaver/automation-sdk 3.3.13-strategies-refactor-dev → 3.3.14
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/services/strategiesService.js +17 -30
- package/cjs/services/strategySubService.d.ts +11 -5
- package/cjs/services/strategySubService.js +62 -27
- package/cjs/services/strategySubService.test.js +234 -0
- package/cjs/services/subDataService.d.ts +2 -35
- package/cjs/services/subDataService.js +20 -84
- package/cjs/services/subDataService.test.js +42 -0
- package/esm/services/strategiesService.js +17 -30
- package/esm/services/strategySubService.d.ts +11 -5
- package/esm/services/strategySubService.js +58 -26
- package/esm/services/strategySubService.test.js +236 -2
- package/esm/services/subDataService.d.ts +2 -35
- package/esm/services/subDataService.js +19 -82
- package/esm/services/subDataService.test.js +42 -0
- package/package.json +1 -1
- package/src/services/strategiesService.ts +17 -30
- package/src/services/strategySubService.test.ts +279 -0
- package/src/services/strategySubService.ts +111 -60
- package/src/services/subDataService.test.ts +48 -0
- package/src/services/subDataService.ts +28 -107
|
@@ -124,6 +124,28 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
124
124
|
});
|
|
125
125
|
});
|
|
126
126
|
});
|
|
127
|
+
describe('leverageManagement()', () => {
|
|
128
|
+
const examples = [
|
|
129
|
+
[
|
|
130
|
+
[
|
|
131
|
+
5791,
|
|
132
|
+
new decimal_js_1.default('210').mul(1e16).toString(),
|
|
133
|
+
new decimal_js_1.default('290').mul(1e16).toString(),
|
|
134
|
+
new decimal_js_1.default('240').mul(1e16).toString(),
|
|
135
|
+
new decimal_js_1.default('240').mul(1e16).toString(),
|
|
136
|
+
true,
|
|
137
|
+
],
|
|
138
|
+
[
|
|
139
|
+
5791, '210', '290', '240', '240', true,
|
|
140
|
+
]
|
|
141
|
+
]
|
|
142
|
+
];
|
|
143
|
+
examples.forEach(([expected, actual]) => {
|
|
144
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
145
|
+
(0, chai_1.expect)(strategySubService_1.makerEncode.leverageManagement(...actual)).to.eql(expected);
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
});
|
|
127
149
|
describe('leverageManagementWithoutSubProxy()', () => {
|
|
128
150
|
const examples = [
|
|
129
151
|
// Repay scenario (isBoost=false, RatioState.UNDER)
|
|
@@ -223,6 +245,27 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
223
245
|
});
|
|
224
246
|
});
|
|
225
247
|
});
|
|
248
|
+
describe('leverageManagement()', () => {
|
|
249
|
+
const examples = [
|
|
250
|
+
[
|
|
251
|
+
[
|
|
252
|
+
new decimal_js_1.default('210').mul(1e16).toString(),
|
|
253
|
+
new decimal_js_1.default('290').mul(1e16).toString(),
|
|
254
|
+
new decimal_js_1.default('240').mul(1e16).toString(),
|
|
255
|
+
new decimal_js_1.default('240').mul(1e16).toString(),
|
|
256
|
+
false,
|
|
257
|
+
],
|
|
258
|
+
[
|
|
259
|
+
'210', '290', '240', '240', false,
|
|
260
|
+
]
|
|
261
|
+
]
|
|
262
|
+
];
|
|
263
|
+
examples.forEach(([expected, actual]) => {
|
|
264
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
265
|
+
(0, chai_1.expect)(strategySubService_1.liquityEncode.leverageManagement(...actual)).to.eql(expected);
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
});
|
|
226
269
|
describe('paybackFromChickenBondStrategySub()', () => {
|
|
227
270
|
const examples = [
|
|
228
271
|
[
|
|
@@ -309,7 +352,43 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
309
352
|
});
|
|
310
353
|
});
|
|
311
354
|
});
|
|
355
|
+
describe('When testing strategySubService.aaveV2Encode', () => {
|
|
356
|
+
describe('leverageManagement()', () => {
|
|
357
|
+
const examples = [
|
|
358
|
+
[
|
|
359
|
+
[new decimal_js_1.default(160).mul(1e16).toString(), new decimal_js_1.default(220).mul(1e16).toString(), new decimal_js_1.default(180).mul(1e16).toString(), new decimal_js_1.default(190).mul(1e16).toString(), true],
|
|
360
|
+
[160, 220, 180, 190, true]
|
|
361
|
+
],
|
|
362
|
+
[
|
|
363
|
+
[new decimal_js_1.default(160).mul(1e16).toString(), new decimal_js_1.default(200).mul(1e16).toString(), new decimal_js_1.default(180).mul(1e16).toString(), new decimal_js_1.default(190).mul(1e16).toString(), false],
|
|
364
|
+
[160, 200, 180, 190, false]
|
|
365
|
+
],
|
|
366
|
+
];
|
|
367
|
+
examples.forEach(([expected, actual]) => {
|
|
368
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
369
|
+
(0, chai_1.expect)(strategySubService_1.aaveV2Encode.leverageManagement(...actual)).to.eql(expected);
|
|
370
|
+
});
|
|
371
|
+
});
|
|
372
|
+
});
|
|
373
|
+
});
|
|
312
374
|
describe('When testing strategySubService.aaveV3Encode', () => {
|
|
375
|
+
describe('leverageManagement()', () => {
|
|
376
|
+
const examples = [
|
|
377
|
+
[
|
|
378
|
+
'0x000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e000001',
|
|
379
|
+
[160, 220, 180, 190, true]
|
|
380
|
+
],
|
|
381
|
+
[
|
|
382
|
+
'0x000000000000000016345785d8a0000000000000000000001bc16d674ec80000000000000000000018fae27693b4000000000000000000001a5e27eef13e000000',
|
|
383
|
+
[160, 200, 180, 190, false]
|
|
384
|
+
],
|
|
385
|
+
];
|
|
386
|
+
examples.forEach(([expected, actual]) => {
|
|
387
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
388
|
+
(0, chai_1.expect)(strategySubService_1.aaveV3Encode.leverageManagement(...actual)).to.eql(expected);
|
|
389
|
+
});
|
|
390
|
+
});
|
|
391
|
+
});
|
|
313
392
|
describe('closeToAsset()', () => {
|
|
314
393
|
const examples = [
|
|
315
394
|
[
|
|
@@ -876,7 +955,69 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
876
955
|
});
|
|
877
956
|
});
|
|
878
957
|
});
|
|
958
|
+
describe('When testing strategySubService.compoundV2Encode', () => {
|
|
959
|
+
describe('leverageManagement()', () => {
|
|
960
|
+
const examples = [
|
|
961
|
+
[
|
|
962
|
+
[new decimal_js_1.default(160).mul(1e16).toString(), new decimal_js_1.default(220).mul(1e16).toString(), new decimal_js_1.default(180).mul(1e16).toString(), new decimal_js_1.default(190).mul(1e16).toString(), true],
|
|
963
|
+
[160, 220, 180, 190, true]
|
|
964
|
+
],
|
|
965
|
+
[
|
|
966
|
+
[new decimal_js_1.default(160).mul(1e16).toString(), new decimal_js_1.default(200).mul(1e16).toString(), new decimal_js_1.default(180).mul(1e16).toString(), new decimal_js_1.default(190).mul(1e16).toString(), false],
|
|
967
|
+
[160, 200, 180, 190, false]
|
|
968
|
+
],
|
|
969
|
+
];
|
|
970
|
+
examples.forEach(([expected, actual]) => {
|
|
971
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
972
|
+
(0, chai_1.expect)(strategySubService_1.compoundV2Encode.leverageManagement(...actual)).to.eql(expected);
|
|
973
|
+
});
|
|
974
|
+
});
|
|
975
|
+
});
|
|
976
|
+
});
|
|
879
977
|
describe('When testing strategySubService.compoundV3Encode', () => {
|
|
978
|
+
describe('leverageManagement()', () => {
|
|
979
|
+
const examples = [
|
|
980
|
+
[
|
|
981
|
+
[
|
|
982
|
+
web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
983
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
|
|
984
|
+
new decimal_js_1.default(160).mul(1e16).toString(),
|
|
985
|
+
new decimal_js_1.default(220).mul(1e16).toString(),
|
|
986
|
+
new decimal_js_1.default(180).mul(1e16).toString(),
|
|
987
|
+
new decimal_js_1.default(190).mul(1e16).toString(),
|
|
988
|
+
true, false,
|
|
989
|
+
],
|
|
990
|
+
[
|
|
991
|
+
web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
992
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
|
|
993
|
+
160, 220, 180, 190,
|
|
994
|
+
true, false,
|
|
995
|
+
]
|
|
996
|
+
],
|
|
997
|
+
[
|
|
998
|
+
[
|
|
999
|
+
web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
1000
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
|
|
1001
|
+
new decimal_js_1.default(160).mul(1e16).toString(),
|
|
1002
|
+
new decimal_js_1.default(210).mul(1e16).toString(),
|
|
1003
|
+
new decimal_js_1.default(180).mul(1e16).toString(),
|
|
1004
|
+
new decimal_js_1.default(190).mul(1e16).toString(),
|
|
1005
|
+
false, true,
|
|
1006
|
+
],
|
|
1007
|
+
[
|
|
1008
|
+
web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
1009
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
|
|
1010
|
+
160, 210, 180, 190,
|
|
1011
|
+
false, true,
|
|
1012
|
+
]
|
|
1013
|
+
],
|
|
1014
|
+
];
|
|
1015
|
+
examples.forEach(([expected, actual]) => {
|
|
1016
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1017
|
+
(0, chai_1.expect)(strategySubService_1.compoundV3Encode.leverageManagement(...actual)).to.eql(expected);
|
|
1018
|
+
});
|
|
1019
|
+
});
|
|
1020
|
+
});
|
|
880
1021
|
describe('leverageManagementOnPrice()', () => {
|
|
881
1022
|
const examples = [
|
|
882
1023
|
[
|
|
@@ -1051,6 +1192,51 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1051
1192
|
});
|
|
1052
1193
|
});
|
|
1053
1194
|
});
|
|
1195
|
+
describe('limitOrder()', () => {
|
|
1196
|
+
const examples = [
|
|
1197
|
+
[
|
|
1198
|
+
[
|
|
1199
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
|
|
1200
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
|
|
1201
|
+
'2131',
|
|
1202
|
+
'0.53123',
|
|
1203
|
+
'1696590921159',
|
|
1204
|
+
`${enums_1.OrderType.STOP_LOSS}`
|
|
1205
|
+
],
|
|
1206
|
+
[
|
|
1207
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
|
|
1208
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
|
|
1209
|
+
'2131',
|
|
1210
|
+
'0.53123',
|
|
1211
|
+
1696590921159,
|
|
1212
|
+
enums_1.OrderType.STOP_LOSS
|
|
1213
|
+
]
|
|
1214
|
+
],
|
|
1215
|
+
[
|
|
1216
|
+
[
|
|
1217
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('LINK', enums_1.ChainId.Arbitrum).address),
|
|
1218
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Arbitrum).address),
|
|
1219
|
+
'2131',
|
|
1220
|
+
'0.43123',
|
|
1221
|
+
'1646590921159',
|
|
1222
|
+
`${enums_1.OrderType.TAKE_PROFIT}`
|
|
1223
|
+
],
|
|
1224
|
+
[
|
|
1225
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('LINK', enums_1.ChainId.Arbitrum).address),
|
|
1226
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Arbitrum).address),
|
|
1227
|
+
'2131',
|
|
1228
|
+
'0.43123',
|
|
1229
|
+
1646590921159,
|
|
1230
|
+
enums_1.OrderType.TAKE_PROFIT
|
|
1231
|
+
]
|
|
1232
|
+
],
|
|
1233
|
+
];
|
|
1234
|
+
examples.forEach(([expected, actual]) => {
|
|
1235
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1236
|
+
(0, chai_1.expect)(strategySubService_1.exchangeEncode.limitOrder(...actual)).to.eql(expected);
|
|
1237
|
+
});
|
|
1238
|
+
});
|
|
1239
|
+
});
|
|
1054
1240
|
});
|
|
1055
1241
|
describe('When testing strategySubService.crvUSDEncode', () => {
|
|
1056
1242
|
describe('leverageManagement()', () => {
|
|
@@ -1264,7 +1450,55 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1264
1450
|
});
|
|
1265
1451
|
});
|
|
1266
1452
|
});
|
|
1453
|
+
describe('When testing strategySubService.compoundV3L2Encode', () => {
|
|
1454
|
+
describe('leverageManagement()', () => {
|
|
1455
|
+
const examples = [
|
|
1456
|
+
[
|
|
1457
|
+
'0x0313D212133AFab8F2b829B1066c7e43caD94e2c0213D212133AfaB8F2b829B1066C7E43cAD94E2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e00000100',
|
|
1458
|
+
[
|
|
1459
|
+
web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'),
|
|
1460
|
+
web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'),
|
|
1461
|
+
160, 220, 180, 190,
|
|
1462
|
+
true,
|
|
1463
|
+
false,
|
|
1464
|
+
],
|
|
1465
|
+
],
|
|
1466
|
+
[
|
|
1467
|
+
'0x0313D212133AFab8F2b829B1066c7e43caD94e2c0413d212133afAb8F2B829b1066C7e43cAd94e2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000000f43fc2c04ee00000000',
|
|
1468
|
+
[
|
|
1469
|
+
web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'),
|
|
1470
|
+
web3Utils.toChecksumAddress('0x0413d212133AFaB8F2B829B1066c7E43cAd94E2c'),
|
|
1471
|
+
160, 220, 180, 110,
|
|
1472
|
+
false,
|
|
1473
|
+
false,
|
|
1474
|
+
],
|
|
1475
|
+
],
|
|
1476
|
+
];
|
|
1477
|
+
examples.forEach(([expected, actual]) => {
|
|
1478
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1479
|
+
(0, chai_1.expect)(strategySubService_1.compoundV3L2Encode.leverageManagement(...actual)).to.eql(expected);
|
|
1480
|
+
});
|
|
1481
|
+
});
|
|
1482
|
+
});
|
|
1483
|
+
});
|
|
1267
1484
|
describe('When testing strategySubService.sparkEncode', () => {
|
|
1485
|
+
describe('leverageManagement()', () => {
|
|
1486
|
+
const examples = [
|
|
1487
|
+
[
|
|
1488
|
+
'0x0000000000000000136dcc951d8c00000000000000000000214e8348c4f0000000000000000000001d24b2dfac52000000000000000000001a5e27eef13e000001',
|
|
1489
|
+
[140, 240, 210, 190, true]
|
|
1490
|
+
],
|
|
1491
|
+
[
|
|
1492
|
+
'0x0000000000000000130337bdce49000000000000000000001988fe4052b800000000000000000000281b57b028e1000000000000000000002223acf76376000000',
|
|
1493
|
+
[137, 184, 289, 246, false]
|
|
1494
|
+
]
|
|
1495
|
+
];
|
|
1496
|
+
examples.forEach(([expected, actual]) => {
|
|
1497
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1498
|
+
(0, chai_1.expect)(strategySubService_1.sparkEncode.leverageManagement(...actual)).to.eql(expected);
|
|
1499
|
+
});
|
|
1500
|
+
});
|
|
1501
|
+
});
|
|
1268
1502
|
describe('leverageManagementOnPrice()', () => {
|
|
1269
1503
|
const examples = [
|
|
1270
1504
|
[
|
|
@@ -89,13 +89,6 @@ export declare const liquityLeverageManagementSubData: {
|
|
|
89
89
|
targetRatio: number;
|
|
90
90
|
};
|
|
91
91
|
};
|
|
92
|
-
export declare const liquityLeverageManagementSubDataWithoutSubProxy: {
|
|
93
|
-
encode(targetRatio: number, ratioState: RatioState): string[];
|
|
94
|
-
decode(subData: string[]): {
|
|
95
|
-
targetRatio: number;
|
|
96
|
-
ratioState: RatioState;
|
|
97
|
-
};
|
|
98
|
-
};
|
|
99
92
|
export declare const liquityCloseSubData: {
|
|
100
93
|
encode(closeToAssetAddr: EthereumAddress, chainId?: ChainId, collAddr?: EthereumAddress, debtAddr?: EthereumAddress): string[];
|
|
101
94
|
decode(subData: string[]): {
|
|
@@ -184,14 +177,6 @@ export declare const aaveV2LeverageManagementSubData: {
|
|
|
184
177
|
targetRatio: number;
|
|
185
178
|
};
|
|
186
179
|
};
|
|
187
|
-
export declare const aaveV2LeverageManagementSubDataWithoutSubProxy: {
|
|
188
|
-
encode(market: EthereumAddress, targetRatio: number, ratioState: RatioState): string[];
|
|
189
|
-
decode(subData: string[]): {
|
|
190
|
-
market: EthereumAddress;
|
|
191
|
-
targetRatio: number;
|
|
192
|
-
ratioState: RatioState;
|
|
193
|
-
};
|
|
194
|
-
};
|
|
195
180
|
/**
|
|
196
181
|
___ ___ ____ ____ _______ ____ ____ ____
|
|
197
182
|
/ \ / \ \ \ / / | ____| \ \ / / |___ \
|
|
@@ -335,13 +320,6 @@ export declare const compoundV2LeverageManagementSubData: {
|
|
|
335
320
|
targetRatio: number;
|
|
336
321
|
};
|
|
337
322
|
};
|
|
338
|
-
export declare const compoundV2LeverageManagementSubDataWithoutSubProxy: {
|
|
339
|
-
encode(targetRatio: number, ratioState: RatioState): string[];
|
|
340
|
-
decode(subData: string[]): {
|
|
341
|
-
targetRatio: number;
|
|
342
|
-
ratioState: RatioState;
|
|
343
|
-
};
|
|
344
|
-
};
|
|
345
323
|
/**
|
|
346
324
|
______ ______ .___ ___. .______ ____ ____ ____
|
|
347
325
|
/ | / __ \ | \/ | | _ \ \ \ / / |___ \
|
|
@@ -356,13 +334,10 @@ export declare const compoundV3LeverageManagementSubData: {
|
|
|
356
334
|
targetRatio: number;
|
|
357
335
|
};
|
|
358
336
|
};
|
|
359
|
-
export declare const
|
|
360
|
-
encode(market: EthereumAddress, baseToken: EthereumAddress,
|
|
337
|
+
export declare const compoundV3L2LeverageManagementSubData: {
|
|
338
|
+
encode(market: EthereumAddress, baseToken: EthereumAddress, triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean, isEOA: boolean): string;
|
|
361
339
|
decode(subData: string[]): {
|
|
362
|
-
market: EthereumAddress;
|
|
363
|
-
baseToken: EthereumAddress;
|
|
364
340
|
targetRatio: number;
|
|
365
|
-
ratioState: RatioState;
|
|
366
341
|
};
|
|
367
342
|
};
|
|
368
343
|
export declare const compoundV3LeverageManagementOnPriceSubData: {
|
|
@@ -411,14 +386,6 @@ export declare const exchangeLimitOrderSubData: {
|
|
|
411
386
|
amount: string;
|
|
412
387
|
};
|
|
413
388
|
};
|
|
414
|
-
export declare const exchangeLimitOrderSubDataWithoutSubProxy: {
|
|
415
|
-
encode(fromToken: EthereumAddress, toToken: EthereumAddress, amount: string): string[];
|
|
416
|
-
decode: (subData: string[], chainId: ChainId) => {
|
|
417
|
-
fromToken: string;
|
|
418
|
-
toToken: string;
|
|
419
|
-
amount: string;
|
|
420
|
-
};
|
|
421
|
-
};
|
|
422
389
|
/**
|
|
423
390
|
_______..______ ___ .______ __ ___
|
|
424
391
|
/ || _ \ / \ | _ \ | |/ /
|
|
@@ -3,8 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.morphoBlueCloseOnPriceSubData = exports.morphoBlueLeverageManagementOnPriceSubData = exports.morphoBlueLeverageManagementSubData = exports.crvUSDPaybackSubData = exports.crvUSDLeverageManagementSubData = exports.sparkCollateralSwitchSubData = exports.sparkLeverageManagementOnPriceSubData = exports.sparkCloseGenericSubData = exports.sparkLeverageManagementSubDataWithoutSubProxy = exports.sparkLeverageManagementSubData = exports.
|
|
7
|
-
exports.fluidLeverageManagementSubData = void 0;
|
|
6
|
+
exports.fluidLeverageManagementSubData = exports.morphoBlueCloseOnPriceSubData = exports.morphoBlueLeverageManagementOnPriceSubData = exports.morphoBlueLeverageManagementSubData = exports.crvUSDPaybackSubData = exports.crvUSDLeverageManagementSubData = exports.sparkCollateralSwitchSubData = exports.sparkLeverageManagementOnPriceSubData = exports.sparkCloseGenericSubData = exports.sparkLeverageManagementSubDataWithoutSubProxy = exports.sparkLeverageManagementSubData = exports.exchangeLimitOrderSubData = exports.exchangeDcaSubData = exports.compoundV3CloseSubData = exports.compoundV3LeverageManagementOnPriceSubData = exports.compoundV3L2LeverageManagementSubData = exports.compoundV3LeverageManagementSubData = exports.compoundV2LeverageManagementSubData = exports.aaveV4CollateralSwitchSubData = exports.aaveV4CloseSubData = exports.aaveV4LeverageManagementOnPriceSubData = exports.aaveV4LeverageManagementSubData = exports.aaveV3LeverageManagementOnPriceSubData = exports.aaveV3QuotePriceSubData = exports.aaveV3CollateralSwitchSubData = exports.aaveV3CloseGenericSubData = exports.aaveV3LeverageManagementOnPriceGeneric = exports.aaveV3LeverageManagementSubDataWithoutSubProxy = exports.aaveV3LeverageManagementSubData = exports.aaveV2LeverageManagementSubData = exports.liquityV2PaybackSubData = exports.liquityV2LeverageManagementOnPriceSubData = exports.liquityV2CloseSubData = exports.liquityV2LeverageManagementSubData = exports.liquityDebtInFrontRepaySubData = exports.liquityDsrSupplySubData = exports.liquityDsrPaybackSubData = exports.liquityCloseSubData = exports.liquityLeverageManagementSubData = exports.liquityRepayFromSavingsSubData = exports.makerLeverageManagementWithoutSubProxy = exports.makerLeverageManagementSubData = exports.makerCloseSubData = exports.makerRepayFromSavingsSubData = exports.liquityPaybackUsingChickenBondSubData = exports.cBondsRebondSubData = exports.morphoAaveV2LeverageManagementSubData = void 0;
|
|
8
7
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
9
8
|
const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
|
|
10
9
|
const web3_utils_1 = require("web3-utils");
|
|
@@ -168,23 +167,6 @@ exports.liquityLeverageManagementSubData = {
|
|
|
168
167
|
return { targetRatio };
|
|
169
168
|
},
|
|
170
169
|
};
|
|
171
|
-
exports.liquityLeverageManagementSubDataWithoutSubProxy = {
|
|
172
|
-
encode(targetRatio, ratioState) {
|
|
173
|
-
const encodedRatioState = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
174
|
-
const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
175
|
-
const isRepay = ratioState === enums_1.RatioState.UNDER;
|
|
176
|
-
const collActionType = isRepay ? enums_1.CollActionType.WITHDRAW : enums_1.CollActionType.SUPPLY;
|
|
177
|
-
const debtActionType = isRepay ? enums_1.DebtActionType.PAYBACK : enums_1.DebtActionType.BORROW;
|
|
178
|
-
const collActionTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', collActionType);
|
|
179
|
-
const debtActionTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', debtActionType);
|
|
180
|
-
return [encodedRatioState, encodedTargetRatio, collActionTypeEncoded, debtActionTypeEncoded];
|
|
181
|
-
},
|
|
182
|
-
decode(subData) {
|
|
183
|
-
const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[0]);
|
|
184
|
-
const targetRatio = (0, utils_1.weiToRatioPercentage)(web3_eth_abi_1.default.decodeParameter('uint256', subData[1]));
|
|
185
|
-
return { targetRatio, ratioState };
|
|
186
|
-
},
|
|
187
|
-
};
|
|
188
170
|
exports.liquityCloseSubData = {
|
|
189
171
|
encode(closeToAssetAddr, chainId = enums_1.ChainId.Ethereum, collAddr, debtAddr) {
|
|
190
172
|
const _collAddr = collAddr || (0, tokens_1.getAssetInfo)('WETH', chainId).address;
|
|
@@ -416,25 +398,6 @@ exports.aaveV2LeverageManagementSubData = {
|
|
|
416
398
|
return { targetRatio };
|
|
417
399
|
},
|
|
418
400
|
};
|
|
419
|
-
exports.aaveV2LeverageManagementSubDataWithoutSubProxy = {
|
|
420
|
-
encode(market, targetRatio, ratioState) {
|
|
421
|
-
const encodedMarket = web3_eth_abi_1.default.encodeParameter('address', market);
|
|
422
|
-
const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
423
|
-
const encodedRatioState = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
424
|
-
const isBoost = ratioState === enums_1.RatioState.OVER;
|
|
425
|
-
if (isBoost) {
|
|
426
|
-
const enableAsCollEncoded = web3_eth_abi_1.default.encodeParameter('uint256', 1);
|
|
427
|
-
return [encodedMarket, encodedTargetRatio, encodedRatioState, enableAsCollEncoded];
|
|
428
|
-
}
|
|
429
|
-
return [encodedMarket, encodedTargetRatio, encodedRatioState];
|
|
430
|
-
},
|
|
431
|
-
decode(subData) {
|
|
432
|
-
const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
433
|
-
const targetRatio = (0, utils_1.weiToRatioPercentage)(web3_eth_abi_1.default.decodeParameter('uint256', subData[1]));
|
|
434
|
-
const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[2]);
|
|
435
|
-
return { market, targetRatio, ratioState };
|
|
436
|
-
},
|
|
437
|
-
};
|
|
438
401
|
/**
|
|
439
402
|
___ ___ ____ ____ _______ ____ ____ ____
|
|
440
403
|
/ \ / \ \ \ / / | ____| \ \ / / |___ \
|
|
@@ -789,23 +752,6 @@ exports.compoundV2LeverageManagementSubData = {
|
|
|
789
752
|
return { targetRatio };
|
|
790
753
|
},
|
|
791
754
|
};
|
|
792
|
-
exports.compoundV2LeverageManagementSubDataWithoutSubProxy = {
|
|
793
|
-
encode(targetRatio, ratioState) {
|
|
794
|
-
const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
795
|
-
const encodedRatioState = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
796
|
-
const isBoost = ratioState === enums_1.RatioState.OVER;
|
|
797
|
-
if (isBoost) {
|
|
798
|
-
const enableAsCollEncoded = web3_eth_abi_1.default.encodeParameter('uint256', 1);
|
|
799
|
-
return [encodedTargetRatio, encodedRatioState, enableAsCollEncoded];
|
|
800
|
-
}
|
|
801
|
-
return [encodedTargetRatio, encodedRatioState];
|
|
802
|
-
},
|
|
803
|
-
decode(subData) {
|
|
804
|
-
const targetRatio = (0, utils_1.weiToRatioPercentage)(web3_eth_abi_1.default.decodeParameter('uint256', subData[0]));
|
|
805
|
-
const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[1]);
|
|
806
|
-
return { targetRatio, ratioState };
|
|
807
|
-
},
|
|
808
|
-
};
|
|
809
755
|
/**
|
|
810
756
|
______ ______ .___ ___. .______ ____ ____ ____
|
|
811
757
|
/ | / __ \ | \/ | | _ \ \ \ / / |___ \
|
|
@@ -833,22 +779,27 @@ exports.compoundV3LeverageManagementSubData = {
|
|
|
833
779
|
return { targetRatio };
|
|
834
780
|
},
|
|
835
781
|
};
|
|
836
|
-
exports.
|
|
837
|
-
encode(market, baseToken,
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
782
|
+
exports.compoundV3L2LeverageManagementSubData = {
|
|
783
|
+
encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled, isEOA) {
|
|
784
|
+
let subInput = '0x';
|
|
785
|
+
subInput = subInput.concat(market.slice(2));
|
|
786
|
+
subInput = subInput.concat(baseToken.slice(2));
|
|
787
|
+
subInput = subInput.concat(new decimal_js_1.default(triggerRepayRatio).mul(1e16).toHex().slice(2)
|
|
788
|
+
.padStart(32, '0'));
|
|
789
|
+
subInput = subInput.concat(new decimal_js_1.default(triggerBoostRatio).mul(1e16).toHex().slice(2)
|
|
790
|
+
.padStart(32, '0'));
|
|
791
|
+
subInput = subInput.concat(new decimal_js_1.default(targetBoostRatio).mul(1e16).toHex().slice(2)
|
|
792
|
+
.padStart(32, '0'));
|
|
793
|
+
subInput = subInput.concat(new decimal_js_1.default(targetRepayRatio).mul(1e16).toHex().slice(2)
|
|
794
|
+
.padStart(32, '0'));
|
|
795
|
+
subInput = subInput.concat(boostEnabled ? '01' : '00');
|
|
796
|
+
subInput = subInput.concat(isEOA ? '01' : '00');
|
|
797
|
+
return subInput;
|
|
843
798
|
},
|
|
844
799
|
decode(subData) {
|
|
845
|
-
const
|
|
846
|
-
const
|
|
847
|
-
|
|
848
|
-
const targetRatio = (0, utils_1.weiToRatioPercentage)(web3_eth_abi_1.default.decodeParameter('uint256', subData[3]));
|
|
849
|
-
return {
|
|
850
|
-
market, baseToken, targetRatio, ratioState,
|
|
851
|
-
};
|
|
800
|
+
const ratioWei = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]);
|
|
801
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(ratioWei);
|
|
802
|
+
return { targetRatio };
|
|
852
803
|
},
|
|
853
804
|
};
|
|
854
805
|
exports.compoundV3LeverageManagementOnPriceSubData = {
|
|
@@ -954,21 +905,6 @@ exports.exchangeLimitOrderSubData = {
|
|
|
954
905
|
return { fromToken, toToken, amount };
|
|
955
906
|
},
|
|
956
907
|
};
|
|
957
|
-
exports.exchangeLimitOrderSubDataWithoutSubProxy = {
|
|
958
|
-
encode(fromToken, toToken, amount) {
|
|
959
|
-
return [
|
|
960
|
-
web3_eth_abi_1.default.encodeParameter('address', fromToken),
|
|
961
|
-
web3_eth_abi_1.default.encodeParameter('address', toToken),
|
|
962
|
-
web3_eth_abi_1.default.encodeParameter('uint256', amount),
|
|
963
|
-
];
|
|
964
|
-
},
|
|
965
|
-
decode: (subData, chainId) => {
|
|
966
|
-
const fromToken = web3_eth_abi_1.default.decodeParameter('address', subData[0]).toString();
|
|
967
|
-
const toToken = web3_eth_abi_1.default.decodeParameter('address', subData[1]).toString();
|
|
968
|
-
const amount = (0, tokens_1.assetAmountInEth)(web3_eth_abi_1.default.decodeParameter('uint256', subData[2]).toString(), (0, tokens_1.getAssetInfoByAddress)(fromToken, chainId).symbol);
|
|
969
|
-
return { fromToken, toToken, amount };
|
|
970
|
-
},
|
|
971
|
-
};
|
|
972
908
|
/**
|
|
973
909
|
_______..______ ___ .______ __ ___
|
|
974
910
|
/ || _ \ / \ | _ \ | |/ /
|
|
@@ -1337,6 +1337,48 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1337
1337
|
});
|
|
1338
1338
|
});
|
|
1339
1339
|
});
|
|
1340
|
+
describe('When testing subDataService.compoundV3L2LeverageManagementSubData', () => {
|
|
1341
|
+
describe('encode()', () => {
|
|
1342
|
+
const examples = [
|
|
1343
|
+
[
|
|
1344
|
+
'0x0313D212133AFab8F2b829B1066c7e43caD94e2c0213D212133AfaB8F2b829B1066C7E43cAD94E2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e00000100',
|
|
1345
|
+
[web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'), web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'), 160, 220, 180, 190, true, false]
|
|
1346
|
+
],
|
|
1347
|
+
[
|
|
1348
|
+
'0x0313D212133AFab8F2b829B1066c7e43caD94e2c0413d212133afAb8F2B829b1066C7e43cAd94e2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000000f43fc2c04ee00000000',
|
|
1349
|
+
[web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'), web3Utils.toChecksumAddress('0x0413d212133AFaB8F2B829B1066c7E43cAd94E2c'), 160, 220, 180, 110, false, false]
|
|
1350
|
+
],
|
|
1351
|
+
];
|
|
1352
|
+
examples.forEach(([expected, actual]) => {
|
|
1353
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1354
|
+
(0, chai_1.expect)(subDataService.compoundV3L2LeverageManagementSubData.encode(...actual)).to.eql(expected);
|
|
1355
|
+
});
|
|
1356
|
+
});
|
|
1357
|
+
});
|
|
1358
|
+
describe('decode()', () => {
|
|
1359
|
+
const examples = [
|
|
1360
|
+
[
|
|
1361
|
+
{ targetRatio: 200 },
|
|
1362
|
+
[
|
|
1363
|
+
'0x0000000000000000000000000313d212133AFaB8F2B829B1066c7E43cAd94E2c', '0x0000000000000000000000000213d212133AFaB8F2B829B1066c7E43cAd94E2c',
|
|
1364
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
1365
|
+
],
|
|
1366
|
+
],
|
|
1367
|
+
[
|
|
1368
|
+
{ targetRatio: 123 },
|
|
1369
|
+
[
|
|
1370
|
+
'0x0000000000000000000000000313d212133AFaB8F2B829B1066c7E43cAd94E2c', '0x0000000000000000000000000413d212133AFaB8F2B829B1066c7E43cAd94E2c',
|
|
1371
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
|
|
1372
|
+
],
|
|
1373
|
+
],
|
|
1374
|
+
];
|
|
1375
|
+
examples.forEach(([expected, actual]) => {
|
|
1376
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1377
|
+
(0, chai_1.expect)(subDataService.compoundV3L2LeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
1378
|
+
});
|
|
1379
|
+
});
|
|
1380
|
+
});
|
|
1381
|
+
});
|
|
1340
1382
|
describe('When testing subDataService.morphoBlueLeverageManagementSubData', () => {
|
|
1341
1383
|
describe('encode()', () => {
|
|
1342
1384
|
const examples = [
|