@n1xyz/nord-ts 0.0.1 → 0.0.5
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/README.md +148 -65
- package/dist/bridge/client.d.ts +150 -0
- package/dist/bridge/client.js +394 -0
- package/dist/bridge/const.d.ts +23 -0
- package/dist/bridge/const.js +47 -0
- package/dist/bridge/index.d.ts +5 -0
- package/dist/bridge/index.js +23 -0
- package/dist/bridge/types.d.ts +118 -0
- package/dist/bridge/types.js +16 -0
- package/dist/bridge/utils.d.ts +64 -0
- package/dist/bridge/utils.js +131 -0
- package/dist/const.d.ts +2 -5
- package/dist/const.js +2 -6
- package/dist/gen/common.d.ts +6 -1
- package/dist/gen/common.js +19 -9
- package/dist/gen/nord.d.ts +76 -21
- package/dist/gen/nord.js +987 -423
- package/dist/idl/bridge.d.ts +2 -0
- package/dist/idl/bridge.js +703 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +18 -2
- package/dist/nord/{actions.d.ts → api/actions.d.ts} +6 -6
- package/dist/nord/{actions.js → api/actions.js} +6 -10
- package/dist/nord/api/core.d.ts +49 -0
- package/dist/nord/api/core.js +121 -0
- package/dist/nord/api/market.d.ts +36 -0
- package/dist/nord/api/market.js +98 -0
- package/dist/nord/api/metrics.d.ts +67 -0
- package/dist/nord/api/metrics.js +132 -0
- package/dist/nord/api/queries.d.ts +81 -0
- package/dist/nord/api/queries.js +187 -0
- package/dist/nord/client/Nord.d.ts +335 -0
- package/dist/nord/client/Nord.js +532 -0
- package/dist/nord/client/NordUser.d.ts +320 -0
- package/dist/nord/client/NordUser.js +697 -0
- package/dist/nord/index.d.ts +9 -2
- package/dist/nord/index.js +30 -6
- package/dist/nord/models/Subscriber.d.ts +37 -0
- package/dist/nord/models/Subscriber.js +25 -0
- package/dist/nord/utils/NordError.d.ts +35 -0
- package/dist/nord/utils/NordError.js +46 -0
- package/dist/types.d.ts +143 -86
- package/dist/types.js +12 -1
- package/dist/utils.d.ts +9 -0
- package/dist/utils.js +20 -1
- package/dist/websocket/NordWebSocketClient.d.ts +71 -0
- package/dist/websocket/NordWebSocketClient.js +343 -0
- package/dist/websocket/events.d.ts +19 -0
- package/dist/websocket/events.js +2 -0
- package/dist/websocket/index.d.ts +2 -0
- package/dist/websocket/index.js +5 -0
- package/docs/assets/hierarchy.js +1 -0
- package/docs/assets/highlight.css +16 -16
- package/docs/assets/icons.js +17 -14
- package/docs/assets/icons.svg +1 -1
- package/docs/assets/main.js +5 -4
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/assets/style.css +1423 -1227
- package/docs/classes/Nord.html +189 -43
- package/docs/classes/NordError.html +24 -0
- package/docs/classes/NordUser.html +120 -35
- package/docs/classes/NordWebSocketClient.html +335 -0
- package/docs/classes/SolanaBridgeClient.html +86 -0
- package/docs/classes/Subscriber.html +10 -6
- package/docs/enums/FillMode.html +5 -5
- package/docs/enums/KeyType.html +4 -4
- package/docs/enums/MetricPeriod.html +9 -0
- package/docs/enums/PdaSeedType.html +9 -0
- package/docs/enums/PeakTpsPeriodUnit.html +7 -7
- package/docs/enums/Side.html +3 -3
- package/docs/enums/WebSocketMessageType.html +7 -0
- package/docs/functions/actionQueryRollman.html +6 -0
- package/docs/functions/actionsQueryRollman.html +6 -0
- package/docs/functions/aggregateMetrics-1.html +7 -0
- package/docs/functions/assert.html +1 -1
- package/docs/functions/bigIntToProtoU128.html +3 -3
- package/docs/functions/blockQueryRollman.html +6 -0
- package/docs/functions/blockSummaryQueryRollman.html +6 -0
- package/docs/functions/bridgeToBN.html +5 -0
- package/docs/functions/bufferToHex.html +4 -0
- package/docs/functions/cancelOrder.html +1 -0
- package/docs/functions/checkPubKeyLength.html +1 -1
- package/docs/functions/checkedFetch.html +4 -4
- package/docs/functions/createSession.html +1 -0
- package/docs/functions/decodeLengthDelimited.html +7 -6
- package/docs/functions/encodeLengthDelimited.html +4 -4
- package/docs/functions/fillModeToProtoFillMode.html +4 -4
- package/docs/functions/findMarket.html +1 -1
- package/docs/functions/findPda.html +6 -0
- package/docs/functions/findToken.html +1 -1
- package/docs/functions/fromBN.html +5 -0
- package/docs/functions/getAccount.html +6 -0
- package/docs/functions/getActionNonce.html +5 -0
- package/docs/functions/getCurrentTps.html +6 -0
- package/docs/functions/getInfo.html +5 -0
- package/docs/functions/getMedianLatency.html +6 -0
- package/docs/functions/getOrderbook.html +6 -0
- package/docs/functions/getPeakTps.html +6 -0
- package/docs/functions/getTimestamp.html +5 -0
- package/docs/functions/getTotalTransactions.html +5 -0
- package/docs/functions/getTrades.html +6 -0
- package/docs/functions/getUserAccountIds.html +6 -0
- package/docs/functions/hexToBuffer.html +4 -0
- package/docs/functions/initWebSocketClient.html +12 -0
- package/docs/functions/keypairFromPrivateKey.html +4 -0
- package/docs/functions/makeSigningFunction.html +4 -0
- package/docs/functions/makeWalletSignFn.html +5 -5
- package/docs/functions/marketsStats.html +5 -0
- package/docs/functions/optExpect.html +4 -4
- package/docs/functions/optMap.html +5 -5
- package/docs/functions/optUnwrap.html +2 -2
- package/docs/functions/panic.html +1 -1
- package/docs/functions/placeOrder.html +1 -0
- package/docs/functions/queryAction.html +6 -0
- package/docs/functions/queryBlock.html +6 -0
- package/docs/functions/queryLastNBlocks.html +5 -0
- package/docs/functions/queryPrometheus.html +6 -0
- package/docs/functions/queryRecentActions.html +6 -0
- package/docs/functions/queryRecentBlocks.html +6 -0
- package/docs/functions/revokeSession.html +1 -0
- package/docs/functions/shortenPublicKey.html +5 -0
- package/docs/functions/signAction.html +2 -2
- package/docs/functions/toBN.html +5 -0
- package/docs/functions/toScaledU128.html +5 -5
- package/docs/functions/toScaledU64.html +5 -5
- package/docs/functions/transfer.html +1 -0
- package/docs/functions/withdraw.html +1 -0
- package/docs/hierarchy.html +1 -0
- package/docs/index.html +39 -20
- package/docs/interfaces/Account.html +8 -8
- package/docs/interfaces/ActionInfo.html +8 -8
- package/docs/interfaces/ActionNonceResponse.html +3 -0
- package/docs/interfaces/ActionQuery.html +4 -4
- package/docs/interfaces/ActionResponse.html +8 -8
- package/docs/interfaces/ActionsExtendedInfo.html +10 -10
- package/docs/interfaces/ActionsQuery.html +5 -5
- package/docs/interfaces/ActionsResponse.html +6 -6
- package/docs/interfaces/AggregateMetrics.html +12 -12
- package/docs/interfaces/BlockFacts.html +10 -0
- package/docs/interfaces/BlockQuery.html +6 -6
- package/docs/interfaces/BlockResponse.html +6 -6
- package/docs/interfaces/BlockSummary.html +8 -8
- package/docs/interfaces/BlockSummaryResponse.html +6 -6
- package/docs/interfaces/DeltaEvent.html +6 -6
- package/docs/interfaces/DepositSplParams.html +10 -0
- package/docs/interfaces/Info.html +3 -3
- package/docs/interfaces/Market.html +8 -6
- package/docs/interfaces/MarketStats.html +7 -7
- package/docs/interfaces/MarketsStatsResponse.html +2 -2
- package/docs/interfaces/NordConfig.html +14 -5
- package/docs/interfaces/NordWebSocketClientEvents.html +4 -0
- package/docs/interfaces/NordWebSocketEvents.html +8 -0
- package/docs/interfaces/Order.html +6 -6
- package/docs/interfaces/OrderInfo.html +6 -6
- package/docs/interfaces/OrderbookEntry.html +4 -0
- package/docs/interfaces/OrderbookQuery.html +6 -0
- package/docs/interfaces/OrderbookResponse.html +6 -10
- package/docs/interfaces/OrderbookSubscription.html +159 -0
- package/docs/interfaces/PerpMarketStats.html +5 -5
- package/docs/interfaces/RollmanActionExtendedInfo.html +4 -4
- package/docs/interfaces/RollmanActionInfo.html +4 -4
- package/docs/interfaces/RollmanActionResponse.html +4 -4
- package/docs/interfaces/RollmanActionsResponse.html +2 -2
- package/docs/interfaces/RollmanBlockResponse.html +3 -3
- package/docs/interfaces/SPLTokenInfo.html +10 -0
- package/docs/interfaces/SolanaBridgeConfig.html +10 -0
- package/docs/interfaces/StateFacts.html +10 -0
- package/docs/interfaces/SubscriberConfig.html +3 -3
- package/docs/interfaces/TimestampResponse.html +3 -0
- package/docs/interfaces/Token.html +5 -5
- package/docs/interfaces/TokenInfo.html +5 -0
- package/docs/interfaces/Trade.html +5 -5
- package/docs/interfaces/TradeSubscription.html +159 -0
- package/docs/interfaces/Trades.html +5 -5
- package/docs/interfaces/TradesQuery.html +6 -0
- package/docs/interfaces/TradesResponse.html +7 -12
- package/docs/interfaces/TransferParams.html +8 -0
- package/docs/interfaces/UserAccountIdsQuery.html +3 -0
- package/docs/interfaces/UserAccountIdsResponse.html +3 -0
- package/docs/interfaces/WebSocketDeltaUpdate.html +9 -0
- package/docs/interfaces/WebSocketSubscription.html +4 -0
- package/docs/interfaces/WebSocketTradeUpdate.html +6 -0
- package/docs/interfaces/WebSocketUserUpdate.html +6 -0
- package/docs/interfaces/WithdrawalClaim.html +14 -0
- package/docs/interfaces/WithdrawalParams.html +8 -0
- package/docs/modules.html +1 -77
- package/docs/types/BigIntValue.html +2 -2
- package/docs/types/WebSocketMessage.html +1 -0
- 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 +2 -0
- package/eslint.config.mjs +66 -0
- package/package.json +20 -23
- package/src/bridge/client.ts +487 -0
- package/src/bridge/const.ts +53 -0
- package/src/bridge/index.ts +7 -0
- package/src/bridge/types.ts +127 -0
- package/src/bridge/utils.ts +140 -0
- package/src/const.ts +4 -9
- package/src/gen/common.ts +27 -10
- package/src/gen/nord.ts +1045 -487
- package/src/idl/bridge.ts +702 -0
- package/src/index.ts +21 -2
- package/src/nord/{actions.ts → api/actions.ts} +12 -16
- package/src/nord/api/core.ts +130 -0
- package/src/nord/api/market.ts +125 -0
- package/src/nord/api/metrics.ts +154 -0
- package/src/nord/api/queries.ts +236 -0
- package/src/nord/client/Nord.ts +652 -0
- package/src/nord/client/NordUser.ts +1101 -0
- package/src/nord/index.ts +16 -2
- package/src/nord/models/Subscriber.ts +56 -0
- package/src/nord/utils/NordError.ts +72 -0
- package/src/types.ts +163 -92
- package/src/utils.ts +22 -1
- package/src/websocket/NordWebSocketClient.ts +432 -0
- package/src/websocket/events.ts +31 -0
- package/src/websocket/index.ts +2 -0
- package/tsconfig.eslint.json +12 -0
- package/.eslintignore +0 -1
- package/.eslintrc.js +0 -20
- package/dist/abis/ERC20_ABI.d.ts +0 -39
- package/dist/abis/ERC20_ABI.js +0 -313
- package/dist/abis/NORD_GETTERS_FACET_ABI.d.ts +0 -34
- package/dist/abis/NORD_GETTERS_FACET_ABI.js +0 -195
- package/dist/abis/NORD_RAMP_FACET_ABI.d.ts +0 -35
- package/dist/abis/NORD_RAMP_FACET_ABI.js +0 -144
- package/dist/abis/index.d.ts +0 -3
- package/dist/abis/index.js +0 -9
- package/dist/nord/Nord.d.ts +0 -76
- package/dist/nord/Nord.js +0 -376
- package/dist/nord/NordImpl.d.ts +0 -7
- package/dist/nord/NordImpl.js +0 -6
- package/dist/nord/NordUser.d.ts +0 -77
- package/dist/nord/NordUser.js +0 -249
- package/docs/functions/createWebSocketSubscription.html +0 -12
- package/docs/interfaces/ERC20TokenInfo.html +0 -5
- package/docs/interfaces/OrderbookOrder.html +0 -6
- package/docs/interfaces/TradeInfo.html +0 -20
- package/docs/interfaces/TradesQueryParams.html +0 -10
- package/docs/variables/DEV_CONTRACT_ADDRESS.html +0 -1
- package/docs/variables/ERC20_ABI.html +0 -1
- package/docs/variables/EVM_DEV_URL.html +0 -1
- package/docs/variables/FAUCET_PRIVATE_ADDRESS.html +0 -1
- package/docs/variables/NORD_GETTERS_FACET_ABI.html +0 -1
- package/docs/variables/NORD_RAMP_FACET_ABI.html +0 -1
- package/src/abis/ERC20_ABI.ts +0 -310
- package/src/abis/NORD_GETTERS_FACET_ABI.ts +0 -192
- package/src/abis/NORD_RAMP_FACET_ABI.ts +0 -141
- package/src/abis/index.ts +0 -3
- package/src/nord/Nord.ts +0 -504
- package/src/nord/NordImpl.ts +0 -8
- package/src/nord/NordUser.ts +0 -469
package/dist/index.js
CHANGED
|
@@ -14,8 +14,24 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.shortenPublicKey = exports.hexToBuffer = exports.bufferToHex = exports.findPda = exports.makeSigningFunction = exports.keypairFromPrivateKey = exports.fromBN = exports.bridgeToBN = void 0;
|
|
18
|
+
// Export types
|
|
17
19
|
__exportStar(require("./types"), exports);
|
|
18
20
|
__exportStar(require("./utils"), exports);
|
|
19
|
-
__exportStar(require("./abis"), exports);
|
|
20
|
-
__exportStar(require("./nord"), exports);
|
|
21
21
|
__exportStar(require("./const"), exports);
|
|
22
|
+
// Export Nord modules
|
|
23
|
+
__exportStar(require("./nord"), exports);
|
|
24
|
+
// Export WebSocket modules
|
|
25
|
+
__exportStar(require("./websocket/index"), exports);
|
|
26
|
+
// Export bridge modules
|
|
27
|
+
__exportStar(require("./bridge/client"), exports);
|
|
28
|
+
__exportStar(require("./bridge/types"), exports);
|
|
29
|
+
var utils_1 = require("./bridge/utils");
|
|
30
|
+
Object.defineProperty(exports, "bridgeToBN", { enumerable: true, get: function () { return utils_1.bridgeToBN; } });
|
|
31
|
+
Object.defineProperty(exports, "fromBN", { enumerable: true, get: function () { return utils_1.fromBN; } });
|
|
32
|
+
Object.defineProperty(exports, "keypairFromPrivateKey", { enumerable: true, get: function () { return utils_1.keypairFromPrivateKey; } });
|
|
33
|
+
Object.defineProperty(exports, "makeSigningFunction", { enumerable: true, get: function () { return utils_1.makeSigningFunction; } });
|
|
34
|
+
Object.defineProperty(exports, "findPda", { enumerable: true, get: function () { return utils_1.findPda; } });
|
|
35
|
+
Object.defineProperty(exports, "bufferToHex", { enumerable: true, get: function () { return utils_1.bufferToHex; } });
|
|
36
|
+
Object.defineProperty(exports, "hexToBuffer", { enumerable: true, get: function () { return utils_1.hexToBuffer; } });
|
|
37
|
+
Object.defineProperty(exports, "shortenPublicKey", { enumerable: true, get: function () { return utils_1.shortenPublicKey; } });
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { FillMode, Side } from "../types";
|
|
2
|
-
import { BigIntValue } from "../utils";
|
|
3
1
|
import Decimal from "decimal.js";
|
|
4
|
-
|
|
2
|
+
import { FillMode, Side } from "../../types";
|
|
3
|
+
import { BigIntValue } from "../../utils";
|
|
4
|
+
declare function createSessionImpl(sendFn: (encoded: Uint8Array) => Promise<Uint8Array>, walletSignFn: (message: string | Uint8Array) => Promise<Uint8Array>, currentTimestamp: bigint, nonce: number, params: {
|
|
5
5
|
userPubkey: Uint8Array;
|
|
6
6
|
sessionPubkey: Uint8Array;
|
|
7
7
|
expiryTimestamp?: bigint;
|
|
8
8
|
}): Promise<bigint>;
|
|
9
|
-
export declare function createSession(serverUrl: string, walletSignFn: (message: string | Uint8Array) => Promise<
|
|
9
|
+
export declare function createSession(serverUrl: string, walletSignFn: (message: string | Uint8Array) => Promise<Uint8Array>, currentTimestamp: bigint, nonce: number, params: {
|
|
10
10
|
userPubkey: Uint8Array;
|
|
11
11
|
sessionPubkey: Uint8Array;
|
|
12
12
|
expiryTimestamp?: bigint;
|
|
13
13
|
}): Promise<bigint>;
|
|
14
|
-
declare function revokeSessionImpl(sendFn: (encoded: Uint8Array) => Promise<Uint8Array>, walletSignFn: (message: string | Uint8Array) => Promise<
|
|
14
|
+
declare function revokeSessionImpl(sendFn: (encoded: Uint8Array) => Promise<Uint8Array>, walletSignFn: (message: string | Uint8Array) => Promise<Uint8Array>, currentTimestamp: bigint, nonce: number, params: {
|
|
15
15
|
sessionId: BigIntValue;
|
|
16
16
|
}): Promise<void>;
|
|
17
|
-
export declare function revokeSession(serverUrl: string, walletSignFn: (message: string | Uint8Array) => Promise<
|
|
17
|
+
export declare function revokeSession(serverUrl: string, walletSignFn: (message: string | Uint8Array) => Promise<Uint8Array>, currentTimestamp: bigint, nonce: number, params: {
|
|
18
18
|
sessionId: BigIntValue;
|
|
19
19
|
}): Promise<void>;
|
|
20
20
|
declare function withdrawImpl(sendFn: (encoded: Uint8Array) => Promise<Uint8Array>, signFn: (message: Uint8Array) => Promise<Uint8Array>, currentTimestamp: bigint, nonce: number, params: {
|
|
@@ -40,20 +40,16 @@ exports.withdraw = withdraw;
|
|
|
40
40
|
exports.placeOrder = placeOrder;
|
|
41
41
|
exports.cancelOrder = cancelOrder;
|
|
42
42
|
exports.transfer = transfer;
|
|
43
|
-
const
|
|
44
|
-
const types_1 = require("
|
|
45
|
-
const utils_1 = require("
|
|
46
|
-
const proto = __importStar(require("../gen/nord"));
|
|
43
|
+
const proto = __importStar(require("../../gen/nord"));
|
|
44
|
+
const types_1 = require("../../types");
|
|
45
|
+
const utils_1 = require("../../utils");
|
|
47
46
|
async function sessionSign(signFn, message) {
|
|
48
47
|
const signature = await signFn(message);
|
|
49
48
|
return new Uint8Array([...message, ...signature]);
|
|
50
49
|
}
|
|
51
50
|
async function walletSign(walletSignFn, message) {
|
|
52
51
|
const signature = await walletSignFn(message);
|
|
53
|
-
return new Uint8Array([
|
|
54
|
-
...message,
|
|
55
|
-
...ethers_1.ethers.getBytes(signature.slice(0, -2)),
|
|
56
|
-
]);
|
|
52
|
+
return new Uint8Array([...message, ...signature]);
|
|
57
53
|
}
|
|
58
54
|
function makeSendHttp(serverUrl) {
|
|
59
55
|
return async (body) => {
|
|
@@ -78,7 +74,7 @@ async function sendAction(sendFn, makeSignedMessage, action, actionErrorDesc) {
|
|
|
78
74
|
return resp;
|
|
79
75
|
}
|
|
80
76
|
async function createSessionImpl(sendFn, walletSignFn, currentTimestamp, nonce, params) {
|
|
81
|
-
(0, utils_1.checkPubKeyLength)(types_1.KeyType.
|
|
77
|
+
(0, utils_1.checkPubKeyLength)(types_1.KeyType.Ed25519, params.userPubkey.length);
|
|
82
78
|
(0, utils_1.checkPubKeyLength)(types_1.KeyType.Ed25519, params.sessionPubkey.length);
|
|
83
79
|
let expiry = 0n;
|
|
84
80
|
if (params.expiryTimestamp !== undefined) {
|
|
@@ -228,7 +224,7 @@ async function transferImpl(sendFn, signFn, currentTimestamp, nonce, params) {
|
|
|
228
224
|
const resp = await sendAction(sendFn, (m) => sessionSign(signFn, m), action, "transfer asset to other account");
|
|
229
225
|
if (resp.kind?.$case === "transferred") {
|
|
230
226
|
if (resp.kind.value.accountCreated) {
|
|
231
|
-
return resp.kind.value.
|
|
227
|
+
return resp.kind.value.toUserAccount;
|
|
232
228
|
}
|
|
233
229
|
else {
|
|
234
230
|
return undefined;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Account, Info } from "../../types";
|
|
2
|
+
import { NordWebSocketClient } from "../../websocket/index";
|
|
3
|
+
/**
|
|
4
|
+
* Get the current timestamp from the Nord server
|
|
5
|
+
*
|
|
6
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
7
|
+
* @returns Current timestamp as a bigint
|
|
8
|
+
* @throws {NordError} If the request fails
|
|
9
|
+
*/
|
|
10
|
+
export declare function getTimestamp(webServerUrl: string): Promise<bigint>;
|
|
11
|
+
/**
|
|
12
|
+
* Get the next action nonce from the Nord server
|
|
13
|
+
*
|
|
14
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
15
|
+
* @returns Next action nonce
|
|
16
|
+
* @throws {NordError} If the request fails
|
|
17
|
+
*/
|
|
18
|
+
export declare function getActionNonce(webServerUrl: string): Promise<number>;
|
|
19
|
+
/**
|
|
20
|
+
* Get information about the Nord server
|
|
21
|
+
*
|
|
22
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
23
|
+
* @returns Information about markets and tokens
|
|
24
|
+
* @throws {NordError} If the request fails
|
|
25
|
+
*/
|
|
26
|
+
export declare function getInfo(webServerUrl: string): Promise<Info>;
|
|
27
|
+
/**
|
|
28
|
+
* Get account information
|
|
29
|
+
*
|
|
30
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
31
|
+
* @param accountId - Account ID to get information for
|
|
32
|
+
* @returns Account information
|
|
33
|
+
* @throws {NordError} If the request fails
|
|
34
|
+
*/
|
|
35
|
+
export declare function getAccount(webServerUrl: string, accountId: number): Promise<Account>;
|
|
36
|
+
/**
|
|
37
|
+
* Initialize a WebSocket client for Nord
|
|
38
|
+
*
|
|
39
|
+
* Connects to one of the specific Nord WebSocket endpoints:
|
|
40
|
+
* - /ws/trades - For trade updates (default)
|
|
41
|
+
* - /ws/deltas - For orderbook delta updates
|
|
42
|
+
* - /ws/user - For user-specific updates
|
|
43
|
+
*
|
|
44
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
45
|
+
* @param endpoint - Specific WebSocket endpoint to connect to (trades, deltas, or user)
|
|
46
|
+
* @param initialSubscriptions - Optional array of initial subscriptions (e.g., ["trades@BTCUSDC"])
|
|
47
|
+
* @returns WebSocket client
|
|
48
|
+
*/
|
|
49
|
+
export declare function initWebSocketClient(webServerUrl: string, endpoint?: "trades" | "deltas" | "user", initialSubscriptions?: string[]): NordWebSocketClient;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTimestamp = getTimestamp;
|
|
4
|
+
exports.getActionNonce = getActionNonce;
|
|
5
|
+
exports.getInfo = getInfo;
|
|
6
|
+
exports.getAccount = getAccount;
|
|
7
|
+
exports.initWebSocketClient = initWebSocketClient;
|
|
8
|
+
const utils_1 = require("../../utils");
|
|
9
|
+
const index_1 = require("../../websocket/index");
|
|
10
|
+
const NordError_1 = require("../utils/NordError");
|
|
11
|
+
/**
|
|
12
|
+
* Get the current timestamp from the Nord server
|
|
13
|
+
*
|
|
14
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
15
|
+
* @returns Current timestamp as a bigint
|
|
16
|
+
* @throws {NordError} If the request fails
|
|
17
|
+
*/
|
|
18
|
+
async function getTimestamp(webServerUrl) {
|
|
19
|
+
try {
|
|
20
|
+
const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/timestamp`);
|
|
21
|
+
return BigInt(await response.json());
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
throw new NordError_1.NordError("Failed to get timestamp", { cause: error });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Get the next action nonce from the Nord server
|
|
29
|
+
*
|
|
30
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
31
|
+
* @returns Next action nonce
|
|
32
|
+
* @throws {NordError} If the request fails
|
|
33
|
+
*/
|
|
34
|
+
async function getActionNonce(webServerUrl) {
|
|
35
|
+
try {
|
|
36
|
+
const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/action_nonce`);
|
|
37
|
+
const data = await response.json();
|
|
38
|
+
return data.nonce;
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
throw new NordError_1.NordError("Failed to get action nonce", { cause: error });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get information about the Nord server
|
|
46
|
+
*
|
|
47
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
48
|
+
* @returns Information about markets and tokens
|
|
49
|
+
* @throws {NordError} If the request fails
|
|
50
|
+
*/
|
|
51
|
+
async function getInfo(webServerUrl) {
|
|
52
|
+
try {
|
|
53
|
+
const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/info`);
|
|
54
|
+
return await response.json();
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
throw new NordError_1.NordError("Failed to get info", { cause: error });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get account information
|
|
62
|
+
*
|
|
63
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
64
|
+
* @param accountId - Account ID to get information for
|
|
65
|
+
* @returns Account information
|
|
66
|
+
* @throws {NordError} If the request fails
|
|
67
|
+
*/
|
|
68
|
+
async function getAccount(webServerUrl, accountId) {
|
|
69
|
+
try {
|
|
70
|
+
const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/account?account_id=${accountId}`);
|
|
71
|
+
return await response.json();
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
throw new NordError_1.NordError(`Failed to get account ${accountId}`, { cause: error });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Initialize a WebSocket client for Nord
|
|
79
|
+
*
|
|
80
|
+
* Connects to one of the specific Nord WebSocket endpoints:
|
|
81
|
+
* - /ws/trades - For trade updates (default)
|
|
82
|
+
* - /ws/deltas - For orderbook delta updates
|
|
83
|
+
* - /ws/user - For user-specific updates
|
|
84
|
+
*
|
|
85
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
86
|
+
* @param endpoint - Specific WebSocket endpoint to connect to (trades, deltas, or user)
|
|
87
|
+
* @param initialSubscriptions - Optional array of initial subscriptions (e.g., ["trades@BTCUSDC"])
|
|
88
|
+
* @returns WebSocket client
|
|
89
|
+
*/
|
|
90
|
+
function initWebSocketClient(webServerUrl, endpoint, initialSubscriptions) {
|
|
91
|
+
try {
|
|
92
|
+
// Convert HTTP URL to WebSocket URL with specific endpoint
|
|
93
|
+
// If no specific endpoint is provided, we'll connect to trades by default
|
|
94
|
+
const specificEndpoint = endpoint || "trades";
|
|
95
|
+
const wsUrl = webServerUrl.replace(/^http/, "ws") + `/ws/${specificEndpoint}`;
|
|
96
|
+
console.log(`Initializing WebSocket client with URL: ${wsUrl}`);
|
|
97
|
+
// Create and connect the WebSocket client
|
|
98
|
+
const ws = new index_1.NordWebSocketClient(wsUrl);
|
|
99
|
+
// Add error handler
|
|
100
|
+
ws.on("error", (error) => {
|
|
101
|
+
console.error("Nord WebSocket error:", error);
|
|
102
|
+
});
|
|
103
|
+
// Add connected handler for debugging
|
|
104
|
+
ws.on("connected", () => {
|
|
105
|
+
console.log("Nord WebSocket connected successfully");
|
|
106
|
+
// Subscribe to initial subscriptions if provided
|
|
107
|
+
if (initialSubscriptions && initialSubscriptions.length > 0) {
|
|
108
|
+
ws.subscribe(initialSubscriptions);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
// Connect the WebSocket
|
|
112
|
+
ws.connect();
|
|
113
|
+
return ws;
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
console.error("Failed to initialize WebSocket client:", error);
|
|
117
|
+
throw new NordError_1.NordError("Failed to initialize WebSocket client", {
|
|
118
|
+
cause: error,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { MarketsStatsResponse, OrderbookQuery, OrderbookResponse, TradesQuery, TradesResponse, UserAccountIdsQuery, UserAccountIdsResponse } from "../../types";
|
|
2
|
+
/**
|
|
3
|
+
* Get market statistics
|
|
4
|
+
*
|
|
5
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
6
|
+
* @returns Market statistics response
|
|
7
|
+
* @throws {NordError} If the request fails
|
|
8
|
+
*/
|
|
9
|
+
export declare function marketsStats(webServerUrl: string): Promise<MarketsStatsResponse>;
|
|
10
|
+
/**
|
|
11
|
+
* Get trades for a market
|
|
12
|
+
*
|
|
13
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
14
|
+
* @param query - Trades query parameters
|
|
15
|
+
* @returns Trades response
|
|
16
|
+
* @throws {NordError} If the request fails
|
|
17
|
+
*/
|
|
18
|
+
export declare function getTrades(webServerUrl: string, query: TradesQuery): Promise<TradesResponse>;
|
|
19
|
+
/**
|
|
20
|
+
* Get user account IDs
|
|
21
|
+
*
|
|
22
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
23
|
+
* @param query - User account IDs query parameters
|
|
24
|
+
* @returns User account IDs response
|
|
25
|
+
* @throws {NordError} If the request fails
|
|
26
|
+
*/
|
|
27
|
+
export declare function getUserAccountIds(webServerUrl: string, query: UserAccountIdsQuery): Promise<UserAccountIdsResponse>;
|
|
28
|
+
/**
|
|
29
|
+
* Get orderbook for a market
|
|
30
|
+
*
|
|
31
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
32
|
+
* @param query - Orderbook query parameters
|
|
33
|
+
* @returns Orderbook response
|
|
34
|
+
* @throws {NordError} If the request fails
|
|
35
|
+
*/
|
|
36
|
+
export declare function getOrderbook(webServerUrl: string, query: OrderbookQuery): Promise<OrderbookResponse>;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.marketsStats = marketsStats;
|
|
4
|
+
exports.getTrades = getTrades;
|
|
5
|
+
exports.getUserAccountIds = getUserAccountIds;
|
|
6
|
+
exports.getOrderbook = getOrderbook;
|
|
7
|
+
const utils_1 = require("../../utils");
|
|
8
|
+
const NordError_1 = require("../utils/NordError");
|
|
9
|
+
/**
|
|
10
|
+
* Get market statistics
|
|
11
|
+
*
|
|
12
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
13
|
+
* @returns Market statistics response
|
|
14
|
+
* @throws {NordError} If the request fails
|
|
15
|
+
*/
|
|
16
|
+
async function marketsStats(webServerUrl) {
|
|
17
|
+
try {
|
|
18
|
+
const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/stats`);
|
|
19
|
+
return await response.json();
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
throw new NordError_1.NordError("Failed to fetch markets stats", { cause: error });
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get trades for a market
|
|
27
|
+
*
|
|
28
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
29
|
+
* @param query - Trades query parameters
|
|
30
|
+
* @returns Trades response
|
|
31
|
+
* @throws {NordError} If the request fails
|
|
32
|
+
*/
|
|
33
|
+
async function getTrades(webServerUrl, query) {
|
|
34
|
+
try {
|
|
35
|
+
const params = new URLSearchParams();
|
|
36
|
+
params.append("accountId", query.accountId.toString());
|
|
37
|
+
if (query.since) {
|
|
38
|
+
params.append("since", query.since);
|
|
39
|
+
}
|
|
40
|
+
if (query.until) {
|
|
41
|
+
params.append("until", query.until);
|
|
42
|
+
}
|
|
43
|
+
if (query.pageId) {
|
|
44
|
+
params.append("pageId", query.pageId);
|
|
45
|
+
}
|
|
46
|
+
const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/trades?${params.toString()}`);
|
|
47
|
+
return await response.json();
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
throw new NordError_1.NordError("Failed to get trades", { cause: error });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get user account IDs
|
|
55
|
+
*
|
|
56
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
57
|
+
* @param query - User account IDs query parameters
|
|
58
|
+
* @returns User account IDs response
|
|
59
|
+
* @throws {NordError} If the request fails
|
|
60
|
+
*/
|
|
61
|
+
async function getUserAccountIds(webServerUrl, query) {
|
|
62
|
+
try {
|
|
63
|
+
const params = new URLSearchParams();
|
|
64
|
+
params.append("pubkey", query.pubkey);
|
|
65
|
+
const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/user?${params.toString()}`);
|
|
66
|
+
return await response.json();
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
throw new NordError_1.NordError("Failed to get user account IDs", { cause: error });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get orderbook for a market
|
|
74
|
+
*
|
|
75
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
76
|
+
* @param query - Orderbook query parameters
|
|
77
|
+
* @returns Orderbook response
|
|
78
|
+
* @throws {NordError} If the request fails
|
|
79
|
+
*/
|
|
80
|
+
async function getOrderbook(webServerUrl, query) {
|
|
81
|
+
try {
|
|
82
|
+
const params = new URLSearchParams();
|
|
83
|
+
if (query.symbol) {
|
|
84
|
+
params.append("symbol", query.symbol);
|
|
85
|
+
}
|
|
86
|
+
else if (query.market_id !== undefined) {
|
|
87
|
+
params.append("market_id", query.market_id.toString());
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
throw new NordError_1.NordError("Either symbol or market_id must be provided for orderbook query");
|
|
91
|
+
}
|
|
92
|
+
const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/orderbook?${params.toString()}`);
|
|
93
|
+
return await response.json();
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
throw new NordError_1.NordError("Failed to get orderbook", { cause: error });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { AggregateMetrics, PeakTpsPeriodUnit } from "../../types";
|
|
2
|
+
/**
|
|
3
|
+
* Time periods for metrics queries
|
|
4
|
+
*/
|
|
5
|
+
export declare enum MetricPeriod {
|
|
6
|
+
ONE_MINUTE = "1m",
|
|
7
|
+
FIVE_MINUTES = "5m",
|
|
8
|
+
FIFTEEN_MINUTES = "15m",
|
|
9
|
+
ONE_HOUR = "1h",
|
|
10
|
+
FOUR_HOURS = "4h",
|
|
11
|
+
ONE_DAY = "24h",
|
|
12
|
+
ONE_WEEK = "7d"
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Fetch aggregate metrics from the Nord API
|
|
16
|
+
*
|
|
17
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
18
|
+
* @param txPeakTpsPeriod - Period for peak TPS calculation
|
|
19
|
+
* @param txPeakTpsPeriodUnit - Unit for peak TPS period
|
|
20
|
+
* @returns Aggregate metrics
|
|
21
|
+
* @throws {NordError} If the request fails
|
|
22
|
+
*/
|
|
23
|
+
export declare function aggregateMetrics(webServerUrl: string, txPeakTpsPeriod?: number, txPeakTpsPeriodUnit?: PeakTpsPeriodUnit): Promise<AggregateMetrics>;
|
|
24
|
+
/**
|
|
25
|
+
* Get current transactions per second
|
|
26
|
+
*
|
|
27
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
28
|
+
* @param period - Time period for the query
|
|
29
|
+
* @returns Current TPS value
|
|
30
|
+
* @throws {NordError} If the request fails
|
|
31
|
+
*/
|
|
32
|
+
export declare function getCurrentTps(webServerUrl: string, period?: string): Promise<number>;
|
|
33
|
+
/**
|
|
34
|
+
* Get peak transactions per second
|
|
35
|
+
*
|
|
36
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
37
|
+
* @param period - Time period for the query
|
|
38
|
+
* @returns Peak TPS value
|
|
39
|
+
* @throws {NordError} If the request fails
|
|
40
|
+
*/
|
|
41
|
+
export declare function getPeakTps(webServerUrl: string, period?: string): Promise<number>;
|
|
42
|
+
/**
|
|
43
|
+
* Get median transaction latency
|
|
44
|
+
*
|
|
45
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
46
|
+
* @param period - Time period for the query
|
|
47
|
+
* @returns Median latency in milliseconds
|
|
48
|
+
* @throws {NordError} If the request fails
|
|
49
|
+
*/
|
|
50
|
+
export declare function getMedianLatency(webServerUrl: string, period?: string): Promise<number>;
|
|
51
|
+
/**
|
|
52
|
+
* Get total transaction count
|
|
53
|
+
*
|
|
54
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
55
|
+
* @returns Total transaction count
|
|
56
|
+
* @throws {NordError} If the request fails
|
|
57
|
+
*/
|
|
58
|
+
export declare function getTotalTransactions(webServerUrl: string): Promise<number>;
|
|
59
|
+
/**
|
|
60
|
+
* Query Prometheus metrics
|
|
61
|
+
*
|
|
62
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
63
|
+
* @param params - Prometheus query parameters
|
|
64
|
+
* @returns Query result as a number
|
|
65
|
+
* @throws {NordError} If the request fails
|
|
66
|
+
*/
|
|
67
|
+
export declare function queryPrometheus(webServerUrl: string, params: string): Promise<number>;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MetricPeriod = void 0;
|
|
4
|
+
exports.aggregateMetrics = aggregateMetrics;
|
|
5
|
+
exports.getCurrentTps = getCurrentTps;
|
|
6
|
+
exports.getPeakTps = getPeakTps;
|
|
7
|
+
exports.getMedianLatency = getMedianLatency;
|
|
8
|
+
exports.getTotalTransactions = getTotalTransactions;
|
|
9
|
+
exports.queryPrometheus = queryPrometheus;
|
|
10
|
+
const types_1 = require("../../types");
|
|
11
|
+
const utils_1 = require("../../utils");
|
|
12
|
+
const NordError_1 = require("../utils/NordError");
|
|
13
|
+
/**
|
|
14
|
+
* Time periods for metrics queries
|
|
15
|
+
*/
|
|
16
|
+
var MetricPeriod;
|
|
17
|
+
(function (MetricPeriod) {
|
|
18
|
+
MetricPeriod["ONE_MINUTE"] = "1m";
|
|
19
|
+
MetricPeriod["FIVE_MINUTES"] = "5m";
|
|
20
|
+
MetricPeriod["FIFTEEN_MINUTES"] = "15m";
|
|
21
|
+
MetricPeriod["ONE_HOUR"] = "1h";
|
|
22
|
+
MetricPeriod["FOUR_HOURS"] = "4h";
|
|
23
|
+
MetricPeriod["ONE_DAY"] = "24h";
|
|
24
|
+
MetricPeriod["ONE_WEEK"] = "7d";
|
|
25
|
+
})(MetricPeriod || (exports.MetricPeriod = MetricPeriod = {}));
|
|
26
|
+
/**
|
|
27
|
+
* Fetch aggregate metrics from the Nord API
|
|
28
|
+
*
|
|
29
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
30
|
+
* @param txPeakTpsPeriod - Period for peak TPS calculation
|
|
31
|
+
* @param txPeakTpsPeriodUnit - Unit for peak TPS period
|
|
32
|
+
* @returns Aggregate metrics
|
|
33
|
+
* @throws {NordError} If the request fails
|
|
34
|
+
*/
|
|
35
|
+
async function aggregateMetrics(webServerUrl, txPeakTpsPeriod = 1, txPeakTpsPeriodUnit = types_1.PeakTpsPeriodUnit.Day) {
|
|
36
|
+
try {
|
|
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();
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
throw new NordError_1.NordError("Failed to fetch aggregate metrics", { cause: error });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get current transactions per second
|
|
46
|
+
*
|
|
47
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
48
|
+
* @param period - Time period for the query
|
|
49
|
+
* @returns Current TPS value
|
|
50
|
+
* @throws {NordError} If the request fails
|
|
51
|
+
*/
|
|
52
|
+
async function getCurrentTps(webServerUrl, period = "1m") {
|
|
53
|
+
try {
|
|
54
|
+
return await queryPrometheus(webServerUrl, `sum(rate(nord_tx_count[${period}]))`);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
throw new NordError_1.NordError(`Failed to get current TPS for period ${period}`, {
|
|
58
|
+
cause: error,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get peak transactions per second
|
|
64
|
+
*
|
|
65
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
66
|
+
* @param period - Time period for the query
|
|
67
|
+
* @returns Peak TPS value
|
|
68
|
+
* @throws {NordError} If the request fails
|
|
69
|
+
*/
|
|
70
|
+
async function getPeakTps(webServerUrl, period = "24h") {
|
|
71
|
+
try {
|
|
72
|
+
return await queryPrometheus(webServerUrl, `max_over_time(sum(rate(nord_tx_count[1m]))[${period}:])`);
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
throw new NordError_1.NordError(`Failed to get peak TPS for period ${period}`, {
|
|
76
|
+
cause: error,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Get median transaction latency
|
|
82
|
+
*
|
|
83
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
84
|
+
* @param period - Time period for the query
|
|
85
|
+
* @returns Median latency in milliseconds
|
|
86
|
+
* @throws {NordError} If the request fails
|
|
87
|
+
*/
|
|
88
|
+
async function getMedianLatency(webServerUrl, period = "1m") {
|
|
89
|
+
try {
|
|
90
|
+
return await queryPrometheus(webServerUrl, `quantile_over_time(0.5, nord_tx_latency_ms[${period}])`);
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
throw new NordError_1.NordError(`Failed to get median latency for period ${period}`, {
|
|
94
|
+
cause: error,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Get total transaction count
|
|
100
|
+
*
|
|
101
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
102
|
+
* @returns Total transaction count
|
|
103
|
+
* @throws {NordError} If the request fails
|
|
104
|
+
*/
|
|
105
|
+
async function getTotalTransactions(webServerUrl) {
|
|
106
|
+
try {
|
|
107
|
+
return await queryPrometheus(webServerUrl, "sum(nord_tx_count)");
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
throw new NordError_1.NordError("Failed to get total transactions", { cause: error });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Query Prometheus metrics
|
|
115
|
+
*
|
|
116
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
117
|
+
* @param params - Prometheus query parameters
|
|
118
|
+
* @returns Query result as a number
|
|
119
|
+
* @throws {NordError} If the request fails
|
|
120
|
+
*/
|
|
121
|
+
async function queryPrometheus(webServerUrl, params) {
|
|
122
|
+
try {
|
|
123
|
+
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;
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
throw new NordError_1.NordError(`Failed to query Prometheus: ${params}`, {
|
|
129
|
+
cause: error,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|