@paraswap/dex-lib 4.1.9 → 4.1.10-ekubo

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 (372) hide show
  1. package/build/abi/AaveV1_lending_pool.json +27 -0
  2. package/build/abi/Aave_GSM.json +751 -0
  3. package/build/abi/Balancer.json +257 -0
  4. package/build/abi/BalancerV2.json +1179 -0
  5. package/build/abi/RamsesV2Pool.abi.json +1554 -0
  6. package/build/abi/RamsesV2Quoter.abi.json +274 -0
  7. package/build/abi/USDM.json +807 -0
  8. package/build/abi/UniswapV2Router.json +397 -0
  9. package/build/abi/angle-transmuter/ChainlinkAccessControlledOffchainAggregator.json +1246 -0
  10. package/build/abi/angle-transmuter/ChainlinkEACAggregatorProxy.json +509 -0
  11. package/build/abi/curve-v1/CurveBUSDv2.abi.json +1356 -0
  12. package/build/abi/curve-v1/CurveTokenV1.json +305 -0
  13. package/build/abi/curve-v1/CurveTokenV2.json +318 -0
  14. package/build/abi/curve-v1/CurveV1StableNg.json +1452 -0
  15. package/build/abi/curve-v1/CurveV2Swap.json +700 -0
  16. package/build/abi/curve-v1/FactoryCryptoRegistry.json +316 -0
  17. package/build/abi/curve-v1/FactoryRegistry.json +508 -0
  18. package/build/abi/curve-v1/StableSwapAave.json +1152 -0
  19. package/build/abi/curve-v1/StableSwapBUSD.json +814 -0
  20. package/build/abi/curve-v1/StableSwapCompound.json +814 -0
  21. package/build/abi/curve-v1/StableSwapIDLE.json +1253 -0
  22. package/build/abi/curve-v1/StableSwapPax.json +865 -0
  23. package/build/abi/curve-v1/StableSwapSnow.json +900 -0
  24. package/build/abi/curve-v1/StableSwapUSDN.json +1004 -0
  25. package/build/abi/curve-v1/StableSwapUSDT.json +814 -0
  26. package/build/abi/curve-v1/StableSwapY.json +814 -0
  27. package/build/abi/ekubo/core.json +1266 -0
  28. package/build/abi/ekubo/data-fetcher.json +161 -0
  29. package/build/abi/ekubo/router.json +803 -0
  30. package/build/abi/inception/inception-ineth-pool.json +1062 -0
  31. package/build/abi/inception/inception-ineth.json +609 -0
  32. package/build/abi/inception/inception-ratio-feed.json +329 -0
  33. package/build/abi/inception/inception-vault.json +991 -0
  34. package/build/abi/kyberdmm/kyber-storage.abi.json +824 -0
  35. package/build/abi/kyberdmm.abi.json +1148 -0
  36. package/build/abi/maverick-v2/MaverickV2Quoter.json +278 -0
  37. package/build/abi/nerve/nerve-metapool.json +790 -0
  38. package/build/abi/platypus/asset.json +490 -0
  39. package/build/abi/platypus/avax-pool.json +820 -0
  40. package/build/abi/platypus/oracle.json +119 -0
  41. package/build/abi/platypus/pool.json +677 -0
  42. package/build/abi/smardex/all/smardex-router.json +648 -0
  43. package/build/abi/smardex/layer-1/smardex-factory.json +242 -0
  44. package/build/abi/smardex/layer-1/smardex-pool.json +506 -0
  45. package/build/abi/smardex/layer-2/smardex-factory.json +185 -0
  46. package/build/abi/smardex/layer-2/smardex-pool.json +578 -0
  47. package/build/abi/swaap-v1/pool.json +1346 -0
  48. package/build/abi/uniswap-v3/UniswapV3Quoter.abi.json +193 -0
  49. package/build/abi/velodrome-slipstream/VelodromeSlipstreamQuoterV2.abi.json +267 -0
  50. package/build/dex/aave-v1/aave-v1.d.ts +34 -0
  51. package/build/dex/aave-v1/aave-v1.js +180 -0
  52. package/build/dex/aave-v1/aave-v1.js.map +1 -0
  53. package/build/dex/aave-v1/config.d.ts +11 -0
  54. package/build/dex/aave-v1/config.js +20 -0
  55. package/build/dex/aave-v1/config.js.map +1 -0
  56. package/build/dex/aave-v1/tokens-mainnet.json +134 -0
  57. package/build/dex/aave-v1/tokens.d.ts +3 -0
  58. package/build/dex/aave-v1/tokens.js +50 -0
  59. package/build/dex/aave-v1/tokens.js.map +1 -0
  60. package/build/dex/aave-v1/types.d.ts +12 -0
  61. package/build/dex/aave-v1/types.js +3 -0
  62. package/build/dex/aave-v1/types.js.map +1 -0
  63. package/build/dex/aave-v3-stata/config.js +8 -8
  64. package/build/dex/aave-v3-stata/config.js.map +1 -1
  65. package/build/dex/aave-v3-stata-v2/aave-v3-stata-v2.js +2 -2
  66. package/build/dex/aave-v3-stata-v2/aave-v3-stata-v2.js.map +1 -1
  67. package/build/dex/aave-v3-stata-v2/config.js +31 -24
  68. package/build/dex/aave-v3-stata-v2/config.js.map +1 -1
  69. package/build/dex/aave-v3-stata-v2/types.d.ts +3 -2
  70. package/build/dex/aave-v3-stata-v2/types.js.map +1 -1
  71. package/build/dex/aave-v3-stata-v2/utils.d.ts +2 -2
  72. package/build/dex/aave-v3-stata-v2/utils.js +7 -6
  73. package/build/dex/aave-v3-stata-v2/utils.js.map +1 -1
  74. package/build/dex/balancer-v1/balancer-pools.json +33333 -0
  75. package/build/dex/bebop/websocket-fetcher.d.ts +35 -0
  76. package/build/dex/bebop/websocket-fetcher.js +87 -0
  77. package/build/dex/bebop/websocket-fetcher.js.map +1 -0
  78. package/build/dex/ekubo/config.d.ts +3 -0
  79. package/build/dex/ekubo/config.js +16 -0
  80. package/build/dex/ekubo/config.js.map +1 -0
  81. package/build/dex/ekubo/ekubo.d.ts +49 -0
  82. package/build/dex/ekubo/ekubo.js +419 -0
  83. package/build/dex/ekubo/ekubo.js.map +1 -0
  84. package/build/dex/ekubo/pools/base-pool.d.ts +47 -0
  85. package/build/dex/ekubo/pools/base-pool.js +184 -0
  86. package/build/dex/ekubo/pools/base-pool.js.map +1 -0
  87. package/build/dex/ekubo/pools/math/constants.d.ts +3 -0
  88. package/build/dex/ekubo/pools/math/constants.js +7 -0
  89. package/build/dex/ekubo/pools/math/constants.js.map +1 -0
  90. package/build/dex/ekubo/pools/math/delta.d.ts +2 -0
  91. package/build/dex/ekubo/pools/math/delta.js +51 -0
  92. package/build/dex/ekubo/pools/math/delta.js.map +1 -0
  93. package/build/dex/ekubo/pools/math/price.d.ts +7 -0
  94. package/build/dex/ekubo/pools/math/price.js +116 -0
  95. package/build/dex/ekubo/pools/math/price.js.map +1 -0
  96. package/build/dex/ekubo/pools/math/swap.d.ts +18 -0
  97. package/build/dex/ekubo/pools/math/swap.js +128 -0
  98. package/build/dex/ekubo/pools/math/swap.js.map +1 -0
  99. package/build/dex/ekubo/pools/math/tick.d.ts +7 -0
  100. package/build/dex/ekubo/pools/math/tick.js +112 -0
  101. package/build/dex/ekubo/pools/math/tick.js.map +1 -0
  102. package/build/dex/ekubo/pools/oracle-pool.d.ts +10 -0
  103. package/build/dex/ekubo/pools/oracle-pool.js +19 -0
  104. package/build/dex/ekubo/pools/oracle-pool.js.map +1 -0
  105. package/build/dex/ekubo/types.d.ts +88 -0
  106. package/build/dex/ekubo/types.js +238 -0
  107. package/build/dex/ekubo/types.js.map +1 -0
  108. package/build/dex/ekubo/utils.d.ts +6 -0
  109. package/build/dex/ekubo/utils.js +30 -0
  110. package/build/dex/ekubo/utils.js.map +1 -0
  111. package/build/dex/idle-dao/idle-dao-pool.d.ts +56 -0
  112. package/build/dex/idle-dao/idle-dao-pool.js +176 -0
  113. package/build/dex/idle-dao/idle-dao-pool.js.map +1 -0
  114. package/build/dex/idle-dao/idle-dao-pooling-pool.d.ts +16 -0
  115. package/build/dex/idle-dao/idle-dao-pooling-pool.js +57 -0
  116. package/build/dex/idle-dao/idle-dao-pooling-pool.js.map +1 -0
  117. package/build/dex/idle-dao/scripts.d.ts +9 -0
  118. package/build/dex/idle-dao/scripts.js +552 -0
  119. package/build/dex/idle-dao/scripts.js.map +1 -0
  120. package/build/dex/inception/config.d.ts +4 -0
  121. package/build/dex/inception/config.js +109 -0
  122. package/build/dex/inception/config.js.map +1 -0
  123. package/build/dex/inception/inception-event-pool.d.ts +16 -0
  124. package/build/dex/inception/inception-event-pool.js +51 -0
  125. package/build/dex/inception/inception-event-pool.js.map +1 -0
  126. package/build/dex/inception/inception-native.d.ts +43 -0
  127. package/build/dex/inception/inception-native.js +131 -0
  128. package/build/dex/inception/inception-native.js.map +1 -0
  129. package/build/dex/inception/inception-pool.d.ts +18 -0
  130. package/build/dex/inception/inception-pool.js +32 -0
  131. package/build/dex/inception/inception-pool.js.map +1 -0
  132. package/build/dex/inception/inception-price-feed.d.ts +19 -0
  133. package/build/dex/inception/inception-price-feed.js +51 -0
  134. package/build/dex/inception/inception-price-feed.js.map +1 -0
  135. package/build/dex/inception/inception.d.ts +43 -0
  136. package/build/dex/inception/inception.js +204 -0
  137. package/build/dex/inception/inception.js.map +1 -0
  138. package/build/dex/inception/tokens.d.ts +9 -0
  139. package/build/dex/inception/tokens.js +28 -0
  140. package/build/dex/inception/tokens.js.map +1 -0
  141. package/build/dex/inception/types.d.ts +22 -0
  142. package/build/dex/inception/types.js +3 -0
  143. package/build/dex/inception/types.js.map +1 -0
  144. package/build/dex/inception/utils.d.ts +6 -0
  145. package/build/dex/inception/utils.js +37 -0
  146. package/build/dex/inception/utils.js.map +1 -0
  147. package/build/dex/index.js +2 -0
  148. package/build/dex/index.js.map +1 -1
  149. package/build/dex/platypus/asset.d.ts +14 -0
  150. package/build/dex/platypus/asset.js +97 -0
  151. package/build/dex/platypus/asset.js.map +1 -0
  152. package/build/dex/platypus/config.d.ts +11 -0
  153. package/build/dex/platypus/config.js +69 -0
  154. package/build/dex/platypus/config.js.map +1 -0
  155. package/build/dex/platypus/platypus.d.ts +63 -0
  156. package/build/dex/platypus/platypus.js +473 -0
  157. package/build/dex/platypus/platypus.js.map +1 -0
  158. package/build/dex/platypus/pool-avax.d.ts +8 -0
  159. package/build/dex/platypus/pool-avax.js +54 -0
  160. package/build/dex/platypus/pool-avax.js.map +1 -0
  161. package/build/dex/platypus/pool-base.d.ts +19 -0
  162. package/build/dex/platypus/pool-base.js +86 -0
  163. package/build/dex/platypus/pool-base.js.map +1 -0
  164. package/build/dex/platypus/pool-pure.d.ts +8 -0
  165. package/build/dex/platypus/pool-pure.js +37 -0
  166. package/build/dex/platypus/pool-pure.js.map +1 -0
  167. package/build/dex/platypus/pool-subscriber.d.ts +14 -0
  168. package/build/dex/platypus/pool-subscriber.js +167 -0
  169. package/build/dex/platypus/pool-subscriber.js.map +1 -0
  170. package/build/dex/platypus/pool.d.ts +8 -0
  171. package/build/dex/platypus/pool.js +58 -0
  172. package/build/dex/platypus/pool.js.map +1 -0
  173. package/build/dex/platypus/types.d.ts +92 -0
  174. package/build/dex/platypus/types.js +10 -0
  175. package/build/dex/platypus/types.js.map +1 -0
  176. package/build/dex/quickswap/spiritswap-v3.d.ts +6 -0
  177. package/build/dex/quickswap/spiritswap-v3.js +19 -0
  178. package/build/dex/quickswap/spiritswap-v3.js.map +1 -0
  179. package/build/dex/smardex/config.d.ts +4 -0
  180. package/build/dex/smardex/config.js +64 -0
  181. package/build/dex/smardex/config.js.map +1 -0
  182. package/build/dex/smardex/constants.d.ts +18 -0
  183. package/build/dex/smardex/constants.js +33 -0
  184. package/build/dex/smardex/constants.js.map +1 -0
  185. package/build/dex/smardex/sdk/constants.d.ts +6 -0
  186. package/build/dex/smardex/sdk/constants.js +13 -0
  187. package/build/dex/smardex/sdk/constants.js.map +1 -0
  188. package/build/dex/smardex/sdk/core.d.ts +113 -0
  189. package/build/dex/smardex/sdk/core.js +499 -0
  190. package/build/dex/smardex/sdk/core.js.map +1 -0
  191. package/build/dex/smardex/sdk/errors.d.ts +15 -0
  192. package/build/dex/smardex/sdk/errors.js +22 -0
  193. package/build/dex/smardex/sdk/errors.js.map +1 -0
  194. package/build/dex/smardex/sdk/types.d.ts +62 -0
  195. package/build/dex/smardex/sdk/types.js +3 -0
  196. package/build/dex/smardex/sdk/types.js.map +1 -0
  197. package/build/dex/smardex/sdk/utils.d.ts +44 -0
  198. package/build/dex/smardex/sdk/utils.js +133 -0
  199. package/build/dex/smardex/sdk/utils.js.map +1 -0
  200. package/build/dex/smardex/smardex-event-pool.d.ts +28 -0
  201. package/build/dex/smardex/smardex-event-pool.js +119 -0
  202. package/build/dex/smardex/smardex-event-pool.js.map +1 -0
  203. package/build/dex/smardex/smardex.d.ts +65 -0
  204. package/build/dex/smardex/smardex.js +519 -0
  205. package/build/dex/smardex/smardex.js.map +1 -0
  206. package/build/dex/smardex/types.d.ts +55 -0
  207. package/build/dex/smardex/types.js +3 -0
  208. package/build/dex/smardex/types.js.map +1 -0
  209. package/build/dex/solidly/forks-override/cone.d.ts +22 -0
  210. package/build/dex/solidly/forks-override/cone.js +53 -0
  211. package/build/dex/solidly/forks-override/cone.js.map +1 -0
  212. package/build/dex/solidly/forks-override/solisnek.d.ts +8 -0
  213. package/build/dex/solidly/forks-override/solisnek.js +15 -0
  214. package/build/dex/solidly/forks-override/solisnek.js.map +1 -0
  215. package/build/dex/swaap-v1/config.d.ts +17 -0
  216. package/build/dex/swaap-v1/config.js +56 -0
  217. package/build/dex/swaap-v1/config.js.map +1 -0
  218. package/build/dex/swaap-v1/constants.d.ts +6 -0
  219. package/build/dex/swaap-v1/constants.js +17 -0
  220. package/build/dex/swaap-v1/constants.js.map +1 -0
  221. package/build/dex/swaap-v1/libraries/ChainlinkUtils.d.ts +25 -0
  222. package/build/dex/swaap-v1/libraries/ChainlinkUtils.js +62 -0
  223. package/build/dex/swaap-v1/libraries/ChainlinkUtils.js.map +1 -0
  224. package/build/dex/swaap-v1/libraries/Const.d.ts +18 -0
  225. package/build/dex/swaap-v1/libraries/Const.js +26 -0
  226. package/build/dex/swaap-v1/libraries/Const.js.map +1 -0
  227. package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.d.ts +77 -0
  228. package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.js +316 -0
  229. package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.js.map +1 -0
  230. package/build/dex/swaap-v1/libraries/LogExpMath.d.ts +75 -0
  231. package/build/dex/swaap-v1/libraries/LogExpMath.js +418 -0
  232. package/build/dex/swaap-v1/libraries/LogExpMath.js.map +1 -0
  233. package/build/dex/swaap-v1/libraries/MathMMM.d.ts +185 -0
  234. package/build/dex/swaap-v1/libraries/MathMMM.js +453 -0
  235. package/build/dex/swaap-v1/libraries/MathMMM.js.map +1 -0
  236. package/build/dex/swaap-v1/libraries/Num.d.ts +31 -0
  237. package/build/dex/swaap-v1/libraries/Num.js +167 -0
  238. package/build/dex/swaap-v1/libraries/Num.js.map +1 -0
  239. package/build/dex/swaap-v1/libraries/PoolQuotations.d.ts +23 -0
  240. package/build/dex/swaap-v1/libraries/PoolQuotations.js +131 -0
  241. package/build/dex/swaap-v1/libraries/PoolQuotations.js.map +1 -0
  242. package/build/dex/swaap-v1/libraries/Struct.d.ts +56 -0
  243. package/build/dex/swaap-v1/libraries/Struct.js +3 -0
  244. package/build/dex/swaap-v1/libraries/Struct.js.map +1 -0
  245. package/build/dex/swaap-v1/swaap-v1-pool.d.ts +45 -0
  246. package/build/dex/swaap-v1/swaap-v1-pool.js +656 -0
  247. package/build/dex/swaap-v1/swaap-v1-pool.js.map +1 -0
  248. package/build/dex/swaap-v1/swaap-v1.d.ts +62 -0
  249. package/build/dex/swaap-v1/swaap-v1.js +379 -0
  250. package/build/dex/swaap-v1/swaap-v1.js.map +1 -0
  251. package/build/dex/swaap-v1/types.d.ts +106 -0
  252. package/build/dex/swaap-v1/types.js +9 -0
  253. package/build/dex/swaap-v1/types.js.map +1 -0
  254. package/build/dex/zerox/index.d.ts +1 -1
  255. package/build/dex/zerox/index.js.map +1 -1
  256. package/build/dex-helper/dummy-dex-helper.js +3 -0
  257. package/build/dex-helper/dummy-dex-helper.js.map +1 -1
  258. package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-balancerv1-curvev1-eth-usdc-gusd.json +16 -0
  259. package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-balancerv1-sushiv3-wbtc-eth-sushi.json +16 -0
  260. package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-curvev1-eth-usdc-gusd.json +16 -0
  261. package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-curvev1-gusd-usdc-eth.json +16 -0
  262. package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-dai-usdc-eth.json +16 -0
  263. package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-eth-usdc-dai.json +16 -0
  264. package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-usdc-eth-wbtc.json +16 -0
  265. package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-usdt-usdc-dai.json +16 -0
  266. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-balancerv1-eth-usdc.json +9 -0
  267. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-balancerv1-usdc-eth.json +9 -0
  268. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-balancerv1-usdc-wbtc.json +9 -0
  269. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-curvev1-eth-steth.json +9 -0
  270. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-curvev1-steth-eth.json +9 -0
  271. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-curvev1-usdc-usdt.json +9 -0
  272. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-univ3-eth-usdc.json +9 -0
  273. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-univ3-usdc-eth.json +9 -0
  274. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-univ3-usdc-usdt.json +9 -0
  275. package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-balancerv1-sushiv3-wbtc-eth-sushi.json +12 -0
  276. package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-curvev1-eth-usdc-gusd.json +7 -0
  277. package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-curvev1-gusd-usdc-eth.json +7 -0
  278. package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-dai-usdc-eth.json +7 -0
  279. package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-eth-usdc-dai.json +7 -0
  280. package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-usdc-eth-wbtc.json +12 -0
  281. package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-simpleSwap-univ3-eth-usdc.json +7 -0
  282. package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-simpleSwap-univ3-usdc-eth.json +7 -0
  283. package/build/executor/fixtures/executor01/routes/price-route-multiswap-balancerv1-curvev1-eth-usdc-gusd.json +78 -0
  284. package/build/executor/fixtures/executor01/routes/price-route-multiswap-balancerv1-sushiv3-wbtc-eth-sushi.json +81 -0
  285. package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-curvev1-eth-usdc-gusd.json +78 -0
  286. package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-curvev1-gusd-usdc-eth.json +78 -0
  287. package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-dai-usdc-eth.json +81 -0
  288. package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-eth-usdc-dai.json +81 -0
  289. package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-usdc-eth-wbtc.json +81 -0
  290. package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-usdt-usdc-dai.json +81 -0
  291. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-balancerv1-eth-usdc.json +64 -0
  292. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-balancerv1-usdc-eth.json +85 -0
  293. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-balancerv1-usdc-wbtc.json +64 -0
  294. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-curvev1-eth-steth.json +52 -0
  295. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-curvev1-steth-eth.json +52 -0
  296. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-curvev1-usdc-usdt.json +52 -0
  297. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-univ3-eth-usdc.json +55 -0
  298. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-univ3-usdc-eth.json +55 -0
  299. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-univ3-usdc-usdt.json +55 -0
  300. package/build/executor/fixtures/executor02/exchange-params/price-route-multiSwap-balancerv1-sushiv3-univ3-bal-eth-sushi.json +23 -0
  301. package/build/executor/fixtures/executor02/exchange-params/price-route-multiSwap-maverickv1-sushiv3-univ3-eth-usdc-mav.json +37 -0
  302. package/build/executor/fixtures/executor02/exchange-params/price-route-multiSwap-univ3-sushiv3-sushi-eth-wbtc.json +23 -0
  303. package/build/executor/fixtures/executor02/exchange-params/price-route-multiSwap-univ3-sushiv3-wbtc-eth-sushi.json +23 -0
  304. package/build/executor/fixtures/executor02/exchange-params/price-route-multiswap-curvev1-univ3-dai-usdc-eth.json +51 -0
  305. package/build/executor/fixtures/executor02/exchange-params/price-route-multiswap-univ3-usdt-dai-eth.json +58 -0
  306. package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-balancerv1-eth-usdc.json +23 -0
  307. package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-balancerv1-usdc-eth.json +23 -0
  308. package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-univ3-eth-sushi.json +9 -0
  309. package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-univ3-sushi-eth.json +16 -0
  310. package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-univ3-curvev1-usdt-dai.json +23 -0
  311. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-balancerv1-sushiv3-univ3-bal-eth-sushi.json +12 -0
  312. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-maverickv1-sushiv3-univ3-eth-usdc-mav.json +7 -0
  313. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-univ3-sushiv3-sushi-eth-wbtc.json +12 -0
  314. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-univ3-sushiv3-wbtc-eth-sushi.json +12 -0
  315. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiswap-curvev1-univ3-dai-usdc-eth.json +7 -0
  316. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiswap-univ3-usdt-dai-eth.json +7 -0
  317. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-balancerv1-eth-usdc.json +7 -0
  318. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-balancerv1-usdc-eth.json +7 -0
  319. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-univ3-eth-sushi.json +7 -0
  320. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-univ3-sushi-eth.json +7 -0
  321. package/build/executor/fixtures/executor02/routes/price-route-multiSwap-balancerv1-sushiv3-univ3-bal-eth-sushi.json +130 -0
  322. package/build/executor/fixtures/executor02/routes/price-route-multiSwap-maverickv1-sushiv3-univ3-eth-usdc-mav.json +136 -0
  323. package/build/executor/fixtures/executor02/routes/price-route-multiSwap-univ3-sushiv3-sushi-eth-wbtc.json +100 -0
  324. package/build/executor/fixtures/executor02/routes/price-route-multiSwap-univ3-sushiv3-wbtc-eth-sushi.json +100 -0
  325. package/build/executor/fixtures/executor02/routes/price-route-multiswap-curvev1-univ3-dai-usdc-eth.json +166 -0
  326. package/build/executor/fixtures/executor02/routes/price-route-multiswap-univ3-usdt-dai-eth.json +190 -0
  327. package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-balancerv1-eth-usdc.json +114 -0
  328. package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-balancerv1-usdc-eth.json +114 -0
  329. package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-univ3-eth-sushi.json +55 -0
  330. package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-univ3-sushi-eth.json +73 -0
  331. package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-univ3-curvev1-usdt-dai.json +82 -0
  332. package/package.json +2 -2
  333. package/src/abi/ekubo/core.json +1266 -0
  334. package/src/abi/ekubo/data-fetcher.json +161 -0
  335. package/src/abi/ekubo/router.json +803 -0
  336. package/src/dex/aave-v3-stata/config.ts +8 -8
  337. package/src/dex/aave-v3-stata-v2/aave-v3-stata-v2-e2e.test.ts +5 -5
  338. package/src/dex/aave-v3-stata-v2/aave-v3-stata-v2.ts +2 -2
  339. package/src/dex/aave-v3-stata-v2/config.ts +31 -24
  340. package/src/dex/aave-v3-stata-v2/types.ts +3 -2
  341. package/src/dex/aave-v3-stata-v2/utils.ts +18 -10
  342. package/src/dex/ekubo/config.ts +15 -0
  343. package/src/dex/ekubo/ekubo-e2e.test.ts +124 -0
  344. package/src/dex/ekubo/ekubo-events.test.ts +209 -0
  345. package/src/dex/ekubo/ekubo-integration.test.ts +243 -0
  346. package/src/dex/ekubo/ekubo.ts +657 -0
  347. package/src/dex/ekubo/pools/base-pool.ts +267 -0
  348. package/src/dex/ekubo/pools/math/constants.ts +5 -0
  349. package/src/dex/ekubo/pools/math/delta.test.ts +131 -0
  350. package/src/dex/ekubo/pools/math/delta.ts +68 -0
  351. package/src/dex/ekubo/pools/math/price.test.ts +54 -0
  352. package/src/dex/ekubo/pools/math/price.ts +129 -0
  353. package/src/dex/ekubo/pools/math/swap.test.ts +215 -0
  354. package/src/dex/ekubo/pools/math/swap.ts +161 -0
  355. package/src/dex/ekubo/pools/math/tick.test.ts +72 -0
  356. package/src/dex/ekubo/pools/math/tick.ts +120 -0
  357. package/src/dex/ekubo/pools/oracle-pool.ts +46 -0
  358. package/src/dex/ekubo/types.test.ts +552 -0
  359. package/src/dex/ekubo/types.ts +408 -0
  360. package/src/dex/ekubo/utils.ts +34 -0
  361. package/src/dex/index.ts +2 -0
  362. package/src/dex-helper/dummy-dex-helper.ts +10 -0
  363. package/tests/constants-e2e.ts +15 -0
  364. package/tests/utils-e2e.ts +0 -1
  365. package/.idea/codeStyles/Project.xml +0 -59
  366. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  367. package/.idea/inspectionProfiles/Project_Default.xml +0 -6
  368. package/.idea/modules.xml +0 -8
  369. package/.idea/paraswap-dex-lib.iml +0 -12
  370. package/.idea/prettier.xml +0 -7
  371. package/.idea/vcs.xml +0 -6
  372. package/scripts/get-uniswap-v3-dexes.ts +0 -64
