@paraswap/dex-lib 3.11.2 → 3.11.3

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 (257) hide show
  1. package/.idea/aws.xml +17 -0
  2. package/.idea/codeStyles/Project.xml +19 -0
  3. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  4. package/.idea/misc.xml +6 -0
  5. package/.idea/modules.xml +8 -0
  6. package/.idea/paraswap-dex-lib.iml +9 -0
  7. package/.idea/prettier.xml +7 -0
  8. package/.idea/vcs.xml +6 -0
  9. package/build/abi/integral/factory.json +333 -0
  10. package/build/abi/{angle-transmuter/ChainlinkEACAggregatorProxy.json → integral/oracle.json} +239 -247
  11. package/build/abi/{curve-v1/StableSwapUSDN.json → integral/pool.json} +487 -450
  12. package/build/abi/{RamsesV2Pool.abi.json → integral/relayer.json} +833 -851
  13. package/build/dex/aave-v1/aave-v1.d.ts +1 -2
  14. package/build/dex/aave-v1/aave-v1.js +0 -22
  15. package/build/dex/aave-v1/aave-v1.js.map +1 -1
  16. package/build/dex/bProtocol.d.ts +18 -0
  17. package/build/dex/bProtocol.js +39 -0
  18. package/build/dex/bProtocol.js.map +1 -0
  19. package/build/dex/bancor.d.ts +26 -0
  20. package/build/dex/bancor.js +58 -0
  21. package/build/dex/bancor.js.map +1 -0
  22. package/build/dex/compound.d.ts +18 -0
  23. package/build/dex/compound.js +46 -0
  24. package/build/dex/compound.js.map +1 -0
  25. package/build/dex/curve-v2.d.ts +58 -0
  26. package/build/dex/curve-v2.js +180 -0
  27. package/build/dex/curve-v2.js.map +1 -0
  28. package/build/dex/dodo-v1.d.ts +33 -0
  29. package/build/dex/dodo-v1.js +63 -0
  30. package/build/dex/dodo-v1.js.map +1 -0
  31. package/build/dex/fluid-dex/fluid-dex-generate-pool.d.ts +49 -0
  32. package/build/dex/fluid-dex/fluid-dex-generate-pool.js +104 -0
  33. package/build/dex/fluid-dex/fluid-dex-generate-pool.js.map +1 -0
  34. package/build/dex/fluid-dex/fluid-dex-pool.d.ts +47 -0
  35. package/build/dex/fluid-dex/fluid-dex-pool.js +119 -0
  36. package/build/dex/fluid-dex/fluid-dex-pool.js.map +1 -0
  37. package/build/dex/fluid-dex/fluid-dex.d.ts +1 -1
  38. package/build/dex/fluid-dex/fluid-dex.js +7 -11
  39. package/build/dex/fluid-dex/fluid-dex.js.map +1 -1
  40. package/build/dex/fluid-dex/types.d.ts +1 -5
  41. package/build/dex/integral/config.d.ts +4 -0
  42. package/build/dex/integral/config.js +20 -0
  43. package/build/dex/integral/config.js.map +1 -0
  44. package/build/dex/integral/context.d.ts +40 -0
  45. package/build/dex/integral/context.js +158 -0
  46. package/build/dex/integral/context.js.map +1 -0
  47. package/build/dex/integral/integral-factory.d.ts +24 -0
  48. package/build/dex/integral/integral-factory.js +95 -0
  49. package/build/dex/integral/integral-factory.js.map +1 -0
  50. package/build/dex/integral/integral-pool.d.ts +50 -0
  51. package/build/dex/integral/integral-pool.js +149 -0
  52. package/build/dex/integral/integral-pool.js.map +1 -0
  53. package/build/dex/integral/integral-pricing.d.ts +18 -0
  54. package/build/dex/integral/integral-pricing.js +114 -0
  55. package/build/dex/integral/integral-pricing.js.map +1 -0
  56. package/build/dex/integral/integral-relayer.d.ts +42 -0
  57. package/build/dex/integral/integral-relayer.js +192 -0
  58. package/build/dex/integral/integral-relayer.js.map +1 -0
  59. package/build/dex/integral/integral-token.d.ts +27 -0
  60. package/build/dex/integral/integral-token.js +59 -0
  61. package/build/dex/integral/integral-token.js.map +1 -0
  62. package/build/dex/{inception/inception-native.d.ts → integral/integral.d.ts} +19 -21
  63. package/build/dex/integral/integral.js +376 -0
  64. package/build/dex/integral/integral.js.map +1 -0
  65. package/build/dex/integral/types.d.ts +85 -0
  66. package/build/dex/integral/types.js +9 -0
  67. package/build/dex/integral/types.js.map +1 -0
  68. package/build/dex/integral/utils-e2e.d.ts +9 -0
  69. package/build/dex/integral/utils-e2e.js +131 -0
  70. package/build/dex/integral/utils-e2e.js.map +1 -0
  71. package/build/dex/integral/utils.d.ts +17 -0
  72. package/build/dex/integral/utils.js +94 -0
  73. package/build/dex/integral/utils.js.map +1 -0
  74. package/build/dex/jarvis.d.ts +1 -2
  75. package/build/dex/jarvis.js +0 -58
  76. package/build/dex/jarvis.js.map +1 -1
  77. package/build/dex/lido.d.ts +19 -0
  78. package/build/dex/lido.js +42 -0
  79. package/build/dex/lido.js.map +1 -0
  80. package/build/dex/onebit.d.ts +25 -0
  81. package/build/dex/onebit.js +42 -0
  82. package/build/dex/onebit.js.map +1 -0
  83. package/build/dex/platypus/platypus.d.ts +1 -2
  84. package/build/dex/platypus/platypus.js +0 -31
  85. package/build/dex/platypus/platypus.js.map +1 -1
  86. package/build/dex/smoothy.d.ts +26 -0
  87. package/build/dex/smoothy.js +48 -0
  88. package/build/dex/smoothy.js.map +1 -0
  89. package/build/dex/stable-pool.d.ts +28 -0
  90. package/build/dex/stable-pool.js +62 -0
  91. package/build/dex/stable-pool.js.map +1 -0
  92. package/build/dex/swaap-v1/swaap-v1.d.ts +1 -2
  93. package/build/dex/swaap-v1/swaap-v1.js +0 -10
  94. package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
  95. package/build/dex/trader-joe-v2.1/optimizer.d.ts +2 -0
  96. package/build/dex/trader-joe-v2.1/optimizer.js +47 -0
  97. package/build/dex/trader-joe-v2.1/optimizer.js.map +1 -0
  98. package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.d.ts +7 -0
  99. package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.js +20 -0
  100. package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.js.map +1 -0
  101. package/build/dex/trader-joe-v2.1.d.ts +43 -0
  102. package/build/dex/trader-joe-v2.1.js +79 -0
  103. package/build/dex/trader-joe-v2.1.js.map +1 -0
  104. package/build/dex/zerox/index.d.ts +26 -4
  105. package/build/dex/zerox/index.js +42 -50
  106. package/build/dex/zerox/index.js.map +1 -1
  107. package/build/dex/zerox/types.d.ts +0 -29
  108. package/build/dex/zerox/types.js +1 -8
  109. package/build/dex/zerox/types.js.map +1 -1
  110. package/package.json +1 -1
  111. package/src/dex/fluid-dex/fluid-dex.ts +8 -18
  112. package/src/dex/fluid-dex/types.ts +1 -5
  113. package/build/abi/Aave_GSM.json +0 -751
  114. package/build/abi/Balancer.json +0 -257
  115. package/build/abi/BalancerV2.json +0 -1179
  116. package/build/abi/RamsesV2Quoter.abi.json +0 -274
  117. package/build/abi/USDM.json +0 -807
  118. package/build/abi/UniswapV2Router.json +0 -397
  119. package/build/abi/angle-transmuter/ChainlinkAccessControlledOffchainAggregator.json +0 -1246
  120. package/build/abi/curve-v1/CurveBUSDv2.abi.json +0 -1356
  121. package/build/abi/curve-v1/CurveTokenV1.json +0 -305
  122. package/build/abi/curve-v1/CurveTokenV2.json +0 -318
  123. package/build/abi/curve-v1/CurveV1StableNg.json +0 -1452
  124. package/build/abi/curve-v1/CurveV2Swap.json +0 -700
  125. package/build/abi/curve-v1/FactoryCryptoRegistry.json +0 -316
  126. package/build/abi/curve-v1/FactoryRegistry.json +0 -508
  127. package/build/abi/curve-v1/StableSwapAave.json +0 -1152
  128. package/build/abi/curve-v1/StableSwapBUSD.json +0 -814
  129. package/build/abi/curve-v1/StableSwapCompound.json +0 -814
  130. package/build/abi/curve-v1/StableSwapIDLE.json +0 -1253
  131. package/build/abi/curve-v1/StableSwapPax.json +0 -865
  132. package/build/abi/curve-v1/StableSwapSnow.json +0 -900
  133. package/build/abi/curve-v1/StableSwapUSDT.json +0 -814
  134. package/build/abi/curve-v1/StableSwapY.json +0 -814
  135. package/build/abi/inception/inception-ineth-pool.json +0 -1062
  136. package/build/abi/inception/inception-ineth.json +0 -609
  137. package/build/abi/inception/inception-ratio-feed.json +0 -329
  138. package/build/abi/inception/inception-vault.json +0 -991
  139. package/build/abi/kyberdmm/kyber-storage.abi.json +0 -824
  140. package/build/abi/kyberdmm.abi.json +0 -1148
  141. package/build/abi/maverick-v2/MaverickV2Quoter.json +0 -278
  142. package/build/abi/nerve/nerve-metapool.json +0 -790
  143. package/build/abi/uniswap-v3/UniswapV3Quoter.abi.json +0 -193
  144. package/build/abi/velodrome-slipstream/VelodromeSlipstreamQuoterV2.abi.json +0 -267
  145. package/build/dex/balancer-v1/balancer-pools.json +0 -33333
  146. package/build/dex/bebop/websocket-fetcher.d.ts +0 -35
  147. package/build/dex/bebop/websocket-fetcher.js +0 -87
  148. package/build/dex/bebop/websocket-fetcher.js.map +0 -1
  149. package/build/dex/idle-dao/idle-dao-pool.d.ts +0 -56
  150. package/build/dex/idle-dao/idle-dao-pool.js +0 -176
  151. package/build/dex/idle-dao/idle-dao-pool.js.map +0 -1
  152. package/build/dex/idle-dao/idle-dao-pooling-pool.d.ts +0 -16
  153. package/build/dex/idle-dao/idle-dao-pooling-pool.js +0 -57
  154. package/build/dex/idle-dao/idle-dao-pooling-pool.js.map +0 -1
  155. package/build/dex/idle-dao/scripts.d.ts +0 -9
  156. package/build/dex/idle-dao/scripts.js +0 -552
  157. package/build/dex/idle-dao/scripts.js.map +0 -1
  158. package/build/dex/inception/config.d.ts +0 -4
  159. package/build/dex/inception/config.js +0 -109
  160. package/build/dex/inception/config.js.map +0 -1
  161. package/build/dex/inception/inception-event-pool.d.ts +0 -16
  162. package/build/dex/inception/inception-event-pool.js +0 -51
  163. package/build/dex/inception/inception-event-pool.js.map +0 -1
  164. package/build/dex/inception/inception-native.js +0 -131
  165. package/build/dex/inception/inception-native.js.map +0 -1
  166. package/build/dex/inception/inception-pool.d.ts +0 -18
  167. package/build/dex/inception/inception-pool.js +0 -32
  168. package/build/dex/inception/inception-pool.js.map +0 -1
  169. package/build/dex/inception/inception-price-feed.d.ts +0 -19
  170. package/build/dex/inception/inception-price-feed.js +0 -51
  171. package/build/dex/inception/inception-price-feed.js.map +0 -1
  172. package/build/dex/inception/inception.d.ts +0 -43
  173. package/build/dex/inception/inception.js +0 -204
  174. package/build/dex/inception/inception.js.map +0 -1
  175. package/build/dex/inception/tokens.d.ts +0 -9
  176. package/build/dex/inception/tokens.js +0 -28
  177. package/build/dex/inception/tokens.js.map +0 -1
  178. package/build/dex/inception/types.d.ts +0 -22
  179. package/build/dex/inception/types.js +0 -3
  180. package/build/dex/inception/types.js.map +0 -1
  181. package/build/dex/inception/utils.d.ts +0 -6
  182. package/build/dex/inception/utils.js +0 -37
  183. package/build/dex/inception/utils.js.map +0 -1
  184. package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-balancerv1-curvev1-eth-usdc-gusd.json +0 -16
  185. package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-balancerv1-sushiv3-wbtc-eth-sushi.json +0 -16
  186. package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-curvev1-eth-usdc-gusd.json +0 -16
  187. package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-curvev1-gusd-usdc-eth.json +0 -16
  188. package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-dai-usdc-eth.json +0 -16
  189. package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-eth-usdc-dai.json +0 -16
  190. package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-usdc-eth-wbtc.json +0 -16
  191. package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-usdt-usdc-dai.json +0 -16
  192. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-balancerv1-eth-usdc.json +0 -9
  193. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-balancerv1-usdc-eth.json +0 -9
  194. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-balancerv1-usdc-wbtc.json +0 -9
  195. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-curvev1-eth-steth.json +0 -9
  196. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-curvev1-steth-eth.json +0 -9
  197. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-curvev1-usdc-usdt.json +0 -9
  198. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-univ3-eth-usdc.json +0 -9
  199. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-univ3-usdc-eth.json +0 -9
  200. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-univ3-usdc-usdt.json +0 -9
  201. package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-balancerv1-sushiv3-wbtc-eth-sushi.json +0 -12
  202. package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-curvev1-eth-usdc-gusd.json +0 -7
  203. package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-curvev1-gusd-usdc-eth.json +0 -7
  204. package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-dai-usdc-eth.json +0 -7
  205. package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-eth-usdc-dai.json +0 -7
  206. package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-usdc-eth-wbtc.json +0 -12
  207. package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-simpleSwap-univ3-eth-usdc.json +0 -7
  208. package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-simpleSwap-univ3-usdc-eth.json +0 -7
  209. package/build/executor/fixtures/executor01/routes/price-route-multiswap-balancerv1-curvev1-eth-usdc-gusd.json +0 -78
  210. package/build/executor/fixtures/executor01/routes/price-route-multiswap-balancerv1-sushiv3-wbtc-eth-sushi.json +0 -81
  211. package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-curvev1-eth-usdc-gusd.json +0 -78
  212. package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-curvev1-gusd-usdc-eth.json +0 -78
  213. package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-dai-usdc-eth.json +0 -81
  214. package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-eth-usdc-dai.json +0 -81
  215. package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-usdc-eth-wbtc.json +0 -81
  216. package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-usdt-usdc-dai.json +0 -81
  217. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-balancerv1-eth-usdc.json +0 -64
  218. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-balancerv1-usdc-eth.json +0 -85
  219. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-balancerv1-usdc-wbtc.json +0 -64
  220. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-curvev1-eth-steth.json +0 -52
  221. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-curvev1-steth-eth.json +0 -52
  222. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-curvev1-usdc-usdt.json +0 -52
  223. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-univ3-eth-usdc.json +0 -55
  224. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-univ3-usdc-eth.json +0 -55
  225. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-univ3-usdc-usdt.json +0 -55
  226. package/build/executor/fixtures/executor02/exchange-params/price-route-multiSwap-balancerv1-sushiv3-univ3-bal-eth-sushi.json +0 -23
  227. package/build/executor/fixtures/executor02/exchange-params/price-route-multiSwap-maverickv1-sushiv3-univ3-eth-usdc-mav.json +0 -37
  228. package/build/executor/fixtures/executor02/exchange-params/price-route-multiSwap-univ3-sushiv3-sushi-eth-wbtc.json +0 -23
  229. package/build/executor/fixtures/executor02/exchange-params/price-route-multiSwap-univ3-sushiv3-wbtc-eth-sushi.json +0 -23
  230. package/build/executor/fixtures/executor02/exchange-params/price-route-multiswap-curvev1-univ3-dai-usdc-eth.json +0 -51
  231. package/build/executor/fixtures/executor02/exchange-params/price-route-multiswap-univ3-usdt-dai-eth.json +0 -58
  232. package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-balancerv1-eth-usdc.json +0 -23
  233. package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-balancerv1-usdc-eth.json +0 -23
  234. package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-univ3-eth-sushi.json +0 -9
  235. package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-univ3-sushi-eth.json +0 -16
  236. package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-univ3-curvev1-usdt-dai.json +0 -23
  237. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-balancerv1-sushiv3-univ3-bal-eth-sushi.json +0 -12
  238. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-maverickv1-sushiv3-univ3-eth-usdc-mav.json +0 -7
  239. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-univ3-sushiv3-sushi-eth-wbtc.json +0 -12
  240. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-univ3-sushiv3-wbtc-eth-sushi.json +0 -12
  241. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiswap-curvev1-univ3-dai-usdc-eth.json +0 -7
  242. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiswap-univ3-usdt-dai-eth.json +0 -7
  243. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-balancerv1-eth-usdc.json +0 -7
  244. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-balancerv1-usdc-eth.json +0 -7
  245. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-univ3-eth-sushi.json +0 -7
  246. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-univ3-sushi-eth.json +0 -7
  247. package/build/executor/fixtures/executor02/routes/price-route-multiSwap-balancerv1-sushiv3-univ3-bal-eth-sushi.json +0 -130
  248. package/build/executor/fixtures/executor02/routes/price-route-multiSwap-maverickv1-sushiv3-univ3-eth-usdc-mav.json +0 -136
  249. package/build/executor/fixtures/executor02/routes/price-route-multiSwap-univ3-sushiv3-sushi-eth-wbtc.json +0 -100
  250. package/build/executor/fixtures/executor02/routes/price-route-multiSwap-univ3-sushiv3-wbtc-eth-sushi.json +0 -100
  251. package/build/executor/fixtures/executor02/routes/price-route-multiswap-curvev1-univ3-dai-usdc-eth.json +0 -166
  252. package/build/executor/fixtures/executor02/routes/price-route-multiswap-univ3-usdt-dai-eth.json +0 -190
  253. package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-balancerv1-eth-usdc.json +0 -114
  254. package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-balancerv1-usdc-eth.json +0 -114
  255. package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-univ3-eth-sushi.json +0 -55
  256. package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-univ3-sushi-eth.json +0 -73
  257. package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-univ3-curvev1-usdt-dai.json +0 -82
