@0xmonaco/core 0.8.1 → 0.8.5

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.
@@ -0,0 +1,10 @@
1
+ import type { CreateDelegatedSessionRequest, CreateDelegatedSessionResponse, DelegatedAgent, DelegatedAgentsAPI, ListDelegatedAgentsResponse, UpsertDelegatedAgentRequest } from "@0xmonaco/types";
2
+ import { BaseAPI } from "../base";
3
+ export declare class DelegatedAgentsAPIImpl extends BaseAPI implements DelegatedAgentsAPI {
4
+ upsertDelegatedAgent(request: UpsertDelegatedAgentRequest): Promise<DelegatedAgent>;
5
+ listDelegatedAgents(): Promise<ListDelegatedAgentsResponse>;
6
+ revokeDelegatedAgent(delegatedAgentId: string): Promise<{
7
+ status: "REVOKED";
8
+ }>;
9
+ createDelegatedSession(request: CreateDelegatedSessionRequest): Promise<CreateDelegatedSessionResponse>;
10
+ }
@@ -0,0 +1,38 @@
1
+ import { BaseAPI } from "../base";
2
+ import { perpRoutes } from "../perp";
3
+ export class DelegatedAgentsAPIImpl extends BaseAPI {
4
+ async upsertDelegatedAgent(request) {
5
+ return this.makeAuthenticatedRequest(perpRoutes.delegatedAgents.list(), {
6
+ method: "POST",
7
+ body: JSON.stringify({
8
+ agent_address: request.agentAddress,
9
+ name: request.name,
10
+ expires_at: request.expiresAt,
11
+ allowed_actions: request.allowedActions,
12
+ allowed_trading_pair_ids: request.allowedTradingPairIds,
13
+ allowed_margin_account_ids: request.allowedMarginAccountIds,
14
+ allowed_order_types: request.allowedOrderTypes,
15
+ allowed_time_in_force: request.allowedTimeInForce,
16
+ max_leverage: request.maxLeverage,
17
+ max_order_notional: request.maxOrderNotional,
18
+ max_open_orders: request.maxOpenOrders,
19
+ }),
20
+ });
21
+ }
22
+ async listDelegatedAgents() {
23
+ return this.makeAuthenticatedRequest(perpRoutes.delegatedAgents.list());
24
+ }
25
+ async revokeDelegatedAgent(delegatedAgentId) {
26
+ return this.makeAuthenticatedRequest(perpRoutes.delegatedAgents.byId(delegatedAgentId), {
27
+ method: "DELETE",
28
+ });
29
+ }
30
+ async createDelegatedSession(request) {
31
+ return this.makeAuthenticatedRequest(perpRoutes.delegatedAgents.sessions(), {
32
+ method: "POST",
33
+ body: JSON.stringify({
34
+ owner_user_id: request.ownerUserId,
35
+ }),
36
+ });
37
+ }
38
+ }
@@ -0,0 +1 @@
1
+ export * from "./api";
@@ -0,0 +1 @@
1
+ export * from "./api";
@@ -5,6 +5,7 @@
5
5
  */
6
6
  export * from "./applications/index";
7
7
  export * from "./base";
8
+ export * from "./delegated-agents";
8
9
  export * from "./fees";
9
10
  export * from "./margin-accounts";
10
11
  export * from "./market";
package/dist/api/index.js CHANGED
@@ -5,6 +5,7 @@
5
5
  */
6
6
  export * from "./applications/index";
7
7
  export * from "./base";
8
+ export * from "./delegated-agents";
8
9
  export * from "./fees";
9
10
  export * from "./margin-accounts";
10
11
  export * from "./market";
