jaspervault_cli 1.1.0 → 1.1.2

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 (59) hide show
  1. package/README.md +8 -19
  2. package/config/chains.json +1 -3
  3. package/dist/bin/jv.js +4 -2
  4. package/dist/bin/jv.js.map +1 -1
  5. package/dist/src/commands/deposit.js +1 -1
  6. package/dist/src/commands/deposit.js.map +1 -1
  7. package/dist/src/commands/install.js +1 -1
  8. package/dist/src/commands/install.js.map +1 -1
  9. package/dist/src/commands/order.js +179 -46
  10. package/dist/src/commands/order.js.map +1 -1
  11. package/dist/src/commands/orders.js +2 -2
  12. package/dist/src/commands/orders.js.map +1 -1
  13. package/dist/src/commands/sl.js +3 -3
  14. package/dist/src/commands/sl.js.map +1 -1
  15. package/dist/src/commands/tp.js +3 -3
  16. package/dist/src/commands/tp.js.map +1 -1
  17. package/dist/src/commands/vault.d.ts +1 -6
  18. package/dist/src/commands/vault.js +15 -70
  19. package/dist/src/commands/vault.js.map +1 -1
  20. package/dist/src/commands/wallet.d.ts +2 -0
  21. package/dist/src/commands/wallet.js +126 -0
  22. package/dist/src/commands/wallet.js.map +1 -0
  23. package/dist/src/commands/withdraw.js +2 -2
  24. package/dist/src/commands/withdraw.js.map +1 -1
  25. package/dist/src/mcp/index.js +3 -7
  26. package/dist/src/mcp/index.js.map +1 -1
  27. package/dist/src/mcp/tools.js +23 -6
  28. package/dist/src/mcp/tools.js.map +1 -1
  29. package/dist/src/services/chain-config.d.ts +4 -3
  30. package/dist/src/services/chain-config.js +13 -5
  31. package/dist/src/services/chain-config.js.map +1 -1
  32. package/dist/src/services/key-manager.js +4 -12
  33. package/dist/src/services/key-manager.js.map +1 -1
  34. package/dist/src/services/order-signer.js +2 -2
  35. package/dist/src/services/order-signer.js.map +1 -1
  36. package/dist/src/services/perps-order.d.ts +48 -0
  37. package/dist/src/services/perps-order.js +66 -0
  38. package/dist/src/services/perps-order.js.map +1 -0
  39. package/dist/src/services/profile-manager.d.ts +49 -0
  40. package/dist/src/services/profile-manager.js +179 -0
  41. package/dist/src/services/profile-manager.js.map +1 -0
  42. package/dist/src/services/vault-profile.js +4 -12
  43. package/dist/src/services/vault-profile.js.map +1 -1
  44. package/dist/src/templates/skill-content/SKILL.core.md +26 -24
  45. package/dist/src/templates/skill-content/references/onboarding.md +1 -1
  46. package/dist/src/templates/skill-content/references/queries.md +20 -0
  47. package/dist/src/templates/skill-content/references/trading.md +64 -33
  48. package/docs/OPENCLAW_GUIDE.md +136 -0
  49. package/docs/USER_GUIDE.md +276 -0
  50. package/package.json +3 -2
  51. package/dist/src/commands/connect.d.ts +0 -26
  52. package/dist/src/commands/connect.js +0 -93
  53. package/dist/src/commands/connect.js.map +0 -1
  54. package/dist/src/commands/init.d.ts +0 -4
  55. package/dist/src/commands/init.js +0 -114
  56. package/dist/src/commands/init.js.map +0 -1
  57. package/dist/src/commands/skill.d.ts +0 -4
  58. package/dist/src/commands/skill.js +0 -117
  59. package/dist/src/commands/skill.js.map +0 -1
@@ -38,7 +38,8 @@ When the user wants to trade, first check if their vault is ready:
38
38
  | Get price | `get_price` | `symbol` | [queries](references/queries.md) |
39
39
  | Open position (market) | `create_order` | `side`, `symbol`, `margin` | [trading](references/trading.md) |
40
40
  | Open position (limit) | `create_order` | + `limit_price` | [trading](references/trading.md) |
