@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,538 @@
|
|
|
1
|
+
import { AsyncOrSync, DeepReadonly } from 'ts-essentials';
|
|
2
|
+
import {
|
|
3
|
+
Token,
|
|
4
|
+
Address,
|
|
5
|
+
ExchangePrices,
|
|
6
|
+
PoolPrices,
|
|
7
|
+
AdapterExchangeParam,
|
|
8
|
+
PoolLiquidity,
|
|
9
|
+
Logger,
|
|
10
|
+
DexExchangeParam,
|
|
11
|
+
} from '../../types';
|
|
12
|
+
import { SwapSide, Network } from '../../constants';
|
|
13
|
+
import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
|
|
14
|
+
import { getBigIntPow, getDexKeysWithNetwork, isETHAddress } from '../../utils';
|
|
15
|
+
import { IDex } from '../../dex/idex';
|
|
16
|
+
import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
17
|
+
import { BalancerV3Data, PoolState, PoolStateMap } from './types';
|
|
18
|
+
import { SimpleExchange } from '../simple-exchange';
|
|
19
|
+
import { BalancerV3Config } from './config';
|
|
20
|
+
import { BalancerV3EventPool } from './balancer-v3-pool';
|
|
21
|
+
import { NumberAsString } from '@paraswap/core';
|
|
22
|
+
import { SwapKind } from '@balancer-labs/balancer-maths';
|
|
23
|
+
import { Interface } from '@ethersproject/abi';
|
|
24
|
+
import { extractReturnAmountPosition } from '../../executor/utils';
|
|
25
|
+
import { getTopPoolsApi } from './getTopPoolsApi';
|
|
26
|
+
import balancerRouterAbi from '../../abi/balancer-v3/router.json';
|
|
27
|
+
import balancerBatchRouterAbi from '../../abi/balancer-v3/batch-router.json';
|
|
28
|
+
import { getGasCost } from './getGasCost';
|
|
29
|
+
|
|
30
|
+
const MAX_UINT256 =
|
|
31
|
+
'115792089237316195423570985008687907853269984665640564039457584007913129639935';
|
|
32
|
+
const POOL_UPDATE_TTL = 5 * 60; // 5mins
|
|
33
|
+
const RATE_UPDATE_TTL = 1 * 60; // 1min
|
|
34
|
+
|
|
35
|
+
type DeepMutable<T> = {
|
|
36
|
+
-readonly [P in keyof T]: T[P] extends object ? DeepMutable<T[P]> : T[P];
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export class BalancerV3 extends SimpleExchange implements IDex<BalancerV3Data> {
|
|
40
|
+
protected eventPools: BalancerV3EventPool;
|
|
41
|
+
|
|
42
|
+
readonly hasConstantPriceLargeAmounts = false;
|
|
43
|
+
// Vault can handle native
|
|
44
|
+
readonly needWrapNative = false;
|
|
45
|
+
|
|
46
|
+
readonly isFeeOnTransferSupported = false;
|
|
47
|
+
|
|
48
|
+
public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
|
|
49
|
+
getDexKeysWithNetwork(BalancerV3Config);
|
|
50
|
+
|
|
51
|
+
logger: Logger;
|
|
52
|
+
balancerRouter: Interface;
|
|
53
|
+
balancerBatchRouter: Interface;
|
|
54
|
+
updateNewPoolsTimer?: NodeJS.Timeout;
|
|
55
|
+
updateRatesTimer?: NodeJS.Timeout;
|
|
56
|
+
|
|
57
|
+
constructor(
|
|
58
|
+
readonly network: Network,
|
|
59
|
+
readonly dexKey: string,
|
|
60
|
+
readonly dexHelper: IDexHelper,
|
|
61
|
+
) {
|
|
62
|
+
super(dexHelper, dexKey);
|
|
63
|
+
this.logger = dexHelper.getLogger(dexKey);
|
|
64
|
+
this.eventPools = new BalancerV3EventPool(
|
|
65
|
+
dexKey,
|
|
66
|
+
network,
|
|
67
|
+
dexHelper,
|
|
68
|
+
this.logger,
|
|
69
|
+
);
|
|
70
|
+
this.balancerRouter = new Interface(balancerRouterAbi);
|
|
71
|
+
this.balancerBatchRouter = new Interface(balancerBatchRouterAbi);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Initialize pricing is called once in the start of
|
|
75
|
+
// pricing service. It is intended to setup the integration
|
|
76
|
+
// for pricing requests. It is optional for a DEX to
|
|
77
|
+
// implement this function
|
|
78
|
+
async initializePricing(blockNumber: number) {
|
|
79
|
+
await this.eventPools.initialize(blockNumber);
|
|
80
|
+
|
|
81
|
+
// This will periodically query API and add any new pools to pool state
|
|
82
|
+
if (!this.updateNewPoolsTimer) {
|
|
83
|
+
this.updateNewPoolsTimer = setInterval(async () => {
|
|
84
|
+
try {
|
|
85
|
+
await this.updatePoolState();
|
|
86
|
+
} catch (e) {
|
|
87
|
+
this.logger.error(`${this.dexKey}: Failed to update pool state:`, e);
|
|
88
|
+
}
|
|
89
|
+
}, POOL_UPDATE_TTL * 1000);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// This will periodically refresh tokenRates with onchain state
|
|
93
|
+
if (!this.updateRatesTimer) {
|
|
94
|
+
this.updateRatesTimer = setInterval(async () => {
|
|
95
|
+
try {
|
|
96
|
+
await this.updateStatePoolRates();
|
|
97
|
+
} catch (e) {
|
|
98
|
+
this.logger.error(`${this.dexKey}: Failed to update pool rates:`, e);
|
|
99
|
+
}
|
|
100
|
+
}, RATE_UPDATE_TTL * 1000);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
getAdapters(side: SwapSide): null {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Returns list of pool identifiers that can be used
|
|
109
|
+
// for a given swap. poolIdentifiers must be unique
|
|
110
|
+
// across DEXes. It is recommended to use
|
|
111
|
+
// ${dexKey}_${poolAddress} as a poolIdentifier
|
|
112
|
+
async getPoolIdentifiers(
|
|
113
|
+
srcToken: Token,
|
|
114
|
+
destToken: Token,
|
|
115
|
+
side: SwapSide,
|
|
116
|
+
blockNumber: number,
|
|
117
|
+
): Promise<string[]> {
|
|
118
|
+
const _from = this.dexHelper.config.wrapETH(srcToken);
|
|
119
|
+
const _to = this.dexHelper.config.wrapETH(destToken);
|
|
120
|
+
const poolState = this.eventPools.getState(blockNumber);
|
|
121
|
+
if (poolState === null) return [];
|
|
122
|
+
return this.findPoolAddressesWithTokens(
|
|
123
|
+
poolState,
|
|
124
|
+
_from.address.toLowerCase(),
|
|
125
|
+
_to.address.toLowerCase(),
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
findPoolAddressesWithTokens(
|
|
130
|
+
pools: DeepReadonly<PoolStateMap>,
|
|
131
|
+
tokenA: string,
|
|
132
|
+
tokenB: string,
|
|
133
|
+
): string[] {
|
|
134
|
+
return Object.entries(pools)
|
|
135
|
+
.filter(([, poolState]) => {
|
|
136
|
+
return this.hasTokens(poolState, [tokenA, tokenB]);
|
|
137
|
+
})
|
|
138
|
+
.map(([address]) => address);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Filter pools that have tokens from/to and are in limitPool list
|
|
143
|
+
* @param pools
|
|
144
|
+
* @param from
|
|
145
|
+
* @param to
|
|
146
|
+
* @param limitPools
|
|
147
|
+
* @returns Array of PoolState
|
|
148
|
+
*/
|
|
149
|
+
filterPools(
|
|
150
|
+
pools: DeepReadonly<PoolStateMap>,
|
|
151
|
+
from: string,
|
|
152
|
+
to: string,
|
|
153
|
+
limitPools?: string[],
|
|
154
|
+
): PoolState[] {
|
|
155
|
+
return Object.entries(pools)
|
|
156
|
+
.filter(([address, poolState]) => {
|
|
157
|
+
const hasRequiredTokens = this.hasTokens(poolState, [from, to]);
|
|
158
|
+
const isAllowedPool = !limitPools || limitPools.includes(address);
|
|
159
|
+
return hasRequiredTokens && isAllowedPool;
|
|
160
|
+
})
|
|
161
|
+
.map(([_, poolState]) => poolState as DeepMutable<typeof poolState>);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
hasTokens(pool: DeepReadonly<PoolState>, tokens: string[]): boolean {
|
|
165
|
+
return tokens.every(
|
|
166
|
+
token =>
|
|
167
|
+
pool.tokens.includes(token) || pool.tokensUnderlying.includes(token),
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Returns pool prices for amounts.
|
|
172
|
+
// If limitPools is defined only pools in limitPools
|
|
173
|
+
// should be used. If limitPools is undefined then
|
|
174
|
+
// any pools can be used.
|
|
175
|
+
async getPricesVolume(
|
|
176
|
+
srcToken: Token,
|
|
177
|
+
destToken: Token,
|
|
178
|
+
amounts: bigint[],
|
|
179
|
+
side: SwapSide,
|
|
180
|
+
blockNumber: number,
|
|
181
|
+
limitPools?: string[],
|
|
182
|
+
): Promise<null | ExchangePrices<BalancerV3Data>> {
|
|
183
|
+
try {
|
|
184
|
+
const _from = this.dexHelper.config.wrapETH(srcToken);
|
|
185
|
+
const _to = this.dexHelper.config.wrapETH(destToken);
|
|
186
|
+
if (_from.address === _to.address) {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// This is used to get block timestamp which is needed to calculate Amp if it is updating
|
|
191
|
+
const block = await this.dexHelper.provider.getBlock(blockNumber);
|
|
192
|
+
|
|
193
|
+
// get up to date pools and state
|
|
194
|
+
const allPoolState = this.eventPools.getState(blockNumber);
|
|
195
|
+
if (allPoolState === null) {
|
|
196
|
+
this.logger.error(`getState returned null`);
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// filter for pools with tokens and to only use limit pools
|
|
201
|
+
const allowedPools = this.filterPools(
|
|
202
|
+
allPoolState,
|
|
203
|
+
_from.address.toLowerCase(),
|
|
204
|
+
_to.address.toLowerCase(),
|
|
205
|
+
limitPools,
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
if (!allowedPools.length) return null;
|
|
209
|
+
|
|
210
|
+
const swapKind =
|
|
211
|
+
side === SwapSide.SELL ? SwapKind.GivenIn : SwapKind.GivenOut;
|
|
212
|
+
const tokenIn = _from.address;
|
|
213
|
+
const tokenOut = _to.address;
|
|
214
|
+
|
|
215
|
+
// Gets the single unit amount based off token decimals, e.g. for USDC its 1e6
|
|
216
|
+
const unitAmount = getBigIntPow(
|
|
217
|
+
(side === SwapSide.SELL ? _from : _to).decimals,
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
const poolPrices: ExchangePrices<BalancerV3Data> = [];
|
|
221
|
+
// For each pool we calculate swap result using balancer maths
|
|
222
|
+
for (let i = 0; i < allowedPools.length; i++) {
|
|
223
|
+
const pool = {
|
|
224
|
+
...allowedPools[i],
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
const tokenInInfo = this.eventPools.getTokenInfo(pool, tokenIn);
|
|
228
|
+
const tokenOutInfo = this.eventPools.getTokenInfo(pool, tokenOut);
|
|
229
|
+
if (!tokenInInfo || !tokenOutInfo) {
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const steps = this.eventPools.getSteps(pool, tokenInInfo, tokenOutInfo);
|
|
234
|
+
|
|
235
|
+
try {
|
|
236
|
+
// This is the max amount the pool can swap
|
|
237
|
+
const maxSwapAmount = this.eventPools.getMaxSwapAmount(
|
|
238
|
+
pool,
|
|
239
|
+
tokenInInfo,
|
|
240
|
+
tokenOutInfo,
|
|
241
|
+
swapKind,
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
let unit = 0n;
|
|
245
|
+
if (unitAmount < maxSwapAmount)
|
|
246
|
+
unit = this.eventPools.getSwapResult(
|
|
247
|
+
steps,
|
|
248
|
+
unitAmount,
|
|
249
|
+
swapKind,
|
|
250
|
+
block.timestamp,
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
const poolExchangePrice: PoolPrices<BalancerV3Data> = {
|
|
254
|
+
prices: new Array(amounts.length).fill(0n),
|
|
255
|
+
unit,
|
|
256
|
+
data: {
|
|
257
|
+
steps: steps,
|
|
258
|
+
},
|
|
259
|
+
exchange: this.dexKey,
|
|
260
|
+
gasCost: getGasCost(steps),
|
|
261
|
+
poolAddresses: [pool.poolAddress],
|
|
262
|
+
poolIdentifier: `${this.dexKey}_${pool.poolAddress}`,
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
for (let j = 0; j < amounts.length; j++) {
|
|
266
|
+
if (amounts[j] < maxSwapAmount) {
|
|
267
|
+
// Uses balancer maths to calculate swap
|
|
268
|
+
poolExchangePrice.prices[j] = this.eventPools.getSwapResult(
|
|
269
|
+
steps,
|
|
270
|
+
amounts[j],
|
|
271
|
+
swapKind,
|
|
272
|
+
block.timestamp,
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
poolPrices.push(poolExchangePrice);
|
|
277
|
+
} catch (err) {
|
|
278
|
+
this.logger.error(
|
|
279
|
+
`error fetching prices for pool: ${pool.poolAddress}`,
|
|
280
|
+
);
|
|
281
|
+
this.logger.error(err);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
return poolPrices;
|
|
286
|
+
} catch (err) {}
|
|
287
|
+
return null;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// Returns estimated gas cost of calldata for this DEX in multiSwap
|
|
291
|
+
getCalldataGasCost(
|
|
292
|
+
poolPrices: PoolPrices<BalancerV3Data>,
|
|
293
|
+
): number | number[] {
|
|
294
|
+
// TODO: update if there is any payload in getAdapterParam
|
|
295
|
+
return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// Not used for V6
|
|
299
|
+
getAdapterParam(): AdapterExchangeParam {
|
|
300
|
+
return {
|
|
301
|
+
targetExchange: '0x',
|
|
302
|
+
payload: '0x',
|
|
303
|
+
networkFee: '0',
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
getDexParam(
|
|
308
|
+
srcToken: Address,
|
|
309
|
+
destToken: Address,
|
|
310
|
+
srcAmount: NumberAsString,
|
|
311
|
+
destAmount: NumberAsString,
|
|
312
|
+
recipient: Address,
|
|
313
|
+
data: BalancerV3Data,
|
|
314
|
+
side: SwapSide,
|
|
315
|
+
): DexExchangeParam {
|
|
316
|
+
if (side === SwapSide.SELL) {
|
|
317
|
+
return this.getExactInParam(srcToken, destToken, srcAmount, data);
|
|
318
|
+
} else {
|
|
319
|
+
return this.getExactOutParam(
|
|
320
|
+
srcToken,
|
|
321
|
+
destToken,
|
|
322
|
+
srcAmount,
|
|
323
|
+
destAmount,
|
|
324
|
+
data,
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
getExactInParam(
|
|
330
|
+
srcToken: Address,
|
|
331
|
+
destToken: Address,
|
|
332
|
+
srcAmount: NumberAsString,
|
|
333
|
+
data: BalancerV3Data,
|
|
334
|
+
): DexExchangeParam {
|
|
335
|
+
if (data.steps.length === 1) {
|
|
336
|
+
const exchangeData = this.balancerRouter.encodeFunctionData(
|
|
337
|
+
'swapSingleTokenExactIn',
|
|
338
|
+
[
|
|
339
|
+
data.steps[0].pool,
|
|
340
|
+
this.dexHelper.config.wrapETH(srcToken),
|
|
341
|
+
this.dexHelper.config.wrapETH(destToken),
|
|
342
|
+
srcAmount,
|
|
343
|
+
'0', // This should be limit for min amount out. Assume this is set elsewhere via Paraswap contract.
|
|
344
|
+
MAX_UINT256, // Deadline
|
|
345
|
+
isETHAddress(srcToken) || isETHAddress(destToken),
|
|
346
|
+
'0x',
|
|
347
|
+
],
|
|
348
|
+
);
|
|
349
|
+
return {
|
|
350
|
+
permit2Approval: true,
|
|
351
|
+
needWrapNative: this.needWrapNative,
|
|
352
|
+
dexFuncHasRecipient: false,
|
|
353
|
+
exchangeData,
|
|
354
|
+
// This router handles single swaps
|
|
355
|
+
targetExchange:
|
|
356
|
+
BalancerV3Config.BalancerV3[this.network].balancerRouterAddress,
|
|
357
|
+
returnAmountPos: extractReturnAmountPosition(
|
|
358
|
+
this.balancerRouter,
|
|
359
|
+
'swapSingleTokenExactIn',
|
|
360
|
+
),
|
|
361
|
+
};
|
|
362
|
+
} else {
|
|
363
|
+
// for each step:
|
|
364
|
+
// if tokenIn == pool router uses removeLiquidity SINGLE_TOKEN_EXACT_IN
|
|
365
|
+
// if tokenOut == pool router uses addLiquidity UNBALANCED
|
|
366
|
+
const exchangeData = this.balancerBatchRouter.encodeFunctionData(
|
|
367
|
+
'swapExactIn',
|
|
368
|
+
[
|
|
369
|
+
[
|
|
370
|
+
{
|
|
371
|
+
tokenIn: srcToken,
|
|
372
|
+
steps: data.steps.map(step => ({
|
|
373
|
+
pool: step.pool,
|
|
374
|
+
tokenOut: step.swapInput.tokenOut,
|
|
375
|
+
isBuffer: step.isBuffer,
|
|
376
|
+
})),
|
|
377
|
+
exactAmountIn: srcAmount,
|
|
378
|
+
minAmountOut: '0', // This should be limit for min amount out. Assume this is set elsewhere via Paraswap contract.
|
|
379
|
+
},
|
|
380
|
+
],
|
|
381
|
+
MAX_UINT256, // Deadline
|
|
382
|
+
isETHAddress(srcToken) || isETHAddress(destToken),
|
|
383
|
+
'0x',
|
|
384
|
+
],
|
|
385
|
+
);
|
|
386
|
+
|
|
387
|
+
return {
|
|
388
|
+
permit2Approval: true,
|
|
389
|
+
needWrapNative: this.needWrapNative,
|
|
390
|
+
dexFuncHasRecipient: false,
|
|
391
|
+
exchangeData,
|
|
392
|
+
// This router handles batch swaps
|
|
393
|
+
targetExchange:
|
|
394
|
+
BalancerV3Config.BalancerV3[this.network].balancerBatchRouterAddress,
|
|
395
|
+
returnAmountPos: undefined,
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
getExactOutParam(
|
|
401
|
+
srcToken: Address,
|
|
402
|
+
destToken: Address,
|
|
403
|
+
srcAmount: NumberAsString,
|
|
404
|
+
destAmount: NumberAsString,
|
|
405
|
+
data: BalancerV3Data,
|
|
406
|
+
): DexExchangeParam {
|
|
407
|
+
if (data.steps.length === 1) {
|
|
408
|
+
const exchangeData = this.balancerRouter.encodeFunctionData(
|
|
409
|
+
'swapSingleTokenExactOut',
|
|
410
|
+
[
|
|
411
|
+
data.steps[0].pool,
|
|
412
|
+
this.dexHelper.config.wrapETH(srcToken),
|
|
413
|
+
this.dexHelper.config.wrapETH(destToken),
|
|
414
|
+
destAmount,
|
|
415
|
+
MAX_UINT256, // This should be limit for max amount in. Assume this is set elsewhere via Paraswap contract.
|
|
416
|
+
MAX_UINT256, // Deadline
|
|
417
|
+
isETHAddress(srcToken) || isETHAddress(destToken),
|
|
418
|
+
'0x',
|
|
419
|
+
],
|
|
420
|
+
);
|
|
421
|
+
|
|
422
|
+
return {
|
|
423
|
+
permit2Approval: true,
|
|
424
|
+
needWrapNative: this.needWrapNative,
|
|
425
|
+
dexFuncHasRecipient: false,
|
|
426
|
+
exchangeData,
|
|
427
|
+
// Single swaps are submitted via Balancer Router
|
|
428
|
+
targetExchange:
|
|
429
|
+
BalancerV3Config.BalancerV3[this.network].balancerRouterAddress,
|
|
430
|
+
returnAmountPos: undefined,
|
|
431
|
+
};
|
|
432
|
+
} else {
|
|
433
|
+
// for each step:
|
|
434
|
+
// if tokenIn == pool use removeLiquidity SINGLE_TOKEN_EXACT_OUT
|
|
435
|
+
// if tokenOut == pool use addLiquidity SINGLE_TOKEN_EXACT_OUT
|
|
436
|
+
const exchangeData = this.balancerBatchRouter.encodeFunctionData(
|
|
437
|
+
'swapExactOut',
|
|
438
|
+
[
|
|
439
|
+
[
|
|
440
|
+
{
|
|
441
|
+
tokenIn: srcToken,
|
|
442
|
+
steps: data.steps.map(step => ({
|
|
443
|
+
pool: step.pool,
|
|
444
|
+
tokenOut: step.swapInput.tokenOut,
|
|
445
|
+
isBuffer: step.isBuffer,
|
|
446
|
+
})),
|
|
447
|
+
exactAmountOut: destAmount,
|
|
448
|
+
maxAmountIn: srcAmount,
|
|
449
|
+
},
|
|
450
|
+
],
|
|
451
|
+
MAX_UINT256, // Deadline
|
|
452
|
+
isETHAddress(srcToken) || isETHAddress(destToken),
|
|
453
|
+
'0x',
|
|
454
|
+
],
|
|
455
|
+
);
|
|
456
|
+
|
|
457
|
+
return {
|
|
458
|
+
permit2Approval: true,
|
|
459
|
+
needWrapNative: this.needWrapNative,
|
|
460
|
+
dexFuncHasRecipient: false,
|
|
461
|
+
exchangeData,
|
|
462
|
+
// This router handles batch swaps
|
|
463
|
+
targetExchange:
|
|
464
|
+
BalancerV3Config.BalancerV3[this.network].balancerBatchRouterAddress,
|
|
465
|
+
returnAmountPos: undefined,
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Uses multicall to get onchain token rate for each pool then updates pool state
|
|
472
|
+
*/
|
|
473
|
+
async updateStatePoolRates(): Promise<void> {
|
|
474
|
+
await this.eventPools.updateStatePoolRates();
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
// This is called once before getTopPoolsForToken is
|
|
478
|
+
// called for multiple tokens. This can be helpful to
|
|
479
|
+
// update common state required for calculating
|
|
480
|
+
// getTopPoolsForToken. It is optional for a DEX
|
|
481
|
+
// to implement this
|
|
482
|
+
async updatePoolState(): Promise<void> {
|
|
483
|
+
await this.eventPools.updateStatePools();
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
// Returns list of top pools based on liquidity. Max
|
|
487
|
+
// limit number pools should be returned.
|
|
488
|
+
async getTopPoolsForToken(
|
|
489
|
+
tokenAddress: Address,
|
|
490
|
+
count: number,
|
|
491
|
+
): Promise<PoolLiquidity[]> {
|
|
492
|
+
const poolsWithToken = Object.entries(this.eventPools.getStaleState() || {})
|
|
493
|
+
.filter(([, poolState]) => {
|
|
494
|
+
return this.hasTokens(poolState, [tokenAddress.toLowerCase()]);
|
|
495
|
+
})
|
|
496
|
+
.map(([address]) => address);
|
|
497
|
+
|
|
498
|
+
const topPools = await getTopPoolsApi(this.network, poolsWithToken, count);
|
|
499
|
+
|
|
500
|
+
return topPools.map(pool => {
|
|
501
|
+
const tokens = pool.poolTokens
|
|
502
|
+
.filter(t => t.address !== tokenAddress)
|
|
503
|
+
.map(t => ({
|
|
504
|
+
address: t.address,
|
|
505
|
+
decimals: t.decimals,
|
|
506
|
+
}));
|
|
507
|
+
|
|
508
|
+
const underlyingTokens = pool.poolTokens
|
|
509
|
+
.map(t => t.underlyingToken)
|
|
510
|
+
.filter(t => !!t)
|
|
511
|
+
.filter(t => t?.address !== tokenAddress) as Token[];
|
|
512
|
+
|
|
513
|
+
return {
|
|
514
|
+
exchange: this.dexKey,
|
|
515
|
+
address: pool.address,
|
|
516
|
+
liquidityUSD: parseFloat(pool.dynamicData.totalLiquidity),
|
|
517
|
+
connectorTokens: tokens.concat(underlyingTokens),
|
|
518
|
+
};
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
releaseResources(): AsyncOrSync<void> {
|
|
523
|
+
if (this.updateNewPoolsTimer) {
|
|
524
|
+
clearInterval(this.updateNewPoolsTimer);
|
|
525
|
+
this.updateNewPoolsTimer = undefined;
|
|
526
|
+
this.logger.info(
|
|
527
|
+
`${this.dexKey}: cleared updateNewPoolsTimer before shutting down`,
|
|
528
|
+
);
|
|
529
|
+
}
|
|
530
|
+
if (this.updateRatesTimer) {
|
|
531
|
+
clearInterval(this.updateRatesTimer);
|
|
532
|
+
this.updateRatesTimer = undefined;
|
|
533
|
+
this.logger.info(
|
|
534
|
+
`${this.dexKey}: cleared updateRatesTimer before shutting down`,
|
|
535
|
+
);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { DexParams } from './types';
|
|
2
|
+
import { DexConfigMap, AdapterMappings } from '../../types';
|
|
3
|
+
import { Network, SwapSide } from '../../constants';
|
|
4
|
+
|
|
5
|
+
// These map to the Balancer API poolType. Only Balancer supported pools will be added
|
|
6
|
+
export enum SUPPORTED_POOLS {
|
|
7
|
+
WEIGHTED = 'WEIGHTED',
|
|
8
|
+
STABLE = 'STABLE',
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const disabledPoolIds: Record<string, Record<number, string[]>> = {
|
|
12
|
+
BalancerV3: {
|
|
13
|
+
[Network.GNOSIS]: [
|
|
14
|
+
// pools with rate provider that returns nested rate instead of wrap/unwrap rate
|
|
15
|
+
'0x6e6bb18449fcf15b79efa2cfa70acf7593088029',
|
|
16
|
+
'0x272d6be442e30d7c87390edeb9b96f1e84cecd8d',
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// Balancer API - aggregatorSpecific query serves all useful static pool data
|
|
22
|
+
export const apiUrl = 'https://test-api-v3.balancer.fi/';
|
|
23
|
+
|
|
24
|
+
// TODO Full config added after V3 release
|
|
25
|
+
export const BalancerV3Config: DexConfigMap<DexParams> = {
|
|
26
|
+
BalancerV3: {
|
|
27
|
+
[Network.SEPOLIA]: {
|
|
28
|
+
vaultAddress: '0xbA1333333333a1BA1108E8412f11850A5C319bA9',
|
|
29
|
+
apiNetworkName: 'SEPOLIA',
|
|
30
|
+
balancerRouterAddress: '0x0BF61f706105EA44694f2e92986bD01C39930280',
|
|
31
|
+
balancerBatchRouterAddress: '0xC85b652685567C1B074e8c0D4389f83a2E458b1C',
|
|
32
|
+
},
|
|
33
|
+
[Network.GNOSIS]: {
|
|
34
|
+
vaultAddress: '0xbA1333333333a1BA1108E8412f11850A5C319bA9',
|
|
35
|
+
apiNetworkName: 'GNOSIS',
|
|
36
|
+
balancerRouterAddress: '0x84813aA3e079A665C0B80F944427eE83cBA63617',
|
|
37
|
+
balancerBatchRouterAddress: '0xe2fa4e1d17725e72dcdAfe943Ecf45dF4B9E285b',
|
|
38
|
+
},
|
|
39
|
+
[Network.MAINNET]: {
|
|
40
|
+
vaultAddress: '0xbA1333333333a1BA1108E8412f11850A5C319bA9',
|
|
41
|
+
apiNetworkName: 'MAINNET',
|
|
42
|
+
balancerRouterAddress: '0x5C6fb490BDFD3246EB0bB062c168DeCAF4bD9FDd',
|
|
43
|
+
balancerBatchRouterAddress: '0x136f1EFcC3f8f88516B9E94110D56FDBfB1778d1',
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { STABLE_GAS_COST } from './stablePool';
|
|
2
|
+
import { Step } from './types';
|
|
3
|
+
import { WEIGHTED_GAS_COST } from './weightedPool';
|
|
4
|
+
|
|
5
|
+
// https://sepolia.etherscan.io/tx/0x8c2c5ec7fc2855ed2ffab3467ee434f4e374e0ecf791e8d2b93c8d74e3f5b1fe
|
|
6
|
+
// 0x7ec61d6dcf0ea412327c30f013e60578c0ff4d83c334a95fb3a68739860e6f59
|
|
7
|
+
// 0xb45331fe60091bdf4ba4c201b7fdfefc1ca8087fa1b6bc28877ef84d167809f4
|
|
8
|
+
const FULL_BOOSTED_SWAP_GAS_COST = 283070;
|
|
9
|
+
// 0xb47bcae19ba4693d18f2148073d0d469ff59223e90d6f75eb25e06b0063f1556
|
|
10
|
+
// 0x4730b0c1dce820f14747698446865364b98d96d3ed926e8e74bbead6482b8f8b
|
|
11
|
+
const PARTIAL_BOOSTED_SWAP_GAS_COST = 259815;
|
|
12
|
+
// 0xef9037f992645a9ecf26ddbdf65690a71acbffce2cc68445c869bb9707cb706a
|
|
13
|
+
// 0x77aa06350df079a077147f1051b10e0612542eb3aff3ae1b3d4004341cb64690
|
|
14
|
+
const BUFFER_WRAP_UNWRAP_GAS_COST = 155921;
|
|
15
|
+
|
|
16
|
+
export function getGasCost(steps: Step[]): number {
|
|
17
|
+
if (steps.length === 2) {
|
|
18
|
+
// Partial boosted/buffer swap:
|
|
19
|
+
// token[wrap]wrappedToken[swap]wrappedToken or
|
|
20
|
+
// wrappedToken[swap]wrappedToken[unwrap]token
|
|
21
|
+
return PARTIAL_BOOSTED_SWAP_GAS_COST;
|
|
22
|
+
} else if (steps.length === 3) {
|
|
23
|
+
// Full boosted/buffer swap: token[wrap]wrappedToken[swap]wrappedToken[unwrap]token
|
|
24
|
+
return FULL_BOOSTED_SWAP_GAS_COST;
|
|
25
|
+
} else {
|
|
26
|
+
switch (steps[0].poolState.poolType) {
|
|
27
|
+
case 'WEIGHTED':
|
|
28
|
+
return WEIGHTED_GAS_COST;
|
|
29
|
+
case 'STABLE':
|
|
30
|
+
return STABLE_GAS_COST;
|
|
31
|
+
case 'BUFFER':
|
|
32
|
+
return BUFFER_WRAP_UNWRAP_GAS_COST;
|
|
33
|
+
default:
|
|
34
|
+
return WEIGHTED_GAS_COST;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|