@defisaver/automation-sdk 3.1.10 → 3.1.14-spark-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.
Files changed (72) hide show
  1. package/cjs/automation/private/StrategiesAutomation.d.ts +5 -3
  2. package/cjs/automation/private/StrategiesAutomation.js +27 -10
  3. package/cjs/automation/private/StrategiesAutomation.test.js +25 -0
  4. package/cjs/constants/index.d.ts +1 -0
  5. package/cjs/constants/index.js +352 -11
  6. package/cjs/index.d.ts +2 -1
  7. package/cjs/index.js +1 -1
  8. package/cjs/services/ethereumService.js +21 -14
  9. package/cjs/services/ethereumService.test.js +3 -0
  10. package/cjs/services/strategiesService.js +329 -54
  11. package/cjs/services/strategiesService.test.js +1 -0
  12. package/cjs/services/strategySubService.d.ts +24 -5
  13. package/cjs/services/strategySubService.js +116 -10
  14. package/cjs/services/strategySubService.test.js +1049 -173
  15. package/cjs/services/subDataService.d.ts +361 -88
  16. package/cjs/services/subDataService.js +799 -249
  17. package/cjs/services/subDataService.test.js +1287 -142
  18. package/cjs/services/triggerService.d.ts +100 -9
  19. package/cjs/services/triggerService.js +188 -19
  20. package/cjs/services/triggerService.test.js +437 -46
  21. package/cjs/services/utils.d.ts +1 -1
  22. package/cjs/services/utils.js +10 -2
  23. package/cjs/services/utils.test.js +0 -77
  24. package/cjs/types/enums.d.ts +88 -12
  25. package/cjs/types/enums.js +78 -2
  26. package/cjs/types/index.d.ts +59 -1
  27. package/esm/automation/private/StrategiesAutomation.d.ts +5 -3
  28. package/esm/automation/private/StrategiesAutomation.js +27 -10
  29. package/esm/automation/private/StrategiesAutomation.test.js +25 -0
  30. package/esm/constants/index.d.ts +1 -0
  31. package/esm/constants/index.js +351 -10
  32. package/esm/index.d.ts +2 -1
  33. package/esm/index.js +2 -2
  34. package/esm/services/ethereumService.js +21 -14
  35. package/esm/services/ethereumService.test.js +3 -0
  36. package/esm/services/strategiesService.js +330 -55
  37. package/esm/services/strategiesService.test.js +1 -0
  38. package/esm/services/strategySubService.d.ts +24 -5
  39. package/esm/services/strategySubService.js +115 -9
  40. package/esm/services/strategySubService.test.js +1052 -176
  41. package/esm/services/subDataService.d.ts +361 -88
  42. package/esm/services/subDataService.js +799 -249
  43. package/esm/services/subDataService.test.js +1288 -143
  44. package/esm/services/triggerService.d.ts +100 -9
  45. package/esm/services/triggerService.js +187 -18
  46. package/esm/services/triggerService.test.js +438 -47
  47. package/esm/services/utils.d.ts +1 -1
  48. package/esm/services/utils.js +10 -2
  49. package/esm/services/utils.test.js +1 -52
  50. package/esm/types/enums.d.ts +88 -12
  51. package/esm/types/enums.js +78 -2
  52. package/esm/types/index.d.ts +59 -1
  53. package/package.json +4 -5
  54. package/src/automation/private/StrategiesAutomation.test.ts +40 -0
  55. package/src/automation/private/StrategiesAutomation.ts +38 -15
  56. package/src/constants/index.ts +353 -11
  57. package/src/index.ts +4 -2
  58. package/src/services/ethereumService.test.ts +3 -0
  59. package/src/services/ethereumService.ts +23 -16
  60. package/src/services/strategiesService.test.ts +1 -0
  61. package/src/services/strategiesService.ts +387 -72
  62. package/src/services/strategySubService.test.ts +1330 -316
  63. package/src/services/strategySubService.ts +365 -12
  64. package/src/services/subDataService.test.ts +1413 -170
  65. package/src/services/subDataService.ts +1148 -431
  66. package/src/services/triggerService.test.ts +482 -52
  67. package/src/services/triggerService.ts +272 -27
  68. package/src/services/utils.test.ts +0 -59
  69. package/src/services/utils.ts +15 -4
  70. package/src/types/enums.ts +78 -2
  71. package/src/types/index.ts +74 -1
  72. package/umd/index.js +0 -34219
@@ -2,9 +2,10 @@ import Dec from 'decimal.js';
2
2
  import { expect } from 'chai';
3
3
  import { getAssetInfo } from '@defisaver/tokens';
4
4
  import * as web3Utils from 'web3-utils';
5
- import { ChainId, OrderType, RatioState } from '../types/enums';
5
+ import { MAXUINT } from '@defisaver/tokens';
6
+ import { ChainId, CloseStrategyType, OrderType, RatioState } from '../types/enums';
6
7
  import '../configuration';
7
- import { aaveV2LeverageManagementSubData, aaveV3LeverageManagementSubData, aaveV3QuotePriceSubData, cBondsRebondSubData, compoundV2LeverageManagementSubData, compoundV3LeverageManagementSubData, exchangeDcaSubData, exchangeLimitOrderSubData, liquityCloseSubData, liquityDebtInFrontRepaySubData, liquityDsrPaybackSubData, liquityDsrSupplySubData, liquityLeverageManagementSubData, liquityPaybackUsingChickenBondSubData, liquityRepayFromSavingsSubData, makerCloseSubData, makerLeverageManagementSubData, makerRepayFromSavingsSubData, morphoAaveV2LeverageManagementSubData, sparkLeverageManagementSubData, sparkQuotePriceSubData, crvUSDLeverageManagementSubData, compoundV3L2LeverageManagementSubData, morphoBlueLeverageManagementSubData, crvUSDPaybackSubData, aaveV3LeverageManagementOnPriceSubData, } from './subDataService';
8
+ import * as subDataService from './subDataService';
8
9
  describe('Feature: subDataService.ts', () => {
9
10
  describe('When testing subDataService.makerRepayFromSavingsSubData', () => {
10
11
  describe('encode()', () => {
@@ -19,7 +20,7 @@ describe('Feature: subDataService.ts', () => {
19
20
  ];
20
21
  examples.forEach(([expected, actual]) => {
21
22
  it(`Given ${actual} should return expected value: ${expected}`, () => {
22
- expect(makerRepayFromSavingsSubData.encode(...actual)).to.eql(expected);
23
+ expect(subDataService.makerRepayFromSavingsSubData.encode(...actual)).to.eql(expected);
23
24
  });
24
25
  });
25
26
  });
@@ -40,7 +41,7 @@ describe('Feature: subDataService.ts', () => {
40
41
  ];
41
42
  examples.forEach(([expected, actual]) => {
42
43
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
43
- expect(makerRepayFromSavingsSubData.decode(actual)).to.eql(expected);
44
+ expect(subDataService.makerRepayFromSavingsSubData.decode(actual)).to.eql(expected);
44
45
  });
45
46
  });
46
47
  });
@@ -58,7 +59,7 @@ describe('Feature: subDataService.ts', () => {
58
59
  ];
59
60
  examples.forEach(([expected, actual]) => {
60
61
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
61
- expect(liquityRepayFromSavingsSubData.decode(actual)).to.eql(expected);
62
+ expect(subDataService.liquityRepayFromSavingsSubData.decode(actual)).to.eql(expected);
62
63
  });
63
64
  });
64
65
  });
@@ -83,7 +84,7 @@ describe('Feature: subDataService.ts', () => {
83
84
  ];
84
85
  examples.forEach(([expected, actual]) => {
85
86
  it(`Given ${actual} should return expected value: ${expected}`, () => {
86
- expect(makerCloseSubData.encode(...actual)).to.eql(expected);
87
+ expect(subDataService.makerCloseSubData.encode(...actual)).to.eql(expected);
87
88
  });
88
89
  });
89
90
  });