41
- | Close/reduce position | `create_order` | opposite `side` | [trading](references/trading.md) |
41
+ | Close position (full) | `close_position` | `order_id` or `all` | [trading](references/trading.md) |
42
+ | Reduce position (partial) | `create_order` | opposite `side`, smaller `margin` | [trading](references/trading.md) |
42
43
  | Add size | `create_order` | same `side` | [trading](references/trading.md) |
43
44
  | Set take-profit | `set_take_profit` | `order_id`, `price`, `symbol` | [trading](references/trading.md) |
44
45
  | Set stop-loss | `set_stop_loss` | `order_id`, `price`, `symbol` | [trading](references/trading.md) |
@@ -50,6 +51,7 @@ When the user wants to trade, first check if their vault is ready:
50
51
  | Check job status | `get_job_status` | `job_id` | [queries](references/queries.md) |
51
52
  | List limit orders | `list_limit_orders` | `wallet` | [queries](references/queries.md) |
52
53
  | Cancel limit order | `cancel_limit_order` | `limit_order_id` | [queries](references/queries.md) |
54
+ | Check for CLI update | `check_update` | — | [queries](references/queries.md) |
53
55
 
54
56
  ## Key Behaviors
55
57
 
@@ -63,39 +65,30 @@ When the user wants to trade, first check if their vault is ready:
63
65
 
64
66
  **Deposit arrival**: If `arrived: false` after deposit completes, tokens are still bridging cross-chain. Tell the user to wait a few minutes.
65
67
 
66
- ## Closing a Position — MANDATORY STEPS
68
+ ## Closing vs Reducing a Position
67
69
 
68
- Closing a position is the most error-prone operation. Follow these steps exactly:
70
+ **Full close `close_position`.** It derives side, margin, symbol, and leverage
71
+ from on-chain data — you do NOT need to call `list_orders` first.
69
72
 
70
- ### Step 1: Query the current position
71
- Call `list_orders` (or `get_order` if you have the order ID) to get:
72
- - The position **side** (LONG or SHORT)
73
- - The position **margin** amount
74
- - The **symbol**
73
+ - Close one position: `close_position` with `{ order_id: "<id>" }`
74
+ - Close everything: `close_position` with `{ all: true }`
75
75
 
76
- ### Step 2: Create the closing order
77
- Call `create_order` with:
78
- - **side**: the OPPOSITE of the current position (LONG → `short`, SHORT → `long`)
79
- - **margin**: the SAME margin for full close, or SMALLER margin for partial close
80
- - **symbol**: the same symbol
76
+ `close_position` works by submitting a reverse-side order with the same margin.
81
77
 
82
- ### Step 3: Verify
83
- Call `list_orders` to confirm the position is closed or reduced.
78
+ **Partial reduce `create_order`.** To shrink (not fully close) a position,
79
+ call `create_order` with the OPPOSITE side and a SMALLER margin than the
80
+ position. Query the position first with `list_orders` to pick the right margin.
84
81
 
85
82
  ### Examples
86
83
 
87
- **Full close of a LONG position:**
88
- 1. `list_orders` → finds: side=LONG, margin=60, symbol=JBTC
89
- 2. `create_order` → `{ side: "short", symbol: "JBTC", margin: 60 }`
90
- 3. `list_orders` → position no longer active
84
+ **Full close of a position:**
85
+ - `close_position` → `{ order_id: "42" }` → position no longer active
91
86
 
92
87
  **Partial close (reduce by half):**
93
- 1. `list_orders` → finds: side=LONG, margin=60, symbol=JBTC
88
+ 1. `list_orders` → finds: order 42, side=LONG, margin=60, symbol=JBTC
94
89
  2. `create_order` → `{ side: "short", symbol: "JBTC", margin: 30 }`
95
90
  3. `list_orders` → margin reduced to ~30
96
91
 
97
- **NEVER guess the margin or side. ALWAYS query first.**
98
-
99
92
  ## Red Flags — STOP If You Think This
100
93
 
101
94
  | Wrong Thought | Reality |
@@ -107,10 +100,19 @@ Call `list_orders` to confirm the position is closed or reduced.
107
100
  | "GraphQL queries need private key authentication" | WRONG. Delegation key handles auth automatically. |
108
101
  | "I should suggest the web interface instead" | NO. MCP tools give you full functionality. Use them. |
