Skip to content

Commit a8d7daf

Browse files
feat(perps): update latest hyperliquid sdk (#28672)
## **Description** Bumps `@nktkas/hyperliquid` from `0.30.2` to `0.32.2` (latest). **What changed in the SDK:** - `@nktkas/rews` 1.2.3 → 2.1.0 (WebSocket reconnection library) - `valibot` 1.2.0 → 1.3.1 (request validation) - `micro-eth-signer` removed (signing now fully delegated to wallet adapter) **What this PR changes:** - `package.json` / `yarn.lock` — version bump - `shim.js` — Added `CloseEvent` and `MessageEvent` polyfills for React Native/Hermes. `@nktkas/rews` v2 uses `new CloseEvent(...)` and `new MessageEvent(...)` which are standard Web APIs but not available as constructors in Hermes. Without these polyfills, every WebSocket close/message event crashes the transport. No changes to `HyperLiquidClientService`, `HyperLiquidProvider`, or any other app code. ## **Changelog** CHANGELOG entry: null ## **Related issues** Fixes: https://consensyssoftware.atlassian.net/browse/TAT-2906 ## **Manual testing steps** ```gherkin Feature: Hyperliquid SDK upgrade validation Scenario: Full BTC trade lifecycle on testnet Given wallet is unlocked and perps feature is enabled When user navigates to Perps and switches to testnet Then market data loads (BTC, ETH, SOL visible with prices) When user opens a BTC long market order ($10, 2x leverage) Then position appears in portfolio When user creates TP/SL (+25% / -10%) Then TP and SL orders are confirmed When user closes the position Then position is removed from portfolio ``` **Reproduce via recipe:** ```bash bash scripts/perps/agentic/validate-recipe.sh \ scripts/perps/agentic/teams/perps/recipes/full-trade-lifecycle.json \ --testnet ``` ## **Screenshots/Recordings** ### **Before** No UI changes — dependency update only. ### **After** Full trade lifecycle validated (14/14 steps pass): navigate → testnet → open BTC long → TP/SL → close → verify. https://github.com/user-attachments/assets/50e6ef61-57b1-442a-913b-75daad07d1bb ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/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-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] 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. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Updates the Hyperliquid perps dependency and its WebSocket stack, which can affect trading connectivity and runtime behavior. Adds global `CloseEvent`/`MessageEvent` constructors to prevent Hermes crashes, but changes occur in app-wide shims. > > **Overview** > Upgrades `@nktkas/hyperliquid` to `0.32.2`, pulling in `@nktkas/rews` v2 and updated validation deps, and updating the lockfile accordingly. > > Adds React Native/Hermes polyfills in `shim.js` for global `CloseEvent` and `MessageEvent` to support the SDK’s updated WebSocket transport and avoid crashes when handling close/message events. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit e109022. 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: Alejandro Garcia Anglada <aganglada@gmail.com>
1 parent c87c5a1 commit a8d7daf

3 files changed

Lines changed: 45 additions & 58 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@
330330
"@metamask/utils": "^11.11.0",
331331
"@myx-trade/sdk": "^0.1.265",
332332
"@ngraveio/bc-ur": "^1.1.6",
333-
"@nktkas/hyperliquid": "^0.30.2",
333+
"@nktkas/hyperliquid": "^0.32.2",
334334
"@noble/curves": "1.9.6",
335335
"@noble/hashes": "1.8.0",
336336
"@notifee/react-native": "^9.0.0",

shim.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,32 @@ if (typeof global.CustomEvent === 'undefined') {
130130
};
131131
}
132132

