@n1xyz/nord-ts 0.0.4 → 0.0.5

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 (306) hide show
  1. package/dist/bridge/client.d.ts +4 -4
  2. package/dist/bridge/client.js +4 -4
  3. package/dist/bridge/const.d.ts +2 -2
  4. package/dist/bridge/const.js +22 -22
  5. package/dist/bridge/index.d.ts +4 -4
  6. package/dist/bridge/types.d.ts +3 -3
  7. package/dist/bridge/utils.d.ts +4 -4
  8. package/dist/bridge/utils.js +10 -10
  9. package/dist/const.d.ts +1 -1
  10. package/dist/const.js +17 -17
  11. package/dist/gen/nord.d.ts +1 -4
  12. package/dist/idl/bridge.d.ts +1 -1
  13. package/dist/idl/bridge.js +185 -185
  14. package/dist/index.d.ts +8 -8
  15. package/dist/nord/api/actions.d.ts +3 -3
  16. package/dist/nord/api/actions.js +21 -21
  17. package/dist/nord/api/core.d.ts +3 -3
  18. package/dist/nord/api/core.js +12 -12
  19. package/dist/nord/api/market.d.ts +1 -1
  20. package/dist/nord/api/market.js +12 -12
  21. package/dist/nord/api/metrics.d.ts +1 -1
  22. package/dist/nord/api/metrics.js +6 -6
  23. package/dist/nord/api/queries.d.ts +1 -1
  24. package/dist/nord/api/queries.js +9 -9
  25. package/dist/nord/client/Nord.d.ts +4 -4
  26. package/dist/nord/client/Nord.js +18 -18
  27. package/dist/nord/client/NordUser.d.ts +7 -7
  28. package/dist/nord/client/NordUser.js +45 -49
  29. package/dist/nord/index.d.ts +9 -9
  30. package/dist/nord/models/Subscriber.d.ts +6 -6
  31. package/dist/nord/models/Subscriber.js +1 -5
  32. package/dist/nord/utils/NordError.js +2 -2
  33. package/dist/types.d.ts +1 -1
  34. package/dist/types.js +1 -1
  35. package/dist/utils.d.ts +6 -6
  36. package/dist/utils.js +8 -8
  37. package/dist/websocket/NordWebSocketClient.d.ts +2 -2
  38. package/dist/websocket/NordWebSocketClient.js +38 -38
  39. package/dist/websocket/events.d.ts +1 -1
  40. package/dist/websocket/index.d.ts +2 -2
  41. package/docs/assets/hierarchy.js +1 -0
  42. package/docs/assets/highlight.css +16 -16
  43. package/docs/assets/icons.js +17 -14
  44. package/docs/assets/icons.svg +1 -1
  45. package/docs/assets/main.js +5 -4
  46. package/docs/assets/navigation.js +1 -1
  47. package/docs/assets/search.js +1 -1
  48. package/docs/assets/style.css +1423 -1227
  49. package/docs/classes/Nord.html +190 -31
  50. package/docs/classes/NordError.html +24 -0
  51. package/docs/classes/NordUser.html +120 -35
  52. package/docs/classes/NordWebSocketClient.html +335 -0
  53. package/docs/classes/SolanaBridgeClient.html +86 -0
  54. package/docs/classes/Subscriber.html +10 -0
  55. package/docs/enums/FillMode.html +5 -5
  56. package/docs/enums/KeyType.html +4 -4
  57. package/docs/enums/MetricPeriod.html +9 -0
  58. package/docs/enums/PdaSeedType.html +9 -0
  59. package/docs/enums/PeakTpsPeriodUnit.html +7 -7
  60. package/docs/enums/Side.html +3 -3
  61. package/docs/enums/WebSocketMessageType.html +7 -0
  62. package/docs/functions/actionQueryRollman.html +6 -0
  63. package/docs/functions/actionsQueryRollman.html +6 -0
  64. package/docs/functions/aggregateMetrics-1.html +7 -0
  65. package/docs/functions/assert.html +1 -1
  66. package/docs/functions/bigIntToProtoU128.html +3 -3
  67. package/docs/functions/blockQueryRollman.html +6 -0
  68. package/docs/functions/blockSummaryQueryRollman.html +6 -0
  69. package/docs/functions/bridgeToBN.html +5 -0
  70. package/docs/functions/bufferToHex.html +4 -0
  71. package/docs/functions/cancelOrder.html +1 -0
  72. package/docs/functions/checkPubKeyLength.html +1 -1
  73. package/docs/functions/checkedFetch.html +4 -4
  74. package/docs/functions/createSession.html +1 -0
  75. package/docs/functions/decodeLengthDelimited.html +7 -6
  76. package/docs/functions/encodeLengthDelimited.html +4 -4
  77. package/docs/functions/fillModeToProtoFillMode.html +4 -4
  78. package/docs/functions/findMarket.html +1 -1
  79. package/docs/functions/findPda.html +6 -0
  80. package/docs/functions/findToken.html +1 -1
  81. package/docs/functions/fromBN.html +5 -0
  82. package/docs/functions/getAccount.html +6 -0
  83. package/docs/functions/getActionNonce.html +5 -0
  84. package/docs/functions/getCurrentTps.html +6 -0
  85. package/docs/functions/getInfo.html +5 -0
  86. package/docs/functions/getMedianLatency.html +6 -0
  87. package/docs/functions/getOrderbook.html +6 -0
  88. package/docs/functions/getPeakTps.html +6 -0
  89. package/docs/functions/getTimestamp.html +5 -0
  90. package/docs/functions/getTotalTransactions.html +5 -0
  91. package/docs/functions/getTrades.html +6 -0
  92. package/docs/functions/getUserAccountIds.html +6 -0
  93. package/docs/functions/hexToBuffer.html +4 -0
  94. package/docs/functions/initWebSocketClient.html +12 -0
  95. package/docs/functions/keypairFromPrivateKey.html +4 -0
  96. package/docs/functions/makeSigningFunction.html +4 -0
  97. package/docs/functions/makeWalletSignFn.html +5 -5
  98. package/docs/functions/marketsStats.html +5 -0
  99. package/docs/functions/optExpect.html +4 -4
  100. package/docs/functions/optMap.html +5 -5
  101. package/docs/functions/optUnwrap.html +2 -2
  102. package/docs/functions/panic.html +1 -1
  103. package/docs/functions/placeOrder.html +1 -0
  104. package/docs/functions/queryAction.html +6 -0
  105. package/docs/functions/queryBlock.html +6 -0
  106. package/docs/functions/queryLastNBlocks.html +5 -0
  107. package/docs/functions/queryPrometheus.html +6 -0
  108. package/docs/functions/queryRecentActions.html +6 -0
  109. package/docs/functions/queryRecentBlocks.html +6 -0
  110. package/docs/functions/revokeSession.html +1 -0
  111. package/docs/functions/shortenPublicKey.html +5 -0
  112. package/docs/functions/signAction.html +2 -2
  113. package/docs/functions/toBN.html +5 -0
  114. package/docs/functions/toScaledU128.html +5 -5
  115. package/docs/functions/toScaledU64.html +5 -5
  116. package/docs/functions/transfer.html +1 -0
  117. package/docs/functions/withdraw.html +1 -0
  118. package/docs/hierarchy.html +1 -0
  119. package/docs/index.html +39 -20
  120. package/docs/interfaces/Account.html +8 -8
  121. package/docs/interfaces/ActionInfo.html +8 -8
  122. package/docs/interfaces/ActionNonceResponse.html +3 -0
  123. package/docs/interfaces/ActionQuery.html +4 -4
  124. package/docs/interfaces/ActionResponse.html +8 -8
  125. package/docs/interfaces/ActionsExtendedInfo.html +10 -10
  126. package/docs/interfaces/ActionsQuery.html +5 -5
  127. package/docs/interfaces/ActionsResponse.html +6 -6
  128. package/docs/interfaces/AggregateMetrics.html +12 -12
  129. package/docs/interfaces/BlockFacts.html +10 -0
  130. package/docs/interfaces/BlockQuery.html +6 -6
  131. package/docs/interfaces/BlockResponse.html +6 -6
  132. package/docs/interfaces/BlockSummary.html +8 -8
  133. package/docs/interfaces/BlockSummaryResponse.html +6 -6
  134. package/docs/interfaces/DeltaEvent.html +6 -6
  135. package/docs/interfaces/DepositSplParams.html +10 -0
  136. package/docs/interfaces/Info.html +3 -3
  137. package/docs/interfaces/Market.html +8 -6
  138. package/docs/interfaces/MarketStats.html +7 -7
  139. package/docs/interfaces/MarketsStatsResponse.html +2 -2
  140. package/docs/interfaces/NordConfig.html +14 -5
  141. package/docs/interfaces/NordWebSocketClientEvents.html +4 -0
  142. package/docs/interfaces/NordWebSocketEvents.html +8 -0
  143. package/docs/interfaces/Order.html +6 -6
  144. package/docs/interfaces/OrderInfo.html +6 -6
  145. package/docs/interfaces/OrderbookEntry.html +4 -0
  146. package/docs/interfaces/OrderbookQuery.html +6 -0
  147. package/docs/interfaces/OrderbookResponse.html +6 -0
  148. package/docs/interfaces/OrderbookSubscription.html +159 -0
  149. package/docs/interfaces/PerpMarketStats.html +5 -5
  150. package/docs/interfaces/RollmanActionExtendedInfo.html +4 -4
  151. package/docs/interfaces/RollmanActionInfo.html +4 -4
  152. package/docs/interfaces/RollmanActionResponse.html +4 -4
  153. package/docs/interfaces/RollmanActionsResponse.html +2 -2
  154. package/docs/interfaces/RollmanBlockResponse.html +3 -3
  155. package/docs/interfaces/SPLTokenInfo.html +10 -0
  156. package/docs/interfaces/SolanaBridgeConfig.html +10 -0
  157. package/docs/interfaces/StateFacts.html +10 -0
  158. package/docs/interfaces/SubscriberConfig.html +3 -3
  159. package/docs/interfaces/TimestampResponse.html +3 -0
  160. package/docs/interfaces/Token.html +5 -5
  161. package/docs/interfaces/TokenInfo.html +5 -0
  162. package/docs/interfaces/Trade.html +5 -5
  163. package/docs/interfaces/TradeSubscription.html +159 -0
  164. package/docs/interfaces/Trades.html +5 -5
  165. package/docs/interfaces/TradesQuery.html +6 -0
  166. package/docs/interfaces/TradesResponse.html +7 -0
  167. package/docs/interfaces/TransferParams.html +8 -0
  168. package/docs/interfaces/UserAccountIdsQuery.html +3 -0
  169. package/docs/interfaces/UserAccountIdsResponse.html +3 -0
  170. package/docs/interfaces/WebSocketDeltaUpdate.html +9 -0
  171. package/docs/interfaces/WebSocketSubscription.html +4 -0
  172. package/docs/interfaces/WebSocketTradeUpdate.html +6 -0
  173. package/docs/interfaces/WebSocketUserUpdate.html +6 -0
  174. package/docs/interfaces/WithdrawalClaim.html +14 -0
  175. package/docs/interfaces/WithdrawalParams.html +8 -0
  176. package/docs/modules.html +1 -70
  177. package/docs/types/BigIntValue.html +2 -2
  178. package/docs/types/WebSocketMessage.html +1 -0
  179. package/docs/variables/DEBUG_KEYS.html +1 -1
  180. package/docs/variables/DEFAULT_FUNDING_AMOUNTS.html +1 -1
  181. package/docs/variables/DEV_TOKEN_INFOS.html +1 -1
  182. package/docs/variables/DEV_URL.html +1 -1
  183. package/docs/variables/MAX_BUFFER_LEN.html +1 -1
  184. package/docs/variables/SESSION_TTL.html +1 -1
  185. package/docs/variables/WEBSERVER_DEV_URL.html +1 -1
  186. package/docs/variables/ZERO_DECIMAL.html +1 -1
  187. package/docs/variables/_private.html +2 -0
  188. package/eslint.config.mjs +66 -0
  189. package/package.json +12 -13
  190. package/src/bridge/client.ts +10 -10
  191. package/src/bridge/const.ts +24 -24
  192. package/src/bridge/index.ts +4 -4
  193. package/src/bridge/types.ts +10 -10
  194. package/src/bridge/utils.ts +14 -14
  195. package/src/const.ts +18 -18
  196. package/src/gen/nord.ts +1 -4
  197. package/src/idl/bridge.ts +186 -186
  198. package/src/index.ts +8 -8
  199. package/src/nord/api/actions.ts +25 -25
  200. package/src/nord/api/core.ts +16 -16
  201. package/src/nord/api/market.ts +15 -15
  202. package/src/nord/api/metrics.ts +16 -16
  203. package/src/nord/api/queries.ts +12 -12
  204. package/src/nord/client/Nord.ts +27 -27
  205. package/src/nord/client/NordUser.ts +59 -63
  206. package/src/nord/index.ts +9 -9
  207. package/src/nord/models/Subscriber.ts +11 -12
  208. package/src/nord/utils/NordError.ts +2 -2
  209. package/src/types.ts +12 -12
  210. package/src/utils.ts +20 -20
  211. package/src/websocket/NordWebSocketClient.ts +42 -42
  212. package/src/websocket/events.ts +1 -1
  213. package/src/websocket/index.ts +2 -2
  214. package/tests/utils.spec.ts +24 -24
  215. package/tsconfig.eslint.json +12 -0
  216. package/.eslintignore +0 -1
  217. package/.eslintrc.js +0 -31
  218. package/dist/abis/ERC20_ABI.d.ts +0 -39
  219. package/dist/abis/ERC20_ABI.js +0 -313
  220. package/dist/abis/NORD_GETTERS_FACET_ABI.d.ts +0 -34
  221. package/dist/abis/NORD_GETTERS_FACET_ABI.js +0 -195
  222. package/dist/abis/NORD_RAMP_FACET_ABI.d.ts +0 -35
  223. package/dist/abis/NORD_RAMP_FACET_ABI.js +0 -144
  224. package/dist/abis/index.d.ts +0 -3
  225. package/dist/abis/index.js +0 -9
  226. package/dist/bridge/NordUser.d.ts +0 -78
  227. package/dist/bridge/NordUser.js +0 -196
  228. package/dist/client.d.ts +0 -70
  229. package/dist/client.js +0 -129
  230. package/dist/constants/endpoints.d.ts +0 -65
  231. package/dist/constants/endpoints.js +0 -68
  232. package/dist/models/account.d.ts +0 -58
  233. package/dist/models/account.js +0 -6
  234. package/dist/models/index.d.ts +0 -8
  235. package/dist/models/index.js +0 -28
  236. package/dist/models/market.d.ts +0 -137
  237. package/dist/models/market.js +0 -6
  238. package/dist/models/order.d.ts +0 -211
  239. package/dist/models/order.js +0 -6
  240. package/dist/models/token.d.ts +0 -50
  241. package/dist/models/token.js +0 -6
  242. package/dist/nord/Nord.d.ts +0 -249
  243. package/dist/nord/Nord.js +0 -388
  244. package/dist/nord/NordError.d.ts +0 -23
  245. package/dist/nord/NordError.js +0 -48
  246. package/dist/nord/NordImpl.d.ts +0 -11
  247. package/dist/nord/NordImpl.js +0 -26
  248. package/dist/nord/NordUser.d.ts +0 -243
  249. package/dist/nord/NordUser.js +0 -481
  250. package/dist/nord/Subscriber.d.ts +0 -37
  251. package/dist/nord/Subscriber.js +0 -29
  252. package/dist/nord/actions.d.ts +0 -101
  253. package/dist/nord/actions.js +0 -254
  254. package/dist/nord/api/index.d.ts +0 -1
  255. package/dist/nord/api/index.js +0 -17
  256. package/dist/nord/api/orderFunctions.d.ts +0 -168
  257. package/dist/nord/api/orderFunctions.js +0 -133
  258. package/dist/nord/core.d.ts +0 -48
  259. package/dist/nord/core.js +0 -97
  260. package/dist/nord/market.d.ts +0 -36
  261. package/dist/nord/market.js +0 -90
  262. package/dist/nord/metrics.d.ts +0 -67
  263. package/dist/nord/metrics.js +0 -124
  264. package/dist/nord/queries.d.ts +0 -81
  265. package/dist/nord/queries.js +0 -181
  266. package/dist/nord/types.d.ts +0 -88
  267. package/dist/nord/types.js +0 -2
  268. package/dist/nord/websocket.d.ts +0 -49
  269. package/dist/nord/websocket.js +0 -107
  270. package/dist/operations/account.d.ts +0 -58
  271. package/dist/operations/account.js +0 -112
  272. package/dist/operations/market.d.ts +0 -65
  273. package/dist/operations/market.js +0 -131
  274. package/dist/operations/orders.d.ts +0 -57
  275. package/dist/operations/orders.js +0 -129
  276. package/dist/solana/NordUser.d.ts +0 -78
  277. package/dist/solana/NordUser.js +0 -196
  278. package/dist/solana/client.d.ts +0 -139
  279. package/dist/solana/client.js +0 -360
  280. package/dist/solana/const.d.ts +0 -23
  281. package/dist/solana/const.js +0 -47
  282. package/dist/solana/index.d.ts +0 -5
  283. package/dist/solana/index.js +0 -23
  284. package/dist/solana/types.d.ts +0 -118
  285. package/dist/solana/types.js +0 -16
  286. package/dist/solana/utils.d.ts +0 -64
  287. package/dist/solana/utils.js +0 -131
  288. package/dist/types/api.d.ts +0 -152
  289. package/dist/types/api.js +0 -6
  290. package/dist/types/config.d.ts +0 -34
  291. package/dist/types/config.js +0 -6
  292. package/dist/utils/errors.d.ts +0 -96
  293. package/dist/utils/errors.js +0 -132
  294. package/dist/utils/http.d.ts +0 -35
  295. package/dist/utils/http.js +0 -105
  296. package/dist/websocket/client.d.ts +0 -93
  297. package/dist/websocket/client.js +0 -222
  298. package/dist/websocket.d.ts +0 -55
  299. package/dist/websocket.js +0 -211
  300. package/docs/interfaces/ERC20TokenInfo.html +0 -5
  301. package/docs/variables/DEV_CONTRACT_ADDRESS.html +0 -1
  302. package/docs/variables/ERC20_ABI.html +0 -1
  303. package/docs/variables/EVM_DEV_URL.html +0 -1
  304. package/docs/variables/FAUCET_PRIVATE_ADDRESS.html +0 -1
  305. package/docs/variables/NORD_GETTERS_FACET_ABI.html +0 -1
  306. package/docs/variables/NORD_RAMP_FACET_ABI.html +0 -1
