@paraswap/dex-lib 2.28.9-take-surplus.0 → 2.28.9-take-surplus.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (330) hide show
  1. package/build/abi/RamsesV2StateMulticall.abi.json +891 -0
  2. package/build/abi/aerodrome/aerodrome-pool-factory.json +586 -0
  3. package/build/abi/algebra/AlgebraFactory-v1_1.abi.json +250 -0
  4. package/build/abi/api3-proxy.json +53 -0
  5. package/build/abi/api3-server-v1.json +463 -0
  6. package/build/abi/nomiswap-v2/nomiswap-v2-pool.json +773 -0
  7. package/build/abi/pancakeswap-v3/PancakeswapV3Factory.abi.json +300 -0
  8. package/build/abi/quick-perps/fast-price-events.json +70 -0
  9. package/build/abi/quick-perps/fast-price-feed.json +741 -0
  10. package/build/abi/quick-perps/reader.json +313 -0
  11. package/build/abi/quick-perps/vault-price-feed.json +323 -0
  12. package/build/abi/quick-perps/vault.json +1953 -0
  13. package/build/abi/quickPerps/fast-price-events.json +70 -0
  14. package/build/abi/quickPerps/fast-price-feed.json +748 -0
  15. package/build/abi/quickPerps/reader.json +313 -0
  16. package/build/abi/quickPerps/vault-price-feed.json +477 -0
  17. package/build/abi/quickPerps/vault.json +1953 -0
  18. package/build/abi/ramses-v2/RamsesV2Pool.abi.json +1599 -0
  19. package/build/abi/uniswap-v3/UniswapV3Factory.abi.json +148 -0
  20. package/build/abi/uniswap-v3/UniswapV3QuoterV2.abi.json +155 -0
  21. package/build/composed-event-subscriber.js +8 -2
  22. package/build/composed-event-subscriber.js.map +1 -1
  23. package/build/config.d.ts +0 -1
  24. package/build/config.js +75 -14
  25. package/build/config.js.map +1 -1
  26. package/build/constants.d.ts +2 -1
  27. package/build/constants.js +1 -0
  28. package/build/constants.js.map +1 -1
  29. package/build/dex/algebra/algebra-factory.d.ts +25 -0
  30. package/build/dex/algebra/algebra-factory.js +43 -0
  31. package/build/dex/algebra/algebra-factory.js.map +1 -0
  32. package/build/dex/algebra/algebra-pool-v1_1.d.ts +16 -2
  33. package/build/dex/algebra/algebra-pool-v1_1.js +166 -4
  34. package/build/dex/algebra/algebra-pool-v1_1.js.map +1 -1
  35. package/build/dex/algebra/algebra.d.ts +4 -1
  36. package/build/dex/algebra/algebra.js +42 -21
  37. package/build/dex/algebra/algebra.js.map +1 -1
  38. package/build/dex/algebra/config.js +1 -0
  39. package/build/dex/algebra/config.js.map +1 -1
  40. package/build/dex/algebra/lib/TickTable.js +51 -40
  41. package/build/dex/algebra/lib/TickTable.js.map +1 -1
  42. package/build/dex/algebra/types.d.ts +5 -2
  43. package/build/dex/algebra/utils.d.ts +3 -1
  44. package/build/dex/algebra/utils.js +59 -1
  45. package/build/dex/algebra/utils.js.map +1 -1
  46. package/build/dex/balancer-v2/balancer-v2.js +79 -6
  47. package/build/dex/balancer-v2/balancer-v2.js.map +1 -1
  48. package/build/dex/balancer-v2/config.js +10 -2
  49. package/build/dex/balancer-v2/config.js.map +1 -1
  50. package/build/dex/balancer-v2/optimizer.js +38 -51
  51. package/build/dex/balancer-v2/optimizer.js.map +1 -1
  52. package/build/dex/balancer-v2/types.d.ts +0 -4
  53. package/build/dex/balancer-v2/types.js.map +1 -1
  54. package/build/dex/curve-v1/config.js +40 -38
  55. package/build/dex/curve-v1/config.js.map +1 -1
  56. package/build/dex/curve-v1-factory/config.js +17 -9
  57. package/build/dex/curve-v1-factory/config.js.map +1 -1
  58. package/build/dex/curve-v1-factory/curve-v1-factory.d.ts +1 -1
  59. package/build/dex/curve-v1-factory/curve-v1-factory.js +205 -182
  60. package/build/dex/curve-v1-factory/curve-v1-factory.js.map +1 -1
  61. package/build/dex/curve-v1-factory/curve-v1-pool-manager.d.ts +2 -1
  62. package/build/dex/curve-v1-factory/curve-v1-pool-manager.js +8 -2
  63. package/build/dex/curve-v1-factory/curve-v1-pool-manager.js.map +1 -1
  64. package/build/dex/curve-v1-factory/price-handlers/functions/_calc_withdraw_one_coin.js +1 -0
  65. package/build/dex/curve-v1-factory/price-handlers/functions/_calc_withdraw_one_coin.js.map +1 -1
  66. package/build/dex/curve-v1-factory/price-handlers/functions/_dynamic_fee.js +1 -0
  67. package/build/dex/curve-v1-factory/price-handlers/functions/_dynamic_fee.js.map +1 -1
  68. package/build/dex/curve-v1-factory/price-handlers/functions/_rates.js +2 -1
  69. package/build/dex/curve-v1-factory/price-handlers/functions/_rates.js.map +1 -1
  70. package/build/dex/curve-v1-factory/price-handlers/functions/_xp.js +1 -0
  71. package/build/dex/curve-v1-factory/price-handlers/functions/_xp.js.map +1 -1
  72. package/build/dex/curve-v1-factory/price-handlers/functions/_xp_mem.js +1 -0
  73. package/build/dex/curve-v1-factory/price-handlers/functions/_xp_mem.js.map +1 -1
  74. package/build/dex/curve-v1-factory/price-handlers/functions/calc_token_amount.js +61 -14
  75. package/build/dex/curve-v1-factory/price-handlers/functions/calc_token_amount.js.map +1 -1
  76. package/build/dex/curve-v1-factory/price-handlers/functions/calc_withdraw_one_coin.js +1 -0
  77. package/build/dex/curve-v1-factory/price-handlers/functions/calc_withdraw_one_coin.js.map +1 -1
  78. package/build/dex/curve-v1-factory/price-handlers/functions/constants.js +10 -0
  79. package/build/dex/curve-v1-factory/price-handlers/functions/constants.js.map +1 -1
  80. package/build/dex/curve-v1-factory/price-handlers/functions/get_D.js +1 -0
  81. package/build/dex/curve-v1-factory/price-handlers/functions/get_D.js.map +1 -1
  82. package/build/dex/curve-v1-factory/price-handlers/functions/get_D_mem.js +1 -0
  83. package/build/dex/curve-v1-factory/price-handlers/functions/get_D_mem.js.map +1 -1
  84. package/build/dex/curve-v1-factory/price-handlers/functions/get_D_precisions.js +1 -0
  85. package/build/dex/curve-v1-factory/price-handlers/functions/get_D_precisions.js.map +1 -1
  86. package/build/dex/curve-v1-factory/price-handlers/functions/get_dy.js +1 -0
  87. package/build/dex/curve-v1-factory/price-handlers/functions/get_dy.js.map +1 -1
  88. package/build/dex/curve-v1-factory/price-handlers/functions/get_dy_underlying.js +1 -0
  89. package/build/dex/curve-v1-factory/price-handlers/functions/get_dy_underlying.js.map +1 -1
  90. package/build/dex/curve-v1-factory/price-handlers/functions/get_y.js +1 -0
  91. package/build/dex/curve-v1-factory/price-handlers/functions/get_y.js.map +1 -1
  92. package/build/dex/curve-v1-factory/price-handlers/functions/get_y_D.js +1 -0
  93. package/build/dex/curve-v1-factory/price-handlers/functions/get_y_D.js.map +1 -1
  94. package/build/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.js +11 -4
  95. package/build/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.js.map +1 -1
  96. package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.d.ts +1 -1
  97. package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.js +2 -2
  98. package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.js.map +1 -1
  99. package/build/dex/curve-v1-factory/types.d.ts +4 -1
  100. package/build/dex/curve-v1-factory/types.js +1 -0
  101. package/build/dex/curve-v1-factory/types.js.map +1 -1
  102. package/build/dex/generic-rfq/generic-rfq.d.ts +2 -1
  103. package/build/dex/generic-rfq/generic-rfq.js +9 -5
  104. package/build/dex/generic-rfq/generic-rfq.js.map +1 -1
  105. package/build/dex/generic-rfq/rate-fetcher.d.ts +1 -1
  106. package/build/dex/generic-rfq/rate-fetcher.js +2 -1
  107. package/build/dex/generic-rfq/rate-fetcher.js.map +1 -1
  108. package/build/dex/generic-rfq/types.d.ts +1 -0
  109. package/build/dex/generic-rfq/types.js.map +1 -1
  110. package/build/dex/hashflow/hashflow.d.ts +1 -0
  111. package/build/dex/hashflow/hashflow.js +1 -0
  112. package/build/dex/hashflow/hashflow.js.map +1 -1
  113. package/build/dex/idex.d.ts +1 -0
  114. package/build/dex/index.d.ts +1 -0
  115. package/build/dex/index.js +21 -0
  116. package/build/dex/index.js.map +1 -1
  117. package/build/dex/maverick-v1/config.js +9 -0
  118. package/build/dex/maverick-v1/config.js.map +1 -1
  119. package/build/dex/maverick-v1/maverick-v1.js +11 -2
  120. package/build/dex/maverick-v1/maverick-v1.js.map +1 -1
  121. package/build/dex/maverick-v1/scripts/event-sequence.d.ts +1 -0
  122. package/build/dex/maverick-v1/scripts/event-sequence.js +110 -0
  123. package/build/dex/maverick-v1/scripts/event-sequence.js.map +1 -0
  124. package/build/dex/pancakeswap-v3/config.js +17 -0
  125. package/build/dex/pancakeswap-v3/config.js.map +1 -1
  126. package/build/dex/pancakeswap-v3/pancakeswap-v3-factory.d.ts +26 -0
  127. package/build/dex/pancakeswap-v3/pancakeswap-v3-factory.js +44 -0
  128. package/build/dex/pancakeswap-v3/pancakeswap-v3-factory.js.map +1 -0
  129. package/build/dex/pancakeswap-v3/pancakeswap-v3.d.ts +3 -0
  130. package/build/dex/pancakeswap-v3/pancakeswap-v3.js +26 -2
  131. package/build/dex/pancakeswap-v3/pancakeswap-v3.js.map +1 -1
  132. package/build/dex/quick-perps/config.d.ts +11 -0
  133. package/build/dex/quick-perps/config.js +27 -0
  134. package/build/dex/quick-perps/config.js.map +1 -0
  135. package/build/dex/quick-perps/fast-price-feed.d.ts +26 -0
  136. package/build/dex/quick-perps/fast-price-feed.js +176 -0
  137. package/build/dex/quick-perps/fast-price-feed.js.map +1 -0
  138. package/build/dex/quick-perps/pool.d.ts +21 -0
  139. package/build/dex/quick-perps/pool.js +225 -0
  140. package/build/dex/quick-perps/pool.js.map +1 -0
  141. package/build/dex/quick-perps/quick-perps.d.ts +52 -0
  142. package/build/dex/quick-perps/quick-perps.js +211 -0
  143. package/build/dex/quick-perps/quick-perps.js.map +1 -0
  144. package/build/dex/quick-perps/types.d.ts +98 -0
  145. package/build/dex/quick-perps/types.js +3 -0
  146. package/build/dex/quick-perps/types.js.map +1 -0
  147. package/build/dex/quick-perps/usdq.d.ts +15 -0
  148. package/build/dex/quick-perps/usdq.js +61 -0
  149. package/build/dex/quick-perps/usdq.js.map +1 -0
  150. package/build/dex/quick-perps/vault-price-feed.d.ts +43 -0
  151. package/build/dex/quick-perps/vault-price-feed.js +194 -0
  152. package/build/dex/quick-perps/vault-price-feed.js.map +1 -0
  153. package/build/dex/quick-perps/vault-utils.d.ts +8 -0
  154. package/build/dex/quick-perps/vault-utils.js +41 -0
  155. package/build/dex/quick-perps/vault-utils.js.map +1 -0
  156. package/build/dex/quick-perps/vault.d.ts +46 -0
  157. package/build/dex/quick-perps/vault.js +166 -0
  158. package/build/dex/quick-perps/vault.js.map +1 -0
  159. package/build/dex/solidly/config.js +52 -2
  160. package/build/dex/solidly/config.js.map +1 -1
  161. package/build/dex/solidly/forks-override/aerodrome.d.ts +14 -0
  162. package/build/dex/solidly/forks-override/aerodrome.js +48 -0
  163. package/build/dex/solidly/forks-override/aerodrome.js.map +1 -0
  164. package/build/dex/solidly/forks-override/equalizer.d.ts +20 -0
  165. package/build/dex/solidly/forks-override/equalizer.js +46 -0
  166. package/build/dex/solidly/forks-override/equalizer.js.map +1 -0
  167. package/build/dex/solidly/forks-override/ramses.d.ts +44 -0
  168. package/build/dex/solidly/forks-override/ramses.js +144 -0
  169. package/build/dex/solidly/forks-override/ramses.js.map +1 -0
  170. package/build/dex/solidly/forks-override/velodromeV2.d.ts +20 -0
  171. package/build/dex/solidly/forks-override/velodromeV2.js +50 -0
  172. package/build/dex/solidly/forks-override/velodromeV2.js.map +1 -0
  173. package/build/dex/solidly/solidly.js +4 -0
  174. package/build/dex/solidly/solidly.js.map +1 -1
  175. package/build/dex/uniswap-v2/nomiswap-v2.d.ts +24 -0
  176. package/build/dex/uniswap-v2/nomiswap-v2.js +44 -0
  177. package/build/dex/uniswap-v2/nomiswap-v2.js.map +1 -0
  178. package/build/dex/uniswap-v3/config.js +166 -0
  179. package/build/dex/uniswap-v3/config.js.map +1 -1
  180. package/build/dex/uniswap-v3/forks/ramses-v2/ramses-v2-pool.d.ts +19 -0
  181. package/build/dex/uniswap-v3/forks/ramses-v2/ramses-v2-pool.js +99 -0
  182. package/build/dex/uniswap-v3/forks/ramses-v2/ramses-v2-pool.js.map +1 -0
  183. package/build/dex/uniswap-v3/forks/ramses-v2/utils.d.ts +4 -0
  184. package/build/dex/uniswap-v3/forks/ramses-v2/utils.js +63 -0
  185. package/build/dex/uniswap-v3/forks/ramses-v2/utils.js.map +1 -0
  186. package/build/dex/uniswap-v3/types.d.ts +10 -1
  187. package/build/dex/uniswap-v3/types.js.map +1 -1
  188. package/build/dex/uniswap-v3/uniswap-v3-factory.d.ts +26 -0
  189. package/build/dex/uniswap-v3/uniswap-v3-factory.js +44 -0
  190. package/build/dex/uniswap-v3/uniswap-v3-factory.js.map +1 -0
  191. package/build/dex/uniswap-v3/uniswap-v3-pool.d.ts +8 -6
  192. package/build/dex/uniswap-v3/uniswap-v3-pool.js +5 -2
  193. package/build/dex/uniswap-v3/uniswap-v3-pool.js.map +1 -1
  194. package/build/dex/uniswap-v3/uniswap-v3.d.ts +7 -4
  195. package/build/dex/uniswap-v3/uniswap-v3.js +51 -10
  196. package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
  197. package/build/dex/weth/config.js +3 -0
  198. package/build/dex/weth/config.js.map +1 -1
  199. package/build/dex/woo-fi-v2/config.js +13 -0
  200. package/build/dex/woo-fi-v2/config.js.map +1 -1
  201. package/build/dex-helper/dummy-dex-helper.js +7 -1
  202. package/build/dex-helper/dummy-dex-helper.js.map +1 -1
  203. package/build/dex-helper/icache.d.ts +1 -0
  204. package/build/lib/api3-feed.d.ts +30 -0
  205. package/build/lib/api3-feed.js +100 -0
  206. package/build/lib/api3-feed.js.map +1 -0
  207. package/build/lib/decoders.d.ts +3 -0
  208. package/build/lib/decoders.js +9 -1
  209. package/build/lib/decoders.js.map +1 -1
  210. package/build/stateful-event-subscriber.d.ts +1 -0
  211. package/build/stateful-event-subscriber.js +6 -0
  212. package/build/stateful-event-subscriber.js.map +1 -1
  213. package/build/types.d.ts +2 -0
  214. package/build/workers.d.ts +0 -0
  215. package/build/workers.js +2 -0
  216. package/build/workers.js.map +1 -0
  217. package/package.json +1 -1
  218. package/src/abi/RamsesV2Pool.abi.json +1554 -0
  219. package/src/abi/RamsesV2Quoter.abi.json +274 -0
  220. package/src/abi/RamsesV2StateMulticall.abi.json +891 -0
  221. package/src/abi/aerodrome/aerodrome-pool-factory.json +586 -0
  222. package/src/abi/algebra/AlgebraFactory-v1_1.abi.json +250 -0
  223. package/src/abi/api3-proxy.json +53 -0
  224. package/src/abi/api3-server-v1.json +463 -0
  225. package/src/abi/nomiswap-v2/nomiswap-v2-pool.json +773 -0
  226. package/src/abi/pancakeswap-v3/PancakeswapV3Factory.abi.json +300 -0
  227. package/src/abi/quick-perps/fast-price-events.json +70 -0
  228. package/src/abi/quick-perps/fast-price-feed.json +741 -0
  229. package/src/abi/quick-perps/reader.json +313 -0
  230. package/src/abi/quick-perps/vault-price-feed.json +323 -0
  231. package/src/abi/quick-perps/vault.json +1953 -0
  232. package/src/abi/ramses-v2/RamsesV2Pool.abi.json +1599 -0
  233. package/src/composed-event-subscriber.ts +16 -11
  234. package/src/config.ts +80 -14
  235. package/src/constants.ts +1 -0
  236. package/src/dex/algebra/algebra-factory.ts +70 -0
  237. package/src/dex/algebra/algebra-integration.test.ts +316 -16
  238. package/src/dex/algebra/algebra-pool-v1_1.ts +259 -8
  239. package/src/dex/algebra/algebra.ts +73 -22
  240. package/src/dex/algebra/config.ts +1 -0
  241. package/src/dex/algebra/lib/TickTable.ts +75 -74
  242. package/src/dex/algebra/types.ts +6 -2
  243. package/src/dex/algebra/utils.ts +83 -2
  244. package/src/dex/balancer-v2/balancer-v2-e2e.test.ts +133 -4
  245. package/src/dex/balancer-v2/balancer-v2.ts +87 -6
  246. package/src/dex/balancer-v2/config.ts +11 -2
  247. package/src/dex/balancer-v2/optimizer.ts +49 -62
  248. package/src/dex/balancer-v2/types.ts +0 -4
  249. package/src/dex/curve-v1/config.ts +40 -38
  250. package/src/dex/curve-v1-factory/config.ts +17 -9
  251. package/src/dex/curve-v1-factory/curve-v1-factory-e2e.test.ts +19 -0
  252. package/src/dex/curve-v1-factory/curve-v1-factory-integration.test.ts +165 -45
  253. package/src/dex/curve-v1-factory/curve-v1-factory.ts +477 -415
  254. package/src/dex/curve-v1-factory/curve-v1-pool-manager.ts +15 -2
  255. package/src/dex/curve-v1-factory/price-handlers/functions/_calc_withdraw_one_coin.ts +1 -0
  256. package/src/dex/curve-v1-factory/price-handlers/functions/_dynamic_fee.ts +1 -0
  257. package/src/dex/curve-v1-factory/price-handlers/functions/_rates.ts +2 -1
  258. package/src/dex/curve-v1-factory/price-handlers/functions/_xp.ts +1 -0
  259. package/src/dex/curve-v1-factory/price-handlers/functions/_xp_mem.ts +1 -0
  260. package/src/dex/curve-v1-factory/price-handlers/functions/calc_token_amount.ts +71 -13
  261. package/src/dex/curve-v1-factory/price-handlers/functions/calc_withdraw_one_coin.ts +1 -0
  262. package/src/dex/curve-v1-factory/price-handlers/functions/constants.ts +11 -0
  263. package/src/dex/curve-v1-factory/price-handlers/functions/get_D.ts +2 -0
  264. package/src/dex/curve-v1-factory/price-handlers/functions/get_D_mem.ts +1 -0
  265. package/src/dex/curve-v1-factory/price-handlers/functions/get_D_precisions.ts +1 -0
  266. package/src/dex/curve-v1-factory/price-handlers/functions/get_dy.ts +1 -0
  267. package/src/dex/curve-v1-factory/price-handlers/functions/get_dy_underlying.ts +1 -0
  268. package/src/dex/curve-v1-factory/price-handlers/functions/get_y.ts +1 -0
  269. package/src/dex/curve-v1-factory/price-handlers/functions/get_y_D.ts +1 -0
  270. package/src/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.ts +13 -5
  271. package/src/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.ts +2 -1
  272. package/src/dex/curve-v1-factory/types.ts +3 -1
  273. package/src/dex/generic-rfq/example-api.test.ts +1 -1
  274. package/src/dex/generic-rfq/generic-rfq.ts +12 -4
  275. package/src/dex/generic-rfq/rate-fetcher.ts +4 -2
  276. package/src/dex/generic-rfq/types.ts +1 -0
  277. package/src/dex/hashflow/hashflow-e2e.test.ts +36 -3
  278. package/src/dex/hashflow/hashflow.ts +2 -1
  279. package/src/dex/idex.ts +1 -0
  280. package/src/dex/index.ts +21 -0
  281. package/src/dex/maverick-v1/config.ts +10 -0
  282. package/src/dex/maverick-v1/maverick-v1-e2e.test.ts +115 -1
  283. package/src/dex/maverick-v1/maverick-v1.ts +12 -2
  284. package/src/dex/pancakeswap-v3/config.ts +19 -0
  285. package/src/dex/pancakeswap-v3/pancakeswap-v3-e2e.test.ts +114 -0
  286. package/src/dex/pancakeswap-v3/pancakeswap-v3-factory.ts +73 -0
  287. package/src/dex/pancakeswap-v3/pancakeswap-v3.ts +50 -2
  288. package/src/dex/quick-perps/config.ts +31 -0
  289. package/src/dex/quick-perps/fast-price-feed.ts +279 -0
  290. package/src/dex/quick-perps/pool.ts +407 -0
  291. package/src/dex/quick-perps/quick-perps-e2e.test.ts +65 -0
  292. package/src/dex/quick-perps/quick-perps-events.test.ts +100 -0
  293. package/src/dex/quick-perps/quick-perps-integration.test.ts +153 -0
  294. package/src/dex/quick-perps/quick-perps.ts +302 -0
  295. package/src/dex/quick-perps/types.ts +97 -0
  296. package/src/dex/quick-perps/usdq.ts +83 -0
  297. package/src/dex/quick-perps/vault-price-feed.ts +322 -0
  298. package/src/dex/quick-perps/vault-utils.ts +53 -0
  299. package/src/dex/quick-perps/vault.ts +290 -0
  300. package/src/dex/solidly/config.ts +58 -2
  301. package/src/dex/solidly/forks-override/aerodrome.ts +53 -0
  302. package/src/dex/solidly/forks-override/equalizer.ts +58 -0
  303. package/src/dex/solidly/forks-override/ramses.ts +253 -0
  304. package/src/dex/solidly/forks-override/velodromeV2.ts +63 -0
  305. package/src/dex/solidly/solidly-e2e.test.ts +313 -1
  306. package/src/dex/solidly/solidly-integration.test.ts +540 -41
  307. package/src/dex/solidly/solidly.ts +5 -0
  308. package/src/dex/uniswap-v2/nomiswap-v2.ts +63 -0
  309. package/src/dex/uniswap-v2/uniswap-v2-e2e-bsc.test.ts +120 -1
  310. package/src/dex/uniswap-v3/config.ts +174 -0
  311. package/src/dex/uniswap-v3/forks/ramses-v2/ramses-v2-pool.ts +156 -0
  312. package/src/dex/uniswap-v3/forks/ramses-v2/utils.ts +72 -0
  313. package/src/dex/uniswap-v3/types.ts +14 -1
  314. package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +1071 -346
  315. package/src/dex/uniswap-v3/uniswap-v3-factory.ts +73 -0
  316. package/src/dex/uniswap-v3/uniswap-v3-integration.test.ts +787 -14
  317. package/src/dex/uniswap-v3/uniswap-v3-pool.ts +13 -5
  318. package/src/dex/uniswap-v3/uniswap-v3.ts +87 -20
  319. package/src/dex/weth/config.ts +3 -0
  320. package/src/dex/woo-fi-v2/config.ts +13 -0
  321. package/src/dex/woo-fi-v2/woo-fi-v2-e2e.test.ts +64 -0
  322. package/src/dex-helper/dummy-dex-helper.ts +8 -1
  323. package/src/dex-helper/icache.ts +2 -0
  324. package/src/lib/api3-feed.ts +175 -0
  325. package/src/lib/decoders.ts +13 -0
  326. package/src/stateful-event-subscriber.ts +8 -0
  327. package/src/types.ts +2 -0
  328. package/tests/constants-e2e.ts +102 -6
  329. package/tests/tenderly-simulation.ts +48 -4
  330. package/tests/utils-e2e.ts +21 -11