@@ -0,0 +1,657 @@
1
+ import {
2
+ Token,
3
+ Address,
4
+ ExchangePrices,
5
+ PoolPrices,
6
+ AdapterExchangeParam,
7
+ PoolLiquidity,
8
+ DexExchangeParam,
9
+ NumberAsString,
10
+ } from '../../types';
11
+ import { SwapSide, Network, ETHER_ADDRESS } from '../../constants';
12
+ import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
13
+ import { getBigIntPow, getDexKeysWithNetwork } from '../../utils';
14
+ import { Context, IDex } from '../../dex/idex';
15
+ import { IDexHelper } from '../../dex-helper/idex-helper';
16
+ import {
17
+ EkuboData,
18
+ GetQuoteDataResponse,
19
+ PoolConfig,
20
+ PoolKey,
21
+ PoolState,
22
+ VanillaPoolParameters,
23
+ } from './types';
24
+ import { SimpleExchange } from '../simple-exchange';
25
+ import { EkuboConfig } from './config';
26
+ import { BasePool } from './pools/base-pool';
27
+ import {
28
+ convertEkuboToParaSwap,
29
+ convertParaSwapToEkubo,
30
+ hexStringTokenPair,
31
+ NATIVE_TOKEN_ADDRESS,
32
+ sortAndConvertTokens,
33
+ } from './utils';
34
+ import Joi from 'joi';
35
+ import { Interface } from '@ethersproject/abi';
36
+
37
+ import CoreABI from '../../abi/ekubo/core.json';
38
+ import DataFetcherABI from '../../abi/ekubo/data-fetcher.json';
39
+ import { BigNumber, Contract } from 'ethers';
40
+ import { FULL_RANGE_TICK_SPACING } from './pools/math/tick';
41
+ import { hexlify } from 'ethers/lib/utils';
42
+ import RouterABI from '../../abi/ekubo/router.json';
43
+ import { isPriceIncreasing } from './pools/math/swap';
44
+ import { OraclePool } from './pools/oracle-pool';
45
+ import { erc20Iface } from '../../lib/tokens/utils';
46
+ import { AsyncOrSync } from 'ts-essentials';
47
+ import { MAX_SQRT_RATIO_FLOAT, MIN_SQRT_RATIO_FLOAT } from './pools/math/price';
48
+ import { MIN_I256 } from './pools/math/constants';
49
+
50
+ const FALLBACK_POOL_PARAMETERS: VanillaPoolParameters[] = [
51
+ {
52
+ fee: 1844674407370955n,
53
+ tickSpacing: 200,
54
+ },
55
+ {
56
+ fee: 9223372036854775n,
57
+ tickSpacing: 1000,
58
+ },
59
+ {
60
+ fee: 55340232221128654n,
61
+ tickSpacing: 5982,
62
+ },
63
+ {
64
+ fee: 184467440737095516n,
65
+ tickSpacing: 19802,
66
+ },
67
+ {
68
+ fee: 922337203685477580n,
69
+ tickSpacing: 95310,
70
+ },
71
+ ];
72
+
73
+ type PairInfo = {
74
+ fee: string;
75
+ tick_spacing: number;
76
+ core_address: string;
77
+ extension: string;
78
+ tvl0_total: string;
79
+ tvl1_total: string;
80
+ };
81
+
82
+ const tokenPairSchema = Joi.object<{
83
+ topPools: PairInfo[];
84
+ }>({
85
+ topPools: Joi.array().items(
86
+ Joi.object({
87
+ fee: Joi.string(),
88
+ tick_spacing: Joi.number(),
89
+ extension: Joi.string(),
90
+ tvl0_total: Joi.string(),
91
+ tvl1_total: Joi.string(),
92
+ }),
93
+ ),
94
+ });
95
+
96
+ const allPoolsSchema = Joi.array<
97
+ {
98
+ core_address: string;
99
+ token0: string;
100
+ token1: string;
101
+ fee: string;
102
+ tick_spacing: number;
103
+ extension: string;
104
+ }[]
105
+ >().items(
106
+ Joi.object({
107
+ core_address: Joi.string(),
108
+ token0: Joi.string(),
109
+ token1: Joi.string(),
110
+ fee: Joi.string(),
111
+ tick_spacing: Joi.number(),
112
+ extension: Joi.string(),
113
+ }),
114
+ );
115
+
116
+ const MIN_TICK_SPACINGS_PER_POOL = 2;
117
+ const MAX_BATCH_SIZE = 100;
118
+
119
+ const POOL_MAP_UPDATE_INTERVAL_MS = 5 * 60 * 1000;
120
+
121
+ // Ekubo Protocol https://ekubo.org/
122
+ export class Ekubo extends SimpleExchange implements IDex<EkuboData> {
123
+ public readonly hasConstantPriceLargeAmounts = false;
124
+ public readonly needWrapNative = false;
125
+ public readonly isFeeOnTransferSupported = false;
126
+
127
+ public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
128
+ getDexKeysWithNetwork(EkuboConfig);
129
+
130
+ private readonly pools: Map<string, BasePool> = new Map();
131
+
132
+ public logger;
133
+
134
+ public readonly config;
135
+ public readonly routerIface;
136
+
137
+ private readonly core;
138
+ private readonly coreIface;
139
+ private readonly dataFetcher;
140
+ private readonly supportedExtensions;
141
+
142
+ private interval?: NodeJS.Timeout;
143
+
144
+ // Caches the number of decimals for TVL computation purposes
145
+ private readonly decimals: Record<string, number> = {
146
+ [ETHER_ADDRESS]: 18,
147
+ };
148
+
149
+ public constructor(
150
+ readonly network: Network,
151
+ readonly dexKey: string,
152
+ readonly dexHelper: IDexHelper,
153
+ ) {
154
+ super(dexHelper, dexKey);
155
+
156
+ this.logger = dexHelper.getLogger(dexKey);
157
+ this.config = EkuboConfig[dexKey][network];
158
+ this.core = new Contract(this.config.core, CoreABI, dexHelper.provider);
159
+ this.coreIface = new Interface(CoreABI);
160
+ this.dataFetcher = new Contract(
161
+ this.config.dataFetcher,
162
+ DataFetcherABI,
163
+ dexHelper.provider,
164
+ );
165
+ this.routerIface = new Interface(RouterABI);
166
+
167
+ // 0 are vanilla pools
168
+ this.supportedExtensions = [0n, BigInt(this.config.oracle)];
169
+ }
170
+
171
+ // Periodically schedules fetching pool keys from the Ekubo API and filling in details with the quote data fetcher
172
+ public async initializePricing(blockNumber: number) {
173
+ await this.updatePoolMap(blockNumber);
174
+
175
+ this.interval = setInterval(async () => {
176
+ await this.updatePoolMap(await this.dexHelper.provider.getBlockNumber());
177
+ }, POOL_MAP_UPDATE_INTERVAL_MS);
178
+ }
179
+
180
+ // LEGACY
181
+ public getAdapters(
182
+ _side: SwapSide,
183
+ ): { name: string; index: number }[] | null {
184
+ return null;
185
+ }
186
+
187
+ public async getPoolIdentifiers(
188
+ srcToken: Token,
189
+ destToken: Token,
190
+ _side: SwapSide,
191
+ blockNumber: number,
192
+ ): Promise<string[]> {
193
+ const [token0, token1] = sortAndConvertTokens(srcToken, destToken);
194
+ const pair = hexStringTokenPair(token0, token1);
195
+
196
+ let poolKeys: PoolKey[];
197
+ try {
198
+ poolKeys = (await this.fetchAllPoolKeys()).filter(
199
+ poolKey => poolKey.token0 === token0 && poolKey.token1 === token1,
200
+ );
201
+ } catch (err) {
202
+ this.logger.error(
203
+ `Fetching pools from Ekubo API for token pair ${pair} failed, falling back to default pool parameters: ${err}`,
204
+ );
205
+
206
+ poolKeys = FALLBACK_POOL_PARAMETERS.map(
207
+ params =>
208
+ new PoolKey(
209
+ token0,
210
+ token1,
211
+ new PoolConfig(params.tickSpacing, params.fee, 0n),
212
+ ),
213
+ );
214
+
215
+ if ([token0, token1].includes(NATIVE_TOKEN_ADDRESS)) {
216
+ poolKeys.push(
217
+ new PoolKey(
218
+ token0,
219
+ token1,
220
+ new PoolConfig(
221
+ FULL_RANGE_TICK_SPACING,
222
+ 0n,
223
+ BigInt(this.config.oracle),
224
+ ),
225
+ ),
226
+ );
227
+ }
228
+ }
229
+
230
+ const uninitializedPoolKeys: PoolKey[] = [];
231
+ const initializedPoolKeys: PoolKey[] = [];
232
+
233
+ for (const poolKey of poolKeys) {
234
+ (this.pools.has(poolKey.string_id)
235
+ ? initializedPoolKeys
236
+ : uninitializedPoolKeys
237
+ ).push(poolKey);
238
+ }
239
+
240
+ const promises = this.initializePools(uninitializedPoolKeys, blockNumber);
241
+
242
+ const oldPoolIds = initializedPoolKeys.map(poolKey => poolKey.string_id);
243
+ const newPoolIds = (await Promise.allSettled(promises)).flatMap(res => {
244
+ if (res.status === 'rejected') {
245
+ this.logger.error(
246
+ `Fetching batch failed. Pool keys: ${res.reason.batch}. Error: ${res.reason.err}`,
247
+ );
248
+ return [];
249
+ } else {
250
+ return res.value;
251
+ }
252
+ });
253
+
254
+ return oldPoolIds.concat(newPoolIds);
255
+ }
256
+
257
+ public async getPricesVolume(
258
+ srcToken: Token,
259
+ destToken: Token,
260
+ amounts: bigint[],
261
+ side: SwapSide,
262
+ blockNumber: number,
263
+ limitPools?: string[],
264
+ ): Promise<null | ExchangePrices<EkuboData>> {
265
+ const pools = this.getInitializedPools(srcToken, destToken, limitPools);
266
+
267
+ const isExactOut = side === SwapSide.BUY;
268
+
269
+ const amountToken = isExactOut ? destToken : srcToken;
270
+ const amountTokenAddress = convertParaSwapToEkubo(amountToken.address);
271
+ const unitAmount = getBigIntPow(amountToken.decimals);
272
+
273
+ const [token0, token1] = sortAndConvertTokens(srcToken, destToken);
274
+
275
+ const exchangePrices = [];
276
+
277
+ // eslint-disable-next-line no-restricted-syntax
278
+ poolLoop: for (const pool of pools) {
279
+ const poolId = pool.key.string_id;
280
+
281
+ if (pool.key.token0 !== token0 || pool.key.token1 !== token1) {
282
+ this.logger.error(
283
+ `Can't quote pair ${hexStringTokenPair(
284
+ token0,
285
+ token1,
286
+ )} on pool ${poolId}`,
287
+ );
288
+ continue;
289
+ }
290
+
291
+ try {
292
+ const quotes = [];
293
+ const skipAheadMap: Record<string, number> = {};
294
+
295
+ for (const amount of [unitAmount, ...amounts]) {
296
+ const inputAmount = isExactOut ? -amount : amount;
297
+
298
+ const quote = pool.quote(
299
+ inputAmount,
300
+ amountTokenAddress,
301
+ blockNumber,
302
+ );
303
+
304
+ if (isExactOut && quote.consumedAmount !== inputAmount) {
305
+ this.logger.debug(
306
+ `Pool ${poolId} doesn't have enough liquidity to support exact-out swap of ${amount} ${
307
+ amountToken.symbol ?? amountToken.address
308
+ }`,
309
+ );
310
+
311
+ // There doesn't seem to be a way to skip just this one price.
312
+ // Anyway, this pool is probably not the right one if it has such thin liquidity.
313
+ continue poolLoop;
314
+ }
315
+
316
+ quotes.push(quote);
317
+ skipAheadMap[amount.toString()] = quote.skipAhead;
318
+ }
319
+
320
+ const [unitQuote, ...otherQuotes] = quotes;
321
+
322
+ exchangePrices.push({
323
+ prices: otherQuotes.map(quote => quote.calculatedAmount),
324
+ unit: unitQuote.calculatedAmount,
325
+ data: {
326
+ poolKeyAbi: pool.key.toAbi(),
327
+ isToken1: amountTokenAddress === token1,
328
+ skipAhead: skipAheadMap,
329
+ },
330
+ poolIdentifier: poolId,
331
+ exchange: this.dexKey,
332
+ gasCost: otherQuotes.map(quote => quote.gasConsumed),
333
+ });
334
+ } catch (err) {
335
+ this.logger.error('Quote error:', err);
336
+ continue;
337
+ }
338
+ }
339
+
340
+ return exchangePrices;
341
+ }
342
+
343
+ // LEGACY
344
+ public getCalldataGasCost(
345
+ _poolPrices: PoolPrices<EkuboData>,
346
+ ): number | number[] {
347
+ return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
348
+ }
349
+
350
+ // LEGACY
351
+ public getAdapterParam(
352
+ _srcToken: string,
353
+ _destToken: string,
354
+ _srcAmount: string,
355
+ _destAmount: string,
356
+ _data: EkuboData,
357
+ _side: SwapSide,
358
+ ): AdapterExchangeParam {
359
+ return {
360
+ targetExchange: this.dexKey,
361
+ payload: '',
362
+ networkFee: '0',
363
+ };
364
+ }
365
+
366
+ public async updatePoolState(): Promise<void> {}
367
+
368
+ public async getTopPoolsForToken(
369
+ tokenAddress: Address,
370
+ limit: number,
371
+ ): Promise<PoolLiquidity[]> {
372
+ // The integration tests skip initializePricing, hence this check
373
+ if (this.pools.size === 0) {
374
+ await this.updatePoolMap(await this.dexHelper.provider.getBlockNumber());
375
+ }
376
+
377
+ const token = convertParaSwapToEkubo(tokenAddress);
378
+
379
+ const settledPromises = await Promise.allSettled(
380
+ Array.from(this.pools.entries()).map(async ([poolId, pool]) => {
381
+ const tokenPair = [pool.key.token0, pool.key.token1];
382
+ if (!tokenPair.includes(token)) {
383
+ return null;
384
+ }
385
+
386
+ const tvlRes = pool.computeTvl();
387
+ if (tvlRes === null) {
388
+ throw new Error(`failed to compute TVL for pool ${poolId}`);
389
+ }
390
+
391
+ const [info0, info1] = await Promise.all(
392
+ tokenPair.map((ekuboToken, i) =>
393
+ (async () => {
394
+ const paraswapToken = convertEkuboToParaSwap(ekuboToken);
395
+ const decimals = await this.getDecimals(paraswapToken);
396
+
397
+ const token = {
398
+ address: paraswapToken,
399
+ decimals,
400
+ };
401
+
402
+ return {
403
+ token,
404
+ tvl: await this.dexHelper.getTokenUSDPrice(token, tvlRes[i]),
405
+ };
406
+ })(),
407
+ ),
408
+ );
409
+
410
+ return {
411
+ exchange: this.dexKey,
412
+ address: this.config.core,
413
+ connectorTokens: [
414
+ (info0.token.address !== tokenAddress ? info0 : info1).token,
415
+ ],
416
+ liquidityUSD: info0.tvl + info1.tvl,
417
+ };
418
+ }),
419
+ );
420
+
421
+ const poolLiquidities = settledPromises.flatMap(res => {
422
+ if (res.status === 'rejected') {
423
+ this.logger.error('TVL computation failed:', res.reason);
424
+ return [];
425
+ }
426
+
427
+ return res.value ? [res.value] : [];
428
+ });
429
+
430
+ poolLiquidities
431
+ .sort((a, b) => b.liquidityUSD - a.liquidityUSD)
432
+ .splice(limit, Infinity);
433
+
434
+ return poolLiquidities;
435
+ }
436
+
437
+ private async getDecimals(paraswapToken: string): Promise<number> {
438
+ const cached = this.decimals[paraswapToken];
439
+ if (typeof cached === 'number') {
440
+ return cached;
441
+ }
442
+
443
+ const decimals: number = await new Contract(
444
+ paraswapToken,
445
+ erc20Iface,
446
+ this.dexHelper.provider,
447
+ ).decimals();
448
+
449
+ this.decimals[paraswapToken] = decimals;
450
+
451
+ return decimals;
452
+ }
453
+
454
+ public getDexParam(
455
+ _srcToken: Address,
456
+ _destToken: Address,
457
+ srcAmount: NumberAsString,
458
+ destAmount: NumberAsString,
459
+ recipient: Address,
460
+ data: EkuboData,
461
+ side: SwapSide,
462
+ _context: Context,
463
+ _executorAddress: Address,
464
+ ): DexExchangeParam {
465
+ const amount = BigInt(side === SwapSide.BUY ? `-${destAmount}` : srcAmount);
466
+ const amountStr = (
467
+ side === SwapSide.SELL ? srcAmount : destAmount
468
+ ).toString();
469
+
470
+ return {
471
+ needWrapNative: this.needWrapNative,
472
+ exchangeData: this.routerIface.encodeFunctionData(
473
+ 'swap((address,address,bytes32),bool,int128,uint96,uint256,int256,address)',
474
+ [
475
+ data.poolKeyAbi,
476
+ data.isToken1,
477
+ BigNumber.from(amount),
478
+ isPriceIncreasing(amount, data.isToken1)
479
+ ? MAX_SQRT_RATIO_FLOAT
480
+ : MIN_SQRT_RATIO_FLOAT,
481
+ BigNumber.from(data.skipAhead[amountStr] ?? 0),
482
+ MIN_I256,
483
+ recipient,
484
+ ],
485
+ ),
486
+ targetExchange: this.config.router,
487
+ dexFuncHasRecipient: true,
488
+ returnAmountPos: undefined,
489
+ };
490
+ }
491
+
492
+ releaseResources(): AsyncOrSync<void> {
493
+ if (this.interval) {
494
+ clearInterval(this.interval);
495
+ this.interval = undefined;
496
+ }
497
+ }
498
+
499
+ private getInitializedPools(
500
+ tokenA: Token,
501
+ tokenB: Token,
502
+ limitPools: string[] | undefined,
503
+ ): BasePool[] {
504
+ if (typeof limitPools === 'undefined') {
505
+ const [token0, token1] = sortAndConvertTokens(tokenA, tokenB);
506
+
507
+ return Array.from(
508
+ this.pools
509
+ .values()
510
+ .filter(
511
+ pool => pool.key.token0 === token0 && pool.key.token1 === token1,
512
+ ),
513
+ );
514
+ }
515
+
516
+ return limitPools.flatMap(poolId => {
517
+ const pool = this.pools.get(poolId);
518
+
519
+ if (typeof pool === 'undefined') {
520
+ this.logger.warn(`Pool ${poolId} requested but not found`);
521
+ return [];
522
+ }
523
+
524
+ return [pool];
525
+ });
526
+ }
527
+
528
+ private async updatePoolMap(blockNumber: number) {
529
+ let poolKeys: PoolKey[];
530
+ try {
531
+ poolKeys = await this.fetchAllPoolKeys();
532
+ } catch (err) {
533
+ this.logger.error(`Updating pool map from Ekubo API failed: ${err}`);
534
+
535
+ return;
536
+ }
537
+
538
+ const uninitializedPoolKeys = poolKeys.filter(
539
+ poolKey => !this.pools.has(poolKey.string_id),
540
+ );
541
+ const promises = this.initializePools(uninitializedPoolKeys, blockNumber);
542
+
543
+ (await Promise.allSettled(promises)).flatMap(res => {
544
+ if (res.status === 'rejected') {
545
+ this.logger.error(
546
+ `Fetching batch failed. Pool keys: ${res.reason.batch}. Error: ${res.reason.err}`,
547
+ );
548
+ }
549
+ });
550
+ }
551
+
552
+ private initializePools(
553
+ poolKeys: PoolKey[],
554
+ blockNumber: number,
555
+ ): Promise<string[]>[] {
556
+ const promises = [];
557
+
558
+ for (
559
+ let batchStart = 0;
560
+ batchStart < poolKeys.length;
561
+ batchStart += MAX_BATCH_SIZE
562
+ ) {
563
+ const batch = poolKeys.slice(batchStart, batchStart + MAX_BATCH_SIZE);
564
+
565
+ promises.push(
566
+ (async () => {
567
+ const fetchedData: GetQuoteDataResponse =
568
+ await this.dataFetcher.getQuoteData(
569
+ batch.map(poolKey => poolKey.toAbi()),
570
+ MIN_TICK_SPACINGS_PER_POOL,
571
+ {
572
+ blockTag: blockNumber,
573
+ },
574
+ );
575
+
576
+ return fetchedData.map((data, i) => {
577
+ const poolKey = poolKeys[batchStart + i];
578
+ const initialState = PoolState.fromQuoter(
579
+ data,
580
+ poolKey.config.tickSpacing === FULL_RANGE_TICK_SPACING,
581
+ );
582
+ const poolId = poolKey.string_id;
583
+ const extension = poolKey.config.extension;
584
+
585
+ let poolConstructor;
586
+ if (extension === 0n) {
587
+ poolConstructor = BasePool;
588
+ } else if (extension === BigInt(this.config.oracle)) {
589
+ poolConstructor = OraclePool;
590
+ } else {
591
+ throw new Error(`Unknown pool extension ${hexlify(extension)}`);
592
+ }
593
+
594
+ const pool = new poolConstructor(
595
+ this.dexKey,
596
+ this.network,
597
+ this.dexHelper,
598
+ this.logger,
599
+ this.coreIface,
600
+ this.dataFetcher,
601
+ poolKey,
602
+ this.core,
603
+ );
604
+
605
+ this.pools.set(poolId, pool);
606
+
607
+ // This is fulfilled immediately
608
+ pool.initialize(blockNumber, { state: initialState });
609
+
610
+ return poolId;
611
+ });
612
+ })().catch(err => {
613
+ throw {
614
+ batch,
615
+ err,
616
+ };
617
+ }),
618
+ );
619
+ }
620
+
621
+ return promises;
622
+ }
623
+
624
+ private async fetchAllPoolKeys(): Promise<PoolKey[]> {
625
+ const res = await this.dexHelper.httpRequest.get(
626
+ `${this.config.apiUrl}/v1/poolKeys`,
627
+ );
628
+
629
+ const { error, value } = allPoolsSchema.validate(res, {
630
+ allowUnknown: true,
631
+ presence: 'required',
632
+ });
633
+
634
+ if (typeof error !== 'undefined') {
635
+ throw new Error(`validating API response: ${error}`);
636
+ }
637
+
638
+ return value
639
+ .filter(
640
+ res =>
641
+ this.supportedExtensions.includes(BigInt(res.extension)) &&
642
+ BigInt(res.core_address) === BigInt(this.core.address),
643
+ )
644
+ .map(
645
+ info =>
646
+ new PoolKey(
647
+ BigInt(info.token0),
648
+ BigInt(info.token1),
649
+ new PoolConfig(
650
+ info.tick_spacing,
651
+ BigInt(info.fee),
652
+ BigInt(info.extension),
653
+ ),
654
+ ),
655
+ );
656
+ }
657
+ }