@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
@@ -146,6 +146,53 @@ describe('Feature: strategySubService.ts', () => {
146
146
  });
147
147
  });
148
148
  });
149
+ describe('leverageManagementWithoutSubProxy()', () => {
150
+ const examples = [
151
+ // Repay scenario (isBoost=false, RatioState.UNDER)
152
+ [
153
+ [
154
+ enums_1.Bundles.MainnetIds.MAKER_REPAY,
155
+ true,
156
+ ['0x00000000000000000000000000000000000000000000000000000000000000de000000000000000000000000000000000000000000000000136dcc951d8c00000000000000000000000000000000000000000000000000000000000000000001'],
157
+ [
158
+ '0x00000000000000000000000000000000000000000000000000000000000000de', '0x00000000000000000000000000000000000000000000000018fae27693b40000',
159
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
160
+ ],
161
+ ],
162
+ [
163
+ 222,
164
+ 140,
165
+ 180,
166
+ enums_1.RatioState.UNDER,
167
+ false, // isBoost
168
+ ]
169
+ ],
170
+ // Boost scenario (isBoost=true, RatioState.OVER)
171
+ [
172
+ [
173
+ enums_1.Bundles.MainnetIds.MAKER_BOOST,
174
+ true,
175
+ ['0x000000000000000000000000000000000000000000000000000000000000014d00000000000000000000000000000000000000000000000026db992a3b1800000000000000000000000000000000000000000000000000000000000000000000'],
176
+ [
177
+ '0x000000000000000000000000000000000000000000000000000000000000014d', '0x00000000000000000000000000000000000000000000000022b1c8c1227a0000',
178
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
179
+ ],
180
+ ],
181
+ [
182
+ 333,
183
+ 280,
184
+ 250,
185
+ enums_1.RatioState.OVER,
186
+ true, // isBoost
187
+ ]
188
+ ],
189
+ ];
190
+ examples.forEach(([expected, actual]) => {
191
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
192
+ (0, chai_1.expect)(strategySubService_1.makerEncode.leverageManagementWithoutSubProxy(...actual)).to.eql(expected);
193
+ });
194
+ });
195
+ });
149
196
  });
150
197
  describe('When testing strategySubService.liquityEncode', () => {
151
198
  describe('closeOnPrice()', () => {
@@ -494,238 +541,699 @@ describe('Feature: strategySubService.ts', () => {
494
541
  });
495
542
  });
496
543
  });
497
- });
498
- describe('When testing strategySubService.compoundV2Encode', () => {
499
- describe('leverageManagement()', () => {
500
- const examples = [
501
- [
502
- [new decimal_js_1.default(160).mul(1e16).toString(), new decimal_js_1.default(220).mul(1e16).toString(), new decimal_js_1.default(180).mul(1e16).toString(), new decimal_js_1.default(190).mul(1e16).toString(), true],
503
- [160, 220, 180, 190, true]
504
- ],
505
- [
506
- [new decimal_js_1.default(160).mul(1e16).toString(), new decimal_js_1.default(200).mul(1e16).toString(), new decimal_js_1.default(180).mul(1e16).toString(), new decimal_js_1.default(190).mul(1e16).toString(), false],
507
- [160, 200, 180, 190, false]
508
- ],
509
- ];
510
- examples.forEach(([expected, actual]) => {
511
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
512
- (0, chai_1.expect)(strategySubService_1.compoundV2Encode.leverageManagement(...actual)).to.eql(expected);
513
- });
514
- });
515
- });
516
- });
517
- describe('When testing strategySubService.compoundV3Encode', () => {
518
- describe('leverageManagement()', () => {
544
+ describe('leverageManagementOnPriceGeneric()', () => {
519
545
  const examples = [
520
546
  [
521
547
  [
522
- web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
523
- web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
524
- new decimal_js_1.default(160).mul(1e16).toString(),
525
- new decimal_js_1.default(220).mul(1e16).toString(),
526
- new decimal_js_1.default(180).mul(1e16).toString(),
527
- new decimal_js_1.default(190).mul(1e16).toString(),
528
- true, false,
548
+ enums_1.Bundles.MainnetIds.AAVE_V3_EOA_REPAY_ON_PRICE,
549
+ true,
550
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000026e1f9c6000000000000000000000000000000000000000000000000000000000000000001'],
551
+ [
552
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
553
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
554
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
555
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
556
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
557
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
558
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
559
+ ],
529
560
  ],
530
561
  [
531
- web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
562
+ enums_1.Bundles.MainnetIds.AAVE_V3_EOA_REPAY_ON_PRICE,
563
+ 1670,
564
+ enums_1.RatioState.UNDER,
565
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
566
+ 0,
532
567
  web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
533
- 160, 220, 180, 190,
534
- true, false,
568
+ 1,
569
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
570
+ 200,
571
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
535
572
  ]
536
573
  ],
537
574
  [
538
575
  [
539
- web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
540
- web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
541
- new decimal_js_1.default(160).mul(1e16).toString(),
542
- new decimal_js_1.default(210).mul(1e16).toString(),
543
- new decimal_js_1.default(180).mul(1e16).toString(),
544
- new decimal_js_1.default(190).mul(1e16).toString(),
545
- false, true,
576
+ enums_1.Bundles.MainnetIds.AAVE_V3_EOA_BOOST_ON_PRICE,
577
+ true,
578
+ ['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000002faf0800000000000000000000000000000000000000000000000000000000000000000'],
579
+ [
580
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
581
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
582
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
583
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
584
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
585
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
586
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
587
+ ],
546
588
  ],
547
589
  [
548
- web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
549
- web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
550
- 160, 210, 180, 190,
551
- false, true,
590
+ enums_1.Bundles.MainnetIds.AAVE_V3_EOA_BOOST_ON_PRICE,
591
+ 0.5,
592
+ enums_1.RatioState.OVER,
593
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address),
594
+ 2,
595
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
596
+ 1,
597
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
598
+ 200,
599
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
552
600
  ]
553
601
  ],
554
602
  ];
555
603
  examples.forEach(([expected, actual]) => {
556
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
557
- (0, chai_1.expect)(strategySubService_1.compoundV3Encode.leverageManagement(...actual)).to.eql(expected);
558
- });
559
- });
560
- });
561
- });
562
- describe('When testing strategySubService.morphoAaveV2Encode', () => {
563
- describe('leverageManagement()', () => {
564
- const examples = [
565
- [
566
- [new decimal_js_1.default(160).mul(1e16).toString(), new decimal_js_1.default(220).mul(1e16).toString(), new decimal_js_1.default(180).mul(1e16).toString(), new decimal_js_1.default(190).mul(1e16).toString(), true],
567
- [160, 220, 180, 190, true]
568
- ],
569
- [
570
- [new decimal_js_1.default(160).mul(1e16).toString(), new decimal_js_1.default(200).mul(1e16).toString(), new decimal_js_1.default(180).mul(1e16).toString(), new decimal_js_1.default(190).mul(1e16).toString(), false],
571
- [160, 200, 180, 190, false]
572
- ],
573
- ];
574
- examples.forEach(([expected, actual]) => {
575
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
576
- (0, chai_1.expect)(strategySubService_1.morphoAaveV2Encode.leverageManagement(...actual)).to.eql(expected);
604
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
605
+ (0, chai_1.expect)(strategySubService_1.aaveV3Encode.leverageManagementOnPriceGeneric(...actual)).to.eql(expected);
577
606
  });
578
607
  });
579
608
  });
