@0xmonaco/core 0.1.5 → 0.1.7

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 (62) hide show
  1. package/README.md +180 -108
  2. package/dist/api/applications/api.d.ts +45 -0
  3. package/dist/api/applications/api.d.ts.map +1 -0
  4. package/dist/api/applications/api.js +61 -0
  5. package/dist/api/applications/api.js.map +1 -0
  6. package/dist/api/applications/index.d.ts +6 -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 +5 -5
  11. package/dist/api/auth/api.d.ts.map +1 -1
  12. package/dist/api/auth/api.js +6 -6
  13. package/dist/api/auth/api.js.map +1 -1
  14. package/dist/api/auth/index.d.ts +1 -1
  15. package/dist/api/index.d.ts +5 -2
  16. package/dist/api/index.d.ts.map +1 -1
  17. package/dist/api/index.js +5 -2
  18. package/dist/api/index.js.map +1 -1
  19. package/dist/api/market/api.d.ts +12 -0
  20. package/dist/api/market/api.d.ts.map +1 -0
  21. package/dist/api/market/api.js +31 -0
  22. package/dist/api/market/api.js.map +1 -0
  23. package/dist/api/market/index.d.ts +3 -0
  24. package/dist/api/market/index.d.ts.map +1 -0
  25. package/dist/api/market/index.js +2 -0
  26. package/dist/api/market/index.js.map +1 -0
  27. package/dist/api/trading/api.d.ts +40 -33
  28. package/dist/api/trading/api.d.ts.map +1 -1
  29. package/dist/api/trading/api.js +59 -46
  30. package/dist/api/trading/api.js.map +1 -1
  31. package/dist/api/trading/index.d.ts +1 -1
  32. package/dist/api/vault/api.d.ts +90 -30
  33. package/dist/api/vault/api.d.ts.map +1 -1
  34. package/dist/api/vault/api.js +214 -67
  35. package/dist/api/vault/api.js.map +1 -1
  36. package/dist/api/vault/index.d.ts +1 -1
  37. package/dist/api/websocket/base-ws-client.d.ts +59 -0
  38. package/dist/api/websocket/base-ws-client.d.ts.map +1 -0
  39. package/dist/api/websocket/base-ws-client.js +211 -0
  40. package/dist/api/websocket/base-ws-client.js.map +1 -0
  41. package/dist/api/websocket/index.d.ts +8 -0
  42. package/dist/api/websocket/index.d.ts.map +1 -0
  43. package/dist/api/websocket/index.js +8 -0
  44. package/dist/api/websocket/index.js.map +1 -0
  45. package/dist/api/websocket/order-ws-client.d.ts +29 -0
  46. package/dist/api/websocket/order-ws-client.d.ts.map +1 -0
  47. package/dist/api/websocket/order-ws-client.js +128 -0
  48. package/dist/api/websocket/order-ws-client.js.map +1 -0
  49. package/dist/errors.d.ts +67 -76
  50. package/dist/index.d.ts +1 -1
  51. package/dist/index.d.ts.map +1 -1
  52. package/dist/index.js.map +1 -1
  53. package/dist/networks.d.ts +1 -1
  54. package/dist/sdk.d.ts +4 -2
  55. package/dist/sdk.d.ts.map +1 -1
  56. package/dist/sdk.js +20 -14
  57. package/dist/sdk.js.map +1 -1
  58. package/package.json +16 -6
  59. package/dist/chains.d.ts +0 -110
  60. package/dist/chains.d.ts.map +0 -1
  61. package/dist/chains.js +0 -56
  62. package/dist/chains.js.map +0 -1
@@ -27,24 +27,51 @@
27
27
  * console.log(`Deposit transaction: ${result.hash}`);
28
28
  * ```
29
29
  */
30
- import { type VaultAPI, type Balance, type TransactionResult } from "@0xmonaco/types";
30
+ import type { Balance, TransactionResult, VaultAPI, MarketAPI, ApplicationsAPI } from "@0xmonaco/types";
31
31
  import { type Address, type Chain, type PublicClient, type WalletClient } from "viem";
32
32
  import { BaseAPI } from "../base";
33
33
  export declare class VaultAPIImpl extends BaseAPI implements VaultAPI {
34
34
  private readonly publicClient;
35
35
  private readonly walletClient;
36
- private readonly vaultAddress;
37
36
  private readonly chain;
37
+ private marketAPI;
38
+ private applicationsAPI;
38
39
  /**
39
40
  * Creates a new VaultAPI instance.
40
41
  *
41
42
  * @param publicClient - The viem public client for reading blockchain state
42
43
  * @param walletClient - The viem wallet client for signing transactions
43
- * @param vaultAddress - The address of the Monaco vault contract
44
- * @param apiUrl - The base URL for the Monaco API Gateway
45
44
  * @param chain - The blockchain network configuration
45
+ * @param marketAPI - The market API instance for token validation
46
+ * @param applicationsAPI - The applications API instance for fetching vault address
47
+ * @param apiUrl - The base URL for the Monaco API Gateway
48
+ */
49
+ constructor(publicClient: PublicClient, walletClient: WalletClient, chain: Chain, marketAPI: MarketAPI, applicationsAPI: ApplicationsAPI, apiUrl: string);
50
+ /**
51
+ * Fetches the vault contract address from the applications API.
52
+ *
53
+ * @returns Promise resolving to the vault contract address
54
+ * @throws {APIError} When vault address cannot be retrieved
55
+ * @private
56
+ */
57
+ getVaultAddress(): Promise<Address>;
58
+ /**
59
+ * Maps a token symbol to its contract address.
60
+ *
61
+ * Looks up the token symbol in active trading pairs to find the corresponding
62
+ * contract address. Supports both base and quote token symbols.
63
+ *
64
+ * @param tokenSymbol - The token symbol to map (e.g., "USDC", "ETH", "MockUSDC")
65
+ * @returns Promise mapping to the token contract address
66
+ * @throws {APIError} When token symbol is not found or not supported
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * const address = await vaultAPI.mapTokenSymbolToAddress("USDC");
71
+ * console.log(address); // "0x6A86dA986797D59A839D136dB490292Cd560C131"
72
+ * ```
46
73
  */
47
- constructor(publicClient: PublicClient, walletClient: WalletClient, vaultAddress: Address, apiUrl: string, chain: Chain);
74
+ private mapTokenSymbolToAddress;
48
75
  /**
49
76
  * Approves the vault contract to spend tokens on behalf of the user.
50
77
  *
@@ -52,8 +79,9 @@ export declare class VaultAPIImpl extends BaseAPI implements VaultAPI {
52
79
  * to transfer tokens from the user's wallet. Approval is required before any
53
80
  * deposit operations can be performed.
54
81
  *
55
- * @param token - The ERC20 token contract address to approve
82
+ * @param tokenSymbol - The token symbol to approve (e.g., "USDC", "ETH", "MockUSDC")
56
83
  * @param amount - The maximum amount of tokens the vault can spend (as bigint)
84
+ * @param autoWait - Whether to automatically wait for transaction confirmation (defaults to true)
57
85
  * @returns Promise resolving to TransactionResult with transaction details
58
86
  * @throws {ContractError} When approval transaction fails
59
87
  * @throws {InvalidConfigError} When wallet account is not available
@@ -61,15 +89,25 @@ export declare class VaultAPIImpl extends BaseAPI implements VaultAPI {
61
89
  *
62
90
  * @example
63
91
  * ```typescript
64
- * // Approve vault to spend up to 1000 USDC
92
+ * // Approve vault to spend up to 1000 USDC (auto-waits by default)
65
93
  * const result = await vaultAPI.approve(
66
- * usdcAddress,
94
+ * "USDC",
67
95
  * parseUnits("1000", 6)
68
96
  * );
69
97
  * console.log(`Approval transaction: ${result.hash}`);
98
+ * console.log(`Status: ${result.status}`); // "confirmed" if successful
99
+ *
100
+ * // Or skip auto-waiting
101
+ * const result = await vaultAPI.approve(
102
+ * "MockUSDC",
103
+ * parseUnits("1000", 6),
104
+ * false
105
+ * );
106
+ * // Then manually wait later if needed
107
+ * const receipt = await sdk.waitForTransaction(result.hash);
70
108
  * ```
71
109
  */
72
- approve(token: string, amount: bigint): Promise<TransactionResult>;
110
+ approve(tokenSymbol: string, amount: bigint, autoWait?: boolean): Promise<TransactionResult>;
73
111
  /**
74
112
  * Deposits tokens into the Monaco vault.
75
113
  *
@@ -79,25 +117,35 @@ export declare class VaultAPIImpl extends BaseAPI implements VaultAPI {
79
117
  *
80
118
  * Note: This method requires prior approval via the approve() method.
81
119
  *
82
- * @param token - The ERC20 token contract address to deposit
120
+ * @param tokenSymbol - The token symbol to deposit (e.g., "USDC", "ETH", "MockUSDC")
83
121
  * @param amount - The amount of tokens to deposit (as bigint)
122
+ * @param autoWait - Whether to automatically wait for transaction confirmation (defaults to true)
84
123
  * @returns Promise resolving to TransactionResult with transaction details
85
124
  * @throws {ContractError} When deposit fails or approval is insufficient
86
- * @throws {APIError} When signature retrieval fails
87
125
  * @throws {InvalidConfigError} When wallet account is not available
88
126
  * @throws {TransactionError} When transaction signing fails
89
127
  *
90
128
  * @example
91
129
  * ```typescript
92
- * // Deposit 100 USDC into the vault
130
+ * // Deposit 100 USDC into the vault (auto-waits by default)
93
131
  * const result = await vaultAPI.deposit(
94
- * usdcAddress,
132
+ * "USDC",
95
133
  * parseUnits("100", 6)
96
134
  * );
97
135
  * console.log(`Deposit transaction: ${result.hash}`);
136
+ * console.log(`Status: ${result.status}`); // "confirmed" if successful
137
+ *
138
+ * // Or skip auto-waiting
139
+ * const result = await vaultAPI.deposit(
140
+ * "MockUSDC",
141
+ * parseUnits("100", 6),
142
+ * false
143
+ * );
144
+ * // Then manually wait later if needed
145
+ * const receipt = await sdk.waitForTransaction(result.hash);
98
146
  * ```
99
147
  */
