@0xmonaco/types 1.0.47 → 1.0.50
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/margin-accounts/index.d.ts +75 -2
- package/dist/portfolio/index.d.ts +12 -0
- package/dist/sdk/index.d.ts +1 -1
- package/dist/sweeper/index.d.ts +49 -27
- package/dist/sweeper/index.js +4 -6
- package/dist/validation/margin-accounts.d.ts +2 -0
- package/dist/validation/margin-accounts.js +4 -0
- package/dist/vault/index.d.ts +7 -1
- package/dist/websocket/events/account-events.d.ts +8 -5
- package/dist/websocket/events/conditional-order-events.d.ts +61 -2
- package/dist/wire/schema.d.ts +142 -21
- package/package.json +2 -2
|
@@ -32,6 +32,42 @@ export interface MarginAccountSummary {
|
|
|
32
32
|
unrealizedPnl: string;
|
|
33
33
|
realizedPnl: string;
|
|
34
34
|
updatedAt: string;
|
|
35
|
+
/**
|
|
36
|
+
* The collateral still available to open NEW orders in this risk bucket:
|
|
37
|
+
* the largest increase in the bucket's worst-case order reserve the risk
|
|
38
|
+
* engine's admission gate accepts, automatic top-up from the parent margin
|
|
39
|
+
* account's unallocated capacity included. Zero while the account or bucket
|
|
40
|
+
* is frozen for liquidation, and for an isolated bucket whose market is
|
|
41
|
+
* halted (a cross bucket's market is chosen per order, so a halt cannot be
|
|
42
|
+
* folded into its figure — a halted pair still refuses orders).
|
|
43
|
+
*
|
|
44
|
+
* The trading-side sibling of `withdrawableCollateral`, and deliberately a
|
|
45
|
+
* different figure: this one credits an unrealized gain in full, because a
|
|
46
|
+
* gain is legitimate initial margin for new positions, while a withdrawal
|
|
47
|
+
* never counts one. It already contains the bucket's live free collateral —
|
|
48
|
+
* do not add `freeCollateral` or `unrealizedPnl` on top. It can also
|
|
49
|
+
* legitimately differ from this row's `freeCollateral`, a persisted
|
|
50
|
+
* reconstruction that cannot see the engine's worst-case resting-order
|
|
51
|
+
* reserve.
|
|
52
|
+
*
|
|
53
|
+
* NOT additive across rows: every bucket's figure includes the SAME parent
|
|
54
|
+
* unallocated headroom, so summing rows multiply-counts it, and committing
|
|
55
|
+
* collateral in one bucket shrinks its siblings' figures.
|
|
56
|
+
*
|
|
57
|
+
* This is a requirement budget, not an order size: an order is charged the
|
|
58
|
+
* increase it causes in the bucket's worst-case per-pair reserve, so a
|
|
59
|
+
* reducing, reduce-only, or opposite-side order sheltered by a larger
|
|
60
|
+
* resting ladder needs less or none of it (and can be admitted even when
|
|
61
|
+
* this field is zero), while an order crossing a losing position can need
|
|
62
|
+
* more than its own margin-plus-fee. Divide by a market's initial margin
|
|
63
|
+
* rate for indicative notional capacity; the authoritative per-order answer
|
|
64
|
+
* remains `simulateRiskBucketOrderRisk`.
|
|
65
|
+
*
|
|
66
|
+
* Present only on risk-bucket rows served from a live risk engine snapshot;
|
|
67
|
+
* absent (the key is omitted, never null) on parent rows and on
|
|
68
|
+
* persisted-fallback reads.
|
|
69
|
+
*/
|
|
70
|
+
availableOrderCollateral?: string;
|
|
35
71
|
}
|
|
36
72
|
export interface ListMarginAccountsParams {
|
|
37
73
|
page?: number;
|
|
@@ -95,17 +131,43 @@ export interface TransferCollateralToParentMarginAccountRequest {
|
|
|
95
131
|
asset: string;
|
|
96
132
|
amount: string;
|
|
97
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Fund a pair's isolated risk bucket from the parent margin account's
|
|
136
|
+
* unallocated collateral (no wallet movement; the bucket is created if
|
|
137
|
+
* needed). What the money becomes when the bucket holds an open position is
|
|
138
|
+
* stated by `applyToPositionMargin` — the two intents want opposite fates for
|
|
139
|
+
* the same dollars. Either way the liquidation cushion improves identically.
|
|
140
|
+
*/
|
|
98
141
|
export interface TransferCollateralToIsolatedRiskBucketRequest extends TransferCollateralToParentMarginAccountRequest {
|
|
99
142
|
marginMode?: "ISOLATED";
|
|
100
143
|
tradingPairId: string;
|
|
101
144
|
strategyKey?: string;
|
|
102
145
|
selectedTradingPairIds?: never;
|
|
146
|
+
/**
|
|
147
|
+
* `true` (and OMITTED — the default is the human "Adjust Margin" gesture):
|
|
148
|
+
* the amount is COMMITTED to the sole open position's stored margin.
|
|
149
|
+
* Effective leverage drops and stays down, initial margin required rises by
|
|
150
|
+
* the amount, free collateral is unchanged — new orders cannot spend it.
|
|
151
|
+
*
|
|
152
|
+
* `false`: plain allocation. Free collateral rises and the next order can
|
|
153
|
+
* spend it. Programmatic funding loops that top a bucket up to a free
|
|
154
|
+
* collateral target MUST pass `false`, or each top-up converts into
|
|
155
|
+
* requirement and the loop never converges.
|
|
156
|
+
*
|
|
157
|
+
* On a flat bucket both values are a plain allocation. The response's
|
|
158
|
+
* `positionMarginCredited` reports what actually happened — a credit can
|
|
159
|
+
* degrade to a plain allocation when the persisted position row is stale
|
|
160
|
+
* (close/reopen race).
|
|
161
|
+
*/
|
|
162
|
+
applyToPositionMargin?: boolean;
|
|
103
163
|
}
|
|
104
164
|
export interface TransferCollateralToCrossRiskBucketRequest extends TransferCollateralToParentMarginAccountRequest {
|
|
105
165
|
marginMode: "CROSS";
|
|
106
166
|
selectedTradingPairIds: string[];
|
|
107
167
|
tradingPairId?: never;
|
|
108
168
|
strategyKey?: never;
|
|
169
|
+
/** Cross risk is pooled at bucket equity — there is no per-position margin; an explicit `true` is rejected. */
|
|
170
|
+
applyToPositionMargin?: never;
|
|
109
171
|
}
|
|
110
172
|
export type TransferCollateralToRiskBucketRequest = TransferCollateralToIsolatedRiskBucketRequest | TransferCollateralToCrossRiskBucketRequest;
|
|
111
173
|
export interface TransferCollateralFromParentMarginAccountRequest {
|
|
@@ -125,6 +187,16 @@ export interface TransferCollateralResponse {
|
|
|
125
187
|
newEquity: string;
|
|
126
188
|
newTotalCollateralValue: string;
|
|
127
189
|
newWithdrawableCollateral: string;
|
|
190
|
+
/**
|
|
191
|
+
* Whether the transfer was committed to a position's stored margin. Present
|
|
192
|
+
* only when a position-margin credit was in play: `true` — the credit
|
|
193
|
+
* landed; `false` — a credit was requested (or defaulted) but degraded to a
|
|
194
|
+
* plain allocation because the bucket's persisted position row was stale
|
|
195
|
+
* (close/reopen race) — re-issue the Adjust Margin once the new position
|
|
196
|
+
* row lands if the commitment still matters. Absent (never null) on plain
|
|
197
|
+
* allocations, parent deposits, and releases.
|
|
198
|
+
*/
|
|
199
|
+
positionMarginCredited?: boolean;
|
|
128
200
|
}
|
|
129
201
|
export interface GetMarginAccountMovementsParams {
|
|
130
202
|
movementType?: string;
|
|
@@ -201,8 +273,9 @@ export interface MarginAccountsAPI extends BaseAPI {
|
|
|
201
273
|
getMarginAccountSummary(marginAccountId: string, params?: GetMarginAccountSummaryParams): Promise<MarginAccountSummary>;
|
|
202
274
|
getAvailableCollateral(params?: GetAvailableCollateralParams): Promise<GetAvailableCollateralResponse>;
|
|
203
275
|
/**
|
|
204
|
-
* @deprecated
|
|
205
|
-
*
|
|
276
|
+
* @deprecated Use `transferCollateralToRiskBucket` for bucket funding
|
|
277
|
+
* (which now credits a sole open position's stored margin the same way) and
|
|
278
|
+
* `transferCollateralToParentMarginAccount` for wallet-to-margin deposits.
|
|
206
279
|
*/
|
|
207
280
|
transferCollateralToMarginAccount(marginAccountId: string, request: TransferCollateralRequest): Promise<TransferCollateralResponse>;
|
|
208
281
|
transferCollateralToParentMarginAccount(request: TransferCollateralToParentMarginAccountRequest): Promise<TransferCollateralResponse>;
|
|
@@ -203,6 +203,18 @@ export interface PortfolioRiskBucket {
|
|
|
203
203
|
* partial withdrawals below it.
|
|
204
204
|
*/
|
|
205
205
|
withdrawableCollateral: string;
|
|
206
|
+
/**
|
|
207
|
+
* The collateral still available to open NEW orders in this risk bucket —
|
|
208
|
+
* the same engine-served admission bound as
|
|
209
|
+
* `MarginAccountSummary.availableOrderCollateral` (see that field for the
|
|
210
|
+
* full semantics: an envelope delta with parent auto top-up included, NOT
|
|
211
|
+
* additive across rows, zero while frozen), truncated toward zero at quote
|
|
212
|
+
* decimals like `withdrawableCollateral` beside it.
|
|
213
|
+
*
|
|
214
|
+
* Present only when a live risk engine snapshot served the bound; absent
|
|
215
|
+
* (the key is omitted, never null) on persisted-fallback reads.
|
|
216
|
+
*/
|
|
217
|
+
availableOrderCollateral?: string;
|
|
206
218
|
}
|
|
207
219
|
export interface PortfolioMargin {
|
|
208
220
|
asOf: string;
|
package/dist/sdk/index.d.ts
CHANGED
|
@@ -109,7 +109,7 @@ export interface MonacoSDK {
|
|
|
109
109
|
pitpass: PitpassAPI;
|
|
110
110
|
/** Testnet faucet API */
|
|
111
111
|
faucet: FaucetAPI;
|
|
112
|
-
/**
|
|
112
|
+
/** Deposit-address registration (sweeper) API; requires a session */
|
|
113
113
|
sweeper: SweeperAPI;
|
|
114
114
|
/** Public whitelist (waitlist) submission API */
|
|
115
115
|
whitelist: WhitelistAPI;
|
package/dist/sweeper/index.d.ts
CHANGED
|
@@ -1,43 +1,59 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Sweeper Types
|
|
3
3
|
*
|
|
4
|
-
* Types for the
|
|
4
|
+
* Types for the deposit-address registration endpoint. Wire shapes are
|
|
5
5
|
* snake_case; these are the camelCase ergonomic forms.
|
|
6
6
|
*
|
|
7
|
-
* NOTE: This endpoint is **
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* they already belong to. Abuse is bounded by a per-client rate limit and an
|
|
11
|
-
* active-application check instead of authentication.
|
|
7
|
+
* NOTE: This endpoint is **authenticated**. The credited address is the calling
|
|
8
|
+
* session's own rather than a request field, so a caller can only ever register
|
|
9
|
+
* an address they hold the session key for.
|
|
12
10
|
*/
|
|
11
|
+
import type { DepositTarget } from "@0xmonaco/contracts";
|
|
13
12
|
import type { BaseAPI } from "../api";
|
|
14
13
|
/**
|
|
15
14
|
* What happened to the registration.
|
|
16
15
|
*
|
|
17
|
-
* - `registered` — the
|
|
18
|
-
* - `already_registered` — the
|
|
16
|
+
* - `registered` — the triple was added; its deposit address is now monitored.
|
|
17
|
+
* - `already_registered` — the triple was known before this call; nothing was
|
|
19
18
|
* re-triggered.
|
|
20
19
|
*/
|
|
21
20
|
export type RegisterSweeperStatus = "registered" | "already_registered";
|
|
22
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Body for a deposit-address registration.
|
|
23
|
+
*
|
|
24
|
+
* Deliberately tiny: the application and the credited address both come from
|
|
25
|
+
* the authenticated session (`login` takes the application's client id), so the
|
|
26
|
+
* only thing left to say is which ledger to aim at.
|
|
27
|
+
*/
|
|
23
28
|
export interface RegisterSweeperRequest {
|
|
24
29
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
30
|
+
* Which ledger swept deposits ask to be credited to. Defaults to `"spot"`.
|
|
31
|
+
*
|
|
32
|
+
* `"margin"` asks for the parent margin account's collateral, skipping the
|
|
33
|
+
* separate `transferCollateralToParentMarginAccount` step. The target is part
|
|
34
|
+
* of the address derivation, so the two targets yield two different deposit
|
|
35
|
+
* addresses for the same pair, each carrying its own request. A `"spot"`
|
|
36
|
+
* address is never credited to margin.
|
|
37
|
+
*
|
|
38
|
+
* `"margin"` is a request rather than a guarantee: a deposit the backend
|
|
39
|
+
* cannot route to collateral — an unsupported collateral asset, or a margin
|
|
40
|
+
* account that fails validation — is credited to the spot wallet instead, so
|
|
41
|
+
* funds are never stranded. Read the balance back rather than treating the
|
|
42
|
+
* address as proof of where the credit landed.
|
|
43
|
+
*
|
|
44
|
+
* An unrecognized value is rejected (400) rather than falling back to spot,
|
|
45
|
+
* which would return an address pointed at a ledger the caller did not ask
|
|
46
|
+
* for.
|
|
29
47
|
*/
|
|
30
|
-
|
|
31
|
-
/** Address credited on the rollup, and half of the deposit-address derivation */
|
|
32
|
-
userAddress: string;
|
|
48
|
+
depositTarget?: DepositTarget;
|
|
33
49
|
}
|
|
34
50
|
/** Result of a deposit-address registration. */
|
|
35
51
|
export interface RegisterSweeperResponse {
|
|
36
|
-
/** Whether this call added the
|
|
52
|
+
/** Whether this call added the triple or it was known before */
|
|
37
53
|
status: RegisterSweeperStatus;
|
|
38
54
|
/**
|
|
39
|
-
* The
|
|
40
|
-
* any contract exists there.
|
|
55
|
+
* The deposit address for this (application, user, deposit target) triple.
|
|
56
|
+
* Stable, and valid to publish and fund before any contract exists there.
|
|
41
57
|
*/
|
|
42
58
|
sweeperAddress: string;
|
|
43
59
|
/**
|
|
@@ -48,20 +64,26 @@ export interface RegisterSweeperResponse {
|
|
|
48
64
|
initialSweepCheck: boolean;
|
|
49
65
|
}
|
|
50
66
|
/**
|
|
51
|
-
* Sweeper API interface. The register endpoint
|
|
67
|
+
* Sweeper API interface. The register endpoint requires authentication.
|
|
52
68
|
*/
|
|
53
69
|
export interface SweeperAPI extends BaseAPI {
|
|
54
70
|
/**
|
|
55
|
-
* Registers an (application, user)
|
|
56
|
-
* address is monitored and every ERC20 deposit is
|
|
57
|
-
* automatically.
|
|
71
|
+
* Registers an (application, user, deposit target) triple so its
|
|
72
|
+
* deterministic deposit address is monitored and every ERC20 deposit is
|
|
73
|
+
* swept into the rollup automatically.
|
|
74
|
+
*
|
|
75
|
+
* The application and the credited address both come from the authenticated
|
|
76
|
+
* session, so this only ever registers the caller's own address under their
|
|
77
|
+
* own application. Call it with no arguments for a spot address.
|
|
58
78
|
*
|
|
59
79
|
* Returns immediately with the derived deposit address; the one-time
|
|
60
80
|
* initial balance check runs in the background. Idempotent and safe to
|
|
61
81
|
* retry: re-registering answers `already_registered` with the same address
|
|
62
|
-
* and never re-triggers the initial check.
|
|
63
|
-
*
|
|
64
|
-
*
|
|
82
|
+
* and never re-triggers the initial check.
|
|
83
|
+
*
|
|
84
|
+
* Throws on an unrecognized `depositTarget` (before sending), when the
|
|
85
|
+
* session's application is no longer active (403), and when the endpoint's
|
|
86
|
+
* global admission limit is exceeded (429).
|
|
65
87
|
*/
|
|
66
|
-
register(body
|
|
88
|
+
register(body?: RegisterSweeperRequest): Promise<RegisterSweeperResponse>;
|
|
67
89
|
}
|
package/dist/sweeper/index.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Sweeper Types
|
|
3
3
|
*
|
|
4
|
-
* Types for the
|
|
4
|
+
* Types for the deposit-address registration endpoint. Wire shapes are
|
|
5
5
|
* snake_case; these are the camelCase ergonomic forms.
|
|
6
6
|
*
|
|
7
|
-
* NOTE: This endpoint is **
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* they already belong to. Abuse is bounded by a per-client rate limit and an
|
|
11
|
-
* active-application check instead of authentication.
|
|
7
|
+
* NOTE: This endpoint is **authenticated**. The credited address is the calling
|
|
8
|
+
* session's own rather than a request field, so a caller can only ever register
|
|
9
|
+
* an address they hold the session key for.
|
|
12
10
|
*/
|
|
@@ -45,6 +45,7 @@ export declare const TransferCollateralToRiskBucketSchema: z.ZodObject<{
|
|
|
45
45
|
strategyKey: z.ZodOptional<z.ZodString>;
|
|
46
46
|
marginMode: z.ZodOptional<z.ZodLiteral<"ISOLATED">>;
|
|
47
47
|
selectedTradingPairIds: z.ZodOptional<z.ZodNever>;
|
|
48
|
+
applyToPositionMargin: z.ZodOptional<z.ZodBoolean>;
|
|
48
49
|
}, z.core.$strict>, z.ZodObject<{
|
|
49
50
|
asset: z.ZodString;
|
|
50
51
|
amount: z.ZodString;
|
|
@@ -139,6 +140,7 @@ export declare const SimulateRiskBucketOrderRiskSchema: z.ZodObject<{
|
|
|
139
140
|
strategyKey: z.ZodOptional<z.ZodString>;
|
|
140
141
|
marginMode: z.ZodOptional<z.ZodLiteral<"ISOLATED">>;
|
|
141
142
|
selectedTradingPairIds: z.ZodOptional<z.ZodNever>;
|
|
143
|
+
applyToPositionMargin: z.ZodOptional<z.ZodBoolean>;
|
|
142
144
|
}, z.core.$strict>, z.ZodObject<{
|
|
143
145
|
tradingPairId: z.ZodUUID;
|
|
144
146
|
side: z.ZodEnum<{
|
|
@@ -51,6 +51,10 @@ const SelectedCrossTradingPairIdsSchema = z.array(UUIDSchema).min(1, "selectedTr
|
|
|
51
51
|
const IsolatedRiskBucketRequestSchema = RiskBucketRequestSchema.extend({
|
|
52
52
|
marginMode: z.literal("ISOLATED").optional(),
|
|
53
53
|
selectedTradingPairIds: z.never().optional(),
|
|
54
|
+
// Omitted defaults server-side to true (the Adjust Margin gesture); false
|
|
55
|
+
// is the plain allocation programmatic funding loops need. The CROSS form
|
|
56
|
+
// stays strict-rejected (no per-position margin to commit to).
|
|
57
|
+
applyToPositionMargin: z.boolean().optional(),
|
|
54
58
|
});
|
|
55
59
|
const CrossRiskBucketScopeSchema = z.object({
|
|
56
60
|
marginMode: z.literal("CROSS"),
|
package/dist/vault/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Types for vault operations including deposits, withdrawals, and balance management.
|
|
5
5
|
*/
|
|
6
|
+
import type { DepositTarget } from "@0xmonaco/contracts";
|
|
6
7
|
import type { Address } from "viem";
|
|
7
8
|
import type { BaseAPI } from "../api/index";
|
|
8
9
|
import type { Balance, TransactionResult, WithdrawalRetryOptions, WithdrawResult } from "./responses";
|
|
@@ -13,8 +14,13 @@ import type { Balance, TransactionResult, WithdrawalRetryOptions, WithdrawResult
|
|
|
13
14
|
* collateral (auto-creating the account if it does not exist yet). A deposit
|
|
14
15
|
* that cannot be routed to margin (unsupported asset, etc.) safely falls back
|
|
15
16
|
* to spot — funds are never lost.
|
|
17
|
+
*
|
|
18
|
+
* Re-exported from `@0xmonaco/contracts` rather than redeclared: the same
|
|
19
|
+
* value selects the on-chain routing hint for a direct deposit and the
|
|
20
|
+
* derivation of a sweeper deposit address, so one definition keeps the two
|
|
21
|
+
* from drifting into separately-maintained unions.
|
|
16
22
|
*/
|
|
17
|
-
export type DepositTarget
|
|
23
|
+
export type { DepositTarget };
|
|
18
24
|
/**
|
|
19
25
|
* Options for a deposit.
|
|
20
26
|
*/
|
|
@@ -42,11 +42,14 @@ export interface AccountEventData {
|
|
|
42
42
|
freeCollateral: string;
|
|
43
43
|
/**
|
|
44
44
|
* Account distress ratio: maintenance margin required over equity (higher is
|
|
45
|
-
* closer to liquidation, decimal string).
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
45
|
+
* closer to liquidation, decimal string). The quotient saturates to the
|
|
46
|
+
* max-decimal sentinel (`79228162514264337593543950335`, maximal distress)
|
|
47
|
+
* whenever it cannot be computed or represented: an account still owing a
|
|
48
|
+
* maintenance requirement at zero or negative equity, and equally at
|
|
49
|
+
* near-zero POSITIVE equity where the true ratio exceeds the decimal range.
|
|
50
|
+
* An empty account with no requirement is `0`. Clamp the sentinel before
|
|
51
|
+
* display; treat any value at or above the liquidation threshold as maximal
|
|
52
|
+
* distress rather than distinguishing the sentinel's causes.
|
|
50
53
|
*/
|
|
51
54
|
marginRatio: string;
|
|
52
55
|
/** Maintenance margin required to keep the account solvent (decimal string) */
|
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
import type { ConditionalOrderConditionType, ConditionalOrderState, ConditionalOrderTriggerSource, OrderSide, OrderType, PositionSide, TimeInForce } from "../../trading";
|
|
2
|
+
/**
|
|
3
|
+
* The canonical `reason` values carried by a **live** conditional-order update.
|
|
4
|
+
*
|
|
5
|
+
* Not the complete set of strings the field can hold: the subscribe-time
|
|
6
|
+
* snapshot reuses this same data shape with the literal `"snapshot"`, and the
|
|
7
|
+
* wire field is a free-form server string rather than a closed enum, so this
|
|
8
|
+
* alias is documentation and a narrowing aid only. Match on it with a default
|
|
9
|
+
* branch; see `ConditionalOrderEventData.reason`.
|
|
10
|
+
*/
|
|
2
11
|
export type ConditionalOrderEventReason = "created" | "activated" | "cancelled" | "parent_cancelled" | "triggered" | "failed" | "oco_cancelled";
|
|
12
|
+
/**
|
|
13
|
+
* A conditional (TP/SL) order's current state.
|
|
14
|
+
*
|
|
15
|
+
* **The value unions below are the values the server can send today, not a
|
|
16
|
+
* runtime guarantee.** `@0xmonaco/core` parses this frame leniently — an
|
|
17
|
+
* unrecognized `orderType`, `state`, `side`, `positionSide`, `conditionType`,
|
|
18
|
+
* `triggerSource`, `associationType` or `timeInForce` is passed through as-is
|
|
19
|
+
* rather than validated, because throwing inside the WebSocket message handler
|
|
20
|
+
* would drop the entire update with nothing surfaced to the consumer
|
|
21
|
+
* (0XM-2627). Most of these unions mirror an exhaustive server-side mapping, so
|
|
22
|
+
* a value outside one means the server gained a variant this SDK version
|
|
23
|
+
* predates. `orderType` is the exception — its mapping ends in a catch-all arm,
|
|
24
|
+
* so its completeness rests on producer validation instead; see that field's
|
|
25
|
+
* own note.
|
|
26
|
+
*
|
|
27
|
+
* Consequently: match on these fields with a `default` branch rather than
|
|
28
|
+
* relying on exhaustiveness, exactly as you would for the free-form `reason`.
|
|
29
|
+
* A dropped frame is a worse failure than an unhandled value, so the parser
|
|
30
|
+
* chooses the latter — the same trade the position, liquidation and
|
|
31
|
+
* market-stats parsers already make.
|
|
32
|
+
*/
|
|
3
33
|
export interface ConditionalOrderEventData {
|
|
4
34
|
conditionalOrderId: string;
|
|
5
35
|
tradingPairId: string;
|
|
@@ -13,12 +43,35 @@ export interface ConditionalOrderEventData {
|
|
|
13
43
|
triggerPrice: string;
|
|
14
44
|
side: OrderSide;
|
|
15
45
|
positionSide: PositionSide;
|
|
46
|
+
/**
|
|
47
|
+
* Order shape the conditional order places when it triggers.
|
|
48
|
+
*
|
|
49
|
+
* `LIMIT` and `MARKET` are the complete set: both creation paths reject
|
|
50
|
+
* anything else — `orderType must be MARKET or LIMIT` from the TP/SL handler
|
|
51
|
+
* and `parent TP/SL order_type must be MARKET or LIMIT` from the matching
|
|
52
|
+
* engine's leg-shape check. The other server-side `OrderType` variants
|
|
53
|
+
* cannot reach this event.
|
|
54
|
+
*
|
|
55
|
+
* Unlike the other fields here, that rests on validation rather than on an
|
|
56
|
+
* exhaustive mapping: the server's `order_type` arm ends in a catch-all that
|
|
57
|
+
* Debug-formats and uppercases the variant, so were validation ever relaxed
|
|
58
|
+
* the value would arrive as e.g. `STOPLOSS` rather than the canonical
|
|
59
|
+
* `STOP_LOSS`. The parser passes such a value through untouched.
|
|
60
|
+
*/
|
|
16
61
|
orderType: OrderType;
|
|
17
62
|
limitPrice?: string;
|
|
18
63
|
quantity?: string;
|
|
19
64
|
slippageToleranceBps?: number;
|
|
20
65
|
reduceOnly: boolean;
|
|
21
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Time in force for a `LIMIT` conditional order; absent for `MARKET`.
|
|
68
|
+
*
|
|
69
|
+
* The full `TimeInForce` enum, not the `GTC`/`IOC` subset the creation paths
|
|
70
|
+
* validate: this field mirrors an unconstrained `time_in_force` column that
|
|
71
|
+
* the server maps exhaustively over every variant, so a value written by any
|
|
72
|
+
* other path reaches the wire as-is. Narrow before relying on the subset.
|
|
73
|
+
*/
|
|
74
|
+
timeInForce?: TimeInForce;
|
|
22
75
|
state: ConditionalOrderState;
|
|
23
76
|
triggeredOrderId?: string;
|
|
24
77
|
triggeredAt?: string;
|
|
@@ -26,7 +79,13 @@ export interface ConditionalOrderEventData {
|
|
|
26
79
|
cancelledAt?: string;
|
|
27
80
|
expiresAt?: string;
|
|
28
81
|
failureReason?: string;
|
|
29
|
-
|
|
82
|
+
/**
|
|
83
|
+
* What produced this update. Free-form on the wire — the server field is a
|
|
84
|
+
* plain string, not an enum — but a live update's canonical values are the
|
|
85
|
+
* ones listed on {@link ConditionalOrderEventReason}. The subscribe-time
|
|
86
|
+
* snapshot builds the same shape with `"snapshot"` instead.
|
|
87
|
+
*/
|
|
88
|
+
reason: string;
|
|
30
89
|
updatedAt: string;
|
|
31
90
|
}
|
|
32
91
|
export interface ConditionalOrderEvent {
|
package/dist/wire/schema.d.ts
CHANGED
|
@@ -869,6 +869,17 @@ export interface paths {
|
|
|
869
869
|
};
|
|
870
870
|
get?: never;
|
|
871
871
|
put?: never;
|
|
872
|
+
/**
|
|
873
|
+
* @deprecated
|
|
874
|
+
* @description DEPRECATED (0XM-2632): this endpoint overloads two unrelated operations —
|
|
875
|
+
* with `trading_pair_id` it allocates into that pair's isolated risk bucket
|
|
876
|
+
* (crediting the sole open position's stored margin), without it it performs
|
|
877
|
+
* a wallet-debiting deposit to the parent margin account. Use
|
|
878
|
+
* `TransferCollateralToRiskBucket` for bucket funding (which now applies the
|
|
879
|
+
* same position-margin credit) and `TransferCollateralToParentMarginAccount`
|
|
880
|
+
* for wallet-to-margin deposits. Kept for backward compatibility; no removal
|
|
881
|
+
* date scheduled.
|
|
882
|
+
*/
|
|
872
883
|
post: operations["transfer_collateral_to_margin_account"];
|
|
873
884
|
delete?: never;
|
|
874
885
|
options?: never;
|
|
@@ -1029,6 +1040,15 @@ export interface paths {
|
|
|
1029
1040
|
};
|
|
1030
1041
|
get?: never;
|
|
1031
1042
|
put?: never;
|
|
1043
|
+
/**
|
|
1044
|
+
* @description Fund a risk bucket from the parent margin account's unallocated
|
|
1045
|
+
* collateral (no wallet movement; the bucket is created if needed). Since
|
|
1046
|
+
* 0XM-2632, funding an ISOLATED bucket that holds an open position also
|
|
1047
|
+
* credits that position's stored margin — the same behavior as the
|
|
1048
|
+
* deprecated `TransferCollateralToMarginAccount` Adjust Margin rail — so
|
|
1049
|
+
* adding collateral to support a position has one behavior on every route.
|
|
1050
|
+
* A flat isolated bucket and the cross bucket stay plain allocations.
|
|
1051
|
+
*/
|
|
1032
1052
|
post: operations["transfer_collateral_to_risk_bucket"];
|
|
1033
1053
|
delete?: never;
|
|
1034
1054
|
options?: never;
|
|
@@ -2072,23 +2092,29 @@ export interface paths {
|
|
|
2072
2092
|
* Register a deposit address for monitoring
|
|
2073
2093
|
* @description Register a deposit address for monitoring.
|
|
2074
2094
|
*
|
|
2075
|
-
* Every (application, user)
|
|
2076
|
-
*
|
|
2077
|
-
* automatically forwards every ERC20 deposit into the
|
|
2078
|
-
*
|
|
2095
|
+
* Every (application, user, deposit target) triple has a deterministic
|
|
2096
|
+
* deposit address. This registers the caller's own address so the sweeper
|
|
2097
|
+
* service watches it and automatically forwards every ERC20 deposit into the
|
|
2098
|
+
* rollup, crediting the caller under the application.
|
|
2099
|
+
*
|
|
2100
|
+
* Authenticated, and the whole identity comes from the session: the
|
|
2101
|
+
* application is the one `login` established the session under, and the
|
|
2102
|
+
* credited address is the session's own. Neither is a request parameter, so a
|
|
2103
|
+
* caller can only ever register their own address under their own
|
|
2104
|
+
* application. The only thing the body carries is which ledger to aim at.
|
|
2079
2105
|
*
|
|
2080
2106
|
* Registration also runs a one-time initial check in the background: any
|
|
2081
2107
|
* balance already sitting on the address is swept without waiting for a new
|
|
2082
2108
|
* transfer. The response returns immediately with the derived address; it
|
|
2083
2109
|
* does not wait for that check.
|
|
2084
2110
|
*
|
|
2085
|
-
* Idempotent and safe to retry: re-registering an existing
|
|
2111
|
+
* Idempotent and safe to retry: re-registering an existing triple returns
|
|
2086
2112
|
* `already_registered` with the same address and never re-triggers the
|
|
2087
2113
|
* initial check.
|
|
2088
2114
|
*
|
|
2089
|
-
*
|
|
2090
|
-
*
|
|
2091
|
-
*
|
|
2115
|
+
* Globally rate-limited: registration creates durable state, so the endpoint
|
|
2116
|
+
* admits a bounded number per minute across all callers and answers `429`
|
|
2117
|
+
* beyond it.
|
|
2092
2118
|
*/
|
|
2093
2119
|
post: operations["register_deposit_address"];
|
|
2094
2120
|
delete?: never;
|
|
@@ -4064,6 +4090,14 @@ export interface components {
|
|
|
4064
4090
|
riskBucketId?: string | null;
|
|
4065
4091
|
marginMode?: string | null;
|
|
4066
4092
|
selectedTradingPairIds?: string[] | null;
|
|
4093
|
+
/**
|
|
4094
|
+
* @description See `MarginAccountSummary.available_order_collateral`: the collateral
|
|
4095
|
+
* still available to open NEW orders in this risk bucket, the risk engine
|
|
4096
|
+
* admission gate's own bound with parent auto top-up included. Present only
|
|
4097
|
+
* on risk-bucket rows served from a live engine snapshot; absent on parent
|
|
4098
|
+
* rows and persisted-fallback reads.
|
|
4099
|
+
*/
|
|
4100
|
+
availableOrderCollateral?: string | null;
|
|
4067
4101
|
};
|
|
4068
4102
|
GetMarkPriceResponse: {
|
|
4069
4103
|
/** Format: uuid */
|
|
@@ -5706,6 +5740,42 @@ export interface components {
|
|
|
5706
5740
|
marginMode?: string | null;
|
|
5707
5741
|
/** @description Present for cross risk-bucket summary rows. */
|
|
5708
5742
|
selectedTradingPairIds?: string[] | null;
|
|
5743
|
+
/**
|
|
5744
|
+
* @description The collateral still available to open NEW orders in this risk bucket:
|
|
5745
|
+
* the largest increase in the bucket's worst-case order reserve the risk
|
|
5746
|
+
* engine's admission gate accepts, automatic top-up from the parent margin
|
|
5747
|
+
* account's unallocated capacity included. Zero while the account or bucket
|
|
5748
|
+
* is frozen for liquidation, and for an isolated bucket whose market is
|
|
5749
|
+
* halted. (A cross bucket's market is chosen per order, so a halt cannot be
|
|
5750
|
+
* folded into its figure — a halted pair still refuses orders.)
|
|
5751
|
+
*
|
|
5752
|
+
* The trading-side sibling of `withdrawable_collateral`, and deliberately a
|
|
5753
|
+
* different figure: this one credits an unrealized gain in full, because a
|
|
5754
|
+
* gain is legitimate initial margin for new positions, while a withdrawal
|
|
5755
|
+
* never counts one. It already contains the bucket's live free collateral —
|
|
5756
|
+
* do not add `free_collateral` or `unrealized_pnl` on top. It can also
|
|
5757
|
+
* legitimately differ from this row's `free_collateral`, which is a
|
|
5758
|
+
* persisted reconstruction that cannot see the engine's worst-case
|
|
5759
|
+
* resting-order reserve.
|
|
5760
|
+
*
|
|
5761
|
+
* NOT additive across rows: every bucket's figure includes the SAME parent
|
|
5762
|
+
* unallocated headroom, so summing rows multiply-counts it, and committing
|
|
5763
|
+
* collateral in one bucket shrinks its siblings' figures.
|
|
5764
|
+
*
|
|
5765
|
+
* This is a requirement budget, not an order size: an order is charged the
|
|
5766
|
+
* increase it causes in the bucket's worst-case per-pair reserve, so a
|
|
5767
|
+
* reducing, reduce-only, or opposite-side order sheltered by a larger
|
|
5768
|
+
* resting ladder needs less or none of it (and can be admitted even when
|
|
5769
|
+
* this field is zero), while an order crossing a losing position can need
|
|
5770
|
+
* more than its own margin-plus-fee. Divide by a market's initial margin
|
|
5771
|
+
* rate for indicative notional capacity; the authoritative per-order answer
|
|
5772
|
+
* remains `simulate_risk_bucket_order_risk`.
|
|
5773
|
+
*
|
|
5774
|
+
* Present only on risk-bucket summary rows served from a live risk engine
|
|
5775
|
+
* snapshot; absent on parent rows and on persisted-fallback reads, where
|
|
5776
|
+
* neither of the gate's terms is reconstructable.
|
|
5777
|
+
*/
|
|
5778
|
+
availableOrderCollateral?: string | null;
|
|
5709
5779
|
};
|
|
5710
5780
|
MatchResult: {
|
|
5711
5781
|
/**
|
|
@@ -6081,6 +6151,19 @@ export interface components {
|
|
|
6081
6151
|
* may carry sub-tick tails).
|
|
6082
6152
|
*/
|
|
6083
6153
|
withdrawableCollateral?: string | null;
|
|
6154
|
+
/**
|
|
6155
|
+
* @description The collateral still available to open NEW orders in this risk bucket —
|
|
6156
|
+
* the same engine-served admission bound as
|
|
6157
|
+
* `MarginAccountSummary.available_order_collateral` (see that field for the
|
|
6158
|
+
* full semantics: an envelope delta with parent auto top-up included, NOT
|
|
6159
|
+
* additive across rows, zero while frozen), truncated toward zero at quote
|
|
6160
|
+
* decimals like `withdrawable_collateral` beside it.
|
|
6161
|
+
*
|
|
6162
|
+
* Present only when a live risk engine snapshot served the bound; absent on
|
|
6163
|
+
* persisted-fallback reads, where neither of the gate's terms is
|
|
6164
|
+
* reconstructable.
|
|
6165
|
+
*/
|
|
6166
|
+
availableOrderCollateral?: string | null;
|
|
6084
6167
|
};
|
|
6085
6168
|
PortfolioSeriesWindow: {
|
|
6086
6169
|
/**
|
|
@@ -6455,25 +6538,21 @@ export interface components {
|
|
|
6455
6538
|
};
|
|
6456
6539
|
RegisterRequest: {
|
|
6457
6540
|
/**
|
|
6458
|
-
* @description
|
|
6459
|
-
* @example
|
|
6460
|
-
|
|
6461
|
-
clientId: string;
|
|
6462
|
-
/**
|
|
6463
|
-
* @description Address credited on the rollup, and half of the deposit address derivation
|
|
6464
|
-
* @example 0x742d35Cc6634C0532925a3b8D4060f31E2C3d8B5
|
|
6541
|
+
* @description Which ledger swept deposits are requested to be credited to. `SPOT` (the default when omitted) credits the spot wallet; `MARGIN` asks for the parent margin account's collateral, skipping the separate collateral transfer. The target is part of the address derivation, so `SPOT` and `MARGIN` yield two different deposit addresses for the same pair, and each address carries its own request. `MARGIN` is a routing request rather than a guarantee: a deposit the matching engine cannot route to collateral — an unsupported collateral asset, or a margin account that fails validation — is credited to the spot wallet instead, so funds are never stranded. A `SPOT` address is never credited to margin.
|
|
6542
|
+
* @example MARGIN
|
|
6543
|
+
* @enum {string|null}
|
|
6465
6544
|
*/
|
|
6466
|
-
|
|
6545
|
+
depositTarget?: "SPOT" | "MARGIN" | null;
|
|
6467
6546
|
};
|
|
6468
6547
|
RegisterResponse: {
|
|
6469
6548
|
/**
|
|
6470
|
-
* @description `registered` when the
|
|
6549
|
+
* @description `registered` when the triple was added, `already_registered` when it was known before this call
|
|
6471
6550
|
* @example registered
|
|
6472
6551
|
* @enum {string|null}
|
|
6473
6552
|
*/
|
|
6474
6553
|
status?: "registered" | "already_registered" | null;
|
|
6475
6554
|
/**
|
|
6476
|
-
* @description The
|
|
6555
|
+
* @description The deposit address for this (application, user, deposit target) triple. Stable, and valid to publish and fund before any contract exists there.
|
|
6477
6556
|
* @example 0xcf1eF339798914EF7Ee4984Ed45BD141D63a65C9
|
|
6478
6557
|
*/
|
|
6479
6558
|
sweeperAddress?: string | null;
|
|
@@ -7298,6 +7377,16 @@ export interface components {
|
|
|
7298
7377
|
marginMode?: string | null;
|
|
7299
7378
|
/** @description Present for cross risk-bucket transfers. */
|
|
7300
7379
|
selectedTradingPairIds?: string[] | null;
|
|
7380
|
+
/**
|
|
7381
|
+
* @description Whether the transfer was committed to a position's stored margin.
|
|
7382
|
+
* Present only when a position-margin credit was in play: true — the credit
|
|
7383
|
+
* landed; false — a credit was requested (or defaulted) but degraded to a
|
|
7384
|
+
* plain allocation because the bucket's persisted position row was stale
|
|
7385
|
+
* (close/reopen race) — re-issue the Adjust Margin once the new position
|
|
7386
|
+
* row lands if the commitment still matters. Absent on plain allocations,
|
|
7387
|
+
* parent deposits, and releases.
|
|
7388
|
+
*/
|
|
7389
|
+
positionMarginCredited?: boolean | null;
|
|
7301
7390
|
};
|
|
7302
7391
|
TransferCollateralToParentMarginAccountRequest: {
|
|
7303
7392
|
asset?: string | null;
|
|
@@ -7317,6 +7406,31 @@ export interface components {
|
|
|
7317
7406
|
marginMode?: string | null;
|
|
7318
7407
|
/** @description Trading pair UUIDs selected into the cross risk bucket. Required when marginMode is CROSS. */
|
|
7319
7408
|
selectedTradingPairIds?: string[] | null;
|
|
7409
|
+
/**
|
|
7410
|
+
* @description What the transferred collateral becomes when the ISOLATED bucket holds an
|
|
7411
|
+
* open position. The two intents want opposite fates for the same dollars,
|
|
7412
|
+
* so the caller states theirs:
|
|
7413
|
+
*
|
|
7414
|
+
* - true (and UNSET — the default is the human "Adjust Margin" gesture):
|
|
7415
|
+
* the amount is COMMITTED to the position's stored margin. Effective
|
|
7416
|
+
* leverage drops and stays down, initial margin required rises by the
|
|
7417
|
+
* amount, free collateral is unchanged — new orders cannot spend it.
|
|
7418
|
+
* - false: plain allocation. Free collateral rises and the next order can
|
|
7419
|
+
* spend it. Programmatic funding loops that top a bucket up to a free
|
|
7420
|
+
* collateral target MUST pass false, or each top-up converts into
|
|
7421
|
+
* requirement and the loop never converges.
|
|
7422
|
+
*
|
|
7423
|
+
* Either way the liquidation cushion improves identically (the breach
|
|
7424
|
+
* check is bucket-equity based). On a FLAT isolated bucket there is no
|
|
7425
|
+
* position to commit to and both values are a plain allocation. Explicit
|
|
7426
|
+
* true is rejected for CROSS buckets (cross has no per-position margin);
|
|
7427
|
+
* unset/false is a plain allocation there.
|
|
7428
|
+
*
|
|
7429
|
+
* The response reports what actually happened in `position_margin_credited`
|
|
7430
|
+
* — a credit can degrade to a plain allocation when the persisted position
|
|
7431
|
+
* row is stale (close/reopen race).
|
|
7432
|
+
*/
|
|
7433
|
+
applyToPositionMargin?: boolean | null;
|
|
7320
7434
|
};
|
|
7321
7435
|
TransferRewardsRequest: {
|
|
7322
7436
|
/**
|
|
@@ -11951,14 +12065,21 @@ export interface operations {
|
|
|
11951
12065
|
};
|
|
11952
12066
|
content?: never;
|
|
11953
12067
|
};
|
|
11954
|
-
/** @description
|
|
11955
|
-
|
|
12068
|
+
/** @description Authentication required */
|
|
12069
|
+
401: {
|
|
12070
|
+
headers: {
|
|
12071
|
+
[name: string]: unknown;
|
|
12072
|
+
};
|
|
12073
|
+
content?: never;
|
|
12074
|
+
};
|
|
12075
|
+
/** @description The application for this session is not active */
|
|
12076
|
+
403: {
|
|
11956
12077
|
headers: {
|
|
11957
12078
|
[name: string]: unknown;
|
|
11958
12079
|
};
|
|
11959
12080
|
content?: never;
|
|
11960
12081
|
};
|
|
11961
|
-
/** @description Registration
|
|
12082
|
+
/** @description Registration admission limit exceeded; retry shortly */
|
|
11962
12083
|
429: {
|
|
11963
12084
|
headers: {
|
|
11964
12085
|
[name: string]: unknown;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xmonaco/types",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.50",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"homepage": "https://docs.0xmonaco.com/sdk/typescript",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"lint": "biome lint ."
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@0xmonaco/contracts": "1.0.
|
|
19
|
+
"@0xmonaco/contracts": "1.0.50",
|
|
20
20
|
"zod": "^4.1.12"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|