@0xmonaco/core 0.8.8 → 0.8.11
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/README.md +3 -12
- package/dist/api/applications/api.d.ts +61 -8
- package/dist/api/applications/api.js +71 -7
- package/dist/api/auth/api.d.ts +7 -26
- package/dist/api/auth/api.js +6 -42
- package/dist/api/base.d.ts +35 -0
- package/dist/api/base.js +60 -0
- package/dist/api/delegated-agents/api.d.ts +2 -1
- package/dist/api/delegated-agents/api.js +4 -0
- package/dist/api/faucet/api.d.ts +25 -0
- package/dist/api/faucet/api.js +29 -0
- package/dist/api/faucet/index.d.ts +1 -0
- package/dist/api/faucet/index.js +1 -0
- package/dist/api/index.d.ts +4 -0
- package/dist/api/index.js +4 -0
- package/dist/api/margin-accounts/api.d.ts +3 -4
- package/dist/api/margin-accounts/api.js +8 -15
- package/dist/api/market/api.d.ts +4 -1
- package/dist/api/market/api.js +14 -0
- package/dist/api/perp/routes.d.ts +64 -4
- package/dist/api/perp/routes.js +28 -4
- package/dist/api/profile/api.d.ts +18 -1
- package/dist/api/profile/api.js +41 -1
- package/dist/api/sub-accounts/api.d.ts +62 -0
- package/dist/api/sub-accounts/api.js +80 -0
- package/dist/api/sub-accounts/index.d.ts +1 -0
- package/dist/api/sub-accounts/index.js +1 -0
- package/dist/api/trades/api.d.ts +12 -1
- package/dist/api/trades/api.js +13 -1
- package/dist/api/trading/api.d.ts +5 -2
- package/dist/api/trading/api.js +7 -24
- package/dist/api/vault/api.d.ts +26 -2
- package/dist/api/vault/api.js +33 -4
- package/dist/api/vault/index.d.ts +1 -1
- package/dist/api/vault/index.js +1 -1
- package/dist/api/whitelist/api.d.ts +27 -0
- package/dist/api/whitelist/api.js +32 -0
- package/dist/api/whitelist/index.d.ts +1 -0
- package/dist/api/whitelist/index.js +1 -0
- package/dist/api/withdrawals/api.d.ts +15 -0
- package/dist/api/withdrawals/api.js +27 -0
- package/dist/api/withdrawals/index.d.ts +1 -0
- package/dist/api/withdrawals/index.js +1 -0
- package/dist/coverage.d.ts +86 -0
- package/dist/coverage.js +86 -0
- package/dist/sdk.d.ts +32 -1
- package/dist/sdk.js +88 -0
- package/package.json +3 -3
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.
|
|
3
|
+
"version": "0.8.11",
|
|
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.
|
|
27
|
-
"@0xmonaco/types": "0.8.
|
|
26
|
+
"@0xmonaco/contracts": "0.8.11",
|
|
27
|
+
"@0xmonaco/types": "0.8.11",
|
|
28
28
|
"@noble/curves": "^1.9.1",
|
|
29
29
|
"@noble/hashes": "^1.8.0",
|
|
30
30
|
"http-status-codes": "^2.3.0"
|