@0xmonaco/core 0.1.0

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 (50) hide show
  1. package/README.md +421 -0
  2. package/dist/api/auth/api.d.ts +198 -0
  3. package/dist/api/auth/api.d.ts.map +1 -0
  4. package/dist/api/auth/api.js +359 -0
  5. package/dist/api/auth/api.js.map +1 -0
  6. package/dist/api/auth/index.d.ts +6 -0
  7. package/dist/api/auth/index.d.ts.map +1 -0
  8. package/dist/api/auth/index.js +5 -0
  9. package/dist/api/auth/index.js.map +1 -0
  10. package/dist/api/index.d.ts +8 -0
  11. package/dist/api/index.d.ts.map +1 -0
  12. package/dist/api/index.js +8 -0
  13. package/dist/api/index.js.map +1 -0
  14. package/dist/api/trading/api.d.ts +152 -0
  15. package/dist/api/trading/api.d.ts.map +1 -0
  16. package/dist/api/trading/api.js +229 -0
  17. package/dist/api/trading/api.js.map +1 -0
  18. package/dist/api/trading/index.d.ts +6 -0
  19. package/dist/api/trading/index.d.ts.map +1 -0
  20. package/dist/api/trading/index.js +5 -0
  21. package/dist/api/trading/index.js.map +1 -0
  22. package/dist/api/vault/api.d.ts +224 -0
  23. package/dist/api/vault/api.d.ts.map +1 -0
  24. package/dist/api/vault/api.js +514 -0
  25. package/dist/api/vault/api.js.map +1 -0
  26. package/dist/api/vault/index.d.ts +6 -0
  27. package/dist/api/vault/index.d.ts.map +1 -0
  28. package/dist/api/vault/index.js +5 -0
  29. package/dist/api/vault/index.js.map +1 -0
  30. package/dist/chains.d.ts +90 -0
  31. package/dist/chains.d.ts.map +1 -0
  32. package/dist/chains.js +56 -0
  33. package/dist/chains.js.map +1 -0
  34. package/dist/errors.d.ts +132 -0
  35. package/dist/errors.d.ts.map +1 -0
  36. package/dist/errors.js +165 -0
  37. package/dist/errors.js.map +1 -0
  38. package/dist/index.d.ts +11 -0
  39. package/dist/index.d.ts.map +1 -0
  40. package/dist/index.js +19 -0
  41. package/dist/index.js.map +1 -0
  42. package/dist/networks.d.ts +8 -0
  43. package/dist/networks.d.ts.map +1 -0
  44. package/dist/networks.js +16 -0
  45. package/dist/networks.js.map +1 -0
  46. package/dist/sdk.d.ts +76 -0
  47. package/dist/sdk.d.ts.map +1 -0
  48. package/dist/sdk.js +203 -0
  49. package/dist/sdk.js.map +1 -0
  50. package/package.json +38 -0
