@paraswap/dex-lib 4.1.9 → 4.1.10
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/.idea/aws.xml +17 -0
- package/.idea/codeStyles/Project.xml +4 -44
- package/.idea/codeStyles/codeStyleConfig.xml +1 -1
- package/.idea/misc.xml +6 -0
- package/.idea/paraswap-dex-lib.iml +4 -7
- package/.idea/prettier.xml +1 -1
- package/build/abi/AaveV1_lending_pool.json +27 -0
- package/build/abi/integral/factory.json +333 -0
- package/build/abi/integral/oracle.json +501 -0
- package/build/abi/integral/pool.json +1041 -0
- package/build/abi/integral/relayer.json +1536 -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-v4/pool-manager.abi.json +1366 -0
- package/build/abi/uniswap-v4/quoter.abi.json +461 -0
- package/build/abi/uniswap-v4/router.abi.json +230 -0
- package/build/abi/uniswap-v4/state-view.abi.json +365 -0
- package/build/dex/aave-v1/aave-v1.d.ts +33 -0
- package/build/dex/aave-v1/aave-v1.js +158 -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/bProtocol.d.ts +18 -0
- package/build/dex/bProtocol.js +39 -0
- package/build/dex/bProtocol.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/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-generate-pool.d.ts +49 -0
- package/build/dex/fluid-dex/fluid-dex-generate-pool.js +104 -0
- package/build/dex/fluid-dex/fluid-dex-generate-pool.js.map +1 -0
- package/build/dex/integral/config.d.ts +4 -0
- package/build/dex/integral/config.js +20 -0
- package/build/dex/integral/config.js.map +1 -0
- package/build/dex/integral/context.d.ts +40 -0
- package/build/dex/integral/context.js +158 -0
- package/build/dex/integral/context.js.map +1 -0
- package/build/dex/integral/integral-factory.d.ts +24 -0
- package/build/dex/integral/integral-factory.js +95 -0
- package/build/dex/integral/integral-factory.js.map +1 -0
- package/build/dex/integral/integral-pool.d.ts +50 -0
- package/build/dex/integral/integral-pool.js +149 -0
- package/build/dex/integral/integral-pool.js.map +1 -0
- package/build/dex/integral/integral-pricing.d.ts +18 -0
- package/build/dex/integral/integral-pricing.js +114 -0
- package/build/dex/integral/integral-pricing.js.map +1 -0
- package/build/dex/integral/integral-relayer.d.ts +42 -0
- package/build/dex/integral/integral-relayer.js +192 -0
- package/build/dex/integral/integral-relayer.js.map +1 -0
- package/build/dex/integral/integral-token.d.ts +27 -0
- package/build/dex/integral/integral-token.js +59 -0
- package/build/dex/integral/integral-token.js.map +1 -0
- package/build/dex/integral/integral.d.ts +41 -0
- package/build/dex/integral/integral.js +376 -0
- package/build/dex/integral/integral.js.map +1 -0
- package/build/dex/integral/types.d.ts +85 -0
- package/build/dex/integral/types.js +9 -0
- package/build/dex/integral/types.js.map +1 -0
- package/build/dex/integral/utils-e2e.d.ts +9 -0
- package/build/dex/integral/utils-e2e.js +131 -0
- package/build/dex/integral/utils-e2e.js.map +1 -0
- package/build/dex/integral/utils.d.ts +17 -0
- package/build/dex/integral/utils.js +94 -0
- package/build/dex/integral/utils.js.map +1 -0
- package/build/dex/jarvis.d.ts +1 -2
- package/build/dex/jarvis.js +0 -58
- package/build/dex/jarvis.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/m-token/config.d.ts +3 -0
- package/build/dex/m-token/config.js +19 -0
- package/build/dex/m-token/config.js.map +1 -0
- package/build/dex/m-token/m-token.d.ts +29 -0
- package/build/dex/m-token/m-token.js +145 -0
- package/build/dex/m-token/m-token.js.map +1 -0
- package/build/dex/m-token/m-wrapped-m.d.ts +17 -0
- package/build/dex/m-token/m-wrapped-m.js +50 -0
- package/build/dex/m-token/m-wrapped-m.js.map +1 -0
- package/build/dex/m-token/types.d.ts +12 -0
- package/build/dex/m-token/types.js +3 -0
- package/build/dex/m-token/types.js.map +1 -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/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 +62 -0
- package/build/dex/platypus/platypus.js +442 -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/smoothy.d.ts +26 -0
- package/build/dex/smoothy.js +48 -0
- package/build/dex/smoothy.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/stable-pool.d.ts +28 -0
- package/build/dex/stable-pool.js +62 -0
- package/build/dex/stable-pool.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 +61 -0
- package/build/dex/swaap-v1/swaap-v1.js +369 -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/trader-joe-v2.1/optimizer.d.ts +2 -0
- package/build/dex/trader-joe-v2.1/optimizer.js +47 -0
- package/build/dex/trader-joe-v2.1/optimizer.js.map +1 -0
- 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-v4/config.d.ts +3 -0
- package/build/dex/uniswap-v4/config.js +58 -0
- package/build/dex/uniswap-v4/config.js.map +1 -0
- package/build/dex/uniswap-v4/constants.d.ts +7 -0
- package/build/dex/uniswap-v4/constants.js +18 -0
- package/build/dex/uniswap-v4/constants.js.map +1 -0
- package/build/dex/uniswap-v4/contract-math/BitMath.d.ts +4 -0
- package/build/dex/uniswap-v4/contract-math/BitMath.js +93 -0
- package/build/dex/uniswap-v4/contract-math/BitMath.js.map +1 -0
- package/build/dex/uniswap-v4/contract-math/FixedPoint128.d.ts +3 -0
- package/build/dex/uniswap-v4/contract-math/FixedPoint128.js +8 -0
- package/build/dex/uniswap-v4/contract-math/FixedPoint128.js.map +1 -0
- package/build/dex/uniswap-v4/contract-math/FixedPoint96.d.ts +4 -0
- package/build/dex/uniswap-v4/contract-math/FixedPoint96.js +9 -0
- package/build/dex/uniswap-v4/contract-math/FixedPoint96.js.map +1 -0
- package/build/dex/uniswap-v4/contract-math/FullMath.d.ts +4 -0
- package/build/dex/uniswap-v4/contract-math/FullMath.js +19 -0
- package/build/dex/uniswap-v4/contract-math/FullMath.js.map +1 -0
- package/build/dex/uniswap-v4/contract-math/LiquidityMath.d.ts +3 -0
- package/build/dex/uniswap-v4/contract-math/LiquidityMath.js +22 -0
- package/build/dex/uniswap-v4/contract-math/LiquidityMath.js.map +1 -0
- package/build/dex/uniswap-v4/contract-math/SqrtPriceMath.d.ts +10 -0
- package/build/dex/uniswap-v4/contract-math/SqrtPriceMath.js +91 -0
- package/build/dex/uniswap-v4/contract-math/SqrtPriceMath.js.map +1 -0
- package/build/dex/uniswap-v4/contract-math/SwapMath.d.ts +8 -0
- package/build/dex/uniswap-v4/contract-math/SwapMath.js +70 -0
- package/build/dex/uniswap-v4/contract-math/SwapMath.js.map +1 -0
- package/build/dex/uniswap-v4/contract-math/TickBitMap.d.ts +7 -0
- package/build/dex/uniswap-v4/contract-math/TickBitMap.js +86 -0
- package/build/dex/uniswap-v4/contract-math/TickBitMap.js.map +1 -0
- package/build/dex/uniswap-v4/contract-math/TickMath.d.ts +8 -0
- package/build/dex/uniswap-v4/contract-math/TickMath.js +162 -0
- package/build/dex/uniswap-v4/contract-math/TickMath.js.map +1 -0
- package/build/dex/uniswap-v4/contract-math/UnsafeMath.d.ts +3 -0
- package/build/dex/uniswap-v4/contract-math/UnsafeMath.js +10 -0
- package/build/dex/uniswap-v4/contract-math/UnsafeMath.js.map +1 -0
- package/build/dex/uniswap-v4/contract-math/uniswap-v4-math.d.ts +8 -0
- package/build/dex/uniswap-v4/contract-math/uniswap-v4-math.js +12 -0
- package/build/dex/uniswap-v4/contract-math/uniswap-v4-math.js.map +1 -0
- package/build/dex/uniswap-v4/encoder.d.ts +16 -0
- package/build/dex/uniswap-v4/encoder.js +104 -0
- package/build/dex/uniswap-v4/encoder.js.map +1 -0
- package/build/dex/uniswap-v4/subgraph.d.ts +5 -0
- package/build/dex/uniswap-v4/subgraph.js +80 -0
- package/build/dex/uniswap-v4/subgraph.js.map +1 -0
- package/build/dex/uniswap-v4/types.d.ts +64 -0
- package/build/dex/uniswap-v4/types.js +3 -0
- package/build/dex/uniswap-v4/types.js.map +1 -0
- package/build/dex/uniswap-v4/uniswap-v4-pool-manager.d.ts +30 -0
- package/build/dex/uniswap-v4/uniswap-v4-pool-manager.js +139 -0
- package/build/dex/uniswap-v4/uniswap-v4-pool-manager.js.map +1 -0
- package/build/dex/uniswap-v4/uniswap-v4.d.ts +38 -0
- package/build/dex/uniswap-v4/uniswap-v4.js +169 -0
- package/build/dex/uniswap-v4/uniswap-v4.js.map +1 -0
- package/build/dex/uniswap-v4/utils.d.ts +2 -0
- package/build/dex/uniswap-v4/utils.js +15 -0
- package/build/dex/uniswap-v4/utils.js.map +1 -0
- package/build/dex/zerox/index.d.ts +25 -3
- package/build/dex/zerox/index.js +42 -50
- package/build/dex/zerox/index.js.map +1 -1
- package/build/dex/zerox/types.d.ts +0 -29
- package/build/dex/zerox/types.js +1 -8
- package/build/dex/zerox/types.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/package.json +2 -2
- 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-helper/dummy-dex-helper.ts +10 -0
- package/tests/constants-e2e.ts +10 -0
- package/tests/utils-e2e.ts +0 -1
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/scripts/get-uniswap-v3-dexes.ts +0 -64
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.querySinglePoolFromSubgraphById = querySinglePoolFromSubgraphById;
|
|
4
|
+
exports.queryOnePageForAllAvailablePoolsFromSubgraph = queryOnePageForAllAvailablePoolsFromSubgraph;
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
async function querySinglePoolFromSubgraphById(dexHelper, subgraphUrl, blockNumber, id) {
|
|
7
|
+
const ticksLimit = 200;
|
|
8
|
+
const poolQuery = `query {
|
|
9
|
+
pools(
|
|
10
|
+
block: { number: ${blockNumber} },
|
|
11
|
+
where: {id: "${id}"}
|
|
12
|
+
) {
|
|
13
|
+
id
|
|
14
|
+
fee: feeTier
|
|
15
|
+
tickSpacing
|
|
16
|
+
token0 {
|
|
17
|
+
address: id
|
|
18
|
+
}
|
|
19
|
+
token1 {
|
|
20
|
+
address: id
|
|
21
|
+
}
|
|
22
|
+
hooks
|
|
23
|
+
}
|
|
24
|
+
}`;
|
|
25
|
+
// tick
|
|
26
|
+
// ticks(first: ${ticksLimit}) {
|
|
27
|
+
// id
|
|
28
|
+
// liquidityGross
|
|
29
|
+
// liquidityNet
|
|
30
|
+
// tickIdx
|
|
31
|
+
// }
|
|
32
|
+
const { data } = await dexHelper.httpRequest.querySubgraph(subgraphUrl, {
|
|
33
|
+
query: poolQuery,
|
|
34
|
+
variables: {},
|
|
35
|
+
}, { timeout: constants_1.SUBGRAPH_TIMEOUT });
|
|
36
|
+
return data.pools[0] || null;
|
|
37
|
+
}
|
|
38
|
+
async function queryOnePageForAllAvailablePoolsFromSubgraph(dexHelper, logger, dexKey, subgraphUrl, blockNumber, skip, limit, latestBlock = false) {
|
|
39
|
+
const ticksLimit = 200;
|
|
40
|
+
const poolsQuery = `query ($skip: Int!) {
|
|
41
|
+
pools(
|
|
42
|
+
${latestBlock ? '' : `block: { number: ${blockNumber} }`}
|
|
43
|
+
orderBy: volumeUSD
|
|
44
|
+
orderDirection: desc
|
|
45
|
+
skip: $skip
|
|
46
|
+
first: ${limit}
|
|
47
|
+
) {
|
|
48
|
+
id
|
|
49
|
+
fee: feeTier
|
|
50
|
+
tickSpacing
|
|
51
|
+
token0 {
|
|
52
|
+
address: id
|
|
53
|
+
}
|
|
54
|
+
token1 {
|
|
55
|
+
address: id
|
|
56
|
+
}
|
|
57
|
+
hooks
|
|
58
|
+
}
|
|
59
|
+
}`;
|
|
60
|
+
// console.log('poolsQuery: ', poolsQuery);
|
|
61
|
+
//tick
|
|
62
|
+
// ticks(first: ${ticksLimit}) {
|
|
63
|
+
// id
|
|
64
|
+
// liquidityGross
|
|
65
|
+
// liquidityNet
|
|
66
|
+
// tickIdx
|
|
67
|
+
// }
|
|
68
|
+
const res = await dexHelper.httpRequest.querySubgraph(subgraphUrl, {
|
|
69
|
+
query: poolsQuery,
|
|
70
|
+
variables: { skip: skip },
|
|
71
|
+
}, { timeout: constants_1.SUBGRAPH_TIMEOUT });
|
|
72
|
+
if (res.errors &&
|
|
73
|
+
res.errors.length &&
|
|
74
|
+
res.errors[0].message.includes('missing block')) {
|
|
75
|
+
logger.info(`${dexKey}: subgraph fallback to the latest block...`);
|
|
76
|
+
return queryOnePageForAllAvailablePoolsFromSubgraph(dexHelper, logger, dexKey, subgraphUrl, blockNumber, skip, limit, true);
|
|
77
|
+
}
|
|
78
|
+
return res.data.pools;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=subgraph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subgraph.js","sourceRoot":"","sources":["../../../src/dex/uniswap-v4/subgraph.ts"],"names":[],"mappings":";;AAKA,0EAgDC;AAED,oGA4EC;AAlID,2CAA+C;AAIxC,KAAK,UAAU,+BAA+B,CACnD,SAAqB,EACrB,WAAmB,EACnB,WAAmB,EACnB,EAAU;IAEV,MAAM,UAAU,GAAG,GAAG,CAAC;IAEvB,MAAM,SAAS,GAAG;;2BAEO,WAAW;uBACf,EAAE;;;;;;;;;;;;;IAarB,CAAC;IAEH,cAAc;IACd,uCAAuC;IACvC,eAAe;IACf,2BAA2B;IAC3B,yBAAyB;IACzB,oBAAoB;IACpB,YAAY;IAEZ,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,SAAS,CAAC,WAAW,CAAC,aAAa,CAK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xB,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Address } from '../../types';
|
|
2
|
+
export type Tick = {
|
|
3
|
+
id: string;
|
|
4
|
+
tickIdx: string;
|
|
5
|
+
liquidityGross: string;
|
|
6
|
+
liquidityNet: string;
|
|
7
|
+
};
|
|
8
|
+
export type PoolManagerState = {
|
|
9
|
+
_pools: PoolState[];
|
|
10
|
+
};
|
|
11
|
+
export type PoolState = {
|
|
12
|
+
id: string;
|
|
13
|
+
token0: Address;
|
|
14
|
+
token1: Address;
|
|
15
|
+
fee: string;
|
|
16
|
+
tickSpacing: string;
|
|
17
|
+
hooks: string;
|
|
18
|
+
tick?: number;
|
|
19
|
+
ticks?: Tick[];
|
|
20
|
+
};
|
|
21
|
+
export type UniswapV4Data = {
|
|
22
|
+
exchange: Address;
|
|
23
|
+
zeroForOne: boolean;
|
|
24
|
+
pool: Pool;
|
|
25
|
+
};
|
|
26
|
+
export type Pool = {
|
|
27
|
+
id: string;
|
|
28
|
+
key: PoolKey;
|
|
29
|
+
};
|
|
30
|
+
export type SubgraphPool = {
|
|
31
|
+
id: string;
|
|
32
|
+
fee: string;
|
|
33
|
+
hooks: string;
|
|
34
|
+
token0: {
|
|
35
|
+
address: string;
|
|
36
|
+
};
|
|
37
|
+
token1: {
|
|
38
|
+
address: string;
|
|
39
|
+
};
|
|
40
|
+
tick: string;
|
|
41
|
+
tickSpacing: string;
|
|
42
|
+
ticks: Tick[];
|
|
43
|
+
};
|
|
44
|
+
export type DexParams = {
|
|
45
|
+
poolManager: Address;
|
|
46
|
+
quoter: Address;
|
|
47
|
+
router: Address;
|
|
48
|
+
subgraphURL: string;
|
|
49
|
+
stateView: string;
|
|
50
|
+
};
|
|
51
|
+
export type PoolKey = {
|
|
52
|
+
currency0: Address;
|
|
53
|
+
currency1: Address;
|
|
54
|
+
fee: string;
|
|
55
|
+
tickSpacing: string;
|
|
56
|
+
hooks: Address;
|
|
57
|
+
tick?: string;
|
|
58
|
+
ticks?: {
|
|
59
|
+
id: string;
|
|
60
|
+
tickIdx: string;
|
|
61
|
+
liquidityGross: string;
|
|
62
|
+
liquidityNet: string;
|
|
63
|
+
}[];
|
|
64
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/dex/uniswap-v4/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { InitializeStateOptions, StatefulEventSubscriber } from '../../stateful-event-subscriber';
|
|
2
|
+
import { Pool, PoolManagerState } from './types';
|
|
3
|
+
import { Address, Log, Logger } from '../../types';
|
|
4
|
+
import { BlockHeader } from 'web3-eth';
|
|
5
|
+
import { Interface } from 'ethers/lib/utils';
|
|
6
|
+
import { IDexHelper } from '../../dex-helper';
|
|
7
|
+
import { AsyncOrSync, DeepReadonly } from 'ts-essentials';
|
|
8
|
+
import { LogDescription } from '@ethersproject/abi/lib.esm';
|
|
9
|
+
export declare class UniswapV4PoolManager extends StatefulEventSubscriber<PoolManagerState> {
|
|
10
|
+
readonly dexHelper: IDexHelper;
|
|
11
|
+
private readonly network;
|
|
12
|
+
private readonly poolManagerAddress;
|
|
13
|
+
private readonly stateViewAddress;
|
|
14
|
+
private readonly subgraphUrl;
|
|
15
|
+
protected logger: Logger;
|
|
16
|
+
handlers: {
|
|
17
|
+
[event: string]: (event: any, pool: PoolManagerState, log: Log, blockHeader: Readonly<BlockHeader>) => AsyncOrSync<PoolManagerState>;
|
|
18
|
+
};
|
|
19
|
+
logDecoder: (log: Log) => any;
|
|
20
|
+
stateViewIface: Interface;
|
|
21
|
+
poolManagerIface: Interface;
|
|
22
|
+
private poolsCacheKey;
|
|
23
|
+
constructor(dexHelper: IDexHelper, parentName: string, network: number, poolManagerAddress: string, stateViewAddress: string, subgraphUrl: string, logger: Logger, mapKey?: string);
|
|
24
|
+
initialize(blockNumber: number, options?: InitializeStateOptions<PoolManagerState>): Promise<void>;
|
|
25
|
+
protected processLog(state: PoolManagerState, log: Readonly<Log>, blockHeader: Readonly<BlockHeader>): Promise<DeepReadonly<PoolManagerState>>;
|
|
26
|
+
getAvailablePoolsForPair(srcToken: Address, destToken: Address, blockNumber: number): Pool[];
|
|
27
|
+
private queryAllAvailablePools;
|
|
28
|
+
generateState(blockNumber: number): Promise<PoolManagerState>;
|
|
29
|
+
handleInitializeEvent(event: LogDescription, state: PoolManagerState, log: Log): Promise<PoolManagerState>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
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.UniswapV4PoolManager = void 0;
|
|
7
|
+
const stateful_event_subscriber_1 = require("../../stateful-event-subscriber");
|
|
8
|
+
const state_view_abi_json_1 = __importDefault(require("../../abi/uniswap-v4/state-view.abi.json"));
|
|
9
|
+
const pool_manager_abi_json_1 = __importDefault(require("../../abi/uniswap-v4/pool-manager.abi.json"));
|
|
10
|
+
const utils_1 = require("ethers/lib/utils");
|
|
11
|
+
const subgraph_1 = require("./subgraph");
|
|
12
|
+
const utils_2 = require("../../utils");
|
|
13
|
+
const constants_1 = require("../../constants");
|
|
14
|
+
const constants_2 = require("./constants");
|
|
15
|
+
const ethers_1 = require("ethers");
|
|
16
|
+
const utils_3 = require("./utils");
|
|
17
|
+
class UniswapV4PoolManager extends stateful_event_subscriber_1.StatefulEventSubscriber {
|
|
18
|
+
dexHelper;
|
|
19
|
+
network;
|
|
20
|
+
poolManagerAddress;
|
|
21
|
+
stateViewAddress;
|
|
22
|
+
subgraphUrl;
|
|
23
|
+
logger;
|
|
24
|
+
handlers = {};
|
|
25
|
+
logDecoder;
|
|
26
|
+
stateViewIface;
|
|
27
|
+
poolManagerIface;
|
|
28
|
+
poolsCacheKey = 'pools_states';
|
|
29
|
+
constructor(dexHelper, parentName, network, poolManagerAddress, stateViewAddress, subgraphUrl, logger, mapKey = '') {
|
|
30
|
+
super(parentName, `${parentName} PoolManager`, dexHelper, logger, true, mapKey);
|
|
31
|
+
this.dexHelper = dexHelper;
|
|
32
|
+
this.network = network;
|
|
33
|
+
this.poolManagerAddress = poolManagerAddress;
|
|
34
|
+
this.stateViewAddress = stateViewAddress;
|
|
35
|
+
this.subgraphUrl = subgraphUrl;
|
|
36
|
+
this.logger = logger;
|
|
37
|
+
this.stateViewIface = new utils_1.Interface(state_view_abi_json_1.default);
|
|
38
|
+
this.poolManagerIface = new utils_1.Interface(pool_manager_abi_json_1.default);
|
|
39
|
+
this.addressesSubscribed = [poolManagerAddress];
|
|
40
|
+
this.logDecoder = (log) => this.poolManagerIface.parseLog(log);
|
|
41
|
+
// Add handlers
|
|
42
|
+
this.handlers['Initialize'] = this.handleInitializeEvent.bind(this);
|
|
43
|
+
}
|
|
44
|
+
async initialize(blockNumber, options) {
|
|
45
|
+
await super.initialize(blockNumber, options);
|
|
46
|
+
}
|
|
47
|
+
async processLog(state, log, blockHeader) {
|
|
48
|
+
const event = this.logDecoder(log);
|
|
49
|
+
if (event.name in this.handlers) {
|
|
50
|
+
await this.handlers[event.name](event, state, log, blockHeader);
|
|
51
|
+
}
|
|
52
|
+
return state;
|
|
53
|
+
}
|
|
54
|
+
getAvailablePoolsForPair(srcToken, destToken, blockNumber) {
|
|
55
|
+
const isEthSrc = (0, utils_2.isETHAddress)(srcToken);
|
|
56
|
+
const isEthDest = (0, utils_2.isETHAddress)(destToken);
|
|
57
|
+
const src = isEthSrc ? constants_1.NULL_ADDRESS : srcToken.toLowerCase();
|
|
58
|
+
const dest = isEthDest ? constants_1.NULL_ADDRESS : destToken.toLowerCase();
|
|
59
|
+
const state = this.getState(blockNumber);
|
|
60
|
+
if (!state) {
|
|
61
|
+
ethers_1.logger.info(`${this.name} PoolManager: state was not found blocknumber: ${blockNumber}`);
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
const poolStates = state._pools.filter(pool => (pool.token0 === src && pool.token1 === dest) ||
|
|
65
|
+
(pool.token0 === dest && pool.token1 === src));
|
|
66
|
+
return poolStates.map(state => ({
|
|
67
|
+
id: state.id,
|
|
68
|
+
key: {
|
|
69
|
+
currency0: state.token0,
|
|
70
|
+
currency1: state.token1,
|
|
71
|
+
fee: state.fee,
|
|
72
|
+
tickSpacing: state.tickSpacing,
|
|
73
|
+
hooks: state.hooks,
|
|
74
|
+
},
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
async queryAllAvailablePools(blockNumber) {
|
|
78
|
+
const cachedPools = await this.dexHelper.cache.getAndCacheLocally(this.parentName, this.network, this.poolsCacheKey, constants_2.POOL_CACHE_REFRESH_INTERVAL);
|
|
79
|
+
if (cachedPools) {
|
|
80
|
+
const pools = JSON.parse(cachedPools);
|
|
81
|
+
return pools;
|
|
82
|
+
}
|
|
83
|
+
let pools = [];
|
|
84
|
+
let curPage = 0;
|
|
85
|
+
const limit = 1000;
|
|
86
|
+
let currentPools = await (0, subgraph_1.queryOnePageForAllAvailablePoolsFromSubgraph)(this.dexHelper, this.logger, this.parentName, this.subgraphUrl, blockNumber, curPage * limit, limit);
|
|
87
|
+
pools = pools.concat(currentPools);
|
|
88
|
+
while (currentPools.length === limit) {
|
|
89
|
+
curPage++;
|
|
90
|
+
currentPools = await (0, subgraph_1.queryOnePageForAllAvailablePoolsFromSubgraph)(this.dexHelper, this.logger, this.parentName, this.subgraphUrl, blockNumber, curPage * limit, limit);
|
|
91
|
+
pools = pools.concat(currentPools);
|
|
92
|
+
}
|
|
93
|
+
const results = pools
|
|
94
|
+
.map(pool => ({
|
|
95
|
+
id: pool.id,
|
|
96
|
+
token0: pool.token0.address,
|
|
97
|
+
token1: pool.token1.address,
|
|
98
|
+
fee: pool.fee,
|
|
99
|
+
tickSpacing: pool.tickSpacing,
|
|
100
|
+
hooks: pool.hooks,
|
|
101
|
+
// tick: parseInt(pool.tick),
|
|
102
|
+
// ticks: pool.ticks,
|
|
103
|
+
}))
|
|
104
|
+
.sort(utils_3.sortPools);
|
|
105
|
+
this.dexHelper.cache.setexAndCacheLocally(this.parentName, this.network, this.poolsCacheKey, constants_2.POOL_CACHE_REFRESH_INTERVAL, JSON.stringify(results));
|
|
106
|
+
return results;
|
|
107
|
+
}
|
|
108
|
+
async generateState(blockNumber) {
|
|
109
|
+
const pools = await this.queryAllAvailablePools(blockNumber);
|
|
110
|
+
return {
|
|
111
|
+
_pools: pools,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
async handleInitializeEvent(event, state, log) {
|
|
115
|
+
const id = event.args.id.toLowerCase();
|
|
116
|
+
const subgraphPool = await (0, subgraph_1.querySinglePoolFromSubgraphById)(this.dexHelper, this.subgraphUrl, log.blockNumber, id);
|
|
117
|
+
if (subgraphPool) {
|
|
118
|
+
const newPool = {
|
|
119
|
+
id: subgraphPool.id,
|
|
120
|
+
token0: subgraphPool.token0.address,
|
|
121
|
+
token1: subgraphPool.token1.address,
|
|
122
|
+
fee: subgraphPool.fee,
|
|
123
|
+
tickSpacing: subgraphPool.tickSpacing,
|
|
124
|
+
hooks: subgraphPool.hooks,
|
|
125
|
+
// tick: parseInt(subgraphPool.tick),
|
|
126
|
+
// ticks: subgraphPool.ticks,
|
|
127
|
+
};
|
|
128
|
+
const pools = state._pools;
|
|
129
|
+
pools.push(newPool);
|
|
130
|
+
state = {
|
|
131
|
+
...state,
|
|
132
|
+
_pools: pools.sort(utils_3.sortPools),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
return state;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
exports.UniswapV4PoolManager = UniswapV4PoolManager;
|
|
139
|
+
//# sourceMappingURL=uniswap-v4-pool-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uniswap-v4-pool-manager.js","sourceRoot":"","sources":["../../../src/dex/uniswap-v4/uniswap-v4-pool-manager.ts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EAAE,CAAC,WAAW,EAAE,CAAC;QAEvC,MAAM,YAAY,GAAG,MAAM,IAAA,0CAA+B,EACxD,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,WAAW,EAChB,GAAG,CAAC,WAAW,EACf,EAAE,CACH,CAAC;QAEF,IAAI,YAAY,EAAE,CAAC;YACjB,MAAM,OAAO,GAAG;gBACd,EAAE,EAAE,YAAY,CAAC,EAAE;gBACnB,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,OAAO;gBACnC,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,OAAO;gBACnC,GAAG,EAAE,YAAY,CAAC,GAAG;gBACrB,WAAW,EAAE,YAAY,CAAC,WAAW;gBACrC,KAAK,EAAE,YAAY,CAAC,KAAK;gBACzB,qCAAqC;gBACrC,6BAA6B;aACjB,CAAC;YAEf,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC;YAC3B,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAEpB,KAAK,GAAG;gBACN,GAAG,KAAK;gBACR,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,iBAAS,CAAC;aAC9B,CAAC;QACJ,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AA3ND,oDA2NC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { AdapterExchangeParam, Address, DexExchangeParam, NumberAsString, Token } from '../../types';
|
|
2
|
+
import { Logger } from 'log4js';
|
|
3
|
+
import { Network, SwapSide } from '../../constants';
|
|
4
|
+
import { IDexHelper } from '../../dex-helper';
|
|
5
|
+
import { ExchangePrices, PoolPrices, PoolLiquidity } from '../../types';
|
|
6
|
+
import { IDex } from '../idex';
|
|
7
|
+
import { SimpleExchange } from '../simple-exchange';
|
|
8
|
+
import { Pool, UniswapV4Data } from './types';
|
|
9
|
+
import { Interface } from '@ethersproject/abi';
|
|
10
|
+
export declare class UniswapV4 extends SimpleExchange implements IDex<UniswapV4Data> {
|
|
11
|
+
protected network: Network;
|
|
12
|
+
protected dexHelper: IDexHelper;
|
|
13
|
+
protected routerAddress: string;
|
|
14
|
+
protected quoterAddress: string;
|
|
15
|
+
protected poolManagerAddress: string;
|
|
16
|
+
readonly hasConstantPriceLargeAmounts = false;
|
|
17
|
+
needWrapNative: boolean;
|
|
18
|
+
logger: Logger;
|
|
19
|
+
protected quoterIface: Interface;
|
|
20
|
+
private poolManager;
|
|
21
|
+
static dexKeysWithNetwork: {
|
|
22
|
+
key: string;
|
|
23
|
+
networks: Network[];
|
|
24
|
+
}[];
|
|
25
|
+
constructor(network: Network, dexKey: string, dexHelper: IDexHelper, routerAddress?: string, quoterAddress?: string, poolManagerAddress?: string);
|
|
26
|
+
initializePricing(blockNumber: number): Promise<void>;
|
|
27
|
+
getPoolIdentifiers(from: Token, to: Token, side: SwapSide, blockNumber: number): Promise<string[]>;
|
|
28
|
+
getPricesVolume(from: Token, to: Token, amounts: bigint[], side: SwapSide, blockNumber: number, limitPools?: string[]): Promise<ExchangePrices<UniswapV4Data> | null>;
|
|
29
|
+
getCalldataGasCost(poolPrices: PoolPrices<UniswapV4Data>): number | number[];
|
|
30
|
+
getAdapters(side: SwapSide): {
|
|
31
|
+
name: string;
|
|
32
|
+
index: number;
|
|
33
|
+
}[] | null;
|
|
34
|
+
getTopPoolsForToken(tokenAddress: Address, count: number): Promise<PoolLiquidity[]>;
|
|
35
|
+
queryPrice(zeroForOne: boolean, amounts: bigint[], pool: Pool): Promise<bigint[]>;
|
|
36
|
+
getDexParam(srcToken: Address, destToken: Address, srcAmount: NumberAsString, destAmount: NumberAsString, recipient: Address, data: UniswapV4Data, side: SwapSide): DexExchangeParam;
|
|
37
|
+
getAdapterParam(srcToken: string, destToken: string, srcAmount: string, destAmount: string, data: UniswapV4Data, side: SwapSide): AdapterExchangeParam;
|
|
38
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.UniswapV4 = void 0;
|
|
40
|
+
const lodash_1 = require("lodash");
|
|
41
|
+
const constants_1 = require("../../constants");
|
|
42
|
+
const utils_1 = require("../../utils");
|
|
43
|
+
const simple_exchange_1 = require("../simple-exchange");
|
|
44
|
+
const config_1 = require("./config");
|
|
45
|
+
const CALLDATA_GAS_COST = __importStar(require("../../calldata-gas-cost"));
|
|
46
|
+
const quoter_abi_json_1 = __importDefault(require("../../abi/uniswap-v4/quoter.abi.json"));
|
|
47
|
+
const bigint_constants_1 = require("../../bigint-constants");
|
|
48
|
+
const abi_1 = require("@ethersproject/abi");
|
|
49
|
+
const decoders_1 = require("../../lib/decoders");
|
|
50
|
+
const encoder_1 = require("./encoder");
|
|
51
|
+
const uniswap_v4_pool_manager_1 = require("./uniswap-v4-pool-manager");
|
|
52
|
+
class UniswapV4 extends simple_exchange_1.SimpleExchange {
|
|
53
|
+
network;
|
|
54
|
+
dexHelper;
|
|
55
|
+
routerAddress;
|
|
56
|
+
quoterAddress;
|
|
57
|
+
poolManagerAddress;
|
|
58
|
+
hasConstantPriceLargeAmounts = false;
|
|
59
|
+
needWrapNative = false;
|
|
60
|
+
logger;
|
|
61
|
+
quoterIface;
|
|
62
|
+
poolManager;
|
|
63
|
+
static dexKeysWithNetwork = (0, utils_1.getDexKeysWithNetwork)(config_1.UniswapV4Config);
|
|
64
|
+
constructor(network, dexKey, dexHelper, routerAddress = config_1.UniswapV4Config[dexKey][network].router, quoterAddress = config_1.UniswapV4Config[dexKey][network].quoter, poolManagerAddress = config_1.UniswapV4Config[dexKey][network].poolManager) {
|
|
65
|
+
super(dexHelper, dexKey);
|
|
66
|
+
this.network = network;
|
|
67
|
+
this.dexHelper = dexHelper;
|
|
68
|
+
this.routerAddress = routerAddress;
|
|
69
|
+
this.quoterAddress = quoterAddress;
|
|
70
|
+
this.poolManagerAddress = poolManagerAddress;
|
|
71
|
+
this.logger = dexHelper.getLogger(dexKey);
|
|
72
|
+
this.quoterIface = new abi_1.Interface(quoter_abi_json_1.default);
|
|
73
|
+
this.poolManager = new uniswap_v4_pool_manager_1.UniswapV4PoolManager(dexHelper, dexKey, network, config_1.UniswapV4Config[dexKey][network].poolManager, config_1.UniswapV4Config[dexKey][network].stateView, config_1.UniswapV4Config[dexKey][network].subgraphURL, this.logger);
|
|
74
|
+
}
|
|
75
|
+
async initializePricing(blockNumber) {
|
|
76
|
+
await this.poolManager.initialize(blockNumber);
|
|
77
|
+
}
|
|
78
|
+
async getPoolIdentifiers(from, to, side, blockNumber) {
|
|
79
|
+
const pools = await this.poolManager.getAvailablePoolsForPair(from.address.toLowerCase(), to.address.toLowerCase(), blockNumber);
|
|
80
|
+
return pools.map(pool => pool.id);
|
|
81
|
+
}
|
|
82
|
+
async getPricesVolume(from, to, amounts, side, blockNumber, limitPools) {
|
|
83
|
+
if (side === constants_1.SwapSide.BUY)
|
|
84
|
+
return null;
|
|
85
|
+
const pools = await this.poolManager.getAvailablePoolsForPair(from.address.toLowerCase(), to.address.toLowerCase(), blockNumber);
|
|
86
|
+
const availablePools = limitPools?.filter(t => pools.find(p => p.id === t)) ??
|
|
87
|
+
pools.map(t => t.id);
|
|
88
|
+
const pricesPromises = availablePools.map(async (poolId) => {
|
|
89
|
+
const pool = pools.find(p => p.id === poolId);
|
|
90
|
+
const zeroForOne = from.address.toLowerCase() === pool.key.currency0.toLowerCase() ||
|
|
91
|
+
((0, utils_1.isETHAddress)(from.address) && pool.key.currency0 === constants_1.NULL_ADDRESS);
|
|
92
|
+
const prices = await this.queryPrice(zeroForOne, amounts, pool);
|
|
93
|
+
if (prices?.every(price => price === 0n || price === 1n)) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
unit: bigint_constants_1.BI_POWS[to.decimals],
|
|
98
|
+
prices,
|
|
99
|
+
data: {
|
|
100
|
+
exchange: this.dexKey,
|
|
101
|
+
pool: {
|
|
102
|
+
id: pool.id,
|
|
103
|
+
key: (0, lodash_1.omit)(pool.key, ['tick', 'ticks']),
|
|
104
|
+
},
|
|
105
|
+
zeroForOne,
|
|
106
|
+
},
|
|
107
|
+
poolAddresses: [this.poolManagerAddress],
|
|
108
|
+
exchange: this.dexKey,
|
|
109
|
+
gasCost: 100_000,
|
|
110
|
+
poolIdentifier: poolId,
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
const prices = await Promise.all(pricesPromises);
|
|
114
|
+
return prices.filter(res => res !== null);
|
|
115
|
+
}
|
|
116
|
+
// Returns estimated gas cost of calldata for this DEX in multiSwap
|
|
117
|
+
getCalldataGasCost(poolPrices) {
|
|
118
|
+
return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
|
|
119
|
+
}
|
|
120
|
+
getAdapters(side) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
async getTopPoolsForToken(tokenAddress, count) {
|
|
124
|
+
return [];
|
|
125
|
+
}
|
|
126
|
+
async queryPrice(zeroForOne, amounts, pool) {
|
|
127
|
+
const calls = amounts.map(amount => ({
|
|
128
|
+
target: this.quoterAddress,
|
|
129
|
+
callData: this.quoterIface.encodeFunctionData('quoteExactInputSingle', [
|
|
130
|
+
{
|
|
131
|
+
poolKey: pool.key,
|
|
132
|
+
zeroForOne,
|
|
133
|
+
exactAmount: amount.toString(),
|
|
134
|
+
hookData: '0x',
|
|
135
|
+
},
|
|
136
|
+
]),
|
|
137
|
+
decodeFunction: (result) => {
|
|
138
|
+
// amountOut, gasEstimate
|
|
139
|
+
return (0, decoders_1.generalDecoder)(result, ['uint256', 'uint256'], 0n, value => BigInt(value[0].toString()));
|
|
140
|
+
},
|
|
141
|
+
}));
|
|
142
|
+
const results = await this.dexHelper.multiWrapper.tryAggregate(false, calls);
|
|
143
|
+
return results.map(result => (result.success ? result.returnData : 0n));
|
|
144
|
+
}
|
|
145
|
+
getDexParam(srcToken, destToken, srcAmount, destAmount, recipient, data, side) {
|
|
146
|
+
const exchangeData = (0, encoder_1.swapExactInputSingleCalldata)(srcToken, destToken, data.pool.key, data.zeroForOne, BigInt(srcAmount),
|
|
147
|
+
// destMinAmount (can be 0 on dex level)
|
|
148
|
+
BigInt(0), recipient);
|
|
149
|
+
return {
|
|
150
|
+
needWrapNative: this.needWrapNative,
|
|
151
|
+
dexFuncHasRecipient: true,
|
|
152
|
+
exchangeData,
|
|
153
|
+
targetExchange: this.routerAddress,
|
|
154
|
+
permit2Approval: true,
|
|
155
|
+
returnAmountPos: undefined,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
getAdapterParam(srcToken, destToken, srcAmount, destAmount, data, side) {
|
|
159
|
+
const { exchange } = data;
|
|
160
|
+
const payload = '';
|
|
161
|
+
return {
|
|
162
|
+
targetExchange: exchange,
|
|
163
|
+
payload,
|
|
164
|
+
networkFee: '0',
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
exports.UniswapV4 = UniswapV4;
|
|
169
|
+
//# sourceMappingURL=uniswap-v4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uniswap-v4.js","sourceRoot":"","sources":["../../../src/dex/uniswap-v4/uniswap-v4.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAA8B;AAS9B,+CAAkE;AAGlE,uCAAkE;AAElE,wDAAoD;AACpD,qCAA2C;AAG3C,2EAA6D;AAC7D,2FAA6D;AAC7D,6DAAiD;AACjD,4CAA+C;AAC/C,iDAAoD;AAEpD,uCAAyD;AACzD,uEAAiE;AAEjE,MAAa,SAAU,SAAQ,gCAAc;IAa/B;IAEA;IACA;IACA;IACA;IAjBH,4BAA4B,GAAG,KAAK,CAAC;IAC9C,cAAc,GAAG,KAAK,CAAC;IAEvB,MAAM,CAAS;IACL,WAAW,CAAY;IAEzB,WAAW,CAAuB;IAEnC,MAAM,CAAC,kBAAkB,GAC9B,IAAA,6BAAqB,EAAC,wBAAe,CAAC,CAAC;IAEzC,YACY,OAAgB,EAC1B,MAAc,EACJ,SAAqB,EACrB,gBAAgB,wBAAe,CAAC,MAAM,CAAC,CAAC,OAAO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,CAAC;IAED,eAAe,CACb,QAAgB,EAChB,SAAiB,EACjB,SAAiB,EACjB,UAAkB,EAClB,IAAmB,EACnB,IAAc;QAEd,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QAE1B,MAAM,OAAO,GAAG,EAAE,CAAC;QAEnB,OAAO;YACL,cAAc,EAAE,QAAQ;YACxB,OAAO;YACP,UAAU,EAAE,GAAG;SAChB,CAAC;IACJ,CAAC;;AA1MH,8BA2MC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sortPools = sortPools;
|
|
4
|
+
function sortPools(a, b) {
|
|
5
|
+
const idA = a.id.toUpperCase();
|
|
6
|
+
const idB = b.id.toUpperCase();
|
|
7
|
+
if (idA < idB) {
|
|
8
|
+
return -1;
|
|
9
|
+
}
|
|
10
|
+
if (idA > idB) {
|
|
11
|
+
return 1;
|
|
12
|
+
}
|
|
13
|
+
return 0;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/dex/uniswap-v4/utils.ts"],"names":[],"mappings":";;AAEA,8BAUC;AAVD,SAAgB,SAAS,CAAC,CAAY,EAAE,CAAY;IAClD,MAAM,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC;IAC/B,MAAM,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC;IAC/B,IAAI,GAAG,GAAG,GAAG,EAAE,CAAC;QACd,OAAO,CAAC,CAAC,CAAC;IACZ,CAAC;IACD,IAAI,GAAG,GAAG,GAAG,EAAE,CAAC;QACd,OAAO,CAAC,CAAC;IACX,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC"}
|
|
@@ -2,9 +2,31 @@ import { Interface } from '@ethersproject/abi';
|
|
|
2
2
|
import { SwapSide } from '../../constants';
|
|
3
3
|
import { SimpleExchange } from '../simple-exchange';
|
|
4
4
|
import type { IDexTxBuilder } from '../idex';
|
|
5
|
-
import type { AdapterExchangeParam, Address,
|
|
6
|
-
import
|
|
5
|
+
import type { AdapterExchangeParam, Address, NumberAsString, SimpleExchangeParam, TxInfo } from '../../types';
|
|
6
|
+
import type { ZeroXSignedOrder } from './types';
|
|
7
7
|
import { IDexHelper } from '../../dex-helper';
|
|
8
|
+
declare type ZeroXData = {
|
|
9
|
+
version: number;
|
|
10
|
+
order: ZeroXSignedOrder;
|
|
11
|
+
};
|
|
12
|
+
declare type SwapOnZeroXParam = [
|
|
13
|
+
srcToken: Address,
|
|
14
|
+
destToken: Address,
|
|
15
|
+
srcAmount: NumberAsString,
|
|
16
|
+
destAmount: NumberAsString,
|
|
17
|
+
exchange: Address,
|
|
18
|
+
payload: string
|
|
19
|
+
];
|
|
20
|
+
declare type SwapOnZeroXWithPermitParam = [
|
|
21
|
+
srcToken: Address,
|
|
22
|
+
destToken: Address,
|
|
23
|
+
srcAmount: NumberAsString,
|
|
24
|
+
destAmount: NumberAsString,
|
|
25
|
+
exchange: Address,
|
|
26
|
+
payload: string,
|
|
27
|
+
permit: string
|
|
28
|
+
];
|
|
29
|
+
declare type ZeroXParam = SwapOnZeroXParam | SwapOnZeroXWithPermitParam;
|
|
8
30
|
export declare class ZeroX extends SimpleExchange implements IDexTxBuilder<ZeroXData, ZeroXParam> {
|
|
9
31
|
static dexKeys: string[];
|
|
10
32
|
routerInterface: Interface;
|
|
@@ -16,7 +38,7 @@ export declare class ZeroX extends SimpleExchange implements IDexTxBuilder<ZeroX
|
|
|
16
38
|
getAdapterParam(srcToken: Address, destToken: Address, srcAmount: NumberAsString, toAmount: NumberAsString, // required for buy case
|
|
17
39
|
data: ZeroXData, side: SwapSide): AdapterExchangeParam;
|
|
18
40
|
getSimpleParam(src: Address, dest: Address, srcAmount: NumberAsString, destAmount: NumberAsString, data: ZeroXData, side: SwapSide): Promise<SimpleExchangeParam>;
|
|
19
|
-
getDexParam(_srcToken: Address, _destToken: Address, srcAmount: NumberAsString, destAmount: NumberAsString, _recipient: Address, data: ZeroXData, side: SwapSide): DexExchangeParam;
|
|
20
41
|
getDirectParam(srcToken: Address, destToken: Address, srcAmount: NumberAsString, destAmount: NumberAsString, expectedAmount: NumberAsString, data: ZeroXData, side: SwapSide, permit: string, uuid: string, feePercent: NumberAsString, deadline: NumberAsString, partner: string, beneficiary: string, contractMethod?: string): TxInfo<ZeroXParam>;
|
|
21
42
|
static getDirectFunctionName(): string[];
|
|
22
43
|
}
|
|
44
|
+
export {};
|