@defisaver/automation-sdk 3.3.22-instant-twap-close-dev → 3.3.23

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 (52) hide show
  1. package/cjs/automation/private/StrategiesAutomation.d.ts +5 -1
  2. package/cjs/automation/private/StrategiesAutomation.js +12 -0
  3. package/cjs/automation/private/StrategiesAutomation.test.js +51 -0
  4. package/cjs/constants/index.js +40 -40
  5. package/cjs/services/apiSubscriptionsService.d.ts +7 -0
  6. package/cjs/services/apiSubscriptionsService.js +33 -0
  7. package/cjs/services/apiSubscriptionsService.test.d.ts +1 -0
  8. package/cjs/services/apiSubscriptionsService.test.js +67 -0
  9. package/cjs/services/strategiesService.js +8 -21
  10. package/cjs/services/strategiesService.test.js +0 -63
  11. package/cjs/services/strategySubService.d.ts +1 -1
  12. package/cjs/services/strategySubService.js +6 -7
  13. package/cjs/services/strategySubService.test.js +71 -111
  14. package/cjs/services/subDataService.d.ts +10 -12
  15. package/cjs/services/subDataService.js +30 -36
  16. package/cjs/services/subDataService.test.js +104 -70
  17. package/cjs/types/enums.d.ts +18 -18
  18. package/cjs/types/enums.js +10 -11
  19. package/cjs/types/index.d.ts +24 -2
  20. package/esm/automation/private/StrategiesAutomation.d.ts +5 -1
  21. package/esm/automation/private/StrategiesAutomation.js +12 -0
  22. package/esm/automation/private/StrategiesAutomation.test.js +51 -0
  23. package/esm/constants/index.js +40 -40
  24. package/esm/services/apiSubscriptionsService.d.ts +7 -0
  25. package/esm/services/apiSubscriptionsService.js +29 -0
  26. package/esm/services/apiSubscriptionsService.test.d.ts +1 -0
  27. package/esm/services/apiSubscriptionsService.test.js +65 -0
  28. package/esm/services/strategiesService.js +8 -21
  29. package/esm/services/strategiesService.test.js +1 -64
  30. package/esm/services/strategySubService.d.ts +1 -1
  31. package/esm/services/strategySubService.js +6 -7
  32. package/esm/services/strategySubService.test.js +71 -111
  33. package/esm/services/subDataService.d.ts +10 -12
  34. package/esm/services/subDataService.js +29 -35
  35. package/esm/services/subDataService.test.js +104 -70
  36. package/esm/types/enums.d.ts +18 -18
  37. package/esm/types/enums.js +10 -11
  38. package/esm/types/index.d.ts +24 -2
  39. package/package.json +1 -1
  40. package/src/automation/private/StrategiesAutomation.test.ts +65 -1
  41. package/src/automation/private/StrategiesAutomation.ts +17 -0
  42. package/src/constants/index.ts +40 -40
  43. package/src/services/apiSubscriptionsService.test.ts +73 -0
  44. package/src/services/apiSubscriptionsService.ts +33 -0
  45. package/src/services/strategiesService.test.ts +1 -79
  46. package/src/services/strategiesService.ts +8 -27
  47. package/src/services/strategySubService.test.ts +84 -125
  48. package/src/services/strategySubService.ts +16 -20
  49. package/src/services/subDataService.test.ts +108 -98
  50. package/src/services/subDataService.ts +40 -51
  51. package/src/types/enums.ts +10 -11
  52. package/src/types/index.ts +26 -2
@@ -164,19 +164,18 @@ export const aaveV3Encode = {
164
164
  const triggerDataEncoded = triggerService.aaveV3QuotePriceRangeTrigger.encode(collAsset, debtAsset, stopLossPrice, takeProfitPrice);
165
165
  return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
166
166
  },
