@silvana-one/orderbook 1.1.11 → 1.1.14
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/node/index.cjs +352 -10
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.js +1 -0
- package/dist/node/index.js.map +1 -1
- package/dist/node/orderbook.d.ts +48 -1
- package/dist/node/orderbook.js +61 -1
- package/dist/node/orderbook.js.map +1 -1
- package/dist/node/proto/silvana/orderbook/v1/orderbook_pb.d.ts +414 -0
- package/dist/node/proto/silvana/orderbook/v1/orderbook_pb.js +63 -8
- package/dist/node/proto/silvana/orderbook/v1/orderbook_pb.js.map +1 -1
- package/dist/node/proto/silvana/settlement/v1/settlement_pb.d.ts +1466 -0
- package/dist/node/proto/silvana/settlement/v1/settlement_pb.js +351 -0
- package/dist/node/proto/silvana/settlement/v1/settlement_pb.js.map +1 -0
- package/dist/node/settlement.d.ts +59 -0
- package/dist/node/settlement.js +81 -0
- package/dist/node/settlement.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/tsconfig.web.tsbuildinfo +1 -1
- package/dist/web/index.d.ts +1 -0
- package/dist/web/index.js +1 -0
- package/dist/web/index.js.map +1 -1
- package/dist/web/orderbook.d.ts +48 -1
- package/dist/web/orderbook.js +61 -1
- package/dist/web/orderbook.js.map +1 -1
- package/dist/web/proto/silvana/orderbook/v1/orderbook_pb.d.ts +414 -0
- package/dist/web/proto/silvana/orderbook/v1/orderbook_pb.js +63 -8
- package/dist/web/proto/silvana/orderbook/v1/orderbook_pb.js.map +1 -1
- package/dist/web/proto/silvana/settlement/v1/settlement_pb.d.ts +1466 -0
- package/dist/web/proto/silvana/settlement/v1/settlement_pb.js +351 -0
- package/dist/web/proto/silvana/settlement/v1/settlement_pb.js.map +1 -0
- package/dist/web/settlement.d.ts +59 -0
- package/dist/web/settlement.js +81 -0
- package/dist/web/settlement.js.map +1 -0
- package/package.json +9 -8
- package/src/index.ts +1 -0
- package/src/orderbook.ts +102 -0
- package/src/proto/silvana/orderbook/v1/orderbook_pb.ts +499 -8
- package/src/proto/silvana/settlement/v1/settlement_pb.ts +1743 -0
- package/src/settlement.ts +133 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { createGrpcTransport } from "@connectrpc/connect-node";
|
|
2
|
+
import { createClient, ConnectError } from "@connectrpc/connect";
|
|
3
|
+
import { create } from "@bufbuild/protobuf";
|
|
4
|
+
|
|
5
|
+
// Export all types and schemas from the generated protobuf file
|
|
6
|
+
export * from "./proto/silvana/settlement/v1/settlement_pb.js";
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
SettlementService,
|
|
10
|
+
type GetPendingProposalsResponse,
|
|
11
|
+
type GetSettlementStatusResponse,
|
|
12
|
+
GetPendingProposalsRequestSchema,
|
|
13
|
+
GetSettlementStatusRequestSchema,
|
|
14
|
+
SubmitPreconfirmationRequestSchema,
|
|
15
|
+
CantonToServerMessageSchema,
|
|
16
|
+
type CantonNodeAuth,
|
|
17
|
+
type PreconfirmationDecision,
|
|
18
|
+
type CantonToServerMessage,
|
|
19
|
+
} from "./proto/silvana/settlement/v1/settlement_pb.js";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Custom error class for Settlement client errors
|
|
23
|
+
*/
|
|
24
|
+
export class SettlementError extends Error {
|
|
25
|
+
constructor(
|
|
26
|
+
message: string,
|
|
27
|
+
public code?: string,
|
|
28
|
+
public details?: any
|
|
29
|
+
) {
|
|
30
|
+
super(message);
|
|
31
|
+
this.name = 'SettlementError';
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Settlement client configuration
|
|
37
|
+
*/
|
|
38
|
+
export interface SettlementClientConfig {
|
|
39
|
+
/** Base URL of the settlement service (e.g., "http://localhost:50055") */
|
|
40
|
+
baseUrl: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Settlement client for interacting with the Silvana Settlement Service
|
|
45
|
+
*/
|
|
46
|
+
export class SettlementClient {
|
|
47
|
+
private client: ReturnType<typeof createClient<typeof SettlementService>>;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Creates a new SettlementClient instance
|
|
51
|
+
* @param config Client configuration
|
|
52
|
+
*/
|
|
53
|
+
constructor(config: SettlementClientConfig) {
|
|
54
|
+
const transport = createGrpcTransport({
|
|
55
|
+
baseUrl: config.baseUrl,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
this.client = createClient(SettlementService, transport);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Wraps async calls with error handling
|
|
63
|
+
*/
|
|
64
|
+
private async wrapCall<T>(
|
|
65
|
+
operation: () => Promise<T>,
|
|
66
|
+
operationName: string
|
|
67
|
+
): Promise<T> {
|
|
68
|
+
try {
|
|
69
|
+
return await operation();
|
|
70
|
+
} catch (error) {
|
|
71
|
+
if (error instanceof ConnectError) {
|
|
72
|
+
throw new SettlementError(
|
|
73
|
+
`${operationName} failed: ${error.message}`,
|
|
74
|
+
String(error.code),
|
|
75
|
+
error.metadata
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
throw new SettlementError(
|
|
79
|
+
`${operationName} failed: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
80
|
+
'UNKNOWN',
|
|
81
|
+
error
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Bidirectional streaming for settlement flow
|
|
88
|
+
* Canton node initiates connection and maintains stream
|
|
89
|
+
*/
|
|
90
|
+
settlementStream(messages: AsyncIterable<CantonToServerMessage>) {
|
|
91
|
+
return this.client.settlementStream(messages);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Get pending proposals for a party
|
|
96
|
+
*/
|
|
97
|
+
async getPendingProposals(params: {
|
|
98
|
+
auth: CantonNodeAuth;
|
|
99
|
+
partyId: string;
|
|
100
|
+
limit?: number;
|
|
101
|
+
}): Promise<GetPendingProposalsResponse> {
|
|
102
|
+
return await this.wrapCall(async () => {
|
|
103
|
+
const request = create(GetPendingProposalsRequestSchema, params);
|
|
104
|
+
return await this.client.getPendingProposals(request);
|
|
105
|
+
}, 'getPendingProposals');
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Query settlement status
|
|
110
|
+
*/
|
|
111
|
+
async getSettlementStatus(params: {
|
|
112
|
+
auth: CantonNodeAuth;
|
|
113
|
+
settlementId: string;
|
|
114
|
+
}): Promise<GetSettlementStatusResponse> {
|
|
115
|
+
return await this.wrapCall(async () => {
|
|
116
|
+
const request = create(GetSettlementStatusRequestSchema, params);
|
|
117
|
+
return await this.client.getSettlementStatus(request);
|
|
118
|
+
}, 'getSettlementStatus');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Manual preconfirmation (if not using stream)
|
|
123
|
+
*/
|
|
124
|
+
async submitPreconfirmation(params: {
|
|
125
|
+
auth: CantonNodeAuth;
|
|
126
|
+
decision: PreconfirmationDecision;
|
|
127
|
+
}): Promise<void> {
|
|
128
|
+
return await this.wrapCall(async () => {
|
|
129
|
+
const request = create(SubmitPreconfirmationRequestSchema, params);
|
|
130
|
+
await this.client.submitPreconfirmation(request);
|
|
131
|
+
}, 'submitPreconfirmation');
|
|
132
|
+
}
|
|
133
|
+
}
|