@@ -112,7 +113,7 @@ describe('Feature: subDataService.ts', () => {
112
113
  ];
113
114
  examples.forEach(([expected, actual]) => {
114
115
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
115
- expect(makerCloseSubData.decode(actual)).to.eql(expected);
116
+ expect(subDataService.makerCloseSubData.decode(actual)).to.eql(expected);
116
117
  });
117
118
  });
118
119
  });
@@ -130,7 +131,63 @@ describe('Feature: subDataService.ts', () => {
130
131
  ];
131
132
  examples.forEach(([expected, actual]) => {
132
133
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
133
- expect(makerLeverageManagementSubData.decode(actual)).to.eql(expected);
134
+ expect(subDataService.makerLeverageManagementSubData.decode(actual)).to.eql(expected);
135
+ });
136
+ });
137
+ });
138
+ });
139
+ describe('When testing subDataService.makerLeverageManagementWithoutSubProxy', () => {
140
+ describe('encode()', () => {
141
+ const examples = [
142
+ [
143
+ [
144
+ '0x00000000000000000000000000000000000000000000000000000000000000de', '0x00000000000000000000000000000000000000000000000018fae27693b40000',
145
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
146
+ ],
147
+ [222, 180], // Uses default DAI address
148
+ ],
149
+ [
150
+ [
151
+ '0x000000000000000000000000000000000000000000000000000000000000014d', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
152
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
153
+ ],
154
+ [333, 200, web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address)], // Custom address
155
+ ],
156
+ ];
157
+ examples.forEach(([expected, actual]) => {
158
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
159
+ expect(subDataService.makerLeverageManagementWithoutSubProxy.encode(...actual)).to.eql(expected);
160
+ });
161
+ });
162
+ });
163
+ describe('decode()', () => {
164
+ const examples = [
165
+ [
166
+ {
167
+ vaultId: 222,
168
+ targetRatio: 180,
169
+ daiAddr: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
170
+ },
171
+ [
172
+ '0x00000000000000000000000000000000000000000000000000000000000000de', '0x00000000000000000000000000000000000000000000000018fae27693b40000',
173
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
174
+ ],
175
+ ],
176
+ [
177
+ {
178
+ vaultId: 333,
179
+ targetRatio: 200,
180
+ daiAddr: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
181
+ },
182
+ [
183
+ '0x000000000000000000000000000000000000000000000000000000000000014d', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
184
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
185
+ ],
186
+ ],
187
+ ];
188
+ examples.forEach(([expected, actual]) => {
189
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
190
+ expect(subDataService.makerLeverageManagementWithoutSubProxy.decode(actual)).to.eql(expected);
134
191
  });
135
192
  });
136
193
  });
@@ -148,7 +205,7 @@ describe('Feature: subDataService.ts', () => {
148
205
  ];
149
206
  examples.forEach(([expected, actual]) => {
150
207
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
151
- expect(liquityLeverageManagementSubData.decode(actual)).to.eql(expected);
208
+ expect(subDataService.liquityLeverageManagementSubData.decode(actual)).to.eql(expected);
152
209
  });
153
210
  });
154
211
  });
@@ -171,7 +228,7 @@ describe('Feature: subDataService.ts', () => {
171
228
  ];
172
229
  examples.forEach(([expected, actual]) => {
173
230
  it(`Given ${actual} should return expected value: ${expected}`, () => {
174
- expect(liquityCloseSubData.encode(...actual)).to.eql(expected);
231
+ expect(subDataService.liquityCloseSubData.encode(...actual)).to.eql(expected);
175
232
  });
176
233
  });
177
234
  });
@@ -198,7 +255,7 @@ describe('Feature: subDataService.ts', () => {
198
255
  ];
199
256
  examples.forEach(([expected, actual]) => {
200
257
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
201
- expect(liquityCloseSubData.decode(actual)).to.eql(expected);
258
+ expect(subDataService.liquityCloseSubData.decode(actual)).to.eql(expected);
202
259
  });
203
260
  });
204
261
  });
@@ -217,7 +274,7 @@ describe('Feature: subDataService.ts', () => {
217
274
  ];
218
275
  examples.forEach(([expected, actual]) => {
219
276
  it(`Given ${actual} should return expected value: ${expected}`, () => {
220
- expect(aaveV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
277
+ expect(subDataService.aaveV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
221
278
  });
222
279
  });
223
280
  });
@@ -234,7 +291,7 @@ describe('Feature: subDataService.ts', () => {
234
291
  ];
235
292
  examples.forEach(([expected, actual]) => {
236
293
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
237
- expect(aaveV2LeverageManagementSubData.decode(actual)).to.eql(expected);
294
+ expect(subDataService.aaveV2LeverageManagementSubData.decode(actual)).to.eql(expected);
238
295
  });
239
296
  });
240
297
  });
@@ -253,7 +310,7 @@ describe('Feature: subDataService.ts', () => {
253
310
  ];
254
311
  examples.forEach(([expected, actual]) => {
255
312
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
256
- expect(aaveV3LeverageManagementSubData.decode(actual)).to.eql(expected);
313
+ expect(subDataService.aaveV3LeverageManagementSubData.decode(actual)).to.eql(expected);
257
314
  });
258
315
  });
259
316
  });
@@ -290,7 +347,7 @@ describe('Feature: subDataService.ts', () => {
290
347
  ];
291
348
  examples.forEach(([expected, actual]) => {
292
349
  it(`Given ${actual} should return expected value: ${expected}`, () => {
293
- expect(aaveV3QuotePriceSubData.encode(...actual)).to.eql(expected);
350
+ expect(subDataService.aaveV3QuotePriceSubData.encode(...actual)).to.eql(expected);
294
351
  });
295
352
  });
296
353
  });
