@n1xyz/nord-ts 0.6.3 → 0.7.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.
package/README.md CHANGED
@@ -127,10 +127,29 @@ await user.placeOrder({
127
127
  ```
128
128
 
129
129
  Notes:
130
+
130
131
  - `quoteSize` is a positive decimal representing the desired quote amount.
131
132
  - The wire format encodes quote amount as a 128-bit value scaled by `price_decimals + size_decimals` of the target market.
132
133
  - At least one limit must be provided among `size`, `price`, or `quoteSize`.
133
134
 
135
+ ### RFQ fills and funding sampling
136
+
137
+ `fillRfqOrder` always returns the normal RFQ fill result. For non-executable
138
+ funding sampling, `filledSize` and `tradeId` are `null`:
139
+
140
+ ```typescript
141
+ const result = await user.fillRfqOrder({ marketId, orderId, price });
142
+
143
+ if (result.filledSize === null) {
144
+ // A price observation only; no trade, balance, or position change occurred.
145
+ console.log(result.orderId, result.makerAccountId);
146
+ } else {
147
+ console.log(result.filledSize, result.tradeId);
148
+ }
149
+ ```
150
+
151
+ Real RFQ executions use the same result shape with both execution values set.
152
+
134
153
  ### Deposits and Withdrawals
135
154
 
136
155
  ```typescript
package/dist/actions.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import Decimal from "decimal.js";
2
2
  import * as proto from "./gen/nord_pb";
3
+ import * as core from "./gen/core_pb";
3
4
  import { paths } from "./gen/openapi";
4
5
  import { Client } from "openapi-fetch";
5
- import { FillMode, PlacementRequest, Side, TriggerKind } from "./types";
6
+ import { type Duration, FillMode, PlacementRequest, Side, TriggerKind } from "./types";
6
7
  import { BigIntValue } from "./utils";
7
8
  import { PublicKey, Transaction } from "@solana/web3.js";
8
9
  type ReceiptKind = NonNullable<proto.Receipt["kind"]>;
@@ -14,7 +15,7 @@ export declare function expectReceiptKind<K extends ReceiptKind["case"]>(receipt
14
15
  kind: ExtractReceiptKind<K>;
15
16
  };
16
17
  export declare function buildLimits(marketPriceDecimals: number, marketSizeDecimals: number, limitPrice?: Decimal.Value, limitBaseSize?: Decimal.Value, limitQuoteSize?: Decimal.Value): proto.OrderLimit | undefined;
17
- export declare function toProtoU128(value: BigIntValue): proto.U128;
18
+ export declare function toProtoU128(value: BigIntValue): core.U128;
18
19
  export declare function createAction(currentTimestamp: bigint, nonce: number, kind: proto.Action["kind"]): proto.Action;
19
20
  export declare function sendAction(client: Client<paths>, makeSignedMessage: (message: Uint8Array) => Promise<Uint8Array>, action: proto.Action): Promise<proto.Receipt>;
20
21
  export declare function prepareAction(action: proto.Action, makeSignedMessage: (message: Uint8Array) => Promise<Uint8Array>): Promise<Uint8Array<ArrayBufferLike>>;
@@ -23,16 +24,31 @@ export declare function createSession(client: Client<paths>, signMessage: (_: Ui
23
24
  sessionPubkey: PublicKey;
24
25
  signatureFraming: "hex" | "solanaTransaction";
25
26
  expiryTimestamp?: bigint;
27
+ refreshDeadline?: bigint;
26
28
  signTransactionFn: (tx: Transaction) => Promise<Transaction>;
27
29
  }): Promise<{
28
30
  actionId: bigint;
29
31
  sessionId: bigint;
32
+ expiry: bigint;
33
+ refreshDeadline?: bigint;
30
34
  }>;
31
35
  export declare function revokeSession(client: Client<paths>, signMessage: (_: Uint8Array) => Promise<Uint8Array>, currentTimestamp: bigint, nonce: number, params: {
32
36
  sessionId: BigIntValue;
33
37
  }): Promise<{
34
38
  actionId: bigint;
35
39
  }>;
40
+ export declare function refreshSession(client: Client<paths>, signFn: (message: Uint8Array) => Promise<Uint8Array>, currentTimestamp: bigint, nonce: number, params: {
41
+ sessionId: BigIntValue;
42
+ newExpiry: bigint;
43
+ }): Promise<{
44
+ actionId: bigint;
45
+ newExpiry: bigint;
46
+ }>;
47
+ export declare function selfRevokeSession(client: Client<paths>, signFn: (message: Uint8Array) => Promise<Uint8Array>, currentTimestamp: bigint, nonce: number, params: {
48
+ sessionId: BigIntValue;
49
+ }): Promise<{
50
+ actionId: bigint;
51
+ }>;
36
52
  export declare function createTakeAllPositionsInput(params: {
37
53
  sessionId: BigIntValue;
38
54
  targetAccountId: number;
@@ -68,6 +84,31 @@ export type AtomicSubaction = {
68
84
  clientOrderId: BigIntValue;
69
85
  delegatorAccountId?: number;
70
86
  placement?: PlacementRequest;
87
+ } | {
88
+ kind: "reduceOrderLiquidation";
89
+ targetAccountId: number;
90
+ marketId: number;
91
+ delegatorAccountId?: number;
92
+ placement?: PlacementRequest;
93
+ } | {
94
+ kind: "rfq";
95
+ marketId: number;
96
+ side: Side;
97
+ priceDecimals: number;
98
+ sizeDecimals: number;
99
+ price: Decimal.Value;
100
+ size: Decimal.Value;
101
+ timeout?: Duration;
102
+ clientOrderId?: BigIntValue;
103
+ delegatorAccountId?: number;
104
+ } | {
105
+ kind: "rfqFill";
106
+ marketId: number;
107
+ orderId: BigIntValue;
108
+ priceDecimals: number;
109
+ price: Decimal.Value;
110
+ timeout?: Duration;
111
+ delegatorAccountId?: number;
71
112
  } | {
72
113
  kind: "addTrigger";
73
114
  marketId: number;
@@ -100,6 +141,7 @@ export type AtomicSubaction = {
100
141
  triggerId: BigIntValue;
101
142
  placement?: PlacementRequest;
102
143
  };
144
+ export declare function atomicSubactionToProto(currentTimestamp: bigint, a: AtomicSubaction, omitDelegatorAccountId?: boolean): proto.AtomicSubaction;
103
145
  export declare function atomic(client: Client<paths>, signFn: (message: Uint8Array) => Promise<Uint8Array>, currentTimestamp: bigint, nonce: number, params: {
104
146
  sessionId: BigIntValue;
105
147
  accountId?: number;
@@ -3,9 +3,9 @@ import { Connection, PublicKey } from "@solana/web3.js";
3
3
  import { EventEmitter } from "events";
4
4
  import { Client } from "openapi-fetch";
5
5
  import type { paths } from "../gen/openapi.ts";
6
- import { Account, AccountPnlInfoPage, AccountPositionInfoPage, AccountPnlSummaryResult, ActionIdSubActionIdMarketIdCursor, AtomicActionId, GetAccountPositionHistoryQuery, GetAccountPnlQuery, PagedQuery, ActionResponse, MarketsInfo, Market, MarketStats, NordConfig, OrderbookQuery, OrderbookResponse, FeeTierConfig, Token, TradesResponse, User, AccountTriggerInfo, TriggerPlaceHistoryPage, TriggerFinaliseHistoryPage, WithdrawalHistoryPage, FeeTierId, AccountFeeTierPage, PageResultStringOrderInfo, PageResultStringTrade, OrderInfoFromApi, TokenStats, FillRole, AdminInfo, AccountVolumeInfo, GetAccountVolumeQuery, CandleResolution, TakeAllInfo, MarketsLiveInfo, MarketLiveInfo } from "../types";
6
+ import { Account, AccountPnlInfoPage, AccountPositionInfoPage, AccountPnlSummaryResult, ActionIdSubActionIdMarketIdCursor, AtomicActionId, GetAccountPositionHistoryQuery, GetAccountPnlQuery, PagedQuery, ActionResponse, MarketsInfo, Market, MarketSymbol, MarketStats, NordConfig, OrderbookQuery, OrderbookResponse, FeeTierConfig, Token, TradesResponse, User, AccountTriggerInfo, TriggerPlaceHistoryPage, TriggerFinaliseHistoryPage, WithdrawalHistoryPage, FeeTierId, AccountFeeTierPage, PageResultStringOrderInfo, PageResultStringTrade, OrderInfoFromApi, TokenStats, FillRole, AdminInfo, AccountVolumeInfo, GetAccountVolumeQuery, CandleResolution, TakeAllInfo, MarketsLiveInfo, MarketLiveInfo } from "../types";
7
7
  import { NordWebSocketClient } from "../websocket/index";
8
- import { OrderbookSubscription, TradeSubscription, CandleSubscription } from "../websocket/Subscriber";
8
+ import { OrderbookSubscription, TradeSubscription, CandleSubscription, RfqFillsSubscription } from "../websocket/Subscriber";
9
9
  /**
10
10
  * User subscription interface
11
11
  */
@@ -46,6 +46,7 @@ export declare class Nord {
46
46
  * @param deltas - Market symbols to subscribe to for orderbook delta updates
47
47
  * @param accounts - Account IDs to subscribe to for account updates
48
48
  * @param candles - Candle subscriptions with symbol and resolution
49
+ * @param rfqFills - Market symbols or market ids to subscribe to for RFQ fill requests
49
50
  * @param liquidations - Whether to subscribe to take-all liquidation updates
50
51
  * @returns A new WebSocket client with the requested subscriptions
51
52
  * @throws {NordError} If invalid subscription options are provided
@@ -64,7 +65,7 @@ export declare class Nord {
64
65
  * trades: ["BTCUSDC", "ETHUSDC"]
65
66
  * });
66
67
  */
67
- createWebSocketClient({ trades, deltas, accounts, candles, liquidations, }: Readonly<{
68
+ createWebSocketClient({ trades, deltas, accounts, candles, rfqFills, liquidations, }: Readonly<{
68
69
  trades?: string[];
69
70
  deltas?: string[];
70
71
  accounts?: number[];
@@ -72,6 +73,7 @@ export declare class Nord {
72
73
  symbol: string;
73
74
  resolution: CandleResolution;
74
75
  }>;
76
+ rfqFills?: MarketSymbol[];
75
77
  liquidations?: boolean;
76
78
  }>): NordWebSocketClient;
77
79
  private GET;
@@ -184,6 +186,7 @@ export declare class Nord {
184
186
  * @throws {NordError} If symbol is invalid
185
187
  */
186
188
  subscribeTrades(symbol: string): TradeSubscription;
189
+ subscribeRfqFills(market: MarketSymbol): RfqFillsSubscription;
187
190
  /**
188
191
  * Subscribe to account updates
189
192
  *
@@ -8,6 +8,22 @@ export declare enum AclRole {
8
8
  MARKET_MANAGER = 2,
9
9
  ADMIN = 2147483648
10
10
  }
11
+ /**
12
+ * Pyth Lazer ed25519 trusted signer configuration.
13
+ *
14
+ * This mirrors the Pyth Solana contract manager shape:
15
+ * `{ publicKey: string; expiresAt: bigint }`.
16
+ */
17
+ export type PythLazerTrustedSigner = Readonly<{
18
+ /** Base58 Solana public key, or a `PublicKey` instance. */
19
+ publicKey: PublicKey;
20
+ /** Solana timestamp */
21
+ expiresAt: number;
22
+ }>;
23
+ export type PythLazerFeedSymbolInput = Readonly<{
24
+ feedId: number;
25
+ oracleSymbol: string;
26
+ }>;
11
27
  /**
12
28
  * Administrative client capable of submitting privileged configuration actions.
13
29
  */
@@ -133,6 +149,45 @@ export declare class NordAdmin {
133
149
  }>): Promise<{
134
150
  actionId: bigint;
135
151
  } & proto.Receipt_OracleSymbolFeedResult>;
152
+ /**
153
+ * Configure the fixed Pyth Lazer ed25519 trusted signer set.
154
+ *
155
+ * The input must contain exactly five unique Solana public keys. Signer
156
+ * entries use the same external shape as Pyth's Solana contract manager:
157
+ * `{ publicKey: string; expiresAt: bigint }`.
158
+ *
159
+ * @param trustedSigners - Five ed25519 trusted signer entries
160
+ * @returns Action identifier and trusted signer receipt
161
+ * @throws {NordError} If the signer shape is invalid or submission fails
162
+ */
163
+ pythLazerSetTrustedSigners({ trustedSigners, }: Readonly<{
164
+ trustedSigners: readonly PythLazerTrustedSigner[];
165
+ }>): Promise<{
166
+ actionId: bigint;
167
+ } & proto.Receipt_PythLazerTrustedSignersSetResult>;
168
+ /**
169
+ * Link one or more Pyth Lazer feed ids to Nord oracle symbols.
170
+ *
171
+ * @param feeds - Feed id to oracle symbol mappings
172
+ * @returns Action identifier and feed-symbol receipt
173
+ * @throws {NordError} If the feed mapping shape is invalid or submission fails
174
+ */
175
+ pythLazerSetFeedSymbols({ feeds, }: Readonly<{
176
+ feeds: readonly PythLazerFeedSymbolInput[];
177
+ }>): Promise<{
178
+ actionId: bigint;
179
+ } & proto.Receipt_PythLazerFeedSymbolSetResult>;
180
+ /**
181
+ * Link a single Pyth Lazer feed id to a Nord oracle symbol.
182
+ *
183
+ * @param feedId - Pyth Lazer feed id
184
+ * @param oracleSymbol - Symbol resolved by the oracle adapter
185
+ * @returns Action identifier and feed-symbol receipt
186
+ * @throws {NordError} If the feed mapping shape is invalid or submission fails
187
+ */
188
+ pythLazerSetFeedSymbol({ feedId, oracleSymbol, }: PythLazerFeedSymbolInput): Promise<{
189
+ actionId: bigint;
190
+ } & proto.Receipt_PythLazerFeedSymbolSetResult>;
136
191
  /**
137
192
  * Pause all trading activity on the exchange.
138
193
  *
@@ -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, TriggerKind, SelfTradePrevention, PlacementRequest, VaultWithdrawRequestKind } from "../types";
3
+ import { FillMode, Side, SPLTokenInfo, TriggerKind, SelfTradePrevention, PlacementRequest, VaultWithdrawRequestKind, type Duration, type RfqFillResult } from "../types";
4
4
  import * as proto from "../gen/nord_pb";
5
5
  import { BigIntValue } from "../utils";
6
6
  import { Nord } from "./Nord";
@@ -27,6 +27,28 @@ export type UserAtomicSubaction = {
27
27
  clientOrderId: BigIntValue;
28
28
  delegatorAccountId?: number;
29
29
  placement?: PlacementRequest;
30
+ } | {
31
+ kind: "reduceOrderLiquidation";
32
+ targetAccountId: number;
33
+ marketId: number;
34
+ delegatorAccountId?: number;
35
+ placement?: PlacementRequest;
36
+ } | {
37
+ kind: "rfq";
38
+ marketId: number;
39
+ side: Side;
40
+ price: Decimal.Value;
41
+ size: Decimal.Value;
42
+ timeout?: Duration;
43
+ clientOrderId?: BigIntValue;
44
+ delegatorAccountId?: number;
45
+ } | {
46
+ kind: "rfqFill";
47
+ marketId: number;
48
+ orderId: BigIntValue;
49
+ price: Decimal.Value;
50
+ timeout?: Duration;
51
+ delegatorAccountId?: number;
30
52
  } | {
31
53
  kind: "addTrigger";
32
54
  marketId: number;
@@ -55,6 +77,7 @@ export type UserAtomicSubaction = {
55
77
  triggerId: BigIntValue;
56
78
  placement?: PlacementRequest;
57
79
  };
80
+ export declare function decodeRfqFillResult(actionId: bigint, result: proto.Receipt_AtomicSubactionResultKind["inner"] | undefined): RfqFillResult;
58
81
  export interface NormalizedReceiptTrade {
59
82
  orderId: bigint;
60
83
  price: number;
@@ -107,7 +130,7 @@ export declare class NordUser {
107
130
  size: number;
108
131
  price: number;
109
132
  originalOrderSize: number;
110
- clientOrderId: number | null;
133
+ clientOrderId: string | null;
111
134
  }[];
112
135
  };
113
136
  /** User positions by account ID */
@@ -241,7 +264,11 @@ export declare class NordUser {
241
264
  *
242
265
  * @throws {NordError} If the operation fails
243
266
  */
244
- refreshSession(expiryTimestamp?: bigint): Promise<void>;
267
+ refreshSession(expiryTimestamp?: bigint, refreshDeadline?: bigint): Promise<{
268
+ sessionId: bigint;
269
+ expiry: bigint;
270
+ refreshDeadline?: bigint;
271
+ }>;
245
272
  /**
246
273
  * Revoke a session
247
274
  *
@@ -249,6 +276,33 @@ export declare class NordUser {
249
276
  * @throws {NordError} If the operation fails
250
277
  */
251
278
  revokeSession(sessionId: BigIntValue): Promise<void>;
279
+ /**
280
+ * Extend the CURRENT session's expiry in place, signed by the session key
281
+ * (no wallet popup). Unlike {@link refreshSession}, this keeps the same
282
+ * session id and does not require a wallet signature.
283
+ *
284
+ * The engine clamps the new expiry to the session's `refresh_deadline`
285
+ * (the hard bound chosen at session creation); once that deadline is reached,
286
+ * or if the session was created without one, a fresh {@link refreshSession}
287
+ * (wallet) is required.
288
+ *
289
+ * @param newExpiry - Desired new expiry (unix seconds). Defaults to now + TTL.
290
+ * @throws {NordError} If the operation fails
291
+ */
292
+ selfRefreshSession(newExpiry?: bigint): Promise<{
293
+ actionId: bigint;
294
+ newExpiry: bigint;
295
+ }>;
296
+ /**
297
+ * Revoke the CURRENT session itself, signed by the session key (no wallet
298
+ * popup). Safe logout: can only ever revoke this session. Clears the local
299
+ * session id on success.
300
+ *
301
+ * @throws {NordError} If the operation fails
302
+ */
303
+ selfRevoke(): Promise<{
304
+ actionId: bigint;
305
+ }>;
252
306
  /**
253
307
  * Checks if the session is valid
254
308
  * @private
@@ -351,6 +405,25 @@ export declare class NordUser {
351
405
  orderId: bigint;
352
406
  accountId: number;
353
407
  }>;
408
+ placeRfqOrder({ marketId, side, size, price, timeout, accountId, clientOrderId, }: Readonly<{
409
+ marketId: number;
410
+ side: Side;
411
+ size: Decimal.Value;
412
+ price: Decimal.Value;
413
+ timeout?: Duration;
414
+ accountId?: number;
415
+ clientOrderId?: BigIntValue;
416
+ }>): Promise<{
417
+ actionId: bigint;
418
+ orderId: bigint;
419
+ }>;
420
+ fillRfqOrder({ marketId, orderId, price, timeout, accountId, }: Readonly<{
421
+ marketId: number;
422
+ orderId: BigIntValue;
423
+ price: Decimal.Value;
424
+ timeout?: Duration;
425
+ accountId?: number;
426
+ }>): Promise<RfqFillResult>;
354
427
  /**
355
428
  * Cancel an order by client_order_id.
356
429
  *
@@ -0,0 +1,120 @@
1
+ import type { GenEnum, GenFile, GenMessage } from "@bufbuild/protobuf/codegenv2";
2
+ import type { Message } from "@bufbuild/protobuf";
3
+ /**
4
+ * Describes the file core.proto.
5
+ */
6
+ export declare const file_core: GenFile;
7
+ /**
8
+ * Helper struct to represent 128-bit
9
+ * unsigned values.
10
+ *
11
+ * @generated from message nord.U128
12
+ */
13
+ export type U128 = Message<"nord.U128"> & {
14
+ /**
15
+ * lower 64 bits
16
+ *
17
+ * @generated from field: uint64 lo = 1;
18
+ */
19
+ lo: bigint;
20
+ /**
21
+ * upper 64 bits
22
+ *
23
+ * @generated from field: uint64 hi = 2;
24
+ */
25
+ hi: bigint;
26
+ };
27
+ /**
28
+ * Helper struct to represent 128-bit
29
+ * unsigned values.
30
+ *
31
+ * @generated from message nord.U128
32
+ */
33
+ export type U128Json = {
34
+ /**
35
+ * lower 64 bits
36
+ *
37
+ * @generated from field: uint64 lo = 1;
38
+ */
39
+ lo?: string;
40
+ /**
41
+ * upper 64 bits
42
+ *
43
+ * @generated from field: uint64 hi = 2;
44
+ */
45
+ hi?: string;
46
+ };
47
+ /**
48
+ * Describes the message nord.U128.
49
+ * Use `create(U128Schema)` to create a new message.
50
+ */
51
+ export declare const U128Schema: GenMessage<U128, {
52
+ jsonType: U128Json;
53
+ }>;
54
+ /**
55
+ * @generated from enum nord.Side
56
+ */
57
+ export declare enum Side {
58
+ /**
59
+ * @generated from enum value: ASK = 0;
60
+ */
61
+ ASK = 0,
62
+ /**
63
+ * @generated from enum value: BID = 1;
64
+ */
65
+ BID = 1
66
+ }
67
+ /**
68
+ * @generated from enum nord.Side
69
+ */
70
+ export type SideJson = "ASK" | "BID";
71
+ /**
72
+ * Describes the enum nord.Side.
73
+ */
74
+ export declare const SideSchema: GenEnum<Side, SideJson>;
75
+ /**
76
+ * @generated from enum nord.MarketMode
77
+ */
78
+ export declare enum MarketMode {
79
+ /**
80
+ * @generated from enum value: CLOB = 0;
81
+ */
82
+ CLOB = 0,
83
+ /**
84
+ * @generated from enum value: RFQ = 1;
85
+ */
86
+ RFQ = 1
87
+ }
88
+ /**
89
+ * @generated from enum nord.MarketMode
90
+ */
91
+ export type MarketModeJson = "CLOB" | "RFQ";
92
+ /**
93
+ * Describes the enum nord.MarketMode.
94
+ */
95
+ export declare const MarketModeSchema: GenEnum<MarketMode, MarketModeJson>;
96
+ /**
97
+ * @generated from enum nord.MarketRegime
98
+ */
99
+ export declare enum MarketRegime {
100
+ /**
101
+ * @generated from enum value: MARKET_REGIME_NORMAL = 0;
102
+ */
103
+ NORMAL = 0,
104
+ /**
105
+ * @generated from enum value: MARKET_REGIME_POST_ONLY = 1;
106
+ */
107
+ POST_ONLY = 1,
108
+ /**
109
+ * @generated from enum value: MARKET_REGIME_TRADE_ONLY = 2;
110
+ */
111
+ TRADE_ONLY = 2
112
+ }
113
+ /**
114
+ * @generated from enum nord.MarketRegime
115
+ */
116
+ export type MarketRegimeJson = "MARKET_REGIME_NORMAL" | "MARKET_REGIME_POST_ONLY" | "MARKET_REGIME_TRADE_ONLY";
117
+ /**
118
+ * Describes the enum nord.MarketRegime.
119
+ */
120
+ export declare const MarketRegimeSchema: GenEnum<MarketRegime, MarketRegimeJson>;