{"record":{"id":"945e98ddc3582bf2","repo":"nautechsystems/nautilus_trader","slug":"swap-event-data-is-too-short","errorCode":null,"errorMessage":"Swap event data is too short","messagePattern":"Swap event data is too short","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/exchanges/parsing/pancakeswap_v3/swap.rs","lineNumber":71,"sourceCode":"///\n/// # Errors\n///\n/// Returns an error if the log parsing fails or if the event data is invalid.\n///\n/// # Panics\n///\n/// Panics if the contract address is not set in the log.\npub fn parse_swap_event_hypersync(dex: SharedDex, log: &HypersyncLog) -> anyhow::Result<SwapEvent> {\n    validate_event_signature_hash(\"SwapEvent\", SWAP_EVENT_SIGNATURE_HASH, log)?;\n\n    let sender = extract_address_from_topic(log, 1, \"sender\")?;\n    let recipient = extract_address_from_topic(log, 2, \"recipient\")?;\n\n    if let Some(data) = &log.data {\n        let data_bytes = data.as_ref();\n\n        if data_bytes.len() < 7 * 32 {\n            anyhow::bail!(\"Swap event data is too short\");\n        }\n\n        let decoded = match <SwapEventData as SolType>::abi_decode(data_bytes) {\n            Ok(decoded) => decoded,\n            Err(e) => anyhow::bail!(\"Failed to decode swap event data: {e}\"),\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        Ok(SwapEvent::new(\n            dex,\n            pool_identifier,\n            extract_block_number(log)?,\n            extract_transaction_hash(log)?,","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/exchanges/parsing/pancakeswap_v3/swap.rs#L53-L89","documentation":"parse_swap_event_hypersync decodes a PancakeSwap V3 Swap log whose data section must carry 7 ABI words (Uniswap V3's 5 fields plus two appended protocolFees words). Before decoding, the function checks `data_bytes.len() < 7 * 32` and bails with 'Swap event data is too short' if the payload cannot hold all 7 words. This guards the ABI decoder and surfaces a common case: a log with a Uniswap V3-style (5-word) data payload being fed to the PancakeSwap parser.","triggerScenarios":"Calling parse_swap_event_hypersync with a HypersyncLog whose topic0 matches the PancakeSwap V3 Swap signature hash (0x19b47279...) but whose `data` hex is shorter than 224 bytes (7 x 32 bytes) — e.g. a truncated 5-word Uniswap V3 layout, a partially fetched log, or corrupted data.","commonSituations":"Indexing BSC pools with a query that mixes Uniswap V3 and PancakeSwap V3 logs; copying a Uniswap V3 Swap log fixture into PancakeSwap test data; HyperSync responses truncated by size limits or network errors; manually constructing test logs with incomplete data fields.","solutions":["Verify the log is actually a PancakeSwap V3 Swap event: its topic0 must be 0x19b47279256b2a23a1665c810c8d55a1758940ee09377d4f8d26497a3577dc83 and data must be 0x + 448 hex chars (7 words); route Uniswap V3 topic0 (0xc42079f9...) to the Uniswap V3 parser instead","Check the HyperSync query/response for truncation — re-fetch the log and confirm the full data field is returned","Validate `log.data` length in your ingestion pipeline before calling parse_swap_event_hypersync and skip or quarantine logs shorter than 224 bytes","If building fixtures/tests, base them on a real PancakeSwap V3 Swap log (7 data words) rather than a Uniswap V3 one"],"exampleFix":"// before: feeding a Uniswap V3 (5-word) data payload to the PancakeSwap parser\nlet log: HypersyncLog = serde_json::from_str(uniswap_style_log)?;\nlet event = parse_swap_event_hypersync(dex, &log)?; // bail: data too short\n\n// after: route by topic0 to the correct parser\nconst PANCAKE_V3_SWAP_TOPIC: &str = \"19b47279256b2a23a1665c810c8d55a1758940ee09377d4f8d26497a3577dc83\";\nconst UNISWAP_V3_SWAP_TOPIC: &str = \"c42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67\";\nlet event = if log.topics[0].to_string().contains(PANCAKE_V3_SWAP_TOPIC) {\n    parse_swap_event_hypersync(pancake_dex, &log)?\n} else if log.topics[0].to_string().contains(UNISWAP_V3_SWAP_TOPIC) {\n    parse_uniswap_v3_swap(dex, &log)?\n} else { anyhow::bail!(\"unknown swap topic\"); };","handlingStrategy":"validation","validationCode":"const PANCAKE_V3_SWAP_TOPIC: &str = \"19b47279256b2a23a1665c810c8d55a1758940ee09377d4f8d26497a3577dc83\";\npub fn can_parse_pancake_swap(log: &HypersyncLog) -> bool {\n    let topic_ok = log.topics.first()\n        .and_then(|t| t.as_ref())\n        .map(|t| t.to_string().contains(PANCAKE_V3_SWAP_TOPIC))\n        .unwrap_or(false);\n    let data_ok = log.data.as_ref()\n        .map(|d| d.as_ref().len() >= 7 * 32)\n        .unwrap_or(false);\n    topic_ok && data_ok\n}","typeGuard":"fn is_full_pancake_swap_data(log: &HypersyncLog) -> bool {\n    log.data.as_ref().map(|d| d.as_ref().len() >= 224).unwrap_or(false)\n}","tryCatchPattern":"match parse_swap_event_hypersync(dex, &log) {\n    Ok(event) => store(event),\n    Err(e) if e.to_string().contains(\"too short\") => {\n        tracing::warn!(tx = ?log.transaction_hash, \"short swap data — likely Uniswap V3 log routed to PancakeSwap parser; skipping\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Dispatch log parsing on full topic0 hash, not event name — PancakeSwap V3 and Uniswap V3 Swap topics differ","Check log.data length (>= 224 bytes for PancakeSwap V3 Swap) before parsing","Base test fixtures on real PancakeSwap V3 logs with 7 data words, not Uniswap V3 ones","Watch for HyperSync response truncation on large batch queries"],"tags":["blockchain","abi-decoding","hypersync","data-length","pancakeswap-v3"],"backgroundTag":"payload-too-large","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"}