Skip to content

Commit 93bd559

Browse files
committed
fix(perps-controller): rebuild allMids baseline for fastAssetCtxs coins in assetCtxs handler (TAT-3387)
1 parent 06e81f9 commit 93bd559

1 file changed

Lines changed: 23 additions & 8 deletions

File tree

packages/perps-controller/src/services/HyperLiquidSubscriptionService.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3653,15 +3653,30 @@ export class HyperLiquidSubscriptionService {
36533653
this.#marketDataCache.set(asset.name, marketData);
36543654

36553655
// HIP-3: Extract price from assetCtx and update cached prices.
3656-
// Skip symbols fastAssetCtxs already covers (TAT-3387 owns their
3657-
// price path with fresher, ~5s-cadence data); assetCtxs remains
3658-
// the price source only for symbols outside fastAssetCtxs'
3659-
// coverage, e.g. HIP-3 dex:SYMBOL assets.
3656+
// For HIP-3 DEXs, meta() returns asset.name already containing the
3657+
// DEX prefix (e.g., "xyz:XYZ100"), so use it directly.
3658+
const symbol = asset.name;
36603659
const price = ctx.midPx?.toString() ?? ctx.markPx?.toString();
3661-
if (price && !this.#fastAssetCtxsCoins.has(asset.name)) {
3662-
// For HIP-3 DEXs, meta() returns asset.name already containing the DEX prefix
3663-
// (e.g., "xyz:XYZ100"), so use it directly
3664-
const symbol = asset.name;
3660+
if (this.#fastAssetCtxsCoins.has(symbol)) {
3661+
// fastAssetCtxs (TAT-3387) owns the price string for this coin
3662+
// with fresher, ~5s-cadence data, so don't overwrite it with
3663+
// this batch's price. Still rebuild the baseline (keeping the
3664+
// existing price) so derived fields just refreshed above in
3665+
// #marketDataCache (funding, openInterest, volume24h,
3666+
// oraclePrice, percentChange24h/isTradable via markPrice) reach
3667+
// list subscribers instead of going stale until the next
3668+
// fastAssetCtxs/allMids price change. Only rebuild an existing
3669+
// baseline to preserve the startup zero-price guard: we never
3670+
// want to synthesize a baseline from a '0' / absent allMids
3671+
// price.
3672+
const existingBaseline = this.#cachedPriceData?.get(symbol);
3673+
if (this.#cachedPriceData && existingBaseline) {
3674+
this.#cachedPriceData.set(
3675+
symbol,
3676+
this.#createPriceUpdate(symbol, existingBaseline.price),
3677+
);
3678+
}
3679+
} else if (price) {
36653680
const priceUpdate = this.#createPriceUpdate(symbol, price);
36663681
this.#cachedPriceData ??= new Map<string, PriceUpdate>();
36673682
this.#cachedPriceData.set(symbol, priceUpdate);

0 commit comments

Comments
 (0)