@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,215 @@
1
+ import {
2
+ amountBeforeFee,
3
+ computeFee,
4
+ computeStep,
5
+ isPriceIncreasing,
6
+ } from './swap';
7
+ import { MAX_SQRT_RATIO, MIN_SQRT_RATIO } from './tick';
8
+
9
+ describe(isPriceIncreasing, () => {
10
+ it('many cases', () => {
11
+ expect(isPriceIncreasing(0n, false)).toBe(false);
12
+ expect(isPriceIncreasing(1n, false)).toBe(false);
13
+ expect(isPriceIncreasing(-1n, false)).toBe(true);
14
+ expect(isPriceIncreasing(0n, true)).toBe(true);
15
+ expect(isPriceIncreasing(1n, true)).toBe(true);
16
+ expect(isPriceIncreasing(-1n, true)).toBe(false);
17
+ });
18
+ });
19
+
20
+ describe(amountBeforeFee, () => {
21
+ it('rounds up', () => {
22
+ expect(amountBeforeFee(105n, (1n << 64n) / 100n)).toMatchInlineSnapshot(
23
+ `107n`,
24
+ );
25
+ });
26
+ });
27
+
28
+ describe(computeFee, () => {
29
+ it('rounds up', () => {
30
+ expect(computeFee(105n, (1n << 64n) / 100n)).toMatchInlineSnapshot(`2n`);
31
+ });
32
+ it('rounds evenly', () => {
33
+ expect(computeFee(100n, (1n << 64n) / 100n)).toMatchInlineSnapshot(`1n`);
34
+ });
35
+ });
36
+
37
+ describe(computeStep, () => {
38
+ it('zero_amount_token0', () => {
39
+ expect(
40
+ computeStep({
41
+ sqrtRatio: 0x100000000000000000000000000000000n,
42
+ liquidity: 100000n,
43
+ sqrtRatioLimit: 0n,
44
+ amount: 0n,
45
+ isToken1: false,
46
+ fee: 0n,
47
+ }),
48
+ ).toMatchInlineSnapshot(`
49
+ {
50
+ "calculatedAmount": 0n,
51
+ "consumedAmount": 0n,
52
+ "feeAmount": 0n,
53
+ "sqrtRatioNext": 340282366920938463463374607431768211456n,
54
+ }
55
+ `);
56
+ });
57
+ it('zero_amount_token1', () => {
58
+ expect(
59
+ computeStep({
60
+ sqrtRatio: 0x100000000000000000000000000000000n,
61
+ liquidity: 100000n,
62
+ sqrtRatioLimit: 0n,
63
+ amount: 0n,
64
+ isToken1: true,
65
+ fee: 0n,
66
+ }),
67
+ ).toMatchInlineSnapshot(`
68
+ {
69
+ "calculatedAmount": 0n,
70
+ "consumedAmount": 0n,
71
+ "feeAmount": 0n,
72
+ "sqrtRatioNext": 340282366920938463463374607431768211456n,
73
+ }
74
+ `);
75
+ });
76
+ it('swap_ratio_equal_limit_token1', () => {
77
+ expect(
78
+ computeStep({
79
+ sqrtRatio: 0x100000000000000000000000000000000n,
80
+ liquidity: 100000n,
81
+ sqrtRatioLimit: 0x100000000000000000000000000000000n,
82
+ amount: 10000n,
83
+ isToken1: true,
84
+ fee: 0n,
85
+ }),
86
+ ).toMatchInlineSnapshot(`
87
+ {
88
+ "calculatedAmount": 0n,
89
+ "consumedAmount": 0n,
90
+ "feeAmount": 0n,
91
+ "sqrtRatioNext": 340282366920938463463374607431768211456n,
92
+ }
93
+ `);
94
+ });
95
+
96
+ it('max limit token0 input', () => {
97
+ expect(
98
+ computeStep({
99
+ sqrtRatio: 0x100000000000000000000000000000000n,
100
+ liquidity: 100000n,
101
+ sqrtRatioLimit: MIN_SQRT_RATIO,
102
+ amount: 10000n,
103
+ isToken1: false,
104
+ fee: 1n << 63n,
105
+ }),
106
+ ).toMatchInlineSnapshot(`
107
+ {
108
+ "calculatedAmount": 4761n,
109
+ "consumedAmount": 10000n,
110
+ "feeAmount": 5000n,
111
+ "sqrtRatioNext": 324078444686608060441309149935017344244n,
112
+ }
113
+ `);
114
+ });
115
+
116
+ it('max limit token1 input', () => {
117
+ expect(
118
+ computeStep({
119
+ sqrtRatio: 0x100000000000000000000000000000000n,
120
+ liquidity: 100000n,
121
+ sqrtRatioLimit: MAX_SQRT_RATIO,
122
+ amount: 10000n,
123
+ isToken1: true,
124
+ fee: 1n << 63n,
125
+ }),
126
+ ).toMatchInlineSnapshot(`
127
+ {
128
+ "calculatedAmount": 4761n,
129
+ "consumedAmount": 10000n,
130
+ "feeAmount": 5000n,
131
+ "sqrtRatioNext": 357296485266985386636543337803356622028n,
132
+ }
133
+ `);
134
+ });
135
+
136
+ it('max limit token0 output', () => {
137
+ expect(
138
+ computeStep({
139
+ sqrtRatio: 0x100000000000000000000000000000000n,
140
+ liquidity: 100000n,
141
+ sqrtRatioLimit: MAX_SQRT_RATIO,
142
+ amount: -10000n,
143
+ isToken1: false,
144
+ fee: 1n << 63n,
145
+ }),
146
+ ).toMatchInlineSnapshot(`
147
+ {
148
+ "calculatedAmount": 22224n,
149
+ "consumedAmount": -10000n,
150
+ "feeAmount": 11112n,
151
+ "sqrtRatioNext": 378091518801042737181527341590853568285n,
152
+ }
153
+ `);
154
+ });
155
+
156
+ it('max limit token1 output', () => {
157
+ expect(
158
+ computeStep({
159
+ sqrtRatio: 0x100000000000000000000000000000000n,
160
+ liquidity: 100000n,
161
+ sqrtRatioLimit: MIN_SQRT_RATIO,
162
+ amount: -10000n,
163
+ isToken1: true,
164
+ fee: 1n << 63n,
165
+ }),
166
+ ).toMatchInlineSnapshot(`
167
+ {
168
+ "calculatedAmount": 22224n,
169
+ "consumedAmount": -10000n,
170
+ "feeAmount": 11112n,
171
+ "sqrtRatioNext": 306254130228844617117037146688591390310n,
172
+ }
173
+ `);
174
+ });
175
+
176
+ it('limited token0 output', () => {
177
+ expect(
178
+ computeStep({
179
+ sqrtRatio: 0x100000000000000000000000000000000n,
180
+ liquidity: 100000n,
181
+ sqrtRatioLimit: 359186942860990600322450974511310889870n,
182
+ amount: -10000n,
183
+ isToken1: false,
184
+ fee: 1n << 63n,
185
+ }),
186
+ ).toMatchInlineSnapshot(`
187
+ {
188
+ "calculatedAmount": 11112n,
189
+ "consumedAmount": -5263n,
190
+ "feeAmount": 5556n,
191
+ "sqrtRatioNext": 359186942860990600322450974511310889870n,
192
+ }
193
+ `);
194
+ });
195
+
196
+ it('limited token1 output', () => {
197
+ expect(
198
+ computeStep({
199
+ sqrtRatio: 0x100000000000000000000000000000000n,
200
+ liquidity: 100000n,
201
+ sqrtRatioLimit: 323268248574891540290205877060179800883n,
202
+ amount: -10000n,
203
+ isToken1: true,
204
+ fee: 1n << 63n,
205
+ }),
206
+ ).toMatchInlineSnapshot(`
207
+ {
208
+ "calculatedAmount": 10528n,
209
+ "consumedAmount": -5000n,
210
+ "feeAmount": 5264n,
211
+ "sqrtRatioNext": 323268248574891540290205877060179800883n,
212
+ }
213
+ `);
214
+ });
215
+ });
@@ -0,0 +1,161 @@
1
+ import { nextSqrtRatioFromAmount0, nextSqrtRatioFromAmount1 } from './price';
2
+ import { amount0Delta, amount1Delta } from './delta';
3
+ import { MAX_U128 } from './constants';
4
+
5
+ interface SwapResult {
6
+ consumedAmount: bigint;
7
+ calculatedAmount: bigint;
8
+ sqrtRatioNext: bigint;
9
+ feeAmount: bigint;
10
+ }
11
+
12
+ export function isPriceIncreasing(amount: bigint, isToken1: boolean): boolean {
13
+ return amount < 0n !== isToken1;
14
+ }
15
+
16
+ function noOp(sqrtRatioNext: bigint): SwapResult {
17
+ return {
18
+ consumedAmount: 0n,
19
+ calculatedAmount: 0n,
20
+ sqrtRatioNext,
21
+ feeAmount: 0n,
22
+ };
23
+ }
24
+
25
+ export function amountBeforeFee(amount: bigint, fee: bigint): bigint {
26
+ if (fee === 0n) return amount;
27
+ const num = amount << 64n;
28
+ const denom = (1n << 64n) - fee;
29
+ const val = num / denom;
30
+ const result = val + (num % denom !== 0n ? 1n : 0n);
31
+ if (result > MAX_U128) throw new Error('AMOUNT_BEFORE_FEE_OVERFLOW');
32
+ return result;
33
+ }
34
+
35
+ export function computeFee(amount: bigint, fee: bigint) {
36
+ const num = amount * fee;
37
+ const denom = 2n ** 64n;
38
+ if (num % denom !== 0n) {
39
+ return num / denom + 1n;
40
+ } else {
41
+ return num / denom;
42
+ }
43
+ }
44
+
45
+ export function computeStep({
46
+ sqrtRatio,
47
+ liquidity,
48
+ sqrtRatioLimit,
49
+ amount,
50
+ isToken1,
51
+ fee,
52
+ }: {
53
+ sqrtRatio: bigint;
54
+ liquidity: bigint;
55
+ sqrtRatioLimit: bigint;
56
+ amount: bigint;
57
+ isToken1: boolean;
58
+ fee: bigint;
59
+ }): SwapResult {
60
+ if (amount === 0n || sqrtRatio === sqrtRatioLimit) {
61
+ return noOp(sqrtRatio);
62
+ }
63
+
64
+ const increasing = isPriceIncreasing(amount, isToken1);
65
+
66
+ if (sqrtRatioLimit < sqrtRatio === increasing) {
67
+ throw new Error('computeStep: wrong direction');
68
+ }
69
+
70
+ if (liquidity === 0n) {
71
+ return noOp(sqrtRatioLimit);
72
+ }
73
+
74
+ let priceImpactAmount: bigint;
75
+ if (amount < 0n) {
76
+ priceImpactAmount = amount;
77
+ } else {
78
+ priceImpactAmount = amount - computeFee(amount, fee);
79
+ }
80
+
81
+ let sqrtRatioNextFromAmount: bigint | null;
82
+ if (isToken1) {
83
+ sqrtRatioNextFromAmount = nextSqrtRatioFromAmount1(
84
+ sqrtRatio,
85
+ liquidity,
86
+ priceImpactAmount,
87
+ );
88
+ } else {
89
+ sqrtRatioNextFromAmount = nextSqrtRatioFromAmount0(
90
+ sqrtRatio,
91
+ liquidity,
92
+ priceImpactAmount,
93
+ );
94
+ }
95
+
96
+ if (
97
+ sqrtRatioNextFromAmount === null ||
98
+ sqrtRatioNextFromAmount > sqrtRatioLimit === increasing
99
+ ) {
100
+ const [specifiedAmountDelta, calculatedAmountDelta]: [bigint, bigint] =
101
+ isToken1
102
+ ? [
103
+ amount1Delta(sqrtRatioLimit, sqrtRatio, liquidity, amount >= 0n) *
104
+ (amount < 0n ? -1n : 1n),
105
+ amount0Delta(sqrtRatioLimit, sqrtRatio, liquidity, amount < 0n),
106
+ ]
107
+ : [
108
+ amount0Delta(sqrtRatioLimit, sqrtRatio, liquidity, amount >= 0n) *
109
+ (amount < 0n ? -1n : 1n),
110
+ amount1Delta(sqrtRatioLimit, sqrtRatio, liquidity, amount < 0n),
111
+ ];
112
+
113
+ if (amount < 0n) {
114
+ const beforeFee = amountBeforeFee(calculatedAmountDelta, fee);
115
+ return {
116
+ consumedAmount: specifiedAmountDelta,
117
+ calculatedAmount: beforeFee,
118
+ feeAmount: beforeFee - calculatedAmountDelta,
119
+ sqrtRatioNext: sqrtRatioLimit,
120
+ };
121
+ } else {
122
+ const beforeFee = amountBeforeFee(specifiedAmountDelta, fee);
123
+ return {
124
+ consumedAmount: beforeFee,
125
+ calculatedAmount: calculatedAmountDelta,
126
+ feeAmount: beforeFee - specifiedAmountDelta,
127
+ sqrtRatioNext: sqrtRatioLimit,
128
+ };
129
+ }
130
+ }
131
+
132
+ if (sqrtRatioNextFromAmount === sqrtRatio) {
133
+ return {
134
+ consumedAmount: amount,
135
+ calculatedAmount: 0n,
136
+ feeAmount: amount,
137
+ sqrtRatioNext: sqrtRatio,
138
+ };
139
+ }
140
+
141
+ const calculatedAmountExcludingFee = isToken1
142
+ ? amount0Delta(sqrtRatioNextFromAmount, sqrtRatio, liquidity, amount < 0n)
143
+ : amount1Delta(sqrtRatioNextFromAmount, sqrtRatio, liquidity, amount < 0n);
144
+
145
+ if (amount < 0n) {
146
+ const includingFee = amountBeforeFee(calculatedAmountExcludingFee, fee);
147
+ return {
148
+ consumedAmount: amount,
149
+ calculatedAmount: includingFee,
150
+ sqrtRatioNext: sqrtRatioNextFromAmount,
151
+ feeAmount: includingFee - calculatedAmountExcludingFee,
152
+ };
153
+ } else {
154
+ return {
155
+ consumedAmount: amount,
156
+ calculatedAmount: calculatedAmountExcludingFee,
157
+ sqrtRatioNext: sqrtRatioNextFromAmount,
158
+ feeAmount: amount - priceImpactAmount,
159
+ };
160
+ }
161
+ }
@@ -0,0 +1,72 @@
1
+ import {
2
+ approximateNumberOfTickSpacingsCrossed,
3
+ MAX_SQRT_RATIO,
4
+ MAX_TICK,
5
+ MIN_SQRT_RATIO,
6
+ MIN_TICK,
7
+ toSqrtRatio,
8
+ } from './tick';
9
+
10
+ describe(toSqrtRatio, () => {
11
+ it('min tick', () => {
12
+ expect(toSqrtRatio(MIN_TICK)).toEqual(MIN_SQRT_RATIO);
13
+ });
14
+ it('max tick', () => {
15
+ expect(toSqrtRatio(MAX_TICK)).toEqual(MAX_SQRT_RATIO);
16
+ });
17
+ it('zero', () => {
18
+ expect(toSqrtRatio(0)).toEqual(1n << 128n);
19
+ });
20
+
21
+ it('snapshots', () => {
22
+ expect(toSqrtRatio(1e6)).toMatchInlineSnapshot(
23
+ `561030636129153856592777659729523183729n`,
24
+ );
25
+ expect(toSqrtRatio(1e7)).toMatchInlineSnapshot(
26
+ `50502254805927926084427918474025309948677n`,
27
+ );
28
+ expect(toSqrtRatio(-1e6)).toMatchInlineSnapshot(
29
+ `206391740095027370700312310531588921767n`,
30
+ );
31
+ expect(toSqrtRatio(-1e7)).toMatchInlineSnapshot(
32
+ `2292810285051363400276741638672651165n`,
33
+ );
34
+ });
35
+ });
36
+
37
+ describe(approximateNumberOfTickSpacingsCrossed, () => {
38
+ it('same price', () => {
39
+ expect(
40
+ approximateNumberOfTickSpacingsCrossed(1n << 128n, 1n << 128n, 1),
41
+ ).toEqual(0);
42
+ });
43
+ it('price doubling 1 tick spacing', () => {
44
+ expect(
45
+ approximateNumberOfTickSpacingsCrossed(1n << 128n, 1n << 129n, 1),
46
+ ).toMatchInlineSnapshot(`5415`);
47
+ });
48
+ it('price doubling 1000 tick spacing', () => {
49
+ expect(
50
+ approximateNumberOfTickSpacingsCrossed(1n << 128n, 1n << 129n, 1000),
51
+ ).toMatchInlineSnapshot(`5`);
52
+ });
53
+ it('max to min', () => {
54
+ expect(
55
+ approximateNumberOfTickSpacingsCrossed(MAX_SQRT_RATIO, MIN_SQRT_RATIO, 1),
56
+ ).toMatchInlineSnapshot(`693146`);
57
+ });
58
+ it('min to max', () => {
59
+ expect(
60
+ approximateNumberOfTickSpacingsCrossed(MIN_SQRT_RATIO, MAX_SQRT_RATIO, 1),
61
+ ).toMatchInlineSnapshot(`693146`);
62
+ });
63
+ it('min to max 1k tick spacing', () => {
64
+ expect(
65
+ approximateNumberOfTickSpacingsCrossed(
66
+ MIN_SQRT_RATIO,
67
+ MAX_SQRT_RATIO,
68
+ 1000,
69
+ ),
70
+ ).toMatchInlineSnapshot(`693`);
71
+ });
72
+ });
@@ -0,0 +1,120 @@
1
+ import { MAX_U256 } from './constants';
2
+
3
+ export const MIN_TICK = -88722835;
4
+ export const MAX_TICK = 88722835;
5
+ export const MAX_SQRT_RATIO: bigint =
6
+ 6276949602062853172742588666638147158083741740262337144812n;
7
+ export const MIN_SQRT_RATIO: bigint = 18447191164202170526n;
8
+ export const FULL_RANGE_TICK_SPACING = 0;
9
+
10
+ export function toSqrtRatio(tick: number): bigint {
11
+ if (tick < MIN_TICK || tick > MAX_TICK)
12
+ throw new Error(`Invalid tick: ${tick}`);
13
+ let sign = tick < 0;
14
+ tick = Math.abs(tick);
15
+ let ratio = 0x100000000000000000000000000000000n;
16
+ if ((tick & 0x1) != 0) {
17
+ ratio = 0xfffff79c8499329c7cbb2510d893283bn;
18
+ }
19
+ if ((tick & 0x2) != 0) {
20
+ ratio = (ratio * 0xffffef390978c398134b4ff3764fe410n) >> 128n;
21
+ }
22
+ if ((tick & 0x4) != 0) {
23
+ ratio = (ratio * 0xffffde72140b00a354bd3dc828e976c9n) >> 128n;
24
+ }
25
+ if ((tick & 0x8) != 0) {
26
+ ratio = (ratio * 0xffffbce42c7be6c998ad6318193c0b18n) >> 128n;
27
+ }
28
+ if ((tick & 0x10) != 0) {
29
+ ratio = (ratio * 0xffff79c86a8f6150a32d9778eceef97cn) >> 128n;
30
+ }
31
+ if ((tick & 0x20) != 0) {
32
+ ratio = (ratio * 0xfffef3911b7cff24ba1b3dbb5f8f5974n) >> 128n;
33
+ }
34
+ if ((tick & 0x40) != 0) {
35
+ ratio = (ratio * 0xfffde72350725cc4ea8feece3b5f13c8n) >> 128n;
36
+ }
37
+ if ((tick & 0x80) != 0) {
38
+ ratio = (ratio * 0xfffbce4b06c196e9247ac87695d53c60n) >> 128n;
39
+ }
40
+ if ((tick & 0x100) != 0) {
41
+ ratio = (ratio * 0xfff79ca7a4d1bf1ee8556cea23cdbaa5n) >> 128n;
42
+ }
43
+ if ((tick & 0x200) != 0) {
44
+ ratio = (ratio * 0xffef3995a5b6a6267530f207142a5764n) >> 128n;
45
+ }
46
+ if ((tick & 0x400) != 0) {
47
+ ratio = (ratio * 0xffde7444b28145508125d10077ba83b8n) >> 128n;
48
+ }
49
+ if ((tick & 0x800) != 0) {
50
+ ratio = (ratio * 0xffbceceeb791747f10df216f2e53ec57n) >> 128n;
51
+ }
52
+ if ((tick & 0x1000) != 0) {
53
+ ratio = (ratio * 0xff79eb706b9a64c6431d76e63531e929n) >> 128n;
54
+ }
55
+ if ((tick & 0x2000) != 0) {
56
+ ratio = (ratio * 0xfef41d1a5f2ae3a20676bec6f7f9459an) >> 128n;
57
+ }
58
+ if ((tick & 0x4000) != 0) {
59
+ ratio = (ratio * 0xfde95287d26d81bea159c37073122c73n) >> 128n;
60
+ }
61
+ if ((tick & 0x8000) != 0) {
62
+ ratio = (ratio * 0xfbd701c7cbc4c8a6bb81efd232d1e4e7n) >> 128n;
63
+ }
64
+ if ((tick & 0x10000) != 0) {
65
+ ratio = (ratio * 0xf7bf5211c72f5185f372aeb1d48f937en) >> 128n;
66
+ }
67
+ if ((tick & 0x20000) != 0) {
68
+ ratio = (ratio * 0xefc2bf59df33ecc28125cf78ec4f167fn) >> 128n;
69
+ }
70
+ if ((tick & 0x40000) != 0) {
71
+ ratio = (ratio * 0xe08d35706200796273f0b3a981d90cfdn) >> 128n;
72
+ }
73
+ if ((tick & 0x80000) != 0) {
74
+ ratio = (ratio * 0xc4f76b68947482dc198a48a54348c4edn) >> 128n;
75
+ }
76
+ if ((tick & 0x100000) != 0) {
77
+ ratio = (ratio * 0x978bcb9894317807e5fa4498eee7c0fan) >> 128n;
78
+ }
79
+ if ((tick & 0x200000) != 0) {
80
+ ratio = (ratio * 0x59b63684b86e9f486ec54727371ba6can) >> 128n;
81
+ }
82
+ if ((tick & 0x400000) != 0) {
83
+ ratio = (ratio * 0x1f703399d88f6aa83a28b22d4a1f56e3n) >> 128n;
84
+ }
85
+ if ((tick & 0x800000) != 0) {
86
+ ratio = (ratio * 0x3dc5dac7376e20fc8679758d1bcdcfcn) >> 128n;
87
+ }
88
+ if ((tick & 0x1000000) != 0) {
89
+ ratio = (ratio * 0xee7e32d61fdb0a5e622b820f681d0n) >> 128n;
90
+ }
91
+ if ((tick & 0x2000000) != 0) {
92
+ ratio = (ratio * 0xde2ee4bc381afa7089aa84bb66n) >> 128n;
93
+ }
94
+ if ((tick & 0x4000000) != 0) {
95
+ ratio = (ratio * 0xc0d55d4d7152c25fb139n) >> 128n;
96
+ }
97
+
98
+ if (tick > 0 && !sign) {
99
+ ratio = MAX_U256 / ratio;
100
+ }
101
+
102
+ return ratio;
103
+ }
104
+
105
+ const logBase = Math.log(1.0000005);
106
+
107
+ export function approximateNumberOfTickSpacingsCrossed(
108
+ sqrtRatioStart: bigint,
109
+ sqrtRatioEnd: bigint,
110
+ tickSpacing: number,
111
+ ): number {
112
+ if (tickSpacing === FULL_RANGE_TICK_SPACING) {
113
+ return 0;
114
+ }
115
+
116
+ const logPriceDiff =
117
+ Math.log(Number(sqrtRatioEnd) / Number(sqrtRatioStart)) / logBase;
118
+
119
+ return Math.floor(Math.abs(logPriceDiff / (tickSpacing * 256)));
120
+ }
@@ -0,0 +1,46 @@
1
+ import { Contract } from 'ethers';
2
+ import { IDexHelper } from '../../../dex-helper';
3
+ import { Logger } from '../../../types';
4
+ import { BasePool, Quote } from './base-pool';
5
+ import { PoolKey } from '../types';
6
+ import { Interface } from '@ethersproject/abi';
7
+
8
+ const GAS_COST_OF_UPDATING_ORACLE_SNAPSHOT = 15_000;
9
+
10
+ export class OraclePool extends BasePool {
11
+ public constructor(
12
+ parentName: string,
13
+ network: number,
14
+ dexHelper: IDexHelper,
15
+ logger: Logger,
16
+ coreIface: Interface,
17
+ dataFetcher: Contract,
18
+ key: PoolKey,
19
+ core: Contract,
20
+ ) {
21
+ super(
22
+ parentName,
23
+ network,
24
+ dexHelper,
25
+ logger,
26
+ coreIface,
27
+ dataFetcher,
28
+ key,
29
+ core,
30
+ );
31
+ }
32
+
33
+ public override quote(
34
+ amount: bigint,
35
+ token: bigint,
36
+ blockNumber: number,
37
+ ): Quote {
38
+ let baseQuote = super.quote(amount, token, blockNumber);
39
+
40
+ if (baseQuote.gasConsumed > 0n) {
41
+ baseQuote.gasConsumed += GAS_COST_OF_UPDATING_ORACLE_SNAPSHOT;
42
+ }
43
+
44
+ return baseQuote;
45
+ }
46
+ }