580
- });
581
- describe('When testing strategySubService.exchangeEncode', () => {
582
- describe('dca()', () => {
609
+ describe('closeOnPriceGeneric()', () => {
583
610
  const examples = [
611
+ // Stop loss only (to debt)
584
612
  [
585
613
  [
586
- enums_1.Strategies.ArbitrumIds.EXCHANGE_DCA,
587
- false,
588
- ['0x0000000000000000000000000000000000000000000000000000018b23bd88cd000000000000000000000000000000000000000000000000000000000012d068'],
614
+ enums_1.Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
615
+ true,
616
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000000000000000'],
589
617
  [
590
- '0x000000000000000000000000da10009cbd5d07dd0cecc66161fc93d7c9000da1', '0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831',
591
- '0x0000000000000000000000000000000000000000000000000000000000038270', '0x000000000000000000000000000000000000000000000000000000000012d068'
618
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
619
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
620
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
621
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
622
+ '0x0000000000000000000000000000000000000000000000000000000000000003',
623
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
624
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
592
625
  ],
593
626
  ],
594
- [(0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Arbitrum).address, (0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Arbitrum).address, '230000', 1697111705805, 1233000, enums_1.ChainId.Arbitrum]
627
+ [
628
+ enums_1.Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
629
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
630
+ 0,
631
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
632
+ 1,
633
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
634
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
635
+ 1500,
636
+ enums_1.CloseToAssetType.DEBT,
637
+ 0,
638
+ enums_1.CloseToAssetType.COLLATERAL, // takeProfitType (not used since price is 0)
639
+ ]
595
640
  ],
641
+ // Take profit only (to collateral)
596
642
  [
597
643
  [
598
- enums_1.Strategies.MainnetIds.EXCHANGE_DCA,
599
- false,
600
- ['0x0000000000000000000000000000000000000000000000000000018b23bd88cd0000000000000000000000000000000000000000000000000000000000067458'],
644
+ enums_1.Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
645
+ true,
646
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
601
647
  [
602
- '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599', '0x000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
603
- '0x0000000000000000000000000000000000000000000000000000000000000015', '0x0000000000000000000000000000000000000000000000000000000000067458',
648
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
649
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
650
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
651
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
652
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
653
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
654
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
604
655
  ],
605
656
  ],
606
- [(0, tokens_1.getAssetInfo)('WBTC').address, (0, tokens_1.getAssetInfo)('ETH').address, '21', 1697111705805, 423000, enums_1.ChainId.Ethereum]
607
- ],
608
- ];
609
- examples.forEach(([expected, actual]) => {
610
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
611
- (0, chai_1.expect)(strategySubService_1.exchangeEncode.dca(...actual)).to.eql(expected);
612
- });
613
- });
614
- });
615
- describe('limitOrder()', () => {
616
- const examples = [
617
- [
618
- [
619
- web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
620
- web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
621
- '2131',
622
- '0.53123',
623
- '1696590921159',
624
- `${enums_1.OrderType.STOP_LOSS}`
625
- ],
626
657
  [
658
+ enums_1.Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
627
659
  web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
628
- web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
629
- '2131',
630
- '0.53123',
631
- 1696590921159,
632
- enums_1.OrderType.STOP_LOSS
660
+ 0,
661
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
662
+ 1,
663
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
664
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
665
+ 0,
666
+ enums_1.CloseToAssetType.DEBT,
667
+ 5000,
668
+ enums_1.CloseToAssetType.COLLATERAL, // takeProfitType
633
669
  ]
634
670
  ],
671
+ // Both stop loss and take profit with useOnBehalf
635
672
  [
636
673
  [
637
- web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('LINK', enums_1.ChainId.Arbitrum).address),
638
- web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Arbitrum).address),
639
- '2131',
640
- '0.43123',
641
- '1646590921159',
642
- `${enums_1.OrderType.TAKE_PROFIT}`
674
+ enums_1.Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
675
+ true,
676
+ ['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
677
+ [
678
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
679
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
680
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
681
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
682
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
683
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
684
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
685
+ ],
643
686
  ],
644
687
  [
645
- web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('LINK', enums_1.ChainId.Arbitrum).address),
646
- web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Arbitrum).address),
647
- '2131',
648
- '0.43123',
649
- 1646590921159,
650
- enums_1.OrderType.TAKE_PROFIT
688
+ enums_1.Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
689
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address),
690
+ 2,
691
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
692
+ 1,
693
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
694
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
695
+ 1500,
696
+ enums_1.CloseToAssetType.COLLATERAL,
697
+ 4000,
698
+ enums_1.CloseToAssetType.COLLATERAL, // takeProfitType
651
699
  ]
