@n1xyz/nord-ts 0.0.18-8121ed05.0 → 0.0.18
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/.local/qa.ts +77 -0
- package/.local/test-atomic.ts +112 -0
- package/check.sh +4 -0
- package/default.nix +47 -0
- package/dist/api/client.d.ts +14 -0
- package/dist/api/client.js +45 -0
- package/dist/gen/nord.d.ts +52 -23
- package/dist/gen/nord.js +322 -170
- package/dist/gen/openapi.d.ts +2244 -0
- package/dist/gen/openapi.js +6 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -9
- package/dist/nord/api/actions.d.ts +30 -1
- package/dist/nord/api/actions.js +60 -3
- package/dist/nord/api/core.d.ts +1 -34
- package/dist/nord/api/core.js +0 -71
- package/dist/nord/client/Nord.d.ts +31 -33
- package/dist/nord/client/Nord.js +100 -60
- package/dist/nord/client/NordUser.d.ts +64 -11
- package/dist/nord/client/NordUser.js +90 -33
- package/dist/nord/index.d.ts +0 -2
- package/dist/nord/index.js +0 -2
- package/dist/nord/models/Subscriber.d.ts +2 -2
- package/dist/types.d.ts +43 -190
- package/dist/utils.d.ts +1 -19
- package/dist/utils.js +5 -39
- package/dist/websocket/NordWebSocketClient.js +18 -13
- package/dist/websocket/index.d.ts +1 -1
- package/package.json +20 -27
- package/src/index.ts +0 -16
- package/src/nord/api/actions.ts +131 -9
- package/src/nord/api/core.ts +0 -71
- package/src/nord/client/Nord.ts +142 -76
- package/src/nord/client/NordUser.ts +171 -50
- package/src/nord/index.ts +0 -2
- package/src/nord/models/Subscriber.ts +2 -2
- package/src/types.ts +55 -216
- package/src/utils.ts +6 -42
- package/src/websocket/NordWebSocketClient.ts +23 -15
- package/src/websocket/index.ts +1 -1
- package/tests/utils.spec.ts +1 -34
- package/dist/idl/bridge.json +0 -1506
- package/jest.config.ts +0 -9
- package/nodemon.json +0 -4
- package/protoc-generate.sh +0 -23
- package/src/idl/bridge.json +0 -1506
- package/src/nord/api/market.ts +0 -122
- package/src/nord/api/queries.ts +0 -135
|
@@ -9,8 +9,9 @@ import Decimal from "decimal.js";
|
|
|
9
9
|
import * as ed from "@noble/ed25519";
|
|
10
10
|
import { sha512 } from "@noble/hashes/sha512";
|
|
11
11
|
ed.etc.sha512Sync = sha512;
|
|
12
|
-
import {
|
|
13
|
-
import { FillMode, Order, Side } from "../../types";
|
|
12
|
+
import { floatToScaledBigIntLossy } from "@n1xyz/proton";
|
|
13
|
+
import { FillMode, Order, Side, SPLTokenInfo } from "../../types";
|
|
14
|
+
import * as proto from "../../gen/nord";
|
|
14
15
|
import {
|
|
15
16
|
BigIntValue,
|
|
16
17
|
checkedFetch,
|
|
@@ -26,6 +27,8 @@ import {
|
|
|
26
27
|
revokeSession,
|
|
27
28
|
transfer,
|
|
28
29
|
withdraw,
|
|
30
|
+
atomic as atomicAction,
|
|
31
|
+
AtomicSubaction as ApiAtomicSubaction,
|
|
29
32
|
} from "../api/actions";
|
|
30
33
|
import { NordError } from "../utils/NordError";
|
|
31
34
|
import { Nord } from "./Nord";
|
|
@@ -47,7 +50,7 @@ export interface NordUserParams {
|
|
|
47
50
|
sessionSignFn: (message: Uint8Array) => Promise<Uint8Array>;
|
|
48
51
|
|
|
49
52
|
/** Function to sign transactions with the user's wallet (optional) */
|
|
50
|
-
transactionSignFn: (
|
|
53
|
+
transactionSignFn: <T extends Transaction>(tx: T) => Promise<T>;
|
|
51
54
|
|
|
52
55
|
/** Solana connection (optional) */
|
|
53
56
|
connection?: Connection;
|
|
@@ -111,6 +114,41 @@ export interface TransferParams {
|
|
|
111
114
|
toAccountId: number;
|
|
112
115
|
}
|
|
113
116
|
|
|
117
|
+
/**
|
|
118
|
+
* Parameters for individual atomic subactions (user-friendly version)
|
|
119
|
+
*/
|
|
120
|
+
export interface UserAtomicSubaction {
|
|
121
|
+
/** The type of action to perform. */
|
|
122
|
+
kind: "place" | "cancel";
|
|
123
|
+
|
|
124
|
+
/** The market ID to place the order in. */
|
|
125
|
+
marketId?: number;
|
|
126
|
+
|
|
127
|
+
/** The order ID to cancel. */
|
|
128
|
+
orderId?: BigIntValue;
|
|
129
|
+
|
|
130
|
+
/** Order side (bid or ask) */
|
|
131
|
+
side?: Side;
|
|
132
|
+
|
|
133
|
+
/** Fill mode (limit, market, etc.) */
|
|
134
|
+
fillMode?: FillMode;
|
|
135
|
+
|
|
136
|
+
/** Whether the order is reduce-only. */
|
|
137
|
+
isReduceOnly?: boolean;
|
|
138
|
+
|
|
139
|
+
/** The size of the order. */
|
|
140
|
+
size?: Decimal.Value;
|
|
141
|
+
|
|
142
|
+
/** Order price */
|
|
143
|
+
price?: Decimal.Value;
|
|
144
|
+
|
|
145
|
+
/** Quote size (for market orders) */
|
|
146
|
+
quoteSize?: Decimal.Value;
|
|
147
|
+
|
|
148
|
+
/** The client order ID of the order. */
|
|
149
|
+
clientOrderId?: BigIntValue;
|
|
150
|
+
}
|
|
151
|
+
|
|
114
152
|
/**
|
|
115
153
|
* User class for interacting with the Nord protocol
|
|
116
154
|
*/
|
|
@@ -130,16 +168,15 @@ export class NordUser {
|
|
|
130
168
|
public readonly sessionSignFn: (message: Uint8Array) => Promise<Uint8Array>;
|
|
131
169
|
|
|
132
170
|
/** Function to sign transactions with the user's wallet */
|
|
133
|
-
public readonly transactionSignFn:
|
|
171
|
+
public readonly transactionSignFn: <T extends Transaction>(
|
|
172
|
+
tx: T,
|
|
173
|
+
) => Promise<T>;
|
|
134
174
|
|
|
135
175
|
/** User balances by token symbol */
|
|
136
176
|
public balances: {
|
|
137
177
|
[key: string]: { accountId: number; balance: number; symbol: string }[];
|
|
138
178
|
} = {};
|
|
139
179
|
|
|
140
|
-
/** User orders by market symbol */
|
|
141
|
-
public orders: { [key: string]: Order[] } = {};
|
|
142
|
-
|
|
143
180
|
/** User positions by account ID */
|
|
144
181
|
public positions: {
|
|
145
182
|
[key: string]: {
|
|
@@ -275,7 +312,6 @@ export class NordUser {
|
|
|
275
312
|
|
|
276
313
|
// Copy other properties
|
|
277
314
|
cloned.balances = { ...this.balances };
|
|
278
|
-
cloned.orders = { ...this.orders };
|
|
279
315
|
cloned.positions = { ...this.positions };
|
|
280
316
|
cloned.margins = { ...this.margins };
|
|
281
317
|
cloned.accountIds = this.accountIds ? [...this.accountIds] : undefined;
|
|
@@ -416,10 +452,37 @@ export class NordUser {
|
|
|
416
452
|
*
|
|
417
453
|
* @param amount - Amount to deposit
|
|
418
454
|
* @param tokenId - Token ID
|
|
455
|
+
* @param recipient - Recipient address; defaults to the user's address
|
|
419
456
|
* @returns Transaction signature
|
|
457
|
+
* @deprecated Use deposit instead
|
|
420
458
|
* @throws {NordError} If required parameters are missing or operation fails
|
|
421
459
|
*/
|
|
422
|
-
async depositSpl(
|
|
460
|
+
async depositSpl(
|
|
461
|
+
amount: number,
|
|
462
|
+
tokenId: number,
|
|
463
|
+
recipient?: PublicKey,
|
|
464
|
+
): Promise<string> {
|
|
465
|
+
return this.deposit({ amount, tokenId, recipient });
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* Deposit SPL tokens to the bridge
|
|
470
|
+
*
|
|
471
|
+
* @param amount - Amount to deposit
|
|
472
|
+
* @param tokenId - Token ID
|
|
473
|
+
* @param recipient - Recipient address; defaults to the user's address
|
|
474
|
+
* @returns Transaction signature
|
|
475
|
+
* @throws {NordError} If required parameters are missing or operation fails
|
|
476
|
+
*/
|
|
477
|
+
async deposit({
|
|
478
|
+
amount,
|
|
479
|
+
tokenId,
|
|
480
|
+
recipient,
|
|
481
|
+
}: Readonly<{
|
|
482
|
+
amount: number;
|
|
483
|
+
tokenId: number;
|
|
484
|
+
recipient?: PublicKey;
|
|
485
|
+
}>): Promise<string> {
|
|
423
486
|
try {
|
|
424
487
|
// Find the token info
|
|
425
488
|
const tokenInfo = this.splTokenInfos.find((t) => t.tokenId === tokenId);
|
|
@@ -428,35 +491,28 @@ export class NordUser {
|
|
|
428
491
|
}
|
|
429
492
|
|
|
430
493
|
const mint = new PublicKey(tokenInfo.mint);
|
|
431
|
-
// Get the user's token account
|
|
432
494
|
const fromAccount = await this.getAssociatedTokenAccount(mint);
|
|
495
|
+
const payer = this.getSolanaPublicKey();
|
|
433
496
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
const depositParams: DepositSplParams = {
|
|
439
|
-
amount: amountBN,
|
|
497
|
+
const { ix, extraSigner } = await this.nord.protonClient.buildDepositIx({
|
|
498
|
+
payer,
|
|
499
|
+
recipient: recipient ?? payer,
|
|
500
|
+
quantAmount: floatToScaledBigIntLossy(amount, tokenInfo.precision),
|
|
440
501
|
mint,
|
|
441
|
-
fromAccount,
|
|
442
|
-
};
|
|
443
|
-
|
|
444
|
-
// Build the deposit transaction using proton client
|
|
445
|
-
const depositTx = await this.nord.protonClient.buildDepositTx(
|
|
446
|
-
depositParams,
|
|
447
|
-
this.getSolanaPublicKey(),
|
|
448
|
-
this.connection,
|
|
449
|
-
);
|
|
502
|
+
sourceTokenAccount: fromAccount,
|
|
503
|
+
});
|
|
450
504
|
|
|
451
|
-
const { blockhash } =
|
|
505
|
+
const { blockhash } =
|
|
506
|
+
await this.connection.getLatestBlockhash("confirmed");
|
|
507
|
+
const tx = new Transaction();
|
|
452
508
|
|
|
453
|
-
|
|
454
|
-
|
|
509
|
+
tx.add(ix);
|
|
510
|
+
tx.recentBlockhash = blockhash;
|
|
511
|
+
tx.feePayer = payer;
|
|
455
512
|
|
|
456
|
-
const signedTx = await this.transactionSignFn(
|
|
513
|
+
const signedTx = await this.transactionSignFn(tx);
|
|
514
|
+
signedTx.partialSign(extraSigner);
|
|
457
515
|
|
|
458
|
-
// TODO: should use `VersionedTransaction` and remove any for `transactionSignFn`,
|
|
459
|
-
// this is incredibly annoying to debug and i could've saved 30 mins.
|
|
460
516
|
const signature = await this.connection.sendRawTransaction(
|
|
461
517
|
signedTx.serialize(),
|
|
462
518
|
);
|
|
@@ -490,10 +546,14 @@ export class NordUser {
|
|
|
490
546
|
throw new NordError("Public key is required to update account ID");
|
|
491
547
|
}
|
|
492
548
|
|
|
493
|
-
const resp = await this.nord.
|
|
549
|
+
const resp = await this.nord.getUser({
|
|
494
550
|
pubkey: this.publicKey.toBase58(),
|
|
495
551
|
});
|
|
496
552
|
|
|
553
|
+
if (!resp) {
|
|
554
|
+
throw new NordError(`User ${this.publicKey.toBase58()} not found`);
|
|
555
|
+
}
|
|
556
|
+
|
|
497
557
|
this.accountIds = resp.accountIds;
|
|
498
558
|
} catch (error) {
|
|
499
559
|
throw new NordError("Failed to update account ID", { cause: error });
|
|
@@ -582,19 +642,6 @@ export class NordUser {
|
|
|
582
642
|
});
|
|
583
643
|
}
|
|
584
644
|
|
|
585
|
-
// Process orders
|
|
586
|
-
this.orders[accountData.accountId] = accountData.orders.map(
|
|
587
|
-
(order: OpenOrder) => {
|
|
588
|
-
return {
|
|
589
|
-
orderId: order.orderId,
|
|
590
|
-
isLong: order.side === "bid",
|
|
591
|
-
size: order.size,
|
|
592
|
-
price: order.price,
|
|
593
|
-
marketId: order.marketId,
|
|
594
|
-
};
|
|
595
|
-
},
|
|
596
|
-
);
|
|
597
|
-
|
|
598
645
|
// Process positions
|
|
599
646
|
this.positions[accountData.accountId] = accountData.positions;
|
|
600
647
|
|
|
@@ -610,7 +657,6 @@ export class NordUser {
|
|
|
610
657
|
* @throws {NordError} If the operation fails
|
|
611
658
|
*/
|
|
612
659
|
async refreshSession(): Promise<void> {
|
|
613
|
-
console.log(this.publicKey);
|
|
614
660
|
this.sessionId = await createSession(
|
|
615
661
|
this.nord.webServerUrl,
|
|
616
662
|
this.walletSignFn,
|
|
@@ -666,10 +712,13 @@ export class NordUser {
|
|
|
666
712
|
* @param amount - Amount to withdraw
|
|
667
713
|
* @throws {NordError} If the operation fails
|
|
668
714
|
*/
|
|
669
|
-
async withdraw(
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
715
|
+
async withdraw({
|
|
716
|
+
amount,
|
|
717
|
+
tokenId,
|
|
718
|
+
}: Readonly<{
|
|
719
|
+
tokenId: number;
|
|
720
|
+
amount: number;
|
|
721
|
+
}>): Promise<{ actionId: bigint }> {
|
|
673
722
|
try {
|
|
674
723
|
this.checkSessionValidity();
|
|
675
724
|
const { actionId } = await withdraw(
|
|
@@ -796,6 +845,78 @@ export class NordUser {
|
|
|
796
845
|
}
|
|
797
846
|
}
|
|
798
847
|
|
|
848
|
+
/**
|
|
849
|
+
* Execute up to four place/cancel operations atomically.
|
|
850
|
+
* Per Market:
|
|
851
|
+
* 1. cancels can only be in the start (one cannot predict future order ids)
|
|
852
|
+
* 2. intermediate trades can trade only
|
|
853
|
+
* 3. placements go last
|
|
854
|
+
*
|
|
855
|
+
* Across Markets, order action can be any
|
|
856
|
+
*
|
|
857
|
+
* @param userActions array of user-friendly subactions
|
|
858
|
+
* @param providedAccountId optional account performing the action (defaults to first account)
|
|
859
|
+
*/
|
|
860
|
+
async atomic(
|
|
861
|
+
userActions: UserAtomicSubaction[],
|
|
862
|
+
providedAccountId?: number,
|
|
863
|
+
): Promise<proto.Receipt_AtomicResult> {
|
|
864
|
+
try {
|
|
865
|
+
this.checkSessionValidity();
|
|
866
|
+
|
|
867
|
+
const accountId =
|
|
868
|
+
providedAccountId != null ? providedAccountId : this.accountIds?.[0];
|
|
869
|
+
|
|
870
|
+
if (accountId == null) {
|
|
871
|
+
throw new NordError(
|
|
872
|
+
"Account ID is undefined. Make sure to call updateAccountId() before atomic operations.",
|
|
873
|
+
);
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
const apiActions: ApiAtomicSubaction[] = userActions.map((act) => {
|
|
877
|
+
if (act.kind === "place") {
|
|
878
|
+
const market = findMarket(this.nord.markets, act.marketId!);
|
|
879
|
+
if (!market) {
|
|
880
|
+
throw new NordError(`Market ${act.marketId} not found`);
|
|
881
|
+
}
|
|
882
|
+
return {
|
|
883
|
+
kind: "place",
|
|
884
|
+
marketId: act.marketId,
|
|
885
|
+
side: act.side,
|
|
886
|
+
fillMode: act.fillMode,
|
|
887
|
+
isReduceOnly: act.isReduceOnly,
|
|
888
|
+
sizeDecimals: market.sizeDecimals,
|
|
889
|
+
priceDecimals: market.priceDecimals,
|
|
890
|
+
size: act.size,
|
|
891
|
+
price: act.price,
|
|
892
|
+
quoteSizeSize: act.quoteSize, // treated as quote size; we pass only size component
|
|
893
|
+
quoteSizePrice: undefined,
|
|
894
|
+
clientOrderId: act.clientOrderId,
|
|
895
|
+
} as ApiAtomicSubaction;
|
|
896
|
+
}
|
|
897
|
+
return {
|
|
898
|
+
kind: "cancel",
|
|
899
|
+
orderId: act.orderId,
|
|
900
|
+
} as ApiAtomicSubaction;
|
|
901
|
+
});
|
|
902
|
+
|
|
903
|
+
const result = await atomicAction(
|
|
904
|
+
this.nord.webServerUrl,
|
|
905
|
+
this.sessionSignFn,
|
|
906
|
+
await this.nord.getTimestamp(),
|
|
907
|
+
this.getNonce(),
|
|
908
|
+
{
|
|
909
|
+
sessionId: optExpect(this.sessionId, "No session"),
|
|
910
|
+
accountId: accountId,
|
|
911
|
+
actions: apiActions,
|
|
912
|
+
},
|
|
913
|
+
);
|
|
914
|
+
return result;
|
|
915
|
+
} catch (error) {
|
|
916
|
+
throw new NordError("Atomic operation failed", { cause: error });
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
|
|
799
920
|
/**
|
|
800
921
|
* Helper function to retry a promise with exponential backoff
|
|
801
922
|
*
|
package/src/nord/index.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
DeltaEvent,
|
|
5
5
|
OrderbookResponse,
|
|
6
6
|
SubscriberConfig,
|
|
7
|
-
|
|
7
|
+
StreamTrade,
|
|
8
8
|
Trades,
|
|
9
9
|
} from "../../types";
|
|
10
10
|
import { MAX_BUFFER_LEN } from "../../utils";
|
|
@@ -49,7 +49,7 @@ export interface OrderbookSubscription extends EventEmitter {
|
|
|
49
49
|
* Interface for trade subscription
|
|
50
50
|
*/
|
|
51
51
|
export interface TradeSubscription extends EventEmitter {
|
|
52
|
-
on(event: "message", listener: (data:
|
|
52
|
+
on(event: "message", listener: (data: StreamTrade[]) => void): this;
|
|
53
53
|
on(event: "error", listener: (error: Error) => void): this;
|
|
54
54
|
close(): void;
|
|
55
55
|
removeAllListeners(event?: string): this;
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as proto from "./gen/nord";
|
|
2
|
+
import type { components } from "./gen/openapi.ts";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* The peak TPS rate is queried over the specified period.
|
|
@@ -46,6 +47,46 @@ export interface NordConfig {
|
|
|
46
47
|
initWebSockets?: boolean;
|
|
47
48
|
}
|
|
48
49
|
|
|
50
|
+
export type Info = components["schemas"]["Info2"];
|
|
51
|
+
export type Market = Info["markets"][number];
|
|
52
|
+
export type Token = Info["tokens"][number];
|
|
53
|
+
export type Account = components["schemas"]["Account"];
|
|
54
|
+
export type TradesResponse =
|
|
55
|
+
components["schemas"]["PageResult_for_String_and_Trade"];
|
|
56
|
+
export type User = components["schemas"]["User"];
|
|
57
|
+
export type OrderbookResponse = components["schemas"]["OrderbookInfo"];
|
|
58
|
+
export type MarketStats = components["schemas"]["MarketStats"];
|
|
59
|
+
export type OrderbookInfo = components["schemas"]["OrderbookInfo"];
|
|
60
|
+
export type MarketStatsFromApi = components["schemas"]["MarketStats"];
|
|
61
|
+
export type TradeFromApi = components["schemas"]["Trade"];
|
|
62
|
+
// Generic PageResult type - note that K and V must match existing schema keys
|
|
63
|
+
export type PageResult<K extends string, V extends string> = K extends "String"
|
|
64
|
+
? V extends "OrderInfo"
|
|
65
|
+
? components["schemas"]["PageResult_for_String_and_OrderInfo"]
|
|
66
|
+
: V extends "Trade"
|
|
67
|
+
? components["schemas"]["PageResult_for_String_and_Trade"]
|
|
68
|
+
: never
|
|
69
|
+
: never;
|
|
70
|
+
export type PageResultStringOrderInfo =
|
|
71
|
+
components["schemas"]["PageResult_for_String_and_OrderInfo"];
|
|
72
|
+
export type PageResultStringTrade =
|
|
73
|
+
components["schemas"]["PageResult_for_String_and_Trade"];
|
|
74
|
+
export type OrderInfoFromApi = components["schemas"]["OrderInfo"];
|
|
75
|
+
export type OpenOrder = components["schemas"]["OpenOrder"];
|
|
76
|
+
export type Balance = components["schemas"]["Balance"];
|
|
77
|
+
export type PositionSummary = components["schemas"]["PositionSummary"];
|
|
78
|
+
export type PerpPosition = components["schemas"]["PerpPosition"];
|
|
79
|
+
export type AccountMarginsView = components["schemas"]["AccountMarginsView"];
|
|
80
|
+
export type SideSummary = components["schemas"]["SideSummary"];
|
|
81
|
+
export type UserSession = components["schemas"]["UserSession"];
|
|
82
|
+
export type ActionsItem = components["schemas"]["ActionsItem"];
|
|
83
|
+
export type FillRole = components["schemas"]["FillRole"];
|
|
84
|
+
export type PerpMarketStatsFromApi = components["schemas"]["PerpMarketStats"];
|
|
85
|
+
export type SideFromApi = components["schemas"]["Side"];
|
|
86
|
+
export type FillModeFromApi = components["schemas"]["FillMode"];
|
|
87
|
+
export type PlacementOrigin = components["schemas"]["PlacementOrigin"];
|
|
88
|
+
export type FinalizationReason = components["schemas"]["FinalizationReason"];
|
|
89
|
+
|
|
49
90
|
/**
|
|
50
91
|
* Configuration options for the Nord client
|
|
51
92
|
*/
|
|
@@ -87,28 +128,6 @@ export interface SubscriberConfig {
|
|
|
87
128
|
maxBufferLen?: number;
|
|
88
129
|
}
|
|
89
130
|
|
|
90
|
-
export interface Market {
|
|
91
|
-
marketId: number;
|
|
92
|
-
symbol: string;
|
|
93
|
-
priceDecimals: number;
|
|
94
|
-
sizeDecimals: number;
|
|
95
|
-
baseTokenId: number;
|
|
96
|
-
quoteTokenId: number;
|
|
97
|
-
frozen: boolean;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export interface Token {
|
|
101
|
-
tokenId: number;
|
|
102
|
-
symbol: string;
|
|
103
|
-
decimals: number;
|
|
104
|
-
mintAddr: string;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export interface Info {
|
|
108
|
-
markets: Market[];
|
|
109
|
-
tokens: Token[];
|
|
110
|
-
}
|
|
111
|
-
|
|
112
131
|
export interface DeltaEvent {
|
|
113
132
|
last_update_id: number;
|
|
114
133
|
update_id: number;
|
|
@@ -117,7 +136,7 @@ export interface DeltaEvent {
|
|
|
117
136
|
bids: OrderbookEntry[];
|
|
118
137
|
}
|
|
119
138
|
|
|
120
|
-
export interface
|
|
139
|
+
export interface StreamTrade {
|
|
121
140
|
side: Side;
|
|
122
141
|
price: number;
|
|
123
142
|
size: number;
|
|
@@ -128,95 +147,26 @@ export interface Trades {
|
|
|
128
147
|
last_update_id: number;
|
|
129
148
|
update_id: number;
|
|
130
149
|
market_symbol: string;
|
|
131
|
-
trades:
|
|
150
|
+
trades: StreamTrade[];
|
|
132
151
|
}
|
|
133
152
|
|
|
134
|
-
export interface
|
|
153
|
+
export interface LocalOrderInfo {
|
|
135
154
|
id: number;
|
|
136
155
|
reduce_only: boolean;
|
|
137
156
|
limit_price: number;
|
|
138
157
|
size: number;
|
|
139
158
|
account_id: number;
|
|
159
|
+
sender_tracking_id?: number;
|
|
140
160
|
}
|
|
141
161
|
|
|
142
162
|
export interface HashMap<T> {
|
|
143
163
|
[key: number]: T;
|
|
144
164
|
}
|
|
145
165
|
|
|
146
|
-
export interface Account {
|
|
147
|
-
last_update_id: number;
|
|
148
|
-
update_id: number;
|
|
149
|
-
account_id: number;
|
|
150
|
-
fills: HashMap<number>;
|
|
151
|
-
places: HashMap<OrderInfo>;
|
|
152
|
-
cancels: HashMap<OrderInfo>;
|
|
153
|
-
balances: HashMap<number>;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Query the transactions in the specified L2 block.
|
|
158
|
-
* block_number specifies the block number to query.
|
|
159
|
-
* If not specified, transactions from latest block are returned.
|
|
160
|
-
*/
|
|
161
|
-
export interface BlockQuery {
|
|
162
|
-
block_number?: number;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Response for BlockQuery.
|
|
167
|
-
* block_number specifies the block number being returned.
|
|
168
|
-
* actions are the list of transactions from the block.
|
|
169
|
-
*/
|
|
170
|
-
export interface BlockResponse {
|
|
171
|
-
block_number: number;
|
|
172
|
-
actions: ActionInfo[];
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Response for BlockSummaryQuery.
|
|
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.
|
|
180
|
-
*/
|
|
181
|
-
export interface BlockSummaryResponse {
|
|
182
|
-
block_summary: BlockSummary[];
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Query the action for the specified action id.
|
|
187
|
-
* action_id specifies the action to query.
|
|
188
|
-
*/
|
|
189
|
-
export interface ActionQuery {
|
|
190
|
-
action_id: number;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Response for ActionQuery.
|
|
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.
|
|
198
|
-
*/
|
|
199
166
|
export interface ActionResponse {
|
|
200
|
-
|
|
167
|
+
actionId: number;
|
|
201
168
|
action: proto.Action;
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* Query the recent actions
|
|
206
|
-
* last_n requests last N actions.
|
|
207
|
-
*/
|
|
208
|
-
export interface ActionsQuery {
|
|
209
|
-
last_n: number;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Response for ActionsQuery.
|
|
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.
|
|
217
|
-
*/
|
|
218
|
-
export interface ActionsResponse {
|
|
219
|
-
actions: ActionsExtendedInfo[];
|
|
169
|
+
physicalExecTime: Date;
|
|
220
170
|
}
|
|
221
171
|
|
|
222
172
|
/**
|
|
@@ -231,31 +181,6 @@ export interface BlockSummary {
|
|
|
231
181
|
to_action_id: number;
|
|
232
182
|
}
|
|
233
183
|
|
|
234
|
-
/**
|
|
235
|
-
* Info about the block transaction.
|
|
236
|
-
* action_id is the action identifier.
|
|
237
|
-
* action in protobuf format.
|
|
238
|
-
* exec_timestamp is the execution timestamp.
|
|
239
|
-
*/
|
|
240
|
-
export interface ActionInfo {
|
|
241
|
-
action_id: number;
|
|
242
|
-
action: proto.Action;
|
|
243
|
-
exec_timestamp: number;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Extended info about the block 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.
|
|
252
|
-
*/
|
|
253
|
-
export interface ActionsExtendedInfo {
|
|
254
|
-
block_number?: number;
|
|
255
|
-
action_id: number;
|
|
256
|
-
action: proto.Action;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
184
|
/**
|
|
260
185
|
* Aggregate metrics
|
|
261
186
|
* blocks_total: Total number of L2 blocks.
|
|
@@ -272,54 +197,6 @@ export interface AggregateMetrics {
|
|
|
272
197
|
request_latency_average: number;
|
|
273
198
|
}
|
|
274
199
|
|
|
275
|
-
// The JSON types returned by rollman, that need to be translated to TS format.
|
|
276
|
-
export interface RollmanBlockResponse {
|
|
277
|
-
block_number: number;
|
|
278
|
-
actions: RollmanActionInfo[];
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
export interface RollmanActionResponse {
|
|
282
|
-
block_number?: number;
|
|
283
|
-
action_pb: Uint8Array;
|
|
284
|
-
exec_timestamp: number;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
export interface RollmanActionsResponse {
|
|
288
|
-
actions: RollmanActionExtendedInfo[];
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
export interface RollmanActionInfo {
|
|
292
|
-
action_id: number;
|
|
293
|
-
action_pb: Uint8Array;
|
|
294
|
-
exec_timestamp: number;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
export interface RollmanActionExtendedInfo {
|
|
298
|
-
block_number?: number;
|
|
299
|
-
action_id: number;
|
|
300
|
-
action_pb: Uint8Array;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
export interface MarketsStatsResponse {
|
|
304
|
-
markets: MarketStats[];
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
export interface MarketStats {
|
|
308
|
-
market_id: number;
|
|
309
|
-
index_price: [number, number];
|
|
310
|
-
volume_24h: number;
|
|
311
|
-
high_24h: number;
|
|
312
|
-
low_24h: number;
|
|
313
|
-
perp_stats?: PerpMarketStats;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
export interface PerpMarketStats {
|
|
317
|
-
mark_price?: number;
|
|
318
|
-
funding_rate?: number;
|
|
319
|
-
next_funding_time?: Date;
|
|
320
|
-
open_interest?: number;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
200
|
/**
|
|
324
201
|
* Converts a `FillMode` enum to its corresponding protobuf representation.
|
|
325
202
|
*
|
|
@@ -337,41 +214,6 @@ export function fillModeToProtoFillMode(x: FillMode): proto.FillMode {
|
|
|
337
214
|
throw new Error("Invalid fill mode");
|
|
338
215
|
}
|
|
339
216
|
|
|
340
|
-
/**
|
|
341
|
-
* Response for trades query with pagination support
|
|
342
|
-
*/
|
|
343
|
-
export interface TradesResponse {
|
|
344
|
-
trades: Trade[];
|
|
345
|
-
accountId: number;
|
|
346
|
-
since?: string; // RFC3339 timestamp
|
|
347
|
-
until?: string; // RFC3339 timestamp
|
|
348
|
-
nextPageId?: string;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
/**
|
|
352
|
-
* Query parameters for trades endpoint
|
|
353
|
-
*/
|
|
354
|
-
export interface TradesQuery {
|
|
355
|
-
accountId: number;
|
|
356
|
-
since?: string; // RFC3339 timestamp
|
|
357
|
-
until?: string; // RFC3339 timestamp
|
|
358
|
-
pageId?: string;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
/**
|
|
362
|
-
* Response for user account IDs query
|
|
363
|
-
*/
|
|
364
|
-
export interface UserAccountIdsResponse {
|
|
365
|
-
accountIds: number[];
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
/**
|
|
369
|
-
* Query parameters for user account IDs
|
|
370
|
-
*/
|
|
371
|
-
export interface UserAccountIdsQuery {
|
|
372
|
-
pubkey: string; // secp256k1 public key in hex format
|
|
373
|
-
}
|
|
374
|
-
|
|
375
217
|
/**
|
|
376
218
|
* Orderbook entry representing price and size
|
|
377
219
|
*/
|
|
@@ -380,16 +222,6 @@ export interface OrderbookEntry {
|
|
|
380
222
|
size: number;
|
|
381
223
|
}
|
|
382
224
|
|
|
383
|
-
/**
|
|
384
|
-
* Response for orderbook query
|
|
385
|
-
*/
|
|
386
|
-
export interface OrderbookResponse {
|
|
387
|
-
symbol: string;
|
|
388
|
-
asks: OrderbookEntry[];
|
|
389
|
-
bids: OrderbookEntry[];
|
|
390
|
-
timestamp: number;
|
|
391
|
-
}
|
|
392
|
-
|
|
393
225
|
/**
|
|
394
226
|
* Query parameters for orderbook
|
|
395
227
|
*
|
|
@@ -440,7 +272,7 @@ export interface WebSocketSubscription {
|
|
|
440
272
|
export interface WebSocketTradeUpdate {
|
|
441
273
|
e: WebSocketMessageType.TradeUpdate;
|
|
442
274
|
symbol: string;
|
|
443
|
-
trades:
|
|
275
|
+
trades: StreamTrade[];
|
|
444
276
|
timestamp: number;
|
|
445
277
|
}
|
|
446
278
|
|
|
@@ -472,3 +304,10 @@ export type WebSocketMessage =
|
|
|
472
304
|
| WebSocketTradeUpdate
|
|
473
305
|
| WebSocketDeltaUpdate
|
|
474
306
|
| WebSocketAccountUpdate;
|
|
307
|
+
|
|
308
|
+
export interface SPLTokenInfo {
|
|
309
|
+
mint: string;
|
|
310
|
+
precision: number;
|
|
311
|
+
tokenId: number;
|
|
312
|
+
name: string;
|
|
313
|
+
}
|