@n1xyz/nord-ts 0.0.19 → 0.0.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/dist/api/client.d.ts +14 -0
- package/dist/api/client.js +45 -0
- package/dist/bridge/client.d.ts +151 -0
- package/dist/bridge/client.js +434 -0
- package/dist/bridge/const.d.ts +23 -0
- package/dist/bridge/const.js +47 -0
- package/dist/bridge/index.d.ts +4 -0
- package/dist/bridge/index.js +23 -0
- package/dist/bridge/types.d.ts +120 -0
- package/dist/bridge/types.js +18 -0
- package/dist/bridge/utils.d.ts +64 -0
- package/dist/bridge/utils.js +131 -0
- package/dist/const.d.ts +8 -0
- package/dist/const.js +30 -0
- package/dist/gen/common.d.ts +68 -0
- package/dist/gen/common.js +215 -0
- package/dist/gen/nord.d.ts +882 -0
- package/dist/gen/nord.js +6520 -0
- package/dist/gen/openapi.d.ts +2244 -0
- package/dist/gen/openapi.js +6 -0
- package/dist/idl/bridge.d.ts +569 -0
- package/dist/idl/bridge.js +8 -0
- package/dist/idl/bridge.json +1506 -0
- package/dist/idl/index.d.ts +607 -0
- package/dist/idl/index.js +8 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +21 -0
- package/dist/nord/api/actions.d.ts +135 -0
- package/dist/nord/api/actions.js +313 -0
- package/dist/nord/api/core.d.ts +16 -0
- package/dist/nord/api/core.js +93 -0
- package/dist/nord/api/market.d.ts +36 -0
- package/dist/nord/api/market.js +96 -0
- package/dist/nord/api/metrics.d.ts +67 -0
- package/dist/nord/api/metrics.js +229 -0
- package/dist/nord/api/queries.d.ts +46 -0
- package/dist/nord/api/queries.js +109 -0
- package/dist/nord/client/Nord.d.ts +282 -0
- package/dist/nord/client/Nord.js +531 -0
- package/dist/nord/client/NordUser.d.ts +340 -0
- package/dist/nord/client/NordUser.js +652 -0
- package/dist/nord/index.d.ts +7 -0
- package/dist/nord/index.js +31 -0
- package/dist/nord/models/Subscriber.d.ts +37 -0
- package/dist/nord/models/Subscriber.js +25 -0
- package/dist/nord/utils/NordError.d.ts +35 -0
- package/dist/nord/utils/NordError.js +49 -0
- package/dist/types.d.ts +260 -0
- package/dist/types.js +103 -0
- package/dist/utils.d.ts +98 -0
- package/dist/utils.js +237 -0
- package/dist/websocket/NordWebSocketClient.d.ts +68 -0
- package/dist/websocket/NordWebSocketClient.js +343 -0
- package/dist/websocket/events.d.ts +19 -0
- package/dist/websocket/events.js +2 -0
- package/dist/websocket/index.d.ts +2 -0
- package/dist/websocket/index.js +5 -0
- package/package.json +7 -1
- package/src/gen/.gitkeep +0 -0
- package/src/gen/nord.ts +7593 -0
- package/src/gen/openapi.ts +2245 -0
- package/.claude/settings.local.json +0 -11
- package/.local/qa.ts +0 -77
- package/.local/test-atomic.ts +0 -112
- package/.prettierignore +0 -2
- package/check.sh +0 -4
- package/default.nix +0 -47
- package/eslint.config.mjs +0 -66
- package/tests/utils.spec.ts +0 -121
- package/tsconfig.eslint.json +0 -12
- package/tsconfig.json +0 -24
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { EventEmitter } from "events";
|
|
2
|
+
import { PublicKey } from "@solana/web3.js";
|
|
3
|
+
import { Info, Account, ActionResponse, AggregateMetrics, Market, NordConfig, OrderbookQuery, OrderbookResponse, PeakTpsPeriodUnit, Token, TradesResponse, User, MarketStats } from "../../types";
|
|
4
|
+
import { ProtonClient } from "@n1xyz/proton";
|
|
5
|
+
import { NordWebSocketClient } from "../../websocket/index";
|
|
6
|
+
import { OrderbookSubscription, TradeSubscription } from "../models/Subscriber";
|
|
7
|
+
/**
|
|
8
|
+
* User subscription interface
|
|
9
|
+
*/
|
|
10
|
+
export interface UserSubscription extends EventEmitter {
|
|
11
|
+
close: () => void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* WebSocket subscription options interface
|
|
15
|
+
*/
|
|
16
|
+
export interface WebSocketSubscriptionOptions {
|
|
17
|
+
/** Market symbols to subscribe to for trade updates */
|
|
18
|
+
trades?: string[];
|
|
19
|
+
/** Market symbols to subscribe to for orderbook delta updates */
|
|
20
|
+
deltas?: string[];
|
|
21
|
+
/** Account IDs to subscribe to for account updates */
|
|
22
|
+
accounts?: number[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Main Nord client class for interacting with the Nord API
|
|
26
|
+
*/
|
|
27
|
+
export declare class Nord {
|
|
28
|
+
/** Base URL for the Nord web server */
|
|
29
|
+
readonly webServerUrl: string;
|
|
30
|
+
/** Bridge verification key */
|
|
31
|
+
readonly bridgeVk: PublicKey;
|
|
32
|
+
/** Solana RPC URL */
|
|
33
|
+
readonly solanaUrl: string;
|
|
34
|
+
/** Available markets */
|
|
35
|
+
markets: Market[];
|
|
36
|
+
/** Available tokens */
|
|
37
|
+
tokens: Token[];
|
|
38
|
+
/** Map of symbol to market_id */
|
|
39
|
+
private symbolToMarketId;
|
|
40
|
+
/** Proton client for bridge and hansel operations */
|
|
41
|
+
protonClient: ProtonClient;
|
|
42
|
+
/** HTTP client for Nord operations */
|
|
43
|
+
private httpClient;
|
|
44
|
+
/**
|
|
45
|
+
* Create a new Nord client
|
|
46
|
+
*
|
|
47
|
+
* @param config - Configuration options for the Nord client
|
|
48
|
+
* @param config.webServerUrl - Base URL for the Nord web server
|
|
49
|
+
* @param config.bridgeVk - Bridge verification key
|
|
50
|
+
* @param config.solanaUrl - Solana cluster URL
|
|
51
|
+
* @throws {Error} If required configuration is missing
|
|
52
|
+
*/
|
|
53
|
+
private constructor();
|
|
54
|
+
/**
|
|
55
|
+
* Create a WebSocket client with specific subscriptions
|
|
56
|
+
*
|
|
57
|
+
* @param options - Subscription options that specify which data streams to subscribe to
|
|
58
|
+
* @returns A new WebSocket client with the requested subscriptions
|
|
59
|
+
* @throws {NordError} If invalid subscription options are provided
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* // Create a client for trades and deltas from one market and an account
|
|
63
|
+
* const wsClient = nord.createWebSocketClient({
|
|
64
|
+
* trades: ["BTCUSDC"],
|
|
65
|
+
* deltas: ["BTCUSDC"],
|
|
66
|
+
* accounts: [123]
|
|
67
|
+
* });
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* // Create a client for trades from multiple markets
|
|
71
|
+
* const tradesClient = nord.createWebSocketClient({
|
|
72
|
+
* trades: ["BTCUSDC", "ETHUSDC"]
|
|
73
|
+
* });
|
|
74
|
+
*/
|
|
75
|
+
createWebSocketClient(options: WebSocketSubscriptionOptions): NordWebSocketClient;
|
|
76
|
+
private GET;
|
|
77
|
+
/**
|
|
78
|
+
* Get the current timestamp from the Nord server
|
|
79
|
+
*
|
|
80
|
+
* @returns Current timestamp as a bigint
|
|
81
|
+
* @throws {NordError} If the request fails
|
|
82
|
+
*/
|
|
83
|
+
getTimestamp(): Promise<bigint>;
|
|
84
|
+
/**
|
|
85
|
+
* Get the last event nonce from the Nord server
|
|
86
|
+
*
|
|
87
|
+
* @returns Next action nonce
|
|
88
|
+
* @throws {NordError} If the request fails
|
|
89
|
+
*/
|
|
90
|
+
getActionNonce(): Promise<number>;
|
|
91
|
+
/**
|
|
92
|
+
* Fetch information about Nord markets and tokens
|
|
93
|
+
*
|
|
94
|
+
* @throws {NordError} If the request fails
|
|
95
|
+
*/
|
|
96
|
+
fetchNordInfo(): Promise<void>;
|
|
97
|
+
/**
|
|
98
|
+
* Initialize a new Nord client
|
|
99
|
+
*
|
|
100
|
+
* @param nordConfig - Configuration options for the Nord client
|
|
101
|
+
* @param nordConfig.webServerUrl - Base URL for the Nord web server
|
|
102
|
+
* @param nordConfig.bridgeVk - Bridge verification key
|
|
103
|
+
* @param nordConfig.solanaUrl - Solana cluster URL
|
|
104
|
+
* @returns Initialized Nord client
|
|
105
|
+
* @throws {NordError} If initialization fails
|
|
106
|
+
*/
|
|
107
|
+
static initNord({ bridgeVk: bridgeVk_, solanaUrl, webServerUrl, }: Readonly<NordConfig>): Promise<Nord>;
|
|
108
|
+
/**
|
|
109
|
+
* Initialize the Nord client
|
|
110
|
+
* @private
|
|
111
|
+
*/
|
|
112
|
+
private init;
|
|
113
|
+
/**
|
|
114
|
+
* Query a specific action
|
|
115
|
+
*
|
|
116
|
+
* @param query - Action query parameters
|
|
117
|
+
* @returns Action response
|
|
118
|
+
* @throws {NordError} If the request fails
|
|
119
|
+
*/
|
|
120
|
+
queryAction({ action_id, }: {
|
|
121
|
+
action_id: number;
|
|
122
|
+
}): Promise<ActionResponse | null>;
|
|
123
|
+
/**
|
|
124
|
+
* Query recent actions
|
|
125
|
+
*
|
|
126
|
+
* @param from - Starting action index
|
|
127
|
+
* @param to - Ending action index
|
|
128
|
+
* @returns Actions response
|
|
129
|
+
* @throws {NordError} If the request fails
|
|
130
|
+
*/
|
|
131
|
+
queryRecentActions(query: {
|
|
132
|
+
from: number;
|
|
133
|
+
to: number;
|
|
134
|
+
}): Promise<ActionResponse[]>;
|
|
135
|
+
/**
|
|
136
|
+
* Get the last action ID
|
|
137
|
+
*
|
|
138
|
+
* @returns Last action ID
|
|
139
|
+
* @throws {NordError} If the request fails
|
|
140
|
+
*/
|
|
141
|
+
getLastActionId(): Promise<number>;
|
|
142
|
+
/**
|
|
143
|
+
* Fetch aggregate metrics from the Nord API
|
|
144
|
+
*
|
|
145
|
+
* @param txPeakTpsPeriod - Period for peak TPS calculation
|
|
146
|
+
* @param txPeakTpsPeriodUnit - Unit for peak TPS period
|
|
147
|
+
* @returns Aggregate metrics
|
|
148
|
+
* @throws {NordError} If the request fails
|
|
149
|
+
*/
|
|
150
|
+
aggregateMetrics(txPeakTpsPeriod?: number, txPeakTpsPeriodUnit?: PeakTpsPeriodUnit): Promise<AggregateMetrics>;
|
|
151
|
+
/**
|
|
152
|
+
* Get current transactions per second
|
|
153
|
+
*
|
|
154
|
+
* @param period - Time period for the query
|
|
155
|
+
* @returns Current TPS value
|
|
156
|
+
* @throws {NordError} If the request fails
|
|
157
|
+
*/
|
|
158
|
+
getCurrentTps(period?: string): Promise<number>;
|
|
159
|
+
/**
|
|
160
|
+
* Get peak transactions per second
|
|
161
|
+
*
|
|
162
|
+
* @param period - Time period for the query
|
|
163
|
+
* @returns Peak TPS value
|
|
164
|
+
* @throws {NordError} If the request fails
|
|
165
|
+
*/
|
|
166
|
+
getPeakTps(period?: string): Promise<number>;
|
|
167
|
+
/**
|
|
168
|
+
* Get median transaction latency
|
|
169
|
+
*
|
|
170
|
+
* @param period - Time period for the query
|
|
171
|
+
* @returns Median latency in milliseconds
|
|
172
|
+
* @throws {NordError} If the request fails
|
|
173
|
+
*/
|
|
174
|
+
getMedianLatency(period?: string): Promise<number>;
|
|
175
|
+
/**
|
|
176
|
+
* Get total transaction count
|
|
177
|
+
*
|
|
178
|
+
* @returns Total transaction count
|
|
179
|
+
* @throws {NordError} If the request fails
|
|
180
|
+
*/
|
|
181
|
+
getTotalTransactions(): Promise<number>;
|
|
182
|
+
/**
|
|
183
|
+
* Query Prometheus metrics
|
|
184
|
+
*
|
|
185
|
+
* @param params - Prometheus query parameters
|
|
186
|
+
* @returns Query result as a number
|
|
187
|
+
* @throws {NordError} If the request fails
|
|
188
|
+
*/
|
|
189
|
+
queryPrometheus(params: string): Promise<number>;
|
|
190
|
+
/**
|
|
191
|
+
* Subscribe to orderbook updates for a market
|
|
192
|
+
*
|
|
193
|
+
* @param symbol - Market symbol
|
|
194
|
+
* @returns Orderbook subscription
|
|
195
|
+
* @throws {NordError} If symbol is invalid
|
|
196
|
+
*/
|
|
197
|
+
subscribeOrderbook(symbol: string): OrderbookSubscription;
|
|
198
|
+
/**
|
|
199
|
+
* Subscribe to trade updates for a market
|
|
200
|
+
*
|
|
201
|
+
* @param symbol - Market symbol
|
|
202
|
+
* @returns Trade subscription
|
|
203
|
+
* @throws {NordError} If symbol is invalid
|
|
204
|
+
*/
|
|
205
|
+
subscribeTrades(symbol: string): TradeSubscription;
|
|
206
|
+
/**
|
|
207
|
+
* Subscribe to account updates
|
|
208
|
+
*
|
|
209
|
+
* @param accountId - Account ID to subscribe to
|
|
210
|
+
* @returns User subscription
|
|
211
|
+
* @throws {NordError} If accountId is invalid
|
|
212
|
+
*/
|
|
213
|
+
subscribeAccount(accountId: number): UserSubscription;
|
|
214
|
+
/**
|
|
215
|
+
* Get trades for a market
|
|
216
|
+
*
|
|
217
|
+
* @param query - Trades query parameters
|
|
218
|
+
* @returns Trades response
|
|
219
|
+
* @throws {NordError} If the request fails
|
|
220
|
+
*/
|
|
221
|
+
getTrades(query: Readonly<{
|
|
222
|
+
marketId?: number;
|
|
223
|
+
takerId?: number;
|
|
224
|
+
makerId?: number;
|
|
225
|
+
takerSide?: "bid" | "ask";
|
|
226
|
+
pageSize?: number;
|
|
227
|
+
sinceRcf3339?: string;
|
|
228
|
+
untilRfc3339?: string;
|
|
229
|
+
pageId?: string;
|
|
230
|
+
}>): Promise<TradesResponse>;
|
|
231
|
+
/**
|
|
232
|
+
* Get user account IDs
|
|
233
|
+
*
|
|
234
|
+
* @param query - User account IDs query parameters
|
|
235
|
+
* @returns User account IDs response
|
|
236
|
+
* @throws {NordError} If the request fails
|
|
237
|
+
*/
|
|
238
|
+
getUser(query: {
|
|
239
|
+
pubkey: string | PublicKey;
|
|
240
|
+
}): Promise<User | null>;
|
|
241
|
+
/**
|
|
242
|
+
* Get orderbook for a market
|
|
243
|
+
*
|
|
244
|
+
* @param query - Orderbook query parameters (either market_id or symbol must be provided)
|
|
245
|
+
* @returns Orderbook response
|
|
246
|
+
* @throws {NordError} If the request fails or if the market symbol is unknown
|
|
247
|
+
* @remarks It's recommended to initialize the Nord client using the static `initNord` method
|
|
248
|
+
* to ensure market information is properly loaded before calling this method.
|
|
249
|
+
*/
|
|
250
|
+
getOrderbook(query: OrderbookQuery): Promise<OrderbookResponse>;
|
|
251
|
+
/**
|
|
252
|
+
* Get information about the Nord server
|
|
253
|
+
*
|
|
254
|
+
* @returns Information about markets and tokens
|
|
255
|
+
* @throws {NordError} If the request fails
|
|
256
|
+
*/
|
|
257
|
+
getInfo(): Promise<Info>;
|
|
258
|
+
/**
|
|
259
|
+
* Get account information
|
|
260
|
+
*
|
|
261
|
+
* @param accountId - Account ID to get information for
|
|
262
|
+
* @returns Account information
|
|
263
|
+
* @throws {NordError} If the request fails
|
|
264
|
+
*/
|
|
265
|
+
getAccount(accountId: number): Promise<Account>;
|
|
266
|
+
/**
|
|
267
|
+
* Get market statistics (alias for marketsStats for backward compatibility)
|
|
268
|
+
*
|
|
269
|
+
* @returns Market statistics response
|
|
270
|
+
*/
|
|
271
|
+
getMarketStats({ marketId, }: {
|
|
272
|
+
marketId: number;
|
|
273
|
+
}): Promise<MarketStats>;
|
|
274
|
+
/**
|
|
275
|
+
* Check if an account exists for the given address
|
|
276
|
+
*
|
|
277
|
+
* @param address - The public key address to check
|
|
278
|
+
* @returns True if the account exists, false otherwise
|
|
279
|
+
* @deprecated use getUser instead
|
|
280
|
+
*/
|
|
281
|
+
accountExists(pubkey: string | PublicKey): Promise<boolean>;
|
|
282
|
+
}
|