@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
@@ -0,0 +1,253 @@
1
+ import { Network, SUBGRAPH_TIMEOUT } from '../../../constants';
2
+ import { getDexKeysWithNetwork } from '../../../utils';
3
+ import { SolidlyConfig } from '../config';
4
+ import _ from 'lodash';
5
+ import { Address, PoolLiquidity } from '../../../types';
6
+ import BigNumber from 'bignumber.js';
7
+ import { Solidly } from '../solidly';
8
+ import { IDexHelper } from '../../../dex-helper';
9
+ import { SolidlyPair } from '../types';
10
+ import { Interface } from '@ethersproject/abi';
11
+
12
+ const RamsesFactoryABI = [
13
+ {
14
+ inputs: [{ internalType: 'address', name: '', type: 'address' }],
15
+ name: 'pairFee',
16
+ outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
17
+ stateMutability: 'view',
18
+ type: 'function',
19
+ },
20
+ ];
21
+
22
+ const ramsesFactoryIface = new Interface(RamsesFactoryABI);
23
+
24
+ export type RamsesSubgraphPool = {
25
+ id: string;
26
+ isStable: boolean;
27
+ token0: string;
28
+ reserve0: string;
29
+ reserve1: string;
30
+ token1: string;
31
+ };
32
+
33
+ export type RamsesSubgraphToken = {
34
+ id: string;
35
+ decimals: string;
36
+ };
37
+
38
+ export class Ramses extends Solidly {
39
+ public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
40
+ getDexKeysWithNetwork(_.pick(SolidlyConfig, ['Ramses']));
41
+
42
+ constructor(
43
+ protected network: Network,
44
+ dexKey: string,
45
+ protected dexHelper: IDexHelper,
46
+ ) {
47
+ super(
48
+ network,
49
+ dexKey,
50
+ dexHelper,
51
+ true, // dynamic fees
52
+ );
53
+ }
54
+
55
+ protected getFeesMultiCallData(pair: SolidlyPair) {
56
+ const callEntry = {
57
+ target: this.factoryAddress,
58
+ callData: ramsesFactoryIface.encodeFunctionData('pairFee', [
59
+ pair.exchange,
60
+ ]),
61
+ };
62
+ const callDecoder = (values: any[]) =>
63
+ parseInt(
64
+ ramsesFactoryIface
65
+ .decodeFunctionResult('pairFee', values)[0]
66
+ .toString(),
67
+ );
68
+
69
+ return {
70
+ callEntry,
71
+ callDecoder,
72
+ };
73
+ }
74
+
75
+ async getTopPoolsForToken(
76
+ tokenAddress: Address,
77
+ count: number,
78
+ ): Promise<PoolLiquidity[]> {
79
+ if (!this.subgraphURL) return [];
80
+
81
+ const query = `query ($token: Bytes!, $count: Int) {
82
+ pools0: pairs(first: $count, orderBy: reserve0, orderDirection: desc, where: {token0: $token, reserve0_gt: 1, reserve1_gt: 1}) {
83
+ id
84
+ isStable
85
+ token0
86
+ token1
87
+ reserve0,
88
+ reserve1,
89
+ }
90
+ pools1: pairs(first: $count, orderBy: reserve1, orderDirection: desc, where: {token1: $token, reserve0_gt: 1, reserve1_gt: 1}) {
91
+ id
92
+ isStable
93
+ token0
94
+ token1
95
+ reserve0,
96
+ reserve1,
97
+ }
98
+ }`;
99
+
100
+ const { data } = await this.dexHelper.httpRequest.post(
101
+ this.subgraphURL,
102
+ {
103
+ query,
104
+ variables: { token: tokenAddress.toLowerCase(), count },
105
+ },
106
+ SUBGRAPH_TIMEOUT,
107
+ );
108
+
109
+ if (!(data && data.pools0 && data.pools1))
110
+ throw new Error("Couldn't fetch the pools from the subgraph");
111
+
112
+ const tokenIds = _.uniq(
113
+ []
114
+ .concat(data.pools0, data.pools1)
115
+ .map((pool: RamsesSubgraphPool) => [pool.token0, pool.token1])
116
+ .flat(),
117
+ );
118
+
119
+ const tokensQuery = `
120
+ query ($tokenIds: [String!]) {
121
+ tokens(where: {id_in: $tokenIds}) {
122
+ id
123
+ decimals
124
+ }
125
+ }`;
126
+
127
+ const { data: tokensData } = await this.dexHelper.httpRequest.post(
128
+ this.subgraphURL,
129
+ {
130
+ query: tokensQuery,
131
+ variables: { tokenIds },
132
+ },
133
+ SUBGRAPH_TIMEOUT,
134
+ );
135
+
136
+ const pools0 = await this.prepareSubgraphPools(
137
+ tokensData.tokens,
138
+ data.pools0,
139
+ (
140
+ pool,
141
+ { address1, decimals1, liquidityUSDToken0, liquidityUSDToken1 },
142
+ ) => ({
143
+ exchange: this.dexKey,
144
+ stable: pool.isStable,
145
+ address: pool.id.toLowerCase(),
146
+ connectorTokens: [
147
+ {
148
+ address: address1,
149
+ decimals: decimals1,
150
+ },
151
+ ],
152
+ liquidityUSD: liquidityUSDToken0 + liquidityUSDToken1,
153
+ }),
154
+ );
155
+
156
+ const pools1 = await this.prepareSubgraphPools(
157
+ tokensData.tokens,
158
+ data.pools1,
159
+ (
160
+ pool,
161
+ { address0, decimals0, liquidityUSDToken0, liquidityUSDToken1 },
162
+ ) => ({
163
+ exchange: this.dexKey,
164
+ stable: pool.isStable,
165
+ address: pool.id.toLowerCase(),
166
+ connectorTokens: [
167
+ {
168
+ address: address0,
169
+ decimals: decimals0,
170
+ },
171
+ ],
172
+ liquidityUSD: liquidityUSDToken0 + liquidityUSDToken1,
173
+ }),
174
+ );
175
+
176
+ return _.slice(
177
+ _.sortBy(_.concat(pools0, pools1), [pool => -1 * pool.liquidityUSD]),
178
+ 0,
179
+ count,
180
+ );
181
+ }
182
+
183
+ protected async prepareSubgraphPools(
184
+ tokens: RamsesSubgraphToken[],
185
+ pools: RamsesSubgraphPool[],
186
+ iterator: (
187
+ pool: RamsesSubgraphPool,
188
+ {
189
+ address0,
190
+ address1,
191
+ decimals0,
192
+ decimals1,
193
+ reserve0,
194
+ reserve1,
195
+ liquidityUSDToken0,
196
+ liquidityUSDToken1,
197
+ }: {
198
+ address0: string;
199
+ address1: string;
200
+ decimals0: number;
201
+ decimals1: number;
202
+ reserve0: bigint;
203
+ reserve1: bigint;
204
+ liquidityUSDToken0: number;
205
+ liquidityUSDToken1: number;
206
+ },
207
+ ) => PoolLiquidity,
208
+ ): Promise<PoolLiquidity[]> {
209
+ return Promise.all(
210
+ pools.map(async (pool: RamsesSubgraphPool) => {
211
+ const address0 = pool.token0.toLowerCase();
212
+ const address1 = pool.token1.toLowerCase();
213
+
214
+ const decimals0 = parseInt(
215
+ tokens.find(t => t.id === address0)!.decimals,
216
+ );
217
+ const decimals1 = parseInt(
218
+ tokens.find(t => t.id === address1)!.decimals,
219
+ );
220
+
221
+ const reserve0 = BigInt(new BigNumber(pool.reserve0).toFixed());
222
+ const reserve1 = BigInt(new BigNumber(pool.reserve1).toFixed());
223
+
224
+ const liquidityUSDToken0 = await this.dexHelper.getTokenUSDPrice(
225
+ {
226
+ address: address0,
227
+ decimals: decimals0,
228
+ },
229
+ reserve0,
230
+ );
231
+
232
+ const liquidityUSDToken1 = await this.dexHelper.getTokenUSDPrice(
233
+ {
234
+ address: address1,
235
+ decimals: decimals1,
236
+ },
237
+ reserve1,
238
+ );
239
+
240
+ return iterator(pool, {
241
+ address0,
242
+ address1,
243
+ decimals0,
244
+ decimals1,
245
+ reserve0,
246
+ reserve1,
247
+ liquidityUSDToken0,
248
+ liquidityUSDToken1,
249
+ });
250
+ }),
251
+ );
252
+ }
253
+ }
@@ -0,0 +1,63 @@
1
+ import { Solidly } from '../solidly';
2
+ import { Network } from '../../../constants';
3
+ import { getDexKeysWithNetwork } from '../../../utils';
4
+ import { SolidlyConfig } from '../config';
5
+ import _ from 'lodash';
6
+ import { Address, PoolLiquidity } from '../../../types';
7
+ import { SolidlyPair } from '../types';
8
+ import { Interface } from '@ethersproject/abi';
9
+ import { IDexHelper } from '../../../dex-helper';
10
+
11
+ const VelodromeV2FactoryABI = [
12
+ {
13
+ inputs: [
14
+ { internalType: 'address', name: 'pool', type: 'address' },
15
+ { internalType: 'bool', name: '_stable', type: 'bool' },
16
+ ],
17
+ name: 'getFee',
18
+ outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
19
+ stateMutability: 'view',
20
+ type: 'function',
21
+ },
22
+ ];
23
+
24
+ const velodromeV2FactoryIface = new Interface(VelodromeV2FactoryABI);
25
+
26
+ export class VelodromeV2 extends Solidly {
27
+ public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
28
+ getDexKeysWithNetwork(_.pick(SolidlyConfig, ['VelodromeV2']));
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, // dynamic fees
40
+ );
41
+ }
42
+
43
+ protected getFeesMultiCallData(pair: SolidlyPair) {
44
+ const callEntry = {
45
+ target: this.factoryAddress,
46
+ callData: velodromeV2FactoryIface.encodeFunctionData('getFee', [
47
+ pair.exchange,
48
+ pair.stable,
49
+ ]),
50
+ };
51
+ const callDecoder = (values: any[]) =>
52
+ parseInt(
53
+ velodromeV2FactoryIface
54
+ .decodeFunctionResult('getFee', values)[0]
55
+ .toString(),
56
+ );
57
+
58
+ return {
59
+ callEntry,
60
+ callDecoder,
61
+ };
62
+ }
63
+ }
@@ -2,11 +2,95 @@ 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
+ ) {
23
+ const provider = new StaticJsonRpcProvider(
24
+ generateConfig(network).privateHttpProvider,
25
+ network,
26
+ );
27
+ const tokens = Tokens[network];
28
+ const holders = Holders[network];
29
+ const nativeTokenSymbol = NativeTokenSymbols[network];
30
+
31
+ // TODO: Add any direct swap contractMethod name if it exists
32
+ const sideToContractMethods = new Map([
33
+ [
34
+ SwapSide.SELL,
35
+ [
36
+ ContractMethod.simpleSwap,
37
+ ContractMethod.multiSwap,
38
+ ContractMethod.megaSwap,
39
+ ],
40
+ ],
41
+ ]);
42
+
43
+ describe(`${network}`, () => {
44
+ sideToContractMethods.forEach((contractMethods, side) =>
45
+ describe(`${side}`, () => {
46
+ contractMethods.forEach((contractMethod: ContractMethod) => {
47
+ describe(`${contractMethod}`, () => {
48
+ it(`${nativeTokenSymbol} -> ${tokenASymbol}`, async () => {
49
+ await testE2E(
50
+ tokens[nativeTokenSymbol],
51
+ tokens[tokenASymbol],
52
+ holders[nativeTokenSymbol],
53
+ side === SwapSide.SELL ? nativeTokenAmount : tokenAAmount,
54
+ side,
55
+ dexKey,
56
+ contractMethod,
57
+ network,
58
+ provider,
59
+ );
60
+ });
61
+ it(`${tokenASymbol} -> ${nativeTokenSymbol}`, async () => {
62
+ await testE2E(
63
+ tokens[tokenASymbol],
64
+ tokens[nativeTokenSymbol],
65
+ holders[tokenASymbol],
66
+ side === SwapSide.SELL ? tokenAAmount : nativeTokenAmount,
67
+ side,
68
+ dexKey,
69
+ contractMethod,
70
+ network,
71
+ provider,
72
+ );
73
+ });
74
+ it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => {
75
+ await testE2E(
76
+ tokens[tokenASymbol],
77
+ tokens[tokenBSymbol],
78
+ holders[tokenASymbol],
79
+ side === SwapSide.SELL ? tokenAAmount : tokenBAmount,
80
+ side,
81
+ dexKey,
82
+ contractMethod,
83
+ network,
84
+ provider,
85
+ );
86
+ });
87
+ });
88
+ });
89
+ }),
90
+ );
91
+ });
92
+ }
93
+
10
94
  describe('Solidly E2E', () => {
11
95
  describe('Fantom', () => {
12
96
  const network = Network.FANTOM;
@@ -309,6 +393,28 @@ describe('Solidly E2E', () => {
309
393
  });
310
394
  });
311
395
  });
