@defisaver/automation-sdk 3.3.17 → 3.3.18-spark-eoa-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 (38) hide show
  1. package/cjs/constants/index.js +170 -0
  2. package/cjs/index.d.ts +2 -2
  3. package/cjs/index.js +5 -2
  4. package/cjs/services/ethereumService.test.js +4 -7
  5. package/cjs/services/strategiesService.js +195 -15
  6. package/cjs/services/strategySubService.d.ts +22 -17
  7. package/cjs/services/strategySubService.js +92 -28
  8. package/cjs/services/strategySubService.test.js +297 -40
  9. package/cjs/services/subDataService.d.ts +108 -20
  10. package/cjs/services/subDataService.js +97 -79
  11. package/cjs/services/subDataService.test.js +479 -174
  12. package/cjs/types/enums.d.ts +44 -6
  13. package/cjs/types/enums.js +38 -0
  14. package/esm/constants/index.js +170 -0
  15. package/esm/index.d.ts +2 -2
  16. package/esm/index.js +5 -2
  17. package/esm/services/ethereumService.test.js +4 -7
  18. package/esm/services/strategiesService.js +195 -15
  19. package/esm/services/strategySubService.d.ts +22 -17
  20. package/esm/services/strategySubService.js +91 -27
  21. package/esm/services/strategySubService.test.js +298 -38
  22. package/esm/services/subDataService.d.ts +108 -20
  23. package/esm/services/subDataService.js +95 -77
  24. package/esm/services/subDataService.test.js +480 -172
  25. package/esm/types/enums.d.ts +44 -6
  26. package/esm/types/enums.js +38 -0
  27. package/package.json +1 -1
  28. package/src/constants/index.ts +172 -1
  29. package/src/index.ts +22 -6
  30. package/src/services/ethereumService.test.ts +5 -8
  31. package/src/services/strategiesService.ts +262 -16
  32. package/src/services/strategySubService.test.ts +384 -46
  33. package/src/services/strategySubService.ts +251 -40
  34. package/src/services/subDataService.test.ts +639 -231
  35. package/src/services/subDataService.ts +149 -106
  36. package/src/services/utils.test.ts +1 -1
  37. package/src/services/utils.ts +3 -1
  38. package/src/types/enums.ts +38 -2
@@ -22,11 +22,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
25
  Object.defineProperty(exports, "__esModule", { value: true });
29
- const decimal_js_1 = __importDefault(require("decimal.js"));
30
26
  const chai_1 = require("chai");
31
27
  const tokens_1 = require("@defisaver/tokens");
32
28
  const web3Utils = __importStar(require("web3-utils"));
@@ -146,7 +142,7 @@ describe('Feature: subDataService.ts', () => {
146
142
  });
147
143
  });
148
144
  });