167
- instantCloseOnPriceGeneric(strategyOrBundleId, collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, user, tsi, slippage, stopLossPrice = 0, stopLossType = CloseToAssetType.DEBT, takeProfitPrice = 0, takeProfitType = CloseToAssetType.COLLATERAL) {
168
- const isBundle = true;
169
- const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
170
- const subDataEncoded = subDataService.aaveV3InstantCloseGenericSubData.encode(collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, user, tsi, slippage);
171
- const triggerDataEncoded = triggerService.aaveV3QuotePriceRangeTrigger.encode(collAsset, debtAsset, stopLossPrice, takeProfitPrice);
172
- return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
173
- },
174
167
  collateralSwitch(strategyOrBundleId, fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, baseTokenAddress, quoteTokenAddress, price, state) {
175
168
  const isBundle = false;
176
169
  const subDataEncoded = subDataService.aaveV3CollateralSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch);
177
170
  const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
178
171
  return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
179
172
  },
173
+ debtSwitch(strategyOrBundleId, fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user, baseTokenAddress, quoteTokenAddress, price, state) {
174
+ const isBundle = false;
175
+ const subDataEncoded = subDataService.aaveV3DebtSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user);
176
+ const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
177
+ return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
178
+ },
180
179
  };
181
180
  export const compoundV2Encode = {
182
181
  leverageManagement(strategyOrBundleId, user, ratioState, targetRatio, triggerRatio) {
@@ -732,117 +732,6 @@ describe('Feature: strategySubService.ts', () => {
732
732
  });
733
733
  });
734
734
  });
735
- describe('instantCloseOnPriceGeneric()', () => {
736
- const examples = [
737
- // Stop loss only (to debt)
738
- [
739
- [
740
- Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
741
- true,
742
- ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000000000000000'],
743
- [
744
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
745
- '0x0000000000000000000000000000000000000000000000000000000000000000',
746
- '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
747
- '0x0000000000000000000000000000000000000000000000000000000000000001',
748
- '0x0000000000000000000000000000000000000000000000000000000000000003',
749
- '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
750
- '0x0000000000000000000000001234567890123456789012345678901234567890',
751
- '0x0000000000000000000000000000000000000000000000000de0b6b3a7640000',
752
- '0x000000000000000000000000000000000000000000000000002386f26fc10000',
753
- ],
754
- ],
755
- [
756
- Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
757
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
758
- 0,
759
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
760
- 1,
761
- web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
762
- web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
763
- '1000000000000000000',
764
- '10000000000000000',
765
- 1500,
766
- CloseToAssetType.DEBT,
767
- 0,
768
- CloseToAssetType.COLLATERAL, // takeProfitType (not used since price is 0)
769
- ]
770
- ],
771
- // Take profit only (to collateral), zero tsi and slippage
772
- [
773
- [
774
- Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
775
- true,
776
- ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
777
- [
778
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
779
- '0x0000000000000000000000000000000000000000000000000000000000000000',
780
- '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
781
- '0x0000000000000000000000000000000000000000000000000000000000000001',
782
- '0x0000000000000000000000000000000000000000000000000000000000000000',
783
- '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
784
- '0x0000000000000000000000001234567890123456789012345678901234567890',
785
- '0x0000000000000000000000000000000000000000000000000000000000000000',
786
- '0x0000000000000000000000000000000000000000000000000000000000000000',
787
- ],
788
- ],
789
- [
790
- Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
791
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
792
- 0,
793
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
794
- 1,
795
- web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
796
- web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
797
- '0',
798
- '0',
799
- 0,
800
- CloseToAssetType.DEBT,
801
- 5000,
802
- CloseToAssetType.COLLATERAL, // takeProfitType
803
- ]
804
- ],
805
- // Take profit (to debt) and stop loss (to collateral)
806
- [
807
- [
808
- Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
809
- true,
810
- ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
811
- [
812
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
813
- '0x0000000000000000000000000000000000000000000000000000000000000000',
814
- '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
815
- '0x0000000000000000000000000000000000000000000000000000000000000001',
816
- '0x0000000000000000000000000000000000000000000000000000000000000007',
817
- '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
818
- '0x0000000000000000000000001234567890123456789012345678901234567890',
819
- '0x00000000000000000000000000000000000000000000000000b1a2bc2ec50000',
820
- '0x0000000000000000000000000000000000000000000000000011c37937e08000',
821
- ],
822
- ],
823
- [
824
- Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
825
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
826
- 0,
827
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
828
- 1,
829
- web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
830
- web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
831
- '50000000000000000',
832
- '5000000000000000',
833
- 1500,
834
- CloseToAssetType.COLLATERAL,
835
- 4000,
836
- CloseToAssetType.DEBT, // takeProfitType
837
- ]
838
- ],
839
- ];
840
- examples.forEach(([expected, actual]) => {
841
- it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
842
- expect(aaveV3Encode.instantCloseOnPriceGeneric(...actual)).to.eql(expected);
843
- });
844
- });
845
- });
846
735
  describe('collateralSwitch()', () => {
847
736
  const examples = [
848
737
  // WETH -> USDC, price 100000, state UNDER
@@ -942,6 +831,77 @@ describe('Feature: strategySubService.ts', () => {
942
831
  });
943
832
  });
944
833
  });
