@paraswap/dex-lib 4.1.2-pubsub-fluid → 4.1.2

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 (279) hide show
  1. package/.idea/aws.xml +17 -0
  2. package/.idea/codeStyles/Project.xml +19 -0
  3. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  4. package/.idea/misc.xml +6 -0
  5. package/.idea/modules.xml +8 -0
  6. package/.idea/paraswap-dex-lib.iml +9 -0
  7. package/.idea/prettier.xml +7 -0
  8. package/.idea/vcs.xml +6 -0
  9. package/build/abi/fluid-dex/resolver.abi.json +0 -30
  10. package/build/abi/integral/factory.json +333 -0
  11. package/build/abi/{angle-transmuter/ChainlinkEACAggregatorProxy.json → integral/oracle.json} +239 -247
  12. package/build/abi/{curve-v1/StableSwapUSDN.json → integral/pool.json} +487 -450
  13. package/build/abi/{RamsesV2Pool.abi.json → integral/relayer.json} +833 -851
  14. package/build/dex/aave-v1/aave-v1.d.ts +1 -2
  15. package/build/dex/aave-v1/aave-v1.js +0 -22
  16. package/build/dex/aave-v1/aave-v1.js.map +1 -1
  17. package/build/dex/bProtocol.d.ts +18 -0
  18. package/build/dex/bProtocol.js +39 -0
  19. package/build/dex/bProtocol.js.map +1 -0
  20. package/build/dex/bancor.d.ts +26 -0
  21. package/build/dex/bancor.js +58 -0
  22. package/build/dex/bancor.js.map +1 -0
  23. package/build/dex/compound.d.ts +18 -0
  24. package/build/dex/compound.js +46 -0
  25. package/build/dex/compound.js.map +1 -0
  26. package/build/dex/curve-v2.d.ts +58 -0
  27. package/build/dex/curve-v2.js +180 -0
  28. package/build/dex/curve-v2.js.map +1 -0
  29. package/build/dex/dodo-v1.d.ts +33 -0
  30. package/build/dex/dodo-v1.js +63 -0
  31. package/build/dex/dodo-v1.js.map +1 -0
  32. package/build/dex/fluid-dex/config.js +2 -2
  33. package/build/dex/fluid-dex/constants.d.ts +1 -1
  34. package/build/dex/fluid-dex/constants.js +1 -2
  35. package/build/dex/fluid-dex/constants.js.map +1 -1
  36. package/build/dex/fluid-dex/fluid-dex-generate-pool.d.ts +49 -0
  37. package/build/dex/fluid-dex/fluid-dex-generate-pool.js +104 -0
  38. package/build/dex/fluid-dex/fluid-dex-generate-pool.js.map +1 -0
  39. package/build/dex/fluid-dex/fluid-dex-liquidity-proxy.js +1 -3
  40. package/build/dex/fluid-dex/fluid-dex-liquidity-proxy.js.map +1 -1
  41. package/build/dex/fluid-dex/fluid-dex.d.ts +5 -4
  42. package/build/dex/fluid-dex/fluid-dex.js +57 -63
  43. package/build/dex/fluid-dex/fluid-dex.js.map +1 -1
  44. package/build/dex/fluid-dex/types.d.ts +0 -3
  45. package/build/dex/generic-rfq/generic-rfq.js +2 -1
  46. package/build/dex/generic-rfq/generic-rfq.js.map +1 -1
  47. package/build/dex/generic-rfq/rate-fetcher.d.ts +1 -4
  48. package/build/dex/generic-rfq/rate-fetcher.js +20 -53
  49. package/build/dex/generic-rfq/rate-fetcher.js.map +1 -1
  50. package/build/dex/integral/config.d.ts +4 -0
  51. package/build/dex/integral/config.js +20 -0
  52. package/build/dex/integral/config.js.map +1 -0
  53. package/build/dex/integral/context.d.ts +40 -0
  54. package/build/dex/integral/context.js +158 -0
  55. package/build/dex/integral/context.js.map +1 -0
  56. package/build/dex/integral/integral-factory.d.ts +24 -0
  57. package/build/dex/integral/integral-factory.js +95 -0
  58. package/build/dex/integral/integral-factory.js.map +1 -0
  59. package/build/dex/integral/integral-pool.d.ts +50 -0
  60. package/build/dex/integral/integral-pool.js +149 -0
  61. package/build/dex/integral/integral-pool.js.map +1 -0
  62. package/build/dex/integral/integral-pricing.d.ts +18 -0
  63. package/build/dex/integral/integral-pricing.js +114 -0
  64. package/build/dex/integral/integral-pricing.js.map +1 -0
  65. package/build/dex/integral/integral-relayer.d.ts +42 -0
  66. package/build/dex/integral/integral-relayer.js +192 -0
  67. package/build/dex/integral/integral-relayer.js.map +1 -0
  68. package/build/dex/integral/integral-token.d.ts +27 -0
  69. package/build/dex/integral/integral-token.js +59 -0
  70. package/build/dex/integral/integral-token.js.map +1 -0
  71. package/build/dex/{inception/inception-native.d.ts → integral/integral.d.ts} +19 -21
  72. package/build/dex/integral/integral.js +376 -0
  73. package/build/dex/integral/integral.js.map +1 -0
  74. package/build/dex/integral/types.d.ts +85 -0
  75. package/build/dex/integral/types.js +9 -0
  76. package/build/dex/integral/types.js.map +1 -0
  77. package/build/dex/integral/utils-e2e.d.ts +9 -0
  78. package/build/dex/integral/utils-e2e.js +131 -0
  79. package/build/dex/integral/utils-e2e.js.map +1 -0
  80. package/build/dex/integral/utils.d.ts +17 -0
  81. package/build/dex/integral/utils.js +94 -0
  82. package/build/dex/integral/utils.js.map +1 -0
  83. package/build/dex/jarvis.d.ts +1 -2
  84. package/build/dex/jarvis.js +0 -58
  85. package/build/dex/jarvis.js.map +1 -1
  86. package/build/dex/lido.d.ts +19 -0
  87. package/build/dex/lido.js +42 -0
  88. package/build/dex/lido.js.map +1 -0
  89. package/build/dex/onebit.d.ts +25 -0
  90. package/build/dex/onebit.js +42 -0
  91. package/build/dex/onebit.js.map +1 -0
  92. package/build/dex/platypus/platypus.d.ts +1 -2
  93. package/build/dex/platypus/platypus.js +0 -31
  94. package/build/dex/platypus/platypus.js.map +1 -1
  95. package/build/dex/smoothy.d.ts +26 -0
  96. package/build/dex/smoothy.js +48 -0
  97. package/build/dex/smoothy.js.map +1 -0
  98. package/build/dex/stable-pool.d.ts +28 -0
  99. package/build/dex/stable-pool.js +62 -0
  100. package/build/dex/stable-pool.js.map +1 -0
  101. package/build/dex/swaap-v1/swaap-v1.d.ts +1 -2
  102. package/build/dex/swaap-v1/swaap-v1.js +0 -10
  103. package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
  104. package/build/dex/trader-joe-v2.1/optimizer.d.ts +2 -0
  105. package/build/dex/trader-joe-v2.1/optimizer.js +47 -0
  106. package/build/dex/trader-joe-v2.1/optimizer.js.map +1 -0
  107. package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.d.ts +7 -0
  108. package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.js +20 -0
  109. package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.js.map +1 -0
  110. package/build/dex/trader-joe-v2.1.d.ts +43 -0
  111. package/build/dex/trader-joe-v2.1.js +79 -0
  112. package/build/dex/trader-joe-v2.1.js.map +1 -0
  113. package/build/dex/zerox/index.d.ts +26 -4
  114. package/build/dex/zerox/index.js +42 -50
  115. package/build/dex/zerox/index.js.map +1 -1
  116. package/build/dex/zerox/types.d.ts +0 -29
  117. package/build/dex/zerox/types.js +1 -8
  118. package/build/dex/zerox/types.js.map +1 -1
  119. package/build/lib/pub-sub.d.ts +0 -15
  120. package/build/lib/pub-sub.js +1 -72
  121. package/build/lib/pub-sub.js.map +1 -1
  122. package/package.json +1 -1
  123. package/src/abi/fluid-dex/resolver.abi.json +0 -30
  124. package/src/dex/fluid-dex/config.ts +2 -2
  125. package/src/dex/fluid-dex/constants.ts +1 -2
  126. package/src/dex/fluid-dex/fluid-dex-e2e.test.ts +71 -31
  127. package/src/dex/fluid-dex/fluid-dex-liquidity-proxy.ts +0 -3
  128. package/src/dex/fluid-dex/fluid-dex.ts +91 -98
  129. package/src/dex/fluid-dex/types.ts +0 -3
  130. package/src/dex/generic-rfq/generic-rfq.ts +6 -1
  131. package/src/dex/generic-rfq/rate-fetcher.ts +47 -83
  132. package/src/lib/pub-sub.ts +0 -86
  133. package/tests/constants-e2e.ts +1 -1
  134. package/tests/tenderly-simulation.ts +0 -1
  135. package/build/abi/Aave_GSM.json +0 -751
  136. package/build/abi/Balancer.json +0 -257
  137. package/build/abi/BalancerV2.json +0 -1179
  138. package/build/abi/RamsesV2Quoter.abi.json +0 -274
  139. package/build/abi/USDM.json +0 -807
  140. package/build/abi/UniswapV2Router.json +0 -397
  141. package/build/abi/angle-transmuter/ChainlinkAccessControlledOffchainAggregator.json +0 -1246
  142. package/build/abi/curve-v1/CurveBUSDv2.abi.json +0 -1356
  143. package/build/abi/curve-v1/CurveTokenV1.json +0 -305
  144. package/build/abi/curve-v1/CurveTokenV2.json +0 -318
  145. package/build/abi/curve-v1/CurveV1StableNg.json +0 -1452
  146. package/build/abi/curve-v1/CurveV2Swap.json +0 -700
  147. package/build/abi/curve-v1/FactoryCryptoRegistry.json +0 -316
  148. package/build/abi/curve-v1/FactoryRegistry.json +0 -508
  149. package/build/abi/curve-v1/StableSwapAave.json +0 -1152
  150. package/build/abi/curve-v1/StableSwapBUSD.json +0 -814
  151. package/build/abi/curve-v1/StableSwapCompound.json +0 -814
  152. package/build/abi/curve-v1/StableSwapIDLE.json +0 -1253
  153. package/build/abi/curve-v1/StableSwapPax.json +0 -865
  154. package/build/abi/curve-v1/StableSwapSnow.json +0 -900
  155. package/build/abi/curve-v1/StableSwapUSDT.json +0 -814
  156. package/build/abi/curve-v1/StableSwapY.json +0 -814
  157. package/build/abi/inception/inception-ineth-pool.json +0 -1062
  158. package/build/abi/inception/inception-ineth.json +0 -609
  159. package/build/abi/inception/inception-ratio-feed.json +0 -329
  160. package/build/abi/inception/inception-vault.json +0 -991
  161. package/build/abi/kyberdmm/kyber-storage.abi.json +0 -824
  162. package/build/abi/kyberdmm.abi.json +0 -1148
  163. package/build/abi/maverick-v2/MaverickV2Quoter.json +0 -278
  164. package/build/abi/nerve/nerve-metapool.json +0 -790
  165. package/build/abi/uniswap-v3/UniswapV3Quoter.abi.json +0 -193
  166. package/build/abi/velodrome-slipstream/VelodromeSlipstreamQuoterV2.abi.json +0 -267
  167. package/build/dex/balancer-v1/balancer-pools.json +0 -33333
  168. package/build/dex/bebop/websocket-fetcher.d.ts +0 -35
  169. package/build/dex/bebop/websocket-fetcher.js +0 -87
  170. package/build/dex/bebop/websocket-fetcher.js.map +0 -1
  171. package/build/dex/idle-dao/idle-dao-pool.d.ts +0 -56
  172. package/build/dex/idle-dao/idle-dao-pool.js +0 -176
  173. package/build/dex/idle-dao/idle-dao-pool.js.map +0 -1
  174. package/build/dex/idle-dao/idle-dao-pooling-pool.d.ts +0 -16
  175. package/build/dex/idle-dao/idle-dao-pooling-pool.js +0 -57
  176. package/build/dex/idle-dao/idle-dao-pooling-pool.js.map +0 -1
  177. package/build/dex/idle-dao/scripts.d.ts +0 -9
  178. package/build/dex/idle-dao/scripts.js +0 -552
  179. package/build/dex/idle-dao/scripts.js.map +0 -1
  180. package/build/dex/inception/config.d.ts +0 -4
  181. package/build/dex/inception/config.js +0 -109
  182. package/build/dex/inception/config.js.map +0 -1
  183. package/build/dex/inception/inception-event-pool.d.ts +0 -16
  184. package/build/dex/inception/inception-event-pool.js +0 -51
  185. package/build/dex/inception/inception-event-pool.js.map +0 -1
  186. package/build/dex/inception/inception-native.js +0 -131
  187. package/build/dex/inception/inception-native.js.map +0 -1
  188. package/build/dex/inception/inception-pool.d.ts +0 -18
  189. package/build/dex/inception/inception-pool.js +0 -32
  190. package/build/dex/inception/inception-pool.js.map +0 -1
  191. package/build/dex/inception/inception-price-feed.d.ts +0 -19
  192. package/build/dex/inception/inception-price-feed.js +0 -51
  193. package/build/dex/inception/inception-price-feed.js.map +0 -1
  194. package/build/dex/inception/inception.d.ts +0 -43
  195. package/build/dex/inception/inception.js +0 -204
  196. package/build/dex/inception/inception.js.map +0 -1
  197. package/build/dex/inception/tokens.d.ts +0 -9
  198. package/build/dex/inception/tokens.js +0 -28
  199. package/build/dex/inception/tokens.js.map +0 -1
  200. package/build/dex/inception/types.d.ts +0 -22
  201. package/build/dex/inception/types.js +0 -3
  202. package/build/dex/inception/types.js.map +0 -1
  203. package/build/dex/inception/utils.d.ts +0 -6
  204. package/build/dex/inception/utils.js +0 -37
  205. package/build/dex/inception/utils.js.map +0 -1
  206. package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-balancerv1-curvev1-eth-usdc-gusd.json +0 -16
  207. package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-balancerv1-sushiv3-wbtc-eth-sushi.json +0 -16
  208. package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-curvev1-eth-usdc-gusd.json +0 -16
  209. package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-curvev1-gusd-usdc-eth.json +0 -16
  210. package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-dai-usdc-eth.json +0 -16
  211. package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-eth-usdc-dai.json +0 -16
  212. package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-usdc-eth-wbtc.json +0 -16
  213. package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-usdt-usdc-dai.json +0 -16
  214. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-balancerv1-eth-usdc.json +0 -9
  215. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-balancerv1-usdc-eth.json +0 -9
  216. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-balancerv1-usdc-wbtc.json +0 -9
  217. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-curvev1-eth-steth.json +0 -9
  218. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-curvev1-steth-eth.json +0 -9
  219. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-curvev1-usdc-usdt.json +0 -9
  220. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-univ3-eth-usdc.json +0 -9
  221. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-univ3-usdc-eth.json +0 -9
  222. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-univ3-usdc-usdt.json +0 -9
  223. package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-balancerv1-sushiv3-wbtc-eth-sushi.json +0 -12
  224. package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-curvev1-eth-usdc-gusd.json +0 -7
  225. package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-curvev1-gusd-usdc-eth.json +0 -7
  226. package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-dai-usdc-eth.json +0 -7
  227. package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-eth-usdc-dai.json +0 -7
  228. package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-usdc-eth-wbtc.json +0 -12
  229. package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-simpleSwap-univ3-eth-usdc.json +0 -7
  230. package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-simpleSwap-univ3-usdc-eth.json +0 -7
  231. package/build/executor/fixtures/executor01/routes/price-route-multiswap-balancerv1-curvev1-eth-usdc-gusd.json +0 -78
  232. package/build/executor/fixtures/executor01/routes/price-route-multiswap-balancerv1-sushiv3-wbtc-eth-sushi.json +0 -81
  233. package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-curvev1-eth-usdc-gusd.json +0 -78
  234. package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-curvev1-gusd-usdc-eth.json +0 -78
  235. package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-dai-usdc-eth.json +0 -81
  236. package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-eth-usdc-dai.json +0 -81
  237. package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-usdc-eth-wbtc.json +0 -81
  238. package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-usdt-usdc-dai.json +0 -81
  239. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-balancerv1-eth-usdc.json +0 -64
  240. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-balancerv1-usdc-eth.json +0 -85
  241. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-balancerv1-usdc-wbtc.json +0 -64
  242. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-curvev1-eth-steth.json +0 -52
  243. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-curvev1-steth-eth.json +0 -52
  244. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-curvev1-usdc-usdt.json +0 -52
  245. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-univ3-eth-usdc.json +0 -55
  246. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-univ3-usdc-eth.json +0 -55
  247. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-univ3-usdc-usdt.json +0 -55
  248. package/build/executor/fixtures/executor02/exchange-params/price-route-multiSwap-balancerv1-sushiv3-univ3-bal-eth-sushi.json +0 -23
  249. package/build/executor/fixtures/executor02/exchange-params/price-route-multiSwap-maverickv1-sushiv3-univ3-eth-usdc-mav.json +0 -37
  250. package/build/executor/fixtures/executor02/exchange-params/price-route-multiSwap-univ3-sushiv3-sushi-eth-wbtc.json +0 -23
  251. package/build/executor/fixtures/executor02/exchange-params/price-route-multiSwap-univ3-sushiv3-wbtc-eth-sushi.json +0 -23
  252. package/build/executor/fixtures/executor02/exchange-params/price-route-multiswap-curvev1-univ3-dai-usdc-eth.json +0 -51
  253. package/build/executor/fixtures/executor02/exchange-params/price-route-multiswap-univ3-usdt-dai-eth.json +0 -58
  254. package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-balancerv1-eth-usdc.json +0 -23
  255. package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-balancerv1-usdc-eth.json +0 -23
  256. package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-univ3-eth-sushi.json +0 -9
  257. package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-univ3-sushi-eth.json +0 -16
  258. package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-univ3-curvev1-usdt-dai.json +0 -23
  259. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-balancerv1-sushiv3-univ3-bal-eth-sushi.json +0 -12
  260. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-maverickv1-sushiv3-univ3-eth-usdc-mav.json +0 -7
  261. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-univ3-sushiv3-sushi-eth-wbtc.json +0 -12
  262. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-univ3-sushiv3-wbtc-eth-sushi.json +0 -12
  263. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiswap-curvev1-univ3-dai-usdc-eth.json +0 -7
  264. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiswap-univ3-usdt-dai-eth.json +0 -7
  265. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-balancerv1-eth-usdc.json +0 -7
  266. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-balancerv1-usdc-eth.json +0 -7
  267. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-univ3-eth-sushi.json +0 -7
  268. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-univ3-sushi-eth.json +0 -7
  269. package/build/executor/fixtures/executor02/routes/price-route-multiSwap-balancerv1-sushiv3-univ3-bal-eth-sushi.json +0 -130
  270. package/build/executor/fixtures/executor02/routes/price-route-multiSwap-maverickv1-sushiv3-univ3-eth-usdc-mav.json +0 -136
  271. package/build/executor/fixtures/executor02/routes/price-route-multiSwap-univ3-sushiv3-sushi-eth-wbtc.json +0 -100
  272. package/build/executor/fixtures/executor02/routes/price-route-multiSwap-univ3-sushiv3-wbtc-eth-sushi.json +0 -100
  273. package/build/executor/fixtures/executor02/routes/price-route-multiswap-curvev1-univ3-dai-usdc-eth.json +0 -166
  274. package/build/executor/fixtures/executor02/routes/price-route-multiswap-univ3-usdt-dai-eth.json +0 -190
  275. package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-balancerv1-eth-usdc.json +0 -114
  276. package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-balancerv1-usdc-eth.json +0 -114
  277. package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-univ3-eth-sushi.json +0 -55
  278. package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-univ3-sushi-eth.json +0 -73
  279. package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-univ3-curvev1-usdt-dai.json +0 -82
