@paraswap/dex-lib 4.1.9 → 4.1.10-ekubo
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/build/abi/AaveV1_lending_pool.json +27 -0
- package/build/abi/Aave_GSM.json +751 -0
- package/build/abi/Balancer.json +257 -0
- package/build/abi/BalancerV2.json +1179 -0
- package/build/abi/RamsesV2Pool.abi.json +1554 -0
- package/build/abi/RamsesV2Quoter.abi.json +274 -0
- package/build/abi/USDM.json +807 -0
- package/build/abi/UniswapV2Router.json +397 -0
- package/build/abi/angle-transmuter/ChainlinkAccessControlledOffchainAggregator.json +1246 -0
- package/build/abi/angle-transmuter/ChainlinkEACAggregatorProxy.json +509 -0
- package/build/abi/curve-v1/CurveBUSDv2.abi.json +1356 -0
- package/build/abi/curve-v1/CurveTokenV1.json +305 -0
- package/build/abi/curve-v1/CurveTokenV2.json +318 -0
- package/build/abi/curve-v1/CurveV1StableNg.json +1452 -0
- package/build/abi/curve-v1/CurveV2Swap.json +700 -0
- package/build/abi/curve-v1/FactoryCryptoRegistry.json +316 -0
- package/build/abi/curve-v1/FactoryRegistry.json +508 -0
- package/build/abi/curve-v1/StableSwapAave.json +1152 -0
- package/build/abi/curve-v1/StableSwapBUSD.json +814 -0
- package/build/abi/curve-v1/StableSwapCompound.json +814 -0
- package/build/abi/curve-v1/StableSwapIDLE.json +1253 -0
- package/build/abi/curve-v1/StableSwapPax.json +865 -0
- package/build/abi/curve-v1/StableSwapSnow.json +900 -0
- package/build/abi/curve-v1/StableSwapUSDN.json +1004 -0
- package/build/abi/curve-v1/StableSwapUSDT.json +814 -0
- package/build/abi/curve-v1/StableSwapY.json +814 -0
- package/build/abi/ekubo/core.json +1266 -0
- package/build/abi/ekubo/data-fetcher.json +161 -0
- package/build/abi/ekubo/router.json +803 -0
- package/build/abi/inception/inception-ineth-pool.json +1062 -0
- package/build/abi/inception/inception-ineth.json +609 -0
- package/build/abi/inception/inception-ratio-feed.json +329 -0
- package/build/abi/inception/inception-vault.json +991 -0
- package/build/abi/kyberdmm/kyber-storage.abi.json +824 -0
- package/build/abi/kyberdmm.abi.json +1148 -0
- package/build/abi/maverick-v2/MaverickV2Quoter.json +278 -0
- package/build/abi/nerve/nerve-metapool.json +790 -0
- package/build/abi/platypus/asset.json +490 -0
- package/build/abi/platypus/avax-pool.json +820 -0
- package/build/abi/platypus/oracle.json +119 -0
- package/build/abi/platypus/pool.json +677 -0
- package/build/abi/smardex/all/smardex-router.json +648 -0
- package/build/abi/smardex/layer-1/smardex-factory.json +242 -0
- package/build/abi/smardex/layer-1/smardex-pool.json +506 -0
- package/build/abi/smardex/layer-2/smardex-factory.json +185 -0
- package/build/abi/smardex/layer-2/smardex-pool.json +578 -0
- package/build/abi/swaap-v1/pool.json +1346 -0
- package/build/abi/uniswap-v3/UniswapV3Quoter.abi.json +193 -0
- package/build/abi/velodrome-slipstream/VelodromeSlipstreamQuoterV2.abi.json +267 -0
- package/build/dex/aave-v1/aave-v1.d.ts +34 -0
- package/build/dex/aave-v1/aave-v1.js +180 -0
- package/build/dex/aave-v1/aave-v1.js.map +1 -0
- package/build/dex/aave-v1/config.d.ts +11 -0
- package/build/dex/aave-v1/config.js +20 -0
- package/build/dex/aave-v1/config.js.map +1 -0
- package/build/dex/aave-v1/tokens-mainnet.json +134 -0
- package/build/dex/aave-v1/tokens.d.ts +3 -0
- package/build/dex/aave-v1/tokens.js +50 -0
- package/build/dex/aave-v1/tokens.js.map +1 -0
- package/build/dex/aave-v1/types.d.ts +12 -0
- package/build/dex/aave-v1/types.js +3 -0
- package/build/dex/aave-v1/types.js.map +1 -0
- package/build/dex/aave-v3-stata/config.js +8 -8
- package/build/dex/aave-v3-stata/config.js.map +1 -1
- package/build/dex/aave-v3-stata-v2/aave-v3-stata-v2.js +2 -2
- package/build/dex/aave-v3-stata-v2/aave-v3-stata-v2.js.map +1 -1
- package/build/dex/aave-v3-stata-v2/config.js +31 -24
- package/build/dex/aave-v3-stata-v2/config.js.map +1 -1
- package/build/dex/aave-v3-stata-v2/types.d.ts +3 -2
- package/build/dex/aave-v3-stata-v2/types.js.map +1 -1
- package/build/dex/aave-v3-stata-v2/utils.d.ts +2 -2
- package/build/dex/aave-v3-stata-v2/utils.js +7 -6
- package/build/dex/aave-v3-stata-v2/utils.js.map +1 -1
- package/build/dex/balancer-v1/balancer-pools.json +33333 -0
- package/build/dex/bebop/websocket-fetcher.d.ts +35 -0
- package/build/dex/bebop/websocket-fetcher.js +87 -0
- package/build/dex/bebop/websocket-fetcher.js.map +1 -0
- package/build/dex/ekubo/config.d.ts +3 -0
- package/build/dex/ekubo/config.js +16 -0
- package/build/dex/ekubo/config.js.map +1 -0
- package/build/dex/ekubo/ekubo.d.ts +49 -0
- package/build/dex/ekubo/ekubo.js +419 -0
- package/build/dex/ekubo/ekubo.js.map +1 -0
- package/build/dex/ekubo/pools/base-pool.d.ts +47 -0
- package/build/dex/ekubo/pools/base-pool.js +184 -0
- package/build/dex/ekubo/pools/base-pool.js.map +1 -0
- package/build/dex/ekubo/pools/math/constants.d.ts +3 -0
- package/build/dex/ekubo/pools/math/constants.js +7 -0
- package/build/dex/ekubo/pools/math/constants.js.map +1 -0
- package/build/dex/ekubo/pools/math/delta.d.ts +2 -0
- package/build/dex/ekubo/pools/math/delta.js +51 -0
- package/build/dex/ekubo/pools/math/delta.js.map +1 -0
- package/build/dex/ekubo/pools/math/price.d.ts +7 -0
- package/build/dex/ekubo/pools/math/price.js +116 -0
- package/build/dex/ekubo/pools/math/price.js.map +1 -0
- package/build/dex/ekubo/pools/math/swap.d.ts +18 -0
- package/build/dex/ekubo/pools/math/swap.js +128 -0
- package/build/dex/ekubo/pools/math/swap.js.map +1 -0
- package/build/dex/ekubo/pools/math/tick.d.ts +7 -0
- package/build/dex/ekubo/pools/math/tick.js +112 -0
- package/build/dex/ekubo/pools/math/tick.js.map +1 -0
- package/build/dex/ekubo/pools/oracle-pool.d.ts +10 -0
- package/build/dex/ekubo/pools/oracle-pool.js +19 -0
- package/build/dex/ekubo/pools/oracle-pool.js.map +1 -0
- package/build/dex/ekubo/types.d.ts +88 -0
- package/build/dex/ekubo/types.js +238 -0
- package/build/dex/ekubo/types.js.map +1 -0
- package/build/dex/ekubo/utils.d.ts +6 -0
- package/build/dex/ekubo/utils.js +30 -0
- package/build/dex/ekubo/utils.js.map +1 -0
- package/build/dex/idle-dao/idle-dao-pool.d.ts +56 -0
- package/build/dex/idle-dao/idle-dao-pool.js +176 -0
- package/build/dex/idle-dao/idle-dao-pool.js.map +1 -0
- package/build/dex/idle-dao/idle-dao-pooling-pool.d.ts +16 -0
- package/build/dex/idle-dao/idle-dao-pooling-pool.js +57 -0
- package/build/dex/idle-dao/idle-dao-pooling-pool.js.map +1 -0
- package/build/dex/idle-dao/scripts.d.ts +9 -0
- package/build/dex/idle-dao/scripts.js +552 -0
- package/build/dex/idle-dao/scripts.js.map +1 -0
- package/build/dex/inception/config.d.ts +4 -0
- package/build/dex/inception/config.js +109 -0
- package/build/dex/inception/config.js.map +1 -0
- package/build/dex/inception/inception-event-pool.d.ts +16 -0
- package/build/dex/inception/inception-event-pool.js +51 -0
- package/build/dex/inception/inception-event-pool.js.map +1 -0
- package/build/dex/inception/inception-native.d.ts +43 -0
- package/build/dex/inception/inception-native.js +131 -0
- package/build/dex/inception/inception-native.js.map +1 -0
- package/build/dex/inception/inception-pool.d.ts +18 -0
- package/build/dex/inception/inception-pool.js +32 -0
- package/build/dex/inception/inception-pool.js.map +1 -0
- package/build/dex/inception/inception-price-feed.d.ts +19 -0
- package/build/dex/inception/inception-price-feed.js +51 -0
- package/build/dex/inception/inception-price-feed.js.map +1 -0
- package/build/dex/inception/inception.d.ts +43 -0
- package/build/dex/inception/inception.js +204 -0
- package/build/dex/inception/inception.js.map +1 -0
- package/build/dex/inception/tokens.d.ts +9 -0
- package/build/dex/inception/tokens.js +28 -0
- package/build/dex/inception/tokens.js.map +1 -0
- package/build/dex/inception/types.d.ts +22 -0
- package/build/dex/inception/types.js +3 -0
- package/build/dex/inception/types.js.map +1 -0
- package/build/dex/inception/utils.d.ts +6 -0
- package/build/dex/inception/utils.js +37 -0
- package/build/dex/inception/utils.js.map +1 -0
- package/build/dex/index.js +2 -0
- package/build/dex/index.js.map +1 -1
- package/build/dex/platypus/asset.d.ts +14 -0
- package/build/dex/platypus/asset.js +97 -0
- package/build/dex/platypus/asset.js.map +1 -0
- package/build/dex/platypus/config.d.ts +11 -0
- package/build/dex/platypus/config.js +69 -0
- package/build/dex/platypus/config.js.map +1 -0
- package/build/dex/platypus/platypus.d.ts +63 -0
- package/build/dex/platypus/platypus.js +473 -0
- package/build/dex/platypus/platypus.js.map +1 -0
- package/build/dex/platypus/pool-avax.d.ts +8 -0
- package/build/dex/platypus/pool-avax.js +54 -0
- package/build/dex/platypus/pool-avax.js.map +1 -0
- package/build/dex/platypus/pool-base.d.ts +19 -0
- package/build/dex/platypus/pool-base.js +86 -0
- package/build/dex/platypus/pool-base.js.map +1 -0
- package/build/dex/platypus/pool-pure.d.ts +8 -0
- package/build/dex/platypus/pool-pure.js +37 -0
- package/build/dex/platypus/pool-pure.js.map +1 -0
- package/build/dex/platypus/pool-subscriber.d.ts +14 -0
- package/build/dex/platypus/pool-subscriber.js +167 -0
- package/build/dex/platypus/pool-subscriber.js.map +1 -0
- package/build/dex/platypus/pool.d.ts +8 -0
- package/build/dex/platypus/pool.js +58 -0
- package/build/dex/platypus/pool.js.map +1 -0
- package/build/dex/platypus/types.d.ts +92 -0
- package/build/dex/platypus/types.js +10 -0
- package/build/dex/platypus/types.js.map +1 -0
- package/build/dex/quickswap/spiritswap-v3.d.ts +6 -0
- package/build/dex/quickswap/spiritswap-v3.js +19 -0
- package/build/dex/quickswap/spiritswap-v3.js.map +1 -0
- package/build/dex/smardex/config.d.ts +4 -0
- package/build/dex/smardex/config.js +64 -0
- package/build/dex/smardex/config.js.map +1 -0
- package/build/dex/smardex/constants.d.ts +18 -0
- package/build/dex/smardex/constants.js +33 -0
- package/build/dex/smardex/constants.js.map +1 -0
- package/build/dex/smardex/sdk/constants.d.ts +6 -0
- package/build/dex/smardex/sdk/constants.js +13 -0
- package/build/dex/smardex/sdk/constants.js.map +1 -0
- package/build/dex/smardex/sdk/core.d.ts +113 -0
- package/build/dex/smardex/sdk/core.js +499 -0
- package/build/dex/smardex/sdk/core.js.map +1 -0
- package/build/dex/smardex/sdk/errors.d.ts +15 -0
- package/build/dex/smardex/sdk/errors.js +22 -0
- package/build/dex/smardex/sdk/errors.js.map +1 -0
- package/build/dex/smardex/sdk/types.d.ts +62 -0
- package/build/dex/smardex/sdk/types.js +3 -0
- package/build/dex/smardex/sdk/types.js.map +1 -0
- package/build/dex/smardex/sdk/utils.d.ts +44 -0
- package/build/dex/smardex/sdk/utils.js +133 -0
- package/build/dex/smardex/sdk/utils.js.map +1 -0
- package/build/dex/smardex/smardex-event-pool.d.ts +28 -0
- package/build/dex/smardex/smardex-event-pool.js +119 -0
- package/build/dex/smardex/smardex-event-pool.js.map +1 -0
- package/build/dex/smardex/smardex.d.ts +65 -0
- package/build/dex/smardex/smardex.js +519 -0
- package/build/dex/smardex/smardex.js.map +1 -0
- package/build/dex/smardex/types.d.ts +55 -0
- package/build/dex/smardex/types.js +3 -0
- package/build/dex/smardex/types.js.map +1 -0
- package/build/dex/solidly/forks-override/cone.d.ts +22 -0
- package/build/dex/solidly/forks-override/cone.js +53 -0
- package/build/dex/solidly/forks-override/cone.js.map +1 -0
- package/build/dex/solidly/forks-override/solisnek.d.ts +8 -0
- package/build/dex/solidly/forks-override/solisnek.js +15 -0
- package/build/dex/solidly/forks-override/solisnek.js.map +1 -0
- package/build/dex/swaap-v1/config.d.ts +17 -0
- package/build/dex/swaap-v1/config.js +56 -0
- package/build/dex/swaap-v1/config.js.map +1 -0
- package/build/dex/swaap-v1/constants.d.ts +6 -0
- package/build/dex/swaap-v1/constants.js +17 -0
- package/build/dex/swaap-v1/constants.js.map +1 -0
- package/build/dex/swaap-v1/libraries/ChainlinkUtils.d.ts +25 -0
- package/build/dex/swaap-v1/libraries/ChainlinkUtils.js +62 -0
- package/build/dex/swaap-v1/libraries/ChainlinkUtils.js.map +1 -0
- package/build/dex/swaap-v1/libraries/Const.d.ts +18 -0
- package/build/dex/swaap-v1/libraries/Const.js +26 -0
- package/build/dex/swaap-v1/libraries/Const.js.map +1 -0
- package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.d.ts +77 -0
- package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.js +316 -0
- package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.js.map +1 -0
- package/build/dex/swaap-v1/libraries/LogExpMath.d.ts +75 -0
- package/build/dex/swaap-v1/libraries/LogExpMath.js +418 -0
- package/build/dex/swaap-v1/libraries/LogExpMath.js.map +1 -0
- package/build/dex/swaap-v1/libraries/MathMMM.d.ts +185 -0
- package/build/dex/swaap-v1/libraries/MathMMM.js +453 -0
- package/build/dex/swaap-v1/libraries/MathMMM.js.map +1 -0
- package/build/dex/swaap-v1/libraries/Num.d.ts +31 -0
- package/build/dex/swaap-v1/libraries/Num.js +167 -0
- package/build/dex/swaap-v1/libraries/Num.js.map +1 -0
- package/build/dex/swaap-v1/libraries/PoolQuotations.d.ts +23 -0
- package/build/dex/swaap-v1/libraries/PoolQuotations.js +131 -0
- package/build/dex/swaap-v1/libraries/PoolQuotations.js.map +1 -0
- package/build/dex/swaap-v1/libraries/Struct.d.ts +56 -0
- package/build/dex/swaap-v1/libraries/Struct.js +3 -0
- package/build/dex/swaap-v1/libraries/Struct.js.map +1 -0
- package/build/dex/swaap-v1/swaap-v1-pool.d.ts +45 -0
- package/build/dex/swaap-v1/swaap-v1-pool.js +656 -0
- package/build/dex/swaap-v1/swaap-v1-pool.js.map +1 -0
- package/build/dex/swaap-v1/swaap-v1.d.ts +62 -0
- package/build/dex/swaap-v1/swaap-v1.js +379 -0
- package/build/dex/swaap-v1/swaap-v1.js.map +1 -0
- package/build/dex/swaap-v1/types.d.ts +106 -0
- package/build/dex/swaap-v1/types.js +9 -0
- package/build/dex/swaap-v1/types.js.map +1 -0
- package/build/dex/zerox/index.d.ts +1 -1
- package/build/dex/zerox/index.js.map +1 -1
- package/build/dex-helper/dummy-dex-helper.js +3 -0
- package/build/dex-helper/dummy-dex-helper.js.map +1 -1
- package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-balancerv1-curvev1-eth-usdc-gusd.json +16 -0
- package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-balancerv1-sushiv3-wbtc-eth-sushi.json +16 -0
- package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-curvev1-eth-usdc-gusd.json +16 -0
- package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-curvev1-gusd-usdc-eth.json +16 -0
- package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-dai-usdc-eth.json +16 -0
- package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-eth-usdc-dai.json +16 -0
- package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-usdc-eth-wbtc.json +16 -0
- package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-usdt-usdc-dai.json +16 -0
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-balancerv1-eth-usdc.json +9 -0
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-balancerv1-usdc-eth.json +9 -0
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-balancerv1-usdc-wbtc.json +9 -0
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-curvev1-eth-steth.json +9 -0
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-curvev1-steth-eth.json +9 -0
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-curvev1-usdc-usdt.json +9 -0
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-univ3-eth-usdc.json +9 -0
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-univ3-usdc-eth.json +9 -0
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-univ3-usdc-usdt.json +9 -0
- package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-balancerv1-sushiv3-wbtc-eth-sushi.json +12 -0
- package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-curvev1-eth-usdc-gusd.json +7 -0
- package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-curvev1-gusd-usdc-eth.json +7 -0
- package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-dai-usdc-eth.json +7 -0
- package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-eth-usdc-dai.json +7 -0
- package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-usdc-eth-wbtc.json +12 -0
- package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-simpleSwap-univ3-eth-usdc.json +7 -0
- package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-simpleSwap-univ3-usdc-eth.json +7 -0
- package/build/executor/fixtures/executor01/routes/price-route-multiswap-balancerv1-curvev1-eth-usdc-gusd.json +78 -0
- package/build/executor/fixtures/executor01/routes/price-route-multiswap-balancerv1-sushiv3-wbtc-eth-sushi.json +81 -0
- package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-curvev1-eth-usdc-gusd.json +78 -0
- package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-curvev1-gusd-usdc-eth.json +78 -0
- package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-dai-usdc-eth.json +81 -0
- package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-eth-usdc-dai.json +81 -0
- package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-usdc-eth-wbtc.json +81 -0
- package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-usdt-usdc-dai.json +81 -0
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-balancerv1-eth-usdc.json +64 -0
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-balancerv1-usdc-eth.json +85 -0
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-balancerv1-usdc-wbtc.json +64 -0
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-curvev1-eth-steth.json +52 -0
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-curvev1-steth-eth.json +52 -0
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-curvev1-usdc-usdt.json +52 -0
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-univ3-eth-usdc.json +55 -0
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-univ3-usdc-eth.json +55 -0
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-univ3-usdc-usdt.json +55 -0
- package/build/executor/fixtures/executor02/exchange-params/price-route-multiSwap-balancerv1-sushiv3-univ3-bal-eth-sushi.json +23 -0
- package/build/executor/fixtures/executor02/exchange-params/price-route-multiSwap-maverickv1-sushiv3-univ3-eth-usdc-mav.json +37 -0
- package/build/executor/fixtures/executor02/exchange-params/price-route-multiSwap-univ3-sushiv3-sushi-eth-wbtc.json +23 -0
- package/build/executor/fixtures/executor02/exchange-params/price-route-multiSwap-univ3-sushiv3-wbtc-eth-sushi.json +23 -0
- package/build/executor/fixtures/executor02/exchange-params/price-route-multiswap-curvev1-univ3-dai-usdc-eth.json +51 -0
- package/build/executor/fixtures/executor02/exchange-params/price-route-multiswap-univ3-usdt-dai-eth.json +58 -0
- package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-balancerv1-eth-usdc.json +23 -0
- package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-balancerv1-usdc-eth.json +23 -0
- package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-univ3-eth-sushi.json +9 -0
- package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-univ3-sushi-eth.json +16 -0
- package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-univ3-curvev1-usdt-dai.json +23 -0
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-balancerv1-sushiv3-univ3-bal-eth-sushi.json +12 -0
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-maverickv1-sushiv3-univ3-eth-usdc-mav.json +7 -0
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-univ3-sushiv3-sushi-eth-wbtc.json +12 -0
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-univ3-sushiv3-wbtc-eth-sushi.json +12 -0
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiswap-curvev1-univ3-dai-usdc-eth.json +7 -0
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiswap-univ3-usdt-dai-eth.json +7 -0
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-balancerv1-eth-usdc.json +7 -0
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-balancerv1-usdc-eth.json +7 -0
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-univ3-eth-sushi.json +7 -0
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-univ3-sushi-eth.json +7 -0
- package/build/executor/fixtures/executor02/routes/price-route-multiSwap-balancerv1-sushiv3-univ3-bal-eth-sushi.json +130 -0
- package/build/executor/fixtures/executor02/routes/price-route-multiSwap-maverickv1-sushiv3-univ3-eth-usdc-mav.json +136 -0
- package/build/executor/fixtures/executor02/routes/price-route-multiSwap-univ3-sushiv3-sushi-eth-wbtc.json +100 -0
- package/build/executor/fixtures/executor02/routes/price-route-multiSwap-univ3-sushiv3-wbtc-eth-sushi.json +100 -0
- package/build/executor/fixtures/executor02/routes/price-route-multiswap-curvev1-univ3-dai-usdc-eth.json +166 -0
- package/build/executor/fixtures/executor02/routes/price-route-multiswap-univ3-usdt-dai-eth.json +190 -0
- package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-balancerv1-eth-usdc.json +114 -0
- package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-balancerv1-usdc-eth.json +114 -0
- package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-univ3-eth-sushi.json +55 -0
- package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-univ3-sushi-eth.json +73 -0
- package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-univ3-curvev1-usdt-dai.json +82 -0
- package/package.json +2 -2
- package/src/abi/ekubo/core.json +1266 -0
- package/src/abi/ekubo/data-fetcher.json +161 -0
- package/src/abi/ekubo/router.json +803 -0
- package/src/dex/aave-v3-stata/config.ts +8 -8
- package/src/dex/aave-v3-stata-v2/aave-v3-stata-v2-e2e.test.ts +5 -5
- package/src/dex/aave-v3-stata-v2/aave-v3-stata-v2.ts +2 -2
- package/src/dex/aave-v3-stata-v2/config.ts +31 -24
- package/src/dex/aave-v3-stata-v2/types.ts +3 -2
- package/src/dex/aave-v3-stata-v2/utils.ts +18 -10
- package/src/dex/ekubo/config.ts +15 -0
- package/src/dex/ekubo/ekubo-e2e.test.ts +124 -0
- package/src/dex/ekubo/ekubo-events.test.ts +209 -0
- package/src/dex/ekubo/ekubo-integration.test.ts +243 -0
- package/src/dex/ekubo/ekubo.ts +657 -0
- package/src/dex/ekubo/pools/base-pool.ts +267 -0
- package/src/dex/ekubo/pools/math/constants.ts +5 -0
- package/src/dex/ekubo/pools/math/delta.test.ts +131 -0
- package/src/dex/ekubo/pools/math/delta.ts +68 -0
- package/src/dex/ekubo/pools/math/price.test.ts +54 -0
- package/src/dex/ekubo/pools/math/price.ts +129 -0
- package/src/dex/ekubo/pools/math/swap.test.ts +215 -0
- package/src/dex/ekubo/pools/math/swap.ts +161 -0
- package/src/dex/ekubo/pools/math/tick.test.ts +72 -0
- package/src/dex/ekubo/pools/math/tick.ts +120 -0
- package/src/dex/ekubo/pools/oracle-pool.ts +46 -0
- package/src/dex/ekubo/types.test.ts +552 -0
- package/src/dex/ekubo/types.ts +408 -0
- package/src/dex/ekubo/utils.ts +34 -0
- package/src/dex/index.ts +2 -0
- package/src/dex-helper/dummy-dex-helper.ts +10 -0
- package/tests/constants-e2e.ts +15 -0
- package/tests/utils-e2e.ts +0 -1
- package/.idea/codeStyles/Project.xml +0 -59
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/paraswap-dex-lib.iml +0 -12
- package/.idea/prettier.xml +0 -7
- package/.idea/vcs.xml +0 -6
- package/scripts/get-uniswap-v3-dexes.ts +0 -64
|
@@ -0,0 +1,657 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Token,
|
|
3
|
+
Address,
|
|
4
|
+
ExchangePrices,
|
|
5
|
+
PoolPrices,
|
|
6
|
+
AdapterExchangeParam,
|
|
7
|
+
PoolLiquidity,
|
|
8
|
+
DexExchangeParam,
|
|
9
|
+
NumberAsString,
|
|
10
|
+
} from '../../types';
|
|
11
|
+
import { SwapSide, Network, ETHER_ADDRESS } from '../../constants';
|
|
12
|
+
import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
|
|
13
|
+
import { getBigIntPow, getDexKeysWithNetwork } from '../../utils';
|
|
14
|
+
import { Context, IDex } from '../../dex/idex';
|
|
15
|
+
import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
16
|
+
import {
|
|
17
|
+
EkuboData,
|
|
18
|
+
GetQuoteDataResponse,
|
|
19
|
+
PoolConfig,
|
|
20
|
+
PoolKey,
|
|
21
|
+
PoolState,
|
|
22
|
+
VanillaPoolParameters,
|
|
23
|
+
} from './types';
|
|
24
|
+
import { SimpleExchange } from '../simple-exchange';
|
|
25
|
+
import { EkuboConfig } from './config';
|
|
26
|
+
import { BasePool } from './pools/base-pool';
|
|
27
|
+
import {
|
|
28
|
+
convertEkuboToParaSwap,
|
|
29
|
+
convertParaSwapToEkubo,
|
|
30
|
+
hexStringTokenPair,
|
|
31
|
+
NATIVE_TOKEN_ADDRESS,
|
|
32
|
+
sortAndConvertTokens,
|
|
33
|
+
} from './utils';
|
|
34
|
+
import Joi from 'joi';
|
|
35
|
+
import { Interface } from '@ethersproject/abi';
|
|
36
|
+
|
|
37
|
+
import CoreABI from '../../abi/ekubo/core.json';
|
|
38
|
+
import DataFetcherABI from '../../abi/ekubo/data-fetcher.json';
|
|
39
|
+
import { BigNumber, Contract } from 'ethers';
|
|
40
|
+
import { FULL_RANGE_TICK_SPACING } from './pools/math/tick';
|
|
41
|
+
import { hexlify } from 'ethers/lib/utils';
|
|
42
|
+
import RouterABI from '../../abi/ekubo/router.json';
|
|
43
|
+
import { isPriceIncreasing } from './pools/math/swap';
|
|
44
|
+
import { OraclePool } from './pools/oracle-pool';
|
|
45
|
+
import { erc20Iface } from '../../lib/tokens/utils';
|
|
46
|
+
import { AsyncOrSync } from 'ts-essentials';
|
|
47
|
+
import { MAX_SQRT_RATIO_FLOAT, MIN_SQRT_RATIO_FLOAT } from './pools/math/price';
|
|
48
|
+
import { MIN_I256 } from './pools/math/constants';
|
|
49
|
+
|
|
50
|
+
const FALLBACK_POOL_PARAMETERS: VanillaPoolParameters[] = [
|
|
51
|
+
{
|
|
52
|
+
fee: 1844674407370955n,
|
|
53
|
+
tickSpacing: 200,
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
fee: 9223372036854775n,
|
|
57
|
+
tickSpacing: 1000,
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
fee: 55340232221128654n,
|
|
61
|
+
tickSpacing: 5982,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
fee: 184467440737095516n,
|
|
65
|
+
tickSpacing: 19802,
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
fee: 922337203685477580n,
|
|
69
|
+
tickSpacing: 95310,
|
|
70
|
+
},
|
|
71
|
+
];
|
|
72
|
+
|
|
73
|
+
type PairInfo = {
|
|
74
|
+
fee: string;
|
|
75
|
+
tick_spacing: number;
|
|
76
|
+
core_address: string;
|
|
77
|
+
extension: string;
|
|
78
|
+
tvl0_total: string;
|
|
79
|
+
tvl1_total: string;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const tokenPairSchema = Joi.object<{
|
|
83
|
+
topPools: PairInfo[];
|
|
84
|
+
}>({
|
|
85
|
+
topPools: Joi.array().items(
|
|
86
|
+
Joi.object({
|
|
87
|
+
fee: Joi.string(),
|
|
88
|
+
tick_spacing: Joi.number(),
|
|
89
|
+
extension: Joi.string(),
|
|
90
|
+
tvl0_total: Joi.string(),
|
|
91
|
+
tvl1_total: Joi.string(),
|
|
92
|
+
}),
|
|
93
|
+
),
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const allPoolsSchema = Joi.array<
|
|
97
|
+
{
|
|
98
|
+
core_address: string;
|
|
99
|
+
token0: string;
|
|
100
|
+
token1: string;
|
|
101
|
+
fee: string;
|
|
102
|
+
tick_spacing: number;
|
|
103
|
+
extension: string;
|
|
104
|
+
}[]
|
|
105
|
+
>().items(
|
|
106
|
+
Joi.object({
|
|
107
|
+
core_address: Joi.string(),
|
|
108
|
+
token0: Joi.string(),
|
|
109
|
+
token1: Joi.string(),
|
|
110
|
+
fee: Joi.string(),
|
|
111
|
+
tick_spacing: Joi.number(),
|
|
112
|
+
extension: Joi.string(),
|
|
113
|
+
}),
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
const MIN_TICK_SPACINGS_PER_POOL = 2;
|
|
117
|
+
const MAX_BATCH_SIZE = 100;
|
|
118
|
+
|
|
119
|
+
const POOL_MAP_UPDATE_INTERVAL_MS = 5 * 60 * 1000;
|
|
120
|
+
|
|
121
|
+
// Ekubo Protocol https://ekubo.org/
|
|
122
|
+
export class Ekubo extends SimpleExchange implements IDex<EkuboData> {
|
|
123
|
+
public readonly hasConstantPriceLargeAmounts = false;
|
|
124
|
+
public readonly needWrapNative = false;
|
|
125
|
+
public readonly isFeeOnTransferSupported = false;
|
|
126
|
+
|
|
127
|
+
public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
|
|
128
|
+
getDexKeysWithNetwork(EkuboConfig);
|
|
129
|
+
|
|
130
|
+
private readonly pools: Map<string, BasePool> = new Map();
|
|
131
|
+
|
|
132
|
+
public logger;
|
|
133
|
+
|
|
134
|
+
public readonly config;
|
|
135
|
+
public readonly routerIface;
|
|
136
|
+
|
|
137
|
+
private readonly core;
|
|
138
|
+
private readonly coreIface;
|
|
139
|
+
private readonly dataFetcher;
|
|
140
|
+
private readonly supportedExtensions;
|
|
141
|
+
|
|
142
|
+
private interval?: NodeJS.Timeout;
|
|
143
|
+
|
|
144
|
+
// Caches the number of decimals for TVL computation purposes
|
|
145
|
+
private readonly decimals: Record<string, number> = {
|
|
146
|
+
[ETHER_ADDRESS]: 18,
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
public constructor(
|
|
150
|
+
readonly network: Network,
|
|
151
|
+
readonly dexKey: string,
|
|
152
|
+
readonly dexHelper: IDexHelper,
|
|
153
|
+
) {
|
|
154
|
+
super(dexHelper, dexKey);
|
|
155
|
+
|
|
156
|
+
this.logger = dexHelper.getLogger(dexKey);
|
|
157
|
+
this.config = EkuboConfig[dexKey][network];
|
|
158
|
+
this.core = new Contract(this.config.core, CoreABI, dexHelper.provider);
|
|
159
|
+
this.coreIface = new Interface(CoreABI);
|
|
160
|
+
this.dataFetcher = new Contract(
|
|
161
|
+
this.config.dataFetcher,
|
|
162
|
+
DataFetcherABI,
|
|
163
|
+
dexHelper.provider,
|
|
164
|
+
);
|
|
165
|
+
this.routerIface = new Interface(RouterABI);
|
|
166
|
+
|
|
167
|
+
// 0 are vanilla pools
|
|
168
|
+
this.supportedExtensions = [0n, BigInt(this.config.oracle)];
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Periodically schedules fetching pool keys from the Ekubo API and filling in details with the quote data fetcher
|
|
172
|
+
public async initializePricing(blockNumber: number) {
|
|
173
|
+
await this.updatePoolMap(blockNumber);
|
|
174
|
+
|
|
175
|
+
this.interval = setInterval(async () => {
|
|
176
|
+
await this.updatePoolMap(await this.dexHelper.provider.getBlockNumber());
|
|
177
|
+
}, POOL_MAP_UPDATE_INTERVAL_MS);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// LEGACY
|
|
181
|
+
public getAdapters(
|
|
182
|
+
_side: SwapSide,
|
|
183
|
+
): { name: string; index: number }[] | null {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
public async getPoolIdentifiers(
|
|
188
|
+
srcToken: Token,
|
|
189
|
+
destToken: Token,
|
|
190
|
+
_side: SwapSide,
|
|
191
|
+
blockNumber: number,
|
|
192
|
+
): Promise<string[]> {
|
|
193
|
+
const [token0, token1] = sortAndConvertTokens(srcToken, destToken);
|
|
194
|
+
const pair = hexStringTokenPair(token0, token1);
|
|
195
|
+
|
|
196
|
+
let poolKeys: PoolKey[];
|
|
197
|
+
try {
|
|
198
|
+
poolKeys = (await this.fetchAllPoolKeys()).filter(
|
|
199
|
+
poolKey => poolKey.token0 === token0 && poolKey.token1 === token1,
|
|
200
|
+
);
|
|
201
|
+
} catch (err) {
|
|
202
|
+
this.logger.error(
|
|
203
|
+
`Fetching pools from Ekubo API for token pair ${pair} failed, falling back to default pool parameters: ${err}`,
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
poolKeys = FALLBACK_POOL_PARAMETERS.map(
|
|
207
|
+
params =>
|
|
208
|
+
new PoolKey(
|
|
209
|
+
token0,
|
|
210
|
+
token1,
|
|
211
|
+
new PoolConfig(params.tickSpacing, params.fee, 0n),
|
|
212
|
+
),
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
if ([token0, token1].includes(NATIVE_TOKEN_ADDRESS)) {
|
|
216
|
+
poolKeys.push(
|
|
217
|
+
new PoolKey(
|
|
218
|
+
token0,
|
|
219
|
+
token1,
|
|
220
|
+
new PoolConfig(
|
|
221
|
+
FULL_RANGE_TICK_SPACING,
|
|
222
|
+
0n,
|
|
223
|
+
BigInt(this.config.oracle),
|
|
224
|
+
),
|
|
225
|
+
),
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const uninitializedPoolKeys: PoolKey[] = [];
|
|
231
|
+
const initializedPoolKeys: PoolKey[] = [];
|
|
232
|
+
|
|
233
|
+
for (const poolKey of poolKeys) {
|
|
234
|
+
(this.pools.has(poolKey.string_id)
|
|
235
|
+
? initializedPoolKeys
|
|
236
|
+
: uninitializedPoolKeys
|
|
237
|
+
).push(poolKey);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const promises = this.initializePools(uninitializedPoolKeys, blockNumber);
|
|
241
|
+
|
|
242
|
+
const oldPoolIds = initializedPoolKeys.map(poolKey => poolKey.string_id);
|
|
243
|
+
const newPoolIds = (await Promise.allSettled(promises)).flatMap(res => {
|
|
244
|
+
if (res.status === 'rejected') {
|
|
245
|
+
this.logger.error(
|
|
246
|
+
`Fetching batch failed. Pool keys: ${res.reason.batch}. Error: ${res.reason.err}`,
|
|
247
|
+
);
|
|
248
|
+
return [];
|
|
249
|
+
} else {
|
|
250
|
+
return res.value;
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
return oldPoolIds.concat(newPoolIds);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
public async getPricesVolume(
|
|
258
|
+
srcToken: Token,
|
|
259
|
+
destToken: Token,
|
|
260
|
+
amounts: bigint[],
|
|
261
|
+
side: SwapSide,
|
|
262
|
+
blockNumber: number,
|
|
263
|
+
limitPools?: string[],
|
|
264
|
+
): Promise<null | ExchangePrices<EkuboData>> {
|
|
265
|
+
const pools = this.getInitializedPools(srcToken, destToken, limitPools);
|
|
266
|
+
|
|
267
|
+
const isExactOut = side === SwapSide.BUY;
|
|
268
|
+
|
|
269
|
+
const amountToken = isExactOut ? destToken : srcToken;
|
|
270
|
+
const amountTokenAddress = convertParaSwapToEkubo(amountToken.address);
|
|
271
|
+
const unitAmount = getBigIntPow(amountToken.decimals);
|
|
272
|
+
|
|
273
|
+
const [token0, token1] = sortAndConvertTokens(srcToken, destToken);
|
|
274
|
+
|
|
275
|
+
const exchangePrices = [];
|
|
276
|
+
|
|
277
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
278
|
+
poolLoop: for (const pool of pools) {
|
|
279
|
+
const poolId = pool.key.string_id;
|
|
280
|
+
|
|
281
|
+
if (pool.key.token0 !== token0 || pool.key.token1 !== token1) {
|
|
282
|
+
this.logger.error(
|
|
283
|
+
`Can't quote pair ${hexStringTokenPair(
|
|
284
|
+
token0,
|
|
285
|
+
token1,
|
|
286
|
+
)} on pool ${poolId}`,
|
|
287
|
+
);
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
try {
|
|
292
|
+
const quotes = [];
|
|
293
|
+
const skipAheadMap: Record<string, number> = {};
|
|
294
|
+
|
|
295
|
+
for (const amount of [unitAmount, ...amounts]) {
|
|
296
|
+
const inputAmount = isExactOut ? -amount : amount;
|
|
297
|
+
|
|
298
|
+
const quote = pool.quote(
|
|
299
|
+
inputAmount,
|
|
300
|
+
amountTokenAddress,
|
|
301
|
+
blockNumber,
|
|
302
|
+
);
|
|
303
|
+
|
|
304
|
+
if (isExactOut && quote.consumedAmount !== inputAmount) {
|
|
305
|
+
this.logger.debug(
|
|
306
|
+
`Pool ${poolId} doesn't have enough liquidity to support exact-out swap of ${amount} ${
|
|
307
|
+
amountToken.symbol ?? amountToken.address
|
|
308
|
+
}`,
|
|
309
|
+
);
|
|
310
|
+
|
|
311
|
+
// There doesn't seem to be a way to skip just this one price.
|
|
312
|
+
// Anyway, this pool is probably not the right one if it has such thin liquidity.
|
|
313
|
+
continue poolLoop;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
quotes.push(quote);
|
|
317
|
+
skipAheadMap[amount.toString()] = quote.skipAhead;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const [unitQuote, ...otherQuotes] = quotes;
|
|
321
|
+
|
|
322
|
+
exchangePrices.push({
|
|
323
|
+
prices: otherQuotes.map(quote => quote.calculatedAmount),
|
|
324
|
+
unit: unitQuote.calculatedAmount,
|
|
325
|
+
data: {
|
|
326
|
+
poolKeyAbi: pool.key.toAbi(),
|
|
327
|
+
isToken1: amountTokenAddress === token1,
|
|
328
|
+
skipAhead: skipAheadMap,
|
|
329
|
+
},
|
|
330
|
+
poolIdentifier: poolId,
|
|
331
|
+
exchange: this.dexKey,
|
|
332
|
+
gasCost: otherQuotes.map(quote => quote.gasConsumed),
|
|
333
|
+
});
|
|
334
|
+
} catch (err) {
|
|
335
|
+
this.logger.error('Quote error:', err);
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
return exchangePrices;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// LEGACY
|
|
344
|
+
public getCalldataGasCost(
|
|
345
|
+
_poolPrices: PoolPrices<EkuboData>,
|
|
346
|
+
): number | number[] {
|
|
347
|
+
return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// LEGACY
|
|
351
|
+
public getAdapterParam(
|
|
352
|
+
_srcToken: string,
|
|
353
|
+
_destToken: string,
|
|
354
|
+
_srcAmount: string,
|
|
355
|
+
_destAmount: string,
|
|
356
|
+
_data: EkuboData,
|
|
357
|
+
_side: SwapSide,
|
|
358
|
+
): AdapterExchangeParam {
|
|
359
|
+
return {
|
|
360
|
+
targetExchange: this.dexKey,
|
|
361
|
+
payload: '',
|
|
362
|
+
networkFee: '0',
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
public async updatePoolState(): Promise<void> {}
|
|
367
|
+
|
|
368
|
+
public async getTopPoolsForToken(
|
|
369
|
+
tokenAddress: Address,
|
|
370
|
+
limit: number,
|
|
371
|
+
): Promise<PoolLiquidity[]> {
|
|
372
|
+
// The integration tests skip initializePricing, hence this check
|
|
373
|
+
if (this.pools.size === 0) {
|
|
374
|
+
await this.updatePoolMap(await this.dexHelper.provider.getBlockNumber());
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
const token = convertParaSwapToEkubo(tokenAddress);
|
|
378
|
+
|
|
379
|
+
const settledPromises = await Promise.allSettled(
|
|
380
|
+
Array.from(this.pools.entries()).map(async ([poolId, pool]) => {
|
|
381
|
+
const tokenPair = [pool.key.token0, pool.key.token1];
|
|
382
|
+
if (!tokenPair.includes(token)) {
|
|
383
|
+
return null;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
const tvlRes = pool.computeTvl();
|
|
387
|
+
if (tvlRes === null) {
|
|
388
|
+
throw new Error(`failed to compute TVL for pool ${poolId}`);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
const [info0, info1] = await Promise.all(
|
|
392
|
+
tokenPair.map((ekuboToken, i) =>
|
|
393
|
+
(async () => {
|
|
394
|
+
const paraswapToken = convertEkuboToParaSwap(ekuboToken);
|
|
395
|
+
const decimals = await this.getDecimals(paraswapToken);
|
|
396
|
+
|
|
397
|
+
const token = {
|
|
398
|
+
address: paraswapToken,
|
|
399
|
+
decimals,
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
return {
|
|
403
|
+
token,
|
|
404
|
+
tvl: await this.dexHelper.getTokenUSDPrice(token, tvlRes[i]),
|
|
405
|
+
};
|
|
406
|
+
})(),
|
|
407
|
+
),
|
|
408
|
+
);
|
|
409
|
+
|
|
410
|
+
return {
|
|
411
|
+
exchange: this.dexKey,
|
|
412
|
+
address: this.config.core,
|
|
413
|
+
connectorTokens: [
|
|
414
|
+
(info0.token.address !== tokenAddress ? info0 : info1).token,
|
|
415
|
+
],
|
|
416
|
+
liquidityUSD: info0.tvl + info1.tvl,
|
|
417
|
+
};
|
|
418
|
+
}),
|
|
419
|
+
);
|
|
420
|
+
|
|
421
|
+
const poolLiquidities = settledPromises.flatMap(res => {
|
|
422
|
+
if (res.status === 'rejected') {
|
|
423
|
+
this.logger.error('TVL computation failed:', res.reason);
|
|
424
|
+
return [];
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
return res.value ? [res.value] : [];
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
poolLiquidities
|
|
431
|
+
.sort((a, b) => b.liquidityUSD - a.liquidityUSD)
|
|
432
|
+
.splice(limit, Infinity);
|
|
433
|
+
|
|
434
|
+
return poolLiquidities;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
private async getDecimals(paraswapToken: string): Promise<number> {
|
|
438
|
+
const cached = this.decimals[paraswapToken];
|
|
439
|
+
if (typeof cached === 'number') {
|
|
440
|
+
return cached;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
const decimals: number = await new Contract(
|
|
444
|
+
paraswapToken,
|
|
445
|
+
erc20Iface,
|
|
446
|
+
this.dexHelper.provider,
|
|
447
|
+
).decimals();
|
|
448
|
+
|
|
449
|
+
this.decimals[paraswapToken] = decimals;
|
|
450
|
+
|
|
451
|
+
return decimals;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
public getDexParam(
|
|
455
|
+
_srcToken: Address,
|
|
456
|
+
_destToken: Address,
|
|
457
|
+
srcAmount: NumberAsString,
|
|
458
|
+
destAmount: NumberAsString,
|
|
459
|
+
recipient: Address,
|
|
460
|
+
data: EkuboData,
|
|
461
|
+
side: SwapSide,
|
|
462
|
+
_context: Context,
|
|
463
|
+
_executorAddress: Address,
|
|
464
|
+
): DexExchangeParam {
|
|
465
|
+
const amount = BigInt(side === SwapSide.BUY ? `-${destAmount}` : srcAmount);
|
|
466
|
+
const amountStr = (
|
|
467
|
+
side === SwapSide.SELL ? srcAmount : destAmount
|
|
468
|
+
).toString();
|
|
469
|
+
|
|
470
|
+
return {
|
|
471
|
+
needWrapNative: this.needWrapNative,
|
|
472
|
+
exchangeData: this.routerIface.encodeFunctionData(
|
|
473
|
+
'swap((address,address,bytes32),bool,int128,uint96,uint256,int256,address)',
|
|
474
|
+
[
|
|
475
|
+
data.poolKeyAbi,
|
|
476
|
+
data.isToken1,
|
|
477
|
+
BigNumber.from(amount),
|
|
478
|
+
isPriceIncreasing(amount, data.isToken1)
|
|
479
|
+
? MAX_SQRT_RATIO_FLOAT
|
|
480
|
+
: MIN_SQRT_RATIO_FLOAT,
|
|
481
|
+
BigNumber.from(data.skipAhead[amountStr] ?? 0),
|
|
482
|
+
MIN_I256,
|
|
483
|
+
recipient,
|
|
484
|
+
],
|
|
485
|
+
),
|
|
486
|
+
targetExchange: this.config.router,
|
|
487
|
+
dexFuncHasRecipient: true,
|
|
488
|
+
returnAmountPos: undefined,
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
releaseResources(): AsyncOrSync<void> {
|
|
493
|
+
if (this.interval) {
|
|
494
|
+
clearInterval(this.interval);
|
|
495
|
+
this.interval = undefined;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
private getInitializedPools(
|
|
500
|
+
tokenA: Token,
|
|
501
|
+
tokenB: Token,
|
|
502
|
+
limitPools: string[] | undefined,
|
|
503
|
+
): BasePool[] {
|
|
504
|
+
if (typeof limitPools === 'undefined') {
|
|
505
|
+
const [token0, token1] = sortAndConvertTokens(tokenA, tokenB);
|
|
506
|
+
|
|
507
|
+
return Array.from(
|
|
508
|
+
this.pools
|
|
509
|
+
.values()
|
|
510
|
+
.filter(
|
|
511
|
+
pool => pool.key.token0 === token0 && pool.key.token1 === token1,
|
|
512
|
+
),
|
|
513
|
+
);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
return limitPools.flatMap(poolId => {
|
|
517
|
+
const pool = this.pools.get(poolId);
|
|
518
|
+
|
|
519
|
+
if (typeof pool === 'undefined') {
|
|
520
|
+
this.logger.warn(`Pool ${poolId} requested but not found`);
|
|
521
|
+
return [];
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
return [pool];
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
private async updatePoolMap(blockNumber: number) {
|
|
529
|
+
let poolKeys: PoolKey[];
|
|
530
|
+
try {
|
|
531
|
+
poolKeys = await this.fetchAllPoolKeys();
|
|
532
|
+
} catch (err) {
|
|
533
|
+
this.logger.error(`Updating pool map from Ekubo API failed: ${err}`);
|
|
534
|
+
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
const uninitializedPoolKeys = poolKeys.filter(
|
|
539
|
+
poolKey => !this.pools.has(poolKey.string_id),
|
|
540
|
+
);
|
|
541
|
+
const promises = this.initializePools(uninitializedPoolKeys, blockNumber);
|
|
542
|
+
|
|
543
|
+
(await Promise.allSettled(promises)).flatMap(res => {
|
|
544
|
+
if (res.status === 'rejected') {
|
|
545
|
+
this.logger.error(
|
|
546
|
+
`Fetching batch failed. Pool keys: ${res.reason.batch}. Error: ${res.reason.err}`,
|
|
547
|
+
);
|
|
548
|
+
}
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
private initializePools(
|
|
553
|
+
poolKeys: PoolKey[],
|
|
554
|
+
blockNumber: number,
|
|
555
|
+
): Promise<string[]>[] {
|
|
556
|
+
const promises = [];
|
|
557
|
+
|
|
558
|
+
for (
|
|
559
|
+
let batchStart = 0;
|
|
560
|
+
batchStart < poolKeys.length;
|
|
561
|
+
batchStart += MAX_BATCH_SIZE
|
|
562
|
+
) {
|
|
563
|
+
const batch = poolKeys.slice(batchStart, batchStart + MAX_BATCH_SIZE);
|
|
564
|
+
|
|
565
|
+
promises.push(
|
|
566
|
+
(async () => {
|
|
567
|
+
const fetchedData: GetQuoteDataResponse =
|
|
568
|
+
await this.dataFetcher.getQuoteData(
|
|
569
|
+
batch.map(poolKey => poolKey.toAbi()),
|
|
570
|
+
MIN_TICK_SPACINGS_PER_POOL,
|
|
571
|
+
{
|
|
572
|
+
blockTag: blockNumber,
|
|
573
|
+
},
|
|
574
|
+
);
|
|
575
|
+
|
|
576
|
+
return fetchedData.map((data, i) => {
|
|
577
|
+
const poolKey = poolKeys[batchStart + i];
|
|
578
|
+
const initialState = PoolState.fromQuoter(
|
|
579
|
+
data,
|
|
580
|
+
poolKey.config.tickSpacing === FULL_RANGE_TICK_SPACING,
|
|
581
|
+
);
|
|
582
|
+
const poolId = poolKey.string_id;
|
|
583
|
+
const extension = poolKey.config.extension;
|
|
584
|
+
|
|
585
|
+
let poolConstructor;
|
|
586
|
+
if (extension === 0n) {
|
|
587
|
+
poolConstructor = BasePool;
|
|
588
|
+
} else if (extension === BigInt(this.config.oracle)) {
|
|
589
|
+
poolConstructor = OraclePool;
|
|
590
|
+
} else {
|
|
591
|
+
throw new Error(`Unknown pool extension ${hexlify(extension)}`);
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
const pool = new poolConstructor(
|
|
595
|
+
this.dexKey,
|
|
596
|
+
this.network,
|
|
597
|
+
this.dexHelper,
|
|
598
|
+
this.logger,
|
|
599
|
+
this.coreIface,
|
|
600
|
+
this.dataFetcher,
|
|
601
|
+
poolKey,
|
|
602
|
+
this.core,
|
|
603
|
+
);
|
|
604
|
+
|
|
605
|
+
this.pools.set(poolId, pool);
|
|
606
|
+
|
|
607
|
+
// This is fulfilled immediately
|
|
608
|
+
pool.initialize(blockNumber, { state: initialState });
|
|
609
|
+
|
|
610
|
+
return poolId;
|
|
611
|
+
});
|
|
612
|
+
})().catch(err => {
|
|
613
|
+
throw {
|
|
614
|
+
batch,
|
|
615
|
+
err,
|
|
616
|
+
};
|
|
617
|
+
}),
|
|
618
|
+
);
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
return promises;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
private async fetchAllPoolKeys(): Promise<PoolKey[]> {
|
|
625
|
+
const res = await this.dexHelper.httpRequest.get(
|
|
626
|
+
`${this.config.apiUrl}/v1/poolKeys`,
|
|
627
|
+
);
|
|
628
|
+
|
|
629
|
+
const { error, value } = allPoolsSchema.validate(res, {
|
|
630
|
+
allowUnknown: true,
|
|
631
|
+
presence: 'required',
|
|
632
|
+
});
|
|
633
|
+
|
|
634
|
+
if (typeof error !== 'undefined') {
|
|
635
|
+
throw new Error(`validating API response: ${error}`);
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
return value
|
|
639
|
+
.filter(
|
|
640
|
+
res =>
|
|
641
|
+
this.supportedExtensions.includes(BigInt(res.extension)) &&
|
|
642
|
+
BigInt(res.core_address) === BigInt(this.core.address),
|
|
643
|
+
)
|
|
644
|
+
.map(
|
|
645
|
+
info =>
|
|
646
|
+
new PoolKey(
|
|
647
|
+
BigInt(info.token0),
|
|
648
|
+
BigInt(info.token1),
|
|
649
|
+
new PoolConfig(
|
|
650
|
+
info.tick_spacing,
|
|
651
|
+
BigInt(info.fee),
|
|
652
|
+
BigInt(info.extension),
|
|
653
|
+
),
|
|
654
|
+
),
|
|
655
|
+
);
|
|
656
|
+
}
|
|
657
|
+
}
|