{"record":{"id":"56e9f071240200b8","repo":"nautechsystems/nautilus_trader","slug":"initialize-event-missing-topics-expected-4-was-56e9f0","errorCode":null,"errorMessage":"Initialize event missing topics: expected 4, was {log_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":176,"sourceCode":"/// # Errors\n///\n/// Returns an error if the log parsing fails or if the event data is invalid.\npub fn parse_initialize_event_rpc(log: &RpcLog) -> anyhow::Result<PoolCreatedEvent> {\n    rpc_log::validate_event_signature(log, INITIALIZE_EVENT_SIGNATURE_HASH, \"InitializeEvent\")?;\n\n    let block_number = rpc_log::extract_block_number(log)?;\n\n    // Pool address is the PoolManager contract (event emitter)\n    let pool_manager_bytes = rpc_log::decode_hex(&log.address)?;\n    let pool_manager_address = Address::from_slice(&pool_manager_bytes);\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    if log.topics.len() < 4 {\n        anyhow::bail!(\n            \"Initialize event missing topics: expected 4, was {}\",\n            log.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 = rpc_log::decode_hex(&log.topics[1])?;\n    let pool_identifier = Ustr::from(&hex::encode_prefixed(pool_id_bytes));\n\n    let currency0_bytes = rpc_log::decode_hex(&log.topics[2])?;\n    let currency0 = Address::from_slice(&currency0_bytes[12..32]);\n\n    let currency1_bytes = rpc_log::decode_hex(&log.topics[3])?;\n    let currency1 = Address::from_slice(&currency1_bytes[12..32]);\n\n    // Extract and decode event data\n    let data_bytes = rpc_log::extract_data_bytes(log)?;\n","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/exchanges/parsing/uniswap_v4/initialize.rs#L158-L194","documentation":"parse_initialize_event_rpc mirrors the hypersync parser: it requires 4 topics (event signature, poolId, currency0, currency1) on the RPC log before extracting V4 pool parameters. Fewer topics means the log cannot be a V4 Initialize event and the parser bails.","triggerScenarios":"Calling parse_initialize_event_rpc with an RPC log having fewer than 4 topics — non-V4 contract logs, a filter without topic0 constraint, or logs from a V3 pool whose Initialize has different indexed layout.","commonSituations":"get_logs calls scoped by address but not by topics, pulling in every event the contract emits; decoding logs from unrelated protocols; re-indexing forks with different event definitions.","solutions":["Pass topic0 (exact V4 Initialize signature) in the eth_getLogs filter so only matching logs are fetched","Check log.topics.len() >= 4 in the caller before invoking the parser and skip otherwise","Verify the emitting contract is the chain's V4 PoolManager","Route non-V4 logs to the correct version-specific parser"],"exampleFix":"// before\nif log.topics.len() < 4 {\n    anyhow::bail!(\"Initialize event missing topics: expected 4, was {}\", log.topics.len());\n}\n// after\nif log.topics.len() < 4 {\n    tracing::debug!(n = log.topics.len(), \"skipping non-V4 initialize log\");\n    return Ok(None); // or continue\n}","handlingStrategy":"validation","validationCode":"fn is_v4_initialize_rpc_log(log: &RpcLog) -> bool {\n    log.topics.len() >= 4 && log.topics[0] == INITIALIZE_V4_TOPIC0\n}\nif !is_v4_initialize_rpc_log(&log) { skip_or_log(); }","typeGuard":null,"tryCatchPattern":"match parse_initialize_event_rpc(&log, &dex) {\n    Ok(ev) => handle(ev),\n    Err(e) => { tracing::debug!(%e, \"non-V4 initialize log skipped\"); Ok(None) }\n}","preventionTips":["Scope eth_getLogs with the exact V4 Initialize topic0","Check topic count before calling the parser","Confirm PoolManager addresses per chain","Keep version-specific parsers separate"],"tags":["blockchain","uniswap-v4","rpc","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-14T05:17:10.506Z"}