@0xmonaco/core 0.0.0-develop-20260120180031

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.
Files changed (130) hide show
  1. package/README.md +693 -0
  2. package/dist/api/applications/api.d.ts +44 -0
  3. package/dist/api/applications/api.d.ts.map +1 -0
  4. package/dist/api/applications/api.js +54 -0
  5. package/dist/api/applications/api.js.map +1 -0
  6. package/dist/api/applications/index.d.ts +5 -0
  7. package/dist/api/applications/index.d.ts.map +1 -0
  8. package/dist/api/applications/index.js +5 -0
  9. package/dist/api/applications/index.js.map +1 -0
  10. package/dist/api/auth/api.d.ts +201 -0
  11. package/dist/api/auth/api.d.ts.map +1 -0
  12. package/dist/api/auth/api.js +293 -0
  13. package/dist/api/auth/api.js.map +1 -0
  14. package/dist/api/auth/index.d.ts +5 -0
  15. package/dist/api/auth/index.d.ts.map +1 -0
  16. package/dist/api/auth/index.js +5 -0
  17. package/dist/api/auth/index.js.map +1 -0
  18. package/dist/api/base.d.ts +124 -0
  19. package/dist/api/base.d.ts.map +1 -0
  20. package/dist/api/base.js +284 -0
  21. package/dist/api/base.js.map +1 -0
  22. package/dist/api/fees/api.d.ts +71 -0
  23. package/dist/api/fees/api.d.ts.map +1 -0
  24. package/dist/api/fees/api.js +83 -0
  25. package/dist/api/fees/api.js.map +1 -0
  26. package/dist/api/fees/index.d.ts +7 -0
  27. package/dist/api/fees/index.d.ts.map +1 -0
  28. package/dist/api/fees/index.js +7 -0
  29. package/dist/api/fees/index.js.map +1 -0
  30. package/dist/api/index.d.ts +16 -0
  31. package/dist/api/index.d.ts.map +1 -0
  32. package/dist/api/index.js +16 -0
  33. package/dist/api/index.js.map +1 -0
  34. package/dist/api/market/api.d.ts +14 -0
  35. package/dist/api/market/api.d.ts.map +1 -0
  36. package/dist/api/market/api.js +70 -0
  37. package/dist/api/market/api.js.map +1 -0
  38. package/dist/api/market/index.d.ts +2 -0
  39. package/dist/api/market/index.d.ts.map +1 -0
  40. package/dist/api/market/index.js +2 -0
  41. package/dist/api/market/index.js.map +1 -0
  42. package/dist/api/orderbook/api.d.ts +16 -0
  43. package/dist/api/orderbook/api.d.ts.map +1 -0
  44. package/dist/api/orderbook/api.js +38 -0
  45. package/dist/api/orderbook/api.js.map +1 -0
  46. package/dist/api/orderbook/index.d.ts +2 -0
  47. package/dist/api/orderbook/index.d.ts.map +1 -0
  48. package/dist/api/orderbook/index.js +2 -0
  49. package/dist/api/orderbook/index.js.map +1 -0
  50. package/dist/api/profile/api.d.ts +119 -0
  51. package/dist/api/profile/api.d.ts.map +1 -0
  52. package/dist/api/profile/api.js +162 -0
  53. package/dist/api/profile/api.js.map +1 -0
  54. package/dist/api/profile/index.d.ts +7 -0
  55. package/dist/api/profile/index.d.ts.map +1 -0
  56. package/dist/api/profile/index.js +7 -0
  57. package/dist/api/profile/index.js.map +1 -0
  58. package/dist/api/trades/api.d.ts +45 -0
  59. package/dist/api/trades/api.d.ts.map +1 -0
  60. package/dist/api/trades/api.js +43 -0
  61. package/dist/api/trades/api.js.map +1 -0
  62. package/dist/api/trades/index.d.ts +2 -0
  63. package/dist/api/trades/index.d.ts.map +1 -0
  64. package/dist/api/trades/index.js +2 -0
  65. package/dist/api/trades/index.js.map +1 -0
  66. package/dist/api/trading/api.d.ts +213 -0
  67. package/dist/api/trading/api.d.ts.map +1 -0
  68. package/dist/api/trading/api.js +285 -0
  69. package/dist/api/trading/api.js.map +1 -0
  70. package/dist/api/trading/index.d.ts +5 -0
  71. package/dist/api/trading/index.d.ts.map +1 -0
  72. package/dist/api/trading/index.js +5 -0
  73. package/dist/api/trading/index.js.map +1 -0
  74. package/dist/api/vault/api.d.ts +257 -0
  75. package/dist/api/vault/api.d.ts.map +1 -0
  76. package/dist/api/vault/api.js +526 -0
  77. package/dist/api/vault/api.js.map +1 -0
  78. package/dist/api/vault/index.d.ts +5 -0
  79. package/dist/api/vault/index.d.ts.map +1 -0
  80. package/dist/api/vault/index.js +5 -0
  81. package/dist/api/vault/index.js.map +1 -0
  82. package/dist/api/websocket/index.d.ts +4 -0
  83. package/dist/api/websocket/index.d.ts.map +1 -0
  84. package/dist/api/websocket/index.js +4 -0
  85. package/dist/api/websocket/index.js.map +1 -0
  86. package/dist/api/websocket/types.d.ts +36 -0
  87. package/dist/api/websocket/types.d.ts.map +1 -0
  88. package/dist/api/websocket/types.js +2 -0
  89. package/dist/api/websocket/types.js.map +1 -0
  90. package/dist/api/websocket/utils.d.ts +9 -0
  91. package/dist/api/websocket/utils.d.ts.map +1 -0
  92. package/dist/api/websocket/utils.js +23 -0
  93. package/dist/api/websocket/utils.js.map +1 -0
  94. package/dist/api/websocket/websocket.d.ts +6 -0
  95. package/dist/api/websocket/websocket.d.ts.map +1 -0
  96. package/dist/api/websocket/websocket.js +345 -0
  97. package/dist/api/websocket/websocket.js.map +1 -0
  98. package/dist/errors/errors.d.ts +382 -0
  99. package/dist/errors/errors.d.ts.map +1 -0
  100. package/dist/errors/errors.js +801 -0
  101. package/dist/errors/errors.js.map +1 -0
  102. package/dist/errors/index.d.ts +2 -0
  103. package/dist/errors/index.d.ts.map +1 -0
  104. package/dist/errors/index.js +2 -0
  105. package/dist/errors/index.js.map +1 -0
  106. package/dist/index.d.ts +6 -0
  107. package/dist/index.d.ts.map +1 -0
  108. package/dist/index.js +6 -0
  109. package/dist/index.js.map +1 -0
  110. package/dist/networks/index.d.ts +2 -0
  111. package/dist/networks/index.d.ts.map +1 -0
  112. package/dist/networks/index.js +2 -0
  113. package/dist/networks/index.js.map +1 -0
  114. package/dist/networks/networks.d.ts +15 -0
  115. package/dist/networks/networks.d.ts.map +1 -0
  116. package/dist/networks/networks.js +34 -0
  117. package/dist/networks/networks.js.map +1 -0
  118. package/dist/sdk.d.ts +128 -0
  119. package/dist/sdk.d.ts.map +1 -0
  120. package/dist/sdk.js +272 -0
  121. package/dist/sdk.js.map +1 -0
  122. package/dist/utils/index.d.ts +2 -0
  123. package/dist/utils/index.d.ts.map +1 -0
  124. package/dist/utils/index.js +2 -0
  125. package/dist/utils/index.js.map +1 -0
  126. package/dist/utils/magnitude.d.ts +27 -0
  127. package/dist/utils/magnitude.d.ts.map +1 -0
  128. package/dist/utils/magnitude.js +32 -0
  129. package/dist/utils/magnitude.js.map +1 -0
  130. package/package.json +49 -0
