@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
|
@@ -3,9 +3,9 @@ import Dec from 'decimal.js';
|
|
|
3
3
|
import { otherAddresses } from '@defisaver/sdk';
|
|
4
4
|
import { getAssetInfo, MAXUINT } from '@defisaver/tokens';
|
|
5
5
|
import * as web3Utils from 'web3-utils';
|
|
6
|
-
import { Bundles, ChainId, CloseToAssetType, RatioState, Strategies } from '../types/enums';
|
|
6
|
+
import { Bundles, ChainId, CloseToAssetType, OrderType, RatioState, Strategies } from '../types/enums';
|
|
7
7
|
import '../configuration';
|
|
8
|
-
import { chickenBondsEncode, liquityEncode, makerEncode, aaveV3Encode, compoundV3Encode, morphoAaveV2Encode, exchangeEncode, crvUSDEncode, morphoBlueEncode, sparkEncode, aaveV4Encode, } from './strategySubService';
|
|
8
|
+
import { aaveV2Encode, chickenBondsEncode, liquityEncode, makerEncode, aaveV3Encode, compoundV2Encode, compoundV3Encode, morphoAaveV2Encode, exchangeEncode, crvUSDEncode, compoundV3L2Encode, morphoBlueEncode, sparkEncode, aaveV4Encode, } from './strategySubService';
|
|
9
9
|
describe('Feature: strategySubService.ts', () => {
|
|
10
10
|
describe('When testing strategySubService.makerEncode', () => {
|
|
11
11
|
// @ts-ignore // TODO - this requires change in @defisaver/tokens
|
|
@@ -96,6 +96,28 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
96
96
|
});
|
|
97
97
|
});
|
|
98
98
|
});
|
|
99
|
+
describe('leverageManagement()', () => {
|
|
100
|
+
const examples = [
|
|
101
|
+
[
|
|
102
|
+
[
|
|
103
|
+
5791,
|
|
104
|
+
new Dec('210').mul(1e16).toString(),
|
|
105
|
+
new Dec('290').mul(1e16).toString(),
|
|
106
|
+
new Dec('240').mul(1e16).toString(),
|
|
107
|
+
new Dec('240').mul(1e16).toString(),
|
|
108
|
+
true,
|
|
109
|
+
],
|
|
110
|
+
[
|
|
111
|
+
5791, '210', '290', '240', '240', true,
|
|
112
|
+
]
|
|
113
|
+
]
|
|
114
|
+
];
|
|
115
|
+
examples.forEach(([expected, actual]) => {
|
|
116
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
117
|
+
expect(makerEncode.leverageManagement(...actual)).to.eql(expected);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
});
|
|
99
121
|
describe('leverageManagementWithoutSubProxy()', () => {
|
|
100
122
|
const examples = [
|
|
101
123
|
// Repay scenario (isBoost=false, RatioState.UNDER)
|
|
@@ -195,6 +217,27 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
195
217
|
});
|
|
196
218
|
});
|
|
197
219
|
});
|
|
220
|
+
describe('leverageManagement()', () => {
|
|
221
|
+
const examples = [
|
|
222
|
+
[
|
|
223
|
+
[
|
|
224
|
+
new Dec('210').mul(1e16).toString(),
|
|
225
|
+
new Dec('290').mul(1e16).toString(),
|
|
226
|
+
new Dec('240').mul(1e16).toString(),
|
|
227
|
+
new Dec('240').mul(1e16).toString(),
|
|
228
|
+
false,
|
|
229
|
+
],
|
|
230
|
+
[
|
|
231
|
+
'210', '290', '240', '240', false,
|
|
232
|
+
]
|
|
233
|
+
]
|
|
234
|
+
];
|
|
235
|
+
examples.forEach(([expected, actual]) => {
|
|
236
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
237
|
+
expect(liquityEncode.leverageManagement(...actual)).to.eql(expected);
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
});
|
|
198
241
|
describe('paybackFromChickenBondStrategySub()', () => {
|
|
199
242
|
const examples = [
|
|
200
243
|
[
|
|
@@ -281,7 +324,43 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
281
324
|
});
|
|
282
325
|
});
|
|
283
326
|
});
|
|
327
|
+
describe('When testing strategySubService.aaveV2Encode', () => {
|
|
328
|
+
describe('leverageManagement()', () => {
|
|
329
|
+
const examples = [
|
|
330
|
+
[
|
|
331
|
+
[new Dec(160).mul(1e16).toString(), new Dec(220).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), true],
|
|
332
|
+
[160, 220, 180, 190, true]
|
|
333
|
+
],
|
|
334
|
+
[
|
|
335
|
+
[new Dec(160).mul(1e16).toString(), new Dec(200).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), false],
|
|
336
|
+
[160, 200, 180, 190, false]
|
|
337
|
+
],
|
|
338
|
+
];
|
|
339
|
+
examples.forEach(([expected, actual]) => {
|
|
340
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
341
|
+
expect(aaveV2Encode.leverageManagement(...actual)).to.eql(expected);
|
|
342
|
+
});
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
});
|
|
284
346
|
describe('When testing strategySubService.aaveV3Encode', () => {
|
|
347
|
+
describe('leverageManagement()', () => {
|
|
348
|
+
const examples = [
|
|
349
|
+
[
|
|
350
|
+
'0x000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e000001',
|
|
351
|
+
[160, 220, 180, 190, true]
|
|
352
|
+
],
|
|
353
|
+
[
|
|
354
|
+
'0x000000000000000016345785d8a0000000000000000000001bc16d674ec80000000000000000000018fae27693b4000000000000000000001a5e27eef13e000000',
|
|
355
|
+
[160, 200, 180, 190, false]
|
|
356
|
+
],
|
|
357
|
+
];
|
|
358
|
+
examples.forEach(([expected, actual]) => {
|
|
359
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
360
|
+
expect(aaveV3Encode.leverageManagement(...actual)).to.eql(expected);
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
});
|
|
285
364
|
describe('closeToAsset()', () => {
|
|
286
365
|
const examples = [
|
|
287
366
|
[
|
|
@@ -848,7 +927,69 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
848
927
|
});
|
|
849
928
|
});
|
|
850
929
|
});
|
|
930
|
+
describe('When testing strategySubService.compoundV2Encode', () => {
|
|
931
|
+
describe('leverageManagement()', () => {
|
|
932
|
+
const examples = [
|
|
933
|
+
[
|
|
934
|
+
[new Dec(160).mul(1e16).toString(), new Dec(220).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), true],
|
|
935
|
+
[160, 220, 180, 190, true]
|
|
936
|
+
],
|
|
937
|
+
[
|
|
938
|
+
[new Dec(160).mul(1e16).toString(), new Dec(200).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), false],
|
|
939
|
+
[160, 200, 180, 190, false]
|
|
940
|
+
],
|
|
941
|
+
];
|
|
942
|
+
examples.forEach(([expected, actual]) => {
|
|
943
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
944
|
+
expect(compoundV2Encode.leverageManagement(...actual)).to.eql(expected);
|
|
945
|
+
});
|
|
946
|
+
});
|
|
947
|
+
});
|
|
948
|
+
});
|
|
851
949
|
describe('When testing strategySubService.compoundV3Encode', () => {
|
|
950
|
+
describe('leverageManagement()', () => {
|
|
951
|
+
const examples = [
|
|
952
|
+
[
|
|
953
|
+
[
|
|
954
|
+
web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
955
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
956
|
+
new Dec(160).mul(1e16).toString(),
|
|
957
|
+
new Dec(220).mul(1e16).toString(),
|
|
958
|
+
new Dec(180).mul(1e16).toString(),
|
|
959
|
+
new Dec(190).mul(1e16).toString(),
|
|
960
|
+
true, false,
|
|
961
|
+
],
|
|
962
|
+
[
|
|
963
|
+
web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
964
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
965
|
+
160, 220, 180, 190,
|
|
966
|
+
true, false,
|
|
967
|
+
]
|
|
968
|
+
],
|
|
969
|
+
[
|
|
970
|
+
[
|
|
971
|
+
web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
972
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
973
|
+
new Dec(160).mul(1e16).toString(),
|
|
974
|
+
new Dec(210).mul(1e16).toString(),
|
|
975
|
+
new Dec(180).mul(1e16).toString(),
|
|
976
|
+
new Dec(190).mul(1e16).toString(),
|
|
977
|
+
false, true,
|
|
978
|
+
],
|
|
979
|
+
[
|
|
980
|
+
web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
981
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
982
|
+
160, 210, 180, 190,
|
|
983
|
+
false, true,
|
|
984
|
+
]
|
|
985
|
+
],
|
|
986
|
+
];
|
|
987
|
+
examples.forEach(([expected, actual]) => {
|
|
988
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
989
|
+
expect(compoundV3Encode.leverageManagement(...actual)).to.eql(expected);
|
|
990
|
+
});
|
|
991
|
+
});
|
|
992
|
+
});
|
|
852
993
|
describe('leverageManagementOnPrice()', () => {
|
|
853
994
|
const examples = [
|
|
854
995
|
[
|
|
@@ -1023,6 +1164,51 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1023
1164
|
});
|
|
1024
1165
|
});
|
|
1025
1166
|
});
|
|
1167
|
+
describe('limitOrder()', () => {
|
|
1168
|
+
const examples = [
|
|
1169
|
+
[
|
|
1170
|
+
[
|
|
1171
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1172
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1173
|
+
'2131',
|
|
1174
|
+
'0.53123',
|
|
1175
|
+
'1696590921159',
|
|
1176
|
+
`${OrderType.STOP_LOSS}`
|
|
1177
|
+
],
|
|
1178
|
+
[
|
|
1179
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1180
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1181
|
+
'2131',
|
|
1182
|
+
'0.53123',
|
|
1183
|
+
1696590921159,
|
|
1184
|
+
OrderType.STOP_LOSS
|
|
1185
|
+
]
|
|
1186
|
+
],
|
|
1187
|
+
[
|
|
1188
|
+
[
|
|
1189
|
+
web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
|
|
1190
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
|
|
1191
|
+
'2131',
|
|
1192
|
+
'0.43123',
|
|
1193
|
+
'1646590921159',
|
|
1194
|
+
`${OrderType.TAKE_PROFIT}`
|
|
1195
|
+
],
|
|
1196
|
+
[
|
|
1197
|
+
web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
|
|
1198
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
|
|
1199
|
+
'2131',
|
|
1200
|
+
'0.43123',
|
|
1201
|
+
1646590921159,
|
|
1202
|
+
OrderType.TAKE_PROFIT
|
|
1203
|
+
]
|
|
1204
|
+
],
|
|
1205
|
+
];
|
|
1206
|
+
examples.forEach(([expected, actual]) => {
|
|
1207
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1208
|
+
expect(exchangeEncode.limitOrder(...actual)).to.eql(expected);
|
|
1209
|
+
});
|
|
1210
|
+
});
|
|
1211
|
+
});
|
|
1026
1212
|
});
|
|
1027
1213
|
describe('When testing strategySubService.crvUSDEncode', () => {
|
|
1028
1214
|
describe('leverageManagement()', () => {
|
|
@@ -1236,7 +1422,55 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1236
1422
|
});
|
|
1237
1423
|
});
|
|
1238
1424
|
});
|
|
1425
|
+
describe('When testing strategySubService.compoundV3L2Encode', () => {
|
|
1426
|
+
describe('leverageManagement()', () => {
|
|
1427
|
+
const examples = [
|
|
1428
|
+
[
|
|
1429
|
+
'0x0313D212133AFab8F2b829B1066c7e43caD94e2c0213D212133AfaB8F2b829B1066C7E43cAD94E2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e00000100',
|
|
1430
|
+
[
|
|
1431
|
+
web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'),
|
|
1432
|
+
web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'),
|
|
1433
|
+
160, 220, 180, 190,
|
|
1434
|
+
true,
|
|
1435
|
+
false,
|
|
1436
|
+
],
|
|
1437
|
+
],
|
|
1438
|
+
[
|
|
1439
|
+
'0x0313D212133AFab8F2b829B1066c7e43caD94e2c0413d212133afAb8F2B829b1066C7e43cAd94e2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000000f43fc2c04ee00000000',
|
|
1440
|
+
[
|
|
1441
|
+
web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'),
|
|
1442
|
+
web3Utils.toChecksumAddress('0x0413d212133AFaB8F2B829B1066c7E43cAd94E2c'),
|
|
1443
|
+
160, 220, 180, 110,
|
|
1444
|
+
false,
|
|
1445
|
+
false,
|
|
1446
|
+
],
|
|
1447
|
+
],
|
|
1448
|
+
];
|
|
1449
|
+
examples.forEach(([expected, actual]) => {
|
|
1450
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1451
|
+
expect(compoundV3L2Encode.leverageManagement(...actual)).to.eql(expected);
|
|
1452
|
+
});
|
|
1453
|
+
});
|
|
1454
|
+
});
|
|
1455
|
+
});
|
|
1239
1456
|
describe('When testing strategySubService.sparkEncode', () => {
|
|
1457
|
+
describe('leverageManagement()', () => {
|
|
1458
|
+
const examples = [
|
|
1459
|
+
[
|
|
1460
|
+
'0x0000000000000000136dcc951d8c00000000000000000000214e8348c4f0000000000000000000001d24b2dfac52000000000000000000001a5e27eef13e000001',
|
|
1461
|
+
[140, 240, 210, 190, true]
|
|
1462
|
+
],
|
|
1463
|
+
[
|
|
1464
|
+
'0x0000000000000000130337bdce49000000000000000000001988fe4052b800000000000000000000281b57b028e1000000000000000000002223acf76376000000',
|
|
1465
|
+
[137, 184, 289, 246, false]
|
|
1466
|
+
]
|
|
1467
|
+
];
|
|
1468
|
+
examples.forEach(([expected, actual]) => {
|
|
1469
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1470
|
+
expect(sparkEncode.leverageManagement(...actual)).to.eql(expected);
|
|
1471
|
+
});
|
|
1472
|
+
});
|
|
1473
|
+
});
|
|
1240
1474
|
describe('leverageManagementOnPrice()', () => {
|
|
1241
1475
|
const examples = [
|
|
1242
1476
|
[
|
|
@@ -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
|
/ || _ \ / \ | _ \ | |/ /
|
|
@@ -161,23 +161,6 @@ export const liquityLeverageManagementSubData = {
|
|
|
161
161
|
return { targetRatio };
|
|
162
162
|
},
|
|
163
163
|
};
|
|
164
|
-
export const liquityLeverageManagementSubDataWithoutSubProxy = {
|
|
165
|
-
encode(targetRatio, ratioState) {
|
|
166
|
-
const encodedRatioState = AbiCoder.encodeParameter('uint8', ratioState);
|
|
167
|
-
const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
168
|
-
const isRepay = ratioState === RatioState.UNDER;
|
|
169
|
-
const collActionType = isRepay ? CollActionType.WITHDRAW : CollActionType.SUPPLY;
|
|
170
|
-
const debtActionType = isRepay ? DebtActionType.PAYBACK : DebtActionType.BORROW;
|
|
171
|
-
const collActionTypeEncoded = AbiCoder.encodeParameter('uint8', collActionType);
|
|
172
|
-
const debtActionTypeEncoded = AbiCoder.encodeParameter('uint8', debtActionType);
|
|
173
|
-
return [encodedRatioState, encodedTargetRatio, collActionTypeEncoded, debtActionTypeEncoded];
|
|
174
|
-
},
|
|
175
|
-
decode(subData) {
|
|
176
|
-
const ratioState = AbiCoder.decodeParameter('uint8', subData[0]);
|
|
177
|
-
const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[1]));
|
|
178
|
-
return { targetRatio, ratioState };
|
|
179
|
-
},
|
|
180
|
-
};
|
|
181
164
|
export const liquityCloseSubData = {
|
|
182
165
|
encode(closeToAssetAddr, chainId = ChainId.Ethereum, collAddr, debtAddr) {
|
|
183
166
|
const _collAddr = collAddr || getAssetInfo('WETH', chainId).address;
|
|
@@ -409,25 +392,6 @@ export const aaveV2LeverageManagementSubData = {
|
|
|
409
392
|
return { targetRatio };
|
|
410
393
|
},
|
|
411
394
|
};
|
|
412
|
-
export const aaveV2LeverageManagementSubDataWithoutSubProxy = {
|
|
413
|
-
encode(market, targetRatio, ratioState) {
|
|
414
|
-
const encodedMarket = AbiCoder.encodeParameter('address', market);
|
|
415
|
-
const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
416
|
-
const encodedRatioState = AbiCoder.encodeParameter('uint8', ratioState);
|
|
417
|
-
const isBoost = ratioState === RatioState.OVER;
|
|
418
|
-
if (isBoost) {
|
|
419
|
-
const enableAsCollEncoded = AbiCoder.encodeParameter('uint256', 1);
|
|
420
|
-
return [encodedMarket, encodedTargetRatio, encodedRatioState, enableAsCollEncoded];
|
|
421
|
-
}
|
|
422
|
-
return [encodedMarket, encodedTargetRatio, encodedRatioState];
|
|
423
|
-
},
|
|
424
|
-
decode(subData) {
|
|
425
|
-
const market = AbiCoder.decodeParameter('address', subData[0]);
|
|
426
|
-
const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[1]));
|
|
427
|
-
const ratioState = AbiCoder.decodeParameter('uint8', subData[2]);
|
|
428
|
-
return { market, targetRatio, ratioState };
|
|
429
|
-
},
|
|
430
|
-
};
|
|
431
395
|
/**
|
|
432
396
|
___ ___ ____ ____ _______ ____ ____ ____
|
|
433
397
|
/ \ / \ \ \ / / | ____| \ \ / / |___ \
|
|
@@ -782,23 +746,6 @@ export const compoundV2LeverageManagementSubData = {
|
|
|
782
746
|
return { targetRatio };
|
|
783
747
|
},
|
|
784
748
|
};
|
|
785
|
-
export const compoundV2LeverageManagementSubDataWithoutSubProxy = {
|
|
786
|
-
encode(targetRatio, ratioState) {
|
|
787
|
-
const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
788
|
-
const encodedRatioState = AbiCoder.encodeParameter('uint8', ratioState);
|
|
789
|
-
const isBoost = ratioState === RatioState.OVER;
|
|
790
|
-
if (isBoost) {
|
|
791
|
-
const enableAsCollEncoded = AbiCoder.encodeParameter('uint256', 1);
|
|
792
|
-
return [encodedTargetRatio, encodedRatioState, enableAsCollEncoded];
|
|
793
|
-
}
|
|
794
|
-
return [encodedTargetRatio, encodedRatioState];
|
|
795
|
-
},
|
|
796
|
-
decode(subData) {
|
|
797
|
-
const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[0]));
|
|
798
|
-
const ratioState = AbiCoder.decodeParameter('uint8', subData[1]);
|
|
799
|
-
return { targetRatio, ratioState };
|
|
800
|
-
},
|
|
801
|
-
};
|
|
802
749
|
/**
|
|
803
750
|
______ ______ .___ ___. .______ ____ ____ ____
|
|
804
751
|
/ | / __ \ | \/ | | _ \ \ \ / / |___ \
|
|
@@ -826,22 +773,27 @@ export const compoundV3LeverageManagementSubData = {
|
|
|
826
773
|
return { targetRatio };
|
|
827
774
|
},
|
|
828
775
|
};
|
|
829
|
-
export const
|
|
830
|
-
encode(market, baseToken,
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
776
|
+
export const compoundV3L2LeverageManagementSubData = {
|
|
777
|
+
encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled, isEOA) {
|
|
778
|
+
let subInput = '0x';
|
|
779
|
+
subInput = subInput.concat(market.slice(2));
|
|
780
|
+
subInput = subInput.concat(baseToken.slice(2));
|
|
781
|
+
subInput = subInput.concat(new Dec(triggerRepayRatio).mul(1e16).toHex().slice(2)
|
|
782
|
+
.padStart(32, '0'));
|
|
783
|
+
subInput = subInput.concat(new Dec(triggerBoostRatio).mul(1e16).toHex().slice(2)
|
|
784
|
+
.padStart(32, '0'));
|
|
785
|
+
subInput = subInput.concat(new Dec(targetBoostRatio).mul(1e16).toHex().slice(2)
|
|
786
|
+
.padStart(32, '0'));
|
|
787
|
+
subInput = subInput.concat(new Dec(targetRepayRatio).mul(1e16).toHex().slice(2)
|
|
788
|
+
.padStart(32, '0'));
|
|
789
|
+
subInput = subInput.concat(boostEnabled ? '01' : '00');
|
|
790
|
+
subInput = subInput.concat(isEOA ? '01' : '00');
|
|
791
|
+
return subInput;
|
|
836
792
|
},
|
|
837
793
|
decode(subData) {
|
|
838
|
-
const
|
|
839
|
-
const
|
|
840
|
-
|
|
841
|
-
const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[3]));
|
|
842
|
-
return {
|
|
843
|
-
market, baseToken, targetRatio, ratioState,
|
|
844
|
-
};
|
|
794
|
+
const ratioWei = AbiCoder.decodeParameter('uint256', subData[3]);
|
|
795
|
+
const targetRatio = weiToRatioPercentage(ratioWei);
|
|
796
|
+
return { targetRatio };
|
|
845
797
|
},
|
|
846
798
|
};
|
|
847
799
|
export const compoundV3LeverageManagementOnPriceSubData = {
|
|
@@ -947,21 +899,6 @@ export const exchangeLimitOrderSubData = {
|
|
|
947
899
|
return { fromToken, toToken, amount };
|
|
948
900
|
},
|
|
949
901
|
};
|
|
950
|
-
export const exchangeLimitOrderSubDataWithoutSubProxy = {
|
|
951
|
-
encode(fromToken, toToken, amount) {
|
|
952
|
-
return [
|
|
953
|
-
AbiCoder.encodeParameter('address', fromToken),
|
|
954
|
-
AbiCoder.encodeParameter('address', toToken),
|
|
955
|
-
AbiCoder.encodeParameter('uint256', amount),
|
|
956
|
-
];
|
|
957
|
-
},
|
|
958
|
-
decode: (subData, chainId) => {
|
|
959
|
-
const fromToken = AbiCoder.decodeParameter('address', subData[0]).toString();
|
|
960
|
-
const toToken = AbiCoder.decodeParameter('address', subData[1]).toString();
|
|
961
|
-
const amount = assetAmountInEth(AbiCoder.decodeParameter('uint256', subData[2]).toString(), getAssetInfoByAddress(fromToken, chainId).symbol);
|
|
962
|
-
return { fromToken, toToken, amount };
|
|
963
|
-
},
|
|
964
|
-
};
|
|
965
902
|
/**
|
|
966
903
|
_______..______ ___ .______ __ ___
|
|
967
904
|
/ || _ \ / \ | _ \ | |/ /
|
|
@@ -1309,6 +1309,48 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1309
1309
|
});
|
|
1310
1310
|
});
|
|
1311
1311
|
});
|
|
1312
|
+
describe('When testing subDataService.compoundV3L2LeverageManagementSubData', () => {
|
|
1313
|
+
describe('encode()', () => {
|
|
1314
|
+
const examples = [
|
|
1315
|
+
[
|
|
1316
|
+
'0x0313D212133AFab8F2b829B1066c7e43caD94e2c0213D212133AfaB8F2b829B1066C7E43cAD94E2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e00000100',
|
|
1317
|
+
[web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'), web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'), 160, 220, 180, 190, true, false]
|
|
1318
|
+
],
|
|
1319
|
+
[
|
|
1320
|
+
'0x0313D212133AFab8F2b829B1066c7e43caD94e2c0413d212133afAb8F2B829b1066C7e43cAd94e2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000000f43fc2c04ee00000000',
|
|
1321
|
+
[web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'), web3Utils.toChecksumAddress('0x0413d212133AFaB8F2B829B1066c7E43cAd94E2c'), 160, 220, 180, 110, false, false]
|
|
1322
|
+
],
|
|
1323
|
+
];
|
|
1324
|
+
examples.forEach(([expected, actual]) => {
|
|
1325
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1326
|
+
expect(subDataService.compoundV3L2LeverageManagementSubData.encode(...actual)).to.eql(expected);
|
|
1327
|
+
});
|
|
1328
|
+
});
|
|
1329
|
+
});
|
|
1330
|
+
describe('decode()', () => {
|
|
1331
|
+
const examples = [
|
|
1332
|
+
[
|
|
1333
|
+
{ targetRatio: 200 },
|
|
1334
|
+
[
|
|
1335
|
+
'0x0000000000000000000000000313d212133AFaB8F2B829B1066c7E43cAd94E2c', '0x0000000000000000000000000213d212133AFaB8F2B829B1066c7E43cAd94E2c',
|
|
1336
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
1337
|
+
],
|
|
1338
|
+
],
|
|
1339
|
+
[
|
|
1340
|
+
{ targetRatio: 123 },
|
|
1341
|
+
[
|
|
1342
|
+
'0x0000000000000000000000000313d212133AFaB8F2B829B1066c7E43cAd94E2c', '0x0000000000000000000000000413d212133AFaB8F2B829B1066c7E43cAd94E2c',
|
|
1343
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
|
|
1344
|
+
],
|
|
1345
|
+
],
|
|
1346
|
+
];
|
|
1347
|
+
examples.forEach(([expected, actual]) => {
|
|
1348
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1349
|
+
expect(subDataService.compoundV3L2LeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
1350
|
+
});
|
|
1351
|
+
});
|
|
1352
|
+
});
|
|
1353
|
+
});
|
|
1312
1354
|
describe('When testing subDataService.morphoBlueLeverageManagementSubData', () => {
|
|
1313
1355
|
describe('encode()', () => {
|
|
1314
1356
|
const examples = [
|