834
+ describe('debtSwitch()', () => {
835
+ const examples = [
836
+ // USDC -> DAI, price 100000, state UNDER
837
+ [
838
+ [
839
+ Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
840
+ false,
841
+ ['0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000000000000009184e72a0000000000000000000000000000000000000000000000000000000000000000001'],
842
+ [
843
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
844
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
845
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
846
+ '0x0000000000000000000000000000000000000000000000000000000000000003',
847
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
848
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
849
+ '0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
850
+ ],
851
+ ],
852
+ [
853
+ Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
854
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
855
+ 1,
856
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
857
+ 3,
858
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
859
+ '10000000000000000000',
860
+ web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
861
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
862
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
863
+ 100000,
864
+ RatioState.UNDER,
865
+ ]
866
+ ],
867
+ // DAI -> USDC (MaxUint256), price 1, state OVER
868
+ [
869
+ [
870
+ Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
871
+ false,
872
+ ['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000005f5e1000000000000000000000000000000000000000000000000000000000000000000'],
873
+ [
874
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
875
+ '0x0000000000000000000000000000000000000000000000000000000000000003',
876
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
877
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
878
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
879
+ '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
880
+ '0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
881
+ ],
882
+ ],
883
+ [
884
+ Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
885
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
886
+ 3,
887
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
888
+ 1,
889
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
890
+ MAXUINT,
891
+ web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
892
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
893
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
894
+ 1,
895
+ RatioState.OVER,
896
+ ]
897
+ ],
898
+ ];
899
+ examples.forEach(([expected, actual]) => {
900
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
901
+ expect(aaveV3Encode.debtSwitch(...actual)).to.eql(expected);
902
+ });
903
+ });
904
+ });
945
905
  });
