mirror of
https://github.com/logos-blockchain/lez-programs.git
synced 2026-08-25 14:11:09 +00:00
Lift the inverse constant-product SwapExactOutput math out of the guest's exact_output_swap_logic into amm_core::swap_exact_out_amounts(amount_out, reserve_in, reserve_out, fee_bps) -> Option<(effective_in, required_in)>: ceil(reserve_in * amount_out / (reserve_out - amount_out)) lifted through the fee via mul_div_ceil. exact_output_swap_logic now calls it and keeps its nonzero/exceeds-reserve asserts. Behavior-preserving (the panic-message tests still pass); None (out >= reserve or zero fee multiplier) surfaces as the existing expect. Makes the on-chain exact-output pricing one reusable function so the off-chain quote can produce byte-identical required-input figures instead of re-deriving the inverse formula. Mirrors swap_exact_in_amounts.