@n1xyz/nord-ts 0.1.6 → 0.1.8

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 (85) hide show
  1. package/dist/actions.d.ts +57 -0
  2. package/dist/actions.js +186 -0
  3. package/dist/bundle.js +79181 -0
  4. package/dist/{nord/client → client}/Nord.d.ts +90 -107
  5. package/dist/{nord/client → client}/Nord.js +157 -218
  6. package/dist/{nord/client → client}/NordAdmin.d.ts +68 -102
  7. package/dist/{nord/client → client}/NordAdmin.js +109 -140
  8. package/dist/{nord/client → client}/NordUser.d.ts +86 -98
  9. package/dist/{nord/client → client}/NordUser.js +204 -271
  10. package/dist/const.js +5 -8
  11. package/dist/{nord/utils/NordError.js → error.js} +7 -5
  12. package/dist/gen/nord_pb.js +88 -92
  13. package/dist/gen/openapi.d.ts +39 -0
  14. package/dist/gen/openapi.js +1 -2
  15. package/dist/index.d.ts +6 -1
  16. package/dist/index.js +10 -21
  17. package/dist/types.d.ts +5 -50
  18. package/dist/types.js +21 -83
  19. package/dist/utils.d.ts +8 -11
  20. package/dist/utils.js +55 -90
  21. package/dist/websocket/NordWebSocketClient.js +12 -17
  22. package/dist/{nord/models → websocket}/Subscriber.d.ts +1 -1
  23. package/dist/{nord/models → websocket}/Subscriber.js +6 -7
  24. package/dist/websocket/events.js +1 -2
  25. package/dist/websocket/index.d.ts +19 -2
  26. package/dist/websocket/index.js +80 -5
  27. package/package.json +2 -3
  28. package/dist/api/client.d.ts +0 -14
  29. package/dist/api/client.js +0 -45
  30. package/dist/bridge/client.d.ts +0 -151
  31. package/dist/bridge/client.js +0 -434
  32. package/dist/bridge/const.d.ts +0 -23
  33. package/dist/bridge/const.js +0 -47
  34. package/dist/bridge/index.d.ts +0 -4
  35. package/dist/bridge/index.js +0 -23
  36. package/dist/bridge/types.d.ts +0 -120
  37. package/dist/bridge/types.js +0 -18
  38. package/dist/bridge/utils.d.ts +0 -64
  39. package/dist/bridge/utils.js +0 -131
  40. package/dist/gen/common.d.ts +0 -68
  41. package/dist/gen/common.js +0 -215
  42. package/dist/gen/nord.d.ts +0 -882
  43. package/dist/gen/nord.js +0 -6520
  44. package/dist/idl/bridge.d.ts +0 -569
  45. package/dist/idl/bridge.js +0 -8
  46. package/dist/idl/bridge.json +0 -1506
  47. package/dist/idl/index.d.ts +0 -607
  48. package/dist/idl/index.js +0 -8
  49. package/dist/nord/api/actions.d.ts +0 -126
  50. package/dist/nord/api/actions.js +0 -397
  51. package/dist/nord/api/core.d.ts +0 -16
  52. package/dist/nord/api/core.js +0 -81
  53. package/dist/nord/api/market.d.ts +0 -36
  54. package/dist/nord/api/market.js +0 -96
  55. package/dist/nord/api/metrics.d.ts +0 -67
  56. package/dist/nord/api/metrics.js +0 -229
  57. package/dist/nord/api/queries.d.ts +0 -46
  58. package/dist/nord/api/queries.js +0 -109
  59. package/dist/nord/api/triggers.d.ts +0 -7
  60. package/dist/nord/api/triggers.js +0 -38
  61. package/dist/nord/client/NordClient.d.ts +0 -33
  62. package/dist/nord/client/NordClient.js +0 -45
  63. package/dist/nord/index.d.ts +0 -11
  64. package/dist/nord/index.js +0 -36
  65. package/src/const.ts +0 -34
  66. package/src/gen/.gitkeep +0 -0
  67. package/src/gen/nord_pb.ts +0 -5053
  68. package/src/gen/openapi.ts +0 -2864
  69. package/src/index.ts +0 -5
  70. package/src/nord/api/actions.ts +0 -648
  71. package/src/nord/api/core.ts +0 -96
  72. package/src/nord/api/metrics.ts +0 -269
  73. package/src/nord/client/Nord.ts +0 -937
  74. package/src/nord/client/NordAdmin.ts +0 -514
  75. package/src/nord/client/NordClient.ts +0 -79
  76. package/src/nord/client/NordUser.ts +0 -1211
  77. package/src/nord/index.ts +0 -25
  78. package/src/nord/models/Subscriber.ts +0 -56
  79. package/src/nord/utils/NordError.ts +0 -76
  80. package/src/types.ts +0 -377
  81. package/src/utils.ts +0 -269
  82. package/src/websocket/NordWebSocketClient.ts +0 -316
  83. package/src/websocket/events.ts +0 -31
  84. package/src/websocket/index.ts +0 -2
  85. /package/dist/{nord/utils/NordError.d.ts → error.d.ts} +0 -0
