@paraswap/dex-lib 4.0.0 → 4.0.1-balancer-v3-cables.0

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 (359) hide show
  1. package/.vscode/launch.json +53 -0
  2. package/.vscode/settings.json +2 -0
  3. package/.vscode/tasks.json +15 -0
  4. package/build/abi/balancer-v3/batch-router.json +989 -0
  5. package/build/abi/balancer-v3/router.json +1792 -0
  6. package/build/abi/balancer-v3/vault-extension.json +2834 -0
  7. package/build/abi/permit2.json +581 -0
  8. package/build/abi/uniswap-v3/AlienBaseV3Router.abi.json +52 -0
  9. package/build/abi/usual-m-smart-m/usualM.abi.json +483 -0
  10. package/build/abi/usual-m-usd0/usualCollateralDao.abi.json +681 -0
  11. package/build/abi/{angle-transmuter/ChainlinkAccessControlledOffchainAggregator.json → wombat/pool.json} +637 -594
  12. package/build/bigint-constants.d.ts +1 -0
  13. package/build/bigint-constants.js +2 -1
  14. package/build/bigint-constants.js.map +1 -1
  15. package/build/config.js +28 -0
  16. package/build/config.js.map +1 -1
  17. package/build/constants.d.ts +2 -0
  18. package/build/constants.js +4 -1
  19. package/build/constants.js.map +1 -1
  20. package/build/dex/aave-v1/aave-v1.js +1 -0
  21. package/build/dex/aave-v1/aave-v1.js.map +1 -1
  22. package/build/dex/aave-v2/tokens-avalanche.json +44 -0
  23. package/build/dex/aave-v2/tokens-mainnet.json +188 -0
  24. package/build/dex/aave-v2/tokens-polygon.json +44 -0
  25. package/build/dex/augustus-approvals.d.ts +3 -2
  26. package/build/dex/augustus-approvals.js +35 -16
  27. package/build/dex/augustus-approvals.js.map +1 -1
  28. package/build/dex/bProtocol.d.ts +18 -0
  29. package/build/dex/bProtocol.js +39 -0
  30. package/build/dex/bProtocol.js.map +1 -0
  31. package/build/dex/balancer-v3/abi/balancerBatchRouter.d.ts +729 -0
  32. package/build/dex/balancer-v3/abi/balancerBatchRouter.js +732 -0
  33. package/build/dex/balancer-v3/abi/balancerBatchRouter.js.map +1 -0
  34. package/build/dex/balancer-v3/abi/balancerRouter.d.ts +1406 -0
  35. package/build/dex/balancer-v3/abi/balancerRouter.js +1175 -0
  36. package/build/dex/balancer-v3/abi/balancerRouter.js.map +1 -0
  37. package/build/dex/balancer-v3/abi/vaultExtension.V3.d.ts +2081 -0
  38. package/build/dex/balancer-v3/abi/vaultExtension.V3.js +1851 -0
  39. package/build/dex/balancer-v3/abi/vaultExtension.V3.js.map +1 -0
  40. package/build/dex/balancer-v3/balancer-v3-pool.d.ts +80 -0
  41. package/build/dex/balancer-v3/balancer-v3-pool.js +469 -0
  42. package/build/dex/balancer-v3/balancer-v3-pool.js.map +1 -0
  43. package/build/dex/balancer-v3/balancer-v3-sepolia-pools.d.ts +34 -0
  44. package/build/dex/balancer-v3/balancer-v3-sepolia-pools.js +406 -0
  45. package/build/dex/balancer-v3/balancer-v3-sepolia-pools.js.map +1 -0
  46. package/build/dex/balancer-v3/balancer-v3.d.ts +56 -0
  47. package/build/dex/balancer-v3/balancer-v3.js +412 -0
  48. package/build/dex/balancer-v3/balancer-v3.js.map +1 -0
  49. package/build/dex/balancer-v3/config.d.ts +9 -0
  50. package/build/dex/balancer-v3/config.js +45 -0
  51. package/build/dex/balancer-v3/config.js.map +1 -0
  52. package/build/dex/balancer-v3/getGasCost.d.ts +2 -0
  53. package/build/dex/balancer-v3/getGasCost.js +40 -0
  54. package/build/dex/balancer-v3/getGasCost.js.map +1 -0
  55. package/build/dex/balancer-v3/getOnChainState.d.ts +10 -0
  56. package/build/dex/balancer-v3/getOnChainState.js +163 -0
  57. package/build/dex/balancer-v3/getOnChainState.js.map +1 -0
  58. package/build/dex/balancer-v3/getPoolsApi.d.ts +2 -0
  59. package/build/dex/balancer-v3/getPoolsApi.js +84 -0
  60. package/build/dex/balancer-v3/getPoolsApi.js.map +1 -0
  61. package/build/dex/balancer-v3/getTopPoolsApi.d.ts +17 -0
  62. package/build/dex/balancer-v3/getTopPoolsApi.js +65 -0
  63. package/build/dex/balancer-v3/getTopPoolsApi.js.map +1 -0
  64. package/build/dex/balancer-v3/optimizer.d.ts +2 -0
  65. package/build/dex/balancer-v3/optimizer.js +47 -0
  66. package/build/dex/balancer-v3/optimizer.js.map +1 -0
  67. package/build/dex/balancer-v3/stablePool.d.ts +7 -0
  68. package/build/dex/balancer-v3/stablePool.js +73 -0
  69. package/build/dex/balancer-v3/stablePool.js.map +1 -0
  70. package/build/dex/balancer-v3/types.d.ts +62 -0
  71. package/build/dex/balancer-v3/types.js +3 -0
  72. package/build/dex/balancer-v3/types.js.map +1 -0
  73. package/build/dex/balancer-v3/weightedPool.d.ts +1 -0
  74. package/build/dex/balancer-v3/weightedPool.js +6 -0
  75. package/build/dex/balancer-v3/weightedPool.js.map +1 -0
  76. package/build/dex/bancor.d.ts +26 -0
  77. package/build/dex/bancor.js +58 -0
  78. package/build/dex/bancor.js.map +1 -0
  79. package/build/dex/cables/cables.d.ts +7 -5
  80. package/build/dex/cables/cables.js +229 -86
  81. package/build/dex/cables/cables.js.map +1 -1
  82. package/build/dex/cables/constants.d.ts +13 -12
  83. package/build/dex/cables/constants.js +14 -16
  84. package/build/dex/cables/constants.js.map +1 -1
  85. package/build/dex/cables/types.d.ts +7 -0
  86. package/build/dex/cables/types.js +8 -1
  87. package/build/dex/cables/types.js.map +1 -1
  88. package/build/dex/compound.d.ts +18 -0
  89. package/build/dex/compound.js +46 -0
  90. package/build/dex/compound.js.map +1 -0
  91. package/build/dex/curve-v2.d.ts +58 -0
  92. package/build/dex/curve-v2.js +180 -0
  93. package/build/dex/curve-v2.js.map +1 -0
  94. package/build/dex/dodo-v1.d.ts +33 -0
  95. package/build/dex/dodo-v1.js +63 -0
  96. package/build/dex/dodo-v1.js.map +1 -0
  97. package/build/dex/fluid-dex/fluid-dex-pool.d.ts +47 -0
  98. package/build/dex/fluid-dex/fluid-dex-pool.js +119 -0
  99. package/build/dex/fluid-dex/fluid-dex-pool.js.map +1 -0
  100. package/build/dex/inception/inception-event-pool.d.ts +4 -4
  101. package/build/dex/inception/inception-event-pool.js +7 -9
  102. package/build/dex/inception/inception-event-pool.js.map +1 -1
  103. package/build/dex/inception/inception.d.ts +6 -6
  104. package/build/dex/inception/inception.js +16 -40
  105. package/build/dex/inception/inception.js.map +1 -1
  106. package/build/dex/inception/utils.d.ts +1 -0
  107. package/build/dex/inception/utils.js +22 -1
  108. package/build/dex/inception/utils.js.map +1 -1
  109. package/build/dex/index.js +4 -0
  110. package/build/dex/index.js.map +1 -1
  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/maker-psm/scripts/gem.abi.json +136 -0
  115. package/build/dex/maker-psm/scripts/validate-state.d.ts +0 -0
  116. package/build/dex/maker-psm/scripts/validate-state.js +185 -0
  117. package/build/dex/maker-psm/scripts/validate-state.js.map +1 -0
  118. package/build/dex/maker-psm/scripts/vat.abi.json +243 -0
  119. package/build/dex/onebit.d.ts +25 -0
  120. package/build/dex/onebit.js +42 -0
  121. package/build/dex/onebit.js.map +1 -0
  122. package/build/dex/platypus/platypus.js +17 -3
  123. package/build/dex/platypus/platypus.js.map +1 -1
  124. package/build/dex/smoothy.d.ts +26 -0
  125. package/build/dex/smoothy.js +48 -0
  126. package/build/dex/smoothy.js.map +1 -0
  127. package/build/dex/solidly-v3/scripts/check-event-pool-event.d.ts +1 -0
  128. package/build/dex/solidly-v3/scripts/check-event-pool-event.js +53 -0
  129. package/build/dex/solidly-v3/scripts/check-event-pool-event.js.map +1 -0
  130. package/build/dex/stable-pool.d.ts +28 -0
  131. package/build/dex/stable-pool.js +55 -0
  132. package/build/dex/stable-pool.js.map +1 -0
  133. package/build/dex/swaap-v1/swaap-v1.js +4 -0
  134. package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
  135. package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.d.ts +7 -0
  136. package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.js +20 -0
  137. package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.js.map +1 -0
  138. package/build/dex/trader-joe-v2.1.d.ts +43 -0
  139. package/build/dex/trader-joe-v2.1.js +79 -0
  140. package/build/dex/trader-joe-v2.1.js.map +1 -0
  141. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.d.ts +17 -0
  142. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js +64 -0
  143. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js.map +1 -0
  144. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.d.ts +17 -0
  145. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js +79 -0
  146. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js.map +1 -0
  147. package/build/dex/uniswap-v3/uniswap-v3-pricing.d.ts +4 -0
  148. package/build/dex/uniswap-v3/uniswap-v3-pricing.js +43 -0
  149. package/build/dex/uniswap-v3/uniswap-v3-pricing.js.map +1 -0
  150. package/build/dex/uniswap-v3/uniswap-v3-worker.d.ts +1 -0
  151. package/build/dex/uniswap-v3/uniswap-v3-worker.js +10 -0
  152. package/build/dex/uniswap-v3/uniswap-v3-worker.js.map +1 -0
  153. package/build/dex/usual/types.d.ts +13 -0
  154. package/build/dex/usual/types.js +3 -0
  155. package/build/dex/usual/types.js.map +1 -0
  156. package/build/dex/usual/usual-bond.d.ts +18 -0
  157. package/build/dex/usual/usual-bond.js +52 -0
  158. package/build/dex/usual/usual-bond.js.map +1 -0
  159. package/build/dex/usual/usual-m-smart-m.d.ts +17 -0
  160. package/build/dex/usual/usual-m-smart-m.js +50 -0
  161. package/build/dex/usual/usual-m-smart-m.js.map +1 -0
  162. package/build/dex/usual/usual-m-usd0.d.ts +17 -0
  163. package/build/dex/usual/usual-m-usd0.js +51 -0
  164. package/build/dex/usual/usual-m-usd0.js.map +1 -0
  165. package/build/dex/usual/usual.d.ts +27 -0
  166. package/build/dex/usual/usual.js +125 -0
  167. package/build/dex/usual/usual.js.map +1 -0
  168. package/build/dex/usual-m-smart-m/config.d.ts +3 -0
  169. package/build/dex/usual-m-smart-m/config.js +13 -0
  170. package/build/dex/usual-m-smart-m/config.js.map +1 -0
  171. package/build/dex/usual-m-smart-m/types.d.ts +7 -0
  172. package/build/dex/usual-m-smart-m/types.js +3 -0
  173. package/build/dex/usual-m-smart-m/types.js.map +1 -0
  174. package/build/dex/usual-m-smart-m/usual-m-smart-m.d.ts +35 -0
  175. package/build/dex/usual-m-smart-m/usual-m-smart-m.js +161 -0
  176. package/build/dex/usual-m-smart-m/usual-m-smart-m.js.map +1 -0
  177. package/build/dex/usual-m-usd0/config.d.ts +3 -0
  178. package/build/dex/usual-m-usd0/config.js +14 -0
  179. package/build/dex/usual-m-usd0/config.js.map +1 -0
  180. package/build/dex/usual-m-usd0/types.d.ts +8 -0
  181. package/build/dex/usual-m-usd0/types.js +3 -0
  182. package/build/dex/usual-m-usd0/types.js.map +1 -0
  183. package/build/dex/usual-m-usd0/usual-m-usd0.d.ts +35 -0
  184. package/build/dex/usual-m-usd0/usual-m-usd0.js +159 -0
  185. package/build/dex/usual-m-usd0/usual-m-usd0.js.map +1 -0
  186. package/build/dex/weth/config.js +3 -0
  187. package/build/dex/weth/config.js.map +1 -1
  188. package/build/executor/Executor01BytecodeBuilder.js +2 -2
  189. package/build/executor/Executor01BytecodeBuilder.js.map +1 -1
  190. package/build/executor/Executor02BytecodeBuilder.js +2 -2
  191. package/build/executor/Executor02BytecodeBuilder.js.map +1 -1
  192. package/build/executor/Executor03BytecodeBuilder.js +2 -2
  193. package/build/executor/Executor03BytecodeBuilder.js.map +1 -1
  194. package/build/executor/ExecutorBytecodeBuilder.d.ts +3 -1
  195. package/build/executor/ExecutorBytecodeBuilder.js +35 -2
  196. package/build/executor/ExecutorBytecodeBuilder.js.map +1 -1
  197. package/build/generic-swap-transaction-builder.js +5 -1
  198. package/build/generic-swap-transaction-builder.js.map +1 -1
  199. package/build/types.d.ts +1 -0
  200. package/package.json +2 -1
  201. package/scripts/run-dex-integration-v3.ts +78 -0
  202. package/src/abi/balancer-v3/batch-router.json +989 -0
  203. package/src/abi/balancer-v3/router.json +1792 -0
  204. package/src/abi/balancer-v3/vault-extension.json +2834 -0
  205. package/src/abi/permit2.json +581 -0
  206. package/src/bigint-constants.ts +1 -0
  207. package/src/config.ts +29 -0
  208. package/src/constants.ts +4 -0
  209. package/src/dex/augustus-approvals.ts +52 -19
  210. package/src/dex/balancer-v3/balancer-v3-e2e.test.ts +275 -0
  211. package/src/dex/balancer-v3/balancer-v3-events.test.ts +223 -0
  212. package/src/dex/balancer-v3/balancer-v3-integration.test.ts +879 -0
  213. package/src/dex/balancer-v3/balancer-v3-pool.ts +656 -0
  214. package/src/dex/balancer-v3/balancer-v3.ts +538 -0
  215. package/src/dex/balancer-v3/config.ts +46 -0
  216. package/src/dex/balancer-v3/getGasCost.ts +37 -0
  217. package/src/dex/balancer-v3/getOnChainState.ts +326 -0
  218. package/src/dex/balancer-v3/getPoolsApi.ts +129 -0
  219. package/src/dex/balancer-v3/getTopPoolsApi.ts +96 -0
  220. package/src/dex/balancer-v3/optimizer.ts +66 -0
  221. package/src/dex/balancer-v3/stablePool.ts +78 -0
  222. package/src/dex/balancer-v3/types.ts +86 -0
  223. package/src/dex/balancer-v3/weightedPool.ts +2 -0
  224. package/src/dex/index.ts +4 -0
  225. package/src/dex/weth/config.ts +3 -0
  226. package/src/executor/Executor01BytecodeBuilder.ts +2 -0
  227. package/src/executor/Executor02BytecodeBuilder.ts +2 -0
  228. package/src/executor/Executor03BytecodeBuilder.ts +2 -0
  229. package/src/executor/ExecutorBytecodeBuilder.ts +63 -2
  230. package/src/generic-swap-transaction-builder.ts +6 -2
  231. package/src/types.ts +1 -0
  232. package/tests/constants-e2e.ts +66 -0
  233. package/build/abi/Aave_GSM.json +0 -751
  234. package/build/abi/Balancer.json +0 -257
  235. package/build/abi/BalancerV2.json +0 -1179
  236. package/build/abi/RamsesV2Pool.abi.json +0 -1554
  237. package/build/abi/RamsesV2Quoter.abi.json +0 -274
  238. package/build/abi/USDM.json +0 -807
  239. package/build/abi/UniswapV2Router.json +0 -397
  240. package/build/abi/angle-transmuter/ChainlinkEACAggregatorProxy.json +0 -509
  241. package/build/abi/curve-v1/CurveBUSDv2.abi.json +0 -1356
  242. package/build/abi/curve-v1/CurveTokenV1.json +0 -305
  243. package/build/abi/curve-v1/CurveTokenV2.json +0 -318
  244. package/build/abi/curve-v1/CurveV1StableNg.json +0 -1452
  245. package/build/abi/curve-v1/CurveV2Swap.json +0 -700
  246. package/build/abi/curve-v1/FactoryCryptoRegistry.json +0 -316
  247. package/build/abi/curve-v1/FactoryRegistry.json +0 -508
  248. package/build/abi/curve-v1/StableSwapAave.json +0 -1152
  249. package/build/abi/curve-v1/StableSwapBUSD.json +0 -814
  250. package/build/abi/curve-v1/StableSwapCompound.json +0 -814
  251. package/build/abi/curve-v1/StableSwapIDLE.json +0 -1253
  252. package/build/abi/curve-v1/StableSwapPax.json +0 -865
  253. package/build/abi/curve-v1/StableSwapSnow.json +0 -900
  254. package/build/abi/curve-v1/StableSwapUSDN.json +0 -1004
  255. package/build/abi/curve-v1/StableSwapUSDT.json +0 -814
  256. package/build/abi/curve-v1/StableSwapY.json +0 -814
  257. package/build/abi/inception/inception-ineth.json +0 -609
  258. package/build/abi/kyberdmm/kyber-storage.abi.json +0 -824
  259. package/build/abi/kyberdmm.abi.json +0 -1148
  260. package/build/abi/maverick-v2/MaverickV2Quoter.json +0 -278
  261. package/build/abi/nerve/nerve-metapool.json +0 -790
  262. package/build/abi/uniswap-v3/UniswapV3Quoter.abi.json +0 -193
  263. package/build/abi/velodrome-slipstream/VelodromeSlipstreamQuoterV2.abi.json +0 -267
  264. package/build/dex/balancer-v1/balancer-pools.json +0 -33333
  265. package/build/dex/bebop/websocket-fetcher.d.ts +0 -35
  266. package/build/dex/bebop/websocket-fetcher.js +0 -87
  267. package/build/dex/bebop/websocket-fetcher.js.map +0 -1
  268. package/build/dex/idle-dao/idle-dao-pool.d.ts +0 -56
  269. package/build/dex/idle-dao/idle-dao-pool.js +0 -176
  270. package/build/dex/idle-dao/idle-dao-pool.js.map +0 -1
  271. package/build/dex/idle-dao/idle-dao-pooling-pool.d.ts +0 -16
  272. package/build/dex/idle-dao/idle-dao-pooling-pool.js +0 -57
  273. package/build/dex/idle-dao/idle-dao-pooling-pool.js.map +0 -1
  274. package/build/dex/idle-dao/scripts.d.ts +0 -9
  275. package/build/dex/idle-dao/scripts.js +0 -552
  276. package/build/dex/idle-dao/scripts.js.map +0 -1
  277. package/build/dex/inception/inception-native.d.ts +0 -43
  278. package/build/dex/inception/inception-native.js +0 -131
  279. package/build/dex/inception/inception-native.js.map +0 -1
  280. package/build/dex/inception/inception-pool.d.ts +0 -18
  281. package/build/dex/inception/inception-pool.js +0 -32
  282. package/build/dex/inception/inception-pool.js.map +0 -1
  283. package/build/dex/inception/inception-price-feed.d.ts +0 -19
  284. package/build/dex/inception/inception-price-feed.js +0 -51
  285. package/build/dex/inception/inception-price-feed.js.map +0 -1
  286. package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-balancerv1-curvev1-eth-usdc-gusd.json +0 -16
  287. package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-balancerv1-sushiv3-wbtc-eth-sushi.json +0 -16
  288. package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-curvev1-eth-usdc-gusd.json +0 -16
  289. package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-curvev1-gusd-usdc-eth.json +0 -16
  290. package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-dai-usdc-eth.json +0 -16
  291. package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-eth-usdc-dai.json +0 -16
  292. package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-usdc-eth-wbtc.json +0 -16
  293. package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-usdt-usdc-dai.json +0 -16
  294. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-balancerv1-eth-usdc.json +0 -9
  295. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-balancerv1-usdc-eth.json +0 -9
  296. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-balancerv1-usdc-wbtc.json +0 -9
  297. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-curvev1-eth-steth.json +0 -9
  298. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-curvev1-steth-eth.json +0 -9
  299. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-curvev1-usdc-usdt.json +0 -9
  300. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-univ3-eth-usdc.json +0 -9
  301. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-univ3-usdc-eth.json +0 -9
  302. package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-univ3-usdc-usdt.json +0 -9
  303. package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-balancerv1-sushiv3-wbtc-eth-sushi.json +0 -12
  304. package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-curvev1-eth-usdc-gusd.json +0 -7
  305. package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-curvev1-gusd-usdc-eth.json +0 -7
  306. package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-dai-usdc-eth.json +0 -7
  307. package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-eth-usdc-dai.json +0 -7
  308. package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-usdc-eth-wbtc.json +0 -12
  309. package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-simpleSwap-univ3-eth-usdc.json +0 -7
  310. package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-simpleSwap-univ3-usdc-eth.json +0 -7
  311. package/build/executor/fixtures/executor01/routes/price-route-multiswap-balancerv1-curvev1-eth-usdc-gusd.json +0 -78
  312. package/build/executor/fixtures/executor01/routes/price-route-multiswap-balancerv1-sushiv3-wbtc-eth-sushi.json +0 -81
  313. package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-curvev1-eth-usdc-gusd.json +0 -78
  314. package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-curvev1-gusd-usdc-eth.json +0 -78
  315. package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-dai-usdc-eth.json +0 -81
  316. package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-eth-usdc-dai.json +0 -81
  317. package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-usdc-eth-wbtc.json +0 -81
  318. package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-usdt-usdc-dai.json +0 -81
  319. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-balancerv1-eth-usdc.json +0 -64
  320. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-balancerv1-usdc-eth.json +0 -85
  321. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-balancerv1-usdc-wbtc.json +0 -64
  322. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-curvev1-eth-steth.json +0 -52
  323. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-curvev1-steth-eth.json +0 -52
  324. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-curvev1-usdc-usdt.json +0 -52
  325. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-univ3-eth-usdc.json +0 -55
  326. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-univ3-usdc-eth.json +0 -55
  327. package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-univ3-usdc-usdt.json +0 -55
  328. package/build/executor/fixtures/executor02/exchange-params/price-route-multiSwap-balancerv1-sushiv3-univ3-bal-eth-sushi.json +0 -23
  329. package/build/executor/fixtures/executor02/exchange-params/price-route-multiSwap-maverickv1-sushiv3-univ3-eth-usdc-mav.json +0 -37
  330. package/build/executor/fixtures/executor02/exchange-params/price-route-multiSwap-univ3-sushiv3-sushi-eth-wbtc.json +0 -23
  331. package/build/executor/fixtures/executor02/exchange-params/price-route-multiSwap-univ3-sushiv3-wbtc-eth-sushi.json +0 -23
  332. package/build/executor/fixtures/executor02/exchange-params/price-route-multiswap-curvev1-univ3-dai-usdc-eth.json +0 -51
  333. package/build/executor/fixtures/executor02/exchange-params/price-route-multiswap-univ3-usdt-dai-eth.json +0 -58
  334. package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-balancerv1-eth-usdc.json +0 -23
  335. package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-balancerv1-usdc-eth.json +0 -23
  336. package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-univ3-eth-sushi.json +0 -9
  337. package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-univ3-sushi-eth.json +0 -16
  338. package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-univ3-curvev1-usdt-dai.json +0 -23
  339. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-balancerv1-sushiv3-univ3-bal-eth-sushi.json +0 -12
  340. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-maverickv1-sushiv3-univ3-eth-usdc-mav.json +0 -7
  341. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-univ3-sushiv3-sushi-eth-wbtc.json +0 -12
  342. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-univ3-sushiv3-wbtc-eth-sushi.json +0 -12
  343. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiswap-curvev1-univ3-dai-usdc-eth.json +0 -7
  344. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiswap-univ3-usdt-dai-eth.json +0 -7
  345. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-balancerv1-eth-usdc.json +0 -7
  346. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-balancerv1-usdc-eth.json +0 -7
  347. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-univ3-eth-sushi.json +0 -7
  348. package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-univ3-sushi-eth.json +0 -7
  349. package/build/executor/fixtures/executor02/routes/price-route-multiSwap-balancerv1-sushiv3-univ3-bal-eth-sushi.json +0 -130
  350. package/build/executor/fixtures/executor02/routes/price-route-multiSwap-maverickv1-sushiv3-univ3-eth-usdc-mav.json +0 -136
  351. package/build/executor/fixtures/executor02/routes/price-route-multiSwap-univ3-sushiv3-sushi-eth-wbtc.json +0 -100
  352. package/build/executor/fixtures/executor02/routes/price-route-multiSwap-univ3-sushiv3-wbtc-eth-sushi.json +0 -100
  353. package/build/executor/fixtures/executor02/routes/price-route-multiswap-curvev1-univ3-dai-usdc-eth.json +0 -166
  354. package/build/executor/fixtures/executor02/routes/price-route-multiswap-univ3-usdt-dai-eth.json +0 -190
  355. package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-balancerv1-eth-usdc.json +0 -114
  356. package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-balancerv1-usdc-eth.json +0 -114
  357. package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-univ3-eth-sushi.json +0 -55
  358. package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-univ3-sushi-eth.json +0 -73
  359. package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-univ3-curvev1-usdt-dai.json +0 -82
