1. Load and fetch the pool
2. Quote (offline)
- Exact in
- Exact out
3. Execute
swap re-fetches the pool state and re-quotes before signing, so the minimum it enforces is based on the state at send time, not the state you displayed.
The ALPH balance check compares against the swap input only. The transaction also needs a few
DUST_AMOUNTs of ALPH for outputs, plus gas. Keep some headroom when the input token is ALPH.4. Handle errors
Moving the price to a target
For arbitrage or rebalancing,swapTo computes the trade that moves the pool to a target price (token1 per token0 in sorted order, human units):
swapTo skips the 5% price-impact guard.