Skip to content

Security: Implement lending pool price manipulation protection with TWAP oracle #605

Description

@devdianax

Context

Spot price oracles are vulnerable to manipulation via flash loans or low-liquidity pools.

Current Limitation/Problem

Current oracle integration uses spot prices directly. Manipulated spot prices can trigger false liquidations or bad debt.

Expected Outcome

TWAP (Time-Weighted Average Price) oracle integration that smooths price data to resist short-term manipulation.

Acceptance Criteria

  • Implement TWAP calculation: accumulate price * time over configurable window
  • Configurable TWAP window: 30min (volatile assets) to 24h (stable assets)
  • Spot vs TWAP deviation check: reject liquidation if deviation > configurable %
  • Fallback: if TWAP unavailable, use spot price with higher safety margin
  • TWAP update: update accumulator on each oracle price update
  • TWAP accuracy monitoring: historical TWAP vs actual price at liquidation
  • Governance: per-pool TWAP window configuration

Technical Scope

  • contracts/oracle/twap.rs - TWAP oracle implementation
  • Integration with pool liquidation and borrowing
  • TWAP accuracy dashboard
  • Edge cases: TWAP initialization for new pools, low-volume periods, TWAP manipulation resistance analysis

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions