@n1xyz/nord-ts 0.0.1 → 0.0.5

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 (260) hide show
  1. package/README.md +148 -65
  2. package/dist/bridge/client.d.ts +150 -0
  3. package/dist/bridge/client.js +394 -0
  4. package/dist/bridge/const.d.ts +23 -0
  5. package/dist/bridge/const.js +47 -0
  6. package/dist/bridge/index.d.ts +5 -0
  7. package/dist/bridge/index.js +23 -0
  8. package/dist/bridge/types.d.ts +118 -0
  9. package/dist/bridge/types.js +16 -0
  10. package/dist/bridge/utils.d.ts +64 -0
  11. package/dist/bridge/utils.js +131 -0
  12. package/dist/const.d.ts +2 -5
  13. package/dist/const.js +2 -6
  14. package/dist/gen/common.d.ts +6 -1
  15. package/dist/gen/common.js +19 -9
  16. package/dist/gen/nord.d.ts +76 -21
  17. package/dist/gen/nord.js +987 -423
  18. package/dist/idl/bridge.d.ts +2 -0
  19. package/dist/idl/bridge.js +703 -0
  20. package/dist/index.d.ts +5 -2
  21. package/dist/index.js +18 -2
  22. package/dist/nord/{actions.d.ts → api/actions.d.ts} +6 -6
  23. package/dist/nord/{actions.js → api/actions.js} +6 -10
  24. package/dist/nord/api/core.d.ts +49 -0
  25. package/dist/nord/api/core.js +121 -0
  26. package/dist/nord/api/market.d.ts +36 -0
  27. package/dist/nord/api/market.js +98 -0
  28. package/dist/nord/api/metrics.d.ts +67 -0
  29. package/dist/nord/api/metrics.js +132 -0
  30. package/dist/nord/api/queries.d.ts +81 -0
  31. package/dist/nord/api/queries.js +187 -0
  32. package/dist/nord/client/Nord.d.ts +335 -0
  33. package/dist/nord/client/Nord.js +532 -0
  34. package/dist/nord/client/NordUser.d.ts +320 -0
  35. package/dist/nord/client/NordUser.js +697 -0
  36. package/dist/nord/index.d.ts +9 -2
  37. package/dist/nord/index.js +30 -6
  38. package/dist/nord/models/Subscriber.d.ts +37 -0
  39. package/dist/nord/models/Subscriber.js +25 -0
  40. package/dist/nord/utils/NordError.d.ts +35 -0
  41. package/dist/nord/utils/NordError.js +46 -0
  42. package/dist/types.d.ts +143 -86
  43. package/dist/types.js +12 -1
  44. package/dist/utils.d.ts +9 -0
  45. package/dist/utils.js +20 -1
  46. package/dist/websocket/NordWebSocketClient.d.ts +71 -0
  47. package/dist/websocket/NordWebSocketClient.js +343 -0
  48. package/dist/websocket/events.d.ts +19 -0
  49. package/dist/websocket/events.js +2 -0
  50. package/dist/websocket/index.d.ts +2 -0
  51. package/dist/websocket/index.js +5 -0
  52. package/docs/assets/hierarchy.js +1 -0
  53. package/docs/assets/highlight.css +16 -16
  54. package/docs/assets/icons.js +17 -14
  55. package/docs/assets/icons.svg +1 -1
  56. package/docs/assets/main.js +5 -4
  57. package/docs/assets/navigation.js +1 -1
  58. package/docs/assets/search.js +1 -1
  59. package/docs/assets/style.css +1423 -1227
  60. package/docs/classes/Nord.html +189 -43
  61. package/docs/classes/NordError.html +24 -0
  62. package/docs/classes/NordUser.html +120 -35
  63. package/docs/classes/NordWebSocketClient.html +335 -0
  64. package/docs/classes/SolanaBridgeClient.html +86 -0
  65. package/docs/classes/Subscriber.html +10 -6
  66. package/docs/enums/FillMode.html +5 -5
  67. package/docs/enums/KeyType.html +4 -4
  68. package/docs/enums/MetricPeriod.html +9 -0
  69. package/docs/enums/PdaSeedType.html +9 -0
  70. package/docs/enums/PeakTpsPeriodUnit.html +7 -7
  71. package/docs/enums/Side.html +3 -3
  72. package/docs/enums/WebSocketMessageType.html +7 -0
  73. package/docs/functions/actionQueryRollman.html +6 -0
  74. package/docs/functions/actionsQueryRollman.html +6 -0
  75. package/docs/functions/aggregateMetrics-1.html +7 -0
  76. package/docs/functions/assert.html +1 -1
  77. package/docs/functions/bigIntToProtoU128.html +3 -3
  78. package/docs/functions/blockQueryRollman.html +6 -0
  79. package/docs/functions/blockSummaryQueryRollman.html +6 -0
  80. package/docs/functions/bridgeToBN.html +5 -0
  81. package/docs/functions/bufferToHex.html +4 -0
  82. package/docs/functions/cancelOrder.html +1 -0
  83. package/docs/functions/checkPubKeyLength.html +1 -1
  84. package/docs/functions/checkedFetch.html +4 -4
  85. package/docs/functions/createSession.html +1 -0
  86. package/docs/functions/decodeLengthDelimited.html +7 -6
  87. package/docs/functions/encodeLengthDelimited.html +4 -4
  88. package/docs/functions/fillModeToProtoFillMode.html +4 -4
  89. package/docs/functions/findMarket.html +1 -1
  90. package/docs/functions/findPda.html +6 -0
  91. package/docs/functions/findToken.html +1 -1
  92. package/docs/functions/fromBN.html +5 -0
  93. package/docs/functions/getAccount.html +6 -0
  94. package/docs/functions/getActionNonce.html +5 -0
  95. package/docs/functions/getCurrentTps.html +6 -0
  96. package/docs/functions/getInfo.html +5 -0
  97. package/docs/functions/getMedianLatency.html +6 -0
  98. package/docs/functions/getOrderbook.html +6 -0
  99. package/docs/functions/getPeakTps.html +6 -0
  100. package/docs/functions/getTimestamp.html +5 -0
  101. package/docs/functions/getTotalTransactions.html +5 -0
  102. package/docs/functions/getTrades.html +6 -0
  103. package/docs/functions/getUserAccountIds.html +6 -0
  104. package/docs/functions/hexToBuffer.html +4 -0
  105. package/docs/functions/initWebSocketClient.html +12 -0
  106. package/docs/functions/keypairFromPrivateKey.html +4 -0
  107. package/docs/functions/makeSigningFunction.html +4 -0
  108. package/docs/functions/makeWalletSignFn.html +5 -5
  109. package/docs/functions/marketsStats.html +5 -0
  110. package/docs/functions/optExpect.html +4 -4
  111. package/docs/functions/optMap.html +5 -5
  112. package/docs/functions/optUnwrap.html +2 -2
  113. package/docs/functions/panic.html +1 -1
  114. package/docs/functions/placeOrder.html +1 -0
  115. package/docs/functions/queryAction.html +6 -0
  116. package/docs/functions/queryBlock.html +6 -0
  117. package/docs/functions/queryLastNBlocks.html +5 -0
  118. package/docs/functions/queryPrometheus.html +6 -0
  119. package/docs/functions/queryRecentActions.html +6 -0
  120. package/docs/functions/queryRecentBlocks.html +6 -0
  121. package/docs/functions/revokeSession.html +1 -0
  122. package/docs/functions/shortenPublicKey.html +5 -0
  123. package/docs/functions/signAction.html +2 -2
  124. package/docs/functions/toBN.html +5 -0
  125. package/docs/functions/toScaledU128.html +5 -5
  126. package/docs/functions/toScaledU64.html +5 -5
  127. package/docs/functions/transfer.html +1 -0
  128. package/docs/functions/withdraw.html +1 -0
  129. package/docs/hierarchy.html +1 -0
  130. package/docs/index.html +39 -20
  131. package/docs/interfaces/Account.html +8 -8
  132. package/docs/interfaces/ActionInfo.html +8 -8
  133. package/docs/interfaces/ActionNonceResponse.html +3 -0
  134. package/docs/interfaces/ActionQuery.html +4 -4
  135. package/docs/interfaces/ActionResponse.html +8 -8
  136. package/docs/interfaces/ActionsExtendedInfo.html +10 -10
  137. package/docs/interfaces/ActionsQuery.html +5 -5
  138. package/docs/interfaces/ActionsResponse.html +6 -6
  139. package/docs/interfaces/AggregateMetrics.html +12 -12
  140. package/docs/interfaces/BlockFacts.html +10 -0
  141. package/docs/interfaces/BlockQuery.html +6 -6
  142. package/docs/interfaces/BlockResponse.html +6 -6
  143. package/docs/interfaces/BlockSummary.html +8 -8
  144. package/docs/interfaces/BlockSummaryResponse.html +6 -6
  145. package/docs/interfaces/DeltaEvent.html +6 -6
  146. package/docs/interfaces/DepositSplParams.html +10 -0
  147. package/docs/interfaces/Info.html +3 -3
  148. package/docs/interfaces/Market.html +8 -6
  149. package/docs/interfaces/MarketStats.html +7 -7
  150. package/docs/interfaces/MarketsStatsResponse.html +2 -2
  151. package/docs/interfaces/NordConfig.html +14 -5
  152. package/docs/interfaces/NordWebSocketClientEvents.html +4 -0
  153. package/docs/interfaces/NordWebSocketEvents.html +8 -0
  154. package/docs/interfaces/Order.html +6 -6
  155. package/docs/interfaces/OrderInfo.html +6 -6
  156. package/docs/interfaces/OrderbookEntry.html +4 -0
  157. package/docs/interfaces/OrderbookQuery.html +6 -0
  158. package/docs/interfaces/OrderbookResponse.html +6 -10
  159. package/docs/interfaces/OrderbookSubscription.html +159 -0
  160. package/docs/interfaces/PerpMarketStats.html +5 -5
  161. package/docs/interfaces/RollmanActionExtendedInfo.html +4 -4
  162. package/docs/interfaces/RollmanActionInfo.html +4 -4
  163. package/docs/interfaces/RollmanActionResponse.html +4 -4
  164. package/docs/interfaces/RollmanActionsResponse.html +2 -2
  165. package/docs/interfaces/RollmanBlockResponse.html +3 -3
  166. package/docs/interfaces/SPLTokenInfo.html +10 -0
  167. package/docs/interfaces/SolanaBridgeConfig.html +10 -0
  168. package/docs/interfaces/StateFacts.html +10 -0
  169. package/docs/interfaces/SubscriberConfig.html +3 -3
  170. package/docs/interfaces/TimestampResponse.html +3 -0
  171. package/docs/interfaces/Token.html +5 -5
  172. package/docs/interfaces/TokenInfo.html +5 -0
  173. package/docs/interfaces/Trade.html +5 -5
  174. package/docs/interfaces/TradeSubscription.html +159 -0
  175. package/docs/interfaces/Trades.html +5 -5
  176. package/docs/interfaces/TradesQuery.html +6 -0
  177. package/docs/interfaces/TradesResponse.html +7 -12
  178. package/docs/interfaces/TransferParams.html +8 -0
  179. package/docs/interfaces/UserAccountIdsQuery.html +3 -0
  180. package/docs/interfaces/UserAccountIdsResponse.html +3 -0
  181. package/docs/interfaces/WebSocketDeltaUpdate.html +9 -0
  182. package/docs/interfaces/WebSocketSubscription.html +4 -0
  183. package/docs/interfaces/WebSocketTradeUpdate.html +6 -0
  184. package/docs/interfaces/WebSocketUserUpdate.html +6 -0
  185. package/docs/interfaces/WithdrawalClaim.html +14 -0
  186. package/docs/interfaces/WithdrawalParams.html +8 -0
  187. package/docs/modules.html +1 -77
  188. package/docs/types/BigIntValue.html +2 -2
  189. package/docs/types/WebSocketMessage.html +1 -0
  190. package/docs/variables/DEBUG_KEYS.html +1 -1
  191. package/docs/variables/DEFAULT_FUNDING_AMOUNTS.html +1 -1
  192. package/docs/variables/DEV_TOKEN_INFOS.html +1 -1
  193. package/docs/variables/DEV_URL.html +1 -1
  194. package/docs/variables/MAX_BUFFER_LEN.html +1 -1
  195. package/docs/variables/SESSION_TTL.html +1 -1
  196. package/docs/variables/WEBSERVER_DEV_URL.html +1 -1
  197. package/docs/variables/ZERO_DECIMAL.html +1 -1
  198. package/docs/variables/_private.html +2 -0
  199. package/eslint.config.mjs +66 -0
  200. package/package.json +20 -23
  201. package/src/bridge/client.ts +487 -0
  202. package/src/bridge/const.ts +53 -0
  203. package/src/bridge/index.ts +7 -0
  204. package/src/bridge/types.ts +127 -0
  205. package/src/bridge/utils.ts +140 -0
  206. package/src/const.ts +4 -9
  207. package/src/gen/common.ts +27 -10
  208. package/src/gen/nord.ts +1045 -487
  209. package/src/idl/bridge.ts +702 -0
  210. package/src/index.ts +21 -2
  211. package/src/nord/{actions.ts → api/actions.ts} +12 -16
  212. package/src/nord/api/core.ts +130 -0
  213. package/src/nord/api/market.ts +125 -0
  214. package/src/nord/api/metrics.ts +154 -0
  215. package/src/nord/api/queries.ts +236 -0
  216. package/src/nord/client/Nord.ts +652 -0
  217. package/src/nord/client/NordUser.ts +1101 -0
  218. package/src/nord/index.ts +16 -2
  219. package/src/nord/models/Subscriber.ts +56 -0
  220. package/src/nord/utils/NordError.ts +72 -0
  221. package/src/types.ts +163 -92
  222. package/src/utils.ts +22 -1
  223. package/src/websocket/NordWebSocketClient.ts +432 -0
  224. package/src/websocket/events.ts +31 -0
  225. package/src/websocket/index.ts +2 -0
  226. package/tsconfig.eslint.json +12 -0
  227. package/.eslintignore +0 -1
  228. package/.eslintrc.js +0 -20
  229. package/dist/abis/ERC20_ABI.d.ts +0 -39
  230. package/dist/abis/ERC20_ABI.js +0 -313
  231. package/dist/abis/NORD_GETTERS_FACET_ABI.d.ts +0 -34
  232. package/dist/abis/NORD_GETTERS_FACET_ABI.js +0 -195
  233. package/dist/abis/NORD_RAMP_FACET_ABI.d.ts +0 -35
  234. package/dist/abis/NORD_RAMP_FACET_ABI.js +0 -144
  235. package/dist/abis/index.d.ts +0 -3
  236. package/dist/abis/index.js +0 -9
  237. package/dist/nord/Nord.d.ts +0 -76
  238. package/dist/nord/Nord.js +0 -376
  239. package/dist/nord/NordImpl.d.ts +0 -7
  240. package/dist/nord/NordImpl.js +0 -6
  241. package/dist/nord/NordUser.d.ts +0 -77
  242. package/dist/nord/NordUser.js +0 -249
  243. package/docs/functions/createWebSocketSubscription.html +0 -12
  244. package/docs/interfaces/ERC20TokenInfo.html +0 -5
  245. package/docs/interfaces/OrderbookOrder.html +0 -6
  246. package/docs/interfaces/TradeInfo.html +0 -20
  247. package/docs/interfaces/TradesQueryParams.html +0 -10
  248. package/docs/variables/DEV_CONTRACT_ADDRESS.html +0 -1
  249. package/docs/variables/ERC20_ABI.html +0 -1
  250. package/docs/variables/EVM_DEV_URL.html +0 -1
  251. package/docs/variables/FAUCET_PRIVATE_ADDRESS.html +0 -1
  252. package/docs/variables/NORD_GETTERS_FACET_ABI.html +0 -1
  253. package/docs/variables/NORD_RAMP_FACET_ABI.html +0 -1
  254. package/src/abis/ERC20_ABI.ts +0 -310
  255. package/src/abis/NORD_GETTERS_FACET_ABI.ts +0 -192
  256. package/src/abis/NORD_RAMP_FACET_ABI.ts +0 -141
  257. package/src/abis/index.ts +0 -3
  258. package/src/nord/Nord.ts +0 -504
  259. package/src/nord/NordImpl.ts +0 -8
  260. package/src/nord/NordUser.ts +0 -469
