@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
|
@@ -0,0 +1,81 @@
|
|
|
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>;
|
|
28
|
+
/**
|
|
29
|
+
* Query a specific action
|
|
30
|
+
*
|
|
31
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
32
|
+
* @param query - Action query parameters
|
|
33
|
+
* @returns Action response
|
|
34
|
+
* @throws {NordError} If the request fails
|
|
35
|
+
*/
|
|
36
|
+
export declare function queryAction(webServerUrl: string, query: ActionQuery): Promise<ActionResponse>;
|
|
37
|
+
/**
|
|
38
|
+
* Query recent actions
|
|
39
|
+
*
|
|
40
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
41
|
+
* @param last_n - Number of recent actions to query
|
|
42
|
+
* @returns Actions response
|
|
43
|
+
* @throws {NordError} If the request fails
|
|
44
|
+
*/
|
|
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>;
|
|
55
|
+
/**
|
|
56
|
+
* Query block summaries from Rollman
|
|
57
|
+
*
|
|
58
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
59
|
+
* @param last_n - Number of recent blocks to query
|
|
60
|
+
* @returns Block summary response
|
|
61
|
+
* @throws {NordError} If the request fails
|
|
62
|
+
*/
|
|
63
|
+
export declare function blockSummaryQueryRollman(webServerUrl: string, last_n: number): Promise<BlockSummaryResponse>;
|
|
64
|
+
/**
|
|
65
|
+
* Query an action from Rollman
|
|
66
|
+
*
|
|
67
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
68
|
+
* @param query - Action query parameters
|
|
69
|
+
* @returns Rollman action response
|
|
70
|
+
* @throws {NordError} If the request fails
|
|
71
|
+
*/
|
|
72
|
+
export declare function actionQueryRollman(webServerUrl: string, query: ActionQuery): Promise<RollmanActionResponse>;
|
|
73
|
+
/**
|
|
74
|
+
* Query actions from Rollman
|
|
75
|
+
*
|
|
76
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
77
|
+
* @param last_n - Number of recent actions to query
|
|
78
|
+
* @returns Rollman actions response
|
|
79
|
+
* @throws {NordError} If the request fails
|
|
80
|
+
*/
|
|
81
|
+
export declare function actionsQueryRollman(webServerUrl: string, last_n: number): Promise<RollmanActionsResponse>;
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.queryBlock = queryBlock;
|
|
4
|
+
exports.queryLastNBlocks = queryLastNBlocks;
|
|
5
|
+
exports.queryRecentBlocks = queryRecentBlocks;
|
|
6
|
+
exports.queryAction = queryAction;
|
|
7
|
+
exports.queryRecentActions = queryRecentActions;
|
|
8
|
+
exports.blockQueryRollman = blockQueryRollman;
|
|
9
|
+
exports.blockSummaryQueryRollman = blockSummaryQueryRollman;
|
|
10
|
+
exports.actionQueryRollman = actionQueryRollman;
|
|
11
|
+
exports.actionsQueryRollman = actionsQueryRollman;
|
|
12
|
+
const utils_1 = require("../../utils");
|
|
13
|
+
const NordError_1 = require("../utils/NordError");
|
|
14
|
+
/**
|
|
15
|
+
* Query a specific block
|
|
16
|
+
*
|
|
17
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
18
|
+
* @param query - Block query parameters
|
|
19
|
+
* @returns Block response
|
|
20
|
+
* @throws {NordError} If the request fails
|
|
21
|
+
*/
|
|
22
|
+
async function queryBlock(webServerUrl, query) {
|
|
23
|
+
try {
|
|
24
|
+
const params = new URLSearchParams();
|
|
25
|
+
if (query.block_number !== undefined) {
|
|
26
|
+
params.append("block_height", query.block_number.toString());
|
|
27
|
+
}
|
|
28
|
+
const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/block?${params.toString()}`);
|
|
29
|
+
return await response.json();
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
throw new NordError_1.NordError("Failed to query block", { cause: error });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Query the last N blocks
|
|
37
|
+
*
|
|
38
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
39
|
+
* @returns Block response for the last N blocks
|
|
40
|
+
* @throws {NordError} If the request fails
|
|
41
|
+
*/
|
|
42
|
+
async function queryLastNBlocks(webServerUrl) {
|
|
43
|
+
try {
|
|
44
|
+
const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/blocks`);
|
|
45
|
+
return await response.json();
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
throw new NordError_1.NordError("Failed to query last N blocks", { cause: error });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Query recent blocks
|
|
53
|
+
*
|
|
54
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
55
|
+
* @param last_n - Number of recent blocks to query
|
|
56
|
+
* @returns Block summary response
|
|
57
|
+
* @throws {NordError} If the request fails
|
|
58
|
+
*/
|
|
59
|
+
async function queryRecentBlocks(webServerUrl, last_n) {
|
|
60
|
+
try {
|
|
61
|
+
const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/blocks_summary?last_n=${last_n}`);
|
|
62
|
+
return await response.json();
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
throw new NordError_1.NordError(`Failed to query recent blocks (last ${last_n})`, {
|
|
66
|
+
cause: error,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Query a specific action
|
|
72
|
+
*
|
|
73
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
74
|
+
* @param query - Action query parameters
|
|
75
|
+
* @returns Action response
|
|
76
|
+
* @throws {NordError} If the request fails
|
|
77
|
+
*/
|
|
78
|
+
async function queryAction(webServerUrl, query) {
|
|
79
|
+
try {
|
|
80
|
+
const params = new URLSearchParams();
|
|
81
|
+
if (query.action_id !== undefined) {
|
|
82
|
+
params.append("action_id", query.action_id.toString());
|
|
83
|
+
}
|
|
84
|
+
const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/action?${params.toString()}`);
|
|
85
|
+
return await response.json();
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
throw new NordError_1.NordError("Failed to query action", { cause: error });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Query recent actions
|
|
93
|
+
*
|
|
94
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
95
|
+
* @param last_n - Number of recent actions to query
|
|
96
|
+
* @returns Actions response
|
|
97
|
+
* @throws {NordError} If the request fails
|
|
98
|
+
*/
|
|
99
|
+
async function queryRecentActions(webServerUrl, last_n) {
|
|
100
|
+
try {
|
|
101
|
+
const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/actions?last_n=${last_n}`);
|
|
102
|
+
return await response.json();
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
throw new NordError_1.NordError(`Failed to query recent actions (last ${last_n})`, {
|
|
106
|
+
cause: error,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Query a block from Rollman
|
|
112
|
+
*
|
|
113
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
114
|
+
* @param query - Block query parameters
|
|
115
|
+
* @returns Rollman block response
|
|
116
|
+
* @throws {NordError} If the request fails
|
|
117
|
+
*/
|
|
118
|
+
async function blockQueryRollman(webServerUrl, query) {
|
|
119
|
+
try {
|
|
120
|
+
const params = new URLSearchParams();
|
|
121
|
+
if (query.block_number !== undefined) {
|
|
122
|
+
params.append("block_height", query.block_number.toString());
|
|
123
|
+
}
|
|
124
|
+
const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/rollman/block?${params.toString()}`);
|
|
125
|
+
return await response.json();
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
throw new NordError_1.NordError("Failed to query Rollman block", { cause: error });
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Query block summaries from Rollman
|
|
133
|
+
*
|
|
134
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
135
|
+
* @param last_n - Number of recent blocks to query
|
|
136
|
+
* @returns Block summary response
|
|
137
|
+
* @throws {NordError} If the request fails
|
|
138
|
+
*/
|
|
139
|
+
async function blockSummaryQueryRollman(webServerUrl, last_n) {
|
|
140
|
+
try {
|
|
141
|
+
const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/rollman/blocks_summary?last_n=${last_n}`);
|
|
142
|
+
return await response.json();
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
throw new NordError_1.NordError(`Failed to query Rollman block summaries (last ${last_n})`, { cause: error });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Query an action from Rollman
|
|
150
|
+
*
|
|
151
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
152
|
+
* @param query - Action query parameters
|
|
153
|
+
* @returns Rollman action response
|
|
154
|
+
* @throws {NordError} If the request fails
|
|
155
|
+
*/
|
|
156
|
+
async function actionQueryRollman(webServerUrl, query) {
|
|
157
|
+
try {
|
|
158
|
+
const params = new URLSearchParams();
|
|
159
|
+
if (query.action_id !== undefined) {
|
|
160
|
+
params.append("action_id", query.action_id.toString());
|
|
161
|
+
}
|
|
162
|
+
const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/rollman/action?${params.toString()}`);
|
|
163
|
+
return await response.json();
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
throw new NordError_1.NordError("Failed to query Rollman action", { cause: error });
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Query actions from Rollman
|
|
171
|
+
*
|
|
172
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
173
|
+
* @param last_n - Number of recent actions to query
|
|
174
|
+
* @returns Rollman actions response
|
|
175
|
+
* @throws {NordError} If the request fails
|
|
176
|
+
*/
|
|
177
|
+
async function actionsQueryRollman(webServerUrl, last_n) {
|
|
178
|
+
try {
|
|
179
|
+
const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/rollman/actions?last_n=${last_n}`);
|
|
180
|
+
return await response.json();
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
throw new NordError_1.NordError(`Failed to query Rollman actions (last ${last_n})`, {
|
|
184
|
+
cause: error,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import { EventEmitter } from "events";
|
|
2
|
+
import { Account, ActionQuery, ActionResponse, ActionsResponse, AggregateMetrics, BlockQuery, BlockResponse, BlockSummaryResponse, Info, Market, MarketsStatsResponse, NordConfig, OrderbookQuery, OrderbookResponse, PeakTpsPeriodUnit, RollmanActionResponse, RollmanActionsResponse, RollmanBlockResponse, Token, TradesQuery, TradesResponse, UserAccountIdsQuery, UserAccountIdsResponse } from "../../types";
|
|
3
|
+
import { NordWebSocketClient } from "../../websocket/index";
|
|
4
|
+
import { OrderbookSubscription, TradeSubscription } from "../models/Subscriber";
|
|
5
|
+
/**
|
|
6
|
+
* User subscription interface
|
|
7
|
+
*/
|
|
8
|
+
export interface UserSubscription extends EventEmitter {
|
|
9
|
+
close: () => void;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Main Nord client class for interacting with the Nord API
|
|
13
|
+
*/
|
|
14
|
+
export declare class Nord {
|
|
15
|
+
/** Base URL for the Nord web server */
|
|
16
|
+
readonly webServerUrl: string;
|
|
17
|
+
/** Solana program ID */
|
|
18
|
+
readonly solanaProgramId: string;
|
|
19
|
+
/** Solana RPC URL */
|
|
20
|
+
readonly solanaUrl: string;
|
|
21
|
+
/** Available markets */
|
|
22
|
+
markets: Market[];
|
|
23
|
+
/** Available tokens */
|
|
24
|
+
tokens: Token[];
|
|
25
|
+
/** Map of symbol to market_id */
|
|
26
|
+
private symbolToMarketId;
|
|
27
|
+
/**
|
|
28
|
+
* WebSocket client for trades
|
|
29
|
+
* @private
|
|
30
|
+
*/
|
|
31
|
+
private tradesWs;
|
|
32
|
+
/**
|
|
33
|
+
* WebSocket client for orderbook deltas
|
|
34
|
+
* @private
|
|
35
|
+
*/
|
|
36
|
+
private deltasWs;
|
|
37
|
+
/**
|
|
38
|
+
* WebSocket client for user updates
|
|
39
|
+
* @private
|
|
40
|
+
*/
|
|
41
|
+
private userWs;
|
|
42
|
+
/**
|
|
43
|
+
* Initial subscriptions for the trades WebSocket
|
|
44
|
+
* @private
|
|
45
|
+
*/
|
|
46
|
+
private tradesSubscriptions?;
|
|
47
|
+
/**
|
|
48
|
+
* Initial subscriptions for the deltas WebSocket
|
|
49
|
+
* @private
|
|
50
|
+
*/
|
|
51
|
+
private deltasSubscriptions?;
|
|
52
|
+
/**
|
|
53
|
+
* Create a new Nord client
|
|
54
|
+
*
|
|
55
|
+
* @param config - Configuration options for the Nord client
|
|
56
|
+
* @param config.webServerUrl - Base URL for the Nord web server
|
|
57
|
+
* @param config.solanaProgramId - Solana program ID
|
|
58
|
+
* @param config.solanaUrl - Solana cluster URL
|
|
59
|
+
* @param config.initWebSockets - Whether to initialize WebSockets on creation, defaults to true
|
|
60
|
+
* @param config.tradesSubscriptions - Optional array of trades subscriptions to initialize with (e.g., ["trades@BTCUSDC"])
|
|
61
|
+
* @param config.deltasSubscriptions - Optional array of deltas subscriptions to initialize with (e.g., ["deltas@BTCUSDC"])
|
|
62
|
+
* @throws {Error} If required configuration is missing
|
|
63
|
+
*/
|
|
64
|
+
constructor({ webServerUrl, solanaProgramId, solanaUrl, initWebSockets, tradesSubscriptions, deltasSubscriptions, }: NordConfig);
|
|
65
|
+
/**
|
|
66
|
+
* Initialize WebSocket clients for trades and deltas
|
|
67
|
+
*
|
|
68
|
+
* This method can be called manually if websockets were not initialized during construction
|
|
69
|
+
* (i.e., if initWebSockets was set to false in the constructor).
|
|
70
|
+
*
|
|
71
|
+
* It initializes the trades and deltas WebSocket clients. The user WebSocket client
|
|
72
|
+
* is initialized on demand when needed.
|
|
73
|
+
*
|
|
74
|
+
* @param tradesSubscriptions - Optional array of trades subscriptions to initialize with
|
|
75
|
+
* @param deltasSubscriptions - Optional array of deltas subscriptions to initialize with
|
|
76
|
+
*/
|
|
77
|
+
initializeWebSockets(tradesSubscriptions?: string[], deltasSubscriptions?: string[]): void;
|
|
78
|
+
/**
|
|
79
|
+
* Get the current timestamp from the Nord server
|
|
80
|
+
*
|
|
81
|
+
* @returns Current timestamp as a bigint
|
|
82
|
+
* @throws {NordError} If the request fails
|
|
83
|
+
*/
|
|
84
|
+
getTimestamp(): Promise<bigint>;
|
|
85
|
+
/**
|
|
86
|
+
* Get the next action nonce from the Nord server
|
|
87
|
+
*
|
|
88
|
+
* @returns Next action nonce
|
|
89
|
+
* @throws {NordError} If the request fails
|
|
90
|
+
*/
|
|
91
|
+
getActionNonce(): Promise<number>;
|
|
92
|
+
/**
|
|
93
|
+
* Fetch information about Nord markets and tokens
|
|
94
|
+
*
|
|
95
|
+
* @throws {NordError} If the request fails
|
|
96
|
+
*/
|
|
97
|
+
fetchNordInfo(): Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Initialize a new Nord client
|
|
100
|
+
*
|
|
101
|
+
* @param nordConfig - Configuration options for the Nord client
|
|
102
|
+
* @param nordConfig.webServerUrl - Base URL for the Nord web server
|
|
103
|
+
* @param nordConfig.solanaProgramId - Solana program ID
|
|
104
|
+
* @param nordConfig.solanaUrl - Solana cluster URL
|
|
105
|
+
* @param nordConfig.initWebSockets - Whether to initialize WebSockets on creation, defaults to true
|
|
106
|
+
* @param nordConfig.tradesSubscriptions - Optional array of trades subscriptions (e.g., ["trades@BTCUSDC"])
|
|
107
|
+
* @param nordConfig.deltasSubscriptions - Optional array of deltas subscriptions (e.g., ["deltas@BTCUSDC"])
|
|
108
|
+
* @returns Initialized Nord client
|
|
109
|
+
* @throws {NordError} If initialization fails
|
|
110
|
+
*/
|
|
111
|
+
static initNord(nordConfig: NordConfig): Promise<Nord>;
|
|
112
|
+
/**
|
|
113
|
+
* Get market statistics
|
|
114
|
+
*
|
|
115
|
+
* @returns Market statistics response
|
|
116
|
+
* @throws {NordError} If the request fails
|
|
117
|
+
*/
|
|
118
|
+
marketsStats(): Promise<MarketsStatsResponse>;
|
|
119
|
+
/**
|
|
120
|
+
* Query a specific block
|
|
121
|
+
*
|
|
122
|
+
* @param query - Block query parameters
|
|
123
|
+
* @returns Block response
|
|
124
|
+
* @throws {NordError} If the request fails
|
|
125
|
+
*/
|
|
126
|
+
queryBlock(query: BlockQuery): Promise<BlockResponse>;
|
|
127
|
+
/**
|
|
128
|
+
* Query the last N blocks
|
|
129
|
+
*
|
|
130
|
+
* @returns Block response for the last N blocks
|
|
131
|
+
* @throws {NordError} If the request fails
|
|
132
|
+
*/
|
|
133
|
+
queryLastNBlocks(): Promise<BlockResponse>;
|
|
134
|
+
/**
|
|
135
|
+
* Query recent blocks
|
|
136
|
+
*
|
|
137
|
+
* @param last_n - Number of recent blocks to query
|
|
138
|
+
* @returns Block summary response
|
|
139
|
+
* @throws {NordError} If the request fails
|
|
140
|
+
*/
|
|
141
|
+
queryRecentBlocks(last_n: number): Promise<BlockSummaryResponse>;
|
|
142
|
+
/**
|
|
143
|
+
* Query a specific action
|
|
144
|
+
*
|
|
145
|
+
* @param query - Action query parameters
|
|
146
|
+
* @returns Action response
|
|
147
|
+
* @throws {NordError} If the request fails
|
|
148
|
+
*/
|
|
149
|
+
queryAction(query: ActionQuery): Promise<ActionResponse>;
|
|
150
|
+
/**
|
|
151
|
+
* Query recent actions
|
|
152
|
+
*
|
|
153
|
+
* @param last_n - Number of recent actions to query
|
|
154
|
+
* @returns Actions response
|
|
155
|
+
* @throws {NordError} If the request fails
|
|
156
|
+
*/
|
|
157
|
+
queryRecentActions(last_n: number): Promise<ActionsResponse>;
|
|
158
|
+
/**
|
|
159
|
+
* Fetch aggregate metrics from the Nord API
|
|
160
|
+
*
|
|
161
|
+
* @param txPeakTpsPeriod - Period for peak TPS calculation
|
|
162
|
+
* @param txPeakTpsPeriodUnit - Unit for peak TPS period
|
|
163
|
+
* @returns Aggregate metrics
|
|
164
|
+
* @throws {NordError} If the request fails
|
|
165
|
+
*/
|
|
166
|
+
aggregateMetrics(txPeakTpsPeriod?: number, txPeakTpsPeriodUnit?: PeakTpsPeriodUnit): Promise<AggregateMetrics>;
|
|
167
|
+
/**
|
|
168
|
+
* Get current transactions per second
|
|
169
|
+
*
|
|
170
|
+
* @param period - Time period for the query
|
|
171
|
+
* @returns Current TPS value
|
|
172
|
+
* @throws {NordError} If the request fails
|
|
173
|
+
*/
|
|
174
|
+
getCurrentTps(period?: string): Promise<number>;
|
|
175
|
+
/**
|
|
176
|
+
* Get peak transactions per second
|
|
177
|
+
*
|
|
178
|
+
* @param period - Time period for the query
|
|
179
|
+
* @returns Peak TPS value
|
|
180
|
+
* @throws {NordError} If the request fails
|
|
181
|
+
*/
|
|
182
|
+
getPeakTps(period?: string): Promise<number>;
|
|
183
|
+
/**
|
|
184
|
+
* Get median transaction latency
|
|
185
|
+
*
|
|
186
|
+
* @param period - Time period for the query
|
|
187
|
+
* @returns Median latency in milliseconds
|
|
188
|
+
* @throws {NordError} If the request fails
|
|
189
|
+
*/
|
|
190
|
+
getMedianLatency(period?: string): Promise<number>;
|
|
191
|
+
/**
|
|
192
|
+
* Get total transaction count
|
|
193
|
+
*
|
|
194
|
+
* @returns Total transaction count
|
|
195
|
+
* @throws {NordError} If the request fails
|
|
196
|
+
*/
|
|
197
|
+
getTotalTransactions(): Promise<number>;
|
|
198
|
+
/**
|
|
199
|
+
* Query a block from Rollman
|
|
200
|
+
*
|
|
201
|
+
* @param query - Block query parameters
|
|
202
|
+
* @returns Rollman block response
|
|
203
|
+
* @throws {NordError} If the request fails
|
|
204
|
+
*/
|
|
205
|
+
blockQueryRollman(query: BlockQuery): Promise<RollmanBlockResponse>;
|
|
206
|
+
/**
|
|
207
|
+
* Query block summaries from Rollman
|
|
208
|
+
*
|
|
209
|
+
* @param last_n - Number of recent blocks to query
|
|
210
|
+
* @returns Block summary response
|
|
211
|
+
* @throws {NordError} If the request fails
|
|
212
|
+
*/
|
|
213
|
+
blockSummaryQueryRollman(last_n: number): Promise<BlockSummaryResponse>;
|
|
214
|
+
/**
|
|
215
|
+
* Query an action from Rollman
|
|
216
|
+
*
|
|
217
|
+
* @param query - Action query parameters
|
|
218
|
+
* @returns Rollman action response
|
|
219
|
+
* @throws {NordError} If the request fails
|
|
220
|
+
*/
|
|
221
|
+
actionQueryRollman(query: ActionQuery): Promise<RollmanActionResponse>;
|
|
222
|
+
/**
|
|
223
|
+
* Query actions from Rollman
|
|
224
|
+
*
|
|
225
|
+
* @param last_n - Number of recent actions to query
|
|
226
|
+
* @returns Rollman actions response
|
|
227
|
+
* @throws {NordError} If the request fails
|
|
228
|
+
*/
|
|
229
|
+
actionsQueryRollman(last_n: number): Promise<RollmanActionsResponse>;
|
|
230
|
+
/**
|
|
231
|
+
* Query Prometheus metrics
|
|
232
|
+
*
|
|
233
|
+
* @param params - Prometheus query parameters
|
|
234
|
+
* @returns Query result as a number
|
|
235
|
+
* @throws {NordError} If the request fails
|
|
236
|
+
*/
|
|
237
|
+
queryPrometheus(params: string): Promise<number>;
|
|
238
|
+
/**
|
|
239
|
+
* Get the trades WebSocket client (default)
|
|
240
|
+
* If not already initialized, it will be created
|
|
241
|
+
*
|
|
242
|
+
* @returns WebSocket client for trades
|
|
243
|
+
*/
|
|
244
|
+
getWebSocketClient(): NordWebSocketClient;
|
|
245
|
+
/**
|
|
246
|
+
* Get the trades WebSocket client
|
|
247
|
+
* If not already initialized, it will be created
|
|
248
|
+
*
|
|
249
|
+
* @returns WebSocket client for trades
|
|
250
|
+
*/
|
|
251
|
+
getTradesWebSocketClient(): NordWebSocketClient;
|
|
252
|
+
/**
|
|
253
|
+
* Get the deltas WebSocket client
|
|
254
|
+
* If not already initialized, it will be created
|
|
255
|
+
*
|
|
256
|
+
* @returns WebSocket client for orderbook deltas
|
|
257
|
+
*/
|
|
258
|
+
getDeltasWebSocketClient(): NordWebSocketClient;
|
|
259
|
+
/**
|
|
260
|
+
* Get the user WebSocket client
|
|
261
|
+
* If not already initialized, it will be created
|
|
262
|
+
*
|
|
263
|
+
* @returns WebSocket client for user updates
|
|
264
|
+
*/
|
|
265
|
+
getUserWebSocketClient(): NordWebSocketClient;
|
|
266
|
+
/**
|
|
267
|
+
* Subscribe to orderbook updates for a market
|
|
268
|
+
*
|
|
269
|
+
* @param symbol - Market symbol
|
|
270
|
+
* @returns Orderbook subscription
|
|
271
|
+
*/
|
|
272
|
+
subscribeOrderbook(symbol: string): OrderbookSubscription;
|
|
273
|
+
/**
|
|
274
|
+
* Subscribe to trade updates for a market
|
|
275
|
+
*
|
|
276
|
+
* @param symbol - Market symbol
|
|
277
|
+
* @returns Trade subscription
|
|
278
|
+
*/
|
|
279
|
+
subscribeTrades(symbol: string): TradeSubscription;
|
|
280
|
+
/**
|
|
281
|
+
* Get trades for a market
|
|
282
|
+
*
|
|
283
|
+
* @param query - Trades query parameters
|
|
284
|
+
* @returns Trades response
|
|
285
|
+
* @throws {NordError} If the request fails
|
|
286
|
+
*/
|
|
287
|
+
getTrades(query: TradesQuery): Promise<TradesResponse>;
|
|
288
|
+
/**
|
|
289
|
+
* Get user account IDs
|
|
290
|
+
*
|
|
291
|
+
* @param query - User account IDs query parameters
|
|
292
|
+
* @returns User account IDs response
|
|
293
|
+
* @throws {NordError} If the request fails
|
|
294
|
+
*/
|
|
295
|
+
getUserAccountIds(query: UserAccountIdsQuery): Promise<UserAccountIdsResponse>;
|
|
296
|
+
/**
|
|
297
|
+
* Get orderbook for a market
|
|
298
|
+
*
|
|
299
|
+
* @param query - Orderbook query parameters (either market_id or symbol must be provided)
|
|
300
|
+
* @returns Orderbook response
|
|
301
|
+
* @throws {NordError} If the request fails or if the market symbol is unknown
|
|
302
|
+
* @remarks It's recommended to initialize the Nord client using the static `initNord` method
|
|
303
|
+
* to ensure market information is properly loaded before calling this method.
|
|
304
|
+
*/
|
|
305
|
+
getOrderbook(query: OrderbookQuery): Promise<OrderbookResponse>;
|
|
306
|
+
/**
|
|
307
|
+
* Get information about the Nord server
|
|
308
|
+
*
|
|
309
|
+
* @returns Information about markets and tokens
|
|
310
|
+
* @throws {NordError} If the request fails
|
|
311
|
+
*/
|
|
312
|
+
getInfo(): Promise<Info>;
|
|
313
|
+
/**
|
|
314
|
+
* Get account information
|
|
315
|
+
*
|
|
316
|
+
* @param accountId - Account ID to get information for
|
|
317
|
+
* @returns Account information
|
|
318
|
+
* @throws {NordError} If the request fails
|
|
319
|
+
*/
|
|
320
|
+
getAccount(accountId: number): Promise<Account>;
|
|
321
|
+
/**
|
|
322
|
+
* Get market statistics (alias for marketsStats for backward compatibility)
|
|
323
|
+
*
|
|
324
|
+
* @deprecated Use marketsStats instead
|
|
325
|
+
* @returns Market statistics response
|
|
326
|
+
*/
|
|
327
|
+
getMarketStats(): Promise<MarketsStatsResponse>;
|
|
328
|
+
/**
|
|
329
|
+
* Check if an account exists for the given address
|
|
330
|
+
*
|
|
331
|
+
* @param address - The public key address to check
|
|
332
|
+
* @returns True if the account exists, false otherwise
|
|
333
|
+
*/
|
|
334
|
+
accountExists(address: string): Promise<boolean>;
|
|
335
|
+
}
|