@n1xyz/nord-ts 0.0.4 → 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/dist/bridge/client.d.ts +4 -4
- package/dist/bridge/client.js +4 -4
- package/dist/bridge/const.d.ts +2 -2
- package/dist/bridge/const.js +22 -22
- package/dist/bridge/index.d.ts +4 -4
- package/dist/bridge/types.d.ts +3 -3
- package/dist/bridge/utils.d.ts +4 -4
- package/dist/bridge/utils.js +10 -10
- package/dist/const.d.ts +1 -1
- package/dist/const.js +17 -17
- package/dist/gen/nord.d.ts +1 -4
- package/dist/idl/bridge.d.ts +1 -1
- package/dist/idl/bridge.js +185 -185
- package/dist/index.d.ts +8 -8
- package/dist/nord/api/actions.d.ts +3 -3
- package/dist/nord/api/actions.js +21 -21
- package/dist/nord/api/core.d.ts +3 -3
- package/dist/nord/api/core.js +12 -12
- package/dist/nord/api/market.d.ts +1 -1
- package/dist/nord/api/market.js +12 -12
- package/dist/nord/api/metrics.d.ts +1 -1
- package/dist/nord/api/metrics.js +6 -6
- package/dist/nord/api/queries.d.ts +1 -1
- package/dist/nord/api/queries.js +9 -9
- package/dist/nord/client/Nord.d.ts +4 -4
- package/dist/nord/client/Nord.js +18 -18
- package/dist/nord/client/NordUser.d.ts +7 -7
- package/dist/nord/client/NordUser.js +45 -49
- package/dist/nord/index.d.ts +9 -9
- package/dist/nord/models/Subscriber.d.ts +6 -6
- package/dist/nord/models/Subscriber.js +1 -5
- package/dist/nord/utils/NordError.js +2 -2
- package/dist/types.d.ts +1 -1
- package/dist/types.js +1 -1
- package/dist/utils.d.ts +6 -6
- package/dist/utils.js +8 -8
- package/dist/websocket/NordWebSocketClient.d.ts +2 -2
- package/dist/websocket/NordWebSocketClient.js +38 -38
- package/dist/websocket/events.d.ts +1 -1
- package/dist/websocket/index.d.ts +2 -2
- 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 +190 -31
- 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 -0
- 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 -0
- 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 -0
- 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 -70
- 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 +12 -13
- package/src/bridge/client.ts +10 -10
- package/src/bridge/const.ts +24 -24
- package/src/bridge/index.ts +4 -4
- package/src/bridge/types.ts +10 -10
- package/src/bridge/utils.ts +14 -14
- package/src/const.ts +18 -18
- package/src/gen/nord.ts +1 -4
- package/src/idl/bridge.ts +186 -186
- package/src/index.ts +8 -8
- package/src/nord/api/actions.ts +25 -25
- package/src/nord/api/core.ts +16 -16
- package/src/nord/api/market.ts +15 -15
- package/src/nord/api/metrics.ts +16 -16
- package/src/nord/api/queries.ts +12 -12
- package/src/nord/client/Nord.ts +27 -27
- package/src/nord/client/NordUser.ts +59 -63
- package/src/nord/index.ts +9 -9
- package/src/nord/models/Subscriber.ts +11 -12
- package/src/nord/utils/NordError.ts +2 -2
- package/src/types.ts +12 -12
- package/src/utils.ts +20 -20
- package/src/websocket/NordWebSocketClient.ts +42 -42
- package/src/websocket/events.ts +1 -1
- package/src/websocket/index.ts +2 -2
- package/tests/utils.spec.ts +24 -24
- package/tsconfig.eslint.json +12 -0
- package/.eslintignore +0 -1
- package/.eslintrc.js +0 -31
- 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/bridge/NordUser.d.ts +0 -78
- package/dist/bridge/NordUser.js +0 -196
- package/dist/client.d.ts +0 -70
- package/dist/client.js +0 -129
- package/dist/constants/endpoints.d.ts +0 -65
- package/dist/constants/endpoints.js +0 -68
- package/dist/models/account.d.ts +0 -58
- package/dist/models/account.js +0 -6
- package/dist/models/index.d.ts +0 -8
- package/dist/models/index.js +0 -28
- package/dist/models/market.d.ts +0 -137
- package/dist/models/market.js +0 -6
- package/dist/models/order.d.ts +0 -211
- package/dist/models/order.js +0 -6
- package/dist/models/token.d.ts +0 -50
- package/dist/models/token.js +0 -6
- package/dist/nord/Nord.d.ts +0 -249
- package/dist/nord/Nord.js +0 -388
- package/dist/nord/NordError.d.ts +0 -23
- package/dist/nord/NordError.js +0 -48
- package/dist/nord/NordImpl.d.ts +0 -11
- package/dist/nord/NordImpl.js +0 -26
- package/dist/nord/NordUser.d.ts +0 -243
- package/dist/nord/NordUser.js +0 -481
- package/dist/nord/Subscriber.d.ts +0 -37
- package/dist/nord/Subscriber.js +0 -29
- package/dist/nord/actions.d.ts +0 -101
- package/dist/nord/actions.js +0 -254
- package/dist/nord/api/index.d.ts +0 -1
- package/dist/nord/api/index.js +0 -17
- package/dist/nord/api/orderFunctions.d.ts +0 -168
- package/dist/nord/api/orderFunctions.js +0 -133
- package/dist/nord/core.d.ts +0 -48
- package/dist/nord/core.js +0 -97
- package/dist/nord/market.d.ts +0 -36
- package/dist/nord/market.js +0 -90
- package/dist/nord/metrics.d.ts +0 -67
- package/dist/nord/metrics.js +0 -124
- package/dist/nord/queries.d.ts +0 -81
- package/dist/nord/queries.js +0 -181
- package/dist/nord/types.d.ts +0 -88
- package/dist/nord/types.js +0 -2
- package/dist/nord/websocket.d.ts +0 -49
- package/dist/nord/websocket.js +0 -107
- package/dist/operations/account.d.ts +0 -58
- package/dist/operations/account.js +0 -112
- package/dist/operations/market.d.ts +0 -65
- package/dist/operations/market.js +0 -131
- package/dist/operations/orders.d.ts +0 -57
- package/dist/operations/orders.js +0 -129
- package/dist/solana/NordUser.d.ts +0 -78
- package/dist/solana/NordUser.js +0 -196
- package/dist/solana/client.d.ts +0 -139
- package/dist/solana/client.js +0 -360
- package/dist/solana/const.d.ts +0 -23
- package/dist/solana/const.js +0 -47
- package/dist/solana/index.d.ts +0 -5
- package/dist/solana/index.js +0 -23
- package/dist/solana/types.d.ts +0 -118
- package/dist/solana/types.js +0 -16
- package/dist/solana/utils.d.ts +0 -64
- package/dist/solana/utils.js +0 -131
- package/dist/types/api.d.ts +0 -152
- package/dist/types/api.js +0 -6
- package/dist/types/config.d.ts +0 -34
- package/dist/types/config.js +0 -6
- package/dist/utils/errors.d.ts +0 -96
- package/dist/utils/errors.js +0 -132
- package/dist/utils/http.d.ts +0 -35
- package/dist/utils/http.js +0 -105
- package/dist/websocket/client.d.ts +0 -93
- package/dist/websocket/client.js +0 -222
- package/dist/websocket.d.ts +0 -55
- package/dist/websocket.js +0 -211
- package/docs/interfaces/ERC20TokenInfo.html +0 -5
- 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/index.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
// Export types
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
2
|
+
export * from "./types";
|
|
3
|
+
export * from "./utils";
|
|
4
|
+
export * from "./const";
|
|
5
5
|
|
|
6
6
|
// Export Nord modules
|
|
7
|
-
export * from
|
|
7
|
+
export * from "./nord";
|
|
8
8
|
|
|
9
9
|
// Export WebSocket modules
|
|
10
|
-
export * from
|
|
10
|
+
export * from "./websocket/index";
|
|
11
11
|
|
|
12
12
|
// Export bridge modules
|
|
13
|
-
export * from
|
|
14
|
-
export * from
|
|
13
|
+
export * from "./bridge/client";
|
|
14
|
+
export * from "./bridge/types";
|
|
15
15
|
export {
|
|
16
16
|
bridgeToBN,
|
|
17
17
|
fromBN,
|
|
@@ -21,4 +21,4 @@ export {
|
|
|
21
21
|
bufferToHex,
|
|
22
22
|
hexToBuffer,
|
|
23
23
|
shortenPublicKey,
|
|
24
|
-
} from
|
|
24
|
+
} from "./bridge/utils";
|
package/src/nord/api/actions.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import Decimal from
|
|
2
|
-
import * as proto from
|
|
3
|
-
import { FillMode, fillModeToProtoFillMode, KeyType, Side } from
|
|
1
|
+
import Decimal from "decimal.js";
|
|
2
|
+
import * as proto from "../../gen/nord";
|
|
3
|
+
import { FillMode, fillModeToProtoFillMode, KeyType, Side } from "../../types";
|
|
4
4
|
import {
|
|
5
5
|
assert,
|
|
6
6
|
bigIntToProtoU128,
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
SESSION_TTL,
|
|
14
14
|
toScaledU128,
|
|
15
15
|
toScaledU64,
|
|
16
|
-
} from
|
|
16
|
+
} from "../../utils";
|
|
17
17
|
|
|
18
18
|
async function sessionSign(
|
|
19
19
|
signFn: (message: Uint8Array) => Promise<Uint8Array>,
|
|
@@ -36,9 +36,9 @@ function makeSendHttp(
|
|
|
36
36
|
): (encoded: Uint8Array) => Promise<Uint8Array> {
|
|
37
37
|
return async (body) => {
|
|
38
38
|
const response = await checkedFetch(`${serverUrl}/action`, {
|
|
39
|
-
method:
|
|
39
|
+
method: "POST",
|
|
40
40
|
headers: {
|
|
41
|
-
|
|
41
|
+
"Content-Type": "application/json",
|
|
42
42
|
},
|
|
43
43
|
body,
|
|
44
44
|
});
|
|
@@ -57,7 +57,7 @@ async function sendAction(
|
|
|
57
57
|
const rawResp = await sendFn(body);
|
|
58
58
|
const resp: proto.Receipt = decodeLengthDelimited(rawResp, proto.Receipt);
|
|
59
59
|
|
|
60
|
-
if (resp.kind?.$case ===
|
|
60
|
+
if (resp.kind?.$case === "err") {
|
|
61
61
|
throw new Error(
|
|
62
62
|
`Could not ${actionErrorDesc}, reason: ${proto.errorToJSON(resp.kind.value)}`,
|
|
63
63
|
);
|
|
@@ -87,7 +87,7 @@ async function createSessionImpl(
|
|
|
87
87
|
expiry = params.expiryTimestamp;
|
|
88
88
|
assert(
|
|
89
89
|
expiry > currentTimestamp,
|
|
90
|
-
|
|
90
|
+
"Cannot set expiry timestamp in the past",
|
|
91
91
|
);
|
|
92
92
|
} else {
|
|
93
93
|
expiry = currentTimestamp + SESSION_TTL;
|
|
@@ -97,7 +97,7 @@ async function createSessionImpl(
|
|
|
97
97
|
currentTimestamp,
|
|
98
98
|
nonce,
|
|
99
99
|
kind: {
|
|
100
|
-
$case:
|
|
100
|
+
$case: "createSession",
|
|
101
101
|
value: {
|
|
102
102
|
userPubkey: params.userPubkey,
|
|
103
103
|
blstPubkey: params.sessionPubkey,
|
|
@@ -110,10 +110,10 @@ async function createSessionImpl(
|
|
|
110
110
|
sendFn,
|
|
111
111
|
(m) => walletSign(walletSignFn, m),
|
|
112
112
|
action,
|
|
113
|
-
|
|
113
|
+
"create a new session",
|
|
114
114
|
);
|
|
115
115
|
|
|
116
|
-
if (resp.kind?.$case ===
|
|
116
|
+
if (resp.kind?.$case === "createSessionResult") {
|
|
117
117
|
return resp.kind.value.sessionId;
|
|
118
118
|
} else {
|
|
119
119
|
throw new Error(`Unexpected receipt kind ${resp.kind?.$case}`);
|
|
@@ -154,7 +154,7 @@ async function revokeSessionImpl(
|
|
|
154
154
|
currentTimestamp,
|
|
155
155
|
nonce,
|
|
156
156
|
kind: {
|
|
157
|
-
$case:
|
|
157
|
+
$case: "revokeSession",
|
|
158
158
|
value: {
|
|
159
159
|
sessionId: BigInt(params.sessionId),
|
|
160
160
|
},
|
|
@@ -165,7 +165,7 @@ async function revokeSessionImpl(
|
|
|
165
165
|
sendFn,
|
|
166
166
|
(m) => walletSign(walletSignFn, m),
|
|
167
167
|
action,
|
|
168
|
-
|
|
168
|
+
"create a new session",
|
|
169
169
|
);
|
|
170
170
|
}
|
|
171
171
|
|
|
@@ -202,14 +202,14 @@ async function withdrawImpl(
|
|
|
202
202
|
const amount = toScaledU64(params.amount, params.sizeDecimals);
|
|
203
203
|
|
|
204
204
|
if (amount <= 0) {
|
|
205
|
-
throw new Error(
|
|
205
|
+
throw new Error("Withdraw amount must be positive");
|
|
206
206
|
}
|
|
207
207
|
|
|
208
208
|
const action: proto.Action = {
|
|
209
209
|
currentTimestamp,
|
|
210
210
|
nonce,
|
|
211
211
|
kind: {
|
|
212
|
-
$case:
|
|
212
|
+
$case: "withdraw",
|
|
213
213
|
value: {
|
|
214
214
|
sessionId: BigInt(params.sessionId),
|
|
215
215
|
tokenId: params.tokenId,
|
|
@@ -218,7 +218,7 @@ async function withdrawImpl(
|
|
|
218
218
|
},
|
|
219
219
|
};
|
|
220
220
|
|
|
221
|
-
await sendAction(sendFn, (m) => sessionSign(signFn, m), action,
|
|
221
|
+
await sendAction(sendFn, (m) => sessionSign(signFn, m), action, "withdraw");
|
|
222
222
|
}
|
|
223
223
|
|
|
224
224
|
export async function withdraw(
|
|
@@ -276,7 +276,7 @@ async function placeOrderImpl(
|
|
|
276
276
|
currentTimestamp,
|
|
277
277
|
nonce,
|
|
278
278
|
kind: {
|
|
279
|
-
$case:
|
|
279
|
+
$case: "placeOrder",
|
|
280
280
|
value: {
|
|
281
281
|
sessionId: BigInt(params.sessionId),
|
|
282
282
|
senderAccountId: params.senderId,
|
|
@@ -297,10 +297,10 @@ async function placeOrderImpl(
|
|
|
297
297
|
sendFn,
|
|
298
298
|
(m) => sessionSign(signFn, m),
|
|
299
299
|
action,
|
|
300
|
-
|
|
300
|
+
"place the order",
|
|
301
301
|
);
|
|
302
302
|
|
|
303
|
-
if (resp.kind?.$case ===
|
|
303
|
+
if (resp.kind?.$case === "placeOrderResult") {
|
|
304
304
|
return resp.kind.value.posted?.orderId;
|
|
305
305
|
} else {
|
|
306
306
|
throw new Error(`Unexpected receipt kind ${resp.kind?.$case}`);
|
|
@@ -353,7 +353,7 @@ async function cancelOrderImpl(
|
|
|
353
353
|
currentTimestamp,
|
|
354
354
|
nonce: nonce,
|
|
355
355
|
kind: {
|
|
356
|
-
$case:
|
|
356
|
+
$case: "cancelOrderById",
|
|
357
357
|
value: {
|
|
358
358
|
orderId: BigInt(params.orderId),
|
|
359
359
|
sessionId: BigInt(params.sessionId),
|
|
@@ -367,10 +367,10 @@ async function cancelOrderImpl(
|
|
|
367
367
|
sendFn,
|
|
368
368
|
(m) => sessionSign(signFn, m),
|
|
369
369
|
action,
|
|
370
|
-
|
|
370
|
+
"cancel the order",
|
|
371
371
|
);
|
|
372
372
|
|
|
373
|
-
if (resp.kind?.$case ===
|
|
373
|
+
if (resp.kind?.$case === "cancelOrderResult") {
|
|
374
374
|
return resp.kind.value.orderId;
|
|
375
375
|
} else {
|
|
376
376
|
throw new Error(`Unexpected receipt kind ${resp.kind?.$case}`);
|
|
@@ -416,7 +416,7 @@ async function transferImpl(
|
|
|
416
416
|
currentTimestamp,
|
|
417
417
|
nonce: nonce,
|
|
418
418
|
kind: {
|
|
419
|
-
$case:
|
|
419
|
+
$case: "transfer",
|
|
420
420
|
value: {
|
|
421
421
|
sessionId: BigInt(params.sessionId),
|
|
422
422
|
fromAccountId: params.fromAccountId,
|
|
@@ -431,10 +431,10 @@ async function transferImpl(
|
|
|
431
431
|
sendFn,
|
|
432
432
|
(m) => sessionSign(signFn, m),
|
|
433
433
|
action,
|
|
434
|
-
|
|
434
|
+
"transfer asset to other account",
|
|
435
435
|
);
|
|
436
436
|
|
|
437
|
-
if (resp.kind?.$case ===
|
|
437
|
+
if (resp.kind?.$case === "transferred") {
|
|
438
438
|
if (resp.kind.value.accountCreated) {
|
|
439
439
|
return resp.kind.value.toUserAccount;
|
|
440
440
|
} else {
|
package/src/nord/api/core.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Account, Info
|
|
2
|
-
import { checkedFetch } from
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { Account, Info } from "../../types";
|
|
2
|
+
import { checkedFetch } from "../../utils";
|
|
3
|
+
import { NordWebSocketClient } from "../../websocket/index";
|
|
4
|
+
import { NordError } from "../utils/NordError";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Get the current timestamp from the Nord server
|
|
@@ -15,7 +15,7 @@ export async function getTimestamp(webServerUrl: string): Promise<bigint> {
|
|
|
15
15
|
const response = await checkedFetch(`${webServerUrl}/timestamp`);
|
|
16
16
|
return BigInt(await response.json());
|
|
17
17
|
} catch (error) {
|
|
18
|
-
throw new NordError(
|
|
18
|
+
throw new NordError("Failed to get timestamp", { cause: error });
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -32,7 +32,7 @@ export async function getActionNonce(webServerUrl: string): Promise<number> {
|
|
|
32
32
|
const data = await response.json();
|
|
33
33
|
return data.nonce;
|
|
34
34
|
} catch (error) {
|
|
35
|
-
throw new NordError(
|
|
35
|
+
throw new NordError("Failed to get action nonce", { cause: error });
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
|
|
@@ -48,7 +48,7 @@ export async function getInfo(webServerUrl: string): Promise<Info> {
|
|
|
48
48
|
const response = await checkedFetch(`${webServerUrl}/info`);
|
|
49
49
|
return await response.json();
|
|
50
50
|
} catch (error) {
|
|
51
|
-
throw new NordError(
|
|
51
|
+
throw new NordError("Failed to get info", { cause: error });
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -89,28 +89,28 @@ export async function getAccount(
|
|
|
89
89
|
*/
|
|
90
90
|
export function initWebSocketClient(
|
|
91
91
|
webServerUrl: string,
|
|
92
|
-
endpoint?:
|
|
92
|
+
endpoint?: "trades" | "deltas" | "user",
|
|
93
93
|
initialSubscriptions?: string[],
|
|
94
94
|
): NordWebSocketClient {
|
|
95
95
|
try {
|
|
96
96
|
// Convert HTTP URL to WebSocket URL with specific endpoint
|
|
97
97
|
// If no specific endpoint is provided, we'll connect to trades by default
|
|
98
|
-
const specificEndpoint = endpoint ||
|
|
98
|
+
const specificEndpoint = endpoint || "trades";
|
|
99
99
|
const wsUrl =
|
|
100
|
-
webServerUrl.replace(/^http/,
|
|
100
|
+
webServerUrl.replace(/^http/, "ws") + `/ws/${specificEndpoint}`;
|
|
101
101
|
console.log(`Initializing WebSocket client with URL: ${wsUrl}`);
|
|
102
102
|
|
|
103
103
|
// Create and connect the WebSocket client
|
|
104
104
|
const ws = new NordWebSocketClient(wsUrl);
|
|
105
105
|
|
|
106
106
|
// Add error handler
|
|
107
|
-
ws.on(
|
|
108
|
-
console.error(
|
|
107
|
+
ws.on("error", (error) => {
|
|
108
|
+
console.error("Nord WebSocket error:", error);
|
|
109
109
|
});
|
|
110
110
|
|
|
111
111
|
// Add connected handler for debugging
|
|
112
|
-
ws.on(
|
|
113
|
-
console.log(
|
|
112
|
+
ws.on("connected", () => {
|
|
113
|
+
console.log("Nord WebSocket connected successfully");
|
|
114
114
|
|
|
115
115
|
// Subscribe to initial subscriptions if provided
|
|
116
116
|
if (initialSubscriptions && initialSubscriptions.length > 0) {
|
|
@@ -122,8 +122,8 @@ export function initWebSocketClient(
|
|
|
122
122
|
ws.connect();
|
|
123
123
|
return ws;
|
|
124
124
|
} catch (error) {
|
|
125
|
-
console.error(
|
|
126
|
-
throw new NordError(
|
|
125
|
+
console.error("Failed to initialize WebSocket client:", error);
|
|
126
|
+
throw new NordError("Failed to initialize WebSocket client", {
|
|
127
127
|
cause: error,
|
|
128
128
|
});
|
|
129
129
|
}
|
package/src/nord/api/market.ts
CHANGED
|
@@ -6,9 +6,9 @@ import {
|
|
|
6
6
|
TradesResponse,
|
|
7
7
|
UserAccountIdsQuery,
|
|
8
8
|
UserAccountIdsResponse,
|
|
9
|
-
} from
|
|
10
|
-
import { checkedFetch } from
|
|
11
|
-
import { NordError } from
|
|
9
|
+
} from "../../types";
|
|
10
|
+
import { checkedFetch } from "../../utils";
|
|
11
|
+
import { NordError } from "../utils/NordError";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Get market statistics
|
|
@@ -24,7 +24,7 @@ export async function marketsStats(
|
|
|
24
24
|
const response = await checkedFetch(`${webServerUrl}/stats`);
|
|
25
25
|
return await response.json();
|
|
26
26
|
} catch (error) {
|
|
27
|
-
throw new NordError(
|
|
27
|
+
throw new NordError("Failed to fetch markets stats", { cause: error });
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -42,18 +42,18 @@ export async function getTrades(
|
|
|
42
42
|
): Promise<TradesResponse> {
|
|
43
43
|
try {
|
|
44
44
|
const params = new URLSearchParams();
|
|
45
|
-
params.append(
|
|
45
|
+
params.append("accountId", query.accountId.toString());
|
|
46
46
|
|
|
47
47
|
if (query.since) {
|
|
48
|
-
params.append(
|
|
48
|
+
params.append("since", query.since);
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
if (query.until) {
|
|
52
|
-
params.append(
|
|
52
|
+
params.append("until", query.until);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
if (query.pageId) {
|
|
56
|
-
params.append(
|
|
56
|
+
params.append("pageId", query.pageId);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
const response = await checkedFetch(
|
|
@@ -61,7 +61,7 @@ export async function getTrades(
|
|
|
61
61
|
);
|
|
62
62
|
return await response.json();
|
|
63
63
|
} catch (error) {
|
|
64
|
-
throw new NordError(
|
|
64
|
+
throw new NordError("Failed to get trades", { cause: error });
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
|
@@ -79,14 +79,14 @@ export async function getUserAccountIds(
|
|
|
79
79
|
): Promise<UserAccountIdsResponse> {
|
|
80
80
|
try {
|
|
81
81
|
const params = new URLSearchParams();
|
|
82
|
-
params.append(
|
|
82
|
+
params.append("pubkey", query.pubkey);
|
|
83
83
|
|
|
84
84
|
const response = await checkedFetch(
|
|
85
85
|
`${webServerUrl}/user?${params.toString()}`,
|
|
86
86
|
);
|
|
87
87
|
return await response.json();
|
|
88
88
|
} catch (error) {
|
|
89
|
-
throw new NordError(
|
|
89
|
+
throw new NordError("Failed to get user account IDs", { cause: error });
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
|
|
@@ -106,12 +106,12 @@ export async function getOrderbook(
|
|
|
106
106
|
const params = new URLSearchParams();
|
|
107
107
|
|
|
108
108
|
if (query.symbol) {
|
|
109
|
-
params.append(
|
|
109
|
+
params.append("symbol", query.symbol);
|
|
110
110
|
} else if (query.market_id !== undefined) {
|
|
111
|
-
params.append(
|
|
111
|
+
params.append("market_id", query.market_id.toString());
|
|
112
112
|
} else {
|
|
113
113
|
throw new NordError(
|
|
114
|
-
|
|
114
|
+
"Either symbol or market_id must be provided for orderbook query",
|
|
115
115
|
);
|
|
116
116
|
}
|
|
117
117
|
|
|
@@ -120,6 +120,6 @@ export async function getOrderbook(
|
|
|
120
120
|
);
|
|
121
121
|
return await response.json();
|
|
122
122
|
} catch (error) {
|
|
123
|
-
throw new NordError(
|
|
123
|
+
throw new NordError("Failed to get orderbook", { cause: error });
|
|
124
124
|
}
|
|
125
125
|
}
|
package/src/nord/api/metrics.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { AggregateMetrics, PeakTpsPeriodUnit } from
|
|
2
|
-
import { checkedFetch } from
|
|
3
|
-
import { NordError } from
|
|
1
|
+
import { AggregateMetrics, PeakTpsPeriodUnit } from "../../types";
|
|
2
|
+
import { checkedFetch } from "../../utils";
|
|
3
|
+
import { NordError } from "../utils/NordError";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Time periods for metrics queries
|
|
7
7
|
*/
|
|
8
8
|
export enum MetricPeriod {
|
|
9
|
-
ONE_MINUTE =
|
|
10
|
-
FIVE_MINUTES =
|
|
11
|
-
FIFTEEN_MINUTES =
|
|
12
|
-
ONE_HOUR =
|
|
13
|
-
FOUR_HOURS =
|
|
14
|
-
ONE_DAY =
|
|
15
|
-
ONE_WEEK =
|
|
9
|
+
ONE_MINUTE = "1m",
|
|
10
|
+
FIVE_MINUTES = "5m",
|
|
11
|
+
FIFTEEN_MINUTES = "15m",
|
|
12
|
+
ONE_HOUR = "1h",
|
|
13
|
+
FOUR_HOURS = "4h",
|
|
14
|
+
ONE_DAY = "24h",
|
|
15
|
+
ONE_WEEK = "7d",
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -35,7 +35,7 @@ export async function aggregateMetrics(
|
|
|
35
35
|
);
|
|
36
36
|
return await response.json();
|
|
37
37
|
} catch (error) {
|
|
38
|
-
throw new NordError(
|
|
38
|
+
throw new NordError("Failed to fetch aggregate metrics", { cause: error });
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|
|
@@ -49,7 +49,7 @@ export async function aggregateMetrics(
|
|
|
49
49
|
*/
|
|
50
50
|
export async function getCurrentTps(
|
|
51
51
|
webServerUrl: string,
|
|
52
|
-
period: string =
|
|
52
|
+
period: string = "1m",
|
|
53
53
|
): Promise<number> {
|
|
54
54
|
try {
|
|
55
55
|
return await queryPrometheus(
|
|
@@ -73,7 +73,7 @@ export async function getCurrentTps(
|
|
|
73
73
|
*/
|
|
74
74
|
export async function getPeakTps(
|
|
75
75
|
webServerUrl: string,
|
|
76
|
-
period: string =
|
|
76
|
+
period: string = "24h",
|
|
77
77
|
): Promise<number> {
|
|
78
78
|
try {
|
|
79
79
|
return await queryPrometheus(
|
|
@@ -97,7 +97,7 @@ export async function getPeakTps(
|
|
|
97
97
|
*/
|
|
98
98
|
export async function getMedianLatency(
|
|
99
99
|
webServerUrl: string,
|
|
100
|
-
period: string =
|
|
100
|
+
period: string = "1m",
|
|
101
101
|
): Promise<number> {
|
|
102
102
|
try {
|
|
103
103
|
return await queryPrometheus(
|
|
@@ -122,9 +122,9 @@ export async function getTotalTransactions(
|
|
|
122
122
|
webServerUrl: string,
|
|
123
123
|
): Promise<number> {
|
|
124
124
|
try {
|
|
125
|
-
return await queryPrometheus(webServerUrl,
|
|
125
|
+
return await queryPrometheus(webServerUrl, "sum(nord_tx_count)");
|
|
126
126
|
} catch (error) {
|
|
127
|
-
throw new NordError(
|
|
127
|
+
throw new NordError("Failed to get total transactions", { cause: error });
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
|
package/src/nord/api/queries.ts
CHANGED
|
@@ -8,9 +8,9 @@ import {
|
|
|
8
8
|
RollmanActionResponse,
|
|
9
9
|
RollmanActionsResponse,
|
|
10
10
|
RollmanBlockResponse,
|
|
11
|
-
} from
|
|
12
|
-
import { checkedFetch } from
|
|
13
|
-
import { NordError } from
|
|
11
|
+
} from "../../types";
|
|
12
|
+
import { checkedFetch } from "../../utils";
|
|
13
|
+
import { NordError } from "../utils/NordError";
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Query a specific block
|
|
@@ -27,7 +27,7 @@ export async function queryBlock(
|
|
|
27
27
|
try {
|
|
28
28
|
const params = new URLSearchParams();
|
|
29
29
|
if (query.block_number !== undefined) {
|
|
30
|
-
params.append(
|
|
30
|
+
params.append("block_height", query.block_number.toString());
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
const response = await checkedFetch(
|
|
@@ -35,7 +35,7 @@ export async function queryBlock(
|
|
|
35
35
|
);
|
|
36
36
|
return await response.json();
|
|
37
37
|
} catch (error) {
|
|
38
|
-
throw new NordError(
|
|
38
|
+
throw new NordError("Failed to query block", { cause: error });
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|
|
@@ -53,7 +53,7 @@ export async function queryLastNBlocks(
|
|
|
53
53
|
const response = await checkedFetch(`${webServerUrl}/blocks`);
|
|
54
54
|
return await response.json();
|
|
55
55
|
} catch (error) {
|
|
56
|
-
throw new NordError(
|
|
56
|
+
throw new NordError("Failed to query last N blocks", { cause: error });
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
|
@@ -96,7 +96,7 @@ export async function queryAction(
|
|
|
96
96
|
try {
|
|
97
97
|
const params = new URLSearchParams();
|
|
98
98
|
if (query.action_id !== undefined) {
|
|
99
|
-
params.append(
|
|
99
|
+
params.append("action_id", query.action_id.toString());
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
const response = await checkedFetch(
|
|
@@ -104,7 +104,7 @@ export async function queryAction(
|
|
|
104
104
|
);
|
|
105
105
|
return await response.json();
|
|
106
106
|
} catch (error) {
|
|
107
|
-
throw new NordError(
|
|
107
|
+
throw new NordError("Failed to query action", { cause: error });
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
|
|
@@ -147,7 +147,7 @@ export async function blockQueryRollman(
|
|
|
147
147
|
try {
|
|
148
148
|
const params = new URLSearchParams();
|
|
149
149
|
if (query.block_number !== undefined) {
|
|
150
|
-
params.append(
|
|
150
|
+
params.append("block_height", query.block_number.toString());
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
const response = await checkedFetch(
|
|
@@ -155,7 +155,7 @@ export async function blockQueryRollman(
|
|
|
155
155
|
);
|
|
156
156
|
return await response.json();
|
|
157
157
|
} catch (error) {
|
|
158
|
-
throw new NordError(
|
|
158
|
+
throw new NordError("Failed to query Rollman block", { cause: error });
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
|
|
@@ -199,7 +199,7 @@ export async function actionQueryRollman(
|
|
|
199
199
|
try {
|
|
200
200
|
const params = new URLSearchParams();
|
|
201
201
|
if (query.action_id !== undefined) {
|
|
202
|
-
params.append(
|
|
202
|
+
params.append("action_id", query.action_id.toString());
|
|
203
203
|
}
|
|
204
204
|
|
|
205
205
|
const response = await checkedFetch(
|
|
@@ -207,7 +207,7 @@ export async function actionQueryRollman(
|
|
|
207
207
|
);
|
|
208
208
|
return await response.json();
|
|
209
209
|
} catch (error) {
|
|
210
|
-
throw new NordError(
|
|
210
|
+
throw new NordError("Failed to query Rollman action", { cause: error });
|
|
211
211
|
}
|
|
212
212
|
}
|
|
213
213
|
|