@n1xyz/nord-ts 0.1.7 → 0.1.8
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/actions.js +39 -82
- package/dist/bundle.js +79181 -0
- package/dist/client/Nord.d.ts +2 -2
- package/dist/client/Nord.js +46 -78
- package/dist/client/NordAdmin.d.ts +2 -2
- package/dist/client/NordAdmin.js +57 -89
- package/dist/client/NordUser.js +118 -147
- package/dist/const.js +5 -8
- package/dist/error.js +7 -5
- package/dist/gen/nord_pb.js +88 -92
- package/dist/gen/openapi.d.ts +5 -6
- package/dist/gen/openapi.js +1 -2
- package/dist/index.js +10 -49
- package/dist/types.d.ts +1 -0
- package/dist/types.js +21 -60
- package/dist/utils.js +38 -86
- package/dist/websocket/NordWebSocketClient.js +12 -17
- package/dist/websocket/Subscriber.js +6 -7
- package/dist/websocket/events.js +1 -2
- package/dist/websocket/index.js +10 -15
- package/package.json +2 -3
- package/dist/api/client.d.ts +0 -14
- package/dist/api/client.js +0 -45
- package/dist/bridge/client.d.ts +0 -151
- package/dist/bridge/client.js +0 -434
- package/dist/bridge/const.d.ts +0 -23
- package/dist/bridge/const.js +0 -47
- package/dist/bridge/index.d.ts +0 -4
- package/dist/bridge/index.js +0 -23
- package/dist/bridge/types.d.ts +0 -120
- package/dist/bridge/types.js +0 -18
- package/dist/bridge/utils.d.ts +0 -64
- package/dist/bridge/utils.js +0 -131
- package/dist/gen/common.d.ts +0 -68
- package/dist/gen/common.js +0 -215
- package/dist/gen/nord.d.ts +0 -882
- package/dist/gen/nord.js +0 -6520
- package/dist/idl/bridge.d.ts +0 -569
- package/dist/idl/bridge.js +0 -8
- package/dist/idl/bridge.json +0 -1506
- package/dist/idl/index.d.ts +0 -607
- package/dist/idl/index.js +0 -8
- package/dist/nord/api/actions.d.ts +0 -126
- package/dist/nord/api/actions.js +0 -397
- package/dist/nord/api/core.d.ts +0 -16
- package/dist/nord/api/core.js +0 -81
- package/dist/nord/api/market.d.ts +0 -36
- package/dist/nord/api/market.js +0 -96
- package/dist/nord/api/metrics.d.ts +0 -67
- package/dist/nord/api/metrics.js +0 -229
- package/dist/nord/api/queries.d.ts +0 -46
- package/dist/nord/api/queries.js +0 -109
- package/dist/nord/api/triggers.d.ts +0 -7
- package/dist/nord/api/triggers.js +0 -38
- package/dist/nord/client/Nord.d.ts +0 -396
- package/dist/nord/client/Nord.js +0 -747
- package/dist/nord/client/NordAdmin.d.ts +0 -259
- package/dist/nord/client/NordAdmin.js +0 -395
- package/dist/nord/client/NordClient.d.ts +0 -33
- package/dist/nord/client/NordClient.js +0 -45
- package/dist/nord/client/NordUser.d.ts +0 -362
- package/dist/nord/client/NordUser.js +0 -781
- package/dist/nord/index.d.ts +0 -11
- package/dist/nord/index.js +0 -36
- package/dist/nord/models/Subscriber.d.ts +0 -37
- package/dist/nord/models/Subscriber.js +0 -25
- package/dist/nord/utils/NordError.d.ts +0 -35
- package/dist/nord/utils/NordError.js +0 -49
- package/src/actions.ts +0 -333
- package/src/client/Nord.ts +0 -934
- package/src/client/NordAdmin.ts +0 -484
- package/src/client/NordUser.ts +0 -1122
- package/src/const.ts +0 -34
- package/src/error.ts +0 -76
- package/src/gen/.gitkeep +0 -0
- package/src/gen/nord_pb.ts +0 -5053
- package/src/gen/openapi.ts +0 -2904
- package/src/index.ts +0 -11
- package/src/types.ts +0 -327
- package/src/utils.ts +0 -266
- package/src/websocket/NordWebSocketClient.ts +0 -316
- package/src/websocket/Subscriber.ts +0 -56
- package/src/websocket/events.ts +0 -31
- package/src/websocket/index.ts +0 -105
package/dist/client/Nord.d.ts
CHANGED
|
@@ -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 } from "../types";
|
|
7
7
|
import { NordWebSocketClient } from "../websocket/index";
|
|
8
8
|
import { OrderbookSubscription, TradeSubscription } from "../websocket/Subscriber";
|
|
9
9
|
/**
|
|
@@ -88,7 +88,7 @@ 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<
|
|
91
|
+
getAdminList(): Promise<Array<AdminInfo>>;
|
|
92
92
|
/**
|
|
93
93
|
* Fetch information about Nord markets and tokens
|
|
94
94
|
*
|
package/dist/client/Nord.js
CHANGED
|
@@ -1,54 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 = (
|
|
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
|
|
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
|
|
89
|
+
throw new NordError("At least one subscription must be provided");
|
|
121
90
|
}
|
|
122
91
|
// Create and return a new WebSocket client
|
|
123
|
-
return
|
|
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
|
|
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
|
|
102
|
+
throw new NordError("internal assertion violation", { cause: r });
|
|
134
103
|
}
|
|
135
104
|
return r.data;
|
|
136
105
|
}
|
|
@@ -178,7 +147,7 @@ class Nord {
|
|
|
178
147
|
});
|
|
179
148
|
}
|
|
180
149
|
catch (error) {
|
|
181
|
-
throw new
|
|
150
|
+
throw new NordError("Failed to fetch Nord info", { cause: error });
|
|
182
151
|
}
|
|
183
152
|
}
|
|
184
153
|
/** @deprecated use Nord.new */
|
|
@@ -196,9 +165,9 @@ class Nord {
|
|
|
196
165
|
* @throws {NordError} If initialization fails
|
|
197
166
|
*/
|
|
198
167
|
static async new({ app, solanaConnection, webServerUrl, protonUrl, }) {
|
|
199
|
-
const protonClient = await
|
|
168
|
+
const protonClient = await ProtonClient.init({
|
|
200
169
|
protonUrl: protonUrl ?? webServerUrl,
|
|
201
|
-
app: new
|
|
170
|
+
app: new PublicKey(app),
|
|
202
171
|
solConn: solanaConnection,
|
|
203
172
|
});
|
|
204
173
|
const nord = new Nord({
|
|
@@ -267,9 +236,9 @@ class Nord {
|
|
|
267
236
|
*/
|
|
268
237
|
subscribeOrderbook(symbol) {
|
|
269
238
|
if (!symbol || typeof symbol !== "string") {
|
|
270
|
-
throw new
|
|
239
|
+
throw new NordError("Invalid market symbol");
|
|
271
240
|
}
|
|
272
|
-
const subscription = new
|
|
241
|
+
const subscription = new EventEmitter();
|
|
273
242
|
const wsClient = this.createWebSocketClient({
|
|
274
243
|
deltas: [symbol],
|
|
275
244
|
});
|
|
@@ -295,9 +264,9 @@ class Nord {
|
|
|
295
264
|
*/
|
|
296
265
|
subscribeTrades(symbol) {
|
|
297
266
|
if (!symbol || typeof symbol !== "string") {
|
|
298
|
-
throw new
|
|
267
|
+
throw new NordError("Invalid market symbol");
|
|
299
268
|
}
|
|
300
|
-
const subscription = new
|
|
269
|
+
const subscription = new EventEmitter();
|
|
301
270
|
const wsClient = this.createWebSocketClient({
|
|
302
271
|
trades: [symbol],
|
|
303
272
|
});
|
|
@@ -323,9 +292,9 @@ class Nord {
|
|
|
323
292
|
*/
|
|
324
293
|
subscribeAccount(accountId) {
|
|
325
294
|
if (isNaN(accountId) || accountId <= 0) {
|
|
326
|
-
throw new
|
|
295
|
+
throw new NordError("Invalid account ID");
|
|
327
296
|
}
|
|
328
|
-
const subscription = new
|
|
297
|
+
const subscription = new EventEmitter();
|
|
329
298
|
const wsClient = this.createWebSocketClient({
|
|
330
299
|
accounts: [accountId],
|
|
331
300
|
});
|
|
@@ -358,10 +327,10 @@ class Nord {
|
|
|
358
327
|
*/
|
|
359
328
|
async getTrades({ marketId, takerId, makerId, takerSide, pageSize, since, until, startInclusive, }) {
|
|
360
329
|
if (since && !utils.isRfc3339(since)) {
|
|
361
|
-
throw new
|
|
330
|
+
throw new NordError(`Invalid RFC3339 timestamp: ${since}`);
|
|
362
331
|
}
|
|
363
332
|
if (until && !utils.isRfc3339(until)) {
|
|
364
|
-
throw new
|
|
333
|
+
throw new NordError(`Invalid RFC3339 timestamp: ${until}`);
|
|
365
334
|
}
|
|
366
335
|
return await this.GET("/trades", {
|
|
367
336
|
params: {
|
|
@@ -416,7 +385,7 @@ class Nord {
|
|
|
416
385
|
}
|
|
417
386
|
const id = this.symbolToMarketId.get(symbol);
|
|
418
387
|
if (id === undefined) {
|
|
419
|
-
throw new
|
|
388
|
+
throw new NordError(`Unknown market symbol: ${symbol}`);
|
|
420
389
|
}
|
|
421
390
|
_marketId = id;
|
|
422
391
|
}
|
|
@@ -424,7 +393,7 @@ class Nord {
|
|
|
424
393
|
_marketId = marketId;
|
|
425
394
|
}
|
|
426
395
|
else {
|
|
427
|
-
throw new
|
|
396
|
+
throw new NordError("Either symbol or market_id must be provided for orderbook query");
|
|
428
397
|
}
|
|
429
398
|
return await this.GET("/market/{market_id}/orderbook", {
|
|
430
399
|
params: {
|
|
@@ -667,7 +636,7 @@ class Nord {
|
|
|
667
636
|
*/
|
|
668
637
|
async getAccountTriggers({ accountId, } = {}) {
|
|
669
638
|
if (accountId == null) {
|
|
670
|
-
throw new
|
|
639
|
+
throw new NordError("Account ID is undefined. Make sure to call updateAccountId() before requesting triggers.");
|
|
671
640
|
}
|
|
672
641
|
try {
|
|
673
642
|
const triggers = await this.GET("/account/{account_id}/triggers", {
|
|
@@ -678,7 +647,7 @@ class Nord {
|
|
|
678
647
|
return triggers ?? [];
|
|
679
648
|
}
|
|
680
649
|
catch (error) {
|
|
681
|
-
throw new
|
|
650
|
+
throw new NordError("Failed to fetch account triggers", { cause: error });
|
|
682
651
|
}
|
|
683
652
|
}
|
|
684
653
|
/**
|
|
@@ -693,7 +662,7 @@ class Nord {
|
|
|
693
662
|
*/
|
|
694
663
|
async getAccountTriggerHistory({ accountId, since, until, pageSize, startInclusive, }) {
|
|
695
664
|
if (accountId == null) {
|
|
696
|
-
throw new
|
|
665
|
+
throw new NordError("Account ID is undefined. Make sure to call updateAccountId() before requesting trigger history.");
|
|
697
666
|
}
|
|
698
667
|
try {
|
|
699
668
|
return await this.GET("/account/{account_id}/triggers/history", {
|
|
@@ -709,10 +678,9 @@ class Nord {
|
|
|
709
678
|
});
|
|
710
679
|
}
|
|
711
680
|
catch (error) {
|
|
712
|
-
throw new
|
|
681
|
+
throw new NordError("Failed to fetch account trigger history", {
|
|
713
682
|
cause: error,
|
|
714
683
|
});
|
|
715
684
|
}
|
|
716
685
|
}
|
|
717
686
|
}
|
|
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 =
|
|
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
|
*
|
package/dist/client/NordAdmin.js
CHANGED
|
@@ -1,57 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
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
|
-
|
|
49
|
-
|
|
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 =
|
|
82
|
-
return
|
|
83
|
-
const signature = await
|
|
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
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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:
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
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 =
|
|
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
|
|
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:
|
|
180
|
+
value: create(proto.Action_PythSetWormholeGuardiansSchema, {
|
|
212
181
|
aclPubkey: this.admin.toBytes(),
|
|
213
182
|
guardianSetIndex,
|
|
214
183
|
addresses: parsedAddresses,
|
|
215
184
|
}),
|
|
216
185
|
});
|
|
217
|
-
|
|
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 =
|
|
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
|
|
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:
|
|
216
|
+
value: create(proto.Action_PythSetSymbolFeedSchema, {
|
|
248
217
|
aclPubkey: this.admin.toBytes(),
|
|
249
218
|
oracleSymbol,
|
|
250
219
|
priceFeedId,
|
|
251
220
|
}),
|
|
252
221
|
});
|
|
253
|
-
|
|
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:
|
|
234
|
+
value: create(proto.Action_PauseSchema, {
|
|
266
235
|
aclPubkey: this.admin.toBytes(),
|
|
267
236
|
}),
|
|
268
237
|
});
|
|
269
|
-
|
|
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:
|
|
250
|
+
value: create(proto.Action_UnpauseSchema, {
|
|
282
251
|
aclPubkey: this.admin.toBytes(),
|
|
283
252
|
}),
|
|
284
253
|
});
|
|
285
|
-
|
|
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:
|
|
267
|
+
value: create(proto.Action_FreezeMarketSchema, {
|
|
299
268
|
marketId,
|
|
300
269
|
aclPubkey: this.admin.toBytes(),
|
|
301
270
|
}),
|
|
302
271
|
});
|
|
303
|
-
|
|
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:
|
|
285
|
+
value: create(proto.Action_UnfreezeMarketSchema, {
|
|
317
286
|
marketId,
|
|
318
287
|
aclPubkey: this.admin.toBytes(),
|
|
319
288
|
}),
|
|
320
289
|
});
|
|
321
|
-
|
|
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:
|
|
307
|
+
value: create(proto.Action_AddFeeTierSchema, {
|
|
339
308
|
aclPubkey: this.admin.toBytes(),
|
|
340
|
-
config:
|
|
309
|
+
config: create(proto.FeeTierConfigSchema, config),
|
|
341
310
|
}),
|
|
342
311
|
});
|
|
343
|
-
|
|
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:
|
|
329
|
+
value: create(proto.Action_UpdateFeeTierSchema, {
|
|
361
330
|
aclPubkey: this.admin.toBytes(),
|
|
362
331
|
id: tierId,
|
|
363
|
-
config:
|
|
332
|
+
config: create(proto.FeeTierConfigSchema, config),
|
|
364
333
|
}),
|
|
365
334
|
});
|
|
366
|
-
|
|
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:
|
|
353
|
+
value: create(proto.Action_UpdateAccountsTierSchema, {
|
|
385
354
|
aclPubkey: this.admin.toBytes(),
|
|
386
355
|
accounts,
|
|
387
356
|
tierId,
|
|
388
357
|
}),
|
|
389
358
|
});
|
|
390
|
-
|
|
359
|
+
expectReceiptKind(receipt, "accountsTierUpdated", "update accounts tier");
|
|
391
360
|
return { actionId: receipt.actionId, ...receipt.kind.value };
|
|
392
361
|
}
|
|
393
362
|
}
|
|
394
|
-
exports.NordAdmin = NordAdmin;
|