@@ -325,7 +382,269 @@ describe('Feature: subDataService.ts', () => {
325
382
  ];
326
383
  examples.forEach(([expected, actual]) => {
327
384
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
328
- expect(aaveV3QuotePriceSubData.decode(actual)).to.eql(expected);
385
+ expect(subDataService.aaveV3QuotePriceSubData.decode(actual)).to.eql(expected);
386
+ });
387
+ });
388
+ });
389
+ });
390
+ describe('When testing subDataService.aaveV3CollateralSwitchSubData', () => {
391
+ describe('encode()', () => {
392
+ const examples = [
393
+ // WETH -> USDC
394
+ [
395
+ [
396
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
397
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
398
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
399
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
400
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
401
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
402
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
403
+ ],
404
+ [
405
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
406
+ 0,
407
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
408
+ 1,
409
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
410
+ '10000000000000000000',
411
+ false,
412
+ ]
413
+ ],
414
+ // USDC -> WETH (MaxUint256)
415
+ [
416
+ [
417
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
418
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
419
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
420
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
421
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
422
+ '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
423
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
424
+ ],
425
+ [
426
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
427
+ 1,
428
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
429
+ 0,
430
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
431
+ MAXUINT, // MaxUint256
432
+ ]
433
+ ],
434
+ // WETH -> WBTC
435
+ [
436
+ [
437
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
438
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
439
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
440
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
441
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
442
+ '0x0000000000000000000000000000000000000000000000004563918244f40000',
443
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
444
+ ],
445
+ [
446
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
447
+ 0,
448
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
449
+ 2,
450
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
451
+ '5000000000000000000', // 5 WETH
452
+ ]
453
+ ],
454
+ ];
455
+ examples.forEach(([expected, actual]) => {
456
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
457
+ expect(subDataService.aaveV3CollateralSwitchSubData.encode(...actual)).to.eql(expected);
458
+ });
459
+ });
460
+ });
461
+ describe('decode()', () => {
462
+ const examples = [
463
+ // WETH -> USDC
464
+ [
465
+ {
466
+ fromAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
467
+ fromAssetId: 0,
468
+ toAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
469
+ toAssetId: 1,
470
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
471
+ amountToSwitch: '10000000000000000000',
472
+ },
473
+ [
474
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
475
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
476
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
477
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
478
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
479
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
480
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
481
+ ],
482
+ ],
483
+ // USDC -> WETH (MaxUint256)
484
+ [
485
+ {
486
+ fromAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
487
+ fromAssetId: 1,
488
+ toAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
489
+ toAssetId: 0,
490
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
491
+ amountToSwitch: MAXUINT,
492
+ },
493
+ [
494
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
495
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
496
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
497
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
498
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
499
+ '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
500
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
501
+ ],
502
+ ],
503
+ // WETH -> WBTC
504
+ [
505
+ {
506
+ fromAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
507
+ fromAssetId: 0,
508
+ toAsset: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
509
+ toAssetId: 2,
510
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
511
+ amountToSwitch: '5000000000000000000',
512
+ },
513
+ [
514
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
515
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
516
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
517
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
518
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
519
+ '0x0000000000000000000000000000000000000000000000004563918244f40000',
520
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
521
+ ],
522
+ ],
523
+ ];
524
+ examples.forEach(([expected, actual]) => {
525
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
526
+ expect(subDataService.aaveV3CollateralSwitchSubData.decode(actual)).to.eql(expected);
527
+ });
528
+ });
529
+ });
530
+ });
531
+ describe('When testing subDataService.sparkCollateralSwitchSubData', () => {
532
+ describe('encode()', () => {
533
+ const examples = [
534
+ // WETH -> cbBTC
535
+ [
536
+ [
537
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
538
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
539
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
540
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
541
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
542
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
543
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
544
+ ],
545
+ [
546
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
547
+ 0,
548
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
549
+ 7,
550
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
551
+ '10000000000000000000',
552
+ false,
553
+ ]
554
+ ],
555
+ // cbBTC -> WETH (MaxUint256)
556
+ [
557
+ [
558
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
559
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
560
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
561
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
562
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
563
+ '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
564
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
565
+ ],
566
+ [
567
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
568
+ 7,
569
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
570
+ 0,
571
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
572
+ MAXUINT,
573
+ ]
574
+ ],
575
+ // WETH -> cbBTC (5 WETH)
576
+ [
577
+ [
578
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
579
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
580
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
581
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
582
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
583
+ '0x0000000000000000000000000000000000000000000000004563918244f40000',
584
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
585
+ ],
586
+ [
587
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
588
+ 0,
589
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
590
+ 7,
591
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
592
+ '5000000000000000000', // 5 WETH
593
+ ]
594
+ ],
595
+ ];
596
+ examples.forEach(([expected, actual]) => {
597
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
598
+ expect(subDataService.sparkCollateralSwitchSubData.encode(...actual)).to.eql(expected);
599
+ });
600
+ });
601
+ });
602
+ describe('decode()', () => {
603
+ const examples = [
604
+ // WETH -> cbBTC
605
+ [
606
+ {
607
+ fromAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
608
+ fromAssetId: 0,
609
+ toAsset: web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
610
+ toAssetId: 7,
611
+ marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
612
+ amountToSwitch: '10000000000000000000',
613
+ },
614
+ [
615
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
616
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
617
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
618
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
619
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
620
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
621
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
622
+ ],
623
+ ],
624
+ // cbBTC -> WETH (MaxUint256)
625
+ [
626
+ {
627
+ fromAsset: web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
628
+ fromAssetId: 7,
629
+ toAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
630
+ toAssetId: 0,
631
+ marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
632
+ amountToSwitch: MAXUINT,
633
+ },
634
+ [
635
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
636
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
637
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
638
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
639
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
640
+ '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
641
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
642
+ ],
643
+ ],
644
+ ];
645
+ examples.forEach(([expected, actual]) => {
646
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
647
+ expect(subDataService.sparkCollateralSwitchSubData.decode(actual)).to.eql(expected);
329
648
  });
330
649
  });
331
650
  });
@@ -344,7 +663,7 @@ describe('Feature: subDataService.ts', () => {
344
663
  ];
345
664
  examples.forEach(([expected, actual]) => {
346
665
  it(`Given ${actual} should return expected value: ${expected}`, () => {
347
- expect(compoundV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
666
+ expect(subDataService.compoundV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
348
667
  });
349
668
  });
350
669
  });
@@ -361,7 +680,7 @@ describe('Feature: subDataService.ts', () => {
361
680
  ];
362
681
  examples.forEach(([expected, actual]) => {
363
682
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
364
- expect(compoundV2LeverageManagementSubData.decode(actual)).to.eql(expected);
683
+ expect(subDataService.compoundV2LeverageManagementSubData.decode(actual)).to.eql(expected);
365
684
  });
366
685
  });
367
686
  });
@@ -406,7 +725,7 @@ describe('Feature: subDataService.ts', () => {
406
725
  ];
407
726
  examples.forEach(([expected, actual]) => {
408
727
  it(`Given ${actual} should return expected value: ${expected}`, () => {
409
- expect(compoundV3LeverageManagementSubData.encode(...actual)).to.eql(expected);
728
+ expect(subDataService.compoundV3LeverageManagementSubData.encode(...actual)).to.eql(expected);
410
729
  });
411
730
  });
412
731
  });
@@ -429,7 +748,7 @@ describe('Feature: subDataService.ts', () => {
429
748
  ];
430
749
  examples.forEach(([expected, actual]) => {
431
750
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
432
- expect(compoundV3LeverageManagementSubData.decode(actual)).to.eql(expected);
751
+ expect(subDataService.compoundV3LeverageManagementSubData.decode(actual)).to.eql(expected);
433
752
  });
434
753
  });
435
754
  });
@@ -448,7 +767,7 @@ describe('Feature: subDataService.ts', () => {
448
767
  ];
449
768
  examples.forEach(([expected, actual]) => {
450
769
  it(`Given ${actual} should return expected value: ${expected}`, () => {
451
- expect(morphoAaveV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
770
+ expect(subDataService.morphoAaveV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
452
771
  });
453
772
  });
454
773
  });
@@ -465,7 +784,7 @@ describe('Feature: subDataService.ts', () => {
465
784
  ];
466
785
  examples.forEach(([expected, actual]) => {
467
786
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
468
- expect(morphoAaveV2LeverageManagementSubData.decode(actual)).to.eql(expected);
787
+ expect(subDataService.morphoAaveV2LeverageManagementSubData.decode(actual)).to.eql(expected);
469
788
  });
470
789
  });
471
790
  });
@@ -484,7 +803,7 @@ describe('Feature: subDataService.ts', () => {
484
803
  ];
485
804
  examples.forEach(([expected, actual]) => {
486
805
  it(`Given ${actual} should return expected value: ${expected}`, () => {
487
- expect(cBondsRebondSubData.encode(...actual)).to.eql(expected);
806
+ expect(subDataService.cBondsRebondSubData.encode(...actual)).to.eql(expected);
488
807
  });
489
808
  });
490
809
  });
@@ -501,7 +820,7 @@ describe('Feature: subDataService.ts', () => {
501
820
  ];
502
821
  examples.forEach(([expected, actual]) => {
503
822
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
504
- expect(cBondsRebondSubData.decode(actual)).to.eql(expected);
823
+ expect(subDataService.cBondsRebondSubData.decode(actual)).to.eql(expected);
505
824
  });
506
825
  });
507
826
  });
@@ -526,7 +845,7 @@ describe('Feature: subDataService.ts', () => {
526
845
  ];
527
846
  examples.forEach(([expected, actual]) => {
528
847
  it(`Given ${actual} should return expected value: ${expected}`, () => {
529
- expect(liquityPaybackUsingChickenBondSubData.encode(...actual)).to.eql(expected);
848
+ expect(subDataService.liquityPaybackUsingChickenBondSubData.encode(...actual)).to.eql(expected);
530
849
  });
531
850
  });
532
851
  });