@@ -1,129 +0,0 @@
1
- "use strict";
2
- /**
3
- * Order-related operations
4
- * @module operations/orders
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.OrderOperations = void 0;
8
- const errors_1 = require("../utils/errors");
9
- const http_1 = require("../utils/http");
10
- const endpoints_1 = require("../constants/endpoints");
11
- /**
12
- * Order operations implementation
13
- */
14
- class OrderOperations {
15
- /**
16
- * Create a new OrderOperations instance
17
- *
18
- * @param config - Client configuration
19
- */
20
- constructor(config) {
21
- this.config = config;
22
- }
23
- /**
24
- * Place a new order
25
- *
26
- * @param params - Order parameters
27
- * @returns Promise resolving to order result
28
- * @throws {NordValidationError} If any parameters are invalid
29
- * @throws {NordApiError} If the API request fails
30
- */
31
- async placeOrder(params) {
32
- // Validate required parameters
33
- if (!params.market) {
34
- throw new errors_1.NordValidationError('Market symbol is required', 'market');
35
- }
36
- if (!params.side) {
37
- throw new errors_1.NordValidationError('Order side is required', 'side');
38
- }
39
- if (params.size === undefined || params.size <= 0) {
40
- throw new errors_1.NordValidationError('Order size must be greater than zero', 'size');
41
- }
42
- // Type-specific validation
43
- if (params.type === 'limit' && (params.price === undefined || params.price <= 0)) {
44
- throw new errors_1.NordValidationError('Limit price must be greater than zero', 'price');
45
- }
46
- if (params.type === 'stop' && (params.stopPrice === undefined || params.stopPrice <= 0)) {
47
- throw new errors_1.NordValidationError('Stop price must be greater than zero', 'stopPrice');
48
- }
49
- if (params.type === 'stopLimit') {
50
- if (params.stopPrice === undefined || params.stopPrice <= 0) {
51
- throw new errors_1.NordValidationError('Stop price must be greater than zero', 'stopPrice');
52
- }
53
- if (params.limitPrice === undefined || params.limitPrice <= 0) {
54
- throw new errors_1.NordValidationError('Limit price must be greater than zero', 'limitPrice');
55
- }
56
- }
57
- try {
58
- const response = await (0, http_1.httpPost)(this.config.webServerUrl, endpoints_1.ENDPOINTS.PLACE_ORDER, params);
59
- return response;
60
- }
61
- catch (error) {
62
- throw new errors_1.NordApiError(`Failed to place order for market ${params.market}`, error instanceof errors_1.NordApiError ? error.statusCode : 500, endpoints_1.ENDPOINTS.PLACE_ORDER, error instanceof Error ? error : undefined);
63
- }
64
- }
65
- /**
66
- * Cancel an existing order
67
- *
68
- * @param orderId - Order ID to cancel
69
- * @returns Promise resolving to true if successful
70
- * @throws {NordValidationError} If the orderId parameter is invalid
71
- * @throws {NordApiError} If the API request fails
72
- */
73
- async cancelOrder(orderId) {
74
- if (orderId === undefined || orderId === null) {
75
- throw new errors_1.NordValidationError('Order ID is required', 'orderId');
76
- }
77
- try {
78
- const endpoint = `${endpoints_1.ENDPOINTS.CANCEL_ORDER}/${orderId}`;
79
- await (0, http_1.httpDelete)(this.config.webServerUrl, endpoint);
80
- return true;
81
- }
82
- catch (error) {
83
- throw new errors_1.NordApiError(`Failed to cancel order ${orderId}`, error instanceof errors_1.NordApiError ? error.statusCode : 500, endpoints_1.ENDPOINTS.CANCEL_ORDER, error instanceof Error ? error : undefined);
84
- }
85
- }
86
- /**
87
- * Get information about a specific order
88
- *
89
- * @param orderId - Order ID
90
- * @returns Promise resolving to order information
91
- * @throws {NordValidationError} If the orderId parameter is invalid
92
- * @throws {NordApiError} If the API request fails
93
- */
94
- async getOrder(orderId) {
95
- if (orderId === undefined || orderId === null) {
96
- throw new errors_1.NordValidationError('Order ID is required', 'orderId');
97
- }
98
- try {
99
- const endpoint = `${endpoints_1.ENDPOINTS.ORDER}/${orderId}`;
100
- const response = await (0, http_1.httpGet)(this.config.webServerUrl, endpoint);
101
- return response;
102
- }
103
- catch (error) {
104
- throw new errors_1.NordApiError(`Failed to fetch order ${orderId}`, error instanceof errors_1.NordApiError ? error.statusCode : 500, endpoints_1.ENDPOINTS.ORDER, error instanceof Error ? error : undefined);
105
- }
106
- }
107
- /**
108
- * Get all orders for an account
109
- *
110
- * @param accountId - Account ID
111
- * @returns Promise resolving to an array of orders
112
- * @throws {NordValidationError} If the accountId parameter is invalid
113
- * @throws {NordApiError} If the API request fails
114
- */
115
- async getOrders(accountId) {
116
- if (accountId === undefined || accountId === null) {
117
- throw new errors_1.NordValidationError('Account ID is required', 'accountId');
118
- }
119
- try {
120
- const endpoint = `${endpoints_1.ENDPOINTS.ORDERS}?accountId=${accountId}`;
121
- const response = await (0, http_1.httpGet)(this.config.webServerUrl, endpoint);
122
- return response;
123
- }
124
- catch (error) {
125
- throw new errors_1.NordApiError(`Failed to fetch orders for account ${accountId}`, error instanceof errors_1.NordApiError ? error.statusCode : 500, endpoints_1.ENDPOINTS.ORDERS, error instanceof Error ? error : undefined);
126
- }
127
- }
128
- }
129
- exports.OrderOperations = OrderOperations;
@@ -1,78 +0,0 @@
1
- import { Connection, Keypair, PublicKey } from '@solana/web3.js';
2
- import { Nord } from '../nord/Nord';
3
- import { Order } from '../types';
4
- import { SolanaBridgeClient } from './client';
5
- import { SPLTokenInfo } from './types';
6
- export declare class NordUser {
7
- nord: Nord;
8
- publicKey: PublicKey;
9
- walletSignFn: (message: Uint8Array | string) => Promise<Uint8Array>;
10
- sessionSignFn: (message: Uint8Array) => Promise<Uint8Array>;
11
- balances: {
12
- [key: string]: {
13
- accountId: number;
14
- balance: number;
15
- symbol: string;
16
- }[];
17
- };
18
- orders: {
19
- [key: string]: Order[];
20
- };
21
- accountIds?: number[];
22
- sessionId?: bigint;
23
- keypair?: Keypair;
24
- bridgeClient?: SolanaBridgeClient;
25
- connection?: Connection;
26
- splTokenInfos: SPLTokenInfo[];
27
- lastTs: number;
28
- lastNonce: number;
29
- constructor(params: {
30
- nord: Nord;
31
- publicKey: PublicKey | string;
32
- walletSignFn: (message: Uint8Array | string) => Promise<Uint8Array>;
33
- sessionSignFn: (message: Uint8Array) => Promise<Uint8Array>;
34
- keypair?: Keypair;
35
- connection?: Connection;
36
- });
37
- /**
38
- * Initialize the Solana bridge client
39
- */
40
- private initBridgeClient;
41
- /**
42
- * Create a NordUser from a private key
43
- *
44
- * @param nord Nord instance
45
- * @param privateKey Private key as string or Uint8Array
46
- * @param connection Solana connection
47
- * @returns NordUser instance
48
- */
49
- static fromPrivateKey(nord: Nord, privateKey: string | Uint8Array, connection?: Connection): NordUser;
50
- /**
51
- * Get the associated token account for a token mint
52
- *
53
- * @param mint Token mint address
54
- * @returns Associated token account address
55
- */
56
- getAssociatedTokenAccount(mint: PublicKey): Promise<PublicKey>;
57
- /**
58
- * Deposit SPL tokens to the bridge
59
- *
60
- * @param amount Amount to deposit
61
- * @param tokenId Token ID
62
- * @returns Transaction signature
63
- */
64
- depositSpl(amount: number, tokenId: number): Promise<string>;
65
- /**
66
- * Withdraw tokens from the bridge
67
- *
68
- * @param claim Withdrawal claim
69
- * @returns Transaction signature
70
- */
71
- withdrawSpl(claim: any): Promise<string>;
72
- /**
73
- * Fund the user's SPL token accounts for testing
74
- *
75
- * @param faucetKeypair Keypair with funds to distribute
76
- */
77
- fundSplWallet(faucetKeypair: Keypair): Promise<void>;
78
- }
@@ -1,196 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NordUser = void 0;
4
- const spl_token_1 = require("@solana/spl-token");
5
- const web3_js_1 = require("@solana/web3.js");
6
- const client_1 = require("./client");
7
- const const_1 = require("./const");
8
- const utils_1 = require("./utils");
9
- class NordUser {
10
- constructor(params) {
11
- this.balances = {};
12
- this.orders = {};
13
- // Convert TokenInfo to SPLTokenInfo
14
- this.splTokenInfos = [];
15
- this.lastTs = 0;
16
- this.lastNonce = 0;
17
- this.nord = params.nord;
18
- this.publicKey = typeof params.publicKey === 'string'
19
- ? new web3_js_1.PublicKey(params.publicKey)
20
- : params.publicKey;
21
- this.walletSignFn = params.walletSignFn;
22
- this.sessionSignFn = params.sessionSignFn;
23
- this.keypair = params.keypair;
24
- this.connection = params.connection;
25
- // Convert TokenInfo to SPLTokenInfo
26
- this.splTokenInfos = this.nord.tokenInfos.map(tokenInfo => ({
27
- mint: tokenInfo.address, // Use address as mint
28
- precision: tokenInfo.precision,
29
- tokenId: tokenInfo.tokenId,
30
- name: tokenInfo.name
31
- }));
32
- // Initialize bridge client if keypair and connection are provided
33
- if (this.keypair && this.connection && this.nord.solanaProgramId) {
34
- this.initBridgeClient();
35
- }
36
- }
37
- /**
38
- * Initialize the Solana bridge client
39
- */
40
- initBridgeClient() {
41
- if (!this.keypair || !this.connection || !this.nord.solanaProgramId) {
42
- throw new Error('Keypair, connection, and program ID are required to initialize bridge client');
43
- }
44
- // Create an Anchor wallet from the keypair
45
- const wallet = {
46
- publicKey: this.keypair.publicKey,
47
- signTransaction: async (tx) => {
48
- tx.partialSign(this.keypair);
49
- return tx;
50
- },
51
- signAllTransactions: async (txs) => {
52
- return txs.map(tx => {
53
- tx.partialSign(this.keypair);
54
- return tx;
55
- });
56
- },
57
- // Add payer property to satisfy NodeWallet interface
58
- payer: this.keypair
59
- };
60
- // Initialize the bridge client
61
- this.bridgeClient = new client_1.SolanaBridgeClient({
62
- rpcUrl: this.connection.rpcEndpoint,
63
- programId: this.nord.solanaProgramId,
64
- commitment: 'confirmed',
65
- tokenInfos: this.splTokenInfos
66
- }, wallet);
67
- }
68
- /**
69
- * Create a NordUser from a private key
70
- *
71
- * @param nord Nord instance
72
- * @param privateKey Private key as string or Uint8Array
73
- * @param connection Solana connection
74
- * @returns NordUser instance
75
- */
76
- static fromPrivateKey(nord, privateKey, connection) {
77
- const keypair = (0, utils_1.keypairFromPrivateKey)(privateKey);
78
- // Create a signing function that returns Uint8Array
79
- const walletSignFn = async (message) => {
80
- const messageBuffer = typeof message === 'string'
81
- ? Buffer.from(message)
82
- : Buffer.from(message);
83
- // Use nacl for signing since Keypair doesn't have a sign method
84
- // This is a simplified version - in a real implementation, you would use proper signing
85
- return new Uint8Array(keypair.secretKey.slice(0, 64));
86
- };
87
- return new NordUser({
88
- nord,
89
- publicKey: keypair.publicKey,
90
- walletSignFn,
91
- sessionSignFn: walletSignFn,
92
- keypair,
93
- connection
94
- });
95
- }
96
- /**
97
- * Get the associated token account for a token mint
98
- *
99
- * @param mint Token mint address
100
- * @returns Associated token account address
101
- */
102
- async getAssociatedTokenAccount(mint) {
103
- if (!this.connection) {
104
- throw new Error('Connection is required to get associated token account');
105
- }
106
- const associatedTokenAddress = await (0, spl_token_1.getAssociatedTokenAddress)(mint, this.publicKey);
107
- try {
108
- await (0, spl_token_1.getAccount)(this.connection, associatedTokenAddress);
109
- }
110
- catch (error) {
111
- // Account doesn't exist, create it if keypair is available
112
- if (this.keypair && this.bridgeClient) {
113
- await this.bridgeClient.createTokenAccountIfNeeded(mint, this.publicKey, this.keypair);
114
- }
115
- }
116
- return associatedTokenAddress;
117
- }
118
- /**
119
- * Deposit SPL tokens to the bridge
120
- *
121
- * @param amount Amount to deposit
122
- * @param tokenId Token ID
123
- * @returns Transaction signature
124
- */
125
- async depositSpl(amount, tokenId) {
126
- if (!this.bridgeClient || !this.keypair || !this.connection) {
127
- throw new Error('Bridge client, keypair, and connection are required for deposit');
128
- }
129
- // Find the token info
130
- const tokenInfo = this.splTokenInfos.find(t => t.tokenId === tokenId);
131
- if (!tokenInfo) {
132
- throw new Error(`Token with ID ${tokenId} not found`);
133
- }
134
- const mint = new web3_js_1.PublicKey(tokenInfo.mint);
135
- // Get the user's token account
136
- const fromAccount = await this.getAssociatedTokenAccount(mint);
137
- // Get the bridge's token account
138
- const [authority] = await this.bridgeClient.findAuthorityPda();
139
- const toAccount = await (0, spl_token_1.getAssociatedTokenAddress)(mint, authority, true);
140
- // Convert amount to BN with proper decimals
141
- const amountBN = (0, utils_1.toBN)(amount, tokenInfo.precision);
142
- // Deposit tokens
143
- return await this.bridgeClient.depositSpl({
144
- amount: amountBN,
145
- mint,
146
- fromAccount,
147
- toAccount
148
- }, this.keypair);
149
- }
150
- /**
151
- * Withdraw tokens from the bridge
152
- *
153
- * @param claim Withdrawal claim
154
- * @returns Transaction signature
155
- */
156
- async withdrawSpl(claim) {
157
- if (!this.bridgeClient || !this.keypair || !this.connection) {
158
- throw new Error('Bridge client, keypair, and connection are required for withdrawal');
159
- }
160
- // Get the user's token account
161
- const toAccount = await this.getAssociatedTokenAccount(claim.mint);
162
- // Get the bridge's token account
163
- const [authority] = await this.bridgeClient.findAuthorityPda();
164
- const fromAccount = await (0, spl_token_1.getAssociatedTokenAddress)(claim.mint, authority, true);
165
- // Withdraw tokens
166
- return await this.bridgeClient.withdraw({
167
- claim,
168
- toAccount,
169
- fromAccount
170
- }, this.keypair);
171
- }
172
- /**
173
- * Fund the user's SPL token accounts for testing
174
- *
175
- * @param faucetKeypair Keypair with funds to distribute
176
- */
177
- async fundSplWallet(faucetKeypair) {
178
- if (!this.connection) {
179
- throw new Error('Connection is required to fund wallet');
180
- }
181
- // Fund SOL if needed
182
- const solBalance = await this.connection.getBalance(this.publicKey);
183
- if (solBalance < 10000000) { // 0.01 SOL
184
- const solFundingAmount = const_1.DEFAULT_FUNDING_AMOUNTS["SOL"];
185
- // Implement SOL transfer logic here
186
- }
187
- // Fund SPL tokens
188
- for (const tokenInfo of this.splTokenInfos) {
189
- if (const_1.DEFAULT_FUNDING_AMOUNTS[tokenInfo.mint]) {
190
- const tokenAccount = await this.getAssociatedTokenAccount(new web3_js_1.PublicKey(tokenInfo.mint));
191
- // Implement SPL token transfer logic here
192
- }
193
- }
194
- }
195
- }
196
- exports.NordUser = NordUser;
@@ -1,139 +0,0 @@
1
- import * as anchor from '@coral-xyz/anchor';
2
- import { Connection, PublicKey, Keypair } from '@solana/web3.js';
3
- import { BlockFacts, DepositSplParams, PdaSeedType, SolanaBridgeConfig, WithdrawalParams } from './types';
4
- /**
5
- * Solana Bridge Client for interacting with the bridge program
6
- */
7
- export declare class SolanaBridgeClient {
8
- /** Anchor program instance */
9
- program: any;
10
- /** Solana connection */
11
- connection: Connection;
12
- /** Program ID */
13
- programId: PublicKey;
14
- /** Configuration */
15
- config: SolanaBridgeConfig;
16
- /**
17
- * Create a new Solana Bridge Client
18
- *
19
- * @param config Bridge configuration
20
- * @param wallet Anchor wallet for signing transactions
21
- */
22
- constructor(config: SolanaBridgeConfig, wallet: anchor.Wallet);
23
- /**
24
- * Derive a PDA (Program Derived Address) for the given seeds
25
- *
26
- * @param type PDA seed type
27
- * @param seeds Additional seeds
28
- * @returns [PDA, bump]
29
- */
30
- findPda(type: PdaSeedType, ...seeds: (Buffer | PublicKey | string | number)[]): Promise<[PublicKey, number]>;
31
- /**
32
- * Find the contract storage PDA
33
- *
34
- * @returns [PDA, bump]
35
- */
36
- findContractStoragePda(): Promise<[PublicKey, number]>;
37
- /**
38
- * Find the asset whitelisted PDA for a token mint
39
- *
40
- * @param mint Token mint address
41
- * @returns [PDA, bump]
42
- */
43
- findAssetWhitelistedPda(mint: PublicKey): Promise<[PublicKey, number]>;
44
- /**
45
- * Find the deposit storage PDA for a deposit index
46
- *
47
- * @param depositIndex Deposit index
48
- * @returns [PDA, bump]
49
- */
50
- findDepositStoragePda(depositIndex: number): Promise<[PublicKey, number]>;
51
- /**
52
- * Find the block storage PDA for a block ID
53
- *
54
- * @param blockId Block ID
55
- * @returns [PDA, bump]
56
- */
57
- findBlockStoragePda(blockId: number): Promise<[PublicKey, number]>;
58
- /**
59
- * Find the withdrawal nullifier PDA
60
- *
61
- * @param blockId Block ID
62
- * @param leafIndex Leaf index
63
- * @returns [PDA, bump]
64
- */
65
- findWithdrawalNullifierPda(blockId: number, leafIndex: number): Promise<[PublicKey, number]>;
66
- /**
67
- * Find the authority PDA
68
- *
69
- * @returns [PDA, bump]
70
- */
71
- findAuthorityPda(): Promise<[PublicKey, number]>;
72
- /**
73
- * Deposit SPL tokens to the bridge
74
- *
75
- * @param params Deposit parameters
76
- * @param signer Signer keypair
77
- * @returns Transaction signature
78
- */
79
- depositSpl(params: DepositSplParams, signer: Keypair): Promise<string>;
80
- /**
81
- * Withdraw tokens from the bridge
82
- *
83
- * @param params Withdrawal parameters
84
- * @param signer Signer keypair
85
- * @returns Transaction signature
86
- */
87
- withdraw(params: WithdrawalParams, signer: Keypair): Promise<string>;
88
- /**
89
- * Whitelist an asset (token) for use with the bridge
90
- *
91
- * @param mint Token mint address
92
- * @param signer Operator keypair
93
- * @returns Transaction signature
94
- */
95
- whitelistAsset(mint: PublicKey, signer: Keypair): Promise<string>;
96
- /**
97
- * Propose a new block
98
- *
99
- * @param facts Block facts
100
- * @param signer Operator keypair
101
- * @returns Transaction signature
102
- */
103
- proposeBlock(facts: BlockFacts, signer: Keypair): Promise<string>;
104
- /**
105
- * Finalize a block
106
- *
107
- * @param blockId Block ID
108
- * @param stateUpdateId State update ID
109
- * @param signer Payer keypair
110
- * @returns Transaction signature
111
- */
112
- finalizeBlock(blockId: number, stateUpdateId: number, signer: Keypair): Promise<string>;
113
- /**
114
- * Finalize a DA fact
115
- *
116
- * @param fact DA fact (32-byte array)
117
- * @param signer Payer keypair
118
- * @returns Transaction signature
119
- */
120
- finalizeDaFact(fact: Buffer, signer: Keypair): Promise<string>;
121
- /**
122
- * Initialize the bridge contract
123
- *
124
- * @param operator Operator public key
125
- * @param initialAppStateCommitment Initial app state commitment (32-byte array)
126
- * @param signer Payer keypair
127
- * @returns Transaction signature
128
- */
129
- initialize(operator: PublicKey, initialAppStateCommitment: Buffer, signer: Keypair): Promise<string>;
130
- /**
131
- * Create an associated token account if it doesn't exist
132
- *
133
- * @param mint Token mint
134
- * @param owner Account owner
135
- * @param payer Transaction payer
136
- * @returns Associated token account address
137
- */
138
- createTokenAccountIfNeeded(mint: PublicKey, owner: PublicKey, payer: Keypair): Promise<PublicKey>;
139
- }