@0xmonaco/types 0.7.7 → 0.7.8
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/api/index.d.ts +18 -0
- package/dist/api/index.js +6 -0
- package/dist/applications/index.d.ts +23 -0
- package/dist/applications/index.js +5 -0
- package/dist/applications/responses.d.ts +22 -0
- package/dist/applications/responses.js +5 -0
- package/dist/auth/index.d.ts +81 -0
- package/dist/auth/index.js +6 -0
- package/dist/auth/responses.d.ts +67 -0
- package/dist/auth/responses.js +5 -0
- package/dist/contracts/balances.d.ts +43 -0
- package/dist/contracts/balances.js +5 -0
- package/dist/contracts/index.d.ts +27 -0
- package/dist/contracts/index.js +5 -0
- package/dist/fees/index.d.ts +39 -0
- package/dist/fees/index.js +6 -0
- package/dist/fees/responses.d.ts +54 -0
- package/dist/fees/responses.js +86 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +21 -0
- package/dist/margin-accounts/index.d.ts +110 -0
- package/dist/margin-accounts/index.js +0 -0
- package/dist/market/index.d.ts +312 -0
- package/dist/market/index.js +5 -0
- package/dist/positions/index.d.ts +128 -0
- package/dist/positions/index.js +0 -0
- package/dist/profile/index.d.ts +405 -0
- package/dist/profile/index.js +5 -0
- package/dist/sdk/index.d.ts +131 -0
- package/dist/sdk/index.js +0 -0
- package/dist/sdk/network.d.ts +25 -0
- package/dist/sdk/network.js +5 -0
- package/dist/trading/index.d.ts +132 -0
- package/dist/trading/index.js +6 -0
- package/dist/trading/orders.d.ts +137 -0
- package/dist/trading/orders.js +9 -0
- package/dist/trading/responses.d.ts +347 -0
- package/dist/trading/responses.js +5 -0
- package/dist/validation/common.d.ts +179 -0
- package/dist/validation/common.js +199 -0
- package/dist/validation/index.d.ts +22 -0
- package/dist/validation/index.js +24 -0
- package/dist/validation/margin-accounts.d.ts +55 -0
- package/dist/validation/margin-accounts.js +59 -0
- package/dist/validation/market.d.ts +214 -0
- package/dist/validation/market.js +225 -0
- package/dist/validation/positions.d.ts +89 -0
- package/dist/validation/positions.js +93 -0
- package/dist/validation/profile.d.ts +69 -0
- package/dist/validation/profile.js +44 -0
- package/dist/validation/trading.d.ts +350 -0
- package/dist/validation/trading.js +313 -0
- package/dist/validation/vault.d.ts +66 -0
- package/dist/validation/vault.js +79 -0
- package/dist/vault/index.d.ts +84 -0
- package/dist/vault/index.js +5 -0
- package/dist/vault/responses.d.ts +51 -0
- package/dist/vault/responses.js +5 -0
- package/dist/websocket/base.d.ts +31 -0
- package/dist/websocket/base.js +5 -0
- package/dist/websocket/clients/orderbook-client.d.ts +14 -0
- package/dist/websocket/clients/orderbook-client.js +3 -0
- package/dist/websocket/events/balance-events.d.ts +48 -0
- package/dist/websocket/events/balance-events.js +6 -0
- package/dist/websocket/events/conditional-order-events.d.ts +33 -0
- package/dist/websocket/events/conditional-order-events.js +0 -0
- package/dist/websocket/events/index.d.ts +7 -0
- package/dist/websocket/events/index.js +7 -0
- package/dist/websocket/events/movement-events.d.ts +64 -0
- package/dist/websocket/events/movement-events.js +6 -0
- package/dist/websocket/events/ohlcv-events.d.ts +31 -0
- package/dist/websocket/events/ohlcv-events.js +5 -0
- package/dist/websocket/events/orderbook-events.d.ts +72 -0
- package/dist/websocket/events/orderbook-events.js +5 -0
- package/dist/websocket/events/orders-events.d.ts +284 -0
- package/dist/websocket/events/orders-events.js +0 -0
- package/dist/websocket/events/trade-events.d.ts +34 -0
- package/dist/websocket/events/trade-events.js +5 -0
- package/dist/websocket/index.d.ts +8 -0
- package/dist/websocket/index.js +8 -0
- package/package.json +2 -2
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trading API Validation Schemas
|
|
3
|
+
*
|
|
4
|
+
* Zod schemas for validating trading API inputs before making requests.
|
|
5
|
+
* Provides clear, actionable error messages for invalid parameters.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
import { ORDER_STATUS_VALUES } from "../trading/orders";
|
|
9
|
+
/**
|
|
10
|
+
* Order side validation
|
|
11
|
+
*/
|
|
12
|
+
export const OrderSideSchema = z.enum(["BUY", "SELL"], {
|
|
13
|
+
message: 'Order side must be "BUY" or "SELL"',
|
|
14
|
+
});
|
|
15
|
+
/**
|
|
16
|
+
* Trading mode validation
|
|
17
|
+
*/
|
|
18
|
+
export const TradingModeSchema = z.enum(["SPOT", "MARGIN"], {
|
|
19
|
+
message: 'Trading mode must be "SPOT" or "MARGIN"',
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* Position side validation
|
|
23
|
+
*/
|
|
24
|
+
export const PositionSideSchema = z.enum(["LONG", "SHORT", "NONE"], {
|
|
25
|
+
message: 'Position side must be "LONG", "SHORT", or "NONE"',
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* Time in force validation
|
|
29
|
+
*/
|
|
30
|
+
export const TimeInForceSchema = z.enum(["GTC", "IOC", "FOK"], {
|
|
31
|
+
message: 'Time in force must be "GTC", "IOC", or "FOK"',
|
|
32
|
+
});
|
|
33
|
+
export const ConditionalTimeInForceSchema = z.enum(["GTC", "IOC"], {
|
|
34
|
+
message: 'Conditional order time in force must be "GTC" or "IOC"',
|
|
35
|
+
});
|
|
36
|
+
/**
|
|
37
|
+
* Positive decimal string validation (for quantities and prices)
|
|
38
|
+
*/
|
|
39
|
+
export const PositiveDecimalStringSchema = z
|
|
40
|
+
.string()
|
|
41
|
+
.trim()
|
|
42
|
+
.min(1, "Value cannot be empty")
|
|
43
|
+
.regex(/^\d+(\.\d+)?$/, "Value must be a positive decimal number (e.g., '1.5', '100')")
|
|
44
|
+
.refine((val) => Number.parseFloat(val) > 0, {
|
|
45
|
+
message: "Value must be greater than 0",
|
|
46
|
+
});
|
|
47
|
+
/**
|
|
48
|
+
* UUID validation
|
|
49
|
+
*/
|
|
50
|
+
export const UUIDSchema = z.uuid({
|
|
51
|
+
message: "Must be a valid UUID (e.g., '123e4567-e89b-12d3-a456-426614174000')",
|
|
52
|
+
});
|
|
53
|
+
/**
|
|
54
|
+
* ISO 8601 date string validation
|
|
55
|
+
*/
|
|
56
|
+
export const ISO8601DateSchema = z.iso.datetime({
|
|
57
|
+
message: "Must be a valid ISO 8601 date string (e.g., '2024-12-31T23:59:59Z')",
|
|
58
|
+
});
|
|
59
|
+
/**
|
|
60
|
+
* Slippage tolerance validation (0 to 1, where 0.01 = 1%)
|
|
61
|
+
*/
|
|
62
|
+
export const SlippageToleranceSchema = z
|
|
63
|
+
.number()
|
|
64
|
+
.min(0, "Slippage tolerance must be at least 0 (no slippage)")
|
|
65
|
+
.max(1, "Slippage tolerance cannot exceed 1 (100%)")
|
|
66
|
+
.optional();
|
|
67
|
+
/**
|
|
68
|
+
* Place Limit Order validation schema
|
|
69
|
+
*/
|
|
70
|
+
export const PlaceLimitOrderSchema = z
|
|
71
|
+
.object({
|
|
72
|
+
tradingPairId: UUIDSchema,
|
|
73
|
+
side: OrderSideSchema,
|
|
74
|
+
quantity: PositiveDecimalStringSchema,
|
|
75
|
+
price: PositiveDecimalStringSchema,
|
|
76
|
+
options: z
|
|
77
|
+
.object({
|
|
78
|
+
tradingMode: TradingModeSchema.optional(),
|
|
79
|
+
useMasterBalance: z.boolean().optional(),
|
|
80
|
+
expirationDate: ISO8601DateSchema.optional(),
|
|
81
|
+
timeInForce: TimeInForceSchema.optional(),
|
|
82
|
+
marginAccountId: UUIDSchema.optional(),
|
|
83
|
+
positionSide: PositionSideSchema.optional(),
|
|
84
|
+
leverage: PositiveDecimalStringSchema.optional(),
|
|
85
|
+
reduceOnly: z.boolean().optional(),
|
|
86
|
+
})
|
|
87
|
+
.optional(),
|
|
88
|
+
})
|
|
89
|
+
.refine((data) => data.options?.tradingMode !== "MARGIN" || data.options.marginAccountId !== undefined, {
|
|
90
|
+
message: "marginAccountId is required for MARGIN orders",
|
|
91
|
+
path: ["options", "marginAccountId"],
|
|
92
|
+
})
|
|
93
|
+
.refine((data) => data.options?.tradingMode !== "MARGIN" || data.options.positionSide !== undefined, {
|
|
94
|
+
message: "positionSide is required for MARGIN orders",
|
|
95
|
+
path: ["options", "positionSide"],
|
|
96
|
+
})
|
|
97
|
+
.refine((data) => data.options?.tradingMode !== "MARGIN" || data.options.leverage !== undefined, {
|
|
98
|
+
message: "leverage is required for MARGIN orders",
|
|
99
|
+
path: ["options", "leverage"],
|
|
100
|
+
});
|
|
101
|
+
/**
|
|
102
|
+
* Place Market Order validation schema
|
|
103
|
+
*/
|
|
104
|
+
export const PlaceMarketOrderSchema = z
|
|
105
|
+
.object({
|
|
106
|
+
tradingPairId: UUIDSchema,
|
|
107
|
+
side: OrderSideSchema,
|
|
108
|
+
quantity: PositiveDecimalStringSchema,
|
|
109
|
+
options: z
|
|
110
|
+
.object({
|
|
111
|
+
tradingMode: TradingModeSchema.optional(),
|
|
112
|
+
slippageTolerance: SlippageToleranceSchema,
|
|
113
|
+
marginAccountId: UUIDSchema.optional(),
|
|
114
|
+
positionSide: PositionSideSchema.optional(),
|
|
115
|
+
leverage: PositiveDecimalStringSchema.optional(),
|
|
116
|
+
reduceOnly: z.boolean().optional(),
|
|
117
|
+
})
|
|
118
|
+
.optional(),
|
|
119
|
+
})
|
|
120
|
+
.refine((data) => data.options?.tradingMode !== "MARGIN" || data.options.marginAccountId !== undefined, {
|
|
121
|
+
message: "marginAccountId is required for MARGIN orders",
|
|
122
|
+
path: ["options", "marginAccountId"],
|
|
123
|
+
})
|
|
124
|
+
.refine((data) => data.options?.tradingMode !== "MARGIN" || data.options.positionSide !== undefined, {
|
|
125
|
+
message: "positionSide is required for MARGIN orders",
|
|
126
|
+
path: ["options", "positionSide"],
|
|
127
|
+
})
|
|
128
|
+
.refine((data) => data.options?.tradingMode !== "MARGIN" || data.options.leverage !== undefined, {
|
|
129
|
+
message: "leverage is required for MARGIN orders",
|
|
130
|
+
path: ["options", "leverage"],
|
|
131
|
+
});
|
|
132
|
+
/**
|
|
133
|
+
* Cancel Order validation schema
|
|
134
|
+
*/
|
|
135
|
+
export const CancelOrderSchema = z.object({
|
|
136
|
+
orderId: UUIDSchema,
|
|
137
|
+
});
|
|
138
|
+
/**
|
|
139
|
+
* Replace Order validation schema
|
|
140
|
+
*
|
|
141
|
+
* Validates parameters for replacing an existing order.
|
|
142
|
+
* Matches the replaceOrder method signature which accepts:
|
|
143
|
+
* - orderId: string (UUID)
|
|
144
|
+
* - newOrder: { price?: string, quantity?: string, useMasterBalance?: boolean }
|
|
145
|
+
*/
|
|
146
|
+
export const ReplaceOrderSchema = z.object({
|
|
147
|
+
orderId: UUIDSchema,
|
|
148
|
+
newOrder: z.object({
|
|
149
|
+
price: PositiveDecimalStringSchema.optional(),
|
|
150
|
+
quantity: PositiveDecimalStringSchema.optional(),
|
|
151
|
+
useMasterBalance: z.boolean().optional(),
|
|
152
|
+
}),
|
|
153
|
+
});
|
|
154
|
+
/**
|
|
155
|
+
* Get Paginated Orders validation schema
|
|
156
|
+
*
|
|
157
|
+
* Validates parameters for fetching paginated orders.
|
|
158
|
+
* Matches the getPaginatedOrders method signature which accepts:
|
|
159
|
+
* - status: OrderStatus (optional filter)
|
|
160
|
+
* - trading_pair_id: trading pair UUID (optional filter)
|
|
161
|
+
* - page: number (default: 1)
|
|
162
|
+
* - page_size: number (default: 10, max: 100)
|
|
163
|
+
*/
|
|
164
|
+
export const GetPaginatedOrdersSchema = z.object({
|
|
165
|
+
status: z.enum(ORDER_STATUS_VALUES).optional(),
|
|
166
|
+
trading_pair_id: UUIDSchema.optional(),
|
|
167
|
+
trading_mode: TradingModeSchema.optional(),
|
|
168
|
+
margin_account_id: UUIDSchema.optional(),
|
|
169
|
+
page: z.number().int().min(1, "Page must be at least 1").optional(),
|
|
170
|
+
page_size: z.number().int().min(1, "Page size must be at least 1").max(100, "Page size cannot exceed 100").optional(),
|
|
171
|
+
});
|
|
172
|
+
/**
|
|
173
|
+
* Order type validation
|
|
174
|
+
*/
|
|
175
|
+
export const OrderTypeSchema = z.enum(["LIMIT", "MARKET"], {
|
|
176
|
+
message: 'Order type must be "LIMIT" or "MARKET"',
|
|
177
|
+
});
|
|
178
|
+
export const ConditionalOrderConditionTypeSchema = z.enum(["STOP_LOSS", "TAKE_PROFIT"], {
|
|
179
|
+
message: 'conditionType must be "STOP_LOSS" or "TAKE_PROFIT"',
|
|
180
|
+
});
|
|
181
|
+
export const ConditionalOrderTriggerSourceSchema = z.enum(["MARK_PRICE"], {
|
|
182
|
+
message: 'triggerSource must be "MARK_PRICE"',
|
|
183
|
+
});
|
|
184
|
+
export const ConditionalOrderStateSchema = z.enum(["ACTIVE", "TRIGGERING", "TRIGGERED", "CANCELLED", "EXPIRED", "FAILED"], {
|
|
185
|
+
message: "Invalid conditional order state",
|
|
186
|
+
});
|
|
187
|
+
export const ClosePositionSideSchema = z.enum(["LONG", "SHORT"], {
|
|
188
|
+
message: 'Position side must be "LONG" or "SHORT"',
|
|
189
|
+
});
|
|
190
|
+
export const SlippageToleranceBpsSchema = z
|
|
191
|
+
.number()
|
|
192
|
+
.int()
|
|
193
|
+
.min(0, "Slippage tolerance must be at least 0 bps")
|
|
194
|
+
.max(10000, "Slippage tolerance cannot exceed 10000 bps");
|
|
195
|
+
export const CreateConditionalOrderSchema = z
|
|
196
|
+
.object({
|
|
197
|
+
tradingPairId: UUIDSchema,
|
|
198
|
+
marginAccountId: UUIDSchema,
|
|
199
|
+
conditionType: ConditionalOrderConditionTypeSchema,
|
|
200
|
+
triggerPrice: PositiveDecimalStringSchema,
|
|
201
|
+
triggerSource: ConditionalOrderTriggerSourceSchema.optional(),
|
|
202
|
+
side: OrderSideSchema,
|
|
203
|
+
positionSide: ClosePositionSideSchema,
|
|
204
|
+
orderType: OrderTypeSchema,
|
|
205
|
+
limitPrice: PositiveDecimalStringSchema.optional(),
|
|
206
|
+
quantity: PositiveDecimalStringSchema.optional(),
|
|
207
|
+
reduceOnly: z.boolean().optional(),
|
|
208
|
+
timeInForce: ConditionalTimeInForceSchema.optional(),
|
|
209
|
+
slippageToleranceBps: SlippageToleranceBpsSchema.optional(),
|
|
210
|
+
expiresAt: ISO8601DateSchema.optional(),
|
|
211
|
+
})
|
|
212
|
+
.refine((data) => data.orderType !== "LIMIT" || data.limitPrice !== undefined, {
|
|
213
|
+
message: "limitPrice is required for LIMIT conditional orders",
|
|
214
|
+
path: ["limitPrice"],
|
|
215
|
+
})
|
|
216
|
+
.refine((data) => data.orderType !== "MARKET" || data.limitPrice === undefined, {
|
|
217
|
+
message: "limitPrice must not be provided for MARKET conditional orders",
|
|
218
|
+
path: ["limitPrice"],
|
|
219
|
+
})
|
|
220
|
+
.refine((data) => data.orderType !== "MARKET" || data.timeInForce === undefined, {
|
|
221
|
+
message: "timeInForce is only allowed for LIMIT conditional orders",
|
|
222
|
+
path: ["timeInForce"],
|
|
223
|
+
})
|
|
224
|
+
.refine((data) => data.orderType !== "LIMIT" || data.slippageToleranceBps === undefined, {
|
|
225
|
+
message: "slippageToleranceBps is only allowed for MARKET conditional orders",
|
|
226
|
+
path: ["slippageToleranceBps"],
|
|
227
|
+
});
|
|
228
|
+
export const CancelConditionalOrderSchema = z.object({
|
|
229
|
+
conditionalOrderId: UUIDSchema,
|
|
230
|
+
});
|
|
231
|
+
export const ListConditionalOrdersSchema = z.object({
|
|
232
|
+
margin_account_id: UUIDSchema.optional(),
|
|
233
|
+
trading_pair_id: UUIDSchema.optional(),
|
|
234
|
+
state: ConditionalOrderStateSchema.optional(),
|
|
235
|
+
page: z.number().int().min(1, "Page must be at least 1").optional(),
|
|
236
|
+
page_size: z.number().int().min(1, "Page size must be at least 1").max(100, "Page size cannot exceed 100").optional(),
|
|
237
|
+
});
|
|
238
|
+
/**
|
|
239
|
+
* Single batch create order item validation schema
|
|
240
|
+
*
|
|
241
|
+
* Validates each order in a batch create request.
|
|
242
|
+
* - LIMIT orders require a price
|
|
243
|
+
* - MARKET orders must not have a price
|
|
244
|
+
*/
|
|
245
|
+
export const BatchCreateOrderItemSchema = z
|
|
246
|
+
.object({
|
|
247
|
+
tradingPairId: UUIDSchema,
|
|
248
|
+
orderType: OrderTypeSchema,
|
|
249
|
+
side: OrderSideSchema,
|
|
250
|
+
price: PositiveDecimalStringSchema.optional(),
|
|
251
|
+
quantity: PositiveDecimalStringSchema,
|
|
252
|
+
tradingMode: TradingModeSchema.optional(),
|
|
253
|
+
slippageTolerance: SlippageToleranceSchema,
|
|
254
|
+
useMasterBalance: z.boolean().optional(),
|
|
255
|
+
expirationDate: ISO8601DateSchema.optional(),
|
|
256
|
+
timeInForce: TimeInForceSchema.optional(),
|
|
257
|
+
marginAccountId: UUIDSchema.optional(),
|
|
258
|
+
positionSide: PositionSideSchema.optional(),
|
|
259
|
+
leverage: PositiveDecimalStringSchema.optional(),
|
|
260
|
+
reduceOnly: z.boolean().optional(),
|
|
261
|
+
})
|
|
262
|
+
.refine((data) => data.orderType !== "LIMIT" || data.price !== undefined, {
|
|
263
|
+
message: "Price is required for LIMIT orders",
|
|
264
|
+
path: ["price"],
|
|
265
|
+
})
|
|
266
|
+
.refine((data) => data.orderType !== "MARKET" || data.price === undefined, {
|
|
267
|
+
message: "Price must not be provided for MARKET orders",
|
|
268
|
+
path: ["price"],
|
|
269
|
+
})
|
|
270
|
+
.refine((data) => data.tradingMode !== "MARGIN" || data.marginAccountId !== undefined, {
|
|
271
|
+
message: "marginAccountId is required for MARGIN orders",
|
|
272
|
+
path: ["marginAccountId"],
|
|
273
|
+
})
|
|
274
|
+
.refine((data) => data.tradingMode !== "MARGIN" || data.positionSide !== undefined, {
|
|
275
|
+
message: "positionSide is required for MARGIN orders",
|
|
276
|
+
path: ["positionSide"],
|
|
277
|
+
})
|
|
278
|
+
.refine((data) => data.tradingMode !== "MARGIN" || data.leverage !== undefined, {
|
|
279
|
+
message: "leverage is required for MARGIN orders",
|
|
280
|
+
path: ["leverage"],
|
|
281
|
+
});
|
|
282
|
+
/**
|
|
283
|
+
* Batch Create Orders validation schema
|
|
284
|
+
*
|
|
285
|
+
* Validates the full array of orders for a batch create request.
|
|
286
|
+
*/
|
|
287
|
+
export const BatchCreateOrdersSchema = z.object({
|
|
288
|
+
orders: z.array(BatchCreateOrderItemSchema).min(1, "At least one order is required"),
|
|
289
|
+
});
|
|
290
|
+
/**
|
|
291
|
+
* Single batch replace order item validation schema
|
|
292
|
+
*
|
|
293
|
+
* Validates each order in a batch replace request.
|
|
294
|
+
* At least one of price or quantity must be provided.
|
|
295
|
+
*/
|
|
296
|
+
export const BatchReplaceOrderItemSchema = z
|
|
297
|
+
.object({
|
|
298
|
+
orderId: UUIDSchema,
|
|
299
|
+
price: PositiveDecimalStringSchema.optional(),
|
|
300
|
+
quantity: PositiveDecimalStringSchema.optional(),
|
|
301
|
+
useMasterBalance: z.boolean().optional(),
|
|
302
|
+
})
|
|
303
|
+
.refine((data) => data.price !== undefined || data.quantity !== undefined, {
|
|
304
|
+
message: "At least one of price or quantity must be provided",
|
|
305
|
+
});
|
|
306
|
+
/**
|
|
307
|
+
* Batch Replace Orders validation schema
|
|
308
|
+
*
|
|
309
|
+
* Validates the full array of orders for a batch replace request.
|
|
310
|
+
*/
|
|
311
|
+
export const BatchReplaceOrdersSchema = z.object({
|
|
312
|
+
orders: z.array(BatchReplaceOrderItemSchema).min(1, "At least one order is required"),
|
|
313
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vault API Validation Schemas
|
|
3
|
+
*/
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
/**
|
|
6
|
+
* Ethereum address validation
|
|
7
|
+
*/
|
|
8
|
+
export declare const AddressSchema: z.ZodString;
|
|
9
|
+
/**
|
|
10
|
+
* Positive BigInt validation
|
|
11
|
+
*
|
|
12
|
+
* Accepts either:
|
|
13
|
+
* - A positive integer string (e.g., "1000000000000000000" for 1 token with 18 decimals)
|
|
14
|
+
* - A positive bigint value (e.g., 1000000000000000000n)
|
|
15
|
+
*
|
|
16
|
+
* This flexibility allows validation of:
|
|
17
|
+
* - User input (strings from forms)
|
|
18
|
+
* - Parsed amounts (bigint from parseUnits())
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* // String input (from user)
|
|
23
|
+
* validate(PositiveBigIntStringSchema, "1000000");
|
|
24
|
+
*
|
|
25
|
+
* // BigInt input (from parseUnits)
|
|
26
|
+
* import { parseUnits } from 'viem';
|
|
27
|
+
* const amount = parseUnits("1.0", 18); // 1000000000000000000n
|
|
28
|
+
* validate(PositiveBigIntStringSchema, amount);
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare const PositiveBigIntStringSchema: z.ZodUnion<readonly [z.ZodString, z.ZodBigInt]>;
|
|
32
|
+
/**
|
|
33
|
+
* Approve Token validation schema
|
|
34
|
+
*/
|
|
35
|
+
export declare const ApproveTokenSchema: z.ZodObject<{
|
|
36
|
+
assetId: z.ZodUUID;
|
|
37
|
+
amount: z.ZodUnion<readonly [z.ZodString, z.ZodBigInt]>;
|
|
38
|
+
autoWait: z.ZodOptional<z.ZodBoolean>;
|
|
39
|
+
}, z.core.$strip>;
|
|
40
|
+
/**
|
|
41
|
+
* Deposit validation schema
|
|
42
|
+
*/
|
|
43
|
+
export declare const DepositSchema: z.ZodObject<{
|
|
44
|
+
assetId: z.ZodUUID;
|
|
45
|
+
amount: z.ZodUnion<readonly [z.ZodString, z.ZodBigInt]>;
|
|
46
|
+
autoWait: z.ZodOptional<z.ZodBoolean>;
|
|
47
|
+
}, z.core.$strip>;
|
|
48
|
+
/**
|
|
49
|
+
* Withdraw validation schema.
|
|
50
|
+
*
|
|
51
|
+
* The SDK calls the gateway to allocate the `withdrawalIndex` and obtain
|
|
52
|
+
* pre-signed calldata, then submits that calldata via the connected wallet.
|
|
53
|
+
* `autoWait` controls whether the SDK awaits on-chain confirmation.
|
|
54
|
+
*/
|
|
55
|
+
export declare const WithdrawSchema: z.ZodObject<{
|
|
56
|
+
assetId: z.ZodUUID;
|
|
57
|
+
amount: z.ZodUnion<readonly [z.ZodString, z.ZodBigInt]>;
|
|
58
|
+
destination: z.ZodString;
|
|
59
|
+
autoWait: z.ZodOptional<z.ZodBoolean>;
|
|
60
|
+
}, z.core.$strip>;
|
|
61
|
+
/**
|
|
62
|
+
* Get Balance validation schema
|
|
63
|
+
*/
|
|
64
|
+
export declare const GetBalanceSchema: z.ZodObject<{
|
|
65
|
+
assetId: z.ZodUUID;
|
|
66
|
+
}, z.core.$strip>;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vault API Validation Schemas
|
|
3
|
+
*/
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { UUIDSchema } from "./trading";
|
|
6
|
+
/**
|
|
7
|
+
* Ethereum address validation
|
|
8
|
+
*/
|
|
9
|
+
export const AddressSchema = z.string().regex(/^0x[a-fA-F0-9]{40}$/, {
|
|
10
|
+
message: "Must be a valid Ethereum address (e.g., '0x1234...5678')",
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* Positive BigInt validation
|
|
14
|
+
*
|
|
15
|
+
* Accepts either:
|
|
16
|
+
* - A positive integer string (e.g., "1000000000000000000" for 1 token with 18 decimals)
|
|
17
|
+
* - A positive bigint value (e.g., 1000000000000000000n)
|
|
18
|
+
*
|
|
19
|
+
* This flexibility allows validation of:
|
|
20
|
+
* - User input (strings from forms)
|
|
21
|
+
* - Parsed amounts (bigint from parseUnits())
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* // String input (from user)
|
|
26
|
+
* validate(PositiveBigIntStringSchema, "1000000");
|
|
27
|
+
*
|
|
28
|
+
* // BigInt input (from parseUnits)
|
|
29
|
+
* import { parseUnits } from 'viem';
|
|
30
|
+
* const amount = parseUnits("1.0", 18); // 1000000000000000000n
|
|
31
|
+
* validate(PositiveBigIntStringSchema, amount);
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export const PositiveBigIntStringSchema = z.union([
|
|
35
|
+
z
|
|
36
|
+
.string()
|
|
37
|
+
.regex(/^\d+$/, "Must be a positive integer string")
|
|
38
|
+
.refine((val) => BigInt(val) > 0n, {
|
|
39
|
+
message: "Amount must be greater than 0",
|
|
40
|
+
}),
|
|
41
|
+
z.bigint().refine((val) => val > 0n, {
|
|
42
|
+
message: "Amount must be greater than 0",
|
|
43
|
+
}),
|
|
44
|
+
]);
|
|
45
|
+
/**
|
|
46
|
+
* Approve Token validation schema
|
|
47
|
+
*/
|
|
48
|
+
export const ApproveTokenSchema = z.object({
|
|
49
|
+
assetId: UUIDSchema,
|
|
50
|
+
amount: PositiveBigIntStringSchema,
|
|
51
|
+
autoWait: z.boolean().optional(),
|
|
52
|
+
});
|
|
53
|
+
/**
|
|
54
|
+
* Deposit validation schema
|
|
55
|
+
*/
|
|
56
|
+
export const DepositSchema = z.object({
|
|
57
|
+
assetId: UUIDSchema,
|
|
58
|
+
amount: PositiveBigIntStringSchema,
|
|
59
|
+
autoWait: z.boolean().optional(),
|
|
60
|
+
});
|
|
61
|
+
/**
|
|
62
|
+
* Withdraw validation schema.
|
|
63
|
+
*
|
|
64
|
+
* The SDK calls the gateway to allocate the `withdrawalIndex` and obtain
|
|
65
|
+
* pre-signed calldata, then submits that calldata via the connected wallet.
|
|
66
|
+
* `autoWait` controls whether the SDK awaits on-chain confirmation.
|
|
67
|
+
*/
|
|
68
|
+
export const WithdrawSchema = z.object({
|
|
69
|
+
assetId: UUIDSchema,
|
|
70
|
+
amount: PositiveBigIntStringSchema,
|
|
71
|
+
destination: z.string().regex(/^0x[a-fA-F0-9]{40}$/, "destination must be a 0x-prefixed 20-byte hex address"),
|
|
72
|
+
autoWait: z.boolean().optional(),
|
|
73
|
+
});
|
|
74
|
+
/**
|
|
75
|
+
* Get Balance validation schema
|
|
76
|
+
*/
|
|
77
|
+
export const GetBalanceSchema = z.object({
|
|
78
|
+
assetId: UUIDSchema,
|
|
79
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vault Types
|
|
3
|
+
*
|
|
4
|
+
* Types for vault operations including deposits, withdrawals, and balance management.
|
|
5
|
+
*/
|
|
6
|
+
import type { BaseAPI } from "../api/index";
|
|
7
|
+
import type { Balance, TransactionResult, WithdrawResult } from "./responses";
|
|
8
|
+
/**
|
|
9
|
+
* Vault API interface.
|
|
10
|
+
* Provides methods for managing token deposits and withdrawals.
|
|
11
|
+
* Handles token approvals and balance management.
|
|
12
|
+
*/
|
|
13
|
+
export interface VaultAPI extends BaseAPI {
|
|
14
|
+
/**
|
|
15
|
+
* Approves the vault to spend tokens.
|
|
16
|
+
* @param assetId - Asset identifier (UUID) to approve
|
|
17
|
+
* @param amount - Amount to approve
|
|
18
|
+
* @param autoWait - Whether to automatically wait for transaction confirmation (defaults to true)
|
|
19
|
+
* @returns Promise resolving to the transaction result
|
|
20
|
+
*/
|
|
21
|
+
approve(assetId: string, amount: bigint, autoWait?: boolean): Promise<TransactionResult>;
|
|
22
|
+
/**
|
|
23
|
+
* Deposits tokens into the vault.
|
|
24
|
+
* @param assetId - Asset identifier (UUID) to deposit
|
|
25
|
+
* @param amount - Amount to deposit
|
|
26
|
+
* @param autoWait - Whether to automatically wait for transaction confirmation (defaults to true)
|
|
27
|
+
* @returns Promise resolving to the transaction result
|
|
28
|
+
*/
|
|
29
|
+
deposit(assetId: string, amount: bigint, autoWait?: boolean): Promise<TransactionResult>;
|
|
30
|
+
/**
|
|
31
|
+
* Initiates a withdrawal: allocates a `withdrawalIndex` via the API Gateway,
|
|
32
|
+
* receives pre-signed calldata for `executeSignedWithdrawal(...)`, and
|
|
33
|
+
* submits it on-chain through the connected wallet.
|
|
34
|
+
*
|
|
35
|
+
* @param assetId - Asset identifier (UUID) to withdraw
|
|
36
|
+
* @param amount - Raw token amount (smallest unit, as bigint)
|
|
37
|
+
* @param autoWait - Whether to await on-chain confirmation (defaults to true)
|
|
38
|
+
* @returns Promise resolving to `{ withdrawalIndex, transaction }`
|
|
39
|
+
*/
|
|
40
|
+
withdraw(assetId: string, amount: bigint, autoWait?: boolean): Promise<WithdrawResult>;
|
|
41
|
+
/**
|
|
42
|
+
* Retries a previously-initiated withdrawal whose on-chain submission never
|
|
43
|
+
* landed (wallet rejected, page reloaded before receipt, stuck mempool).
|
|
44
|
+
* Re-fetches the same signed calldata and resubmits via the connected wallet
|
|
45
|
+
* — does NOT initiate a new withdrawal.
|
|
46
|
+
*
|
|
47
|
+
* @param withdrawalIndex - Index returned by the original `withdraw()` call
|
|
48
|
+
* @param autoWait - Whether to await on-chain confirmation (defaults to true)
|
|
49
|
+
* @returns Promise resolving to `{ withdrawalIndex, ...transaction }`
|
|
50
|
+
*/
|
|
51
|
+
retryWithdrawal(withdrawalIndex: number, autoWait?: boolean): Promise<WithdrawResult>;
|
|
52
|
+
/**
|
|
53
|
+
* Gets the balance of a token in the vault.
|
|
54
|
+
* @param assetId - Asset identifier (UUID) to check
|
|
55
|
+
* @returns Promise resolving to the balance
|
|
56
|
+
* @deprecated This method is no longer supported and will throw an APIError (410 Gone). Use `profileAPI.getUserBalances()` or `profileAPI.getUserBalanceByAssetId()` instead.
|
|
57
|
+
*/
|
|
58
|
+
getBalance(assetId: string): Promise<Balance>;
|
|
59
|
+
/**
|
|
60
|
+
* Gets the allowance for a token.
|
|
61
|
+
* @param assetId - Asset identifier (UUID) to check
|
|
62
|
+
* @returns Promise resolving to the allowance
|
|
63
|
+
*/
|
|
64
|
+
getAllowance(assetId: string): Promise<bigint>;
|
|
65
|
+
/**
|
|
66
|
+
* Checks if a token needs approval for an amount.
|
|
67
|
+
* @param assetId - Asset identifier (UUID) to check
|
|
68
|
+
* @param amount - Amount to check
|
|
69
|
+
* @returns Promise resolving to whether approval is needed
|
|
70
|
+
*/
|
|
71
|
+
needsApproval(assetId: string, amount: bigint): Promise<boolean>;
|
|
72
|
+
/**
|
|
73
|
+
* Gets the address of the vault.
|
|
74
|
+
* @returns Promise resolving to the address of the vault
|
|
75
|
+
*/
|
|
76
|
+
getVaultAddress(): Promise<string>;
|
|
77
|
+
/**
|
|
78
|
+
* Sets the wallet client for signing transactions.
|
|
79
|
+
* Used when the wallet becomes available after SDK initialization.
|
|
80
|
+
* @param walletClient - The wallet client to set
|
|
81
|
+
*/
|
|
82
|
+
setWalletClient(walletClient: unknown): void;
|
|
83
|
+
}
|
|
84
|
+
export type { Balance, TransactionResult, WithdrawResult } from "./responses";
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vault Response Types
|
|
3
|
+
*
|
|
4
|
+
* Response types for vault operations.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Response from a transaction.
|
|
8
|
+
*/
|
|
9
|
+
export interface TransactionResult {
|
|
10
|
+
/** Transaction hash */
|
|
11
|
+
hash: string;
|
|
12
|
+
/** Transaction status */
|
|
13
|
+
status: "pending" | "confirmed" | "failed";
|
|
14
|
+
/** Nonce used for this operation */
|
|
15
|
+
nonce: bigint;
|
|
16
|
+
/** Transaction receipt (only available when autoWait is enabled) */
|
|
17
|
+
receipt?: import("viem").TransactionReceipt;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Result of initiating a withdrawal.
|
|
21
|
+
*
|
|
22
|
+
* The API gateway allocates a `withdrawalIndex` via the matching engine and
|
|
23
|
+
* returns pre-signed calldata for the vault contract's
|
|
24
|
+
* `executeSignedWithdrawal(...)` function. The SDK submits that calldata on
|
|
25
|
+
* behalf of the connected wallet — the user is the on-chain caller, but the
|
|
26
|
+
* `WITHDRAWAL_SIGNER` signature embedded in the calldata is what the contract
|
|
27
|
+
* authenticates against.
|
|
28
|
+
*
|
|
29
|
+
* Extends [`TransactionResult`] so callers can read `hash`, `status`, `nonce`
|
|
30
|
+
* (and `receipt` when `autoWait` is true) directly off the result, just like
|
|
31
|
+
* `approve` / `deposit`.
|
|
32
|
+
*/
|
|
33
|
+
export interface WithdrawResult extends TransactionResult {
|
|
34
|
+
/** Allocated withdrawal index — matches `executeSignedWithdrawal.index`. */
|
|
35
|
+
withdrawalIndex: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Token balance information.
|
|
39
|
+
*/
|
|
40
|
+
export interface Balance {
|
|
41
|
+
/** Token address */
|
|
42
|
+
token: string;
|
|
43
|
+
/** Balance amount */
|
|
44
|
+
amount: bigint;
|
|
45
|
+
/** Formatted balance string */
|
|
46
|
+
formatted: string;
|
|
47
|
+
/** Token symbol */
|
|
48
|
+
symbol: string;
|
|
49
|
+
/** Token decimals */
|
|
50
|
+
decimals: number;
|
|
51
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebSocket Types
|
|
3
|
+
*
|
|
4
|
+
* Types for the functional Monaco WebSocket client.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* WebSocket connection status
|
|
8
|
+
*/
|
|
9
|
+
export type WebSocketStatus = "connected" | "connecting" | "disconnected" | "reconnecting";
|
|
10
|
+
/**
|
|
11
|
+
* Raw event message interface
|
|
12
|
+
* This is the raw message received from the backend
|
|
13
|
+
*/
|
|
14
|
+
export interface RawEventMessage {
|
|
15
|
+
/** Channel name */
|
|
16
|
+
channel: string;
|
|
17
|
+
/** Event data */
|
|
18
|
+
data: unknown;
|
|
19
|
+
/** Event type */
|
|
20
|
+
type: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Base error event that can be used across different components
|
|
24
|
+
*/
|
|
25
|
+
export interface BaseErrorEvent {
|
|
26
|
+
type: string;
|
|
27
|
+
message: string;
|
|
28
|
+
timestamp: number;
|
|
29
|
+
code?: string | number;
|
|
30
|
+
details?: unknown;
|
|
31
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Orderbook Types
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Quotation mode for orderbook subscription.
|
|
6
|
+
*
|
|
7
|
+
* - "BASE": Prices are displayed in the quote currency per unit of the base currency.
|
|
8
|
+
* For example, for the BTC/USD market, prices are shown as USD per BTC.
|
|
9
|
+
* - "QUOTE": Prices are displayed in the base currency per unit of the quote currency.
|
|
10
|
+
* For example, for the BTC/USD market, prices are shown as BTC per USD.
|
|
11
|
+
*
|
|
12
|
+
* Choose the mode based on how you want to interpret price levels in the orderbook.
|
|
13
|
+
*/
|
|
14
|
+
export type OrderbookQuotationMode = "BASE" | "QUOTE";
|