Fee-adjusted input
Boundary selection
The engine chooses the nearer value in the swap direction:- next initialized-tick price; or
- user price limit.
Amount relationships
For token0 input, price moves down. Input follows the amount0 delta and output follows the amount1 delta. For token1 input, price moves up and the roles reverse. All price formulas use Q128.128 and full-width division.Fees
The contract calculates gross input consumed, swap fee, protocol share, LP fee growth, output, and remainder with one consistent capped amount. Protocol fee isfee_charged * fee_protocol / 16. The LP share increases global Q128.128 fee growth for the input token.
Stored tick
An upward fill that would stop exactly on an initialized tick is held one Q128.128 unit below that boundary when the tick cannot be crossed. This preserves the half-open liquidity convention.resolve_stored_tick then makes stored tick agree with stored price and crossing state.
Quotes must reproduce these branch and rounding rules. A continuous constant-product formula is not sufficient.