@0xmonaco/core 1.0.70 → 1.0.73-develop.af0f5d0

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.
@@ -153,11 +153,13 @@ export declare class AuthAPIImpl extends BaseAPI implements AuthAPI {
153
153
  */
154
154
  verifySignature(address: string, signature: string, nonce: string, clientId: string, session: SessionCredentials, referralCode?: string): Promise<AuthState>;
155
155
  /**
156
- * Extends the current session's expiry.
156
+ * Refreshes the current session's expiry.
157
157
  *
158
158
  * The request is signed with the active session key (set via
159
- * {@link setSessionKeypair}); the server bumps the session's `expiresAt`.
160
- * No new credential is issued — the same keypair keeps working.
159
+ * {@link setSessionKeypair}). For a delegated session, the delegation must
160
+ * still be active; the returned expiry is capped by its current expiry and
161
+ * may move earlier if the owner shortened the delegation. No new credential
162
+ * is issued — the same keypair keeps working.
161
163
  *
162
164
  * @returns Promise resolving to the new expiry
163
165
  * @throws {APIError} When refresh fails (e.g. session expired or revoked)
@@ -237,11 +237,13 @@ export class AuthAPIImpl extends BaseAPI {
237
237
  };
238
238
  }
239
239
  /**
240
- * Extends the current session's expiry.
240
+ * Refreshes the current session's expiry.
241
241
  *
242
242
  * The request is signed with the active session key (set via
243
- * {@link setSessionKeypair}); the server bumps the session's `expiresAt`.
244
- * No new credential is issued — the same keypair keeps working.
243
+ * {@link setSessionKeypair}). For a delegated session, the delegation must
244
+ * still be active; the returned expiry is capped by its current expiry and
245
+ * may move earlier if the owner shortened the delegation. No new credential
246
+ * is issued — the same keypair keeps working.
245
247
  *
246
248
  * @returns Promise resolving to the new expiry
247
249
  * @throws {APIError} When refresh fails (e.g. session expired or revoked)
@@ -34,10 +34,13 @@ export declare abstract class BaseAPI {
34
34
  /** Application secret key (`sk_...`) sent in the `x-server-key` header for backend-authenticated requests. */
35
35
  protected serverKey?: string;
36
36
  private requestSigning;
37
+ private redirectPolicy?;
37
38
  /** Server time learned from responses; signing timestamps are read from it. */
38
39
  protected serverClock: ServerClock;
39
40
  /** Opt in only after the target server supports RFC 9421. No automatic downgrade. */
40
41
  setRequestSigning(protocol: RequestSigning): void;
42
+ /** Refuse cross-origin and same-origin redirects when set to `error`. */
43
+ setRedirectPolicy(policy: "error" | undefined): void;
41
44
  protected retryOptions: Required<RetryOptions>;
42
45
  /** Share one server clock across API instances so any response calibrates all of them. */
43
46
  setServerClock(clock: ServerClock): void;
package/dist/api/base.js CHANGED
@@ -44,6 +44,7 @@ export class BaseAPI {
44
44
  /** Application secret key (`sk_...`) sent in the `x-server-key` header for backend-authenticated requests. */
45
45
  serverKey;
46
46
  requestSigning = "legacy";
47
+ redirectPolicy;
47
48
  /** Server time learned from responses; signing timestamps are read from it. */
48
49
  serverClock = new ServerClock();
49
50
  /** Opt in only after the target server supports RFC 9421. No automatic downgrade. */
@@ -52,6 +53,10 @@ export class BaseAPI {
52
53
  throw new Error("Unsupported request signing protocol");
53
54
  this.requestSigning = protocol;
54
55
  }
56
+ /** Refuse cross-origin and same-origin redirects when set to `error`. */
57
+ setRedirectPolicy(policy) {
58
+ this.redirectPolicy = policy;
59
+ }
55
60
  retryOptions;
56
61
  /** Share one server clock across API instances so any response calibrates all of them. */
57
62
  setServerClock(clock) {
@@ -186,7 +191,7 @@ export class BaseAPI {
186
191
  // authenticated, backend, and public request paths.
187
192
  const headers = { "User-Agent": SDK_USER_AGENT, ...options.headers };
188
193
  try {
189
- response = await fetch(url, { ...options, headers });
194
+ response = await fetch(url, { ...options, headers, ...(this.redirectPolicy ? { redirect: this.redirectPolicy } : {}) });
190
195
  }
191
196
  catch (error) {
192
197
  throw new APIError(`Network request failed for ${endpoint}`, {
@@ -19,7 +19,7 @@
19
19
  * console.log(`Now tradeable: ${result.tradingBalance}`);
20
20
  * ```
21
21
  */
22
- import type { BuildercodesAPI, ClaimBuildercodeRewardsParams, ClaimBuildercodeRewardsResponse, GetBuildercodePayoutSummaryResponse, GetBuildercodeRewardsBalanceResponse, GetBuildercodesConfigResponse, ListBuildercodePayoutsParams, ListBuildercodePayoutsResponse } from "@0xmonaco/types";
22
+ import type { BuildercodesAPI, ClaimBuildercodeRewardsParams, ClaimBuildercodeRewardsResponse, GetBuildercodePayoutSummaryResponse, GetBuildercodeRewardsBalanceResponse, GetBuildercodesConfigResponse, ListBuildercodePayoutsParams, ListBuildercodePayoutsResponse, ListBuilderFeeChangesParams, ListBuilderFeeChangesResponse, SetBuilderFeeParams, SetBuilderFeeResponse } from "@0xmonaco/types";
23
23
  import { BaseAPI } from "../base";
24
24
  export declare class BuildercodesAPIImpl extends BaseAPI implements BuildercodesAPI {
25
25
  /**
@@ -30,11 +30,15 @@ export declare class BuildercodesAPIImpl extends BaseAPI implements Buildercodes
30
30
  * application's configured payout address.
31
31
  */
32
32
  getConfig(): Promise<GetBuildercodesConfigResponse>;
33
+ /** Set this frontend's builder fee. */
34
+ setBuilderFee(params: SetBuilderFeeParams): Promise<SetBuilderFeeResponse>;
35
+ /** List this frontend's builder-fee audit log, newest first. */
36
+ listBuilderFeeChanges(params?: ListBuilderFeeChangesParams): Promise<ListBuilderFeeChangesResponse>;
33
37
  /**
34
38
  * List this frontend's per-trade BuilderCodes credits, newest first. Each
35
- * credit carries its payout `kind`: `REVENUE_SHARE` (your share of Monaco's
36
- * fee) or `BUILDER_FEE` (your builder fee). Pass `kind` to list one stream;
37
- * `total` then counts only that stream.
39
+ * credit carries its payout `kind`: `REVENUE_SHARE` for Monaco revenue share
40
+ * or `BUILDER_FEE` for builder fees charged to takers. Pass `kind` to filter
41
+ * the list; `total` then counts only that category.
38
42
  *
39
43
  * The server scopes every query to the authenticated application; neither
40
44
  * the application id nor payout wallet can be supplied by the caller.
@@ -19,7 +19,7 @@
19
19
  * console.log(`Now tradeable: ${result.tradingBalance}`);
20
20
  * ```
21
21
  */
22
- import { ClaimBuildercodeRewardsParamsSchema, ListBuildercodePayoutsParamsSchema, validate } from "@0xmonaco/types";
22
+ import { ClaimBuildercodeRewardsParamsSchema, ListBuildercodePayoutsParamsSchema, ListBuilderFeeChangesParamsSchema, SetBuilderFeeParamsSchema, validate, } from "@0xmonaco/types";
23
23
  import { APIError } from "../../errors";
24
24
  import { BaseAPI } from "../base";
25
25
  /**
@@ -102,11 +102,35 @@ export class BuildercodesAPIImpl extends BaseAPI {
102
102
  method: "GET",
103
103
  });
104
104
  }
105
+ /** Set this frontend's builder fee. */
106
+ async setBuilderFee(params) {
107
+ const validated = validate(SetBuilderFeeParamsSchema, params);
108
+ return this.makeAuthenticatedRequest("/api/v1/buildercodes/builder-fee", {
109
+ method: "PUT",
110
+ body: JSON.stringify({ bps: validated.bps }),
111
+ });
112
+ }
113
+ /** List this frontend's builder-fee audit log, newest first. */
114
+ async listBuilderFeeChanges(params) {
115
+ if (params) {
116
+ validate(ListBuilderFeeChangesParamsSchema, params);
117
+ }
118
+ const searchParams = new URLSearchParams();
119
+ if (params?.pageSize !== undefined) {
120
+ searchParams.append("pageSize", params.pageSize.toString());
121
+ }
122
+ if (params?.pageToken !== undefined) {
123
+ searchParams.append("pageToken", params.pageToken);
124
+ }
125
+ const query = searchParams.toString();
126
+ const path = query ? `/api/v1/buildercodes/builder-fee/changes?${query}` : "/api/v1/buildercodes/builder-fee/changes";
127
+ return this.makeAuthenticatedRequest(path, { method: "GET" });
128
+ }
105
129
  /**
106
130
  * List this frontend's per-trade BuilderCodes credits, newest first. Each
107
- * credit carries its payout `kind`: `REVENUE_SHARE` (your share of Monaco's
108
- * fee) or `BUILDER_FEE` (your builder fee). Pass `kind` to list one stream;
109
- * `total` then counts only that stream.
131
+ * credit carries its payout `kind`: `REVENUE_SHARE` for Monaco revenue share
132
+ * or `BUILDER_FEE` for builder fees charged to takers. Pass `kind` to filter
133
+ * the list; `total` then counts only that category.
110
134
  *
111
135
  * The server scopes every query to the authenticated application; neither
112
136
  * the application id nor payout wallet can be supplied by the caller.
@@ -20,7 +20,7 @@
20
20
  * const { followId } = await sdk.copyTrading.upsertFollow({ leader, allocation: "1000", slPct: "0.25" });
21
21
  * ```
22
22
  */
23
- import type { CopyTradingAPI, GetFollowResponse, GetLeadTraderResponse, ListFollowLeaderPositionsResponse, ListLeadTraderClosedTradesParams, ListLeadTraderClosedTradesResponse, ListLeadTraderOpenPositionsResponse, ListLeadTradersParams, ListLeadTradersResponse, ListMyFollowersParams, ListMyFollowersResponse, ListMyFollowsParams, ListMyFollowsResponse, PreviewFollowParams, PreviewFollowResponse, StopFollowResponse, UpsertFollowParams, UpsertFollowResponse, UpsertLeadTraderParams, UpsertLeadTraderResponse } from "@0xmonaco/types";
23
+ import type { AddFollowPositionMarginParams, AddFollowPositionMarginResponse, CloseAllCopyPositionsResponse, CloseFollowPositionsResponse, CopyTradingAPI, GetFollowResponse, GetLeadTraderResponse, ListFollowLeaderPositionsResponse, ListLeadTraderClosedTradesParams, ListLeadTraderClosedTradesResponse, ListLeadTraderOpenPositionsResponse, ListLeadTradersParams, ListLeadTradersResponse, ListMyFollowersParams, ListMyFollowersResponse, ListMyFollowsParams, ListMyFollowsResponse, PreviewFollowParams, PreviewFollowResponse, StopFollowResponse, UpsertFollowParams, UpsertFollowResponse, UpsertLeadTraderParams, UpsertLeadTraderResponse } from "@0xmonaco/types";
24
24
  import { BaseAPI } from "../base";
25
25
  export declare class CopyTradingAPIImpl extends BaseAPI implements CopyTradingAPI {
26
26
  /**
@@ -77,6 +77,30 @@ export declare class CopyTradingAPIImpl extends BaseAPI implements CopyTradingAP
77
77
  previewFollow(params: PreviewFollowParams): Promise<PreviewFollowResponse>;
78
78
  /** Stop one of your follows: the leader's fills stop being mirrored. */
79
79
  stopFollow(followId: string): Promise<StopFollowResponse>;
80
+ /**
81
+ * Close every position in one of your follows' copy accounts and keep the
82
+ * follow. The response acknowledges the batch; fills arrive on the order,
83
+ * position and copy channels.
84
+ */
85
+ closeFollowPositions(followId: string): Promise<CloseFollowPositionsResponse>;
86
+ /** Close the copy positions of every live follow of yours, keeping the follows. */
87
+ closeAllCopyPositions(): Promise<CloseAllCopyPositionsResponse>;
88
+ /**
89
+ * Add margin to one of your copy positions: moves `amount` (quote units)
90
+ * from the follow's copy account into the margin of its isolated copy
91
+ * position on `tradingPairId`. The position's margin rises by exactly
92
+ * `amount`, the copy account's remaining collateral falls by the same, and
93
+ * your margin account is never touched. It opens no exposure, so it works
94
+ * while copy trading is switched off and on a `CLOSE_ONLY` follow; there is
95
+ * no margin reduction (a follow exits by being stopped).
96
+ *
97
+ * Master account sessions only (403 otherwise); 404 for a follow that is
98
+ * not yours; 409 while the follow is stopping or once it is stopped; 400
99
+ * `COPY_TRADING_REJECTED` when the engine refuses the add; 429 over the
100
+ * shared movement budget. Not idempotent: a retry after a timeout whose
101
+ * first attempt landed adds the amount twice.
102
+ */
103
+ addFollowPositionMargin(params: AddFollowPositionMarginParams): Promise<AddFollowPositionMarginResponse>;
80
104
  /** List your follows, newest first. Cursor paged, up to 1000 per page. */
81
105
  listMyFollows(params?: ListMyFollowsParams): Promise<ListMyFollowsResponse>;
82
106
  /**
@@ -20,7 +20,7 @@
20
20
  * const { followId } = await sdk.copyTrading.upsertFollow({ leader, allocation: "1000", slPct: "0.25" });
21
21
  * ```
22
22
  */
23
- import { LeaderHandleSchema, ListLeadTraderClosedTradesSchema, ListLeadTradersSchema, ListMyFollowersSchema, ListMyFollowsSchema, PreviewFollowSchema, UpsertFollowSchema, UpsertLeadTraderSchema, UUIDSchema, validate, } from "@0xmonaco/types";
23
+ import { AddFollowPositionMarginSchema, LeaderHandleSchema, ListLeadTraderClosedTradesSchema, ListLeadTradersSchema, ListMyFollowersSchema, ListMyFollowsSchema, PreviewFollowSchema, UpsertFollowSchema, UpsertLeadTraderSchema, UUIDSchema, validate, } from "@0xmonaco/types";
24
24
  import { BaseAPI } from "../base";
25
25
  const BASE = "/api/v1/copy-trading";
26
26
  /** `?k=v&...` from the defined entries, or `""` when there are none. */
@@ -183,6 +183,42 @@ export class CopyTradingAPIImpl extends BaseAPI {
183
183
  async stopFollow(followId) {
184
184
  return await this.makeAuthenticatedRequest(`${followPath(followId)}/stop`, { method: "POST" });
185
185
  }
186
+ /**
187
+ * Close every position in one of your follows' copy accounts and keep the
188
+ * follow. The response acknowledges the batch; fills arrive on the order,
189
+ * position and copy channels.
190
+ */
191
+ async closeFollowPositions(followId) {
192
+ return await this.makeAuthenticatedRequest(`${followPath(followId)}/close-positions`, { method: "POST" });
193
+ }
194
+ /** Close the copy positions of every live follow of yours, keeping the follows. */
195
+ async closeAllCopyPositions() {
196
+ return await this.makeAuthenticatedRequest(`${BASE}/follows/close-positions`, { method: "POST" });
197
+ }
198
+ /**
199
+ * Add margin to one of your copy positions: moves `amount` (quote units)
200
+ * from the follow's copy account into the margin of its isolated copy
201
+ * position on `tradingPairId`. The position's margin rises by exactly
202
+ * `amount`, the copy account's remaining collateral falls by the same, and
203
+ * your margin account is never touched. It opens no exposure, so it works
204
+ * while copy trading is switched off and on a `CLOSE_ONLY` follow; there is
205
+ * no margin reduction (a follow exits by being stopped).
206
+ *
207
+ * Master account sessions only (403 otherwise); 404 for a follow that is
208
+ * not yours; 409 while the follow is stopping or once it is stopped; 400
209
+ * `COPY_TRADING_REJECTED` when the engine refuses the add; 429 over the
210
+ * shared movement budget. Not idempotent: a retry after a timeout whose
211
+ * first attempt landed adds the amount twice.
212
+ */
213
+ async addFollowPositionMargin(params) {
214
+ const { followId, tradingPairId, amount } = validate(AddFollowPositionMarginSchema, params);
215
+ // The follow id travels in the path only; the body carries the rest.
216
+ const body = { tradingPairId, amount };
217
+ return await this.makeAuthenticatedRequest(`${followPath(followId)}/position-margin`, {
218
+ method: "POST",
219
+ body: JSON.stringify(body),
220
+ });
221
+ }
186
222
  /** List your follows, newest first. Cursor paged, up to 1000 per page. */
187
223
  async listMyFollows(params = {}) {
188
224
  const { pageSize, pageToken } = validate(ListMyFollowsSchema, params);
@@ -16,6 +16,7 @@ export class DelegatedAgentsAPIImpl extends BaseAPI {
16
16
  maxLeverage: request.maxLeverage,
17
17
  maxOrderNotional: request.maxOrderNotional,
18
18
  maxOpenOrders: request.maxOpenOrders,
19
+ ipAllowlist: request.ipAllowlist,
19
20
  }),
20
21
  });
21
22
  }
@@ -76,6 +76,9 @@ export declare class FeesAPIImpl extends BaseAPI implements FeesAPI {
76
76
  * spot/perp breakdown), the volume still needed to reach the next tier, and the
77
77
  * requested pair's six-row fee schedule.
78
78
  *
79
+ * The tier and volumes are wallet-wide: the caller's wallet total across every
80
+ * application it trades through, so they read the same from any application.
81
+ *
79
82
  * @param params - Parameters for the lookup
80
83
  * @param params.tradingPairId - Trading pair whose fee schedule to return
81
84
  * @returns Promise resolving to the caller's tier and the pair's schedule
@@ -94,6 +94,9 @@ export class FeesAPIImpl extends BaseAPI {
94
94
  * spot/perp breakdown), the volume still needed to reach the next tier, and the
95
95
  * requested pair's six-row fee schedule.
96
96
  *
97
+ * The tier and volumes are wallet-wide: the caller's wallet total across every
98
+ * application it trades through, so they read the same from any application.
99
+ *
97
100
  * @param params - Parameters for the lookup
98
101
  * @param params.tradingPairId - Trading pair whose fee schedule to return
99
102
  * @returns Promise resolving to the caller's tier and the pair's schedule
@@ -1,6 +1,10 @@
1
- import type { GetAvailableCollateralParams, GetAvailableCollateralResponse, GetMarginAccountMovementsParams, GetMarginAccountMovementsResponse, GetMarginAccountSummaryParams, ListMarginAccountsParams, ListMarginAccountsResponse, MarginAccountSummary, MarginAccountsAPI, SimulateOrderRiskRequest, SimulateOrderRiskResponse, SimulateRiskBucketOrderRiskRequest, TransferCollateralFromParentMarginAccountRequest, TransferCollateralRequest, TransferCollateralResponse, TransferCollateralToParentMarginAccountRequest, TransferCollateralToRiskBucketRequest } from "@0xmonaco/types";
1
+ import type { CloseMarginSubAccountResponse, CreateMarginSubAccountRequest, CreateMarginSubAccountResponse, GetAvailableCollateralParams, GetAvailableCollateralResponse, GetMarginAccountMovementsParams, GetMarginAccountMovementsResponse, GetMarginAccountSummaryParams, ListMarginAccountsParams, ListMarginAccountsResponse, MarginAccountPnl, MarginAccountSummary, MarginAccountsAPI, SimulateOrderRiskRequest, SimulateOrderRiskResponse, SimulateRiskBucketOrderRiskRequest, TransferCollateralFromParentMarginAccountRequest, TransferCollateralRequest, TransferCollateralResponse, TransferCollateralToParentMarginAccountRequest, TransferCollateralToRiskBucketRequest, TransferMarginCollateralRequest, TransferMarginCollateralResponse } from "@0xmonaco/types";
2
2
  import { BaseAPI } from "../base";
3
3
  export declare class MarginAccountsAPIImpl extends BaseAPI implements MarginAccountsAPI {
4
+ createMarginSubAccount(request: CreateMarginSubAccountRequest): Promise<CreateMarginSubAccountResponse>;
5
+ closeMarginSubAccount(marginAccountId: string): Promise<CloseMarginSubAccountResponse>;
6
+ getMarginAccountPnl(marginAccountId: string): Promise<MarginAccountPnl>;
7
+ transferMarginCollateral(request: TransferMarginCollateralRequest): Promise<TransferMarginCollateralResponse>;
4
8
  listMarginAccounts(params?: ListMarginAccountsParams): Promise<ListMarginAccountsResponse>;
5
9
  getMarginAccountSummary(marginAccountId: string, params?: GetMarginAccountSummaryParams): Promise<MarginAccountSummary>;
6
10
  getParentMarginAccountSummary(params?: GetMarginAccountSummaryParams): Promise<MarginAccountSummary>;
@@ -1,7 +1,37 @@
1
- import { GetAvailableCollateralSchema, GetMarginAccountMovementsSchema, GetMarginAccountSummarySchema, GetParentMarginAccountMovementsSchema, GetParentMarginAccountSummarySchema, ListMarginAccountsSchema, SimulateOrderRiskSchema, SimulateParentMarginOrderRiskSchema, SimulateRiskBucketOrderRiskSchema, TransferCollateralFromParentMarginAccountSchema, TransferCollateralSchema, TransferCollateralToParentMarginAccountSchema, TransferCollateralToRiskBucketSchema, validate, } from "@0xmonaco/types";
1
+ import { CloseMarginSubAccountSchema, CreateMarginSubAccountSchema, GetAvailableCollateralSchema, GetMarginAccountMovementsSchema, GetMarginAccountPnlSchema, GetMarginAccountSummarySchema, GetParentMarginAccountMovementsSchema, GetParentMarginAccountSummarySchema, ListMarginAccountsSchema, SimulateOrderRiskSchema, SimulateParentMarginOrderRiskSchema, SimulateRiskBucketOrderRiskSchema, TransferCollateralFromParentMarginAccountSchema, TransferCollateralSchema, TransferCollateralToParentMarginAccountSchema, TransferCollateralToRiskBucketSchema, TransferMarginCollateralSchema, validate, } from "@0xmonaco/types";
2
2
  import { BaseAPI } from "../base";
3
3
  import { perpRoutes } from "../perp";
4
4
  export class MarginAccountsAPIImpl extends BaseAPI {
5
+ async createMarginSubAccount(request) {
6
+ validate(CreateMarginSubAccountSchema, { request });
7
+ return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.createSubAccount(), {
8
+ method: "POST",
9
+ body: JSON.stringify({ subaccountKey: request.subaccountKey, label: request.label }),
10
+ });
11
+ }
12
+ async closeMarginSubAccount(marginAccountId) {
13
+ validate(CloseMarginSubAccountSchema, { marginAccountId });
14
+ return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.closeSubAccount(marginAccountId), {
15
+ method: "POST",
16
+ body: JSON.stringify({}),
17
+ });
18
+ }
19
+ async getMarginAccountPnl(marginAccountId) {
20
+ validate(GetMarginAccountPnlSchema, { marginAccountId });
21
+ return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.pnl(marginAccountId));
22
+ }
23
+ async transferMarginCollateral(request) {
24
+ validate(TransferMarginCollateralSchema, { request });
25
+ return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.transferCollateral(), {
26
+ method: "POST",
27
+ body: JSON.stringify({
28
+ asset: request.asset,
29
+ amount: request.amount,
30
+ from: request.from,
31
+ to: request.to,
32
+ }),
33
+ });
34
+ }
5
35
  async listMarginAccounts(params) {
6
36
  if (params) {
7
37
  validate(ListMarginAccountsSchema, params);
@@ -69,6 +99,7 @@ export class MarginAccountsAPIImpl extends BaseAPI {
69
99
  tradingPairId: request.tradingPairId,
70
100
  strategyKey: request.strategyKey,
71
101
  marginMode: request.marginMode,
102
+ marginAccountId: request.marginAccountId,
72
103
  // No selectedTradingPairIds: cross scope is derived from trading, and
73
104
  // the server ignores the deprecated field. Not sending it keeps a
74
105
  // pre-upgrade caller's stale list from reaching the wire at all.
@@ -152,6 +183,7 @@ export class MarginAccountsAPIImpl extends BaseAPI {
152
183
  tradingPairId: request.tradingPairId,
153
184
  strategyKey: request.strategyKey,
154
185
  marginMode: request.marginMode,
186
+ marginAccountId: request.marginAccountId,
155
187
  // No selectedTradingPairIds: cross scope is derived from trading, and
156
188
  // the server ignores the deprecated field. Not sending it keeps a
157
189
  // pre-upgrade caller's stale list from reaching the wire at all.
@@ -230,6 +230,10 @@ export declare const perpRoutes: {
230
230
  readonly simulateParentMarginOrderRisk: () => string;
231
231
  readonly simulateOrderRisk: (marginAccountId: string) => string;
232
232
  readonly simulateRiskBucketOrderRisk: () => string;
233
+ readonly createSubAccount: () => string;
234
+ readonly closeSubAccount: (marginAccountId: string) => string;
235
+ readonly pnl: (marginAccountId: string) => string;
236
+ readonly transferCollateral: () => string;
233
237
  };
234
238
  readonly streams: {
235
239
  readonly orderbook: () => string;
@@ -119,6 +119,10 @@ export const perpRoutes = {
119
119
  simulateParentMarginOrderRisk: () => `${API_V1}/margin/parent-margin-account/simulate-order-risk`,
120
120
  simulateOrderRisk: (marginAccountId) => `${API_V1}/margin/accounts/${encodeSegment(marginAccountId)}/simulate-order-risk`,
121
121
  simulateRiskBucketOrderRisk: () => `${API_V1}/margin/risk-buckets/simulate-order-risk`,
122
+ createSubAccount: () => `${API_V1}/margin/sub-accounts`,
123
+ closeSubAccount: (marginAccountId) => `${API_V1}/margin/sub-accounts/${encodeSegment(marginAccountId)}/close`,
124
+ pnl: (marginAccountId) => `${API_V1}/margin/accounts/${encodeSegment(marginAccountId)}/pnl`,
125
+ transferCollateral: () => `${API_V1}/margin/collateral/transfer`,
122
126
  },
123
127
  streams: {
124
128
  orderbook: () => `${API_V1}/streaming/orderbook`,
@@ -33,7 +33,7 @@
33
33
  * console.log(`Rewards remaining: ${result.rewardsBalance}`);
34
34
  * ```
35
35
  */
36
- import type { GetMyReferralDownlineResponse, GetMyReferralPositionResponse, GetRewardsBalanceResponse, PitpassAPI, TraderCodeAvailabilityResponse, TraderCodeInfoResponse, TraderCodeResponse, TransferRewardsParams, TransferRewardsResponse } from "@0xmonaco/types";
36
+ import type { GetMyReferralDownlineResponse, GetMyReferralPositionResponse, GetMyReferralTreeParams, GetMyReferralTreeResponse, GetRewardsBalanceResponse, PitpassAPI, TraderCodeAvailabilityResponse, TraderCodeInfoResponse, TraderCodeResponse, TransferRewardsParams, TransferRewardsResponse } from "@0xmonaco/types";
37
37
  import { BaseAPI } from "../base";
38
38
  export declare class PitpassAPIImpl extends BaseAPI implements PitpassAPI {
39
39
  /**
@@ -77,9 +77,10 @@ export declare class PitpassAPIImpl extends BaseAPI implements PitpassAPI {
77
77
  */
78
78
  transferRewards(params: TransferRewardsParams): Promise<TransferRewardsResponse>;
79
79
  /**
80
- * Read the caller's own referral position: their L1 referrer, total earned,
81
- * and recent rewards. Self-scoped — no id is sent, so it can only ever return
82
- * your own chain. `referrer` is "" when you were not referred.
80
+ * Read the caller's own referral position: their upline (L1, L2, L3), their
81
+ * L1 referrer, total earned, and recent rewards. Self-scoped — no id is sent,
82
+ * so it can only ever return your own chain. `referrer` is "" and `upline` is
83
+ * empty when you were not referred.
83
84
  */
84
85
  getMyReferralPosition(): Promise<GetMyReferralPositionResponse>;
85
86
  /**
@@ -88,4 +89,11 @@ export declare class PitpassAPIImpl extends BaseAPI implements PitpassAPI {
88
89
  * per-level earnings summary. Self-scoped, read-only.
89
90
  */
90
91
  getMyReferralDownline(): Promise<GetMyReferralDownlineResponse>;
92
+ /**
93
+ * Read one level of the caller's own referral tree: the wallets `parent`
94
+ * directly referred (the caller when omitted), a page at a time, newest
95
+ * first. `parent` must be the caller or one of their own L1/L2 referees;
96
+ * any other wallet is a 404.
97
+ */
98
+ getMyReferralTree(params?: GetMyReferralTreeParams): Promise<GetMyReferralTreeResponse>;
91
99
  }
@@ -33,7 +33,7 @@
33
33
  * console.log(`Rewards remaining: ${result.rewardsBalance}`);
34
34
  * ```
35
35
  */
36
- import { SetTraderCodeParamsSchema, TransferRewardsParamsSchema, validate } from "@0xmonaco/types";
36
+ import { GetMyReferralTreeParamsSchema, SetTraderCodeParamsSchema, TransferRewardsParamsSchema, validate } from "@0xmonaco/types";
37
37
  import { BaseAPI } from "../base";
38
38
  export class PitpassAPIImpl extends BaseAPI {
39
39
  /**
@@ -109,9 +109,10 @@ export class PitpassAPIImpl extends BaseAPI {
109
109
  });
110
110
  }
111
111
  /**
112
- * Read the caller's own referral position: their L1 referrer, total earned,
113
- * and recent rewards. Self-scoped — no id is sent, so it can only ever return
114
- * your own chain. `referrer` is "" when you were not referred.
112
+ * Read the caller's own referral position: their upline (L1, L2, L3), their
113
+ * L1 referrer, total earned, and recent rewards. Self-scoped — no id is sent,
114
+ * so it can only ever return your own chain. `referrer` is "" and `upline` is
115
+ * empty when you were not referred.
115
116
  */
116
117
  async getMyReferralPosition() {
117
118
  return await this.makeAuthenticatedRequest("/api/v1/pitpass/referrals/me", {
@@ -128,4 +129,28 @@ export class PitpassAPIImpl extends BaseAPI {
128
129
  method: "GET",
129
130
  });
130
131
  }
132
+ /**
133
+ * Read one level of the caller's own referral tree: the wallets `parent`
134
+ * directly referred (the caller when omitted), a page at a time, newest
135
+ * first. `parent` must be the caller or one of their own L1/L2 referees;
136
+ * any other wallet is a 404.
137
+ */
138
+ async getMyReferralTree(params) {
139
+ if (params) {
140
+ validate(GetMyReferralTreeParamsSchema, params);
141
+ }
142
+ const searchParams = new URLSearchParams();
143
+ if (params?.parent !== undefined) {
144
+ searchParams.append("parent", params.parent);
145
+ }
146
+ if (params?.pageSize !== undefined) {
147
+ searchParams.append("pageSize", params.pageSize.toString());
148
+ }
149
+ if (params?.pageToken !== undefined) {
150
+ searchParams.append("pageToken", params.pageToken);
151
+ }
152
+ const query = searchParams.toString();
153
+ const path = query ? `/api/v1/pitpass/referrals/me/tree?${query}` : "/api/v1/pitpass/referrals/me/tree";
154
+ return await this.makeAuthenticatedRequest(path, { method: "GET" });
155
+ }
131
156
  }
@@ -1,9 +1,9 @@
1
- import type { PortfolioAPI, PortfolioAssets, PortfolioMargin, PortfolioPerformance, PortfolioPeriodParams, PortfolioRealizedPnl, PortfolioSummary } from "@0xmonaco/types";
1
+ import type { PortfolioAPI, PortfolioAssets, PortfolioMargin, PortfolioMarginParams, PortfolioPerformance, PortfolioPeriodParams, PortfolioRealizedPnl, PortfolioSummary } from "@0xmonaco/types";
2
2
  import { BaseAPI } from "../base";
3
3
  export declare class PortfolioAPIImpl extends BaseAPI implements PortfolioAPI {
4
4
  getSummary(params?: PortfolioPeriodParams): Promise<PortfolioSummary>;
5
5
  getPerformance(params?: PortfolioPeriodParams): Promise<PortfolioPerformance>;
6
6
  getRealizedPnl(params?: PortfolioPeriodParams): Promise<PortfolioRealizedPnl>;
7
7
  getAssets(params?: PortfolioPeriodParams): Promise<PortfolioAssets>;
8
- getMargin(): Promise<PortfolioMargin>;
8
+ getMargin(params?: PortfolioMarginParams): Promise<PortfolioMargin>;
9
9
  }
@@ -19,7 +19,16 @@ export class PortfolioAPIImpl extends BaseAPI {
19
19
  async getAssets(params) {
20
20
  return await this.makeAuthenticatedRequest(withPeriod(`${BASE_PATH}/assets`, params));
21
21
  }
22
- async getMargin() {
23
- return await this.makeAuthenticatedRequest(`${BASE_PATH}/margin`);
22
+ async getMargin(params) {
23
+ const query = new URLSearchParams();
24
+ if (params?.marginAccountId) {
25
+ query.set("marginAccountId", params.marginAccountId);
26
+ }
27
+ if (params?.includeAccounts !== undefined) {
28
+ query.set("includeAccounts", String(params.includeAccounts));
29
+ }
30
+ const search = query.toString();
31
+ const suffix = search ? `?${search}` : "";
32
+ return await this.makeAuthenticatedRequest(`${BASE_PATH}/margin${suffix}`);
24
33
  }
25
34
  }
@@ -284,7 +284,7 @@ function parseLiquidationEventData(raw) {
284
284
  positionId: readOptionalString(data, "positionId"),
285
285
  tradingPairId: readOptionalString(data, "tradingPairId"),
286
286
  status: readString(data, "status"),
287
- accountState: readString(data, "accountState"),
287
+ riskBucketState: readString(data, "riskBucketState"),
288
288
  liquidationPrice: readOptionalString(data, "liquidationPrice"),
289
289
  markPrice: readOptionalString(data, "markPrice"),
290
290
  estimatedShortfall: readString(data, "estimatedShortfall"),
@@ -299,7 +299,7 @@ function parseLiquidationEvent(rawData) {
299
299
  return {
300
300
  // event_type is the event-class discriminator, validated strictly so a
301
301
  // mis-routed frame is rejected rather than parsed as a liquidation. The
302
- // free-form value fields in the payload (status/accountState) stay lenient
302
+ // free-form value fields in the payload (status/riskBucketState) stay lenient
303
303
  // so an unexpected *value* never drops a risk-critical alert.
304
304
  eventType: readEnum(rawData, "event_type", ["liquidation_alert"]),
305
305
  userId: readString(rawData, "user_id"),
@@ -19,6 +19,9 @@ export declare const COVERED: {
19
19
  list_lead_trader_open_positions: string;
20
20
  upsert_follow: string;
21
21
  stop_follow: string;
22
+ close_follow_positions: string;
23
+ close_all_copy_positions: string;
24
+ add_follow_position_margin: string;
22
25
  list_my_follows: string;
23
26
  get_follow: string;
24
27
  list_follow_leader_positions: string;
@@ -59,6 +62,7 @@ export declare const COVERED: {
59
62
  get_rewards_balance: string;
60
63
  get_my_referral_position: string;
61
64
  get_my_referral_downline: string;
65
+ get_my_referral_tree: string;
62
66
  get_self_trade_prevention_default: string;
63
67
  get_trader_code_info: string;
64
68
  set_self_trade_prevention_default: string;
@@ -102,6 +106,7 @@ export declare const COVERED: {
102
106
  list_application_orders: string;
103
107
  list_application_users: string;
104
108
  list_buildercode_payouts: string;
109
+ list_builder_fee_changes: string;
105
110
  list_conditional_orders: string;
106
111
  list_delegated_agent_owners: string;
107
112
  list_delegated_agents: string;
@@ -128,7 +133,12 @@ export declare const COVERED: {
128
133
  transfer_collateral_to_margin_account: string;
129
134
  transfer_collateral_to_parent_margin_account: string;
130
135
  transfer_collateral_to_risk_bucket: string;
136
+ create_sub_account: string;
137
+ close_sub_account: string;
138
+ get_margin_account_pnl: string;
139
+ transfer_collateral: string;
131
140
  claim_buildercode_rewards: string;
141
+ set_builder_fee: string;
132
142
  transfer_rewards: string;
133
143
  update_sub_account_limit: string;
134
144
  upsert_delegated_agent: string;
package/dist/coverage.js CHANGED
@@ -19,6 +19,9 @@ export const COVERED = {
19
19
  list_lead_trader_open_positions: "copyTrading.listLeadTraderOpenPositions",
20
20
  upsert_follow: "copyTrading.upsertFollow",
21
21
  stop_follow: "copyTrading.stopFollow",
22
+ close_follow_positions: "copyTrading.closeFollowPositions",
23
+ close_all_copy_positions: "copyTrading.closeAllCopyPositions",
24
+ add_follow_position_margin: "copyTrading.addFollowPositionMargin",
22
25
  list_my_follows: "copyTrading.listMyFollows",
23
26
  get_follow: "copyTrading.getFollow",
24
27
  list_follow_leader_positions: "copyTrading.listFollowLeaderPositions",
@@ -59,6 +62,7 @@ export const COVERED = {
59
62
  get_rewards_balance: "pitpass.getRewardsBalance",
60
63
  get_my_referral_position: "pitpass.getMyReferralPosition",
61
64
  get_my_referral_downline: "pitpass.getMyReferralDownline",
65
+ get_my_referral_tree: "pitpass.getMyReferralTree",
62
66
  get_self_trade_prevention_default: "profile.getSelfTradePreventionDefault",
63
67
  get_trader_code_info: "pitpass.getTraderCodeInfo",
64
68
  set_self_trade_prevention_default: "profile.setSelfTradePreventionDefault",
@@ -102,6 +106,7 @@ export const COVERED = {
102
106
  list_application_orders: "listApplicationOrders",
103
107
  list_application_users: "listApplicationUsers",
104
108
  list_buildercode_payouts: "buildercodes.listPayouts",
109
+ list_builder_fee_changes: "buildercodes.listBuilderFeeChanges",
105
110
  list_conditional_orders: "listConditionalOrders",
106
111
  list_delegated_agent_owners: "listDelegatedOwners",
107
112
  list_delegated_agents: "listDelegatedAgents",
@@ -128,7 +133,12 @@ export const COVERED = {
128
133
  transfer_collateral_to_margin_account: "transferCollateralToMarginAccount",
129
134
  transfer_collateral_to_parent_margin_account: "transferCollateralToParentMarginAccount",
130
135
  transfer_collateral_to_risk_bucket: "transferCollateralToRiskBucket",
136
+ create_sub_account: "createMarginSubAccount",
137
+ close_sub_account: "closeMarginSubAccount",
138
+ get_margin_account_pnl: "getMarginAccountPnl",
139
+ transfer_collateral: "transferMarginCollateral",
131
140
  claim_buildercode_rewards: "buildercodes.claimBuildercodeRewards",
141
+ set_builder_fee: "buildercodes.setBuilderFee",
132
142
  transfer_rewards: "pitpass.transferRewards",
133
143
  update_sub_account_limit: "subAccounts.updateLimit",
134
144
  upsert_delegated_agent: "upsertDelegatedAgent",
package/dist/sdk.d.ts CHANGED
@@ -99,6 +99,8 @@ export declare class MonacoSDKImpl implements MonacoSDK {
99
99
  * session uses a fresh ed25519 keypair generated locally; the current agent
100
100
  * session signs the registration request, and subsequent SDK calls use the
101
101
  * delegated session keypair.
102
+ * The session expires no later than the delegation. Revocation or an earlier
103
+ * policy expiry also ends access, including reads and session refresh.
102
104
  */
103
105
  loginAsDelegatedOwner(ownerUserId: string): Promise<AuthState>;
104
106
  /**
@@ -134,6 +136,8 @@ export declare class MonacoSDKImpl implements MonacoSDK {
134
136
  * Signs a refresh request with the active session key and updates the local
135
137
  * `expiresAt`. The session keypair is unchanged. If no session is active, or
136
138
  * the session has expired/been revoked, this throws.
139
+ * Delegated sessions also require an active grant; refresh cannot extend
140
+ * access beyond its expiry or renew the owner's authorization.
137
141
  *
138
142
  * @returns The updated authentication state
139
143
  */
package/dist/sdk.js CHANGED
@@ -278,6 +278,8 @@ export class MonacoSDKImpl {
278
278
  * session uses a fresh ed25519 keypair generated locally; the current agent
279
279
  * session signs the registration request, and subsequent SDK calls use the
280
280
  * delegated session keypair.
281
+ * The session expires no later than the delegation. Revocation or an earlier
282
+ * policy expiry also ends access, including reads and session refresh.
281
283
  */
282
284
  async loginAsDelegatedOwner(ownerUserId) {
283
285
  if (!this.authState) {
@@ -358,6 +360,8 @@ export class MonacoSDKImpl {
358
360
  * Signs a refresh request with the active session key and updates the local
359
361
  * `expiresAt`. The session keypair is unchanged. If no session is active, or
360
362
  * the session has expired/been revoked, this throws.
363
+ * Delegated sessions also require an active grant; refresh cannot extend
364
+ * access beyond its expiry or renew the owner's authorization.
361
365
  *
362
366
  * @returns The updated authentication state
363
367
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xmonaco/core",
3
- "version": "1.0.70",
3
+ "version": "1.0.73-develop.af0f5d0",
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.70",
23
- "@0xmonaco/types": "1.0.70",
22
+ "@0xmonaco/contracts": "1.0.73-develop.af0f5d0",
23
+ "@0xmonaco/types": "1.0.73-develop.af0f5d0",
24
24
  "@noble/curves": "^1.9.1",
25
25
  "@noble/hashes": "^2.4.0",
26
26
  "http-status-codes": "^2.3.0"