652
700
  ],
653
- ];
654
- examples.forEach(([expected, actual]) => {
655
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
656
- (0, chai_1.expect)(strategySubService_1.exchangeEncode.limitOrder(...actual)).to.eql(expected);
657
- });
658
- });
659
- });
660
- });
661
- describe('When testing strategySubService.sparkEncode', () => {
662
- describe('leverageManagement()', () => {
663
- const examples = [
664
- [
665
- '0x000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e000001',
666
- [160, 220, 180, 190, true]
667
- ],
668
- [
669
- '0x000000000000000016345785d8a0000000000000000000001bc16d674ec80000000000000000000018fae27693b4000000000000000000001a5e27eef13e000000',
670
- [160, 200, 180, 190, false]
671
- ],
672
- ];
673
- examples.forEach(([expected, actual]) => {
674
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
675
- (0, chai_1.expect)(strategySubService_1.sparkEncode.leverageManagement(...actual)).to.eql(expected);
676
- });
677
- });
678
- });
679
- describe('closeToAsset()', () => {
680
- const examples = [
701
+ // Stop loss only (to collateral) - CloseStrategyType.STOP_LOSS_IN_COLLATERAL
681
702
  [
682
703
  [
683
- enums_1.Bundles.MainnetIds.SPARK_CLOSE_TO_COLLATERAL,
704
+ enums_1.Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
684
705
  true,
685
- ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000026e1f9c6000000000000000000000000000000000000000000000000000000000000000000'],
706
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000000000000000'],
686
707
  [
687
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000015',
688
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000020',
708
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
709
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
710
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
711
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
712
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
713
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
689
714
  '0x0000000000000000000000000000000000000000000000000000000000000000',
690
715
  ],
691
716
  ],
692
717
  [
693
- enums_1.Bundles.MainnetIds.SPARK_CLOSE_TO_COLLATERAL,
694
- true,
695
- {
696
- baseTokenAddress: (0, tokens_1.getAssetInfo)('WETH').address, quoteTokenAddress: (0, tokens_1.getAssetInfo)('DAI').address, price: 1670, ratioState: enums_1.RatioState.OVER
697
- },
698
- {
699
- collAsset: (0, tokens_1.getAssetInfo)('WETH').address, collAssetId: 21, debtAsset: (0, tokens_1.getAssetInfo)('DAI').address, debtAssetId: 32,
700
- },
718
+ enums_1.Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
719
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
720
+ 0,
721
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
722
+ 1,
723
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
724
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
725
+ 1500,
726
+ enums_1.CloseToAssetType.COLLATERAL,
727
+ 0,
728
+ enums_1.CloseToAssetType.DEBT, // takeProfitType (not used since price is 0)
701
729
  ]
702
730
  ],
731
+ // Take profit only (to debt) - CloseStrategyType.TAKE_PROFIT_IN_DEBT
703
732
  [
704
733
  [
705
- enums_1.Bundles.MainnetIds.SPARK_CLOSE_TO_DEBT,
734
+ enums_1.Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
706
735
  true,
707
- ['0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000000084d000000000000000000000000000000000000000000000000000000000000000001'],
736
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
708
737
  [
709
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000015',
710
- '0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca', '0x0000000000000000000000000000000000000000000000000000000000000020',
738
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
739
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
740
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
741
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
742
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
743
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
711
744
  '0x0000000000000000000000000000000000000000000000000000000000000000',
712
745
  ],
713
746
  ],
714
747
  [
715
- enums_1.Bundles.MainnetIds.SPARK_CLOSE_TO_DEBT,
716
- true,
717
- {
718
- baseTokenAddress: (0, tokens_1.getAssetInfo)('LINK').address, quoteTokenAddress: (0, tokens_1.getAssetInfo)('DAI').address, price: 0.00544, ratioState: enums_1.RatioState.UNDER
719
- },
720
- {
721
- collAsset: (0, tokens_1.getAssetInfo)('DAI').address, collAssetId: 21, debtAsset: (0, tokens_1.getAssetInfo)('LINK').address, debtAssetId: 32,
722
- },
748
+ enums_1.Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
749
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
750
+ 0,
751
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
752
+ 1,
753
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
754
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
755
+ 0,
756
+ enums_1.CloseToAssetType.COLLATERAL,
757
+ 5000,
758
+ enums_1.CloseToAssetType.DEBT, // takeProfitType
759
+ ]
760
+ ],
761
+ // Take profit in collateral and stop loss in debt - CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT
762
+ [
763
+ [
764
+ enums_1.Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
765
+ true,
766
+ ['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
767
+ [
768
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
769
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
770
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
771
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
772
+ '0x0000000000000000000000000000000000000000000000000000000000000005',
773
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
774
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
775
+ ],
776
+ ],
777
+ [
778
+ enums_1.Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
779
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address),
780
+ 2,
781
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
782
+ 1,
783
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
784
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
785
+ 1500,
786
+ enums_1.CloseToAssetType.DEBT,
787
+ 4000,
788
+ enums_1.CloseToAssetType.COLLATERAL, // takeProfitType
789
+ ]
790
+ ],
791
+ // Both stop loss and take profit in debt - CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT
792
+ [
793
+ [
794
+ enums_1.Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
795
+ true,
796
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
797
+ [
798
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
799
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
800
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
801
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
802
+ '0x0000000000000000000000000000000000000000000000000000000000000006',
803
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
804
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
805
+ ],
806
+ ],
807
+ [
808
+ enums_1.Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
809
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
810
+ 0,
811
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
812
+ 1,
813
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
814
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
815
+ 1500,
816
+ enums_1.CloseToAssetType.DEBT,
817
+ 4000,
818
+ enums_1.CloseToAssetType.DEBT, // takeProfitType
819
+ ]
820
+ ],
821
+ // Take profit in debt and stop loss in collateral - CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL
822
+ [
823
+ [
824
+ enums_1.Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
825
+ true,
826
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
827
+ [
828
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
829
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
830
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
831
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
832
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
833
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
834
+ '0x0000000000000000000000009876543210987654321098765432109876543210',
835
+ ],
836
+ ],
837
+ [
838
+ enums_1.Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
839
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
840
+ 0,
841
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
842
+ 1,
843
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
844
+ web3Utils.toChecksumAddress('0x9876543210987654321098765432109876543210'),
845
+ 1500,
846
+ enums_1.CloseToAssetType.COLLATERAL,
847
+ 4000,
848
+ enums_1.CloseToAssetType.DEBT, // takeProfitType
849
+ ]
850
+ ],
851
+ ];
852
+ examples.forEach(([expected, actual]) => {
853
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
854
+ (0, chai_1.expect)(strategySubService_1.aaveV3Encode.closeOnPriceGeneric(...actual)).to.eql(expected);
855
+ });
856
+ });
857
+ });
858
+ describe('collateralSwitch()', () => {
859
+ const examples = [
860
+ // WETH -> USDC, price 100000, state UNDER
861
+ [
862
+ [
863
+ enums_1.Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
864
+ false,
865
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000000000000000000000000000000009184e72a0000000000000000000000000000000000000000000000000000000000000000001'],
866
+ [
867
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
868
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
869
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
870
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
871
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
872
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
873
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
874
+ ],
875
+ ],
876
+ [
877
+ enums_1.Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
878
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
879
+ 0,
880
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
881
+ 1,
882
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
883
+ '10000000000000000000',
884
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
885
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
886
+ 100000,
887
+ enums_1.RatioState.UNDER,
888
+ ]
889
+ ],
890
+ // USDC -> WETH, price 0.00001, state OVER
891
+ [
892
+ [
893
+ enums_1.Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
894
+ false,
895
+ ['0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000003e80000000000000000000000000000000000000000000000000000000000000000'],
896
+ [
897
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
898
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
899
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
900
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
901
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
902
+ '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
903
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
904
+ ],
905
+ ],
906
+ [
907
+ enums_1.Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
908
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
909
+ 1,
910
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
911
+ 0,
912
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
913
+ tokens_1.MAXUINT,
914
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
915
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
916
+ 0.00001,
917
+ enums_1.RatioState.OVER,
918
+ ]
919
+ ],
920
+ // WETH -> WBTC, price 1, state UNDER
921
+ [
922
+ [
923
+ enums_1.Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
924
+ false,
925
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000005f5e1000000000000000000000000000000000000000000000000000000000000000001'],
926
+ [
927
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
928
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
929
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
930
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
931
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
932
+ '0x0000000000000000000000000000000000000000000000004563918244f40000',
933
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
934
+ ],
935
+ ],
936
+ [
937
+ enums_1.Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
938
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
939
+ 0,
940
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address),
941
+ 2,
942
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
943
+ '5000000000000000000',
944
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
945
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address),
946
+ 1,
947
+ enums_1.RatioState.UNDER,
948
+ ]
949
+ ],
950
+ ];
951
+ examples.forEach(([expected, actual]) => {
952
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
953
+ (0, chai_1.expect)(strategySubService_1.aaveV3Encode.collateralSwitch(...actual)).to.eql(expected);
954
+ });
955
+ });
956
+ });
957
+ });
958
+ describe('When testing strategySubService.compoundV2Encode', () => {
959
+ describe('leverageManagement()', () => {
960
+ const examples = [
961
+ [
962
+ [new decimal_js_1.default(160).mul(1e16).toString(), new decimal_js_1.default(220).mul(1e16).toString(), new decimal_js_1.default(180).mul(1e16).toString(), new decimal_js_1.default(190).mul(1e16).toString(), true],
963
+ [160, 220, 180, 190, true]
964
+ ],
965
+ [
966
+ [new decimal_js_1.default(160).mul(1e16).toString(), new decimal_js_1.default(200).mul(1e16).toString(), new decimal_js_1.default(180).mul(1e16).toString(), new decimal_js_1.default(190).mul(1e16).toString(), false],
967
+ [160, 200, 180, 190, false]
968
+ ],
969
+ ];
970
+ examples.forEach(([expected, actual]) => {
971
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
972
+ (0, chai_1.expect)(strategySubService_1.compoundV2Encode.leverageManagement(...actual)).to.eql(expected);
973
+ });
974
+ });
975
+ });
976
+ });
977
+ describe('When testing strategySubService.compoundV3Encode', () => {
978
+ describe('leverageManagement()', () => {
979
+ const examples = [
980
+ [
981
+ [
982
+ web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
983
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
984
+ new decimal_js_1.default(160).mul(1e16).toString(),
985
+ new decimal_js_1.default(220).mul(1e16).toString(),
986
+ new decimal_js_1.default(180).mul(1e16).toString(),
987
+ new decimal_js_1.default(190).mul(1e16).toString(),
988
+ true, false,
989
+ ],
990
+ [
991
+ web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
992
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
993
+ 160, 220, 180, 190,
994
+ true, false,
995
+ ]
996
+ ],
997
+ [
998
+ [
999
+ web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
1000
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1001
+ new decimal_js_1.default(160).mul(1e16).toString(),
1002
+ new decimal_js_1.default(210).mul(1e16).toString(),
1003
+ new decimal_js_1.default(180).mul(1e16).toString(),
1004
+ new decimal_js_1.default(190).mul(1e16).toString(),
1005
+ false, true,
1006
+ ],
1007
+ [
1008
+ web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
1009
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1010
+ 160, 210, 180, 190,
1011
+ false, true,
1012
+ ]
1013
+ ],
1014
+ ];
1015
+ examples.forEach(([expected, actual]) => {
1016
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1017
+ (0, chai_1.expect)(strategySubService_1.compoundV3Encode.leverageManagement(...actual)).to.eql(expected);
1018
+ });
1019
+ });
1020
+ });
1021
+ describe('leverageManagementOnPrice()', () => {
1022
+ const examples = [
1023
+ [
1024
+ [
1025
+ enums_1.Bundles.MainnetIds.COMP_V3_SW_REPAY_ON_PRICE,
1026
+ true,
1027
+ ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f07775030000000000000000000000000000000000000000000000000000002e90edd0000000000000000000000000000000000000000000000000000000000000000001'],
1028
+ [
1029
+ '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
1030
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1031
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1032
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1033
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1034
+ '0x0000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f0777503',
1035
+ ],
1036
+ ],
1037
+ [
1038
+ enums_1.Bundles.MainnetIds.COMP_V3_SW_REPAY_ON_PRICE,
1039
+ web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
1040
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1041
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
1042
+ 200,
1043
+ 2000,
1044
+ enums_1.RatioState.UNDER,
1045
+ enums_1.RatioState.UNDER,
1046
+ web3Utils.toChecksumAddress('0x9a959B9ee2847a66A5A3d43Fd1Ec38a4f0777503'),
1047
+ ],
1048
+ ],
1049
+ [
1050
+ [
1051
+ enums_1.Bundles.MainnetIds.COMP_V3_SW_BOOST_ON_PRICE,
1052
+ true,
1053
+ ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f077750300000000000000000000000000000000000000000000000000000045d964b8000000000000000000000000000000000000000000000000000000000000000000'],
1054
+ [
1055
+ '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
1056
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1057
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1058
+ '0x0000000000000000000000000000000000000000000000001a5e27eef13e0000',
1059
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1060
+ '0x0000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f0777503',
1061
+ ],
1062
+ ],
1063
+ [
1064
+ enums_1.Bundles.MainnetIds.COMP_V3_SW_BOOST_ON_PRICE,
1065
+ web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
1066
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1067
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
1068
+ 190,
1069
+ 3000,
1070
+ enums_1.RatioState.OVER,
1071
+ enums_1.RatioState.OVER,
1072
+ web3Utils.toChecksumAddress('0x9a959B9ee2847a66A5A3d43Fd1Ec38a4f0777503'),
1073
+ ],
1074
+ ]
1075
+ ];
1076
+ examples.forEach(([expected, actual]) => {
1077
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1078
+ (0, chai_1.expect)(strategySubService_1.compoundV3Encode.leverageManagementOnPrice(...actual)).to.eql(expected);
1079
+ });
1080
+ });
1081
+ });
1082
+ describe('closeOnPrice()', () => {
1083
+ const examples = [
1084
+ [
1085
+ [
1086
+ enums_1.Bundles.MainnetIds.COMP_V3_SW_CLOSE,
1087
+ true,
1088
+ ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
1089
+ [
1090
+ '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
1091
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1092
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1093
+ '0x0000000000000000000000000000000000000000000000000000000000000006',
1094
+ '0x0000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f0777503',
1095
+ ],
1096
+ ],
1097
+ [
1098
+ enums_1.Bundles.MainnetIds.COMP_V3_SW_CLOSE,
1099
+ web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
1100
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1101
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
1102
+ 1500,
1103
+ enums_1.CloseToAssetType.DEBT,
1104
+ 4000,
1105
+ enums_1.CloseToAssetType.DEBT,
1106
+ web3Utils.toChecksumAddress('0x9a959B9ee2847a66A5A3d43Fd1Ec38a4f0777503'),
1107
+ ],
1108
+ ],
1109
+ [
1110
+ [
1111
+ enums_1.Bundles.MainnetIds.COMP_V3_EOA_CLOSE,
1112
+ true,
1113
+ ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
1114
+ [
1115
+ '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
1116
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1117
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1118
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1119
+ '0x0000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f0777503',
1120
+ ],
1121
+ ],
1122
+ [
1123
+ enums_1.Bundles.MainnetIds.COMP_V3_EOA_CLOSE,
1124
+ web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
1125
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1126
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
1127
+ 0,
1128
+ enums_1.CloseToAssetType.DEBT,
1129
+ 5000,
1130
+ enums_1.CloseToAssetType.COLLATERAL,
1131
+ web3Utils.toChecksumAddress('0x9a959B9ee2847a66A5A3d43Fd1Ec38a4f0777503'),
1132
+ ],
1133
+ ]
1134
+ ];
1135
+ examples.forEach(([expected, actual]) => {
1136
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1137
+ (0, chai_1.expect)(strategySubService_1.compoundV3Encode.closeOnPrice(...actual)).to.eql(expected);
1138
+ });
1139
+ });
1140
+ });
1141
+ });
1142
+ describe('When testing strategySubService.morphoAaveV2Encode', () => {
1143
+ describe('leverageManagement()', () => {
1144
+ const examples = [
1145
+ [
1146
+ [new decimal_js_1.default(160).mul(1e16).toString(), new decimal_js_1.default(220).mul(1e16).toString(), new decimal_js_1.default(180).mul(1e16).toString(), new decimal_js_1.default(190).mul(1e16).toString(), true],
1147
+ [160, 220, 180, 190, true]
1148
+ ],
1149
+ [
1150
+ [new decimal_js_1.default(160).mul(1e16).toString(), new decimal_js_1.default(200).mul(1e16).toString(), new decimal_js_1.default(180).mul(1e16).toString(), new decimal_js_1.default(190).mul(1e16).toString(), false],
1151
+ [160, 200, 180, 190, false]
1152
+ ],
1153
+ ];
1154
+ examples.forEach(([expected, actual]) => {
1155
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1156
+ (0, chai_1.expect)(strategySubService_1.morphoAaveV2Encode.leverageManagement(...actual)).to.eql(expected);
1157
+ });
1158
+ });
1159
+ });
1160
+ });
1161
+ describe('When testing strategySubService.exchangeEncode', () => {
1162
+ describe('dca()', () => {
1163
+ const examples = [
1164
+ [
1165
+ [
1166
+ enums_1.Strategies.ArbitrumIds.EXCHANGE_DCA,
1167
+ false,
1168
+ ['0x0000000000000000000000000000000000000000000000000000018b23bd88cd000000000000000000000000000000000000000000000000000000000012d068'],
1169
+ [
1170
+ '0x000000000000000000000000da10009cbd5d07dd0cecc66161fc93d7c9000da1', '0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831',
1171
+ '0x0000000000000000000000000000000000000000000000000000000000038270', '0x000000000000000000000000000000000000000000000000000000000012d068'
1172
+ ],
1173
+ ],
1174
+ [(0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Arbitrum).address, (0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Arbitrum).address, '230000', 1697111705805, 1233000, enums_1.ChainId.Arbitrum]
1175
+ ],
1176
+ [
1177
+ [
1178
+ enums_1.Strategies.MainnetIds.EXCHANGE_DCA,
1179
+ false,
1180
+ ['0x0000000000000000000000000000000000000000000000000000018b23bd88cd0000000000000000000000000000000000000000000000000000000000067458'],
1181
+ [
1182
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599', '0x000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
1183
+ '0x0000000000000000000000000000000000000000000000000000000000000015', '0x0000000000000000000000000000000000000000000000000000000000067458',
1184
+ ],
1185
+ ],
1186
+ [(0, tokens_1.getAssetInfo)('WBTC').address, (0, tokens_1.getAssetInfo)('ETH').address, '21', 1697111705805, 423000, enums_1.ChainId.Ethereum]
1187
+ ],
1188
+ ];
1189
+ examples.forEach(([expected, actual]) => {
1190
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1191
+ (0, chai_1.expect)(strategySubService_1.exchangeEncode.dca(...actual)).to.eql(expected);
1192
+ });
1193
+ });
1194
+ });
1195
+ describe('limitOrder()', () => {
1196
+ const examples = [
1197
+ [
1198
+ [
1199
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1200
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
1201
+ '2131',
1202
+ '0.53123',
1203
+ '1696590921159',
1204
+ `${enums_1.OrderType.STOP_LOSS}`
1205
+ ],
1206
+ [
1207
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1208
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
1209
+ '2131',
1210
+ '0.53123',
1211
+ 1696590921159,
1212
+ enums_1.OrderType.STOP_LOSS
723
1213
  ]
724
- ]
1214
+ ],
1215
+ [
1216
+ [
1217
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('LINK', enums_1.ChainId.Arbitrum).address),
1218
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Arbitrum).address),
1219
+ '2131',
1220
+ '0.43123',
1221
+ '1646590921159',
1222
+ `${enums_1.OrderType.TAKE_PROFIT}`
1223
+ ],
1224
+ [
1225
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('LINK', enums_1.ChainId.Arbitrum).address),
1226
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Arbitrum).address),
1227
+ '2131',
1228
+ '0.43123',
1229
+ 1646590921159,
1230
+ enums_1.OrderType.TAKE_PROFIT
1231
+ ]
1232
+ ],
725
1233
  ];
