diff --git a/bin/tel-indexer/main.rs b/bin/tel-indexer/main.rs index 9ef2f46..bd3c0cb 100644 --- a/bin/tel-indexer/main.rs +++ b/bin/tel-indexer/main.rs @@ -1,7 +1,7 @@ use clap::Parser; use tel_core::{config, dexes::uniswap_v3}; -use tel_indexer::{run_indexer, run_indexer_fetch}; +use tel_indexer::{run_indexer, run_indexer_fetch, run_indexer_fetch_light}; use tracing::Level; use tracing_subscriber::FmtSubscriber; @@ -25,6 +25,10 @@ struct Args { /// Fetch all blocks #[arg(long)] fetch_all: bool, + + /// Fetch blocks for light mode pools only + #[arg(long)] + fetch_light: bool, } #[tokio::main] @@ -49,6 +53,8 @@ async fn main() -> Result<(), Box> { if args.fetch_all { run_indexer_fetch(config).await?; + } else if args.fetch_light { + run_indexer_fetch_light(config).await?; } else { run_indexer(config, args.dex, args.pair, false).await?; } diff --git a/crates/tel-indexer/src/lib.rs b/crates/tel-indexer/src/lib.rs index 6baf8af..6fa3b96 100644 --- a/crates/tel-indexer/src/lib.rs +++ b/crates/tel-indexer/src/lib.rs @@ -170,6 +170,44 @@ impl Indexer { Ok(()) } + pub async fn fetch_light(&self) -> Result<(), Error> { + info!("Starting indexer fetch light mode (light_mode_pools: {:?})...", LIGHT_MODE_POOLS); + + // Fetch all pools from each DEX + for (dex_name, dex) in &self.dexes { + info!("Fetching pools for DEX: {}", dex_name); + // TODO: use get_all_pools_with_addresses instead of get_all_pools + match dex.get_all_pools().await { + Ok(pools) => { + // Filter pools to only include light mode pools + let light_pools: Vec<_> = pools + .into_iter() + .filter(|pool| { + LIGHT_MODE_POOLS.contains(&pool.address.to_string().as_str()) + }) + .collect(); + + info!("Found {} light mode pools for {} (filtered from total)", light_pools.len(), dex_name); + + for pool in light_pools { + match self.process_pool(&pool).await { + Ok(_) => debug!("Processed pool {} on {}", pool.address, pool.dex), + Err(e) => warn!( + "Failed to process pool {} on {}: {}", + pool.address, pool.dex, e + ), + } + } + } + Err(e) => { + warn!("Failed to fetch pools for {}: {}", dex_name, e); + } + } + } + + Ok(()) + } + /// Processes a liquidity pool by retrieving and storing its liquidity distribution. /// /// Attempts to obtain the DEX implementation for the given pool, fetches the pool's liquidity distribution asynchronously, and saves the result to storage. @@ -367,5 +405,19 @@ pub async fn run_indexer_fetch( indexer.fetch().await?; + Ok(()) +} + +pub async fn run_indexer_fetch_light( + config: Config, +) -> Result<(), Error> { + // Initialize the database connection + let storage = Arc::new(SqliteStorage::new(&config.database.url)?); + let indexer = Indexer::new(config, storage)?; + + info!("Indexer running in fetch light mode"); + indexer.fetch_light().await?; + + Ok(()) } diff --git a/scripts/run-fetch.sh b/scripts/run-fetch.sh index 1bc9727..6fbec84 100755 --- a/scripts/run-fetch.sh +++ b/scripts/run-fetch.sh @@ -3,19 +3,27 @@ # Colors for output GREEN='\033[0;32m' BLUE='\033[0;34m' +RED='\033[0;31m' NC='\033[0m' # No Color -echo -e "${BLUE}Starting tel-indexer to fetch all blocks...${NC}" - -# Run the indexer with the --fetch-all flag -cargo run --bin tel-indexer -- --fetch-all +# Check if "full" argument is passed +if [ "$1" = "full" ]; then + echo -e "${BLUE}Starting tel-indexer to fetch all pools...${NC}" + cargo run --bin tel-indexer -- --fetch-all + FETCH_TYPE="all pools" +else + echo -e "${BLUE}Starting tel-indexer to fetch light mode pools...${NC}" + echo -e "${BLUE}(Use './run-fetch.sh full' to fetch all pools)${NC}" + cargo run --bin tel-indexer -- --fetch-light + FETCH_TYPE="light mode pools" +fi EXIT_CODE=$? if [ $EXIT_CODE -eq 0 ]; then - echo -e "${GREEN}Successfully fetched all blocks.${NC}" + echo -e "${GREEN}Successfully fetched ${FETCH_TYPE}.${NC}" else - echo -e "${RED}Failed to fetch blocks. Exit code: $EXIT_CODE${NC}" + echo -e "${RED}Failed to fetch ${FETCH_TYPE}. Exit code: $EXIT_CODE${NC}" fi exit $EXIT_CODE