@n1xyz/nord-ts 0.0.19 → 0.0.21
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/const.d.ts +8 -0
- package/dist/const.js +30 -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/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 +81 -0
- package/dist/nord/api/metrics.d.ts +67 -0
- package/dist/nord/api/metrics.js +229 -0
- package/dist/nord/client/Nord.d.ts +282 -0
- package/dist/nord/client/Nord.js +528 -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 +251 -0
- package/dist/types.js +101 -0
- package/dist/utils.d.ts +98 -0
- package/dist/utils.js +237 -0
- package/dist/websocket/NordWebSocketClient.d.ts +57 -0
- package/dist/websocket/NordWebSocketClient.js +251 -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 +8 -2
- package/src/gen/.gitkeep +0 -0
- package/src/gen/nord.ts +7593 -0
- package/src/gen/openapi.ts +2245 -0
- package/src/nord/api/core.ts +1 -16
- package/src/nord/client/Nord.ts +7 -11
- package/src/types.ts +0 -11
- package/src/websocket/NordWebSocketClient.ts +0 -113
- 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,37 @@
|
|
|
1
|
+
import { EventEmitter } from "events";
|
|
2
|
+
import { Account, DeltaEvent, OrderbookResponse, SubscriberConfig, StreamTrade, Trades } from "../../types";
|
|
3
|
+
/**
|
|
4
|
+
* Subscriber class for handling WebSocket subscriptions
|
|
5
|
+
*/
|
|
6
|
+
export declare class Subscriber {
|
|
7
|
+
streamURL: string;
|
|
8
|
+
buffer: (DeltaEvent | Trades | Account)[];
|
|
9
|
+
maxBufferLen: number;
|
|
10
|
+
/**
|
|
11
|
+
* Create a new Subscriber instance
|
|
12
|
+
* @param config Subscriber configuration
|
|
13
|
+
*/
|
|
14
|
+
constructor(config: SubscriberConfig);
|
|
15
|
+
/**
|
|
16
|
+
* Subscribe to WebSocket events
|
|
17
|
+
*/
|
|
18
|
+
subscribe(): void;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Interface for orderbook subscription
|
|
22
|
+
*/
|
|
23
|
+
export interface OrderbookSubscription extends EventEmitter {
|
|
24
|
+
on(event: "message", listener: (data: OrderbookResponse) => void): this;
|
|
25
|
+
on(event: "error", listener: (error: Error) => void): this;
|
|
26
|
+
close(): void;
|
|
27
|
+
removeAllListeners(event?: string): this;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Interface for trade subscription
|
|
31
|
+
*/
|
|
32
|
+
export interface TradeSubscription extends EventEmitter {
|
|
33
|
+
on(event: "message", listener: (data: StreamTrade[]) => void): this;
|
|
34
|
+
on(event: "error", listener: (error: Error) => void): this;
|
|
35
|
+
close(): void;
|
|
36
|
+
removeAllListeners(event?: string): this;
|
|
37
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Subscriber = void 0;
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
5
|
+
/**
|
|
6
|
+
* Subscriber class for handling WebSocket subscriptions
|
|
7
|
+
*/
|
|
8
|
+
class Subscriber {
|
|
9
|
+
/**
|
|
10
|
+
* Create a new Subscriber instance
|
|
11
|
+
* @param config Subscriber configuration
|
|
12
|
+
*/
|
|
13
|
+
constructor(config) {
|
|
14
|
+
this.streamURL = config.streamURL;
|
|
15
|
+
this.buffer = [];
|
|
16
|
+
this.maxBufferLen = config.maxBufferLen ?? utils_1.MAX_BUFFER_LEN;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Subscribe to WebSocket events
|
|
20
|
+
*/
|
|
21
|
+
subscribe() {
|
|
22
|
+
// TODO: Implement subscription logic
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.Subscriber = Subscriber;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for creating a NordError
|
|
3
|
+
*/
|
|
4
|
+
export interface NordErrorOptions {
|
|
5
|
+
/** The original error that caused this error */
|
|
6
|
+
cause?: unknown;
|
|
7
|
+
/** HTTP status code (if applicable) */
|
|
8
|
+
statusCode?: number;
|
|
9
|
+
/** Additional error details */
|
|
10
|
+
details?: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Custom error class for Nord-related errors
|
|
14
|
+
*/
|
|
15
|
+
export declare class NordError extends Error {
|
|
16
|
+
/** The original error that caused this error */
|
|
17
|
+
readonly cause?: unknown;
|
|
18
|
+
/** HTTP status code (if applicable) */
|
|
19
|
+
readonly statusCode?: number;
|
|
20
|
+
/** Additional error details */
|
|
21
|
+
readonly details?: Record<string, unknown>;
|
|
22
|
+
/**
|
|
23
|
+
* Create a new NordError
|
|
24
|
+
*
|
|
25
|
+
* @param message - Error message
|
|
26
|
+
* @param options - Error options
|
|
27
|
+
*/
|
|
28
|
+
constructor(message: string, options?: NordErrorOptions);
|
|
29
|
+
/**
|
|
30
|
+
* Convert the error to a string representation
|
|
31
|
+
*
|
|
32
|
+
* @returns String representation of the error
|
|
33
|
+
*/
|
|
34
|
+
toString(): string;
|
|
35
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NordError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Custom error class for Nord-related errors
|
|
6
|
+
*/
|
|
7
|
+
class NordError extends Error {
|
|
8
|
+
/**
|
|
9
|
+
* Create a new NordError
|
|
10
|
+
*
|
|
11
|
+
* @param message - Error message
|
|
12
|
+
* @param options - Error options
|
|
13
|
+
*/
|
|
14
|
+
constructor(message, options = {}) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = "NordError";
|
|
17
|
+
this.cause = options.cause;
|
|
18
|
+
this.statusCode = options.statusCode;
|
|
19
|
+
this.details = options.details;
|
|
20
|
+
// Capture stack trace
|
|
21
|
+
if (Error.captureStackTrace) {
|
|
22
|
+
Error.captureStackTrace(this, NordError);
|
|
23
|
+
}
|
|
24
|
+
// Handle nested errors
|
|
25
|
+
if (this.cause instanceof Error) {
|
|
26
|
+
this.stack =
|
|
27
|
+
this.stack + "\nCaused by: " + (this.cause.stack || this.cause.message);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Convert the error to a string representation
|
|
32
|
+
*
|
|
33
|
+
* @returns String representation of the error
|
|
34
|
+
*/
|
|
35
|
+
toString() {
|
|
36
|
+
let result = `${this.name}: ${this.message}`;
|
|
37
|
+
if (this.statusCode) {
|
|
38
|
+
result += ` \nstatus: ${this.statusCode}`;
|
|
39
|
+
}
|
|
40
|
+
if (this.details && Object.keys(this.details).length > 0) {
|
|
41
|
+
result += ` \ndetails: ${JSON.stringify(this.details, null, 2)}`;
|
|
42
|
+
}
|
|
43
|
+
if (this.cause) {
|
|
44
|
+
result += ` \ncause: ${this.cause.toString()}`;
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.NordError = NordError;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import * as proto from "./gen/nord";
|
|
2
|
+
import type { components } from "./gen/openapi.ts";
|
|
3
|
+
/**
|
|
4
|
+
* The peak TPS rate is queried over the specified period.
|
|
5
|
+
* The period is specified in units of: {hour, day, week, month, year}.
|
|
6
|
+
* Example inputs:
|
|
7
|
+
* 1. AggregateMetrics.txPeakTpsPeriod = 3,
|
|
8
|
+
* AggregateMetrics.txPeakTpsPeriodUnit = "d" => Peak TPS over last 3 days.
|
|
9
|
+
* 1. AggregateMetrics.txPeakTpsPeriod = 1,
|
|
10
|
+
* AggregateMetrics.txPeakTpsPeriodUnit = "w" => Peak TPS over last week.
|
|
11
|
+
*/
|
|
12
|
+
export declare enum PeakTpsPeriodUnit {
|
|
13
|
+
Hour = "h",
|
|
14
|
+
Day = "d",
|
|
15
|
+
Week = "w",
|
|
16
|
+
Month = "m",
|
|
17
|
+
Year = "y"
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Nord subscription type for trades or deltas
|
|
21
|
+
*/
|
|
22
|
+
export type SubscriptionType = "trades" | "deltas" | "account";
|
|
23
|
+
/**
|
|
24
|
+
* Pattern for a valid Nord subscription
|
|
25
|
+
* Format should be: "<type>@<parameter>"
|
|
26
|
+
* Examples: "trades@BTCUSDC", "deltas@ETHUSDC", "account@42"
|
|
27
|
+
*/
|
|
28
|
+
export type SubscriptionPattern = `${SubscriptionType}@${string}` | string;
|
|
29
|
+
/**
|
|
30
|
+
* Configuration options for the Nord client
|
|
31
|
+
*/
|
|
32
|
+
export interface NordConfig {
|
|
33
|
+
/** Base URL for the Nord web server */
|
|
34
|
+
webServerUrl: string;
|
|
35
|
+
/** Bridge verification key */
|
|
36
|
+
bridgeVk: string;
|
|
37
|
+
/** Solana cluster URL */
|
|
38
|
+
solanaUrl: string;
|
|
39
|
+
/**
|
|
40
|
+
* Whether to initialize WebSockets on creation, defaults to true
|
|
41
|
+
* @deprecated this is a funky api we're gonna be removing it
|
|
42
|
+
*/
|
|
43
|
+
initWebSockets?: boolean;
|
|
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"];
|
|
74
|
+
/**
|
|
75
|
+
* Configuration options for the Nord client
|
|
76
|
+
*/
|
|
77
|
+
export interface TokenInfo {
|
|
78
|
+
address: string;
|
|
79
|
+
precision: number;
|
|
80
|
+
tokenId: number;
|
|
81
|
+
name: string;
|
|
82
|
+
}
|
|
83
|
+
export interface Order {
|
|
84
|
+
orderId: number;
|
|
85
|
+
isLong: boolean;
|
|
86
|
+
size: number;
|
|
87
|
+
price: number;
|
|
88
|
+
marketId: number;
|
|
89
|
+
}
|
|
90
|
+
export declare enum KeyType {
|
|
91
|
+
Ed25519 = 0,
|
|
92
|
+
Secp256k1 = 1,
|
|
93
|
+
Bls12_381 = 2
|
|
94
|
+
}
|
|
95
|
+
export declare enum Side {
|
|
96
|
+
Ask = 0,
|
|
97
|
+
Bid = 1
|
|
98
|
+
}
|
|
99
|
+
export declare enum FillMode {
|
|
100
|
+
Limit = 0,
|
|
101
|
+
PostOnly = 1,
|
|
102
|
+
ImmediateOrCancel = 2,
|
|
103
|
+
FillOrKill = 3
|
|
104
|
+
}
|
|
105
|
+
export interface SubscriberConfig {
|
|
106
|
+
streamURL: string;
|
|
107
|
+
maxBufferLen?: number;
|
|
108
|
+
}
|
|
109
|
+
export interface DeltaEvent {
|
|
110
|
+
last_update_id: number;
|
|
111
|
+
update_id: number;
|
|
112
|
+
market_symbol: string;
|
|
113
|
+
asks: OrderbookEntry[];
|
|
114
|
+
bids: OrderbookEntry[];
|
|
115
|
+
}
|
|
116
|
+
export interface StreamTrade {
|
|
117
|
+
side: Side;
|
|
118
|
+
price: number;
|
|
119
|
+
size: number;
|
|
120
|
+
order_id: number;
|
|
121
|
+
}
|
|
122
|
+
export interface Trades {
|
|
123
|
+
last_update_id: number;
|
|
124
|
+
update_id: number;
|
|
125
|
+
market_symbol: string;
|
|
126
|
+
trades: StreamTrade[];
|
|
127
|
+
}
|
|
128
|
+
export interface LocalOrderInfo {
|
|
129
|
+
id: number;
|
|
130
|
+
reduce_only: boolean;
|
|
131
|
+
limit_price: number;
|
|
132
|
+
size: number;
|
|
133
|
+
account_id: number;
|
|
134
|
+
sender_tracking_id?: number;
|
|
135
|
+
}
|
|
136
|
+
export interface HashMap<T> {
|
|
137
|
+
[key: number]: T;
|
|
138
|
+
}
|
|
139
|
+
export interface ActionResponse {
|
|
140
|
+
actionId: number;
|
|
141
|
+
action: proto.Action;
|
|
142
|
+
physicalExecTime: Date;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Block summary.
|
|
146
|
+
* block_number Block number.
|
|
147
|
+
* from_action_id First action_id in the block.
|
|
148
|
+
* to_action_id Last action_id in the block.
|
|
149
|
+
*/
|
|
150
|
+
export interface BlockSummary {
|
|
151
|
+
block_number: number;
|
|
152
|
+
from_action_id: number;
|
|
153
|
+
to_action_id: number;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Aggregate metrics
|
|
157
|
+
* blocks_total: Total number of L2 blocks.
|
|
158
|
+
* tx_total: Total number of transactions.
|
|
159
|
+
* tx_tps: Transaction throughput.
|
|
160
|
+
* tx_tps_peak: Peak transaction throughput.
|
|
161
|
+
* request_latency_average: Average request latency.
|
|
162
|
+
*/
|
|
163
|
+
export interface AggregateMetrics {
|
|
164
|
+
blocks_total: number;
|
|
165
|
+
tx_total: number;
|
|
166
|
+
tx_tps: number;
|
|
167
|
+
tx_tps_peak: number;
|
|
168
|
+
request_latency_average: number;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Converts a `FillMode` enum to its corresponding protobuf representation.
|
|
172
|
+
*
|
|
173
|
+
* @param x - The fill mode to convert.
|
|
174
|
+
* @returns The corresponding protobuf fill mode.
|
|
175
|
+
* @throws Will throw an error if provided with an invalid fill mode.
|
|
176
|
+
*/
|
|
177
|
+
export declare function fillModeToProtoFillMode(x: FillMode): proto.FillMode;
|
|
178
|
+
/**
|
|
179
|
+
* Orderbook entry representing price and size
|
|
180
|
+
*/
|
|
181
|
+
export interface OrderbookEntry {
|
|
182
|
+
price: number;
|
|
183
|
+
size: number;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Query parameters for orderbook
|
|
187
|
+
*
|
|
188
|
+
* Note: While you can provide either symbol or market_id, the API endpoint only accepts market_id.
|
|
189
|
+
* If you provide a symbol, it will be converted to a market_id internally.
|
|
190
|
+
*/
|
|
191
|
+
export interface OrderbookQuery {
|
|
192
|
+
symbol?: string;
|
|
193
|
+
market_id?: number;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Response for timestamp query
|
|
197
|
+
*/
|
|
198
|
+
export interface TimestampResponse {
|
|
199
|
+
timestamp: number;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Response for action nonce query
|
|
203
|
+
*/
|
|
204
|
+
export interface ActionNonceResponse {
|
|
205
|
+
nonce: number;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* WebSocket message types
|
|
209
|
+
*/
|
|
210
|
+
export declare enum WebSocketMessageType {
|
|
211
|
+
TradeUpdate = "trades",
|
|
212
|
+
DeltaUpdate = "delta",
|
|
213
|
+
AccountUpdate = "account"
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* WebSocket trade update message
|
|
217
|
+
*/
|
|
218
|
+
export interface WebSocketTradeUpdate {
|
|
219
|
+
e: WebSocketMessageType.TradeUpdate;
|
|
220
|
+
symbol: string;
|
|
221
|
+
trades: StreamTrade[];
|
|
222
|
+
timestamp: number;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* WebSocket delta update message
|
|
226
|
+
*/
|
|
227
|
+
export interface WebSocketDeltaUpdate {
|
|
228
|
+
e: WebSocketMessageType.DeltaUpdate;
|
|
229
|
+
last_update_id: number;
|
|
230
|
+
update_id: number;
|
|
231
|
+
market_symbol: string;
|
|
232
|
+
asks: OrderbookEntry[];
|
|
233
|
+
bids: OrderbookEntry[];
|
|
234
|
+
timestamp: number;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* WebSocket user update message
|
|
238
|
+
*/
|
|
239
|
+
export interface WebSocketAccountUpdate {
|
|
240
|
+
e: WebSocketMessageType.AccountUpdate;
|
|
241
|
+
accountId: number;
|
|
242
|
+
account: Account;
|
|
243
|
+
timestamp: number;
|
|
244
|
+
}
|
|
245
|
+
export type WebSocketMessage = WebSocketTradeUpdate | WebSocketDeltaUpdate | WebSocketAccountUpdate;
|
|
246
|
+
export interface SPLTokenInfo {
|
|
247
|
+
mint: string;
|
|
248
|
+
precision: number;
|
|
249
|
+
tokenId: number;
|
|
250
|
+
name: string;
|
|
251
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.WebSocketMessageType = exports.FillMode = exports.Side = exports.KeyType = exports.PeakTpsPeriodUnit = void 0;
|
|
37
|
+
exports.fillModeToProtoFillMode = fillModeToProtoFillMode;
|
|
38
|
+
const proto = __importStar(require("./gen/nord"));
|
|
39
|
+
/**
|
|
40
|
+
* The peak TPS rate is queried over the specified period.
|
|
41
|
+
* The period is specified in units of: {hour, day, week, month, year}.
|
|
42
|
+
* Example inputs:
|
|
43
|
+
* 1. AggregateMetrics.txPeakTpsPeriod = 3,
|
|
44
|
+
* AggregateMetrics.txPeakTpsPeriodUnit = "d" => Peak TPS over last 3 days.
|
|
45
|
+
* 1. AggregateMetrics.txPeakTpsPeriod = 1,
|
|
46
|
+
* AggregateMetrics.txPeakTpsPeriodUnit = "w" => Peak TPS over last week.
|
|
47
|
+
*/
|
|
48
|
+
var PeakTpsPeriodUnit;
|
|
49
|
+
(function (PeakTpsPeriodUnit) {
|
|
50
|
+
PeakTpsPeriodUnit["Hour"] = "h";
|
|
51
|
+
PeakTpsPeriodUnit["Day"] = "d";
|
|
52
|
+
PeakTpsPeriodUnit["Week"] = "w";
|
|
53
|
+
PeakTpsPeriodUnit["Month"] = "m";
|
|
54
|
+
PeakTpsPeriodUnit["Year"] = "y";
|
|
55
|
+
})(PeakTpsPeriodUnit || (exports.PeakTpsPeriodUnit = PeakTpsPeriodUnit = {}));
|
|
56
|
+
var KeyType;
|
|
57
|
+
(function (KeyType) {
|
|
58
|
+
KeyType[KeyType["Ed25519"] = 0] = "Ed25519";
|
|
59
|
+
KeyType[KeyType["Secp256k1"] = 1] = "Secp256k1";
|
|
60
|
+
KeyType[KeyType["Bls12_381"] = 2] = "Bls12_381";
|
|
61
|
+
})(KeyType || (exports.KeyType = KeyType = {}));
|
|
62
|
+
var Side;
|
|
63
|
+
(function (Side) {
|
|
64
|
+
Side[Side["Ask"] = 0] = "Ask";
|
|
65
|
+
Side[Side["Bid"] = 1] = "Bid";
|
|
66
|
+
})(Side || (exports.Side = Side = {}));
|
|
67
|
+
var FillMode;
|
|
68
|
+
(function (FillMode) {
|
|
69
|
+
FillMode[FillMode["Limit"] = 0] = "Limit";
|
|
70
|
+
FillMode[FillMode["PostOnly"] = 1] = "PostOnly";
|
|
71
|
+
FillMode[FillMode["ImmediateOrCancel"] = 2] = "ImmediateOrCancel";
|
|
72
|
+
FillMode[FillMode["FillOrKill"] = 3] = "FillOrKill";
|
|
73
|
+
})(FillMode || (exports.FillMode = FillMode = {}));
|
|
74
|
+
/**
|
|
75
|
+
* Converts a `FillMode` enum to its corresponding protobuf representation.
|
|
76
|
+
*
|
|
77
|
+
* @param x - The fill mode to convert.
|
|
78
|
+
* @returns The corresponding protobuf fill mode.
|
|
79
|
+
* @throws Will throw an error if provided with an invalid fill mode.
|
|
80
|
+
*/
|
|
81
|
+
function fillModeToProtoFillMode(x) {
|
|
82
|
+
if (x === FillMode.Limit)
|
|
83
|
+
return proto.FillMode.LIMIT;
|
|
84
|
+
if (x === FillMode.PostOnly)
|
|
85
|
+
return proto.FillMode.POST_ONLY;
|
|
86
|
+
if (x === FillMode.ImmediateOrCancel) {
|
|
87
|
+
return proto.FillMode.IMMEDIATE_OR_CANCEL;
|
|
88
|
+
}
|
|
89
|
+
if (x === FillMode.FillOrKill)
|
|
90
|
+
return proto.FillMode.FILL_OR_KILL;
|
|
91
|
+
throw new Error("Invalid fill mode");
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* WebSocket message types
|
|
95
|
+
*/
|
|
96
|
+
var WebSocketMessageType;
|
|
97
|
+
(function (WebSocketMessageType) {
|
|
98
|
+
WebSocketMessageType["TradeUpdate"] = "trades";
|
|
99
|
+
WebSocketMessageType["DeltaUpdate"] = "delta";
|
|
100
|
+
WebSocketMessageType["AccountUpdate"] = "account";
|
|
101
|
+
})(WebSocketMessageType || (exports.WebSocketMessageType = WebSocketMessageType = {}));
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Decimal } from "decimal.js";
|
|
2
|
+
import { KeyType, type Market, type Token } from "./types";
|
|
3
|
+
import * as proto from "./gen/nord";
|
|
4
|
+
import { ethers } from "ethers";
|
|
5
|
+
import { RequestInfo, RequestInit, Response } from "node-fetch";
|
|
6
|
+
import { Keypair } from "@solana/web3.js";
|
|
7
|
+
export declare const SESSION_TTL: bigint;
|
|
8
|
+
export declare const ZERO_DECIMAL: Decimal;
|
|
9
|
+
export declare const MAX_BUFFER_LEN = 10000;
|
|
10
|
+
/** Any type convertible to bigint */
|
|
11
|
+
export type BigIntValue = bigint | number | string;
|
|
12
|
+
export declare function panic(message: string): never;
|
|
13
|
+
export declare function isRfc3339(s: string): boolean;
|
|
14
|
+
export declare function assert(predicate: boolean, message?: string): void;
|
|
15
|
+
/**
|
|
16
|
+
* Extracts value out of optional if it's defined, or throws error if it's not
|
|
17
|
+
* @param value Optional value to unwrap
|
|
18
|
+
* @param message Error message
|
|
19
|
+
* @returns Unwrapped value
|
|
20
|
+
*/
|
|
21
|
+
export declare function optExpect<T>(value: T | undefined, message: string): T;
|
|
22
|
+
/** Behaves same as `node-fetch/fetch` but throws if response is a failure
|
|
23
|
+
*
|
|
24
|
+
* @param url Request HTTP URL
|
|
25
|
+
* @param init Request parameters
|
|
26
|
+
* @returns Raw response if fetch succeeded
|
|
27
|
+
* @throws If response wasn't Ok
|
|
28
|
+
*/
|
|
29
|
+
export declare function checkedFetch(url: RequestInfo, init?: RequestInit): Promise<Response>;
|
|
30
|
+
/**
|
|
31
|
+
* Signs an action using the specified secret key and key type.
|
|
32
|
+
* @param action - The action data to be signed.
|
|
33
|
+
* @param sk - Secret key used for signing the action.
|
|
34
|
+
* @param keyType - Type of the key used for signing.
|
|
35
|
+
* @returns A new Uint8Array containing the action followed by its signature.
|
|
36
|
+
*/
|
|
37
|
+
export declare function signAction(action: Uint8Array, sk: Uint8Array, keyType: KeyType): Uint8Array;
|
|
38
|
+
/**
|
|
39
|
+
* Constructs wallet signing function, usable with `NordUser` type
|
|
40
|
+
*
|
|
41
|
+
* @param walletKey Either raw signing key as bytes array or hex string prefixed with `"0x"`
|
|
42
|
+
* @returns Async function which accepts arbitrary message, generates its digets,
|
|
43
|
+
* then signs it with provided user wallet key and returns signature
|
|
44
|
+
* as hex string prefixed with `"0x"`
|
|
45
|
+
*/
|
|
46
|
+
export declare function makeWalletSignFn(walletKey: ethers.BytesLike): (message: Uint8Array | string) => Promise<string>;
|
|
47
|
+
/**
|
|
48
|
+
* Converts decimal value into rescaled 64-bit unsigned integer
|
|
49
|
+
* by scaling it up by specified number of decimal digits.
|
|
50
|
+
*
|
|
51
|
+
* Ensures that number won't accidentally become zero
|
|
52
|
+
* or exceed U64's value range
|
|
53
|
+
*
|
|
54
|
+
* @param x Decimal value to rescale
|
|
55
|
+
* @param decimals Number of decimal digits
|
|
56
|
+
* @returns Rescaled unsigned integer
|
|
57
|
+
*/
|
|
58
|
+
export declare const toScaledU64: (x: Decimal.Value, decimals: number) => bigint;
|
|
59
|
+
/**
|
|
60
|
+
* Converts decimal value into rescaled 128-bit unsigned integer
|
|
61
|
+
* by scaling it up by specified number of decimal digits.
|
|
62
|
+
*
|
|
63
|
+
* Ensures that number won't accidentally become zero
|
|
64
|
+
* or exceed U128's value range
|
|
65
|
+
*
|
|
66
|
+
* @param x Decimal value to rescale
|
|
67
|
+
* @param decimals Number of decimal digits
|
|
68
|
+
* @returns Rescaled unsigned integer
|
|
69
|
+
*/
|
|
70
|
+
export declare const toScaledU128: (x: Decimal.Value, decimals: number) => bigint;
|
|
71
|
+
/**
|
|
72
|
+
* Encodes any protobuf message into a length-delimited format,
|
|
73
|
+
* i.e. prefixed with its length encoded as varint
|
|
74
|
+
* @param message message object
|
|
75
|
+
* @param coder associated coder object which implements `MessageFns` interface
|
|
76
|
+
* @returns Encoded message as Uint8Array, prefixed with its length
|
|
77
|
+
*/
|
|
78
|
+
export declare function encodeLengthDelimited<T, M extends proto.MessageFns<T>>(message: T, coder: M): Uint8Array;
|
|
79
|
+
/**
|
|
80
|
+
* Decodes any protobuf message from a length-delimited format,
|
|
81
|
+
* i.e. prefixed with its length encoded as varint
|
|
82
|
+
*
|
|
83
|
+
* NB: Please note that due to limitations of Typescript type inference
|
|
84
|
+
* it requires to specify variable type explicitly:
|
|
85
|
+
*
|
|
86
|
+
* ```
|
|
87
|
+
* const foo: proto.Bar = decodeLengthDelimited(bytes, proto.Bar);
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* @param bytes Byte array with encoded message
|
|
91
|
+
* @param coder associated coder object which implements `MessageFns` interface
|
|
92
|
+
* @returns Decoded Action as Uint8Array.
|
|
93
|
+
*/
|
|
94
|
+
export declare function decodeLengthDelimited<T, M extends proto.MessageFns<T>>(bytes: Uint8Array, coder: M): T;
|
|
95
|
+
export declare function checkPubKeyLength(keyType: KeyType, len: number): void;
|
|
96
|
+
export declare function findMarket(markets: Market[], marketId: number): Market;
|
|
97
|
+
export declare function findToken(tokens: Token[], tokenId: number): Token;
|
|
98
|
+
export declare function keypairFromPrivateKey(privateKey: string | Uint8Array): Keypair;
|