726
1234
  examples.forEach(([expected, actual]) => {
727
1235
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
728
- (0, chai_1.expect)(strategySubService_1.sparkEncode.closeToAsset(...actual)).to.eql(expected);
1236
+ (0, chai_1.expect)(strategySubService_1.exchangeEncode.limitOrder(...actual)).to.eql(expected);
729
1237
  });
730
1238
  });
731
1239
  });
@@ -903,26 +1411,66 @@ describe('Feature: strategySubService.ts', () => {
903
1411
  });
904
1412
  });
905
1413
  });
1414
+ describe('closeOnPrice()', () => {
1415
+ const examples = [
1416
+ [
1417
+ [
1418
+ enums_1.Bundles.MainnetIds.MORPHO_BLUE_CLOSE,
1419
+ true,
1420
+ ['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
1421
+ [
1422
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1423
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1424
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1425
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1426
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1427
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1428
+ '0x0000000000000000000000000000000000000000000000000000000000000005',
1429
+ ],
1430
+ ],
1431
+ [
1432
+ enums_1.Bundles.MainnetIds.MORPHO_BLUE_CLOSE,
1433
+ web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
1434
+ web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
1435
+ web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
1436
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1437
+ '945000000000000000',
1438
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1439
+ 1500,
1440
+ enums_1.CloseToAssetType.DEBT,
1441
+ 4000,
1442
+ enums_1.CloseToAssetType.COLLATERAL
1443
+ ]
1444
+ ],
1445
+ ];
1446
+ examples.forEach(([expected, actual]) => {
1447
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1448
+ (0, chai_1.expect)(strategySubService_1.morphoBlueEncode.closeOnPrice(...actual)).to.eql(expected);
1449
+ });
1450
+ });
1451
+ });
906
1452
  });
