@0xmonaco/core 0.8.7-develop.34bd452 → 0.8.7-develop.a107b34
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/README.md +3 -12
- package/dist/api/applications/api.d.ts +61 -8
- package/dist/api/applications/api.js +71 -7
- package/dist/api/auth/api.d.ts +7 -26
- package/dist/api/auth/api.js +6 -42
- package/dist/api/base.d.ts +35 -0
- package/dist/api/base.js +60 -0
- package/dist/api/delegated-agents/api.d.ts +2 -1
- package/dist/api/delegated-agents/api.js +4 -0
- package/dist/api/faucet/api.d.ts +25 -0
- package/dist/api/faucet/api.js +29 -0
- package/dist/api/faucet/index.d.ts +1 -0
- package/dist/api/faucet/index.js +1 -0
- package/dist/api/index.d.ts +4 -0
- package/dist/api/index.js +4 -0
- package/dist/api/margin-accounts/api.d.ts +9 -5
- package/dist/api/margin-accounts/api.js +57 -20
- package/dist/api/market/api.d.ts +5 -2
- package/dist/api/market/api.js +19 -3
- package/dist/api/perp/routes.d.ts +78 -6
- package/dist/api/perp/routes.js +36 -6
- package/dist/api/positions/api.d.ts +2 -1
- package/dist/api/positions/api.js +13 -1
- package/dist/api/profile/api.d.ts +18 -1
- package/dist/api/profile/api.js +41 -1
- package/dist/api/sub-accounts/api.d.ts +62 -0
- package/dist/api/sub-accounts/api.js +80 -0
- package/dist/api/sub-accounts/index.d.ts +1 -0
- package/dist/api/sub-accounts/index.js +1 -0
- package/dist/api/trades/api.d.ts +12 -1
- package/dist/api/trades/api.js +13 -1
- package/dist/api/trading/api.d.ts +5 -2
- package/dist/api/trading/api.js +7 -24
- package/dist/api/vault/api.d.ts +70 -26
- package/dist/api/vault/api.js +124 -39
- package/dist/api/vault/index.d.ts +1 -1
- package/dist/api/vault/index.js +1 -1
- package/dist/api/whitelist/api.d.ts +27 -0
- package/dist/api/whitelist/api.js +32 -0
- package/dist/api/whitelist/index.d.ts +1 -0
- package/dist/api/whitelist/index.js +1 -0
- package/dist/api/withdrawals/api.d.ts +17 -0
- package/dist/api/withdrawals/api.js +30 -0
- package/dist/api/withdrawals/index.d.ts +1 -0
- package/dist/api/withdrawals/index.js +1 -0
- package/dist/coverage.d.ts +92 -0
- package/dist/coverage.js +92 -0
- package/dist/sdk.d.ts +32 -1
- package/dist/sdk.js +88 -0
- package/package.json +3 -3
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sub-Accounts API Implementation
|
|
3
|
+
*
|
|
4
|
+
* Manage a master account's sub-accounts and their per-asset spending limits.
|
|
5
|
+
* All methods are session-authenticated. The limit mutations (`createLimit`,
|
|
6
|
+
* `updateLimit`, `deleteLimit`) additionally require the master account to hold
|
|
7
|
+
* the `ManageSubAccounts` permission — enforced server-side, so a non-master or
|
|
8
|
+
* unpermissioned caller receives a 403.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const { sub_accounts } = await sdk.subAccounts.list();
|
|
13
|
+
* await sdk.subAccounts.createLimit({ sub_account_id, asset_id, max_amount: "1000.00" });
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
import { BaseAPI } from "../base";
|
|
17
|
+
import { perpRoutes } from "../perp/routes";
|
|
18
|
+
export class SubAccountsAPIImpl extends BaseAPI {
|
|
19
|
+
/**
|
|
20
|
+
* Lists the authenticated master account's sub-accounts with balances.
|
|
21
|
+
*
|
|
22
|
+
* @returns Promise resolving to the sub-accounts and total count
|
|
23
|
+
*/
|
|
24
|
+
async list() {
|
|
25
|
+
return await this.makeAuthenticatedRequest(perpRoutes.subAccounts.list());
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Creates a per-asset spending limit on a sub-account.
|
|
29
|
+
*
|
|
30
|
+
* Requires the `ManageSubAccounts` permission (enforced server-side).
|
|
31
|
+
*
|
|
32
|
+
* @param body - Sub-account, asset, max amount, and optional daily limit
|
|
33
|
+
* @returns Promise resolving to the created limit
|
|
34
|
+
*/
|
|
35
|
+
async createLimit(body) {
|
|
36
|
+
return await this.makeAuthenticatedRequest(perpRoutes.subAccounts.createLimit(), {
|
|
37
|
+
method: "POST",
|
|
38
|
+
body: JSON.stringify(body),
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Gets the limits configured for a sub-account.
|
|
43
|
+
*
|
|
44
|
+
* @param subAccountId - Sub-account UUID
|
|
45
|
+
* @returns Promise resolving to the sub-account's limits
|
|
46
|
+
*/
|
|
47
|
+
async getLimits(subAccountId) {
|
|
48
|
+
return await this.makeAuthenticatedRequest(perpRoutes.subAccounts.getLimits(subAccountId));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Updates a sub-account's per-asset limit (partial update).
|
|
52
|
+
*
|
|
53
|
+
* Requires the `ManageSubAccounts` permission (enforced server-side).
|
|
54
|
+
*
|
|
55
|
+
* @param subAccountId - Sub-account UUID
|
|
56
|
+
* @param assetId - Asset UUID
|
|
57
|
+
* @param body - Fields to update
|
|
58
|
+
* @returns Promise resolving to the updated limit
|
|
59
|
+
*/
|
|
60
|
+
async updateLimit(subAccountId, assetId, body) {
|
|
61
|
+
return await this.makeAuthenticatedRequest(perpRoutes.subAccounts.limit(subAccountId, assetId), {
|
|
62
|
+
method: "PUT",
|
|
63
|
+
body: JSON.stringify(body),
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Deletes a sub-account's per-asset limit.
|
|
68
|
+
*
|
|
69
|
+
* Requires the `ManageSubAccounts` permission (enforced server-side).
|
|
70
|
+
*
|
|
71
|
+
* @param subAccountId - Sub-account UUID
|
|
72
|
+
* @param assetId - Asset UUID
|
|
73
|
+
* @returns Promise resolving when the limit is deleted
|
|
74
|
+
*/
|
|
75
|
+
async deleteLimit(subAccountId, assetId) {
|
|
76
|
+
await this.makeAuthenticatedRequest(perpRoutes.subAccounts.limit(subAccountId, assetId), {
|
|
77
|
+
method: "DELETE",
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SubAccountsAPIImpl } from "./api";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SubAccountsAPIImpl } from "./api";
|
package/dist/api/trades/api.d.ts
CHANGED
|
@@ -11,8 +11,11 @@ interface RawTradeEvent {
|
|
|
11
11
|
trade_id: string;
|
|
12
12
|
price: string;
|
|
13
13
|
quantity: string;
|
|
14
|
+
/** Raw (integer) quantity; present on single-trade lookups, ignored when mapping */
|
|
15
|
+
quantity_raw?: string;
|
|
14
16
|
maker_side: string;
|
|
15
|
-
|
|
17
|
+
/** Absent when the trade has no recorded execution time */
|
|
18
|
+
executed_at?: string;
|
|
16
19
|
};
|
|
17
20
|
}
|
|
18
21
|
/**
|
|
@@ -40,5 +43,13 @@ export declare class TradesAPIImpl extends BaseAPI {
|
|
|
40
43
|
* @returns Array of TradeEvent records sorted by executed_at descending (newest first)
|
|
41
44
|
*/
|
|
42
45
|
getTrades(tradingPairId: string, options?: GetTradesOptions): Promise<TradeEvent[]>;
|
|
46
|
+
/**
|
|
47
|
+
* Get a single trade by its UUID.
|
|
48
|
+
*
|
|
49
|
+
* @param tradeId - The trade UUID
|
|
50
|
+
* @returns The matching TradeEvent
|
|
51
|
+
* @throws {APIError} If the trade is not found
|
|
52
|
+
*/
|
|
53
|
+
getTradeById(tradeId: string): Promise<TradeEvent>;
|
|
43
54
|
}
|
|
44
55
|
export {};
|
package/dist/api/trades/api.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BaseAPI } from "../base";
|
|
2
|
+
import { perpRoutes } from "../perp";
|
|
2
3
|
/**
|
|
3
4
|
* Convert a raw trade event (snake_case) to a TradeEvent (camelCase)
|
|
4
5
|
*/
|
|
@@ -12,7 +13,7 @@ export function parseRawTradeEvent(raw) {
|
|
|
12
13
|
price: raw.data.price,
|
|
13
14
|
quantity: raw.data.quantity,
|
|
14
15
|
makerSide: raw.data.maker_side.toUpperCase(),
|
|
15
|
-
executedAt: raw.data.executed_at,
|
|
16
|
+
executedAt: raw.data.executed_at ?? "",
|
|
16
17
|
},
|
|
17
18
|
};
|
|
18
19
|
}
|
|
@@ -39,4 +40,15 @@ export class TradesAPIImpl extends BaseAPI {
|
|
|
39
40
|
const response = await this.makePublicRequest(`/api/v1/trades/${encodeURIComponent(tradingPairId)}?${params.toString()}`);
|
|
40
41
|
return response.trades.map(parseRawTradeEvent);
|
|
41
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Get a single trade by its UUID.
|
|
45
|
+
*
|
|
46
|
+
* @param tradeId - The trade UUID
|
|
47
|
+
* @returns The matching TradeEvent
|
|
48
|
+
* @throws {APIError} If the trade is not found
|
|
49
|
+
*/
|
|
50
|
+
async getTradeById(tradeId) {
|
|
51
|
+
const response = await this.makePublicRequest(perpRoutes.trades.byId(tradeId));
|
|
52
|
+
return parseRawTradeEvent(response);
|
|
53
|
+
}
|
|
42
54
|
}
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* );
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
|
-
import type { BatchCancelOrdersResponse, BatchCreateOrderParams, BatchCreateOrdersResponse, BatchReplaceOrderParams, BatchReplaceOrdersResponse, CancelConditionalOrderResponse, CancelOrderResponse,
|
|
24
|
+
import type { BatchCancelOrdersResponse, BatchCreateOrderParams, BatchCreateOrdersResponse, BatchReplaceOrderParams, BatchReplaceOrdersResponse, CancelConditionalOrderResponse, CancelOrderResponse, CreateOrderResponse, GetOrderResponse, GetPaginatedOrdersParams, GetPaginatedOrdersResponse, ListConditionalOrdersParams, ListConditionalOrdersResponse, OrderSide, ParentTpSlLegParams, PositionSide, ReplaceOrderResponse, TimeInForce, TradingAPI, TradingMode } from "@0xmonaco/types";
|
|
25
25
|
import { BaseAPI } from "../base";
|
|
26
26
|
export declare class TradingAPIImpl extends BaseAPI implements TradingAPI {
|
|
27
27
|
/**
|
|
@@ -80,6 +80,8 @@ export declare class TradingAPIImpl extends BaseAPI implements TradingAPI {
|
|
|
80
80
|
expirationDate?: string;
|
|
81
81
|
timeInForce?: TimeInForce;
|
|
82
82
|
marginAccountId?: string;
|
|
83
|
+
riskBucketId?: string;
|
|
84
|
+
riskBucketCollateral?: string;
|
|
83
85
|
strategyKey?: string;
|
|
84
86
|
positionSide?: PositionSide;
|
|
85
87
|
leverage?: string;
|
|
@@ -132,6 +134,8 @@ export declare class TradingAPIImpl extends BaseAPI implements TradingAPI {
|
|
|
132
134
|
tradingMode?: TradingMode;
|
|
133
135
|
slippageTolerance?: number;
|
|
134
136
|
marginAccountId?: string;
|
|
137
|
+
riskBucketId?: string;
|
|
138
|
+
riskBucketCollateral?: string;
|
|
135
139
|
strategyKey?: string;
|
|
136
140
|
positionSide?: PositionSide;
|
|
137
141
|
leverage?: string;
|
|
@@ -156,7 +160,6 @@ export declare class TradingAPIImpl extends BaseAPI implements TradingAPI {
|
|
|
156
160
|
* ```
|
|
157
161
|
*/
|
|
158
162
|
cancelOrder(orderId: string): Promise<CancelOrderResponse>;
|
|
159
|
-
createConditionalOrder(params: CreateConditionalOrderParams): Promise<CreateConditionalOrderResponse>;
|
|
160
163
|
cancelConditionalOrder(conditionalOrderId: string): Promise<CancelConditionalOrderResponse>;
|
|
161
164
|
listConditionalOrders(params?: ListConditionalOrdersParams): Promise<ListConditionalOrdersResponse>;
|
|
162
165
|
/**
|
package/dist/api/trading/api.js
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* );
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
|
-
import { BatchCreateOrdersSchema, BatchReplaceOrdersSchema, CancelConditionalOrderSchema, CancelOrderSchema,
|
|
24
|
+
import { BatchCreateOrdersSchema, BatchReplaceOrdersSchema, CancelConditionalOrderSchema, CancelOrderSchema, GetPaginatedOrdersSchema, ListConditionalOrdersSchema, PlaceLimitOrderSchema, PlaceMarketOrderSchema, ReplaceOrderSchema, validate, } from "@0xmonaco/types";
|
|
25
25
|
import { BaseAPI } from "../base";
|
|
26
26
|
import { perpRoutes } from "../perp";
|
|
27
27
|
function parentTpSlLegToRequest(leg) {
|
|
@@ -107,6 +107,8 @@ export class TradingAPIImpl extends BaseAPI {
|
|
|
107
107
|
expiration_date: options?.expirationDate,
|
|
108
108
|
time_in_force: options?.timeInForce,
|
|
109
109
|
margin_account_id: options?.marginAccountId,
|
|
110
|
+
risk_bucket_id: options?.riskBucketId,
|
|
111
|
+
risk_bucket_collateral: options?.riskBucketCollateral,
|
|
110
112
|
strategy_key: options?.strategyKey,
|
|
111
113
|
position_side: options?.positionSide,
|
|
112
114
|
leverage: options?.leverage,
|
|
@@ -177,6 +179,8 @@ export class TradingAPIImpl extends BaseAPI {
|
|
|
177
179
|
quantity,
|
|
178
180
|
trading_mode: options?.tradingMode || "SPOT",
|
|
179
181
|
margin_account_id: options?.marginAccountId,
|
|
182
|
+
risk_bucket_id: options?.riskBucketId,
|
|
183
|
+
risk_bucket_collateral: options?.riskBucketCollateral,
|
|
180
184
|
strategy_key: options?.strategyKey,
|
|
181
185
|
position_side: options?.positionSide,
|
|
182
186
|
leverage: options?.leverage,
|
|
@@ -216,29 +220,6 @@ export class TradingAPIImpl extends BaseAPI {
|
|
|
216
220
|
body: JSON.stringify(requestBody),
|
|
217
221
|
});
|
|
218
222
|
}
|
|
219
|
-
async createConditionalOrder(params) {
|
|
220
|
-
validate(CreateConditionalOrderSchema, params);
|
|
221
|
-
const requestBody = {
|
|
222
|
-
trading_pair_id: params.tradingPairId,
|
|
223
|
-
margin_account_id: params.marginAccountId,
|
|
224
|
-
condition_type: params.conditionType,
|
|
225
|
-
trigger_price: params.triggerPrice,
|
|
226
|
-
trigger_source: params.triggerSource ?? "MARK_PRICE",
|
|
227
|
-
side: params.side,
|
|
228
|
-
position_side: params.positionSide,
|
|
229
|
-
order_type: params.orderType,
|
|
230
|
-
limit_price: params.limitPrice,
|
|
231
|
-
quantity: params.quantity,
|
|
232
|
-
reduce_only: params.reduceOnly ?? true,
|
|
233
|
-
time_in_force: params.timeInForce,
|
|
234
|
-
slippage_tolerance_bps: params.slippageToleranceBps,
|
|
235
|
-
expires_at: params.expiresAt,
|
|
236
|
-
};
|
|
237
|
-
return await this.makeAuthenticatedRequest(perpRoutes.orders.createConditional(), {
|
|
238
|
-
method: "POST",
|
|
239
|
-
body: JSON.stringify(requestBody),
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
223
|
async cancelConditionalOrder(conditionalOrderId) {
|
|
243
224
|
validate(CancelConditionalOrderSchema, { conditionalOrderId });
|
|
244
225
|
return await this.makeAuthenticatedRequest(perpRoutes.orders.cancelConditional(conditionalOrderId), {
|
|
@@ -363,6 +344,8 @@ export class TradingAPIImpl extends BaseAPI {
|
|
|
363
344
|
expiration_date: order.expirationDate,
|
|
364
345
|
time_in_force: order.timeInForce,
|
|
365
346
|
margin_account_id: order.marginAccountId,
|
|
347
|
+
risk_bucket_id: order.riskBucketId,
|
|
348
|
+
risk_bucket_collateral: order.riskBucketCollateral,
|
|
366
349
|
strategy_key: order.strategyKey,
|
|
367
350
|
position_side: order.positionSide,
|
|
368
351
|
leverage: order.leverage,
|
package/dist/api/vault/api.d.ts
CHANGED
|
@@ -23,9 +23,21 @@
|
|
|
23
23
|
* console.log(`Deposit transaction: ${result.hash}`);
|
|
24
24
|
* ```
|
|
25
25
|
*/
|
|
26
|
-
import type { ApplicationsAPI, Balance, ProfileAPI, TransactionResult, VaultAPI, WithdrawResult } from "@0xmonaco/types";
|
|
26
|
+
import type { ApplicationsAPI, Balance, DepositTarget, ProfileAPI, TransactionResult, VaultAPI, WithdrawalRetryOptions, WithdrawalSource, WithdrawResult } from "@0xmonaco/types";
|
|
27
27
|
import { type Address, type Chain, type PublicClient, type WalletClient } from "viem";
|
|
28
28
|
import { BaseAPI } from "../base";
|
|
29
|
+
/**
|
|
30
|
+
* Encode the on-chain `applicationData` for a deposit.
|
|
31
|
+
*
|
|
32
|
+
* For `"spot"` (the default) this stays the bare `clientId` string — byte-for-byte
|
|
33
|
+
* identical to the legacy encoding, so existing deposits are unchanged. For
|
|
34
|
+
* `"margin"` it emits a small JSON routing hint the indexer decodes to credit the
|
|
35
|
+
* deposit to margin collateral.
|
|
36
|
+
*
|
|
37
|
+
* MUST stay in sync with the indexer decoder in
|
|
38
|
+
* `indexer/src/listeners/deposit_routing.rs`.
|
|
39
|
+
*/
|
|
40
|
+
export declare function encodeDepositApplicationData(clientId: string, target: DepositTarget): string;
|
|
29
41
|
export declare class VaultAPIImpl extends BaseAPI implements VaultAPI {
|
|
30
42
|
private readonly publicClient;
|
|
31
43
|
private readonly chain;
|
|
@@ -121,6 +133,10 @@ export declare class VaultAPIImpl extends BaseAPI implements VaultAPI {
|
|
|
121
133
|
* @param assetId - The asset identifier (UUID) to deposit
|
|
122
134
|
* @param amount - The amount of tokens to deposit (as bigint)
|
|
123
135
|
* @param autoWait - Whether to automatically wait for transaction confirmation (defaults to true)
|
|
136
|
+
* @param target - Destination ledger: `"spot"` (default) credits the spot
|
|
137
|
+
* wallet; `"margin"` routes the deposit into the parent margin account's
|
|
138
|
+
* collateral (auto-creating the account if needed). Margin deposits that
|
|
139
|
+
* cannot be routed safely fall back to spot.
|
|
124
140
|
* @returns Promise resolving to TransactionResult with transaction details
|
|
125
141
|
* @throws {ContractError} When deposit fails or approval is insufficient
|
|
126
142
|
* @throws {APIError} When the asset is not found or the assetId is invalid
|
|
@@ -136,6 +152,14 @@ export declare class VaultAPIImpl extends BaseAPI implements VaultAPI {
|
|
|
136
152
|
* console.log(`Deposit transaction: ${result.hash}`);
|
|
137
153
|
* console.log(`Status: ${result.status}`); // "confirmed" if successful
|
|
138
154
|
*
|
|
155
|
+
* // Deposit straight into margin collateral
|
|
156
|
+
* const marginDeposit = await vaultAPI.deposit(
|
|
157
|
+
* "123e4567-e89b-12d3-a456-426614174000",
|
|
158
|
+
* parseUnits("100", 6),
|
|
159
|
+
* true,
|
|
160
|
+
* "margin"
|
|
161
|
+
* );
|
|
162
|
+
*
|
|
139
163
|
* // Or skip auto-waiting
|
|
140
164
|
* const result = await vaultAPI.deposit(
|
|
141
165
|
* "123e4567-e89b-12d3-a456-426614174000",
|
|
@@ -146,23 +170,41 @@ export declare class VaultAPIImpl extends BaseAPI implements VaultAPI {
|
|
|
146
170
|
* const receipt = await sdk.waitForTransaction(result.hash);
|
|
147
171
|
* ```
|
|
148
172
|
*/
|
|
149
|
-
deposit(assetId: string, amount: bigint, autoWait?: boolean): Promise<TransactionResult>;
|
|
173
|
+
deposit(assetId: string, amount: bigint, autoWait?: boolean, target?: DepositTarget): Promise<TransactionResult>;
|
|
174
|
+
/**
|
|
175
|
+
* Polls `GET /api/v1/withdrawals/{index}` until the gateway can serve the
|
|
176
|
+
* `executeWithdrawal` calldata, then returns it with the vault address.
|
|
177
|
+
*
|
|
178
|
+
* The calldata only exists once the withdrawal's root is confirmed on-chain
|
|
179
|
+
* and its merkle proof is persisted. Until then the gateway returns 404 (the
|
|
180
|
+
* row is written asynchronously by the persistor after `initiate`) or 409
|
|
181
|
+
* (the proof is not confirmed yet); both are transient for a freshly-allocated
|
|
182
|
+
* index, so we retry on each until ready or the timeout elapses.
|
|
183
|
+
*
|
|
184
|
+
* @throws {APIError} On non-transient errors, or when the timeout elapses
|
|
185
|
+
* before the proof is available.
|
|
186
|
+
*/
|
|
187
|
+
private pollWithdrawalCalldata;
|
|
150
188
|
/**
|
|
151
|
-
* Initiates a withdrawal through the API Gateway
|
|
152
|
-
*
|
|
189
|
+
* Initiates a withdrawal through the API Gateway, waits for its on-chain
|
|
190
|
+
* confirmation, then submits the resulting `executeWithdrawal` calldata via
|
|
191
|
+
* the connected wallet.
|
|
153
192
|
*
|
|
154
|
-
* The gateway allocates a `withdrawalIndex` via the matching engine and
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
193
|
+
* The gateway allocates a `withdrawalIndex` via the matching engine and debits
|
|
194
|
+
* the balance immediately, but the executable calldata needs the withdrawal's
|
|
195
|
+
* merkle proof, which only exists once its root is confirmed on-chain. This
|
|
196
|
+
* method polls until the calldata is available (see `retry`), then submits it.
|
|
197
|
+
* The connected wallet pays gas; the contract authorises the withdrawal
|
|
198
|
+
* against the merkle proof embedded in the calldata. The wallet's address is
|
|
199
|
+
* sent as the on-chain `destination`.
|
|
160
200
|
*
|
|
161
201
|
* @param assetId - The asset identifier (UUID) to withdraw
|
|
162
202
|
* @param amount - The raw token amount to withdraw (as bigint)
|
|
163
203
|
* @param autoWait - Whether to automatically wait for transaction confirmation (defaults to true)
|
|
204
|
+
* @param sourceOrRetry - Source ledger (`"spot"` or `"margin"`) or legacy retry options
|
|
205
|
+
* @param retry - Polling cadence/timeout while waiting for the proof when a source is supplied
|
|
164
206
|
* @returns Promise resolving to `{ withdrawalIndex, transaction }`
|
|
165
|
-
* @throws {APIError} When the asset is not found
|
|
207
|
+
* @throws {APIError} When the asset is not found, the request is rejected, or the proof never becomes available within the timeout
|
|
166
208
|
* @throws {ContractError} When the on-chain submission fails
|
|
167
209
|
* @throws {InvalidConfigError} When wallet account is not available
|
|
168
210
|
*
|
|
@@ -176,36 +218,38 @@ export declare class VaultAPIImpl extends BaseAPI implements VaultAPI {
|
|
|
176
218
|
* console.log(`Withdrawal index: ${result.withdrawalIndex}`);
|
|
177
219
|
* console.log(`Tx hash: ${result.hash}, status: ${result.status}`);
|
|
178
220
|
*
|
|
179
|
-
* //
|
|
221
|
+
* // Custom polling (check every 10s, wait up to an hour)
|
|
180
222
|
* const result = await vaultAPI.withdraw(
|
|
181
223
|
* "123e4567-e89b-12d3-a456-426614174000",
|
|
182
224
|
* parseUnits("50", 6),
|
|
183
|
-
*
|
|
225
|
+
* true,
|
|
226
|
+
* { pollIntervalMs: 10_000, timeoutMs: 3_600_000 },
|
|
184
227
|
* );
|
|
185
|
-
* const receipt = await sdk.waitForTransaction(result.hash);
|
|
186
228
|
* ```
|
|
187
229
|
*/
|
|
188
|
-
withdraw(assetId: string, amount: bigint, autoWait?: boolean): Promise<WithdrawResult>;
|
|
230
|
+
withdraw(assetId: string, amount: bigint, autoWait?: boolean, sourceOrRetry?: WithdrawalSource | WithdrawalRetryOptions, retry?: WithdrawalRetryOptions): Promise<WithdrawResult>;
|
|
189
231
|
/**
|
|
190
|
-
*
|
|
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.
|
|
232
|
+
* Submits (or resubmits) a previously-initiated withdrawal on-chain.
|
|
193
233
|
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
234
|
+
* Use this when the original `withdraw()` could not complete — e.g. the proof
|
|
235
|
+
* was not yet confirmed within its polling window, the wallet rejected the tx,
|
|
236
|
+
* the page reloaded before the receipt came back, or a stuck mempool entry
|
|
237
|
+
* needs resending. Polls `GET /withdrawals/{index}` for the
|
|
238
|
+
* `executeWithdrawal` calldata (retrying while it is not yet confirmed), then
|
|
239
|
+
* submits it through the connected wallet. Does NOT initiate a new withdrawal
|
|
240
|
+
* — the matching engine already debited the balance and allocated the index.
|
|
241
|
+
* The contract is idempotent against double-submission of a settled
|
|
242
|
+
* withdrawal: it reverts once the index is consumed on-chain.
|
|
200
243
|
*
|
|
201
244
|
* @param withdrawalIndex - The index returned by the original `withdraw()` call
|
|
202
245
|
* @param autoWait - Whether to await on-chain confirmation (defaults to true)
|
|
246
|
+
* @param retry - Polling cadence/timeout while waiting for the proof
|
|
203
247
|
* @returns Promise resolving to `{ withdrawalIndex, ...transaction }`
|
|
204
|
-
* @throws {APIError} When the index doesn't exist
|
|
248
|
+
* @throws {APIError} When the index doesn't exist or the proof never becomes available within the timeout
|
|
205
249
|
* @throws {ContractError} When the on-chain submission fails
|
|
206
250
|
* @throws {InvalidConfigError} When wallet account is not available
|
|
207
251
|
*/
|
|
208
|
-
retryWithdrawal(withdrawalIndex: number, autoWait?: boolean): Promise<WithdrawResult>;
|
|
252
|
+
retryWithdrawal(withdrawalIndex: number, autoWait?: boolean, retry?: WithdrawalRetryOptions): Promise<WithdrawResult>;
|
|
209
253
|
/**
|
|
210
254
|
* Retrieves the user's token balance in the vault.
|
|
211
255
|
*
|