Problem
The TWAP ring buffer exists in liquidity.rs, but settlement/resolution can still read a spot price that a single large swap moved. This enables last-block price manipulation of payouts.
Requirements
- Add a settlement helper that requires the spot vs. TWAP deviation to be within a configurable max-deviation (bps); revert
PriceDeviationTooHigh otherwise.
- Return
TwapInsufficientHistory (already modeled) when the window isn't covered, instead of silently using a short window.
- Config value stored/validated in
config.rs.
Acceptance Criteria
- Manipulated spot price beyond the deviation band is rejected at settlement; normal price passes. Covered by tests.
Files
contracts/open-market/src/liquidity.rs
contracts/open-market/src/market.rs
contracts/open-market/src/config.rs
contracts/open-market/tests/twap_validation_tests.rs
Problem
The TWAP ring buffer exists in
liquidity.rs, but settlement/resolution can still read a spot price that a single large swap moved. This enables last-block price manipulation of payouts.Requirements
PriceDeviationTooHighotherwise.TwapInsufficientHistory(already modeled) when the window isn't covered, instead of silently using a short window.config.rs.Acceptance Criteria
Files
contracts/open-market/src/liquidity.rscontracts/open-market/src/market.rscontracts/open-market/src/config.rscontracts/open-market/tests/twap_validation_tests.rs