@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,326 @@
1
+ import _ from 'lodash';
2
+ import {
3
+ ImmutablePoolStateMap,
4
+ CommonMutableState,
5
+ PoolStateMap,
6
+ StableMutableState,
7
+ } from './types';
8
+ import { BalancerV3Config } from './config';
9
+ import { Interface, Result } from '@ethersproject/abi';
10
+ import { IDexHelper } from '../../dex-helper';
11
+
12
+ interface callData {
13
+ target: string;
14
+ callData: string;
15
+ }
16
+
17
+ // Encoding & Decoding for onchain calls to fetch mutable pool data
18
+ // Each supported pool type should have its own specific calls if needed
19
+ const poolOnChain: Record<
20
+ string,
21
+ {
22
+ count: number;
23
+ encode: (
24
+ network: number,
25
+ contractInterface: Interface,
26
+ address: string,
27
+ ) => callData[];
28
+ decode: (
29
+ contractInterface: Interface,
30
+ poolAddress: string,
31
+ data: any,
32
+ startIndex: number,
33
+ ) => {} | CommonMutableState | StableMutableState;
34
+ }
35
+ > = {
36
+ ['COMMON']: {
37
+ count: 6,
38
+ ['encode']: (
39
+ network: number,
40
+ contractInterface: Interface,
41
+ address: string,
42
+ ): callData[] => {
43
+ return [
44
+ {
45
+ target: BalancerV3Config.BalancerV3[network].vaultAddress,
46
+ callData: contractInterface.encodeFunctionData('getPoolTokenRates', [
47
+ address,
48
+ ]),
49
+ },
50
+ {
51
+ target: BalancerV3Config.BalancerV3[network].vaultAddress,
52
+ callData: contractInterface.encodeFunctionData(
53
+ 'getCurrentLiveBalances',
54
+ [address],
55
+ ),
56
+ },
57
+ {
58
+ target: BalancerV3Config.BalancerV3[network].vaultAddress,
59
+ callData: contractInterface.encodeFunctionData('getPoolConfig', [
60
+ address,
61
+ ]),
62
+ },
63
+ {
64
+ target: BalancerV3Config.BalancerV3[network].vaultAddress,
65
+ callData: contractInterface.encodeFunctionData('totalSupply', [
66
+ address,
67
+ ]),
68
+ },
69
+ {
70
+ target: BalancerV3Config.BalancerV3[network].vaultAddress,
71
+ callData: contractInterface.encodeFunctionData('isPoolPaused', [
72
+ address,
73
+ ]),
74
+ },
75
+ {
76
+ target: BalancerV3Config.BalancerV3[network].vaultAddress,
77
+ callData: contractInterface.encodeFunctionData('getHooksConfig', [
78
+ address,
79
+ ]),
80
+ },
81
+ ];
82
+ },
83
+ ['decode']: (
84
+ contractInterface: Interface,
85
+ poolAddress: string,
86
+ data: any,
87
+ startIndex: number,
88
+ ): CommonMutableState => {
89
+ const resultTokenRates = decodeThrowError(
90
+ contractInterface,
91
+ 'getPoolTokenRates',
92
+ data[startIndex++],
93
+ poolAddress,
94
+ );
95
+ if (!resultTokenRates)
96
+ throw new Error(
97
+ `Failed to get result for getPoolTokenRates for ${poolAddress}`,
98
+ );
99
+ const resultLiveBalances = decodeThrowError(
100
+ contractInterface,
101
+ 'getCurrentLiveBalances',
102
+ data[startIndex++],
103
+ poolAddress,
104
+ );
105
+ if (!resultLiveBalances)
106
+ throw new Error(
107
+ `Failed to get result for getCurrentLiveBalances for ${poolAddress}`,
108
+ );
109
+ const resultGetPoolConfig = decodeThrowError(
110
+ contractInterface,
111
+ 'getPoolConfig',
112
+ data[startIndex++],
113
+ poolAddress,
114
+ );
115
+ if (!resultGetPoolConfig)
116
+ throw new Error(
117
+ `Failed to get result for getPoolConfig for ${poolAddress}`,
118
+ );
119
+ const resultTotalSupply = decodeThrowError(
120
+ contractInterface,
121
+ 'totalSupply',
122
+ data[startIndex++],
123
+ poolAddress,
124
+ );
125
+ if (!resultTotalSupply)
126
+ throw new Error(
127
+ `Failed to get result for totalSupply for ${poolAddress}`,
128
+ );
129
+ const resultIsPoolPaused = decodeThrowError(
130
+ contractInterface,
131
+ 'isPoolPaused',
132
+ data[startIndex++],
133
+ poolAddress,
134
+ );
135
+ if (!resultIsPoolPaused)
136
+ throw new Error(
137
+ `Failed to get result for isPoolPaused for ${poolAddress}`,
138
+ );
139
+ const resultHooksConfig = decodeThrowError(
140
+ contractInterface,
141
+ 'getHooksConfig',
142
+ data[startIndex++],
143
+ poolAddress,
144
+ );
145
+ if (!resultHooksConfig)
146
+ throw new Error(
147
+ `Failed to get result for resultHooksConfig for ${poolAddress}`,
148
+ );
149
+ return {
150
+ tokenRates: resultTokenRates.tokenRates.map((r: string) => BigInt(r)),
151
+ balancesLiveScaled18: resultLiveBalances.balancesLiveScaled18.map(
152
+ (b: string) => BigInt(b),
153
+ ),
154
+ swapFee: BigInt(resultGetPoolConfig[0].staticSwapFeePercentage),
155
+ aggregateSwapFee: BigInt(
156
+ resultGetPoolConfig[0].aggregateSwapFeePercentage,
157
+ ),
158
+ totalSupply: BigInt(resultTotalSupply[0]),
159
+ scalingFactors: resultTokenRates.decimalScalingFactors.map(
160
+ (r: string) => BigInt(r),
161
+ ),
162
+ isPoolPaused: resultIsPoolPaused[0],
163
+ hasHook:
164
+ resultHooksConfig[0].hooksContract !==
165
+ '0x0000000000000000000000000000000000000000',
166
+ };
167
+ },
168
+ },
169
+ ['WEIGHTED']: {
170
+ count: 0,
171
+ ['encode']: (
172
+ network: number,
173
+ contractInterface: Interface,
174
+ address: string,
175
+ ): callData[] => {
176
+ return [];
177
+ },
178
+ ['decode']: (
179
+ contractInterface: Interface,
180
+ poolAddress: string,
181
+ data: any,
182
+ startIndex: number,
183
+ ) => {
184
+ return {};
185
+ },
186
+ },
187
+ ['STABLE']: {
188
+ count: 2,
189
+ ['encode']: (
190
+ network: number,
191
+ contractInterface: Interface,
192
+ address: string,
193
+ ): callData[] => {
194
+ return [
195
+ {
196
+ target: address,
197
+ callData: contractInterface.encodeFunctionData(
198
+ 'getAmplificationParameter',
199
+ ),
200
+ },
201
+ {
202
+ target: address,
203
+ callData: contractInterface.encodeFunctionData(
204
+ 'getAmplificationState',
205
+ ),
206
+ },
207
+ ];
208
+ },
209
+ ['decode']: (
210
+ contractInterface: Interface,
211
+ poolAddress: string,
212
+ data: any,
213
+ startIndex: number,
214
+ ): StableMutableState => {
215
+ const resultAmp = decodeThrowError(
216
+ contractInterface,
217
+ 'getAmplificationParameter',
218
+ data[startIndex++],
219
+ poolAddress,
220
+ );
221
+ if (!resultAmp)
222
+ throw new Error(
223
+ `Failed to get result for getAmplificationParameter for ${poolAddress}`,
224
+ );
225
+ const resultAmpState = decodeThrowError(
226
+ contractInterface,
227
+ 'getAmplificationState',
228
+ data[startIndex++],
229
+ poolAddress,
230
+ );
231
+ if (!resultAmpState)
232
+ throw new Error(
233
+ `Failed to get result for getAmplificationState for ${poolAddress}`,
234
+ );
235
+
236
+ return {
237
+ amp: resultAmp[0].toBigInt(),
238
+ ampIsUpdating: !!resultAmp[1],
239
+ ampStartValue: resultAmpState[0][0].toBigInt(),
240
+ ampEndValue: resultAmpState[0][1].toBigInt(),
241
+ ampStartTime: BigInt(resultAmpState[0][2]),
242
+ ampStopTime: BigInt(resultAmpState[0][3]),
243
+ };
244
+ },
245
+ },
246
+ };
247
+
248
+ export function decodeThrowError(
249
+ contractInterface: Interface,
250
+ functionName: string,
251
+ resultEntry: { success: boolean; returnData: any },
252
+ poolAddress: string,
253
+ ): Result {
254
+ if (!resultEntry.success)
255
+ throw new Error(`Failed to execute ${functionName} for ${poolAddress}`);
256
+ return contractInterface.decodeFunctionResult(
257
+ functionName,
258
+ resultEntry.returnData,
259
+ );
260
+ }
261
+
262
+ // Any data from API will be immutable. Mutable data such as balances, etc will be fetched via onchain/event state.
263
+ export async function getOnChainState(
264
+ network: number,
265
+ immutablePoolStateMap: ImmutablePoolStateMap,
266
+ dexHelper: IDexHelper,
267
+ interfaces: {
268
+ [name: string]: Interface;
269
+ },
270
+ blockNumber?: number,
271
+ ): Promise<PoolStateMap> {
272
+ const multiCallData = Object.entries(immutablePoolStateMap)
273
+ .map(([address, pool]) => {
274
+ return [
275
+ ...poolOnChain['COMMON'].encode(network, interfaces['VAULT'], address),
276
+ ...poolOnChain[pool.poolType].encode(
277
+ network,
278
+ interfaces[pool.poolType],
279
+ address,
280
+ ),
281
+ ];
282
+ })
283
+ .flat();
284
+
285
+ // 500 is an arbitrary number chosen based on the blockGasLimit
286
+ const slicedMultiCallData = _.chunk(multiCallData, 500);
287
+
288
+ const multicallData = (
289
+ await Promise.all(
290
+ slicedMultiCallData.map(async _multiCallData =>
291
+ dexHelper.multiContract.methods
292
+ .tryAggregate(false, _multiCallData)
293
+ .call({}, blockNumber),
294
+ ),
295
+ )
296
+ ).flat();
297
+
298
+ let i = 0;
299
+ const poolStateMap = Object.fromEntries(
300
+ Object.entries(immutablePoolStateMap).map(([address, pool]) => {
301
+ const commonMutableData = poolOnChain['COMMON'].decode(
302
+ interfaces['VAULT'],
303
+ address,
304
+ multicallData,
305
+ i,
306
+ ) as CommonMutableState;
307
+ i = i + poolOnChain['COMMON'].count;
308
+ const poolMutableData = poolOnChain[pool.poolType].decode(
309
+ interfaces[pool.poolType],
310
+ address,
311
+ multicallData,
312
+ i,
313
+ );
314
+ i = i + poolOnChain[pool.poolType].count;
315
+ return [
316
+ address,
317
+ {
318
+ ...pool,
319
+ ...commonMutableData,
320
+ ...poolMutableData,
321
+ },
322
+ ];
323
+ }),
324
+ );
325
+ return poolStateMap;
326
+ }
@@ -0,0 +1,129 @@
1
+ import axios from 'axios';
2
+ import {
3
+ apiUrl,
4
+ BalancerV3Config,
5
+ disabledPoolIds,
6
+ SUPPORTED_POOLS,
7
+ } from './config';
8
+ import { CommonImmutablePoolState, ImmutablePoolStateMap } from './types';
9
+ import { parseUnits } from 'ethers/lib/utils';
10
+
11
+ interface PoolToken {
12
+ address: string;
13
+ weight: string | null;
14
+ isErc4626: boolean;
15
+ underlyingToken: {
16
+ address: string;
17
+ } | null;
18
+ }
19
+
20
+ interface Pool {
21
+ id: string;
22
+ type: string;
23
+ poolTokens: PoolToken[];
24
+ }
25
+
26
+ interface QueryResponse {
27
+ data: {
28
+ poolGetAggregatorPools: Pool[];
29
+ };
30
+ }
31
+
32
+ function createQuery(
33
+ networkId: number,
34
+ poolTypes: SUPPORTED_POOLS[],
35
+ timestamp?: number,
36
+ ): string {
37
+ const poolTypesString = poolTypes.map(type => `${type}`).join(', ');
38
+ const networkString = BalancerV3Config.BalancerV3[networkId].apiNetworkName;
39
+ const disabledPoolIdsString = disabledPoolIds.BalancerV3[networkId]
40
+ ?.map(p => `"${p}"`)
41
+ .join(', ');
42
+
43
+ // Build the where clause conditionally
44
+ const whereClause = {
45
+ chainIn: networkString,
46
+ protocolVersionIn: 3,
47
+ hasHook: false,
48
+ poolTypeIn: `[${poolTypesString}]`,
49
+ ...(timestamp && { createTime: `{lt: ${timestamp}}` }),
50
+ ...(disabledPoolIdsString && { idNotIn: `[${disabledPoolIdsString}]` }),
51
+ };
52
+
53
+ // Convert where clause to string, filtering out undefined values
54
+ const whereString = Object.entries(whereClause)
55
+ .map(([key, value]) => `${key}: ${value}`)
56
+ .join(', ');
57
+ return `
58
+ query MyQuery {
59
+ poolGetAggregatorPools(
60
+ where: {${whereString}}
61
+ ) {
62
+ id
63
+ type
64
+ poolTokens {
65
+ address
66
+ weight
67
+ isErc4626
68
+ underlyingToken {
69
+ address
70
+ }
71
+ }
72
+ }
73
+ }
74
+ `;
75
+ }
76
+
77
+ function toImmutablePoolStateMap(pools: Pool[]): ImmutablePoolStateMap {
78
+ return pools.reduce((map, pool) => {
79
+ const immutablePoolState: CommonImmutablePoolState = {
80
+ poolAddress: pool.id,
81
+ tokens: pool.poolTokens.map(t => t.address),
82
+ tokensUnderlying: pool.poolTokens.map(t =>
83
+ t.underlyingToken ? t.underlyingToken.address : null,
84
+ ),
85
+ weights: pool.poolTokens.map(t =>
86
+ t.weight ? parseUnits(t.weight, 18).toBigInt() : 0n,
87
+ ),
88
+ poolType: pool.type,
89
+ // TODO add scalingFactors once API provides them
90
+ // scalingFactors: pool.poolTokens.map(t => parseUnits('1', 18).toBigInt()),
91
+ // TODO Hook support will be added in future PR
92
+ hookType: undefined,
93
+ };
94
+
95
+ map[pool.id] = immutablePoolState;
96
+ return map;
97
+ }, {} as ImmutablePoolStateMap);
98
+ }
99
+
100
+ // Any data from API will be immutable. Mutable data such as balances, etc will be fetched via onchain/event state.
101
+ export async function getPoolsApi(
102
+ network: number,
103
+ timestamp?: number,
104
+ ): Promise<ImmutablePoolStateMap> {
105
+ try {
106
+ const query = createQuery(
107
+ network,
108
+ Object.values(SUPPORTED_POOLS),
109
+ timestamp,
110
+ );
111
+ const response = await axios.post<QueryResponse>(
112
+ apiUrl,
113
+ {
114
+ query,
115
+ },
116
+ {
117
+ headers: {
118
+ 'Content-Type': 'application/json',
119
+ },
120
+ },
121
+ );
122
+
123
+ const pools = response.data.data.poolGetAggregatorPools;
124
+ return toImmutablePoolStateMap(pools);
125
+ } catch (error) {
126
+ // console.error('Error executing GraphQL query:', error);
127
+ throw error;
128
+ }
129
+ }
@@ -0,0 +1,96 @@
1
+ import axios from 'axios';
2
+ import { apiUrl, BalancerV3Config } from './config';
3
+
4
+ interface PoolToken {
5
+ address: string;
6
+ decimals: number;
7
+ underlyingToken?: {
8
+ address: string;
9
+ decimals: number;
10
+ };
11
+ }
12
+
13
+ export interface Pool {
14
+ address: string;
15
+ poolTokens: PoolToken[];
16
+ dynamicData: {
17
+ totalLiquidity: string;
18
+ };
19
+ }
20
+
21
+ interface QueryResponse {
22
+ data: {
23
+ poolGetAggregatorPools: Pool[];
24
+ };
25
+ }
26
+
27
+ function createQuery(
28
+ networkId: number,
29
+ poolsFilter: string[],
30
+ count: number,
31
+ ): string {
32
+ const networkString = BalancerV3Config.BalancerV3[networkId].apiNetworkName;
33
+ const poolIdString = poolsFilter.map(a => `"${a}"`).join(', ');
34
+ // Build the where clause conditionally
35
+ const whereClause = {
36
+ chainIn: networkString,
37
+ protocolVersionIn: 3,
38
+ hasHook: false,
39
+ idIn: `[${poolIdString}]`,
40
+ };
41
+
42
+ // Convert where clause to string, filtering out undefined values
43
+ const whereString = Object.entries(whereClause)
44
+ .map(([key, value]) => `${key}: ${value}`)
45
+ .join(', ');
46
+ return `
47
+ query MyQuery {
48
+ poolGetAggregatorPools(
49
+ where: {${whereString}}
50
+ first: ${count}
51
+ orderBy: totalLiquidity
52
+ orderDirection: desc
53
+ ) {
54
+ address
55
+ poolTokens {
56
+ address
57
+ decimals
58
+ underlyingToken {
59
+ address
60
+ decimals
61
+ }
62
+ }
63
+ dynamicData {
64
+ totalLiquidity
65
+ }
66
+ }
67
+ }
68
+ `;
69
+ }
70
+
71
+ export async function getTopPoolsApi(
72
+ networkId: number,
73
+ poolsFilter: string[],
74
+ count: number,
75
+ ): Promise<Pool[]> {
76
+ try {
77
+ const query = createQuery(networkId, poolsFilter, count);
78
+ const response = await axios.post<QueryResponse>(
79
+ apiUrl,
80
+ {
81
+ query,
82
+ },
83
+ {
84
+ headers: {
85
+ 'Content-Type': 'application/json',
86
+ },
87
+ },
88
+ );
89
+
90
+ const pools = response.data.data.poolGetAggregatorPools;
91
+ return pools;
92
+ } catch (error) {
93
+ // console.error('Error executing GraphQL query:', error);
94
+ throw error;
95
+ }
96
+ }
@@ -0,0 +1,66 @@
1
+ import { UnoptimizedRate, OptimalSwap } from '../../types';
2
+ import _ from 'lodash';
3
+
4
+ export function balancerV3Merge(or: UnoptimizedRate): UnoptimizedRate {
5
+ const fixRoute = (rawRate: OptimalSwap[]): OptimalSwap[] => {
6
+ let lastExchange: false | OptimalSwap = false;
7
+
8
+ let optimizedRate = new Array<OptimalSwap>();
9
+
10
+ rawRate.forEach((s: OptimalSwap) => {
11
+ if (
12
+ s.swapExchanges.length !== 1 ||
13
+ s.swapExchanges[0].exchange.toLowerCase() !== 'balancerv3'
14
+ ) {
15
+ lastExchange = false;
16
+ optimizedRate.push(s);
17
+ return;
18
+ }
19
+
20
+ if (
21
+ lastExchange &&
22
+ lastExchange.swapExchanges[0].exchange.toLowerCase() ===
23
+ s.swapExchanges[0].exchange.toLowerCase() &&
24
+ _.last(
25
+ <any[]>lastExchange.swapExchanges[0].data.steps,
26
+ )!.swapInput.tokenOut.toLowerCase() ===
27
+ s.swapExchanges[0].data.steps[0].swapInput.tokenIn.toLowerCase()
28
+ ) {
29
+ lastExchange.swapExchanges[0].data.steps =
30
+ lastExchange.swapExchanges[0].data.steps.concat(
31
+ s.swapExchanges[0].data.steps,
32
+ );
33
+
34
+ lastExchange.swapExchanges[0].poolAddresses =
35
+ lastExchange.swapExchanges[0].poolAddresses!.concat(
36
+ s.swapExchanges[0].poolAddresses!,
37
+ );
38
+
39
+ lastExchange.swapExchanges[0].data.gasUSD = (
40
+ parseFloat(lastExchange.swapExchanges[0].data.gasUSD) +
41
+ parseFloat(s.swapExchanges[0].data.gasUSD)
42
+ ).toFixed(6);
43
+
44
+ lastExchange.destToken = s.destToken;
45
+ lastExchange.destDecimals = s.destDecimals;
46
+
47
+ lastExchange.swapExchanges[0].destAmount =
48
+ s.swapExchanges[0].destAmount;
49
+
50
+ return;
51
+ }
52
+
53
+ lastExchange = _.cloneDeep(s);
54
+ optimizedRate.push(lastExchange);
55
+ });
56
+
57
+ return optimizedRate;
58
+ };
59
+
60
+ or.bestRoute = or.bestRoute.map(r => ({
61
+ ...r,
62
+ swaps: fixRoute(r.swaps),
63
+ }));
64
+
65
+ return or;
66
+ }
@@ -0,0 +1,78 @@
1
+ import { defaultAbiCoder } from '@ethersproject/abi';
2
+ import { PoolState } from '@balancer-labs/balancer-maths';
3
+ import { StableMutableState } from './types';
4
+
5
+ // TODO - Update with more accurate
6
+ export const STABLE_GAS_COST = 155000;
7
+
8
+ export function isStableMutableState(
9
+ poolState: any,
10
+ ): poolState is StableMutableState {
11
+ return (
12
+ poolState &&
13
+ typeof poolState === 'object' &&
14
+ 'amp' in poolState &&
15
+ 'ampIsUpdating' in poolState &&
16
+ 'ampStartValue' in poolState &&
17
+ 'ampEndValue' in poolState &&
18
+ 'ampStartTime' in poolState &&
19
+ 'ampStopTime' in poolState
20
+ );
21
+ }
22
+
23
+ // https://github.com/balancer/balancer-v3-monorepo/blob/009f2793abda248b150ccd15c1db25930c96ca82/pkg/pool-stable/contracts/StablePool.sol#L274
24
+ export function getAmplificationParameter(
25
+ startValue: bigint,
26
+ endValue: bigint,
27
+ startTime: bigint,
28
+ endTime: bigint,
29
+ timestamp: bigint,
30
+ ): bigint {
31
+ let value: bigint;
32
+ if (timestamp < endTime) {
33
+ if (endValue > startValue) {
34
+ value =
35
+ startValue +
36
+ ((endValue - startValue) * (timestamp - startTime)) /
37
+ (endTime - startTime);
38
+ } else {
39
+ value =
40
+ startValue -
41
+ ((startValue - endValue) * (timestamp - startTime)) /
42
+ (endTime - startTime);
43
+ }
44
+ } else {
45
+ value = endValue;
46
+ }
47
+ return value;
48
+ }
49
+
50
+ export function ampUpdateStartedEvent(poolState: PoolState, eventData: any) {
51
+ // abi.encode(currentValueUint64, endValueUint64, startTimeUint32, endTimeUint32)
52
+ const decodedParams = defaultAbiCoder.decode(
53
+ ['uint64', 'uint64', 'uint32', 'uint32'],
54
+ eventData,
55
+ );
56
+ if (isStableMutableState(poolState)) {
57
+ if (decodedParams[3] > decodedParams[2]) poolState.ampIsUpdating = true;
58
+ poolState.ampStartValue = decodedParams[0].toBigInt();
59
+ poolState.ampEndValue = decodedParams[1].toBigInt();
60
+ poolState.ampStartTime = BigInt(decodedParams[2]);
61
+ poolState.ampStopTime = BigInt(decodedParams[3]);
62
+ } else throw new Error("Can't update amp on non-stable pool");
63
+ }
64
+
65
+ export function ampUpdateStoppedEvent(poolState: PoolState, eventData: any) {
66
+ // abi.encode(currentValue)
67
+ const decodedParams = defaultAbiCoder.decode(['uint256'], eventData);
68
+ if (isStableMutableState(poolState)) {
69
+ poolState.ampIsUpdating = false;
70
+ poolState.amp = decodedParams[0].toBigInt();
71
+ poolState.ampStartValue = decodedParams[0].toBigInt();
72
+ poolState.ampEndValue = decodedParams[0].toBigInt();
73
+ // In Contract these are update to timestamp event is called.
74
+ // There doesn't appear to be a way to easily get timestamp non-async so default to 0n which should have no effect
75
+ poolState.ampStartTime = BigInt(0n);
76
+ poolState.ampStopTime = BigInt(0n);
77
+ } else throw new Error("Can't update amp on non-stable pool");
78
+ }