@n1xyz/nord-ts 0.1.4 → 0.1.6

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.
@@ -361,6 +361,14 @@ export interface paths {
361
361
  "application/json": number;
362
362
  };
363
363
  };
364
+ 404: {
365
+ headers: {
366
+ [name: string]: unknown;
367
+ };
368
+ content: {
369
+ "application/json": components["schemas"]["UserNotFound"];
370
+ };
371
+ };
364
372
  };
365
373
  };
366
374
  put?: never;
@@ -1102,6 +1110,127 @@ export interface paths {
1102
1110
  patch?: never;
1103
1111
  trace?: never;
1104
1112
  };
1113
+ "/fee/brackets/info": {
1114
+ parameters: {
1115
+ query?: never;
1116
+ header?: never;
1117
+ path?: never;
1118
+ cookie?: never;
1119
+ };
1120
+ get: {
1121
+ parameters: {
1122
+ query?: never;
1123
+ header?: never;
1124
+ path?: never;
1125
+ cookie?: never;
1126
+ };
1127
+ requestBody?: never;
1128
+ responses: {
1129
+ 200: {
1130
+ headers: {
1131
+ [name: string]: unknown;
1132
+ };
1133
+ content: {
1134
+ "application/json": [
1135
+ components["schemas"]["FeeTierId"],
1136
+ components["schemas"]["FeeTierConfig"]
1137
+ ][];
1138
+ };
1139
+ };
1140
+ };
1141
+ };
1142
+ put?: never;
1143
+ post?: never;
1144
+ delete?: never;
1145
+ options?: never;
1146
+ head?: never;
1147
+ patch?: never;
1148
+ trace?: never;
1149
+ };
1150
+ "/account/{account_id}/fee/tier": {
1151
+ parameters: {
1152
+ query?: never;
1153
+ header?: never;
1154
+ path?: never;
1155
+ cookie?: never;
1156
+ };
1157
+ get: {
1158
+ parameters: {
1159
+ query?: never;
1160
+ header?: never;
1161
+ path: {
1162
+ account_id: number;
1163
+ };
1164
+ cookie?: never;
1165
+ };
1166
+ requestBody?: never;
1167
+ responses: {
1168
+ 200: {
1169
+ headers: {
1170
+ [name: string]: unknown;
1171
+ };
1172
+ content: {
1173
+ "application/json": components["schemas"]["FeeTierId"];
1174
+ };
1175
+ };
1176
+ 404: {
1177
+ headers: {
1178
+ [name: string]: unknown;
1179
+ };
1180
+ content: {
1181
+ "application/json": components["schemas"]["UserNotFound"];
1182
+ };
1183
+ };
1184
+ };
1185
+ };
1186
+ put?: never;
1187
+ post?: never;
1188
+ delete?: never;
1189
+ options?: never;
1190
+ head?: never;
1191
+ patch?: never;
1192
+ trace?: never;
1193
+ };
1194
+ "/accounts/fee-tiers": {
1195
+ parameters: {
1196
+ query?: never;
1197
+ header?: never;
1198
+ path?: never;
1199
+ cookie?: never;
1200
+ };
1201
+ /** @description List fee tiers assigned to accounts. */
1202
+ get: {
1203
+ parameters: {
1204
+ query?: {
1205
+ /** @description fetch results starting with this page; query starts with first entry if page isn't specified */
1206
+ startInclusive?: number | null;
1207
+ /** @description Query returns up to 50 trades in one go. */
1208
+ pageSize?: number | null;
1209
+ };
1210
+ header?: never;
1211
+ path?: never;
1212
+ cookie?: never;
1213
+ };
1214
+ requestBody?: never;
1215
+ responses: {
1216
+ 200: {
1217
+ headers: {
1218
+ [name: string]: unknown;
1219
+ };
1220
+ content: {
1221
+ "application/json": components["schemas"]["PageResult_for_uint32_and_AccountFeeTier"];
1222
+ };
1223
+ };
1224
+ };
1225
+ };
1226
+ put?: never;
1227
+ post?: never;
1228
+ delete?: never;
1229
+ options?: never;
1230
+ head?: never;
1231
+ patch?: never;
1232
+ trace?: never;
1233
+ };
1105
1234
  "/tv": {
1106
1235
  parameters: {
1107
1236
  query?: never;
@@ -2075,6 +2204,7 @@ export interface components {
2075
2204
  ActionNotFound: null;
2076
2205
  /** @description Returns fee parts per market per balance change per action per account. Fee is taken from user without return. Please note that some operations need some deposit which will be returned - these are not part of fees. */
2077
2206
  FillRole: "maker" | "taker";
2207
+ UserNotFound: null;
2078
2208
  OrderbookInfo: {
2079
2209
  /** Format: uint64 */
2080
2210
  updateId: number;
@@ -2152,7 +2282,6 @@ export interface components {
2152
2282
  pubkey: string;
2153
2283
  expiry: string;
2154
2284
  };
2155
- UserNotFound: null;
2156
2285
  PageQueryPart_for_String: {
2157
2286
  /** @description fetch results starting with this page; query starts with first entry if page isn't specified */
2158
2287
  startInclusive?: string | null;
@@ -2524,6 +2653,41 @@ export interface components {
2524
2653
  timestamp: number;
2525
2654
  paused: boolean;
2526
2655
  };
2656
+ /** Format: uint32 */
2657
+ FeeTierId: number;
2658
+ FeeTierConfig: {
2659
+ /** Format: uint16 */
2660
+ maker_fee_bps: number;
2661
+ /** Format: uint16 */
2662
+ taker_fee_bps: number;
2663
+ };
2664
+ PageQueryPart_for_uint32: {
2665
+ /**
2666
+ * Format: uint32
2667
+ * @description fetch results starting with this page; query starts with first entry if page isn't specified
2668
+ */
2669
+ startInclusive?: number | null;
2670
+ /**
2671
+ * Format: uint8
2672
+ * @description Query returns up to 50 trades in one go.
2673
+ * @default null
2674
+ */
2675
+ pageSize: number | null;
2676
+ };
2677
+ PageResult_for_uint32_and_AccountFeeTier: {
2678
+ /** @description Set of items for requested by query. */
2679
+ items: components["schemas"]["AccountFeeTier"][];
2680
+ /**
2681
+ * Format: uint32
2682
+ * @description If request contains more data, this is the id is set with which next request should be performed to get next page. If no more data, then it is undefined.
2683
+ */
2684
+ nextStartInclusive?: number | null;
2685
+ };
2686
+ AccountFeeTier: {
2687
+ /** Format: uint32 */
2688
+ accountId: number;
2689
+ feeTier: components["schemas"]["FeeTierId"];
2690
+ };
2527
2691
  /** @description TV config query response https://www.tradingview.com/charting-library-docs/latest/connecting_data/UDF/#data-feed-configuration-data */
2528
2692
  TvConfigResponse: {
2529
2693
  supported_resolutions: components["schemas"]["Resolution"][];
@@ -2,6 +2,14 @@ import Decimal from "decimal.js";
2
2
  import * as proto from "../../gen/nord_pb";
3
3
  import { FillMode, Side, QuoteSize, TriggerKind } from "../../types";
4
4
  import { BigIntValue } from "../../utils";
5
+ type ReceiptKind = NonNullable<proto.Receipt["kind"]>;
6
+ type ExtractReceiptKind<K extends ReceiptKind["case"]> = Extract<ReceiptKind, {
7
+ case: K;
8
+ }>;
9
+ export declare function formatReceiptError(receipt: proto.Receipt): string;
10
+ export declare function expectReceiptKind<K extends ReceiptKind["case"]>(receipt: proto.Receipt, expected: K, action: string): asserts receipt is proto.Receipt & {
11
+ kind: ExtractReceiptKind<K>;
12
+ };
5
13
  export declare function createAction(currentTimestamp: bigint, nonce: number, kind: proto.Action["kind"]): proto.Action;
6
14
  export declare function sendAction(serverUrl: string, makeSignedMessage: (message: Uint8Array) => Promise<Uint8Array>, action: proto.Action): Promise<proto.Receipt>;
7
15
  export declare function prepareAction(action: proto.Action, makeSignedMessage: (message: Uint8Array) => Promise<Uint8Array>): Promise<Uint8Array<ArrayBufferLike>>;
@@ -115,3 +123,4 @@ export declare function atomic(serverUrl: string, signFn: (message: Uint8Array)
115
123
  actionId: bigint;
116
124
  results: proto.Receipt_AtomicSubactionResultKind[];
117
125
  }>;
126
+ export {};
@@ -36,6 +36,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.formatReceiptError = formatReceiptError;
40
+ exports.expectReceiptKind = expectReceiptKind;
39
41
  exports.createAction = createAction;
40
42
  exports.sendAction = sendAction;
41
43
  exports.prepareAction = prepareAction;
@@ -54,6 +56,20 @@ const protobuf_1 = require("@bufbuild/protobuf");
54
56
  const types_1 = require("../../types");
55
57
  const utils_1 = require("../../utils");
56
58
  const wire_1 = require("@bufbuild/protobuf/wire");
59
+ const NordError_1 = require("../utils/NordError");
60
+ function formatReceiptError(receipt) {
61
+ if (receipt.kind?.case === "err") {
62
+ const err = receipt.kind.value;
63
+ return proto.Error[err] ?? err.toString();
64
+ }
65
+ return receipt.kind?.case ?? "unknown";
66
+ }
67
+ function expectReceiptKind(receipt, expected, action) {
68
+ if (receipt.kind?.case !== expected) {
69
+ const label = formatReceiptError(receipt);
70
+ throw new NordError_1.NordError(`Failed to ${action}: ${label}`);
71
+ }
72
+ }
57
73
  async function sessionSign(signFn, message) {
58
74
  const signature = await signFn(message);
59
75
  return new Uint8Array([...message, ...signature]);
@@ -1,7 +1,7 @@
1
1
  import { ProtonClient } from "@n1xyz/proton";
2
2
  import { PublicKey } from "@solana/web3.js";
3
3
  import { EventEmitter } from "events";
4
- import { Account, AccountPnlPage, AccountPnlQuery, ActionResponse, AggregateMetrics, MarketsInfo, Market, MarketStats, NordConfig, OrderbookQuery, OrderbookResponse, PeakTpsPeriodUnit, Token, TradesResponse, User, AccountTriggerInfo, HistoryTriggerQuery, TriggerHistoryPage } from "../../types";
4
+ import { Account, AccountPnlPage, AccountPnlQuery, ActionResponse, AggregateMetrics, MarketsInfo, Market, MarketStats, NordConfig, OrderbookQuery, OrderbookResponse, FeeTierConfig, PeakTpsPeriodUnit, Token, TradesResponse, User, AccountTriggerInfo, HistoryTriggerQuery, TriggerHistoryPage, FeeTierId, AccountFeeTierPage, PageResultStringOrderInfo, PageResultStringTrade, OrderInfoFromApi, TokenStats, FillRole } from "../../types";
5
5
  import { NordWebSocketClient } from "../../websocket/index";
6
6
  import { OrderbookSubscription, TradeSubscription } from "../models/Subscriber";
7
7
  /**
@@ -101,7 +101,7 @@ export declare class Nord {
101
101
  * @returns Initialized Nord client
102
102
  * @throws {NordError} If initialization fails
103
103
  */
104
- static initNord({ app, solanaUrl, webServerUrl, }: Readonly<NordConfig>): Promise<Nord>;
104
+ static initNord({ app, solanaUrl, webServerUrl, protonUrl, }: Readonly<NordConfig>): Promise<Nord>;
105
105
  /**
106
106
  * Initialize the Nord client
107
107
  * @private
@@ -252,6 +252,21 @@ export declare class Nord {
252
252
  * @throws {NordError} If the request fails
253
253
  */
254
254
  getInfo(): Promise<MarketsInfo>;
255
+ /**
256
+ * Fetch the current fee tier brackets configured on Nord.
257
+ *
258
+ * @returns Array of fee tier identifiers paired with their configuration
259
+ * @throws {NordError} If the request fails
260
+ */
261
+ getFeeBrackets(): Promise<Array<[FeeTierId, FeeTierConfig]>>;
262
+ /**
263
+ * Retrieve the fee tier assigned to a specific account.
264
+ *
265
+ * @param accountId - Account identifier to query
266
+ * @returns Fee tier details for the requested account
267
+ * @throws {NordError} If the request fails
268
+ */
269
+ getAccountFeeTier(accountId: number): Promise<FeeTierId>;
255
270
  /**
256
271
  * Get account information
257
272
  *
@@ -260,6 +275,41 @@ export declare class Nord {
260
275
  * @throws {NordError} If the request fails
261
276
  */
262
277
  getAccount(accountId: number): Promise<Account>;
278
+ /**
279
+ * Get the public key associated with an account id.
280
+ *
281
+ * @param accountId - Account id to query
282
+ * @returns Base58-encoded account public key
283
+ * @throws {NordError} If the request fails
284
+ */
285
+ getAccountPubkey(accountId: number): Promise<string>;
286
+ /**
287
+ * Get the withdrawal fee charged for an account.
288
+ *
289
+ * @param accountId - Account id to query
290
+ * @returns Withdrawal fee quoted in quote token units
291
+ * @throws {NordError} If the request fails
292
+ */
293
+ getAccountWithdrawalFee(accountId: number): Promise<number>;
294
+ /**
295
+ * Get open orders for an account.
296
+ *
297
+ * @param accountId - Account id to query
298
+ * @param query - Optional pagination parameters
299
+ * @returns Page of orders keyed by client order id
300
+ * @throws {NordError} If the request fails
301
+ */
302
+ getAccountOrders(accountId: number, query?: {
303
+ startInclusive?: string | null;
304
+ pageSize?: number | null;
305
+ }): Promise<PageResultStringOrderInfo>;
306
+ /**
307
+ * List account fee tiers with pagination support.
308
+ */
309
+ getAccountsFeeTiers(query?: {
310
+ startInclusive?: number | null;
311
+ pageSize?: number | null;
312
+ }): Promise<AccountFeeTierPage>;
263
313
  /**
264
314
  * Get profit and loss history for an account
265
315
  *
@@ -277,6 +327,46 @@ export declare class Nord {
277
327
  getMarketStats({ marketId, }: {
278
328
  marketId: number;
279
329
  }): Promise<MarketStats>;
330
+ /**
331
+ * Fetch the per-market fee quote for an account.
332
+ *
333
+ * @param params - Market id, fee kind, and account id to quote
334
+ * @returns Fee in quote token units (negative means fee is charged)
335
+ * @throws {NordError} If the request fails
336
+ */
337
+ getMarketFee({ marketId, feeKind, accountId, }: {
338
+ marketId: number;
339
+ feeKind: FillRole;
340
+ accountId: number;
341
+ }): Promise<number>;
342
+ /**
343
+ * Fetch token statistics such as index price and oracle metadata.
344
+ *
345
+ * @param tokenId - Token identifier
346
+ * @returns Token stats
347
+ * @throws {NordError} If the request fails
348
+ */
349
+ getTokenStats(tokenId: number): Promise<TokenStats>;
350
+ /**
351
+ * Get order summary by order id.
352
+ *
353
+ * @param orderId - Order identifier
354
+ * @returns Order information
355
+ * @throws {NordError} If the request fails
356
+ */
357
+ getOrder(orderId: string): Promise<OrderInfoFromApi>;
358
+ /**
359
+ * Get trade history for a specific order.
360
+ *
361
+ * @param orderId - Order identifier
362
+ * @param query - Optional pagination parameters
363
+ * @returns Page of trades associated with the order
364
+ * @throws {NordError} If the request fails
365
+ */
366
+ getOrderTrades(orderId: string, query?: {
367
+ startInclusive?: string | null;
368
+ pageSize?: number | null;
369
+ }): Promise<PageResultStringTrade>;
280
370
  /**
281
371
  * Check if an account exists for the given address
282
372
  *
@@ -182,13 +182,13 @@ class Nord {
182
182
  * @returns Initialized Nord client
183
183
  * @throws {NordError} If initialization fails
184
184
  */
185
- static async initNord({ app, solanaUrl, webServerUrl, }) {
185
+ static async initNord({ app, solanaUrl, webServerUrl, protonUrl, }) {
186
186
  // TODO: we should parametrize the connectionn not have it done here.
187
187
  // this is a dogshit api, only here to be compatible with the shitty
188
188
  // vibecoded code and not break zero one team's workflow.
189
189
  const connection = new web3_js_1.Connection(solanaUrl, { commitment: "confirmed" });
190
190
  const protonClient = await proton_1.ProtonClient.init({
191
- protonUrl: webServerUrl,
191
+ protonUrl: protonUrl ?? webServerUrl,
192
192
  app: new web3_js_1.PublicKey(app),
193
193
  solConn: connection,
194
194
  });
@@ -484,6 +484,29 @@ class Nord {
484
484
  async getInfo() {
485
485
  return await this.GET("/info", {});
486
486
  }
487
+ /**
488
+ * Fetch the current fee tier brackets configured on Nord.
489
+ *
490
+ * @returns Array of fee tier identifiers paired with their configuration
491
+ * @throws {NordError} If the request fails
492
+ */
493
+ async getFeeBrackets() {
494
+ return await this.GET("/fee/brackets/info", {});
495
+ }
496
+ /**
497
+ * Retrieve the fee tier assigned to a specific account.
498
+ *
499
+ * @param accountId - Account identifier to query
500
+ * @returns Fee tier details for the requested account
501
+ * @throws {NordError} If the request fails
502
+ */
503
+ async getAccountFeeTier(accountId) {
504
+ return await this.GET("/account/{account_id}/fee/tier", {
505
+ params: {
506
+ path: { account_id: accountId },
507
+ },
508
+ });
509
+ }
487
510
  /**
488
511
  * Get account information
489
512
  *
@@ -498,6 +521,66 @@ class Nord {
498
521
  },
499
522
  });
500
523
  }
524
+ /**
525
+ * Get the public key associated with an account id.
526
+ *
527
+ * @param accountId - Account id to query
528
+ * @returns Base58-encoded account public key
529
+ * @throws {NordError} If the request fails
530
+ */
531
+ async getAccountPubkey(accountId) {
532
+ return await this.GET("/account/{account_id}/pubkey", {
533
+ params: {
534
+ path: { account_id: accountId },
535
+ },
536
+ });
537
+ }
538
+ /**
539
+ * Get the withdrawal fee charged for an account.
540
+ *
541
+ * @param accountId - Account id to query
542
+ * @returns Withdrawal fee quoted in quote token units
543
+ * @throws {NordError} If the request fails
544
+ */
545
+ async getAccountWithdrawalFee(accountId) {
546
+ return await this.GET("/account/{account_id}/fees/withdrawal", {
547
+ params: {
548
+ path: { account_id: accountId },
549
+ },
550
+ });
551
+ }
552
+ /**
553
+ * Get open orders for an account.
554
+ *
555
+ * @param accountId - Account id to query
556
+ * @param query - Optional pagination parameters
557
+ * @returns Page of orders keyed by client order id
558
+ * @throws {NordError} If the request fails
559
+ */
560
+ async getAccountOrders(accountId, query) {
561
+ return await this.GET("/account/{account_id}/orders", {
562
+ params: {
563
+ path: { account_id: accountId },
564
+ query: {
565
+ startInclusive: query?.startInclusive,
566
+ pageSize: query?.pageSize,
567
+ },
568
+ },
569
+ });
570
+ }
571
+ /**
572
+ * List account fee tiers with pagination support.
573
+ */
574
+ async getAccountsFeeTiers(query) {
575
+ return await this.GET("/accounts/fee-tiers", {
576
+ params: {
577
+ query: {
578
+ startInclusive: query?.startInclusive ?? undefined,
579
+ pageSize: query?.pageSize ?? undefined,
580
+ },
581
+ },
582
+ });
583
+ }
501
584
  /**
502
585
  * Get profit and loss history for an account
503
586
  *
@@ -531,6 +614,71 @@ class Nord {
531
614
  },
532
615
  });
533
616
  }
617
+ /**
618
+ * Fetch the per-market fee quote for an account.
619
+ *
620
+ * @param params - Market id, fee kind, and account id to quote
621
+ * @returns Fee in quote token units (negative means fee is charged)
622
+ * @throws {NordError} If the request fails
623
+ */
624
+ async getMarketFee({ marketId, feeKind, accountId, }) {
625
+ return await this.GET("/market/{market_id}/fees/{fee_kind}/{account_id}", {
626
+ params: {
627
+ path: {
628
+ market_id: marketId,
629
+ fee_kind: feeKind,
630
+ account_id: accountId,
631
+ },
632
+ },
633
+ });
634
+ }
635
+ /**
636
+ * Fetch token statistics such as index price and oracle metadata.
637
+ *
638
+ * @param tokenId - Token identifier
639
+ * @returns Token stats
640
+ * @throws {NordError} If the request fails
641
+ */
642
+ async getTokenStats(tokenId) {
643
+ return await this.GET("/tokens/{token_id}/stats", {
644
+ params: {
645
+ path: { token_id: tokenId },
646
+ },
647
+ });
648
+ }
649
+ /**
650
+ * Get order summary by order id.
651
+ *
652
+ * @param orderId - Order identifier
653
+ * @returns Order information
654
+ * @throws {NordError} If the request fails
655
+ */
656
+ async getOrder(orderId) {
657
+ return await this.GET("/order/{order_id}", {
658
+ params: {
659
+ path: { order_id: orderId },
660
+ },
661
+ });
662
+ }
663
+ /**
664
+ * Get trade history for a specific order.
665
+ *
666
+ * @param orderId - Order identifier
667
+ * @param query - Optional pagination parameters
668
+ * @returns Page of trades associated with the order
669
+ * @throws {NordError} If the request fails
670
+ */
671
+ async getOrderTrades(orderId, query) {
672
+ return await this.GET("/order/{order_id}/trades", {
673
+ params: {
674
+ path: { order_id: orderId },
675
+ query: {
676
+ startInclusive: query?.startInclusive,
677
+ pageSize: query?.pageSize,
678
+ },
679
+ },
680
+ });
681
+ }
534
682
  /**
535
683
  * Check if an account exists for the given address
536
684
  *