@defisaver/automation-sdk 3.3.2-dev → 3.3.2-dev.0

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 (45) hide show
  1. package/cjs/constants/index.js +100 -5
  2. package/cjs/index.d.ts +2 -1
  3. package/cjs/index.js +1 -1
  4. package/cjs/services/strategiesService.js +28 -27
  5. package/cjs/services/strategySubService.d.ts +3 -2
  6. package/cjs/services/strategySubService.js +15 -9
  7. package/cjs/services/strategySubService.test.js +314 -0
  8. package/cjs/services/subDataService.d.ts +25 -9
  9. package/cjs/services/subDataService.js +78 -26
  10. package/cjs/services/subDataService.test.js +456 -0
  11. package/cjs/services/triggerService.d.ts +6 -6
  12. package/cjs/services/triggerService.js +14 -11
  13. package/cjs/services/triggerService.test.js +46 -0
  14. package/cjs/types/enums.d.ts +26 -8
  15. package/cjs/types/enums.js +21 -2
  16. package/cjs/types/index.d.ts +1 -8
  17. package/esm/constants/index.js +100 -5
  18. package/esm/index.d.ts +2 -1
  19. package/esm/index.js +2 -2
  20. package/esm/services/strategiesService.js +28 -27
  21. package/esm/services/strategySubService.d.ts +3 -2
  22. package/esm/services/strategySubService.js +15 -9
  23. package/esm/services/strategySubService.test.js +314 -0
  24. package/esm/services/subDataService.d.ts +25 -9
  25. package/esm/services/subDataService.js +77 -25
  26. package/esm/services/subDataService.test.js +456 -0
  27. package/esm/services/triggerService.d.ts +6 -6
  28. package/esm/services/triggerService.js +13 -10
  29. package/esm/services/triggerService.test.js +47 -1
  30. package/esm/types/enums.d.ts +26 -8
  31. package/esm/types/enums.js +21 -2
  32. package/esm/types/index.d.ts +1 -8
  33. package/package.json +2 -2
  34. package/src/constants/index.ts +103 -5
  35. package/src/index.ts +4 -2
  36. package/src/services/strategiesService.ts +31 -37
  37. package/src/services/strategySubService.test.ts +347 -0
  38. package/src/services/strategySubService.ts +57 -20
  39. package/src/services/subDataService.test.ts +532 -0
  40. package/src/services/subDataService.ts +122 -33
  41. package/src/services/triggerService.test.ts +50 -0
  42. package/src/services/triggerService.ts +21 -14
  43. package/src/types/enums.ts +21 -2
  44. package/src/types/index.ts +20 -9
  45. package/umd/index.js +0 -34219
@@ -618,6 +618,353 @@ describe('Feature: strategySubService.ts', () => {
618
618
  });
619
619
  });
620
620
  });
