ault-sdk-ts 0.0.2-alpha.11 → 0.0.2-alpha.13
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 +10 -2
- package/dist/client.d.ts +4 -0
- package/dist/core/network.d.ts +11 -8
- package/dist/eip712/msg.generated.d.ts +7 -3
- package/dist/eip712/sign-and-broadcast.d.ts +10 -1
- package/dist/high-level/tx/accountx.d.ts +3 -0
- package/dist/high-level/types.d.ts +31 -5
- package/dist/index.cjs +3279 -1926
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +3244 -1928
- 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 +56 -0
- package/dist/proto/gen/ault/accountx/v1/tx.d.ts +52 -0
- package/dist/proto/gen/ault/license/v1/genesis.d.ts +15 -15
- package/dist/proto/gen/ault/license/v1/license.d.ts +0 -12
- package/dist/proto/gen/ault/tokenregistry/v1/tx.d.ts +0 -15
- 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/rest/accountx.d.ts +8 -0
- package/dist/rest/bank.d.ts +15 -0
- package/dist/rest/dex-types.generated.d.ts +129 -101
- package/dist/rest/dex.generated.d.ts +133 -56
- package/dist/rest/feemarket.d.ts +58 -0
- package/dist/utils/address.d.ts +1 -0
- package/dist/utils/opaque-id.d.ts +24 -0
- package/dist/utils/tx-hash.d.ts +1 -0
- package/dist/ws/types.d.ts +35 -3
- package/package.json +1 -1
|
@@ -90,10 +90,18 @@ export interface MarketResponse {
|
|
|
90
90
|
/** @nullable */
|
|
91
91
|
optionType?: string | null;
|
|
92
92
|
feeSide?: string;
|
|
93
|
-
/**
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
93
|
+
/**
|
|
94
|
+
* Taker fee rate as a canonical decimal string. Strings preserve
|
|
95
|
+
precision past 2^53 raw units and avoid float-rounding noise.
|
|
96
|
+
|
|
97
|
+
* @pattern ^-?\d+(\.\d+)?$
|
|
98
|
+
*/
|
|
99
|
+
taker: string;
|
|
100
|
+
/**
|
|
101
|
+
* Maker fee rate as a canonical decimal string.
|
|
102
|
+
* @pattern ^-?\d+(\.\d+)?$
|
|
103
|
+
*/
|
|
104
|
+
maker: string;
|
|
97
105
|
percentage?: boolean;
|
|
98
106
|
tierBased?: boolean;
|
|
99
107
|
precision: MarketPrecision;
|
|
@@ -136,10 +144,16 @@ export type TradingFeeResponseInfo = {
|
|
|
136
144
|
};
|
|
137
145
|
export interface TradingFeeResponse {
|
|
138
146
|
symbol: string;
|
|
139
|
-
/**
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
147
|
+
/**
|
|
148
|
+
* Maker fee rate as a canonical decimal string.
|
|
149
|
+
* @pattern ^-?\d+(\.\d+)?$
|
|
150
|
+
*/
|
|
151
|
+
maker: string;
|
|
152
|
+
/**
|
|
153
|
+
* Taker fee rate as a canonical decimal string.
|
|
154
|
+
* @pattern ^-?\d+(\.\d+)?$
|
|
155
|
+
*/
|
|
156
|
+
taker: string;
|
|
143
157
|
percentage: boolean;
|
|
144
158
|
tierBased: boolean;
|
|
145
159
|
info: TradingFeeResponseInfo;
|
|
@@ -147,54 +161,61 @@ export interface TradingFeeResponse {
|
|
|
147
161
|
export type TickerResponseInfo = {
|
|
148
162
|
[key: string]: unknown;
|
|
149
163
|
};
|
|
164
|
+
/**
|
|
165
|
+
* 24h ticker stats. All numeric fields are canonical decimal strings
|
|
166
|
+
so quantities at any magnitude survive the JSON round-trip without
|
|
167
|
+
rounding through float64. Pointer-style fields (high/low/bid/etc.)
|
|
168
|
+
are nullable when no data is available for that field.
|
|
169
|
+
|
|
170
|
+
*/
|
|
150
171
|
export interface TickerResponse {
|
|
151
172
|
symbol: string;
|
|
152
173
|
/** @nullable */
|
|
153
|
-
high?:
|
|
174
|
+
high?: string | null;
|
|
154
175
|
/** @nullable */
|
|
155
|
-
low?:
|
|
176
|
+
low?: string | null;
|
|
156
177
|
/** @nullable */
|
|
157
|
-
bid?:
|
|
178
|
+
bid?: string | null;
|
|
158
179
|
/**
|
|
159
180
|
* Volume at the best bid price level. Extracted from the orderbook snapshot.
|
|
160
181
|
* @nullable
|
|
161
182
|
*/
|
|
162
|
-
bidVolume?:
|
|
183
|
+
bidVolume?: string | null;
|
|
163
184
|
/** @nullable */
|
|
164
|
-
ask?:
|
|
185
|
+
ask?: string | null;
|
|
165
186
|
/**
|
|
166
187
|
* Volume at the best ask price level. Extracted from the orderbook snapshot.
|
|
167
188
|
* @nullable
|
|
168
189
|
*/
|
|
169
|
-
askVolume?:
|
|
190
|
+
askVolume?: string | null;
|
|
170
191
|
/**
|
|
171
192
|
* Volume-weighted average price: quoteVolume / baseVolume
|
|
172
193
|
* @nullable
|
|
173
194
|
*/
|
|
174
|
-
vwap?:
|
|
195
|
+
vwap?: string | null;
|
|
175
196
|
/** @nullable */
|
|
176
|
-
open?:
|
|
197
|
+
open?: string | null;
|
|
177
198
|
/** @nullable */
|
|
178
|
-
close?:
|
|
199
|
+
close?: string | null;
|
|
179
200
|
/** @nullable */
|
|
180
|
-
last?:
|
|
201
|
+
last?: string | null;
|
|
181
202
|
/**
|
|
182
203
|
* Close price of the last bar before the 24h window.
|
|
183
204
|
* @nullable
|
|
184
205
|
*/
|
|
185
|
-
previousClose?:
|
|
206
|
+
previousClose?: string | null;
|
|
186
207
|
/** @nullable */
|
|
187
|
-
change?:
|
|
208
|
+
change?: string | null;
|
|
188
209
|
/** @nullable */
|
|
189
|
-
percentage?:
|
|
210
|
+
percentage?: string | null;
|
|
190
211
|
/**
|
|
191
|
-
* Simple average: (open +
|
|
212
|
+
* Simple average: (open + last) / 2
|
|
192
213
|
* @nullable
|
|
193
214
|
*/
|
|
194
|
-
average?:
|
|
195
|
-
baseVolume:
|
|
215
|
+
average?: string | null;
|
|
216
|
+
baseVolume: string;
|
|
196
217
|
/** @nullable */
|
|
197
|
-
quoteVolume?:
|
|
218
|
+
quoteVolume?: string | null;
|
|
198
219
|
/** Milliseconds */
|
|
199
220
|
timestamp: number;
|
|
200
221
|
datetime: string;
|
|
@@ -202,8 +223,20 @@ export interface TickerResponse {
|
|
|
202
223
|
}
|
|
203
224
|
export interface OrderbookResponse {
|
|
204
225
|
symbol: string;
|
|
205
|
-
|
|
206
|
-
|
|
226
|
+
/**
|
|
227
|
+
* Hex-encoded chain market identifier (no `0x` prefix). Provided so
|
|
228
|
+
consumers can round-trip back to chain proto endpoints which key
|
|
229
|
+
on the binary market id without re-resolving the symbol map.
|
|
230
|
+
Layout on the chain side is `MarketType (1 byte) | baseDenom |
|
|
231
|
+
\\x00 | quoteDenom`, with the full id stored as `VARBINARY(255)`
|
|
232
|
+
in the indexer; the hex form is therefore variable-length, even
|
|
233
|
+
for short-denom test markets that hit the lower bound.
|
|
234
|
+
|
|
235
|
+
* @pattern ^[0-9a-f]{2,510}$
|
|
236
|
+
*/
|
|
237
|
+
market_id: string;
|
|
238
|
+
bids: [string, string][];
|
|
239
|
+
asks: [string, string][];
|
|
207
240
|
timestamp: number;
|
|
208
241
|
datetime: string;
|
|
209
242
|
nonce: number;
|
|
@@ -233,16 +266,28 @@ export declare const TradeResponseTakerOrMaker: {
|
|
|
233
266
|
* Estimated fee for the trade: cost = amount * price * taker_fee_rate
|
|
234
267
|
*/
|
|
235
268
|
export type TradeResponseFee = {
|
|
236
|
-
/**
|
|
237
|
-
|
|
269
|
+
/**
|
|
270
|
+
* Fee cost in quote currency, decimal string.
|
|
271
|
+
* @pattern ^-?\d+(\.\d+)?$
|
|
272
|
+
*/
|
|
273
|
+
cost?: string;
|
|
238
274
|
/** Quote currency ticker (e.g., "USDT") */
|
|
239
275
|
currency?: string;
|
|
240
|
-
/**
|
|
241
|
-
|
|
276
|
+
/**
|
|
277
|
+
* Taker fee rate from the market, decimal string.
|
|
278
|
+
* @pattern ^-?\d+(\.\d+)?$
|
|
279
|
+
*/
|
|
280
|
+
rate?: string;
|
|
242
281
|
};
|
|
243
282
|
export type TradeResponseInfo = {
|
|
244
283
|
[key: string]: unknown;
|
|
245
284
|
};
|
|
285
|
+
/**
|
|
286
|
+
* All numeric fields are canonical decimal strings — quantities at any
|
|
287
|
+
magnitude survive the JSON round-trip without rounding through
|
|
288
|
+
float64. Consumers parse with their own bigdecimal.
|
|
289
|
+
|
|
290
|
+
*/
|
|
246
291
|
export interface TradeResponse {
|
|
247
292
|
id: string;
|
|
248
293
|
/** @nullable */
|
|
@@ -258,10 +303,15 @@ export interface TradeResponse {
|
|
|
258
303
|
side: TradeResponseSide;
|
|
259
304
|
/** Always 'taker' — on-chain DEX treats all executed trades as taker fills. */
|
|
260
305
|
takerOrMaker?: TradeResponseTakerOrMaker;
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
|
|
306
|
+
/** @pattern ^-?\d+(\.\d+)?$ */
|
|
307
|
+
price: string;
|
|
308
|
+
/** @pattern ^-?\d+(\.\d+)?$ */
|
|
309
|
+
amount: string;
|
|
310
|
+
/**
|
|
311
|
+
* price * amount
|
|
312
|
+
* @pattern ^-?\d+(\.\d+)?$
|
|
313
|
+
*/
|
|
314
|
+
cost: string;
|
|
265
315
|
/** Estimated fee for the trade: cost = amount * price * taker_fee_rate */
|
|
266
316
|
fee?: TradeResponseFee;
|
|
267
317
|
info: TradeResponseInfo;
|
|
@@ -289,16 +339,28 @@ export type OrderResponseTradesItem = {
|
|
|
289
339
|
* Estimated fee for the order: cost = filled * price * taker_fee_rate
|
|
290
340
|
*/
|
|
291
341
|
export type OrderResponseFee = {
|
|
292
|
-
/**
|
|
293
|
-
|
|
342
|
+
/**
|
|
343
|
+
* Fee cost in quote currency, decimal string.
|
|
344
|
+
* @pattern ^-?\d+(\.\d+)?$
|
|
345
|
+
*/
|
|
346
|
+
cost?: string;
|
|
294
347
|
/** Quote currency ticker (e.g., "USDT") */
|
|
295
348
|
currency?: string;
|
|
296
|
-
/**
|
|
297
|
-
|
|
349
|
+
/**
|
|
350
|
+
* Fee rate from the market, decimal string.
|
|
351
|
+
* @pattern ^-?\d+(\.\d+)?$
|
|
352
|
+
*/
|
|
353
|
+
rate?: string;
|
|
298
354
|
};
|
|
299
355
|
export type OrderResponseInfo = {
|
|
300
356
|
[key: string]: unknown;
|
|
301
357
|
};
|
|
358
|
+
/**
|
|
359
|
+
* All numeric fields (price, amount, filled, remaining, cost,
|
|
360
|
+
fee.cost, fee.rate, average, triggerPrice, stopPrice) are canonical
|
|
361
|
+
decimal strings.
|
|
362
|
+
|
|
363
|
+
*/
|
|
302
364
|
export interface OrderResponse {
|
|
303
365
|
id: string;
|
|
304
366
|
/**
|
|
@@ -319,44 +381,52 @@ export interface OrderResponse {
|
|
|
319
381
|
/** @nullable */
|
|
320
382
|
timeInForce?: string | null;
|
|
321
383
|
side: OrderResponseSide;
|
|
322
|
-
|
|
384
|
+
/** @pattern ^-?\d+(\.\d+)?$ */
|
|
385
|
+
price: string;
|
|
323
386
|
/**
|
|
324
|
-
* Average execution price
|
|
387
|
+
* Average execution price as decimal string. Null when filled is 0.
|
|
325
388
|
* @nullable
|
|
326
389
|
*/
|
|
327
|
-
average?:
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
390
|
+
average?: string | null;
|
|
391
|
+
/** @pattern ^-?\d+(\.\d+)?$ */
|
|
392
|
+
amount: string;
|
|
393
|
+
/** @pattern ^-?\d+(\.\d+)?$ */
|
|
394
|
+
filled: string;
|
|
395
|
+
/** @pattern ^-?\d+(\.\d+)?$ */
|
|
396
|
+
remaining: string;
|
|
397
|
+
/**
|
|
398
|
+
* filled * price, decimal string.
|
|
399
|
+
* @pattern ^-?\d+(\.\d+)?$
|
|
400
|
+
*/
|
|
401
|
+
cost: string;
|
|
333
402
|
trades?: OrderResponseTradesItem[];
|
|
334
403
|
/** Estimated fee for the order: cost = filled * price * taker_fee_rate */
|
|
335
404
|
fee?: OrderResponseFee;
|
|
336
405
|
reduceOnly?: boolean;
|
|
337
406
|
postOnly?: boolean;
|
|
338
407
|
/** @nullable */
|
|
339
|
-
stopPrice?:
|
|
408
|
+
stopPrice?: string | null;
|
|
340
409
|
/** @nullable */
|
|
341
|
-
triggerPrice?:
|
|
410
|
+
triggerPrice?: string | null;
|
|
342
411
|
info: OrderResponseInfo;
|
|
343
412
|
}
|
|
344
413
|
export type BalancesResponseFree = {
|
|
345
|
-
[key: string]:
|
|
414
|
+
[key: string]: string;
|
|
346
415
|
};
|
|
347
416
|
export type BalancesResponseUsed = {
|
|
348
|
-
[key: string]:
|
|
417
|
+
[key: string]: string;
|
|
349
418
|
};
|
|
350
419
|
export type BalancesResponseTotal = {
|
|
351
|
-
[key: string]:
|
|
420
|
+
[key: string]: string;
|
|
352
421
|
};
|
|
353
422
|
export type BalancesResponseInfo = {
|
|
354
423
|
[key: string]: unknown;
|
|
355
424
|
};
|
|
356
425
|
/**
|
|
357
426
|
* Balance object. Contains `free`, `used`, `total` dictionaries
|
|
358
|
-
(currency code ->
|
|
359
|
-
and `info`, `timestamp`,
|
|
427
|
+
(currency code -> decimal string), plus per-currency entries with
|
|
428
|
+
{free, used, total} as decimal strings, and `info`, `timestamp`,
|
|
429
|
+
`datetime`. Strings preserve precision past 2^53 raw units.
|
|
360
430
|
|
|
361
431
|
*/
|
|
362
432
|
export interface BalancesResponse {
|
|
@@ -370,11 +440,17 @@ export interface BalancesResponse {
|
|
|
370
440
|
info: BalancesResponseInfo;
|
|
371
441
|
}
|
|
372
442
|
/**
|
|
373
|
-
* [timestamp_ms, open, high, low, close, volume]
|
|
443
|
+
* [timestamp_ms, open, high, low, close, volume]. Timestamp is a
|
|
444
|
+
numeric ms epoch; the o/h/l/c/v fields are canonical decimal
|
|
445
|
+
strings so quantities at any magnitude survive the JSON round-trip.
|
|
446
|
+
(Patterns omitted on tuple items because orval generates broken
|
|
447
|
+
regex references when `prefixItems` carry `pattern`; the format is
|
|
448
|
+
documented in the descriptions.)
|
|
449
|
+
|
|
374
450
|
* @minItems 6
|
|
375
451
|
* @maxItems 6
|
|
376
452
|
*/
|
|
377
|
-
export type OHLCVEntry = number
|
|
453
|
+
export type OHLCVEntry = [number, string, string, string, string, string];
|
|
378
454
|
export interface UDFExchange {
|
|
379
455
|
value: string;
|
|
380
456
|
name: string;
|
|
@@ -558,6 +634,7 @@ export type GetAllTickers200 = {
|
|
|
558
634
|
export type GetOrderbookParams = {
|
|
559
635
|
/**
|
|
560
636
|
* @minimum 1
|
|
637
|
+
* @maximum 20
|
|
561
638
|
*/
|
|
562
639
|
limit?: number;
|
|
563
640
|
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type FetchFn, type FetchWithRetryOptions } from "../core/http";
|
|
2
|
+
import type { NetworkConfig } from "../core/network";
|
|
3
|
+
export interface FeeMarketParams {
|
|
4
|
+
noBaseFee: boolean;
|
|
5
|
+
/** Decimal string in aault per unit gas. */
|
|
6
|
+
baseFee: string;
|
|
7
|
+
/** Decimal string in aault per unit gas (chain-side floor). */
|
|
8
|
+
minGasPrice: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Fetch the current `cosmos/evm` feemarket params from the chain REST gateway.
|
|
12
|
+
*
|
|
13
|
+
* Throws on transport / 4xx / 5xx errors; callers wanting graceful fallback
|
|
14
|
+
* (e.g. for chains that don't expose the feemarket gateway) should use
|
|
15
|
+
* `getCachedFeeMarketParams` which absorbs the failure.
|
|
16
|
+
*/
|
|
17
|
+
export declare function fetchFeeMarketParams(network: NetworkConfig, fetchFn?: FetchFn, fetchOptions?: FetchWithRetryOptions): Promise<FeeMarketParams>;
|
|
18
|
+
/**
|
|
19
|
+
* Compute the minimum fee amount (raw aault) required for the given gas
|
|
20
|
+
* limit under the supplied feemarket params, with a safety margin to absorb
|
|
21
|
+
* intra-block base-fee bumps. The chain's DynamicFeeChecker enforces
|
|
22
|
+
* `fee.amount / gas >= effective`, where `effective = max(baseFee, minGasPrice)`
|
|
23
|
+
* when base fee is enabled, else `minGasPrice` alone.
|
|
24
|
+
*
|
|
25
|
+
* Returns the smallest non-negative integer string `feeAmount` such that
|
|
26
|
+
* `feeAmount / gas >= effective * (1 + marginPercent/100)`.
|
|
27
|
+
*/
|
|
28
|
+
export declare function computeRequiredFee(params: FeeMarketParams, gas: string | number | bigint, options?: {
|
|
29
|
+
marginPercent?: number;
|
|
30
|
+
}): string;
|
|
31
|
+
interface FeeMarketEntry {
|
|
32
|
+
params: FeeMarketParams | null;
|
|
33
|
+
fetchedAt: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Per-chain cache for feemarket params. Reused across tx submissions to
|
|
37
|
+
* avoid hitting `/params` on every signature; one entry per `chainId`.
|
|
38
|
+
*/
|
|
39
|
+
export interface FeeMarketCache {
|
|
40
|
+
ttlMs: number;
|
|
41
|
+
entries: Map<string, FeeMarketEntry>;
|
|
42
|
+
}
|
|
43
|
+
export declare function createFeeMarketCache(ttlMs?: number): FeeMarketCache;
|
|
44
|
+
/**
|
|
45
|
+
* Look up cached feemarket params or fetch fresh ones. Returns `null` only
|
|
46
|
+
* when the chain definitively does not expose the feemarket gateway — i.e.
|
|
47
|
+
* the gateway returns 404 (path not registered) or 501 (not implemented).
|
|
48
|
+
* Negative responses are cached for `ttlMs` to avoid re-spamming a chain
|
|
49
|
+
* that lacks the module.
|
|
50
|
+
*
|
|
51
|
+
* Transient failures (timeouts, network errors, 5xx) propagate unchanged so
|
|
52
|
+
* callers can decide whether to retry. Caching a transient miss would force
|
|
53
|
+
* every tx for `ttlMs` onto the static fallback fee, which on chains where
|
|
54
|
+
* `min_gas_price` exceeds the static default would underprice the tx and
|
|
55
|
+
* trigger the same "insufficient fee" rejection this module exists to avoid.
|
|
56
|
+
*/
|
|
57
|
+
export declare function getCachedFeeMarketParams(cache: FeeMarketCache | undefined, network: NetworkConfig, fetchFn?: FetchFn, fetchOptions?: FetchWithRetryOptions): Promise<FeeMarketParams | null>;
|
|
58
|
+
export {};
|
package/dist/utils/address.d.ts
CHANGED
|
@@ -2,5 +2,6 @@ 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;
|
|
5
6
|
export declare function isValidValidatorAddress(address: string): boolean;
|
|
6
7
|
export declare function assertValidatorAddress(address: string): string;
|
|
@@ -0,0 +1,24 @@
|
|
|
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 class OrderId extends OpaqueId {
|
|
18
|
+
static fromHex(hex: string): OrderId;
|
|
19
|
+
static fromBase64(b64: string): OrderId;
|
|
20
|
+
static fromBytes(bytes: Uint8Array): OrderId;
|
|
21
|
+
private static assertLength;
|
|
22
|
+
equals(other: OrderId): boolean;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function normalizeTxHash(raw: string): string;
|
package/dist/ws/types.d.ts
CHANGED
|
@@ -1,4 +1,30 @@
|
|
|
1
|
-
import type { OrderbookResponse, TradeResponse, TickerResponse, OrderResponse,
|
|
1
|
+
import type { OrderbookResponse, TradeResponse, TickerResponse, OrderResponse, OHLCVEntry } from "../rest/dex.generated";
|
|
2
|
+
export interface WsTradeInfo {
|
|
3
|
+
address: string;
|
|
4
|
+
paid: string;
|
|
5
|
+
received: string;
|
|
6
|
+
block_height: string;
|
|
7
|
+
}
|
|
8
|
+
export interface WsOrderInfo {
|
|
9
|
+
orderer: string;
|
|
10
|
+
block_height: string;
|
|
11
|
+
tx_index: number;
|
|
12
|
+
remaining_deposit: string;
|
|
13
|
+
chain_status: string;
|
|
14
|
+
chain_type: string;
|
|
15
|
+
}
|
|
16
|
+
export interface WsTradeUpdate extends Omit<TradeResponse, "info"> {
|
|
17
|
+
info: WsTradeInfo;
|
|
18
|
+
}
|
|
19
|
+
export interface WsOrderUpdate extends Omit<OrderResponse, "info"> {
|
|
20
|
+
info: WsOrderInfo;
|
|
21
|
+
}
|
|
22
|
+
export interface CurrencyBalanceDelta {
|
|
23
|
+
free?: string;
|
|
24
|
+
used?: string;
|
|
25
|
+
total?: string;
|
|
26
|
+
}
|
|
27
|
+
export type WsBalancesUpdate = Record<string, CurrencyBalanceDelta>;
|
|
2
28
|
export type WsEvent = "snapshot" | "new_trades" | "update" | "bar_update" | "response" | "subscription_expired";
|
|
3
29
|
export interface WsServerMessage<T = unknown> {
|
|
4
30
|
topic: string;
|
|
@@ -30,9 +56,15 @@ export interface WsCommandResponse {
|
|
|
30
56
|
*
|
|
31
57
|
* The block header fields (hash, proposer, tx_count, gas_used, gas_wanted)
|
|
32
58
|
* are optional because older chain versions may not supply them.
|
|
59
|
+
*
|
|
60
|
+
* `height` is a decimal string for symmetry with the WS trade/order
|
|
61
|
+
* `info.block_height`. At one-second blocks the JS-Number boundary
|
|
62
|
+
* (~285k years) is a practical non-issue today; the string form keeps
|
|
63
|
+
* the numeric WS contract uniform so consumers don't have to special-case
|
|
64
|
+
* `chain:block` in their parsing layer.
|
|
33
65
|
*/
|
|
34
66
|
export interface BlockUpdate {
|
|
35
|
-
height:
|
|
67
|
+
height: string;
|
|
36
68
|
timestamp: number;
|
|
37
69
|
hash?: string;
|
|
38
70
|
proposer?: string;
|
|
@@ -40,7 +72,7 @@ export interface BlockUpdate {
|
|
|
40
72
|
gas_used?: number;
|
|
41
73
|
gas_wanted?: number;
|
|
42
74
|
}
|
|
43
|
-
export type PayloadFor<T extends string> = T extends `orderbook:${string}` ? OrderbookResponse : T extends `trades:${string}` ?
|
|
75
|
+
export type PayloadFor<T extends string> = T extends `orderbook:${string}` ? OrderbookResponse : T extends `trades:${string}` ? WsTradeUpdate[] : T extends `ticker:${string}` ? TickerResponse : T extends `chart:${string}` ? OHLCVEntry : T extends `orders:${string}` ? WsOrderUpdate[] : T extends `balances:${string}` ? WsBalancesUpdate : T extends `mytrades:${string}` ? WsTradeUpdate[] : T extends "chain:block" ? BlockUpdate : unknown;
|
|
44
76
|
export interface SubscriptionHandlers<T> {
|
|
45
77
|
onData: (data: T, message: WsServerMessage<T>) => void;
|
|
46
78
|
onError?: (error: Error) => void;
|