@@ -549,7 +868,7 @@ describe('Feature: subDataService.ts', () => {
549
868
  ];
550
869
  examples.forEach(([expected, actual]) => {
551
870
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
552
- expect(liquityPaybackUsingChickenBondSubData.decode(actual)).to.eql(expected);
871
+ expect(subDataService.liquityPaybackUsingChickenBondSubData.decode(actual)).to.eql(expected);
553
872
  });
554
873
  });
555
874
  });
@@ -584,7 +903,7 @@ describe('Feature: subDataService.ts', () => {
584
903
  ];
585
904
  examples.forEach(([expected, actual]) => {
586
905
  it(`Given ${actual} should return expected value: ${expected}`, () => {
587
- expect(exchangeDcaSubData.encode(...actual)).to.eql(expected);
906
+ expect(subDataService.exchangeDcaSubData.encode(...actual)).to.eql(expected);
588
907
  });
589
908
  });
590
909
  });
@@ -623,7 +942,7 @@ describe('Feature: subDataService.ts', () => {
623
942
  ];
624
943
  examples.forEach(([expected, actual]) => {
625
944
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
626
- expect(exchangeDcaSubData.decode(...actual)).to.eql(expected);
945
+ expect(subDataService.exchangeDcaSubData.decode(...actual)).to.eql(expected);
627
946
  });
628
947
  });
629
948
  });
@@ -670,7 +989,7 @@ describe('Feature: subDataService.ts', () => {
670
989
  ];
671
990
  examples.forEach(([expected, actual]) => {
672
991
  it(`Given ${actual} should return expected value: ${expected}`, () => {
673
- expect(exchangeLimitOrderSubData.encode(...actual)).to.eql(expected);
992
+ expect(subDataService.exchangeLimitOrderSubData.encode(...actual)).to.eql(expected);
674
993
  });
675
994
  });
676
995
  });
@@ -707,7 +1026,7 @@ describe('Feature: subDataService.ts', () => {
707
1026
  ];
708
1027
  examples.forEach(([expected, actual]) => {
709
1028
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
710
- expect(exchangeLimitOrderSubData.decode(...actual)).to.eql(expected);
1029
+ expect(subDataService.exchangeLimitOrderSubData.decode(...actual)).to.eql(expected);
711
1030
  });
712
1031
  });
713
1032
  });
@@ -726,44 +1045,32 @@ describe('Feature: subDataService.ts', () => {
726
1045
  ];
727
1046
  examples.forEach(([expected, actual]) => {
728
1047
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
729
- expect(sparkLeverageManagementSubData.decode(actual)).to.eql(expected);
1048
+ expect(subDataService.sparkLeverageManagementSubData.decode(actual)).to.eql(expected);
730
1049
  });
731
1050
  });
732
1051
  });
733
1052
  });
734
- describe('When testing subDataService.sparkQuotePriceSubData', () => {
1053
+ describe('When testing subDataService.liquityDsrPaybackSubData', () => {
735
1054
  describe('encode()', () => {
736
1055
  const examples = [
737
1056
  [
738
1057
  [
739
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000002',
740
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000004',
741
- '0x0000000000000000000000000000000000000000000000000000000000000000',
1058
+ '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
1059
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
742
1060
  ],
743
- [
744
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
745
- 2,
746
- web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
747
- 4,
748
- ]
1061
+ [123]
749
1062
  ],
750
1063
  [
751
1064
  [
752
- '0x0000000000000000000000005979d7b546e38e414f7e9822514be443a4800529', '0x0000000000000000000000000000000000000000000000000000000000000006',
753
- '0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831', '0x0000000000000000000000000000000000000000000000000000000000000002',
754
- '0x0000000000000000000000000000000000000000000000000000000000000000',
1065
+ '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000003a4965bf58a40000',
1066
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
755
1067
  ],
756
- [
757
- web3Utils.toChecksumAddress(getAssetInfo('wstETH', ChainId.Arbitrum).address),
758
- 6,
759
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
760
- 2,
761
- ]
1068
+ [420]
762
1069
  ],
763
1070
  ];
764
1071
  examples.forEach(([expected, actual]) => {
765
1072
  it(`Given ${actual} should return expected value: ${expected}`, () => {
766
- expect(sparkQuotePriceSubData.encode(...actual)).to.eql(expected);
1073
+ expect(subDataService.liquityDsrPaybackSubData.encode(...actual)).to.eql(expected);
767
1074
  });
768
1075
  });
769
1076
  });
@@ -771,111 +1078,51 @@ describe('Feature: subDataService.ts', () => {
771
1078
  const examples = [
772
1079
  [
773
1080
  {
774
- collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
775
- collAssetId: 2,
776
- debtAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
777
- debtAssetId: 4,
1081
+ targetRatio: 123,
778
1082
  },
779
1083
  [
780
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000002',
781
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000004',
782
- '0x0000000000000000000000000000000000000000000000000000000000000000',
1084
+ '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
1085
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
783
1086
  ],
784
1087
  ],
785
1088
  [
786
1089
  {
787
- collAsset: web3Utils.toChecksumAddress(getAssetInfo('wstETH', ChainId.Arbitrum).address),
788
- collAssetId: 6,
789
- debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
790
- debtAssetId: 2,
1090
+ targetRatio: 420,
791
1091
  },
792
1092
  [
793
- '0x0000000000000000000000005979d7b546e38e414f7e9822514be443a4800529', '0x0000000000000000000000000000000000000000000000000000000000000006',
794
- '0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831', '0x0000000000000000000000000000000000000000000000000000000000000002',
795
- '0x0000000000000000000000000000000000000000000000000000000000000000',
1093
+ '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000003a4965bf58a40000',
1094
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
796
1095
  ],
797
1096
  ],
798
1097
  ];
799
1098
  examples.forEach(([expected, actual]) => {
800
1099
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
801
- expect(sparkQuotePriceSubData.decode(actual)).to.eql(expected);
1100
+ expect(subDataService.liquityDsrPaybackSubData.decode(actual)).to.eql(expected);
802
1101
  });
803
1102
  });
804
1103
  });
805
1104
  });
806
- describe('When testing subDataService.liquityDsrPaybackSubData', () => {
1105
+ describe('When testing subDataService.liquityDsrSupplySubData', () => {
807
1106
  describe('encode()', () => {
808
1107
  const examples = [
809
1108
  [
810
1109
  [
811
- '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
812
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
1110
+ '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000002c68af0bb1400000',
1111
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
813
1112
  ],
814
- [123]
1113
+ [320]
815
1114
  ],
816
1115
  [
817
1116
  [
818
- '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000003a4965bf58a40000',
819
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
1117
+ '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001eab7f4a799d0000',
1118
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
820
1119
  ],
821
- [420]
1120
+ [221]
822
1121
  ],
823
1122
  ];
824
1123
  examples.forEach(([expected, actual]) => {
825
1124
  it(`Given ${actual} should return expected value: ${expected}`, () => {
826
- expect(liquityDsrPaybackSubData.encode(...actual)).to.eql(expected);
827
- });
828
- });
829
- });
830
- describe('decode()', () => {
831
- const examples = [
832
- [
833
- {
834
- targetRatio: 123,
835
- },
836
- [
837
- '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
838
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
839
- ],
840
- ],
841
- [
842
- {
843
- targetRatio: 420,
844
- },
845
- [
846
- '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000003a4965bf58a40000',
847
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
848
- ],
849
- ],
850
- ];
851
- examples.forEach(([expected, actual]) => {
852
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
853
- expect(liquityDsrPaybackSubData.decode(actual)).to.eql(expected);
854
- });
855
- });
856
- });
857
- });
858
- describe('When testing subDataService.liquityDsrSupplySubData', () => {
859
- describe('encode()', () => {
860
- const examples = [
861
- [
862
- [
863
- '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000002c68af0bb1400000',
864
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
865
- ],
866
- [320]
867
- ],
868
- [
869
- [
870
- '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001eab7f4a799d0000',
871
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
872
- ],
873
- [221]
874
- ],
875
- ];
876
- examples.forEach(([expected, actual]) => {
877
- it(`Given ${actual} should return expected value: ${expected}`, () => {
878
- expect(liquityDsrSupplySubData.encode(...actual)).to.eql(expected);
1125
+ expect(subDataService.liquityDsrSupplySubData.encode(...actual)).to.eql(expected);
879
1126
  });
880
1127
  });
881
1128
  });
@@ -902,7 +1149,7 @@ describe('Feature: subDataService.ts', () => {
902
1149
  ];
903
1150
  examples.forEach(([expected, actual]) => {
904
1151
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
905
- expect(liquityDsrSupplySubData.decode(actual)).to.eql(expected);
1152
+ expect(subDataService.liquityDsrSupplySubData.decode(actual)).to.eql(expected);
906
1153
  });
907
1154
  });
908
1155
  });
