@n1xyz/nord-ts 0.0.16 → 0.0.18-8121ed05.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/dist/bridge/client.js +45 -6
- package/dist/gen/nord.d.ts +48 -4
- package/dist/gen/nord.js +634 -34
- package/dist/idl/bridge.d.ts +569 -0
- package/dist/idl/bridge.js +8 -0
- package/dist/idl/bridge.json +75 -62
- package/dist/idl/index.d.ts +71 -49
- package/dist/index.d.ts +1 -3
- package/dist/index.js +6 -13
- package/dist/nord/api/actions.d.ts +7 -2
- package/dist/nord/api/actions.js +7 -1
- package/dist/nord/api/core.d.ts +1 -1
- package/dist/nord/api/core.js +3 -3
- package/dist/nord/api/market.js +1 -3
- package/dist/nord/api/queries.js +2 -2
- package/dist/nord/client/Nord.d.ts +9 -14
- package/dist/nord/client/Nord.js +27 -38
- package/dist/nord/client/NordUser.d.ts +7 -23
- package/dist/nord/client/NordUser.js +67 -143
- package/dist/nord/utils/NordError.js +5 -2
- package/dist/types.d.ts +34 -50
- package/dist/utils.d.ts +2 -9
- package/dist/utils.js +13 -18
- package/package.json +17 -18
- package/protoc-generate.sh +0 -0
- package/src/idl/bridge.json +75 -62
- package/src/index.ts +9 -12
- package/src/nord/api/actions.ts +14 -3
- package/src/nord/api/core.ts +4 -2
- package/src/nord/api/market.ts +1 -4
- package/src/nord/api/queries.ts +2 -2
- package/src/nord/client/Nord.ts +45 -50
- package/src/nord/client/NordUser.ts +90 -171
- package/src/nord/utils/NordError.ts +6 -2
- package/src/types.ts +34 -49
- package/src/utils.ts +16 -19
- package/codebase.md +0 -18886
- package/docs/.nojekyll +0 -1
- package/docs/assets/hierarchy.js +0 -1
- package/docs/assets/highlight.css +0 -92
- package/docs/assets/icons.js +0 -18
- package/docs/assets/icons.svg +0 -1
- package/docs/assets/main.js +0 -60
- package/docs/assets/navigation.js +0 -1
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1611
- package/docs/classes/Nord.html +0 -189
- package/docs/classes/NordError.html +0 -24
- package/docs/classes/NordUser.html +0 -115
- package/docs/classes/NordWebSocketClient.html +0 -330
- package/docs/classes/SolanaBridgeClient.html +0 -91
- package/docs/classes/Subscriber.html +0 -10
- package/docs/enums/FillMode.html +0 -5
- package/docs/enums/KeyType.html +0 -4
- package/docs/enums/MetricPeriod.html +0 -9
- package/docs/enums/PdaSeedType.html +0 -11
- package/docs/enums/PeakTpsPeriodUnit.html +0 -15
- package/docs/enums/Side.html +0 -3
- package/docs/enums/WebSocketMessageType.html +0 -7
- package/docs/functions/actionQueryRollman.html +0 -6
- package/docs/functions/actionsQueryRollman.html +0 -6
- package/docs/functions/aggregateMetrics-1.html +0 -7
- package/docs/functions/assert.html +0 -1
- package/docs/functions/bigIntToProtoU128.html +0 -4
- package/docs/functions/bridgeToBN.html +0 -5
- package/docs/functions/bufferToHex.html +0 -4
- package/docs/functions/cancelOrder.html +0 -1
- package/docs/functions/checkPubKeyLength.html +0 -1
- package/docs/functions/checkedFetch.html +0 -6
- package/docs/functions/createSession.html +0 -1
- package/docs/functions/decodeLengthDelimited.html +0 -11
- package/docs/functions/encodeLengthDelimited.html +0 -6
- package/docs/functions/fillModeToProtoFillMode.html +0 -5
- package/docs/functions/findMarket.html +0 -1
- package/docs/functions/findPda.html +0 -6
- package/docs/functions/findToken.html +0 -1
- package/docs/functions/fromBN.html +0 -5
- package/docs/functions/getAccount.html +0 -6
- package/docs/functions/getActionNonce.html +0 -5
- package/docs/functions/getCurrentTps.html +0 -6
- package/docs/functions/getInfo.html +0 -5
- package/docs/functions/getLastActionId.html +0 -5
- package/docs/functions/getMedianLatency.html +0 -6
- package/docs/functions/getOrderbook.html +0 -6
- package/docs/functions/getPeakTps.html +0 -6
- package/docs/functions/getTimestamp.html +0 -5
- package/docs/functions/getTotalTransactions.html +0 -5
- package/docs/functions/getTrades.html +0 -6
- package/docs/functions/getUserAccountIds.html +0 -6
- package/docs/functions/hexToBuffer.html +0 -4
- package/docs/functions/initWebSocketClient.html +0 -12
- package/docs/functions/keypairFromPrivateKey.html +0 -4
- package/docs/functions/makeSigningFunction.html +0 -4
- package/docs/functions/makeWalletSignFn.html +0 -6
- package/docs/functions/marketsStats.html +0 -5
- package/docs/functions/optExpect.html +0 -5
- package/docs/functions/optMap.html +0 -5
- package/docs/functions/optUnwrap.html +0 -2
- package/docs/functions/panic.html +0 -1
- package/docs/functions/placeOrder.html +0 -1
- package/docs/functions/queryAction.html +0 -6
- package/docs/functions/queryPrometheus.html +0 -6
- package/docs/functions/queryRecentActions.html +0 -7
- package/docs/functions/revokeSession.html +0 -1
- package/docs/functions/shortenPublicKey.html +0 -5
- package/docs/functions/signAction.html +0 -6
- package/docs/functions/toBN.html +0 -5
- package/docs/functions/toScaledU128.html +0 -8
- package/docs/functions/toScaledU64.html +0 -8
- package/docs/functions/transfer.html +0 -1
- package/docs/functions/withdraw.html +0 -1
- package/docs/hierarchy.html +0 -1
- package/docs/index.html +0 -40
- package/docs/interfaces/Account.html +0 -8
- package/docs/interfaces/ActionInfo.html +0 -8
- package/docs/interfaces/ActionNonceResponse.html +0 -3
- package/docs/interfaces/ActionQuery.html +0 -4
- package/docs/interfaces/ActionResponse.html +0 -8
- package/docs/interfaces/ActionsExtendedInfo.html +0 -10
- package/docs/interfaces/ActionsQuery.html +0 -5
- package/docs/interfaces/ActionsResponse.html +0 -6
- package/docs/interfaces/AggregateMetrics.html +0 -12
- package/docs/interfaces/BlockFacts.html +0 -10
- package/docs/interfaces/BlockQuery.html +0 -6
- package/docs/interfaces/BlockResponse.html +0 -6
- package/docs/interfaces/BlockSummary.html +0 -8
- package/docs/interfaces/BlockSummaryResponse.html +0 -6
- package/docs/interfaces/DeltaEvent.html +0 -6
- package/docs/interfaces/DepositSplParams.html +0 -8
- package/docs/interfaces/Info.html +0 -3
- package/docs/interfaces/Market.html +0 -8
- package/docs/interfaces/MarketStats.html +0 -7
- package/docs/interfaces/MarketsStatsResponse.html +0 -2
- package/docs/interfaces/NordConfig.html +0 -24
- package/docs/interfaces/NordWebSocketClientEvents.html +0 -4
- package/docs/interfaces/NordWebSocketEvents.html +0 -8
- package/docs/interfaces/Order.html +0 -6
- package/docs/interfaces/OrderInfo.html +0 -6
- package/docs/interfaces/OrderbookEntry.html +0 -4
- package/docs/interfaces/OrderbookQuery.html +0 -6
- package/docs/interfaces/OrderbookResponse.html +0 -6
- package/docs/interfaces/OrderbookSubscription.html +0 -159
- package/docs/interfaces/PerpMarketStats.html +0 -5
- package/docs/interfaces/RollmanActionExtendedInfo.html +0 -4
- package/docs/interfaces/RollmanActionInfo.html +0 -4
- package/docs/interfaces/RollmanActionResponse.html +0 -4
- package/docs/interfaces/RollmanActionsResponse.html +0 -2
- package/docs/interfaces/RollmanBlockResponse.html +0 -3
- package/docs/interfaces/SPLTokenInfo.html +0 -10
- package/docs/interfaces/SolanaBridgeConfig.html +0 -12
- package/docs/interfaces/StateFacts.html +0 -10
- package/docs/interfaces/SubscriberConfig.html +0 -3
- package/docs/interfaces/TimestampResponse.html +0 -3
- package/docs/interfaces/Token.html +0 -5
- package/docs/interfaces/TokenInfo.html +0 -6
- package/docs/interfaces/Trade.html +0 -5
- package/docs/interfaces/TradeSubscription.html +0 -159
- package/docs/interfaces/Trades.html +0 -5
- package/docs/interfaces/TradesQuery.html +0 -6
- package/docs/interfaces/TradesResponse.html +0 -7
- package/docs/interfaces/TransferParams.html +0 -8
- package/docs/interfaces/UserAccountIdsQuery.html +0 -3
- package/docs/interfaces/UserAccountIdsResponse.html +0 -3
- package/docs/interfaces/WebSocketAccountUpdate.html +0 -6
- package/docs/interfaces/WebSocketDeltaUpdate.html +0 -9
- package/docs/interfaces/WebSocketSubscription.html +0 -4
- package/docs/interfaces/WebSocketTradeUpdate.html +0 -6
- package/docs/interfaces/WithdrawalClaim.html +0 -14
- package/docs/interfaces/WithdrawalParams.html +0 -8
- package/docs/modules.html +0 -1
- package/docs/types/BigIntValue.html +0 -2
- package/docs/types/SubscriptionPattern.html +0 -4
- package/docs/types/SubscriptionType.html +0 -2
- package/docs/types/WebSocketMessage.html +0 -1
- package/docs/variables/DEBUG_KEYS.html +0 -1
- package/docs/variables/DEFAULT_FUNDING_AMOUNTS.html +0 -1
- package/docs/variables/DEV_TOKEN_INFOS.html +0 -1
- package/docs/variables/DEV_URL.html +0 -1
- package/docs/variables/MAX_BUFFER_LEN.html +0 -1
- package/docs/variables/SESSION_TTL.html +0 -1
- package/docs/variables/WEBSERVER_DEV_URL.html +0 -1
- package/docs/variables/ZERO_DECIMAL.html +0 -1
- package/docs/variables/_private.html +0 -2
- package/idl-generate.sh +0 -4
- package/src/bridge/client.ts +0 -498
- package/src/bridge/const.ts +0 -53
- package/src/bridge/index.ts +0 -6
- package/src/bridge/types.ts +0 -129
- package/src/bridge/utils.ts +0 -140
- package/src/gen/common.ts +0 -297
- package/src/gen/nord.ts +0 -6716
- package/src/idl/index.ts +0 -2
package/src/types.ts
CHANGED
|
@@ -39,22 +39,11 @@ export interface NordConfig {
|
|
|
39
39
|
bridgeVk: string;
|
|
40
40
|
/** Solana cluster URL */
|
|
41
41
|
solanaUrl: string;
|
|
42
|
-
/** Whether to initialize WebSockets on creation, defaults to true */
|
|
43
|
-
initWebSockets?: boolean;
|
|
44
|
-
/**
|
|
45
|
-
* Initial subscriptions for the trades WebSocket
|
|
46
|
-
* Supports both formats:
|
|
47
|
-
* - Legacy format: ["BTCUSDC", "ETHUSDC"]
|
|
48
|
-
* - New format: ["trades@BTCUSDC", "trades@ETHUSDC"]
|
|
49
|
-
*/
|
|
50
|
-
tradesSubscriptions?: SubscriptionPattern[];
|
|
51
42
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* - Legacy format: ["BTCUSDC", "ETHUSDC"]
|
|
55
|
-
* - New format: ["deltas@BTCUSDC", "deltas@ETHUSDC"]
|
|
43
|
+
* Whether to initialize WebSockets on creation, defaults to true
|
|
44
|
+
* @deprecated this is a funky api we're gonna be removing it
|
|
56
45
|
*/
|
|
57
|
-
|
|
46
|
+
initWebSockets?: boolean;
|
|
58
47
|
}
|
|
59
48
|
|
|
60
49
|
/**
|
|
@@ -150,7 +139,7 @@ export interface OrderInfo {
|
|
|
150
139
|
account_id: number;
|
|
151
140
|
}
|
|
152
141
|
|
|
153
|
-
interface HashMap<T> {
|
|
142
|
+
export interface HashMap<T> {
|
|
154
143
|
[key: number]: T;
|
|
155
144
|
}
|
|
156
145
|
|
|
@@ -166,9 +155,8 @@ export interface Account {
|
|
|
166
155
|
|
|
167
156
|
/**
|
|
168
157
|
* Query the transactions in the specified L2 block.
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
* are returned.
|
|
158
|
+
* block_number specifies the block number to query.
|
|
159
|
+
* If not specified, transactions from latest block are returned.
|
|
172
160
|
*/
|
|
173
161
|
export interface BlockQuery {
|
|
174
162
|
block_number?: number;
|
|
@@ -176,8 +164,8 @@ export interface BlockQuery {
|
|
|
176
164
|
|
|
177
165
|
/**
|
|
178
166
|
* Response for BlockQuery.
|
|
179
|
-
*
|
|
180
|
-
*
|
|
167
|
+
* block_number specifies the block number being returned.
|
|
168
|
+
* actions are the list of transactions from the block.
|
|
181
169
|
*/
|
|
182
170
|
export interface BlockResponse {
|
|
183
171
|
block_number: number;
|
|
@@ -186,9 +174,9 @@ export interface BlockResponse {
|
|
|
186
174
|
|
|
187
175
|
/**
|
|
188
176
|
* Response for BlockSummaryQuery.
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
177
|
+
* block_summary is the summary of upto the last N blocks.
|
|
178
|
+
* The server can return fewer than last_n block summary if
|
|
179
|
+
* fewer blocks are available or if it exceeds a max cap.
|
|
192
180
|
*/
|
|
193
181
|
export interface BlockSummaryResponse {
|
|
194
182
|
block_summary: BlockSummary[];
|
|
@@ -196,7 +184,7 @@ export interface BlockSummaryResponse {
|
|
|
196
184
|
|
|
197
185
|
/**
|
|
198
186
|
* Query the action for the specified action id.
|
|
199
|
-
*
|
|
187
|
+
* action_id specifies the action to query.
|
|
200
188
|
*/
|
|
201
189
|
export interface ActionQuery {
|
|
202
190
|
action_id: number;
|
|
@@ -204,10 +192,9 @@ export interface ActionQuery {
|
|
|
204
192
|
|
|
205
193
|
/**
|
|
206
194
|
* Response for ActionQuery.
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
* @field {Action} the transaction.
|
|
195
|
+
* block_number the block the action is part of.
|
|
196
|
+
* If the action is not yet included in any block, null is returned.
|
|
197
|
+
* action the transaction.
|
|
211
198
|
*/
|
|
212
199
|
export interface ActionResponse {
|
|
213
200
|
block_number?: number;
|
|
@@ -216,8 +203,7 @@ export interface ActionResponse {
|
|
|
216
203
|
|
|
217
204
|
/**
|
|
218
205
|
* Query the recent actions
|
|
219
|
-
*
|
|
220
|
-
* @field {number} action_id specifies the action to query.
|
|
206
|
+
* last_n requests last N actions.
|
|
221
207
|
*/
|
|
222
208
|
export interface ActionsQuery {
|
|
223
209
|
last_n: number;
|
|
@@ -225,9 +211,9 @@ export interface ActionsQuery {
|
|
|
225
211
|
|
|
226
212
|
/**
|
|
227
213
|
* Response for ActionsQuery.
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
214
|
+
* actions returns upto the last N actions.
|
|
215
|
+
* The server can return fewer than last_n actions if
|
|
216
|
+
* fewer actions are available or if it exceeds a max cap.
|
|
231
217
|
*/
|
|
232
218
|
export interface ActionsResponse {
|
|
233
219
|
actions: ActionsExtendedInfo[];
|
|
@@ -235,9 +221,9 @@ export interface ActionsResponse {
|
|
|
235
221
|
|
|
236
222
|
/**
|
|
237
223
|
* Block summary.
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
224
|
+
* block_number Block number.
|
|
225
|
+
* from_action_id First action_id in the block.
|
|
226
|
+
* to_action_id Last action_id in the block.
|
|
241
227
|
*/
|
|
242
228
|
export interface BlockSummary {
|
|
243
229
|
block_number: number;
|
|
@@ -247,9 +233,9 @@ export interface BlockSummary {
|
|
|
247
233
|
|
|
248
234
|
/**
|
|
249
235
|
* Info about the block transaction.
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
236
|
+
* action_id is the action identifier.
|
|
237
|
+
* action in protobuf format.
|
|
238
|
+
* exec_timestamp is the execution timestamp.
|
|
253
239
|
*/
|
|
254
240
|
export interface ActionInfo {
|
|
255
241
|
action_id: number;
|
|
@@ -259,11 +245,10 @@ export interface ActionInfo {
|
|
|
259
245
|
|
|
260
246
|
/**
|
|
261
247
|
* Extended info about the block transaction.
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
* @field {Action} action the transaction.
|
|
248
|
+
* block_number the block the action is part of.
|
|
249
|
+
* If the action is not yet included in any block, null is returned.
|
|
250
|
+
* action_id of the action.
|
|
251
|
+
* action the transaction.
|
|
267
252
|
*/
|
|
268
253
|
export interface ActionsExtendedInfo {
|
|
269
254
|
block_number?: number;
|
|
@@ -273,11 +258,11 @@ export interface ActionsExtendedInfo {
|
|
|
273
258
|
|
|
274
259
|
/**
|
|
275
260
|
* Aggregate metrics
|
|
276
|
-
*
|
|
277
|
-
*
|
|
278
|
-
*
|
|
279
|
-
*
|
|
280
|
-
*
|
|
261
|
+
* blocks_total: Total number of L2 blocks.
|
|
262
|
+
* tx_total: Total number of transactions.
|
|
263
|
+
* tx_tps: Transaction throughput.
|
|
264
|
+
* tx_tps_peak: Peak transaction throughput.
|
|
265
|
+
* request_latency_average: Average request latency.
|
|
281
266
|
*/
|
|
282
267
|
export interface AggregateMetrics {
|
|
283
268
|
blocks_total: number;
|
package/src/utils.ts
CHANGED
|
@@ -9,7 +9,8 @@ import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
|
|
|
9
9
|
import { ethers } from "ethers";
|
|
10
10
|
import fetch from "node-fetch";
|
|
11
11
|
import { RequestInfo, RequestInit, Response } from "node-fetch";
|
|
12
|
-
import {
|
|
12
|
+
import { Keypair } from "@solana/web3.js";
|
|
13
|
+
import bs58 from "bs58";
|
|
13
14
|
|
|
14
15
|
export const SESSION_TTL: bigint = 60n * 60n * 24n * 30n;
|
|
15
16
|
export const ZERO_DECIMAL = new Decimal(0);
|
|
@@ -300,22 +301,18 @@ export function findToken(tokens: Token[], tokenId: number): Token {
|
|
|
300
301
|
return tokens[tokenId];
|
|
301
302
|
}
|
|
302
303
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
? new BN(fraction.padEnd(decimals, "0").slice(0, decimals))
|
|
318
|
-
: new BN(0);
|
|
319
|
-
|
|
320
|
-
return wholeBN.add(fractionBN);
|
|
304
|
+
export function keypairFromPrivateKey(
|
|
305
|
+
privateKey: string | Uint8Array,
|
|
306
|
+
): Keypair {
|
|
307
|
+
if (typeof privateKey === "string") {
|
|
308
|
+
if (!privateKey.startsWith("0x")) {
|
|
309
|
+
return Keypair.fromSecretKey(bs58.decode(privateKey));
|
|
310
|
+
}
|
|
311
|
+
const hex = privateKey.startsWith("0x") ? privateKey.slice(2) : privateKey;
|
|
312
|
+
const bytes = new Uint8Array(
|
|
313
|
+
hex.match(/.{1,2}/g)!.map((byte) => parseInt(byte, 16)),
|
|
314
|
+
);
|
|
315
|
+
return Keypair.fromSecretKey(bytes);
|
|
316
|
+
}
|
|
317
|
+
return Keypair.fromSecretKey(privateKey);
|
|
321
318
|
}
|