@0xmonaco/core 1.0.58 → 1.0.60
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/dist/api/auth/api.d.ts +18 -4
- package/dist/api/auth/api.js +17 -3
- package/dist/api/buildercodes/api.d.ts +81 -0
- package/dist/api/buildercodes/api.js +182 -0
- package/dist/api/buildercodes/index.d.ts +6 -0
- package/dist/api/buildercodes/index.js +6 -0
- package/dist/api/index.d.ts +2 -0
- package/dist/api/index.js +2 -0
- package/dist/api/managed-markets/index.d.ts +8 -0
- package/dist/api/managed-markets/index.js +24 -0
- package/dist/api/margin-accounts/api.js +3 -1
- package/dist/api/websocket/websocket.js +19 -0
- package/dist/coverage.d.ts +8 -0
- package/dist/coverage.js +8 -0
- package/dist/sdk.d.ts +3 -1
- package/dist/sdk.js +10 -0
- package/package.json +3 -3
package/dist/api/auth/api.d.ts
CHANGED
|
@@ -75,10 +75,24 @@ export declare class AuthAPIImpl extends BaseAPI implements AuthAPI {
|
|
|
75
75
|
/**
|
|
76
76
|
* Signs a challenge message using the wallet client.
|
|
77
77
|
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
78
|
+
* Asks the connected wallet to authorize the message, proving control of the
|
|
79
|
+
* address. An EOA signs it with its private key (EIP-191 `personal_sign`). A
|
|
80
|
+
* smart-contract wallet such as a Safe has no private key and returns a
|
|
81
|
+
* signature its own contract will accept, which the server checks under
|
|
82
|
+
* EIP-1271; the wallet client handles that difference, and the returned value
|
|
83
|
+
* is submitted unchanged either way.
|
|
84
|
+
*
|
|
85
|
+
* The returned signature is therefore not guaranteed to be 65 bytes — a
|
|
86
|
+
* contract signature is usually longer — so callers must not assume the EOA
|
|
87
|
+
* shape.
|
|
88
|
+
*
|
|
89
|
+
* Note the scope. Server-side EIP-1271 verification is deliberately narrow:
|
|
90
|
+
* it is offered only to a wallet holding a BuilderCodes payout bucket, on a
|
|
91
|
+
* deployment with the contract-wallet flag on and a chain RPC endpoint
|
|
92
|
+
* configured. An ordinary smart-contract trading account is not covered — it
|
|
93
|
+
* still takes the recovery path, which it cannot satisfy.
|
|
94
|
+
*
|
|
95
|
+
* @param message - The message to authorize
|
|
82
96
|
* @returns Promise resolving to the signature
|
|
83
97
|
* @throws {InvalidConfigError} When wallet account is not available
|
|
84
98
|
* @throws {APIError} When signing fails
|
package/dist/api/auth/api.js
CHANGED
|
@@ -102,10 +102,24 @@ export class AuthAPIImpl extends BaseAPI {
|
|
|
102
102
|
/**
|
|
103
103
|
* Signs a challenge message using the wallet client.
|
|
104
104
|
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
105
|
+
* Asks the connected wallet to authorize the message, proving control of the
|
|
106
|
+
* address. An EOA signs it with its private key (EIP-191 `personal_sign`). A
|
|
107
|
+
* smart-contract wallet such as a Safe has no private key and returns a
|
|
108
|
+
* signature its own contract will accept, which the server checks under
|
|
109
|
+
* EIP-1271; the wallet client handles that difference, and the returned value
|
|
110
|
+
* is submitted unchanged either way.
|
|
107
111
|
*
|
|
108
|
-
*
|
|
112
|
+
* The returned signature is therefore not guaranteed to be 65 bytes — a
|
|
113
|
+
* contract signature is usually longer — so callers must not assume the EOA
|
|
114
|
+
* shape.
|
|
115
|
+
*
|
|
116
|
+
* Note the scope. Server-side EIP-1271 verification is deliberately narrow:
|
|
117
|
+
* it is offered only to a wallet holding a BuilderCodes payout bucket, on a
|
|
118
|
+
* deployment with the contract-wallet flag on and a chain RPC endpoint
|
|
119
|
+
* configured. An ordinary smart-contract trading account is not covered — it
|
|
120
|
+
* still takes the recovery path, which it cannot satisfy.
|
|
121
|
+
*
|
|
122
|
+
* @param message - The message to authorize
|
|
109
123
|
* @returns Promise resolving to the signature
|
|
110
124
|
* @throws {InvalidConfigError} When wallet account is not available
|
|
111
125
|
* @throws {APIError} When signing fails
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BuilderCodes API Implementation
|
|
3
|
+
*
|
|
4
|
+
* Provides authenticated reads of an enrolled frontend's BuilderCodes program,
|
|
5
|
+
* earnings, and reserved balance, plus the claim into a tradeable balance.
|
|
6
|
+
*
|
|
7
|
+
* `claimBuildercodeRewards` requires authentication: the payout bucket is
|
|
8
|
+
* resolved from the authenticated caller's own wallet address, so a caller can
|
|
9
|
+
* only ever claim their own accrued balance.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* // Claim accrued payout balance into a trading balance (authenticated)
|
|
14
|
+
* const result = await sdk.buildercodes.claimBuildercodeRewards({
|
|
15
|
+
* token: "0x0000000000000000000000000000000000000002",
|
|
16
|
+
* amount: "1000000",
|
|
17
|
+
* });
|
|
18
|
+
* console.log(`Payout remaining: ${result.payoutBalance}`);
|
|
19
|
+
* console.log(`Now tradeable: ${result.tradingBalance}`);
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
import type { BuildercodesAPI, ClaimBuildercodeRewardsParams, ClaimBuildercodeRewardsResponse, GetBuildercodePayoutSummaryResponse, GetBuildercodeRewardsBalanceResponse, GetBuildercodesConfigResponse, ListBuildercodePayoutsParams, ListBuildercodePayoutsResponse } from "@0xmonaco/types";
|
|
23
|
+
import { BaseAPI } from "../base";
|
|
24
|
+
export declare class BuildercodesAPIImpl extends BaseAPI implements BuildercodesAPI {
|
|
25
|
+
/**
|
|
26
|
+
* Read this frontend's current BuilderCodes program state.
|
|
27
|
+
*
|
|
28
|
+
* The application comes from the authenticated session; callers cannot
|
|
29
|
+
* select another application. The authenticated wallet must match the
|
|
30
|
+
* application's configured payout address.
|
|
31
|
+
*/
|
|
32
|
+
getConfig(): Promise<GetBuildercodesConfigResponse>;
|
|
33
|
+
/**
|
|
34
|
+
* List this frontend's per-trade BuilderCodes credits, newest first.
|
|
35
|
+
*
|
|
36
|
+
* The server scopes every query to the authenticated application; neither
|
|
37
|
+
* the application id nor payout wallet can be supplied by the caller.
|
|
38
|
+
*/
|
|
39
|
+
listPayouts(params?: ListBuildercodePayoutsParams): Promise<ListBuildercodePayoutsResponse>;
|
|
40
|
+
/**
|
|
41
|
+
* Summarize this frontend's BuilderCodes earnings by token.
|
|
42
|
+
*
|
|
43
|
+
* Amounts are RAW atomic units and remain separated by token.
|
|
44
|
+
*/
|
|
45
|
+
getPayoutSummary(): Promise<GetBuildercodePayoutSummaryResponse>;
|
|
46
|
+
/**
|
|
47
|
+
* Read the authenticated wallet's available BuilderCodes reward balances.
|
|
48
|
+
*
|
|
49
|
+
* Current enrollment is not required: a former payout wallet can still see
|
|
50
|
+
* and claim the balance it accrued before an address rotation.
|
|
51
|
+
*/
|
|
52
|
+
getRewardsBalance(): Promise<GetBuildercodeRewardsBalanceResponse>;
|
|
53
|
+
/**
|
|
54
|
+
* Claim accrued BuilderCodes payout balance into a trading balance.
|
|
55
|
+
*
|
|
56
|
+
* Throws 403 when the caller is refused — either BuilderCodes is not
|
|
57
|
+
* enabled, or the session is a delegated agent. Delegated sessions are
|
|
58
|
+
* refused before the feature flag is read, so a 403 there is permanent for
|
|
59
|
+
* that session type rather than a rollout state.
|
|
60
|
+
*
|
|
61
|
+
* Throws 409 when the payout balance is insufficient for the requested
|
|
62
|
+
* amount (including when the caller has never accrued a share).
|
|
63
|
+
*
|
|
64
|
+
* Throws 503 when the matching engine is unreachable, restarting, or slow to
|
|
65
|
+
* answer. Treat that as an UNKNOWN outcome rather than a rejection: the claim
|
|
66
|
+
* is admitted to the sequencer before its reply is sent, so it may still
|
|
67
|
+
* commit, and there is no idempotency key — a blind retry can claim twice.
|
|
68
|
+
* Do not retry automatically, and do not settle it with a balance read: an
|
|
69
|
+
* admitted claim can still be queued, so an unchanged balance does not prove
|
|
70
|
+
* it will not commit. Treat the claim as pending and reconcile first.
|
|
71
|
+
*
|
|
72
|
+
* Because that warning has to hold for code as well as readers, an ambiguous
|
|
73
|
+
* failure (any 5xx, or a network error with no response at all) is thrown
|
|
74
|
+
* with `retryable: false`, against the SDK's usual "every 5xx is retryable"
|
|
75
|
+
* rule, so a caller driving retries off that flag cannot claim twice. A
|
|
76
|
+
* pre-admission rejection is exempt and stays retryable: a maintenance block,
|
|
77
|
+
* and a sequencer overload (`code: "OVERLOADED"`), both of which are refused
|
|
78
|
+
* before the claim is queued and so committed nothing.
|
|
79
|
+
*/
|
|
80
|
+
claimBuildercodeRewards(params: ClaimBuildercodeRewardsParams): Promise<ClaimBuildercodeRewardsResponse>;
|
|
81
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BuilderCodes API Implementation
|
|
3
|
+
*
|
|
4
|
+
* Provides authenticated reads of an enrolled frontend's BuilderCodes program,
|
|
5
|
+
* earnings, and reserved balance, plus the claim into a tradeable balance.
|
|
6
|
+
*
|
|
7
|
+
* `claimBuildercodeRewards` requires authentication: the payout bucket is
|
|
8
|
+
* resolved from the authenticated caller's own wallet address, so a caller can
|
|
9
|
+
* only ever claim their own accrued balance.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* // Claim accrued payout balance into a trading balance (authenticated)
|
|
14
|
+
* const result = await sdk.buildercodes.claimBuildercodeRewards({
|
|
15
|
+
* token: "0x0000000000000000000000000000000000000002",
|
|
16
|
+
* amount: "1000000",
|
|
17
|
+
* });
|
|
18
|
+
* console.log(`Payout remaining: ${result.payoutBalance}`);
|
|
19
|
+
* console.log(`Now tradeable: ${result.tradingBalance}`);
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
import { ClaimBuildercodeRewardsParamsSchema, ListBuildercodePayoutsParamsSchema, validate } from "@0xmonaco/types";
|
|
23
|
+
import { APIError } from "../../errors";
|
|
24
|
+
import { BaseAPI } from "../base";
|
|
25
|
+
/**
|
|
26
|
+
* REST `error` code carried by a deliberate maintenance block. The write guard
|
|
27
|
+
* runs as middleware BEFORE the handler, so nothing was admitted to the
|
|
28
|
+
* sequencer and the claim provably did not commit — that 503 stays retryable.
|
|
29
|
+
*/
|
|
30
|
+
const MAINTENANCE_BLOCK_ERROR = "OPERATIONS_BLOCKED";
|
|
31
|
+
/**
|
|
32
|
+
* Stable engine `code` for a sequencer admission rejection. The engine refuses a
|
|
33
|
+
* full lane strictly before sequencing, so the command was never queued and left
|
|
34
|
+
* no durable-log or state footprint — provably nothing committed, and exactly the
|
|
35
|
+
* case a client SHOULD retry with backoff.
|
|
36
|
+
*/
|
|
37
|
+
const OVERLOADED_ENGINE_CODE = "OVERLOADED";
|
|
38
|
+
/**
|
|
39
|
+
* Clear `retryable` on a claim failure whose outcome is UNKNOWN.
|
|
40
|
+
*
|
|
41
|
+
* A claim is not idempotent and is admitted to the sequencer before its reply
|
|
42
|
+
* is sent, so a 5xx or a dropped connection can arrive after the claim already
|
|
43
|
+
* committed. `APIError` classifies every 5xx and every network failure as
|
|
44
|
+
* `retryable: true`, and the documented consumer pattern retries whenever that
|
|
45
|
+
* flag is set — which would claim a second amount. The prose warning on the
|
|
46
|
+
* method is not enough on its own: the flag is the machine-readable signal, so
|
|
47
|
+
* it has to agree with it.
|
|
48
|
+
*
|
|
49
|
+
* Left alone deliberately: the two 503s that are provably PRE-admission and so
|
|
50
|
+
* committed nothing — a maintenance block (`OPERATIONS_BLOCKED`, refused in
|
|
51
|
+
* middleware ahead of the handler) and a sequencer admission rejection
|
|
52
|
+
* (`OVERLOADED`, refused before the command is queued) — plus every 4xx, which
|
|
53
|
+
* is a decided outcome. Marking those non-retryable would tell a client to
|
|
54
|
+
* reconcile a claim that never existed, and would stop it backing off and
|
|
55
|
+
* retrying an overload, which is the one 503 that most wants a retry.
|
|
56
|
+
*
|
|
57
|
+
* The error is mutated rather than replaced so the endpoint, status, request id
|
|
58
|
+
* and response body all survive for the caller's logs; `APIError`'s constructor
|
|
59
|
+
* recomputes `retryable` from the status, so a fresh instance could not carry
|
|
60
|
+
* the override anyway.
|
|
61
|
+
*/
|
|
62
|
+
function markAmbiguousOutcomeNonRetryable(error) {
|
|
63
|
+
if (!(error instanceof APIError) || !error.retryable) {
|
|
64
|
+
return error;
|
|
65
|
+
}
|
|
66
|
+
// No status at all means the response was never seen — the most ambiguous
|
|
67
|
+
// case of the lot, since the request may well have been served.
|
|
68
|
+
const outcomeUnknown = error.statusCode === undefined || error.statusCode >= 500;
|
|
69
|
+
if (!outcomeUnknown || isPreAdmissionRejection(error)) {
|
|
70
|
+
return error;
|
|
71
|
+
}
|
|
72
|
+
error.retryable = false;
|
|
73
|
+
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 endpoint has no idempotency key, so a retry can claim a second time.";
|
|
75
|
+
return error;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Whether the failure was refused before the claim could be admitted to the
|
|
79
|
+
* sequencer, which makes it provably non-committing and safe to retry.
|
|
80
|
+
*
|
|
81
|
+
* `error` is the gateway's own classification; `code` is the stable engine code
|
|
82
|
+
* the matching engine tags onto an otherwise-ambiguous `Unavailable`.
|
|
83
|
+
*/
|
|
84
|
+
function isPreAdmissionRejection(error) {
|
|
85
|
+
const body = error.responseBody;
|
|
86
|
+
if (body === null || typeof body !== "object") {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
const { error: errorCode, code: engineCode } = body;
|
|
90
|
+
return errorCode === MAINTENANCE_BLOCK_ERROR || engineCode === OVERLOADED_ENGINE_CODE;
|
|
91
|
+
}
|
|
92
|
+
export class BuildercodesAPIImpl extends BaseAPI {
|
|
93
|
+
/**
|
|
94
|
+
* Read this frontend's current BuilderCodes program state.
|
|
95
|
+
*
|
|
96
|
+
* The application comes from the authenticated session; callers cannot
|
|
97
|
+
* select another application. The authenticated wallet must match the
|
|
98
|
+
* application's configured payout address.
|
|
99
|
+
*/
|
|
100
|
+
async getConfig() {
|
|
101
|
+
return this.makeAuthenticatedRequest("/api/v1/buildercodes/config", {
|
|
102
|
+
method: "GET",
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* List this frontend's per-trade BuilderCodes credits, newest first.
|
|
107
|
+
*
|
|
108
|
+
* The server scopes every query to the authenticated application; neither
|
|
109
|
+
* the application id nor payout wallet can be supplied by the caller.
|
|
110
|
+
*/
|
|
111
|
+
async listPayouts(params) {
|
|
112
|
+
if (params) {
|
|
113
|
+
validate(ListBuildercodePayoutsParamsSchema, params);
|
|
114
|
+
}
|
|
115
|
+
const searchParams = new URLSearchParams();
|
|
116
|
+
if (params?.page !== undefined) {
|
|
117
|
+
searchParams.append("page", params.page.toString());
|
|
118
|
+
}
|
|
119
|
+
if (params?.pageSize !== undefined) {
|
|
120
|
+
searchParams.append("pageSize", params.pageSize.toString());
|
|
121
|
+
}
|
|
122
|
+
const query = searchParams.toString();
|
|
123
|
+
const path = query ? `/api/v1/buildercodes/payouts?${query}` : "/api/v1/buildercodes/payouts";
|
|
124
|
+
return this.makeAuthenticatedRequest(path, { method: "GET" });
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Summarize this frontend's BuilderCodes earnings by token.
|
|
128
|
+
*
|
|
129
|
+
* Amounts are RAW atomic units and remain separated by token.
|
|
130
|
+
*/
|
|
131
|
+
async getPayoutSummary() {
|
|
132
|
+
return this.makeAuthenticatedRequest("/api/v1/buildercodes/payouts/summary", { method: "GET" });
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Read the authenticated wallet's available BuilderCodes reward balances.
|
|
136
|
+
*
|
|
137
|
+
* Current enrollment is not required: a former payout wallet can still see
|
|
138
|
+
* and claim the balance it accrued before an address rotation.
|
|
139
|
+
*/
|
|
140
|
+
async getRewardsBalance() {
|
|
141
|
+
return this.makeAuthenticatedRequest("/api/v1/buildercodes/rewards/balance", { method: "GET" });
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Claim accrued BuilderCodes payout balance into a trading balance.
|
|
145
|
+
*
|
|
146
|
+
* Throws 403 when the caller is refused — either BuilderCodes is not
|
|
147
|
+
* enabled, or the session is a delegated agent. Delegated sessions are
|
|
148
|
+
* refused before the feature flag is read, so a 403 there is permanent for
|
|
149
|
+
* that session type rather than a rollout state.
|
|
150
|
+
*
|
|
151
|
+
* Throws 409 when the payout balance is insufficient for the requested
|
|
152
|
+
* amount (including when the caller has never accrued a share).
|
|
153
|
+
*
|
|
154
|
+
* Throws 503 when the matching engine is unreachable, restarting, or slow to
|
|
155
|
+
* answer. Treat that as an UNKNOWN outcome rather than a rejection: the claim
|
|
156
|
+
* is admitted to the sequencer before its reply is sent, so it may still
|
|
157
|
+
* commit, and there is no idempotency key — a blind retry can claim twice.
|
|
158
|
+
* Do not retry automatically, and do not settle it with a balance read: an
|
|
159
|
+
* admitted claim can still be queued, so an unchanged balance does not prove
|
|
160
|
+
* it will not commit. Treat the claim as pending and reconcile first.
|
|
161
|
+
*
|
|
162
|
+
* Because that warning has to hold for code as well as readers, an ambiguous
|
|
163
|
+
* failure (any 5xx, or a network error with no response at all) is thrown
|
|
164
|
+
* with `retryable: false`, against the SDK's usual "every 5xx is retryable"
|
|
165
|
+
* rule, so a caller driving retries off that flag cannot claim twice. A
|
|
166
|
+
* pre-admission rejection is exempt and stays retryable: a maintenance block,
|
|
167
|
+
* and a sequencer overload (`code: "OVERLOADED"`), both of which are refused
|
|
168
|
+
* before the claim is queued and so committed nothing.
|
|
169
|
+
*/
|
|
170
|
+
async claimBuildercodeRewards(params) {
|
|
171
|
+
const validated = validate(ClaimBuildercodeRewardsParamsSchema, params);
|
|
172
|
+
try {
|
|
173
|
+
return await this.makeAuthenticatedRequest("/api/v1/buildercodes/rewards/claim", {
|
|
174
|
+
method: "POST",
|
|
175
|
+
body: JSON.stringify({ token: validated.token, amount: validated.amount }),
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
throw markAmbiguousOutcomeNonRetryable(error);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
package/dist/api/index.d.ts
CHANGED
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export * from "./applications/index";
|
|
7
7
|
export * from "./base";
|
|
8
|
+
export * from "./buildercodes";
|
|
8
9
|
export * from "./delegated-agents";
|
|
9
10
|
export * from "./faucet";
|
|
10
11
|
export * from "./fees";
|
|
12
|
+
export * from "./managed-markets";
|
|
11
13
|
export * from "./margin-accounts";
|
|
12
14
|
export * from "./market";
|
|
13
15
|
export * from "./orderbook";
|
package/dist/api/index.js
CHANGED
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export * from "./applications/index";
|
|
7
7
|
export * from "./base";
|
|
8
|
+
export * from "./buildercodes";
|
|
8
9
|
export * from "./delegated-agents";
|
|
9
10
|
export * from "./faucet";
|
|
10
11
|
export * from "./fees";
|
|
12
|
+
export * from "./managed-markets";
|
|
11
13
|
export * from "./margin-accounts";
|
|
12
14
|
export * from "./market";
|
|
13
15
|
export * from "./orderbook";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ClaimManagedMarketLeaseRequest, ListManagedMarketAssignmentsRequest, ListManagedMarketAssignmentsResponse, ManagedMarketLease, ManagedMarketQuoteStatus, ManagedMarketsAPI, RefreshManagedMarketQuotesRequest } from "@0xmonaco/types";
|
|
2
|
+
import { BaseAPI } from "../base";
|
|
3
|
+
/** Managed quote intents use the existing wallet session and never move funding. */
|
|
4
|
+
export declare class ManagedMarketsAPIImpl extends BaseAPI implements ManagedMarketsAPI {
|
|
5
|
+
listAssignments(request?: ListManagedMarketAssignmentsRequest): Promise<ListManagedMarketAssignmentsResponse>;
|
|
6
|
+
claimLease(launchId: string, request: ClaimManagedMarketLeaseRequest): Promise<ManagedMarketLease>;
|
|
7
|
+
refreshQuotes(launchId: string, request: RefreshManagedMarketQuotesRequest): Promise<ManagedMarketQuoteStatus>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BaseAPI } from "../base";
|
|
2
|
+
/** Managed quote intents use the existing wallet session and never move funding. */
|
|
3
|
+
export class ManagedMarketsAPIImpl extends BaseAPI {
|
|
4
|
+
async listAssignments(request = {}) {
|
|
5
|
+
const query = new URLSearchParams();
|
|
6
|
+
if (request.page !== undefined)
|
|
7
|
+
query.set("page", String(request.page));
|
|
8
|
+
if (request.pageSize !== undefined)
|
|
9
|
+
query.set("pageSize", String(request.pageSize));
|
|
10
|
+
return this.makeAuthenticatedRequest(`/api/v1/managed-markets/assignments${query.size ? `?${query}` : ""}`);
|
|
11
|
+
}
|
|
12
|
+
async claimLease(launchId, request) {
|
|
13
|
+
return this.makeAuthenticatedRequest(`/api/v1/managed-markets/${encodeURIComponent(launchId)}/lease`, {
|
|
14
|
+
method: "POST",
|
|
15
|
+
body: JSON.stringify(request),
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
async refreshQuotes(launchId, request) {
|
|
19
|
+
return this.makeAuthenticatedRequest(`/api/v1/managed-markets/${encodeURIComponent(launchId)}/quotes`, {
|
|
20
|
+
method: "POST",
|
|
21
|
+
body: JSON.stringify(request),
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -150,7 +150,9 @@ export class MarginAccountsAPIImpl extends BaseAPI {
|
|
|
150
150
|
tradingPairId: request.tradingPairId,
|
|
151
151
|
strategyKey: request.strategyKey,
|
|
152
152
|
marginMode: request.marginMode,
|
|
153
|
-
selectedTradingPairIds:
|
|
153
|
+
// No selectedTradingPairIds: cross scope is derived from trading, and
|
|
154
|
+
// the server ignores the deprecated field. Not sending it keeps a
|
|
155
|
+
// pre-upgrade caller's stale list from reaching the wire at all.
|
|
154
156
|
side: request.side,
|
|
155
157
|
positionSide: request.positionSide,
|
|
156
158
|
orderType: request.orderType,
|
|
@@ -204,10 +204,29 @@ function parsePositionEventData(raw) {
|
|
|
204
204
|
liquidationPrice: readOptionalString(data, "liquidationPrice"),
|
|
205
205
|
isolatedMargin: readString(data, "isolatedMargin"),
|
|
206
206
|
leverage: readString(data, "leverage"),
|
|
207
|
+
// REST parity fields (0XM-2668). All four are optional here even though
|
|
208
|
+
// the server populates the margin requirements on every frame it builds
|
|
209
|
+
// today: this parser also runs against frames produced by an older
|
|
210
|
+
// deployment during a rolling release, and a `readString` on a key that
|
|
211
|
+
// deployment does not send would throw inside the message handler and drop
|
|
212
|
+
// a risk-critical update. `riskBucketId` and `marginMode` are genuinely
|
|
213
|
+
// optional besides — a legacy unbucketed position has neither.
|
|
214
|
+
riskBucketId: readOptionalString(data, "riskBucketId"),
|
|
215
|
+
marginMode: readOptionalString(data, "marginMode"),
|
|
216
|
+
maintenanceMarginRequired: readOptionalString(data, "maintenanceMarginRequired"),
|
|
217
|
+
initialMarginRequired: readOptionalString(data, "initialMarginRequired"),
|
|
207
218
|
tradeId: readOptionalString(data, "tradeId"),
|
|
208
219
|
orderId: readOptionalString(data, "orderId"),
|
|
209
220
|
reason: readString(data, "reason"),
|
|
210
221
|
updatedAt: readString(data, "updatedAt"),
|
|
222
|
+
// Opaque durable row version (0XM-2673). `readOptionalSequence`, not
|
|
223
|
+
// `readOptionalNumber`: this is an ordering counter, so a fractional,
|
|
224
|
+
// negative, or unsafe-integer value would silently corrupt every
|
|
225
|
+
// comparison against it. Same helper the balance version uses. Absent
|
|
226
|
+
// stays absent — a definite 0 would be read as a real revision and lose
|
|
227
|
+
// every `>=` comparison, so the server omits the key rather than sending
|
|
228
|
+
// zero.
|
|
229
|
+
version: readOptionalSequence(data, "version"),
|
|
211
230
|
};
|
|
212
231
|
}
|
|
213
232
|
function parsePositionEvent(rawData) {
|
package/dist/coverage.d.ts
CHANGED
|
@@ -24,6 +24,9 @@ export declare const COVERED: {
|
|
|
24
24
|
get_application_config: string;
|
|
25
25
|
get_application_stats: string;
|
|
26
26
|
get_available_collateral: string;
|
|
27
|
+
get_buildercode_payout_summary: string;
|
|
28
|
+
get_buildercode_rewards_balance: string;
|
|
29
|
+
get_buildercodes_config: string;
|
|
27
30
|
get_candles: string;
|
|
28
31
|
get_faucet_info: string;
|
|
29
32
|
get_funding_state: string;
|
|
@@ -35,6 +38,9 @@ export declare const COVERED: {
|
|
|
35
38
|
get_market_stats: string;
|
|
36
39
|
get_my_fee_tier: string;
|
|
37
40
|
get_pulse: string;
|
|
41
|
+
list_managed_market_assignments: string;
|
|
42
|
+
claim_managed_market_lease: string;
|
|
43
|
+
refresh_managed_market_quotes: string;
|
|
38
44
|
get_sweeper_chains: string;
|
|
39
45
|
get_my_trader_code: string;
|
|
40
46
|
get_rewards_balance: string;
|
|
@@ -80,6 +86,7 @@ export declare const COVERED: {
|
|
|
80
86
|
list_application_movements: string;
|
|
81
87
|
list_application_orders: string;
|
|
82
88
|
list_application_users: string;
|
|
89
|
+
list_buildercode_payouts: string;
|
|
83
90
|
list_conditional_orders: string;
|
|
84
91
|
list_delegated_agent_owners: string;
|
|
85
92
|
list_delegated_agents: string;
|
|
@@ -106,6 +113,7 @@ export declare const COVERED: {
|
|
|
106
113
|
transfer_collateral_to_margin_account: string;
|
|
107
114
|
transfer_collateral_to_parent_margin_account: string;
|
|
108
115
|
transfer_collateral_to_risk_bucket: string;
|
|
116
|
+
claim_buildercode_rewards: string;
|
|
109
117
|
transfer_rewards: string;
|
|
110
118
|
update_sub_account_limit: string;
|
|
111
119
|
upsert_delegated_agent: string;
|
package/dist/coverage.js
CHANGED
|
@@ -24,6 +24,9 @@ export const COVERED = {
|
|
|
24
24
|
get_application_config: "getApplicationConfig",
|
|
25
25
|
get_application_stats: "getApplicationStats",
|
|
26
26
|
get_available_collateral: "getAvailableCollateral",
|
|
27
|
+
get_buildercode_payout_summary: "buildercodes.getPayoutSummary",
|
|
28
|
+
get_buildercode_rewards_balance: "buildercodes.getRewardsBalance",
|
|
29
|
+
get_buildercodes_config: "buildercodes.getConfig",
|
|
27
30
|
get_candles: "getCandlesticks",
|
|
28
31
|
get_faucet_info: "faucet.getInfo",
|
|
29
32
|
get_funding_state: "getFundingState",
|
|
@@ -35,6 +38,9 @@ export const COVERED = {
|
|
|
35
38
|
get_market_stats: "getMarketStats",
|
|
36
39
|
get_my_fee_tier: "getMyFeeTier",
|
|
37
40
|
get_pulse: "pulse.getPulse",
|
|
41
|
+
list_managed_market_assignments: "managedMarkets.listAssignments",
|
|
42
|
+
claim_managed_market_lease: "managedMarkets.claimLease",
|
|
43
|
+
refresh_managed_market_quotes: "managedMarkets.refreshQuotes",
|
|
38
44
|
get_sweeper_chains: "sweeper.getChains",
|
|
39
45
|
get_my_trader_code: "pitpass.getMyTraderCode",
|
|
40
46
|
get_rewards_balance: "pitpass.getRewardsBalance",
|
|
@@ -80,6 +86,7 @@ export const COVERED = {
|
|
|
80
86
|
list_application_movements: "listApplicationMovements",
|
|
81
87
|
list_application_orders: "listApplicationOrders",
|
|
82
88
|
list_application_users: "listApplicationUsers",
|
|
89
|
+
list_buildercode_payouts: "buildercodes.listPayouts",
|
|
83
90
|
list_conditional_orders: "listConditionalOrders",
|
|
84
91
|
list_delegated_agent_owners: "listDelegatedOwners",
|
|
85
92
|
list_delegated_agents: "listDelegatedAgents",
|
|
@@ -106,6 +113,7 @@ export const COVERED = {
|
|
|
106
113
|
transfer_collateral_to_margin_account: "transferCollateralToMarginAccount",
|
|
107
114
|
transfer_collateral_to_parent_margin_account: "transferCollateralToParentMarginAccount",
|
|
108
115
|
transfer_collateral_to_risk_bucket: "transferCollateralToRiskBucket",
|
|
116
|
+
claim_buildercode_rewards: "buildercodes.claimBuildercodeRewards",
|
|
109
117
|
transfer_rewards: "pitpass.transferRewards",
|
|
110
118
|
update_sub_account_limit: "subAccounts.updateLimit",
|
|
111
119
|
upsert_delegated_agent: "upsertDelegatedAgent",
|
package/dist/sdk.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ApplicationsAPI, AuthAPI, AuthState, DelegatedAgentsAPI, FaucetAPI, FeesAPI, MarginAccountsAPI, MarketAPI, MonacoSDK, Network, PitpassAPI, PortfolioAPI, PositionsAPI, ProfileAPI, PulseAPI, SDKConfig, SubAccountsAPI, SweeperAPI, TradingAPI, VaultAPI, WhitelistAPI, WithdrawalsAPI } from "@0xmonaco/types";
|
|
1
|
+
import type { ApplicationsAPI, AuthAPI, AuthState, BuildercodesAPI, DelegatedAgentsAPI, FaucetAPI, FeesAPI, ManagedMarketsAPI, MarginAccountsAPI, MarketAPI, MonacoSDK, Network, PitpassAPI, PortfolioAPI, PositionsAPI, ProfileAPI, PulseAPI, SDKConfig, SubAccountsAPI, SweeperAPI, TradingAPI, VaultAPI, WhitelistAPI, WithdrawalsAPI } from "@0xmonaco/types";
|
|
2
2
|
import { type Address, type PublicClient, type TransactionReceipt, type WalletClient } from "viem";
|
|
3
3
|
import { type MonacoWebSocket, OrderbookAPIImpl, TradesAPIImpl } from "./api";
|
|
4
4
|
export declare class MonacoSDKImpl implements MonacoSDK {
|
|
@@ -6,6 +6,7 @@ export declare class MonacoSDKImpl implements MonacoSDK {
|
|
|
6
6
|
delegatedAgents: DelegatedAgentsAPI;
|
|
7
7
|
applications: ApplicationsAPI;
|
|
8
8
|
fees: FeesAPI;
|
|
9
|
+
buildercodes: BuildercodesAPI;
|
|
9
10
|
pitpass: PitpassAPI;
|
|
10
11
|
vault: VaultAPI;
|
|
11
12
|
withdrawals: WithdrawalsAPI;
|
|
@@ -17,6 +18,7 @@ export declare class MonacoSDKImpl implements MonacoSDK {
|
|
|
17
18
|
subAccounts: SubAccountsAPI;
|
|
18
19
|
faucet: FaucetAPI;
|
|
19
20
|
sweeper: SweeperAPI;
|
|
21
|
+
managedMarkets: ManagedMarketsAPI;
|
|
20
22
|
whitelist: WhitelistAPI;
|
|
21
23
|
profile: ProfileAPI;
|
|
22
24
|
pulse: PulseAPI;
|
package/dist/sdk.js
CHANGED
|
@@ -3,9 +3,11 @@ import { createPublicClient, http } from "viem";
|
|
|
3
3
|
import { sei, seiTestnet } from "viem/chains";
|
|
4
4
|
import { ApplicationsAPIImpl, createMonacoWebSocket, OrderbookAPIImpl, TradesAPIImpl } from "./api";
|
|
5
5
|
import { AuthAPIImpl } from "./api/auth";
|
|
6
|
+
import { BuildercodesAPIImpl } from "./api/buildercodes";
|
|
6
7
|
import { DelegatedAgentsAPIImpl } from "./api/delegated-agents";
|
|
7
8
|
import { FaucetAPIImpl } from "./api/faucet";
|
|
8
9
|
import { FeesAPIImpl } from "./api/fees";
|
|
10
|
+
import { ManagedMarketsAPIImpl } from "./api/managed-markets";
|
|
9
11
|
import { MarginAccountsAPIImpl } from "./api/margin-accounts";
|
|
10
12
|
import { MarketAPIImpl } from "./api/market";
|
|
11
13
|
import { PitpassAPIImpl } from "./api/pitpass";
|
|
@@ -44,6 +46,7 @@ export class MonacoSDKImpl {
|
|
|
44
46
|
delegatedAgents;
|
|
45
47
|
applications;
|
|
46
48
|
fees;
|
|
49
|
+
buildercodes;
|
|
47
50
|
pitpass;
|
|
48
51
|
vault;
|
|
49
52
|
withdrawals;
|
|
@@ -55,6 +58,7 @@ export class MonacoSDKImpl {
|
|
|
55
58
|
subAccounts;
|
|
56
59
|
faucet;
|
|
57
60
|
sweeper;
|
|
61
|
+
managedMarkets;
|
|
58
62
|
whitelist;
|
|
59
63
|
profile;
|
|
60
64
|
pulse;
|
|
@@ -75,6 +79,7 @@ export class MonacoSDKImpl {
|
|
|
75
79
|
this.delegatedAgents.setSessionKeypair(credentials);
|
|
76
80
|
this.applications.setSessionKeypair(credentials);
|
|
77
81
|
this.fees.setSessionKeypair(credentials);
|
|
82
|
+
this.buildercodes.setSessionKeypair(credentials);
|
|
78
83
|
this.pitpass.setSessionKeypair(credentials);
|
|
79
84
|
this.vault.setSessionKeypair(credentials);
|
|
80
85
|
this.withdrawals.setSessionKeypair(credentials);
|
|
@@ -86,6 +91,7 @@ export class MonacoSDKImpl {
|
|
|
86
91
|
this.subAccounts.setSessionKeypair(credentials);
|
|
87
92
|
this.faucet.setSessionKeypair(credentials);
|
|
88
93
|
this.sweeper.setSessionKeypair(credentials);
|
|
94
|
+
this.managedMarkets.setSessionKeypair(credentials);
|
|
89
95
|
this.whitelist.setSessionKeypair(credentials);
|
|
90
96
|
this.pulse.setSessionKeypair(credentials);
|
|
91
97
|
this.profile.setSessionKeypair(credentials);
|
|
@@ -115,6 +121,7 @@ export class MonacoSDKImpl {
|
|
|
115
121
|
this.delegatedAgents.setServerKey(serverKey);
|
|
116
122
|
this.applications.setServerKey(serverKey);
|
|
117
123
|
this.fees.setServerKey(serverKey);
|
|
124
|
+
this.buildercodes.setServerKey(serverKey);
|
|
118
125
|
this.pitpass.setServerKey(serverKey);
|
|
119
126
|
this.vault.setServerKey(serverKey);
|
|
120
127
|
this.withdrawals.setServerKey(serverKey);
|
|
@@ -126,6 +133,7 @@ export class MonacoSDKImpl {
|
|
|
126
133
|
this.subAccounts.setServerKey(serverKey);
|
|
127
134
|
this.faucet.setServerKey(serverKey);
|
|
128
135
|
this.sweeper.setServerKey(serverKey);
|
|
136
|
+
this.managedMarkets.setServerKey(serverKey);
|
|
129
137
|
this.whitelist.setServerKey(serverKey);
|
|
130
138
|
this.pulse.setServerKey(serverKey);
|
|
131
139
|
this.profile.setServerKey(serverKey);
|
|
@@ -193,11 +201,13 @@ export class MonacoSDKImpl {
|
|
|
193
201
|
this.subAccounts = configureSigning(new SubAccountsAPIImpl(apiUrl));
|
|
194
202
|
this.faucet = configureSigning(new FaucetAPIImpl(apiUrl));
|
|
195
203
|
this.sweeper = configureSigning(new SweeperAPIImpl(apiUrl));
|
|
204
|
+
this.managedMarkets = configureSigning(new ManagedMarketsAPIImpl(apiUrl));
|
|
196
205
|
this.whitelist = configureSigning(new WhitelistAPIImpl(apiUrl));
|
|
197
206
|
this.pulse = configureSigning(new PulseAPIImpl(apiUrl));
|
|
198
207
|
this.auth = configureSigning(new AuthAPIImpl(this.walletClient, this.chain, apiUrl));
|
|
199
208
|
this.delegatedAgents = configureSigning(new DelegatedAgentsAPIImpl(apiUrl));
|
|
200
209
|
this.fees = configureSigning(new FeesAPIImpl(apiUrl));
|
|
210
|
+
this.buildercodes = configureSigning(new BuildercodesAPIImpl(apiUrl));
|
|
201
211
|
this.pitpass = configureSigning(new PitpassAPIImpl(apiUrl));
|
|
202
212
|
this.profile = configureSigning(new ProfileAPIImpl(apiUrl));
|
|
203
213
|
this.vault = configureSigning(new VaultAPIImpl(this.publicClient, this.walletClient, this.chain, this.applications, this.profile, apiUrl));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xmonaco/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.60",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"homepage": "https://docs.0xmonaco.com/sdk/typescript",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"viem": "^2.45.2"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@0xmonaco/contracts": "1.0.
|
|
23
|
-
"@0xmonaco/types": "1.0.
|
|
22
|
+
"@0xmonaco/contracts": "1.0.60",
|
|
23
|
+
"@0xmonaco/types": "1.0.60",
|
|
24
24
|
"@noble/curves": "^1.9.1",
|
|
25
25
|
"@noble/hashes": "^2.4.0",
|
|
26
26
|
"http-status-codes": "^2.3.0"
|