396
+
397
+ describe('Equalizer', () => {
398
+ const dexKey = 'Equalizer';
399
+ const network = Network.FANTOM;
400
+
401
+ const tokenASymbol: string = 'FUSDT';
402
+ const tokenBSymbol: string = 'USDC';
403
+
404
+ const tokenAAmount: string = '111110';
405
+ const tokenBAmount: string = '100000';
406
+ const nativeTokenAmount = '11000000000000000';
407
+
408
+ testForNetwork(
409
+ network,
410
+ dexKey,
411
+ tokenASymbol,
412
+ tokenBSymbol,
413
+ tokenAAmount,
414
+ tokenBAmount,
415
+ nativeTokenAmount,
416
+ );
417
+ });
312
418
  });
313
419
 
314
420
  describe('Mainnet', () => {
@@ -689,6 +795,29 @@ describe('Solidly E2E', () => {
689
795
  });
690
796
  });
691
797
  });
798
+
799
+ describe('VelodromeV2', () => {
800
+ const dexKey = 'VelodromeV2';
801
+
802
+ const network = Network.OPTIMISM;
803
+
804
+ const tokenASymbol: string = 'USDC';
805
+ const tokenBSymbol: string = 'USDT';
806
+
807
+ const tokenAAmount: string = '111110000';
808
+ const tokenBAmount: string = '1100000000';
809
+ const nativeTokenAmount = '11000000000000000';
810
+
811
+ testForNetwork(
812
+ network,
813
+ dexKey,
814
+ tokenASymbol,
815
+ tokenBSymbol,
816
+ tokenAAmount,
817
+ tokenBAmount,
818
+ nativeTokenAmount,
819
+ );
820
+ });
692
821
  });
