@n1xyz/nord-ts 0.1.7 → 0.1.8

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 (84) hide show
  1. package/dist/actions.js +39 -82
  2. package/dist/bundle.js +79181 -0
  3. package/dist/client/Nord.d.ts +2 -2
  4. package/dist/client/Nord.js +46 -78
  5. package/dist/client/NordAdmin.d.ts +2 -2
  6. package/dist/client/NordAdmin.js +57 -89
  7. package/dist/client/NordUser.js +118 -147
  8. package/dist/const.js +5 -8
  9. package/dist/error.js +7 -5
  10. package/dist/gen/nord_pb.js +88 -92
  11. package/dist/gen/openapi.d.ts +5 -6
  12. package/dist/gen/openapi.js +1 -2
  13. package/dist/index.js +10 -49
  14. package/dist/types.d.ts +1 -0
  15. package/dist/types.js +21 -60
  16. package/dist/utils.js +38 -86
  17. package/dist/websocket/NordWebSocketClient.js +12 -17
  18. package/dist/websocket/Subscriber.js +6 -7
  19. package/dist/websocket/events.js +1 -2
  20. package/dist/websocket/index.js +10 -15
  21. package/package.json +2 -3
  22. package/dist/api/client.d.ts +0 -14
  23. package/dist/api/client.js +0 -45
  24. package/dist/bridge/client.d.ts +0 -151
  25. package/dist/bridge/client.js +0 -434
  26. package/dist/bridge/const.d.ts +0 -23
  27. package/dist/bridge/const.js +0 -47
  28. package/dist/bridge/index.d.ts +0 -4
  29. package/dist/bridge/index.js +0 -23
  30. package/dist/bridge/types.d.ts +0 -120
  31. package/dist/bridge/types.js +0 -18
  32. package/dist/bridge/utils.d.ts +0 -64
  33. package/dist/bridge/utils.js +0 -131
  34. package/dist/gen/common.d.ts +0 -68
  35. package/dist/gen/common.js +0 -215
  36. package/dist/gen/nord.d.ts +0 -882
  37. package/dist/gen/nord.js +0 -6520
  38. package/dist/idl/bridge.d.ts +0 -569
  39. package/dist/idl/bridge.js +0 -8
  40. package/dist/idl/bridge.json +0 -1506
  41. package/dist/idl/index.d.ts +0 -607
  42. package/dist/idl/index.js +0 -8
  43. package/dist/nord/api/actions.d.ts +0 -126
  44. package/dist/nord/api/actions.js +0 -397
  45. package/dist/nord/api/core.d.ts +0 -16
  46. package/dist/nord/api/core.js +0 -81
  47. package/dist/nord/api/market.d.ts +0 -36
  48. package/dist/nord/api/market.js +0 -96
  49. package/dist/nord/api/metrics.d.ts +0 -67
  50. package/dist/nord/api/metrics.js +0 -229
  51. package/dist/nord/api/queries.d.ts +0 -46
  52. package/dist/nord/api/queries.js +0 -109
  53. package/dist/nord/api/triggers.d.ts +0 -7
  54. package/dist/nord/api/triggers.js +0 -38
  55. package/dist/nord/client/Nord.d.ts +0 -396
  56. package/dist/nord/client/Nord.js +0 -747
  57. package/dist/nord/client/NordAdmin.d.ts +0 -259
  58. package/dist/nord/client/NordAdmin.js +0 -395
  59. package/dist/nord/client/NordClient.d.ts +0 -33
  60. package/dist/nord/client/NordClient.js +0 -45
  61. package/dist/nord/client/NordUser.d.ts +0 -362
  62. package/dist/nord/client/NordUser.js +0 -781
  63. package/dist/nord/index.d.ts +0 -11
  64. package/dist/nord/index.js +0 -36
  65. package/dist/nord/models/Subscriber.d.ts +0 -37
  66. package/dist/nord/models/Subscriber.js +0 -25
  67. package/dist/nord/utils/NordError.d.ts +0 -35
  68. package/dist/nord/utils/NordError.js +0 -49
  69. package/src/actions.ts +0 -333
  70. package/src/client/Nord.ts +0 -934
  71. package/src/client/NordAdmin.ts +0 -484
  72. package/src/client/NordUser.ts +0 -1122
  73. package/src/const.ts +0 -34
  74. package/src/error.ts +0 -76
  75. package/src/gen/.gitkeep +0 -0
  76. package/src/gen/nord_pb.ts +0 -5053
  77. package/src/gen/openapi.ts +0 -2904
  78. package/src/index.ts +0 -11
  79. package/src/types.ts +0 -327
  80. package/src/utils.ts +0 -266
  81. package/src/websocket/NordWebSocketClient.ts +0 -316
  82. package/src/websocket/Subscriber.ts +0 -56
  83. package/src/websocket/events.ts +0 -31
  84. package/src/websocket/index.ts +0 -105
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NordClient = void 0;
4
- const web3_js_1 = require("@solana/web3.js");
5
- const actions_1 = require("../api/actions");
6
- class NordClient {
7
- constructor(params) {
8
- this.lastTs = 0;
9
- this.actionNonce = 0;
10
- this.nord = params.nord;
11
- this.address = params.address;
12
- this.walletSignFn = params.walletSignFn;
13
- this.sessionSignFn = params.sessionSignFn;
14
- this.transactionSignFn = params.transactionSignFn;
15
- this.connection =
16
- params.connection ??
17
- new web3_js_1.Connection(params.nord.solanaUrl, {
18
- commitment: "confirmed",
19
- });
20
- this.sessionId = params.sessionId;
21
- this.sessionPubKey = new Uint8Array(params.sessionPubKey);
22
- this.publicKey = params.publicKey;
23
- }
24
- async submitSignedAction(kind, makeSignedMessage) {
25
- const nonce = this.nextActionNonce();
26
- const currentTimestamp = await this.nord.getTimestamp();
27
- const action = (0, actions_1.createAction)(currentTimestamp, nonce, kind);
28
- return (0, actions_1.sendAction)(this.nord.webServerUrl, makeSignedMessage, action);
29
- }
30
- nextActionNonce() {
31
- return ++this.actionNonce;
32
- }
33
- cloneClientState(target) {
34
- target.connection = this.connection;
35
- target.sessionId = this.sessionId;
36
- target.sessionPubKey = new Uint8Array(this.sessionPubKey);
37
- target.publicKey = this.publicKey;
38
- target.lastTs = this.lastTs;
39
- target.actionNonce = this.actionNonce;
40
- }
41
- getSolanaPublicKey() {
42
- return this.address;
43
- }
44
- }
45
- exports.NordClient = NordClient;
@@ -1,362 +0,0 @@
1
- import { Connection, PublicKey, Transaction, SendOptions } from "@solana/web3.js";
2
- import Decimal from "decimal.js";
3
- import { FillMode, Side, SPLTokenInfo, QuoteSize, TriggerKind } from "../../types";
4
- import * as proto from "../../gen/nord_pb";
5
- import { BigIntValue } from "../../utils";
6
- import { Nord } from "./Nord";
7
- import { NordClient } from "./NordClient";
8
- /**
9
- * Parameters for creating a NordUser instance
10
- */
11
- export interface NordUserParams {
12
- /** Nord client instance */
13
- nord: Nord;
14
- /** User's blockchain address */
15
- address: string;
16
- /** Function to sign messages with the user's wallet */
17
- walletSignFn: (message: Uint8Array | string) => Promise<Uint8Array>;
18
- /** Function to sign messages with the user's session key */
19
- sessionSignFn: (message: Uint8Array) => Promise<Uint8Array>;
20
- /** Function to sign transactions with the user's wallet (optional) */
21
- transactionSignFn: <T extends Transaction>(tx: T) => Promise<T>;
22
- /** Solana connection (optional) */
23
- connection?: Connection;
24
- /** Session ID (optional) */
25
- sessionId?: bigint;
26
- /** Session public key (required) */
27
- sessionPubKey: Uint8Array;
28
- /** Session public key (required) */
29
- publicKey: PublicKey;
30
- }
31
- /**
32
- * Parameters for placing an order
33
- */
34
- export interface PlaceOrderParams {
35
- /** Market ID */
36
- marketId: number;
37
- /** Order side (bid or ask) */
38
- side: Side;
39
- /** Fill mode (limit, market, etc.) */
40
- fillMode: FillMode;
41
- /** Whether the order is reduce-only */
42
- isReduceOnly: boolean;
43
- /** Order size */
44
- size?: Decimal.Value;
45
- /** Order price */
46
- price?: Decimal.Value;
47
- /** Quote size object (requires non-zero price and size) */
48
- quoteSize?: QuoteSize;
49
- /** Account ID to place the order from */
50
- accountId?: number;
51
- clientOrderId?: BigIntValue;
52
- }
53
- export interface AddTriggerParams {
54
- marketId: number;
55
- side: Side;
56
- kind: TriggerKind;
57
- triggerPrice: Decimal.Value;
58
- limitPrice?: Decimal.Value;
59
- accountId?: number;
60
- }
61
- export interface RemoveTriggerParams {
62
- marketId: number;
63
- side: Side;
64
- kind: TriggerKind;
65
- accountId?: number;
66
- }
67
- /**
68
- * Parameters for transferring tokens between accounts
69
- */
70
- export interface TransferParams {
71
- /** Recipient user */
72
- to: NordUser;
73
- /** Token ID to transfer */
74
- tokenId: number;
75
- /** Amount to transfer */
76
- amount: Decimal.Value;
77
- /** Source account ID */
78
- fromAccountId: number;
79
- /** Destination account ID */
80
- toAccountId: number;
81
- }
82
- /**
83
- * Parameters for individual atomic subactions (user-friendly version)
84
- */
85
- export interface UserAtomicSubaction {
86
- /** The type of action to perform. */
87
- kind: "place" | "cancel";
88
- /** The market ID to place the order in. */
89
- marketId?: number;
90
- /** The order ID to cancel. */
91
- orderId?: BigIntValue;
92
- /** Order side (bid or ask) */
93
- side?: Side;
94
- /** Fill mode (limit, market, etc.) */
95
- fillMode?: FillMode;
96
- /** Whether the order is reduce-only. */
97
- isReduceOnly?: boolean;
98
- /** The size of the order. */
99
- size?: Decimal.Value;
100
- /** Order price */
101
- price?: Decimal.Value;
102
- /** Quote size object (for market-style placement) */
103
- quoteSize?: QuoteSize;
104
- /** The client order ID of the order. */
105
- clientOrderId?: BigIntValue;
106
- }
107
- /**
108
- * User class for interacting with the Nord protocol
109
- */
110
- export declare class NordUser extends NordClient {
111
- /** User balances by token symbol */
112
- balances: {
113
- [key: string]: {
114
- accountId: number;
115
- balance: number;
116
- symbol: string;
117
- }[];
118
- };
119
- /** User positions by account ID */
120
- positions: {
121
- [key: string]: {
122
- marketId: number;
123
- openOrders: number;
124
- perp?: {
125
- baseSize: number;
126
- price: number;
127
- updatedFundingRateIndex: number;
128
- fundingPaymentPnl: number;
129
- sizePricePnl: number;
130
- isLong: boolean;
131
- };
132
- actionId: number;
133
- }[];
134
- };
135
- /** User margins by account ID */
136
- margins: {
137
- [key: string]: {
138
- omf: number;
139
- mf: number;
140
- imf: number;
141
- cmf: number;
142
- mmf: number;
143
- pon: number;
144
- pn: number;
145
- bankruptcy: boolean;
146
- };
147
- };
148
- /** User's account IDs */
149
- accountIds?: number[];
150
- /** SPL token information */
151
- splTokenInfos: SPLTokenInfo[];
152
- /**
153
- * Create a new NordUser instance
154
- *
155
- * @param params - Parameters for creating a NordUser
156
- * @throws {NordError} If required parameters are missing
157
- */
158
- constructor({ address, nord, publicKey, sessionPubKey, sessionSignFn, transactionSignFn, walletSignFn, connection, sessionId, }: NordUserParams);
159
- /**
160
- * Create a clone of this NordUser instance
161
- *
162
- * @returns A new NordUser instance with the same properties
163
- */
164
- clone(): NordUser;
165
- /**
166
- * Create a NordUser from a private key
167
- *
168
- * @param nord - Nord instance
169
- * @param privateKey - Private key as string or Uint8Array
170
- * @param connection - Solana connection (optional)
171
- * @returns NordUser instance
172
- * @throws {NordError} If the private key is invalid
173
- */
174
- static fromPrivateKey(nord: Nord, privateKey: string | Uint8Array, connection?: Connection): NordUser;
175
- /**
176
- * Get the associated token account for a token mint
177
- *
178
- * @param mint - Token mint address
179
- * @returns Associated token account address
180
- * @throws {NordError} If required parameters are missing or operation fails
181
- */
182
- getAssociatedTokenAccount(mint: PublicKey): Promise<PublicKey>;
183
- /**
184
- * Deposit SPL tokens to the app
185
- *
186
- * @param amount - Amount to deposit
187
- * @param tokenId - Token ID
188
- * @param recipient - Recipient address; defaults to the user's address
189
- * @returns Transaction signature
190
- * @deprecated Use deposit instead
191
- * @throws {NordError} If required parameters are missing or operation fails
192
- */
193
- depositSpl(amount: number, tokenId: number, recipient?: PublicKey): Promise<string>;
194
- /**
195
- * Deposit SPL tokens to the app
196
- *
197
- * @param amount - Amount to deposit
198
- * @param tokenId - Token ID
199
- * @param recipient - Recipient address; defaults to the user's address
200
- * @param sendOptions - Send options for .sendTransaction
201
- * @returns Transaction signature
202
- * @throws {NordError} If required parameters are missing or operation fails
203
- */
204
- deposit({ amount, tokenId, recipient, sendOptions, }: Readonly<{
205
- amount: number;
206
- tokenId: number;
207
- recipient?: PublicKey;
208
- sendOptions?: SendOptions;
209
- }>): Promise<string>;
210
- /**
211
- * Get a new nonce for actions
212
- *
213
- * @returns Nonce as number
214
- */
215
- getNonce(): number;
216
- private submitSessionAction;
217
- /**
218
- * Update account IDs for this user
219
- *
220
- * @throws {NordError} If the operation fails
221
- */
222
- updateAccountId(): Promise<void>;
223
- /**
224
- * Fetch user information including balances and orders
225
- *
226
- * @throws {NordError} If the operation fails
227
- */
228
- fetchInfo(): Promise<void>;
229
- /**
230
- * Refresh the user's session
231
- *
232
- * @throws {NordError} If the operation fails
233
- */
234
- refreshSession(): Promise<void>;
235
- /**
236
- * Revoke a session
237
- *
238
- * @param sessionId - Session ID to revoke
239
- * @throws {NordError} If the operation fails
240
- */
241
- revokeSession(sessionId: BigIntValue): Promise<void>;
242
- /**
243
- * Checks if the session is valid
244
- * @private
245
- * @throws {NordError} If the session is not valid
246
- */
247
- private checkSessionValidity;
248
- /**
249
- * Withdraw tokens from the exchange
250
- *
251
- * @param tokenId - Token ID to withdraw
252
- * @param amount - Amount to withdraw
253
- * @throws {NordError} If the operation fails
254
- */
255
- withdraw({ amount, tokenId, }: Readonly<{
256
- tokenId: number;
257
- amount: number;
258
- }>): Promise<{
259
- actionId: bigint;
260
- }>;
261
- /**
262
- * Place an order on the exchange
263
- *
264
- * @param params - Order parameters
265
- * @returns Object containing actionId, orderId (if posted), fills, and clientOrderId
266
- * @throws {NordError} If the operation fails
267
- */
268
- placeOrder(params: PlaceOrderParams): Promise<{
269
- actionId: bigint;
270
- orderId?: bigint;
271
- fills: proto.Receipt_Trade[];
272
- }>;
273
- /**
274
- * Cancel an order
275
- *
276
- * @param orderId - Order ID to cancel
277
- * @param providedAccountId - Account ID that placed the order
278
- * @returns Object containing actionId, cancelled orderId, and accountId
279
- * @throws {NordError} If the operation fails
280
- */
281
- cancelOrder(orderId: BigIntValue, providedAccountId?: number): Promise<{
282
- actionId: bigint;
283
- orderId: bigint;
284
- accountId: number;
285
- }>;
286
- /**
287
- * Add a trigger for the current session
288
- *
289
- * @param params - Trigger parameters including market, side, and prices
290
- * @returns Object containing the actionId of the submitted trigger
291
- * @throws {NordError} If the operation fails
292
- */
293
- addTrigger(params: AddTriggerParams): Promise<{
294
- actionId: bigint;
295
- }>;
296
- /**
297
- * Remove a trigger for the current session
298
- *
299
- * @param params - Trigger parameters identifying the trigger to remove
300
- * @returns Object containing the actionId of the removal action
301
- * @throws {NordError} If the operation fails
302
- */
303
- removeTrigger(params: RemoveTriggerParams): Promise<{
304
- actionId: bigint;
305
- }>;
306
- /**
307
- * Transfer tokens to another account
308
- *
309
- * @param params - Transfer parameters
310
- * @throws {NordError} If the operation fails
311
- */
312
- transferToAccount(params: TransferParams): Promise<void>;
313
- /**
314
- * Execute up to four place/cancel operations atomically.
315
- * Per Market:
316
- * 1. cancels can only be in the start (one cannot predict future order ids)
317
- * 2. intermediate trades can trade only
318
- * 3. placements go last
319
- *
320
- * Across Markets, order action can be any
321
- *
322
- * @param userActions array of user-friendly subactions
323
- * @param providedAccountId optional account performing the action (defaults to first account)
324
- */
325
- atomic(userActions: UserAtomicSubaction[], providedAccountId?: number): Promise<{
326
- actionId: bigint;
327
- results: proto.Receipt_AtomicSubactionResultKind[];
328
- }>;
329
- /**
330
- * Helper function to retry a promise with exponential backoff
331
- *
332
- * @param fn - Function to retry
333
- * @param maxRetries - Maximum number of retries
334
- * @param initialDelay - Initial delay in milliseconds
335
- * @returns Promise result
336
- */
337
- private retryWithBackoff;
338
- /**
339
- * Get user's token balances on Solana chain using mintAddr
340
- *
341
- * @param options - Optional parameters
342
- * @param options.includeZeroBalances - Whether to include tokens with zero balance (default: true)
343
- * @param options.includeTokenAccounts - Whether to include token account addresses in the result (default: false)
344
- * @param options.maxConcurrent - Maximum number of concurrent requests (default: 5)
345
- * @param options.maxRetries - Maximum number of retries for rate-limited requests (default: 3)
346
- * @returns Object with token balances and optional token account addresses
347
- * @throws {NordError} If required parameters are missing or operation fails
348
- */
349
- getSolanaBalances(options?: {
350
- includeZeroBalances?: boolean;
351
- includeTokenAccounts?: boolean;
352
- maxConcurrent?: number;
353
- maxRetries?: number;
354
- }): Promise<{
355
- balances: {
356
- [symbol: string]: number;
357
- };
358
- tokenAccounts?: {
359
- [symbol: string]: string;
360
- };
361
- }>;
362
- }