@n1xyz/nord-ts 0.0.21 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +20 -16
  2. package/dist/api/client.d.ts +14 -0
  3. package/dist/api/client.js +45 -0
  4. package/dist/bridge/client.d.ts +151 -0
  5. package/dist/bridge/client.js +434 -0
  6. package/dist/bridge/const.d.ts +23 -0
  7. package/dist/bridge/const.js +47 -0
  8. package/dist/bridge/index.d.ts +4 -0
  9. package/dist/bridge/index.js +23 -0
  10. package/dist/bridge/types.d.ts +120 -0
  11. package/dist/bridge/types.js +18 -0
  12. package/dist/bridge/utils.d.ts +64 -0
  13. package/dist/bridge/utils.js +131 -0
  14. package/dist/gen/common.d.ts +68 -0
  15. package/dist/gen/common.js +215 -0
  16. package/dist/gen/nord_pb.d.ts +3719 -0
  17. package/dist/gen/nord_pb.js +945 -0
  18. package/dist/gen/openapi.d.ts +268 -4
  19. package/dist/idl/bridge.d.ts +569 -0
  20. package/dist/idl/bridge.js +8 -0
  21. package/dist/idl/bridge.json +1506 -0
  22. package/dist/idl/index.d.ts +607 -0
  23. package/dist/idl/index.js +8 -0
  24. package/dist/nord/api/actions.d.ts +31 -72
  25. package/dist/nord/api/actions.js +199 -201
  26. package/dist/nord/api/market.d.ts +36 -0
  27. package/dist/nord/api/market.js +96 -0
  28. package/dist/nord/api/queries.d.ts +46 -0
  29. package/dist/nord/api/queries.js +109 -0
  30. package/dist/nord/client/Nord.js +3 -3
  31. package/dist/nord/client/NordUser.d.ts +26 -13
  32. package/dist/nord/client/NordUser.js +13 -10
  33. package/dist/types.d.ts +12 -1
  34. package/dist/types.js +29 -2
  35. package/dist/utils.d.ts +6 -20
  36. package/dist/utils.js +17 -35
  37. package/dist/websocket/NordWebSocketClient.js +2 -6
  38. package/package.json +26 -23
  39. package/src/gen/nord_pb.ts +4257 -0
  40. package/src/gen/openapi.ts +268 -4
  41. package/src/nord/api/actions.ts +278 -369
  42. package/src/nord/client/Nord.ts +3 -3
  43. package/src/nord/client/NordUser.ts +40 -19
  44. package/src/types.ts +32 -1
  45. package/src/utils.ts +24 -43
  46. package/src/websocket/NordWebSocketClient.ts +2 -8
