Skip to content

Price Impact, Fee & Slippage Display #57

@0x-r4bbit

Description

@0x-r4bbit

Below the swap fields, display a summary row showing the calculated fee, price impact, slippage tolerance input, and the resulting min-received / max-sent guarantee.

Calculations

Fee (deducted from input before the swap):

fee_amount = swap_amount_in × fees / 10_000

Price impact (how much the trade moves the pool price):

price_before = reserve_a / reserve_b
price_after  = (reserve_a + amount_in) / (reserve_b − amount_out)
price_impact = (price_after − price_before) / price_before × 100

Min received (exact-input mode, applying user slippage tolerance s in %):

min_received = amount_out × (1 − s / 100)

Max sent (exact-output mode):

max_sent = amount_in × (1 + s / 100)

Requirements

  • Slippage tolerance input defaulting to 0.5%, with preset buttons for 0.1%, 0.5%, 1.0%
  • Fee shown in input token units (e.g. 0.30 USDC)
  • Price impact shown as a percentage; highlight amber when > 1%, red when > 5%
  • Min received / max sent updates in real time as amounts or slippage changes

Acceptance criteria

  • Fee amount is correct for both swap directions
  • Price impact matches the constant-product formula
  • Slippage presets and custom input both update min received / max sent
  • Color thresholds apply correctly (neutral / amber / red)
  • All values update on amount change, direction flip, and slippage change

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions