@n1xyz/nord-ts 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/dist/gen/common.js +1 -1
  2. package/dist/gen/nord.js +1 -1
  3. package/dist/nord/api/metrics.js +101 -7
  4. package/docs/classes/Nord.html +41 -41
  5. package/docs/classes/NordError.html +8 -8
  6. package/docs/classes/NordUser.html +37 -37
  7. package/docs/classes/NordWebSocketClient.html +34 -34
  8. package/docs/classes/SolanaBridgeClient.html +22 -22
  9. package/docs/classes/Subscriber.html +3 -3
  10. package/docs/enums/FillMode.html +2 -2
  11. package/docs/enums/KeyType.html +2 -2
  12. package/docs/enums/MetricPeriod.html +2 -2
  13. package/docs/enums/PdaSeedType.html +2 -2
  14. package/docs/enums/PeakTpsPeriodUnit.html +2 -2
  15. package/docs/enums/Side.html +2 -2
  16. package/docs/enums/WebSocketMessageType.html +2 -2
  17. package/docs/functions/actionQueryRollman.html +1 -1
  18. package/docs/functions/actionsQueryRollman.html +1 -1
  19. package/docs/functions/aggregateMetrics-1.html +1 -1
  20. package/docs/functions/assert.html +1 -1
  21. package/docs/functions/bigIntToProtoU128.html +1 -1
  22. package/docs/functions/blockQueryRollman.html +1 -1
  23. package/docs/functions/blockSummaryQueryRollman.html +1 -1
  24. package/docs/functions/bridgeToBN.html +1 -1
  25. package/docs/functions/bufferToHex.html +1 -1
  26. package/docs/functions/cancelOrder.html +1 -1
  27. package/docs/functions/checkPubKeyLength.html +1 -1
  28. package/docs/functions/checkedFetch.html +1 -1
  29. package/docs/functions/createSession.html +1 -1
  30. package/docs/functions/decodeLengthDelimited.html +1 -1
  31. package/docs/functions/encodeLengthDelimited.html +1 -1
  32. package/docs/functions/fillModeToProtoFillMode.html +1 -1
  33. package/docs/functions/findMarket.html +1 -1
  34. package/docs/functions/findPda.html +1 -1
  35. package/docs/functions/findToken.html +1 -1
  36. package/docs/functions/fromBN.html +1 -1
  37. package/docs/functions/getAccount.html +1 -1
  38. package/docs/functions/getActionNonce.html +1 -1
  39. package/docs/functions/getCurrentTps.html +1 -1
  40. package/docs/functions/getInfo.html +1 -1
  41. package/docs/functions/getMedianLatency.html +1 -1
  42. package/docs/functions/getOrderbook.html +1 -1
  43. package/docs/functions/getPeakTps.html +1 -1
  44. package/docs/functions/getTimestamp.html +1 -1
  45. package/docs/functions/getTotalTransactions.html +1 -1
  46. package/docs/functions/getTrades.html +1 -1
  47. package/docs/functions/getUserAccountIds.html +1 -1
  48. package/docs/functions/hexToBuffer.html +1 -1
  49. package/docs/functions/initWebSocketClient.html +1 -1
  50. package/docs/functions/keypairFromPrivateKey.html +1 -1
  51. package/docs/functions/makeSigningFunction.html +1 -1
  52. package/docs/functions/makeWalletSignFn.html +1 -1
  53. package/docs/functions/marketsStats.html +1 -1
  54. package/docs/functions/optExpect.html +1 -1
  55. package/docs/functions/optMap.html +1 -1
  56. package/docs/functions/optUnwrap.html +1 -1
  57. package/docs/functions/panic.html +1 -1
  58. package/docs/functions/placeOrder.html +1 -1
  59. package/docs/functions/queryAction.html +1 -1
  60. package/docs/functions/queryBlock.html +1 -1
  61. package/docs/functions/queryLastNBlocks.html +1 -1
  62. package/docs/functions/queryPrometheus.html +1 -1
  63. package/docs/functions/queryRecentActions.html +1 -1
  64. package/docs/functions/queryRecentBlocks.html +1 -1
  65. package/docs/functions/revokeSession.html +1 -1
  66. package/docs/functions/shortenPublicKey.html +1 -1
  67. package/docs/functions/signAction.html +1 -1
  68. package/docs/functions/toBN.html +1 -1
  69. package/docs/functions/toScaledU128.html +1 -1
  70. package/docs/functions/toScaledU64.html +1 -1
  71. package/docs/functions/transfer.html +1 -1
  72. package/docs/functions/withdraw.html +1 -1
  73. package/docs/interfaces/Account.html +2 -2
  74. package/docs/interfaces/ActionInfo.html +2 -2
  75. package/docs/interfaces/ActionNonceResponse.html +2 -2
  76. package/docs/interfaces/ActionQuery.html +2 -2
  77. package/docs/interfaces/ActionResponse.html +2 -2
  78. package/docs/interfaces/ActionsExtendedInfo.html +2 -2
  79. package/docs/interfaces/ActionsQuery.html +2 -2
  80. package/docs/interfaces/ActionsResponse.html +2 -2
  81. package/docs/interfaces/AggregateMetrics.html +2 -2
  82. package/docs/interfaces/BlockFacts.html +5 -5
  83. package/docs/interfaces/BlockQuery.html +2 -2
  84. package/docs/interfaces/BlockResponse.html +2 -2
  85. package/docs/interfaces/BlockSummary.html +2 -2
  86. package/docs/interfaces/BlockSummaryResponse.html +2 -2
  87. package/docs/interfaces/DeltaEvent.html +2 -2
  88. package/docs/interfaces/DepositSplParams.html +5 -5
  89. package/docs/interfaces/Info.html +2 -2
  90. package/docs/interfaces/Market.html +2 -2
  91. package/docs/interfaces/MarketStats.html +2 -2
  92. package/docs/interfaces/MarketsStatsResponse.html +2 -2
  93. package/docs/interfaces/NordConfig.html +7 -7
  94. package/docs/interfaces/NordWebSocketClientEvents.html +2 -2
  95. package/docs/interfaces/NordWebSocketEvents.html +2 -2
  96. package/docs/interfaces/Order.html +2 -2
  97. package/docs/interfaces/OrderInfo.html +2 -2
  98. package/docs/interfaces/OrderbookEntry.html +2 -2
  99. package/docs/interfaces/OrderbookQuery.html +2 -2
  100. package/docs/interfaces/OrderbookResponse.html +2 -2
  101. package/docs/interfaces/OrderbookSubscription.html +18 -18
  102. package/docs/interfaces/PerpMarketStats.html +2 -2
  103. package/docs/interfaces/RollmanActionExtendedInfo.html +2 -2
  104. package/docs/interfaces/RollmanActionInfo.html +2 -2
  105. package/docs/interfaces/RollmanActionResponse.html +2 -2
  106. package/docs/interfaces/RollmanActionsResponse.html +2 -2
  107. package/docs/interfaces/RollmanBlockResponse.html +2 -2
  108. package/docs/interfaces/SPLTokenInfo.html +5 -5
  109. package/docs/interfaces/SolanaBridgeConfig.html +5 -5
  110. package/docs/interfaces/StateFacts.html +5 -5
  111. package/docs/interfaces/SubscriberConfig.html +2 -2
  112. package/docs/interfaces/TimestampResponse.html +2 -2
  113. package/docs/interfaces/Token.html +2 -2
  114. package/docs/interfaces/TokenInfo.html +2 -2
  115. package/docs/interfaces/Trade.html +2 -2
  116. package/docs/interfaces/TradeSubscription.html +18 -18
  117. package/docs/interfaces/Trades.html +2 -2
  118. package/docs/interfaces/TradesQuery.html +2 -2
  119. package/docs/interfaces/TradesResponse.html +2 -2
  120. package/docs/interfaces/TransferParams.html +4 -4
  121. package/docs/interfaces/UserAccountIdsQuery.html +2 -2
  122. package/docs/interfaces/UserAccountIdsResponse.html +2 -2
  123. package/docs/interfaces/WebSocketDeltaUpdate.html +2 -2
  124. package/docs/interfaces/WebSocketSubscription.html +2 -2
  125. package/docs/interfaces/WebSocketTradeUpdate.html +2 -2
  126. package/docs/interfaces/WebSocketUserUpdate.html +2 -2
  127. package/docs/interfaces/WithdrawalClaim.html +7 -7
  128. package/docs/interfaces/WithdrawalParams.html +4 -4
  129. package/docs/types/BigIntValue.html +1 -1
  130. package/docs/types/WebSocketMessage.html +1 -1
  131. package/docs/variables/DEBUG_KEYS.html +1 -1
  132. package/docs/variables/DEFAULT_FUNDING_AMOUNTS.html +1 -1
  133. package/docs/variables/DEV_TOKEN_INFOS.html +1 -1
  134. package/docs/variables/DEV_URL.html +1 -1
  135. package/docs/variables/MAX_BUFFER_LEN.html +1 -1
  136. package/docs/variables/SESSION_TTL.html +1 -1
  137. package/docs/variables/WEBSERVER_DEV_URL.html +1 -1
  138. package/docs/variables/ZERO_DECIMAL.html +1 -1
  139. package/docs/variables/_private.html +1 -1
  140. package/package.json +1 -1
  141. package/src/gen/common.ts +1 -1
  142. package/src/gen/nord.ts +1 -1
  143. package/test.ts +80 -0
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
3
  // versions:
