This PR is the base branch for the perps controller update and
decimal-logic work in
[TAT-2699](https://consensyssoftware.atlassian.net/browse/TAT-2699).
It upgrades the extension to `@metamask/perps-controller@3.1.1`, keeps
the decimal/calculation logic changes, and includes the required
extension integration support for that controller update
(`StorageService` wiring, Jest support, and LavaMoat updates). A few
perps UI files still appear here only where the retained hunks are
logic-owned rather than presentation-only.
The UI-facing display/formatting parity changes were split out into
stacked PR
[#41853](#41853).
CHANGELOG entry: null
Fixes:
[TAT-2699](https://consensyssoftware.atlassian.net/browse/TAT-2699)
Related:
- [TAT-2870](https://consensyssoftware.atlassian.net/browse/TAT-2870)
- MetaMask/core#8473
- MetaMask/metamask-mobile#28871
- MetaMask/metamask-mobile#28892
- Stacked UI/display follow-up: #41853
1. Open a perps market such as BTC or ETH in extension.
2. Verify order-entry calculations use the updated decimal logic for
size, margin, liquidation, and fees.
3. Verify the perps controller initializes correctly and the relevant
perps screens still load.
4. Run the extension perps validation recipe:
`temp/agentic/recipes/teams/perps/recipes/pr-41558-decimal-formatting.json`.
N/A for this split PR. UI-facing screenshot evidence lives in stacked PR
N/A for this split PR. UI-facing screenshot evidence lives in stacked PR
- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
[TAT-2699]:
https://consensyssoftware.atlassian.net/browse/TAT-2699?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[TAT-2699]:
https://consensyssoftware.atlassian.net/browse/TAT-2699?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[TAT-2870]:
https://consensyssoftware.atlassian.net/browse/TAT-2870?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Medium risk because it upgrades a core dependency and changes perps
infrastructure wiring (formatting, Sentry breadcrumbs, and persistent
cache via StorageService), which can affect order-entry calculations and
cached market data behavior.
>
> **Overview**
> Upgrades `@metamask/perps-controller` to `3.1.1` and updates perps
infrastructure to use the package-provided
`formatPerpsFiat`/`formatPercentage` and expose
`PRICE_RANGES_UNIVERSAL`, aligning formatting behavior with the
controller.
>
> Adds a `diskCache` implementation to `createPerpsInfrastructure`
backed by `StorageService` (with an in-memory read-through cache) and
wires the required `StorageService:getItem/setItem/removeItem` actions
through the perps messenger/init path.
>
> Extends tracing to forward `addBreadcrumb` calls to Sentry, adds
`perpsCalculateLiquidationPrice` to the background API wiring/tests, and
updates LavaMoat policies to allow `Intl.NumberFormat` for the perps
controller.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
428562d. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: MetaMask Bot <metamaskbot@users.noreply.github.com>
Description
This PR is the base branch for the perps controller update and
decimal-logic work in
TAT-2699.
It upgrades the extension to
@metamask/perps-controller@3.1.1, keepsthe decimal/calculation logic changes, and includes the required
extension integration support for that controller update
(
StorageServicewiring, Jest support, and LavaMoat updates). A fewperps UI files still appear here only where the retained hunks are
logic-owned rather than presentation-only.
The UI-facing display/formatting parity changes were split out into
stacked PR
#41853.
Changelog
CHANGELOG entry: null
Related issues
Fixes:
TAT-2699
Related:
Manual testing steps
size, margin, liquidation, and fees.
perps screens still load.
temp/agentic/recipes/teams/perps/recipes/pr-41558-decimal-formatting.json.Screenshots/Recordings
Before
N/A for this split PR. UI-facing screenshot evidence lives in stacked PR
#41853.
After
N/A for this split PR. UI-facing screenshot evidence lives in stacked PR
#41853.
Pre-merge author checklist
Docs and MetaMask
Extension Coding
Standards.
if applicable
guidelines).
Not required for external contributors.
Pre-merge reviewer checklist
app, test code being changed).
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
Note
Medium Risk
Medium risk because it upgrades a core dependency and changes perps
infrastructure wiring (formatting, Sentry breadcrumbs, and persistent
cache via StorageService), which can affect order-entry calculations and
cached market data behavior.
Overview
Upgrades
@metamask/perps-controllerto3.1.1and updates perpsinfrastructure to use the package-provided
formatPerpsFiat/formatPercentageand exposePRICE_RANGES_UNIVERSAL, aligning formatting behavior with thecontroller.
Adds a
diskCacheimplementation tocreatePerpsInfrastructurebacked by
StorageService(with an in-memory read-through cache) andwires the required
StorageService:getItem/setItem/removeItemactionsthrough the perps messenger/init path.
Extends tracing to forward
addBreadcrumbcalls to Sentry, addsperpsCalculateLiquidationPriceto the background API wiring/tests, andupdates LavaMoat policies to allow
Intl.NumberFormatfor the perpscontroller.
Reviewed by Cursor Bugbot for commit
428562d. Bugbot is set up for automated
code reviews on this repo. Configure
here.
Co-authored-by: MetaMask Bot metamaskbot@users.noreply.github.com 97ee416