@paraswap/dex-lib 3.4.0 → 3.4.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 (360) hide show
  1. package/.vscode/launch.json +53 -0
  2. package/.vscode/settings.json +2 -0
  3. package/.vscode/tasks.json +15 -0
  4. package/README.md +3 -3
  5. package/abis.txt +92 -0
  6. package/build/abi/uniswap-v3/AlienBaseV3Router.abi.json +52 -0
  7. package/build/abi/{integral/relayer.json → wombat/pool.json} +587 -446
  8. package/build/config.js +0 -35
  9. package/build/config.js.map +1 -1
  10. package/build/constants.d.ts +0 -1
  11. package/build/constants.js +0 -1
  12. package/build/constants.js.map +1 -1
  13. package/build/dex/augustus-rfq.js +0 -1
  14. package/build/dex/augustus-rfq.js.map +1 -1
  15. package/build/dex/curve-v1/config.js +1 -57
  16. package/build/dex/curve-v1/config.js.map +1 -1
  17. package/build/dex/curve-v1-factory/config.js +1 -1
  18. package/build/dex/curve-v1-factory/config.js.map +1 -1
  19. package/build/dex/etherfi.js +1 -1
  20. package/build/dex/gmx/gmx.js.map +1 -1
  21. package/build/dex/index.js +0 -14
  22. package/build/dex/index.js.map +1 -1
  23. package/build/dex/nerve/config.js +0 -399
  24. package/build/dex/nerve/config.js.map +1 -1
  25. package/build/dex/paraswap-limit-orders/config.js +0 -7
  26. package/build/dex/paraswap-limit-orders/config.js.map +1 -1
  27. package/build/dex/quick-perps/quick-perps.js.map +1 -1
  28. package/build/dex/quickswap/config.js +0 -8
  29. package/build/dex/quickswap/config.js.map +1 -1
  30. package/build/dex/solidly/config.js +1 -27
  31. package/build/dex/solidly/config.js.map +1 -1
  32. package/build/dex/solidly/solidly.js +0 -2
  33. package/build/dex/solidly/solidly.js.map +1 -1
  34. package/build/dex/solidly-v3/scripts/check-event-pool-event.d.ts +1 -0
  35. package/build/dex/solidly-v3/scripts/check-event-pool-event.js +53 -0
  36. package/build/dex/solidly-v3/scripts/check-event-pool-event.js.map +1 -0
  37. package/build/dex/stable-pool/stable-pool.js +1 -8
  38. package/build/dex/stable-pool/stable-pool.js.map +1 -1
  39. package/build/dex/stable-pool.js +1 -8
  40. package/build/dex/stable-pool.js.map +1 -1
  41. package/build/dex/uniswap-v2/config.js +0 -152
  42. package/build/dex/uniswap-v2/config.js.map +1 -1
  43. package/build/dex/uniswap-v2/constants.js +0 -1
  44. package/build/dex/uniswap-v2/constants.js.map +1 -1
  45. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.d.ts +17 -0
  46. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js +64 -0
  47. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js.map +1 -0
  48. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.d.ts +17 -0
  49. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js +79 -0
  50. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js.map +1 -0
  51. package/build/dex/weth/config.js +0 -3
  52. package/build/dex/weth/config.js.map +1 -1
  53. package/build/dex/wsteth/wsteth.js.map +1 -1
  54. package/build/types.d.ts +0 -1
  55. package/package.json +1 -1
  56. package/src/config.ts +0 -39
  57. package/src/constants.ts +0 -1
  58. package/src/dex/augustus-rfq.ts +0 -1
  59. package/src/dex/curve-v1/config.ts +1 -57
  60. package/src/dex/curve-v1/curve-v1-e2e.test.ts +0 -51
  61. package/src/dex/curve-v1-factory/config.ts +1 -1
  62. package/src/dex/etherfi.ts +1 -1
  63. package/src/dex/gmx/gmx.ts +1 -4
  64. package/src/dex/index.ts +0 -14
  65. package/src/dex/nerve/config.ts +0 -400
  66. package/src/dex/nerve/nerve-e2e.test.ts +0 -507
  67. package/src/dex/nerve/nerve-events.test.ts +0 -268
  68. package/src/dex/paraswap-limit-orders/config.ts +0 -7
  69. package/src/dex/paraswap-limit-orders/paraswap-limit-orders-e2e.test.ts +2 -2
  70. package/src/dex/paraswap-limit-orders/paraswap-limit-orders-integration.test.ts +1 -1
  71. package/src/dex/quick-perps/quick-perps.ts +1 -4
  72. package/src/dex/quickswap/config.ts +0 -9
  73. package/src/dex/quickswap/quickswap-e2e.test.ts +0 -97
  74. package/src/dex/solidly/config.ts +1 -30
  75. package/src/dex/solidly/solidly-e2e.test.ts +0 -280
  76. package/src/dex/solidly/solidly-integration.test.ts +0 -135
  77. package/src/dex/solidly/solidly.ts +0 -2
  78. package/src/dex/stable-pool/stable-pool.ts +1 -8
  79. package/src/dex/uniswap-v2/config.ts +0 -185
  80. package/src/dex/uniswap-v2/constants.ts +0 -1
  81. package/src/dex/uniswap-v2/uniswap-v2-e2e-avalanche.test.ts +0 -272
  82. package/src/dex/uniswap-v2/uniswap-v2-e2e-base.test.ts +0 -6
  83. package/src/dex/uniswap-v2/uniswap-v2-e2e-bsc.test.ts +0 -325
  84. package/src/dex/uniswap-v2/uniswap-v2-e2e-mainnet.test.ts +0 -175
  85. package/src/dex/uniswap-v2/uniswap-v2-e2e-polygon.test.ts +0 -413
  86. package/src/dex/weth/config.ts +0 -3
  87. package/src/dex/wsteth/wsteth.ts +1 -4
  88. package/src/types.ts +0 -1
  89. package/tests/constants-e2e.ts +0 -21
  90. package/tests/generate-new-limit-order.ts +1 -1
  91. package/.idea/aws.xml +0 -17
  92. package/.idea/codeStyles/Project.xml +0 -19
  93. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  94. package/.idea/misc.xml +0 -6
  95. package/.idea/modules.xml +0 -8
  96. package/.idea/paraswap-dex-lib.iml +0 -9
  97. package/.idea/prettier.xml +0 -7
  98. package/.idea/vcs.xml +0 -6
  99. package/build/abi/AugustusV6.abi.json +0 -395
  100. package/build/abi/algebra/AlgebraPool.abi.json +0 -727
  101. package/build/abi/curve-v1/StableSwapFRXETH.json +0 -889
  102. package/build/abi/curve-v1/StableSwapWBETH.json +0 -1223
  103. package/build/abi/sushiswap-v3/QuoterV2.json +0 -267
  104. package/build/abi/sushiswap-v3/RouterProcessor3.json +0 -289
  105. package/build/abi/uniswap-v3/UniswapV3Quoter.abi.json +0 -193
  106. package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3QuoterV2.abi.json +0 -285
  107. package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3Router.abi.json +0 -583
  108. package/build/abi/wBETH.json +0 -1527
  109. package/build/abi/woo-fi/WooFeeManager.abi.json +0 -318
  110. package/build/abi/woo-fi/WooPP.abi.json +0 -548
  111. package/build/abi/woo-fi/Wooracle.abi.json +0 -260
  112. package/build/dex/aave-v3/tokens/arbitrum.json +0 -50
  113. package/build/dex/aave-v3/tokens/avalanche.json +0 -74
  114. package/build/dex/aave-v3/tokens/fantom.json +0 -62
  115. package/build/dex/aave-v3/tokens/optimism.json +0 -50
  116. package/build/dex/aave-v3/tokens/polygon.json +0 -116
  117. package/build/dex/algebra/algebra-pool.d.ts +0 -114
  118. package/build/dex/algebra/algebra-pool.js +0 -448
  119. package/build/dex/algebra/algebra-pool.js.map +0 -1
  120. package/build/dex/balancer-v2/Gyro3Pool.d.ts +0 -43
  121. package/build/dex/balancer-v2/Gyro3Pool.js +0 -160
  122. package/build/dex/balancer-v2/Gyro3Pool.js.map +0 -1
  123. package/build/dex/balancer-v2/LinearMath.d.ts +0 -88
  124. package/build/dex/balancer-v2/LinearMath.js +0 -285
  125. package/build/dex/balancer-v2/LinearMath.js.map +0 -1
  126. package/build/dex/balancer-v2/LinearPool.d.ts +0 -81
  127. package/build/dex/balancer-v2/LinearPool.js +0 -444
  128. package/build/dex/balancer-v2/LinearPool.js.map +0 -1
  129. package/build/dex/balancer-v2/PhantomStablePool.d.ts +0 -90
  130. package/build/dex/balancer-v2/PhantomStablePool.js +0 -418
  131. package/build/dex/balancer-v2/PhantomStablePool.js.map +0 -1
  132. package/build/dex/balancer-v2/StableMath.d.ts +0 -9
  133. package/build/dex/balancer-v2/StableMath.js +0 -272
  134. package/build/dex/balancer-v2/StableMath.js.map +0 -1
  135. package/build/dex/balancer-v2/balancer-v2-pool.d.ts +0 -140
  136. package/build/dex/balancer-v2/balancer-v2-pool.js +0 -647
  137. package/build/dex/balancer-v2/balancer-v2-pool.js.map +0 -1
  138. package/build/dex/curve-v1/pools/frxETHpool.d.ts +0 -7
  139. package/build/dex/curve-v1/pools/frxETHpool.js +0 -27
  140. package/build/dex/curve-v1/pools/frxETHpool.js.map +0 -1
  141. package/build/dex/curve-v1/pools/wbETHpool.d.ts +0 -29
  142. package/build/dex/curve-v1/pools/wbETHpool.js +0 -408
  143. package/build/dex/curve-v1/pools/wbETHpool.js.map +0 -1
  144. package/build/dex/integral/config.d.ts +0 -4
  145. package/build/dex/integral/config.js +0 -18
  146. package/build/dex/integral/config.js.map +0 -1
  147. package/build/dex/integral/integral-pool.d.ts +0 -39
  148. package/build/dex/integral/integral-pool.js +0 -67
  149. package/build/dex/integral/integral-pool.js.map +0 -1
  150. package/build/dex/integral/integral.d.ts +0 -48
  151. package/build/dex/integral/integral.js +0 -402
  152. package/build/dex/integral/integral.js.map +0 -1
  153. package/build/dex/integral/types.d.ts +0 -25
  154. package/build/dex/integral/types.js +0 -9
  155. package/build/dex/integral/types.js.map +0 -1
  156. package/build/dex/lighter-v1/abi/erc20.json +0 -222
  157. package/build/dex/lighter-v1/abi/factory.json +0 -291
  158. package/build/dex/lighter-v1/abi/order_book.json +0 -594
  159. package/build/dex/lighter-v1/abi/order_book_helper.json +0 -176
  160. package/build/dex/lighter-v1/abi/router.json +0 -488
  161. package/build/dex/lighter-v1/config.d.ts +0 -4
  162. package/build/dex/lighter-v1/config.js +0 -17
  163. package/build/dex/lighter-v1/config.js.map +0 -1
  164. package/build/dex/lighter-v1/constants.d.ts +0 -2
  165. package/build/dex/lighter-v1/constants.js +0 -13
  166. package/build/dex/lighter-v1/constants.js.map +0 -1
  167. package/build/dex/lighter-v1/lighter-v1-pool.d.ts +0 -57
  168. package/build/dex/lighter-v1/lighter-v1-pool.js +0 -310
  169. package/build/dex/lighter-v1/lighter-v1-pool.js.map +0 -1
  170. package/build/dex/lighter-v1/lighter-v1.d.ts +0 -45
  171. package/build/dex/lighter-v1/lighter-v1.js +0 -331
  172. package/build/dex/lighter-v1/lighter-v1.js.map +0 -1
  173. package/build/dex/lighter-v1/types.d.ts +0 -40
  174. package/build/dex/lighter-v1/types.js +0 -3
  175. package/build/dex/lighter-v1/types.js.map +0 -1
  176. package/build/dex/pancakeswap-v3/types.d.ts +0 -14
  177. package/build/dex/pancakeswap-v3/types.js +0 -3
  178. package/build/dex/pancakeswap-v3/types.js.map +0 -1
  179. package/build/dex/quickswap/camelot-v3.d.ts +0 -6
  180. package/build/dex/quickswap/camelot-v3.js +0 -19
  181. package/build/dex/quickswap/camelot-v3.js.map +0 -1
  182. package/build/dex/quickswap/zyberswap-v3.d.ts +0 -6
  183. package/build/dex/quickswap/zyberswap-v3.js +0 -19
  184. package/build/dex/quickswap/zyberswap-v3.js.map +0 -1
  185. package/build/dex/quickswap-v3.d.ts +0 -21
  186. package/build/dex/quickswap-v3.js +0 -40
  187. package/build/dex/quickswap-v3.js.map +0 -1
  188. package/build/dex/ramses-v2/config.d.ts +0 -4
  189. package/build/dex/ramses-v2/config.js +0 -28
  190. package/build/dex/ramses-v2/config.js.map +0 -1
  191. package/build/dex/ramses-v2/constants.d.ts +0 -28
  192. package/build/dex/ramses-v2/constants.js +0 -35
  193. package/build/dex/ramses-v2/constants.js.map +0 -1
  194. package/build/dex/ramses-v2/contract-math/BitMath.d.ts +0 -4
  195. package/build/dex/ramses-v2/contract-math/BitMath.js +0 -93
  196. package/build/dex/ramses-v2/contract-math/BitMath.js.map +0 -1
  197. package/build/dex/ramses-v2/contract-math/FixedPoint128.d.ts +0 -3
  198. package/build/dex/ramses-v2/contract-math/FixedPoint128.js +0 -8
  199. package/build/dex/ramses-v2/contract-math/FixedPoint128.js.map +0 -1
  200. package/build/dex/ramses-v2/contract-math/FixedPoint96.d.ts +0 -4
  201. package/build/dex/ramses-v2/contract-math/FixedPoint96.js +0 -9
  202. package/build/dex/ramses-v2/contract-math/FixedPoint96.js.map +0 -1
  203. package/build/dex/ramses-v2/contract-math/FullMath.d.ts +0 -4
  204. package/build/dex/ramses-v2/contract-math/FullMath.js +0 -19
  205. package/build/dex/ramses-v2/contract-math/FullMath.js.map +0 -1
  206. package/build/dex/ramses-v2/contract-math/LiquidityMath.d.ts +0 -3
  207. package/build/dex/ramses-v2/contract-math/LiquidityMath.js +0 -22
  208. package/build/dex/ramses-v2/contract-math/LiquidityMath.js.map +0 -1
  209. package/build/dex/ramses-v2/contract-math/Oracle.d.ts +0 -10
  210. package/build/dex/ramses-v2/contract-math/Oracle.js +0 -133
  211. package/build/dex/ramses-v2/contract-math/Oracle.js.map +0 -1
  212. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.d.ts +0 -10
  213. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js +0 -91
  214. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js.map +0 -1
  215. package/build/dex/ramses-v2/contract-math/SwapMath.d.ts +0 -8
  216. package/build/dex/ramses-v2/contract-math/SwapMath.js +0 -70
  217. package/build/dex/ramses-v2/contract-math/SwapMath.js.map +0 -1
  218. package/build/dex/ramses-v2/contract-math/Tick.d.ts +0 -7
  219. package/build/dex/ramses-v2/contract-math/Tick.js +0 -45
  220. package/build/dex/ramses-v2/contract-math/Tick.js.map +0 -1
  221. package/build/dex/ramses-v2/contract-math/TickBitMap.d.ts +0 -8
  222. package/build/dex/ramses-v2/contract-math/TickBitMap.js +0 -87
  223. package/build/dex/ramses-v2/contract-math/TickBitMap.js.map +0 -1
  224. package/build/dex/ramses-v2/contract-math/TickMath.d.ts +0 -8
  225. package/build/dex/ramses-v2/contract-math/TickMath.js +0 -162
  226. package/build/dex/ramses-v2/contract-math/TickMath.js.map +0 -1
  227. package/build/dex/ramses-v2/contract-math/UnsafeMath.d.ts +0 -3
  228. package/build/dex/ramses-v2/contract-math/UnsafeMath.js +0 -10
  229. package/build/dex/ramses-v2/contract-math/UnsafeMath.js.map +0 -1
  230. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.d.ts +0 -18
  231. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js +0 -392
  232. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js.map +0 -1
  233. package/build/dex/ramses-v2/contract-math/utils.d.ts +0 -3
  234. package/build/dex/ramses-v2/contract-math/utils.js +0 -16
  235. package/build/dex/ramses-v2/contract-math/utils.js.map +0 -1
  236. package/build/dex/ramses-v2/ramses-v2-pool.d.ts +0 -42
  237. package/build/dex/ramses-v2/ramses-v2-pool.js +0 -307
  238. package/build/dex/ramses-v2/ramses-v2-pool.js.map +0 -1
  239. package/build/dex/ramses-v2/ramses-v2.d.ts +0 -61
  240. package/build/dex/ramses-v2/ramses-v2.js +0 -690
  241. package/build/dex/ramses-v2/ramses-v2.js.map +0 -1
  242. package/build/dex/ramses-v2/types.d.ts +0 -154
  243. package/build/dex/ramses-v2/types.js +0 -9
  244. package/build/dex/ramses-v2/types.js.map +0 -1
  245. package/build/dex/ramses-v2/utils.d.ts +0 -6
  246. package/build/dex/ramses-v2/utils.js +0 -71
  247. package/build/dex/ramses-v2/utils.js.map +0 -1
  248. package/build/dex/solidly/forks-override/fvm.d.ts +0 -20
  249. package/build/dex/solidly/forks-override/fvm.js +0 -42
  250. package/build/dex/solidly/forks-override/fvm.js.map +0 -1
  251. package/build/dex/sushiswap-v3/config.d.ts +0 -4
  252. package/build/dex/sushiswap-v3/config.js +0 -132
  253. package/build/dex/sushiswap-v3/config.js.map +0 -1
  254. package/build/dex/sushiswap-v3/constants.d.ts +0 -4
  255. package/build/dex/sushiswap-v3/constants.js +0 -32
  256. package/build/dex/sushiswap-v3/constants.js.map +0 -1
  257. package/build/dex/sushiswap-v3/sushiswap-v3-original.d.ts +0 -56
  258. package/build/dex/sushiswap-v3/sushiswap-v3-original.js +0 -598
  259. package/build/dex/sushiswap-v3/sushiswap-v3-original.js.map +0 -1
  260. package/build/dex/sushiswap-v3/sushiswap-v3-pool.d.ts +0 -1
  261. package/build/dex/sushiswap-v3/sushiswap-v3-pool.js +0 -6
  262. package/build/dex/sushiswap-v3/sushiswap-v3-pool.js.map +0 -1
  263. package/build/dex/sushiswap-v3/sushiswap-v3.d.ts +0 -21
  264. package/build/dex/sushiswap-v3/sushiswap-v3.js +0 -58
  265. package/build/dex/sushiswap-v3/sushiswap-v3.js.map +0 -1
  266. package/build/dex/sushiswap-v3/token.d.ts +0 -6
  267. package/build/dex/sushiswap-v3/token.js +0 -23
  268. package/build/dex/sushiswap-v3/token.js.map +0 -1
  269. package/build/dex/sushiswap-v3/types.d.ts +0 -15
  270. package/build/dex/sushiswap-v3/types.js +0 -18
  271. package/build/dex/sushiswap-v3/types.js.map +0 -1
  272. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.d.ts +0 -12
  273. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js +0 -23
  274. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js.map +0 -1
  275. package/build/dex/woo-fi/config.d.ts +0 -4
  276. package/build/dex/woo-fi/config.js +0 -141
  277. package/build/dex/woo-fi/config.js.map +0 -1
  278. package/build/dex/woo-fi/constants.d.ts +0 -5
  279. package/build/dex/woo-fi/constants.js +0 -20
  280. package/build/dex/woo-fi/constants.js.map +0 -1
  281. package/build/dex/woo-fi/types.d.ts +0 -48
  282. package/build/dex/woo-fi/types.js +0 -3
  283. package/build/dex/woo-fi/types.js.map +0 -1
  284. package/build/dex/woo-fi/woo-fi-decimal-math.d.ts +0 -14
  285. package/build/dex/woo-fi/woo-fi-decimal-math.js +0 -42
  286. package/build/dex/woo-fi/woo-fi-decimal-math.js.map +0 -1
  287. package/build/dex/woo-fi/woo-fi-math.d.ts +0 -31
  288. package/build/dex/woo-fi/woo-fi-math.js +0 -300
  289. package/build/dex/woo-fi/woo-fi-math.js.map +0 -1
  290. package/build/dex/woo-fi/woo-fi.d.ts +0 -65
  291. package/build/dex/woo-fi/woo-fi.js +0 -480
  292. package/build/dex/woo-fi/woo-fi.js.map +0 -1
  293. package/build/executor/IExecutorBytecodeBuilder.d.ts +0 -6
  294. package/build/executor/IExecutorBytecodeBuilder.js +0 -3
  295. package/build/executor/IExecutorBytecodeBuilder.js.map +0 -1
  296. package/src/abi/AaveV1_lending_pool.json +0 -27
  297. package/src/abi/platypus/asset.json +0 -490
  298. package/src/abi/platypus/avax-pool.json +0 -820
  299. package/src/abi/platypus/oracle.json +0 -119
  300. package/src/abi/platypus/pool.json +0 -677
  301. package/src/abi/smardex/all/smardex-router.json +0 -648
  302. package/src/abi/smardex/layer-1/smardex-factory.json +0 -242
  303. package/src/abi/smardex/layer-1/smardex-pool.json +0 -506
  304. package/src/abi/smardex/layer-2/smardex-factory.json +0 -185
  305. package/src/abi/smardex/layer-2/smardex-pool.json +0 -578
  306. package/src/abi/swaap-v1/asset.json +0 -490
  307. package/src/abi/swaap-v1/oracle.json +0 -119
  308. package/src/abi/swaap-v1/pool.json +0 -1346
  309. package/src/dex/aave-v1/aave-v1-e2e.test.ts +0 -105
  310. package/src/dex/aave-v1/aave-v1-integration.test.ts +0 -100
  311. package/src/dex/aave-v1/aave-v1.ts +0 -261
  312. package/src/dex/aave-v1/config.ts +0 -22
  313. package/src/dex/aave-v1/tokens-mainnet.json +0 -134
  314. package/src/dex/aave-v1/tokens.ts +0 -58
  315. package/src/dex/aave-v1/types.ts +0 -24
  316. package/src/dex/platypus/asset.ts +0 -139
  317. package/src/dex/platypus/config.ts +0 -72
  318. package/src/dex/platypus/platypus-e2e.test.ts +0 -168
  319. package/src/dex/platypus/platypus-events.test.ts +0 -167
  320. package/src/dex/platypus/platypus-integration.test.ts +0 -256
  321. package/src/dex/platypus/platypus.ts +0 -639
  322. package/src/dex/platypus/pool-avax.ts +0 -92
  323. package/src/dex/platypus/pool-base.ts +0 -155
  324. package/src/dex/platypus/pool-pure.ts +0 -71
  325. package/src/dex/platypus/pool-subscriber.ts +0 -239
  326. package/src/dex/platypus/pool.ts +0 -99
  327. package/src/dex/platypus/types.ts +0 -104
  328. package/src/dex/quickswap/spiritswap-v3.ts +0 -19
  329. package/src/dex/smardex/config.ts +0 -67
  330. package/src/dex/smardex/constants.ts +0 -35
  331. package/src/dex/smardex/sdk/constants.ts +0 -10
  332. package/src/dex/smardex/sdk/core.ts +0 -832
  333. package/src/dex/smardex/sdk/errors.ts +0 -18
  334. package/src/dex/smardex/sdk/types.ts +0 -68
  335. package/src/dex/smardex/sdk/utils.ts +0 -156
  336. package/src/dex/smardex/smardex-e2e.test.ts +0 -275
  337. package/src/dex/smardex/smardex-event-pool.ts +0 -164
  338. package/src/dex/smardex/smardex-events.test.ts +0 -297
  339. package/src/dex/smardex/smardex-integration.test.ts +0 -258
  340. package/src/dex/smardex/smardex.ts +0 -770
  341. package/src/dex/smardex/types.ts +0 -69
  342. package/src/dex/solidly/forks-override/cone.ts +0 -67
  343. package/src/dex/solidly/forks-override/solisnek.ts +0 -10
  344. package/src/dex/swaap-v1/config.ts +0 -62
  345. package/src/dex/swaap-v1/constants.ts +0 -22
  346. package/src/dex/swaap-v1/libraries/ChainlinkUtils.ts +0 -152
  347. package/src/dex/swaap-v1/libraries/Const.ts +0 -29
  348. package/src/dex/swaap-v1/libraries/GeometricBrownianMotion.ts +0 -433
  349. package/src/dex/swaap-v1/libraries/LogExpMath.ts +0 -511
  350. package/src/dex/swaap-v1/libraries/MathMMM.ts +0 -717
  351. package/src/dex/swaap-v1/libraries/Num.ts +0 -184
  352. package/src/dex/swaap-v1/libraries/PoolQuotations.ts +0 -322
  353. package/src/dex/swaap-v1/libraries/Struct.ts +0 -66
  354. package/src/dex/swaap-v1/swaap-v1-e2e.test.ts +0 -75
  355. package/src/dex/swaap-v1/swaap-v1-events.test.ts +0 -138
  356. package/src/dex/swaap-v1/swaap-v1-integration.test.ts +0 -232
  357. package/src/dex/swaap-v1/swaap-v1-pool.ts +0 -919
  358. package/src/dex/swaap-v1/swaap-v1.ts +0 -668
  359. package/src/dex/swaap-v1/types.ts +0 -124
  360. package/src/dex/uniswap-v2/uniswap-v2-e2e-ropsten.test.ts +0 -481
