@paraswap/dex-lib 2.50.6-sdai → 2.50.7-sdai

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 (113) hide show
  1. package/build/config.js +4 -2
  2. package/build/config.js.map +1 -1
  3. package/build/dex/algebra/config.js +0 -16
  4. package/build/dex/algebra/config.js.map +1 -1
  5. package/build/dex/curve-v1-factory/config.js +128 -11
  6. package/build/dex/curve-v1-factory/config.js.map +1 -1
  7. package/build/dex/curve-v1-factory/curve-v1-factory.d.ts +1 -0
  8. package/build/dex/curve-v1-factory/curve-v1-factory.js +29 -17
  9. package/build/dex/curve-v1-factory/curve-v1-factory.js.map +1 -1
  10. package/build/dex/curve-v1-factory/curve-v1-pool-manager.js +1 -0
  11. package/build/dex/curve-v1-factory/curve-v1-pool-manager.js.map +1 -1
  12. package/build/dex/curve-v1-factory/price-handlers/functions/_calc_withdraw_one_coin.js +1 -0
  13. package/build/dex/curve-v1-factory/price-handlers/functions/_calc_withdraw_one_coin.js.map +1 -1
  14. package/build/dex/curve-v1-factory/price-handlers/functions/_dynamic_fee.js +4 -1
  15. package/build/dex/curve-v1-factory/price-handlers/functions/_dynamic_fee.js.map +1 -1
  16. package/build/dex/curve-v1-factory/price-handlers/functions/_rates.js +1 -0
  17. package/build/dex/curve-v1-factory/price-handlers/functions/_rates.js.map +1 -1
  18. package/build/dex/curve-v1-factory/price-handlers/functions/_xp.js +1 -0
  19. package/build/dex/curve-v1-factory/price-handlers/functions/_xp.js.map +1 -1
  20. package/build/dex/curve-v1-factory/price-handlers/functions/_xp_mem.js +1 -0
  21. package/build/dex/curve-v1-factory/price-handlers/functions/_xp_mem.js.map +1 -1
  22. package/build/dex/curve-v1-factory/price-handlers/functions/calc_token_amount.js +1 -0
  23. package/build/dex/curve-v1-factory/price-handlers/functions/calc_token_amount.js.map +1 -1
  24. package/build/dex/curve-v1-factory/price-handlers/functions/calc_withdraw_one_coin.js +1 -0
  25. package/build/dex/curve-v1-factory/price-handlers/functions/calc_withdraw_one_coin.js.map +1 -1
  26. package/build/dex/curve-v1-factory/price-handlers/functions/constants.js +10 -0
  27. package/build/dex/curve-v1-factory/price-handlers/functions/constants.js.map +1 -1
  28. package/build/dex/curve-v1-factory/price-handlers/functions/get_D.js +40 -0
  29. package/build/dex/curve-v1-factory/price-handlers/functions/get_D.js.map +1 -1
  30. package/build/dex/curve-v1-factory/price-handlers/functions/get_D_mem.js +1 -0
  31. package/build/dex/curve-v1-factory/price-handlers/functions/get_D_mem.js.map +1 -1
  32. package/build/dex/curve-v1-factory/price-handlers/functions/get_D_precisions.js +1 -0
  33. package/build/dex/curve-v1-factory/price-handlers/functions/get_D_precisions.js.map +1 -1
  34. package/build/dex/curve-v1-factory/price-handlers/functions/get_dy.js +24 -0
  35. package/build/dex/curve-v1-factory/price-handlers/functions/get_dy.js.map +1 -1
  36. package/build/dex/curve-v1-factory/price-handlers/functions/get_dy_underlying.js +1 -0
  37. package/build/dex/curve-v1-factory/price-handlers/functions/get_dy_underlying.js.map +1 -1
  38. package/build/dex/curve-v1-factory/price-handlers/functions/get_y.js +53 -0
  39. package/build/dex/curve-v1-factory/price-handlers/functions/get_y.js.map +1 -1
  40. package/build/dex/curve-v1-factory/price-handlers/functions/get_y_D.js +1 -0
  41. package/build/dex/curve-v1-factory/price-handlers/functions/get_y_D.js.map +1 -1
  42. package/build/dex/curve-v1-factory/price-handlers/functions/utils.d.ts +1 -0
  43. package/build/dex/curve-v1-factory/price-handlers/functions/utils.js +5 -1
  44. package/build/dex/curve-v1-factory/price-handlers/functions/utils.js.map +1 -1
  45. package/build/dex/curve-v1-factory/price-handlers/types.d.ts +2 -2
  46. package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.d.ts +3 -2
  47. package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.js +38 -6
  48. package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.js.map +1 -1
  49. package/build/dex/curve-v1-factory/state-polling-pools/pool-polling-base.js.map +1 -1
  50. package/build/dex/curve-v1-factory/types.d.ts +11 -2
  51. package/build/dex/curve-v1-factory/types.js +3 -0
  52. package/build/dex/curve-v1-factory/types.js.map +1 -1
  53. package/build/dex/dexalot/config.js +7 -0
  54. package/build/dex/dexalot/config.js.map +1 -1
  55. package/build/dex/hashflow/constants.d.ts +27 -0
  56. package/build/dex/hashflow/constants.js +29 -1
  57. package/build/dex/hashflow/constants.js.map +1 -1
  58. package/build/dex/hashflow/hashflow.d.ts +3 -2
  59. package/build/dex/hashflow/hashflow.js +69 -12
  60. package/build/dex/hashflow/hashflow.js.map +1 -1
  61. package/build/dex/hashflow/types.d.ts +11 -0
  62. package/build/dex/hashflow/types.js +9 -0
  63. package/build/dex/hashflow/types.js.map +1 -1
  64. package/build/dex/idex.d.ts +1 -1
  65. package/build/dex/index.d.ts +2 -2
  66. package/build/dex/pancakeswap-v3/config.js +30 -0
  67. package/build/dex/pancakeswap-v3/config.js.map +1 -1
  68. package/build/dex/pancakeswap-v3/pancakeswap-v3.js +5 -1
  69. package/build/dex/pancakeswap-v3/pancakeswap-v3.js.map +1 -1
  70. package/build/dex/woo-fi-v2/config.js +4 -4
  71. package/package.json +1 -1
  72. package/src/config.ts +4 -2
  73. package/src/dex/algebra/config.ts +0 -18
  74. package/src/dex/curve-v1-factory/config.ts +128 -11
  75. package/src/dex/curve-v1-factory/curve-v1-factory-e2e.test.ts +123 -1
  76. package/src/dex/curve-v1-factory/curve-v1-factory-integration.test.ts +392 -0
  77. package/src/dex/curve-v1-factory/curve-v1-factory.ts +61 -39
  78. package/src/dex/curve-v1-factory/curve-v1-pool-manager.ts +1 -0
  79. package/src/dex/curve-v1-factory/price-handlers/functions/_calc_withdraw_one_coin.ts +2 -0
  80. package/src/dex/curve-v1-factory/price-handlers/functions/_dynamic_fee.ts +6 -2
  81. package/src/dex/curve-v1-factory/price-handlers/functions/_rates.ts +2 -0
  82. package/src/dex/curve-v1-factory/price-handlers/functions/_xp.ts +2 -0
  83. package/src/dex/curve-v1-factory/price-handlers/functions/_xp_mem.ts +2 -0
  84. package/src/dex/curve-v1-factory/price-handlers/functions/calc_token_amount.ts +2 -0
  85. package/src/dex/curve-v1-factory/price-handlers/functions/calc_withdraw_one_coin.ts +2 -0
  86. package/src/dex/curve-v1-factory/price-handlers/functions/constants.ts +11 -0
  87. package/src/dex/curve-v1-factory/price-handlers/functions/get_D.ts +59 -1
  88. package/src/dex/curve-v1-factory/price-handlers/functions/get_D_mem.ts +2 -0
  89. package/src/dex/curve-v1-factory/price-handlers/functions/get_D_precisions.ts +2 -0
  90. package/src/dex/curve-v1-factory/price-handlers/functions/get_dy.ts +51 -0
  91. package/src/dex/curve-v1-factory/price-handlers/functions/get_dy_underlying.ts +2 -0
  92. package/src/dex/curve-v1-factory/price-handlers/functions/get_y.ts +68 -1
  93. package/src/dex/curve-v1-factory/price-handlers/functions/get_y_D.ts +2 -0
  94. package/src/dex/curve-v1-factory/price-handlers/functions/utils.ts +4 -0
  95. package/src/dex/curve-v1-factory/price-handlers/types.ts +8 -1
  96. package/src/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.ts +71 -18
  97. package/src/dex/curve-v1-factory/state-polling-pools/pool-polling-base.ts +1 -0
  98. package/src/dex/curve-v1-factory/types.ts +12 -1
  99. package/src/dex/dexalot/config.ts +7 -0
  100. package/src/dex/dexalot/dexalot-e2e.test.ts +23 -1
  101. package/src/dex/dexalot/dexalot-integration.test.ts +121 -0
  102. package/src/dex/hashflow/constants.ts +32 -0
  103. package/src/dex/hashflow/hashflow.ts +121 -19
  104. package/src/dex/hashflow/types.ts +20 -2
  105. package/src/dex/idex.ts +1 -1
  106. package/src/dex/index.ts +2 -2
  107. package/src/dex/pancakeswap-v3/config.ts +32 -0
  108. package/src/dex/pancakeswap-v3/pancakeswap-v3-e2e.test.ts +21 -0
  109. package/src/dex/pancakeswap-v3/pancakeswap-v3.ts +7 -1
  110. package/src/dex/woo-fi-v2/config.ts +4 -4
  111. package/tests/constants-e2e.ts +38 -3
  112. package/tests/utils-e2e.ts +1 -0
  113. package/src/abi/uniswap-v3/AlienBaseV3Router.abi.json +0 -52
