genius-intents 0.18.2 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +73 -3
- package/dist/direct-pools/fourmeme/fourmeme-direct.service.js +16 -16
- package/dist/direct-pools/fourmeme/fourmeme-direct.service.js.map +1 -1
- package/dist/direct-pools/meteora/pool-info/meteora-damm-v1-pool-info.service.d.ts +1 -1
- package/dist/direct-pools/meteora/pool-info/meteora-damm-v1-pool-info.service.d.ts.map +1 -1
- package/dist/direct-pools/meteora/pool-info/meteora-damm-v1-pool-info.service.js +9 -2
- package/dist/direct-pools/meteora/pool-info/meteora-damm-v1-pool-info.service.js.map +1 -1
- package/dist/direct-pools/meteora/pool-info/meteora-damm-v2-pool-info.service.d.ts +1 -1
- package/dist/direct-pools/meteora/pool-info/meteora-damm-v2-pool-info.service.d.ts.map +1 -1
- package/dist/direct-pools/meteora/pool-info/meteora-damm-v2-pool-info.service.js +9 -2
- package/dist/direct-pools/meteora/pool-info/meteora-damm-v2-pool-info.service.js.map +1 -1
- package/dist/direct-pools/meteora/pool-info/meteora-dbc-pool-info.service.d.ts +1 -1
- package/dist/direct-pools/meteora/pool-info/meteora-dbc-pool-info.service.d.ts.map +1 -1
- package/dist/direct-pools/meteora/pool-info/meteora-dbc-pool-info.service.js +9 -2
- package/dist/direct-pools/meteora/pool-info/meteora-dbc-pool-info.service.js.map +1 -1
- package/dist/direct-pools/meteora/pool-info/meteora-dlmm-pool-info.service.d.ts +1 -1
- package/dist/direct-pools/meteora/pool-info/meteora-dlmm-pool-info.service.d.ts.map +1 -1
- package/dist/direct-pools/meteora/pool-info/meteora-dlmm-pool-info.service.js +9 -2
- package/dist/direct-pools/meteora/pool-info/meteora-dlmm-pool-info.service.js.map +1 -1
- package/dist/direct-pools/pump-fun/pool-info/pump-fun-pool-info.service.d.ts +1 -1
- package/dist/direct-pools/pump-fun/pool-info/pump-fun-pool-info.service.d.ts.map +1 -1
- package/dist/direct-pools/pump-fun/pool-info/pump-fun-pool-info.service.js +9 -2
- package/dist/direct-pools/pump-fun/pool-info/pump-fun-pool-info.service.js.map +1 -1
- package/dist/direct-pools/pump-fun/pool-info/pump-swap-amm-pool-info.service.d.ts +1 -1
- package/dist/direct-pools/pump-fun/pool-info/pump-swap-amm-pool-info.service.d.ts.map +1 -1
- package/dist/direct-pools/pump-fun/pool-info/pump-swap-amm-pool-info.service.js +9 -2
- package/dist/direct-pools/pump-fun/pool-info/pump-swap-amm-pool-info.service.js.map +1 -1
- package/dist/direct-pools/raydium/pool-info/raydium-amm-pool-info.service.d.ts +1 -1
- package/dist/direct-pools/raydium/pool-info/raydium-amm-pool-info.service.d.ts.map +1 -1
- package/dist/direct-pools/raydium/pool-info/raydium-amm-pool-info.service.js +9 -2
- package/dist/direct-pools/raydium/pool-info/raydium-amm-pool-info.service.js.map +1 -1
- package/dist/direct-pools/raydium/pool-info/raydium-clmm-pool-info.service.d.ts +1 -1
- package/dist/direct-pools/raydium/pool-info/raydium-clmm-pool-info.service.d.ts.map +1 -1
- package/dist/direct-pools/raydium/pool-info/raydium-clmm-pool-info.service.js +9 -2
- package/dist/direct-pools/raydium/pool-info/raydium-clmm-pool-info.service.js.map +1 -1
- package/dist/direct-pools/raydium/pool-info/raydium-cpmm-pool-info.service.d.ts +1 -1
- package/dist/direct-pools/raydium/pool-info/raydium-cpmm-pool-info.service.d.ts.map +1 -1
- package/dist/direct-pools/raydium/pool-info/raydium-cpmm-pool-info.service.js +9 -2
- package/dist/direct-pools/raydium/pool-info/raydium-cpmm-pool-info.service.js.map +1 -1
- package/dist/direct-pools/raydium/pool-info/raydium-launchlab-pool-info.service.d.ts +1 -1
- package/dist/direct-pools/raydium/pool-info/raydium-launchlab-pool-info.service.d.ts.map +1 -1
- package/dist/direct-pools/raydium/pool-info/raydium-launchlab-pool-info.service.js +9 -2
- package/dist/direct-pools/raydium/pool-info/raydium-launchlab-pool-info.service.js.map +1 -1
- package/dist/direct-pools/whirlpools/pool-info/whirlpools-pool-info.service.d.ts +1 -1
- package/dist/direct-pools/whirlpools/pool-info/whirlpools-pool-info.service.d.ts.map +1 -1
- package/dist/direct-pools/whirlpools/pool-info/whirlpools-pool-info.service.js +9 -2
- package/dist/direct-pools/whirlpools/pool-info/whirlpools-pool-info.service.js.map +1 -1
- package/dist/genius-intents.d.ts.map +1 -1
- package/dist/genius-intents.js +11 -2
- package/dist/genius-intents.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/dex/algebra/algebra-dex-deployments.d.ts +3 -0
- package/dist/lib/dex/algebra/algebra-dex-deployments.d.ts.map +1 -0
- package/dist/lib/dex/algebra/algebra-dex-deployments.js +34 -0
- package/dist/lib/dex/algebra/algebra-dex-deployments.js.map +1 -0
- package/dist/lib/dex/algebra/algebra-factory.abi.d.ts +3 -0
- package/dist/lib/dex/algebra/algebra-factory.abi.d.ts.map +1 -0
- package/dist/lib/dex/algebra/algebra-factory.abi.js +34 -0
- package/dist/lib/dex/algebra/algebra-factory.abi.js.map +1 -0
- package/dist/lib/dex/algebra/algebra-quoter.abi.d.ts +3 -0
- package/dist/lib/dex/algebra/algebra-quoter.abi.d.ts.map +1 -0
- package/dist/lib/dex/algebra/algebra-quoter.abi.js +135 -0
- package/dist/lib/dex/algebra/algebra-quoter.abi.js.map +1 -0
- package/dist/lib/dex/algebra/algebra-router.abi.d.ts +3 -0
- package/dist/lib/dex/algebra/algebra-router.abi.d.ts.map +1 -0
- package/dist/lib/dex/algebra/algebra-router.abi.js +273 -0
- package/dist/lib/dex/algebra/algebra-router.abi.js.map +1 -0
- package/dist/lib/dex/algebra/quickswap-quoter.abi.d.ts +3 -0
- package/dist/lib/dex/algebra/quickswap-quoter.abi.d.ts.map +1 -0
- package/dist/lib/dex/algebra/quickswap-quoter.abi.js +103 -0
- package/dist/lib/dex/algebra/quickswap-quoter.abi.js.map +1 -0
- package/dist/lib/dex/fourmeme/fourmeme-v3-helper.abi.d.ts +3 -0
- package/dist/lib/dex/fourmeme/fourmeme-v3-helper.abi.d.ts.map +1 -0
- package/dist/lib/dex/fourmeme/fourmeme-v3-helper.abi.js +61 -0
- package/dist/lib/dex/fourmeme/fourmeme-v3-helper.abi.js.map +1 -0
- package/dist/lib/dex/lfj/lfj-dex-deployments.d.ts +3 -0
- package/dist/lib/dex/lfj/lfj-dex-deployments.d.ts.map +1 -0
- package/dist/lib/dex/lfj/lfj-dex-deployments.js +21 -0
- package/dist/lib/dex/lfj/lfj-dex-deployments.js.map +1 -0
- package/dist/lib/dex/lfj/lfj-quoter.abi.d.ts +3 -0
- package/dist/lib/dex/lfj/lfj-quoter.abi.d.ts.map +1 -0
- package/dist/lib/dex/lfj/lfj-quoter.abi.js +135 -0
- package/dist/lib/dex/lfj/lfj-quoter.abi.js.map +1 -0
- package/dist/lib/dex/lfj/lfj-router.abi.d.ts +3 -0
- package/dist/lib/dex/lfj/lfj-router.abi.d.ts.map +1 -0
- package/dist/lib/dex/lfj/lfj-router.abi.js +587 -0
- package/dist/lib/dex/lfj/lfj-router.abi.js.map +1 -0
- package/dist/lib/dex/pair-discovery/adapters/algebra-dex-pair-discovery.adapter.d.ts +22 -0
- package/dist/lib/dex/pair-discovery/adapters/algebra-dex-pair-discovery.adapter.d.ts.map +1 -0
- package/dist/lib/dex/pair-discovery/adapters/algebra-dex-pair-discovery.adapter.js +225 -0
- package/dist/lib/dex/pair-discovery/adapters/algebra-dex-pair-discovery.adapter.js.map +1 -0
- package/dist/lib/dex/pair-discovery/adapters/fourmeme-dex-pair-discovery.adapter.d.ts +20 -0
- package/dist/lib/dex/pair-discovery/adapters/fourmeme-dex-pair-discovery.adapter.d.ts.map +1 -0
- package/dist/lib/dex/pair-discovery/adapters/fourmeme-dex-pair-discovery.adapter.js +265 -0
- package/dist/lib/dex/pair-discovery/adapters/fourmeme-dex-pair-discovery.adapter.js.map +1 -0
- package/dist/lib/dex/pair-discovery/adapters/lfj-v3-dex-pair-doscovery.adapter.d.ts +19 -0
- package/dist/lib/dex/pair-discovery/adapters/lfj-v3-dex-pair-doscovery.adapter.d.ts.map +1 -0
- package/dist/lib/dex/pair-discovery/adapters/lfj-v3-dex-pair-doscovery.adapter.js +130 -0
- package/dist/lib/dex/pair-discovery/adapters/lfj-v3-dex-pair-doscovery.adapter.js.map +1 -0
- package/dist/lib/dex/pair-discovery/adapters/v2-dex-pair-discovery.adapter.d.ts +29 -0
- package/dist/lib/dex/pair-discovery/adapters/v2-dex-pair-discovery.adapter.d.ts.map +1 -0
- package/dist/lib/dex/pair-discovery/adapters/v2-dex-pair-discovery.adapter.js +179 -0
- package/dist/lib/dex/pair-discovery/adapters/v2-dex-pair-discovery.adapter.js.map +1 -0
- package/dist/lib/dex/pair-discovery/adapters/v3-dex-pair-discovery.adapter.d.ts +29 -0
- package/dist/lib/dex/pair-discovery/adapters/v3-dex-pair-discovery.adapter.d.ts.map +1 -0
- package/dist/lib/dex/pair-discovery/adapters/v3-dex-pair-discovery.adapter.js +345 -0
- package/dist/lib/dex/pair-discovery/adapters/v3-dex-pair-discovery.adapter.js.map +1 -0
- package/dist/lib/dex/pair-discovery/adapters/ve33-dex-pair-discovery.adapter.d.ts +36 -0
- package/dist/lib/dex/pair-discovery/adapters/ve33-dex-pair-discovery.adapter.d.ts.map +1 -0
- package/dist/lib/dex/pair-discovery/adapters/ve33-dex-pair-discovery.adapter.js +275 -0
- package/dist/lib/dex/pair-discovery/adapters/ve33-dex-pair-discovery.adapter.js.map +1 -0
- package/dist/lib/dex/pair-discovery/pair-discovery.service.d.ts +16 -0
- package/dist/lib/dex/pair-discovery/pair-discovery.service.d.ts.map +1 -0
- package/dist/lib/dex/pair-discovery/pair-discovery.service.js +98 -0
- package/dist/lib/dex/pair-discovery/pair-discovery.service.js.map +1 -0
- package/dist/lib/dex/pair-discovery/pair-discovery.types.d.ts +189 -0
- package/dist/lib/dex/pair-discovery/pair-discovery.types.d.ts.map +1 -0
- package/dist/lib/dex/pair-discovery/pair-discovery.types.js +3 -0
- package/dist/lib/dex/pair-discovery/pair-discovery.types.js.map +1 -0
- package/dist/lib/dex/uniswapV2/v2-dex-deployments.d.ts +5 -0
- package/dist/lib/dex/uniswapV2/v2-dex-deployments.d.ts.map +1 -0
- package/dist/lib/dex/uniswapV2/v2-dex-deployments.js +166 -0
- package/dist/lib/dex/uniswapV2/v2-dex-deployments.js.map +1 -0
- package/dist/lib/dex/uniswapv3/{v3-offchain-quoter.service.d.ts → offchain-quoter/v3-offchain-quoter.service.d.ts} +1 -1
- package/dist/lib/dex/uniswapv3/offchain-quoter/v3-offchain-quoter.service.d.ts.map +1 -0
- package/dist/lib/dex/uniswapv3/{v3-offchain-quoter.service.js → offchain-quoter/v3-offchain-quoter.service.js} +3 -3
- package/dist/lib/dex/uniswapv3/offchain-quoter/v3-offchain-quoter.service.js.map +1 -0
- package/dist/lib/dex/uniswapv3/offchain-quoter/v3-offchain-quoter.types.d.ts +162 -0
- package/dist/lib/dex/uniswapv3/offchain-quoter/v3-offchain-quoter.types.d.ts.map +1 -0
- package/dist/lib/dex/uniswapv3/offchain-quoter/v3-offchain-quoter.types.js +3 -0
- package/dist/lib/dex/uniswapv3/offchain-quoter/v3-offchain-quoter.types.js.map +1 -0
- package/dist/lib/dex/uniswapv3/ramses-quoter.abi.d.ts +3 -0
- package/dist/lib/dex/uniswapv3/ramses-quoter.abi.d.ts.map +1 -0
- package/dist/lib/dex/uniswapv3/ramses-quoter.abi.js +114 -0
- package/dist/lib/dex/uniswapv3/ramses-quoter.abi.js.map +1 -0
- package/dist/lib/dex/uniswapv3/slipstream-quoter.abi.d.ts +3 -0
- package/dist/lib/dex/uniswapv3/slipstream-quoter.abi.d.ts.map +1 -0
- package/dist/lib/dex/uniswapv3/slipstream-quoter.abi.js +30 -0
- package/dist/lib/dex/uniswapv3/slipstream-quoter.abi.js.map +1 -0
- package/dist/lib/dex/uniswapv3/slipstream-router.abi.d.ts +3 -0
- package/dist/lib/dex/uniswapv3/slipstream-router.abi.d.ts.map +1 -0
- package/dist/lib/dex/uniswapv3/slipstream-router.abi.js +45 -0
- package/dist/lib/dex/uniswapv3/slipstream-router.abi.js.map +1 -0
- package/dist/lib/dex/uniswapv3/v3-dex-deployments.d.ts +32 -0
- package/dist/lib/dex/uniswapv3/v3-dex-deployments.d.ts.map +1 -0
- package/dist/lib/dex/uniswapv3/v3-dex-deployments.js +283 -0
- package/dist/lib/dex/uniswapv3/v3-dex-deployments.js.map +1 -0
- package/dist/lib/dex/ve33/aerodrome-factory.abi.d.ts +3 -0
- package/dist/lib/dex/ve33/aerodrome-factory.abi.d.ts.map +1 -0
- package/dist/lib/dex/ve33/aerodrome-factory.abi.js +17 -0
- package/dist/lib/dex/ve33/aerodrome-factory.abi.js.map +1 -0
- package/dist/lib/dex/ve33/aerodrome-router.abi.d.ts +3 -0
- package/dist/lib/dex/ve33/aerodrome-router.abi.d.ts.map +1 -0
- package/dist/lib/dex/ve33/aerodrome-router.abi.js +119 -0
- package/dist/lib/dex/ve33/aerodrome-router.abi.js.map +1 -0
- package/dist/lib/dex/ve33/blackhole-router.abi.d.ts +3 -0
- package/dist/lib/dex/ve33/blackhole-router.abi.d.ts.map +1 -0
- package/dist/lib/dex/ve33/blackhole-router.abi.js +1492 -0
- package/dist/lib/dex/ve33/blackhole-router.abi.js.map +1 -0
- package/dist/lib/dex/ve33/pharaoh-router.abi.d.ts +3 -0
- package/dist/lib/dex/ve33/pharaoh-router.abi.d.ts.map +1 -0
- package/dist/lib/dex/ve33/pharaoh-router.abi.js +502 -0
- package/dist/lib/dex/ve33/pharaoh-router.abi.js.map +1 -0
- package/dist/lib/dex/ve33/pharaoh-swap-router.abi.d.ts +3 -0
- package/dist/lib/dex/ve33/pharaoh-swap-router.abi.d.ts.map +1 -0
- package/dist/lib/dex/ve33/pharaoh-swap-router.abi.js +239 -0
- package/dist/lib/dex/ve33/pharaoh-swap-router.abi.js.map +1 -0
- package/dist/lib/dex/ve33/ve33-dex-deployments.d.ts +4 -0
- package/dist/lib/dex/ve33/ve33-dex-deployments.d.ts.map +1 -0
- package/dist/lib/dex/ve33/ve33-dex-deployments.js +34 -0
- package/dist/lib/dex/ve33/ve33-dex-deployments.js.map +1 -0
- package/dist/lib/dex/ve33/velodrome-router.abi.d.ts +3 -0
- package/dist/lib/dex/ve33/velodrome-router.abi.d.ts.map +1 -0
- package/dist/lib/dex/ve33/velodrome-router.abi.js +634 -0
- package/dist/lib/dex/ve33/velodrome-router.abi.js.map +1 -0
- package/dist/protocols/algebra/algebra.service.d.ts +63 -0
- package/dist/protocols/algebra/algebra.service.d.ts.map +1 -0
- package/dist/protocols/algebra/algebra.service.js +532 -0
- package/dist/protocols/algebra/algebra.service.js.map +1 -0
- package/dist/protocols/algebra/algebra.types.d.ts +98 -0
- package/dist/protocols/algebra/algebra.types.d.ts.map +1 -0
- package/dist/protocols/algebra/algebra.types.js +9 -0
- package/dist/protocols/algebra/algebra.types.js.map +1 -0
- package/dist/protocols/algebra/index.d.ts +3 -0
- package/dist/protocols/algebra/index.d.ts.map +1 -0
- package/dist/protocols/algebra/index.js +21 -0
- package/dist/protocols/algebra/index.js.map +1 -0
- package/dist/protocols/four-meme/four-meme.service.d.ts.map +1 -1
- package/dist/protocols/four-meme/four-meme.service.js +49 -57
- package/dist/protocols/four-meme/four-meme.service.js.map +1 -1
- package/dist/protocols/four-meme/four-meme.types.d.ts +8 -3
- package/dist/protocols/four-meme/four-meme.types.d.ts.map +1 -1
- package/dist/protocols/genius-bridge/genius-bridge.service.d.ts +2 -1
- package/dist/protocols/genius-bridge/genius-bridge.service.d.ts.map +1 -1
- package/dist/protocols/genius-bridge/genius-bridge.service.js.map +1 -1
- package/dist/protocols/genius-bridge/index.d.ts +1 -1
- package/dist/protocols/genius-bridge/index.d.ts.map +1 -1
- package/dist/protocols/lfj/index.d.ts +3 -0
- package/dist/protocols/lfj/index.d.ts.map +1 -0
- package/dist/protocols/lfj/index.js +21 -0
- package/dist/protocols/lfj/index.js.map +1 -0
- package/dist/protocols/lfj/lfj.service.d.ts +45 -0
- package/dist/protocols/lfj/lfj.service.d.ts.map +1 -0
- package/dist/protocols/lfj/lfj.service.js +323 -0
- package/dist/protocols/lfj/lfj.service.js.map +1 -0
- package/dist/protocols/lfj/lfj.types.d.ts +136 -0
- package/dist/protocols/lfj/lfj.types.d.ts.map +1 -0
- package/dist/protocols/lfj/lfj.types.js +16 -0
- package/dist/protocols/lfj/lfj.types.js.map +1 -0
- package/dist/protocols/okx/okx.service.d.ts +9 -8
- package/dist/protocols/okx/okx.service.d.ts.map +1 -1
- package/dist/protocols/okx/okx.service.js +133 -143
- package/dist/protocols/okx/okx.service.js.map +1 -1
- package/dist/protocols/okx/okx.types.d.ts +9 -3
- package/dist/protocols/okx/okx.types.d.ts.map +1 -1
- package/dist/protocols/relay/relay.service.d.ts +3 -0
- package/dist/protocols/relay/relay.service.d.ts.map +1 -1
- package/dist/protocols/relay/relay.service.js +7 -1
- package/dist/protocols/relay/relay.service.js.map +1 -1
- package/dist/protocols/v2-dex/index.d.ts +1 -1
- package/dist/protocols/v2-dex/index.d.ts.map +1 -1
- package/dist/protocols/v2-dex/index.js +15 -0
- package/dist/protocols/v2-dex/index.js.map +1 -1
- package/dist/protocols/v2-dex/v2-dex.service.d.ts +9 -16
- package/dist/protocols/v2-dex/v2-dex.service.d.ts.map +1 -1
- package/dist/protocols/v2-dex/v2-dex.service.js +107 -530
- package/dist/protocols/v2-dex/v2-dex.service.js.map +1 -1
- package/dist/protocols/v2-dex/v2-dex.types.d.ts +32 -32
- package/dist/protocols/v2-dex/v2-dex.types.d.ts.map +1 -1
- package/dist/protocols/v2-dex/v2-dex.types.js.map +1 -1
- package/dist/protocols/v3-dex/adapters/slipstream.adapter.d.ts +42 -0
- package/dist/protocols/v3-dex/adapters/slipstream.adapter.d.ts.map +1 -0
- package/dist/protocols/v3-dex/adapters/slipstream.adapter.js +185 -0
- package/dist/protocols/v3-dex/adapters/slipstream.adapter.js.map +1 -0
- package/dist/protocols/v3-dex/adapters/uniswap-fork.adapter.d.ts +40 -0
- package/dist/protocols/v3-dex/adapters/uniswap-fork.adapter.d.ts.map +1 -0
- package/dist/protocols/v3-dex/adapters/uniswap-fork.adapter.js +237 -0
- package/dist/protocols/v3-dex/adapters/uniswap-fork.adapter.js.map +1 -0
- package/dist/protocols/v3-dex/adapters/uniswap.adapter.d.ts +39 -0
- package/dist/protocols/v3-dex/adapters/uniswap.adapter.d.ts.map +1 -0
- package/dist/protocols/v3-dex/adapters/uniswap.adapter.js +226 -0
- package/dist/protocols/v3-dex/adapters/uniswap.adapter.js.map +1 -0
- package/dist/protocols/v3-dex/index.d.ts +1 -1
- package/dist/protocols/v3-dex/index.d.ts.map +1 -1
- package/dist/protocols/v3-dex/index.js +15 -0
- package/dist/protocols/v3-dex/index.js.map +1 -1
- package/dist/protocols/v3-dex/v3-dex.service.d.ts +21 -76
- package/dist/protocols/v3-dex/v3-dex.service.d.ts.map +1 -1
- package/dist/protocols/v3-dex/v3-dex.service.js +387 -1196
- package/dist/protocols/v3-dex/v3-dex.service.js.map +1 -1
- package/dist/protocols/v3-dex/v3-dex.types.d.ts +154 -365
- package/dist/protocols/v3-dex/v3-dex.types.d.ts.map +1 -1
- package/dist/protocols/v3-dex/v3-dex.types.js +13 -1
- package/dist/protocols/v3-dex/v3-dex.types.js.map +1 -1
- package/dist/protocols/ve33/adapters/blackhole.adapter.d.ts +29 -0
- package/dist/protocols/ve33/adapters/blackhole.adapter.d.ts.map +1 -0
- package/dist/protocols/ve33/adapters/blackhole.adapter.js +59 -0
- package/dist/protocols/ve33/adapters/blackhole.adapter.js.map +1 -0
- package/dist/protocols/ve33/adapters/pharaoh.adapter.d.ts +34 -0
- package/dist/protocols/ve33/adapters/pharaoh.adapter.d.ts.map +1 -0
- package/dist/protocols/ve33/adapters/pharaoh.adapter.js +51 -0
- package/dist/protocols/ve33/adapters/pharaoh.adapter.js.map +1 -0
- package/dist/protocols/ve33/adapters/solidly.adapter.d.ts +42 -0
- package/dist/protocols/ve33/adapters/solidly.adapter.d.ts.map +1 -0
- package/dist/protocols/ve33/adapters/solidly.adapter.js +63 -0
- package/dist/protocols/ve33/adapters/solidly.adapter.js.map +1 -0
- package/dist/protocols/ve33/index.d.ts +3 -0
- package/dist/protocols/ve33/index.d.ts.map +1 -0
- package/dist/protocols/ve33/index.js +21 -0
- package/dist/protocols/ve33/index.js.map +1 -0
- package/dist/protocols/ve33/ve33.handlers.d.ts +3 -0
- package/dist/protocols/ve33/ve33.handlers.d.ts.map +1 -0
- package/dist/protocols/ve33/ve33.handlers.js +187 -0
- package/dist/protocols/ve33/ve33.handlers.js.map +1 -0
- package/dist/protocols/ve33/ve33.service.d.ts +31 -0
- package/dist/protocols/ve33/ve33.service.d.ts.map +1 -0
- package/dist/protocols/ve33/ve33.service.js +488 -0
- package/dist/protocols/ve33/ve33.service.js.map +1 -0
- package/dist/protocols/ve33/ve33.types.d.ts +137 -0
- package/dist/protocols/ve33/ve33.types.d.ts.map +1 -0
- package/dist/protocols/ve33/ve33.types.js +16 -0
- package/dist/protocols/ve33/ve33.types.js.map +1 -0
- package/dist/token-launches/jupiter/jupiter-studio-launch.constants.d.ts +40 -0
- package/dist/token-launches/jupiter/jupiter-studio-launch.constants.d.ts.map +1 -0
- package/dist/token-launches/jupiter/jupiter-studio-launch.constants.js +43 -0
- package/dist/token-launches/jupiter/jupiter-studio-launch.constants.js.map +1 -0
- package/dist/token-launches/jupiter/jupiter-studio-launch.service.d.ts +10 -0
- package/dist/token-launches/jupiter/jupiter-studio-launch.service.d.ts.map +1 -0
- package/dist/token-launches/jupiter/jupiter-studio-launch.service.js +56 -0
- package/dist/token-launches/jupiter/jupiter-studio-launch.service.js.map +1 -0
- package/dist/token-launches/jupiter/jupiter-studio-launch.types.d.ts +49 -0
- package/dist/token-launches/jupiter/jupiter-studio-launch.types.d.ts.map +1 -0
- package/dist/token-launches/jupiter/jupiter-studio-launch.types.js +3 -0
- package/dist/token-launches/jupiter/jupiter-studio-launch.types.js.map +1 -0
- package/dist/token-launches/jupiter/jupiter-studio-launch.utils.d.ts +9 -0
- package/dist/token-launches/jupiter/jupiter-studio-launch.utils.d.ts.map +1 -0
- package/dist/token-launches/jupiter/jupiter-studio-launch.utils.js +82 -0
- package/dist/token-launches/jupiter/jupiter-studio-launch.utils.js.map +1 -0
- package/dist/token-launches/meteora/meteora-launch.constants.d.ts +11 -0
- package/dist/token-launches/meteora/meteora-launch.constants.d.ts.map +1 -0
- package/dist/token-launches/meteora/meteora-launch.constants.js +15 -0
- package/dist/token-launches/meteora/meteora-launch.constants.js.map +1 -0
- package/dist/token-launches/meteora/meteora-launch.service.d.ts +13 -0
- package/dist/token-launches/meteora/meteora-launch.service.d.ts.map +1 -0
- package/dist/token-launches/meteora/meteora-launch.service.js +64 -0
- package/dist/token-launches/meteora/meteora-launch.service.js.map +1 -0
- package/dist/token-launches/meteora/meteora-launch.types.d.ts +18 -0
- package/dist/token-launches/meteora/meteora-launch.types.d.ts.map +1 -0
- package/dist/token-launches/meteora/meteora-launch.types.js +3 -0
- package/dist/token-launches/meteora/meteora-launch.types.js.map +1 -0
- package/dist/token-launches/meteora/meteora-launch.utils.d.ts +4 -0
- package/dist/token-launches/meteora/meteora-launch.utils.d.ts.map +1 -0
- package/dist/token-launches/meteora/meteora-launch.utils.js +54 -0
- package/dist/token-launches/meteora/meteora-launch.utils.js.map +1 -0
- package/dist/token-launches/pump-fun/pump-fun-launch.service.d.ts +13 -0
- package/dist/token-launches/pump-fun/pump-fun-launch.service.d.ts.map +1 -0
- package/dist/token-launches/pump-fun/pump-fun-launch.service.js +63 -0
- package/dist/token-launches/pump-fun/pump-fun-launch.service.js.map +1 -0
- package/dist/token-launches/pump-fun/pump-fun-launch.types.d.ts +12 -0
- package/dist/token-launches/pump-fun/pump-fun-launch.types.d.ts.map +1 -0
- package/dist/token-launches/pump-fun/pump-fun-launch.types.js +3 -0
- package/dist/token-launches/pump-fun/pump-fun-launch.types.js.map +1 -0
- package/dist/token-launches/raydium-launchlab/raydium-launch.constants.d.ts +13 -0
- package/dist/token-launches/raydium-launchlab/raydium-launch.constants.d.ts.map +1 -0
- package/dist/token-launches/raydium-launchlab/raydium-launch.constants.js +18 -0
- package/dist/token-launches/raydium-launchlab/raydium-launch.constants.js.map +1 -0
- package/dist/token-launches/raydium-launchlab/raydium-launch.service.d.ts +13 -0
- package/dist/token-launches/raydium-launchlab/raydium-launch.service.d.ts.map +1 -0
- package/dist/token-launches/raydium-launchlab/raydium-launch.service.js +102 -0
- package/dist/token-launches/raydium-launchlab/raydium-launch.service.js.map +1 -0
- package/dist/token-launches/raydium-launchlab/raydium-launch.types.d.ts +57 -0
- package/dist/token-launches/raydium-launchlab/raydium-launch.types.d.ts.map +1 -0
- package/dist/token-launches/raydium-launchlab/raydium-launch.types.js +3 -0
- package/dist/token-launches/raydium-launchlab/raydium-launch.types.js.map +1 -0
- package/dist/types/enums.d.ts +8 -3
- package/dist/types/enums.d.ts.map +1 -1
- package/dist/types/enums.js +5 -0
- package/dist/types/enums.js.map +1 -1
- package/dist/types/price-params.d.ts +12 -3
- package/dist/types/price-params.d.ts.map +1 -1
- package/dist/types/price-response.d.ts +7 -4
- package/dist/types/price-response.d.ts.map +1 -1
- package/dist/types/quote-response.d.ts +6 -3
- package/dist/types/quote-response.d.ts.map +1 -1
- package/dist/utils/chainId-to-chain.d.ts +4 -0
- package/dist/utils/chainId-to-chain.d.ts.map +1 -0
- package/dist/utils/chainId-to-chain.js +44 -0
- package/dist/utils/chainId-to-chain.js.map +1 -0
- package/dist/utils/dex-deployment-key.d.ts +14 -0
- package/dist/utils/dex-deployment-key.d.ts.map +1 -0
- package/dist/utils/dex-deployment-key.js +17 -0
- package/dist/utils/dex-deployment-key.js.map +1 -0
- package/dist/utils/min-amount-out.d.ts +12 -0
- package/dist/utils/min-amount-out.d.ts.map +1 -0
- package/dist/utils/min-amount-out.js +18 -0
- package/dist/utils/min-amount-out.js.map +1 -0
- package/dist/utils/norm-dex-token.d.ts +13 -0
- package/dist/utils/norm-dex-token.d.ts.map +1 -0
- package/dist/utils/norm-dex-token.js +19 -0
- package/dist/utils/norm-dex-token.js.map +1 -0
- package/dist/utils/pair-result.d.ts +3 -0
- package/dist/utils/pair-result.d.ts.map +1 -0
- package/dist/utils/pair-result.js +11 -0
- package/dist/utils/pair-result.js.map +1 -0
- package/dist/utils/sort-addresses.d.ts +3 -0
- package/dist/utils/sort-addresses.d.ts.map +1 -0
- package/dist/utils/sort-addresses.js +16 -0
- package/dist/utils/sort-addresses.js.map +1 -0
- package/dist/utils/to-pool-key.d.ts +4 -0
- package/dist/utils/to-pool-key.d.ts.map +1 -0
- package/dist/utils/to-pool-key.js +15 -0
- package/dist/utils/to-pool-key.js.map +1 -0
- package/dist/utils/transaction-builder.util.d.ts +3 -0
- package/dist/utils/transaction-builder.util.d.ts.map +1 -0
- package/dist/utils/transaction-builder.util.js +13 -0
- package/dist/utils/transaction-builder.util.js.map +1 -0
- package/package.json +2 -2
- package/dist/lib/dex/uniswapv3/v3-offchain-quoter.service.d.ts.map +0 -1
- package/dist/lib/dex/uniswapv3/v3-offchain-quoter.service.js.map +0 -1
|
@@ -2,617 +2,269 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.V3StyleDexService = void 0;
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
|
-
const ethers_1 = require("ethers");
|
|
6
5
|
const v3_dex_types_1 = require("./v3-dex.types");
|
|
7
|
-
const
|
|
8
|
-
const pacakeswapV3_router_abi_1 = require("../../lib/dex/pancakeswap/pacakeswapV3-router.abi");
|
|
9
|
-
const v3_offchain_quoter_service_1 = require("../../lib/dex/uniswapv3/v3-offchain-quoter.service");
|
|
10
|
-
const uniswapV3_quoter_abi_1 = require("../../lib/dex/uniswapv3/uniswapV3-quoter.abi");
|
|
11
|
-
const uniswapV3_router_abi_1 = require("../../lib/dex/uniswapv3/uniswapV3-router.abi");
|
|
12
|
-
const uniswapV3_pool_abi_1 = require("../../lib/dex/uniswapv3/uniswapV3-pool.abi");
|
|
6
|
+
const v3_dex_deployments_1 = require("../../lib/dex/uniswapv3/v3-dex-deployments");
|
|
13
7
|
const enums_1 = require("../../types/enums");
|
|
8
|
+
const slipstream_adapter_1 = require("./adapters/slipstream.adapter");
|
|
9
|
+
const uniswap_fork_adapter_1 = require("./adapters/uniswap-fork.adapter");
|
|
10
|
+
const min_amount_out_1 = require("../../utils/min-amount-out");
|
|
14
11
|
const wrapped_native_1 = require("../../utils/wrapped-native");
|
|
12
|
+
const uniswap_adapter_1 = require("./adapters/uniswap.adapter");
|
|
13
|
+
const chainId_to_chain_1 = require("../../utils/chainId-to-chain");
|
|
15
14
|
const constants_1 = require("../../utils/constants");
|
|
15
|
+
const to_pool_key_1 = require("../../utils/to-pool-key");
|
|
16
16
|
const is_native_1 = require("../../utils/is-native");
|
|
17
|
-
const logger_1 = require("../../utils/logger");
|
|
18
17
|
const utils_1 = require("../../utils");
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* @remarks
|
|
26
|
-
* - Only single-chain swaps are supported.
|
|
27
|
-
* - Deployments and RPC clients are configured via the constructor.
|
|
28
|
-
* - Supports Uniswap V3, PancakeSwap V3, and SushiSwap V3 deployments on Avalanche, Arbitrum, BSC, Base, Ethereum, Optimism, and Polygon.
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```typescript
|
|
32
|
-
* const service = new V3StyleDexService(config);
|
|
33
|
-
* const price = await service.fetchPrice({ ... });
|
|
34
|
-
* const quote = await service.fetchQuote({ ... });
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* @implements IIntentProtocol
|
|
38
|
-
*/
|
|
18
|
+
const logger_1 = require("../../utils/logger");
|
|
19
|
+
let logger;
|
|
20
|
+
/** -----------------------------------------------------------------------
|
|
21
|
+
* V3StyleDexService
|
|
22
|
+
* --------------------------------------------------------------------- */
|
|
39
23
|
class V3StyleDexService {
|
|
40
24
|
constructor(config) {
|
|
41
|
-
/**
|
|
42
|
-
* The protocol that the service produces
|
|
43
|
-
*/
|
|
44
25
|
this.protocol = enums_1.ProtocolEnum.UNISWAP_V3;
|
|
45
|
-
/**
|
|
46
|
-
* Whether the service supports a single chain
|
|
47
|
-
*/
|
|
48
26
|
this.singleChain = true;
|
|
49
|
-
/**
|
|
50
|
-
* Whether the service supports multiple chains
|
|
51
|
-
*/
|
|
52
27
|
this.multiChain = false;
|
|
53
|
-
|
|
54
|
-
* The chains that the service supports
|
|
55
|
-
*/
|
|
56
|
-
this.chains = [
|
|
57
|
-
enums_1.ChainIdEnum.AVALANCHE,
|
|
58
|
-
enums_1.ChainIdEnum.ARBITRUM,
|
|
59
|
-
enums_1.ChainIdEnum.BSC,
|
|
60
|
-
enums_1.ChainIdEnum.BASE,
|
|
61
|
-
enums_1.ChainIdEnum.ETHEREUM,
|
|
62
|
-
enums_1.ChainIdEnum.OPTIMISM,
|
|
63
|
-
enums_1.ChainIdEnum.POLYGON,
|
|
64
|
-
enums_1.ChainIdEnum.HYPEREVM,
|
|
65
|
-
];
|
|
66
|
-
/**
|
|
67
|
-
* Public clients by chain
|
|
68
|
-
*/
|
|
28
|
+
this.chains = v3_dex_deployments_1.uniV3SupportedChains;
|
|
69
29
|
this._clients = {};
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
dex: v3_dex_types_1.UniswapV3StyleDexEnum.PANGOLIN_V3,
|
|
91
|
-
quoter: '0xA86522CCc412dBC4FA10991900FE46De95983822',
|
|
92
|
-
factory: '0x1128F23D0bc0A8396E9FBC3c0c68f5EA228B8256',
|
|
93
|
-
router: '0x5485A0751a249225D3bA2f6f296551507e22547f',
|
|
94
|
-
initHash: '0x40231f6b438bce0797c9ada29b718a87ea0a5cea3fe9a771abdd76bd41a3e545',
|
|
95
|
-
},
|
|
96
|
-
// {
|
|
97
|
-
// dex: UniswapV3StyleDexEnum.SUSHISWAP_V3,
|
|
98
|
-
// router: '0x81602ef321c46d73f5ba7f476947ae1a862957dc', // RouteProcessor9
|
|
99
|
-
// factory: '0x3e603c14af37ebdad31709c4f848fc6ad5bec715',
|
|
100
|
-
// },
|
|
101
|
-
],
|
|
102
|
-
[enums_1.ChainIdEnum.ARBITRUM]: [
|
|
103
|
-
{
|
|
104
|
-
dex: v3_dex_types_1.UniswapV3StyleDexEnum.UNISWAP_V3,
|
|
105
|
-
quoter: '0x61fFE014bA17989E743c5F6cB21bF9697530B21e',
|
|
106
|
-
router: '0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45',
|
|
107
|
-
factory: '0x1F98431c8aD98523631AE4a59f267346ea31F984',
|
|
108
|
-
initHash: '0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54',
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
dex: v3_dex_types_1.UniswapV3StyleDexEnum.PANCAKESWAP_V3,
|
|
112
|
-
quoter: '0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997',
|
|
113
|
-
deployer: '0x41ff9AA7e16B8B1a8a8dc4f0eFacd93D02d071c9',
|
|
114
|
-
router: '0x1b81D678ffb9C0263b24A97847620C99d213eB14',
|
|
115
|
-
factory: '0x0BFbCF9fa4f9C56B0F40a671Ad40E0805A091865',
|
|
116
|
-
initHash: '0x6ce8eb472fa82df5469c6ab6d485f17c3ad13c8cd7af59b3d4a8026c5ce0f7e2',
|
|
117
|
-
},
|
|
118
|
-
// {
|
|
119
|
-
// dex: UniswapV3StyleDexEnum.SUSHISWAP_V3,
|
|
120
|
-
// router: '0x81602ef321c46d73f5ba7f476947ae1a862957dc', // RouteProcessor9
|
|
121
|
-
// factory: '0x1af415a1eba07a4986a52b6f2e7de7003d82231e',
|
|
122
|
-
// },
|
|
123
|
-
],
|
|
124
|
-
[enums_1.ChainIdEnum.BSC]: [
|
|
125
|
-
{
|
|
126
|
-
dex: v3_dex_types_1.UniswapV3StyleDexEnum.UNISWAP_V3,
|
|
127
|
-
quoter: '0x78D78E420Da98ad378D7799bE8f4AF69033EB077',
|
|
128
|
-
router: '0xB971eF87ede563556b2ED4b1C0b0019111Dd85d2',
|
|
129
|
-
factory: '0xdB1d10011AD0Ff90774D0C6Bb92e5C5c8b4461F7',
|
|
130
|
-
initHash: '0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54',
|
|
131
|
-
},
|
|
132
|
-
{
|
|
133
|
-
dex: v3_dex_types_1.UniswapV3StyleDexEnum.PANCAKESWAP_V3,
|
|
134
|
-
quoter: '0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997',
|
|
135
|
-
deployer: '0x41ff9AA7e16B8B1a8a8dc4f0eFacd93D02d071c9',
|
|
136
|
-
router: '0x1b81D678ffb9C0263b24A97847620C99d213eB14',
|
|
137
|
-
factory: '0x0BFbCF9fa4f9C56B0F40a671Ad40E0805A091865',
|
|
138
|
-
initHash: '0x6ce8eb472fa82df5469c6ab6d485f17c3ad13c8cd7af59b3d4a8026c5ce0f7e2',
|
|
139
|
-
},
|
|
140
|
-
// {
|
|
141
|
-
// dex: UniswapV3StyleDexEnum.SUSHISWAP_V3,
|
|
142
|
-
// router: '0x81602ef321c46d73f5ba7f476947ae1a862957dc', // RouteProcessor9
|
|
143
|
-
// factory: '0x126555dd55a39328f69400d6ae4f782bd4c34abb',
|
|
144
|
-
// },
|
|
145
|
-
],
|
|
146
|
-
[enums_1.ChainIdEnum.BASE]: [
|
|
147
|
-
{
|
|
148
|
-
dex: v3_dex_types_1.UniswapV3StyleDexEnum.UNISWAP_V3,
|
|
149
|
-
quoter: '0x3d4e44Eb1374240CE5F1B871ab261CD16335B76a',
|
|
150
|
-
router: '0x2626664c2603336E57B271c5C0b26F421741e481',
|
|
151
|
-
factory: '0x33128a8fC17869897dcE68Ed026d694621f6FDfD',
|
|
152
|
-
initHash: '0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54',
|
|
153
|
-
},
|
|
154
|
-
{
|
|
155
|
-
dex: v3_dex_types_1.UniswapV3StyleDexEnum.PANCAKESWAP_V3,
|
|
156
|
-
quoter: '0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997',
|
|
157
|
-
deployer: '0x41ff9AA7e16B8B1a8a8dc4f0eFacd93D02d071c9',
|
|
158
|
-
router: '0x1b81D678ffb9C0263b24A97847620C99d213eB14',
|
|
159
|
-
factory: '0x0BFbCF9fa4f9C56B0F40a671Ad40E0805A091865',
|
|
160
|
-
initHash: '0x6ce8eb472fa82df5469c6ab6d485f17c3ad13c8cd7af59b3d4a8026c5ce0f7e2',
|
|
161
|
-
},
|
|
162
|
-
// {
|
|
163
|
-
// dex: UniswapV3StyleDexEnum.SUSHISWAP_V3,
|
|
164
|
-
// router: '0x81602ef321c46d73f5ba7f476947ae1a862957dc', // RouteProcessor9
|
|
165
|
-
// factory: '0xc35dadb65012ec5796536bd9864ed8773abc74c4',
|
|
166
|
-
// },
|
|
167
|
-
],
|
|
168
|
-
[enums_1.ChainIdEnum.ETHEREUM]: [
|
|
169
|
-
{
|
|
170
|
-
dex: v3_dex_types_1.UniswapV3StyleDexEnum.UNISWAP_V3,
|
|
171
|
-
quoter: '0x61fFE014bA17989E743c5F6cB21bF9697530B21e',
|
|
172
|
-
router: '0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45',
|
|
173
|
-
factory: '0x1F98431c8aD98523631AE4a59f267346ea31F984',
|
|
174
|
-
initHash: '0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54',
|
|
175
|
-
},
|
|
176
|
-
{
|
|
177
|
-
dex: v3_dex_types_1.UniswapV3StyleDexEnum.PANCAKESWAP_V3,
|
|
178
|
-
quoter: '0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997',
|
|
179
|
-
deployer: '0x41ff9AA7e16B8B1a8a8dc4f0eFacd93D02d071c9',
|
|
180
|
-
router: '0x1b81D678ffb9C0263b24A97847620C99d213eB14',
|
|
181
|
-
factory: '0x0BFbCF9fa4f9C56B0F40a671Ad40E0805A091865',
|
|
182
|
-
initHash: '0x6ce8eb472fa82df5469c6ab6d485f17c3ad13c8cd7af59b3d4a8026c5ce0f7e2',
|
|
183
|
-
},
|
|
184
|
-
// {
|
|
185
|
-
// dex: UniswapV3StyleDexEnum.SUSHISWAP_V3,
|
|
186
|
-
// router: '0x81602ef321c46d73f5ba7f476947ae1a862957dc', // RouteProcessor9
|
|
187
|
-
// factory: '0xbaceb8ec6b9355dfc0269c18bac9d6e2bdc29c4f',
|
|
188
|
-
// },
|
|
189
|
-
],
|
|
190
|
-
[enums_1.ChainIdEnum.OPTIMISM]: [
|
|
191
|
-
{
|
|
192
|
-
dex: v3_dex_types_1.UniswapV3StyleDexEnum.UNISWAP_V3,
|
|
193
|
-
quoter: '0x61fFE014bA17989E743c5F6cB21bF9697530B21e',
|
|
194
|
-
router: '0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45',
|
|
195
|
-
factory: '0x1F98431c8aD98523631AE4a59f267346ea31F984',
|
|
196
|
-
initHash: '0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54',
|
|
197
|
-
},
|
|
198
|
-
// {
|
|
199
|
-
// dex: UniswapV3StyleDexEnum.SUSHISWAP_V3,
|
|
200
|
-
// router: '0x81602ef321c46d73f5ba7f476947ae1a862957dc', // RouteProcessor9
|
|
201
|
-
// factory: '0x9c6522117e2ed1fe5bdb72bb0ed5e3f2bde7dbe0',
|
|
202
|
-
// },
|
|
203
|
-
],
|
|
204
|
-
[enums_1.ChainIdEnum.POLYGON]: [
|
|
205
|
-
{
|
|
206
|
-
dex: v3_dex_types_1.UniswapV3StyleDexEnum.UNISWAP_V3,
|
|
207
|
-
quoter: '0x61fFE014bA17989E743c5F6cB21bF9697530B21e',
|
|
208
|
-
router: '0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45',
|
|
209
|
-
factory: '0x1F98431c8aD98523631AE4a59f267346ea31F984',
|
|
210
|
-
initHash: '0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54',
|
|
211
|
-
},
|
|
212
|
-
// {
|
|
213
|
-
// dex: UniswapV3StyleDexEnum.SUSHISWAP_V3,
|
|
214
|
-
// router: '0x81602ef321c46d73f5ba7f476947ae1a862957dc', // RouteProcessor9
|
|
215
|
-
// factory: '0x917933899c6a5f8e37f31e19f92cdbff7e8ff0e2',
|
|
216
|
-
// },
|
|
217
|
-
],
|
|
218
|
-
[enums_1.ChainIdEnum.HYPEREVM]: [
|
|
219
|
-
{
|
|
220
|
-
dex: v3_dex_types_1.UniswapV3StyleDexEnum.HYPERSWAP_V3,
|
|
221
|
-
quoter: '0x03A918028f22D9E1473B7959C927AD7425A45C7C',
|
|
222
|
-
router: '0x6D99e7f6747AF2cDbB5164b6DD50e40D4fDe1e77',
|
|
223
|
-
factory: '0xB1c0fa0B789320044A6F623cFe5eBda9562602E3',
|
|
224
|
-
initHash: '0xe3572921be1688dba92df30c6781b8770499ff274d20ae9b325f4242634774fb',
|
|
225
|
-
},
|
|
226
|
-
],
|
|
227
|
-
};
|
|
228
|
-
if (config?.rpcs) {
|
|
229
|
-
for (const [chainIdStr, rpc] of Object.entries(config.rpcs)) {
|
|
230
|
-
const chainId = Number(chainIdStr);
|
|
231
|
-
if (!rpc || rpc === '') {
|
|
232
|
-
logger_1.logger.warn(`Skipping empty RPC for chainId ${chainId}`);
|
|
233
|
-
continue;
|
|
234
|
-
}
|
|
235
|
-
const expectedConfig = config.uniV3ChainConfigs[chainId];
|
|
236
|
-
if (!expectedConfig) {
|
|
237
|
-
logger_1.logger.warn(`No RPC URL found for chainId ${chainId}, skipping client creation`);
|
|
238
|
-
continue;
|
|
239
|
-
}
|
|
240
|
-
const chainConfig = config.uniV3ChainConfigs[chainId];
|
|
241
|
-
this._clients[chainId] = (0, viem_1.createPublicClient)({
|
|
242
|
-
chain: chainConfig,
|
|
243
|
-
transport: (0, viem_1.http)(rpc),
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
if (config?.uniV3ExtraDeployments) {
|
|
248
|
-
for (const [k, extras] of Object.entries(config.uniV3ExtraDeployments)) {
|
|
249
|
-
const chain = Number(k);
|
|
250
|
-
const base = this.deployments[chain] ?? [];
|
|
251
|
-
this.deployments[chain] = [...base, ...(extras ?? [])];
|
|
30
|
+
this._deployments = v3_dex_deployments_1.uniV3DexDeployments;
|
|
31
|
+
this._adapterCache = new Map();
|
|
32
|
+
if (!config) {
|
|
33
|
+
throw new Error('V3StyleDexService requires configuration');
|
|
34
|
+
}
|
|
35
|
+
if (config?.debug) {
|
|
36
|
+
logger_1.LoggerFactory.configure(logger_1.LoggerFactory.createConsoleLogger({ level: logger_1.LogLevelEnum.DEBUG }));
|
|
37
|
+
}
|
|
38
|
+
// Use custom logger if provided
|
|
39
|
+
else if (config?.logger) {
|
|
40
|
+
logger_1.LoggerFactory.configure(config.logger);
|
|
41
|
+
}
|
|
42
|
+
logger = logger_1.LoggerFactory.getLogger();
|
|
43
|
+
// Create clients where both chainConfig & rpc are provided
|
|
44
|
+
for (const [key, rpcUrl] of Object.entries(config.rpcs ?? {})) {
|
|
45
|
+
const chainId = Number(key);
|
|
46
|
+
const chainObj = chainId_to_chain_1.chainIdToChain[chainId];
|
|
47
|
+
if (!rpcUrl || !chainObj) {
|
|
48
|
+
logger.warn(`Skipping V3StyleDexService client creation for chainId ${chainId} - missing RPC or chain config`);
|
|
49
|
+
continue;
|
|
252
50
|
}
|
|
51
|
+
this._clients[chainId] = (0, viem_1.createPublicClient)({
|
|
52
|
+
chain: chainObj,
|
|
53
|
+
transport: (0, viem_1.http)(rpcUrl),
|
|
54
|
+
});
|
|
253
55
|
}
|
|
254
56
|
}
|
|
57
|
+
// --------------------------- Public API -----------------------------------
|
|
255
58
|
isCorrectConfig(_config) {
|
|
256
|
-
// V2StyleDexService has no required config fields, all are optional
|
|
257
59
|
return true;
|
|
258
60
|
}
|
|
61
|
+
/** -----------------------------------------------------------------------
|
|
62
|
+
* fetchPrice
|
|
63
|
+
* --------------------------------------------------------------------- */
|
|
259
64
|
async fetchPrice(params) {
|
|
260
|
-
const { networkIn, networkOut, tokenIn, tokenOut, amountIn, slippage
|
|
261
|
-
const pair = overrideParamsV3Dex?.pair;
|
|
262
|
-
const expectedAmountOutMin = overrideParamsV3Dex?.amountOutMin;
|
|
263
|
-
const dex = overrideParamsV3Dex?.dex;
|
|
65
|
+
const { networkIn, networkOut, tokenIn, tokenOut, amountIn, slippage } = params;
|
|
264
66
|
if (networkIn !== networkOut) {
|
|
265
|
-
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, 'V3StyleDexService
|
|
266
|
-
}
|
|
267
|
-
const amountInBI = BigInt(amountIn);
|
|
268
|
-
if (amountInBI <= 0n) {
|
|
269
|
-
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, 'amountIn must be greater than zero');
|
|
270
|
-
}
|
|
271
|
-
const deployments = this.deployments[networkIn] ?? [];
|
|
272
|
-
if (!deployments.length) {
|
|
273
|
-
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, `No V3-style deployments configured for network ${networkIn}`);
|
|
274
|
-
}
|
|
275
|
-
if (pair && expectedAmountOutMin && dex) {
|
|
276
|
-
/**
|
|
277
|
-
* Use the dex enum to find the corresponding router given the networkIn
|
|
278
|
-
*/
|
|
279
|
-
const router = deployments.find(d => d.dex === dex)?.router;
|
|
280
|
-
if (!router) {
|
|
281
|
-
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, `No router found for dex ${dex} on chainId ${networkIn}`);
|
|
282
|
-
}
|
|
283
|
-
const dexKey = this._buildDexKey(networkIn, router);
|
|
284
|
-
const earlyResponse = {
|
|
285
|
-
dex: dexKey,
|
|
286
|
-
amountOut: expectedAmountOutMin,
|
|
287
|
-
quoterAddress: undefined,
|
|
288
|
-
feeTier: 3000,
|
|
289
|
-
sqrtPriceX96After: undefined,
|
|
290
|
-
initializedTicksCrossed: undefined,
|
|
291
|
-
gasEstimate: undefined,
|
|
292
|
-
method: 'ExpectedAmountOut',
|
|
293
|
-
path: pair,
|
|
294
|
-
notes: `Early return due to supplied pair and amountOutMin`,
|
|
295
|
-
};
|
|
296
|
-
const priceResponse = {
|
|
297
|
-
protocol: this.protocol,
|
|
298
|
-
networkIn,
|
|
299
|
-
networkOut,
|
|
300
|
-
tokenIn,
|
|
301
|
-
tokenOut,
|
|
302
|
-
amountIn,
|
|
303
|
-
amountOut: expectedAmountOutMin,
|
|
304
|
-
slippage,
|
|
305
|
-
protocolResponse: earlyResponse,
|
|
306
|
-
};
|
|
307
|
-
return priceResponse;
|
|
67
|
+
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, 'V3StyleDexService supports only single-chain swaps');
|
|
308
68
|
}
|
|
309
69
|
const client = this._clients[networkIn];
|
|
310
70
|
if (!client) {
|
|
311
|
-
console.log(`No RPC client configured for chainId ${networkIn}`);
|
|
312
71
|
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, `No RPC client configured for chainId ${networkIn}`);
|
|
313
72
|
}
|
|
314
|
-
|
|
73
|
+
let deployments = this._deployments[networkIn] ?? [];
|
|
74
|
+
/**
|
|
75
|
+
* If an override pair + amountOutMin + dex + feeTier is provided, use fast route
|
|
76
|
+
* logic, which does not rely on any on-chain quoting – assumes the caller has done
|
|
77
|
+
* their own due diligence to verify the pair exists and is valid.
|
|
78
|
+
*/
|
|
79
|
+
const overrides = params?.overrideParamsV3Dex;
|
|
80
|
+
const overridePair = overrides?.pair;
|
|
81
|
+
const overrideAmountOutMin = overrides?.amountOutMin;
|
|
82
|
+
const overrideDex = overrides?.dex;
|
|
83
|
+
const overrideFeeTier = overrides?.feeOrTick;
|
|
84
|
+
const useFastRoute = overridePair && overrideAmountOutMin && overrideDex && overrideFeeTier;
|
|
85
|
+
if (useFastRoute) {
|
|
86
|
+
logger.info(`V3StyleDexService: Using fast route price fetch logic.`);
|
|
87
|
+
return this._buildFastRoutePriceResponse({
|
|
88
|
+
networkIn: networkIn,
|
|
89
|
+
networkOut: networkOut,
|
|
90
|
+
tokenIn: tokenIn,
|
|
91
|
+
tokenOut: tokenOut,
|
|
92
|
+
slippage: slippage ?? 0,
|
|
93
|
+
amountIn: amountIn,
|
|
94
|
+
overrideDex: overrideDex,
|
|
95
|
+
overrideAmountOutMin: overrideAmountOutMin,
|
|
96
|
+
overrideFeeTier: overrideFeeTier,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
const deploymentsToExclude = overrides?.excludeDexes ?? [];
|
|
100
|
+
if (deploymentsToExclude) {
|
|
101
|
+
logger.info(`V3StyleDexService: Excluding deployments for dexes: ${deploymentsToExclude.join(', ')}`);
|
|
102
|
+
deployments = deployments.filter(d => !deploymentsToExclude?.includes(d.dex));
|
|
103
|
+
}
|
|
104
|
+
if (!deployments.length) {
|
|
105
|
+
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, `No CLMM deployments for chainId ${networkIn}`);
|
|
106
|
+
}
|
|
107
|
+
const amountInBI = BigInt(amountIn);
|
|
108
|
+
if (amountInBI <= 0n) {
|
|
109
|
+
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, 'amountIn must be greater than zero');
|
|
110
|
+
}
|
|
111
|
+
// Normalize for quoting (wrap native)
|
|
315
112
|
const nativeIn = (0, is_native_1.isNative)(tokenIn);
|
|
316
113
|
const nativeOut = (0, is_native_1.isNative)(tokenOut);
|
|
317
114
|
const wrapped = wrapped_native_1.wrappedNativeTokens[networkIn];
|
|
318
115
|
if ((nativeIn || nativeOut) && !wrapped) {
|
|
319
|
-
|
|
320
|
-
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, `Missing wrapped native token mapping for chainId ${networkIn}`);
|
|
116
|
+
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, `Missing wrapped native token mapping for ${networkIn}`);
|
|
321
117
|
}
|
|
322
|
-
const
|
|
323
|
-
const
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
const
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
tokenIn,
|
|
341
|
-
tokenOut,
|
|
342
|
-
amountIn,
|
|
343
|
-
amountOut: best.amountOut.toString(),
|
|
344
|
-
slippage,
|
|
345
|
-
protocolResponse: best.payload,
|
|
346
|
-
};
|
|
347
|
-
}
|
|
348
|
-
// Split deployments by quoter availability
|
|
349
|
-
const orthodox = deployments.filter(d => !!d.quoter);
|
|
350
|
-
const quoterless = deployments.filter(d => !('quoter' in d) || !d.quoter);
|
|
351
|
-
let best;
|
|
352
|
-
/** ---------------------------------------
|
|
353
|
-
* Round 1: QuoterV2.quoteExactInputSingle
|
|
354
|
-
* ------------------------------------- */
|
|
355
|
-
const v2Contracts = orthodox.flatMap(d => {
|
|
356
|
-
const feeTiers = this._determineFeeTiersForDex(d.dex);
|
|
357
|
-
return feeTiers.map(fee => ({
|
|
358
|
-
address: d.quoter,
|
|
359
|
-
abi: uniswapV3_quoter_abi_1.uniswapV3QuoterAbi,
|
|
360
|
-
functionName: 'quoteExactInputSingle',
|
|
361
|
-
args: [
|
|
362
|
-
{
|
|
363
|
-
tokenIn: (0, viem_1.getAddress)(tokenInForQuote),
|
|
364
|
-
tokenOut: (0, viem_1.getAddress)(tokenOutForQuote),
|
|
365
|
-
amountIn: amountInBI,
|
|
366
|
-
fee,
|
|
367
|
-
sqrtPriceLimitX96: 0n,
|
|
368
|
-
},
|
|
369
|
-
],
|
|
370
|
-
}));
|
|
371
|
-
});
|
|
372
|
-
const v2Metas = orthodox.flatMap(d => {
|
|
373
|
-
const feeTiers = this._determineFeeTiersForDex(d.dex);
|
|
374
|
-
return feeTiers.map(fee => ({
|
|
375
|
-
dex: this._buildDexKey(networkIn, d.router),
|
|
376
|
-
fee,
|
|
377
|
-
quoter: d.quoter,
|
|
378
|
-
method: 'QuoterV2.quoteExactInputSingle',
|
|
379
|
-
}));
|
|
380
|
-
});
|
|
381
|
-
let v2Results;
|
|
382
|
-
if (networkIn === enums_1.ChainIdEnum.HYPEREVM) {
|
|
383
|
-
// Use individual calls with Promise.all for HyperEVM due to 30M gas limit
|
|
384
|
-
v2Results = await Promise.all(v2Contracts.map(async (contract) => {
|
|
118
|
+
const tokenInQ = (nativeIn ? wrapped : tokenIn);
|
|
119
|
+
const tokenOutQ = (nativeOut ? wrapped : tokenOut);
|
|
120
|
+
// Build all QuoterV2 calls (first pass)
|
|
121
|
+
const v2Specs = [];
|
|
122
|
+
for (const d of deployments) {
|
|
123
|
+
const adapter = this._getAdapter(d.dex);
|
|
124
|
+
const presets = adapter.presets(networkIn); // fee tiers or tick spacings
|
|
125
|
+
for (const p of presets) {
|
|
126
|
+
const poolKey = (0, to_pool_key_1.toPoolKey)(tokenInQ, tokenOutQ, p);
|
|
127
|
+
const task = {
|
|
128
|
+
deployment: d,
|
|
129
|
+
tokenIn: tokenInQ,
|
|
130
|
+
tokenOut: tokenOutQ,
|
|
131
|
+
amountIn: amountInBI,
|
|
132
|
+
poolKey,
|
|
133
|
+
nativeIn,
|
|
134
|
+
nativeOut,
|
|
135
|
+
};
|
|
385
136
|
try {
|
|
386
|
-
const
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
args: contract.args,
|
|
391
|
-
});
|
|
392
|
-
return { status: 'success', result };
|
|
137
|
+
const spec = adapter.buildQuoterV2Call(task);
|
|
138
|
+
if (!spec)
|
|
139
|
+
continue;
|
|
140
|
+
v2Specs.push({ spec, adapter, meta: task, d, preset: p });
|
|
393
141
|
}
|
|
394
|
-
catch
|
|
395
|
-
|
|
142
|
+
catch {
|
|
143
|
+
// Adapter may not support V2 (shouldn't happen here), skip
|
|
396
144
|
}
|
|
397
|
-
}));
|
|
398
|
-
}
|
|
399
|
-
else {
|
|
400
|
-
v2Results = v2Contracts.length
|
|
401
|
-
? await client.multicall({ allowFailure: true, contracts: v2Contracts })
|
|
402
|
-
: [];
|
|
403
|
-
}
|
|
404
|
-
for (let i = 0; i < v2Results.length; i++) {
|
|
405
|
-
const res = v2Results[i];
|
|
406
|
-
const meta = v2Metas[i];
|
|
407
|
-
if (!res || !meta)
|
|
408
|
-
continue;
|
|
409
|
-
if (res.status === 'success' && Array.isArray(res.result)) {
|
|
410
|
-
const [amountOut, sqrtAfter, ticks, gas] = res.result;
|
|
411
|
-
const candidate = {
|
|
412
|
-
amountOut,
|
|
413
|
-
payload: {
|
|
414
|
-
dex: meta.dex,
|
|
415
|
-
quoterAddress: meta.quoter,
|
|
416
|
-
method: meta.method,
|
|
417
|
-
feeTier: meta.fee,
|
|
418
|
-
amountOut: amountOut.toString(),
|
|
419
|
-
gasEstimate: gas ? gas.toString() : undefined,
|
|
420
|
-
sqrtPriceX96After: sqrtAfter ? sqrtAfter.toString() : undefined,
|
|
421
|
-
initializedTicksCrossed: ticks,
|
|
422
|
-
notes: nativeIn || nativeOut
|
|
423
|
-
? `Quoted with wrapped native: in=${nativeIn ? 'wrapped' : 'erc20'}, out=${nativeOut ? 'wrapped' : 'erc20'}`
|
|
424
|
-
: undefined,
|
|
425
|
-
},
|
|
426
|
-
};
|
|
427
|
-
if (!best || candidate.amountOut > best.amountOut)
|
|
428
|
-
best = candidate;
|
|
429
|
-
continue;
|
|
430
|
-
}
|
|
431
|
-
// Try to decode revert (some quoters return data on revert)
|
|
432
|
-
// @ts-ignore – Viem surfaces revert data in error.data
|
|
433
|
-
const data = res?.error?.data;
|
|
434
|
-
if (!data || data === '0x')
|
|
435
|
-
continue;
|
|
436
|
-
try {
|
|
437
|
-
const [amountOut, sqrtAfter, ticks, gas] = (0, viem_1.decodeFunctionResult)({
|
|
438
|
-
abi: uniswapV3_quoter_abi_1.uniswapV3QuoterAbi,
|
|
439
|
-
functionName: 'quoteExactInputSingle',
|
|
440
|
-
data,
|
|
441
|
-
});
|
|
442
|
-
const candidate = {
|
|
443
|
-
amountOut,
|
|
444
|
-
payload: {
|
|
445
|
-
dex: meta.dex,
|
|
446
|
-
quoterAddress: meta.quoter,
|
|
447
|
-
method: meta.method,
|
|
448
|
-
feeTier: meta.fee,
|
|
449
|
-
amountOut: amountOut.toString(),
|
|
450
|
-
gasEstimate: gas ? gas.toString() : undefined,
|
|
451
|
-
sqrtPriceX96After: sqrtAfter ? sqrtAfter.toString() : undefined,
|
|
452
|
-
initializedTicksCrossed: ticks,
|
|
453
|
-
notes: nativeIn || nativeOut
|
|
454
|
-
? `Quoted with wrapped native: in=${nativeIn ? 'wrapped' : 'erc20'}, out=${nativeOut ? 'wrapped' : 'erc20'}`
|
|
455
|
-
: undefined,
|
|
456
|
-
},
|
|
457
|
-
};
|
|
458
|
-
if (!best || candidate.amountOut > (best.amountOut ?? 0n))
|
|
459
|
-
best = candidate;
|
|
460
|
-
}
|
|
461
|
-
catch {
|
|
462
|
-
/* ignore; fallback below */
|
|
463
145
|
}
|
|
464
146
|
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
amountIn: amountInBI,
|
|
480
|
-
fee,
|
|
481
|
-
sqrtPriceLimitX96: 0n,
|
|
482
|
-
},
|
|
483
|
-
],
|
|
484
|
-
}));
|
|
485
|
-
});
|
|
486
|
-
const v1Metas = orthodox.flatMap(d => {
|
|
487
|
-
const feeTiers = this._determineFeeTiersForDex(d.dex);
|
|
488
|
-
return feeTiers.map(fee => ({
|
|
489
|
-
dex: this._buildDexKey(networkIn, d.router),
|
|
490
|
-
fee,
|
|
491
|
-
quoter: d.quoter,
|
|
492
|
-
method: 'Quoter.quoteExactInputSingle',
|
|
493
|
-
}));
|
|
494
|
-
});
|
|
495
|
-
const v1Results = v1Contracts.length
|
|
496
|
-
? await client.multicall({
|
|
497
|
-
allowFailure: true,
|
|
498
|
-
contracts: v1Contracts,
|
|
499
|
-
...(networkIn === enums_1.ChainIdEnum.HYPEREVM && {
|
|
500
|
-
multicallAddress: '0xcA11bde05977b3631167028862bE2a173976CA11',
|
|
501
|
-
}),
|
|
502
|
-
})
|
|
503
|
-
: [];
|
|
504
|
-
for (let i = 0; i < v1Results.length; i++) {
|
|
505
|
-
const res = v1Results[i];
|
|
506
|
-
const meta = v1Metas[i];
|
|
507
|
-
if (!meta || !res)
|
|
147
|
+
// Execute V2 multicall
|
|
148
|
+
let best;
|
|
149
|
+
if (v2Specs.length) {
|
|
150
|
+
const calls = v2Specs.map(s => ({
|
|
151
|
+
address: s.spec.address,
|
|
152
|
+
abi: s.spec.abi,
|
|
153
|
+
functionName: s.spec.fn,
|
|
154
|
+
args: s.spec.args,
|
|
155
|
+
}));
|
|
156
|
+
const results = await this._execBatch(networkIn, calls);
|
|
157
|
+
for (let i = 0; i < results.length; i++) {
|
|
158
|
+
const res = results[i];
|
|
159
|
+
const s = v2Specs[i];
|
|
160
|
+
if (!s)
|
|
508
161
|
continue;
|
|
509
|
-
if (res
|
|
510
|
-
const [amountOut] = res.result;
|
|
511
|
-
const candidate = {
|
|
512
|
-
amountOut,
|
|
513
|
-
payload: {
|
|
514
|
-
dex: meta.dex,
|
|
515
|
-
quoterAddress: meta.quoter,
|
|
516
|
-
method: meta.method,
|
|
517
|
-
feeTier: meta.fee,
|
|
518
|
-
amountOut: amountOut.toString(),
|
|
519
|
-
notes: nativeIn || nativeOut
|
|
520
|
-
? `Quoted with wrapped native: in=${nativeIn ? 'wrapped' : 'erc20'}, out=${nativeOut ? 'wrapped' : 'erc20'}`
|
|
521
|
-
: undefined,
|
|
522
|
-
},
|
|
523
|
-
};
|
|
524
|
-
if (!best || candidate.amountOut > best.amountOut)
|
|
525
|
-
best = candidate;
|
|
162
|
+
if (!res)
|
|
526
163
|
continue;
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
// @ts-ignore
|
|
530
|
-
const data = res?.error?.data;
|
|
531
|
-
if (!data || data === '0x')
|
|
164
|
+
const decoded = s.adapter.decodeQuoterV2(res);
|
|
165
|
+
if (!decoded)
|
|
532
166
|
continue;
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
method:
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
notes: nativeIn || nativeOut
|
|
548
|
-
? `Quoted with wrapped native: in=${nativeIn ? 'wrapped' : 'erc20'}, out=${nativeOut ? 'wrapped' : 'erc20'}`
|
|
549
|
-
: undefined,
|
|
550
|
-
},
|
|
551
|
-
};
|
|
552
|
-
if (!best || candidate.amountOut > best.amountOut)
|
|
553
|
-
best = candidate;
|
|
554
|
-
}
|
|
555
|
-
catch {
|
|
556
|
-
/* ignore; no more fallbacks */
|
|
167
|
+
if (decoded.amountOut > 0n) {
|
|
168
|
+
if (!best || decoded.amountOut > best.amountOut) {
|
|
169
|
+
best = {
|
|
170
|
+
adapter: s.adapter,
|
|
171
|
+
d: s.d,
|
|
172
|
+
p: s.preset,
|
|
173
|
+
amountOut: decoded.amountOut,
|
|
174
|
+
sqrt: decoded.sqrt,
|
|
175
|
+
ticks: decoded.ticks,
|
|
176
|
+
gas: decoded.gas,
|
|
177
|
+
meta: s.meta,
|
|
178
|
+
method: 'QuoterV2.quoteExactInputSingle',
|
|
179
|
+
};
|
|
180
|
+
}
|
|
557
181
|
}
|
|
558
182
|
}
|
|
559
183
|
}
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
for (const
|
|
184
|
+
// If no V2 winner, try V1 where supported (Uniswap/V3Fork; NOT Slipstream)
|
|
185
|
+
if (!best) {
|
|
186
|
+
const v1Specs = [];
|
|
187
|
+
for (const d of deployments) {
|
|
188
|
+
const adapter = this._getAdapter(d.dex);
|
|
189
|
+
// Slipstream throws on V1 – guard out by capability or key
|
|
190
|
+
const skipV1 = adapter.caps?.usesTickSpacing ||
|
|
191
|
+
adapter.family === v3_dex_types_1.UniswapV3StyleDexFamilyEnum.SLIPSTREAM;
|
|
192
|
+
if (skipV1)
|
|
193
|
+
continue;
|
|
194
|
+
const presets = adapter.presets(networkIn);
|
|
195
|
+
for (const p of presets) {
|
|
196
|
+
const poolKey = (0, to_pool_key_1.toPoolKey)(tokenInQ, tokenOutQ, p);
|
|
197
|
+
const task = {
|
|
198
|
+
deployment: d,
|
|
199
|
+
tokenIn: tokenInQ,
|
|
200
|
+
tokenOut: tokenOutQ,
|
|
201
|
+
amountIn: amountInBI,
|
|
202
|
+
poolKey,
|
|
203
|
+
nativeIn,
|
|
204
|
+
nativeOut,
|
|
205
|
+
};
|
|
572
206
|
try {
|
|
573
|
-
const
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
amountIn: amountInBI,
|
|
578
|
-
factory: (0, viem_1.getAddress)(d.factory),
|
|
579
|
-
fees: this.uniFeeTiers,
|
|
580
|
-
// optional safety knobs can be wired via UniV3Config in the future:
|
|
581
|
-
// maxTickReads, prefetchWords
|
|
582
|
-
});
|
|
583
|
-
if (res?.best && res.best.ok && res.best.amountOut > 0n) {
|
|
584
|
-
const dexKey = this._buildDexKey(networkIn, d.router);
|
|
585
|
-
const candidate = {
|
|
586
|
-
amountOut: res.best.amountOut,
|
|
587
|
-
payload: {
|
|
588
|
-
dex: dexKey,
|
|
589
|
-
quoterAddress: undefined, // no on-chain quoter used
|
|
590
|
-
method: 'OffchainQuoter.simulateExactInputSingle',
|
|
591
|
-
feeTier: res.best.fee,
|
|
592
|
-
amountOut: res.best.amountOut.toString(),
|
|
593
|
-
sqrtPriceX96After: res.best.sqrtPriceX96After
|
|
594
|
-
? res.best.sqrtPriceX96After.toString()
|
|
595
|
-
: undefined,
|
|
596
|
-
initializedTicksCrossed: res.best.initializedTicksCrossed,
|
|
597
|
-
notes: (nativeIn || nativeOut
|
|
598
|
-
? `Quoted with wrapped native: in=${nativeIn ? 'wrapped' : 'erc20'}, out=${nativeOut ? 'wrapped' : 'erc20'}; `
|
|
599
|
-
: '') + `Factory=${(0, viem_1.getAddress)(d.factory)}`,
|
|
600
|
-
},
|
|
601
|
-
};
|
|
602
|
-
if (!best || candidate.amountOut > best.amountOut)
|
|
603
|
-
best = candidate;
|
|
604
|
-
}
|
|
207
|
+
const spec = adapter.buildQuoterV1Call(task);
|
|
208
|
+
if (!spec)
|
|
209
|
+
continue;
|
|
210
|
+
v1Specs.push({ spec, adapter, meta: task, d, preset: p });
|
|
605
211
|
}
|
|
606
212
|
catch {
|
|
607
|
-
|
|
213
|
+
/* unsupported; skip */
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (v1Specs.length) {
|
|
218
|
+
const calls = v1Specs.map(s => ({
|
|
219
|
+
address: s.spec.address,
|
|
220
|
+
abi: s.spec.abi,
|
|
221
|
+
functionName: s.spec.fn,
|
|
222
|
+
args: s.spec.args,
|
|
223
|
+
}));
|
|
224
|
+
const results = await this._execBatch(networkIn, calls);
|
|
225
|
+
for (let i = 0; i < results.length; i++) {
|
|
226
|
+
const res = results[i];
|
|
227
|
+
const s = v1Specs[i];
|
|
228
|
+
if (!s)
|
|
229
|
+
continue;
|
|
230
|
+
if (!res)
|
|
231
|
+
continue;
|
|
232
|
+
const decoded = s.adapter.decodeQuoterV1(res);
|
|
233
|
+
if (!decoded)
|
|
234
|
+
continue;
|
|
235
|
+
if (decoded.amountOut > 0n) {
|
|
236
|
+
if (!best || decoded.amountOut > best.amountOut) {
|
|
237
|
+
best = {
|
|
238
|
+
adapter: s.adapter,
|
|
239
|
+
d: s.d,
|
|
240
|
+
p: s.preset,
|
|
241
|
+
amountOut: decoded.amountOut,
|
|
242
|
+
meta: s.meta,
|
|
243
|
+
method: 'Quoter.quoteExactInputSingle',
|
|
244
|
+
};
|
|
245
|
+
}
|
|
608
246
|
}
|
|
609
247
|
}
|
|
610
248
|
}
|
|
611
249
|
}
|
|
612
250
|
if (!best) {
|
|
613
|
-
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.QUOTE_NOT_FOUND,
|
|
614
|
-
}
|
|
615
|
-
|
|
251
|
+
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.QUOTE_NOT_FOUND, 'No CLMM quote could be found');
|
|
252
|
+
}
|
|
253
|
+
const payload = {
|
|
254
|
+
dex: best.d.dex,
|
|
255
|
+
router: best.d.router,
|
|
256
|
+
quoter: best.d.quoter,
|
|
257
|
+
method: best.method,
|
|
258
|
+
feeOrTick: best.p,
|
|
259
|
+
amountOut: best.amountOut.toString(),
|
|
260
|
+
sqrtPriceX96After: best.sqrt ? best.sqrt.toString() : undefined,
|
|
261
|
+
initializedTicksCrossed: best?.ticks,
|
|
262
|
+
gasEstimate: best.gas ? best.gas.toString() : undefined,
|
|
263
|
+
notes: (nativeIn || nativeOut
|
|
264
|
+
? `Quoted with wrapped native (in=${nativeIn ? 'wrapped' : 'erc20'}, out=${nativeOut ? 'wrapped' : 'erc20'}). `
|
|
265
|
+
: '') + `Adapter=${best.adapter.constructor.name}`,
|
|
266
|
+
};
|
|
267
|
+
const priceResponse = {
|
|
616
268
|
protocol: this.protocol,
|
|
617
269
|
networkIn,
|
|
618
270
|
networkOut,
|
|
@@ -621,680 +273,219 @@ class V3StyleDexService {
|
|
|
621
273
|
amountIn,
|
|
622
274
|
amountOut: best.amountOut.toString(),
|
|
623
275
|
slippage,
|
|
624
|
-
protocolResponse:
|
|
276
|
+
protocolResponse: payload,
|
|
625
277
|
};
|
|
278
|
+
logger.info(`V3StyleDexService: Fetched price: ${amountIn} ${tokenIn} -> ${priceResponse.amountOut} ${tokenOut} on ${networkIn} via ${best.d.dex}`);
|
|
279
|
+
return priceResponse;
|
|
626
280
|
}
|
|
281
|
+
/** -----------------------------------------------------------------------
|
|
282
|
+
* fetchQuote
|
|
283
|
+
* --------------------------------------------------------------------- */
|
|
627
284
|
async fetchQuote(params) {
|
|
628
|
-
const { networkIn, networkOut, tokenIn, tokenOut, amountIn, slippage, from, receiver,
|
|
629
|
-
if (overrideParamsV3Dex &&
|
|
630
|
-
overrideParamsV3Dex.nativePrice &&
|
|
631
|
-
overrideParamsV3Dex.tokenInPrice &&
|
|
632
|
-
overrideParamsV3Dex.tokenInDecimals) {
|
|
633
|
-
await this._validateNativeLiquidity({
|
|
634
|
-
tokenIn,
|
|
635
|
-
networkIn: enums_1.ChainIdEnum.UNKNOWN,
|
|
636
|
-
dexes: this.deployments[networkIn]?.map(d => d.dex) ?? [],
|
|
637
|
-
nativePrice: overrideParamsV3Dex.nativePrice,
|
|
638
|
-
tokenInPrice: overrideParamsV3Dex.tokenInPrice,
|
|
639
|
-
tokenInDecimals: overrideParamsV3Dex.tokenInDecimals,
|
|
640
|
-
});
|
|
641
|
-
}
|
|
285
|
+
const { networkIn, networkOut, tokenIn, tokenOut, amountIn, slippage, from, receiver, priceResponse, } = params;
|
|
642
286
|
if (networkIn !== networkOut) {
|
|
643
|
-
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, 'V3StyleDexService
|
|
287
|
+
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, 'V3StyleDexService supports only single-chain swaps');
|
|
644
288
|
}
|
|
645
|
-
const
|
|
646
|
-
if (
|
|
647
|
-
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS,
|
|
289
|
+
const client = this._clients[networkIn];
|
|
290
|
+
if (!client) {
|
|
291
|
+
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, `No RPC client configured for chainId ${networkIn}`);
|
|
648
292
|
}
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
if ((expectNativeIn || expectNativeOut) && !wrapped) {
|
|
654
|
-
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, `Missing wrapped native token mapping for chainId ${networkIn}`);
|
|
293
|
+
let price = undefined;
|
|
294
|
+
if (priceResponse) {
|
|
295
|
+
logger.info(`V3StyleDexService: Using provided price response for quote fetch.`);
|
|
296
|
+
price = priceResponse;
|
|
655
297
|
}
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
slippage,
|
|
671
|
-
overrideParamsV3Dex,
|
|
672
|
-
});
|
|
673
|
-
}
|
|
674
|
-
catch (e) {
|
|
675
|
-
const errorMessage = e.message ?? e;
|
|
676
|
-
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.QUOTE_NOT_FOUND, errorMessage);
|
|
677
|
-
}
|
|
678
|
-
v3Price = priceRes.protocolResponse;
|
|
298
|
+
else {
|
|
299
|
+
logger.info(`V3StyleDexService: Fetching price for quote.`);
|
|
300
|
+
price = await this.fetchPrice(params);
|
|
301
|
+
}
|
|
302
|
+
const overrides = params?.overrideParamsV3Dex;
|
|
303
|
+
const sqrtPriceX96After = overrides?.sqrtPriceX96After ||
|
|
304
|
+
(price.protocolResponse && 'sqrtPriceX96After' in price.protocolResponse)
|
|
305
|
+
? price.protocolResponse.sqrtPriceX96After
|
|
306
|
+
: undefined;
|
|
307
|
+
const pp = price.protocolResponse;
|
|
308
|
+
const deployments = this._deployments[networkIn] ?? [];
|
|
309
|
+
const deployment = deployments.find(d => d.dex === pp.dex && d.router.toLowerCase() === pp.router.toLowerCase()) ?? deployments.find(d => d.dex === pp.dex);
|
|
310
|
+
if (!deployment) {
|
|
311
|
+
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, `No deployment found for ${pp.dex} on ${networkIn}`);
|
|
679
312
|
}
|
|
680
|
-
|
|
681
|
-
|
|
313
|
+
const adapter = this._getAdapter(deployment.dex);
|
|
314
|
+
logger.info(`V3StyleDexService: Building quote for ${amountIn} ${tokenIn} -> ${price.amountOut} ${tokenOut} on ${networkIn} via ${deployment.dex}`);
|
|
315
|
+
// Native flags & recipient
|
|
316
|
+
const nativeIn = (0, is_native_1.isNative)(tokenIn);
|
|
317
|
+
const nativeOut = (0, is_native_1.isNative)(tokenOut);
|
|
318
|
+
const wrapped = wrapped_native_1.wrappedNativeTokens[networkIn];
|
|
319
|
+
if ((nativeIn || nativeOut) && !wrapped) {
|
|
320
|
+
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, `Missing wrapped native token mapping for ${networkIn}`);
|
|
682
321
|
}
|
|
683
|
-
|
|
684
|
-
const bestAmountOut = BigInt(v3Price.amountOut);
|
|
322
|
+
const recipient = (receiver || from);
|
|
685
323
|
const slippagePct = typeof slippage === 'number' ? slippage : Number(slippage || 0);
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
const
|
|
712
|
-
|
|
713
|
-
:
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
* If your pipeline already has the route bytes available at this stage, replace `routeBytes` accordingly.
|
|
732
|
-
*/
|
|
733
|
-
const routeBytes = '0x';
|
|
734
|
-
const takeSurplus = false;
|
|
735
|
-
const referralCode = 0;
|
|
736
|
-
if (expectNativeIn) {
|
|
737
|
-
// Payable path: send msg.value and call *WithTransferValueInput*
|
|
738
|
-
// We forward value to the RP9 itself (common pattern); adjust if you have a dedicated treasury.
|
|
739
|
-
data = (0, viem_1.encodeFunctionData)({
|
|
740
|
-
abi: sushiswap_route_processor_9_abi_1.sushiswapRouteProcessor9Abi,
|
|
741
|
-
functionName: 'processRouteWithTransferValueInput',
|
|
742
|
-
args: [
|
|
743
|
-
(0, viem_1.getAddress)(chosenRouter), // transferValueTo
|
|
744
|
-
amountInBI, // amountValueTransfer
|
|
745
|
-
(0, viem_1.getAddress)(tokenInExec), // tokenIn (wrapped native is fine; RP9/tines route may unwrap/rewrap as needed)
|
|
746
|
-
amountInBI, // amountIn
|
|
747
|
-
(0, viem_1.getAddress)(tokenOutExec), // tokenOut (use wrapped if nativeOut; route should handle unwrap if desired)
|
|
748
|
-
amountOutMin, // amountOutQuote
|
|
749
|
-
(0, viem_1.getAddress)(receiver || from), // to
|
|
750
|
-
routeBytes, // route (to be produced off-chain)
|
|
751
|
-
takeSurplus,
|
|
752
|
-
referralCode,
|
|
753
|
-
],
|
|
754
|
-
});
|
|
755
|
-
methodForResponse = 'RouteProcessor9.processRouteWithTransferValueInput';
|
|
756
|
-
// txValue already set to amountInBI for native-in case
|
|
757
|
-
}
|
|
758
|
-
else {
|
|
759
|
-
// ERC-20 in: no msg.value required; standard processRoute
|
|
760
|
-
data = (0, viem_1.encodeFunctionData)({
|
|
761
|
-
abi: sushiswap_route_processor_9_abi_1.sushiswapRouteProcessor9Abi,
|
|
762
|
-
functionName: 'processRoute',
|
|
763
|
-
args: [
|
|
764
|
-
(0, viem_1.getAddress)(tokenInExec), // tokenIn
|
|
765
|
-
amountInBI, // amountIn
|
|
766
|
-
(0, viem_1.getAddress)(tokenOutExec), // tokenOut
|
|
767
|
-
amountOutMin, // amountOutQuote
|
|
768
|
-
(0, viem_1.getAddress)(receiver || from), // to
|
|
769
|
-
routeBytes, // route (to be produced off-chain)
|
|
770
|
-
takeSurplus,
|
|
771
|
-
referralCode,
|
|
772
|
-
],
|
|
773
|
-
});
|
|
774
|
-
methodForResponse = 'RouteProcessor9.processRoute';
|
|
775
|
-
txValue = '0';
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
else {
|
|
779
|
-
const routerAbi = isPancakeV3 || isPangolinV3 ? pacakeswapV3_router_abi_1.pancakeswapV3RouterAbi : uniswapV3_router_abi_1.uniswapV3RouterAbi;
|
|
780
|
-
const struct = isPancakeV3 || isPangolinV3
|
|
781
|
-
? {
|
|
782
|
-
tokenIn: (0, viem_1.getAddress)(tokenInExec),
|
|
783
|
-
tokenOut: (0, viem_1.getAddress)(tokenOutExec),
|
|
784
|
-
fee: (v3Price.feeTier ?? 3000),
|
|
785
|
-
recipient: recipientForFirstLeg,
|
|
786
|
-
deadline,
|
|
787
|
-
amountIn: amountInBI,
|
|
788
|
-
amountOutMinimum: amountOutMin,
|
|
789
|
-
sqrtPriceLimitX96: 0n,
|
|
790
|
-
}
|
|
791
|
-
: {
|
|
792
|
-
tokenIn: (0, viem_1.getAddress)(tokenInExec),
|
|
793
|
-
tokenOut: (0, viem_1.getAddress)(tokenOutExec),
|
|
794
|
-
fee: (v3Price.feeTier ?? 3000),
|
|
795
|
-
recipient: recipientForFirstLeg,
|
|
796
|
-
amountIn: amountInBI,
|
|
797
|
-
amountOutMinimum: amountOutMin,
|
|
798
|
-
sqrtPriceLimitX96: 0n,
|
|
799
|
-
};
|
|
800
|
-
const exactInputSingleCalldata = (0, viem_1.encodeFunctionData)({
|
|
801
|
-
abi: routerAbi,
|
|
802
|
-
functionName: 'exactInputSingle',
|
|
803
|
-
args: [struct],
|
|
804
|
-
});
|
|
805
|
-
if (expectNativeOut) {
|
|
806
|
-
const unwrapCalldata = (0, viem_1.encodeFunctionData)({
|
|
807
|
-
abi: routerAbi,
|
|
808
|
-
functionName: 'unwrapWETH9',
|
|
809
|
-
args: [amountOutMin, (0, viem_1.getAddress)(receiver || from)],
|
|
810
|
-
});
|
|
811
|
-
data = (0, viem_1.encodeFunctionData)({
|
|
812
|
-
abi: routerAbi,
|
|
813
|
-
functionName: 'multicall',
|
|
814
|
-
args: [[exactInputSingleCalldata, unwrapCalldata]],
|
|
815
|
-
});
|
|
816
|
-
methodForResponse = 'SwapRouter.exactInputSingle';
|
|
817
|
-
}
|
|
818
|
-
else {
|
|
819
|
-
data = exactInputSingleCalldata;
|
|
820
|
-
methodForResponse = 'SwapRouter.exactInputSingle';
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
// ETH value handling:
|
|
824
|
-
// - For Sushi RP9 branch with native in: msg.value == amountIn
|
|
825
|
-
// - For UniV3 branch with native in: msg.value == amountIn
|
|
826
|
-
// - Else: 0
|
|
827
|
-
// (txValue already assigned above)
|
|
828
|
-
const approval = expectNativeIn
|
|
829
|
-
? undefined
|
|
830
|
-
: {
|
|
831
|
-
token: (0, viem_1.getAddress)(tokenIn),
|
|
832
|
-
spender: chosenRouter,
|
|
833
|
-
amount: amountInBI.toString(),
|
|
834
|
-
};
|
|
324
|
+
// Build the "pick" for the adapter
|
|
325
|
+
const poolKey = (0, to_pool_key_1.toPoolKey)(nativeIn ? wrapped : tokenIn, nativeOut ? wrapped : tokenOut, pp.feeOrTick);
|
|
326
|
+
const task = {
|
|
327
|
+
deployment,
|
|
328
|
+
tokenIn: poolKey.tokenA === tokenIn
|
|
329
|
+
? tokenIn
|
|
330
|
+
: nativeIn
|
|
331
|
+
? wrapped
|
|
332
|
+
: tokenIn,
|
|
333
|
+
tokenOut: poolKey.tokenB === tokenOut
|
|
334
|
+
? tokenOut
|
|
335
|
+
: nativeOut
|
|
336
|
+
? wrapped
|
|
337
|
+
: tokenOut,
|
|
338
|
+
amountIn: BigInt(amountIn),
|
|
339
|
+
poolKey,
|
|
340
|
+
nativeIn,
|
|
341
|
+
nativeOut,
|
|
342
|
+
};
|
|
343
|
+
const pick = {
|
|
344
|
+
task,
|
|
345
|
+
amountOut: BigInt(price.amountOut),
|
|
346
|
+
decoded: { feeOrTick: pp.feeOrTick, quoter: pp.quoter, method: pp.method },
|
|
347
|
+
};
|
|
348
|
+
// Adapter calldata
|
|
349
|
+
const calldataInput = {
|
|
350
|
+
pick,
|
|
351
|
+
slippage: slippagePct,
|
|
352
|
+
recipient,
|
|
353
|
+
expectNativeIn: nativeIn,
|
|
354
|
+
expectNativeOut: nativeOut,
|
|
355
|
+
deadline: BigInt(Math.floor(Date.now() / 1000) + 1800), // +30 mins
|
|
356
|
+
sqrtPriceLimitX96: BigInt(sqrtPriceX96After || 0),
|
|
357
|
+
};
|
|
358
|
+
const cd = adapter.buildCalldata(calldataInput);
|
|
359
|
+
logger.info(`V3StyleDexService: Built calldata for quote: to=${cd.to} data=${cd.data} value=${cd.valueWei}`);
|
|
360
|
+
// Build approval if ERC-20 in
|
|
361
|
+
const approvalToken = nativeIn ? constants_1.ZERO_ADDRESS : tokenIn;
|
|
362
|
+
const approvalAmount = nativeIn ? BigInt(0) : BigInt(amountIn);
|
|
363
|
+
const approvalSpender = nativeIn ? constants_1.ZERO_ADDRESS : cd.to;
|
|
364
|
+
const approval = {
|
|
365
|
+
token: approvalToken,
|
|
366
|
+
spender: approvalSpender,
|
|
367
|
+
amount: approvalAmount.toString(),
|
|
368
|
+
};
|
|
835
369
|
const evmExecutionPayload = {
|
|
836
370
|
transactionData: {
|
|
837
|
-
to:
|
|
838
|
-
data,
|
|
839
|
-
value:
|
|
371
|
+
to: cd.to,
|
|
372
|
+
data: cd.data,
|
|
373
|
+
value: cd.valueWei ?? '0',
|
|
840
374
|
gasEstimate: '0',
|
|
841
375
|
gasLimit: '0',
|
|
842
376
|
},
|
|
843
|
-
|
|
377
|
+
approval,
|
|
844
378
|
};
|
|
845
|
-
|
|
846
|
-
const
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
}
|
|
850
|
-
const
|
|
851
|
-
dex:
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
quoterAddress: v3Price.quoterAddress, // undefined for off-chain path
|
|
864
|
-
feeTier: v3Price.feeTier,
|
|
865
|
-
method: methodForResponse,
|
|
866
|
-
amountOut: bestAmountOut.toString(),
|
|
867
|
-
amountOutMin: amountOutMin.toString(),
|
|
868
|
-
calldata: data,
|
|
869
|
-
value: txValue,
|
|
870
|
-
gasEstimate: v3Price.gasEstimate,
|
|
871
|
-
sqrtPriceX96After: v3Price.sqrtPriceX96After,
|
|
872
|
-
initializedTicksCrossed: v3Price.initializedTicksCrossed,
|
|
873
|
-
notes: (v3Price.method?.startsWith('OffchainQuoter') ? 'Off-chain pool simulation; ' : '') +
|
|
874
|
-
(isSushiV3
|
|
875
|
-
? 'Sushi Route Processor 9 calldata (route bytes expected from off-chain pathfinder); '
|
|
876
|
-
: '') +
|
|
877
|
-
(expectNativeIn ? 'Native in; ' : '') +
|
|
878
|
-
(expectNativeOut
|
|
879
|
-
? isSushiV3
|
|
880
|
-
? 'Native out should be handled inside route bytes.'
|
|
881
|
-
: 'Native out via multicall(unwrapWETH9).'
|
|
882
|
-
: 'ERC-20 out to recipient.'),
|
|
379
|
+
// For completeness, compute minOut here for protocol payload
|
|
380
|
+
const amountOutMin = (0, min_amount_out_1.calculateMinAmountOut)({
|
|
381
|
+
amountOut: price.amountOut,
|
|
382
|
+
slippage: slippagePct,
|
|
383
|
+
}).toString();
|
|
384
|
+
const qPayload = {
|
|
385
|
+
dex: deployment.dex,
|
|
386
|
+
router: cd.to,
|
|
387
|
+
quoter: deployment.quoter,
|
|
388
|
+
method: cd.methodName,
|
|
389
|
+
feeOrTick: pp.feeOrTick,
|
|
390
|
+
amountOut: price.amountOut,
|
|
391
|
+
amountOutMin,
|
|
392
|
+
calldata: cd.data,
|
|
393
|
+
value: cd.valueWei ?? '0',
|
|
394
|
+
notes: (nativeIn ? 'Native in; ' : '') +
|
|
395
|
+
(nativeOut ? 'Native out via unwrap; ' : '') +
|
|
396
|
+
`Adapter=${adapter.constructor.name}`,
|
|
883
397
|
};
|
|
884
|
-
|
|
398
|
+
const quoteResponse = {
|
|
885
399
|
protocol: this.protocol,
|
|
886
400
|
networkIn,
|
|
887
401
|
networkOut,
|
|
888
402
|
tokenIn,
|
|
889
403
|
tokenOut,
|
|
890
404
|
amountIn,
|
|
891
|
-
amountOut:
|
|
892
|
-
estimatedGas:
|
|
405
|
+
amountOut: price.amountOut,
|
|
406
|
+
estimatedGas: pp.gasEstimate,
|
|
893
407
|
slippage,
|
|
894
408
|
from,
|
|
895
409
|
receiver,
|
|
896
410
|
evmExecutionPayload,
|
|
897
|
-
protocolResponse,
|
|
411
|
+
protocolResponse: qPayload,
|
|
898
412
|
};
|
|
413
|
+
logger.info(`V3StyleDexService: Built quote response for ${amountIn} ${tokenIn} -> ${quoteResponse.amountOut} ${tokenOut} on ${networkIn} via ${deployment.dex}`);
|
|
414
|
+
return quoteResponse;
|
|
899
415
|
}
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
const
|
|
903
|
-
if (!
|
|
904
|
-
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, `No
|
|
905
|
-
}
|
|
906
|
-
return `${deployment.dex}:${router}:${network}`;
|
|
907
|
-
}
|
|
908
|
-
_convertKeyToDexEnum(dexKey) {
|
|
909
|
-
const parts = dexKey.split(':');
|
|
910
|
-
if (parts.length !== 3) {
|
|
911
|
-
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, `Invalid dex key format: ${dexKey}`);
|
|
416
|
+
// --------------------------- Internals -------------------------------------
|
|
417
|
+
async _execBatch(network, contracts) {
|
|
418
|
+
const client = this._clients[network];
|
|
419
|
+
if (!client) {
|
|
420
|
+
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, `No RPC client configured for chainId ${network}`);
|
|
912
421
|
}
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
422
|
+
if (network === enums_1.ChainIdEnum.HYPEREVM) {
|
|
423
|
+
return Promise.all(contracts.map(async (c) => {
|
|
424
|
+
try {
|
|
425
|
+
const result = await client.readContract(c);
|
|
426
|
+
return { status: 'success', result };
|
|
427
|
+
}
|
|
428
|
+
catch (error) {
|
|
429
|
+
return { status: 'failure', error };
|
|
430
|
+
}
|
|
431
|
+
}));
|
|
922
432
|
}
|
|
923
|
-
return
|
|
433
|
+
return client.multicall({ allowFailure: true, contracts });
|
|
924
434
|
}
|
|
925
|
-
|
|
926
|
-
const
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
: dexString === v3_dex_types_1.UniswapV3StyleDexEnum.SUSHISWAP_V3
|
|
931
|
-
? v3_dex_types_1.UniswapV3StyleDexEnum.SUSHISWAP_V3
|
|
932
|
-
: dexString === v3_dex_types_1.UniswapV3StyleDexEnum.HYPERSWAP_V3
|
|
933
|
-
? v3_dex_types_1.UniswapV3StyleDexEnum.HYPERSWAP_V3
|
|
934
|
-
: v3_dex_types_1.UniswapV3StyleDexEnum.UNISWAP_V3;
|
|
435
|
+
_getAdapter(dex) {
|
|
436
|
+
const cached = this._adapterCache.get(dex);
|
|
437
|
+
if (cached)
|
|
438
|
+
return cached;
|
|
439
|
+
let adapter;
|
|
935
440
|
switch (dex) {
|
|
441
|
+
case v3_dex_types_1.UniswapV3StyleDexEnum.AERODROME_CLMM:
|
|
442
|
+
case v3_dex_types_1.UniswapV3StyleDexEnum.VELODROME_CLMM:
|
|
443
|
+
adapter = new slipstream_adapter_1.SlipstreamDexAdapter(dex);
|
|
444
|
+
break;
|
|
936
445
|
case v3_dex_types_1.UniswapV3StyleDexEnum.PANCAKESWAP_V3:
|
|
937
|
-
return this.pancakeFeeTiers;
|
|
938
446
|
case v3_dex_types_1.UniswapV3StyleDexEnum.PANGOLIN_V3:
|
|
939
|
-
|
|
940
|
-
case v3_dex_types_1.UniswapV3StyleDexEnum.
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
return this.hyperswapFeeTiers;
|
|
447
|
+
case v3_dex_types_1.UniswapV3StyleDexEnum.PHARAOH_CLMM:
|
|
448
|
+
case v3_dex_types_1.UniswapV3StyleDexEnum.RAMSES_CLMM:
|
|
449
|
+
adapter = new uniswap_fork_adapter_1.V3ForkDexAdapter(dex);
|
|
450
|
+
break;
|
|
944
451
|
case v3_dex_types_1.UniswapV3StyleDexEnum.UNISWAP_V3:
|
|
452
|
+
case v3_dex_types_1.UniswapV3StyleDexEnum.HYPERSWAP_V3:
|
|
453
|
+
adapter = new uniswap_adapter_1.UniswapV3DexAdapter(dex);
|
|
454
|
+
break;
|
|
945
455
|
default:
|
|
946
|
-
|
|
456
|
+
throw new Error(`Unsupported CLMM DEX enum: ${dex}`);
|
|
947
457
|
}
|
|
458
|
+
this._adapterCache.set(dex, adapter);
|
|
459
|
+
return adapter;
|
|
948
460
|
}
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
const
|
|
957
|
-
const
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
(0, viem_1.hexToBytes)('0xff'),
|
|
965
|
-
(0, viem_1.hexToBytes)(addressToUse),
|
|
966
|
-
(0, viem_1.hexToBytes)(salt),
|
|
967
|
-
(0, viem_1.hexToBytes)(initHash),
|
|
968
|
-
]));
|
|
969
|
-
// Take last 20 bytes
|
|
970
|
-
return (0, viem_1.getAddress)(`0x${digest.slice(26)}`); // remove '0x' + 24 hex (12 bytes)
|
|
971
|
-
}
|
|
972
|
-
async _validateNativeLiquidity(params) {
|
|
973
|
-
const { tokenIn, networkIn, dexes, nativePrice, tokenInPrice, tokenInDecimals } = params;
|
|
974
|
-
// --- setup & guards
|
|
975
|
-
const stable = constants_1.networkStablecoins[networkIn];
|
|
976
|
-
if (!stable) {
|
|
977
|
-
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, `No stablecoin mapping for chainId ${networkIn}`);
|
|
978
|
-
}
|
|
979
|
-
const usdcEntry = stable.usdc; // { address, decimals } | undefined
|
|
980
|
-
const usdtEntry = stable.usdt;
|
|
981
|
-
const wrappedNative = wrapped_native_1.wrappedNativeTokens[networkIn]; // string
|
|
982
|
-
const tokenInAddr = (0, viem_1.getAddress)(tokenIn);
|
|
983
|
-
const baseTokenAddrs = [wrappedNative, usdcEntry?.address, usdtEntry?.address]
|
|
984
|
-
.filter((a) => !!a)
|
|
985
|
-
.filter(a => !(0, is_native_1.isNative)(a))
|
|
986
|
-
.map(a => (0, viem_1.getAddress)(a))
|
|
987
|
-
.filter(a => a !== tokenInAddr);
|
|
988
|
-
if (baseTokenAddrs.length === 0) {
|
|
989
|
-
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, `No valid base tokens (WETH/USDC/USDT) for liquidity check on chainId ${networkIn}`);
|
|
990
|
-
}
|
|
991
|
-
const deployments = (this.deployments[networkIn] ?? []).filter(d => dexes.includes(d.dex));
|
|
992
|
-
if (!deployments.length) {
|
|
993
|
-
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, `No V3-style deployments configured for network ${networkIn} (requested: ${dexes.join(', ')})`);
|
|
994
|
-
}
|
|
995
|
-
const client = this._clients[networkIn];
|
|
996
|
-
if (!client) {
|
|
997
|
-
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, `No RPC client configured for chainId ${networkIn}`);
|
|
998
|
-
}
|
|
999
|
-
const feeTiers = this.uniFeeTiers; // e.g. [500, 3000, 10000]
|
|
1000
|
-
// --- helpers
|
|
1001
|
-
const isWrappedNative = (addr) => !!wrappedNative &&
|
|
1002
|
-
(0, viem_1.getAddress)(addr).toLowerCase() === (0, viem_1.getAddress)(wrappedNative).toLowerCase();
|
|
1003
|
-
const stableAddrLower = new Set([
|
|
1004
|
-
usdcEntry?.address ? (0, viem_1.getAddress)(usdcEntry.address).toLowerCase() : '',
|
|
1005
|
-
usdtEntry?.address ? (0, viem_1.getAddress)(usdtEntry.address).toLowerCase() : '',
|
|
1006
|
-
].filter(Boolean));
|
|
1007
|
-
const isStable = (addr) => stableAddrLower.has(addr.toLowerCase());
|
|
1008
|
-
const getBaseDecimals = (base) => {
|
|
1009
|
-
const lower = base.toLowerCase();
|
|
1010
|
-
if (usdcEntry && (0, viem_1.getAddress)(usdcEntry.address).toLowerCase() === lower)
|
|
1011
|
-
return usdcEntry.decimals;
|
|
1012
|
-
if (usdtEntry && (0, viem_1.getAddress)(usdtEntry.address).toLowerCase() === lower)
|
|
1013
|
-
return usdtEntry.decimals;
|
|
1014
|
-
if (isWrappedNative(base))
|
|
1015
|
-
return 18; // adjust per-chain if needed
|
|
1016
|
-
return 18; // fallback for any other ERC-20s you might allow as base later
|
|
461
|
+
_buildFastRoutePriceResponse(params) {
|
|
462
|
+
const { networkIn, networkOut, tokenIn, tokenOut, slippage, amountIn, overrideDex, overrideAmountOutMin, overrideFeeTier, } = params;
|
|
463
|
+
const deployment = this._deployments[networkIn]?.find(d => d.dex === overrideDex);
|
|
464
|
+
if (!deployment) {
|
|
465
|
+
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, `No CLMM deployment for DEX ${overrideDex} on chainId ${networkIn}`);
|
|
466
|
+
}
|
|
467
|
+
const router = deployment.router ?? constants_1.ZERO_ADDRESS;
|
|
468
|
+
const quoter = deployment.quoter ?? constants_1.ZERO_ADDRESS;
|
|
469
|
+
const rawPriceResponse = {
|
|
470
|
+
dex: overrideDex,
|
|
471
|
+
router,
|
|
472
|
+
quoter,
|
|
473
|
+
method: `ExpectedAmountOut`,
|
|
474
|
+
feeOrTick: overrideFeeTier,
|
|
475
|
+
amountOut: overrideAmountOutMin,
|
|
1017
476
|
};
|
|
1018
|
-
const
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
deployer: d.deployer,
|
|
1031
|
-
initHash: d.initHash, // whatever your deployment holds
|
|
1032
|
-
tokenA: tokenInAddr,
|
|
1033
|
-
tokenB: base,
|
|
1034
|
-
fee,
|
|
1035
|
-
});
|
|
1036
|
-
const key = poolAddr.toLowerCase();
|
|
1037
|
-
if (!candidatesMap.has(key)) {
|
|
1038
|
-
candidatesMap.set(key, { pool: poolAddr, baseToken: base, dex: d.dex, fee });
|
|
1039
|
-
}
|
|
1040
|
-
}
|
|
1041
|
-
}
|
|
1042
|
-
}
|
|
1043
|
-
const candidates = [...candidatesMap.values()];
|
|
1044
|
-
if (!candidates.length) {
|
|
1045
|
-
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, `No candidate V3 pools could be constructed for chainId ${networkIn}`);
|
|
1046
|
-
}
|
|
1047
|
-
// --- 2) single multicall: balanceOf(tokenIn, pool) + balanceOf(base, pool) for each candidate
|
|
1048
|
-
const balanceCalls = candidates.flatMap(({ pool, baseToken }) => [
|
|
1049
|
-
{
|
|
1050
|
-
address: tokenInAddr,
|
|
1051
|
-
abi: viem_1.erc20Abi,
|
|
1052
|
-
functionName: 'balanceOf',
|
|
1053
|
-
args: [pool],
|
|
1054
|
-
},
|
|
1055
|
-
{
|
|
1056
|
-
address: baseToken,
|
|
1057
|
-
abi: viem_1.erc20Abi,
|
|
1058
|
-
functionName: 'balanceOf',
|
|
1059
|
-
args: [pool],
|
|
1060
|
-
},
|
|
1061
|
-
]);
|
|
1062
|
-
const balanceResults = await client.multicall({
|
|
1063
|
-
allowFailure: true,
|
|
1064
|
-
contracts: balanceCalls,
|
|
1065
|
-
...(networkIn === enums_1.ChainIdEnum.HYPEREVM && {
|
|
1066
|
-
multicallAddress: '0xcA11bde05977b3631167028862bE2a173976CA11',
|
|
1067
|
-
}),
|
|
1068
|
-
});
|
|
1069
|
-
const poolTVLs = [];
|
|
1070
|
-
for (let i = 0; i < candidates.length; i++) {
|
|
1071
|
-
const candidate = candidates[i];
|
|
1072
|
-
if (!candidate)
|
|
1073
|
-
continue; // should not happen
|
|
1074
|
-
const { pool, baseToken } = candidate;
|
|
1075
|
-
const tokenInBalRes = balanceResults[i * 2];
|
|
1076
|
-
const baseBalRes = balanceResults[i * 2 + 1];
|
|
1077
|
-
const tokenInRaw = tokenInBalRes?.status === 'success' && typeof tokenInBalRes.result === 'bigint'
|
|
1078
|
-
? tokenInBalRes.result
|
|
1079
|
-
: 0n;
|
|
1080
|
-
const baseRaw = baseBalRes?.status === 'success' && typeof baseBalRes.result === 'bigint'
|
|
1081
|
-
? baseBalRes.result
|
|
1082
|
-
: 0n;
|
|
1083
|
-
// quick skip if both zero to avoid NaN issues later
|
|
1084
|
-
if (tokenInRaw === 0n && baseRaw === 0n)
|
|
1085
|
-
continue;
|
|
1086
|
-
const baseDec = getBaseDecimals(baseToken);
|
|
1087
|
-
const tokenInAmt = Number(tokenInRaw) / 10 ** tokenInDecimals;
|
|
1088
|
-
const baseAmt = Number(baseRaw) / 10 ** baseDec;
|
|
1089
|
-
const usdValue = tokenInAmt * tokenInPrice + baseAmt * getBasePriceUSD(baseToken);
|
|
1090
|
-
poolTVLs.push({
|
|
1091
|
-
pool,
|
|
1092
|
-
baseToken,
|
|
1093
|
-
usdValue,
|
|
1094
|
-
baseIsNative: isWrappedNative(baseToken) ?? false,
|
|
1095
|
-
});
|
|
1096
|
-
}
|
|
1097
|
-
if (!poolTVLs.length) {
|
|
1098
|
-
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.PRICE_NOT_FOUND, `No liquidity detected for ${tokenIn} on chainId ${networkIn} across requested dexes: ${dexes.join(', ')}`);
|
|
1099
|
-
}
|
|
1100
|
-
// --- 4) pick the most liquid and validate base
|
|
1101
|
-
poolTVLs.sort((a, b) => b.usdValue - a.usdValue);
|
|
1102
|
-
const top = poolTVLs[0];
|
|
1103
|
-
if (!top) {
|
|
1104
|
-
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.PRICE_NOT_FOUND, `No liquidity detected for ${tokenIn} on chainId ${networkIn} across requested dexes: ${dexes.join(', ')}`);
|
|
1105
|
-
}
|
|
1106
|
-
if (isStable(top.baseToken)) {
|
|
1107
|
-
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.PRICE_NOT_FOUND, `Most liquid pool for ${tokenIn} on chain ${networkIn} is against a stablecoin, not native.`);
|
|
1108
|
-
}
|
|
1109
|
-
if (!top.baseIsNative) {
|
|
1110
|
-
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.PRICE_NOT_FOUND, `Most liquid pool for ${tokenIn} is not against the native token.`);
|
|
1111
|
-
}
|
|
1112
|
-
// success — top pool is native-based
|
|
1113
|
-
return;
|
|
1114
|
-
}
|
|
1115
|
-
/**
|
|
1116
|
-
* Read token0, token1, fee from a known pool via a single multicall,
|
|
1117
|
-
* then identify which configured deployment this pool belongs to by
|
|
1118
|
-
* recomputing CREATE2 for each deployment and comparing addresses.
|
|
1119
|
-
*/
|
|
1120
|
-
async _resolvePairDeploymentFast(network, pair) {
|
|
1121
|
-
const client = this._clients[network];
|
|
1122
|
-
if (!client) {
|
|
1123
|
-
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, `No RPC client configured for chainId ${network}`);
|
|
1124
|
-
}
|
|
1125
|
-
const [t0, t1, feeRes] = (await client.multicall({
|
|
1126
|
-
allowFailure: false,
|
|
1127
|
-
contracts: [
|
|
1128
|
-
{ address: pair, abi: uniswapV3_pool_abi_1.uniswapV3PoolAbi, functionName: 'token0' },
|
|
1129
|
-
{ address: pair, abi: uniswapV3_pool_abi_1.uniswapV3PoolAbi, functionName: 'token1' },
|
|
1130
|
-
{ address: pair, abi: uniswapV3_pool_abi_1.uniswapV3PoolAbi, functionName: 'fee' },
|
|
1131
|
-
],
|
|
1132
|
-
...(network === enums_1.ChainIdEnum.HYPEREVM && {
|
|
1133
|
-
multicallAddress: '0xcA11bde05977b3631167028862bE2a173976CA11',
|
|
1134
|
-
}),
|
|
1135
|
-
}));
|
|
1136
|
-
if (t0.status !== 'success' || t1.status !== 'success' || feeRes.status !== 'success') {
|
|
1137
|
-
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, `Failed to read pool data from pair address ${pair} on chain ${network}`);
|
|
1138
|
-
}
|
|
1139
|
-
const token0 = (0, viem_1.getAddress)(t0.result);
|
|
1140
|
-
const token1 = (0, viem_1.getAddress)(t1.result);
|
|
1141
|
-
const fee = Number(feeRes.result);
|
|
1142
|
-
const pairLower = pair.toLowerCase();
|
|
1143
|
-
const deployments = this.deployments[network] ?? [];
|
|
1144
|
-
for (const d of deployments) {
|
|
1145
|
-
const expected = this._create2Address({
|
|
1146
|
-
dex: d.dex,
|
|
1147
|
-
factory: d.factory,
|
|
1148
|
-
deployer: d.deployer,
|
|
1149
|
-
initHash: d.initHash,
|
|
1150
|
-
tokenA: token0,
|
|
1151
|
-
tokenB: token1,
|
|
1152
|
-
fee,
|
|
1153
|
-
});
|
|
1154
|
-
if (expected.toLowerCase() === pairLower) {
|
|
1155
|
-
return {
|
|
1156
|
-
token0,
|
|
1157
|
-
token1,
|
|
1158
|
-
fee,
|
|
1159
|
-
deployment: {
|
|
1160
|
-
dex: d.dex,
|
|
1161
|
-
router: d.router,
|
|
1162
|
-
quoter: d.quoter,
|
|
1163
|
-
factory: d.factory,
|
|
1164
|
-
deployer: d.deployer,
|
|
1165
|
-
initHash: d.initHash,
|
|
1166
|
-
},
|
|
1167
|
-
};
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, `Pair ${pair} does not match any configured V3 deployments on chain ${network}`);
|
|
1171
|
-
}
|
|
1172
|
-
/**
|
|
1173
|
-
* Fast-quote using a known pair:
|
|
1174
|
-
* - Validate the pair matches tokenIn/tokenOut (after native wrapping).
|
|
1175
|
-
* - Use the single matched deployment's quoter if present (V2 -> V1 fallback).
|
|
1176
|
-
* - Else, fallback to Offchain quoter limited to this one factory + fee.
|
|
1177
|
-
*/
|
|
1178
|
-
async _fetchKnownPairPrice(params) {
|
|
1179
|
-
const { network, tokenInForQuote, tokenOutForQuote, amountInBI, pair } = params;
|
|
1180
|
-
const client = this._clients[network];
|
|
1181
|
-
if (!client) {
|
|
1182
|
-
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, `No RPC client configured for chainId ${network}`);
|
|
1183
|
-
}
|
|
1184
|
-
// 1) Resolve pool meta + deployment (single multicall + deterministic match)
|
|
1185
|
-
const { token0, token1, fee, deployment } = await this._resolvePairDeploymentFast(network, pair);
|
|
1186
|
-
// Confirm the requested direction is (tokenIn, tokenOut) ∈ {(token0,token1),(token1,token0)}
|
|
1187
|
-
const inLower = (0, viem_1.getAddress)(tokenInForQuote).toLowerCase();
|
|
1188
|
-
const outLower = (0, viem_1.getAddress)(tokenOutForQuote).toLowerCase();
|
|
1189
|
-
const t0 = token0.toLowerCase();
|
|
1190
|
-
const t1 = token1.toLowerCase();
|
|
1191
|
-
const directionValid = (inLower === t0 && outLower === t1) || (inLower === t1 && outLower === t0);
|
|
1192
|
-
if (!directionValid) {
|
|
1193
|
-
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, `Supplied pair/token direction mismatch. Pair ${pair} tokens are ${token0}/${token1}; received ${tokenInForQuote}/${tokenOutForQuote}`);
|
|
1194
|
-
}
|
|
1195
|
-
// Build dex key for response routing
|
|
1196
|
-
const dexKey = this._buildDexKey(network, deployment.router);
|
|
1197
|
-
// 2) Try on-chain quoter (struct signature first, then legacy)
|
|
1198
|
-
if (deployment?.quoter) {
|
|
1199
|
-
// V2 (struct)
|
|
1200
|
-
try {
|
|
1201
|
-
// V2 (struct) via static call
|
|
1202
|
-
const sim = await client.simulateContract({
|
|
1203
|
-
address: deployment.quoter,
|
|
1204
|
-
abi: uniswapV3_quoter_abi_1.uniswapV3QuoterAbi,
|
|
1205
|
-
functionName: 'quoteExactInputSingle',
|
|
1206
|
-
args: [
|
|
1207
|
-
{
|
|
1208
|
-
tokenIn: (0, viem_1.getAddress)(tokenInForQuote),
|
|
1209
|
-
tokenOut: (0, viem_1.getAddress)(tokenOutForQuote),
|
|
1210
|
-
amountIn: amountInBI,
|
|
1211
|
-
fee,
|
|
1212
|
-
sqrtPriceLimitX96: 0n,
|
|
1213
|
-
},
|
|
1214
|
-
],
|
|
1215
|
-
});
|
|
1216
|
-
const [amountOut, sqrtAfter, ticks, gas] = sim.result;
|
|
1217
|
-
return {
|
|
1218
|
-
amountOut,
|
|
1219
|
-
payload: {
|
|
1220
|
-
dex: dexKey,
|
|
1221
|
-
quoterAddress: deployment.quoter,
|
|
1222
|
-
method: 'QuoterV2.quoteExactInputSingle',
|
|
1223
|
-
feeTier: fee,
|
|
1224
|
-
amountOut: amountOut.toString(),
|
|
1225
|
-
gasEstimate: gas ? gas.toString() : undefined,
|
|
1226
|
-
sqrtPriceX96After: sqrtAfter ? sqrtAfter.toString() : undefined,
|
|
1227
|
-
initializedTicksCrossed: ticks,
|
|
1228
|
-
notes: `Known pair fast path (${pair}).`,
|
|
1229
|
-
},
|
|
1230
|
-
};
|
|
1231
|
-
}
|
|
1232
|
-
catch (eV2) {
|
|
1233
|
-
// Legacy V1 (tuple) via static call
|
|
1234
|
-
try {
|
|
1235
|
-
const simV1 = await client.simulateContract({
|
|
1236
|
-
address: deployment.quoter,
|
|
1237
|
-
abi: uniswapV3_quoter_abi_1.uniswapV3QuoterAbi,
|
|
1238
|
-
functionName: 'quoteExactInputSingle',
|
|
1239
|
-
args: [
|
|
1240
|
-
{
|
|
1241
|
-
tokenIn: (0, viem_1.getAddress)(tokenInForQuote),
|
|
1242
|
-
tokenOut: (0, viem_1.getAddress)(tokenOutForQuote),
|
|
1243
|
-
fee,
|
|
1244
|
-
amountIn: amountInBI,
|
|
1245
|
-
sqrtPriceLimitX96: 0n,
|
|
1246
|
-
},
|
|
1247
|
-
],
|
|
1248
|
-
});
|
|
1249
|
-
const [amountOut] = simV1.result;
|
|
1250
|
-
return {
|
|
1251
|
-
amountOut,
|
|
1252
|
-
payload: {
|
|
1253
|
-
dex: dexKey,
|
|
1254
|
-
quoterAddress: deployment.quoter,
|
|
1255
|
-
method: 'Quoter.quoteExactInputSingle',
|
|
1256
|
-
feeTier: fee,
|
|
1257
|
-
amountOut: amountOut.toString(),
|
|
1258
|
-
notes: `Known pair fast path (${pair}).`,
|
|
1259
|
-
},
|
|
1260
|
-
};
|
|
1261
|
-
}
|
|
1262
|
-
catch (eV1) {
|
|
1263
|
-
console.log(`Warning: on-chain quoter calls failed for pair ${pair} on chain ${network}. V2 error: ${eV2}; V1 error: ${eV1}. Falling back to off-chain quoter.`);
|
|
1264
|
-
// fall through to off-chain
|
|
1265
|
-
}
|
|
1266
|
-
}
|
|
1267
|
-
}
|
|
1268
|
-
// 3) Off-chain fallback (constrained)
|
|
1269
|
-
if (deployment.factory) {
|
|
1270
|
-
const off = new v3_offchain_quoter_service_1.V3OffchainQuoter();
|
|
1271
|
-
const res = await off.fetchV3Quote({
|
|
1272
|
-
client,
|
|
1273
|
-
tokenIn: (0, viem_1.getAddress)(tokenInForQuote),
|
|
1274
|
-
tokenOut: (0, viem_1.getAddress)(tokenOutForQuote),
|
|
1275
|
-
amountIn: amountInBI,
|
|
1276
|
-
factory: (0, viem_1.getAddress)(deployment.factory),
|
|
1277
|
-
fees: [fee],
|
|
1278
|
-
});
|
|
1279
|
-
if (res?.best && res.best.ok && res.best.amountOut > 0n) {
|
|
1280
|
-
return {
|
|
1281
|
-
amountOut: res.best.amountOut,
|
|
1282
|
-
payload: {
|
|
1283
|
-
dex: dexKey,
|
|
1284
|
-
quoterAddress: undefined,
|
|
1285
|
-
method: 'OffchainQuoter.simulateExactInputSingle',
|
|
1286
|
-
feeTier: fee,
|
|
1287
|
-
amountOut: res.best.amountOut.toString(),
|
|
1288
|
-
sqrtPriceX96After: res.best.sqrtPriceX96After
|
|
1289
|
-
? res.best.sqrtPriceX96After.toString()
|
|
1290
|
-
: undefined,
|
|
1291
|
-
initializedTicksCrossed: res.best.initializedTicksCrossed,
|
|
1292
|
-
notes: `Known pair fast path (${pair}).`,
|
|
1293
|
-
},
|
|
1294
|
-
};
|
|
1295
|
-
}
|
|
1296
|
-
}
|
|
1297
|
-
throw (0, utils_1.sdkError)(enums_1.SdkErrorEnum.QUOTE_NOT_FOUND, `Unable to quote via known pair ${pair}`);
|
|
477
|
+
const priceResponse = {
|
|
478
|
+
protocol: this.protocol,
|
|
479
|
+
networkIn,
|
|
480
|
+
networkOut,
|
|
481
|
+
tokenIn,
|
|
482
|
+
tokenOut,
|
|
483
|
+
amountIn,
|
|
484
|
+
amountOut: overrideAmountOutMin,
|
|
485
|
+
protocolResponse: rawPriceResponse,
|
|
486
|
+
slippage,
|
|
487
|
+
};
|
|
488
|
+
return priceResponse;
|
|
1298
489
|
}
|
|
1299
490
|
}
|
|
1300
491
|
exports.V3StyleDexService = V3StyleDexService;
|