@n1xyz/nord-ts 0.0.7 → 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.
Files changed (151) hide show
  1. package/dist/gen/common.js +1 -1
  2. package/dist/gen/nord.js +1 -1
  3. package/dist/idl/bridge.js +237 -10
  4. package/dist/nord/api/metrics.js +101 -7
  5. package/dist/nord/api/queries.d.ts +7 -42
  6. package/dist/nord/api/queries.js +15 -93
  7. package/dist/nord/client/Nord.d.ts +11 -42
  8. package/dist/nord/client/Nord.js +13 -52
  9. package/docs/classes/Nord.html +41 -41
  10. package/docs/classes/NordError.html +8 -8
  11. package/docs/classes/NordUser.html +37 -37
  12. package/docs/classes/NordWebSocketClient.html +34 -34
  13. package/docs/classes/SolanaBridgeClient.html +22 -22
  14. package/docs/classes/Subscriber.html +3 -3
  15. package/docs/enums/FillMode.html +2 -2
  16. package/docs/enums/KeyType.html +2 -2
  17. package/docs/enums/MetricPeriod.html +2 -2
  18. package/docs/enums/PdaSeedType.html +2 -2
  19. package/docs/enums/PeakTpsPeriodUnit.html +2 -2
  20. package/docs/enums/Side.html +2 -2
  21. package/docs/enums/WebSocketMessageType.html +2 -2
  22. package/docs/functions/actionQueryRollman.html +1 -1
  23. package/docs/functions/actionsQueryRollman.html +1 -1
  24. package/docs/functions/aggregateMetrics-1.html +1 -1
  25. package/docs/functions/assert.html +1 -1
  26. package/docs/functions/bigIntToProtoU128.html +1 -1
  27. package/docs/functions/blockQueryRollman.html +1 -1
  28. package/docs/functions/blockSummaryQueryRollman.html +1 -1
  29. package/docs/functions/bridgeToBN.html +1 -1
  30. package/docs/functions/bufferToHex.html +1 -1
  31. package/docs/functions/cancelOrder.html +1 -1
  32. package/docs/functions/checkPubKeyLength.html +1 -1
  33. package/docs/functions/checkedFetch.html +1 -1
  34. package/docs/functions/createSession.html +1 -1
  35. package/docs/functions/decodeLengthDelimited.html +1 -1
  36. package/docs/functions/encodeLengthDelimited.html +1 -1
  37. package/docs/functions/fillModeToProtoFillMode.html +1 -1
  38. package/docs/functions/findMarket.html +1 -1
  39. package/docs/functions/findPda.html +1 -1
  40. package/docs/functions/findToken.html +1 -1
  41. package/docs/functions/fromBN.html +1 -1
  42. package/docs/functions/getAccount.html +1 -1
  43. package/docs/functions/getActionNonce.html +1 -1
  44. package/docs/functions/getCurrentTps.html +1 -1
  45. package/docs/functions/getInfo.html +1 -1
  46. package/docs/functions/getMedianLatency.html +1 -1
  47. package/docs/functions/getOrderbook.html +1 -1
  48. package/docs/functions/getPeakTps.html +1 -1
  49. package/docs/functions/getTimestamp.html +1 -1
  50. package/docs/functions/getTotalTransactions.html +1 -1
  51. package/docs/functions/getTrades.html +1 -1
  52. package/docs/functions/getUserAccountIds.html +1 -1
  53. package/docs/functions/hexToBuffer.html +1 -1
  54. package/docs/functions/initWebSocketClient.html +1 -1
  55. package/docs/functions/keypairFromPrivateKey.html +1 -1
  56. package/docs/functions/makeSigningFunction.html +1 -1
  57. package/docs/functions/makeWalletSignFn.html +1 -1
  58. package/docs/functions/marketsStats.html +1 -1
  59. package/docs/functions/optExpect.html +1 -1
  60. package/docs/functions/optMap.html +1 -1
  61. package/docs/functions/optUnwrap.html +1 -1
  62. package/docs/functions/panic.html +1 -1
  63. package/docs/functions/placeOrder.html +1 -1
  64. package/docs/functions/queryAction.html +1 -1
  65. package/docs/functions/queryBlock.html +1 -1
  66. package/docs/functions/queryLastNBlocks.html +1 -1
  67. package/docs/functions/queryPrometheus.html +1 -1
  68. package/docs/functions/queryRecentActions.html +1 -1
  69. package/docs/functions/queryRecentBlocks.html +1 -1
  70. package/docs/functions/revokeSession.html +1 -1
  71. package/docs/functions/shortenPublicKey.html +1 -1
  72. package/docs/functions/signAction.html +1 -1
  73. package/docs/functions/toBN.html +1 -1
  74. package/docs/functions/toScaledU128.html +1 -1
  75. package/docs/functions/toScaledU64.html +1 -1
  76. package/docs/functions/transfer.html +1 -1
  77. package/docs/functions/withdraw.html +1 -1
  78. package/docs/interfaces/Account.html +2 -2
  79. package/docs/interfaces/ActionInfo.html +2 -2
  80. package/docs/interfaces/ActionNonceResponse.html +2 -2
  81. package/docs/interfaces/ActionQuery.html +2 -2
  82. package/docs/interfaces/ActionResponse.html +2 -2
  83. package/docs/interfaces/ActionsExtendedInfo.html +2 -2
  84. package/docs/interfaces/ActionsQuery.html +2 -2
  85. package/docs/interfaces/ActionsResponse.html +2 -2
  86. package/docs/interfaces/AggregateMetrics.html +2 -2
  87. package/docs/interfaces/BlockFacts.html +5 -5
  88. package/docs/interfaces/BlockQuery.html +2 -2
  89. package/docs/interfaces/BlockResponse.html +2 -2
  90. package/docs/interfaces/BlockSummary.html +2 -2
  91. package/docs/interfaces/BlockSummaryResponse.html +2 -2
  92. package/docs/interfaces/DeltaEvent.html +2 -2
  93. package/docs/interfaces/DepositSplParams.html +5 -5
  94. package/docs/interfaces/Info.html +2 -2
  95. package/docs/interfaces/Market.html +2 -2
  96. package/docs/interfaces/MarketStats.html +2 -2
  97. package/docs/interfaces/MarketsStatsResponse.html +2 -2
  98. package/docs/interfaces/NordConfig.html +7 -7
  99. package/docs/interfaces/NordWebSocketClientEvents.html +2 -2
  100. package/docs/interfaces/NordWebSocketEvents.html +2 -2
  101. package/docs/interfaces/Order.html +2 -2
  102. package/docs/interfaces/OrderInfo.html +2 -2
  103. package/docs/interfaces/OrderbookEntry.html +2 -2
  104. package/docs/interfaces/OrderbookQuery.html +2 -2
  105. package/docs/interfaces/OrderbookResponse.html +2 -2
  106. package/docs/interfaces/OrderbookSubscription.html +18 -18
  107. package/docs/interfaces/PerpMarketStats.html +2 -2
  108. package/docs/interfaces/RollmanActionExtendedInfo.html +2 -2
  109. package/docs/interfaces/RollmanActionInfo.html +2 -2
  110. package/docs/interfaces/RollmanActionResponse.html +2 -2
  111. package/docs/interfaces/RollmanActionsResponse.html +2 -2
  112. package/docs/interfaces/RollmanBlockResponse.html +2 -2
  113. package/docs/interfaces/SPLTokenInfo.html +5 -5
  114. package/docs/interfaces/SolanaBridgeConfig.html +5 -5
  115. package/docs/interfaces/StateFacts.html +5 -5
  116. package/docs/interfaces/SubscriberConfig.html +2 -2
  117. package/docs/interfaces/TimestampResponse.html +2 -2
  118. package/docs/interfaces/Token.html +2 -2
  119. package/docs/interfaces/TokenInfo.html +2 -2
  120. package/docs/interfaces/Trade.html +2 -2
  121. package/docs/interfaces/TradeSubscription.html +18 -18
  122. package/docs/interfaces/Trades.html +2 -2
  123. package/docs/interfaces/TradesQuery.html +2 -2
  124. package/docs/interfaces/TradesResponse.html +2 -2
  125. package/docs/interfaces/TransferParams.html +4 -4
  126. package/docs/interfaces/UserAccountIdsQuery.html +2 -2
  127. package/docs/interfaces/UserAccountIdsResponse.html +2 -2
  128. package/docs/interfaces/WebSocketDeltaUpdate.html +2 -2
  129. package/docs/interfaces/WebSocketSubscription.html +2 -2
  130. package/docs/interfaces/WebSocketTradeUpdate.html +2 -2
  131. package/docs/interfaces/WebSocketUserUpdate.html +2 -2
  132. package/docs/interfaces/WithdrawalClaim.html +7 -7
  133. package/docs/interfaces/WithdrawalParams.html +4 -4
  134. package/docs/types/BigIntValue.html +1 -1
  135. package/docs/types/WebSocketMessage.html +1 -1
  136. package/docs/variables/DEBUG_KEYS.html +1 -1
  137. package/docs/variables/DEFAULT_FUNDING_AMOUNTS.html +1 -1
  138. package/docs/variables/DEV_TOKEN_INFOS.html +1 -1
  139. package/docs/variables/DEV_URL.html +1 -1
  140. package/docs/variables/MAX_BUFFER_LEN.html +1 -1
  141. package/docs/variables/SESSION_TTL.html +1 -1
  142. package/docs/variables/WEBSERVER_DEV_URL.html +1 -1
  143. package/docs/variables/ZERO_DECIMAL.html +1 -1
  144. package/docs/variables/_private.html +1 -1
  145. package/package.json +1 -1
  146. package/src/gen/common.ts +1 -1
  147. package/src/gen/nord.ts +1 -1
  148. package/src/idl/bridge.ts +238 -11
  149. package/src/nord/api/queries.ts +16 -113
  150. package/src/nord/client/Nord.ts +15 -64
  151. package/test.ts +107 -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 });
