Skip to content

Commit 5272b8a

Browse files
chore: sync from internal
1 parent 7757b5c commit 5272b8a

201 files changed

Lines changed: 8023 additions & 5970 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
diff --git a/dist/Cli.d.ts b/dist/Cli.d.ts
2+
index 5c8cfeccb7595a4129d882cb8a1b94776b3d151b..fbe7e0237803be5553de268a331178ed46f81461 100644
3+
--- a/dist/Cli.d.ts
4+
+++ b/dist/Cli.d.ts
5+
@@ -200,6 +200,15 @@ export declare namespace create {
6+
agents?: string[] | undefined;
7+
/** Override the command agents will run to start the MCP server. Auto-detected if omitted. */
8+
command?: string | undefined;
9+
+ /** Instructions passed to the MCP server, surfaced to the AI agent. Only effective on the root CLI. */
10+
+ instructions?: string | undefined;
11+
+ /** MCP tool annotations for this command. */
12+
+ annotations?: {
13+
+ readOnlyHint?: boolean;
14+
+ destructiveHint?: boolean;
15+
+ idempotentHint?: boolean;
16+
+ openWorldHint?: boolean;
17+
+ } | undefined;
18+
} | undefined;
19+
/** Options for the built-in `skills add` command. */
20+
sync?: {
21+
diff --git a/dist/Cli.js b/dist/Cli.js
22+
index 1467ccf7a6eb6c2bf1e7a5172631032ea3c342e7..0ab7e87b073b3c63844cf17698df153ead4abe50 100644
23+
--- a/dist/Cli.js
24+
+++ b/dist/Cli.js
25+
@@ -171,6 +171,7 @@ async function serveImpl(name, commands, argv, options = {}) {
26+
env: options.envSchema,
27+
vars: options.vars,
28+
version: options.version,
29+
+ ...(options.mcp?.instructions ? { instructions: options.mcp.instructions } : undefined),
30+
});
31+
return;
32+
}
33+
diff --git a/dist/Mcp.d.ts b/dist/Mcp.d.ts
34+
index 19133240a3ca922693a027040510d5bb0ca143af..0383af1e3dff306c35b3bf9ea3d82618365b0827 100644
35+
--- a/dist/Mcp.d.ts
36+
+++ b/dist/Mcp.d.ts
37+
@@ -62,6 +62,13 @@ export type ToolEntry = {
38+
required?: string[];
39+
};
40+
outputSchema?: Record<string, unknown> | undefined;
41+
+ annotations?: {
42+
+ readOnlyHint?: boolean;
43+
+ destructiveHint?: boolean;
44+
+ idempotentHint?: boolean;
45+
+ openWorldHint?: boolean;
46+
+ } | undefined;
47+
+ instructions?: string | undefined;
48+
command: any;
49+
middlewares?: MiddlewareHandler[] | undefined;
50+
};
51+
diff --git a/dist/Mcp.js b/dist/Mcp.js
52+
index 74f218ddbad2b0febf9a33e5ea29df2a25a0fc99..15afbfd2830e31ac6eea5bae9815fb9eed1b8260 100644
53+
--- a/dist/Mcp.js
54+
+++ b/dist/Mcp.js
55+
@@ -4,7 +4,7 @@ import * as Command from './internal/command.js';
56+
import * as Schema from './Schema.js';
57+
/** Starts a stdio MCP server that exposes commands as tools. */
58+
export async function serve(name, version, commands, options = {}) {
59+
- const server = new McpServer({ name, version });
60+
+ const server = new McpServer({ name, version, ...(options.instructions ? { instructions: options.instructions } : undefined) });
61+
for (const tool of collectTools(commands, [])) {
62+
const mergedShape = {
63+
...tool.command.args?.shape,
64+
@@ -15,6 +15,8 @@ export async function serve(name, version, commands, options = {}) {
65+
...(tool.description ? { description: tool.description } : undefined),
66+
...(hasInput ? { inputSchema: z.object(mergedShape) } : undefined),
67+
...(tool.outputSchema ? { outputSchema: tool.outputSchema } : undefined),
68+
+ ...(tool.annotations ? { annotations: tool.annotations } : undefined),
69+
+ ...(tool.instructions ? { _meta: { instructions: tool.instructions } } : undefined),
70+
}, async (...callArgs) => {
71+
// registerTool passes (args, extra) when inputSchema is set, (extra) when not
72+
const params = hasInput ? callArgs[0] : {};
73+
@@ -114,6 +116,8 @@ export function collectTools(commands, prefix, parentMiddlewares = []) {
74+
...(entry.output
75+
? { outputSchema: Schema.toJsonSchema(entry.output) }
76+
: undefined),
77+
+ ...(entry.mcp?.annotations ? { annotations: entry.mcp.annotations } : undefined),
78+
+ ...(entry.mcp?.instructions ? { instructions: entry.mcp.instructions } : undefined),
79+
command: entry,
80+
...(parentMiddlewares.length > 0 ? { middlewares: parentMiddlewares } : undefined),
81+
});

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ import {
3030
// App wrapper with provider and theme configuration
3131
<PhantomProvider
3232
config={{
33-
providers: ["google", "apple", "phantom", "injected"], // Allowed auth providers
33+
providers: ["google", "apple", "injected"], // Allowed auth providers
3434
addressTypes: [AddressType.solana, AddressType.ethereum],
35-
appId: "your-app-id", // Required when using embedded providers (google, apple, phantom, etc.)
35+
appId: "your-app-id", // Required when using embedded providers (google, apple, etc.)
3636
// Optional:
3737
// apiBaseUrl: "https://api.phantom.app/v1/wallets",
3838
}}
@@ -193,7 +193,7 @@ Thin wrapper over `@phantom/browser-sdk` that provides React hooks, context prov
193193

194194
- React hooks: `usePhantom`, `useConnect`, `useDisconnect`, `useSolana`, `useEthereum`
195195
- `ConnectButton` component - Ready-to-use button that handles the complete connection flow
196-
- Built-in connection modal with authentication providers (Google, Apple, Phantom Login, Browser Extension)
196+
- Built-in connection modal with authentication providers (Google, Apple, Browser Extension)
197197
- Theme system with `darkTheme` and `lightTheme` presets
198198
- Automatic mobile deeplink support for Phantom mobile app
199199

packages/cli/PERPS.md

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
# Perpetuals (Hyperliquid) — @phantom/cli
2+
3+
The Phantom CLI exposes a full suite of perpetuals commands backed by [Hyperliquid](https://hyperliquid.xyz/). This document covers each command, its options, and common workflows.
4+
5+
When running in MCP server mode (`phantom --mcp`), all commands are exposed as MCP tools under the `perps_` prefix.
6+
7+
## Command Reference
8+
9+
### `phantom perps markets` — MCP: `perps_markets`
10+
11+
List all available perpetual markets on Hyperliquid with current prices, funding rates, open interest, 24h volume, max leverage, and asset IDs. Use this to discover tradeable markets and get current prices before opening positions.
12+
13+
**Options:** none required
14+
15+
---
16+
17+
### `phantom perps account` — MCP: `perps_account`
18+
19+
Get your perpetuals account balance including total account value, available balance, and withdrawable amount. The account is funded with USDC on Hyperliquid.
20+
21+
**Options:**
22+
23+
- `--walletId` (optional) — wallet ID, defaults to authenticated wallet
24+
- `--derivationIndex` (optional) — derivation index, default 0
25+
26+
---
27+
28+
### `phantom perps positions` — MCP: `perps_positions`
29+
30+
Get your open perpetual positions including entry price, mark price, unrealized PnL, and margin used.
31+
32+
**Options:**
33+
34+
- `--walletId` (optional)
35+
- `--derivationIndex` (optional)
36+
37+
---
38+
39+
### `phantom perps orders` — MCP: `perps_orders`
40+
41+
Get your open perpetual orders (resting limit orders waiting to be filled).
42+
43+
**Options:**
44+
45+
- `--walletId` (optional)
46+
- `--derivationIndex` (optional)
47+
48+
---
49+
50+
### `phantom perps history` — MCP: `perps_history`
51+
52+
Get your perpetual trade history (filled orders).
53+
54+
**Options:**
55+
56+
- `--walletId` (optional)
57+
- `--derivationIndex` (optional)
58+
59+
---
60+
61+
### `phantom perps open` — MCP: `perps_open`
62+
63+
Open a perpetual position on Hyperliquid. Supports market and limit orders in long or short direction. The position size is specified in USD.
64+
65+
**Options:**
66+
67+
- `--market` — market symbol, e.g. `BTC`, `ETH`, `SOL`
68+
- `--direction``long` or `short`
69+
- `--sizeUsd` — position size in USD (e.g. `100` for $100 notional)
70+
- `--leverage` — leverage multiplier (e.g. `1` for 1x, `10` for 10x)
71+
- `--orderType``market` or `limit`
72+
- `--limitPrice` (required for limit orders) — the limit price
73+
- `--marginType``isolated` (default) or `cross`
74+
- `--reduceOnly` (optional) — if set, can only reduce an existing position
75+
- `--walletId` (optional)
76+
- `--derivationIndex` (optional)
77+
78+
**Notes:**
79+
80+
- Run `phantom perps markets` first to verify the market symbol and current price.
81+
- Market orders apply a 10% slippage buffer automatically.
82+
- Requires USDC in the perps account. Use `phantom perps deposit` then `phantom perps transfer` if needed.
83+
84+
---
85+
86+
### `phantom perps close` — MCP: `perps_close`
87+
88+
Close an open perpetual position. Submits a market order in the opposite direction to fully close the position.
89+
90+
**Options:**
91+
92+
- `--market` — market symbol of the position to close
93+
- `--walletId` (optional)
94+
- `--derivationIndex` (optional)
95+
96+
---
97+
98+
### `phantom perps cancel` — MCP: `perps_cancel`
99+
100+
Cancel an open perpetual order by order ID.
101+
102+
**Options:**
103+
104+
- `--orderId` — the order ID to cancel
105+
- `--market` — market symbol of the order
106+
- `--walletId` (optional)
107+
- `--derivationIndex` (optional)
108+
109+
---
110+
111+
### `phantom perps leverage` — MCP: `perps_leverage`
112+
113+
Update the leverage multiplier for a market without changing any positions.
114+
115+
**Options:**
116+
117+
- `--market` — market symbol
118+
- `--leverage` — new leverage multiplier
119+
- `--marginType``isolated` or `cross`
120+
- `--walletId` (optional)
121+
- `--derivationIndex` (optional)
122+
123+
---
124+
125+
### `phantom perps transfer` — MCP: `perps_transfer`
126+
127+
Move USDC from the Hyperliquid spot account into the perpetuals account. This is an internal Hyperliquid transfer — both accounts live on Hypercore (Hyperliquid's chain).
128+
129+
**Options:**
130+
131+
- `--amountUsdc` — amount of USDC to transfer (e.g. `100`)
132+
- `--walletId` (optional)
133+
- `--derivationIndex` (optional)
134+
135+
**Note:** USDC must already be in your Hyperliquid spot account. Use `phantom perps deposit` to bridge tokens from external chains first.
136+
137+
---
138+
139+
### `phantom perps deposit` — MCP: `perps_deposit`
140+
141+
Bridge tokens from an external chain (Solana, Arbitrum, Base, Ethereum, Polygon) into Hyperliquid as USDC via a cross-chain swap. USDC is delivered to your Hyperliquid spot account. Run `phantom perps transfer` afterwards to move it into the perp account.
142+
143+
**Options:**
144+
145+
- `--sourceChainId` — CAIP-2 source chain ID (e.g. `solana:mainnet`, `eip155:42161` for Arbitrum, `eip155:8453` for Base)
146+
- `--amount` — amount to send in human-readable units (e.g. `100` for 100 USDC)
147+
- `--sellTokenMint` (optional) — token to sell on source chain; defaults to USDC on source chain
148+
- `--sellTokenIsNative` (optional) — set to sell native SOL or ETH
149+
- `--execute` — omit to preview quote only; pass `--execute` to sign and broadcast
150+
151+
---
152+
153+
### `phantom perps withdraw` — MCP: `perps_withdraw`
154+
155+
Bridge USDC from the Hyperliquid perpetuals account to an external chain (Solana, Base, Ethereum, Arbitrum, Polygon) via the Relay bridge.
156+
157+
**Options:**
158+
159+
- `--amountUsdc` — amount of USDC to withdraw (e.g. `50`)
160+
- `--destinationChainId` — CAIP-2 destination chain (e.g. `solana:mainnet`, `eip155:8453` for Base)
161+
- `--buyToken` (optional) — CAIP-19 token to receive; defaults to USDC on destination chain
162+
- `--walletId` (optional)
163+
- `--derivationIndex` (optional)
164+
165+
**Note:** Run `phantom perps account` to check the withdrawable balance before withdrawing.
166+
167+
---
168+
169+
## Common Workflows
170+
171+
### Fund and open a position
172+
173+
```bash
174+
# 1. Bridge USDC from Solana to Hyperliquid spot
175+
phantom perps deposit --sourceChainId solana:mainnet --amount 100 --execute
176+
177+
# 2. Move USDC from Hyperliquid spot into perps account
178+
phantom perps transfer --amountUsdc 100
179+
180+
# 3. Check available markets and current price
181+
phantom perps markets
182+
183+
# 4. Open a long position
184+
phantom perps open --market BTC --direction long --sizeUsd 100 --leverage 5 --orderType market
185+
186+
# 5. Verify the position
187+
phantom perps positions
188+
```
189+
190+
### Close and withdraw
191+
192+
```bash
193+
# 1. Check open positions
194+
phantom perps positions
195+
196+
# 2. Close the position
197+
phantom perps close --market BTC
198+
199+
# 3. Check withdrawable balance
200+
phantom perps account
201+
202+
# 4. Bridge USDC back to Solana
203+
phantom perps withdraw --amountUsdc 100 --destinationChainId solana:mainnet
204+
```
205+
206+
### Place and manage a limit order
207+
208+
```bash
209+
# 1. Place a limit order
210+
phantom perps open --market ETH --direction long --sizeUsd 50 --leverage 3 --orderType limit --limitPrice 3000
211+
212+
# 2. Check the order is on the book
213+
phantom perps orders
214+
215+
# 3. Cancel the order if needed
216+
phantom perps cancel --orderId <orderId> --market ETH
217+
```

0 commit comments

Comments
 (0)