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 (30 files, +1995 -46)
|
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)
|
Feature Flag Registry CheckThis PR introduces feature flag references that are not yet registered in the Unregistered flags
How to fixAdd an entry for each flag in myNewFlag: {
name: 'myNewFlag',
type: FeatureFlagType.Remote,
inProd: false,
productionDefault: false,
status: FeatureFlagStatus.Active,
},Set If you access the flag via a constant (e.g. |
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
Drop KeyringController:withKeyringV2 and SnapAccountService:ensureReady from the delegate list; they are not in MultichainAccountServiceMessenger allowed actions and break lint:tsc in CI. Co-authored-by: Cursor <cursoragent@cursor.com>
Builds ready [7772e1b]
⚡ Performance Benchmarks (Total: 🟢 21 pass · 🟡 0 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Remove SnapController state delegates that are no longer in the package messenger contract and restore withKeyringV2 plus SnapAccountService ensureReady. Co-authored-by: Cursor <cursoragent@cursor.com>
Builds ready [7b9c17e]
⚡ Performance Benchmarks (Total: 🟢 18 pass · 🟡 7 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Disable the slippage row and keep the config modal closed while perpsGetMaxSlippage is in flight so saving cannot overwrite a stored cap with the documented default fallback. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 267b6d6. Configure here.
Builds ready [267b6d6]
⚡ Performance Benchmarks (Total: 🟢 19 pass · 🟡 6 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Use the active leverage when recomputing default size and balancePercent after price or balance updates, and fix order-entry test formatting for CI. Co-authored-by: Cursor <cursoragent@cursor.com>
Builds ready [e56953f]
⚡ Performance Benchmarks (Total: 🟢 16 pass · 🟡 9 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Collapse the recap effect dependency array to one line so Test lint passes the repo-wide format check. Co-authored-by: Cursor <cursoragent@cursor.com>
Builds ready [50af04c]
⚡ Performance Benchmarks (Total: 🟢 19 pass · 🟡 6 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!]
|

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.
Before
N/A — this adds a new flag-gated order-summary control.
After
Additional validation:
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Medium Risk
Changes the market-order submit path (blocking, params, and live book dependency) behind a remote flag; mis-estimation or stream issues could affect when users can trade.
Overview
Adds configurable max slippage for Extension perps market orders, gated by the remote flag
perpsSlippageConfig2.When enabled, the order summary shows estimated vs max slippage (from a live L2 book walk), opens a preset/custom modal (0.1%–10%), and persists the cap via new background APIs
perpsGetMaxSlippage/perpsSetMaxSlippage. Submit stays disabled while the cap or estimate loads, and is blocked with an error (plus analytics) if estimate exceeds max;maxSlippageBpsis sent onperpsPlaceOrderwhen the flag is on.Supporting changes: order-book stream activation now forwards
levels/nSigFigs/mantissa;usePerpsLiveOrderBookmanages the background stream with optionalmanageStream: falsefor shared lifecycle; default new-order amount prefills from controller trading defaults and recaps when price/balance/leverage change.Reviewed by Cursor Bugbot for commit 2e7bd1c. Bugbot is set up for automated code reviews on this repo. Configure here.