@@ -1,4 +1,4 @@
1
- import type { CreateMarginAccountRequest, CreateMarginAccountResponse, GetAvailableCollateralParams, GetAvailableCollateralResponse, GetMarginAccountMovementsParams, GetMarginAccountMovementsResponse, ListMarginAccountsParams, ListMarginAccountsResponse, MarginAccountSummary, MarginAccountsAPI, SimulateOrderRiskRequest, SimulateOrderRiskResponse, TransferCollateralRequest, TransferCollateralResponse } from "@0xmonaco/types";
1
+ import type { CreateMarginAccountRequest, CreateMarginAccountResponse, GetAvailableCollateralParams, GetAvailableCollateralResponse, GetMarginAccountMovementsParams, GetMarginAccountMovementsResponse, ListMarginAccountsParams, ListMarginAccountsResponse, MarginAccountSummary, MarginAccountsAPI, SimulateOrderRiskRequest, SimulateOrderRiskResponse, TransferCollateralRequest, TransferCollateralResponse, TransferCollateralToAutoMarginAccountRequest } from "@0xmonaco/types";
2
2
  import { BaseAPI } from "../base";
3
3
  export declare class MarginAccountsAPIImpl extends BaseAPI implements MarginAccountsAPI {
4
4
  listMarginAccounts(params?: ListMarginAccountsParams): Promise<ListMarginAccountsResponse>;
@@ -6,7 +6,9 @@ export declare class MarginAccountsAPIImpl extends BaseAPI implements MarginAcco
6
6
  getMarginAccountSummary(marginAccountId: string): Promise<MarginAccountSummary>;
7
7
  getAvailableCollateral(params?: GetAvailableCollateralParams): Promise<GetAvailableCollateralResponse>;
8
8
  transferCollateralToMarginAccount(marginAccountId: string, request: TransferCollateralRequest): Promise<TransferCollateralResponse>;
9
+ transferCollateralToAutoMarginAccount(request: TransferCollateralToAutoMarginAccountRequest): Promise<TransferCollateralResponse>;
9
10
  transferCollateralFromMarginAccount(marginAccountId: string, request: TransferCollateralRequest): Promise<TransferCollateralResponse>;
10
11
  getMarginAccountMovements(marginAccountId: string, params?: GetMarginAccountMovementsParams): Promise<GetMarginAccountMovementsResponse>;
11
12
  simulateOrderRisk(marginAccountId: string, request: SimulateOrderRiskRequest): Promise<SimulateOrderRiskResponse>;
13
+ simulateAutoMarginOrderRisk(request: SimulateOrderRiskRequest): Promise<SimulateOrderRiskResponse>;
12
14
  }
@@ -1,4 +1,4 @@
1
- import { CreateMarginAccountSchema, GetAvailableCollateralSchema, GetMarginAccountMovementsSchema, GetMarginAccountSummarySchema, ListMarginAccountsSchema, SimulateOrderRiskSchema, TransferCollateralSchema, validate, } from "@0xmonaco/types";
1
+ import { CreateMarginAccountSchema, GetAvailableCollateralSchema, GetMarginAccountMovementsSchema, GetMarginAccountSummarySchema, ListMarginAccountsSchema, SimulateAutoMarginOrderRiskSchema, SimulateOrderRiskSchema, TransferCollateralSchema, TransferCollateralToAutoMarginAccountSchema, validate, } from "@0xmonaco/types";
2
2
  import { BaseAPI } from "../base";
3
3
  import { perpRoutes } from "../perp";
4
4
  export class MarginAccountsAPIImpl extends BaseAPI {
@@ -6,7 +6,14 @@ export class MarginAccountsAPIImpl extends BaseAPI {
6
6
  if (params) {
7
7
  validate(ListMarginAccountsSchema, params);
8
8
  }
9
- return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.list(params));
9
+ return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.list(params
10
+ ? {
11
+ page: params.page,
12
+ page_size: params.page_size,
13
+ state: params.state,
14
+ trading_pair_id: params.tradingPairId,
15
+ }
16
+ : undefined));
10
17
  }
11
18
  async createMarginAccount(request) {
12
19
  validate(CreateMarginAccountSchema, request);
@@ -36,6 +43,18 @@ export class MarginAccountsAPIImpl extends BaseAPI {
36
43
  }),