907
1453
  describe('When testing strategySubService.compoundV3L2Encode', () => {
908
1454
  describe('leverageManagement()', () => {
909
1455
  const examples = [
910
1456
  [
911
- '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0213D212133AfaB8F2b829B1066C7E43cAD94E2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e000001',
1457
+ '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0213D212133AfaB8F2b829B1066C7E43cAD94E2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e00000100',
912
1458
  [
913
1459
  web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'),
914
1460
  web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'),
915
1461
  160, 220, 180, 190,
916
- true
1462
+ true,
1463
+ false,
917
1464
  ],
918
1465
  ],
919
1466
  [
920
- '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0413d212133afAb8F2B829b1066C7e43cAd94e2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000000f43fc2c04ee000000',
1467
+ '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0413d212133afAb8F2B829b1066C7e43cAd94e2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000000f43fc2c04ee00000000',
921
1468
  [
922
1469
  web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'),
923
1470
  web3Utils.toChecksumAddress('0x0413d212133AFaB8F2B829B1066c7E43cAd94E2c'),
924
1471
  160, 220, 180, 110,
925
- false
1472
+ false,
1473
+ false,
926
1474
  ],
927
1475
  ],
928
1476
  ];
@@ -933,4 +1481,332 @@ describe('Feature: strategySubService.ts', () => {
933
1481
  });
934
1482
  });
935
1483
  });