@@ -1,639 +0,0 @@
1
- import { Interface } from '@ethersproject/abi';
2
- import {
3
- Token,
4
- Address,
5
- ExchangePrices,
6
- PoolPrices,
7
- AdapterExchangeParam,
8
- SimpleExchangeParam,
9
- PoolLiquidity,
10
- Logger,
11
- MultiCallInput,
12
- NumberAsString,
13
- DexExchangeParam,
14
- } from '../../types';
15
- import { SwapSide, Network } from '../../constants';
16
- import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
17
- import { getDexKeysWithNetwork, getBigIntPow, isETHAddress } from '../../utils';
18
- import { IDex } from '../../dex/idex';
19
- import { IDexHelper } from '../../dex-helper/idex-helper';
20
- import {
21
- DexParams,
22
- PlatypusOracleType,
23
- PlatypusData,
24
- PlatypusConfigInfo,
25
- } from './types';
26
- import {
27
- getLocalDeadlineAsFriendlyPlaceholder,
28
- SimpleExchange,
29
- } from '../simple-exchange';
30
- import { PlatypusConfig, Adapters } from './config';
31
- import { ChainLinkSubscriber } from '../../lib/chainlink';
32
- import { PlatypusPoolBase } from './pool-base';
33
- import { PlatypusPool } from './pool';
34
- import { PlatypusPurePool } from './pool-pure';
35
- import { PlatypusAvaxPool } from './pool-avax';
36
- import ERC20ABI from '../../abi/erc20.json';
37
- import PoolABI from '../../abi/platypus/pool.json';
38
- import AvaxPoolABI from '../../abi/platypus/avax-pool.json';
39
- import AssetABI from '../../abi/platypus/asset.json';
40
- import OracleABI from '../../abi/platypus/oracle.json';
41
- import { extractReturnAmountPosition } from '../../executor/utils';
42
-
43
- export class Platypus extends SimpleExchange implements IDex<PlatypusData> {
44
- static readonly erc20Interface = new Interface(ERC20ABI);
45
- static readonly poolInterface = new Interface(PoolABI);
46
- static readonly avaxPoolInterface = new Interface(AvaxPoolABI);
47
- static readonly assetInterface = new Interface(AssetABI);
48
- static readonly oracleInterface = new Interface(OracleABI);
49
-
50
- protected config: DexParams;
51
- protected cfgInfo?: PlatypusConfigInfo;
52
- protected poolLiquidityUSD?: { [poolAddress: string]: number };
53
-
54
- protected eventPools?: {
55
- [poolAddress: string]: PlatypusPool | PlatypusPurePool | PlatypusAvaxPool;
56
- };
57
-
58
- readonly hasConstantPriceLargeAmounts = false;
59
- readonly isFeeOnTransferSupported = false;
60
-
61
- public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
62
- getDexKeysWithNetwork(PlatypusConfig);
63
-
64
- logger: Logger;
65
-
66
- constructor(
67
- protected network: Network,
68
- dexKey: string,
69
- protected dexHelper: IDexHelper,
70
- protected adapters = Adapters[network], // TODO: add any additional optional params to support other fork DEXes
71
- ) {
72
- super(dexHelper, dexKey);
73
- this.config = PlatypusConfig[dexKey][network];
74
- this.logger = dexHelper.getLogger(`${dexKey}-${network}`);
75
- }
76
-
77
- async generateConfigInfo(blockNumber: number): Promise<PlatypusConfigInfo> {
78
- const cfgInfo: PlatypusConfigInfo = {
79
- poolAddresses: [],
80
- pools: {},
81
- };
82
- // Need to filter pools in case we are testing against an old block where the pool didn't exist!
83
- for (const p of this.config.pools) {
84
- // When there's no code, getCode should return '0x' but could return '0x0' instead
85
- if (
86
- (await this.dexHelper.web3Provider.eth.getCode(p.address, blockNumber))
87
- .length > 3
88
- ) {
89
- const poolAddress = p.address.toLowerCase();
90
- cfgInfo.poolAddresses.push(poolAddress);
91
- if (p.oracleType === PlatypusOracleType.None) {
92
- cfgInfo.pools[poolAddress] = {
93
- oracleType: PlatypusOracleType.None,
94
- tokenAddresses: [],
95
- tokens: {},
96
- };
97
- } else if (p.oracleType === PlatypusOracleType.ChainLink) {
98
- cfgInfo.pools[poolAddress] = {
99
- oracleType: PlatypusOracleType.ChainLink,
100
- priceOracleAddress: '',
101
- tokenAddresses: [],
102
- tokens: {},
103
- };
104
- } else if (p.oracleType === PlatypusOracleType.StakedAvax) {
105
- cfgInfo.pools[poolAddress] = {
106
- oracleType: PlatypusOracleType.StakedAvax,
107
- priceOracleAddress: '',
108
- tokenAddresses: [],
109
- tokens: {},
110
- };
111
- } else {
112
- throw new Error(`Invalid pool oracle type in ${this.dexKey}`);
113
- }
114
- }
115
- }
116
- let inputs: MultiCallInput[] = [];
117
- for (const poolAddress of cfgInfo.poolAddresses) {
118
- const pool = cfgInfo.pools[poolAddress];
119
- if (pool.oracleType !== PlatypusOracleType.None) {
120
- inputs.push({
121
- target: poolAddress,
122
- callData: Platypus.poolInterface.encodeFunctionData('getPriceOracle'),
123
- });
124
- }
125
- inputs.push({
126
- target: poolAddress,
127
- callData:
128
- Platypus.poolInterface.encodeFunctionData('getTokenAddresses'),
129
- });
130
- }
131
- let returnData = (
132
- await this.dexHelper.multiContract.methods
133
- .aggregate(inputs)
134
- .call({}, blockNumber)
135
- ).returnData;
136
- let i = 0;
137
- for (const poolAddress of cfgInfo.poolAddresses) {
138
- const pool = cfgInfo.pools[poolAddress];
139
- if (pool.oracleType !== PlatypusOracleType.None) {
140
- pool.priceOracleAddress = Platypus.poolInterface
141
- .decodeFunctionResult('getPriceOracle', returnData[i++])[0]
142
- .toLowerCase();
143
- }
144
- pool.tokenAddresses = Platypus.poolInterface
145
- .decodeFunctionResult('getTokenAddresses', returnData[i++])[0]
146
- .map((a: Address) => a.toLowerCase());
147
- }
148
- inputs = [];
149
- for (const poolAddress of cfgInfo.poolAddresses) {
150
- const pool = cfgInfo.pools[poolAddress];
151
- for (const tokenAddress of pool.tokenAddresses) {
152
- inputs.push({
153
- target: tokenAddress,
154
- callData: Platypus.erc20Interface.encodeFunctionData('symbol'),
155
- });
156
- inputs.push({
157
- target: tokenAddress,
158
- callData: Platypus.erc20Interface.encodeFunctionData('decimals'),
159
- });
160
- inputs.push({
161
- target: poolAddress,
162
- callData: Platypus.poolInterface.encodeFunctionData('assetOf', [
163
- tokenAddress,
164
- ]),
165
- });
166
- if (pool.oracleType === PlatypusOracleType.ChainLink) {
167
- inputs.push({
168
- target: pool.priceOracleAddress,
169
- callData: Platypus.oracleInterface.encodeFunctionData(
170
- 'getSourceOfAsset',
171
- [tokenAddress],
172
- ),
173
- });
174
- }
175
- }
176
- }
177
- returnData = (
178
- await this.dexHelper.multiContract.methods
179
- .aggregate(inputs)
180
- .call({}, blockNumber)
181
- ).returnData;
182
- i = 0;
183
- for (const poolAddress of cfgInfo.poolAddresses) {
184
- const pool = cfgInfo.pools[poolAddress];
185
- for (const tokenAddress of pool.tokenAddresses) {
186
- const tokenSymbol = Platypus.erc20Interface.decodeFunctionResult(
187
- 'symbol',
188
- returnData[i++],
189
- )[0];
190
- const tokenDecimals = Platypus.erc20Interface.decodeFunctionResult(
191
- 'decimals',
192
- returnData[i++],
193
- )[0];
194
- const assetAddress = Platypus.poolInterface
195
- .decodeFunctionResult('assetOf', returnData[i++])[0]
196
- .toLowerCase();
197
- if (pool.oracleType === PlatypusOracleType.ChainLink) {
198
- const proxyAddress = Platypus.oracleInterface
199
- .decodeFunctionResult('getSourceOfAsset', returnData[i++])[0]
200
- .toLowerCase();
201
- pool.tokens[tokenAddress] = {
202
- tokenSymbol,
203
- tokenDecimals,
204
- assetAddress,
205
- chainlink: {
206
- proxyAddress,
207
- aggregatorAddress: '',
208
- },
209
- };
210
- } else {
211
- pool.tokens[tokenAddress] = {
212
- tokenSymbol,
213
- tokenDecimals,
214
- assetAddress,
215
- };
216
- }
217
- }
218
- }
219
- inputs = [];
220
- for (const poolAddress of cfgInfo.poolAddresses) {
221
- const pool = cfgInfo.pools[poolAddress];
222
- if (pool.oracleType === PlatypusOracleType.ChainLink) {
223
- for (const tokenAddress of pool.tokenAddresses) {
224
- inputs.push(
225
- ChainLinkSubscriber.getReadAggregatorMultiCallInput(
226
- pool.tokens[tokenAddress].chainlink.proxyAddress,
227
- ),
228
- );
229
- }
230
- }
231
- }
232
- returnData = (
233
- await this.dexHelper.multiContract.methods
234
- .aggregate(inputs)
235
- .call({}, blockNumber)
236
- ).returnData;
237
- i = 0;
238
- for (const poolAddress of cfgInfo.poolAddresses) {
239
- const pool = cfgInfo.pools[poolAddress];
240
- if (pool.oracleType === PlatypusOracleType.ChainLink) {
241
- for (const tokenAddress of pool.tokenAddresses) {
242
- pool.tokens[tokenAddress].chainlink.aggregatorAddress =
243
- ChainLinkSubscriber.readAggregator(returnData[i++]).toLowerCase();
244
- }
245
- }
246
- }
247
- return cfgInfo;
248
- }
249
-
250
- async init(blockNumber: number) {
251
- if (this.cfgInfo) return;
252
- this.cfgInfo = await this.generateConfigInfo(blockNumber);
253
- }
254
-
255
- // Initialize pricing is called once in the start of
256
- // pricing service. It is intended to setup the integration
257
- // for pricing requests. It is optional for a DEX to
258
- // implement this function
259
- async initializePricing(blockNumber: number) {
260
- await this.init(blockNumber);
261
- if (!this.cfgInfo)
262
- throw new Error(
263
- `initializePricing: ${this.dexKey} cfgInfo still null after init`,
264
- );
265
- const eventPools: {
266
- [poolAddress: string]: PlatypusPool | PlatypusPurePool | PlatypusAvaxPool;
267
- } = {};
268
- for (const poolAddress of this.cfgInfo.poolAddresses) {
269
- const cfgPool = this.cfgInfo.pools[poolAddress];
270
- const poolName = this.config.pools.find(
271
- p => p.address.toLowerCase() === poolAddress,
272
- )!.name;
273
- let pool: PlatypusPool | PlatypusPurePool | PlatypusAvaxPool;
274
- if (cfgPool.oracleType === PlatypusOracleType.None) {
275
- pool = new PlatypusPurePool(
276
- this.dexKey,
277
- this.network,
278
- poolName,
279
- poolAddress,
280
- cfgPool,
281
- this.dexHelper,
282
- );
283
- } else if (cfgPool.oracleType === PlatypusOracleType.ChainLink) {
284
- pool = new PlatypusPool(
285
- this.dexKey,
286
- this.network,
287
- poolName,
288
- poolAddress,
289
- cfgPool,
290
- this.dexHelper,
291
- );
292
- } else if (cfgPool.oracleType === PlatypusOracleType.StakedAvax) {
293
- pool = new PlatypusAvaxPool(
294
- this.dexKey,
295
- this.network,
296
- poolName,
297
- poolAddress,
298
- cfgPool,
299
- this.dexHelper,
300
- );
301
- } else {
302
- throw new Error(`${this.dexKey} cfgInfo invalid pool type`);
303
- }
304
- await pool.initialize(blockNumber);
305
- eventPools[poolAddress] = pool;
306
- }
307
- this.eventPools = eventPools;
308
- }
309
-
310
- // Returns the list of contract adapters (name and index)
311
- // for a buy/sell. Return null if there are no adapters.
312
- getAdapters(side: SwapSide): { name: string; index: number }[] | null {
313
- return this.adapters[side];
314
- }
315
-
316
- protected findPools(
317
- srcTokenAddress: Address,
318
- destTokenAddress: Address,
319
- ): Address[] {
320
- if (!this.cfgInfo) return [];
321
- return Object.entries(this.cfgInfo.pools)
322
- .filter(
323
- ([poolAddress, poolConfig]) =>
324
- poolConfig.tokenAddresses.includes(srcTokenAddress) &&
325
- poolConfig.tokenAddresses.includes(destTokenAddress),
326
- )
327
- .map(([poolAddress, poolConfig]) => poolAddress);
328
- }
329
-
330
- protected getPoolIdentifier(poolAddress: Address): string {
331
- return `${this.dexKey}_${poolAddress}`;
332
- }
333
-
334
- // Returns list of pool identifiers that can be used
335
- // for a given swap. poolIdentifers must be unique
336
- // across DEXes. It is recommended to use
337
- // ${dexKey}_${poolAddress} as a poolIdentifier
338
- async getPoolIdentifiers(
339
- srcToken: Token,
340
- destToken: Token,
341
- side: SwapSide,
342
- blockNumber: number,
343
- ): Promise<string[]> {
344
- if (side === SwapSide.BUY) return [];
345
- return this.findPools(
346
- this.dexHelper.config.wrapETH(srcToken).address.toLowerCase(),
347
- this.dexHelper.config.wrapETH(destToken).address.toLowerCase(),
348
- ).map(p => this.getPoolIdentifier(p));
349
- }
350
-
351
- // Returns pool prices for amounts.
352
- // If limitPools is defined only pools in limitPools
353
- // should be used. If limitPools is undefined then
354
- // any pools can be used.
355
- async getPricesVolume(
356
- srcToken: Token,
357
- destToken: Token,
358
- amounts: bigint[],
359
- side: SwapSide,
360
- blockNumber: number,
361
- limitPools?: string[],
362
- ): Promise<null | ExchangePrices<PlatypusData>> {
363
- if (side === SwapSide.BUY) return null;
364
- if (!this.eventPools) {
365
- this.logger.error(
366
- `Missing event pools for ${this.dexKey} in getPricesVolume`,
367
- );
368
- return null;
369
- }
370
- const srcTokenAddress = this.dexHelper.config
371
- .wrapETH(srcToken)
372
- .address.toLowerCase();
373
- const destTokenAddress = this.dexHelper.config
374
- .wrapETH(destToken)
375
- .address.toLowerCase();
376
- if (srcTokenAddress === destTokenAddress) return null;
377
- return (
378
- await Promise.all(
379
- this.findPools(srcTokenAddress, destTokenAddress)
380
- .filter(
381
- poolAddress =>
382
- !limitPools ||
383
- limitPools.includes(this.getPoolIdentifier(poolAddress)),
384
- )
385
- .map(poolAddress =>
386
- (async <P>(
387
- pool: P extends PlatypusPoolBase<infer S> ? P : never,
388
- ) => {
389
- let state = pool.getState(blockNumber);
390
- if (!state) {
391
- state = await pool.generateState(blockNumber);
392
- pool.setState(state, blockNumber);
393
- }
394
- if (state.params.paused) return null;
395
- const [unit, ...prices] = pool.computePrices(
396
- {
397
- address: srcTokenAddress,
398
- decimals: srcToken.decimals,
399
- },
400
- {
401
- address: destTokenAddress,
402
- decimals: destToken.decimals,
403
- },
404
- [getBigIntPow(srcToken.decimals), ...amounts],
405
- state,
406
- );
407
- const ret: PoolPrices<PlatypusData> = {
408
- prices,
409
- unit,
410
- data: {
411
- pool: poolAddress,
412
- },
413
- poolAddresses: [poolAddress],
414
- exchange: this.dexKey,
415
- gasCost: 260 * 1000,
416
- poolIdentifier: this.getPoolIdentifier(poolAddress),
417
- };
418
- return ret;
419
- })(this.eventPools![poolAddress]),
420
- ),
421
- )
422
- ).filter((p): p is PoolPrices<PlatypusData> => !!p);
423
- }
424
-
425
- // Returns estimated gas cost of calldata for this DEX in multiSwap
426
- getCalldataGasCost(poolPrices: PoolPrices<PlatypusData>): number | number[] {
427
- return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
428
- }
429
-
430
- // Encode params required by the exchange adapter
431
- // Used for multiSwap, buy & megaSwap
432
- // Hint: abiCoder.encodeParameter() couls be useful
433
- getAdapterParam(
434
- srcToken: string,
435
- destToken: string,
436
- srcAmount: string,
437
- destAmount: string,
438
- data: PlatypusData,
439
- side: SwapSide,
440
- ): AdapterExchangeParam {
441
- return {
442
- targetExchange: data.pool,
443
- payload: '0x',
444
- networkFee: '0',
445
- };
446
- }
447
-
448
- // Encode call data used by simpleSwap like routers
449
- // Used for simpleSwap & simpleBuy
450
- // Hint: this.buildSimpleParamWithoutWETHConversion
451
- // could be useful
452
- async getSimpleParam(
453
- srcToken: string,
454
- destToken: string,
455
- srcAmount: string,
456
- destAmount: string,
457
- data: PlatypusData,
458
- side: SwapSide,
459
- ): Promise<SimpleExchangeParam> {
460
- return this.buildSimpleParamWithoutWETHConversion(
461
- srcToken,
462
- srcAmount,
463
- destToken,
464
- destAmount,
465
- isETHAddress(srcToken)
466
- ? Platypus.avaxPoolInterface.encodeFunctionData('swapFromETH', [
467
- destToken,
468
- 1,
469
- this.augustusAddress,
470
- getLocalDeadlineAsFriendlyPlaceholder(),
471
- ])
472
- : isETHAddress(destToken)
473
- ? Platypus.avaxPoolInterface.encodeFunctionData('swapToETH', [
474
- srcToken,
475
- srcAmount,
476
- 1,
477
- this.augustusAddress,
478
- getLocalDeadlineAsFriendlyPlaceholder(),
479
- ])
480
- : Platypus.poolInterface.encodeFunctionData('swap', [
481
- srcToken,
482
- destToken,
483
- srcAmount,
484
- 1,
485
- this.augustusAddress,
486
- getLocalDeadlineAsFriendlyPlaceholder(),
487
- ]),
488
- data.pool,
489
- );
490
- }
491
-
492
- getDexParam(
493
- srcToken: Address,
494
- destToken: Address,
495
- srcAmount: NumberAsString,
496
- destAmount: NumberAsString,
497
- recipient: Address,
498
- data: PlatypusData,
499
- side: SwapSide,
500
- ): DexExchangeParam {
501
- const iface = isETHAddress(srcToken)
502
- ? Platypus.avaxPoolInterface
503
- : isETHAddress(destToken)
504
- ? Platypus.avaxPoolInterface
505
- : Platypus.poolInterface;
506
-
507
- const swapFunction = isETHAddress(srcToken)
508
- ? 'swapFromETH'
509
- : isETHAddress(destToken)
510
- ? 'swapToETH'
511
- : 'swap';
512
-
513
- const swapData = isETHAddress(srcToken)
514
- ? iface.encodeFunctionData(swapFunction, [
515
- destToken,
516
- 1,
517
- recipient,
518
- getLocalDeadlineAsFriendlyPlaceholder(),
519
- ])
520
- : isETHAddress(destToken)
521
- ? iface.encodeFunctionData(swapFunction, [
522
- srcToken,
523
- srcAmount,
524
- 1,
525
- recipient,
526
- getLocalDeadlineAsFriendlyPlaceholder(),
527
- ])
528
- : iface.encodeFunctionData(swapFunction, [
529
- srcToken,
530
- destToken,
531
- srcAmount,
532
- 1,
533
- recipient,
534
- getLocalDeadlineAsFriendlyPlaceholder(),
535
- ]);
536
-
537
- return {
538
- needWrapNative: this.needWrapNative,
539
- dexFuncHasRecipient: true,
540
- exchangeData: swapData,
541
- targetExchange: data.pool,
542
- returnAmountPos:
543
- side === SwapSide.SELL
544
- ? extractReturnAmountPosition(iface, swapFunction, 'actualToAmount')
545
- : undefined,
546
- };
547
- }
548
-
549
- // This is called once before getTopPoolsForToken is
550
- // called for multiple tokens. This can be helpful to
551
- // update common state required for calculating
552
- // getTopPoolsForToken. It is optional for a DEX
553
- // to implement this
554
- async updatePoolState(): Promise<void> {
555
- const blockNumber = await this.dexHelper.web3Provider.eth.getBlockNumber();
556
- await this.init(blockNumber);
557
- if (!this.cfgInfo)
558
- throw new Error(
559
- 'updatePoolState: Platypus cfgInfo still null after init',
560
- );
561
-
562
- // All tokens are USD stablecoins so to estimate liquidity can just add
563
- // the cash balances of all the tokens
564
- const poolLiquidityUSD: { [poolAddress: string]: number } = {};
565
- let inputs: MultiCallInput[] = [];
566
- for (const poolAddress of this.cfgInfo.poolAddresses) {
567
- for (const tokenAddress of this.cfgInfo.pools[poolAddress]
568
- .tokenAddresses) {
569
- inputs.push({
570
- target:
571
- this.cfgInfo.pools[poolAddress].tokens[tokenAddress].assetAddress,
572
- callData: Platypus.assetInterface.encodeFunctionData('cash'),
573
- });
574
- }
575
- }
576
- const returnData = (
577
- await this.dexHelper.multiContract.methods
578
- .aggregate(inputs)
579
- .call({}, blockNumber)
580
- ).returnData;
581
- const usdPromises = [];
582
- let i = 0;
583
- for (const poolAddress of this.cfgInfo.poolAddresses) {
584
- for (const tokenAddress of this.cfgInfo.pools[poolAddress]
585
- .tokenAddresses) {
586
- usdPromises.push(
587
- this.dexHelper.getTokenUSDPrice(
588
- {
589
- address: tokenAddress,
590
- decimals:
591
- this.cfgInfo.pools[poolAddress].tokens[tokenAddress]
592
- .tokenDecimals,
593
- },
594
- BigInt(
595
- Platypus.assetInterface
596
- .decodeFunctionResult('cash', returnData[i++])[0]
597
- .toString(),
598
- ),
599
- ),
600
- );
601
- }
602
- }
603
- const usdValues = await Promise.all(usdPromises);
604
- i = 0;
605
- for (const poolAddress of this.cfgInfo.poolAddresses) {
606
- poolLiquidityUSD[poolAddress] = 0;
607
- for (const tokenAddress of this.cfgInfo.pools[poolAddress]
608
- .tokenAddresses) {
609
- poolLiquidityUSD[poolAddress] += usdValues[i++];
610
- }
611
- }
612
- this.poolLiquidityUSD = poolLiquidityUSD;
613
- }
614
-
615
- // Returns list of top pools based on liquidity. Max
616
- // limit number pools should be returned.
617
- async getTopPoolsForToken(
618
- tokenAddress: Address,
619
- limit: number,
620
- ): Promise<PoolLiquidity[]> {
621
- if (!this.cfgInfo || !this.poolLiquidityUSD) await this.updatePoolState();
622
- tokenAddress = tokenAddress.toLowerCase();
623
- const pools = this.cfgInfo!.poolAddresses.filter(
624
- poolAddress => !!this.cfgInfo!.pools[poolAddress].tokens[tokenAddress],
625
- );
626
- pools.sort((a, b) => this.poolLiquidityUSD![b] - this.poolLiquidityUSD![a]);
627
- return pools.slice(0, limit).map(poolAddress => ({
628
- exchange: this.dexKey,
629
- address: poolAddress,
630
- connectorTokens: this.cfgInfo!.pools[poolAddress].tokenAddresses.filter(
631
- t => t !== tokenAddress,
632
- ).map(t => ({
633
- decimals: this.cfgInfo!.pools[poolAddress].tokens[t].tokenDecimals,
634
- address: t,
635
- })),
636
- liquidityUSD: this.poolLiquidityUSD![poolAddress],
637
- }));
638
- }
639
- }