@n1xyz/nord-ts 0.0.18-8121ed05.0 → 0.0.18
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/.local/qa.ts +77 -0
- package/.local/test-atomic.ts +112 -0
- package/check.sh +4 -0
- package/default.nix +47 -0
- package/dist/api/client.d.ts +14 -0
- package/dist/api/client.js +45 -0
- package/dist/gen/nord.d.ts +52 -23
- package/dist/gen/nord.js +322 -170
- package/dist/gen/openapi.d.ts +2244 -0
- package/dist/gen/openapi.js +6 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -9
- package/dist/nord/api/actions.d.ts +30 -1
- package/dist/nord/api/actions.js +60 -3
- package/dist/nord/api/core.d.ts +1 -34
- package/dist/nord/api/core.js +0 -71
- package/dist/nord/client/Nord.d.ts +31 -33
- package/dist/nord/client/Nord.js +100 -60
- package/dist/nord/client/NordUser.d.ts +64 -11
- package/dist/nord/client/NordUser.js +90 -33
- package/dist/nord/index.d.ts +0 -2
- package/dist/nord/index.js +0 -2
- package/dist/nord/models/Subscriber.d.ts +2 -2
- package/dist/types.d.ts +43 -190
- package/dist/utils.d.ts +1 -19
- package/dist/utils.js +5 -39
- package/dist/websocket/NordWebSocketClient.js +18 -13
- package/dist/websocket/index.d.ts +1 -1
- package/package.json +20 -27
- package/src/index.ts +0 -16
- package/src/nord/api/actions.ts +131 -9
- package/src/nord/api/core.ts +0 -71
- package/src/nord/client/Nord.ts +142 -76
- package/src/nord/client/NordUser.ts +171 -50
- package/src/nord/index.ts +0 -2
- package/src/nord/models/Subscriber.ts +2 -2
- package/src/types.ts +55 -216
- package/src/utils.ts +6 -42
- package/src/websocket/NordWebSocketClient.ts +23 -15
- package/src/websocket/index.ts +1 -1
- package/tests/utils.spec.ts +1 -34
- package/dist/idl/bridge.json +0 -1506
- package/jest.config.ts +0 -9
- package/nodemon.json +0 -4
- package/protoc-generate.sh +0 -23
- package/src/idl/bridge.json +0 -1506
- package/src/nord/api/market.ts +0 -122
- package/src/nord/api/queries.ts +0 -135
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as proto from "./gen/nord";
|
|
2
|
+
import type { components } from "./gen/openapi.ts";
|
|
2
3
|
/**
|
|
3
4
|
* The peak TPS rate is queried over the specified period.
|
|
4
5
|
* The period is specified in units of: {hour, day, week, month, year}.
|
|
@@ -41,6 +42,35 @@ export interface NordConfig {
|
|
|
41
42
|
*/
|
|
42
43
|
initWebSockets?: boolean;
|
|
43
44
|
}
|
|
45
|
+
export type Info = components["schemas"]["Info2"];
|
|
46
|
+
export type Market = Info["markets"][number];
|
|
47
|
+
export type Token = Info["tokens"][number];
|
|
48
|
+
export type Account = components["schemas"]["Account"];
|
|
49
|
+
export type TradesResponse = components["schemas"]["PageResult_for_String_and_Trade"];
|
|
50
|
+
export type User = components["schemas"]["User"];
|
|
51
|
+
export type OrderbookResponse = components["schemas"]["OrderbookInfo"];
|
|
52
|
+
export type MarketStats = components["schemas"]["MarketStats"];
|
|
53
|
+
export type OrderbookInfo = components["schemas"]["OrderbookInfo"];
|
|
54
|
+
export type MarketStatsFromApi = components["schemas"]["MarketStats"];
|
|
55
|
+
export type TradeFromApi = components["schemas"]["Trade"];
|
|
56
|
+
export type PageResult<K extends string, V extends string> = K extends "String" ? V extends "OrderInfo" ? components["schemas"]["PageResult_for_String_and_OrderInfo"] : V extends "Trade" ? components["schemas"]["PageResult_for_String_and_Trade"] : never : never;
|
|
57
|
+
export type PageResultStringOrderInfo = components["schemas"]["PageResult_for_String_and_OrderInfo"];
|
|
58
|
+
export type PageResultStringTrade = components["schemas"]["PageResult_for_String_and_Trade"];
|
|
59
|
+
export type OrderInfoFromApi = components["schemas"]["OrderInfo"];
|
|
60
|
+
export type OpenOrder = components["schemas"]["OpenOrder"];
|
|
61
|
+
export type Balance = components["schemas"]["Balance"];
|
|
62
|
+
export type PositionSummary = components["schemas"]["PositionSummary"];
|
|
63
|
+
export type PerpPosition = components["schemas"]["PerpPosition"];
|
|
64
|
+
export type AccountMarginsView = components["schemas"]["AccountMarginsView"];
|
|
65
|
+
export type SideSummary = components["schemas"]["SideSummary"];
|
|
66
|
+
export type UserSession = components["schemas"]["UserSession"];
|
|
67
|
+
export type ActionsItem = components["schemas"]["ActionsItem"];
|
|
68
|
+
export type FillRole = components["schemas"]["FillRole"];
|
|
69
|
+
export type PerpMarketStatsFromApi = components["schemas"]["PerpMarketStats"];
|
|
70
|
+
export type SideFromApi = components["schemas"]["Side"];
|
|
71
|
+
export type FillModeFromApi = components["schemas"]["FillMode"];
|
|
72
|
+
export type PlacementOrigin = components["schemas"]["PlacementOrigin"];
|
|
73
|
+
export type FinalizationReason = components["schemas"]["FinalizationReason"];
|
|
44
74
|
/**
|
|
45
75
|
* Configuration options for the Nord client
|
|
46
76
|
*/
|
|
@@ -76,25 +106,6 @@ export interface SubscriberConfig {
|
|
|
76
106
|
streamURL: string;
|
|
77
107
|
maxBufferLen?: number;
|
|
78
108
|
}
|
|
79
|
-
export interface Market {
|
|
80
|
-
marketId: number;
|
|
81
|
-
symbol: string;
|
|
82
|
-
priceDecimals: number;
|
|
83
|
-
sizeDecimals: number;
|
|
84
|
-
baseTokenId: number;
|
|
85
|
-
quoteTokenId: number;
|
|
86
|
-
frozen: boolean;
|
|
87
|
-
}
|
|
88
|
-
export interface Token {
|
|
89
|
-
tokenId: number;
|
|
90
|
-
symbol: string;
|
|
91
|
-
decimals: number;
|
|
92
|
-
mintAddr: string;
|
|
93
|
-
}
|
|
94
|
-
export interface Info {
|
|
95
|
-
markets: Market[];
|
|
96
|
-
tokens: Token[];
|
|
97
|
-
}
|
|
98
109
|
export interface DeltaEvent {
|
|
99
110
|
last_update_id: number;
|
|
100
111
|
update_id: number;
|
|
@@ -102,7 +113,7 @@ export interface DeltaEvent {
|
|
|
102
113
|
asks: OrderbookEntry[];
|
|
103
114
|
bids: OrderbookEntry[];
|
|
104
115
|
}
|
|
105
|
-
export interface
|
|
116
|
+
export interface StreamTrade {
|
|
106
117
|
side: Side;
|
|
107
118
|
price: number;
|
|
108
119
|
size: number;
|
|
@@ -112,85 +123,23 @@ export interface Trades {
|
|
|
112
123
|
last_update_id: number;
|
|
113
124
|
update_id: number;
|
|
114
125
|
market_symbol: string;
|
|
115
|
-
trades:
|
|
126
|
+
trades: StreamTrade[];
|
|
116
127
|
}
|
|
117
|
-
export interface
|
|
128
|
+
export interface LocalOrderInfo {
|
|
118
129
|
id: number;
|
|
119
130
|
reduce_only: boolean;
|
|
120
131
|
limit_price: number;
|
|
121
132
|
size: number;
|
|
122
133
|
account_id: number;
|
|
134
|
+
sender_tracking_id?: number;
|
|
123
135
|
}
|
|
124
136
|
export interface HashMap<T> {
|
|
125
137
|
[key: number]: T;
|
|
126
138
|
}
|
|
127
|
-
export interface Account {
|
|
128
|
-
last_update_id: number;
|
|
129
|
-
update_id: number;
|
|
130
|
-
account_id: number;
|
|
131
|
-
fills: HashMap<number>;
|
|
132
|
-
places: HashMap<OrderInfo>;
|
|
133
|
-
cancels: HashMap<OrderInfo>;
|
|
134
|
-
balances: HashMap<number>;
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Query the transactions in the specified L2 block.
|
|
138
|
-
* block_number specifies the block number to query.
|
|
139
|
-
* If not specified, transactions from latest block are returned.
|
|
140
|
-
*/
|
|
141
|
-
export interface BlockQuery {
|
|
142
|
-
block_number?: number;
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Response for BlockQuery.
|
|
146
|
-
* block_number specifies the block number being returned.
|
|
147
|
-
* actions are the list of transactions from the block.
|
|
148
|
-
*/
|
|
149
|
-
export interface BlockResponse {
|
|
150
|
-
block_number: number;
|
|
151
|
-
actions: ActionInfo[];
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Response for BlockSummaryQuery.
|
|
155
|
-
* block_summary is the summary of upto the last N blocks.
|
|
156
|
-
* The server can return fewer than last_n block summary if
|
|
157
|
-
* fewer blocks are available or if it exceeds a max cap.
|
|
158
|
-
*/
|
|
159
|
-
export interface BlockSummaryResponse {
|
|
160
|
-
block_summary: BlockSummary[];
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Query the action for the specified action id.
|
|
164
|
-
* action_id specifies the action to query.
|
|
165
|
-
*/
|
|
166
|
-
export interface ActionQuery {
|
|
167
|
-
action_id: number;
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Response for ActionQuery.
|
|
171
|
-
* block_number the block the action is part of.
|
|
172
|
-
* If the action is not yet included in any block, null is returned.
|
|
173
|
-
* action the transaction.
|
|
174
|
-
*/
|
|
175
139
|
export interface ActionResponse {
|
|
176
|
-
|
|
140
|
+
actionId: number;
|
|
177
141
|
action: proto.Action;
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Query the recent actions
|
|
181
|
-
* last_n requests last N actions.
|
|
182
|
-
*/
|
|
183
|
-
export interface ActionsQuery {
|
|
184
|
-
last_n: number;
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Response for ActionsQuery.
|
|
188
|
-
* actions returns upto the last N actions.
|
|
189
|
-
* The server can return fewer than last_n actions if
|
|
190
|
-
* fewer actions are available or if it exceeds a max cap.
|
|
191
|
-
*/
|
|
192
|
-
export interface ActionsResponse {
|
|
193
|
-
actions: ActionsExtendedInfo[];
|
|
142
|
+
physicalExecTime: Date;
|
|
194
143
|
}
|
|
195
144
|
/**
|
|
196
145
|
* Block summary.
|
|
@@ -203,29 +152,6 @@ export interface BlockSummary {
|
|
|
203
152
|
from_action_id: number;
|
|
204
153
|
to_action_id: number;
|
|
205
154
|
}
|
|
206
|
-
/**
|
|
207
|
-
* Info about the block transaction.
|
|
208
|
-
* action_id is the action identifier.
|
|
209
|
-
* action in protobuf format.
|
|
210
|
-
* exec_timestamp is the execution timestamp.
|
|
211
|
-
*/
|
|
212
|
-
export interface ActionInfo {
|
|
213
|
-
action_id: number;
|
|
214
|
-
action: proto.Action;
|
|
215
|
-
exec_timestamp: number;
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Extended info about the block transaction.
|
|
219
|
-
* block_number the block the action is part of.
|
|
220
|
-
* If the action is not yet included in any block, null is returned.
|
|
221
|
-
* action_id of the action.
|
|
222
|
-
* action the transaction.
|
|
223
|
-
*/
|
|
224
|
-
export interface ActionsExtendedInfo {
|
|
225
|
-
block_number?: number;
|
|
226
|
-
action_id: number;
|
|
227
|
-
action: proto.Action;
|
|
228
|
-
}
|
|
229
155
|
/**
|
|
230
156
|
* Aggregate metrics
|
|
231
157
|
* blocks_total: Total number of L2 blocks.
|
|
@@ -241,45 +167,6 @@ export interface AggregateMetrics {
|
|
|
241
167
|
tx_tps_peak: number;
|
|
242
168
|
request_latency_average: number;
|
|
243
169
|
}
|
|
244
|
-
export interface RollmanBlockResponse {
|
|
245
|
-
block_number: number;
|
|
246
|
-
actions: RollmanActionInfo[];
|
|
247
|
-
}
|
|
248
|
-
export interface RollmanActionResponse {
|
|
249
|
-
block_number?: number;
|
|
250
|
-
action_pb: Uint8Array;
|
|
251
|
-
exec_timestamp: number;
|
|
252
|
-
}
|
|
253
|
-
export interface RollmanActionsResponse {
|
|
254
|
-
actions: RollmanActionExtendedInfo[];
|
|
255
|
-
}
|
|
256
|
-
export interface RollmanActionInfo {
|
|
257
|
-
action_id: number;
|
|
258
|
-
action_pb: Uint8Array;
|
|
259
|
-
exec_timestamp: number;
|
|
260
|
-
}
|
|
261
|
-
export interface RollmanActionExtendedInfo {
|
|
262
|
-
block_number?: number;
|
|
263
|
-
action_id: number;
|
|
264
|
-
action_pb: Uint8Array;
|
|
265
|
-
}
|
|
266
|
-
export interface MarketsStatsResponse {
|
|
267
|
-
markets: MarketStats[];
|
|
268
|
-
}
|
|
269
|
-
export interface MarketStats {
|
|
270
|
-
market_id: number;
|
|
271
|
-
index_price: [number, number];
|
|
272
|
-
volume_24h: number;
|
|
273
|
-
high_24h: number;
|
|
274
|
-
low_24h: number;
|
|
275
|
-
perp_stats?: PerpMarketStats;
|
|
276
|
-
}
|
|
277
|
-
export interface PerpMarketStats {
|
|
278
|
-
mark_price?: number;
|
|
279
|
-
funding_rate?: number;
|
|
280
|
-
next_funding_time?: Date;
|
|
281
|
-
open_interest?: number;
|
|
282
|
-
}
|
|
283
170
|
/**
|
|
284
171
|
* Converts a `FillMode` enum to its corresponding protobuf representation.
|
|
285
172
|
*
|
|
@@ -288,37 +175,6 @@ export interface PerpMarketStats {
|
|
|
288
175
|
* @throws Will throw an error if provided with an invalid fill mode.
|
|
289
176
|
*/
|
|
290
177
|
export declare function fillModeToProtoFillMode(x: FillMode): proto.FillMode;
|
|
291
|
-
/**
|
|
292
|
-
* Response for trades query with pagination support
|
|
293
|
-
*/
|
|
294
|
-
export interface TradesResponse {
|
|
295
|
-
trades: Trade[];
|
|
296
|
-
accountId: number;
|
|
297
|
-
since?: string;
|
|
298
|
-
until?: string;
|
|
299
|
-
nextPageId?: string;
|
|
300
|
-
}
|
|
301
|
-
/**
|
|
302
|
-
* Query parameters for trades endpoint
|
|
303
|
-
*/
|
|
304
|
-
export interface TradesQuery {
|
|
305
|
-
accountId: number;
|
|
306
|
-
since?: string;
|
|
307
|
-
until?: string;
|
|
308
|
-
pageId?: string;
|
|
309
|
-
}
|
|
310
|
-
/**
|
|
311
|
-
* Response for user account IDs query
|
|
312
|
-
*/
|
|
313
|
-
export interface UserAccountIdsResponse {
|
|
314
|
-
accountIds: number[];
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
* Query parameters for user account IDs
|
|
318
|
-
*/
|
|
319
|
-
export interface UserAccountIdsQuery {
|
|
320
|
-
pubkey: string;
|
|
321
|
-
}
|
|
322
178
|
/**
|
|
323
179
|
* Orderbook entry representing price and size
|
|
324
180
|
*/
|
|
@@ -326,15 +182,6 @@ export interface OrderbookEntry {
|
|
|
326
182
|
price: number;
|
|
327
183
|
size: number;
|
|
328
184
|
}
|
|
329
|
-
/**
|
|
330
|
-
* Response for orderbook query
|
|
331
|
-
*/
|
|
332
|
-
export interface OrderbookResponse {
|
|
333
|
-
symbol: string;
|
|
334
|
-
asks: OrderbookEntry[];
|
|
335
|
-
bids: OrderbookEntry[];
|
|
336
|
-
timestamp: number;
|
|
337
|
-
}
|
|
338
185
|
/**
|
|
339
186
|
* Query parameters for orderbook
|
|
340
187
|
*
|
|
@@ -380,7 +227,7 @@ export interface WebSocketSubscription {
|
|
|
380
227
|
export interface WebSocketTradeUpdate {
|
|
381
228
|
e: WebSocketMessageType.TradeUpdate;
|
|
382
229
|
symbol: string;
|
|
383
|
-
trades:
|
|
230
|
+
trades: StreamTrade[];
|
|
384
231
|
timestamp: number;
|
|
385
232
|
}
|
|
386
233
|
/**
|
|
@@ -405,3 +252,9 @@ export interface WebSocketAccountUpdate {
|
|
|
405
252
|
timestamp: number;
|
|
406
253
|
}
|
|
407
254
|
export type WebSocketMessage = WebSocketSubscription | WebSocketTradeUpdate | WebSocketDeltaUpdate | WebSocketAccountUpdate;
|
|
255
|
+
export interface SPLTokenInfo {
|
|
256
|
+
mint: string;
|
|
257
|
+
precision: number;
|
|
258
|
+
tokenId: number;
|
|
259
|
+
name: string;
|
|
260
|
+
}
|
package/dist/utils.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export declare const MAX_BUFFER_LEN = 10000;
|
|
|
10
10
|
/** Any type convertible to bigint */
|
|
11
11
|
export type BigIntValue = bigint | number | string;
|
|
12
12
|
export declare function panic(message: string): never;
|
|
13
|
+
export declare function isRfc3339(s: string): boolean;
|
|
13
14
|
export declare function assert(predicate: boolean, message?: string): void;
|
|
14
15
|
/**
|
|
15
16
|
* Extracts value out of optional if it's defined, or throws error if it's not
|
|
@@ -18,19 +19,6 @@ export declare function assert(predicate: boolean, message?: string): void;
|
|
|
18
19
|
* @returns Unwrapped value
|
|
19
20
|
*/
|
|
20
21
|
export declare function optExpect<T>(value: T | undefined, message: string): T;
|
|
21
|
-
/**
|
|
22
|
-
* Unwraps optional value with default error message
|
|
23
|
-
* @param value
|
|
24
|
-
* @returns
|
|
25
|
-
*/
|
|
26
|
-
export declare function optUnwrap<T>(value: T | undefined): T;
|
|
27
|
-
/**
|
|
28
|
-
* Applies function to value if it's defined, or passes `undefined` through
|
|
29
|
-
* @param value Optional value to map
|
|
30
|
-
* @param mapFn Mapper function
|
|
31
|
-
* @returns Either mapped value or undefined
|
|
32
|
-
*/
|
|
33
|
-
export declare function optMap<T, U>(value: T | undefined, mapFn: (arg: T) => U): U | undefined;
|
|
34
22
|
/** Behaves same as `node-fetch/fetch` but throws if response is a failure
|
|
35
23
|
*
|
|
36
24
|
* @param url Request HTTP URL
|
|
@@ -80,12 +68,6 @@ export declare const toScaledU64: (x: Decimal.Value, decimals: number) => bigint
|
|
|
80
68
|
* @returns Rescaled unsigned integer
|
|
81
69
|
*/
|
|
82
70
|
export declare const toScaledU128: (x: Decimal.Value, decimals: number) => bigint;
|
|
83
|
-
/**
|
|
84
|
-
* Converts U128 into pair of U64 numbers, to pass it through protobuf
|
|
85
|
-
* @param value integer, must fit U128 limits
|
|
86
|
-
* @returns Pair of U64 integers which represent original number split in two
|
|
87
|
-
*/
|
|
88
|
-
export declare function bigIntToProtoU128(value: bigint): proto.U128;
|
|
89
71
|
/**
|
|
90
72
|
* Encodes any protobuf message into a length-delimited format,
|
|
91
73
|
* i.e. prefixed with its length encoded as varint
|
package/dist/utils.js
CHANGED
|
@@ -5,14 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.toScaledU128 = exports.toScaledU64 = exports.MAX_BUFFER_LEN = exports.ZERO_DECIMAL = exports.SESSION_TTL = void 0;
|
|
7
7
|
exports.panic = panic;
|
|
8
|
+
exports.isRfc3339 = isRfc3339;
|
|
8
9
|
exports.assert = assert;
|
|
9
10
|
exports.optExpect = optExpect;
|
|
10
|
-
exports.optUnwrap = optUnwrap;
|
|
11
|
-
exports.optMap = optMap;
|
|
12
11
|
exports.checkedFetch = checkedFetch;
|
|
13
12
|
exports.signAction = signAction;
|
|
14
13
|
exports.makeWalletSignFn = makeWalletSignFn;
|
|
15
|
-
exports.bigIntToProtoU128 = bigIntToProtoU128;
|
|
16
14
|
exports.encodeLengthDelimited = encodeLengthDelimited;
|
|
17
15
|
exports.decodeLengthDelimited = decodeLengthDelimited;
|
|
18
16
|
exports.checkPubKeyLength = checkPubKeyLength;
|
|
@@ -37,6 +35,10 @@ const MAX_PAYLOAD_SIZE = 100 * 1024; // 100 kB
|
|
|
37
35
|
function panic(message) {
|
|
38
36
|
throw new Error(message);
|
|
39
37
|
}
|
|
38
|
+
function isRfc3339(s) {
|
|
39
|
+
const REGEX = /^((?:(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2}:\d{2}(?:\.\d+)?))(Z|[\+-]\d{2}:\d{2})?)$/;
|
|
40
|
+
return REGEX.test(s);
|
|
41
|
+
}
|
|
40
42
|
function assert(predicate, message) {
|
|
41
43
|
if (!predicate)
|
|
42
44
|
panic(message ?? "Assertion violated");
|
|
@@ -52,23 +54,6 @@ function optExpect(value, message) {
|
|
|
52
54
|
throw new Error(message);
|
|
53
55
|
return value;
|
|
54
56
|
}
|
|
55
|
-
/**
|
|
56
|
-
* Unwraps optional value with default error message
|
|
57
|
-
* @param value
|
|
58
|
-
* @returns
|
|
59
|
-
*/
|
|
60
|
-
function optUnwrap(value) {
|
|
61
|
-
return optExpect(value, "Optional contains no value");
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Applies function to value if it's defined, or passes `undefined` through
|
|
65
|
-
* @param value Optional value to map
|
|
66
|
-
* @param mapFn Mapper function
|
|
67
|
-
* @returns Either mapped value or undefined
|
|
68
|
-
*/
|
|
69
|
-
function optMap(value, mapFn) {
|
|
70
|
-
return value !== undefined ? mapFn(value) : undefined;
|
|
71
|
-
}
|
|
72
57
|
/** Behaves same as `node-fetch/fetch` but throws if response is a failure
|
|
73
58
|
*
|
|
74
59
|
* @param url Request HTTP URL
|
|
@@ -174,25 +159,6 @@ exports.toScaledU128 = makeToScaledBigUint({
|
|
|
174
159
|
precision: 40,
|
|
175
160
|
exponent: 56,
|
|
176
161
|
});
|
|
177
|
-
const U64_MAX = (1n << 64n) - 1n;
|
|
178
|
-
const U128_MAX = (1n << 128n) - 1n;
|
|
179
|
-
/**
|
|
180
|
-
* Converts U128 into pair of U64 numbers, to pass it through protobuf
|
|
181
|
-
* @param value integer, must fit U128 limits
|
|
182
|
-
* @returns Pair of U64 integers which represent original number split in two
|
|
183
|
-
*/
|
|
184
|
-
function bigIntToProtoU128(value) {
|
|
185
|
-
if (value < 0n) {
|
|
186
|
-
throw new Error(`Negative number (${value})`);
|
|
187
|
-
}
|
|
188
|
-
if (value > U128_MAX) {
|
|
189
|
-
throw new Error(`U128 overflow (${value})`);
|
|
190
|
-
}
|
|
191
|
-
return {
|
|
192
|
-
lo: value & U64_MAX,
|
|
193
|
-
hi: (value >> 64n) & U64_MAX,
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
162
|
/**
|
|
197
163
|
* Encodes any protobuf message into a length-delimited format,
|
|
198
164
|
* i.e. prefixed with its length encoded as varint
|
|
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.NordWebSocketClient = void 0;
|
|
7
|
-
const ws_1 = __importDefault(require("ws"));
|
|
8
7
|
const events_1 = require("events");
|
|
8
|
+
const ws_1 = __importDefault(require("ws"));
|
|
9
9
|
const types_1 = require("../types");
|
|
10
10
|
const VALID_STREAM_TYPES = ["trades", "delta", "account"];
|
|
11
11
|
// Constants for WebSocket readyState
|
|
@@ -306,19 +306,24 @@ class NordWebSocketClient extends events_1.EventEmitter {
|
|
|
306
306
|
* @param message WebSocket message
|
|
307
307
|
*/
|
|
308
308
|
handleMessage(message) {
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
309
|
+
if (!message || typeof message !== "object") {
|
|
310
|
+
this.emit("error", new Error(`Unexpected message type: ${message}`));
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
const hasOwn = (k) => Object.prototype.hasOwnProperty.call(message, k);
|
|
314
|
+
if (hasOwn("trades")) {
|
|
315
|
+
this.emit("trades", message);
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
if (hasOwn("delta")) {
|
|
319
|
+
this.emit("delta", message);
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
if (hasOwn("account")) {
|
|
323
|
+
this.emit("account", message);
|
|
324
|
+
return;
|
|
321
325
|
}
|
|
326
|
+
this.emit("error", new Error(`Unexpected message type: ${message}`));
|
|
322
327
|
}
|
|
323
328
|
/**
|
|
324
329
|
* Attempt to reconnect to the WebSocket server
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { NordWebSocketClient } from "./NordWebSocketClient";
|
|
2
|
-
export { NordWebSocketEvents, NordWebSocketClientEvents } from "./events";
|
|
2
|
+
export type { NordWebSocketEvents, NordWebSocketClientEvents } from "./events";
|
package/package.json
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@n1xyz/nord-ts",
|
|
3
|
-
"version": "0.0.18
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"description": "Typescript for Nord",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"repository": {
|
|
8
|
-
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/n1xyz/nord.git"
|
|
10
|
-
},
|
|
11
5
|
"keywords": [],
|
|
12
6
|
"author": "",
|
|
13
7
|
"license": "ISC",
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"gen:proto": "nix run ..#nord-ts-proto ../engine/nord.proto src/gen/",
|
|
12
|
+
"gen:api": "nix run ..#nord-openapi | bunx openapi-typescript > src/gen/openapi.ts",
|
|
13
|
+
"gen": "bun run gen:proto && bun run gen:api",
|
|
14
|
+
"build": "bun run gen && bunx tsc && bun run docs",
|
|
15
|
+
"docs": "bunx typedoc --out ./docs ./src",
|
|
16
|
+
"compile": "tsc",
|
|
17
|
+
"clean": "rm -rf ./src/gen ./dist ./docs",
|
|
18
|
+
"fmt": "prettier --write src tests",
|
|
19
|
+
"ci": "bunx eslint && prettier --check src tests"
|
|
20
|
+
},
|
|
14
21
|
"devDependencies": {
|
|
15
|
-
"@
|
|
16
|
-
"@jest/types": "^29.6.3",
|
|
22
|
+
"@types/bun": "latest",
|
|
17
23
|
"@types/google-protobuf": "^3.15.10",
|
|
18
|
-
"@types/jest": "^29.5.12",
|
|
19
24
|
"@types/node": "^22.15.29",
|
|
20
25
|
"@types/node-fetch": "^2.6.9",
|
|
21
26
|
"@types/ws": "^8.5.10",
|
|
@@ -23,16 +28,15 @@
|
|
|
23
28
|
"@typescript-eslint/parser": "^8.26.1",
|
|
24
29
|
"eslint": "^9.22.0",
|
|
25
30
|
"globals": "^16.0.0",
|
|
26
|
-
"
|
|
31
|
+
"openapi-typescript": "^7.8.0",
|
|
27
32
|
"prettier": "^3.5.3",
|
|
28
|
-
"ts-jest": "^29.1.4",
|
|
29
33
|
"ts-node": "^10.9.2",
|
|
30
|
-
"ts-proto": "^2.7.0",
|
|
31
34
|
"typedoc": "^0.27.9",
|
|
32
35
|
"typescript": "*"
|
|
33
36
|
},
|
|
34
37
|
"dependencies": {
|
|
35
38
|
"@bufbuild/protobuf": "^2.0.0",
|
|
39
|
+
"@n1xyz/proton": "workspace:*",
|
|
36
40
|
"@noble/curves": "^1.3.0",
|
|
37
41
|
"@noble/ed25519": "^2.2.3",
|
|
38
42
|
"@noble/hashes": "^1.3.2",
|
|
@@ -42,19 +46,8 @@
|
|
|
42
46
|
"decimal.js": "^10.4.3",
|
|
43
47
|
"ethers": "^6.11.1",
|
|
44
48
|
"node-fetch": "2.6.13",
|
|
49
|
+
"openapi-fetch": "^0.14.0",
|
|
45
50
|
"tweetnacl": "^1.0.3",
|
|
46
|
-
"ws": "^8.16.0"
|
|
47
|
-
"@n1xyz/proton": "0.0.1-8121ed05.0"
|
|
48
|
-
},
|
|
49
|
-
"scripts": {
|
|
50
|
-
"dev": "nodemon --exec npx tsc",
|
|
51
|
-
"build:proto": "./protoc-generate.sh",
|
|
52
|
-
"build": "pnpm run build:proto && pnpm exec tsc && pnpm run docs",
|
|
53
|
-
"test": "pnpm exec jest",
|
|
54
|
-
"docs": "pnpm exec typedoc --out ./docs ./src",
|
|
55
|
-
"compile": "tsc",
|
|
56
|
-
"clean": "rm -rf ./src/gen ./dist ./docs",
|
|
57
|
-
"fmt": "prettier --write src tests",
|
|
58
|
-
"ci": "eslint && prettier --check src tests"
|
|
51
|
+
"ws": "^8.16.0"
|
|
59
52
|
}
|
|
60
|
-
}
|
|
53
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,21 +1,5 @@
|
|
|
1
|
-
// Export types
|
|
2
1
|
export * from "./types";
|
|
3
2
|
export * from "./utils";
|
|
4
3
|
export * from "./const";
|
|
5
|
-
|
|
6
|
-
// Export Nord modules
|
|
7
4
|
export * from "./nord";
|
|
8
|
-
|
|
9
|
-
// Export WebSocket modules
|
|
10
5
|
export * from "./websocket/index";
|
|
11
|
-
|
|
12
|
-
// Re-export proton bridge functionality for backward compatibility
|
|
13
|
-
export {
|
|
14
|
-
ProtonClient,
|
|
15
|
-
buildDepositTx,
|
|
16
|
-
createTokenAccountIfNeeded,
|
|
17
|
-
type DepositSplParams,
|
|
18
|
-
type WithdrawalParams,
|
|
19
|
-
type WithdrawalClaim,
|
|
20
|
-
type SPLTokenInfo,
|
|
21
|
-
} from "@n1xyz/proton";
|