@0xmonaco/core 1.0.73 → 1.0.75

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 CHANGED
@@ -19,7 +19,6 @@ npm install viem@^2.31.7
19
19
  - **Session-key Authentication**: Noncustodial ed25519 session keys — the server never holds a credential that can impersonate you
20
20
  - **Wallet Signature Verification**: EIP-712 signature authorizes each session key
21
21
  - **Session Refresh**: Extend session expiry without re-prompting the wallet
22
- - **Server-key Auth**: Optional `sk_...` application key for backend/service access
23
22
 
24
23
  ### 🏦 **Vault Operations**
25
24
  - **Token Approvals**: ERC20 token approvals for vault usage
@@ -280,9 +279,6 @@ await sdk.logout(); // Automatically calls revokeSession internally
280
279
  - `getAuthState()` - Get current auth state with the session keypair
281
280
  - `setAuthState(authState)` - Set auth state directly (useful for sharing across SDK instances)
282
281
 
283
- **Server-key Auth (backend/service access):**
284
- - `setServerKey(serverKey)` - Authenticate with an application secret key (`sk_...`) instead of, or alongside, a session. Useful for server-side integrations.
285
-
286
282
  ### Vault API
287
283
 
288
284
  The vault API provides secure token management operations:
@@ -513,7 +509,6 @@ bun run lint --filter @0xmonaco/core
513
509
  - **Noncustodial**: ed25519 session keys are generated locally; the server never holds a credential that can impersonate you
514
510
  - **EIP-712 login**: Wallet signature authorizes each session key
515
511
  - **Session refresh**: Extend expiry without re-prompting the wallet
516
- - **Server-key auth**: Optional `sk_...` application key for backend/service access
517
512
 
518
513
  ### API Gateway Integration
519
514
  - **Secure communication**: TLS encryption for all API calls
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * Applications API Implementation
3
3
  *
4
- * Handles application configuration and reporting operations. This is a
5
- * mixed-auth domain: `getApplicationConfig` is session-authenticated, while
6
- * the reporting methods are backend-authenticated via the application secret
7
- * key (set with {@link BaseAPI.setServerKey}, sent as `x-server-key`).
4
+ * Handles application configuration and reporting operations.
5
+ * `getApplicationConfig` is session-authenticated; the reporting methods are
6
+ * public, select their application by `clientId`, and are rate limited per
7
+ * client IP.
8
8
  *
9
9
  * @example
10
10
  * ```typescript
@@ -14,9 +14,8 @@
14
14
  * const config = await applicationsAPI.getApplicationConfig();
15
15
  * console.log(`App name: ${config.name}`);
16
16
  *
17
- * // Reporting endpoints (backend auth)
18
- * applicationsAPI.setServerKey("sk_live_...");
19
- * const orders = await applicationsAPI.listApplicationOrders({ status: "FILLED" });
17
+ * // Reporting endpoints (public, selected by client ID)
18
+ * const orders = await applicationsAPI.listApplicationOrders({ clientId: config.clientId, status: "FILLED" });
20
19
  * ```
21
20
  */
22
21
  import type { ApplicationConfigResponse, ApplicationsAPI, GetAppStatsParams, GetAppStatsResponse, ListAppBalancesParams, ListAppBalancesResponse, ListAppMovementsParams, ListAppMovementsResponse, ListAppOrdersParams, ListAppOrdersResponse, ListAppUsersParams, ListAppUsersResponse } from "@0xmonaco/types";
@@ -45,52 +44,84 @@ export declare class ApplicationsAPIImpl extends BaseAPI implements Applications
45
44
  /**
46
45
  * Lists orders placed by the application's users.
47
46
  *
48
- * Backend-authenticated — call {@link BaseAPI.setServerKey} first.
47
+ * Public — the application is selected by `params.clientId`.
48
+ *
49
+ *
50
+ * Cursor paged (0XM-2822): omit `pageToken` or pass `""` to start, then
51
+ * follow `nextPageToken` until it comes back empty. There is no `page`: it
52
+ * is REJECTED here, not dropped. The params are forwarded field by field
53
+ * rather than spread, so a stray `page` would otherwise never reach the
54
+ * server's 400 and a loose (`any`) caller looping on it would be handed the
55
+ * first cursor page forever.
49
56
  *
50
57
  * @param params - Pagination and filter options
51
58
  * @returns Promise resolving to a paginated list of orders
52
- * @throws {APIError} When the server key is unset or the request fails
59
+ * @throws {APIError} When the request fails (404 for an unknown client ID, 429 when rate limited)
53
60
  */
