@paraswap/dex-lib 3.8.26 → 3.8.27-dualsync.1

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 (368) hide show
  1. package/build/dex/idex.d.ts +4 -0
  2. package/build/dex/pancakeswap-v3/pancakeswap-v3-pool.d.ts +4 -3
  3. package/build/dex/pancakeswap-v3/pancakeswap-v3-pool.js +5 -4
  4. package/build/dex/pancakeswap-v3/pancakeswap-v3-pool.js.map +1 -1
  5. package/build/dex/pancakeswap-v3/pancakeswap-v3.d.ts +5 -1
  6. package/build/dex/pancakeswap-v3/pancakeswap-v3.js +11 -2
  7. package/build/dex/pancakeswap-v3/pancakeswap-v3.js.map +1 -1
  8. package/build/dex/uniswap-v2/uniswap-v2.d.ts +11 -4
  9. package/build/dex/uniswap-v2/uniswap-v2.js +40 -13
  10. package/build/dex/uniswap-v2/uniswap-v2.js.map +1 -1
  11. package/build/dex/uniswap-v3/uniswap-v3-pool.d.ts +3 -2
  12. package/build/dex/uniswap-v3/uniswap-v3-pool.js +3 -3
  13. package/build/dex/uniswap-v3/uniswap-v3-pool.js.map +1 -1
  14. package/build/dex/uniswap-v3/uniswap-v3.d.ts +4 -0
  15. package/build/dex/uniswap-v3/uniswap-v3.js +11 -2
  16. package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
  17. package/build/dex-helper/dummy-dex-helper.d.ts +2 -0
  18. package/build/dex-helper/dummy-dex-helper.js.map +1 -1
  19. package/build/dex-helper/idex-helper.d.ts +2 -0
  20. package/build/dex-utils.d.ts +3 -0
  21. package/build/dex-utils.js +10 -0
  22. package/build/dex-utils.js.map +1 -0
  23. package/build/stateful-dual-synchronizer.d.ts +46 -0
  24. package/build/stateful-dual-synchronizer.js +300 -0
  25. package/build/stateful-dual-synchronizer.js.map +1 -0
  26. package/package.json +1 -1
  27. package/src/dex/idex.ts +8 -0
  28. package/src/dex/pancakeswap-v3/pancakeswap-v3-pool.ts +5 -10
  29. package/src/dex/pancakeswap-v3/pancakeswap-v3.ts +22 -2
  30. package/src/dex/uniswap-v2/uniswap-v2.ts +66 -16
  31. package/src/dex/uniswap-v3/uniswap-v3-pool.ts +4 -6
  32. package/src/dex/uniswap-v3/uniswap-v3.ts +28 -2
  33. package/src/dex-helper/dummy-dex-helper.ts +2 -0
  34. package/src/dex-helper/idex-helper.ts +2 -0
  35. package/src/dex-utils.ts +5 -0
  36. package/src/stateful-dual-synchronizer.ts +415 -0
  37. package/.vscode/launch.json +0 -16
  38. package/.vscode/settings.json +0 -3
  39. package/build/abi/AaveV1_lending_pool.json +0 -27
  40. package/build/abi/BProtocol.json +0 -1155
  41. package/build/abi/Jarvis.json +0 -1172
  42. package/build/abi/MStableAsset.json +0 -1545
  43. package/build/abi/OneInchLp.json +0 -1304
  44. package/build/abi/Onebit.json +0 -736
  45. package/build/abi/Shell.json +0 -1294
  46. package/build/abi/TraderJoeV2Router.json +0 -50
  47. package/build/abi/Uncompressor.json +0 -250
  48. package/build/abi/integral/factory.json +0 -333
  49. package/build/abi/integral/oracle.json +0 -501
  50. package/build/abi/integral/pool.json +0 -1041
  51. package/build/abi/integral/relayer.json +0 -1536
  52. package/build/abi/platypus/asset.json +0 -490
  53. package/build/abi/platypus/avax-pool.json +0 -820
  54. package/build/abi/platypus/oracle.json +0 -119
  55. package/build/abi/platypus/pool.json +0 -677
  56. package/build/abi/smardex/all/smardex-router.json +0 -648
  57. package/build/abi/smardex/layer-1/smardex-factory.json +0 -242
  58. package/build/abi/smardex/layer-1/smardex-pool.json +0 -506
  59. package/build/abi/smardex/layer-2/smardex-factory.json +0 -185
  60. package/build/abi/smardex/layer-2/smardex-pool.json +0 -578
  61. package/build/abi/swaap-v1/pool.json +0 -1346
  62. package/build/abi/zrx.v2.json +0 -1967
  63. package/build/abi/zrx.v3.json +0 -3454
  64. package/build/abi/zrx.v4.json +0 -2193
  65. package/build/dex/OneInchLp.d.ts +0 -24
  66. package/build/dex/OneInchLp.js +0 -43
  67. package/build/dex/OneInchLp.js.map +0 -1
  68. package/build/dex/aave-v1/aave-v1.d.ts +0 -33
  69. package/build/dex/aave-v1/aave-v1.js +0 -158
  70. package/build/dex/aave-v1/aave-v1.js.map +0 -1
  71. package/build/dex/aave-v1/config.d.ts +0 -11
  72. package/build/dex/aave-v1/config.js +0 -20
  73. package/build/dex/aave-v1/config.js.map +0 -1
  74. package/build/dex/aave-v1/tokens-mainnet.json +0 -134
  75. package/build/dex/aave-v1/tokens.d.ts +0 -3
  76. package/build/dex/aave-v1/tokens.js +0 -50
  77. package/build/dex/aave-v1/tokens.js.map +0 -1
  78. package/build/dex/aave-v1/types.d.ts +0 -12
  79. package/build/dex/aave-v1/types.js +0 -3
  80. package/build/dex/aave-v1/types.js.map +0 -1
  81. package/build/dex/bProtocol/bProtocol.d.ts +0 -15
  82. package/build/dex/bProtocol/bProtocol.js +0 -56
  83. package/build/dex/bProtocol/bProtocol.js.map +0 -1
  84. package/build/dex/bProtocol/types.d.ts +0 -11
  85. package/build/dex/bProtocol/types.js +0 -8
  86. package/build/dex/bProtocol/types.js.map +0 -1
  87. package/build/dex/bProtocol.d.ts +0 -18
  88. package/build/dex/bProtocol.js +0 -39
  89. package/build/dex/bProtocol.js.map +0 -1
  90. package/build/dex/bancor.d.ts +0 -26
  91. package/build/dex/bancor.js +0 -58
  92. package/build/dex/bancor.js.map +0 -1
  93. package/build/dex/compound.d.ts +0 -18
  94. package/build/dex/compound.js +0 -46
  95. package/build/dex/compound.js.map +0 -1
  96. package/build/dex/curve-v2.d.ts +0 -58
  97. package/build/dex/curve-v2.js +0 -180
  98. package/build/dex/curve-v2.js.map +0 -1
  99. package/build/dex/dodo-v1.d.ts +0 -33
  100. package/build/dex/dodo-v1.js +0 -63
  101. package/build/dex/dodo-v1.js.map +0 -1
  102. package/build/dex/etherfi/etherfi.d.ts +0 -26
  103. package/build/dex/etherfi/etherfi.js +0 -96
  104. package/build/dex/etherfi/etherfi.js.map +0 -1
  105. package/build/dex/integral/config.d.ts +0 -4
  106. package/build/dex/integral/config.js +0 -20
  107. package/build/dex/integral/config.js.map +0 -1
  108. package/build/dex/integral/context.d.ts +0 -40
  109. package/build/dex/integral/context.js +0 -158
  110. package/build/dex/integral/context.js.map +0 -1
  111. package/build/dex/integral/helpers.d.ts +0 -17
  112. package/build/dex/integral/helpers.js +0 -157
  113. package/build/dex/integral/helpers.js.map +0 -1
  114. package/build/dex/integral/integral-factory.d.ts +0 -24
  115. package/build/dex/integral/integral-factory.js +0 -95
  116. package/build/dex/integral/integral-factory.js.map +0 -1
  117. package/build/dex/integral/integral-pool.d.ts +0 -50
  118. package/build/dex/integral/integral-pool.js +0 -149
  119. package/build/dex/integral/integral-pool.js.map +0 -1
  120. package/build/dex/integral/integral-pricing.d.ts +0 -18
  121. package/build/dex/integral/integral-pricing.js +0 -114
  122. package/build/dex/integral/integral-pricing.js.map +0 -1
  123. package/build/dex/integral/integral-relayer.d.ts +0 -42
  124. package/build/dex/integral/integral-relayer.js +0 -192
  125. package/build/dex/integral/integral-relayer.js.map +0 -1
  126. package/build/dex/integral/integral-token.d.ts +0 -27
  127. package/build/dex/integral/integral-token.js +0 -59
  128. package/build/dex/integral/integral-token.js.map +0 -1
  129. package/build/dex/integral/integral.d.ts +0 -41
  130. package/build/dex/integral/integral.js +0 -376
  131. package/build/dex/integral/integral.js.map +0 -1
  132. package/build/dex/integral/types.d.ts +0 -85
  133. package/build/dex/integral/types.js +0 -9
  134. package/build/dex/integral/types.js.map +0 -1
  135. package/build/dex/integral/utils-e2e.d.ts +0 -9
  136. package/build/dex/integral/utils-e2e.js +0 -131
  137. package/build/dex/integral/utils-e2e.js.map +0 -1
  138. package/build/dex/integral/utils.d.ts +0 -17
  139. package/build/dex/integral/utils.js +0 -94
  140. package/build/dex/integral/utils.js.map +0 -1
  141. package/build/dex/jarvis.d.ts +0 -56
  142. package/build/dex/jarvis.js +0 -163
  143. package/build/dex/jarvis.js.map +0 -1
  144. package/build/dex/lido.d.ts +0 -19
  145. package/build/dex/lido.js +0 -42
  146. package/build/dex/lido.js.map +0 -1
  147. package/build/dex/mStable.d.ts +0 -44
  148. package/build/dex/mStable.js +0 -75
  149. package/build/dex/mStable.js.map +0 -1
  150. package/build/dex/onebit/onebit.d.ts +0 -16
  151. package/build/dex/onebit/onebit.js +0 -61
  152. package/build/dex/onebit/onebit.js.map +0 -1
  153. package/build/dex/onebit/types.d.ts +0 -14
  154. package/build/dex/onebit/types.js +0 -8
  155. package/build/dex/onebit/types.js.map +0 -1
  156. package/build/dex/onebit.d.ts +0 -25
  157. package/build/dex/onebit.js +0 -42
  158. package/build/dex/onebit.js.map +0 -1
  159. package/build/dex/platypus/asset.d.ts +0 -14
  160. package/build/dex/platypus/asset.js +0 -97
  161. package/build/dex/platypus/asset.js.map +0 -1
  162. package/build/dex/platypus/config.d.ts +0 -11
  163. package/build/dex/platypus/config.js +0 -69
  164. package/build/dex/platypus/config.js.map +0 -1
  165. package/build/dex/platypus/platypus.d.ts +0 -62
  166. package/build/dex/platypus/platypus.js +0 -442
  167. package/build/dex/platypus/platypus.js.map +0 -1
  168. package/build/dex/platypus/pool-avax.d.ts +0 -8
  169. package/build/dex/platypus/pool-avax.js +0 -54
  170. package/build/dex/platypus/pool-avax.js.map +0 -1
  171. package/build/dex/platypus/pool-base.d.ts +0 -19
  172. package/build/dex/platypus/pool-base.js +0 -86
  173. package/build/dex/platypus/pool-base.js.map +0 -1
  174. package/build/dex/platypus/pool-pure.d.ts +0 -8
  175. package/build/dex/platypus/pool-pure.js +0 -37
  176. package/build/dex/platypus/pool-pure.js.map +0 -1
  177. package/build/dex/platypus/pool-subscriber.d.ts +0 -14
  178. package/build/dex/platypus/pool-subscriber.js +0 -167
  179. package/build/dex/platypus/pool-subscriber.js.map +0 -1
  180. package/build/dex/platypus/pool.d.ts +0 -8
  181. package/build/dex/platypus/pool.js +0 -58
  182. package/build/dex/platypus/pool.js.map +0 -1
  183. package/build/dex/platypus/types.d.ts +0 -92
  184. package/build/dex/platypus/types.js +0 -10
  185. package/build/dex/platypus/types.js.map +0 -1
  186. package/build/dex/quickswap/spiritswap-v3.d.ts +0 -6
  187. package/build/dex/quickswap/spiritswap-v3.js +0 -19
  188. package/build/dex/quickswap/spiritswap-v3.js.map +0 -1
  189. package/build/dex/sdai/config.d.ts +0 -11
  190. package/build/dex/sdai/config.js +0 -21
  191. package/build/dex/sdai/config.js.map +0 -1
  192. package/build/dex/sdai/constants.d.ts +0 -2
  193. package/build/dex/sdai/constants.js +0 -6
  194. package/build/dex/sdai/constants.js.map +0 -1
  195. package/build/dex/sdai/scripts/validate-state.d.ts +0 -1
  196. package/build/dex/sdai/scripts/validate-state.js +0 -102
  197. package/build/dex/sdai/scripts/validate-state.js.map +0 -1
  198. package/build/dex/sdai/sdai-pool.d.ts +0 -16
  199. package/build/dex/sdai/sdai-pool.js +0 -85
  200. package/build/dex/sdai/sdai-pool.js.map +0 -1
  201. package/build/dex/sdai/sdai.d.ts +0 -51
  202. package/build/dex/sdai/sdai.js +0 -172
  203. package/build/dex/sdai/sdai.js.map +0 -1
  204. package/build/dex/sdai/types.d.ts +0 -21
  205. package/build/dex/sdai/types.js +0 -11
  206. package/build/dex/sdai/types.js.map +0 -1
  207. package/build/dex/sdai/utils.d.ts +0 -4
  208. package/build/dex/sdai/utils.js +0 -39
  209. package/build/dex/sdai/utils.js.map +0 -1
  210. package/build/dex/shell.d.ts +0 -25
  211. package/build/dex/shell.js +0 -41
  212. package/build/dex/shell.js.map +0 -1
  213. package/build/dex/smardex/config.d.ts +0 -4
  214. package/build/dex/smardex/config.js +0 -64
  215. package/build/dex/smardex/config.js.map +0 -1
  216. package/build/dex/smardex/constants.d.ts +0 -18
  217. package/build/dex/smardex/constants.js +0 -33
  218. package/build/dex/smardex/constants.js.map +0 -1
  219. package/build/dex/smardex/sdk/constants.d.ts +0 -6
  220. package/build/dex/smardex/sdk/constants.js +0 -13
  221. package/build/dex/smardex/sdk/constants.js.map +0 -1
  222. package/build/dex/smardex/sdk/core.d.ts +0 -113
  223. package/build/dex/smardex/sdk/core.js +0 -499
  224. package/build/dex/smardex/sdk/core.js.map +0 -1
  225. package/build/dex/smardex/sdk/errors.d.ts +0 -15
  226. package/build/dex/smardex/sdk/errors.js +0 -22
  227. package/build/dex/smardex/sdk/errors.js.map +0 -1
  228. package/build/dex/smardex/sdk/types.d.ts +0 -62
  229. package/build/dex/smardex/sdk/types.js +0 -3
  230. package/build/dex/smardex/sdk/types.js.map +0 -1
  231. package/build/dex/smardex/sdk/utils.d.ts +0 -44
  232. package/build/dex/smardex/sdk/utils.js +0 -133
  233. package/build/dex/smardex/sdk/utils.js.map +0 -1
  234. package/build/dex/smardex/smardex-event-pool.d.ts +0 -28
  235. package/build/dex/smardex/smardex-event-pool.js +0 -119
  236. package/build/dex/smardex/smardex-event-pool.js.map +0 -1
  237. package/build/dex/smardex/smardex.d.ts +0 -65
  238. package/build/dex/smardex/smardex.js +0 -519
  239. package/build/dex/smardex/smardex.js.map +0 -1
  240. package/build/dex/smardex/types.d.ts +0 -55
  241. package/build/dex/smardex/types.js +0 -3
  242. package/build/dex/smardex/types.js.map +0 -1
  243. package/build/dex/smoothy.d.ts +0 -26
  244. package/build/dex/smoothy.js +0 -48
  245. package/build/dex/smoothy.js.map +0 -1
  246. package/build/dex/solidly/forks-override/cone.d.ts +0 -22
  247. package/build/dex/solidly/forks-override/cone.js +0 -53
  248. package/build/dex/solidly/forks-override/cone.js.map +0 -1
  249. package/build/dex/solidly/forks-override/solisnek.d.ts +0 -8
  250. package/build/dex/solidly/forks-override/solisnek.js +0 -15
  251. package/build/dex/solidly/forks-override/solisnek.js.map +0 -1
  252. package/build/dex/stable-pool.d.ts +0 -28
  253. package/build/dex/stable-pool.js +0 -62
  254. package/build/dex/stable-pool.js.map +0 -1
  255. package/build/dex/swaap-v1/config.d.ts +0 -17
  256. package/build/dex/swaap-v1/config.js +0 -56
  257. package/build/dex/swaap-v1/config.js.map +0 -1
  258. package/build/dex/swaap-v1/constants.d.ts +0 -6
  259. package/build/dex/swaap-v1/constants.js +0 -17
  260. package/build/dex/swaap-v1/constants.js.map +0 -1
  261. package/build/dex/swaap-v1/libraries/ChainlinkUtils.d.ts +0 -25
  262. package/build/dex/swaap-v1/libraries/ChainlinkUtils.js +0 -62
  263. package/build/dex/swaap-v1/libraries/ChainlinkUtils.js.map +0 -1
  264. package/build/dex/swaap-v1/libraries/Const.d.ts +0 -18
  265. package/build/dex/swaap-v1/libraries/Const.js +0 -26
  266. package/build/dex/swaap-v1/libraries/Const.js.map +0 -1
  267. package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.d.ts +0 -77
  268. package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.js +0 -316
  269. package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.js.map +0 -1
  270. package/build/dex/swaap-v1/libraries/LogExpMath.d.ts +0 -75
  271. package/build/dex/swaap-v1/libraries/LogExpMath.js +0 -418
  272. package/build/dex/swaap-v1/libraries/LogExpMath.js.map +0 -1
  273. package/build/dex/swaap-v1/libraries/MathMMM.d.ts +0 -185
  274. package/build/dex/swaap-v1/libraries/MathMMM.js +0 -453
  275. package/build/dex/swaap-v1/libraries/MathMMM.js.map +0 -1
  276. package/build/dex/swaap-v1/libraries/Num.d.ts +0 -31
  277. package/build/dex/swaap-v1/libraries/Num.js +0 -167
  278. package/build/dex/swaap-v1/libraries/Num.js.map +0 -1
  279. package/build/dex/swaap-v1/libraries/PoolQuotations.d.ts +0 -23
  280. package/build/dex/swaap-v1/libraries/PoolQuotations.js +0 -131
  281. package/build/dex/swaap-v1/libraries/PoolQuotations.js.map +0 -1
  282. package/build/dex/swaap-v1/libraries/Struct.d.ts +0 -56
  283. package/build/dex/swaap-v1/libraries/Struct.js +0 -3
  284. package/build/dex/swaap-v1/libraries/Struct.js.map +0 -1
  285. package/build/dex/swaap-v1/swaap-v1-pool.d.ts +0 -45
  286. package/build/dex/swaap-v1/swaap-v1-pool.js +0 -656
  287. package/build/dex/swaap-v1/swaap-v1-pool.js.map +0 -1
  288. package/build/dex/swaap-v1/swaap-v1.d.ts +0 -61
  289. package/build/dex/swaap-v1/swaap-v1.js +0 -369
  290. package/build/dex/swaap-v1/swaap-v1.js.map +0 -1
  291. package/build/dex/swaap-v1/types.d.ts +0 -106
  292. package/build/dex/swaap-v1/types.js +0 -9
  293. package/build/dex/swaap-v1/types.js.map +0 -1
  294. package/build/dex/trader-joe-v2.1/optimizer.d.ts +0 -2
  295. package/build/dex/trader-joe-v2.1/optimizer.js +0 -44
  296. package/build/dex/trader-joe-v2.1/optimizer.js.map +0 -1
  297. package/build/dex/trader-joe-v2.1.d.ts +0 -43
  298. package/build/dex/trader-joe-v2.1.js +0 -79
  299. package/build/dex/trader-joe-v2.1.js.map +0 -1
  300. package/build/dex/trader-joe-v2.d.ts +0 -40
  301. package/build/dex/trader-joe-v2.js +0 -74
  302. package/build/dex/trader-joe-v2.js.map +0 -1
  303. package/build/dex/zerox/config.d.ts +0 -2
  304. package/build/dex/zerox/config.js +0 -33
  305. package/build/dex/zerox/config.js.map +0 -1
  306. package/build/dex/zerox/index.d.ts +0 -22
  307. package/build/dex/zerox/index.js +0 -225
  308. package/build/dex/zerox/index.js.map +0 -1
  309. package/build/dex/zerox/order.d.ts +0 -88
  310. package/build/dex/zerox/order.js +0 -53
  311. package/build/dex/zerox/order.js.map +0 -1
  312. package/build/dex/zerox/types.d.ts +0 -73
  313. package/build/dex/zerox/types.js +0 -21
  314. package/build/dex/zerox/types.js.map +0 -1
  315. package/build/executor/compressor/Compressor.d.ts +0 -23
  316. package/build/executor/compressor/Compressor.js +0 -144
  317. package/build/executor/compressor/Compressor.js.map +0 -1
  318. package/build/executor/compressor/compress.d.ts +0 -17
  319. package/build/executor/compressor/compress.js +0 -187
  320. package/build/executor/compressor/compress.js.map +0 -1
  321. package/build/executor/compressor/compress_functions/addressSubstitution.d.ts +0 -6
  322. package/build/executor/compressor/compress_functions/addressSubstitution.js +0 -29
  323. package/build/executor/compressor/compress_functions/addressSubstitution.js.map +0 -1
  324. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.d.ts +0 -10
  325. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.js +0 -40
  326. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.js.map +0 -1
  327. package/build/executor/compressor/compress_functions/byteSubstitution.d.ts +0 -11
  328. package/build/executor/compressor/compress_functions/byteSubstitution.js +0 -64
  329. package/build/executor/compressor/compress_functions/byteSubstitution.js.map +0 -1
  330. package/build/executor/compressor/compress_functions/ffSubstitution.d.ts +0 -7
  331. package/build/executor/compressor/compress_functions/ffSubstitution.js +0 -54
  332. package/build/executor/compressor/compress_functions/ffSubstitution.js.map +0 -1
  333. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.d.ts +0 -8
  334. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.js +0 -67
  335. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.js.map +0 -1
  336. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.d.ts +0 -8
  337. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.js +0 -61
  338. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.js.map +0 -1
  339. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.d.ts +0 -6
  340. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.js +0 -37
  341. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.js.map +0 -1
  342. package/build/executor/compressor/compress_functions/searchUnusedBytes.d.ts +0 -9
  343. package/build/executor/compressor/compress_functions/searchUnusedBytes.js +0 -33
  344. package/build/executor/compressor/compress_functions/searchUnusedBytes.js.map +0 -1
  345. package/build/executor/compressor/fetchSaved.d.ts +0 -0
  346. package/build/executor/compressor/fetchSaved.js +0 -17
  347. package/build/executor/compressor/fetchSaved.js.map +0 -1
  348. package/build/executor/compressor/utils/computeCostL2.d.ts +0 -2
  349. package/build/executor/compressor/utils/computeCostL2.js +0 -14
  350. package/build/executor/compressor/utils/computeCostL2.js.map +0 -1
  351. package/build/executor/compressor/utils/findLongestDuplicatedString.d.ts +0 -2
  352. package/build/executor/compressor/utils/findLongestDuplicatedString.js +0 -30
  353. package/build/executor/compressor/utils/findLongestDuplicatedString.js.map +0 -1
  354. package/build/executor/compressor/utils/getAllIndexes.d.ts +0 -2
  355. package/build/executor/compressor/utils/getAllIndexes.js +0 -12
  356. package/build/executor/compressor/utils/getAllIndexes.js.map +0 -1
  357. package/build/executor/compressor/utils/getByteForAddress.d.ts +0 -2
  358. package/build/executor/compressor/utils/getByteForAddress.js +0 -14
  359. package/build/executor/compressor/utils/getByteForAddress.js.map +0 -1
  360. package/build/executor/compressor/utils/intTo2Bytes.d.ts +0 -2
  361. package/build/executor/compressor/utils/intTo2Bytes.js +0 -14
  362. package/build/executor/compressor/utils/intTo2Bytes.js.map +0 -1
  363. package/build/executor/compressor/utils/intTo3Bytes.d.ts +0 -2
  364. package/build/executor/compressor/utils/intTo3Bytes.js +0 -18
  365. package/build/executor/compressor/utils/intTo3Bytes.js.map +0 -1
  366. package/build/executor/compressor/utils/intToByte.d.ts +0 -2
  367. package/build/executor/compressor/utils/intToByte.js +0 -10
  368. package/build/executor/compressor/utils/intToByte.js.map +0 -1
