{"record":{"id":"96e2c45d0179074a","repo":"nautechsystems/nautilus_trader","slug":"failed-to-decode-initialize-event-data-e","errorCode":null,"errorMessage":"Failed to decode initialize event data: {e}","messagePattern":"Failed to decode initialize event data: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/exchanges/parsing/uniswap_v3/initialize.rs","lineNumber":65,"sourceCode":"/// Panics if the contract address is not set in the log.\npub fn parse_initialize_event_hypersync(\n    dex: SharedDex,\n    log: &HypersyncLog,\n) -> anyhow::Result<InitializeEvent> {\n    validate_event_signature_hash(\"InitializeEvent\", INITIALIZE_EVENT_SIGNATURE_HASH, log)?;\n\n    if let Some(data) = &log.data {\n        let data_bytes = data.as_ref();\n\n        // Validate if data contains 2 parameters of 32 bytes each (sqrtPriceX96 and tick)\n        if data_bytes.len() < 2 * 32 {\n            anyhow::bail!(\"Initialize event data is too short\");\n        }\n\n        // Decode the data using the InitializeEventData struct\n        let decoded = match <InitializeEventData as SolType>::abi_decode(data_bytes) {\n            Ok(decoded) => decoded,\n            Err(e) => anyhow::bail!(\"Failed to decode initialize event data: {e}\"),\n        };\n\n        let pool_address = Address::from_slice(\n            log.address\n                .clone()\n                .expect(\"Contract address should be set in logs\")\n                .as_ref(),\n        );\n        let pool_identifier = PoolIdentifier::Address(Ustr::from(&pool_address.to_string()));\n\n        Ok(InitializeEvent::new(\n            dex,\n            pool_identifier,\n            decoded.sqrt_price_x96,\n            i32::try_from(decoded.tick)?,\n        ))\n    } else {\n        Err(anyhow::anyhow!(\"Missing data in initialize event log\"))","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/exchanges/parsing/uniswap_v3/initialize.rs#L47-L83","documentation":"Thrown by parse_initialize_event_hypersync when the data payload is at least 64 bytes but alloy's abi_decode of InitializeEventData still fails, with the underlying decode error message embedded. This usually means the words are present but the values/types do not match the struct (e.g. dynamic-encoded data or extra/odd-length bytes).","triggerScenarios":"A Hypersync log whose data is >= 64 bytes but not exactly two 32-byte static words — e.g. data length not a multiple of 32, trailing bytes, or data from a different event ABI.","commonSituations":"Forked V3 deployments with modified Initialize events, corrupted or re-serialized hypersync payloads, mixing up data from a different event with the same topic0.","solutions":["Check that data_bytes.len() is exactly 64 bytes; truncate or reject otherwise.","Decode the two words manually (sqrtPriceX96: uint256, tick: int24 in first 32-byte word) to inspect raw values.","Verify the emitting contract is a canonical Uniswap V3 pool.","Check alloy-sol-types version compatibility for the generated InitializeEventData type."],"exampleFix":"// before\nif data_bytes.len() < 2 * 32 { bail!(\"too short\"); }\nlet decoded = <InitializeEventData as SolType>::abi_decode(data_bytes)?;\n// after: strict length check\nif data_bytes.len() != 2 * 32 {\n    anyhow::bail!(\"Initialize data must be 64 bytes, got {}\", data_bytes.len());\n}\nlet decoded = <InitializeEventData as SolType>::abi_decode(data_bytes)?;","handlingStrategy":"validation","validationCode":"// Ensure exact-length data before parsing\nfn is_initialize_shaped(log: &HypersyncLog) -> bool {\n    log.data.as_ref().map(|d| d.len() == 64).unwrap_or(false)\n}\nif !is_initialize_shaped(&log) { skip(&log); }","typeGuard":"fn exact_initialize_data(log: &HypersyncLog) -> Option<&[u8]> {\n    let d = log.data.as_deref()?;\n    (d.len() == 64).then_some(d)\n}","tryCatchPattern":"match parse_initialize_event_hypersync(log, dex) {\n    Ok(event) => process(event),\n    Err(e) if e.to_string().contains(\"Failed to decode initialize\") => {\n        log::warn!(\"non-canonical initialize payload: {e}\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Require exactly 64 bytes of data, not just >= 64","Confirm the emitting address is a canonical Uniswap V3 pool","Hex-inspect failing payloads manually to identify layout drift","Pin alloy-sol-types versions used for InitializeEventData codegen"],"tags":["abi-decode","uniswap-v3","hypersync","events"],"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-14T00:17:10.932Z"}