@n1xyz/nord-ts 0.0.18-8121ed05.0 → 0.0.19

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 (77) hide show
  1. package/.claude/settings.local.json +11 -0
  2. package/.local/qa.ts +77 -0
  3. package/.local/test-atomic.ts +112 -0
  4. package/check.sh +4 -0
  5. package/default.nix +47 -0
  6. package/package.json +20 -27
  7. package/src/index.ts +0 -16
  8. package/src/nord/api/actions.ts +131 -9
  9. package/src/nord/api/core.ts +0 -71
  10. package/src/nord/client/Nord.ts +142 -76
  11. package/src/nord/client/NordUser.ts +171 -50
  12. package/src/nord/index.ts +0 -2
  13. package/src/nord/models/Subscriber.ts +2 -2
  14. package/src/types.ts +55 -216
  15. package/src/utils.ts +6 -42
  16. package/src/websocket/NordWebSocketClient.ts +23 -15
  17. package/src/websocket/index.ts +1 -1
  18. package/tests/utils.spec.ts +1 -34
  19. package/dist/bridge/client.d.ts +0 -151
  20. package/dist/bridge/client.js +0 -434
  21. package/dist/bridge/const.d.ts +0 -23
  22. package/dist/bridge/const.js +0 -47
  23. package/dist/bridge/index.d.ts +0 -4
  24. package/dist/bridge/index.js +0 -23
  25. package/dist/bridge/types.d.ts +0 -120
  26. package/dist/bridge/types.js +0 -18
  27. package/dist/bridge/utils.d.ts +0 -64
  28. package/dist/bridge/utils.js +0 -131
  29. package/dist/const.d.ts +0 -8
  30. package/dist/const.js +0 -30
  31. package/dist/gen/common.d.ts +0 -68
  32. package/dist/gen/common.js +0 -215
  33. package/dist/gen/nord.d.ts +0 -853
  34. package/dist/gen/nord.js +0 -6368
  35. package/dist/idl/bridge.d.ts +0 -569
  36. package/dist/idl/bridge.js +0 -8
  37. package/dist/idl/bridge.json +0 -1506
  38. package/dist/idl/index.d.ts +0 -607
  39. package/dist/idl/index.js +0 -8
  40. package/dist/index.d.ts +0 -6
  41. package/dist/index.js +0 -30
  42. package/dist/nord/api/actions.d.ts +0 -106
  43. package/dist/nord/api/actions.js +0 -256
  44. package/dist/nord/api/core.d.ts +0 -49
  45. package/dist/nord/api/core.js +0 -164
  46. package/dist/nord/api/market.d.ts +0 -36
  47. package/dist/nord/api/market.js +0 -96
  48. package/dist/nord/api/metrics.d.ts +0 -67
  49. package/dist/nord/api/metrics.js +0 -229
  50. package/dist/nord/api/queries.d.ts +0 -46
  51. package/dist/nord/api/queries.js +0 -109
  52. package/dist/nord/client/Nord.d.ts +0 -284
  53. package/dist/nord/client/Nord.js +0 -491
  54. package/dist/nord/client/NordUser.d.ts +0 -287
  55. package/dist/nord/client/NordUser.js +0 -595
  56. package/dist/nord/index.d.ts +0 -9
  57. package/dist/nord/index.js +0 -33
  58. package/dist/nord/models/Subscriber.d.ts +0 -37
  59. package/dist/nord/models/Subscriber.js +0 -25
  60. package/dist/nord/utils/NordError.d.ts +0 -35
  61. package/dist/nord/utils/NordError.js +0 -49
  62. package/dist/types.d.ts +0 -407
  63. package/dist/types.js +0 -103
  64. package/dist/utils.d.ts +0 -116
  65. package/dist/utils.js +0 -271
  66. package/dist/websocket/NordWebSocketClient.d.ts +0 -68
  67. package/dist/websocket/NordWebSocketClient.js +0 -338
  68. package/dist/websocket/events.d.ts +0 -19
  69. package/dist/websocket/events.js +0 -2
  70. package/dist/websocket/index.d.ts +0 -2
  71. package/dist/websocket/index.js +0 -5
  72. package/jest.config.ts +0 -9
  73. package/nodemon.json +0 -4
  74. package/protoc-generate.sh +0 -23
  75. package/src/idl/bridge.json +0 -1506
  76. package/src/nord/api/market.ts +0 -122
  77. package/src/nord/api/queries.ts +0 -135
