@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,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.decodeThrowError = decodeThrowError;
|
|
7
|
+
exports.getOnChainState = getOnChainState;
|
|
8
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
9
|
+
const config_1 = require("./config");
|
|
10
|
+
// Encoding & Decoding for onchain calls to fetch mutable pool data
|
|
11
|
+
// Each supported pool type should have its own specific calls if needed
|
|
12
|
+
const poolOnChain = {
|
|
13
|
+
['COMMON']: {
|
|
14
|
+
count: 6,
|
|
15
|
+
['encode']: (network, contractInterface, address) => {
|
|
16
|
+
return [
|
|
17
|
+
{
|
|
18
|
+
target: config_1.BalancerV3Config.BalancerV3[network].vaultAddress,
|
|
19
|
+
callData: contractInterface.encodeFunctionData('getPoolTokenRates', [
|
|
20
|
+
address,
|
|
21
|
+
]),
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
target: config_1.BalancerV3Config.BalancerV3[network].vaultAddress,
|
|
25
|
+
callData: contractInterface.encodeFunctionData('getCurrentLiveBalances', [address]),
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
target: config_1.BalancerV3Config.BalancerV3[network].vaultAddress,
|
|
29
|
+
callData: contractInterface.encodeFunctionData('getPoolConfig', [
|
|
30
|
+
address,
|
|
31
|
+
]),
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
target: config_1.BalancerV3Config.BalancerV3[network].vaultAddress,
|
|
35
|
+
callData: contractInterface.encodeFunctionData('totalSupply', [
|
|
36
|
+
address,
|
|
37
|
+
]),
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
target: config_1.BalancerV3Config.BalancerV3[network].vaultAddress,
|
|
41
|
+
callData: contractInterface.encodeFunctionData('isPoolPaused', [
|
|
42
|
+
address,
|
|
43
|
+
]),
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
target: config_1.BalancerV3Config.BalancerV3[network].vaultAddress,
|
|
47
|
+
callData: contractInterface.encodeFunctionData('getHooksConfig', [
|
|
48
|
+
address,
|
|
49
|
+
]),
|
|
50
|
+
},
|
|
51
|
+
];
|
|
52
|
+
},
|
|
53
|
+
['decode']: (contractInterface, poolAddress, data, startIndex) => {
|
|
54
|
+
const resultTokenRates = decodeThrowError(contractInterface, 'getPoolTokenRates', data[startIndex++], poolAddress);
|
|
55
|
+
if (!resultTokenRates)
|
|
56
|
+
throw new Error(`Failed to get result for getPoolTokenRates for ${poolAddress}`);
|
|
57
|
+
const resultLiveBalances = decodeThrowError(contractInterface, 'getCurrentLiveBalances', data[startIndex++], poolAddress);
|
|
58
|
+
if (!resultLiveBalances)
|
|
59
|
+
throw new Error(`Failed to get result for getCurrentLiveBalances for ${poolAddress}`);
|
|
60
|
+
const resultGetPoolConfig = decodeThrowError(contractInterface, 'getPoolConfig', data[startIndex++], poolAddress);
|
|
61
|
+
if (!resultGetPoolConfig)
|
|
62
|
+
throw new Error(`Failed to get result for getPoolConfig for ${poolAddress}`);
|
|
63
|
+
const resultTotalSupply = decodeThrowError(contractInterface, 'totalSupply', data[startIndex++], poolAddress);
|
|
64
|
+
if (!resultTotalSupply)
|
|
65
|
+
throw new Error(`Failed to get result for totalSupply for ${poolAddress}`);
|
|
66
|
+
const resultIsPoolPaused = decodeThrowError(contractInterface, 'isPoolPaused', data[startIndex++], poolAddress);
|
|
67
|
+
if (!resultIsPoolPaused)
|
|
68
|
+
throw new Error(`Failed to get result for isPoolPaused for ${poolAddress}`);
|
|
69
|
+
const resultHooksConfig = decodeThrowError(contractInterface, 'getHooksConfig', data[startIndex++], poolAddress);
|
|
70
|
+
if (!resultHooksConfig)
|
|
71
|
+
throw new Error(`Failed to get result for resultHooksConfig for ${poolAddress}`);
|
|
72
|
+
return {
|
|
73
|
+
tokenRates: resultTokenRates.tokenRates.map((r) => BigInt(r)),
|
|
74
|
+
balancesLiveScaled18: resultLiveBalances.balancesLiveScaled18.map((b) => BigInt(b)),
|
|
75
|
+
swapFee: BigInt(resultGetPoolConfig[0].staticSwapFeePercentage),
|
|
76
|
+
aggregateSwapFee: BigInt(resultGetPoolConfig[0].aggregateSwapFeePercentage),
|
|
77
|
+
totalSupply: BigInt(resultTotalSupply[0]),
|
|
78
|
+
scalingFactors: resultTokenRates.decimalScalingFactors.map((r) => BigInt(r)),
|
|
79
|
+
isPoolPaused: resultIsPoolPaused[0],
|
|
80
|
+
hasHook: resultHooksConfig[0].hooksContract !==
|
|
81
|
+
'0x0000000000000000000000000000000000000000',
|
|
82
|
+
};
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
['WEIGHTED']: {
|
|
86
|
+
count: 0,
|
|
87
|
+
['encode']: (network, contractInterface, address) => {
|
|
88
|
+
return [];
|
|
89
|
+
},
|
|
90
|
+
['decode']: (contractInterface, poolAddress, data, startIndex) => {
|
|
91
|
+
return {};
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
['STABLE']: {
|
|
95
|
+
count: 2,
|
|
96
|
+
['encode']: (network, contractInterface, address) => {
|
|
97
|
+
return [
|
|
98
|
+
{
|
|
99
|
+
target: address,
|
|
100
|
+
callData: contractInterface.encodeFunctionData('getAmplificationParameter'),
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
target: address,
|
|
104
|
+
callData: contractInterface.encodeFunctionData('getAmplificationState'),
|
|
105
|
+
},
|
|
106
|
+
];
|
|
107
|
+
},
|
|
108
|
+
['decode']: (contractInterface, poolAddress, data, startIndex) => {
|
|
109
|
+
const resultAmp = decodeThrowError(contractInterface, 'getAmplificationParameter', data[startIndex++], poolAddress);
|
|
110
|
+
if (!resultAmp)
|
|
111
|
+
throw new Error(`Failed to get result for getAmplificationParameter for ${poolAddress}`);
|
|
112
|
+
const resultAmpState = decodeThrowError(contractInterface, 'getAmplificationState', data[startIndex++], poolAddress);
|
|
113
|
+
if (!resultAmpState)
|
|
114
|
+
throw new Error(`Failed to get result for getAmplificationState for ${poolAddress}`);
|
|
115
|
+
return {
|
|
116
|
+
amp: resultAmp[0].toBigInt(),
|
|
117
|
+
ampIsUpdating: !!resultAmp[1],
|
|
118
|
+
ampStartValue: resultAmpState[0][0].toBigInt(),
|
|
119
|
+
ampEndValue: resultAmpState[0][1].toBigInt(),
|
|
120
|
+
ampStartTime: BigInt(resultAmpState[0][2]),
|
|
121
|
+
ampStopTime: BigInt(resultAmpState[0][3]),
|
|
122
|
+
};
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
function decodeThrowError(contractInterface, functionName, resultEntry, poolAddress) {
|
|
127
|
+
if (!resultEntry.success)
|
|
128
|
+
throw new Error(`Failed to execute ${functionName} for ${poolAddress}`);
|
|
129
|
+
return contractInterface.decodeFunctionResult(functionName, resultEntry.returnData);
|
|
130
|
+
}
|
|
131
|
+
// Any data from API will be immutable. Mutable data such as balances, etc will be fetched via onchain/event state.
|
|
132
|
+
async function getOnChainState(network, immutablePoolStateMap, dexHelper, interfaces, blockNumber) {
|
|
133
|
+
const multiCallData = Object.entries(immutablePoolStateMap)
|
|
134
|
+
.map(([address, pool]) => {
|
|
135
|
+
return [
|
|
136
|
+
...poolOnChain['COMMON'].encode(network, interfaces['VAULT'], address),
|
|
137
|
+
...poolOnChain[pool.poolType].encode(network, interfaces[pool.poolType], address),
|
|
138
|
+
];
|
|
139
|
+
})
|
|
140
|
+
.flat();
|
|
141
|
+
// 500 is an arbitrary number chosen based on the blockGasLimit
|
|
142
|
+
const slicedMultiCallData = lodash_1.default.chunk(multiCallData, 500);
|
|
143
|
+
const multicallData = (await Promise.all(slicedMultiCallData.map(async (_multiCallData) => dexHelper.multiContract.methods
|
|
144
|
+
.tryAggregate(false, _multiCallData)
|
|
145
|
+
.call({}, blockNumber)))).flat();
|
|
146
|
+
let i = 0;
|
|
147
|
+
const poolStateMap = Object.fromEntries(Object.entries(immutablePoolStateMap).map(([address, pool]) => {
|
|
148
|
+
const commonMutableData = poolOnChain['COMMON'].decode(interfaces['VAULT'], address, multicallData, i);
|
|
149
|
+
i = i + poolOnChain['COMMON'].count;
|
|
150
|
+
const poolMutableData = poolOnChain[pool.poolType].decode(interfaces[pool.poolType], address, multicallData, i);
|
|
151
|
+
i = i + poolOnChain[pool.poolType].count;
|
|
152
|
+
return [
|
|
153
|
+
address,
|
|
154
|
+
{
|
|
155
|
+
...pool,
|
|
156
|
+
...commonMutableData,
|
|
157
|
+
...poolMutableData,
|
|
158
|
+
},
|
|
159
|
+
];
|
|
160
|
+
}));
|
|
161
|
+
return poolStateMap;
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=getOnChainState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getOnChainState.js","sourceRoot":"","sources":["../../../src/dex/balancer-v3/getOnChainState.ts"],"names":[],"mappings":";;;;;AAuPA,4CAYC;AAGD,0CA+DC;AArUD,oDAAuB;AAOvB,qCAA4C;AAS5C,mEAAmE;AACnE,wEAAwE;AACxE,MAAM,WAAW,GAgBb;IACF,CAAC,QAAQ,CAAC,EAAE;QACV,KAAK,EAAE,CAAC;QACR,CAAC,QAAQ,CAAC,EAAE,CACV,OAAe,EACf,iBAA4B,EAC5B,OAAe,EACH,EAAE;YACd,OAAO;gBACL;oBACE,MAAM,EAAE,yBAAgB,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,YAAY;oBACzD,QAAQ,EAAE,iBAAiB,CAAC,kBAAkB,CAAC,mBAAmB,EAAE;wBAClE,OAAO;qBACR,CAAC;iBACH;gBACD;oBACE,MAAM,EAAE,yBAAgB,C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WAAW,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC;QACpC,MAAM,eAAe,GAAG,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,CACvD,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,EACzB,OAAO,EACP,aAAa,EACb,CAAC,CACF,CAAC;QACF,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC;QACzC,OAAO;YACL,OAAO;YACP;gBACE,GAAG,IAAI;gBACP,GAAG,iBAAiB;gBACpB,GAAG,eAAe;aACnB;SACF,CAAC;IACJ,CAAC,CAAC,CACH,CAAC;IACF,OAAO,YAAY,CAAC;AACtB,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getPoolsApi = getPoolsApi;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const config_1 = require("./config");
|
|
9
|
+
const utils_1 = require("ethers/lib/utils");
|
|
10
|
+
function createQuery(networkId, poolTypes, timestamp) {
|
|
11
|
+
const poolTypesString = poolTypes.map(type => `${type}`).join(', ');
|
|
12
|
+
const networkString = config_1.BalancerV3Config.BalancerV3[networkId].apiNetworkName;
|
|
13
|
+
const disabledPoolIdsString = config_1.disabledPoolIds.BalancerV3[networkId]
|
|
14
|
+
?.map(p => `"${p}"`)
|
|
15
|
+
.join(', ');
|
|
16
|
+
// Build the where clause conditionally
|
|
17
|
+
const whereClause = {
|
|
18
|
+
chainIn: networkString,
|
|
19
|
+
protocolVersionIn: 3,
|
|
20
|
+
hasHook: false,
|
|
21
|
+
poolTypeIn: `[${poolTypesString}]`,
|
|
22
|
+
...(timestamp && { createTime: `{lt: ${timestamp}}` }),
|
|
23
|
+
...(disabledPoolIdsString && { idNotIn: `[${disabledPoolIdsString}]` }),
|
|
24
|
+
};
|
|
25
|
+
// Convert where clause to string, filtering out undefined values
|
|
26
|
+
const whereString = Object.entries(whereClause)
|
|
27
|
+
.map(([key, value]) => `${key}: ${value}`)
|
|
28
|
+
.join(', ');
|
|
29
|
+
return `
|
|
30
|
+
query MyQuery {
|
|
31
|
+
poolGetAggregatorPools(
|
|
32
|
+
where: {${whereString}}
|
|
33
|
+
) {
|
|
34
|
+
id
|
|
35
|
+
type
|
|
36
|
+
poolTokens {
|
|
37
|
+
address
|
|
38
|
+
weight
|
|
39
|
+
isErc4626
|
|
40
|
+
underlyingToken {
|
|
41
|
+
address
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
`;
|
|
47
|
+
}
|
|
48
|
+
function toImmutablePoolStateMap(pools) {
|
|
49
|
+
return pools.reduce((map, pool) => {
|
|
50
|
+
const immutablePoolState = {
|
|
51
|
+
poolAddress: pool.id,
|
|
52
|
+
tokens: pool.poolTokens.map(t => t.address),
|
|
53
|
+
tokensUnderlying: pool.poolTokens.map(t => t.underlyingToken ? t.underlyingToken.address : null),
|
|
54
|
+
weights: pool.poolTokens.map(t => t.weight ? (0, utils_1.parseUnits)(t.weight, 18).toBigInt() : 0n),
|
|
55
|
+
poolType: pool.type,
|
|
56
|
+
// TODO add scalingFactors once API provides them
|
|
57
|
+
// scalingFactors: pool.poolTokens.map(t => parseUnits('1', 18).toBigInt()),
|
|
58
|
+
// TODO Hook support will be added in future PR
|
|
59
|
+
hookType: undefined,
|
|
60
|
+
};
|
|
61
|
+
map[pool.id] = immutablePoolState;
|
|
62
|
+
return map;
|
|
63
|
+
}, {});
|
|
64
|
+
}
|
|
65
|
+
// Any data from API will be immutable. Mutable data such as balances, etc will be fetched via onchain/event state.
|
|
66
|
+
async function getPoolsApi(network, timestamp) {
|
|
67
|
+
try {
|
|
68
|
+
const query = createQuery(network, Object.values(config_1.SUPPORTED_POOLS), timestamp);
|
|
69
|
+
const response = await axios_1.default.post(config_1.apiUrl, {
|
|
70
|
+
query,
|
|
71
|
+
}, {
|
|
72
|
+
headers: {
|
|
73
|
+
'Content-Type': 'application/json',
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
const pools = response.data.data.poolGetAggregatorPools;
|
|
77
|
+
return toImmutablePoolStateMap(pools);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
// console.error('Error executing GraphQL query:', error);
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=getPoolsApi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPoolsApi.js","sourceRoot":"","sources":["../../../src/dex/balancer-v3/getPoolsApi.ts"],"names":[],"mappings":";;;;;AAoGA,kCA4BC;AAhID,kDAA0B;AAC1B,qCAKkB;AAElB,4CAA8C;AAuB9C,SAAS,WAAW,CAClB,SAAiB,EACjB,SAA4B,EAC5B,SAAkB;IAElB,MAAM,eAAe,GAAG,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpE,MAAM,aAAa,GAAG,yBAAgB,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,cAAc,CAAC;IAC5E,MAAM,qBAAqB,GAAG,wBAAe,CAAC,UAAU,CAAC,SAAS,CAAC;QACjE,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC;SACnB,IAAI,CAAC,IAAI,CAAC,CAAC;IAEd,uCAAuC;IACvC,MAAM,WAAW,GAAG;QAClB,OAAO,EAAE,aAAa;QACtB,iBAAiB,EAAE,CAAC;QACpB,OAAO,EAAE,KAAK;QACd,UAAU,EAAE,IAAI,eAAe,GAAG;QAClC,GAAG,CAAC,SAAS,IAAI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CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,kBAAkB,CAAC;QAClC,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAA2B,CAAC,CAAC;AAClC,CAAC;AAED,mHAAmH;AAC5G,KAAK,UAAU,WAAW,CAC/B,OAAe,EACf,SAAkB;IAElB,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,WAAW,CACvB,OAAO,EACP,MAAM,CAAC,MAAM,CAAC,wBAAe,CAAC,EAC9B,SAAS,CACV,CAAC;QACF,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,IAAI,CAC/B,eAAM,EACN;YACE,KAAK;SACN,EACD;YACE,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;aACnC;SACF,CACF,CAAC;QAEF,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC;QACxD,OAAO,uBAAuB,CAAC,KAAK,CAAC,CAAC;IACxC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,0DAA0D;QAC1D,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
interface PoolToken {
|
|
2
|
+
address: string;
|
|
3
|
+
decimals: number;
|
|
4
|
+
underlyingToken?: {
|
|
5
|
+
address: string;
|
|
6
|
+
decimals: number;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export interface Pool {
|
|
10
|
+
address: string;
|
|
11
|
+
poolTokens: PoolToken[];
|
|
12
|
+
dynamicData: {
|
|
13
|
+
totalLiquidity: string;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export declare function getTopPoolsApi(networkId: number, poolsFilter: string[], count: number): Promise<Pool[]>;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getTopPoolsApi = getTopPoolsApi;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const config_1 = require("./config");
|
|
9
|
+
function createQuery(networkId, poolsFilter, count) {
|
|
10
|
+
const networkString = config_1.BalancerV3Config.BalancerV3[networkId].apiNetworkName;
|
|
11
|
+
const poolIdString = poolsFilter.map(a => `"${a}"`).join(', ');
|
|
12
|
+
// Build the where clause conditionally
|
|
13
|
+
const whereClause = {
|
|
14
|
+
chainIn: networkString,
|
|
15
|
+
protocolVersionIn: 3,
|
|
16
|
+
hasHook: false,
|
|
17
|
+
idIn: `[${poolIdString}]`,
|
|
18
|
+
};
|
|
19
|
+
// Convert where clause to string, filtering out undefined values
|
|
20
|
+
const whereString = Object.entries(whereClause)
|
|
21
|
+
.map(([key, value]) => `${key}: ${value}`)
|
|
22
|
+
.join(', ');
|
|
23
|
+
return `
|
|
24
|
+
query MyQuery {
|
|
25
|
+
poolGetAggregatorPools(
|
|
26
|
+
where: {${whereString}}
|
|
27
|
+
first: ${count}
|
|
28
|
+
orderBy: totalLiquidity
|
|
29
|
+
orderDirection: desc
|
|
30
|
+
) {
|
|
31
|
+
address
|
|
32
|
+
poolTokens {
|
|
33
|
+
address
|
|
34
|
+
decimals
|
|
35
|
+
underlyingToken {
|
|
36
|
+
address
|
|
37
|
+
decimals
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
dynamicData {
|
|
41
|
+
totalLiquidity
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
`;
|
|
46
|
+
}
|
|
47
|
+
async function getTopPoolsApi(networkId, poolsFilter, count) {
|
|
48
|
+
try {
|
|
49
|
+
const query = createQuery(networkId, poolsFilter, count);
|
|
50
|
+
const response = await axios_1.default.post(config_1.apiUrl, {
|
|
51
|
+
query,
|
|
52
|
+
}, {
|
|
53
|
+
headers: {
|
|
54
|
+
'Content-Type': 'application/json',
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
const pools = response.data.data.poolGetAggregatorPools;
|
|
58
|
+
return pools;
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
// console.error('Error executing GraphQL query:', error);
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=getTopPoolsApi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTopPoolsApi.js","sourceRoot":"","sources":["../../../src/dex/balancer-v3/getTopPoolsApi.ts"],"names":[],"mappings":";;;;;AAsEA,wCAyBC;AA/FD,kDAA0B;AAC1B,qCAAoD;AAyBpD,SAAS,WAAW,CAClB,SAAiB,EACjB,WAAqB,EACrB,KAAa;IAEb,MAAM,aAAa,GAAG,yBAAgB,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,cAAc,CAAC;IAC5E,MAAM,YAAY,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/D,uCAAuC;IACvC,MAAM,WAAW,GAAG;QAClB,OAAO,EAAE,aAAa;QACtB,iBAAiB,EAAE,CAAC;QACpB,OAAO,EAAE,KAAK;QACd,IAAI,EAAE,IAAI,YAAY,GAAG;KAC1B,CAAC;IAEF,iEAAiE;IACjE,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC;SAC5C,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,KAAK,KAAK,EAAE,CAAC;SACzC,IAAI,CAAC,IAAI,CAAC,CAAC;IACd,OAAO;;;kBAGS,WAAW;iBACZ,KAAK;;;;;;;;;;;;;;;;;;GAkBnB,CAAC;AACJ,CAAC;AAEM,KAAK,UAAU,cAAc,CAClC,SAAiB,EACjB,WAAqB,EACrB,KAAa;IAEb,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,WAAW,CAAC,SAAS,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;QACzD,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,IAAI,CAC/B,eAAM,EACN;YACE,KAAK;SACN,EACD;YACE,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;aACnC;SACF,CACF,CAAC;QAEF,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC;QACxD,OAAO,KAAK,CAAC;IACf,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,0DAA0D;QAC1D,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.balancerV3Merge = balancerV3Merge;
|
|
7
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
+
function balancerV3Merge(or) {
|
|
9
|
+
const fixRoute = (rawRate) => {
|
|
10
|
+
let lastExchange = false;
|
|
11
|
+
let optimizedRate = new Array();
|
|
12
|
+
rawRate.forEach((s) => {
|
|
13
|
+
if (s.swapExchanges.length !== 1 ||
|
|
14
|
+
s.swapExchanges[0].exchange.toLowerCase() !== 'balancerv3') {
|
|
15
|
+
lastExchange = false;
|
|
16
|
+
optimizedRate.push(s);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (lastExchange &&
|
|
20
|
+
lastExchange.swapExchanges[0].exchange.toLowerCase() ===
|
|
21
|
+
s.swapExchanges[0].exchange.toLowerCase() &&
|
|
22
|
+
lodash_1.default.last(lastExchange.swapExchanges[0].data.steps).swapInput.tokenOut.toLowerCase() ===
|
|
23
|
+
s.swapExchanges[0].data.steps[0].swapInput.tokenIn.toLowerCase()) {
|
|
24
|
+
lastExchange.swapExchanges[0].data.steps =
|
|
25
|
+
lastExchange.swapExchanges[0].data.steps.concat(s.swapExchanges[0].data.steps);
|
|
26
|
+
lastExchange.swapExchanges[0].poolAddresses =
|
|
27
|
+
lastExchange.swapExchanges[0].poolAddresses.concat(s.swapExchanges[0].poolAddresses);
|
|
28
|
+
lastExchange.swapExchanges[0].data.gasUSD = (parseFloat(lastExchange.swapExchanges[0].data.gasUSD) +
|
|
29
|
+
parseFloat(s.swapExchanges[0].data.gasUSD)).toFixed(6);
|
|
30
|
+
lastExchange.destToken = s.destToken;
|
|
31
|
+
lastExchange.destDecimals = s.destDecimals;
|
|
32
|
+
lastExchange.swapExchanges[0].destAmount =
|
|
33
|
+
s.swapExchanges[0].destAmount;
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
lastExchange = lodash_1.default.cloneDeep(s);
|
|
37
|
+
optimizedRate.push(lastExchange);
|
|
38
|
+
});
|
|
39
|
+
return optimizedRate;
|
|
40
|
+
};
|
|
41
|
+
or.bestRoute = or.bestRoute.map(r => ({
|
|
42
|
+
...r,
|
|
43
|
+
swaps: fixRoute(r.swaps),
|
|
44
|
+
}));
|
|
45
|
+
return or;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=optimizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"optimizer.js","sourceRoot":"","sources":["../../../src/dex/balancer-v3/optimizer.ts"],"names":[],"mappings":";;;;;AAGA,0CA8DC;AAhED,oDAAuB;AAEvB,SAAgB,eAAe,CAAC,EAAmB;IACjD,MAAM,QAAQ,GAAG,CAAC,OAAsB,EAAiB,EAAE;QACzD,IAAI,YAAY,GAAwB,KAAK,CAAC;QAE9C,IAAI,aAAa,GAAG,IAAI,KAAK,EAAe,CAAC;QAE7C,OAAO,CAAC,OAAO,CAAC,CAAC,CAAc,EAAE,EAAE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a,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;oBACrD,UAAU,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAC3C,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;gBAEb,YAAY,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC;gBACrC,YAAY,CAAC,YAAY,GAAG,CAAC,CAAC,YAAY,CAAC;gBAE3C,YAAY,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,UAAU;oBACtC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;gBAEhC,OAAO;YACT,CAAC;YAED,YAAY,GAAG,gBAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;YAC9B,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;QAEH,OAAO,aAAa,CAAC;IACvB,CAAC,CAAC;IAEF,EAAE,CAAC,SAAS,GAAG,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACpC,GAAG,CAAC;QACJ,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC;KACzB,CAAC,CAAC,CAAC;IAEJ,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PoolState } from '@balancer-labs/balancer-maths';
|
|
2
|
+
import { StableMutableState } from './types';
|
|
3
|
+
export declare const STABLE_GAS_COST = 155000;
|
|
4
|
+
export declare function isStableMutableState(poolState: any): poolState is StableMutableState;
|
|
5
|
+
export declare function getAmplificationParameter(startValue: bigint, endValue: bigint, startTime: bigint, endTime: bigint, timestamp: bigint): bigint;
|
|
6
|
+
export declare function ampUpdateStartedEvent(poolState: PoolState, eventData: any): void;
|
|
7
|
+
export declare function ampUpdateStoppedEvent(poolState: PoolState, eventData: any): void;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.STABLE_GAS_COST = void 0;
|
|
4
|
+
exports.isStableMutableState = isStableMutableState;
|
|
5
|
+
exports.getAmplificationParameter = getAmplificationParameter;
|
|
6
|
+
exports.ampUpdateStartedEvent = ampUpdateStartedEvent;
|
|
7
|
+
exports.ampUpdateStoppedEvent = ampUpdateStoppedEvent;
|
|
8
|
+
const abi_1 = require("@ethersproject/abi");
|
|
9
|
+
// TODO - Update with more accurate
|
|
10
|
+
exports.STABLE_GAS_COST = 155000;
|
|
11
|
+
function isStableMutableState(poolState) {
|
|
12
|
+
return (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
|
+
// https://github.com/balancer/balancer-v3-monorepo/blob/009f2793abda248b150ccd15c1db25930c96ca82/pkg/pool-stable/contracts/StablePool.sol#L274
|
|
22
|
+
function getAmplificationParameter(startValue, endValue, startTime, endTime, timestamp) {
|
|
23
|
+
let value;
|
|
24
|
+
if (timestamp < endTime) {
|
|
25
|
+
if (endValue > startValue) {
|
|
26
|
+
value =
|
|
27
|
+
startValue +
|
|
28
|
+
((endValue - startValue) * (timestamp - startTime)) /
|
|
29
|
+
(endTime - startTime);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
value =
|
|
33
|
+
startValue -
|
|
34
|
+
((startValue - endValue) * (timestamp - startTime)) /
|
|
35
|
+
(endTime - startTime);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
value = endValue;
|
|
40
|
+
}
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
function ampUpdateStartedEvent(poolState, eventData) {
|
|
44
|
+
// abi.encode(currentValueUint64, endValueUint64, startTimeUint32, endTimeUint32)
|
|
45
|
+
const decodedParams = abi_1.defaultAbiCoder.decode(['uint64', 'uint64', 'uint32', 'uint32'], eventData);
|
|
46
|
+
if (isStableMutableState(poolState)) {
|
|
47
|
+
if (decodedParams[3] > decodedParams[2])
|
|
48
|
+
poolState.ampIsUpdating = true;
|
|
49
|
+
poolState.ampStartValue = decodedParams[0].toBigInt();
|
|
50
|
+
poolState.ampEndValue = decodedParams[1].toBigInt();
|
|
51
|
+
poolState.ampStartTime = BigInt(decodedParams[2]);
|
|
52
|
+
poolState.ampStopTime = BigInt(decodedParams[3]);
|
|
53
|
+
}
|
|
54
|
+
else
|
|
55
|
+
throw new Error("Can't update amp on non-stable pool");
|
|
56
|
+
}
|
|
57
|
+
function ampUpdateStoppedEvent(poolState, eventData) {
|
|
58
|
+
// abi.encode(currentValue)
|
|
59
|
+
const decodedParams = abi_1.defaultAbiCoder.decode(['uint256'], eventData);
|
|
60
|
+
if (isStableMutableState(poolState)) {
|
|
61
|
+
poolState.ampIsUpdating = false;
|
|
62
|
+
poolState.amp = decodedParams[0].toBigInt();
|
|
63
|
+
poolState.ampStartValue = decodedParams[0].toBigInt();
|
|
64
|
+
poolState.ampEndValue = decodedParams[0].toBigInt();
|
|
65
|
+
// In Contract these are update to timestamp event is called.
|
|
66
|
+
// There doesn't appear to be a way to easily get timestamp non-async so default to 0n which should have no effect
|
|
67
|
+
poolState.ampStartTime = BigInt(0n);
|
|
68
|
+
poolState.ampStopTime = BigInt(0n);
|
|
69
|
+
}
|
|
70
|
+
else
|
|
71
|
+
throw new Error("Can't update amp on non-stable pool");
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=stablePool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stablePool.js","sourceRoot":"","sources":["../../../src/dex/balancer-v3/stablePool.ts"],"names":[],"mappings":";;;AAOA,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CAAC;AAChE,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { BufferState } from '@balancer-labs/balancer-maths';
|
|
2
|
+
import { Address } from '../../types';
|
|
3
|
+
export type CommonImmutablePoolState = {
|
|
4
|
+
poolAddress: string;
|
|
5
|
+
poolType: string;
|
|
6
|
+
tokens: string[];
|
|
7
|
+
tokensUnderlying: (string | null)[];
|
|
8
|
+
weights: bigint[];
|
|
9
|
+
hookType: string | undefined;
|
|
10
|
+
};
|
|
11
|
+
export interface CommonMutableState {
|
|
12
|
+
tokenRates: bigint[];
|
|
13
|
+
balancesLiveScaled18: bigint[];
|
|
14
|
+
swapFee: bigint;
|
|
15
|
+
aggregateSwapFee: bigint;
|
|
16
|
+
totalSupply: bigint;
|
|
17
|
+
isPoolPaused: boolean;
|
|
18
|
+
scalingFactors: bigint[];
|
|
19
|
+
hasHook: boolean;
|
|
20
|
+
}
|
|
21
|
+
type CommonPoolState = CommonImmutablePoolState & CommonMutableState;
|
|
22
|
+
export type PoolState = CommonPoolState | (CommonPoolState & StableMutableState);
|
|
23
|
+
export interface StableMutableState {
|
|
24
|
+
amp: bigint;
|
|
25
|
+
ampIsUpdating: boolean;
|
|
26
|
+
ampStartValue: bigint;
|
|
27
|
+
ampEndValue: bigint;
|
|
28
|
+
ampStartTime: bigint;
|
|
29
|
+
ampStopTime: bigint;
|
|
30
|
+
}
|
|
31
|
+
export type PoolStateMap = {
|
|
32
|
+
[address: string]: PoolState;
|
|
33
|
+
};
|
|
34
|
+
export type ImmutablePoolStateMap = {
|
|
35
|
+
[address: string]: CommonImmutablePoolState;
|
|
36
|
+
};
|
|
37
|
+
export type Step = {
|
|
38
|
+
pool: Address;
|
|
39
|
+
isBuffer: boolean;
|
|
40
|
+
swapInput: {
|
|
41
|
+
tokenIn: Address;
|
|
42
|
+
tokenOut: Address;
|
|
43
|
+
};
|
|
44
|
+
poolState: PoolState | BufferState;
|
|
45
|
+
};
|
|
46
|
+
export type BalancerV3Data = {
|
|
47
|
+
steps: Step[];
|
|
48
|
+
};
|
|
49
|
+
export type DexParams = {
|
|
50
|
+
apiNetworkName: string;
|
|
51
|
+
vaultAddress: string;
|
|
52
|
+
balancerRouterAddress: string;
|
|
53
|
+
balancerBatchRouterAddress: string;
|
|
54
|
+
};
|
|
55
|
+
export type TokenInfo = {
|
|
56
|
+
isBoosted: boolean;
|
|
57
|
+
underlyingToken: string | null;
|
|
58
|
+
mainToken: string;
|
|
59
|
+
index: number;
|
|
60
|
+
rate: bigint;
|
|
61
|
+
};
|
|
62
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/dex/balancer-v3/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const WEIGHTED_GAS_COST = 154000;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WEIGHTED_GAS_COST = void 0;
|
|
4
|
+
// https://sepolia.etherscan.io/tx/0xe07958ff341aab57ab96a10347b65979b5b041f6408336d7e160e59bd02f9a40
|
|
5
|
+
exports.WEIGHTED_GAS_COST = 154000;
|
|
6
|
+
//# sourceMappingURL=weightedPool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"weightedPool.js","sourceRoot":"","sources":["../../../src/dex/balancer-v3/weightedPool.ts"],"names":[],"mappings":";;;AAAA,qGAAqG;AACxF,QAAA,iBAAiB,GAAG,MAAM,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Interface } from '@ethersproject/abi';
|
|
2
|
+
import { SwapSide } from '../constants';
|
|
3
|
+
import { AdapterExchangeParam, Address, SimpleExchangeParam } from '../types';
|
|
4
|
+
import { IDexTxBuilder } from './idex';
|
|
5
|
+
import { SimpleExchange } from './simple-exchange';
|
|
6
|
+
import { IDexHelper } from '../dex-helper';
|
|
7
|
+
export declare type BancorData = {
|
|
8
|
+
minDestToken: string;
|
|
9
|
+
path: Address[];
|
|
10
|
+
bancorNetwork?: string;
|
|
11
|
+
};
|
|
12
|
+
declare type BancorParam = [
|
|
13
|
+
path: Address[],
|
|
14
|
+
srcAmount: string,
|
|
15
|
+
minDestToken: string,
|
|
16
|
+
affiliateAccount: string,
|
|
17
|
+
affiliateFee: string
|
|
18
|
+
];
|
|
19
|
+
export declare class Bancor extends SimpleExchange implements IDexTxBuilder<BancorData, BancorParam> {
|
|
20
|
+
static dexKeys: string[];
|
|
21
|
+
exchangeRouterInterface: Interface;
|
|
22
|
+
constructor(dexHelper: IDexHelper);
|
|
23
|
+
getAdapterParam(srcToken: string, destToken: string, srcAmount: string, destAmount: string, data: BancorData, side: SwapSide): AdapterExchangeParam;
|
|
24
|
+
getSimpleParam(srcToken: string, destToken: string, srcAmount: string, destAmount: string, data: BancorData, side: SwapSide): Promise<SimpleExchangeParam>;
|
|
25
|
+
}
|
|
26
|
+
export {};
|