@usherlabs/cex-broker 0.2.0 → 0.2.1
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 +2 -2
- package/dist/helpers/constants.d.ts +1 -0
- package/dist/helpers/index.d.ts +62 -0
- package/dist/helpers/logger.d.ts +9 -0
- package/dist/helpers/otel.d.ts +70 -0
- package/dist/index.js +3 -3
- package/dist/index.js.map +3 -3
- package/dist/proto/cex_broker/Action.d.ts +17 -0
- package/dist/proto/cex_broker/ActionRequest.d.ts +17 -0
- package/dist/proto/cex_broker/ActionResponse.d.ts +8 -0
- package/dist/proto/cex_broker/SubscribeRequest.d.ts +17 -0
- package/dist/proto/cex_broker/SubscribeResponse.d.ts +14 -0
- package/dist/proto/cex_broker/SubscriptionType.d.ts +11 -0
- package/dist/proto/cex_broker/cex_service.d.ts +28 -0
- package/dist/proto/node.d.ts +20 -0
- package/dist/proto/node.descriptor.d.ts +124 -0
- package/package.json +6 -6
package/dist/commands/cli.js
CHANGED
|
@@ -314446,7 +314446,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl, ot
|
|
|
314446
314446
|
}
|
|
314447
314447
|
case Action.FetchAccountId: {
|
|
314448
314448
|
try {
|
|
314449
|
-
|
|
314449
|
+
const accountId = await broker.fetchAccountId();
|
|
314450
314450
|
return wrappedCallback(null, {
|
|
314451
314451
|
proof: verityProof,
|
|
314452
314452
|
result: JSON.stringify({ accountId })
|
|
@@ -314855,7 +314855,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl, ot
|
|
|
314855
314855
|
});
|
|
314856
314856
|
const subscriptionTypeName = (() => {
|
|
314857
314857
|
for (const [key, value] of Object.entries(SubscriptionType)) {
|
|
314858
|
-
if (value === subscriptionType && isNaN(Number(key))) {
|
|
314858
|
+
if (value === subscriptionType && Number.isNaN(Number(key))) {
|
|
314859
314859
|
return key;
|
|
314860
314860
|
}
|
|
314861
314861
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const CCXT_METHODS_WITH_VERITY: string[];
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { PolicyConfig, BrokerCredentials } from "../types";
|
|
2
|
+
import type { Metadata, ServerUnaryCall } from "@grpc/grpc-js";
|
|
3
|
+
import type { Exchange, HttpClientOverride, HttpOverridePredicate } from "@usherlabs/ccxt";
|
|
4
|
+
export declare function authenticateRequest<T, E>(call: ServerUnaryCall<T, E>, whitelistIps: string[]): boolean;
|
|
5
|
+
export declare function createVerityHttpClientOverride(verityProverUrl: string, onProofCallback: (proof: string, notaryPubKey?: string) => void): (redact: string, proofTimeout: number) => HttpClientOverride;
|
|
6
|
+
export declare function applyCommonExchangeConfig(exchange: Exchange): void;
|
|
7
|
+
export declare function buildHttpClientOverrideFromMetadata(metadata: Metadata, verityProverUrl: string, onProofCallback: (proof: string, notaryPubKey?: string) => void): HttpClientOverride;
|
|
8
|
+
export declare const verityHttpClientOverridePredicate: HttpOverridePredicate;
|
|
9
|
+
export declare function createBroker(cex: string, credsOrMetadata: {
|
|
10
|
+
apiKey: string;
|
|
11
|
+
apiSecret: string;
|
|
12
|
+
} | Metadata): Exchange | null;
|
|
13
|
+
type EnvConfigMap = Record<string, Partial<BrokerCredentials> & {
|
|
14
|
+
_secondaryMap?: Record<number, {
|
|
15
|
+
apiKey?: string;
|
|
16
|
+
apiSecret?: string;
|
|
17
|
+
}>;
|
|
18
|
+
}>;
|
|
19
|
+
type ValidatedCredentialsMap = Record<string, BrokerCredentials & {
|
|
20
|
+
secondaryKeys: BrokerCredentials[];
|
|
21
|
+
}>;
|
|
22
|
+
export declare function createBrokerPool(cfg: EnvConfigMap | ValidatedCredentialsMap): Record<string, {
|
|
23
|
+
primary: Exchange;
|
|
24
|
+
secondaryBrokers: Exchange[];
|
|
25
|
+
}>;
|
|
26
|
+
export declare function selectBroker(brokers: {
|
|
27
|
+
primary: Exchange;
|
|
28
|
+
secondaryBrokers: Exchange[];
|
|
29
|
+
} | undefined, metadata: Metadata): Exchange | null;
|
|
30
|
+
/**
|
|
31
|
+
* Loads and validates policy configuration
|
|
32
|
+
*/
|
|
33
|
+
export declare function loadPolicy(policyPath: string): PolicyConfig;
|
|
34
|
+
export declare function validateWithdraw(policy: PolicyConfig, exchange: string, network: string, recipientAddress: string, _amount: number, _ticker: string): {
|
|
35
|
+
valid: boolean;
|
|
36
|
+
error?: string;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Validates order request against policy rules
|
|
40
|
+
*/
|
|
41
|
+
export declare function validateOrder(policy: PolicyConfig, fromToken: string, toToken: string, amount: number, broker: string): {
|
|
42
|
+
valid: boolean;
|
|
43
|
+
error?: string;
|
|
44
|
+
};
|
|
45
|
+
type OrderExecutionResolution = {
|
|
46
|
+
valid: boolean;
|
|
47
|
+
error?: string;
|
|
48
|
+
symbol?: string;
|
|
49
|
+
side?: "buy" | "sell";
|
|
50
|
+
amountBase?: number;
|
|
51
|
+
limitsApplied?: boolean;
|
|
52
|
+
matchedPatterns?: string[];
|
|
53
|
+
};
|
|
54
|
+
export declare function resolveOrderExecution(policy: PolicyConfig, broker: Exchange, cex: string, fromToken: string, toToken: string, amount: number, price: number): Promise<OrderExecutionResolution>;
|
|
55
|
+
/**
|
|
56
|
+
* Validates deposit request (currently empty but can be extended)
|
|
57
|
+
*/
|
|
58
|
+
export declare function validateDeposit(_policy: PolicyConfig, _chain: string, _amount: number): {
|
|
59
|
+
valid: boolean;
|
|
60
|
+
error?: string;
|
|
61
|
+
};
|
|
62
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare const log: {
|
|
2
|
+
trace: (...args: unknown[]) => void;
|
|
3
|
+
debug: (...args: unknown[]) => void;
|
|
4
|
+
info: (...args: unknown[]) => void;
|
|
5
|
+
warn: (...args: unknown[]) => void;
|
|
6
|
+
error: (...args: unknown[]) => void;
|
|
7
|
+
fatal: (...args: unknown[]) => void;
|
|
8
|
+
};
|
|
9
|
+
export { log };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { type LogRecord } from "@opentelemetry/api-logs";
|
|
2
|
+
import { LoggerProvider } from "@opentelemetry/sdk-logs";
|
|
3
|
+
import { type MeterProvider as MeterProviderType } from "@opentelemetry/sdk-metrics";
|
|
4
|
+
/** OTLP/OpenTelemetry metrics config. Metrics are sent to an OTel Collector. */
|
|
5
|
+
export interface OtelConfig {
|
|
6
|
+
/** OTLP HTTP endpoint (e.g. http://localhost:4318). Takes precedence over host/port. */
|
|
7
|
+
otlpEndpoint?: string;
|
|
8
|
+
/** Collector host (legacy). Used with port to build otlpEndpoint when otlpEndpoint is not set. */
|
|
9
|
+
host?: string;
|
|
10
|
+
/** Collector port (legacy). Default 4318 for OTLP HTTP. */
|
|
11
|
+
port?: number;
|
|
12
|
+
protocol?: "http" | "https";
|
|
13
|
+
/** Service name for metrics. */
|
|
14
|
+
serviceName?: string;
|
|
15
|
+
/** @deprecated Unused when using OTLP; kept for config compatibility. */
|
|
16
|
+
username?: string;
|
|
17
|
+
/** @deprecated Unused when using OTLP; kept for config compatibility. */
|
|
18
|
+
password?: string;
|
|
19
|
+
/** @deprecated Unused when using OTLP; kept for config compatibility. */
|
|
20
|
+
database?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface MetricData {
|
|
23
|
+
timestamp: Date;
|
|
24
|
+
metric_name: string;
|
|
25
|
+
metric_type: "counter" | "gauge" | "histogram";
|
|
26
|
+
value: number;
|
|
27
|
+
labels: string;
|
|
28
|
+
service: string;
|
|
29
|
+
}
|
|
30
|
+
declare abstract class BaseOtelSignal<TProvider> {
|
|
31
|
+
private readonly signal;
|
|
32
|
+
private provider;
|
|
33
|
+
private isEnabled;
|
|
34
|
+
private readonly serviceName;
|
|
35
|
+
protected constructor(config: OtelConfig | undefined, signal: "metrics" | "logs");
|
|
36
|
+
protected abstract createProvider(endpoint: string, serviceName: string, appendSignalPath: boolean): TProvider;
|
|
37
|
+
protected onProviderCreated(_provider: TProvider): void;
|
|
38
|
+
protected abstract shutdownProvider(provider: TProvider): Promise<void>;
|
|
39
|
+
protected onProviderClosed(): void;
|
|
40
|
+
protected getProvider(): TProvider | null;
|
|
41
|
+
protected getServiceName(): string;
|
|
42
|
+
isOtelEnabled(): boolean;
|
|
43
|
+
close(): Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
export declare class OtelMetrics extends BaseOtelSignal<MeterProviderType> {
|
|
46
|
+
private readonly counters;
|
|
47
|
+
private readonly histograms;
|
|
48
|
+
constructor(config?: OtelConfig);
|
|
49
|
+
protected createProvider(endpoint: string, serviceName: string, appendSignalPath: boolean): MeterProviderType;
|
|
50
|
+
protected onProviderCreated(provider: MeterProviderType): void;
|
|
51
|
+
protected shutdownProvider(provider: MeterProviderType): Promise<void>;
|
|
52
|
+
initialize(): Promise<void>;
|
|
53
|
+
insertMetric(metric: MetricData): Promise<void>;
|
|
54
|
+
insertMetrics(metricsList: MetricData[]): Promise<void>;
|
|
55
|
+
recordCounter(metricName: string, value: number, labels: Record<string, string | number>, service?: string): Promise<void>;
|
|
56
|
+
recordGauge(metricName: string, value: number, labels: Record<string, string | number>, service?: string): Promise<void>;
|
|
57
|
+
recordHistogram(metricName: string, value: number, labels: Record<string, string | number>, service?: string): Promise<void>;
|
|
58
|
+
}
|
|
59
|
+
export declare class OtelLogs extends BaseOtelSignal<LoggerProvider> {
|
|
60
|
+
private logger;
|
|
61
|
+
constructor(config?: OtelConfig);
|
|
62
|
+
protected createProvider(endpoint: string, serviceName: string, appendSignalPath: boolean): LoggerProvider;
|
|
63
|
+
protected onProviderCreated(provider: LoggerProvider): void;
|
|
64
|
+
protected shutdownProvider(provider: LoggerProvider): Promise<void>;
|
|
65
|
+
protected onProviderClosed(): void;
|
|
66
|
+
emit(record: LogRecord): void;
|
|
67
|
+
}
|
|
68
|
+
export declare function createOtelMetricsFromEnv(): OtelMetrics;
|
|
69
|
+
export declare function createOtelLogsFromEnv(): OtelLogs;
|
|
70
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -277399,7 +277399,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl, ot
|
|
|
277399
277399
|
}
|
|
277400
277400
|
case Action.FetchAccountId: {
|
|
277401
277401
|
try {
|
|
277402
|
-
|
|
277402
|
+
const accountId = await broker.fetchAccountId();
|
|
277403
277403
|
return wrappedCallback(null, {
|
|
277404
277404
|
proof: verityProof,
|
|
277405
277405
|
result: JSON.stringify({ accountId })
|
|
@@ -277808,7 +277808,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl, ot
|
|
|
277808
277808
|
});
|
|
277809
277809
|
const subscriptionTypeName = (() => {
|
|
277810
277810
|
for (const [key, value] of Object.entries(SubscriptionType)) {
|
|
277811
|
-
if (value === subscriptionType && isNaN(Number(key))) {
|
|
277811
|
+
if (value === subscriptionType && Number.isNaN(Number(key))) {
|
|
277812
277812
|
return key;
|
|
277813
277813
|
}
|
|
277814
277814
|
}
|
|
@@ -278296,4 +278296,4 @@ export {
|
|
|
278296
278296
|
CEXBroker as default
|
|
278297
278297
|
};
|
|
278298
278298
|
|
|
278299
|
-
//# debugId=
|
|
278299
|
+
//# debugId=6C79197AF2F32F2E64756E2164756E21
|