@@ -0,0 +1,229 @@
1
+ /**
2
+ * Trading API Implementation
3
+ *
4
+ * Handles trading operations including order placement and management.
5
+ * All operations use JWT authentication and go through the API Gateway.
6
+ *
7
+ * This class provides a complete interface for trading operations on the Monaco protocol,
8
+ * including various order types, order management, and position operations.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const tradingAPI = new TradingAPIImpl(apiUrl);
13
+ * tradingAPI.setAccessToken(jwtToken);
14
+ *
15
+ * // Place a limit order
16
+ * const order = await tradingAPI.placeLimitOrder(
17
+ * "ETH-USD",
18
+ * "BUY",
19
+ * "1.5",
20
+ * "2000.50"
21
+ * );
22
+ *
23
+ * // Get open orders
24
+ * const openOrders = await tradingAPI.getOpenOrders({ market: "ETH-USD" });
25
+ * ```
26
+ */
27
+ import { APIError, OrderError } from "../../errors";
28
+ export class TradingAPIImpl {
29
+ /**
30
+ * Creates a new TradingAPI instance.
31
+ *
32
+ * @param apiUrl - The base URL for the Monaco API Gateway
33
+ */
34
+ constructor(apiUrl) {
35
+ this.apiUrl = apiUrl;
36
+ }
37
+ /**
38
+ * Set the access token for the TradingAPI
39
+ * @param token - The access token to set
40
+ */
41
+ setAccessToken(token) {
42
+ this.accessToken = token;
43
+ }
44
+ /**
45
+ * Internal method to make authenticated API requests.
46
+ *
47
+ * @param endpoint - The API endpoint to call
48
+ * @param options - Request options
49
+ * @returns Promise resolving to the response data
50
+ * @throws {APIError} When API communication fails
51
+ */
52
+ async makeRequest(endpoint, options = {}) {
53
+ if (!this.accessToken) {
54
+ throw new APIError("Access token not set. Call setAccessToken() first.", endpoint, 401);
55
+ }
56
+ const response = await fetch(`${this.apiUrl}${endpoint}`, {
57
+ headers: {
58
+ "Content-Type": "application/json",
59
+ "Authorization": `Bearer ${this.accessToken}`,
60
+ ...options.headers,
61
+ },
62
+ ...options,
63
+ });
64
+ if (!response.ok) {
65
+ throw new APIError(`API request failed: ${response.status}`, endpoint, response.status);
66
+ }
67
+ return response.json();
68
+ }
69
+ /**
70
+ * Places a limit order on the order book.
71
+ *
72
+ * Limit orders are executed only when the market price reaches or improves upon
73
+ * the specified price. They provide price protection but may not execute immediately.
74
+ *
75
+ * @param market - The trading pair identifier (e.g., "ETH-USD")
76
+ * @param side - The order side ("BUY" or "SELL")
77
+ * @param quantity - The order quantity as string
78
+ * @param price - The limit price as string
79
+ * @param options - Optional parameters for the limit order
80
+ * @param options.tradingMode - Trading mode (e.g., "SPOT")
81
+ * @returns Promise resolving to CreateOrderResponse with order details
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * const order = await tradingAPI.placeLimitOrder(
86
+ * "ETH-USD",
87
+ * "BUY",
88
+ * "1.5",
89
+ * "2000.50",
90
+ * { tradingMode: "SPOT" }
91
+ * );
92
+ * console.log(`Limit order placed: ${order.order_id}`);
93
+ * ```
94
+ */
95
+ async placeLimitOrder(market, side, quantity, price, options) {
96
+ try {
97
+ const requestBody = {
98
+ trading_pair: market,
99
+ order_type: "LIMIT",
100
+ side,
101
+ price,
102
+ quantity,
103
+ trading_mode: options?.tradingMode || "SPOT",
104
+ };
105
+ return await this.makeRequest("/api/v1/orders", {
106
+ method: "POST",
107
+ body: JSON.stringify(requestBody),
108
+ });
109
+ }
110
+ catch (error) {
111
+ throw new OrderError(`Failed to place limit order: ${error instanceof Error ? error.message : "Unknown error"}`, undefined, market);
112
+ }
113
+ }
114
+ /**
115
+ * Places a market order for immediate execution.
116
+ *
117
+ * Market orders execute immediately at the current market price. They provide
118
+ * immediate execution but may experience slippage.
119
+ *
120
+ * @param market - The trading pair identifier (e.g., "ETH-USD")
121
+ * @param side - The order side ("BUY" or "SELL")
122
+ * @param quantity - The order quantity as string
123
+ * @param options - Optional parameters for the market order
124
+ * @param options.tradingMode - Trading mode (e.g., "SPOT")
125
+ * @returns Promise resolving to CreateOrderResponse with order details
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * const order = await tradingAPI.placeMarketOrder(
130
+ * "ETH-USD",
131
+ * "SELL",
132
+ * "0.5",
133
+ * { tradingMode: "SPOT" }
134
+ * );
135
+ * ```
136
+ */
137
+ async placeMarketOrder(market, side, quantity, options) {
138
+ try {
139
+ const requestBody = {
140
+ trading_pair: market,
141
+ order_type: "MARKET",
142
+ side,
143
+ price: null, // Market orders don't need price
144
+ quantity,
145
+ trading_mode: options?.tradingMode || "SPOT",
146
+ };
147
+ return await this.makeRequest("/api/v1/orders", {
148
+ method: "POST",
149
+ body: JSON.stringify(requestBody),
150
+ });
151
+ }
152
+ catch (error) {
153
+ throw new OrderError(`Failed to place market order: ${error instanceof Error ? error.message : "Unknown error"}`, undefined, market);
154
+ }
155
+ }
156
+ /**
157
+ * Cancels an existing order.
158
+ *
159
+ * Cancels an open order by its ID. The order must be in an open state to be cancelled.
160
+ * Cancelled orders cannot be recovered.
161
+ *
162
+ * @param orderId - The ID of the order to cancel
163
+ * @returns Promise resolving to CancelOrderResponse with cancellation details
164
+ * @throws {OrderError} When cancellation fails
165
+ * @throws {APIError} When API communication fails
166
+ *
167
+ * @example
168
+ * ```typescript
169
+ * const result = await tradingAPI.cancelOrder("order_123");
170
+ * console.log(`Order cancelled: ${result.status}`);
171
+ * ```
172
+ */
173
+ async cancelOrder(orderId) {
174
+ try {
175
+ const requestBody = {
176
+ order_id: orderId,
177
+ };
178
+ return await this.makeRequest("/api/v1/orders/cancel", {
179
+ method: "POST",
180
+ body: JSON.stringify(requestBody),
181
+ });
182
+ }
183
+ catch (error) {
184
+ throw new OrderError(`Failed to cancel order ${orderId}: ${error instanceof Error ? error.message : "Unknown error"}`, undefined, orderId);
185
+ }
186
+ }
187
+ /**
188
+ * Updates an existing order (price and/or quantity).
189
+ *
190
+ * Updates an open order by changing its price or quantity.
191
+ * This creates a new order and cancels the old one.
192
+ *
193
+ * @param orderId - The ID of the order to update
194
+ * @param updates - Fields to update
195
+ * @param updates.price - New price (optional)
196
+ * @param updates.quantity - New quantity (optional)
197
+ * @returns Promise resolving to UpdateOrderResponse with update details
198
+ * @throws {OrderError} When update fails
199
+ * @throws {APIError} When API communication fails
200
+ *
201
+ * @example
202
+ * ```typescript
203
+ * const result = await tradingAPI.updateOrder("order_123", {
204
+ * price: "2100.00",
205
+ * quantity: "2.0"
206
+ * });
207
+ * console.log(`Order updated: ${result.order_id}`);
208
+ * ```
209
+ */
210
+ async updateOrder(orderId, updates) {
211
+ try {
212
+ const requestBody = {};
213
+ if (updates.price !== undefined) {
214
+ requestBody.price = updates.price;
215
+ }
216
+ if (updates.quantity !== undefined) {
217
+ requestBody.quantity = updates.quantity;
218
+ }
219
+ return await this.makeRequest(`/api/v1/orders/${orderId}`, {
220
+ method: "PUT",
221
+ body: JSON.stringify(requestBody),
222
+ });
223
+ }
224
+ catch (error) {
225
+ throw new OrderError(`Failed to update order ${orderId}: ${error instanceof Error ? error.message : "Unknown error"}`, undefined, orderId);
226
+ }
227
+ }
228
+ }
229
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/api/trading/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAUH,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAEpD,MAAM,OAAO,cAAc;IAGzB;;;;OAIG;IACH,YAA6B,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IAAG,CAAC;IAE/C;;;OAGG;IACH,cAAc,CAAC,KAAa;QAC1B,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;IAC3B,CAAC;IAED;;;;;;;OAOG;IACK,KAAK,CAAC,WAAW,CACvB,QAAgB,EAChB,UAAuB,EAAE;QA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,CAAC,CAAC,eAAe,EAAE,EAChG,SAAS,EACT,OAAO,CACR,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,KAAK,CAAC,WAAW,CACf,OAAe,EACf,OAGC;QAED,IAAI,CAAC;YACH,MAAM,WAAW,GAAQ,EAAE,CAAC;YAE5B,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;gBAChC,WAAW,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;YACpC,CAAC;YACD,IAAI,OAAO,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;gBACnC,WAAW,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;YAC1C,CAAC;YAED,OAAO,MAAM,IAAI,CAAC,WAAW,CAC3B,kBAAkB,OAAO,EAAE,EAC3B;gBACE,MAAM,EAAE,KAAK;gBACb,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC;aAClC,CACF,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,UAAU,CAClB,0BAA0B,OAAO,KAAK,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE,EAChG,SAAS,EACT,OAAO,CACR,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Trading API Module
3
+ */
4
+ export { TradingAPIImpl } from "./api";
5
+ export type { TradingAPI } from "@0xmonaco/types";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/trading/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AACvC,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Trading API Module
3
+ */
4
+ export { TradingAPIImpl } from "./api";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/trading/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC"}
@@ -0,0 +1,224 @@
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 { type PublicClient, type WalletClient, type Address, type Chain } from "viem";
31
+ import { type VaultAPI, type Balance, type TransactionResult } from "@0xmonaco/types";
32
+ export declare class VaultAPIImpl implements VaultAPI {
33
+ private readonly publicClient;
34
+ private readonly walletClient;
35
+ private readonly vaultAddress;
36
+ private readonly apiUrl;
37
+ private readonly chain;
38
+ private accessToken?;
39
+ /**
40
+ * Creates a new VaultAPI instance.
41
+ *
42
+ * @param publicClient - The viem public client for reading blockchain state
43
+ * @param walletClient - The viem wallet client for signing transactions
44
+ * @param vaultAddress - The address of the Monaco vault contract
45
+ * @param apiUrl - The base URL for the Monaco API Gateway
46
+ * @param chain - The blockchain network configuration
47
+ */
48
+ constructor(publicClient: PublicClient, walletClient: WalletClient, vaultAddress: Address, apiUrl: string, chain: Chain);
49
+ /**
50
+ * Set the access token for the VaultAPI
51
+ * @param token - The access token to set
52
+ */
53
+ setAccessToken(token: string): void;
54
+ /**
55
+ * Approves the vault contract to spend tokens on behalf of the user.
56
+ *
57
+ * This method creates and sends an ERC20 approve transaction to allow the vault
58
+ * to transfer tokens from the user's wallet. Approval is required before any
59
+ * deposit operations can be performed.
60
+ *
61
+ * @param token - The ERC20 token contract address to approve
62
+ * @param amount - The maximum amount of tokens the vault can spend (as bigint)
63
+ * @returns Promise resolving to TransactionResult with transaction details
64
+ * @throws {ContractError} When approval transaction fails
65
+ * @throws {InvalidConfigError} When wallet account is not available
66
+ * @throws {TransactionError} When transaction signing fails
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * // Approve vault to spend up to 1000 USDC
71
+ * const result = await vaultAPI.approve(
72
+ * usdcAddress,
73
+ * parseUnits("1000", 6)
74
+ * );
75
+ * console.log(`Approval transaction: ${result.hash}`);
76
+ * ```
77
+ */
78
+ approve(token: string, amount: bigint): Promise<TransactionResult>;
79
+ /**
80
+ * Deposits tokens into the Monaco vault.
81
+ *
82
+ * Deposits the specified amount of tokens into the vault contract. The method
83
+ * first checks if sufficient approval exists, then obtains a signature from the
84
+ * API Gateway, and finally executes the deposit transaction on-chain.
85
+ *
86
+ * Note: This method requires prior approval via the approve() method.
87
+ *
88
+ * @param token - The ERC20 token contract address to deposit
89
+ * @param amount - The amount of tokens to deposit (as bigint)
90
+ * @returns Promise resolving to TransactionResult with transaction details
91
+ * @throws {ContractError} When deposit fails or approval is insufficient
92
+ * @throws {APIError} When signature retrieval fails
93
+ * @throws {InvalidConfigError} When wallet account is not available
94
+ * @throws {TransactionError} When transaction signing fails
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * // Deposit 100 USDC into the vault
99
+ * const result = await vaultAPI.deposit(
100
+ * usdcAddress,
101
+ * parseUnits("100", 6)
102
+ * );
103
+ * console.log(`Deposit transaction: ${result.hash}`);
104
+ * ```
105
+ */
106
+ deposit(token: string, amount: bigint): Promise<TransactionResult>;
107
+ /**
108
+ * Withdraws tokens from the Monaco vault.
109
+ *
110
+ * Withdraws the specified amount of tokens from the vault contract back to the
111
+ * user's wallet. The method obtains a signature from the API Gateway and then
112
+ * executes the withdrawal transaction on-chain.
113
+ *
114
+ * @param token - The ERC20 token contract address to withdraw
115
+ * @param amount - The amount of tokens to withdraw (as bigint)
116
+ * @returns Promise resolving to TransactionResult with transaction details
117
+ * @throws {ContractError} When withdrawal fails
118
+ * @throws {APIError} When signature retrieval fails
119
+ * @throws {InvalidConfigError} When wallet account is not available
120
+ * @throws {TransactionError} When transaction signing fails
121
+ *
122
+ * @example
123
+ * ```typescript
124
+ * // Withdraw 50 USDC from the vault
125
+ * const result = await vaultAPI.withdraw(
126
+ * usdcAddress,
127
+ * parseUnits("50", 6)
128
+ * );
129
+ * console.log(`Withdrawal transaction: ${result.hash}`);
130
+ * ```
131
+ */
132
+ withdraw(token: string, amount: bigint): Promise<TransactionResult>;
133
+ /**
134
+ * Retrieves the user's token balance in the vault.
135
+ *
136
+ * Queries the vault contract to get the current balance of a specific token
137
+ * for the connected wallet. Returns both raw amount and formatted display values.
138
+ *
139
+ * @param token - The ERC20 token contract address to check balance for
140
+ * @returns Promise resolving to Balance with token balance details
141
+ * @throws {ContractError} When balance retrieval fails
142
+ *
143
+ * @example
144
+ * ```typescript
145
+ * const balance = await vaultAPI.getBalance(usdcAddress);
146
+ * console.log(`Vault balance: ${balance.formatted} ${balance.symbol}`);
147
+ * console.log(`Raw amount: ${balance.amount}`);
148
+ * ```
149
+ */
150
+ getBalance(token: string): Promise<Balance>;
151
+ /**
152
+ * Retrieves the current allowance for a token.
153
+ *
154
+ * Queries the ERC20 token contract to get the current allowance granted to the
155
+ * vault contract for spending tokens on behalf of the user.
156
+ *
157
+ * @param token - The ERC20 token contract address to check allowance for
158
+ * @returns Promise resolving to the current allowance amount as bigint
159
+ * @throws {ContractError} When allowance retrieval fails
160
+ *
161
+ * @example
162
+ * ```typescript
163
+ * const allowance = await vaultAPI.getAllowance(usdcAddress);
164
+ * console.log(`Current allowance: ${formatUnits(allowance, 6)} USDC`);
165
+ * ```
166
+ */
167
+ getAllowance(token: string): Promise<bigint>;
168
+ /**
169
+ * Checks if approval is needed for a specific amount.
170
+ *
171
+ * Compares the current allowance with the requested amount to determine if
172
+ * the user needs to approve more tokens before performing operations.
173
+ *
174
+ * @param token - The ERC20 token contract address to check
175
+ * @param amount - The amount to check approval for (as bigint)
176
+ * @returns Promise resolving to true if approval is needed, false otherwise
177
+ * @throws {ContractError} When approval check fails
178
+ *
179
+ * @example
180
+ * ```typescript
181
+ * const needsApproval = await vaultAPI.needsApproval(
182
+ * usdcAddress,
183
+ * parseUnits("100", 6)
184
+ * );
185
+ *
186
+ * if (needsApproval) {
187
+ * console.log("Approval required before deposit");
188
+ * await vaultAPI.approve(usdcAddress, parseUnits("100", 6));
189
+ * }
190
+ * ```
191
+ */
192
+ needsApproval(token: string, amount: bigint): Promise<boolean>;
193
+ /**
194
+ * Retrieves a deposit signature from the API Gateway.
195
+ *
196
+ * Internal method that communicates with the Monaco API Gateway to obtain
197
+ * the cryptographic signature required for deposit transactions. The signature
198
+ * validates the deposit request and ensures proper authorization.
199
+ *
200
+ * @param token - The ERC20 token contract address
201
+ * @param amount - The amount to deposit (as bigint)
202
+ * @param userAddress - The user's wallet address
203
+ * @returns Promise resolving to object containing seed and signature
204
+ * @throws {APIError} When signature retrieval fails
205
+ * @private
206
+ */
207
+ private getDepositSignature;
208
+ /**
209
+ * Retrieves a withdrawal signature from the API Gateway.
210
+ *
211
+ * Internal method that communicates with the Monaco API Gateway to obtain
212
+ * the cryptographic signature required for withdrawal transactions. The signature
213
+ * validates the withdrawal request and ensures proper authorization.
214
+ *
215
+ * @param token - The ERC20 token contract address
216
+ * @param amount - The amount to withdraw (as bigint)
217
+ * @param userAddress - The user's wallet address
218
+ * @returns Promise resolving to object containing seed and signature
219
+ * @throws {APIError} When signature retrieval fails
220
+ * @private
221
+ */
222
+ private getWithdrawSignature;
223
+ }
224
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/api/vault/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,OAAO,EACZ,KAAK,KAAK,EAMX,MAAM,MAAM,CAAC;AACd,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,OAAO,EACZ,KAAK,iBAAiB,EACvB,MAAM,iBAAiB,CAAC;AASzB,qBAAa,YAAa,YAAW,QAAQ;IAazC,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,KAAK;IAhBxB,OAAO,CAAC,WAAW,CAAC,CAAS;IAE7B;;;;;;;;OAQG;gBAEgB,YAAY,EAAE,YAAY,EAC1B,YAAY,EAAE,YAAY,EAC1B,YAAY,EAAE,OAAO,EACrB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,KAAK;IAI/B;;;OAGG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAInC;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACG,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAsExE;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACG,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;IA2FxE;;;;;;;;;;;;;;;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