{"record":{"id":"9e5b87871dc09c63","repo":"nautechsystems/nautilus_trader","slug":"failed-to-decode-initialize-event-data-e-9e5b87","errorCode":null,"errorMessage":"Failed to decode initialize event data: {e}","messagePattern":"Failed to decode initialize event data: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/exchanges/parsing/uniswap_v4/initialize.rs","lineNumber":135,"sourceCode":"            .ok_or_else(|| anyhow::anyhow!(\"Missing currency1 topic\"))?\n            .as_ref()\n            .get(12..32)\n            .ok_or_else(|| anyhow::anyhow!(\"Invalid currency1 topic length\"))?,\n    );\n\n    if let Some(data) = log.data {\n        let data_bytes = data.as_ref();\n\n        // Validate minimum data length (5 fields × 32 bytes = 160 bytes)\n        if data_bytes.len() < 160 {\n            anyhow::bail!(\n                \"Initialize event data too short: expected at least 160 bytes, was {}\",\n                data_bytes.len()\n            );\n        }\n\n        let decoded = <InitializeEventData as SolType>::abi_decode(data_bytes)\n            .map_err(|e| anyhow::anyhow!(\"Failed to decode initialize event data: {e}\"))?;\n\n        let mut event = PoolCreatedEvent::new(\n            block_number,\n            currency0,\n            currency1,\n            pool_manager_address, // V4 pools are managed by PoolManager\n            PoolIdentifier::PoolId(pool_identifier), // Pool ID (bytes32 as hex string)\n            Some(decoded.fee.to::<u32>()),\n            Some(i32::try_from(decoded.tick_spacing)? as u32),\n        );\n\n        event.set_initialize_params(decoded.sqrtPriceX96, i32::try_from(decoded.tick)?);\n        event.set_hooks(decoded.hooks);\n\n        Ok(event)\n    } else {\n        Err(anyhow::anyhow!(\"Missing data in initialize event log\"))\n    }","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/exchanges/parsing/uniswap_v4/initialize.rs#L117-L153","documentation":"Thrown by `parse_initialize_event_hypersync` when the ABI decode of the log's data section fails after passing the 160-byte length check. The data should decode into `InitializeEventData` (sqrtPriceX96, tick, protocolFee, lpFee, hooks). A decode error means the bytes don't match the expected ABI layout.","triggerScenarios":"Calling `parse_initialize_event_hypersync` with a log whose `data` field passes the 160-byte length check but whose contents do not conform to the `InitializeEventData` ABI layout (e.g. extra/missing words, non-standard encoding from a fork).","commonSituations":"Parsing logs from a Uniswap V4 fork whose Initialize event has extra/renamed parameters; ABI type drift (uint160 vs uint256, int24 packing) after an alloy sol! definition update; indexer returning corrupted data payloads.","solutions":["Log the raw `e` from the alloy decode error and hex of `data_bytes` to see which field failed.","Confirm the `InitializeEventData` sol! definition matches the deployed Uniswap V4 contract's event (field order/types).","Decode manually (offsets of 32 bytes per field) for the specific log to verify the layout.","Update the adapter/ABI if the pool manager version on the target chain differs."],"exampleFix":"// before\nlet decoded = <InitializeEventData as SolType>::abi_decode(data_bytes)\n    .map_err(|e| anyhow::anyhow!(\"Failed to decode initialize event data: {e}\"))?;\n// after\nlet decoded = <InitializeEventData as SolType>::abi_decode(data_bytes).with_context(|| {\n    format!(\"decode failed for tx {:?}, data: {}\", log.transaction_hash.as_deref().map(hex::encode), hex::encode(data_bytes))\n})?;","handlingStrategy":"try-catch","validationCode":"// precondition check before decode\nif log.data.as_ref().map(|d| d.as_ref().len() % 32 != 0 || d.as_ref().len() < 160).unwrap_or(true) {\n    return Ok(None);\n}","typeGuard":null,"tryCatchPattern":"match parse_initialize_event_hypersync(&log) {\n    Ok(ev) => store(ev),\n    Err(e) if e.to_string().starts_with(\"Failed to decode initialize event data\") => {\n        quarantine_log(&log, e); // keep hex for later ABI review\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Keep the sol! InitializeEventData definition matching the deployed contract","Quarantine undecodable logs with their hex payload for offline analysis","Test parsing against known-good mainnet Initialize logs in CI"],"tags":["blockchain","abi-decoding","hypersync","uniswap-v4"],"backgroundTag":"schema-validation-failed","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"}