@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,10 +1,9 @@
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
5
 
7
- import { ChainId, CloseStrategyType, OrderType, RatioState } from '../types/enums';
6
+ import { ChainId, CloseStrategyType, RatioState } from '../types/enums';
8
7
  import type { EthereumAddress, SubData } from '../types';
9
8
 
10
9
  import '../configuration';
@@ -133,7 +132,7 @@ describe('Feature: subDataService.ts', () => {
133
132
  });
134
133
  });
135
134
 
136
- describe('When testing subDataService.makerLeverageManagementSubData', () => {
135
+ describe('When testing subDataService.legacyMakerLeverageManagementSubData', () => {
137
136
  describe('decode()', () => {
138
137
  const examples: Array<[{ vaultId: number, targetRatio: number }, SubData]> = [
139
138
  [
@@ -147,13 +146,13 @@ describe('Feature: subDataService.ts', () => {
147
146
 
148
147
  examples.forEach(([expected, actual]) => {
149
148
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
150
- expect(subDataService.makerLeverageManagementSubData.decode(actual)).to.eql(expected);
149
+ expect(subDataService.legacyMakerLeverageManagementSubData.decode(actual)).to.eql(expected);
151
150
  });
152
151
  });
153
152
  });
154
153
  });
155
154
 
156
- describe('When testing subDataService.makerLeverageManagementWithoutSubProxy', () => {
155
+ describe('When testing subDataService.makerLeverageManagementSubData', () => {
157
156
  describe('encode()', () => {
158
157
  const examples: Array<[SubData, [vaultId: number, targetRatio: number, daiAddr?: EthereumAddress]]> = [
159
158
  [
@@ -174,7 +173,7 @@ describe('Feature: subDataService.ts', () => {
174
173
 
175
174
  examples.forEach(([expected, actual]) => {
176
175
  it(`Given ${actual} should return expected value: ${expected}`, () => {
177
- expect(subDataService.makerLeverageManagementWithoutSubProxy.encode(...actual)).to.eql(expected);
176
+ expect(subDataService.makerLeverageManagementSubData.encode(...actual)).to.eql(expected);
178
177
  });
179
178
  });
180
179
  });
@@ -207,13 +206,13 @@ describe('Feature: subDataService.ts', () => {
207
206
 
208
207
  examples.forEach(([expected, actual]) => {
209
208
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
210
- expect(subDataService.makerLeverageManagementWithoutSubProxy.decode(actual)).to.eql(expected);
209
+ expect(subDataService.makerLeverageManagementSubData.decode(actual)).to.eql(expected);
211
210
  });
212
211
  });
213
212
  });
214
213
  });
215
214
 
216
- describe('When testing subDataService.liquityLeverageManagementSubData', () => {
215
+ describe('When testing subDataService.legacyLiquityLeverageManagementSubData', () => {
217
216
  describe('decode()', () => {
218
217
  const examples: Array<[{ targetRatio: number }, SubData]> = [
219
218
  [
@@ -227,7 +226,7 @@ describe('Feature: subDataService.ts', () => {
227
226
 
228
227
  examples.forEach(([expected, actual]) => {
229
228
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
230
- expect(subDataService.liquityLeverageManagementSubData.decode(actual)).to.eql(expected);
229
+ expect(subDataService.legacyLiquityLeverageManagementSubData.decode(actual)).to.eql(expected);
231
230
  });
232
231
  });
233
232
  });
@@ -287,26 +286,7 @@ describe('Feature: subDataService.ts', () => {
287
286
  });
288
287
  });
289
288
 
290
- describe('When testing subDataService.aaveV2LeverageManagementSubData', () => {
291
- describe('encode()', () => {
292
- const examples: Array<[[string, string, string, string, boolean], [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean]]> = [
293
- [
294
- [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],
295
- [160, 220, 180, 190, true]
296
- ],
297
- [
298
- [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],
299
- [160, 200, 180, 190, false]
300
- ],
301
- ];
302
-
303
- examples.forEach(([expected, actual]) => {
304
- it(`Given ${actual} should return expected value: ${expected}`, () => {
305
- expect(subDataService.aaveV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
306
- });
307
- });
308
- });
309
-
289
+ describe('When testing subDataService.legacyAaveV2LeverageManagementSubData', () => {
310
290
  describe('decode()', () => {
311
291
  const examples: Array<[{ targetRatio: number }, SubData]> = [
312
292
  [
@@ -321,13 +301,13 @@ describe('Feature: subDataService.ts', () => {
321
301
 
322
302
  examples.forEach(([expected, actual]) => {
323
303
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
324
- expect(subDataService.aaveV2LeverageManagementSubData.decode(actual)).to.eql(expected);
304
+ expect(subDataService.legacyAaveV2LeverageManagementSubData.decode(actual)).to.eql(expected);
325
305
  });
326
306
  });
327
307
  });
328
308
  });
329
309
 
330
- describe('When testing subDataService.aaveV3LeverageManagementSubData', () => {
310
+ describe('When testing subDataService.legacyAaveV3LeverageManagementSubData', () => {
331
311
  describe('decode()', () => {
332
312
  const examples: Array<[{ targetRatio: number }, SubData]> = [
333
313
  [
@@ -342,7 +322,7 @@ describe('Feature: subDataService.ts', () => {
342
322
 
343
323
  examples.forEach(([expected, actual]) => {
344
324
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
345
- expect(subDataService.aaveV3LeverageManagementSubData.decode(actual)).to.eql(expected);
325
+ expect(subDataService.legacyAaveV3LeverageManagementSubData.decode(actual)).to.eql(expected);
346
326
  });
347
327
  });
348
328
  });
@@ -694,138 +674,142 @@ describe('Feature: subDataService.ts', () => {
694
674
  });
695
675
  });
696
676
 
697
- describe('When testing subDataService.compoundV2LeverageManagementSubData', () => {
677
+ describe('When testing subDataService.sparkGenericFLCollateralSwitchSubData', () => {
698
678
  describe('encode()', () => {
699
- const examples: Array<[[string, string, string, string, boolean], [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean]]> = [
679
+ const examples: Array<[
680
+ SubData,
700
681
  [
701
- [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],
702
- [160, 220, 180, 190, true]
703
- ],
682
+ fromAsset: EthereumAddress,
683
+ fromAssetId: number,
684
+ toAsset: EthereumAddress,
685
+ toAssetId: number,
686
+ marketAddr: EthereumAddress,
687
+ amountToSwitch: string,
688
+ user: EthereumAddress,
689
+ ]
690
+ ]> = [
704
691
  [
705
- [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],
706
- [160, 200, 180, 190, false]
692
+ [
693
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
694
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
695
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
696
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
697
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
698
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
699
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
700
+ ],
701
+ [
702
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
703
+ 0,
704
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
705
+ 7,
706
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
707
+ '10000000000000000000',
708
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
709
+ ],
707
710
  ],
708
711
  ];
709
712
 
710
713
  examples.forEach(([expected, actual]) => {
711
- it(`Given ${actual} should return expected value: ${expected}`, () => {
712
- expect(subDataService.compoundV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
714
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
715
+ expect(subDataService.sparkGenericFLCollateralSwitchSubData.encode(...actual)).to.eql(expected);
713
716
  });
714
717
  });
715
718
  });
716
719
 
717
720
  describe('decode()', () => {
718
- const examples: Array<[{ targetRatio: number }, SubData]> = [
719
- [
720
- { targetRatio: 200 },
721
- ['0x0000000000000000000000000000000000000000000000001bc16d674ec80000'],
722
- ],
721
+ const examples: Array<[
722
+ {
723
+ fromAsset: EthereumAddress,
724
+ fromAssetId: number,
725
+ toAsset: EthereumAddress,
726
+ toAssetId: number,
727
+ marketAddr: EthereumAddress,
728
+ amountToSwitch: string,
729
+ user: EthereumAddress,
730
+ },
731
+ SubData,
732
+ ]> = [
723
733
  [
724
- { targetRatio: 123 },
725
- ['0x0000000000000000000000000000000000000000000000001111d67bb1bb0000'],
734
+ {
735
+ fromAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
736
+ fromAssetId: 0,
737
+ toAsset: web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
738
+ toAssetId: 7,
739
+ marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
740
+ amountToSwitch: '10000000000000000000',
741
+ user: web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
742
+ },
743
+ [
744
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
745
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
746
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
747
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
748
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
749
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
750
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
751
+ ],
726
752
  ],
727
753
  ];
728
754
 
729
755
  examples.forEach(([expected, actual]) => {
730
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
731
- expect(subDataService.compoundV2LeverageManagementSubData.decode(actual)).to.eql(expected);
756
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
757
+ expect(subDataService.sparkGenericFLCollateralSwitchSubData.decode(actual)).to.eql(expected);
732
758
  });
733
759
  });
734
760
  });
735
761
  });
736
762
 
737
- describe('When testing subDataService.compoundV3LeverageManagementSubData', () => {
763
+ describe('When testing subDataService.compoundV2LeverageManagementSubData', () => {
738
764
  describe('encode()', () => {
739
- const examples: Array<[[EthereumAddress, EthereumAddress, string, string, string, string, boolean, boolean], [market: EthereumAddress, baseToken: EthereumAddress, triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean, isEOA: boolean]]> = [
765
+ const examples: Array<[SubData, [targetRatio: number, ratioState: RatioState]]> = [
740
766
  [
741
767
  [
742
- web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
743
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
744
- new Dec(160).mul(1e16).toString(),
745
- new Dec(220).mul(1e16).toString(),
746
- new Dec(180).mul(1e16).toString(),
747
- new Dec(190).mul(1e16).toString(),
748
- true, false,
768
+ '0x00000000000000000000000000000000000000000000000018fae27693b40000',
769
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
749
770
  ],
750
- [
751
- web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
752
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
753
- 160, 220, 180, 190,
754
- true, false,
755
- ]
771
+ [180, RatioState.UNDER],
756
772
  ],
757
773
  [
758
774
  [
759
- web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
760
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
761
- new Dec(160).mul(1e16).toString(),
762
- new Dec(210).mul(1e16).toString(),
763
- new Dec(180).mul(1e16).toString(),
764
- new Dec(190).mul(1e16).toString(),
765
- false, true,
775
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
776
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
777
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
766
778
  ],
767
- [
768
- web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
769
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
770
- 160, 210, 180, 190,
771
- false, true,
772
- ]
779
+ [160, RatioState.OVER],
773
780
  ],
774
781
  ];
775
782
 
776
783
  examples.forEach(([expected, actual]) => {
777
784
  it(`Given ${actual} should return expected value: ${expected}`, () => {
778
- expect(subDataService.compoundV3LeverageManagementSubData.encode(...actual)).to.eql(expected);
785
+ expect(subDataService.compoundV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
779
786
  });
780
787
  });
781
788
  });
789
+ });
782
790
 
791
+ describe('When testing subDataService.legacyCompoundV2LeverageManagementSubData', () => {
783
792
  describe('decode()', () => {
784
793
  const examples: Array<[{ targetRatio: number }, SubData]> = [
785
794
  [
786
- { targetRatio: 123 },
787
- [
788
- '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
789
- '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
790
- ],
795
+ { targetRatio: 200 },
796
+ ['0x0000000000000000000000000000000000000000000000001bc16d674ec80000'],
791
797
  ],
792
798
  [
793
- { targetRatio: 200 },
794
- [
795
- '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
796
- '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
797
- ],
799
+ { targetRatio: 123 },
800
+ ['0x0000000000000000000000000000000000000000000000001111d67bb1bb0000'],
798
801
  ],
799
802
  ];
800
803
 
801
804
  examples.forEach(([expected, actual]) => {
802
805
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
803
- expect(subDataService.compoundV3LeverageManagementSubData.decode(actual)).to.eql(expected);
806
+ expect(subDataService.legacyCompoundV2LeverageManagementSubData.decode(actual)).to.eql(expected);
804
807
  });
805
808
  });
806
809
  });
807
810
  });
808
811
 
809
812
  describe('When testing subDataService.morphoAaveV2LeverageManagementSubData', () => {
810
- describe('encode()', () => {
811
- const examples: Array<[[string, string, string, string, boolean], [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean]]> = [
812
- [
813
- [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],
814
- [160, 220, 180, 190, true]
815
- ],
816
- [
817
- [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],
818
- [160, 200, 180, 190, false]
819
- ],
820
- ];
821
-
822
- examples.forEach(([expected, actual]) => {
823
- it(`Given ${actual} should return expected value: ${expected}`, () => {
824
- expect(subDataService.morphoAaveV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
825
- });
826
- });
827
- });
828
-
829
813
  describe('decode()', () => {
830
814
  const examples: Array<[{ targetRatio: number }, SubData]> = [
831
815
  [
@@ -847,25 +831,6 @@ describe('Feature: subDataService.ts', () => {
847
831
  });
848
832
 
849
833
  describe('When testing subDataService.cBondsRebondSubData', () => {
850
- describe('encode()', () => {
851
- const examples: Array<[SubData, [bondId: number | string]]> = [
852
- [
853
- ['0x00000000000000000000000000000000000000000000000000000000000000c8'],
854
- [200]
855
- ],
856
- [
857
- ['0x000000000000000000000000000000000000000000000000000000000000a119'],
858
- [41241]
859
- ],
860
- ];
861
-
862
- examples.forEach(([expected, actual]) => {
863
- it(`Given ${actual} should return expected value: ${expected}`, () => {
864
- expect(subDataService.cBondsRebondSubData.encode(...actual)).to.eql(expected);
865
- });
866
- });
867
- });
868
-
869
834
  describe('decode()', () => {
870
835
  const examples: Array<[{ bondId: string }, SubData]> = [
871
836
  [
@@ -1016,54 +981,7 @@ describe('Feature: subDataService.ts', () => {
1016
981
  });
1017
982
  });
1018
983
 
1019
- describe('When testing subDataService.exchangeLimitOrderSubData', () => {
1020
- describe('encode()', () => {
1021
- const examples: Array<[[EthereumAddress, EthereumAddress, string, string, string, string], [fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, targetPrice: string, goodUntil: string | number, orderType: OrderType]]> = [
1022
- [
1023
- [
1024
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1025
- web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
1026
- '2131',
1027
- '0.53123',
1028
- '1696590921159',
1029
- `${OrderType.STOP_LOSS}`
1030
- ],
1031
- [
1032
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1033
- web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
1034
- '2131',
1035
- '0.53123',
1036
- 1696590921159,
1037
- OrderType.STOP_LOSS
1038
- ]
1039
- ],
1040
- [
1041
- [
1042
- web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
1043
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
1044
- '2131',
1045
- '0.43123',
1046
- '1646590921159',
1047
- `${OrderType.TAKE_PROFIT}`
1048
- ],
1049
- [
1050
- web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
1051
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
1052
- '2131',
1053
- '0.43123',
1054
- 1646590921159,
1055
- OrderType.TAKE_PROFIT
1056
- ]
1057
- ],
1058
- ];
1059
-
1060
- examples.forEach(([expected, actual]) => {
1061
- it(`Given ${actual} should return expected value: ${expected}`, () => {
1062
- expect(subDataService.exchangeLimitOrderSubData.encode(...actual)).to.eql(expected);
1063
- });
1064
- });
1065
- });
1066
-
984
+ describe('When testing subDataService.legacyExchangeLimitOrderSubData', () => {
1067
985
  describe('decode()', () => {
1068
986
  const examples: Array<[{ fromToken: EthereumAddress, toToken: EthereumAddress, amount: string }, [SubData, ChainId]]> = [
1069
987
  [
@@ -1098,127 +1016,254 @@ describe('Feature: subDataService.ts', () => {
1098
1016
 
1099
1017
  examples.forEach(([expected, actual]) => {
1100
1018
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1101
- expect(subDataService.exchangeLimitOrderSubData.decode(...actual)).to.eql(expected);
1019
+ expect(subDataService.legacyExchangeLimitOrderSubData.decode(...actual)).to.eql(expected);
1102
1020
  });
1103
1021
  });
1104
1022
  });
1105
1023
  });
1106
1024
 
1025
+
1107
1026
  describe('When testing subDataService.sparkLeverageManagementSubData', () => {
1108
- describe('decode()', () => {
1109
- const examples: Array<[{ targetRatio: number }, SubData]> = [
1027
+ describe('encode()', () => {
1028
+ const examples: Array<[
1029
+ SubData,
1030
+ [targetRatio: number, ratioState: RatioState]
1031
+ ]> = [
1110
1032
  [
1111
- { targetRatio: 200 },
1112
- ['0x0000000000000000000000000000000000000000000000001bc16d674ec80000'],
1033
+ [
1034
+ '0x00000000000000000000000000000000000000000000000018fae27693b40000',
1035
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1036
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1037
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1038
+ ],
1039
+ [180, RatioState.UNDER],
1113
1040
  ],
1114
1041
  [
1115
- { targetRatio: 123 },
1116
- ['0x0000000000000000000000000000000000000000000000001111d67bb1bb0000'],
1042
+ [
1043
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
1044
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1045
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1046
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1047
+ ],
1048
+ [160, RatioState.OVER],
1117
1049
  ],
1118
1050
  ];
1119
1051
 
1120
1052
  examples.forEach(([expected, actual]) => {
1121
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1122
- expect(subDataService.sparkLeverageManagementSubData.decode(actual)).to.eql(expected);
1053
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1054
+ expect(subDataService.sparkLeverageManagementSubData.encode(...actual)).to.eql(expected);
1123
1055
  });
1124
1056
  });
1125
1057
  });
1126
- });
1127
1058
 
1128
- describe('When testing subDataService.liquityDsrPaybackSubData', () => {
1129
- describe('encode()', () => {
1130
- const examples: Array<[SubData, [targetRatio: number]]> = [
1059
+ describe('decode()', () => {
1060
+ const examples: Array<[{ targetRatio: number, ratioState: string }, SubData]> = [
1131
1061
  [
1062
+ { targetRatio: 180, ratioState: '1' },
1132
1063
  [
1133
- '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
1134
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
1064
+ '0x00000000000000000000000000000000000000000000000018fae27693b40000',
1065
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1066
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1067
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1135
1068
  ],
1136
- [123]
1137
1069
  ],
1138
1070
  [
1071
+ { targetRatio: 160, ratioState: '0' },
1139
1072
  [
1140
- '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000003a4965bf58a40000',
1141
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
1073
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
1074
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1075
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1076
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1142
1077
  ],
1143
- [420]
1144
1078
  ],
1145
1079
  ];
1146
1080
 
1147
1081
  examples.forEach(([expected, actual]) => {
1148
- it(`Given ${actual} should return expected value: ${expected}`, () => {
1149
- expect(subDataService.liquityDsrPaybackSubData.encode(...actual)).to.eql(expected);
1082
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1083
+ expect(subDataService.sparkLeverageManagementSubData.decode(actual)).to.eql(expected);
1150
1084
  });
1151
1085
  });
1152
1086
  });
1087
+ });
1153
1088
 
1089
+ describe('When testing subDataService.legacySparkLeverageManagementSubData', () => {
1154
1090
  describe('decode()', () => {
1155
1091
  const examples: Array<[{ targetRatio: number }, SubData]> = [
1156
1092
  [
1157
- {
1158
- targetRatio: 123,
1159
- },
1160
- [
1161
- '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
1162
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
1163
- ],
1093
+ { targetRatio: 180 },
1094
+ ['0x00000000000000000000000000000000000000000000000018fae27693b40000'],
1164
1095
  ],
1165
1096
  [
1166
- {
1167
- targetRatio: 420,
1168
- },
1169
- [
1170
- '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000003a4965bf58a40000',
1171
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
1172
- ],
1097
+ { targetRatio: 160 },
1098
+ ['0x00000000000000000000000000000000000000000000000016345785d8a00000'],
1173
1099
  ],
1174
1100
  ];
1175
1101
 
1176
1102
  examples.forEach(([expected, actual]) => {
1177
1103
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1178
- expect(subDataService.liquityDsrPaybackSubData.decode(actual)).to.eql(expected);
1104
+ expect(subDataService.legacySparkLeverageManagementSubData.decode(actual)).to.eql(expected);
1179
1105
  });
1180
1106
  });
1181
1107
  });
1182
1108
  });
1183
1109
 
1184
- describe('When testing subDataService.liquityDsrSupplySubData', () => {
1110
+ describe('When testing subDataService.sparkLiquidationProtectionSubData', () => {
1185
1111
  describe('encode()', () => {
1186
- const examples: Array<[SubData, [targetRatio: number]]> = [
1112
+ const examples: Array<[
1113
+ SubData,
1114
+ [targetRatio: number, ratioState: RatioState]
1115
+ ]> = [
1187
1116
  [
1188
1117
  [
1189
- '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000002c68af0bb1400000',
1190
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1118
+ '0x00000000000000000000000000000000000000000000000018fae27693b40000',
1119
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1120
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1121
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1191
1122
  ],
1192
- [320]
1123
+ [180, RatioState.UNDER],
1193
1124
  ],
1194
1125
  [
1195
1126
  [
1196
- '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001eab7f4a799d0000',
1197
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1127
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
1128
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1129
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1130
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1198
1131
  ],
1199
- [221]
1132
+ [160, RatioState.OVER],
1200
1133
  ],
1201
1134
  ];
1202
1135
 
1203
1136
  examples.forEach(([expected, actual]) => {
1204
- it(`Given ${actual} should return expected value: ${expected}`, () => {
1205
- expect(subDataService.liquityDsrSupplySubData.encode(...actual)).to.eql(expected);
1137
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1138
+ expect(subDataService.sparkLiquidationProtectionSubData.encode(...actual)).to.eql(expected);
1206
1139
  });
1207
1140
  });
1208
1141
  });
1209
1142
 
1210
1143
  describe('decode()', () => {
1211
- const examples: Array<[{ targetRatio: number }, SubData]> = [
1144
+ const examples: Array<[{ targetRatio: number, ratioState: string }, SubData]> = [
1212
1145
  [
1213
- {
1214
- targetRatio: 320,
1215
- },
1146
+ { targetRatio: 180, ratioState: '1' },
1216
1147
  [
1217
- '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000002c68af0bb1400000',
1218
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1219
- ],
1220
- ],
1221
- [
1148
+ '0x00000000000000000000000000000000000000000000000018fae27693b40000',
1149
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1150
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1151
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1152
+ ],
1153
+ ],
1154
+ [
1155
+ { targetRatio: 160, ratioState: '0' },
1156
+ [
1157
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
1158
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1159
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1160
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1161
+ ],
1162
+ ],
1163
+ ];
1164
+
1165
+ examples.forEach(([expected, actual]) => {
1166
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1167
+ expect(subDataService.sparkLiquidationProtectionSubData.decode(actual)).to.eql(expected);
1168
+ });
1169
+ });
1170
+ });
1171
+ });
1172
+
1173
+ describe('When testing subDataService.liquityDsrPaybackSubData', () => {
1174
+ describe('encode()', () => {
1175
+ const examples: Array<[SubData, [targetRatio: number]]> = [
1176
+ [
1177
+ [
1178
+ '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
1179
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
1180
+ ],
1181
+ [123]
1182
+ ],
1183
+ [
1184
+ [
1185
+ '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000003a4965bf58a40000',
1186
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
1187
+ ],
1188
+ [420]
1189
+ ],
1190
+ ];
1191
+
1192
+ examples.forEach(([expected, actual]) => {
1193
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1194
+ expect(subDataService.liquityDsrPaybackSubData.encode(...actual)).to.eql(expected);
1195
+ });
1196
+ });
1197
+ });
1198
+
1199
+ describe('decode()', () => {
1200
+ const examples: Array<[{ targetRatio: number }, SubData]> = [
1201
+ [
1202
+ {
1203
+ targetRatio: 123,
1204
+ },
1205
+ [
1206
+ '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
1207
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
1208
+ ],
1209
+ ],
1210
+ [
1211
+ {
1212
+ targetRatio: 420,
1213
+ },
1214
+ [
1215
+ '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000003a4965bf58a40000',
1216
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
1217
+ ],
1218
+ ],
1219
+ ];
1220
+
1221
+ examples.forEach(([expected, actual]) => {
1222
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1223
+ expect(subDataService.liquityDsrPaybackSubData.decode(actual)).to.eql(expected);
1224
+ });
1225
+ });
1226
+ });
1227
+ });
1228
+
1229
+ describe('When testing subDataService.liquityDsrSupplySubData', () => {
1230
+ describe('encode()', () => {
1231
+ const examples: Array<[SubData, [targetRatio: number]]> = [
1232
+ [
1233
+ [
1234
+ '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000002c68af0bb1400000',
1235
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1236
+ ],
1237
+ [320]
1238
+ ],
1239
+ [
1240
+ [
1241
+ '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001eab7f4a799d0000',
1242
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1243
+ ],
1244
+ [221]
1245
+ ],
1246
+ ];
1247
+
1248
+ examples.forEach(([expected, actual]) => {
1249
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1250
+ expect(subDataService.liquityDsrSupplySubData.encode(...actual)).to.eql(expected);
1251
+ });
1252
+ });
1253
+ });
1254
+
1255
+ describe('decode()', () => {
1256
+ const examples: Array<[{ targetRatio: number }, SubData]> = [
1257
+ [
1258
+ {
1259
+ targetRatio: 320,
1260
+ },
1261
+ [
1262
+ '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000002c68af0bb1400000',
1263
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1264
+ ],
1265
+ ],
1266
+ [
1222
1267
  {
1223
1268
  targetRatio: 221,
1224
1269
  },
@@ -2517,6 +2562,369 @@ describe('Feature: subDataService.ts', () => {
2517
2562
  });
2518
2563
  });
2519
2564
  });
2565
+ describe('When testing subDataService.sparkCloseGenericSubData', () => {
2566
+ describe('encode()', () => {
2567
+ const examples: Array<[
2568
+ SubData,
2569
+ [
2570
+ collAsset: EthereumAddress,
2571
+ collAssetId: number,
2572
+ debtAsset: EthereumAddress,
2573
+ debtAssetId: number,
2574
+ closeType: CloseStrategyType,
2575
+ marketAddr: EthereumAddress,
2576
+ user: EthereumAddress,
2577
+ ]
2578
+ ]> = [
2579
+ [
2580
+ [
2581
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
2582
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
2583
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
2584
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
2585
+ '0x0000000000000000000000000000000000000000000000000000000000000005',
2586
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2587
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2588
+ ],
2589
+ [
2590
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
2591
+ 2,
2592
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
2593
+ 4,
2594
+ CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT,
2595
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2596
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
2597
+ ],
2598
+ ],
2599
+ ];
2600
+
2601
+ examples.forEach(([expected, actual]) => {
2602
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2603
+ expect(subDataService.sparkCloseGenericSubData.encode(...actual)).to.eql(expected);
2604
+ });
2605
+ });
2606
+ });
2607
+
2608
+ describe('decode()', () => {
2609
+ const examples: Array<[
2610
+ {
2611
+ collAsset: EthereumAddress,
2612
+ collAssetId: number,
2613
+ debtAsset: EthereumAddress,
2614
+ debtAssetId: number,
2615
+ closeType: CloseStrategyType,
2616
+ marketAddr: EthereumAddress,
2617
+ owner: EthereumAddress,
2618
+ },
2619
+ SubData,
2620
+ ]> = [
2621
+ [
2622
+ {
2623
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
2624
+ collAssetId: 2,
2625
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
2626
+ debtAssetId: 4,
2627
+ closeType: CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT,
2628
+ marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2629
+ owner: web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
2630
+ },
2631
+ [
2632
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
2633
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
2634
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
2635
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
2636
+ '0x0000000000000000000000000000000000000000000000000000000000000005',
2637
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2638
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2639
+ ],
2640
+ ],
2641
+ ];
2642
+
2643
+ examples.forEach(([expected, actual]) => {
2644
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2645
+ expect(subDataService.sparkCloseGenericSubData.decode(actual)).to.eql(expected);
2646
+ });
2647
+ });
2648
+ });
2649
+ });
2650
+
2651
+ describe('When testing subDataService.sparkGenericLeverageManagementSubData', () => {
2652
+ describe('encode()', () => {
2653
+ const examples: Array<[
2654
+ SubData,
2655
+ [targetRatio: number, ratioState: RatioState, market: EthereumAddress, user: EthereumAddress]
2656
+ ]> = [
2657
+ [
2658
+ [
2659
+ '0x00000000000000000000000000000000000000000000000018fae27693b40000',
2660
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2661
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2662
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2663
+ ],
2664
+ [
2665
+ 180,
2666
+ RatioState.UNDER,
2667
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2668
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
2669
+ ],
2670
+ ],
2671
+ [
2672
+ [
2673
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
2674
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2675
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2676
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2677
+ ],
2678
+ [
2679
+ 160,
2680
+ RatioState.OVER,
2681
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2682
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
2683
+ ],
2684
+ ],
2685
+ ];
2686
+
2687
+ examples.forEach(([expected, actual]) => {
2688
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2689
+ expect(subDataService.sparkGenericLeverageManagementSubData.encode(...actual)).to.eql(expected);
2690
+ });
2691
+ });
2692
+ });
2693
+
2694
+ describe('decode()', () => {
2695
+ const examples: Array<[
2696
+ { targetRatio: number, ratioState: RatioState },
2697
+ SubData,
2698
+ ]> = [
2699
+ [
2700
+ { targetRatio: 180, ratioState: RatioState.UNDER },
2701
+ [
2702
+ '0x00000000000000000000000000000000000000000000000018fae27693b40000',
2703
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2704
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2705
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2706
+ ],
2707
+ ],
2708
+ [
2709
+ { targetRatio: 160, ratioState: RatioState.OVER },
2710
+ [
2711
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
2712
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2713
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2714
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2715
+ ],
2716
+ ],
2717
+ ];
2718
+
2719
+ examples.forEach(([expected, actual]) => {
2720
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2721
+ expect(subDataService.sparkGenericLeverageManagementSubData.decode(actual)).to.eql(expected);
2722
+ });
2723
+ });
2724
+ });
2725
+ });
2726
+
2727
+ describe('When testing subDataService.sparkGenericLiquidationProtectionSubData', () => {
2728
+ describe('encode()', () => {
2729
+ const examples: Array<[
2730
+ SubData,
2731
+ [targetRatio: number, ratioState: RatioState, market: EthereumAddress, user: EthereumAddress]
2732
+ ]> = [
2733
+ [
2734
+ [
2735
+ '0x00000000000000000000000000000000000000000000000018fae27693b40000',
2736
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2737
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2738
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2739
+ ],
2740
+ [
2741
+ 180,
2742
+ RatioState.UNDER,
2743
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2744
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
2745
+ ],
2746
+ ],
2747
+ [
2748
+ [
2749
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
2750
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2751
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2752
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2753
+ ],
2754
+ [
2755
+ 160,
2756
+ RatioState.OVER,
2757
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2758
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
2759
+ ],
2760
+ ],
2761
+ ];
2762
+
2763
+ examples.forEach(([expected, actual]) => {
2764
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2765
+ expect(subDataService.sparkGenericLiquidationProtectionSubData.encode(...actual)).to.eql(expected);
2766
+ });
2767
+ });
2768
+ });
2769
+
2770
+ describe('decode()', () => {
2771
+ const examples: Array<[
2772
+ { targetRatio: number, ratioState: RatioState },
2773
+ SubData,
2774
+ ]> = [
2775
+ [
2776
+ { targetRatio: 180, ratioState: RatioState.UNDER },
2777
+ [
2778
+ '0x00000000000000000000000000000000000000000000000018fae27693b40000',
2779
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2780
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2781
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2782
+ ],
2783
+ ],
2784
+ [
2785
+ { targetRatio: 160, ratioState: RatioState.OVER },
2786
+ [
2787
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
2788
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2789
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2790
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2791
+ ],
2792
+ ],
2793
+ ];
2794
+
2795
+ examples.forEach(([expected, actual]) => {
2796
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2797
+ expect(subDataService.sparkGenericLiquidationProtectionSubData.decode(actual)).to.eql(expected);
2798
+ });
2799
+ });
2800
+ });
2801
+ });
2802
+
2803
+ describe('When testing subDataService.sparkLeverageManagementOnPriceGenericSubData', () => {
2804
+ describe('encode()', () => {
2805
+ const examples: Array<[
2806
+ SubData,
2807
+ [
2808
+ collAsset: EthereumAddress,
2809
+ collAssetId: number,
2810
+ debtAsset: EthereumAddress,
2811
+ debtAssetId: number,
2812
+ marketAddr: EthereumAddress,
2813
+ targetRatio: number,
2814
+ user: EthereumAddress,
2815
+ ]
2816
+ ]> = [
2817
+ [
2818
+ [
2819
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
2820
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2821
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
2822
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2823
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2824
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
2825
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2826
+ ],
2827
+ [
2828
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
2829
+ 0,
2830
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
2831
+ 1,
2832
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2833
+ 200,
2834
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
2835
+ ],
2836
+ ],
2837
+ [
2838
+ [
2839
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
2840
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
2841
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
2842
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
2843
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2844
+ '0x00000000000000000000000000000000000000000000000022b1c8c1227a0000',
2845
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2846
+ ],
2847
+ [
2848
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
2849
+ 2,
2850
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
2851
+ 4,
2852
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2853
+ 250,
2854
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
2855
+ ],
2856
+ ],
2857
+ ];
2858
+
2859
+ examples.forEach(([expected, actual]) => {
2860
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2861
+ expect(subDataService.sparkLeverageManagementOnPriceGenericSubData.encode(...actual)).to.eql(expected);
2862
+ });
2863
+ });
2864
+ });
2865
+
2866
+ describe('decode()', () => {
2867
+ const examples: Array<[
2868
+ {
2869
+ collAsset: EthereumAddress,
2870
+ collAssetId: number,
2871
+ debtAsset: EthereumAddress,
2872
+ debtAssetId: number,
2873
+ marketAddr: EthereumAddress,
2874
+ targetRatio: number,
2875
+ user: EthereumAddress,
2876
+ },
2877
+ SubData,
2878
+ ]> = [
2879
+ [
2880
+ {
2881
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
2882
+ collAssetId: 0,
2883
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
2884
+ debtAssetId: 1,
2885
+ marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2886
+ targetRatio: 200,
2887
+ user: web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
2888
+ },
2889
+ [
2890
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
2891
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2892
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
2893
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2894
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2895
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
2896
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2897
+ ],
2898
+ ],
2899
+ [
2900
+ {
2901
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
2902
+ collAssetId: 2,
2903
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
2904
+ debtAssetId: 4,
2905
+ marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2906
+ targetRatio: 250,
2907
+ user: web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
2908
+ },
2909
+ [
2910
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
2911
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
2912
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
2913
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
2914
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2915
+ '0x00000000000000000000000000000000000000000000000022b1c8c1227a0000',
2916
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2917
+ ],
2918
+ ],
2919
+ ];
2920
+
2921
+ examples.forEach(([expected, actual]) => {
2922
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2923
+ expect(subDataService.sparkLeverageManagementOnPriceGenericSubData.decode(actual)).to.eql(expected);
2924
+ });
2925
+ });
2926
+ });
2927
+ });
2520
2928
  describe('When testing subDataService.aaveV4LeverageManagementSubData', () => {
2521
2929
  describe('encode()', () => {
2522
2930
  const examples: Array<[SubData, [spoke: EthereumAddress, owner: EthereumAddress, ratioState: RatioState, targetRatio: number]]> = [