@0xmonaco/core 0.8.7-develop.34bd452 → 0.8.7-develop.a107b34

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.
Files changed (50) hide show
  1. package/README.md +3 -12
  2. package/dist/api/applications/api.d.ts +61 -8
  3. package/dist/api/applications/api.js +71 -7
  4. package/dist/api/auth/api.d.ts +7 -26
  5. package/dist/api/auth/api.js +6 -42
  6. package/dist/api/base.d.ts +35 -0
  7. package/dist/api/base.js +60 -0
  8. package/dist/api/delegated-agents/api.d.ts +2 -1
  9. package/dist/api/delegated-agents/api.js +4 -0
  10. package/dist/api/faucet/api.d.ts +25 -0
  11. package/dist/api/faucet/api.js +29 -0
  12. package/dist/api/faucet/index.d.ts +1 -0
  13. package/dist/api/faucet/index.js +1 -0
  14. package/dist/api/index.d.ts +4 -0
  15. package/dist/api/index.js +4 -0
  16. package/dist/api/margin-accounts/api.d.ts +9 -5
  17. package/dist/api/margin-accounts/api.js +57 -20
  18. package/dist/api/market/api.d.ts +5 -2
  19. package/dist/api/market/api.js +19 -3
  20. package/dist/api/perp/routes.d.ts +78 -6
  21. package/dist/api/perp/routes.js +36 -6
  22. package/dist/api/positions/api.d.ts +2 -1
  23. package/dist/api/positions/api.js +13 -1
  24. package/dist/api/profile/api.d.ts +18 -1
  25. package/dist/api/profile/api.js +41 -1
  26. package/dist/api/sub-accounts/api.d.ts +62 -0
  27. package/dist/api/sub-accounts/api.js +80 -0
  28. package/dist/api/sub-accounts/index.d.ts +1 -0
  29. package/dist/api/sub-accounts/index.js +1 -0
  30. package/dist/api/trades/api.d.ts +12 -1
  31. package/dist/api/trades/api.js +13 -1
  32. package/dist/api/trading/api.d.ts +5 -2
  33. package/dist/api/trading/api.js +7 -24
  34. package/dist/api/vault/api.d.ts +70 -26
  35. package/dist/api/vault/api.js +124 -39
  36. package/dist/api/vault/index.d.ts +1 -1
  37. package/dist/api/vault/index.js +1 -1
  38. package/dist/api/whitelist/api.d.ts +27 -0
  39. package/dist/api/whitelist/api.js +32 -0
  40. package/dist/api/whitelist/index.d.ts +1 -0
  41. package/dist/api/whitelist/index.js +1 -0
  42. package/dist/api/withdrawals/api.d.ts +17 -0
  43. package/dist/api/withdrawals/api.js +30 -0
  44. package/dist/api/withdrawals/index.d.ts +1 -0
  45. package/dist/api/withdrawals/index.js +1 -0
  46. package/dist/coverage.d.ts +92 -0
  47. package/dist/coverage.js +92 -0
  48. package/dist/sdk.d.ts +32 -1
  49. package/dist/sdk.js +88 -0
  50. package/package.json +3 -3