package/src/nord/index.ts DELETED
@@ -1,25 +0,0 @@
1
- // Export main client classes
2
- export { Nord } from "./client/Nord";
3
- export { NordUser } from "./client/NordUser";
4
- export { NordAdmin, AclRole } from "./client/NordAdmin";
5
- export { NordClient } from "./client/NordClient";
6
- export type { NordClientParams } from "./client/NordClient";
7
- export type {
8
- CreateTokenParams,
9
- CreateMarketParams,
10
- PythSetWormholeGuardiansParams,
11
- PythSetSymbolFeedParams,
12
- FreezeMarketParams,
13
- UnfreezeMarketParams,
14
- } from "./client/NordAdmin";
15
-
16
- // Export utility classes
17
- export { NordError } from "./utils/NordError";
18
-
19
- // Export API modules
20
- export * from "./api/core";
21
- export * from "./api/metrics";
22
- export * from "./api/actions";
23
-
24
- // Export models
25
- export * from "./models/Subscriber";
@@ -1,56 +0,0 @@
1
- import { EventEmitter } from "events";
2
- import {
3
- Account,
4
- DeltaEvent,
5
- OrderbookResponse,
6
- SubscriberConfig,
7
- StreamTrade,
8
- Trades,
9
- } from "../../types";
10
- import { MAX_BUFFER_LEN } from "../../utils";
11
-
12
- /**
13
- * Subscriber class for handling WebSocket subscriptions
14
- */
15
- export class Subscriber {
16
- streamURL: string;
17
- buffer: (DeltaEvent | Trades | Account)[];
18
- maxBufferLen: number;
19
-
20
- /**
21
- * Create a new Subscriber instance
22
- * @param config Subscriber configuration
23
- */
24
- constructor(config: SubscriberConfig) {
25
- this.streamURL = config.streamURL;
26
- this.buffer = [];
27
- this.maxBufferLen = config.maxBufferLen ?? MAX_BUFFER_LEN;
28
- }
29
-
30
- /**
31
- * Subscribe to WebSocket events
32
- */
33
- subscribe(): void {
34
- // TODO: Implement subscription logic
35
- }
36
- }
37
-
38
- /**
39
- * Interface for orderbook subscription
40
- */
41
- export interface OrderbookSubscription extends EventEmitter {
42
- on(event: "message", listener: (data: OrderbookResponse) => void): this;
43
- on(event: "error", listener: (error: Error) => void): this;
44
- close(): void;
45
- removeAllListeners(event?: string): this;
46
- }
47
-
48
- /**
49
- * Interface for trade subscription
50
- */
51
- export interface TradeSubscription extends EventEmitter {
52
- on(event: "message", listener: (data: StreamTrade[]) => void): this;
53
- on(event: "error", listener: (error: Error) => void): this;
54
- close(): void;
55
- removeAllListeners(event?: string): this;
56
- }
@@ -1,76 +0,0 @@
1
- /**
2
- * Options for creating a NordError
3
- */
4
- export interface NordErrorOptions {
5
- /** The original error that caused this error */
6
- cause?: unknown;
7
-
8
- /** HTTP status code (if applicable) */
9
- statusCode?: number;
10
-
11
- /** Additional error details */
12
- details?: Record<string, unknown>;
13
- }
14
-
15
- /**
16
- * Custom error class for Nord-related errors
17
- */
18
- export class NordError extends Error {
19
- /** The original error that caused this error */
20
- public readonly cause?: unknown;
21
-
22
- /** HTTP status code (if applicable) */
23
- public readonly statusCode?: number;
24
-
25
- /** Additional error details */
26
- public readonly details?: Record<string, unknown>;
27
-
28
- /**
29
- * Create a new NordError
30
- *
31
- * @param message - Error message
32
- * @param options - Error options
33
- */
34
- constructor(message: string, options: NordErrorOptions = {}) {
35
- super(message);
36
-
37
- this.name = "NordError";
38
- this.cause = options.cause;
39
- this.statusCode = options.statusCode;
40
- this.details = options.details;
41
-
42
- // Capture stack trace
43
- if (Error.captureStackTrace) {
44
- Error.captureStackTrace(this, NordError);
45
- }
46
-
47
- // Handle nested errors
48
- if (this.cause instanceof Error) {
49
- this.stack =
50
- this.stack + "\nCaused by: " + (this.cause.stack || this.cause.message);
51
- }
52
- }
53
-
54
- /**
55
- * Convert the error to a string representation
56
- *
57
- * @returns String representation of the error
58
- */
59
- toString(): string {
60
- let result = `${this.name}: ${this.message}`;
61
-
62
- if (this.statusCode) {
63
- result += ` \nstatus: ${this.statusCode}`;
64
- }
65
-
66
- if (this.details && Object.keys(this.details).length > 0) {
67
- result += ` \ndetails: ${JSON.stringify(this.details, null, 2)}`;
68
- }
69
-
70
- if (this.cause) {
71
- result += ` \ncause: ${this.cause.toString()}`;
72
- }
73
-
74
- return result;
75
- }
76
- }
package/src/types.ts DELETED
@@ -1,377 +0,0 @@
1
- import * as proto from "./gen/nord_pb";
2
- import type { components } from "./gen/openapi.ts";
3
- import Decimal from "decimal.js";
4
- import { toScaledU64 } from "./utils";
5
-
6
- /**
7
- * The peak TPS rate is queried over the specified period.
8
- * The period is specified in units of: {hour, day, week, month, year}.
9
- * Example inputs:
10
- * 1. AggregateMetrics.txPeakTpsPeriod = 3,
11
- * AggregateMetrics.txPeakTpsPeriodUnit = "d" => Peak TPS over last 3 days.
12
- * 1. AggregateMetrics.txPeakTpsPeriod = 1,
13
- * AggregateMetrics.txPeakTpsPeriodUnit = "w" => Peak TPS over last week.
14
- */
15
- export enum PeakTpsPeriodUnit {
16
- Hour = "h",
17
- Day = "d",
18
- Week = "w",
19
- Month = "m",
20
- Year = "y",
21
- }
22
-
23
- /**
24
- * Nord subscription type for trades or deltas
25
- */
26
- export type SubscriptionType = "trades" | "deltas" | "account";
27
-
28
- /**
29
- * Pattern for a valid Nord subscription
30
- * Format should be: "<type>@<parameter>"
31
- * Examples: "trades@BTCUSDC", "deltas@ETHUSDC", "account@42"
32
- */
33
- export type SubscriptionPattern = `${SubscriptionType}@${string}` | string;
34
-
35
- /**
36
- * Configuration options for the Nord client
37
- */
38
- export interface NordConfig {
39
- /** Base URL for the Nord web server */
40
- webServerUrl: string;
41
- /** App address */
42
- app: string;
43
- /** Solana cluster URL */
44
- solanaUrl: string;
45
- /** Proton URL, defaults to webServerUrl */
46
- // TODO: this is ass. move to NordUser.
47
- protonUrl?: string;
48
- /**
49
- * Whether to initialize WebSockets on creation, defaults to true
50
- * @deprecated this is a funky api we're gonna be removing it
51
- */
52
- initWebSockets?: boolean;
53
- }
54
-
55
- export type MarketsInfo = components["schemas"]["MarketsInfo"];
56
- export type Market = MarketsInfo["markets"][number];
57
- export type Token = MarketsInfo["tokens"][number];
58
- export type Account = components["schemas"]["Account"];
59
- export type TradesResponse =
60
- components["schemas"]["PageResult_for_String_and_Trade"];
61
- export type User = components["schemas"]["User"];
62
- export type OrderbookResponse = components["schemas"]["OrderbookInfo"];
63
- export type MarketStats = components["schemas"]["MarketStats"];
64
- export type OrderbookInfo = components["schemas"]["OrderbookInfo"];
65
- export type MarketStatsFromApi = components["schemas"]["MarketStats"];
66
- export type TradeFromApi = components["schemas"]["Trade"];
67
- // Generic PageResult type - note that K and V must match existing schema keys
68
- export type PageResult<K extends string, V extends string> = K extends "String"
69
- ? V extends "OrderInfo"
70
- ? components["schemas"]["PageResult_for_String_and_OrderInfo"]
71
- : V extends "Trade"
72
- ? components["schemas"]["PageResult_for_String_and_Trade"]
73
- : never
74
- : never;
75
- export type PageResultStringOrderInfo =
76
- components["schemas"]["PageResult_for_String_and_OrderInfo"];
77
- export type PageResultStringTrade =
78
- components["schemas"]["PageResult_for_String_and_Trade"];
79
- export type OrderInfoFromApi = components["schemas"]["OrderInfo"];
80
- export type OpenOrder = components["schemas"]["OpenOrder"];
81
- export type Balance = components["schemas"]["Balance"];
82
- export type PositionSummary = components["schemas"]["PositionSummary"];
83
- export type PerpPosition = components["schemas"]["PerpPosition"];
84
- export type AccountMarginsView = components["schemas"]["AccountMarginsView"];
85
- export type SideSummary = components["schemas"]["SideSummary"];
86
- export type UserSession = components["schemas"]["UserSession"];
87
- export type ActionsItem = components["schemas"]["ActionsItem"];
88
- export type FillRole = components["schemas"]["FillRole"];
89
- export type PerpMarketStatsFromApi = components["schemas"]["PerpMarketStats"];
90
- export type SideFromApi = components["schemas"]["Side"];
91
- export type FillModeFromApi = components["schemas"]["FillMode"];
92
- export type PlacementOrigin = components["schemas"]["PlacementOrigin"];
93
- export type FinalizationReason = components["schemas"]["FinalizationReason"];
94
- export type AccountPnlQuery = components["schemas"]["AccountPnlQuery"];
95
- export type AccountPnl = components["schemas"]["AccountPnl"];
96
- export type AccountPnlPage =
97
- components["schemas"]["PageResult_for_uint64_and_AccountPnl"];
98
- export type AccountTriggerInfo = components["schemas"]["AccountTriggerInfo"];
99
- export type TriggerHistoryPage =
100
- components["schemas"]["PageResult_for_uint64_and_HistoryTriggerInfo"];
101
- export type HistoryTriggerQuery = components["schemas"]["AccountTriggersQuery"];
102
- export type FeeTierConfig = components["schemas"]["FeeTierConfig"];
103
- export type FeeTierId = components["schemas"]["FeeTierId"];
104
- export type TokenStats = components["schemas"]["TokenStats"];
105
- export type AccountFeeTier = components["schemas"]["AccountFeeTier"];
106
- export type AccountFeeTierPage =
107
- components["schemas"]["PageResult_for_uint32_and_AccountFeeTier"];
108
-
109
- /**
110
- * Configuration options for the Nord client
111
- */
112
- export interface TokenInfo {
113
- address: string;
114
- precision: number;
115
- tokenId: number;
116
- name: string;
117
- }
118
-
119
- export interface Order {
120
- orderId: number;
121
- isLong: boolean;
122
- size: number;
123
- price: number;
124
- marketId: number;
125
- }
126
-
127
- export enum KeyType {
128
- Ed25519,
129
- Secp256k1,
130
- Bls12_381,
131
- }
132
-
133
- export enum Side {
134
- Ask = "ask",
135
- Bid = "bid",
136
- }
137
-
138
- export enum FillMode {
139
- Limit,
140
- PostOnly,
141
- ImmediateOrCancel,
142
- FillOrKill,
143
- }
144
-
145
- export enum TriggerKind {
146
- StopLoss = 0,
147
- TakeProfit = 1,
148
- }
149
-
150
- export enum TriggerStatus {
151
- Active = 0,
152
- Success = 1,
153
- Cancel = 2,
154
- Remove = 4,
155
- }
156
-
157
- export interface SubscriberConfig {
158
- streamURL: string;
159
- maxBufferLen?: number;
160
- }
161
-
162
- export interface DeltaEvent {
163
- last_update_id: number;
164
- update_id: number;
165
- market_symbol: string;
166
- asks: OrderbookEntry[];
167
- bids: OrderbookEntry[];
168
- }
169
-
170
- export interface StreamTrade {
171
- side: Side;
172
- price: number;
173
- size: number;
174
- order_id: number;
175
- }
176
-
177
- export interface Trades {
178
- last_update_id: number;
179
- update_id: number;
180
- market_symbol: string;
181
- trades: StreamTrade[];
182
- }
183
-
184
- export interface LocalOrderInfo {
185
- id: number;
186
- reduce_only: boolean;
187
- limit_price: number;
188
- size: number;
189
- account_id: number;
190
- sender_tracking_id?: number;
191
- }
192
-
193
- export interface HashMap<T> {
194
- [key: number]: T;
195
- }
196
-
197
- export interface ActionResponse {
198
- actionId: number;
199
- action: proto.Action;
200
- physicalExecTime: Date;
201
- }
202
-
203
- /**
204
- * Block summary.
205
- * block_number Block number.
206
- * from_action_id First action_id in the block.
207
- * to_action_id Last action_id in the block.
208
- */
209
- export interface BlockSummary {
210
- block_number: number;
211
- from_action_id: number;
212
- to_action_id: number;
213
- }
214
-
215
- /**
216
- * Aggregate metrics
217
- * blocks_total: Total number of L2 blocks.
218
- * tx_total: Total number of transactions.
219
- * tx_tps: Transaction throughput.
220
- * tx_tps_peak: Peak transaction throughput.
221
- * request_latency_average: Average request latency.
222
- */
223
- export interface AggregateMetrics {
224
- blocks_total: number;
225
- tx_total: number;
226
- tx_tps: number;
227
- tx_tps_peak: number;
228
- request_latency_average: number;
229
- }
230
-
231
- /**
232
- * Converts a `FillMode` enum to its corresponding protobuf representation.
233
- *
234
- * @param x - The fill mode to convert.
235
- * @returns The corresponding protobuf fill mode.
236
- * @throws Will throw an error if provided with an invalid fill mode.
237
- */
238
- export function fillModeToProtoFillMode(x: FillMode): proto.FillMode {
239
- if (x === FillMode.Limit) return proto.FillMode.LIMIT;
240
- if (x === FillMode.PostOnly) return proto.FillMode.POST_ONLY;
241
- if (x === FillMode.ImmediateOrCancel) {
242
- return proto.FillMode.IMMEDIATE_OR_CANCEL;
243
- }
244
- if (x === FillMode.FillOrKill) return proto.FillMode.FILL_OR_KILL;
245
- throw new Error("Invalid fill mode");
246
- }
247
-
248
- /**
249
- * Orderbook entry representing price and size
250
- */
251
- export interface OrderbookEntry {
252
- price: number;
253
- size: number;
254
- }
255
-
256
- /**
257
- * Query parameters for orderbook
258
- *
259
- * Note: While you can provide either symbol or market_id, the API endpoint only accepts market_id.
260
- * If you provide a symbol, it will be converted to a market_id internally.
261
- */
262
- export interface OrderbookQuery {
263
- symbol?: string;
264
- market_id?: number;
265
- }
266
-
267
- /**
268
- * Response for timestamp query
269
- */
270
- export interface TimestampResponse {
271
- timestamp: number; // engine's current logical timestamp
272
- }
273
-
274
- /**
275
- * Response for action nonce query
276
- */
277
- export interface ActionNonceResponse {
278
- nonce: number; // next expected action nonce
279
- }
280
-
281
- /**
282
- * WebSocket message types
283
- */
284
- export enum WebSocketMessageType {
285
- TradeUpdate = "trades",
286
- DeltaUpdate = "delta",
287
- AccountUpdate = "account",
288
- }
289
-
290
- /**
291
- * WebSocket trade update message
292
- */
293
- export interface WebSocketTradeUpdate {
294
- e: WebSocketMessageType.TradeUpdate;
295
- symbol: string;
296
- trades: StreamTrade[];
297
- timestamp: number;
298
- }
299
-
300
- /**
301
- * WebSocket delta update message
302
- */
303
- export interface WebSocketDeltaUpdate {
304
- e: WebSocketMessageType.DeltaUpdate;
305
- last_update_id: number;
306
- update_id: number;
307
- market_symbol: string;
308
- asks: OrderbookEntry[];
309
- bids: OrderbookEntry[];
310
- timestamp: number;
311
- }
312
-
313
- /**
314
- * WebSocket user update message
315
- */
316
- export interface WebSocketAccountUpdate {
317
- e: WebSocketMessageType.AccountUpdate;
318
- accountId: number;
319
- account: Account;
320
- timestamp: number;
321
- }
322
-
323
- export type WebSocketMessage =
324
- | WebSocketTradeUpdate
325
- | WebSocketDeltaUpdate
326
- | WebSocketAccountUpdate;
327
-
328
- export interface SPLTokenInfo {
329
- mint: string;
330
- precision: number;
331
- tokenId: number;
332
- name: string;
333
- }
334
-
335
- // Positive decimal price and size.
336
- // Example:
337
- // ```
338
- // const limit = new QuoteSize(new Decimal(114000), new Decimal(0.00035)),
339
- //```
340
- // Gives 40$ USD limit.
341
- //
342
- // Given price is same(or very close) to the market price,
343
- // limit gives size tick as close as possible to settlemnt size tick.
344
-
345
- // If you want to get smaller tick on client (on server it will not change),
346
- // do `new QuoteSize(new Decimal(114000/2), new Decimal(0.00070))`.
347
- // It will be 40$ limit, but may help if BTC suddently moves fast.
348
- export class QuoteSize {
349
- price: Decimal;
350
- size: Decimal;
351
- /// Input can be only positive values.
352
- constructor(quotePrice: Decimal.Value, quoteSize: Decimal.Value) {
353
- const p = new Decimal(quotePrice);
354
- const s = new Decimal(quoteSize);
355
- if (!p.isPositive() || !s.isPositive()) {
356
- throw new Error("quotePrice and quoteSize must be positive");
357
- }
358
- this.price = p;
359
- this.size = s;
360
- }
361
-
362
- // USD value of limit, use for debug
363
- value(): Decimal {
364
- return this.price.mul(this.size);
365
- }
366
-
367
- // Converts to wire format to be send to server, scaling price and size according to market decimals.
368
- toWire(
369
- marketPriceDecimals: number,
370
- marketSizeDecimals: number,
371
- ): { price: bigint; size: bigint } {
372
- return {
373
- price: toScaledU64(this.price, marketPriceDecimals),
374
- size: toScaledU64(this.size, marketSizeDecimals),
375
- };
376
- }
377
- }