DEX Pool Scanner (Rust)
Rust crate for multi-protocol DEX liquidity pool discovery and real-time price tracking on EVM networks. Discovers pools from multiple DEX protocols using The Graph and is designed to monitor price changes via WebSocket. Mirrors the behavior of the TypeScript dex-pool-scanner package.
Crate root: All paths in this README and in docs are relative to the crate root (the rust/ directory). Run commands and config file lookups from rust/ so that protocols.json and tokens.json resolve to rust/protocols.json and rust/tokens.json unless overridden with env vars.
Supported Protocols
Full support for pool discovery (real-time price tracking via swap events is in progress):
- Uniswap V3
- Uniswap V2
Other protocols with V3-compatible subgraphs (e.g. Aerodrome CL, SushiSwap V3) work with poolType: "UniswapV3" in config.
Installation
Add to your Cargo.toml:
[]
= "0.1"
Or clone the repo and use the path (from the repository root):
[]
= { = "rust" }
Quick Start
- Create
protocols.jsonat the crate root (rust/protocols.json) or setPROTOCOLS_JSON:
- Set environment variables (e.g. in
.env):
THE_GRAPH_API_KEY=your_api_key
RPC_URL=wss://your-rpc-url
ENABLE_LOG=true
- From the crate root (
rust/), run the example:
Build on top
use ;
use Arc;
async
Configuration
protocols.json
Required configuration file:
- protocols: Map of protocol ID → config
name: Display namefactory: Factory contract addresssubgraphId: The Graph subgraph IDenabled: Enable/disable protocolpoolType:"UniswapV3"or"UniswapV2"
- discovery:
minLiquidityUSD: Minimum liquidity threshold (USD)cacheRefreshMinutes: Reserved for future cache behaviormaxPoolsPerProtocol: Max pools to fetch per protocol
tokens.json (Optional)
Token whitelist (symbol → address). Used for reference or future filtering.
Config paths default to protocols.json and tokens.json at the crate root (when run from rust/). Override with PROTOCOLS_JSON and TOKENS_JSON.
API
Config
config::load_protocols_file(path) -> Result<(Vec<ProtocolConfig>, DiscoveryConfig)>– Load protocols and discovery fromprotocols.json(subgraph URLs built fromTHE_GRAPH_API_KEY).config::load_tokens_file(path) -> Result<HashMap<String, Address>>– Load token whitelist.
Discovery
PoolDiscovery::new()– Create discovery client.discover_pools(&self, protocols, config) -> Result<Vec<CachedPool>>– Fetch pools from all enabled protocols’ subgraphs.
Scanner
Scanner::new(on_price_change) -> Result<Self>– Create scanner with callback. ReadsRPC_URLfrom the environment.scanner.start() -> Result<()>– Load config (protocols.json,tokens.json), discover pools, filter by token whitelist, and subscribe to price changes.PriceChangeCallback:Arc<dyn Fn(CachedPool, PoolPrice, Option<PoolPrice>) + Send + Sync>.
Environment Variables
THE_GRAPH_API_KEY: The Graph API key (required for discovery)RPC_URL: WebSocket RPC URL (required)PROTOCOLS_JSON: Path toprotocols.json(default:protocols.jsonat crate root)TOKENS_JSON: Path totokens.json(default:tokens.jsonat crate root)
Documentation
All docs live under the crate root at rust/docs/:
- Configuration – Config files and env vars
- Pool Discovery – How discovery works
- Protocols – Supported protocols and types
- Troubleshooting – Common issues
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT © Maximiliano Malvido