@n1xyz/nord-ts 0.3.4 → 0.3.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.
package/README.md CHANGED
@@ -110,6 +110,27 @@ try {
110
110
  }
111
111
  ```
112
112
 
113
+ ### Quote-Sized Orders
114
+
115
+ For orders limited by quote amount (e.g., USD value), pass a single decimal value:
116
+
117
+ ```typescript
118
+ // Place a market/limit order capped by quote value
119
+ await user.placeOrder({
120
+ marketId: 0,
121
+ side: Side.Bid,
122
+ fillMode: FillMode.Limit,
123
+ isReduceOnly: false,
124
+ // Limit by quote: $100 at $50,000 results in ~0.002 BTC
125
+ quoteSize: 100,
126
+ });
127
+ ```
128
+
129
+ Notes:
130
+ - `quoteSize` is a positive decimal representing the desired quote amount.
131
+ - The wire format encodes quote amount as a 128-bit value scaled by `price_decimals + size_decimals` of the target market.
132
+ - At least one limit must be provided among `size`, `price`, or `quoteSize`.
133
+
113
134
  ### Deposits and Withdrawals
114
135
 
115
136
  ```typescript
package/dist/actions.d.ts CHANGED
@@ -2,9 +2,9 @@ import Decimal from "decimal.js";
2
2
  import * as proto from "./gen/nord_pb";
3
3
  import { paths } from "./gen/openapi";
4
4
  import { Client } from "openapi-fetch";
5
- import { FillMode, Side, QuoteSize } from "./types";
5
+ import { FillMode, Side } from "./types";
6
6
  import { BigIntValue } from "./utils";
7
- import { PublicKey } from "@solana/web3.js";
7
+ import { PublicKey, Transaction } from "@solana/web3.js";
8
8
  type ReceiptKind = NonNullable<proto.Receipt["kind"]>;
