@n1xyz/nord-ts 0.0.8 → 0.0.9
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/idl/bridge.js +237 -10
- package/dist/nord/api/queries.d.ts +7 -42
- package/dist/nord/api/queries.js +15 -93
- package/dist/nord/client/Nord.d.ts +11 -42
- package/dist/nord/client/Nord.js +13 -52
- package/package.json +1 -1
- package/src/idl/bridge.ts +238 -11
- package/src/nord/api/queries.ts +16 -113
- package/src/nord/client/Nord.ts +15 -64
- package/test.ts +50 -23
package/src/nord/client/Nord.ts
CHANGED
|
@@ -5,9 +5,6 @@ import {
|
|
|
5
5
|
ActionResponse,
|
|
6
6
|
ActionsResponse,
|
|
7
7
|
AggregateMetrics,
|
|
8
|
-
BlockQuery,
|
|
9
|
-
BlockResponse,
|
|
10
|
-
BlockSummaryResponse,
|
|
11
8
|
Info,
|
|
12
9
|
Market,
|
|
13
10
|
MarketsStatsResponse,
|
|
@@ -17,12 +14,11 @@ import {
|
|
|
17
14
|
PeakTpsPeriodUnit,
|
|
18
15
|
RollmanActionResponse,
|
|
19
16
|
RollmanActionsResponse,
|
|
20
|
-
RollmanBlockResponse,
|
|
21
17
|
Token,
|
|
22
18
|
TradesQuery,
|
|
23
19
|
TradesResponse,
|
|
24
20
|
UserAccountIdsQuery,
|
|
25
|
-
UserAccountIdsResponse
|
|
21
|
+
UserAccountIdsResponse
|
|
26
22
|
} from "../../types";
|
|
27
23
|
import { NordWebSocketClient } from "../../websocket/index";
|
|
28
24
|
import * as core from "../api/core";
|
|
@@ -240,38 +236,6 @@ export class Nord {
|
|
|
240
236
|
return market.marketsStats(this.webServerUrl);
|
|
241
237
|
}
|
|
242
238
|
|
|
243
|
-
/**
|
|
244
|
-
* Query a specific block
|
|
245
|
-
*
|
|
246
|
-
* @param query - Block query parameters
|
|
247
|
-
* @returns Block response
|
|
248
|
-
* @throws {NordError} If the request fails
|
|
249
|
-
*/
|
|
250
|
-
async queryBlock(query: BlockQuery): Promise<BlockResponse> {
|
|
251
|
-
return queries.queryBlock(this.webServerUrl, query);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Query the last N blocks
|
|
256
|
-
*
|
|
257
|
-
* @returns Block response for the last N blocks
|
|
258
|
-
* @throws {NordError} If the request fails
|
|
259
|
-
*/
|
|
260
|
-
async queryLastNBlocks(): Promise<BlockResponse> {
|
|
261
|
-
return queries.queryLastNBlocks(this.webServerUrl);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Query recent blocks
|
|
266
|
-
*
|
|
267
|
-
* @param last_n - Number of recent blocks to query
|
|
268
|
-
* @returns Block summary response
|
|
269
|
-
* @throws {NordError} If the request fails
|
|
270
|
-
*/
|
|
271
|
-
async queryRecentBlocks(last_n: number): Promise<BlockSummaryResponse> {
|
|
272
|
-
return queries.queryRecentBlocks(this.webServerUrl, last_n);
|
|
273
|
-
}
|
|
274
|
-
|
|
275
239
|
/**
|
|
276
240
|
* Query a specific action
|
|
277
241
|
*
|
|
@@ -286,14 +250,25 @@ export class Nord {
|
|
|
286
250
|
/**
|
|
287
251
|
* Query recent actions
|
|
288
252
|
*
|
|
289
|
-
* @param
|
|
253
|
+
* @param from - Starting action index
|
|
254
|
+
* @param to - Ending action index
|
|
290
255
|
* @returns Actions response
|
|
291
256
|
* @throws {NordError} If the request fails
|
|
292
257
|
*/
|
|
293
|
-
async queryRecentActions(
|
|
294
|
-
return queries.queryRecentActions(this.webServerUrl,
|
|
258
|
+
async queryRecentActions(from: number, to: number): Promise<ActionsResponse> {
|
|
259
|
+
return queries.queryRecentActions(this.webServerUrl, from, to);
|
|
295
260
|
}
|
|
296
261
|
|
|
262
|
+
/**
|
|
263
|
+
* Get the last action ID
|
|
264
|
+
*
|
|
265
|
+
* @returns Last action ID
|
|
266
|
+
* @throws {NordError} If the request fails
|
|
267
|
+
*/
|
|
268
|
+
async getLastActionId(): Promise<number> {
|
|
269
|
+
return queries.getLastActionId(this.webServerUrl);
|
|
270
|
+
}
|
|
271
|
+
|
|
297
272
|
/**
|
|
298
273
|
* Fetch aggregate metrics from the Nord API
|
|
299
274
|
*
|
|
@@ -356,30 +331,6 @@ export class Nord {
|
|
|
356
331
|
return metrics.getTotalTransactions(this.webServerUrl);
|
|
357
332
|
}
|
|
358
333
|
|
|
359
|
-
/**
|
|
360
|
-
* Query a block from Rollman
|
|
361
|
-
*
|
|
362
|
-
* @param query - Block query parameters
|
|
363
|
-
* @returns Rollman block response
|
|
364
|
-
* @throws {NordError} If the request fails
|
|
365
|
-
*/
|
|
366
|
-
async blockQueryRollman(query: BlockQuery): Promise<RollmanBlockResponse> {
|
|
367
|
-
return queries.blockQueryRollman(this.webServerUrl, query);
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* Query block summaries from Rollman
|
|
372
|
-
*
|
|
373
|
-
* @param last_n - Number of recent blocks to query
|
|
374
|
-
* @returns Block summary response
|
|
375
|
-
* @throws {NordError} If the request fails
|
|
376
|
-
*/
|
|
377
|
-
async blockSummaryQueryRollman(
|
|
378
|
-
last_n: number,
|
|
379
|
-
): Promise<BlockSummaryResponse> {
|
|
380
|
-
return queries.blockSummaryQueryRollman(this.webServerUrl, last_n);
|
|
381
|
-
}
|
|
382
|
-
|
|
383
334
|
/**
|
|
384
335
|
* Query an action from Rollman
|
|
385
336
|
*
|
package/test.ts
CHANGED
|
@@ -1,32 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
getCurrentTps,
|
|
4
|
-
getPeakTps,
|
|
5
|
-
getMedianLatency,
|
|
6
|
-
getTotalTransactions,
|
|
7
|
-
queryPrometheus,
|
|
8
|
-
MetricPeriod
|
|
9
|
-
} from './src/nord/api/metrics';
|
|
1
|
+
import { Nord } from './src/nord/client/Nord';
|
|
2
|
+
import { MetricPeriod } from './src/nord/api/metrics';
|
|
10
3
|
import { PeakTpsPeriodUnit } from './src/types';
|
|
11
4
|
|
|
12
|
-
//
|
|
13
|
-
const
|
|
5
|
+
// Configuration for Nord client
|
|
6
|
+
const NORD_CONFIG = {
|
|
7
|
+
webServerUrl: 'https://zo-devnet.n1.xyz',
|
|
8
|
+
solanaProgramId: 'nord1111111111111111111111111111111111111',
|
|
9
|
+
solanaUrl: 'https://api.devnet.solana.com',
|
|
10
|
+
initWebSockets: false // We don't need WebSockets for these tests
|
|
11
|
+
};
|
|
14
12
|
|
|
15
13
|
// Function to run all tests
|
|
16
14
|
async function runTests() {
|
|
17
|
-
console.log('Testing Nord
|
|
15
|
+
console.log('Testing Nord API with URL:', NORD_CONFIG.webServerUrl);
|
|
18
16
|
console.log('----------------------------------------');
|
|
19
17
|
|
|
20
18
|
try {
|
|
19
|
+
// Initialize Nord client
|
|
20
|
+
console.log('\nInitializing Nord client...');
|
|
21
|
+
const nord = await Nord.initNord(NORD_CONFIG);
|
|
22
|
+
console.log('Nord client initialized successfully');
|
|
23
|
+
|
|
21
24
|
// Test aggregateMetrics
|
|
22
25
|
console.log('\n1. Testing aggregateMetrics:');
|
|
23
|
-
const metrics = await aggregateMetrics(
|
|
26
|
+
const metrics = await nord.aggregateMetrics();
|
|
24
27
|
console.log('Aggregate Metrics:', JSON.stringify(metrics, null, 2));
|
|
25
28
|
|
|
26
29
|
// Test with custom parameters
|
|
27
30
|
console.log('\nTesting aggregateMetrics with custom parameters:');
|
|
28
|
-
const customMetrics = await aggregateMetrics(
|
|
29
|
-
NORD_URL,
|
|
31
|
+
const customMetrics = await nord.aggregateMetrics(
|
|
30
32
|
3,
|
|
31
33
|
PeakTpsPeriodUnit.Hour
|
|
32
34
|
);
|
|
@@ -34,39 +36,64 @@ async function runTests() {
|
|
|
34
36
|
|
|
35
37
|
// Test getCurrentTps
|
|
36
38
|
console.log('\n2. Testing getCurrentTps:');
|
|
37
|
-
const tps1m = await getCurrentTps(
|
|
39
|
+
const tps1m = await nord.getCurrentTps(MetricPeriod.ONE_MINUTE);
|
|
38
40
|
console.log(`Current TPS (1m): ${tps1m}`);
|
|
39
41
|
|
|
40
|
-
const tps5m = await getCurrentTps(
|
|
42
|
+
const tps5m = await nord.getCurrentTps(MetricPeriod.FIVE_MINUTES);
|
|
41
43
|
console.log(`Current TPS (5m): ${tps5m}`);
|
|
42
44
|
|
|
43
45
|
// Test getPeakTps
|
|
44
46
|
console.log('\n3. Testing getPeakTps:');
|
|
45
|
-
const peakTps24h = await getPeakTps(
|
|
47
|
+
const peakTps24h = await nord.getPeakTps(MetricPeriod.ONE_DAY);
|
|
46
48
|
console.log(`Peak TPS (24h): ${peakTps24h}`);
|
|
47
49
|
|
|
48
|
-
const peakTps1w = await getPeakTps(
|
|
50
|
+
const peakTps1w = await nord.getPeakTps(MetricPeriod.ONE_WEEK);
|
|
49
51
|
console.log(`Peak TPS (1w): ${peakTps1w}`);
|
|
50
52
|
|
|
51
53
|
// Test getMedianLatency
|
|
52
54
|
console.log('\n4. Testing getMedianLatency:');
|
|
53
|
-
const medianLatency1m = await getMedianLatency(
|
|
55
|
+
const medianLatency1m = await nord.getMedianLatency(MetricPeriod.ONE_MINUTE);
|
|
54
56
|
console.log(`Median Latency (1m): ${medianLatency1m} ms`);
|
|
55
57
|
|
|
56
|
-
const medianLatency1h = await getMedianLatency(
|
|
58
|
+
const medianLatency1h = await nord.getMedianLatency(MetricPeriod.ONE_HOUR);
|
|
57
59
|
console.log(`Median Latency (1h): ${medianLatency1h} ms`);
|
|
58
60
|
|
|
59
61
|
// Test getTotalTransactions
|
|
60
62
|
console.log('\n5. Testing getTotalTransactions:');
|
|
61
|
-
const totalTx = await getTotalTransactions(
|
|
63
|
+
const totalTx = await nord.getTotalTransactions();
|
|
62
64
|
console.log(`Total Transactions: ${totalTx}`);
|
|
63
65
|
|
|
64
66
|
// Test queryPrometheus with a custom query
|
|
65
67
|
console.log('\n6. Testing queryPrometheus with custom query:');
|
|
66
68
|
const customQuery = 'sum(rate(nord_requests_ok_count[15m]))';
|
|
67
|
-
const customQueryResult = await queryPrometheus(
|
|
69
|
+
const customQueryResult = await nord.queryPrometheus(customQuery);
|
|
68
70
|
console.log(`Custom Query Result (${customQuery}): ${customQueryResult}`);
|
|
69
71
|
|
|
72
|
+
// Test getLastActionId
|
|
73
|
+
console.log('\n7. Testing getLastActionId:');
|
|
74
|
+
const lastActionId = await nord.getLastActionId();
|
|
75
|
+
console.log(`Last Action ID: ${lastActionId}`);
|
|
76
|
+
|
|
77
|
+
// Test queryRecentActions
|
|
78
|
+
console.log('\n8. Testing queryRecentActions:');
|
|
79
|
+
// Get 10 recent actions starting from 0
|
|
80
|
+
const recentActions = await nord.queryRecentActions(0, 10);
|
|
81
|
+
console.log(`Recent Actions (from 0 to 10):`);
|
|
82
|
+
console.log(JSON.stringify(recentActions, null, 2));
|
|
83
|
+
|
|
84
|
+
// Test queryActionsRange
|
|
85
|
+
console.log('\n9. Testing queryActionsRange:');
|
|
86
|
+
// If lastActionId is available, use it to get a range of actions
|
|
87
|
+
if (lastActionId > 10) {
|
|
88
|
+
const fromId = Math.max(0, lastActionId - 10);
|
|
89
|
+
const toId = lastActionId;
|
|
90
|
+
const actionsRange = await nord.queryRecentActions(fromId, toId);
|
|
91
|
+
console.log(`Actions Range (from ${fromId} to ${toId}):`);
|
|
92
|
+
console.log(JSON.stringify(actionsRange, null, 2));
|
|
93
|
+
} else {
|
|
94
|
+
console.log('Not enough actions to demonstrate range query');
|
|
95
|
+
}
|
|
96
|
+
|
|
70
97
|
} catch (error) {
|
|
71
98
|
console.error('Error running tests:', error);
|
|
72
99
|
}
|