@0xmonaco/core 1.0.74 → 1.0.76
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 +0 -5
- package/dist/api/applications/api.d.ts +53 -22
- package/dist/api/applications/api.js +88 -22
- package/dist/api/auth/api.d.ts +1 -3
- package/dist/api/auth/api.js +1 -3
- package/dist/api/base.d.ts +0 -35
- package/dist/api/base.js +0 -54
- package/dist/api/buildercodes/api.d.ts +3 -4
- package/dist/api/buildercodes/api.js +6 -7
- package/dist/api/managed-markets/index.js +4 -2
- package/dist/api/margin-accounts/api.d.ts +2 -0
- package/dist/api/margin-accounts/api.js +16 -2
- package/dist/api/market/api.js +3 -1
- package/dist/api/perp/routes.d.ts +19 -12
- package/dist/api/perp/routes.js +2 -0
- package/dist/api/pitpass/api.d.ts +11 -8
- package/dist/api/pitpass/api.js +24 -11
- package/dist/api/positions/api.d.ts +20 -8
- package/dist/api/positions/api.js +20 -8
- package/dist/api/profile/api.d.ts +55 -18
- package/dist/api/profile/api.js +77 -28
- package/dist/api/trades/api.d.ts +38 -7
- package/dist/api/trades/api.js +38 -11
- package/dist/api/trading/api.d.ts +6 -11
- package/dist/api/trading/api.js +6 -11
- package/dist/api/websocket/websocket.js +149 -24
- package/dist/api/withdrawals/api.js +3 -1
- package/dist/coverage.d.ts +2 -0
- package/dist/coverage.js +2 -0
- package/dist/sdk.d.ts +0 -18
- package/dist/sdk.js +0 -42
- package/package.json +3 -3
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.
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
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 (
|
|
18
|
-
* applicationsAPI.
|
|
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
|
-
*
|
|
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
|
|
59
|
+
* @throws {APIError} When the request fails (404 for an unknown client ID, 429 when rate limited)
|
|
53
60
|
*/
|
|
54
|
-
listApplicationOrders(params
|
|
61
|
+
listApplicationOrders(params: ListAppOrdersParams): Promise<ListAppOrdersResponse>;
|
|
55
62
|
/**
|
|
56
63
|
* Lists the application's users.
|
|
57
64
|
*
|
|
58
|
-
*
|
|
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
|
|
77
|
+
* @throws {APIError} When the request fails (404 for an unknown client ID, 429 when rate limited)
|
|
63
78
|
*/
|
|
64
|
-
listApplicationUsers(params
|
|
79
|
+
listApplicationUsers(params: ListAppUsersParams): Promise<ListAppUsersResponse>;
|
|
65
80
|
/**
|
|
66
81
|
* Lists ledger movements for the application's users.
|
|
67
82
|
*
|
|
68
|
-
*
|
|
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
|
|
95
|
+
* @throws {APIError} When the request fails (404 for an unknown client ID, 429 when rate limited)
|
|
73
96
|
*/
|
|
74
|
-
listApplicationMovements(params
|
|
97
|
+
listApplicationMovements(params: ListAppMovementsParams): Promise<ListAppMovementsResponse>;
|
|
75
98
|
/**
|
|
76
99
|
* Lists user balances held within the application.
|
|
77
100
|
*
|
|
78
|
-
*
|
|
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
|
|
113
|
+
* @throws {APIError} When the request fails (404 for an unknown client ID, 429 when rate limited)
|
|
83
114
|
*/
|
|
84
|
-
listApplicationBalances(params
|
|
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
|
-
*
|
|
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
|
|
124
|
+
* @throws {APIError} When the request fails (404 for an unknown client ID, 429 when rate limited)
|
|
94
125
|
*/
|
|
95
|
-
getApplicationStats(params
|
|
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.
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
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 (
|
|
18
|
-
* applicationsAPI.
|
|
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
|
-
*
|
|
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
|
|
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
|
-
|
|
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
|
-
*
|
|
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
|
|
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
|
-
|
|
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
|
-
*
|
|
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
|
|
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
|
-
|
|
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
|
-
*
|
|
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
|
|
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
|
-
|
|
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
|
-
*
|
|
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
|
|
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.
|
|
182
|
+
return await this.makePublicRequest(perpRoutes.applications.stats({ clientId: params.clientId, since: params.since }));
|
|
117
183
|
}
|
|
118
184
|
}
|
package/dist/api/auth/api.d.ts
CHANGED
|
@@ -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.
|
|
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
|
package/dist/api/auth/api.js
CHANGED
|
@@ -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.
|
|
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
|
package/dist/api/base.d.ts
CHANGED
|
@@ -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
|
*
|
|
@@ -62,10 +62,9 @@ export declare class BuildercodesAPIImpl extends BaseAPI implements Buildercodes
|
|
|
62
62
|
/**
|
|
63
63
|
* Claim accrued BuilderCodes payout balance into a trading balance.
|
|
64
64
|
*
|
|
65
|
-
* Throws 403 when the
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* that session type rather than a rollout state.
|
|
65
|
+
* Throws 403 when the session is a delegated agent — permanent for that
|
|
66
|
+
* session type rather than a rollout state. No program switch gates the
|
|
67
|
+
* claim, so a balance already credited stays claimable.
|
|
69
68
|
*
|
|
70
69
|
* Throws 409 when the payout balance is insufficient for the requested
|
|
71
70
|
* amount (including when the caller has never accrued a share).
|
|
@@ -140,12 +140,12 @@ export class BuildercodesAPIImpl extends BaseAPI {
|
|
|
140
140
|
validate(ListBuildercodePayoutsParamsSchema, params);
|
|
141
141
|
}
|
|
142
142
|
const searchParams = new URLSearchParams();
|
|
143
|
-
if (params?.page !== undefined) {
|
|
144
|
-
searchParams.append("page", params.page.toString());
|
|
145
|
-
}
|
|
146
143
|
if (params?.pageSize !== undefined) {
|
|
147
144
|
searchParams.append("pageSize", params.pageSize.toString());
|
|
148
145
|
}
|
|
146
|
+
if (params?.pageToken !== undefined) {
|
|
147
|
+
searchParams.append("pageToken", params.pageToken);
|
|
148
|
+
}
|
|
149
149
|
if (params?.kind !== undefined) {
|
|
150
150
|
searchParams.append("kind", params.kind);
|
|
151
151
|
}
|
|
@@ -175,10 +175,9 @@ export class BuildercodesAPIImpl extends BaseAPI {
|
|
|
175
175
|
/**
|
|
176
176
|
* Claim accrued BuilderCodes payout balance into a trading balance.
|
|
177
177
|
*
|
|
178
|
-
* Throws 403 when the
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
* that session type rather than a rollout state.
|
|
178
|
+
* Throws 403 when the session is a delegated agent — permanent for that
|
|
179
|
+
* session type rather than a rollout state. No program switch gates the
|
|
180
|
+
* claim, so a balance already credited stays claimable.
|
|
182
181
|
*
|
|
183
182
|
* Throws 409 when the payout balance is insufficient for the requested
|
|
184
183
|
* amount (including when the caller has never accrued a share).
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import { ListManagedMarketAssignmentsSchema, validate } from "@0xmonaco/types";
|
|
1
2
|
import { BaseAPI } from "../base";
|
|
2
3
|
/** Managed quote intents use the existing wallet session and never move funding. */
|
|
3
4
|
export class ManagedMarketsAPIImpl extends BaseAPI {
|
|
4
5
|
async listAssignments(request = {}) {
|
|
6
|
+
validate(ListManagedMarketAssignmentsSchema, request);
|
|
5
7
|
const query = new URLSearchParams();
|
|
6
|
-
if (request.page !== undefined)
|
|
7
|
-
query.set("page", String(request.page));
|
|
8
8
|
if (request.pageSize !== undefined)
|
|
9
9
|
query.set("pageSize", String(request.pageSize));
|
|
10
|
+
if (request.pageToken !== undefined)
|
|
11
|
+
query.set("pageToken", request.pageToken);
|
|
10
12
|
return this.makeAuthenticatedRequest(`/api/v1/managed-markets/assignments${query.size ? `?${query}` : ""}`);
|
|
11
13
|
}
|
|
12
14
|
async claimLease(launchId, request) {
|
|
@@ -5,6 +5,8 @@ export declare class MarginAccountsAPIImpl extends BaseAPI implements MarginAcco
|
|
|
5
5
|
closeMarginSubAccount(marginAccountId: string): Promise<CloseMarginSubAccountResponse>;
|
|
6
6
|
getMarginAccountPnl(marginAccountId: string): Promise<MarginAccountPnl>;
|
|
7
7
|
transferMarginCollateral(request: TransferMarginCollateralRequest): Promise<TransferMarginCollateralResponse>;
|
|
8
|
+
transferCollateralToSubAccount(marginAccountId: string, amount: string): Promise<TransferMarginCollateralResponse>;
|
|
9
|
+
transferCollateralFromSubAccount(marginAccountId: string, amount: string): Promise<TransferMarginCollateralResponse>;
|
|
8
10
|
listMarginAccounts(params?: ListMarginAccountsParams): Promise<ListMarginAccountsResponse>;
|
|
9
11
|
getMarginAccountSummary(marginAccountId: string, params?: GetMarginAccountSummaryParams): Promise<MarginAccountSummary>;
|
|
10
12
|
getParentMarginAccountSummary(params?: GetMarginAccountSummaryParams): Promise<MarginAccountSummary>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CloseMarginSubAccountSchema, CreateMarginSubAccountSchema, GetAvailableCollateralSchema, GetMarginAccountMovementsSchema, GetMarginAccountPnlSchema, GetMarginAccountSummarySchema, GetParentMarginAccountMovementsSchema, GetParentMarginAccountSummarySchema, ListMarginAccountsSchema, SimulateOrderRiskSchema, SimulateParentMarginOrderRiskSchema, SimulateRiskBucketOrderRiskSchema, TransferCollateralFromParentMarginAccountSchema, TransferCollateralSchema, TransferCollateralToParentMarginAccountSchema, TransferCollateralToRiskBucketSchema, TransferMarginCollateralSchema, 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 {
|
|
@@ -32,14 +32,28 @@ export class MarginAccountsAPIImpl extends BaseAPI {
|
|
|
32
32
|
}),
|
|
33
33
|
});
|
|
34
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
|
+
}
|
|
35
49
|
async listMarginAccounts(params) {
|
|
36
50
|
if (params) {
|
|
37
51
|
validate(ListMarginAccountsSchema, params);
|
|
38
52
|
}
|
|
39
53
|
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.list(params
|
|
40
54
|
? {
|
|
41
|
-
page: params.page,
|
|
42
55
|
pageSize: params.pageSize,
|
|
56
|
+
pageToken: params.pageToken,
|
|
43
57
|
state: params.state,
|
|
44
58
|
tradingPairId: params.tradingPairId,
|
|
45
59
|
}
|
package/dist/api/market/api.js
CHANGED
|
@@ -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) {
|