ault-sdk-ts 0.0.2-alpha.8 → 0.1.0

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 (90) hide show
  1. package/README.md +375 -50
  2. package/dist/agent/attach.d.ts +26 -0
  3. package/dist/agent/sign-and-broadcast.d.ts +9 -2
  4. package/dist/agent/tx/clob.d.ts +8 -1
  5. package/dist/agent/tx-executor.d.ts +24 -2
  6. package/dist/client.d.ts +6 -7
  7. package/dist/core/clob-gas.d.ts +28 -0
  8. package/dist/core/clob-msgs.d.ts +31 -5
  9. package/dist/core/clob-responses.d.ts +20 -0
  10. package/dist/core/cloid.d.ts +4 -0
  11. package/dist/core/errors.d.ts +79 -0
  12. package/dist/core/manifest-fetcher.d.ts +12 -0
  13. package/dist/core/manifest-resolver.d.ts +121 -0
  14. package/dist/core/manifest-types.d.ts +102 -0
  15. package/dist/core/network.d.ts +42 -13
  16. package/dist/eip712/msg.generated.d.ts +26 -10
  17. package/dist/eip712/registry.d.ts +2 -0
  18. package/dist/eip712/sign-and-broadcast.d.ts +27 -3
  19. package/dist/high-level/cloid-lookup.d.ts +9 -0
  20. package/dist/high-level/create-client.d.ts +15 -11
  21. package/dist/high-level/tx/accountx.d.ts +3 -0
  22. package/dist/high-level/tx/agent.d.ts +1 -1
  23. package/dist/high-level/tx/clob.d.ts +1 -1
  24. package/dist/high-level/tx/context.d.ts +8 -0
  25. package/dist/high-level/tx/license.d.ts +1 -1
  26. package/dist/high-level/tx/miner.d.ts +1 -1
  27. package/dist/high-level/tx/reward.d.ts +1 -1
  28. package/dist/high-level/tx/staking.d.ts +1 -1
  29. package/dist/high-level/tx-executor.d.ts +23 -3
  30. package/dist/high-level/types.d.ts +356 -100
  31. package/dist/high-level-client.d.ts +1 -1
  32. package/dist/index.cjs +16101 -7908
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.d.ts +10 -1
  35. package/dist/index.js +15860 -7678
  36. package/dist/index.js.map +1 -1
  37. package/dist/proto/gen/ault/accountx/v1/genesis.d.ts +38 -0
  38. package/dist/proto/gen/ault/accountx/v1/params.d.ts +32 -0
  39. package/dist/proto/gen/ault/accountx/v1/query.d.ts +88 -0
  40. package/dist/proto/gen/ault/accountx/v1/tx.d.ts +52 -0
  41. package/dist/proto/gen/ault/agent/v1/tx.d.ts +4 -5
  42. package/dist/proto/gen/ault/authority/v1/authority.d.ts +2 -0
  43. package/dist/proto/gen/ault/clob/v1/genesis.d.ts +6 -5
  44. package/dist/proto/gen/ault/clob/v1/query.d.ts +14 -0
  45. package/dist/proto/gen/ault/clob/v1/tx.d.ts +30 -3
  46. package/dist/proto/gen/ault/common/v1/system.d.ts +31 -0
  47. package/dist/proto/gen/ault/license/v1/genesis.d.ts +1 -26
  48. package/dist/proto/gen/ault/license/v1/license.d.ts +0 -26
  49. package/dist/proto/gen/ault/license/v1/query.d.ts +44 -18
  50. package/dist/proto/gen/ault/market/v1/market.d.ts +1 -0
  51. package/dist/proto/gen/ault/market/v1/tx.d.ts +9 -0
  52. package/dist/proto/gen/ault/miner/v1/genesis.d.ts +52 -84
  53. package/dist/proto/gen/ault/miner/v1/miner.d.ts +10 -45
  54. package/dist/proto/gen/ault/miner/v1/query.d.ts +0 -13
  55. package/dist/proto/gen/ault/spot/v1/genesis.d.ts +2 -2
  56. package/dist/proto/gen/ault/spot/v1/order.d.ts +12 -4
  57. package/dist/proto/gen/ault/systemtx/v1/genesis.d.ts +37 -0
  58. package/dist/proto/gen/ault/tokenregistry/v1/genesis.d.ts +3 -3
  59. package/dist/proto/gen/ault/tokenregistry/v1/query.d.ts +2 -2
  60. package/dist/proto/gen/ault/tokenregistry/v1/tokenregistry.d.ts +24 -15
  61. package/dist/proto/gen/ault/tokenregistry/v1/tx.d.ts +1 -16
  62. package/dist/proto/gen/cosmos/bank/v1beta1/bank.d.ts +119 -0
  63. package/dist/proto/gen/cosmos/bank/v1beta1/query.d.ts +264 -0
  64. package/dist/proto/gen/cosmos/distribution/v1beta1/query.d.ts +203 -0
  65. package/dist/proto/gen/cosmos/query/v1/query.d.ts +1 -0
  66. package/dist/proto/gen/cosmos/staking/v1beta1/query.d.ts +275 -0
  67. package/dist/proto/gen/google/api/http.d.ts +20 -28
  68. package/dist/proto/gen/tendermint/abci/types.d.ts +23 -0
  69. package/dist/proto/tx-decode.d.ts +18 -0
  70. package/dist/rest/accountx.d.ts +8 -0
  71. package/dist/rest/bank.d.ts +15 -0
  72. package/dist/rest/clob.d.ts +9 -1
  73. package/dist/rest/context.d.ts +4 -4
  74. package/dist/rest/dex-types.generated.d.ts +363 -120
  75. package/dist/rest/dex.d.ts +6 -0
  76. package/dist/rest/dex.generated.d.ts +599 -83
  77. package/dist/rest/feemarket.d.ts +114 -0
  78. package/dist/rest/license.d.ts +21 -59
  79. package/dist/rest/miner.d.ts +16 -46
  80. package/dist/rest/portfolio.d.ts +103 -0
  81. package/dist/rest/staking.d.ts +14 -28
  82. package/dist/rest/tokenregistry.d.ts +3 -1
  83. package/dist/rest/types.d.ts +82 -858
  84. package/dist/utils/address.d.ts +2 -0
  85. package/dist/utils/opaque-id.d.ts +25 -0
  86. package/dist/utils/tx-hash.d.ts +1 -0
  87. package/dist/ws/client.d.ts +45 -5
  88. package/dist/ws/types.d.ts +377 -34
  89. package/package.json +2 -1
  90. package/dist/agent/create-agent-client.d.ts +0 -3
