@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,257 @@
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 { ApplicationsAPI, Balance, ProfileAPI, TransactionResult, VaultAPI } from "@0xmonaco/types";
31
+ import { type Address, type Chain, type PublicClient, type WalletClient } from "viem";
32
+ import { BaseAPI } from "../base";
33
+ export declare class VaultAPIImpl extends BaseAPI implements VaultAPI {
34
+ private readonly publicClient;
35
+ private readonly walletClient;
36
+ private readonly chain;
37
+ private applicationsAPI;
38
+ private profileAPI;
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 chain - The blockchain network configuration
45
+ * @param applicationsAPI - The applications API instance for fetching vault address
46
+ * @param profileAPI - The profile API instance for fetching asset information
47
+ * @param apiUrl - The base URL for the Monaco API Gateway
48
+ */
49
+ constructor(publicClient: PublicClient, walletClient: WalletClient, chain: Chain, applicationsAPI: ApplicationsAPI, profileAPI: ProfileAPI, 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
+ * Approves the vault contract to spend tokens on behalf of the user.
60
+ *
61
+ * This method creates and sends an ERC20 approve transaction to allow the vault
62
+ * to transfer tokens from the user's wallet. Approval is required before any
63
+ * deposit operations can be performed.
64
+ *
65
+ * @param assetId - The asset identifier (UUID) to approve
66
+ * @param amount - The maximum amount of tokens the vault can spend (as bigint)
67
+ * @param autoWait - Whether to automatically wait for transaction confirmation (defaults to true)
68
+ * @returns Promise resolving to TransactionResult with transaction details
69
+ * @throws {ContractError} When approval transaction fails or asset not found
70
+ * @throws {InvalidConfigError} When wallet account is not available
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * // Approve vault to spend up to 1000 USDC (auto-waits by default)
75
+ * const result = await vaultAPI.approve(
76
+ * "123e4567-e89b-12d3-a456-426614174000",
77
+ * parseUnits("1000", 6)
78
+ * );
79
+ * console.log(`Approval transaction: ${result.hash}`);
80
+ * console.log(`Status: ${result.status}`); // "confirmed" if successful
81
+ *
82
+ * // Or skip auto-waiting
83
+ * const result = await vaultAPI.approve(
84
+ * "123e4567-e89b-12d3-a456-426614174000",
85
+ * parseUnits("1000", 6),
86
+ * false
87
+ * );
88
+ * // Then manually wait later if needed
89
+ * const receipt = await sdk.waitForTransaction(result.hash);
90
+ * ```
91
+ */
92
+ approve(assetId: string, amount: bigint, autoWait?: boolean): Promise<TransactionResult>;
93
+ /**
94
+ * Deposits tokens into the Monaco vault.
95
+ *
96
+ * Deposits the specified amount of tokens into the vault contract. The method
97
+ * first checks if sufficient approval exists, then obtains a signature from the
98
+ * API Gateway, and finally executes the deposit transaction on-chain.
99
+ *
100
+ * Note: This method requires prior approval via the approve() method.
101
+ *
102
+ * @param assetId - The asset identifier (UUID) to deposit
103
+ * @param amount - The amount of tokens to deposit (as bigint)
104
+ * @param autoWait - Whether to automatically wait for transaction confirmation (defaults to true)
105
+ * @returns Promise resolving to TransactionResult with transaction details
106
+ * @throws {ContractError} When deposit fails or approval is insufficient
107
+ * @throws {APIError} When the asset is not found or the assetId is invalid
108
+ * @throws {InvalidConfigError} When wallet account is not available
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * // Deposit 100 USDC into the vault (auto-waits by default)
113
+ * const result = await vaultAPI.deposit(
114
+ * "123e4567-e89b-12d3-a456-426614174000",
115
+ * parseUnits("100", 6)
116
+ * );
117
+ * console.log(`Deposit transaction: ${result.hash}`);
118
+ * console.log(`Status: ${result.status}`); // "confirmed" if successful
119
+ *
120
+ * // Or skip auto-waiting
121
+ * const result = await vaultAPI.deposit(
122
+ * "123e4567-e89b-12d3-a456-426614174000",
123
+ * parseUnits("100", 6),
124
+ * false
125
+ * );
126
+ * // Then manually wait later if needed
127
+ * const receipt = await sdk.waitForTransaction(result.hash);
128
+ * ```
129
+ */
130
+ deposit(assetId: string, amount: bigint, autoWait?: boolean): Promise<TransactionResult>;
131
+ /**
132
+ * Withdraws tokens from the Monaco vault.
133
+ *
134
+ * Withdraws the specified amount of tokens from the vault contract back to the
135
+ * user's wallet. The method obtains a signature from the API Gateway and then
136
+ * executes the withdrawal transaction on-chain.
137
+ *
138
+ * @param assetId - The asset identifier (UUID) to withdraw
139
+ * @param amount - The amount of tokens to withdraw (as bigint)
140
+ * @param autoWait - Whether to automatically wait for transaction confirmation (defaults to true)
141
+ * @returns Promise resolving to TransactionResult with transaction details
142
+ * @throws {ContractError} When withdrawal fails
143
+ * @throws {APIError} When signature retrieval fails or the asset is not found/assetId is invalid
144
+ * @throws {InvalidConfigError} When wallet account is not available
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * // Withdraw 50 USDC from the vault (auto-waits by default)
149
+ * const result = await vaultAPI.withdraw(
150
+ * "123e4567-e89b-12d3-a456-426614174000",
151
+ * parseUnits("50", 6)
152
+ * );
153
+ * console.log(`Withdrawal transaction: ${result.hash}`);
154
+ * console.log(`Status: ${result.status}`); // "confirmed" if successful
155
+ *
156
+ * // Or skip auto-waiting
157
+ * const result = await vaultAPI.withdraw(
158
+ * "123e4567-e89b-12d3-a456-426614174000",
159
+ * parseUnits("50", 6),
160
+ * false
161
+ * );
162
+ * // Then manually wait later if needed
163
+ * const receipt = await sdk.waitForTransaction(result.hash);
164
+ * ```
165
+ */
166
+ withdraw(assetId: string, amount: bigint, autoWait?: boolean): Promise<TransactionResult>;
167
+ /**
168
+ * Retrieves the user's token balance in the vault.
169
+ *
170
+ * Queries the vault contract to get the current balance of a specific token
171
+ * for the connected wallet. Returns both raw amount and formatted display values.
172
+ *
173
+ * @param assetId - The asset identifier (UUID) to check balance for
174
+ * @returns Promise resolving to Balance with token balance details
175
+ * @throws {ContractError} When balance retrieval fails or asset not found
176
+ *
177
+ * @example
178
+ * ```typescript
179
+ * const balance = await vaultAPI.getBalance("123e4567-e89b-12d3-a456-426614174000");
180
+ * console.log(`Vault balance: ${balance.formatted} ${balance.symbol}`);
181
+ * console.log(`Raw amount: ${balance.amount}`);
182
+ * ```
183
+ */
184
+ getBalance(assetId: string): Promise<Balance>;
185
+ /**
186
+ * Retrieves the current allowance for a token.
187
+ *
188
+ * Queries the ERC20 token contract to get the current allowance granted to the
189
+ * vault contract for spending tokens on behalf of the user.
190
+ *
191
+ * @param assetId - The asset identifier (UUID) to check allowance for
192
+ * @returns Promise resolving to the current allowance amount as bigint
193
+ * @throws {ContractError} When allowance retrieval fails or asset not found
194
+ *
195
+ * @example
196
+ * ```typescript
197
+ * const allowance = await vaultAPI.getAllowance("123e4567-e89b-12d3-a456-426614174000");
198
+ * console.log(`Current allowance: ${formatUnits(allowance, 6)} USDC`);
199
+ * ```
200
+ */
201
+ getAllowance(assetId: string): Promise<bigint>;
202
+ /**
203
+ * Checks if approval is needed for a specific amount.
204
+ *
205
+ * Compares the current allowance with the requested amount to determine if
206
+ * the user needs to approve more tokens before performing operations.
207
+ *
208
+ * @param assetId - The asset identifier (UUID) to check for
209
+ * @param amount - The amount to check approval for (as bigint)
210
+ * @returns Promise resolving to true if approval is needed, false otherwise
211
+ * @throws {ContractError} When approval check fails or asset not found
212
+ *
213
+ * @example
214
+ * ```typescript
215
+ * const needsApproval = await vaultAPI.needsApproval(
216
+ * "123e4567-e89b-12d3-a456-426614174000",
217
+ * parseUnits("100", 6)
218
+ * );
219
+ *
220
+ * if (needsApproval) {
221
+ * console.log("Approval required before deposit");
222
+ * await vaultAPI.approve("123e4567-e89b-12d3-a456-426614174000", parseUnits("100", 6));
223
+ * }
224
+ * ```
225
+ */
226
+ needsApproval(assetId: string, amount: bigint): Promise<boolean>;
227
+ /**
228
+ * Retrieves a deposit signature from the API Gateway.
229
+ *
230
+ * Internal method that communicates with the Monaco API Gateway to obtain
231
+ * the cryptographic signature required for deposit transactions. The signature
232
+ * validates the deposit request and ensures proper authorization.
233
+ *
234
+ * @param assetId - The asset identifier (UUID) to deposit
235
+ * @param amount - The amount to deposit (as bigint)
236
+ * @returns Promise resolving to object containing seed and signature
237
+ * @throws {APIError} When signature retrieval fails
238
+ * @private
239
+ */
240
+ private getDepositSignature;
241
+ /**
242
+ * Retrieves a withdrawal signature from the API Gateway.
243
+ *
244
+ * Internal method that communicates with the Monaco API Gateway to obtain
245
+ * the cryptographic signature required for withdrawal transactions. The signature
246
+ * validates the withdrawal request and ensures proper authorization.
247
+ *
248
+ * @param assetId - The asset identifier (UUID) to withdraw
249
+ * @param amount - The amount to withdraw (as bigint)
250
+ * @returns Promise resolving to object containing seed and signature
251
+ * @throws {APIError} When signature retrieval fails
252
+ * @private
253
+ */
254
+ private getWithdrawSignature;
255
+ private waitForTransaction;
256
+ }
257
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {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