@@ -44,14 +44,13 @@ exports.BRIDGE_IDL = {
44
44
  },
45
45
  },
46
46
  {
47
- name: "asset_whitelisted",
47
+ name: "asset_config",
48
48
  pda: {
49
49
  seeds: [
50
50
  {
51
51
  kind: "const",
52
52
  value: [
53
- 97, 115, 115, 101, 116, 95, 119, 104, 105, 116, 101, 108, 105,
54
- 115, 116, 101, 100,
53
+ 97, 115, 115, 101, 116, 95, 99, 111, 110, 102, 105, 103,
55
54
  ],
56
55
  },
57
56
  {
@@ -83,6 +82,38 @@ exports.BRIDGE_IDL = {
83
82
  {
84
83
  name: "to_account",
85
84
  writable: true,
85
+ pda: {
86
+ seeds: [
87
+ {
88
+ kind: "const",
89
+ value: [
90
+ 79, 224, 127, 226, 92, 181, 26, 89, 30, 167, 10, 86, 86, 68,
91
+ 128, 20, 156, 34, 76, 69, 18, 76, 98, 233, 62, 41, 163, 58,
92
+ 15, 16, 9, 188,
93
+ ],
94
+ },
95
+ {
96
+ kind: "account",
97
+ path: "token_program",
98
+ },
99
+ {
100
+ kind: "account",
101
+ path: "from_account.mint",
102
+ },
103
+ ],
104
+ program: {
105
+ kind: "const",
106
+ value: [
107
+ 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
108
+ 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
109
+ 219, 233, 248, 89,
110
+ ],
111
+ },
112
+ },
113
+ },
114
+ {
115
+ name: "program",
116
+ address: "CVDFLCAjXhVWiPXH9nTCTpCgVzmDVoiPzNJYuccr1dqB",
86
117
  },
87
118
  {
88
119
  name: "token_program",
@@ -99,6 +130,34 @@ exports.BRIDGE_IDL = {
99
130
  },
100
131
  ],
101
132
  },
133
+ {
134
+ name: "emit_crumb",
135
+ discriminator: [96, 96, 18, 122, 83, 60, 102, 37],
136
+ accounts: [
137
+ {
138
+ name: "contract_storage",
139
+ docs: [
140
+ "Need a PDA to ensure that only this contract is allowed to",
141
+ "call this instruction; the contract storage account is",
142
+ "chosen since pretty much every other ix uses it, so this",
143
+ "avoids having to introduce a new account.",
144
+ ],
145
+ signer: true,
146
+ pda: {
147
+ seeds: [
148
+ {
149
+ kind: "const",
150
+ value: [
151
+ 99, 111, 110, 116, 114, 97, 99, 116, 95, 115, 116, 111, 114,
152
+ 97, 103, 101,
153
+ ],
154
+ },
155
+ ],
156
+ },
157
+ },
158
+ ],
159
+ args: [],
160
+ },
102
161
  {
103
162
  name: "finalize_block",
104
163
  discriminator: [63, 101, 92, 132, 135, 251, 98, 177],
@@ -141,6 +200,10 @@ exports.BRIDGE_IDL = {
141
200
  ],
142
201
  },
143
202
  },
203
+ {
204
+ name: "program",
205
+ address: "CVDFLCAjXhVWiPXH9nTCTpCgVzmDVoiPzNJYuccr1dqB",
206
+ },
144
207
  {
145
208
  name: "system_program",
146
209
  address: "11111111111111111111111111111111",
@@ -162,6 +225,20 @@ exports.BRIDGE_IDL = {
162
225
  writable: true,
163
226
  signer: true,
164
227
  },
228
+ {
229
+ name: "contract_storage",
230
+ pda: {
231
+ seeds: [
232
+ {
233
+ kind: "const",
234
+ value: [
235
+ 99, 111, 110, 116, 114, 97, 99, 116, 95, 115, 116, 111, 114,
236
+ 97, 103, 101,
237
+ ],
238
+ },
239
+ ],
240
+ },
241
+ },
165
242
  {
166
243
  name: "fact_state_storage",
167
244
  writable: true,
@@ -181,6 +258,10 @@ exports.BRIDGE_IDL = {
181
258
  ],
182
259
  },
183
260
  },
261
+ {
262
+ name: "program",
263
+ address: "CVDFLCAjXhVWiPXH9nTCTpCgVzmDVoiPzNJYuccr1dqB",
264
+ },
184
265
  {
185
266
  name: "system_program",
186
267
  address: "11111111111111111111111111111111",
@@ -234,6 +315,10 @@ exports.BRIDGE_IDL = {
234
315
  name: "operator",
235
316
  type: "pubkey",
236
317
  },
318
+ {
319
+ name: "challenge_period_slots",
320
+ type: "u64",
321
+ },
237
322
  {
238
323
  name: "initial_app_state_commitment",
239
324
  type: {
@@ -292,6 +377,10 @@ exports.BRIDGE_IDL = {
292
377
  ],
293
378
  },
294
379
  },
380
+ {
381
+ name: "program",
382
+ address: "CVDFLCAjXhVWiPXH9nTCTpCgVzmDVoiPzNJYuccr1dqB",
383
+ },
295
384
  {
296
385
  name: "system_program",
297
386
  address: "11111111111111111111111111111111",
@@ -308,6 +397,62 @@ exports.BRIDGE_IDL = {
308
397
  },
309
398
  ],
310
399
  },
400
+ {
401
+ name: "set_min_deposit",
402
+ discriminator: [15, 182, 74, 248, 251, 148, 186, 171],
403
+ accounts: [
404
+ {
405
+ name: "operator",
406
+ signer: true,
407
+ },
408
+ {
409
+ name: "contract_storage",
410
+ pda: {
411
+ seeds: [
412
+ {
413
+ kind: "const",
414
+ value: [
415
+ 99, 111, 110, 116, 114, 97, 99, 116, 95, 115, 116, 111, 114,
416
+ 97, 103, 101,
417
+ ],
418
+ },
419
+ ],
420
+ },
421
+ },
422
+ {
423
+ name: "asset_config",
424
+ writable: true,
425
+ pda: {
426
+ seeds: [
427
+ {
428
+ kind: "const",
429
+ value: [
430
+ 97, 115, 115, 101, 116, 95, 99, 111, 110, 102, 105, 103,
431
+ ],
432
+ },
433
+ {
434
+ kind: "arg",
435
+ path: "asset",
436
+ },
437
+ ],
438
+ },
439
+ },
440
+ {
441
+ name: "program",
442
+ address: "CVDFLCAjXhVWiPXH9nTCTpCgVzmDVoiPzNJYuccr1dqB",
443
+ },
444
+ ],
445
+ args: [
446
+ {
447
+ name: "asset",
448
+ type: "pubkey",
449
+ },
450
+ {
451
+ name: "min_deposit",
452
+ type: "u64",
453
+ },
454
+ ],
455
+ },
311
456
  {
312
457
  name: "whitelist_asset",
313
458
  discriminator: [113, 64, 172, 191, 33, 33, 57, 18],
@@ -332,15 +477,14 @@ exports.BRIDGE_IDL = {
332
477
  },
333
478
  },
334
479
  {
335
- name: "asset_whitelisted",
480
+ name: "asset_config",
336
481
  writable: true,
337
482
  pda: {
338
483
  seeds: [
339
484
  {
340
485
  kind: "const",
341
486
  value: [
342
- 97, 115, 115, 101, 116, 95, 119, 104, 105, 116, 101, 108, 105,
343
- 115, 116, 101, 100,
487
+ 97, 115, 115, 101, 116, 95, 99, 111, 110, 102, 105, 103,
344
488
  ],
345
489
  },
346
490
  {
@@ -350,6 +494,10 @@ exports.BRIDGE_IDL = {
350
494
  ],
351
495
  },
352
496
  },
497
+ {
498
+ name: "program",
499
+ address: "CVDFLCAjXhVWiPXH9nTCTpCgVzmDVoiPzNJYuccr1dqB",
500
+ },
353
501
  {
354
502
  name: "system_program",
355
503
  address: "11111111111111111111111111111111",
@@ -360,6 +508,10 @@ exports.BRIDGE_IDL = {
360
508
  name: "asset",
361
509
  type: "pubkey",
362
510
  },
511
+ {
512
+ name: "min_deposit",
513
+ type: "u64",
514
+ },
363
515
  ],
364
516
  },
365
517
  {
@@ -414,6 +566,34 @@ exports.BRIDGE_IDL = {
414
566
  {
415
567
  name: "from_account",
416
568
  writable: true,
569
+ pda: {
570
+ seeds: [
571
+ {
572
+ kind: "const",
573
+ value: [
574
+ 79, 224, 127, 226, 92, 181, 26, 89, 30, 167, 10, 86, 86, 68,
575
+ 128, 20, 156, 34, 76, 69, 18, 76, 98, 233, 62, 41, 163, 58,
576
+ 15, 16, 9, 188,
577
+ ],
578
+ },
579
+ {
580
+ kind: "account",
581
+ path: "token_program",
582
+ },
583
+ {
584
+ kind: "account",
585
+ path: "to_account.mint",
586
+ },
587
+ ],
588
+ program: {
589
+ kind: "const",
590
+ value: [
591
+ 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
592
+ 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
593
+ 219, 233, 248, 89,
594
+ ],
595
+ },
596
+ },
417
597
  },
418
598
  {
419
599
  name: "to_account",
@@ -430,6 +610,24 @@ exports.BRIDGE_IDL = {
430
610
  ],
431
611
  },
432
612
  },
613
+ {
614
+ name: "contract_storage",
615
+ pda: {
616
+ seeds: [
617
+ {
618
+ kind: "const",
619
+ value: [
620
+ 99, 111, 110, 116, 114, 97, 99, 116, 95, 115, 116, 111, 114,
621
+ 97, 103, 101,
622
+ ],
623
+ },
624
+ ],
625
+ },
626
+ },
627
+ {
628
+ name: "program",
629
+ address: "CVDFLCAjXhVWiPXH9nTCTpCgVzmDVoiPzNJYuccr1dqB",
630
+ },
433
631
  {
434
632
  name: "token_program",
435
633
  },
@@ -452,8 +650,8 @@ exports.BRIDGE_IDL = {
452
650
  ],
453
651
  accounts: [
454
652
  {
455
- name: "AssetWhitelisted",
456
- discriminator: [170, 42, 144, 120, 189, 54, 255, 166],
653
+ name: "AssetConfig",
654
+ discriminator: [57, 112, 247, 166, 247, 64, 140, 23],
457
655
  },
458
656
  {
459
657
  name: "Block",
@@ -478,10 +676,15 @@ exports.BRIDGE_IDL = {
478
676
  ],
479
677
  types: [
480
678
  {
481
- name: "AssetWhitelisted",
679
+ name: "AssetConfig",
482
680
  type: {
483
681
  kind: "struct",
484
- fields: [],
682
+ fields: [
683
+ {
684
+ name: "min_deposit",
685
+ type: "u64",
686
+ },
687
+ ],
485
688
  },
486
689
  },
487
690
  {
@@ -501,6 +704,10 @@ exports.BRIDGE_IDL = {
501
704
  name: "finalized",
502
705
  type: "bool",
503
706
  },
707
+ {
708
+ name: "slot_proposed",
709
+ type: "u64",
710
+ },
504
711
  ],
505
712
  },
506
713
  },
@@ -549,6 +756,10 @@ exports.BRIDGE_IDL = {
549
756
  name: "operator",
550
757
  type: "pubkey",
551
758
  },
759
+ {
760
+ name: "challenge_period_slots",
761
+ type: "u64",
762
+ },
552
763
  {
553
764
  name: "last_block_id",
554
765
  type: "u64",
@@ -689,6 +900,22 @@ exports.BRIDGE_IDL = {
689
900
  name: "block_id",
690
901
  type: "u64",
691
902
  },
903
+ {
904
+ name: "proof",
905
+ type: {
906
+ vec: {
907
+ array: ["u8", 32],
908
+ },
909
+ },
910
+ },
911
+ {
912
+ name: "leaf_index",
913
+ type: "u64",
914
+ },
915
+ {
916
+ name: "leaves_count",
917
+ type: "u64",
918
+ },
692
919
  ],
693
920
  },
694
921
  },
@@ -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}`, {
@@ -1,30 +1,4 @@
1
- import { ActionQuery, ActionResponse, ActionsResponse, BlockQuery, BlockResponse, BlockSummaryResponse, RollmanActionResponse, RollmanActionsResponse, RollmanBlockResponse } from "../../types";
2
- /**
3
- * Query a specific block
4
- *
5
- * @param webServerUrl - Base URL for the Nord web server
6
- * @param query - Block query parameters
7
- * @returns Block response
8
- * @throws {NordError} If the request fails
9
- */
10
- export declare function queryBlock(webServerUrl: string, query: BlockQuery): Promise<BlockResponse>;
11
- /**
12
- * Query the last N blocks
13
- *
14
- * @param webServerUrl - Base URL for the Nord web server
15
- * @returns Block response for the last N blocks
16
- * @throws {NordError} If the request fails
17
- */
18
- export declare function queryLastNBlocks(webServerUrl: string): Promise<BlockResponse>;
19
- /**
20
- * Query recent blocks
21
- *
22
- * @param webServerUrl - Base URL for the Nord web server
23
- * @param last_n - Number of recent blocks to query
24
- * @returns Block summary response
25
- * @throws {NordError} If the request fails
26
- */
27
- export declare function queryRecentBlocks(webServerUrl: string, last_n: number): Promise<BlockSummaryResponse>;
1
+ import { ActionQuery, ActionResponse, ActionsResponse, RollmanActionResponse, RollmanActionsResponse } from "../../types";
28
2
  /**
29
3
  * Query a specific action
30
4
  *
@@ -38,29 +12,20 @@ export declare function queryAction(webServerUrl: string, query: ActionQuery): P
38
12
  * Query recent actions
39
13
  *
40
14
  * @param webServerUrl - Base URL for the Nord web server
41
- * @param last_n - Number of recent actions to query
15
+ * @param from - Starting action index
16
+ * @param to - Ending action index
42
17
  * @returns Actions response
43
18
  * @throws {NordError} If the request fails
44
19
  */
45
- export declare function queryRecentActions(webServerUrl: string, last_n: number): Promise<ActionsResponse>;
46
- /**
47
- * Query a block from Rollman
48
- *
49
- * @param webServerUrl - Base URL for the Nord web server
50
- * @param query - Block query parameters
51
- * @returns Rollman block response
52
- * @throws {NordError} If the request fails
53
- */
54
- export declare function blockQueryRollman(webServerUrl: string, query: BlockQuery): Promise<RollmanBlockResponse>;
20
+ export declare function queryRecentActions(webServerUrl: string, from: number, to: number): Promise<ActionsResponse>;
55
21
  /**
56
- * Query block summaries from Rollman
22
+ * Get the last action ID
57
23
  *
58
24
  * @param webServerUrl - Base URL for the Nord web server
59
- * @param last_n - Number of recent blocks to query
60
- * @returns Block summary response
25
+ * @returns Last action ID
61
26
  * @throws {NordError} If the request fails
62
27
  */
63
- export declare function blockSummaryQueryRollman(webServerUrl: string, last_n: number): Promise<BlockSummaryResponse>;
28
+ export declare function getLastActionId(webServerUrl: string): Promise<number>;
64
29
  /**
65
30
  * Query an action from Rollman
66
31
  *