Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion bin/tel-indexer/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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]
Expand All @@ -49,6 +53,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

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?;
}
Expand Down
52 changes: 52 additions & 0 deletions crates/tel-indexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(())
}
20 changes: 14 additions & 6 deletions scripts/run-fetch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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