@paraswap/dex-lib 3.8.2 → 3.8.3-integral-dex

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 (403) hide show
  1. package/.vscode/launch.json +13 -0
  2. package/.vscode/settings.json +3 -0
  3. package/build/abi/AaveV1_lending_pool.json +27 -0
  4. package/build/abi/Uncompressor.json +250 -0
  5. package/build/abi/integral/factory.json +333 -0
  6. package/build/abi/integral/oracle.json +501 -0
  7. package/build/abi/integral/pool.json +1041 -0
  8. package/build/abi/integral/relayer.json +1536 -0
  9. package/build/abi/oswap/oswap.abi.json +452 -0
  10. package/build/abi/platypus/asset.json +490 -0
  11. package/build/abi/platypus/avax-pool.json +820 -0
  12. package/build/abi/platypus/oracle.json +119 -0
  13. package/build/abi/platypus/pool.json +677 -0
  14. package/build/abi/smardex/all/smardex-router.json +648 -0
  15. package/build/abi/smardex/layer-1/smardex-factory.json +242 -0
  16. package/build/abi/smardex/layer-1/smardex-pool.json +506 -0
  17. package/build/abi/smardex/layer-2/smardex-factory.json +185 -0
  18. package/build/abi/smardex/layer-2/smardex-pool.json +578 -0
  19. package/build/abi/swaap-v1/pool.json +1346 -0
  20. package/build/config.js +1 -1
  21. package/build/dex/aave-v1/aave-v1.d.ts +33 -0
  22. package/build/dex/aave-v1/aave-v1.js +158 -0
  23. package/build/dex/aave-v1/aave-v1.js.map +1 -0
  24. package/build/dex/aave-v1/config.d.ts +11 -0
  25. package/build/dex/aave-v1/config.js +20 -0
  26. package/build/dex/aave-v1/config.js.map +1 -0
  27. package/build/dex/aave-v1/tokens-mainnet.json +134 -0
  28. package/build/dex/aave-v1/tokens.d.ts +3 -0
  29. package/build/dex/aave-v1/tokens.js +50 -0
  30. package/build/dex/aave-v1/tokens.js.map +1 -0
  31. package/build/dex/aave-v1/types.d.ts +12 -0
  32. package/build/dex/aave-v1/types.js +3 -0
  33. package/build/dex/aave-v1/types.js.map +1 -0
  34. package/build/dex/bProtocol.d.ts +18 -0
  35. package/build/dex/bProtocol.js +39 -0
  36. package/build/dex/bProtocol.js.map +1 -0
  37. package/build/dex/bancor.d.ts +26 -0
  38. package/build/dex/bancor.js +58 -0
  39. package/build/dex/bancor.js.map +1 -0
  40. package/build/dex/compound.d.ts +18 -0
  41. package/build/dex/compound.js +46 -0
  42. package/build/dex/compound.js.map +1 -0
  43. package/build/dex/curve-v1-factory/config.js +10 -47
  44. package/build/dex/curve-v1-factory/config.js.map +1 -1
  45. package/build/dex/curve-v1-factory/curve-v1-factory.d.ts +2 -2
  46. package/build/dex/curve-v1-factory/curve-v1-factory.js +36 -96
  47. package/build/dex/curve-v1-factory/curve-v1-factory.js.map +1 -1
  48. package/build/dex/curve-v1-factory/price-handlers/functions/constants.js.map +1 -1
  49. package/build/dex/curve-v1-factory/price-handlers/functions/get_dx.js +1 -13
  50. package/build/dex/curve-v1-factory/price-handlers/functions/get_dx.js.map +1 -1
  51. package/build/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.d.ts +2 -2
  52. package/build/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.js +1 -1
  53. package/build/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.js.map +1 -1
  54. package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.js +1 -1
  55. package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.js.map +1 -1
  56. package/build/dex/curve-v1-factory/state-polling-pools/pool-polling-base.d.ts +3 -4
  57. package/build/dex/curve-v1-factory/state-polling-pools/pool-polling-base.js +9 -24
  58. package/build/dex/curve-v1-factory/state-polling-pools/pool-polling-base.js.map +1 -1
  59. package/build/dex/curve-v1-factory/types.d.ts +4 -20
  60. package/build/dex/curve-v1-factory/types.js +3 -11
  61. package/build/dex/curve-v1-factory/types.js.map +1 -1
  62. package/build/dex/curve-v1-stable-ng/config.js +0 -18
  63. package/build/dex/curve-v1-stable-ng/config.js.map +1 -1
  64. package/build/dex/curve-v2.d.ts +58 -0
  65. package/build/dex/curve-v2.js +180 -0
  66. package/build/dex/curve-v2.js.map +1 -0
  67. package/build/dex/dodo-v1.d.ts +33 -0
  68. package/build/dex/dodo-v1.js +63 -0
  69. package/build/dex/dodo-v1.js.map +1 -0
  70. package/build/dex/etherfi/etherfi.d.ts +26 -0
  71. package/build/dex/etherfi/etherfi.js +96 -0
  72. package/build/dex/etherfi/etherfi.js.map +1 -0
  73. package/build/dex/index.js +21 -3
  74. package/build/dex/index.js.map +1 -1
  75. package/build/dex/integral/config.d.ts +4 -0
  76. package/build/dex/integral/config.js +20 -0
  77. package/build/dex/integral/config.js.map +1 -0
  78. package/build/dex/integral/context.d.ts +40 -0
  79. package/build/dex/integral/context.js +158 -0
  80. package/build/dex/integral/context.js.map +1 -0
  81. package/build/dex/integral/helpers.d.ts +17 -0
  82. package/build/dex/integral/helpers.js +157 -0
  83. package/build/dex/integral/helpers.js.map +1 -0
  84. package/build/dex/integral/integral-factory.d.ts +21 -0
  85. package/build/dex/integral/integral-factory.js +92 -0
  86. package/build/dex/integral/integral-factory.js.map +1 -0
  87. package/build/dex/integral/integral-pool.d.ts +46 -0
  88. package/build/dex/integral/integral-pool.js +143 -0
  89. package/build/dex/integral/integral-pool.js.map +1 -0
  90. package/build/dex/integral/integral-pricing.d.ts +18 -0
  91. package/build/dex/integral/integral-pricing.js +114 -0
  92. package/build/dex/integral/integral-pricing.js.map +1 -0
  93. package/build/dex/integral/integral-relayer.d.ts +39 -0
  94. package/build/dex/integral/integral-relayer.js +189 -0
  95. package/build/dex/integral/integral-relayer.js.map +1 -0
  96. package/build/dex/integral/integral-token.d.ts +24 -0
  97. package/build/dex/integral/integral-token.js +56 -0
  98. package/build/dex/integral/integral-token.js.map +1 -0
  99. package/build/dex/integral/integral.d.ts +41 -0
  100. package/build/dex/integral/integral.js +377 -0
  101. package/build/dex/integral/integral.js.map +1 -0
  102. package/build/dex/integral/types.d.ts +84 -0
  103. package/build/dex/integral/types.js +9 -0
  104. package/build/dex/integral/types.js.map +1 -0
  105. package/build/dex/integral/utils-e2e.d.ts +9 -0
  106. package/build/dex/integral/utils-e2e.js +131 -0
  107. package/build/dex/integral/utils-e2e.js.map +1 -0
  108. package/build/dex/integral/utils.d.ts +17 -0
  109. package/build/dex/integral/utils.js +94 -0
  110. package/build/dex/integral/utils.js.map +1 -0
  111. package/build/dex/lido.d.ts +19 -0
  112. package/build/dex/lido.js +42 -0
  113. package/build/dex/lido.js.map +1 -0
  114. package/build/dex/onebit.d.ts +25 -0
  115. package/build/dex/onebit.js +42 -0
  116. package/build/dex/onebit.js.map +1 -0
  117. package/build/dex/oswap/config.d.ts +5 -0
  118. package/build/dex/oswap/config.js +31 -0
  119. package/build/dex/oswap/config.js.map +1 -0
  120. package/build/dex/oswap/oswap-pool.d.ts +51 -0
  121. package/build/dex/oswap/oswap-pool.js +150 -0
  122. package/build/dex/oswap/oswap-pool.js.map +1 -0
  123. package/build/dex/oswap/oswap.d.ts +46 -0
  124. package/build/dex/oswap/oswap.js +266 -0
  125. package/build/dex/oswap/oswap.js.map +1 -0
  126. package/build/dex/oswap/types.d.ts +20 -0
  127. package/build/dex/oswap/types.js +3 -0
  128. package/build/dex/oswap/types.js.map +1 -0
  129. package/build/dex/paraswap-limit-orders/paraswap-limit-orders.js +0 -3
  130. package/build/dex/paraswap-limit-orders/paraswap-limit-orders.js.map +1 -1
  131. package/build/dex/platypus/asset.d.ts +14 -0
  132. package/build/dex/platypus/asset.js +97 -0
  133. package/build/dex/platypus/asset.js.map +1 -0
  134. package/build/dex/platypus/config.d.ts +11 -0
  135. package/build/dex/platypus/config.js +69 -0
  136. package/build/dex/platypus/config.js.map +1 -0
  137. package/build/dex/platypus/platypus.d.ts +62 -0
  138. package/build/dex/platypus/platypus.js +442 -0
  139. package/build/dex/platypus/platypus.js.map +1 -0
  140. package/build/dex/platypus/pool-avax.d.ts +8 -0
  141. package/build/dex/platypus/pool-avax.js +54 -0
  142. package/build/dex/platypus/pool-avax.js.map +1 -0
  143. package/build/dex/platypus/pool-base.d.ts +19 -0
  144. package/build/dex/platypus/pool-base.js +86 -0
  145. package/build/dex/platypus/pool-base.js.map +1 -0
  146. package/build/dex/platypus/pool-pure.d.ts +8 -0
  147. package/build/dex/platypus/pool-pure.js +37 -0
  148. package/build/dex/platypus/pool-pure.js.map +1 -0
  149. package/build/dex/platypus/pool-subscriber.d.ts +14 -0
  150. package/build/dex/platypus/pool-subscriber.js +167 -0
  151. package/build/dex/platypus/pool-subscriber.js.map +1 -0
  152. package/build/dex/platypus/pool.d.ts +8 -0
  153. package/build/dex/platypus/pool.js +58 -0
  154. package/build/dex/platypus/pool.js.map +1 -0
  155. package/build/dex/platypus/types.d.ts +92 -0
  156. package/build/dex/platypus/types.js +10 -0
  157. package/build/dex/platypus/types.js.map +1 -0
  158. package/build/dex/quickswap/spiritswap-v3.d.ts +6 -0
  159. package/build/dex/quickswap/spiritswap-v3.js +19 -0
  160. package/build/dex/quickswap/spiritswap-v3.js.map +1 -0
  161. package/build/dex/sdai/config.d.ts +11 -0
  162. package/build/dex/sdai/config.js +21 -0
  163. package/build/dex/sdai/config.js.map +1 -0
  164. package/build/dex/sdai/constants.d.ts +2 -0
  165. package/build/dex/sdai/constants.js +6 -0
  166. package/build/dex/sdai/constants.js.map +1 -0
  167. package/build/dex/sdai/scripts/validate-state.d.ts +1 -0
  168. package/build/dex/sdai/scripts/validate-state.js +102 -0
  169. package/build/dex/sdai/scripts/validate-state.js.map +1 -0
  170. package/build/dex/sdai/sdai-pool.d.ts +16 -0
  171. package/build/dex/sdai/sdai-pool.js +85 -0
  172. package/build/dex/sdai/sdai-pool.js.map +1 -0
  173. package/build/dex/sdai/sdai.d.ts +51 -0
  174. package/build/dex/sdai/sdai.js +172 -0
  175. package/build/dex/sdai/sdai.js.map +1 -0
  176. package/build/dex/sdai/types.d.ts +21 -0
  177. package/build/dex/sdai/types.js +11 -0
  178. package/build/dex/sdai/types.js.map +1 -0
  179. package/build/dex/sdai/utils.d.ts +4 -0
  180. package/build/dex/sdai/utils.js +39 -0
  181. package/build/dex/sdai/utils.js.map +1 -0
  182. package/build/dex/smardex/config.d.ts +4 -0
  183. package/build/dex/smardex/config.js +64 -0
  184. package/build/dex/smardex/config.js.map +1 -0
  185. package/build/dex/smardex/constants.d.ts +18 -0
  186. package/build/dex/smardex/constants.js +33 -0
  187. package/build/dex/smardex/constants.js.map +1 -0
  188. package/build/dex/smardex/sdk/constants.d.ts +6 -0
  189. package/build/dex/smardex/sdk/constants.js +13 -0
  190. package/build/dex/smardex/sdk/constants.js.map +1 -0
  191. package/build/dex/smardex/sdk/core.d.ts +113 -0
  192. package/build/dex/smardex/sdk/core.js +499 -0
  193. package/build/dex/smardex/sdk/core.js.map +1 -0
  194. package/build/dex/smardex/sdk/errors.d.ts +15 -0
  195. package/build/dex/smardex/sdk/errors.js +22 -0
  196. package/build/dex/smardex/sdk/errors.js.map +1 -0
  197. package/build/dex/smardex/sdk/types.d.ts +62 -0
  198. package/build/dex/smardex/sdk/types.js +3 -0
  199. package/build/dex/smardex/sdk/types.js.map +1 -0
  200. package/build/dex/smardex/sdk/utils.d.ts +44 -0
  201. package/build/dex/smardex/sdk/utils.js +133 -0
  202. package/build/dex/smardex/sdk/utils.js.map +1 -0
  203. package/build/dex/smardex/smardex-event-pool.d.ts +28 -0
  204. package/build/dex/smardex/smardex-event-pool.js +119 -0
  205. package/build/dex/smardex/smardex-event-pool.js.map +1 -0
  206. package/build/dex/smardex/smardex.d.ts +65 -0
  207. package/build/dex/smardex/smardex.js +519 -0
  208. package/build/dex/smardex/smardex.js.map +1 -0
  209. package/build/dex/smardex/types.d.ts +55 -0
  210. package/build/dex/smardex/types.js +3 -0
  211. package/build/dex/smardex/types.js.map +1 -0
  212. package/build/dex/smoothy.d.ts +26 -0
  213. package/build/dex/smoothy.js +48 -0
  214. package/build/dex/smoothy.js.map +1 -0
  215. package/build/dex/solidly/forks-override/cone.d.ts +22 -0
  216. package/build/dex/solidly/forks-override/cone.js +53 -0
  217. package/build/dex/solidly/forks-override/cone.js.map +1 -0
  218. package/build/dex/solidly/forks-override/solisnek.d.ts +8 -0
  219. package/build/dex/solidly/forks-override/solisnek.js +15 -0
  220. package/build/dex/solidly/forks-override/solisnek.js.map +1 -0
  221. package/build/dex/stable-pool.d.ts +28 -0
  222. package/build/dex/stable-pool.js +62 -0
  223. package/build/dex/stable-pool.js.map +1 -0
  224. package/build/dex/swaap-v1/config.d.ts +17 -0
  225. package/build/dex/swaap-v1/config.js +56 -0
  226. package/build/dex/swaap-v1/config.js.map +1 -0
  227. package/build/dex/swaap-v1/constants.d.ts +6 -0
  228. package/build/dex/swaap-v1/constants.js +17 -0
  229. package/build/dex/swaap-v1/constants.js.map +1 -0
  230. package/build/dex/swaap-v1/libraries/ChainlinkUtils.d.ts +25 -0
  231. package/build/dex/swaap-v1/libraries/ChainlinkUtils.js +62 -0
  232. package/build/dex/swaap-v1/libraries/ChainlinkUtils.js.map +1 -0
  233. package/build/dex/swaap-v1/libraries/Const.d.ts +18 -0
  234. package/build/dex/swaap-v1/libraries/Const.js +26 -0
  235. package/build/dex/swaap-v1/libraries/Const.js.map +1 -0
  236. package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.d.ts +77 -0
  237. package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.js +316 -0
  238. package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.js.map +1 -0
  239. package/build/dex/swaap-v1/libraries/LogExpMath.d.ts +75 -0
  240. package/build/dex/swaap-v1/libraries/LogExpMath.js +418 -0
  241. package/build/dex/swaap-v1/libraries/LogExpMath.js.map +1 -0
  242. package/build/dex/swaap-v1/libraries/MathMMM.d.ts +185 -0
  243. package/build/dex/swaap-v1/libraries/MathMMM.js +453 -0
  244. package/build/dex/swaap-v1/libraries/MathMMM.js.map +1 -0
  245. package/build/dex/swaap-v1/libraries/Num.d.ts +31 -0
  246. package/build/dex/swaap-v1/libraries/Num.js +167 -0
  247. package/build/dex/swaap-v1/libraries/Num.js.map +1 -0
  248. package/build/dex/swaap-v1/libraries/PoolQuotations.d.ts +23 -0
  249. package/build/dex/swaap-v1/libraries/PoolQuotations.js +131 -0
  250. package/build/dex/swaap-v1/libraries/PoolQuotations.js.map +1 -0
  251. package/build/dex/swaap-v1/libraries/Struct.d.ts +56 -0
  252. package/build/dex/swaap-v1/libraries/Struct.js +3 -0
  253. package/build/dex/swaap-v1/libraries/Struct.js.map +1 -0
  254. package/build/dex/swaap-v1/swaap-v1-pool.d.ts +45 -0
  255. package/build/dex/swaap-v1/swaap-v1-pool.js +656 -0
  256. package/build/dex/swaap-v1/swaap-v1-pool.js.map +1 -0
  257. package/build/dex/swaap-v1/swaap-v1.d.ts +61 -0
  258. package/build/dex/swaap-v1/swaap-v1.js +369 -0
  259. package/build/dex/swaap-v1/swaap-v1.js.map +1 -0
  260. package/build/dex/swaap-v1/types.d.ts +106 -0
  261. package/build/dex/swaap-v1/types.js +9 -0
  262. package/build/dex/swaap-v1/types.js.map +1 -0
  263. package/build/dex/trader-joe-v2.1.d.ts +43 -0
  264. package/build/dex/trader-joe-v2.1.js +79 -0
  265. package/build/dex/trader-joe-v2.1.js.map +1 -0
  266. package/build/dex/uniswap-v3/contract-math/Oracle.js +4 -4
  267. package/build/dex/uniswap-v3/contract-math/Oracle.js.map +1 -1
  268. package/build/executor/compressor/Compressor.d.ts +23 -0
  269. package/build/executor/compressor/Compressor.js +144 -0
  270. package/build/executor/compressor/Compressor.js.map +1 -0
  271. package/build/executor/compressor/compress.d.ts +17 -0
  272. package/build/executor/compressor/compress.js +187 -0
  273. package/build/executor/compressor/compress.js.map +1 -0
  274. package/build/executor/compressor/compress_functions/addressSubstitution.d.ts +6 -0
  275. package/build/executor/compressor/compress_functions/addressSubstitution.js +29 -0
  276. package/build/executor/compressor/compress_functions/addressSubstitution.js.map +1 -0
  277. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.d.ts +10 -0
  278. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.js +40 -0
  279. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.js.map +1 -0
  280. package/build/executor/compressor/compress_functions/byteSubstitution.d.ts +11 -0
  281. package/build/executor/compressor/compress_functions/byteSubstitution.js +64 -0
  282. package/build/executor/compressor/compress_functions/byteSubstitution.js.map +1 -0
  283. package/build/executor/compressor/compress_functions/ffSubstitution.d.ts +7 -0
  284. package/build/executor/compressor/compress_functions/ffSubstitution.js +54 -0
  285. package/build/executor/compressor/compress_functions/ffSubstitution.js.map +1 -0
  286. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.d.ts +8 -0
  287. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.js +67 -0
  288. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.js.map +1 -0
  289. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.d.ts +8 -0
  290. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.js +61 -0
  291. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.js.map +1 -0
  292. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.d.ts +6 -0
  293. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.js +37 -0
  294. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.js.map +1 -0
  295. package/build/executor/compressor/compress_functions/searchUnusedBytes.d.ts +9 -0
  296. package/build/executor/compressor/compress_functions/searchUnusedBytes.js +33 -0
  297. package/build/executor/compressor/compress_functions/searchUnusedBytes.js.map +1 -0
  298. package/build/executor/compressor/fetchSaved.d.ts +0 -0
  299. package/build/executor/compressor/fetchSaved.js +17 -0
  300. package/build/executor/compressor/fetchSaved.js.map +1 -0
  301. package/build/executor/compressor/utils/computeCostL2.d.ts +2 -0
  302. package/build/executor/compressor/utils/computeCostL2.js +14 -0
  303. package/build/executor/compressor/utils/computeCostL2.js.map +1 -0
  304. package/build/executor/compressor/utils/findLongestDuplicatedString.d.ts +2 -0
  305. package/build/executor/compressor/utils/findLongestDuplicatedString.js +30 -0
  306. package/build/executor/compressor/utils/findLongestDuplicatedString.js.map +1 -0
  307. package/build/executor/compressor/utils/getAllIndexes.d.ts +2 -0
  308. package/build/executor/compressor/utils/getAllIndexes.js +12 -0
  309. package/build/executor/compressor/utils/getAllIndexes.js.map +1 -0
  310. package/build/executor/compressor/utils/getByteForAddress.d.ts +2 -0
  311. package/build/executor/compressor/utils/getByteForAddress.js +14 -0
  312. package/build/executor/compressor/utils/getByteForAddress.js.map +1 -0
  313. package/build/executor/compressor/utils/intTo2Bytes.d.ts +2 -0
  314. package/build/executor/compressor/utils/intTo2Bytes.js +14 -0
  315. package/build/executor/compressor/utils/intTo2Bytes.js.map +1 -0
  316. package/build/executor/compressor/utils/intTo3Bytes.d.ts +2 -0
  317. package/build/executor/compressor/utils/intTo3Bytes.js +18 -0
  318. package/build/executor/compressor/utils/intTo3Bytes.js.map +1 -0
  319. package/build/executor/compressor/utils/intToByte.d.ts +2 -0
  320. package/build/executor/compressor/utils/intToByte.js +10 -0
  321. package/build/executor/compressor/utils/intToByte.js.map +1 -0
  322. package/build/generic-swap-transaction-builder.js +3 -1
  323. package/build/generic-swap-transaction-builder.js.map +1 -1
  324. package/build/router/simpleswap.js +3 -1
  325. package/build/router/simpleswap.js.map +1 -1
  326. package/package.json +2 -2
  327. package/src/abi/BProtocol.json +1155 -0
  328. package/src/abi/Jarvis.json +1172 -0
  329. package/src/abi/MStableAsset.json +1545 -0
  330. package/src/abi/OneInchLp.json +1304 -0
  331. package/src/abi/Onebit.json +736 -0
  332. package/src/abi/Shell.json +1294 -0
  333. package/src/abi/TraderJoeV2Router.json +50 -0
  334. package/src/abi/integral/factory.json +333 -0
  335. package/src/abi/integral/oracle.json +501 -0
  336. package/src/abi/integral/pool.json +1041 -0
  337. package/src/abi/integral/relayer.json +1536 -0
  338. package/src/abi/zrx.v2.json +1967 -0
  339. package/src/abi/zrx.v3.json +3454 -0
  340. package/src/abi/zrx.v4.json +2193 -0
  341. package/src/config.ts +1 -1
  342. package/src/dex/OneInchLp.ts +84 -0
  343. package/src/dex/bProtocol/bProtocol-e2e.test.ts +93 -0
  344. package/src/dex/bProtocol/bProtocol.ts +108 -0
  345. package/src/dex/bProtocol/types.ts +13 -0
  346. package/src/dex/curve-v1-factory/config.ts +10 -47
  347. package/src/dex/curve-v1-factory/curve-v1-factory-e2e.test.ts +16 -92
  348. package/src/dex/curve-v1-factory/curve-v1-factory-integration.test.ts +5 -125
  349. package/src/dex/curve-v1-factory/curve-v1-factory.ts +45 -137
  350. package/src/dex/curve-v1-factory/price-handlers/functions/constants.ts +2 -0
  351. package/src/dex/curve-v1-factory/price-handlers/functions/get_dx.ts +1 -24
  352. package/src/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.ts +2 -3
  353. package/src/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.ts +0 -1
  354. package/src/dex/curve-v1-factory/state-polling-pools/pool-polling-base.ts +10 -31
  355. package/src/dex/curve-v1-factory/types.ts +6 -22
  356. package/src/dex/curve-v1-stable-ng/config.ts +0 -18
  357. package/src/dex/curve-v1-stable-ng/curve-v1-stable-ng-e2e.test.ts +0 -17
  358. package/src/dex/index.ts +20 -3
  359. package/src/dex/integral/config.ts +20 -0
  360. package/src/dex/integral/context.ts +287 -0
  361. package/src/dex/integral/integral-e2e.test.ts +86 -0
  362. package/src/dex/integral/integral-events.test.ts +412 -0
  363. package/src/dex/integral/integral-factory.ts +146 -0
  364. package/src/dex/integral/integral-integration.test.ts +221 -0
  365. package/src/dex/integral/integral-pool.ts +198 -0
  366. package/src/dex/integral/integral-pricing.ts +190 -0
  367. package/src/dex/integral/integral-relayer.ts +285 -0
  368. package/src/dex/integral/integral-token.ts +95 -0
  369. package/src/dex/integral/integral.ts +523 -0
  370. package/src/dex/integral/test-artifacts/configs.json +1 -0
  371. package/src/dex/integral/test-artifacts/logs.json +1 -0
  372. package/src/dex/integral/test-artifacts/states.json +1 -0
  373. package/src/dex/integral/types.ts +88 -0
  374. package/src/dex/integral/utils-e2e.ts +194 -0
  375. package/src/dex/integral/utils.ts +146 -0
  376. package/src/dex/jarvis.ts +262 -0
  377. package/src/dex/mStable.ts +147 -0
  378. package/src/dex/onebit/onebit.ts +113 -0
  379. package/src/dex/onebit/types.ts +17 -0
  380. package/src/dex/paraswap-limit-orders/paraswap-limit-orders-e2e.test.ts +68 -152
  381. package/src/dex/paraswap-limit-orders/paraswap-limit-orders.ts +0 -3
  382. package/src/dex/shell.ts +84 -0
  383. package/src/dex/trader-joe-v2.ts +148 -0
  384. package/src/dex/uniswap-v3/contract-math/Oracle.ts +5 -4
  385. package/src/dex/zerox/config.ts +31 -0
  386. package/src/dex/zerox/index.ts +328 -0
  387. package/src/dex/zerox/order.ts +62 -0
  388. package/src/dex/zerox/types.ts +82 -0
  389. package/src/dex/zerox/zerox-e2e.test.ts +110 -0
  390. package/src/generic-swap-transaction-builder.ts +3 -1
  391. package/src/router/simpleswap.ts +3 -1
  392. package/tests/constants-e2e.ts +2 -2
  393. package/tests/utils-e2e.ts +0 -2
  394. package/.idea/aws.xml +0 -17
  395. package/.idea/codeStyles/Project.xml +0 -19
  396. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  397. package/.idea/misc.xml +0 -6
  398. package/.idea/modules.xml +0 -8
  399. package/.idea/paraswap-dex-lib.iml +0 -9
  400. package/.idea/prettier.xml +0 -7
  401. package/.idea/vcs.xml +0 -6
  402. package/src/abi/curve-v1-factory/CurveV1Router.abi.json +0 -331
  403. package/src/dex/curve-v1-factory/optimizer.ts +0 -61
