Skip to main content

Module utils

Module utils 

Source
Expand description

Generic numeric helpers shared by the quote builders. Pure functions โ€” no domain types, no I/O.

Functionsยง

add_slippage
value * (10_000 + bps) / 10_000. Saturates on the rare case the multiplication itself overflows u64.
slippage_bounds
(value - delta, value + delta) where delta = value * bps / 10_000. Returns None if any intermediate overflows u128 โ€” callers can map that to crate::math::QuoteError::MathOverflow. Mirrors handle_bps from mayhem-program::math so both validate_market_cap paths can share a slippage envelope.
sub_slippage
value * (10_000 - bps) / 10_000. bps larger than 10_000 saturates to 0.