@@ -66,12 +66,16 @@ export class Solidly extends UniswapV2 {
66
66
  getDexKeysWithNetwork(
67
67
  _.omit(SolidlyConfig, [
68
68
  'Velodrome',
69
+ 'VelodromeV2',
69
70
  'SpiritSwapV2',
70
71
  'Cone',
71
72
  'SolidlyV2',
72
73
  'Thena',
73
74
  'SoliSnek',
74
75
  'Chronos',
76
+ 'Ramses',
77
+ 'Equalizer',
78
+ 'Aerodrome',
75
79
  ]),
76
80
  );
77
81
 
@@ -520,6 +524,7 @@ export class Solidly extends UniswapV2 {
520
524
  const pair = await this.findSolidlyPair(from, to, stable);
521
525
  if (!(pair && pair.pool && pair.exchange)) return null;
522
526
  const pairState = pair.pool.getState(blockNumber);
527
+
523
528
  if (!pairState) {
524
529
  this.logger.error(
525
530
  `Error_orderPairParams expected reserves, got none (maybe the pool doesn't exist) ${
@@ -0,0 +1,63 @@
1
+ import { Network } from '../../constants';
2
+ import { getDexKeysWithNetwork } from '../../utils';
3
+ import { IDexHelper } from '../../dex-helper/idex-helper';
4
+ import { UniswapV2, UniswapV2Pair } from '../uniswap-v2/uniswap-v2';
5
+ import { Interface } from '@ethersproject/abi';
6
+ import NomiswapPoolABI from '../../abi/nomiswap-v2/nomiswap-v2-pool.json';
7
+ import { DexParams } from './types';
8
+ import { DexConfigMap } from '../../types';
9
+
10
+ export const NomiswapV2Config: DexConfigMap<DexParams> = {
11
+ NomiswapV2: {
12
+ [Network.BSC]: {
13
+ factoryAddress: '0xd6715A8be3944ec72738F0BFDC739d48C3c29349',
14
+ initCode:
15
+ '0x83eb759f5ea0525124f03d4ac741bb4af0bb1c703d5f694bd42a8bd72e495a01',
16
+ poolGasCost: 120 * 1000,
17
+ feeCode: 0, // this is ignored as Nomiswap uses dynamic fees,
18
+ subgraphURL:
19
+ 'https://api.thegraph.com/subgraphs/name/nominex/nomiswap-exchange-subgraph',
20
+ },
21
+ },
22
+ };
23
+
24
+ export class NomiswapV2 extends UniswapV2 {
25
+ nomiswapPool: Interface;
26
+
27
+ public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
28
+ getDexKeysWithNetwork(NomiswapV2Config);
29
+
30
+ constructor(
31
+ protected network: Network,
32
+ dexKey: string,
33
+ protected dexHelper: IDexHelper,
34
+ ) {
35
+ super(
36
+ network,
37
+ dexKey,
38
+ dexHelper,
39
+ true,
40
+ NomiswapV2Config[dexKey][network].factoryAddress,
41
+ NomiswapV2Config[dexKey][network].subgraphURL,
42
+ NomiswapV2Config[dexKey][network].initCode,
43
+ NomiswapV2Config[dexKey][network].feeCode,
44
+ NomiswapV2Config[dexKey][network].poolGasCost,
45
+ );
46
+ this.nomiswapPool = new Interface(NomiswapPoolABI);
47
+ }
48
+
49
+ protected getFeesMultiCallData(pair: UniswapV2Pair) {
50
+ const callEntry = {
51
+ target: pair.exchange!,
52
+ callData: this.nomiswapPool.encodeFunctionData('swapFee', []),
53
+ };
54
+ const callDecoder = (values: any[]) =>
55
+ parseInt(
56
+ this.nomiswapPool.decodeFunctionResult('swapFee', values)[0].toString(),
57
+ ) * 10;
58
+ return {
59
+ callEntry,
60
+ callDecoder,
61
+ };
62
+ }
63
+ }
@@ -2,11 +2,108 @@ import dotenv from 'dotenv';
2
2
  dotenv.config();
3
3
 
4
4
  import { testE2E } from '../../../tests/utils-e2e';
5
- import { Tokens, Holders } from '../../../tests/constants-e2e';
5
+ import {
6
+ Tokens,
7
+ Holders,
8
+ NativeTokenSymbols,
9
+ } from '../../../tests/constants-e2e';
6
10
  import { Network, ContractMethod, SwapSide } from '../../constants';
7
11
  import { StaticJsonRpcProvider } from '@ethersproject/providers';
8
12
  import { generateConfig } from '../../config';
9
13
 
14
+ function testForNetwork(
15
+ network: Network,
16
+ dexKey: string,
17
+ tokenASymbol: string,
18
+ tokenBSymbol: string,
19
+ tokenAAmount: string,
20
+ tokenBAmount: string,
21
+ nativeTokenAmount: string,
22
+ slippage?: number | undefined,
23
+ ) {
24
+ const provider = new StaticJsonRpcProvider(
25
+ generateConfig(network).privateHttpProvider,
26
+ network,
27
+ );
28
+ const tokens = Tokens[network];
29
+ const holders = Holders[network];
30
+ const nativeTokenSymbol = NativeTokenSymbols[network];
31
+
32
+ const sideToContractMethods = new Map([
33
+ [
34
+ SwapSide.SELL,
35
+ [
36
+ ContractMethod.simpleSwap,
37
+ ContractMethod.multiSwap,
38
+ ContractMethod.megaSwap,
39
+ ],
40
+ ],
41
+ [SwapSide.BUY, [ContractMethod.simpleBuy, ContractMethod.buy]],
42
+ ]);
43
+
44
+ describe(`${network}`, () => {
45
+ sideToContractMethods.forEach((contractMethods, side) =>
46
+ describe(`${side}`, () => {
47
+ contractMethods.forEach((contractMethod: ContractMethod) => {
48
+ describe(`${contractMethod}`, () => {
49
+ it(`${nativeTokenSymbol} -> ${tokenASymbol}`, async () => {
50
+ await testE2E(
51
+ tokens[nativeTokenSymbol],
52
+ tokens[tokenASymbol],
53
+ holders[nativeTokenSymbol],
54
+ side === SwapSide.SELL ? nativeTokenAmount : tokenAAmount,
55
+ side,
56
+ dexKey,
57
+ contractMethod,
58
+ network,
59
+ provider,
60
+ undefined,
61
+ undefined,
62
+ undefined,
63
+ slippage,
64
+ );
65
+ });
66
+ it(`${tokenASymbol} -> ${nativeTokenSymbol}`, async () => {
67
+ await testE2E(
68
+ tokens[tokenASymbol],
69
+ tokens[nativeTokenSymbol],
70
+ holders[tokenASymbol],
71
+ side === SwapSide.SELL ? tokenAAmount : nativeTokenAmount,
72
+ side,
73
+ dexKey,
74
+ contractMethod,
75
+ network,
76
+ provider,
77
+ undefined,
78
+ undefined,
79
+ undefined,
80
+ slippage,
81
+ );
82
+ });
83
+ it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => {
84
+ await testE2E(
85
+ tokens[tokenASymbol],
86
+ tokens[tokenBSymbol],
87
+ holders[tokenASymbol],
88
+ side === SwapSide.SELL ? tokenAAmount : tokenBAmount,
89
+ side,
90
+ dexKey,
91
+ contractMethod,
92
+ network,
93
+ provider,
94
+ undefined,
95
+ undefined,
96
+ undefined,
97
+ slippage,
98
+ );
99
+ });
100
+ });
101
+ });
102
+ }),
103
+ );
104
+ });
105
+ }
106
+
10
107
  describe('UniswapV2 E2E BSC', () => {
11
108
  const network = Network.BSC;
12
109
  const tokens = Tokens[network];
@@ -1407,6 +1504,28 @@ describe('UniswapV2 E2E BSC', () => {
1407
1504
  });
1408
1505
  });
1409
1506
 
1507
+ describe('NomiswapV2', () => {
1508
+ const dexKey = 'NomiswapV2';
1509
+ const network = Network.BSC;
1510
+
1511
+ const tokenASymbol: string = 'USDC';
1512
+ const tokenBSymbol: string = 'USDT';
1513
+
1514
+ const tokenAAmount: string = '1111100000';
1515
+ const tokenBAmount: string = '1000000000';
1516
+ const nativeTokenAmount = '11000000000000';
1517
+
1518
+ testForNetwork(
1519
+ network,
1520
+ dexKey,
1521
+ tokenASymbol,
1522
+ tokenBSymbol,
1523
+ tokenAAmount,
1524
+ tokenBAmount,
1525
+ nativeTokenAmount,
1526
+ );
1527
+ });
1528
+
1410
1529
  describe(`Swapsicle`, () => {
1411
1530
  const dexKey = 'Swapsicle';
1412
1531
 
@@ -2,6 +2,10 @@ import { DexParams } from './types';
2
2
  import { DexConfigMap, AdapterMappings } from '../../types';
3
3
  import { Network, SwapSide } from '../../constants';
4
4
  import { Address } from '../../types';
5
+ import RamsesV2StateMulticallABI from '../../abi/RamsesV2StateMulticall.abi.json';
6
+ import { AbiItem } from 'web3-utils';
7
+ import { decodeStateMultiCallResultWithRelativeBitmaps } from './forks/ramses-v2/utils';
8
+ import { RamsesV2EventPool } from './forks/ramses-v2/ramses-v2-pool';
5
9
 
6
10
  const SUPPORTED_FEES = [10000n, 3000n, 500n, 100n];
7
11
 
@@ -103,6 +107,158 @@ export const UniswapV3Config: DexConfigMap<DexParams> = {
103
107
  subgraphURL:
104
108
  'https://api.thegraph.com/subgraphs/name/lynnshaoyu/uniswap-v3-avax',
105
109
  },
110
+ [Network.BASE]: {
111
+ factory: '0x33128a8fC17869897dcE68Ed026d694621f6FDfD',
112
+ quoter: '0x3d4e44Eb1374240CE5F1B871ab261CD16335B76a',
113
+ router: '0xaeE2b8d4A154e36f479dAeCe3FB3e6c3c03d396E',
114
+ supportedFees: SUPPORTED_FEES,
115
+ stateMulticall: '0x7160f736c52e1e78e92FD4eE4D73e21A7Cf4F950',
116
+ uniswapMulticall: '0x091e99cb1C49331a94dD62755D168E941AbD0693',
117
+ chunksCount: 10,
118
+ initRetryFrequency: 10,
119
+ initHash: `0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54`,
120
+ subgraphURL:
121
+ 'https://api.studio.thegraph.com/query/48211/uniswap-v3-base/version/latest',
122
+ },
123
+ },
124
+ SushiSwapV3: {
125
+ [Network.MAINNET]: {
126
+ factory: '0xbACEB8eC6b9355Dfc0269C18bac9d6E2Bdc29C4F',
127
+ quoter: '0x64e8802FE490fa7cc61d3463958199161Bb608A7',
128
+ router: '0x00F23572b16c5e9e58e7b965DEF51Ff8Ff546E34',
129
+ supportedFees: SUPPORTED_FEES,
130
+ stateMulticall: '0x9c764D2e92dA68E4CDfD784B902283A095ff8b63',
131
+ uniswapMulticall: '0x1F98415757620B543A52E61c46B32eB19261F984',
132
+ chunksCount: 10,
133
+ initRetryFrequency: 10,
134
+ initHash: `0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54`,
135
+ subgraphURL:
136
+ 'https://api.thegraph.com/subgraphs/name/sushi-v3/v3-ethereum',
137
+ },
138
+ [Network.POLYGON]: {
139
+ factory: '0x917933899c6a5f8e37f31e19f92cdbff7e8ff0e2',
140
+ quoter: '0xb1E835Dc2785b52265711e17fCCb0fd018226a6e',
141
+ router: '0x34D41cE301257a4615D4F5AD260FA91D03925243',
142
+ supportedFees: SUPPORTED_FEES,
143
+ stateMulticall: '0x6Dc993Fe1e945A640576B4Dca81281d8e998DF71',
144
+ uniswapMulticall: '0x1F98415757620B543A52E61c46B32eB19261F984',
145
+ chunksCount: 10,
146
+ initRetryFrequency: 10,
147
+ initHash: `0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54`,
148
+ subgraphURL:
149
+ 'https://api.thegraph.com/subgraphs/name/sushi-v3/v3-polygon',
150
+ },
151
+ [Network.BSC]: {
152
+ factory: '0x126555dd55a39328F69400d6aE4F782Bd4C34ABb',
153
+ quoter: '0xb1E835Dc2785b52265711e17fCCb0fd018226a6e',
154
+ router: '0xDCf4EE5B700e2a5Fec458e06B763A4a3E3004494',
155
+ supportedFees: SUPPORTED_FEES,
156
+ stateMulticall: '0x593F39A4Ba26A9c8ed2128ac95D109E8e403C485',
157
+ uniswapMulticall: '0x963Df249eD09c358A4819E39d9Cd5736c3087184',
158
+ chunksCount: 10,
159
+ initRetryFrequency: 10,
160
+ initHash: `0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54`,
161
+ subgraphURL: 'https://api.thegraph.com/subgraphs/name/sushi-v3/v3-bsc',
162
+ },
163
+ [Network.AVALANCHE]: {
164
+ factory: '0x3e603C14aF37EBdaD31709C4f848Fc6aD5BEc715',
165
+ quoter: '0xb1E835Dc2785b52265711e17fCCb0fd018226a6e',
166
+ router: '0x24c90C7d8fb463722e304A71255341610Fa7589b',
167
+ supportedFees: SUPPORTED_FEES,
168
+ stateMulticall: '0x30F6B9b6485ff0B67E881f5ac80D3F1c70A4B23d',
169
+ uniswapMulticall: '0x8C0F842791F03C095b6c633759224FcC9ACe68ea',
170
+ chunksCount: 10,
171
+ initRetryFrequency: 10,
172
+ initHash: `0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54`,
173
+ subgraphURL:
174
+ 'https://api.thegraph.com/subgraphs/name/sushi-v3/v3-avalanche',
175
+ },
176
+ [Network.FANTOM]: {
177
+ factory: '0x7770978eED668a3ba661d51a773d3a992Fc9DDCB',
178
+ quoter: '0xb1E835Dc2785b52265711e17fCCb0fd018226a6e',
179
+ router: '0xDCf4EE5B700e2a5Fec458e06B763A4a3E3004494',
180
+ supportedFees: SUPPORTED_FEES,
181
+ stateMulticall: '0x30F6B9b6485ff0B67E881f5ac80D3F1c70A4B23d',
182
+ uniswapMulticall: '0xB1395e098c0a847CC719Bcf1Fc8114421a9F8232',
183
+ chunksCount: 10,
184
+ initRetryFrequency: 10,
185
+ initHash: `0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54`,
186
+ subgraphURL: 'https://api.thegraph.com/subgraphs/name/sushi-v3/v3-fantom',
187
+ },
188
+ [Network.ARBITRUM]: {
189
+ factory: '0x1af415a1eba07a4986a52b6f2e7de7003d82231e',
190
+ quoter: '0x0524E833cCD057e4d7A296e3aaAb9f7675964Ce1',
191
+ router: '0xbDa4176fD98b47018aF673805d069b9dbd49373D',
192
+ supportedFees: SUPPORTED_FEES,
193
+ stateMulticall: '0xaBB58098A7B5172A9b0B38a1925A522dbf0b4FC3',
194
+ uniswapMulticall: '0x1F98415757620B543A52E61c46B32eB19261F984',
195
+ chunksCount: 10,
196
+ initRetryFrequency: 10,
197
+ initHash: `0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54`,
198
+ subgraphURL:
199
+ 'https://api.thegraph.com/subgraphs/name/sushi-v3/v3-arbitrum',
200
+ },
201
+ [Network.OPTIMISM]: {
202
+ factory: '0x9c6522117e2ed1fE5bdb72bb0eD5E3f2bdE7DBe0',
203
+ quoter: '0xb1E835Dc2785b52265711e17fCCb0fd018226a6e',
204
+ router: '0xa05d8C3F278fC7b20b39Ea7A3035E3aD8D808c78',
205
+ supportedFees: SUPPORTED_FEES,
206
+ stateMulticall: '0x4FF0dEC5f9a763Aa1E5C2a962aa6f4eDFeE4f9eA',
207
+ uniswapMulticall: '0x1F98415757620B543A52E61c46B32eB19261F984',
208
+ chunksCount: 10,
209
+ initRetryFrequency: 10,
210
+ initHash: `0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54`,
211
+ subgraphURL:
212
+ 'https://api.thegraph.com/subgraphs/name/sushi-v3/v3-optimism',
213
+ },
214
+ [Network.BASE]: {
215
+ factory: '0xc35DADB65012eC5796536bD9864eD8773aBc74C4',
216
+ quoter: '0xb1E835Dc2785b52265711e17fCCb0fd018226a6e',
217
+ router: '0xCc0e85901f33D375FcdD9a888B05Df9616F68277',
218
+ supportedFees: SUPPORTED_FEES,
219
+ stateMulticall: '0x7160f736c52e1e78e92FD4eE4D73e21A7Cf4F950',
220
+ uniswapMulticall: '0x091e99cb1C49331a94dD62755D168E941AbD0693',
221
+ chunksCount: 10,
222
+ initRetryFrequency: 10,
223
+ initHash: `0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54`,
224
+ subgraphURL: 'https://api.studio.thegraph.com/query/32073/v3-base/v0.0.1',
225
+ },
226
+ },
227
+ ChronosV3: {
228
+ [Network.ARBITRUM]: {
229
+ factory: '0x4Db9D624F67E00dbF8ef7AE0e0e8eE54aF1dee49',
230
+ quoter: '0x6E7f0Ca45171a4440c0CDdF3A46A8dC5D4c2d4A0',
231
+ router: '0xE0aBdFD837D451640CF43cB1Ec4eE87976eFbb41',
232
+ supportedFees: SUPPORTED_FEES,
233
+ stateMulticall: '0x46b44eb4Cc3bEbB9f04C419f691aB85Ff885A4D6',
234
+ uniswapMulticall: '0xaBB58098A7B5172A9b0B38a1925A522dbf0b4FC3',
235
+ chunksCount: 10,
236
+ initRetryFrequency: 10,
237
+ initHash:
238
+ '0x09c178be473df44d1de6970978a4fdedce1ce52a23b2b979754547f6b43a19a5',
239
+ subgraphURL:
240
+ 'https://subgraph.chronos.exchange/subgraphs/name/chronos-v3',
241
+ },
242
+ },
243
+ RamsesV2: {
244
+ [Network.ARBITRUM]: {
245
+ factory: '0xAA2cd7477c451E703f3B9Ba5663334914763edF8',
246
+ deployer: '0xb3e423ab9cE6C03D98326A3A2a0D7D96b0829f22',
247
+ quoter: '0xAA20EFF7ad2F523590dE6c04918DaAE0904E3b20',
248
+ router: '0xAA23611badAFB62D37E7295A682D21960ac85A90',
249
+ supportedFees: [...SUPPORTED_FEES, 50n],
250
+ stateMulticall: '0x50EE4112Cab9c79812F23bE079aB3911395ACc8e',
251
+ stateMultiCallAbi: RamsesV2StateMulticallABI as AbiItem[],
252
+ uniswapMulticall: '0x1F98415757620B543A52E61c46B32eB19261F984',
253
+ chunksCount: 10,
254
+ initRetryFrequency: 10,
255
+ eventPoolImplementation: RamsesV2EventPool,
256
+ decodeStateMultiCallResultWithRelativeBitmaps,
257
+ initHash:
258
+ '0x1565b129f2d1790f12d45301b9b084335626f0c92410bc43130763b69971135d',
259
+ subgraphURL:
260
+ 'https://api.thegraph.com/subgraphs/name/ramsesexchange/concentrated-liquidity-graph',
261
+ },
106
262
  },
107
263
  'QuickSwapV3.1': {
108
264
  [Network.ZKEVM]: {
@@ -119,6 +275,20 @@ export const UniswapV3Config: DexConfigMap<DexParams> = {
119
275
  'https://api.studio.thegraph.com/query/44554/uniswap-v3/version/latest',
120
276
  },
121
277
  },
278
+ Retro: {
279
+ [Network.POLYGON]: {
280
+ factory: '0x91e1B99072f238352f59e58de875691e20Dc19c1',
281
+ quoter: '0xfe08be075758935cb6cb9318d1fbb60920416d4e',
282
+ router: '0x1891783cb3497Fdad1F25C933225243c2c7c4102',
283
+ supportedFees: SUPPORTED_FEES,
284
+ stateMulticall: '0x6Dc993Fe1e945A640576B4Dca81281d8e998DF71',
285
+ uniswapMulticall: '0x1F98415757620B543A52E61c46B32eB19261F984',
286
+ chunksCount: 10,
287
+ initRetryFrequency: 10,
288
+ initHash: `0x817e07951f93017a93327ac8cc31e946540203a19e1ecc37bc1761965c2d1090`,
289
+ subgraphURL: 'https://api.thegraph.com/subgraphs/name/ruvlol/univ3-test',
290
+ },
291
+ },
122
292
  };
123
293
 
124
294
  export const Adapters: Record<number, AdapterMappings> = {
@@ -154,4 +324,8 @@ export const Adapters: Record<number, AdapterMappings> = {
154
324
  [SwapSide.SELL]: [{ name: 'AvalancheAdapter02', index: 5 }],
155
325
  [SwapSide.BUY]: [{ name: 'AvalancheBuyAdapter', index: 6 }],
156
326
  },
327
+ [Network.BASE]: {
328
+ [SwapSide.SELL]: [{ name: 'BaseAdapter01', index: 1 }],
329
+ [SwapSide.BUY]: [{ name: 'BaseBuyAdapter', index: 1 }],
330
+ },
157
331
  };
@@ -0,0 +1,156 @@
1
+ import { UniswapV3EventPool } from '../../uniswap-v3-pool';
2
+ import {
3
+ DecodedStateMultiCallResultWithRelativeBitmaps,
4
+ DecodeStateMultiCallFunc,
5
+ PoolState,
6
+ } from '../../types';
7
+ import { assert } from 'ts-essentials';
8
+ import { _reduceTickBitmap, _reduceTicks } from '../../contract-math/utils';
9
+ import { bigIntify } from '../../../../utils';
10
+ import { TickBitMap } from '../../contract-math/TickBitMap';
11
+ import { uint24ToBigInt } from '../../../../lib/decoders';
12
+ import { Interface } from 'ethers/lib/utils';
13
+ import RamsesV2PoolABI from '../../../../abi/ramses-v2/RamsesV2Pool.abi.json';
14
+ import { IDexHelper } from '../../../../dex-helper';
15
+ import { Contract } from 'web3-eth-contract';
16
+ import { Address, Logger } from '../../../../types';
17
+
18
+ export class RamsesV2EventPool extends UniswapV3EventPool {
19
+ public readonly poolIface = new Interface(RamsesV2PoolABI);
20
+
21
+ constructor(
22
+ readonly dexHelper: IDexHelper,
23
+ parentName: string,
24
+ readonly stateMultiContract: Contract,
25
+ readonly decodeStateMultiCallResultWithRelativeBitmaps:
26
+ | DecodeStateMultiCallFunc
27
+ | undefined,
28
+ readonly erc20Interface: Interface,
29
+ protected readonly factoryAddress: Address,
30
+ public feeCode: bigint,
31
+ token0: Address,
32
+ token1: Address,
33
+ logger: Logger,
34
+ mapKey: string = '',
35
+ readonly poolInitCodeHash: string,
36
+ ) {
37
+ super(
38
+ dexHelper,
39
+ parentName,
40
+ stateMultiContract,
41
+ decodeStateMultiCallResultWithRelativeBitmaps,
42
+ erc20Interface,
43
+ factoryAddress,
44
+ feeCode,
45
+ token0,
46
+ token1,
47
+ logger,
48
+ mapKey,
49
+ poolInitCodeHash,
50
+ );
51
+
52
+ this.handlers['FeeAdjustment'] = this.handleFeeAdjustmentEvent.bind(this);
53
+ }
54
+
55
+ handleFeeAdjustmentEvent(event: any, pool: PoolState): PoolState {
56
+ const newFee = bigIntify(event.args.newFee);
57
+
58
+ pool.fee = newFee;
59
+
60
+ return pool;
61
+ }
62
+
63
+ async generateState(blockNumber: number): Promise<Readonly<PoolState>> {
64
+ const callData = this._getStateRequestCallData();
65
+
66
+ const calldataWithFee = [
67
+ ...callData,
68
+ {
69
+ target: this.poolAddress,
70
+ callData: this.poolIface.encodeFunctionData('currentFee'),
71
+ decodeFunction: uint24ToBigInt,
72
+ },
73
+ ];
74
+
75
+ this._stateRequestCallData = calldataWithFee;
76
+
77
+ const [resBalance0, resBalance1, resState, resCurrentFee] =
78
+ await this.dexHelper.multiWrapper.tryAggregate<
79
+ bigint | DecodedStateMultiCallResultWithRelativeBitmaps
80
+ >(
81
+ false,
82
+ calldataWithFee,
83
+ blockNumber,
84
+ this.dexHelper.multiWrapper.defaultBatchSize,
85
+ false,
86
+ );
87
+
88
+ assert(resState.success, 'Pool does not exist');
89
+
90
+ const [balance0, balance1, _state, fee] = [
91
+ resBalance0.returnData,
92
+ resBalance1.returnData,
93
+ resState.returnData,
94
+ resCurrentFee.returnData,
95
+ ] as [
96
+ bigint,
97
+ bigint,
98
+ DecodedStateMultiCallResultWithRelativeBitmaps,
99
+ bigint,
100
+ ];
101
+
102
+ const tickBitmap = {};
103
+ const ticks = {};
104
+
105
+ _reduceTickBitmap(tickBitmap, _state.tickBitmap);
106
+ _reduceTicks(ticks, _state.ticks);
107
+
108
+ const observations = {
109
+ [_state.slot0.observationIndex]: {
110
+ blockTimestamp: bigIntify(_state.observation.blockTimestamp),
111
+ tickCumulative: bigIntify(_state.observation.tickCumulative),
112
+ secondsPerLiquidityCumulativeX128: bigIntify(
113
+ _state.observation.secondsPerLiquidityCumulativeX128,
114
+ ),
115
+ initialized: _state.observation.initialized,
116
+ },
117
+ };
118
+
119
+ const currentTick = bigIntify(_state.slot0.tick);
120
+ const tickSpacing = bigIntify(_state.tickSpacing);
121
+
122
+ const startTickBitmap = TickBitMap.position(currentTick / tickSpacing)[0];
123
+ const requestedRange = this.getBitmapRangeToRequest();
124
+
125
+ return {
126
+ pool: _state.pool,
127
+ blockTimestamp: bigIntify(_state.blockTimestamp),
128
+ slot0: {
129
+ sqrtPriceX96: bigIntify(_state.slot0.sqrtPriceX96),
130
+ tick: currentTick,
131
+ observationIndex: +_state.slot0.observationIndex,
132
+ observationCardinality: +_state.slot0.observationCardinality,
133
+ observationCardinalityNext: +_state.slot0.observationCardinalityNext,
134
+ feeProtocol: bigIntify(_state.slot0.feeProtocol),
135
+ },
136
+ liquidity: bigIntify(_state.liquidity),
137
+ fee,
138
+ tickSpacing,
139
+ maxLiquidityPerTick: bigIntify(_state.maxLiquidityPerTick),
140
+ tickBitmap,
141
+ ticks,
142
+ observations,
143
+ isValid: true,
144
+ startTickBitmap,
145
+ lowestKnownTick:
146
+ (BigInt.asIntN(24, startTickBitmap - requestedRange) << 8n) *
147
+ tickSpacing,
148
+ highestKnownTick:
149
+ ((BigInt.asIntN(24, startTickBitmap + requestedRange) << 8n) +
150
+ BigInt.asIntN(24, 255n)) *
151
+ tickSpacing,
152
+ balance0,
153
+ balance1,
154
+ };
155
+ }
156
+ }
@@ -0,0 +1,72 @@
1
+ import { MultiResult } from '../../../../lib/multi-wrapper';
2
+ import { BytesLike, ethers } from 'ethers';
3
+ import { DecodedStateMultiCallResultWithRelativeBitmaps } from '../../types';
4
+ import { extractSuccessAndValue } from '../../../../lib/decoders';
5
+ import { assert } from 'ts-essentials';
6
+
7
+ export function decodeStateMultiCallResultWithRelativeBitmaps(
8
+ result: MultiResult<BytesLike> | BytesLike,
9
+ ): DecodedStateMultiCallResultWithRelativeBitmaps {
10
+ const [isSuccess, toDecode] = extractSuccessAndValue(result);
11
+
12
+ assert(
13
+ isSuccess && toDecode !== '0x',
14
+ `decodeStateMultiCallResultWithRelativeBitmaps failed to get decodable result: ${result}`,
15
+ );
16
+
17
+ const decoded = ethers.utils.defaultAbiCoder.decode(
18
+ [
19
+ // I don't want to pass here any interface, so I just use it in ethers format
20
+ `
21
+ tuple(
22
+ address pool,
23
+ uint256 blockTimestamp,
24
+ tuple(
25
+ uint160 sqrtPriceX96,
26
+ int24 tick,
27
+ uint16 observationIndex,
28
+ uint16 observationCardinality,
29
+ uint16 observationCardinalityNext,
30
+ uint8 feeProtocol,
31
+ bool unlocked,
32
+ ) slot0,
33
+ uint128 liquidity,
34
+ int24 tickSpacing,
35
+ uint128 maxLiquidityPerTick,
36
+ tuple(
37
+ uint32 blockTimestamp,
38
+ int56 tickCumulative,
39
+ uint160 secondsPerLiquidityCumulativeX128,
40
+ bool initialized,
41
+ uint160 secondsPerBoostedLiquidityPeriodX128,
42
+ uint32 boostedInRange,
43
+ ) observation,
44
+ tuple(
45
+ int16 index,
46
+ uint256 value
47
+ )[] tickBitmap,
48
+ tuple(
49
+ int24 index,
50
+ tuple(
51
+ uint128 liquidityGross,
52
+ int128 liquidityNet,
53
+ uint128 cleanUnusedSlot,
54
+ uint128 cleanUnusedSlot2,
55
+ uint256 feeGrowthOutside0X128,
56
+ uint256 feeGrowthOutside1X128,
57
+ int56 tickCumulativeOutside,
58
+ uint160 secondsPerLiquidityOutsideX128,
59
+ uint32 secondsOutside,
60
+ bool initialized,
61
+ ) value,
62
+ )[] ticks
63
+ )
64
+ `,
65
+ ],
66
+ toDecode,
67
+ )[0];
68
+
69
+ // This conversion is not precise, because when we decode, we have more values
70
+ // But I typed only the ones that are used later
71
+ return decoded as DecodedStateMultiCallResultWithRelativeBitmaps;
72
+ }
@@ -1,6 +1,9 @@
1
- import { BigNumber } from 'ethers';
1
+ import { BigNumber, BytesLike } from 'ethers';
2
2
  import { NumberAsString } from '../../types';
3
3
  import { Address } from '../../types';
4
+ import { AbiItem } from 'web3-utils';
5
+ import { MultiResult } from '../../lib/multi-wrapper';
6
+ import { UniswapV3EventPool } from './uniswap-v3-pool';
4
7
 
5
8
  export type OracleObservation = {
6
9
  blockTimestamp: bigint;
@@ -51,15 +54,22 @@ export type PoolState = {
51
54
  balance1: bigint;
52
55
  };
53
56
 
57
+ export type FactoryState = Record<string, never>;
58
+
54
59
  export type UniswapV3Data = {
55
60
  path: {
56
61
  tokenIn: Address;
57
62
  tokenOut: Address;
58
63
  fee: NumberAsString;
64
+ currentFee?: NumberAsString;
59
65
  }[];
60
66
  isApproved?: boolean;
61
67
  };
62
68
 
69
+ export type DecodeStateMultiCallFunc = (
70
+ result: MultiResult<BytesLike> | BytesLike,
71
+ ) => DecodedStateMultiCallResultWithRelativeBitmaps;
72
+
63
73
  export type DexParams = {
64
74
  router: Address;
65
75
  quoter: Address;
@@ -72,6 +82,9 @@ export type DexParams = {
72
82
  deployer?: Address;
73
83
  subgraphURL: string;
74
84
  initHash: string;
85
+ stateMultiCallAbi?: AbiItem[];
86
+ eventPoolImplementation?: typeof UniswapV3EventPool;
87
+ decodeStateMultiCallResultWithRelativeBitmaps?: DecodeStateMultiCallFunc;
75
88
  };
76
89
 
77
90
  export type UniswapV3SimpleSwapSellParam = {