From 85d2c602f3427e122bc06311e7bf01ad66c305be Mon Sep 17 00:00:00 2001 From: 0xfnzero <0xfnzero@users.noreply.github.com> Date: Sun, 3 May 2026 17:30:09 +0800 Subject: [PATCH] fix(calc): return 0 for zero sell amount in slippage helper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit calculate_with_slippage_sell previously fell through to the branch that returned 1 when amount <= basis_points/10_000, which is true for amount=0 and typical bps values—yielding a bogus minimum of 1. Short-circuit on zero input so sell quotes stay correct. Co-authored-by: Cursor --- src/utils/calc/common.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/utils/calc/common.rs b/src/utils/calc/common.rs index e833acc..db7f630 100644 --- a/src/utils/calc/common.rs +++ b/src/utils/calc/common.rs @@ -72,6 +72,9 @@ pub const fn calculate_with_slippage_buy(amount: u64, basis_points: u64) -> u64 /// * basis_points = 500 -> 5% slippage #[inline(always)] pub const fn calculate_with_slippage_sell(amount: u64, basis_points: u64) -> u64 { + if amount == 0 { + return 0; + } if amount <= basis_points / 10000 { 1 } else {