Swap
Performs a token swap using the constant-product AMM formula.Accounts
The pair account. PDA derived from
[PAIR_SEED_PREFIX, token0, token1, params_hash].The pair vault for the input token. Must be owned by pair PDA.
The pair vault for the output token. Must be owned by pair PDA.
User’s input token account. Must have sufficient balance.
User’s output token account. Will receive swapped tokens.
The user performing the swap. Must be a signer.
Arguments
Amount of input token to swap. Must be greater than 0.
Minimum amount of output token to receive. Used for slippage protection.
Formula
The swap uses the constant-product formula:Δx= input amount after feesy= output reservex= input reserveΔy= output amount
Fee Structure
Swap fees are split between liquidity providers and the protocol:Fee Distribution
| Recipient | Calculation | Destination |
|---|---|---|
| Futarchy | swap_fee × revenue_share.swap_bps / 10000 | Transferred immediately to authority token account |
| LPs | swap_fee - futarchy_fee | Added to virtual and cash reserves |
Reserve Updates
The LP portion of the fee increases both virtual and cash reserves:- LP fees compound directly into pool liquidity
- Futarchy fees are extracted immediately and do not affect reserves
- The constant product invariant is preserved or increased after each swap