9
9
  type ExtractReceiptKind<K extends ReceiptKind["case"]> = Extract<ReceiptKind, {
10
10
  case: K;
@@ -19,7 +19,9 @@ export declare function prepareAction(action: proto.Action, makeSignedMessage: (
19
19
  export declare function createSession(client: Client<paths>, signMessage: (_: Uint8Array) => Promise<Uint8Array>, currentTimestamp: bigint, nonce: number, params: {
20
20
  userPubkey: PublicKey;
21
21
  sessionPubkey: PublicKey;
22
+ signatureFraming: "hex" | "solanaTransaction";
22
23
  expiryTimestamp?: bigint;
24
+ signTransactionFn: (tx: Transaction) => Promise<Transaction>;
23
25
  }): Promise<{
24
26
  actionId: bigint;
25
27
  sessionId: bigint;
@@ -39,7 +41,7 @@ export type AtomicSubaction = {
39
41
  priceDecimals: number;
40
42
  size?: Decimal.Value;
41
43
  price?: Decimal.Value;
42
- quoteSize?: QuoteSize;
44
+ quoteSize?: Decimal.Value;
43
45
  clientOrderId?: BigIntValue;
44
46
  } | {
45
47
  kind: "cancel";
@@ -205,7 +205,7 @@ export declare class Nord {
205
205
  pageSize?: number;
206
206
  since?: string;
207
207
  until?: string;
208
- startInclusive?: string;
208
+ startInclusive?: number;
209
209
  }>): Promise<TradesResponse>;
210
210
  /**
211
211
  * Get user account IDs
@@ -284,18 +284,20 @@ export declare class Nord {
284
284
  * @throws {NordError} If the request fails
285
285
  */
286
286
  getAccountOrders(accountId: number, { startInclusive, pageSize, }?: Readonly<{
287
- startInclusive?: string | null;
288
- pageSize?: number | null;
287
+ startInclusive?: number;
288
+ pageSize?: number;
289
289
  }>): Promise<PageResultStringOrderInfo>;
290
290
  /**
291
291
  * List account fee tiers with pagination support.
292
292
  *
293
293
  * @param startInclusive - Account id cursor to resume from
294
294
  * @param pageSize - Maximum number of entries to return
295
+ * @param tier - Optional fee tier filter
295
296
  */
296
- getAccountsFeeTiers({ startInclusive, pageSize, }?: Readonly<{
297
- startInclusive?: number | null;
298
- pageSize?: number | null;
297
+ getAccountsFeeTiers({ startInclusive, pageSize, tier, }?: Readonly<{
298
+ startInclusive?: number;
299
+ pageSize?: number;
300
+ tier?: FeeTierId;
299
301
  }>): Promise<AccountFeeTierPage>;
300
302
  /**
301
303
  * Get profit and loss history for an account
@@ -349,7 +351,7 @@ export declare class Nord {
349
351
  * @returns Order information
350
352
  * @throws {NordError} If the request fails
351
353
  */
352
- getOrder(orderId: string): Promise<OrderInfoFromApi>;
354
+ getOrder(orderId: number): Promise<OrderInfoFromApi>;
353
355
  /**
354
356
  * Get trade history for a specific order.
355
357
  *
@@ -359,9 +361,9 @@ export declare class Nord {
359
361
  * @returns Page of trades associated with the order
360
362
  * @throws {NordError} If the request fails
361
363
  */
362
- getOrderTrades(orderId: string, { startInclusive, pageSize, }?: Readonly<{
363
- startInclusive?: string | null;
364
- pageSize?: number | null;
364
+ getOrderTrades(orderId: number, { startInclusive, pageSize, }?: Readonly<{
365
+ startInclusive?: number;
366
+ pageSize?: number;
365
367
  }>): Promise<PageResultStringTrade>;
366
368
  /**
367
369
  * Check if an account exists for the given address
@@ -2,6 +2,7 @@ import { PublicKey, Transaction } from "@solana/web3.js";
2
2
  import * as proto from "../gen/nord_pb";
3
3
  import { Nord } from "./Nord";
4
4
  import { FeeTierConfig } from "../gen/nord_pb";
5
+ import Decimal from "decimal.js";
5
6
  export declare enum AclRole {
6
7
  FEE_MANAGER = 1,
7
8
  MARKET_MANAGER = 2,
@@ -182,6 +183,20 @@ export declare class NordAdmin {
182
183
  * - The first appended tier receives id 1, and subsequent tiers increment the id.
183
184
  *
184
185
  * @param config - Fee tier configuration to insert
186
+ *
187
+ * Use 1/1_000_000 granularity (ppm)
188
+ * | ppm | decimal | percent |
189
+ * |------|----------|---------|
190
+ * | 1 | 0.000001 | 0.0001% |
191
+ * | 5 | 0.000005 | 0.0005% |
192
+ * | 10 | 0.00001 | 0.001% |
193
+ * | 50 | 0.00005 | 0.005% |
194
+ * | 100 | 0.0001 | 0.01% |
195
+ * | 500 | 0.0005 | 0.05% |
196
+ * | 1000 | 0.001 | 0.10% |
197
+ * | 5000 | 0.005 | 0.50% |
198
+ * | 10000| 0.01 | 1.00% |
199
+ *
185
200
  * @returns Action identifier and fee tier addition receipt
186
201
  * @throws {NordError} If the action submission fails or the new tier exceeds the maximum range (0-15).
187
202
  */
@@ -222,4 +237,11 @@ export declare class NordAdmin {
222
237
  updateAccountsTier(accounts: number[], tierId: number): Promise<{
223
238
  actionId: bigint;
224
239
  } & proto.Receipt_AccountsTierUpdated>;
240
+ feeVaultTransfer({ recipient, tokenId, amount, }: Readonly<{
241
+ recipient: number;
242
+ tokenId: number;
243
+ amount: Decimal.Value;
244
+ }>): Promise<{
245
+ actionId: bigint;
246
+ } & proto.Receipt_FeeVaultTransferred>;
225
247
  }
@@ -1,6 +1,6 @@
1
1
  import { PublicKey, Transaction, SendOptions } from "@solana/web3.js";
2
2
  import Decimal from "decimal.js";
3
- import { FillMode, Side, SPLTokenInfo, QuoteSize, TriggerKind } from "../types";
3
+ import { FillMode, Side, SPLTokenInfo, TriggerKind } from "../types";
4
4
  import * as proto from "../gen/nord_pb";
5
5
  import { BigIntValue } from "../utils";
6
6
  import { Nord } from "./Nord";
@@ -24,8 +24,8 @@ export interface UserAtomicSubaction {
24
24
  size?: Decimal.Value;
25
25
  /** Order price */
26
26
  price?: Decimal.Value;
27
- /** Quote size object (for market-style placement) */
28
- quoteSize?: QuoteSize;
27
+ /** Quote size in `base_decimals` + `price_decimals` (for market-style placement) */
28
+ quoteSize?: Decimal.Value;
29
29
  /** The client order ID of the order. */
30
30
  clientOrderId?: BigIntValue;
31
31
  }
@@ -36,6 +36,13 @@ export declare class NordUser {
36
36
  private readonly signSessionMessage;
37
37
  private readonly signMessage;
38
38
  private readonly signTransaction;
39
+ /** If set, will use signTransaction instead of signMessage for session creation.
40
+ * Because ledgers don't support signMessage, we have an escape hatch for them.
41
+ * However, the escape hatch is brittle and we recommend avoiditing as much as
42
+ * possible. Thus, _only_ use this if you are forced to use ledgers.
43
+ * To use this, just set it to true in your NordUser instance.
44
+ */
45
+ __use_solana_transaction_framing__: boolean;
39
46
  readonly nord: Nord;
40
47
  sessionId?: bigint;
41
48
  sessionPubKey: PublicKey;
@@ -52,7 +59,7 @@ export declare class NordUser {
52
59
  };
53
60
  orders: {
54
61
  [key: string]: {
55
- orderId: string;
62
+ orderId: number;
56
63
  marketId: number;
57
64
  side: "ask" | "bid";
58
65
  size: number;
@@ -243,7 +250,7 @@ export declare class NordUser {
243
250
  isReduceOnly: boolean;
244
251
  size?: Decimal.Value;
245
252
  price?: Decimal.Value;
246
- quoteSize?: QuoteSize;
253
+ quoteSize?: Decimal.Value;
247
254
  accountId?: number;
248
255
  clientOrderId?: BigIntValue;
249
256
  }>): Promise<{
@@ -259,7 +266,20 @@ export declare class NordUser {
259
266
  * @returns Object containing actionId, cancelled orderId, and accountId
260
267
  * @throws {NordError} If the operation fails
261
268
  */
262
- cancelOrder(orderId: BigIntValue, providedAccountId?: number): Promise<{
269
+ cancelOrder(orderId: BigIntValue, accountId?: number): Promise<{
270
+ actionId: bigint;
271
+ orderId: bigint;
272
+ accountId: number;
273
+ }>;
274
+ /**
275
+ * Cancel an order by client_order_id.
276
+ *
277
+ * @param clientOrderId - Client order ID to cancel
278
+ * @param providedAccountId - Account ID that placed the order (defaults to the first account)
279
+ * @returns Object containing actionId, cancelled orderId, and accountId
280
+ * @throws {NordError} If the operation fails
281
+ */
282
+ cancelOrderByClientId(clientOrderId: BigIntValue, accountId?: number): Promise<{
263
283
  actionId: bigint;
264
284
  orderId: bigint;
265
285
  accountId: number;
@@ -295,20 +315,22 @@ export declare class NordUser {
295
315
  * @param marketId - Market the trigger belongs to
296
316
  * @param side - Order side for the trigger
297
317
  * @param kind - Stop-loss or take-profit trigger type
318
+ * @param triggerPrice - Trigger price of the trigger to remove
298
319
  * @param accountId - Account executing the trigger
299
320
  * @returns Object containing the actionId of the removal action
300
321
  * @throws {NordError} If the operation fails
301
322
  */
302
- removeTrigger({ marketId, side, kind, accountId, }: Readonly<{
323
+ removeTrigger({ marketId, side, kind, triggerPrice, accountId, }: Readonly<{
303
324
  marketId: number;
304
325
  side: Side;
305
326
  kind: TriggerKind;
327
+ triggerPrice: Decimal.Value;
306
328
  accountId?: number;
307
329
  }>): Promise<{
308
330
  actionId: bigint;
309
331
  }>;
310
332
  /**
311
- * Transfer tokens to another account
333
+ * Transfer tokens to one of the user's subaccounts
312
334
  *
313
335
  * @param tokenId - Token identifier to move
314
336
  * @param amount - Amount to transfer
@@ -316,15 +338,43 @@ export declare class NordUser {
316
338
  * @param toAccountId - Destination account id
317
339
  * @throws {NordError} If the operation fails
318
340
  */
319
- transferToAccount({ tokenId, amount, fromAccountId, toAccountId, }: Readonly<{
341
+ transferOwned({ tokenId, amount, fromAccountId, toAccountId, }: Readonly<{
320
342
  tokenId: number;
321
343
  amount: Decimal.Value;
322
- fromAccountId?: number;
323
- toAccountId?: number;
344
+ fromAccountId: number;
345
+ toAccountId: number;
324
346
  }>): Promise<{
325
347
  actionId: bigint;
326
348
  newAccountId?: number;
327
349
  }>;
350
+ /**
351
+ * Transfer tokens to another unowned account
352
+ *
353
+ * @param tokenId - Token identifier to move
354
+ * @param amount - Amount to transfer
355
+ * @param fromAccountId - Source account id
356
+ * @param toAccountId - Destination account id
357
+ * @throws {NordError} If the operation fails
358
+ */
359
+ transferUnowned({ tokenId, amount, fromAccountId, toAccountId, }: Readonly<{
360
+ tokenId: number;
361
+ amount: Decimal.Value;
362
+ fromAccountId: number;
363
+ toAccountId: number;
364
+ }>): Promise<{
365
+ actionId: bigint;
366
+ newAccountId?: number;
367
+ }>;
368
+ /**
369
+ * Transfer tokens to another account
370
+ *
371
+ * @param tokenId - Token identifier to move
372
+ * @param amount - Amount to transfer
373
+ * @param fromAccountId - Source account id
374
+ * @param toAccountId - Destination account id
375
+ * @throws {NordError} If the operation fails
376
+ */
377
+ private transferToAccount;
328
378
  /**
329
379
  * Execute up to four place/cancel operations atomically.
330
380
  * Per Market: