@n1xyz/nord-ts 0.1.7 → 0.1.9

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.
Files changed (84) hide show
  1. package/dist/actions.js +39 -82
  2. package/dist/bundle.js +79181 -0
  3. package/dist/client/Nord.d.ts +13 -2
  4. package/dist/client/Nord.js +68 -78
  5. package/dist/client/NordAdmin.d.ts +2 -2
  6. package/dist/client/NordAdmin.js +57 -89
  7. package/dist/client/NordUser.js +118 -147
  8. package/dist/const.js +5 -8
  9. package/dist/error.js +7 -5
  10. package/dist/gen/nord_pb.js +88 -92
  11. package/dist/gen/openapi.d.ts +83 -6
  12. package/dist/gen/openapi.js +1 -2
  13. package/dist/index.js +10 -49
  14. package/dist/types.d.ts +3 -0
  15. package/dist/types.js +21 -60
  16. package/dist/utils.js +38 -86
  17. package/dist/websocket/NordWebSocketClient.js +12 -17
  18. package/dist/websocket/Subscriber.js +6 -7
  19. package/dist/websocket/events.js +1 -2
  20. package/dist/websocket/index.js +10 -15
  21. package/package.json +3 -4
  22. package/dist/api/client.d.ts +0 -14
  23. package/dist/api/client.js +0 -45
  24. package/dist/bridge/client.d.ts +0 -151
  25. package/dist/bridge/client.js +0 -434
  26. package/dist/bridge/const.d.ts +0 -23
  27. package/dist/bridge/const.js +0 -47
  28. package/dist/bridge/index.d.ts +0 -4
  29. package/dist/bridge/index.js +0 -23
  30. package/dist/bridge/types.d.ts +0 -120
  31. package/dist/bridge/types.js +0 -18
  32. package/dist/bridge/utils.d.ts +0 -64
  33. package/dist/bridge/utils.js +0 -131
  34. package/dist/gen/common.d.ts +0 -68
  35. package/dist/gen/common.js +0 -215
  36. package/dist/gen/nord.d.ts +0 -882
  37. package/dist/gen/nord.js +0 -6520
  38. package/dist/idl/bridge.d.ts +0 -569
  39. package/dist/idl/bridge.js +0 -8
  40. package/dist/idl/bridge.json +0 -1506
  41. package/dist/idl/index.d.ts +0 -607
  42. package/dist/idl/index.js +0 -8
  43. package/dist/nord/api/actions.d.ts +0 -126
  44. package/dist/nord/api/actions.js +0 -397
  45. package/dist/nord/api/core.d.ts +0 -16
  46. package/dist/nord/api/core.js +0 -81
  47. package/dist/nord/api/market.d.ts +0 -36
  48. package/dist/nord/api/market.js +0 -96
  49. package/dist/nord/api/metrics.d.ts +0 -67
  50. package/dist/nord/api/metrics.js +0 -229
  51. package/dist/nord/api/queries.d.ts +0 -46
  52. package/dist/nord/api/queries.js +0 -109
  53. package/dist/nord/api/triggers.d.ts +0 -7
  54. package/dist/nord/api/triggers.js +0 -38
  55. package/dist/nord/client/Nord.d.ts +0 -396
  56. package/dist/nord/client/Nord.js +0 -747
  57. package/dist/nord/client/NordAdmin.d.ts +0 -259
  58. package/dist/nord/client/NordAdmin.js +0 -395
  59. package/dist/nord/client/NordClient.d.ts +0 -33
  60. package/dist/nord/client/NordClient.js +0 -45
  61. package/dist/nord/client/NordUser.d.ts +0 -362
  62. package/dist/nord/client/NordUser.js +0 -781
  63. package/dist/nord/index.d.ts +0 -11
  64. package/dist/nord/index.js +0 -36
  65. package/dist/nord/models/Subscriber.d.ts +0 -37
  66. package/dist/nord/models/Subscriber.js +0 -25
  67. package/dist/nord/utils/NordError.d.ts +0 -35
  68. package/dist/nord/utils/NordError.js +0 -49
  69. package/src/actions.ts +0 -333
  70. package/src/client/Nord.ts +0 -934
  71. package/src/client/NordAdmin.ts +0 -484
  72. package/src/client/NordUser.ts +0 -1122
  73. package/src/const.ts +0 -34
  74. package/src/error.ts +0 -76
  75. package/src/gen/.gitkeep +0 -0
  76. package/src/gen/nord_pb.ts +0 -5053
  77. package/src/gen/openapi.ts +0 -2904
  78. package/src/index.ts +0 -11
  79. package/src/types.ts +0 -327
  80. package/src/utils.ts +0 -266
  81. package/src/websocket/NordWebSocketClient.ts +0 -316
  82. package/src/websocket/Subscriber.ts +0 -56
  83. package/src/websocket/events.ts +0 -31
  84. package/src/websocket/index.ts +0 -105
@@ -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, AccountPnlQuery, ActionResponse, MarketsInfo, Market, MarketStats, NordConfig, OrderbookQuery, OrderbookResponse, FeeTierConfig, Token, TradesResponse, User, AccountTriggerInfo, HistoryTriggerQuery, TriggerHistoryPage, FeeTierId, AccountFeeTierPage, PageResultStringOrderInfo, PageResultStringTrade, OrderInfoFromApi, TokenStats, FillRole } from "../types";
6
+ import { Account, AccountPnlPage, AccountPnlQuery, ActionResponse, MarketsInfo, Market, MarketStats, NordConfig, OrderbookQuery, OrderbookResponse, FeeTierConfig, Token, TradesResponse, User, AccountTriggerInfo, HistoryTriggerQuery, TriggerHistoryPage, FeeTierId, AccountFeeTierPage, PageResultStringOrderInfo, PageResultStringTrade, OrderInfoFromApi, TokenStats, FillRole, AdminInfo, AccountVolumeInfo, GetAccountVolumeQuery } from "../types";
7
7
  import { NordWebSocketClient } from "../websocket/index";
8
8
  import { OrderbookSubscription, TradeSubscription } from "../websocket/Subscriber";
9
9
  /**
@@ -88,7 +88,18 @@ export declare class Nord {
88
88
  * @returns List of admin registration keys paired with their ACL role mask
89
89
  * @throws {NordError} If the request fails
90
90
  */
91
- getAdminList(): Promise<Array<[string, number]>>;
91
+ getAdminList(): Promise<Array<AdminInfo>>;
92
+ /**
93
+ * Get account volume across all markets, optionally for a specific market.
94
+ *
95
+ * @param accountId - Account identifier
96
+ * @param since - RFC3339 timestamp marking the inclusive start of the window
97
+ * @param until - RFC3339 timestamp marking the exclusive end of the window
98
+ * @param marketId - Optional market identifier to scope the volume
99
+ * @returns Array of market volumes (single entry when `marketId` is provided)
100
+ * @throws {NordError} If the request fails
101
+ */
102
+ getAccountVolume({ accountId, since, until, marketId, }: Readonly<GetAccountVolumeQuery>): Promise<Array<AccountVolumeInfo>>;
92
103
  /**
93
104
  * Fetch information about Nord markets and tokens
94
105
  *
@@ -1,54 +1,29 @@
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.Nord = void 0;
40
- const proton_1 = require("@n1xyz/proton");
41
- const web3_js_1 = require("@solana/web3.js");
42
- const events_1 = require("events");
43
- const openapi_fetch_1 = __importDefault(require("openapi-fetch"));
44
- const proto = __importStar(require("../gen/nord_pb"));
45
- const utils = __importStar(require("../utils"));
46
- const websocket_1 = require("../websocket");
47
- const error_1 = require("../error");
1
+ import { ProtonClient } from "@n1xyz/proton";
2
+ import { PublicKey } from "@solana/web3.js";
3
+ import { EventEmitter } from "events";
4
+ import createClient from "openapi-fetch";
5
+ import * as proto from "../gen/nord_pb";
6
+ import * as utils from "../utils";
7
+ import { initWebSocketClient } from "../websocket";
8
+ import { NordError } from "../error";
48
9
  /**
49
10
  * Main Nord client class for interacting with the Nord API
50
11
  */
