@0xmonaco/core 1.0.70 → 1.0.73

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` is active;
40
+ * `BUILDER_FEE` is reserved and is not currently emitted. Pass `kind` to
41
+ * filter 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` is active;
132
+ * `BUILDER_FEE` is reserved and is not currently emitted. Pass `kind` to
133
+ * filter 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);
@@ -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
@@ -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;
@@ -102,6 +105,7 @@ export declare const COVERED: {
102
105
  list_application_orders: string;
103
106
  list_application_users: string;
104
107
  list_buildercode_payouts: string;
108
+ list_builder_fee_changes: string;
105
109
  list_conditional_orders: string;
106
110
  list_delegated_agent_owners: string;
107
111
  list_delegated_agents: string;
@@ -129,6 +133,7 @@ export declare const COVERED: {
129
133
  transfer_collateral_to_parent_margin_account: string;
130
134
  transfer_collateral_to_risk_bucket: string;
131
135
  claim_buildercode_rewards: string;
136
+ set_builder_fee: string;
132
137
  transfer_rewards: string;
133
138
  update_sub_account_limit: string;
134
139
  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",
@@ -102,6 +105,7 @@ export const COVERED = {
102
105
  list_application_orders: "listApplicationOrders",
103
106
  list_application_users: "listApplicationUsers",
104
107
  list_buildercode_payouts: "buildercodes.listPayouts",
108
+ list_builder_fee_changes: "buildercodes.listBuilderFeeChanges",
105
109
  list_conditional_orders: "listConditionalOrders",
106
110
  list_delegated_agent_owners: "listDelegatedOwners",
107
111
  list_delegated_agents: "listDelegatedAgents",
@@ -129,6 +133,7 @@ export const COVERED = {
129
133
  transfer_collateral_to_parent_margin_account: "transferCollateralToParentMarginAccount",
130
134
  transfer_collateral_to_risk_bucket: "transferCollateralToRiskBucket",
131
135
  claim_buildercode_rewards: "buildercodes.claimBuildercodeRewards",
136
+ set_builder_fee: "buildercodes.setBuilderFee",
132
137
  transfer_rewards: "pitpass.transferRewards",
133
138
  update_sub_account_limit: "subAccounts.updateLimit",
134
139
  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",
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",
23
+ "@0xmonaco/types": "1.0.73",
24
24
  "@noble/curves": "^1.9.1",
25
25
  "@noble/hashes": "^2.4.0",
26
26
  "http-status-codes": "^2.3.0"