@n1xyz/nord-ts 0.1.2 → 0.1.4
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/README.md +2 -2
- package/dist/gen/nord_pb.d.ts +113 -0
- package/dist/gen/nord_pb.js +21 -6
- package/dist/gen/openapi.d.ts +51 -2
- package/dist/nord/api/actions.d.ts +2 -0
- package/dist/nord/api/actions.js +2 -0
- package/dist/nord/client/Nord.d.ts +23 -8
- package/dist/nord/client/Nord.js +58 -8
- package/dist/nord/client/NordAdmin.d.ts +70 -0
- package/dist/nord/client/NordAdmin.js +187 -0
- package/dist/nord/client/NordClient.d.ts +42 -0
- package/dist/nord/client/NordClient.js +93 -0
- package/dist/nord/client/NordUser.d.ts +6 -50
- package/dist/nord/client/NordUser.js +162 -133
- package/dist/nord/index.d.ts +4 -0
- package/dist/nord/index.js +5 -1
- package/dist/types.d.ts +8 -5
- package/package.json +2 -2
- package/src/gen/nord_pb.ts +128 -4
- package/src/gen/openapi.ts +51 -2
- package/src/nord/api/actions.ts +2 -3
- package/src/nord/client/Nord.ts +75 -15
- package/src/nord/client/NordAdmin.ts +232 -0
- package/src/nord/client/NordClient.ts +105 -0
- package/src/nord/client/NordUser.ts +175 -229
- package/src/nord/index.ts +12 -0
- package/src/types.ts +9 -5
- package/src/nord/api/triggers.ts +0 -57
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import * as proto from "../../gen/nord_pb";
|
|
2
|
+
import { NordClient } from "./NordClient";
|
|
3
|
+
import type { NordClientParams } from "./NordClient";
|
|
4
|
+
import type { NordUser } from "./NordUser";
|
|
5
|
+
export interface CreateTokenParams {
|
|
6
|
+
tokenDecimals: number;
|
|
7
|
+
weightBps: number;
|
|
8
|
+
viewSymbol: string;
|
|
9
|
+
oracleSymbol: string;
|
|
10
|
+
solAddr: Uint8Array;
|
|
11
|
+
}
|
|
12
|
+
export interface CreateMarketParams {
|
|
13
|
+
sizeDecimals: number;
|
|
14
|
+
priceDecimals: number;
|
|
15
|
+
imfBps: number;
|
|
16
|
+
cmfBps: number;
|
|
17
|
+
mmfBps: number;
|
|
18
|
+
marketType: proto.MarketType;
|
|
19
|
+
viewSymbol: string;
|
|
20
|
+
oracleSymbol: string;
|
|
21
|
+
baseTokenId: number;
|
|
22
|
+
}
|
|
23
|
+
export interface PythSetWormholeGuardiansParams {
|
|
24
|
+
guardianSetIndex: number;
|
|
25
|
+
addresses: Uint8Array[];
|
|
26
|
+
}
|
|
27
|
+
export interface PythSetSymbolFeedParams {
|
|
28
|
+
oracleSymbol: string;
|
|
29
|
+
priceFeedId: Uint8Array;
|
|
30
|
+
}
|
|
31
|
+
export interface FreezeMarketParams {
|
|
32
|
+
marketId: number;
|
|
33
|
+
}
|
|
34
|
+
export interface UnfreezeMarketParams {
|
|
35
|
+
marketId: number;
|
|
36
|
+
}
|
|
37
|
+
export interface NordAdminParams extends NordClientParams {
|
|
38
|
+
signFn: (message: Uint8Array) => Promise<Uint8Array>;
|
|
39
|
+
}
|
|
40
|
+
export declare class NordAdmin extends NordClient {
|
|
41
|
+
private readonly signFn;
|
|
42
|
+
constructor(params: NordAdminParams);
|
|
43
|
+
clone(): NordAdmin;
|
|
44
|
+
static fromUser(user: NordUser, adminSignFn: (message: Uint8Array) => Promise<Uint8Array>): NordAdmin;
|
|
45
|
+
private submitAction;
|
|
46
|
+
createToken(params: CreateTokenParams): Promise<{
|
|
47
|
+
actionId: bigint;
|
|
48
|
+
} & proto.Receipt_InsertTokenResult>;
|
|
49
|
+
createMarket(params: CreateMarketParams): Promise<{
|
|
50
|
+
actionId: bigint;
|
|
51
|
+
} & proto.Receipt_InsertMarketResult>;
|
|
52
|
+
pythSetWormholeGuardians(params: PythSetWormholeGuardiansParams): Promise<{
|
|
53
|
+
actionId: bigint;
|
|
54
|
+
} & proto.Receipt_UpdateGuardianSetResult>;
|
|
55
|
+
pythSetSymbolFeed(params: PythSetSymbolFeedParams): Promise<{
|
|
56
|
+
actionId: bigint;
|
|
57
|
+
} & proto.Receipt_OracleSymbolFeedResult>;
|
|
58
|
+
pause(): Promise<{
|
|
59
|
+
actionId: bigint;
|
|
60
|
+
}>;
|
|
61
|
+
unpause(): Promise<{
|
|
62
|
+
actionId: bigint;
|
|
63
|
+
}>;
|
|
64
|
+
freezeMarket(params: FreezeMarketParams): Promise<{
|
|
65
|
+
actionId: bigint;
|
|
66
|
+
} & proto.Receipt_MarketFreezeUpdated>;
|
|
67
|
+
unfreezeMarket(params: UnfreezeMarketParams): Promise<{
|
|
68
|
+
actionId: bigint;
|
|
69
|
+
} & proto.Receipt_MarketFreezeUpdated>;
|
|
70
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.NordAdmin = void 0;
|
|
37
|
+
const proto = __importStar(require("../../gen/nord_pb"));
|
|
38
|
+
const protobuf_1 = require("@bufbuild/protobuf");
|
|
39
|
+
const utils_1 = require("../../utils");
|
|
40
|
+
const types_1 = require("../../types");
|
|
41
|
+
const NordError_1 = require("../utils/NordError");
|
|
42
|
+
const NordClient_1 = require("./NordClient");
|
|
43
|
+
class NordAdmin extends NordClient_1.NordClient {
|
|
44
|
+
constructor(params) {
|
|
45
|
+
const { signFn: adminSignFn, ...clientParams } = params;
|
|
46
|
+
super(clientParams);
|
|
47
|
+
this.signFn = adminSignFn;
|
|
48
|
+
}
|
|
49
|
+
clone() {
|
|
50
|
+
const copy = new NordAdmin({
|
|
51
|
+
nord: this.nord,
|
|
52
|
+
address: this.address,
|
|
53
|
+
walletSignFn: this.walletSignFn,
|
|
54
|
+
sessionSignFn: this.sessionSignFn,
|
|
55
|
+
transactionSignFn: this.transactionSignFn,
|
|
56
|
+
connection: this.connection,
|
|
57
|
+
sessionId: this.sessionId,
|
|
58
|
+
sessionPubKey: new Uint8Array(this.sessionPubKey),
|
|
59
|
+
publicKey: this.publicKey,
|
|
60
|
+
signFn: this.signFn,
|
|
61
|
+
});
|
|
62
|
+
this.cloneClientState(copy);
|
|
63
|
+
return copy;
|
|
64
|
+
}
|
|
65
|
+
static fromUser(user, adminSignFn) {
|
|
66
|
+
return new NordAdmin({
|
|
67
|
+
nord: user.nord,
|
|
68
|
+
address: user.address,
|
|
69
|
+
walletSignFn: user.walletSignFn,
|
|
70
|
+
sessionSignFn: user.sessionSignFn,
|
|
71
|
+
transactionSignFn: user.transactionSignFn,
|
|
72
|
+
connection: user.connection,
|
|
73
|
+
sessionId: user.sessionId,
|
|
74
|
+
sessionPubKey: new Uint8Array(user.sessionPubKey),
|
|
75
|
+
publicKey: user.publicKey,
|
|
76
|
+
signFn: adminSignFn,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
async submitAction(kind) {
|
|
80
|
+
try {
|
|
81
|
+
return await this.submitSignedAction(kind, async (message) => {
|
|
82
|
+
const signature = await this.signFn(message);
|
|
83
|
+
const signed = new Uint8Array(message.length + signature.length);
|
|
84
|
+
signed.set(message);
|
|
85
|
+
signed.set(signature, message.length);
|
|
86
|
+
return signed;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
throw new NordError_1.NordError(`Admin action ${kind.case} failed`, {
|
|
91
|
+
cause: error,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async createToken(params) {
|
|
96
|
+
(0, utils_1.checkPubKeyLength)(types_1.KeyType.Ed25519, params.solAddr.length);
|
|
97
|
+
const receipt = await this.submitAction({
|
|
98
|
+
case: "createToken",
|
|
99
|
+
value: (0, protobuf_1.create)(proto.Action_CreateTokenSchema, {
|
|
100
|
+
tokenDecimals: params.tokenDecimals,
|
|
101
|
+
weightBps: params.weightBps,
|
|
102
|
+
viewSymbol: params.viewSymbol,
|
|
103
|
+
oracleSymbol: params.oracleSymbol,
|
|
104
|
+
solAddr: params.solAddr,
|
|
105
|
+
}),
|
|
106
|
+
});
|
|
107
|
+
this.expectReceiptKind(receipt, "insertTokenResult", "create token");
|
|
108
|
+
return { actionId: receipt.actionId, ...receipt.kind.value };
|
|
109
|
+
}
|
|
110
|
+
async createMarket(params) {
|
|
111
|
+
const receipt = await this.submitAction({
|
|
112
|
+
case: "createMarket",
|
|
113
|
+
value: (0, protobuf_1.create)(proto.Action_CreateMarketSchema, {
|
|
114
|
+
sizeDecimals: params.sizeDecimals,
|
|
115
|
+
priceDecimals: params.priceDecimals,
|
|
116
|
+
imfBps: params.imfBps,
|
|
117
|
+
cmfBps: params.cmfBps,
|
|
118
|
+
mmfBps: params.mmfBps,
|
|
119
|
+
marketType: params.marketType,
|
|
120
|
+
viewSymbol: params.viewSymbol,
|
|
121
|
+
oracleSymbol: params.oracleSymbol,
|
|
122
|
+
baseTokenId: params.baseTokenId,
|
|
123
|
+
}),
|
|
124
|
+
});
|
|
125
|
+
this.expectReceiptKind(receipt, "insertMarketResult", "create market");
|
|
126
|
+
return { actionId: receipt.actionId, ...receipt.kind.value };
|
|
127
|
+
}
|
|
128
|
+
async pythSetWormholeGuardians(params) {
|
|
129
|
+
const receipt = await this.submitAction({
|
|
130
|
+
case: "pythSetWormholeGuardians",
|
|
131
|
+
value: (0, protobuf_1.create)(proto.Action_PythSetWormholeGuardiansSchema, {
|
|
132
|
+
guardianSetIndex: params.guardianSetIndex,
|
|
133
|
+
addresses: params.addresses,
|
|
134
|
+
}),
|
|
135
|
+
});
|
|
136
|
+
this.expectReceiptKind(receipt, "updateGuardianSetResult", "update wormhole guardians");
|
|
137
|
+
return { actionId: receipt.actionId, ...receipt.kind.value };
|
|
138
|
+
}
|
|
139
|
+
async pythSetSymbolFeed(params) {
|
|
140
|
+
const receipt = await this.submitAction({
|
|
141
|
+
case: "pythSetSymbolFeed",
|
|
142
|
+
value: (0, protobuf_1.create)(proto.Action_PythSetSymbolFeedSchema, {
|
|
143
|
+
oracleSymbol: params.oracleSymbol,
|
|
144
|
+
priceFeedId: params.priceFeedId,
|
|
145
|
+
}),
|
|
146
|
+
});
|
|
147
|
+
this.expectReceiptKind(receipt, "oracleSymbolFeedResult", "set symbol feed");
|
|
148
|
+
return { actionId: receipt.actionId, ...receipt.kind.value };
|
|
149
|
+
}
|
|
150
|
+
async pause() {
|
|
151
|
+
const receipt = await this.submitAction({
|
|
152
|
+
case: "pause",
|
|
153
|
+
value: (0, protobuf_1.create)(proto.Action_PauseSchema, {}),
|
|
154
|
+
});
|
|
155
|
+
this.expectReceiptKind(receipt, "paused", "pause");
|
|
156
|
+
return { actionId: receipt.actionId };
|
|
157
|
+
}
|
|
158
|
+
async unpause() {
|
|
159
|
+
const receipt = await this.submitAction({
|
|
160
|
+
case: "unpause",
|
|
161
|
+
value: (0, protobuf_1.create)(proto.Action_UnpauseSchema, {}),
|
|
162
|
+
});
|
|
163
|
+
this.expectReceiptKind(receipt, "unpaused", "unpause");
|
|
164
|
+
return { actionId: receipt.actionId };
|
|
165
|
+
}
|
|
166
|
+
async freezeMarket(params) {
|
|
167
|
+
const receipt = await this.submitAction({
|
|
168
|
+
case: "freezeMarket",
|
|
169
|
+
value: (0, protobuf_1.create)(proto.Action_FreezeMarketSchema, {
|
|
170
|
+
marketId: params.marketId,
|
|
171
|
+
}),
|
|
172
|
+
});
|
|
173
|
+
this.expectReceiptKind(receipt, "marketFreezeUpdated", "freeze market");
|
|
174
|
+
return { actionId: receipt.actionId, ...receipt.kind.value };
|
|
175
|
+
}
|
|
176
|
+
async unfreezeMarket(params) {
|
|
177
|
+
const receipt = await this.submitAction({
|
|
178
|
+
case: "unfreezeMarket",
|
|
179
|
+
value: (0, protobuf_1.create)(proto.Action_UnfreezeMarketSchema, {
|
|
180
|
+
marketId: params.marketId,
|
|
181
|
+
}),
|
|
182
|
+
});
|
|
183
|
+
this.expectReceiptKind(receipt, "marketFreezeUpdated", "unfreeze market");
|
|
184
|
+
return { actionId: receipt.actionId, ...receipt.kind.value };
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
exports.NordAdmin = NordAdmin;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
2
|
+
import type { Transaction } from "@solana/web3.js";
|
|
3
|
+
import * as proto from "../../gen/nord_pb";
|
|
4
|
+
import { Nord } from "./Nord";
|
|
5
|
+
type ReceiptKind = NonNullable<proto.Receipt["kind"]>;
|
|
6
|
+
type ExtractReceiptKind<K extends ReceiptKind["case"]> = Extract<ReceiptKind, {
|
|
7
|
+
case: K;
|
|
8
|
+
}>;
|
|
9
|
+
export interface NordClientParams {
|
|
10
|
+
nord: Nord;
|
|
11
|
+
address: PublicKey;
|
|
12
|
+
walletSignFn: (message: Uint8Array | string) => Promise<Uint8Array>;
|
|
13
|
+
sessionSignFn: (message: Uint8Array) => Promise<Uint8Array>;
|
|
14
|
+
transactionSignFn: <T extends Transaction>(tx: T) => Promise<T>;
|
|
15
|
+
connection?: Connection;
|
|
16
|
+
sessionId?: bigint;
|
|
17
|
+
sessionPubKey: Uint8Array;
|
|
18
|
+
publicKey: PublicKey;
|
|
19
|
+
}
|
|
20
|
+
export declare abstract class NordClient {
|
|
21
|
+
readonly nord: Nord;
|
|
22
|
+
readonly address: PublicKey;
|
|
23
|
+
readonly walletSignFn: (message: Uint8Array | string) => Promise<Uint8Array>;
|
|
24
|
+
readonly sessionSignFn: (message: Uint8Array) => Promise<Uint8Array>;
|
|
25
|
+
readonly transactionSignFn: <T extends Transaction>(tx: T) => Promise<T>;
|
|
26
|
+
connection: Connection;
|
|
27
|
+
sessionId?: bigint;
|
|
28
|
+
sessionPubKey: Uint8Array;
|
|
29
|
+
publicKey: PublicKey;
|
|
30
|
+
lastTs: number;
|
|
31
|
+
protected actionNonce: number;
|
|
32
|
+
protected constructor(params: NordClientParams);
|
|
33
|
+
protected submitSignedAction(kind: proto.Action["kind"], makeSignedMessage: (message: Uint8Array) => Promise<Uint8Array>): Promise<proto.Receipt>;
|
|
34
|
+
protected nextActionNonce(): number;
|
|
35
|
+
protected cloneClientState(target: NordClient): void;
|
|
36
|
+
getSolanaPublicKey(): PublicKey;
|
|
37
|
+
protected expectReceiptKind<K extends ReceiptKind["case"]>(receipt: proto.Receipt, expected: K, action: string): asserts receipt is proto.Receipt & {
|
|
38
|
+
kind: ExtractReceiptKind<K>;
|
|
39
|
+
};
|
|
40
|
+
protected formatReceiptError(receipt: proto.Receipt): string;
|
|
41
|
+
}
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.NordClient = void 0;
|
|
37
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
38
|
+
const proto = __importStar(require("../../gen/nord_pb"));
|
|
39
|
+
const actions_1 = require("../api/actions");
|
|
40
|
+
const NordError_1 = require("../utils/NordError");
|
|
41
|
+
class NordClient {
|
|
42
|
+
constructor(params) {
|
|
43
|
+
this.lastTs = 0;
|
|
44
|
+
this.actionNonce = 0;
|
|
45
|
+
this.nord = params.nord;
|
|
46
|
+
this.address = params.address;
|
|
47
|
+
this.walletSignFn = params.walletSignFn;
|
|
48
|
+
this.sessionSignFn = params.sessionSignFn;
|
|
49
|
+
this.transactionSignFn = params.transactionSignFn;
|
|
50
|
+
this.connection =
|
|
51
|
+
params.connection ??
|
|
52
|
+
new web3_js_1.Connection(params.nord.solanaUrl, {
|
|
53
|
+
commitment: "confirmed",
|
|
54
|
+
});
|
|
55
|
+
this.sessionId = params.sessionId;
|
|
56
|
+
this.sessionPubKey = new Uint8Array(params.sessionPubKey);
|
|
57
|
+
this.publicKey = params.publicKey;
|
|
58
|
+
}
|
|
59
|
+
async submitSignedAction(kind, makeSignedMessage) {
|
|
60
|
+
const nonce = this.nextActionNonce();
|
|
61
|
+
const currentTimestamp = await this.nord.getTimestamp();
|
|
62
|
+
const action = (0, actions_1.createAction)(currentTimestamp, nonce, kind);
|
|
63
|
+
return (0, actions_1.sendAction)(this.nord.webServerUrl, makeSignedMessage, action);
|
|
64
|
+
}
|
|
65
|
+
nextActionNonce() {
|
|
66
|
+
return ++this.actionNonce;
|
|
67
|
+
}
|
|
68
|
+
cloneClientState(target) {
|
|
69
|
+
target.connection = this.connection;
|
|
70
|
+
target.sessionId = this.sessionId;
|
|
71
|
+
target.sessionPubKey = new Uint8Array(this.sessionPubKey);
|
|
72
|
+
target.publicKey = this.publicKey;
|
|
73
|
+
target.lastTs = this.lastTs;
|
|
74
|
+
target.actionNonce = this.actionNonce;
|
|
75
|
+
}
|
|
76
|
+
getSolanaPublicKey() {
|
|
77
|
+
return this.address;
|
|
78
|
+
}
|
|
79
|
+
expectReceiptKind(receipt, expected, action) {
|
|
80
|
+
if (receipt.kind?.case !== expected) {
|
|
81
|
+
const label = this.formatReceiptError(receipt);
|
|
82
|
+
throw new NordError_1.NordError(`Failed to ${action}: ${label}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
formatReceiptError(receipt) {
|
|
86
|
+
if (receipt.kind?.case === "err") {
|
|
87
|
+
const err = receipt.kind.value;
|
|
88
|
+
return proto.Error[err] ?? err.toString();
|
|
89
|
+
}
|
|
90
|
+
return receipt.kind?.case ?? "unknown";
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.NordClient = NordClient;
|
|
@@ -3,8 +3,8 @@ import Decimal from "decimal.js";
|
|
|
3
3
|
import { FillMode, Side, SPLTokenInfo, QuoteSize, TriggerKind } from "../../types";
|
|
4
4
|
import * as proto from "../../gen/nord_pb";
|
|
5
5
|
import { BigIntValue } from "../../utils";
|
|
6
|
-
import type { AccountTriggerInfo, TriggerHistoryPage, HistoryTriggerQuery } from "../api/triggers";
|
|
7
6
|
import { Nord } from "./Nord";
|
|
7
|
+
import { NordClient } from "./NordClient";
|
|
8
8
|
/**
|
|
9
9
|
* Parameters for creating a NordUser instance
|
|
10
10
|
*/
|
|
@@ -48,6 +48,7 @@ export interface PlaceOrderParams {
|
|
|
48
48
|
quoteSize?: QuoteSize;
|
|
49
49
|
/** Account ID to place the order from */
|
|
50
50
|
accountId?: number;
|
|
51
|
+
clientOrderId?: BigIntValue;
|
|
51
52
|
}
|
|
52
53
|
export interface AddTriggerParams {
|
|
53
54
|
marketId: number;
|
|
@@ -106,17 +107,7 @@ export interface UserAtomicSubaction {
|
|
|
106
107
|
/**
|
|
107
108
|
* User class for interacting with the Nord protocol
|
|
108
109
|
*/
|
|
109
|
-
export declare class NordUser {
|
|
110
|
-
/** Nord client instance */
|
|
111
|
-
readonly nord: Nord;
|
|
112
|
-
/** User's blockchain address */
|
|
113
|
-
readonly address: PublicKey;
|
|
114
|
-
/** Function to sign messages with the user's wallet */
|
|
115
|
-
readonly walletSignFn: (message: Uint8Array | string) => Promise<Uint8Array>;
|
|
116
|
-
/** Function to sign messages with the user's session key */
|
|
117
|
-
readonly sessionSignFn: (message: Uint8Array) => Promise<Uint8Array>;
|
|
118
|
-
/** Function to sign transactions with the user's wallet */
|
|
119
|
-
readonly transactionSignFn: <T extends Transaction>(tx: T) => Promise<T>;
|
|
110
|
+
export declare class NordUser extends NordClient {
|
|
120
111
|
/** User balances by token symbol */
|
|
121
112
|
balances: {
|
|
122
113
|
[key: string]: {
|
|
@@ -156,18 +147,6 @@ export declare class NordUser {
|
|
|
156
147
|
};
|
|
157
148
|
/** User's account IDs */
|
|
158
149
|
accountIds?: number[];
|
|
159
|
-
/** Current session ID */
|
|
160
|
-
sessionId?: bigint;
|
|
161
|
-
/** User's public key */
|
|
162
|
-
publicKey: PublicKey;
|
|
163
|
-
/** Session public key */
|
|
164
|
-
sessionPubKey: Uint8Array;
|
|
165
|
-
/** Last timestamp used */
|
|
166
|
-
lastTs: number;
|
|
167
|
-
/** Last nonce used */
|
|
168
|
-
lastNonce: number;
|
|
169
|
-
/** Solana connection */
|
|
170
|
-
connection: Connection;
|
|
171
150
|
/** SPL token information */
|
|
172
151
|
splTokenInfos: SPLTokenInfo[];
|
|
173
152
|
/**
|
|
@@ -202,7 +181,7 @@ export declare class NordUser {
|
|
|
202
181
|
*/
|
|
203
182
|
getAssociatedTokenAccount(mint: PublicKey): Promise<PublicKey>;
|
|
204
183
|
/**
|
|
205
|
-
* Deposit SPL tokens to the
|
|
184
|
+
* Deposit SPL tokens to the app
|
|
206
185
|
*
|
|
207
186
|
* @param amount - Amount to deposit
|
|
208
187
|
* @param tokenId - Token ID
|
|
@@ -213,7 +192,7 @@ export declare class NordUser {
|
|
|
213
192
|
*/
|
|
214
193
|
depositSpl(amount: number, tokenId: number, recipient?: PublicKey): Promise<string>;
|
|
215
194
|
/**
|
|
216
|
-
* Deposit SPL tokens to the
|
|
195
|
+
* Deposit SPL tokens to the app
|
|
217
196
|
*
|
|
218
197
|
* @param amount - Amount to deposit
|
|
219
198
|
* @param tokenId - Token ID
|
|
@@ -234,6 +213,7 @@ export declare class NordUser {
|
|
|
234
213
|
* @returns Nonce as number
|
|
235
214
|
*/
|
|
236
215
|
getNonce(): number;
|
|
216
|
+
private submitSessionAction;
|
|
237
217
|
/**
|
|
238
218
|
* Update account IDs for this user
|
|
239
219
|
*
|
|
@@ -323,24 +303,6 @@ export declare class NordUser {
|
|
|
323
303
|
removeTrigger(params: RemoveTriggerParams): Promise<{
|
|
324
304
|
actionId: bigint;
|
|
325
305
|
}>;
|
|
326
|
-
/**
|
|
327
|
-
* Fetch active triggers for an account.
|
|
328
|
-
*
|
|
329
|
-
* @param params Optional parameters containing an explicit account id.
|
|
330
|
-
* @throws {NordError} If no account can be resolved or the request fails.
|
|
331
|
-
*/
|
|
332
|
-
getAccountTriggers(params?: {
|
|
333
|
-
accountId?: number;
|
|
334
|
-
}): Promise<AccountTriggerInfo[]>;
|
|
335
|
-
/**
|
|
336
|
-
* Fetch trigger history for an account.
|
|
337
|
-
*
|
|
338
|
-
* @param params Optional parameters with account id and history query filters.
|
|
339
|
-
* @throws {NordError} If no account can be resolved or the request fails.
|
|
340
|
-
*/
|
|
341
|
-
getAccountTriggerHistory(params: HistoryTriggerQuery & {
|
|
342
|
-
accountId?: number;
|
|
343
|
-
}): Promise<TriggerHistoryPage>;
|
|
344
306
|
/**
|
|
345
307
|
* Transfer tokens to another account
|
|
346
308
|
*
|
|
@@ -397,10 +359,4 @@ export declare class NordUser {
|
|
|
397
359
|
[symbol: string]: string;
|
|
398
360
|
};
|
|
399
361
|
}>;
|
|
400
|
-
/**
|
|
401
|
-
* Get the Solana public key derived from the address
|
|
402
|
-
*
|
|
403
|
-
* @returns The Solana public key
|
|
404
|
-
*/
|
|
405
|
-
getSolanaPublicKey(): PublicKey;
|
|
406
362
|
}
|