@usherlabs/cex-broker 0.2.30 → 0.2.32
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/commands/cli.js
CHANGED
|
@@ -315603,6 +315603,7 @@ function buildTransferEventArchiveRow(input) {
|
|
|
315603
315603
|
address: transfer.address,
|
|
315604
315604
|
network: transfer.network,
|
|
315605
315605
|
external_id: transfer.externalId ?? "",
|
|
315606
|
+
client_withdrawal_id: transfer.clientWithdrawalId ?? "",
|
|
315606
315607
|
txid: transfer.txid,
|
|
315607
315608
|
result_index: transfer.resultIndex ?? 0,
|
|
315608
315609
|
fee_amount: transfer.feeAmount,
|
|
@@ -331489,6 +331490,7 @@ async function handleCreateOrder(ctx) {
|
|
|
331489
331490
|
}
|
|
331490
331491
|
};
|
|
331491
331492
|
let resolvedOrderTelemetry = {};
|
|
331493
|
+
let marketMetadataHash;
|
|
331492
331494
|
try {
|
|
331493
331495
|
if (!broker) {
|
|
331494
331496
|
return ctx.wrappedCallback({
|
|
@@ -331513,7 +331515,7 @@ async function handleCreateOrder(ctx) {
|
|
|
331513
331515
|
}
|
|
331514
331516
|
const telemetryIds = extractOrderTelemetryIds(createOrderParams);
|
|
331515
331517
|
const submissionTimestamp = new Date().toISOString();
|
|
331516
|
-
|
|
331518
|
+
marketMetadataHash = await captureMarketMetadataSnapshot(brokerArchiver, broker, {
|
|
331517
331519
|
exchange: cex3,
|
|
331518
331520
|
accountSelector: selectedBrokerAccount?.label,
|
|
331519
331521
|
symbol: resolution.symbol,
|
|
@@ -331552,7 +331554,7 @@ async function handleCreateOrder(ctx) {
|
|
|
331552
331554
|
...extractOrderTelemetryIds(createOrderParams)
|
|
331553
331555
|
};
|
|
331554
331556
|
emitOrderExecutionTelemetryInBackground(otelMetrics, failedCreateContext, undefined, error48);
|
|
331555
|
-
archiveOrderExecutionInBackground(brokerArchiver, failedCreateContext, undefined, error48);
|
|
331557
|
+
archiveOrderExecutionInBackground(brokerArchiver, failedCreateContext, undefined, error48, { marketMetadataHash });
|
|
331556
331558
|
ctx.wrappedCallback({
|
|
331557
331559
|
code: grpc6.status.INTERNAL,
|
|
331558
331560
|
message: `Order Creation failed: ${sanitizeErrorDetail(error48)}`
|
|
@@ -332250,6 +332252,8 @@ async function handleTreasuryCall(ctx) {
|
|
|
332250
332252
|
const callValue = parsePayloadForAction(ctx, CallPayloadSchema);
|
|
332251
332253
|
if (callValue === null)
|
|
332252
332254
|
return;
|
|
332255
|
+
let createOrderContext;
|
|
332256
|
+
let marketMetadataHash;
|
|
332253
332257
|
try {
|
|
332254
332258
|
if (callValue.functionName.startsWith("_") || callValue.functionName.includes("constructor") || callValue.functionName.includes("prototype")) {
|
|
332255
332259
|
return ctx.wrappedCallback({
|
|
@@ -332272,8 +332276,41 @@ async function handleTreasuryCall(ctx) {
|
|
|
332272
332276
|
message: `Function not found on broker: ${callValue.functionName}`
|
|
332273
332277
|
}, null);
|
|
332274
332278
|
}
|
|
332279
|
+
if (callValue.functionName === "createOrder") {
|
|
332280
|
+
const [symbol2, orderType, side, quantity, price] = callValue.args;
|
|
332281
|
+
const requestedQuantity = asFiniteNumber(quantity);
|
|
332282
|
+
const requestedPrice = asFiniteNumber(price);
|
|
332283
|
+
const requestedNotional = requestedQuantity !== undefined && requestedPrice !== undefined ? asFiniteNumber(requestedQuantity * requestedPrice) : undefined;
|
|
332284
|
+
const telemetryIds = extractOrderTelemetryIds(callValue.params);
|
|
332285
|
+
const submissionTimestamp = new Date().toISOString();
|
|
332286
|
+
createOrderContext = {
|
|
332287
|
+
action: "CreateOrder",
|
|
332288
|
+
cex: ctx.cex,
|
|
332289
|
+
accountLabel: ctx.selectedBrokerAccount?.label,
|
|
332290
|
+
symbol: asNonEmptyString(symbol2),
|
|
332291
|
+
orderType: asNonEmptyString(orderType),
|
|
332292
|
+
side: asNonEmptyString(side),
|
|
332293
|
+
requestedQuantity,
|
|
332294
|
+
requestedNotional,
|
|
332295
|
+
brokerObservedTimestamp: submissionTimestamp,
|
|
332296
|
+
...telemetryIds
|
|
332297
|
+
};
|
|
332298
|
+
if (createOrderContext.symbol !== undefined) {
|
|
332299
|
+
marketMetadataHash = await captureMarketMetadataSnapshot(ctx.brokerArchiver, broker, {
|
|
332300
|
+
exchange: ctx.cex,
|
|
332301
|
+
accountSelector: ctx.selectedBrokerAccount?.label,
|
|
332302
|
+
symbol: createOrderContext.symbol,
|
|
332303
|
+
action: "CreateOrder",
|
|
332304
|
+
brokerObservedTimestamp: submissionTimestamp,
|
|
332305
|
+
...telemetryIds
|
|
332306
|
+
});
|
|
332307
|
+
}
|
|
332308
|
+
}
|
|
332275
332309
|
const result = await fn.apply(broker, argsArray);
|
|
332276
|
-
if (
|
|
332310
|
+
if (createOrderContext !== undefined) {
|
|
332311
|
+
emitOrderExecutionTelemetryInBackground(ctx.otelMetrics, createOrderContext, result);
|
|
332312
|
+
archiveOrderExecutionInBackground(ctx.brokerArchiver, createOrderContext, result, undefined, { marketMetadataHash });
|
|
332313
|
+
} else if (callValue.functionName === "fetchWithdrawals") {
|
|
332277
332314
|
archiveWithdrawalObservationsInBackground(ctx.brokerArchiver, ctx.withdrawalObservationTracker, {
|
|
332278
332315
|
exchange: ctx.normalizedCex,
|
|
332279
332316
|
accountSelector: ctx.selectedBrokerAccount?.label,
|
|
@@ -332285,6 +332322,11 @@ async function handleTreasuryCall(ctx) {
|
|
|
332285
332322
|
result: JSON.stringify(result)
|
|
332286
332323
|
});
|
|
332287
332324
|
} catch (error48) {
|
|
332325
|
+
if (createOrderContext !== undefined) {
|
|
332326
|
+
rethrowArchiveDurabilityError(error48);
|
|
332327
|
+
emitOrderExecutionTelemetryInBackground(ctx.otelMetrics, createOrderContext, undefined, error48);
|
|
332328
|
+
archiveOrderExecutionInBackground(ctx.brokerArchiver, createOrderContext, undefined, error48, { marketMetadataHash });
|
|
332329
|
+
}
|
|
332288
332330
|
safeLogError("Call failed", error48);
|
|
332289
332331
|
rejectWithGrpcError(ctx, error48, {
|
|
332290
332332
|
message: getErrorMessage(error48),
|
|
@@ -332293,6 +332335,19 @@ async function handleTreasuryCall(ctx) {
|
|
|
332293
332335
|
});
|
|
332294
332336
|
}
|
|
332295
332337
|
}
|
|
332338
|
+
function asNonEmptyString(value) {
|
|
332339
|
+
return typeof value === "string" && value.trim() ? value : undefined;
|
|
332340
|
+
}
|
|
332341
|
+
function asFiniteNumber(value) {
|
|
332342
|
+
if (typeof value === "number") {
|
|
332343
|
+
return Number.isFinite(value) ? value : undefined;
|
|
332344
|
+
}
|
|
332345
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
332346
|
+
return;
|
|
332347
|
+
}
|
|
332348
|
+
const parsed = Number(value);
|
|
332349
|
+
return Number.isFinite(parsed) ? parsed : undefined;
|
|
332350
|
+
}
|
|
332296
332351
|
|
|
332297
332352
|
// src/handlers/execute-action/withdraw.ts
|
|
332298
332353
|
var grpc10 = __toESM(require_src3(), 1);
|
|
@@ -332349,6 +332404,8 @@ async function handleWithdraw(ctx) {
|
|
|
332349
332404
|
message: `travel_rule_denied: ${travelRule.error}`
|
|
332350
332405
|
}, null);
|
|
332351
332406
|
}
|
|
332407
|
+
const withdrawOrderId = transferValue.params.withdrawOrderId;
|
|
332408
|
+
const clientWithdrawalId = typeof withdrawOrderId === "string" && withdrawOrderId.length > 0 ? withdrawOrderId : undefined;
|
|
332352
332409
|
try {
|
|
332353
332410
|
const transaction = travelRule.mode === "localentity" ? await withdrawViaLocalEntity(broker, {
|
|
332354
332411
|
code: symbol2,
|
|
@@ -332375,6 +332432,7 @@ async function handleWithdraw(ctx) {
|
|
|
332375
332432
|
address: normalized.address ?? transferValue.recipientAddress,
|
|
332376
332433
|
network: normalized.network ?? withdrawNetwork.exchangeNetworkId,
|
|
332377
332434
|
externalId: normalized.externalId,
|
|
332435
|
+
clientWithdrawalId,
|
|
332378
332436
|
txid: normalized.txid,
|
|
332379
332437
|
feeAmount: normalized.feeAmount,
|
|
332380
332438
|
feeCurrency: normalized.feeCurrency,
|
|
@@ -332404,6 +332462,7 @@ async function handleWithdraw(ctx) {
|
|
|
332404
332462
|
amount: String(transferValue.amount),
|
|
332405
332463
|
address: transferValue.recipientAddress,
|
|
332406
332464
|
network: withdrawNetwork.exchangeNetworkId,
|
|
332465
|
+
clientWithdrawalId,
|
|
332407
332466
|
errorSummary: getErrorMessage(error48),
|
|
332408
332467
|
payload: { recipientAddress: transferValue.recipientAddress }
|
|
332409
332468
|
}
|
|
@@ -45,4 +45,4 @@ export type OrderExecutionTelemetry = {
|
|
|
45
45
|
export declare function emitOrderExecutionTelemetry(otelMetrics: OtelMetrics | undefined, context: OrderTelemetryContext, order: unknown, error?: unknown): Promise<OrderExecutionTelemetry | undefined>;
|
|
46
46
|
export declare function buildOrderExecutionTelemetry(context: OrderTelemetryContext, order: unknown, error?: unknown): OrderExecutionTelemetry;
|
|
47
47
|
export declare function emitOrderExecutionTelemetryInBackground(otelMetrics: OtelMetrics | undefined, context: OrderTelemetryContext, order: unknown, error?: unknown): void;
|
|
48
|
-
export declare function extractOrderTelemetryIds(params: Record<string,
|
|
48
|
+
export declare function extractOrderTelemetryIds(params: Record<string, unknown> | undefined): Pick<OrderTelemetryContext, "clientOrderId" | "idempotencyId" | "makerActionId">;
|
package/dist/index.js
CHANGED
|
@@ -291117,6 +291117,7 @@ function buildTransferEventArchiveRow(input) {
|
|
|
291117
291117
|
address: transfer.address,
|
|
291118
291118
|
network: transfer.network,
|
|
291119
291119
|
external_id: transfer.externalId ?? "",
|
|
291120
|
+
client_withdrawal_id: transfer.clientWithdrawalId ?? "",
|
|
291120
291121
|
txid: transfer.txid,
|
|
291121
291122
|
result_index: transfer.resultIndex ?? 0,
|
|
291122
291123
|
fee_amount: transfer.feeAmount,
|
|
@@ -307003,6 +307004,7 @@ async function handleCreateOrder(ctx) {
|
|
|
307003
307004
|
}
|
|
307004
307005
|
};
|
|
307005
307006
|
let resolvedOrderTelemetry = {};
|
|
307007
|
+
let marketMetadataHash;
|
|
307006
307008
|
try {
|
|
307007
307009
|
if (!broker) {
|
|
307008
307010
|
return ctx.wrappedCallback({
|
|
@@ -307027,7 +307029,7 @@ async function handleCreateOrder(ctx) {
|
|
|
307027
307029
|
}
|
|
307028
307030
|
const telemetryIds = extractOrderTelemetryIds(createOrderParams);
|
|
307029
307031
|
const submissionTimestamp = new Date().toISOString();
|
|
307030
|
-
|
|
307032
|
+
marketMetadataHash = await captureMarketMetadataSnapshot(brokerArchiver, broker, {
|
|
307031
307033
|
exchange: cex3,
|
|
307032
307034
|
accountSelector: selectedBrokerAccount?.label,
|
|
307033
307035
|
symbol: resolution.symbol,
|
|
@@ -307066,7 +307068,7 @@ async function handleCreateOrder(ctx) {
|
|
|
307066
307068
|
...extractOrderTelemetryIds(createOrderParams)
|
|
307067
307069
|
};
|
|
307068
307070
|
emitOrderExecutionTelemetryInBackground(otelMetrics, failedCreateContext, undefined, error48);
|
|
307069
|
-
archiveOrderExecutionInBackground(brokerArchiver, failedCreateContext, undefined, error48);
|
|
307071
|
+
archiveOrderExecutionInBackground(brokerArchiver, failedCreateContext, undefined, error48, { marketMetadataHash });
|
|
307070
307072
|
ctx.wrappedCallback({
|
|
307071
307073
|
code: grpc6.status.INTERNAL,
|
|
307072
307074
|
message: `Order Creation failed: ${sanitizeErrorDetail(error48)}`
|
|
@@ -307764,6 +307766,8 @@ async function handleTreasuryCall(ctx) {
|
|
|
307764
307766
|
const callValue = parsePayloadForAction(ctx, CallPayloadSchema);
|
|
307765
307767
|
if (callValue === null)
|
|
307766
307768
|
return;
|
|
307769
|
+
let createOrderContext;
|
|
307770
|
+
let marketMetadataHash;
|
|
307767
307771
|
try {
|
|
307768
307772
|
if (callValue.functionName.startsWith("_") || callValue.functionName.includes("constructor") || callValue.functionName.includes("prototype")) {
|
|
307769
307773
|
return ctx.wrappedCallback({
|
|
@@ -307786,8 +307790,41 @@ async function handleTreasuryCall(ctx) {
|
|
|
307786
307790
|
message: `Function not found on broker: ${callValue.functionName}`
|
|
307787
307791
|
}, null);
|
|
307788
307792
|
}
|
|
307793
|
+
if (callValue.functionName === "createOrder") {
|
|
307794
|
+
const [symbol2, orderType, side, quantity, price] = callValue.args;
|
|
307795
|
+
const requestedQuantity = asFiniteNumber(quantity);
|
|
307796
|
+
const requestedPrice = asFiniteNumber(price);
|
|
307797
|
+
const requestedNotional = requestedQuantity !== undefined && requestedPrice !== undefined ? asFiniteNumber(requestedQuantity * requestedPrice) : undefined;
|
|
307798
|
+
const telemetryIds = extractOrderTelemetryIds(callValue.params);
|
|
307799
|
+
const submissionTimestamp = new Date().toISOString();
|
|
307800
|
+
createOrderContext = {
|
|
307801
|
+
action: "CreateOrder",
|
|
307802
|
+
cex: ctx.cex,
|
|
307803
|
+
accountLabel: ctx.selectedBrokerAccount?.label,
|
|
307804
|
+
symbol: asNonEmptyString(symbol2),
|
|
307805
|
+
orderType: asNonEmptyString(orderType),
|
|
307806
|
+
side: asNonEmptyString(side),
|
|
307807
|
+
requestedQuantity,
|
|
307808
|
+
requestedNotional,
|
|
307809
|
+
brokerObservedTimestamp: submissionTimestamp,
|
|
307810
|
+
...telemetryIds
|
|
307811
|
+
};
|
|
307812
|
+
if (createOrderContext.symbol !== undefined) {
|
|
307813
|
+
marketMetadataHash = await captureMarketMetadataSnapshot(ctx.brokerArchiver, broker, {
|
|
307814
|
+
exchange: ctx.cex,
|
|
307815
|
+
accountSelector: ctx.selectedBrokerAccount?.label,
|
|
307816
|
+
symbol: createOrderContext.symbol,
|
|
307817
|
+
action: "CreateOrder",
|
|
307818
|
+
brokerObservedTimestamp: submissionTimestamp,
|
|
307819
|
+
...telemetryIds
|
|
307820
|
+
});
|
|
307821
|
+
}
|
|
307822
|
+
}
|
|
307789
307823
|
const result = await fn.apply(broker, argsArray);
|
|
307790
|
-
if (
|
|
307824
|
+
if (createOrderContext !== undefined) {
|
|
307825
|
+
emitOrderExecutionTelemetryInBackground(ctx.otelMetrics, createOrderContext, result);
|
|
307826
|
+
archiveOrderExecutionInBackground(ctx.brokerArchiver, createOrderContext, result, undefined, { marketMetadataHash });
|
|
307827
|
+
} else if (callValue.functionName === "fetchWithdrawals") {
|
|
307791
307828
|
archiveWithdrawalObservationsInBackground(ctx.brokerArchiver, ctx.withdrawalObservationTracker, {
|
|
307792
307829
|
exchange: ctx.normalizedCex,
|
|
307793
307830
|
accountSelector: ctx.selectedBrokerAccount?.label,
|
|
@@ -307799,6 +307836,11 @@ async function handleTreasuryCall(ctx) {
|
|
|
307799
307836
|
result: JSON.stringify(result)
|
|
307800
307837
|
});
|
|
307801
307838
|
} catch (error48) {
|
|
307839
|
+
if (createOrderContext !== undefined) {
|
|
307840
|
+
rethrowArchiveDurabilityError(error48);
|
|
307841
|
+
emitOrderExecutionTelemetryInBackground(ctx.otelMetrics, createOrderContext, undefined, error48);
|
|
307842
|
+
archiveOrderExecutionInBackground(ctx.brokerArchiver, createOrderContext, undefined, error48, { marketMetadataHash });
|
|
307843
|
+
}
|
|
307802
307844
|
safeLogError("Call failed", error48);
|
|
307803
307845
|
rejectWithGrpcError(ctx, error48, {
|
|
307804
307846
|
message: getErrorMessage(error48),
|
|
@@ -307807,6 +307849,19 @@ async function handleTreasuryCall(ctx) {
|
|
|
307807
307849
|
});
|
|
307808
307850
|
}
|
|
307809
307851
|
}
|
|
307852
|
+
function asNonEmptyString(value) {
|
|
307853
|
+
return typeof value === "string" && value.trim() ? value : undefined;
|
|
307854
|
+
}
|
|
307855
|
+
function asFiniteNumber(value) {
|
|
307856
|
+
if (typeof value === "number") {
|
|
307857
|
+
return Number.isFinite(value) ? value : undefined;
|
|
307858
|
+
}
|
|
307859
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
307860
|
+
return;
|
|
307861
|
+
}
|
|
307862
|
+
const parsed = Number(value);
|
|
307863
|
+
return Number.isFinite(parsed) ? parsed : undefined;
|
|
307864
|
+
}
|
|
307810
307865
|
|
|
307811
307866
|
// src/handlers/execute-action/withdraw.ts
|
|
307812
307867
|
import * as grpc10 from "@grpc/grpc-js";
|
|
@@ -307863,6 +307918,8 @@ async function handleWithdraw(ctx) {
|
|
|
307863
307918
|
message: `travel_rule_denied: ${travelRule.error}`
|
|
307864
307919
|
}, null);
|
|
307865
307920
|
}
|
|
307921
|
+
const withdrawOrderId = transferValue.params.withdrawOrderId;
|
|
307922
|
+
const clientWithdrawalId = typeof withdrawOrderId === "string" && withdrawOrderId.length > 0 ? withdrawOrderId : undefined;
|
|
307866
307923
|
try {
|
|
307867
307924
|
const transaction = travelRule.mode === "localentity" ? await withdrawViaLocalEntity(broker, {
|
|
307868
307925
|
code: symbol2,
|
|
@@ -307889,6 +307946,7 @@ async function handleWithdraw(ctx) {
|
|
|
307889
307946
|
address: normalized.address ?? transferValue.recipientAddress,
|
|
307890
307947
|
network: normalized.network ?? withdrawNetwork.exchangeNetworkId,
|
|
307891
307948
|
externalId: normalized.externalId,
|
|
307949
|
+
clientWithdrawalId,
|
|
307892
307950
|
txid: normalized.txid,
|
|
307893
307951
|
feeAmount: normalized.feeAmount,
|
|
307894
307952
|
feeCurrency: normalized.feeCurrency,
|
|
@@ -307918,6 +307976,7 @@ async function handleWithdraw(ctx) {
|
|
|
307918
307976
|
amount: String(transferValue.amount),
|
|
307919
307977
|
address: transferValue.recipientAddress,
|
|
307920
307978
|
network: withdrawNetwork.exchangeNetworkId,
|
|
307979
|
+
clientWithdrawalId,
|
|
307921
307980
|
errorSummary: getErrorMessage(error48),
|
|
307922
307981
|
payload: { recipientAddress: transferValue.recipientAddress }
|
|
307923
307982
|
}
|
|
@@ -310126,4 +310185,4 @@ export {
|
|
|
310126
310185
|
CEXBroker as default
|
|
310127
310186
|
};
|
|
310128
310187
|
|
|
310129
|
-
//# debugId=
|
|
310188
|
+
//# debugId=109E847089BBC4A964756E2164756E21
|