@@ -1,287 +0,0 @@
1
- import { Connection, PublicKey } from "@solana/web3.js";
2
- import Decimal from "decimal.js";
3
- import { SPLTokenInfo } from "@n1xyz/proton";
4
- import { FillMode, Order, Side } from "../../types";
5
- import { BigIntValue } from "../../utils";
6
- import { Nord } from "./Nord";
7
- /**
8
- * Parameters for creating a NordUser instance
9
- */
10
- export interface NordUserParams {
11
- /** Nord client instance */
12
- nord: Nord;
13
- /** User's blockchain address */
14
- address: string;
15
- /** Function to sign messages with the user's wallet */
16
- walletSignFn: (message: Uint8Array | string) => Promise<Uint8Array>;
17
- /** Function to sign messages with the user's session key */
18
- sessionSignFn: (message: Uint8Array) => Promise<Uint8Array>;
19
- /** Function to sign transactions with the user's wallet (optional) */
20
- transactionSignFn: (transaction: any) => Promise<any>;
21
- /** Solana connection (optional) */
22
- connection?: Connection;
23
- /** Session ID (optional) */
24
- sessionId?: bigint;
25
- /** Session public key (required) */
26
- sessionPubKey: Uint8Array;
27
- /** Session public key (required) */
28
- publicKey: PublicKey;
29
- }
30
- /**
31
- * Parameters for placing an order
32
- */
33
- export interface PlaceOrderParams {
34
- /** Market ID */
35
- marketId: number;
36
- /** Order side (bid or ask) */
37
- side: Side;
38
- /** Fill mode (limit, market, etc.) */
39
- fillMode: FillMode;
40
- /** Whether the order is reduce-only */
41
- isReduceOnly: boolean;
42
- /** Order size */
43
- size?: Decimal.Value;
44
- /** Order price */
45
- price?: Decimal.Value;
46
- /** Quote size (for market orders) */
47
- quoteSize?: Decimal.Value;
48
- /** Account ID to place the order from */
49
- accountId?: number;
50
- }
51
- /**
52
- * Parameters for transferring tokens between accounts
53
- */
54
- export interface TransferParams {
55
- /** Recipient user */
56
- to: NordUser;
57
- /** Token ID to transfer */
58
- tokenId: number;
59
- /** Amount to transfer */
60
- amount: Decimal.Value;
61
- /** Source account ID */
62
- fromAccountId: number;
63
- /** Destination account ID */
64
- toAccountId: number;
65
- }
66
- /**
67
- * User class for interacting with the Nord protocol
68
- */
69
- export declare class NordUser {
70
- /** Nord client instance */
71
- readonly nord: Nord;
72
- /** User's blockchain address */
73
- readonly address: PublicKey;
74
- /** Function to sign messages with the user's wallet */
75
- readonly walletSignFn: (message: Uint8Array | string) => Promise<Uint8Array>;
76
- /** Function to sign messages with the user's session key */
77
- readonly sessionSignFn: (message: Uint8Array) => Promise<Uint8Array>;
78
- /** Function to sign transactions with the user's wallet */
79
- readonly transactionSignFn: (transaction: any) => Promise<any>;
80
- /** User balances by token symbol */
81
- balances: {
82
- [key: string]: {
83
- accountId: number;
84
- balance: number;
85
- symbol: string;
86
- }[];
87
- };
88
- /** User orders by market symbol */
89
- orders: {
90
- [key: string]: Order[];
91
- };
92
- /** User positions by account ID */
93
- positions: {
94
- [key: string]: {
95
- marketId: number;
96
- openOrders: number;
97
- perp?: {
98
- baseSize: number;
99
- price: number;
100
- updatedFundingRateIndex: number;
101
- fundingPaymentPnl: number;
102
- sizePricePnl: number;
103
- isLong: boolean;
104
- };
105
- actionId: number;
106
- }[];
107
- };
108
- /** User margins by account ID */
109
- margins: {
110
- [key: string]: {
111
- omf: number;
112
- mf: number;
113
- imf: number;
114
- cmf: number;
115
- mmf: number;
116
- pon: number;
117
- pn: number;
118
- bankruptcy: boolean;
119
- };
120
- };
121
- /** User's account IDs */
122
- accountIds?: number[];
123
- /** Current session ID */
124
- sessionId?: bigint;
125
- /** User's public key */
126
- publicKey: PublicKey;
127
- /** Session public key */
128
- sessionPubKey: Uint8Array;
129
- /** Last timestamp used */
130
- lastTs: number;
131
- /** Last nonce used */
132
- lastNonce: number;
133
- /** Solana connection */
134
- connection: Connection;
135
- /** SPL token information */
136
- splTokenInfos: SPLTokenInfo[];
137
- /**
138
- * Create a new NordUser instance
139
- *
140
- * @param params - Parameters for creating a NordUser
141
- * @throws {NordError} If required parameters are missing
142
- */
143
- constructor({ address, nord, publicKey, sessionPubKey, sessionSignFn, transactionSignFn, walletSignFn, connection, sessionId, }: NordUserParams);
144
- /**
145
- * Create a clone of this NordUser instance
146
- *
147
- * @returns A new NordUser instance with the same properties
148
- */
149
- clone(): NordUser;
150
- /**
151
- * Create a NordUser from a private key
152
- *
153
- * @param nord - Nord instance
154
- * @param privateKey - Private key as string or Uint8Array
155
- * @param connection - Solana connection (optional)
156
- * @returns NordUser instance
157
- * @throws {NordError} If the private key is invalid
158
- */
159
- static fromPrivateKey(nord: Nord, privateKey: string | Uint8Array, connection?: Connection): NordUser;
160
- /**
161
- * Get the associated token account for a token mint
162
- *
163
- * @param mint - Token mint address
164
- * @returns Associated token account address
165
- * @throws {NordError} If required parameters are missing or operation fails
166
- */
167
- getAssociatedTokenAccount(mint: PublicKey): Promise<PublicKey>;
168
- /**
169
- * Deposit SPL tokens to the bridge
170
- *
171
- * @param amount - Amount to deposit
172
- * @param tokenId - Token ID
173
- * @returns Transaction signature
174
- * @throws {NordError} If required parameters are missing or operation fails
175
- */
176
- depositSpl(amount: number, tokenId: number): Promise<string>;
177
- /**
178
- * Get a new nonce for actions
179
- *
180
- * @returns Nonce as number
181
- */
182
- getNonce(): number;
183
- /**
184
- * Update account IDs for this user
185
- *
186
- * @throws {NordError} If the operation fails
187
- */
188
- updateAccountId(): Promise<void>;
189
- /**
190
- * Fetch user information including balances and orders
191
- *
192
- * @throws {NordError} If the operation fails
193
- */
194
- fetchInfo(): Promise<void>;
195
- /**
196
- * Refresh the user's session
197
- *
198
- * @throws {NordError} If the operation fails
199
- */
200
- refreshSession(): Promise<void>;
201
- /**
202
- * Revoke a session
203
- *
204
- * @param sessionId - Session ID to revoke
205
- * @throws {NordError} If the operation fails
206
- */
207
- revokeSession(sessionId: BigIntValue): Promise<void>;
208
- /**
209
- * Checks if the session is valid
210
- * @private
211
- * @throws {NordError} If the session is not valid
212
- */
213
- private checkSessionValidity;
214
- /**
215
- * Withdraw tokens from the exchange
216
- *
217
- * @param tokenId - Token ID to withdraw
218
- * @param amount - Amount to withdraw
219
- * @throws {NordError} If the operation fails
220
- */
221
- withdraw(tokenId: number, amount: number): Promise<{
222
- actionId: bigint;
223
- }>;
224
- /**
225
- * Place an order on the exchange
226
- *
227
- * @param params - Order parameters
228
- * @returns Order ID if successful
229
- * @throws {NordError} If the operation fails
230
- */
231
- placeOrder(params: PlaceOrderParams): Promise<bigint | undefined>;
232
- /**
233
- * Cancel an order
234
- *
235
- * @param orderId - Order ID to cancel
236
- * @param providedAccountId - Account ID that placed the order
237
- * @returns Action ID if successful
238
- * @throws {NordError} If the operation fails
239
- */
240
- cancelOrder(orderId: BigIntValue, providedAccountId?: number): Promise<bigint>;
241
- /**
242
- * Transfer tokens to another account
243
- *
244
- * @param params - Transfer parameters
245
- * @throws {NordError} If the operation fails
246
- */
247
- transferToAccount(params: TransferParams): Promise<void>;
248
- /**
249
- * Helper function to retry a promise with exponential backoff
250
- *
251
- * @param fn - Function to retry
252
- * @param maxRetries - Maximum number of retries
253
- * @param initialDelay - Initial delay in milliseconds
254
- * @returns Promise result
255
- */
256
- private retryWithBackoff;
257
- /**
258
- * Get user's token balances on Solana chain using mintAddr
259
- *
260
- * @param options - Optional parameters
261
- * @param options.includeZeroBalances - Whether to include tokens with zero balance (default: true)
262
- * @param options.includeTokenAccounts - Whether to include token account addresses in the result (default: false)
263
- * @param options.maxConcurrent - Maximum number of concurrent requests (default: 5)
264
- * @param options.maxRetries - Maximum number of retries for rate-limited requests (default: 3)
265
- * @returns Object with token balances and optional token account addresses
266
- * @throws {NordError} If required parameters are missing or operation fails
267
- */
268
- getSolanaBalances(options?: {
269
- includeZeroBalances?: boolean;
270
- includeTokenAccounts?: boolean;
271
- maxConcurrent?: number;
272
- maxRetries?: number;
273
- }): Promise<{
274
- balances: {
275
- [symbol: string]: number;
276
- };
277
- tokenAccounts?: {
278
- [symbol: string]: string;
279
- };
280
- }>;
281
- /**
282
- * Get the Solana public key derived from the address
283
- *
284
- * @returns The Solana public key
285
- */
286
- getSolanaPublicKey(): PublicKey;
287
- }