@@ -929,7 +1176,7 @@ describe('Feature: subDataService.ts', () => {
929
1176
  ];
930
1177
  examples.forEach(([expected, actual]) => {
931
1178
  it(`Given ${actual} should return expected value: ${expected}`, () => {
932
- expect(liquityDebtInFrontRepaySubData.encode(...actual)).to.eql(expected);
1179
+ expect(subDataService.liquityDebtInFrontRepaySubData.encode(...actual)).to.eql(expected);
933
1180
  });
934
1181
  });
935
1182
  });
@@ -958,7 +1205,7 @@ describe('Feature: subDataService.ts', () => {
958
1205
  ];
959
1206
  examples.forEach(([expected, actual]) => {
960
1207
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
961
- expect(liquityDebtInFrontRepaySubData.decode(actual)).to.eql(expected);
1208
+ expect(subDataService.liquityDebtInFrontRepaySubData.decode(actual)).to.eql(expected);
962
1209
  });
963
1210
  });
964
1211
  });
@@ -989,7 +1236,7 @@ describe('Feature: subDataService.ts', () => {
989
1236
  ];
990
1237
  examples.forEach(([expected, actual]) => {
991
1238
  it(`Given ${actual} should return expected value: ${expected}`, () => {
992
- expect(crvUSDLeverageManagementSubData.encode(...actual)).to.eql(expected);
1239
+ expect(subDataService.crvUSDLeverageManagementSubData.encode(...actual)).to.eql(expected);
993
1240
  });
994
1241
  });
995
1242
  });
@@ -1012,7 +1259,7 @@ describe('Feature: subDataService.ts', () => {
1012
1259
  ];
1013
1260
  examples.forEach(([expected, actual]) => {
1014
1261
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1015
- expect(crvUSDLeverageManagementSubData.decode(actual)).to.eql(expected);
1262
+ expect(subDataService.crvUSDLeverageManagementSubData.decode(actual)).to.eql(expected);
1016
1263
  });
1017
1264
  });
1018
1265
  });
@@ -1033,7 +1280,7 @@ describe('Feature: subDataService.ts', () => {
1033
1280
  ];
1034
1281
  examples.forEach(([expected, actual]) => {
1035
1282
  it(`Given ${actual} should return expected value: ${expected}`, () => {
1036
- expect(crvUSDPaybackSubData.encode(...actual)).to.eql(expected);
1283
+ expect(subDataService.crvUSDPaybackSubData.encode(...actual)).to.eql(expected);
1037
1284
  });
1038
1285
  });
1039
1286
  });
@@ -1057,7 +1304,7 @@ describe('Feature: subDataService.ts', () => {
1057
1304
  ];
1058
1305
  examples.forEach(([expected, actual]) => {
1059
1306
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1060
- expect(crvUSDPaybackSubData.decode(actual)).to.eql(expected);
1307
+ expect(subDataService.crvUSDPaybackSubData.decode(actual)).to.eql(expected);
1061
1308
  });
1062
1309
  });
1063
1310
  });
@@ -1066,17 +1313,17 @@ describe('Feature: subDataService.ts', () => {
1066
1313
  describe('encode()', () => {
1067
1314
  const examples = [
1068
1315
  [
1069
- '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0213D212133AfaB8F2b829B1066C7E43cAD94E2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e000001',
1070
- [web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'), web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'), 160, 220, 180, 190, true]
1316
+ '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0213D212133AfaB8F2b829B1066C7E43cAD94E2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e00000100',
1317
+ [web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'), web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'), 160, 220, 180, 190, true, false]
1071
1318
  ],
1072
1319
  [
1073
- '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0413d212133afAb8F2B829b1066C7e43cAd94e2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000000f43fc2c04ee000000',
1074
- [web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'), web3Utils.toChecksumAddress('0x0413d212133AFaB8F2B829B1066c7E43cAd94E2c'), 160, 220, 180, 110, false]
1320
+ '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0413d212133afAb8F2B829b1066C7e43cAd94e2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000000f43fc2c04ee00000000',
1321
+ [web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'), web3Utils.toChecksumAddress('0x0413d212133AFaB8F2B829B1066c7E43cAd94E2c'), 160, 220, 180, 110, false, false]
1075
1322
  ],
1076
1323
  ];
1077
1324
  examples.forEach(([expected, actual]) => {
1078
1325
  it(`Given ${actual} should return expected value: ${expected}`, () => {
1079
- expect(compoundV3L2LeverageManagementSubData.encode(...actual)).to.eql(expected);
1326
+ expect(subDataService.compoundV3L2LeverageManagementSubData.encode(...actual)).to.eql(expected);
1080
1327
  });
1081
1328
  });
1082
1329
  });
@@ -1099,7 +1346,7 @@ describe('Feature: subDataService.ts', () => {
1099
1346
  ];
1100
1347
  examples.forEach(([expected, actual]) => {
1101
1348
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1102
- expect(compoundV3L2LeverageManagementSubData.decode(actual)).to.eql(expected);
1349
+ expect(subDataService.compoundV3L2LeverageManagementSubData.decode(actual)).to.eql(expected);
1103
1350
  });
1104
1351
  });
1105
1352
  });
@@ -1138,7 +1385,7 @@ describe('Feature: subDataService.ts', () => {
1138
1385
  ];
1139
1386
  examples.forEach(([expected, actual]) => {
1140
1387
  it(`Given ${actual} should return expected value: ${expected}`, () => {
1141
- expect(morphoBlueLeverageManagementSubData.encode(...actual)).to.eql(expected);
1388
+ expect(subDataService.morphoBlueLeverageManagementSubData.encode(...actual)).to.eql(expected);
1142
1389
  });
1143
1390
  });
1144
1391
  });
@@ -1189,7 +1436,59 @@ describe('Feature: subDataService.ts', () => {
1189
1436
  ];
1190
1437
  examples.forEach(([expected, actual]) => {
1191
1438
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1192
- expect(morphoBlueLeverageManagementSubData.decode(actual)).to.eql(expected);
1439
+ expect(subDataService.morphoBlueLeverageManagementSubData.decode(actual)).to.eql(expected);
1440
+ });
1441
+ });
1442
+ });
1443
+ });
1444
+ describe('When testing subDataService.morphoBlueCloseOnPriceSubData', () => {
1445
+ describe('encode()', () => {
1446
+ const examples = [
1447
+ [
1448
+ [
1449
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1450
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1451
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1452
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1453
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1454
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1455
+ '0x0000000000000000000000000000000000000000000000000000000000000006',
1456
+ ],
1457
+ [web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'), '945000000000000000', web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT]
1458
+ ],
1459
+ ];
1460
+ examples.forEach(([expected, actual]) => {
1461
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1462
+ expect(subDataService.morphoBlueCloseOnPriceSubData.encode(...actual)).to.eql(expected);
1463
+ });
1464
+ });
1465
+ });
1466
+ describe('decode()', () => {
1467
+ const examples = [
1468
+ [
1469
+ {
1470
+ loanToken: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
1471
+ collToken: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0',
1472
+ oracle: '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
1473
+ irm: '0x0000000000000000000000000000000000000000',
1474
+ lltv: '945000000000000000',
1475
+ user: '0x1031d218133AFaB8C2B819B1366c7e434Ad91e9c',
1476
+ closeType: CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT,
1477
+ },
1478
+ [
1479
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1480
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1481
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1482
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1483
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1484
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1485
+ '0x0000000000000000000000000000000000000000000000000000000000000006',
1486
+ ],
1487
+ ],
1488
+ ];
1489
+ examples.forEach(([expected, actual]) => {
1490
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1491
+ expect(subDataService.morphoBlueCloseOnPriceSubData.decode(actual)).to.eql(expected);
1193
1492
  });
1194
1493
  });
1195
1494
  });