1484
+ describe('When testing strategySubService.sparkEncode', () => {
1485
+ describe('leverageManagement()', () => {
1486
+ const examples = [
1487
+ [
1488
+ '0x0000000000000000136dcc951d8c00000000000000000000214e8348c4f0000000000000000000001d24b2dfac52000000000000000000001a5e27eef13e000001',
1489
+ [140, 240, 210, 190, true]
1490
+ ],
1491
+ [
1492
+ '0x0000000000000000130337bdce49000000000000000000001988fe4052b800000000000000000000281b57b028e1000000000000000000002223acf76376000000',
1493
+ [137, 184, 289, 246, false]
1494
+ ]
1495
+ ];
1496
+ examples.forEach(([expected, actual]) => {
1497
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1498
+ (0, chai_1.expect)(strategySubService_1.sparkEncode.leverageManagement(...actual)).to.eql(expected);
1499
+ });
1500
+ });
1501
+ });
1502
+ describe('leverageManagementOnPrice()', () => {
1503
+ const examples = [
1504
+ [
1505
+ [
1506
+ enums_1.Bundles.MainnetIds.SPARK_REPAY_ON_PRICE,
1507
+ true,
1508
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
1509
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1510
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1511
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1512
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1513
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1514
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1515
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1516
+ ],
1517
+ ],
1518
+ [
1519
+ 59,
1520
+ true,
1521
+ {
1522
+ baseTokenAddr: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1523
+ quoteTokenAddr: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
1524
+ price: 2500,
1525
+ ratioState: enums_1.RatioState.UNDER,
1526
+ },
1527
+ {
1528
+ collAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1529
+ collAssetId: 0,
1530
+ debtAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
1531
+ debtAssetId: 1,
1532
+ marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1533
+ targetRatio: 200,
1534
+ },
1535
+ ]
1536
+ ],
1537
+ [
1538
+ [
1539
+ enums_1.Bundles.MainnetIds.SPARK_BOOST_ON_PRICE,
1540
+ true,
1541
+ ['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000417bce6c8000000000000000000000000000000000000000000000000000000000000000000'],
1542
+ [
1543
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
1544
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1545
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
1546
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
1547
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1548
+ '0x00000000000000000000000000000000000000000000000022b1c8c1227a0000',
1549
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1550
+ ]
1551
+ ],
1552
+ [
1553
+ 60,
1554
+ true,
1555
+ {
1556
+ baseTokenAddr: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address),
1557
+ quoteTokenAddr: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
1558
+ price: 45000,
1559
+ ratioState: enums_1.RatioState.OVER,
1560
+ },
1561
+ {
1562
+ collAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address),
1563
+ collAssetId: 2,
1564
+ debtAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
1565
+ debtAssetId: 4,
1566
+ marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1567
+ targetRatio: 250,
1568
+ },
1569
+ ]
1570
+ ]
1571
+ ];
1572
+ examples.forEach(([expected, actual]) => {
1573
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1574
+ (0, chai_1.expect)(strategySubService_1.sparkEncode.leverageManagementOnPrice(...actual)).to.eql(expected);
1575
+ });
1576
+ });
1577
+ });
1578
+ describe('closeOnPrice()', () => {
1579
+ const examples = [
1580
+ [
1581
+ [
1582
+ enums_1.Bundles.MainnetIds.SPARK_CLOSE,
1583
+ true,
1584
+ ['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000000000000003a35294400000000000000000000000000000000000000000000000000000000574fbde6000'],
1585
+ [
1586
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
1587
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1588
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
1589
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
1590
+ '0x0000000000000000000000000000000000000000000000000000000000000005',
1591
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1592
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
1593
+ ]
1594
+ ],
1595
+ [
1596
+ 57,
1597
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address),
1598
+ 2,
1599
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
1600
+ 4,
1601
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1602
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
1603
+ 40000,
1604
+ enums_1.CloseToAssetType.DEBT,
1605
+ 60000,
1606
+ enums_1.CloseToAssetType.COLLATERAL,
1607
+ ]
1608
+ ],
1609
+ ];
1610
+ examples.forEach(([expected, actual]) => {
1611
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1612
+ (0, chai_1.expect)(strategySubService_1.sparkEncode.closeOnPriceGeneric(...actual)).to.eql(expected);
1613
+ });
1614
+ });
1615
+ });
1616
+ describe('collateralSwitch()', () => {
1617
+ const examples = [
1618
+ // WETH -> cbBTC, price 0.025 WETH/cbBTC, state UNDER
1619
+ [
1620
+ [
1621
+ enums_1.Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1622
+ false,
1623
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf00000000000000000000000000000000000000000000000000000000002625a00000000000000000000000000000000000000000000000000000000000000001'],
1624
+ [
1625
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1626
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1627
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
1628
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
1629
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1630
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
1631
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1632
+ ],
1633
+ ],
1634
+ [
1635
+ enums_1.Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1636
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1637
+ 0,
1638
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('cbBTC', enums_1.ChainId.Ethereum).address),
1639
+ 7,
1640
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1641
+ '10000000000000000000',
1642
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1643
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('cbBTC', enums_1.ChainId.Ethereum).address),
1644
+ 0.025,
1645
+ enums_1.RatioState.UNDER,
1646
+ ]
1647
+ ],
1648
+ // cbBTC -> WETH, price 25 cbBTC/WETH, state UNDER
1649
+ [
1650
+ [
1651
+ enums_1.Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1652
+ false,
1653
+ ['0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000009502f9000000000000000000000000000000000000000000000000000000000000000001'],
1654
+ [
1655
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
1656
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
1657
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1658
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1659
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1660
+ '0x0000000000000000000000000000000000000000000000000000000005f5e100',
1661
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1662
+ ],
1663
+ ],
1664
+ [
1665
+ enums_1.Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1666
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('cbBTC', enums_1.ChainId.Ethereum).address),
1667
+ 7,
1668
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1669
+ 0,
1670
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1671
+ '100000000',
1672
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('cbBTC', enums_1.ChainId.Ethereum).address),
1673
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1674
+ 25,
1675
+ enums_1.RatioState.UNDER,
1676
+ ]
1677
+ ],
1678
+ // cbBTC -> WETH, price 40 cbBTC/WETH, state OVER
1679
+ [
1680
+ [
1681
+ enums_1.Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1682
+ false,
1683
+ ['0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000ee6b28000000000000000000000000000000000000000000000000000000000000000000'],
1684
+ [
1685
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
1686
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
1687
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1688
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1689
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1690
+ '0x0000000000000000000000000000000000000000000000000000000005f5e100',
1691
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1692
+ ],
1693
+ ],
1694
+ [
1695
+ enums_1.Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1696
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('cbBTC', enums_1.ChainId.Ethereum).address),
1697
+ 7,
1698
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1699
+ 0,
1700
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1701
+ '100000000',
1702
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('cbBTC', enums_1.ChainId.Ethereum).address),
1703
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1704
+ 40,
1705
+ enums_1.RatioState.OVER,
1706
+ ]
1707
+ ],
1708
+ ];
1709
+ examples.forEach(([expected, actual]) => {
1710
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1711
+ (0, chai_1.expect)(strategySubService_1.sparkEncode.collateralSwitch(...actual)).to.eql(expected);
1712
+ });
1713
+ });
1714
+ });
1715
+ });
1716
+ describe('When testing strategySubService.aaveV4Encode', () => {
1717
+ describe('leverageManagement()', () => {
1718
+ const examples = [
1719
+ [
1720
+ [1, true, ["0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x00000000000000000000000000000000000000000000000014d1120d7b160000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"]],
1721
+ [
1722
+ 1,
1723
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1724
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
1725
+ enums_1.RatioState.UNDER,
1726
+ 150,
1727
+ 120,
1728
+ ]
1729
+ ]
1730
+ ];
1731
+ examples.forEach(([expected, actual]) => {
1732
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1733
+ (0, chai_1.expect)(strategySubService_1.aaveV4Encode.leverageManagement(...actual)).to.eql(expected);
1734
+ });
1735
+ });
1736
+ });
1737
+ describe('leverageManagementOnPrice()', () => {
1738
+ const examples = [
1739
+ [
1740
+ [2, true, ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000000"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x00000000000000000000000000000000000000000000000016345785d8a00000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"]],
1741
+ [
1742
+ 2,
1743
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1744
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
1745
+ web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1746
+ 10,
1747
+ web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
1748
+ 20,
1749
+ 160,
1750
+ '1500',
1751
+ enums_1.RatioState.OVER,
1752
+ enums_1.RatioState.OVER, // ratioState - UNDER for repay, OVER for boost
1753
+ ]
1754
+ ]
1755
+ ];
1756
+ examples.forEach(([expected, actual]) => {
1757
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1758
+ (0, chai_1.expect)(strategySubService_1.aaveV4Encode.leverageManagementOnPrice(...actual)).to.eql(expected);
1759
+ });
1760
+ });
1761
+ });
1762
+ describe('closeOnPrice()', () => {
1763
+ const examples = [
1764
+ [
1765
+ [3, true, ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000004be4e7267b6ae000000000000000000000000000000000000000000000000000000000000000000000"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000003", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"]],
1766
+ [
1767
+ 3,
1768
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1769
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
1770
+ web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1771
+ 10,
1772
+ web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
1773
+ 20,
1774
+ '1400',
1775
+ enums_1.CloseToAssetType.DEBT,
1776
+ '0',
1777
+ enums_1.CloseToAssetType.COLLATERAL
1778
+ ]
1779
+ ]
1780
+ ];
1781
+ examples.forEach(([expected, actual]) => {
1782
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1783
+ (0, chai_1.expect)(strategySubService_1.aaveV4Encode.closeOnPrice(...actual)).to.eql(expected);
1784
+ });
1785
+ });
1786
+ });
1787
+ describe('collateralSwitch()', () => {
1788
+ const examples = [
1789
+ [
1790
+ [4, false, ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000001"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"]],
1791
+ [
1792
+ 4,
1793
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1794
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
1795
+ web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1796
+ 10,
1797
+ web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
1798
+ 20,
1799
+ '1000000000000000000',
1800
+ '1500',
1801
+ enums_1.RatioState.UNDER,
1802
+ ]
1803
+ ]
1804
+ ];
1805
+ examples.forEach(([expected, actual]) => {
1806
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1807
+ (0, chai_1.expect)(strategySubService_1.aaveV4Encode.collateralSwitch(...actual)).to.eql(expected);
1808
+ });
1809
+ });
1810
+ });
1811
+ });
936
1812
  });