You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a Swap view in the DEX app that allows users to trade one token for another through an existing AMM pool. Inspired by the https://app.uniswap.org/swap.
The AMM program exposes a Swap instruction that executes a constant-product trade against an active pool:
Required accounts: the AMM pool, vault A, vault B, the user's holding account for Token A, and the user's holding account for Token B (whichever is the input side must be authorized). The output amount is calculated against the pool's reserve_a / reserve_b using the
constant-product formula, minus the pool's fee tier.
UX Flow
Select input token and amount — user picks the token they want to sell and enters an amount; available balance is shown beneath the
field
Select output token — user picks the token they want to receive; the expected output amount is calculated and displayed automatically
Swap direction toggle — an arrow/swap button between the two fields reverses the direction without clearing the selected tokens
Route / pool indicator — shows which pool will be used (token pair + fee tier), and that only direct single-hop swaps are supported for
now
Swap details panel — shown before confirmation, displaying:
Exchange rate (e.g. 1 TOKEN_A = X TOKEN_B)
Fee tier of the pool (e.g. 0.30%)
Price impact (estimated % change against current reserves)
Minimum received — output amount after applying the user's slippage tolerance
Slippage tolerance setting — user-configurable (e.g. 0.1%, 0.5%, 1.0%, or custom); used to compute min_amount_out
Submit — dispatches the Swap instruction; button disabled when input exceeds balance, pool does not exist/is inactive, or amounts are zero
Technical Notes
Output amount is estimated client-side using the constant-product formula, accounting for the pool fee:
amount_in_with_fee = swap_amount_in * (FEE_BPS_DENOMINATOR - fees)
amount_out = (reserve_out * amount_in_with_fee) / (reserve_in * FEE_BPS_DENOMINATOR + amount_in_with_fee)
min_amount_out passed to the instruction is amount_out * (1 - slippage_tolerance)
Create a Swap view in the DEX app that allows users to trade one token for another through an existing AMM pool. Inspired by the
https://app.uniswap.org/swap.
The AMM program exposes a Swap instruction that executes a constant-product trade against an active pool:
Required accounts: the AMM pool, vault A, vault B, the user's holding account for Token A, and the user's holding account for Token B (whichever is the input side must be authorized). The output amount is calculated against the pool's reserve_a / reserve_b using the
constant-product formula, minus the pool's fee tier.
UX Flow
field
now
Technical Notes
amount_in_with_fee = swap_amount_in * (FEE_BPS_DENOMINATOR - fees)
amount_out = (reserve_out * amount_in_with_fee) / (reserve_in * FEE_BPS_DENOMINATOR + amount_in_with_fee)
activeflag in PoolDefinition is redundant afterMINIMUM_LIQUIDITYlock #25), the swap UIshould show a "no liquidity" state
Acceptance Criteria
References