@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
@@ -1,9 +1,8 @@
1
- import Dec from 'decimal.js';
2
1
  import { expect } from 'chai';
3
2
  import { getAssetInfo } from '@defisaver/tokens';
4
3
  import * as web3Utils from 'web3-utils';
5
4
  import { MAXUINT } from '@defisaver/tokens';
6
- import { ChainId, CloseStrategyType, OrderType, RatioState } from '../types/enums';
5
+ import { ChainId, CloseStrategyType, RatioState } from '../types/enums';
7
6
  import '../configuration';
8
7
  import * as subDataService from './subDataService';
9
8
  describe('Feature: subDataService.ts', () => {
@@ -118,7 +117,7 @@ describe('Feature: subDataService.ts', () => {
118
117
  });
119
118
  });
120
119
  });
121
- describe('When testing subDataService.makerLeverageManagementSubData', () => {
120
+ describe('When testing subDataService.legacyMakerLeverageManagementSubData', () => {
122
121
  describe('decode()', () => {
123
122
  const examples = [
124
123
  [
@@ -131,12 +130,12 @@ describe('Feature: subDataService.ts', () => {
131
130
  ];
132
131
  examples.forEach(([expected, actual]) => {
133
132
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
134
- expect(subDataService.makerLeverageManagementSubData.decode(actual)).to.eql(expected);
133
+ expect(subDataService.legacyMakerLeverageManagementSubData.decode(actual)).to.eql(expected);
135
134
  });
136
135
  });
137
136
  });
138
137
  });
139
- describe('When testing subDataService.makerLeverageManagementWithoutSubProxy', () => {
138
+ describe('When testing subDataService.makerLeverageManagementSubData', () => {
140
139
  describe('encode()', () => {
141
140
  const examples = [
142
141
  [
@@ -156,7 +155,7 @@ describe('Feature: subDataService.ts', () => {
156
155
  ];
157
156
  examples.forEach(([expected, actual]) => {
158
157
  it(`Given ${actual} should return expected value: ${expected}`, () => {
159
- expect(subDataService.makerLeverageManagementWithoutSubProxy.encode(...actual)).to.eql(expected);
158
+ expect(subDataService.makerLeverageManagementSubData.encode(...actual)).to.eql(expected);
160
159
  });
161
160
  });
162
161
  });
@@ -187,12 +186,12 @@ describe('Feature: subDataService.ts', () => {
187
186
  ];
188
187
  examples.forEach(([expected, actual]) => {
189
188
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
190
- expect(subDataService.makerLeverageManagementWithoutSubProxy.decode(actual)).to.eql(expected);
189
+ expect(subDataService.makerLeverageManagementSubData.decode(actual)).to.eql(expected);
191
190
  });
192
191
  });
193
192
  });
194
193
  });
195
- describe('When testing subDataService.liquityLeverageManagementSubData', () => {
194
+ describe('When testing subDataService.legacyLiquityLeverageManagementSubData', () => {
196
195
  describe('decode()', () => {
197
196
  const examples = [
198
197
  [
@@ -205,7 +204,7 @@ describe('Feature: subDataService.ts', () => {
205
204
  ];
206
205
  examples.forEach(([expected, actual]) => {
207
206
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
208
- expect(subDataService.liquityLeverageManagementSubData.decode(actual)).to.eql(expected);
207
+ expect(subDataService.legacyLiquityLeverageManagementSubData.decode(actual)).to.eql(expected);
209
208
  });
210
209
  });
211
210
  });
@@ -260,24 +259,7 @@ describe('Feature: subDataService.ts', () => {
260
259
  });
261
260
  });
262
261
  });
263
- describe('When testing subDataService.aaveV2LeverageManagementSubData', () => {
264
- describe('encode()', () => {
265
- const examples = [
266
- [
267
- [new Dec(160).mul(1e16).toString(), new Dec(220).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), true],
268
- [160, 220, 180, 190, true]
269
- ],
270
- [
271
- [new Dec(160).mul(1e16).toString(), new Dec(200).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), false],
272
- [160, 200, 180, 190, false]
273
- ],
274
- ];
275
- examples.forEach(([expected, actual]) => {
276
- it(`Given ${actual} should return expected value: ${expected}`, () => {
277
- expect(subDataService.aaveV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
278
- });
279
- });
280
- });
262
+ describe('When testing subDataService.legacyAaveV2LeverageManagementSubData', () => {
281
263
  describe('decode()', () => {
282
264
  const examples = [
283
265
  [
@@ -291,12 +273,12 @@ describe('Feature: subDataService.ts', () => {
291
273
  ];
292
274
  examples.forEach(([expected, actual]) => {
293
275
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
294
- expect(subDataService.aaveV2LeverageManagementSubData.decode(actual)).to.eql(expected);
276
+ expect(subDataService.legacyAaveV2LeverageManagementSubData.decode(actual)).to.eql(expected);
295
277
  });
296
278
  });
297
279
  });
298
280
  });
299
- describe('When testing subDataService.aaveV3LeverageManagementSubData', () => {
281
+ describe('When testing subDataService.legacyAaveV3LeverageManagementSubData', () => {
300
282
  describe('decode()', () => {
301
283
  const examples = [
302
284
  [
@@ -310,7 +292,7 @@ describe('Feature: subDataService.ts', () => {
310
292
  ];
311
293
  examples.forEach(([expected, actual]) => {
312
294
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
313
- expect(subDataService.aaveV3LeverageManagementSubData.decode(actual)).to.eql(expected);
295
+ expect(subDataService.legacyAaveV3LeverageManagementSubData.decode(actual)).to.eql(expected);
314
296
  });
315
297
  });
316
298
  });
@@ -649,128 +631,112 @@ describe('Feature: subDataService.ts', () => {
649
631
  });
650
632
  });
651
633
  });
652
- describe('When testing subDataService.compoundV2LeverageManagementSubData', () => {
634
+ describe('When testing subDataService.sparkGenericFLCollateralSwitchSubData', () => {
653
635
  describe('encode()', () => {
654
636
  const examples = [
655
637
  [
656
- [new Dec(160).mul(1e16).toString(), new Dec(220).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), true],
657
- [160, 220, 180, 190, true]
658
- ],
659
- [
660
- [new Dec(160).mul(1e16).toString(), new Dec(200).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), false],
661
- [160, 200, 180, 190, false]
638
+ [
639
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
640
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
641
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
642
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
643
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
644
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
645
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
646
+ ],
647
+ [
648
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
649
+ 0,
650
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
651
+ 7,
652
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
653
+ '10000000000000000000',
654
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
655
+ ],
662
656
  ],
663
657
  ];
664
658
  examples.forEach(([expected, actual]) => {
665
- it(`Given ${actual} should return expected value: ${expected}`, () => {
666
- expect(subDataService.compoundV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
659
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
660
+ expect(subDataService.sparkGenericFLCollateralSwitchSubData.encode(...actual)).to.eql(expected);
667
661
  });
668
662
  });
669
663
  });
670
664
  describe('decode()', () => {
671
665
  const examples = [
672
666
  [
673
- { targetRatio: 200 },
674
- ['0x0000000000000000000000000000000000000000000000001bc16d674ec80000'],
675
- ],
676
- [
677
- { targetRatio: 123 },
678
- ['0x0000000000000000000000000000000000000000000000001111d67bb1bb0000'],
667
+ {
668
+ fromAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
669
+ fromAssetId: 0,
670
+ toAsset: web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
671
+ toAssetId: 7,
672
+ marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
673
+ amountToSwitch: '10000000000000000000',
674
+ user: web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
675
+ },
676
+ [
677
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
678
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
679
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
680
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
681
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
682
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
683
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
684
+ ],
679
685
  ],
680
686
  ];
681
687
  examples.forEach(([expected, actual]) => {
682
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
683
- expect(subDataService.compoundV2LeverageManagementSubData.decode(actual)).to.eql(expected);
688
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
689
+ expect(subDataService.sparkGenericFLCollateralSwitchSubData.decode(actual)).to.eql(expected);
684
690
  });
685
691
  });
686
692
  });
687
693
  });
688
- describe('When testing subDataService.compoundV3LeverageManagementSubData', () => {
694
+ describe('When testing subDataService.compoundV2LeverageManagementSubData', () => {
689
695
  describe('encode()', () => {
690
696
  const examples = [
691
697
  [
692
698
  [
693
- web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
694
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
695
- new Dec(160).mul(1e16).toString(),
696
- new Dec(220).mul(1e16).toString(),
697
- new Dec(180).mul(1e16).toString(),
698
- new Dec(190).mul(1e16).toString(),
699
- true, false,
699
+ '0x00000000000000000000000000000000000000000000000018fae27693b40000',
700
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
700
701
  ],
701
- [
702
- web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
703
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
704
- 160, 220, 180, 190,
705
- true, false,
706
- ]
702
+ [180, RatioState.UNDER],
707
703
  ],
708
704
  [
709
705
  [
710
- web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
711
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
712
- new Dec(160).mul(1e16).toString(),
713
- new Dec(210).mul(1e16).toString(),
714
- new Dec(180).mul(1e16).toString(),
715
- new Dec(190).mul(1e16).toString(),
716
- false, true,
706
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
707
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
708
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
717
709
  ],
718
- [
719
- web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
720
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
721
- 160, 210, 180, 190,
722
- false, true,
723
- ]
710
+ [160, RatioState.OVER],
724
711
  ],
725
712
  ];
726
713
  examples.forEach(([expected, actual]) => {
727
714
  it(`Given ${actual} should return expected value: ${expected}`, () => {
728
- expect(subDataService.compoundV3LeverageManagementSubData.encode(...actual)).to.eql(expected);
715
+ expect(subDataService.compoundV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
729
716
  });
730
717
  });
731
718
  });
719
+ });
720
+ describe('When testing subDataService.legacyCompoundV2LeverageManagementSubData', () => {
732
721
  describe('decode()', () => {
733
722
  const examples = [
734
723
  [
735
- { targetRatio: 123 },
736
- [
737
- '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
738
- '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
739
- ],
724
+ { targetRatio: 200 },
725
+ ['0x0000000000000000000000000000000000000000000000001bc16d674ec80000'],
740
726
  ],
741
727
  [
742
- { targetRatio: 200 },
743
- [
744
- '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
745
- '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
746
- ],
728
+ { targetRatio: 123 },
729
+ ['0x0000000000000000000000000000000000000000000000001111d67bb1bb0000'],
747
730
  ],
748
731
  ];
749
732
  examples.forEach(([expected, actual]) => {
750
733
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
751
- expect(subDataService.compoundV3LeverageManagementSubData.decode(actual)).to.eql(expected);
734
+ expect(subDataService.legacyCompoundV2LeverageManagementSubData.decode(actual)).to.eql(expected);
752
735
  });
753
736
  });
754
737
  });
755
738
  });
756
739
  describe('When testing subDataService.morphoAaveV2LeverageManagementSubData', () => {
757
- describe('encode()', () => {
758
- const examples = [
759
- [
760
- [new Dec(160).mul(1e16).toString(), new Dec(220).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), true],
761
- [160, 220, 180, 190, true]
762
- ],
763
- [
764
- [new Dec(160).mul(1e16).toString(), new Dec(200).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), false],
765
- [160, 200, 180, 190, false]
766
- ],
767
- ];
768
- examples.forEach(([expected, actual]) => {
769
- it(`Given ${actual} should return expected value: ${expected}`, () => {
770
- expect(subDataService.morphoAaveV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
771
- });
772
- });
773
- });
774
740
  describe('decode()', () => {
775
741
  const examples = [
776
742
  [
@@ -790,23 +756,6 @@ describe('Feature: subDataService.ts', () => {
790
756
  });
791
757
  });
792
758
  describe('When testing subDataService.cBondsRebondSubData', () => {
793
- describe('encode()', () => {
794
- const examples = [
795
- [
796
- ['0x00000000000000000000000000000000000000000000000000000000000000c8'],
797
- [200]
798
- ],
799
- [
800
- ['0x000000000000000000000000000000000000000000000000000000000000a119'],
801
- [41241]
802
- ],
803
- ];
804
- examples.forEach(([expected, actual]) => {
805
- it(`Given ${actual} should return expected value: ${expected}`, () => {
806
- expect(subDataService.cBondsRebondSubData.encode(...actual)).to.eql(expected);
807
- });
808
- });
809
- });
810
759
  describe('decode()', () => {
811
760
  const examples = [
812
761
  [
@@ -947,52 +896,7 @@ describe('Feature: subDataService.ts', () => {
947
896
  });
948
897
  });
949
898
  });
950
- describe('When testing subDataService.exchangeLimitOrderSubData', () => {
951
- describe('encode()', () => {
952
- const examples = [
953
- [
954
- [
955
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
956
- web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
957
- '2131',
958
- '0.53123',
959
- '1696590921159',
960
- `${OrderType.STOP_LOSS}`
961
- ],
962
- [
963
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
964
- web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
965
- '2131',
966
- '0.53123',
967
- 1696590921159,
968
- OrderType.STOP_LOSS
969
- ]
970
- ],
971
- [
972
- [
973
- web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
974
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
975
- '2131',
976
- '0.43123',
977
- '1646590921159',
978
- `${OrderType.TAKE_PROFIT}`
979
- ],
980
- [
981
- web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
982
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
983
- '2131',
984
- '0.43123',
985
- 1646590921159,
986
- OrderType.TAKE_PROFIT
987
- ]
988
- ],
989
- ];
990
- examples.forEach(([expected, actual]) => {
991
- it(`Given ${actual} should return expected value: ${expected}`, () => {
992
- expect(subDataService.exchangeLimitOrderSubData.encode(...actual)).to.eql(expected);
993
- });
994
- });
995
- });
899
+ describe('When testing subDataService.legacyExchangeLimitOrderSubData', () => {
996
900
  describe('decode()', () => {
997
901
  const examples = [
998
902
  [
@@ -1026,30 +930,142 @@ describe('Feature: subDataService.ts', () => {
1026
930
  ];
1027
931
  examples.forEach(([expected, actual]) => {
1028
932
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1029
- expect(subDataService.exchangeLimitOrderSubData.decode(...actual)).to.eql(expected);
933
+ expect(subDataService.legacyExchangeLimitOrderSubData.decode(...actual)).to.eql(expected);
1030
934
  });
1031
935
  });
1032
936
  });
1033
937
  });
1034
938
  describe('When testing subDataService.sparkLeverageManagementSubData', () => {
939
+ describe('encode()', () => {
940
+ const examples = [
941
+ [
942
+ [
943
+ '0x00000000000000000000000000000000000000000000000018fae27693b40000',
944
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
945
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
946
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
947
+ ],
948
+ [180, RatioState.UNDER],
949
+ ],
950
+ [
951
+ [
952
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
953
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
954
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
955
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
956
+ ],
957
+ [160, RatioState.OVER],
958
+ ],
959
+ ];
960
+ examples.forEach(([expected, actual]) => {
961
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
962
+ expect(subDataService.sparkLeverageManagementSubData.encode(...actual)).to.eql(expected);
963
+ });
964
+ });
965
+ });
1035
966
  describe('decode()', () => {
1036
967
  const examples = [
1037
968
  [
1038
- { targetRatio: 200 },
1039
- ['0x0000000000000000000000000000000000000000000000001bc16d674ec80000'],
969
+ { targetRatio: 180, ratioState: '1' },
970
+ [
971
+ '0x00000000000000000000000000000000000000000000000018fae27693b40000',
972
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
973
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
974
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
975
+ ],
1040
976
  ],
1041
977
  [
1042
- { targetRatio: 123 },
1043
- ['0x0000000000000000000000000000000000000000000000001111d67bb1bb0000'],
978
+ { targetRatio: 160, ratioState: '0' },
979
+ [
980
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
981
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
982
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
983
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
984
+ ],
1044
985
  ],
1045
986
  ];
1046
987
  examples.forEach(([expected, actual]) => {
1047
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
988
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1048
989
  expect(subDataService.sparkLeverageManagementSubData.decode(actual)).to.eql(expected);
1049
990
  });
1050
991
  });
1051
992
  });
1052
993
  });
994
+ describe('When testing subDataService.legacySparkLeverageManagementSubData', () => {
995
+ describe('decode()', () => {
996
+ const examples = [
997
+ [
998
+ { targetRatio: 180 },
999
+ ['0x00000000000000000000000000000000000000000000000018fae27693b40000'],
1000
+ ],
1001
+ [
1002
+ { targetRatio: 160 },
1003
+ ['0x00000000000000000000000000000000000000000000000016345785d8a00000'],
1004
+ ],
1005
+ ];
1006
+ examples.forEach(([expected, actual]) => {
1007
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1008
+ expect(subDataService.legacySparkLeverageManagementSubData.decode(actual)).to.eql(expected);
1009
+ });
1010
+ });
1011
+ });
1012
+ });
1013
+ describe('When testing subDataService.sparkLiquidationProtectionSubData', () => {
1014
+ describe('encode()', () => {
1015
+ const examples = [
1016
+ [
1017
+ [
1018
+ '0x00000000000000000000000000000000000000000000000018fae27693b40000',
1019
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1020
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1021
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1022
+ ],
1023
+ [180, RatioState.UNDER],
1024
+ ],
1025
+ [
1026
+ [
1027
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
1028
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1029
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1030
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1031
+ ],
1032
+ [160, RatioState.OVER],
1033
+ ],
1034
+ ];
1035
+ examples.forEach(([expected, actual]) => {
1036
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1037
+ expect(subDataService.sparkLiquidationProtectionSubData.encode(...actual)).to.eql(expected);
1038
+ });
1039
+ });
1040
+ });
1041
+ describe('decode()', () => {
1042
+ const examples = [
1043
+ [
1044
+ { targetRatio: 180, ratioState: '1' },
1045
+ [
1046
+ '0x00000000000000000000000000000000000000000000000018fae27693b40000',
1047
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1048
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1049
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1050
+ ],
1051
+ ],
1052
+ [
1053
+ { targetRatio: 160, ratioState: '0' },
1054
+ [
1055
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
1056
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1057
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1058
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1059
+ ],
1060
+ ],
1061
+ ];
1062
+ examples.forEach(([expected, actual]) => {
1063
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1064
+ expect(subDataService.sparkLiquidationProtectionSubData.decode(actual)).to.eql(expected);
1065
+ });
1066
+ });
1067
+ });
1068
+ });
1053
1069
  describe('When testing subDataService.liquityDsrPaybackSubData', () => {
1054
1070
  describe('encode()', () => {
1055
1071
  const examples = [
@@ -2297,6 +2313,298 @@ describe('Feature: subDataService.ts', () => {
2297
2313
  });
2298
2314
  });
2299
2315
  });
2316
+ describe('When testing subDataService.sparkCloseGenericSubData', () => {
2317
+ describe('encode()', () => {
2318
+ const examples = [
2319
+ [
2320
+ [
2321
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
2322
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
2323
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
2324
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
2325
+ '0x0000000000000000000000000000000000000000000000000000000000000005',
2326
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2327
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2328
+ ],
2329
+ [
2330
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
2331
+ 2,
2332
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
2333
+ 4,
2334
+ CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT,
2335
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2336
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
2337
+ ],
2338
+ ],
2339
+ ];
2340
+ examples.forEach(([expected, actual]) => {
2341
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2342
+ expect(subDataService.sparkCloseGenericSubData.encode(...actual)).to.eql(expected);
2343
+ });
2344
+ });
2345
+ });
2346
+ describe('decode()', () => {
2347
+ const examples = [
2348
+ [
2349
+ {
2350
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
2351
+ collAssetId: 2,
2352
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
2353
+ debtAssetId: 4,
2354
+ closeType: CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT,
2355
+ marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2356
+ owner: web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
2357
+ },
2358
+ [
2359
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
2360
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
2361
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
2362
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
2363
+ '0x0000000000000000000000000000000000000000000000000000000000000005',
2364
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2365
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2366
+ ],
2367
+ ],
2368
+ ];
2369
+ examples.forEach(([expected, actual]) => {
2370
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2371
+ expect(subDataService.sparkCloseGenericSubData.decode(actual)).to.eql(expected);
2372
+ });
2373
+ });
2374
+ });
2375
+ });
2376
+ describe('When testing subDataService.sparkGenericLeverageManagementSubData', () => {
2377
+ describe('encode()', () => {
2378
+ const examples = [
2379
+ [
2380
+ [
2381
+ '0x00000000000000000000000000000000000000000000000018fae27693b40000',
2382
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2383
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2384
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2385
+ ],
2386
+ [
2387
+ 180,
2388
+ RatioState.UNDER,
2389
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2390
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
2391
+ ],
2392
+ ],
2393
+ [
2394
+ [
2395
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
2396
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2397
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2398
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2399
+ ],
2400
+ [
2401
+ 160,
2402
+ RatioState.OVER,
2403
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2404
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
2405
+ ],
2406
+ ],
2407
+ ];
2408
+ examples.forEach(([expected, actual]) => {
2409
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2410
+ expect(subDataService.sparkGenericLeverageManagementSubData.encode(...actual)).to.eql(expected);
2411
+ });
2412
+ });
2413
+ });
2414
+ describe('decode()', () => {
2415
+ const examples = [
2416
+ [
2417
+ { targetRatio: 180, ratioState: RatioState.UNDER },
2418
+ [
2419
+ '0x00000000000000000000000000000000000000000000000018fae27693b40000',
2420
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2421
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2422
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2423
+ ],
2424
+ ],
2425
+ [
2426
+ { targetRatio: 160, ratioState: RatioState.OVER },
2427
+ [
2428
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
2429
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2430
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2431
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2432
+ ],
2433
+ ],
2434
+ ];
2435
+ examples.forEach(([expected, actual]) => {
2436
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2437
+ expect(subDataService.sparkGenericLeverageManagementSubData.decode(actual)).to.eql(expected);
2438
+ });
2439
+ });
2440
+ });
2441
+ });
2442
+ describe('When testing subDataService.sparkGenericLiquidationProtectionSubData', () => {
2443
+ describe('encode()', () => {
2444
+ const examples = [
2445
+ [
2446
+ [
2447
+ '0x00000000000000000000000000000000000000000000000018fae27693b40000',
2448
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2449
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2450
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2451
+ ],
2452
+ [
2453
+ 180,
2454
+ RatioState.UNDER,
2455
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2456
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
2457
+ ],
2458
+ ],
2459
+ [
2460
+ [
2461
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
2462
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2463
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2464
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2465
+ ],
2466
+ [
2467
+ 160,
2468
+ RatioState.OVER,
2469
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2470
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
2471
+ ],
2472
+ ],
2473
+ ];
2474
+ examples.forEach(([expected, actual]) => {
2475
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2476
+ expect(subDataService.sparkGenericLiquidationProtectionSubData.encode(...actual)).to.eql(expected);
2477
+ });
2478
+ });
2479
+ });
2480
+ describe('decode()', () => {
2481
+ const examples = [
2482
+ [
2483
+ { targetRatio: 180, ratioState: RatioState.UNDER },
2484
+ [
2485
+ '0x00000000000000000000000000000000000000000000000018fae27693b40000',
2486
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2487
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2488
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2489
+ ],
2490
+ ],
2491
+ [
2492
+ { targetRatio: 160, ratioState: RatioState.OVER },
2493
+ [
2494
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
2495
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2496
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2497
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2498
+ ],
2499
+ ],
2500
+ ];
2501
+ examples.forEach(([expected, actual]) => {
2502
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2503
+ expect(subDataService.sparkGenericLiquidationProtectionSubData.decode(actual)).to.eql(expected);
2504
+ });
2505
+ });
2506
+ });
2507
+ });
2508
+ describe('When testing subDataService.sparkLeverageManagementOnPriceGenericSubData', () => {
2509
+ describe('encode()', () => {
2510
+ const examples = [
2511
+ [
2512
+ [
2513
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
2514
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2515
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
2516
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2517
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2518
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
2519
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2520
+ ],
2521
+ [
2522
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
2523
+ 0,
2524
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
2525
+ 1,
2526
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2527
+ 200,
2528
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
2529
+ ],
2530
+ ],
2531
+ [
2532
+ [
2533
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
2534
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
2535
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
2536
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
2537
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2538
+ '0x00000000000000000000000000000000000000000000000022b1c8c1227a0000',
2539
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2540
+ ],
2541
+ [
2542
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
2543
+ 2,
2544
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
2545
+ 4,
2546
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2547
+ 250,
2548
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
2549
+ ],
2550
+ ],
2551
+ ];
2552
+ examples.forEach(([expected, actual]) => {
2553
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2554
+ expect(subDataService.sparkLeverageManagementOnPriceGenericSubData.encode(...actual)).to.eql(expected);
2555
+ });
2556
+ });
2557
+ });
2558
+ describe('decode()', () => {
2559
+ const examples = [
2560
+ [
2561
+ {
2562
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
2563
+ collAssetId: 0,
2564
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
2565
+ debtAssetId: 1,
2566
+ marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2567
+ targetRatio: 200,
2568
+ user: web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
2569
+ },
2570
+ [
2571
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
2572
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2573
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
2574
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2575
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2576
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
2577
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2578
+ ],
2579
+ ],
2580
+ [
2581
+ {
2582
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
2583
+ collAssetId: 2,
2584
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
2585
+ debtAssetId: 4,
2586
+ marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2587
+ targetRatio: 250,
2588
+ user: web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
2589
+ },
2590
+ [
2591
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
2592
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
2593
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
2594
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
2595
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2596
+ '0x00000000000000000000000000000000000000000000000022b1c8c1227a0000',
2597
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2598
+ ],
2599
+ ],
2600
+ ];
2601
+ examples.forEach(([expected, actual]) => {
2602
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2603
+ expect(subDataService.sparkLeverageManagementOnPriceGenericSubData.decode(actual)).to.eql(expected);
2604
+ });
2605
+ });
2606
+ });
2607
+ });
2300
2608
  describe('When testing subDataService.aaveV4LeverageManagementSubData', () => {
2301
2609
  describe('encode()', () => {
2302
2610
  const examples = [