@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,412 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.BalancerV3 = void 0;
40
+ const constants_1 = require("../../constants");
41
+ const CALLDATA_GAS_COST = __importStar(require("../../calldata-gas-cost"));
42
+ const utils_1 = require("../../utils");
43
+ const simple_exchange_1 = require("../simple-exchange");
44
+ const config_1 = require("./config");
45
+ const balancer_v3_pool_1 = require("./balancer-v3-pool");
46
+ const balancer_maths_1 = require("@balancer-labs/balancer-maths");
47
+ const abi_1 = require("@ethersproject/abi");
48
+ const utils_2 = require("../../executor/utils");
49
+ const getTopPoolsApi_1 = require("./getTopPoolsApi");
50
+ const router_json_1 = __importDefault(require("../../abi/balancer-v3/router.json"));
51
+ const batch_router_json_1 = __importDefault(require("../../abi/balancer-v3/batch-router.json"));
52
+ const getGasCost_1 = require("./getGasCost");
53
+ const MAX_UINT256 = '115792089237316195423570985008687907853269984665640564039457584007913129639935';
54
+ const POOL_UPDATE_TTL = 5 * 60; // 5mins
55
+ const RATE_UPDATE_TTL = 1 * 60; // 1min
56
+ class BalancerV3 extends simple_exchange_1.SimpleExchange {
57
+ network;
58
+ dexKey;
59
+ dexHelper;
60
+ eventPools;
61
+ hasConstantPriceLargeAmounts = false;
62
+ // Vault can handle native
63
+ needWrapNative = false;
64
+ isFeeOnTransferSupported = false;
65
+ static dexKeysWithNetwork = (0, utils_1.getDexKeysWithNetwork)(config_1.BalancerV3Config);
66
+ logger;
67
+ balancerRouter;
68
+ balancerBatchRouter;
69
+ updateNewPoolsTimer;
70
+ updateRatesTimer;
71
+ constructor(network, dexKey, dexHelper) {
72
+ super(dexHelper, dexKey);
73
+ this.network = network;
74
+ this.dexKey = dexKey;
75
+ this.dexHelper = dexHelper;
76
+ this.logger = dexHelper.getLogger(dexKey);
77
+ this.eventPools = new balancer_v3_pool_1.BalancerV3EventPool(dexKey, network, dexHelper, this.logger);
78
+ this.balancerRouter = new abi_1.Interface(router_json_1.default);
79
+ this.balancerBatchRouter = new abi_1.Interface(batch_router_json_1.default);
80
+ }
81
+ // Initialize pricing is called once in the start of
82
+ // pricing service. It is intended to setup the integration
83
+ // for pricing requests. It is optional for a DEX to
84
+ // implement this function
85
+ async initializePricing(blockNumber) {
86
+ await this.eventPools.initialize(blockNumber);
87
+ // This will periodically query API and add any new pools to pool state
88
+ if (!this.updateNewPoolsTimer) {
89
+ this.updateNewPoolsTimer = setInterval(async () => {
90
+ try {
91
+ await this.updatePoolState();
92
+ }
93
+ catch (e) {
94
+ this.logger.error(`${this.dexKey}: Failed to update pool state:`, e);
95
+ }
96
+ }, POOL_UPDATE_TTL * 1000);
97
+ }
98
+ // This will periodically refresh tokenRates with onchain state
99
+ if (!this.updateRatesTimer) {
100
+ this.updateRatesTimer = setInterval(async () => {
101
+ try {
102
+ await this.updateStatePoolRates();
103
+ }
104
+ catch (e) {
105
+ this.logger.error(`${this.dexKey}: Failed to update pool rates:`, e);
106
+ }
107
+ }, RATE_UPDATE_TTL * 1000);
108
+ }
109
+ }
110
+ getAdapters(side) {
111
+ return null;
112
+ }
113
+ // Returns list of pool identifiers that can be used
114
+ // for a given swap. poolIdentifiers must be unique
115
+ // across DEXes. It is recommended to use
116
+ // ${dexKey}_${poolAddress} as a poolIdentifier
117
+ async getPoolIdentifiers(srcToken, destToken, side, blockNumber) {
118
+ const _from = this.dexHelper.config.wrapETH(srcToken);
119
+ const _to = this.dexHelper.config.wrapETH(destToken);
120
+ const poolState = this.eventPools.getState(blockNumber);
121
+ if (poolState === null)
122
+ return [];
123
+ return this.findPoolAddressesWithTokens(poolState, _from.address.toLowerCase(), _to.address.toLowerCase());
124
+ }
125
+ findPoolAddressesWithTokens(pools, tokenA, tokenB) {
126
+ return Object.entries(pools)
127
+ .filter(([, poolState]) => {
128
+ return this.hasTokens(poolState, [tokenA, tokenB]);
129
+ })
130
+ .map(([address]) => address);
131
+ }
132
+ /**
133
+ * Filter pools that have tokens from/to and are in limitPool list
134
+ * @param pools
135
+ * @param from
136
+ * @param to
137
+ * @param limitPools
138
+ * @returns Array of PoolState
139
+ */
140
+ filterPools(pools, from, to, limitPools) {
141
+ return Object.entries(pools)
142
+ .filter(([address, poolState]) => {
143
+ const hasRequiredTokens = this.hasTokens(poolState, [from, to]);
144
+ const isAllowedPool = !limitPools || limitPools.includes(address);
145
+ return hasRequiredTokens && isAllowedPool;
146
+ })
147
+ .map(([_, poolState]) => poolState);
148
+ }
149
+ hasTokens(pool, tokens) {
150
+ return tokens.every(token => pool.tokens.includes(token) || pool.tokensUnderlying.includes(token));
151
+ }
152
+ // Returns pool prices for amounts.
153
+ // If limitPools is defined only pools in limitPools
154
+ // should be used. If limitPools is undefined then
155
+ // any pools can be used.
156
+ async getPricesVolume(srcToken, destToken, amounts, side, blockNumber, limitPools) {
157
+ try {
158
+ const _from = this.dexHelper.config.wrapETH(srcToken);
159
+ const _to = this.dexHelper.config.wrapETH(destToken);
160
+ if (_from.address === _to.address) {
161
+ return null;
162
+ }
163
+ // This is used to get block timestamp which is needed to calculate Amp if it is updating
164
+ const block = await this.dexHelper.provider.getBlock(blockNumber);
165
+ // get up to date pools and state
166
+ const allPoolState = this.eventPools.getState(blockNumber);
167
+ if (allPoolState === null) {
168
+ this.logger.error(`getState returned null`);
169
+ return null;
170
+ }
171
+ // filter for pools with tokens and to only use limit pools
172
+ const allowedPools = this.filterPools(allPoolState, _from.address.toLowerCase(), _to.address.toLowerCase(), limitPools);
173
+ if (!allowedPools.length)
174
+ return null;
175
+ const swapKind = side === constants_1.SwapSide.SELL ? balancer_maths_1.SwapKind.GivenIn : balancer_maths_1.SwapKind.GivenOut;
176
+ const tokenIn = _from.address;
177
+ const tokenOut = _to.address;
178
+ // Gets the single unit amount based off token decimals, e.g. for USDC its 1e6
179
+ const unitAmount = (0, utils_1.getBigIntPow)((side === constants_1.SwapSide.SELL ? _from : _to).decimals);
180
+ const poolPrices = [];
181
+ // For each pool we calculate swap result using balancer maths
182
+ for (let i = 0; i < allowedPools.length; i++) {
183
+ const pool = {
184
+ ...allowedPools[i],
185
+ };
186
+ const tokenInInfo = this.eventPools.getTokenInfo(pool, tokenIn);
187
+ const tokenOutInfo = this.eventPools.getTokenInfo(pool, tokenOut);
188
+ if (!tokenInInfo || !tokenOutInfo) {
189
+ continue;
190
+ }
191
+ const steps = this.eventPools.getSteps(pool, tokenInInfo, tokenOutInfo);
192
+ try {
193
+ // This is the max amount the pool can swap
194
+ const maxSwapAmount = this.eventPools.getMaxSwapAmount(pool, tokenInInfo, tokenOutInfo, swapKind);
195
+ let unit = 0n;
196
+ if (unitAmount < maxSwapAmount)
197
+ unit = this.eventPools.getSwapResult(steps, unitAmount, swapKind, block.timestamp);
198
+ const poolExchangePrice = {
199
+ prices: new Array(amounts.length).fill(0n),
200
+ unit,
201
+ data: {
202
+ steps: steps,
203
+ },
204
+ exchange: this.dexKey,
205
+ gasCost: (0, getGasCost_1.getGasCost)(steps),
206
+ poolAddresses: [pool.poolAddress],
207
+ poolIdentifier: `${this.dexKey}_${pool.poolAddress}`,
208
+ };
209
+ for (let j = 0; j < amounts.length; j++) {
210
+ if (amounts[j] < maxSwapAmount) {
211
+ // Uses balancer maths to calculate swap
212
+ poolExchangePrice.prices[j] = this.eventPools.getSwapResult(steps, amounts[j], swapKind, block.timestamp);
213
+ }
214
+ }
215
+ poolPrices.push(poolExchangePrice);
216
+ }
217
+ catch (err) {
218
+ this.logger.error(`error fetching prices for pool: ${pool.poolAddress}`);
219
+ this.logger.error(err);
220
+ }
221
+ }
222
+ return poolPrices;
223
+ }
224
+ catch (err) { }
225
+ return null;
226
+ }
227
+ // Returns estimated gas cost of calldata for this DEX in multiSwap
228
+ getCalldataGasCost(poolPrices) {
229
+ // TODO: update if there is any payload in getAdapterParam
230
+ return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
231
+ }
232
+ // Not used for V6
233
+ getAdapterParam() {
234
+ return {
235
+ targetExchange: '0x',
236
+ payload: '0x',
237
+ networkFee: '0',
238
+ };
239
+ }
240
+ getDexParam(srcToken, destToken, srcAmount, destAmount, recipient, data, side) {
241
+ if (side === constants_1.SwapSide.SELL) {
242
+ return this.getExactInParam(srcToken, destToken, srcAmount, data);
243
+ }
244
+ else {
245
+ return this.getExactOutParam(srcToken, destToken, srcAmount, destAmount, data);
246
+ }
247
+ }
248
+ getExactInParam(srcToken, destToken, srcAmount, data) {
249
+ if (data.steps.length === 1) {
250
+ const exchangeData = this.balancerRouter.encodeFunctionData('swapSingleTokenExactIn', [
251
+ data.steps[0].pool,
252
+ this.dexHelper.config.wrapETH(srcToken),
253
+ this.dexHelper.config.wrapETH(destToken),
254
+ srcAmount,
255
+ '0', // This should be limit for min amount out. Assume this is set elsewhere via Paraswap contract.
256
+ MAX_UINT256, // Deadline
257
+ (0, utils_1.isETHAddress)(srcToken) || (0, utils_1.isETHAddress)(destToken),
258
+ '0x',
259
+ ]);
260
+ return {
261
+ permit2Approval: true,
262
+ needWrapNative: this.needWrapNative,
263
+ dexFuncHasRecipient: false,
264
+ exchangeData,
265
+ // This router handles single swaps
266
+ targetExchange: config_1.BalancerV3Config.BalancerV3[this.network].balancerRouterAddress,
267
+ returnAmountPos: (0, utils_2.extractReturnAmountPosition)(this.balancerRouter, 'swapSingleTokenExactIn'),
268
+ };
269
+ }
270
+ else {
271
+ // for each step:
272
+ // if tokenIn == pool router uses removeLiquidity SINGLE_TOKEN_EXACT_IN
273
+ // if tokenOut == pool router uses addLiquidity UNBALANCED
274
+ const exchangeData = this.balancerBatchRouter.encodeFunctionData('swapExactIn', [
275
+ [
276
+ {
277
+ tokenIn: srcToken,
278
+ steps: data.steps.map(step => ({
279
+ pool: step.pool,
280
+ tokenOut: step.swapInput.tokenOut,
281
+ isBuffer: step.isBuffer,
282
+ })),
283
+ exactAmountIn: srcAmount,
284
+ minAmountOut: '0', // This should be limit for min amount out. Assume this is set elsewhere via Paraswap contract.
285
+ },
286
+ ],
287
+ MAX_UINT256, // Deadline
288
+ (0, utils_1.isETHAddress)(srcToken) || (0, utils_1.isETHAddress)(destToken),
289
+ '0x',
290
+ ]);
291
+ return {
292
+ permit2Approval: true,
293
+ needWrapNative: this.needWrapNative,
294
+ dexFuncHasRecipient: false,
295
+ exchangeData,
296
+ // This router handles batch swaps
297
+ targetExchange: config_1.BalancerV3Config.BalancerV3[this.network].balancerBatchRouterAddress,
298
+ returnAmountPos: undefined,
299
+ };
300
+ }
301
+ }
302
+ getExactOutParam(srcToken, destToken, srcAmount, destAmount, data) {
303
+ if (data.steps.length === 1) {
304
+ const exchangeData = this.balancerRouter.encodeFunctionData('swapSingleTokenExactOut', [
305
+ data.steps[0].pool,
306
+ this.dexHelper.config.wrapETH(srcToken),
307
+ this.dexHelper.config.wrapETH(destToken),
308
+ destAmount,
309
+ MAX_UINT256, // This should be limit for max amount in. Assume this is set elsewhere via Paraswap contract.
310
+ MAX_UINT256, // Deadline
311
+ (0, utils_1.isETHAddress)(srcToken) || (0, utils_1.isETHAddress)(destToken),
312
+ '0x',
313
+ ]);
314
+ return {
315
+ permit2Approval: true,
316
+ needWrapNative: this.needWrapNative,
317
+ dexFuncHasRecipient: false,
318
+ exchangeData,
319
+ // Single swaps are submitted via Balancer Router
320
+ targetExchange: config_1.BalancerV3Config.BalancerV3[this.network].balancerRouterAddress,
321
+ returnAmountPos: undefined,
322
+ };
323
+ }
324
+ else {
325
+ // for each step:
326
+ // if tokenIn == pool use removeLiquidity SINGLE_TOKEN_EXACT_OUT
327
+ // if tokenOut == pool use addLiquidity SINGLE_TOKEN_EXACT_OUT
328
+ const exchangeData = this.balancerBatchRouter.encodeFunctionData('swapExactOut', [
329
+ [
330
+ {
331
+ tokenIn: srcToken,
332
+ steps: data.steps.map(step => ({
333
+ pool: step.pool,
334
+ tokenOut: step.swapInput.tokenOut,
335
+ isBuffer: step.isBuffer,
336
+ })),
337
+ exactAmountOut: destAmount,
338
+ maxAmountIn: srcAmount,
339
+ },
340
+ ],
341
+ MAX_UINT256, // Deadline
342
+ (0, utils_1.isETHAddress)(srcToken) || (0, utils_1.isETHAddress)(destToken),
343
+ '0x',
344
+ ]);
345
+ return {
346
+ permit2Approval: true,
347
+ needWrapNative: this.needWrapNative,
348
+ dexFuncHasRecipient: false,
349
+ exchangeData,
350
+ // This router handles batch swaps
351
+ targetExchange: config_1.BalancerV3Config.BalancerV3[this.network].balancerBatchRouterAddress,
352
+ returnAmountPos: undefined,
353
+ };
354
+ }
355
+ }
356
+ /**
357
+ * Uses multicall to get onchain token rate for each pool then updates pool state
358
+ */
359
+ async updateStatePoolRates() {
360
+ await this.eventPools.updateStatePoolRates();
361
+ }
362
+ // This is called once before getTopPoolsForToken is
363
+ // called for multiple tokens. This can be helpful to
364
+ // update common state required for calculating
365
+ // getTopPoolsForToken. It is optional for a DEX
366
+ // to implement this
367
+ async updatePoolState() {
368
+ await this.eventPools.updateStatePools();
369
+ }
370
+ // Returns list of top pools based on liquidity. Max
371
+ // limit number pools should be returned.
372
+ async getTopPoolsForToken(tokenAddress, count) {
373
+ const poolsWithToken = Object.entries(this.eventPools.getStaleState() || {})
374
+ .filter(([, poolState]) => {
375
+ return this.hasTokens(poolState, [tokenAddress.toLowerCase()]);
376
+ })
377
+ .map(([address]) => address);
378
+ const topPools = await (0, getTopPoolsApi_1.getTopPoolsApi)(this.network, poolsWithToken, count);
379
+ return topPools.map(pool => {
380
+ const tokens = pool.poolTokens
381
+ .filter(t => t.address !== tokenAddress)
382
+ .map(t => ({
383
+ address: t.address,
384
+ decimals: t.decimals,
385
+ }));
386
+ const underlyingTokens = pool.poolTokens
387
+ .map(t => t.underlyingToken)
388
+ .filter(t => !!t)
389
+ .filter(t => t?.address !== tokenAddress);
390
+ return {
391
+ exchange: this.dexKey,
392
+ address: pool.address,
393
+ liquidityUSD: parseFloat(pool.dynamicData.totalLiquidity),
394
+ connectorTokens: tokens.concat(underlyingTokens),
395
+ };
396
+ });
397
+ }
398
+ releaseResources() {
399
+ if (this.updateNewPoolsTimer) {
400
+ clearInterval(this.updateNewPoolsTimer);
401
+ this.updateNewPoolsTimer = undefined;
402
+ this.logger.info(`${this.dexKey}: cleared updateNewPoolsTimer before shutting down`);
403
+ }
404
+ if (this.updateRatesTimer) {
405
+ clearInterval(this.updateRatesTimer);
406
+ this.updateRatesTimer = undefined;
407
+ this.logger.info(`${this.dexKey}: cleared updateRatesTimer before shutting down`);
408
+ }
409
+ }
410
+ }
411
+ exports.BalancerV3 = BalancerV3;
412
+ //# sourceMappingURL=balancer-v3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"balancer-v3.js","sourceRoot":"","sources":["../../../src/dex/balancer-v3/balancer-v3.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,+CAAoD;AACpD,2EAA6D;AAC7D,uCAAgF;AAIhF,wDAAoD;AACpD,qCAA4C;AAC5C,yDAAyD;AAEzD,kEAAyD;AACzD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,gBAAgB,EAAE,CAAC;YAC1B,aAAa,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;YACrC,IAAI,CAAC,gBAAgB,GAAG,SAAS,CAAC;YAClC,IAAI,CAAC,MAAM,CAAC,IAAI,CACd,GAAG,IAAI,CAAC,MAAM,iDAAiD,CAChE,CAAC;QACJ,CAAC;IACH,CAAC;;AAlfH,gCAmfC"}
@@ -0,0 +1,9 @@
1
+ import { DexParams } from './types';
2
+ import { DexConfigMap } from '../../types';
3
+ export declare enum SUPPORTED_POOLS {
4
+ WEIGHTED = "WEIGHTED",
5
+ STABLE = "STABLE"
6
+ }
7
+ export declare const disabledPoolIds: Record<string, Record<number, string[]>>;
8
+ export declare const apiUrl = "https://test-api-v3.balancer.fi/";
9
+ export declare const BalancerV3Config: DexConfigMap<DexParams>;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BalancerV3Config = exports.apiUrl = exports.disabledPoolIds = exports.SUPPORTED_POOLS = void 0;
4
+ const constants_1 = require("../../constants");
5
+ // These map to the Balancer API poolType. Only Balancer supported pools will be added
6
+ var SUPPORTED_POOLS;
7
+ (function (SUPPORTED_POOLS) {
8
+ SUPPORTED_POOLS["WEIGHTED"] = "WEIGHTED";
9
+ SUPPORTED_POOLS["STABLE"] = "STABLE";
10
+ })(SUPPORTED_POOLS || (exports.SUPPORTED_POOLS = SUPPORTED_POOLS = {}));
11
+ exports.disabledPoolIds = {
12
+ BalancerV3: {
13
+ [constants_1.Network.GNOSIS]: [
14
+ // pools with rate provider that returns nested rate instead of wrap/unwrap rate
15
+ '0x6e6bb18449fcf15b79efa2cfa70acf7593088029',
16
+ '0x272d6be442e30d7c87390edeb9b96f1e84cecd8d',
17
+ ],
18
+ },
19
+ };
20
+ // Balancer API - aggregatorSpecific query serves all useful static pool data
21
+ exports.apiUrl = 'https://test-api-v3.balancer.fi/';
22
+ // TODO Full config added after V3 release
23
+ exports.BalancerV3Config = {
24
+ BalancerV3: {
25
+ [constants_1.Network.SEPOLIA]: {
26
+ vaultAddress: '0xbA1333333333a1BA1108E8412f11850A5C319bA9',
27
+ apiNetworkName: 'SEPOLIA',
28
+ balancerRouterAddress: '0x0BF61f706105EA44694f2e92986bD01C39930280',
29
+ balancerBatchRouterAddress: '0xC85b652685567C1B074e8c0D4389f83a2E458b1C',
30
+ },
31
+ [constants_1.Network.GNOSIS]: {
32
+ vaultAddress: '0xbA1333333333a1BA1108E8412f11850A5C319bA9',
33
+ apiNetworkName: 'GNOSIS',
34
+ balancerRouterAddress: '0x84813aA3e079A665C0B80F944427eE83cBA63617',
35
+ balancerBatchRouterAddress: '0xe2fa4e1d17725e72dcdAfe943Ecf45dF4B9E285b',
36
+ },
37
+ [constants_1.Network.MAINNET]: {
38
+ vaultAddress: '0xbA1333333333a1BA1108E8412f11850A5C319bA9',
39
+ apiNetworkName: 'MAINNET',
40
+ balancerRouterAddress: '0x5C6fb490BDFD3246EB0bB062c168DeCAF4bD9FDd',
41
+ balancerBatchRouterAddress: '0x136f1EFcC3f8f88516B9E94110D56FDBfB1778d1',
42
+ },
43
+ },
44
+ };
45
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/dex/balancer-v3/config.ts"],"names":[],"mappings":";;;AAEA,+CAAoD;AAEpD,sFAAsF;AACtF,IAAY,eAGX;AAHD,WAAY,eAAe;IACzB,wCAAqB,CAAA;IACrB,oCAAiB,CAAA;AACnB,CAAC,EAHW,eAAe,+BAAf,eAAe,QAG1B;AAEY,QAAA,eAAe,GAA6C;IACvE,UAAU,EAAE;QACV,CAAC,mBAAO,CAAC,MAAM,CAAC,EAAE;YAChB,gFAAgF;YAChF,4CAA4C;YAC5C,4CAA4C;SAC7C;KACF;CACF,CAAC;AAEF,6EAA6E;AAChE,QAAA,MAAM,GAAG,kCAAkC,CAAC;AAEzD,0CAA0C;AAC7B,QAAA,gBAAgB,GAA4B;IACvD,UAAU,EAAE;QACV,CAAC,mBAAO,CAAC,OAAO,CAAC,EAAE;YACjB,YAAY,EAAE,4CAA4C;YAC1D,cAAc,EAAE,SAAS;YACzB,qBAAqB,EAAE,4CAA4C;YACnE,0BAA0B,EAAE,4CAA4C;SACzE;QACD,CAAC,mBAAO,CAAC,MAAM,CAAC,EAAE;YAChB,YAAY,EAAE,4CAA4C;YAC1D,cAAc,EAAE,QAAQ;YACxB,qBAAqB,EAAE,4CAA4C;YACnE,0BAA0B,EAAE,4CAA4C;SACzE;QACD,CAAC,mBAAO,CAAC,OAAO,CAAC,EAAE;YACjB,YAAY,EAAE,4CAA4C;YAC1D,cAAc,EAAE,SAAS;YACzB,qBAAqB,EAAE,4CAA4C;YACnE,0BAA0B,EAAE,4CAA4C;SACzE;KACF;CACF,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { Step } from './types';
2
+ export declare function getGasCost(steps: Step[]): number;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getGasCost = getGasCost;
4
+ const stablePool_1 = require("./stablePool");
5
+ const weightedPool_1 = require("./weightedPool");
6
+ // https://sepolia.etherscan.io/tx/0x8c2c5ec7fc2855ed2ffab3467ee434f4e374e0ecf791e8d2b93c8d74e3f5b1fe
7
+ // 0x7ec61d6dcf0ea412327c30f013e60578c0ff4d83c334a95fb3a68739860e6f59
8
+ // 0xb45331fe60091bdf4ba4c201b7fdfefc1ca8087fa1b6bc28877ef84d167809f4
9
+ const FULL_BOOSTED_SWAP_GAS_COST = 283070;
10
+ // 0xb47bcae19ba4693d18f2148073d0d469ff59223e90d6f75eb25e06b0063f1556
11
+ // 0x4730b0c1dce820f14747698446865364b98d96d3ed926e8e74bbead6482b8f8b
12
+ const PARTIAL_BOOSTED_SWAP_GAS_COST = 259815;
13
+ // 0xef9037f992645a9ecf26ddbdf65690a71acbffce2cc68445c869bb9707cb706a
14
+ // 0x77aa06350df079a077147f1051b10e0612542eb3aff3ae1b3d4004341cb64690
15
+ const BUFFER_WRAP_UNWRAP_GAS_COST = 155921;
16
+ function getGasCost(steps) {
17
+ if (steps.length === 2) {
18
+ // Partial boosted/buffer swap:
19
+ // token[wrap]wrappedToken[swap]wrappedToken or
20
+ // wrappedToken[swap]wrappedToken[unwrap]token
21
+ return PARTIAL_BOOSTED_SWAP_GAS_COST;
22
+ }
23
+ else if (steps.length === 3) {
24
+ // Full boosted/buffer swap: token[wrap]wrappedToken[swap]wrappedToken[unwrap]token
25
+ return FULL_BOOSTED_SWAP_GAS_COST;
26
+ }
27
+ else {
28
+ switch (steps[0].poolState.poolType) {
29
+ case 'WEIGHTED':
30
+ return weightedPool_1.WEIGHTED_GAS_COST;
31
+ case 'STABLE':
32
+ return stablePool_1.STABLE_GAS_COST;
33
+ case 'BUFFER':
34
+ return BUFFER_WRAP_UNWRAP_GAS_COST;
35
+ default:
36
+ return weightedPool_1.WEIGHTED_GAS_COST;
37
+ }
38
+ }
39
+ }
40
+ //# sourceMappingURL=getGasCost.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getGasCost.js","sourceRoot":"","sources":["../../../src/dex/balancer-v3/getGasCost.ts"],"names":[],"mappings":";;AAeA,gCAqBC;AApCD,6CAA+C;AAE/C,iDAAmD;AAEnD,qGAAqG;AACrG,qEAAqE;AACrE,qEAAqE;AACrE,MAAM,0BAA0B,GAAG,MAAM,CAAC;AAC1C,qEAAqE;AACrE,qEAAqE;AACrE,MAAM,6BAA6B,GAAG,MAAM,CAAC;AAC7C,qEAAqE;AACrE,qEAAqE;AACrE,MAAM,2BAA2B,GAAG,MAAM,CAAC;AAE3C,SAAgB,UAAU,CAAC,KAAa;IACtC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,+BAA+B;QAC/B,+CAA+C;QAC/C,8CAA8C;QAC9C,OAAO,6BAA6B,CAAC;IACvC,CAAC;SAAM,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC9B,mFAAmF;QACnF,OAAO,0BAA0B,CAAC;IACpC,CAAC;SAAM,CAAC;QACN,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;YACpC,KAAK,UAAU;gBACb,OAAO,gCAAiB,CAAC;YAC3B,KAAK,QAAQ;gBACX,OAAO,4BAAe,CAAC;YACzB,KAAK,QAAQ;gBACX,OAAO,2BAA2B,CAAC;YACrC;gBACE,OAAO,gCAAiB,CAAC;QAC7B,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { ImmutablePoolStateMap, PoolStateMap } from './types';
2
+ import { Interface, Result } from '@ethersproject/abi';
3
+ import { IDexHelper } from '../../dex-helper';
4
+ export declare function decodeThrowError(contractInterface: Interface, functionName: string, resultEntry: {
5
+ success: boolean;
6
+ returnData: any;
7
+ }, poolAddress: string): Result;
8
+ export declare function getOnChainState(network: number, immutablePoolStateMap: ImmutablePoolStateMap, dexHelper: IDexHelper, interfaces: {
9
+ [name: string]: Interface;
10
+ }, blockNumber?: number): Promise<PoolStateMap>;