ault-sdk-ts 0.0.2-alpha.19 → 0.0.2-alpha.20
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 +54 -43
- package/dist/core/manifest-resolver.d.ts +4 -3
- package/dist/core/network.d.ts +14 -5
- package/dist/index.cjs +381 -143
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +380 -143
- package/dist/index.js.map +1 -1
- package/dist/utils/address.d.ts +1 -0
- package/dist/ws/client.d.ts +42 -5
- package/dist/ws/types.d.ts +334 -72
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -434,7 +434,7 @@ const tsMarks = await dex.getUDFTimescaleMarks({
|
|
|
434
434
|
|
|
435
435
|
## DEX WebSocket
|
|
436
436
|
|
|
437
|
-
The SDK
|
|
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
|
|
461
|
+
### Subscribing to Channels
|
|
462
462
|
|
|
463
|
-
|
|
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
|
-
//
|
|
467
|
-
const sub = client.ws.subscribe(
|
|
468
|
-
|
|
469
|
-
|
|
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
|
|
474
|
-
client.ws.subscribe(
|
|
475
|
-
|
|
476
|
-
|
|
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
|
-
//
|
|
481
|
-
client.ws.subscribe(
|
|
482
|
-
|
|
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
|
-
//
|
|
486
|
-
client.ws.subscribe(
|
|
487
|
-
|
|
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
|
-
"
|
|
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
|
-
###
|
|
518
|
+
### User channels
|
|
513
519
|
|
|
514
|
-
|
|
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
|
-
//
|
|
519
|
-
client.ws.subscribe(
|
|
520
|
-
|
|
521
|
-
|
|
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
|
-
//
|
|
526
|
-
client.ws.subscribe(
|
|
527
|
-
|
|
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
|
-
//
|
|
531
|
-
client.ws.subscribe(
|
|
532
|
-
|
|
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.
|
|
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,
|
|
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 `
|
|
40
|
-
* object — the broadcast layer reads
|
|
41
|
-
*
|
|
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
|
package/dist/core/network.d.ts
CHANGED
|
@@ -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:
|
|
54
|
-
readonly MARKET_ORDER:
|
|
62
|
+
readonly LIMIT_ORDER: 125000;
|
|
63
|
+
readonly MARKET_ORDER: 119000;
|
|
55
64
|
readonly SCALE_ORDER_BASE: 115000;
|
|
56
|
-
readonly SCALE_ORDER_PER_SUB:
|
|
57
|
-
readonly CANCEL_ORDER_BASE:
|
|
58
|
-
readonly CANCEL_ORDER_PER_ID:
|
|
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;
|