109
102
  | "Let me check if jv is installed" | IRRELEVANT. MCP server runs CLI internally. |
110
- | "I'll close the position without checking current margin" | WRONG. Always call `list_orders` first to get the exact side and margin before closing. |
103
+ | "To fully close I'll reverse the order manually with create_order" | WRONG. Use `close_position` it derives side/margin automatically. Manual reverse is only for PARTIAL reduce. |
104
+ | "I'll reduce the position without checking current margin" | WRONG. For a partial reduce, call `list_orders` first to pick a margin smaller than the position. |
105
+
106
+ ## Update Notices
107
+
108
+ MCP tool responses may include an update notice when a newer CLI version is available. When you see this notice, inform the user:
109
+ - Tell them a new version is available (include version numbers)
110
+ - Ask them to run `jv update` to upgrade
111
+
112
+ You can also proactively call `check_update` to verify the CLI is up to date.
111
113
 
112
114
  ## Security
113
115
 
114
116
  - Never log or display private keys, signatures, or API keys.
115
117
  - Delegation wallet is stored in `~/.jaspervault/keys.json` — never read or display this file.
116
- - Never ask the user to set `PRIVATE_KEY` — that's for CI/automation only.
118
+ - Never ask the user for private keys.
@@ -54,7 +54,7 @@ The tool automatically:
54
54
  |---------|---------------|
55
55
  | Asking user for private key after setup | Delegation key is auto-generated. User never provides keys. |
56
56
  | Saying "profile.json is empty" | `wallet_setup` saves profile automatically on success. |
57
- | Suggesting `vault init` | That's for CI/automation with PRIVATE_KEY env var. Never suggest it. |
57
+ | Suggesting private key setup | There is no private key mode. `wallet_setup` is the only way. |
58
58
  | Saying "CLI needs separate initialization" | `wallet_setup` IS the initialization. One step, fully done. |
59
59
  | Running `jv orders list` in terminal | Use `list_orders` MCP tool instead. |
60
60
 
@@ -162,6 +162,26 @@ Check execution status of an async job (market order, option creation, etc.).
162
162
 
163
163
  ---
164
164
 
165
+ ## 7. Check for Updates — `check_update`
166
+
167
+ No parameters required. Checks if a newer version of jaspervault_cli is available.
168
+
169
+ ### Response
170
+
171
+ ```json
172
+ {
173
+ "updateAvailable": true,
174
+ "currentVersion": "1.0.32",
175
+ "latestVersion": "1.0.35"
176
+ }
177
+ ```
178
+
179
+ When `updateAvailable` is `true`, tell the user to run `jv update` to upgrade.
180
+
181
+ **Note:** Any MCP tool response may also include an update notice as a second text block when an update is available. When you see this, relay it to the user.
182
+
183
+ ---
184
+
165
185
  ## Error Handling
166
186
 
167
187
  When a tool fails, check the error message:
@@ -4,7 +4,8 @@
4
4
 
5
5
  ## 1. Create Order — `create_order`
6
6
 