@@ -0,0 +1,300 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StatefulDualSynchronizer = void 0;
4
+ const ts_essentials_1 = require("ts-essentials");
5
+ const constants_1 = require("./constants");
6
+ const utils_1 = require("./utils");
7
+ // TODO: make sure that we can get either state object or string
8
+ class StatefulDualSynchronizer {
9
+ constructor(dexKey, poolIdentifier, dexHelper, logger) {
10
+ this.dexKey = dexKey;
11
+ this.poolIdentifier = poolIdentifier;
12
+ this.dexHelper = dexHelper;
13
+ this.logger = logger;
14
+ //The current state and its block number
15
+ //Derived classes should not set these directly, and instead use setState()
16
+ this.state = null;
17
+ this.stateBlockNumber = 0;
18
+ //Derived classes should use setState() to record a new entry
19
+ this.stateHistory = {};
20
+ //Invalid flag - indicates that the currently stored state might not be valid
21
+ this.invalid = false;
22
+ this.isTracking = () => false;
23
+ this.addressesSubscribed = [];
24
+ this.isInitialized = false;
25
+ this.dexKey = dexKey.toLowerCase();
26
+ this.poolIdentifier = poolIdentifier.toLowerCase();
27
+ // parentName and Name are imposed by the interface. Prefer dexKey and poolIdentifier
28
+ this.parentName = this.dexKey;
29
+ this.name = this.poolIdentifier;
30
+ if (!this.dexHelper.config.isSlave) {
31
+ this.dexHelper.dexStatePublisher.registerPool(this.dexKey, this.poolIdentifier, this);
32
+ }
33
+ }
34
+ getStateBlockNumber() {
35
+ return this.stateBlockNumber;
36
+ }
37
+ //Function which set the initial state and bounded it to blockNumber
38
+ //There is multiple possible case:
39
+ // 1. You provide a state in options object the function will initialize with the provided state
40
+ // with blockNumber and subscribe to logs.
41
+ // 2. if you are a master instance of dex-lib and no state is provided in options object
42
+ // then the function generate a new state with blockNumber as height and set the state with
43
+ // the result.
44
+ // 3. if you are a slave instance of dex-lib
45
+ // either:
46
+ // - If a state is found in the cache and the state is not null we set our state with the
47
+ // cache state and cache blockNumber. Subscribe to logs with the cache blockNumber
48
+ // or:
49
+ // - If no valid state found in cache, we generate a new state with blockNumber
50
+ // and se state with blockNumber. Subscribe to logs with blockNumber. The function
51
+ // will also publish a message to cache to tell one master version of dex-lib that this slave
52
+ // instance subscribed to a pool from dex this.parentName and name this.name.
53
+ async initialize(blockNumber, options) {
54
+ let masterBn = undefined;
55
+ if (options && options.state) {
56
+ this.setState(options.state, blockNumber);
57
+ }
58
+ else {
59
+ if (this.dexHelper.config.isSlave) {
60
+ let updatedState = await this.dexHelper.dexStateSubscriber.requestDEXPoolState(this.dexKey, this.poolIdentifier, blockNumber);
61
+ this.setState(updatedState, blockNumber);
62
+ }
63
+ else {
64
+ // if you are not a slave instance always generate new state
65
+ this.logger.info(`${this.dexKey}: ${this.poolIdentifier}: cache generating state`);
66
+ const state = await this.generateState(blockNumber);
67
+ this.setState(state, blockNumber);
68
+ }
69
+ }
70
+ // apply a callback on the state
71
+ if (options && options.initCallback) {
72
+ if (this.state) {
73
+ (0, ts_essentials_1.assert)(typeof this.state !== 'string', 'LOGIC ERROR: state is serialised');
74
+ options.initCallback(this.state);
75
+ }
76
+ }
77
+ if (this.dexHelper.config.isSlave) {
78
+ this.dexHelper.dexStateSubscriber.subscribeToDEXPoolUpdates(this.dexKey, this.poolIdentifier, (state, blockNumber) => {
79
+ this.setState(state, blockNumber);
80
+ });
81
+ }
82
+ else {
83
+ this.dexHelper.blockManager.subscribeToLogs(this, this.addressesSubscribed, masterBn || blockNumber);
84
+ }
85
+ this.isInitialized = true;
86
+ }
87
+ //This function processes all logs for a single block (the block number is
88
+ //contained in each of the logs). It is not allowed to call this function
89
+ //with an empty logs array. The default implementation here will just call
90
+ //processLog for each of the logs; it may be overridden, if block specific
91
+ //handling or handling multiple logs at once is needed. Null should be
92
+ //returned if none of the provided logs affect the state.
93
+ async processBlockLogs(state, logs, blockHeader) {
94
+ let nextState = null;
95
+ for (const log of logs) {
96
+ const retState = await this.processLog(nextState || state, log, blockHeader);
97
+ if (retState)
98
+ nextState = retState;
99
+ }
100
+ return nextState;
101
+ }
102
+ restart(blockNumber) {
103
+ for (const _bn of Object.keys(this.stateHistory)) {
104
+ const bn = +_bn;
105
+ if (bn >= blockNumber)
106
+ break;
107
+ delete this.stateHistory[bn];
108
+ }
109
+ if (this.state && this.stateBlockNumber < blockNumber) {
110
+ this.logger.info(`StatefulDualSynchronizer restart, bn: ${blockNumber}, state_bn: ${this.stateBlockNumber}: ${this.dexKey}: ${this.poolIdentifier}`);
111
+ this._setState(null, blockNumber);
112
+ }
113
+ }
114
+ //Implementation must call setState() for every block in which the state
115
+ //changes and must ignore any logs that aren't newer than the oldest state
116
+ //stored. If state is not set or null, then the implementation should derive
117
+ //the state by another method for the block number of the first log, ignore
118
+ //all logs with that block number and then proceed as normal for the remaining
119
+ //logs. Remember to clear the invalid flag, even if there are no logs!
120
+ //A default implementation is provided here, but could be overridden.
121
+ async update(logs, blockHeaders) {
122
+ if (this.dexHelper.config.isSlave) {
123
+ throw new Error('LOGIC ERROR: we should expect to listen to events on slave instances');
124
+ }
125
+ let index = 0;
126
+ let lastBlockNumber;
127
+ while (index < logs.length) {
128
+ const blockNumber = logs[index].blockNumber;
129
+ if (index && blockNumber <= lastBlockNumber) {
130
+ this.logger.error('update() received blocks out of order!');
131
+ }
132
+ const blockHeader = blockHeaders[blockNumber];
133
+ if (!blockHeader) {
134
+ this.logger.error('update() missing block header!');
135
+ }
136
+ let lastLogIndex = logs[index].logIndex;
137
+ let indexBlockEnd = index + 1;
138
+ while (indexBlockEnd < logs.length &&
139
+ logs[indexBlockEnd].blockNumber === blockNumber) {
140
+ if (logs[indexBlockEnd].logIndex <= lastLogIndex) {
141
+ this.logger.error('update() received logs out of order!');
142
+ }
143
+ lastLogIndex = logs[indexBlockEnd].logIndex;
144
+ ++indexBlockEnd;
145
+ }
146
+ if (!this.state) {
147
+ const freshState = await this.generateState(blockNumber);
148
+ this.setState(freshState, blockNumber);
149
+ }
150
+ //Find the last state before the blockNumber of the logs
151
+ let stateBeforeLog;
152
+ for (const _bn of Object.keys(this.stateHistory)) {
153
+ const bn = +_bn;
154
+ if (bn >= blockNumber)
155
+ break;
156
+ stateBeforeLog = this.stateHistory[bn];
157
+ }
158
+ //Ignoring logs if there's no older state to play them onto
159
+ if (stateBeforeLog) {
160
+ (0, ts_essentials_1.assert)(typeof stateBeforeLog !== 'string', 'LOGIC ERROR: state is serialised');
161
+ const nextState = await this.processBlockLogs(stateBeforeLog, logs.slice(index, indexBlockEnd), blockHeader);
162
+ if (nextState)
163
+ this.setState(nextState, blockNumber);
164
+ }
165
+ lastBlockNumber = blockNumber;
166
+ index = indexBlockEnd;
167
+ }
168
+ this.invalid = false;
169
+ if (!this.dexHelper.config.isSlave && this.state === null) {
170
+ const network = this.dexHelper.config.data.network;
171
+ const createNewState = async () => {
172
+ if (this.state !== null) {
173
+ return true;
174
+ }
175
+ const latestBlockNumber = this.dexHelper.blockManager.getLatestBlockNumber();
176
+ this.logger.warn(`${network}: ${this.dexKey}: ${this.poolIdentifier}: master generate (latest: ${latestBlockNumber}) new state because state is null`);
177
+ try {
178
+ const state = await this.generateState(latestBlockNumber);
179
+ this.setState(state, latestBlockNumber);
180
+ return true;
181
+ }
182
+ catch (e) {
183
+ this.logger.error(`${network}: ${this.dexKey} ${this.poolIdentifier}: (${latestBlockNumber}) failed fetch state:`, e);
184
+ }
185
+ return false;
186
+ };
187
+ this.dexHelper.promiseScheduler.addPromise(createNewState);
188
+ }
189
+ }
190
+ //Removes all states that are beyond the given block number and sets the
191
+ //current state to the latest one that is left, if any, unless the invalid
192
+ //flag is not set, in which case the most recent state can be kept.
193
+ rollback(blockNumber) {
194
+ if (this.invalid) {
195
+ let lastBn = undefined;
196
+ //loop in the ascending order of the blockNumber. V8 property when object keys are number.
197
+ for (const bn of Object.keys(this.stateHistory)) {
198
+ const bnAsNumber = +bn;
199
+ if (bnAsNumber > blockNumber) {
200
+ delete this.stateHistory[+bn];
201
+ }
202
+ else {
203
+ lastBn = bnAsNumber;
204
+ }
205
+ }
206
+ if (lastBn) {
207
+ this._setState(this.stateHistory[lastBn], lastBn);
208
+ }
209
+ else {
210
+ this.logger.info(`StatefulDualSynchronizer rollback, bn: ${blockNumber}: ${this.dexKey}: ${this.poolIdentifier}`);
211
+ this._setState(null, blockNumber);
212
+ // TODO: explore generating new state on invalidation
213
+ }
214
+ }
215
+ else {
216
+ //Keep the current state in this.state and in the history
217
+ for (const _bn of Object.keys(this.stateHistory)) {
218
+ const bn = +_bn;
219
+ if (+bn > blockNumber && +bn !== this.stateBlockNumber) {
220
+ delete this.stateHistory[bn];
221
+ }
222
+ }
223
+ }
224
+ }
225
+ invalidate() {
226
+ this.logger.info(`StatefulDualSynchronizer invalidate: ${this.dexKey}: ${this.poolIdentifier}`);
227
+ this.invalid = true;
228
+ // TODO: explore generating new state on invalidation
229
+ }
230
+ //May return a state that is more recent than the block number specified, or
231
+ //will return null if a recent enough state cannot be found, in which case the
232
+ //caller should derive a state using another method (at an exact block
233
+ //number), possibly using generateState(), and set it on this object using
234
+ //setState. In case isTracking() returns true, it is assumed that the stored
235
+ //state is current and so the minBlockNumber will be disregarded.
236
+ getState(minBlockNumber) {
237
+ if (!this.state || this.invalid)
238
+ return null;
239
+ if (this.dexHelper.config.isSlave) {
240
+ if (this.dexHelper.dexStateSubscriber.isSynced(minBlockNumber) ||
241
+ this.stateBlockNumber >= minBlockNumber) {
242
+ if (typeof this.state === 'string') {
243
+ this.state = utils_1.Utils.Parse(this.state);
244
+ }
245
+ (0, ts_essentials_1.assert)(typeof this.state !== 'string', 'LOGIC ERROR: state is serialised');
246
+ return this.state;
247
+ }
248
+ }
249
+ else {
250
+ if (this.isTracking() || this.stateBlockNumber >= minBlockNumber) {
251
+ if (typeof this.state === 'string') {
252
+ this.state = utils_1.Utils.Parse(this.state);
253
+ }
254
+ (0, ts_essentials_1.assert)(typeof this.state !== 'string', 'LOGIC ERROR: state is serialised');
255
+ return this.state;
256
+ }
257
+ }
258
+ return null; // DEX need to implement an fallback strategy here
259
+ }
260
+ // Returns the last set state. The state might be invalid or not updated.
261
+ getStaleState() {
262
+ if (typeof this.state === 'string') {
263
+ this.state = utils_1.Utils.Parse(this.state);
264
+ }
265
+ (0, ts_essentials_1.assert)(typeof this.state !== 'string', 'LOGIC ERROR: state is serialised');
266
+ return this.state;
267
+ }
268
+ _setState(state, blockNumber) {
269
+ this.state = state;
270
+ this.stateBlockNumber = blockNumber;
271
+ }
272
+ //Saves the state into the stateHistory, and cleans up any old state that is
273
+ //no longer needed. If the blockNumber is greater than or equal to the
274
+ //current state, then the current state will be updated and the invalid flag
275
+ //can be reset.
276
+ setState(state, blockNumber) {
277
+ if (!blockNumber) {
278
+ this.logger.error('setState() with blockNumber', blockNumber);
279
+ return;
280
+ }
281
+ this.stateHistory[blockNumber] = state;
282
+ if (!this.state || blockNumber >= this.stateBlockNumber) {
283
+ this._setState(state, blockNumber);
284
+ this.invalid = false;
285
+ }
286
+ const minBlockNumberToKeep = this.stateBlockNumber - constants_1.MAX_BLOCKS_HISTORY;
287
+ let lastBlockNumber;
288
+ for (const bn of Object.keys(this.stateHistory)) {
289
+ if (+bn <= minBlockNumberToKeep) {
290
+ if (lastBlockNumber)
291
+ delete this.stateHistory[lastBlockNumber];
292
+ }
293
+ if (+bn >= minBlockNumberToKeep)
294
+ break;
295
+ lastBlockNumber = +bn;
296
+ }
297
+ }
298
+ }
299
+ exports.StatefulDualSynchronizer = StatefulDualSynchronizer;
300
+ //# sourceMappingURL=stateful-dual-synchronizer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stateful-dual-synchronizer.js","sourceRoot":"","sources":["../src/stateful-dual-synchronizer.ts"],"names":[],"mappings":";;;AAAA,iDAAkE;AAKlE,2CAAiD;AAEjD,mCAAgC;AAWhC,iEAAiE;AACjE,MAAsB,wBAAwB;IAwB5C,YACS,MAAc,EACd,cAAsB,EACnB,SAAqB,EACrB,MAAc;QAHjB,WAAM,GAAN,MAAM,CAAQ;QACd,mBAAc,GAAd,cAAc,CAAQ;QACnB,cAAS,GAAT,SAAS,CAAY;QACrB,WAAM,GAAN,MAAM,CAAQ;QAzB1B,wCAAwC;QACxC,2EAA2E;QACjE,UAAK,GAAgC,IAAI,CAAC;QAC1C,qBAAgB,GAAW,CAAC,CAAC;QAEvC,6DAA6D;QACnD,iBAAY,GAElB,EAAE,CAAC;QAEP,6EAA6E;QACnE,YAAO,GAAY,KAAK,CAAC;QAEnC,eAAU,GAAkB,GAAG,EAAE,CAAC,KAAK,CAAC;QACjC,wBAAmB,GAAa,EAAE,CAAC;QAKnC,kBAAa,GAAG,KAAK,CAAC;QAQ3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;QACnC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC,WAAW,EAAE,CAAC;QAEnD,qFAAqF;QACrF,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,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C,EAAE,CAAC;SACvB;IACH,CAAC;CACF;AA3YD,4DA2YC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paraswap/dex-lib",
3
- "version": "3.8.26",
3
+ "version": "3.8.27-dualsync.1",
4
4
  "main": "build/index.js",