@@ -0,0 +1,221 @@
1
+ /* eslint-disable no-console */
2
+ import dotenv from 'dotenv';
3
+ dotenv.config();
4
+
5
+ import { DummyDexHelper } from '../../dex-helper/index';
6
+ import { Network, SwapSide } from '../../constants';
7
+ import { BI_POWS } from '../../bigint-constants';
8
+ import { Integral } from './integral';
9
+ import {
10
+ checkPoolPrices,
11
+ checkPoolsLiquidity,
12
+ checkConstantPoolPrices,
13
+ } from '../../../tests/utils';
14
+ import { Tokens } from '../../../tests/constants-e2e';
15
+ import { Token } from '../../types';
16
+ import { IntegralConfig } from './config';
17
+ import IntegralRelayerABI from '../../abi/integral/relayer.json';
18
+ import { Interface } from '@ethersproject/abi';
19
+ import { uint256ToBigInt } from '../../lib/decoders';
20
+ import { MultiCallParams } from '../../lib/multi-wrapper';
21
+
22
+ jest.setTimeout(50 * 1000);
23
+ const network = Network.MAINNET;
24
+ const testDatas: {
25
+ tokenA: Token;
26
+ tokenB: Token;
27
+ block: number;
28
+ data: number[];
29
+ }[] = [
30
+ {
31
+ tokenA: { symbol: 'USDC' } as Token,
32
+ tokenB: { symbol: 'USDT' } as Token,
33
+ block: 19608294,
34
+ data: [
35
+ 0, 5100, 10200, 15300, 20400, 25500, 30600, 35700, 40800, 45900, 51000,
36
+ ],
37
+ },
38
+ {
39
+ tokenA: { symbol: 'USDT' } as Token,
40
+ tokenB: { symbol: 'WETH' } as Token,
41
+ block: 19831195,
42
+ data: [0, 1.7, 3.4, 5.1, 6.8, 8.5, 10.2, 11.9, 13.6, 15.3, 17],
43
+ },
44
+ ];
45
+ initializeTokens();
46
+
47
+ const dexHelper = new DummyDexHelper(network);
48
+ const dexKey = 'Integral';
49
+
50
+ function initializeTokens() {
51
+ for (const [i, testData] of testDatas.entries()) {
52
+ const tokenA = Tokens[network][testData.tokenA.symbol!];
53
+ const tokenB = Tokens[network][testData.tokenB.symbol!];
54
+ tokenA.symbol = testData.tokenA.symbol;
55
+ tokenB.symbol = testData.tokenB.symbol;
56
+ testDatas[i].tokenA = tokenA;
57
+ testDatas[i].tokenB = tokenB;
58
+ }
59
+ }
60
+
61
+ function initializeAmounts(token: Token, units: number[]) {
62
+ const precision = 10 ** 18;
63
+ return units.map(
64
+ unit =>
65
+ (BigInt(unit * precision) * BI_POWS[token.decimals]) / BigInt(precision),
66
+ );
67
+ }
68
+
69
+ async function checkOnChainPricing(
70
+ relayerAddress: string,
71
+ funcName: string,
72
+ blockNumber: number,
73
+ prices: bigint[],
74
+ TokenA: Token,
75
+ TokenB: Token,
76
+ expectedAmounts: bigint[],
77
+ ) {
78
+ const relayerInterface = new Interface(IntegralRelayerABI);
79
+ const callData = expectedAmounts
80
+ .slice(1)
81
+ .map<MultiCallParams<bigint>>(amount => ({
82
+ target: relayerAddress,
83
+ callData: relayerInterface.encodeFunctionData(funcName, [
84
+ TokenA.address,
85
+ TokenB.address,
86
+ amount,
87
+ ]),
88
+ decodeFunction: uint256ToBigInt,
89
+ }));
90
+ const results = await dexHelper.multiWrapper.tryAggregate(
91
+ false,
92
+ callData,
93
+ blockNumber,
94
+ dexHelper.multiWrapper.defaultBatchSize,
95
+ false,
96
+ );
97
+
98
+ const expectedPrices = [0n].concat(results.map(result => result.returnData));
99
+ expect(prices).toEqual(expectedPrices);
100
+ }
101
+
102
+ for (const { tokenA, tokenB, data, block } of testDatas) {
103
+ describe(`Integral Pool ${tokenB.symbol}-${tokenA.symbol}`, function () {
104
+ let integral: Integral;
105
+
106
+ beforeAll(async () => {
107
+ integral = new Integral(network, dexKey, dexHelper);
108
+ await integral.initializePricing(block);
109
+ });
110
+
111
+ it(`getPoolIdentifiers and getPricesVolume SELL [${tokenB.symbol}, ${tokenA.symbol}]`, async function () {
112
+ const amounts = initializeAmounts(tokenB, data);
113
+ const pools = await integral.getPoolIdentifiers(
114
+ tokenB,
115
+ tokenA,
116
+ SwapSide.SELL,
117
+ block,
118
+ );
119
+ console.log(
120
+ `${tokenA.symbol} <> ${tokenB.symbol} Pool Identifiers: `,
121
+ pools,
122
+ );
123
+
124
+ expect(pools.length).toBeGreaterThan(0);
125
+
126
+ const poolPrices = await integral.getPricesVolume(
127
+ tokenB,
128
+ tokenA,
129
+ amounts,
130
+ SwapSide.SELL,
131
+ block,
132
+ pools,
133
+ );
134
+ console.log(
135
+ `${tokenA.symbol} <> ${tokenB.symbol} Pool Prices, SELL: `,
136
+ poolPrices,
137
+ );
138
+
139
+ expect(poolPrices).not.toBeNull();
140
+ if (integral.hasConstantPriceLargeAmounts) {
141
+ checkConstantPoolPrices(poolPrices!, amounts, dexKey);
142
+ } else {
143
+ checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
144
+ }
145
+
146
+ // Check if onchain pricing equals to calculated ones
147
+ await checkOnChainPricing(
148
+ IntegralConfig[dexKey][network].relayerAddress,
149
+ 'quoteSell',
150
+ block,
151
+ poolPrices![0].prices,
152
+ tokenB,
153
+ tokenA,
154
+ amounts,
155
+ );
156
+ });
157
+
158
+ it(`getPoolIdentifiers and getPricesVolume BUY [${tokenA.symbol}, ${tokenB.symbol}]`, async function () {
159
+ const amounts = initializeAmounts(tokenB, data);
160
+ const pools = await integral.getPoolIdentifiers(
161
+ tokenA,
162
+ tokenB,
163
+ SwapSide.BUY,
164
+ block,
165
+ );
166
+ console.log(
167
+ `${tokenA.symbol} <> ${tokenB.symbol} Pool Identifiers: `,
168
+ pools,
169
+ );
170
+
171
+ expect(pools.length).toBeGreaterThan(0);
172
+
173
+ const poolPrices = await integral.getPricesVolume(
174
+ tokenA,
175
+ tokenB,
176
+ amounts,
177
+ SwapSide.BUY,
178
+ block,
179
+ pools,
180
+ );
181
+ console.log(
182
+ `${tokenA.symbol} <> ${tokenB.symbol} Pool Prices, Buy: `,
183
+ poolPrices,
184
+ );
185
+
186
+ expect(poolPrices).not.toBeNull();
187
+ if (integral.hasConstantPriceLargeAmounts) {
188
+ checkConstantPoolPrices(poolPrices!, amounts, dexKey);
189
+ } else {
190
+ checkPoolPrices(poolPrices!, amounts, SwapSide.BUY, dexKey);
191
+ }
192
+
193
+ // Check if onchain pricing equals to calculated ones
194
+ await checkOnChainPricing(
195
+ IntegralConfig[dexKey][network].relayerAddress,
196
+ 'quoteBuy',
197
+ block,
198
+ poolPrices![0].prices,
199
+ tokenA,
200
+ tokenB,
201
+ amounts,
202
+ );
203
+ });
204
+ });
205
+ }
206
+
207
+ describe('Integral Top Pools', function () {
208
+ const integral = new Integral(network, dexKey, dexHelper);
209
+ const { tokenA } = testDatas[0];
210
+ it(`getTopPoolsForToken [${tokenA.symbol}]`, async function () {
211
+ const poolLiquidity = await integral.getTopPoolsForToken(
212
+ tokenA.address,
213
+ 10,
214
+ );
215
+ console.log(`${tokenA.symbol} Top Pools:`, poolLiquidity);
216
+
217
+ if (!integral.hasConstantPriceLargeAmounts) {
218
+ checkPoolsLiquidity(poolLiquidity, tokenA.address, dexKey);
219
+ }
220
+ });
221
+ });
@@ -0,0 +1,198 @@
1
+ import _ from 'lodash';
2
+ import { Interface } from '@ethersproject/abi';
3
+ import { LogDescription } from 'ethers/lib/utils';
4
+ import { AsyncOrSync } from 'ts-essentials';
5
+ import { BlockHeader, Log, Logger } from '../../types';
6
+ import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
7
+ import { IDexHelper } from '../../dex-helper/idex-helper';
8
+ import { PoolState } from './types';
9
+ import IntegralPoolABI from '../../abi/integral/pool.json';
10
+ import IntegralOracleABI from '../../abi/integral/oracle.json';
11
+ import UniswapV3PoolABI from '../../abi/uniswap-v3/UniswapV3Pool.abi.json';
12
+ import { Address } from '../../types';
13
+ import { MultiCallParams } from '../../lib/multi-wrapper';
14
+ import {
15
+ addressDecode,
16
+ uint256ToBigInt,
17
+ uint8ToNumber,
18
+ } from '../../lib/decoders';
19
+ import { AbiItem } from 'web3-utils';
20
+ import { BigNumber } from 'ethers';
21
+
22
+ export class IntegralEventPool extends StatefulEventSubscriber<PoolState> {
23
+ handlers: {
24
+ [event: string]: (
25
+ event: any,
26
+ pool: PoolState,
27
+ blockHeader: Readonly<BlockHeader>,
28
+ ) => AsyncOrSync<PoolState>;
29
+ } = {};
30
+
31
+ logDecoder: (log: Log) => any;
32
+
33
+ addressesSubscribed: string[];
34
+
35
+ readonly poolAddress: Address;
36
+ readonly token0: Address;
37
+ readonly token1: Address;
38
+
39
+ constructor(
40
+ public parentName: string,
41
+ protected network: number,
42
+ protected dexHelper: IDexHelper,
43
+ poolAddress: Address,
44
+ token0: Address,
45
+ token1: Address,
46
+ logger: Logger,
47
+ protected poolIface = new Interface(IntegralPoolABI),
48
+ ) {
49
+ super(parentName, `${token0}_${token1}`, dexHelper, logger);
50
+ this.token0 = token0.toLowerCase();
51
+ this.token1 = token1.toLowerCase();
52
+ this.poolAddress = poolAddress.toLowerCase();
53
+
54
+ this.logDecoder = (log: Log) => this.poolIface.parseLog(log);
55
+ this.addressesSubscribed = [this.poolAddress];
56
+ this.handlers['SetSwapFee'] = this.handleSetSwapFee.bind(this);
57
+ this.handlers['SetMintFee'] = this.handleSetMintFee.bind(this);
58
+ this.handlers['SetBurnFee'] = this.handleSetBurnFee.bind(this);
59
+ }
60
+
61
+ /**
62
+ * The function is called every time any of the subscribed
63
+ * addresses release log. The function accepts the current
64
+ * state, updates the state according to the log, and returns
65
+ * the updated state.
66
+ * @param state - Current state of event subscriber
67
+ * @param log - Log released by one of the subscribed addresses
68
+ * @returns Updates state of the event subscriber after the log
69
+ */
70
+ protected async processLog(
71
+ state: PoolState,
72
+ log: Readonly<Log>,
73
+ blockHeader: Readonly<BlockHeader>,
74
+ ): Promise<PoolState | null> {
75
+ try {
76
+ const event = this.logDecoder(log);
77
+ if (event.name in this.handlers) {
78
+ return await this.handlers[event.name](event, state, blockHeader);
79
+ }
80
+ return state;
81
+ } catch (e) {
82
+ this.logger.error(
83
+ `Error_${this.parentName}_processLog could not parse the log with topic ${log.topics}:`,
84
+ e,
85
+ );
86
+ return null;
87
+ }
88
+ }
89
+
90
+ /**
91
+ * The function generates state using on-chain calls. This
92
+ * function is called to regenerate state if the event based
93
+ * system fails to fetch events and the local state is no
94
+ * more correct.
95
+ * @param blockNumber - Blocknumber for which the state should
96
+ * should be generated
97
+ * @returns state of the event subscriber at blocknumber
98
+ */
99
+ async generateState(blockNumber: number): Promise<Readonly<PoolState>> {
100
+ const state = {} as PoolState;
101
+ const pool = new this.dexHelper.web3Provider.eth.Contract(
102
+ IntegralPoolABI as AbiItem[],
103
+ this.poolAddress,
104
+ );
105
+ const poolInfoCallDatas: MultiCallParams<string | bigint>[] = [
106
+ {
107
+ target: this.poolAddress,
108
+ callData: pool.methods.oracle().encodeABI(),
109
+ decodeFunction: addressDecode,
110
+ },
111
+ {
112
+ target: this.poolAddress,
113
+ callData: pool.methods.mintFee().encodeABI(),
114
+ decodeFunction: uint256ToBigInt,
115
+ },
116
+ {
117
+ target: this.poolAddress,
118
+ callData: pool.methods.burnFee().encodeABI(),
119
+ decodeFunction: uint256ToBigInt,
120
+ },
121
+ {
122
+ target: this.poolAddress,
123
+ callData: pool.methods.swapFee().encodeABI(),
124
+ decodeFunction: uint256ToBigInt,
125
+ },
126
+ ];
127
+ const poolInfos = await this.dexHelper.multiWrapper.aggregate<
128
+ string | bigint
129
+ >(poolInfoCallDatas, blockNumber);
130
+ const oracleAddress = poolInfos[0].toString();
131
+
132
+ state.mintFee = BigInt(poolInfos[1]);
133
+ state.burnFee = BigInt(poolInfos[2]);
134
+ state.swapFee = BigInt(poolInfos[3]);
135
+ state.oracle = oracleAddress;
136
+
137
+ const historyState = this.getStaleState();
138
+ if (!historyState) {
139
+ const oracle = new this.dexHelper.web3Provider.eth.Contract(
140
+ IntegralOracleABI as AbiItem[],
141
+ oracleAddress,
142
+ );
143
+ const oracleInfosCallDatas: MultiCallParams<number | string>[] = [
144
+ {
145
+ target: oracleAddress,
146
+ callData: oracle.methods.xDecimals().encodeABI(),
147
+ decodeFunction: uint8ToNumber,
148
+ },
149
+ {
150
+ target: oracleAddress,
151
+ callData: oracle.methods.yDecimals().encodeABI(),
152
+ decodeFunction: uint8ToNumber,
153
+ },
154
+ {
155
+ target: oracleAddress,
156
+ callData: oracle.methods.uniswapPair().encodeABI(),
157
+ decodeFunction: addressDecode,
158
+ },
159
+ ];
160
+ const oracleInfos = await this.dexHelper.multiWrapper.aggregate<
161
+ number | string
162
+ >(oracleInfosCallDatas, blockNumber);
163
+
164
+ state.uniswapPool = oracleInfos[2].toString();
165
+ state.decimals0 = Number(oracleInfos[0]);
166
+ state.decimals1 = Number(oracleInfos[1]);
167
+
168
+ const uniswapPool = new this.dexHelper.web3Provider.eth.Contract(
169
+ UniswapV3PoolABI as AbiItem[],
170
+ state.uniswapPool,
171
+ );
172
+ const fee = await uniswapPool.methods.fee().call(undefined, blockNumber);
173
+ state.uniswapPoolFee = BigInt(fee);
174
+ } else {
175
+ state.uniswapPool = historyState.uniswapPool;
176
+ state.decimals0 = historyState.decimals0;
177
+ state.decimals1 = historyState.decimals1;
178
+ state.uniswapPoolFee = historyState.uniswapPoolFee;
179
+ }
180
+
181
+ return state;
182
+ }
183
+
184
+ handleSetSwapFee(event: LogDescription, pool: PoolState) {
185
+ pool.swapFee = BigInt(BigNumber.from(event.args.fee).toString());
186
+ return pool;
187
+ }
188
+
189
+ handleSetMintFee(event: LogDescription, pool: PoolState) {
190
+ pool.mintFee = BigInt(BigNumber.from(event.args.fee).toString());
191
+ return pool;
192
+ }
193
+
194
+ handleSetBurnFee(event: LogDescription, pool: PoolState) {
195
+ pool.burnFee = BigInt(BigNumber.from(event.args.fee).toString());
196
+ return pool;
197
+ }
198
+ }
@@ -0,0 +1,190 @@
1
+ import { Interface } from '@ethersproject/abi';
2
+ import { IDexHelper } from '../../dex-helper';
3
+ import { Address, Logger } from '../../types';
4
+ import { UniswapV3EventPool } from '../uniswap-v3/uniswap-v3-pool';
5
+ import { UniswapV3Config } from '../uniswap-v3/config';
6
+ import UniswapV3StateMulticallABI from '../../abi/uniswap-v3/UniswapV3StateMulticall.abi.json';
7
+ import { Network } from '../../constants';
8
+ import { AbiItem } from 'web3-utils';
9
+ import {
10
+ DecodedStateMultiCallResultWithRelativeBitmaps,
11
+ OracleObservation,
12
+ PoolState,
13
+ } from '../uniswap-v3/types';
14
+ import {
15
+ _reduceTickBitmap,
16
+ _reduceTicks,
17
+ } from '../uniswap-v3/contract-math/utils';
18
+ import { bigIntify } from '../../utils';
19
+ import { TickBitMap } from '../uniswap-v3/contract-math/TickBitMap';
20
+ import { Observation } from './types';
21
+ import { MultiResult } from '../../lib/multi-wrapper';
22
+ import { BytesLike, ethers } from 'ethers';
23
+ import { extractSuccessAndValue } from '../../lib/decoders';
24
+
25
+ export function decodeStateMultiCallResultWithObservation(
26
+ result: MultiResult<BytesLike> | BytesLike,
27
+ ): Observation {
28
+ const [isSuccess, toDecode] = extractSuccessAndValue(result);
29
+
30
+ if (!isSuccess || toDecode === '0x')
31
+ throw new Error(
32
+ `decodeStateMultiCallResultWithRelativeBitmaps failed to get decodable result: ${result}`,
33
+ );
34
+
35
+ const decoded = ethers.utils.defaultAbiCoder.decode(
36
+ [
37
+ `
38
+ tuple(
39
+ uint32 blockTimestamp,
40
+ int56 tickCumulative,
41
+ uint160 secondsPerLiquidityCumulativeX128,
42
+ bool initialized,
43
+ )
44
+ `,
45
+ ],
46
+ toDecode,
47
+ )[0];
48
+ return decoded as Observation;
49
+ }
50
+
51
+ export class IntegralPricing extends UniswapV3EventPool {
52
+ private readonly providedPoolAddress: Address;
53
+ constructor(
54
+ readonly dexHelper: IDexHelper,
55
+ parentName: string,
56
+ erc20Interface: Interface,
57
+ poolAddress: Address,
58
+ token0: Address,
59
+ token1: Address,
60
+ feeCode: bigint,
61
+ logger: Logger,
62
+ network: Network,
63
+ mapKey: string = '',
64
+ ) {
65
+ const uniswapConfig = UniswapV3Config['UniswapV3'][network];
66
+ const stateMultiContract = new dexHelper.web3Provider.eth.Contract(
67
+ uniswapConfig.stateMultiCallAbi !== undefined
68
+ ? uniswapConfig.stateMultiCallAbi
69
+ : (UniswapV3StateMulticallABI as AbiItem[]),
70
+ uniswapConfig.stateMulticall,
71
+ );
72
+ super(
73
+ dexHelper,
74
+ parentName,
75
+ stateMultiContract,
76
+ undefined,
77
+ erc20Interface,
78
+ uniswapConfig.factory,
79
+ feeCode,
80
+ token0,
81
+ token1,
82
+ logger,
83
+ mapKey,
84
+ uniswapConfig.initHash,
85
+ );
86
+ this.providedPoolAddress = poolAddress;
87
+ }
88
+
89
+ get poolAddress() {
90
+ return this.providedPoolAddress;
91
+ }
92
+
93
+ set poolAddress(_address: Address) {}
94
+
95
+ async generateState(blockNumber: number): Promise<Readonly<PoolState>> {
96
+ const callData = this._getStateRequestCallData();
97
+
98
+ const [resBalance0, resBalance1, resState] =
99
+ await this.dexHelper.multiWrapper.tryAggregate<
100
+ bigint | DecodedStateMultiCallResultWithRelativeBitmaps
101
+ >(
102
+ false,
103
+ callData,
104
+ blockNumber,
105
+ this.dexHelper.multiWrapper.defaultBatchSize,
106
+ false,
107
+ );
108
+
109
+ if (!resState.success) throw new Error('Pool does not exist');
110
+
111
+ const [balance0, balance1, _state] = [
112
+ resBalance0.returnData,
113
+ resBalance1.returnData,
114
+ resState.returnData,
115
+ ] as [bigint, bigint, DecodedStateMultiCallResultWithRelativeBitmaps];
116
+
117
+ const observationsCallData = [
118
+ ...Array(_state.slot0.observationCardinality),
119
+ ].map((_, i) => {
120
+ return {
121
+ target: this.poolAddress,
122
+ callData: this.poolIface.encodeFunctionData('observations', [i]),
123
+ decodeFunction: decodeStateMultiCallResultWithObservation,
124
+ };
125
+ });
126
+
127
+ const resObservations =
128
+ await this.dexHelper.multiWrapper.tryAggregate<Observation>(
129
+ false,
130
+ observationsCallData,
131
+ blockNumber,
132
+ 13107,
133
+ false,
134
+ );
135
+ const observations = resObservations.reduce((memo, obs, i) => {
136
+ memo[i] = {
137
+ blockTimestamp: BigInt(obs.returnData.blockTimestamp),
138
+ tickCumulative: BigInt(obs.returnData.tickCumulative.toString()),
139
+ secondsPerLiquidityCumulativeX128: BigInt(
140
+ obs.returnData.secondsPerLiquidityCumulativeX128.toString(),
141
+ ),
142
+ initialized: obs.returnData.initialized,
143
+ };
144
+ return memo;
145
+ }, {} as { [index: number]: OracleObservation });
146
+
147
+ const tickBitmap = {};
148
+ const ticks = {};
149
+
150
+ _reduceTickBitmap(tickBitmap, _state.tickBitmap);
151
+ _reduceTicks(ticks, _state.ticks);
152
+
153
+ const currentTick = bigIntify(_state.slot0.tick);
154
+ const tickSpacing = bigIntify(_state.tickSpacing);
155
+
156
+ const startTickBitmap = TickBitMap.position(currentTick / tickSpacing)[0];
157
+ const requestedRange = this.getBitmapRangeToRequest();
158
+
159
+ return {
160
+ pool: _state.pool,
161
+ blockTimestamp: bigIntify(_state.blockTimestamp),
162
+ slot0: {
163
+ sqrtPriceX96: bigIntify(_state.slot0.sqrtPriceX96),
164
+ tick: currentTick,
165
+ observationIndex: +_state.slot0.observationIndex,
166
+ observationCardinality: +_state.slot0.observationCardinality,
167
+ observationCardinalityNext: +_state.slot0.observationCardinalityNext,
168
+ feeProtocol: bigIntify(_state.slot0.feeProtocol),
169
+ },
170
+ liquidity: bigIntify(_state.liquidity),
171
+ fee: this.feeCode,
172
+ tickSpacing,
173
+ maxLiquidityPerTick: bigIntify(_state.maxLiquidityPerTick),
174
+ tickBitmap,
175
+ ticks,
176
+ observations,
177
+ isValid: true,
178
+ startTickBitmap,
179
+ lowestKnownTick:
180
+ (BigInt.asIntN(24, startTickBitmap - requestedRange) << 8n) *
181
+ tickSpacing,
182
+ highestKnownTick:
183
+ ((BigInt.asIntN(24, startTickBitmap + requestedRange) << 8n) +
184
+ BigInt.asIntN(24, 255n)) *
185
+ tickSpacing,
186
+ balance0,
187
+ balance1,
188
+ };
189
+ }
190
+ }