100
- deposit(token: string, amount: bigint): Promise<TransactionResult>;
148
+ deposit(tokenSymbol: string, amount: bigint, autoWait?: boolean): Promise<TransactionResult>;
101
149
  /**
102
150
  * Withdraws tokens from the Monaco vault.
103
151
  *
@@ -105,8 +153,9 @@ export declare class VaultAPIImpl extends BaseAPI implements VaultAPI {
105
153
  * user's wallet. The method obtains a signature from the API Gateway and then
106
154
  * executes the withdrawal transaction on-chain.
107
155
  *
108
- * @param token - The ERC20 token contract address to withdraw
156
+ * @param tokenSymbol - The token symbol to withdraw (e.g., "USDC", "ETH", "MockUSDC")
109
157
  * @param amount - The amount of tokens to withdraw (as bigint)
158
+ * @param autoWait - Whether to automatically wait for transaction confirmation (defaults to true)
110
159
  * @returns Promise resolving to TransactionResult with transaction details
111
160
  * @throws {ContractError} When withdrawal fails
112
161
  * @throws {APIError} When signature retrieval fails
@@ -115,57 +164,67 @@ export declare class VaultAPIImpl extends BaseAPI implements VaultAPI {
115
164
  *
116
165
  * @example
117
166
  * ```typescript
118
- * // Withdraw 50 USDC from the vault
167
+ * // Withdraw 50 USDC from the vault (auto-waits by default)
119
168
  * const result = await vaultAPI.withdraw(
120
- * usdcAddress,
169
+ * "USDC",
121
170
  * parseUnits("50", 6)
122
171
  * );
123
172
  * console.log(`Withdrawal transaction: ${result.hash}`);
173
+ * console.log(`Status: ${result.status}`); // "confirmed" if successful
174
+ *
175
+ * // Or skip auto-waiting
176
+ * const result = await vaultAPI.withdraw(
177
+ * "MockUSDC",
178
+ * parseUnits("50", 6),
179
+ * false
180
+ * );
181
+ * // Then manually wait later if needed
182
+ * const receipt = await sdk.waitForTransaction(result.hash);
124
183
  * ```
125
184
  */
126
- withdraw(token: string, amount: bigint): Promise<TransactionResult>;
185
+ withdraw(tokenSymbol: string, amount: bigint, autoWait?: boolean): Promise<TransactionResult>;
127
186
  /**
128
187
  * Retrieves the user's token balance in the vault.
129
188
  *
130
189
  * Queries the vault contract to get the current balance of a specific token
131
190
  * for the connected wallet. Returns both raw amount and formatted display values.
132
191
  *
133
- * @param token - The ERC20 token contract address to check balance for
192
+ * @param tokenSymbol - The token symbol to check balance for (e.g., "USDC", "ETH", "MockUSDC")
134
193
  * @returns Promise resolving to Balance with token balance details
135
194
  * @throws {ContractError} When balance retrieval fails
136
195
  *
137
196
  * @example
138
197
  * ```typescript
139
- * const balance = await vaultAPI.getBalance(usdcAddress);
198
+ * const balance = await vaultAPI.getBalance("USDC");
140
199
  * console.log(`Vault balance: ${balance.formatted} ${balance.symbol}`);
141
200
  * console.log(`Raw amount: ${balance.amount}`);
142
201
  * ```
143
202
  */
