@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
@@ -26,53 +26,57 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.KyberswapElastic = void 0;
30
- const abi_1 = require("@ethersproject/abi");
31
- const solidity_1 = require("@ethersproject/solidity");
32
- const lodash_1 = __importDefault(require("lodash"));
33
- const types_1 = require("../../lib/tokens/types");
29
+ exports.SushiswapV3 = void 0;
34
30
  const constants_1 = require("../../constants");
35
31
  const CALLDATA_GAS_COST = __importStar(require("../../calldata-gas-cost"));
36
32
  const utils_1 = require("../../utils");
37
- const balancer_fetcher_1 = require("../../lib/tokens/balancer-fetcher");
38
33
  const simple_exchange_1 = require("../simple-exchange");
39
- const multi_v2_json_1 = __importDefault(require("../../abi/multi-v2.json"));
40
- const IRouter_json_1 = __importDefault(require("../../abi/kyberswap-elastic/IRouter.json"));
41
- const IQuoterV2_json_1 = __importDefault(require("../../abi/kyberswap-elastic/IQuoterV2.json"));
42
- const types_2 = require("./types");
43
34
  const config_1 = require("./config");
35
+ const sushiswap_v3_pool_1 = require("./sushiswap-v3-pool");
36
+ const utils_2 = require("ethers/lib/utils");
37
+ const solidity_1 = require("@ethersproject/solidity");
44
38
  const constants_2 = require("./constants");