@@ -1219,7 +1518,7 @@ describe('Feature: subDataService.ts', () => {
1219
1518
  ];
1220
1519
  examples.forEach(([expected, actual]) => {
1221
1520
  it(`Given ${actual} should return expected value: ${expected}`, () => {
1222
- expect(aaveV3LeverageManagementOnPriceSubData.encode(...actual)).to.eql(expected);
1521
+ expect(subDataService.aaveV3LeverageManagementOnPriceSubData.encode(...actual)).to.eql(expected);
1223
1522
  });
1224
1523
  });
1225
1524
  });
@@ -1246,7 +1545,853 @@ describe('Feature: subDataService.ts', () => {
1246
1545
  ];
1247
1546
  examples.forEach(([expected, actual]) => {
1248
1547
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1249
- expect(aaveV3LeverageManagementOnPriceSubData.decode(actual)).to.eql(expected);
1548
+ expect(subDataService.aaveV3LeverageManagementOnPriceSubData.decode(actual)).to.eql(expected);
1549
+ });
1550
+ });
1551
+ });
1552
+ });
1553
+ describe('When testing subDataService.compoundV3LeverageManagementOnPriceSubData', () => {
1554
+ describe('encode()', () => {
1555
+ const examples = [
1556
+ [
1557
+ [
1558
+ '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
1559
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1560
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1561
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1562
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1563
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c'
1564
+ ],
1565
+ [
1566
+ web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
1567
+ web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1568
+ web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
1569
+ 200,
1570
+ RatioState.UNDER,
1571
+ web3Utils.toChecksumAddress('0x1031d218133afab8c2b819b1366c7e434ad91e9c')
1572
+ ]
1573
+ ],
1574
+ [
1575
+ [
1576
+ '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
1577
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1578
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1579
+ '0x0000000000000000000000000000000000000000000000001a5e27eef13e0000',
1580
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1581
+ '0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c'
1582
+ ],
1583
+ [
1584
+ web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
1585
+ web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1586
+ web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
1587
+ 190,
1588
+ RatioState.OVER,
1589
+ web3Utils.toChecksumAddress('0x0043d218133afab8f2b829b106633e434ad94e2c')
1590
+ ]
1591
+ ],
1592
+ ];
1593
+ examples.forEach(([expected, actual]) => {
1594
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1595
+ expect(subDataService.compoundV3LeverageManagementOnPriceSubData.encode(...actual)).to.eql(expected);
1596
+ });
1597
+ });
1598
+ });
1599
+ describe('decode()', () => {
1600
+ const examples = [
1601
+ [
1602
+ {
1603
+ market: web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
1604
+ collToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1605
+ baseToken: web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
1606
+ targetRatio: 200,
1607
+ ratioState: RatioState.UNDER,
1608
+ owner: web3Utils.toChecksumAddress('0x1031d218133afab8c2b819b1366c7e434ad91e9c')
1609
+ },
1610
+ [
1611
+ '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
1612
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1613
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1614
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1615
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1616
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c'
1617
+ ]
1618
+ ],
1619
+ [
1620
+ {
1621
+ market: web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
1622
+ collToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1623
+ baseToken: web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
1624
+ targetRatio: 190,
1625
+ ratioState: RatioState.OVER,
1626
+ owner: web3Utils.toChecksumAddress('0x0043d218133afab8f2b829b106633e434ad94e2c')
1627
+ },
1628
+ [
1629
+ '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
1630
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1631
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1632
+ '0x0000000000000000000000000000000000000000000000001a5e27eef13e0000',
1633
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1634
+ '0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c'
1635
+ ]
1636
+ ],
1637
+ ];
1638
+ examples.forEach(([expected, actual]) => {
1639
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1640
+ expect(subDataService.compoundV3LeverageManagementOnPriceSubData.decode(actual)).to.eql(expected);
1641
+ });
1642
+ });
1643
+ });
1644
+ });
1645
+ describe('When testing subDataService.compoundV3CloseSubData', () => {
1646
+ describe('encode()', () => {
1647
+ const examples = [
1648
+ [
1649
+ [
1650
+ '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
1651
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1652
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1653
+ '0x0000000000000000000000000000000000000000000000000000000000000006',
1654
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1655
+ ],
1656
+ [
1657
+ web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
1658
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1659
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1660
+ CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT,
1661
+ web3Utils.toChecksumAddress('0x1031d218133afab8c2b819b1366c7e434ad91e9c'),
1662
+ ]
1663
+ ],
1664
+ [
1665
+ [
1666
+ '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
1667
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1668
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1669
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1670
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1671
+ ],
1672
+ [
1673
+ web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
1674
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1675
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1676
+ CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL,
1677
+ web3Utils.toChecksumAddress('0x1031d218133afab8c2b819b1366c7e434ad91e9c'),
1678
+ ]
1679
+ ],
1680
+ ];
1681
+ examples.forEach(([expected, actual]) => {
1682
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1683
+ expect(subDataService.compoundV3CloseSubData.encode(...actual)).to.eql(expected);
1684
+ });
1685
+ });
1686
+ });
1687
+ describe('decode()', () => {
1688
+ const examples = [
1689
+ [
1690
+ {
1691
+ market: web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
1692
+ collToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1693
+ baseToken: web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
1694
+ closeType: CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT,
1695
+ owner: web3Utils.toChecksumAddress('0x1031d218133afab8c2b819b1366c7e434ad91e9c')
1696
+ },
1697
+ [
1698
+ '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
1699
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1700
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1701
+ '0x0000000000000000000000000000000000000000000000000000000000000006',
1702
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c'
1703
+ ]
1704
+ ],
1705
+ [
1706
+ {
1707
+ market: web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
1708
+ collToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1709
+ baseToken: web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
1710
+ closeType: CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL,
1711
+ owner: web3Utils.toChecksumAddress('0x1031d218133afab8c2b819b1366c7e434ad91e9c')
1712
+ },
1713
+ [
1714
+ '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
1715
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1716
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1717
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1718
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c'
1719
+ ]
1720
+ ],
1721
+ ];
1722
+ examples.forEach(([expected, actual]) => {
1723
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1724
+ expect(subDataService.compoundV3CloseSubData.decode(actual)).to.eql(expected);
1725
+ });
1726
+ });
1727
+ });
1728
+ });
1729
+ describe("When testing subDataService.aaveV3LeverageManagementOnPriceGeneric", () => {
1730
+ describe("encode()", () => {
1731
+ const examples = [
1732
+ [
1733
+ [
1734
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1735
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1736
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1737
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1738
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1739
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1740
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1741
+ ],
1742
+ [
1743
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1744
+ 0,
1745
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1746
+ 1,
1747
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1748
+ 200,
1749
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1750
+ ]
1751
+ ],
1752
+ [
1753
+ [
1754
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
1755
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1756
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1757
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1758
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1759
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1760
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
1761
+ ],
1762
+ [
1763
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
1764
+ 2,
1765
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1766
+ 1,
1767
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1768
+ 200,
1769
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
1770
+ ]
1771
+ ],
1772
+ ];
1773
+ examples.forEach(([expected, actual]) => {
1774
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1775
+ expect(subDataService.aaveV3LeverageManagementOnPriceGeneric.encode(...actual)).to.eql(expected);
1776
+ });
1777
+ });
1778
+ });
1779
+ describe("decode()", () => {
1780
+ const examples = [
1781
+ [
1782
+ {
1783
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1784
+ collAssetId: 0,
1785
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1786
+ debtAssetId: 1,
1787
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1788
+ targetRatio: 200,
1789
+ owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1790
+ },
1791
+ [
1792
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1793
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1794
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1795
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1796
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1797
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1798
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1799
+ ]
1800
+ ],
1801
+ [
1802
+ {
1803
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
1804
+ collAssetId: 2,
1805
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1806
+ debtAssetId: 1,
1807
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1808
+ targetRatio: 200,
1809
+ owner: web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
1810
+ },
1811
+ [
1812
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
1813
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1814
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1815
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1816
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1817
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1818
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
1819
+ ]
1820
+ ],
1821
+ ];
1822
+ examples.forEach(([expected, actual]) => {
1823
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1824
+ expect(subDataService.aaveV3LeverageManagementOnPriceGeneric.decode(actual)).to.eql(expected);
1825
+ });
1826
+ });
1827
+ });
1828
+ });
1829
+ describe("When testing subDataService.aaveV3CloseGenericSubData", () => {
1830
+ describe("encode()", () => {
1831
+ const examples = [
1832
+ // TAKE_PROFIT_IN_COLLATERAL
1833
+ [
1834
+ [
1835
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1836
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1837
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1838
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1839
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1840
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1841
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1842
+ ],
1843
+ [
1844
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1845
+ 0,
1846
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1847
+ 1,
1848
+ CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL,
1849
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1850
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1851
+ ]
1852
+ ],
1853
+ // STOP_LOSS_IN_COLLATERAL
1854
+ [
1855
+ [
1856
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1857
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1858
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1859
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1860
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1861
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1862
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1863
+ ],
1864
+ [
1865
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1866
+ 0,
1867
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1868
+ 1,
1869
+ CloseStrategyType.STOP_LOSS_IN_COLLATERAL,
1870
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1871
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1872
+ ]
1873
+ ],
1874
+ // TAKE_PROFIT_IN_DEBT
1875
+ [
1876
+ [
1877
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1878
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1879
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1880
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1881
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1882
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1883
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1884
+ ],
1885
+ [
1886
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1887
+ 0,
1888
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1889
+ 1,
1890
+ CloseStrategyType.TAKE_PROFIT_IN_DEBT,
1891
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1892
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1893
+ ]
1894
+ ],
1895
+ // STOP_LOSS_IN_DEBT
1896
+ [
1897
+ [
1898
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1899
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1900
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1901
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1902
+ '0x0000000000000000000000000000000000000000000000000000000000000003',
1903
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1904
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1905
+ ],
1906
+ [
1907
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1908
+ 0,
1909
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1910
+ 1,
1911
+ CloseStrategyType.STOP_LOSS_IN_DEBT,
1912
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1913
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1914
+ ]
1915
+ ],
1916
+ // TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL
1917
+ [
1918
+ [
1919
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1920
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1921
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1922
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1923
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
1924
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1925
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
1926
+ ],
1927
+ [
1928
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1929
+ 0,
1930
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1931
+ 1,
1932
+ CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL,
1933
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1934
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
1935
+ ]
1936
+ ],
1937
+ // TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT
1938
+ [
1939
+ [
1940
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
1941
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1942
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1943
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1944
+ '0x0000000000000000000000000000000000000000000000000000000000000005',
1945
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1946
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1947
+ ],
1948
+ [
1949
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
1950
+ 2,
1951
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1952
+ 1,
1953
+ CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT,
1954
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1955
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1956
+ ]
1957
+ ],
1958
+ // TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT
1959
+ [
1960
+ [
1961
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
1962
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1963
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1964
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1965
+ '0x0000000000000000000000000000000000000000000000000000000000000006',
1966
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1967
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1968
+ ],
1969
+ [
1970
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
1971
+ 2,
1972
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1973
+ 1,
1974
+ CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT,
1975
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1976
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1977
+ ]
1978
+ ],
1979
+ // TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL
1980
+ [
1981
+ [
1982
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
1983
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1984
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1985
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1986
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
1987
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1988
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1989
+ ],
1990
+ [
1991
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
1992
+ 2,
1993
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1994
+ 1,
1995
+ CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL,
1996
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1997
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1998
+ ]
1999
+ ],
2000
+ ];
2001
+ examples.forEach(([expected, actual]) => {
2002
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2003
+ expect(subDataService.aaveV3CloseGenericSubData.encode(...actual)).to.eql(expected);
2004
+ });
2005
+ });
2006
+ });
2007
+ describe("decode()", () => {
2008
+ const examples = [
2009
+ // TAKE_PROFIT_IN_COLLATERAL
2010
+ [
2011
+ {
2012
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
2013
+ collAssetId: 0,
2014
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
2015
+ debtAssetId: 1,
2016
+ closeType: CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL,
2017
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
2018
+ owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
2019
+ },
2020
+ [
2021
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
2022
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2023
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
2024
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2025
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2026
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
2027
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2028
+ ]
2029
+ ],
2030
+ // STOP_LOSS_IN_COLLATERAL
2031
+ [
2032
+ {
2033
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
2034
+ collAssetId: 0,
2035
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
2036
+ debtAssetId: 1,
2037
+ closeType: CloseStrategyType.STOP_LOSS_IN_COLLATERAL,
2038
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
2039
+ owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
2040
+ },
2041
+ [
2042
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
2043
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2044
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
2045
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2046
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2047
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
2048
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2049
+ ]
2050
+ ],
2051
+ // TAKE_PROFIT_IN_DEBT
2052
+ [
2053
+ {
2054
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
2055
+ collAssetId: 0,
2056
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
2057
+ debtAssetId: 1,
2058
+ closeType: CloseStrategyType.TAKE_PROFIT_IN_DEBT,
2059
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
2060
+ owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
2061
+ },
2062
+ [
2063
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
2064
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2065
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
2066
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2067
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
2068
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
2069
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2070
+ ]
2071
+ ],
2072
+ // STOP_LOSS_IN_DEBT
2073
+ [
2074
+ {
2075
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
2076
+ collAssetId: 0,
2077
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
2078
+ debtAssetId: 1,
2079
+ closeType: CloseStrategyType.STOP_LOSS_IN_DEBT,
2080
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
2081
+ owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
2082
+ },
2083
+ [
2084
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
2085
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2086
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
2087
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2088
+ '0x0000000000000000000000000000000000000000000000000000000000000003',
2089
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
2090
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2091
+ ]
2092
+ ],
2093
+ // TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL
2094
+ [
2095
+ {
2096
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
2097
+ collAssetId: 0,
2098
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
2099
+ debtAssetId: 1,
2100
+ closeType: CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL,
2101
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
2102
+ owner: web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
2103
+ },
2104
+ [
2105
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
2106
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2107
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
2108
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2109
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
2110
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
2111
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2112
+ ]
2113
+ ],
2114
+ // TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT
2115
+ [
2116
+ {
2117
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
2118
+ collAssetId: 2,
2119
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
2120
+ debtAssetId: 1,
2121
+ closeType: CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT,
2122
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
2123
+ owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
2124
+ },
2125
+ [
2126
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
2127
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
2128
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
2129
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2130
+ '0x0000000000000000000000000000000000000000000000000000000000000005',
2131
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
2132
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2133
+ ]
2134
+ ],
2135
+ // TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT
2136
+ [
2137
+ {
2138
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
2139
+ collAssetId: 2,
2140
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
2141
+ debtAssetId: 1,
2142
+ closeType: CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT,
2143
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
2144
+ owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
2145
+ },
2146
+ [
2147
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
2148
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
2149
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
2150
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2151
+ '0x0000000000000000000000000000000000000000000000000000000000000006',
2152
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
2153
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2154
+ ]
2155
+ ],
2156
+ // TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL
2157
+ [
2158
+ {
2159
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
2160
+ collAssetId: 2,
2161
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
2162
+ debtAssetId: 1,
2163
+ closeType: CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL,
2164
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
2165
+ owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
2166
+ },
2167
+ [
2168
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
2169
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
2170
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
2171
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2172
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
2173
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
2174
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2175
+ ]
2176
+ ],
2177
+ ];
2178
+ examples.forEach(([expected, actual]) => {
2179
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2180
+ expect(subDataService.aaveV3CloseGenericSubData.decode(actual)).to.eql(expected);
2181
+ });
2182
+ });
2183
+ });
2184
+ });
2185
+ describe('When testing subDataService.sparkLeverageManagementOnPriceSubData', () => {
2186
+ describe('encode()', () => {
2187
+ const examples = [
2188
+ [
2189
+ [
2190
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
2191
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2192
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
2193
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2194
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2195
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
2196
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2197
+ ],
2198
+ [
2199
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
2200
+ 0,
2201
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
2202
+ 1,
2203
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2204
+ 200,
2205
+ ]
2206
+ ]
2207
+ ];
2208
+ examples.forEach(([expected, actual]) => {
2209
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2210
+ expect(subDataService.sparkLeverageManagementOnPriceSubData.encode(...actual)).to.eql(expected);
2211
+ });
2212
+ });
2213
+ });
2214
+ describe('decode()', () => {
2215
+ const examples = [
2216
+ [
2217
+ {
2218
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
2219
+ collAssetId: 2,
2220
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
2221
+ debtAssetId: 4,
2222
+ marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2223
+ targetRatio: 175
2224
+ },
2225
+ [
2226
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
2227
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
2228
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
2229
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
2230
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2231
+ '0x00000000000000000000000000000000000000000000000018493fba64ef0000'
2232
+ ]
2233
+ ]
2234
+ ];
2235
+ examples.forEach(([expected, actual]) => {
2236
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2237
+ expect(subDataService.sparkLeverageManagementOnPriceSubData.decode(actual)).to.eql(expected);
2238
+ });
2239
+ });
2240
+ });
2241
+ });
2242
+ describe('When testing subDataService.aaveV4LeverageManagementSubData', () => {
2243
+ describe('encode()', () => {
2244
+ const examples = [
2245
+ [
2246
+ ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x00000000000000000000000000000000000000000000000014d1120d7b160000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"],
2247
+ [web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), RatioState.UNDER, 150]
2248
+ ],
2249
+ ];
2250
+ examples.forEach(([expected, actual]) => {
2251
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
2252
+ expect(subDataService.aaveV4LeverageManagementSubData.encode(...actual)).to.eql(expected);
2253
+ });
2254
+ });
2255
+ });
2256
+ describe('decode()', () => {
2257
+ const examples = [
2258
+ [
2259
+ {
2260
+ spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
2261
+ owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
2262
+ ratioState: RatioState.UNDER,
2263
+ targetRatio: 150,
2264
+ },
2265
+ ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x00000000000000000000000000000000000000000000000014d1120d7b160000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"],
2266
+ ],
2267
+ ];
2268
+ examples.forEach(([expected, actual]) => {
2269
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
2270
+ expect(subDataService.aaveV4LeverageManagementSubData.decode(actual)).to.eql(expected);
2271
+ });
2272
+ });
2273
+ });
2274
+ });
2275
+ describe('When testing subDataService.aaveV4LeverageManagementOnPriceSubData', () => {
2276
+ describe('encode()', () => {
2277
+ const examples = [
2278
+ [
2279
+ ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x00000000000000000000000000000000000000000000000016345785d8a00000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"],
2280
+ [
2281
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
2282
+ web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 10,
2283
+ web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), 20,
2284
+ RatioState.OVER, 160
2285
+ ]
2286
+ ],
2287
+ ];
2288
+ examples.forEach(([expected, actual]) => {
2289
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
2290
+ expect(subDataService.aaveV4LeverageManagementOnPriceSubData.encode(...actual)).to.eql(expected);
2291
+ });
2292
+ });
2293
+ });
2294
+ describe('decode()', () => {
2295
+ const examples = [
2296
+ [
2297
+ {
2298
+ spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
2299
+ owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
2300
+ collAsset: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
2301
+ collAssetId: 10,
2302
+ debtAsset: web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
2303
+ debtAssetId: 20,
2304
+ ratioState: RatioState.OVER,
2305
+ targetRatio: 160,
2306
+ },
2307
+ ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x00000000000000000000000000000000000000000000000016345785d8a00000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"],
2308
+ ],
2309
+ ];
2310
+ examples.forEach(([expected, actual]) => {
2311
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
2312
+ expect(subDataService.aaveV4LeverageManagementOnPriceSubData.decode(actual)).to.eql(expected);
2313
+ });
2314
+ });
2315
+ });
2316
+ });
2317
+ describe('When testing subDataService.aaveV4CloseSubData', () => {
2318
+ describe('encode()', () => {
2319
+ const examples = [
2320
+ [
2321
+ ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"],
2322
+ [
2323
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
2324
+ web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 10,
2325
+ web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), 20,
2326
+ CloseStrategyType.STOP_LOSS_IN_COLLATERAL
2327
+ ]
2328
+ ],
2329
+ ];
2330
+ examples.forEach(([expected, actual]) => {
2331
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
2332
+ expect(subDataService.aaveV4CloseSubData.encode(...actual)).to.eql(expected);
2333
+ });
2334
+ });
2335
+ });
2336
+ describe('decode()', () => {
2337
+ const examples = [
2338
+ [
2339
+ {
2340
+ spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
2341
+ owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
2342
+ collAsset: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
2343
+ collAssetId: 10,
2344
+ debtAsset: web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
2345
+ debtAssetId: 20,
2346
+ closeType: CloseStrategyType.STOP_LOSS_IN_COLLATERAL,
2347
+ },
2348
+ ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"],
2349
+ ],
2350
+ ];
2351
+ examples.forEach(([expected, actual]) => {
2352
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
2353
+ expect(subDataService.aaveV4CloseSubData.decode(actual)).to.eql(expected);
2354
+ });
2355
+ });
2356
+ });
2357
+ });
2358
+ describe('When testing subDataService.aaveV4CollateralSwitchSubData', () => {
2359
+ describe('encode()', () => {
2360
+ const examples = [
2361
+ [
2362
+ ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"],
2363
+ [
2364
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
2365
+ web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 10,
2366
+ web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), 20,
2367
+ '1000000000000000000'
2368
+ ]
2369
+ ],
2370
+ ];
2371
+ examples.forEach(([expected, actual]) => {
2372
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
2373
+ expect(subDataService.aaveV4CollateralSwitchSubData.encode(...actual)).to.eql(expected);
2374
+ });
2375
+ });
2376
+ });
2377
+ describe('decode()', () => {
2378
+ const examples = [
2379
+ [
2380
+ {
2381
+ spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
2382
+ owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
2383
+ fromAsset: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
2384
+ fromAssetId: 10,
2385
+ toAsset: web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
2386
+ toAssetId: 20,
2387
+ amountToSwitch: '1000000000000000000'
2388
+ },
2389
+ ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"],
2390
+ ],
2391
+ ];
2392
+ examples.forEach(([expected, actual]) => {
2393
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
2394
+ expect(subDataService.aaveV4CollateralSwitchSubData.decode(actual)).to.eql(expected);
1250
2395
  });
1251
2396
  });
1252
2397
  });