@@ -1,2 +1,9 @@
1
- export { NordUser } from "./NordUser";
2
- export { Nord, createWebSocketSubscription, Subscriber } from "./Nord";
1
+ export { Nord } from "./client/Nord";
2
+ export { NordUser } from "./client/NordUser";
3
+ export { NordError } from "./utils/NordError";
4
+ export * from "./api/core";
5
+ export * from "./api/metrics";
6
+ export * from "./api/queries";
7
+ export * from "./api/market";
8
+ export * from "./api/actions";
9
+ export * from "./models/Subscriber";
@@ -1,9 +1,33 @@
1
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Subscriber = exports.createWebSocketSubscription = exports.Nord = exports.NordUser = void 0;
4
- var NordUser_1 = require("./NordUser");
5
- Object.defineProperty(exports, "NordUser", { enumerable: true, get: function () { return NordUser_1.NordUser; } });
6
- var Nord_1 = require("./Nord");
17
+ exports.NordError = exports.NordUser = exports.Nord = void 0;
18
+ // Export main client classes
19
+ var Nord_1 = require("./client/Nord");
7
20
  Object.defineProperty(exports, "Nord", { enumerable: true, get: function () { return Nord_1.Nord; } });
8
- Object.defineProperty(exports, "createWebSocketSubscription", { enumerable: true, get: function () { return Nord_1.createWebSocketSubscription; } });
9
- Object.defineProperty(exports, "Subscriber", { enumerable: true, get: function () { return Nord_1.Subscriber; } });
21
+ var NordUser_1 = require("./client/NordUser");
22
+ Object.defineProperty(exports, "NordUser", { enumerable: true, get: function () { return NordUser_1.NordUser; } });
23
+ // Export utility classes
24
+ var NordError_1 = require("./utils/NordError");
25
+ Object.defineProperty(exports, "NordError", { enumerable: true, get: function () { return NordError_1.NordError; } });
26
+ // Export API modules
27
+ __exportStar(require("./api/core"), exports);
28
+ __exportStar(require("./api/metrics"), exports);
29
+ __exportStar(require("./api/queries"), exports);
30
+ __exportStar(require("./api/market"), exports);
31
+ __exportStar(require("./api/actions"), exports);
32
+ // Export models
33
+ __exportStar(require("./models/Subscriber"), exports);
@@ -0,0 +1,37 @@
1
+ import { EventEmitter } from "events";
2
+ import { Account, DeltaEvent, OrderbookResponse, SubscriberConfig, Trade, 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: Trade[]) => 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,46 @@
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 += ` (Status: ${this.statusCode})`;
39
+ }
40
+ if (this.details && Object.keys(this.details).length > 0) {
41
+ result += `\nDetails: ${JSON.stringify(this.details, null, 2)}`;
42
+ }
43
+ return result;
44
+ }
45
+ }
46
+ exports.NordError = NordError;
package/dist/types.d.ts CHANGED
@@ -15,13 +15,24 @@ export declare enum PeakTpsPeriodUnit {
15
15
  Month = "m",
16
16
  Year = "y"
17
17
  }