5
5
  "types": "build/index.d.ts",
6
6
  "repository": "https://github.com/paraswap/paraswap-dex-lib",
package/src/dex/idex.ts CHANGED
@@ -207,6 +207,14 @@ export interface IDexPricing<ExchangeData> {
207
207
  // useful for RFQ system
208
208
  isBlacklisted?(userAddress?: Address): AsyncOrSync<boolean>;
209
209
 
210
+ addPoolGenerateState?({
211
+ poolIdentifier,
212
+ blockNumber,
213
+ }: {
214
+ poolIdentifier: string;
215
+ blockNumber: number;
216
+ }): AsyncOrSync<null | unknown>;
217
+
210
218
  // blacklist a specific userAddress from exchange
211
219
  setBlacklist?(userAddress?: Address): AsyncOrSync<boolean>;
212
220
  }
@@ -29,8 +29,9 @@ import {
29
29
  _reduceTickBitmap,
30
30
  _reduceTicks,
31
31
  } from '../uniswap-v3/contract-math/utils';
32
+ import { StatefulDualSynchronizer } from '../../stateful-dual-synchronizer';
32
33
 
33
- export class PancakeSwapV3EventPool extends StatefulEventSubscriber<PoolState> {
34
+ export class PancakeSwapV3EventPool extends StatefulDualSynchronizer<PoolState> {
34
35
  handlers: {
35
36
  [event: string]: (
36
37
  event: any,
@@ -61,7 +62,7 @@ export class PancakeSwapV3EventPool extends StatefulEventSubscriber<PoolState> {
61
62
 
62
63
  constructor(
63
64
  readonly dexHelper: IDexHelper,
64
- parentName: string,
65
+ dexKey: string,
65
66
  readonly stateMultiContract: Contract,
66
67
  readonly erc20Interface: Interface,
67
68
  protected readonly factoryAddress: Address,
@@ -73,14 +74,8 @@ export class PancakeSwapV3EventPool extends StatefulEventSubscriber<PoolState> {
73
74
  readonly poolInitCodeHash: string,
74
75
  readonly poolDeployer?: string,
75
76
  ) {
76
- super(
77
- parentName,
78
- `${token0}_${token1}_${feeCode}`,
79
- dexHelper,
80
- logger,
81
- true,
82
- mapKey,
83
- );
77
+ const poolIdentifier = `${token0}_${token1}_${feeCode}`;
78
+ super(dexKey, poolIdentifier, dexHelper, logger);
84
79
  this.feeCodeAsString = feeCode.toString();
85
80
  this.token0 = token0.toLowerCase();
86
81
  this.token1 = token1.toLowerCase();
@@ -62,6 +62,7 @@ import {
62
62
  PancakeswapV3Factory,
63
63
  } from './pancakeswap-v3-factory';
64
64
  import { extractReturnAmountPosition } from '../../executor/utils';
65
+ import { DexPoolNotFoundError } from '../../dex-utils';
65
66
 
66
67
  type PoolPairsInfo = {
67
68
  token0: Address;
@@ -293,7 +294,10 @@ export class PancakeswapV3
293
294
  },
294
295
  });
295
296
  } catch (e) {
296
- if (e instanceof Error && e.message.endsWith('Pool does not exist')) {
297
+ if (
298
+ (e instanceof Error && e.message.endsWith('Pool does not exist')) ||
299
+ e instanceof DexPoolNotFoundError
300
+ ) {
297
301
  // no need to await we want the set to have the pool key but it's not blocking
298
302
  this.dexHelper.cache.zadd(
299
303
  this.notExistingPoolSetKey,
@@ -368,6 +372,22 @@ export class PancakeswapV3
368
372
  return true;
369
373
  }
370
374
 
375
+ async addPoolGenerateState({
376
+ poolIdentifier,
377
+ blockNumber,
378
+ }: {
379
+ poolIdentifier: string;
380
+ blockNumber: number;
381
+ }): Promise<PoolState | null> {
382
+ const [token0, token1, fee] = poolIdentifier.split('_');
383
+
384
+ const pool = await this.getPool(token0, token1, BigInt(fee), blockNumber);
385
+
386
+ if (!pool) return null;
387
+
388
+ return pool.getState(blockNumber);
389
+ }
390
+
371
391
  async getPoolIdentifiers(
372
392
  srcToken: Token,
373
393
  destToken: Token,
@@ -661,7 +681,7 @@ export class PancakeswapV3
661
681
  if (state.liquidity <= 0n) {
662
682
  if (state.liquidity < 0) {
663
683
  this.logger.error(
664
- `${this.dexKey}-${this.network}: ${pool.poolAddress} pool has negative liquidity: ${state.liquidity}. Find with key: ${pool.mapKey}`,
684
+ `${this.dexKey}-${this.network}: ${pool.poolAddress} pool has negative liquidity: ${state.liquidity}. Find with key: ${pool.poolIdentifier}`,
665
685
  );
666
686
  }
667
687
  this.logger.trace(`pool have 0 liquidity`);
@@ -3,7 +3,6 @@ import { pack } from '@ethersproject/solidity';
3
3
  import _ from 'lodash';
4
4
  import { AsyncOrSync, DeepReadonly } from 'ts-essentials';
5
5
  import erc20ABI from '../../abi/erc20.json';
6
- import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
7
6
  import {
8
7
  AdapterExchangeParam,
9
8
  Address,
@@ -69,6 +68,7 @@ import {
69
68
  hexConcat,
70
69
  } from 'ethers/lib/utils';
71
70
  import { BigNumber } from 'ethers';
71
+ import { StatefulDualSynchronizer } from '../../stateful-dual-synchronizer';
72
72
 
73
73
  const rebaseTokens = _rebaseTokens as { chainId: number; address: string }[];
74
74
 
@@ -124,11 +124,12 @@ export interface UniswapV2Pair {
124
124
  pool?: UniswapV2EventPool;
125
125
  }
126
126
 
127
- export class UniswapV2EventPool extends StatefulEventSubscriber<UniswapV2PoolState> {
127
+ export class UniswapV2EventPool extends StatefulDualSynchronizer<UniswapV2PoolState> {
128
128
  decoder = (log: Log) => this.iface.parseLog(log);
129
129
 
130
130
  constructor(
131
- parentName: string,
131
+ public parentName: string,
132
+ public poolIdentifier: string,
132
133
  protected dexHelper: IDexHelper,
133
134
  private poolAddress: Address,
134
135
  private token0: Token,
@@ -142,15 +143,7 @@ export class UniswapV2EventPool extends StatefulEventSubscriber<UniswapV2PoolSta
142
143
  private feesMultiCallDecoder?: (values: any[]) => number,
143
144
  private iface: Interface = uniswapV2PoolIface,
144
145
  ) {
145
- super(
146
- parentName,
147
- (token0.symbol || token0.address) +
148
- '-' +
149
- (token1.symbol || token1.address) +
150
- ' pool',
151
- dexHelper,
152
- logger,
153
- );
146
+ super(parentName, poolIdentifier, dexHelper, logger);
154
147
  }
155
148
 
156
149
  protected processLog(
@@ -301,10 +294,11 @@ export class UniswapV2
301
294
  reserves1: string,
302
295
  feeCode: number,
303
296
  blockNumber: number,
304
- ) {
297
+ ): Promise<UniswapV2EventPool | null> {
305
298
  const { callEntry, callDecoder } = this.getFeesMultiCallData(pair) || {};
306
299
  pair.pool = new UniswapV2EventPool(
307
300
  this.dexKey,
301
+ this._getPoolIdentifier(pair.token0, pair.token1),
308
302
  this.dexHelper,
309
303
  pair.exchange!,
310
304
  pair.token0,
@@ -318,9 +312,50 @@ export class UniswapV2
318
312
  );
319
313
  pair.pool.addressesSubscribed.push(pair.exchange!);
320
314
 
321
- await pair.pool.initialize(blockNumber, {
315
+ try {
316
+ await pair.pool.initialize(
317
+ blockNumber,
318
+ /*, {
322
319
  state: { reserves0, reserves1, feeCode },
323
- });
320
+ }
321
+ */
322
+ );
323
+ return pair.pool;
324
+ } catch (e) {
325
+ this.logger.error(`Error_addPool could not add pool with error:`, e);
326
+ delete pair.pool;
327
+ return null;
328
+ }
329
+ }
330
+
331
+ async addPoolGenerateState({
332
+ poolIdentifier,
333
+ blockNumber,
334
+ }: {
335
+ poolIdentifier: string;
336
+ blockNumber: number;
337
+ }): Promise<UniswapV2PoolState | null> {
338
+ // poolIdentifier is in the format of 'uniswapv2_<token0>_<token1>'
339
+ const [, token0, token1] = poolIdentifier.split('_');
340
+ const pair = await this.findPair(
341
+ { address: token0, decimals: 0 },
342
+ { address: token1, decimals: 0 },
343
+ );
344
+ if (!(pair && pair.exchange)) return null;
345
+
346
+ const [pairState] = await this.getManyPoolReserves([pair], blockNumber);
347
+
348
+ const pool = await this.addPool(
349
+ pair,
350
+ pairState.reserves0,
351
+ pairState.reserves1,
352
+ pairState.feeCode,
353
+ blockNumber,
354
+ );
355
+
356
+ if (!pool) return null;
357
+
358
+ return pool.getState(blockNumber);
324
359
  }
325
360
 
326
361
  async getBuyPrice(
@@ -479,7 +514,9 @@ export class UniswapV2
479
514
  pairState.feeCode,
480
515
  blockNumber,
481
516
  );
482
- } else pair.pool.setState(pairState, blockNumber);
517
+ } else {
518
+ // pair.pool.setState(pairState, blockNumber); // TEMP: temporarily disabled to prevent confusions with new system
519
+ }
483
520
  }
484
521
  }
485
522
 
@@ -525,6 +562,19 @@ export class UniswapV2
525
562
  };
526
563
  }
527
564
 
565
+ _getPoolIdentifier(_from: Token, _to: Token) {
566
+ const from = this.dexHelper.config.wrapETH(_from);
567
+ const to = this.dexHelper.config.wrapETH(_to);
568
+
569
+ const tokenAddress = [from.address.toLowerCase(), to.address.toLowerCase()]
570
+ .sort((a, b) => (a > b ? 1 : -1))
571
+ .join('_');
572
+
573
+ const poolIdentifier = `${this.dexKey}_${tokenAddress}`;
574
+
575
+ return poolIdentifier.toLowerCase();
576
+ }
577
+
528
578
  async getPoolIdentifiers(
529
579
  _from: Token,
530
580
  _to: Token,
@@ -4,10 +4,7 @@ import { Interface } from '@ethersproject/abi';
4
4
  import { ethers } from 'ethers';
5
5
  import { assert, DeepReadonly } from 'ts-essentials';
6
6
  import { Log, Logger, BlockHeader, Address } from '../../types';
7
- import {
8
- InitializeStateOptions,
9
- StatefulEventSubscriber,
10
- } from '../../stateful-event-subscriber';
7
+ import { InitializeStateOptions } from '../../stateful-event-subscriber';
11
8
  import { IDexHelper } from '../../dex-helper/idex-helper';
12
9
  import {
13
10
  PoolState,
@@ -27,8 +24,9 @@ import { TickBitMap } from './contract-math/TickBitMap';
27
24
  import { uint256ToBigInt } from '../../lib/decoders';
28
25
  import { decodeStateMultiCallResultWithRelativeBitmaps } from './utils';
29
26
  import { _reduceTickBitmap, _reduceTicks } from './contract-math/utils';
27
+ import { StatefulDualSynchronizer } from '../../stateful-dual-synchronizer';
30
28
 
31
- export class UniswapV3EventPool extends StatefulEventSubscriber<PoolState> {
29
+ export class UniswapV3EventPool extends StatefulDualSynchronizer<PoolState> {
32
30
  handlers: {
33
31
  [event: string]: (
34
32
  event: any,
@@ -79,7 +77,7 @@ export class UniswapV3EventPool extends StatefulEventSubscriber<PoolState> {
79
77
  poolKey = `${poolKey}_${tickSpacing}`;
80
78
  }
81
79
 
82
- super(parentName, poolKey, dexHelper, logger, true, mapKey);
80
+ super(parentName, poolKey, dexHelper, logger);
83
81
  this.feeCodeAsString = feeCode.toString();
84
82
  this.token0 = token0.toLowerCase();
85
83
  this.token1 = token1.toLowerCase();
@@ -72,6 +72,7 @@ import { OptimalSwapExchange } from '@paraswap/core';
72
72
  import { OnPoolCreatedCallback, UniswapV3Factory } from './uniswap-v3-factory';
73
73
  import { hexConcat, hexlify, hexZeroPad, hexValue } from 'ethers/lib/utils';
74
74
  import { extractReturnAmountPosition } from '../../executor/utils';
75
+ import { DexPoolNotFoundError } from '../../dex-utils';
75
76
 
76
77
  type PoolPairsInfo = {
77
78
  token0: Address;
@@ -321,7 +322,10 @@ export class UniswapV3
321
322
  },
322
323
  });
323
324
  } catch (e) {
324
- if (e instanceof Error && e.message.endsWith('Pool does not exist')) {
325
+ if (
326
+ (e instanceof Error && e.message.endsWith('Pool does not exist')) ||
327
+ e instanceof DexPoolNotFoundError
328
+ ) {
325
329
  // no need to await we want the set to have the pool key but it's not blocking
326
330
  this.dexHelper.cache.zadd(
327
331
  this.notExistingPoolSetKey,
@@ -443,6 +447,28 @@ export class UniswapV3
443
447
  return true;
444
448
  }
445
449
 
450
+ async addPoolGenerateState({
451
+ poolIdentifier,
452
+ blockNumber,
453
+ }: {
454
+ poolIdentifier: string;
455
+ blockNumber: number;
456
+ }): Promise<PoolState | null> {
457
+ const [token0, token1, fee, tickSpacing] = poolIdentifier.split('_');
458
+
459
+ const pool = await this.getPool(
460
+ token0,
461
+ token1,
462
+ BigInt(fee),
463
+ blockNumber,
464
+ tickSpacing !== undefined ? BigInt(tickSpacing) : undefined,
465
+ );
466
+
467
+ if (!pool) return null;
468
+
469
+ return pool.getState(blockNumber);
470
+ }
471
+
446
472
  async getPoolIdentifiers(
447
473
  srcToken: Token,
448
474
  destToken: Token,
@@ -763,7 +789,7 @@ export class UniswapV3
763
789
  if (state.liquidity <= 0n) {
764
790
  if (state.liquidity < 0) {
765
791
  this.logger.error(
766
- `${this.dexKey}-${this.network}: ${pool.poolAddress} pool has negative liquidity: ${state.liquidity}. Find with key: ${pool.mapKey}`,
792
+ `${this.dexKey}-${this.network}: ${pool.poolAddress} pool has negative liquidity: ${state.liquidity}. Find with key: ${pool.poolIdentifier}`,
767
793
  );
768
794
  }
769
795
  this.logger.trace(`pool have 0 liquidity`);
@@ -299,6 +299,8 @@ export class DummyDexHelper implements IDexHelper {
299
299
  getLogger: LoggerConstructor;
300
300
  web3Provider: Web3;
301
301
  getTokenUSDPrice: (token: Token, amount: bigint) => Promise<number>;
302
+ dexStatePublisher: any; // FIXME
303
+ dexStateSubscriber: any; // FIXME
302
304
 
303
305
  constructor(network: number, rpcUrl?: string) {
304
306
  this.config = new ConfigHelper(false, generateConfig(network), 'is');