@@ -7,14 +7,14 @@ exports.FluidDexConfig = {
7
7
  [constants_1.Network.MAINNET]: {
8
8
  commonAddresses: {
9
9
  liquidityProxy: '0x52aa899454998be5b000ad077a46bbe360f4e497',
10
- resolver: '0xb387f9C2092cF7c4943F97842887eBff7AE96EB3',
10
+ resolver: '0x45f4ad57e300da55c33dea579a40fcee000d7b94',
11
11
  dexFactory: '0x91716C4EDA1Fb55e84Bf8b4c7085f84285c19085',
12
12
  },
13
13
  },
14
14
  [constants_1.Network.ARBITRUM]: {
15
15
  commonAddresses: {
16
16
  liquidityProxy: '0x52Aa899454998Be5b000Ad077a46Bbe360F4e497',
17
- resolver: '0xCe6F4E40152a1DF97ae95a7e4F60D944871A4060',
17
+ resolver: '0xb8f526718FF58758E256D9aD86bC194a9ff5986D',
18
18
  dexFactory: '0x91716C4EDA1Fb55e84Bf8b4c7085f84285c19085',
19
19
  },
20
20
  },
@@ -1 +1 @@
1
- export declare const MIN_SWAP_LIQUIDITY = 8500n;
1
+ export declare const MIN_SWAP_LIQUIDITY: bigint;
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MIN_SWAP_LIQUIDITY = void 0;
4
- // on-chain we use 1e4 but use extra buffer to avoid reverts
5
- exports.MIN_SWAP_LIQUIDITY = 8500n;
4
+ exports.MIN_SWAP_LIQUIDITY = 10n ** 4n;
6
5
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/dex/fluid-dex/constants.ts"],"names":[],"mappings":";;;AAAA,4DAA4D;AAC/C,QAAA,kBAAkB,GAAG,KAAK,CAAC"}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/dex/fluid-dex/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,kBAAkB,GAAG,GAAG,IAAI,EAAE,CAAC"}
@@ -0,0 +1,49 @@
1
+ import { Interface } from '@ethersproject/abi';
2
+ import { BytesLike } from 'ethers/lib/utils';
3
+ import { DeepReadonly } from 'ts-essentials';
4
+ import { Log, Logger } from '../../types';
5
+ import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
6
+ import { IDexHelper } from '../../dex-helper/idex-helper';
7
+ import { CommonAddresses, Pool } from './types';
8
+ import { MultiResult } from '../../lib/multi-wrapper';
9
+ import { Address } from '../../types';
10
+ export declare class FluidDexCommonAddresses extends StatefulEventSubscriber<Pool[]> {
11
+ readonly parentName: string;
12
+ readonly commonAddresses: CommonAddresses;
13
+ protected network: number;
14
+ protected dexHelper: IDexHelper;
15
+ handlers: {
16
+ [event: string]: (event: any, state: DeepReadonly<Pool[]>, log: Readonly<Log>) => Promise<DeepReadonly<Pool[]> | null>;
17
+ };
18
+ logDecoder: (log: Log) => any;
19
+ addressesSubscribed: Address[];
20
+ protected dexFactoryIface: Interface;
21
+ protected resolverIface: Interface;
22
+ constructor(parentName: string, commonAddresses: CommonAddresses, network: number, dexHelper: IDexHelper, logger: Logger);
23
+ /**
24
+ * Handle a trade rate change on the pool.
25
+ */
26
+ handleDexDeployed(event: any, state: DeepReadonly<Pool[]>, log: Readonly<Log>): Promise<DeepReadonly<Pool[]> | null>;
27
+ decodePool: (result: MultiResult<BytesLike> | BytesLike) => Pool;
28
+ /**
29
+ * The function is called every time any of the subscribed
30
+ * addresses release log. The function accepts the current
31
+ * state, updates the state according to the log, and returns
32
+ * the updated state.
33
+ * @param state - Current state of event subscriber
34
+ * @param log - Log released by one of the subscribed addresses
35
+ * @returns Updates state of the event subscriber after the log
36
+ */
37
+ processLog(state: DeepReadonly<Pool[]>, log: Readonly<Log>): Promise<DeepReadonly<Pool[]> | null>;
38
+ getStateOrGenerate(blockNumber: number, readonly?: boolean): Promise<DeepReadonly<Pool[]>>;
39
+ /**
40
+ * The function generates state using on-chain calls. This
41
+ * function is called to regenerate state if the event based
42
+ * system fails to fetch events and the local state is no
43
+ * more correct.
44
+ * @param blockNumber - Blocknumber for which the state should
45
+ * should be generated
46
+ * @returns state of the event subscriber at blocknumber
47
+ */
48
+ generateState(blockNumber: number): Promise<DeepReadonly<Pool[]>>;
49
+ }
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.FluidDexCommonAddresses = void 0;
7
+ const abi_1 = require("@ethersproject/abi");
8
+ const utils_1 = require("../../utils");
9
+ const stateful_event_subscriber_1 = require("../../stateful-event-subscriber");
10
+ const resolver_abi_json_1 = __importDefault(require("../../abi/fluid-dex/resolver.abi.json"));
11
+ const dexFactory_abi_json_1 = __importDefault(require("../../abi/fluid-dex/dexFactory.abi.json"));
12
+ const decoders_1 = require("../../lib/decoders");
13
+ const ethers_1 = require("ethers");
14
+ class FluidDexCommonAddresses extends stateful_event_subscriber_1.StatefulEventSubscriber {
15
+ constructor(parentName, commonAddresses, network, dexHelper, logger) {
16
+ super(parentName, 'getAllPools', dexHelper, logger);
17
+ this.parentName = parentName;
18
+ this.commonAddresses = commonAddresses;
19
+ this.network = network;
20
+ this.dexHelper = dexHelper;
21
+ this.handlers = {};
22
+ this.dexFactoryIface = new abi_1.Interface(dexFactory_abi_json_1.default);
23
+ this.resolverIface = new abi_1.Interface(resolver_abi_json_1.default);
24
+ this.decodePool = (result) => {
25
+ return (0, decoders_1.generalDecoder)(result, ['tuple(address pool, address token0, address token1, uint256 fee)'], undefined, decoded => {
26
+ return {
27
+ address: decoded[0].toLowerCase(),
28
+ token0: decoded[1].toLowerCase(),
29
+ token1: decoded[2].toLowerCase(),
30
+ };
31
+ });
32
+ };
33
+ this.logDecoder = (log) => this.dexFactoryIface.parseLog(log);
34
+ this.addressesSubscribed = [commonAddresses.dexFactory];
35
+ // Add handlers
36
+ this.handlers['DexDeployed'] = this.handleDexDeployed.bind(this);
37
+ }
38
+ /**
39
+ * Handle a trade rate change on the pool.
40
+ */
41
+ async handleDexDeployed(event, state, log) {
42
+ const blockNumber_ = await this.dexHelper.provider.getBlockNumber();
43
+ return this.getStateOrGenerate(blockNumber_, false);
44
+ }
45
+ /**
46
+ * The function is called every time any of the subscribed
47
+ * addresses release log. The function accepts the current
48
+ * state, updates the state according to the log, and returns
49
+ * the updated state.
50
+ * @param state - Current state of event subscriber
51
+ * @param log - Log released by one of the subscribed addresses
52
+ * @returns Updates state of the event subscriber after the log
53
+ */
54
+ async processLog(state, log) {
55
+ try {
56
+ let event;
57
+ try {
58
+ event = this.logDecoder(log);
59
+ }
60
+ catch (e) {
61
+ return null;
62
+ }
63
+ if (event.name in this.handlers) {
64
+ return await this.handlers[event.name](event, state, log);
65
+ }
66
+ }
67
+ catch (e) {
68
+ (0, utils_1.catchParseLogError)(e, this.logger);
69
+ }
70
+ return null;
71
+ }
72
+ async getStateOrGenerate(blockNumber, readonly = false) {
73
+ let state = this.getState(blockNumber);
74
+ if (!state) {
75
+ state = await this.generateState(blockNumber);
76
+ if (!readonly)
77
+ this.setState(state, blockNumber);
78
+ }
79
+ return state;
80
+ }
81
+ /**
82
+ * The function generates state using on-chain calls. This
83
+ * function is called to regenerate state if the event based
84
+ * system fails to fetch events and the local state is no
85
+ * more correct.
86
+ * @param blockNumber - Blocknumber for which the state should
87
+ * should be generated
88
+ * @returns state of the event subscriber at blocknumber
89
+ */
90
+ async generateState(blockNumber) {
91
+ const resolverContract = new ethers_1.Contract(this.commonAddresses.resolver, resolver_abi_json_1.default, this.dexHelper.provider);
92
+ const rawResult = await resolverContract.callStatic.getAllPools({
93
+ blockTag: blockNumber,
94
+ });
95
+ const pools = rawResult.map((result) => ({
96
+ address: result[0],
97
+ token0: result[1],
98
+ token1: result[2],
99
+ }));
100
+ return pools;
101
+ }
102
+ }
103
+ exports.FluidDexCommonAddresses = FluidDexCommonAddresses;
104
+ //# sourceMappingURL=fluid-dex-generate-pool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fluid-dex-generate-pool.js","sourceRoot":"","sources":["../../../src/dex/fluid-dex/fluid-dex-generate-pool.ts"],"names":[],"mappings":";;;;;;AAAA,4CAA+C;AAI/C,uCAAiD;AACjD,+EAA0E;AAE1E,8FAAgE;AAChE,kGAAoE;AAIpE,iDAAoD;AACpD,mCAAkC;AAElC,MAAa,uBAAwB,SAAQ,mDAA+B;IAe1E,YACW,UAAkB,EAClB,eAAgC,EAC/B,OAAe,EACf,SAAqB,EAC/B,MAAc;QAEd,KAAK,CAAC,UAAU,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;QAN3C,eAAU,GAAV,UAAU,CAAQ;QAClB,oBAAe,GAAf,eAAe,CAAiB;QAC/B,YAAO,GAAP,OAAO,CAAQ;QACf,cAAS,GAAT,SAAS,CAAY;QAlBjC,aAAQ,GAMJ,EAAE,CAAC;QAKG,oBAAe,GAAG,IAAI,eAAS,CAAC,6BAAa,CAAC,CAAC;QAC/C,kBAAa,GAAG,IAAI,eAAS,CAAC,2BAAW,CAAC,CAAC;QA8BrD,eAAU,GAAG,CAAC,MAA0C,EAAQ,EAAE;YAChE,OAAO,IAAA,yBAAc,EACnB,MAAM,EACN,CAAC,kEAAkE,CAAC,EACpE,SAAS,EACT,OAAO,CAAC,EAAE;gBACR,OAAO;oBACL,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE;oBACjC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE;oBAChC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE;iBACjC,CAAC;YACJ,CAAC,CACF,CAAC;QACJ,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AC,WAAW,CAAC,CAAC;QACvC,IAAI,CAAC,KAAK,EAAE;YACV,KAAK,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;YAC9C,IAAI,CAAC,QAAQ;gBAAE,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;SAClD;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,aAAa,CAAC,WAAmB;QACrC,MAAM,gBAAgB,GAAG,IAAI,iBAAQ,CACnC,IAAI,CAAC,eAAe,CAAC,QAAQ,EAC7B,2BAAW,EACX,IAAI,CAAC,SAAS,CAAC,QAAQ,CACxB,CAAC;QACF,MAAM,SAAS,GAAG,MAAM,gBAAgB,CAAC,UAAU,CAAC,WAAW,CAAC;YAC9D,QAAQ,EAAE,WAAW;SACtB,CAAC,CAAC;QAEH,MAAM,KAAK,GAAW,SAAS,CAAC,GAAG,CAAC,CAAC,MAAW,EAAE,EAAE,CAAC,CAAC;YACpD,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;YAClB,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;YACjB,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;SAClB,CAAC,CAAC,CAAC;QAEJ,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AA/HD,0DA+HC"}
@@ -88,9 +88,8 @@ class FluidDexLiquidityProxy extends stateful_event_subscriber_1.StatefulEventSu
88
88
  }