946
906
  describe('When testing strategySubService.compoundV3Encode', () => {
947
907
  describe('leverageManagementOnPrice()', () => {
@@ -248,22 +248,19 @@ export declare const aaveV3CloseGenericSubData: {
248
248
  owner: EthereumAddress;
249
249
  };
250
250
  };
251
- export declare const aaveV3InstantCloseGenericSubData: {
252
- encode(collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, closeType: CloseStrategyType, marketAddr: EthereumAddress, user: EthereumAddress, tsi: string, slippage: string): string[];
251
+ export declare const aaveV3CollateralSwitchSubData: {
252
+ encode(fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, useOnBehalf?: boolean): string[];
253
253
  decode(subData: string[]): {
254
- collAsset: EthereumAddress;
255
- collAssetId: number;
256
- debtAsset: EthereumAddress;
257
- debtAssetId: number;
258
- closeType: CloseStrategyType;
254
+ fromAsset: EthereumAddress;
255
+ fromAssetId: number;
256
+ toAsset: EthereumAddress;
257
+ toAssetId: number;
259
258
  marketAddr: EthereumAddress;
260
- owner: EthereumAddress;
261
- tsi: string;
262
- slippage: string;
259
+ amountToSwitch: string;
263
260
  };
264
261
  };
265
- export declare const aaveV3CollateralSwitchSubData: {
266
- encode(fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, useOnBehalf?: boolean): string[];
262
+ export declare const aaveV3DebtSwitchSubData: {
263
+ encode(fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, user: EthereumAddress): string[];
267
264
  decode(subData: string[]): {
268
265
  fromAsset: EthereumAddress;
269
266
  fromAssetId: number;
@@ -271,6 +268,7 @@ export declare const aaveV3CollateralSwitchSubData: {
271
268
  toAssetId: number;
272
269
  marketAddr: EthereumAddress;
273
270
  amountToSwitch: string;
271
+ user: EthereumAddress;
274
272
  };
275
273
  };
276
274
  export declare const aaveV3QuotePriceSubData: {
@@ -511,53 +511,46 @@ export const aaveV3CloseGenericSubData = {
511
511
  };
512
512
  },
513
513
  };
514
- export const aaveV3InstantCloseGenericSubData = {
515
- encode(collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, user, tsi, slippage) {
516
- const encodedColl = AbiCoder.encodeParameter('address', collAsset);
517
- const encodedCollId = AbiCoder.encodeParameter('uint16', collAssetId);
518
- const encodedDebt = AbiCoder.encodeParameter('address', debtAsset);
519
- const encodedDebtId = AbiCoder.encodeParameter('uint16', debtAssetId);
520
- const encodedCloseType = AbiCoder.encodeParameter('uint8', closeType);
521
- const encodedMarket = AbiCoder.encodeParameter('address', marketAddr);
522
- const encodedUser = AbiCoder.encodeParameter('address', user);
523
- const encodedTsi = AbiCoder.encodeParameter('uint256', tsi);
524
- const encodedSlippage = AbiCoder.encodeParameter('uint256', slippage);
514
+ export const aaveV3CollateralSwitchSubData = {
515
+ encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, useOnBehalf = false) {
516
+ const encodedFromAsset = AbiCoder.encodeParameter('address', fromAsset);
517
+ const encodedFromAssetId = AbiCoder.encodeParameter('uint8', fromAssetId);
518
+ const encodedToAsset = AbiCoder.encodeParameter('address', toAsset);
519
+ const encodedToAssetId = AbiCoder.encodeParameter('uint8', toAssetId);
520
+ const encodedMarketAddr = AbiCoder.encodeParameter('address', marketAddr);
521
+ const encodedAmountToSwitch = AbiCoder.encodeParameter('uint256', amountToSwitch);
522
+ const encodedUseOnBehalf = AbiCoder.encodeParameter('bool', useOnBehalf);
525
523
  return [
526
- encodedColl,
527
- encodedCollId,
528
- encodedDebt,
529
- encodedDebtId,
530
- encodedCloseType,
531
- encodedMarket,
532
- encodedUser,
533
- encodedTsi,
534
- encodedSlippage,
524
+ encodedFromAsset,
525
+ encodedFromAssetId,
526
+ encodedToAsset,
527
+ encodedToAssetId,
528
+ encodedMarketAddr,
529
+ encodedAmountToSwitch,
530
+ encodedUseOnBehalf,
535
531
  ];
536
532
  },
537
533
  decode(subData) {
538
- const collAsset = AbiCoder.decodeParameter('address', subData[0]);
539
- const collAssetId = Number(AbiCoder.decodeParameter('uint16', subData[1]));
540
- const debtAsset = AbiCoder.decodeParameter('address', subData[2]);
541
- const debtAssetId = Number(AbiCoder.decodeParameter('uint16', subData[3]));
542
- const closeType = Number(AbiCoder.decodeParameter('uint8', subData[4]));
543
- const marketAddr = AbiCoder.decodeParameter('address', subData[5]);
544
- const owner = AbiCoder.decodeParameter('address', subData[6]);
545
- const tsi = AbiCoder.decodeParameter('uint256', subData[7]);
546
- const slippage = AbiCoder.decodeParameter('uint256', subData[8]);
534
+ const fromAsset = AbiCoder.decodeParameter('address', subData[0]);
535
+ const fromAssetId = Number(AbiCoder.decodeParameter('uint8', subData[1]));
536
+ const toAsset = AbiCoder.decodeParameter('address', subData[2]);
537
+ const toAssetId = Number(AbiCoder.decodeParameter('uint8', subData[3]));
538
+ const marketAddr = AbiCoder.decodeParameter('address', subData[4]);
539
+ const amountToSwitch = AbiCoder.decodeParameter('uint256', subData[5]);
547
540
  return {
548
- collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, owner, tsi, slippage,
541
+ fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch,
549
542
  };
550
543
  },
551
544
  };
552
- export const aaveV3CollateralSwitchSubData = {
553
- encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, useOnBehalf = false) {
545
+ export const aaveV3DebtSwitchSubData = {
546
+ encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user) {
554
547
  const encodedFromAsset = AbiCoder.encodeParameter('address', fromAsset);
555
548
  const encodedFromAssetId = AbiCoder.encodeParameter('uint8', fromAssetId);
556
549
  const encodedToAsset = AbiCoder.encodeParameter('address', toAsset);
557
550
  const encodedToAssetId = AbiCoder.encodeParameter('uint8', toAssetId);
558
551
  const encodedMarketAddr = AbiCoder.encodeParameter('address', marketAddr);
559
552
  const encodedAmountToSwitch = AbiCoder.encodeParameter('uint256', amountToSwitch);
560
- const encodedUseOnBehalf = AbiCoder.encodeParameter('bool', useOnBehalf);
553
+ const encodedUser = AbiCoder.encodeParameter('address', user);
561
554
  return [
562
555
  encodedFromAsset,
563
556
  encodedFromAssetId,
@@ -565,7 +558,7 @@ export const aaveV3CollateralSwitchSubData = {
565
558
  encodedToAssetId,
566
559
  encodedMarketAddr,
567
560
  encodedAmountToSwitch,
568
- encodedUseOnBehalf,
561
+ encodedUser,
569
562
  ];
570
563
  },
571
564
  decode(subData) {
@@ -575,8 +568,9 @@ export const aaveV3CollateralSwitchSubData = {
575
568
  const toAssetId = Number(AbiCoder.decodeParameter('uint8', subData[3]));
576
569
  const marketAddr = AbiCoder.decodeParameter('address', subData[4]);
577
570
  const amountToSwitch = AbiCoder.decodeParameter('uint256', subData[5]);
571
+ const user = AbiCoder.decodeParameter('address', subData[6]);
578
572
  return {
579
- fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch,
573
+ fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user,
580
574
  };
581
575
  },
582
576
  };
@@ -510,6 +510,110 @@ describe('Feature: subDataService.ts', () => {
510
510
  });
511
511
  });
512
512
  });
513
+ describe('When testing subDataService.aaveV3DebtSwitchSubData', () => {
514
+ describe('encode()', () => {
515
+ const examples = [
516
+ // USDC -> DAI
517
+ [
518
+ [
519
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
520
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
521
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
522
+ '0x0000000000000000000000000000000000000000000000000000000000000003',
523
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
524
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
525
+ '0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
526
+ ],
527
+ [
528
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
529
+ 1,
530
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
531
+ 3,
532
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
533
+ '10000000000000000000',
534
+ web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
535
+ ]
536
+ ],
537
+ // DAI -> USDC (MaxUint256)
538
+ [
539
+ [
540
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
541
+ '0x0000000000000000000000000000000000000000000000000000000000000003',
542
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
543
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
544
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
545
+ '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
546
+ '0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
547
+ ],
548
+ [
549
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
550
+ 3,
551
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
552
+ 1,
553
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
554
+ MAXUINT,
555
+ web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
556
+ ]
557
+ ],
558
+ ];
559
+ examples.forEach(([expected, actual]) => {
560
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
561
+ expect(subDataService.aaveV3DebtSwitchSubData.encode(...actual)).to.eql(expected);
562
+ });
563
+ });
564
+ });
565
+ describe('decode()', () => {
566
+ const examples = [
567
+ // USDC -> DAI
568
+ [
569
+ {
570
+ fromAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
571
+ fromAssetId: 1,
572
+ toAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
573
+ toAssetId: 3,
574
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
575
+ amountToSwitch: '10000000000000000000',
576
+ user: web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
577
+ },
578
+ [
579
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
580
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
581
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
582
+ '0x0000000000000000000000000000000000000000000000000000000000000003',
583
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
584
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
585
+ '0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
586
+ ],
587
+ ],
588
+ // DAI -> USDC (MaxUint256)
589
+ [
590
+ {
591
+ fromAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
592
+ fromAssetId: 3,
593
+ toAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
594
+ toAssetId: 1,
595
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
596
+ amountToSwitch: MAXUINT,
597
+ user: web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
598
+ },
599
+ [
600
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
601
+ '0x0000000000000000000000000000000000000000000000000000000000000003',
602
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
603
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
604
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
605
+ '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
606
+ '0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
607
+ ],
608
+ ],
609
+ ];
610
+ examples.forEach(([expected, actual]) => {
611
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
612
+ expect(subDataService.aaveV3DebtSwitchSubData.decode(actual)).to.eql(expected);
613
+ });
614
+ });
615
+ });
616
+ });
513
617
  describe('When testing subDataService.sparkCollateralSwitchSubData', () => {
514
618
  describe('encode()', () => {
515
619
  const examples = [
@@ -2256,76 +2360,6 @@ describe('Feature: subDataService.ts', () => {
2256
2360
  });
2257
2361
  });
2258
2362
  });
2259
- describe("When testing subDataService.aaveV3InstantCloseGenericSubData", () => {
2260
- const WETH = web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address);
2261
- const USDC = web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address);
2262
- const MARKET = web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39');
2263
- const USER = web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890');
2264
- const examples = [
2265
- // TAKE_PROFIT_IN_COLLATERAL, zero tsi and slippage
2266
- [
2267
- [
2268
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
2269
- '0x0000000000000000000000000000000000000000000000000000000000000000',
2270
- '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
2271
- '0x0000000000000000000000000000000000000000000000000000000000000001',
2272
- '0x0000000000000000000000000000000000000000000000000000000000000000',
2273
- '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
2274
- '0x0000000000000000000000001234567890123456789012345678901234567890',
2275
- '0x0000000000000000000000000000000000000000000000000000000000000000',
2276
- '0x0000000000000000000000000000000000000000000000000000000000000000',
2277
- ],
2278
- [WETH, 0, USDC, 1, CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL, MARKET, USER, '0', '0'],
2279
- ],
2280
- // STOP_LOSS_IN_DEBT
2281
- [
2282
- [
2283
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
2284
- '0x0000000000000000000000000000000000000000000000000000000000000000',
2285
- '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
2286
- '0x0000000000000000000000000000000000000000000000000000000000000001',
2287
- '0x0000000000000000000000000000000000000000000000000000000000000003',
2288
- '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
2289
- '0x0000000000000000000000001234567890123456789012345678901234567890',
2290
- '0x0000000000000000000000000000000000000000000000000de0b6b3a7640000',
2291
- '0x000000000000000000000000000000000000000000000000002386f26fc10000',
2292
- ],
2293
- [WETH, 0, USDC, 1, CloseStrategyType.STOP_LOSS_IN_DEBT, MARKET, USER, '1000000000000000000', '10000000000000000'],
2294
- ],
2295
- // TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL, asset ids above uint8 range
2296
- [
2297
- [
2298
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
2299
- '0x000000000000000000000000000000000000000000000000000000000000012c',
2300
- '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
2301
- '0x0000000000000000000000000000000000000000000000000000000000000190',
2302
- '0x0000000000000000000000000000000000000000000000000000000000000007',
2303
- '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
2304
- '0x0000000000000000000000001234567890123456789012345678901234567890',
2305
- '0x00000000000000000000000000000000000000000000000000b1a2bc2ec50000',
2306
- '0x0000000000000000000000000000000000000000000000000011c37937e08000',
2307
- ],
2308
- [WETH, 300, USDC, 400, CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL, MARKET, USER, '50000000000000000', '5000000000000000'],
2309
- ],
2310
- ];
2311
- describe("encode()", () => {
2312
- examples.forEach(([expected, actual]) => {
2313
- it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2314
- expect(subDataService.aaveV3InstantCloseGenericSubData.encode(...actual)).to.eql(expected);
2315
- });
2316
- });
2317
- });
2318
- describe("decode()", () => {
2319
- examples.forEach(([encoded, [collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, user, tsi, slippage]]) => {
2320
- const expected = {
2321
- collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, owner: user, tsi, slippage,
2322
- };
2323
- it(`Given ${JSON.stringify(encoded)} should return expected value: ${JSON.stringify(expected)}`, () => {
2324
- expect(subDataService.aaveV3InstantCloseGenericSubData.decode(encoded)).to.eql(expected);
2325
- });
2326
- });
2327
- });
2328
- });
2329
2363
  describe('When testing subDataService.sparkLeverageManagementOnPriceSubData', () => {
2330
2364
  describe('encode()', () => {
2331
2365
  const examples = [
@@ -91,22 +91,30 @@ export declare namespace Strategies {
91
91
  AAVE_V4_COLLATERAL_SWITCH = 154,
92
92
  AAVE_V4_COLLATERAL_SWITCH_EOA = 155,
93
93
  SPARK_COLLATERAL_SWITCH = 156,
94
- SPARK_GENERIC_FL_COLLATERAL_SWITCH = 167
94
+ SPARK_GENERIC_FL_COLLATERAL_SWITCH = 167,
95
+ AAVE_V3_DEBT_SWITCH = 168,
96
+ AAVE_V3_DEBT_SWITCH_EOA = 169
95
97
  }
96
98
  enum OptimismIds {
97
99
  EXCHANGE_DCA = 8,
98
100
  EXCHANGE_LIMIT_ORDER = 9,
99
- AAVE_V3_COLLATERAL_SWITCH = 24
101
+ AAVE_V3_COLLATERAL_SWITCH = 24,
102
+ AAVE_V3_DEBT_SWITCH = 25,
103
+ AAVE_V3_DEBT_SWITCH_EOA = 26
100
104
  }
101
105
  enum BaseIds {
102
106
  EXCHANGE_DCA = 8,
103
107
  EXCHANGE_LIMIT_ORDER = 9,
104
- AAVE_V3_COLLATERAL_SWITCH = 56
108
+ AAVE_V3_COLLATERAL_SWITCH = 56,
109
+ AAVE_V3_DEBT_SWITCH = 61,
110
+ AAVE_V3_DEBT_SWITCH_EOA = 62
105
111
  }
106
112
  enum ArbitrumIds {
107
113
  EXCHANGE_DCA = 8,
108
114
  EXCHANGE_LIMIT_ORDER = 9,
109
- AAVE_V3_COLLATERAL_SWITCH = 50
115
+ AAVE_V3_COLLATERAL_SWITCH = 50,
116
+ AAVE_V3_DEBT_SWITCH = 55,
117
+ AAVE_V3_DEBT_SWITCH_EOA = 56
110
118
  }
111
119
  enum Identifiers {
112
120
  SavingsLiqProtection = "smart-savings-liquidation-protection",
@@ -124,8 +132,6 @@ export declare namespace Strategies {
124
132
  CloseOnPriceToColl = "close-on-price-to-collateral",
125
133
  CloseOnPrice = "close-on-price",
126
134
  EoaCloseOnPrice = "eoa-close-on-price",
127
- InstantCloseOnPrice = "instant-close-on-price",
128
- EoaInstantCloseOnPrice = "eoa-instant-close-on-price",
129
135
  TrailingStopToColl = "trailing-stop-to-collateral",
130
136
  TrailingStopToDebt = "trailing-stop-to-debt",
131
137
  Rebond = "rebond",
@@ -142,6 +148,8 @@ export declare namespace Strategies {
142
148
  EoaRepayOnPrice = "eoa-repay-on-price",
143
149
  CollateralSwitch = "collateral-switch",
144
150
  EoaCollateralSwitch = "eoa-collateral-switch",
151
+ DebtSwitch = "debt-switch",
152
+ EoaDebtSwitch = "eoa-debt-switch",
145
153
  LiquidationProtection = "liquidation-protection",
146
154
  EoaLiquidationProtection = "liquidation-protection-eoa"
147
155
  }
@@ -252,9 +260,7 @@ export declare namespace Bundles {
252
260
  SPARK_EOA_REPAY_ON_PRICE = 90,
253
261
  SPARK_EOA_BOOST_ON_PRICE = 91,
254
262
  SPARK_EOA_CLOSE = 92,
255
- SPARK_EOA_LIQUIDATION_PROTECTION = 93,
256
- AAVE_V3_SW_INSTANT_CLOSE = 94,
257
- AAVE_V3_EOA_INSTANT_CLOSE = 95
263
+ SPARK_EOA_LIQUIDATION_PROTECTION = 93
258
264
  }
259
265
  enum OptimismIds {
260
266
  AAVE_V3_REPAY = 0,
@@ -269,9 +275,7 @@ export declare namespace Bundles {
269
275
  AAVE_V3_EOA_BOOST_ON_PRICE = 9,
270
276
  AAVE_V3_EOA_CLOSE = 10,
271
277
  AAVE_V3_SW_LIQUIDATION_PROTECTION = 11,
272
- AAVE_V3_EOA_LIQUIDATION_PROTECTION = 12,
273
- AAVE_V3_SW_INSTANT_CLOSE = 13,
274
- AAVE_V3_EOA_INSTANT_CLOSE = 14
278
+ AAVE_V3_EOA_LIQUIDATION_PROTECTION = 12
275
279
  }
276
280
  enum BaseIds {
277
281
  AAVE_V3_REPAY = 0,
@@ -313,9 +317,7 @@ export declare namespace Bundles {
313
317
  MORPHO_BLUE_EOA_BOOST_ON_PRICE = 39,
314
318
  MORPHO_BLUE_EOA_REPAY_ON_PRICE = 40,
315
319
  MORPHO_BLUE_EOA_CLOSE = 41,
316
- MORPHO_BLUE_EOA_LIQUIDATION_PROTECTION = 42,
317
- AAVE_V3_SW_INSTANT_CLOSE = 43,
318
- AAVE_V3_EOA_INSTANT_CLOSE = 44
320
+ MORPHO_BLUE_EOA_LIQUIDATION_PROTECTION = 42
319
321
  }
320
322
  enum ArbitrumIds {
321
323
  AAVE_V3_REPAY = 0,
@@ -357,8 +359,6 @@ export declare namespace Bundles {
357
359
  MORPHO_BLUE_REPAY_ON_PRICE = 36,
358
360
  MORPHO_BLUE_EOA_BOOST_ON_PRICE = 37,
359
361
  MORPHO_BLUE_EOA_REPAY_ON_PRICE = 38,
360
- MORPHO_BLUE_EOA_CLOSE = 39,
361
- AAVE_V3_SW_INSTANT_CLOSE = 40,
362
- AAVE_V3_EOA_INSTANT_CLOSE = 41
362
+ MORPHO_BLUE_EOA_CLOSE = 39
363
363
  }
364
364
  }