@0xmonaco/core 1.1.2 → 1.1.5-develop.129b2c6
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 +7 -1
- package/dist/api/analytics/api.d.ts +40 -0
- package/dist/api/analytics/api.js +107 -0
- package/dist/api/analytics/index.d.ts +1 -0
- package/dist/api/analytics/index.js +1 -0
- package/dist/api/applications/api.d.ts +5 -5
- package/dist/api/applications/api.js +5 -5
- package/dist/api/buildercodes/api.d.ts +18 -11
- package/dist/api/buildercodes/api.js +31 -15
- package/dist/api/index.d.ts +2 -0
- package/dist/api/index.js +2 -0
- package/dist/api/market/api.d.ts +3 -1
- package/dist/api/market/api.js +9 -0
- package/dist/api/orderbook/api.d.ts +5 -2
- package/dist/api/orderbook/api.js +2 -0
- package/dist/api/perp/routes.d.ts +68 -0
- package/dist/api/perp/routes.js +22 -0
- package/dist/api/rfq/api.d.ts +69 -0
- package/dist/api/rfq/api.js +129 -0
- package/dist/api/rfq/index.d.ts +6 -0
- package/dist/api/rfq/index.js +6 -0
- package/dist/api/trades/api.d.ts +24 -0
- package/dist/api/trades/api.js +28 -1
- package/dist/api/trading/api.d.ts +35 -3
- package/dist/api/trading/api.js +49 -7
- package/dist/api/websocket/local-book.d.ts +112 -0
- package/dist/api/websocket/local-book.js +423 -0
- package/dist/api/websocket/websocket.js +790 -38
- package/dist/coverage.d.ts +28 -0
- package/dist/coverage.js +28 -0
- package/dist/sdk.d.ts +3 -1
- package/dist/sdk.js +8 -0
- package/dist/utils/magnitude.d.ts +5 -2
- package/dist/utils/magnitude.js +6 -3
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -118,7 +118,13 @@ async function marketExample() {
|
|
|
118
118
|
|
|
119
119
|
// Get specific trading pair
|
|
120
120
|
const btcPair = await monaco.market.getTradingPairBySymbol("BTC/USDC");
|
|
121
|
-
console.log("BTC pair:", btcPair?.symbol, btcPair?.
|
|
121
|
+
console.log("BTC pair:", btcPair?.symbol, btcPair?.tickSize);
|
|
122
|
+
|
|
123
|
+
// Fee rates are tiered: read the pair's schedule (public) or your own tier
|
|
124
|
+
if (btcPair) {
|
|
125
|
+
const { feeSchedule } = await monaco.fees.getFeeSchedule(btcPair.id);
|
|
126
|
+
console.log("Tier 1 taker fee (bps):", feeSchedule[0]?.takerFeeBps);
|
|
127
|
+
}
|
|
122
128
|
}
|
|
123
129
|
|
|
124
130
|
// Vault Operations
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Analytics API Implementation
|
|
3
|
+
*
|
|
4
|
+
* The public explorer analytics: protocol totals and series over a window,
|
|
5
|
+
* per-market volume, the treasury's all-time net fees, and the builder
|
|
6
|
+
* directory, figures and leaderboard; wallets, token custody and the vault
|
|
7
|
+
* deposit and withdrawal feeds. Volume, trade
|
|
8
|
+
* counts and the spot/perp split count the builders the explorer displays;
|
|
9
|
+
* fees, active takers, new traders and market volume count every trade.
|
|
10
|
+
* Public — no authentication required; each client IP has a read budget.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const week = await sdk.analytics.getProtocolTotals({ window: "7d" });
|
|
15
|
+
* // Both window ends are inclusive, so the previous window ends 1 ms before
|
|
16
|
+
* // this one starts; ending at `startTime` itself would count a bucket twice
|
|
17
|
+
* // whenever the start falls on a bucket boundary.
|
|
18
|
+
* const previous = await sdk.analytics.getProtocolTotals({ window: "7d", endTime: week.window.startTime - 1 });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
import type { AnalyticsAPI, AnalyticsWindowParams, GetBuilderResponse, GetBuilderSeriesResponse, GetBuilderTotalsResponse, GetProtocolSeriesResponse, GetProtocolTotalsResponse, GetTokenCustodyResponse, GetTreasuryNetFeesResponse, GetWalletSummaryResponse, ListBuilderLeaderboardParams, ListBuilderLeaderboardResponse, ListBuildersResponse, ListMarketVolumesParams, ListMarketVolumesResponse, ListTokenCustodyResponse, ListVaultDepositsResponse, ListVaultWithdrawalsResponse, ListWalletLeaderboardParams, ListWalletLeaderboardResponse, ListWalletLiquidationsParams, ListWalletLiquidationsResponse, VaultFeedParams } from "@0xmonaco/types";
|
|
22
|
+
import { BaseAPI } from "../base";
|
|
23
|
+
export declare class AnalyticsAPIImpl extends BaseAPI implements AnalyticsAPI {
|
|
24
|
+
getProtocolTotals(params?: AnalyticsWindowParams): Promise<GetProtocolTotalsResponse>;
|
|
25
|
+
getProtocolSeries(params?: AnalyticsWindowParams): Promise<GetProtocolSeriesResponse>;
|
|
26
|
+
listMarketVolumes(params?: ListMarketVolumesParams): Promise<ListMarketVolumesResponse>;
|
|
27
|
+
getTreasuryNetFees(): Promise<GetTreasuryNetFeesResponse>;
|
|
28
|
+
listBuilders(): Promise<ListBuildersResponse>;
|
|
29
|
+
getBuilder(builder: string): Promise<GetBuilderResponse>;
|
|
30
|
+
getBuilderTotals(builder: string, params?: AnalyticsWindowParams): Promise<GetBuilderTotalsResponse>;
|
|
31
|
+
getBuilderSeries(builder: string, params?: AnalyticsWindowParams): Promise<GetBuilderSeriesResponse>;
|
|
32
|
+
listBuilderLeaderboard(params?: ListBuilderLeaderboardParams): Promise<ListBuilderLeaderboardResponse>;
|
|
33
|
+
listWalletLeaderboard(params?: ListWalletLeaderboardParams): Promise<ListWalletLeaderboardResponse>;
|
|
34
|
+
getWalletSummary(wallet: string): Promise<GetWalletSummaryResponse>;
|
|
35
|
+
listWalletLiquidations(wallet: string, params?: ListWalletLiquidationsParams): Promise<ListWalletLiquidationsResponse>;
|
|
36
|
+
listTokenCustody(): Promise<ListTokenCustodyResponse>;
|
|
37
|
+
getTokenCustody(token: string): Promise<GetTokenCustodyResponse>;
|
|
38
|
+
listVaultDeposits(params?: VaultFeedParams): Promise<ListVaultDepositsResponse>;
|
|
39
|
+
listVaultWithdrawals(params?: VaultFeedParams): Promise<ListVaultWithdrawalsResponse>;
|
|
40
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Analytics API Implementation
|
|
3
|
+
*
|
|
4
|
+
* The public explorer analytics: protocol totals and series over a window,
|
|
5
|
+
* per-market volume, the treasury's all-time net fees, and the builder
|
|
6
|
+
* directory, figures and leaderboard; wallets, token custody and the vault
|
|
7
|
+
* deposit and withdrawal feeds. Volume, trade
|
|
8
|
+
* counts and the spot/perp split count the builders the explorer displays;
|
|
9
|
+
* fees, active takers, new traders and market volume count every trade.
|
|
10
|
+
* Public — no authentication required; each client IP has a read budget.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const week = await sdk.analytics.getProtocolTotals({ window: "7d" });
|
|
15
|
+
* // Both window ends are inclusive, so the previous window ends 1 ms before
|
|
16
|
+
* // this one starts; ending at `startTime` itself would count a bucket twice
|
|
17
|
+
* // whenever the start falls on a bucket boundary.
|
|
18
|
+
* const previous = await sdk.analytics.getProtocolTotals({ window: "7d", endTime: week.window.startTime - 1 });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
import { BaseAPI } from "../base";
|
|
22
|
+
import { perpRoutes } from "../perp/routes";
|
|
23
|
+
export class AnalyticsAPIImpl extends BaseAPI {
|
|
24
|
+
async getProtocolTotals(params) {
|
|
25
|
+
return await this.makePublicRequest(perpRoutes.analytics.protocolTotals(params), { method: "GET" });
|
|
26
|
+
}
|
|
27
|
+
async getProtocolSeries(params) {
|
|
28
|
+
const response = await this.makePublicRequest(perpRoutes.analytics.protocolSeries(params), { method: "GET" });
|
|
29
|
+
return { ...response, points: response.points ?? [] };
|
|
30
|
+
}
|
|
31
|
+
async listMarketVolumes(params) {
|
|
32
|
+
const response = await this.makePublicRequest(perpRoutes.analytics.marketVolumes(params), { method: "GET" });
|
|
33
|
+
return { ...response, markets: response.markets ?? [] };
|
|
34
|
+
}
|
|
35
|
+
async getTreasuryNetFees() {
|
|
36
|
+
return await this.makePublicRequest(perpRoutes.analytics.treasuryNetFees(), { method: "GET" });
|
|
37
|
+
}
|
|
38
|
+
async listBuilders() {
|
|
39
|
+
const response = await this.makePublicRequest(perpRoutes.analytics.builders(), { method: "GET" });
|
|
40
|
+
return { builders: (response.builders ?? []).map(withApplications) };
|
|
41
|
+
}
|
|
42
|
+
async getBuilder(builder) {
|
|
43
|
+
const response = await this.makePublicRequest(perpRoutes.analytics.builder(builder), { method: "GET" });
|
|
44
|
+
return { builder: withApplications(response.builder) };
|
|
45
|
+
}
|
|
46
|
+
async getBuilderTotals(builder, params) {
|
|
47
|
+
const response = await this.makePublicRequest(perpRoutes.analytics.builderTotals(builder, params), {
|
|
48
|
+
method: "GET",
|
|
49
|
+
});
|
|
50
|
+
return { ...response, builder: withApplications(response.builder) };
|
|
51
|
+
}
|
|
52
|
+
async getBuilderSeries(builder, params) {
|
|
53
|
+
const response = await this.makePublicRequest(perpRoutes.analytics.builderSeries(builder, params), { method: "GET" });
|
|
54
|
+
return { ...response, builder: withApplications(response.builder), points: response.points ?? [] };
|
|
55
|
+
}
|
|
56
|
+
async listBuilderLeaderboard(params) {
|
|
57
|
+
const response = await this.makePublicRequest(perpRoutes.analytics.builderLeaderboard(params), { method: "GET" });
|
|
58
|
+
return { ...response, rows: (response.rows ?? []).map((row) => ({ ...row, builder: withApplications(row.builder) })) };
|
|
59
|
+
}
|
|
60
|
+
async listWalletLeaderboard(params) {
|
|
61
|
+
const response = await this.makePublicRequest(perpRoutes.analytics.walletLeaderboard(params), {
|
|
62
|
+
method: "GET",
|
|
63
|
+
});
|
|
64
|
+
return { wallets: response.wallets ?? [] };
|
|
65
|
+
}
|
|
66
|
+
async getWalletSummary(wallet) {
|
|
67
|
+
const response = await this.makePublicRequest(perpRoutes.analytics.walletSummary(wallet), { method: "GET" });
|
|
68
|
+
// Absent optionals and an empty repeated field are omitted on the wire.
|
|
69
|
+
return {
|
|
70
|
+
...response,
|
|
71
|
+
totals: response.totals ?? null,
|
|
72
|
+
builders: (response.builders ?? []).map((row) => ({ ...row, builder: withApplications(row.builder) })),
|
|
73
|
+
unattributed: response.unattributed ?? null,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
async listWalletLiquidations(wallet, params) {
|
|
77
|
+
const response = await this.makePublicRequest(perpRoutes.analytics.walletLiquidations(wallet, params), { method: "GET" });
|
|
78
|
+
return { ...response, events: response.events ?? [], nextPageToken: response.nextPageToken ?? "" };
|
|
79
|
+
}
|
|
80
|
+
async listTokenCustody() {
|
|
81
|
+
const response = await this.makePublicRequest(perpRoutes.analytics.tokenCustody(), { method: "GET" });
|
|
82
|
+
return { ...response, tokens: response.tokens ?? [] };
|
|
83
|
+
}
|
|
84
|
+
async getTokenCustody(token) {
|
|
85
|
+
return await this.makePublicRequest(perpRoutes.analytics.tokenCustodyDetail(token), { method: "GET" });
|
|
86
|
+
}
|
|
87
|
+
async listVaultDeposits(params) {
|
|
88
|
+
const response = await this.makePublicRequest(perpRoutes.analytics.vaultDeposits(params), { method: "GET" });
|
|
89
|
+
return {
|
|
90
|
+
...response,
|
|
91
|
+
deposits: (response.deposits ?? []).map((row) => ({ ...row, builder: row.builder ? withApplications(row.builder) : null })),
|
|
92
|
+
nextPageToken: response.nextPageToken ?? "",
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
async listVaultWithdrawals(params) {
|
|
96
|
+
const response = await this.makePublicRequest(perpRoutes.analytics.vaultWithdrawals(params), { method: "GET" });
|
|
97
|
+
return {
|
|
98
|
+
...response,
|
|
99
|
+
withdrawals: (response.withdrawals ?? []).map((row) => ({ ...row, builder: row.builder ? withApplications(row.builder) : null })),
|
|
100
|
+
nextPageToken: response.nextPageToken ?? "",
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/** A builder with its application list present, empty when the wire omitted it. */
|
|
105
|
+
function withApplications(builder) {
|
|
106
|
+
return { ...builder, applications: builder.applications ?? [] };
|
|
107
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AnalyticsAPIImpl } from "./api";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AnalyticsAPIImpl } from "./api";
|
|
@@ -56,7 +56,7 @@ export declare class ApplicationsAPIImpl extends BaseAPI implements Applications
|
|
|
56
56
|
*
|
|
57
57
|
* @param params - Pagination and filter options
|
|
58
58
|
* @returns Promise resolving to a paginated list of orders
|
|
59
|
-
* @throws {APIError} When the request fails (404 for an unknown client ID, 429 when rate limited)
|
|
59
|
+
* @throws {APIError} When the request fails (404 for an unknown, inactive or hidden client ID, 429 when rate limited)
|
|
60
60
|
*/
|
|
61
61
|
listApplicationOrders(params: ListAppOrdersParams): Promise<ListAppOrdersResponse>;
|
|
62
62
|
/**
|
|
@@ -74,7 +74,7 @@ export declare class ApplicationsAPIImpl extends BaseAPI implements Applications
|
|
|
74
74
|
*
|
|
75
75
|
* @param params - Pagination and filter options
|
|
76
76
|
* @returns Promise resolving to a paginated list of users
|
|
77
|
-
* @throws {APIError} When the request fails (404 for an unknown client ID, 429 when rate limited)
|
|
77
|
+
* @throws {APIError} When the request fails (404 for an unknown, inactive or hidden client ID, 429 when rate limited)
|
|
78
78
|
*/
|
|
79
79
|
listApplicationUsers(params: ListAppUsersParams): Promise<ListAppUsersResponse>;
|
|
80
80
|
/**
|
|
@@ -92,7 +92,7 @@ export declare class ApplicationsAPIImpl extends BaseAPI implements Applications
|
|
|
92
92
|
*
|
|
93
93
|
* @param params - Pagination and filter options
|
|
94
94
|
* @returns Promise resolving to a paginated list of movements
|
|
95
|
-
* @throws {APIError} When the request fails (404 for an unknown client ID, 429 when rate limited)
|
|
95
|
+
* @throws {APIError} When the request fails (404 for an unknown, inactive or hidden client ID, 429 when rate limited)
|
|
96
96
|
*/
|
|
97
97
|
listApplicationMovements(params: ListAppMovementsParams): Promise<ListAppMovementsResponse>;
|
|
98
98
|
/**
|
|
@@ -110,7 +110,7 @@ export declare class ApplicationsAPIImpl extends BaseAPI implements Applications
|
|
|
110
110
|
*
|
|
111
111
|
* @param params - Pagination and filter options
|
|
112
112
|
* @returns Promise resolving to a paginated list of balances
|
|
113
|
-
* @throws {APIError} When the request fails (404 for an unknown client ID, 429 when rate limited)
|
|
113
|
+
* @throws {APIError} When the request fails (404 for an unknown, inactive or hidden client ID, 429 when rate limited)
|
|
114
114
|
*/
|
|
115
115
|
listApplicationBalances(params: ListAppBalancesParams): Promise<ListAppBalancesResponse>;
|
|
116
116
|
/**
|
|
@@ -121,7 +121,7 @@ export declare class ApplicationsAPIImpl extends BaseAPI implements Applications
|
|
|
121
121
|
*
|
|
122
122
|
* @param params - Optional `since` filter
|
|
123
123
|
* @returns Promise resolving to the application stats
|
|
124
|
-
* @throws {APIError} When the request fails (404 for an unknown client ID, 429 when rate limited)
|
|
124
|
+
* @throws {APIError} When the request fails (404 for an unknown, inactive or hidden client ID, 429 when rate limited)
|
|
125
125
|
*/
|
|
126
126
|
getApplicationStats(params: GetAppStatsParams): Promise<GetAppStatsResponse>;
|
|
127
127
|
}
|
|
@@ -69,7 +69,7 @@ export class ApplicationsAPIImpl extends BaseAPI {
|
|
|
69
69
|
*
|
|
70
70
|
* @param params - Pagination and filter options
|
|
71
71
|
* @returns Promise resolving to a paginated list of orders
|
|
72
|
-
* @throws {APIError} When the request fails (404 for an unknown client ID, 429 when rate limited)
|
|
72
|
+
* @throws {APIError} When the request fails (404 for an unknown, inactive or hidden client ID, 429 when rate limited)
|
|
73
73
|
*/
|
|
74
74
|
async listApplicationOrders(params) {
|
|
75
75
|
validate(ListAppOrdersSchema, params);
|
|
@@ -99,7 +99,7 @@ export class ApplicationsAPIImpl extends BaseAPI {
|
|
|
99
99
|
*
|
|
100
100
|
* @param params - Pagination and filter options
|
|
101
101
|
* @returns Promise resolving to a paginated list of users
|
|
102
|
-
* @throws {APIError} When the request fails (404 for an unknown client ID, 429 when rate limited)
|
|
102
|
+
* @throws {APIError} When the request fails (404 for an unknown, inactive or hidden client ID, 429 when rate limited)
|
|
103
103
|
*/
|
|
104
104
|
async listApplicationUsers(params) {
|
|
105
105
|
validate(ListAppUsersSchema, params);
|
|
@@ -127,7 +127,7 @@ export class ApplicationsAPIImpl extends BaseAPI {
|
|
|
127
127
|
*
|
|
128
128
|
* @param params - Pagination and filter options
|
|
129
129
|
* @returns Promise resolving to a paginated list of movements
|
|
130
|
-
* @throws {APIError} When the request fails (404 for an unknown client ID, 429 when rate limited)
|
|
130
|
+
* @throws {APIError} When the request fails (404 for an unknown, inactive or hidden client ID, 429 when rate limited)
|
|
131
131
|
*/
|
|
132
132
|
async listApplicationMovements(params) {
|
|
133
133
|
validate(ListAppMovementsSchema, params);
|
|
@@ -156,7 +156,7 @@ export class ApplicationsAPIImpl extends BaseAPI {
|
|
|
156
156
|
*
|
|
157
157
|
* @param params - Pagination and filter options
|
|
158
158
|
* @returns Promise resolving to a paginated list of balances
|
|
159
|
-
* @throws {APIError} When the request fails (404 for an unknown client ID, 429 when rate limited)
|
|
159
|
+
* @throws {APIError} When the request fails (404 for an unknown, inactive or hidden client ID, 429 when rate limited)
|
|
160
160
|
*/
|
|
161
161
|
async listApplicationBalances(params) {
|
|
162
162
|
validate(ListAppBalancesSchema, params);
|
|
@@ -176,7 +176,7 @@ export class ApplicationsAPIImpl extends BaseAPI {
|
|
|
176
176
|
*
|
|
177
177
|
* @param params - Optional `since` filter
|
|
178
178
|
* @returns Promise resolving to the application stats
|
|
179
|
-
* @throws {APIError} When the request fails (404 for an unknown client ID, 429 when rate limited)
|
|
179
|
+
* @throws {APIError} When the request fails (404 for an unknown, inactive or hidden client ID, 429 when rate limited)
|
|
180
180
|
*/
|
|
181
181
|
async getApplicationStats(params) {
|
|
182
182
|
return await this.makePublicRequest(perpRoutes.applications.stats({ clientId: params.clientId, since: params.since }));
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* const result = await sdk.buildercodes.claimBuildercodeRewards({
|
|
15
15
|
* token: "0x0000000000000000000000000000000000000002",
|
|
16
16
|
* amount: "1000000",
|
|
17
|
+
* idempotencyKey: crypto.randomUUID(), // keep it across retries of this claim
|
|
17
18
|
* });
|
|
18
19
|
* console.log(`Payout remaining: ${result.payoutBalance}`);
|
|
19
20
|
* console.log(`Now tradeable: ${result.tradingBalance}`);
|
|
@@ -78,18 +79,24 @@ export declare class BuildercodesAPIImpl extends BaseAPI implements Buildercodes
|
|
|
78
79
|
* Throws 503 when the matching engine is unreachable, restarting, or slow to
|
|
79
80
|
* answer. Treat that as an UNKNOWN outcome rather than a rejection: the claim
|
|
80
81
|
* is admitted to the sequencer before its reply is sent, so it may still
|
|
81
|
-
* commit
|
|
82
|
-
* Do not retry automatically, and do not settle it with a balance read: an
|
|
83
|
-
* admitted claim can still be queued, so an unchanged balance does not prove
|
|
84
|
-
* it will not commit. Treat the claim as pending and reconcile first.
|
|
82
|
+
* commit.
|
|
85
83
|
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
84
|
+
* Pass `idempotencyKey` to make that retry safe: the same key and claim
|
|
85
|
+
* retried within 15 minutes returns the first claim's result without moving
|
|
86
|
+
* money again, so a keyed claim's 5xx keeps the SDK's usual `retryable`
|
|
87
|
+
* flag. The same key with a different claim throws 409
|
|
88
|
+
* `IDEMPOTENCY_KEY_CONFLICT`.
|
|
89
|
+
*
|
|
90
|
+
* Without a key a blind retry can claim twice. Do not retry automatically,
|
|
91
|
+
* and do not settle it with a balance read: an admitted claim can still be
|
|
92
|
+
* queued, so an unchanged balance does not prove it will not commit. Treat
|
|
93
|
+
* the claim as pending and reconcile first. Because that warning has to hold
|
|
94
|
+
* for code as well as readers, an unkeyed claim's ambiguous failure (any 5xx,
|
|
95
|
+
* or a network error with no response at all) is thrown with
|
|
96
|
+
* `retryable: false`, against the SDK's usual "every 5xx is retryable" rule.
|
|
97
|
+
* A pre-admission rejection is exempt and stays retryable: a maintenance
|
|
98
|
+
* block, and a sequencer overload (`code: "OVERLOADED"`), both of which are
|
|
99
|
+
* refused before the claim is queued and so committed nothing.
|
|
93
100
|
*/
|
|
94
101
|
claimBuildercodeRewards(params: ClaimBuildercodeRewardsParams): Promise<ClaimBuildercodeRewardsResponse>;
|
|
95
102
|
}
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* const result = await sdk.buildercodes.claimBuildercodeRewards({
|
|
15
15
|
* token: "0x0000000000000000000000000000000000000002",
|
|
16
16
|
* amount: "1000000",
|
|
17
|
+
* idempotencyKey: crypto.randomUUID(), // keep it across retries of this claim
|
|
17
18
|
* });
|
|
18
19
|
* console.log(`Payout remaining: ${result.payoutBalance}`);
|
|
19
20
|
* console.log(`Now tradeable: ${result.tradingBalance}`);
|
|
@@ -36,9 +37,9 @@ const MAINTENANCE_BLOCK_ERROR = "OPERATIONS_BLOCKED";
|
|
|
36
37
|
*/
|
|
37
38
|
const OVERLOADED_ENGINE_CODE = "OVERLOADED";
|
|
38
39
|
/**
|
|
39
|
-
* Clear `retryable` on
|
|
40
|
+
* Clear `retryable` on an unkeyed claim failure whose outcome is UNKNOWN.
|
|
40
41
|
*
|
|
41
|
-
*
|
|
42
|
+
* An unkeyed claim is not idempotent and is admitted to the sequencer before its reply
|
|
42
43
|
* is sent, so a 5xx or a dropped connection can arrive after the claim already
|
|
43
44
|
* committed. `APIError` classifies every 5xx and every network failure as
|
|
44
45
|
* `retryable: true`, and the documented consumer pattern retries whenever that
|
|
@@ -71,7 +72,7 @@ function markAmbiguousOutcomeNonRetryable(error) {
|
|
|
71
72
|
}
|
|
72
73
|
error.retryable = false;
|
|
73
74
|
error.suggestion =
|
|
74
|
-
"The claim's outcome is unknown: it may have committed after this failure. Do not retry automatically, and do not rely on a balance read to decide — an admitted claim can still be queued, so an unchanged balance does not prove it will not commit. Treat the claim as pending and reconcile before issuing another; this
|
|
75
|
+
"The claim's outcome is unknown: it may have committed after this failure. Do not retry automatically, and do not rely on a balance read to decide — an admitted claim can still be queued, so an unchanged balance does not prove it will not commit. Treat the claim as pending and reconcile before issuing another; this claim carried no idempotencyKey, so a retry can claim a second time. Send one to make retries safe.";
|
|
75
76
|
return error;
|
|
76
77
|
}
|
|
77
78
|
/**
|
|
@@ -192,28 +193,43 @@ export class BuildercodesAPIImpl extends BaseAPI {
|
|
|
192
193
|
* Throws 503 when the matching engine is unreachable, restarting, or slow to
|
|
193
194
|
* answer. Treat that as an UNKNOWN outcome rather than a rejection: the claim
|
|
194
195
|
* is admitted to the sequencer before its reply is sent, so it may still
|
|
195
|
-
* commit
|
|
196
|
-
* Do not retry automatically, and do not settle it with a balance read: an
|
|
197
|
-
* admitted claim can still be queued, so an unchanged balance does not prove
|
|
198
|
-
* it will not commit. Treat the claim as pending and reconcile first.
|
|
196
|
+
* commit.
|
|
199
197
|
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
198
|
+
* Pass `idempotencyKey` to make that retry safe: the same key and claim
|
|
199
|
+
* retried within 15 minutes returns the first claim's result without moving
|
|
200
|
+
* money again, so a keyed claim's 5xx keeps the SDK's usual `retryable`
|
|
201
|
+
* flag. The same key with a different claim throws 409
|
|
202
|
+
* `IDEMPOTENCY_KEY_CONFLICT`.
|
|
203
|
+
*
|
|
204
|
+
* Without a key a blind retry can claim twice. Do not retry automatically,
|
|
205
|
+
* and do not settle it with a balance read: an admitted claim can still be
|
|
206
|
+
* queued, so an unchanged balance does not prove it will not commit. Treat
|
|
207
|
+
* the claim as pending and reconcile first. Because that warning has to hold
|
|
208
|
+
* for code as well as readers, an unkeyed claim's ambiguous failure (any 5xx,
|
|
209
|
+
* or a network error with no response at all) is thrown with
|
|
210
|
+
* `retryable: false`, against the SDK's usual "every 5xx is retryable" rule.
|
|
211
|
+
* A pre-admission rejection is exempt and stays retryable: a maintenance
|
|
212
|
+
* block, and a sequencer overload (`code: "OVERLOADED"`), both of which are
|
|
213
|
+
* refused before the claim is queued and so committed nothing.
|
|
207
214
|
*/
|
|
208
215
|
async claimBuildercodeRewards(params) {
|
|
209
216
|
const validated = validate(ClaimBuildercodeRewardsParamsSchema, params);
|
|
217
|
+
const body = validated.idempotencyKey === undefined
|
|
218
|
+
? { token: validated.token, amount: validated.amount }
|
|
219
|
+
: { token: validated.token, amount: validated.amount, idempotencyKey: validated.idempotencyKey };
|
|
210
220
|
try {
|
|
211
221
|
return await this.makeAuthenticatedRequest("/api/v1/buildercodes/rewards/claim", {
|
|
212
222
|
method: "POST",
|
|
213
|
-
body: JSON.stringify(
|
|
223
|
+
body: JSON.stringify(body),
|
|
214
224
|
});
|
|
215
225
|
}
|
|
216
226
|
catch (error) {
|
|
227
|
+
// A keyed claim retried under the same key returns the first claim's
|
|
228
|
+
// result instead of claiming again, so its 5xx keeps the flag `APIError`
|
|
229
|
+
// gave it.
|
|
230
|
+
if (validated.idempotencyKey !== undefined) {
|
|
231
|
+
throw error;
|
|
232
|
+
}
|
|
217
233
|
throw markAmbiguousOutcomeNonRetryable(error);
|
|
218
234
|
}
|
|
219
235
|
}
|
package/dist/api/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This module exports the new simplified APIs for the Monaco SDK.
|
|
5
5
|
*/
|
|
6
|
+
export * from "./analytics";
|
|
6
7
|
export * from "./applications/index";
|
|
7
8
|
export * from "./base";
|
|
8
9
|
export * from "./buildercodes";
|
|
@@ -20,6 +21,7 @@ export * from "./portfolio";
|
|
|
20
21
|
export * from "./positions";
|
|
21
22
|
export * from "./profile";
|
|
22
23
|
export * from "./pulse";
|
|
24
|
+
export * from "./rfq";
|
|
23
25
|
export * from "./sub-accounts";
|
|
24
26
|
export * from "./sweeper";
|
|
25
27
|
export * from "./tradercodes";
|
package/dist/api/index.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This module exports the new simplified APIs for the Monaco SDK.
|
|
5
5
|
*/
|
|
6
|
+
export * from "./analytics";
|
|
6
7
|
export * from "./applications/index";
|
|
7
8
|
export * from "./base";
|
|
8
9
|
export * from "./buildercodes";
|
|
@@ -20,6 +21,7 @@ export * from "./portfolio";
|
|
|
20
21
|
export * from "./positions";
|
|
21
22
|
export * from "./profile";
|
|
22
23
|
export * from "./pulse";
|
|
24
|
+
export * from "./rfq";
|
|
23
25
|
export * from "./sub-accounts";
|
|
24
26
|
export * from "./sweeper";
|
|
25
27
|
export * from "./tradercodes";
|
package/dist/api/market/api.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Candlestick, FundingState, GetCandlesticksParams, GetLiquidationMetricsParams, GetScreenerParams, GetScreenerResponse, GetTradeFlowParams, GetTradingPairsParams, GetTradingPairsResponse, IndexPrice, Interval, LiquidationMetrics, ListAllFundingHistoryParams, ListAllFundingHistoryResponse, ListFundingHistoryParams, ListFundingHistoryResponse, ListLiquidationEventsParams, ListLiquidationEventsResponse, MarketAPI, MarketMetadata, MarketStats, MarkPrice, OpenInterest, PerpMarketConfig, PerpMarketSummary, TradeFlow, TraderMetrics, TradingMode, TradingPair } from "@0xmonaco/types";
|
|
1
|
+
import type { Candlestick, FundingState, GetCandlesticksParams, GetLiquidationMetricsParams, GetScreenerParams, GetScreenerResponse, GetTradeFlowParams, GetTradingPairsParams, GetTradingPairsResponse, IndexPrice, Interval, LiquidationMetrics, ListAllFundingHistoryParams, ListAllFundingHistoryResponse, ListAllLiquidationEventsParams, ListAllLiquidationEventsResponse, ListFundingHistoryParams, ListFundingHistoryResponse, ListInsuranceFundsResponse, ListLiquidationEventsParams, ListLiquidationEventsResponse, MarketAPI, MarketMetadata, MarketStats, MarkPrice, OpenInterest, PerpMarketConfig, PerpMarketSummary, TradeFlow, TraderMetrics, TradingMode, TradingPair } from "@0xmonaco/types";
|
|
2
2
|
import { BaseAPI } from "../base";
|
|
3
3
|
/**
|
|
4
4
|
* Market API Implementation
|
|
@@ -22,6 +22,8 @@ export declare class MarketAPIImpl extends BaseAPI implements MarketAPI {
|
|
|
22
22
|
getTraderMetrics(tradingPairId: string): Promise<TraderMetrics>;
|
|
23
23
|
getTradeFlow(tradingPairId: string, params: GetTradeFlowParams): Promise<TradeFlow>;
|
|
24
24
|
listLiquidationEvents(tradingPairId: string, params?: ListLiquidationEventsParams): Promise<ListLiquidationEventsResponse>;
|
|
25
|
+
listAllLiquidationEvents(params?: ListAllLiquidationEventsParams): Promise<ListAllLiquidationEventsResponse>;
|
|
26
|
+
listInsuranceFunds(): Promise<ListInsuranceFundsResponse>;
|
|
25
27
|
getLiquidationMetrics(tradingPairId: string, params: GetLiquidationMetricsParams): Promise<LiquidationMetrics>;
|
|
26
28
|
getScreener(params?: GetScreenerParams): Promise<GetScreenerResponse>;
|
|
27
29
|
getMarketStats(): Promise<MarketStats>;
|
package/dist/api/market/api.js
CHANGED
|
@@ -125,6 +125,15 @@ export class MarketAPIImpl extends BaseAPI {
|
|
|
125
125
|
validate(GetMarketMetadataSchema, { tradingPairId });
|
|
126
126
|
return await this.makePublicRequest(perpRoutes.market.listLiquidationEvents(tradingPairId, params));
|
|
127
127
|
}
|
|
128
|
+
async listAllLiquidationEvents(params) {
|
|
129
|
+
const response = await this.makePublicRequest(perpRoutes.market.listAllLiquidationEvents(params));
|
|
130
|
+
// An empty page omits the repeated field and the finished cursor.
|
|
131
|
+
return { ...response, events: response.events ?? [], nextPageToken: response.nextPageToken ?? "" };
|
|
132
|
+
}
|
|
133
|
+
async listInsuranceFunds() {
|
|
134
|
+
const response = await this.makePublicRequest(perpRoutes.market.listInsuranceFunds());
|
|
135
|
+
return { funds: response.funds ?? [] };
|
|
136
|
+
}
|
|
128
137
|
async getLiquidationMetrics(tradingPairId, params) {
|
|
129
138
|
validate(GetMarketMetadataSchema, { tradingPairId });
|
|
130
139
|
return await this.makePublicRequest(perpRoutes.market.getLiquidationMetrics(tradingPairId, params));
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import type { OrderbookEvent, OrderbookQuotationMode, TradingMode } from "@0xmonaco/types";
|
|
2
2
|
import { BaseAPI } from "../base";
|
|
3
3
|
export interface GetOrderbookOptions {
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* Number of price levels per side (max 1000). Defaults to 10. Above 100 the
|
|
6
|
+
* snapshot comes from the market-data book and carries `bookSeq`.
|
|
7
|
+
*/
|
|
5
8
|
depth?: number;
|
|
6
9
|
/** Trading mode: 'Spot' or 'Margin'. Defaults to 'Spot'. */
|
|
7
10
|
tradingMode?: TradingMode;
|
|
8
|
-
/** Price grouping magnitude. Valid values: 0.0001, 0.001, 0.01, 0.1, 1, 10, 100, 1000, 10000. */
|
|
11
|
+
/** Price grouping magnitude. Valid values: 0.000001, 0.00001, 0.0001, 0.001, 0.01, 0.1, 1, 10, 100, 1000, 10000. */
|
|
9
12
|
magnitude?: number;
|
|
10
13
|
/** Quantity denomination: 'BASE' or 'QUOTE'. When 'QUOTE', quantities are multiplied by price. */
|
|
11
14
|
denomination?: OrderbookQuotationMode;
|
|
@@ -33,6 +33,8 @@ export class OrderbookAPIImpl extends BaseAPI {
|
|
|
33
33
|
quoteDecimals: response.quoteDecimals,
|
|
34
34
|
timestamp: response.timestamp,
|
|
35
35
|
sequence: response.sequenceNumber,
|
|
36
|
+
// Kept as the wire's decimal string: a u64 can exceed Number.MAX_SAFE_INTEGER.
|
|
37
|
+
...(response.bookSeq != null ? { bookSeq: response.bookSeq } : {}),
|
|
36
38
|
};
|
|
37
39
|
}
|
|
38
40
|
}
|
|
@@ -1,4 +1,59 @@
|
|
|
1
1
|
export declare const perpRoutes: {
|
|
2
|
+
readonly analytics: {
|
|
3
|
+
readonly protocolTotals: (params?: {
|
|
4
|
+
window?: string;
|
|
5
|
+
startTime?: number;
|
|
6
|
+
endTime?: number;
|
|
7
|
+
}) => string;
|
|
8
|
+
readonly protocolSeries: (params?: {
|
|
9
|
+
window?: string;
|
|
10
|
+
startTime?: number;
|
|
11
|
+
endTime?: number;
|
|
12
|
+
}) => string;
|
|
13
|
+
readonly marketVolumes: (params?: {
|
|
14
|
+
window?: string;
|
|
15
|
+
startTime?: number;
|
|
16
|
+
endTime?: number;
|
|
17
|
+
limit?: number;
|
|
18
|
+
}) => string;
|
|
19
|
+
readonly treasuryNetFees: () => string;
|
|
20
|
+
readonly builders: () => string;
|
|
21
|
+
readonly builder: (builder: string) => string;
|
|
22
|
+
readonly builderTotals: (builder: string, params?: {
|
|
23
|
+
window?: string;
|
|
24
|
+
startTime?: number;
|
|
25
|
+
endTime?: number;
|
|
26
|
+
}) => string;
|
|
27
|
+
readonly builderSeries: (builder: string, params?: {
|
|
28
|
+
window?: string;
|
|
29
|
+
startTime?: number;
|
|
30
|
+
endTime?: number;
|
|
31
|
+
}) => string;
|
|
32
|
+
readonly builderLeaderboard: (params?: {
|
|
33
|
+
window?: string;
|
|
34
|
+
startTime?: number;
|
|
35
|
+
endTime?: number;
|
|
36
|
+
limit?: number;
|
|
37
|
+
}) => string;
|
|
38
|
+
readonly walletLeaderboard: (params?: {
|
|
39
|
+
limit?: number;
|
|
40
|
+
}) => string;
|
|
41
|
+
readonly walletSummary: (wallet: string) => string;
|
|
42
|
+
readonly walletLiquidations: (wallet: string, params?: {
|
|
43
|
+
pageSize?: number;
|
|
44
|
+
pageToken?: string;
|
|
45
|
+
}) => string;
|
|
46
|
+
readonly tokenCustody: () => string;
|
|
47
|
+
readonly tokenCustodyDetail: (token: string) => string;
|
|
48
|
+
readonly vaultDeposits: (params?: {
|
|
49
|
+
pageSize?: number;
|
|
50
|
+
pageToken?: string;
|
|
51
|
+
}) => string;
|
|
52
|
+
readonly vaultWithdrawals: (params?: {
|
|
53
|
+
pageSize?: number;
|
|
54
|
+
pageToken?: string;
|
|
55
|
+
}) => string;
|
|
56
|
+
};
|
|
2
57
|
readonly orders: {
|
|
3
58
|
readonly create: () => string;
|
|
4
59
|
readonly list: (params?: {
|
|
@@ -15,6 +70,7 @@ export declare const perpRoutes: {
|
|
|
15
70
|
readonly batchCancel: () => string;
|
|
16
71
|
readonly batchCancelAll: () => string;
|
|
17
72
|
readonly batchCancelAllByPair: (tradingPairId: string) => string;
|
|
73
|
+
readonly cancelAllAfter: () => string;
|
|
18
74
|
readonly batchCreate: () => string;
|
|
19
75
|
readonly batchReplace: () => string;
|
|
20
76
|
readonly listConditional: (params?: {
|
|
@@ -109,6 +165,13 @@ export declare const perpRoutes: {
|
|
|
109
165
|
startTime: number;
|
|
110
166
|
endTime: number;
|
|
111
167
|
}) => string;
|
|
168
|
+
readonly listAllLiquidationEvents: (params?: {
|
|
169
|
+
startTime?: number;
|
|
170
|
+
endTime?: number;
|
|
171
|
+
pageSize?: number;
|
|
172
|
+
pageToken?: string;
|
|
173
|
+
}) => string;
|
|
174
|
+
readonly listInsuranceFunds: () => string;
|
|
112
175
|
readonly getScreener: (params?: {
|
|
113
176
|
page?: number;
|
|
114
177
|
pageSize?: number;
|
|
@@ -132,6 +195,11 @@ export declare const perpRoutes: {
|
|
|
132
195
|
limit?: number;
|
|
133
196
|
}) => string;
|
|
134
197
|
readonly byId: (tradeId: string) => string;
|
|
198
|
+
readonly feed: (params?: {
|
|
199
|
+
takerApplicationId?: string;
|
|
200
|
+
pageSize?: number;
|
|
201
|
+
pageToken?: string;
|
|
202
|
+
}) => string;
|
|
135
203
|
readonly user: (params?: {
|
|
136
204
|
marginAccountId?: string;
|
|
137
205
|
tradingPairId?: string;
|
package/dist/api/perp/routes.js
CHANGED
|
@@ -15,6 +15,24 @@ function withQuery(path, params) {
|
|
|
15
15
|
return query ? `${path}?${query}` : path;
|
|
16
16
|
}
|
|
17
17
|
export const perpRoutes = {
|
|
18
|
+
analytics: {
|
|
19
|
+
protocolTotals: (params) => withQuery(`${API_V1}/analytics/protocol/totals`, params),
|
|
20
|
+
protocolSeries: (params) => withQuery(`${API_V1}/analytics/protocol/series`, params),
|
|
21
|
+
marketVolumes: (params) => withQuery(`${API_V1}/analytics/markets/volume`, params),
|
|
22
|
+
treasuryNetFees: () => `${API_V1}/analytics/treasury/net-fees`,
|
|
23
|
+
builders: () => `${API_V1}/analytics/builders`,
|
|
24
|
+
builder: (builder) => `${API_V1}/analytics/builders/${encodeURIComponent(builder)}`,
|
|
25
|
+
builderTotals: (builder, params) => withQuery(`${API_V1}/analytics/builders/${encodeURIComponent(builder)}/totals`, params),
|
|
26
|
+
builderSeries: (builder, params) => withQuery(`${API_V1}/analytics/builders/${encodeURIComponent(builder)}/series`, params),
|
|
27
|
+
builderLeaderboard: (params) => withQuery(`${API_V1}/analytics/builder-leaderboard`, params),
|
|
28
|
+
walletLeaderboard: (params) => withQuery(`${API_V1}/analytics/wallet-leaderboard`, params),
|
|
29
|
+
walletSummary: (wallet) => `${API_V1}/analytics/wallets/${encodeSegment(wallet)}`,
|
|
30
|
+
walletLiquidations: (wallet, params) => withQuery(`${API_V1}/analytics/wallets/${encodeSegment(wallet)}/liquidations`, params),
|
|
31
|
+
tokenCustody: () => `${API_V1}/analytics/tokens`,
|
|
32
|
+
tokenCustodyDetail: (token) => `${API_V1}/analytics/tokens/${encodeSegment(token)}`,
|
|
33
|
+
vaultDeposits: (params) => withQuery(`${API_V1}/analytics/deposits`, params),
|
|
34
|
+
vaultWithdrawals: (params) => withQuery(`${API_V1}/analytics/withdrawals`, params),
|
|
35
|
+
},
|
|
18
36
|
orders: {
|
|
19
37
|
create: () => `${API_V1}/orders`,
|
|
20
38
|
list: (params) => withQuery(`${API_V1}/orders`, params),
|
|
@@ -24,6 +42,7 @@ export const perpRoutes = {
|
|
|
24
42
|
batchCancel: () => `${API_V1}/orders/batch-cancel`,
|
|
25
43
|
batchCancelAll: () => `${API_V1}/orders/batch-cancel-all`,
|
|
26
44
|
batchCancelAllByPair: (tradingPairId) => `${API_V1}/orders/batch-cancel-all/${encodeSegment(tradingPairId)}`,
|
|
45
|
+
cancelAllAfter: () => `${API_V1}/orders/cancel-all-after`,
|
|
27
46
|
batchCreate: () => `${API_V1}/orders/batch-create`,
|
|
28
47
|
batchReplace: () => `${API_V1}/orders/batch-replace`,
|
|
29
48
|
listConditional: (params) => withQuery(`${API_V1}/orders/conditional`, params),
|
|
@@ -64,6 +83,8 @@ export const perpRoutes = {
|
|
|
64
83
|
getTradeFlow: (tradingPairId, params) => withQuery(`${API_V1}/market/pairs/${encodeSegment(tradingPairId)}/trade-flow`, params),
|
|
65
84
|
listLiquidationEvents: (tradingPairId, params) => withQuery(`${API_V1}/market/pairs/${encodeSegment(tradingPairId)}/liquidation-events`, params),
|
|
66
85
|
getLiquidationMetrics: (tradingPairId, params) => withQuery(`${API_V1}/market/pairs/${encodeSegment(tradingPairId)}/liquidation-metrics`, params),
|
|
86
|
+
listAllLiquidationEvents: (params) => withQuery(`${API_V1}/market/liquidation-events`, params),
|
|
87
|
+
listInsuranceFunds: () => `${API_V1}/market/insurance-funds`,
|
|
67
88
|
getScreener: (params) => withQuery(`${API_V1}/market/screener`, params),
|
|
68
89
|
getMarketStats: () => `${API_V1}/market/stats`,
|
|
69
90
|
},
|
|
@@ -73,6 +94,7 @@ export const perpRoutes = {
|
|
|
73
94
|
trades: {
|
|
74
95
|
publicByPair: (tradingPairId, params) => withQuery(`${API_V1}/trades/${encodeSegment(tradingPairId)}`, params),
|
|
75
96
|
byId: (tradeId) => `${API_V1}/trades/by-id/${encodeSegment(tradeId)}`,
|
|
97
|
+
feed: (params) => withQuery(`${API_V1}/trades`, params),
|
|
76
98
|
user: (params) => withQuery(`${API_V1}/accounts/trades`, params),
|
|
77
99
|
},
|
|
78
100
|
applications: {
|