@lightconexyz/lightcone-sdk 0.8.1 → 0.8.2

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 (95) hide show
  1. package/README.md +150 -3
  2. package/dist/auth/client.d.ts +17 -1
  3. package/dist/auth/client.d.ts.map +1 -1
  4. package/dist/auth/client.js +68 -0
  5. package/dist/auth/client.js.map +1 -1
  6. package/dist/auth/index.d.ts +57 -5
  7. package/dist/auth/index.d.ts.map +1 -1
  8. package/dist/auth/index.js +26 -5
  9. package/dist/auth/index.js.map +1 -1
  10. package/dist/client.d.ts +23 -1
  11. package/dist/client.d.ts.map +1 -1
  12. package/dist/client.js +38 -2
  13. package/dist/client.js.map +1 -1
  14. package/dist/context.d.ts +23 -2
  15. package/dist/context.d.ts.map +1 -1
  16. package/dist/context.js +238 -17
  17. package/dist/context.js.map +1 -1
  18. package/dist/domain/market/outcome.d.ts +9 -3
  19. package/dist/domain/market/outcome.d.ts.map +1 -1
  20. package/dist/domain/market/outcome.js +10 -7
  21. package/dist/domain/market/outcome.js.map +1 -1
  22. package/dist/domain/market/wire.d.ts +3 -3
  23. package/dist/domain/market/wire.d.ts.map +1 -1
  24. package/dist/domain/market/wire.js.map +1 -1
  25. package/dist/domain/orderbook/wire.d.ts +5 -0
  26. package/dist/domain/orderbook/wire.d.ts.map +1 -1
  27. package/dist/domain/orderbook/wire.js.map +1 -1
  28. package/dist/domain/position/client.d.ts +160 -4
  29. package/dist/domain/position/client.d.ts.map +1 -1
  30. package/dist/domain/position/client.js +592 -4
  31. package/dist/domain/position/client.js.map +1 -1
  32. package/dist/domain/position/index.d.ts +54 -3
  33. package/dist/domain/position/index.d.ts.map +1 -1
  34. package/dist/domain/position/index.js +1 -0
  35. package/dist/domain/position/index.js.map +1 -1
  36. package/dist/domain/position/state.d.ts +118 -0
  37. package/dist/domain/position/state.d.ts.map +1 -0
  38. package/dist/domain/position/state.js +262 -0
  39. package/dist/domain/position/state.js.map +1 -0
  40. package/dist/error.d.ts +8 -2
  41. package/dist/error.d.ts.map +1 -1
  42. package/dist/error.js +14 -1
  43. package/dist/error.js.map +1 -1
  44. package/dist/index.d.ts +4 -3
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +3 -1
  47. package/dist/index.js.map +1 -1
  48. package/dist/prelude.d.ts +6 -5
  49. package/dist/prelude.d.ts.map +1 -1
  50. package/dist/prelude.js +10 -1
  51. package/dist/prelude.js.map +1 -1
  52. package/dist/privy/client.d.ts +4 -0
  53. package/dist/privy/client.d.ts.map +1 -1
  54. package/dist/privy/client.js +4 -0
  55. package/dist/privy/client.js.map +1 -1
  56. package/dist/rpc.d.ts +46 -1
  57. package/dist/rpc.d.ts.map +1 -1
  58. package/dist/rpc.js +125 -0
  59. package/dist/rpc.js.map +1 -1
  60. package/dist/shared/api_response.d.ts +7 -0
  61. package/dist/shared/api_response.d.ts.map +1 -1
  62. package/dist/shared/api_response.js +16 -0
  63. package/dist/shared/api_response.js.map +1 -1
  64. package/dist/shared/index.d.ts +1 -1
  65. package/dist/shared/index.d.ts.map +1 -1
  66. package/dist/shared/index.js +2 -1
  67. package/dist/shared/index.js.map +1 -1
  68. package/dist/shared/signing.d.ts +17 -0
  69. package/dist/shared/signing.d.ts.map +1 -1
  70. package/dist/shared/signing.js +27 -0
  71. package/dist/shared/signing.js.map +1 -1
  72. package/dist/shared/types.d.ts +3 -1
  73. package/dist/shared/types.d.ts.map +1 -1
  74. package/dist/shared/types.js +12 -4
  75. package/dist/shared/types.js.map +1 -1
  76. package/dist/ws/client.browser.d.ts +4 -0
  77. package/dist/ws/client.browser.d.ts.map +1 -1
  78. package/dist/ws/client.browser.js +13 -1
  79. package/dist/ws/client.browser.js.map +1 -1
  80. package/dist/ws/client.node.d.ts +4 -0
  81. package/dist/ws/client.node.d.ts.map +1 -1
  82. package/dist/ws/client.node.js +13 -1
  83. package/dist/ws/client.node.js.map +1 -1
  84. package/dist/ws/index.d.ts +24 -0
  85. package/dist/ws/index.d.ts.map +1 -1
  86. package/dist/ws/index.js +162 -1
  87. package/dist/ws/index.js.map +1 -1
  88. package/dist/ws/subscriptions.d.ts +12 -1
  89. package/dist/ws/subscriptions.d.ts.map +1 -1
  90. package/dist/ws/subscriptions.js +11 -0
  91. package/dist/ws/subscriptions.js.map +1 -1
  92. package/dist/ws/types.d.ts +5 -0
  93. package/dist/ws/types.d.ts.map +1 -1
  94. package/dist/ws/types.js.map +1 -1
  95. package/package.json +2 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ws/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAuB,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC7F,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EACV,sBAAsB,EACtB,YAAY,EACZ,YAAY,EACb,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAG/C,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAGpE,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC,MAAM,MAAM,UAAU,GAClB;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,MAAM,EAAE,OAAO,iBAAiB,EAAE,eAAe,CAAA;CAAE,GAC1E;IAAE,MAAM,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,OAAO,iBAAiB,EAAE,iBAAiB,CAAA;CAAE,GAC9E;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvB,M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E;AAED,wBAAgB,4BAA4B,CAAC,YAAY,EAAE,MAAM,GAAG,UAAU,CAK7E;AAiBD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CA6DvD"}
package/dist/ws/index.js CHANGED
@@ -23,6 +23,8 @@ exports.subscribeTrades = subscribeTrades;
23
23
  exports.unsubscribeTrades = unsubscribeTrades;
24
24
  exports.subscribeUser = subscribeUser;
25
25
  exports.unsubscribeUser = unsubscribeUser;
26
+ exports.subscribeWalletDepositBalances = subscribeWalletDepositBalances;
27
+ exports.unsubscribeWalletDepositBalances = unsubscribeWalletDepositBalances;
26
28
  exports.subscribePriceHistory = subscribePriceHistory;
27
29
  exports.unsubscribePriceHistory = unsubscribePriceHistory;
28
30
  exports.subscribeTicker = subscribeTicker;
@@ -148,6 +150,33 @@ function unsubscribeUser(walletAddress) {
148
150
  },
149
151
  };
150
152
  }
