@metamask-previews/perps-controller 22.3.0-preview-a2a3d82 → 22.3.0-preview-13e241f7f
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.
- package/CHANGELOG.md +0 -31
- package/dist/PerpsController-method-action-types.d.ts +1 -19
- package/dist/PerpsController-method-action-types.d.ts.map +1 -1
- package/dist/PerpsController-method-action-types.js.map +1 -1
- package/dist/PerpsController.d.ts +1 -16
- package/dist/PerpsController.d.ts.map +1 -1
- package/dist/PerpsController.js +0 -32
- package/dist/PerpsController.js.map +1 -1
- package/dist/constants/perpsConfig.d.ts +0 -16
- package/dist/constants/perpsConfig.d.ts.map +1 -1
- package/dist/constants/perpsConfig.js +0 -24
- package/dist/constants/perpsConfig.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/providers/AggregatedPerpsProvider.d.ts +1 -10
- package/dist/providers/AggregatedPerpsProvider.d.ts.map +1 -1
- package/dist/providers/AggregatedPerpsProvider.js +0 -20
- package/dist/providers/AggregatedPerpsProvider.js.map +1 -1
- package/dist/providers/HyperLiquidProvider.d.ts +1 -10
- package/dist/providers/HyperLiquidProvider.d.ts.map +1 -1
- package/dist/providers/HyperLiquidProvider.js +0 -20
- package/dist/providers/HyperLiquidProvider.js.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.d.ts +1 -22
- package/dist/services/HyperLiquidSubscriptionService.d.ts.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.js +0 -90
- package/dist/services/HyperLiquidSubscriptionService.js.map +1 -1
- package/dist/types/index.d.ts +0 -43
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/utils/perpsFormatters.d.ts +53 -125
- package/dist/utils/perpsFormatters.d.ts.map +1 -1
- package/dist/utils/perpsFormatters.js +202 -345
- package/dist/utils/perpsFormatters.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { TwapHistoryResponse, ActiveAssetDataWsEvent, AssetCtxsWsEvent } from '@nktkas/hyperliquid';
|
|
1
|
+
import type { TwapHistoryResponse, AssetCtxsWsEvent } from '@nktkas/hyperliquid';
|
|
3
2
|
import type { HyperLiquidAbstractionMode } from '../types/hyperliquid-types.js';
|
|
4
3
|
import type { Position, OrderFill, Order, TwapOrder, SubscribePricesParams, SubscribePositionsParams, SubscribeOrderFillsParams, SubscribeOrdersParams, SubscribeTwapOrdersParams, SubscribeAccountParams, SubscribeOICapsParams, SubscribeOrderBookParams, PerpsPlatformDependencies } from '../types/index.js';
|
|
5
4
|
import type { HyperLiquidClientService } from './HyperLiquidClientService.js';
|
|
@@ -255,26 +254,6 @@ export declare class HyperLiquidSubscriptionService {
|
|
|
255
254
|
* @returns Cleanup function to unsubscribe
|
|
256
255
|
*/
|
|
257
256
|
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;
|
|
278
257
|
/**
|
|
279
258
|
* Restore all active subscriptions after WebSocket reconnection
|
|
280
259
|
* 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":"
|
|
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,mBAA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,IAAI,SAAS,EAAE,GAAG,IAAI,CAKtD;IAilCD;;;;;;;OAOG;IACI,oBAAoB,CAAC,MAAM,EAAE,wBAAwB,GAAG,MAAM,IAAI,CAiGxE;IAsJD;;;;;;OAMG;IACU,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC,CAmQjD;IAED;;OAEG;IACI,QAAQ,IAAI,IAAI,CAkPtB;CACF"}
|
|
@@ -84,10 +84,6 @@ 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();
|
|
91
87
|
// Track in-progress activeAssetCtx subscription promises to prevent leaks
|
|
92
88
|
// when cleanup fires before the async subscription resolves (#28141)
|
|
93
89
|
#pendingActiveAssetPromises = new Map();
|
|
@@ -3452,86 +3448,6 @@ export class HyperLiquidSubscriptionService {
|
|
|
3452
3448
|
}
|
|
3453
3449
|
};
|
|
3454
3450
|
}
|
|
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
|
-
}
|
|
3535
3451
|
/**
|
|
3536
3452
|
* Process raw L2Book data into OrderBookData format
|
|
3537
3453
|
* Calculates cumulative totals, notional values, and spread metrics
|
|
@@ -3754,9 +3670,6 @@ export class HyperLiquidSubscriptionService {
|
|
|
3754
3670
|
});
|
|
3755
3671
|
}));
|
|
3756
3672
|
}
|
|
3757
|
-
// Reopen activeAssetData streams on the replacement transport. A failure
|
|
3758
|
-
// reaches the caller's onError.
|
|
3759
|
-
this.#activeAssetDataStreams.forEach((stream) => stream.reopen());
|
|
3760
3673
|
// Re-establish user data subscriptions if there are user data subscribers
|
|
3761
3674
|
if (this.#positionSubscribers.size > 0 ||
|
|
3762
3675
|
this.#orderSubscribers.size > 0 ||
|
|
@@ -3899,9 +3812,6 @@ export class HyperLiquidSubscriptionService {
|
|
|
3899
3812
|
this.#accountSubscribers.clear();
|
|
3900
3813
|
this.#marketDataSubscribers.clear();
|
|
3901
3814
|
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());
|
|
3905
3815
|
// Clear order fill subscriptions; generations were bumped above.
|
|
3906
3816
|
this.#orderFillSubscriptions.forEach((subscription) => {
|
|
3907
3817
|
subscription.unsubscribe().catch(() => {
|