Reference

Trading units and rounding

Every Trading quantity is an integer in an atomic unit, and swap rounding always favors existing liquidity providers.

Units

Rounding

Exact input computes net = ⌊gross × (10,000 − fee) / 10,000⌋ and out = ⌊reserveOut × net / (reserveIn + net)⌋. Exact output computes net = ⌈reserveIn × out / (reserveOut − out)⌉ and gross = ⌈net × 10,000 / (10,000 − fee)⌉. These directions favor existing LPs.

Liquidity deposits round reserve use down. Removal rounds each reserve output down. Initial alternative odds round the smaller deposited reserve down. Conditional YES is NO / (YES + NO); Conditional NO is YES / (YES + NO).