@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
@@ -0,0 +1,879 @@
1
+ /* eslint-disable no-console */
2
+ import dotenv from 'dotenv';
3
+ dotenv.config();
4
+
5
+ import { Interface, Result } from '@ethersproject/abi';
6
+ import { DummyDexHelper } from '../../dex-helper/index';
7
+ import { Network, NULL_ADDRESS, SwapSide } from '../../constants';
8
+ import { BI_POWS } from '../../bigint-constants';
9
+ import { BalancerV3 } from './balancer-v3';
10
+ import {
11
+ checkPoolPrices,
12
+ checkConstantPoolPrices,
13
+ checkPoolsLiquidity,
14
+ } from '../../../tests/utils';
15
+ import { Tokens } from '../../../tests/constants-e2e';
16
+ import { BalancerV3Config } from './config';
17
+ import { BalancerV3Data, Step } from './types';
18
+ import { Address, ExchangePrices, PoolPrices } from '../../types';
19
+ import balancerBatchRouterAbi from '../../abi/balancer-v3/batch-router.json';
20
+ import balancerRouterAbi from '../../abi/balancer-v3/router.json';
21
+
22
+ function getQuerySwapSingleTokenCalldata(
23
+ routerAddress: Address,
24
+ routerInterface: Interface,
25
+ amounts: bigint[],
26
+ step: Step,
27
+ side: SwapSide,
28
+ ) {
29
+ return amounts
30
+ .filter(amount => amount !== 0n)
31
+ .map(amount => {
32
+ return {
33
+ target: routerAddress,
34
+ callData: routerInterface.encodeFunctionData(
35
+ side === SwapSide.SELL
36
+ ? `querySwapSingleTokenExactIn`
37
+ : `querySwapSingleTokenExactOut`,
38
+ [
39
+ step.pool,
40
+ step.swapInput.tokenIn,
41
+ step.swapInput.tokenOut,
42
+ amount,
43
+ NULL_ADDRESS,
44
+ '0x',
45
+ ],
46
+ ),
47
+ };
48
+ });
49
+ }
50
+
51
+ function getQuerySwapMultiTokenCalldata(
52
+ routerAddress: Address,
53
+ routerInterface: Interface,
54
+ amounts: bigint[],
55
+ steps: Step[],
56
+ side: SwapSide,
57
+ ) {
58
+ const tokenIn = steps[0].swapInput.tokenIn;
59
+ const stepsNew = steps.map(s => ({
60
+ pool: s.pool,
61
+ tokenOut: s.swapInput.tokenOut,
62
+ isBuffer: s.isBuffer,
63
+ }));
64
+ return amounts
65
+ .filter(amount => amount !== 0n)
66
+ .map(amount => {
67
+ let args: any[] = [];
68
+ if (side === SwapSide.SELL)
69
+ args = [
70
+ {
71
+ tokenIn,
72
+ steps: stepsNew,
73
+ exactAmountIn: amount,
74
+ minAmountOut: 0n,
75
+ },
76
+ ];
77
+ else
78
+ args = [
79
+ {
80
+ tokenIn,
81
+ steps: stepsNew,
82
+ exactAmountOut: amount,
83
+ maxAmountIn: 0n,
84
+ },
85
+ ];
86
+ return {
87
+ target: routerAddress,
88
+ callData: routerInterface.encodeFunctionData(
89
+ side === SwapSide.SELL ? `querySwapExactIn` : `querySwapExactOut`,
90
+ [args, NULL_ADDRESS, '0x'],
91
+ ),
92
+ };
93
+ });
94
+ }
95
+
96
+ async function querySinglePathPrices(
97
+ network: number,
98
+ side: SwapSide,
99
+ balancerV3: BalancerV3,
100
+ blockNumber: number,
101
+ price: PoolPrices<BalancerV3Data>,
102
+ amounts: bigint[],
103
+ ) {
104
+ const balancerRouter = new Interface(balancerRouterAbi);
105
+ const readerCallData = getQuerySwapSingleTokenCalldata(
106
+ BalancerV3Config.BalancerV3[network].balancerRouterAddress,
107
+ balancerRouter,
108
+ amounts,
109
+ price.data.steps[0],
110
+ side,
111
+ );
112
+
113
+ const expectedPrices = [0n];
114
+ for (const call of readerCallData) {
115
+ try {
116
+ const result = await balancerV3.dexHelper.provider.call(
117
+ {
118
+ to: call.target,
119
+ data: call.callData,
120
+ },
121
+ blockNumber,
122
+ );
123
+ const parsed = balancerRouter.decodeFunctionResult(
124
+ side === SwapSide.SELL
125
+ ? `querySwapSingleTokenExactIn`
126
+ : `querySwapSingleTokenExactOut`,
127
+ result,
128
+ );
129
+ expectedPrices.push(BigInt(parsed[0]._hex));
130
+ } catch (error) {
131
+ console.log('Error in querySinglePathPrices', error);
132
+ expectedPrices.push(0n);
133
+ }
134
+ }
135
+ return expectedPrices;
136
+ }
137
+
138
+ async function queryMultiPathPrices(
139
+ network: number,
140
+ side: SwapSide,
141
+ balancerV3: BalancerV3,
142
+ blockNumber: number,
143
+ price: PoolPrices<BalancerV3Data>,
144
+ amounts: bigint[],
145
+ ) {
146
+ const balancerBatchRouter = new Interface(balancerBatchRouterAbi);
147
+ const readerCallData = getQuerySwapMultiTokenCalldata(
148
+ BalancerV3Config.BalancerV3[network].balancerBatchRouterAddress,
149
+ balancerBatchRouter,
150
+ amounts,
151
+ price.data.steps,
152
+ side,
153
+ );
154
+
155
+ const expectedPrices = [0n];
156
+ for (const call of readerCallData) {
157
+ try {
158
+ const result = await balancerV3.dexHelper.provider.call(
159
+ {
160
+ to: call.target,
161
+ data: call.callData,
162
+ },
163
+ blockNumber,
164
+ );
165
+ const parsed = balancerBatchRouter.decodeFunctionResult(
166
+ side === SwapSide.SELL ? `querySwapExactIn` : `querySwapExactOut`,
167
+ result,
168
+ );
169
+ expectedPrices.push(BigInt(parsed[2][0]._hex));
170
+ } catch (error) {
171
+ console.log('Error in queryMultiPathPrices', error);
172
+ expectedPrices.push(0n);
173
+ }
174
+ }
175
+ return expectedPrices;
176
+ }
177
+
178
+ // Note - this is currently needed because queries won't work with multicall but should be updated in future
179
+ async function checkOnChainPricingNonMulti(
180
+ network: number,
181
+ side: SwapSide,
182
+ balancerV3: BalancerV3,
183
+ blockNumber: number,
184
+ prices: ExchangePrices<BalancerV3Data>,
185
+ amounts: bigint[],
186
+ ) {
187
+ // test match for each returned price
188
+ for (const price of prices) {
189
+ let expectedPrices: bigint[] = [];
190
+ if (price.data.steps.length === 1)
191
+ expectedPrices = await querySinglePathPrices(
192
+ network,
193
+ side,
194
+ balancerV3,
195
+ blockNumber,
196
+ price,
197
+ amounts,
198
+ );
199
+ else
200
+ expectedPrices = await queryMultiPathPrices(
201
+ network,
202
+ side,
203
+ balancerV3,
204
+ blockNumber,
205
+ price,
206
+ amounts,
207
+ );
208
+ expect(price.prices).toEqual(expectedPrices);
209
+ }
210
+ }
211
+
212
+ async function testPricingOnNetwork(
213
+ balancerV3: BalancerV3,
214
+ network: Network,
215
+ dexKey: string,
216
+ blockNumber: number,
217
+ srcTokenSymbol: string,
218
+ destTokenSymbol: string,
219
+ side: SwapSide,
220
+ amounts: bigint[],
221
+ ) {
222
+ const networkTokens = Tokens[network];
223
+
224
+ const pools = await balancerV3.getPoolIdentifiers(
225
+ networkTokens[srcTokenSymbol],
226
+ networkTokens[destTokenSymbol],
227
+ side,
228
+ blockNumber,
229
+ );
230
+ console.log(
231
+ `${srcTokenSymbol} <> ${destTokenSymbol} Pool Identifiers: `,
232
+ pools,
233
+ );
234
+
235
+ expect(pools.length).toBeGreaterThan(0);
236
+
237
+ const poolPrices = await balancerV3.getPricesVolume(
238
+ networkTokens[srcTokenSymbol],
239
+ networkTokens[destTokenSymbol],
240
+ amounts,
241
+ side,
242
+ blockNumber,
243
+ pools,
244
+ );
245
+ console.log(
246
+ `${srcTokenSymbol} <> ${destTokenSymbol} Pool Prices: `,
247
+ poolPrices,
248
+ );
249
+
250
+ expect(poolPrices).not.toBeNull();
251
+ if (balancerV3.hasConstantPriceLargeAmounts) {
252
+ checkConstantPoolPrices(poolPrices!, amounts, dexKey);
253
+ } else {
254
+ checkPoolPrices(poolPrices!, amounts, side, dexKey, false);
255
+ }
256
+
257
+ // Check if onchain pricing equals to calculated ones
258
+ await checkOnChainPricingNonMulti(
259
+ network,
260
+ side,
261
+ balancerV3,
262
+ blockNumber,
263
+ poolPrices!,
264
+ amounts,
265
+ );
266
+ }
267
+
268
+ describe('BalancerV3', function () {
269
+ const dexKey = 'BalancerV3';
270
+ let blockNumber: number;
271
+ let balancerV3: BalancerV3;
272
+
273
+ describe('Sepolia', () => {
274
+ const network = Network.SEPOLIA;
275
+
276
+ describe('Weighted Pool', () => {
277
+ const dexHelper = new DummyDexHelper(network);
278
+
279
+ const tokens = Tokens[network];
280
+ const srcTokenSymbol = 'bal';
281
+ const destTokenSymbol = 'daiAave';
282
+
283
+ const amountsForSell = [
284
+ 0n,
285
+ 1n * BI_POWS[tokens[srcTokenSymbol].decimals],
286
+ 2n * BI_POWS[tokens[srcTokenSymbol].decimals],
287
+ 3n * BI_POWS[tokens[srcTokenSymbol].decimals],
288
+ 4n * BI_POWS[tokens[srcTokenSymbol].decimals],
289
+ 5n * BI_POWS[tokens[srcTokenSymbol].decimals],
290
+ 6n * BI_POWS[tokens[srcTokenSymbol].decimals],
291
+ 7n * BI_POWS[tokens[srcTokenSymbol].decimals],
292
+ 8n * BI_POWS[tokens[srcTokenSymbol].decimals],
293
+ 9n * BI_POWS[tokens[srcTokenSymbol].decimals],
294
+ 10n * BI_POWS[tokens[srcTokenSymbol].decimals],
295
+ ];
296
+
297
+ const amountsForBuy = [
298
+ 0n,
299
+ 1n * BI_POWS[tokens[destTokenSymbol].decimals],
300
+ 2n * BI_POWS[tokens[destTokenSymbol].decimals],
301
+ 3n * BI_POWS[tokens[destTokenSymbol].decimals],
302
+ 4n * BI_POWS[tokens[destTokenSymbol].decimals],
303
+ 5n * BI_POWS[tokens[destTokenSymbol].decimals],
304
+ 6n * BI_POWS[tokens[destTokenSymbol].decimals],
305
+ 7n * BI_POWS[tokens[destTokenSymbol].decimals],
306
+ 8n * BI_POWS[tokens[destTokenSymbol].decimals],
307
+ 9n * BI_POWS[tokens[destTokenSymbol].decimals],
308
+ 10n * BI_POWS[tokens[destTokenSymbol].decimals],
309
+ ];
310
+
311
+ beforeAll(async () => {
312
+ blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
313
+ balancerV3 = new BalancerV3(network, dexKey, dexHelper);
314
+ if (balancerV3.initializePricing) {
315
+ await balancerV3.initializePricing(blockNumber);
316
+ }
317
+ });
318
+
319
+ it('getPoolIdentifiers and getPricesVolume SELL', async function () {
320
+ await testPricingOnNetwork(
321
+ balancerV3,
322
+ network,
323
+ dexKey,
324
+ blockNumber,
325
+ srcTokenSymbol,
326
+ destTokenSymbol,
327
+ SwapSide.SELL,
328
+ amountsForSell,
329
+ );
330
+ });
331
+
332
+ it('getPoolIdentifiers and getPricesVolume BUY', async function () {
333
+ await testPricingOnNetwork(
334
+ balancerV3,
335
+ network,
336
+ dexKey,
337
+ blockNumber,
338
+ srcTokenSymbol,
339
+ destTokenSymbol,
340
+ SwapSide.BUY,
341
+ amountsForBuy,
342
+ );
343
+ });
344
+
345
+ it('getTopPoolsForToken', async function () {
346
+ // We have to check without calling initializePricing, because
347
+ // pool-tracker is not calling that function
348
+ const newBalancerV3 = new BalancerV3(network, dexKey, dexHelper);
349
+ if (newBalancerV3.updatePoolState) {
350
+ await newBalancerV3.updatePoolState();
351
+ }
352
+ const poolLiquidity = await newBalancerV3.getTopPoolsForToken(
353
+ tokens[srcTokenSymbol].address,
354
+ 10,
355
+ );
356
+ console.log(`${srcTokenSymbol} Top Pools:`, poolLiquidity);
357
+
358
+ if (!newBalancerV3.hasConstantPriceLargeAmounts) {
359
+ checkPoolsLiquidity(
360
+ poolLiquidity,
361
+ Tokens[network][srcTokenSymbol].address,
362
+ dexKey,
363
+ );
364
+ }
365
+ });
366
+ });
367
+
368
+ describe('Stable Pool', () => {
369
+ const dexHelper = new DummyDexHelper(network);
370
+
371
+ const tokens = Tokens[network];
372
+ const srcTokenSymbol = 'stataUSDC';
373
+ const destTokenSymbol = 'stataUSDT';
374
+
375
+ const amountsForSell = [
376
+ 0n,
377
+ 1n * BI_POWS[tokens[srcTokenSymbol].decimals],
378
+ 2n * BI_POWS[tokens[srcTokenSymbol].decimals],
379
+ 3n * BI_POWS[tokens[srcTokenSymbol].decimals],
380
+ 4n * BI_POWS[tokens[srcTokenSymbol].decimals],
381
+ 5n * BI_POWS[tokens[srcTokenSymbol].decimals],
382
+ 6n * BI_POWS[tokens[srcTokenSymbol].decimals],
383
+ 7n * BI_POWS[tokens[srcTokenSymbol].decimals],
384
+ 8n * BI_POWS[tokens[srcTokenSymbol].decimals],
385
+ 9n * BI_POWS[tokens[srcTokenSymbol].decimals],
386
+ 10n * BI_POWS[tokens[srcTokenSymbol].decimals],
387
+ ];
388
+
389
+ const amountsForBuy = [
390
+ 0n,
391
+ 1n * BI_POWS[tokens[destTokenSymbol].decimals],
392
+ 2n * BI_POWS[tokens[destTokenSymbol].decimals],
393
+ 3n * BI_POWS[tokens[destTokenSymbol].decimals],
394
+ 4n * BI_POWS[tokens[destTokenSymbol].decimals],
395
+ 5n * BI_POWS[tokens[destTokenSymbol].decimals],
396
+ 6n * BI_POWS[tokens[destTokenSymbol].decimals],
397
+ 7n * BI_POWS[tokens[destTokenSymbol].decimals],
398
+ 8n * BI_POWS[tokens[destTokenSymbol].decimals],
399
+ 9n * BI_POWS[tokens[destTokenSymbol].decimals],
400
+ 10n * BI_POWS[tokens[destTokenSymbol].decimals],
401
+ ];
402
+
403
+ beforeAll(async () => {
404
+ blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
405
+ balancerV3 = new BalancerV3(network, dexKey, dexHelper);
406
+ if (balancerV3.initializePricing) {
407
+ await balancerV3.initializePricing(blockNumber);
408
+ }
409
+ });
410
+
411
+ it('getPoolIdentifiers and getPricesVolume SELL', async function () {
412
+ await testPricingOnNetwork(
413
+ balancerV3,
414
+ network,
415
+ dexKey,
416
+ blockNumber,
417
+ srcTokenSymbol,
418
+ destTokenSymbol,
419
+ SwapSide.SELL,
420
+ amountsForSell,
421
+ );
422
+ });
423
+
424
+ it('getPoolIdentifiers and getPricesVolume BUY', async function () {
425
+ await testPricingOnNetwork(
426
+ balancerV3,
427
+ network,
428
+ dexKey,
429
+ blockNumber,
430
+ srcTokenSymbol,
431
+ destTokenSymbol,
432
+ SwapSide.BUY,
433
+ amountsForBuy,
434
+ );
435
+ });
436
+
437
+ it('getTopPoolsForToken', async function () {
438
+ // We have to check without calling initializePricing, because
439
+ // pool-tracker is not calling that function
440
+ const newBalancerV3 = new BalancerV3(network, dexKey, dexHelper);
441
+ if (newBalancerV3.updatePoolState) {
442
+ await newBalancerV3.updatePoolState();
443
+ }
444
+ const poolLiquidity = await newBalancerV3.getTopPoolsForToken(
445
+ tokens[srcTokenSymbol].address,
446
+ 10,
447
+ );
448
+ console.log(`${srcTokenSymbol} Top Pools:`, poolLiquidity);
449
+
450
+ if (!newBalancerV3.hasConstantPriceLargeAmounts) {
451
+ checkPoolsLiquidity(
452
+ poolLiquidity,
453
+ Tokens[network][srcTokenSymbol].address,
454
+ dexKey,
455
+ );
456
+ }
457
+ });
458
+ });
459
+
460
+ describe('Boosted Path', () => {
461
+ const dexHelper = new DummyDexHelper(network);
462
+
463
+ const tokens = Tokens[network];
464
+ const srcTokenSymbol = 'usdcAave';
465
+ const destTokenSymbol = 'usdtAave';
466
+
467
+ const amountsForSell = [
468
+ 0n,
469
+ 1n * BI_POWS[tokens[srcTokenSymbol].decimals],
470
+ 2n * BI_POWS[tokens[srcTokenSymbol].decimals],
471
+ 3n * BI_POWS[tokens[srcTokenSymbol].decimals],
472
+ 4n * BI_POWS[tokens[srcTokenSymbol].decimals],
473
+ 5n * BI_POWS[tokens[srcTokenSymbol].decimals],
474
+ 6n * BI_POWS[tokens[srcTokenSymbol].decimals],
475
+ 7n * BI_POWS[tokens[srcTokenSymbol].decimals],
476
+ 8n * BI_POWS[tokens[srcTokenSymbol].decimals],
477
+ 9n * BI_POWS[tokens[srcTokenSymbol].decimals],
478
+ 10n * BI_POWS[tokens[srcTokenSymbol].decimals],
479
+ ];
480
+
481
+ const amountsForBuy = [
482
+ 0n,
483
+ 1n * BI_POWS[tokens[destTokenSymbol].decimals],
484
+ 2n * BI_POWS[tokens[destTokenSymbol].decimals],
485
+ 3n * BI_POWS[tokens[destTokenSymbol].decimals],
486
+ 4n * BI_POWS[tokens[destTokenSymbol].decimals],
487
+ 5n * BI_POWS[tokens[destTokenSymbol].decimals],
488
+ 6n * BI_POWS[tokens[destTokenSymbol].decimals],
489
+ 7n * BI_POWS[tokens[destTokenSymbol].decimals],
490
+ 8n * BI_POWS[tokens[destTokenSymbol].decimals],
491
+ 9n * BI_POWS[tokens[destTokenSymbol].decimals],
492
+ 10n * BI_POWS[tokens[destTokenSymbol].decimals],
493
+ ];
494
+
495
+ beforeAll(async () => {
496
+ blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
497
+ balancerV3 = new BalancerV3(network, dexKey, dexHelper);
498
+ if (balancerV3.initializePricing) {
499
+ await balancerV3.initializePricing(blockNumber);
500
+ }
501
+ });
502
+
503
+ it('getPoolIdentifiers and getPricesVolume SELL', async function () {
504
+ await testPricingOnNetwork(
505
+ balancerV3,
506
+ network,
507
+ dexKey,
508
+ blockNumber,
509
+ srcTokenSymbol,
510
+ destTokenSymbol,
511
+ SwapSide.SELL,
512
+ amountsForSell,
513
+ );
514
+ });
515
+
516
+ // TODO 1 WEI rounding issue in maths - investigating
517
+ it('getPoolIdentifiers and getPricesVolume BUY', async function () {
518
+ await testPricingOnNetwork(
519
+ balancerV3,
520
+ network,
521
+ dexKey,
522
+ blockNumber,
523
+ srcTokenSymbol,
524
+ destTokenSymbol,
525
+ SwapSide.BUY,
526
+ amountsForBuy,
527
+ );
528
+ });
529
+
530
+ it('getTopPoolsForToken', async function () {
531
+ // We have to check without calling initializePricing, because
532
+ // pool-tracker is not calling that function
533
+ const newBalancerV3 = new BalancerV3(network, dexKey, dexHelper);
534
+ if (newBalancerV3.updatePoolState) {
535
+ await newBalancerV3.updatePoolState();
536
+ }
537
+ const poolLiquidity = await newBalancerV3.getTopPoolsForToken(
538
+ tokens[srcTokenSymbol].address,
539
+ 10,
540
+ );
541
+ console.log(`${srcTokenSymbol} Top Pools:`, poolLiquidity);
542
+
543
+ if (!newBalancerV3.hasConstantPriceLargeAmounts) {
544
+ checkPoolsLiquidity(
545
+ poolLiquidity,
546
+ Tokens[network][srcTokenSymbol].address,
547
+ dexKey,
548
+ );
549
+ }
550
+ });
551
+ });
552
+ });
553
+
554
+ describe('Gnosis', () => {
555
+ const network = Network.GNOSIS;
556
+
557
+ describe('Weighted Pool', () => {
558
+ const dexHelper = new DummyDexHelper(network);
559
+
560
+ const tokens = Tokens[network];
561
+ const srcTokenSymbol = 'USDCe';
562
+ const destTokenSymbol = 'sDAI';
563
+
564
+ const amountsForSell = [
565
+ 0n,
566
+ 1n * BI_POWS[tokens[srcTokenSymbol].decimals],
567
+ 2n * BI_POWS[tokens[srcTokenSymbol].decimals],
568
+ 3n * BI_POWS[tokens[srcTokenSymbol].decimals],
569
+ 4n * BI_POWS[tokens[srcTokenSymbol].decimals],
570
+ 5n * BI_POWS[tokens[srcTokenSymbol].decimals],
571
+ 6n * BI_POWS[tokens[srcTokenSymbol].decimals],
572
+ 7n * BI_POWS[tokens[srcTokenSymbol].decimals],
573
+ 8n * BI_POWS[tokens[srcTokenSymbol].decimals],
574
+ 9n * BI_POWS[tokens[srcTokenSymbol].decimals],
575
+ 10n * BI_POWS[tokens[srcTokenSymbol].decimals],
576
+ ];
577
+
578
+ const amountsForBuy = [
579
+ 0n,
580
+ 1n * BI_POWS[tokens[destTokenSymbol].decimals],
581
+ 2n * BI_POWS[tokens[destTokenSymbol].decimals],
582
+ 3n * BI_POWS[tokens[destTokenSymbol].decimals],
583
+ 4n * BI_POWS[tokens[destTokenSymbol].decimals],
584
+ 5n * BI_POWS[tokens[destTokenSymbol].decimals],
585
+ 6n * BI_POWS[tokens[destTokenSymbol].decimals],
586
+ 7n * BI_POWS[tokens[destTokenSymbol].decimals],
587
+ 8n * BI_POWS[tokens[destTokenSymbol].decimals],
588
+ 9n * BI_POWS[tokens[destTokenSymbol].decimals],
589
+ 10n * BI_POWS[tokens[destTokenSymbol].decimals],
590
+ ];
591
+
592
+ beforeAll(async () => {
593
+ blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
594
+ balancerV3 = new BalancerV3(network, dexKey, dexHelper);
595
+ if (balancerV3.initializePricing) {
596
+ await balancerV3.initializePricing(blockNumber);
597
+ }
598
+ });
599
+
600
+ it('getPoolIdentifiers and getPricesVolume SELL', async function () {
601
+ await testPricingOnNetwork(
602
+ balancerV3,
603
+ network,
604
+ dexKey,
605
+ blockNumber,
606
+ srcTokenSymbol,
607
+ destTokenSymbol,
608
+ SwapSide.SELL,
609
+ amountsForSell,
610
+ );
611
+ });
612
+
613
+ it('getPoolIdentifiers and getPricesVolume BUY', async function () {
614
+ await testPricingOnNetwork(
615
+ balancerV3,
616
+ network,
617
+ dexKey,
618
+ blockNumber,
619
+ srcTokenSymbol,
620
+ destTokenSymbol,
621
+ SwapSide.BUY,
622
+ amountsForBuy,
623
+ );
624
+ });
625
+
626
+ it('getTopPoolsForToken', async function () {
627
+ // We have to check without calling initializePricing, because
628
+ // pool-tracker is not calling that function
629
+ const newBalancerV3 = new BalancerV3(network, dexKey, dexHelper);
630
+ if (newBalancerV3.updatePoolState) {
631
+ await newBalancerV3.updatePoolState();
632
+ }
633
+ const poolLiquidity = await newBalancerV3.getTopPoolsForToken(
634
+ tokens[srcTokenSymbol].address,
635
+ 10,
636
+ );
637
+ console.log(`${srcTokenSymbol} Top Pools:`, poolLiquidity);
638
+
639
+ if (!newBalancerV3.hasConstantPriceLargeAmounts) {
640
+ checkPoolsLiquidity(
641
+ poolLiquidity,
642
+ Tokens[network][srcTokenSymbol].address,
643
+ dexKey,
644
+ );
645
+ }
646
+ });
647
+ });
648
+
649
+ describe('Stable Pool', () => {
650
+ const dexHelper = new DummyDexHelper(network);
651
+
652
+ const tokens = Tokens[network];
653
+ const srcTokenSymbol = 'WXDAI';
654
+ const destTokenSymbol = 'COW';
655
+
656
+ const amountsForSell = [
657
+ 0n,
658
+ 1n * BI_POWS[tokens[srcTokenSymbol].decimals],
659
+ 2n * BI_POWS[tokens[srcTokenSymbol].decimals],
660
+ 3n * BI_POWS[tokens[srcTokenSymbol].decimals],
661
+ 4n * BI_POWS[tokens[srcTokenSymbol].decimals],
662
+ 5n * BI_POWS[tokens[srcTokenSymbol].decimals],
663
+ 6n * BI_POWS[tokens[srcTokenSymbol].decimals],
664
+ 7n * BI_POWS[tokens[srcTokenSymbol].decimals],
665
+ 8n * BI_POWS[tokens[srcTokenSymbol].decimals],
666
+ 9n * BI_POWS[tokens[srcTokenSymbol].decimals],
667
+ 10n * BI_POWS[tokens[srcTokenSymbol].decimals],
668
+ ];
669
+
670
+ const amountsForBuy = [
671
+ 0n,
672
+ 1n * BI_POWS[tokens[destTokenSymbol].decimals],
673
+ 2n * BI_POWS[tokens[destTokenSymbol].decimals],
674
+ 3n * BI_POWS[tokens[destTokenSymbol].decimals],
675
+ 4n * BI_POWS[tokens[destTokenSymbol].decimals],
676
+ 5n * BI_POWS[tokens[destTokenSymbol].decimals],
677
+ 6n * BI_POWS[tokens[destTokenSymbol].decimals],
678
+ 7n * BI_POWS[tokens[destTokenSymbol].decimals],
679
+ 8n * BI_POWS[tokens[destTokenSymbol].decimals],
680
+ 9n * BI_POWS[tokens[destTokenSymbol].decimals],
681
+ 10n * BI_POWS[tokens[destTokenSymbol].decimals],
682
+ ];
683
+
684
+ beforeAll(async () => {
685
+ blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
686
+ balancerV3 = new BalancerV3(network, dexKey, dexHelper);
687
+ if (balancerV3.initializePricing) {
688
+ await balancerV3.initializePricing(blockNumber);
689
+ }
690
+ });
691
+
692
+ it('getPoolIdentifiers and getPricesVolume SELL', async function () {
693
+ await testPricingOnNetwork(
694
+ balancerV3,
695
+ network,
696
+ dexKey,
697
+ blockNumber,
698
+ srcTokenSymbol,
699
+ destTokenSymbol,
700
+ SwapSide.SELL,
701
+ amountsForSell,
702
+ );
703
+ });
704
+
705
+ it('getPoolIdentifiers and getPricesVolume BUY', async function () {
706
+ await testPricingOnNetwork(
707
+ balancerV3,
708
+ network,
709
+ dexKey,
710
+ blockNumber,
711
+ srcTokenSymbol,
712
+ destTokenSymbol,
713
+ SwapSide.BUY,
714
+ amountsForBuy,
715
+ );
716
+ });
717
+
718
+ it('getTopPoolsForToken', async function () {
719
+ // We have to check without calling initializePricing, because
720
+ // pool-tracker is not calling that function
721
+ const newBalancerV3 = new BalancerV3(network, dexKey, dexHelper);
722
+ if (newBalancerV3.updatePoolState) {
723
+ await newBalancerV3.updatePoolState();
724
+ }
725
+ const poolLiquidity = await newBalancerV3.getTopPoolsForToken(
726
+ tokens[srcTokenSymbol].address,
727
+ 10,
728
+ );
729
+ console.log(`${srcTokenSymbol} Top Pools:`, poolLiquidity);
730
+
731
+ if (!newBalancerV3.hasConstantPriceLargeAmounts) {
732
+ checkPoolsLiquidity(
733
+ poolLiquidity,
734
+ Tokens[network][srcTokenSymbol].address,
735
+ dexKey,
736
+ );
737
+ }
738
+ });
739
+ });
740
+
741
+ describe('Boosted Path', () => {
742
+ const dexHelper = new DummyDexHelper(network);
743
+
744
+ const tokens = Tokens[network];
745
+ const srcTokenSymbol = 'waGnoWETH';
746
+ const destTokenSymbol = 'waGnowstETH';
747
+
748
+ const amountsForSell = [
749
+ 0n,
750
+ (1n * BI_POWS[tokens[srcTokenSymbol].decimals]) / 1000n,
751
+ (2n * BI_POWS[tokens[srcTokenSymbol].decimals]) / 1000n,
752
+ (3n * BI_POWS[tokens[srcTokenSymbol].decimals]) / 1000n,
753
+ (4n * BI_POWS[tokens[srcTokenSymbol].decimals]) / 1000n,
754
+ (5n * BI_POWS[tokens[srcTokenSymbol].decimals]) / 1000n,
755
+ (6n * BI_POWS[tokens[srcTokenSymbol].decimals]) / 1000n,
756
+ (7n * BI_POWS[tokens[srcTokenSymbol].decimals]) / 1000n,
757
+ (8n * BI_POWS[tokens[srcTokenSymbol].decimals]) / 1000n,
758
+ (9n * BI_POWS[tokens[srcTokenSymbol].decimals]) / 1000n,
759
+ (10n * BI_POWS[tokens[srcTokenSymbol].decimals]) / 1000n,
760
+ ];
761
+
762
+ const amountsForBuy = [
763
+ 0n,
764
+ (1n * BI_POWS[tokens[destTokenSymbol].decimals]) / 1000n,
765
+ (2n * BI_POWS[tokens[destTokenSymbol].decimals]) / 1000n,
766
+ (3n * BI_POWS[tokens[destTokenSymbol].decimals]) / 1000n,
767
+ (4n * BI_POWS[tokens[destTokenSymbol].decimals]) / 1000n,
768
+ (5n * BI_POWS[tokens[destTokenSymbol].decimals]) / 1000n,
769
+ (6n * BI_POWS[tokens[destTokenSymbol].decimals]) / 1000n,
770
+ (7n * BI_POWS[tokens[destTokenSymbol].decimals]) / 1000n,
771
+ (8n * BI_POWS[tokens[destTokenSymbol].decimals]) / 1000n,
772
+ (9n * BI_POWS[tokens[destTokenSymbol].decimals]) / 1000n,
773
+ (10n * BI_POWS[tokens[destTokenSymbol].decimals]) / 1000n,
774
+ ];
775
+
776
+ beforeAll(async () => {
777
+ blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
778
+ balancerV3 = new BalancerV3(network, dexKey, dexHelper);
779
+ if (balancerV3.initializePricing) {
780
+ await balancerV3.initializePricing(blockNumber);
781
+ }
782
+ });
783
+
784
+ it('getPoolIdentifiers and getPricesVolume SELL', async function () {
785
+ await testPricingOnNetwork(
786
+ balancerV3,
787
+ network,
788
+ dexKey,
789
+ blockNumber,
790
+ srcTokenSymbol,
791
+ destTokenSymbol,
792
+ SwapSide.SELL,
793
+ amountsForSell,
794
+ );
795
+ });
796
+
797
+ // TODO 1 WEI rounding issue in maths - investigating
798
+ it('getPoolIdentifiers and getPricesVolume BUY', async function () {
799
+ await testPricingOnNetwork(
800
+ balancerV3,
801
+ network,
802
+ dexKey,
803
+ blockNumber,
804
+ srcTokenSymbol,
805
+ destTokenSymbol,
806
+ SwapSide.BUY,
807
+ amountsForBuy,
808
+ );
809
+ });
810
+
811
+ it('getTopPoolsForToken', async function () {
812
+ // We have to check without calling initializePricing, because
813
+ // pool-tracker is not calling that function
814
+ const newBalancerV3 = new BalancerV3(network, dexKey, dexHelper);
815
+ if (newBalancerV3.updatePoolState) {
816
+ await newBalancerV3.updatePoolState();
817
+ }
818
+ const poolLiquidity = await newBalancerV3.getTopPoolsForToken(
819
+ tokens[srcTokenSymbol].address,
820
+ 10,
821
+ );
822
+
823
+ console.log(`${srcTokenSymbol} Top Pools:`, poolLiquidity);
824
+
825
+ if (!newBalancerV3.hasConstantPriceLargeAmounts) {
826
+ checkPoolsLiquidity(
827
+ poolLiquidity,
828
+ Tokens[network][srcTokenSymbol].address,
829
+ dexKey,
830
+ );
831
+ }
832
+ });
833
+ });
834
+ });
835
+ });
836
+
837
+ // Add back once multicall queries are working
838
+ /*
839
+ function decodeQuerySwapSingleTokenResult(results: Result, side: SwapSide) {
840
+ const balancerRouter = new Interface(balancerRouterAbi);
841
+ return results.map(result => {
842
+ const parsed = balancerRouter.decodeFunctionResult(
843
+ side === SwapSide.SELL
844
+ ? `querySwapSingleTokenExactIn`
845
+ : `querySwapSingleTokenExactOut`,
846
+ result,
847
+ );
848
+ return BigInt(parsed[0]._hex);
849
+ });
850
+ }
851
+
852
+ async function checkOnChainPricing(
853
+ network: number,
854
+ side: SwapSide,
855
+ balancerV3: BalancerV3,
856
+ blockNumber: number,
857
+ prices: ExchangePrices<BalancerV3Data>,
858
+ amounts: bigint[],
859
+ ) {
860
+ // test match for each returned price
861
+ for (const price of prices) {
862
+ const readerCallData = getQuerySwapSingleTokenCalldata(
863
+ network,
864
+ amounts,
865
+ price.data.steps[0],
866
+ side,
867
+ );
868
+ const readerResult = (
869
+ await balancerV3.dexHelper.multiContract.methods
870
+ .aggregate(readerCallData)
871
+ .call({}, blockNumber)
872
+ ).returnData;
873
+ const expectedPrices = [0n].concat(
874
+ decodeQuerySwapSingleTokenResult(readerResult, side),
875
+ );
876
+ expect(price.prices).toEqual(expectedPrices);
877
+ }
878
+ }
879
+ */