perf(perps): add coherent bootstrap snapshots - #9815
Open
abretonc7s wants to merge 4 commits into
Open
Conversation
abretonc7s
force-pushed
the
perf/3662-perps-bootstrap-snapshots
branch
from
August 11, 2026 03:37
4355de0 to
a73cce2
Compare
abretonc7s
marked this pull request as ready for review
August 11, 2026 07:58
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 3378749. Configure here.
abretonc7s
force-pushed
the
perf/3662-perps-bootstrap-snapshots
branch
from
August 11, 2026 08:33
3378749 to
9a75d43
Compare
abretonc7s
enabled auto-merge
August 12, 2026 02:04
geositta
requested changes
Aug 12, 2026
geositta
left a comment
Contributor
There was a problem hiding this comment.
Requesting changes. The identity, freshness, completeness, and lifecycle guards are implemented and tested, but requesting that the snapshot path remain time bounded through body consumption.
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.

Explanation
Perps cold start currently assembles market and account data through independent provider requests. That makes first content sensitive to request ordering, stale cache identity, and WebSocket readiness.
This PR adds two opt-in, client-neutral bootstrap paths:
terminalApi.globalSnapshotUrl. It validates provider/network/DEX identity, freshness, completeness, units, trends, and payload size, then falls back exactly once to HyperLiquid.PerpsController.getUserDataSnapshot(), which returns positions, open orders, and account state as one address/network/HIP-3/DEX-scoped result while reusing each DEX clearinghouse response.It also makes market/account preloading independent, guards cache writes across account/provider/network/HIP-3 lifecycle changes, persists exact cache identity, and reuses provider DEX discovery for subscriptions. The existing
terminalApiUrlremains supported as a deprecated legacy market-data URL. No production Terminal snapshot endpoint is enabled by this package change; client configuration is a separate adoption step.PerpsControllernow consumes the modernRemoteFeatureFlagController:stateChangedevent and reads the initial flag state duringinit(), avoiding messenger action calls in the constructor.Validation
@metamask/remote-feature-flag-controllerforced TypeScript build: passed.@metamask/perps-controllerbuild: passed.References
Checklist
Note
High Risk
Touches Perps account/market caching and cold-start data paths, plus a breaking messenger/init change for remote feature flags that consumers must adopt correctly.
Overview
Adds opt-in coherent bootstrap paths so Perps cold start no longer depends on independently ordered market and account requests.
Market data: Prefer a schema-v2 Terminal global snapshot (
terminalApi.globalSnapshotUrl) with strict provider/network/DEX identity, freshness, completeness, unit, and payload checks, then fall back once to HyperLiquid. LegacyterminalApiUrlremains as a deprecated market-data URL.Account data: Add
getUserDataSnapshot()to fetch and atomically cache positions, open orders, and account state as one address/network/HIP-3/DEX-scoped result. Market and user preloading now run independently, with race guards that discard stale writes across account, provider, network, and HIP-3 changes.BREAKING: Subscribe to
RemoteFeatureFlagController:stateChangedand read initial remote flags ininit()instead of the constructor. Cached account reads also fail closed unless the selected EVM address and current HyperLiquid identity match.Reviewed by Cursor Bugbot for commit ebb9f4f. Bugbot is set up for automated code reviews on this repo. Configure here.