@@ -0,0 +1,36 @@
1
+ import { MarketsStatsResponse, OrderbookQuery, OrderbookResponse, TradesQuery, TradesResponse, UserAccountIdsQuery, UserAccountIdsResponse } from "../../types";
2
+ /**
3
+ * Get market statistics
4
+ *
5
+ * @param webServerUrl - Base URL for the Nord web server
6
+ * @returns Market statistics response
7
+ * @throws {NordError} If the request fails
8
+ */
9
+ export declare function marketsStats(webServerUrl: string): Promise<MarketsStatsResponse>;
10
+ /**
11
+ * Get trades for a market
12
+ *
13
+ * @param webServerUrl - Base URL for the Nord web server
14
+ * @param query - Trades query parameters
15
+ * @returns Trades response
16
+ * @throws {NordError} If the request fails
17
+ */
18
+ export declare function getTrades(webServerUrl: string, query: TradesQuery): Promise<TradesResponse>;
19
+ /**
20
+ * Get user account IDs
21
+ *
22
+ * @param webServerUrl - Base URL for the Nord web server
23
+ * @param query - User account IDs query parameters
24
+ * @returns User account IDs response
25
+ * @throws {NordError} If the request fails
26
+ */
27
+ export declare function getUserAccountIds(webServerUrl: string, query: UserAccountIdsQuery): Promise<UserAccountIdsResponse>;
28
+ /**
29
+ * Get orderbook for a market
30
+ *
31
+ * @param webServerUrl - Base URL for the Nord web server
32
+ * @param query - Orderbook query parameters
33
+ * @returns Orderbook response
34
+ * @throws {NordError} If the request fails
35
+ */
36
+ export declare function getOrderbook(webServerUrl: string, query: OrderbookQuery): Promise<OrderbookResponse>;
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.marketsStats = marketsStats;
4
+ exports.getTrades = getTrades;
5
+ exports.getUserAccountIds = getUserAccountIds;
6
+ exports.getOrderbook = getOrderbook;
7
+ const utils_1 = require("../../utils");
8
+ const NordError_1 = require("../utils/NordError");
9
+ /**
10
+ * Get market statistics
11
+ *
12
+ * @param webServerUrl - Base URL for the Nord web server
13
+ * @returns Market statistics response
14
+ * @throws {NordError} If the request fails
15
+ */
16
+ async function marketsStats(webServerUrl) {
17
+ try {
18
+ const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/stats`);
19
+ return await response.json();
20
+ }
21
+ catch (error) {
22
+ throw new NordError_1.NordError("Failed to fetch markets stats", { cause: error });
23
+ }
24
+ }
25
+ /**
26
+ * Get trades for a market
27
+ *
28
+ * @param webServerUrl - Base URL for the Nord web server
29
+ * @param query - Trades query parameters
30
+ * @returns Trades response
31
+ * @throws {NordError} If the request fails
32
+ */
33
+ async function getTrades(webServerUrl, query) {
34
+ try {
35
+ const params = new URLSearchParams();
36
+ params.append("accountId", query.accountId.toString());
37
+ if (query.since) {
38
+ params.append("since", query.since);
39
+ }
40
+ if (query.until) {
41
+ params.append("until", query.until);
42
+ }
43
+ if (query.pageId) {
44
+ params.append("pageId", query.pageId);
45
+ }
46
+ const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/trades?${params.toString()}`);
47
+ return await response.json();
48
+ }
49
+ catch (error) {
50
+ throw new NordError_1.NordError("Failed to get trades", { cause: error });
51
+ }
52
+ }
53
+ /**
54
+ * Get user account IDs
55
+ *
56
+ * @param webServerUrl - Base URL for the Nord web server
57
+ * @param query - User account IDs query parameters
58
+ * @returns User account IDs response
59
+ * @throws {NordError} If the request fails
60
+ */
61
+ async function getUserAccountIds(webServerUrl, query) {
62
+ try {
63
+ const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/user/${query.pubkey.toString()}`);
64
+ return await response.json();
65
+ }
66
+ catch (error) {
67
+ throw new NordError_1.NordError("Failed to get user account IDs", { cause: error });
68
+ }
69
+ }
70
+ /**
71
+ * Get orderbook for a market
72
+ *
73
+ * @param webServerUrl - Base URL for the Nord web server
74
+ * @param query - Orderbook query parameters
75
+ * @returns Orderbook response
76
+ * @throws {NordError} If the request fails
77
+ */
78
+ async function getOrderbook(webServerUrl, query) {
79
+ try {
80
+ const params = new URLSearchParams();
81
+ if (query.symbol) {
82
+ params.append("symbol", query.symbol);
83
+ }
84
+ else if (query.market_id !== undefined) {
85
+ params.append("market_id", query.market_id.toString());
86
+ }
87
+ else {
88
+ throw new NordError_1.NordError("Either symbol or market_id must be provided for orderbook query");
89
+ }
90
+ const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/orderbook?${params.toString()}`);
91
+ return await response.json();
92
+ }
93
+ catch (error) {
94
+ throw new NordError_1.NordError("Failed to get orderbook", { cause: error });
95
+ }
96
+ }
@@ -0,0 +1,46 @@
1
+ import { ActionQuery, ActionResponse, ActionsResponse, RollmanActionResponse, RollmanActionsResponse } from "../../types";
2
+ /**
3
+ * Query a specific action
4
+ *
5
+ * @param webServerUrl - Base URL for the Nord web server
6
+ * @param query - Action query parameters
7
+ * @returns Action response
8
+ * @throws {NordError} If the request fails
9
+ */
10
+ export declare function queryAction(webServerUrl: string, query: ActionQuery): Promise<ActionResponse>;
11
+ /**
12
+ * Query recent actions
13
+ *
14
+ * @param webServerUrl - Base URL for the Nord web server
15
+ * @param from - Starting action index
16
+ * @param to - Ending action index
17
+ * @returns Actions response
18
+ * @throws {NordError} If the request fails
19
+ */
20
+ export declare function queryRecentActions(webServerUrl: string, from: number, to: number): Promise<ActionsResponse>;
21
+ /**
22
+ * Get the last action ID
23
+ *
24
+ * @param webServerUrl - Base URL for the Nord web server
25
+ * @returns Last action ID
26
+ * @throws {NordError} If the request fails
27
+ */
28
+ export declare function getLastActionId(webServerUrl: string): Promise<number>;
29
+ /**
30
+ * Query an action from Rollman
31
+ *
32
+ * @param webServerUrl - Base URL for the Nord web server
33
+ * @param query - Action query parameters
34
+ * @returns Rollman action response
35
+ * @throws {NordError} If the request fails
36
+ */
37
+ export declare function actionQueryRollman(webServerUrl: string, query: ActionQuery): Promise<RollmanActionResponse>;
38
+ /**
39
+ * Query actions from Rollman
40
+ *
41
+ * @param webServerUrl - Base URL for the Nord web server
42
+ * @param last_n - Number of recent actions to query
43
+ * @returns Rollman actions response
44
+ * @throws {NordError} If the request fails
45
+ */
46
+ export declare function actionsQueryRollman(webServerUrl: string, last_n: number): Promise<RollmanActionsResponse>;
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.queryAction = queryAction;
4
+ exports.queryRecentActions = queryRecentActions;
5
+ exports.getLastActionId = getLastActionId;
6
+ exports.actionQueryRollman = actionQueryRollman;
7
+ exports.actionsQueryRollman = actionsQueryRollman;
8
+ const utils_1 = require("../../utils");
9
+ const NordError_1 = require("../utils/NordError");
10
+ /**
11
+ * Query a specific action
12
+ *
13
+ * @param webServerUrl - Base URL for the Nord web server
14
+ * @param query - Action query parameters
15
+ * @returns Action response
16
+ * @throws {NordError} If the request fails
17
+ */
18
+ async function queryAction(webServerUrl, query) {
19
+ try {
20
+ const params = new URLSearchParams();
21
+ if (query.action_id !== undefined) {
22
+ params.append("action_id", query.action_id.toString());
23
+ }
24
+ const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/action?${params.toString()}`);
25
+ return await response.json();
26
+ }
27
+ catch (error) {
28
+ throw new NordError_1.NordError("Failed to query action", { cause: error });
29
+ }
30
+ }
31
+ /**
32
+ * Query recent actions
33
+ *
34
+ * @param webServerUrl - Base URL for the Nord web server
35
+ * @param from - Starting action index
36
+ * @param to - Ending action index
37
+ * @returns Actions response
38
+ * @throws {NordError} If the request fails
39
+ */
40
+ async function queryRecentActions(webServerUrl, from, to) {
41
+ try {
42
+ const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/actions?from=${from}&to=${to}`);
43
+ return await response.json();
44
+ }
45
+ catch (error) {
46
+ throw new NordError_1.NordError(`Failed to query recent actions (from ${from} to ${to})`, {
47
+ cause: error,
48
+ });
49
+ }
50
+ }
51
+ /**
52
+ * Get the last action ID
53
+ *
54
+ * @param webServerUrl - Base URL for the Nord web server
55
+ * @returns Last action ID
56
+ * @throws {NordError} If the request fails
57
+ */
58
+ async function getLastActionId(webServerUrl) {
59
+ try {
60
+ const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/actions/last-id`);
61
+ const data = await response.json();
62
+ return data;
63
+ }
64
+ catch (error) {
65
+ throw new NordError_1.NordError("Failed to get last action ID", {
66
+ cause: error,
67
+ });
68
+ }
69
+ }
70
+ /**
71
+ * Query an action from Rollman
72
+ *
73
+ * @param webServerUrl - Base URL for the Nord web server
74
+ * @param query - Action query parameters
75
+ * @returns Rollman action response
76
+ * @throws {NordError} If the request fails
77
+ */
78
+ async function actionQueryRollman(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}/rollman/action?${params.toString()}`);
85
+ return await response.json();
86
+ }
87
+ catch (error) {
88
+ throw new NordError_1.NordError("Failed to query Rollman action", { cause: error });
89
+ }
90
+ }
91
+ /**
92
+ * Query actions from Rollman
93
+ *
94
+ * @param webServerUrl - Base URL for the Nord web server
95
+ * @param last_n - Number of recent actions to query
96
+ * @returns Rollman actions response
97
+ * @throws {NordError} If the request fails
98
+ */
99
+ async function actionsQueryRollman(webServerUrl, last_n) {
100
+ try {
101
+ const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/rollman/actions?last_n=${last_n}`);
102
+ return await response.json();
103
+ }
104
+ catch (error) {
105
+ throw new NordError_1.NordError(`Failed to query Rollman actions (last ${last_n})`, {
106
+ cause: error,
107
+ });
108
+ }
109
+ }
@@ -41,7 +41,7 @@ const proton_1 = require("@n1xyz/proton");
41
41
  const web3_js_1 = require("@solana/web3.js");
42
42
  const events_1 = require("events");
43
43
  const openapi_fetch_1 = __importDefault(require("openapi-fetch"));
44
- const proto = __importStar(require("../../gen/nord"));
44
+ const proto = __importStar(require("../../gen/nord_pb"));
45
45
  const types_1 = require("../../types");
46
46
  const utils = __importStar(require("../../utils"));
47
47
  const core = __importStar(require("../api/core"));
@@ -240,8 +240,8 @@ class Nord {
240
240
  });
241
241
  return xs.map((x) => ({
242
242
  actionId: x.actionId,
243
- action: utils.decodeLengthDelimited(Buffer.from(x.payload, "base64"), proto.Action),
244
- physicalExecTime: new Date(x.physicalTime * 1000),
243
+ action: utils.decodeLengthDelimited(Buffer.from(x.payload, "base64"), proto.ActionSchema),
244
+ physicalExecTime: new Date(x.physicalTime),
245
245
  }));
246
246
  }
247
247
  /**
@@ -1,7 +1,7 @@
1
- import { Connection, PublicKey, Transaction } from "@solana/web3.js";
1
+ import { Connection, PublicKey, Transaction, SendOptions } from "@solana/web3.js";
2
2
  import Decimal from "decimal.js";
3
- import { FillMode, Side, SPLTokenInfo } from "../../types";
4
- import * as proto from "../../gen/nord";
3
+ import { FillMode, Side, SPLTokenInfo, QuoteSize } from "../../types";
4
+ import * as proto from "../../gen/nord_pb";
5
5
  import { BigIntValue } from "../../utils";
6
6
  import { Nord } from "./Nord";
7
7
  /**
@@ -43,8 +43,8 @@ export interface PlaceOrderParams {
43
43
  size?: Decimal.Value;
44
44
  /** Order price */
45
45
  price?: Decimal.Value;
46
- /** Quote size (for market orders) */
47
- quoteSize?: Decimal.Value;
46
+ /** Quote size object (requires non-zero price and size) */
47
+ quoteSize?: QuoteSize;
48
48
  /** Account ID to place the order from */
49
49
  accountId?: number;
50
50
  }
@@ -83,8 +83,8 @@ export interface UserAtomicSubaction {
83
83
  size?: Decimal.Value;
84
84
  /** Order price */
85
85
  price?: Decimal.Value;
86
- /** Quote size (for market orders) */
87
- quoteSize?: Decimal.Value;
86
+ /** Quote size object (for market-style placement) */
87
+ quoteSize?: QuoteSize;
88
88
  /** The client order ID of the order. */
89
89
  clientOrderId?: BigIntValue;
90
90
  }
@@ -203,13 +203,15 @@ export declare class NordUser {
203
203
  * @param amount - Amount to deposit
204
204
  * @param tokenId - Token ID
205
205
  * @param recipient - Recipient address; defaults to the user's address
206
+ * @param sendOptions - Send options for .sendTransaction
206
207
  * @returns Transaction signature
207
208
  * @throws {NordError} If required parameters are missing or operation fails
208
209
  */
209
- deposit({ amount, tokenId, recipient, }: Readonly<{
210
+ deposit({ amount, tokenId, recipient, sendOptions, }: Readonly<{
210
211
  amount: number;
211
212
  tokenId: number;
212
213
  recipient?: PublicKey;
214
+ sendOptions?: SendOptions;
213
215
  }>): Promise<string>;
214
216
  /**
215
217
  * Get a new nonce for actions
@@ -265,19 +267,27 @@ export declare class NordUser {
265
267
  * Place an order on the exchange
266
268
  *
267
269
  * @param params - Order parameters
268
- * @returns Order ID if successful
270
+ * @returns Object containing actionId, orderId (if posted), fills, and clientOrderId
269
271
  * @throws {NordError} If the operation fails
270
272
  */
271
- placeOrder(params: PlaceOrderParams): Promise<bigint | undefined>;
273
+ placeOrder(params: PlaceOrderParams): Promise<{
274
+ actionId: bigint;
275
+ orderId?: bigint;
276
+ fills: proto.Receipt_Trade[];
277
+ }>;
272
278
  /**
273
279
  * Cancel an order
274
280
  *
275
281
  * @param orderId - Order ID to cancel
276
282
  * @param providedAccountId - Account ID that placed the order
277
- * @returns Action ID if successful
283
+ * @returns Object containing actionId, cancelled orderId, and accountId
278
284
  * @throws {NordError} If the operation fails
279
285
  */
280
- cancelOrder(orderId: BigIntValue, providedAccountId?: number): Promise<bigint>;
286
+ cancelOrder(orderId: BigIntValue, providedAccountId?: number): Promise<{
287
+ actionId: bigint;
288
+ orderId: bigint;
289
+ accountId: number;
290
+ }>;
281
291
  /**
282
292
  * Transfer tokens to another account
283
293
  *
@@ -297,7 +307,10 @@ export declare class NordUser {
297
307
  * @param userActions array of user-friendly subactions
298
308
  * @param providedAccountId optional account performing the action (defaults to first account)
299
309
  */
300
- atomic(userActions: UserAtomicSubaction[], providedAccountId?: number): Promise<proto.Receipt_AtomicResult>;
310
+ atomic(userActions: UserAtomicSubaction[], providedAccountId?: number): Promise<{
311
+ actionId: bigint;
312
+ results: proto.Receipt_AtomicSubactionResultKind[];
313
+ }>;
301
314
  /**
302
315
  * Helper function to retry a promise with exponential backoff
303
316
  *
@@ -242,10 +242,11 @@ class NordUser {
242
242
  * @param amount - Amount to deposit
243
243
  * @param tokenId - Token ID
244
244
  * @param recipient - Recipient address; defaults to the user's address
245
+ * @param sendOptions - Send options for .sendTransaction
245
246
  * @returns Transaction signature
246
247
  * @throws {NordError} If required parameters are missing or operation fails
247
248
  */
248
- async deposit({ amount, tokenId, recipient, }) {
249
+ async deposit({ amount, tokenId, recipient, sendOptions, }) {
249
250
  try {
250
251
  // Find the token info
251
252
  const tokenInfo = this.splTokenInfos.find((t) => t.tokenId === tokenId);
@@ -262,14 +263,14 @@ class NordUser {
262
263
  mint,
263
264
  sourceTokenAccount: fromAccount,
264
265
  });
265
- const { blockhash } = await this.connection.getLatestBlockhash("confirmed");
266
+ const { blockhash } = await this.connection.getLatestBlockhash();
266
267
  const tx = new web3_js_1.Transaction();
267
268
  tx.add(ix);
268
269
  tx.recentBlockhash = blockhash;
269
270
  tx.feePayer = payer;
270
271
  const signedTx = await this.transactionSignFn(tx);
271
272
  signedTx.partialSign(extraSigner);
272
- const signature = await this.connection.sendRawTransaction(signedTx.serialize());
273
+ const signature = await this.connection.sendRawTransaction(signedTx.serialize(), sendOptions);
273
274
  return signature;
274
275
  }
275
276
  catch (error) {
@@ -345,10 +346,11 @@ class NordUser {
345
346
  * @throws {NordError} If the operation fails
346
347
  */
347
348
  async refreshSession() {
348
- this.sessionId = await (0, actions_1.createSession)(this.nord.webServerUrl, this.walletSignFn, await this.nord.getTimestamp(), this.getNonce(), {
349
+ const result = await (0, actions_1.createSession)(this.nord.webServerUrl, this.walletSignFn, await this.nord.getTimestamp(), this.getNonce(), {
349
350
  userPubkey: (0, utils_1.optExpect)(this.publicKey.toBytes(), "No user's public key"),
350
351
  sessionPubkey: this.sessionPubKey,
351
352
  });
353
+ this.sessionId = result.sessionId;
352
354
  }
353
355
  /**
354
356
  * Revoke a session
@@ -404,7 +406,7 @@ class NordUser {
404
406
  * Place an order on the exchange
405
407
  *
406
408
  * @param params - Order parameters
407
- * @returns Order ID if successful
409
+ * @returns Object containing actionId, orderId (if posted), fills, and clientOrderId
408
410
  * @throws {NordError} If the operation fails
409
411
  */
410
412
  async placeOrder(params) {
@@ -414,7 +416,7 @@ class NordUser {
414
416
  if (!market) {
415
417
  throw new NordError_1.NordError(`Market with ID ${params.marketId} not found`);
416
418
  }
417
- return (0, actions_1.placeOrder)(this.nord.webServerUrl, this.sessionSignFn, await this.nord.getTimestamp(), this.getNonce(), {
419
+ const result = await (0, actions_1.placeOrder)(this.nord.webServerUrl, this.sessionSignFn, await this.nord.getTimestamp(), this.getNonce(), {
418
420
  sessionId: (0, utils_1.optExpect)(this.sessionId, "No session"),
419
421
  senderId: params.accountId,
420
422
  sizeDecimals: market.sizeDecimals,
@@ -427,6 +429,7 @@ class NordUser {
427
429
  price: params.price,
428
430
  quoteSize: params.quoteSize,
429
431
  });
432
+ return result;
430
433
  }
431
434
  catch (error) {
432
435
  throw new NordError_1.NordError("Failed to place order", { cause: error });
@@ -437,18 +440,19 @@ class NordUser {
437
440
  *
438
441
  * @param orderId - Order ID to cancel
439
442
  * @param providedAccountId - Account ID that placed the order
440
- * @returns Action ID if successful
443
+ * @returns Object containing actionId, cancelled orderId, and accountId
441
444
  * @throws {NordError} If the operation fails
442
445
  */
443
446
  async cancelOrder(orderId, providedAccountId) {
444
447
  const accountId = providedAccountId != null ? providedAccountId : this.accountIds?.[0];
445
448
  try {
446
449
  this.checkSessionValidity();
447
- return (0, actions_1.cancelOrder)(this.nord.webServerUrl, this.sessionSignFn, await this.nord.getTimestamp(), this.getNonce(), {
450
+ const result = await (0, actions_1.cancelOrder)(this.nord.webServerUrl, this.sessionSignFn, await this.nord.getTimestamp(), this.getNonce(), {
448
451
  sessionId: (0, utils_1.optExpect)(this.sessionId, "No session"),
449
452
  senderId: accountId,
450
453
  orderId,
451
454
  });
455
+ return result;
452
456
  }
453
457
  catch (error) {
454
458
  throw new NordError_1.NordError(`Failed to cancel order ${orderId}`, {
@@ -514,8 +518,7 @@ class NordUser {
514
518
  priceDecimals: market.priceDecimals,
515
519
  size: act.size,
516
520
  price: act.price,
517
- quoteSizeSize: act.quoteSize, // treated as quote size; we pass only size component
518
- quoteSizePrice: undefined,
521
+ quoteSize: act.quoteSize,
519
522
  clientOrderId: act.clientOrderId,
520
523
  };
521
524
  }
package/dist/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import * as proto from "./gen/nord";
1
+ import * as proto from "./gen/nord_pb";
2
2
  import type { components } from "./gen/openapi.ts";
3
+ import Decimal from "decimal.js";
3
4
  /**
4
5
  * The peak TPS rate is queried over the specified period.
5
6
  * The period is specified in units of: {hour, day, week, month, year}.
@@ -249,3 +250,13 @@ export interface SPLTokenInfo {
249
250
  tokenId: number;
250
251
  name: string;
251
252
  }
253
+ export declare class QuoteSize {
254
+ price: Decimal;
255
+ size: Decimal;
256
+ constructor(quotePrice: Decimal.Value, quoteSize: Decimal.Value);
257
+ value(): Decimal;
258
+ toScaledU64(marketPriceDecimals: number, marketSizeDecimals: number): {
259
+ price: bigint;
260
+ size: bigint;
261
+ };
262
+ }
package/dist/types.js CHANGED
@@ -32,10 +32,15 @@ var __importStar = (this && this.__importStar) || (function () {
32
32
  return result;
33
33
  };
34
34
  })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
35
38
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.WebSocketMessageType = exports.FillMode = exports.Side = exports.KeyType = exports.PeakTpsPeriodUnit = void 0;
39
+ exports.QuoteSize = exports.WebSocketMessageType = exports.FillMode = exports.Side = exports.KeyType = exports.PeakTpsPeriodUnit = void 0;
37
40
  exports.fillModeToProtoFillMode = fillModeToProtoFillMode;
38
- const proto = __importStar(require("./gen/nord"));
41
+ const proto = __importStar(require("./gen/nord_pb"));
42
+ const decimal_js_1 = __importDefault(require("decimal.js"));
43
+ const utils_1 = require("./utils");
39
44
  /**
40
45
  * The peak TPS rate is queried over the specified period.
41
46
  * The period is specified in units of: {hour, day, week, month, year}.
@@ -99,3 +104,25 @@ var WebSocketMessageType;
99
104
  WebSocketMessageType["DeltaUpdate"] = "delta";
100
105
  WebSocketMessageType["AccountUpdate"] = "account";
101
106
  })(WebSocketMessageType || (exports.WebSocketMessageType = WebSocketMessageType = {}));
107
+ // Positive decimal price and size.
108
+ class QuoteSize {
109
+ constructor(quotePrice, quoteSize) {
110
+ const p = new decimal_js_1.default(quotePrice);
111
+ const s = new decimal_js_1.default(quoteSize);
112
+ if (!p.isPositive() || !s.isPositive()) {
113
+ throw new Error("quotePrice and quoteSize must be positive");
114
+ }
115
+ this.price = p;
116
+ this.size = s;
117
+ }
118
+ value() {
119
+ return this.price.mul(this.size);
120
+ }
121
+ toScaledU64(marketPriceDecimals, marketSizeDecimals) {
122
+ return {
123
+ price: (0, utils_1.toScaledU64)(this.price, marketPriceDecimals),
124
+ size: (0, utils_1.toScaledU64)(this.size, marketSizeDecimals),
125
+ };
126
+ }
127
+ }
128
+ exports.QuoteSize = QuoteSize;
package/dist/utils.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Decimal } from "decimal.js";
2
2
  import { KeyType, type Market, type Token } from "./types";
3
- import * as proto from "./gen/nord";
3
+ import { type Message } from "@bufbuild/protobuf";
4
+ import type { GenMessage } from "@bufbuild/protobuf/codegenv2";
4
5
  import { ethers } from "ethers";
5
6
  import { RequestInfo, RequestInit, Response } from "node-fetch";
6
7
  import { Keypair } from "@solana/web3.js";
@@ -68,30 +69,15 @@ export declare const toScaledU64: (x: Decimal.Value, decimals: number) => bigint
68
69
  * @returns Rescaled unsigned integer
69
70
  */
70
71
  export declare const toScaledU128: (x: Decimal.Value, decimals: number) => bigint;
71
- /**
72
- * Encodes any protobuf message into a length-delimited format,
73
- * i.e. prefixed with its length encoded as varint
74
- * @param message message object
75
- * @param coder associated coder object which implements `MessageFns` interface
76
- * @returns Encoded message as Uint8Array, prefixed with its length
77
- */
78
- export declare function encodeLengthDelimited<T, M extends proto.MessageFns<T>>(message: T, coder: M): Uint8Array;
79
72
  /**
80
73
  * Decodes any protobuf message from a length-delimited format,
81
74
  * i.e. prefixed with its length encoded as varint
82
75
  *
83
- * NB: Please note that due to limitations of Typescript type inference
84
- * it requires to specify variable type explicitly:
85
- *
86
- * ```
87
- * const foo: proto.Bar = decodeLengthDelimited(bytes, proto.Bar);
88
- * ```
89
- *
90
- * @param bytes Byte array with encoded message
91
- * @param coder associated coder object which implements `MessageFns` interface
92
- * @returns Decoded Action as Uint8Array.
76
+ * @param bytes Byte array with encoded message
77
+ * @param schema Message schema for decoding
78
+ * @returns Decoded message
93
79
  */
94
- export declare function decodeLengthDelimited<T, M extends proto.MessageFns<T>>(bytes: Uint8Array, coder: M): T;
80
+ export declare function decodeLengthDelimited<T extends Message>(bytes: Uint8Array, schema: GenMessage<T>): T;
95
81
  export declare function checkPubKeyLength(keyType: KeyType, len: number): void;
96
82
  export declare function findMarket(markets: Market[], marketId: number): Market;
97
83
  export declare function findToken(tokens: Token[], tokenId: number): Token;