@@ -698,4 +698,396 @@ describe('CurveV1Factory', function () {
698
698
  }
699
699
  });
700
700
  });
701
+
702
+ describe('Stable NG', () => {
703
+ describe('Mainnet', () => {
704
+ const network = Network.MAINNET;
705
+ const dexHelper = new DummyDexHelper(network);
706
+
707
+ const tokens = Tokens[network];
708
+
709
+ beforeAll(async () => {
710
+ blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
711
+ // @ts-expect-error for testing there is dummy blocknumber, but it is not
712
+ // part of the interface
713
+ dexHelper.blockManager._blockNumber = blockNumber;
714
+ console.log(
715
+ `Received blockNumber ${blockNumber} on network ${dexHelper.config.data.network}`,
716
+ );
717
+ curveV1Factory = new CurveV1Factory(network, dexKey, dexHelper);
718
+ if (curveV1Factory.initializePricing) {
719
+ await curveV1Factory.initializePricing(blockNumber);
720
+ }
721
+ });
722
+
723
+ describe('GHO -> USDe', () => {
724
+ const srcTokenSymbol = 'GHO';
725
+ const destTokenSymbol = 'USDe';
726
+ const amountsForSell = [
727
+ 0n,
728
+ 1n * BI_POWS[tokens[srcTokenSymbol].decimals],
729
+ 2n * BI_POWS[tokens[srcTokenSymbol].decimals],
730
+ 3n * BI_POWS[tokens[srcTokenSymbol].decimals],
731
+ 4n * BI_POWS[tokens[srcTokenSymbol].decimals],
732
+ 5n * BI_POWS[tokens[srcTokenSymbol].decimals],
733
+ 6n * BI_POWS[tokens[srcTokenSymbol].decimals],
734
+ 7n * BI_POWS[tokens[srcTokenSymbol].decimals],
735
+ 8n * BI_POWS[tokens[srcTokenSymbol].decimals],
736
+ 9n * BI_POWS[tokens[srcTokenSymbol].decimals],
737
+ 10n * BI_POWS[tokens[srcTokenSymbol].decimals],
738
+ ];
739
+
740
+ it('getPoolIdentifiers and getPricesVolume SELL', async function () {
741
+ await testPricingOnNetwork(
742
+ curveV1Factory,
743
+ network,
744
+ dexKey,
745
+ blockNumber,
746
+ srcTokenSymbol,
747
+ destTokenSymbol,
748
+ SwapSide.SELL,
749
+ amountsForSell,
750
+ );
751
+ });
752
+
753
+ it('getTopPoolsForToken', async function () {
754
+ // We have to check without calling initializePricing, because
755
+ // pool-tracker is not calling that function
756
+ const newCurveV1Factory = new CurveV1Factory(
757
+ network,
758
+ dexKey,
759
+ dexHelper,
760
+ );
761
+ if (newCurveV1Factory.updatePoolState) {
762
+ await newCurveV1Factory.updatePoolState();
763
+ }
764
+ const poolLiquidity = await newCurveV1Factory.getTopPoolsForToken(
765
+ tokens[srcTokenSymbol].address,
766
+ 10,
767
+ );
768
+ console.log(`${srcTokenSymbol} Top Pools:`, poolLiquidity);
769
+
770
+ if (!newCurveV1Factory.hasConstantPriceLargeAmounts) {
771
+ checkPoolsLiquidity(
772
+ poolLiquidity,
773
+ Tokens[network][srcTokenSymbol].address,
774
+ dexKey,
775
+ );
776
+ }
777
+ });
778
+ });
779
+ });
780
+
781
+ describe('Polygon', () => {
782
+ const network = Network.POLYGON;
783
+ const dexHelper = new DummyDexHelper(network);
784
+
785
+ const tokens = Tokens[network];
786
+
787
+ beforeAll(async () => {
788
+ blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
789
+ // @ts-expect-error for testing there is dummy blocknumber, but it is not
790
+ // part of the interface
791
+ dexHelper.blockManager._blockNumber = blockNumber;
792
+ console.log(
793
+ `Received blockNumber ${blockNumber} on network ${dexHelper.config.data.network}`,
794
+ );
795
+ curveV1Factory = new CurveV1Factory(network, dexKey, dexHelper);
796
+ if (curveV1Factory.initializePricing) {
797
+ await curveV1Factory.initializePricing(blockNumber);
798
+ }
799
+ });
800
+
801
+ describe('crvUSD -> USDT', () => {
802
+ const srcTokenSymbol = 'crvUSD';
803
+ const destTokenSymbol = 'USDT';
804
+ const amountsForSell = [
805
+ 0n,
806
+ 1n * BI_POWS[tokens[srcTokenSymbol].decimals],
807
+ 2n * BI_POWS[tokens[srcTokenSymbol].decimals],
808
+ 3n * BI_POWS[tokens[srcTokenSymbol].decimals],
809
+ 4n * BI_POWS[tokens[srcTokenSymbol].decimals],
810
+ 5n * BI_POWS[tokens[srcTokenSymbol].decimals],
811
+ 6n * BI_POWS[tokens[srcTokenSymbol].decimals],
812
+ 7n * BI_POWS[tokens[srcTokenSymbol].decimals],
813
+ 8n * BI_POWS[tokens[srcTokenSymbol].decimals],
814
+ 9n * BI_POWS[tokens[srcTokenSymbol].decimals],
815
+ 10n * BI_POWS[tokens[srcTokenSymbol].decimals],
816
+ ];
817
+
818
+ it('getPoolIdentifiers and getPricesVolume SELL', async function () {
819
+ await testPricingOnNetwork(
820
+ curveV1Factory,
821
+ network,
822
+ dexKey,
823
+ blockNumber,
824
+ srcTokenSymbol,
825
+ destTokenSymbol,
826
+ SwapSide.SELL,
827
+ amountsForSell,
828
+ );
829
+ });
830
+
831
+ it('getTopPoolsForToken', async function () {
832
+ // We have to check without calling initializePricing, because
833
+ // pool-tracker is not calling that function
834
+ const newCurveV1Factory = new CurveV1Factory(
835
+ network,
836
+ dexKey,
837
+ dexHelper,
838
+ );
839
+ if (newCurveV1Factory.updatePoolState) {
840
+ await newCurveV1Factory.updatePoolState();
841
+ }
842
+ const poolLiquidity = await newCurveV1Factory.getTopPoolsForToken(
843
+ tokens[srcTokenSymbol].address,
844
+ 10,
845
+ );
846
+ console.log(`${srcTokenSymbol} Top Pools:`, poolLiquidity);
847
+
848
+ if (!newCurveV1Factory.hasConstantPriceLargeAmounts) {
849
+ checkPoolsLiquidity(
850
+ poolLiquidity,
851
+ Tokens[network][srcTokenSymbol].address,
852
+ dexKey,
853
+ );
854
+ }
855
+ });
856
+ });
857
+ });
858
+
859
+ describe('Fantom', () => {
860
+ const network = Network.FANTOM;
861
+ const dexHelper = new DummyDexHelper(network);
862
+
863
+ const tokens = Tokens[network];
864
+
865
+ beforeAll(async () => {
866
+ blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
867
+ // @ts-expect-error for testing there is dummy blocknumber, but it is not
868
+ // part of the interface
869
+ dexHelper.blockManager._blockNumber = blockNumber;
870
+ console.log(
871
+ `Received blockNumber ${blockNumber} on network ${dexHelper.config.data.network}`,
872
+ );
873
+ curveV1Factory = new CurveV1Factory(network, dexKey, dexHelper);
874
+ if (curveV1Factory.initializePricing) {
875
+ await curveV1Factory.initializePricing(blockNumber);
876
+ }
877
+ });
878
+
879
+ describe('scrvUSDC_e -> scrvUSDC_p', () => {
880
+ const srcTokenSymbol = 'scrvUSDC_e';
881
+ const destTokenSymbol = 'scrvUSDC_p';
882
+ const amountsForSell = [
883
+ 0n,
884
+ 1n * BI_POWS[tokens[srcTokenSymbol].decimals],
885
+ 2n * BI_POWS[tokens[srcTokenSymbol].decimals],
886
+ 3n * BI_POWS[tokens[srcTokenSymbol].decimals],
887
+ 4n * BI_POWS[tokens[srcTokenSymbol].decimals],
888
+ 5n * BI_POWS[tokens[srcTokenSymbol].decimals],
889
+ 6n * BI_POWS[tokens[srcTokenSymbol].decimals],
890
+ 7n * BI_POWS[tokens[srcTokenSymbol].decimals],
891
+ 8n * BI_POWS[tokens[srcTokenSymbol].decimals],
892
+ 9n * BI_POWS[tokens[srcTokenSymbol].decimals],
893
+ 10n * BI_POWS[tokens[srcTokenSymbol].decimals],
894
+ ];
895
+
896
+ it('getPoolIdentifiers and getPricesVolume SELL', async function () {
897
+ await testPricingOnNetwork(
898
+ curveV1Factory,
899
+ network,
900
+ dexKey,
901
+ blockNumber,
902
+ srcTokenSymbol,
903
+ destTokenSymbol,
904
+ SwapSide.SELL,
905
+ amountsForSell,
906
+ );
907
+ });
908
+
909
+ it('getTopPoolsForToken', async function () {
910
+ // We have to check without calling initializePricing, because
911
+ // pool-tracker is not calling that function
912
+ const newCurveV1Factory = new CurveV1Factory(
913
+ network,
914
+ dexKey,
915
+ dexHelper,
916
+ );
917
+ if (newCurveV1Factory.updatePoolState) {
918
+ await newCurveV1Factory.updatePoolState();
919
+ }
920
+ const poolLiquidity = await newCurveV1Factory.getTopPoolsForToken(
921
+ tokens[srcTokenSymbol].address,
922
+ 10,
923
+ );
924
+ console.log(`${srcTokenSymbol} Top Pools:`, poolLiquidity);
925
+
926
+ if (!newCurveV1Factory.hasConstantPriceLargeAmounts) {
927
+ checkPoolsLiquidity(
928
+ poolLiquidity,
929
+ Tokens[network][srcTokenSymbol].address,
930
+ dexKey,
931
+ );
932
+ }
933
+ });
934
+ });
935
+ });
936
+
937
+ describe('Arbitrum', () => {
938
+ const network = Network.ARBITRUM;
939
+ const dexHelper = new DummyDexHelper(network);
940
+
941
+ const tokens = Tokens[network];
942
+
943
+ beforeAll(async () => {
944
+ blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
945
+ // @ts-expect-error for testing there is dummy blocknumber, but it is not
946
+ // part of the interface
947
+ dexHelper.blockManager._blockNumber = blockNumber;
948
+ console.log(
949
+ `Received blockNumber ${blockNumber} on network ${dexHelper.config.data.network}`,
950
+ );
951
+ curveV1Factory = new CurveV1Factory(network, dexKey, dexHelper);
952
+ if (curveV1Factory.initializePricing) {
953
+ await curveV1Factory.initializePricing(blockNumber);
954
+ }
955
+ });
956
+
957
+ describe('crvUSD -> USDCe', () => {
958
+ const srcTokenSymbol = 'crvUSD';
959
+ const destTokenSymbol = 'USDCe';
960
+ const amountsForSell = [
961
+ 0n,
962
+ 1n * BI_POWS[tokens[srcTokenSymbol].decimals],
963
+ 2n * BI_POWS[tokens[srcTokenSymbol].decimals],
964
+ 3n * BI_POWS[tokens[srcTokenSymbol].decimals],
965
+ 4n * BI_POWS[tokens[srcTokenSymbol].decimals],
966
+ 5n * BI_POWS[tokens[srcTokenSymbol].decimals],
967
+ 6n * BI_POWS[tokens[srcTokenSymbol].decimals],
968
+ 7n * BI_POWS[tokens[srcTokenSymbol].decimals],
969
+ 8n * BI_POWS[tokens[srcTokenSymbol].decimals],
970
+ 9n * BI_POWS[tokens[srcTokenSymbol].decimals],
971
+ 10n * BI_POWS[tokens[srcTokenSymbol].decimals],
972
+ ];
973
+
974
+ it('getPoolIdentifiers and getPricesVolume SELL', async function () {
975
+ await testPricingOnNetwork(
976
+ curveV1Factory,
977
+ network,
978
+ dexKey,
979
+ blockNumber,
980
+ srcTokenSymbol,
981
+ destTokenSymbol,
982
+ SwapSide.SELL,
983
+ amountsForSell,
984
+ );
985
+ });
986
+
987
+ it('getTopPoolsForToken', async function () {
988
+ // We have to check without calling initializePricing, because
989
+ // pool-tracker is not calling that function
990
+ const newCurveV1Factory = new CurveV1Factory(
991
+ network,
992
+ dexKey,
993
+ dexHelper,
994
+ );
995
+ if (newCurveV1Factory.updatePoolState) {
996
+ await newCurveV1Factory.updatePoolState();
997
+ }
998
+ const poolLiquidity = await newCurveV1Factory.getTopPoolsForToken(
999
+ tokens[srcTokenSymbol].address,
1000
+ 10,
1001
+ );
1002
+ console.log(`${srcTokenSymbol} Top Pools:`, poolLiquidity);
1003
+
1004
+ if (!newCurveV1Factory.hasConstantPriceLargeAmounts) {
1005
+ checkPoolsLiquidity(
1006
+ poolLiquidity,
1007
+ Tokens[network][srcTokenSymbol].address,
1008
+ dexKey,
1009
+ );
1010
+ }
1011
+ });
1012
+ });
1013
+ });
1014
+
1015
+ describe('Optimism', () => {
1016
+ const network = Network.OPTIMISM;
1017
+ const dexHelper = new DummyDexHelper(network);
1018
+
1019
+ const tokens = Tokens[network];
1020
+
1021
+ beforeAll(async () => {
1022
+ blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
1023
+ // @ts-expect-error for testing there is dummy blocknumber, but it is not
1024
+ // part of the interface
1025
+ dexHelper.blockManager._blockNumber = blockNumber;
1026
+ console.log(
1027
+ `Received blockNumber ${blockNumber} on network ${dexHelper.config.data.network}`,
1028
+ );
1029
+ curveV1Factory = new CurveV1Factory(network, dexKey, dexHelper);
1030
+ if (curveV1Factory.initializePricing) {
1031
+ await curveV1Factory.initializePricing(blockNumber);
1032
+ }
1033
+ });
1034
+
1035
+ describe('crvUSD -> USDT', () => {
1036
+ const srcTokenSymbol = 'crvUSD';
1037
+ const destTokenSymbol = 'USDT';
1038
+ const amountsForSell = [
1039
+ 0n,
1040
+ 1n * BI_POWS[tokens[srcTokenSymbol].decimals],
1041
+ 2n * BI_POWS[tokens[srcTokenSymbol].decimals],
1042
+ 3n * BI_POWS[tokens[srcTokenSymbol].decimals],
1043
+ 4n * BI_POWS[tokens[srcTokenSymbol].decimals],
1044
+ 5n * BI_POWS[tokens[srcTokenSymbol].decimals],
1045
+ 6n * BI_POWS[tokens[srcTokenSymbol].decimals],
1046
+ 7n * BI_POWS[tokens[srcTokenSymbol].decimals],
1047
+ 8n * BI_POWS[tokens[srcTokenSymbol].decimals],
1048
+ 9n * BI_POWS[tokens[srcTokenSymbol].decimals],
1049
+ 10n * BI_POWS[tokens[srcTokenSymbol].decimals],
1050
+ ];
1051
+
1052
+ it('getPoolIdentifiers and getPricesVolume SELL', async function () {
1053
+ await testPricingOnNetwork(
1054
+ curveV1Factory,
1055
+ network,
1056
+ dexKey,
1057
+ blockNumber,
1058
+ srcTokenSymbol,
1059
+ destTokenSymbol,
1060
+ SwapSide.SELL,
1061
+ amountsForSell,
1062
+ );
1063
+ });
1064
+
1065
+ it('getTopPoolsForToken', async function () {
1066
+ // We have to check without calling initializePricing, because
1067
+ // pool-tracker is not calling that function
1068
+ const newCurveV1Factory = new CurveV1Factory(
1069
+ network,
1070
+ dexKey,
1071
+ dexHelper,
1072
+ );
1073
+ if (newCurveV1Factory.updatePoolState) {
1074
+ await newCurveV1Factory.updatePoolState();
1075
+ }
1076
+ const poolLiquidity = await newCurveV1Factory.getTopPoolsForToken(
1077
+ tokens[srcTokenSymbol].address,
1078
+ 10,
1079
+ );
1080
+ console.log(`${srcTokenSymbol} Top Pools:`, poolLiquidity);
1081
+
1082
+ if (!newCurveV1Factory.hasConstantPriceLargeAmounts) {
1083
+ checkPoolsLiquidity(
1084
+ poolLiquidity,
1085
+ Tokens[network][srcTokenSymbol].address,
1086
+ dexKey,
1087
+ );
1088
+ }
1089
+ });
1090
+ });
1091
+ });
1092
+ });
701
1093
  });
