@lightconexyz/lightcone-sdk 0.5.1 → 0.6.1

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 (153) hide show
  1. package/README.md +35 -5
  2. package/dist/client.d.ts +30 -1
  3. package/dist/client.d.ts.map +1 -1
  4. package/dist/client.js +38 -0
  5. package/dist/client.js.map +1 -1
  6. package/dist/domain/admin/client.d.ts +10 -1
  7. package/dist/domain/admin/client.d.ts.map +1 -1
  8. package/dist/domain/admin/client.js +51 -0
  9. package/dist/domain/admin/client.js.map +1 -1
  10. package/dist/domain/admin/wire.d.ts +267 -7
  11. package/dist/domain/admin/wire.d.ts.map +1 -1
  12. package/dist/domain/admin/wire.js.map +1 -1
  13. package/dist/domain/faucet.d.ts +25 -0
  14. package/dist/domain/faucet.d.ts.map +1 -0
  15. package/dist/domain/faucet.js +3 -0
  16. package/dist/domain/faucet.js.map +1 -0
  17. package/dist/domain/index.d.ts +2 -0
  18. package/dist/domain/index.d.ts.map +1 -1
  19. package/dist/domain/index.js +3 -1
  20. package/dist/domain/index.js.map +1 -1
  21. package/dist/domain/market/client.d.ts +23 -2
  22. package/dist/domain/market/client.d.ts.map +1 -1
  23. package/dist/domain/market/client.js +30 -0
  24. package/dist/domain/market/client.js.map +1 -1
  25. package/dist/domain/market/convert.d.ts +10 -0
  26. package/dist/domain/market/convert.d.ts.map +1 -1
  27. package/dist/domain/market/convert.js +43 -4
  28. package/dist/domain/market/convert.js.map +1 -1
  29. package/dist/domain/market/icon.d.ts +17 -0
  30. package/dist/domain/market/icon.d.ts.map +1 -0
  31. package/dist/domain/market/icon.js +25 -0
  32. package/dist/domain/market/icon.js.map +1 -0
  33. package/dist/domain/market/index.d.ts +13 -4
  34. package/dist/domain/market/index.d.ts.map +1 -1
  35. package/dist/domain/market/index.js +3 -1
  36. package/dist/domain/market/index.js.map +1 -1
  37. package/dist/domain/market/outcome.d.ts +3 -1
  38. package/dist/domain/market/outcome.d.ts.map +1 -1
  39. package/dist/domain/market/outcome.js +7 -7
  40. package/dist/domain/market/outcome.js.map +1 -1
  41. package/dist/domain/market/tokens.d.ts +53 -3
  42. package/dist/domain/market/tokens.d.ts.map +1 -1
  43. package/dist/domain/market/tokens.js +99 -8
  44. package/dist/domain/market/tokens.js.map +1 -1
  45. package/dist/domain/market/wire.d.ts +46 -8
  46. package/dist/domain/market/wire.d.ts.map +1 -1
  47. package/dist/domain/market/wire.js.map +1 -1
  48. package/dist/domain/metrics/client.d.ts +66 -0
  49. package/dist/domain/metrics/client.d.ts.map +1 -0
  50. package/dist/domain/metrics/client.js +124 -0
  51. package/dist/domain/metrics/client.js.map +1 -0
  52. package/dist/domain/metrics/index.d.ts +3 -0
  53. package/dist/domain/metrics/index.d.ts.map +1 -0
  54. package/dist/domain/metrics/index.js +19 -0
  55. package/dist/domain/metrics/index.js.map +1 -0
  56. package/dist/domain/metrics/wire.d.ts +342 -0
  57. package/dist/domain/metrics/wire.d.ts.map +1 -0
  58. package/dist/domain/metrics/wire.js +3 -0
  59. package/dist/domain/metrics/wire.js.map +1 -0
  60. package/dist/domain/notification/client.d.ts +6 -0
  61. package/dist/domain/notification/client.d.ts.map +1 -1
  62. package/dist/domain/notification/client.js +10 -0
  63. package/dist/domain/notification/client.js.map +1 -1
  64. package/dist/domain/notification/index.d.ts +3 -1
  65. package/dist/domain/notification/index.d.ts.map +1 -1
  66. package/dist/domain/notification/index.js.map +1 -1
  67. package/dist/domain/order/client.d.ts +28 -2
  68. package/dist/domain/order/client.d.ts.map +1 -1
  69. package/dist/domain/order/client.js +76 -16
  70. package/dist/domain/order/client.js.map +1 -1
  71. package/dist/domain/order/convert.d.ts +5 -5
  72. package/dist/domain/order/convert.d.ts.map +1 -1
  73. package/dist/domain/order/convert.js +1 -1
  74. package/dist/domain/order/convert.js.map +1 -1
  75. package/dist/domain/order/index.d.ts +1 -1
  76. package/dist/domain/order/index.d.ts.map +1 -1
  77. package/dist/domain/order/index.js.map +1 -1
  78. package/dist/domain/order/state.d.ts +9 -7
  79. package/dist/domain/order/state.d.ts.map +1 -1
  80. package/dist/domain/order/state.js +81 -28
  81. package/dist/domain/order/state.js.map +1 -1
  82. package/dist/domain/orderbook/index.d.ts +1 -1
  83. package/dist/domain/orderbook/index.d.ts.map +1 -1
  84. package/dist/domain/orderbook/index.js +3 -8
  85. package/dist/domain/orderbook/index.js.map +1 -1
  86. package/dist/domain/orderbook/state.d.ts +44 -2
  87. package/dist/domain/orderbook/state.d.ts.map +1 -1
  88. package/dist/domain/orderbook/state.js +67 -4
  89. package/dist/domain/orderbook/state.js.map +1 -1
  90. package/dist/domain/orderbook/wire.d.ts +1 -0
  91. package/dist/domain/orderbook/wire.d.ts.map +1 -1
  92. package/dist/domain/orderbook/wire.js.map +1 -1
  93. package/dist/domain/position/client.d.ts +55 -0
  94. package/dist/domain/position/client.d.ts.map +1 -1
  95. package/dist/domain/position/client.js +71 -0
  96. package/dist/domain/position/client.js.map +1 -1
  97. package/dist/domain/position/index.d.ts +3 -2
  98. package/dist/domain/position/index.d.ts.map +1 -1
  99. package/dist/domain/position/index.js.map +1 -1
  100. package/dist/domain/price_history/client.d.ts +12 -1
  101. package/dist/domain/price_history/client.d.ts.map +1 -1
  102. package/dist/domain/price_history/client.js +14 -0
  103. package/dist/domain/price_history/client.js.map +1 -1
  104. package/dist/domain/price_history/wire.d.ts +27 -0
  105. package/dist/domain/price_history/wire.d.ts.map +1 -1
  106. package/dist/domain/price_history/wire.js.map +1 -1
  107. package/dist/domain/referral/client.d.ts +6 -0
  108. package/dist/domain/referral/client.d.ts.map +1 -1
  109. package/dist/domain/referral/client.js +22 -9
  110. package/dist/domain/referral/client.js.map +1 -1
  111. package/dist/domain/trade/convert.d.ts.map +1 -1
  112. package/dist/domain/trade/convert.js +5 -1
  113. package/dist/domain/trade/convert.js.map +1 -1
  114. package/dist/domain/trade/index.d.ts +4 -0
  115. package/dist/domain/trade/index.d.ts.map +1 -1
  116. package/dist/domain/trade/index.js.map +1 -1
  117. package/dist/domain/trade/state.d.ts +7 -0
  118. package/dist/domain/trade/state.d.ts.map +1 -1
  119. package/dist/domain/trade/state.js +36 -1
  120. package/dist/domain/trade/state.js.map +1 -1
  121. package/dist/domain/trade/wire.d.ts +3 -0
  122. package/dist/domain/trade/wire.d.ts.map +1 -1
  123. package/dist/domain/trade/wire.js.map +1 -1
  124. package/dist/http/client.d.ts +9 -0
  125. package/dist/http/client.d.ts.map +1 -1
  126. package/dist/http/client.js +24 -9
  127. package/dist/http/client.js.map +1 -1
  128. package/dist/index.d.ts +1 -1
  129. package/dist/index.d.ts.map +1 -1
  130. package/dist/index.js.map +1 -1
  131. package/dist/prelude.d.ts +13 -5
  132. package/dist/prelude.d.ts.map +1 -1
  133. package/dist/prelude.js +5 -3
  134. package/dist/prelude.js.map +1 -1
  135. package/dist/shared/fmt/decimal.js +4 -4
  136. package/dist/shared/fmt/decimal.js.map +1 -1
  137. package/dist/shared/index.d.ts +1 -1
  138. package/dist/shared/index.d.ts.map +1 -1
  139. package/dist/shared/index.js +2 -1
  140. package/dist/shared/index.js.map +1 -1
  141. package/dist/shared/types.d.ts +5 -2
  142. package/dist/shared/types.d.ts.map +1 -1
  143. package/dist/shared/types.js +21 -0
  144. package/dist/shared/types.js.map +1 -1
  145. package/dist/ws/index.d.ts +12 -1
  146. package/dist/ws/index.d.ts.map +1 -1
  147. package/dist/ws/index.js +20 -0
  148. package/dist/ws/index.js.map +1 -1
  149. package/dist/ws/subscriptions.d.ts +6 -0
  150. package/dist/ws/subscriptions.d.ts.map +1 -1
  151. package/dist/ws/subscriptions.js +4 -0
  152. package/dist/ws/subscriptions.js.map +1 -1
  153. package/package.json +2 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ws/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AA0EA,wCAYC;AAED,oBAEC;AAED,wCAQC;AAED,4CAQC;AAED,0CAQC;AAED,8CAQC;AAED,sCAQC;AAED,0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I,IAAI,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,EAAE,CAAC;QACzE,MAAM,IAAI,eAAY,CAAC,eAAe,EAAE,0CAA0C,CAAC,CAAC;IACtF,CAAC;IACD,MAAM,GAAG,GAAG,MAAiC,CAAC;IAC9C,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QACvE,MAAM,IAAI,eAAY,CAAC,eAAe,EAAE,6BAA6B,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC5F,CAAC;IACD,IAAI,CAAC,CAAC,SAAS,IAAI,GAAG,CAAC,IAAI,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC3D,MAAM,IAAI,eAAY,CAAC,eAAe,EAAE,wDAAwD,CAAC,CAAC;IACpG,CAAC;IACD,IAAI,CAAC,CAAC,MAAM,IAAI,GAAG,CAAC,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,IAAI,GAAG,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;QAC1E,MAAM,IAAI,eAAY,CAAC,eAAe,EAAE,qDAAqD,CAAC,CAAC;IACjG,CAAC;IACD,MAAM,OAAO,GAAG,MAAmB,CAAC;IACpC,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QAC5B,OAAO;YACL,GAAG,OAAO;YACV,IAAI,EAAE,IAAA,0BAAmB,EAAC,OAAO,CAAC,IAAiD,CAAC;SACrF,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,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 type { DepositPrice, PriceHistory } 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\";\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\nexport type Kind = MessageIn;\n\nexport interface WsError {\n error: string;\n code?: string;\n orderbook_id?: string;\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\nexport function subscribeBooks(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"book_update\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function unsubscribeBooks(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"book_update\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function subscribeTrades(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"trades\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function unsubscribeTrades(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"trades\",\n orderbook_ids: orderbookIds,\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,\n },\n };\n}\n\nexport function unsubscribeTicker(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"ticker\",\n orderbook_ids: orderbookIds,\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\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]);\n\nexport function parseMessageIn(input: string): MessageIn {\n const parsed: unknown = JSON.parse(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 const message = parsed as MessageIn;\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":";;;;;;;;;;;;;;;;;AA+EA,wCAYC;AAED,oBAEC;AAED,wCAQC;AAED,4CAQC;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,wCAuBC;AAzSD,+CAA6F;AAQ7F,oCAAmD;AACnD,gCAA6C;AAG7C,gDAA8B;AAC9B,kDAAgC;AAiDnB,QAAA,iBAAiB,GAAa;IACzC,GAAG,EAAE,IAAA,WAAK,EAAC,kBAAY,CAAC,IAAI,CAAC;IAC7B,SAAS,EAAE,IAAI;IACf,oBAAoB,EAAE,EAAE;IACxB,oBAAoB,EAAE,KAAK;IAC3B,cAAc,EAAE,MAAM;IACtB,aAAa,EAAE,MAAM;CACtB,CAAC;AAEF,IAAY,UAKX;AALD,WAAY,UAAU;IACpB,uDAAc,CAAA;IACd,2CAAQ,CAAA;IACR,iDAAW,CAAA;IACX,+CAAU,CAAA;AACZ,CAAC,EALW,UAAU,0BAAV,UAAU,QAKrB;AAED,SAAgB,cAAc,CAAC,KAAa;IAC1C,QAAQ,KAAK,EAAE,CAAC;QACd,KAAK,CAAC;YACJ,OAAO,UAAU,CAAC,UAAU,CAAC;QAC/B,KAAK,CAAC;YACJ,OAAO,UAAU,CAAC,IAAI,CAAC;QACzB,KAAK,CAAC;YACJ,OAAO,UAAU,CAAC,OAAO,CAAC;QAC5B,KAAK,CAAC,CAAC;QACP;YACE,OAAO,UAAU,CAAC,MAAM,CAAC;IAC7B,CAAC;AACH,CAAC;AAED,SAAgB,IAAI;IAClB,OAA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,EAAE,wDAAwD,CAAC,CAAC;IACpG,CAAC;IACD,IAAI,CAAC,CAAC,MAAM,IAAI,GAAG,CAAC,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,IAAI,GAAG,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;QAC1E,MAAM,IAAI,eAAY,CAAC,eAAe,EAAE,qDAAqD,CAAC,CAAC;IACjG,CAAC;IACD,MAAM,OAAO,GAAG,MAAmB,CAAC;IACpC,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QAC5B,OAAO;YACL,GAAG,OAAO;YACV,IAAI,EAAE,IAAA,0BAAmB,EAAC,OAAO,CAAC,IAAiD,CAAC;SACrF,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,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 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\";\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 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\nexport function subscribeBooks(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"book_update\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function unsubscribeBooks(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"book_update\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function subscribeTrades(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"trades\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function unsubscribeTrades(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"trades\",\n orderbook_ids: orderbookIds,\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,\n },\n };\n}\n\nexport function unsubscribeTicker(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"ticker\",\n orderbook_ids: orderbookIds,\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 = JSON.parse(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 const message = parsed as MessageIn;\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"]}
@@ -23,6 +23,9 @@ export type SubscribeParams = {
23
23
  type: "deposit_price";
24
24
  deposit_asset: string;
25
25
  resolution: Resolution;
26
+ } | {
27
+ type: "deposit_asset_price";
28
+ deposit_asset: string;
26
29
  };
27
30
  export type UnsubscribeParams = {
28
31
  type: "book_update";
@@ -47,6 +50,9 @@ export type UnsubscribeParams = {
47
50
  type: "deposit_price";
48
51
  deposit_asset: string;
49
52
  resolution: Resolution;
53
+ } | {
54
+ type: "deposit_asset_price";
55
+ deposit_asset: string;
50
56
  };
51
57
  export interface Subscription {
52
58
  toSubscribeParams(): SubscribeParams;
@@ -1 +1 @@
1
- {"version":3,"file":"subscriptions.d.ts","sourceRoot":"","sources":["../../src/ws/subscriptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEpE,MAAM,MAAM,eAAe,GACvB;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,aAAa,EAAE,WAAW,EAAE,CAAA;CAAE,GACrD;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,aAAa,EAAE,WAAW,EAAE,CAAA;CAAE,GAChD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,SAAS,CAAA;CAAE,GAC3C;IACE,IAAI,EAAE,eAAe,CAAC;IACtB,YAAY,EAAE,WAAW,CAAC;IAC1B,UAAU,EAAE,UAAU,CAAC;IACvB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,GACD;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,aAAa,EAAE,WAAW,EAAE,CAAA;CAAE,GAChD;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,aAAa,EAAE,SAAS,CAAA;CAAE,GAC5C;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,aAAa,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,UAAU,CAAA;CAAE,CAAC;AAE7E,MAAM,MAAM,iBAAiB,GACzB;IAAE,IAAI,EAAE,aAAa,CAA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,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,eAAe,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CAmB/D;AAED,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,eAAe,EAC1B,WAAW,EAAE,iBAAiB,GAC7B,OAAO,CA6BT"}
@@ -18,6 +18,8 @@ function subscriptionKey(params) {
18
18
  return `market:${params.market_pubkey}`;
19
19
  case "deposit_price":
20
20
  return `deposit_price:${params.deposit_asset}:${params.resolution}`;
21
+ case "deposit_asset_price":
22
+ return `deposit_asset_price:${params.deposit_asset}`;
21
23
  }
22
24
  }
23
25
  function unsubscribeMatches(subscribe, unsubscribe) {
@@ -41,6 +43,8 @@ function unsubscribeMatches(subscribe, unsubscribe) {
41
43
  case "deposit_price":
42
44
  return (subscribe.deposit_asset === unsubscribe.deposit_asset &&
43
45
  subscribe.resolution === unsubscribe.resolution);
46
+ case "deposit_asset_price":
47
+ return subscribe.deposit_asset === unsubscribe.deposit_asset;
44
48
  }
45
49
  }
46
50
  function idsKey(ids) {
@@ -1 +1 @@
1
- {"version":3,"file":"subscriptions.js","sourceRoot":"","sources":["../../src/ws/subscriptions.ts"],"names":[],"mappings":";;AAgCA,0CAiBC;AAED,gDA8BC;AAjDD,SAAgB,eAAe,CAAC,MAAuB;IACrD,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,aAAa;YAChB,OAAO,QAAQ,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;QAChD,KAAK,QAAQ;YACX,OAAO,UAAU,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;QAClD,KAAK,MAAM;Y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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;IACN,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 type { OrderBookId, PubkeyStr, Resolution } from \"../shared\";\n\nexport type SubscribeParams =\n | { type: \"book_update\"; orderbook_ids: OrderBookId[] }\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\nexport type UnsubscribeParams =\n | { type: \"book_update\"; orderbook_ids: OrderBookId[] }\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\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 return `book:${idsKey(params.orderbook_ids)}`;\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 }\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 return idsKey(subscribe.orderbook_ids) === idsKey((unsubscribe as { orderbook_ids: OrderBookId[] }).orderbook_ids);\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 }\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":";;AAkCA,0CAmBC;AAED,gDAgCC;AArDD,SAAgB,eAAe,CAAC,MAAuB;IACrD,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,aAAa;YAChB,OAAO,QAAQ,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,E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,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 type { OrderBookId, PubkeyStr, Resolution } from \"../shared\";\n\nexport type SubscribeParams =\n | { type: \"book_update\"; orderbook_ids: OrderBookId[] }\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 | { type: \"book_update\"; orderbook_ids: OrderBookId[] }\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 return `book:${idsKey(params.orderbook_ids)}`;\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 return idsKey(subscribe.orderbook_ids) === idsKey((unsubscribe as { orderbook_ids: OrderBookId[] }).orderbook_ids);\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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightconexyz/lightcone-sdk",
3
- "version": "0.5.1",
3
+ "version": "0.6.1",
4
4
  "description": "TypeScript SDK for Lightcone",
5
5
  "author": "Lightcone",
6
6
  "license": "MIT",
@@ -34,6 +34,7 @@
34
34
  "lint:fix": "eslint src --fix",
35
35
  "typecheck": "tsc --noEmit",
36
36
  "typecheck:examples": "tsc --noEmit -p tsconfig.examples.json",
37
+ "test": "npx tsx --test tests/**/*.test.ts",
37
38
  "prepublishOnly": "npm run clean && npm run lint && npm run typecheck && npm run typecheck:examples && npm run build"
38
39
  },
39
40
  "dependencies": {