@metamask-previews/perps-controller 22.3.0-preview-9dfb538be → 22.3.0-preview-a2a3d82

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/dist/PerpsController-method-action-types.d.ts +19 -1
  3. package/dist/PerpsController-method-action-types.d.ts.map +1 -1
  4. package/dist/PerpsController-method-action-types.js.map +1 -1
  5. package/dist/PerpsController.d.ts +16 -1
  6. package/dist/PerpsController.d.ts.map +1 -1
  7. package/dist/PerpsController.js +32 -0
  8. package/dist/PerpsController.js.map +1 -1
  9. package/dist/constants/perpsConfig.d.ts +16 -0
  10. package/dist/constants/perpsConfig.d.ts.map +1 -1
  11. package/dist/constants/perpsConfig.js +24 -0
  12. package/dist/constants/perpsConfig.js.map +1 -1
  13. package/dist/index.d.ts +4 -4
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +1 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/providers/AggregatedPerpsProvider.d.ts +10 -1
  18. package/dist/providers/AggregatedPerpsProvider.d.ts.map +1 -1
  19. package/dist/providers/AggregatedPerpsProvider.js +20 -0
  20. package/dist/providers/AggregatedPerpsProvider.js.map +1 -1
  21. package/dist/providers/HyperLiquidProvider.d.ts +10 -1
  22. package/dist/providers/HyperLiquidProvider.d.ts.map +1 -1
  23. package/dist/providers/HyperLiquidProvider.js +20 -0
  24. package/dist/providers/HyperLiquidProvider.js.map +1 -1
  25. package/dist/services/HyperLiquidSubscriptionService.d.ts +22 -1
  26. package/dist/services/HyperLiquidSubscriptionService.d.ts.map +1 -1
  27. package/dist/services/HyperLiquidSubscriptionService.js +90 -0
  28. package/dist/services/HyperLiquidSubscriptionService.js.map +1 -1
  29. package/dist/types/index.d.ts +43 -0
  30. package/dist/types/index.d.ts.map +1 -1
  31. package/dist/types/index.js.map +1 -1
  32. package/dist/utils/perpsFormatters.d.ts +125 -53
  33. package/dist/utils/perpsFormatters.d.ts.map +1 -1
  34. package/dist/utils/perpsFormatters.js +345 -202
  35. package/dist/utils/perpsFormatters.js.map +1 -1
  36. package/package.json +5 -4
@@ -1,4 +1,5 @@
1
- import type { TwapHistoryResponse, AssetCtxsWsEvent } from '@nktkas/hyperliquid';
1
+ import type { CaipAccountId } from '@metamask/utils';
2
+ import type { TwapHistoryResponse, ActiveAssetDataWsEvent, AssetCtxsWsEvent } from '@nktkas/hyperliquid';
2
3
  import type { HyperLiquidAbstractionMode } from '../types/hyperliquid-types.js';
3
4
  import type { Position, OrderFill, Order, TwapOrder, SubscribePricesParams, SubscribePositionsParams, SubscribeOrderFillsParams, SubscribeOrdersParams, SubscribeTwapOrdersParams, SubscribeAccountParams, SubscribeOICapsParams, SubscribeOrderBookParams, PerpsPlatformDependencies } from '../types/index.js';
4
5
  import type { HyperLiquidClientService } from './HyperLiquidClientService.js';
