{"record":{"id":"c0bfbc2bf6c2d2e6","repo":"nautechsystems/nautilus_trader","slug":"impact-cannot-exceed-100-10000-bps","errorCode":null,"errorMessage":"Impact cannot exceed 100% (10000 bps)","messagePattern":"Impact cannot exceed 100% \\(10000 bps\\)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/model/src/defi/pool_analysis/size_estimator.rs","lineNumber":214,"sourceCode":"        .as_ref()\n        .ok_or_else(|| anyhow::anyhow!(\"Trade info not initialized\"))?;\n\n    trade_info.get_slippage_bps()\n}\n\nfn binary_search_for_size(\n    profiler: &PoolProfiler,\n    impact_bps: u32,\n    zero_for_one: bool,\n    config: &EstimationConfig,\n) -> anyhow::Result<BinarySearchState> {\n    // Validate inputs\n    if impact_bps == 0 {\n        anyhow::bail!(\"Impact must be greater than zero\");\n    }\n\n    if impact_bps > 10000 {\n        anyhow::bail!(\"Impact cannot exceed 100% (10000 bps)\");\n    }\n    profiler.check_if_initialized(PoolEventKind::Swap)?;\n\n    // Estimate initial bounds\n    let mut low = U256::ZERO;\n    let mut high = estimate_max_size_for_impact(profiler, impact_bps, zero_for_one);\n    let initial_high = high;\n\n    let mut iterations = 0;\n    let mut expansions = 0;\n    let mut converged = false;\n    let mut final_slippage_bps = None;\n\n    // Binary search with optional adaptive expansion\n    while iterations < config.max_iterations {\n        iterations += 1;\n\n        // Calculate midpoint","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/defi/pool_analysis/size_estimator.rs#L196-L232","documentation":"`binary_search_for_size` caps the requested price impact at 10000 basis points (100%). An impact above 100% is rejected because it is unrepresentable for the search (impact cannot exceed the full range in this model), so the library fails fast with this message.","triggerScenarios":"Calling `size_for_impact_bps` or `size_for_impact_bps_detailed` with `impact_bps > 10000`, which forwards to `binary_search_for_size` and hits the `if impact_bps > 10000` guard.","commonSituations":"Unit confusion between percent and basis points (e.g. passing 150 meaning 150% or 1.5x); unbounded user input; multiplying impact by a leverage factor without clamping; mixing decimal impact (1.5) with bps-scale APIs.","solutions":["Clamp or validate `impact_bps` to at most 10000 before calling the estimator.","Convert user-facing percentages correctly: percent * 100 = bps, and reject >100% at input.","Normalize the impact scale at the config boundary so all callers pass bps.","Return a graceful 'impact too large' signal to users instead of letting the API error propagate."],"exampleFix":"// before\nlet impact_bps = 150; // meant 150%\nlet size = size_for_impact_bps(&profiler, impact_bps, true, &config)?;\n// after\nlet impact_bps = 15000.min(10_000); // cap at 100% (10000 bps)\nlet size = size_for_impact_bps(&profiler, impact_bps, true, &config)?;","handlingStrategy":"validation","validationCode":"fn valid_impact(impact_bps: u32) -> bool {\n    (1..=10000).contains(&impact_bps)\n}\nlet impact_bps = impact_bps.min(10_000);","typeGuard":null,"tryCatchPattern":"let size = match size_for_impact_bps(&profiler, impact_bps, zero_for_one, &config) {\n    Ok(s) => s,\n    Err(e) if e.to_string().contains(\"cannot exceed 100%\") => {\n        // clamp to 10000 bps and retry, or surface a user-facing input error\n    },\n    Err(e) => return Err(e),\n};","preventionTips":["Convert user percentages to bps in one place: percent * 100.","Clamp impact inputs to 10000 bps at every ingestion point.","Watch for percent-vs-bps confusion producing values like 150 or 15000.","Validate estimator config fields on load."],"tags":["defi","validation","size-estimation","arguments"],"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-14T05:17:10.506Z"}