@n1xyz/nord-ts 0.0.8 → 0.0.10
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/bridge/client.d.ts +2 -2
- package/dist/bridge/client.js +5 -5
- package/dist/bridge/types.d.ts +1 -1
- package/dist/bridge/types.js +1 -1
- package/dist/idl/bridge.js +209 -15
- 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/bridge/client.ts +5 -5
- package/src/bridge/types.ts +1 -1
- package/src/idl/bridge.ts +209 -15
- package/src/nord/api/queries.ts +16 -113
- package/src/nord/client/Nord.ts +15 -64
- package/test.ts +50 -23
package/src/nord/api/queries.ts
CHANGED
|
@@ -12,74 +12,6 @@ import {
|
|
|
12
12
|
import { checkedFetch } from "../../utils";
|
|
13
13
|
import { NordError } from "../utils/NordError";
|
|
14
14
|
|
|
15
|
-
/**
|
|
16
|
-
* Query a specific block
|
|
17
|
-
*
|
|
18
|
-
* @param webServerUrl - Base URL for the Nord web server
|
|
19
|
-
* @param query - Block query parameters
|
|
20
|
-
* @returns Block response
|
|
21
|
-
* @throws {NordError} If the request fails
|
|
22
|
-
*/
|
|
23
|
-
export async function queryBlock(
|
|
24
|
-
webServerUrl: string,
|
|
25
|
-
query: BlockQuery,
|
|
26
|
-
): Promise<BlockResponse> {
|
|
27
|
-
try {
|
|
28
|
-
const params = new URLSearchParams();
|
|
29
|
-
if (query.block_number !== undefined) {
|
|
30
|
-
params.append("block_height", query.block_number.toString());
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const response = await checkedFetch(
|
|
34
|
-
`${webServerUrl}/block?${params.toString()}`,
|
|
35
|
-
);
|
|
36
|
-
return await response.json();
|
|
37
|
-
} catch (error) {
|
|
38
|
-
throw new NordError("Failed to query block", { cause: error });
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Query the last N blocks
|
|
44
|
-
*
|
|
45
|
-
* @param webServerUrl - Base URL for the Nord web server
|
|
46
|
-
* @returns Block response for the last N blocks
|
|
47
|
-
* @throws {NordError} If the request fails
|
|
48
|
-
*/
|
|
49
|
-
export async function queryLastNBlocks(
|
|
50
|
-
webServerUrl: string,
|
|
51
|
-
): Promise<BlockResponse> {
|
|
52
|
-
try {
|
|
53
|
-
const response = await checkedFetch(`${webServerUrl}/blocks`);
|
|
54
|
-
return await response.json();
|
|
55
|
-
} catch (error) {
|
|
56
|
-
throw new NordError("Failed to query last N blocks", { cause: error });
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Query recent blocks
|
|
62
|
-
*
|
|
63
|
-
* @param webServerUrl - Base URL for the Nord web server
|
|
64
|
-
* @param last_n - Number of recent blocks to query
|
|
65
|
-
* @returns Block summary response
|
|
66
|
-
* @throws {NordError} If the request fails
|
|
67
|
-
*/
|
|
68
|
-
export async function queryRecentBlocks(
|
|
69
|
-
webServerUrl: string,
|
|
70
|
-
last_n: number,
|
|
71
|
-
): Promise<BlockSummaryResponse> {
|
|
72
|
-
try {
|
|
73
|
-
const response = await checkedFetch(
|
|
74
|
-
`${webServerUrl}/blocks_summary?last_n=${last_n}`,
|
|
75
|
-
);
|
|
76
|
-
return await response.json();
|
|
77
|
-
} catch (error) {
|
|
78
|
-
throw new NordError(`Failed to query recent blocks (last ${last_n})`, {
|
|
79
|
-
cause: error,
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
15
|
|
|
84
16
|
/**
|
|
85
17
|
* Query a specific action
|
|
@@ -112,75 +44,46 @@ export async function queryAction(
|
|
|
112
44
|
* Query recent actions
|
|
113
45
|
*
|
|
114
46
|
* @param webServerUrl - Base URL for the Nord web server
|
|
115
|
-
* @param
|
|
47
|
+
* @param from - Starting action index
|
|
48
|
+
* @param to - Ending action index
|
|
116
49
|
* @returns Actions response
|
|
117
50
|
* @throws {NordError} If the request fails
|
|
118
51
|
*/
|
|
119
52
|
export async function queryRecentActions(
|
|
120
53
|
webServerUrl: string,
|
|
121
|
-
|
|
54
|
+
from: number,
|
|
55
|
+
to: number,
|
|
122
56
|
): Promise<ActionsResponse> {
|
|
123
57
|
try {
|
|
124
58
|
const response = await checkedFetch(
|
|
125
|
-
`${webServerUrl}/actions?
|
|
59
|
+
`${webServerUrl}/actions?from=${from}&to=${to}`,
|
|
126
60
|
);
|
|
127
61
|
return await response.json();
|
|
128
62
|
} catch (error) {
|
|
129
|
-
throw new NordError(`Failed to query recent actions (
|
|
63
|
+
throw new NordError(`Failed to query recent actions (from ${from} to ${to})`, {
|
|
130
64
|
cause: error,
|
|
131
65
|
});
|
|
132
66
|
}
|
|
133
67
|
}
|
|
134
68
|
|
|
135
69
|
/**
|
|
136
|
-
*
|
|
70
|
+
* Get the last action ID
|
|
137
71
|
*
|
|
138
72
|
* @param webServerUrl - Base URL for the Nord web server
|
|
139
|
-
* @
|
|
140
|
-
* @returns Rollman block response
|
|
73
|
+
* @returns Last action ID
|
|
141
74
|
* @throws {NordError} If the request fails
|
|
142
75
|
*/
|
|
143
|
-
export async function
|
|
76
|
+
export async function getLastActionId(
|
|
144
77
|
webServerUrl: string,
|
|
145
|
-
|
|
146
|
-
): Promise<RollmanBlockResponse> {
|
|
78
|
+
): Promise<number> {
|
|
147
79
|
try {
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const response = await checkedFetch(
|
|
154
|
-
`${webServerUrl}/rollman/block?${params.toString()}`,
|
|
155
|
-
);
|
|
156
|
-
return await response.json();
|
|
80
|
+
const response = await checkedFetch(`${webServerUrl}/last_actionid`);
|
|
81
|
+
const data = await response.json();
|
|
82
|
+
return data.last_actionid;
|
|
157
83
|
} catch (error) {
|
|
158
|
-
throw new NordError("Failed to
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Query block summaries from Rollman
|
|
164
|
-
*
|
|
165
|
-
* @param webServerUrl - Base URL for the Nord web server
|
|
166
|
-
* @param last_n - Number of recent blocks to query
|
|
167
|
-
* @returns Block summary response
|
|
168
|
-
* @throws {NordError} If the request fails
|
|
169
|
-
*/
|
|
170
|
-
export async function blockSummaryQueryRollman(
|
|
171
|
-
webServerUrl: string,
|
|
172
|
-
last_n: number,
|
|
173
|
-
): Promise<BlockSummaryResponse> {
|
|
174
|
-
try {
|
|
175
|
-
const response = await checkedFetch(
|
|
176
|
-
`${webServerUrl}/rollman/blocks_summary?last_n=${last_n}`,
|
|
177
|
-
);
|
|
178
|
-
return await response.json();
|
|
179
|
-
} catch (error) {
|
|
180
|
-
throw new NordError(
|
|
181
|
-
`Failed to query Rollman block summaries (last ${last_n})`,
|
|
182
|
-
{ cause: error },
|
|
183
|
-
);
|
|
84
|
+
throw new NordError("Failed to get last action ID", {
|
|
85
|
+
cause: error,
|
|
86
|
+
});
|
|
184
87
|
}
|
|
185
88
|
}
|
|
186
89
|
|
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
|
}
|