@@ -1,11 +1,13 @@
1
- import { Address, ParaSwapVersion } from '@paraswap/core';
2
- import { CACHE_PREFIX, ETHER_ADDRESS } from '../constants';
3
- import { ICache, IDexHelper } from '../dex-helper';
1
+ import { Address } from '@paraswap/core';
2
+ import { CACHE_PREFIX, ETHER_ADDRESS, PERMIT2_ADDRESS } from '../constants';
3
+ import { ICache } from '../dex-helper';
4
4
  import { Interface } from '@ethersproject/abi';
5
5
  import ERC20ABI from '../abi/erc20.json';
6
+ import Permit2Abi from '../abi/permit2.json';
6
7
  import { uint256ToBigInt } from '../lib/decoders';
7
8
  import { MultiCallParams, MultiWrapper } from '../lib/multi-wrapper';
8
9
  import { ConfigHelper } from '../config';
10
+ import { BigNumber } from 'ethers';
9
11
 
10
12
  const DEFAULT_APPROVE_CACHE_KEY_VALUE = 'true';
11
13
 
@@ -14,6 +16,7 @@ type ApprovalsMapping = Record<string, boolean>;
14
16
 
15
17
  export class AugustusApprovals {
16
18
  erc20Interface: Interface;
19
+ permit2Interface: Interface;
17
20
 
18
21
  private cache: ICache;
19
22
 
@@ -32,6 +35,7 @@ export class AugustusApprovals {
32
35
  this.augustusAddress = config.data.augustusAddress;
33
36
  this.augustusV6Address = config.data.augustusV6Address;
34
37
  this.erc20Interface = new Interface(ERC20ABI);
38
+ this.permit2Interface = new Interface(Permit2Abi);
35
39
  this.cache = cache;
36
40
 
37
41
  this.cacheApprovesKey = `${CACHE_PREFIX}_${this.network}_generic_approves`;
@@ -41,19 +45,22 @@ export class AugustusApprovals {
41
45
  spender: Address,
42
46
  token: Address,
43
47
  target: Address,
48
+ permit2 = false,
44
49
  ): Promise<boolean> {
45
- const approvals = await this.hasApprovals(spender, [[token, target]]);
50
+ const approvals = await this.hasApprovals(spender, [
51
+ [token, target, permit2],
52
+ ]);
46
53
  return approvals[0];
47
54
  }
48
55
 
49
56
  async hasApprovals(
50
57
  spender: Address,
51
- tokenTargetMapping: [token: Address, target: Address][],
58
+ tokenTargetMapping: [token: Address, target: Address, permit2: boolean][],
52
59
  ): Promise<boolean[]> {
53
60
  let approvalsMapping: Record<string, boolean> = {};
54
61
 
55
- tokenTargetMapping.forEach(([token, target]) => {
56
- const key = this.createCacheKey(spender, token, target);
62
+ tokenTargetMapping.forEach(([token, target, permit2]) => {
63
+ const key = this.createCacheKey(spender, token, target, permit2);
57
64
  // set approved 'true' for ETH
58
65
  approvalsMapping[key] = token.toLowerCase() === ETHER_ADDRESS;
59
66
  });
@@ -68,7 +75,9 @@ export class AugustusApprovals {
68
75
 
69
76
  // to keep same order and length as input
70
77
  return tokenTargetMapping
71
- .map(([token, target]) => this.createCacheKey(spender, token, target))
78
+ .map(([token, target, permit2]) =>
79
+ this.createCacheKey(spender, token, target, permit2),
80
+ )
72
81
  .map(key => approvalsMapping[key]);
73
82
  }
74
83
 
@@ -107,17 +116,37 @@ export class AugustusApprovals {
107
116
  spender: Address,
108
117
  token: Address,
109
118
  target: Address,
119
+ permit2: boolean,
110
120
  ][],
111
121
  ): Promise<boolean[]> {
112
122
  const allowanceCalldata: MultiCallParams<bigint>[] =
113
- spenderTokenTargetMapping.map(([spender, token, target]) => ({
114
- target: token,
115
- callData: this.erc20Interface.encodeFunctionData('allowance', [
116
- spender,
117
- target,
118
- ]),
119
- decodeFunction: uint256ToBigInt,
120
- }));
123
+ spenderTokenTargetMapping.map(([spender, token, target, permit2]) =>
124
+ permit2
125
+ ? {
126
+ target: PERMIT2_ADDRESS,
127
+ callData: this.permit2Interface.encodeFunctionData('allowance', [
128
+ spender,
129
+ token,
130
+ target,
131
+ ]),
132
+ decodeFunction: value => {
133
+ const [amount, expiration, nonce] =
134
+ this.permit2Interface.decodeFunctionResult(
135
+ 'allowance',
136
+ value.toString(),
137
+ ) as [BigNumber, BigNumber, BigNumber];
138
+ return amount.toBigInt();
139
+ },
140
+ }
141
+ : {
142
+ target: token,
143
+ callData: this.erc20Interface.encodeFunctionData('allowance', [
144
+ spender,
145
+ target,
146
+ ]),
147
+ decodeFunction: uint256ToBigInt,
148
+ },
149
+ );
121
150
 
122
151
  const allowances = await this.multiWrapper.tryAggregate<bigint>(
123
152
  false,
@@ -157,14 +186,18 @@ export class AugustusApprovals {
157
186
  spender: Address,
158
187
  token: Address,
159
188
  target: Address,
189
+ permit2 = false,
160
190
  ): string {
161
- return `${spender}_${token}_${target}`;
191
+ return `${spender}_${token}_${target}${
192
+ permit2 ? '_permit2' : ''
193
+ }`.toLowerCase();
162
194
  }
163
195
 
164
196
  private splitCacheKey(
165
197
  key: string,
166
- ): [spender: Address, token: Address, target: Address] {
167
- return key.split('_') as [Address, Address, Address];
198
+ ): [spender: Address, token: Address, target: Address, permit2: boolean] {
199
+ const [spender, token, target, permit2] = key.split('_');
200
+ return [spender, token, target, permit2 === 'permit2'];
168
201
  }
169
202
 
170
203
  private filterKeys(tokenTargetMapping: ApprovalsMapping, approved = false) {
@@ -0,0 +1,275 @@
1
+ /* eslint-disable no-console */
2
+ import dotenv from 'dotenv';
3
+ dotenv.config();
4
+
5
+ import { testE2E } from '../../../tests/utils-e2e';
6
+ import {
7
+ Tokens,
8
+ Holders,
9
+ NativeTokenSymbols,
10
+ } from '../../../tests/constants-e2e';
11
+ import { Network, ContractMethod, SwapSide } from '../../constants';
12
+ import { StaticJsonRpcProvider } from '@ethersproject/providers';
13
+ import { generateConfig } from '../../config';
14
+
15
+ /*
16
+ README
17
+ ======
18
+
19
+ This test script should add e2e tests for BalancerV3. The tests
20
+ should cover as many cases as possible. Most of the DEXes follow
21
+ the following test structure:
22
+ - DexName
23
+ - ForkName + Network
24
+ - ContractMethod
25
+ - ETH -> Token swap
26
+ - Token -> ETH swap
27
+ - Token -> Token swap
28
+
29
+ The template already enumerates the basic structure which involves
30
+ testing simpleSwap, multiSwap, megaSwap contract methods for
31
+ ETH <> TOKEN and TOKEN <> TOKEN swaps. You should replace tokenA and
32
+ tokenB with any two highly liquid tokens on BalancerV3 for the tests
33
+ to work. If the tokens that you would like to use are not defined in
34
+ Tokens or Holders map, you can update the './tests/constants-e2e'
35
+
36
+ Other than the standard cases that are already added by the template
37
+ it is highly recommended to add test cases which could be specific
38
+ to testing BalancerV3 (Eg. Tests based on poolType, special tokens,
39
+ etc).
40
+
41
+ You can run this individual test script by running:
42
+ `npx jest src/dex/<dex-name>/<dex-name>-e2e.test.ts`
43
+
44
+ e2e tests use the Tenderly fork api. Please add the following to your
45
+ .env file:
46
+ TENDERLY_TOKEN=Find this under Account>Settings>Authorization.
47
+ TENDERLY_ACCOUNT_ID=Your Tenderly account name.
48
+ TENDERLY_PROJECT=Name of a Tenderly project you have created in your
49
+ dashboard.
50
+
51
+ (This comment should be removed from the final implementation)
52
+ */
53
+
54
+ function testForNetwork(
55
+ network: Network,
56
+ dexKey: string,
57
+ tokenASymbol: string,
58
+ tokenBSymbol: string,
59
+ tokenAAmount: string,
60
+ tokenBAmount: string,
61
+ nativeTokenAmount: string,
62
+ testNative: boolean,
63
+ ) {
64
+ const provider = new StaticJsonRpcProvider(
65
+ generateConfig(network).privateHttpProvider,
66
+ network,
67
+ );
68
+ const tokens = Tokens[network];
69
+ const holders = Holders[network];
70
+ const nativeTokenSymbol = NativeTokenSymbols[network];
71
+
72
+ // TODO: Add any direct swap contractMethod name if it exists
73
+ const sideToContractMethods = new Map([
74
+ [SwapSide.SELL, [ContractMethod.swapExactAmountIn]],
75
+ [SwapSide.BUY, [ContractMethod.swapExactAmountOut]],
76
+ ]);
77
+
78
+ describe(`${network}`, () => {
79
+ sideToContractMethods.forEach((contractMethods, side) =>
80
+ describe(`${side}`, () => {
81
+ contractMethods.forEach((contractMethod: ContractMethod) => {
82
+ describe(`${contractMethod}`, () => {
83
+ if (testNative) {
84
+ it(`${nativeTokenSymbol} -> ${tokenASymbol}`, async () => {
85
+ await testE2E(
86
+ tokens[nativeTokenSymbol],
87
+ tokens[tokenASymbol],
88
+ holders[nativeTokenSymbol],
89
+ side === SwapSide.SELL ? nativeTokenAmount : tokenAAmount,
90
+ side,
91
+ dexKey,
92
+ contractMethod,
93
+ network,
94
+ provider,
95
+ );
96
+ });
97
+ it(`${tokenASymbol} -> ${nativeTokenSymbol}`, async () => {
98
+ await testE2E(
99
+ tokens[tokenASymbol],
100
+ tokens[nativeTokenSymbol],
101
+ holders[tokenASymbol],
102
+ side === SwapSide.SELL ? tokenAAmount : nativeTokenAmount,
103
+ side,
104
+ dexKey,
105
+ contractMethod,
106
+ network,
107
+ provider,
108
+ );
109
+ });
110
+ }
111
+ it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => {
112
+ await testE2E(
113
+ tokens[tokenASymbol],
114
+ tokens[tokenBSymbol],
115
+ holders[tokenASymbol],
116
+ side === SwapSide.SELL ? tokenAAmount : tokenBAmount,
117
+ side,
118
+ dexKey,
119
+ contractMethod,
120
+ network,
121
+ provider,
122
+ );
123
+ });
124
+ it(`${tokenBSymbol} -> ${tokenASymbol}`, async () => {
125
+ await testE2E(
126
+ tokens[tokenBSymbol],
127
+ tokens[tokenASymbol],
128
+ holders[tokenBSymbol],
129
+ side === SwapSide.SELL ? tokenBAmount : tokenAAmount,
130
+ side,
131
+ dexKey,
132
+ contractMethod,
133
+ network,
134
+ provider,
135
+ );
136
+ });
137
+ });
138
+ });
139
+ }),
140
+ );
141
+ });
142
+ }
143
+
144
+ // TODO - these tests dont currently run without full PS setup on Sepolia
145
+ describe('BalancerV3 E2E', () => {
146
+ const dexKey = 'BalancerV3';
147
+
148
+ describe('Sepolia', () => {
149
+ const network = Network.SEPOLIA;
150
+
151
+ describe('Weighted Path', () => {
152
+ const tokenASymbol: string = 'bal';
153
+ const tokenBSymbol: string = 'daiAave';
154
+
155
+ const tokenAAmount: string = '1000000000000000000';
156
+ const tokenBAmount: string = '1000000000000000000';
157
+ const nativeTokenAmount = '100000000000000';
158
+
159
+ testForNetwork(
160
+ network,
161
+ dexKey,
162
+ tokenASymbol,
163
+ tokenBSymbol,
164
+ tokenAAmount,
165
+ tokenBAmount,
166
+ nativeTokenAmount,
167
+ true,
168
+ );
169
+ });
170
+
171
+ describe('Stable Path', () => {
172
+ const tokenASymbol: string = 'stataUSDT';
173
+ const tokenBSymbol: string = 'stataUSDC';
174
+
175
+ const tokenAAmount: string = '10000000';
176
+ const tokenBAmount: string = '10000000';
177
+ const nativeTokenAmount = '0';
178
+
179
+ testForNetwork(
180
+ network,
181
+ dexKey,
182
+ tokenASymbol,
183
+ tokenBSymbol,
184
+ tokenAAmount,
185
+ tokenBAmount,
186
+ nativeTokenAmount,
187
+ false,
188
+ );
189
+ });
190
+
191
+ describe('Boosted Path', () => {
192
+ const tokenASymbol: string = 'usdcAave';
193
+ const tokenBSymbol: string = 'daiAave';
194
+
195
+ const tokenAAmount: string = '10000000';
196
+ const tokenBAmount: string = '1000000000000000000';
197
+ const nativeTokenAmount = '0';
198
+
199
+ testForNetwork(
200
+ network,
201
+ dexKey,
202
+ tokenASymbol,
203
+ tokenBSymbol,
204
+ tokenAAmount,
205
+ tokenBAmount,
206
+ nativeTokenAmount,
207
+ false,
208
+ );
209
+ });
210
+ });
211
+
212
+ describe('Gnosis', () => {
213
+ const network = Network.GNOSIS;
214
+
215
+ describe('Stable Path', () => {
216
+ const tokenASymbol: string = 'WXDAI';
217
+ const tokenBSymbol: string = 'COW';
218
+
219
+ const tokenAAmount: string = '1000000000000000000';
220
+ const tokenBAmount: string = '1000000000000000000';
221
+ const nativeTokenAmount = '100000000000000';
222
+
223
+ testForNetwork(
224
+ network,
225
+ dexKey,
226
+ tokenASymbol,
227
+ tokenBSymbol,
228
+ tokenAAmount,
229
+ tokenBAmount,
230
+ nativeTokenAmount,
231
+ false,
232
+ );
233
+ });
234
+
235
+ describe('Weighed Path', () => {
236
+ const tokenASymbol: string = 'USDCe';
237
+ const tokenBSymbol: string = 'sDAI';
238
+
239
+ const tokenAAmount: string = '1000000';
240
+ const tokenBAmount: string = '100000000000000000';
241
+ const nativeTokenAmount = '0';
242
+
243
+ testForNetwork(
244
+ network,
245
+ dexKey,
246
+ tokenASymbol,
247
+ tokenBSymbol,
248
+ tokenAAmount,
249
+ tokenBAmount,
250
+ nativeTokenAmount,
251
+ false,
252
+ );
253
+ });
254
+
255
+ describe('Boosted Path', () => {
256
+ const tokenASymbol: string = 'waGnoWETH';
257
+ const tokenBSymbol: string = 'waGnowstETH';
258
+
259
+ const tokenAAmount: string = '1000000000000000';
260
+ const tokenBAmount: string = '1000000000000000';
261
+ const nativeTokenAmount = '0';
262
+
263
+ testForNetwork(
264
+ network,
265
+ dexKey,
266
+ tokenASymbol,
267
+ tokenBSymbol,
268
+ tokenAAmount,
269
+ tokenBAmount,
270
+ nativeTokenAmount,
271
+ false,
272
+ );
273
+ });
274
+ });
275
+ });
@@ -0,0 +1,223 @@
1
+ /* eslint-disable no-console */
2
+ import dotenv from 'dotenv';
3
+ dotenv.config();
4
+
5
+ import { BalancerV3EventPool } from './balancer-v3-pool';
6
+ import { Network } from '../../constants';
7
+ import { Address } from '../../types';
8
+ import { DummyDexHelper } from '../../dex-helper/index';
9
+ import { testEventSubscriber } from '../../../tests/utils-events';
10
+ import { PoolStateMap, StableMutableState } from './types';
11
+ import { BalancerV3Config } from './config';
12
+ import _ from 'lodash';
13
+
14
+ /*
15
+ README
16
+ ======
17
+
18
+ This test script adds unit tests for BalancerV3 event based
19
+ system. This is done by fetching the state on-chain before the
20
+ event block, manually pushing the block logs to the event-subscriber,
21
+ comparing the local state with on-chain state.
22
+
23
+ Most of the logic for testing is abstracted by `testEventSubscriber`.
24
+ You need to do two things to make the tests work:
25
+
26
+ 1. Fetch the block numbers where certain events were released. You
27
+ can modify the `./scripts/fetch-event-blocknumber.ts` to get the
28
+ block numbers for different events. Make sure to get sufficient
29
+ number of blockNumbers to cover all possible cases for the event
30
+ mutations.
31
+
32
+ 2. Complete the implementation for fetchPoolState function. The
33
+ function should fetch the on-chain state of the event subscriber
34
+ using just the blocknumber.
35
+
36
+ The template tests only include the test for a single event
37
+ subscriber. There can be cases where multiple event subscribers
38
+ exist for a single DEX. In such cases additional tests should be
39
+ added.
40
+
41
+ You can run this individual test script by running:
42
+ `npx jest src/dex/balancer-v3/balancer-v3-events.test.ts`
43
+
44
+ (This comment should be removed from the final implementation)
45
+ */
46
+
47
+ jest.setTimeout(50 * 1000);
48
+
49
+ async function fetchPoolState(
50
+ balancerV3Pools: BalancerV3EventPool,
51
+ blockNumber: number,
52
+ poolAddress: string,
53
+ ): Promise<PoolStateMap> {
54
+ const pools = await balancerV3Pools.generateState(blockNumber);
55
+ // Filter to pool of interest
56
+ return Object.entries(_.cloneDeep(pools) as PoolStateMap)
57
+ .filter(([address]) => {
58
+ return address.toLowerCase() === poolAddress.toLowerCase();
59
+ })
60
+ .reduce((acc, [address, pool]) => {
61
+ acc[address] = pool;
62
+ return acc;
63
+ }, {} as PoolStateMap);
64
+ }
65
+
66
+ function stateCompare(state: PoolStateMap, expectedState: PoolStateMap) {
67
+ if (state['0xd63db0b88dca565633fb8d70a70b9b8093d34a7e']) {
68
+ if (
69
+ (
70
+ expectedState[
71
+ '0xd63db0b88dca565633fb8d70a70b9b8093d34a7e'
72
+ ] as StableMutableState
73
+ ).ampIsUpdating
74
+ ) {
75
+ compareAmpUpdating(state, expectedState);
76
+ } else compareAmpStopped(state, expectedState);
77
+ } else expect(state).toEqual(expectedState);
78
+ }
79
+
80
+ function compareAmpUpdating(state: PoolStateMap, expectedState: PoolStateMap) {
81
+ // tokenRates and balancesLiveScaled18 are gradually increasing between blocks due to tokenRate (and can't be tracked via event) so will be ignored
82
+ const compare = {
83
+ ...state,
84
+ ['0xd63db0b88dca565633fb8d70a70b9b8093d34a7e']: _.omit(
85
+ state['0xd63db0b88dca565633fb8d70a70b9b8093d34a7e'],
86
+ ['balancesLiveScaled18', 'tokenRates'],
87
+ ),
88
+ };
89
+ const expectedCompare = {
90
+ ...expectedState,
91
+ ['0xd63db0b88dca565633fb8d70a70b9b8093d34a7e']: _.omit(
92
+ expectedState['0xd63db0b88dca565633fb8d70a70b9b8093d34a7e'],
93
+ ['balancesLiveScaled18', 'tokenRates'],
94
+ ),
95
+ };
96
+ expect(compare).toEqual(expectedCompare);
97
+ }
98
+
99
+ function compareAmpStopped(state: PoolStateMap, expectedState: PoolStateMap) {
100
+ if (state['0xd63db0b88dca565633fb8d70a70b9b8093d34a7e']) {
101
+ // tokenRates and balancesLiveScaled18 are gradually increasing between blocks due to tokenRate (and can't be tracked via event) so will be ignored
102
+ // In Contract ampStartTime & ampStopTime are updated to timestamp event is called.
103
+ // There doesn't appear to be a way to easily get timestamp non-async so we default to 0n which should have no effect.
104
+ const compare = {
105
+ ...state,
106
+ ['0xd63db0b88dca565633fb8d70a70b9b8093d34a7e']: _.omit(
107
+ state['0xd63db0b88dca565633fb8d70a70b9b8093d34a7e'],
108
+ ['balancesLiveScaled18', 'tokenRates'],
109
+ ),
110
+ };
111
+ const expectedCompare = {
112
+ ...expectedState,
113
+ ['0xd63db0b88dca565633fb8d70a70b9b8093d34a7e']: {
114
+ ..._.omit(expectedState['0xd63db0b88dca565633fb8d70a70b9b8093d34a7e'], [
115
+ 'balancesLiveScaled18',
116
+ 'tokenRates',
117
+ ]),
118
+ ampStartTime: 0n,
119
+ ampStopTime: 0n,
120
+ },
121
+ };
122
+ expect(compare).toEqual(expectedCompare);
123
+ } else expect(state).toEqual(expectedState);
124
+ }
125
+
126
+ // eventName -> blockNumbers
127
+ type EventMappings = Record<string, EventData>;
128
+ type EventData = { blockNumbers: number[]; poolAddress: string[] };
129
+
130
+ describe('BalancerV3 EventPool', function () {
131
+ const dexKey = 'BalancerV3';
132
+ const network = Network.SEPOLIA;
133
+ const dexHelper = new DummyDexHelper(network);
134
+ const logger = dexHelper.getLogger(dexKey);
135
+ let balancerV3Pool: BalancerV3EventPool;
136
+
137
+ // vault -> EventMappings
138
+ // TODO once we have a new test deployment add tests for: AggregateSwapFeePercentageChanged, SwapFeePercentageChanged, PoolPausedStateChanged
139
+ const eventsToTest: Record<Address, EventMappings> = {
140
+ [BalancerV3Config.BalancerV3[network].vaultAddress]: {
141
+ // https://eth-sepolia.blockscout.com/tx/0xc417d38ad6e21250c9ddded37680b40f0991cfd3f8ae2d8b5800507a58d48c44
142
+ LiquidityAdded: {
143
+ blockNumbers: [7170937],
144
+ poolAddress: ['0x2ff3b96e0057a1f25f1d62ab800554ccdb268ab8'],
145
+ },
146
+ // https://sepolia.etherscan.io/tx/0xc1596e26d51104b9236a0debc3e1946b30b82f92b8331639ad6f6aea2ff2decc
147
+ LiquidityRemoved: {
148
+ blockNumbers: [7170957],
149
+ poolAddress: ['0x2ff3b96e0057a1f25f1d62ab800554ccdb268ab8'],
150
+ },
151
+ // https://sepolia.etherscan.io/tx/0x78d18503c2dd4458c94ec916b10c088bb4e8b90059676d00dbcec83f763d8c0e
152
+ Swap: {
153
+ blockNumbers: [7175721],
154
+ poolAddress: ['0x2ff3b96e0057a1f25f1d62ab800554ccdb268ab8'],
155
+ },
156
+ // 7170034, AmpUpdateStarted, https://eth-sepolia.blockscout.com/tx/0xfbe2e53d9cede1dc900100a1d6e809a89d909746ac7b8cc011e93227af8dda8b?tab=logs
157
+ // 7170069, AmpUpdateStopped, https://eth-sepolia.blockscout.com/tx/0x2ee2e1d5980013fdf1cf9c3789e0321fb598c2412db8ee8057fcfaffd1c792ab?tab=logs
158
+ VaultAuxiliary: {
159
+ blockNumbers: [7170034, 7170069],
160
+ poolAddress: [
161
+ '0xD63dB0B88dca565633fB8d70a70b9b8093d34A7E',
162
+ '0xD63dB0B88dca565633fB8d70a70b9b8093d34A7E',
163
+ ],
164
+ },
165
+ // https://sepolia.etherscan.io/tx/0x71f9879485f4e4cf97aa42381988ffe277f05a872d6b507cfa007cec1239a3f8#eventlog
166
+ SwapFeePercentageChanged: {
167
+ blockNumbers: [7206571],
168
+ poolAddress: ['0xe69b70a86A4e1fD33dA95693A1aE12Be1c26C8ea'],
169
+ },
170
+ // https://sepolia.etherscan.io/tx/0xaf232ca2df59ba5fad38d74e9b54ec2ae1ad2e6abca8348f107cf3fd94c787c7#eventlog
171
+ // Should remove pool from state as its paused and no longer supports swaps
172
+ PoolPausedStateChanged: {
173
+ blockNumbers: [7206586],
174
+ poolAddress: ['0xe69b70a86A4e1fD33dA95693A1aE12Be1c26C8ea'],
175
+ },
176
+ // https://sepolia.etherscan.io/tx/0xa23dc10bd0fbed7ffffe867766d9b0d7670ca4a0bc352669f547bc7775644349#eventlog
177
+ AggregateSwapFeePercentageChanged: {
178
+ blockNumbers: [7206701],
179
+ poolAddress: ['0xe69b70a86A4e1fD33dA95693A1aE12Be1c26C8ea'],
180
+ },
181
+ },
182
+ };
183
+
184
+ beforeEach(async () => {
185
+ balancerV3Pool = new BalancerV3EventPool(
186
+ dexKey,
187
+ network,
188
+ dexHelper,
189
+ logger,
190
+ );
191
+ });
192
+
193
+ Object.entries(eventsToTest).forEach(
194
+ ([vaultAddress, events]: [string, EventMappings]) => {
195
+ describe(`Events for Vault: ${vaultAddress}`, () => {
196
+ Object.entries(events).forEach(
197
+ ([eventName, eventData]: [string, EventData]) => {
198
+ describe(`${eventName}`, () => {
199
+ eventData.blockNumbers.forEach((blockNumber: number, i) => {
200
+ it(`Pool: ${eventData.poolAddress[i]} State after ${blockNumber}`, async function () {
201
+ await testEventSubscriber(
202
+ balancerV3Pool,
203
+ balancerV3Pool.addressesSubscribed,
204
+ (_blockNumber: number) =>
205
+ fetchPoolState(
206
+ balancerV3Pool,
207
+ _blockNumber,
208
+ eventData.poolAddress[i],
209
+ ),
210
+ blockNumber,
211
+ `${dexKey}_${vaultAddress}`,
212
+ dexHelper.provider,
213
+ stateCompare,
214
+ );
215
+ });
216
+ });
217
+ });
218
+ },
219
+ );
220
+ });
221
+ },
222
+ );
223
+ });