@continuumdao/ctm-mpc-defi 0.2.8 → 0.2.9

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,177 @@
1
+ ---
2
+ name: hyperliquid
3
+ description: Hyperliquid perps, vaults, and HYPE staking via HyperEVM CoreWriter — Continuum MPC multi-sign.
4
+ ---
5
+
6
+ # Hyperliquid (MCP)
7
+
8
+ Hyperliquid is a perpetuals and spot exchange with on-chain actions routed through **HyperEVM CoreWriter** (`0x3333…3333`). Continuum MPC sends **single-tx CoreWriter batches** from the KeyGen executor on HyperEVM.
9
+
10
+ Supported chains (must be in node chain registry with `rpcGateway`):
11
+
12
+ | chainId | Network |
13
+ |--------:|---------|
14
+ | **999** | HyperEVM mainnet |
15
+ | **998** | Hyperliquid testnet |
16
+
17
+ The MPC **executor address** (`keyGen.ethereumaddress`) is the Hyperliquid **user account** for balances, positions, and orders.
18
+
19
+ ## What Hyperliquid does (explain to users)
20
+
21
+ - **Perps:** USD-margined perpetuals (BTC, ETH, …) plus optional **HIP-3** builder dexes.
22
+ - **Spot ↔ Perp:** USDC is one asset split between **spot** and **perp margin** ledgers (not separate ERC20s). Move with `usdClassTransfer`.
23
+ - **Vaults:** Deposit/withdraw USD into protocol vaults (withdraw includes accrued PnL).
24
+ - **Staking:** Stake/unstake **HYPE** and delegate to validators.
25
+
26
+ Trading reads use Hyperliquid **REST `/info`**. Writes use **CoreWriter** on HyperEVM (not the signed `/exchange` API).
27
+
28
+ ## Getting started (funding)
29
+
30
+ Before first trade, the user typically needs:
31
+
32
+ 1. **USDC on Hyperliquid** — deposit via the official Hyperliquid bridge (commonly from **Arbitrum** USDC). Funds appear in the spot/perp account tied to the MPC address.
33
+ 2. **Perp margin** — for perp orders, USDC must be in the **perp** bucket. Use `ctm_hyperliquid_fetch_usd_class_balances` then `ctm_hyperliquid_build_usd_transfer_multisign` with `toPerp: true` if spot USDC is high but perp withdrawable is low.
34
+ 3. **HYPE on HyperEVM for gas** — CoreWriter txs on chain **999** / **998** require **native HYPE** on the executor for gas. Ensure the KeyGen wallet holds enough HYPE on HyperEVM (bridge/deposit separately from USDC trading balance).
35
+ 4. **Leverage** — Hyperliquid stores a per-market leverage setting. Check `ctm_hyperliquid_fetch_open_context` (`leverageLabel`, `availableToBuy` / `availableToSell`). Changing leverage on-exchange is **not** exposed in v1 MCP (user adjusts on Hyperliquid UI if needed).
36
+
37
+ Positions and orders from MCP reflect **live HyperCore state** after prior txs are **broadcast** — pending multi-sign requests are not visible until executed.
38
+
39
+ ## Typical agent flow (open perp)
40
+
41
+ 1. `load_defi_protocol({ protocolId: "hyperliquid" })`
42
+ 2. `get_defi_protocol_skill` — this file (+ shared gas/submit section appended)
43
+ 3. Confirm chain **999** or **998** in `get_chain_registry` with RPC
44
+ 4. `ctm_hyperliquid_fetch_markets({ chainId: 999 })` — pick `coin` (e.g. `BTC`); note `maxLeverage`
45
+ 5. `ctm_hyperliquid_fetch_market_snapshot({ chainId, coin, interval: "15m" })` — mid + candles
46
+ 6. `ctm_hyperliquid_fetch_open_context({ chainId, executorAddress, coin })` — account, leverage, max size
47
+ 7. `ctm_hyperliquid_fetch_usd_class_balances({ chainId, executorAddress })` — spot vs perp USD if needed
48
+ 8. `get_multi_sign_gas_options({ chainId })` — confirm `useCustomGas` with user
49
+ 9. `ctm_hyperliquid_build_limit_order_multisign` → **`{ requestId }`**
50
+ 10. Base MPC lifecycle (shared gas/submit section below)
51
+
52
+ ## Tool selection
53
+
54
+ ### Read-only
55
+
56
+ | User intent | MCP tool |
57
+ |-------------|----------|
58
+ | List perp markets + HIP-3 dexes | `ctm_hyperliquid_fetch_markets` |
59
+ | Mid price + OHLCV | `ctm_hyperliquid_fetch_market_snapshot` |
60
+ | Account + capacity for one coin | `ctm_hyperliquid_fetch_open_context` |
61
+ | Open positions | `ctm_hyperliquid_fetch_positions` |
62
+ | Open orders | `ctm_hyperliquid_fetch_open_orders` |
63
+ | Spot vs perp USDC | `ctm_hyperliquid_fetch_usd_class_balances` |
64
+ | Vault catalog (+ APR) | `ctm_hyperliquid_fetch_vaults` |
65
+ | User vault equity | `ctm_hyperliquid_fetch_user_vault_equities` |
66
+ | HYPE stake summary | `ctm_hyperliquid_fetch_staking_summary` |
67
+ | Validator delegations | `ctm_hyperliquid_fetch_delegations` |
68
+
69
+ ### Multi-sign (writes)
70
+
71
+ | User intent | MCP tool |
72
+ |-------------|----------|
73
+ | Open / add limit or IoC order | `ctm_hyperliquid_build_limit_order_multisign` |
74
+ | Close / reduce position | `ctm_hyperliquid_build_close_multisign` |
75
+ | Cancel open order | `ctm_hyperliquid_build_cancel_multisign` |
76
+ | Move USDC spot ↔ perp | `ctm_hyperliquid_build_usd_transfer_multisign` |
77
+ | Vault deposit | `ctm_hyperliquid_build_vault_deposit_multisign` |
78
+ | Vault withdraw | `ctm_hyperliquid_build_vault_withdraw_multisign` |
79
+ | Stake HYPE | `ctm_hyperliquid_build_stake_multisign` |
80
+ | Unstake HYPE | `ctm_hyperliquid_build_unstake_multisign` |
81
+ | Delegate to validator | `ctm_hyperliquid_build_delegate_multisign` |
82
+ | Undelegate | `ctm_hyperliquid_build_undelegate_multisign` |
83
+
84
+ ## Common multisign inputs (all `build_*` tools)
85
+
86
+ | Field | Required | Notes |
87
+ |-------|----------|-------|
88
+ | `keyGen` | yes | `{ pubkeyhex, keylist?, ClientKeys? }` |
89
+ | `chainId` | yes | **999** or **998** |
90
+ | `rpcUrl` | yes | HyperEVM RPC from chain registry |
91
+ | `executorAddress` | yes | MPC `ethereumaddress` |
92
+ | `chainDetail` | yes | Gas config row from registry |
93
+ | `purposeText` | yes | Human-readable sign request purpose |
94
+ | `useCustomGas` | yes | See gas section below |
95
+ | `customGasChainDetails` | no | Snapshot when `useCustomGas: true` |
96
+
97
+ ## Limit order example
98
+
99
+ ```json
100
+ {
101
+ "keyGen": { "pubkeyhex": "…", "keylist": ["…"] },
102
+ "chainId": 999,
103
+ "rpcUrl": "https://…",
104
+ "executorAddress": "0x…",
105
+ "chainDetail": {},
106
+ "purposeText": "Hyperliquid: long BTC 0.01 @ 95000",
107
+ "useCustomGas": false,
108
+ "coin": "BTC",
109
+ "isBuy": true,
110
+ "limitPxHuman": "95000",
111
+ "szHuman": "0.01",
112
+ "tif": "gtc"
113
+ }
114
+ ```
115
+
116
+ - `tif`: `gtc` (default), `ioc`, or `alo`
117
+ - `marketKind`: optional `perp` (default) or `spot`
118
+ - `dex`: optional HIP-3 dex name; coin may be prefixed e.g. `xyz:SYMBOL`
119
+
120
+ Validate `szHuman` against `availableToBuy` / `availableToSell` from `fetch_open_context`.
121
+
122
+ ## Close position example
123
+
124
+ Use `isLong: true` for a **long** position (submits sell reduce-only IoC):
125
+
126
+ ```json
127
+ {
128
+ "coin": "BTC",
129
+ "isLong": true,
130
+ "limitPxHuman": "94000",
131
+ "szHuman": "0.01",
132
+ "tif": "ioc"
133
+ }
134
+ ```
135
+
136
+ ## Cancel example
137
+
138
+ ```json
139
+ {
140
+ "coin": "BTC",
141
+ "oid": 123456789
142
+ }
143
+ ```
144
+
145
+ `oid` from `ctm_hyperliquid_fetch_open_orders`.
146
+
147
+ ## Spot ↔ Perp USD transfer
148
+
149
+ ```json
150
+ {
151
+ "usdHuman": "100",
152
+ "toPerp": true
153
+ }
154
+ ```
155
+
156
+ Check balances first with `ctm_hyperliquid_fetch_usd_class_balances`.
157
+
158
+ ## Vault / stake
159
+
160
+ - **Vault deposit/withdraw:** `vaultAddress` from `fetch_vaults`; `usdHuman` amount. Mainnet vault catalog fetch can take ~10–15s (large stats feed). Testnet catalog is empty.
161
+ - **Stake/unstake:** `hypeHuman` amount in HYPE units.
162
+ - **Delegate/undelegate:** `validator` address + `hypeHuman`.
163
+
164
+ ## HIP-3 dexes
165
+
166
+ `fetch_markets` returns `dexes[]`. Pass `dex` on reads and on limit/cancel/close when trading builder-deployed perps. Coin names may include a dex prefix.
167
+
168
+ ## Troubleshooting
169
+
170
+ | Symptom | Likely cause |
171
+ |---------|----------------|
172
+ | `availableToBuy` / `availableToSell` is 0 | No perp margin, leverage too high, or USDC still in spot — transfer to perp |
173
+ | Order succeeds on-chain but no position | Limit not filled yet; IoC may partially/fully reject |
174
+ | Position missing after multi-sign | Request not yet broadcast; or wrong dex filter |
175
+ | Vault list empty on 998 | Expected — catalog is mainnet-only |
176
+ | CoreWriter tx fails on broadcast | Insufficient **HYPE** on HyperEVM for gas |
177
+ | Size rejected | Exceeds `availableToBuy`/`availableToSell` at current leverage |