@@ -2,5 +2,7 @@ export declare function evmToAult(evmAddress: string): string;
2
2
  export declare function aultToEvm(aultAddress: string): string;
3
3
  export declare function isValidAultAddress(address: string): boolean;
4
4
  export declare function isValidEvmAddress(address: string): boolean;
5
+ export declare function addressEquals(a: string, b: string): boolean;
6
+ export declare function addressBytes(s: string): Uint8Array | null;
5
7
  export declare function isValidValidatorAddress(address: string): boolean;
6
8
  export declare function assertValidatorAddress(address: string): string;
@@ -0,0 +1,25 @@
1
+ declare abstract class OpaqueId {
2
+ private readonly bytes;
3
+ protected constructor(bytes: Uint8Array);
4
+ toBytes(): Uint8Array;
5
+ toHex(): string;
6
+ toBase64(): string;
7
+ toString(): string;
8
+ protected equalsBytes(other: OpaqueId): boolean;
9
+ }
10
+ export declare class MarketId extends OpaqueId {
11
+ static fromHex(hex: string): MarketId;
12
+ static fromBase64(b64: string): MarketId;
13
+ static fromBytes(bytes: Uint8Array): MarketId;
14
+ private static assertNonEmpty;
15
+ equals(other: MarketId): boolean;
16
+ }
17
+ export declare const ORDER_ID_LENGTH = 16;
18
+ export declare class OrderId extends OpaqueId {
19
+ static fromHex(hex: string): OrderId;
20
+ static fromBase64(b64: string): OrderId;
21
+ static fromBytes(bytes: Uint8Array): OrderId;
22
+ private static assertLength;
23
+ equals(other: OrderId): boolean;
24
+ }
25
+ export {};
@@ -0,0 +1 @@
1
+ export declare function normalizeTxHash(raw: string): string;
@@ -1,7 +1,10 @@
1
- import type { DexWsEventMap, DexWsOptions, PayloadFor, Subscription, SubscriptionHandlers, WsConnectionState } from "./types";
1
+ import type { DexWsEventMap, DexWsOptions, PayloadFor, Subscription, SubscriptionHandlers, WsChannelType, WsConnectionState, WsSubscription } from "./types";
2
+ /** Standard `WebSocket.readyState` value for an open socket. */
3
+ export declare const WS_READY_STATE_OPEN = 1;
2
4
  export declare class DexWsClient {
3
5
  private url;
4
6
  private options;
7
+ private userFactory;
5
8
  private ws;
6
9
  private connectionState;
7
10
  private subscriptions;
@@ -10,20 +13,57 @@ export declare class DexWsClient {
10
13
  private reconnectAttempt;
11
14
  private reconnectTimer;
12
15
  private connectResolvers;
16
+ private connectGeneration;
13
17
  constructor(url: string, opts?: DexWsOptions);
14
18
  get state(): WsConnectionState;
15
19
  connect(): Promise<void>;
16
20
  disconnect(): void;
17
- subscribe<T extends string>(topic: T, handlers: SubscriptionHandlers<PayloadFor<T>>, options?: {
21
+ /**
22
+ * Subscribe to a channel. `handlers.onData` receives every frame (snapshot
23
+ * and deltas alike); the SDK makes no assumption that the first frame is a
24
+ * delta. Returns a handle whose `unsubscribe()` tears the subscription down.
25
+ */
26
+ subscribe<T extends WsChannelType>(subscription: WsSubscription & {
27
+ type: T;
28
+ }, handlers: SubscriptionHandlers<PayloadFor<T>>, options?: {
18
29
  ttl?: number;
19
30
  }): Subscription;
20
- unsubscribe(topic: string): void;
31
+ /**
32
+ * Send a subscribe for an already-registered active subscription and wire its
33
+ * ack/error/onSubscribed handling. Shared by the initial subscribe and the
34
+ * reconnect replay so both paths surface failures via onError instead of
35
+ * leaving a silent dead subscription.
36
+ */
37
+ private dispatchSubscribe;
38
+ /**
39
+ * Enforce the per-channel required key at runtime. The `WsSubscription` union
40
+ * already encodes this at compile time, but a caller can cast through it (e.g.
41
+ * `type` via `as never` for a not-yet-typed channel). Registering a partial
42
+ * sub is unsafe: a user channel with no `user` would match every frame on that
43
+ * channel (frameMatches returns true for orderUpdates/userEvents) until the
44
+ * async server reject lands. Throw before `subscriptions.set` instead.
45
+ */
46
+ private assertRequiredKey;
47
+ /**
48
+ * Guard against multiplexing two different users across a user-ambiguous
49
+ * channel (orderUpdates/userEvents) on one connection. Their frames carry no
50
+ * `user`, so a second user's subscription would fan out into the first's
51
+ * handler and vice-versa, leaking private order flow. Re-subscribing the same
52
+ * user is allowed (it just refreshes handlers/ttl).
53
+ */
54
+ private assertNoUserAmbiguity;
55
+ unsubscribe(subscription: WsSubscription): void;
21
56
  on<E extends keyof DexWsEventMap>(event: E, handler: DexWsEventMap[E]): () => void;
22
57
  private createSocket;
58
+ private resolveFactory;
23
59
  private handleMessage;
60
+ private handleChannelError;
61
+ private handleAck;
62
+ private handleExpired;
63
+ private dispatchData;
64
+ private deliver;
24
65
  private send;
25
- private sendCommand;
26
- private commandKey;
66
+ private sendSubscribe;
27
67
  private scheduleReconnect;
28
68
  private resubscribeAll;
29
69
  private resolveConnect;
@@ -1,57 +1,393 @@
1
- import type { OrderbookResponse, TradeResponse, TickerResponse, OrderResponse, BalancesResponse, OHLCVEntry } from "../rest/dex.generated";
2
- export type WsEvent = "snapshot" | "new_trades" | "update" | "bar_update" | "response" | "subscription_expired";
3
- export interface WsServerMessage<T = unknown> {
4
- topic: string;
5
- event: WsEvent;
6
- data: T;
7
- ts: number;
8
- height: number;
1
+ /** Market channels require a `coin` (BASE/QUOTE) subscription field. */
2
+ export type WsMarketChannel = "l2Book" | "bbo" | "trades" | "candle" | "activeAssetCtx";
3
+ /** User channels require a `user` (address) subscription field. */
4
+ export type WsUserChannel = "orderUpdates" | "openOrders" | "userFills" | "userEvents" | "spotState";
5
+ /** Keyless channels require no key. `chainBlock` is an Ault extension. */
6
+ export type WsKeylessChannel = "allMids" | "chainBlock";
7
+ export type WsChannelType = WsMarketChannel | WsUserChannel | WsKeylessChannel;
8
+ /** Named candle intervals accepted by the `candle` channel. */
9
+ export type CandleInterval = "1m" | "3m" | "5m" | "15m" | "30m" | "1h" | "2h" | "4h" | "8h" | "12h" | "1d" | "3d" | "1w" | "1M";
10
+ /**
11
+ * A subscription descriptor, modeled as a discriminated union on `type` so the
12
+ * required key per channel is enforced at compile time: market channels carry
13
+ * `coin`, `candle` additionally carries `interval`, user channels carry `user`,
14
+ * and keyless channels carry neither. The client omits empty optionals on the
15
+ * wire. A runtime guard in `subscribe()` re-checks the same invariant for
16
+ * untyped callers (e.g. `type` cast through `as never`).
17
+ */
18
+ export type WsSubscription = {
19
+ type: Exclude<WsMarketChannel, "candle">;
20
+ coin: string;
21
+ user?: undefined;
22
+ interval?: undefined;
23
+ } | {
24
+ type: "candle";
25
+ coin: string;
26
+ interval: CandleInterval;
27
+ user?: undefined;
28
+ } | {
29
+ type: WsUserChannel;
30
+ user: string;
31
+ coin?: undefined;
32
+ interval?: undefined;
33
+ } | {
34
+ type: WsKeylessChannel;
35
+ coin?: undefined;
36
+ user?: undefined;
37
+ interval?: undefined;
38
+ };
39
+ export type WsSide = "buy" | "sell";
40
+ /**
41
+ * A single book level. `px` and `sz` are canonical decimal strings with the
42
+ * relay's LegacyDec 18-decimal padding already collapsed server-side (`"1.5"`,
43
+ * not `"1.500000000000000000"`); `sz` is in human units. Do not re-pad or
44
+ * assume a fixed precision. `n` is the order count at the level and is `0`
45
+ * until the relay supplies it.
46
+ */
47
+ export interface WsLevel {
48
+ px: string;
49
+ sz: string;
50
+ n: number;
9
51
  }
10
- export interface WsSubscribeCommand {
11
- action: "subscribe";
12
- topic: string;
13
- ttl?: number;
52
+ /** `allMids` — map of every market's current mid price (decimal strings). */
53
+ export interface WsAllMids {
54
+ mids: Record<string, string>;
14
55
  }
15
- export interface WsUnsubscribeCommand {
16
- action: "unsubscribe";
17
- topic: string;
56
+ /**
57
+ * `l2Book` — `levels[0]` is bids (descending), `levels[1]` is asks (ascending).
58
+ * Snapshot-gated: the first frame after subscribe is the book snapshot, then
59
+ * per-block deltas stream.
60
+ */
61
+ export interface WsBook {
62
+ coin: string;
63
+ levels: [WsLevel[], WsLevel[]];
64
+ time: number;
18
65
  }
19
- export type WsClientCommand = WsSubscribeCommand | WsUnsubscribeCommand;
20
- export interface WsCommandResponse {
21
- action: string;
22
- topic?: string;
23
- success: boolean;
24
- error?: string;
25
- ttl?: number;
66
+ /**
67
+ * `bbo` — best bid/offer. `bbo[0]` is the best bid (or `null`), `bbo[1]` the
68
+ * best ask (or `null`). Emitted only when the top of book changes.
69
+ */
70
+ export interface WsBbo {
71
+ coin: string;
72
+ time: number;
73
+ bbo: [WsLevel | null, WsLevel | null];
74
+ }
75
+ /** A single execution in the `trades` array. `tid` is a 50-bit numeric id. */
76
+ export interface WsTrade {
77
+ coin: string;
78
+ side: WsSide;
79
+ px: string;
80
+ sz: string;
81
+ time: number;
82
+ tid: number;
26
83
  }
84
+ /** `trades` — array of executions in the block. */
85
+ export type WsTrades = WsTrade[];
27
86
  /**
28
- * Payload for the `chain:block` topic. Emitted once per new block regardless
29
- * of market activity so subscribers can drive liveness indicators.
30
- *
31
- * The block header fields (hash, proposer, tx_count, gas_used, gas_wanted)
32
- * are optional because older chain versions may not supply them.
87
+ * A candle bar. `t` is the open time, `T` the close time (`t + period`), both
88
+ * in ms. `s` / `i` echo the coin and interval. OHLCV values are numbers; `n`
89
+ * is the trade count (`0` for snapshot bars).
90
+ */
91
+ export interface WsCandle {
92
+ t: number;
93
+ T: number;
94
+ s: string;
95
+ i: CandleInterval;
96
+ o: number;
97
+ c: number;
98
+ h: number;
99
+ l: number;
100
+ v: number;
101
+ n: number;
102
+ }
103
+ /**
104
+ * `candle` — always an array. The snapshot sends recent history (up to 300
105
+ * bars); a streaming update sends a single-element array.
106
+ */
107
+ export type WsCandles = WsCandle[];
108
+ /**
109
+ * `activeAssetCtx` — per-block market context. The Hyperliquid base fields
110
+ * (`dayNtlVlm`, `prevDayPx`, `markPx`, `midPx`, `circulatingSupply`) are JSON
111
+ * numbers; the Ault extension fields are decimal strings to preserve precision
112
+ * past 2^53. `midPx` and the extension fields are present only when the
113
+ * underlying value resolved (the relay omits them otherwise).
114
+ * `circulatingSupply` is always `0` (not tracked).
115
+ */
116
+ export interface WsActiveAssetCtxData {
117
+ dayNtlVlm: number;
118
+ prevDayPx: number;
119
+ markPx: number;
120
+ midPx?: number;
121
+ circulatingSupply: number;
122
+ high?: string;
123
+ low?: string;
124
+ last?: string;
125
+ average?: string;
126
+ bid?: string;
127
+ bidVolume?: string;
128
+ ask?: string;
129
+ askVolume?: string;
130
+ vwap?: string;
131
+ change?: string;
132
+ percentage?: string;
133
+ baseVolume: string;
134
+ quoteVolume: string;
135
+ }
136
+ export interface WsActiveAssetCtx {
137
+ coin: string;
138
+ ctx: WsActiveAssetCtxData;
139
+ }
140
+ /** HL-collapsed public order status. */
141
+ export type WsOrderStatus = "open" | "filled" | "canceled" | "triggered" | "unknown";
142
+ /** Ault extension: the granular chain-side order status. */
143
+ export type WsChainOrderStatus = "open" | "partially_filled" | "filled" | "cancelled" | "expired" | "triggered_pending" | "unknown";
144
+ /**
145
+ * The basic order shape shared by `orderUpdates` and `openOrders`. `oid` is the
146
+ * JS-safe 50-bit numeric id; `oidHex` is the full 32-char hex id. `sz` is the
147
+ * current remaining size, `origSz` the original. Prices/sizes are decimal
148
+ * strings in human units.
149
+ */
150
+ export interface WsBasicOrder {
151
+ coin: string;
152
+ side: WsSide;
153
+ limitPx: string;
154
+ sz: string;
155
+ oid: number;
156
+ oidHex: string;
157
+ timestamp: number;
158
+ origSz: string;
159
+ }
160
+ /** A single entry in the `orderUpdates` array. */
161
+ export interface WsOrderUpdate {
162
+ order: WsBasicOrder;
163
+ status: WsOrderStatus;
164
+ /** Ault extension: granular chain status. */
165
+ chainStatus: WsChainOrderStatus;
166
+ statusTimestamp: number;
167
+ }
168
+ /** `orderUpdates` — array of changed orders. */
169
+ export type WsOrderUpdates = WsOrderUpdate[];
170
+ /** `openOrders` — snapshot-only. `dex` is always `"ault"`. */
171
+ export interface WsOpenOrders {
172
+ dex: string;
173
+ user: string;
174
+ orders: WsBasicOrder[];
175
+ }
176
+ /**
177
+ * A single fill, shared by `userFills` and the `userEvents` fills shape.
178
+ * `crossed` is `true` for taker fills (all fills are taker-side today). `fee`
179
+ * is estimated from the taker rate; `feeToken` is the quote currency. `oid` is
180
+ * the JS-safe 50-bit numeric id; `oidHex` is the full hex chain order id,
181
+ * matching the orders channels and the REST order/trade surfaces.
182
+ */
183
+ export interface WsFill {
184
+ coin: string;
185
+ px: string;
186
+ sz: string;
187
+ side: WsSide;
188
+ time: number;
189
+ oid: number;
190
+ oidHex: string;
191
+ /**
192
+ * Client order id (hex, 8 bytes). Present on snapshot fills when the order
193
+ * carried one; live fills omit it until the relay event carries the cloid.
194
+ */
195
+ cloid?: string;
196
+ tid: number;
197
+ crossed: boolean;
198
+ fee: string;
199
+ feeToken: string;
200
+ }
201
+ /**
202
+ * `userFills` — the first frame after subscribe is the snapshot (recent fills,
203
+ * up to 200) with `isSnapshot: true`; live frames carry `isSnapshot: false`.
33
204
  */
34
- export interface BlockUpdate {
205
+ export interface WsUserFills {
206
+ isSnapshot: boolean;
207
+ user: string;
208
+ fills: WsFill[];
209
+ }
210
+ /** A system-initiated cancel in the `userEvents` nonUserCancel shape. */
211
+ export interface WsNonUserCancel {
212
+ coin: string;
213
+ oid: number;
214
+ }
215
+ /**
216
+ * `userEvents` — delivered on the `user` channel (not `userEvents`). Each block
217
+ * carries one of two shapes: a `fills` array or a `nonUserCancel` array. A
218
+ * non-user cancel is currently emitted only for expired orders.
219
+ */
220
+ export type WsUserEvents = {
221
+ fills: WsFill[];
222
+ } | {
223
+ nonUserCancel: WsNonUserCancel[];
224
+ };
225
+ /**
226
+ * A single balance entry. `hold` is the amount locked in open orders. `token`
227
+ * is `0` for all assets (Ault assigns no numeric token ids) and `entryNtl` is
228
+ * `"0"` (cost basis not tracked). Amounts are decimal strings in human units.
229
+ */
230
+ export interface WsSpotBalance {
231
+ coin: string;
232
+ token: number;
233
+ hold: string;
234
+ total: string;
235
+ entryNtl: string;
236
+ }
237
+ /**
238
+ * `spotState` — the first frame after subscribe is the full balance set;
239
+ * subsequent frames are **deltas** containing only the balances that changed in
240
+ * the block. Merge them into local state by `coin`. There is no `isSnapshot`
241
+ * flag (matching Hyperliquid).
242
+ */
243
+ export interface WsSpotState {
244
+ user: string;
245
+ spotState: {
246
+ balances: WsSpotBalance[];
247
+ };
248
+ }
249
+ /**
250
+ * `chainBlock` — **Ault extension.** One frame per finalized block. `height`
251
+ * and `timestamp` are always present (both JSON numbers). `hash`, `proposer`,
252
+ * `txCount`, `gasUsed`, and `gasWanted` are present only when the chain
253
+ * publisher supplied block info (older chains omit them).
254
+ */
255
+ export interface WsChainBlock {
35
256
  height: number;
36
257
  timestamp: number;
37
258
  hash?: string;
38
259
  proposer?: string;
39
- tx_count?: number;
40
- gas_used?: number;
41
- gas_wanted?: number;
260
+ txCount?: number;
261
+ gasUsed?: number;
262
+ gasWanted?: number;
263
+ }
264
+ export interface WsPayloadMap {
265
+ allMids: WsAllMids;
266
+ l2Book: WsBook;
267
+ bbo: WsBbo;
268
+ trades: WsTrades;
269
+ candle: WsCandles;
270
+ activeAssetCtx: WsActiveAssetCtx;
271
+ orderUpdates: WsOrderUpdates;
272
+ openOrders: WsOpenOrders;
273
+ userFills: WsUserFills;
274
+ userEvents: WsUserEvents;
275
+ spotState: WsSpotState;
276
+ chainBlock: WsChainBlock;
277
+ }
278
+ /** Resolves a channel type to its payload shape. */
279
+ export type PayloadFor<T extends WsChannelType> = T extends keyof WsPayloadMap ? WsPayloadMap[T] : unknown;
280
+ /**
281
+ * Every server message is a two-field envelope. `channel` is the subscription
282
+ * `type`, with one exception: `userEvents` data is delivered on the `user`
283
+ * channel. Three control channels (`subscriptionResponse`, `error`,
284
+ * `subscriptionExpired`) carry lifecycle payloads rather than channel data.
285
+ */
286
+ export interface WsServerMessage<T = unknown> {
287
+ channel: string;
288
+ data: T;
289
+ }
290
+ /**
291
+ * Data attached to a `subscriptionResponse`. Echoes the subscription back so
292
+ * the client's view round-trips intact — including ignored fields like `dex`
293
+ * and, for user channels, the `user` in the exact format the client sent
294
+ * (bech32 or `0x`). `ttl` is the effective (clamped) lifetime; `error` is
295
+ * present on failure.
296
+ */
297
+ export interface WsSubscriptionAck {
298
+ type: string;
299
+ coin?: string;
300
+ user?: string;
301
+ interval?: string;
302
+ ttl?: number;
303
+ dex?: string;
304
+ error?: string;
305
+ [key: string]: unknown;
42
306
  }
43
- export type PayloadFor<T extends string> = T extends `orderbook:${string}` ? OrderbookResponse : T extends `trades:${string}` ? TradeResponse[] : T extends `ticker:${string}` ? TickerResponse : T extends `chart:${string}` ? OHLCVEntry : T extends `orders:${string}` ? OrderResponse[] : T extends `balances:${string}` ? BalancesResponse : T extends `mytrades:${string}` ? TradeResponse[] : T extends "chain:block" ? BlockUpdate : unknown;
307
+ /**
308
+ * Data attached to an `error` frame (protocol-level failure). When the failure
309
+ * is tied to a specific subscribe/unsubscribe command (e.g. rate limit,
310
+ * rejection), the server echoes the offending `subscription` so the client can
311
+ * reject the matching pending command and notify only that subscription instead
312
+ * of relying on the 10s command timeout.
313
+ */
314
+ export interface WsErrorData {
315
+ message: string;
316
+ subscription?: WsSubscription;
317
+ }
318
+ /** Data attached to a `subscriptionExpired` frame. */
319
+ export interface WsSubscriptionExpiredData {
320
+ subscription: WsSubscription;
321
+ reason: string;
322
+ }
323
+ /**
324
+ * The subscription object sent on the wire (descriptor + optional ttl). Modeled
325
+ * as an intersection because `WsSubscription` is a discriminated union — an
326
+ * interface cannot `extends` a union, so we add the `ttl` field across every
327
+ * member instead.
328
+ *
329
+ * Ault extension: `ttl` is the subscription lifetime in seconds. `0` = no
330
+ * expiry. The server caps it at 3,600 (1 hour) and echoes the effective value
331
+ * in the ack.
332
+ */
333
+ export type WsSubscriptionRequest = WsSubscription & {
334
+ ttl?: number;
335
+ };
336
+ export interface WsSubscribeCommand {
337
+ method: "subscribe";
338
+ subscription: WsSubscriptionRequest;
339
+ }
340
+ export interface WsUnsubscribeCommand {
341
+ method: "unsubscribe";
342
+ subscription: WsSubscription;
343
+ }
344
+ export type WsClientCommand = WsSubscribeCommand | WsUnsubscribeCommand;
44
345
  export interface SubscriptionHandlers<T> {
346
+ /** Called for every data frame on the channel (snapshot and deltas alike). */
45
347
  onData: (data: T, message: WsServerMessage<T>) => void;
348
+ /** Called on subscribe failure or a per-frame handler throw. */
46
349
  onError?: (error: Error) => void;
47
- onSubscribed?: () => void;
350
+ /**
351
+ * Called once the server acks the subscription. The ack carries the
352
+ * effective (clamped) `ttl` and the echoed `user` in the client's original
353
+ * format.
354
+ */
355
+ onSubscribed?: (ack: WsSubscriptionAck) => void;
356
+ /** Called when a TTL-based subscription expires server-side. */
48
357
  onExpired?: () => void;
49
358
  }
50
359
  export interface Subscription {
51
- topic: string;
360
+ subscription: WsSubscription;
52
361
  unsubscribe: () => void;
53
362
  }
54
363
  export type WsConnectionState = "disconnected" | "connecting" | "connected" | "reconnecting";
364
+ /**
365
+ * Subset of the WebSocket DOM type that the SDK actually uses. Browser
366
+ * `WebSocket`, `isows.WebSocket`, the `ws` package, and lightweight test
367
+ * doubles all structurally satisfy this interface — none of them need to
368
+ * extend `EventTarget` or expose `addEventListener`.
369
+ *
370
+ * Event parameters use `any` so that the lib.dom `WebSocket` (with its
371
+ * richer `Event` / `CloseEvent` / `MessageEvent` types) remains assignable
372
+ * to this interface under `strictFunctionTypes`. The SDK reads `code`,
373
+ * `reason`, and `data` from these events at runtime — those properties are
374
+ * spec-guaranteed for real WebSocket implementations.
375
+ */
376
+ export interface WebSocketLike {
377
+ readyState: number;
378
+ send(data: string): void;
379
+ close(code?: number, reason?: string): void;
380
+ onopen: ((ev: any) => any) | null;
381
+ onclose: ((ev: any) => any) | null;
382
+ onerror: ((ev: any) => any) | null;
383
+ onmessage: ((ev: any) => any) | null;
384
+ }
385
+ /**
386
+ * Factory used to construct the underlying socket when the SDK connects.
387
+ * Must return synchronously — the SDK wires the standard
388
+ * `onopen`/`onclose`/`onerror`/`onmessage` handlers immediately after.
389
+ */
390
+ export type WebSocketFactory = (url: string | URL, protocols?: string | string[]) => WebSocketLike;
55
391
  export interface DexWsOptions {
56
392
  /** Auto-reconnect on unexpected disconnect (default: true). */
57
393
  reconnect?: boolean;
@@ -61,6 +397,13 @@ export interface DexWsOptions {
61
397
  reconnectDelay?: number;
62
398
  /** Max reconnect delay in ms (default: 30000). */
63
399
  maxReconnectDelay?: number;
400
+ /**
401
+ * Optional factory for constructing the underlying socket. When omitted the
402
+ * SDK reads `globalThis.WebSocket` lazily at connect time, falling back to
403
+ * `isows` for Node environments that lack a global. Pass an explicit factory
404
+ * to inject a mock or polyfilled implementation.
405
+ */
406
+ createWebSocket?: WebSocketFactory;
64
407
  }
65
408
  export interface DexWsEventMap {
66
409
  open: () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ault-sdk-ts",
3
- "version": "0.0.2-alpha.8",
3
+ "version": "0.1.0",
4
4
  "description": "TypeScript SDK for the Ault blockchain with high-level transaction methods and REST query clients",
5
5
  "keywords": [
6
6
  "ault",
@@ -48,6 +48,7 @@
48
48
  "gen:openapi": "orval",
49
49
  "gen:proto": "node scripts/generate-protos.mjs",
50
50
  "gen:eip712": "node scripts/generate-eip712-registry.mjs",
51
+ "gen:all": "npm run gen:openapi && npm run gen:proto && npm run gen:eip712 && pnpm lint:fix && pnpm format",
51
52
  "prepare": "node scripts/prepare.mjs",
52
53
  "build": "tsup && tsc -p tsconfig.build.json && npx tsc-alias -p tsconfig.build.json",
53
54
  "dev": "tsup --watch",
@@ -1,3 +0,0 @@
1
- import type { AgentClient, AgentClientOptions } from "../high-level/types";
2
- export { AGENT_DEFAULTS } from "./sign-and-broadcast";
3
- export declare function createAgentClient(options: AgentClientOptions): Promise<AgentClient>;