@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.
@@ -7,6 +7,15 @@ import { NordError } from "../utils/NordError";
7
7
  import { Nord } from "./Nord";
8
8
  import { FeeTierConfig } from "../../gen/nord_pb";
9
9
 
10
+ // NOTE: keep in sync with `acl.rs`.
11
+ // NOTE: don't forget `number` as int is internally a u32.
12
+ export enum AclRole {
13
+ FEE_MANAGER = 1 << 0,
14
+ MARKET_MANAGER = 1 << 1,
15
+ // TODO: unsure about this?
16
+ ADMIN = 1 << 31,
17
+ }
18
+
10
19
  /**
11
20
  * Parameters required to register a new token via the admin API.
12
21
  */
@@ -83,22 +92,27 @@ export interface UpdateFeeTierParams {
83
92
  */
84
93
  export class NordAdmin {
85
94
  private readonly nord: Nord;
95
+ private readonly admin: PublicKey;
86
96
  private readonly signFn: (x: Uint8Array) => Promise<Uint8Array>;
87
97
 
88
98
  private constructor({
89
99
  nord,
100
+ admin,
90
101
  signFn,
91
102
  }: {
92
103
  nord: Nord;
104
+ admin: PublicKey;
93
105
  signFn: (x: Uint8Array) => Promise<Uint8Array>;
94
106
  }) {
95
107
  this.nord = nord;
108
+ this.admin = admin;
96
109
  this.signFn = signFn;
97
110
  }
98
111
 
99
112
  /** Create a new admin client.
100
113
  *
101
114
  * @param nord - Nord instance
115
+ * @param admin - The user that will be signing actions.
102
116
  * @param signFn - Function to sign messages with the admin's wallet.
103
117
  *
104
118
  * `signFn` must sign the _hex-encoded_ message, not the raw message itself, for
@@ -120,13 +134,16 @@ export class NordAdmin {
120
134
  */
121
135
  public static new({
122
136
  nord,
137
+ admin,
123
138
  signFn,
124
139
  }: Readonly<{
125
140
  nord: Nord;
141
+ admin: PublicKey;
126
142
  signFn: (m: Uint8Array) => Promise<Uint8Array>;
127
143
  }>): NordAdmin {
128
144
  return new NordAdmin({
129
145
  nord,
146
+ admin,
130
147
  signFn,
131
148
  });
132
149
  }
@@ -155,6 +172,49 @@ export class NordAdmin {
155
172
  );
156
173
  }
157
174
 
175
+ /** Set acl permissions for a given user.
176
+ *
177
+ * If all roles are removed, the user is removed from the acl.
178
+ *
179
+ * @param target - User to update.
180
+ * @param addRoles - Roles to add to the user.
181
+ * @param removeRoles - Reles to remove from the user.
182
+ */
183
+ async updateAcl({
184
+ target,
185
+ addRoles,
186
+ removeRoles,
187
+ }: Readonly<{
188
+ target: PublicKey;
189
+ addRoles: AclRole[];
190
+ removeRoles: AclRole[];
191
+ }>): Promise<{ actionId: bigint } & proto.Receipt_AclUpdated> {
192
+ const allRoles = addRoles.concat(removeRoles);
193
+ if (allRoles.length !== new Set(allRoles).size) {
194
+ throw new NordError("duplicate roles in acl update; must be unique");
195
+ }
196
+
197
+ let mask = 0;
198
+ let values = 0;
199
+ for (const role of allRoles) {
200
+ mask |= role;
201
+ }
202
+ for (const role of addRoles) {
203
+ values |= role;
204
+ }
205
+
206
+ const receipt = await this.submitAction({
207
+ case: "updateAcl",
208
+ value: create(proto.Action_UpdateAclSchema, {
209
+ aclPubkey: this.admin.toBytes(),
210
+ targetPubkey: target.toBytes(),
211
+ }),
212
+ });
213
+ expectReceiptKind(receipt, "aclUpdated", "update acl");
214
+
215
+ return { ...receipt.kind.value, actionId: receipt.actionId };
216
+ }
217
+
158
218
  /**
159
219
  * Register a new token that can be listed on Nord.
160
220
  *
@@ -174,6 +234,7 @@ export class NordAdmin {
174
234
  const receipt = await this.submitAction({
175
235
  case: "createToken",
176
236
  value: create(proto.Action_CreateTokenSchema, {
237
+ aclPubkey: this.admin.toBytes(),
177
238
  tokenDecimals,
178
239
  weightBps,
179
240
  viewSymbol,
@@ -198,6 +259,7 @@ export class NordAdmin {
198
259
  const receipt = await this.submitAction({
199
260
  case: "createMarket",
200
261
  value: create(proto.Action_CreateMarketSchema, {
262
+ aclPubkey: this.admin.toBytes(),
201
263
  sizeDecimals: params.sizeDecimals,
202
264
  priceDecimals: params.priceDecimals,
203
265
  imfBps: params.imfBps,
@@ -245,6 +307,7 @@ export class NordAdmin {
245
307
  const receipt = await this.submitAction({
246
308
  case: "pythSetWormholeGuardians",
247
309
  value: create(proto.Action_PythSetWormholeGuardiansSchema, {
310
+ aclPubkey: this.admin.toBytes(),
248
311
  guardianSetIndex: params.guardianSetIndex,
249
312
  addresses,
250
313
  }),
@@ -286,6 +349,7 @@ export class NordAdmin {
286
349
  const receipt = await this.submitAction({
287
350
  case: "pythSetSymbolFeed",
288
351
  value: create(proto.Action_PythSetSymbolFeedSchema, {
352
+ aclPubkey: this.admin.toBytes(),
289
353
  oracleSymbol: params.oracleSymbol,
290
354
  priceFeedId,
291
355
  }),
@@ -303,7 +367,9 @@ export class NordAdmin {
303
367
  async pause(): Promise<{ actionId: bigint }> {
304
368
  const receipt = await this.submitAction({
305
369
  case: "pause",
306
- value: create(proto.Action_PauseSchema, {}),
370
+ value: create(proto.Action_PauseSchema, {
371
+ aclPubkey: this.admin.toBytes(),
372
+ }),
307
373
  });
308
374
  expectReceiptKind(receipt, "paused", "pause");
309
375
  return { actionId: receipt.actionId };
@@ -318,7 +384,9 @@ export class NordAdmin {
318
384
  async unpause(): Promise<{ actionId: bigint }> {
319
385
  const receipt = await this.submitAction({
320
386
  case: "unpause",
321
- value: create(proto.Action_UnpauseSchema, {}),
387
+ value: create(proto.Action_UnpauseSchema, {
388
+ aclPubkey: this.admin.toBytes(),
389
+ }),
322
390
  });
323
391
  expectReceiptKind(receipt, "unpaused", "unpause");
324
392
  return { actionId: receipt.actionId };
@@ -338,6 +406,7 @@ export class NordAdmin {
338
406
  case: "freezeMarket",
339
407
  value: create(proto.Action_FreezeMarketSchema, {
340
408
  marketId: params.marketId,
409
+ aclPubkey: this.admin.toBytes(),
341
410
  }),
342
411
  });
343
412
  expectReceiptKind(receipt, "marketFreezeUpdated", "freeze market");
@@ -358,6 +427,7 @@ export class NordAdmin {
358
427
  case: "unfreezeMarket",
359
428
  value: create(proto.Action_UnfreezeMarketSchema, {
360
429
  marketId: params.marketId,
430
+ aclPubkey: this.admin.toBytes(),
361
431
  }),
362
432
  });
363
433
  expectReceiptKind(receipt, "marketFreezeUpdated", "unfreeze market");
@@ -381,6 +451,7 @@ export class NordAdmin {
381
451
  const receipt = await this.submitAction({
382
452
  case: "addFeeTier",
383
453
  value: create(proto.Action_AddFeeTierSchema, {
454
+ aclPubkey: this.admin.toBytes(),
384
455
  config: create(proto.FeeTierConfigSchema, params.config),
385
456
  }),
386
457
  });
@@ -404,6 +475,7 @@ export class NordAdmin {
404
475
  const receipt = await this.submitAction({
405
476
  case: "updateFeeTier",
406
477
  value: create(proto.Action_UpdateFeeTierSchema, {
478
+ aclPubkey: this.admin.toBytes(),
407
479
  id: params.tierId,
408
480
  config: create(proto.FeeTierConfigSchema, params.config),
409
481
  }),
@@ -431,6 +503,7 @@ export class NordAdmin {
431
503
  const receipt = await this.submitAction({
432
504
  case: "updateAccountsTier",
433
505
  value: create(proto.Action_UpdateAccountsTierSchema, {
506
+ aclPubkey: this.admin.toBytes(),
434
507
  accounts,
435
508
  tierId,
436
509
  }),
package/src/nord/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  // Export main client classes
2
2
  export { Nord } from "./client/Nord";
3
3
  export { NordUser } from "./client/NordUser";
4
- export { NordAdmin } from "./client/NordAdmin";
4
+ export { NordAdmin, AclRole } from "./client/NordAdmin";
5
5
  export { NordClient } from "./client/NordClient";
6
6
  export type { NordClientParams } from "./client/NordClient";
7
7
  export type {
package/src/types.ts CHANGED
@@ -42,6 +42,9 @@ export interface NordConfig {
42
42
  app: string;
43
43
  /** Solana cluster URL */
44
44
  solanaUrl: string;
45
+ /** Proton URL, defaults to webServerUrl */
46
+ // TODO: this is ass. move to NordUser.
47
+ protonUrl?: string;
45
48
  /**
46
49
  * Whether to initialize WebSockets on creation, defaults to true
47
50
  * @deprecated this is a funky api we're gonna be removing it