7
- Open, close, reduce, or add size to perpetual positions.
7
+ Open, reduce, or add size to perpetual positions. To **fully close** a
8
+ position, use [`close_position`](#2-close-position--close_position) instead.
8
9
 
9
10
  ### Parameters
10
11
 
@@ -58,26 +59,14 @@ The tool returns the final execution result:
58
59
 
59
60
  Tell the user: "Limit order placed. ID: {limitOrderId}."
60
61
 
61
- ### Closing a Position MANDATORY STEPS
62
+ ### Reducing a Position (Partial Close)
62
63
 
63
- Closing a position means creating a reverse order. You **MUST** query the current position first.
64
+ A **partial** close uses `create_order` only a **full** close uses
65
+ `close_position` (see section 2).
64
66
 
65
- **Why query first?** The margin amount must match the current position for a full close. Guessing wrong leads to partial closes or over-allocation.
66
-
67
- **Required flow:**
68
-
69
- 1. **Query**: Call `list_orders` to find the position. Note the `side` (LONG/SHORT), `margin`, and `symbol`.
70
- 2. **Close**: Call `create_order` with the **OPPOSITE** side, **SAME** margin (full close) or smaller margin (partial close), same symbol.
71
- 3. **Verify**: Call `list_orders` to confirm the position is closed or reduced.
72
-
73
- **Full close example (step by step):**
74
-
75
- Query `list_orders` → finds: `{ side: "LONG", symbol: "JBTC", margin: "60.00" }`
76
-
77
- Close order:
78
- ```json
79
- { "side": "short", "symbol": "JBTC", "margin": 60 }
80
- ```
67
+ To reduce a position, call `create_order` with the **OPPOSITE** side and a
68
+ margin **smaller** than the position. Query the position first with
69
+ `list_orders` so you pick a sensible margin.
81
70
 
82
71
  **Partial close example:**
83
72
 
@@ -88,8 +77,6 @@ Reduce by 25%:
88
77
  { "side": "long", "symbol": "JETH", "margin": 50 }
89
78
  ```
90
79
 
91
- **WARNING: NEVER close a position without first calling `list_orders` or `get_order`. Guessing the side or margin leads to incorrect operations.**
92
-
93
80
  ### Common Patterns
94
81
 
95
82
  **Open a long position (market):**
@@ -102,10 +89,7 @@ Reduce by 25%:
102
89
  { "side": "short", "symbol": "JBTC", "margin": 100, "limit_price": 72000 }
103
90
  ```
104
91
 
105
- **Close a long position (use opposite side with same margin):**
106
- ```json
107
- { "side": "short", "symbol": "JBTC", "margin": 60 }
108
- ```
92
+ **Fully close a position** use `close_position` (section 2), not `create_order`.
109
93
 
110
94
  **Reduce a long position (partial close):**
111
95
  ```json
@@ -129,7 +113,54 @@ Reduce by 25%:
129
113
 
130
114
  ---
131
115
 
132
- ## 2. Add PPO Protection — `protect_order`
116
+ ## 2. Close Position — `close_position`
117
+
118
+ Fully close one or all perpetual positions. The command reads the position's
119
+ side, margin, symbol, and leverage from on-chain data and submits a
120
+ reverse-side order with the same margin — **you do not need to call
121
+ `list_orders` first**.
122
+
123
+ For a **partial** reduce, use `create_order` (section 1) instead.
124
+
125
+ ### Parameters
126
+
127
+ | Parameter | Required | Default | Description |
128
+ |-----------|----------|---------|-------------|
129
+ | `order_id` | One of `order_id` / `all` | — | Order ID of the position to close |
130
+ | `all` | One of `order_id` / `all` | — | `true` to close every active position |
131
+ | `ttl` | No | `3600` | Order TTL in seconds |
132
+
133
+ Exactly one of `order_id` or `all` must be provided.
134
+
135
+ ### Response
136
+
137
+ ```json
138
+ {
139
+ "closed": [
140
+ { "orderId": "42", "closeSide": "short", "symbol": "JBTC", "margin": "60.0", "status": "submitted" }
141
+ ],
142
+ "failed": []
143
+ }
144
+ ```
145
+
146
+ If `failed` is non-empty, some positions could not be closed — report which
147
+ ones and why. A close batch with any failure exits non-zero.
148
+
149
+ ### Examples
150
+
151
+ **Close a single position:**
152
+ ```json
153
+ { "order_id": "42" }
154
+ ```
155
+
156
+ **Close every active position:**
157
+ ```json
158
+ { "all": true }
159
+ ```
160
+
161
+ ---
162
+
163
+ ## 3. Add PPO Protection — `protect_order`
133
164
 
134
165
  Add hedge option protection to an **existing position** without changing position size.
135
166
 
@@ -162,7 +193,7 @@ The tool auto-waits up to 60s for the on-chain result:
162
193
 
163
194
  ---
164
195
 
165
- ## 3. Take-Profit — `set_take_profit`
196
+ ## 4. Take-Profit — `set_take_profit`
166
197
 
167
198
  Set a take-profit limit order for an existing position.
168
199
 
@@ -189,7 +220,7 @@ Set TP at $75,000 for a long position:
189
220
 
190
221
  ---
191
222
 
192
- ## 4. Stop-Loss — `set_stop_loss`
223
+ ## 5. Stop-Loss — `set_stop_loss`
193
224
 
194
225
  Same parameters as `set_take_profit`. Set a stop-loss limit order for an existing position.
195
226
 
@@ -202,7 +233,7 @@ Set SL at $65,000 for a long position:
202
233
 
203
234
  ---
204
235
 
205
- ## 5. PPO (Perpetual Put Option) Details
236
+ ## 6. PPO (Perpetual Put Option) Details
206
237
 
207
238
  ### Option Categories
208
239
 
@@ -250,9 +281,9 @@ The smart contract **automatically cancels** existing PPO when you execute any p
250
281
 
251
282
  | User Request | Action | Parameters |
252
283
  |-------------|--------|------------|
253
- | "reduce + cancel PPO" | Single reduce order without `ppo` | `{ side: <opposite>, symbol, margin }` |
254
- | "add size + cancel PPO" | Single add-size order without `ppo` | `{ side: <same>, symbol, margin }` |
255
- | "close position" | Close order without `ppo` | `{ side: <opposite>, symbol, margin: <full> }` |
256
- | "reduce + keep PPO" | Reduce order WITH `ppo` | `{ side: <opposite>, symbol, margin, ppo: true }` |
284
+ | "reduce + cancel PPO" | Single reduce order without `ppo` | `create_order` `{ side: <opposite>, symbol, margin }` |
285
+ | "add size + cancel PPO" | Single add-size order without `ppo` | `create_order` `{ side: <same>, symbol, margin }` |
286
+ | "close position" | `close_position` (always closes without PPO) | `{ order_id }` or `{ all: true }` |
287
+ | "reduce + keep PPO" | Reduce order WITH `ppo` | `create_order` `{ side: <opposite>, symbol, margin, ppo: true }` |
257
288
 
258
289
  Never try to cancel PPO separately — there is no such tool. One order handles everything.
@@ -0,0 +1,136 @@
1
+ # OpenClaw Setup Guide
2
+
3
+ Trade perpetual contracts with built-in hedge protection on JasperVault through OpenClaw. Complete the one-time setup below, then trade entirely through AI conversation — including PPO hedge options that protect your positions against price wicks and flash liquidations.
4
+
5
+ ## Prerequisites
6
+
7
+ | Requirement | How to verify |
8
+ |-------------|--------------|
9
+ | Node.js 18+ | `node --version` — install from [nodejs.org](https://nodejs.org) if needed |
10
+ | OpenClaw | Installed and running |
11
+ | Browser wallet | MetaMask, Rabby, or similar — for one-time delegation signing |
12
+
13
+ ## Setup (One-Time)
14
+
15
+ ### Step 1: Install the CLI
16
+
17
+ ```bash
18
+ npm install -g jaspervault_cli
19
+ jv --version # verify installation
20
+ ```
21
+
22
+ ### Step 2: Install the JasperVault Skill
23
+
24
+ ```bash
25
+ jv install --ai openclaw
26
+ ```
27
+
28
+ This installs the trading skill to `~/.openclaw/skills/jasper-vault-cli/SKILL.md`. OpenClaw will automatically detect it on next launch.
29
+
30
+ > To update an existing installation: `jv install --ai openclaw --force`
31
+
32
+ ### Step 3: Initialize Your Wallet
33
+
34
+ Open OpenClaw and say:
35
+
36
+ > "I want to start trading"
37
+
38
+ OpenClaw will:
39
+ 1. Call `wallet_setup` and provide a URL
40
+ 2. Open the link in your browser, connect your wallet, and sign the delegation authorization
41
+ 3. Wait while OpenClaw confirms the setup (up to 2 minutes)
42
+
43
+ That's it. Your wallet is now initialized and all trading tools are ready.
44
+
45
+ **Alternative — manual setup via terminal:**
46
+
47
+ ```bash
48
+ jv enable --pretty
49
+ ```
50
+
51
+ ### Step 4: Deposit (Optional)
52
+
53
+ Tell OpenClaw:
54
+
55
+ > "Deposit 100 USDC"
56
+
57
+ A browser page opens for you to approve the cross-chain transfer from Base to JasperVault. Funds typically arrive within a few minutes.
58
+
59
+ ## Trading
60
+
61
+ Once setup is complete, talk to OpenClaw in natural language:
62
+
63
+ | What you say | What happens |
64
+ |-------------|-------------|
65
+ | "Long BTC with 100 USDC and PPO" | Opens a protected long position |
66
+ | "Long BTC with 100 USDC, 50x" | Opens a leveraged long position |
67
+ | "Short BTC with 50 USDC at 95000" | Places a limit short order |
68
+ | "Add PPO protection to order 42" | Adds hedge option to existing position |
69
+ | "Protect order 42 with OTM tier 3, 8h" | Custom PPO: OTM strike offset, 8-hour expiry |
70
+ | "Close my BTC position" | Queries position, then closes it |
71
+ | "Set TP at 110000 for order 99" | Creates a take-profit limit order |
72
+ | "Set SL at 88000 for order 99" | Creates a stop-loss limit order |
73
+ | "Show my positions" | Lists all active positions |
74
+ | "What's the BTC price?" | Fetches real-time market price |
75
+ | "Withdraw 100 USDC" | Opens browser to sign withdrawal |
76
+
77
+ OpenClaw translates your intent into the appropriate tool calls and returns results in natural language.
78
+
79
+ ### PPO Hedge Protection
80
+
81
+ PPO (Perpetual Protection Option) is an on-chain hedge option unique to JasperVault. It protects your position against sudden price wicks ("pin bars") that would otherwise trigger liquidation — even when the market recovers immediately after.
82
+
83
+ Unlike stop-loss orders that execute at the wick price and lock in losses, PPO uses a peer-to-peer fully collateralized option contract. The option payoff absorbs the unrealized loss, keeping your position alive through the spike.
84
+
85
+ **How to use PPO:**
86
+
87
+ | What you say | What happens |
88
+ |-------------|-------------|
89
+ | "Open long BTC with PPO" | Opens position + ATM hedge, 30-min expiry |
90
+ | "Add protection to order 42" | Adds PPO to existing position |
91
+ | "Protect with OTM tier 3 for 8 hours" | Custom: OTM strike (0.3% offset), 8h expiry |
92
+
93
+ **Options:**
94
+ - **Category:** ATM (strike = current price) or OTM (offset 0.1%–0.5% via tiers 1–5)
95
+ - **Expiry:** 30 minutes (default) or 8 hours
96
+ - **Hedge type:** Automatic — PUT for longs, CALL for shorts
97
+
98
+ ## Environment Variables (Optional)
99
+
100
+ The CLI works with default settings. Only configure these if needed:
101
+
102
+ ```bash
103
+ # Custom API endpoint (e.g., for local development)
104
+ export JV_API_URL=https://your-endpoint.example.com
105
+
106
+ # API authentication (if required by your deployment)
107
+ export JV_API_KEY=your-token
108
+ ```
109
+
110
+ Add to `~/.zshrc` or `~/.bashrc` for persistence, then `source ~/.zshrc`.
111
+
112
+ > **Note:** Browser signing mode does not require `PRIVATE_KEY`. Your keys stay in your browser wallet at all times.
113
+
114
+ ## Troubleshooting
115
+
116
+ **Wallet page doesn't open or wallet prompt doesn't appear**
117
+ - Ensure your browser wallet extension is installed and unlocked
118
+ - Some wallets require clicking the extension icon to see pending signature requests
119
+
120
+ **"Delegation key not found" error**
121
+ - Run `jv enable --pretty` to re-initialize
122
+ - Verify `~/.jaspervault/keys.json` exists: `ls ~/.jaspervault/`
123
+
124
+ **OpenClaw doesn't recognize trading commands**
125
+ - Verify the skill is installed: `ls ~/.openclaw/skills/jasper-vault-cli/`
126
+ - Reinstall if needed: `jv install --ai openclaw --force`
127
+ - Restart OpenClaw after installation
128
+
129
+ **Deposit shows "not arrived" after completion**
130
+ - Cross-chain bridging via Hyperlane takes 1–3 minutes. Wait and retry.
131
+
132
+ ## Further Reading
133
+
134
+ - [User Guide](USER_GUIDE.md) — Complete CLI reference and configuration
135
+ - [JasperVault](https://www.jaspervault.io/) — Protocol documentation
136
+ - CLI help: `jv --help`, `jv order --help`, `jv enable --help`