@n1xyz/nord-ts 0.1.4 → 0.1.6
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/gen/nord_pb.d.ts +516 -7
- package/dist/gen/nord_pb.js +133 -64
- package/dist/gen/openapi.d.ts +165 -1
- package/dist/nord/api/actions.d.ts +9 -0
- package/dist/nord/api/actions.js +16 -0
- package/dist/nord/client/Nord.d.ts +92 -2
- package/dist/nord/client/Nord.js +150 -2
- package/dist/nord/client/NordAdmin.d.ts +202 -13
- package/dist/nord/client/NordAdmin.js +273 -67
- package/dist/nord/client/NordClient.d.ts +0 -9
- package/dist/nord/client/NordClient.js +0 -48
- package/dist/nord/client/NordUser.js +6 -6
- package/dist/nord/index.d.ts +2 -2
- package/dist/nord/index.js +2 -1
- package/dist/types.d.ts +7 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +5 -0
- package/package.json +2 -2
- package/src/gen/nord_pb.ts +640 -63
- package/src/gen/openapi.ts +165 -1
- package/src/nord/api/actions.ts +26 -1
- package/src/nord/client/Nord.ts +185 -1
- package/src/nord/client/NordAdmin.ts +366 -84
- package/src/nord/client/NordClient.ts +0 -26
- package/src/nord/client/NordUser.ts +7 -6
- package/src/nord/index.ts +1 -2
- package/src/types.ts +9 -0
- package/src/utils.ts +5 -0
|
@@ -33,84 +33,142 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.NordAdmin = void 0;
|
|
37
|
-
const proto = __importStar(require("../../gen/nord_pb"));
|
|
36
|
+
exports.NordAdmin = exports.AclRole = void 0;
|
|
38
37
|
const protobuf_1 = require("@bufbuild/protobuf");
|
|
38
|
+
const proto = __importStar(require("../../gen/nord_pb"));
|
|
39
39
|
const utils_1 = require("../../utils");
|
|
40
|
-
const
|
|
40
|
+
const actions_1 = require("../api/actions");
|
|
41
41
|
const NordError_1 = require("../utils/NordError");
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
publicKey: this.publicKey,
|
|
60
|
-
signFn: this.signFn,
|
|
61
|
-
});
|
|
62
|
-
this.cloneClientState(copy);
|
|
63
|
-
return copy;
|
|
42
|
+
// NOTE: keep in sync with `acl.rs`.
|
|
43
|
+
// NOTE: don't forget `number` as int is internally a u32.
|
|
44
|
+
var AclRole;
|
|
45
|
+
(function (AclRole) {
|
|
46
|
+
AclRole[AclRole["FEE_MANAGER"] = 1] = "FEE_MANAGER";
|
|
47
|
+
AclRole[AclRole["MARKET_MANAGER"] = 2] = "MARKET_MANAGER";
|
|
48
|
+
// TODO: unsure about this?
|
|
49
|
+
AclRole[AclRole["ADMIN"] = -2147483648] = "ADMIN";
|
|
50
|
+
})(AclRole || (exports.AclRole = AclRole = {}));
|
|
51
|
+
/**
|
|
52
|
+
* Administrative client capable of submitting privileged configuration actions.
|
|
53
|
+
*/
|
|
54
|
+
class NordAdmin {
|
|
55
|
+
constructor({ nord, admin, signFn, }) {
|
|
56
|
+
this.nord = nord;
|
|
57
|
+
this.admin = admin;
|
|
58
|
+
this.signFn = signFn;
|
|
64
59
|
}
|
|
65
|
-
|
|
60
|
+
/** Create a new admin client.
|
|
61
|
+
*
|
|
62
|
+
* @param nord - Nord instance
|
|
63
|
+
* @param admin - The user that will be signing actions.
|
|
64
|
+
* @param signFn - Function to sign messages with the admin's wallet.
|
|
65
|
+
*
|
|
66
|
+
* `signFn` must sign the _hex-encoded_ message, not the raw message itself, for
|
|
67
|
+
* the purpose of being compatible with Solana wallets.
|
|
68
|
+
*
|
|
69
|
+
* In practice, you will do something along the lines of:
|
|
70
|
+
*
|
|
71
|
+
* ```typescript
|
|
72
|
+
* (x) => wallet.signMessage(new TextEncoder().encode(x.toHex()));
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* For a software signing key, this might look more like:
|
|
76
|
+
*
|
|
77
|
+
* ```typescript
|
|
78
|
+
* (x) => nacl.sign.detached(new TextEncoder().encode(x.toHex()), sk);
|
|
79
|
+
* ``
|
|
80
|
+
*
|
|
81
|
+
* where `nacl` is the tweetnacl library.
|
|
82
|
+
*/
|
|
83
|
+
static new({ nord, admin, signFn, }) {
|
|
66
84
|
return new NordAdmin({
|
|
67
|
-
nord
|
|
68
|
-
|
|
69
|
-
|
|
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,
|
|
85
|
+
nord,
|
|
86
|
+
admin,
|
|
87
|
+
signFn,
|
|
77
88
|
});
|
|
78
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Submit an action and append the admin signature before sending it to Nord.
|
|
92
|
+
*
|
|
93
|
+
* @param kind - Action payload describing the admin request
|
|
94
|
+
* @throws {NordError} If signing or submission fails
|
|
95
|
+
*/
|
|
79
96
|
async submitAction(kind) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
97
|
+
const timestamp = await this.nord.getTimestamp();
|
|
98
|
+
const action = (0, actions_1.createAction)(timestamp, 0, kind);
|
|
99
|
+
return (0, actions_1.sendAction)(this.nord.webServerUrl, async (xs) => {
|
|
100
|
+
const signature = await this.signFn(xs);
|
|
101
|
+
if (signature.length !== 64) {
|
|
102
|
+
throw new NordError_1.NordError("invalid signature length; must be 64 bytes");
|
|
103
|
+
}
|
|
104
|
+
return Uint8Array.from([...xs, ...signature]);
|
|
105
|
+
}, action);
|
|
106
|
+
}
|
|
107
|
+
/** Set acl permissions for a given user.
|
|
108
|
+
*
|
|
109
|
+
* If all roles are removed, the user is removed from the acl.
|
|
110
|
+
*
|
|
111
|
+
* @param target - User to update.
|
|
112
|
+
* @param addRoles - Roles to add to the user.
|
|
113
|
+
* @param removeRoles - Reles to remove from the user.
|
|
114
|
+
*/
|
|
115
|
+
async updateAcl({ target, addRoles, removeRoles, }) {
|
|
116
|
+
const allRoles = addRoles.concat(removeRoles);
|
|
117
|
+
if (allRoles.length !== new Set(allRoles).size) {
|
|
118
|
+
throw new NordError_1.NordError("duplicate roles in acl update; must be unique");
|
|
88
119
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
120
|
+
let mask = 0;
|
|
121
|
+
let values = 0;
|
|
122
|
+
for (const role of allRoles) {
|
|
123
|
+
mask |= role;
|
|
93
124
|
}
|
|
125
|
+
for (const role of addRoles) {
|
|
126
|
+
values |= role;
|
|
127
|
+
}
|
|
128
|
+
const receipt = await this.submitAction({
|
|
129
|
+
case: "updateAcl",
|
|
130
|
+
value: (0, protobuf_1.create)(proto.Action_UpdateAclSchema, {
|
|
131
|
+
aclPubkey: this.admin.toBytes(),
|
|
132
|
+
targetPubkey: target.toBytes(),
|
|
133
|
+
}),
|
|
134
|
+
});
|
|
135
|
+
(0, actions_1.expectReceiptKind)(receipt, "aclUpdated", "update acl");
|
|
136
|
+
return { ...receipt.kind.value, actionId: receipt.actionId };
|
|
94
137
|
}
|
|
95
|
-
|
|
96
|
-
|
|
138
|
+
/**
|
|
139
|
+
* Register a new token that can be listed on Nord.
|
|
140
|
+
*
|
|
141
|
+
* @param params - Token configuration values
|
|
142
|
+
* @returns Action identifier and resulting token metadata
|
|
143
|
+
* @throws {NordError} If the action submission fails
|
|
144
|
+
*/
|
|
145
|
+
async createToken({ tokenDecimals, weightBps, viewSymbol, oracleSymbol, mintAddr, }) {
|
|
97
146
|
const receipt = await this.submitAction({
|
|
98
147
|
case: "createToken",
|
|
99
148
|
value: (0, protobuf_1.create)(proto.Action_CreateTokenSchema, {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
149
|
+
aclPubkey: this.admin.toBytes(),
|
|
150
|
+
tokenDecimals,
|
|
151
|
+
weightBps,
|
|
152
|
+
viewSymbol,
|
|
153
|
+
oracleSymbol,
|
|
154
|
+
solAddr: mintAddr.toBytes(),
|
|
105
155
|
}),
|
|
106
156
|
});
|
|
107
|
-
|
|
157
|
+
(0, actions_1.expectReceiptKind)(receipt, "insertTokenResult", "create token");
|
|
108
158
|
return { actionId: receipt.actionId, ...receipt.kind.value };
|
|
109
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* Open a new market with the provided trading parameters.
|
|
162
|
+
*
|
|
163
|
+
* @param params - Market configuration to apply
|
|
164
|
+
* @returns Action identifier and resulting market metadata
|
|
165
|
+
* @throws {NordError} If the action submission fails
|
|
166
|
+
*/
|
|
110
167
|
async createMarket(params) {
|
|
111
168
|
const receipt = await this.submitAction({
|
|
112
169
|
case: "createMarket",
|
|
113
170
|
value: (0, protobuf_1.create)(proto.Action_CreateMarketSchema, {
|
|
171
|
+
aclPubkey: this.admin.toBytes(),
|
|
114
172
|
sizeDecimals: params.sizeDecimals,
|
|
115
173
|
priceDecimals: params.priceDecimals,
|
|
116
174
|
imfBps: params.imfBps,
|
|
@@ -122,65 +180,213 @@ class NordAdmin extends NordClient_1.NordClient {
|
|
|
122
180
|
baseTokenId: params.baseTokenId,
|
|
123
181
|
}),
|
|
124
182
|
});
|
|
125
|
-
|
|
183
|
+
(0, actions_1.expectReceiptKind)(receipt, "insertMarketResult", "create market");
|
|
126
184
|
return { actionId: receipt.actionId, ...receipt.kind.value };
|
|
127
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* Update the Pyth guardian set used for verifying Wormhole messages.
|
|
188
|
+
*
|
|
189
|
+
* Each address must decode from a 20-byte hex string (with or without a
|
|
190
|
+
* leading `0x` prefix). The engine validates the supplied guardian set index
|
|
191
|
+
* before applying the update.
|
|
192
|
+
*
|
|
193
|
+
* @param params - Guardian set index and guardian addresses
|
|
194
|
+
* @returns Action identifier and guardian update receipt
|
|
195
|
+
* @throws {NordError} If the action submission fails
|
|
196
|
+
*/
|
|
128
197
|
async pythSetWormholeGuardians(params) {
|
|
198
|
+
const addresses = params.addresses.map((address) => {
|
|
199
|
+
try {
|
|
200
|
+
const decoded = (0, utils_1.decodeHex)(address);
|
|
201
|
+
if (decoded.length !== 20) {
|
|
202
|
+
throw new Error("guardian address must be 20 bytes");
|
|
203
|
+
}
|
|
204
|
+
return decoded;
|
|
205
|
+
}
|
|
206
|
+
catch (e) {
|
|
207
|
+
throw new NordError_1.NordError("invalid guardian address; must be a 20 byte hex address", { cause: e });
|
|
208
|
+
}
|
|
209
|
+
});
|
|
129
210
|
const receipt = await this.submitAction({
|
|
130
211
|
case: "pythSetWormholeGuardians",
|
|
131
212
|
value: (0, protobuf_1.create)(proto.Action_PythSetWormholeGuardiansSchema, {
|
|
213
|
+
aclPubkey: this.admin.toBytes(),
|
|
132
214
|
guardianSetIndex: params.guardianSetIndex,
|
|
133
|
-
addresses
|
|
215
|
+
addresses,
|
|
134
216
|
}),
|
|
135
217
|
});
|
|
136
|
-
|
|
218
|
+
(0, actions_1.expectReceiptKind)(receipt, "updateGuardianSetResult", "update wormhole guardians");
|
|
137
219
|
return { actionId: receipt.actionId, ...receipt.kind.value };
|
|
138
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* Link an oracle symbol to a specific Pyth price feed.
|
|
223
|
+
*
|
|
224
|
+
* The price feed identifier must decode to 32 bytes (with or without a
|
|
225
|
+
* leading `0x` prefix). Use this call to create or update the mapping used
|
|
226
|
+
* by the oracle integration.
|
|
227
|
+
*
|
|
228
|
+
* @param params - Oracle symbol and price feed identifier
|
|
229
|
+
* @returns Action identifier and symbol feed receipt
|
|
230
|
+
* @throws {NordError} If the action submission fails
|
|
231
|
+
*/
|
|
139
232
|
async pythSetSymbolFeed(params) {
|
|
233
|
+
let priceFeedId;
|
|
234
|
+
try {
|
|
235
|
+
priceFeedId = (0, utils_1.decodeHex)(params.priceFeedId);
|
|
236
|
+
if (priceFeedId.length !== 32) {
|
|
237
|
+
throw new Error("price feed id must be 32 bytes");
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
catch (e) {
|
|
241
|
+
throw new NordError_1.NordError("invalid price feed id; must be a 32 byte hex id", {
|
|
242
|
+
cause: e,
|
|
243
|
+
});
|
|
244
|
+
}
|
|
140
245
|
const receipt = await this.submitAction({
|
|
141
246
|
case: "pythSetSymbolFeed",
|
|
142
247
|
value: (0, protobuf_1.create)(proto.Action_PythSetSymbolFeedSchema, {
|
|
248
|
+
aclPubkey: this.admin.toBytes(),
|
|
143
249
|
oracleSymbol: params.oracleSymbol,
|
|
144
|
-
priceFeedId
|
|
250
|
+
priceFeedId,
|
|
145
251
|
}),
|
|
146
252
|
});
|
|
147
|
-
|
|
253
|
+
(0, actions_1.expectReceiptKind)(receipt, "oracleSymbolFeedResult", "set symbol feed");
|
|
148
254
|
return { actionId: receipt.actionId, ...receipt.kind.value };
|
|
149
255
|
}
|
|
256
|
+
/**
|
|
257
|
+
* Pause all trading activity on the exchange.
|
|
258
|
+
*
|
|
259
|
+
* @returns Action identifier confirming the pause
|
|
260
|
+
* @throws {NordError} If the action submission fails
|
|
261
|
+
*/
|
|
150
262
|
async pause() {
|
|
151
263
|
const receipt = await this.submitAction({
|
|
152
264
|
case: "pause",
|
|
153
|
-
value: (0, protobuf_1.create)(proto.Action_PauseSchema, {
|
|
265
|
+
value: (0, protobuf_1.create)(proto.Action_PauseSchema, {
|
|
266
|
+
aclPubkey: this.admin.toBytes(),
|
|
267
|
+
}),
|
|
154
268
|
});
|
|
155
|
-
|
|
269
|
+
(0, actions_1.expectReceiptKind)(receipt, "paused", "pause");
|
|
156
270
|
return { actionId: receipt.actionId };
|
|
157
271
|
}
|
|
272
|
+
/**
|
|
273
|
+
* Resume trading activity after a pause.
|
|
274
|
+
*
|
|
275
|
+
* @returns Action identifier confirming the unpause
|
|
276
|
+
* @throws {NordError} If the action submission fails
|
|
277
|
+
*/
|
|
158
278
|
async unpause() {
|
|
159
279
|
const receipt = await this.submitAction({
|
|
160
280
|
case: "unpause",
|
|
161
|
-
value: (0, protobuf_1.create)(proto.Action_UnpauseSchema, {
|
|
281
|
+
value: (0, protobuf_1.create)(proto.Action_UnpauseSchema, {
|
|
282
|
+
aclPubkey: this.admin.toBytes(),
|
|
283
|
+
}),
|
|
162
284
|
});
|
|
163
|
-
|
|
285
|
+
(0, actions_1.expectReceiptKind)(receipt, "unpaused", "unpause");
|
|
164
286
|
return { actionId: receipt.actionId };
|
|
165
287
|
}
|
|
288
|
+
/**
|
|
289
|
+
* Freeze an individual market, preventing new trades and orders.
|
|
290
|
+
*
|
|
291
|
+
* @param params - Target market identifier
|
|
292
|
+
* @returns Action identifier and freeze receipt
|
|
293
|
+
* @throws {NordError} If the action submission fails
|
|
294
|
+
*/
|
|
166
295
|
async freezeMarket(params) {
|
|
167
296
|
const receipt = await this.submitAction({
|
|
168
297
|
case: "freezeMarket",
|
|
169
298
|
value: (0, protobuf_1.create)(proto.Action_FreezeMarketSchema, {
|
|
170
299
|
marketId: params.marketId,
|
|
300
|
+
aclPubkey: this.admin.toBytes(),
|
|
171
301
|
}),
|
|
172
302
|
});
|
|
173
|
-
|
|
303
|
+
(0, actions_1.expectReceiptKind)(receipt, "marketFreezeUpdated", "freeze market");
|
|
174
304
|
return { actionId: receipt.actionId, ...receipt.kind.value };
|
|
175
305
|
}
|
|
306
|
+
/**
|
|
307
|
+
* Unfreeze a market that was previously halted.
|
|
308
|
+
*
|
|
309
|
+
* @param params - Target market identifier
|
|
310
|
+
* @returns Action identifier and freeze receipt
|
|
311
|
+
* @throws {NordError} If the action submission fails
|
|
312
|
+
*/
|
|
176
313
|
async unfreezeMarket(params) {
|
|
177
314
|
const receipt = await this.submitAction({
|
|
178
315
|
case: "unfreezeMarket",
|
|
179
316
|
value: (0, protobuf_1.create)(proto.Action_UnfreezeMarketSchema, {
|
|
180
317
|
marketId: params.marketId,
|
|
318
|
+
aclPubkey: this.admin.toBytes(),
|
|
319
|
+
}),
|
|
320
|
+
});
|
|
321
|
+
(0, actions_1.expectReceiptKind)(receipt, "marketFreezeUpdated", "unfreeze market");
|
|
322
|
+
return { actionId: receipt.actionId, ...receipt.kind.value };
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Append a new fee tier to the account bracket configuration.
|
|
326
|
+
*
|
|
327
|
+
* - The engine supports at most 16 tiers (ids 0–15). Tier 0 is reserved for
|
|
328
|
+
* the default Nord fees; use `updateFeeTier` if you need to change it.
|
|
329
|
+
* - The first appended tier receives id 1, and subsequent tiers increment the id.
|
|
330
|
+
*
|
|
331
|
+
* @param params - Fee tier configuration to insert
|
|
332
|
+
* @returns Action identifier and fee tier addition receipt
|
|
333
|
+
* @throws {NordError} If the action submission fails or the new tier exceeds the maximum range (0-15).
|
|
334
|
+
*/
|
|
335
|
+
async addFeeTier(params) {
|
|
336
|
+
const receipt = await this.submitAction({
|
|
337
|
+
case: "addFeeTier",
|
|
338
|
+
value: (0, protobuf_1.create)(proto.Action_AddFeeTierSchema, {
|
|
339
|
+
aclPubkey: this.admin.toBytes(),
|
|
340
|
+
config: (0, protobuf_1.create)(proto.FeeTierConfigSchema, params.config),
|
|
341
|
+
}),
|
|
342
|
+
});
|
|
343
|
+
(0, actions_1.expectReceiptKind)(receipt, "feeTierAdded", "add fee tier");
|
|
344
|
+
return { actionId: receipt.actionId, ...receipt.kind.value };
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Update an existing fee tier with new maker/taker rates.
|
|
348
|
+
*
|
|
349
|
+
* Tier identifiers must already exist; attempting to update a missing tier
|
|
350
|
+
* causes the action to fail.
|
|
351
|
+
*
|
|
352
|
+
* @param params - Fee tier identifier and updated configuration
|
|
353
|
+
* @returns Action identifier and fee tier update receipt
|
|
354
|
+
* @throws {NordError} If the action submission fails or the tier ID exceeds the configured range.
|
|
355
|
+
*/
|
|
356
|
+
async updateFeeTier(params) {
|
|
357
|
+
const receipt = await this.submitAction({
|
|
358
|
+
case: "updateFeeTier",
|
|
359
|
+
value: (0, protobuf_1.create)(proto.Action_UpdateFeeTierSchema, {
|
|
360
|
+
aclPubkey: this.admin.toBytes(),
|
|
361
|
+
id: params.tierId,
|
|
362
|
+
config: (0, protobuf_1.create)(proto.FeeTierConfigSchema, params.config),
|
|
363
|
+
}),
|
|
364
|
+
});
|
|
365
|
+
(0, actions_1.expectReceiptKind)(receipt, "feeTierUpdated", "update fee tier");
|
|
366
|
+
return { actionId: receipt.actionId, ...receipt.kind.value };
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Assign a fee tier to one or more accounts.
|
|
370
|
+
*
|
|
371
|
+
* The tier id must be within the configured range (0–15). Every account starts
|
|
372
|
+
* on tier 0; assigning it to another tier requires that tier to exist already.
|
|
373
|
+
* Invalid account ids or tier ids cause the action to fail.
|
|
374
|
+
*
|
|
375
|
+
* @param accounts - Account IDs to update
|
|
376
|
+
* @param tierId - Target fee tier identifier
|
|
377
|
+
* @returns Action identifier and accounts-tier receipt
|
|
378
|
+
* @throws {NordError} If the tier id exceeds the configured range or an account id is invalid.
|
|
379
|
+
*/
|
|
380
|
+
async updateAccountsTier(accounts, tierId) {
|
|
381
|
+
const receipt = await this.submitAction({
|
|
382
|
+
case: "updateAccountsTier",
|
|
383
|
+
value: (0, protobuf_1.create)(proto.Action_UpdateAccountsTierSchema, {
|
|
384
|
+
aclPubkey: this.admin.toBytes(),
|
|
385
|
+
accounts,
|
|
386
|
+
tierId,
|
|
181
387
|
}),
|
|
182
388
|
});
|
|
183
|
-
|
|
389
|
+
(0, actions_1.expectReceiptKind)(receipt, "accountsTierUpdated", "update accounts tier");
|
|
184
390
|
return { actionId: receipt.actionId, ...receipt.kind.value };
|
|
185
391
|
}
|
|
186
392
|
}
|
|
@@ -2,10 +2,6 @@ import { Connection, PublicKey } from "@solana/web3.js";
|
|
|
2
2
|
import type { Transaction } from "@solana/web3.js";
|
|
3
3
|
import * as proto from "../../gen/nord_pb";
|
|
4
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
5
|
export interface NordClientParams {
|
|
10
6
|
nord: Nord;
|
|
11
7
|
address: PublicKey;
|
|
@@ -34,9 +30,4 @@ export declare abstract class NordClient {
|
|
|
34
30
|
protected nextActionNonce(): number;
|
|
35
31
|
protected cloneClientState(target: NordClient): void;
|
|
36
32
|
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
33
|
}
|
|
42
|
-
export {};
|
|
@@ -1,43 +1,8 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.NordClient = void 0;
|
|
37
4
|
const web3_js_1 = require("@solana/web3.js");
|
|
38
|
-
const proto = __importStar(require("../../gen/nord_pb"));
|
|
39
5
|
const actions_1 = require("../api/actions");
|
|
40
|
-
const NordError_1 = require("../utils/NordError");
|
|
41
6
|
class NordClient {
|
|
42
7
|
constructor(params) {
|
|
43
8
|
this.lastTs = 0;
|
|
@@ -76,18 +41,5 @@ class NordClient {
|
|
|
76
41
|
getSolanaPublicKey() {
|
|
77
42
|
return this.address;
|
|
78
43
|
}
|
|
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
44
|
}
|
|
93
45
|
exports.NordClient = NordClient;
|
|
@@ -407,7 +407,7 @@ class NordUser extends NordClient_1.NordClient {
|
|
|
407
407
|
amount: scaledAmount,
|
|
408
408
|
}),
|
|
409
409
|
});
|
|
410
|
-
|
|
410
|
+
(0, actions_1.expectReceiptKind)(receipt, "withdrawResult", "withdraw");
|
|
411
411
|
return { actionId: receipt.actionId };
|
|
412
412
|
}
|
|
413
413
|
catch (error) {
|
|
@@ -457,7 +457,7 @@ class NordUser extends NordClient_1.NordClient {
|
|
|
457
457
|
: BigInt(params.clientOrderId),
|
|
458
458
|
}),
|
|
459
459
|
});
|
|
460
|
-
|
|
460
|
+
(0, actions_1.expectReceiptKind)(receipt, "placeOrderResult", "place order");
|
|
461
461
|
const result = receipt.kind.value;
|
|
462
462
|
return {
|
|
463
463
|
actionId: receipt.actionId,
|
|
@@ -489,7 +489,7 @@ class NordUser extends NordClient_1.NordClient {
|
|
|
489
489
|
senderAccountId: accountId,
|
|
490
490
|
}),
|
|
491
491
|
});
|
|
492
|
-
|
|
492
|
+
(0, actions_1.expectReceiptKind)(receipt, "cancelOrderResult", "cancel order");
|
|
493
493
|
return {
|
|
494
494
|
actionId: receipt.actionId,
|
|
495
495
|
orderId: receipt.kind.value.orderId,
|
|
@@ -544,7 +544,7 @@ class NordUser extends NordClient_1.NordClient {
|
|
|
544
544
|
accountId: params.accountId,
|
|
545
545
|
}),
|
|
546
546
|
});
|
|
547
|
-
|
|
547
|
+
(0, actions_1.expectReceiptKind)(receipt, "triggerAdded", "add trigger");
|
|
548
548
|
return { actionId: receipt.actionId };
|
|
549
549
|
}
|
|
550
550
|
catch (error) {
|
|
@@ -580,7 +580,7 @@ class NordUser extends NordClient_1.NordClient {
|
|
|
580
580
|
accountId: params.accountId,
|
|
581
581
|
}),
|
|
582
582
|
});
|
|
583
|
-
|
|
583
|
+
(0, actions_1.expectReceiptKind)(receipt, "triggerRemoved", "remove trigger");
|
|
584
584
|
return { actionId: receipt.actionId };
|
|
585
585
|
}
|
|
586
586
|
catch (error) {
|
|
@@ -611,7 +611,7 @@ class NordUser extends NordClient_1.NordClient {
|
|
|
611
611
|
amount,
|
|
612
612
|
}),
|
|
613
613
|
});
|
|
614
|
-
|
|
614
|
+
(0, actions_1.expectReceiptKind)(receipt, "transferred", "transfer tokens");
|
|
615
615
|
}
|
|
616
616
|
catch (error) {
|
|
617
617
|
throw new NordError_1.NordError("Failed to transfer tokens", { cause: error });
|
package/dist/nord/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export { Nord } from "./client/Nord";
|
|
2
2
|
export { NordUser } from "./client/NordUser";
|
|
3
|
-
export { NordAdmin } from "./client/NordAdmin";
|
|
3
|
+
export { NordAdmin, AclRole } from "./client/NordAdmin";
|
|
4
4
|
export { NordClient } from "./client/NordClient";
|
|
5
5
|
export type { NordClientParams } from "./client/NordClient";
|
|
6
|
-
export type { CreateTokenParams, CreateMarketParams, PythSetWormholeGuardiansParams, PythSetSymbolFeedParams, FreezeMarketParams, UnfreezeMarketParams,
|
|
6
|
+
export type { CreateTokenParams, CreateMarketParams, PythSetWormholeGuardiansParams, PythSetSymbolFeedParams, FreezeMarketParams, UnfreezeMarketParams, } from "./client/NordAdmin";
|
|
7
7
|
export { NordError } from "./utils/NordError";
|
|
8
8
|
export * from "./api/core";
|
|
9
9
|
export * from "./api/metrics";
|
package/dist/nord/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.NordError = exports.NordClient = exports.NordAdmin = exports.NordUser = exports.Nord = void 0;
|
|
17
|
+
exports.NordError = exports.NordClient = exports.AclRole = exports.NordAdmin = exports.NordUser = exports.Nord = void 0;
|
|
18
18
|
// Export main client classes
|
|
19
19
|
var Nord_1 = require("./client/Nord");
|
|
20
20
|
Object.defineProperty(exports, "Nord", { enumerable: true, get: function () { return Nord_1.Nord; } });
|
|
@@ -22,6 +22,7 @@ var NordUser_1 = require("./client/NordUser");
|
|
|
22
22
|
Object.defineProperty(exports, "NordUser", { enumerable: true, get: function () { return NordUser_1.NordUser; } });
|
|
23
23
|
var NordAdmin_1 = require("./client/NordAdmin");
|
|
24
24
|
Object.defineProperty(exports, "NordAdmin", { enumerable: true, get: function () { return NordAdmin_1.NordAdmin; } });
|
|
25
|
+
Object.defineProperty(exports, "AclRole", { enumerable: true, get: function () { return NordAdmin_1.AclRole; } });
|
|
25
26
|
var NordClient_1 = require("./client/NordClient");
|
|
26
27
|
Object.defineProperty(exports, "NordClient", { enumerable: true, get: function () { return NordClient_1.NordClient; } });
|
|
27
28
|
// Export utility classes
|
package/dist/types.d.ts
CHANGED
|
@@ -37,6 +37,8 @@ export interface NordConfig {
|
|
|
37
37
|
app: string;
|
|
38
38
|
/** Solana cluster URL */
|
|
39
39
|
solanaUrl: string;
|
|
40
|
+
/** Proton URL, defaults to webServerUrl */
|
|
41
|
+
protonUrl?: string;
|
|
40
42
|
/**
|
|
41
43
|
* Whether to initialize WebSockets on creation, defaults to true
|
|
42
44
|
* @deprecated this is a funky api we're gonna be removing it
|
|
@@ -78,6 +80,11 @@ export type AccountPnlPage = components["schemas"]["PageResult_for_uint64_and_Ac
|
|
|
78
80
|
export type AccountTriggerInfo = components["schemas"]["AccountTriggerInfo"];
|
|
79
81
|
export type TriggerHistoryPage = components["schemas"]["PageResult_for_uint64_and_HistoryTriggerInfo"];
|
|
80
82
|
export type HistoryTriggerQuery = components["schemas"]["AccountTriggersQuery"];
|
|
83
|
+
export type FeeTierConfig = components["schemas"]["FeeTierConfig"];
|
|
84
|
+
export type FeeTierId = components["schemas"]["FeeTierId"];
|
|
85
|
+
export type TokenStats = components["schemas"]["TokenStats"];
|
|
86
|
+
export type AccountFeeTier = components["schemas"]["AccountFeeTier"];
|
|
87
|
+
export type AccountFeeTierPage = components["schemas"]["PageResult_for_uint32_and_AccountFeeTier"];
|
|
81
88
|
/**
|
|
82
89
|
* Configuration options for the Nord client
|
|
83
90
|
*/
|
package/dist/utils.d.ts
CHANGED
|
@@ -79,6 +79,7 @@ export declare const toScaledU128: (x: Decimal.Value, decimals: number) => bigin
|
|
|
79
79
|
*/
|
|
80
80
|
export declare function decodeLengthDelimited<T extends Message>(bytes: Uint8Array, schema: GenMessage<T>): T;
|
|
81
81
|
export declare function checkPubKeyLength(keyType: KeyType, len: number): void;
|
|
82
|
+
export declare function decodeHex(value: string): Uint8Array;
|
|
82
83
|
export declare function findMarket(markets: Market[], marketId: number): Market;
|
|
83
84
|
export declare function findToken(tokens: Token[], tokenId: number): Token;
|
|
84
85
|
export declare function keypairFromPrivateKey(privateKey: string | Uint8Array): Keypair;
|
package/dist/utils.js
CHANGED
|
@@ -13,6 +13,7 @@ exports.signAction = signAction;
|
|
|
13
13
|
exports.makeWalletSignFn = makeWalletSignFn;
|
|
14
14
|
exports.decodeLengthDelimited = decodeLengthDelimited;
|
|
15
15
|
exports.checkPubKeyLength = checkPubKeyLength;
|
|
16
|
+
exports.decodeHex = decodeHex;
|
|
16
17
|
exports.findMarket = findMarket;
|
|
17
18
|
exports.findToken = findToken;
|
|
18
19
|
exports.keypairFromPrivateKey = keypairFromPrivateKey;
|
|
@@ -195,6 +196,10 @@ function checkPubKeyLength(keyType, len) {
|
|
|
195
196
|
throw new Error("Secp256k1 pubkeys must be 33 length.");
|
|
196
197
|
}
|
|
197
198
|
}
|
|
199
|
+
function decodeHex(value) {
|
|
200
|
+
const hex = value.startsWith("0x") ? value.slice(2) : value;
|
|
201
|
+
return Uint8Array.from(Buffer.from(hex, "hex"));
|
|
202
|
+
}
|
|
198
203
|
function findMarket(markets, marketId) {
|
|
199
204
|
if (marketId < 0 || markets.length - 1 < marketId) {
|
|
200
205
|
throw new Error(`The market with marketId=${marketId} not found`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@n1xyz/nord-ts",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Typescript for Nord",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@bufbuild/protobuf": "^2.6.3",
|
|
48
|
-
"@n1xyz/proton": "0.0.
|
|
48
|
+
"@n1xyz/proton": "0.0.6",
|
|
49
49
|
"@noble/curves": "^1.9.6",
|
|
50
50
|
"@noble/ed25519": "^2.3.0",
|
|
51
51
|
"@noble/hashes": "^1.8.0",
|