54
- listApplicationOrders(params?: ListAppOrdersParams): Promise<ListAppOrdersResponse>;
61
+ listApplicationOrders(params: ListAppOrdersParams): Promise<ListAppOrdersResponse>;
55
62
  /**
56
63
  * Lists the application's users.
57
64
  *
58
- * Backend-authenticated — call {@link BaseAPI.setServerKey} first.
65
+ * Public — the application is selected by `params.clientId`.
66
+ *
67
+ *
68
+ * Cursor paged (0XM-2822): omit `pageToken` or pass `""` to start, then
69
+ * follow `nextPageToken` until it comes back empty. There is no `page`: it
70
+ * is REJECTED here, not dropped. The params are forwarded field by field
71
+ * rather than spread, so a stray `page` would otherwise never reach the
72
+ * server's 400 and a loose (`any`) caller looping on it would be handed the
73
+ * first cursor page forever.
59
74
  *
60
75
  * @param params - Pagination and filter options
61
76
  * @returns Promise resolving to a paginated list of users
62
- * @throws {APIError} When the server key is unset or the request fails
77
+ * @throws {APIError} When the request fails (404 for an unknown client ID, 429 when rate limited)
63
78
  */
64
- listApplicationUsers(params?: ListAppUsersParams): Promise<ListAppUsersResponse>;
79
+ listApplicationUsers(params: ListAppUsersParams): Promise<ListAppUsersResponse>;
65
80
  /**
66
81
  * Lists ledger movements for the application's users.
67
82
  *
68
- * Backend-authenticated — call {@link BaseAPI.setServerKey} first.
83
+ * Public — the application is selected by `params.clientId`.
84
+ *
85
+ *
86
+ * Cursor paged (0XM-2822): omit `pageToken` or pass `""` to start, then
87
+ * follow `nextPageToken` until it comes back empty. There is no `page`: it
88
+ * is REJECTED here, not dropped. The params are forwarded field by field
89
+ * rather than spread, so a stray `page` would otherwise never reach the
90
+ * server's 400 and a loose (`any`) caller looping on it would be handed the
91
+ * first cursor page forever.
69
92
  *
70
93
  * @param params - Pagination and filter options
71
94
  * @returns Promise resolving to a paginated list of movements
72
- * @throws {APIError} When the server key is unset or the request fails
95
+ * @throws {APIError} When the request fails (404 for an unknown client ID, 429 when rate limited)
73
96
  */
74
- listApplicationMovements(params?: ListAppMovementsParams): Promise<ListAppMovementsResponse>;
97
+ listApplicationMovements(params: ListAppMovementsParams): Promise<ListAppMovementsResponse>;
75
98
  /**
76
99
  * Lists user balances held within the application.
77
100
  *
78
- * Backend-authenticated — call {@link BaseAPI.setServerKey} first.
101
+ * Public — the application is selected by `params.clientId`.
102
+ *
103
+ *
104
+ * Cursor paged (0XM-2822): omit `pageToken` or pass `""` to start, then
105
+ * follow `nextPageToken` until it comes back empty. There is no `page`: it
106
+ * is REJECTED here, not dropped. The params are forwarded field by field
107
+ * rather than spread, so a stray `page` would otherwise never reach the
108
+ * server's 400 and a loose (`any`) caller looping on it would be handed the
109
+ * first cursor page forever.
79
110
  *
80
111
  * @param params - Pagination and filter options
81
112
  * @returns Promise resolving to a paginated list of balances
82
- * @throws {APIError} When the server key is unset or the request fails
113
+ * @throws {APIError} When the request fails (404 for an unknown client ID, 429 when rate limited)
83
114
  */
84
- listApplicationBalances(params?: ListAppBalancesParams): Promise<ListAppBalancesResponse>;
115
+ listApplicationBalances(params: ListAppBalancesParams): Promise<ListAppBalancesResponse>;
85
116
  /**
86
117
  * Gets aggregate volume and fee stats for the application.
87
118
  *
88
119
  * Stats are scoped to trades where the application's users were the taker.
89
- * Backend-authenticated — call {@link BaseAPI.setServerKey} first.
120
+ * Public — the application is selected by `params.clientId`.
90
121
  *
91
122
  * @param params - Optional `since` filter
92
123
  * @returns Promise resolving to the application stats
93
- * @throws {APIError} When the server key is unset or the request fails
124
+ * @throws {APIError} When the request fails (404 for an unknown client ID, 429 when rate limited)
94
125
  */
