ault-sdk-ts 0.0.2-alpha.19 → 0.0.2-alpha.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -434,7 +434,7 @@ const tsMarks = await dex.getUDFTimescaleMarks({
434
434
 
435
435
  ## DEX WebSocket
436
436
 
437
- The SDK includes a WebSocket client for real-time streaming from the DEX API. All payload types are shared with the REST client — no extra types needed.
437
+ The SDK ships a WebSocket client for streaming live data from the DEX API. It speaks the v2 subscription protocol: open one connection, subscribe to channels, and receive `{ channel, data }` frames. The payload types are WebSocket-native (they differ from the REST shapes) and are exported from the SDK.
438
438
 
439
439
  ### Connecting
440
440
 
@@ -458,34 +458,39 @@ const ws = createDexWs("wss://my-dex-api.example.com/ws");
458
458
  await ws.connect();
459
459
  ```
460
460
 
461
- ### Subscribing to Topics
461
+ ### Subscribing to Channels
462
462
 
463
- Subscriptions are type-safe — the `onData` callback is automatically typed based on the topic string.
463
+ Pass a subscription descriptor and the `onData` callback is typed from its `type`. Market channels need a `coin`; the `candle` channel also needs an `interval`. Frames flow through `onData` as they arrive. For snapshot-gated channels the first frame is the snapshot and the rest are deltas, so don't assume the first frame is a delta.
464
464
 
465
465
  ```typescript
466
- // Orderbook snapshots (data typed as OrderbookResponse)
467
- const sub = client.ws.subscribe("orderbook:AULT/USDT", {
468
- onData: (orderbook) => {
469
- console.log(orderbook.bids[0], orderbook.asks[0]);
466
+ // L2 order book — snapshot first, then per-block deltas (data typed as WsBook)
467
+ const sub = client.ws.subscribe(
468
+ { type: "l2Book", coin: "AULT/USDC" },
469
+ {
470
+ onData: (book) => {
471
+ const [bids, asks] = book.levels;
472
+ console.log(bids[0], asks[0]); // { px, sz, n }
473
+ },
470
474
  },
471
- });
475
+ );
472
476
 
473
- // Trades (data typed as TradeResponse[])
474
- client.ws.subscribe("trades:AULT/USDT", {
475
- onData: (trades) => {
476
- for (const t of trades) console.log(t.side, t.price, t.amount);
477
- },
478
- });
477
+ // Trades in each block (data typed as WsTrade[])
478
+ client.ws.subscribe(
479
+ { type: "trades", coin: "AULT/USDC" },
480
+ { onData: (trades) => trades.forEach((t) => console.log(t.side, t.px, t.sz)) },
481
+ );
479
482
 
480
- // 24h ticker (data typed as TickerResponse)
481
- client.ws.subscribe("ticker:AULT/USDT", {
482
- onData: (ticker) => console.log(ticker.last, ticker.percentage),
483
- });
483
+ // Best bid / offer (data typed as WsBbo)
484
+ client.ws.subscribe(
485
+ { type: "bbo", coin: "AULT/USDC" },
486
+ { onData: (b) => console.log(b.bbo[0], b.bbo[1]) },
487
+ );
484
488
 
485
- // OHLCV candles (data typed as OHLCVEntry)
486
- client.ws.subscribe("chart:AULT/USDT:60", {
487
- onData: (bar) => console.log(bar), // [timestamp, o, h, l, c, v]
488
- });
489
+ // Candles (data typed as WsCandle[])
490
+ client.ws.subscribe(
491
+ { type: "candle", coin: "AULT/USDC", interval: "1m" },
492
+ { onData: (bars) => console.log(bars[bars.length - 1]) },
493
+ );
489
494
 
490
495
  // Unsubscribe
491
496
  sub.unsubscribe();
@@ -493,15 +498,16 @@ sub.unsubscribe();
493
498
 
494
499
  ### Subscription Options
495
500
 
501
+ `ttl` sets a subscription lifetime in seconds (the server caps it at 3,600). The ack carries the effective, clamped value.
502
+
496
503
  ```typescript
497
- // TTL: auto-expire after 300 seconds
498
504
  client.ws.subscribe(
499
- "orderbook:AULT/USDT",
505
+ { type: "l2Book", coin: "AULT/USDC" },
500
506
  {
501
507
  onData: (data) => {
502
508
  /* ... */
503
509
  },
504
- onSubscribed: () => console.log("subscribed!"),
510
+ onSubscribed: (ack) => console.log("subscribed; effective ttl", ack.ttl),
505
511
  onExpired: () => console.log("subscription expired"),
506
512
  onError: (err) => console.error(err),
507
513
  },
@@ -509,28 +515,33 @@ client.ws.subscribe(
509
515
  );
510
516
  ```
511
517
 
512
- ### Address Topics
518
+ ### User channels
513
519
 
514
- Address topics (`orders`, `balances`, `mytrades`) expose read-only projections
515
- of public on-chain state — no authentication is required:
520
+ User channels key on an address (`ault1...` or `0x...`, either case) and expose read-only projections of public on-chain state, so no authentication is required. The address round-trips in the ack in the format you sent.
516
521
 
517
522
  ```typescript
518
- // Orders (data typed as OrderResponse[])
519
- client.ws.subscribe("orders:ault1...", {
520
- onData: (orders) => {
521
- for (const o of orders) console.log(o.id, o.status, o.filled);
523
+ // Order updates (data typed as WsOrderUpdate[])
524
+ client.ws.subscribe(
525
+ { type: "orderUpdates", user: "ault1..." },
526
+ {
527
+ onData: (orders) => orders.forEach((o) => console.log(o.order.oid, o.status, o.chainStatus)),
522
528
  },
523
- });
529
+ );
524
530
 
525
- // Balances (data typed as BalancesResponse)
526
- client.ws.subscribe("balances:ault1...", {
527
- onData: (balances) => console.log(balances.free),
528
- });
531
+ // Spot balances — first frame is the full set, later frames are per-coin deltas
532
+ client.ws.subscribe(
533
+ { type: "spotState", user: "ault1..." },
534
+ { onData: (state) => console.log(state.spotState.balances) },
535
+ );
529
536
 
530
- // User trades (data typed as TradeResponse[])
531
- client.ws.subscribe("mytrades:ault1...", {
532
- onData: (trades) => console.log(trades[0].order, trades[0].price),
533
- });
537
+ // Fills — the snapshot frame carries isSnapshot: true, live frames false
538
+ client.ws.subscribe(
539
+ { type: "userFills", user: "ault1..." },
540
+ { onData: (f) => console.log(f.isSnapshot, f.fills) },
541
+ );
542
+
543
+ // userEvents data arrives on the wire "user" channel; the SDK routes it back here
544
+ client.ws.subscribe({ type: "userEvents", user: "ault1..." }, { onData: (ev) => console.log(ev) });
534
545
  ```
535
546
 
536
547
  ### Connection Events
@@ -543,12 +554,12 @@ client.ws.on("reconnecting", (attempt) => console.log("reconnecting...", attempt
543
554
  client.ws.on("reconnected", () => console.log("reconnected"));
544
555
 
545
556
  // Raw message listener
546
- client.ws.on("message", (msg) => console.log(msg.topic, msg.event));
557
+ client.ws.on("message", (msg) => console.log(msg.channel, msg.data));
547
558
  ```
548
559
 
549
560
  ### Reconnection
550
561
 
551
- Auto-reconnect is enabled by default with exponential backoff. On reconnect, all active subscriptions are automatically restored (including re-authentication if needed).
562
+ Auto-reconnect is enabled by default with exponential backoff. On reconnect, every active subscription is re-sent with its original TTL.
552
563
 
553
564
  ```typescript
554
565
  const ws = createDexWs("wss://my-dex-api.example.com/ws", {
@@ -36,9 +36,10 @@ export declare function applyNetworkOverrides(network: NetworkConfig, manifest:
36
36
  * `ManifestEip712Schema` and apply through `applyNetworkOverrides`. As
37
37
  * defense in depth (in case a caller bypasses zod and passes a hand-rolled
38
38
  * blob), this helper actively drops `EIP712_FEE_AMOUNT`, `EIP712_GAS_LIMIT`,
39
- * and `DENOM` so the embedded values stay authoritative for the gas-constants
40
- * object — the broadcast layer reads those off `network.eip712*`, never off
41
- * the gas blob.
39
+ * `DENOM`, and `EIP712_ANTE_GAS` so the embedded values stay authoritative for
40
+ * the gas-constants object — the broadcast layer reads the fee/gas/denom off
41
+ * `network.eip712*`, and `EIP712_ANTE_GAS` is a fixed chain-ante constant the
42
+ * manifest is not allowed to override.
42
43
  *
43
44
  * The cast widens the zod-partial back to the concrete `GAS_CONSTANTS` type:
44
45
  * every field has a baseline value, so any key the manifest omits keeps the
@@ -39,6 +39,15 @@ export declare const GAS_CONSTANTS: {
39
39
  readonly DENOM: "aault";
40
40
  /** Chain multiplier applied to min gas to derive max gas (120 = 1.2×). */
41
41
  readonly FEE_FREE_GAS_MULTIPLIER: 120;
42
+ /**
43
+ * EIP-712 ante overhead, in gas. The chain's per-message MinGasLimit values
44
+ * (mirrored below) measure the *handler* cost only; a fee-free EIP-712 tx
45
+ * additionally burns ante gas (sig verification + typed-data decode + tx
46
+ * size) that counts against gasWanted. For small-base ops (cancel) the 1.2×
47
+ * buffer doesn't cover it, so the high-level (EIP-712) path adds this on top.
48
+ * The agent path is capped at MinGasLimit×1.2 and must not add it.
49
+ */
50
+ readonly EIP712_ANTE_GAS: 30000;
42
51
  readonly PER_LICENSE: 200000;
43
52
  readonly PER_KYC_MEMBER: 200000;
44
53
  readonly PER_DELEGATE_MINING: 200000;
@@ -50,12 +59,12 @@ export declare const GAS_CONSTANTS: {
50
59
  readonly REVOKE_BUILDER: 57000;
51
60
  readonly SET_REFERRAL_CODE: 76000;
52
61
  readonly SET_REFERRAL: 90000;
53
- readonly LIMIT_ORDER: 124000;
54
- readonly MARKET_ORDER: 116000;
62
+ readonly LIMIT_ORDER: 125000;
63
+ readonly MARKET_ORDER: 119000;
55
64
  readonly SCALE_ORDER_BASE: 115000;
56
- readonly SCALE_ORDER_PER_SUB: 11000;
57
- readonly CANCEL_ORDER_BASE: 49000;
58
- readonly CANCEL_ORDER_PER_ID: 22000;
65
+ readonly SCALE_ORDER_PER_SUB: 13000;
66
+ readonly CANCEL_ORDER_BASE: 50000;
67
+ readonly CANCEL_ORDER_PER_ID: 19000;
59
68
  readonly OPEN_ACCOUNT: 96000;
60
69
  readonly DELEGATE: 220000;
61
70
  readonly UNDELEGATE: 220000;