feat(perps): add configurable slippage controls#43357
Conversation
… config Gate the order-entry slippage UI behind opt-in remote flag perps-slippage-config2, show Est/Max on market orders, persist user max (default 3%), and block submit when estimate exceeds the cap. Co-authored-by: Cursor <cursoragent@cursor.com>
Resolve TypeScript and test failures from the slippage feature pass, surface persistence errors, and align the slippage modal with existing perps modal patterns. Co-authored-by: Cursor <cursoragent@cursor.com>
Use i18n-backed slippage exceed message in the submit-block unit test instead of a brittle regex. Co-authored-by: Cursor <cursoragent@cursor.com>
- usePerpsEstimatedSlippage: propagate `enabled` to usePerpsLiveOrderBook so disabled (e.g. limit orders) no longer activates the background order-book stream. - usePerpsLiveOrderBook: gate stream activation on `enabled`; thread `levels`/`nSigFigs`/`mantissa` through to the bridge; drop the `onError` option that could not cross the background RPC. - perps-stream-bridge: forward `levels`/`nSigFigs`/`mantissa` from perpsActivateOrderBookStream to controller.subscribeToOrderBook. - slippage config modal: validate the full input as a single numeric token before enabling/saving Set, rejecting partial strings like `1abc`/`1.2.3`. - tests: bridge option forwarding + modal validation coverage.
…age config (TAT-1043)
RemoteFeatureFlagController camelCases LaunchDarkly keys, so the stored key is
`perpsSlippageConfig2` (not kebab). Switch the selector to read the camelCase
key and accept the `{ enabled, minimumVersion }` rollout shape via
isPerpsRemoteConfigSatisfied (boolean still supported). Update the order-entry
test fixture to the new flag shape.
Import BASIS_POINTS_DIVISOR from perps-controller, derive max-slippage source from PERPS_EVENT_VALUE, add usePerpsMaxSlippage unit tests, and label the slippage exceed row for screen readers. Co-authored-by: Cursor <cursoragent@cursor.com>
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
✨ Files requiring CODEOWNER review ✨👨🔧 @MetaMask/perps (31 files, +2009 -55)
|
Worker reportTAT-1043 Implementation ReportSummaryExtension perps order entry now shows estimated slippage, lets users configure a persisted max slippage (default 3%), and blocks market-order submit when the live estimate exceeds the cap. Feature is opt-in via remote flag Self-Review Fixes
Self-Review Fixes (round 2)
Self-Review Fixes (round 3)
|
Worker reportTAT-1043 Implementation ReportSummaryExtension perps order entry now shows estimated slippage, lets users configure a persisted max slippage (default 3%), and blocks market-order submit when the live estimate exceeds the cap. Feature is opt-in via remote flag Self-Review Fixes
Self-Review Fixes (round 2)
Self-Review Fixes (round 3)
|
…ps-slippage-config
Builds ready [8261ab0]
⚡ Performance Benchmarks (Total: 🟢 14 pass · 🟡 11 warn · 🔴 0 fail)
Bundle size diffs [🚀 Bundle size reduced!]
|
Recap default order amount when price resolves after mount, and keep the slippage config modal open until async persist succeeds. Co-authored-by: Cursor <cursoragent@cursor.com>
Worker reportPR #43357 Comment Triage Report
Summary
|
…ps-slippage-config
Builds ready [033330b]
⚡ Performance Benchmarks (Total: 🟢 13 pass · 🟡 12 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [2e7bd1c] [reused from 50af04c]
⚡ Performance Benchmarks (Total: 🟢 19 pass · 🟡 6 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
…ps-slippage-config # Conflicts: # jest.integration.config.js # test/mocks/metamask-perps-controller.js # ui/pages/perps/perps-layout.test.tsx # ui/pages/perps/perps-order-entry-page.tsx
farmslot run summary
Worker reportPR #43357 Comment Triage ReportPR: feat(perps): add configurable slippage controls Triage
Summary
This run's primary contributionMerged latest
Validation (post-merge: branch + origin/main)
Finalization
|
Builds ready [93f1ff5]
⚡ Performance Benchmarks (Total: 🟢 18 pass · 🟡 6 warn · 🔴 1 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [eef4891] [reused from 93f1ff5]
⚡ Performance Benchmarks (Total: 🟢 18 pass · 🟡 6 warn · 🔴 1 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Registering perpsSlippageConfig2 (enabled in prod) auto-seeded it into the shared perps e2e fixture, which gates market-order submit on a live order-book slippage estimate the lifecycle WS mock never feeds. submit-order-button stayed disabled, failing perps-position-lifecycle across all e2e shards. Override the flag off in the fixture (matching the confirmations_pay_post_quote pattern); the registry entry stays prod-on and the feature keeps unit + recipe coverage.
Worker reportPR #43357 Comment Triage ReportPR: feat(perps): add configurable slippage controls Triage table
Notes
Detail — Comment #1 (REAL)
Root cause: Fix: add Validation
Summary
|
Builds ready [7720371]
⚡ Performance Benchmarks (Total: 🟢 18 pass · 🟡 7 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Farmslot run summary
Worker reportPR #43357 Comment Triage ReportPR: feat(perps): add configurable slippage controls Summary
Conclusion: Every cursor[bot] finding on this PR was already fixed and its thread resolved by earlier worker runs in the family. No new code fix was required for review feedback. The only outstanding merge-readiness change was a prettier compliance fix in Merge-readiness actions this run
Final totals
Validation
|
geositta
left a comment
There was a problem hiding this comment.
Approve. The branch adds configurable Perps max slippage with controller backed persistence, live order-book estimation, feature-flag gating, and focused unit coverage. The implementation keeps the new behavior scoped to market order entry when the feature flag is enabled, and the controller bridge forwards the new order-book parameters explicitly.
Description
Adds configurable max slippage controls for Extension perps market orders behind the
perpsSlippageConfig2remote flag.This PR:
perpsGetMaxSlippage/perpsSetMaxSlippage;maxSlippageBpswhen placing flag-enabled market orders;Changelog
CHANGELOG entry: Added configurable max slippage controls for perps market orders
Related issues
Fixes: https://consensyssoftware.atlassian.net/browse/TAT-1043
Manual testing steps
perpsSlippageConfig2remote flag.Screenshots/Recordings
Recipe screenshots prove slippage row visibility, max-slippage configuration, persistence, and default 3% cap on the perps order entry screen.
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Medium Risk
Changes market-order submit preconditions and order params (
maxSlippageBps); mistakes could block trading or pass wrong slippage, though behavior is gated by remote flag and covered by tests.Overview
Behind the
perpsSlippageConfig2remote flag, Extension perps market orders get user-configurable max slippage with live estimated slippage from the order book.The order summary gains an editable Est / Max slippage row and a Set slippage modal (presets + custom, 0.1%–10%). Caps are loaded and saved via
perpsGetMaxSlippage/perpsSetMaxSlippage;maxSlippageBpsis sent on place-order when the flag is on. Submit stays disabled while the cap or estimate is loading, and is blocked with messaging when estimate exceeds max (with related analytics).Supporting work: L2 order-book stream options (
levels,nSigFigs,mantissa) through the stream bridge;usePerpsLiveOrderBooknow activates/deactivates the background stream (withmanageStreamfor shared lifecycle);calculateEstimatedSlippageBps+usePerpsEstimatedSlippage(throttled book reads). New orders can prefill default size from controller trading defaults. Generic Perps E2E keeps the flag off so mocks without book estimates do not lock submit.Reviewed by Cursor Bugbot for commit 5981254. Bugbot is set up for automated code reviews on this repo. Configure here.