@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
package/dist/index.js CHANGED
@@ -14,8 +14,24 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.shortenPublicKey = exports.hexToBuffer = exports.bufferToHex = exports.findPda = exports.makeSigningFunction = exports.keypairFromPrivateKey = exports.fromBN = exports.bridgeToBN = void 0;
18
+ // Export types
17
19
  __exportStar(require("./types"), exports);
18
20
  __exportStar(require("./utils"), exports);
19
- __exportStar(require("./abis"), exports);
20
- __exportStar(require("./nord"), exports);
21
21
  __exportStar(require("./const"), exports);
22
+ // Export Nord modules
23
+ __exportStar(require("./nord"), exports);
24
+ // Export WebSocket modules
25
+ __exportStar(require("./websocket/index"), exports);
26
+ // Export bridge modules
27
+ __exportStar(require("./bridge/client"), exports);
28
+ __exportStar(require("./bridge/types"), exports);
29
+ var utils_1 = require("./bridge/utils");
30
+ Object.defineProperty(exports, "bridgeToBN", { enumerable: true, get: function () { return utils_1.bridgeToBN; } });
31
+ Object.defineProperty(exports, "fromBN", { enumerable: true, get: function () { return utils_1.fromBN; } });
32
+ Object.defineProperty(exports, "keypairFromPrivateKey", { enumerable: true, get: function () { return utils_1.keypairFromPrivateKey; } });
33
+ Object.defineProperty(exports, "makeSigningFunction", { enumerable: true, get: function () { return utils_1.makeSigningFunction; } });
34
+ Object.defineProperty(exports, "findPda", { enumerable: true, get: function () { return utils_1.findPda; } });
35
+ Object.defineProperty(exports, "bufferToHex", { enumerable: true, get: function () { return utils_1.bufferToHex; } });
36
+ Object.defineProperty(exports, "hexToBuffer", { enumerable: true, get: function () { return utils_1.hexToBuffer; } });
37
+ Object.defineProperty(exports, "shortenPublicKey", { enumerable: true, get: function () { return utils_1.shortenPublicKey; } });
@@ -1,20 +1,20 @@
1
- import { FillMode, Side } from "../types";
2
- import { BigIntValue } from "../utils";
3
1
  import Decimal from "decimal.js";