693
822
 
694
823
  describe('BSC', () => {
@@ -1179,5 +1308,188 @@ describe('Solidly E2E', () => {
1179
1308
  }),
1180
1309
  );
1181
1310
  });
1311
+
1312
+ describe('Ramses', () => {
1313
+ const dexKey = 'Ramses';
1314
+
1315
+ const sideToContractMethods = new Map([
1316
+ [
1317
+ SwapSide.SELL,
1318
+ [
1319
+ ContractMethod.simpleSwap,
1320
+ ContractMethod.multiSwap,
1321
+ ContractMethod.megaSwap,
1322
+ ],
1323
+ ],
1324
+ ]);
1325
+
1326
+ const pairs: { name: string; sellAmount: string }[][] = [
1327
+ [
1328
+ {
1329
+ name: 'ETH',
1330
+ sellAmount: '10000000000000',
1331
+ },
1332
+ {
1333
+ name: 'USDCe',
1334
+ sellAmount: '100000000',
1335
+ },
1336
+ ],
1337
+ [
1338
+ {
1339
+ name: 'WETH',
1340
+ sellAmount: '10000000000000',
1341
+ },
1342
+ {
1343
+ name: 'USDCe',
1344
+ sellAmount: '100000000',
1345
+ },
1346
+ ],
1347
+ [
1348
+ {
1349
+ name: 'USDT',
1350
+ sellAmount: '100000000',
1351
+ },
1352
+ {
1353
+ name: 'USDCe',
1354
+ sellAmount: '100000000',
1355
+ },
1356
+ ],
1357
+ [
1358
+ {
1359
+ name: 'USDCe',
1360
+ sellAmount: '500000',
1361
+ },
1362
+ {
1363
+ name: 'DAI',
1364
+ sellAmount: '1000000000000000000',
1365
+ },
1366
+ ],
1367
+ ];
1368
+
1369
+ sideToContractMethods.forEach((contractMethods, side) =>
1370
+ describe(`${side}`, () => {
1371
+ contractMethods.forEach((contractMethod: ContractMethod) => {
1372
+ pairs.forEach(pair => {
1373
+ describe(`${contractMethod}`, () => {
1374
+ it(`${pair[0].name} -> ${pair[1].name}`, async () => {
1375
+ await testE2E(
1376
+ tokens[pair[0].name],
1377
+ tokens[pair[1].name],
1378
+ holders[pair[0].name],
1379
+ pair[0].sellAmount,
1380
+ side,
1381
+ dexKey,
1382
+ contractMethod,
1383
+ network,
1384
+ provider,
1385
+ );
1386
+ });
1387
+ it(`${pair[1].name} -> ${pair[0].name}`, async () => {
1388
+ await testE2E(
1389
+ tokens[pair[1].name],
1390
+ tokens[pair[0].name],
1391
+ holders[pair[1].name],
1392
+ pair[1].sellAmount,
1393
+ side,
1394
+ dexKey,
1395
+ contractMethod,
1396
+ network,
1397
+ provider,
1398
+ );
1399
+ });
1400
+ });
1401
+ });
1402
+ });
1403
+ }),
1404
+ );
1405
+ });
1406
+ });
1407
+
1408
+ describe('Base', () => {
1409
+ const network = Network.BASE;
1410
+
1411
+ describe('Aerodrome', () => {
1412
+ const dexKey = 'Aerodrome';
1413
+ const tokenASymbol: string = 'USDbC';
1414
+ const tokenBSymbol: string = 'DAI';
1415
+
1416
+ const tokenAAmount: string = '1111100000';
1417
+ const tokenBAmount: string = '100000000000000000';
1418
+ const nativeTokenAmount = '100000000000000000';
1419
+
1420
+ testForNetwork(
1421
+ network,
1422
+ dexKey,
1423
+ tokenASymbol,
1424
+ tokenBSymbol,
1425
+ tokenAAmount,
1426
+ tokenBAmount,
1427
+ nativeTokenAmount,
1428
+ );
1429
+ });
1430
+
1431
+ describe('Equalizer', () => {
1432
+ const dexKey = 'Equalizer';
1433
+ const network = Network.BASE;
1434
+
1435
+ const tokenASymbol: string = 'USDbC';
1436
+ const tokenAAmount: string = '1111100000';
1437
+ const nativeTokenAmount = '110000000000000000';
1438
+
1439
+ const provider = new StaticJsonRpcProvider(
1440
+ generateConfig(network).privateHttpProvider,
1441
+ network,
1442
+ );
1443
+ const tokens = Tokens[network];
1444
+ const holders = Holders[network];
1445
+ const nativeTokenSymbol = NativeTokenSymbols[network];
1446
+
1447
+ // TODO: Add any direct swap contractMethod name if it exists
1448
+ const sideToContractMethods = new Map([
1449
+ [
1450
+ SwapSide.SELL,
1451
+ [
1452
+ ContractMethod.simpleSwap,
1453
+ ContractMethod.multiSwap,
1454
+ ContractMethod.megaSwap,
1455
+ ],
1456
+ ],
1457
+ ]);
1458
+
1459
+ sideToContractMethods.forEach((contractMethods, side) =>
1460
+ describe(`${side}`, () => {
1461
+ contractMethods.forEach((contractMethod: ContractMethod) => {
1462
+ describe(`${contractMethod}`, () => {
1463
+ it(`${nativeTokenSymbol} -> ${tokenASymbol}`, async () => {
1464
+ await testE2E(
1465
+ tokens[nativeTokenSymbol],
1466
+ tokens[tokenASymbol],
1467
+ holders[nativeTokenSymbol],
1468
+ side === SwapSide.SELL ? nativeTokenAmount : tokenAAmount,
1469
+ side,
1470
+ dexKey,
1471
+ contractMethod,
1472
+ network,
1473
+ provider,
1474
+ );
1475
+ });
1476
+ it(`${tokenASymbol} -> ${nativeTokenSymbol}`, async () => {
1477
+ await testE2E(
1478
+ tokens[tokenASymbol],
1479
+ tokens[nativeTokenSymbol],
1480
+ holders[tokenASymbol],
1481
+ side === SwapSide.SELL ? tokenAAmount : nativeTokenAmount,
1482
+ side,
1483
+ dexKey,
1484
+ contractMethod,
1485
+ network,
1486
+ provider,
1487
+ );
1488
+ });
1489
+ });
1490
+ });
1491
+ }),
1492
+ );
1493
+ });
1182
1494
  });
1183
1495
  });