@0xmonaco/core 0.7.5 → 0.7.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.
- package/package.json +3 -3
- package/dist/api/applications/api.d.ts +0 -43
- package/dist/api/applications/api.js +0 -54
- package/dist/api/applications/index.d.ts +0 -4
- package/dist/api/applications/index.js +0 -4
- package/dist/api/auth/api.d.ts +0 -206
- package/dist/api/auth/api.js +0 -305
- package/dist/api/auth/index.d.ts +0 -4
- package/dist/api/auth/index.js +0 -4
- package/dist/api/base.d.ts +0 -123
- package/dist/api/base.js +0 -286
- package/dist/api/fees/api.d.ts +0 -72
- package/dist/api/fees/api.js +0 -90
- package/dist/api/fees/index.d.ts +0 -6
- package/dist/api/fees/index.js +0 -6
- package/dist/api/index.d.ts +0 -18
- package/dist/api/index.js +0 -18
- package/dist/api/margin-accounts/api.d.ts +0 -12
- package/dist/api/margin-accounts/api.js +0 -69
- package/dist/api/margin-accounts/index.d.ts +0 -1
- package/dist/api/margin-accounts/index.js +0 -1
- package/dist/api/market/api.d.ts +0 -20
- package/dist/api/market/api.js +0 -97
- package/dist/api/market/index.d.ts +0 -1
- package/dist/api/market/index.js +0 -1
- package/dist/api/orderbook/api.d.ts +0 -15
- package/dist/api/orderbook/api.js +0 -37
- package/dist/api/orderbook/index.d.ts +0 -1
- package/dist/api/orderbook/index.js +0 -1
- package/dist/api/perp/index.d.ts +0 -1
- package/dist/api/perp/index.js +0 -1
- package/dist/api/perp/routes.d.ts +0 -133
- package/dist/api/perp/routes.js +0 -85
- package/dist/api/positions/api.d.ts +0 -12
- package/dist/api/positions/api.js +0 -88
- package/dist/api/positions/index.d.ts +0 -1
- package/dist/api/positions/index.js +0 -1
- package/dist/api/profile/api.d.ts +0 -191
- package/dist/api/profile/api.js +0 -259
- package/dist/api/profile/index.d.ts +0 -6
- package/dist/api/profile/index.js +0 -6
- package/dist/api/trades/api.d.ts +0 -44
- package/dist/api/trades/api.js +0 -42
- package/dist/api/trades/index.d.ts +0 -1
- package/dist/api/trades/index.js +0 -1
- package/dist/api/trading/api.d.ts +0 -297
- package/dist/api/trading/api.js +0 -481
- package/dist/api/trading/index.d.ts +0 -4
- package/dist/api/trading/index.js +0 -4
- package/dist/api/vault/api.d.ts +0 -261
- package/dist/api/vault/api.js +0 -506
- package/dist/api/vault/index.d.ts +0 -4
- package/dist/api/vault/index.js +0 -4
- package/dist/api/websocket/index.d.ts +0 -3
- package/dist/api/websocket/index.js +0 -3
- package/dist/api/websocket/types.d.ts +0 -41
- package/dist/api/websocket/types.js +0 -0
- package/dist/api/websocket/utils.d.ts +0 -8
- package/dist/api/websocket/utils.js +0 -22
- package/dist/api/websocket/websocket.d.ts +0 -5
- package/dist/api/websocket/websocket.js +0 -556
- package/dist/errors/errors.d.ts +0 -381
- package/dist/errors/errors.js +0 -815
- package/dist/errors/index.d.ts +0 -1
- package/dist/errors/index.js +0 -1
- package/dist/index.d.ts +0 -5
- package/dist/index.js +0 -5
- package/dist/networks/index.d.ts +0 -1
- package/dist/networks/index.js +0 -1
- package/dist/networks/networks.d.ts +0 -21
- package/dist/networks/networks.js +0 -46
- package/dist/sdk.d.ts +0 -134
- package/dist/sdk.js +0 -294
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +0 -1
- package/dist/utils/magnitude.d.ts +0 -26
- package/dist/utils/magnitude.js +0 -31
package/dist/api/vault/api.d.ts
DELETED
|
@@ -1,261 +0,0 @@
|
|
|
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
|
-
* // Deposit tokens
|
|
22
|
-
* const result = await vaultAPI.deposit(tokenAddress, parseEther("100"));
|
|
23
|
-
* console.log(`Deposit transaction: ${result.hash}`);
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
import type { ApplicationsAPI, Balance, ProfileAPI, TransactionResult, VaultAPI, WithdrawResult } from "@0xmonaco/types";
|
|
27
|
-
import { type Address, type Chain, type PublicClient, type WalletClient } from "viem";
|
|
28
|
-
import { BaseAPI } from "../base";
|
|
29
|
-
export declare class VaultAPIImpl extends BaseAPI implements VaultAPI {
|
|
30
|
-
private readonly publicClient;
|
|
31
|
-
private readonly chain;
|
|
32
|
-
private applicationsAPI;
|
|
33
|
-
private profileAPI;
|
|
34
|
-
private walletClient;
|
|
35
|
-
/**
|
|
36
|
-
* Creates a new VaultAPI instance.
|
|
37
|
-
*
|
|
38
|
-
* @param publicClient - The viem public client for reading blockchain state
|
|
39
|
-
* @param walletClient - The viem wallet client for signing transactions (optional)
|
|
40
|
-
* @param chain - The blockchain network configuration
|
|
41
|
-
* @param applicationsAPI - The applications API instance for fetching vault address
|
|
42
|
-
* @param profileAPI - The profile API instance for fetching asset information
|
|
43
|
-
* @param apiUrl - The base URL for the Monaco API Gateway
|
|
44
|
-
*/
|
|
45
|
-
constructor(publicClient: PublicClient, walletClient: WalletClient | undefined, chain: Chain, applicationsAPI: ApplicationsAPI, profileAPI: ProfileAPI, apiUrl: string);
|
|
46
|
-
/**
|
|
47
|
-
* Sets the wallet client for signing transactions.
|
|
48
|
-
* Used when the wallet becomes available after SDK initialization.
|
|
49
|
-
*/
|
|
50
|
-
setWalletClient(walletClient: WalletClient): void;
|
|
51
|
-
/**
|
|
52
|
-
* Fetches the vault contract address from the applications API.
|
|
53
|
-
*
|
|
54
|
-
* @returns Promise resolving to the vault contract address
|
|
55
|
-
* @throws {APIError} When vault address cannot be retrieved
|
|
56
|
-
* @private
|
|
57
|
-
*/
|
|
58
|
-
getVaultAddress(): Promise<Address>;
|
|
59
|
-
/**
|
|
60
|
-
* Fetches the application's client ID from the applications API.
|
|
61
|
-
* The client ID is embedded in on-chain deposit calls so the indexer can
|
|
62
|
-
* attribute the deposit to the correct application.
|
|
63
|
-
*
|
|
64
|
-
* @returns Promise resolving to the application client ID
|
|
65
|
-
* @private
|
|
66
|
-
*/
|
|
67
|
-
private getClientId;
|
|
68
|
-
/**
|
|
69
|
-
* Resolves an asset ID to its token address and determines if it's a native token.
|
|
70
|
-
*
|
|
71
|
-
* @param assetId - The asset identifier (UUID) to resolve
|
|
72
|
-
* @returns Promise resolving to object with tokenAddress and isNativeToken flag
|
|
73
|
-
* @throws {ContractError} When asset ID cannot be resolved
|
|
74
|
-
* @private
|
|
75
|
-
*/
|
|
76
|
-
private resolveAsset;
|
|
77
|
-
/**
|
|
78
|
-
* Approves the vault contract to spend tokens on behalf of the user.
|
|
79
|
-
*
|
|
80
|
-
* This method creates and sends an ERC20 approve transaction to allow the vault
|
|
81
|
-
* to transfer tokens from the user's wallet. Approval is required before any
|
|
82
|
-
* deposit operations can be performed.
|
|
83
|
-
*
|
|
84
|
-
* @param assetId - The asset identifier (UUID) to approve
|
|
85
|
-
* @param amount - The maximum amount of tokens the vault can spend (as bigint)
|
|
86
|
-
* @param autoWait - Whether to automatically wait for transaction confirmation (defaults to true)
|
|
87
|
-
* @returns Promise resolving to TransactionResult with transaction details
|
|
88
|
-
* @throws {ContractError} When approval transaction fails or asset not found
|
|
89
|
-
* @throws {InvalidConfigError} When wallet account is not available
|
|
90
|
-
*
|
|
91
|
-
* @example
|
|
92
|
-
* ```typescript
|
|
93
|
-
* // Approve vault to spend up to 1000 USDC (auto-waits by default)
|
|
94
|
-
* const result = await vaultAPI.approve(
|
|
95
|
-
* "123e4567-e89b-12d3-a456-426614174000",
|
|
96
|
-
* parseUnits("1000", 6)
|
|
97
|
-
* );
|
|
98
|
-
* console.log(`Approval transaction: ${result.hash}`);
|
|
99
|
-
* console.log(`Status: ${result.status}`); // "confirmed" if successful
|
|
100
|
-
*
|
|
101
|
-
* // Or skip auto-waiting
|
|
102
|
-
* const result = await vaultAPI.approve(
|
|
103
|
-
* "123e4567-e89b-12d3-a456-426614174000",
|
|
104
|
-
* parseUnits("1000", 6),
|
|
105
|
-
* false
|
|
106
|
-
* );
|
|
107
|
-
* // Then manually wait later if needed
|
|
108
|
-
* const receipt = await sdk.waitForTransaction(result.hash);
|
|
109
|
-
* ```
|
|
110
|
-
*/
|
|
111
|
-
approve(assetId: string, amount: bigint, autoWait?: boolean): Promise<TransactionResult>;
|
|
112
|
-
/**
|
|
113
|
-
* Deposits tokens into the Monaco vault.
|
|
114
|
-
*
|
|
115
|
-
* Deposits the specified amount of tokens into the vault contract. The method
|
|
116
|
-
* first checks if sufficient approval exists, then obtains a signature from the
|
|
117
|
-
* API Gateway, and finally executes the deposit transaction on-chain.
|
|
118
|
-
*
|
|
119
|
-
* Note: This method requires prior approval via the `approve()` method.
|
|
120
|
-
*
|
|
121
|
-
* @param assetId - The asset identifier (UUID) to deposit
|
|
122
|
-
* @param amount - The amount of tokens to deposit (as bigint)
|
|
123
|
-
* @param autoWait - Whether to automatically wait for transaction confirmation (defaults to true)
|
|
124
|
-
* @returns Promise resolving to TransactionResult with transaction details
|
|
125
|
-
* @throws {ContractError} When deposit fails or approval is insufficient
|
|
126
|
-
* @throws {APIError} When the asset is not found or the assetId is invalid
|
|
127
|
-
* @throws {InvalidConfigError} When wallet account is not available
|
|
128
|
-
*
|
|
129
|
-
* @example
|
|
130
|
-
* ```typescript
|
|
131
|
-
* // Deposit 100 USDC into the vault (auto-waits by default)
|
|
132
|
-
* const result = await vaultAPI.deposit(
|
|
133
|
-
* "123e4567-e89b-12d3-a456-426614174000",
|
|
134
|
-
* parseUnits("100", 6)
|
|
135
|
-
* );
|
|
136
|
-
* console.log(`Deposit transaction: ${result.hash}`);
|
|
137
|
-
* console.log(`Status: ${result.status}`); // "confirmed" if successful
|
|
138
|
-
*
|
|
139
|
-
* // Or skip auto-waiting
|
|
140
|
-
* const result = await vaultAPI.deposit(
|
|
141
|
-
* "123e4567-e89b-12d3-a456-426614174000",
|
|
142
|
-
* parseUnits("100", 6),
|
|
143
|
-
* false
|
|
144
|
-
* );
|
|
145
|
-
* // Then manually wait later if needed
|
|
146
|
-
* const receipt = await sdk.waitForTransaction(result.hash);
|
|
147
|
-
* ```
|
|
148
|
-
*/
|
|
149
|
-
deposit(assetId: string, amount: bigint, autoWait?: boolean): Promise<TransactionResult>;
|
|
150
|
-
/**
|
|
151
|
-
* Initiates a withdrawal through the API Gateway and submits the resulting
|
|
152
|
-
* pre-signed calldata on-chain via the connected wallet.
|
|
153
|
-
*
|
|
154
|
-
* The gateway allocates a `withdrawalIndex` via the matching engine and returns
|
|
155
|
-
* ABI-encoded calldata for `executeSignedWithdrawal(...)` signed by the
|
|
156
|
-
* server-side `WITHDRAWAL_SIGNER`. The user's wallet pays gas to submit it,
|
|
157
|
-
* but the contract authenticates against the embedded signature — not the
|
|
158
|
-
* `msg.sender`. The connected wallet's address is sent as the on-chain
|
|
159
|
-
* `destination`.
|
|
160
|
-
*
|
|
161
|
-
* @param assetId - The asset identifier (UUID) to withdraw
|
|
162
|
-
* @param amount - The raw token amount to withdraw (as bigint)
|
|
163
|
-
* @param autoWait - Whether to automatically wait for transaction confirmation (defaults to true)
|
|
164
|
-
* @returns Promise resolving to `{ withdrawalIndex, transaction }`
|
|
165
|
-
* @throws {APIError} When the asset is not found or the request is rejected
|
|
166
|
-
* @throws {ContractError} When the on-chain submission fails
|
|
167
|
-
* @throws {InvalidConfigError} When wallet account is not available
|
|
168
|
-
*
|
|
169
|
-
* @example
|
|
170
|
-
* ```typescript
|
|
171
|
-
* // Withdraw 50 USDC, wait for on-chain confirmation
|
|
172
|
-
* const result = await vaultAPI.withdraw(
|
|
173
|
-
* "123e4567-e89b-12d3-a456-426614174000",
|
|
174
|
-
* parseUnits("50", 6),
|
|
175
|
-
* );
|
|
176
|
-
* console.log(`Withdrawal index: ${result.withdrawalIndex}`);
|
|
177
|
-
* console.log(`Tx hash: ${result.hash}, status: ${result.status}`);
|
|
178
|
-
*
|
|
179
|
-
* // Or skip auto-waiting and finalise later
|
|
180
|
-
* const result = await vaultAPI.withdraw(
|
|
181
|
-
* "123e4567-e89b-12d3-a456-426614174000",
|
|
182
|
-
* parseUnits("50", 6),
|
|
183
|
-
* false,
|
|
184
|
-
* );
|
|
185
|
-
* const receipt = await sdk.waitForTransaction(result.hash);
|
|
186
|
-
* ```
|
|
187
|
-
*/
|
|
188
|
-
withdraw(assetId: string, amount: bigint, autoWait?: boolean): Promise<WithdrawResult>;
|
|
189
|
-
/**
|
|
190
|
-
* Retries a previously-initiated withdrawal whose on-chain submission never
|
|
191
|
-
* landed — e.g. the wallet rejected the tx, the page reloaded before the
|
|
192
|
-
* receipt came back, or a stuck mempool entry needs resending.
|
|
193
|
-
*
|
|
194
|
-
* Re-fetches the same `executeSignedWithdrawal` calldata the gateway
|
|
195
|
-
* generated when the withdrawal was initiated, then submits it through the
|
|
196
|
-
* connected wallet. Does NOT initiate a new withdrawal — the matching engine
|
|
197
|
-
* already debited the balance and allocated the index. The contract is
|
|
198
|
-
* idempotent against double-submission of a settled withdrawal: it will
|
|
199
|
-
* revert once the index is consumed on-chain.
|
|
200
|
-
*
|
|
201
|
-
* @param withdrawalIndex - The index returned by the original `withdraw()` call
|
|
202
|
-
* @param autoWait - Whether to await on-chain confirmation (defaults to true)
|
|
203
|
-
* @returns Promise resolving to `{ withdrawalIndex, ...transaction }`
|
|
204
|
-
* @throws {APIError} When the index doesn't exist
|
|
205
|
-
* @throws {ContractError} When the on-chain submission fails
|
|
206
|
-
* @throws {InvalidConfigError} When wallet account is not available
|
|
207
|
-
*/
|
|
208
|
-
retryWithdrawal(withdrawalIndex: number, autoWait?: boolean): Promise<WithdrawResult>;
|
|
209
|
-
/**
|
|
210
|
-
* Retrieves the user's token balance in the vault.
|
|
211
|
-
*
|
|
212
|
-
* @param _assetId - The asset identifier (UUID) to check balance for
|
|
213
|
-
* @returns Promise that always rejects with deprecation error
|
|
214
|
-
* @throws {APIError} Always throws - this method is deprecated
|
|
215
|
-
* @deprecated Use `profileAPI.getUserBalances()` or `profileAPI.getUserBalanceByAssetId()` instead.
|
|
216
|
-
*/
|
|
217
|
-
getBalance(_assetId: string): Promise<Balance>;
|
|
218
|
-
/**
|
|
219
|
-
* Retrieves the current allowance for a token.
|
|
220
|
-
*
|
|
221
|
-
* Queries the ERC20 token contract to get the current allowance granted to the
|
|
222
|
-
* vault contract for spending tokens on behalf of the user.
|
|
223
|
-
*
|
|
224
|
-
* @param assetId - The asset identifier (UUID) to check allowance for
|
|
225
|
-
* @returns Promise resolving to the current allowance amount as bigint
|
|
226
|
-
* @throws {ContractError} When allowance retrieval fails or asset not found
|
|
227
|
-
*
|
|
228
|
-
* @example
|
|
229
|
-
* ```typescript
|
|
230
|
-
* const allowance = await vaultAPI.getAllowance("123e4567-e89b-12d3-a456-426614174000");
|
|
231
|
-
* console.log(`Current allowance: ${formatUnits(allowance, 6)} USDC`);
|
|
232
|
-
* ```
|
|
233
|
-
*/
|
|
234
|
-
getAllowance(assetId: string): Promise<bigint>;
|
|
235
|
-
/**
|
|
236
|
-
* Checks if approval is needed for a specific amount.
|
|
237
|
-
*
|
|
238
|
-
* Compares the current allowance with the requested amount to determine if
|
|
239
|
-
* the user needs to approve more tokens before performing operations.
|
|
240
|
-
*
|
|
241
|
-
* @param assetId - The asset identifier (UUID) to check for
|
|
242
|
-
* @param amount - The amount to check approval for (as bigint)
|
|
243
|
-
* @returns Promise resolving to true if approval is needed, false otherwise
|
|
244
|
-
* @throws {ContractError} When approval check fails or asset not found
|
|
245
|
-
*
|
|
246
|
-
* @example
|
|
247
|
-
* ```typescript
|
|
248
|
-
* const needsApproval = await vaultAPI.needsApproval(
|
|
249
|
-
* "123e4567-e89b-12d3-a456-426614174000",
|
|
250
|
-
* parseUnits("100", 6)
|
|
251
|
-
* );
|
|
252
|
-
*
|
|
253
|
-
* if (needsApproval) {
|
|
254
|
-
* console.log("Approval required before deposit");
|
|
255
|
-
* await vaultAPI.approve("123e4567-e89b-12d3-a456-426614174000", parseUnits("100", 6));
|
|
256
|
-
* }
|
|
257
|
-
* ```
|
|
258
|
-
*/
|
|
259
|
-
needsApproval(assetId: string, amount: bigint): Promise<boolean>;
|
|
260
|
-
private waitForTransaction;
|
|
261
|
-
}
|