4
- // protoc-gen-ts_proto v2.6.1
4
+ // protoc-gen-ts_proto v2.7.0
5
5
  // protoc v3.21.12
6
6
  // source: common.proto
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
package/dist/gen/nord.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
3
  // versions:
4
- // protoc-gen-ts_proto v2.6.1
4
+ // protoc-gen-ts_proto v2.7.0
5
5
  // protoc v3.21.12
6
6
  // source: nord.proto
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -35,12 +35,87 @@ var MetricPeriod;
35
35
  async function aggregateMetrics(webServerUrl, txPeakTpsPeriod = 1, txPeakTpsPeriodUnit = types_1.PeakTpsPeriodUnit.Day) {
36
36
  try {
37
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();
38
+ // Get the raw text response (Prometheus format)
39
+ const text = await response.text();
40
+ // Parse the Prometheus-formatted metrics text into an AggregateMetrics object
41
+ const metrics = {
42
+ blocks_total: 0,
43
+ tx_total: extractMetricValue(text, "nord_requests_ok_count"),
44
+ tx_tps: calculateTps(text),
45
+ tx_tps_peak: calculatePeakTps(text),
46
+ request_latency_average: extractLatency(text)
47
+ };
48
+ return metrics;
39
49
  }
40
50
  catch (error) {
41
51
  throw new NordError_1.NordError("Failed to fetch aggregate metrics", { cause: error });
42
52
  }
43
53
  }
