@n1xyz/nord-ts 0.1.5 → 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 +233 -7
- package/dist/gen/nord_pb.js +34 -8
- package/dist/nord/client/Nord.d.ts +1 -1
- package/dist/nord/client/Nord.js +2 -2
- package/dist/nord/client/NordAdmin.d.ts +24 -1
- package/dist/nord/client/NordAdmin.js +61 -5
- package/dist/nord/index.d.ts +1 -1
- package/dist/nord/index.js +2 -1
- package/dist/types.d.ts +2 -0
- package/package.json +1 -1
- package/src/gen/nord_pb.ts +271 -9
- package/src/nord/client/Nord.ts +2 -1
- package/src/nord/client/NordAdmin.ts +75 -2
- package/src/nord/index.ts +1 -1
- package/src/types.ts +3 -0
|
@@ -2,6 +2,11 @@ import { PublicKey } from "@solana/web3.js";
|
|
|
2
2
|
import * as proto from "../../gen/nord_pb";
|
|
3
3
|
import { Nord } from "./Nord";
|
|
4
4
|
import { FeeTierConfig } from "../../gen/nord_pb";
|
|
5
|
+
export declare enum AclRole {
|
|
6
|
+
FEE_MANAGER = 1,
|
|
7
|
+
MARKET_MANAGER = 2,
|
|
8
|
+
ADMIN = -2147483648
|
|
9
|
+
}
|
|
5
10
|
/**
|
|
6
11
|
* Parameters required to register a new token via the admin API.
|
|
7
12
|
*/
|
|
@@ -70,11 +75,13 @@ export interface UpdateFeeTierParams {
|
|
|
70
75
|
*/
|
|
71
76
|
export declare class NordAdmin {
|
|
72
77
|
private readonly nord;
|
|
78
|
+
private readonly admin;
|
|
73
79
|
private readonly signFn;
|
|
74
80
|
private constructor();
|
|
75
81
|
/** Create a new admin client.
|
|
76
82
|
*
|
|
77
83
|
* @param nord - Nord instance
|
|
84
|
+
* @param admin - The user that will be signing actions.
|
|
78
85
|
* @param signFn - Function to sign messages with the admin's wallet.
|
|
79
86
|
*
|
|
80
87
|
* `signFn` must sign the _hex-encoded_ message, not the raw message itself, for
|
|
@@ -94,8 +101,9 @@ export declare class NordAdmin {
|
|
|
94
101
|
*
|
|
95
102
|
* where `nacl` is the tweetnacl library.
|
|
96
103
|
*/
|
|
97
|
-
static new({ nord, signFn, }: Readonly<{
|
|
104
|
+
static new({ nord, admin, signFn, }: Readonly<{
|
|
98
105
|
nord: Nord;
|
|
106
|
+
admin: PublicKey;
|
|
99
107
|
signFn: (m: Uint8Array) => Promise<Uint8Array>;
|
|
100
108
|
}>): NordAdmin;
|
|
101
109
|
/**
|
|
@@ -105,6 +113,21 @@ export declare class NordAdmin {
|
|
|
105
113
|
* @throws {NordError} If signing or submission fails
|
|
106
114
|
*/
|
|
107
115
|
private submitAction;
|
|
116
|
+
/** Set acl permissions for a given user.
|
|
117
|
+
*
|
|
118
|
+
* If all roles are removed, the user is removed from the acl.
|
|
119
|
+
*
|
|
120
|
+
* @param target - User to update.
|
|
121
|
+
* @param addRoles - Roles to add to the user.
|
|
122
|
+
* @param removeRoles - Reles to remove from the user.
|
|
123
|
+
*/
|
|
124
|
+
updateAcl({ target, addRoles, removeRoles, }: Readonly<{
|
|
125
|
+
target: PublicKey;
|
|
126
|
+
addRoles: AclRole[];
|
|
127
|
+
removeRoles: AclRole[];
|
|
128
|
+
}>): Promise<{
|
|
129
|
+
actionId: bigint;
|
|
130
|
+
} & proto.Receipt_AclUpdated>;
|
|
108
131
|
/**
|
|
109
132
|
* Register a new token that can be listed on Nord.
|
|
110
133
|
*
|
|
@@ -33,23 +33,34 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.NordAdmin = void 0;
|
|
36
|
+
exports.NordAdmin = exports.AclRole = void 0;
|
|
37
37
|
const protobuf_1 = require("@bufbuild/protobuf");
|
|
38
38
|
const proto = __importStar(require("../../gen/nord_pb"));
|
|
39
39
|
const utils_1 = require("../../utils");
|
|
40
40
|
const actions_1 = require("../api/actions");
|
|
41
41
|
const NordError_1 = require("../utils/NordError");
|
|
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 = {}));
|
|
42
51
|
/**
|
|
43
52
|
* Administrative client capable of submitting privileged configuration actions.
|
|
44
53
|
*/
|
|
45
54
|
class NordAdmin {
|
|
46
|
-
constructor({ nord, signFn, }) {
|
|
55
|
+
constructor({ nord, admin, signFn, }) {
|
|
47
56
|
this.nord = nord;
|
|
57
|
+
this.admin = admin;
|
|
48
58
|
this.signFn = signFn;
|
|
49
59
|
}
|
|
50
60
|
/** Create a new admin client.
|
|
51
61
|
*
|
|
52
62
|
* @param nord - Nord instance
|
|
63
|
+
* @param admin - The user that will be signing actions.
|
|
53
64
|
* @param signFn - Function to sign messages with the admin's wallet.
|
|
54
65
|
*
|
|
55
66
|
* `signFn` must sign the _hex-encoded_ message, not the raw message itself, for
|
|
@@ -69,9 +80,10 @@ class NordAdmin {
|
|
|
69
80
|
*
|
|
70
81
|
* where `nacl` is the tweetnacl library.
|
|
71
82
|
*/
|
|
72
|
-
static new({ nord, signFn, }) {
|
|
83
|
+
static new({ nord, admin, signFn, }) {
|
|
73
84
|
return new NordAdmin({
|
|
74
85
|
nord,
|
|
86
|
+
admin,
|
|
75
87
|
signFn,
|
|
76
88
|
});
|
|
77
89
|
}
|
|
@@ -92,6 +104,37 @@ class NordAdmin {
|
|
|
92
104
|
return Uint8Array.from([...xs, ...signature]);
|
|
93
105
|
}, action);
|
|
94
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");
|
|
119
|
+
}
|
|
120
|
+
let mask = 0;
|
|
121
|
+
let values = 0;
|
|
122
|
+
for (const role of allRoles) {
|
|
123
|
+
mask |= role;
|
|
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 };
|
|
137
|
+
}
|
|
95
138
|
/**
|
|
96
139
|
* Register a new token that can be listed on Nord.
|
|
97
140
|
*
|
|
@@ -103,6 +146,7 @@ class NordAdmin {
|
|
|
103
146
|
const receipt = await this.submitAction({
|
|
104
147
|
case: "createToken",
|
|
105
148
|
value: (0, protobuf_1.create)(proto.Action_CreateTokenSchema, {
|
|
149
|
+
aclPubkey: this.admin.toBytes(),
|
|
106
150
|
tokenDecimals,
|
|
107
151
|
weightBps,
|
|
108
152
|
viewSymbol,
|
|
@@ -124,6 +168,7 @@ class NordAdmin {
|
|
|
124
168
|
const receipt = await this.submitAction({
|
|
125
169
|
case: "createMarket",
|
|
126
170
|
value: (0, protobuf_1.create)(proto.Action_CreateMarketSchema, {
|
|
171
|
+
aclPubkey: this.admin.toBytes(),
|
|
127
172
|
sizeDecimals: params.sizeDecimals,
|
|
128
173
|
priceDecimals: params.priceDecimals,
|
|
129
174
|
imfBps: params.imfBps,
|
|
@@ -165,6 +210,7 @@ class NordAdmin {
|
|
|
165
210
|
const receipt = await this.submitAction({
|
|
166
211
|
case: "pythSetWormholeGuardians",
|
|
167
212
|
value: (0, protobuf_1.create)(proto.Action_PythSetWormholeGuardiansSchema, {
|
|
213
|
+
aclPubkey: this.admin.toBytes(),
|
|
168
214
|
guardianSetIndex: params.guardianSetIndex,
|
|
169
215
|
addresses,
|
|
170
216
|
}),
|
|
@@ -199,6 +245,7 @@ class NordAdmin {
|
|
|
199
245
|
const receipt = await this.submitAction({
|
|
200
246
|
case: "pythSetSymbolFeed",
|
|
201
247
|
value: (0, protobuf_1.create)(proto.Action_PythSetSymbolFeedSchema, {
|
|
248
|
+
aclPubkey: this.admin.toBytes(),
|
|
202
249
|
oracleSymbol: params.oracleSymbol,
|
|
203
250
|
priceFeedId,
|
|
204
251
|
}),
|
|
@@ -215,7 +262,9 @@ class NordAdmin {
|
|
|
215
262
|
async pause() {
|
|
216
263
|
const receipt = await this.submitAction({
|
|
217
264
|
case: "pause",
|
|
218
|
-
value: (0, protobuf_1.create)(proto.Action_PauseSchema, {
|
|
265
|
+
value: (0, protobuf_1.create)(proto.Action_PauseSchema, {
|
|
266
|
+
aclPubkey: this.admin.toBytes(),
|
|
267
|
+
}),
|
|
219
268
|
});
|
|
220
269
|
(0, actions_1.expectReceiptKind)(receipt, "paused", "pause");
|
|
221
270
|
return { actionId: receipt.actionId };
|
|
@@ -229,7 +278,9 @@ class NordAdmin {
|
|
|
229
278
|
async unpause() {
|
|
230
279
|
const receipt = await this.submitAction({
|
|
231
280
|
case: "unpause",
|
|
232
|
-
value: (0, protobuf_1.create)(proto.Action_UnpauseSchema, {
|
|
281
|
+
value: (0, protobuf_1.create)(proto.Action_UnpauseSchema, {
|
|
282
|
+
aclPubkey: this.admin.toBytes(),
|
|
283
|
+
}),
|
|
233
284
|
});
|
|
234
285
|
(0, actions_1.expectReceiptKind)(receipt, "unpaused", "unpause");
|
|
235
286
|
return { actionId: receipt.actionId };
|
|
@@ -246,6 +297,7 @@ class NordAdmin {
|
|
|
246
297
|
case: "freezeMarket",
|
|
247
298
|
value: (0, protobuf_1.create)(proto.Action_FreezeMarketSchema, {
|
|
248
299
|
marketId: params.marketId,
|
|
300
|
+
aclPubkey: this.admin.toBytes(),
|
|
249
301
|
}),
|
|
250
302
|
});
|
|
251
303
|
(0, actions_1.expectReceiptKind)(receipt, "marketFreezeUpdated", "freeze market");
|
|
@@ -263,6 +315,7 @@ class NordAdmin {
|
|
|
263
315
|
case: "unfreezeMarket",
|
|
264
316
|
value: (0, protobuf_1.create)(proto.Action_UnfreezeMarketSchema, {
|
|
265
317
|
marketId: params.marketId,
|
|
318
|
+
aclPubkey: this.admin.toBytes(),
|
|
266
319
|
}),
|
|
267
320
|
});
|
|
268
321
|
(0, actions_1.expectReceiptKind)(receipt, "marketFreezeUpdated", "unfreeze market");
|
|
@@ -283,6 +336,7 @@ class NordAdmin {
|
|
|
283
336
|
const receipt = await this.submitAction({
|
|
284
337
|
case: "addFeeTier",
|
|
285
338
|
value: (0, protobuf_1.create)(proto.Action_AddFeeTierSchema, {
|
|
339
|
+
aclPubkey: this.admin.toBytes(),
|
|
286
340
|
config: (0, protobuf_1.create)(proto.FeeTierConfigSchema, params.config),
|
|
287
341
|
}),
|
|
288
342
|
});
|
|
@@ -303,6 +357,7 @@ class NordAdmin {
|
|
|
303
357
|
const receipt = await this.submitAction({
|
|
304
358
|
case: "updateFeeTier",
|
|
305
359
|
value: (0, protobuf_1.create)(proto.Action_UpdateFeeTierSchema, {
|
|
360
|
+
aclPubkey: this.admin.toBytes(),
|
|
306
361
|
id: params.tierId,
|
|
307
362
|
config: (0, protobuf_1.create)(proto.FeeTierConfigSchema, params.config),
|
|
308
363
|
}),
|
|
@@ -326,6 +381,7 @@ class NordAdmin {
|
|
|
326
381
|
const receipt = await this.submitAction({
|
|
327
382
|
case: "updateAccountsTier",
|
|
328
383
|
value: (0, protobuf_1.create)(proto.Action_UpdateAccountsTierSchema, {
|
|
384
|
+
aclPubkey: this.admin.toBytes(),
|
|
329
385
|
accounts,
|
|
330
386
|
tierId,
|
|
331
387
|
}),
|
package/dist/nord/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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
6
|
export type { CreateTokenParams, CreateMarketParams, PythSetWormholeGuardiansParams, PythSetSymbolFeedParams, FreezeMarketParams, UnfreezeMarketParams, } from "./client/NordAdmin";
|
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
|