nautechsystems/nautilus_trader · error

Failed to register DEX exchange: {e}

Error message

Failed to register DEX exchange: {e}

What it means

In `analyze_pool_with_client`, `register_dex_exchange_for_pool` registers the DEX exchange for a single pool in the data client before syncing and profiling. If the registration future returns an error (RPC failure, unsupported DEX, bad pool address), it is wrapped with this message.

Source

Thrown at crates/cli/src/blockchain/analyze.rs:269

    reset: bool,
    require_existing_snapshot: bool,
    checkpoint_blocks: &[u64],
    skip_validation: bool,
    snapshot_from_rpc: bool,
) -> anyhow::Result<Vec<PoolAnalysisOutcome>> {
    if snapshot_from_rpc {
        validate_snapshot_from_rpc_options(from_block, reset, require_existing_snapshot)?;
    }

    let pool_address = validate_address(&pool_address)?;
    let pool_identifier = PoolIdentifier::Address(Ustr::from(&pool_address.to_string()));

    // Load only this pool into the cache rather than the whole DEX pool set (tens of thousands of
    // pools on large DEXes); sync and profiling below operate on this single pool.
    data_client
        .register_dex_exchange_for_pool(dex_type, &pool_identifier)
        .await
        .map_err(|e| anyhow::anyhow!("Failed to register DEX exchange: {e}"))?;

    let checkpoints = if checkpoint_blocks.is_empty() {
        vec![to_block]
    } else {
        normalize_checkpoints(checkpoint_blocks, to_block)
    };
    let Some(first_checkpoint) = checkpoints.first().copied() else {
        anyhow::bail!("All --checkpoint-blocks exceed --to-block {to_block}");
    };

    // Bounded-replay mode: a usable snapshot must already exist at or before the first checkpoint,
    // otherwise the caller wants needs_bootstrap rather than a full creation-to-target bootstrap.
    if require_existing_snapshot
        && needs_bootstrap_before_target(data_client, &pool_identifier, first_checkpoint).await?
    {
        return Ok(vec![PoolAnalysisOutcome::NeedsBootstrap(
            PoolNeedsBootstrapOutcome {
                pool_address: pool_address.to_string(),

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Verify the pool address is a valid contract for the given chain and DEX.
  2. Confirm the DEX type is supported for the chain (`get_supported_dexes_for_chain`).
  3. Retry if the cause is an RPC/network error; use a reliable RPC endpoint.
  4. Inspect the inner error text after the colon to see whether it's transport, contract, or validation related.

Example fix

// before
nautilus blockchain analyze-pool --chain base --dex uniswapv2 --pool 0xdeadbeef
// after: use a real pool address on the chosen chain/DEX
nautilus blockchain analyze-pool --chain base --dex uniswap-v2 --pool 0x<real-uniswap-v2-pool>
Defensive patterns

Strategy: try-catch

Validate before calling

assert!(get_supported_dexes_for_chain(chain.name).contains(&dex_type));
assert!(pool_address.starts_with("0x") && pool_address.len() == 42);

Try / catch

match analyze_pool_with_client(...).await {
    Ok(r) => r,
    Err(e) if e.to_string().contains("Failed to register DEX exchange") => {
        // inspect {e:#} root cause; verify pool address and DEX type, then retry
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling pool analysis (`run_analyze_pool` / `run_analyze_pools`) where `data_client.register_dex_exchange_for_pool(dex_type, pool)` fails — wrong DEX type for the chain, malformed pool address, or the underlying RPC request errors while fetching pool/factory data.

Common situations: Typos or wrong-case DEX names that still pass case-insensitive lookup; pool contract that doesn't match the DEX's expected interface; unstable RPC endpoint during registration.

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/7232646c33c02579. Report an issue: GitHub.