@paraswap/dex-lib 2.42.23 → 2.42.24

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 (351) 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/AugustusV6.abi.json +395 -0
  10. package/build/abi/algebra/AlgebraPool.abi.json +727 -0
  11. package/build/abi/curve-v1/StableSwapFRXETH.json +889 -0
  12. package/build/abi/curve-v1/StableSwapWBETH.json +1223 -0
  13. package/build/abi/sushiswap-v3/QuoterV2.json +267 -0
  14. package/build/abi/sushiswap-v3/RouterProcessor3.json +289 -0
  15. package/build/abi/uniswap-v3/UniswapV3Quoter.abi.json +193 -0
  16. package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3QuoterV2.abi.json +285 -0
  17. package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3Router.abi.json +583 -0
  18. package/build/abi/wBETH.json +1527 -0
  19. package/build/abi/woo-fi/WooFeeManager.abi.json +318 -0
  20. package/build/abi/woo-fi/WooPP.abi.json +548 -0
  21. package/build/abi/woo-fi/Wooracle.abi.json +260 -0
  22. package/build/dex/aave-v3/tokens/arbitrum.json +50 -0
  23. package/build/dex/aave-v3/tokens/avalanche.json +74 -0
  24. package/build/dex/aave-v3/tokens/fantom.json +62 -0
  25. package/build/dex/aave-v3/tokens/optimism.json +50 -0
  26. package/build/dex/aave-v3/tokens/polygon.json +116 -0
  27. package/build/dex/algebra/algebra-pool.d.ts +114 -0
  28. package/build/dex/algebra/algebra-pool.js +448 -0
  29. package/build/dex/algebra/algebra-pool.js.map +1 -0
  30. package/build/dex/balancer-v2/Gyro3Pool.d.ts +43 -0
  31. package/build/dex/balancer-v2/Gyro3Pool.js +160 -0
  32. package/build/dex/balancer-v2/Gyro3Pool.js.map +1 -0
  33. package/build/dex/balancer-v2/LinearMath.d.ts +88 -0
  34. package/build/dex/balancer-v2/LinearMath.js +285 -0
  35. package/build/dex/balancer-v2/LinearMath.js.map +1 -0
  36. package/build/dex/balancer-v2/LinearPool.d.ts +81 -0
  37. package/build/dex/balancer-v2/LinearPool.js +444 -0
  38. package/build/dex/balancer-v2/LinearPool.js.map +1 -0
  39. package/build/dex/balancer-v2/PhantomStablePool.d.ts +90 -0
  40. package/build/dex/balancer-v2/PhantomStablePool.js +418 -0
  41. package/build/dex/balancer-v2/PhantomStablePool.js.map +1 -0
  42. package/build/dex/balancer-v2/StableMath.d.ts +9 -0
  43. package/build/dex/balancer-v2/StableMath.js +272 -0
  44. package/build/dex/balancer-v2/StableMath.js.map +1 -0
  45. package/build/dex/balancer-v2/balancer-v2-pool.d.ts +140 -0
  46. package/build/dex/balancer-v2/balancer-v2-pool.js +647 -0
  47. package/build/dex/balancer-v2/balancer-v2-pool.js.map +1 -0
  48. package/build/dex/balancer-v2/pools/gyro/Gyro3Pool.d.ts +33 -0
  49. package/build/dex/balancer-v2/pools/gyro/Gyro3Pool.js +128 -0
  50. package/build/dex/balancer-v2/pools/gyro/Gyro3Pool.js.map +1 -0
  51. package/build/dex/balancer-v2/pools/gyro/GyroEPool.d.ts +34 -0
  52. package/build/dex/balancer-v2/pools/gyro/GyroEPool.js +151 -0
  53. package/build/dex/balancer-v2/pools/gyro/GyroEPool.js.map +1 -0
  54. package/build/dex/curve-v1/pools/frxETHpool.d.ts +7 -0
  55. package/build/dex/curve-v1/pools/frxETHpool.js +27 -0
  56. package/build/dex/curve-v1/pools/frxETHpool.js.map +1 -0
  57. package/build/dex/curve-v1/pools/wbETHpool.d.ts +29 -0
  58. package/build/dex/curve-v1/pools/wbETHpool.js +408 -0
  59. package/build/dex/curve-v1/pools/wbETHpool.js.map +1 -0
  60. package/build/dex/dexalot/constants.js +1 -1
  61. package/build/dex/lighter-v1/abi/erc20.json +222 -0
  62. package/build/dex/lighter-v1/abi/factory.json +291 -0
  63. package/build/dex/lighter-v1/abi/order_book.json +594 -0
  64. package/build/dex/lighter-v1/abi/order_book_helper.json +176 -0
  65. package/build/dex/lighter-v1/abi/router.json +488 -0
  66. package/build/dex/{my-test-dex → lighter-v1}/config.d.ts +1 -1
  67. package/build/dex/lighter-v1/config.js +17 -0
  68. package/build/dex/lighter-v1/config.js.map +1 -0
  69. package/build/dex/lighter-v1/constants.d.ts +2 -0
  70. package/build/dex/lighter-v1/constants.js +13 -0
  71. package/build/dex/lighter-v1/constants.js.map +1 -0
  72. package/build/dex/{my-test-dex/my-test-dex-pool.d.ts → lighter-v1/lighter-v1-pool.d.ts} +24 -6
  73. package/build/dex/lighter-v1/lighter-v1-pool.js +310 -0
  74. package/build/dex/lighter-v1/lighter-v1-pool.js.map +1 -0
  75. package/build/dex/{my-test-dex/my-test-dex.d.ts → lighter-v1/lighter-v1.d.ts} +18 -10
  76. package/build/dex/lighter-v1/lighter-v1.js +331 -0
  77. package/build/dex/lighter-v1/lighter-v1.js.map +1 -0
  78. package/build/dex/lighter-v1/types.d.ts +40 -0
  79. package/build/dex/{hello → lighter-v1}/types.js.map +1 -1
  80. package/build/dex/pancakeswap-v3/types.d.ts +14 -0
  81. package/build/dex/{my-test-dex → pancakeswap-v3}/types.js.map +1 -1
  82. package/build/dex/quickswap/camelot-v3.d.ts +6 -0
  83. package/build/dex/quickswap/camelot-v3.js +19 -0
  84. package/build/dex/quickswap/camelot-v3.js.map +1 -0
  85. package/build/dex/quickswap/zyberswap-v3.d.ts +6 -0
  86. package/build/dex/quickswap/zyberswap-v3.js +19 -0
  87. package/build/dex/quickswap/zyberswap-v3.js.map +1 -0
  88. package/build/dex/quickswap-v3.d.ts +21 -0
  89. package/build/dex/quickswap-v3.js +40 -0
  90. package/build/dex/quickswap-v3.js.map +1 -0
  91. package/build/dex/{wombat → ramses-v2}/config.d.ts +1 -1
  92. package/build/dex/ramses-v2/config.js +28 -0
  93. package/build/dex/ramses-v2/config.js.map +1 -0
  94. package/build/dex/{baseswap-v3 → ramses-v2}/constants.d.ts +1 -1
  95. package/build/dex/{baseswap-v3 → ramses-v2}/constants.js +1 -1
  96. package/build/dex/ramses-v2/constants.js.map +1 -0
  97. package/build/dex/ramses-v2/contract-math/BitMath.js.map +1 -0
  98. package/build/dex/ramses-v2/contract-math/FixedPoint128.js.map +1 -0
  99. package/build/dex/ramses-v2/contract-math/FixedPoint96.js.map +1 -0
  100. package/build/dex/ramses-v2/contract-math/FullMath.js.map +1 -0
  101. package/build/dex/ramses-v2/contract-math/LiquidityMath.js.map +1 -0
  102. package/build/dex/ramses-v2/contract-math/Oracle.js.map +1 -0
  103. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js.map +1 -0
  104. package/build/dex/ramses-v2/contract-math/SwapMath.js.map +1 -0
  105. package/build/dex/ramses-v2/contract-math/Tick.d.ts +7 -0
  106. package/build/dex/ramses-v2/contract-math/Tick.js.map +1 -0
  107. package/build/dex/ramses-v2/contract-math/TickBitMap.d.ts +8 -0
  108. package/build/dex/{baseswap-v3 → ramses-v2}/contract-math/TickBitMap.js +3 -0
  109. package/build/dex/ramses-v2/contract-math/TickBitMap.js.map +1 -0
  110. package/build/dex/ramses-v2/contract-math/TickMath.js.map +1 -0
  111. package/build/dex/ramses-v2/contract-math/UnsafeMath.js.map +1 -0
  112. package/build/dex/{baseswap-v3 → ramses-v2}/contract-math/uniswap-v3-math.d.ts +0 -19
  113. package/build/dex/{baseswap-v3 → ramses-v2}/contract-math/uniswap-v3-math.js +1 -2
  114. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js.map +1 -0
  115. package/build/dex/ramses-v2/contract-math/utils.js.map +1 -0
  116. package/build/dex/{baseswap-v3/baseswap-v3-pool.d.ts → ramses-v2/ramses-v2-pool.d.ts} +7 -11
  117. package/build/dex/{baseswap-v3/baseswap-v3-pool.js → ramses-v2/ramses-v2-pool.js} +7 -12
  118. package/build/dex/ramses-v2/ramses-v2-pool.js.map +1 -0
  119. package/build/dex/{baseswap-v3/baseswap-v3.d.ts → ramses-v2/ramses-v2.d.ts} +16 -26
  120. package/build/dex/{baseswap-v3/baseswap-v3.js → ramses-v2/ramses-v2.js} +82 -144
  121. package/build/dex/ramses-v2/ramses-v2.js.map +1 -0
  122. package/build/dex/{baseswap-v3 → ramses-v2}/types.d.ts +7 -17
  123. package/build/dex/ramses-v2/types.js +9 -0
  124. package/build/dex/ramses-v2/types.js.map +1 -0
  125. package/build/dex/{baseswap-v3 → ramses-v2}/utils.js +7 -1
  126. package/build/dex/ramses-v2/utils.js.map +1 -0
  127. package/build/dex/{kyberswap-elastic → sushiswap-v3}/config.d.ts +2 -2
  128. package/build/dex/sushiswap-v3/config.js +132 -0
  129. package/build/dex/sushiswap-v3/config.js.map +1 -0
  130. package/build/dex/sushiswap-v3/constants.d.ts +4 -0
  131. package/build/dex/sushiswap-v3/constants.js +32 -0
  132. package/build/dex/sushiswap-v3/constants.js.map +1 -0
  133. package/build/dex/{kyberswap-elastic/kyberswap-elastic.d.ts → sushiswap-v3/sushiswap-v3-original.d.ts} +31 -28
  134. package/build/dex/{kyberswap-elastic/kyberswap-elastic.js → sushiswap-v3/sushiswap-v3-original.js} +257 -269
  135. package/build/dex/sushiswap-v3/sushiswap-v3-original.js.map +1 -0
  136. package/build/dex/sushiswap-v3/sushiswap-v3-pool.d.ts +1 -0
  137. package/build/dex/sushiswap-v3/sushiswap-v3-pool.js +6 -0
  138. package/build/dex/sushiswap-v3/sushiswap-v3-pool.js.map +1 -0
  139. package/build/dex/sushiswap-v3/sushiswap-v3.d.ts +21 -0
  140. package/build/dex/sushiswap-v3/sushiswap-v3.js +58 -0
  141. package/build/dex/sushiswap-v3/sushiswap-v3.js.map +1 -0
  142. package/build/dex/sushiswap-v3/token.d.ts +6 -0
  143. package/build/dex/sushiswap-v3/token.js +23 -0
  144. package/build/dex/sushiswap-v3/token.js.map +1 -0
  145. package/build/dex/sushiswap-v3/types.d.ts +15 -0
  146. package/build/dex/sushiswap-v3/types.js +18 -0
  147. package/build/dex/sushiswap-v3/types.js.map +1 -0
  148. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.d.ts +12 -0
  149. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js +23 -0
  150. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js.map +1 -0
  151. package/build/dex/{hello → woo-fi}/config.d.ts +1 -1
  152. package/build/dex/woo-fi/config.js +141 -0
  153. package/build/dex/woo-fi/config.js.map +1 -0
  154. package/build/dex/woo-fi/constants.d.ts +5 -0
  155. package/build/dex/woo-fi/constants.js +20 -0
  156. package/build/dex/woo-fi/constants.js.map +1 -0
  157. package/build/dex/woo-fi/types.d.ts +48 -0
  158. package/build/dex/{wombat → woo-fi}/types.js.map +1 -1
  159. package/build/dex/woo-fi/woo-fi-decimal-math.d.ts +14 -0
  160. package/build/dex/woo-fi/woo-fi-decimal-math.js +42 -0
  161. package/build/dex/woo-fi/woo-fi-decimal-math.js.map +1 -0
  162. package/build/dex/woo-fi/woo-fi-math.d.ts +31 -0
  163. package/build/dex/woo-fi/woo-fi-math.js +300 -0
  164. package/build/dex/woo-fi/woo-fi-math.js.map +1 -0
  165. package/build/dex/woo-fi/woo-fi.d.ts +65 -0
  166. package/build/dex/woo-fi/woo-fi.js +480 -0
  167. package/build/dex/woo-fi/woo-fi.js.map +1 -0
  168. package/build/executor/Executor01BytecodeBuilder.d.ts +77 -0
  169. package/build/executor/Executor01BytecodeBuilder.js +359 -0
  170. package/build/executor/Executor01BytecodeBuilder.js.map +1 -0
  171. package/build/executor/Executor02BytecodeBuilder.d.ts +12 -0
  172. package/build/executor/Executor02BytecodeBuilder.js +14 -0
  173. package/build/executor/Executor02BytecodeBuilder.js.map +1 -0
  174. package/build/executor/ExecutorDetector.d.ts +28 -0
  175. package/build/executor/ExecutorDetector.js +89 -0
  176. package/build/executor/ExecutorDetector.js.map +1 -0
  177. package/build/executor/IExecutorBytecodeBuilder.d.ts +6 -0
  178. package/build/executor/IExecutorBytecodeBuilder.js +3 -0
  179. package/build/executor/IExecutorBytecodeBuilder.js.map +1 -0
  180. package/build/generic-swap-transaction-builder.d.ts +39 -0
  181. package/build/generic-swap-transaction-builder.js +156 -0
  182. package/build/generic-swap-transaction-builder.js.map +1 -0
  183. package/package.json +1 -1
  184. package/src/dex/dexalot/constants.ts +1 -1
  185. package/build/abi/kyberswap-elastic/IAntiSnipAttackPositionManager.json +0 -1276
  186. package/build/abi/kyberswap-elastic/IFactory.json +0 -550
  187. package/build/abi/kyberswap-elastic/IPool.json +0 -1042
  188. package/build/abi/kyberswap-elastic/IQuoterV2.json +0 -226
  189. package/build/abi/kyberswap-elastic/IRouter.json +0 -239
  190. package/build/abi/kyberswap-elastic/TicksFeesReader.json +0 -142
  191. package/build/abi/wombat/asset.json +0 -769
  192. package/build/abi/wombat/bmw.json +0 -1247
  193. package/build/abi/wombat/pool.json +0 -1364
  194. package/build/dex/baseswap-v3/baseswap-v3-factory.d.ts +0 -26
  195. package/build/dex/baseswap-v3/baseswap-v3-factory.js +0 -44
  196. package/build/dex/baseswap-v3/baseswap-v3-factory.js.map +0 -1
  197. package/build/dex/baseswap-v3/baseswap-v3-pool.js.map +0 -1
  198. package/build/dex/baseswap-v3/baseswap-v3.js.map +0 -1
  199. package/build/dex/baseswap-v3/config.d.ts +0 -9
  200. package/build/dex/baseswap-v3/config.js +0 -48
  201. package/build/dex/baseswap-v3/config.js.map +0 -1
  202. package/build/dex/baseswap-v3/constants.js.map +0 -1
  203. package/build/dex/baseswap-v3/contract-math/BitMath.js.map +0 -1
  204. package/build/dex/baseswap-v3/contract-math/FixedPoint128.js.map +0 -1
  205. package/build/dex/baseswap-v3/contract-math/FixedPoint96.js.map +0 -1
  206. package/build/dex/baseswap-v3/contract-math/FullMath.js.map +0 -1
  207. package/build/dex/baseswap-v3/contract-math/LiquidityMath.js.map +0 -1
  208. package/build/dex/baseswap-v3/contract-math/Oracle.js.map +0 -1
  209. package/build/dex/baseswap-v3/contract-math/SqrtPriceMath.js.map +0 -1
  210. package/build/dex/baseswap-v3/contract-math/SwapMath.js.map +0 -1
  211. package/build/dex/baseswap-v3/contract-math/Tick.d.ts +0 -7
  212. package/build/dex/baseswap-v3/contract-math/Tick.js.map +0 -1
  213. package/build/dex/baseswap-v3/contract-math/TickBitMap.d.ts +0 -7
  214. package/build/dex/baseswap-v3/contract-math/TickBitMap.js.map +0 -1
  215. package/build/dex/baseswap-v3/contract-math/TickMath.js.map +0 -1
  216. package/build/dex/baseswap-v3/contract-math/UnsafeMath.js.map +0 -1
  217. package/build/dex/baseswap-v3/contract-math/uniswap-v3-math.js.map +0 -1
  218. package/build/dex/baseswap-v3/contract-math/utils.d.ts +0 -7
  219. package/build/dex/baseswap-v3/contract-math/utils.js +0 -42
  220. package/build/dex/baseswap-v3/contract-math/utils.js.map +0 -1
  221. package/build/dex/baseswap-v3/types.js +0 -9
  222. package/build/dex/baseswap-v3/types.js.map +0 -1
  223. package/build/dex/baseswap-v3/utils.js.map +0 -1
  224. package/build/dex/hello/config.js +0 -15
  225. package/build/dex/hello/config.js.map +0 -1
  226. package/build/dex/hello/hello-pool.d.ts +0 -39
  227. package/build/dex/hello/hello-pool.js +0 -64
  228. package/build/dex/hello/hello-pool.js.map +0 -1
  229. package/build/dex/hello/hello.d.ts +0 -37
  230. package/build/dex/hello/hello.js +0 -126
  231. package/build/dex/hello/hello.js.map +0 -1
  232. package/build/dex/hello/types.d.ts +0 -6
  233. package/build/dex/kyberswap-elastic/config.js +0 -80
  234. package/build/dex/kyberswap-elastic/config.js.map +0 -1
  235. package/build/dex/kyberswap-elastic/constants.d.ts +0 -17
  236. package/build/dex/kyberswap-elastic/constants.js +0 -42
  237. package/build/dex/kyberswap-elastic/constants.js.map +0 -1
  238. package/build/dex/kyberswap-elastic/contract-math/FixedPoint96.d.ts +0 -4
  239. package/build/dex/kyberswap-elastic/contract-math/FixedPoint96.js +0 -9
  240. package/build/dex/kyberswap-elastic/contract-math/FixedPoint96.js.map +0 -1
  241. package/build/dex/kyberswap-elastic/contract-math/FullMath.d.ts +0 -5
  242. package/build/dex/kyberswap-elastic/contract-math/FullMath.js +0 -22
  243. package/build/dex/kyberswap-elastic/contract-math/FullMath.js.map +0 -1
  244. package/build/dex/kyberswap-elastic/contract-math/LiqDeltaMath.d.ts +0 -3
  245. package/build/dex/kyberswap-elastic/contract-math/LiqDeltaMath.js +0 -12
  246. package/build/dex/kyberswap-elastic/contract-math/LiqDeltaMath.js.map +0 -1
  247. package/build/dex/kyberswap-elastic/contract-math/LiquidityMath.d.ts +0 -3
  248. package/build/dex/kyberswap-elastic/contract-math/LiquidityMath.js +0 -22
  249. package/build/dex/kyberswap-elastic/contract-math/LiquidityMath.js.map +0 -1
  250. package/build/dex/kyberswap-elastic/contract-math/QtyDeltaMath.d.ts +0 -5
  251. package/build/dex/kyberswap-elastic/contract-math/QtyDeltaMath.js +0 -25
  252. package/build/dex/kyberswap-elastic/contract-math/QtyDeltaMath.js.map +0 -1
  253. package/build/dex/kyberswap-elastic/contract-math/QuadMath.d.ts +0 -4
  254. package/build/dex/kyberswap-elastic/contract-math/QuadMath.js +0 -27
  255. package/build/dex/kyberswap-elastic/contract-math/QuadMath.js.map +0 -1
  256. package/build/dex/kyberswap-elastic/contract-math/ReinvestmentMath.d.ts +0 -3
  257. package/build/dex/kyberswap-elastic/contract-math/ReinvestmentMath.js +0 -14
  258. package/build/dex/kyberswap-elastic/contract-math/ReinvestmentMath.js.map +0 -1
  259. package/build/dex/kyberswap-elastic/contract-math/SafeCast.d.ts +0 -8
  260. package/build/dex/kyberswap-elastic/contract-math/SafeCast.js +0 -30
  261. package/build/dex/kyberswap-elastic/contract-math/SafeCast.js.map +0 -1
  262. package/build/dex/kyberswap-elastic/contract-math/SqrtPriceMath.d.ts +0 -10
  263. package/build/dex/kyberswap-elastic/contract-math/SqrtPriceMath.js +0 -91
  264. package/build/dex/kyberswap-elastic/contract-math/SqrtPriceMath.js.map +0 -1
  265. package/build/dex/kyberswap-elastic/contract-math/SwapMath.d.ts +0 -13
  266. package/build/dex/kyberswap-elastic/contract-math/SwapMath.js +0 -188
  267. package/build/dex/kyberswap-elastic/contract-math/SwapMath.js.map +0 -1
  268. package/build/dex/kyberswap-elastic/contract-math/TickLinkedList.d.ts +0 -6
  269. package/build/dex/kyberswap-elastic/contract-math/TickLinkedList.js +0 -41
  270. package/build/dex/kyberswap-elastic/contract-math/TickLinkedList.js.map +0 -1
  271. package/build/dex/kyberswap-elastic/contract-math/TickMath.d.ts +0 -9
  272. package/build/dex/kyberswap-elastic/contract-math/TickMath.js +0 -165
  273. package/build/dex/kyberswap-elastic/contract-math/TickMath.js.map +0 -1
  274. package/build/dex/kyberswap-elastic/contract-math/UnsafeMath.d.ts +0 -3
  275. package/build/dex/kyberswap-elastic/contract-math/UnsafeMath.js +0 -10
  276. package/build/dex/kyberswap-elastic/contract-math/UnsafeMath.js.map +0 -1
  277. package/build/dex/kyberswap-elastic/contract-math/kyberswap-elastic-math.d.ts +0 -28
  278. package/build/dex/kyberswap-elastic/contract-math/kyberswap-elastic-math.js +0 -502
  279. package/build/dex/kyberswap-elastic/contract-math/kyberswap-elastic-math.js.map +0 -1
  280. package/build/dex/kyberswap-elastic/contract-math/utils.js.map +0 -1
  281. package/build/dex/kyberswap-elastic/errors.d.ts +0 -2
  282. package/build/dex/kyberswap-elastic/errors.js +0 -6
  283. package/build/dex/kyberswap-elastic/errors.js.map +0 -1
  284. package/build/dex/kyberswap-elastic/kyberswap-elastic-pool.d.ts +0 -80
  285. package/build/dex/kyberswap-elastic/kyberswap-elastic-pool.js +0 -458
  286. package/build/dex/kyberswap-elastic/kyberswap-elastic-pool.js.map +0 -1
  287. package/build/dex/kyberswap-elastic/kyberswap-elastic.js.map +0 -1
  288. package/build/dex/kyberswap-elastic/types.d.ts +0 -134
  289. package/build/dex/kyberswap-elastic/types.js +0 -9
  290. package/build/dex/kyberswap-elastic/types.js.map +0 -1
  291. package/build/dex/kyberswap-elastic/utils/decoders.d.ts +0 -9
  292. package/build/dex/kyberswap-elastic/utils/decoders.js +0 -78
  293. package/build/dex/kyberswap-elastic/utils/decoders.js.map +0 -1
  294. package/build/dex/morphex/config.d.ts +0 -11
  295. package/build/dex/morphex/config.js +0 -43
  296. package/build/dex/morphex/config.js.map +0 -1
  297. package/build/dex/morphex/morphex.d.ts +0 -25
  298. package/build/dex/morphex/morphex.js +0 -19
  299. package/build/dex/morphex/morphex.js.map +0 -1
  300. package/build/dex/my-test-dex/config.js +0 -15
  301. package/build/dex/my-test-dex/config.js.map +0 -1
  302. package/build/dex/my-test-dex/my-test-dex-pool.js +0 -64
  303. package/build/dex/my-test-dex/my-test-dex-pool.js.map +0 -1
  304. package/build/dex/my-test-dex/my-test-dex.js +0 -126
  305. package/build/dex/my-test-dex/my-test-dex.js.map +0 -1
  306. package/build/dex/my-test-dex/types.d.ts +0 -6
  307. package/build/dex/wombat/config.js +0 -99
  308. package/build/dex/wombat/config.js.map +0 -1
  309. package/build/dex/wombat/types.d.ts +0 -33
  310. package/build/dex/wombat/utils.d.ts +0 -9
  311. package/build/dex/wombat/utils.js +0 -66
  312. package/build/dex/wombat/utils.js.map +0 -1
  313. package/build/dex/wombat/wombat-bmw.d.ts +0 -40
  314. package/build/dex/wombat/wombat-bmw.js +0 -147
  315. package/build/dex/wombat/wombat-bmw.js.map +0 -1
  316. package/build/dex/wombat/wombat-pool.d.ts +0 -22
  317. package/build/dex/wombat/wombat-pool.js +0 -161
  318. package/build/dex/wombat/wombat-pool.js.map +0 -1
  319. package/build/dex/wombat/wombat-quoter.d.ts +0 -16
  320. package/build/dex/wombat/wombat-quoter.js +0 -176
  321. package/build/dex/wombat/wombat-quoter.js.map +0 -1
  322. package/build/dex/wombat/wombat.d.ts +0 -55
  323. package/build/dex/wombat/wombat.js +0 -290
  324. package/build/dex/wombat/wombat.js.map +0 -1
  325. /package/build/dex/{hello → lighter-v1}/types.js +0 -0
  326. /package/build/dex/{my-test-dex → pancakeswap-v3}/types.js +0 -0
  327. /package/build/dex/{baseswap-v3 → ramses-v2}/contract-math/BitMath.d.ts +0 -0
  328. /package/build/dex/{baseswap-v3 → ramses-v2}/contract-math/BitMath.js +0 -0
  329. /package/build/dex/{baseswap-v3 → ramses-v2}/contract-math/FixedPoint128.d.ts +0 -0
  330. /package/build/dex/{baseswap-v3 → ramses-v2}/contract-math/FixedPoint128.js +0 -0
  331. /package/build/dex/{baseswap-v3 → ramses-v2}/contract-math/FixedPoint96.d.ts +0 -0
  332. /package/build/dex/{baseswap-v3 → ramses-v2}/contract-math/FixedPoint96.js +0 -0
  333. /package/build/dex/{baseswap-v3 → ramses-v2}/contract-math/FullMath.d.ts +0 -0
  334. /package/build/dex/{baseswap-v3 → ramses-v2}/contract-math/FullMath.js +0 -0
  335. /package/build/dex/{baseswap-v3 → ramses-v2}/contract-math/LiquidityMath.d.ts +0 -0
  336. /package/build/dex/{baseswap-v3 → ramses-v2}/contract-math/LiquidityMath.js +0 -0
  337. /package/build/dex/{baseswap-v3 → ramses-v2}/contract-math/Oracle.d.ts +0 -0
  338. /package/build/dex/{baseswap-v3 → ramses-v2}/contract-math/Oracle.js +0 -0
  339. /package/build/dex/{baseswap-v3 → ramses-v2}/contract-math/SqrtPriceMath.d.ts +0 -0
  340. /package/build/dex/{baseswap-v3 → ramses-v2}/contract-math/SqrtPriceMath.js +0 -0
  341. /package/build/dex/{baseswap-v3 → ramses-v2}/contract-math/SwapMath.d.ts +0 -0
  342. /package/build/dex/{baseswap-v3 → ramses-v2}/contract-math/SwapMath.js +0 -0
  343. /package/build/dex/{baseswap-v3 → ramses-v2}/contract-math/Tick.js +0 -0
  344. /package/build/dex/{baseswap-v3 → ramses-v2}/contract-math/TickMath.d.ts +0 -0
  345. /package/build/dex/{baseswap-v3 → ramses-v2}/contract-math/TickMath.js +0 -0
  346. /package/build/dex/{baseswap-v3 → ramses-v2}/contract-math/UnsafeMath.d.ts +0 -0
  347. /package/build/dex/{baseswap-v3 → ramses-v2}/contract-math/UnsafeMath.js +0 -0
  348. /package/build/dex/{kyberswap-elastic → ramses-v2}/contract-math/utils.d.ts +0 -0
  349. /package/build/dex/{kyberswap-elastic → ramses-v2}/contract-math/utils.js +0 -0
  350. /package/build/dex/{baseswap-v3 → ramses-v2}/utils.d.ts +0 -0
  351. /package/build/dex/{wombat → woo-fi}/types.js +0 -0