4
- declare function createSessionImpl(sendFn: (encoded: Uint8Array) => Promise<Uint8Array>, walletSignFn: (message: string | Uint8Array) => Promise<string>, currentTimestamp: bigint, nonce: number, params: {
2
+ import { FillMode, Side } from "../../types";
3
+ import { BigIntValue } from "../../utils";
4
+ declare function createSessionImpl(sendFn: (encoded: Uint8Array) => Promise<Uint8Array>, walletSignFn: (message: string | Uint8Array) => Promise<Uint8Array>, currentTimestamp: bigint, nonce: number, params: {
5
5
  userPubkey: Uint8Array;
6
6
  sessionPubkey: Uint8Array;
7
7
  expiryTimestamp?: bigint;
8
8
  }): Promise<bigint>;
9
- export declare function createSession(serverUrl: string, walletSignFn: (message: string | Uint8Array) => Promise<string>, currentTimestamp: bigint, nonce: number, params: {
9
+ export declare function createSession(serverUrl: string, walletSignFn: (message: string | Uint8Array) => Promise<Uint8Array>, currentTimestamp: bigint, nonce: number, params: {
10
10
  userPubkey: Uint8Array;
11
11
  sessionPubkey: Uint8Array;
12
12
  expiryTimestamp?: bigint;
13
13
  }): Promise<bigint>;
14
- declare function revokeSessionImpl(sendFn: (encoded: Uint8Array) => Promise<Uint8Array>, walletSignFn: (message: string | Uint8Array) => Promise<string>, currentTimestamp: bigint, nonce: number, params: {
14
+ declare function revokeSessionImpl(sendFn: (encoded: Uint8Array) => Promise<Uint8Array>, walletSignFn: (message: string | Uint8Array) => Promise<Uint8Array>, currentTimestamp: bigint, nonce: number, params: {
15
15
  sessionId: BigIntValue;
16
16
  }): Promise<void>;
17
- export declare function revokeSession(serverUrl: string, walletSignFn: (message: string | Uint8Array) => Promise<string>, currentTimestamp: bigint, nonce: number, params: {
17
+ export declare function revokeSession(serverUrl: string, walletSignFn: (message: string | Uint8Array) => Promise<Uint8Array>, currentTimestamp: bigint, nonce: number, params: {
18
18
  sessionId: BigIntValue;
19
19
  }): Promise<void>;
20
20
  declare function withdrawImpl(sendFn: (encoded: Uint8Array) => Promise<Uint8Array>, signFn: (message: Uint8Array) => Promise<Uint8Array>, currentTimestamp: bigint, nonce: number, params: {
@@ -40,20 +40,16 @@ exports.withdraw = withdraw;
40
40
  exports.placeOrder = placeOrder;
41
41
  exports.cancelOrder = cancelOrder;
42
42
  exports.transfer = transfer;
43
- const ethers_1 = require("ethers");
44
- const types_1 = require("../types");
45
- const utils_1 = require("../utils");
46
- const proto = __importStar(require("../gen/nord"));
43
+ const proto = __importStar(require("../../gen/nord"));
44
+ const types_1 = require("../../types");
45
+ const utils_1 = require("../../utils");
47
46
  async function sessionSign(signFn, message) {
48
47
  const signature = await signFn(message);
49
48
  return new Uint8Array([...message, ...signature]);
50
49
  }
51
50
  async function walletSign(walletSignFn, message) {
52
51
  const signature = await walletSignFn(message);
53
- return new Uint8Array([
54
- ...message,
55
- ...ethers_1.ethers.getBytes(signature.slice(0, -2)),
56
- ]);
52
+ return new Uint8Array([...message, ...signature]);
57
53
  }
58
54
  function makeSendHttp(serverUrl) {
59
55
  return async (body) => {
@@ -78,7 +74,7 @@ async function sendAction(sendFn, makeSignedMessage, action, actionErrorDesc) {
78
74
  return resp;
79
75
  }
80
76
  async function createSessionImpl(sendFn, walletSignFn, currentTimestamp, nonce, params) {
81
- (0, utils_1.checkPubKeyLength)(types_1.KeyType.Secp256k1, params.userPubkey.length);
77
+ (0, utils_1.checkPubKeyLength)(types_1.KeyType.Ed25519, params.userPubkey.length);
82
78
  (0, utils_1.checkPubKeyLength)(types_1.KeyType.Ed25519, params.sessionPubkey.length);
83
79
  let expiry = 0n;
84
80
  if (params.expiryTimestamp !== undefined) {
@@ -228,7 +224,7 @@ async function transferImpl(sendFn, signFn, currentTimestamp, nonce, params) {
228
224
  const resp = await sendAction(sendFn, (m) => sessionSign(signFn, m), action, "transfer asset to other account");
229
225
  if (resp.kind?.$case === "transferred") {
230
226
  if (resp.kind.value.accountCreated) {
231
- return resp.kind.value.toAccountId;
227
+ return resp.kind.value.toUserAccount;
232
228
  }
233
229
  else {
234
230
  return undefined;
@@ -0,0 +1,49 @@
1
+ import { Account, Info } from "../../types";
2
+ import { NordWebSocketClient } from "../../websocket/index";
3
+ /**
4
+ * Get the current timestamp from the Nord server
5
+ *
6
+ * @param webServerUrl - Base URL for the Nord web server
7
+ * @returns Current timestamp as a bigint
8
+ * @throws {NordError} If the request fails
9
+ */
10
+ export declare function getTimestamp(webServerUrl: string): Promise<bigint>;
11
+ /**
12
+ * Get the next action nonce from the Nord server
13
+ *
14
+ * @param webServerUrl - Base URL for the Nord web server
15
+ * @returns Next action nonce
16
+ * @throws {NordError} If the request fails
17
+ */
18
+ export declare function getActionNonce(webServerUrl: string): Promise<number>;
19
+ /**
20
+ * Get information about the Nord server
21
+ *
22
+ * @param webServerUrl - Base URL for the Nord web server
23
+ * @returns Information about markets and tokens
24
+ * @throws {NordError} If the request fails
25
+ */
26
+ export declare function getInfo(webServerUrl: string): Promise<Info>;
27
+ /**
28
+ * Get account information
29
+ *
30
+ * @param webServerUrl - Base URL for the Nord web server
31
+ * @param accountId - Account ID to get information for
32
+ * @returns Account information
33
+ * @throws {NordError} If the request fails
34
+ */
35
+ export declare function getAccount(webServerUrl: string, accountId: number): Promise<Account>;
36
+ /**
37
+ * Initialize a WebSocket client for Nord
38
+ *
39
+ * Connects to one of the specific Nord WebSocket endpoints:
40
+ * - /ws/trades - For trade updates (default)
41
+ * - /ws/deltas - For orderbook delta updates
42
+ * - /ws/user - For user-specific updates
43
+ *
44
+ * @param webServerUrl - Base URL for the Nord web server
45
+ * @param endpoint - Specific WebSocket endpoint to connect to (trades, deltas, or user)
46
+ * @param initialSubscriptions - Optional array of initial subscriptions (e.g., ["trades@BTCUSDC"])
47
+ * @returns WebSocket client
48
+ */
49
+ export declare function initWebSocketClient(webServerUrl: string, endpoint?: "trades" | "deltas" | "user", initialSubscriptions?: string[]): NordWebSocketClient;
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTimestamp = getTimestamp;
4
+ exports.getActionNonce = getActionNonce;
5
+ exports.getInfo = getInfo;
6
+ exports.getAccount = getAccount;
7
+ exports.initWebSocketClient = initWebSocketClient;
8
+ const utils_1 = require("../../utils");
9
+ const index_1 = require("../../websocket/index");
10
+ const NordError_1 = require("../utils/NordError");
11
+ /**
12
+ * Get the current timestamp from the Nord server
13
+ *
14
+ * @param webServerUrl - Base URL for the Nord web server
15
+ * @returns Current timestamp as a bigint
16
+ * @throws {NordError} If the request fails
17
+ */
18
+ async function getTimestamp(webServerUrl) {
19
+ try {
20
+ const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/timestamp`);
21
+ return BigInt(await response.json());
22
+ }
23
+ catch (error) {
24
+ throw new NordError_1.NordError("Failed to get timestamp", { cause: error });
25
+ }
26
+ }
27
+ /**
28
+ * Get the next action nonce from the Nord server
29
+ *
30
+ * @param webServerUrl - Base URL for the Nord web server
31
+ * @returns Next action nonce
32
+ * @throws {NordError} If the request fails
33
+ */
34
+ async function getActionNonce(webServerUrl) {
35
+ try {
36
+ const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/action_nonce`);
37
+ const data = await response.json();
38
+ return data.nonce;
39
+ }
40
+ catch (error) {
41
+ throw new NordError_1.NordError("Failed to get action nonce", { cause: error });
42
+ }
43
+ }
44
+ /**
45
+ * Get information about the Nord server
46
+ *
47
+ * @param webServerUrl - Base URL for the Nord web server
48
+ * @returns Information about markets and tokens
49
+ * @throws {NordError} If the request fails
50
+ */
51
+ async function getInfo(webServerUrl) {
52
+ try {
53
+ const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/info`);
54
+ return await response.json();
55
+ }
56
+ catch (error) {
57
+ throw new NordError_1.NordError("Failed to get info", { cause: error });
58
+ }
59
+ }
60
+ /**
61
+ * Get account information
62
+ *
63
+ * @param webServerUrl - Base URL for the Nord web server
64
+ * @param accountId - Account ID to get information for
65
+ * @returns Account information
66
+ * @throws {NordError} If the request fails
67
+ */
68
+ async function getAccount(webServerUrl, accountId) {
69
+ try {
70
+ const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/account?account_id=${accountId}`);
71
+ return await response.json();
72
+ }
73
+ catch (error) {
74
+ throw new NordError_1.NordError(`Failed to get account ${accountId}`, { cause: error });
75
+ }
76
+ }
77
+ /**
78
+ * Initialize a WebSocket client for Nord
79
+ *
80
+ * Connects to one of the specific Nord WebSocket endpoints:
81
+ * - /ws/trades - For trade updates (default)
82
+ * - /ws/deltas - For orderbook delta updates
83
+ * - /ws/user - For user-specific updates
84
+ *
85
+ * @param webServerUrl - Base URL for the Nord web server
86
+ * @param endpoint - Specific WebSocket endpoint to connect to (trades, deltas, or user)
87
+ * @param initialSubscriptions - Optional array of initial subscriptions (e.g., ["trades@BTCUSDC"])
88
+ * @returns WebSocket client
89
+ */
90
+ function initWebSocketClient(webServerUrl, endpoint, initialSubscriptions) {
91
+ try {
92
+ // Convert HTTP URL to WebSocket URL with specific endpoint
93
+ // If no specific endpoint is provided, we'll connect to trades by default
94
+ const specificEndpoint = endpoint || "trades";
95
+ const wsUrl = webServerUrl.replace(/^http/, "ws") + `/ws/${specificEndpoint}`;
96
+ console.log(`Initializing WebSocket client with URL: ${wsUrl}`);
97
+ // Create and connect the WebSocket client
98
+ const ws = new index_1.NordWebSocketClient(wsUrl);
99
+ // Add error handler
100
+ ws.on("error", (error) => {
101
+ console.error("Nord WebSocket error:", error);
102
+ });
103
+ // Add connected handler for debugging
104
+ ws.on("connected", () => {
105
+ console.log("Nord WebSocket connected successfully");
106
+ // Subscribe to initial subscriptions if provided
107
+ if (initialSubscriptions && initialSubscriptions.length > 0) {
108
+ ws.subscribe(initialSubscriptions);
109
+ }
110
+ });
111
+ // Connect the WebSocket
112
+ ws.connect();
113
+ return ws;
114
+ }
115
+ catch (error) {
116
+ console.error("Failed to initialize WebSocket client:", error);
117
+ throw new NordError_1.NordError("Failed to initialize WebSocket client", {
118
+ cause: error,
119
+ });
120
+ }
121
+ }
@@ -0,0 +1,36 @@
1
+ import { MarketsStatsResponse, OrderbookQuery, OrderbookResponse, TradesQuery, TradesResponse, UserAccountIdsQuery, UserAccountIdsResponse } from "../../types";
2
+ /**
3
+ * Get market statistics
4
+ *
5
+ * @param webServerUrl - Base URL for the Nord web server
6
+ * @returns Market statistics response
7
+ * @throws {NordError} If the request fails
8
+ */
9
+ export declare function marketsStats(webServerUrl: string): Promise<MarketsStatsResponse>;
10
+ /**
11
+ * Get trades for a market
12
+ *
13
+ * @param webServerUrl - Base URL for the Nord web server
14
+ * @param query - Trades query parameters
15
+ * @returns Trades response
16
+ * @throws {NordError} If the request fails
17
+ */
18
+ export declare function getTrades(webServerUrl: string, query: TradesQuery): Promise<TradesResponse>;
19
+ /**
20
+ * Get user account IDs
21
+ *
22
+ * @param webServerUrl - Base URL for the Nord web server
23
+ * @param query - User account IDs query parameters
24
+ * @returns User account IDs response
25
+ * @throws {NordError} If the request fails
26
+ */
27
+ export declare function getUserAccountIds(webServerUrl: string, query: UserAccountIdsQuery): Promise<UserAccountIdsResponse>;
28
+ /**
29
+ * Get orderbook for a market
30
+ *
31
+ * @param webServerUrl - Base URL for the Nord web server
32
+ * @param query - Orderbook query parameters
33
+ * @returns Orderbook response
34
+ * @throws {NordError} If the request fails
35
+ */
36
+ export declare function getOrderbook(webServerUrl: string, query: OrderbookQuery): Promise<OrderbookResponse>;
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.marketsStats = marketsStats;
4
+ exports.getTrades = getTrades;
5
+ exports.getUserAccountIds = getUserAccountIds;
6
+ exports.getOrderbook = getOrderbook;
7
+ const utils_1 = require("../../utils");
8
+ const NordError_1 = require("../utils/NordError");
9
+ /**
10
+ * Get market statistics
11
+ *
12
+ * @param webServerUrl - Base URL for the Nord web server
13
+ * @returns Market statistics response
14
+ * @throws {NordError} If the request fails
15
+ */
16
+ async function marketsStats(webServerUrl) {
17
+ try {
18
+ const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/stats`);
19
+ return await response.json();
20
+ }
21
+ catch (error) {
22
+ throw new NordError_1.NordError("Failed to fetch markets stats", { cause: error });
23
+ }
24
+ }
25
+ /**
26
+ * Get trades for a market
27
+ *
28
+ * @param webServerUrl - Base URL for the Nord web server
29
+ * @param query - Trades query parameters
30
+ * @returns Trades response
31
+ * @throws {NordError} If the request fails
32
+ */
33
+ async function getTrades(webServerUrl, query) {
34
+ try {
35
+ const params = new URLSearchParams();
36
+ params.append("accountId", query.accountId.toString());
37
+ if (query.since) {
38
+ params.append("since", query.since);
39
+ }
40
+ if (query.until) {
41
+ params.append("until", query.until);
42
+ }
43
+ if (query.pageId) {
44
+ params.append("pageId", query.pageId);
45
+ }
46
+ const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/trades?${params.toString()}`);
47
+ return await response.json();
48
+ }
49
+ catch (error) {
50
+ throw new NordError_1.NordError("Failed to get trades", { cause: error });
51
+ }
52
+ }
53
+ /**
54
+ * Get user account IDs
55
+ *
56
+ * @param webServerUrl - Base URL for the Nord web server
57
+ * @param query - User account IDs query parameters
58
+ * @returns User account IDs response
59
+ * @throws {NordError} If the request fails
60
+ */
61
+ async function getUserAccountIds(webServerUrl, query) {
62
+ try {
63
+ const params = new URLSearchParams();
64
+ params.append("pubkey", query.pubkey);
65
+ const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/user?${params.toString()}`);
66
+ return await response.json();
67
+ }
68
+ catch (error) {
69
+ throw new NordError_1.NordError("Failed to get user account IDs", { cause: error });
70
+ }
71
+ }
72
+ /**
73
+ * Get orderbook for a market
74
+ *
75
+ * @param webServerUrl - Base URL for the Nord web server
76
+ * @param query - Orderbook query parameters
77
+ * @returns Orderbook response
78
+ * @throws {NordError} If the request fails
79
+ */
80
+ async function getOrderbook(webServerUrl, query) {
81
+ try {
82
+ const params = new URLSearchParams();
83
+ if (query.symbol) {
84
+ params.append("symbol", query.symbol);
85
+ }
86
+ else if (query.market_id !== undefined) {
87
+ params.append("market_id", query.market_id.toString());
88
+ }
89
+ else {
90
+ throw new NordError_1.NordError("Either symbol or market_id must be provided for orderbook query");
91
+ }
92
+ const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/orderbook?${params.toString()}`);
93
+ return await response.json();
94
+ }
95
+ catch (error) {
96
+ throw new NordError_1.NordError("Failed to get orderbook", { cause: error });
97
+ }
98
+ }
@@ -0,0 +1,67 @@
1
+ import { AggregateMetrics, PeakTpsPeriodUnit } from "../../types";
2
+ /**
3
+ * Time periods for metrics queries
4
+ */
5
+ export declare enum MetricPeriod {
6
+ ONE_MINUTE = "1m",
7
+ FIVE_MINUTES = "5m",
8
+ FIFTEEN_MINUTES = "15m",
9
+ ONE_HOUR = "1h",
10
+ FOUR_HOURS = "4h",
11
+ ONE_DAY = "24h",
12
+ ONE_WEEK = "7d"
13
+ }
14
+ /**
15
+ * Fetch aggregate metrics from the Nord API
16
+ *
17
+ * @param webServerUrl - Base URL for the Nord web server
18
+ * @param txPeakTpsPeriod - Period for peak TPS calculation
19
+ * @param txPeakTpsPeriodUnit - Unit for peak TPS period
20
+ * @returns Aggregate metrics
21
+ * @throws {NordError} If the request fails
22
+ */
23
+ export declare function aggregateMetrics(webServerUrl: string, txPeakTpsPeriod?: number, txPeakTpsPeriodUnit?: PeakTpsPeriodUnit): Promise<AggregateMetrics>;
24
+ /**
25
+ * Get current transactions per second
26
+ *
27
+ * @param webServerUrl - Base URL for the Nord web server
28
+ * @param period - Time period for the query
29
+ * @returns Current TPS value
30
+ * @throws {NordError} If the request fails
31
+ */
32
+ export declare function getCurrentTps(webServerUrl: string, period?: string): Promise<number>;
33
+ /**
34
+ * Get peak transactions per second
35
+ *
36
+ * @param webServerUrl - Base URL for the Nord web server
37
+ * @param period - Time period for the query
38
+ * @returns Peak TPS value
39
+ * @throws {NordError} If the request fails
40
+ */
41
+ export declare function getPeakTps(webServerUrl: string, period?: string): Promise<number>;
42
+ /**
43
+ * Get median transaction latency
44
+ *
45
+ * @param webServerUrl - Base URL for the Nord web server
46
+ * @param period - Time period for the query
47
+ * @returns Median latency in milliseconds
48
+ * @throws {NordError} If the request fails
49
+ */
50
+ export declare function getMedianLatency(webServerUrl: string, period?: string): Promise<number>;
51
+ /**
52
+ * Get total transaction count
53
+ *
54
+ * @param webServerUrl - Base URL for the Nord web server
55
+ * @returns Total transaction count
56
+ * @throws {NordError} If the request fails
57
+ */
58
+ export declare function getTotalTransactions(webServerUrl: string): Promise<number>;
59
+ /**
60
+ * Query Prometheus metrics
61
+ *
62
+ * @param webServerUrl - Base URL for the Nord web server
63
+ * @param params - Prometheus query parameters
64
+ * @returns Query result as a number
65
+ * @throws {NordError} If the request fails
66
+ */
67
+ export declare function queryPrometheus(webServerUrl: string, params: string): Promise<number>;
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MetricPeriod = void 0;
4
+ exports.aggregateMetrics = aggregateMetrics;
5
+ exports.getCurrentTps = getCurrentTps;
6
+ exports.getPeakTps = getPeakTps;
7
+ exports.getMedianLatency = getMedianLatency;
8
+ exports.getTotalTransactions = getTotalTransactions;
9
+ exports.queryPrometheus = queryPrometheus;
10
+ const types_1 = require("../../types");
11
+ const utils_1 = require("../../utils");
12
+ const NordError_1 = require("../utils/NordError");
13
+ /**
14
+ * Time periods for metrics queries
15
+ */
16
+ var MetricPeriod;
17
+ (function (MetricPeriod) {
18
+ MetricPeriod["ONE_MINUTE"] = "1m";
19
+ MetricPeriod["FIVE_MINUTES"] = "5m";
20
+ MetricPeriod["FIFTEEN_MINUTES"] = "15m";
21
+ MetricPeriod["ONE_HOUR"] = "1h";
22
+ MetricPeriod["FOUR_HOURS"] = "4h";
23
+ MetricPeriod["ONE_DAY"] = "24h";
24
+ MetricPeriod["ONE_WEEK"] = "7d";
25
+ })(MetricPeriod || (exports.MetricPeriod = MetricPeriod = {}));
26
+ /**
27
+ * Fetch aggregate metrics from the Nord API
28
+ *
29
+ * @param webServerUrl - Base URL for the Nord web server
30
+ * @param txPeakTpsPeriod - Period for peak TPS calculation
31
+ * @param txPeakTpsPeriodUnit - Unit for peak TPS period
32
+ * @returns Aggregate metrics
33
+ * @throws {NordError} If the request fails
34
+ */
35
+ async function aggregateMetrics(webServerUrl, txPeakTpsPeriod = 1, txPeakTpsPeriodUnit = types_1.PeakTpsPeriodUnit.Day) {
36
+ try {
37
+ const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/metrics?tx_peak_tps_period=${txPeakTpsPeriod}&tx_peak_tps_period_unit=${txPeakTpsPeriodUnit}`);
38
+ return await response.json();
39
+ }
40
+ catch (error) {
41
+ throw new NordError_1.NordError("Failed to fetch aggregate metrics", { cause: error });
42
+ }
43
+ }
44
+ /**
45
+ * Get current transactions per second
46
+ *
47
+ * @param webServerUrl - Base URL for the Nord web server
48
+ * @param period - Time period for the query
49
+ * @returns Current TPS value
50
+ * @throws {NordError} If the request fails
51
+ */
52
+ async function getCurrentTps(webServerUrl, period = "1m") {
53
+ try {
54
+ return await queryPrometheus(webServerUrl, `sum(rate(nord_tx_count[${period}]))`);
55
+ }
56
+ catch (error) {
57
+ throw new NordError_1.NordError(`Failed to get current TPS for period ${period}`, {
58
+ cause: error,
59
+ });
60
+ }
61
+ }
62
+ /**
63
+ * Get peak transactions per second
64
+ *
65
+ * @param webServerUrl - Base URL for the Nord web server
66
+ * @param period - Time period for the query
67
+ * @returns Peak TPS value
68
+ * @throws {NordError} If the request fails
69
+ */
70
+ async function getPeakTps(webServerUrl, period = "24h") {
71
+ try {
72
+ return await queryPrometheus(webServerUrl, `max_over_time(sum(rate(nord_tx_count[1m]))[${period}:])`);
73
+ }
74
+ catch (error) {
75
+ throw new NordError_1.NordError(`Failed to get peak TPS for period ${period}`, {
76
+ cause: error,
77
+ });
78
+ }
79
+ }
80
+ /**
81
+ * Get median transaction latency
82
+ *
83
+ * @param webServerUrl - Base URL for the Nord web server
84
+ * @param period - Time period for the query
85
+ * @returns Median latency in milliseconds
86
+ * @throws {NordError} If the request fails
87
+ */
88
+ async function getMedianLatency(webServerUrl, period = "1m") {
89
+ try {
90
+ return await queryPrometheus(webServerUrl, `quantile_over_time(0.5, nord_tx_latency_ms[${period}])`);
91
+ }
92
+ catch (error) {
93
+ throw new NordError_1.NordError(`Failed to get median latency for period ${period}`, {
94
+ cause: error,
95
+ });
96
+ }
97
+ }
98
+ /**
99
+ * Get total transaction count
100
+ *
101
+ * @param webServerUrl - Base URL for the Nord web server
102
+ * @returns Total transaction count
103
+ * @throws {NordError} If the request fails
104
+ */
105
+ async function getTotalTransactions(webServerUrl) {
106
+ try {
107
+ return await queryPrometheus(webServerUrl, "sum(nord_tx_count)");
108
+ }
109
+ catch (error) {
110
+ throw new NordError_1.NordError("Failed to get total transactions", { cause: error });
111
+ }
112
+ }
113
+ /**
114
+ * Query Prometheus metrics
115
+ *
116
+ * @param webServerUrl - Base URL for the Nord web server
117
+ * @param params - Prometheus query parameters
118
+ * @returns Query result as a number
119
+ * @throws {NordError} If the request fails
120
+ */
121
+ async function queryPrometheus(webServerUrl, params) {
122
+ try {
123
+ const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/prometheus?query=${encodeURIComponent(params)}`);
124
+ const data = await response.json();
125
+ return data.data.result[0]?.value[1] || 0;
126
+ }
127
+ catch (error) {
128
+ throw new NordError_1.NordError(`Failed to query Prometheus: ${params}`, {
129
+ cause: error,
130
+ });
131
+ }
132
+ }