621
+
622
+ describe('leverageManagementOnPriceGeneric()', () => {
623
+ const examples: Array<[
624
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
625
+ [
626
+ strategyOrBundleId: number,
627
+ price: number,
628
+ ratioState: RatioState,
629
+ collAsset: EthereumAddress,
630
+ collAssetId: number,
631
+ debtAsset: EthereumAddress,
632
+ debtAssetId: number,
633
+ marketAddr: EthereumAddress,
634
+ targetRatio: number,
635
+ user: EthereumAddress
636
+ ]
637
+ ]> = [
638
+ [
639
+ [
640
+ Bundles.MainnetIds.AAVE_V3_EOA_REPAY_ON_PRICE,
641
+ true,
642
+ ['0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000026e1f9c6000000000000000000000000000000000000000000000000000000000000000001'],
643
+ [
644
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
645
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
646
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
647
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
648
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
649
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
650
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
651
+ ],
652
+ ],
653
+ [
654
+ Bundles.MainnetIds.AAVE_V3_EOA_REPAY_ON_PRICE,
655
+ 1670,
656
+ RatioState.UNDER,
657
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
658
+ 0,
659
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
660
+ 1,
661
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
662
+ 200,
663
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
664
+ ]
665
+ ],
666
+ [
667
+ [
668
+ Bundles.MainnetIds.AAVE_V3_EOA_BOOST_ON_PRICE,
669
+ true,
670
+ ['0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000002faf0800000000000000000000000000000000000000000000000000000000000000000'],
671
+ [
672
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
673
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
674
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
675
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
676
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
677
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
678
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
679
+ ],
680
+ ],
681
+ [
682
+ Bundles.MainnetIds.AAVE_V3_EOA_BOOST_ON_PRICE,
683
+ 0.5,
684
+ RatioState.OVER,
685
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
686
+ 2,
687
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
688
+ 1,
689
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
690
+ 200,
691
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
692
+ ]
693
+ ],
694
+ ];
695
+
696
+ examples.forEach(([expected, actual]) => {
697
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
698
+ expect(aaveV3Encode.leverageManagementOnPriceGeneric(...actual)).to.eql(expected);
699
+ });
700
+ });
701
+ });
702
+
703
+ describe('closeOnPriceGeneric()', () => {
704
+ const examples: Array<[
705
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
706
+ [
707
+ strategyOrBundleId: number,
708
+ collAsset: EthereumAddress,
709
+ collAssetId: number,
710
+ debtAsset: EthereumAddress,
711
+ debtAssetId: number,
712
+ marketAddr: EthereumAddress,
713
+ user: EthereumAddress,
714
+ stopLossPrice: number,
715
+ stopLossType: CloseToAssetType,
716
+ takeProfitPrice: number,
717
+ takeProfitType: CloseToAssetType
718
+ ]
719
+ ]> = [
720
+ // Stop loss only (to debt)
721
+ [
722
+ [
723
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
724
+ true,
725
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000000000000000'],
726
+ [
727
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
728
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
729
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
730
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
731
+ '0x0000000000000000000000000000000000000000000000000000000000000003',
732
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
733
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
734
+ ],
735
+ ],
736
+ [
737
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
738
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
739
+ 0,
740
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
741
+ 1,
742
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
743
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
744
+ 1500, // stopLossPrice
745
+ CloseToAssetType.DEBT, // stopLossType
746
+ 0, // takeProfitPrice
747
+ CloseToAssetType.COLLATERAL, // takeProfitType (not used since price is 0)
748
+ ]
749
+ ],
750
+ // Take profit only (to collateral)
751
+ [
752
+ [
753
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
754
+ true,
755
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
756
+ [
757
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
758
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
759
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
760
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
761
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
762
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
763
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
764
+ ],
765
+ ],
766
+ [
767
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
768
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
769
+ 0,
770
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
771
+ 1,
772
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
773
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
774
+ 0, // stopLossPrice
775
+ CloseToAssetType.DEBT, // stopLossType (not used since price is 0)
776
+ 5000, // takeProfitPrice
777
+ CloseToAssetType.COLLATERAL, // takeProfitType
778
+ ]
779
+ ],
780
+ // Both stop loss and take profit with useOnBehalf
781
+ [
782
+ [
783
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
784
+ true,
785
+ ['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
786
+ [
787
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
788
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
789
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
790
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
791
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
792
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
793
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
794
+ ],
795
+ ],
796
+ [
797
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
798
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
799
+ 2,
800
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
801
+ 1,
802
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
803
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
804
+ 1500, // stopLossPrice
805
+ CloseToAssetType.COLLATERAL, // stopLossType
806
+ 4000, // takeProfitPrice
807
+ CloseToAssetType.COLLATERAL, // takeProfitType
808
+ ]
809
+ ],
810
+ // Stop loss only (to collateral) - CloseStrategyType.STOP_LOSS_IN_COLLATERAL
811
+ [
812
+ [
813
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
814
+ true,
815
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000000000000000'],
816
+ [
817
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
818
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
819
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
820
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
821
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
822
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
823
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
824
+ ],
825
+ ],
826
+ [
827
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
828
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
829
+ 0,
830
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
831
+ 1,
832
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
833
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
834
+ 1500, // stopLossPrice
835
+ CloseToAssetType.COLLATERAL, // stopLossType
836
+ 0, // takeProfitPrice
837
+ CloseToAssetType.DEBT, // takeProfitType (not used since price is 0)
838
+ ]
839
+ ],
840
+ // Take profit only (to debt) - CloseStrategyType.TAKE_PROFIT_IN_DEBT
841
+ [
842
+ [
843
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
844
+ true,
845
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
846
+ [
847
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
848
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
849
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
850
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
851
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
852
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
853
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
854
+ ],
855
+ ],
856
+ [
857
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
858
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
859
+ 0,
860
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
861
+ 1,
862
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
863
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
864
+ 0, // stopLossPrice
865
+ CloseToAssetType.COLLATERAL, // stopLossType (not used since price is 0)
866
+ 5000, // takeProfitPrice
867
+ CloseToAssetType.DEBT, // takeProfitType
868
+ ]
869
+ ],
870
+ // Take profit in collateral and stop loss in debt - CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT
871
+ [
872
+ [
873
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
874
+ true,
875
+ ['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
876
+ [
877
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
878
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
879
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
880
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
881
+ '0x0000000000000000000000000000000000000000000000000000000000000005',
882
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
883
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
884
+ ],
885
+ ],
886
+ [
887
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
888
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
889
+ 2,
890
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
891
+ 1,
892
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
893
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
894
+ 1500, // stopLossPrice
895
+ CloseToAssetType.DEBT, // stopLossType
896
+ 4000, // takeProfitPrice
897
+ CloseToAssetType.COLLATERAL, // takeProfitType
898
+ ]
899
+ ],
900
+ // Both stop loss and take profit in debt - CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT
901
+ [
902
+ [
903
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
904
+ true,
905
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
906
+ [
907
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
908
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
909
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
910
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
911
+ '0x0000000000000000000000000000000000000000000000000000000000000006',
912
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
913
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
914
+ ],
915
+ ],
916
+ [
917
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
918
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
919
+ 0,
920
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
921
+ 1,
922
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
923
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
924
+ 1500, // stopLossPrice
925
+ CloseToAssetType.DEBT, // stopLossType
926
+ 4000, // takeProfitPrice
927
+ CloseToAssetType.DEBT, // takeProfitType
928
+ ]
929
+ ],
930
+ // Take profit in debt and stop loss in collateral - CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL
931
+ [
932
+ [
933
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
934
+ true,
935
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
936
+ [
937
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
938
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
939
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
940
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
941
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
942
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
943
+ '0x0000000000000000000000009876543210987654321098765432109876543210',
944
+ ],
945
+ ],
946
+ [
947
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
948
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
949
+ 0,
950
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
951
+ 1,
952
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
953
+ web3Utils.toChecksumAddress('0x9876543210987654321098765432109876543210'),
954
+ 1500, // stopLossPrice
955
+ CloseToAssetType.COLLATERAL, // stopLossType
956
+ 4000, // takeProfitPrice
957
+ CloseToAssetType.DEBT, // takeProfitType
958
+ ]
959
+ ],
960
+ ];
961
+
962
+ examples.forEach(([expected, actual]) => {
963
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
964
+ expect(aaveV3Encode.closeOnPriceGeneric(...actual)).to.eql(expected);
965
+ });
966
+ });
967
+ });
621
968
  });
