{"record":{"id":"3c7047c5860f0de3","repo":"nautechsystems/nautilus_trader","slug":"slippage-slippage-bps-bps-must-be-below-bps-den","errorCode":null,"errorMessage":"Slippage {slippage_bps} bps must be below {BPS_DENOMINATOR}","messagePattern":"Slippage (.+?) bps must be below (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/execution/client.rs","lineNumber":2490,"sourceCode":"fn exact_output_amount(quote: &SwapQuote, zero_for_one: bool) -> anyhow::Result<U256> {\n    let amount = if zero_for_one {\n        quote.amount1\n    } else {\n        quote.amount0\n    };\n\n    if !amount.is_negative() {\n        anyhow::bail!(\"Swap quote output amount {amount} is not a positive output\");\n    }\n    Ok(amount.unsigned_abs())\n}\n\n/// Derives the minimum output accepted for the swap: the quoted output reduced by\n/// `slippage_bps`, in exact integer arithmetic. Rejects a zero minimum, which would leave\n/// the swap without slippage protection.\nfn derive_min_amount_out(quoted_amount_out: U256, slippage_bps: u32) -> anyhow::Result<U256> {\n    if slippage_bps >= BPS_DENOMINATOR {\n        anyhow::bail!(\"Slippage {slippage_bps} bps must be below {BPS_DENOMINATOR}\");\n    }\n    let min_amount_out = quoted_amount_out\n        .checked_mul(U256::from(BPS_DENOMINATOR - slippage_bps))\n        .and_then(|scaled| scaled.checked_div(U256::from(BPS_DENOMINATOR)))\n        .ok_or_else(|| anyhow::anyhow!(\"Minimum output derivation overflow\"))?;\n    if min_amount_out.is_zero() {\n        anyhow::bail!(\n            \"Derived minimum output is zero for quoted output {quoted_amount_out} at {slippage_bps} bps slippage\"\n        );\n    }\n    Ok(min_amount_out)\n}\n\n#[async_trait(?Send)]\nimpl ExecutionClient for BlockchainExecutionClient {\n    fn is_connected(&self) -> bool {\n        self.core.is_connected()\n    }","sourceCodeStart":2472,"sourceCodeEnd":2508,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/2114cf6f761429e0adb5ca9596fcd7b895b16011/crates/adapters/blockchain/src/execution/client.rs#L2472-L2508","documentation":"derive_min_amount_out reduces the quoted output by slippage_bps basis points to compute the minimum accepted output. BPS_DENOMINATOR is 10_000 (100%), so a slippage of 10_000 bps or more would drive the minimum to zero or negative, removing slippage protection entirely; such values are rejected before any math runs.","triggerScenarios":"Passing slippage_bps >= 10_000 to the swap execution path: a value of 10_000 meant as '100% tolerance', a percentage accidentally used as bps (e.g. 50 for 50%), or a fraction scaled wrongly (0.5 passed instead of 50).","commonSituations":"Config files that express slippage in percent while the API expects bps; strategies copying slippage from a different venue's units; defensive 'very high' slippage values like 100000 used in volatile markets.","solutions":["Pass slippage in basis points strictly below 10_000: 0.5% = 50, 1% = 100, 5% = 500","Convert percent configs at the boundary: slippage_bps = (percent * 100) as u32, and assert it is < 10_000","Sanity-check the value in tests/config validation so the mistake surfaces at startup, not mid-swap"],"exampleFix":"// before: percent used as bps / 100% tolerance\nlet slippage_bps = 50;   // user meant 50 percent -> 5000 is still fine, but 10000 is not\nlet slippage_bps = 10000; // Err: must be below 10000\n\n// after: convert percent -> bps and keep it under 100%\nlet percent = 0.5;\nlet slippage_bps = (percent * 100.0) as u32;\nassert!(slippage_bps < 10_000);","handlingStrategy":"validation","validationCode":"const BPS_DENOMINATOR: u32 = 10_000;\nanyhow::ensure!(slippage_bps < BPS_DENOMINATOR, \"slippage {slippage_bps} bps must be < {BPS_DENOMINATOR}\");","typeGuard":"fn valid_slippage_bps(bps: u32) -> bool { bps < 10_000 }","tryCatchPattern":"// Pure input error: correct the value at the call site; retrying with the same bps\n// always fails. Fail fast at config load instead of catching here.","preventionTips":["Convert percent to bps in exactly one place: bps = (percent * 100) as u32","Validate slippage config at startup with a hard assert (< 10_000)","Document the unit (basis points) next to every slippage field"],"tags":["slippage","basis-points","validation","swap","configuration"],"backgroundTag":"slippage-tolerance-out-of-range","analyzedSha":"2114cf6f761429e0adb5ca9596fcd7b895b16011","analyzedAt":"2026-08-21T11:28:30.864Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}