153
+ /**
154
+ * Subscribe to a wallet owned by the authenticated user.
155
+ * The channel begins with a complete replacement snapshot and then emits
156
+ * absolute SPL/native updates plus non-mutating status events.
157
+ */
158
+ function subscribeWalletDepositBalances(walletAddress) {
159
+ return {
160
+ method: "subscribe",
161
+ params: {
162
+ type: "wallet_deposit_balances",
163
+ wallet_address: walletAddress,
164
+ },
165
+ };
166
+ }
167
+ /**
168
+ * Stop the authenticated wallet stream identified by this exact wallet address.
169
+ * This wire operation is separate from clearing local reconnect tracking.
170
+ */
171
+ function unsubscribeWalletDepositBalances(walletAddress) {
172
+ return {
173
+ method: "unsubscribe",
174
+ params: {
175
+ type: "wallet_deposit_balances",
176
+ wallet_address: walletAddress,
177
+ },
178
+ };
179
+ }
151
180
  function subscribePriceHistory(orderbookId, resolution) {
152
181
  return {
153
182
  method: "subscribe",
@@ -254,7 +283,15 @@ const VALID_MESSAGE_TYPES = new Set([
254
283
  "market",
255
284
  "deposit_price",
256
285
  "deposit_asset_price",
286
+ "wallet_deposit_balances",
257
287
  ]);
288
+ /**
289
+ * Parse and normalize one inbound frame.
290
+ *
291
+ * Wallet-balance payloads cross a runtime validation boundary here: malformed
292
+ * nested discriminators, exact values, or slots throw a protocol `WsError`
293
+ * instead of escaping behind TypeScript-only types.
294
+ */
258
295
  function parseMessageIn(input) {
259
296
  const parsed = (0, json_1.parseJsonExact)(input);
260
297
  if (typeof parsed !== "object" || parsed === null || !("type" in parsed)) {
@@ -272,12 +309,28 @@ function parseMessageIn(input) {
272
309
  }
273
310
  let message = parsed;
274
311
  if (message.type === "book_update") {
275
- const seq = message.data.seq;
312
+ const data = message.data;
313
+ const seq = data.seq;
276
314
  if ((typeof seq !== "number" && typeof seq !== "bigint") ||
277
315
  (typeof seq === "number" && (!Number.isSafeInteger(seq) || seq < 0)) ||
278
316
  (typeof seq === "bigint" && seq < 0n)) {
279
317
  throw new error_1.WsError("ProtocolError", "Invalid book_update seq");
280
318
  }
319
+ // Validate only populated level arrays so existing empty/resync frame
320
+ // tolerance is unchanged while exact quote liquidity cannot be omitted.
321
+ for (const side of ["bids", "asks"]) {
322
+ const levels = data[side];
323
+ if (!Array.isArray(levels))
324
+ continue;
325
+ for (const level of levels) {
326
+ if (typeof level !== "object" ||
327
+ level === null ||
328
+ Array.isArray(level) ||
329
+ typeof level.quote_notional !== "string") {
330
+ throw new error_1.WsError("ProtocolError", `Invalid book_update ${side} level: missing or invalid quote_notional`);
331
+ }
332
+ }
333
+ }
281
334
  message = {
282
335
  ...message,
283
336
  data: { ...message.data, seq: BigInt(seq) },
@@ -289,6 +342,114 @@ function parseMessageIn(input) {
289
342
  data: (0, wire_1.normalizeUserUpdate)(message.data),
290
343
  };
291
344
  }
345
+ if (message.type === "wallet_deposit_balances") {
346
+ return {
347
+ ...message,
348
+ data: normalizeWalletDepositBalancesEvent(message.data),
349
+ };
350
+ }
292
351
  return message;
293
352
  }
353
+ /** Validate the nested wallet event before exposing its discriminated union. */
354
+ function normalizeWalletDepositBalancesEvent(input) {
355
+ const data = requireObject(input, "wallet_deposit_balances data");
356
+ const eventType = requireString(data, "event_type");
357
+ const walletAddress = requireString(data, "wallet_address");
358
+ switch (eventType) {
359
+ case "wallet_deposit_balance_snapshot": {
360
+ const rawBalances = requireObject(data.balances, "balances");
361
+ const balances = {};
362
+ for (const [mint, balance] of Object.entries(rawBalances)) {
363
+ balances[mint] = normalizeDepositTokenBalance(balance);
364
+ }
365
+ return {
366
+ event_type: eventType,
367
+ wallet_address: walletAddress,
368
+ context_slot: requireContextSlot(data),
369
+ balances,
370
+ native_sol_balance: requireNativeSolBalance(data),
371
+ };
372
+ }
373
+ case "wallet_deposit_balance_update":
374
+ return {
375
+ event_type: eventType,
376
+ wallet_address: walletAddress,
377
+ context_slot: requireContextSlot(data),
378
+ balance: normalizeDepositTokenBalance(data.balance),
379
+ };
380
+ case "wallet_native_sol_balance_update":
381
+ return {
382
+ event_type: eventType,
383
+ wallet_address: walletAddress,
384
+ context_slot: requireContextSlot(data),
385
+ native_sol_balance: requireNativeSolBalance(data),
386
+ };
387
+ case "wallet_deposit_balance_status": {
388
+ const status = requireString(data, "status");
389
+ if (status !== "reconnecting" && status !== "metadata_unavailable") {
390
+ throw protocolError(`Invalid wallet balance status: "${status}"`);
391
+ }
392
+ return {
393
+ event_type: eventType,
394
+ wallet_address: walletAddress,
395
+ status,
396
+ code: requireString(data, "code"),
397
+ };
398
+ }
399
+ default:
400
+ throw protocolError(`Invalid wallet balance event type: "${eventType}"`);
401
+ }
402
+ }
403
+ /** Preserve exact strings and nullable icons while rejecting incomplete balances. */
404
+ function normalizeDepositTokenBalance(input) {
405
+ const balance = requireObject(input, "deposit-token balance");
406
+ const normalized = {
407
+ mint: requireString(balance, "mint"),
408
+ idle: requireString(balance, "idle"),
409
+ symbol: requireString(balance, "symbol"),
410
+ name: requireString(balance, "name"),
411
+ };
412
+ for (const field of ["icon_url_low", "icon_url_medium", "icon_url_high"]) {
413
+ const value = balance[field];
414
+ if (value !== undefined) {
415
+ if (value !== null && typeof value !== "string") {
416
+ throw protocolError(`Invalid deposit-token balance ${field}`);
417
+ }
418
+ normalized[field] = value;
419
+ }
420
+ }
421
+ return normalized;
422
+ }
423
+ function requireObject(input, field) {
424
+ if (typeof input !== "object" || input === null || Array.isArray(input)) {
425
+ throw protocolError(`Invalid ${field}: expected object`);
426
+ }
427
+ return input;
428
+ }
429
+ function requireString(data, field) {
430
+ const value = data[field];
431
+ if (typeof value !== "string") {
432
+ throw protocolError(`Invalid wallet balance ${field}: expected string`);
433
+ }
434
+ return value;
435
+ }
436
+ function requireNativeSolBalance(data) {
437
+ // Canonical nine-place syntax maps directly to lamports without rounding or exponents.
438
+ const value = requireString(data, "native_sol_balance");
439
+ if (!/^(?:0|[1-9][0-9]*)\.[0-9]{9}$/.test(value)) {
440
+ throw protocolError("Invalid wallet balance native_sol_balance: expected exactly nine decimal places");
441
+ }
442
+ return value;
443
+ }
444
+ function requireContextSlot(data) {
445
+ // Safe integers prevent precision loss when state compares JavaScript slots.
446
+ const value = data.context_slot;
447
+ if (!Number.isSafeInteger(value) || value < 0) {
448
+ throw protocolError("Invalid wallet balance context_slot");
449
+ }
450
+ return value;
451
+ }
452
+ function protocolError(message) {
453
+ return new error_1.WsError("ProtocolError", message);
454
+ }
294
455
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ws/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AA6FA,wCAYC;AAED,oBAEC;AAYD,wCAeC;AAMD,4CAeC;AAED,0CAQC;AAED,8CAQC;AAED,sCAQC;AAED,0CAQC;AAED,sDAUC;AAED,0DASC;AAED,0CAQC;AAED,8CAQC;AAED,0CAQC;AAED,8CAQC;AAED,sDASC;AAED,0DASC;AAOD,gEAKC;AAED,oEAKC;AAgBD,wCAmCC;AA/VD,+CAA6F;AAE7F,iEAIyC;AAOzC,oCAAmD;AACnD,gCAA6C;AAE7C,yCAAgD;AAEhD,gDAA8B;AAC9B,kDAAgC;AAyDnB,QAAA,iBAAiB,GAA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sourcesContent":["import type { MarketEvent } from \"../domain/market\";\nimport { normalizeUserUpdate, type AuthUpdate, type UserUpdate } from \"../domain/order/wire\";\nimport type { OrderBook, WsTickerData } from \"../domain/orderbook\";\nimport {\n FULL_PRECISION,\n normalizeAggregation,\n type BookAggregation,\n} from \"../domain/orderbook/aggregation\";\nimport type {\n DepositAssetPriceEvent,\n DepositPrice,\n PriceHistory,\n} from \"../domain/price_history\";\nimport type { WsTrade } from \"../domain/trade\";\nimport { WsError as WsErrorClass } from \"../error\";\nimport { LightconeEnv, wsUrl } from \"../env\";\nimport type { OrderBookId, PubkeyStr, Resolution } from \"../shared\";\nimport { parseJsonExact } from \"../shared/json\";\n\nexport * from \"./client.node\";\nexport * from \"./subscriptions\";\nexport type { IWsClient } from \"./types\";\n\nexport type MessageOut =\n | { method: \"subscribe\"; params: import(\"./subscriptions\").SubscribeParams }\n | { method: \"unsubscribe\"; params: import(\"./subscriptions\").UnsubscribeParams }\n | { method: \"ping\" };\n\nexport type MessageIn =\n | { type: \"book_update\"; version: number; data: OrderBook }\n | { type: \"pong\"; version: number; data: Record<string, never> }\n | { type: \"user\"; version: number; data: UserUpdate }\n | { type: \"error\"; version: number; data: WsError }\n | { type: \"price_history\"; version: number; data: PriceHistory }\n | { type: \"trades\"; version: number; data: WsTrade }\n | { type: \"auth\"; version: number; data: AuthUpdate }\n | { type: \"ticker\"; version: number; data: WsTickerData }\n | { type: \"market\"; version: number; data: MarketEvent }\n | { type: \"deposit_price\"; version: number; data: DepositPrice }\n | { type: \"deposit_asset_price\"; version: number; data: DepositAssetPriceEvent };\n\nexport type Kind = MessageIn;\n\nexport interface WsError {\n error: string;\n code?: string;\n orderbook_id?: string;\n /**\n * Aggregation of the affected book subscription on book-scoped errors\n * (`ENGINE_UNAVAILABLE`, `SUBSCRIPTION_LIMIT_REACHED`,\n * `INVALID_ORDERBOOK_SUBSCRIPTION`). Absent = full precision; pass to\n * `aggregationFromFrame` to identify the `(orderbook, aggregation)` pair.\n */\n n_sig_figs?: number;\n mantissa?: number;\n wallet_address?: string;\n deposit_asset?: string;\n hint?: string;\n details?: string;\n}\n\nexport type WsEvent =\n | { type: \"Message\"; message: MessageIn }\n | { type: \"Connected\" }\n | { type: \"Disconnected\"; code?: number; reason: string }\n | { type: \"Error\"; error: string }\n | { type: \"MaxReconnectReached\" };\n\nexport interface WsConfig {\n url: string;\n reconnect: boolean;\n maxReconnectAttempts: number;\n baseReconnectDelayMs: number;\n pingIntervalMs: number;\n pongTimeoutMs: number;\n}\n\nexport const WS_DEFAULT_CONFIG: WsConfig = {\n url: wsUrl(LightconeEnv.Prod),\n reconnect: true,\n maxReconnectAttempts: 10,\n baseReconnectDelayMs: 1_000,\n pingIntervalMs: 30_000,\n pongTimeoutMs: 10_000,\n};\n\nexport enum ReadyState {\n Connecting = 0,\n Open = 1,\n Closing = 2,\n Closed = 3,\n}\n\nexport function readyStateFrom(value: number): ReadyState {\n switch (value) {\n case 0:\n return ReadyState.Connecting;\n case 1:\n return ReadyState.Open;\n case 2:\n return ReadyState.Closing;\n case 3:\n default:\n return ReadyState.Closed;\n }\n}\n\nexport function ping(): MessageOut {\n return { method: \"ping\" };\n}\n\n/**\n * Subscribe to book snapshots, optionally aggregated (Hyperliquid-style).\n *\n * Omit `aggregation` for the raw book. The aggregation is normalized before\n * sending ((5, none) → (5, 1)); validate with `validateAggregation` first —\n * invalid combinations are rejected server-side with\n * `INVALID_ORDERBOOK_SUBSCRIPTION`. `undefined` fields are dropped by\n * `JSON.stringify`, so full precision stays byte-identical to the\n * pre-aggregation message.\n */\nexport function subscribeBooks(\n orderbookIds: OrderBookId[],\n aggregation: BookAggregation = FULL_PRECISION\n): MessageOut {\n const sorted = [...orderbookIds].sort();\n const normalized = normalizeAggregation(aggregation);\n return {\n method: \"subscribe\",\n params: {\n type: \"book_update\",\n orderbook_ids: sorted,\n nSigFigs: normalized.nSigFigs,\n mantissa: normalized.mantissa,\n },\n };\n}\n\n/**\n * Unsubscribe a book subscription. The aggregation must match the one\n * subscribed (normalized) or the server removes nothing.\n */\nexport function unsubscribeBooks(\n orderbookIds: OrderBookId[],\n aggregation: BookAggregation = FULL_PRECISION\n): MessageOut {\n const sorted = [...orderbookIds].sort();\n const normalized = normalizeAggregation(aggregation);\n return {\n method: \"unsubscribe\",\n params: {\n type: \"book_update\",\n orderbook_ids: sorted,\n nSigFigs: normalized.nSigFigs,\n mantissa: normalized.mantissa,\n },\n };\n}\n\nexport function subscribeTrades(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"trades\",\n orderbook_ids: [...orderbookIds].sort(),\n },\n };\n}\n\nexport function unsubscribeTrades(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"trades\",\n orderbook_ids: [...orderbookIds].sort(),\n },\n };\n}\n\nexport function subscribeUser(walletAddress: PubkeyStr): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"user\",\n wallet_address: walletAddress,\n },\n };\n}\n\nexport function unsubscribeUser(walletAddress: PubkeyStr): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"user\",\n wallet_address: walletAddress,\n },\n };\n}\n\nexport function subscribePriceHistory(orderbookId: OrderBookId, resolution: Resolution): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"price_history\",\n orderbook_id: orderbookId,\n resolution,\n include_ohlcv: false,\n },\n };\n}\n\nexport function unsubscribePriceHistory(orderbookId: OrderBookId, resolution: Resolution): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"price_history\",\n orderbook_id: orderbookId,\n resolution,\n },\n };\n}\n\nexport function subscribeTicker(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"ticker\",\n orderbook_ids: [...orderbookIds].sort(),\n },\n };\n}\n\nexport function unsubscribeTicker(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"ticker\",\n orderbook_ids: [...orderbookIds].sort(),\n },\n };\n}\n\nexport function subscribeMarket(marketPubkey: PubkeyStr): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"market\",\n market_pubkey: marketPubkey,\n },\n };\n}\n\nexport function unsubscribeMarket(marketPubkey: PubkeyStr): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"market\",\n market_pubkey: marketPubkey,\n },\n };\n}\n\nexport function subscribeDepositPrice(depositAsset: string, resolution: Resolution): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"deposit_price\",\n deposit_asset: depositAsset,\n resolution,\n },\n };\n}\n\nexport function unsubscribeDepositPrice(depositAsset: string, resolution: Resolution): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"deposit_price\",\n deposit_asset: depositAsset,\n resolution,\n },\n };\n}\n\n/**\n * Subscribe to the live spot price for one deposit asset (snapshot +\n * per-asset price ticks). Distinct from `subscribeDepositPrice`, which\n * carries OHLCV candles per resolution.\n */\nexport function subscribeDepositAssetPrice(depositAsset: string): MessageOut {\n return {\n method: \"subscribe\",\n params: { type: \"deposit_asset_price\", deposit_asset: depositAsset },\n };\n}\n\nexport function unsubscribeDepositAssetPrice(depositAsset: string): MessageOut {\n return {\n method: \"unsubscribe\",\n params: { type: \"deposit_asset_price\", deposit_asset: depositAsset },\n };\n}\n\nconst VALID_MESSAGE_TYPES = new Set([\n \"book_update\",\n \"pong\",\n \"user\",\n \"error\",\n \"price_history\",\n \"trades\",\n \"auth\",\n \"ticker\",\n \"market\",\n \"deposit_price\",\n \"deposit_asset_price\",\n]);\n\nexport function parseMessageIn(input: string): MessageIn {\n const parsed: unknown = parseJsonExact(input);\n if (typeof parsed !== \"object\" || parsed === null || !(\"type\" in parsed)) {\n throw new WsErrorClass(\"ProtocolError\", `Invalid WS message: missing \"type\" field`);\n }\n const obj = parsed as Record<string, unknown>;\n if (typeof obj.type !== \"string\" || !VALID_MESSAGE_TYPES.has(obj.type)) {\n throw new WsErrorClass(\"ProtocolError\", `Invalid WS message type: \"${String(obj.type)}\"`);\n }\n if (!(\"version\" in obj) || typeof obj.version !== \"number\") {\n throw new WsErrorClass(\"ProtocolError\", `Invalid WS message: missing or invalid \"version\" field`);\n }\n if (!(\"data\" in obj) || typeof obj.data !== \"object\" || obj.data === null) {\n throw new WsErrorClass(\"ProtocolError\", `Invalid WS message: missing or invalid \"data\" field`);\n }\n let message = parsed as MessageIn;\n if (message.type === \"book_update\") {\n const seq = (message.data as unknown as { seq?: number | bigint }).seq;\n if ((typeof seq !== \"number\" && typeof seq !== \"bigint\") ||\n (typeof seq === \"number\" && (!Number.isSafeInteger(seq) || seq < 0)) ||\n (typeof seq === \"bigint\" && seq < 0n)) {\n throw new WsErrorClass(\"ProtocolError\", \"Invalid book_update seq\");\n }\n message = {\n ...message,\n data: { ...message.data, seq: BigInt(seq) },\n };\n }\n if (message.type === \"user\") {\n return {\n ...message,\n data: normalizeUserUpdate(message.data as Parameters<typeof normalizeUserUpdate>[0]),\n };\n }\n return message;\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ws/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAuGA,wCAYC;AAED,oBAEC;AAYD,wCAeC;AAMD,4CAeC;AAED,0CAQC;AAED,8CAQC;AAED,sCAQC;AAED,0CAQC;AAOD,wEAUC;AAMD,4EAUC;AAED,sDAUC;AAED,0DASC;AAED,0CAQC;AAED,8CAQC;AAED,0CAQC;AAED,8CAQC;AAED,sDASC;AAED,0DASC;AAOD,gEAKC;AAED,oEAKC;AAwBD,wCA6DC;AA5aD,+CAA6F;AAE7F,iEAIyC;AAWzC,oCAAmD;AACnD,gCAA6C;AAE7C,yCAAgD;AAEhD,gDAA8B;AAC9B,kDAAgC;AA+DnB,QAAA,iBAAiB,GAAa;IACzC,GAAG,EAAE,IAAA,WAAK,EAAC,kBAAY,CAAC,IAAI,CAAC;IAC7B,SAAS,EAAE,IAAI;IACf,oBAAoB,EAAE,EAAE;IACxB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AC,WAAW,KAAK,mBAAmB,CAAC,CAAC;IAC3D,CAAC;IACD,OAAO,KAAgC,CAAC;AAC1C,CAAC;AAED,SAAS,aAAa,CAAC,IAA6B,EAAE,KAAa;IACjE,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;IAC1B,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,aAAa,CAAC,0BAA0B,KAAK,mBAAmB,CAAC,CAAC;IAC1E,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,uBAAuB,CAAC,IAA6B;IAC5D,uFAAuF;IACvF,MAAM,KAAK,GAAG,aAAa,CAAC,IAAI,EAAE,oBAAoB,CAAC,CAAC;IACxD,IAAI,CAAC,+BAA+B,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACjD,MAAM,aAAa,CACjB,iFAAiF,CAClF,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,kBAAkB,CAAC,IAA6B;IACvD,6EAA6E;IAC7E,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC;IAChC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAK,KAAgB,GAAG,CAAC,EAAE,CAAC;QAC1D,MAAM,aAAa,CAAC,qCAAqC,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,KAAe,CAAC;AACzB,CAAC;AAED,SAAS,aAAa,CAAC,OAAe;IACpC,OAAO,IAAI,eAAY,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;AACpD,CAAC","sourcesContent":["import type { MarketEvent } from \"../domain/market\";\nimport { normalizeUserUpdate, type AuthUpdate, type UserUpdate } from \"../domain/order/wire\";\nimport type { OrderBook, WsTickerData } from \"../domain/orderbook\";\nimport {\n FULL_PRECISION,\n normalizeAggregation,\n type BookAggregation,\n} from \"../domain/orderbook/aggregation\";\nimport type {\n DepositAssetPriceEvent,\n DepositPrice,\n PriceHistory,\n} from \"../domain/price_history\";\nimport type { WsTrade } from \"../domain/trade\";\nimport type {\n DepositTokenBalance,\n WalletDepositBalancesEvent,\n} from \"../domain/position\";\nimport { WsError as WsErrorClass } from \"../error\";\nimport { LightconeEnv, wsUrl } from \"../env\";\nimport type { OrderBookId, PubkeyStr, Resolution } from \"../shared\";\nimport { parseJsonExact } from \"../shared/json\";\n\nexport * from \"./client.node\";\nexport * from \"./subscriptions\";\nexport type { IWsClient } from \"./types\";\n\nexport type MessageOut =\n | { method: \"subscribe\"; params: import(\"./subscriptions\").SubscribeParams }\n | { method: \"unsubscribe\"; params: import(\"./subscriptions\").UnsubscribeParams }\n | { method: \"ping\" };\n\n/** Parsed inbound channel union; wallet balances contain a strict nested event union. */\nexport type MessageIn =\n | { type: \"book_update\"; version: number; data: OrderBook }\n | { type: \"pong\"; version: number; data: Record<string, never> }\n | { type: \"user\"; version: number; data: UserUpdate }\n | { type: \"error\"; version: number; data: WsError }\n | { type: \"price_history\"; version: number; data: PriceHistory }\n | { type: \"trades\"; version: number; data: WsTrade }\n | { type: \"auth\"; version: number; data: AuthUpdate }\n | { type: \"ticker\"; version: number; data: WsTickerData }\n | { type: \"market\"; version: number; data: MarketEvent }\n | { type: \"deposit_price\"; version: number; data: DepositPrice }\n | { type: \"deposit_asset_price\"; version: number; data: DepositAssetPriceEvent }\n | {\n type: \"wallet_deposit_balances\";\n version: number;\n data: WalletDepositBalancesEvent;\n };\n\nexport type Kind = MessageIn;\n\nexport interface WsError {\n error: string;\n code?: string;\n orderbook_id?: string;\n /**\n * Aggregation of the affected book subscription on book-scoped errors\n * (`ENGINE_UNAVAILABLE`, `SUBSCRIPTION_LIMIT_REACHED`,\n * `INVALID_ORDERBOOK_SUBSCRIPTION`). Absent = full precision; pass to\n * `aggregationFromFrame` to identify the `(orderbook, aggregation)` pair.\n */\n n_sig_figs?: number;\n mantissa?: number;\n wallet_address?: string;\n deposit_asset?: string;\n hint?: string;\n details?: string;\n}\n\nexport type WsEvent =\n | { type: \"Message\"; message: MessageIn }\n | { type: \"Connected\" }\n | { type: \"Disconnected\"; code?: number; reason: string }\n | { type: \"Error\"; error: string }\n | { type: \"MaxReconnectReached\" };\n\nexport interface WsConfig {\n url: string;\n reconnect: boolean;\n maxReconnectAttempts: number;\n baseReconnectDelayMs: number;\n pingIntervalMs: number;\n pongTimeoutMs: number;\n}\n\nexport const WS_DEFAULT_CONFIG: WsConfig = {\n url: wsUrl(LightconeEnv.Prod),\n reconnect: true,\n maxReconnectAttempts: 10,\n baseReconnectDelayMs: 1_000,\n pingIntervalMs: 30_000,\n pongTimeoutMs: 10_000,\n};\n\nexport enum ReadyState {\n Connecting = 0,\n Open = 1,\n Closing = 2,\n Closed = 3,\n}\n\nexport function readyStateFrom(value: number): ReadyState {\n switch (value) {\n case 0:\n return ReadyState.Connecting;\n case 1:\n return ReadyState.Open;\n case 2:\n return ReadyState.Closing;\n case 3:\n default:\n return ReadyState.Closed;\n }\n}\n\nexport function ping(): MessageOut {\n return { method: \"ping\" };\n}\n\n/**\n * Subscribe to book snapshots, optionally aggregated (Hyperliquid-style).\n *\n * Omit `aggregation` for the raw book. The aggregation is normalized before\n * sending ((5, none) → (5, 1)); validate with `validateAggregation` first —\n * invalid combinations are rejected server-side with\n * `INVALID_ORDERBOOK_SUBSCRIPTION`. `undefined` fields are dropped by\n * `JSON.stringify`, so full precision stays byte-identical to the\n * pre-aggregation message.\n */\nexport function subscribeBooks(\n orderbookIds: OrderBookId[],\n aggregation: BookAggregation = FULL_PRECISION\n): MessageOut {\n const sorted = [...orderbookIds].sort();\n const normalized = normalizeAggregation(aggregation);\n return {\n method: \"subscribe\",\n params: {\n type: \"book_update\",\n orderbook_ids: sorted,\n nSigFigs: normalized.nSigFigs,\n mantissa: normalized.mantissa,\n },\n };\n}\n\n/**\n * Unsubscribe a book subscription. The aggregation must match the one\n * subscribed (normalized) or the server removes nothing.\n */\nexport function unsubscribeBooks(\n orderbookIds: OrderBookId[],\n aggregation: BookAggregation = FULL_PRECISION\n): MessageOut {\n const sorted = [...orderbookIds].sort();\n const normalized = normalizeAggregation(aggregation);\n return {\n method: \"unsubscribe\",\n params: {\n type: \"book_update\",\n orderbook_ids: sorted,\n nSigFigs: normalized.nSigFigs,\n mantissa: normalized.mantissa,\n },\n };\n}\n\nexport function subscribeTrades(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"trades\",\n orderbook_ids: [...orderbookIds].sort(),\n },\n };\n}\n\nexport function unsubscribeTrades(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"trades\",\n orderbook_ids: [...orderbookIds].sort(),\n },\n };\n}\n\nexport function subscribeUser(walletAddress: PubkeyStr): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"user\",\n wallet_address: walletAddress,\n },\n };\n}\n\nexport function unsubscribeUser(walletAddress: PubkeyStr): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"user\",\n wallet_address: walletAddress,\n },\n };\n}\n\n/**\n * Subscribe to a wallet owned by the authenticated user.\n * The channel begins with a complete replacement snapshot and then emits\n * absolute SPL/native updates plus non-mutating status events.\n */\nexport function subscribeWalletDepositBalances(\n walletAddress: PubkeyStr\n): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"wallet_deposit_balances\",\n wallet_address: walletAddress,\n },\n };\n}\n\n/**\n * Stop the authenticated wallet stream identified by this exact wallet address.\n * This wire operation is separate from clearing local reconnect tracking.\n */\nexport function unsubscribeWalletDepositBalances(\n walletAddress: PubkeyStr\n): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"wallet_deposit_balances\",\n wallet_address: walletAddress,\n },\n };\n}\n\nexport function subscribePriceHistory(orderbookId: OrderBookId, resolution: Resolution): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"price_history\",\n orderbook_id: orderbookId,\n resolution,\n include_ohlcv: false,\n },\n };\n}\n\nexport function unsubscribePriceHistory(orderbookId: OrderBookId, resolution: Resolution): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"price_history\",\n orderbook_id: orderbookId,\n resolution,\n },\n };\n}\n\nexport function subscribeTicker(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"ticker\",\n orderbook_ids: [...orderbookIds].sort(),\n },\n };\n}\n\nexport function unsubscribeTicker(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"ticker\",\n orderbook_ids: [...orderbookIds].sort(),\n },\n };\n}\n\nexport function subscribeMarket(marketPubkey: PubkeyStr): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"market\",\n market_pubkey: marketPubkey,\n },\n };\n}\n\nexport function unsubscribeMarket(marketPubkey: PubkeyStr): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"market\",\n market_pubkey: marketPubkey,\n },\n };\n}\n\nexport function subscribeDepositPrice(depositAsset: string, resolution: Resolution): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"deposit_price\",\n deposit_asset: depositAsset,\n resolution,\n },\n };\n}\n\nexport function unsubscribeDepositPrice(depositAsset: string, resolution: Resolution): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"deposit_price\",\n deposit_asset: depositAsset,\n resolution,\n },\n };\n}\n\n/**\n * Subscribe to the live spot price for one deposit asset (snapshot +\n * per-asset price ticks). Distinct from `subscribeDepositPrice`, which\n * carries OHLCV candles per resolution.\n */\nexport function subscribeDepositAssetPrice(depositAsset: string): MessageOut {\n return {\n method: \"subscribe\",\n params: { type: \"deposit_asset_price\", deposit_asset: depositAsset },\n };\n}\n\nexport function unsubscribeDepositAssetPrice(depositAsset: string): MessageOut {\n return {\n method: \"unsubscribe\",\n params: { type: \"deposit_asset_price\", deposit_asset: depositAsset },\n };\n}\n\nconst VALID_MESSAGE_TYPES = new Set([\n \"book_update\",\n \"pong\",\n \"user\",\n \"error\",\n \"price_history\",\n \"trades\",\n \"auth\",\n \"ticker\",\n \"market\",\n \"deposit_price\",\n \"deposit_asset_price\",\n \"wallet_deposit_balances\",\n]);\n\n/**\n * Parse and normalize one inbound frame.\n *\n * Wallet-balance payloads cross a runtime validation boundary here: malformed\n * nested discriminators, exact values, or slots throw a protocol `WsError`\n * instead of escaping behind TypeScript-only types.\n */\nexport function parseMessageIn(input: string): MessageIn {\n const parsed: unknown = parseJsonExact(input);\n if (typeof parsed !== \"object\" || parsed === null || !(\"type\" in parsed)) {\n throw new WsErrorClass(\"ProtocolError\", `Invalid WS message: missing \"type\" field`);\n }\n const obj = parsed as Record<string, unknown>;\n if (typeof obj.type !== \"string\" || !VALID_MESSAGE_TYPES.has(obj.type)) {\n throw new WsErrorClass(\"ProtocolError\", `Invalid WS message type: \"${String(obj.type)}\"`);\n }\n if (!(\"version\" in obj) || typeof obj.version !== \"number\") {\n throw new WsErrorClass(\"ProtocolError\", `Invalid WS message: missing or invalid \"version\" field`);\n }\n if (!(\"data\" in obj) || typeof obj.data !== \"object\" || obj.data === null) {\n throw new WsErrorClass(\"ProtocolError\", `Invalid WS message: missing or invalid \"data\" field`);\n }\n let message = parsed as MessageIn;\n if (message.type === \"book_update\") {\n const data = message.data as unknown as Record<string, unknown>;\n const seq = data.seq;\n if ((typeof seq !== \"number\" && typeof seq !== \"bigint\") ||\n (typeof seq === \"number\" && (!Number.isSafeInteger(seq) || seq < 0)) ||\n (typeof seq === \"bigint\" && seq < 0n)) {\n throw new WsErrorClass(\"ProtocolError\", \"Invalid book_update seq\");\n }\n // Validate only populated level arrays so existing empty/resync frame\n // tolerance is unchanged while exact quote liquidity cannot be omitted.\n for (const side of [\"bids\", \"asks\"] as const) {\n const levels = data[side];\n if (!Array.isArray(levels)) continue;\n for (const level of levels) {\n if (\n typeof level !== \"object\" ||\n level === null ||\n Array.isArray(level) ||\n typeof (level as Record<string, unknown>).quote_notional !== \"string\"\n ) {\n throw new WsErrorClass(\n \"ProtocolError\",\n `Invalid book_update ${side} level: missing or invalid quote_notional`,\n );\n }\n }\n }\n message = {\n ...message,\n data: { ...message.data, seq: BigInt(seq) },\n };\n }\n if (message.type === \"user\") {\n return {\n ...message,\n data: normalizeUserUpdate(message.data as Parameters<typeof normalizeUserUpdate>[0]),\n };\n }\n if (message.type === \"wallet_deposit_balances\") {\n return {\n ...message,\n data: normalizeWalletDepositBalancesEvent(message.data),\n };\n }\n return message;\n}\n\n/** Validate the nested wallet event before exposing its discriminated union. */\nfunction normalizeWalletDepositBalancesEvent(\n input: unknown\n): WalletDepositBalancesEvent {\n const data = requireObject(input, \"wallet_deposit_balances data\");\n const eventType = requireString(data, \"event_type\");\n const walletAddress = requireString(data, \"wallet_address\") as PubkeyStr;\n\n switch (eventType) {\n case \"wallet_deposit_balance_snapshot\": {\n const rawBalances = requireObject(data.balances, \"balances\");\n const balances = {} as Record<PubkeyStr, DepositTokenBalance>;\n for (const [mint, balance] of Object.entries(rawBalances)) {\n balances[mint as PubkeyStr] = normalizeDepositTokenBalance(balance);\n }\n return {\n event_type: eventType,\n wallet_address: walletAddress,\n context_slot: requireContextSlot(data),\n balances,\n native_sol_balance: requireNativeSolBalance(data),\n };\n }\n case \"wallet_deposit_balance_update\":\n return {\n event_type: eventType,\n wallet_address: walletAddress,\n context_slot: requireContextSlot(data),\n balance: normalizeDepositTokenBalance(data.balance),\n };\n case \"wallet_native_sol_balance_update\":\n return {\n event_type: eventType,\n wallet_address: walletAddress,\n context_slot: requireContextSlot(data),\n native_sol_balance: requireNativeSolBalance(data),\n };\n case \"wallet_deposit_balance_status\": {\n const status = requireString(data, \"status\");\n if (status !== \"reconnecting\" && status !== \"metadata_unavailable\") {\n throw protocolError(`Invalid wallet balance status: \"${status}\"`);\n }\n return {\n event_type: eventType,\n wallet_address: walletAddress,\n status,\n code: requireString(data, \"code\"),\n };\n }\n default:\n throw protocolError(`Invalid wallet balance event type: \"${eventType}\"`);\n }\n}\n\n/** Preserve exact strings and nullable icons while rejecting incomplete balances. */\nfunction normalizeDepositTokenBalance(input: unknown): DepositTokenBalance {\n const balance = requireObject(input, \"deposit-token balance\");\n const normalized: DepositTokenBalance = {\n mint: requireString(balance, \"mint\") as PubkeyStr,\n idle: requireString(balance, \"idle\"),\n symbol: requireString(balance, \"symbol\"),\n name: requireString(balance, \"name\"),\n };\n for (const field of [\"icon_url_low\", \"icon_url_medium\", \"icon_url_high\"] as const) {\n const value = balance[field];\n if (value !== undefined) {\n if (value !== null && typeof value !== \"string\") {\n throw protocolError(`Invalid deposit-token balance ${field}`);\n }\n normalized[field] = value;\n }\n }\n return normalized;\n}\n\nfunction requireObject(input: unknown, field: string): Record<string, unknown> {\n if (typeof input !== \"object\" || input === null || Array.isArray(input)) {\n throw protocolError(`Invalid ${field}: expected object`);\n }\n return input as Record<string, unknown>;\n}\n\nfunction requireString(data: Record<string, unknown>, field: string): string {\n const value = data[field];\n if (typeof value !== \"string\") {\n throw protocolError(`Invalid wallet balance ${field}: expected string`);\n }\n return value;\n}\n\nfunction requireNativeSolBalance(data: Record<string, unknown>): string {\n // Canonical nine-place syntax maps directly to lamports without rounding or exponents.\n const value = requireString(data, \"native_sol_balance\");\n if (!/^(?:0|[1-9][0-9]*)\\.[0-9]{9}$/.test(value)) {\n throw protocolError(\n \"Invalid wallet balance native_sol_balance: expected exactly nine decimal places\"\n );\n }\n return value;\n}\n\nfunction requireContextSlot(data: Record<string, unknown>): number {\n // Safe integers prevent precision loss when state compares JavaScript slots.\n const value = data.context_slot;\n if (!Number.isSafeInteger(value) || (value as number) < 0) {\n throw protocolError(\"Invalid wallet balance context_slot\");\n }\n return value as number;\n}\n\nfunction protocolError(message: string): WsErrorClass {\n return new WsErrorClass(\"ProtocolError\", message);\n}\n"]}
@@ -5,7 +5,8 @@ import type { OrderBookId, PubkeyStr, Resolution } from "../shared";
5
5
  * backend rejects unknown/snake_case params). Each `(orderbook, aggregation)`
6
6
  * pair is a distinct subscription: one connection may hold multiple
7
7
  * aggregation views of the same orderbook, and unsubscribe must repeat the
8
- * same (normalized) aggregation to match.
8
+ * same (normalized) aggregation to match. The wallet-balance variant is an
9
+ * authenticated wallet identity whose tracked subscription replays on reconnect.
9
10
  */
10
11
  export type SubscribeParams = {
11
12
  type: "book_update";
@@ -18,6 +19,9 @@ export type SubscribeParams = {
18
19
  } | {
19
20
  type: "user";
20
21
  wallet_address: PubkeyStr;
22
+ } | {
23
+ type: "wallet_deposit_balances";
24
+ wallet_address: PubkeyStr;
21
25
  } | {
22
26
  type: "price_history";
23
27
  orderbook_id: OrderBookId;
@@ -37,6 +41,7 @@ export type SubscribeParams = {
37
41
  type: "deposit_asset_price";
38
42
  deposit_asset: string;
39
43
  };
44
+ /** Wire unsubscribe identities; wallet streams must repeat the exact wallet. */
40
45
  export type UnsubscribeParams = {
41
46
  type: "book_update";
42
47
  orderbook_ids: OrderBookId[];
@@ -48,6 +53,9 @@ export type UnsubscribeParams = {
48
53
  } | {
49
54
  type: "user";
50
55
  wallet_address: PubkeyStr;
56
+ } | {
57
+ type: "wallet_deposit_balances";
58
+ wallet_address: PubkeyStr;
51
59
  } | {
52
60
  type: "price_history";
53
61
  orderbook_id: OrderBookId;
@@ -72,6 +80,9 @@ export interface Subscription {
72
80
  matchesUnsubscribe(unsubscribe: UnsubscribeParams): boolean;
73
81
  subscriptionKey(): string;
74
82
  }
83
+ export declare function isAuthedSubscriptionParams(params: SubscribeParams | UnsubscribeParams): boolean;
84
+ /** Stable deduplication and reconnect-replay identity for one subscription. */
75
85
  export declare function subscriptionKey(params: SubscribeParams): string;
86
+ /** Match a wire unsubscribe against locally tracked replay state. */
76
87
  export declare function unsubscribeMatches(subscribe: SubscribeParams, unsubscribe: UnsubscribeParams): boolean;
77
88
  //# sourceMappingURL=subscriptions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"subscriptions.d.ts","sourceRoot":"","sources":["../../src/ws/subscriptions.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,U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,CAAA;CAAE,GAC5C;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,aAAa,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,UAAU,CAAA;CAAE,GACxE;IAAE,IAAI,EAAE,qBAAqB,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3D,MAAM,WAAW,YAAY;IAC3B,iBAAiB,IAAI,eAAe,CAAC;IACrC,mBAAmB,IAAI,iBAAiB,CAAC;IACzC,kBAAkB,CAAC,WAAW,EAAE,iBAAiB,GAAG,OAAO,CAAC;IAC5D,eAAe,IAAI,MAAM,CAAC;CAC3B;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,eAAe,GAAG,iBAAiB,GAC1C,OAAO,CAGT;AAED,+EAA+E;AAC/E,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CA2B/D;AAED,qEAAqE;AACrE,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,eAAe,EAC1B,WAAW,EAAE,iBAAiB,GAC7B,OAAO,CA2CT"}
@@ -1,8 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isAuthedSubscriptionParams = isAuthedSubscriptionParams;
3
4
  exports.subscriptionKey = subscriptionKey;
4
5
  exports.unsubscribeMatches = unsubscribeMatches;
5
6
  const aggregation_1 = require("../domain/orderbook/aggregation");
7
+ function isAuthedSubscriptionParams(params) {
8
+ // Classification drives logout cleanup; it does not itself prove authentication.
9
+ return params.type === "user" || params.type === "wallet_deposit_balances";
10
+ }
11
+ /** Stable deduplication and reconnect-replay identity for one subscription. */
6
12
  function subscriptionKey(params) {
7
13
  switch (params.type) {
8
14
  case "book_update": {
@@ -17,6 +23,8 @@ function subscriptionKey(params) {
17
23
  return `trades:${idsKey(params.orderbook_ids)}`;
18
24
  case "user":
19
25
  return `user:${params.wallet_address}`;
26
+ case "wallet_deposit_balances":
27
+ return `wallet_deposit_balances:${params.wallet_address}`;
20
28
  case "price_history":
21
29
  return `price_history:${params.orderbook_id}:${params.resolution}`;
22
30
  case "ticker":
@@ -29,6 +37,7 @@ function subscriptionKey(params) {
29
37
  return `deposit_asset_price:${params.deposit_asset}`;
30
38
  }
31
39
  }
40
+ /** Match a wire unsubscribe against locally tracked replay state. */
32
41
  function unsubscribeMatches(subscribe, unsubscribe) {
33
42
  if (subscribe.type !== unsubscribe.type) {
34
43
  return false;
@@ -45,6 +54,8 @@ function unsubscribeMatches(subscribe, unsubscribe) {
45
54
  return idsKey(subscribe.orderbook_ids) === idsKey(unsubscribe.orderbook_ids);
46
55
  case "user":
47
56
  return subscribe.wallet_address === unsubscribe.wallet_address;
57
+ case "wallet_deposit_balances":
58
+ return subscribe.wallet_address === unsubscribe.wallet_address;
48
59
  case "price_history":
49
60
  return (subscribe.orderbook_id === unsubscribe.orderbook_id &&
50
61
  subscribe.resolution === unsubscribe.resolution);
@@ -1 +1 @@
1
- {"version":3,"file":"subscriptions.js","sourceRoot":"","sources":["../../src/ws/subscriptions.ts"],"names":[],"mappings":";;AAyDA,0CAyBC;AAED,gDA4CC;AAhID,iEAIyC;AAqDzC,SAAgB,eAAe,CAAC,MAAuB;IACrD,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,aAAa,CAAC,CAAC,CAAC;YACnB,MAAM,WAAW,GAAG,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC;YAC7E,iEAAiE;YACjE,gDAAgD;YAChD,OAAO,IAAA,6BAAe,EAAC,WAAW,CAAC;gBACjC,CAAC,CAAC,QAAQ,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE;gBACxC,CAAC,CAAC,QAAQ,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,IAAA,kCAAoB,EAAC,WAAW,CAAC,EAAE,CAAC;QAClF,CAAC;QACD,KAAK,QAAQ;YACX,OAAO,UAAU,M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D,CAAC,aAAa,CAAC,CAAC;QACrH,KAAK,QAAQ;YACX,OAAO,MAAM,CAAC,SAAS,CAAC,aAAa,CAAC,KAAK,MAAM,CAAE,WAAgD,CAAC,aAAa,CAAC,CAAC;QACrH,KAAK,MAAM;YACT,OAAO,SAAS,CAAC,cAAc,KAAM,WAA6C,CAAC,cAAc,CAAC;QACpG,KAAK,eAAe;YAClB,OAAO,CACL,SAAS,CAAC,YAAY,KAAM,WAA6C,CAAC,YAAY;gBACtF,SAAS,CAAC,UAAU,KAAM,WAA0C,CAAC,UAAU,CAChF,CAAC;QACJ,KAAK,QAAQ;YACX,OAAO,SAAS,CAAC,aAAa,KAAM,WAA4C,CAAC,aAAa,CAAC;QACjG,KAAK,eAAe;YAClB,OAAO,CACL,SAAS,CAAC,aAAa,KAAM,WAAyC,CAAC,aAAa;gBACpF,SAAS,CAAC,UAAU,KAAM,WAA0C,CAAC,UAAU,CAChF,CAAC;QACJ,KAAK,qBAAqB;YACxB,OAAO,SAAS,CAAC,aAAa,KAAM,WAAyC,CAAC,aAAa,CAAC;IAChG,CAAC;AACH,CAAC;AAED,SAAS,MAAM,CAAC,GAAsB;IACpC,OAAO,CAAC,GAAG,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACnC,CAAC","sourcesContent":["import {\n aggregationKeySuffix,\n aggregationsEqual,\n isFullPrecision,\n} from \"../domain/orderbook/aggregation\";\nimport type { OrderBookId, PubkeyStr, Resolution } from \"../shared\";\n\n/**\n * Book subscriptions optionally carry a Hyperliquid-style aggregation\n * (`nSigFigs`/`mantissa`, wire spelling — omit both for full precision; the\n * backend rejects unknown/snake_case params). Each `(orderbook, aggregation)`\n * pair is a distinct subscription: one connection may hold multiple\n * aggregation views of the same orderbook, and unsubscribe must repeat the\n * same (normalized) aggregation to match.\n */\nexport type SubscribeParams =\n | {\n type: \"book_update\";\n orderbook_ids: OrderBookId[];\n nSigFigs?: number;\n mantissa?: number;\n }\n | { type: \"trades\"; orderbook_ids: OrderBookId[] }\n | { type: \"user\"; wallet_address: PubkeyStr }\n | {\n type: \"price_history\";\n orderbook_id: OrderBookId;\n resolution: Resolution;\n include_ohlcv?: boolean;\n }\n | { type: \"ticker\"; orderbook_ids: OrderBookId[] }\n | { type: \"market\"; market_pubkey: PubkeyStr }\n | { type: \"deposit_price\"; deposit_asset: string; resolution: Resolution }\n | { type: \"deposit_asset_price\"; deposit_asset: string };\n\nexport type UnsubscribeParams =\n | {\n type: \"book_update\";\n orderbook_ids: OrderBookId[];\n nSigFigs?: number;\n mantissa?: number;\n }\n | { type: \"trades\"; orderbook_ids: OrderBookId[] }\n | { type: \"user\"; wallet_address: PubkeyStr }\n | { type: \"price_history\"; orderbook_id: OrderBookId; resolution: Resolution }\n | { type: \"ticker\"; orderbook_ids: OrderBookId[] }\n | { type: \"market\"; market_pubkey: PubkeyStr }\n | { type: \"deposit_price\"; deposit_asset: string; resolution: Resolution }\n | { type: \"deposit_asset_price\"; deposit_asset: string };\n\nexport interface Subscription {\n toSubscribeParams(): SubscribeParams;\n toUnsubscribeParams(): UnsubscribeParams;\n matchesUnsubscribe(unsubscribe: UnsubscribeParams): boolean;\n subscriptionKey(): string;\n}\n\nexport function subscriptionKey(params: SubscribeParams): string {\n switch (params.type) {\n case \"book_update\": {\n const aggregation = { nSigFigs: params.nSigFigs, mantissa: params.mantissa };\n // Full precision keeps the pre-aggregation key shape so existing\n // consumers' tracked subscriptions stay stable.\n return isFullPrecision(aggregation)\n ? `book:${idsKey(params.orderbook_ids)}`\n : `book:${idsKey(params.orderbook_ids)}:${aggregationKeySuffix(aggregation)}`;\n }\n case \"trades\":\n return `trades:${idsKey(params.orderbook_ids)}`;\n case \"user\":\n return `user:${params.wallet_address}`;\n case \"price_history\":\n return `price_history:${params.orderbook_id}:${params.resolution}`;\n case \"ticker\":\n return `ticker:${idsKey(params.orderbook_ids)}`;\n case \"market\":\n return `market:${params.market_pubkey}`;\n case \"deposit_price\":\n return `deposit_price:${params.deposit_asset}:${params.resolution}`;\n case \"deposit_asset_price\":\n return `deposit_asset_price:${params.deposit_asset}`;\n }\n}\n\nexport function unsubscribeMatches(\n subscribe: SubscribeParams,\n unsubscribe: UnsubscribeParams\n): boolean {\n if (subscribe.type !== unsubscribe.type) {\n return false;\n }\n\n switch (subscribe.type) {\n case \"book_update\": {\n const unsubscribeBooks = unsubscribe as {\n orderbook_ids: OrderBookId[];\n nSigFigs?: number;\n mantissa?: number;\n };\n return (\n idsKey(subscribe.orderbook_ids) === idsKey(unsubscribeBooks.orderbook_ids) &&\n aggregationsEqual(\n { nSigFigs: subscribe.nSigFigs, mantissa: subscribe.mantissa },\n { nSigFigs: unsubscribeBooks.nSigFigs, mantissa: unsubscribeBooks.mantissa }\n )\n );\n }\n case \"trades\":\n return idsKey(subscribe.orderbook_ids) === idsKey((unsubscribe as { orderbook_ids: OrderBookId[] }).orderbook_ids);\n case \"ticker\":\n return idsKey(subscribe.orderbook_ids) === idsKey((unsubscribe as { orderbook_ids: OrderBookId[] }).orderbook_ids);\n case \"user\":\n return subscribe.wallet_address === (unsubscribe as { wallet_address: PubkeyStr }).wallet_address;\n case \"price_history\":\n return (\n subscribe.orderbook_id === (unsubscribe as { orderbook_id: OrderBookId }).orderbook_id &&\n subscribe.resolution === (unsubscribe as { resolution: Resolution }).resolution\n );\n case \"market\":\n return subscribe.market_pubkey === (unsubscribe as { market_pubkey: PubkeyStr }).market_pubkey;\n case \"deposit_price\":\n return (\n subscribe.deposit_asset === (unsubscribe as { deposit_asset: string }).deposit_asset &&\n subscribe.resolution === (unsubscribe as { resolution: Resolution }).resolution\n );\n case \"deposit_asset_price\":\n return subscribe.deposit_asset === (unsubscribe as { deposit_asset: string }).deposit_asset;\n }\n}\n\nfunction idsKey(ids: readonly string[]): string {\n return [...ids].sort().join(\",\");\n}\n"]}
1
+ {"version":3,"file":"subscriptions.js","sourceRoot":"","sources":["../../src/ws/subscriptions.ts"],"names":[],"mappings":";;AA6DA,gE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,UAAU,KAAM,WAA0C,CAAC,UAAU,CAChF,CAAC;QACJ,KAAK,QAAQ;YACX,OAAO,SAAS,CAAC,aAAa,KAAM,WAA4C,CAAC,aAAa,CAAC;QACjG,KAAK,eAAe;YAClB,OAAO,CACL,SAAS,CAAC,aAAa,KAAM,WAAyC,CAAC,aAAa;gBACpF,SAAS,CAAC,UAAU,KAAM,WAA0C,CAAC,UAAU,CAChF,CAAC;QACJ,KAAK,qBAAqB;YACxB,OAAO,SAAS,CAAC,aAAa,KAAM,WAAyC,CAAC,aAAa,CAAC;IAChG,CAAC;AACH,CAAC;AAED,SAAS,MAAM,CAAC,GAAsB;IACpC,OAAO,CAAC,GAAG,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACnC,CAAC","sourcesContent":["import {\n aggregationKeySuffix,\n aggregationsEqual,\n isFullPrecision,\n} from \"../domain/orderbook/aggregation\";\nimport type { OrderBookId, PubkeyStr, Resolution } from \"../shared\";\n\n/**\n * Book subscriptions optionally carry a Hyperliquid-style aggregation\n * (`nSigFigs`/`mantissa`, wire spelling — omit both for full precision; the\n * backend rejects unknown/snake_case params). Each `(orderbook, aggregation)`\n * pair is a distinct subscription: one connection may hold multiple\n * aggregation views of the same orderbook, and unsubscribe must repeat the\n * same (normalized) aggregation to match. The wallet-balance variant is an\n * authenticated wallet identity whose tracked subscription replays on reconnect.\n */\nexport type SubscribeParams =\n | {\n type: \"book_update\";\n orderbook_ids: OrderBookId[];\n nSigFigs?: number;\n mantissa?: number;\n }\n | { type: \"trades\"; orderbook_ids: OrderBookId[] }\n | { type: \"user\"; wallet_address: PubkeyStr }\n | { type: \"wallet_deposit_balances\"; wallet_address: PubkeyStr }\n | {\n type: \"price_history\";\n orderbook_id: OrderBookId;\n resolution: Resolution;\n include_ohlcv?: boolean;\n }\n | { type: \"ticker\"; orderbook_ids: OrderBookId[] }\n | { type: \"market\"; market_pubkey: PubkeyStr }\n | { type: \"deposit_price\"; deposit_asset: string; resolution: Resolution }\n | { type: \"deposit_asset_price\"; deposit_asset: string };\n\n/** Wire unsubscribe identities; wallet streams must repeat the exact wallet. */\nexport type UnsubscribeParams =\n | {\n type: \"book_update\";\n orderbook_ids: OrderBookId[];\n nSigFigs?: number;\n mantissa?: number;\n }\n | { type: \"trades\"; orderbook_ids: OrderBookId[] }\n | { type: \"user\"; wallet_address: PubkeyStr }\n | { type: \"wallet_deposit_balances\"; wallet_address: PubkeyStr }\n | { type: \"price_history\"; orderbook_id: OrderBookId; resolution: Resolution }\n | { type: \"ticker\"; orderbook_ids: OrderBookId[] }\n | { type: \"market\"; market_pubkey: PubkeyStr }\n | { type: \"deposit_price\"; deposit_asset: string; resolution: Resolution }\n | { type: \"deposit_asset_price\"; deposit_asset: string };\n\nexport interface Subscription {\n toSubscribeParams(): SubscribeParams;\n toUnsubscribeParams(): UnsubscribeParams;\n matchesUnsubscribe(unsubscribe: UnsubscribeParams): boolean;\n subscriptionKey(): string;\n}\n\nexport function isAuthedSubscriptionParams(\n params: SubscribeParams | UnsubscribeParams\n): boolean {\n // Classification drives logout cleanup; it does not itself prove authentication.\n return params.type === \"user\" || params.type === \"wallet_deposit_balances\";\n}\n\n/** Stable deduplication and reconnect-replay identity for one subscription. */\nexport function subscriptionKey(params: SubscribeParams): string {\n switch (params.type) {\n case \"book_update\": {\n const aggregation = { nSigFigs: params.nSigFigs, mantissa: params.mantissa };\n // Full precision keeps the pre-aggregation key shape so existing\n // consumers' tracked subscriptions stay stable.\n return isFullPrecision(aggregation)\n ? `book:${idsKey(params.orderbook_ids)}`\n : `book:${idsKey(params.orderbook_ids)}:${aggregationKeySuffix(aggregation)}`;\n }\n case \"trades\":\n return `trades:${idsKey(params.orderbook_ids)}`;\n case \"user\":\n return `user:${params.wallet_address}`;\n case \"wallet_deposit_balances\":\n return `wallet_deposit_balances:${params.wallet_address}`;\n case \"price_history\":\n return `price_history:${params.orderbook_id}:${params.resolution}`;\n case \"ticker\":\n return `ticker:${idsKey(params.orderbook_ids)}`;\n case \"market\":\n return `market:${params.market_pubkey}`;\n case \"deposit_price\":\n return `deposit_price:${params.deposit_asset}:${params.resolution}`;\n case \"deposit_asset_price\":\n return `deposit_asset_price:${params.deposit_asset}`;\n }\n}\n\n/** Match a wire unsubscribe against locally tracked replay state. */\nexport function unsubscribeMatches(\n subscribe: SubscribeParams,\n unsubscribe: UnsubscribeParams\n): boolean {\n if (subscribe.type !== unsubscribe.type) {\n return false;\n }\n\n switch (subscribe.type) {\n case \"book_update\": {\n const unsubscribeBooks = unsubscribe as {\n orderbook_ids: OrderBookId[];\n nSigFigs?: number;\n mantissa?: number;\n };\n return (\n idsKey(subscribe.orderbook_ids) === idsKey(unsubscribeBooks.orderbook_ids) &&\n aggregationsEqual(\n { nSigFigs: subscribe.nSigFigs, mantissa: subscribe.mantissa },\n { nSigFigs: unsubscribeBooks.nSigFigs, mantissa: unsubscribeBooks.mantissa }\n )\n );\n }\n case \"trades\":\n return idsKey(subscribe.orderbook_ids) === idsKey((unsubscribe as { orderbook_ids: OrderBookId[] }).orderbook_ids);\n case \"ticker\":\n return idsKey(subscribe.orderbook_ids) === idsKey((unsubscribe as { orderbook_ids: OrderBookId[] }).orderbook_ids);\n case \"user\":\n return subscribe.wallet_address === (unsubscribe as { wallet_address: PubkeyStr }).wallet_address;\n case \"wallet_deposit_balances\":\n return subscribe.wallet_address === (unsubscribe as { wallet_address: PubkeyStr }).wallet_address;\n case \"price_history\":\n return (\n subscribe.orderbook_id === (unsubscribe as { orderbook_id: OrderBookId }).orderbook_id &&\n subscribe.resolution === (unsubscribe as { resolution: Resolution }).resolution\n );\n case \"market\":\n return subscribe.market_pubkey === (unsubscribe as { market_pubkey: PubkeyStr }).market_pubkey;\n case \"deposit_price\":\n return (\n subscribe.deposit_asset === (unsubscribe as { deposit_asset: string }).deposit_asset &&\n subscribe.resolution === (unsubscribe as { resolution: Resolution }).resolution\n );\n case \"deposit_asset_price\":\n return subscribe.deposit_asset === (unsubscribe as { deposit_asset: string }).deposit_asset;\n }\n}\n\nfunction idsKey(ids: readonly string[]): string {\n return [...ids].sort().join(\",\");\n}\n"]}
@@ -19,6 +19,11 @@ export interface IWsClient {
19
19
  isConnected(): boolean;
20
20
  readyState(): ReadyState;
21
21
  restartConnection(): Promise<void>;
22
+ /**
23
+ * Purge User/wallet replay tracking and queued authenticated messages.
24
+ * Public subscriptions remain. This does not unsubscribe an open server
25
+ * stream, so callers must also send unsubscribe or disconnect on logout.
26
+ */
22
27
  clearAuthedSubscriptions(): void;
23
28
  on(callback: (event: WsEvent) => void): () => void;
24
29
  }
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/ws/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAE1E;;;;;;;;;GASG;AACH,MAAM,WAAW,SAAS;IACxB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI,CAAC;IAChC,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI,CAAC;IACzC,WAAW,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAC7C,WAAW,IAAI,OAAO,CAAC;IACvB,UAAU,IAAI,UAAU,CAAC;IACzB,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,wBAAwB,IAAI,IAAI,CAAC;IACjC,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;CACpD"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/ws/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAE1E;;;;;;;;;GASG;AACH,MAAM,WAAW,SAAS;IACxB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI,CAAC;IAChC,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI,CAAC;IACzC,WAAW,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAC7C,WAAW,IAAI,OAAO,CAAC;IACvB,UAAU,IAAI,UAAU,CAAC;IACzB,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC;;;;OAIG;IACH,wBAAwB,IAAI,IAAI,CAAC;IACjC,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;CACpD"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/ws/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { MessageOut, ReadyState, WsEvent } from \"./index\";\nimport type { SubscribeParams, UnsubscribeParams } from \"./subscriptions\";\n\n/**\n * Shared interface for WebSocket clients.\n *\n * Two implementations exist:\n * - `client.node.ts` — Node.js, backed by the `ws` npm module\n * - `client.browser.ts` — Browser, backed by native `globalThis.WebSocket`\n *\n * The active implementation is selected at build time via the `\"browser\"`\n * field in package.json.\n */\nexport interface IWsClient {\n connect(): Promise<void>;\n disconnect(): Promise<void>;\n send(message: MessageOut): void;\n subscribe(params: SubscribeParams): void;\n unsubscribe(params: UnsubscribeParams): void;\n isConnected(): boolean;\n readyState(): ReadyState;\n restartConnection(): Promise<void>;\n clearAuthedSubscriptions(): void;\n on(callback: (event: WsEvent) => void): () => void;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/ws/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { MessageOut, ReadyState, WsEvent } from \"./index\";\nimport type { SubscribeParams, UnsubscribeParams } from \"./subscriptions\";\n\n/**\n * Shared interface for WebSocket clients.\n *\n * Two implementations exist:\n * - `client.node.ts` — Node.js, backed by the `ws` npm module\n * - `client.browser.ts` — Browser, backed by native `globalThis.WebSocket`\n *\n * The active implementation is selected at build time via the `\"browser\"`\n * field in package.json.\n */\nexport interface IWsClient {\n connect(): Promise<void>;\n disconnect(): Promise<void>;\n send(message: MessageOut): void;\n subscribe(params: SubscribeParams): void;\n unsubscribe(params: UnsubscribeParams): void;\n isConnected(): boolean;\n readyState(): ReadyState;\n restartConnection(): Promise<void>;\n /**\n * Purge User/wallet replay tracking and queued authenticated messages.\n * Public subscriptions remain. This does not unsubscribe an open server\n * stream, so callers must also send unsubscribe or disconnect on logout.\n */\n clearAuthedSubscriptions(): void;\n on(callback: (event: WsEvent) => void): () => void;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightconexyz/lightcone-sdk",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "description": "TypeScript SDK for Lightcone",
5
5
  "author": "Lightcone",
6
6
  "license": "MIT",
@@ -40,6 +40,7 @@
40
40
  "dependencies": {
41
41
  "@solana/spl-token": "^0.4.14",
42
42
  "@solana/web3.js": "^1.90.0",
43
+ "@noble/hashes": "^1.8.0",
43
44
  "bs58": "^5.0.0",
44
45
  "decimal.js": "^10.6.0",
45
46
  "js-sha3": "^0.9.3",