@n1xyz/nord-ts 0.1.10 → 0.1.12
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/actions.d.ts +3 -4
- package/dist/actions.js +4 -6
- package/dist/client/Nord.d.ts +28 -3
- package/dist/client/Nord.js +51 -0
- package/dist/client/NordAdmin.js +2 -2
- package/dist/client/NordUser.d.ts +16 -12
- package/dist/client/NordUser.js +52 -39
- package/dist/gen/openapi.d.ts +150 -36
- package/dist/types.d.ts +6 -3
- package/dist/utils.d.ts +5 -1
- package/dist/utils.js +4 -1
- package/package.json +1 -1
package/dist/actions.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { paths } from "./gen/openapi";
|
|
|
4
4
|
import { Client } from "openapi-fetch";
|
|
5
5
|
import { FillMode, Side, QuoteSize } from "./types";
|
|
6
6
|
import { BigIntValue } from "./utils";
|
|
7
|
-
import { PublicKey
|
|
7
|
+
import { PublicKey } from "@solana/web3.js";
|
|
8
8
|
type ReceiptKind = NonNullable<proto.Receipt["kind"]>;
|
|
9
9
|
type ExtractReceiptKind<K extends ReceiptKind["case"]> = Extract<ReceiptKind, {
|
|
10
10
|
case: K;
|
|
@@ -16,7 +16,7 @@ export declare function expectReceiptKind<K extends ReceiptKind["case"]>(receipt
|
|
|
16
16
|
export declare function createAction(currentTimestamp: bigint, nonce: number, kind: proto.Action["kind"]): proto.Action;
|
|
17
17
|
export declare function sendAction(client: Client<paths>, makeSignedMessage: (message: Uint8Array) => Promise<Uint8Array>, action: proto.Action): Promise<proto.Receipt>;
|
|
18
18
|
export declare function prepareAction(action: proto.Action, makeSignedMessage: (message: Uint8Array) => Promise<Uint8Array>): Promise<Uint8Array<ArrayBufferLike>>;
|
|
19
|
-
export declare function createSession(client: Client<paths>,
|
|
19
|
+
export declare function createSession(client: Client<paths>, signMessage: (_: Uint8Array) => Promise<Uint8Array>, currentTimestamp: bigint, nonce: number, params: {
|
|
20
20
|
userPubkey: PublicKey;
|
|
21
21
|
sessionPubkey: PublicKey;
|
|
22
22
|
expiryTimestamp?: bigint;
|
|
@@ -24,9 +24,8 @@ export declare function createSession(client: Client<paths>, signTransaction: (t
|
|
|
24
24
|
actionId: bigint;
|
|
25
25
|
sessionId: bigint;
|
|
26
26
|
}>;
|
|
27
|
-
export declare function revokeSession(client: Client<paths>,
|
|
27
|
+
export declare function revokeSession(client: Client<paths>, signMessage: (_: Uint8Array) => Promise<Uint8Array>, currentTimestamp: bigint, nonce: number, params: {
|
|
28
28
|
sessionId: BigIntValue;
|
|
29
|
-
userPubkey: PublicKey;
|
|
30
29
|
}): Promise<{
|
|
31
30
|
actionId: bigint;
|
|
32
31
|
}>;
|
package/dist/actions.js
CHANGED
|
@@ -70,7 +70,7 @@ export async function prepareAction(action, makeSignedMessage) {
|
|
|
70
70
|
}
|
|
71
71
|
return body;
|
|
72
72
|
}
|
|
73
|
-
export async function createSession(client,
|
|
73
|
+
export async function createSession(client, signMessage, currentTimestamp, nonce, params) {
|
|
74
74
|
let expiry = 0n;
|
|
75
75
|
if (params.expiryTimestamp !== undefined) {
|
|
76
76
|
expiry = params.expiryTimestamp;
|
|
@@ -92,8 +92,7 @@ export async function createSession(client, signTransaction, currentTimestamp, n
|
|
|
92
92
|
...payload,
|
|
93
93
|
...(await signUserPayload({
|
|
94
94
|
payload,
|
|
95
|
-
|
|
96
|
-
signTransaction,
|
|
95
|
+
signMessage,
|
|
97
96
|
})),
|
|
98
97
|
]);
|
|
99
98
|
}, action);
|
|
@@ -107,7 +106,7 @@ export async function createSession(client, signTransaction, currentTimestamp, n
|
|
|
107
106
|
throw new Error(`Unexpected receipt kind ${resp.kind?.case}`);
|
|
108
107
|
}
|
|
109
108
|
}
|
|
110
|
-
export async function revokeSession(client,
|
|
109
|
+
export async function revokeSession(client, signMessage, currentTimestamp, nonce, params) {
|
|
111
110
|
const action = createAction(currentTimestamp, nonce, {
|
|
112
111
|
case: "revokeSession",
|
|
113
112
|
value: create(proto.Action_RevokeSessionSchema, {
|
|
@@ -119,8 +118,7 @@ export async function revokeSession(client, signTransaction, currentTimestamp, n
|
|
|
119
118
|
...payload,
|
|
120
119
|
...(await signUserPayload({
|
|
121
120
|
payload,
|
|
122
|
-
|
|
123
|
-
signTransaction,
|
|
121
|
+
signMessage,
|
|
124
122
|
})),
|
|
125
123
|
]);
|
|
126
124
|
}, action);
|
package/dist/client/Nord.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Connection, PublicKey } from "@solana/web3.js";
|
|
|
3
3
|
import { EventEmitter } from "events";
|
|
4
4
|
import { Client } from "openapi-fetch";
|
|
5
5
|
import type { paths } from "../gen/openapi.ts";
|
|
6
|
-
import { Account, AccountPnlPage,
|
|
6
|
+
import { Account, AccountPnlPage, PagedQuery, ActionResponse, MarketsInfo, Market, MarketStats, NordConfig, OrderbookQuery, OrderbookResponse, FeeTierConfig, Token, TradesResponse, User, AccountTriggerInfo, TriggerHistoryPage, WithdrawalHistoryPage, FeeTierId, AccountFeeTierPage, PageResultStringOrderInfo, PageResultStringTrade, OrderInfoFromApi, TokenStats, FillRole, AdminInfo, AccountVolumeInfo, GetAccountVolumeQuery, PreviousMarketPrice } from "../types";
|
|
7
7
|
import { NordWebSocketClient } from "../websocket/index";
|
|
8
8
|
import { OrderbookSubscription, TradeSubscription } from "../websocket/Subscriber";
|
|
9
9
|
/**
|
|
@@ -302,7 +302,7 @@ export declare class Nord {
|
|
|
302
302
|
* @returns Page of PnL entries ordered from latest to oldest
|
|
303
303
|
* @throws {NordError} If the request fails
|
|
304
304
|
*/
|
|
305
|
-
getAccountPnl(accountId: number, { since, until, startInclusive, pageSize, }?: Readonly<Partial<
|
|
305
|
+
getAccountPnl(accountId: number, { since, until, startInclusive, pageSize, }?: Readonly<Partial<PagedQuery>>): Promise<AccountPnlPage>;
|
|
306
306
|
/**
|
|
307
307
|
* Get market statistics (alias for marketsStats for backward compatibility)
|
|
308
308
|
*
|
|
@@ -328,6 +328,18 @@ export declare class Nord {
|
|
|
328
328
|
feeKind: FillRole;
|
|
329
329
|
accountId: number;
|
|
330
330
|
}>): Promise<number>;
|
|
331
|
+
/**
|
|
332
|
+
* Fetch the latest available market price at or before the given timestamp.
|
|
333
|
+
*
|
|
334
|
+
* @param marketId - Market identifier
|
|
335
|
+
* @param atOrBefore - RFC3339 timestamp to look back from (returns the latest price at or before this time)
|
|
336
|
+
* @returns Previous market price record; price is `null` if no trades exist at or before `at`
|
|
337
|
+
* @throws {NordError} If the request fails
|
|
338
|
+
*/
|
|
339
|
+
getPrevMarketPrice({ marketId, atOrBefore, }: Readonly<{
|
|
340
|
+
marketId: number;
|
|
341
|
+
atOrBefore: string;
|
|
342
|
+
}>): Promise<PreviousMarketPrice>;
|
|
331
343
|
/**
|
|
332
344
|
* Fetch token statistics such as index price and oracle metadata.
|
|
333
345
|
*
|
|
@@ -384,7 +396,20 @@ export declare class Nord {
|
|
|
384
396
|
* @param startInclusive - Pagination cursor to resume from
|
|
385
397
|
* @throws {NordError} If no account can be resolved or the request fails.
|
|
386
398
|
*/
|
|
387
|
-
getAccountTriggerHistory({ accountId, since, until, pageSize, startInclusive, }: Readonly<
|
|
399
|
+
getAccountTriggerHistory({ accountId, since, until, pageSize, startInclusive, }: Readonly<PagedQuery & {
|
|
388
400
|
accountId?: number;
|
|
389
401
|
}>): Promise<TriggerHistoryPage>;
|
|
402
|
+
/**
|
|
403
|
+
* Fetch withdrawal history for an account.
|
|
404
|
+
*
|
|
405
|
+
* @param accountId - Account identifier owning the withdrawals
|
|
406
|
+
* @param since - RFC3339 timestamp to start from (inclusive)
|
|
407
|
+
* @param until - RFC3339 timestamp to end at (exclusive)
|
|
408
|
+
* @param pageSize - Maximum number of entries to return
|
|
409
|
+
* @param startInclusive - Pagination cursor to resume from
|
|
410
|
+
* @throws {NordError} If no account can be resolved or the request fails.
|
|
411
|
+
*/
|
|
412
|
+
getAccountWithdrawalHistory({ accountId, since, until, pageSize, startInclusive, }: Readonly<PagedQuery & {
|
|
413
|
+
accountId?: number;
|
|
414
|
+
}>): Promise<WithdrawalHistoryPage>;
|
|
390
415
|
}
|
package/dist/client/Nord.js
CHANGED
|
@@ -592,6 +592,24 @@ export class Nord {
|
|
|
592
592
|
},
|
|
593
593
|
});
|
|
594
594
|
}
|
|
595
|
+
/**
|
|
596
|
+
* Fetch the latest available market price at or before the given timestamp.
|
|
597
|
+
*
|
|
598
|
+
* @param marketId - Market identifier
|
|
599
|
+
* @param atOrBefore - RFC3339 timestamp to look back from (returns the latest price at or before this time)
|
|
600
|
+
* @returns Previous market price record; price is `null` if no trades exist at or before `at`
|
|
601
|
+
* @throws {NordError} If the request fails
|
|
602
|
+
*/
|
|
603
|
+
async getPrevMarketPrice({ marketId, atOrBefore, }) {
|
|
604
|
+
return await this.GET("/market/{market_id}/price/prev", {
|
|
605
|
+
params: {
|
|
606
|
+
path: { market_id: marketId },
|
|
607
|
+
query: {
|
|
608
|
+
atOrBefore,
|
|
609
|
+
},
|
|
610
|
+
},
|
|
611
|
+
});
|
|
612
|
+
}
|
|
595
613
|
/**
|
|
596
614
|
* Fetch token statistics such as index price and oracle metadata.
|
|
597
615
|
*
|
|
@@ -705,4 +723,37 @@ export class Nord {
|
|
|
705
723
|
});
|
|
706
724
|
}
|
|
707
725
|
}
|
|
726
|
+
/**
|
|
727
|
+
* Fetch withdrawal history for an account.
|
|
728
|
+
*
|
|
729
|
+
* @param accountId - Account identifier owning the withdrawals
|
|
730
|
+
* @param since - RFC3339 timestamp to start from (inclusive)
|
|
731
|
+
* @param until - RFC3339 timestamp to end at (exclusive)
|
|
732
|
+
* @param pageSize - Maximum number of entries to return
|
|
733
|
+
* @param startInclusive - Pagination cursor to resume from
|
|
734
|
+
* @throws {NordError} If no account can be resolved or the request fails.
|
|
735
|
+
*/
|
|
736
|
+
async getAccountWithdrawalHistory({ accountId, since, until, pageSize, startInclusive, }) {
|
|
737
|
+
if (accountId == null) {
|
|
738
|
+
throw new NordError("Account ID is undefined. Make sure to call updateAccountId() before requesting withdrawal history.");
|
|
739
|
+
}
|
|
740
|
+
try {
|
|
741
|
+
return await this.GET("/account/{account_id}/history/withdrawal", {
|
|
742
|
+
params: {
|
|
743
|
+
path: { account_id: accountId },
|
|
744
|
+
query: {
|
|
745
|
+
since,
|
|
746
|
+
until,
|
|
747
|
+
pageSize,
|
|
748
|
+
startInclusive,
|
|
749
|
+
},
|
|
750
|
+
},
|
|
751
|
+
});
|
|
752
|
+
}
|
|
753
|
+
catch (error) {
|
|
754
|
+
throw new NordError("Failed to fetch account withdrawal history", {
|
|
755
|
+
cause: error,
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
}
|
|
708
759
|
}
|
package/dist/client/NordAdmin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { create } from "@bufbuild/protobuf";
|
|
2
2
|
import * as proto from "../gen/nord_pb";
|
|
3
|
-
import { decodeHex,
|
|
3
|
+
import { decodeHex, signAdminPayload } from "../utils";
|
|
4
4
|
import { createAction, sendAction, expectReceiptKind } from "../actions";
|
|
5
5
|
import { NordError } from "../error";
|
|
6
6
|
// NOTE: keep in sync with `acl.rs`.
|
|
@@ -49,7 +49,7 @@ export class NordAdmin {
|
|
|
49
49
|
const timestamp = await this.nord.getTimestamp();
|
|
50
50
|
const action = createAction(timestamp, 0, kind);
|
|
51
51
|
return sendAction(this.nord.httpClient, async (xs) => {
|
|
52
|
-
const signature = await
|
|
52
|
+
const signature = await signAdminPayload({
|
|
53
53
|
payload: xs,
|
|
54
54
|
user: this.admin,
|
|
55
55
|
signTransaction: this.signFn,
|
|
@@ -33,9 +33,10 @@ export interface UserAtomicSubaction {
|
|
|
33
33
|
* User class for interacting with the Nord protocol
|
|
34
34
|
*/
|
|
35
35
|
export declare class NordUser {
|
|
36
|
+
private readonly signSessionMessage;
|
|
37
|
+
private readonly signMessage;
|
|
38
|
+
private readonly signTransaction;
|
|
36
39
|
readonly nord: Nord;
|
|
37
|
-
readonly sessionSignFn: (message: Uint8Array) => Promise<Uint8Array>;
|
|
38
|
-
readonly transactionSignFn: (tx: Transaction) => Promise<Transaction>;
|
|
39
40
|
sessionId?: bigint;
|
|
40
41
|
sessionPubKey: PublicKey;
|
|
41
42
|
publicKey: PublicKey;
|
|
@@ -82,25 +83,28 @@ export declare class NordUser {
|
|
|
82
83
|
accountIds?: number[];
|
|
83
84
|
/** SPL token information */
|
|
84
85
|
splTokenInfos: SPLTokenInfo[];
|
|
86
|
+
private constructor();
|
|
85
87
|
/**
|
|
86
88
|
* Create a new NordUser instance
|
|
87
89
|
*
|
|
88
90
|
* @param nord - Nord client instance
|
|
89
|
-
* @param
|
|
90
|
-
* @param transactionSignFn - Function to sign transactions with the user's wallet (optional)
|
|
91
|
-
* @param sessionId - Existing session identifier
|
|
91
|
+
* @param walletPubkey - Wallet public key
|
|
92
92
|
* @param sessionPubKey - Session public key
|
|
93
|
-
* @param
|
|
93
|
+
* @param sessionId - Existing session identifier, if known. Otherwise, pass nothing and call `refreshSession` to fetch a new session.
|
|
94
|
+
* @param signMessageFn - Function to sign the given UTF-8 string with the user's wallet. Typically just your wallet's `signMessage` method.
|
|
95
|
+
* @param signTransactionFn - Function to sign transactions with the user's wallet. Typically just your wallet's `signTransaction` method.
|
|
96
|
+
* @param signSessionFn - Function to sign messages with the provided `sessionPubKey`
|
|
94
97
|
* @throws {NordError} If required parameters are missing
|
|
95
98
|
*/
|
|
96
|
-
|
|
99
|
+
static new({ nord, walletPubkey, sessionPubkey, sessionId, signMessageFn, signTransactionFn, signSessionFn, }: Readonly<{
|
|
97
100
|
nord: Nord;
|
|
98
|
-
|
|
99
|
-
|
|
101
|
+
signSessionFn: (rawMessage: Uint8Array) => Promise<Uint8Array>;
|
|
102
|
+
signMessageFn: (utf8Message: Uint8Array) => Promise<Uint8Array>;
|
|
103
|
+
signTransactionFn: (tx: Transaction) => Promise<Transaction>;
|
|
100
104
|
sessionId?: bigint;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}>)
|
|
105
|
+
sessionPubkey: Uint8Array;
|
|
106
|
+
walletPubkey: PublicKey;
|
|
107
|
+
}>): Promise<NordUser>;
|
|
104
108
|
/**
|
|
105
109
|
* Create a NordUser from a private key
|
|
106
110
|
*
|
package/dist/client/NordUser.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ASSOCIATED_TOKEN_PROGRAM_ID, getAssociatedTokenAddress, TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, } from "@solana/spl-token";
|
|
2
|
-
import { PublicKey, Transaction } from "@solana/web3.js";
|
|
2
|
+
import { PublicKey, Keypair, Transaction } from "@solana/web3.js";
|
|
3
3
|
import * as ed from "@noble/ed25519";
|
|
4
4
|
import { floatToScaledBigIntLossy } from "@n1xyz/proton";
|
|
5
5
|
import { Side, TriggerKind, fillModeToProtoFillMode, } from "../types";
|
|
@@ -12,9 +12,10 @@ import { NordError } from "../error";
|
|
|
12
12
|
* User class for interacting with the Nord protocol
|
|
13
13
|
*/
|
|
14
14
|
export class NordUser {
|
|
15
|
+
signSessionMessage;
|
|
16
|
+
signMessage;
|
|
17
|
+
signTransaction;
|
|
15
18
|
nord;
|
|
16
|
-
sessionSignFn;
|
|
17
|
-
transactionSignFn;
|
|
18
19
|
sessionId;
|
|
19
20
|
sessionPubKey;
|
|
20
21
|
publicKey;
|
|
@@ -30,24 +31,14 @@ export class NordUser {
|
|
|
30
31
|
accountIds;
|
|
31
32
|
/** SPL token information */
|
|
32
33
|
splTokenInfos = [];
|
|
33
|
-
|
|
34
|
-
* Create a new NordUser instance
|
|
35
|
-
*
|
|
36
|
-
* @param nord - Nord client instance
|
|
37
|
-
* @param sessionSignFn - Function to sign messages with the user's session key
|
|
38
|
-
* @param transactionSignFn - Function to sign transactions with the user's wallet (optional)
|
|
39
|
-
* @param sessionId - Existing session identifier
|
|
40
|
-
* @param sessionPubKey - Session public key
|
|
41
|
-
* @param publicKey - Wallet public key
|
|
42
|
-
* @throws {NordError} If required parameters are missing
|
|
43
|
-
*/
|
|
44
|
-
constructor({ nord, sessionSignFn, transactionSignFn, sessionId, sessionPubKey, publicKey, }) {
|
|
34
|
+
constructor({ nord, walletPubkey, sessionPubkey, sessionId, signMessageFn, signTransactionFn, signSessionFn, }) {
|
|
45
35
|
this.nord = nord;
|
|
46
|
-
this.
|
|
47
|
-
this.
|
|
36
|
+
this.signSessionMessage = signSessionFn;
|
|
37
|
+
this.signMessage = signMessageFn;
|
|
38
|
+
this.signTransaction = signTransactionFn;
|
|
48
39
|
this.sessionId = sessionId;
|
|
49
|
-
this.sessionPubKey = new PublicKey(
|
|
50
|
-
this.publicKey =
|
|
40
|
+
this.sessionPubKey = new PublicKey(sessionPubkey);
|
|
41
|
+
this.publicKey = walletPubkey;
|
|
51
42
|
// Convert tokens from info endpoint to SPLTokenInfo
|
|
52
43
|
if (this.nord.tokens && this.nord.tokens.length > 0) {
|
|
53
44
|
this.splTokenInfos = this.nord.tokens.map((token) => ({
|
|
@@ -58,6 +49,29 @@ export class NordUser {
|
|
|
58
49
|
}));
|
|
59
50
|
}
|
|
60
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Create a new NordUser instance
|
|
54
|
+
*
|
|
55
|
+
* @param nord - Nord client instance
|
|
56
|
+
* @param walletPubkey - Wallet public key
|
|
57
|
+
* @param sessionPubKey - Session public key
|
|
58
|
+
* @param sessionId - Existing session identifier, if known. Otherwise, pass nothing and call `refreshSession` to fetch a new session.
|
|
59
|
+
* @param signMessageFn - Function to sign the given UTF-8 string with the user's wallet. Typically just your wallet's `signMessage` method.
|
|
60
|
+
* @param signTransactionFn - Function to sign transactions with the user's wallet. Typically just your wallet's `signTransaction` method.
|
|
61
|
+
* @param signSessionFn - Function to sign messages with the provided `sessionPubKey`
|
|
62
|
+
* @throws {NordError} If required parameters are missing
|
|
63
|
+
*/
|
|
64
|
+
static async new({ nord, walletPubkey, sessionPubkey, sessionId, signMessageFn, signTransactionFn, signSessionFn, }) {
|
|
65
|
+
return new NordUser({
|
|
66
|
+
nord,
|
|
67
|
+
walletPubkey,
|
|
68
|
+
sessionPubkey,
|
|
69
|
+
sessionId,
|
|
70
|
+
signMessageFn,
|
|
71
|
+
signTransactionFn,
|
|
72
|
+
signSessionFn,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
61
75
|
/**
|
|
62
76
|
* Create a NordUser from a private key
|
|
63
77
|
*
|
|
@@ -68,22 +82,22 @@ export class NordUser {
|
|
|
68
82
|
*/
|
|
69
83
|
static fromPrivateKey(nord, privateKey) {
|
|
70
84
|
try {
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
const sessionSignFn = async (message) => {
|
|
74
|
-
// Use ed25519 to sign the message
|
|
75
|
-
return ed.sign(message, keypair.secretKey.slice(0, 32));
|
|
76
|
-
};
|
|
77
|
-
const transactionSignFn = async (tx) => {
|
|
78
|
-
tx.sign(keypair);
|
|
79
|
-
return tx;
|
|
80
|
-
};
|
|
85
|
+
const wallet = keypairFromPrivateKey(privateKey);
|
|
86
|
+
const sessionKey = Keypair.generate();
|
|
81
87
|
return new NordUser({
|
|
82
88
|
nord,
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
89
|
+
walletPubkey: wallet.publicKey,
|
|
90
|
+
sessionPubkey: sessionKey.publicKey.toBytes(),
|
|
91
|
+
signTransactionFn: async (tx) => {
|
|
92
|
+
tx.sign(wallet);
|
|
93
|
+
return tx;
|
|
94
|
+
},
|
|
95
|
+
signMessageFn: async (xs) => {
|
|
96
|
+
return ed.sign(xs, wallet.secretKey);
|
|
97
|
+
},
|
|
98
|
+
signSessionFn: async (xs) => {
|
|
99
|
+
return ed.sign(xs, sessionKey.secretKey);
|
|
100
|
+
},
|
|
87
101
|
});
|
|
88
102
|
}
|
|
89
103
|
catch (error) {
|
|
@@ -171,7 +185,7 @@ export class NordUser {
|
|
|
171
185
|
tx.add(ix);
|
|
172
186
|
tx.recentBlockhash = blockhash;
|
|
173
187
|
tx.feePayer = payer;
|
|
174
|
-
const signedTx = await this.
|
|
188
|
+
const signedTx = await this.signTransaction(tx);
|
|
175
189
|
signedTx.partialSign(extraSigner);
|
|
176
190
|
const signature = await this.nord.solanaConnection.sendRawTransaction(signedTx.serialize(), sendOptions);
|
|
177
191
|
return {
|
|
@@ -193,7 +207,7 @@ export class NordUser {
|
|
|
193
207
|
}
|
|
194
208
|
async submitSessionAction(kind) {
|
|
195
209
|
return this.submitSignedAction(kind, async (message) => {
|
|
196
|
-
const signature = await this.
|
|
210
|
+
const signature = await this.signSessionMessage(message);
|
|
197
211
|
const signed = new Uint8Array(message.length + signature.length);
|
|
198
212
|
signed.set(message);
|
|
199
213
|
signed.set(signature, message.length);
|
|
@@ -261,7 +275,7 @@ export class NordUser {
|
|
|
261
275
|
* @throws {NordError} If the operation fails
|
|
262
276
|
*/
|
|
263
277
|
async refreshSession() {
|
|
264
|
-
const result = await createSession(this.nord.httpClient, this.
|
|
278
|
+
const result = await createSession(this.nord.httpClient, this.signMessage, await this.nord.getTimestamp(), this.getNonce(), {
|
|
265
279
|
userPubkey: this.publicKey,
|
|
266
280
|
sessionPubkey: this.sessionPubKey,
|
|
267
281
|
});
|
|
@@ -275,8 +289,7 @@ export class NordUser {
|
|
|
275
289
|
*/
|
|
276
290
|
async revokeSession(sessionId) {
|
|
277
291
|
try {
|
|
278
|
-
await revokeSession(this.nord.httpClient, this.
|
|
279
|
-
userPubkey: this.publicKey,
|
|
292
|
+
await revokeSession(this.nord.httpClient, this.signMessage, await this.nord.getTimestamp(), this.getNonce(), {
|
|
280
293
|
sessionId,
|
|
281
294
|
});
|
|
282
295
|
}
|
|
@@ -600,7 +613,7 @@ export class NordUser {
|
|
|
600
613
|
orderId: act.orderId,
|
|
601
614
|
};
|
|
602
615
|
});
|
|
603
|
-
const result = await atomic(this.nord.httpClient, this.
|
|
616
|
+
const result = await atomic(this.nord.httpClient, this.signSessionMessage, await this.nord.getTimestamp(), this.getNonce(), {
|
|
604
617
|
sessionId: optExpect(this.sessionId, "No session"),
|
|
605
618
|
accountId: accountId,
|
|
606
619
|
actions: apiActions,
|
package/dist/gen/openapi.d.ts
CHANGED
|
@@ -770,7 +770,7 @@ export interface paths {
|
|
|
770
770
|
[name: string]: unknown;
|
|
771
771
|
};
|
|
772
772
|
content: {
|
|
773
|
-
"application/json": components["schemas"]["
|
|
773
|
+
"application/json": components["schemas"]["PageResult_for_uint64_and_Trigger"];
|
|
774
774
|
};
|
|
775
775
|
};
|
|
776
776
|
};
|
|
@@ -1320,6 +1320,108 @@ export interface paths {
|
|
|
1320
1320
|
patch?: never;
|
|
1321
1321
|
trace?: never;
|
|
1322
1322
|
};
|
|
1323
|
+
"/market/{market_id}/price/prev": {
|
|
1324
|
+
parameters: {
|
|
1325
|
+
query?: never;
|
|
1326
|
+
header?: never;
|
|
1327
|
+
path?: never;
|
|
1328
|
+
cookie?: never;
|
|
1329
|
+
};
|
|
1330
|
+
/** @description Fetch the latest price for a market at or before a timestamp. */
|
|
1331
|
+
get: {
|
|
1332
|
+
parameters: {
|
|
1333
|
+
query: {
|
|
1334
|
+
atOrBefore: string;
|
|
1335
|
+
};
|
|
1336
|
+
header?: never;
|
|
1337
|
+
path: {
|
|
1338
|
+
market_id: number;
|
|
1339
|
+
};
|
|
1340
|
+
cookie?: never;
|
|
1341
|
+
};
|
|
1342
|
+
requestBody?: never;
|
|
1343
|
+
responses: {
|
|
1344
|
+
200: {
|
|
1345
|
+
headers: {
|
|
1346
|
+
[name: string]: unknown;
|
|
1347
|
+
};
|
|
1348
|
+
content: {
|
|
1349
|
+
"application/json": components["schemas"]["PreviousMarketPrice"];
|
|
1350
|
+
};
|
|
1351
|
+
};
|
|
1352
|
+
404: {
|
|
1353
|
+
headers: {
|
|
1354
|
+
[name: string]: unknown;
|
|
1355
|
+
};
|
|
1356
|
+
content: {
|
|
1357
|
+
"application/json": components["schemas"]["MarketNotFound"];
|
|
1358
|
+
};
|
|
1359
|
+
};
|
|
1360
|
+
};
|
|
1361
|
+
};
|
|
1362
|
+
put?: never;
|
|
1363
|
+
post?: never;
|
|
1364
|
+
delete?: never;
|
|
1365
|
+
options?: never;
|
|
1366
|
+
head?: never;
|
|
1367
|
+
patch?: never;
|
|
1368
|
+
trace?: never;
|
|
1369
|
+
};
|
|
1370
|
+
"/account/{account_id}/history/withdrawal": {
|
|
1371
|
+
parameters: {
|
|
1372
|
+
query?: never;
|
|
1373
|
+
header?: never;
|
|
1374
|
+
path?: never;
|
|
1375
|
+
cookie?: never;
|
|
1376
|
+
};
|
|
1377
|
+
/** @description Fetch full history of withdrawals for an account. */
|
|
1378
|
+
get: {
|
|
1379
|
+
parameters: {
|
|
1380
|
+
query?: {
|
|
1381
|
+
/** @description start with this timestamp (RFC3339); defaults to UNIX epoch start */
|
|
1382
|
+
since?: string;
|
|
1383
|
+
/** @description end with this timestamp (RFC3339); defaults to current date-time */
|
|
1384
|
+
until?: string;
|
|
1385
|
+
/** @description fetch results starting with this page; query starts with first entry if page isn't specified */
|
|
1386
|
+
startInclusive?: number | null;
|
|
1387
|
+
/** @description Query returns up to 50 trades in one go. */
|
|
1388
|
+
pageSize?: number | null;
|
|
1389
|
+
};
|
|
1390
|
+
header?: never;
|
|
1391
|
+
path: {
|
|
1392
|
+
/** @description Account ID for which to fetch withdrawal history. */
|
|
1393
|
+
account_id: number;
|
|
1394
|
+
};
|
|
1395
|
+
cookie?: never;
|
|
1396
|
+
};
|
|
1397
|
+
requestBody?: never;
|
|
1398
|
+
responses: {
|
|
1399
|
+
200: {
|
|
1400
|
+
headers: {
|
|
1401
|
+
[name: string]: unknown;
|
|
1402
|
+
};
|
|
1403
|
+
content: {
|
|
1404
|
+
"application/json": components["schemas"]["PageResult_for_uint64_and_Withdrawal"];
|
|
1405
|
+
};
|
|
1406
|
+
};
|
|
1407
|
+
404: {
|
|
1408
|
+
headers: {
|
|
1409
|
+
[name: string]: unknown;
|
|
1410
|
+
};
|
|
1411
|
+
content: {
|
|
1412
|
+
"application/json": components["schemas"]["UserNotFound"];
|
|
1413
|
+
};
|
|
1414
|
+
};
|
|
1415
|
+
};
|
|
1416
|
+
};
|
|
1417
|
+
put?: never;
|
|
1418
|
+
post?: never;
|
|
1419
|
+
delete?: never;
|
|
1420
|
+
options?: never;
|
|
1421
|
+
head?: never;
|
|
1422
|
+
patch?: never;
|
|
1423
|
+
trace?: never;
|
|
1424
|
+
};
|
|
1323
1425
|
"/tv": {
|
|
1324
1426
|
parameters: {
|
|
1325
1427
|
query?: never;
|
|
@@ -2331,7 +2433,9 @@ export interface components {
|
|
|
2331
2433
|
/** Format: double */
|
|
2332
2434
|
low24h: number;
|
|
2333
2435
|
/** Format: double */
|
|
2334
|
-
|
|
2436
|
+
close24h: number;
|
|
2437
|
+
/** Format: double */
|
|
2438
|
+
prevClose24h?: number | null;
|
|
2335
2439
|
perpStats?: components["schemas"]["PerpMarketStats"] | null;
|
|
2336
2440
|
};
|
|
2337
2441
|
PerpMarketStats: {
|
|
@@ -2529,7 +2633,7 @@ export interface components {
|
|
|
2529
2633
|
/** @description See `bankruptcy` in MARKETS.md. In general happens if account does not have enough weighted tokens to covert his debt and negative PnL. */
|
|
2530
2634
|
bankruptcy: boolean;
|
|
2531
2635
|
};
|
|
2532
|
-
|
|
2636
|
+
PagedQuery: {
|
|
2533
2637
|
/**
|
|
2534
2638
|
* @description start with this timestamp (RFC3339); defaults to UNIX epoch start
|
|
2535
2639
|
* @default null
|
|
@@ -2570,45 +2674,22 @@ export interface components {
|
|
|
2570
2674
|
/** Format: double */
|
|
2571
2675
|
pnl: number;
|
|
2572
2676
|
};
|
|
2573
|
-
|
|
2574
|
-
/**
|
|
2575
|
-
* @description start with this timestamp (RFC3339); defaults to UNIX epoch start
|
|
2576
|
-
* @default null
|
|
2577
|
-
*/
|
|
2578
|
-
since: string;
|
|
2579
|
-
/**
|
|
2580
|
-
* @description end with this timestamp (RFC3339); defaults to current date-time
|
|
2581
|
-
* @default null
|
|
2582
|
-
*/
|
|
2583
|
-
until: string;
|
|
2584
|
-
/**
|
|
2585
|
-
* Format: uint64
|
|
2586
|
-
* @description fetch results starting with this page; query starts with first entry if page isn't specified
|
|
2587
|
-
*/
|
|
2588
|
-
startInclusive?: number | null;
|
|
2589
|
-
/**
|
|
2590
|
-
* Format: uint8
|
|
2591
|
-
* @description Query returns up to 50 trades in one go.
|
|
2592
|
-
* @default null
|
|
2593
|
-
*/
|
|
2594
|
-
pageSize: number | null;
|
|
2595
|
-
};
|
|
2596
|
-
PageResult_for_uint64_and_HistoryTriggerInfo: {
|
|
2677
|
+
PageResult_for_uint64_and_Trigger: {
|
|
2597
2678
|
/** @description Set of items for requested by query. */
|
|
2598
|
-
items: components["schemas"]["
|
|
2679
|
+
items: components["schemas"]["Trigger"][];
|
|
2599
2680
|
/**
|
|
2600
2681
|
* Format: uint64
|
|
2601
2682
|
* @description If request contains more data, this is the id is set with which next request should be performed to get next page. If no more data, then it is undefined.
|
|
2602
2683
|
*/
|
|
2603
2684
|
nextStartInclusive?: number | null;
|
|
2604
2685
|
};
|
|
2605
|
-
|
|
2686
|
+
Trigger: {
|
|
2606
2687
|
/** Format: uint32 */
|
|
2607
2688
|
accountId: number;
|
|
2608
2689
|
/** Format: uint32 */
|
|
2609
2690
|
marketId: number;
|
|
2610
|
-
|
|
2611
|
-
|
|
2691
|
+
triggerPrice: components["schemas"]["PositivePriceMantissa"];
|
|
2692
|
+
limitPrice?: components["schemas"]["PositivePriceMantissa"] | null;
|
|
2612
2693
|
side: components["schemas"]["Side"];
|
|
2613
2694
|
kind: components["schemas"]["TriggerKind"];
|
|
2614
2695
|
status: components["schemas"]["TriggerStatus"];
|
|
@@ -2619,6 +2700,11 @@ export interface components {
|
|
|
2619
2700
|
createdAt: string;
|
|
2620
2701
|
finalizedAt: string;
|
|
2621
2702
|
};
|
|
2703
|
+
/**
|
|
2704
|
+
* Format: uint64
|
|
2705
|
+
* @description 63 bit integer, which is always positive
|
|
2706
|
+
*/
|
|
2707
|
+
PositivePriceMantissa: number;
|
|
2622
2708
|
/** @enum {string} */
|
|
2623
2709
|
TriggerKind: "stopLoss" | "takeProfit";
|
|
2624
2710
|
/** @enum {string} */
|
|
@@ -2640,11 +2726,6 @@ export interface components {
|
|
|
2640
2726
|
trigger: components["schemas"]["PositivePriceMantissa"];
|
|
2641
2727
|
settlement?: components["schemas"]["PositivePriceMantissa"] | null;
|
|
2642
2728
|
};
|
|
2643
|
-
/**
|
|
2644
|
-
* Format: uint64
|
|
2645
|
-
* @description 63 bit integer, which is always positive
|
|
2646
|
-
*/
|
|
2647
|
-
PositivePriceMantissa: number;
|
|
2648
2729
|
OrderNotFound: null;
|
|
2649
2730
|
PageResult_for_String_and_Trade: {
|
|
2650
2731
|
/** @description Set of items for requested by query. */
|
|
@@ -2805,6 +2886,39 @@ export interface components {
|
|
|
2805
2886
|
/** Format: double */
|
|
2806
2887
|
volume: number;
|
|
2807
2888
|
};
|
|
2889
|
+
GetPrevMarketPriceQuery: {
|
|
2890
|
+
atOrBefore: string;
|
|
2891
|
+
};
|
|
2892
|
+
PreviousMarketPrice: {
|
|
2893
|
+
/** Format: uint32 */
|
|
2894
|
+
marketId: number;
|
|
2895
|
+
/** Format: double */
|
|
2896
|
+
price?: number | null;
|
|
2897
|
+
};
|
|
2898
|
+
PageResult_for_uint64_and_Withdrawal: {
|
|
2899
|
+
/** @description Set of items for requested by query. */
|
|
2900
|
+
items: components["schemas"]["Withdrawal"][];
|
|
2901
|
+
/**
|
|
2902
|
+
* Format: uint64
|
|
2903
|
+
* @description If request contains more data, this is the id is set with which next request should be performed to get next page. If no more data, then it is undefined.
|
|
2904
|
+
*/
|
|
2905
|
+
nextStartInclusive?: number | null;
|
|
2906
|
+
};
|
|
2907
|
+
Withdrawal: {
|
|
2908
|
+
time: string;
|
|
2909
|
+
/** Format: uint64 */
|
|
2910
|
+
actionId: number;
|
|
2911
|
+
/** Format: uint32 */
|
|
2912
|
+
accountId: number;
|
|
2913
|
+
/** Format: uint32 */
|
|
2914
|
+
tokenId: number;
|
|
2915
|
+
/** Format: uint64 */
|
|
2916
|
+
amount: number;
|
|
2917
|
+
/** Format: int64 */
|
|
2918
|
+
balance: number;
|
|
2919
|
+
/** Format: int64 */
|
|
2920
|
+
fee: number;
|
|
2921
|
+
};
|
|
2808
2922
|
/** @description TV config query response https://www.tradingview.com/charting-library-docs/latest/connecting_data/UDF/#data-feed-configuration-data */
|
|
2809
2923
|
TvConfigResponse: {
|
|
2810
2924
|
supported_resolutions: components["schemas"]["Resolution"][];
|
package/dist/types.d.ts
CHANGED
|
@@ -59,12 +59,12 @@ export type SideFromApi = components["schemas"]["Side"];
|
|
|
59
59
|
export type FillModeFromApi = components["schemas"]["FillMode"];
|
|
60
60
|
export type PlacementOrigin = components["schemas"]["PlacementOrigin"];
|
|
61
61
|
export type FinalizationReason = components["schemas"]["FinalizationReason"];
|
|
62
|
-
export type
|
|
62
|
+
export type PagedQuery = components["schemas"]["PagedQuery"];
|
|
63
63
|
export type AccountPnl = components["schemas"]["AccountPnl"];
|
|
64
64
|
export type AccountPnlPage = components["schemas"]["PageResult_for_uint64_and_AccountPnl"];
|
|
65
65
|
export type AccountTriggerInfo = components["schemas"]["AccountTriggerInfo"];
|
|
66
|
-
export type TriggerHistoryPage = components["schemas"]["
|
|
67
|
-
export type
|
|
66
|
+
export type TriggerHistoryPage = components["schemas"]["PageResult_for_uint64_and_Trigger"];
|
|
67
|
+
export type WithdrawalHistoryPage = components["schemas"]["PageResult_for_uint64_and_Withdrawal"];
|
|
68
68
|
export type FeeTierConfig = components["schemas"]["FeeTierConfig"];
|
|
69
69
|
export type FeeTierId = components["schemas"]["FeeTierId"];
|
|
70
70
|
export type TokenStats = components["schemas"]["TokenStats"];
|
|
@@ -73,6 +73,9 @@ export type AccountFeeTierPage = components["schemas"]["PageResult_for_uint32_an
|
|
|
73
73
|
export type AdminInfo = components["schemas"]["AdminInfo"];
|
|
74
74
|
export type GetAccountVolumeQuery = components["schemas"]["GetAccountVolumeQuery"];
|
|
75
75
|
export type AccountVolumeInfo = components["schemas"]["AccountVolumeInfo"];
|
|
76
|
+
export type GetPrevMarketPriceQuery = components["schemas"]["GetPrevMarketPriceQuery"];
|
|
77
|
+
export type PreviousMarketPrice = components["schemas"]["PreviousMarketPrice"];
|
|
78
|
+
export type WithdrawalInfo = components["schemas"]["Withdrawal"];
|
|
76
79
|
/**
|
|
77
80
|
* Configuration options for the Nord client
|
|
78
81
|
*/
|
package/dist/utils.d.ts
CHANGED
|
@@ -75,8 +75,12 @@ export declare function decodeHex(value: string): Uint8Array;
|
|
|
75
75
|
export declare function findMarket(markets: Market[], marketId: number): Market;
|
|
76
76
|
export declare function findToken(tokens: Token[], tokenId: number): Token;
|
|
77
77
|
export declare function keypairFromPrivateKey(privateKey: string | Uint8Array): Keypair;
|
|
78
|
-
export declare function
|
|
78
|
+
export declare function signAdminPayload({ payload, user, signTransaction, }: Readonly<{
|
|
79
79
|
payload: Uint8Array;
|
|
80
80
|
user: solana.PublicKey;
|
|
81
81
|
signTransaction: (tx: solana.Transaction) => Promise<solana.Transaction>;
|
|
82
82
|
}>): Promise<Uint8Array>;
|
|
83
|
+
export declare function signUserPayload({ payload, signMessage, }: Readonly<{
|
|
84
|
+
payload: Uint8Array;
|
|
85
|
+
signMessage: (message: Uint8Array) => Promise<Uint8Array>;
|
|
86
|
+
}>): Promise<Uint8Array>;
|
package/dist/utils.js
CHANGED
|
@@ -167,7 +167,7 @@ export function keypairFromPrivateKey(privateKey) {
|
|
|
167
167
|
}
|
|
168
168
|
return Keypair.fromSecretKey(privateKey);
|
|
169
169
|
}
|
|
170
|
-
export async function
|
|
170
|
+
export async function signAdminPayload({ payload, user, signTransaction, }) {
|
|
171
171
|
const tx = new solana.Transaction({
|
|
172
172
|
blockhash: bs58.encode(new Uint8Array(32)),
|
|
173
173
|
lastValidBlockHeight: 0,
|
|
@@ -188,3 +188,6 @@ export async function signUserPayload({ payload, user, signTransaction, }) {
|
|
|
188
188
|
assert(sig.publicKey.equals(user), `signature is for ${sig.publicKey}, expected ${user}`);
|
|
189
189
|
return sig.signature;
|
|
190
190
|
}
|
|
191
|
+
export async function signUserPayload({ payload, signMessage, }) {
|
|
192
|
+
return await signMessage(new TextEncoder().encode(payload.toHex()));
|
|
193
|
+
}
|