The core input area of the swap card. The user can either enter how much they want to spend (SwapExactInput) or how much they want to receive (SwapExactOutput). The opposite field is always read-only and computed from the pool math.
Swap math
Exact input (selling amount_in of Token A for Token B):
amount_in_with_fee = amount_in × (10_000 − fees)
amount_out = (reserve_b × amount_in_with_fee) / (reserve_a × 10_000 + amount_in_with_fee)
Exact output (buying exact_out of Token B):
amount_in = (reserve_a × exact_out × 10_000) / ((reserve_b − exact_out) × (10_000 − fees)) + 1
Fee constant: fees = 30, FEE_BPS_DENOMINATOR = 10_000
Requirements
- Two amount fields: "You pay" (top) and "You receive" (bottom)
- Clicking into either field sets the mode to exact-input or exact-output respectively
- The non-active field updates in real time as the user types
- Input is validated: cannot exceed user balance; cannot exceed pool reserve on the output side
- Display the input token's user balance; clicking "MAX" fills the input field with the full balance
Acceptance criteria
The core input area of the swap card. The user can either enter how much they want to spend (
SwapExactInput) or how much they want to receive (SwapExactOutput). The opposite field is always read-only and computed from the pool math.Swap math
Exact input (selling
amount_inof Token A for Token B):Exact output (buying
exact_outof Token B):Fee constant:
fees = 30,FEE_BPS_DENOMINATOR = 10_000Requirements
Acceptance criteria