@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
package/dist/actions.js CHANGED
@@ -1,63 +1,20 @@
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.formatReceiptError = formatReceiptError;
37
- exports.expectReceiptKind = expectReceiptKind;
38
- exports.createAction = createAction;
39
- exports.sendAction = sendAction;
40
- exports.prepareAction = prepareAction;
41
- exports.createSession = createSession;
42
- exports.revokeSession = revokeSession;
43
- exports.atomic = atomic;
44
- const proto = __importStar(require("./gen/nord_pb"));
45
- const protobuf_1 = require("@bufbuild/protobuf");
46
- const types_1 = require("./types");
47
- const utils_1 = require("./utils");
48
- const wire_1 = require("@bufbuild/protobuf/wire");
49
- const error_1 = require("./error");
50
- function formatReceiptError(receipt) {
1
+ import * as proto from "./gen/nord_pb";
2
+ import { create } from "@bufbuild/protobuf";
3
+ import { fillModeToProtoFillMode, Side } from "./types";
4
+ import { assert, decodeLengthDelimited, SESSION_TTL, toScaledU64, signUserPayload, } from "./utils";
5
+ import { sizeDelimitedEncode } from "@bufbuild/protobuf/wire";
6
+ import { NordError } from "./error";
7
+ export function formatReceiptError(receipt) {
51
8
  if (receipt.kind?.case === "err") {
52
9
  const err = receipt.kind.value;
53
10
  return proto.Error[err] ?? err.toString();
54
11
  }
55
12
  return receipt.kind?.case ?? "unknown";
56
13
  }
57
- function expectReceiptKind(receipt, expected, action) {
14
+ export function expectReceiptKind(receipt, expected, action) {
58
15
  if (receipt.kind?.case !== expected) {
59
16
  const label = formatReceiptError(receipt);
60
- throw new error_1.NordError(`Failed to ${action}: ${label}`);
17
+ throw new NordError(`Failed to ${action}: ${label}`);
61
18
  }
62
19
  }
63
20
  async function sessionSign(signFn, message) {
@@ -65,14 +22,14 @@ async function sessionSign(signFn, message) {
65
22
  return new Uint8Array([...message, ...signature]);
66
23
  }
67
24
  // Helper to create an action with common fields
68
- function createAction(currentTimestamp, nonce, kind) {
69
- return (0, protobuf_1.create)(proto.ActionSchema, {
25
+ export function createAction(currentTimestamp, nonce, kind) {
26
+ return create(proto.ActionSchema, {
70
27
  currentTimestamp,
71
28
  nonce,
72
29
  kind,
73
30
  });
74
31
  }
75
- async function sendAction(client, makeSignedMessage, action) {
32
+ export async function sendAction(client, makeSignedMessage, action) {
76
33
  const body = await prepareAction(action, makeSignedMessage);
77
34
  const response = await client.POST("/action", {
78
35
  params: {
@@ -89,8 +46,8 @@ async function sendAction(client, makeSignedMessage, action) {
89
46
  if (response.error) {
90
47
  throw new Error(`Failed to ${action.kind.case}, HTTP status ${JSON.stringify(response.error)}`);
91
48
  }
92
- const rawResp = new Uint8Array(await response.response.bytes());
93
- const resp = (0, utils_1.decodeLengthDelimited)(rawResp, proto.ReceiptSchema);
49
+ const rawResp = new Uint8Array(await response.response.arrayBuffer());
50
+ const resp = decodeLengthDelimited(rawResp, proto.ReceiptSchema);
94
51
  if (resp.kind?.case === "err") {
95
52
  throw new Error(`Could not execute ${action.kind.case}, reason: ${proto.Error[resp.kind.value]}`);
96
53
  }
@@ -98,8 +55,8 @@ async function sendAction(client, makeSignedMessage, action) {
98
55
  }
99
56
  // Given action and signature function, prepare the signed message to send to server as `body`.
100
57
  // `makeSignedMessage` must include the original message and signature.
101
- async function prepareAction(action, makeSignedMessage) {
102
- const encoded = (0, wire_1.sizeDelimitedEncode)(proto.ActionSchema, action);
58
+ export async function prepareAction(action, makeSignedMessage) {
59
+ const encoded = sizeDelimitedEncode(proto.ActionSchema, action);
103
60
  // NOTE(agent): keep in sync with MAX_ENCODED_ACTION_SIZE in Rust code
104
61
  const MAX_ENCODED_ACTION_SIZE = 1024;
105
62
  if (encoded.byteLength > MAX_ENCODED_ACTION_SIZE) {
@@ -113,18 +70,18 @@ async function prepareAction(action, makeSignedMessage) {
113
70
  }
114
71
  return body;
115
72
  }
116
- async function createSession(client, signTransaction, currentTimestamp, nonce, params) {
73
+ export async function createSession(client, signTransaction, currentTimestamp, nonce, params) {
117
74
  let expiry = 0n;
118
75
  if (params.expiryTimestamp !== undefined) {
119
76
  expiry = params.expiryTimestamp;
120
- (0, utils_1.assert)(expiry > currentTimestamp, "Cannot set expiry timestamp in the past");
77
+ assert(expiry > currentTimestamp, "Cannot set expiry timestamp in the past");
121
78
  }
122
79
  else {
123
- expiry = currentTimestamp + utils_1.SESSION_TTL;
80
+ expiry = currentTimestamp + SESSION_TTL;
124
81
  }
125
82
  const action = createAction(currentTimestamp, nonce, {
126
83
  case: "createSession",
127
- value: (0, protobuf_1.create)(proto.Action_CreateSessionSchema, {
84
+ value: create(proto.Action_CreateSessionSchema, {
128
85
  userPubkey: params.userPubkey.toBytes(),
129
86
  blstPubkey: params.sessionPubkey.toBytes(),
130
87
  expiryTimestamp: expiry,
@@ -133,7 +90,7 @@ async function createSession(client, signTransaction, currentTimestamp, nonce, p
133
90
  const resp = await sendAction(client, async (payload) => {
134
91
  return new Uint8Array([
135
92
  ...payload,
136
- ...(await (0, utils_1.signUserPayload)({
93
+ ...(await signUserPayload({
137
94
  payload,
138
95
  user: params.userPubkey,
139
96
  signTransaction,
@@ -150,17 +107,17 @@ async function createSession(client, signTransaction, currentTimestamp, nonce, p
150
107
  throw new Error(`Unexpected receipt kind ${resp.kind?.case}`);
151
108
  }
152
109
  }
153
- async function revokeSession(client, signTransaction, currentTimestamp, nonce, params) {
110
+ export async function revokeSession(client, signTransaction, currentTimestamp, nonce, params) {
154
111
  const action = createAction(currentTimestamp, nonce, {
155
112
  case: "revokeSession",
156
- value: (0, protobuf_1.create)(proto.Action_RevokeSessionSchema, {
113
+ value: create(proto.Action_RevokeSessionSchema, {
157
114
  sessionId: BigInt(params.sessionId),
158
115
  }),
159
116
  });
160
117
  const resp = await sendAction(client, async (payload) => {
161
118
  return new Uint8Array([
162
119
  ...payload,
163
- ...(await (0, utils_1.signUserPayload)({
120
+ ...(await signUserPayload({
164
121
  payload,
165
122
  user: params.userPubkey,
166
123
  signTransaction,
@@ -169,50 +126,50 @@ async function revokeSession(client, signTransaction, currentTimestamp, nonce, p
169
126
  }, action);
170
127
  return { actionId: resp.actionId };
171
128
  }
172
- async function atomic(client, signFn, currentTimestamp, nonce, params) {
173
- (0, utils_1.assert)(params.actions.length > 0 && params.actions.length <= 4, "Atomic action must contain between 1 and 4 sub-actions");
129
+ export async function atomic(client, signFn, currentTimestamp, nonce, params) {
130
+ assert(params.actions.length > 0 && params.actions.length <= 4, "Atomic action must contain between 1 and 4 sub-actions");
174
131
  const subactions = params.actions.map((a) => {
175
132
  if (a.kind === "place") {
176
- const price = (0, utils_1.toScaledU64)(a.price ?? 0, a.priceDecimals);
177
- const size = (0, utils_1.toScaledU64)(a.size ?? 0, a.sizeDecimals);
133
+ const price = toScaledU64(a.price ?? 0, a.priceDecimals);
134
+ const size = toScaledU64(a.size ?? 0, a.sizeDecimals);
178
135
  const scaledQuote = a.quoteSize
179
136
  ? a.quoteSize.toWire(a.priceDecimals, a.sizeDecimals)
180
137
  : undefined;
181
138
  // Require at least one limit to be set (non-zero size, non-zero price, or quoteSize)
182
- (0, utils_1.assert)(price > 0n || size > 0n || scaledQuote !== undefined, "OrderLimit must include at least one of: size, price, or quoteSize");
183
- const tradeOrPlace = (0, protobuf_1.create)(proto.TradeOrPlaceSchema, {
139
+ assert(price > 0n || size > 0n || scaledQuote !== undefined, "OrderLimit must include at least one of: size, price, or quoteSize");
140
+ const tradeOrPlace = create(proto.TradeOrPlaceSchema, {
184
141
  marketId: a.marketId,
185
- orderType: (0, protobuf_1.create)(proto.OrderTypeSchema, {
186
- side: a.side === types_1.Side.Bid ? proto.Side.BID : proto.Side.ASK,
187
- fillMode: (0, types_1.fillModeToProtoFillMode)(a.fillMode),
142
+ orderType: create(proto.OrderTypeSchema, {
143
+ side: a.side === Side.Bid ? proto.Side.BID : proto.Side.ASK,
144
+ fillMode: fillModeToProtoFillMode(a.fillMode),
188
145
  isReduceOnly: a.isReduceOnly,
189
146
  }),
190
- limit: (0, protobuf_1.create)(proto.OrderLimitSchema, {
147
+ limit: create(proto.OrderLimitSchema, {
191
148
  price,
192
149
  size,
193
150
  quoteSize: scaledQuote === undefined
194
151
  ? undefined
195
- : (0, protobuf_1.create)(proto.QuoteSizeSchema, {
152
+ : create(proto.QuoteSizeSchema, {
196
153
  size: scaledQuote.size,
197
154
  price: scaledQuote.price,
198
155
  }),
199
156
  }),
200
157
  clientOrderId: a.clientOrderId === undefined ? undefined : BigInt(a.clientOrderId),
201
158
  });
202
- return (0, protobuf_1.create)(proto.AtomicSubactionKindSchema, {
159
+ return create(proto.AtomicSubactionKindSchema, {
203
160
  inner: { case: "tradeOrPlace", value: tradeOrPlace },
204
161
  });
205
162
  }
206
- return (0, protobuf_1.create)(proto.AtomicSubactionKindSchema, {
163
+ return create(proto.AtomicSubactionKindSchema, {
207
164
  inner: {
208
165
  case: "cancelOrder",
209
- value: (0, protobuf_1.create)(proto.CancelOrderSchema, { orderId: BigInt(a.orderId) }),
166
+ value: create(proto.CancelOrderSchema, { orderId: BigInt(a.orderId) }),
210
167
  },
211
168
  });
212
169
  });
213
170
  const action = createAction(currentTimestamp, nonce, {
214
171
  case: "atomic",
215
- value: (0, protobuf_1.create)(proto.AtomicSchema, {
172
+ value: create(proto.AtomicSchema, {
216
173
  sessionId: BigInt(params.sessionId),
217
174
  accountId: params.accountId, // optional
218
175
  actions: subactions,