149
- describe('When testing subDataService.makerLeverageManagementSubData', () => {
145
+ describe('When testing subDataService.legacyMakerLeverageManagementSubData', () => {
150
146
  describe('decode()', () => {
151
147
  const examples = [
152
148
  [
@@ -159,12 +155,12 @@ describe('Feature: subDataService.ts', () => {
159
155
  ];
160
156
  examples.forEach(([expected, actual]) => {
161
157
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
162
- (0, chai_1.expect)(subDataService.makerLeverageManagementSubData.decode(actual)).to.eql(expected);
158
+ (0, chai_1.expect)(subDataService.legacyMakerLeverageManagementSubData.decode(actual)).to.eql(expected);
163
159
  });
164
160
  });
165
161
  });
166
162
  });
167
- describe('When testing subDataService.makerLeverageManagementWithoutSubProxy', () => {
163
+ describe('When testing subDataService.makerLeverageManagementSubData', () => {
168
164
  describe('encode()', () => {
169
165
  const examples = [
170
166
  [
@@ -184,7 +180,7 @@ describe('Feature: subDataService.ts', () => {
184
180
  ];
185
181
  examples.forEach(([expected, actual]) => {
186
182
  it(`Given ${actual} should return expected value: ${expected}`, () => {
187
- (0, chai_1.expect)(subDataService.makerLeverageManagementWithoutSubProxy.encode(...actual)).to.eql(expected);
183
+ (0, chai_1.expect)(subDataService.makerLeverageManagementSubData.encode(...actual)).to.eql(expected);
188
184
  });
189
185
  });
190
186
  });
@@ -215,12 +211,12 @@ describe('Feature: subDataService.ts', () => {
215
211
  ];
216
212
  examples.forEach(([expected, actual]) => {
217
213
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
218
- (0, chai_1.expect)(subDataService.makerLeverageManagementWithoutSubProxy.decode(actual)).to.eql(expected);
214
+ (0, chai_1.expect)(subDataService.makerLeverageManagementSubData.decode(actual)).to.eql(expected);
219
215
  });
220
216
  });
221
217
  });
222
218
  });
223
- describe('When testing subDataService.liquityLeverageManagementSubData', () => {
219
+ describe('When testing subDataService.legacyLiquityLeverageManagementSubData', () => {
224
220
  describe('decode()', () => {
225
221
  const examples = [
226
222
  [
@@ -233,7 +229,7 @@ describe('Feature: subDataService.ts', () => {
233
229
  ];
234
230
  examples.forEach(([expected, actual]) => {
235
231
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
236
- (0, chai_1.expect)(subDataService.liquityLeverageManagementSubData.decode(actual)).to.eql(expected);
232
+ (0, chai_1.expect)(subDataService.legacyLiquityLeverageManagementSubData.decode(actual)).to.eql(expected);
237
233
  });
238
234
  });
239
235
  });
@@ -288,24 +284,7 @@ describe('Feature: subDataService.ts', () => {
288
284
  });
289
285
  });
290
286
  });
291
- describe('When testing subDataService.aaveV2LeverageManagementSubData', () => {
292
- describe('encode()', () => {
293
- const examples = [
294
- [
295
- [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],
296
- [160, 220, 180, 190, true]
297
- ],
298
- [
299
- [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],
300
- [160, 200, 180, 190, false]
301
- ],
302
- ];
303
- examples.forEach(([expected, actual]) => {
304
- it(`Given ${actual} should return expected value: ${expected}`, () => {
305
- (0, chai_1.expect)(subDataService.aaveV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
306
- });
307
- });
308
- });
287
+ describe('When testing subDataService.legacyAaveV2LeverageManagementSubData', () => {
309
288
  describe('decode()', () => {
310
289
  const examples = [
311
290
  [
@@ -319,12 +298,12 @@ describe('Feature: subDataService.ts', () => {
319
298
  ];
320
299
  examples.forEach(([expected, actual]) => {
321
300
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
322
- (0, chai_1.expect)(subDataService.aaveV2LeverageManagementSubData.decode(actual)).to.eql(expected);
301
+ (0, chai_1.expect)(subDataService.legacyAaveV2LeverageManagementSubData.decode(actual)).to.eql(expected);
323
302
  });
324
303
  });
325
304
  });
326
305
  });
327
- describe('When testing subDataService.aaveV3LeverageManagementSubData', () => {
306
+ describe('When testing subDataService.legacyAaveV3LeverageManagementSubData', () => {
328
307
  describe('decode()', () => {
329
308
  const examples = [
330
309
  [
@@ -338,7 +317,7 @@ describe('Feature: subDataService.ts', () => {
338
317
  ];
339
318
  examples.forEach(([expected, actual]) => {
340
319
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
341
- (0, chai_1.expect)(subDataService.aaveV3LeverageManagementSubData.decode(actual)).to.eql(expected);
320
+ (0, chai_1.expect)(subDataService.legacyAaveV3LeverageManagementSubData.decode(actual)).to.eql(expected);
342
321
  });
343
322
  });
344
323
  });
@@ -677,128 +656,112 @@ describe('Feature: subDataService.ts', () => {
677
656
  });
678
657
  });
679
658
  });
680
- describe('When testing subDataService.compoundV2LeverageManagementSubData', () => {
659
+ describe('When testing subDataService.sparkGenericFLCollateralSwitchSubData', () => {
681
660
  describe('encode()', () => {
682
661
  const examples = [
683
662
  [
684
- [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],
685
- [160, 220, 180, 190, true]
686
- ],
687
- [
688
- [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],
689
- [160, 200, 180, 190, false]
663
+ [
664
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
665
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
666
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
667
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
668
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
669
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
670
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
671
+ ],
672
+ [
673
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
674
+ 0,
675
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('cbBTC', enums_1.ChainId.Ethereum).address),
676
+ 7,
677
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
678
+ '10000000000000000000',
679
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
680
+ ],
690
681
  ],
691
682
  ];
692
683
  examples.forEach(([expected, actual]) => {
693
- it(`Given ${actual} should return expected value: ${expected}`, () => {
694
- (0, chai_1.expect)(subDataService.compoundV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
684
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
685
+ (0, chai_1.expect)(subDataService.sparkGenericFLCollateralSwitchSubData.encode(...actual)).to.eql(expected);
695
686
  });
696
687
  });
697
688
  });
698
689
  describe('decode()', () => {
699
690
  const examples = [
700
691
  [
701
- { targetRatio: 200 },
702
- ['0x0000000000000000000000000000000000000000000000001bc16d674ec80000'],
703
- ],
704
- [
705
- { targetRatio: 123 },
706
- ['0x0000000000000000000000000000000000000000000000001111d67bb1bb0000'],
692
+ {
693
+ fromAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
694
+ fromAssetId: 0,
695
+ toAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('cbBTC', enums_1.ChainId.Ethereum).address),
696
+ toAssetId: 7,
697
+ marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
698
+ amountToSwitch: '10000000000000000000',
699
+ user: web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
700
+ },
701
+ [
702
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
703
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
704
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
705
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
706
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
707
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
708
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
709
+ ],
707
710
  ],
708
711
  ];
709
712
  examples.forEach(([expected, actual]) => {
710
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
711
- (0, chai_1.expect)(subDataService.compoundV2LeverageManagementSubData.decode(actual)).to.eql(expected);
713
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
714
+ (0, chai_1.expect)(subDataService.sparkGenericFLCollateralSwitchSubData.decode(actual)).to.eql(expected);
712
715
  });
713
716
  });
714
717
  });
715
718
  });
716
- describe('When testing subDataService.compoundV3LeverageManagementSubData', () => {
719
+ describe('When testing subDataService.compoundV2LeverageManagementSubData', () => {
717
720
  describe('encode()', () => {
718
721
  const examples = [
719
722
  [
720
723
  [
721
- web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
722
- web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
723
- new decimal_js_1.default(160).mul(1e16).toString(),
724
- new decimal_js_1.default(220).mul(1e16).toString(),
725
- new decimal_js_1.default(180).mul(1e16).toString(),
726
- new decimal_js_1.default(190).mul(1e16).toString(),
727
- true, false,
724
+ '0x00000000000000000000000000000000000000000000000018fae27693b40000',
725
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
728
726
  ],
729
- [
730
- web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
731
- web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
732
- 160, 220, 180, 190,
733
- true, false,
734
- ]
727
+ [180, enums_1.RatioState.UNDER],
735
728
  ],
736
729
  [
737
730
  [
738
- web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
739
- web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
740
- new decimal_js_1.default(160).mul(1e16).toString(),
741
- new decimal_js_1.default(210).mul(1e16).toString(),
742
- new decimal_js_1.default(180).mul(1e16).toString(),
743
- new decimal_js_1.default(190).mul(1e16).toString(),
744
- false, true,
731
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
732
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
733
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
745
734
  ],
746
- [
747
- web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
748
- web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
749
- 160, 210, 180, 190,
750
- false, true,
751
- ]
735
+ [160, enums_1.RatioState.OVER],
752
736
  ],
753
737
  ];
754
738
  examples.forEach(([expected, actual]) => {
755
739
  it(`Given ${actual} should return expected value: ${expected}`, () => {
756
- (0, chai_1.expect)(subDataService.compoundV3LeverageManagementSubData.encode(...actual)).to.eql(expected);
740
+ (0, chai_1.expect)(subDataService.compoundV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
757
741
  });
758
742
  });
759
743
  });
744
+ });
745
+ describe('When testing subDataService.legacyCompoundV2LeverageManagementSubData', () => {
760
746
  describe('decode()', () => {
761
747
  const examples = [
762
748
  [
763
- { targetRatio: 123 },
764
- [
765
- '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
766
- '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
767
- ],
749
+ { targetRatio: 200 },
750
+ ['0x0000000000000000000000000000000000000000000000001bc16d674ec80000'],
768
751
  ],
769
752
  [
770
- { targetRatio: 200 },
771
- [
772
- '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
773
- '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
774
- ],
753
+ { targetRatio: 123 },
754
+ ['0x0000000000000000000000000000000000000000000000001111d67bb1bb0000'],
775
755
  ],
776
756
  ];
777
757
  examples.forEach(([expected, actual]) => {
778
758
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
779
- (0, chai_1.expect)(subDataService.compoundV3LeverageManagementSubData.decode(actual)).to.eql(expected);
759
+ (0, chai_1.expect)(subDataService.legacyCompoundV2LeverageManagementSubData.decode(actual)).to.eql(expected);
780
760
  });
781
761
  });
782
762
  });
783
763
  });
784
764
  describe('When testing subDataService.morphoAaveV2LeverageManagementSubData', () => {
785
- describe('encode()', () => {
786
- const examples = [
787
- [
788
- [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],
789
- [160, 220, 180, 190, true]
790
- ],
791
- [
792
- [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],
793
- [160, 200, 180, 190, false]
794
- ],
795
- ];
796
- examples.forEach(([expected, actual]) => {
797
- it(`Given ${actual} should return expected value: ${expected}`, () => {
798
- (0, chai_1.expect)(subDataService.morphoAaveV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
799
- });
800
- });
801
- });
802
765
  describe('decode()', () => {
803
766
  const examples = [
804
767
  [
@@ -818,23 +781,6 @@ describe('Feature: subDataService.ts', () => {
818
781
  });
819
782
  });
820
783
  describe('When testing subDataService.cBondsRebondSubData', () => {
821
- describe('encode()', () => {
822
- const examples = [
823
- [
824
- ['0x00000000000000000000000000000000000000000000000000000000000000c8'],
825
- [200]
826
- ],
827
- [
828
- ['0x000000000000000000000000000000000000000000000000000000000000a119'],
829
- [41241]
830
- ],
831
- ];
832
- examples.forEach(([expected, actual]) => {
833
- it(`Given ${actual} should return expected value: ${expected}`, () => {
834
- (0, chai_1.expect)(subDataService.cBondsRebondSubData.encode(...actual)).to.eql(expected);
835
- });
836
- });
837
- });
838
784
  describe('decode()', () => {
839
785
  const examples = [
840
786
  [
@@ -975,52 +921,7 @@ describe('Feature: subDataService.ts', () => {
975
921
  });
976
922
  });
977
923
  });
978
- describe('When testing subDataService.exchangeLimitOrderSubData', () => {
979
- describe('encode()', () => {
980
- const examples = [
981
- [
982
- [
983
- web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
984
- web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
985
- '2131',
986
- '0.53123',
987
- '1696590921159',
988
- `${enums_1.OrderType.STOP_LOSS}`
989
- ],
990
- [
991
- web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
992
- web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
993
- '2131',
994
- '0.53123',
995
- 1696590921159,
996
- enums_1.OrderType.STOP_LOSS
997
- ]
998
- ],
999
- [
1000
- [
1001
- web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('LINK', enums_1.ChainId.Arbitrum).address),
1002
- web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Arbitrum).address),
1003
- '2131',
1004
- '0.43123',
1005
- '1646590921159',
1006
- `${enums_1.OrderType.TAKE_PROFIT}`
1007
- ],
1008
- [
1009
- web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('LINK', enums_1.ChainId.Arbitrum).address),
1010
- web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Arbitrum).address),
1011
- '2131',
1012
- '0.43123',
1013
- 1646590921159,
1014
- enums_1.OrderType.TAKE_PROFIT
1015
- ]
1016
- ],
1017
- ];
1018
- examples.forEach(([expected, actual]) => {
1019
- it(`Given ${actual} should return expected value: ${expected}`, () => {
1020
- (0, chai_1.expect)(subDataService.exchangeLimitOrderSubData.encode(...actual)).to.eql(expected);
1021
- });
1022
- });
1023
- });
924
+ describe('When testing subDataService.legacyExchangeLimitOrderSubData', () => {
1024
925
  describe('decode()', () => {
1025
926
  const examples = [
1026
927
  [
@@ -1054,30 +955,142 @@ describe('Feature: subDataService.ts', () => {
1054
955
  ];
1055
956
  examples.forEach(([expected, actual]) => {
1056
957
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1057
- (0, chai_1.expect)(subDataService.exchangeLimitOrderSubData.decode(...actual)).to.eql(expected);
958
+ (0, chai_1.expect)(subDataService.legacyExchangeLimitOrderSubData.decode(...actual)).to.eql(expected);
1058
959
  });
1059
960
  });
1060
961
  });
1061
962
  });
1062
963
  describe('When testing subDataService.sparkLeverageManagementSubData', () => {
964
+ describe('encode()', () => {
965
+ const examples = [
966
+ [
967
+ [
968
+ '0x00000000000000000000000000000000000000000000000018fae27693b40000',
969
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
970
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
971
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
972
+ ],
973
+ [180, enums_1.RatioState.UNDER],
974
+ ],
975
+ [
976
+ [
977
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
978
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
979
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
980
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
981
+ ],
982
+ [160, enums_1.RatioState.OVER],
983
+ ],
984
+ ];
985
+ examples.forEach(([expected, actual]) => {
986
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
987
+ (0, chai_1.expect)(subDataService.sparkLeverageManagementSubData.encode(...actual)).to.eql(expected);
988
+ });
989
+ });
990
+ });
1063
991
  describe('decode()', () => {
1064
992
  const examples = [
1065
993
  [
1066
- { targetRatio: 200 },
1067
- ['0x0000000000000000000000000000000000000000000000001bc16d674ec80000'],
994
+ { targetRatio: 180, ratioState: '1' },
995
+ [
996
+ '0x00000000000000000000000000000000000000000000000018fae27693b40000',
997
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
998
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
999
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1000
+ ],
1068
1001
  ],
1069
1002
  [
1070
- { targetRatio: 123 },
1071
- ['0x0000000000000000000000000000000000000000000000001111d67bb1bb0000'],
1003
+ { targetRatio: 160, ratioState: '0' },
1004
+ [
1005
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
1006
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1007
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1008
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1009
+ ],
1072
1010
  ],
1073
1011
  ];
1074
1012
  examples.forEach(([expected, actual]) => {
1075
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1013
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1076
1014
  (0, chai_1.expect)(subDataService.sparkLeverageManagementSubData.decode(actual)).to.eql(expected);
1077
1015
  });
1078
1016
  });
1079
1017
  });
1080
1018
  });
1019
+ describe('When testing subDataService.legacySparkLeverageManagementSubData', () => {
1020
+ describe('decode()', () => {
1021
+ const examples = [
1022
+ [
1023
+ { targetRatio: 180 },
1024
+ ['0x00000000000000000000000000000000000000000000000018fae27693b40000'],
1025
+ ],
1026
+ [
1027
+ { targetRatio: 160 },
1028
+ ['0x00000000000000000000000000000000000000000000000016345785d8a00000'],
1029
+ ],
1030
+ ];
1031
+ examples.forEach(([expected, actual]) => {
1032
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1033
+ (0, chai_1.expect)(subDataService.legacySparkLeverageManagementSubData.decode(actual)).to.eql(expected);
1034
+ });
1035
+ });
1036
+ });
1037
+ });
1038
+ describe('When testing subDataService.sparkLiquidationProtectionSubData', () => {
1039
+ describe('encode()', () => {
1040
+ const examples = [
1041
+ [
1042
+ [
1043
+ '0x00000000000000000000000000000000000000000000000018fae27693b40000',
1044
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1045
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1046
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1047
+ ],
1048
+ [180, enums_1.RatioState.UNDER],
1049
+ ],
1050
+ [
1051
+ [
1052
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
1053
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1054
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1055
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1056
+ ],
1057
+ [160, enums_1.RatioState.OVER],
1058
+ ],
1059
+ ];
1060
+ examples.forEach(([expected, actual]) => {
1061
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1062
+ (0, chai_1.expect)(subDataService.sparkLiquidationProtectionSubData.encode(...actual)).to.eql(expected);
1063
+ });
1064
+ });
1065
+ });
1066
+ describe('decode()', () => {
1067
+ const examples = [
1068
+ [
1069
+ { targetRatio: 180, ratioState: '1' },
1070
+ [
1071
+ '0x00000000000000000000000000000000000000000000000018fae27693b40000',
1072
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1073
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1074
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1075
+ ],
1076
+ ],
1077
+ [
1078
+ { targetRatio: 160, ratioState: '0' },
1079
+ [
1080
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
1081
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1082
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1083
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1084
+ ],
1085
+ ],
1086
+ ];
1087
+ examples.forEach(([expected, actual]) => {
1088
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1089
+ (0, chai_1.expect)(subDataService.sparkLiquidationProtectionSubData.decode(actual)).to.eql(expected);
1090
+ });
1091
+ });
1092
+ });
1093
+ });
1081
1094
  describe('When testing subDataService.liquityDsrPaybackSubData', () => {
1082
1095
  describe('encode()', () => {
1083
1096
  const examples = [
@@ -2325,6 +2338,298 @@ describe('Feature: subDataService.ts', () => {
2325
2338
  });
2326
2339
  });
2327
2340
  });
2341
+ describe('When testing subDataService.sparkCloseGenericSubData', () => {
2342
+ describe('encode()', () => {
2343
+ const examples = [
2344
+ [
2345
+ [
2346
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
2347
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
2348
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
2349
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
2350
+ '0x0000000000000000000000000000000000000000000000000000000000000005',
2351
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2352
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2353
+ ],
2354
+ [
2355
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address),
2356
+ 2,
2357
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
2358
+ 4,
2359
+ enums_1.CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT,
2360
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2361
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
2362
+ ],
2363
+ ],
2364
+ ];
2365
+ examples.forEach(([expected, actual]) => {
2366
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2367
+ (0, chai_1.expect)(subDataService.sparkCloseGenericSubData.encode(...actual)).to.eql(expected);
2368
+ });
2369
+ });
2370
+ });
2371
+ describe('decode()', () => {
2372
+ const examples = [
2373
+ [
2374
+ {
2375
+ collAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address),
2376
+ collAssetId: 2,
2377
+ debtAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
2378
+ debtAssetId: 4,
2379
+ closeType: enums_1.CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT,
2380
+ marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2381
+ owner: web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
2382
+ },
2383
+ [
2384
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
2385
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
2386
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
2387
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
2388
+ '0x0000000000000000000000000000000000000000000000000000000000000005',
2389
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2390
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2391
+ ],
2392
+ ],
2393
+ ];
2394
+ examples.forEach(([expected, actual]) => {
2395
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2396
+ (0, chai_1.expect)(subDataService.sparkCloseGenericSubData.decode(actual)).to.eql(expected);
2397
+ });
2398
+ });
2399
+ });
2400
+ });
2401
+ describe('When testing subDataService.sparkGenericLeverageManagementSubData', () => {
2402
+ describe('encode()', () => {
2403
+ const examples = [
2404
+ [
2405
+ [
2406
+ '0x00000000000000000000000000000000000000000000000018fae27693b40000',
2407
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2408
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2409
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2410
+ ],
2411
+ [
2412
+ 180,
2413
+ enums_1.RatioState.UNDER,
2414
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2415
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
2416
+ ],
2417
+ ],
2418
+ [
2419
+ [
2420
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
2421
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2422
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2423
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2424
+ ],
2425
+ [
2426
+ 160,
2427
+ enums_1.RatioState.OVER,
2428
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2429
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
2430
+ ],
2431
+ ],
2432
+ ];
2433
+ examples.forEach(([expected, actual]) => {
2434
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2435
+ (0, chai_1.expect)(subDataService.sparkGenericLeverageManagementSubData.encode(...actual)).to.eql(expected);
2436
+ });
2437
+ });
2438
+ });
2439
+ describe('decode()', () => {
2440
+ const examples = [
2441
+ [
2442
+ { targetRatio: 180, ratioState: enums_1.RatioState.UNDER },
2443
+ [
2444
+ '0x00000000000000000000000000000000000000000000000018fae27693b40000',
2445
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2446
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2447
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2448
+ ],
2449
+ ],
2450
+ [
2451
+ { targetRatio: 160, ratioState: enums_1.RatioState.OVER },
2452
+ [
2453
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
2454
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2455
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2456
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2457
+ ],
2458
+ ],
2459
+ ];
2460
+ examples.forEach(([expected, actual]) => {
2461
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2462
+ (0, chai_1.expect)(subDataService.sparkGenericLeverageManagementSubData.decode(actual)).to.eql(expected);
2463
+ });
2464
+ });
2465
+ });
2466
+ });
2467
+ describe('When testing subDataService.sparkGenericLiquidationProtectionSubData', () => {
2468
+ describe('encode()', () => {
2469
+ const examples = [
2470
+ [
2471
+ [
2472
+ '0x00000000000000000000000000000000000000000000000018fae27693b40000',
2473
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2474
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2475
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2476
+ ],
2477
+ [
2478
+ 180,
2479
+ enums_1.RatioState.UNDER,
2480
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2481
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
2482
+ ],
2483
+ ],
2484
+ [
2485
+ [
2486
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
2487
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2488
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2489
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2490
+ ],
2491
+ [
2492
+ 160,
2493
+ enums_1.RatioState.OVER,
2494
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2495
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
2496
+ ],
2497
+ ],
2498
+ ];
2499
+ examples.forEach(([expected, actual]) => {
2500
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2501
+ (0, chai_1.expect)(subDataService.sparkGenericLiquidationProtectionSubData.encode(...actual)).to.eql(expected);
2502
+ });
2503
+ });
2504
+ });
2505
+ describe('decode()', () => {
2506
+ const examples = [
2507
+ [
2508
+ { targetRatio: 180, ratioState: enums_1.RatioState.UNDER },
2509
+ [
2510
+ '0x00000000000000000000000000000000000000000000000018fae27693b40000',
2511
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2512
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2513
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2514
+ ],
2515
+ ],
2516
+ [
2517
+ { targetRatio: 160, ratioState: enums_1.RatioState.OVER },
2518
+ [
2519
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
2520
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2521
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2522
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2523
+ ],
2524
+ ],
2525
+ ];
2526
+ examples.forEach(([expected, actual]) => {
2527
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2528
+ (0, chai_1.expect)(subDataService.sparkGenericLiquidationProtectionSubData.decode(actual)).to.eql(expected);
2529
+ });
2530
+ });
2531
+ });
2532
+ });
2533
+ describe('When testing subDataService.sparkLeverageManagementOnPriceGenericSubData', () => {
2534
+ describe('encode()', () => {
2535
+ const examples = [
2536
+ [
2537
+ [
2538
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
2539
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2540
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
2541
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2542
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2543
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
2544
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2545
+ ],
2546
+ [
2547
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
2548
+ 0,
2549
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
2550
+ 1,
2551
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2552
+ 200,
2553
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
2554
+ ],
2555
+ ],
2556
+ [
2557
+ [
2558
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
2559
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
2560
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
2561
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
2562
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2563
+ '0x00000000000000000000000000000000000000000000000022b1c8c1227a0000',
2564
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2565
+ ],
2566
+ [
2567
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address),
2568
+ 2,
2569
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
2570
+ 4,
2571
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2572
+ 250,
2573
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
2574
+ ],
2575
+ ],
2576
+ ];
2577
+ examples.forEach(([expected, actual]) => {
2578
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2579
+ (0, chai_1.expect)(subDataService.sparkLeverageManagementOnPriceGenericSubData.encode(...actual)).to.eql(expected);
2580
+ });
2581
+ });
2582
+ });
2583
+ describe('decode()', () => {
2584
+ const examples = [
2585
+ [
2586
+ {
2587
+ collAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
2588
+ collAssetId: 0,
2589
+ debtAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
2590
+ debtAssetId: 1,
2591
+ marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2592
+ targetRatio: 200,
2593
+ user: web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
2594
+ },
2595
+ [
2596
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
2597
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2598
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
2599
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2600
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2601
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
2602
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2603
+ ],
2604
+ ],
2605
+ [
2606
+ {
2607
+ collAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address),
2608
+ collAssetId: 2,
2609
+ debtAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
2610
+ debtAssetId: 4,
2611
+ marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2612
+ targetRatio: 250,
2613
+ user: web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
2614
+ },
2615
+ [
2616
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
2617
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
2618
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
2619
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
2620
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2621
+ '0x00000000000000000000000000000000000000000000000022b1c8c1227a0000',
2622
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2623
+ ],
2624
+ ],
2625
+ ];
2626
+ examples.forEach(([expected, actual]) => {
2627
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2628
+ (0, chai_1.expect)(subDataService.sparkLeverageManagementOnPriceGenericSubData.decode(actual)).to.eql(expected);
2629
+ });
2630
+ });
2631
+ });
2632
+ });
2328
2633
  describe('When testing subDataService.aaveV4LeverageManagementSubData', () => {
2329
2634
  describe('encode()', () => {
2330
2635
  const examples = [