@@ -0,0 +1,376 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.Integral = void 0;
30
+ const lodash_1 = __importDefault(require("lodash"));
31
+ const CALLDATA_GAS_COST = __importStar(require("../../calldata-gas-cost"));
32
+ const constants_1 = require("../../constants");
33
+ const utils_1 = require("../../utils");
34
+ const types_1 = require("./types");
35
+ const simple_exchange_1 = require("../simple-exchange");
36
+ const config_1 = require("./config");
37
+ const relayer_json_1 = __importDefault(require("../../abi/integral/relayer.json"));
38
+ const abi_1 = require("@ethersproject/abi");
39
+ const bigint_constants_1 = require("../../bigint-constants");
40
+ const utils_2 = require("./utils");
41
+ const context_1 = require("./context");
42
+ const utils_3 = require("./utils");
43
+ const PRECISION = bigint_constants_1.BI_POWS[18];
44
+ const SUBGRAPH_TIMEOUT = 20 * 1000;
45
+ const SWAP_ORDER_TIMEOUT = Math.floor(Date.now() / 1000) + 24 * 3600;
46
+ const relayerInterface = new abi_1.Interface(relayer_json_1.default);
47
+ class Integral extends simple_exchange_1.SimpleExchange {
48
+ constructor(network, dexKey, dexHelper, adapters = config_1.Adapters[network] || {}) {
49
+ super(dexHelper, dexKey);
50
+ this.network = network;
51
+ this.dexKey = dexKey;
52
+ this.dexHelper = dexHelper;
53
+ this.adapters = adapters;
54
+ this.hasConstantPriceLargeAmounts = false;
55
+ this.isFeeOnTransferSupported = false;
56
+ this.logger = dexHelper.getLogger(dexKey);
57
+ this.context = context_1.IntegralContext.initialize(network, dexKey, dexHelper, this.erc20Interface, config_1.IntegralConfig[dexKey][network].factoryAddress.toLowerCase(), config_1.IntegralConfig[dexKey][network].relayerAddress.toLowerCase());
58
+ this.subgraphURL = config_1.IntegralConfig[dexKey][network].subgraphURL;
59
+ }
60
+ async initializePricing(blockNumber) {
61
+ await this.context.factory.initialize(blockNumber);
62
+ const factoryState = this.context.factory.getState(blockNumber);
63
+ if (factoryState) {
64
+ await this.context.addPools(factoryState.pools, blockNumber, true);
65
+ }
66
+ }
67
+ // Returns the list of contract adapters (name and index)
68
+ // for a buy/sell. Return null if there are no adapters.
69
+ getAdapters(side) {
70
+ return this.adapters[side] ? this.adapters[side] : null;
71
+ }
72
+ async getPoolIdentifiers(srcToken, destToken, side, blockNumber) {
73
+ const src = this.dexHelper.config.wrapETH(srcToken);
74
+ const dest = this.dexHelper.config.wrapETH(destToken);
75
+ if (src.address.toLowerCase() === dest.address.toLowerCase()) {
76
+ return [];
77
+ }
78
+ const tokenAddresses = [
79
+ src.address.toLowerCase(),
80
+ dest.address.toLowerCase(),
81
+ ]
82
+ .sort((a, b) => (a > b ? 1 : -1))
83
+ .join('_');
84
+ const poolIdentifier = `${this.dexKey}_${tokenAddresses}`;
85
+ return [poolIdentifier];
86
+ }
87
+ // Returns pool prices for amounts.
88
+ // If limitPools is defined only pools in limitPools
89
+ // should be used. If limitPools is undefined then
90
+ // any pools can be used.
91
+ async getPricesVolume(srcToken, destToken, amounts, side, blockNumber, limitPools) {
92
+ const src = this.dexHelper.config.wrapETH(srcToken);
93
+ const dest = this.dexHelper.config.wrapETH(destToken);
94
+ if (src.address.toLowerCase() === dest.address.toLowerCase()) {
95
+ return null;
96
+ }
97
+ const poolIdentifier = (0, utils_2.getPoolIdentifier)(this.dexKey, src.address, dest.address);
98
+ if (limitPools && limitPools.every(p => p !== poolIdentifier)) {
99
+ return null;
100
+ }
101
+ const props = await this.getQuotingProps(src, dest, blockNumber);
102
+ if (!props) {
103
+ return null;
104
+ }
105
+ const unitAmount = (0, utils_1.getBigIntPow)(side == constants_1.SwapSide.SELL ? src.decimals : dest.decimals);
106
+ const unit = side == constants_1.SwapSide.SELL
107
+ ? this.quoteSell(unitAmount, props, false)
108
+ : this.quoteBuy(unitAmount, props, false);
109
+ try {
110
+ const prices = side == constants_1.SwapSide.SELL
111
+ ? amounts.map(amount => this.quoteSell(amount, props))
112
+ : amounts.map(amount => this.quoteBuy(amount, props));
113
+ return [
114
+ {
115
+ prices: prices,
116
+ unit: unit,
117
+ data: {
118
+ relayer: this.context.relayerAddress,
119
+ },
120
+ exchange: this.dexKey,
121
+ poolIdentifier,
122
+ gasCost: 350000,
123
+ poolAddresses: [props.poolAddress],
124
+ },
125
+ ];
126
+ }
127
+ catch (e) {
128
+ this.logger.error(`Error_getPricesVolume could not get price with error:`, e);
129
+ return null;
130
+ }
131
+ }
132
+ // Returns estimated gas cost of calldata for this DEX in multiSwap
133
+ getCalldataGasCost(poolPrices) {
134
+ return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
135
+ }
136
+ // Encode params required by the exchange adapter
137
+ // Used for multiSwap, buy & megaSwap
138
+ // Hint: abiCoder.encodeParameter() could be useful
139
+ getAdapterParam(srcToken, destToken, srcAmount, destAmount, data, side) {
140
+ const { relayer: exchange } = data;
141
+ // Encode here the payload for adapter
142
+ const payload = '0x';
143
+ return {
144
+ targetExchange: exchange,
145
+ payload,
146
+ networkFee: '0',
147
+ };
148
+ }
149
+ getDexParam(srcToken, destToken, srcAmount, destAmount, recipient, data, side, _, executorAddress) {
150
+ const tokenIn = this.dexHelper.config.wrapETH(srcToken);
151
+ const tokenOut = this.dexHelper.config.wrapETH(destToken);
152
+ const swapData = relayerInterface.encodeFunctionData(side === constants_1.SwapSide.SELL ? types_1.IntegralFunctions.swap : types_1.IntegralFunctions.buy, [
153
+ {
154
+ ...{
155
+ tokenIn,
156
+ tokenOut,
157
+ wrapUnwrap: (0, utils_1.isETHAddress)(srcToken) || (0, utils_1.isETHAddress)(destToken),
158
+ to: recipient,
159
+ submitDeadline: SWAP_ORDER_TIMEOUT,
160
+ },
161
+ ...(side === constants_1.SwapSide.SELL
162
+ ? { amountIn: srcAmount, amountOutMin: destAmount }
163
+ : { amountInMax: srcAmount, amountOut: destAmount }),
164
+ },
165
+ ]);
166
+ return {
167
+ needWrapNative: this.needWrapNative,
168
+ dexFuncHasRecipient: true,
169
+ exchangeData: swapData,
170
+ targetExchange: this.context.relayerAddress,
171
+ returnAmountPos: undefined,
172
+ };
173
+ }
174
+ async updatePoolState() { }
175
+ async getTopPoolsForToken(tokenAddress, limit) {
176
+ if (!this.subgraphURL) {
177
+ return [];
178
+ }
179
+ const query = `
180
+ query ($token: Bytes!, $limit: Int) {
181
+ pools0: pairs(
182
+ first: $limit
183
+ orderBy: reserveUSD
184
+ orderDirection: desc
185
+ where: {token0: $token}
186
+ ) {
187
+ id
188
+ token0 {
189
+ id
190
+ decimals
191
+ }
192
+ token1 {
193
+ id
194
+ decimals
195
+ }
196
+ reserveUSD
197
+ }
198
+ pools1: pairs(
199
+ first: $limit
200
+ orderBy: reserveUSD
201
+ orderDirection: desc
202
+ where: {token1: $token}
203
+ ) {
204
+ id
205
+ token0 {
206
+ id
207
+ decimals
208
+ }
209
+ token1 {
210
+ id
211
+ decimals
212
+ }
213
+ reserveUSD
214
+ }
215
+ }`;
216
+ const { data } = await this.dexHelper.httpRequest.querySubgraph(this.subgraphURL, {
217
+ query,
218
+ variables: { token: tokenAddress.toLowerCase(), limit },
219
+ }, { timeout: SUBGRAPH_TIMEOUT });
220
+ if (!(data && data.pools0 && data.pools1))
221
+ throw new Error("Couldn't fetch the pools from the subgraph");
222
+ const pools0 = lodash_1.default.map(data.pools0, pool => ({
223
+ exchange: this.dexKey,
224
+ address: pool.id.toLowerCase(),
225
+ connectorTokens: [
226
+ {
227
+ address: pool.token1.id.toLowerCase(),
228
+ decimals: parseInt(pool.token1.decimals),
229
+ },
230
+ ],
231
+ liquidityUSD: parseFloat(pool.reserveUSD),
232
+ }));
233
+ const pools1 = lodash_1.default.map(data.pools1, pool => ({
234
+ exchange: this.dexKey,
235
+ address: pool.id.toLowerCase(),
236
+ connectorTokens: [
237
+ {
238
+ address: pool.token0.id.toLowerCase(),
239
+ decimals: parseInt(pool.token0.decimals),
240
+ },
241
+ ],
242
+ liquidityUSD: parseFloat(pool.reserveUSD),
243
+ }));
244
+ return lodash_1.default.slice(lodash_1.default.sortBy(lodash_1.default.concat(pools0, pools1), [pool => -1 * pool.liquidityUSD]), 0, limit);
245
+ }
246
+ async getPriceOnChain(tokenIn, tokenOut, inverted, blockNumber) {
247
+ try {
248
+ const calldata = [
249
+ {
250
+ target: this.context.relayerAddress,
251
+ callData: relayerInterface.encodeFunctionData('getPoolState', [
252
+ tokenIn.address,
253
+ tokenOut.address,
254
+ ]),
255
+ },
256
+ ];
257
+ const data = await this.dexHelper.multiContract.methods
258
+ .aggregate(calldata)
259
+ .call({}, blockNumber);
260
+ const result = relayerInterface.decodeFunctionResult('getPoolState', data.returnData[0]);
261
+ const _limits = inverted
262
+ ? [result.limitMin1, result.limitMax1]
263
+ : [result.limitMin0, result.limitMax0];
264
+ const limits = [
265
+ BigInt(_limits[0].toString()),
266
+ BigInt(_limits[1].toString()),
267
+ ];
268
+ const [decimals0, decimals1] = inverted
269
+ ? [tokenOut.decimals, tokenIn.decimals]
270
+ : [tokenIn.decimals, tokenOut.decimals];
271
+ return {
272
+ price: BigInt(result.price.toString()),
273
+ poolAddress: result.poolAddress,
274
+ fee: BigInt(result.fee.toString()),
275
+ tokenOutLimits: limits,
276
+ decimalsConverter: (0, utils_2.getDecimalsConverter)(decimals0, decimals1, inverted),
277
+ };
278
+ }
279
+ catch (e) {
280
+ this.logger.error(`Error_getPriceOnChain could not get data with error:`, e);
281
+ return null;
282
+ }
283
+ }
284
+ async getQuotingProps(src, dest, blockNumber) {
285
+ const poolId = (0, utils_2.getPoolIdentifier)(this.dexKey, src.address, dest.address);
286
+ const inverted = (0, utils_2.isInverted)(src.address, dest.address);
287
+ const states = this.getStates(poolId, blockNumber);
288
+ if (!states) {
289
+ const resp = await this.getPriceOnChain(src, dest, inverted, blockNumber);
290
+ return resp;
291
+ }
292
+ const { base, poolAddress, relayer, relayerTokens } = states;
293
+ const price = (0, utils_2.getPrice)(states, inverted);
294
+ const token0 = (0, utils_2.sortTokens)(src.address, dest.address)[0];
295
+ const { max0, max1 } = this.getMaxLimits(poolAddress, relayer, relayerTokens);
296
+ return {
297
+ price,
298
+ poolAddress: states.poolAddress,
299
+ fee: relayer.swapFee,
300
+ tokenOutLimits: dest.address === token0
301
+ ? [relayer.limits.min0, max0]
302
+ : [relayer.limits.min1, max1],
303
+ decimalsConverter: (0, utils_2.getDecimalsConverter)(base.decimals0, base.decimals1, inverted),
304
+ };
305
+ }
306
+ quoteSell(amountIn, props, checkLimit = true) {
307
+ if (amountIn === 0n) {
308
+ return 0n;
309
+ }
310
+ const fee = (amountIn * props.fee) / PRECISION;
311
+ const amountInMinusFee = amountIn - fee;
312
+ const amountOut = (amountInMinusFee * props.price) / props.decimalsConverter;
313
+ if (checkLimit && !this.checkLimits(amountOut, props.tokenOutLimits)) {
314
+ return 0n;
315
+ // throw new Error(
316
+ // `Out of Limits - amountOut ${amountOut} not in between limits ${props.tokenOutLimits}`,
317
+ // );
318
+ }
319
+ return amountOut;
320
+ }
321
+ quoteBuy(amountOut, props, checkLimit = true) {
322
+ if (amountOut === 0n) {
323
+ return 0n;
324
+ }
325
+ if (checkLimit && !this.checkLimits(amountOut, props.tokenOutLimits)) {
326
+ return 0n;
327
+ // throw new Error(
328
+ // `Out of Limits - amountOut ${amountOut} not in between limits ${props.tokenOutLimits}`,
329
+ // );
330
+ }
331
+ const amountIn = (0, utils_3.ceil_div)(amountOut * props.decimalsConverter, props.price);
332
+ if (amountIn <= 0n) {
333
+ return 0n;
334
+ }
335
+ const amountInPlusFee = (0, utils_3.ceil_div)(amountIn * PRECISION, PRECISION - props.fee);
336
+ return amountInPlusFee;
337
+ }
338
+ checkLimits(amount, limits) {
339
+ if (amount < limits[0] || amount > limits[1]) {
340
+ return false;
341
+ }
342
+ return true;
343
+ }
344
+ getStates(poolId, blockNumber) {
345
+ const poolStates = this.context.pools[poolId];
346
+ if (poolStates && poolStates.base) {
347
+ const base = poolStates.base.getState(blockNumber);
348
+ const pricing = poolStates.pricing && poolStates.pricing.getState(blockNumber);
349
+ const relayerState = this.context.relayer.getState(blockNumber);
350
+ const relayer = relayerState && relayerState.pools[poolStates.base.poolAddress];
351
+ return base && pricing && relayer
352
+ ? {
353
+ base,
354
+ pricing,
355
+ relayer,
356
+ relayerTokens: relayerState.tokens,
357
+ poolAddress: poolStates.base.poolAddress,
358
+ }
359
+ : null;
360
+ }
361
+ else {
362
+ return null;
363
+ }
364
+ }
365
+ getMaxLimits(poolAddress, relayer, relayerTokens) {
366
+ const { token0, token1 } = this.context.relayer.getPools()[poolAddress.toLowerCase()];
367
+ const max0 = (relayerTokens[token0].balance * relayer.limits.maxMultiplier0) /
368
+ 10n ** 18n;
369
+ const max1 = (relayerTokens[token1].balance * relayer.limits.maxMultiplier1) /
370
+ 10n ** 18n;
371
+ return { max0, max1 };
372
+ }
373
+ }
374
+ exports.Integral = Integral;
375
+ Integral.dexKeysWithNetwork = (0, utils_1.getDexKeysWithNetwork)(config_1.IntegralConfig);
376
+ //# sourceMappingURL=integral.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integral.js","sourceRoot":"","sources":["../../../src/dex/integral/integral.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAuB;AAEvB,2EAA6D;AAY7D,+CAAoD;AACpD,uCAAgF;AAGhF,mCAOiB;AACjB,wDAAoD;AACpD,qCAAoD;AACpD,mFAAiE;AACjE,4CAA+C;AAC/C,6DAAiD;AACjD,mCAMiB;AACjB,uCAA4C;AAC5C,mCAAmC;AAEnC,MAAM,SAAS,GAAG,0BAAO,CAAC,EAAE,CAAC,CAAC;AAC9B,MAAM,gBAAgB,GAAG,EAAE,GAAG,IAAI,CAAC;AACnC,MAAM,kBAAkB,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AACrE,MAAM,gBAAgB,GAAG,IAAI,eAAS,CA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W,CAAC,CAAC;YAClE,OAAO,IAAI,IAAI,OAAO,IAAI,OAAO;gBAC/B,CAAC,CAAC;oBACE,IAAI;oBACJ,OAAO;oBACP,OAAO;oBACP,aAAa,EAAE,YAAY,CAAC,MAAM;oBAClC,WAAW,EAAE,UAAU,CAAC,IAAI,CAAC,WAAW;iBACzC;gBACH,CAAC,CAAC,IAAI,CAAC;SACV;aAAM;YACL,OAAO,IAAI,CAAC;SACb;IACH,CAAC;IAEO,YAAY,CAClB,WAAoB,EACpB,OAAyB,EACzB,aAAiC;QAEjC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GACtB,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,WAAW,CAAC,WAAW,EAAE,CAAC,CAAC;QAC7D,MAAM,IAAI,GACR,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC;YAC/D,GAAG,IAAI,GAAG,CAAC;QACb,MAAM,IAAI,GACR,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC;YAC/D,GAAG,IAAI,GAAG,CAAC;QACb,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACxB,CAAC;;AAzdH,4BA0dC;AAnde,2BAAkB,GAC9B,IAAA,6BAAqB,EAAC,uBAAc,CAAC,CAAC"}
@@ -0,0 +1,85 @@
1
+ import { Address } from '../../types';
2
+ import { IntegralEventPool } from './integral-pool';
3
+ import { PoolState as UniswapPoolState } from '../uniswap-v3/types';
4
+ import { BigNumber } from 'ethers';
5
+ import { IntegralPricing } from './integral-pricing';
6
+ export declare type Requires<Class, Prop extends keyof Class> = Class & Required<Pick<Class, Prop>>;
7
+ export declare type IntegralPool = {
8
+ base?: IntegralEventPool;
9
+ pricing?: IntegralPricing;
10
+ enabled: boolean;
11
+ };
12
+ export declare type QuotingProps = {
13
+ poolAddress: Address;
14
+ price: bigint;
15
+ fee: bigint;
16
+ tokenOutLimits: [bigint, bigint];
17
+ decimalsConverter: bigint;
18
+ };
19
+ export declare type PoolState = {
20
+ swapFee: bigint;
21
+ mintFee: bigint;
22
+ burnFee: bigint;
23
+ decimals0: number;
24
+ decimals1: number;
25
+ oracle: Address;
26
+ uniswapPool: Address;
27
+ uniswapPoolFee: bigint;
28
+ };
29
+ export declare type RelayerPoolState = {
30
+ isEnabled: boolean;
31
+ swapFee: bigint;
32
+ twapInterval: number;
33
+ limits: {
34
+ min0: bigint;
35
+ min1: bigint;
36
+ maxMultiplier0: bigint;
37
+ maxMultiplier1: bigint;
38
+ };
39
+ };
40
+ export declare type RelayerTokensState = {
41
+ [tokenAddress: string]: {
42
+ balance: bigint;
43
+ };
44
+ };
45
+ export declare type RelayerState = {
46
+ pools: {
47
+ [poolAddress: string]: RelayerPoolState;
48
+ };
49
+ tokens: RelayerTokensState;
50
+ };
51
+ export declare type PoolInitProps = {
52
+ [poolAddress: string]: {
53
+ token0: Address;
54
+ token1: Address;
55
+ };
56
+ };
57
+ export declare type FactoryState = {
58
+ pools: PoolInitProps;
59
+ };
60
+ export declare type PoolStates = {
61
+ base: PoolState;
62
+ relayer: RelayerPoolState;
63
+ relayerTokens: RelayerTokensState;
64
+ pricing: UniswapPoolState;
65
+ poolAddress: Address;
66
+ };
67
+ export declare type TokenState = Record<string, never>;
68
+ export declare type IntegralData = {
69
+ relayer: Address;
70
+ };
71
+ export declare type DexParams = {
72
+ factoryAddress: string;
73
+ relayerAddress: string;
74
+ subgraphURL?: string;
75
+ };
76
+ export declare enum IntegralFunctions {
77
+ swap = "sell",
78
+ buy = "buy"
79
+ }
80
+ export declare type Observation = {
81
+ blockTimestamp: number;
82
+ initialized: boolean;
83
+ secondsPerLiquidityCumulativeX128: BigNumber;
84
+ tickCumulative: BigNumber;
85
+ };
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IntegralFunctions = void 0;
4
+ var IntegralFunctions;
5
+ (function (IntegralFunctions) {
6
+ IntegralFunctions["swap"] = "sell";
7
+ IntegralFunctions["buy"] = "buy";
8
+ })(IntegralFunctions = exports.IntegralFunctions || (exports.IntegralFunctions = {}));
9
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/dex/integral/types.ts"],"names":[],"mappings":";;;AA8EA,IAAY,iBAGX;AAHD,WAAY,iBAAiB;IAC3B,kCAAa,CAAA;IACb,gCAAW,CAAA;AACb,CAAC,EAHW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAG5B"}
@@ -0,0 +1,9 @@
1
+ import { Address } from '../../types';
2
+ import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
3
+ import { Provider } from '@ethersproject/providers';
4
+ export declare function updateEventSubscriber<SubscriberState>(eventSubscriber: StatefulEventSubscriber<SubscriberState>, subscribedAddress: Address[], fetchState: (blocknumber: number) => Promise<SubscriberState>, blockNumber: number, cacheKey: string, provider: Provider): Promise<void>;
5
+ export declare function checkEventSubscriber<SubscriberState>(eventSubscriber: StatefulEventSubscriber<SubscriberState>, fetchState: (blocknumber: number) => Promise<SubscriberState>, blockNumber: number, cacheKey: string, stateCompare?: (state: SubscriberState, expectedState: SubscriberState) => void): Promise<void>;
6
+ export declare function deepTypecast<T>(obj: any, checker: (val: any) => boolean, caster: (val: T) => any): any;
7
+ export declare function getSavedConfig<Config>(blockNumber: number, cacheKey: string): Config | undefined;
8
+ export declare function saveConfig<Config>(blockNumber: number, cacheKey: string, config: Config): void;
9
+ export declare function getSavedState<SubscriberState>(blockNumber: number, cacheKey: string): SubscriberState | undefined;
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getSavedState = exports.saveConfig = exports.getSavedConfig = exports.deepTypecast = exports.checkEventSubscriber = exports.updateEventSubscriber = void 0;
7
+ const lodash_1 = __importDefault(require("lodash"));
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const pathRoot = path_1.default.join(__dirname, './test-artifacts/');
11
+ const configPath = './configs.json';
12
+ const absConfigPath = path_1.default.join(pathRoot, configPath);
13
+ let configs = {};
14
+ if (fs_1.default.existsSync(absConfigPath))
15
+ configs = require(absConfigPath);
16
+ const statePath = './states.json';
17
+ const absStatePath = path_1.default.join(pathRoot, statePath);
18
+ let states = {};
19
+ if (fs_1.default.existsSync(absStatePath))
20
+ states = require(absStatePath);
21
+ const logPath = './logs.json';
22
+ const absLogPath = path_1.default.join(pathRoot, logPath);
23
+ let logs = {};
24
+ if (fs_1.default.existsSync(absLogPath))
25
+ logs = require(absLogPath);
26
+ const bigintify = (val) => BigInt(val);
27
+ const stringify = (val) => val.toString();
28
+ async function updateEventSubscriber(eventSubscriber, subscribedAddress, fetchState, blockNumber, cacheKey, provider) {
29
+ // Get state of the subscriber block before the event was released
30
+ let poolState = getSavedState(blockNumber - 1, cacheKey);
31
+ if (!poolState) {
32
+ poolState = await fetchState(blockNumber - 1);
33
+ saveState(blockNumber - 1, cacheKey, poolState);
34
+ }
35
+ // Set subscriber state before the event block
36
+ eventSubscriber.setState(poolState, blockNumber - 1);
37
+ eventSubscriber.isTracking = () => true;
38
+ // Get logs and blockHeader of the block when the event was emitted
39
+ let blockInfo = getSavedBlockInfo(blockNumber, cacheKey);
40
+ if (!blockInfo) {
41
+ const logs = (await Promise.all(subscribedAddress.map(address => provider.getLogs({
42
+ fromBlock: blockNumber,
43
+ toBlock: blockNumber,
44
+ address,
45
+ }))))
46
+ .flat()
47
+ .sort((a, b) => a.logIndex - b.logIndex);
48
+ blockInfo = {
49
+ logs,
50
+ blockHeaders: {
51
+ [blockNumber]: await provider.getBlock(blockNumber),
52
+ },
53
+ };
54
+ saveBlockInfo(blockNumber, cacheKey, blockInfo);
55
+ }
56
+ // Update subscriber with event logs
57
+ await eventSubscriber.update(blockInfo.logs, blockInfo.blockHeaders);
58
+ }
59
+ exports.updateEventSubscriber = updateEventSubscriber;
60
+ async function checkEventSubscriber(eventSubscriber, fetchState, blockNumber, cacheKey, stateCompare) {
61
+ // Get the expected state of the subscriber after the event
62
+ let expectedNewPoolState = getSavedState(blockNumber, cacheKey);
63
+ if (!expectedNewPoolState) {
64
+ expectedNewPoolState = await fetchState(blockNumber);
65
+ saveState(blockNumber, cacheKey, expectedNewPoolState);
66
+ }
67
+ // Get the updated state of the subscriber
68
+ const newPoolState = eventSubscriber.getState(blockNumber);
69
+ // Expect the updated state to be same as the expected state
70
+ if (stateCompare) {
71
+ expect(newPoolState).not.toBeNull();
72
+ stateCompare(newPoolState, expectedNewPoolState);
73
+ }
74
+ else {
75
+ expect(newPoolState).toEqual(expectedNewPoolState);
76
+ }
77
+ }
78
+ exports.checkEventSubscriber = checkEventSubscriber;
79
+ function deepTypecast(obj, checker, caster) {
80
+ return lodash_1.default.forEach(obj, (val, key, obj) => {
81
+ obj[key] = checker(val)
82
+ ? caster(val)
83
+ : lodash_1.default.isObject(val)
84
+ ? deepTypecast(val, checker, caster)
85
+ : val;
86
+ });
87
+ }
88
+ exports.deepTypecast = deepTypecast;
89
+ function getSavedConfig(blockNumber, cacheKey) {
90
+ const _config = configs[`${cacheKey}_${blockNumber}`];
91
+ if (_config) {
92
+ const checker = (obj) => lodash_1.default.isString(obj) && obj.includes('bi@');
93
+ const caster = (obj) => bigintify(obj.slice(3));
94
+ return deepTypecast(lodash_1.default.cloneDeep(_config), checker, caster);
95
+ }
96
+ return undefined;
97
+ }
98
+ exports.getSavedConfig = getSavedConfig;
99
+ function saveConfig(blockNumber, cacheKey, config) {
100
+ const checker = (obj) => typeof obj === 'bigint';
101
+ const caster = (obj) => 'bi@'.concat(stringify(obj));
102
+ const _config = deepTypecast(lodash_1.default.cloneDeep(config), checker, caster);
103
+ configs[`${cacheKey}_${blockNumber}`] = _config;
104
+ fs_1.default.writeFileSync(absConfigPath, JSON.stringify(configs, null, 2));
105
+ }
106
+ exports.saveConfig = saveConfig;
107
+ function getSavedState(blockNumber, cacheKey) {
108
+ const _state = states[`${cacheKey}_${blockNumber}`];
109
+ if (_state) {
110
+ const checker = (obj) => lodash_1.default.isString(obj) && obj.includes('bi@');
111
+ const caster = (obj) => bigintify(obj.slice(3));
112
+ return deepTypecast(lodash_1.default.cloneDeep(_state), checker, caster);
113
+ }
114
+ return undefined;
115
+ }
116
+ exports.getSavedState = getSavedState;
117
+ function saveState(blockNumber, cacheKey, state) {
118
+ const checker = (obj) => typeof obj === 'bigint';
119
+ const caster = (obj) => 'bi@'.concat(stringify(obj));
120
+ const _state = deepTypecast(lodash_1.default.cloneDeep(state), checker, caster);
121
+ states[`${cacheKey}_${blockNumber}`] = _state;
122
+ fs_1.default.writeFileSync(absStatePath, JSON.stringify(states, null, 2));
123
+ }
124
+ function getSavedBlockInfo(blockNumber, cacheKey) {
125
+ return logs[`${cacheKey}_${blockNumber}`];
126
+ }
127
+ function saveBlockInfo(blockNumber, cacheKey, blockInfo) {
128
+ logs[`${cacheKey}_${blockNumber}`] = blockInfo;
129
+ fs_1.default.writeFileSync(absLogPath, JSON.stringify(logs, null, 2));
130
+ }
131
+ //# sourceMappingURL=utils-e2e.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils-e2e.js","sourceRoot":"","sources":["../../../src/dex/integral/utils-e2e.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAuB;AACvB,4CAAoB;AACpB,gDAAwB;AAMxB,MAAM,QAAQ,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC;AAC3D,MAAM,UAAU,GAAG,gBAAgB,CAAC;AACpC,MAAM,aAAa,GAAG,cAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;AACtD,IAAI,OAAO,GAAyB,EAAE,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AAC;AACnB,CAAC;AAXD,sCAWC;AAED,SAAS,SAAS,CAChB,WAAmB,EACnB,QAAgB,EAChB,KAAsB;IAEtB,MAAM,OAAO,GAAG,CAAC,GAAQ,EAAE,EAAE,CAAC,OAAO,GAAG,KAAK,QAAQ,CAAC;IACtD,MAAM,MAAM,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7D,MAAM,MAAM,GAAG,YAAY,CAAS,gBAAC,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IACzE,MAAM,CAAC,GAAG,QAAQ,IAAI,WAAW,EAAE,CAAC,GAAG,MAAM,CAAC;IAC9C,YAAE,CAAC,aAAa,CAAC,YAAY,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AAClE,CAAC;AAED,SAAS,iBAAiB,CAAC,WAAmB,EAAE,QAAgB;IAC9D,OAAO,IAAI,CAAC,GAAG,QAAQ,IAAI,WAAW,EAAE,CAAC,CAAC;AAC5C,CAAC;AAED,SAAS,aAAa,CACpB,WAAmB,EACnB,QAAgB,EAChB,SAAoB;IAEpB,IAAI,CAAC,GAAG,QAAQ,IAAI,WAAW,EAAE,CAAC,GAAG,SAAS,CAAC;IAC/C,YAAE,CAAC,aAAa,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AAC9D,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { BytesLike } from 'ethers';
2
+ import { MultiResult } from '../../lib/multi-wrapper';
3
+ import { Address } from '@paraswap/core';
4
+ import { PoolState as UniswapPoolState } from '../uniswap-v3/types';
5
+ import { IntegralContext } from './context';
6
+ import { PoolStates, RelayerPoolState } from './types';
7
+ export declare function ceil_div(a: bigint, b: bigint): bigint;
8
+ export declare const uint32ToNumber: (result: MultiResult<BytesLike> | BytesLike) => number;
9
+ export declare function sortTokens(srcAddress: Address, destAddress: Address): string[];
10
+ export declare function getDecimalsConverter(decimals0: number, decimals1: number, inverted: boolean): bigint;
11
+ export declare function getPrice(states: PoolStates, inverted: boolean): bigint;
12
+ export declare function getSpotPrice(pricing: UniswapPoolState, decimalsConverter: bigint): bigint;
13
+ export declare function getAveragePrice(relayer: RelayerPoolState, pricing: UniswapPoolState, decimalsConverter: bigint): bigint;
14
+ export declare function getTickCumulatives(poolState: UniswapPoolState, secondsAgos: bigint[]): bigint[];
15
+ export declare function isInverted(tokenIn: Address, tokenOut: Address): boolean;
16
+ export declare function getPoolIdentifier(dexKey: string, srcAddress: Address, destAddress: Address): string;
17
+ export declare function getPoolBackReferencedFrom(context: IntegralContext, poolAddress: Address): [string, import("./types").IntegralPool] | undefined;