51
- class Nord {
12
+ export class Nord {
13
+ /** Base URL for the Nord web server */
14
+ webServerUrl;
15
+ /** Solana RPC URL */
16
+ solanaConnection;
17
+ /** Available markets */
18
+ markets = [];
19
+ /** Available tokens */
20
+ tokens = [];
21
+ /** Map of symbol to market_id */
22
+ symbolToMarketId = new Map();
23
+ /** Proton client for proton related operations */
24
+ protonClient;
25
+ /** HTTP client for Nord operations */
26
+ httpClient;
52
27
  /**
53
28
  * Create a new Nord client
54
29
  *
@@ -58,16 +33,10 @@ class Nord {
58
33
  * @throws {Error} If required configuration is missing
59
34
  */
60
35
  constructor({ solanaConnection, webServerUrl, protonClient, }) {
61
- /** Available markets */
62
- this.markets = [];
63
- /** Available tokens */
64
- this.tokens = [];
65
- /** Map of symbol to market_id */
66
- this.symbolToMarketId = new Map();
67
36
  this.webServerUrl = webServerUrl;
68
37
  this.solanaConnection = solanaConnection;
69
38
  this.protonClient = protonClient;
70
- this.httpClient = (0, openapi_fetch_1.default)({ baseUrl: webServerUrl });
39
+ this.httpClient = createClient({ baseUrl: webServerUrl });
71
40
  }
72
41
  /**
73
42
  * Create a WebSocket client with specific subscriptions
@@ -110,27 +79,27 @@ class Nord {
110
79
  if (accounts && accounts.length > 0) {
111
80
  accounts.forEach((accountId) => {
112
81
  if (isNaN(accountId) || accountId <= 0) {
113
- throw new error_1.NordError(`Invalid account ID: ${accountId}. Must be a positive number.`);
82
+ throw new NordError(`Invalid account ID: ${accountId}. Must be a positive number.`);
114
83
  }
115
84
  subscriptions.push(`account@${accountId}`);
116
85
  });
117
86
  }
118
87
  // Validate that at least one subscription was provided
119
88
  if (subscriptions.length === 0) {
120
- throw new error_1.NordError("At least one subscription must be provided");
89
+ throw new NordError("At least one subscription must be provided");
121
90
  }
122
91
  // Create and return a new WebSocket client
123
- return (0, websocket_1.initWebSocketClient)(this.webServerUrl, subscriptions);
92
+ return initWebSocketClient(this.webServerUrl, subscriptions);
124
93
  }
125
94
  async GET(path, options) {
126
95
  const r = await this.httpClient.GET(path, options);
127
96
  if (r.error) {
128
- throw new error_1.NordError(`failed to GET ${path}`, { cause: r.error });
97
+ throw new NordError(`failed to GET ${path}`, { cause: r.error });
129
98
  }
130
99
  if (r.data === undefined) {
131
100
  // this should never happen, but the type checker seems unhappy.
132
101
  // if we catch this we'll need to debug accordingly.
133
- throw new error_1.NordError("internal assertion violation", { cause: r });
102
+ throw new NordError("internal assertion violation", { cause: r });
134
103
  }
135
104
  return r.data;
136
105
  }
@@ -161,6 +130,28 @@ class Nord {
161
130
  async getAdminList() {
162
131
  return await this.GET("/admin", {});
163
132
  }
133
+ /**
134
+ * Get account volume across all markets, optionally for a specific market.
135
+ *
136
+ * @param accountId - Account identifier
137
+ * @param since - RFC3339 timestamp marking the inclusive start of the window
138
+ * @param until - RFC3339 timestamp marking the exclusive end of the window
139
+ * @param marketId - Optional market identifier to scope the volume
140
+ * @returns Array of market volumes (single entry when `marketId` is provided)
141
+ * @throws {NordError} If the request fails
142
+ */
143
+ async getAccountVolume({ accountId, since, until, marketId, }) {
144
+ return await this.GET("/account/volume", {
145
+ params: {
146
+ query: {
147
+ accountId,
148
+ since,
149
+ until,
150
+ marketId,
151
+ },
152
+ },
153
+ });
154
+ }
164
155
  /**
165
156
  * Fetch information about Nord markets and tokens
166
157
  *
@@ -178,7 +169,7 @@ class Nord {
178
169
  });
179
170
  }
180
171
  catch (error) {
181
- throw new error_1.NordError("Failed to fetch Nord info", { cause: error });
172
+ throw new NordError("Failed to fetch Nord info", { cause: error });
182
173
  }
183
174
  }
184
175
  /** @deprecated use Nord.new */
@@ -196,9 +187,9 @@ class Nord {
196
187
  * @throws {NordError} If initialization fails
197
188
  */
198
189
  static async new({ app, solanaConnection, webServerUrl, protonUrl, }) {
199
- const protonClient = await proton_1.ProtonClient.init({
190
+ const protonClient = await ProtonClient.init({
200
191
  protonUrl: protonUrl ?? webServerUrl,
201
- app: new web3_js_1.PublicKey(app),
192
+ app: new PublicKey(app),
202
193
  solConn: solanaConnection,
203
194
  });
204
195
  const nord = new Nord({
@@ -267,9 +258,9 @@ class Nord {
267
258
  */
268
259
  subscribeOrderbook(symbol) {
269
260
  if (!symbol || typeof symbol !== "string") {
270
- throw new error_1.NordError("Invalid market symbol");
261
+ throw new NordError("Invalid market symbol");
271
262
  }
272
- const subscription = new events_1.EventEmitter();
263
+ const subscription = new EventEmitter();
273
264
  const wsClient = this.createWebSocketClient({
274
265
  deltas: [symbol],
275
266
  });
@@ -295,9 +286,9 @@ class Nord {
295
286
  */
296
287
  subscribeTrades(symbol) {
297
288
  if (!symbol || typeof symbol !== "string") {
298
- throw new error_1.NordError("Invalid market symbol");
289
+ throw new NordError("Invalid market symbol");
299
290
  }
300
- const subscription = new events_1.EventEmitter();
291
+ const subscription = new EventEmitter();
301
292
  const wsClient = this.createWebSocketClient({
302
293
  trades: [symbol],
303
294
  });
@@ -323,9 +314,9 @@ class Nord {
323
314
  */
324
315
  subscribeAccount(accountId) {
325
316
  if (isNaN(accountId) || accountId <= 0) {
326
- throw new error_1.NordError("Invalid account ID");
317
+ throw new NordError("Invalid account ID");
327
318
  }
328
- const subscription = new events_1.EventEmitter();
319
+ const subscription = new EventEmitter();
329
320
  const wsClient = this.createWebSocketClient({
330
321
  accounts: [accountId],
331
322
  });
@@ -358,10 +349,10 @@ class Nord {
358
349
  */
359
350
  async getTrades({ marketId, takerId, makerId, takerSide, pageSize, since, until, startInclusive, }) {
360
351
  if (since && !utils.isRfc3339(since)) {
361
- throw new error_1.NordError(`Invalid RFC3339 timestamp: ${since}`);
352
+ throw new NordError(`Invalid RFC3339 timestamp: ${since}`);
362
353
  }
363
354
  if (until && !utils.isRfc3339(until)) {
364
- throw new error_1.NordError(`Invalid RFC3339 timestamp: ${until}`);
355
+ throw new NordError(`Invalid RFC3339 timestamp: ${until}`);
365
356
  }
366
357
  return await this.GET("/trades", {
367
358
  params: {
@@ -416,7 +407,7 @@ class Nord {
416
407
  }
417
408
  const id = this.symbolToMarketId.get(symbol);
418
409
  if (id === undefined) {
419
- throw new error_1.NordError(`Unknown market symbol: ${symbol}`);
410
+ throw new NordError(`Unknown market symbol: ${symbol}`);
420
411
  }
421
412
  _marketId = id;
422
413
  }
@@ -424,7 +415,7 @@ class Nord {
424
415
  _marketId = marketId;
425
416
  }
426
417
  else {
427
- throw new error_1.NordError("Either symbol or market_id must be provided for orderbook query");
418
+ throw new NordError("Either symbol or market_id must be provided for orderbook query");
428
419
  }
429
420
  return await this.GET("/market/{market_id}/orderbook", {
430
421
  params: {
@@ -667,7 +658,7 @@ class Nord {
667
658
  */
668
659
  async getAccountTriggers({ accountId, } = {}) {
669
660
  if (accountId == null) {
670
- throw new error_1.NordError("Account ID is undefined. Make sure to call updateAccountId() before requesting triggers.");
661
+ throw new NordError("Account ID is undefined. Make sure to call updateAccountId() before requesting triggers.");
671
662
  }
672
663
  try {
673
664
  const triggers = await this.GET("/account/{account_id}/triggers", {
@@ -678,7 +669,7 @@ class Nord {
678
669
  return triggers ?? [];
679
670
  }
680
671
  catch (error) {
681
- throw new error_1.NordError("Failed to fetch account triggers", { cause: error });
672
+ throw new NordError("Failed to fetch account triggers", { cause: error });
682
673
  }
683
674
  }
684
675
  /**
@@ -693,7 +684,7 @@ class Nord {
693
684
  */
694
685
  async getAccountTriggerHistory({ accountId, since, until, pageSize, startInclusive, }) {
695
686
  if (accountId == null) {
696
- throw new error_1.NordError("Account ID is undefined. Make sure to call updateAccountId() before requesting trigger history.");
687
+ throw new NordError("Account ID is undefined. Make sure to call updateAccountId() before requesting trigger history.");
697
688
  }
698
689
  try {
699
690
  return await this.GET("/account/{account_id}/triggers/history", {
@@ -709,10 +700,9 @@ class Nord {
709
700
  });
710
701
  }
711
702
  catch (error) {
712
- throw new error_1.NordError("Failed to fetch account trigger history", {
703
+ throw new NordError("Failed to fetch account trigger history", {
713
704
  cause: error,
714
705
  });
715
706
  }
716
707
  }
717
708
  }
718
- exports.Nord = Nord;
@@ -5,7 +5,7 @@ import { FeeTierConfig } from "../gen/nord_pb";
5
5
  export declare enum AclRole {
6
6
  FEE_MANAGER = 1,
7
7
  MARKET_MANAGER = 2,
8
- ADMIN = -2147483648
8
+ ADMIN = 2147483648
9
9
  }
10
10
  /**
11
11
  * Administrative client capable of submitting privileged configuration actions.
@@ -25,7 +25,7 @@ export declare class NordAdmin {
25
25
  nord: Nord;
26
26
  admin: PublicKey;
27
27
  signFn: (m: Transaction) => Promise<Transaction>;
28
- }>): NordAdmin;
28
+ }>): Promise<NordAdmin>;
29
29
  /**
30
30
  * Submit an action and append the admin signature before sending it to Nord.
31
31
  *
@@ -1,57 +1,26 @@
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 = exports.AclRole = void 0;
37
- const protobuf_1 = require("@bufbuild/protobuf");
38
- const proto = __importStar(require("../gen/nord_pb"));
39
- const utils_1 = require("../utils");
40
- const actions_1 = require("../actions");
41
- const error_1 = require("../error");
1
+ import { create } from "@bufbuild/protobuf";
2
+ import * as proto from "../gen/nord_pb";
3
+ import { decodeHex, signUserPayload } from "../utils";
4
+ import { createAction, sendAction, expectReceiptKind } from "../actions";
5
+ import { NordError } from "../error";
42
6
  // NOTE: keep in sync with `acl.rs`.
43
- // NOTE: don't forget `number` as int is internally a u32.
44
- var AclRole;
7
+ export var AclRole;
45
8
  (function (AclRole) {
9
+ // note: use 2 ** n instead of 1 << n since js internally
10
+ // casts number to a signed int for bitwise ops. when merging
11
+ // these roles, make sure to use += instead of |=. this will
12
+ // only work when the roles are powers of two.
46
13
  AclRole[AclRole["FEE_MANAGER"] = 1] = "FEE_MANAGER";
47
14
  AclRole[AclRole["MARKET_MANAGER"] = 2] = "MARKET_MANAGER";
48
- // TODO: unsure about this?
49
- AclRole[AclRole["ADMIN"] = -2147483648] = "ADMIN";
50
- })(AclRole || (exports.AclRole = AclRole = {}));
15
+ AclRole[AclRole["ADMIN"] = 2147483648] = "ADMIN";
16
+ })(AclRole || (AclRole = {}));
51
17
  /**
52
18
  * Administrative client capable of submitting privileged configuration actions.
53
19
  */
54
- class NordAdmin {
20
+ export class NordAdmin {
21
+ nord;
22
+ admin;
23
+ signFn;
55
24
  constructor({ nord, admin, signFn, }) {
56
25
  this.nord = nord;
57
26
  this.admin = admin;
@@ -63,7 +32,7 @@ class NordAdmin {
63
32
  * @param admin - The user that will be signing actions.
64
33
  * @param signFn - Function to sign messages with the admin's wallet.
65
34
  */
66
- static new({ nord, admin, signFn, }) {
35
+ static async new({ nord, admin, signFn, }) {
67
36
  return new NordAdmin({
68
37
  nord,
69
38
  admin,
@@ -78,9 +47,9 @@ class NordAdmin {
78
47
  */
79
48
  async submitAction(kind) {
80
49
  const timestamp = await this.nord.getTimestamp();
81
- const action = (0, actions_1.createAction)(timestamp, 0, kind);
82
- return (0, actions_1.sendAction)(this.nord.httpClient, async (xs) => {
83
- const signature = await (0, utils_1.signUserPayload)({
50
+ const action = createAction(timestamp, 0, kind);
51
+ return sendAction(this.nord.httpClient, async (xs) => {
52
+ const signature = await signUserPayload({
84
53
  payload: xs,
85
54
  user: this.admin,
86
55
  signTransaction: this.signFn,
@@ -99,26 +68,26 @@ class NordAdmin {
99
68
  async updateAcl({ target, addRoles, removeRoles, }) {
100
69
  const allRoles = addRoles.concat(removeRoles);
101
70
  if (allRoles.length !== new Set(allRoles).size) {
102
- throw new error_1.NordError("duplicate roles in acl update; must be unique");
71
+ throw new NordError("duplicate roles in acl update; must be unique");
103
72
  }
104
73
  let mask = 0;
105
74
  let values = 0;
106
- for (const role of allRoles) {
107
- mask |= role;
108
- }
109
- for (const role of addRoles) {
110
- values |= role;
111
- }
75
+ // using += instead of |= to avoid the internal cast to i32 >:(
76
+ // this works because our roles are powers of two.
77
+ for (const role of allRoles)
78
+ mask += role;
79
+ for (const role of addRoles)
80
+ values += role;
112
81
  const receipt = await this.submitAction({
113
82
  case: "updateAcl",
114
- value: (0, protobuf_1.create)(proto.Action_UpdateAclSchema, {
83
+ value: create(proto.Action_UpdateAclSchema, {
115
84
  aclPubkey: this.admin.toBytes(),
116
85
  targetPubkey: target.toBytes(),
117
86
  rolesValue: values,
118
87
  rolesMask: mask,
119
88
  }),
120
89
  });
121
- (0, actions_1.expectReceiptKind)(receipt, "aclUpdated", "update acl");
90
+ expectReceiptKind(receipt, "aclUpdated", "update acl");
122
91
  return { ...receipt.kind.value, actionId: receipt.actionId };
123
92
  }
124
93
  /**
@@ -135,7 +104,7 @@ class NordAdmin {
135
104
  async createToken({ tokenDecimals, weightBps, viewSymbol, oracleSymbol, mintAddr, }) {
136
105
  const receipt = await this.submitAction({
137
106
  case: "createToken",
138
- value: (0, protobuf_1.create)(proto.Action_CreateTokenSchema, {
107
+ value: create(proto.Action_CreateTokenSchema, {
139
108
  aclPubkey: this.admin.toBytes(),
140
109
  tokenDecimals,
141
110
  weightBps,
@@ -144,7 +113,7 @@ class NordAdmin {
144
113
  solAddr: mintAddr.toBytes(),
145
114
  }),
146
115
  });
147
- (0, actions_1.expectReceiptKind)(receipt, "insertTokenResult", "create token");
116
+ expectReceiptKind(receipt, "insertTokenResult", "create token");
148
117
  return { actionId: receipt.actionId, ...receipt.kind.value };
149
118
  }
150
119
  /**
@@ -165,7 +134,7 @@ class NordAdmin {
165
134
  async createMarket({ sizeDecimals, priceDecimals, imfBps, cmfBps, mmfBps, marketType, viewSymbol, oracleSymbol, baseTokenId, }) {
166
135
  const receipt = await this.submitAction({
167
136
  case: "createMarket",
168
- value: (0, protobuf_1.create)(proto.Action_CreateMarketSchema, {
137
+ value: create(proto.Action_CreateMarketSchema, {
169
138
  aclPubkey: this.admin.toBytes(),
170
139
  sizeDecimals,
171
140
  priceDecimals,
@@ -178,7 +147,7 @@ class NordAdmin {
178
147
  baseTokenId,
179
148
  }),
180
149
  });
181
- (0, actions_1.expectReceiptKind)(receipt, "insertMarketResult", "create market");
150
+ expectReceiptKind(receipt, "insertMarketResult", "create market");
182
151
  return { actionId: receipt.actionId, ...receipt.kind.value };
183
152
  }
184
153
  /**
@@ -196,25 +165,25 @@ class NordAdmin {
196
165
  async pythSetWormholeGuardians({ guardianSetIndex, addresses, }) {
197
166
  const parsedAddresses = addresses.map((address) => {
198
167
  try {
199
- const decoded = (0, utils_1.decodeHex)(address);
168
+ const decoded = decodeHex(address);
200
169
  if (decoded.length !== 20) {
201
170
  throw new Error("guardian address must be 20 bytes");
202
171
  }
203
172
  return decoded;
204
173
  }
205
174
  catch (e) {
206
- throw new error_1.NordError("invalid guardian address; must be a 20 byte hex address", { cause: e });
175
+ throw new NordError("invalid guardian address; must be a 20 byte hex address", { cause: e });
207
176
  }
208
177
  });
209
178
  const receipt = await this.submitAction({
210
179
  case: "pythSetWormholeGuardians",
211
- value: (0, protobuf_1.create)(proto.Action_PythSetWormholeGuardiansSchema, {
180
+ value: create(proto.Action_PythSetWormholeGuardiansSchema, {
212
181
  aclPubkey: this.admin.toBytes(),
213
182
  guardianSetIndex,
214
183
  addresses: parsedAddresses,
215
184
  }),
216
185
  });
217
- (0, actions_1.expectReceiptKind)(receipt, "updateGuardianSetResult", "update wormhole guardians");
186
+ expectReceiptKind(receipt, "updateGuardianSetResult", "update wormhole guardians");
218
187
  return { actionId: receipt.actionId, ...receipt.kind.value };
219
188
  }
220
189
  /**
@@ -232,25 +201,25 @@ class NordAdmin {
232
201
  async pythSetSymbolFeed({ oracleSymbol, priceFeedId: priceFeedIdHex, }) {
233
202
  let priceFeedId;
234
203
  try {
235
- priceFeedId = (0, utils_1.decodeHex)(priceFeedIdHex);
204
+ priceFeedId = decodeHex(priceFeedIdHex);
236
205
  if (priceFeedId.length !== 32) {
237
206
  throw new Error("price feed id must be 32 bytes");
238
207
  }
239
208
  }
240
209
  catch (e) {
241
- throw new error_1.NordError("invalid price feed id; must be a 32 byte hex id", {
210
+ throw new NordError("invalid price feed id; must be a 32 byte hex id", {
242
211
  cause: e,
243
212
  });
244
213
  }
245
214
  const receipt = await this.submitAction({
246
215
  case: "pythSetSymbolFeed",
247
- value: (0, protobuf_1.create)(proto.Action_PythSetSymbolFeedSchema, {
216
+ value: create(proto.Action_PythSetSymbolFeedSchema, {
248
217
  aclPubkey: this.admin.toBytes(),
249
218
  oracleSymbol,
250
219
  priceFeedId,
251
220
  }),
252
221
  });
253
- (0, actions_1.expectReceiptKind)(receipt, "oracleSymbolFeedResult", "set symbol feed");
222
+ expectReceiptKind(receipt, "oracleSymbolFeedResult", "set symbol feed");
254
223
  return { actionId: receipt.actionId, ...receipt.kind.value };
255
224
  }
256
225
  /**
@@ -262,11 +231,11 @@ class NordAdmin {
262
231
  async pause() {
263
232
  const receipt = await this.submitAction({
264
233
  case: "pause",
265
- value: (0, protobuf_1.create)(proto.Action_PauseSchema, {
234
+ value: create(proto.Action_PauseSchema, {
266
235
  aclPubkey: this.admin.toBytes(),
267
236
  }),
268
237
  });
269
- (0, actions_1.expectReceiptKind)(receipt, "paused", "pause");
238
+ expectReceiptKind(receipt, "paused", "pause");
270
239
  return { actionId: receipt.actionId };
271
240
  }
272
241
  /**
@@ -278,11 +247,11 @@ class NordAdmin {
278
247
  async unpause() {
279
248
  const receipt = await this.submitAction({
280
249
  case: "unpause",
281
- value: (0, protobuf_1.create)(proto.Action_UnpauseSchema, {
250
+ value: create(proto.Action_UnpauseSchema, {
282
251
  aclPubkey: this.admin.toBytes(),
283
252
  }),
284
253
  });
285
- (0, actions_1.expectReceiptKind)(receipt, "unpaused", "unpause");
254
+ expectReceiptKind(receipt, "unpaused", "unpause");
286
255
  return { actionId: receipt.actionId };
287
256
  }
288
257
  /**
@@ -295,12 +264,12 @@ class NordAdmin {
295
264
  async freezeMarket({ marketId, }) {
296
265
  const receipt = await this.submitAction({
297
266
  case: "freezeMarket",
298
- value: (0, protobuf_1.create)(proto.Action_FreezeMarketSchema, {
267
+ value: create(proto.Action_FreezeMarketSchema, {
299
268
  marketId,
300
269
  aclPubkey: this.admin.toBytes(),
301
270
  }),
302
271
  });
303
- (0, actions_1.expectReceiptKind)(receipt, "marketFreezeUpdated", "freeze market");
272
+ expectReceiptKind(receipt, "marketFreezeUpdated", "freeze market");
304
273
  return { actionId: receipt.actionId, ...receipt.kind.value };
305
274
  }
306
275
  /**
@@ -313,12 +282,12 @@ class NordAdmin {
313
282
  async unfreezeMarket({ marketId, }) {
314
283
  const receipt = await this.submitAction({
315
284
  case: "unfreezeMarket",
316
- value: (0, protobuf_1.create)(proto.Action_UnfreezeMarketSchema, {
285
+ value: create(proto.Action_UnfreezeMarketSchema, {
317
286
  marketId,
318
287
  aclPubkey: this.admin.toBytes(),
319
288
  }),
320
289
  });
321
- (0, actions_1.expectReceiptKind)(receipt, "marketFreezeUpdated", "unfreeze market");
290
+ expectReceiptKind(receipt, "marketFreezeUpdated", "unfreeze market");
322
291
  return { actionId: receipt.actionId, ...receipt.kind.value };
323
292
  }
324
293
  /**
@@ -335,12 +304,12 @@ class NordAdmin {
335
304
  async addFeeTier({ config, }) {
336
305
  const receipt = await this.submitAction({
337
306
  case: "addFeeTier",
338
- value: (0, protobuf_1.create)(proto.Action_AddFeeTierSchema, {
307
+ value: create(proto.Action_AddFeeTierSchema, {
339
308
  aclPubkey: this.admin.toBytes(),
340
- config: (0, protobuf_1.create)(proto.FeeTierConfigSchema, config),
309
+ config: create(proto.FeeTierConfigSchema, config),
341
310
  }),
342
311
  });
343
- (0, actions_1.expectReceiptKind)(receipt, "feeTierAdded", "add fee tier");
312
+ expectReceiptKind(receipt, "feeTierAdded", "add fee tier");
344
313
  return { actionId: receipt.actionId, ...receipt.kind.value };
345
314
  }
346
315
  /**
@@ -357,13 +326,13 @@ class NordAdmin {
357
326
  async updateFeeTier({ tierId, config, }) {
358
327
  const receipt = await this.submitAction({
359
328
  case: "updateFeeTier",
360
- value: (0, protobuf_1.create)(proto.Action_UpdateFeeTierSchema, {
329
+ value: create(proto.Action_UpdateFeeTierSchema, {
361
330
  aclPubkey: this.admin.toBytes(),
362
331
  id: tierId,
363
- config: (0, protobuf_1.create)(proto.FeeTierConfigSchema, config),
332
+ config: create(proto.FeeTierConfigSchema, config),
364
333
  }),
365
334
  });
366
- (0, actions_1.expectReceiptKind)(receipt, "feeTierUpdated", "update fee tier");
335
+ expectReceiptKind(receipt, "feeTierUpdated", "update fee tier");
367
336
  return { actionId: receipt.actionId, ...receipt.kind.value };
368
337
  }
369
338
  /**
@@ -381,14 +350,13 @@ class NordAdmin {
381
350
  async updateAccountsTier(accounts, tierId) {
382
351
  const receipt = await this.submitAction({
383
352
  case: "updateAccountsTier",
384
- value: (0, protobuf_1.create)(proto.Action_UpdateAccountsTierSchema, {
353
+ value: create(proto.Action_UpdateAccountsTierSchema, {
385
354
  aclPubkey: this.admin.toBytes(),
386
355
  accounts,
387
356
  tierId,
388
357
  }),
389
358
  });
390
- (0, actions_1.expectReceiptKind)(receipt, "accountsTierUpdated", "update accounts tier");
359
+ expectReceiptKind(receipt, "accountsTierUpdated", "update accounts tier");
391
360
  return { actionId: receipt.actionId, ...receipt.kind.value };
392
361
  }
393
362
  }
394
- exports.NordAdmin = NordAdmin;