@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.
- package/dist/gen/common.js +1 -1
- package/dist/gen/nord.js +1 -1
- package/dist/nord/api/metrics.js +101 -7
- package/docs/classes/Nord.html +41 -41
- package/docs/classes/NordError.html +8 -8
- package/docs/classes/NordUser.html +37 -37
- package/docs/classes/NordWebSocketClient.html +34 -34
- package/docs/classes/SolanaBridgeClient.html +22 -22
- package/docs/classes/Subscriber.html +3 -3
- package/docs/enums/FillMode.html +2 -2
- package/docs/enums/KeyType.html +2 -2
- package/docs/enums/MetricPeriod.html +2 -2
- package/docs/enums/PdaSeedType.html +2 -2
- package/docs/enums/PeakTpsPeriodUnit.html +2 -2
- package/docs/enums/Side.html +2 -2
- package/docs/enums/WebSocketMessageType.html +2 -2
- package/docs/functions/actionQueryRollman.html +1 -1
- package/docs/functions/actionsQueryRollman.html +1 -1
- package/docs/functions/aggregateMetrics-1.html +1 -1
- package/docs/functions/assert.html +1 -1
- package/docs/functions/bigIntToProtoU128.html +1 -1
- package/docs/functions/blockQueryRollman.html +1 -1
- package/docs/functions/blockSummaryQueryRollman.html +1 -1
- package/docs/functions/bridgeToBN.html +1 -1
- package/docs/functions/bufferToHex.html +1 -1
- package/docs/functions/cancelOrder.html +1 -1
- package/docs/functions/checkPubKeyLength.html +1 -1
- package/docs/functions/checkedFetch.html +1 -1
- package/docs/functions/createSession.html +1 -1
- package/docs/functions/decodeLengthDelimited.html +1 -1
- package/docs/functions/encodeLengthDelimited.html +1 -1
- package/docs/functions/fillModeToProtoFillMode.html +1 -1
- package/docs/functions/findMarket.html +1 -1
- package/docs/functions/findPda.html +1 -1
- package/docs/functions/findToken.html +1 -1
- package/docs/functions/fromBN.html +1 -1
- package/docs/functions/getAccount.html +1 -1
- package/docs/functions/getActionNonce.html +1 -1
- package/docs/functions/getCurrentTps.html +1 -1
- package/docs/functions/getInfo.html +1 -1
- package/docs/functions/getMedianLatency.html +1 -1
- package/docs/functions/getOrderbook.html +1 -1
- package/docs/functions/getPeakTps.html +1 -1
- package/docs/functions/getTimestamp.html +1 -1
- package/docs/functions/getTotalTransactions.html +1 -1
- package/docs/functions/getTrades.html +1 -1
- package/docs/functions/getUserAccountIds.html +1 -1
- package/docs/functions/hexToBuffer.html +1 -1
- package/docs/functions/initWebSocketClient.html +1 -1
- package/docs/functions/keypairFromPrivateKey.html +1 -1
- package/docs/functions/makeSigningFunction.html +1 -1
- package/docs/functions/makeWalletSignFn.html +1 -1
- package/docs/functions/marketsStats.html +1 -1
- package/docs/functions/optExpect.html +1 -1
- package/docs/functions/optMap.html +1 -1
- package/docs/functions/optUnwrap.html +1 -1
- package/docs/functions/panic.html +1 -1
- package/docs/functions/placeOrder.html +1 -1
- package/docs/functions/queryAction.html +1 -1
- package/docs/functions/queryBlock.html +1 -1
- package/docs/functions/queryLastNBlocks.html +1 -1
- package/docs/functions/queryPrometheus.html +1 -1
- package/docs/functions/queryRecentActions.html +1 -1
- package/docs/functions/queryRecentBlocks.html +1 -1
- package/docs/functions/revokeSession.html +1 -1
- package/docs/functions/shortenPublicKey.html +1 -1
- package/docs/functions/signAction.html +1 -1
- package/docs/functions/toBN.html +1 -1
- package/docs/functions/toScaledU128.html +1 -1
- package/docs/functions/toScaledU64.html +1 -1
- package/docs/functions/transfer.html +1 -1
- package/docs/functions/withdraw.html +1 -1
- package/docs/interfaces/Account.html +2 -2
- package/docs/interfaces/ActionInfo.html +2 -2
- package/docs/interfaces/ActionNonceResponse.html +2 -2
- package/docs/interfaces/ActionQuery.html +2 -2
- package/docs/interfaces/ActionResponse.html +2 -2
- package/docs/interfaces/ActionsExtendedInfo.html +2 -2
- package/docs/interfaces/ActionsQuery.html +2 -2
- package/docs/interfaces/ActionsResponse.html +2 -2
- package/docs/interfaces/AggregateMetrics.html +2 -2
- package/docs/interfaces/BlockFacts.html +5 -5
- package/docs/interfaces/BlockQuery.html +2 -2
- package/docs/interfaces/BlockResponse.html +2 -2
- package/docs/interfaces/BlockSummary.html +2 -2
- package/docs/interfaces/BlockSummaryResponse.html +2 -2
- package/docs/interfaces/DeltaEvent.html +2 -2
- package/docs/interfaces/DepositSplParams.html +5 -5
- package/docs/interfaces/Info.html +2 -2
- package/docs/interfaces/Market.html +2 -2
- package/docs/interfaces/MarketStats.html +2 -2
- package/docs/interfaces/MarketsStatsResponse.html +2 -2
- package/docs/interfaces/NordConfig.html +7 -7
- package/docs/interfaces/NordWebSocketClientEvents.html +2 -2
- package/docs/interfaces/NordWebSocketEvents.html +2 -2
- package/docs/interfaces/Order.html +2 -2
- package/docs/interfaces/OrderInfo.html +2 -2
- package/docs/interfaces/OrderbookEntry.html +2 -2
- package/docs/interfaces/OrderbookQuery.html +2 -2
- package/docs/interfaces/OrderbookResponse.html +2 -2
- package/docs/interfaces/OrderbookSubscription.html +18 -18
- package/docs/interfaces/PerpMarketStats.html +2 -2
- package/docs/interfaces/RollmanActionExtendedInfo.html +2 -2
- package/docs/interfaces/RollmanActionInfo.html +2 -2
- package/docs/interfaces/RollmanActionResponse.html +2 -2
- package/docs/interfaces/RollmanActionsResponse.html +2 -2
- package/docs/interfaces/RollmanBlockResponse.html +2 -2
- package/docs/interfaces/SPLTokenInfo.html +5 -5
- package/docs/interfaces/SolanaBridgeConfig.html +5 -5
- package/docs/interfaces/StateFacts.html +5 -5
- package/docs/interfaces/SubscriberConfig.html +2 -2
- package/docs/interfaces/TimestampResponse.html +2 -2
- package/docs/interfaces/Token.html +2 -2
- package/docs/interfaces/TokenInfo.html +2 -2
- package/docs/interfaces/Trade.html +2 -2
- package/docs/interfaces/TradeSubscription.html +18 -18
- package/docs/interfaces/Trades.html +2 -2
- package/docs/interfaces/TradesQuery.html +2 -2
- package/docs/interfaces/TradesResponse.html +2 -2
- package/docs/interfaces/TransferParams.html +4 -4
- package/docs/interfaces/UserAccountIdsQuery.html +2 -2
- package/docs/interfaces/UserAccountIdsResponse.html +2 -2
- package/docs/interfaces/WebSocketDeltaUpdate.html +2 -2
- package/docs/interfaces/WebSocketSubscription.html +2 -2
- package/docs/interfaces/WebSocketTradeUpdate.html +2 -2
- package/docs/interfaces/WebSocketUserUpdate.html +2 -2
- package/docs/interfaces/WithdrawalClaim.html +7 -7
- package/docs/interfaces/WithdrawalParams.html +4 -4
- package/docs/types/BigIntValue.html +1 -1
- package/docs/types/WebSocketMessage.html +1 -1
- package/docs/variables/DEBUG_KEYS.html +1 -1
- package/docs/variables/DEFAULT_FUNDING_AMOUNTS.html +1 -1
- package/docs/variables/DEV_TOKEN_INFOS.html +1 -1
- package/docs/variables/DEV_URL.html +1 -1
- package/docs/variables/MAX_BUFFER_LEN.html +1 -1
- package/docs/variables/SESSION_TTL.html +1 -1
- package/docs/variables/WEBSERVER_DEV_URL.html +1 -1
- package/docs/variables/ZERO_DECIMAL.html +1 -1
- package/docs/variables/_private.html +1 -1
- package/package.json +1 -1
- package/src/gen/common.ts +1 -1
- package/src/gen/nord.ts +1 -1
- package/test.ts +80 -0
package/dist/gen/common.js
CHANGED
package/dist/gen/nord.js
CHANGED
package/dist/nord/api/metrics.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
125
|
-
|
|
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}`, {
|