@@ -0,0 +1,114 @@
1
+ import { Interface } from '@ethersproject/abi';
2
+ import { DeepReadonly } from 'ts-essentials';
3
+ import { Address, BlockHeader, Log, Logger } from '../../types';
4
+ import {
5
+ InitializeStateOptions,
6
+ StatefulEventSubscriber,
7
+ } from '../../stateful-event-subscriber';
8
+ import { IDexHelper } from '../../dex-helper/idex-helper';
9
+ import { PoolState } from './types';
10
+ import { Contract } from 'web3-eth-contract';
11
+ import { DecodedStateMultiCallResultWithRelativeBitmaps } from './types';
12
+ export declare class AlgebraEventPool extends StatefulEventSubscriber<PoolState> {
13
+ readonly dexHelper: IDexHelper;
14
+ readonly stateMultiContract: Contract;
15
+ readonly erc20Interface: Interface;
16
+ protected readonly factoryAddress: Address;
17
+ readonly poolInitCodeHash: string;
18
+ readonly poolDeployer: string;
19
+ handlers: {
20
+ [event: string]: (
21
+ event: any,
22
+ state: DeepReadonly<PoolState>,
23
+ log: Readonly<Log>,
24
+ blockHeader: BlockHeader,
25
+ ) => DeepReadonly<PoolState> | null;
26
+ };
27
+ logDecoder: (log: Log) => any;
28
+ addressesSubscribed: string[];
29
+ private _poolAddress?;
30
+ readonly token0: Address;
31
+ readonly token1: Address;
32
+ readonly poolIface: Interface;
33
+ initFailed: boolean;
34
+ initRetryAttemptCount: number;
35
+ constructor(
36
+ dexHelper: IDexHelper,
37
+ parentName: string,
38
+ stateMultiContract: Contract,
39
+ erc20Interface: Interface,
40
+ factoryAddress: Address,
41
+ token0: Address,
42
+ token1: Address,
43
+ logger: Logger,
44
+ mapKey: string | undefined,
45
+ poolInitCodeHash: string,
46
+ poolDeployer: string,
47
+ );
48
+ get poolAddress(): Address;
49
+ set poolAddress(address: Address);
50
+ initialize(
51
+ blockNumber: number,
52
+ options?: InitializeStateOptions<PoolState>,
53
+ ): Promise<void>;
54
+ protected processBlockLogs(
55
+ state: DeepReadonly<PoolState>,
56
+ logs: Readonly<Log>[],
57
+ blockHeader: Readonly<BlockHeader>,
58
+ ): Promise<DeepReadonly<PoolState> | null>;
59
+ protected processLog(
60
+ state: DeepReadonly<PoolState>,
61
+ log: Readonly<Log>,
62
+ blockHeader: Readonly<BlockHeader>,
63
+ ): DeepReadonly<PoolState> | null;
64
+ getBitmapRangeToRequest(): bigint;
65
+ private _fetchPoolStateSingleStep;
66
+ private _fetchPoolStateMultiStep;
67
+ _fetchInitStateMultiStrategies(
68
+ blockNumber: number,
69
+ ): Promise<[bigint, bigint, DecodedStateMultiCallResultWithRelativeBitmaps]>;
70
+ generateState(blockNumber: number): Promise<Readonly<PoolState>>;
71
+ handleSwapEvent(
72
+ event: any,
73
+ pool: PoolState,
74
+ log: Log,
75
+ blockHeader: BlockHeader,
76
+ ): PoolState;
77
+ handleMintEvent(
78
+ event: any,
79
+ pool: PoolState,
80
+ log: Log,
81
+ blockHeader: BlockHeader,
82
+ ): PoolState;
83
+ handleBurnEvent(
84
+ event: any,
85
+ pool: PoolState,
86
+ log: Log,
87
+ blockHeader: BlockHeader,
88
+ ): PoolState;
89
+ handleNewFee(
90
+ event: any,
91
+ pool: PoolState,
92
+ log: Log,
93
+ blockHeader: BlockHeader,
94
+ ): PoolState;
95
+ handleCollectEvent(
96
+ event: any,
97
+ pool: PoolState,
98
+ log: Log,
99
+ blockHeader: BlockHeader,
100
+ ): PoolState;
101
+ handleFlashEvent(
102
+ event: any,
103
+ pool: PoolState,
104
+ log: Log,
105
+ blockHeader: BlockHeader,
106
+ ): PoolState;
107
+ handleCommunityFee(
108
+ event: any,
109
+ pool: PoolState,
110
+ log: Log,
111
+ blockHeader: BlockHeader,
112
+ ): PoolState;
113
+ private _computePoolAddress;
114
+ }
@@ -0,0 +1,448 @@
1
+ 'use strict';
2
+ var __importDefault =
3
+ (this && this.__importDefault) ||
4
+ function (mod) {
5
+ return mod && mod.__esModule ? mod : { default: mod };
6
+ };
7
+ Object.defineProperty(exports, '__esModule', { value: true });
8
+ exports.AlgebraEventPool = void 0;
9
+ const lodash_1 = __importDefault(require('lodash'));
10
+ const abi_1 = require('@ethersproject/abi');
11
+ const ts_essentials_1 = require('ts-essentials');
12
+ const utils_1 = require('../../utils');
13
+ const stateful_event_subscriber_1 = require('../../stateful-event-subscriber');
14
+ const ethers_1 = require('ethers');
15
+ const AlgebraPool_abi_json_1 = __importDefault(
16
+ require('../../abi/algebra/AlgebraPool.abi.json'),
17
+ );
18
+ const constants_1 = require('../uniswap-v3/constants');
19
+ const decoders_1 = require('../../lib/decoders');
20
+ const utils_2 = require('./utils');
21
+ const AlgebraMath_1 = require('./lib/AlgebraMath');
22
+ const TickBitMap_1 = require('../uniswap-v3/contract-math/TickBitMap');
23
+ const utils_3 = require('../uniswap-v3/contract-math/utils');
24
+ const Constants_1 = require('./lib/Constants');
25
+ const constants_2 = require('../../constants');
26
+ class AlgebraEventPool extends stateful_event_subscriber_1.StatefulEventSubscriber {
27
+ constructor(
28
+ dexHelper,
29
+ parentName,
30
+ stateMultiContract,
31
+ erc20Interface,
32
+ factoryAddress,
33
+ token0,
34
+ token1,
35
+ logger,
36
+ mapKey = '',
37
+ poolInitCodeHash,
38
+ poolDeployer,
39
+ ) {
40
+ super(parentName, `${token0}_${token1}`, dexHelper, logger, true, mapKey);
41
+ this.dexHelper = dexHelper;
42
+ this.stateMultiContract = stateMultiContract;
43
+ this.erc20Interface = erc20Interface;
44
+ this.factoryAddress = factoryAddress;
45
+ this.poolInitCodeHash = poolInitCodeHash;
46
+ this.poolDeployer = poolDeployer;
47
+ this.handlers = {};
48
+ this.poolIface = new abi_1.Interface(AlgebraPool_abi_json_1.default);
49
+ this.initFailed = false;
50
+ this.initRetryAttemptCount = 0;
51
+ this.token0 = token0.toLowerCase();
52
+ this.token1 = token1.toLowerCase();
53
+ this.logDecoder = log => this.poolIface.parseLog(log);
54
+ this.addressesSubscribed = new Array(1);
55
+ this.handlers['Fee'] = this.handleNewFee.bind(this);
56
+ this.handlers['Swap'] = this.handleSwapEvent.bind(this);
57
+ this.handlers['Mint'] = this.handleMintEvent.bind(this);
58
+ this.handlers['Burn'] = this.handleBurnEvent.bind(this);
59
+ this.handlers['Flash'] = this.handleFlashEvent.bind(this);
60
+ this.handlers['Collect'] = this.handleCollectEvent.bind(this);
61
+ this.handlers['CommunityFee'] = this.handleCommunityFee.bind(this);
62
+ }
63
+ get poolAddress() {
64
+ if (this._poolAddress === undefined) {
65
+ this._poolAddress = this._computePoolAddress(this.token0, this.token1);
66
+ }
67
+ return this._poolAddress;
68
+ }
69
+ set poolAddress(address) {
70
+ this._poolAddress = address.toLowerCase();
71
+ }
72
+ async initialize(blockNumber, options) {
73
+ await super.initialize(blockNumber, options);
74
+ }
75
+ async processBlockLogs(state, logs, blockHeader) {
76
+ const newState = await super.processBlockLogs(state, logs, blockHeader);
77
+ if (newState && !newState.isValid) {
78
+ return await this.generateState(blockHeader.number);
79
+ }
80
+ return newState;
81
+ }
82
+ processLog(state, log, blockHeader) {
83
+ try {
84
+ const event = this.logDecoder(log);
85
+ if (event.name in this.handlers) {
86
+ // Because we have observations in array which is mutable by nature, there is a
87
+ // ts compile error: https://stackoverflow.com/questions/53412934/disable-allowing-assigning-readonly-types-to-non-readonly-types
88
+ // And there is no good workaround, so turn off the type checker for this line
89
+ const _state = lodash_1.default.cloneDeep(state);
90
+ try {
91
+ const newState = this.handlers[event.name](
92
+ event,
93
+ _state,
94
+ log,
95
+ blockHeader,
96
+ );
97
+ return newState;
98
+ } catch (e) {
99
+ if (
100
+ e instanceof Error &&
101
+ e.message.endsWith(constants_1.OUT_OF_RANGE_ERROR_POSTFIX)
102
+ ) {
103
+ this.logger.warn(
104
+ `${this.parentName}: Pool ${this.poolAddress} on ${
105
+ this.dexHelper.config.data.network
106
+ } is out of TickBitmap requested range. Re-query the state. ${JSON.stringify(
107
+ event,
108
+ )}`,
109
+ e,
110
+ );
111
+ } else {
112
+ this.logger.error(
113
+ `${this.parentName}: Pool ${this.poolAddress}, ` +
114
+ `network=${this.dexHelper.config.data.network}: Unexpected ` +
115
+ `error while handling event on blockNumber=${blockHeader.number}, ` +
116
+ `blockHash=${blockHeader.hash} and parentHash=${
117
+ blockHeader.parentHash
118
+ } for QuickSwapV3, ${JSON.stringify(event)}`,
119
+ e,
120
+ );
121
+ }
122
+ _state.isValid = false;
123
+ return _state;
124
+ }
125
+ }
126
+ } catch (e) {
127
+ (0, utils_1.catchParseLogError)(e, this.logger);
128
+ }
129
+ return null; // ignore unrecognized event
130
+ }
131
+ getBitmapRangeToRequest() {
132
+ return constants_1.TICK_BITMAP_TO_USE + constants_1.TICK_BITMAP_BUFFER;
133
+ }
134
+ async _fetchPoolStateSingleStep(blockNumber) {
135
+ const callData = [
136
+ {
137
+ target: this.token0,
138
+ callData: this.erc20Interface.encodeFunctionData('balanceOf', [
139
+ this.poolAddress,
140
+ ]),
141
+ decodeFunction: decoders_1.uint256ToBigInt,
142
+ },
143
+ {
144
+ target: this.token1,
145
+ callData: this.erc20Interface.encodeFunctionData('balanceOf', [
146
+ this.poolAddress,
147
+ ]),
148
+ decodeFunction: decoders_1.uint256ToBigInt,
149
+ },
150
+ {
151
+ target: this.stateMultiContract.options.address,
152
+ callData: this.stateMultiContract.methods
153
+ .getFullStateWithRelativeBitmaps(
154
+ this.factoryAddress,
155
+ this.token0,
156
+ this.token1,
157
+ this.getBitmapRangeToRequest(),
158
+ this.getBitmapRangeToRequest(),
159
+ )
160
+ .encodeABI(),
161
+ decodeFunction: utils_2.decodeStateMultiCallResultWithRelativeBitmaps,
162
+ },
163
+ ];
164
+ const [resBalance0, resBalance1, resState] =
165
+ await this.dexHelper.multiWrapper.tryAggregate(
166
+ false,
167
+ callData,
168
+ blockNumber,
169
+ this.dexHelper.multiWrapper.defaultBatchSize,
170
+ false,
171
+ );
172
+ (0, ts_essentials_1.assert)(resState.success, 'Pool does not exist');
173
+ const [balance0, balance1, _state] = [
174
+ resBalance0.returnData,
175
+ resBalance1.returnData,
176
+ resState.returnData,
177
+ ];
178
+ return [balance0, balance1, _state];
179
+ }
180
+ async _fetchPoolStateMultiStep(blockNumber) {
181
+ const balancesAndGlobalStateCalldata = [
182
+ {
183
+ target: this.token0,
184
+ callData: this.erc20Interface.encodeFunctionData('balanceOf', [
185
+ this.poolAddress,
186
+ ]),
187
+ decodeFunction: decoders_1.uint256ToBigInt,
188
+ },
189
+ {
190
+ target: this.token1,
191
+ callData: this.erc20Interface.encodeFunctionData('balanceOf', [
192
+ this.poolAddress,
193
+ ]),
194
+ decodeFunction: decoders_1.uint256ToBigInt,
195
+ },
196
+ {
197
+ target: this.stateMultiContract.options.address,
198
+ callData: this.stateMultiContract.methods
199
+ .getFullStateWithoutTicks(
200
+ this.factoryAddress,
201
+ this.token0,
202
+ this.token1,
203
+ 0,
204
+ 0,
205
+ )
206
+ .encodeABI(),
207
+ decodeFunction: utils_2.decodeStateMultiCallResultWithRelativeBitmaps,
208
+ },
209
+ ];
210
+ const [resBalance0, resBalance1, stateWithoutTicksAndTickBitmap] =
211
+ await this.dexHelper.multiWrapper.tryAggregate(
212
+ false,
213
+ balancesAndGlobalStateCalldata,
214
+ blockNumber,
215
+ this.dexHelper.multiWrapper.defaultBatchSize,
216
+ false,
217
+ );
218
+ (0, ts_essentials_1.assert)(
219
+ stateWithoutTicksAndTickBitmap.success,
220
+ 'Pool does not exist',
221
+ );
222
+ const [balance0, balance1, _stateWithoutTicksAndTickBitmap] = [
223
+ resBalance0.returnData,
224
+ resBalance1.returnData,
225
+ stateWithoutTicksAndTickBitmap.returnData,
226
+ ];
227
+ const {
228
+ globalState: { tick },
229
+ } = _stateWithoutTicksAndTickBitmap;
230
+ const currentBitmapIndex = (0, utils_1.int16)(
231
+ (BigInt(tick) / Constants_1.Constants.TICK_SPACING) >> 8n,
232
+ );
233
+ const buffer = this.getBitmapRangeToRequest();
234
+ const startBitMapIndex = currentBitmapIndex - buffer;
235
+ const endBitMapIndex = currentBitmapIndex + buffer;
236
+ const allBitMapIndices = Array.from(
237
+ { length: 2 * Number(buffer) + 1 },
238
+ () => startBitMapIndex + endBitMapIndex,
239
+ );
240
+ const ticksAndBitMaps = await Promise.all(
241
+ allBitMapIndices.map(relativeTick => {
242
+ return this.stateMultiContract.methods
243
+ .getAdditionalBitmapWithTicks(
244
+ this.factoryAddress,
245
+ this.token0,
246
+ this.token1,
247
+ relativeTick,
248
+ relativeTick,
249
+ )
250
+ .call();
251
+ }),
252
+ );
253
+ const _state = {
254
+ ..._stateWithoutTicksAndTickBitmap,
255
+ tickBitmap: ticksAndBitMaps.flatMap(v => v[0]),
256
+ ticks: ticksAndBitMaps.flatMap(v => v[1]),
257
+ };
258
+ return [balance0, balance1, _state];
259
+ }
260
+ async _fetchInitStateMultiStrategies(blockNumber) {
261
+ try {
262
+ return await this._fetchPoolStateSingleStep(blockNumber);
263
+ } catch (e) {
264
+ if (e instanceof Error && e.message.includes('Pool does not exist'))
265
+ throw e;
266
+ if (this.dexHelper.config.data.network != constants_2.Network.ZKEVM)
267
+ throw e;
268
+ return this._fetchPoolStateMultiStep(blockNumber);
269
+ }
270
+ }
271
+ async generateState(blockNumber) {
272
+ const [balance0, balance1, _state] =
273
+ await this._fetchInitStateMultiStrategies(blockNumber);
274
+ const tickBitmap = {};
275
+ const ticks = {};
276
+ (0, utils_3._reduceTickBitmap)(tickBitmap, _state.tickBitmap);
277
+ (0, utils_3._reduceTicks)(ticks, _state.ticks);
278
+ const globalState = {
279
+ communityFeeToken0: (0, utils_1.bigIntify)(
280
+ _state.globalState.communityFeeToken0,
281
+ ),
282
+ communityFeeToken1: (0, utils_1.bigIntify)(
283
+ _state.globalState.communityFeeToken1,
284
+ ),
285
+ fee: (0, utils_1.bigIntify)(_state.globalState.fee),
286
+ price: (0, utils_1.bigIntify)(_state.globalState.price),
287
+ tick: (0, utils_1.bigIntify)(_state.globalState.tick),
288
+ };
289
+ const currentTick = globalState.tick;
290
+ const startTickBitmap = TickBitMap_1.TickBitMap.position(
291
+ BigInt(currentTick) / Constants_1.Constants.TICK_SPACING,
292
+ )[0];
293
+ return {
294
+ pool: _state.pool,
295
+ blockTimestamp: (0, utils_1.bigIntify)(_state.blockTimestamp),
296
+ globalState,
297
+ liquidity: (0, utils_1.bigIntify)(_state.liquidity),
298
+ tickSpacing: Constants_1.Constants.TICK_SPACING,
299
+ maxLiquidityPerTick: Constants_1.Constants.MAX_LIQUIDITY_PER_TICK,
300
+ tickBitmap,
301
+ ticks,
302
+ startTickBitmap,
303
+ isValid: true,
304
+ balance0,
305
+ balance1,
306
+ };
307
+ }
308
+ handleSwapEvent(event, pool, log, blockHeader) {
309
+ const newSqrtPriceX96 = (0, utils_1.bigIntify)(event.args.price);
310
+ const amount0 = (0, utils_1.bigIntify)(event.args.amount0);
311
+ const amount1 = (0, utils_1.bigIntify)(event.args.amount1);
312
+ const newTick = (0, utils_1.bigIntify)(event.args.tick);
313
+ const newLiquidity = (0, utils_1.bigIntify)(event.args.liquidity);
314
+ pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
315
+ if (amount0 <= 0n && amount1 <= 0n) {
316
+ this.logger.error(
317
+ `${this.parentName}: amount0 <= 0n && amount1 <= 0n for ` +
318
+ `${this.poolAddress} and ${blockHeader.number}. Check why it happened`,
319
+ );
320
+ pool.isValid = false;
321
+ return pool;
322
+ } else {
323
+ const zeroForOne = amount0 > 0n;
324
+ const [, , , , , communityFee] =
325
+ AlgebraMath_1.AlgebraMath._calculateSwapAndLock(
326
+ pool,
327
+ zeroForOne,
328
+ newSqrtPriceX96,
329
+ newTick,
330
+ newLiquidity,
331
+ );
332
+ if (zeroForOne) {
333
+ if (amount1 < 0n) {
334
+ pool.balance1 -= BigInt.asUintN(256, -amount1);
335
+ } else {
336
+ this.logger.error(
337
+ `In swapEvent for pool ${pool.pool} received incorrect values ${zeroForOne} and ${amount1}`,
338
+ );
339
+ pool.isValid = false;
340
+ }
341
+ // This is not correct fully, because pool may get more tokens then it needs, but
342
+ // it is not accounted in internal state, it should be good enough
343
+ pool.balance0 += BigInt.asUintN(256, amount0);
344
+ } else {
345
+ if (amount0 < 0n) {
346
+ pool.balance0 -= BigInt.asUintN(256, -amount0);
347
+ } else {
348
+ this.logger.error(
349
+ `In swapEvent for pool ${pool.pool} received incorrect values ${zeroForOne} and ${amount0}`,
350
+ );
351
+ pool.isValid = false;
352
+ }
353
+ pool.balance1 += BigInt.asUintN(256, amount1);
354
+ }
355
+ if (communityFee > 0n) {
356
+ // _payCommunityFee
357
+ if (zeroForOne) {
358
+ pool.balance0 -= communityFee;
359
+ } else {
360
+ pool.balance1 -= communityFee;
361
+ }
362
+ }
363
+ return pool;
364
+ }
365
+ }
366
+ handleMintEvent(event, pool, log, blockHeader) {
367
+ const bottomTick = (0, utils_1.bigIntify)(event.args.bottomTick);
368
+ const topTick = (0, utils_1.bigIntify)(event.args.topTick);
369
+ const liquidityActual = (0, utils_1.bigIntify)(event.args.liquidityAmount);
370
+ const amount0 = (0, utils_1.bigIntify)(event.args.amount0);
371
+ const amount1 = (0, utils_1.bigIntify)(event.args.amount1);
372
+ pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
373
+ AlgebraMath_1.AlgebraMath._updatePositionTicksAndFees(
374
+ pool,
375
+ bottomTick,
376
+ topTick,
377
+ liquidityActual,
378
+ );
379
+ pool.balance0 += amount0;
380
+ pool.balance1 += amount1;
381
+ return pool;
382
+ }
383
+ handleBurnEvent(event, pool, log, blockHeader) {
384
+ const bottomTick = (0, utils_1.bigIntify)(event.args.bottomTick);
385
+ const topTick = (0, utils_1.bigIntify)(event.args.topTick);
386
+ const amount = (0, utils_1.bigIntify)(event.args.liquidityAmount);
387
+ pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
388
+ AlgebraMath_1.AlgebraMath._updatePositionTicksAndFees(
389
+ pool,
390
+ bottomTick,
391
+ topTick,
392
+ -BigInt.asIntN(128, BigInt.asIntN(256, amount)),
393
+ );
394
+ // no balance change
395
+ return pool;
396
+ }
397
+ handleNewFee(event, pool, log, blockHeader) {
398
+ const fee = (0, utils_1.bigIntify)(event.args.fee);
399
+ pool.globalState.fee = fee;
400
+ pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
401
+ return pool;
402
+ }
403
+ handleCollectEvent(event, pool, log, blockHeader) {
404
+ const amount0 = (0, utils_1.bigIntify)(event.args.amount0);
405
+ const amount1 = (0, utils_1.bigIntify)(event.args.amount1);
406
+ pool.balance0 -= amount0;
407
+ pool.balance1 -= amount1;
408
+ pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
409
+ return pool;
410
+ }
411
+ handleFlashEvent(event, pool, log, blockHeader) {
412
+ const paid0 = (0, utils_1.bigIntify)(event.args.paid0);
413
+ const paid1 = (0, utils_1.bigIntify)(event.args.paid1);
414
+ pool.balance0 += paid0;
415
+ pool.balance1 += paid1;
416
+ pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
417
+ return pool;
418
+ }
419
+ handleCommunityFee(event, pool, log, blockHeader) {
420
+ const communityFeeToken0 = (0, utils_1.bigIntify)(
421
+ event.ags.communityFee0New,
422
+ );
423
+ const communityFeeToken1 = (0, utils_1.bigIntify)(
424
+ event.ags.communityFee1New,
425
+ );
426
+ pool.globalState.communityFeeToken0 = communityFeeToken0;
427
+ pool.globalState.communityFeeToken1 = communityFeeToken1;
428
+ pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
429
+ return pool;
430
+ }
431
+ _computePoolAddress(token0, token1) {
432
+ // https://github.com/Uniswap/v3-periphery/blob/main/contracts/libraries/PoolAddress.sol
433
+ if (token0 > token1) [token0, token1] = [token1, token0];
434
+ const encodedKey = ethers_1.ethers.utils.keccak256(
435
+ ethers_1.ethers.utils.defaultAbiCoder.encode(
436
+ ['address', 'address'],
437
+ [token0, token1],
438
+ ),
439
+ );
440
+ return ethers_1.ethers.utils.getCreate2Address(
441
+ this.poolDeployer,
442
+ encodedKey,
443
+ this.poolInitCodeHash,
444
+ );
445
+ }
446
+ }
447
+ exports.AlgebraEventPool = AlgebraEventPool;
448
+ //# sourceMappingURL=algebra-pool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"algebra-pool.js","sourceRoot":"","sources":["../../../src/dex/algebra/algebra-pool.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAuB;AACvB,4CAA+C;AAC/C,iDAAqD;AAErD,uCAAmE;AACnE,+EAGyC;AAOzC,mCAAgC;AAEhC,kGAAgE;AAEhE,uDAIiC;AACjC,iDAAqD;AAErD,mCAAwE;AACxE,mDAAgD;AAChD,uEAAoE;AACpE,6DAG2C;AAC3C,+CAA4C;AAC5C,+CAA0C;AAE1C,MAAa,gBAAiB,SAAQ,mDAAkC;IAuBtE,YACW,SAAqB,EAC9B,UAAkB,EACT,kBAA4B,EAC5B,cAAyB,EACf,cAAuB,EAC1C,MAAe,EACf,MAAe,EACf,MAAc,EACd,SAAiB,EAAE,EACV,gBAAwB,EACxB,YAAoB;QAE7B,KAAK,CAAC,UAAU,EAAE,GAAG,MAAM,IAAI,MAAM,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QAZjE,cAAS,GAAT,SAAS,CAAY;QAErB,uBAAkB,GAAlB,kBAAkB,CAAU;QAC5B,mBAAc,GAAd,cAAc,CAAW;QACf,mBAAc,GAAd,cAAc,CAAS;QAKjC,qBAAgB,GAAhB,gBAAgB,CAAQ;QACxB,iBAAY,GAAZ,YAAY,CAAQ;QAjC/B,aAAQ,GAOJ,EAAE,CAAC;QAUS,cAAS,GAAG,IAAI,eAAS,CAAC,8BAAU,CAAC,CA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,CAAC,CAAC;QAEvD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,kBAAkB,CAChB,KAAU,EACV,IAAe,EACf,GAAQ,EACR,WAAwB;QAExB,MAAM,kBAAkB,GAAG,IAAA,iBAAS,EAAC,KAAK,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;QACjE,MAAM,kBAAkB,GAAG,IAAA,iBAAS,EAAC,KAAK,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;QAEjE,IAAI,CAAC,WAAW,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;QACzD,IAAI,CAAC,WAAW,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;QAEzD,IAAI,CAAC,cAAc,GAAG,IAAA,iBAAS,EAAC,WAAW,CAAC,SAAS,CAAC,CAAC;QAEvD,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,mBAAmB,CAAC,MAAe,EAAE,MAAe;QAC1D,wFAAwF;QACxF,IAAI,MAAM,GAAG,MAAM;YAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAEzD,MAAM,UAAU,GAAG,eAAM,CAAC,KAAK,CAAC,SAAS,CACvC,eAAM,CAAC,KAAK,CAAC,eAAe,CAAC,MAAM,CACjC,CAAC,SAAS,EAAE,SAAS,CAAC,EACtB,CAAC,MAAM,EAAE,MAAM,CAAC,CACjB,CACF,CAAC;QAEF,OAAO,eAAM,CAAC,KAAK,CAAC,iBAAiB,CACnC,IAAI,CAAC,YAAY,EACjB,UAAU,EACV,IAAI,CAAC,gBAAgB,CACtB,CAAC;IACJ,CAAC;CACF;AA1hBD,4CA0hBC"}
@@ -0,0 +1,43 @@
1
+ import { Interface } from '@ethersproject/abi';
2
+ import { BigNumber } from '@ethersproject/bignumber';
3
+ import { BasePool } from './balancer-v2-pool';
4
+ import { SwapSide } from '../../constants';
5
+ import { callData, SubgraphPoolBase, PoolState } from './types';
6
+ export declare type Gyro3PoolPairData = {
7
+ balances: BigNumber[];
8
+ indexIn: number;
9
+ indexOut: number;
10
+ swapFee: bigint;
11
+ balanceTertiary: BigNumber;
12
+ decimalsTertiary: number;
13
+ scalingFactors: bigint[];
14
+ root3Alpha: BigNumber;
15
+ };
16
+ export declare class Gyro3Pool extends BasePool {
17
+ vaultAddress: string;
18
+ vaultInterface: Interface;
19
+ poolInterface: Interface;
20
+ constructor(vaultAddress: string, vaultInterface: Interface);
21
+ parsePoolPairData(
22
+ pool: SubgraphPoolBase,
23
+ poolState: PoolState,
24
+ tokenIn: string,
25
+ tokenOut: string,
26
+ ): Gyro3PoolPairData;
27
+ getSwapMaxAmount(poolPairData: Gyro3PoolPairData, side: SwapSide): bigint;
28
+ getOnChainCalls(pool: SubgraphPoolBase): callData[];
29
+ decodeOnChainCalls(
30
+ pool: SubgraphPoolBase,
31
+ data: {
32
+ success: boolean;
33
+ returnData: any;
34
+ }[],
35
+ startIndex: number,
36
+ ): [
37
+ {
38
+ [address: string]: PoolState;
39
+ },
40
+ number,
41
+ ];
42
+ onSell(amounts: bigint[], poolPairData: Gyro3PoolPairData): bigint[];
43
+ }