@@ -254,6 +255,26 @@ export declare class HyperLiquidSubscriptionService {
254
255
  * @returns Cleanup function to unsubscribe
255
256
  */
256
257
  subscribeToOrderBook(params: SubscribeOrderBookParams): () => void;
258
+ /**
259
+ * Stream the venue's `activeAssetData` for one account and market. Each
260
+ * caller gets its own venue subscription, which restoreSubscriptions()
261
+ * reopens on a replacement transport and clearAll() retires. The venue
262
+ * pushes a new frame when the market's position, leverage or mark price
263
+ * changes.
264
+ *
265
+ * @param params - Subscription parameters.
266
+ * @param params.symbol - Market symbol, including any DEX prefix.
267
+ * @param params.accountId - Optional CAIP account ID; defaults to the selected account.
268
+ * @param params.callback - Receives each frame for this account and market.
269
+ * @param params.onError - Receives a failure to open the subscription.
270
+ * @returns Cleanup function to unsubscribe.
271
+ */
272
+ subscribeToActiveAssetData(params: {
273
+ symbol: string;
274
+ accountId?: CaipAccountId;
275
+ callback: (data: ActiveAssetDataWsEvent) => void;
276
+ onError?: (error: Error) => void;
277
+ }): () => void;
257
278
  /**
258
279
  * Restore all active subscriptions after WebSocket reconnection
259
280
  * Re-establishes WebSocket subscriptions for all active subscribers
@@ -1 +1 @@
1
- {"version":3,"file":"HyperLiquidSubscriptionService.d.ts","sourceRoot":"","sources":["../../src/services/HyperLiquidSubscriptionService.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAMV,mBAAmB,EAKnB,gBAAgB,EAMjB,MAAM,qBAAqB,CAAC;AAO7B,OAAO,KAAK,EAEV,0BAA0B,EAC3B,MAAM,+BAA+B,CAAC;AAGvC,OAAO,KAAK,EAEV,QAAQ,EACR,SAAS,EACT,KAAK,EAEL,SAAS,EACT,qBAAqB,EACrB,wBAAwB,EACxB,yBAAyB,EACzB,qBAAqB,EACrB,yBAAyB,EACzB,sBAAsB,EACtB,qBAAqB,EACrB,wBAAwB,EAGxB,yBAAyB,EAG1B,MAAM,mBAAmB,CAAC;AAgC3B,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAC9E,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAE9E;;;GAGG;AACH,KAAK,kBAAkB,GAAG,IAAI,CAC5B,wBAAwB,EACxB,qBAAqB,GAAG,2BAA2B,CACpD,CAAC;AA0BF;;;GAGG;AACH,qBAAa,8BAA8B;;IAmXzC,YACE,aAAa,EAAE,wBAAwB,EACvC,aAAa,EAAE,kBAAkB,EACjC,oBAAoB,EAAE,yBAAyB,EAC/C,WAAW,CAAC,EAAE,OAAO,EACrB,WAAW,CAAC,EAAE,MAAM,EAAE,EACtB,gBAAgB,CAAC,EAAE,MAAM,EAAE,EAC3B,gBAAgB,CAAC,EAAE,MAAM,EAAE,EAC3B,mBAAmB,CAAC,EAAE,MAAM,EAC5B,mBAAmB,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC,EAa9C;IAwMD;;;;;;;;OAQG;IACI,eAAe,CACpB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE;QACJ,QAAQ,EAAE;YACR,IAAI,EAAE,MAAM,CAAC;YACb,UAAU,EAAE,MAAM,CA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;CACF"}
1
+ {"version":3,"file":"HyperLiquidSubscriptionService.d.ts","sourceRoot":"","sources":["../../src/services/HyperLiquidSubscriptionService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,KAAK,EAMV,mBAAmB,EAEnB,sBAAsB,EAItB,gBAAgB,EAMjB,MAAM,qBAAqB,CAAC;AAO7B,OAAO,KAAK,EAEV,0BAA0B,EAC3B,MAAM,+BAA+B,CAAC;AAGvC,OAAO,KAAK,EAEV,QAAQ,EACR,SAAS,EACT,KAAK,EAEL,SAAS,EACT,qBAAqB,EACrB,wBAAwB,EACxB,yBAAyB,EACzB,qBAAqB,EACrB,yBAAyB,EACzB,sBAAsB,EACtB,qBAAqB,EACrB,wBAAwB,EAGxB,yBAAyB,EAG1B,MAAM,mBAAmB,CAAC;AAgC3B,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAC9E,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAE9E;;;GAGG;AACH,KAAK,kBAAkB,GAAG,IAAI,CAC5B,wBAAwB,EACxB,qBAAqB,GAAG,2BAA2B,CACpD,CAAC;AA0BF;;;GAGG;AACH,qBAAa,8BAA8B;;IA2XzC,YACE,aAAa,EAAE,wBAAwB,EACvC,aAAa,EAAE,kBAAkB,EACjC,oBAAoB,EAAE,yBAAyB,EAC/C,WAAW,CAAC,EAAE,OAAO,EACrB,WAAW,CAAC,EAAE,MAAM,EAAE,EACtB,gBAAgB,CAAC,EAAE,MAAM,EAAE,EAC3B,gBAAgB,CAAC,EAAE,MAAM,EAAE,EAC3B,mBAAmB,CAAC,EAAE,MAAM,EAC5B,mBAAmB,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC,EAa9C;IAwMD;;;;;;;;OAQG;IACI,eAAe,CACpB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE;QACJ,QAAQ,EAA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ACxC,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,CAAC,EAAE,aAAa,CAAC;QAC1B,QAAQ,EAAE,CAAC,IAAI,EAAE,sBAAsB,KAAK,IAAI,CAAC;QACjD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;KAClC,GAAG,MAAM,IAAI,CA0Fb;IAsJD;;;;;;OAMG;IACU,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC,CAuQjD;IAED;;OAEG;IACI,QAAQ,IAAI,IAAI,CAsPtB;CACF"}
@@ -84,6 +84,10 @@ export class HyperLiquidSubscriptionService {
84
84
  // assetCtxs can serve prices again until a fresh snapshot arrives.
85
85
  #fastAssetCtxsCoins = new Set();
86
86
  #globalActiveAssetSubscriptions = new Map();
87
+ // Per-caller activeAssetData streams (available to trade). The service owns
88
+ // them so restoreSubscriptions() can reopen them on a replacement transport
89
+ // and clearAll() can retire pending and open ones.
90
+ #activeAssetDataStreams = new Set();
87
91
  // Track in-progress activeAssetCtx subscription promises to prevent leaks
88
92
  // when cleanup fires before the async subscription resolves (#28141)
89
93
  #pendingActiveAssetPromises = new Map();
@@ -3448,6 +3452,86 @@ export class HyperLiquidSubscriptionService {
3448
3452
  }
3449
3453
  };
3450
3454
  }
3455
+ /**
3456
+ * Stream the venue's `activeAssetData` for one account and market. Each
3457
+ * caller gets its own venue subscription, which restoreSubscriptions()
3458
+ * reopens on a replacement transport and clearAll() retires. The venue
3459
+ * pushes a new frame when the market's position, leverage or mark price
3460
+ * changes.
3461
+ *
3462
+ * @param params - Subscription parameters.
3463
+ * @param params.symbol - Market symbol, including any DEX prefix.
3464
+ * @param params.accountId - Optional CAIP account ID; defaults to the selected account.
3465
+ * @param params.callback - Receives each frame for this account and market.
3466
+ * @param params.onError - Receives a failure to open the subscription.
3467
+ * @returns Cleanup function to unsubscribe.
3468
+ */
3469
+ subscribeToActiveAssetData(params) {
3470
+ const { symbol, accountId, callback, onError } = params;
3471
+ let subscription;
3472
+ let retired = false;
3473
+ // Bumped on every (re)open: a pending or open attempt from an older
3474
+ // transport, or one that was retired, drops its frames and subscription.
3475
+ let attempt = 0;
3476
+ const unsubscribe = (sub) => {
3477
+ sub.unsubscribe().catch((error) => {
3478
+ this.#logErrorUnlessClearing(ensureError(error, 'HyperLiquidSubscriptionService.subscribeToActiveAssetData'), this.#getErrorContext('subscribeToActiveAssetData.unsubscribe', {
3479
+ symbol,
3480
+ }));
3481
+ });
3482
+ };
3483
+ const open = () => {
3484
+ attempt += 1;
3485
+ const thisAttempt = attempt;
3486
+ const isCurrent = () => !retired && thisAttempt === attempt;
3487
+ // On reopen the previous subscription belongs to the closed transport.
3488
+ subscription = undefined;
3489
+ (async () => {
3490
+ await this.#clientService.ensureSubscriptionClient(this.#walletService.createWalletAdapter());
3491
+ const subscriptionClient = this.#clientService.getSubscriptionClient();
3492
+ if (!subscriptionClient) {
3493
+ throw new Error('Subscription client not available');
3494
+ }
3495
+ const user = await this.#walletService.getUserAddressWithDefault(accountId);
3496
+ if (!isCurrent()) {
3497
+ return;
3498
+ }
3499
+ const sub = await subscriptionClient.activeAssetData({ user, coin: symbol }, (data) => {
3500
+ if (!isCurrent() ||
3501
+ data.coin !== symbol ||
3502
+ data.user.toLowerCase() !== user.toLowerCase()) {
3503
+ return;
3504
+ }
3505
+ callback(data);
3506
+ });
3507
+ if (!isCurrent()) {
3508
+ unsubscribe(sub);
3509
+ return;
3510
+ }
3511
+ subscription = sub;
3512
+ })().catch((error) => {
3513
+ const safeError = ensureError(error, 'HyperLiquidSubscriptionService.subscribeToActiveAssetData');
3514
+ this.#logErrorUnlessClearing(safeError, this.#getErrorContext('subscribeToActiveAssetData', { symbol }));
3515
+ if (isCurrent()) {
3516
+ onError?.(safeError);
3517
+ }
3518
+ });
3519
+ };
3520
+ const stream = {
3521
+ reopen: open,
3522
+ retire: () => {
3523
+ retired = true;
3524
+ this.#activeAssetDataStreams.delete(stream);
3525
+ if (subscription) {
3526
+ unsubscribe(subscription);
3527
+ subscription = undefined;
3528
+ }
3529
+ },
3530
+ };
3531
+ this.#activeAssetDataStreams.add(stream);
3532
+ open();
3533
+ return stream.retire;
3534
+ }
3451
3535
  /**
3452
3536
  * Process raw L2Book data into OrderBookData format
3453
3537
  * Calculates cumulative totals, notional values, and spread metrics
@@ -3670,6 +3754,9 @@ export class HyperLiquidSubscriptionService {
3670
3754
  });
3671
3755
  }));
3672
3756
  }
3757
+ // Reopen activeAssetData streams on the replacement transport. A failure
3758
+ // reaches the caller's onError.
3759
+ this.#activeAssetDataStreams.forEach((stream) => stream.reopen());
3673
3760
  // Re-establish user data subscriptions if there are user data subscribers
3674
3761
  if (this.#positionSubscribers.size > 0 ||
3675
3762
  this.#orderSubscribers.size > 0 ||
@@ -3812,6 +3899,9 @@ export class HyperLiquidSubscriptionService {
3812
3899
  this.#accountSubscribers.clear();
3813
3900
  this.#marketDataSubscribers.clear();
3814
3901
  this.#orderBookSubscribers.clear();
3902
+ // Retire activeAssetData streams: pending opens drop their subscription
3903
+ // and open ones stop delivering frames.
3904
+ this.#activeAssetDataStreams.forEach((stream) => stream.retire());
3815
3905
  // Clear order fill subscriptions; generations were bumped above.
3816
3906
  this.#orderFillSubscriptions.forEach((subscription) => {
3817
3907
  subscription.unsubscribe().catch(() => {