Skip to content

Commit 2560458

Browse files
authored
feat(perps): update to perps-controller 22.3.0 and use its shared calculations instead of Extension copies (#47777)
## **Description** Extension computed its own Perps close and TP/SL figures, so the same position showed different numbers than Mobile and Terminal. This bumps `@metamask/perps-controller` to `^22.3.0` and uses Core's shared calculations instead: - **Close and close-all** use `estimateCloseReceive`. Cross margin keeps its PnL (it used to be subtracted), PnL is priced at the live or limit close price, cents round half away from zero (1.005 → 1.01), and close-all shows a signed receive instead of clamping at 0. Amounts keep their cents ($2,114.49, not $2,114.5). A partial close is quoted at the size it submits, rounded to the market's size step. While the fee rate is unquoted, fee and receive show `--` and Close (and Close all) stays disabled, so no fee is reported as 0. - **Activity, recent activity and transaction details** use `calculateNetClosedPnl`. A fill with an unknown fee keeps its net PnL unknown, including when split fills are aggregated. Details show the same amount as the activity row (cents rounded half up, thousands grouped), zero included, and do not subtract the fee again. - **TP/SL** (order entry auto close, edit TP/SL) uses Core's RoE ↔ trigger price, validation, `validateTPSLPrices` and `formatRoePercent`. A stop loss is capped at 99% loss per 1x, trigger prices keep Core's precision after the field loses focus, and an unknown leverage shows no RoE instead of assuming 1x. - Extension has no local account-summary derivation, so `calculateAccountSummary` (TAT-4480) has nothing to replace. Add/remove margin and new-order calculations are unchanged, per the ticket. The dependency bump hoists `@metamask/abi-utils` for the controller, so the LavaMoat policies change only that edge. The Jest stub now re-exports Core's real calculation modules, so the tests check Core's figures. ## **Changelog** CHANGELOG entry: Fixed Perps close amounts, closed PnL and TP/SL prices so they match the MetaMask mobile app ## **Related issues** Fixes: https://consensyssoftware.atlassian.net/browse/TAT-4534 ## **Manual testing steps** 1. Build and run the extension, open Perps on Hyperliquid testnet with a funded account. 2. Open a small long (for example $11 SOL at 1x), open its market page and press Close long. 3. Check that Fees and You'll receive show `--` until the fee loads, Close is disabled until then, and Margin − Fees = You'll receive to the cent. 4. On Perps home, press Close all, check that the rows add up the same way, then press Keep positions. 5. Close the position. Check that the market's Recent activity row, Perps home Recent activity and the transaction details show the same P&L. 6. Open a new order, turn on Auto close and type -5000 in the stop loss %. Check that a stop loss price appears (about 1% of the price at 1x) instead of staying empty. ## **Screenshots/Recordings** <p><strong>AC-2: Close review rows</strong><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-runs/b200f20b-b942-45c3-88c0-7e09e1b91925/screenshots/ac2-close-modal.png?sha=ace5f664d374f0bc" alt="Close review rows" width="320" /></p> <p><strong>AC-3: Market activity net PnL</strong><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-runs/b200f20b-b942-45c3-88c0-7e09e1b91925/screenshots/ac3-market-activity.png?sha=d2e8f5bd7b198ade" alt="Market activity net PnL" width="320" /></p> <p><strong>AC-1: Stop loss at -5000% RoE gets Core's capped price</strong><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-runs/b200f20b-b942-45c3-88c0-7e09e1b91925/screenshots/ac1-stop-loss-cap.png?sha=2e1faaf1599dd713" alt="Stop loss at -5000% RoE gets Core's capped price" width="320" /></p> <details> <summary>Full evidence gallery and publication receipt</summary> <table> <tr><td colspan="2"><strong>Close review rows</strong></td></tr> <tr> <td align="center" valign="top" width="50%"><em>Before</em><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-baseline-run/screenshots/ac2-close-modal.png?sha=7f5afe7afa804c13" alt="before" width="320" /></td> <td align="center" valign="top" width="50%"><em>After</em><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-runs/b200f20b-b942-45c3-88c0-7e09e1b91925/screenshots/ac2-close-modal.png?sha=ace5f664d374f0bc" alt="after" width="320" /></td> </tr> <tr><td colspan="2"><strong>Close all rows</strong></td></tr> <tr> <td align="center" valign="top" width="50%"><em>Before</em><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-baseline-run/screenshots/ac2-close-all.png?sha=6eb8f5ac11763c2f" alt="before" width="320" /></td> <td align="center" valign="top" width="50%"><em>After</em><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-runs/b200f20b-b942-45c3-88c0-7e09e1b91925/screenshots/ac2-close-all.png?sha=09f75aa75f17c8c0" alt="after" width="320" /></td> </tr> <tr><td colspan="2"><strong>Market activity net PnL</strong></td></tr> <tr> <td align="center" valign="top" width="50%"><em>Before</em><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-baseline-run/screenshots/ac3-market-activity.png?sha=4bb5e2152a916df3" alt="before" width="320" /></td> <td align="center" valign="top" width="50%"><em>After</em><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-runs/b200f20b-b942-45c3-88c0-7e09e1b91925/screenshots/ac3-market-activity.png?sha=d2e8f5bd7b198ade" alt="after" width="320" /></td> </tr> <tr><td colspan="2"><strong>Recent activity net PnL</strong></td></tr> <tr> <td align="center" valign="top" width="50%"><em>Before</em><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-baseline-run/screenshots/ac3-recent-activity.png?sha=82a31fa34c180728" alt="before" width="320" /></td> <td align="center" valign="top" width="50%"><em>After</em><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-runs/b200f20b-b942-45c3-88c0-7e09e1b91925/screenshots/ac3-recent-activity.png?sha=3993a84a339ca611" alt="after" width="320" /></td> </tr> <tr><td colspan="2"><strong>Transaction details net PnL</strong></td></tr> <tr> <td align="center" valign="top" width="50%"><em>Before</em><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-baseline-run/screenshots/ac3-transaction-details.png?sha=953969347de201c1" alt="before" width="320" /></td> <td align="center" valign="top" width="50%"><em>After</em><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-runs/b200f20b-b942-45c3-88c0-7e09e1b91925/screenshots/ac3-transaction-details.png?sha=b108137ada845b95" alt="after" width="320" /></td> </tr> </table> <table> <tr><td align="center" valign="top" width="50%"><strong>Stop loss at -5000% RoE gets Core's capped price</strong><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-runs/b200f20b-b942-45c3-88c0-7e09e1b91925/screenshots/ac1-stop-loss-cap.png?sha=2e1faaf1599dd713" alt="Stop loss at -5000% RoE gets Core's capped price" width="320" /></td><td align="center" valign="top" width="50%"><strong>Cross close review: margin includes PnL, fee, receive</strong><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-runs/b200f20b-b942-45c3-88c0-7e09e1b91925/screenshots/x-cross-close.png?sha=a75e4c6db82db031" alt="Cross close review: margin includes PnL, fee, receive" width="320" /><br/><sub>caption confidence: LOW — generic filename — no state-specific suffix</sub></td></tr> <tr><td align="center" valign="top" width="50%"><strong>Partial (50%) close review at the submitted size</strong><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-runs/b200f20b-b942-45c3-88c0-7e09e1b91925/screenshots/x-partial-close.png?sha=691ff6f413b05ceb" alt="Partial (50%) close review at the submitted size" width="320" /><br/><sub>caption confidence: LOW — generic filename — no state-specific suffix</sub></td><td align="center" valign="top" width="50%"><strong>Limit close review priced at the limit</strong><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-runs/b200f20b-b942-45c3-88c0-7e09e1b91925/screenshots/x-limit-close.png?sha=1515fd4f338a877a" alt="Limit close review priced at the limit" width="320" /><br/><sub>caption confidence: LOW — generic filename — no state-specific suffix</sub></td></tr> <tr><td align="center" valign="top" width="50%"><strong>The Perps tutorial is not covering the page</strong><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-runs/b200f20b-b942-45c3-88c0-7e09e1b91925/stills/138319b0d5f3165fb9cece1f7c608f226e509a89799aabedbb62178601a596f8-1.webp?sha=d84ae20432d12ba8" alt="The Perps tutorial is not covering the page" width="320" /><br/><sub>Unassigned capture.</sub></td><td align="center" valign="top" width="50%"><strong>The close review shows a signed amount you will receive</strong><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-runs/b200f20b-b942-45c3-88c0-7e09e1b91925/stills/ada4ebf3dffdc7365ef598e439775a74d603b7528a8d96ef667c058cc2e3ad42-1.webp?sha=98b1510f6bc126b1" alt="The close review shows a signed amount you will receive" width="320" /><br/><sub>Unassigned capture.</sub></td></tr> <tr><td align="center" valign="top" width="50%"><strong>The close review shows the quoted fee</strong><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-runs/b200f20b-b942-45c3-88c0-7e09e1b91925/stills/d02b3d2b5d82994b273c9071b7ae4186eb5a5a6903ee19002ddebd23ac39c98b-1.webp?sha=c9a87dfa78b1e93c" alt="The close review shows the quoted fee" width="320" /><br/><sub>Unassigned capture.</sub></td><td align="center" valign="top" width="50%"><strong>The close review is dismissed</strong><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-runs/b200f20b-b942-45c3-88c0-7e09e1b91925/stills/92b652681daa5b12cc07c8deeb64b241ebd0344e6f7d195b77356a2cdb88d65e-1.webp?sha=0a523fca264791fa" alt="The close review is dismissed" width="320" /><br/><sub>Unassigned capture.</sub></td></tr> <tr><td align="center" valign="top" width="50%"><strong>Close all shows a signed total you will receive</strong><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-runs/b200f20b-b942-45c3-88c0-7e09e1b91925/stills/88bc3e13315797142cefce262e5de425a014457bce1bced59a28b8f8ce959767-1.webp?sha=0ff057b7c15c86d6" alt="Close all shows a signed total you will receive" width="320" /><br/><sub>Unassigned capture.</sub></td><td align="center" valign="top" width="50%"><strong>Close all shows the total margin with PnL</strong><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-runs/b200f20b-b942-45c3-88c0-7e09e1b91925/stills/61acbe4555eb14c23a22479354499119901a1dc6eae47100e061bae9a7722f23-1.webp?sha=6d059110fa11ca63" alt="Close all shows the total margin with PnL" width="320" /><br/><sub>Unassigned capture.</sub></td></tr> <tr><td align="center" valign="top" width="50%"><strong>Close all is dismissed and nothing was closed</strong><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-runs/b200f20b-b942-45c3-88c0-7e09e1b91925/stills/6943e82498f1d88a9d79ca87abd95c7f53d507b80859e6fca53890f1e8940804-1.webp?sha=4ddacffaf34f560f" alt="Close all is dismissed and nothing was closed" width="320" /><br/><sub>Unassigned capture.</sub></td><td align="center" valign="top" width="50%"><strong>Close is enabled once the fee is quoted</strong><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-runs/b200f20b-b942-45c3-88c0-7e09e1b91925/stills/5f61f0ddb69ed0bebc5f7277f8173270b998c8a823e4568e5fe450c4076b2208-1.webp?sha=2b4031fa8ed11dfb" alt="Close is enabled once the fee is quoted" width="320" /><br/><sub>Unassigned capture.</sub></td></tr> <tr><td align="center" valign="top" width="50%"><strong>The owned close shows in the market activity</strong><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-runs/b200f20b-b942-45c3-88c0-7e09e1b91925/stills/6f9a7ae53bd426ce409307270aaf729795f06ada88889f434a21ad7c96a03511-1.webp?sha=805b386a202e0d45" alt="The owned close shows in the market activity" width="320" /><br/><sub>Unassigned capture.</sub></td><td align="center" valign="top" width="50%"><strong>The owned close row is visible before the market activity capture</strong><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-runs/b200f20b-b942-45c3-88c0-7e09e1b91925/stills/2d495bb653ae7e5177bb50f8396fc4f0dcb00990a362dda8c2299e049d0808eb-1.webp?sha=8fb727ad00244a7c" alt="The owned close row is visible before the market activity capture" width="320" /><br/><sub>Unassigned capture.</sub></td></tr> <tr><td align="center" valign="top" width="50%"><strong>The owned close appears in recent activity</strong><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-runs/b200f20b-b942-45c3-88c0-7e09e1b91925/stills/70c9bfd4e2ef59abd39fb46fbd85fd2c6343f916c9d6e03f58cea082e4b14761-1.webp?sha=a7317d5f53ab1577" alt="The owned close appears in recent activity" width="320" /><br/><sub>Unassigned capture.</sub></td><td align="center" valign="top" width="50%"><strong>The owned close row is visible before the recent activity capture</strong><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-runs/b200f20b-b942-45c3-88c0-7e09e1b91925/stills/41094fe340b3e0e1ac3953023a87f1c2bc1444f5eed148412d6e8d75ec90ba28-1.webp?sha=b975440f235535ab" alt="The owned close row is visible before the recent activity capture" width="320" /><br/><sub>Unassigned capture.</sub></td></tr> <tr><td align="center" valign="top" width="50%"><strong>The owned close transaction details are showing</strong><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-runs/b200f20b-b942-45c3-88c0-7e09e1b91925/stills/ee3cdd8dbcdd847a6dcdefce12c6bde9d12721be880b16d778184e69e93b10cd-1.webp?sha=d46e1bf9db6130b1" alt="The owned close transaction details are showing" width="320" /><br/><sub>Unassigned capture.</sub></td><td align="center" valign="top" width="50%"><strong>The Perps tutorial is not covering the page</strong><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-runs/b200f20b-b942-45c3-88c0-7e09e1b91925/stills/03e0edd4a324a623208db42d5a6d0a99922ea0a55d1f5a9694bac43257e75213-1.webp?sha=343db5749a2e0ee1" alt="The Perps tutorial is not covering the page" width="320" /><br/><sub>Unassigned capture.</sub></td></tr> <tr><td align="center" valign="top" width="50%"><strong>The order entry page is showing</strong><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-runs/b200f20b-b942-45c3-88c0-7e09e1b91925/stills/60040af0dc75fec695c4e3f43e8e7416f57f9f59b3bd870bdd3b5fe56a97dc50-1.webp?sha=841cbf841abad8b4" alt="The order entry page is showing" width="320" /><br/><sub>Unassigned capture.</sub></td><td align="center" valign="top" width="50%"><strong>The stop-loss RoE field is showing</strong><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-runs/b200f20b-b942-45c3-88c0-7e09e1b91925/stills/1d2ec56993dc31ff7e3fbb7bfa90b5953b7332e10ccdbb488b08c92cc460aa4b-1.webp?sha=d6be390bb5963760" alt="The stop-loss RoE field is showing" width="320" /><br/><sub>Unassigned capture.</sub></td></tr> <tr><td align="center" valign="top" width="50%"><strong>The stop-loss price is visible before the capture</strong><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-runs/b200f20b-b942-45c3-88c0-7e09e1b91925/stills/fb8e12f1fd12593c3c641b5f33950078a968d170b3eea9f86bdae3cfd210a854-1.webp?sha=3b98d353ba90f95a" alt="The stop-loss price is visible before the capture" width="320" /><br/><sub>Unassigned capture.</sub></td><td align="center" valign="top" width="50%"><strong>The cross close review shows what you will receive</strong><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-runs/b200f20b-b942-45c3-88c0-7e09e1b91925/stills/122a172c67d0ea88dc7bf8f0cfc0b400fc4ad133058fd59b37d5e10f9cec6a7b-1.webp?sha=66f17567d6cfabc2" alt="The cross close review shows what you will receive" width="320" /><br/><sub>Unassigned capture.</sub></td></tr> <tr><td align="center" valign="top" width="50%"><strong>The cross close review shows the quoted fee</strong><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-runs/b200f20b-b942-45c3-88c0-7e09e1b91925/stills/b9b812f6c467f054066661f35532ff625fe64011ed03e0cbfd219334f00594d9-1.webp?sha=72f787c2ea2e4861" alt="The cross close review shows the quoted fee" width="320" /><br/><sub>Unassigned capture.</sub></td><td align="center" valign="top" width="50%"><strong>The slider reflects a 50% close</strong><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-runs/b200f20b-b942-45c3-88c0-7e09e1b91925/stills/b64f08fcc5c0350142d023f831fc022827296400f197860dafe29d2c5d183caf-1.webp?sha=7073505b79174a75" alt="The slider reflects a 50% close" width="320" /><br/><sub>Unassigned capture.</sub></td></tr> <tr><td align="center" valign="top" width="50%"><strong>Close is enabled once the partial fee is quoted</strong><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-runs/b200f20b-b942-45c3-88c0-7e09e1b91925/stills/25334af47f4a928e16837b7822e3229c1312cbc4f87fb83bb4243410e5ae0339-1.webp?sha=95ba2856d69d49e6" alt="Close is enabled once the partial fee is quoted" width="320" /><br/><sub>Unassigned capture.</sub></td><td align="center" valign="top" width="50%"><strong>The limit close review shows the quoted fee</strong><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-runs/b200f20b-b942-45c3-88c0-7e09e1b91925/stills/b97a3ac5c26f10d0b6a1dd8fd6aa5ef739d9fb53b69f4c6351d10cfecc93188f-1.webp?sha=ee8c4c5cf5169a7c" alt="The limit close review shows the quoted fee" width="320" /><br/><sub>Unassigned capture.</sub></td></tr> <tr><td align="center" valign="top" width="50%"><strong>Close is enabled once the limit fee is quoted</strong><br/><img src="https://raw.githubusercontent.com/abretonc7s/mm-extension-farm-artifacts/main/features/47777-evidence/62234107-80cd-42b6-a83f-ce007854adf8/recipe-runs/b200f20b-b942-45c3-88c0-7e09e1b91925/stills/980ae446e789011c356f7194cd0aaf3867372aa8d2751470a6b8c5c09001d124-1.webp?sha=18cf13c7b222f1bb" alt="Close is enabled once the limit fee is quoted" width="320" /><br/><sub>Unassigned capture.</sub></td><td></td></tr> </table> <!-- farmslot-publication-receipt:start --> ### Publication approval Arthur · person · arthur · 2026-11-10T01:04:17.445Z Package: `c100f61b428837415bcd830fa6e8dc5ef9c2f9873476c5f2ef02e50a02729253`. Visual receipts: none. ### Evidence policy attestation Approved by Arthur (arthur) at 2026-11-10T01:04:17.444Z. Package: `c100f61b428837415bcd830fa6e8dc5ef9c2f9873476c5f2ef02e50a02729253`. Decision: `73294e2c-77db-4981-8fea-5db6ee865705`. Reason: ```text Recipe run 3e1bf21c, 123/123. AC-1: depends on perps-controller 22.3; capped stop-loss trigger from Core. AC-2: close review isolated margin $11.22 - fee $0.02 = receive $11.20; close-all $11.21 - $0.02 = $11.19; cross $25.04 - $0.04 = $25; reconciliation assertions pass for close, close-all, cross, partial and limit. AC-3: Recent activity shows the close at -$0.02 and details show P&L -$0.02 with fees $0.02 listed separately. ``` Waived claim-policy findings: - Recorded claim verdicts do not satisfy publication policy. Original evidence and verdicts are retained. Integrity, source, CI and review checks remain required. <!-- farmslot-publication-receipt:end --> </details> ## **Validation Recipe** <details><summary>recipe.json (116 nodes — Perps close figures and TP/SL from Core 22.3.0 on Extension)</summary> ```json { "$schema": "https://farmslot.io/schemas/recipe-v1.schema.json", "title": "Perps close figures and TP/SL from Core 22.3.0 on Extension", "description": "On Hyperliquid testnet, open one smallest owned position, show the close and close-all reviews with Core's margin-with-PnL, fee and signed receive, close it, show the same net closed PnL in market activity, recent activity and transaction details, then show Core's capped stop-loss price in the order entry. Other runs' positions on the shared account are only read.", "proofTargets": [ { "id": "AC-1", "claim": "Extension depends on `@metamask/perps-controller` 22.3.0; no local copy of a calculation Core exports remains in scope.", "proofMode": "mixed" }, { "id": "AC-2", "claim": "Close modal and close-all show Core's receive, margin-with-PnL and fee for Hyperliquid isolated and cross, gain and loss, partial and limit close, with discounts; values match Core's reference rows to the cent; signed receive shown.", "proofMode": "mixed" }, { "id": "AC-3", "claim": "Activity, recent activity and transaction details agree on net closed PnL from Core for split fills, zero, rebates and unknown fees.", "proofMode": "mixed" }, { "id": "AC-4", "claim": "Recipe proof in the browser for each user-visible change (testnet, smallest size), unit tests fail before and pass after, perps-review-pr passes.", "proofMode": "review" }, { "id": "AC-5", "claim": "Research with exact file paths and callers: client migration inventory drafted for Core #11378 (Extension section).", "proofMode": "review" } ], "paramsSchema": { "type": "object", "additionalProperties": false, "properties": { "market": { "type": "string", "default": "SOL", "description": "Market this run owns on the shared testnet account; must start flat." }, "amount": { "type": "string", "default": "11", "description": "Smallest USD order amount above the venue minimum." }, "leverage": { "type": "integer", "default": 1, "description": "Order leverage." }, "stop_loss_roe": { "type": "string", "default": "-5000", "description": "Stop-loss RoE beyond Core's 99% per 1x cap at any market leverage." }, "network": { "type": "string", "enum": [ "testnet" ], "default": "testnet", "description": "Perps network; this proof trades, so testnet only." }, "provider": { "type": "string", "enum": [ "hyperliquid" ], "default": "hyperliquid", "description": "Provider holding the owned position." }, "side": { "type": "string", "enum": [ "long", "short" ], "default": "long", "description": "Side of the owned position." }, "cross_amount": { "type": "string", "default": "24", "description": "USD size of the owned cross position: half of it still clears the venue minimum." } } }, "workflow": { "entry": "setup-unlock", "nodes": { "setup-unlock": { "action": "metamask.wallet.ensure_unlocked", "intent": "Start from the unlocked slot wallet", "next": "setup-perps" }, "setup-perps": { "action": "ui.navigate", "page": "perps", "intent": "Start from Perps home", "next": "setup-tutorial-clear" }, "setup-tutorial-clear": { "action": "ui.wait_for", "test_id": "perps-tutorial-skip-button", "expected": "absent", "timeout_ms": 5000, "intent": "The Perps tutorial is not covering the page", "next": "setup-testnet" }, "setup-testnet": { "action": "metamask.perps.start_state", "network": "{{params.network}}", "page": false, "positions": false, "orders": false, "intent": "Select Hyperliquid testnet and verify it before trading", "next": "setup-flat-positions" }, "setup-flat-positions": { "action": "metamask.perps.assert_positions", "market": "{{params.market}}", "state": "none", "intent": "The owned market starts without a position on either side", "next": "setup-flat-orders" }, "setup-flat-orders": { "action": "metamask.perps.assert_orders", "market": "{{params.market}}", "state": "none", "intent": "The owned market starts without open orders", "next": "setup-run-start" }, "setup-open": { "action": "metamask.perps.place_order", "market": "{{params.market}}", "side": "{{params.side}}", "amount": "{{params.amount}}", "leverage": "{{params.leverage}}", "order_type": "market", "provider": "{{params.provider}}", "network": "{{params.network}}", "confirm_live": true, "intent": "Open one smallest owned long on testnet", "next": "setup-position-open" }, "setup-position-open": { "action": "metamask.perps.assert_positions", "market": "{{params.market}}", "side": "{{params.side}}", "state": "open", "intent": "The owned long is open", "next": "ac2-open-market" }, "ac2-open-market": { "action": "ui.navigate", "page": "perps-market", "market": "{{params.market}}", "intent": "Show the owned position on its market page", "next": "ac2-venue-position" }, "ac2-open-close-modal": { "action": "ui.press", "test_id": "perps-close-cta-button", "intent": "Review closing the owned position", "next": "ac2-close-modal-receive" }, "ac2-close-modal-receive": { "action": "ui.wait_for", "test_id": "perps-close-summary-receive-value", "expected": "visible", "timeout_ms": 15000, "intent": "The close review shows a signed amount you will receive", "next": "ac2-close-modal-fees", "proves": [ "AC-2" ] }, "ac2-close-modal-fees": { "action": "ui.wait_for", "test_id": "perps-close-summary-fees-value", "expected": "visible", "timeout_ms": 15000, "intent": "The close review shows the quoted fee", "next": "ac2-close-modal-figures", "proves": [ "AC-2" ] }, "ac2-close-modal-capture": { "action": "ui.screenshot", "label": "Close review: margin with PnL, fee, receive", "intent": "Keep the close review rows for visual review", "next": "ac2-close-reconciles" }, "ac2-close-modal-dismiss": { "action": "ui.key_press", "key": "Escape", "intent": "Leave the close review without closing", "next": "ac2-close-modal-gone" }, "ac2-close-modal-gone": { "action": "ui.wait_for", "test_id": "perps-close-position-modal", "expected": "absent", "timeout_ms": 5000, "intent": "The close review is dismissed", "next": "ac2-close-all-home" }, "ac2-close-all-home": { "action": "ui.navigate", "page": "perps", "intent": "Show every open position on Perps home", "next": "ac2-close-all-open" }, "ac2-close-all-open": { "action": "ui.press", "test_id": "perps-close-all-positions", "intent": "Review closing all positions without confirming", "next": "ac2-close-all-receive" }, "ac2-close-all-receive": { "action": "ui.wait_for", "test_id": "perps-close-all-receive-value", "expected": "visible", "timeout_ms": 15000, "intent": "Close all shows a signed total you will receive", "next": "ac2-close-all-margin" }, "ac2-close-all-margin": { "action": "ui.wait_for", "test_id": "perps-close-all-total-margin-value", "expected": "visible", "timeout_ms": 5000, "intent": "Close all shows the total margin with PnL", "next": "ac2-close-all-figures", "proves": [ "AC-2" ] }, "ac2-close-all-capture": { "action": "ui.screenshot", "label": "Close all review: margin with PnL, fees, receive", "intent": "Keep the close-all review rows for visual review", "next": "ac2-close-all-reconciles" }, "ac2-close-all-keep": { "action": "ui.press", "test_id": "perps-close-all-positions-modal-cancel", "intent": "Keep every position open", "next": "ac2-close-all-gone" }, "ac2-close-all-gone": { "action": "ui.wait_for", "test_id": "perps-close-all-positions-modal", "expected": "absent", "timeout_ms": 5000, "intent": "Close all is dismissed and nothing was closed", "next": "ac2-reopen-market" }, "ac2-reopen-market": { "action": "ui.navigate", "page": "perps-market", "market": "{{params.market}}", "intent": "Return to the owned position", "next": "ac2-close-review" }, "ac2-venue-position": { "action": "metamask.perps.read_snapshot", "include": [ "positions" ], "market": "{{params.market}}", "intent": "Read the venue margin and PnL of the owned position before reviewing its close", "next": "ac2-open-close-modal" }, "ac2-close-reconciles": { "action": "assert_output", "source": "ac2-close-modal-figures", "stream": "stdout", "contains": "RECONCILED=true", "intent": "Margin with PnL minus fee equals what you receive, to the cent", "next": "ac2-close-modal-dismiss", "proves": [ "AC-2" ] }, "ac3-market-activity": { "action": "ui.navigate", "page": "perps-market", "market": "{{params.market}}", "intent": "Show the market's trade activity after the close", "next": "ac3-owned-close" }, "ac3-amount": { "action": "command", "intent": "Take the owned close's net PnL as shown in market activity", "next": "ac3-market-capture" }, "ac3-market-capture": { "action": "ui.screenshot", "label": "Market activity: owned close net PnL", "intent": "Keep the market activity row for visual review", "next": "ac3-recent-home" }, "ac3-recent-home": { "action": "ui.navigate", "page": "perps", "intent": "Show recent activity on Perps home", "next": "ac3-recent-row" }, "ac3-recent-row": { "action": "ui.wait_for", "selector": "[data-testid^=\"transaction-card-{{outputs.ac3-owned-close.stdout}}-\"]", "expected": "present", "timeout_ms": 30000, "intent": "The owned close appears in recent activity", "next": "ac3-recent-scroll" }, "ac3-recent-scroll": { "action": "ui.scroll", "selector": "[data-testid^=\"transaction-card-{{outputs.ac3-owned-close.stdout}}-\"]", "scroll_into_view": true, "intent": "The owned close row is on screen in recent activity", "next": "ac3-recent-visible" }, "ac3-recent-capture": { "action": "ui.screenshot", "label": "Recent activity: owned close net PnL", "intent": "Keep the recent activity row for visual review", "next": "ac3-recent-matches" }, "ac3-open-details": { "action": "ui.press", "selector": "[data-testid^=\"transaction-card-{{outputs.ac3-owned-close.stdout}}-\"]", "intent": "Open the owned close's transaction details", "next": "ac3-details-pnl" }, "ac3-details-pnl": { "action": "ui.wait_for", "selector": "[data-testid=\"perps-transaction-details-page\"]", "expected": "visible", "timeout_ms": 15000, "intent": "The owned close transaction details are showing", "next": "ac3-details-figures", "proves": [ "AC-3" ] }, "ac3-details-capture": { "action": "ui.screenshot", "label": "Transaction details: owned close net PnL", "intent": "Keep the transaction details for visual review", "next": "ac3-details-matches" }, "ac1-order-entry": { "action": "call", "ref": "perps.open-order-entry", "params": { "market": "{{params.market}}", "side": "{{params.side}}" }, "intent": "Open a new long order entry on the now flat market", "next": "ac1-auto-close-on" }, "ac1-auto-close-on": { "action": "ui.press", "selector": "label:has([data-testid=\"auto-close-toggle\"])", "intent": "Turn auto close on", "next": "ac1-sl-percent-ready" }, "ac1-sl-percent-ready": { "action": "ui.wait_for", "selector": "[data-testid=\"sl-percent-input\"] input", "expected": "visible", "timeout_ms": 5000, "intent": "The stop-loss RoE field is showing", "next": "ac1-sl-roe" }, "ac1-sl-roe": { "action": "ui.set_input", "selector": "[data-testid=\"sl-percent-input\"] input", "value": "{{params.stop_loss_roe}}", "intent": "Ask for a stop loss beyond the largest loss the venue allows", "next": "ac1-read-sl" }, "ac1-read-sl": { "action": "metamask.perps.read_visible_state", "surface": "order-entry", "market": "{{params.market}}", "auto_close": true, "max_items": 150, "intent": "Read the stop-loss price the form derived from the RoE", "next": "ac1-sl-scroll" }, "ac1-sl-capture": { "action": "ui.screenshot", "label": "Order entry: capped stop-loss price", "intent": "Keep the derived stop-loss price for visual review", "next": "ac1-auto-close-off" }, "ac1-auto-close-off": { "action": "call", "ref": "perps.disable-auto-close", "params": { "market": "{{params.market}}" }, "intent": "Leave the order entry without auto close prices in its draft", "next": "ac1-sl-roe-cap" }, "ac1-sl-roe-cap": { "action": "assert_output", "source": "ac1-read-sl", "assert": { "path": "$.orderEntry.stopLossPrice", "operator": "matches", "value": "^\\$?([1-9][0-9,]*(\\.[0-9]+)?|0\\.[0-9]*[1-9][0-9]*)$" }, "intent": "A stop loss beyond the cap gets Core's capped trigger price instead of none", "next": "ac2-cross-margin-includes-pnl", "proves": [ "AC-1" ] }, "ac2-cross-margin-includes-pnl": { "action": "assert_output", "source": "ac2-close-modal-figures", "stream": "stdout", "contains": "MARGIN_INCLUDES_PNL=true", "intent": "The close review margin matches the venue margin with its PnL for this margin mode", "next": "ac1-core-version-read", "proves": [ "AC-2" ] }, "ac1-core-version-read": { "action": "command", "cmd": "node -p \"require('@metamask/perps-controller/package.json').version\"", "intent": "Read the perps-controller version the build resolves", "next": "ac1-core-version" }, "ac1-core-version": { "action": "assert_output", "source": "ac1-core-version-read", "stream": "stdout", "match": "^22\\.3\\.", "intent": "The build depends on perps-controller 22.3", "next": "x-open", "proves": [ "AC-1" ] }, "done": { "action": "end", "status": "pass" }, "teardown-dismiss": { "action": "ui.key_press", "key": "Escape", "intent": "Dismiss any open review before cleanup", "next": "teardown-owned" }, "teardown-read": { "action": "metamask.perps.read_positions", "market": "{{params.market}}", "network": "{{params.network}}", "intent": "Inspect the owned market even after a failure", "next": "teardown-choose" }, "teardown-choose": { "action": "switch", "value": "positions:{{outputs.teardown-read.matchingCount}}", "equals": "positions:0", "cases": { "match": "teardown-flat" }, "default": "teardown-market", "intent": "Close only when the owned position is still open" }, "teardown-market": { "action": "ui.navigate", "page": "perps-market", "market": "{{params.market}}", "intent": "Show the owned position for cleanup", "next": "teardown-review" }, "teardown-flat": { "action": "metamask.perps.assert_positions", "market": "{{params.market}}", "state": "none", "intent": "The owned market ends flat", "next": "teardown-done", "timeout_ms": 45000 }, "teardown-done": { "action": "end", "status": "pass" }, "ac2-close-modal-figures": { "action": "command", "intent": "Read the close review rows once the fee quote has loaded", "next": "ac2-close-modal-capture" }, "ac2-close-all-figures": { "action": "command", "intent": "Read the close-all rows once every fee quote has loaded", "next": "ac2-close-all-capture" }, "ac2-close-all-reconciles": { "action": "assert_output", "source": "ac2-close-all-figures", "stream": "stdout", "contains": "RECONCILED=true", "intent": "Close all margin with PnL minus fees equals what you receive, to the cent", "next": "ac2-close-all-keep", "proves": [ "AC-2" ] }, "ac3-recent-figures": { "action": "command", "intent": "Read the owned close row in recent activity", "next": "ac3-recent-capture" }, "ac3-recent-matches": { "action": "assert_output", "source": "ac3-recent-figures", "stream": "stdout", "contains": "RECENT_MATCHES=true", "intent": "Recent activity shows the same net PnL as market activity", "next": "ac3-open-details", "proves": [ "AC-3" ] }, "ac3-details-figures": { "action": "command", "intent": "Read the net PnL the transaction details show", "next": "ac3-details-capture" }, "ac3-details-matches": { "action": "assert_output", "source": "ac3-details-figures", "stream": "stdout", "contains": "DETAILS_MATCHES=true", "intent": "Transaction details show the same net PnL as the activity rows", "next": "ac1-order-entry", "proves": [ "AC-3" ] }, "ac1-sl-scroll": { "action": "ui.scroll", "selector": "[data-testid=\"sl-price-input\"]", "scroll_into_view": true, "intent": "The stop-loss price and RoE fields are on screen for review", "next": "ac1-sl-visible" }, "setup-run-start": { "action": "command", "cmd": "node -e \"process.stdout.write(String(Date.now()))\"", "intent": "Stamp the run start so only this run's close counts as owned", "next": "setup-open" }, "ac2-close-review": { "action": "ui.press", "test_id": "perps-close-cta-button", "intent": "Review closing the owned position", "next": "ac2-close-ready" }, "ac2-close-ready": { "action": "ui.wait_for", "selector": "[data-testid=\"perps-close-position-modal-submit\"]:not([disabled])", "expected": "visible", "timeout_ms": 15000, "intent": "Close is enabled once the fee is quoted", "next": "ac2-close-submit" }, "ac2-close-submit": { "action": "ui.press", "test_id": "perps-close-position-modal-submit", "intent": "Close the owned position at market", "next": "ac2-closed" }, "ac2-closed": { "action": "metamask.perps.assert_positions", "market": "{{params.market}}", "state": "none", "timeout_ms": 45000, "intent": "The owned market is flat after the close", "next": "ac3-market-activity" }, "ac3-owned-close": { "action": "command", "intent": "Find this run's close at the top of the market activity", "next": "ac3-close-row" }, "ac3-close-row": { "action": "ui.wait_for", "selector": "[data-testid^=\"transaction-card-{{outputs.ac3-owned-close.stdout}}-\"]", "expected": "present", "timeout_ms": 10000, "intent": "The owned close shows in the market activity", "next": "ac3-close-row-scroll" }, "teardown-review": { "action": "ui.press", "test_id": "perps-close-cta-button", "intent": "Review closing the position this run opened", "next": "teardown-ready" }, "teardown-ready": { "action": "ui.wait_for", "selector": "[data-testid=\"perps-close-position-modal-submit\"]:not([disabled])", "expected": "visible", "timeout_ms": 15000, "intent": "Close is enabled once the fee is quoted", "next": "teardown-submit" }, "teardown-submit": { "action": "ui.press", "test_id": "perps-close-position-modal-submit", "intent": "Close only the position this run opened", "next": "teardown-flat" }, "teardown-owned": { "action": "switch", "value": "opened:{{outputs.setup-open.action}}", "equals": "opened:metamask.perps.place_order", "cases": { "match": "teardown-read" }, "default": "teardown-done", "intent": "Clean up only when this run placed its own order" }, "ac3-close-row-scroll": { "action": "ui.scroll", "selector": "[data-testid^=\"transaction-card-{{outputs.ac3-owned-close.stdout}}-\"]", "scroll_into_view": true, "intent": "The owned close row is on screen for review", "next": "ac3-close-row-visible" }, "ac3-close-row-visible": { "action": "ui.wait_for", "selector": "[data-testid^=\"transaction-card-{{outputs.ac3-owned-close.stdout}}-\"]", "visible": true, "timeout_ms": 5000, "intent": "The owned close row is visible before the market activity capture", "next": "ac3-amount", "proves": [ "AC-3" ] }, "ac3-recent-visible": { "action": "ui.wait_for", "selector": "[data-testid^=\"transaction-card-{{outputs.ac3-owned-close.stdout}}-\"]", "visible": true, "timeout_ms": 5000, "intent": "The owned close row is visible before the recent activity capture", "next": "ac3-recent-figures" }, "ac1-sl-visible": { "action": "ui.wait_for", "selector": "[data-testid=\"sl-price-input\"]", "visible": true, "timeout_ms": 5000, "intent": "The stop-loss price is visible before the capture", "next": "ac1-sl-capture" }, "x-open": { "action": "command", "intent": "Open one smallest owned cross long on testnet (the order form has no margin-mode control)", "next": "x-opened" }, "x-opened": { "action": "assert_output", "source": "x-open", "stream": "stdout", "contains": "OPENED=true", "intent": "The owned cross long was placed", "next": "x-position-open" }, "x-position-open": { "action": "metamask.perps.assert_positions", "market": "{{params.market}}", "side": "long", "state": "open", "timeout_ms": 30000, "intent": "The owned cross long is open", "next": "x-market" }, "x-market": { "action": "ui.navigate", "page": "perps-market", "market": "{{params.market}}", "intent": "Show the owned cross position on its market page", "next": "x-venue" }, "x-venue": { "action": "metamask.perps.read_snapshot", "include": [ "positions" ], "market": "{{params.market}}", "intent": "Read the venue margin, PnL and margin mode of the owned position", "next": "x-is-cross" }, "x-is-cross": { "action": "assert_output", "source": "x-venue", "assert": { "path": "$.sections.positions.items.0.leverage.type", "operator": "matches", "value": "^cross$" }, "intent": "The owned position is on cross margin", "proves": [ "AC-2" ], "next": "x-review" }, "x-review": { "action": "ui.press", "test_id": "perps-close-cta-button", "intent": "Review closing the cross position", "next": "x-receive" }, "x-receive": { "action": "ui.wait_for", "test_id": "perps-close-summary-receive-value", "expected": "visible", "timeout_ms": 15000, "intent": "The cross close review shows what you will receive", "proves": [ "AC-2" ], "next": "x-fees" }, "x-fees": { "action": "ui.wait_for", "test_id": "perps-close-summary-fees-value", "expected": "visible", "timeout_ms": 15000, "intent": "The cross close review shows the quoted fee", "next": "x-figures" }, "x-figures": { "action": "command", "intent": "Read the cross close review rows once the fee quote has loaded", "next": "x-capture" }, "x-capture": { "action": "ui.screenshot", "label": "Cross close review: margin with PnL, fee, receive", "intent": "Keep the cross close review for visual review", "next": "x-reconciles" }, "x-reconciles": { "action": "assert_output", "source": "x-figures", "stream": "stdout", "contains": "RECONCILED=true", "intent": "Cross: margin with PnL minus fee equals what you receive, to the cent", "proves": [ "AC-2" ], "next": "x-margin-pnl" }, "x-margin-pnl": { "action": "assert_output", "source": "x-figures", "stream": "stdout", "contains": "MARGIN_INCLUDES_PNL=true", "intent": "Cross: the margin row adds the PnL to the venue margin", "proves": [ "AC-2" ], "next": "p-percent-mode" }, "p-percent-mode": { "action": "ui.press", "test_id": "close-amount-mode-percent", "intent": "Enter the close amount as a percentage", "next": "p-percent" }, "p-percent": { "action": "ui.set_input", "selector": "[data-testid=\"close-amount-percent\"] input", "value": "50", "intent": "Close half of the cross position", "next": "p-percent-ready" }, "p-percent-ready": { "action": "ui.wait_for", "test_id": "close-amount-slider-pct-50", "expected": "present", "timeout_ms": 5000, "intent": "The slider reflects a 50% close", "next": "p-fraction" }, "p-figures": { "action": "command", "intent": "Read the partial close review rows", "next": "p-capture" }, "p-capture": { "action": "ui.screenshot", "label": "Partial close review (50%): margin with PnL, fee, receive", "intent": "Keep the partial close review for visual review", "next": "p-reconciles" }, "p-reconciles": { "action": "assert_output", "source": "p-figures", "stream": "stdout", "contains": "RECONCILED=true", "intent": "Partial: margin with PnL minus fee equals what you receive, to the cent", "proves": [ "AC-2" ], "next": "p-margin-half" }, "p-margin-half": { "action": "assert_output", "source": "p-figures", "stream": "stdout", "contains": "MARGIN_INCLUDES_PNL=true", "intent": "Partial: the margin row is the submitted share of the venue margin with PnL", "proves": [ "AC-2" ], "next": "p-ready" }, "p-ready": { "action": "ui.wait_for", "selector": "[data-testid=\"perps-close-position-modal-submit\"]:not([disabled])", "expected": "visible", "timeout_ms": 15000, "intent": "Close is enabled once the partial fee is quoted", "next": "p-submit" }, "p-submit": { "action": "ui.press", "test_id": "perps-close-position-modal-submit", "intent": "Close half of the cross position at market", "next": "p-half" }, "p-half": { "action": "command", "intent": "Wait for the venue to report the size the partial close leaves open", "next": "p-half-left" }, "p-half-left": { "action": "assert_output", "source": "p-half", "stream": "stdout", "contains": "SIZE_MATCHES=true", "intent": "The partial close submitted the size the review quoted", "proves": [ "AC-2" ], "next": "l-venue" }, "l-venue": { "action": "metamask.perps.read_snapshot", "include": [ "positions" ], "market": "{{params.market}}", "intent": "Read the remaining cross position before its limit close", "next": "l-review" }, "l-review": { "action": "ui.press", "test_id": "perps-close-cta-button", "intent": "Review closing the remaining position", "next": "l-type" }, "l-type": { "action": "ui.press", "test_id": "order-type-limit", "intent": "Close with a limit order", "next": "l-price-calc" }, "l-price-calc": { "action": "command", "intent": "Pick a sell limit 1% under the live price so the close fills", "next": "l-price" }, "l-price": { "action": "ui.set_input", "selector": "[data-testid=\"limit-price-input\"] input", "value": "{{outputs.l-price-calc.stdout}}", "intent": "Enter the limit close price", "next": "l-pnl" }, "l-pnl": { "action": "command", "intent": "PnL of the remaining long closed at the limit price", "next": "l-fees" }, "l-fees": { "action": "ui.wait_for", "test_id": "perps-close-summary-fees-value", "expected": "visible", "timeout_ms": 15000, "intent": "The limit close review shows the quoted fee", "next": "l-figures" }, "l-figures": { "action": "command", "intent": "Read the limit close review rows, priced at the limit", "next": "l-capture" }, "l-capture": { "action": "ui.screenshot", "label": "Limit close review: margin with PnL at the limit price, fee, receive", "intent": "Keep the limit close review for visual review", "next": "l-reconciles" }, "l-reconciles": { "action": "assert_output", "source": "l-figures", "stream": "stdout", "contains": "RECONCILED=true", "intent": "Limit: margin with PnL minus fee equals what you receive, to the cent", "proves": [ "AC-2" ], "next": "l-margin-pnl" }, "l-margin-pnl": { "action": "assert_output", "source": "l-figures", "stream": "stdout", "contains": "MARGIN_INCLUDES_PNL=true", "intent": "Limit: the margin row adds the PnL priced at the limit", "proves": [ "AC-2" ], "next": "l-ready" }, "l-ready": { "action": "ui.wait_for", "selector": "[data-testid=\"perps-close-position-modal-submit\"]:not([disabled])", "expected": "visible", "timeout_ms": 15000, "intent": "Close is enabled once the limit fee is quoted", "next": "l-submit" }, "l-submit": { "action": "ui.press", "test_id": "perps-close-position-modal-submit", "intent": "Place the limit close", "next": "l-flat" }, "l-flat": { "action": "metamask.perps.assert_positions", "market": "{{params.market}}", "state": "none", "timeout_ms": 45000, "intent": "The limit close filled and the owned market is flat", "next": "done" }, "p-fraction": { "action": "command", "intent": "Share of the position a 50% close submits after size-step rounding", "next": "p-remaining" }, "p-remaining": { "action": "command", "intent": "Size left open after the 50% close", "next": "p-figures" } }, "teardown": "teardown-dismiss" } } ``` </details> ## **Validation Logs** Run: 3e1bf21c-67f9-45cf-8853-4f5c47d848ac Runner: @metamask/recipe-runner Runner revision: unknown Recipe digest: sha256:1ce3b0e371fd75d7b04b22799d206c91a9262c905a68a22cab0074fae25cacf5 <details><summary>Full output (123/123 passed, pass)</summary> ``` # MetaMask Recipe Run Status: pass Duration: 79s Nodes: 123/123 passed ## Side findings - REVIEW 1 distinct application warning/error event(s) (non-blocking; expanded below and stored in diagnostics.json) ## Steps - PASS setup-unlock (metamask.wallet.ensure_unlocked, 220ms): proof=extension-unlocked-state - PASS setup-perps (ui.navigate, 1.5s): page=perps, proof=ui-navigation - PASS setup-tutorial-clear (ui.wait_for, 637ms): matched=true, cdpPort=7666, targetUrl=chrome-extension://hebhblbkkdabgoldnojllkipeoacjioc/home.html#/perps-home, cdpTargetId=7E986C920B11ED065CD19466D8D8B705, runtimeSessionId=5764c980-fa7b-46b5-8f62-513d9fb05053 - PASS setup-testnet (metamask.perps.start_state, 247ms): action=metamask.perps.start_state, phase=start_state - PASS setup-flat-positions (metamask.perps.assert_positions, 224ms): matching=0 - PASS setup-flat-orders (metamask.perps.assert_orders, 220ms): matching=0 - PASS setup-run-start (command, 62ms): exitCode=0, stdout=1794248260694 - PASS setup-open (metamask.perps.place_order, 9.9s): matching=1 - PASS setup-position-open (metamask.perps.assert_positions, 234ms): matching=1 - PASS ac2-open-market (ui.navigate, 1.2s): page=perps-market, proof=ui-navigation - PASS ac2-venue-position (metamask.perps.read_snapshot, 237ms): proof=background-perps-snapshot - PASS ac2-open-close-modal (ui.press, 962ms): clicked=true, selector=[data-testid="perps-close-cta-button"], [data-test-id="perps-close-cta-button"], [data-test="perps-close-cta-button"], tagName=BUTTON, cdpPort=7666, targetUrl=chrome-extension://hebhblbkkdabgoldnojllkipeoacjioc/home.html#/perps/market/SOL - PASS ac2-close-modal-receive (ui.wait_for, 585ms): matched=true, cdpPort=7666, targetUrl=chrome-extension://hebhblbkkdabgoldnojllkipeoacjioc/home.html#/perps/market/SOL, cdpTargetId=7E986C920B11ED065CD19466D8D8B705, runtimeSessionId=5764c980-fa7b-46b5-8f62-513d9fb05053 - PASS ac2-close-modal-fees (ui.wait_for, 608ms): matched=true, cdpPort=7666, targetUrl=chrome-extension://hebhblbkkdabgoldnojllkipeoacjioc/home.html#/perps/market/SOL, cdpTargetId=7E986C920B11ED065CD19466D8D8B705, runtimeSessionId=5764c980-fa7b-46b5-8f62-513d9fb05053 - PASS ac2-close-modal-figures (command, 82ms): exitCode=0, stdout={"margin":"$11.22","fees":"$0.02","receive":"$11.20","expectedMargin":11.218504,"marginDeltaCents":0,"leverageType":"isolated"} RECONCILED=true MARGIN_INCLUDES_PNL=true - PASS ac2-close-reconciles (assert_output, 49ms): source=ac2-close-modal-figures, stream=stdout, contains=RECONCILED=true - PASS ac2-close-modal-dismiss (ui.key_press, 508ms): key=Escape, cdpPort=7666, targetUrl=chrome-extension://hebhblbkkdabgoldnojllkipeoacjioc/home.html#/perps/market/SOL, cdpTargetId=7E986C920B11ED065CD19466D8D8B705, runtimeSessionId=5764c980-fa7b-46b5-8f62-513d9fb05053 - PASS ac2-close-modal-gone (ui.wait_for, 810ms): matched=true, cdpPort=7666, targetUrl=chrome-extension://hebhblbkkdabgoldnojllkipeoacjioc/home.html#/perps/market/SOL, cdpTargetId=7E986C920B11ED065CD19466D8D8B705, runtimeSessionId=5764c980-fa7b-46b5-8f62-513d9fb05053 - PASS ac2-close-all-home (ui.navigate, 1.5s): page=perps, proof=ui-navigation - PASS ac2-close-all-open (ui.press, 876ms): clicked=true, selector=[data-testid="perps-close-all-positions"], [data-test-id="perps-close-all-positions"], [data-test="perps-close-all-positions"], tagName=BUTTON, cdpPort=7666, targetUrl=chrome-extension://hebhblbkkdabgoldnojllkipeoacjioc/home.html#/perps-home - PASS ac2-close-all-receive (ui.wait_for, 594ms): matched=true, cdpPort=7666, targetUrl=chrome-extension://hebhblbkkdabgoldnojllkipeoacjioc/home.html#/perps-home, cdpTargetId=7E986C920B11ED065CD19466D8D8B705, runtimeSessionId=5764c980-fa7b-46b5-8f62-513d9fb05053 - PASS ac2-close-all-margin (ui.wait_for, 579ms): matched=true, cdpPort=7666, targetUrl=chrome-extension://hebhblbkkdabgoldnojllkipeoacjioc/home.html#/perps-home, cdpTargetId=7E986C920B11ED065CD19466D8D8B705, runtimeSessionId=5764c980-fa7b-46b5-8f62-513d9fb05053 - PASS ac2-close-all-figures (command, 375ms): exitCode=0, stdout={"margin":"$11.21","fees":"-$0.02","receive":"$11.19"} RECONCILED=true - PASS ac2-close-all-reconciles (assert_output, 50ms): source=ac2-close-all-figures, stream=stdout, contains=RECONCILED=true - PASS ac2-close-all-keep (ui.press, 991ms): clicked=true, selector=[data-testid="perps-close-all-positions-modal-cancel"], [data-test-id="perps-close-all-positions-modal-cancel"], [data-test="perps-close-all-positions-modal-cancel"], tagName=BUTTON, cdpPort=7666, targetUrl=chrome-extension://hebhblbkkdabgoldnojllkipeoacjioc/home.html#/perps-home - PASS ac2-close-all-gone (ui.wait_for, 588ms): matched=true, cdpPort=7666, targetUrl=chrome-extension://hebhblbkkdabgoldnojllkipeoacjioc/home.html#/perps-home, cdpTargetId=7E986C920B11ED065CD19466D8D8B705, runtimeSessionId=5764c980-fa7b-46b5-8f62-513d9fb05053 - PASS ac2-reopen-market (ui.navigate, 1.2s): page=perps-market, proof=ui-navigation - PASS ac2-close-review (ui.press, 714ms): clicked=true, selector=[data-testid="perps-close-cta-button"], [data-test-id="perps-close-cta-button"], [data-test="perps-close-cta-button"], tagName=BUTTON, cdpPort=7666, targetUrl=chrome-extension://hebhblbkkdabgoldnojllkipeoacjioc/home.html#/perps/market/SOL - PASS ac2-close-ready (ui.wait_for, 635ms): matched=true, cdpPort=7666, targetUrl=chrome-extension://hebhblbkkdabgoldnojllkipeoacjioc/home.html#/perps/market/SOL, cdpTargetId=7E986C920B11ED065CD19466D8D8B705, runtimeSessionId=5764c980-fa7b-46b5-8f62-513d9fb05053 - PASS ac2-close-submit (ui.press, 757ms): clicked=true, selector=[data-testid="perps-close-position-modal-submit"], [data-test-id="perps-close-position-modal-submit"], [data-test="perps-close-position-modal-submit"], tagName=BUTTON, cdpPort=7666, targetUrl=chrome-extension://hebhblbkkdabgoldnojllkipeoacjioc/home.html#/perps/market/SOL - PASS ac2-closed (metamask.perps.assert_positions, 757ms): matching=0 - PASS ac3-market-activity (ui.navigate, 1.6s): page=perps-market, proof=ui-navigation - PASS ac3-owned-close (command, 92ms): exitCode=0, stdout=64933273724 - PASS ac3-close-row (ui.wait_for, 593ms): matched=true, cdpPort=7666, targetUrl=chrome-extension://hebhblbkkdabgoldnojllkipeoacjioc/home.html#/perps/market/SOL, cdpTargetId=7E986C920B11ED065CD19466D8D8B705, runtimeSessionId=5764c980-fa7b-46b5-8f62-513d9fb05053 - PASS ac3-close-row-scroll (ui.scroll, 798ms): scrolled=true, selector=[data-testid^="transaction-card-64933273724-"], intoView=true, cdpPort=7666, targetUrl=chrome-extension://hebhblbkkdabgoldnojllkipeoacjioc/home.html#/perps/market/SOL - PASS ac3-close-row-visible (ui.wait_for, 769ms): matched=true, cdpPort=7666, targetUrl=chrome-extension://hebhblbkkdabgoldnojllkipeoacjioc/home.html#/perps/market/SOL, cdpTargetId=7E986C920B11ED065CD19466D8D8B705, runtimeSessionId=5764c980-fa7b-46b5-8f62-513d9fb05053 - PASS ac3-amount (command, 84ms): exitCode=0, stdout=-$0.02 - PASS ac3-recent-home (ui.navigate, 1.5s): page=perps, proof=ui-navigation - PASS ac3-recent-row (ui.wait_for, 614ms): matched=true, cdpPort=7666, targetUrl=chrome-extension://hebhblbkkdabgoldnojllkipeoacjioc/home.html#/perps-home, cdpTargetId=7E986C920B11ED065CD19466D8D8B705, runtimeSessionId=5764c980-fa7b-46b5-8f62-513d9fb05053 - PASS ac3-recent-scroll (ui.scroll, 679ms): scrolled=true, selector=[data-testid^="transaction-card-64933273724-"], intoView=true, cdpPort=7666, targetUrl=chrome-extension://hebhblbkkdabgoldnojllkipeoacjioc/home.html#/perps-home - PASS ac3-recent-visible (ui.wait_for, 583ms): matched=true, cdpPort=7666, targetUrl=chrome-extension://hebhblbkkdabgoldnojllkipeoacjioc/home.html#/perps-home, cdpTargetId=7E986C920B11ED065CD19466D8D8B705, runtimeSessionId=5764c980-fa7b-46b5-8f62-513d9fb05053 - PASS ac3-recent-figures (command, 86ms): exitCode=0, stdout={"text":"Closed long 0.13 SOL -$0.02","amount":"-$0.02"} RECENT_MATCHES=true - PASS ac3-recent-matches (assert_output, 51ms): source=ac3-recent-figures, stream=stdout, contains=RECENT_MATCHES=true - PASS ac3-open-details (ui.press, 526ms): clicked=true, selector=[data-testid^="transaction-card-64933273724-"], tagName=BUTTON, cdpPort=7666, targetUrl=chrome-extension://hebhblbkkdabgoldnojllkipeoacjioc/home.html#/perps-home - PASS ac3-details-pnl (ui.wait_for, 576ms): matched=true, cdpPort=7666, targetUrl=chrome-extension://hebhblbkkdabgoldnojllkip…
1 parent 12efc4e commit 2560458

32 files changed

Lines changed: 1419 additions & 1031 deletions

‎lavamoat/webpack/mv2/beta/policy.json‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -794,12 +794,6 @@
794794
"@metamask/utils": true
795795
}
796796
},
797-
"@metamask/perps-controller>@metamask/abi-utils": {
798-
"packages": {
799-
"@metamask/superstruct": true,
800-
"@metamask/utils": true
801-
}
802-
},
803797
"@metamask/account-api": {
804798
"packages": {
805799
"@metamask/keyring-api": true,
@@ -2744,6 +2738,7 @@
27442738
"@metamask/perps-controller": {
27452739
"globals": {
27462740
"AbortController": true,
2741+
"Intl.NumberFormat": true,
27472742
"URLSearchParams": true,
27482743
"clearInterval": true,
27492744
"clearTimeout": true,
@@ -2753,7 +2748,7 @@
27532748
"setTimeout": true
27542749
},
27552750
"packages": {
2756-
"@metamask/perps-controller>@metamask/abi-utils": true,
2751+
"@metamask/abi-utils": true,
27572752
"@metamask/base-controller": true,
27582753
"@metamask/perps-controller>@metamask/controller-utils": true,
27592754
"@metamask/superstruct": true,

‎lavamoat/webpack/mv2/experimental/policy.json‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -794,12 +794,6 @@
794794
"@metamask/utils": true
795795
}
796796
},
797-
"@metamask/perps-controller>@metamask/abi-utils": {
798-
"packages": {
799-
"@metamask/superstruct": true,
800-
"@metamask/utils": true
801-
}
802-
},
803797
"@metamask/account-api": {
804798
"packages": {
805799
"@metamask/keyring-api": true,
@@ -2744,6 +2738,7 @@
27442738
"@metamask/perps-controller": {
27452739
"globals": {
27462740
"AbortController": true,
2741+
"Intl.NumberFormat": true,
27472742
"URLSearchParams": true,
27482743
"clearInterval": true,
27492744
"clearTimeout": true,
@@ -2753,7 +2748,7 @@
27532748
"setTimeout": true
27542749
},
27552750
"packages": {
2756-
"@metamask/perps-controller>@metamask/abi-utils": true,
2751+
"@metamask/abi-utils": true,
27572752
"@metamask/base-controller": true,
27582753
"@metamask/perps-controller>@metamask/controller-utils": true,
27592754
"@metamask/superstruct": true,

‎lavamoat/webpack/mv2/flask/policy.json‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -794,12 +794,6 @@
794794
"@metamask/utils": true
795795
}
796796
},
797-
"@metamask/perps-controller>@metamask/abi-utils": {
798-
"packages": {
799-
"@metamask/superstruct": true,
800-
"@metamask/utils": true
801-
}
802-
},
803797
"@metamask/account-api": {
804798
"packages": {
805799
"@metamask/keyring-api": true,
@@ -2744,6 +2738,7 @@
27442738
"@metamask/perps-controller": {
27452739
"globals": {
27462740
"AbortController": true,
2741+
"Intl.NumberFormat": true,
27472742
"URLSearchParams": true,
27482743
"clearInterval": true,
27492744
"clearTimeout": true,
@@ -2753,7 +2748,7 @@
27532748
"setTimeout": true
27542749
},
27552750
"packages": {
2756-
"@metamask/perps-controller>@metamask/abi-utils": true,
2751+
"@metamask/abi-utils": true,
27572752
"@metamask/base-controller": true,
27582753
"@metamask/perps-controller>@metamask/controller-utils": true,
27592754
"@metamask/superstruct": true,

‎lavamoat/webpack/mv2/main/policy.json‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -794,12 +794,6 @@
794794
"@metamask/utils": true
795795
}
796796
},
797-
"@metamask/perps-controller>@metamask/abi-utils": {
798-
"packages": {
799-
"@metamask/superstruct": true,
800-
"@metamask/utils": true
801-
}
802-
},
803797
"@metamask/account-api": {
804798
"packages": {
805799
"@metamask/keyring-api": true,
@@ -2744,6 +2738,7 @@
27442738
"@metamask/perps-controller": {
27452739
"globals": {
27462740
"AbortController": true,
2741+
"Intl.NumberFormat": true,
27472742
"URLSearchParams": true,
27482743
"clearInterval": true,
27492744
"clearTimeout": true,
@@ -2753,7 +2748,7 @@
27532748
"setTimeout": true
27542749
},
27552750
"packages": {
2756-
"@metamask/perps-controller>@metamask/abi-utils": true,
2751+
"@metamask/abi-utils": true,
27572752
"@metamask/base-controller": true,
27582753
"@metamask/perps-controller>@metamask/controller-utils": true,
27592754
"@metamask/superstruct": true,

‎lavamoat/webpack/mv3/beta/policy.json‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -998,12 +998,6 @@
998998
"@metamask/utils": true
999999
}
10001000
},
1001-
"@metamask/perps-controller>@metamask/abi-utils": {
1002-
"packages": {
1003-
"@metamask/superstruct": true,
1004-
"@metamask/utils": true
1005-
}
1006-
},
10071001
"@metamask/account-api": {
10081002
"packages": {
10091003
"@metamask/keyring-api": true,
@@ -2951,6 +2945,7 @@
29512945
"@metamask/perps-controller": {
29522946
"globals": {
29532947
"AbortController": true,
2948+
"Intl.NumberFormat": true,
29542949
"URLSearchParams": true,
29552950
"clearInterval": true,
29562951
"clearTimeout": true,
@@ -2960,7 +2955,7 @@
29602955
"setTimeout": true
29612956
},
29622957
"packages": {
2963-
"@metamask/perps-controller>@metamask/abi-utils": true,
2958+
"@metamask/abi-utils": true,
29642959
"@metamask/base-controller": true,
29652960
"@metamask/perps-controller>@metamask/controller-utils": true,
29662961
"@metamask/superstruct": true,

‎lavamoat/webpack/mv3/experimental/policy.json‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -998,12 +998,6 @@
998998
"@metamask/utils": true
999999
}
10001000
},
1001-
"@metamask/perps-controller>@metamask/abi-utils": {
1002-
"packages": {
1003-
"@metamask/superstruct": true,
1004-
"@metamask/utils": true
1005-
}
1006-
},
10071001
"@metamask/account-api": {
10081002
"packages": {
10091003
"@metamask/keyring-api": true,
@@ -2951,6 +2945,7 @@
29512945
"@metamask/perps-controller": {
29522946
"globals": {
29532947
"AbortController": true,
2948+
"Intl.NumberFormat": true,
29542949
"URLSearchParams": true,
29552950
"clearInterval": true,
29562951
"clearTimeout": true,
@@ -2960,7 +2955,7 @@
29602955
"setTimeout": true
29612956
},
29622957
"packages": {
2963-
"@metamask/perps-controller>@metamask/abi-utils": true,
2958+
"@metamask/abi-utils": true,
29642959
"@metamask/base-controller": true,
29652960
"@metamask/perps-controller>@metamask/controller-utils": true,
29662961
"@metamask/superstruct": true,

‎lavamoat/webpack/mv3/flask/policy.json‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -998,12 +998,6 @@
998998
"@metamask/utils": true
999999
}
10001000
},
1001-
"@metamask/perps-controller>@metamask/abi-utils": {
1002-
"packages": {
1003-
"@metamask/superstruct": true,
1004-
"@metamask/utils": true
1005-
}
1006-
},
10071001
"@metamask/account-api": {
10081002
"packages": {
10091003
"@metamask/keyring-api": true,
@@ -2951,6 +2945,7 @@
29512945
"@metamask/perps-controller": {
29522946
"globals": {
29532947
"AbortController": true,
2948+
"Intl.NumberFormat": true,
29542949
"URLSearchParams": true,
29552950
"clearInterval": true,
29562951
"clearTimeout": true,
@@ -2960,7 +2955,7 @@
29602955
"setTimeout": true
29612956
},
29622957
"packages": {
2963-
"@metamask/perps-controller>@metamask/abi-utils": true,
2958+
"@metamask/abi-utils": true,
29642959
"@metamask/base-controller": true,
29652960
"@metamask/perps-controller>@metamask/controller-utils": true,
29662961
"@metamask/superstruct": true,

‎lavamoat/webpack/mv3/main/policy.json‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -998,12 +998,6 @@
998998
"@metamask/utils": true
999999
}
10001000
},
1001-
"@metamask/perps-controller>@metamask/abi-utils": {
1002-
"packages": {
1003-
"@metamask/superstruct": true,
1004-
"@metamask/utils": true
1005-
}
1006-
},
10071001
"@metamask/account-api": {
10081002
"packages": {
10091003
"@metamask/keyring-api": true,
@@ -2951,6 +2945,7 @@
29512945
"@metamask/perps-controller": {
29522946
"globals": {
29532947
"AbortController": true,
2948+
"Intl.NumberFormat": true,
29542949
"URLSearchParams": true,
29552950
"clearInterval": true,
29562951
"clearTimeout": true,
@@ -2960,7 +2955,7 @@
29602955
"setTimeout": true
29612956
},
29622957
"packages": {
2963-
"@metamask/perps-controller>@metamask/abi-utils": true,
2958+
"@metamask/abi-utils": true,
29642959
"@metamask/base-controller": true,
29652960
"@metamask/perps-controller>@metamask/controller-utils": true,
29662961
"@metamask/superstruct": true,

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@
504504
"@metamask/permission-controller": "^14.1.0",
505505
"@metamask/permission-log-controller": "^5.0.0",
506506
"@metamask/permissions-kernel-snap": "^1.3.0",
507-
"@metamask/perps-controller": "^22.1.1",
507+
"@metamask/perps-controller": "^22.3.0",
508508
"@metamask/phishing-controller": "^18.2.1",
509509
"@metamask/polling-controller": "^16.0.7",
510510
"@metamask/post-message-stream": "^10.0.0",

‎test/mocks/metamask-perps-controller.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,21 @@ function mockSelectVisibleCandleCount(state) {
468468
: mockDefaultVisibleCandleCount;
469469
}
470470

471+
// Shared Perps calculations come from the real package so tests assert Core's
472+
// formulas, not a copy. These modules import only `bignumber.js` and constants,
473+
// so they load without the Hyperliquid SDK.
474+
const mockCloseCalculations = require('@metamask/perps-controller/utils/closeCalculations');
475+
const mockTpslCalculations = require('@metamask/perps-controller/utils/tpslCalculations');
476+
const mockPerpsConfig = require('@metamask/perps-controller/constants/perpsConfig');
477+
const mockPerpsFormatters = require('@metamask/perps-controller/utils/perpsFormatters');
478+
471479
module.exports = {
480+
...mockCloseCalculations,
481+
...mockTpslCalculations,
482+
CLOSE_POSITION_CONFIG: mockPerpsConfig.CLOSE_POSITION_CONFIG,
483+
TP_SL_PRECISION_CONFIG: mockPerpsConfig.TP_SL_PRECISION_CONFIG,
484+
formatPerpsFiat: mockPerpsFormatters.formatPerpsFiat,
485+
formatPnl: mockPerpsFormatters.formatPnl,
472486
DEFAULT_ORDER_BOOK_PREFERENCES: mockDefaultOrderBookPreferences,
473487
DEFAULT_PRO_LAYOUT_PREFERENCES: mockDefaultProLayoutPreferences,
474488
DEFAULT_SELECTED_ORDER_TYPE: 'market',

0 commit comments

Comments
 (0)