@n1xyz/nord-ts 0.0.14 → 0.0.16-29f6652
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/.prettierignore +1 -0
- package/README.md +9 -6
- package/dist/bridge/client.d.ts +8 -7
- package/dist/bridge/client.js +39 -37
- package/dist/bridge/index.d.ts +1 -2
- package/dist/bridge/index.js +2 -2
- package/dist/bridge/types.d.ts +7 -3
- package/dist/bridge/types.js +3 -1
- package/dist/gen/common.js +1 -1
- package/dist/gen/nord.d.ts +74 -25
- package/dist/gen/nord.js +498 -78
- package/dist/idl/bridge.json +1493 -0
- package/dist/idl/index.d.ts +585 -0
- package/dist/idl/index.js +8 -0
- package/dist/nord/api/core.js +7 -5
- package/dist/nord/api/metrics.js +7 -4
- package/dist/nord/client/Nord.d.ts +19 -5
- package/dist/nord/client/Nord.js +50 -23
- package/dist/nord/client/NordUser.d.ts +1 -1
- package/dist/nord/client/NordUser.js +19 -16
- package/dist/types.d.ts +3 -3
- package/dist/websocket/NordWebSocketClient.js +0 -2
- package/docs/assets/hierarchy.js +1 -1
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/Nord.html +99 -100
- package/docs/classes/NordError.html +6 -6
- package/docs/classes/NordUser.html +49 -54
- package/docs/classes/NordWebSocketClient.html +6 -11
- package/docs/classes/SolanaBridgeClient.html +32 -27
- package/docs/classes/Subscriber.html +3 -3
- package/docs/enums/FillMode.html +2 -2
- package/docs/enums/KeyType.html +2 -2
- package/docs/enums/MetricPeriod.html +2 -2
- package/docs/enums/PdaSeedType.html +5 -3
- package/docs/enums/PeakTpsPeriodUnit.html +2 -2
- package/docs/enums/Side.html +2 -2
- package/docs/enums/WebSocketMessageType.html +3 -3
- package/docs/functions/actionQueryRollman.html +1 -1
- package/docs/functions/actionsQueryRollman.html +1 -1
- package/docs/functions/aggregateMetrics-1.html +1 -1
- package/docs/functions/assert.html +1 -1
- package/docs/functions/bigIntToProtoU128.html +1 -1
- package/docs/functions/bridgeToBN.html +1 -1
- package/docs/functions/bufferToHex.html +1 -1
- package/docs/functions/cancelOrder.html +1 -1
- package/docs/functions/checkPubKeyLength.html +1 -1
- package/docs/functions/checkedFetch.html +1 -1
- package/docs/functions/createSession.html +1 -1
- package/docs/functions/decodeLengthDelimited.html +1 -1
- package/docs/functions/encodeLengthDelimited.html +1 -1
- package/docs/functions/fillModeToProtoFillMode.html +1 -1
- package/docs/functions/findMarket.html +1 -1
- package/docs/functions/findPda.html +1 -1
- package/docs/functions/findToken.html +1 -1
- package/docs/functions/fromBN.html +1 -1
- package/docs/functions/getAccount.html +1 -1
- package/docs/functions/getActionNonce.html +1 -1
- package/docs/functions/getCurrentTps.html +1 -1
- package/docs/functions/getInfo.html +1 -1
- package/docs/functions/{queryLastNBlocks.html → getLastActionId.html} +3 -3
- package/docs/functions/getMedianLatency.html +1 -1
- package/docs/functions/getOrderbook.html +1 -1
- package/docs/functions/getPeakTps.html +1 -1
- package/docs/functions/getTimestamp.html +1 -1
- package/docs/functions/getTotalTransactions.html +1 -1
- package/docs/functions/getTrades.html +1 -1
- package/docs/functions/getUserAccountIds.html +1 -1
- package/docs/functions/hexToBuffer.html +1 -1
- package/docs/functions/initWebSocketClient.html +9 -9
- package/docs/functions/keypairFromPrivateKey.html +1 -1
- package/docs/functions/makeSigningFunction.html +1 -1
- package/docs/functions/makeWalletSignFn.html +1 -1
- package/docs/functions/marketsStats.html +1 -1
- package/docs/functions/optExpect.html +1 -1
- package/docs/functions/optMap.html +1 -1
- package/docs/functions/optUnwrap.html +1 -1
- package/docs/functions/panic.html +1 -1
- package/docs/functions/placeOrder.html +1 -1
- package/docs/functions/queryAction.html +1 -1
- package/docs/functions/queryPrometheus.html +1 -1
- package/docs/functions/queryRecentActions.html +4 -3
- package/docs/functions/revokeSession.html +1 -1
- package/docs/functions/shortenPublicKey.html +1 -1
- package/docs/functions/signAction.html +1 -1
- package/docs/functions/toBN.html +1 -1
- package/docs/functions/toScaledU128.html +1 -1
- package/docs/functions/toScaledU64.html +1 -1
- package/docs/functions/transfer.html +1 -1
- package/docs/functions/withdraw.html +1 -1
- package/docs/hierarchy.html +1 -1
- package/docs/index.html +2 -2
- package/docs/interfaces/Account.html +2 -2
- package/docs/interfaces/ActionInfo.html +2 -2
- package/docs/interfaces/ActionNonceResponse.html +2 -2
- package/docs/interfaces/ActionQuery.html +2 -2
- package/docs/interfaces/ActionResponse.html +2 -2
- package/docs/interfaces/ActionsExtendedInfo.html +2 -2
- package/docs/interfaces/ActionsQuery.html +2 -2
- package/docs/interfaces/ActionsResponse.html +2 -2
- package/docs/interfaces/AggregateMetrics.html +2 -2
- package/docs/interfaces/BlockFacts.html +5 -5
- package/docs/interfaces/BlockQuery.html +2 -2
- package/docs/interfaces/BlockResponse.html +2 -2
- package/docs/interfaces/BlockSummary.html +2 -2
- package/docs/interfaces/BlockSummaryResponse.html +2 -2
- package/docs/interfaces/DeltaEvent.html +2 -2
- package/docs/interfaces/DepositSplParams.html +6 -6
- package/docs/interfaces/Info.html +2 -2
- package/docs/interfaces/Market.html +2 -2
- package/docs/interfaces/MarketStats.html +2 -2
- package/docs/interfaces/MarketsStatsResponse.html +2 -2
- package/docs/interfaces/NordConfig.html +19 -9
- package/docs/interfaces/NordWebSocketClientEvents.html +2 -2
- package/docs/interfaces/NordWebSocketEvents.html +3 -3
- package/docs/interfaces/Order.html +2 -2
- package/docs/interfaces/OrderInfo.html +2 -2
- package/docs/interfaces/OrderbookEntry.html +2 -2
- package/docs/interfaces/OrderbookQuery.html +2 -2
- package/docs/interfaces/OrderbookResponse.html +2 -2
- package/docs/interfaces/OrderbookSubscription.html +5 -5
- package/docs/interfaces/PerpMarketStats.html +2 -2
- package/docs/interfaces/RollmanActionExtendedInfo.html +2 -2
- package/docs/interfaces/RollmanActionInfo.html +2 -2
- package/docs/interfaces/RollmanActionResponse.html +2 -2
- package/docs/interfaces/RollmanActionsResponse.html +2 -2
- package/docs/interfaces/RollmanBlockResponse.html +2 -2
- package/docs/interfaces/SPLTokenInfo.html +5 -5
- package/docs/interfaces/SolanaBridgeConfig.html +8 -6
- package/docs/interfaces/StateFacts.html +5 -5
- package/docs/interfaces/SubscriberConfig.html +2 -2
- package/docs/interfaces/TimestampResponse.html +2 -2
- package/docs/interfaces/Token.html +2 -2
- package/docs/interfaces/TokenInfo.html +3 -2
- package/docs/interfaces/Trade.html +2 -2
- package/docs/interfaces/TradeSubscription.html +5 -5
- package/docs/interfaces/Trades.html +2 -2
- package/docs/interfaces/TradesQuery.html +2 -2
- package/docs/interfaces/TradesResponse.html +2 -2
- package/docs/interfaces/TransferParams.html +4 -4
- package/docs/interfaces/UserAccountIdsQuery.html +2 -2
- package/docs/interfaces/UserAccountIdsResponse.html +2 -2
- package/docs/interfaces/WebSocketAccountUpdate.html +6 -0
- package/docs/interfaces/WebSocketDeltaUpdate.html +3 -3
- package/docs/interfaces/WebSocketSubscription.html +3 -3
- package/docs/interfaces/WebSocketTradeUpdate.html +3 -3
- package/docs/interfaces/WithdrawalClaim.html +7 -7
- package/docs/interfaces/WithdrawalParams.html +4 -4
- package/docs/modules.html +1 -1
- package/docs/types/BigIntValue.html +1 -1
- package/docs/types/SubscriptionPattern.html +4 -0
- package/docs/types/SubscriptionType.html +2 -0
- package/docs/types/WebSocketMessage.html +1 -1
- 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 +1 -1
- package/idl-generate.sh +4 -0
- package/package.json +6 -3
- package/src/bridge/client.ts +55 -43
- package/src/bridge/index.ts +1 -2
- package/src/bridge/types.ts +7 -3
- package/src/gen/common.ts +1 -1
- package/src/gen/nord.ts +567 -75
- package/src/idl/bridge.json +1493 -0
- package/src/idl/index.ts +2 -0
- package/src/nord/api/core.ts +1 -3
- package/src/nord/api/metrics.ts +2 -0
- package/src/nord/client/Nord.ts +49 -13
- package/src/nord/client/NordUser.ts +52 -59
- package/src/types.ts +2 -2
- package/src/websocket/NordWebSocketClient.ts +0 -2
- package/tsconfig.json +1 -1
- package/dist/idl/bridge.d.ts +0 -2
- package/dist/idl/bridge.js +0 -930
- package/docs/functions/blockQueryRollman.html +0 -6
- package/docs/functions/blockSummaryQueryRollman.html +0 -6
- package/docs/functions/queryBlock.html +0 -6
- package/docs/functions/queryRecentBlocks.html +0 -6
- package/docs/interfaces/WebSocketUserUpdate.html +0 -6
- package/src/idl/bridge.ts +0 -929
package/src/idl/index.ts
ADDED
package/src/nord/api/core.ts
CHANGED
|
@@ -65,9 +65,7 @@ export async function getAccount(
|
|
|
65
65
|
accountId: number,
|
|
66
66
|
): Promise<Account> {
|
|
67
67
|
try {
|
|
68
|
-
const response = await checkedFetch(
|
|
69
|
-
`${webServerUrl}/account?account_id=${accountId}`,
|
|
70
|
-
);
|
|
68
|
+
const response = await checkedFetch(`${webServerUrl}/account/${accountId}`);
|
|
71
69
|
return await response.json();
|
|
72
70
|
} catch (error) {
|
|
73
71
|
throw new NordError(`Failed to get account ${accountId}`, { cause: error });
|
package/src/nord/api/metrics.ts
CHANGED
|
@@ -99,6 +99,7 @@ function calculateTps(text: string): number {
|
|
|
99
99
|
*/
|
|
100
100
|
function calculatePeakTps(text: string): number {
|
|
101
101
|
// For peak TPS, we'll use a simple heuristic: 2x the current TPS estimate
|
|
102
|
+
// TODO: fix this
|
|
102
103
|
return calculateTps(text) * 2;
|
|
103
104
|
}
|
|
104
105
|
|
|
@@ -109,6 +110,7 @@ function calculatePeakTps(text: string): number {
|
|
|
109
110
|
* @returns Average latency in seconds
|
|
110
111
|
*/
|
|
111
112
|
function extractLatency(text: string): number {
|
|
113
|
+
// TODO: fix - using average for latency is kinda wack. ok to merge for now but should change.
|
|
112
114
|
const latencySum = extractSummaryValue(text, "nord_requests_ok_latency_sum");
|
|
113
115
|
const latencyCount = extractSummaryValue(
|
|
114
116
|
text,
|
package/src/nord/client/Nord.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EventEmitter } from "events";
|
|
2
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
2
3
|
import {
|
|
3
4
|
Account,
|
|
4
5
|
ActionQuery,
|
|
@@ -55,8 +56,11 @@ export class Nord {
|
|
|
55
56
|
/** Base URL for the Nord web server */
|
|
56
57
|
public readonly webServerUrl: string;
|
|
57
58
|
|
|
58
|
-
/**
|
|
59
|
-
public readonly
|
|
59
|
+
/** Bridge verification key */
|
|
60
|
+
public readonly bridgeVk: string;
|
|
61
|
+
|
|
62
|
+
/** Optional Solana program ID (will be derived from bridgeVk) */
|
|
63
|
+
private _solanaProgramId!: string;
|
|
60
64
|
|
|
61
65
|
/** Solana RPC URL */
|
|
62
66
|
public readonly solanaUrl: string;
|
|
@@ -75,26 +79,26 @@ export class Nord {
|
|
|
75
79
|
*
|
|
76
80
|
* @param config - Configuration options for the Nord client
|
|
77
81
|
* @param config.webServerUrl - Base URL for the Nord web server
|
|
78
|
-
* @param config.
|
|
82
|
+
* @param config.bridgeVk - Bridge verification key
|
|
79
83
|
* @param config.solanaUrl - Solana cluster URL
|
|
80
84
|
* @throws {Error} If required configuration is missing
|
|
81
85
|
*/
|
|
82
|
-
constructor(
|
|
83
|
-
if (!webServerUrl) {
|
|
86
|
+
constructor(config: NordConfig) {
|
|
87
|
+
if (!config.webServerUrl) {
|
|
84
88
|
throw new NordError("webServerUrl is required");
|
|
85
89
|
}
|
|
86
90
|
|
|
87
|
-
if (!
|
|
88
|
-
throw new NordError("
|
|
91
|
+
if (!config.bridgeVk) {
|
|
92
|
+
throw new NordError("bridgeVk is required");
|
|
89
93
|
}
|
|
90
94
|
|
|
91
|
-
if (!solanaUrl) {
|
|
95
|
+
if (!config.solanaUrl) {
|
|
92
96
|
throw new NordError("solanaUrl is required");
|
|
93
97
|
}
|
|
94
98
|
|
|
95
|
-
this.webServerUrl = webServerUrl;
|
|
96
|
-
this.
|
|
97
|
-
this.solanaUrl = solanaUrl;
|
|
99
|
+
this.webServerUrl = config.webServerUrl;
|
|
100
|
+
this.bridgeVk = config.bridgeVk;
|
|
101
|
+
this.solanaUrl = config.solanaUrl;
|
|
98
102
|
}
|
|
99
103
|
|
|
100
104
|
/**
|
|
@@ -204,17 +208,49 @@ export class Nord {
|
|
|
204
208
|
*
|
|
205
209
|
* @param nordConfig - Configuration options for the Nord client
|
|
206
210
|
* @param nordConfig.webServerUrl - Base URL for the Nord web server
|
|
207
|
-
* @param nordConfig.
|
|
211
|
+
* @param nordConfig.bridgeVk - Bridge verification key
|
|
208
212
|
* @param nordConfig.solanaUrl - Solana cluster URL
|
|
209
213
|
* @returns Initialized Nord client
|
|
210
214
|
* @throws {NordError} If initialization fails
|
|
211
215
|
*/
|
|
212
216
|
public static async initNord(nordConfig: NordConfig): Promise<Nord> {
|
|
213
217
|
const nord = new Nord(nordConfig);
|
|
214
|
-
await nord.
|
|
218
|
+
await nord.init();
|
|
215
219
|
return nord;
|
|
216
220
|
}
|
|
217
221
|
|
|
222
|
+
/**
|
|
223
|
+
* Initialize the Nord client by deriving program ID and fetching info
|
|
224
|
+
* @private
|
|
225
|
+
*/
|
|
226
|
+
private async init(): Promise<void> {
|
|
227
|
+
const connection = new Connection(this.solanaUrl);
|
|
228
|
+
const bridgeVkPubkey = new PublicKey(this.bridgeVk);
|
|
229
|
+
|
|
230
|
+
const bridgeAccount = await connection.getAccountInfo(bridgeVkPubkey);
|
|
231
|
+
if (!bridgeAccount) {
|
|
232
|
+
throw new NordError(`Bridge account ${this.bridgeVk} not found`);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
this._solanaProgramId = bridgeAccount.owner.toString();
|
|
236
|
+
await this.fetchNordInfo();
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Get the Solana program ID derived from bridge VK
|
|
241
|
+
*
|
|
242
|
+
* @returns Program ID string
|
|
243
|
+
* @throws {NordError} If program ID hasn't been initialized
|
|
244
|
+
*/
|
|
245
|
+
public getSolanaProgramId(): string {
|
|
246
|
+
if (!this._solanaProgramId) {
|
|
247
|
+
throw new NordError(
|
|
248
|
+
"Solana program ID not initialized. Have you called Nord.initNord()?",
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
return this._solanaProgramId;
|
|
252
|
+
}
|
|
253
|
+
|
|
218
254
|
/**
|
|
219
255
|
* Get market statistics
|
|
220
256
|
*
|
|
@@ -6,7 +6,9 @@ import {
|
|
|
6
6
|
} from "@solana/spl-token";
|
|
7
7
|
import { Connection, Keypair, PublicKey, Transaction } from "@solana/web3.js";
|
|
8
8
|
import Decimal from "decimal.js";
|
|
9
|
-
import * as
|
|
9
|
+
import * as ed from "@noble/ed25519";
|
|
10
|
+
import { sha512 } from "@noble/hashes/sha512";
|
|
11
|
+
ed.etc.sha512Sync = sha512;
|
|
10
12
|
import { SolanaBridgeClient } from "../../bridge/client";
|
|
11
13
|
import { SPLTokenInfo } from "../../bridge/types";
|
|
12
14
|
import { keypairFromPrivateKey } from "../../bridge/utils";
|
|
@@ -300,7 +302,7 @@ export class NordUser {
|
|
|
300
302
|
if (
|
|
301
303
|
!this.getSolanaPublicKey() ||
|
|
302
304
|
!this.connection ||
|
|
303
|
-
!this.nord.
|
|
305
|
+
!this.nord.getSolanaProgramId()
|
|
304
306
|
) {
|
|
305
307
|
throw new NordError(
|
|
306
308
|
"Solana public key, connection, and program ID are required to initialize bridge client",
|
|
@@ -331,9 +333,10 @@ export class NordUser {
|
|
|
331
333
|
this.bridgeClient = new SolanaBridgeClient(
|
|
332
334
|
{
|
|
333
335
|
rpcUrl: this.connection.rpcEndpoint,
|
|
334
|
-
programId: this.nord.
|
|
336
|
+
programId: this.nord.getSolanaProgramId(),
|
|
335
337
|
commitment: "confirmed",
|
|
336
338
|
tokenInfos: this.splTokenInfos,
|
|
339
|
+
bridgeVk: this.nord.bridgeVk,
|
|
337
340
|
},
|
|
338
341
|
wallet,
|
|
339
342
|
);
|
|
@@ -361,21 +364,28 @@ export class NordUser {
|
|
|
361
364
|
const walletSignFn = async (
|
|
362
365
|
message: Uint8Array | string,
|
|
363
366
|
): Promise<Uint8Array> => {
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
367
|
+
function toHex(buffer: Uint8Array) {
|
|
368
|
+
return Array.from(buffer)
|
|
369
|
+
.map((byte) => byte.toString(16).padStart(2, "0"))
|
|
370
|
+
.join("");
|
|
371
|
+
}
|
|
372
|
+
const messageBuffer = new TextEncoder().encode(
|
|
373
|
+
toHex(message as Uint8Array),
|
|
374
|
+
);
|
|
368
375
|
|
|
369
|
-
// Use
|
|
370
|
-
const signature =
|
|
376
|
+
// Use ed25519 to sign the message
|
|
377
|
+
const signature = ed.sign(
|
|
378
|
+
messageBuffer,
|
|
379
|
+
keypair.secretKey.slice(0, 32),
|
|
380
|
+
);
|
|
371
381
|
return signature;
|
|
372
382
|
};
|
|
373
383
|
|
|
374
384
|
const sessionSignFn = async (
|
|
375
385
|
message: Uint8Array,
|
|
376
386
|
): Promise<Uint8Array> => {
|
|
377
|
-
// Use
|
|
378
|
-
return
|
|
387
|
+
// Use ed25519 to sign the message
|
|
388
|
+
return ed.sign(message, keypair.secretKey.slice(0, 32));
|
|
379
389
|
};
|
|
380
390
|
|
|
381
391
|
// Create a transaction signing function
|
|
@@ -445,7 +455,7 @@ export class NordUser {
|
|
|
445
455
|
* @returns Transaction signature
|
|
446
456
|
* @throws {NordError} If required parameters are missing or operation fails
|
|
447
457
|
*/
|
|
448
|
-
async depositSpl(amount: number, tokenId: number): Promise<string> {
|
|
458
|
+
async depositSpl(amount: number, tokenId: number, recipientAddress?: PublicKey): Promise<string> {
|
|
449
459
|
if (!this.bridgeClient || !this.getSolanaPublicKey() || !this.connection) {
|
|
450
460
|
throw new NordError(
|
|
451
461
|
"Bridge client, Solana public key, and connection are required for deposit",
|
|
@@ -462,16 +472,6 @@ export class NordUser {
|
|
|
462
472
|
const mint = new PublicKey(tokenInfo.mint);
|
|
463
473
|
// Get the user's token account
|
|
464
474
|
const fromAccount = await this.getAssociatedTokenAccount(mint);
|
|
465
|
-
|
|
466
|
-
// Get the bridge's token account
|
|
467
|
-
const [authority] = await this.bridgeClient.findAuthorityPda();
|
|
468
|
-
const toAccount = await getAssociatedTokenAddress(
|
|
469
|
-
mint,
|
|
470
|
-
authority,
|
|
471
|
-
true,
|
|
472
|
-
TOKEN_2022_PROGRAM_ID,
|
|
473
|
-
);
|
|
474
|
-
|
|
475
475
|
// Convert amount to BN with proper decimals
|
|
476
476
|
const amountBN = utilsToBN(amount, tokenInfo.precision);
|
|
477
477
|
|
|
@@ -480,7 +480,7 @@ export class NordUser {
|
|
|
480
480
|
amount: amountBN,
|
|
481
481
|
mint,
|
|
482
482
|
fromAccount,
|
|
483
|
-
|
|
483
|
+
...(recipientAddress ? { recipientAddress } : {})
|
|
484
484
|
});
|
|
485
485
|
} catch (error) {
|
|
486
486
|
throw new NordError(
|
|
@@ -588,23 +588,23 @@ export class NordUser {
|
|
|
588
588
|
* @throws {NordError} If the operation fails
|
|
589
589
|
*/
|
|
590
590
|
async fetchInfo(): Promise<void> {
|
|
591
|
-
|
|
591
|
+
type OpenOrder = {
|
|
592
592
|
orderId: number;
|
|
593
|
-
size: number;
|
|
594
|
-
price: number;
|
|
595
593
|
marketId: number;
|
|
596
594
|
side: "ask" | "bid";
|
|
597
|
-
|
|
595
|
+
size: number;
|
|
596
|
+
price: number;
|
|
597
|
+
originalOrderSize: number;
|
|
598
598
|
clientOrderId?: number | null;
|
|
599
|
-
}
|
|
599
|
+
};
|
|
600
600
|
|
|
601
|
-
|
|
601
|
+
type Balance = {
|
|
602
602
|
tokenId: number;
|
|
603
603
|
token: string;
|
|
604
604
|
amount: number;
|
|
605
|
-
}
|
|
605
|
+
};
|
|
606
606
|
|
|
607
|
-
|
|
607
|
+
type Position = {
|
|
608
608
|
marketId: number;
|
|
609
609
|
openOrders: number;
|
|
610
610
|
perp?: {
|
|
@@ -616,9 +616,9 @@ export class NordUser {
|
|
|
616
616
|
isLong: boolean;
|
|
617
617
|
};
|
|
618
618
|
actionId: number;
|
|
619
|
-
}
|
|
619
|
+
};
|
|
620
620
|
|
|
621
|
-
|
|
621
|
+
type Margins = {
|
|
622
622
|
omf: number;
|
|
623
623
|
mf: number;
|
|
624
624
|
imf: number;
|
|
@@ -627,32 +627,31 @@ export class NordUser {
|
|
|
627
627
|
pon: number;
|
|
628
628
|
pn: number;
|
|
629
629
|
bankruptcy: boolean;
|
|
630
|
-
}
|
|
630
|
+
};
|
|
631
631
|
|
|
632
|
-
|
|
632
|
+
type Account = {
|
|
633
633
|
updateId: number;
|
|
634
|
-
orders:
|
|
634
|
+
orders: OpenOrder[];
|
|
635
635
|
positions: Position[];
|
|
636
636
|
balances: Balance[];
|
|
637
637
|
margins: Margins;
|
|
638
|
-
|
|
639
|
-
accountId: number;
|
|
640
|
-
}
|
|
638
|
+
};
|
|
641
639
|
|
|
642
640
|
if (this.accountIds !== undefined) {
|
|
643
|
-
const accountsData
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
641
|
+
const accountsData: (Account & { accountId: number })[] =
|
|
642
|
+
await Promise.all(
|
|
643
|
+
this.accountIds.map(async (accountId) => {
|
|
644
|
+
const response = await checkedFetch(
|
|
645
|
+
`${this.nord.webServerUrl}/account/${accountId}`,
|
|
646
|
+
);
|
|
647
|
+
const accountData = (await response.json()) as Account;
|
|
648
|
+
// Ensure we have the correct accountId
|
|
649
|
+
return {
|
|
650
|
+
...accountData,
|
|
651
|
+
accountId,
|
|
652
|
+
};
|
|
653
|
+
}),
|
|
654
|
+
);
|
|
656
655
|
|
|
657
656
|
for (const accountData of accountsData) {
|
|
658
657
|
// Process balances
|
|
@@ -667,13 +666,7 @@ export class NordUser {
|
|
|
667
666
|
|
|
668
667
|
// Process orders
|
|
669
668
|
this.orders[accountData.accountId] = accountData.orders.map(
|
|
670
|
-
(order: {
|
|
671
|
-
orderId: number;
|
|
672
|
-
side: string;
|
|
673
|
-
size: number;
|
|
674
|
-
price: number;
|
|
675
|
-
marketId: number;
|
|
676
|
-
}) => {
|
|
669
|
+
(order: OpenOrder) => {
|
|
677
670
|
return {
|
|
678
671
|
orderId: order.orderId,
|
|
679
672
|
isLong: order.side === "bid",
|
package/src/types.ts
CHANGED
|
@@ -35,8 +35,8 @@ export type SubscriptionPattern = `${SubscriptionType}@${string}` | string;
|
|
|
35
35
|
export interface NordConfig {
|
|
36
36
|
/** Base URL for the Nord web server */
|
|
37
37
|
webServerUrl: string;
|
|
38
|
-
/**
|
|
39
|
-
|
|
38
|
+
/** Bridge verification key */
|
|
39
|
+
bridgeVk: string;
|
|
40
40
|
/** Solana cluster URL */
|
|
41
41
|
solanaUrl: string;
|
|
42
42
|
/** Whether to initialize WebSockets on creation, defaults to true */
|
|
@@ -145,9 +145,7 @@ export class NordWebSocketClient
|
|
|
145
145
|
private getWebSocketClass(): any {
|
|
146
146
|
if (this.isBrowser) {
|
|
147
147
|
// In browser environments
|
|
148
|
-
// @ts-expect-error - Check for WebSocket in globalThis
|
|
149
148
|
if (typeof globalThis !== "undefined" && globalThis.WebSocket) {
|
|
150
|
-
// @ts-expect-error - Return WebSocket from globalThis
|
|
151
149
|
return globalThis.WebSocket;
|
|
152
150
|
}
|
|
153
151
|
throw new Error("WebSocket is not available in this environment");
|
package/tsconfig.json
CHANGED
package/dist/idl/bridge.d.ts
DELETED