95
- getApplicationStats(params?: GetAppStatsParams): Promise<GetAppStatsResponse>;
126
+ getApplicationStats(params: GetAppStatsParams): Promise<GetAppStatsResponse>;
96
127
  }
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * Applications API Implementation
3
3
  *
4
- * Handles application configuration and reporting operations. This is a
5
- * mixed-auth domain: `getApplicationConfig` is session-authenticated, while
6
- * the reporting methods are backend-authenticated via the application secret
7
- * key (set with {@link BaseAPI.setServerKey}, sent as `x-server-key`).
4
+ * Handles application configuration and reporting operations.
5
+ * `getApplicationConfig` is session-authenticated; the reporting methods are
6
+ * public, select their application by `clientId`, and are rate limited per
7
+ * client IP.
8
8
  *
9
9
  * @example
10
10
  * ```typescript
@@ -14,11 +14,11 @@
14
14
  * const config = await applicationsAPI.getApplicationConfig();
15
15
  * console.log(`App name: ${config.name}`);
16
16
  *
17
- * // Reporting endpoints (backend auth)
18
- * applicationsAPI.setServerKey("sk_live_...");
19
- * const orders = await applicationsAPI.listApplicationOrders({ status: "FILLED" });
17
+ * // Reporting endpoints (public, selected by client ID)
18
+ * const orders = await applicationsAPI.listApplicationOrders({ clientId: config.clientId, status: "FILLED" });
20
19
  * ```
21
20
  */
21
+ import { ListAppBalancesSchema, ListAppMovementsSchema, ListAppOrdersSchema, ListAppUsersSchema, validate } from "@0xmonaco/types";
22
22
  import { BaseAPI } from "../base";
23
23
  import { perpRoutes } from "../perp/routes";
