@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.
- package/.vscode/launch.json +53 -0
- package/.vscode/settings.json +2 -0
- package/.vscode/tasks.json +15 -0
- package/build/abi/balancer-v3/batch-router.json +989 -0
- package/build/abi/balancer-v3/router.json +1792 -0
- package/build/abi/balancer-v3/vault-extension.json +2834 -0
- package/build/abi/permit2.json +581 -0
- package/build/abi/uniswap-v3/AlienBaseV3Router.abi.json +52 -0
- package/build/abi/usual-m-smart-m/usualM.abi.json +483 -0
- package/build/abi/usual-m-usd0/usualCollateralDao.abi.json +681 -0
- package/build/abi/{angle-transmuter/ChainlinkAccessControlledOffchainAggregator.json → wombat/pool.json} +637 -594
- package/build/bigint-constants.d.ts +1 -0
- package/build/bigint-constants.js +2 -1
- package/build/bigint-constants.js.map +1 -1
- package/build/config.js +28 -0
- package/build/config.js.map +1 -1
- package/build/constants.d.ts +2 -0
- package/build/constants.js +4 -1
- package/build/constants.js.map +1 -1
- package/build/dex/aave-v1/aave-v1.js +1 -0
- package/build/dex/aave-v1/aave-v1.js.map +1 -1
- package/build/dex/aave-v2/tokens-avalanche.json +44 -0
- package/build/dex/aave-v2/tokens-mainnet.json +188 -0
- package/build/dex/aave-v2/tokens-polygon.json +44 -0
- package/build/dex/augustus-approvals.d.ts +3 -2
- package/build/dex/augustus-approvals.js +35 -16
- package/build/dex/augustus-approvals.js.map +1 -1
- package/build/dex/bProtocol.d.ts +18 -0
- package/build/dex/bProtocol.js +39 -0
- package/build/dex/bProtocol.js.map +1 -0
- package/build/dex/balancer-v3/abi/balancerBatchRouter.d.ts +729 -0
- package/build/dex/balancer-v3/abi/balancerBatchRouter.js +732 -0
- package/build/dex/balancer-v3/abi/balancerBatchRouter.js.map +1 -0
- package/build/dex/balancer-v3/abi/balancerRouter.d.ts +1406 -0
- package/build/dex/balancer-v3/abi/balancerRouter.js +1175 -0
- package/build/dex/balancer-v3/abi/balancerRouter.js.map +1 -0
- package/build/dex/balancer-v3/abi/vaultExtension.V3.d.ts +2081 -0
- package/build/dex/balancer-v3/abi/vaultExtension.V3.js +1851 -0
- package/build/dex/balancer-v3/abi/vaultExtension.V3.js.map +1 -0
- package/build/dex/balancer-v3/balancer-v3-pool.d.ts +80 -0
- package/build/dex/balancer-v3/balancer-v3-pool.js +469 -0
- package/build/dex/balancer-v3/balancer-v3-pool.js.map +1 -0
- package/build/dex/balancer-v3/balancer-v3-sepolia-pools.d.ts +34 -0
- package/build/dex/balancer-v3/balancer-v3-sepolia-pools.js +406 -0
- package/build/dex/balancer-v3/balancer-v3-sepolia-pools.js.map +1 -0
- package/build/dex/balancer-v3/balancer-v3.d.ts +56 -0
- package/build/dex/balancer-v3/balancer-v3.js +412 -0
- package/build/dex/balancer-v3/balancer-v3.js.map +1 -0
- package/build/dex/balancer-v3/config.d.ts +9 -0
- package/build/dex/balancer-v3/config.js +45 -0
- package/build/dex/balancer-v3/config.js.map +1 -0
- package/build/dex/balancer-v3/getGasCost.d.ts +2 -0
- package/build/dex/balancer-v3/getGasCost.js +40 -0
- package/build/dex/balancer-v3/getGasCost.js.map +1 -0
- package/build/dex/balancer-v3/getOnChainState.d.ts +10 -0
- package/build/dex/balancer-v3/getOnChainState.js +163 -0
- package/build/dex/balancer-v3/getOnChainState.js.map +1 -0
- package/build/dex/balancer-v3/getPoolsApi.d.ts +2 -0
- package/build/dex/balancer-v3/getPoolsApi.js +84 -0
- package/build/dex/balancer-v3/getPoolsApi.js.map +1 -0
- package/build/dex/balancer-v3/getTopPoolsApi.d.ts +17 -0
- package/build/dex/balancer-v3/getTopPoolsApi.js +65 -0
- package/build/dex/balancer-v3/getTopPoolsApi.js.map +1 -0
- package/build/dex/balancer-v3/optimizer.d.ts +2 -0
- package/build/dex/balancer-v3/optimizer.js +47 -0
- package/build/dex/balancer-v3/optimizer.js.map +1 -0
- package/build/dex/balancer-v3/stablePool.d.ts +7 -0
- package/build/dex/balancer-v3/stablePool.js +73 -0
- package/build/dex/balancer-v3/stablePool.js.map +1 -0
- package/build/dex/balancer-v3/types.d.ts +62 -0
- package/build/dex/balancer-v3/types.js +3 -0
- package/build/dex/balancer-v3/types.js.map +1 -0
- package/build/dex/balancer-v3/weightedPool.d.ts +1 -0
- package/build/dex/balancer-v3/weightedPool.js +6 -0
- package/build/dex/balancer-v3/weightedPool.js.map +1 -0
- package/build/dex/bancor.d.ts +26 -0
- package/build/dex/bancor.js +58 -0
- package/build/dex/bancor.js.map +1 -0
- package/build/dex/cables/cables.d.ts +7 -5
- package/build/dex/cables/cables.js +229 -86
- package/build/dex/cables/cables.js.map +1 -1
- package/build/dex/cables/constants.d.ts +13 -12
- package/build/dex/cables/constants.js +14 -16
- package/build/dex/cables/constants.js.map +1 -1
- package/build/dex/cables/types.d.ts +7 -0
- package/build/dex/cables/types.js +8 -1
- package/build/dex/cables/types.js.map +1 -1
- package/build/dex/compound.d.ts +18 -0
- package/build/dex/compound.js +46 -0
- package/build/dex/compound.js.map +1 -0
- package/build/dex/curve-v2.d.ts +58 -0
- package/build/dex/curve-v2.js +180 -0
- package/build/dex/curve-v2.js.map +1 -0
- package/build/dex/dodo-v1.d.ts +33 -0
- package/build/dex/dodo-v1.js +63 -0
- package/build/dex/dodo-v1.js.map +1 -0
- package/build/dex/fluid-dex/fluid-dex-pool.d.ts +47 -0
- package/build/dex/fluid-dex/fluid-dex-pool.js +119 -0
- package/build/dex/fluid-dex/fluid-dex-pool.js.map +1 -0
- package/build/dex/inception/inception-event-pool.d.ts +4 -4
- package/build/dex/inception/inception-event-pool.js +7 -9
- package/build/dex/inception/inception-event-pool.js.map +1 -1
- package/build/dex/inception/inception.d.ts +6 -6
- package/build/dex/inception/inception.js +16 -40
- package/build/dex/inception/inception.js.map +1 -1
- package/build/dex/inception/utils.d.ts +1 -0
- package/build/dex/inception/utils.js +22 -1
- package/build/dex/inception/utils.js.map +1 -1
- package/build/dex/index.js +4 -0
- package/build/dex/index.js.map +1 -1
- package/build/dex/lido.d.ts +19 -0
- package/build/dex/lido.js +42 -0
- package/build/dex/lido.js.map +1 -0
- package/build/dex/maker-psm/scripts/gem.abi.json +136 -0
- package/build/dex/maker-psm/scripts/validate-state.d.ts +0 -0
- package/build/dex/maker-psm/scripts/validate-state.js +185 -0
- package/build/dex/maker-psm/scripts/validate-state.js.map +1 -0
- package/build/dex/maker-psm/scripts/vat.abi.json +243 -0
- package/build/dex/onebit.d.ts +25 -0
- package/build/dex/onebit.js +42 -0
- package/build/dex/onebit.js.map +1 -0
- package/build/dex/platypus/platypus.js +17 -3
- package/build/dex/platypus/platypus.js.map +1 -1
- package/build/dex/smoothy.d.ts +26 -0
- package/build/dex/smoothy.js +48 -0
- package/build/dex/smoothy.js.map +1 -0
- package/build/dex/solidly-v3/scripts/check-event-pool-event.d.ts +1 -0
- package/build/dex/solidly-v3/scripts/check-event-pool-event.js +53 -0
- package/build/dex/solidly-v3/scripts/check-event-pool-event.js.map +1 -0
- package/build/dex/stable-pool.d.ts +28 -0
- package/build/dex/stable-pool.js +55 -0
- package/build/dex/stable-pool.js.map +1 -0
- package/build/dex/swaap-v1/swaap-v1.js +4 -0
- package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
- package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.d.ts +7 -0
- package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.js +20 -0
- package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.js.map +1 -0
- package/build/dex/trader-joe-v2.1.d.ts +43 -0
- package/build/dex/trader-joe-v2.1.js +79 -0
- package/build/dex/trader-joe-v2.1.js.map +1 -0
- package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.d.ts +17 -0
- package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js +64 -0
- package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js.map +1 -0
- package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.d.ts +17 -0
- package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js +79 -0
- package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js.map +1 -0
- package/build/dex/uniswap-v3/uniswap-v3-pricing.d.ts +4 -0
- package/build/dex/uniswap-v3/uniswap-v3-pricing.js +43 -0
- package/build/dex/uniswap-v3/uniswap-v3-pricing.js.map +1 -0
- package/build/dex/uniswap-v3/uniswap-v3-worker.d.ts +1 -0
- package/build/dex/uniswap-v3/uniswap-v3-worker.js +10 -0
- package/build/dex/uniswap-v3/uniswap-v3-worker.js.map +1 -0
- package/build/dex/usual/types.d.ts +13 -0
- package/build/dex/usual/types.js +3 -0
- package/build/dex/usual/types.js.map +1 -0
- package/build/dex/usual/usual-bond.d.ts +18 -0
- package/build/dex/usual/usual-bond.js +52 -0
- package/build/dex/usual/usual-bond.js.map +1 -0
- package/build/dex/usual/usual-m-smart-m.d.ts +17 -0
- package/build/dex/usual/usual-m-smart-m.js +50 -0
- package/build/dex/usual/usual-m-smart-m.js.map +1 -0
- package/build/dex/usual/usual-m-usd0.d.ts +17 -0
- package/build/dex/usual/usual-m-usd0.js +51 -0
- package/build/dex/usual/usual-m-usd0.js.map +1 -0
- package/build/dex/usual/usual.d.ts +27 -0
- package/build/dex/usual/usual.js +125 -0
- package/build/dex/usual/usual.js.map +1 -0
- package/build/dex/usual-m-smart-m/config.d.ts +3 -0
- package/build/dex/usual-m-smart-m/config.js +13 -0
- package/build/dex/usual-m-smart-m/config.js.map +1 -0
- package/build/dex/usual-m-smart-m/types.d.ts +7 -0
- package/build/dex/usual-m-smart-m/types.js +3 -0
- package/build/dex/usual-m-smart-m/types.js.map +1 -0
- package/build/dex/usual-m-smart-m/usual-m-smart-m.d.ts +35 -0
- package/build/dex/usual-m-smart-m/usual-m-smart-m.js +161 -0
- package/build/dex/usual-m-smart-m/usual-m-smart-m.js.map +1 -0
- package/build/dex/usual-m-usd0/config.d.ts +3 -0
- package/build/dex/usual-m-usd0/config.js +14 -0
- package/build/dex/usual-m-usd0/config.js.map +1 -0
- package/build/dex/usual-m-usd0/types.d.ts +8 -0
- package/build/dex/usual-m-usd0/types.js +3 -0
- package/build/dex/usual-m-usd0/types.js.map +1 -0
- package/build/dex/usual-m-usd0/usual-m-usd0.d.ts +35 -0
- package/build/dex/usual-m-usd0/usual-m-usd0.js +159 -0
- package/build/dex/usual-m-usd0/usual-m-usd0.js.map +1 -0
- package/build/dex/weth/config.js +3 -0
- package/build/dex/weth/config.js.map +1 -1
- package/build/executor/Executor01BytecodeBuilder.js +2 -2
- package/build/executor/Executor01BytecodeBuilder.js.map +1 -1
- package/build/executor/Executor02BytecodeBuilder.js +2 -2
- package/build/executor/Executor02BytecodeBuilder.js.map +1 -1
- package/build/executor/Executor03BytecodeBuilder.js +2 -2
- package/build/executor/Executor03BytecodeBuilder.js.map +1 -1
- package/build/executor/ExecutorBytecodeBuilder.d.ts +3 -1
- package/build/executor/ExecutorBytecodeBuilder.js +35 -2
- package/build/executor/ExecutorBytecodeBuilder.js.map +1 -1
- package/build/generic-swap-transaction-builder.js +5 -1
- package/build/generic-swap-transaction-builder.js.map +1 -1
- package/build/types.d.ts +1 -0
- package/package.json +2 -1
- package/scripts/run-dex-integration-v3.ts +78 -0
- package/src/abi/balancer-v3/batch-router.json +989 -0
- package/src/abi/balancer-v3/router.json +1792 -0
- package/src/abi/balancer-v3/vault-extension.json +2834 -0
- package/src/abi/permit2.json +581 -0
- package/src/bigint-constants.ts +1 -0
- package/src/config.ts +29 -0
- package/src/constants.ts +4 -0
- package/src/dex/augustus-approvals.ts +52 -19
- package/src/dex/balancer-v3/balancer-v3-e2e.test.ts +275 -0
- package/src/dex/balancer-v3/balancer-v3-events.test.ts +223 -0
- package/src/dex/balancer-v3/balancer-v3-integration.test.ts +879 -0
- package/src/dex/balancer-v3/balancer-v3-pool.ts +656 -0
- package/src/dex/balancer-v3/balancer-v3.ts +538 -0
- package/src/dex/balancer-v3/config.ts +46 -0
- package/src/dex/balancer-v3/getGasCost.ts +37 -0
- package/src/dex/balancer-v3/getOnChainState.ts +326 -0
- package/src/dex/balancer-v3/getPoolsApi.ts +129 -0
- package/src/dex/balancer-v3/getTopPoolsApi.ts +96 -0
- package/src/dex/balancer-v3/optimizer.ts +66 -0
- package/src/dex/balancer-v3/stablePool.ts +78 -0
- package/src/dex/balancer-v3/types.ts +86 -0
- package/src/dex/balancer-v3/weightedPool.ts +2 -0
- package/src/dex/index.ts +4 -0
- package/src/dex/weth/config.ts +3 -0
- package/src/executor/Executor01BytecodeBuilder.ts +2 -0
- package/src/executor/Executor02BytecodeBuilder.ts +2 -0
- package/src/executor/Executor03BytecodeBuilder.ts +2 -0
- package/src/executor/ExecutorBytecodeBuilder.ts +63 -2
- package/src/generic-swap-transaction-builder.ts +6 -2
- package/src/types.ts +1 -0
- package/tests/constants-e2e.ts +66 -0
- package/build/abi/Aave_GSM.json +0 -751
- package/build/abi/Balancer.json +0 -257
- package/build/abi/BalancerV2.json +0 -1179
- package/build/abi/RamsesV2Pool.abi.json +0 -1554
- package/build/abi/RamsesV2Quoter.abi.json +0 -274
- package/build/abi/USDM.json +0 -807
- package/build/abi/UniswapV2Router.json +0 -397
- package/build/abi/angle-transmuter/ChainlinkEACAggregatorProxy.json +0 -509
- package/build/abi/curve-v1/CurveBUSDv2.abi.json +0 -1356
- package/build/abi/curve-v1/CurveTokenV1.json +0 -305
- package/build/abi/curve-v1/CurveTokenV2.json +0 -318
- package/build/abi/curve-v1/CurveV1StableNg.json +0 -1452
- package/build/abi/curve-v1/CurveV2Swap.json +0 -700
- package/build/abi/curve-v1/FactoryCryptoRegistry.json +0 -316
- package/build/abi/curve-v1/FactoryRegistry.json +0 -508
- package/build/abi/curve-v1/StableSwapAave.json +0 -1152
- package/build/abi/curve-v1/StableSwapBUSD.json +0 -814
- package/build/abi/curve-v1/StableSwapCompound.json +0 -814
- package/build/abi/curve-v1/StableSwapIDLE.json +0 -1253
- package/build/abi/curve-v1/StableSwapPax.json +0 -865
- package/build/abi/curve-v1/StableSwapSnow.json +0 -900
- package/build/abi/curve-v1/StableSwapUSDN.json +0 -1004
- package/build/abi/curve-v1/StableSwapUSDT.json +0 -814
- package/build/abi/curve-v1/StableSwapY.json +0 -814
- package/build/abi/inception/inception-ineth.json +0 -609
- package/build/abi/kyberdmm/kyber-storage.abi.json +0 -824
- package/build/abi/kyberdmm.abi.json +0 -1148
- package/build/abi/maverick-v2/MaverickV2Quoter.json +0 -278
- package/build/abi/nerve/nerve-metapool.json +0 -790
- package/build/abi/uniswap-v3/UniswapV3Quoter.abi.json +0 -193
- package/build/abi/velodrome-slipstream/VelodromeSlipstreamQuoterV2.abi.json +0 -267
- package/build/dex/balancer-v1/balancer-pools.json +0 -33333
- package/build/dex/bebop/websocket-fetcher.d.ts +0 -35
- package/build/dex/bebop/websocket-fetcher.js +0 -87
- package/build/dex/bebop/websocket-fetcher.js.map +0 -1
- package/build/dex/idle-dao/idle-dao-pool.d.ts +0 -56
- package/build/dex/idle-dao/idle-dao-pool.js +0 -176
- package/build/dex/idle-dao/idle-dao-pool.js.map +0 -1
- package/build/dex/idle-dao/idle-dao-pooling-pool.d.ts +0 -16
- package/build/dex/idle-dao/idle-dao-pooling-pool.js +0 -57
- package/build/dex/idle-dao/idle-dao-pooling-pool.js.map +0 -1
- package/build/dex/idle-dao/scripts.d.ts +0 -9
- package/build/dex/idle-dao/scripts.js +0 -552
- package/build/dex/idle-dao/scripts.js.map +0 -1
- package/build/dex/inception/inception-native.d.ts +0 -43
- package/build/dex/inception/inception-native.js +0 -131
- package/build/dex/inception/inception-native.js.map +0 -1
- package/build/dex/inception/inception-pool.d.ts +0 -18
- package/build/dex/inception/inception-pool.js +0 -32
- package/build/dex/inception/inception-pool.js.map +0 -1
- package/build/dex/inception/inception-price-feed.d.ts +0 -19
- package/build/dex/inception/inception-price-feed.js +0 -51
- package/build/dex/inception/inception-price-feed.js.map +0 -1
- package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-balancerv1-curvev1-eth-usdc-gusd.json +0 -16
- package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-balancerv1-sushiv3-wbtc-eth-sushi.json +0 -16
- package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-curvev1-eth-usdc-gusd.json +0 -16
- package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-curvev1-gusd-usdc-eth.json +0 -16
- package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-dai-usdc-eth.json +0 -16
- package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-eth-usdc-dai.json +0 -16
- package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-usdc-eth-wbtc.json +0 -16
- package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-usdt-usdc-dai.json +0 -16
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-balancerv1-eth-usdc.json +0 -9
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-balancerv1-usdc-eth.json +0 -9
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-balancerv1-usdc-wbtc.json +0 -9
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-curvev1-eth-steth.json +0 -9
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-curvev1-steth-eth.json +0 -9
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-curvev1-usdc-usdt.json +0 -9
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-univ3-eth-usdc.json +0 -9
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-univ3-usdc-eth.json +0 -9
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-univ3-usdc-usdt.json +0 -9
- package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-balancerv1-sushiv3-wbtc-eth-sushi.json +0 -12
- package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-curvev1-eth-usdc-gusd.json +0 -7
- package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-curvev1-gusd-usdc-eth.json +0 -7
- package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-dai-usdc-eth.json +0 -7
- package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-eth-usdc-dai.json +0 -7
- package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-usdc-eth-wbtc.json +0 -12
- package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-simpleSwap-univ3-eth-usdc.json +0 -7
- package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-simpleSwap-univ3-usdc-eth.json +0 -7
- package/build/executor/fixtures/executor01/routes/price-route-multiswap-balancerv1-curvev1-eth-usdc-gusd.json +0 -78
- package/build/executor/fixtures/executor01/routes/price-route-multiswap-balancerv1-sushiv3-wbtc-eth-sushi.json +0 -81
- package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-curvev1-eth-usdc-gusd.json +0 -78
- package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-curvev1-gusd-usdc-eth.json +0 -78
- package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-dai-usdc-eth.json +0 -81
- package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-eth-usdc-dai.json +0 -81
- package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-usdc-eth-wbtc.json +0 -81
- package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-usdt-usdc-dai.json +0 -81
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-balancerv1-eth-usdc.json +0 -64
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-balancerv1-usdc-eth.json +0 -85
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-balancerv1-usdc-wbtc.json +0 -64
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-curvev1-eth-steth.json +0 -52
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-curvev1-steth-eth.json +0 -52
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-curvev1-usdc-usdt.json +0 -52
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-univ3-eth-usdc.json +0 -55
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-univ3-usdc-eth.json +0 -55
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-univ3-usdc-usdt.json +0 -55
- package/build/executor/fixtures/executor02/exchange-params/price-route-multiSwap-balancerv1-sushiv3-univ3-bal-eth-sushi.json +0 -23
- package/build/executor/fixtures/executor02/exchange-params/price-route-multiSwap-maverickv1-sushiv3-univ3-eth-usdc-mav.json +0 -37
- package/build/executor/fixtures/executor02/exchange-params/price-route-multiSwap-univ3-sushiv3-sushi-eth-wbtc.json +0 -23
- package/build/executor/fixtures/executor02/exchange-params/price-route-multiSwap-univ3-sushiv3-wbtc-eth-sushi.json +0 -23
- package/build/executor/fixtures/executor02/exchange-params/price-route-multiswap-curvev1-univ3-dai-usdc-eth.json +0 -51
- package/build/executor/fixtures/executor02/exchange-params/price-route-multiswap-univ3-usdt-dai-eth.json +0 -58
- package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-balancerv1-eth-usdc.json +0 -23
- package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-balancerv1-usdc-eth.json +0 -23
- package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-univ3-eth-sushi.json +0 -9
- package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-univ3-sushi-eth.json +0 -16
- package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-univ3-curvev1-usdt-dai.json +0 -23
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-balancerv1-sushiv3-univ3-bal-eth-sushi.json +0 -12
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-maverickv1-sushiv3-univ3-eth-usdc-mav.json +0 -7
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-univ3-sushiv3-sushi-eth-wbtc.json +0 -12
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-univ3-sushiv3-wbtc-eth-sushi.json +0 -12
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiswap-curvev1-univ3-dai-usdc-eth.json +0 -7
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiswap-univ3-usdt-dai-eth.json +0 -7
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-balancerv1-eth-usdc.json +0 -7
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-balancerv1-usdc-eth.json +0 -7
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-univ3-eth-sushi.json +0 -7
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-univ3-sushi-eth.json +0 -7
- package/build/executor/fixtures/executor02/routes/price-route-multiSwap-balancerv1-sushiv3-univ3-bal-eth-sushi.json +0 -130
- package/build/executor/fixtures/executor02/routes/price-route-multiSwap-maverickv1-sushiv3-univ3-eth-usdc-mav.json +0 -136
- package/build/executor/fixtures/executor02/routes/price-route-multiSwap-univ3-sushiv3-sushi-eth-wbtc.json +0 -100
- package/build/executor/fixtures/executor02/routes/price-route-multiSwap-univ3-sushiv3-wbtc-eth-sushi.json +0 -100
- package/build/executor/fixtures/executor02/routes/price-route-multiswap-curvev1-univ3-dai-usdc-eth.json +0 -166
- package/build/executor/fixtures/executor02/routes/price-route-multiswap-univ3-usdt-dai-eth.json +0 -190
- package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-balancerv1-eth-usdc.json +0 -114
- package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-balancerv1-usdc-eth.json +0 -114
- package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-univ3-eth-sushi.json +0 -55
- package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-univ3-sushi-eth.json +0 -73
- 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
|
+
}
|