@n1xyz/nord-ts 0.0.20 → 0.0.22
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 +3651 -0
- package/dist/gen/nord_pb.js +892 -0
- package/dist/gen/openapi.d.ts +241 -2
- package/dist/nord/api/actions.d.ts +30 -72
- package/dist/nord/api/actions.js +179 -200
- package/dist/nord/api/core.d.ts +1 -1
- package/dist/nord/api/core.js +1 -13
- package/dist/nord/client/Nord.d.ts +3 -3
- package/dist/nord/client/Nord.js +6 -9
- package/dist/nord/client/NordUser.d.ts +26 -13
- package/dist/nord/client/NordUser.js +13 -10
- package/dist/types.d.ts +13 -11
- package/dist/types.js +29 -4
- package/dist/utils.d.ts +6 -20
- package/dist/utils.js +17 -35
- package/dist/websocket/NordWebSocketClient.d.ts +0 -11
- package/dist/websocket/NordWebSocketClient.js +2 -98
- package/package.json +27 -24
- package/src/gen/nord_pb.ts +4172 -0
- package/src/gen/openapi.ts +241 -2
- package/src/nord/api/actions.ts +249 -370
- package/src/nord/api/core.ts +1 -16
- package/src/nord/client/Nord.ts +9 -13
- package/src/nord/client/NordUser.ts +40 -19
- package/src/types.ts +32 -12
- package/src/utils.ts +24 -43
- package/src/websocket/NordWebSocketClient.ts +2 -121
package/dist/nord/api/actions.js
CHANGED
|
@@ -33,7 +33,6 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports._private = void 0;
|
|
37
36
|
exports.createSession = createSession;
|
|
38
37
|
exports.revokeSession = revokeSession;
|
|
39
38
|
exports.withdraw = withdraw;
|
|
@@ -41,9 +40,11 @@ exports.placeOrder = placeOrder;
|
|
|
41
40
|
exports.cancelOrder = cancelOrder;
|
|
42
41
|
exports.transfer = transfer;
|
|
43
42
|
exports.atomic = atomic;
|
|
44
|
-
const proto = __importStar(require("../../gen/
|
|
43
|
+
const proto = __importStar(require("../../gen/nord_pb"));
|
|
44
|
+
const protobuf_1 = require("@bufbuild/protobuf");
|
|
45
45
|
const types_1 = require("../../types");
|
|
46
46
|
const utils_1 = require("../../utils");
|
|
47
|
+
const wire_1 = require("@bufbuild/protobuf/wire");
|
|
47
48
|
async function sessionSign(signFn, message) {
|
|
48
49
|
const signature = await signFn(message);
|
|
49
50
|
return new Uint8Array([...message, ...signature]);
|
|
@@ -52,30 +53,38 @@ async function walletSign(walletSignFn, message) {
|
|
|
52
53
|
const signature = await walletSignFn(message);
|
|
53
54
|
return new Uint8Array([...message, ...signature]);
|
|
54
55
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
},
|
|
63
|
-
body,
|
|
64
|
-
});
|
|
65
|
-
return new Uint8Array(await response.arrayBuffer());
|
|
66
|
-
};
|
|
56
|
+
// Helper to create an action with common fields
|
|
57
|
+
function createAction(currentTimestamp, nonce, kind) {
|
|
58
|
+
return (0, protobuf_1.create)(proto.ActionSchema, {
|
|
59
|
+
currentTimestamp,
|
|
60
|
+
nonce,
|
|
61
|
+
kind,
|
|
62
|
+
});
|
|
67
63
|
}
|
|
68
|
-
async function sendAction(
|
|
69
|
-
const encoded = (0,
|
|
64
|
+
async function sendAction(serverUrl, makeSignedMessage, action, actionErrorDesc) {
|
|
65
|
+
const encoded = (0, wire_1.sizeDelimitedEncode)(proto.ActionSchema, action);
|
|
66
|
+
// validate the payload size
|
|
67
|
+
const MAX_PAYLOAD_SIZE = 100 * 1024; // 100 kB
|
|
68
|
+
if (encoded.byteLength > MAX_PAYLOAD_SIZE) {
|
|
69
|
+
throw new Error(`Encoded message size (${encoded.byteLength} bytes) is greater than max payload size (${MAX_PAYLOAD_SIZE} bytes).`);
|
|
70
|
+
}
|
|
70
71
|
const body = await makeSignedMessage(encoded);
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
// TODO: this should be changed to use openapi
|
|
73
|
+
const response = await (0, utils_1.checkedFetch)(`${serverUrl}/action`, {
|
|
74
|
+
method: "POST",
|
|
75
|
+
headers: {
|
|
76
|
+
"Content-Type": "application/json",
|
|
77
|
+
},
|
|
78
|
+
body,
|
|
79
|
+
});
|
|
80
|
+
const rawResp = new Uint8Array(await response.arrayBuffer());
|
|
81
|
+
const resp = (0, utils_1.decodeLengthDelimited)(rawResp, proto.ReceiptSchema);
|
|
82
|
+
if (resp.kind?.case === "err") {
|
|
83
|
+
throw new Error(`Could not ${actionErrorDesc}, reason: ${proto.Error[resp.kind.value]}`);
|
|
75
84
|
}
|
|
76
85
|
return resp;
|
|
77
86
|
}
|
|
78
|
-
async function
|
|
87
|
+
async function createSession(serverUrl, walletSignFn, currentTimestamp, nonce, params) {
|
|
79
88
|
(0, utils_1.checkPubKeyLength)(types_1.KeyType.Ed25519, params.userPubkey.length);
|
|
80
89
|
(0, utils_1.checkPubKeyLength)(types_1.KeyType.Ed25519, params.sessionPubkey.length);
|
|
81
90
|
let expiry = 0n;
|
|
@@ -86,228 +95,198 @@ async function createSessionImpl(sendFn, walletSignFn, currentTimestamp, nonce,
|
|
|
86
95
|
else {
|
|
87
96
|
expiry = currentTimestamp + utils_1.SESSION_TTL;
|
|
88
97
|
}
|
|
89
|
-
const action = {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return resp.kind.value.sessionId;
|
|
98
|
+
const action = createAction(currentTimestamp, nonce, {
|
|
99
|
+
case: "createSession",
|
|
100
|
+
value: (0, protobuf_1.create)(proto.Action_CreateSessionSchema, {
|
|
101
|
+
userPubkey: params.userPubkey,
|
|
102
|
+
blstPubkey: params.sessionPubkey,
|
|
103
|
+
expiryTimestamp: expiry,
|
|
104
|
+
}),
|
|
105
|
+
});
|
|
106
|
+
const resp = await sendAction(serverUrl, (m) => walletSign(walletSignFn, m), action, "create a new session");
|
|
107
|
+
if (resp.kind?.case === "createSessionResult") {
|
|
108
|
+
return {
|
|
109
|
+
actionId: resp.actionId,
|
|
110
|
+
sessionId: resp.kind.value.sessionId,
|
|
111
|
+
};
|
|
104
112
|
}
|
|
105
113
|
else {
|
|
106
|
-
throw new Error(`Unexpected receipt kind ${resp.kind
|
|
114
|
+
throw new Error(`Unexpected receipt kind ${resp.kind?.case}`);
|
|
107
115
|
}
|
|
108
116
|
}
|
|
109
|
-
async function createSession(serverUrl, walletSignFn, currentTimestamp, nonce, params) {
|
|
110
|
-
return createSessionImpl(makeSendHttp(serverUrl), walletSignFn, currentTimestamp, nonce, params);
|
|
111
|
-
}
|
|
112
|
-
async function revokeSessionImpl(sendFn, walletSignFn, currentTimestamp, nonce, params) {
|
|
113
|
-
const action = {
|
|
114
|
-
currentTimestamp,
|
|
115
|
-
nonce,
|
|
116
|
-
kind: {
|
|
117
|
-
$case: "revokeSession",
|
|
118
|
-
value: {
|
|
119
|
-
sessionId: BigInt(params.sessionId),
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
};
|
|
123
|
-
await sendAction(sendFn, (m) => walletSign(walletSignFn, m), action, "create a new session");
|
|
124
|
-
}
|
|
125
117
|
async function revokeSession(serverUrl, walletSignFn, currentTimestamp, nonce, params) {
|
|
126
|
-
|
|
118
|
+
const action = createAction(currentTimestamp, nonce, {
|
|
119
|
+
case: "revokeSession",
|
|
120
|
+
value: (0, protobuf_1.create)(proto.Action_RevokeSessionSchema, {
|
|
121
|
+
sessionId: BigInt(params.sessionId),
|
|
122
|
+
}),
|
|
123
|
+
});
|
|
124
|
+
const resp = await sendAction(serverUrl, (m) => walletSign(walletSignFn, m), action, "revoke session");
|
|
125
|
+
return { actionId: resp.actionId };
|
|
127
126
|
}
|
|
128
|
-
async function
|
|
127
|
+
async function withdraw(serverUrl, signFn, currentTimestamp, nonce, params) {
|
|
129
128
|
const amount = (0, utils_1.toScaledU64)(params.amount, params.sizeDecimals);
|
|
130
129
|
if (amount <= 0) {
|
|
131
130
|
throw new Error("Withdraw amount must be positive");
|
|
132
131
|
}
|
|
133
|
-
const action = {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
},
|
|
144
|
-
};
|
|
145
|
-
const resp = await sendAction(sendFn, (m) => sessionSign(signFn, m), action, "withdraw");
|
|
146
|
-
if (resp.kind?.$case === "withdrawResult") {
|
|
132
|
+
const action = createAction(currentTimestamp, nonce, {
|
|
133
|
+
case: "withdraw",
|
|
134
|
+
value: (0, protobuf_1.create)(proto.Action_WithdrawSchema, {
|
|
135
|
+
sessionId: BigInt(params.sessionId),
|
|
136
|
+
tokenId: params.tokenId,
|
|
137
|
+
amount,
|
|
138
|
+
}),
|
|
139
|
+
});
|
|
140
|
+
const resp = await sendAction(serverUrl, (m) => sessionSign(signFn, m), action, "withdraw");
|
|
141
|
+
if (resp.kind?.case === "withdrawResult") {
|
|
147
142
|
return { actionId: resp.actionId, ...resp.kind.value };
|
|
148
143
|
}
|
|
149
144
|
else {
|
|
150
|
-
throw new Error(`Unexpected receipt kind ${resp.kind
|
|
145
|
+
throw new Error(`Unexpected receipt kind ${resp.kind?.case}`);
|
|
151
146
|
}
|
|
152
147
|
}
|
|
153
|
-
async function
|
|
154
|
-
return withdrawImpl(makeSendHttp(serverUrl), signFn, currentTimestamp, nonce, params);
|
|
155
|
-
}
|
|
156
|
-
async function placeOrderImpl(sendFn, signFn, currentTimestamp, nonce, params) {
|
|
148
|
+
async function placeOrder(serverUrl, signFn, currentTimestamp, nonce, params) {
|
|
157
149
|
const price = (0, utils_1.toScaledU64)(params.price ?? 0, params.priceDecimals);
|
|
158
150
|
const size = (0, utils_1.toScaledU64)(params.size ?? 0, params.sizeDecimals);
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
const action = {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
151
|
+
const scaledQuote = params.quoteSize
|
|
152
|
+
? params.quoteSize.toScaledU64(params.priceDecimals, params.sizeDecimals)
|
|
153
|
+
: undefined;
|
|
154
|
+
const action = createAction(currentTimestamp, nonce, {
|
|
155
|
+
case: "placeOrder",
|
|
156
|
+
value: (0, protobuf_1.create)(proto.Action_PlaceOrderSchema, {
|
|
157
|
+
sessionId: BigInt(params.sessionId),
|
|
158
|
+
senderAccountId: params.senderId,
|
|
159
|
+
marketId: params.marketId,
|
|
160
|
+
side: params.side === types_1.Side.Bid ? proto.Side.BID : proto.Side.ASK,
|
|
161
|
+
fillMode: (0, types_1.fillModeToProtoFillMode)(params.fillMode),
|
|
162
|
+
isReduceOnly: params.isReduceOnly,
|
|
163
|
+
price,
|
|
164
|
+
size,
|
|
165
|
+
quoteSize: scaledQuote === undefined
|
|
166
|
+
? undefined
|
|
167
|
+
: (0, protobuf_1.create)(proto.QuoteSizeSchema, {
|
|
168
|
+
size: scaledQuote.size,
|
|
169
|
+
price: scaledQuote.price,
|
|
170
|
+
}),
|
|
171
|
+
clientOrderId: params.clientOrderId === undefined
|
|
172
|
+
? undefined
|
|
173
|
+
: BigInt(params.clientOrderId),
|
|
174
|
+
delegatorAccountId: params.liquidateeId,
|
|
175
|
+
}),
|
|
176
|
+
});
|
|
177
|
+
const resp = await sendAction(serverUrl, (m) => sessionSign(signFn, m), action, "place order");
|
|
178
|
+
if (resp.kind?.case === "placeOrderResult") {
|
|
179
|
+
return {
|
|
180
|
+
actionId: resp.actionId,
|
|
181
|
+
orderId: resp.kind.value.posted?.orderId,
|
|
182
|
+
fills: resp.kind.value.fills,
|
|
183
|
+
};
|
|
187
184
|
}
|
|
188
185
|
else {
|
|
189
|
-
throw new Error(`Unexpected receipt kind ${resp.kind
|
|
186
|
+
throw new Error(`Unexpected receipt kind ${resp.kind?.case}`);
|
|
190
187
|
}
|
|
191
188
|
}
|
|
192
|
-
async function
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
const resp = await sendAction(sendFn, (m) => sessionSign(signFn, m), action, "cancel the order");
|
|
210
|
-
if (resp.kind?.$case === "cancelOrderResult") {
|
|
211
|
-
return resp.kind.value.orderId;
|
|
189
|
+
async function cancelOrder(serverUrl, signFn, currentTimestamp, nonce, params) {
|
|
190
|
+
const action = createAction(currentTimestamp, nonce, {
|
|
191
|
+
case: "cancelOrderById",
|
|
192
|
+
value: (0, protobuf_1.create)(proto.Action_CancelOrderByIdSchema, {
|
|
193
|
+
orderId: BigInt(params.orderId),
|
|
194
|
+
sessionId: BigInt(params.sessionId),
|
|
195
|
+
senderAccountId: params.senderId,
|
|
196
|
+
delegatorAccountId: params.liquidateeId,
|
|
197
|
+
}),
|
|
198
|
+
});
|
|
199
|
+
const resp = await sendAction(serverUrl, (m) => sessionSign(signFn, m), action, "cancel order");
|
|
200
|
+
if (resp.kind?.case === "cancelOrderResult") {
|
|
201
|
+
return {
|
|
202
|
+
actionId: resp.actionId,
|
|
203
|
+
orderId: resp.kind.value.orderId,
|
|
204
|
+
accountId: resp.kind.value.accountId,
|
|
205
|
+
};
|
|
212
206
|
}
|
|
213
207
|
else {
|
|
214
|
-
throw new Error(`Unexpected receipt kind ${resp.kind
|
|
208
|
+
throw new Error(`Unexpected receipt kind ${resp.kind?.case}`);
|
|
215
209
|
}
|
|
216
210
|
}
|
|
217
|
-
async function
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
return resp.kind.value.toUserAccount;
|
|
239
|
-
}
|
|
240
|
-
else {
|
|
241
|
-
return undefined;
|
|
242
|
-
}
|
|
211
|
+
async function transfer(serverUrl, signFn, currentTimestamp, nonce, params) {
|
|
212
|
+
const action = createAction(currentTimestamp, nonce, {
|
|
213
|
+
case: "transfer",
|
|
214
|
+
value: (0, protobuf_1.create)(proto.Action_TransferSchema, {
|
|
215
|
+
sessionId: BigInt(params.sessionId),
|
|
216
|
+
fromAccountId: params.fromAccountId,
|
|
217
|
+
toAccountId: params.toAccountId,
|
|
218
|
+
tokenId: params.tokenId,
|
|
219
|
+
amount: (0, utils_1.toScaledU64)(params.amount ?? 0, params.tokenDecimals),
|
|
220
|
+
}),
|
|
221
|
+
});
|
|
222
|
+
const resp = await sendAction(serverUrl, (m) => sessionSign(signFn, m), action, "transfer");
|
|
223
|
+
if (resp.kind?.case === "transferred") {
|
|
224
|
+
return {
|
|
225
|
+
actionId: resp.actionId,
|
|
226
|
+
fromAccountId: resp.kind.value.fromAccountId,
|
|
227
|
+
toAccountId: resp.kind.value.toUserAccount,
|
|
228
|
+
tokenId: resp.kind.value.tokenId,
|
|
229
|
+
amount: resp.kind.value.amount,
|
|
230
|
+
accountCreated: resp.kind.value.accountCreated,
|
|
231
|
+
};
|
|
243
232
|
}
|
|
244
233
|
else {
|
|
245
|
-
throw new Error(`Unexpected receipt kind ${resp.kind
|
|
234
|
+
throw new Error(`Unexpected receipt kind ${resp.kind?.case}`);
|
|
246
235
|
}
|
|
247
236
|
}
|
|
248
|
-
async function
|
|
249
|
-
return transferImpl(makeSendHttp(serverUrl), signFn, currentTimestamp, nonce, params);
|
|
250
|
-
}
|
|
251
|
-
async function atomicImpl(sendFn, signFn, currentTimestamp, nonce, params) {
|
|
237
|
+
async function atomic(serverUrl, signFn, currentTimestamp, nonce, params) {
|
|
252
238
|
(0, utils_1.assert)(params.actions.length > 0 && params.actions.length <= 4, "Atomic action must contain between 1 and 4 sub-actions");
|
|
253
239
|
const subactions = params.actions.map((a) => {
|
|
254
240
|
if (a.kind === "place") {
|
|
255
241
|
const price = (0, utils_1.toScaledU64)(a.price ?? 0, a.priceDecimals);
|
|
256
242
|
const size = (0, utils_1.toScaledU64)(a.size ?? 0, a.sizeDecimals);
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
|
|
243
|
+
const scaledQuote = a.quoteSize
|
|
244
|
+
? a.quoteSize.toScaledU64(a.priceDecimals, a.sizeDecimals)
|
|
245
|
+
: undefined;
|
|
246
|
+
const tradeOrPlace = (0, protobuf_1.create)(proto.TradeOrPlaceSchema, {
|
|
260
247
|
marketId: a.marketId,
|
|
261
|
-
orderType: {
|
|
248
|
+
orderType: (0, protobuf_1.create)(proto.OrderTypeSchema, {
|
|
262
249
|
side: a.side === types_1.Side.Bid ? proto.Side.BID : proto.Side.ASK,
|
|
263
250
|
fillMode: (0, types_1.fillModeToProtoFillMode)(a.fillMode),
|
|
264
251
|
isReduceOnly: a.isReduceOnly,
|
|
265
|
-
},
|
|
266
|
-
limit: {
|
|
252
|
+
}),
|
|
253
|
+
limit: (0, protobuf_1.create)(proto.OrderLimitSchema, {
|
|
267
254
|
price,
|
|
268
255
|
size,
|
|
269
|
-
quoteSize:
|
|
270
|
-
|
|
256
|
+
quoteSize: scaledQuote === undefined
|
|
257
|
+
? undefined
|
|
258
|
+
: (0, protobuf_1.create)(proto.QuoteSizeSchema, {
|
|
259
|
+
size: scaledQuote.size,
|
|
260
|
+
price: scaledQuote.price,
|
|
261
|
+
}),
|
|
262
|
+
}),
|
|
271
263
|
clientOrderId: a.clientOrderId === undefined ? undefined : BigInt(a.clientOrderId),
|
|
272
|
-
};
|
|
273
|
-
return {
|
|
274
|
-
inner: {
|
|
275
|
-
};
|
|
264
|
+
});
|
|
265
|
+
return (0, protobuf_1.create)(proto.AtomicSubactionKindSchema, {
|
|
266
|
+
inner: { case: "tradeOrPlace", value: tradeOrPlace },
|
|
267
|
+
});
|
|
276
268
|
}
|
|
269
|
+
return (0, protobuf_1.create)(proto.AtomicSubactionKindSchema, {
|
|
270
|
+
inner: {
|
|
271
|
+
case: "cancelOrder",
|
|
272
|
+
value: (0, protobuf_1.create)(proto.CancelOrderSchema, { orderId: BigInt(a.orderId) }),
|
|
273
|
+
},
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
const action = createAction(currentTimestamp, nonce, {
|
|
277
|
+
case: "atomic",
|
|
278
|
+
value: (0, protobuf_1.create)(proto.AtomicSchema, {
|
|
279
|
+
sessionId: BigInt(params.sessionId),
|
|
280
|
+
accountId: params.accountId, // optional
|
|
281
|
+
actions: subactions,
|
|
282
|
+
}),
|
|
283
|
+
});
|
|
284
|
+
const resp = await sendAction(serverUrl, (m) => sessionSign(signFn, m), action, "execute atomic action");
|
|
285
|
+
if (resp.kind?.case === "atomic") {
|
|
277
286
|
return {
|
|
278
|
-
|
|
287
|
+
actionId: resp.actionId,
|
|
288
|
+
results: resp.kind.value.results,
|
|
279
289
|
};
|
|
280
|
-
});
|
|
281
|
-
const action = {
|
|
282
|
-
currentTimestamp,
|
|
283
|
-
nonce,
|
|
284
|
-
kind: {
|
|
285
|
-
$case: "atomic",
|
|
286
|
-
value: {
|
|
287
|
-
sessionId: BigInt(params.sessionId),
|
|
288
|
-
accountId: params.accountId, // optional
|
|
289
|
-
actions: subactions,
|
|
290
|
-
},
|
|
291
|
-
},
|
|
292
|
-
};
|
|
293
|
-
const resp = await sendAction(sendFn, (m) => sessionSign(signFn, m), action, "execute atomic action");
|
|
294
|
-
if (resp.kind?.$case === "atomic") {
|
|
295
|
-
return resp.kind.value;
|
|
296
290
|
}
|
|
297
|
-
throw new Error(`Unexpected receipt kind ${resp.kind
|
|
298
|
-
}
|
|
299
|
-
async function atomic(serverUrl, signFn, currentTimestamp, nonce, params) {
|
|
300
|
-
return atomicImpl(makeSendHttp(serverUrl), signFn, currentTimestamp, nonce, params);
|
|
291
|
+
throw new Error(`Unexpected receipt kind ${resp.kind?.case}`);
|
|
301
292
|
}
|
|
302
|
-
/**
|
|
303
|
-
* For testing purposes
|
|
304
|
-
*/
|
|
305
|
-
exports._private = {
|
|
306
|
-
createSessionImpl,
|
|
307
|
-
revokeSessionImpl,
|
|
308
|
-
withdrawImpl,
|
|
309
|
-
placeOrderImpl,
|
|
310
|
-
cancelOrderImpl,
|
|
311
|
-
transferImpl,
|
|
312
|
-
atomicImpl,
|
|
313
|
-
};
|
package/dist/nord/api/core.d.ts
CHANGED
|
@@ -13,4 +13,4 @@ import { NordWebSocketClient } from "../../websocket/index";
|
|
|
13
13
|
* @returns WebSocket client
|
|
14
14
|
* @throws {NordError} If initialization fails or invalid subscription is provided
|
|
15
15
|
*/
|
|
16
|
-
export declare function initWebSocketClient(webServerUrl: string, subscriptions?: SubscriptionPattern[] | "trades" | "delta" | "account"
|
|
16
|
+
export declare function initWebSocketClient(webServerUrl: string, subscriptions?: SubscriptionPattern[] | "trades" | "delta" | "account"): NordWebSocketClient;
|
package/dist/nord/api/core.js
CHANGED
|
@@ -16,11 +16,10 @@ const NordError_1 = require("../utils/NordError");
|
|
|
16
16
|
* @returns WebSocket client
|
|
17
17
|
* @throws {NordError} If initialization fails or invalid subscription is provided
|
|
18
18
|
*/
|
|
19
|
-
function initWebSocketClient(webServerUrl, subscriptions
|
|
19
|
+
function initWebSocketClient(webServerUrl, subscriptions) {
|
|
20
20
|
try {
|
|
21
21
|
// Determine URL and subscriptions based on parameters
|
|
22
22
|
let wsUrl = webServerUrl.replace(/^http/, "ws") + `/ws`;
|
|
23
|
-
let wsSubscriptions = [];
|
|
24
23
|
// Validate subscriptions parameter
|
|
25
24
|
if (typeof subscriptions === "string") {
|
|
26
25
|
// Legacy mode - handle endpoint string
|
|
@@ -28,12 +27,6 @@ function initWebSocketClient(webServerUrl, subscriptions, initialSubscriptions)
|
|
|
28
27
|
subscriptions === "delta" ||
|
|
29
28
|
subscriptions === "account") {
|
|
30
29
|
wsUrl += `/${subscriptions}`;
|
|
31
|
-
// If initialSubscriptions provided, use them
|
|
32
|
-
if (initialSubscriptions && initialSubscriptions.length > 0) {
|
|
33
|
-
// Validate initialSubscriptions
|
|
34
|
-
initialSubscriptions.forEach(validateSubscription);
|
|
35
|
-
wsSubscriptions = initialSubscriptions;
|
|
36
|
-
}
|
|
37
30
|
}
|
|
38
31
|
else {
|
|
39
32
|
throw new NordError_1.NordError(`Invalid endpoint: ${subscriptions}. Must be "trades", "deltas", or "account".`);
|
|
@@ -58,11 +51,6 @@ function initWebSocketClient(webServerUrl, subscriptions, initialSubscriptions)
|
|
|
58
51
|
// Add connected handler for debugging
|
|
59
52
|
ws.on("connected", () => {
|
|
60
53
|
console.log("Nord WebSocket connected successfully");
|
|
61
|
-
// Subscribe to additional subscriptions if provided
|
|
62
|
-
// For new format, these are already part of the URL
|
|
63
|
-
if (wsSubscriptions.length > 0) {
|
|
64
|
-
ws.subscribe(wsSubscriptions);
|
|
65
|
-
}
|
|
66
54
|
});
|
|
67
55
|
// Connect the WebSocket
|
|
68
56
|
ws.connect();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { EventEmitter } from "events";
|
|
2
|
-
import { PublicKey } from "@solana/web3.js";
|
|
3
|
-
import { Info, Account, ActionResponse, AggregateMetrics, Market, NordConfig, OrderbookQuery, OrderbookResponse, PeakTpsPeriodUnit, Token, TradesResponse, User, MarketStats } from "../../types";
|
|
4
1
|
import { ProtonClient } from "@n1xyz/proton";
|
|
2
|
+
import { PublicKey } from "@solana/web3.js";
|
|
3
|
+
import { EventEmitter } from "events";
|
|
4
|
+
import { Account, ActionResponse, AggregateMetrics, Info, Market, MarketStats, NordConfig, OrderbookQuery, OrderbookResponse, PeakTpsPeriodUnit, Token, TradesResponse, User } from "../../types";
|
|
5
5
|
import { NordWebSocketClient } from "../../websocket/index";
|
|
6
6
|
import { OrderbookSubscription, TradeSubscription } from "../models/Subscriber";
|
|
7
7
|
/**
|
package/dist/nord/client/Nord.js
CHANGED
|
@@ -37,15 +37,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.Nord = void 0;
|
|
40
|
-
const
|
|
40
|
+
const proton_1 = require("@n1xyz/proton");
|
|
41
41
|
const web3_js_1 = require("@solana/web3.js");
|
|
42
|
+
const events_1 = require("events");
|
|
42
43
|
const openapi_fetch_1 = __importDefault(require("openapi-fetch"));
|
|
44
|
+
const proto = __importStar(require("../../gen/nord_pb"));
|
|
43
45
|
const types_1 = require("../../types");
|
|
44
|
-
const
|
|
45
|
-
const proto = __importStar(require("../../gen/nord"));
|
|
46
|
+
const utils = __importStar(require("../../utils"));
|
|
46
47
|
const core = __importStar(require("../api/core"));
|
|
47
48
|
const metrics = __importStar(require("../api/metrics"));
|
|
48
|
-
const utils = __importStar(require("../../utils"));
|
|
49
49
|
const NordError_1 = require("../utils/NordError");
|
|
50
50
|
/**
|
|
51
51
|
* Main Nord client class for interacting with the Nord API
|
|
@@ -240,8 +240,8 @@ class Nord {
|
|
|
240
240
|
});
|
|
241
241
|
return xs.map((x) => ({
|
|
242
242
|
actionId: x.actionId,
|
|
243
|
-
action: utils.decodeLengthDelimited(Buffer.from(x.payload, "base64"), proto.
|
|
244
|
-
physicalExecTime: new Date(x.physicalTime
|
|
243
|
+
action: utils.decodeLengthDelimited(Buffer.from(x.payload, "base64"), proto.ActionSchema),
|
|
244
|
+
physicalExecTime: new Date(x.physicalTime),
|
|
245
245
|
}));
|
|
246
246
|
}
|
|
247
247
|
/**
|
|
@@ -336,7 +336,6 @@ class Nord {
|
|
|
336
336
|
};
|
|
337
337
|
wsClient.on("delta", handleDelta);
|
|
338
338
|
subscription.close = () => {
|
|
339
|
-
wsClient.unsubscribe([`deltas@${symbol}`]);
|
|
340
339
|
wsClient.removeListener("delta", handleDelta);
|
|
341
340
|
subscription.removeAllListeners();
|
|
342
341
|
};
|
|
@@ -365,7 +364,6 @@ class Nord {
|
|
|
365
364
|
};
|
|
366
365
|
wsClient.on("trades", handleTrade);
|
|
367
366
|
subscription.close = () => {
|
|
368
|
-
wsClient.unsubscribe([`trades@${symbol}`]);
|
|
369
367
|
wsClient.removeListener("trades", handleTrade);
|
|
370
368
|
subscription.removeAllListeners();
|
|
371
369
|
};
|
|
@@ -394,7 +392,6 @@ class Nord {
|
|
|
394
392
|
};
|
|
395
393
|
wsClient.on("account", handleAccountUpdate);
|
|
396
394
|
subscription.close = () => {
|
|
397
|
-
wsClient.unsubscribe([`account@${accountId}`]);
|
|
398
395
|
wsClient.removeListener("account", handleAccountUpdate);
|
|
399
396
|
subscription.removeAllListeners();
|
|
400
397
|
};
|