54
+ /**
55
+ * Extract a metric value from Prometheus-formatted text
56
+ *
57
+ * @param text - Prometheus-formatted metrics text
58
+ * @param metricName - Name of the metric to extract
59
+ * @returns The metric value as a number, or 0 if not found
60
+ */
61
+ function extractMetricValue(text, metricName) {
62
+ const regex = new RegExp(`^${metricName}\\s+([\\d.]+)`, 'm');
63
+ const match = text.match(regex);
64
+ return match ? parseFloat(match[1]) : 0;
65
+ }
66
+ /**
67
+ * Calculate TPS from Prometheus metrics
68
+ *
69
+ * @param text - Prometheus-formatted metrics text
70
+ * @returns Calculated TPS value
71
+ */
72
+ function calculateTps(text) {
73
+ // Use the request count and latency to estimate TPS
74
+ const requestCount = extractMetricValue(text, "nord_requests_ok_count");
75
+ const latencySum = extractSummaryValue(text, "nord_requests_ok_latency_sum");
76
+ const latencyCount = extractSummaryValue(text, "nord_requests_ok_latency_count");
77
+ if (latencySum > 0 && latencyCount > 0) {
78
+ // Average latency in seconds
79
+ const avgLatency = latencySum / latencyCount;
80
+ // If we have valid latency data, estimate TPS as requests per second
81
+ return avgLatency > 0 ? requestCount / (latencyCount * avgLatency) : 0;
82
+ }
83
+ // Fallback: just return a small fraction of the total request count
84
+ return requestCount > 0 ? requestCount / 100 : 0;
85
+ }
86
+ /**
87
+ * Calculate peak TPS from Prometheus metrics
88
+ *
89
+ * @param text - Prometheus-formatted metrics text
90
+ * @returns Calculated peak TPS value
91
+ */
92
+ function calculatePeakTps(text) {
93
+ // For peak TPS, we'll use a simple heuristic: 2x the current TPS estimate
94
+ return calculateTps(text) * 2;
95
+ }
96
+ /**
97
+ * Extract latency from Prometheus metrics
98
+ *
99
+ * @param text - Prometheus-formatted metrics text
100
+ * @returns Average latency in seconds
101
+ */
102
+ function extractLatency(text) {
103
+ const latencySum = extractSummaryValue(text, "nord_requests_ok_latency_sum");
104
+ const latencyCount = extractSummaryValue(text, "nord_requests_ok_latency_count");
105
+ return latencyCount > 0 ? latencySum / latencyCount : 0;
106
+ }
107
+ /**
108
+ * Extract a summary value from Prometheus-formatted text
109
+ *
110
+ * @param text - Prometheus-formatted metrics text
111
+ * @param metricName - Name of the metric to extract
112
+ * @returns The metric value as a number, or 0 if not found
113
+ */
114
+ function extractSummaryValue(text, metricName) {
115
+ const regex = new RegExp(`^${metricName}\\s+([\\d.]+)`, 'm');
116
+ const match = text.match(regex);
117
+ return match ? parseFloat(match[1]) : 0;
118
+ }
44
119
  /**
45
120
  * Get current transactions per second
46
121
  *
@@ -51,7 +126,8 @@ async function aggregateMetrics(webServerUrl, txPeakTpsPeriod = 1, txPeakTpsPeri
51
126
  */
