ault-sdk-ts 0.0.2-alpha.8 → 0.3.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.
- package/README.md +378 -50
- package/dist/agent/attach.d.ts +26 -0
- package/dist/agent/sign-and-broadcast.d.ts +9 -2
- package/dist/agent/tx/clob.d.ts +8 -1
- package/dist/agent/tx-executor.d.ts +24 -2
- package/dist/client.d.ts +6 -7
- package/dist/core/clob-gas.d.ts +28 -0
- package/dist/core/clob-msgs.d.ts +31 -5
- package/dist/core/clob-responses.d.ts +20 -0
- package/dist/core/cloid.d.ts +4 -0
- package/dist/core/errors.d.ts +79 -0
- package/dist/core/manifest-fetcher.d.ts +12 -0
- package/dist/core/manifest-resolver.d.ts +131 -0
- package/dist/core/manifest-types.d.ts +104 -0
- package/dist/core/network.d.ts +42 -13
- package/dist/eip712/msg.generated.d.ts +26 -10
- package/dist/eip712/registry.d.ts +2 -0
- package/dist/eip712/sign-and-broadcast.d.ts +27 -3
- package/dist/high-level/cloid-lookup.d.ts +9 -0
- package/dist/high-level/create-client.d.ts +15 -11
- package/dist/high-level/tx/accountx.d.ts +3 -0
- package/dist/high-level/tx/agent.d.ts +1 -1
- package/dist/high-level/tx/clob.d.ts +1 -1
- package/dist/high-level/tx/context.d.ts +8 -0
- package/dist/high-level/tx/license.d.ts +1 -1
- package/dist/high-level/tx/miner.d.ts +1 -1
- package/dist/high-level/tx/reward.d.ts +1 -1
- package/dist/high-level/tx/staking.d.ts +1 -1
- package/dist/high-level/tx-executor.d.ts +23 -3
- package/dist/high-level/types.d.ts +356 -100
- package/dist/high-level-client.d.ts +1 -1
- package/dist/index.cjs +15590 -7271
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +15699 -7405
- package/dist/index.js.map +1 -1
- package/dist/proto/gen/ault/accountx/v1/genesis.d.ts +38 -0
- package/dist/proto/gen/ault/accountx/v1/params.d.ts +32 -0
- package/dist/proto/gen/ault/accountx/v1/query.d.ts +88 -0
- package/dist/proto/gen/ault/accountx/v1/tx.d.ts +52 -0
- package/dist/proto/gen/ault/agent/v1/tx.d.ts +4 -5
- package/dist/proto/gen/ault/authority/v1/authority.d.ts +2 -0
- package/dist/proto/gen/ault/clob/v1/genesis.d.ts +6 -5
- package/dist/proto/gen/ault/clob/v1/query.d.ts +14 -0
- package/dist/proto/gen/ault/clob/v1/tx.d.ts +30 -3
- package/dist/proto/gen/ault/common/v1/system.d.ts +31 -0
- package/dist/proto/gen/ault/license/v1/genesis.d.ts +1 -26
- package/dist/proto/gen/ault/license/v1/license.d.ts +0 -26
- package/dist/proto/gen/ault/license/v1/query.d.ts +44 -18
- package/dist/proto/gen/ault/market/v1/market.d.ts +1 -0
- package/dist/proto/gen/ault/market/v1/tx.d.ts +9 -0
- package/dist/proto/gen/ault/miner/v1/genesis.d.ts +52 -84
- package/dist/proto/gen/ault/miner/v1/miner.d.ts +10 -45
- package/dist/proto/gen/ault/miner/v1/query.d.ts +0 -13
- package/dist/proto/gen/ault/spot/v1/genesis.d.ts +2 -2
- package/dist/proto/gen/ault/spot/v1/order.d.ts +12 -4
- package/dist/proto/gen/ault/systemtx/v1/genesis.d.ts +37 -0
- package/dist/proto/gen/ault/tokenregistry/v1/genesis.d.ts +3 -3
- package/dist/proto/gen/ault/tokenregistry/v1/query.d.ts +2 -2
- package/dist/proto/gen/ault/tokenregistry/v1/tokenregistry.d.ts +24 -15
- package/dist/proto/gen/ault/tokenregistry/v1/tx.d.ts +1 -16
- package/dist/proto/gen/cosmos/bank/v1beta1/bank.d.ts +119 -0
- package/dist/proto/gen/cosmos/bank/v1beta1/query.d.ts +264 -0
- package/dist/proto/gen/cosmos/distribution/v1beta1/query.d.ts +203 -0
- package/dist/proto/gen/cosmos/query/v1/query.d.ts +1 -0
- package/dist/proto/gen/cosmos/staking/v1beta1/query.d.ts +275 -0
- package/dist/proto/gen/google/api/http.d.ts +20 -28
- package/dist/proto/gen/tendermint/abci/types.d.ts +23 -0
- package/dist/proto/tx-decode.d.ts +18 -0
- package/dist/rest/accountx.d.ts +8 -0
- package/dist/rest/bank.d.ts +15 -0
- package/dist/rest/clob.d.ts +9 -1
- package/dist/rest/context.d.ts +4 -4
- package/dist/rest/dex-types.generated.d.ts +434 -120
- package/dist/rest/dex.d.ts +7 -0
- package/dist/rest/dex.generated.d.ts +657 -83
- package/dist/rest/feemarket.d.ts +114 -0
- package/dist/rest/license.d.ts +21 -59
- package/dist/rest/miner.d.ts +16 -46
- package/dist/rest/portfolio.d.ts +103 -0
- package/dist/rest/staking.d.ts +14 -28
- package/dist/rest/tokenregistry.d.ts +3 -1
- package/dist/rest/types.d.ts +82 -858
- package/dist/utils/address.d.ts +2 -0
- package/dist/utils/opaque-id.d.ts +25 -0
- package/dist/utils/tx-hash.d.ts +1 -0
- package/dist/ws/client.d.ts +45 -5
- package/dist/ws/types.d.ts +379 -34
- package/package.json +2 -1
- package/dist/agent/create-agent-client.d.ts +0 -3
package/dist/utils/address.d.ts
CHANGED
|
@@ -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;
|
package/dist/ws/client.d.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
|
26
|
-
private commandKey;
|
|
66
|
+
private sendSubscribe;
|
|
27
67
|
private scheduleReconnect;
|
|
28
68
|
private resubscribeAll;
|
|
29
69
|
private resolveConnect;
|
package/dist/ws/types.d.ts
CHANGED
|
@@ -1,57 +1,395 @@
|
|
|
1
|
-
|
|
2
|
-
export type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
|
|
32
|
-
|
|
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` on taker legs and `false` on maker legs; `fee` is
|
|
179
|
+
* estimated from the taker or maker rate accordingly, in the quote currency
|
|
180
|
+
* (`feeToken`). Fills from nodes without the relay is_taker flag (pre-ault#592)
|
|
181
|
+
* arrive as `crossed: true` with a taker-rate fee. `oid` is the JS-safe 50-bit
|
|
182
|
+
* numeric id; `oidHex` is the full hex chain order id, matching the orders
|
|
183
|
+
* channels and the REST order/trade surfaces.
|
|
184
|
+
*/
|
|
185
|
+
export interface WsFill {
|
|
186
|
+
coin: string;
|
|
187
|
+
px: string;
|
|
188
|
+
sz: string;
|
|
189
|
+
side: WsSide;
|
|
190
|
+
time: number;
|
|
191
|
+
oid: number;
|
|
192
|
+
oidHex: string;
|
|
193
|
+
/**
|
|
194
|
+
* Client order id (hex, 8 bytes). Present when the order carried one;
|
|
195
|
+
* absent when it didn't, or against pre-#957 nodes (no per-user relay fills).
|
|
196
|
+
*/
|
|
197
|
+
cloid?: string;
|
|
198
|
+
tid: number;
|
|
199
|
+
crossed: boolean;
|
|
200
|
+
fee: string;
|
|
201
|
+
feeToken: string;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* `userFills` — the first frame after subscribe is the snapshot (recent fills,
|
|
205
|
+
* up to 200) with `isSnapshot: true`; live frames carry `isSnapshot: false`.
|
|
33
206
|
*/
|
|
34
|
-
export interface
|
|
207
|
+
export interface WsUserFills {
|
|
208
|
+
isSnapshot: boolean;
|
|
209
|
+
user: string;
|
|
210
|
+
fills: WsFill[];
|
|
211
|
+
}
|
|
212
|
+
/** A system-initiated cancel in the `userEvents` nonUserCancel shape. */
|
|
213
|
+
export interface WsNonUserCancel {
|
|
214
|
+
coin: string;
|
|
215
|
+
oid: number;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* `userEvents` — delivered on the `user` channel (not `userEvents`). Each block
|
|
219
|
+
* carries one of two shapes: a `fills` array or a `nonUserCancel` array. A
|
|
220
|
+
* non-user cancel is currently emitted only for expired orders.
|
|
221
|
+
*/
|
|
222
|
+
export type WsUserEvents = {
|
|
223
|
+
fills: WsFill[];
|
|
224
|
+
} | {
|
|
225
|
+
nonUserCancel: WsNonUserCancel[];
|
|
226
|
+
};
|
|
227
|
+
/**
|
|
228
|
+
* A single balance entry. `hold` is the amount locked in open orders. `token`
|
|
229
|
+
* is `0` for all assets (Ault assigns no numeric token ids) and `entryNtl` is
|
|
230
|
+
* `"0"` (cost basis not tracked). Amounts are decimal strings in human units.
|
|
231
|
+
*/
|
|
232
|
+
export interface WsSpotBalance {
|
|
233
|
+
coin: string;
|
|
234
|
+
token: number;
|
|
235
|
+
hold: string;
|
|
236
|
+
total: string;
|
|
237
|
+
entryNtl: string;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* `spotState` — the first frame after subscribe is the full balance set;
|
|
241
|
+
* subsequent frames are **deltas** containing only the balances that changed in
|
|
242
|
+
* the block. Merge them into local state by `coin`. There is no `isSnapshot`
|
|
243
|
+
* flag (matching Hyperliquid).
|
|
244
|
+
*/
|
|
245
|
+
export interface WsSpotState {
|
|
246
|
+
user: string;
|
|
247
|
+
spotState: {
|
|
248
|
+
balances: WsSpotBalance[];
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* `chainBlock` — **Ault extension.** One frame per finalized block. `height`
|
|
253
|
+
* and `timestamp` are always present (both JSON numbers). `hash`, `proposer`,
|
|
254
|
+
* `txCount`, `gasUsed`, and `gasWanted` are present only when the chain
|
|
255
|
+
* publisher supplied block info (older chains omit them).
|
|
256
|
+
*/
|
|
257
|
+
export interface WsChainBlock {
|
|
35
258
|
height: number;
|
|
36
259
|
timestamp: number;
|
|
37
260
|
hash?: string;
|
|
38
261
|
proposer?: string;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
262
|
+
txCount?: number;
|
|
263
|
+
gasUsed?: number;
|
|
264
|
+
gasWanted?: number;
|
|
265
|
+
}
|
|
266
|
+
export interface WsPayloadMap {
|
|
267
|
+
allMids: WsAllMids;
|
|
268
|
+
l2Book: WsBook;
|
|
269
|
+
bbo: WsBbo;
|
|
270
|
+
trades: WsTrades;
|
|
271
|
+
candle: WsCandles;
|
|
272
|
+
activeAssetCtx: WsActiveAssetCtx;
|
|
273
|
+
orderUpdates: WsOrderUpdates;
|
|
274
|
+
openOrders: WsOpenOrders;
|
|
275
|
+
userFills: WsUserFills;
|
|
276
|
+
userEvents: WsUserEvents;
|
|
277
|
+
spotState: WsSpotState;
|
|
278
|
+
chainBlock: WsChainBlock;
|
|
279
|
+
}
|
|
280
|
+
/** Resolves a channel type to its payload shape. */
|
|
281
|
+
export type PayloadFor<T extends WsChannelType> = T extends keyof WsPayloadMap ? WsPayloadMap[T] : unknown;
|
|
282
|
+
/**
|
|
283
|
+
* Every server message is a two-field envelope. `channel` is the subscription
|
|
284
|
+
* `type`, with one exception: `userEvents` data is delivered on the `user`
|
|
285
|
+
* channel. Three control channels (`subscriptionResponse`, `error`,
|
|
286
|
+
* `subscriptionExpired`) carry lifecycle payloads rather than channel data.
|
|
287
|
+
*/
|
|
288
|
+
export interface WsServerMessage<T = unknown> {
|
|
289
|
+
channel: string;
|
|
290
|
+
data: T;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Data attached to a `subscriptionResponse`. Echoes the subscription back so
|
|
294
|
+
* the client's view round-trips intact — including ignored fields like `dex`
|
|
295
|
+
* and, for user channels, the `user` in the exact format the client sent
|
|
296
|
+
* (bech32 or `0x`). `ttl` is the effective (clamped) lifetime; `error` is
|
|
297
|
+
* present on failure.
|
|
298
|
+
*/
|
|
299
|
+
export interface WsSubscriptionAck {
|
|
300
|
+
type: string;
|
|
301
|
+
coin?: string;
|
|
302
|
+
user?: string;
|
|
303
|
+
interval?: string;
|
|
304
|
+
ttl?: number;
|
|
305
|
+
dex?: string;
|
|
306
|
+
error?: string;
|
|
307
|
+
[key: string]: unknown;
|
|
42
308
|
}
|
|
43
|
-
|
|
309
|
+
/**
|
|
310
|
+
* Data attached to an `error` frame (protocol-level failure). When the failure
|
|
311
|
+
* is tied to a specific subscribe/unsubscribe command (e.g. rate limit,
|
|
312
|
+
* rejection), the server echoes the offending `subscription` so the client can
|
|
313
|
+
* reject the matching pending command and notify only that subscription instead
|
|
314
|
+
* of relying on the 10s command timeout.
|
|
315
|
+
*/
|
|
316
|
+
export interface WsErrorData {
|
|
317
|
+
message: string;
|
|
318
|
+
subscription?: WsSubscription;
|
|
319
|
+
}
|
|
320
|
+
/** Data attached to a `subscriptionExpired` frame. */
|
|
321
|
+
export interface WsSubscriptionExpiredData {
|
|
322
|
+
subscription: WsSubscription;
|
|
323
|
+
reason: string;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* The subscription object sent on the wire (descriptor + optional ttl). Modeled
|
|
327
|
+
* as an intersection because `WsSubscription` is a discriminated union — an
|
|
328
|
+
* interface cannot `extends` a union, so we add the `ttl` field across every
|
|
329
|
+
* member instead.
|
|
330
|
+
*
|
|
331
|
+
* Ault extension: `ttl` is the subscription lifetime in seconds. `0` = no
|
|
332
|
+
* expiry. The server caps it at 3,600 (1 hour) and echoes the effective value
|
|
333
|
+
* in the ack.
|
|
334
|
+
*/
|
|
335
|
+
export type WsSubscriptionRequest = WsSubscription & {
|
|
336
|
+
ttl?: number;
|
|
337
|
+
};
|
|
338
|
+
export interface WsSubscribeCommand {
|
|
339
|
+
method: "subscribe";
|
|
340
|
+
subscription: WsSubscriptionRequest;
|
|
341
|
+
}
|
|
342
|
+
export interface WsUnsubscribeCommand {
|
|
343
|
+
method: "unsubscribe";
|
|
344
|
+
subscription: WsSubscription;
|
|
345
|
+
}
|
|
346
|
+
export type WsClientCommand = WsSubscribeCommand | WsUnsubscribeCommand;
|
|
44
347
|
export interface SubscriptionHandlers<T> {
|
|
348
|
+
/** Called for every data frame on the channel (snapshot and deltas alike). */
|
|
45
349
|
onData: (data: T, message: WsServerMessage<T>) => void;
|
|
350
|
+
/** Called on subscribe failure or a per-frame handler throw. */
|
|
46
351
|
onError?: (error: Error) => void;
|
|
47
|
-
|
|
352
|
+
/**
|
|
353
|
+
* Called once the server acks the subscription. The ack carries the
|
|
354
|
+
* effective (clamped) `ttl` and the echoed `user` in the client's original
|
|
355
|
+
* format.
|
|
356
|
+
*/
|
|
357
|
+
onSubscribed?: (ack: WsSubscriptionAck) => void;
|
|
358
|
+
/** Called when a TTL-based subscription expires server-side. */
|
|
48
359
|
onExpired?: () => void;
|
|
49
360
|
}
|
|
50
361
|
export interface Subscription {
|
|
51
|
-
|
|
362
|
+
subscription: WsSubscription;
|
|
52
363
|
unsubscribe: () => void;
|
|
53
364
|
}
|
|
54
365
|
export type WsConnectionState = "disconnected" | "connecting" | "connected" | "reconnecting";
|
|
366
|
+
/**
|
|
367
|
+
* Subset of the WebSocket DOM type that the SDK actually uses. Browser
|
|
368
|
+
* `WebSocket`, `isows.WebSocket`, the `ws` package, and lightweight test
|
|
369
|
+
* doubles all structurally satisfy this interface — none of them need to
|
|
370
|
+
* extend `EventTarget` or expose `addEventListener`.
|
|
371
|
+
*
|
|
372
|
+
* Event parameters use `any` so that the lib.dom `WebSocket` (with its
|
|
373
|
+
* richer `Event` / `CloseEvent` / `MessageEvent` types) remains assignable
|
|
374
|
+
* to this interface under `strictFunctionTypes`. The SDK reads `code`,
|
|
375
|
+
* `reason`, and `data` from these events at runtime — those properties are
|
|
376
|
+
* spec-guaranteed for real WebSocket implementations.
|
|
377
|
+
*/
|
|
378
|
+
export interface WebSocketLike {
|
|
379
|
+
readyState: number;
|
|
380
|
+
send(data: string): void;
|
|
381
|
+
close(code?: number, reason?: string): void;
|
|
382
|
+
onopen: ((ev: any) => any) | null;
|
|
383
|
+
onclose: ((ev: any) => any) | null;
|
|
384
|
+
onerror: ((ev: any) => any) | null;
|
|
385
|
+
onmessage: ((ev: any) => any) | null;
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Factory used to construct the underlying socket when the SDK connects.
|
|
389
|
+
* Must return synchronously — the SDK wires the standard
|
|
390
|
+
* `onopen`/`onclose`/`onerror`/`onmessage` handlers immediately after.
|
|
391
|
+
*/
|
|
392
|
+
export type WebSocketFactory = (url: string | URL, protocols?: string | string[]) => WebSocketLike;
|
|
55
393
|
export interface DexWsOptions {
|
|
56
394
|
/** Auto-reconnect on unexpected disconnect (default: true). */
|
|
57
395
|
reconnect?: boolean;
|
|
@@ -61,6 +399,13 @@ export interface DexWsOptions {
|
|
|
61
399
|
reconnectDelay?: number;
|
|
62
400
|
/** Max reconnect delay in ms (default: 30000). */
|
|
63
401
|
maxReconnectDelay?: number;
|
|
402
|
+
/**
|
|
403
|
+
* Optional factory for constructing the underlying socket. When omitted the
|
|
404
|
+
* SDK reads `globalThis.WebSocket` lazily at connect time, falling back to
|
|
405
|
+
* `isows` for Node environments that lack a global. Pass an explicit factory
|
|
406
|
+
* to inject a mock or polyfilled implementation.
|
|
407
|
+
*/
|
|
408
|
+
createWebSocket?: WebSocketFactory;
|
|
64
409
|
}
|
|
65
410
|
export interface DexWsEventMap {
|
|
66
411
|
open: () => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ault-sdk-ts",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.3.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",
|