18
+ /**
19
+ * Configuration options for the Nord client
20
+ */
18
21
  export interface NordConfig {
19
- evmUrl: string;
22
+ /** Base URL for the Nord web server */
20
23
  webServerUrl: string;
21
- contractAddress: string;
22
- tokenInfos: ERC20TokenInfo[];
23
- }
24
- export interface ERC20TokenInfo {
24
+ /** Solana program ID */
25
+ solanaProgramId: string;
26
+ /** Solana cluster URL */
27
+ solanaUrl: string;
28
+ /** Whether to initialize WebSockets on creation, defaults to true */
29
+ initWebSockets?: boolean;
30
+ /** Initial subscriptions for the trades WebSocket (e.g., ["trades@BTCUSDC"]) */
31
+ tradesSubscriptions?: string[];
32
+ /** Initial subscriptions for the deltas WebSocket (e.g., ["deltas@BTCUSDC"]) */
33
+ deltasSubscriptions?: string[];
34
+ }
35
+ export interface TokenInfo {
25
36
  address: string;
26
37
  precision: number;
27
38
  tokenId: number;
@@ -54,17 +65,19 @@ export interface SubscriberConfig {
54
65
  maxBufferLen?: number;
55
66
  }
56
67
  export interface Market {
68
+ marketId: number;
57
69
  symbol: string;
58
- baseTokenId: number;
59
- quoteTokenId: number;
60
70
  priceDecimals: number;
61
71
  sizeDecimals: number;
72
+ baseTokenId: number;
73
+ quoteTokenId: number;
74
+ frozen: boolean;
62
75
  }
63
76
  export interface Token {
77
+ tokenId: number;
64
78
  symbol: string;
65
- ethAddr: string;
66
79
  decimals: number;
67
- tokenId: number;
80
+ mintAddr: string;
68
81
  }
69
82
  export interface Info {
70
83
  markets: Market[];
@@ -74,8 +87,8 @@ export interface DeltaEvent {
74
87
  last_update_id: number;
75
88
  update_id: number;
76
89
  market_symbol: string;
77
- asks: [number, number];
78
- bids: [number, number];
90
+ asks: OrderbookEntry[];
91
+ bids: OrderbookEntry[];
79
92
  }
80
93
  export interface Trade {
81
94
  side: Side;
@@ -92,7 +105,7 @@ export interface Trades {
92
105
  export interface OrderInfo {
93
106
  id: number;
94
107
  reduce_only: boolean;
95
- imit_price: number;
108
+ limit_price: number;
96
109
  size: number;
97
110
  account_id: number;
98
111
  }
@@ -103,7 +116,7 @@ export interface Account {
103
116
  last_update_id: number;
104
117
  update_id: number;
105
118
  account_id: number;
106
- fills: HashMap<FillMode>;
119
+ fills: HashMap<number>;
107
120
  places: HashMap<OrderInfo>;
108
121
  cancels: HashMap<OrderInfo>;
109
122
  balances: HashMap<number>;
@@ -220,79 +233,6 @@ export interface AggregateMetrics {
220
233
  tx_tps_peak: number;
221
234
  request_latency_average: number;
222
235
  }
223
- /**
224
- * Parameters for querying trades
225
- * @field {number} accountId - ID of target account
226
- * @field {string} [since] - Start with this timestamp (RFC3339); defaults to UNIX epoch start
227
- * @field {string} [until] - End with this timestamp (RFC3339); defaults to current date-time
228
- * @field {string} [pageId] - Fetch results starting with this page
229
- */
230
- export interface TradesQueryParams {
231
- accountId: number;
232
- since?: string;
233
- until?: string;
234
- pageId?: string;
235
- }
236
- /**
237
- * Trade information
238
- * @field {string} id - Trade ID
239
- * @field {string} timestamp - Trade timestamp (RFC3339)
240
- * @field {string} symbol - Market symbol
241
- * @field {string} side - Trade side (buy/sell)
242
- * @field {number} price - Trade price
243
- * @field {number} size - Trade size
244
- * @field {number} fee - Trade fee
245
- * @field {string} feeCurrency - Fee currency
246
- * @field {number} orderId - Order ID
247
- */
248
- export interface TradeInfo {
249
- id: string;
250
- timestamp: string;
251
- symbol: string;
252
- side: string;
253
- price: number;
254
- size: number;
255
- fee: number;
256
- feeCurrency: string;
257
- orderId: number;
258
- }
259
- /**
260
- * Response for trades query
261
- * @field {number} accountId - Account ID
262
- * @field {string} since - Start timestamp (RFC3339)
263
- * @field {string} until - End timestamp (RFC3339)
264
- * @field {string} [nextPageId] - ID for the next page of results
265
- * @field {TradeInfo[]} trades - Array of trades
266
- */
267
- export interface TradesResponse {
268
- accountId: number;
269
- since: string;
270
- until: string;
271
- nextPageId?: string;
272
- trades: TradeInfo[];
273
- }
274
- /**
275
- * Order in the orderbook
276
- * @field {number} price - Order price
277
- * @field {number} size - Order size
278
- */
279
- export interface OrderbookOrder {
280
- price: number;
281
- size: number;
282
- }
283
- /**
284
- * Response for orderbook query
285
- * @field {string} symbol - Market symbol
286
- * @field {number} timestamp - Orderbook timestamp
287
- * @field {OrderbookOrder[]} bids - Array of bid orders
288
- * @field {OrderbookOrder[]} asks - Array of ask orders
289
- */
290
- export interface OrderbookResponse {
291
- symbol: string;
292
- timestamp: number;
293
- bids: OrderbookOrder[];
294
- asks: OrderbookOrder[];
295
- }
296
236
  export interface RollmanBlockResponse {
297
237
  block_number: number;
298
238
  actions: RollmanActionInfo[];
@@ -340,4 +280,121 @@ export interface PerpMarketStats {
340
280
  * @throws Will throw an error if provided with an invalid fill mode.
341
281
  */
342
282
  export declare function fillModeToProtoFillMode(x: FillMode): proto.FillMode;
283
+ /**
284
+ * Response for trades query with pagination support
285
+ */
286
+ export interface TradesResponse {
287
+ trades: Trade[];
288
+ accountId: number;
289
+ since?: string;
290
+ until?: string;
291
+ nextPageId?: string;
292
+ }
293
+ /**
294
+ * Query parameters for trades endpoint
295
+ */
296
+ export interface TradesQuery {
297
+ accountId: number;
298
+ since?: string;
299
+ until?: string;
300
+ pageId?: string;
301
+ }
302
+ /**
303
+ * Response for user account IDs query
304
+ */
305
+ export interface UserAccountIdsResponse {
306
+ accountIds: number[];
307
+ }
308
+ /**
309
+ * Query parameters for user account IDs
310
+ */
311
+ export interface UserAccountIdsQuery {
312
+ pubkey: string;
313
+ }
314
+ /**
315
+ * Orderbook entry representing price and size
316
+ */
317
+ export interface OrderbookEntry {
318
+ price: number;
319
+ size: number;
320
+ }
321
+ /**
322
+ * Response for orderbook query
323
+ */
324
+ export interface OrderbookResponse {
325
+ symbol: string;
326
+ asks: OrderbookEntry[];
327
+ bids: OrderbookEntry[];
328
+ timestamp: number;
329
+ }
330
+ /**
331
+ * Query parameters for orderbook
332
+ *
333
+ * Note: While you can provide either symbol or market_id, the API endpoint only accepts market_id.
334
+ * If you provide a symbol, it will be converted to a market_id internally.
335
+ */
336
+ export interface OrderbookQuery {
337
+ symbol?: string;
338
+ market_id?: number;
339
+ }
340
+ /**
341
+ * Response for timestamp query
342
+ */
343
+ export interface TimestampResponse {
344
+ timestamp: number;
345
+ }
346
+ /**
347
+ * Response for action nonce query
348
+ */
349
+ export interface ActionNonceResponse {
350
+ nonce: number;
351
+ }
352
+ /**
353
+ * WebSocket message types
354
+ */
355
+ export declare enum WebSocketMessageType {
356
+ Subscribe = "subscribe",
357
+ Unsubscribe = "unsubscribe",
358
+ TradeUpdate = "trade",
359
+ DeltaUpdate = "delta",
360
+ UserUpdate = "user"
361
+ }
362
+ /**
363
+ * WebSocket subscription request
364
+ */
365
+ export interface WebSocketSubscription {
366
+ type: WebSocketMessageType;
367
+ streams: string[];
368
+ }
369
+ /**
370
+ * WebSocket trade update message
371
+ */
372
+ export interface WebSocketTradeUpdate {
373
+ type: WebSocketMessageType.TradeUpdate;
374
+ symbol: string;
375
+ trades: Trade[];
376
+ timestamp: number;
377
+ }
378
+ /**
379
+ * WebSocket delta update message
380
+ */
381
+ export interface WebSocketDeltaUpdate {
382
+ type: WebSocketMessageType.DeltaUpdate;
383
+ last_update_id: number;
384
+ update_id: number;
385
+ market_symbol: string;
386
+ asks: OrderbookEntry[];
387
+ bids: OrderbookEntry[];
388
+ timestamp: number;
389
+ }
390
+ /**
391
+ * WebSocket user update message
392
+ */
393
+ export interface WebSocketUserUpdate {
394
+ type: WebSocketMessageType.UserUpdate;
395
+ userId: number;
396
+ account: Account;
397
+ timestamp: number;
398
+ }
399
+ export type WebSocketMessage = WebSocketSubscription | WebSocketTradeUpdate | WebSocketDeltaUpdate | WebSocketUserUpdate;
343
400
  export {};
package/dist/types.js CHANGED
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.FillMode = exports.Side = exports.KeyType = exports.PeakTpsPeriodUnit = void 0;
36
+ exports.WebSocketMessageType = exports.FillMode = exports.Side = exports.KeyType = exports.PeakTpsPeriodUnit = void 0;
37
37
  exports.fillModeToProtoFillMode = fillModeToProtoFillMode;
38
38
  const proto = __importStar(require("./gen/nord"));
39
39
  /**
@@ -90,3 +90,14 @@ function fillModeToProtoFillMode(x) {
90
90
  return proto.FillMode.FILL_OR_KILL;
91
91
  throw new Error("Invalid fill mode");
92
92
  }
93
+ /**
94
+ * WebSocket message types
95
+ */
96
+ var WebSocketMessageType;
97
+ (function (WebSocketMessageType) {
98
+ WebSocketMessageType["Subscribe"] = "subscribe";
99
+ WebSocketMessageType["Unsubscribe"] = "unsubscribe";
100
+ WebSocketMessageType["TradeUpdate"] = "trade";
101
+ WebSocketMessageType["DeltaUpdate"] = "delta";
102
+ WebSocketMessageType["UserUpdate"] = "user";
103
+ })(WebSocketMessageType || (exports.WebSocketMessageType = WebSocketMessageType = {}));
package/dist/utils.d.ts CHANGED
@@ -3,6 +3,7 @@ import { KeyType, type Market, type Token } from "./types";
3
3
  import * as proto from "./gen/nord";
4
4
  import { ethers } from "ethers";
5
5
  import { RequestInfo, RequestInit, Response } from "node-fetch";
6
+ import { BN } from "@coral-xyz/anchor";
6
7
  export declare const SESSION_TTL: bigint;
7
8
  export declare const ZERO_DECIMAL: Decimal;
8
9
  export declare const MAX_BUFFER_LEN = 10000;
@@ -112,3 +113,11 @@ export declare function decodeLengthDelimited<T, M extends proto.MessageFns<T>>(
112
113
  export declare function checkPubKeyLength(keyType: KeyType, len: number): void;
113
114
  export declare function findMarket(markets: Market[], marketId: number): Market;
114
115
  export declare function findToken(tokens: Token[], tokenId: number): Token;
116
+ /**
117
+ * Convert a number to a BN with the specified number of decimals
118
+ *
119
+ * @param amount Amount as a number
120
+ * @param decimals Number of decimal places
121
+ * @returns Amount as a BN
122
+ */
123
+ export declare function toBN(amount: number, decimals: number): BN;
package/dist/utils.js CHANGED
@@ -18,6 +18,7 @@ exports.decodeLengthDelimited = decodeLengthDelimited;
18
18
  exports.checkPubKeyLength = checkPubKeyLength;
19
19
  exports.findMarket = findMarket;
20
20
  exports.findToken = findToken;
21
+ exports.toBN = toBN;
21
22
  const decimal_js_1 = require("decimal.js");
22
23
  const ed25519_1 = require("@noble/curves/ed25519");
23
24
  const bls12_381_1 = require("@noble/curves/bls12-381");
@@ -27,7 +28,8 @@ const types_1 = require("./types");
27
28
  const wire_1 = require("@bufbuild/protobuf/wire");
28
29
  const ethers_1 = require("ethers");
29
30
  const node_fetch_1 = __importDefault(require("node-fetch"));
30
- exports.SESSION_TTL = 10n * 60n * 1000n * 10000n;
31
+ const anchor_1 = require("@coral-xyz/anchor");
32
+ exports.SESSION_TTL = 60n * 60n * 24n * 30n;
31
33
  exports.ZERO_DECIMAL = new decimal_js_1.Decimal(0);
32
34
  exports.MAX_BUFFER_LEN = 10000;
33
35
  const MAX_PAYLOAD_SIZE = 100 * 1024; // 100 kB
@@ -255,3 +257,20 @@ function findToken(tokens, tokenId) {
255
257
  }
256
258
  return tokens[tokenId];
257
259
  }
260
+ /**
261
+ * Convert a number to a BN with the specified number of decimals
262
+ *
263
+ * @param amount Amount as a number
264
+ * @param decimals Number of decimal places
265
+ * @returns Amount as a BN
266
+ */
267
+ function toBN(amount, decimals) {
268
+ const amountString = amount.toFixed(decimals);
269
+ const [whole, fraction] = amountString.split(".");
270
+ // Convert to smallest units (no decimals)
271
+ const wholeBN = new anchor_1.BN(whole).mul(new anchor_1.BN(10).pow(new anchor_1.BN(decimals)));
272
+ const fractionBN = fraction
273
+ ? new anchor_1.BN(fraction.padEnd(decimals, "0").slice(0, decimals))
274
+ : new anchor_1.BN(0);
275
+ return wholeBN.add(fractionBN);
276
+ }
@@ -0,0 +1,71 @@
1
+ import { EventEmitter } from "events";
2
+ import { NordWebSocketClientEvents } from "./events";
3
+ /**
4
+ * WebSocket client for Nord exchange
5
+ *
6
+ * This client connects to one of the specific Nord WebSocket endpoints:
7
+ * - /ws/trades - For trade updates
8
+ * - /ws/deltas - For orderbook delta updates
9
+ * - /ws/user - For user-specific updates
10
+ *
11
+ * Each endpoint handles a specific type of data and subscriptions must match
12
+ * the endpoint type (e.g., only 'trades@BTCUSDC' subscriptions are valid on
13
+ * the /ws/trades endpoint).
14
+ */
15
+ export declare class NordWebSocketClient extends EventEmitter implements NordWebSocketClientEvents {
16
+ private ws;
17
+ private url;
18
+ private subscriptions;
19
+ private reconnectAttempts;
20
+ private maxReconnectAttempts;
21
+ private reconnectDelay;
22
+ private pingInterval;
23
+ private pingTimeout;
24
+ private isBrowser;
25
+ /**
26
+ * Create a new NordWebSocketClient
27
+ * @param url WebSocket server URL
28
+ */
29
+ constructor(url: string);
30
+ /**
31
+ * Validate stream format
32
+ * @param stream Stream identifier to validate
33
+ * @throws Error if stream format is invalid
34
+ */
35
+ private validateStream;
36
+ /**
37
+ * Setup WebSocket ping/pong heartbeat
38
+ */
39
+ private setupHeartbeat;
40
+ /**
41
+ * Get the appropriate WebSocket class based on environment
42
+ */
43
+ private getWebSocketClass;
44
+ /**
45
+ * Connect to the Nord WebSocket server
46
+ */
47
+ connect(): void;
48
+ /**
49
+ * Subscribe to one or more streams
50
+ * @param streams Array of streams to subscribe to (e.g. ["trades@BTCUSDC", "deltas@BTCUSDC"])
51
+ */
52
+ subscribe(streams: string[]): void;
53
+ /**
54
+ * Unsubscribe from one or more streams
55
+ * @param streams Array of streams to unsubscribe from
56
+ */
57
+ unsubscribe(streams: string[]): void;
58
+ /**
59
+ * Close the WebSocket connection
60
+ */
61
+ close(): void;
62
+ /**
63
+ * Handle incoming WebSocket messages
64
+ * @param message WebSocket message
65
+ */
66
+ private handleMessage;
67
+ /**
68
+ * Attempt to reconnect to the WebSocket server
69
+ */
70
+ private reconnect;
71
+ }