Repository navigation
fix(perps-controller): handle revoked HyperLiquid agents and wallet-chain signing - #10643
Merged
Merged
Conversation
…gn user actions for the signer's chain, stop re-prompting a refused builder fee - An agent-signed write that the venue answers with "Must deposit before performing actions" is a rejection when extraAgents no longer lists the agent (or lists it as expired): the agent is dropped, onAgentRejected is called and the write fails with KEYRING_LOCKED. Otherwise the venue error is returned as before. - Add optional PerpsAccountSigner.getChainId, passed to the SDK as the signatureChainId of user-signed actions. Without it nothing changes. - A builder fee approval the venue refuses for a reason signing again cannot fix is not requested again until disconnect.
… that signed the request The rejection check used the latest agent signature for the main account on the current network, so a main-signed builder fee approval, an answer that arrived after a network switch, or a request signed by an agent the host had just replaced could evict the wrong agent. - The client service reports each exchange request with the venue's answer, from inside the SDK request; the wallet adapter reports each agent signature; the provider matches them by the signature's r value. - Main-signed requests are never attributed to an agent; requests signed on another network or before a disconnect are not checked. - A builder fee refusal settling after a disconnect is not recorded. - Document that the "Must deposit" check relies on named agents and the device clock, and the prepareTradingWallet result for a refused builder fee.
…before signing The network and lifecycle generation of an agent signature were read once the signature completed, so a mainnet signature that finished after a network switch or a reconnect was checked as a current request. - Read the network, lifecycle generation and main account when the agent is asked for, and record each signature the resolved agent makes with them; the wallet adapter no longer reports signatures. - Do not track a signature the SDK would refuse before sending it, and drop unanswered signatures on disconnect.
…them The SDK queues a write before it asks the wallet to sign, so a mainnet write queued behind another one could sign after toggleTestnet(): it then resolved the testnet agent, recorded the new network and session, and its mainnet rejection was checked against testnet agents. - Each wallet adapter the provider creates is bound to the network and lifecycle generation of its exchange client; it resolves agents on that network and records its agent signatures in the binding. - The client service reports the wallet with each exchange request, so the venue's answer is matched in that wallet's binding. - createWalletAdapter takes the resolver for that adapter.
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 0c63793. Configure here.
…t and bind every wallet - A "User or API Wallet ... does not exist" answer is attributed to the agent signature linked to the request it answers, on that wallet's network, so an agent used on both networks is dropped only where the venue rejected it. The agent's last account is used only when no signature is linked. - The subscription service creates its wallets through the provider, so they are bound and resolve agents like the provider's. - HyperLiquidProvider.getExchangeClient initializes the provider's clients before handing out the exchange client.
geositta
previously approved these changes
Oct 2, 2026
…tion-signature-chain # Conflicts: # packages/perps-controller/CHANGELOG.md
abretonc7s
enabled auto-merge
October 2, 2026 07:54
aganglada
approved these changes
Oct 2, 2026
Naz-Ovh
pushed a commit
to 0x-fork/metamask-core
that referenced
this pull request
Oct 7, 2026
## Explanation Releases `@metamask/perps-controller` **19.0.0 → 20.0.0**. The monorepo version goes **1314.0.0 → 1315.0.0**. No other package is being published. Perps-controller has no in-monorepo dependents that need a workspace range bump. The bump is **major**. Public unions and Lighter order validation change: - **BREAKING:** Lighter `placeOrder` / `validateOrder` accept supported native attached TP/SL instead of refusing all attachments. Gate forwarding on `attachedTpsl`. ([MetaMask#10638](MetaMask#10638)) - **BREAKING:** Grouped Lighter signer calls require grouping/count `1/2` or `2/2` with two orders, or `3/3` with three orders. ([MetaMask#10638](MetaMask#10638)) - **BREAKING:** `ScaleOrderChild.state` adds `canceled`. ([MetaMask#10638](MetaMask#10638)) - **BREAKING:** `DirectProviderOrderCapabilitiesUnavailableReason` and `OrderCapabilitiesUnavailableReason` add `order_market_unsupported`. ([MetaMask#10638](MetaMask#10638)) - **BREAKING:** Stray `triggerPrice` on Lighter basic market/limit orders is refused with `ORDER_TRIGGER_PRICE_NOT_SUPPORTED`. ([MetaMask#10638](MetaMask#10638)) - **BREAKING:** Lighter position TP/SL replacement and removal preserve independent partial triggers. ([MetaMask#10638](MetaMask#10638)) - **BREAKING:** `OrderFill.pnl` is optional when the venue omits realized PnL. Treat missing as unknown, not zero. ([MetaMask#10605](MetaMask#10605)) Also ships Lighter Scale/Chase/TWAP probe work, fee quote attribution (`feeSource`, `metamaskFeeDiscountBips`), HyperLiquid agent/signing fixes, quieter optional-messenger failures, and watchlist hydration/write races. ## Changelog Moved Unreleased entries in `packages/perps-controller/CHANGELOG.md` under `[20.0.0]`. Removed Uncategorized monorepo release markers (1311–1314) that do not affect package consumers. Dropped a duplicate Chase probe summary already covered by more specific entries. ## References - Source PRs: [MetaMask#10638](MetaMask#10638), [MetaMask#10618](MetaMask#10618), [MetaMask#10605](MetaMask#10605), [MetaMask#10643](MetaMask#10643), [MetaMask#10650](MetaMask#10650), [MetaMask#10651](MetaMask#10651), [MetaMask#10665](MetaMask#10665), [MetaMask#10670](MetaMask#10670), [MetaMask#10683](MetaMask#10683) - No in-monorepo consumer packages to bump. Mobile and Extension exhaustive union matches need the new members on upgrade. Lighter attached TP/SL stays gated on `attachedTpsl` and client rollout. ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md) - [x] I've introduced [breaking changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md) in this PR and have prepared draft pull requests for clients and consumer packages to resolve them Made with [Cursor](https://cursor.com) --------- Co-authored-by: Cursor <cursoragent@cursor.com>
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
Running 19.0.0 with an extension wallet (EIP-1193
accountSignerplus a HyperLiquid agent) showed three problems:Must deposit before performing actions, not onlyUser or API Wallet … does not exist. That answer now counts as a rejection only ifextraAgentsno longer lists the agent that signed that request. The answer is attributed by the request's own signature, inside a wallet binding per network and session. When it counts, the write returnsKEYRING_LOCKED, the agent is dropped andonAgentRejectedfires. Main-account signatures are never attributed to an agent.PerpsAccountSignergets an optionalgetChainId(), passed to the SDK assignatureChainId. Builder fee approvals, withdrawals and transfers are then signed on the wallet's chain. Without it nothing changes, so Mobile and Extension are unaffected.prepareTradingWalletreturns the venue's message.Also:
getExchangeClient()initializes the provider's clients before returning one.Validation
mainwith the reported symptoms. Mutation checks on the attribution guards each fail a test. The package suite passes with coverage on Node 22 and 24.KEYRING_LOCKEDand callsonAgentRejected.mainreturns the raw venue error. User-signed actions go out withsignatureChainId0x66eee(421614).Known issues / follow-ups
extraAgentslists an unnamed agent is undocumented. TheonAgentRejecteddocs ask hosts to approve named agents.validUntilis compared against the device clock.toggleTestnet(), the client service keeps the previous network's wallet. This is harmless today; the fix is a follow-up.References
Checklist
Note
Medium Risk
Changes HyperLiquid signing, agent eviction, and trading-wallet setup paths; mistakes could mis-classify venue errors or drop agents incorrectly, but behavior is heavily covered by new tests.
Overview
Fixes HyperLiquid trading setup and signing when hosts use an
accountSignerplus an agent (typical extension wallets).Revoked / expired agents: The provider now ties each L1 signature to the network and session wallet that created it, and links venue answers back to that signature via
onExchangeRequest. A "Must deposit before performing actions" response is treated as agent rejection only whenextraAgentsno longer lists (or has expired) the agent that signed that request—not when the account is simply unfunded. Unknown-wallet errors are attributed to the request’s network, so a shared agent on mainnet and testnet is dropped only where the venue rejected it. Queued writes that sign after a network switch use the original wallet’s agent resolver.User-signed actions: Optional
PerpsAccountSigner.getChainIdflows through the wallet adapter as SDKsignatureChainId, so builder fee, withdraw, and transfer payloads can be signed on the connected chain instead of chain 1.Builder fee: Permanent venue refusals (e.g. insufficient builder balance) are cached until disconnect—no repeat approval prompts;
prepareTradingWalletcan return the venue message without logging it as a generic setup failure.Other:
getExchangeClient()ensures the provider’s SDK clients (and agent wallet) are initialized first; subscription-created wallets use the same agent binding as the provider.Reviewed by Cursor Bugbot for commit 88f7383. Bugbot is set up for automated code reviews on this repo. Configure here.