{"record":{"id":"1dc8329aa6ef0cf1","repo":"nautechsystems/nautilus_trader","slug":"liquidity-liquidity-exceeds-i128-max","errorCode":null,"errorMessage":"Liquidity {liquidity} exceeds i128::MAX","messagePattern":"Liquidity (.+?) exceeds i128::MAX","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/defi/pool_analysis/profiler.rs","lineNumber":959,"sourceCode":"\n        Ok(())\n    }\n\n    /// Adds liquidity to a position.\n    ///\n    /// Updates position state, tracks deposited amounts, and manages tick maps.\n    /// Called by both historical event processing and simulated operations.\n    fn add_liquidity(\n        &mut self,\n        owner: &Address,\n        tick_lower: i32,\n        tick_upper: i32,\n        liquidity: u128,\n        amount0: U256,\n        amount1: U256,\n    ) -> anyhow::Result<()> {\n        let liquidity_delta = i128::try_from(liquidity)\n            .map_err(|_| anyhow::anyhow!(\"Liquidity {liquidity} exceeds i128::MAX\"))?;\n        self.update_position(\n            owner,\n            tick_lower,\n            tick_upper,\n            liquidity_delta,\n            amount0,\n            amount1,\n        )?;\n\n        // Track deposited amounts\n        self.analytics.total_amount0_deposited += amount0;\n        self.analytics.total_amount1_deposited += amount1;\n\n        Ok(())\n    }\n\n    /// Executes a simulated mint (liquidity addition) operation.\n    ///","sourceCodeStart":941,"sourceCodeEnd":977,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/defi/pool_analysis/profiler.rs#L941-L977","documentation":"`PoolProfiler::add_liquidity` converts an unsigned on-chain liquidity amount (`u128`) into a signed `i128` delta for position tracking. `i128::try_from(liquidity)` fails when the liquidity exceeds `i128::MAX`, throwing this error. Values near u128::MAX are astronomically large in practice, so this almost always indicates corrupted or misparsed event data.","triggerScenarios":"Calling `add_liquidity` (via `process_mint`/`execute_mint`) with a `liquidity: u128` value greater than `i128::MAX` (≈1.7e38), typically from a misparsed mint event.","commonSituations":"ABI/log decoding bugs where unrelated bytes are read as liquidity; adversarial or fuzzed event data; reusing raw storage slots as liquidity values.","solutions":["Verify your log/ABI decoding reads the correct word for `liquidity` in the mint event.","Reject or clamp mints whose liquidity exceeds realistic maxima (Uniswap V3 caps liquidity well below i128::MAX) at ingestion.","Skip the event with a logged warning instead of failing the whole profiling run.","If you need to represent such magnitudes, widen your accounting type (not feasible with i128 position deltas — instead validate upstream)."],"exampleFix":"// before\nprofiler.add_liquidity(owner, tick_lower, tick_upper, liquidity, amount0, amount1)?;\n// after\nconst MAX_SANE_LIQUIDITY: u128 = 1 << 120;\nif liquidity > MAX_SANE_LIQUIDITY {\n    eprintln!(\"implausible mint liquidity {liquidity}; skipping\");\n    return Ok(());\n}\nprofiler.add_liquidity(owner, tick_lower, tick_upper, liquidity, amount0, amount1)?;","handlingStrategy":"validation","validationCode":"fn liquidity_fits_i128(liquidity: u128) -> bool { liquidity <= i128::MAX as u128 }","typeGuard":null,"tryCatchPattern":"match profiler.add_liquidity(owner, tl, tu, liq, a0, a1) {\n    Ok(()) => {}\n    Err(e) if e.to_string().contains(\"exceeds i128::MAX\") => warn!(\"skipping corrupt mint: {e}\"),\n    Err(e) => return Err(e),\n}","preventionTips":["Bound-check decoded event values against realistic protocol maxima before applying state updates","Double-check ABI type/offset when decoding Mint events","Fail soft per-event in bulk block replay"],"tags":["defi","overflow","liquidity"],"backgroundTag":"value-out-of-range","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"}