24
24
  export class ApplicationsAPIImpl extends BaseAPI {
@@ -57,62 +57,128 @@ export class ApplicationsAPIImpl extends BaseAPI {
57
57
  /**
58
58
  * Lists orders placed by the application's users.
59
59
  *
60
- * Backend-authenticated — call {@link BaseAPI.setServerKey} first.
60
+ * Public — the application is selected by `params.clientId`.
61
+ *
62
+ *
63
+ * Cursor paged (0XM-2822): omit `pageToken` or pass `""` to start, then
64
+ * follow `nextPageToken` until it comes back empty. There is no `page`: it
65
+ * is REJECTED here, not dropped. The params are forwarded field by field
66
+ * rather than spread, so a stray `page` would otherwise never reach the
67
+ * server's 400 and a loose (`any`) caller looping on it would be handed the
68
+ * first cursor page forever.
61
69
  *
62
70
  * @param params - Pagination and filter options
63
71
  * @returns Promise resolving to a paginated list of orders
64
- * @throws {APIError} When the server key is unset or the request fails
72
+ * @throws {APIError} When the request fails (404 for an unknown client ID, 429 when rate limited)
65
73
  */
66
74
  async listApplicationOrders(params) {
67
- return await this.makeBackendRequest(perpRoutes.applications.orders(params));
75
+ validate(ListAppOrdersSchema, params);
76
+ return await this.makePublicRequest(perpRoutes.applications.orders({
77
+ clientId: params.clientId,
78
+ pageSize: params.pageSize,
79
+ pageToken: params.pageToken,
80
+ status: params.status,
81
+ userId: params.userId,
82
+ tradingPairId: params.tradingPairId,
83
+ side: params.side,
84
+ orderType: params.orderType,
85
+ }));
68
86
  }
69
87
  /**
70
88
  * Lists the application's users.
71
89
  *
72
- * Backend-authenticated — call {@link BaseAPI.setServerKey} first.
90
+ * Public — the application is selected by `params.clientId`.
91
+ *
92
+ *
93
+ * Cursor paged (0XM-2822): omit `pageToken` or pass `""` to start, then
94
+ * follow `nextPageToken` until it comes back empty. There is no `page`: it
95
+ * is REJECTED here, not dropped. The params are forwarded field by field
96
+ * rather than spread, so a stray `page` would otherwise never reach the
97
+ * server's 400 and a loose (`any`) caller looping on it would be handed the
98
+ * first cursor page forever.
73
99
  *
74
100
  * @param params - Pagination and filter options
75
101
  * @returns Promise resolving to a paginated list of users
76
- * @throws {APIError} When the server key is unset or the request fails
102
+ * @throws {APIError} When the request fails (404 for an unknown client ID, 429 when rate limited)
77
103
  */
78
104
  async listApplicationUsers(params) {
79
- return await this.makeBackendRequest(perpRoutes.applications.users(params));
105
+ validate(ListAppUsersSchema, params);
106
+ return await this.makePublicRequest(perpRoutes.applications.users({
107
+ clientId: params.clientId,
108
+ pageSize: params.pageSize,
109
+ pageToken: params.pageToken,
110
+ isActive: params.isActive,
111
+ accountType: params.accountType,
112
+ address: params.address,
113
+ }));
80
114
  }
81
115
  /**
82
116
  * Lists ledger movements for the application's users.
83
117
  *
84
- * Backend-authenticated — call {@link BaseAPI.setServerKey} first.
118
+ * Public — the application is selected by `params.clientId`.
119
+ *
120
+ *
121
+ * Cursor paged (0XM-2822): omit `pageToken` or pass `""` to start, then
122
+ * follow `nextPageToken` until it comes back empty. There is no `page`: it
123
+ * is REJECTED here, not dropped. The params are forwarded field by field
124
+ * rather than spread, so a stray `page` would otherwise never reach the
125
+ * server's 400 and a loose (`any`) caller looping on it would be handed the
126
+ * first cursor page forever.
85
127
  *
86
128
  * @param params - Pagination and filter options
87
129
  * @returns Promise resolving to a paginated list of movements
88
- * @throws {APIError} When the server key is unset or the request fails
130
+ * @throws {APIError} When the request fails (404 for an unknown client ID, 429 when rate limited)
89
131
  */
90
132
  async listApplicationMovements(params) {
91
- return await this.makeBackendRequest(perpRoutes.applications.movements(params));
133
+ validate(ListAppMovementsSchema, params);
134
+ return await this.makePublicRequest(perpRoutes.applications.movements({
135
+ clientId: params.clientId,
136
+ pageSize: params.pageSize,
137
+ pageToken: params.pageToken,
138
+ userId: params.userId,
139
+ transactionType: params.transactionType,
140
+ entryType: params.entryType,
141
+ assetId: params.assetId,
142
+ }));
92
143
  }
93
144
  /**
94
145
  * Lists user balances held within the application.
95
146
  *
96
- * Backend-authenticated — call {@link BaseAPI.setServerKey} first.
147
+ * Public — the application is selected by `params.clientId`.
148
+ *
149
+ *
150
+ * Cursor paged (0XM-2822): omit `pageToken` or pass `""` to start, then
151
+ * follow `nextPageToken` until it comes back empty. There is no `page`: it
152
+ * is REJECTED here, not dropped. The params are forwarded field by field
153
+ * rather than spread, so a stray `page` would otherwise never reach the
154
+ * server's 400 and a loose (`any`) caller looping on it would be handed the
155
+ * first cursor page forever.
97
156
  *
98
157
  * @param params - Pagination and filter options
99
158
  * @returns Promise resolving to a paginated list of balances
100
- * @throws {APIError} When the server key is unset or the request fails
159
+ * @throws {APIError} When the request fails (404 for an unknown client ID, 429 when rate limited)
101
160
  */
102
161
  async listApplicationBalances(params) {
103
- return await this.makeBackendRequest(perpRoutes.applications.balances(params));
162
+ validate(ListAppBalancesSchema, params);
163
+ return await this.makePublicRequest(perpRoutes.applications.balances({
164
+ clientId: params.clientId,
165
+ pageSize: params.pageSize,
166
+ pageToken: params.pageToken,
167
+ userId: params.userId,
168
+ assetId: params.assetId,
169
+ }));
104
170
  }
105
171
  /**
106
172
  * Gets aggregate volume and fee stats for the application.
107
173
  *
108
174
  * Stats are scoped to trades where the application's users were the taker.
109
- * Backend-authenticated — call {@link BaseAPI.setServerKey} first.
175
+ * Public — the application is selected by `params.clientId`.
110
176
  *
111
177
  * @param params - Optional `since` filter
112
178
  * @returns Promise resolving to the application stats
113
- * @throws {APIError} When the server key is unset or the request fails
179
+ * @throws {APIError} When the request fails (404 for an unknown client ID, 429 when rate limited)
114
180
  */
115
181
  async getApplicationStats(params) {
116
- return await this.makeBackendRequest(perpRoutes.applications.stats(params));
182
+ return await this.makePublicRequest(perpRoutes.applications.stats({ clientId: params.clientId, since: params.since }));
117
183
  }
118
184
  }
@@ -5,9 +5,7 @@
5
5
  * verification, and session lifecycle. All operations go through the API Gateway.
6
6
  *
7
7
  * This class provides a complete interface for wallet-based authentication on the
8
- * Monaco protocol. Backend services authenticate separately by setting their
9
- * application secret key (`sk_...`) via {@link BaseAPI.setServerKey}, which is sent
10
- * in the `x-server-key` header on backend requests — there is no token exchange.
8
+ * Monaco protocol.
11
9
  *
12
10
  * @example
13
11
  * ```typescript
@@ -5,9 +5,7 @@
5
5
  * verification, and session lifecycle. All operations go through the API Gateway.
6
6
  *
7
7
  * This class provides a complete interface for wallet-based authentication on the
8
- * Monaco protocol. Backend services authenticate separately by setting their
9
- * application secret key (`sk_...`) via {@link BaseAPI.setServerKey}, which is sent
10
- * in the `x-server-key` header on backend requests — there is no token exchange.
8
+ * Monaco protocol.
11
9
  *
12
10
  * @example
13
11
  * ```typescript
@@ -31,8 +31,6 @@ export declare abstract class BaseAPI {
31
31
  protected readonly apiUrl: string;
32
32
  /** Active session keypair (raw bytes) used to sign authenticated requests. */
33
33
  protected sessionKeypair?: SessionKeypair;
34
- /** Application secret key (`sk_...`) sent in the `x-server-key` header for backend-authenticated requests. */
35
- protected serverKey?: string;
36
34
  private requestSigning;
37
35
  private redirectPolicy?;
38
36
  /** Server time learned from responses; signing timestamps are read from it. */
@@ -57,19 +55,6 @@ export declare abstract class BaseAPI {
57
55
  * @param credentials - Hex-encoded session keypair, or `undefined` to clear.
58
56
  */
59
57
  setSessionKeypair(credentials: SessionCredentials | undefined): void;
60
- /**
61
- * Set (or clear) the application secret key used for backend-authenticated
62
- * requests.
63
- *
64
- * Backend endpoints (those annotated `#[require_backend]` on the gateway)
65
- * authenticate with a static application secret key rather than a session
66
- * signature. When set, the raw key is sent verbatim in the `x-server-key`
67
- * header on every {@link makeBackendRequest}. This is independent of the
68
- * session keypair — a client may hold both.
69
- *
70
- * @param serverKey - The application secret key (`sk_...`), or `undefined` to clear.
71
- */
72
- setServerKey(serverKey: string | undefined): void;
73
58
  /**
74
59
  * Parse request body for error logging
75
60
  *
@@ -126,26 +111,6 @@ export declare abstract class BaseAPI {
126
111
  * and covers the final URL path/query plus Content-Digest.
127
112
  */
128
113
  private buildSignatureHeaders;
129
- /**
130
- * Makes a backend-authenticated API request using the application secret key.
131
- *
132
- * Sends the raw `sk_...` key (set via {@link setServerKey}) in the
133
- * `x-server-key` header. The gateway hashes and matches it against the
134
- * application on every request — there is no signing and no token exchange.
135
- * Use this for endpoints annotated `#[require_backend]`.
136
- *
137
- * @param endpoint - The API endpoint to call (should start with /)
138
- * @param options - Request options (method, body, headers, etc.)
139
- * @returns Promise resolving to the response data
140
- * @throws {APIError} When the server key is not set or the API request fails
141
- *
142
- * @example
143
- * ```typescript
144
- * this.setServerKey("sk_live_...");
145
- * const orders = await this.makeBackendRequest<ListAppOrdersResponse>('/api/v1/applications/orders');
146
- * ```
147
- */
148
- protected makeBackendRequest<T>(endpoint: string, options?: RequestInit): Promise<T>;
149
114
  /**
150
115
  * Makes an unauthenticated API request.
151
116
  *
package/dist/api/base.js CHANGED
@@ -41,8 +41,6 @@ export class BaseAPI {
41
41
  apiUrl;
42
42
  /** Active session keypair (raw bytes) used to sign authenticated requests. */
43
43
  sessionKeypair;
44
- /** Application secret key (`sk_...`) sent in the `x-server-key` header for backend-authenticated requests. */
45
- serverKey;
46
44
  requestSigning = "legacy";
47
45
  redirectPolicy;
48
46
  /** Server time learned from responses; signing timestamps are read from it. */
@@ -83,21 +81,6 @@ export class BaseAPI {
83
81
  setSessionKeypair(credentials) {
84
82
  this.sessionKeypair = credentials ? keypairFromHex(credentials.publicKey, credentials.privateKey) : undefined;
85
83
  }
86
- /**
87
- * Set (or clear) the application secret key used for backend-authenticated
88
- * requests.
89
- *
90
- * Backend endpoints (those annotated `#[require_backend]` on the gateway)
91
- * authenticate with a static application secret key rather than a session
92
- * signature. When set, the raw key is sent verbatim in the `x-server-key`
93
- * header on every {@link makeBackendRequest}. This is independent of the
94
- * session keypair — a client may hold both.
95
- *
96
- * @param serverKey - The application secret key (`sk_...`), or `undefined` to clear.
97
- */
98
- setServerKey(serverKey) {
99
- this.serverKey = serverKey;
100
- }
101
84
  /**
102
85
  * Parse request body for error logging
103
86
  *
@@ -374,43 +357,6 @@ export class BaseAPI {
374
357
  "X-Monaco-Signature": signature,
375
358
  };
376
359
  }
377
- /**
378
- * Makes a backend-authenticated API request using the application secret key.
379
- *
380
- * Sends the raw `sk_...` key (set via {@link setServerKey}) in the
381
- * `x-server-key` header. The gateway hashes and matches it against the
382
- * application on every request — there is no signing and no token exchange.
383
- * Use this for endpoints annotated `#[require_backend]`.
384
- *
385
- * @param endpoint - The API endpoint to call (should start with /)
386
- * @param options - Request options (method, body, headers, etc.)
387
- * @returns Promise resolving to the response data
388
- * @throws {APIError} When the server key is not set or the API request fails
389
- *
390
- * @example
391
- * ```typescript
392
- * this.setServerKey("sk_live_...");
393
- * const orders = await this.makeBackendRequest<ListAppOrdersResponse>('/api/v1/applications/orders');
394
- * ```
395
- */
396
- async makeBackendRequest(endpoint, options = {}) {
397
- if (!this.serverKey) {
398
- throw new APIError("Server key not set. Call setServerKey(sk_...) first.", {
399
- endpoint: `${this.apiUrl}${endpoint}`,
400
- statusCode: StatusCodes.UNAUTHORIZED,
401
- });
402
- }
403
- const url = `${this.apiUrl}${endpoint}`;
404
- const requestBody = this.parseRequestBody(options.body);
405
- return this.executeRequest(url, endpoint, {
406
- ...options,
407
- headers: {
408
- "Content-Type": "application/json",
409
- "x-server-key": this.serverKey,
410
- ...options.headers,
411
- },
412
- }, requestBody);
413
- }
414
360
  /**
415
361
  * Makes an unauthenticated API request.
416
362
  *
@@ -36,9 +36,9 @@ export declare class BuildercodesAPIImpl extends BaseAPI implements Buildercodes
36
36
  listBuilderFeeChanges(params?: ListBuilderFeeChangesParams): Promise<ListBuilderFeeChangesResponse>;
37
37
  /**
38
38
  * List this frontend's per-trade BuilderCodes credits, newest first. Each
39
- * credit carries its payout `kind`. `REVENUE_SHARE` is active;
40
- * `BUILDER_FEE` is reserved and is not currently emitted. Pass `kind` to
41
- * filter the list; `total` then counts only that category.
39
+ * credit carries its payout `kind`: `REVENUE_SHARE` for Monaco revenue share
40
+ * or `BUILDER_FEE` for builder fees charged to takers. Pass `kind` to filter
41
+ * the list; `total` then counts only that category.
42
42
  *
43
43
  * The server scopes every query to the authenticated application; neither
44
44
  * the application id nor payout wallet can be supplied by the caller.
@@ -128,9 +128,9 @@ export class BuildercodesAPIImpl extends BaseAPI {
128
128
  }
129
129
  /**
130
130
  * List this frontend's per-trade BuilderCodes credits, newest first. Each
131
- * credit carries its payout `kind`. `REVENUE_SHARE` is active;
132
- * `BUILDER_FEE` is reserved and is not currently emitted. Pass `kind` to
133
- * filter the list; `total` then counts only that category.
131
+ * credit carries its payout `kind`: `REVENUE_SHARE` for Monaco revenue share
132
+ * or `BUILDER_FEE` for builder fees charged to takers. Pass `kind` to filter
133
+ * the list; `total` then counts only that category.
134
134
  *
135
135
  * The server scopes every query to the authenticated application; neither
136
136
  * the application id nor payout wallet can be supplied by the caller.
@@ -16,6 +16,7 @@ export class DelegatedAgentsAPIImpl extends BaseAPI {
16
16
  maxLeverage: request.maxLeverage,
17
17
  maxOrderNotional: request.maxOrderNotional,
18
18
  maxOpenOrders: request.maxOpenOrders,
19
+ ipAllowlist: request.ipAllowlist,
19
20
  }),
20
21
  });
21
22
  }
@@ -1,6 +1,12 @@
1
- import type { GetAvailableCollateralParams, GetAvailableCollateralResponse, GetMarginAccountMovementsParams, GetMarginAccountMovementsResponse, GetMarginAccountSummaryParams, ListMarginAccountsParams, ListMarginAccountsResponse, MarginAccountSummary, MarginAccountsAPI, SimulateOrderRiskRequest, SimulateOrderRiskResponse, SimulateRiskBucketOrderRiskRequest, TransferCollateralFromParentMarginAccountRequest, TransferCollateralRequest, TransferCollateralResponse, TransferCollateralToParentMarginAccountRequest, TransferCollateralToRiskBucketRequest } from "@0xmonaco/types";
1
+ import type { CloseMarginSubAccountResponse, CreateMarginSubAccountRequest, CreateMarginSubAccountResponse, GetAvailableCollateralParams, GetAvailableCollateralResponse, GetMarginAccountMovementsParams, GetMarginAccountMovementsResponse, GetMarginAccountSummaryParams, ListMarginAccountsParams, ListMarginAccountsResponse, MarginAccountPnl, MarginAccountSummary, MarginAccountsAPI, SimulateOrderRiskRequest, SimulateOrderRiskResponse, SimulateRiskBucketOrderRiskRequest, TransferCollateralFromParentMarginAccountRequest, TransferCollateralRequest, TransferCollateralResponse, TransferCollateralToParentMarginAccountRequest, TransferCollateralToRiskBucketRequest, TransferMarginCollateralRequest, TransferMarginCollateralResponse } from "@0xmonaco/types";
2
2
  import { BaseAPI } from "../base";
3
3
  export declare class MarginAccountsAPIImpl extends BaseAPI implements MarginAccountsAPI {
4
+ createMarginSubAccount(request: CreateMarginSubAccountRequest): Promise<CreateMarginSubAccountResponse>;
5
+ closeMarginSubAccount(marginAccountId: string): Promise<CloseMarginSubAccountResponse>;
6
+ getMarginAccountPnl(marginAccountId: string): Promise<MarginAccountPnl>;
7
+ transferMarginCollateral(request: TransferMarginCollateralRequest): Promise<TransferMarginCollateralResponse>;
8
+ transferCollateralToSubAccount(marginAccountId: string, amount: string): Promise<TransferMarginCollateralResponse>;
9
+ transferCollateralFromSubAccount(marginAccountId: string, amount: string): Promise<TransferMarginCollateralResponse>;
4
10
  listMarginAccounts(params?: ListMarginAccountsParams): Promise<ListMarginAccountsResponse>;
5
11
  getMarginAccountSummary(marginAccountId: string, params?: GetMarginAccountSummaryParams): Promise<MarginAccountSummary>;
6
12
  getParentMarginAccountSummary(params?: GetMarginAccountSummaryParams): Promise<MarginAccountSummary>;
@@ -1,15 +1,59 @@
1
- import { GetAvailableCollateralSchema, GetMarginAccountMovementsSchema, GetMarginAccountSummarySchema, GetParentMarginAccountMovementsSchema, GetParentMarginAccountSummarySchema, ListMarginAccountsSchema, SimulateOrderRiskSchema, SimulateParentMarginOrderRiskSchema, SimulateRiskBucketOrderRiskSchema, TransferCollateralFromParentMarginAccountSchema, TransferCollateralSchema, TransferCollateralToParentMarginAccountSchema, TransferCollateralToRiskBucketSchema, validate, } from "@0xmonaco/types";
1
+ import { CloseMarginSubAccountSchema, CreateMarginSubAccountSchema, GetAvailableCollateralSchema, GetMarginAccountMovementsSchema, GetMarginAccountPnlSchema, GetMarginAccountSummarySchema, GetParentMarginAccountMovementsSchema, GetParentMarginAccountSummarySchema, ListMarginAccountsSchema, SimulateOrderRiskSchema, SimulateParentMarginOrderRiskSchema, SimulateRiskBucketOrderRiskSchema, SubAccountCollateralTransferSchema, TransferCollateralFromParentMarginAccountSchema, TransferCollateralSchema, TransferCollateralToParentMarginAccountSchema, TransferCollateralToRiskBucketSchema, TransferMarginCollateralSchema, validate, } from "@0xmonaco/types";
2
2
  import { BaseAPI } from "../base";
3
3
  import { perpRoutes } from "../perp";
4
4
  export class MarginAccountsAPIImpl extends BaseAPI {
5
+ async createMarginSubAccount(request) {
6
+ validate(CreateMarginSubAccountSchema, { request });
7
+ return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.createSubAccount(), {
8
+ method: "POST",
9
+ body: JSON.stringify({ subaccountKey: request.subaccountKey, label: request.label }),
10
+ });
11
+ }
12
+ async closeMarginSubAccount(marginAccountId) {
13
+ validate(CloseMarginSubAccountSchema, { marginAccountId });
14
+ return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.closeSubAccount(marginAccountId), {
15
+ method: "POST",
16
+ body: JSON.stringify({}),
17
+ });
18
+ }
19
+ async getMarginAccountPnl(marginAccountId) {
20
+ validate(GetMarginAccountPnlSchema, { marginAccountId });
21
+ return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.pnl(marginAccountId));
22
+ }
23
+ async transferMarginCollateral(request) {
24
+ validate(TransferMarginCollateralSchema, { request });
25
+ return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.transferCollateral(), {
26
+ method: "POST",
27
+ body: JSON.stringify({
28
+ asset: request.asset,
29
+ amount: request.amount,
30
+ from: request.from,
31
+ to: request.to,
32
+ }),
33
+ });
34
+ }
35
+ async transferCollateralToSubAccount(marginAccountId, amount) {
36
+ validate(SubAccountCollateralTransferSchema, { marginAccountId, amount });
37
+ return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.subAccountTransferIn(marginAccountId), {
38
+ method: "POST",
39
+ body: JSON.stringify({ amount }),
40
+ });
41
+ }
42
+ async transferCollateralFromSubAccount(marginAccountId, amount) {
43
+ validate(SubAccountCollateralTransferSchema, { marginAccountId, amount });
44
+ return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.subAccountTransferOut(marginAccountId), {
45
+ method: "POST",
46
+ body: JSON.stringify({ amount }),
47
+ });
48
+ }
5
49
  async listMarginAccounts(params) {
6
50
  if (params) {
7
51
  validate(ListMarginAccountsSchema, params);
8
52
  }
9
53
  return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.list(params
10
54
  ? {
11
- page: params.page,
12
55
  pageSize: params.pageSize,
56
+ pageToken: params.pageToken,
13
57
  state: params.state,
14
58
  tradingPairId: params.tradingPairId,
15
59
  }
@@ -69,6 +113,7 @@ export class MarginAccountsAPIImpl extends BaseAPI {
69
113
  tradingPairId: request.tradingPairId,
70
114
  strategyKey: request.strategyKey,
71
115
  marginMode: request.marginMode,
116
+ marginAccountId: request.marginAccountId,
72
117
  // No selectedTradingPairIds: cross scope is derived from trading, and
73
118
  // the server ignores the deprecated field. Not sending it keeps a
74
119
  // pre-upgrade caller's stale list from reaching the wire at all.
@@ -152,6 +197,7 @@ export class MarginAccountsAPIImpl extends BaseAPI {
152
197
  tradingPairId: request.tradingPairId,
153
198
  strategyKey: request.strategyKey,
154
199
  marginMode: request.marginMode,
200
+ marginAccountId: request.marginAccountId,
155
201
  // No selectedTradingPairIds: cross scope is derived from trading, and
156
202
  // the server ignores the deprecated field. Not sending it keeps a
157
203
  // pre-upgrade caller's stale list from reaching the wire at all.
@@ -1,4 +1,4 @@
1
- import { GetCandlesticksByPairIdSchema, GetMarketMetadataSchema, validate } from "@0xmonaco/types";
1
+ import { GetCandlesticksByPairIdSchema, GetMarketMetadataSchema, ListAllFundingHistorySchema, ListFundingHistorySchema, validate } from "@0xmonaco/types";
2
2
  import { BaseAPI } from "../base";
3
3
  import { perpRoutes } from "../perp";
4
4
  /**
@@ -102,9 +102,11 @@ export class MarketAPIImpl extends BaseAPI {
102
102
  }
103
103
  async listFundingHistory(tradingPairId, params) {
104
104
  validate(GetMarketMetadataSchema, { tradingPairId });
105
+ validate(ListFundingHistorySchema, params ?? {});
105
106
  return await this.makePublicRequest(perpRoutes.market.listFundingHistory(tradingPairId, params));
106
107
  }
107
108
  async listAllFundingHistory(params) {
109
+ validate(ListAllFundingHistorySchema, params ?? {});
108
110
  return await this.makePublicRequest(perpRoutes.market.listAllFundingHistory(params));
109
111
  }
110
112
  async getOpenInterest(tradingPairId) {