89
89
  convertToFluidDexPoolState(poolReserves) {
90
90
  const result = poolReserves.map(poolReserve => {
91
- const [pool, token0, token1, feeHex, centerPriceHex, collateralReservesHex, debtReservesHex, dexLimitsHex,] = poolReserve;
91
+ const [pool, token0, token1, feeHex, collateralReservesHex, debtReservesHex, dexLimitsHex,] = poolReserve;
92
92
  const fee = Number(feeHex.toString());
93
- const centerPrice = Number(centerPriceHex.toString());
94
93
  const collateralReserves = {
95
94
  token0RealReserves: (0, utils_1.bigIntify)(collateralReservesHex[0]),
96
95
  token1RealReserves: (0, utils_1.bigIntify)(collateralReservesHex[1]),
@@ -136,7 +135,6 @@ class FluidDexLiquidityProxy extends stateful_event_subscriber_1.StatefulEventSu
136
135
  token0,
137
136
  token1,
138
137
  fee,
139
- centerPrice,
140
138
  collateralReserves,
141
139
  debtReserves,
142
140
  dexLimits,
@@ -1 +1 @@
1
- {"version":3,"file":"fluid-dex-liquidity-proxy.js","sourceRoot":"","sources":["../../../src/dex/fluid-dex/fluid-dex-liquidity-proxy.ts"],"names":[],"mappings":";;;;;;AAAA,4CAA+C;AAG/C,uCAA4D;AAC5D,+EAA0E;AAE1E,8FAAgE;AAChE,oHAA4E;AAQ5E,mCAAkC;AAElC,MAAa,sBAAuB,SAAQ,mDAAoD;IAoBnF;IACA;IACC;IACD;IAtBX,QAAQ,GAMJ,EAAE,CAAC;IAEP,UAAU,CAAoB;IAE9B,mBAAmB,CAAY;IAEtB,cAAc,GAAG,IAAI,eAAS,CAAC,sCAAY,CAAC,CAAC;IAE7C,aAAa,GAAG,IAAI,eAAS,CAAC,2BAAW,CAAC,CAAC;IAEpD,gBAAgB,CAAW;IAE3B,YACW,UAAkB,EAClB,eAAgC,EAC/B,OAAe,EAChB,SAAqB,EAC9B,MAAc;QAEd,KAAK,CAAC,UAAU,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;QAN/C,eAAU,GAAV,UAAU,CAAQ;QAClB,oBAAe,GAAf,eAAe,CAAiB;QAC/B,YAAO,GAAP,OAAO,CAAQ;QAChB,cAAS,GAAT,SAAS,CAAY;QAK9B,IAAI,CAAC,UAAU,GAAG,CAAC,GAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QAElE,IAAI,CAAC,gBAAgB,GAAG,IAAI,iBAAQ,CAClC,IAAI,CAAC,eAAe,CAAC,QAAQ,EAC7B,2BAAW,EACX,IAAI,CAAC,SAAS,CAAC,QAAQ,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;YAEF,MAAM,gBAAgB,GAAG;gBACvB,SAAS,EAAE,IAAA,iBAAS,EAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACxC,SAAS,EAAE,IAAA,iBAAS,EAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACxC,eAAe,EAAE,IAAA,iBAAS,EAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;aAC/C,CAAC;YAEF,MAAM,gBAAgB,GAAG;gBACvB,SAAS,EAAE,IAAA,iBAAS,EAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACxC,SAAS,EAAE,IAAA,iBAAS,EAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACxC,eAAe,EAAE,IAAA,iBAAS,EAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;aAC/C,CAAC;YAEF,MAAM,SAAS,GAAG;gBAChB,kBAAkB;gBAClB,kBAAkB;gBAClB,gBAAgB;gBAChB,gBAAgB;aACjB,CAAC;YAEF,OAAO;gBACL,IAAI;gBACJ,MAAM;gBACN,MAAM;gBACN,GAAG;gBACH,kBAAkB;gBAClB,YAAY;gBACZ,SAAS;aACV,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC;IACnC,CAAC;CACF;AA7LD,wDA6LC"}
@@ -23,6 +23,7 @@ export declare class FluidDex extends SimpleExchange implements IDex<FluidDexDat
23
23
  }[];
24
24
  logger: Logger;
25
25
  pools: FluidDexPool[];
26
+ restrictedIds: string[];
26
27
  eventPools: FluidDexEventPool[];
27
28
  readonly factory: FluidDexFactory;
28
29
  readonly liquidityProxy: FluidDexLiquidityProxy;
@@ -51,7 +52,7 @@ export declare class FluidDex extends SimpleExchange implements IDex<FluidDexDat
51
52
  * @param outDecimals - The number of decimals for the output token.
52
53
  * @returns The calculated output amount (as a BigInt).
53
54
  */
54
- swapIn(swap0To1: boolean, amountIn: bigint, colReserves: CollateralReserves, debtReserves: DebtReserves, inDecimals: number, outDecimals: number, fee: bigint, currentLimits: DexLimits, centerPrice: bigint, syncTime: number): bigint;
55
+ swapIn(swap0To1: boolean, amountIn: bigint, colReserves: CollateralReserves, debtReserves: DebtReserves, inDecimals: number, outDecimals: number, fee: bigint, currentLimits: DexLimits, syncTime: number): bigint;
55
56
  /**
56
57
  * Calculates the output amount for a given input amount in a swap operation.
57
58
  * @param swap0To1 - Direction of the swap. True if swapping token0 for token1, false otherwise.
@@ -60,7 +61,7 @@ export declare class FluidDex extends SimpleExchange implements IDex<FluidDexDat
60
61
  * @param debtReserves - The reserves of the debt pool.
61
62
  * @returns The calculated output amount.
62
63
  */
63
- swapInAdjusted(swap0To1: boolean, amountToSwap: bigint, colReserves: CollateralReserves, debtReserves: DebtReserves, fee: bigint, outDecimals: number, currentLimits: DexLimits, centerPrice: bigint, syncTime: number): bigint;
64
+ swapInAdjusted(swap0To1: boolean, amountToSwap: bigint, colReserves: CollateralReserves, debtReserves: DebtReserves, fee: bigint, outDecimals: number, currentLimits: DexLimits, syncTime: number): bigint;
64
65
  /**
65
66
  * Checks if token0 reserves are sufficient compared to token1 reserves.
66
67
  * This helps prevent edge cases and ensures high precision in calculations.
@@ -139,7 +140,7 @@ export declare class FluidDex extends SimpleExchange implements IDex<FluidDexDat
139
140
  * @param {number} fee - The fee for the swap. 1e4 = 1%
140
141
  * @returns {bigint} amountIn - The calculated input amount required for the swap.
141
142
  */
142
- swapOut(swap0to1: boolean, amountOut: bigint, colReserves: CollateralReserves, debtReserves: DebtReserves, inDecimals: number, outDecimals: number, fee: bigint, currentLimits: DexLimits, centerPrice: bigint, syncTime: number): bigint;
143
+ swapOut(swap0to1: boolean, amountOut: bigint, colReserves: CollateralReserves, debtReserves: DebtReserves, inDecimals: number, outDecimals: number, fee: bigint, currentLimits: DexLimits, syncTime: number): bigint;
143
144
  /**
144
145
  * Calculates the input amount for a given output amount in a swap operation.
145
146
  * @param {boolean} swap0to1 - Direction of the swap. True if swapping token0 for token1, false otherwise.
@@ -148,7 +149,7 @@ export declare class FluidDex extends SimpleExchange implements IDex<FluidDexDat
148
149
  * @param {DebtReserves} debtReserves - The reserves of the debt pool.
149
150
  * @returns {bigint} The calculated input amount required for the swap.
150
151
  */
151
- swapOutAdjusted(swap0to1: boolean, amountOut: bigint, colReserves: CollateralReserves, debtReserves: DebtReserves, fee: bigint, outDecimals: number, currentLimits: DexLimits, centerPrice: bigint, syncTime: number): bigint;
152
+ swapOutAdjusted(swap0to1: boolean, amountOut: bigint, colReserves: CollateralReserves, debtReserves: DebtReserves, fee: bigint, outDecimals: number, currentLimits: DexLimits, syncTime: number): bigint;
152
153
  private applyFeeForBuy;
153
154
  private applyFeeForSell;
154
155
  private abs;
@@ -62,6 +62,10 @@ class FluidDex extends simple_exchange_1.SimpleExchange {
62
62
  static dexKeysWithNetwork = (0, utils_1.getDexKeysWithNetwork)(config_1.FluidDexConfig);
63
63
  logger;
64
64
  pools = [];
65
+ // temporarily limit FLUID-ETH Dex Pool.
66
+ restrictedIds = [
67
+ 'FluidDex_0xc800b0e15c40a1ff0539218100c86f4c1bac8d9c',
68
+ ];
65
69
  eventPools = [];
66
70
  factory;
67
71
  liquidityProxy;
@@ -94,7 +98,7 @@ class FluidDex extends simple_exchange_1.SimpleExchange {
94
98
  // implement this function
95
99
  async initializePricing(blockNumber) {
96
100
  await this.factory.initialize(blockNumber);
97
- this.pools = await this.fetchFluidDexPools(blockNumber);
101
+ this.pools = (await this.fetchFluidDexPools(blockNumber)).filter(pool => !this.restrictedIds.includes(pool.id));
98
102
  this.eventPools = await Promise.all(this.pools.map(async (pool) => {
99
103
  const eventPool = new fluid_dex_pool_1.FluidDexEventPool(this.dexKey, pool.address, this.network, this.dexHelper, this.logger);
100
104
  await eventPool.initialize(blockNumber);
@@ -106,7 +110,7 @@ class FluidDex extends simple_exchange_1.SimpleExchange {
106
110
  return null;
107
111
  }
108
112
  onPoolCreatedUpdatePools(poolsFromFactory) {
109
- this.pools = this.generateFluidDexPoolsFromPoolsFactory(poolsFromFactory);
113
+ this.pools = this.generateFluidDexPoolsFromPoolsFactory(poolsFromFactory).filter(pool => !this.restrictedIds.includes(pool.id));
110
114
  this.logger.info(`${this.dexKey}: pools list was updated ...`);
111
115
  }
112
116
  decodePools = (result) => {
@@ -132,6 +136,7 @@ class FluidDex extends simple_exchange_1.SimpleExchange {
132
136
  // A pair must have 2 different tokens.
133
137
  if (srcAddress === destAddress)
134
138
  return [];
139
+ this.pools = this.pools.filter(pool => !this.restrictedIds.includes(pool.id));
135
140
  const pools = this.pools.filter(pool => (srcAddress === pool.token0 && destAddress === pool.token1) ||
136
141
  (srcAddress === pool.token1 && destAddress === pool.token0));
137
142
  return pools;
@@ -166,10 +171,10 @@ class FluidDex extends simple_exchange_1.SimpleExchange {
166
171
  }
167
172
  const prices = amounts.map(amount => {
168
173
  if (side === constants_1.SwapSide.SELL) {
169
- return this.swapIn(srcToken.address.toLowerCase() === pool.token0.toLowerCase(), amount, currentPoolReserves.collateralReserves, currentPoolReserves.debtReserves, srcToken.decimals, destToken.decimals, BigInt(currentPoolReserves.fee), currentPoolReserves.dexLimits, BigInt(currentPoolReserves.centerPrice), Math.floor(Date.now() / 1000));
174
+ return this.swapIn(srcToken.address.toLowerCase() === pool.token0.toLowerCase(), amount, currentPoolReserves.collateralReserves, currentPoolReserves.debtReserves, srcToken.decimals, destToken.decimals, BigInt(currentPoolReserves.fee), currentPoolReserves.dexLimits, Math.floor(Date.now() / 1000));
170
175
  }
171
176
  else {
172
- return this.swapOut(srcToken.address.toLowerCase() === pool.token0.toLowerCase(), amount, currentPoolReserves.collateralReserves, currentPoolReserves.debtReserves, srcToken.decimals, destToken.decimals, BigInt(currentPoolReserves.fee), currentPoolReserves.dexLimits, BigInt(currentPoolReserves.centerPrice), Math.floor(Date.now() / 1000));
177
+ return this.swapOut(srcToken.address.toLowerCase() === pool.token0.toLowerCase(), amount, currentPoolReserves.collateralReserves, currentPoolReserves.debtReserves, srcToken.decimals, destToken.decimals, BigInt(currentPoolReserves.fee), currentPoolReserves.dexLimits, Math.floor(Date.now() / 1000));
173
178
  }
174
179
  });
175
180
  return {
@@ -189,7 +194,6 @@ class FluidDex extends simple_exchange_1.SimpleExchange {
189
194
  }
190
195
  catch (e) {
191
196
  this.logger.error(`Error_getPricesVolume ${srcToken.address || srcToken.symbol}, ${destToken.address || destToken.symbol}, ${side}:`, e);
192
- throw e;
193
197
  return null;
194
198
  }
195
199
  }
@@ -234,20 +238,10 @@ class FluidDex extends simple_exchange_1.SimpleExchange {
234
238
  }
235
239
  else {
236
240
  if (pool.token0.toLowerCase() !== srcToken.toLowerCase()) {
237
- args = [
238
- false,
239
- (BigInt(destAmount) * 1000001n) / 1000000n, // 0.0001% increase target out amount when calling Fluid Dex as it is not 100% exact. Guarantees meeting reaching exact out amount condition
240
- BigInt(srcAmount),
241
- recipient,
242
- ];
241
+ args = [false, BigInt(destAmount), BigInt(srcAmount), recipient];
243
242
  }
244
243
  else {
245
- args = [
246
- true,
247
- (BigInt(destAmount) * 1000001n) / 1000000n, // 0.0001% increase target out amount when calling Fluid Dex as it is not 100% exact. Guarantees meeting reaching exact out amount condition
248
- BigInt(srcAmount),
249
- recipient,
250
- ];
244
+ args = [true, BigInt(destAmount), BigInt(srcAmount), recipient];
251
245
  }
252
246
  }
253
247
  const swapData = this.fluidDexPoolIface.encodeFunctionData(method, args);
@@ -270,7 +264,7 @@ class FluidDex extends simple_exchange_1.SimpleExchange {
270
264
  * @param outDecimals - The number of decimals for the output token.
271
265
  * @returns The calculated output amount (as a BigInt).
272
266
  */
273
- swapIn(swap0To1, amountIn, colReserves, debtReserves, inDecimals, outDecimals, fee, currentLimits, centerPrice, syncTime) {
267
+ swapIn(swap0To1, amountIn, colReserves, debtReserves, inDecimals, outDecimals, fee, currentLimits, syncTime) {
274
268
  if (amountIn === 0n) {
275
269
  return 0n; // Return 0 if input amount is 0
276
270
  }
@@ -279,7 +273,7 @@ class FluidDex extends simple_exchange_1.SimpleExchange {
279
273
  return 0n;
280
274
  }
281
275
  const amountInAdjusted = (amountIn * BigInt(10 ** 12)) / BigInt(10 ** inDecimals);
282
- const amountOut = this.swapInAdjusted(swap0To1, amountInAdjusted, colReserves, debtReserves, fee, outDecimals, currentLimits, centerPrice, syncTime);
276
+ const amountOut = this.swapInAdjusted(swap0To1, amountInAdjusted, colReserves, debtReserves, fee, outDecimals, currentLimits, syncTime);
283
277
  return (amountOut * BigInt(10 ** outDecimals)) / BigInt(10 ** 12);
284
278
  }
285
279
  /**
@@ -290,7 +284,7 @@ class FluidDex extends simple_exchange_1.SimpleExchange {
290
284
  * @param debtReserves - The reserves of the debt pool.
291
285
  * @returns The calculated output amount.
292
286
  */
293
- swapInAdjusted(swap0To1, amountToSwap, colReserves, debtReserves, fee, outDecimals, currentLimits, centerPrice, syncTime) {
287
+ swapInAdjusted(swap0To1, amountToSwap, colReserves, debtReserves, fee, outDecimals, currentLimits, syncTime) {
294
288
  const { token0RealReserves, token1RealReserves, token0ImaginaryReserves, token1ImaginaryReserves, } = colReserves;
295
289
  const { token0RealReserves: debtToken0RealReserves, token1RealReserves: debtToken1RealReserves, token0ImaginaryReserves: debtToken0ImaginaryReserves, token1ImaginaryReserves: debtToken1ImaginaryReserves, } = debtReserves;
296
290
  // Check if all reserves of collateral pool are greater than 0
@@ -380,22 +374,6 @@ class FluidDex extends simple_exchange_1.SimpleExchange {
380
374
  if (amountOutCollateral > withdrawable) {
381
375
  return 0n;
382
376
  }
383
- if (amountInCollateral > 0) {
384
- let reservesRatioValid = swap0To1
385
- ? this.verifyToken1Reserves(colReserveIn + amountInCollateral, colReserveOut - amountOutCollateral, centerPrice)
386
- : this.verifyToken0Reserves(colReserveOut - amountOutCollateral, colReserveIn + amountInCollateral, centerPrice);
387
- if (!reservesRatioValid) {
388
- return 0n;
389
- }
390
- }
391
- if (amountInDebt > 0) {
392
- let reservesRatioValid = swap0To1
393
- ? this.verifyToken1Reserves(debtReserveIn + amountInDebt, debtReserveOut - amountOutDebt, centerPrice)
394
- : this.verifyToken0Reserves(debtReserveOut - amountOutDebt, debtReserveIn + amountInDebt, centerPrice);
395
- if (!reservesRatioValid) {
396
- return 0n;
397
- }
398
- }
399
377
  // For price calculations, we'll use a precision factor for bigint division
400
378
  const PRECISION = 1000000000000000000000000000n; // 1e27
401
379
  let oldPrice;
@@ -429,6 +407,22 @@ class FluidDex extends simple_exchange_1.SimpleExchange {
429
407
  if (priceDiff > maxAllowedDiff) {
430
408
  return 0n;
431
409
  }
410
+ if (amountInCollateral > 0) {
411
+ let reservesRatioValid = swap0To1
412
+ ? this.verifyToken1Reserves(colReserveIn + amountInCollateral, colReserveOut - amountOutCollateral, oldPrice)
413
+ : this.verifyToken0Reserves(colReserveOut - amountOutCollateral, colReserveIn + amountInCollateral, oldPrice);
414
+ if (!reservesRatioValid) {
415
+ return 0n;
416
+ }
417
+ }
418
+ if (amountInDebt > 0) {
419
+ let reservesRatioValid = swap0To1
420
+ ? this.verifyToken1Reserves(debtReserveIn + amountInDebt, debtReserveOut - amountOutDebt, oldPrice)
421
+ : this.verifyToken0Reserves(debtReserveOut - amountOutDebt, debtReserveIn + amountInDebt, oldPrice);
422
+ if (!reservesRatioValid) {
423
+ return 0n;
424
+ }
425
+ }
432
426
  const totalAmountOut = amountOutCollateral + amountOutDebt;
433
427
  return totalAmountOut;
434
428
  }
@@ -566,14 +560,14 @@ class FluidDex extends simple_exchange_1.SimpleExchange {
566
560
  * @param {number} fee - The fee for the swap. 1e4 = 1%
567
561
  * @returns {bigint} amountIn - The calculated input amount required for the swap.
568
562
  */
569
- swapOut(swap0to1, amountOut, colReserves, debtReserves, inDecimals, outDecimals, fee, currentLimits, centerPrice, syncTime) {
563
+ swapOut(swap0to1, amountOut, colReserves, debtReserves, inDecimals, outDecimals, fee, currentLimits, syncTime) {
570
564
  const amountOutAdjusted = (amountOut * BigInt(10 ** 12)) / BigInt(10 ** outDecimals);
571
- const amountIn = this.swapOutAdjusted(swap0to1, amountOutAdjusted, colReserves, debtReserves, fee, outDecimals, currentLimits, centerPrice, syncTime);
565
+ const amountIn = this.swapOutAdjusted(swap0to1, amountOutAdjusted, colReserves, debtReserves, fee, outDecimals, currentLimits, syncTime);
572
566
  if (amountIn === 2n ** 256n - 1n) {
573
567
  return amountIn;
574
568
  }
575
569
  const ans = (amountIn * BigInt(10 ** inDecimals)) / BigInt(10 ** 12);
576
- return (ans * (100000n - 5n)) / 100000n;
570
+ return ans;
577
571
  }
578
572
  /**
579
573
  * Calculates the input amount for a given output amount in a swap operation.
@@ -583,7 +577,7 @@ class FluidDex extends simple_exchange_1.SimpleExchange {
583
577
  * @param {DebtReserves} debtReserves - The reserves of the debt pool.
584
578
  * @returns {bigint} The calculated input amount required for the swap.
585
579
  */
586
- swapOutAdjusted(swap0to1, amountOut, colReserves, debtReserves, fee, outDecimals, currentLimits, centerPrice, syncTime) {
580
+ swapOutAdjusted(swap0to1, amountOut, colReserves, debtReserves, fee, outDecimals, currentLimits, syncTime) {
587
581
  if (amountOut === 0n) {
588
582
  return 0n; // Return 0 if output amount is 0
589
583
  }
@@ -653,10 +647,10 @@ class FluidDex extends simple_exchange_1.SimpleExchange {
653
647
  amountInDebt = this.getAmountIn(amountOut, debtIReserveIn, debtIReserveOut);
654
648
  amountInDebt = this.applyFeeForBuy(amountInDebt, fee);
655
649
  if (amountOut > debtReserveOut) {
656
- return 0n;
650
+ return 2n ** 256n - 1n;
657
651
  }
658
652
  if (amountOut > borrowable) {
659
- return 0n;
653
+ return 2n ** 256n - 1n;
660
654
  }
661
655
  }
662
656
  else if (a >= amountOut) {
@@ -665,10 +659,10 @@ class FluidDex extends simple_exchange_1.SimpleExchange {
665
659
  amountInCollateral = this.getAmountIn(amountOut, colIReserveIn, colIReserveOut);
666
660
  amountInCollateral = this.applyFeeForBuy(amountInCollateral, fee);
667
661
  if (amountOut > colReserveOut) {
668
- return 0n;
662
+ return 2n ** 256n - 1n;
669
663
  }
670
664
  if (amountOut > withdrawable) {
671
- return 0n;
665
+ return 2n ** 256n - 1n;
672
666
  }
673
667
  }
674
668
  else {
@@ -680,26 +674,10 @@ class FluidDex extends simple_exchange_1.SimpleExchange {
680
674
  amountInDebt = this.getAmountIn(amountOutDebtAdjusted, debtIReserveIn, debtIReserveOut);
681
675
  amountInDebt = this.applyFeeForBuy(amountInDebt, fee);
682
676
  if (amountOutDebt > debtReserveOut || a > colReserveOut) {
683
- return 0n;
677
+ return 2n ** 256n - 1n;
684
678
  }
685
679
  if (amountOutDebt > borrowable || a > withdrawable) {
686
- return 0n;
687
- }
688
- }
689
- if (amountInCollateral > 0) {
690
- let reservesRatioValid = swap0to1
691
- ? this.verifyToken1Reserves(colReserveIn + amountInCollateral, colReserveOut - amountOutCollateral, centerPrice)
692
- : this.verifyToken0Reserves(colReserveOut - amountOutCollateral, colReserveIn + amountInCollateral, centerPrice);
693
- if (!reservesRatioValid) {
694
- return 0n;
695
- }
696
- }
697
- if (amountInDebt > 0) {
698
- let reservesRatioValid = swap0to1
699
- ? this.verifyToken1Reserves(debtReserveIn + amountInDebt, debtReserveOut - amountOutDebt, centerPrice)
700
- : this.verifyToken0Reserves(debtReserveOut - amountOutDebt, debtReserveIn + amountInDebt, centerPrice);
701
- if (!reservesRatioValid) {
702
- return 0n;
680
+ return 2n ** 256n - 1n;
703
681
  }
704
682
  }
705
683
  let oldPrice;
@@ -732,7 +710,23 @@ class FluidDex extends simple_exchange_1.SimpleExchange {
732
710
  if (this.abs(oldPrice - newPrice) >
733
711
  (oldPrice / BigInt(100)) * MAX_PRICE_DIFF) {
734
712
  // if price diff is > 5% then swap would revert.
735
- return 0n;
713
+ return 2n ** 256n - 1n;
714
+ }
715
+ if (amountInCollateral > 0) {
716
+ let reservesRatioValid = swap0to1
717
+ ? this.verifyToken1Reserves(colReserveIn + amountInCollateral, colReserveOut - amountOutCollateral, oldPrice)
718
+ : this.verifyToken0Reserves(colReserveOut - amountOutCollateral, colReserveIn + amountInCollateral, oldPrice);
719
+ if (!reservesRatioValid) {
720
+ return 0n;
721
+ }
722
+ }
723
+ if (amountInDebt > 0) {
724
+ let reservesRatioValid = swap0to1
725
+ ? this.verifyToken1Reserves(debtReserveIn + amountInDebt, debtReserveOut - amountOutDebt, oldPrice)
726
+ : this.verifyToken0Reserves(debtReserveOut - amountOutDebt, debtReserveIn + amountInDebt, oldPrice);
727
+ if (!reservesRatioValid) {
728
+ return 0n;
729
+ }
736
730
  }
737
731
  const totalAmountIn = amountInCollateral + amountInDebt;
738
732
  return totalAmountIn;