fix(perps): block stop loss beyond liquidation boundaries#41922
Open
lexaisnotdead wants to merge 2 commits into
Open
fix(perps): block stop loss beyond liquidation boundaries#41922lexaisnotdead wants to merge 2 commits into
lexaisnotdead wants to merge 2 commits into
Conversation
The Perps TP/SL editor only validated stop loss values against the current price, which allowed values to cross the position liquidation boundary. This change makes stop loss validation liquidation-aware, keeps the UI error specific to the violated boundary, and adds regression coverage for the short-position case reported in MetaMask#41898. Constraint: Keep the fix narrowly scoped to the existing TP/SL validation flow Constraint: Preserve current take-profit behavior and existing form structure Rejected: Backend-only validation | issue report requires immediate UI feedback and disabled submit state Rejected: Broad TP/SL refactor | unnecessary scope increase for a release regression Confidence: high Scope-risk: narrow Reversibility: clean Directive: Keep stop loss validation aligned with both current-price and liquidation-price boundaries when evolving Perps forms Tested: node_modules/.bin/jest ui/components/app/perps/utils/tpslValidation.test.ts ui/components/app/perps/update-tpsl/update-tpsl-modal-content.test.tsx --runInBand Tested: node_modules/.bin/tsx development/lint-changed.mts --fix Not-tested: Full repository lint/test suite Related: MetaMask#41898
The Perps order-entry page still accepted stop loss values beyond the liquidation boundary even though inline validation messaging appeared. The live page owned its own submit-disable logic and only checked stop losses against the current or entry price, so this change makes the page-level validation liquidation-aware and adds regression coverage for that exact flow. Constraint: Keep the fix scoped to the Perps TP/SL validation and submit gating paths Constraint: Do not include unrelated local build or .gitignore changes in this commit Rejected: Rely on OrderEntry internal submit disabling alone | the live page renders its own external submit button Rejected: Backend-only validation | the issue requires immediate UI feedback and blocked submission Confidence: high Scope-risk: narrow Reversibility: clean Directive: Any future TP/SL validation changes must keep the page-level submit-disable logic aligned with the form-level validation helpers Tested: node_modules/.bin/jest ui/pages/perps/perps-order-entry-page.test.tsx ui/components/app/perps/order-entry/components/auto-close-section/auto-close-section.test.tsx ui/components/app/perps/update-tpsl/update-tpsl-modal-content.test.tsx ui/components/app/perps/utils/tpslValidation.test.ts --runInBand Tested: node_modules/.bin/tsx development/lint-changed.mts --fix Not-tested: Full repository lint/test suite Related: MetaMask#41898
Contributor
|
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. |
Author
|
I have read the CLA Document and I hereby sign the CLA |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes issue #41898, where the Perps order entry flow still allowed stop loss values beyond the liquidation boundary.
The original fix only covered the update TP/SL modal for existing positions. This follow-up fixes the actual live submit path used by the Perps order entry page, makes stop-loss validation liquidation-aware in the auto-close section, and disables the real page-level submit button when the stop loss crosses liquidation.
Changelog
CHANGELOG entry: Fixed a bug that allowed Perps stop loss values beyond the liquidation price.
Related issues
Fixes: #41898
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Medium Risk
Changes order-entry and TP/SL editing validation to block stop-loss values that cross liquidation boundaries, which can affect whether users can submit orders. Risk is moderate due to new boundary logic and dependence on liquidation price parsing/availability.
Overview
Stop-loss validation is now liquidation-aware across perps order entry and the update TP/SL modal, preventing SL values that would cross the liquidation boundary.
This introduces
getStopLossValidationResult(replacing directisValidStopLossPriceusage in several UI paths) to distinguish current-price vs liquidation-price validation failures, wiresliquidationPriceintoAutoCloseSectionand the page-level submit-disable logic, and adds a new i18n message (perpsStopLossInvalidLiquidationPrice) plus expanded test coverage for the new boundary and disabled-submit behavior.Reviewed by Cursor Bugbot for commit 29cb42b. Bugbot is set up for automated code reviews on this repo. Configure here.