45
- const kyberswap_elastic_pool_1 = require("./kyberswap-elastic-pool");
46
- const kyberswap_elastic_math_1 = require("./contract-math/kyberswap-elastic-math");
47
- const errors_1 = require("./errors");
48
- const CLEAN_NOT_EXISTING_POOL_TTL_MS = 60 * 60 * 24 * 1000; // 24 hours
49
- const CLEAN_NOT_EXISTING_POOL_INTERVAL_MS = 30 * 60 * 1000; // Once in 30 minutes
50
- class KyberswapElastic extends simple_exchange_1.SimpleExchange {
51
- constructor(network, dexKey, dexHelper, adapters = config_1.Adapters[network] || {}, config = config_1.KyberswapElasticConfig[dexKey][network]) {
39
+ const uniswap_v3_math_1 = require("../uniswap-v3/contract-math/uniswap-v3-math");
40
+ const balancer_fetcher_1 = require("../../lib/tokens/balancer-fetcher");
41
+ const types_1 = require("../../lib/tokens/types");
42
+ const router_1 = require("@sushiswap/router");
43
+ const viem_1 = require("viem");
44
+ const RouterProcessor3_json_1 = __importDefault(require("../../abi/sushiswap-v3/RouterProcessor3.json"));
45
+ const QuoterV2_json_1 = __importDefault(require("../../abi/sushiswap-v3/QuoterV2.json"));
46
+ const UniswapMulti_abi_json_1 = __importDefault(require("../../abi/uniswap-v3/UniswapMulti.abi.json"));
47
+ const UniswapV3StateMulticall_abi_json_1 = __importDefault(require("../../abi/uniswap-v3/UniswapV3StateMulticall.abi.json"));
48
+ const config_2 = require("../../config");
49
+ const ethers_1 = require("ethers");
50
+ const token_1 = require("./token");
51
+ const lodash_1 = __importDefault(require("lodash"));
52
+ const config_3 = require("../uniswap-v3/config");
53
+ const UNISWAPV3_CLEAN_NOT_EXISTING_POOL_TTL_MS = 60 * 60 * 24 * 1000; // 24 hours
54
+ const UNISWAPV3_CLEAN_NOT_EXISTING_POOL_INTERVAL_MS = 30 * 60 * 1000; // Once in 30 minutes
55
+ const UNISWAPV3_QUOTE_GASLIMIT = 200000;
56
+ class SushiswapV3 extends simple_exchange_1.SimpleExchange {
57
+ constructor(network, dexKey, dexHelper, adapters = config_1.Adapters[network] || {}, routerIface = new utils_2.Interface(RouterProcessor3_json_1.default), quoterIface = new utils_2.Interface(QuoterV2_json_1.default), config = config_1.SushiswapV3Config[dexKey][network]) {
52
58
  super(dexHelper, dexKey);
53
59
  this.network = network;
54
60
  this.dexKey = dexKey;
55
61
  this.dexHelper = dexHelper;
56
62
  this.adapters = adapters;
63
+ this.routerIface = routerIface;
64
+ this.quoterIface = quoterIface;
57
65
  this.config = config;
58
66
  this.eventPools = {};
59
67
  this.hasConstantPriceLargeAmounts = false;
60
68
  this.needWrapNative = true;
61
69
  this.isFeeOnTransferSupported = false;
62
- this.routerIface = new abi_1.Interface(IRouter_json_1.default);
63
- this.quoterIface = new abi_1.Interface(IQuoterV2_json_1.default);
64
70
  this.logger = dexHelper.getLogger(dexKey + '-' + network);
71
+ this.uniswapMulti = new this.dexHelper.web3Provider.eth.Contract(UniswapMulti_abi_json_1.default, this.config.uniswapMulticall);
72
+ this.stateMultiContract = new this.dexHelper.web3Provider.eth.Contract(UniswapV3StateMulticall_abi_json_1.default, this.config.stateMulticall);
65
73
  // To receive revert reasons
66
74
  this.dexHelper.web3Provider.eth.handleRevert = false;
67
75
  // Normalise once all config addresses and use across all scenarios
68
76
  this.config = this._toLowerForAllConfigAddresses();
69
- this.multicall = new this.dexHelper.web3Provider.eth.Contract(multi_v2_json_1.default, this.dexHelper.config.data.multicallV2Address);
70
77
  this.notExistingPoolSetKey =
71
78
  `${constants_1.CACHE_PREFIX}_${network}_${dexKey}_not_existings_pool_set`.toLowerCase();
72
79
  }
73
- get supportedFees() {
74
- return this.config.supportedFees;
75
- }
76
80
  // Initialize pricing is called once in the start of
77
81
  // pricing service. It is intended to setup the integration
78
82
  // for pricing requests. It is optional for a DEX to
@@ -80,46 +84,23 @@ class KyberswapElastic extends simple_exchange_1.SimpleExchange {
80
84
  async initializePricing(blockNumber) {
81
85
  if (!this.dexHelper.config.isSlave) {
82
86
  const cleanExpiredNotExistingPoolsKeys = async () => {
83
- const maxTimestamp = Date.now() - CLEAN_NOT_EXISTING_POOL_TTL_MS;
87
+ const maxTimestamp = Date.now() - UNISWAPV3_CLEAN_NOT_EXISTING_POOL_TTL_MS;
84
88
  await this.dexHelper.cache.zremrangebyscore(this.notExistingPoolSetKey, 0, maxTimestamp);
85
89
  };
86
- this._intervalTask = setInterval(cleanExpiredNotExistingPoolsKeys.bind(this), CLEAN_NOT_EXISTING_POOL_INTERVAL_MS);
90
+ this.intervalTask = setInterval(cleanExpiredNotExistingPoolsKeys.bind(this), UNISWAPV3_CLEAN_NOT_EXISTING_POOL_INTERVAL_MS);
87
91
  }
88
92
  }
93
+ get supportedFees() {
94
+ return this.config.supportedFees;
95
+ }
89
96
  // Returns the list of contract adapters (name and index)
90
97
  // for a buy/sell. Return null if there are no adapters.
91
98
  getAdapters(side) {
92
99
  return this.adapters[side] ? this.adapters[side] : null;
93
100
  }
94
- // Build an event based pool with all the info to create inside
95
- // a cache key name poolKey
96
- async addMasterPool(poolKey, blockNumber) {
97
- const _pairs = await this.dexHelper.cache.hget(this.dexmapKey, poolKey);
98
- if (!_pairs) {
99
- this.logger.warn(`did not find poolConfig in for key ${this.dexmapKey} ${poolKey}`);
100
- return false;
101
- }
102
- const poolInfo = JSON.parse(_pairs);
103
- const pool = await this._getPool(poolInfo.token0, poolInfo.token1, BigInt(poolInfo.swapFeeUnits), blockNumber);
104
- if (!pool) {
105
- return false;
106
- }
107
- return true;
108
- }
109
- // Returns list of pool identifiers that can be used
110
- // for a given swap. poolIdentifiers must be unique
111
- // across DEXes. It is recommended to use
112
- // ${dexKey}_${poolAddress} as a poolIdentifier
113
- async getPoolIdentifiers(srcToken, destToken, side, blockNumber) {
114
- const _srcToken = this.dexHelper.config.wrapETH(srcToken);
115
- const _destToken = this.dexHelper.config.wrapETH(destToken);
116
- const [_srcAddress, _destAddress] = this._getLoweredAddresses(_srcToken, _destToken);
117
- if (_srcAddress === _destAddress)
118
- return [];
119
- const pools = (await Promise.all(this.supportedFees.map(async (swapFeeUnits) => this._getPool(_srcAddress, _destAddress, swapFeeUnits, blockNumber)))).filter(pool => pool);
120
- if (pools.length === 0)
121
- return [];
122
- return pools.map(pool => this._getPoolIdentifier(_srcAddress, _destAddress, pool.swapFeeUnits));
101
+ getPoolIdentifier(srcAddress, destAddress, fee) {
102
+ const tokenAddresses = this._sortTokens(srcAddress, destAddress).join('_');
103
+ return `${this.dexKey}_${tokenAddresses}_${fee}`;
123
104
  }
124
105
  // Returns pool prices for amounts.
125
106
  // If limitPools is defined only pools in limitPools
@@ -134,23 +115,23 @@ class KyberswapElastic extends simple_exchange_1.SimpleExchange {
134
115
  return null;
135
116
  let selectedPools = [];
136
117
  if (!limitPools) {
137
- selectedPools = (await Promise.all(this.supportedFees.map(async (swapFeeUnits) => {
138
- const locallyFoundPool = this.eventPools[this._getPoolIdentifier(_srcAddress, _destAddress, swapFeeUnits)];
118
+ selectedPools = (await Promise.all(this.supportedFees.map(async (fee) => {
119
+ const locallyFoundPool = this.eventPools[this.getPoolIdentifier(_srcAddress, _destAddress, fee)];
139
120
  if (locallyFoundPool)
140
121
  return locallyFoundPool;
141
- const newlyFetchedPool = await this._getPool(_srcAddress, _destAddress, swapFeeUnits, blockNumber);
122
+ const newlyFetchedPool = await this.getPool(_srcAddress, _destAddress, fee, blockNumber);
142
123
  return newlyFetchedPool;
143
124
  }))).filter(utils_1.isTruthy);
144
125
  }
145
126
  else {
146
- const pairIdentifierWithoutFee = this._getPoolIdentifier(_srcAddress, _destAddress, 0n).slice(0, -1);
127
+ const pairIdentifierWithoutFee = this.getPoolIdentifier(_srcAddress, _destAddress, 0n).slice(0, -1);
147
128
  const poolIdentifiers = limitPools.filter(identifier => identifier.startsWith(pairIdentifierWithoutFee));
148
129
  selectedPools = (await Promise.all(poolIdentifiers.map(async (identifier) => {
149
130
  let locallyFoundPool = this.eventPools[identifier];
150
131
  if (locallyFoundPool)
151
132
  return locallyFoundPool;
152
- const [, srcAddress, destAddress, swapFeeUnits] = identifier.split('_');
153
- const newlyFetchedPool = await this._getPool(srcAddress, destAddress, BigInt(swapFeeUnits), blockNumber);
133
+ const [, srcAddress, destAddress, fee] = identifier.split('_');
134
+ const newlyFetchedPool = await this.getPool(srcAddress, destAddress, BigInt(fee), blockNumber);
154
135
  return newlyFetchedPool;
155
136
  }))).filter(utils_1.isTruthy);
156
137
  }
@@ -170,21 +151,21 @@ class KyberswapElastic extends simple_exchange_1.SimpleExchange {
170
151
  poolWithState: [],
171
152
  poolWithoutState: [],
172
153
  });
173
- const rpcResultsPromise = this._getPricingFromRpc(_srcToken, _destToken, amounts, side, poolsToUse.poolWithoutState);
154
+ const rpcResultsPromise = this.getPricingFromRpc(_srcToken, _destToken, amounts, side, poolsToUse.poolWithoutState);
174
155
  const states = poolsToUse.poolWithState.map(p => p.getState(blockNumber));
175
156
  const unitAmount = (0, utils_1.getBigIntPow)(side == constants_1.SwapSide.SELL ? _srcToken.decimals : _destToken.decimals);
176
157
  const _amounts = [...amounts.slice(1)];
177
158
  const [token0] = this._sortTokens(_srcAddress, _destAddress);
178
- const isToken0 = token0 === _srcAddress ? true : false;
159
+ const zeroForOne = token0 === _srcAddress ? true : false;
179
160
  const result = await Promise.all(poolsToUse.poolWithState.map(async (pool, i) => {
180
161
  const state = states[i];
181
- if (state.poolData.baseL <= 0n) {
162
+ if (state.liquidity <= 0n) {
182
163
  this.logger.trace(`pool have 0 liquidity`);
183
164
  return null;
184
165
  }
185
166
  const balanceDestToken = _destAddress === pool.token0 ? state.balance0 : state.balance1;
186
- const unitResult = this._getOutputs(state, [unitAmount], isToken0, side, balanceDestToken);
187
- const pricesResult = this._getOutputs(state, _amounts, isToken0, side, balanceDestToken);
167
+ const unitResult = this._getOutputs(state, [unitAmount], zeroForOne, side, balanceDestToken);
168
+ const pricesResult = this._getOutputs(state, _amounts, zeroForOne, side, balanceDestToken);
188
169
  if (!unitResult || !pricesResult) {
189
170
  this.logger.debug('Prices or unit is not calculated');
190
171
  return null;
@@ -197,9 +178,9 @@ class KyberswapElastic extends simple_exchange_1.SimpleExchange {
197
178
  return 0;
198
179
  }
199
180
  else {
200
- return (constants_2.KS_ELASTIC_POOL_SEARCH_OVERHEAD +
201
- constants_2.KS_ELASTIC_TICK_BASE_OVERHEAD +
202
- pricesResult.tickCounts[index] * constants_2.KS_ELASTIC_TICK_GAS_COST);
181
+ return (constants_2.UNISWAPV3_POOL_SEARCH_OVERHEAD +
182
+ constants_2.UNISWAPV3_TICK_BASE_OVERHEAD +
183
+ pricesResult.tickCounts[index] * constants_2.UNISWAPV3_TICK_GAS_COST);
203
184
  }
204
185
  }),
205
186
  ];
@@ -211,11 +192,11 @@ class KyberswapElastic extends simple_exchange_1.SimpleExchange {
211
192
  {
212
193
  tokenIn: _srcAddress,
213
194
  tokenOut: _destAddress,
214
- swapFeeUnits: pool.swapFeeUnits.toString(),
195
+ fee: pool.feeCode.toString(),
215
196
  },
216
197
  ],
217
198
  },
218
- poolIdentifier: this._getPoolIdentifier(pool.token0, pool.token1, pool.swapFeeUnits),
199
+ poolIdentifier: this.getPoolIdentifier(pool.token0, pool.token1, pool.feeCode),
219
200
  exchange: this.dexKey,
220
201
  gasCost: gasCost,
221
202
  poolAddresses: [pool.poolAddress],
@@ -237,21 +218,115 @@ class KyberswapElastic extends simple_exchange_1.SimpleExchange {
237
218
  return null;
238
219
  }
239
220
  }
221
+ getQuoterV2CallData(funcName, tokenIn, tokenOut, amount, fee) {
222
+ return funcName === 'quoteExactInputSingle'
223
+ ? { tokenIn, tokenOut, fee, sqrtPriceLimitX96: 0n, amountIn: amount }
224
+ : { tokenIn, tokenOut, fee, sqrtPriceLimitX96: 0n, amount };
225
+ }
226
+ async getPricingFromRpc(from, to, amounts, side, pools) {
227
+ if (pools.length === 0) {
228
+ return null;
229
+ }
230
+ this.logger.warn(`fallback to rpc for ${pools.length} pool(s)`);
231
+ const requests = pools.map(pool => ({
232
+ owner: pool.poolAddress,
233
+ asset: side == constants_1.SwapSide.SELL ? from.address : to.address,
234
+ assetType: types_1.AssetType.ERC20,
235
+ ids: [
236
+ {
237
+ id: types_1.DEFAULT_ID_ERC20,
238
+ spenders: [],
239
+ },
240
+ ],
241
+ }), []);
242
+ const balances = await (0, balancer_fetcher_1.getBalances)(this.dexHelper.multiWrapper, requests);
243
+ pools = pools.filter((pool, index) => {
244
+ const balance = balances[index].amounts[types_1.DEFAULT_ID_ERC20_AS_STRING];
245
+ if (balance >= amounts[amounts.length - 1]) {
246
+ return true;
247
+ }
248
+ this.logger.warn(`[${this.network}][${pool.parentName}] have no balance ${pool.poolAddress} ${from.address} ${to.address}. (Balance: ${balance})`);
249
+ return false;
250
+ });
251
+ pools.forEach(pool => {
252
+ this.logger.warn(`[${this.network}][${pool.parentName}] fallback to rpc for ${pool.name}`);
253
+ });
254
+ const unitVolume = (0, utils_1.getBigIntPow)((side === constants_1.SwapSide.SELL ? from : to).decimals);
255
+ const chunks = amounts.length - 1;
256
+ const _width = Math.floor(chunks / this.config.chunksCount);
257
+ const _amounts = [unitVolume].concat(Array.from(Array(this.config.chunksCount).keys()).map(i => amounts[(i + 1) * _width]));
258
+ const funcName = side === constants_1.SwapSide.SELL
259
+ ? 'quoteExactInputSingle'
260
+ : 'quoteExactOutputSingle';
261
+ const calldata = pools.map(pool => _amounts.map(_amount => ({
262
+ target: this.config.quoter,
263
+ gasLimit: UNISWAPV3_QUOTE_GASLIMIT,
264
+ callData: this.quoterIface.encodeFunctionData(funcName, [
265
+ this.getQuoterV2CallData(funcName, from.address, to.address, _amount, pool.feeCode),
266
+ ]),
267
+ })));
268
+ const data = await new this.dexHelper.web3Provider.eth.Contract(UniswapMulti_abi_json_1.default, this.config.uniswapMulticall).methods
269
+ .multicall(calldata.flat())
270
+ .call();
271
+ const decode = (j) => {
272
+ if (!data.returnData[j].success) {
273
+ return 0n;
274
+ }
275
+ const decoded = utils_2.defaultAbiCoder.decode(['uint256'], data.returnData[j].returnData);
276
+ return BigInt(decoded[0].toString());
277
+ };
278
+ let i = 0;
279
+ const result = pools.map(pool => {
280
+ const _rates = _amounts.map(() => decode(i++));
281
+ const unit = _rates[0];
282
+ const prices = (0, utils_1.interpolate)(_amounts.slice(1), _rates.slice(1), amounts, side);
283
+ return {
284
+ prices,
285
+ unit,
286
+ data: {
287
+ path: [
288
+ {
289
+ tokenIn: from.address,
290
+ tokenOut: to.address,
291
+ fee: pool.feeCodeAsString,
292
+ },
293
+ ],
294
+ },
295
+ poolIdentifier: this.getPoolIdentifier(pool.token0, pool.token1, pool.feeCode),
296
+ exchange: this.dexKey,
297
+ gasCost: prices.map(p => (p === 0n ? 0 : UNISWAPV3_QUOTE_GASLIMIT)),
298
+ poolAddresses: [pool.poolAddress],
299
+ };
300
+ });
301
+ return result;
302
+ }
240
303
  // Returns estimated gas cost of calldata for this DEX in multiSwap
241
304
  getCalldataGasCost(poolPrices) {
242
- // TODO: update if there is any payload in getAdapterParam
243
- return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
244
- }
245
- // Returns a pool identifier that can be used
246
- // for a given swap. Use:
247
- // ${dexKey}_${poolAddress} as a poolIdentifier
248
- _getPoolIdentifier(srcAddress, destAddress, swapFeeUnits) {
249
- const tokenAddresses = this._sortTokens(srcAddress, destAddress).join('_');
250
- return `${this.dexKey}_${tokenAddresses}_${swapFeeUnits.toString()}`;
305
+ const gasCost = CALLDATA_GAS_COST.DEX_OVERHEAD +
306
+ CALLDATA_GAS_COST.LENGTH_SMALL +
307
+ // ParentStruct header
308
+ CALLDATA_GAS_COST.OFFSET_SMALL +
309
+ // ParentStruct -> path header
310
+ CALLDATA_GAS_COST.OFFSET_SMALL +
311
+ // ParentStruct -> deadline
312
+ CALLDATA_GAS_COST.TIMESTAMP +
313
+ // ParentStruct -> path (20+3+20 = 43 = 32+11 bytes)
314
+ CALLDATA_GAS_COST.LENGTH_SMALL +
315
+ CALLDATA_GAS_COST.FULL_WORD +
316
+ CALLDATA_GAS_COST.wordNonZeroBytes(11);
317
+ const arr = new Array(poolPrices.prices.length);
318
+ poolPrices.prices.forEach((p, index) => {
319
+ if (p == 0n) {
320
+ arr[index] = 0;
321
+ }
322
+ else {
323
+ arr[index] = gasCost;
324
+ }
325
+ });
326
+ return arr;
251
327
  }
252
328
  // Encode params required by the exchange adapter
253
329
  // Used for multiSwap, buy & megaSwap
254
- // Hint: abiCoder.encodeParameter() could be useful
255
330
  getAdapterParam(srcToken, destToken, srcAmount, destAmount, data, side) {
256
331
  const { path: rawPath } = data;
257
332
  const path = this._encodePath(rawPath, side);
@@ -262,45 +337,40 @@ class KyberswapElastic extends simple_exchange_1.SimpleExchange {
262
337
  },
263
338
  }, {
264
339
  path,
265
- deadline: (0, simple_exchange_1.getLocalDeadlineAsFriendlyPlaceholder)(),
340
+ deadline: (0, simple_exchange_1.getLocalDeadlineAsFriendlyPlaceholder)(), // FIXME: more gas efficient to pass block.timestamp in adapter
266
341
  });
267
342
  return {
268
- targetExchange: this.config.router,
343
+ targetExchange: config_3.UniswapV3Config['UniswapV3'][this.network].router,
269
344
  payload,
270
345
  networkFee: '0',
271
346
  };
272
347
  }
273
348
  // Encode call data used by simpleSwap like routers
274
349
  // Used for simpleSwap & simpleBuy
275
- // Hint: this.buildSimpleParamWithoutWETHConversion
276
- // could be useful
277
- async getSimpleParam(srcToken, destToken, srcAmount, destAmount, data, side) {
278
- const swapFunction = side === constants_1.SwapSide.SELL
279
- ? types_2.KyberElasticFunctions.quoteExactInputSingle
280
- : types_2.KyberElasticFunctions.quoteExactOutputSingle;
281
- const path = this._encodePath(data.path, side);
282
- const swapFunctionParams = side === constants_1.SwapSide.SELL
283
- ? {
284
- recipient: this.augustusAddress,
285
- deadline: (0, simple_exchange_1.getLocalDeadlineAsFriendlyPlaceholder)(),
286
- amountIn: srcAmount,
287
- amountOutMinimum: destAmount,
288
- path,
289
- }
290
- : {
291
- recipient: this.augustusAddress,
292
- deadline: (0, simple_exchange_1.getLocalDeadlineAsFriendlyPlaceholder)(),
293
- amountOut: destAmount,
294
- amountInMaximum: srcAmount,
295
- path,
296
- };
297
- const swapData = this.routerIface.encodeFunctionData(swapFunction, [
298
- swapFunctionParams,
350
+ async getSimpleParam(srcToken, destToken, srcAmount, destAmount, data) {
351
+ const web3Client = (0, viem_1.createPublicClient)({
352
+ chain: constants_2.ViemChain[this.network],
353
+ transport: (0, viem_1.http)((0, config_2.generateConfig)(this.network).privateHttpProvider),
354
+ });
355
+ const dataFetcher = new router_1.DataFetcher(web3Client.chain.id, web3Client);
356
+ dataFetcher.startDataFetching([router_1.LiquidityProviders.SushiSwapV3]);
357
+ const fromToken = await (0, token_1.getToken)({ web3Client, address: srcToken });
358
+ const toToken = await (0, token_1.getToken)({ web3Client, address: destToken });
359
+ await dataFetcher.fetchPoolsForToken(fromToken, toToken);
360
+ const pcMap = dataFetcher.getCurrentPoolCodeMap(fromToken, toToken);
361
+ const route = router_1.Router.findBestRoute(pcMap, this.network, fromToken, ethers_1.BigNumber.from(srcAmount), toToken, 50e9, [router_1.LiquidityProviders.SushiSwapV3]);
362
+ const rpParams = router_1.Router.routeProcessor2Params(pcMap, route, fromToken, toToken, this.augustusAddress, this.config.router);
363
+ const swapData = this.routerIface.encodeFunctionData('processRoute', [
364
+ rpParams.tokenIn,
365
+ rpParams.amountIn,
366
+ rpParams.tokenOut,
367
+ rpParams.amountOutMin,
368
+ rpParams.to,
369
+ rpParams.routeCode,
299
370
  ]);
371
+ dataFetcher.stopDataFetching();
300
372
  return this.buildSimpleParamWithoutWETHConversion(srcToken, srcAmount, destToken, destAmount, swapData, this.config.router);
301
373
  }
302
- // Returns list of top pools based on liquidity. Max
303
- // limit number pools should be returned.
304
374
  async getTopPoolsForToken(tokenAddress, limit) {
305
375
  const _tokenAddress = tokenAddress.toLowerCase();
306
376
  const res = await this._querySubgraph(`query ($token: Bytes!, $count: Int) {
@@ -345,7 +415,7 @@ class KyberswapElastic extends simple_exchange_1.SimpleExchange {
345
415
  decimals: parseInt(pool.token1.decimals),
346
416
  },
347
417
  ],
348
- liquidityUSD: parseFloat(pool.totalValueLockedUSD) * constants_2.KS_ELASTIC_EFFICIENCY_FACTOR,
418
+ liquidityUSD: parseFloat(pool.totalValueLockedUSD) * constants_2.UNISWAPV3_EFFICIENCY_FACTOR,
349
419
  }));
350
420
  const pools1 = lodash_1.default.map(res.pools1, pool => ({
351
421
  exchange: this.dexKey,
@@ -356,222 +426,134 @@ class KyberswapElastic extends simple_exchange_1.SimpleExchange {
356
426
  decimals: parseInt(pool.token0.decimals),
357
427
  },
358
428
  ],
359
- liquidityUSD: parseFloat(pool.totalValueLockedUSD) * constants_2.KS_ELASTIC_EFFICIENCY_FACTOR,
429
+ liquidityUSD: parseFloat(pool.totalValueLockedUSD) * constants_2.UNISWAPV3_EFFICIENCY_FACTOR,
360
430
  }));
361
431
  const pools = lodash_1.default.slice(lodash_1.default.sortBy(lodash_1.default.concat(pools0, pools1), [pool => -1 * pool.liquidityUSD]), 0, limit);
362
432
  return pools;
363
433
  }
364
- async _querySubgraph(query, variables, timeout = 30000) {
365
- try {
366
- const res = await this.dexHelper.httpRequest.post(this.config.subgraphURL, { query, variables }, undefined, { timeout: timeout });
367
- return res.data;
368
- }
369
- catch (e) {
370
- this.logger.error(`${this.dexKey}: can not query subgraph: `, e);
371
- return {};
372
- }
373
- }
374
- releaseResources() {
375
- if (this._intervalTask !== undefined) {
376
- clearInterval(this._intervalTask);
377
- this._intervalTask = undefined;
434
+ _encodePath(path, side) {
435
+ if (path.length === 0) {
436
+ this.logger.error(`${this.dexKey}: Received invalid path=${path} for side=${side} to encode`);
437
+ return '0x';
378
438
  }
439
+ const { _path, types } = path.reduce(({ _path, types }, curr, index) => {
440
+ if (index === 0) {
441
+ return {
442
+ types: ['address', 'uint24', 'address'],
443
+ _path: [curr.tokenIn, curr.fee, curr.tokenOut],
444
+ };
445
+ }
446
+ else {
447
+ return {
448
+ types: [...types, 'uint24', 'address'],
449
+ _path: [..._path, curr.fee, curr.tokenOut],
450
+ };
451
+ }
452
+ }, { _path: [], types: [] });
453
+ return side === constants_1.SwapSide.BUY
454
+ ? (0, solidity_1.pack)(types.reverse(), _path.reverse())
455
+ : (0, solidity_1.pack)(types, _path);
379
456
  }
380
- _sortTokens(srcAddress, destAddress) {
381
- return [srcAddress, destAddress].sort((a, b) => (a < b ? -1 : 1));
457
+ async getPoolIdentifiers(srcToken, destToken, side, blockNumber) {
458
+ const _srcToken = this.dexHelper.config.wrapETH(srcToken);
459
+ const _destToken = this.dexHelper.config.wrapETH(destToken);
460
+ const [_srcAddress, _destAddress] = this._getLoweredAddresses(_srcToken, _destToken);
461
+ if (_srcAddress === _destAddress)
462
+ return [];
463
+ const pools = (await Promise.all(this.supportedFees.map(async (fee) => this.getPool(_srcAddress, _destAddress, fee, blockNumber)))).filter(pool => pool);
464
+ if (pools.length === 0)
465
+ return [];
466
+ return pools.map(pool => this.getPoolIdentifier(_srcAddress, _destAddress, pool.feeCode));
382
467
  }
383
- async _getPool(srcAddress, destAddress, swapFeeUnits, blockNumber) {
384
- let pool = this.eventPools[this._getPoolIdentifier(srcAddress, destAddress, swapFeeUnits)];
468
+ async getPool(srcAddress, destAddress, fee, blockNumber) {
469
+ let pool = this.eventPools[this.getPoolIdentifier(srcAddress, destAddress, fee)];
385
470
  if (pool === undefined) {
386
471
  const [token0, token1] = this._sortTokens(srcAddress, destAddress);
387
- const key = `${token0}_${token1}_${swapFeeUnits}`.toLowerCase();
388
- // Check if the pool key is in the notExistingPool set,
389
- // if yes, return null without initialize a new pool instance.
472
+ const key = `${token0}_${token1}_${fee}`.toLowerCase();
390
473
  const notExistingPoolScore = await this.dexHelper.cache.zscore(this.notExistingPoolSetKey, key);
391
474
  const poolDoesNotExist = notExistingPoolScore !== null;
392
475
  if (poolDoesNotExist) {
393
- this.eventPools[this._getPoolIdentifier(srcAddress, destAddress, swapFeeUnits)] = null;
476
+ this.eventPools[this.getPoolIdentifier(srcAddress, destAddress, fee)] =
477
+ null;
394
478
  return null;
395
479
  }
396
- // Store this pool
397
480
  await this.dexHelper.cache.hset(this.dexmapKey, key, JSON.stringify({
398
481
  token0,
399
482
  token1,
400
- swapFeeUnits: swapFeeUnits.toString(),
483
+ fee: fee.toString(),
401
484
  }));
402
- this.logger.trace(`Starting to listen to new pool: ${key}`);
403
- pool = new kyberswap_elastic_pool_1.KyberswapElasticEventPool(this.dexKey, this.network, this.dexHelper, this.logger, this.config, swapFeeUnits, token0, token1);
485
+ this.logger.trace(`starting to listen to new pool: ${key}`);
486
+ pool = new sushiswap_v3_pool_1.SushiswapV3EventPool(this.dexHelper, this.dexKey, this.stateMultiContract, this.erc20Interface, this.config.factory, fee, token0, token1, this.logger, this.cacheStateKey, this.config.initHash);
404
487
  try {
405
488
  await pool.initialize(blockNumber, {
406
489
  initCallback: (state) => {
407
- // Really hacky, we need to push poolAddress so that we subscribeToLogs in StatefulEventSubscriber
490
+ //really hacky, we need to push poolAddress so that we subscribeToLogs in StatefulEventSubscriber
408
491
  pool.addressesSubscribed[0] = state.pool;
409
492
  pool.poolAddress = state.pool;
410
493
  },
411
494
  });
412
495
  }
413
496
  catch (e) {
414
- if (e instanceof Error &&
415
- (e.message.endsWith(errors_1.ERR_POOL_DOES_NOT_EXIST) ||
416
- e.message.search(errors_1.ERR_DECODE) != -1)) {
417
- // No need to await here, we push the pool into the notExistingPool set without blocking
497
+ if (e instanceof Error && e.message.endsWith('Pool does not exist')) {
498
+ // no need to await we want the set to have the pool key but it's not blocking
418
499
  this.dexHelper.cache.zadd(this.notExistingPoolSetKey, [Date.now(), key], 'NX');
419
- // Pool does not exist for this swapFeeUnits, so we can set it to null,
500
+ // Pool does not exist for this feeCode, so we can set it to null
420
501
  // to prevent more requests for this pool
421
502
  pool = null;
422
- this.logger.trace(`${this.dexHelper}: Pool: srcAddress=${srcAddress}, destAddress=${destAddress}, swapFeeUnits=${swapFeeUnits} not found`, e);
503
+ this.logger.trace(`${this.dexHelper}: Pool: srcAddress=${srcAddress}, destAddress=${destAddress}, fee=${fee} not found`, e);
423
504
  }
424
505
  else {
425
506
  // Unexpected Error. Break execution. Do not save the pool in this.eventPools
426
- this.logger.error(`${this.dexKey}: Can not generate pool state for srcAddress=${srcAddress}, destAddress=${destAddress}, swapFeeUnits=${swapFeeUnits} pool`, e);
507
+ this.logger.error(`${this.dexKey}: Can not generate pool state for srcAddress=${srcAddress}, destAddress=${destAddress}, fee=${fee} pool`, e);
427
508
  throw new Error('Cannot generate pool state');
428
509
  }
429
510
  }
430
511
  if (pool !== null) {
431
512
  const allEventPools = Object.values(this.eventPools);
432
- this.logger.info(`Starting to listen to new non-null pool: ${key}. Already following ${allEventPools
513
+ this.logger.info(`starting to listen to new non-null pool: ${key}. Already following ${allEventPools
433
514
  // Not that I like this reduce, but since it is done only on initialization, expect this to be ok
434
515
  .reduce((acc, curr) => (curr !== null ? ++acc : acc), 0)} non-null pools or ${allEventPools.length} total pools`);
435
516
  }
436
- this.eventPools[this._getPoolIdentifier(srcAddress, destAddress, swapFeeUnits)] = pool;
517
+ this.eventPools[this.getPoolIdentifier(srcAddress, destAddress, fee)] =
518
+ pool;
437
519
  }
438
520
  return pool;
439
521
  }
440
- async _getPricingFromRpc(from, to, amounts, side, pools) {
441
- if (pools.length === 0) {
442
- return null;
443
- }
444
- this.logger.warn(`fallback to rpc for ${pools.length} pool(s)`);
445
- const requests = pools.map(pool => ({
446
- owner: pool.poolAddress,
447
- asset: side == constants_1.SwapSide.SELL ? from.address : to.address,
448
- assetType: types_1.AssetType.ERC20,
449
- ids: [
450
- {
451
- id: types_1.DEFAULT_ID_ERC20,
452
- spenders: [],
453
- },
454
- ],
455
- }), []);
456
- const balances = await (0, balancer_fetcher_1.getBalances)(this.dexHelper.multiWrapper, requests);
457
- pools = pools.filter((pool, index) => {
458
- const balance = balances[index].amounts[types_1.DEFAULT_ID_ERC20_AS_STRING];
459
- if (balance >= amounts[amounts.length - 1]) {
460
- return true;
461
- }
462
- this.logger.warn(`[${this.network}][${pool.parentName}] have no balance ${pool.poolAddress} ${from.address} ${to.address}. (Balance: ${balance})`);
463
- return false;
464
- });
465
- pools.forEach(pool => {
466
- this.logger.warn(`[${this.network}][${pool.parentName}] fallback to rpc for ${pool.name}`);
467
- });
468
- const unitVolume = (0, utils_1.getBigIntPow)((side === constants_1.SwapSide.SELL ? from : to).decimals);
469
- const chunks = amounts.length - 1;
470
- const _width = Math.floor(chunks / this.config.chunksCount);
471
- const _amounts = [unitVolume].concat(Array.from(Array(this.config.chunksCount).keys()).map(i => amounts[(i + 1) * _width]));
472
- const calldata = pools.map(pool => _amounts.map(_amount => ({
473
- target: this.config.quoter,
474
- gasLimit: constants_2.KS_ELASTIC_QUOTE_GASLIMIT,
475
- callData: side === constants_1.SwapSide.SELL
476
- ? this.quoterIface.encodeFunctionData(types_2.KyberElasticFunctions.quoteExactInputSingle, [
477
- {
478
- tokenIn: from.address,
479
- tokenOut: to.address,
480
- amountIn: _amount,
481
- feeUnits: pool.swapFeeUnits,
482
- limitSqrtP: 0n,
483
- },
484
- ])
485
- : this.quoterIface.encodeFunctionData(types_2.KyberElasticFunctions.quoteExactOutputSingle, [
486
- {
487
- tokenIn: from.address,
488
- tokenOut: to.address,
489
- amount: _amount,
490
- feeUnits: pool.swapFeeUnits,
491
- limitSqrtP: 0n,
492
- },
493
- ]),
494
- })));
495
- const data = await this.multicall.methods.multicall(calldata.flat()).call();
496
- const decode = (j) => {
497
- if (!data.returnData[j].success) {
498
- return 0n;
499
- }
500
- const decoded = abi_1.defaultAbiCoder.decode(['uint256'], data.returnData[j].returnData);
501
- return BigInt(decoded[0][1].toString());
502
- };
503
- let i = 0;
504
- const result = pools.map(pool => {
505
- const _rates = _amounts.map(() => decode(i++));
506
- const unit = _rates[0];
507
- const prices = (0, utils_1.interpolate)(_amounts.slice(1), _rates.slice(1), amounts, side);
508
- return {
509
- prices,
510
- unit,
511
- data: {
512
- path: [
513
- {
514
- tokenIn: from.address,
515
- tokenOut: to.address,
516
- swapFeeUnits: pool.swapFeeUnits.toString(),
517
- },
518
- ],
519
- },
520
- poolIdentifier: this._getPoolIdentifier(pool.token0, pool.token1, pool.swapFeeUnits),
521
- exchange: this.dexKey,
522
- gasCost: prices.map(p => (p === 0n ? 0 : constants_2.KS_ELASTIC_QUOTE_GASLIMIT)),
523
- poolAddresses: [pool.poolAddress],
524
- };
525
- });
526
- return result;
522
+ _getLoweredAddresses(srcToken, destToken) {
523
+ return [srcToken.address.toLowerCase(), destToken.address.toLowerCase()];
524
+ }
525
+ _sortTokens(srcAddress, destAddress) {
526
+ return [srcAddress, destAddress].sort((a, b) => (a < b ? -1 : 1));
527
527
  }
528
- // Normalise KyberswapElasticConfig
529
528
  _toLowerForAllConfigAddresses() {
529
+ // If new config property will be added, the TS will throw compile error
530
530
  const newConfig = {
531
531
  router: this.config.router.toLowerCase(),
532
532
  quoter: this.config.quoter.toLowerCase(),
533
533
  factory: this.config.factory.toLowerCase(),
534
- positionManager: this.config.positionManager.toLowerCase(),
535
- ticksFeesReader: this.config.ticksFeesReader.toLowerCase(),
536
- tokenPositionDescriptor: this.config.tokenPositionDescriptor.toLowerCase(),
537
534
  supportedFees: this.config.supportedFees,
535
+ stateMulticall: this.config.stateMulticall.toLowerCase(),
538
536
  chunksCount: this.config.chunksCount,
539
- poolInitHash: this.config.poolInitHash,
537
+ uniswapMulticall: this.config.uniswapMulticall,
538
+ deployer: this.config.deployer?.toLowerCase(),
539
+ initHash: this.config.initHash,
540
540
  subgraphURL: this.config.subgraphURL,
541
541
  };
542
542
  return newConfig;
543
543
  }
544
- // Returns addresses in lower case
545
- _getLoweredAddresses(srcToken, destToken) {
546
- return [srcToken.address.toLowerCase(), destToken.address.toLowerCase()];
547
- }
548
- // Returns encoded path of a trade to call to the router contract
549
- _encodePath(path, side) {
550
- if (path.length === 0) {
551
- this.logger.error(`${this.dexKey}: Received invalid path=${path} for side=${side} to encode`);
552
- return '0x';
544
+ async _querySubgraph(query, variables, timeout = 30000) {
545
+ try {
546
+ const res = await this.dexHelper.httpRequest.post(this.config.subgraphURL, { query, variables }, undefined, { timeout: timeout });
547
+ return res.data;
548
+ }
549
+ catch (e) {
550
+ this.logger.error(`${this.dexKey}: can not query subgraph: `, e);
551
+ return {};
553
552
  }
554
- const { _path, types } = path.reduce(({ _path, types }, curr, index) => {
555
- if (index === 0) {
556
- return {
557
- types: ['address', 'uint24', 'address'],
558
- _path: [curr.tokenIn, curr.swapFeeUnits, curr.tokenOut],
559
- };
560
- }
561
- else {
562
- return {
563
- types: [...types, 'uint24', 'address'],
564
- _path: [..._path, curr.swapFeeUnits, curr.tokenOut],
565
- };
566
- }
567
- }, { _path: [], types: [] });
568
- return side === constants_1.SwapSide.BUY
569
- ? (0, solidity_1.pack)(types.reverse(), _path.reverse())
570
- : (0, solidity_1.pack)(types, _path);
571
553
  }
572
- _getOutputs(state, amounts, isToken0, side, destTokenBalance) {
554
+ _getOutputs(state, amounts, zeroForOne, side, destTokenBalance) {
573
555
  try {
574
- const outputsResult = kyberswap_elastic_math_1.ksElasticMath.queryOutputs(state, amounts, isToken0, side);
556
+ const outputsResult = uniswap_v3_math_1.uniswapV3Math.queryOutputs(state, amounts, zeroForOne, side);
575
557
  if (side === constants_1.SwapSide.SELL) {
576
558
  if (outputsResult.outputs[0] > destTokenBalance) {
577
559
  return null;
@@ -604,7 +586,13 @@ class KyberswapElastic extends simple_exchange_1.SimpleExchange {
604
586
  return null;
605
587
  }
606
588
  }
589
+ releaseResources() {
590
+ if (this.intervalTask !== undefined) {
591
+ clearInterval(this.intervalTask);
592
+ this.intervalTask = undefined;
593
+ }
594
+ }
607
595
  }
608
- exports.KyberswapElastic = KyberswapElastic;
609
- KyberswapElastic.dexKeysWithNetwork = (0, utils_1.getDexKeysWithNetwork)(config_1.KyberswapElasticConfig);
610
- //# sourceMappingURL=kyberswap-elastic.js.map
596
+ exports.SushiswapV3 = SushiswapV3;
597
+ SushiswapV3.dexKeysWithNetwork = (0, utils_1.getDexKeysWithNetwork)(config_1.SushiswapV3Config);
598
+ //# sourceMappingURL=sushiswap-v3-original.js.map