@@ -0,0 +1,526 @@
1
+ /**
2
+ * Vault API Implementation
3
+ *
4
+ * Handles vault operations including deposits, withdrawals, and ERC20 approvals.
5
+ * Implements the signature flow for deposit/withdraw operations via API Gateway.
6
+ *
7
+ * This class provides a complete interface for interacting with the Monaco vault contract,
8
+ * including token approvals, deposits, withdrawals, and balance queries. All operations
9
+ * use EIP-712 signatures for security and go through the API Gateway for validation.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const vaultAPI = new VaultAPIImpl(
14
+ * publicClient,
15
+ * walletClient,
16
+ * vaultAddress,
17
+ * apiUrl,
18
+ * chain
19
+ * );
20
+ *
21
+ * // Check balance
22
+ * const balance = await vaultAPI.getBalance(tokenAddress);
23
+ * console.log(`Balance: ${balance.formatted} ${balance.symbol}`);
24
+ *
25
+ * // Deposit tokens
26
+ * const result = await vaultAPI.deposit(tokenAddress, parseEther("100"));
27
+ * console.log(`Deposit transaction: ${result.hash}`);
28
+ * ```
29
+ */
30
+ import { CONTRACT_ABIS } from "@0xmonaco/contracts";
31
+ import { ApproveTokenSchema, DepositSchema, GetBalanceSchema, validate, WithdrawSchema } from "@0xmonaco/types";
32
+ import { erc20Abi, formatUnits, getContract } from "viem";
33
+ import { ContractError, InvalidConfigError } from "../../errors";
34
+ import { BaseAPI } from "../base";
35
+ export class VaultAPIImpl extends BaseAPI {
36
+ /**
37
+ * Creates a new VaultAPI instance.
38
+ *
39
+ * @param publicClient - The viem public client for reading blockchain state
40
+ * @param walletClient - The viem wallet client for signing transactions
41
+ * @param chain - The blockchain network configuration
42
+ * @param applicationsAPI - The applications API instance for fetching vault address
43
+ * @param profileAPI - The profile API instance for fetching asset information
44
+ * @param apiUrl - The base URL for the Monaco API Gateway
45
+ */
46
+ constructor(publicClient, walletClient, chain, applicationsAPI, profileAPI, apiUrl) {
47
+ super(apiUrl);
48
+ this.publicClient = publicClient;
49
+ this.walletClient = walletClient;
50
+ this.chain = chain;
51
+ this.applicationsAPI = applicationsAPI;
52
+ this.profileAPI = profileAPI;
53
+ }
54
+ /**
55
+ * Fetches the vault contract address from the applications API.
56
+ *
57
+ * @returns Promise resolving to the vault contract address
58
+ * @throws {APIError} When vault address cannot be retrieved
59
+ * @private
60
+ */
61
+ async getVaultAddress() {
62
+ const config = await this.applicationsAPI.getApplicationConfig();
63
+ return config.vaultContractAddress;
64
+ }
65
+ /**
66
+ * Approves the vault contract to spend tokens on behalf of the user.
67
+ *
68
+ * This method creates and sends an ERC20 approve transaction to allow the vault
69
+ * to transfer tokens from the user's wallet. Approval is required before any
70
+ * deposit operations can be performed.
71
+ *
72
+ * @param assetId - The asset identifier (UUID) to approve
73
+ * @param amount - The maximum amount of tokens the vault can spend (as bigint)
74
+ * @param autoWait - Whether to automatically wait for transaction confirmation (defaults to true)
75
+ * @returns Promise resolving to TransactionResult with transaction details
76
+ * @throws {ContractError} When approval transaction fails or asset not found
77
+ * @throws {InvalidConfigError} When wallet account is not available
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * // Approve vault to spend up to 1000 USDC (auto-waits by default)
82
+ * const result = await vaultAPI.approve(
83
+ * "123e4567-e89b-12d3-a456-426614174000",
84
+ * parseUnits("1000", 6)
85
+ * );
86
+ * console.log(`Approval transaction: ${result.hash}`);
87
+ * console.log(`Status: ${result.status}`); // "confirmed" if successful
88
+ *
89
+ * // Or skip auto-waiting
90
+ * const result = await vaultAPI.approve(
91
+ * "123e4567-e89b-12d3-a456-426614174000",
92
+ * parseUnits("1000", 6),
93
+ * false
94
+ * );
95
+ * // Then manually wait later if needed
96
+ * const receipt = await sdk.waitForTransaction(result.hash);
97
+ * ```
98
+ */
99
+ async approve(assetId, amount, autoWait = true) {
100
+ // Validate inputs
101
+ validate(ApproveTokenSchema, { assetId, amount, autoWait });
102
+ const vaultAddress = await this.getVaultAddress();
103
+ // Look up token address from asset ID
104
+ let tokenAddress;
105
+ try {
106
+ const assetBalance = await this.profileAPI.getUserBalanceByAssetId(assetId);
107
+ tokenAddress = assetBalance.token;
108
+ }
109
+ catch (error) {
110
+ throw new ContractError(`Failed to resolve asset ID '${assetId}': Asset not found or invalid`, {
111
+ revertReason: "ASSET_NOT_FOUND",
112
+ cause: error instanceof Error ? error : undefined,
113
+ });
114
+ }
115
+ const account = this.walletClient.account;
116
+ if (!account) {
117
+ throw new InvalidConfigError("No account available in wallet client", "account");
118
+ }
119
+ const nonce = account.getNonce ? await account.getNonce() : 0n;
120
+ // Use writeContract - handles nonce, gas estimation, signing, and sending automatically
121
+ const hash = await this.walletClient.writeContract({
122
+ address: tokenAddress,
123
+ abi: erc20Abi,
124
+ functionName: "approve",
125
+ args: [vaultAddress, amount],
126
+ chain: this.chain,
127
+ account,
128
+ });
129
+ const txResult = {
130
+ nonce,
131
+ hash,
132
+ status: "pending",
133
+ };
134
+ // Handle auto-waiting for transaction confirmation
135
+ return await this.waitForTransaction(txResult, autoWait);
136
+ }
137
+ /**
138
+ * Deposits tokens into the Monaco vault.
139
+ *
140
+ * Deposits the specified amount of tokens into the vault contract. The method
141
+ * first checks if sufficient approval exists, then obtains a signature from the
142
+ * API Gateway, and finally executes the deposit transaction on-chain.
143
+ *
144
+ * Note: This method requires prior approval via the approve() method.
145
+ *
146
+ * @param assetId - The asset identifier (UUID) to deposit
147
+ * @param amount - The amount of tokens to deposit (as bigint)
148
+ * @param autoWait - Whether to automatically wait for transaction confirmation (defaults to true)
149
+ * @returns Promise resolving to TransactionResult with transaction details
150
+ * @throws {ContractError} When deposit fails or approval is insufficient
151
+ * @throws {APIError} When the asset is not found or the assetId is invalid
152
+ * @throws {InvalidConfigError} When wallet account is not available
153
+ *
154
+ * @example
155
+ * ```typescript
156
+ * // Deposit 100 USDC into the vault (auto-waits by default)
157
+ * const result = await vaultAPI.deposit(
158
+ * "123e4567-e89b-12d3-a456-426614174000",
159
+ * parseUnits("100", 6)
160
+ * );
161
+ * console.log(`Deposit transaction: ${result.hash}`);
162
+ * console.log(`Status: ${result.status}`); // "confirmed" if successful
163
+ *
164
+ * // Or skip auto-waiting
165
+ * const result = await vaultAPI.deposit(
166
+ * "123e4567-e89b-12d3-a456-426614174000",
167
+ * parseUnits("100", 6),
168
+ * false
169
+ * );
170
+ * // Then manually wait later if needed
171
+ * const receipt = await sdk.waitForTransaction(result.hash);
172
+ * ```
173
+ */
174
+ async deposit(assetId, amount, autoWait = true) {
175
+ // Validate inputs
176
+ validate(DepositSchema, { assetId, amount, autoWait });
177
+ const vaultAddress = await this.getVaultAddress();
178
+ // Look up token address from asset ID
179
+ let tokenAddress;
180
+ try {
181
+ const assetBalance = await this.profileAPI.getUserBalanceByAssetId(assetId);
182
+ tokenAddress = assetBalance.token;
183
+ }
184
+ catch (error) {
185
+ throw new ContractError(`Failed to resolve asset ID '${assetId}': Asset not found or invalid`, {
186
+ revertReason: "ASSET_NOT_FOUND",
187
+ cause: error instanceof Error ? error : undefined,
188
+ });
189
+ }
190
+ // Native SEI has a zero address token - skip allowance check (no ERC20 approval needed)
191
+ const isNativeToken = tokenAddress === "0x0000000000000000000000000000000000000000";
192
+ if (!isNativeToken) {
193
+ // Check if approval is needed before proceeding
194
+ const needsApproval = await this.needsApproval(assetId, amount);
195
+ if (needsApproval) {
196
+ throw new ContractError(`Approval required before deposit. Please invoke approve() first for asset ${assetId} (token address: ${tokenAddress}).`, {
197
+ revertReason: "APPROVAL_REQUIRED",
198
+ });
199
+ }
200
+ }
201
+ // Get signature from backend API using asset_id
202
+ const { seed, signature } = await this.getDepositSignature(assetId, amount);
203
+ const walletAccount = this.walletClient.account;
204
+ if (!walletAccount) {
205
+ throw new InvalidConfigError("No account available in wallet client", "account");
206
+ }
207
+ // For native SEI (zero address), use depositNative (payable); for ERC20 tokens, use deposit
208
+ let hash;
209
+ if (isNativeToken) {
210
+ hash = await this.walletClient.writeContract({
211
+ address: vaultAddress,
212
+ abi: CONTRACT_ABIS.vault,
213
+ functionName: "depositNative",
214
+ args: [seed, signature],
215
+ account: walletAccount,
216
+ chain: this.chain,
217
+ value: amount,
218
+ });
219
+ }
220
+ else {
221
+ hash = await this.walletClient.writeContract({
222
+ address: vaultAddress,
223
+ abi: CONTRACT_ABIS.vault,
224
+ functionName: "deposit",
225
+ args: [tokenAddress, amount, seed, signature],
226
+ account: walletAccount,
227
+ chain: this.chain,
228
+ });
229
+ }
230
+ const nonce = walletAccount.getNonce ? await walletAccount.getNonce() : 0n;
231
+ const txResult = {
232
+ hash,
233
+ status: "pending",
234
+ nonce,
235
+ };
236
+ return await this.waitForTransaction(txResult, autoWait);
237
+ }
238
+ /**
239
+ * Withdraws tokens from the Monaco vault.
240
+ *
241
+ * Withdraws the specified amount of tokens from the vault contract back to the
242
+ * user's wallet. The method obtains a signature from the API Gateway and then
243
+ * executes the withdrawal transaction on-chain.
244
+ *
245
+ * @param assetId - The asset identifier (UUID) to withdraw
246
+ * @param amount - The amount of tokens to withdraw (as bigint)
247
+ * @param autoWait - Whether to automatically wait for transaction confirmation (defaults to true)
248
+ * @returns Promise resolving to TransactionResult with transaction details
249
+ * @throws {ContractError} When withdrawal fails
250
+ * @throws {APIError} When signature retrieval fails or the asset is not found/assetId is invalid
251
+ * @throws {InvalidConfigError} When wallet account is not available
252
+ *
253
+ * @example
254
+ * ```typescript
255
+ * // Withdraw 50 USDC from the vault (auto-waits by default)
256
+ * const result = await vaultAPI.withdraw(
257
+ * "123e4567-e89b-12d3-a456-426614174000",
258
+ * parseUnits("50", 6)
259
+ * );
260
+ * console.log(`Withdrawal transaction: ${result.hash}`);
261
+ * console.log(`Status: ${result.status}`); // "confirmed" if successful
262
+ *
263
+ * // Or skip auto-waiting
264
+ * const result = await vaultAPI.withdraw(
265
+ * "123e4567-e89b-12d3-a456-426614174000",
266
+ * parseUnits("50", 6),
267
+ * false
268
+ * );
269
+ * // Then manually wait later if needed
270
+ * const receipt = await sdk.waitForTransaction(result.hash);
271
+ * ```
272
+ */
273
+ async withdraw(assetId, amount, autoWait = true) {
274
+ validate(WithdrawSchema, { assetId, amount, autoWait });
275
+ const vaultAddress = await this.getVaultAddress();
276
+ // Look up token address from asset ID
277
+ let tokenAddress;
278
+ try {
279
+ const assetBalance = await this.profileAPI.getUserBalanceByAssetId(assetId);
280
+ tokenAddress = assetBalance.token;
281
+ }
282
+ catch (error) {
283
+ throw new ContractError(`Failed to resolve asset ID '${assetId}': Asset not found or invalid`, {
284
+ revertReason: "ASSET_NOT_FOUND",
285
+ cause: error instanceof Error ? error : undefined,
286
+ });
287
+ }
288
+ // Native SEI has a zero address token
289
+ const isNativeToken = tokenAddress === "0x0000000000000000000000000000000000000000";
290
+ // Get signature from backend API using asset_id
291
+ const { seed, signature } = await this.getWithdrawSignature(assetId, amount);
292
+ const walletAccount = this.walletClient.account;
293
+ if (!walletAccount) {
294
+ throw new InvalidConfigError("No account available in wallet client", "account");
295
+ }
296
+ // For native SEI (zero address), use withdrawNative; for ERC20 tokens, use withdraw
297
+ let hash;
298
+ if (isNativeToken) {
299
+ hash = await this.walletClient.writeContract({
300
+ address: vaultAddress,
301
+ abi: CONTRACT_ABIS.vault,
302
+ functionName: "withdrawNative",
303
+ args: [amount, seed, signature],
304
+ account: walletAccount,
305
+ chain: this.chain,
306
+ });
307
+ }
308
+ else {
309
+ hash = await this.walletClient.writeContract({
310
+ address: vaultAddress,
311
+ abi: CONTRACT_ABIS.vault,
312
+ functionName: "withdraw",
313
+ args: [tokenAddress, amount, seed, signature],
314
+ account: walletAccount,
315
+ chain: this.chain,
316
+ });
317
+ }
318
+ const nonce = walletAccount.getNonce ? await walletAccount.getNonce() : 0n;
319
+ const txResult = {
320
+ hash,
321
+ status: "pending",
322
+ nonce,
323
+ };
324
+ // Handle auto-waiting for transaction confirmation
325
+ return await this.waitForTransaction(txResult, autoWait);
326
+ }
327
+ /**
328
+ * Retrieves the user's token balance in the vault.
329
+ *
330
+ * Queries the vault contract to get the current balance of a specific token
331
+ * for the connected wallet. Returns both raw amount and formatted display values.
332
+ *
333
+ * @param assetId - The asset identifier (UUID) to check balance for
334
+ * @returns Promise resolving to Balance with token balance details
335
+ * @throws {ContractError} When balance retrieval fails or asset not found
336
+ *
337
+ * @example
338
+ * ```typescript
339
+ * const balance = await vaultAPI.getBalance("123e4567-e89b-12d3-a456-426614174000");
340
+ * console.log(`Vault balance: ${balance.formatted} ${balance.symbol}`);
341
+ * console.log(`Raw amount: ${balance.amount}`);
342
+ * ```
343
+ */
344
+ async getBalance(assetId) {
345
+ // Validate inputs
346
+ validate(GetBalanceSchema, { assetId });
347
+ const vaultAddress = await this.getVaultAddress();
348
+ // Look up token address from asset ID
349
+ let tokenAddress;
350
+ try {
351
+ const assetBalance = await this.profileAPI.getUserBalanceByAssetId(assetId);
352
+ tokenAddress = assetBalance.token;
353
+ }
354
+ catch (error) {
355
+ throw new ContractError(`Failed to resolve asset ID '${assetId}': Asset not found or invalid`, {
356
+ revertReason: "ASSET_NOT_FOUND",
357
+ cause: error instanceof Error ? error : undefined,
358
+ });
359
+ }
360
+ const [account] = await this.walletClient.getAddresses();
361
+ // Get balance from vault contract
362
+ const balance = (await this.publicClient.readContract({
363
+ address: vaultAddress,
364
+ abi: CONTRACT_ABIS.vault,
365
+ functionName: "balanceOf",
366
+ args: [account, tokenAddress],
367
+ }));
368
+ // Get token metadata
369
+ const tokenContract = getContract({
370
+ address: tokenAddress,
371
+ abi: erc20Abi,
372
+ client: this.publicClient,
373
+ });
374
+ const [symbol, decimals] = await Promise.all([tokenContract.read.symbol(), tokenContract.read.decimals()]);
375
+ return {
376
+ token: tokenAddress,
377
+ amount: balance,
378
+ formatted: formatUnits(balance, decimals),
379
+ symbol: symbol,
380
+ decimals: decimals,
381
+ };
382
+ }
383
+ /**
384
+ * Retrieves the current allowance for a token.
385
+ *
386
+ * Queries the ERC20 token contract to get the current allowance granted to the
387
+ * vault contract for spending tokens on behalf of the user.
388
+ *
389
+ * @param assetId - The asset identifier (UUID) to check allowance for
390
+ * @returns Promise resolving to the current allowance amount as bigint
391
+ * @throws {ContractError} When allowance retrieval fails or asset not found
392
+ *
393
+ * @example
394
+ * ```typescript
395
+ * const allowance = await vaultAPI.getAllowance("123e4567-e89b-12d3-a456-426614174000");
396
+ * console.log(`Current allowance: ${formatUnits(allowance, 6)} USDC`);
397
+ * ```
398
+ */
399
+ async getAllowance(assetId) {
400
+ const vaultAddress = await this.getVaultAddress();
401
+ const [account] = await this.walletClient.getAddresses();
402
+ // Look up token address from asset ID
403
+ let tokenAddress;
404
+ try {
405
+ const assetBalance = await this.profileAPI.getUserBalanceByAssetId(assetId);
406
+ tokenAddress = assetBalance.token;
407
+ }
408
+ catch (error) {
409
+ throw new ContractError(`Failed to resolve asset ID '${assetId}': Asset not found or invalid`, {
410
+ revertReason: "ASSET_NOT_FOUND",
411
+ cause: error instanceof Error ? error : undefined,
412
+ });
413
+ }
414
+ return (await this.publicClient.readContract({
415
+ address: tokenAddress,
416
+ abi: erc20Abi,
417
+ functionName: "allowance",
418
+ args: [account, vaultAddress],
419
+ }));
420
+ }
421
+ /**
422
+ * Checks if approval is needed for a specific amount.
423
+ *
424
+ * Compares the current allowance with the requested amount to determine if
425
+ * the user needs to approve more tokens before performing operations.
426
+ *
427
+ * @param assetId - The asset identifier (UUID) to check for
428
+ * @param amount - The amount to check approval for (as bigint)
429
+ * @returns Promise resolving to true if approval is needed, false otherwise
430
+ * @throws {ContractError} When approval check fails or asset not found
431
+ *
432
+ * @example
433
+ * ```typescript
434
+ * const needsApproval = await vaultAPI.needsApproval(
435
+ * "123e4567-e89b-12d3-a456-426614174000",
436
+ * parseUnits("100", 6)
437
+ * );
438
+ *
439
+ * if (needsApproval) {
440
+ * console.log("Approval required before deposit");
441
+ * await vaultAPI.approve("123e4567-e89b-12d3-a456-426614174000", parseUnits("100", 6));
442
+ * }
443
+ * ```
444
+ */
445
+ async needsApproval(assetId, amount) {
446
+ const allowance = await this.getAllowance(assetId);
447
+ return allowance < amount;
448
+ }
449
+ /**
450
+ * Retrieves a deposit signature from the API Gateway.
451
+ *
452
+ * Internal method that communicates with the Monaco API Gateway to obtain
453
+ * the cryptographic signature required for deposit transactions. The signature
454
+ * validates the deposit request and ensures proper authorization.
455
+ *
456
+ * @param assetId - The asset identifier (UUID) to deposit
457
+ * @param amount - The amount to deposit (as bigint)
458
+ * @returns Promise resolving to object containing seed and signature
459
+ * @throws {APIError} When signature retrieval fails
460
+ * @private
461
+ */
462
+ async getDepositSignature(assetId, amount) {
463
+ const data = await this.makeAuthenticatedRequest("/api/v1/deposit/signature", {
464
+ method: "POST",
465
+ body: JSON.stringify({
466
+ asset_id: assetId,
467
+ amount: amount.toString(),
468
+ }),
469
+ });
470
+ return {
471
+ seed: data.seed,
472
+ signature: data.signature,
473
+ };
474
+ }
475
+ /**
476
+ * Retrieves a withdrawal signature from the API Gateway.
477
+ *
478
+ * Internal method that communicates with the Monaco API Gateway to obtain
479
+ * the cryptographic signature required for withdrawal transactions. The signature
480
+ * validates the withdrawal request and ensures proper authorization.
481
+ *
482
+ * @param assetId - The asset identifier (UUID) to withdraw
483
+ * @param amount - The amount to withdraw (as bigint)
484
+ * @returns Promise resolving to object containing seed and signature
485
+ * @throws {APIError} When signature retrieval fails
486
+ * @private
487
+ */
488
+ async getWithdrawSignature(assetId, amount) {
489
+ const data = await this.makeAuthenticatedRequest("/api/v1/withdraw/signature", {
490
+ method: "POST",
491
+ body: JSON.stringify({
492
+ asset_id: assetId,
493
+ amount: amount.toString(),
494
+ }),
495
+ });
496
+ return {
497
+ seed: data.seed,
498
+ signature: data.signature,
499
+ };
500
+ }
501
+ async waitForTransaction(txResult, autoWait = true, options = {}) {
502
+ if (!autoWait) {
503
+ return txResult;
504
+ }
505
+ const { confirmations = 1, timeout = 60000 } = options;
506
+ try {
507
+ const receipt = await this.publicClient.waitForTransactionReceipt({
508
+ hash: txResult.hash,
509
+ confirmations,
510
+ timeout,
511
+ });
512
+ return {
513
+ ...txResult,
514
+ status: receipt.status === "success" ? "confirmed" : "failed",
515
+ receipt,
516
+ };
517
+ }
518
+ catch {
519
+ return {
520
+ ...txResult,
521
+ status: "failed",
522
+ };
523
+ }
524
+ }
525
+ }
526
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/api/vault/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,gBAAgB,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAChH,OAAO,EAA4B,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAkD,MAAM,MAAM,CAAC;AACpI,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,MAAM,OAAO,YAAa,SAAQ,OAAO;IAIvC;;;;;;;;;OASG;IACH,YACmB,YAA0B,EAC1B,YAA0B,EAC1B,KAAY,EAC7B,eAAgC,EAChC,UAAsB,EACtB,MAAc;QAEd,KAAK,CAAC,MAAM,CAAC,CAAC;QAPG,iBAAY,GAAZ,YAAY,CAAc;QAC1B,iBAAY,GAAZ,YAAY,CAAc;QAC1B,UAAK,GAAL,KAAK,CAAO;QAM7B,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,eAAe;QACnB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,oBAAoB,EAAE,CAAC;QACjE,OAAO,MAAM,CAAC,oBAA+B,CAAC;IAChD,CAAC;IAED;;;;;;;;;;;;;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AQ;gBAC7D,OAAO;aACR,CAAC;QACJ,CAAC;QAAC,MAAM,CAAC;YACP,OAAO;gBACL,GAAG,QAAQ;gBACX,MAAM,EAAE,QAAQ;aACjB,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Vault API Module
3
+ */
4
+ export { VaultAPIImpl } from "./api";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/vault/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Vault API Module
3
+ */
4
+ export { VaultAPIImpl } from "./api";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/vault/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from "./types";
2
+ export * from "./utils";
3
+ export * from "./websocket";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/websocket/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from "./types";
2
+ export * from "./utils";
3
+ export * from "./websocket";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/websocket/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC"}
@@ -0,0 +1,36 @@
1
+ import type { Interval, OHLCVEvent, OrderbookEvent, OrderbookQuotationMode, OrderEvent, TradeEvent, TradingMode, UserMovementEvent, WebSocketStatus } from "@0xmonaco/types";
2
+ export type StatusHandler = (status: WebSocketStatus) => void;
3
+ export type MessageHandler<T> = (data: T) => void;
4
+ export interface MonacoWebSocketOptions {
5
+ /** JWT access token for authenticated channels (orders) */
6
+ token?: string;
7
+ /** Enable auto-reconnect on disconnect (default: true) */
8
+ autoReconnect?: boolean;
9
+ /** Maximum reconnection attempts (default: 5) */
10
+ maxReconnectAttempts?: number;
11
+ /** Callback for connection status changes */
12
+ onStatusChange?: StatusHandler;
13
+ }
14
+ export interface MonacoWebSocket {
15
+ /** Connect to the WebSocket server */
16
+ connect: () => Promise<void>;
17
+ /** Disconnect from the WebSocket server */
18
+ disconnect: () => void;
19
+ /** Check if currently connected */
20
+ isConnected: () => boolean;
21
+ /** Get current websocket connection status */
22
+ getStatus: () => WebSocketStatus;
23
+ /** Update the access token (for re-auth) */
24
+ setToken: (token: string) => void;
25
+ /** Subscribe to order events (requires authentication) */
26
+ orders: (tradingPairId: string, tradingMode: TradingMode, handler: MessageHandler<OrderEvent>) => () => void;
27
+ /** Subscribe to orderbook events (public) */
28
+ orderbook: (tradingPairId: string, tradingMode: TradingMode, magnitude: number, quotationMode: OrderbookQuotationMode, handler: MessageHandler<OrderbookEvent>) => () => void;
29
+ /** Subscribe to OHLCV candlestick events (public) */
30
+ ohlcv: (tradingPairId: string, tradingMode: TradingMode, interval: Interval, handler: MessageHandler<OHLCVEvent>) => () => void;
31
+ /** Subscribe to trade events (public) */
32
+ trades: (tradingPairId: string, handler: MessageHandler<TradeEvent>) => () => void;
33
+ /** Subscribe to user movement events (requires authentication) */
34
+ movements: (handler: MessageHandler<UserMovementEvent>) => () => void;
35
+ }
36
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/api/websocket/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ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C,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,cAAc,CAAC,UAAU,CAAC,KAAK,MAAM,IAAI,CAAC;IAEhI,yCAAyC;IACzC,MAAM,EAAE,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,CAAC,UAAU,CAAC,KAAK,MAAM,IAAI,CAAC;IAEnF,kEAAkE;IAClE,SAAS,EAAE,CAAC,OAAO,EAAE,cAAc,CAAC,iBAAiB,CAAC,KAAK,MAAM,IAAI,CAAC;CACvE"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/api/websocket/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Convert snake_case to camelCase
3
+ */
4
+ export declare function toCamelCase(str: string): string;
5
+ /**
6
+ * Recursively convert object keys from snake_case to camelCase
7
+ */
8
+ export declare function keysToCamelCase<T>(obj: unknown): T;
9
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/api/websocket/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,GAAG,CAAC,CAUlD"}