@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
@@ -3,13 +3,13 @@ import dotenv from 'dotenv';
3
3
  dotenv.config();
4
4
 
5
5
  import { Interface, Result } from '@ethersproject/abi';
6
- import { DummyDexHelper } from '../../dex-helper/index';
6
+ import { DummyDexHelper, IDexHelper } from '../../dex-helper/index';
7
7
  import { Network, SwapSide } from '../../constants';
8
8
  import { BI_POWS } from '../../bigint-constants';
9
9
  import { UniswapV3 } from './uniswap-v3';
10
10
  import { checkPoolPrices, checkPoolsLiquidity } from '../../../tests/utils';
11
11
  import { Tokens } from '../../../tests/constants-e2e';
12
- import UniswapV3QuoterABI from '../../abi/uniswap-v3/UniswapV3Quoter.abi.json';
12
+ import UniswapV3QuoterV2ABI from '../../abi/uniswap-v3/UniswapV3QuoterV2.abi.json';
13
13
  import { Address } from '@paraswap/core';
14
14
 
15
15
  const network = Network.POLYGON;
@@ -28,10 +28,7 @@ const amounts = [
28
28
 
29
29
  const amountsBuy = [0n, 1n * BI_POWS[18], 2n * BI_POWS[18], 3n * BI_POWS[18]];
30
30
 
31
- const dexHelper = new DummyDexHelper(network);
32
- const dexKey = 'UniswapV3';
33
-
34
- const quoterIface = new Interface(UniswapV3QuoterABI);
31
+ const quoterIface = new Interface(UniswapV3QuoterV2ABI);
35
32
 
36
33
  function getReaderCalldata(
37
34
  exchangeAddress: string,
@@ -45,11 +42,7 @@ function getReaderCalldata(
45
42
  return amounts.map(amount => ({
46
43
  target: exchangeAddress,
47
44
  callData: readerIface.encodeFunctionData(funcName, [
48
- tokenIn,
49
- tokenOut,
50
- fee,
51
- amount,
52
- 0n,
45
+ [tokenIn, tokenOut, amount.toString(), fee.toString(), 0],
53
46
  ]),
54
47
  }));
55
48
  }
@@ -66,9 +59,11 @@ function decodeReaderResult(
66
59
  }
67
60
 
68
61
  async function checkOnChainPricing(
62
+ dexHelper: IDexHelper,
69
63
  uniswapV3: UniswapV3,
70
64
  funcName: string,
71
65
  blockNumber: number,
66
+ exchangeAddress: string,
72
67
  prices: bigint[],
73
68
  tokenIn: Address,
74
69
  tokenOut: Address,
@@ -76,7 +71,7 @@ async function checkOnChainPricing(
76
71
  _amounts: bigint[],
77
72
  ) {
78
73
  // Quoter address
79
- const exchangeAddress = '0xb27308f9F90D607463bb33eA1BeBb41C27CE5AB6';
74
+ // const exchangeAddress = '0xb27308f9F90D607463bb33eA1BeBb41C27CE5AB6';
80
75
  const readerIface = quoterIface;
81
76
 
82
77
  const sum = prices.reduce((acc, curr) => (acc += curr), 0n);
@@ -117,6 +112,8 @@ async function checkOnChainPricing(
117
112
  decodeReaderResult(readerResult, readerIface, funcName),
118
113
  );
119
114
 
115
+ console.log('EXPECTED PRICES: ', expectedPrices);
116
+
120
117
  let firstZeroIndex = prices.slice(1).indexOf(0n);
121
118
 
122
119
  // we skipped first, so add +1 on result
@@ -130,6 +127,9 @@ async function checkOnChainPricing(
130
127
  }
131
128
 
132
129
  describe('UniswapV3', function () {
130
+ const dexHelper = new DummyDexHelper(network);
131
+ const dexKey = 'UniswapV3';
132
+
133
133
  let blockNumber: number;
134
134
  let uniswapV3: UniswapV3;
135
135
  let uniswapV3Mainnet: UniswapV3;
@@ -138,9 +138,9 @@ describe('UniswapV3', function () {
138
138
  blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
139
139
  uniswapV3 = new UniswapV3(network, dexKey, dexHelper);
140
140
  uniswapV3Mainnet = new UniswapV3(
141
- Network.MAINNET,
141
+ Network.ARBITRUM,
142
142
  dexKey,
143
- new DummyDexHelper(Network.MAINNET),
143
+ new DummyDexHelper(Network.ARBITRUM),
144
144
  );
145
145
  });
146
146
 
@@ -173,9 +173,11 @@ describe('UniswapV3', function () {
173
173
  poolPrices!.map(async price => {
174
174
  const fee = uniswapV3.eventPools[price.poolIdentifier!]!.feeCode;
175
175
  const res = await checkOnChainPricing(
176
+ dexHelper,
176
177
  uniswapV3,
177
178
  'quoteExactInputSingle',
178
179
  blockNumber,
180
+ '0x61fFE014bA17989E743c5F6cB21bF9697530B21e',
179
181
  price.prices,
180
182
  TokenA.address,
181
183
  TokenB.address,
@@ -219,9 +221,11 @@ describe('UniswapV3', function () {
219
221
  poolPrices!.map(async price => {
220
222
  const fee = uniswapV3.eventPools[price.poolIdentifier!]!.feeCode;
221
223
  const res = await checkOnChainPricing(
224
+ dexHelper,
222
225
  uniswapV3,
223
226
  'quoteExactOutputSingle',
224
227
  blockNumber,
228
+ '0x61fFE014bA17989E743c5F6cB21bF9697530B21e',
225
229
  price.prices,
226
230
  TokenA.address,
227
231
  TokenB.address,
@@ -329,9 +333,11 @@ describe('UniswapV3', function () {
329
333
  poolPrices!.map(async price => {
330
334
  const fee = uniswapV3.eventPools[price.poolIdentifier!]!.feeCode;
331
335
  const res = await checkOnChainPricing(
336
+ dexHelper,
332
337
  uniswapV3,
333
338
  'quoteExactInputSingle',
334
339
  blockNumber,
340
+ '0x61fFE014bA17989E743c5F6cB21bF9697530B21e',
335
341
  price.prices,
336
342
  TokenA.address,
337
343
  TokenB.address,
@@ -439,9 +445,11 @@ describe('UniswapV3', function () {
439
445
  poolPrices!.map(async price => {
440
446
  const fee = uniswapV3.eventPools[price.poolIdentifier!]!.feeCode;
441
447
  const res = await checkOnChainPricing(
448
+ dexHelper,
442
449
  uniswapV3,
443
450
  'quoteExactOutputSingle',
444
451
  blockNumber,
452
+ '0x61fFE014bA17989E743c5F6cB21bF9697530B21e',
445
453
  price.prices,
446
454
  TokenA.address,
447
455
  TokenB.address,
@@ -466,3 +474,768 @@ describe('UniswapV3', function () {
466
474
  }
467
475
  });
468
476
  });
477
+
478
+ describe('RamsesV2', () => {
479
+ const dexKey = 'RamsesV2';
480
+ let blockNumber: number;
481
+ let uniswapV3: UniswapV3;
482
+ let uniswapV3Mainnet: UniswapV3;
483
+
484
+ const network = Network.ARBITRUM;
485
+ const dexHelper = new DummyDexHelper(network);
486
+ const TokenASymbol = 'USDCe';
487
+ const TokenA = Tokens[network][TokenASymbol];
488
+
489
+ const TokenBSymbol = 'USDC';
490
+ const TokenB = Tokens[network][TokenBSymbol];
491
+
492
+ beforeEach(async () => {
493
+ blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
494
+ uniswapV3 = new UniswapV3(network, dexKey, dexHelper);
495
+ uniswapV3Mainnet = new UniswapV3(Network.ARBITRUM, dexKey, dexHelper);
496
+ });
497
+
498
+ it('getPoolIdentifiers and getPricesVolume SELL', async function () {
499
+ const amounts = [
500
+ 0n,
501
+ 6000000n,
502
+ 12000000n,
503
+ 18000000n,
504
+ 24000000n,
505
+ 30000000n,
506
+ 36000000n,
507
+ 42000000n,
508
+ ];
509
+
510
+ const pools = await uniswapV3.getPoolIdentifiers(
511
+ TokenA,
512
+ TokenB,
513
+ SwapSide.SELL,
514
+ blockNumber,
515
+ );
516
+ console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `, pools);
517
+
518
+ expect(pools.length).toBeGreaterThan(0);
519
+
520
+ const poolPrices = await uniswapV3.getPricesVolume(
521
+ TokenA,
522
+ TokenB,
523
+ amounts,
524
+ SwapSide.SELL,
525
+ blockNumber,
526
+ pools,
527
+ );
528
+ console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `, poolPrices);
529
+
530
+ expect(poolPrices).not.toBeNull();
531
+ checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
532
+
533
+ let falseChecksCounter = 0;
534
+ await Promise.all(
535
+ poolPrices!.map(async price => {
536
+ const fee = uniswapV3.eventPools[price.poolIdentifier!]!.feeCode;
537
+ const res = await checkOnChainPricing(
538
+ dexHelper,
539
+ uniswapV3,
540
+ 'quoteExactInputSingle',
541
+ blockNumber,
542
+ '0xAA20EFF7ad2F523590dE6c04918DaAE0904E3b20',
543
+ price.prices,
544
+ TokenA.address,
545
+ TokenB.address,
546
+ fee,
547
+ amounts,
548
+ );
549
+ if (res === false) falseChecksCounter++;
550
+ }),
551
+ );
552
+
553
+ expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
554
+ });
555
+
556
+ it('getPoolIdentifiers and getPricesVolume BUY', async function () {
557
+ const amounts = [
558
+ 0n,
559
+ 6000000n,
560
+ 12000000n,
561
+ 18000000n,
562
+ 24000000n,
563
+ 30000000n,
564
+ 36000000n,
565
+ 42000000n,
566
+ ];
567
+
568
+ const pools = await uniswapV3.getPoolIdentifiers(
569
+ TokenA,
570
+ TokenB,
571
+ SwapSide.BUY,
572
+ blockNumber,
573
+ );
574
+ console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `, pools);
575
+
576
+ expect(pools.length).toBeGreaterThan(0);
577
+
578
+ const poolPrices = await uniswapV3.getPricesVolume(
579
+ TokenA,
580
+ TokenB,
581
+ amounts,
582
+ SwapSide.BUY,
583
+ blockNumber,
584
+ pools,
585
+ );
586
+ console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `, poolPrices);
587
+
588
+ expect(poolPrices).not.toBeNull();
589
+ checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
590
+
591
+ let falseChecksCounter = 0;
592
+ await Promise.all(
593
+ poolPrices!.map(async price => {
594
+ const fee = uniswapV3.eventPools[price.poolIdentifier!]!.feeCode;
595
+ const res = await checkOnChainPricing(
596
+ dexHelper,
597
+ uniswapV3,
598
+ 'quoteExactOutputSingle',
599
+ blockNumber,
600
+ '0xAA20EFF7ad2F523590dE6c04918DaAE0904E3b20',
601
+ price.prices,
602
+ TokenA.address,
603
+ TokenB.address,
604
+ fee,
605
+ amounts,
606
+ );
607
+ if (res === false) falseChecksCounter++;
608
+ }),
609
+ );
610
+
611
+ expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
612
+ });
613
+ });
614
+
615
+ describe('ChronosV3', () => {
616
+ const dexKey = 'ChronosV3';
617
+ let blockNumber: number;
618
+ let uniswapV3: UniswapV3;
619
+ let uniswapV3Mainnet: UniswapV3;
620
+
621
+ const network = Network.ARBITRUM;
622
+ const dexHelper = new DummyDexHelper(network);
623
+ const TokenASymbol = 'USDCe';
624
+ const TokenA = Tokens[network][TokenASymbol];
625
+
626
+ const TokenBSymbol = 'USDT';
627
+ const TokenB = Tokens[network][TokenBSymbol];
628
+
629
+ beforeEach(async () => {
630
+ blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
631
+ uniswapV3 = new UniswapV3(network, dexKey, dexHelper);
632
+ uniswapV3Mainnet = new UniswapV3(Network.ARBITRUM, dexKey, dexHelper);
633
+ });
634
+
635
+ it('getPoolIdentifiers and getPricesVolume SELL', async function () {
636
+ const amounts = [0n, BI_POWS[6], 2000000n];
637
+
638
+ const pools = await uniswapV3.getPoolIdentifiers(
639
+ TokenA,
640
+ TokenB,
641
+ SwapSide.SELL,
642
+ blockNumber,
643
+ );
644
+ console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `, pools);
645
+
646
+ expect(pools.length).toBeGreaterThan(0);
647
+
648
+ const poolPrices = await uniswapV3.getPricesVolume(
649
+ TokenA,
650
+ TokenB,
651
+ amounts,
652
+ SwapSide.SELL,
653
+ blockNumber,
654
+ pools,
655
+ );
656
+ console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `, poolPrices);
657
+
658
+ expect(poolPrices).not.toBeNull();
659
+ checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
660
+
661
+ let falseChecksCounter = 0;
662
+ await Promise.all(
663
+ poolPrices!.map(async price => {
664
+ const fee = uniswapV3.eventPools[price.poolIdentifier!]!.feeCode;
665
+ const res = await checkOnChainPricing(
666
+ dexHelper,
667
+ uniswapV3,
668
+ 'quoteExactInputSingle',
669
+ blockNumber,
670
+ '0x6E7f0Ca45171a4440c0CDdF3A46A8dC5D4c2d4A0',
671
+ price.prices,
672
+ TokenA.address,
673
+ TokenB.address,
674
+ fee,
675
+ amounts,
676
+ );
677
+ if (res === false) falseChecksCounter++;
678
+ }),
679
+ );
680
+
681
+ expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
682
+ });
683
+
684
+ it('getPoolIdentifiers and getPricesVolume BUY', async function () {
685
+ const amounts = [0n, BI_POWS[6], 2000000n];
686
+
687
+ const pools = await uniswapV3.getPoolIdentifiers(
688
+ TokenA,
689
+ TokenB,
690
+ SwapSide.BUY,
691
+ blockNumber,
692
+ );
693
+ console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `, pools);
694
+
695
+ expect(pools.length).toBeGreaterThan(0);
696
+
697
+ const poolPrices = await uniswapV3.getPricesVolume(
698
+ TokenA,
699
+ TokenB,
700
+ amounts,
701
+ SwapSide.BUY,
702
+ blockNumber,
703
+ pools,
704
+ );
705
+ console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `, poolPrices);
706
+
707
+ expect(poolPrices).not.toBeNull();
708
+ checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
709
+
710
+ let falseChecksCounter = 0;
711
+ await Promise.all(
712
+ poolPrices!.map(async price => {
713
+ const fee = uniswapV3.eventPools[price.poolIdentifier!]!.feeCode;
714
+ const res = await checkOnChainPricing(
715
+ dexHelper,
716
+ uniswapV3,
717
+ 'quoteExactOutputSingle',
718
+ blockNumber,
719
+ '0x6E7f0Ca45171a4440c0CDdF3A46A8dC5D4c2d4A0',
720
+ price.prices,
721
+ TokenA.address,
722
+ TokenB.address,
723
+ fee,
724
+ amounts,
725
+ );
726
+ if (res === false) falseChecksCounter++;
727
+ }),
728
+ );
729
+
730
+ expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
731
+ });
732
+
733
+ it.skip('getTopPoolsForToken', async function () {
734
+ const poolLiquidity = await uniswapV3.getTopPoolsForToken(
735
+ TokenB.address,
736
+ 10,
737
+ );
738
+ console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
739
+
740
+ checkPoolsLiquidity(poolLiquidity, TokenB.address, dexKey);
741
+ });
742
+ });
743
+
744
+ describe('SushiSwapV3', () => {
745
+ const dexKey = 'SushiSwapV3';
746
+
747
+ describe('Mainnet', () => {
748
+ let blockNumber: number;
749
+ let sushiSwapV3: UniswapV3;
750
+ let sushiSwapV3Mainnet: UniswapV3;
751
+
752
+ const network = Network.MAINNET;
753
+ const dexHelper = new DummyDexHelper(network);
754
+ const TokenASymbol = 'USDC';
755
+ const TokenA = Tokens[network][TokenASymbol];
756
+
757
+ const TokenBSymbol = 'USDT';
758
+ const TokenB = Tokens[network][TokenBSymbol];
759
+
760
+ beforeEach(async () => {
761
+ blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
762
+ sushiSwapV3 = new UniswapV3(network, dexKey, dexHelper);
763
+ sushiSwapV3Mainnet = new UniswapV3(Network.MAINNET, dexKey, dexHelper);
764
+ });
765
+
766
+ it('getPoolIdentifiers and getPricesVolume SELL', async function () {
767
+ const amounts = [0n, BI_POWS[6], 2000000n];
768
+
769
+ const pools = await sushiSwapV3.getPoolIdentifiers(
770
+ TokenA,
771
+ TokenB,
772
+ SwapSide.SELL,
773
+ blockNumber,
774
+ );
775
+ console.log(
776
+ `${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
777
+ pools,
778
+ );
779
+
780
+ expect(pools.length).toBeGreaterThan(0);
781
+
782
+ const poolPrices = await sushiSwapV3.getPricesVolume(
783
+ TokenA,
784
+ TokenB,
785
+ amounts,
786
+ SwapSide.SELL,
787
+ blockNumber,
788
+ pools,
789
+ );
790
+ console.log(
791
+ `${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
792
+ poolPrices,
793
+ );
794
+
795
+ expect(poolPrices).not.toBeNull();
796
+ checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
797
+
798
+ let falseChecksCounter = 0;
799
+ await Promise.all(
800
+ poolPrices!.map(async price => {
801
+ const fee = sushiSwapV3.eventPools[price.poolIdentifier!]!.feeCode;
802
+ const res = await checkOnChainPricing(
803
+ dexHelper,
804
+ sushiSwapV3,
805
+ 'quoteExactInputSingle',
806
+ blockNumber,
807
+ '0x64e8802FE490fa7cc61d3463958199161Bb608A7',
808
+ price.prices,
809
+ TokenA.address,
810
+ TokenB.address,
811
+ fee,
812
+ amounts,
813
+ );
814
+ if (res === false) falseChecksCounter++;
815
+ }),
816
+ );
817
+
818
+ expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
819
+ });
820
+
821
+ it('getPoolIdentifiers and getPricesVolume BUY', async function () {
822
+ const amounts = [0n, BI_POWS[6], 2000000n];
823
+
824
+ const pools = await sushiSwapV3.getPoolIdentifiers(
825
+ TokenA,
826
+ TokenB,
827
+ SwapSide.BUY,
828
+ blockNumber,
829
+ );
830
+ console.log(
831
+ `${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
832
+ pools,
833
+ );
834
+
835
+ expect(pools.length).toBeGreaterThan(0);
836
+
837
+ const poolPrices = await sushiSwapV3.getPricesVolume(
838
+ TokenA,
839
+ TokenB,
840
+ amounts,
841
+ SwapSide.BUY,
842
+ blockNumber,
843
+ pools,
844
+ );
845
+ console.log(
846
+ `${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
847
+ poolPrices,
848
+ );
849
+
850
+ expect(poolPrices).not.toBeNull();
851
+ checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
852
+
853
+ let falseChecksCounter = 0;
854
+ await Promise.all(
855
+ poolPrices!.map(async price => {
856
+ const fee = sushiSwapV3.eventPools[price.poolIdentifier!]!.feeCode;
857
+ const res = await checkOnChainPricing(
858
+ dexHelper,
859
+ sushiSwapV3,
860
+ 'quoteExactOutputSingle',
861
+ blockNumber,
862
+ '0x64e8802FE490fa7cc61d3463958199161Bb608A7',
863
+ price.prices,
864
+ TokenA.address,
865
+ TokenB.address,
866
+ fee,
867
+ amounts,
868
+ );
869
+ if (res === false) falseChecksCounter++;
870
+ }),
871
+ );
872
+
873
+ expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
874
+ });
875
+
876
+ it('getTopPoolsForToken', async function () {
877
+ const poolLiquidity = await sushiSwapV3.getTopPoolsForToken(
878
+ TokenB.address,
879
+ 10,
880
+ );
881
+ console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
882
+
883
+ checkPoolsLiquidity(poolLiquidity, TokenB.address, dexKey);
884
+ });
885
+ });
886
+
887
+ describe('Arbitrum', () => {
888
+ let blockNumber: number;
889
+ let sushiSwapV3: UniswapV3;
890
+ let sushiSwapV3Mainnet: UniswapV3;
891
+
892
+ const network = Network.ARBITRUM;
893
+ const dexHelper = new DummyDexHelper(network);
894
+ const TokenASymbol = 'USDCe';
895
+ const TokenA = Tokens[network][TokenASymbol];
896
+
897
+ const TokenBSymbol = 'USDT';
898
+ const TokenB = Tokens[network][TokenBSymbol];
899
+
900
+ beforeEach(async () => {
901
+ // blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
902
+ blockNumber = 125789437;
903
+ sushiSwapV3 = new UniswapV3(network, dexKey, dexHelper);
904
+ sushiSwapV3Mainnet = new UniswapV3(Network.ARBITRUM, dexKey, dexHelper);
905
+ });
906
+
907
+ it('getPoolIdentifiers and getPricesVolume BUY', async function () {
908
+ const amounts = [0n, 100000000n, 200000000n];
909
+
910
+ const pools = await sushiSwapV3.getPoolIdentifiers(
911
+ TokenA,
912
+ TokenB,
913
+ SwapSide.BUY,
914
+ blockNumber,
915
+ );
916
+ console.log(
917
+ `${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
918
+ pools,
919
+ );
920
+
921
+ expect(pools.length).toBeGreaterThan(0);
922
+
923
+ const poolPrices = await sushiSwapV3.getPricesVolume(
924
+ TokenA,
925
+ TokenB,
926
+ amounts,
927
+ SwapSide.BUY,
928
+ blockNumber,
929
+ pools,
930
+ );
931
+ console.log(
932
+ `${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
933
+ poolPrices,
934
+ );
935
+
936
+ expect(poolPrices).not.toBeNull();
937
+ checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
938
+
939
+ let falseChecksCounter = 0;
940
+ await Promise.all(
941
+ poolPrices!.map(async price => {
942
+ const fee = sushiSwapV3.eventPools[price.poolIdentifier!]!.feeCode;
943
+ const res = await checkOnChainPricing(
944
+ dexHelper,
945
+ sushiSwapV3,
946
+ 'quoteExactOutputSingle',
947
+ blockNumber,
948
+ '0x0524E833cCD057e4d7A296e3aaAb9f7675964Ce1',
949
+ price.prices,
950
+ TokenA.address,
951
+ TokenB.address,
952
+ fee,
953
+ amounts,
954
+ );
955
+ if (res === false) falseChecksCounter++;
956
+ }),
957
+ );
958
+
959
+ expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
960
+ });
961
+ });
962
+
963
+ describe('Base', () => {
964
+ let blockNumber: number;
965
+ let sushiSwapV3: UniswapV3;
966
+ let sushiSwapV3Mainnet: UniswapV3;
967
+
968
+ const network = Network.BASE;
969
+ const dexHelper = new DummyDexHelper(network);
970
+ const TokenASymbol = 'USDbC';
971
+ const TokenA = Tokens[network][TokenASymbol];
972
+
973
+ const TokenBSymbol = 'DAI';
974
+ const TokenB = Tokens[network][TokenBSymbol];
975
+
976
+ beforeEach(async () => {
977
+ blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
978
+ sushiSwapV3 = new UniswapV3(network, dexKey, dexHelper);
979
+ sushiSwapV3Mainnet = new UniswapV3(Network.MAINNET, dexKey, dexHelper);
980
+ });
981
+
982
+ it('getPoolIdentifiers and getPricesVolume SELL', async function () {
983
+ const amounts = [0n, BI_POWS[6], 2000000n];
984
+
985
+ const pools = await sushiSwapV3.getPoolIdentifiers(
986
+ TokenA,
987
+ TokenB,
988
+ SwapSide.SELL,
989
+ blockNumber,
990
+ );
991
+ console.log(
992
+ `${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
993
+ pools,
994
+ );
995
+
996
+ expect(pools.length).toBeGreaterThan(0);
997
+
998
+ const poolPrices = await sushiSwapV3.getPricesVolume(
999
+ TokenA,
1000
+ TokenB,
1001
+ amounts,
1002
+ SwapSide.SELL,
1003
+ blockNumber,
1004
+ pools,
1005
+ );
1006
+ console.log(
1007
+ `${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
1008
+ poolPrices,
1009
+ );
1010
+
1011
+ expect(poolPrices).not.toBeNull();
1012
+ checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
1013
+
1014
+ let falseChecksCounter = 0;
1015
+ await Promise.all(
1016
+ poolPrices!.map(async price => {
1017
+ const fee = sushiSwapV3.eventPools[price.poolIdentifier!]!.feeCode;
1018
+ const res = await checkOnChainPricing(
1019
+ dexHelper,
1020
+ sushiSwapV3,
1021
+ 'quoteExactInputSingle',
1022
+ blockNumber,
1023
+ '0xb1E835Dc2785b52265711e17fCCb0fd018226a6e',
1024
+ price.prices,
1025
+ TokenA.address,
1026
+ TokenB.address,
1027
+ fee,
1028
+ amounts,
1029
+ );
1030
+ if (res === false) falseChecksCounter++;
1031
+ }),
1032
+ );
1033
+
1034
+ expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
1035
+ });
1036
+
1037
+ it('getPoolIdentifiers and getPricesVolume BUY', async function () {
1038
+ const amounts = [0n, BI_POWS[6], 2000000n];
1039
+
1040
+ const pools = await sushiSwapV3.getPoolIdentifiers(
1041
+ TokenA,
1042
+ TokenB,
1043
+ SwapSide.BUY,
1044
+ blockNumber,
1045
+ );
1046
+ console.log(
1047
+ `${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
1048
+ pools,
1049
+ );
1050
+
1051
+ expect(pools.length).toBeGreaterThan(0);
1052
+
1053
+ const poolPrices = await sushiSwapV3.getPricesVolume(
1054
+ TokenA,
1055
+ TokenB,
1056
+ amounts,
1057
+ SwapSide.BUY,
1058
+ blockNumber,
1059
+ pools,
1060
+ );
1061
+ console.log(
1062
+ `${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
1063
+ poolPrices,
1064
+ );
1065
+
1066
+ expect(poolPrices).not.toBeNull();
1067
+ checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
1068
+
1069
+ let falseChecksCounter = 0;
1070
+ await Promise.all(
1071
+ poolPrices!.map(async price => {
1072
+ const fee = sushiSwapV3.eventPools[price.poolIdentifier!]!.feeCode;
1073
+ const res = await checkOnChainPricing(
1074
+ dexHelper,
1075
+ sushiSwapV3,
1076
+ 'quoteExactOutputSingle',
1077
+ blockNumber,
1078
+ '0xb1E835Dc2785b52265711e17fCCb0fd018226a6e',
1079
+ price.prices,
1080
+ TokenA.address,
1081
+ TokenB.address,
1082
+ fee,
1083
+ amounts,
1084
+ );
1085
+ if (res === false) falseChecksCounter++;
1086
+ }),
1087
+ );
1088
+
1089
+ expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
1090
+ });
1091
+
1092
+ it('getTopPoolsForToken', async function () {
1093
+ const poolLiquidity = await sushiSwapV3.getTopPoolsForToken(
1094
+ TokenB.address,
1095
+ 10,
1096
+ );
1097
+ console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
1098
+
1099
+ checkPoolsLiquidity(poolLiquidity, TokenB.address, dexKey);
1100
+ });
1101
+ });
1102
+ });
1103
+
1104
+ describe('Retro', () => {
1105
+ const dexKey = 'Retro';
1106
+
1107
+ describe('Polygon', () => {
1108
+ let blockNumber: number;
1109
+ let retro: UniswapV3;
1110
+
1111
+ const network = Network.POLYGON;
1112
+ const dexHelper = new DummyDexHelper(network);
1113
+ const TokenASymbol = 'USDC';
1114
+ const TokenA = Tokens[network][TokenASymbol];
1115
+
1116
+ const TokenBSymbol = 'USDT';
1117
+ const TokenB = Tokens[network][TokenBSymbol];
1118
+
1119
+ beforeEach(async () => {
1120
+ blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
1121
+ retro = new UniswapV3(network, dexKey, dexHelper);
1122
+ });
1123
+
1124
+ it('getPoolIdentifiers and getPricesVolume SELL', async function () {
1125
+ const amounts = [0n, BI_POWS[6], 2000000n];
1126
+
1127
+ const pools = await retro.getPoolIdentifiers(
1128
+ TokenA,
1129
+ TokenB,
1130
+ SwapSide.SELL,
1131
+ blockNumber,
1132
+ );
1133
+ console.log(
1134
+ `${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
1135
+ pools,
1136
+ );
1137
+
1138
+ expect(pools.length).toBeGreaterThan(0);
1139
+
1140
+ const poolPrices = await retro.getPricesVolume(
1141
+ TokenA,
1142
+ TokenB,
1143
+ amounts,
1144
+ SwapSide.SELL,
1145
+ blockNumber,
1146
+ pools,
1147
+ );
1148
+ console.log(
1149
+ `${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
1150
+ poolPrices,
1151
+ );
1152
+
1153
+ expect(poolPrices).not.toBeNull();
1154
+ checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
1155
+
1156
+ let falseChecksCounter = 0;
1157
+ await Promise.all(
1158
+ poolPrices!.map(async price => {
1159
+ const fee = retro.eventPools[price.poolIdentifier!]!.feeCode;
1160
+ const res = await checkOnChainPricing(
1161
+ dexHelper,
1162
+ retro,
1163
+ 'quoteExactInputSingle',
1164
+ blockNumber,
1165
+ '0xfe08be075758935cb6cb9318d1fbb60920416d4e',
1166
+ price.prices,
1167
+ TokenA.address,
1168
+ TokenB.address,
1169
+ fee,
1170
+ amounts,
1171
+ );
1172
+ if (res === false) falseChecksCounter++;
1173
+ }),
1174
+ );
1175
+
1176
+ expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
1177
+ });
1178
+
1179
+ it('getPoolIdentifiers and getPricesVolume BUY', async function () {
1180
+ const amounts = [0n, BI_POWS[6], 2000000n];
1181
+
1182
+ const pools = await retro.getPoolIdentifiers(
1183
+ TokenA,
1184
+ TokenB,
1185
+ SwapSide.BUY,
1186
+ blockNumber,
1187
+ );
1188
+ console.log(
1189
+ `${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
1190
+ pools,
1191
+ );
1192
+
1193
+ expect(pools.length).toBeGreaterThan(0);
1194
+
1195
+ const poolPrices = await retro.getPricesVolume(
1196
+ TokenA,
1197
+ TokenB,
1198
+ amounts,
1199
+ SwapSide.BUY,
1200
+ blockNumber,
1201
+ pools,
1202
+ );
1203
+ console.log(
1204
+ `${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
1205
+ poolPrices,
1206
+ );
1207
+
1208
+ expect(poolPrices).not.toBeNull();
1209
+ checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
1210
+
1211
+ let falseChecksCounter = 0;
1212
+ await Promise.all(
1213
+ poolPrices!.map(async price => {
1214
+ const fee = retro.eventPools[price.poolIdentifier!]!.feeCode;
1215
+ const res = await checkOnChainPricing(
1216
+ dexHelper,
1217
+ retro,
1218
+ 'quoteExactOutputSingle',
1219
+ blockNumber,
1220
+ '0xfe08be075758935cb6cb9318d1fbb60920416d4e',
1221
+ price.prices,
1222
+ TokenA.address,
1223
+ TokenB.address,
1224
+ fee,
1225
+ amounts,
1226
+ );
1227
+ if (res === false) falseChecksCounter++;
1228
+ }),
1229
+ );
1230
+
1231
+ expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
1232
+ });
1233
+
1234
+ it('getTopPoolsForToken', async function () {
1235
+ const poolLiquidity = await retro.getTopPoolsForToken(TokenB.address, 10);
1236
+ console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
1237
+
1238
+ checkPoolsLiquidity(poolLiquidity, TokenB.address, dexKey);
1239
+ });
1240
+ });
1241
+ });