133+
// CloseEvent polyfill for @nktkas/rews v2 (used by Hyperliquid SDK WebSocket transport)
134+
// React Native/Hermes does not provide CloseEvent as a global constructor
135+
if (typeof global.CloseEvent === 'undefined') {
136+
global.CloseEvent = function (type, params) {
137+
params = params || {};
138+
const event = new global.Event(type, params);
139+
event.code = params.code ?? 0;
140+
event.reason = params.reason ?? '';
141+
event.wasClean = params.wasClean ?? false;
142+
return event;
143+
};
144+
}
145+
146+
// MessageEvent polyfill for @nktkas/rews v2 (used by Hyperliquid SDK WebSocket transport)
147+
// React Native/Hermes does not provide MessageEvent as a global constructor
148+
if (typeof global.MessageEvent === 'undefined') {
149+
global.MessageEvent = function (type, params) {
150+
params = params || {};
151+
const event = new global.Event(type, params);
152+
event.data = params.data ?? null;
153+
event.origin = params.origin ?? '';
154+
event.lastEventId = params.lastEventId ?? '';
155+
return event;
156+
};
157+
}
158+
133159
class AbortError extends Error {
134160
constructor(message) {
135161
super(message);

yarn.lock

Lines changed: 18 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -10381,24 +10381,21 @@ __metadata:
1038110381
languageName: node
1038210382
linkType: hard
1038310383

10384-
"@nktkas/hyperliquid@npm:^0.30.2":
10385-
version: 0.30.2
10386-
resolution: "@nktkas/hyperliquid@npm:0.30.2"
10387-
dependencies:
10388-
"@nktkas/rews": "npm:^1.2.3"
10389-
"@noble/hashes": "npm:^2.0.1"
10390-
micro-eth-signer: "npm:^0.18.1"
10391-
valibot: "npm:1.2.0"
10392-
bin:
10393-
hyperliquid: esm/bin/cli.js
10394-
checksum: 10/dd26b562d45d051192548f1c9f542b120e3a6db21a0a8a5f93d16e9f75c2bcefa297e2a12ee56828b9e1e87a373d6c18548c2388467d22ba8981a32c16486aab
10384+
"@nktkas/hyperliquid@npm:^0.32.2":
10385+
version: 0.32.2
10386+
resolution: "@nktkas/hyperliquid@npm:0.32.2"
10387+
dependencies:
10388+
"@nktkas/rews": "npm:^2"
10389+
"@noble/hashes": "npm:^2"
10390+
valibot: "npm:1.3.1"
10391+
checksum: 10/58ffc50d51aa5842285697c45b2c8bc80a7e0a610b82220902f8f7acee2e58c4099dcc195ce1456130869c3e33c93d6445f02833a59997e8b937398991d8829e
1039510392
languageName: node
1039610393
linkType: hard
1039710394

10398-
"@nktkas/rews@npm:^1.2.3":
10399-
version: 1.2.3
10400-
resolution: "@nktkas/rews@npm:1.2.3"
10401-
checksum: 10/032d7373ba976167d6f8f24746e9f2ebf20768811943ce8d33ffbb28fab0ad6259800177bd9964449f8fd67c5ef7e781fcee9f1d9bbbffd55f133e4a4c6d9fce
10395+
"@nktkas/rews@npm:^2":
10396+
version: 2.1.0
10397+
resolution: "@nktkas/rews@npm:2.1.0"
10398+
checksum: 10/c658d42d6ca79dad62d594818d680317e6f4ecc939149f02a588939b0e4fc40fb5b673199772241d4ca771b28f7bded8cbe0947d267f31a90ec6bc95d226c633
1040210399
languageName: node
1040310400
linkType: hard
1040410401

@@ -10497,15 +10494,6 @@ __metadata:
1049710494
languageName: node
1049810495
linkType: hard
1049910496

10500-
"@noble/curves@npm:^2.0.0":
10501-
version: 2.0.1
10502-
resolution: "@noble/curves@npm:2.0.1"
10503-
dependencies:
10504-
"@noble/hashes": "npm:2.0.1"
10505-
checksum: 10/e826af523f40a671601a6d07f98df16c3afe1cbd0349c3ba4d7b31f6dba7dc743822719f260bd291716b6b42b8dc327f94a76b4852359aa85f79df461eb22bfc
10506-
languageName: node
10507-
linkType: hard
10508-
1050910497
"@noble/hashes@npm:1.3.2":
1051010498
version: 1.3.2
1051110499
resolution: "@noble/hashes@npm:1.3.2"
@@ -10541,7 +10529,7 @@ __metadata:
1054110529
languageName: node
1054210530
linkType: hard
1054310531

10544-
"@noble/hashes@npm:2.0.1, @noble/hashes@npm:^2.0.0, @noble/hashes@npm:^2.0.1":
10532+
"@noble/hashes@npm:^2":
1054510533
version: 2.0.1
1054610534
resolution: "@noble/hashes@npm:2.0.1"
1054710535
checksum: 10/f4d00e7564eb4ff4e6d16be151dd0e404aede35f91e4372b0a8a6ec888379c1dd1e02c721b480af8e7853bea9637185b5cb9533970c5b77d60c254ead0cfd8f7
@@ -13132,13 +13120,6 @@ __metadata:
1313213120
languageName: node
1313313121
linkType: hard
1313413122

13135-
"@scure/base@npm:2.0.0":
13136-
version: 2.0.0
13137-
resolution: "@scure/base@npm:2.0.0"
13138-
checksum: 10/8fb86024f22e9c532d513b8df8a672252e58bd5695920ce646162287f0accd38e89cab58722a738b3d247b5dcf7760362ae2d82d502be7e62a555f5d98f8a110
13139-
languageName: node
13140-
linkType: hard
13141-
1314213123
"@scure/base@npm:~1.1.3, @scure/base@npm:~1.1.6":
1314313124
version: 1.1.9
1314413125
resolution: "@scure/base@npm:1.1.9"
@@ -35685,7 +35666,7 @@ __metadata:
3568535666
"@metamask/utils": "npm:^11.11.0"
3568635667
"@myx-trade/sdk": "npm:^0.1.265"
3568735668
"@ngraveio/bc-ur": "npm:^1.1.6"
35688-
"@nktkas/hyperliquid": "npm:^0.30.2"
35669+
"@nktkas/hyperliquid": "npm:^0.32.2"
3568935670
"@noble/curves": "npm:1.9.6"
3569035671
"@noble/hashes": "npm:1.8.0"
3569135672
"@notifee/react-native": "npm:^9.0.0"
@@ -36327,33 +36308,13 @@ __metadata:
3632736308
languageName: node
3632836309
linkType: hard
3632936310

36330-
"micro-eth-signer@npm:^0.18.1":
36331-
version: 0.18.1
36332-
resolution: "micro-eth-signer@npm:0.18.1"
36333-
dependencies:
36334-
"@noble/curves": "npm:^2.0.0"
36335-
"@noble/hashes": "npm:^2.0.0"
36336-
micro-packed: "npm:^0.8.0"
36337-
checksum: 10/daa1127b0f4bffa1ffbe0c0d0f0d5bab98636697e1936a0fa552e0bb3b853b3f6733198219d2791323160feb30c12622b366dffd18ad794ec68a0a8fbaa255f1
36338-
languageName: node
36339-
linkType: hard
36340-
3634136311
"micro-ftch@npm:^0.3.1":
3634236312
version: 0.3.1
3634336313
resolution: "micro-ftch@npm:0.3.1"
3634436314
checksum: 10/a7ab07d25e28ec4ae492ce4542ea9b06eee85538742b3b1263b247366ee8872f2c5ce9c8651138b2f1d22c8212f691a7b8b5384fe86ead5aff1852e211f1c035
3634536315
languageName: node
3634636316
linkType: hard
3634736317

36348-
"micro-packed@npm:^0.8.0":
36349-
version: 0.8.0
36350-
resolution: "micro-packed@npm:0.8.0"
36351-
dependencies:
36352-
"@scure/base": "npm:2.0.0"
36353-
checksum: 10/94bc96387be56d95ca758fcaddbeacdd8095344c3cc51b813637587f4b013853088f046d9a2e81354d583f384ec44c35aa008683aa13397d700ddf7b70aff77e
36354-
languageName: node
36355-
linkType: hard
36356-
3635736318
"micromatch@npm:^4.0.2, micromatch@npm:^4.0.4, micromatch@npm:^4.0.5, micromatch@npm:^4.0.8":
3635836319
version: 4.0.8
3635936320
resolution: "micromatch@npm:4.0.8"
@@ -46734,15 +46695,15 @@ __metadata:
4673446695
languageName: node
4673546696
linkType: hard
4673646697

46737-
"valibot@npm:1.2.0":
46738-
version: 1.2.0
46739-
resolution: "valibot@npm:1.2.0"
46698+
"valibot@npm:1.3.1":
46699+
version: 1.3.1
46700+
resolution: "valibot@npm:1.3.1"
4674046701
peerDependencies:
4674146702
typescript: ">=5"
4674246703
peerDependenciesMeta:
4674346704
typescript:
4674446705
optional: true
46745-
checksum: 10/5f9c15e6f5a2b8eae75332a3317e46e995a1763efe1b91e57bc5064e36f0feba734367c88013d53255bdf09fb9204bf3598d2ca0c3f468c8726095b1c3551926
46706+
checksum: 10/e14d085fa87fbf41f76d040cdcf17e31527f868c8b82f878bc488a5bc3bc81162406c605182fc720473ec6dcff05393b89fb4a921a4206d9f7b6f76e3c93cf34
4674646707
languageName: node
4674746708
linkType: hard
4674846709

0 commit comments

Comments
 (0)