Skip to content

Add "Positions" view for managing liquidity positions #32

@0x-r4bbit

Description

@0x-r4bbit

Create a Positions view that lists all liquidity positions held by the user and allows them to add to or remove from each position.
Inspired by the https://app.uniswap.org/positions.

A user's position in a pool is represented by their LP token balance in their holding account for that pool's liquidity token. The
underlying token amounts they are entitled to can be derived from the pool's current state:

user_share      = user_lp_balance / liquidity_pool_supply
underlying_a    = user_share * reserve_a
underlying_b    = user_share * reserve_b

Removing liquidity dispatches the RemoveLiquidity instruction:

RemoveLiquidity {
    remove_liquidity_amount: u128,       // LP tokens to burn
    min_amount_to_remove_token_a: u128,  // slippage guard
    min_amount_to_remove_token_b: u128,  // slippage guard
}

Adding more liquidity to an existing position routes to the New Position view with the pool pre-selected.

UX Flow

Position list

  1. Scan LP token holdings — enumerate the user's holding accounts; identify those that correspond to a known pool's liquidity_pool_id
  2. Position card — for each position display:
  • Token pair (e.g. TOKEN_A / TOKEN_B)
  • Fee tier (e.g. 0.30%)
  • LP token balance and percentage share of the pool
  • Current underlying token amounts (Token A and Token B)
  • Pool status badge — Active or Inactive
  1. Empty state — when the user holds no LP tokens, show a prompt linking to the New Position view

Position detail / management

Tapping a position card opens a detail view or expands inline with:

  1. Position summary — full breakdown of underlying amounts at current reserves, fee tier, pool address
  2. "Add liquidity" action — navigates to the New Position view with the token pair and fee tier pre-filled
  3. "Remove liquidity" action — opens a removal panel:
  • Slider or percentage buttons (25%, 50%, 75%, 100%) to choose how much LP to burn
  • Preview of Token A and Token B amounts to be returned, after applying slippage tolerance
  • Minimum received fields respect user slippage tolerance setting (same setting as Swap view)
  • Confirm button dispatches RemoveLiquidity with the correct accounts and min_amount_to_remove_* values

Technical Notes

  • LP token holding accounts are identified by matching their token definition ID against known pool liquidity_pool_id values; pool accounts
    can be looked up via compute_pool_pda for each known token pair, or discovered by querying all accounts owned by the AMM program
  • remove_liquidity_amount is the raw LP token quantity to burn; min_amount_to_remove_token_a/b are derived as underlying_amount * (1 -
    slippage_tolerance)
  • After full removal (remove_liquidity_amount == user_lp_balance), the pool becomes inactive (active = false) if it was the last position —
    the UI should warn the user when they are about to drain the pool entirely
  • Pool share percentage and underlying amounts should update in real time if the pool state changes while the view is open

Acceptance Criteria

  • All pools in which the user holds LP tokens are listed
  • Each position card shows token pair, fee tier, LP balance, pool share %, and underlying token amounts
  • Inactive pools are clearly marked
  • "Add liquidity" navigates to the New Position view with the pool pre-selected
  • "Remove liquidity" panel lets the user choose an amount and previews the tokens returned
  • Slippage tolerance is respected and used to compute min_amount_to_remove_*
  • A warning is shown when the user is about to fully drain the pool
  • Submitting removal dispatches the correct RemoveLiquidity instruction with the right accounts
  • Empty state is shown when the user has no positions

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions