@stryke-xyz/premarket-sdk 1.0.8 → 1.1.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 (45) hide show
  1. package/README.md +5 -36
  2. package/dist/cjs/api/orderbook-api/index.js +116 -62
  3. package/dist/cjs/package.json +1 -1
  4. package/dist/cjs/shared/types.js +5 -1
  5. package/dist/cjs/sync/clients/activity-client.js +11 -17
  6. package/dist/cjs/sync/clients/order-client.js +84 -150
  7. package/dist/cjs/sync/index.js +0 -4
  8. package/dist/esm/api/orderbook-api/index.js +116 -62
  9. package/dist/esm/package.json +1 -1
  10. package/dist/esm/shared/types.js +5 -1
  11. package/dist/esm/sync/clients/activity-client.js +11 -17
  12. package/dist/esm/sync/clients/order-client.js +84 -150
  13. package/dist/esm/sync/index.js +0 -1
  14. package/dist/esm/sync/types.js +1 -3
  15. package/dist/types/api/orderbook-api/index.d.ts +16 -12
  16. package/dist/types/shared/types.d.ts +13 -27
  17. package/dist/types/sync/clients/order-client.d.ts +9 -12
  18. package/dist/types/sync/index.d.ts +2 -3
  19. package/dist/types/sync/types.d.ts +0 -23
  20. package/package.json +1 -1
  21. package/dist/cjs/api/README.md +0 -296
  22. package/dist/cjs/config/README.md +0 -112
  23. package/dist/cjs/exchange/README.md +0 -280
  24. package/dist/cjs/registry/README.md +0 -150
  25. package/dist/cjs/shared/README.md +0 -235
  26. package/dist/cjs/shared/utils.js +0 -1
  27. package/dist/cjs/sync/README.md +0 -215
  28. package/dist/cjs/sync/clients/base-client.js +0 -518
  29. package/dist/cjs/sync/redis-ws-client.js +0 -235
  30. package/dist/cjs/utils/README.md +0 -89
  31. package/dist/cjs/vault/README.md +0 -268
  32. package/dist/esm/api/README.md +0 -296
  33. package/dist/esm/config/README.md +0 -112
  34. package/dist/esm/exchange/README.md +0 -280
  35. package/dist/esm/registry/README.md +0 -150
  36. package/dist/esm/shared/README.md +0 -235
  37. package/dist/esm/shared/utils.js +0 -0
  38. package/dist/esm/sync/README.md +0 -215
  39. package/dist/esm/sync/clients/base-client.js +0 -508
  40. package/dist/esm/sync/redis-ws-client.js +0 -225
  41. package/dist/esm/utils/README.md +0 -89
  42. package/dist/esm/vault/README.md +0 -268
  43. package/dist/types/shared/utils.d.ts +0 -0
  44. package/dist/types/sync/clients/base-client.d.ts +0 -56
  45. package/dist/types/sync/redis-ws-client.d.ts +0 -21
package/README.md CHANGED
@@ -315,9 +315,8 @@ Public order methods:
315
315
 
316
316
  - `createOrder(params, bearerToken)`
317
317
  - `getOrder(orderHash)`
318
- - `queryOrders(params)`
319
- - `getUserOrders(maker, marketId)`
320
- - `getDepthSnapshot(marketId, tokenId)`
318
+ - `getOrders(marketId, maker?)` — active orders for a market, optionally scoped to a maker
319
+ - `getUserOrders(maker, marketId)` — convenience wrapper around `getOrders`
321
320
 
322
321
  Public market methods:
323
322
 
@@ -349,9 +348,9 @@ Auth-related methods also exposed by the SDK:
349
348
 
350
349
  Integration note:
351
350
 
352
- - `getUserOrders` enforces `marketId` at runtime
353
- - `queryOrders` may accept an optional `marketId` in TypeScript, but reliable
354
- backend integration should still provide one
351
+ - `getOrders` and `getUserOrders` both require a `marketId`. Returned orders
352
+ are restricted to active and partially-filled (cancelled / fully-filled
353
+ / expired are filtered server-side).
355
354
 
356
355
  ### Deserializers
357
356
 
@@ -361,8 +360,6 @@ The API returns string-heavy DTOs because JSON cannot safely transport
361
360
  - `orderToBigInt`
362
361
  - `storedOrderToBigInt`
363
362
  - `ordersSnapshotToBigInt`
364
- - `queryOrdersResponseToBigInt`
365
- - `depthSnapshotToBigInt`
366
363
  - `marketInstrumentToBigInt`
367
364
  - `marketToBigInt`
368
365
  - `marketsToBigInt`
@@ -573,9 +570,6 @@ Public exports:
573
570
 
574
571
  - `SyncStatus`
575
572
  - `"connecting" | "syncing" | "synced" | "recovering" | "disconnected" | "error"`
576
- - `OrderChange`
577
- - `SequencedMessage`
578
- - `SyncClientConfig`
579
573
 
580
574
  ### MarketDepthSyncClient
581
575
 
@@ -620,7 +614,6 @@ Public event types:
620
614
  - `DepthLevel`
621
615
  - `TokenDepthSnapshot`
622
616
  - `DepthLevelUpdate`
623
- - `DepthChangeEvent`
624
617
  - `DepthUpdate`
625
618
 
626
619
  Implementation details captured by the client:
@@ -662,27 +655,6 @@ Public event type:
662
655
 
663
656
  - `OrderFillEvent`
664
657
 
665
- ### BaseSyncClient
666
-
667
- This is the advanced extension point for custom sequenced Redis-backed clients.
668
-
669
- Public methods:
670
-
671
- - `connect()`
672
- - `disconnect()`
673
- - `getStatus()`
674
- - `isSynced()`
675
- - `getLastSequence()`
676
- - `getBufferedCount()`
677
- - `onStatus(callback)`
678
- - `onChange(callback)`
679
- - `onSnapshot(callback)`
680
-
681
- Subclass responsibilities:
682
-
683
- - provide `fetchSnapshot()`
684
- - provide `applyMessage(message)`
685
-
686
658
  ## Config Module
687
659
 
688
660
  Source files:
@@ -772,11 +744,8 @@ Main exports:
772
744
  - `MatchedOrder`
773
745
  - `MatchResult`
774
746
  - `CreateOrderResult`
775
- - `OrderQueryParams`
776
747
  - `OrderResponse`
777
748
  - `OrdersSnapshot`
778
- - `QueryOrdersResponse`
779
- - `DepthSnapshot`
780
749
 
781
750
  Main order write shape:
782
751
 
@@ -104,6 +104,45 @@ function _iterable_to_array_limit(arr, i) {
104
104
  function _non_iterable_rest() {
105
105
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
106
106
  }
107
+ function _object_spread(target) {
108
+ for(var i = 1; i < arguments.length; i++){
109
+ var source = arguments[i] != null ? arguments[i] : {};
110
+ var ownKeys = Object.keys(source);
111
+ if (typeof Object.getOwnPropertySymbols === "function") {
112
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
113
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
114
+ }));
115
+ }
116
+ ownKeys.forEach(function(key) {
117
+ _define_property(target, key, source[key]);
118
+ });
119
+ }
120
+ return target;
121
+ }
122
+ function ownKeys(object, enumerableOnly) {
123
+ var keys = Object.keys(object);
124
+ if (Object.getOwnPropertySymbols) {
125
+ var symbols = Object.getOwnPropertySymbols(object);
126
+ if (enumerableOnly) {
127
+ symbols = symbols.filter(function(sym) {
128
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
129
+ });
130
+ }
131
+ keys.push.apply(keys, symbols);
132
+ }
133
+ return keys;
134
+ }
135
+ function _object_spread_props(target, source) {
136
+ source = source != null ? source : {};
137
+ if (Object.getOwnPropertyDescriptors) {
138
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
139
+ } else {
140
+ ownKeys(Object(source)).forEach(function(key) {
141
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
142
+ });
143
+ }
144
+ return target;
145
+ }
107
146
  function _sliced_to_array(arr, i) {
108
147
  return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
109
148
  }
