{"record":{"id":"c7dc846159560583","repo":"nautechsystems/nautilus_trader","slug":"initialize-event-missing-topics-expected-4-was","errorCode":null,"errorMessage":"Initialize event missing topics: expected 4, was {topics_len}","messagePattern":"Initialize event missing topics: expected 4, was (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/exchanges/parsing/uniswap_v4/initialize.rs","lineNumber":92,"sourceCode":"\n    let block_number = extract_block_number(&log)?;\n\n    // The pool address for V4 is the PoolManager contract address (the event emitter)\n    let pool_manager_address = Address::from_slice(\n        log.address\n            .clone()\n            .expect(\"PoolManager address should be set in logs\")\n            .as_ref(),\n    );\n\n    // Extract currency0 and currency1 from topics\n    // topics[0] = event signature\n    // topics[1] = poolId (bytes32)\n    // topics[2] = currency0 (indexed)\n    // topics[3] = currency1 (indexed)\n    let topics = &log.topics;\n    if topics.len() < 4 {\n        anyhow::bail!(\n            \"Initialize event missing topics: expected 4, was {}\",\n            topics.len()\n        );\n    }\n\n    // Extract Pool ID from topics[1] - this is the unique identifier for V4 pools\n    let pool_id_bytes = topics[1]\n        .as_ref()\n        .ok_or_else(|| anyhow::anyhow!(\"Missing poolId topic\"))?\n        .as_ref();\n    let pool_identifier = Ustr::from(&hex::encode_prefixed(pool_id_bytes));\n\n    let currency0 = Address::from_slice(\n        topics[2]\n            .as_ref()\n            .ok_or_else(|| anyhow::anyhow!(\"Missing currency0 topic\"))?\n            .as_ref()\n            .get(12..32)","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/exchanges/parsing/uniswap_v4/initialize.rs#L74-L110","documentation":"parse_initialize_event_hypersync requires 4 topics for a Uniswap V4 Initialize event (event signature, poolId, currency0, currency1 — the latter two indexed). Fewer topics means the log is not a V4 Initialize event, so the parser cannot proceed.","triggerScenarios":"Calling parse_initialize_event_hypersync with a log carrying fewer than 4 topics — non-V4 PoolManager logs, a broad hypersync filter without topic0, or malformed synthetic logs.","commonSituations":"Subscribing without an event-signature topic filter so unrelated events hit the parser; decoding logs from V3 pools (Initialize has 0 indexed currencies) or other AMMs; test logs missing indexed params.","solutions":["Filter hypersync queries by the exact V4 Initialize topic0 and require 4 topics","Check topics.len() >= 4 in the caller before invoking the parser and skip otherwise","Verify the emitting contract is a V4 PoolManager","If V3 Initialize logs are mixed in, route them to the V3 parser instead"],"exampleFix":"// before\nif topics.len() < 4 {\n    anyhow::bail!(\"Initialize event missing topics: expected 4, was {}\", topics.len());\n}\n// after\nif topics.len() < 4 {\n    tracing::debug!(n = topics.len(), \"skipping non-V4 initialize log\");\n    return Ok(None); // or continue\n}","handlingStrategy":"validation","validationCode":"fn is_v4_initialize_topics(log: &HypersyncLog) -> bool {\n    log.topics.len() >= 4 && log.topics[0].as_ref() == INITIALIZE_V4_TOPIC0\n}\nif !is_v4_initialize_topics(&log) { skip_or_log(); }","typeGuard":null,"tryCatchPattern":"match parse_initialize_event_hypersync(&log, &dex) {\n    Ok(ev) => handle(ev),\n    Err(e) => { tracing::debug!(%e, \"initialize log skipped\"); Ok(None) }\n}","preventionTips":["Filter hypersync queries by the exact V4 Initialize topic0","Require 4 topics in the subscription","Verify the emitting contract is a V4 PoolManager","Route V3 Initialize logs to the V3 parser"],"tags":["blockchain","uniswap-v4","event-parsing","missing-field"],"backgroundTag":"missing-required-argument","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}