Use this checklist when changing buy/sell quote math paths.
- Preserve deterministic output for identical inputs before and after state transitions.
- Keep totals bounded: buy quote
total_amount >= price, sell quotetotal_amount <= price. - Preserve fee accounting identity:
- Buy path:
total_amount = price + creator_fee + protocol_fee - Sell path:
total_amount = price - creator_fee - protocol_fee
- Buy path:
- Maintain zero-supply boundary behavior:
- Buy quote at zero supply is valid and deterministic.
- Sell quote without holder balance remains rejected.
- Keep rounding behavior stable (
protocol_feefloor, remainder to creator).
- Add or update regression tests that cross supply edges (
0 -> 1 -> 0). - Include at least one zero-supply boundary case.
- Cover both quote determinism and boundedness assertions.
- Update snapshot tests when expected outputs intentionally change.
- Reuse shared helpers (
normalize_quote_amount, fee helpers) instead of duplicating math. - Keep error mapping stable for callers and indexers.
- Document externally visible quote behavior changes in docs and PR notes.