Skip to content

feat: fair-LP valuation and MIN_OUT slippage on all swap paths#51

Open
sotoJ24 wants to merge 1 commit into
Neko-Protocol:devfrom
sotoJ24:dev
Open

feat: fair-LP valuation and MIN_OUT slippage on all swap paths#51
sotoJ24 wants to merge 1 commit into
Neko-Protocol:devfrom
sotoJ24:dev

Conversation

@sotoJ24

@sotoJ24 sotoJ24 commented Jun 23, 2026

Copy link
Copy Markdown

Summary

Replaces the spot-price LP valuation in adapter-soroswap with a
manipulation-resistant constant-product fair-value formula, and adds
configurable slippage enforcement to every swap and liquidity call.

Closes #49.

Problem

Two vulnerabilities in the previous implementation:

  1. NAV manipulationposition_value priced LP positions using the
    AMM spot price (reserve_a / reserve_b). An attacker could sandwich a
    vault deposit or withdrawal (skew reserves → transact at distorted NAV
    → swap back) to extract value from other depositors.

  2. Zero slippage protection — every swap_exact_tokens_for_tokens,
    add_liquidity, and remove_liquidity call used MIN_OUT = 0,
    meaning the vault accepted any output no matter how bad.

Changes

common/types.rs

  • Added SlippageConfig struct with max_slippage_bps and
    max_price_impact_bps fields (units: basis points, 1 bps = 0.01%)
  • Added SlippageConfig::default() (50 bps slippage, 100 bps price
    impact) and min_out(expected) helper for computing floor amounts

common/storage.rs

  • Added DataKey::SlippageCfg — a second instance-storage key separate
    from DataKey::Storage so the config can be updated without
    reinitialising the adapter
  • load_slippage falls back to SlippageConfig::default() if never set,
    so existing deployed adapters are safe on upgrade

common/error.rs

  • Added PriceImpactTooHigh = 9 — operation rejected before hitting AMM
  • Added SlippageTooHigh = 10 — swap output fell below computed floor
  • All existing error codes preserved

soroswap_pool/mod.rs — core logic change

get_fair_value (replaces spot-price position_value)

Uses the constant-product fair-value formula:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: fair-LP valuation and MIN_OUT slippage on all swap paths

1 participant