37
44
  });
38
45
  }
46
+ async transferCollateralToAutoMarginAccount(request) {
47
+ validate(TransferCollateralToAutoMarginAccountSchema, { request });
48
+ return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.transferInAuto(), {
49
+ method: "POST",
50
+ body: JSON.stringify({
51
+ asset: request.asset,
52
+ amount: request.amount,
53
+ trading_pair_id: request.tradingPairId,
54
+ strategy_key: request.strategyKey,
55
+ }),
56
+ });
57
+ }
39
58
  async transferCollateralFromMarginAccount(marginAccountId, request) {
40
59
  validate(TransferCollateralSchema, { marginAccountId, request });
41
60
  return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.transferOut(marginAccountId), {
@@ -56,6 +75,24 @@ export class MarginAccountsAPIImpl extends BaseAPI {
56
75
  method: "POST",
57
76
  body: JSON.stringify({
58
77
  trading_pair_id: request.tradingPairId,
78
+ strategy_key: request.strategyKey,
79
+ side: request.side,
80
+ position_side: request.positionSide,
81
+ order_type: request.orderType,
82
+ price: request.price,
83
+ quantity: request.quantity,
84
+ leverage: request.leverage,
85
+ reduce_only: request.reduceOnly,
86
+ }),
87
+ });
88
+ }
89
+ async simulateAutoMarginOrderRisk(request) {
90
+ validate(SimulateAutoMarginOrderRiskSchema, { request });
91
+ return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.simulateOrderRiskAuto(), {
92
+ method: "POST",
93
+ body: JSON.stringify({
94
+ trading_pair_id: request.tradingPairId,
95
+ strategy_key: request.strategyKey,
59
96
  side: request.side,
60
97
  position_side: request.positionSide,
61
98
  order_type: request.orderType,
@@ -27,6 +27,11 @@ export declare const perpRoutes: {
27
27
  }) => string;
28
28
  readonly cancelConditional: (conditionalOrderId: string) => string;
29
29
  };
30
+ readonly delegatedAgents: {
31
+ readonly list: () => string;
32
+ readonly byId: (delegatedAgentId: string) => string;
33
+ readonly sessions: () => string;
34
+ };
30
35
  readonly market: {
31
36
  readonly listTradingPairs: (params?: {
32
37
  page?: number;
@@ -103,6 +108,7 @@ export declare const perpRoutes: {
103
108
  page?: number;
104
109
  page_size?: number;
105
110
  state?: string;
111
+ trading_pair_id?: string;
106
112
  }) => string;
107
113
  readonly create: () => string;
108
114
  readonly summary: (marginAccountId: string) => string;
@@ -110,6 +116,7 @@ export declare const perpRoutes: {
110
116
  asset?: string;
111
117
  }) => string;
112
118
  readonly transferIn: (marginAccountId: string) => string;
119
+ readonly transferInAuto: () => string;
113
120
  readonly transferOut: (marginAccountId: string) => string;
114
121
  readonly movements: (marginAccountId: string, params?: {
115
122
  movement_type?: string;
@@ -117,6 +124,7 @@ export declare const perpRoutes: {
117
124
  page_size?: number;
118
125
  }) => string;
119
126
  readonly simulateOrderRisk: (marginAccountId: string) => string;
127
+ readonly simulateOrderRiskAuto: () => string;
120
128
  };
121
129
  readonly streams: {
122
130
  readonly orderbook: () => string;
@@ -30,6 +30,11 @@ export const perpRoutes = {
30
30
  listConditional: (params) => withQuery(`${API_V1}/orders/conditional`, params),
31
31
  cancelConditional: (conditionalOrderId) => `${API_V1}/orders/conditional/${encodeSegment(conditionalOrderId)}`,
32
32
  },
33
+ delegatedAgents: {
34
+ list: () => `${API_V1}/delegated-agents`,
35
+ byId: (delegatedAgentId) => `${API_V1}/delegated-agents/${encodeSegment(delegatedAgentId)}`,
36
+ sessions: () => `${API_V1}/delegated-agents/sessions`,
37
+ },
33
38
  market: {
34
39
  listTradingPairs: (params) => withQuery(`${API_V1}/market/pairs`, params),
35
40
  getTradingPair: (tradingPairId) => `${API_V1}/market/pairs/${encodeSegment(tradingPairId)}`,
@@ -66,9 +71,11 @@ export const perpRoutes = {
66
71
  summary: (marginAccountId) => `${API_V1}/margin/accounts/${encodeSegment(marginAccountId)}`,
67
72
  availableCollateral: (params) => withQuery(`${API_V1}/margin/collateral/available`, params),
68
73
  transferIn: (marginAccountId) => `${API_V1}/margin/accounts/${encodeSegment(marginAccountId)}/collateral/transfer-in`,
74
+ transferInAuto: () => `${API_V1}/margin/collateral/transfer-in`,
69
75
  transferOut: (marginAccountId) => `${API_V1}/margin/accounts/${encodeSegment(marginAccountId)}/collateral/transfer-out`,
70
76
  movements: (marginAccountId, params) => withQuery(`${API_V1}/margin/accounts/${encodeSegment(marginAccountId)}/movements`, params),
71
77
  simulateOrderRisk: (marginAccountId) => `${API_V1}/margin/accounts/${encodeSegment(marginAccountId)}/simulate-order-risk`,
78
+ simulateOrderRiskAuto: () => `${API_V1}/margin/simulate-order-risk`,
72
79
  },
73
80
  streams: {
74
81
  orderbook: () => `${API_V1}/streaming/orderbook`,
@@ -80,6 +80,7 @@ export declare class TradingAPIImpl extends BaseAPI implements TradingAPI {
80
80
  expirationDate?: string;
81
81
  timeInForce?: TimeInForce;
82
82
  marginAccountId?: string;
83
+ strategyKey?: string;
83
84
  positionSide?: PositionSide;
84
85
  leverage?: string;
85
86
  reduceOnly?: boolean;
@@ -131,6 +132,7 @@ export declare class TradingAPIImpl extends BaseAPI implements TradingAPI {
131
132
  tradingMode?: TradingMode;
132
133
  slippageTolerance?: number;
133
134
  marginAccountId?: string;
135
+ strategyKey?: string;
134
136
  positionSide?: PositionSide;
135
137
  leverage?: string;
136
138
  reduceOnly?: boolean;
@@ -107,6 +107,7 @@ export class TradingAPIImpl extends BaseAPI {
107
107
  expiration_date: options?.expirationDate,
108
108
  time_in_force: options?.timeInForce,
109
109
  margin_account_id: options?.marginAccountId,
110
+ strategy_key: options?.strategyKey,
110
111
  position_side: options?.positionSide,
111
112
  leverage: options?.leverage,
112
113
  reduce_only: options?.reduceOnly,
@@ -176,6 +177,7 @@ export class TradingAPIImpl extends BaseAPI {
176
177
  quantity,
177
178
  trading_mode: options?.tradingMode || "SPOT",
178
179
  margin_account_id: options?.marginAccountId,
180
+ strategy_key: options?.strategyKey,
179
181
  position_side: options?.positionSide,
180
182
  leverage: options?.leverage,
181
183
  reduce_only: options?.reduceOnly,
@@ -361,6 +363,7 @@ export class TradingAPIImpl extends BaseAPI {
361
363
  expiration_date: order.expirationDate,
362
364
  time_in_force: order.timeInForce,
363
365
  margin_account_id: order.marginAccountId,
366
+ strategy_key: order.strategyKey,
364
367
  position_side: order.positionSide,
365
368
  leverage: order.leverage,
366
369
  reduce_only: order.reduceOnly,
package/dist/sdk.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- import type { ApplicationsAPI, AuthAPI, AuthState, FeesAPI, MarginAccountsAPI, MarketAPI, MonacoSDK, Network, PositionsAPI, ProfileAPI, SDKConfig, TradingAPI, VaultAPI } from "@0xmonaco/types";
1
+ import type { ApplicationsAPI, AuthAPI, AuthState, DelegatedAgentsAPI, FeesAPI, MarginAccountsAPI, MarketAPI, MonacoSDK, Network, PositionsAPI, ProfileAPI, SDKConfig, TradingAPI, VaultAPI } from "@0xmonaco/types";
2
2
  import { type PublicClient, type TransactionReceipt, type WalletClient } from "viem";
3
3
  import { type MonacoWebSocket, OrderbookAPIImpl, TradesAPIImpl } from "./api";
4
4
  export declare class MonacoSDKImpl implements MonacoSDK {
5
5
  auth: AuthAPI;
6
+ delegatedAgents: DelegatedAgentsAPI;
6
7
  applications: ApplicationsAPI;
7
8
  fees: FeesAPI;
8
9
  vault: VaultAPI;
package/dist/sdk.js CHANGED
@@ -3,6 +3,7 @@ import { createPublicClient, http } from "viem";
3
3
  import { sei, seiTestnet } from "viem/chains";
4
4
  import { ApplicationsAPIImpl, createMonacoWebSocket, OrderbookAPIImpl, TradesAPIImpl } from "./api";
5
5
  import { AuthAPIImpl } from "./api/auth";
6
+ import { DelegatedAgentsAPIImpl } from "./api/delegated-agents";
6
7
  import { FeesAPIImpl } from "./api/fees";
7
8
  import { MarginAccountsAPIImpl } from "./api/margin-accounts";
8
9
  import { MarketAPIImpl } from "./api/market";
@@ -14,6 +15,7 @@ import { APIError, InvalidConfigError, InvalidStateError } from "./errors";
14
15
  import { resolveApiUrl, resolveWsUrl } from "./networks";
15
16
  export class MonacoSDKImpl {
16
17
  auth;
18
+ delegatedAgents;
17
19
  applications;
18
20
  fees;
19
21
  vault;
@@ -35,6 +37,7 @@ export class MonacoSDKImpl {
35
37
  */
36
38
  propagateAccessToken(accessToken) {
37
39
  this.auth.setAccessToken(accessToken);
40
+ this.delegatedAgents.setAccessToken(accessToken);
38
41
  this.applications.setAccessToken(accessToken);
39
42
  this.fees.setAccessToken(accessToken);
40
43
  this.vault.setAccessToken(accessToken);
@@ -90,6 +93,7 @@ export class MonacoSDKImpl {
90
93
  this.marginAccounts = new MarginAccountsAPIImpl(apiUrl);
91
94
  this.positions = new PositionsAPIImpl(apiUrl);
92
95
  this.auth = new AuthAPIImpl(this.walletClient, this.chain, apiUrl);
96
+ this.delegatedAgents = new DelegatedAgentsAPIImpl(apiUrl);
93
97
  this.fees = new FeesAPIImpl(apiUrl);
94
98
  this.profile = new ProfileAPIImpl(apiUrl);
95
99
  this.vault = new VaultAPIImpl(this.publicClient, this.walletClient, this.chain, this.applications, this.profile, apiUrl);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xmonaco/core",
3
- "version": "0.8.1",
3
+ "version": "0.8.5",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,8 +23,8 @@
23
23
  "viem": "^2.45.2"
24
24
  },
25
25
  "dependencies": {
26
- "@0xmonaco/contracts": "0.8.1",
27
- "@0xmonaco/types": "0.8.1",
26
+ "@0xmonaco/contracts": "0.8.5",
27
+ "@0xmonaco/types": "0.8.5",
28
28
  "http-status-codes": "^2.3.0"
29
29
  },
30
30
  "devDependencies": {