622
969
 
623
970
  describe('When testing strategySubService.compoundV2Encode', () => {
@@ -330,13 +330,69 @@ export const aaveV3Encode = {
330
330
  ratioState: RatioState,
331
331
  targetRatio: number,
332
332
  triggerRatio: number,
333
+ isGeneric: boolean = false, // added later, isGeneric should be `false` for old strategies (if some are using this). For EOA should be `TRUE` !!! In the future, if we switch new SW subs to generic strategies too, then all new strategies should go with `isGeneric = true`. Old ones should stay the same
333
334
  ) {
334
335
  const isBundle = true;
335
- const subData = subDataService.aaveV3LeverageManagementSubDataWithoutSubProxy.encode(targetRatio, ratioState);
336
+
337
+ const subData = subDataService.aaveV3LeverageManagementSubDataWithoutSubProxy.encode(
338
+ targetRatio,
339
+ ratioState,
340
+ market,
341
+ user,
342
+ isGeneric,
343
+ );
336
344
  const triggerData = triggerService.aaveV3RatioTrigger.encode(user, market, triggerRatio, ratioState);
337
345
 
338
346
  return [strategyOrBundleId, isBundle, triggerData, subData];
339
347
  },
348
+
349
+ leverageManagementOnPriceGeneric(
350
+ strategyOrBundleId: number,
351
+ price: number,
352
+ ratioState: RatioState,
353
+ collAsset: EthereumAddress,
354
+ collAssetId: number,
355
+ debtAsset: EthereumAddress,
356
+ debtAssetId: number,
357
+ marketAddr: EthereumAddress,
358
+ targetRatio: number,
359
+ user: EthereumAddress,
360
+ ) {
361
+ const isBundle = true;
362
+ const subDataEncoded = subDataService.aaveV3LeverageManagementOnPriceGeneric.encode(
363
+ collAsset,
364
+ collAssetId,
365
+ debtAsset,
366
+ debtAssetId,
367
+ marketAddr,
368
+ targetRatio,
369
+ user,
370
+ );
371
+ const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(collAsset, debtAsset, price, ratioState);
372
+ return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
373
+ },
374
+
375
+ closeOnPriceGeneric(
376
+ strategyOrBundleId: number,
377
+ collAsset: EthereumAddress,
378
+ collAssetId: number,
379
+ debtAsset: EthereumAddress,
380
+ debtAssetId: number,
381
+ marketAddr: EthereumAddress,
382
+ user: EthereumAddress,
383
+ stopLossPrice: number = 0,
384
+ stopLossType: CloseToAssetType = CloseToAssetType.DEBT,
385
+ takeProfitPrice: number = 0,
386
+ takeProfitType: CloseToAssetType = CloseToAssetType.COLLATERAL,
387
+ ) {
388
+ const isBundle = true;
389
+ const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
390
+
391
+ const subDataEncoded = subDataService.aaveV3CloseGenericSubData.encode(collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, user);
392
+ const triggerDataEncoded = triggerService.aaveV3QuotePriceRangeTrigger.encode(collAsset, debtAsset, stopLossPrice, takeProfitPrice);
393
+
394
+ return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
395
+ },
340
396
  };
341
397
 
342
398
  export const compoundV2Encode = {
@@ -663,25 +719,6 @@ export const liquityV2Encode = {
663
719
  const subData = subDataService.liquityV2PaybackSubData.encode(market, troveId, boldToken, targetRatio, ratioState);
664
720
  const triggerData = triggerService.liquityV2RatioTrigger.encode(market, troveId, triggerRatio, ratioState);
665
721
 
666
- return [strategyId, isBundle, triggerData, subData];
667
- },
668
- interestRateAdjustment(
669
- market: EthereumAddress,
670
- troveId: string,
671
- criticalDebtInFrontLimit: string,
672
- nonCriticalDebtInFrontLimit: string,
673
- interestRateChange: string,
674
- ) {
675
- const strategyId = Strategies.MainnetIds.LIQUITY_V2_INTEREST_RATE_ADJUSTMENT;
676
- const isBundle = false;
677
-
678
- const subData = subDataService.liquityV2InterestRateAdjustmentSubData.encode(
679
- market,
680
- troveId,
681
- interestRateChange,
682
- );
683
- const triggerData = triggerService.liquityV2InterestRateAdjustmentTrigger.encode(market, troveId, criticalDebtInFrontLimit, nonCriticalDebtInFrontLimit);
684
-
685
722
  return [strategyId, isBundle, triggerData, subData];
686
723
  },
687
724
  };