package/dist/sdk.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ApplicationsAPI, AuthAPI, AuthState, DelegatedAgentsAPI, FeesAPI, MarginAccountsAPI, MarketAPI, MonacoSDK, Network, PositionsAPI, ProfileAPI, SDKConfig, TradingAPI, VaultAPI } from "@0xmonaco/types";
1
+ import type { ApplicationsAPI, AuthAPI, AuthState, DelegatedAgentsAPI, FaucetAPI, FeesAPI, MarginAccountsAPI, MarketAPI, MonacoSDK, Network, PositionsAPI, ProfileAPI, SDKConfig, SubAccountsAPI, TradingAPI, VaultAPI, WhitelistAPI, WithdrawalsAPI } 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 {
@@ -7,10 +7,14 @@ export declare class MonacoSDKImpl implements MonacoSDK {
7
7
  applications: ApplicationsAPI;
8
8
  fees: FeesAPI;
9
9
  vault: VaultAPI;
10
+ withdrawals: WithdrawalsAPI;
10
11
  trading: TradingAPI;
11
12
  market: MarketAPI;
12
13
  marginAccounts: MarginAccountsAPI;
13
14
  positions: PositionsAPI;
15
+ subAccounts: SubAccountsAPI;
16
+ faucet: FaucetAPI;
17
+ whitelist: WhitelistAPI;
14
18
  profile: ProfileAPI;
15
19
  orderbook: OrderbookAPIImpl;
16
20
  trades: TradesAPIImpl;
@@ -25,6 +29,24 @@ export declare class MonacoSDKImpl implements MonacoSDK {
25
29
  * the WebSocket client.
26
30
  */
27
31
  private propagateSession;
32
+ /**
33
+ * Set (or clear) the application secret key used for backend-authenticated
34
+ * requests (those annotated `#[require_backend]` on the gateway, e.g. the
35
+ * `applications` reporting endpoints).
36
+ *
37
+ * The raw `sk_...` key is sent in the `x-server-key` header on each such
38
+ * request. This is independent of {@link login}/session auth — a client may
39
+ * hold both a session and a server key at once.
40
+ *
41
+ * @param serverKey - The application secret key (`sk_...`), or `undefined` to clear.
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * sdk.setServerKey("sk_live_...");
46
+ * const orders = await sdk.applications.listApplicationOrders({ status: "FILLED" });
47
+ * ```
48
+ */
49
+ setServerKey(serverKey: string | undefined): void;
28
50
  /** Extract the session keypair from an auth state. */
29
51
  private sessionFromAuthState;
30
52
  constructor(cfg: SDKConfig);
@@ -63,6 +85,15 @@ export declare class MonacoSDKImpl implements MonacoSDK {
63
85
  login(clientId: string, options?: {
64
86
  connectWebSocket?: boolean;
65
87
  }): Promise<AuthState>;
88
+ /**
89
+ * Create and adopt an owner-scoped delegated session.
90
+ *
91
+ * This must be called while authenticated as the agent wallet. The delegated
92
+ * session uses a fresh ed25519 keypair generated locally; the current agent
93
+ * session signs the registration request, and subsequent SDK calls use the
94
+ * delegated session keypair.
95
+ */
96
+ loginAsDelegatedOwner(ownerUserId: string): Promise<AuthState>;
66
97
  /**
67
98
  * Get the current authentication state
68
99
  *
package/dist/sdk.js CHANGED
@@ -4,13 +4,18 @@ import { sei, seiTestnet } from "viem/chains";
4
4
  import { ApplicationsAPIImpl, createMonacoWebSocket, OrderbookAPIImpl, TradesAPIImpl } from "./api";
5
5
  import { AuthAPIImpl } from "./api/auth";
6
6
  import { DelegatedAgentsAPIImpl } from "./api/delegated-agents";
7
+ import { FaucetAPIImpl } from "./api/faucet";
7
8
  import { FeesAPIImpl } from "./api/fees";
8
9
  import { MarginAccountsAPIImpl } from "./api/margin-accounts";
9
10
  import { MarketAPIImpl } from "./api/market";
10
11
  import { PositionsAPIImpl } from "./api/positions";
11
12
  import { ProfileAPIImpl } from "./api/profile";
13
+ import { SubAccountsAPIImpl } from "./api/sub-accounts";
12
14
  import { TradingAPIImpl } from "./api/trading";
13
15
  import { VaultAPIImpl } from "./api/vault";
16
+ import { WhitelistAPIImpl } from "./api/whitelist";
17
+ import { WithdrawalsAPIImpl } from "./api/withdrawals";
18
+ import { generateSessionKeypair, privateKeyHex, publicKeyHex } from "./crypto/session";
14
19
  import { APIError, InvalidConfigError, InvalidStateError } from "./errors";
15
20
  import { resolveApiUrl, resolveWsUrl } from "./networks";
16
21
  /** Validate a user-supplied URL override, returning it unchanged when valid. */
@@ -29,10 +34,14 @@ export class MonacoSDKImpl {
29
34
  applications;
30
35
  fees;
31
36
  vault;
37
+ withdrawals;
32
38
  trading;
33
39
  market;
34
40
  marginAccounts;
35
41
  positions;
42
+ subAccounts;
43
+ faucet;
44
+ whitelist;
36
45
  profile;
37
46
  orderbook;
38
47
  trades;
@@ -52,15 +61,54 @@ export class MonacoSDKImpl {
52
61
  this.applications.setSessionKeypair(credentials);
53
62
  this.fees.setSessionKeypair(credentials);
54
63
  this.vault.setSessionKeypair(credentials);
64
+ this.withdrawals.setSessionKeypair(credentials);
55
65
  this.trading.setSessionKeypair(credentials);
56
66
  this.market.setSessionKeypair(credentials);
57
67
  this.marginAccounts.setSessionKeypair(credentials);
58
68
  this.positions.setSessionKeypair(credentials);
69
+ this.subAccounts.setSessionKeypair(credentials);
70
+ this.faucet.setSessionKeypair(credentials);
71
+ this.whitelist.setSessionKeypair(credentials);
59
72
  this.profile.setSessionKeypair(credentials);
60
73
  this.orderbook.setSessionKeypair(credentials);
61
74
  this.trades.setSessionKeypair(credentials);
62
75
  this.ws.setSessionKeypair(credentials);
63
76
  }
77
+ /**
78
+ * Set (or clear) the application secret key used for backend-authenticated
79
+ * requests (those annotated `#[require_backend]` on the gateway, e.g. the
80
+ * `applications` reporting endpoints).
81
+ *
82
+ * The raw `sk_...` key is sent in the `x-server-key` header on each such
83
+ * request. This is independent of {@link login}/session auth — a client may
84
+ * hold both a session and a server key at once.
85
+ *
86
+ * @param serverKey - The application secret key (`sk_...`), or `undefined` to clear.
87
+ *
88
+ * @example
89
+ * ```typescript
90
+ * sdk.setServerKey("sk_live_...");
91
+ * const orders = await sdk.applications.listApplicationOrders({ status: "FILLED" });
92
+ * ```
93
+ */
94
+ setServerKey(serverKey) {
95
+ this.auth.setServerKey(serverKey);
96
+ this.delegatedAgents.setServerKey(serverKey);
97
+ this.applications.setServerKey(serverKey);
98
+ this.fees.setServerKey(serverKey);
99
+ this.vault.setServerKey(serverKey);
100
+ this.withdrawals.setServerKey(serverKey);
101
+ this.trading.setServerKey(serverKey);
102
+ this.market.setServerKey(serverKey);
103
+ this.marginAccounts.setServerKey(serverKey);
104
+ this.positions.setServerKey(serverKey);
105
+ this.subAccounts.setServerKey(serverKey);
106
+ this.faucet.setServerKey(serverKey);
107
+ this.whitelist.setServerKey(serverKey);
108
+ this.profile.setServerKey(serverKey);
109
+ this.orderbook.setServerKey(serverKey);
110
+ this.trades.setServerKey(serverKey);
111
+ }
64
112
  /** Extract the session keypair from an auth state. */
65
113
  sessionFromAuthState(authState) {
66
114
  return {
@@ -110,11 +158,15 @@ export class MonacoSDKImpl {
110
158
  this.market = new MarketAPIImpl(apiUrl);
111
159
  this.marginAccounts = new MarginAccountsAPIImpl(apiUrl);
112
160
  this.positions = new PositionsAPIImpl(apiUrl);
161
+ this.subAccounts = new SubAccountsAPIImpl(apiUrl);
162
+ this.faucet = new FaucetAPIImpl(apiUrl);
163
+ this.whitelist = new WhitelistAPIImpl(apiUrl);
113
164
  this.auth = new AuthAPIImpl(this.walletClient, this.chain, apiUrl);
114
165
  this.delegatedAgents = new DelegatedAgentsAPIImpl(apiUrl);
115
166
  this.fees = new FeesAPIImpl(apiUrl);
116
167
  this.profile = new ProfileAPIImpl(apiUrl);
117
168
  this.vault = new VaultAPIImpl(this.publicClient, this.walletClient, this.chain, this.applications, this.profile, apiUrl);
169
+ this.withdrawals = new WithdrawalsAPIImpl(apiUrl);
118
170
  this.trading = new TradingAPIImpl(apiUrl);
119
171
  this.orderbook = new OrderbookAPIImpl(apiUrl);
120
172
  this.trades = new TradesAPIImpl(apiUrl);
@@ -163,6 +215,42 @@ export class MonacoSDKImpl {
163
215
  }
164
216
  return this.authState;
165
217
  }
218
+ /**
219
+ * Create and adopt an owner-scoped delegated session.
220
+ *
221
+ * This must be called while authenticated as the agent wallet. The delegated
222
+ * session uses a fresh ed25519 keypair generated locally; the current agent
223
+ * session signs the registration request, and subsequent SDK calls use the
224
+ * delegated session keypair.
225
+ */
226
+ async loginAsDelegatedOwner(ownerUserId) {
227
+ if (!this.authState) {
228
+ throw new APIError("No active agent session to create delegated session", {
229
+ endpoint: "delegated-agents/sessions",
230
+ statusCode: StatusCodes.UNAUTHORIZED,
231
+ });
232
+ }
233
+ const keypair = generateSessionKeypair();
234
+ const session = {
235
+ publicKey: publicKeyHex(keypair),
236
+ privateKey: privateKeyHex(keypair),
237
+ };
238
+ const delegatedSession = await this.delegatedAgents.createDelegatedSession({
239
+ ownerUserId,
240
+ sessionPublicKey: session.publicKey,
241
+ });
242
+ this.authState = {
243
+ sessionPublicKey: session.publicKey,
244
+ sessionPrivateKey: session.privateKey,
245
+ expiresAt: delegatedSession.expires_at,
246
+ user: {
247
+ id: delegatedSession.owner_user_id,
248
+ address: delegatedSession.agent_address,
249
+ },
250
+ };
251
+ this.propagateSession(this.sessionFromAuthState(this.authState));
252
+ return this.authState;
253
+ }
166
254
  /**
167
255
  * Get the current authentication state
168
256
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xmonaco/core",
3
- "version": "0.8.7-develop.34bd452",
3
+ "version": "0.8.7-develop.a107b34",
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.7-develop.34bd452",
27
- "@0xmonaco/types": "0.8.7-develop.34bd452",
26
+ "@0xmonaco/contracts": "0.8.7-develop.a107b34",
27
+ "@0xmonaco/types": "0.8.7-develop.a107b34",
28
28
  "@noble/curves": "^1.9.1",
29
29
  "@noble/hashes": "^1.8.0",
30
30
  "http-status-codes": "^2.3.0"