@n1xyz/nord-ts 0.0.18-8121ed05.0 → 0.0.19

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