144
- getBalance(token: string): Promise<Balance>;
203
+ getBalance(tokenSymbol: string): Promise<Balance>;
145
204
  /**
146
205
  * Retrieves the current allowance for a token.
147
206
  *
148
207
  * Queries the ERC20 token contract to get the current allowance granted to the
149
208
  * vault contract for spending tokens on behalf of the user.
150
209
  *
151
- * @param token - The ERC20 token contract address to check allowance for
210
+ * @param tokenSymbol - The token symbol to check allowance for (e.g., "USDC", "ETH", "MockUSDC")
152
211
  * @returns Promise resolving to the current allowance amount as bigint
153
212
  * @throws {ContractError} When allowance retrieval fails
154
213
  *
155
214
  * @example
156
215
  * ```typescript
157
- * const allowance = await vaultAPI.getAllowance(usdcAddress);
216
+ * const allowance = await vaultAPI.getAllowance("USDC");
158
217
  * console.log(`Current allowance: ${formatUnits(allowance, 6)} USDC`);
159
218
  * ```
160
219
  */
161
- getAllowance(token: string): Promise<bigint>;
220
+ getAllowance(tokenSymbol: string): Promise<bigint>;
162
221
  /**
163
222
  * Checks if approval is needed for a specific amount.
164
223
  *
165
224
  * Compares the current allowance with the requested amount to determine if
166
225
  * the user needs to approve more tokens before performing operations.
167
226
  *
168
- * @param token - The ERC20 token contract address to check
227
+ * @param tokenSymbol - The token symbol to check (e.g., "USDC", "ETH", "MockUSDC")
169
228
  * @param amount - The amount to check approval for (as bigint)
170
229
  * @returns Promise resolving to true if approval is needed, false otherwise
171
230
  * @throws {ContractError} When approval check fails
@@ -173,17 +232,17 @@ export declare class VaultAPIImpl extends BaseAPI implements VaultAPI {
173
232
  * @example
174
233
  * ```typescript
175
234
  * const needsApproval = await vaultAPI.needsApproval(
176
- * usdcAddress,
235
+ * "USDC",
177
236
  * parseUnits("100", 6)
178
237
  * );
179
238
  *
180
239
  * if (needsApproval) {
181
240
  * console.log("Approval required before deposit");
182
- * await vaultAPI.approve(usdcAddress, parseUnits("100", 6));
241
+ * await vaultAPI.approve("USDC", parseUnits("100", 6));
183
242
  * }
184
243
  * ```
185
244
  */
186
- needsApproval(token: string, amount: bigint): Promise<boolean>;
245
+ needsApproval(tokenSymbol: string, amount: bigint): Promise<boolean>;
187
246
  /**
188
247
  * Retrieves a deposit signature from the API Gateway.
189
248
  *
@@ -191,7 +250,7 @@ export declare class VaultAPIImpl extends BaseAPI implements VaultAPI {
191
250
  * the cryptographic signature required for deposit transactions. The signature
192
251
  * validates the deposit request and ensures proper authorization.
193
252
  *
194
- * @param token - The ERC20 token contract address
253
+ * @param tokenSymbol - The token symbol to deposit (e.g., "USDC", "ETH", "MockUSDC")
195
254
  * @param amount - The amount to deposit (as bigint)
196
255
  * @param userAddress - The user's wallet address
197
256
  * @returns Promise resolving to object containing seed and signature
@@ -206,7 +265,7 @@ export declare class VaultAPIImpl extends BaseAPI implements VaultAPI {
206
265
  * the cryptographic signature required for withdrawal transactions. The signature
207
266
  * validates the withdrawal request and ensures proper authorization.
208
267
  *
209
- * @param token - The ERC20 token contract address
268
+ * @param tokenSymbol - The token symbol to withdraw (e.g., "USDC", "ETH", "MockUSDC")
210
269
  * @param amount - The amount to withdraw (as bigint)
211
270
  * @param userAddress - The user's wallet address
212
271
  * @returns Promise resolving to object containing seed and signature
@@ -214,5 +273,6 @@ export declare class VaultAPIImpl extends BaseAPI implements VaultAPI {
214
273
  * @private
215
274
  */
216
275
  private getWithdrawSignature;
276
+ private waitForTransaction;
217
277
  }
218
278
  //# sourceMappingURL=api.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/api/vault/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAGH,OAAO,EACN,KAAK,QAAQ,EACb,KAAK,OAAO,EACZ,KAAK,iBAAiB,EACtB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACN,KAAK,OAAO,EACZ,KAAK,KAAK,EAMV,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,MAAM,MAAM,CAAC;AAOd,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,qBAAa,YAAa,SAAQ,OAAQ,YAAW,QAAQ;IAW3D,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAE7B,OAAO,CAAC,QAAQ,CAAC,KAAK;IAdvB;;;;;;;;OAQG;gBAEe,YAAY,EAAE,YAAY,EAC1B,YAAY,EAAE,YAAY,EAC1B,YAAY,EAAE,OAAO,EACtC,MAAM,EAAE,MAAM,EACG,KAAK,EAAE,KAAK;IAK9B;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACG,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAmExE;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACG,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM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