@@ -222,6 +261,53 @@ function _ts_generator(thisArg, body) {
222
261
  // ORDERBOOK API CLIENT
223
262
  // ============================================================================
224
263
  // ============================================================================
264
+ // SIGNATURE NORMALIZATION
265
+ // ============================================================================
266
+ /**
267
+ * Wire shape expected by orderbook-pg: split EIP-2098 compact signature.
268
+ * `r` is the standard r component (32 bytes hex). `vs` packs s + recovery bit
269
+ * (v-27) into the most-significant bit, per EIP-2098.
270
+ */ /**
271
+ * Accepts either:
272
+ * - a 65-byte concatenated hex signature `0x{r:32}{s:32}{v:1}` (what
273
+ * `walletClient.signTypedData` and `signSimpleAccountOrder` return), or
274
+ * - an already-split `{ r, vs }` payload.
275
+ *
276
+ * Returns the EIP-2098 split form the backend's signature recovery expects.
277
+ */ function toCompactSignature(signature) {
278
+ if ((typeof signature === "undefined" ? "undefined" : _type_of(signature)) === "object" && signature !== null) {
279
+ return {
280
+ r: signature.r,
281
+ vs: signature.vs
282
+ };
283
+ }
284
+ var hex = signature.startsWith("0x") ? signature.slice(2) : signature;
285
+ if (hex.length !== 130) {
286
+ throw new Error("Invalid signature length: expected 65 bytes (130 hex chars), got ".concat(hex.length));
287
+ }
288
+ var r = "0x".concat(hex.slice(0, 64));
289
+ var sHex = hex.slice(64, 128);
290
+ var vByte = parseInt(hex.slice(128, 130), 16);
291
+ if (vByte !== 27 && vByte !== 28) {
292
+ throw new Error("Invalid signature v byte: expected 27 or 28, got ".concat(vByte));
293
+ }
294
+ var recoveryBit = vByte - 27;
295
+ // Pack recoveryBit into the high bit of s to form vs.
296
+ var sBytes = new Uint8Array(32);
297
+ for(var i = 0; i < 32; i++){
298
+ sBytes[i] = parseInt(sHex.slice(i * 2, i * 2 + 2), 16);
299
+ }
300
+ if (recoveryBit === 1) sBytes[0] |= 0x80;
301
+ var vs = "0x";
302
+ for(var i1 = 0; i1 < 32; i1++){
303
+ vs += sBytes[i1].toString(16).padStart(2, "0");
304
+ }
305
+ return {
306
+ r: r,
307
+ vs: vs
308
+ };
309
+ }
310
+ // ============================================================================
225
311
  // ORDERBOOK API CLASS
226
312
  // ============================================================================
227
313
  /**
@@ -409,12 +495,23 @@ function _ts_generator(thisArg, body) {
409
495
  // ORDERBOOK METHODS
410
496
  // ============================================================================
411
497
  /**
412
- * Creates a new order in the orderbook service using a bearer-authenticated request.
498
+ * Submits a new order and synchronously returns the engine's match outcome.
499
+ *
500
+ * The backend awaits the matching engine's reply (up to ~2s) before
501
+ * responding, so callers get the full `matchResult` (`matches`, totals,
502
+ * `createdOrder`) inline. If the engine reply does not arrive in time
503
+ * `matchResult.message === "awaiting match"` and `matches` is empty —
504
+ * clients should then poll `getOrder(orderHash)` or watch the user
505
+ * activity WS for the eventual fill.
413
506
  */ function createOrder(params, bearerToken) {
414
507
  return _async_to_generator(function() {
508
+ var wireParams;
415
509
  return _ts_generator(this, function(_state) {
416
510
  switch(_state.label){
417
511
  case 0:
512
+ wireParams = _object_spread_props(_object_spread({}, params), {
513
+ signature: toCompactSignature(params.signature)
514
+ });
418
515
  return [
419
516
  4,
420
517
  this.requestEnvelope("/orderbook/api/orders", {
@@ -423,7 +520,7 @@ function _ts_generator(thisArg, body) {
423
520
  "Content-Type": "application/json",
424
521
  Authorization: "Bearer ".concat(bearerToken)
425
522
  },
426
- body: JSON.stringify(params)
523
+ body: JSON.stringify(wireParams)
427
524
  }, "Failed to create order")
428
525
  ];
429
526
  case 1:
@@ -454,30 +551,28 @@ function _ts_generator(thisArg, body) {
454
551
  }
455
552
  },
456
553
  {
457
- key: "queryOrders",
554
+ key: "getOrders",
458
555
  value: /**
459
- * Queries orders using optional market, maker, status, and pagination filters.
460
- */ function queryOrders(params) {
556
+ * Returns active (non-cancelled, non-fully-filled, non-expired) orders for a market.
557
+ * If `maker` is provided, scopes to a single user's open orders.
558
+ */ function getOrders(marketId, maker) {
461
559
  return _async_to_generator(function() {
462
- var url;
560
+ var _ref, data;
463
561
  return _ts_generator(this, function(_state) {
464
562
  switch(_state.label){
465
563
  case 0:
466
- url = this.buildUrl("/orderbook/api/orders", {
467
- marketId: params.marketId,
468
- maker: params.maker,
469
- status: params.status,
470
- limit: params.limit,
471
- offset: params.offset
472
- });
473
564
  return [
474
565
  4,
475
- this.requestEnvelope(url, undefined, "Failed to query orders")
566
+ this.requestEnvelope(this.buildUrl("/orderbook/api/orders", {
567
+ marketId: marketId,
568
+ maker: maker
569
+ }), undefined, "Failed to fetch orders")
476
570
  ];
477
571
  case 1:
572
+ data = _state.sent();
478
573
  return [
479
574
  2,
480
- _state.sent()
575
+ (_ref = data === null || data === void 0 ? void 0 : data.orders) !== null && _ref !== void 0 ? _ref : []
481
576
  ];
482
577
  }
483
578
  });
@@ -487,56 +582,15 @@ function _ts_generator(thisArg, body) {
487
582
  {
488
583
  key: "getUserOrders",
489
584
  value: /**
490
- * Get user orders for a market.
491
- * `marketId` is required by backend route contract.
585
+ * Returns active orders for a single user in a market.
586
+ * Convenience wrapper around `getOrders(marketId, maker)`.
492
587
  */ function getUserOrders(maker, marketId) {
493
588
  return _async_to_generator(function() {
494
- var data;
495
589
  return _ts_generator(this, function(_state) {
496
- switch(_state.label){
497
- case 0:
498
- if (!marketId) {
499
- throw new Error("marketId is required to fetch user orders");
500
- }
501
- return [
502
- 4,
503
- this.requestEnvelope(this.buildUrl("/orderbook/api/orders/user/".concat(encodeURIComponent(maker)), {
504
- marketId: marketId
505
- }), undefined, "Failed to get orders snapshot")
506
- ];
507
- case 1:
508
- data = _state.sent();
509
- return [
510
- 2,
511
- (data === null || data === void 0 ? void 0 : data.orders) || []
512
- ];
513
- }
514
- });
515
- }).call(this);
516
- }
517
- },
518
- {
519
- key: "getDepthSnapshot",
520
- value: /**
521
- * Fetches the current depth snapshot for one market and token pair.
522
- */ function getDepthSnapshot(marketId, tokenId) {
523
- return _async_to_generator(function() {
524
- return _ts_generator(this, function(_state) {
525
- switch(_state.label){
526
- case 0:
527
- return [
528
- 4,
529
- this.requestEnvelope(this.buildUrl("/orderbook/api/depth", {
530
- marketId: marketId,
531
- tokenId: tokenId
532
- }), undefined, "Failed to get depth snapshot")
533
- ];
534
- case 1:
535
- return [
536
- 2,
537
- _state.sent()
538
- ];
539
- }
590
+ return [
591
+ 2,
592
+ this.getOrders(marketId, maker)
593
+ ];
540
594
  });
541
595
  }).call(this);
542
596
  }
@@ -1 +1 @@
1
- {"name":"@stryke-xyz/premarket-sdk","version":"1.0.7","type":"commonjs"}
1
+ {"name":"@stryke-xyz/premarket-sdk","version":"1.1.1","type":"commonjs"}
@@ -12,6 +12,10 @@ Object.defineProperty(exports, "OrderStatus", {
12
12
  // ORDER TYPES
13
13
  // ============================================================================
14
14
  /**
15
+ * Wire-format split signature (EIP-2098 compact pair). Used internally when
16
+ * posting orders to orderbook-pg, which expects { r, vs } rather than the
17
+ * 65-byte concatenated hex returned by viem.
18
+ */ /**
15
19
  * Option parameters for legacy OptionTokenFactory
16
20
  * Used for calculating option token IDs
17
21
  */ var OrderStatus = /*#__PURE__*/ function(OrderStatus) {
@@ -21,7 +25,7 @@ Object.defineProperty(exports, "OrderStatus", {
21
25
  OrderStatus["CANCELLED"] = "CANCELLED";
22
26
  OrderStatus["EXPIRED"] = "EXPIRED";
23
27
  return OrderStatus;
24
- }({})/** If true, amount is in maker's makingAmount units. If false, amount is in maker's takingAmount units. */ /** The amount to pass to Exchange.fillOrder */ /** Whether fillAmount is in maker's makingAmount units (true) or takingAmount units (false) */ // ============================================================================
28
+ }({})/** If true, amount is in maker's makingAmount units. If false, amount is in maker's takingAmount units. */ /** The amount to pass to Exchange.fillOrder */ /** Whether fillAmount is in maker's makingAmount units (true) or takingAmount units (false) */ /** True if the user-submitted order's `amount` is in maker's makingAmount units. */ /** Set to "awaiting match" when the engine's match tail did not arrive within the API's wait window. */ // ============================================================================
25
29
  // MARKET TYPES
26
30
  // ============================================================================
27
31
  // ============================================================================
@@ -250,8 +250,8 @@ function _ts_generator(thisArg, body) {
250
250
  new Promise(function(resolve, reject) {
251
251
  var settled = false;
252
252
  var expectedSubscriptions = new Set();
253
- if (_this.config.marketId) expectedSubscriptions.add("orders_matched");
254
- if (_this.config.userAddress) expectedSubscriptions.add("user_info");
253
+ if (_this.config.marketId) expectedSubscriptions.add("subscribed_fills");
254
+ if (_this.config.userAddress) expectedSubscriptions.add("subscribed_user");
255
255
  var resolveOnce = function() {
256
256
  if (settled) return;
257
257
  settled = true;
@@ -268,16 +268,14 @@ function _ts_generator(thisArg, body) {
268
268
  _this.lastPongTime = Date.now();
269
269
  if (_this.config.marketId) {
270
270
  _this.ws.send(JSON.stringify({
271
- type: "subscribe",
272
- channel: "orders_matched",
271
+ type: "subscribe_fills",
273
272
  marketId: _this.config.marketId
274
273
  }));
275
274
  }
276
275
  if (_this.config.userAddress) {
277
276
  _this.ws.send(JSON.stringify({
278
- type: "subscribe",
279
- channel: "user_info",
280
- userAddress: _this.config.userAddress
277
+ type: "subscribe_user",
278
+ address: _this.config.userAddress
281
279
  }));
282
280
  }
283
281
  _this.startHeartbeat();
@@ -290,17 +288,15 @@ function _ts_generator(thisArg, body) {
290
288
  _this.clearHeartbeatTimeout();
291
289
  return;
292
290
  }
293
- if (msg.type === "subscribed") {
294
- if (typeof msg.channel === "string") {
295
- expectedSubscriptions.delete(msg.channel);
296
- }
291
+ if (msg.type === "subscribed_fills" || msg.type === "subscribed_user") {
292
+ expectedSubscriptions.delete(msg.type);
297
293
  if (expectedSubscriptions.size === 0) {
298
294
  _this.setStatus("synced");
299
295
  resolveOnce();
300
296
  }
301
297
  return;
302
298
  }
303
- if (msg.type === "unsubscribed") {
299
+ if (msg.type === "unsubscribed_fills" || msg.type === "unsubscribed_user") {
304
300
  return;
305
301
  }
306
302
  if (msg.type === "error") {
@@ -594,8 +590,7 @@ function _ts_generator(thisArg, body) {
594
590
  if (this.config.marketId) {
595
591
  try {
596
592
  this.ws.send(JSON.stringify({
597
- type: "unsubscribe",
598
- channel: "orders_matched",
593
+ type: "unsubscribe_fills",
599
594
  marketId: this.config.marketId
600
595
  }));
601
596
  } catch (unused) {}
@@ -603,9 +598,8 @@ function _ts_generator(thisArg, body) {
603
598
  /* ignore */ if (this.config.userAddress) {
604
599
  try {
605
600
  this.ws.send(JSON.stringify({
606
- type: "unsubscribe",
607
- channel: "user_info",
608
- userAddress: this.config.userAddress
601
+ type: "unsubscribe_user",
602
+ address: this.config.userAddress
609
603
  }));
610
604
  } catch (unused) {}
611
605
  }