52
127
  async function getCurrentTps(webServerUrl, period = "1m") {
53
128
  try {
54
- return await queryPrometheus(webServerUrl, `sum(rate(nord_tx_count[${period}]))`);
129
+ // nord_tx_count doesn't exist in the metrics, use nord_requests_ok_count instead
130
+ return await queryPrometheus(webServerUrl, `sum(rate(nord_requests_ok_count[${period}]))`);
55
131
  }
56
132
  catch (error) {
57
133
  throw new NordError_1.NordError(`Failed to get current TPS for period ${period}`, {
@@ -69,7 +145,8 @@ async function getCurrentTps(webServerUrl, period = "1m") {
69
145
  */
70
146
  async function getPeakTps(webServerUrl, period = "24h") {
71
147
  try {
72
- return await queryPrometheus(webServerUrl, `max_over_time(sum(rate(nord_tx_count[1m]))[${period}:])`);
148
+ // nord_tx_count doesn't exist in the metrics, use nord_requests_ok_count instead
149
+ return await queryPrometheus(webServerUrl, `max_over_time(sum(rate(nord_requests_ok_count[1m]))[${period}:])`);
73
150
  }
74
151
  catch (error) {
75
152
  throw new NordError_1.NordError(`Failed to get peak TPS for period ${period}`, {
@@ -87,7 +164,9 @@ async function getPeakTps(webServerUrl, period = "24h") {
87
164
  */
88
165
  async function getMedianLatency(webServerUrl, period = "1m") {
89
166
  try {
90
- return await queryPrometheus(webServerUrl, `quantile_over_time(0.5, nord_tx_latency_ms[${period}])`);
167
+ // nord_tx_latency_ms doesn't exist, use nord_requests_ok_latency instead
168
+ // which contains the latency data in the summary metric
169
+ return await queryPrometheus(webServerUrl, `quantile_over_time(0.5, nord_requests_ok_latency[${period}]) * 1000`);
91
170
  }
92
171
  catch (error) {
93
172
  throw new NordError_1.NordError(`Failed to get median latency for period ${period}`, {
@@ -104,7 +183,8 @@ async function getMedianLatency(webServerUrl, period = "1m") {
104
183
  */
105
184
  async function getTotalTransactions(webServerUrl) {
106
185
  try {
107
- return await queryPrometheus(webServerUrl, "sum(nord_tx_count)");
186
+ // nord_tx_count doesn't exist, use nord_requests_ok_count instead
187
+ return await queryPrometheus(webServerUrl, "sum(nord_requests_ok_count)");
108
188
  }
109
189
  catch (error) {
110
190
  throw new NordError_1.NordError("Failed to get total transactions", { cause: error });
@@ -121,8 +201,22 @@ async function getTotalTransactions(webServerUrl) {
121
201
  async function queryPrometheus(webServerUrl, params) {
122
202
  try {
123
203
  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;
204
+ // Handle raw text response
205
+ const text = await response.text();
206
+ try {
207
+ // Try to parse as JSON first
208
+ const data = JSON.parse(text);
209
+ return data.data.result[0]?.value[1] || 0;
210
+ }
211
+ catch (e) {
212
+ // Try to find a number in the response
213
+ const numberMatch = text.match(/[\d.]+/);
214
+ if (numberMatch) {
215
+ return parseFloat(numberMatch[0]);
216
+ }
217
+ // Return 0 if no number is found
218
+ return 0;
219
+ }
126
220
  }
127
221
  catch (error) {
128
222
  throw new NordError_1.NordError(`Failed to query Prometheus: ${params}`, {