@@ -101,6 +101,8 @@ export class CurveV1Factory
101
101
  readonly isFeeOnTransferSupported = true;
102
102
  readonly isStatePollingDex = true;
103
103
 
104
+ private factoryAddresses: string[];
105
+
104
106
  readonly poolManager: CurveV1FactoryPoolManager;
105
107
  readonly ifaces: CurveV1FactoryIfaces;
106
108
 
@@ -128,6 +130,8 @@ export class CurveV1Factory
128
130
  ) {
129
131
  super(dexHelper, dexKey);
130
132
  this.logger = dexHelper.getLogger(`${this.dexKey}-${this.network}`);
133
+ this.factoryAddresses =
134
+ this.config.factories?.map(e => e.address.toLowerCase()) || [];
131
135
  this.ifaces = {
132
136
  exchangeRouter: new Interface(CurveABI),
133
137
  factory: new Interface(FactoryCurveV1ABI as JsonFragment[]),
@@ -348,10 +352,7 @@ export class CurveV1Factory
348
352
  return;
349
353
  }
350
354
 
351
- if (
352
- !this.config.factoryAddresses ||
353
- this.config.factoryAddresses.length == 0
354
- ) {
355
+ if (!this.factoryAddresses || this.factoryAddresses.length == 0) {
355
356
  this.logger.warn(`No factory address specified in configs`);
356
357
  return;
357
358
  }
@@ -360,13 +361,13 @@ export class CurveV1Factory
360
361
  // So I put it here to not forget call, because custom pools must be initialised before factory pools
361
362
  // This function may be called multiple times, but will execute only once
362
363
  await this.initializeCustomPollingPools(
363
- this.config.factoryAddresses,
364
+ this.factoryAddresses,
364
365
  blockNumber,
365
366
  initializeInitialState,
366
367
  );
367
368
 
368
369
  await Promise.all(
369
- this.config.factoryAddresses.map(async factoryAddress => {
370
+ this.factoryAddresses.map(async factoryAddress => {
370
371
  try {
371
372
  const poolCountResult =
372
373
  await this.dexHelper.multiWrapper!.tryAggregate(true, [
@@ -426,6 +427,11 @@ export class CurveV1Factory
426
427
  }
427
428
  });
428
429
 
430
+ const factoryConfig = this.config.factories?.find(
431
+ ({ address }) =>
432
+ factoryAddress.toLowerCase() === address.toLowerCase(),
433
+ );
434
+
429
435
  let callDataFromFactoryPools: MultiCallParams<
430
436
  string[] | number[] | string
431
437
  >[] = poolAddresses
@@ -448,7 +454,11 @@ export class CurveV1Factory
448
454
  ): string[] =>
449
455
  generalDecoder<string[]>(
450
456
  result,
451
- ['address[4]'],
457
+ [
458
+ `address[${
459
+ factoryConfig?.maxPlainCoins?.toString() || ''
460
+ }]`,
461
+ ],
452
462
  new Array(4).fill(NULL_ADDRESS),
453
463
  parsed => parsed[0].map((p: string) => p.toLowerCase()),
454
464
  ),
@@ -464,7 +474,11 @@ export class CurveV1Factory
464
474
  ): number[] =>
465
475
  generalDecoder<number[]>(
466
476
  result,
467
- ['uint256[4]'],
477
+ [
478
+ `uint256[${
479
+ factoryConfig?.maxPlainCoins?.toString() || ''
480
+ }]`,
481
+ ],
468
482
  [0, 0, 0, 0],
469
483
  parsed =>
470
484
  parsed[0].map((p: BigNumber) => Number(p.toString())),
@@ -476,43 +490,51 @@ export class CurveV1Factory
476
490
  // This is divider between pools related results and implementations
477
491
  const factoryResultsDivider = callDataFromFactoryPools.length;
478
492
 
493
+ const metaPoolImplementations = factoryConfig?.isStableNg
494
+ ? []
495
+ : basePoolAddresses.map(basePoolAddress => ({
496
+ target: factoryAddress,
497
+ callData: this.ifaces.factory.encodeFunctionData(
498
+ 'metapool_implementations',
499
+ [basePoolAddress],
500
+ ),
501
+ decodeFunction: (
502
+ result: MultiResult<BytesLike> | BytesLike,
503
+ ): string[] =>
504
+ generalDecoder<string[]>(
505
+ result,
506
+ ['address[10]'],
507
+ new Array(10).fill(NULL_ADDRESS),
508
+ parsed => parsed[0].map((p: string) => p.toLowerCase()),
509
+ ),
510
+ }));
511
+
512
+ const plainImplementations = factoryConfig?.isStableNg
513
+ ? []
514
+ : _.flattenDeep(
515
+ _.range(2, FACTORY_MAX_PLAIN_COINS + 1).map(coinNumber =>
516
+ _.range(FACTORY_MAX_PLAIN_IMPLEMENTATIONS_FOR_COIN).map(
517
+ implInd => ({
518
+ target: factoryAddress,
519
+ callData: this.ifaces.factory.encodeFunctionData(
520
+ 'plain_implementations',
521
+ [coinNumber, implInd],
522
+ ),
523
+ decodeFunction: addressDecode,
524
+ }),
525
+ ),
526
+ ),
527
+ );
528
+
479
529
  // Implementations must be requested from factory, but it accepts as arg basePool address
480
530
  // for metaPools
481
531
  callDataFromFactoryPools = callDataFromFactoryPools.concat(
482
- ...basePoolAddresses.map(basePoolAddress => ({
483
- target: factoryAddress,
484
- callData: this.ifaces.factory.encodeFunctionData(
485
- 'metapool_implementations',
486
- [basePoolAddress],
487
- ),
488
- decodeFunction: (
489
- result: MultiResult<BytesLike> | BytesLike,
490
- ): string[] =>
491
- generalDecoder<string[]>(
492
- result,
493
- ['address[10]'],
494
- new Array(10).fill(NULL_ADDRESS),
495
- parsed => parsed[0].map((p: string) => p.toLowerCase()),
496
- ),
497
- })),
532
+ ...metaPoolImplementations,
498
533
  // To receive plain pool implementation address, you have to call plain_implementations
499
534
  // with two variables: N_COINS and implementations_index
500
535
  // N_COINS is between 2-4. Currently more than 4 coins is not supported
501
536
  // as for implementation index, there are only 0-9 indexes
502
- ..._.flattenDeep(
503
- _.range(2, FACTORY_MAX_PLAIN_COINS + 1).map(coinNumber =>
504
- _.range(FACTORY_MAX_PLAIN_IMPLEMENTATIONS_FOR_COIN).map(
505
- implInd => ({
506
- target: factoryAddress,
507
- callData: this.ifaces.factory.encodeFunctionData(
508
- 'plain_implementations',
509
- [coinNumber, implInd],
510
- ),
511
- decodeFunction: addressDecode,
512
- }),
513
- ),
514
- ),
515
- ),
537
+ ...plainImplementations,
516
538
  );
517
539
 
518
540
  const allResultsFromFactory = (
@@ -619,7 +641,7 @@ export class CurveV1Factory
619
641
  factoryImplementationFromConfig.name,
620
642
  implementationAddress.toLowerCase(),
621
643
  poolAddresses[i],
622
- this.config.stateUpdatePeriodMs,
644
+ this.config,
623
645
  factoryAddress,
624
646
  poolIdentifier,
625
647
  poolConstants,
@@ -45,6 +45,7 @@ export class CurveV1FactoryPoolManager {
45
45
  private allCurveLiquidityApiSlugs: Set<string> = new Set([
46
46
  '/factory',
47
47
  '/factory-crvusd',
48
+ '/factory-stable-ng',
48
49
  ]);
49
50
 
50
51
  private statePollingManager = StatePollingManager;
@@ -285,6 +285,8 @@ const implementations: Record<ImplementationNames, _calc_withdraw_one_coin> = {
285
285
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: customArbitrum2CoinBtc,
286
286
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: factoryPlain2EthEma2,
287
287
  [ImplementationNames.FACTORY_PLAIN_2_CRV_EMA]: customArbitrum2CoinBtc,
288
+
289
+ [ImplementationNames.FACTORY_STABLE_NG]: notImplemented,
288
290
  };
289
291
 
290
292
  export default implementations;
@@ -1,9 +1,8 @@
1
- import _ from 'lodash';
2
1
  import { ImplementationNames } from '../../types';
3
2
  import { IPoolContext, _dynamic_fee } from '../types';
4
3
  import { throwNotExist } from './utils';
5
4
 
6
- const customAvalanche3CoinLending: _dynamic_fee = (
5
+ const dynamicFee: _dynamic_fee = (
7
6
  self: IPoolContext,
8
7
  xpi: bigint,
9
8
  xpj: bigint,
@@ -23,6 +22,9 @@ const customAvalanche3CoinLending: _dynamic_fee = (
23
22
  }
24
23
  };
25
24
 
25
+ const stableNg = dynamicFee;
26
+ const customAvalanche3CoinLending = dynamicFee;
27
+
26
28
  const notExist: _dynamic_fee = (
27
29
  self: IPoolContext,
28
30
  xpi: bigint,
@@ -94,6 +96,8 @@ const implementations: Record<ImplementationNames, _dynamic_fee> = {
94
96
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: notExist,
95
97
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: notExist,
96
98
  [ImplementationNames.FACTORY_PLAIN_2_CRV_EMA]: notExist,
99
+
100
+ [ImplementationNames.FACTORY_STABLE_NG]: stableNg,
97
101
  };
98
102
 
99
103
  export default implementations;
@@ -109,6 +109,8 @@ const implementations: Record<ImplementationNames, _rates> = {
109
109
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: notExist,
110
110
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: notExist,
111
111
  [ImplementationNames.FACTORY_PLAIN_2_CRV_EMA]: notExist,
112
+
113
+ [ImplementationNames.FACTORY_STABLE_NG]: notExist,
112
114
  };
113
115
 
114
116
  export default implementations;
@@ -107,6 +107,8 @@ const implementations: Record<ImplementationNames, _xp> = {
107
107
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: notExist,
108
108
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: notExist,
109
109
  [ImplementationNames.FACTORY_PLAIN_2_CRV_EMA]: notExist,
110
+
111
+ [ImplementationNames.FACTORY_STABLE_NG]: notExist,
110
112
  };
111
113
 
112
114
  export default implementations;
@@ -96,6 +96,8 @@ const implementations: Record<ImplementationNames, _xp_mem> = {
96
96
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: factoryPlain2Basic,
97
97
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: factoryPlain2Basic,
98
98
  [ImplementationNames.FACTORY_PLAIN_2_CRV_EMA]: factoryPlain2Basic,
99
+
100
+ [ImplementationNames.FACTORY_STABLE_NG]: notExist,
99
101
  };
100
102
 
101
103
  export default implementations;
@@ -223,6 +223,8 @@ const implementations: Record<ImplementationNames, calc_token_amount> = {
223
223
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: customPlain3CoinThree,
224
224
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: customPlain3CoinThree,
225
225
  [ImplementationNames.FACTORY_PLAIN_2_CRV_EMA]: customPlain2CoinCrv,
226
+
227
+ [ImplementationNames.FACTORY_STABLE_NG]: notImplemented,
226
228
  };
227
229
 
228
230
  export default implementations;
@@ -83,6 +83,8 @@ export const implementations: Record<
83
83
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: customPlain3CoinThree,
84
84
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: customPlain3CoinThree,
85
85
  [ImplementationNames.FACTORY_PLAIN_2_CRV_EMA]: customPlain3CoinThree,
86
+
87
+ [ImplementationNames.FACTORY_STABLE_NG]: notImplemented,
86
88
  };
87
89
 
88
90
  export default implementations;
@@ -584,6 +584,17 @@ const implementationConstants: Record<
584
584
  isFeeOnTransferSupported: false,
585
585
  isLending: false,
586
586
 
587
+ N_COINS: 2,
588
+ BI_N_COINS: 2n,
589
+ PRECISION: BI_POWS[18],
590
+ FEE_DENOMINATOR: BI_POWS[10],
591
+ A_PRECISION: 100n,
592
+ },
593
+ [ImplementationNames.FACTORY_STABLE_NG]: {
594
+ isWrapNative: false,
595
+ isFeeOnTransferSupported: false,
596
+ isLending: false,
597
+
587
598
  N_COINS: 2,
588
599
  BI_N_COINS: 2n,
589
600
  PRECISION: BI_POWS[18],