oneie 5.7.6 → 5.8.1

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 (245) hide show
  1. package/README.md +19 -1
  2. package/dist/package.json +7 -8
  3. package/dist/src/age-yefbe8pe.js +1 -0
  4. package/dist/src/evm-tx-ee2q0e3w.js +1 -0
  5. package/dist/src/hl-run-tgrkrk69.js +1 -0
  6. package/dist/src/index-0rj9wdk9.js +4 -0
  7. package/dist/src/index-91y484c2.js +2052 -0
  8. package/dist/src/index-940y3rnv.js +12 -0
  9. package/dist/src/index.js +1047 -121
  10. package/dist/src/message-key-db1xjdkw.js +1 -0
  11. package/dist/src/message-lock-5vr8079x.js +5 -0
  12. package/dist/src/sweep-order-c2p6rk8c.js +1 -0
  13. package/dist/src/sweep-runner-t68xe7vx.js +1 -0
  14. package/package.json +7 -8
  15. package/dist/src/agent.d.ts +0 -75
  16. package/dist/src/agent.js +0 -1334
  17. package/dist/src/agentverse.d.ts +0 -26
  18. package/dist/src/agentverse.js +0 -171
  19. package/dist/src/args.d.ts +0 -9
  20. package/dist/src/args.js +0 -61
  21. package/dist/src/auth.d.ts +0 -6
  22. package/dist/src/auth.js +0 -121
  23. package/dist/src/balances.d.ts +0 -89
  24. package/dist/src/balances.js +0 -202
  25. package/dist/src/banner.d.ts +0 -1
  26. package/dist/src/banner.js +0 -17
  27. package/dist/src/broadcast.d.ts +0 -8
  28. package/dist/src/broadcast.js +0 -175
  29. package/dist/src/catalog.d.ts +0 -12
  30. package/dist/src/catalog.js +0 -76
  31. package/dist/src/chat.d.ts +0 -2
  32. package/dist/src/chat.js +0 -92
  33. package/dist/src/client.d.ts +0 -5
  34. package/dist/src/client.js +0 -157
  35. package/dist/src/compiler.d.ts +0 -36
  36. package/dist/src/compiler.js +0 -366
  37. package/dist/src/config.d.ts +0 -24
  38. package/dist/src/config.js +0 -70
  39. package/dist/src/connect.d.ts +0 -2
  40. package/dist/src/connect.js +0 -64
  41. package/dist/src/coordinate.d.ts +0 -3
  42. package/dist/src/coordinate.js +0 -58
  43. package/dist/src/create.d.ts +0 -2
  44. package/dist/src/create.js +0 -113
  45. package/dist/src/deploy.d.ts +0 -2
  46. package/dist/src/deploy.js +0 -19
  47. package/dist/src/dev.d.ts +0 -2
  48. package/dist/src/dev.js +0 -75
  49. package/dist/src/device-flow.d.ts +0 -57
  50. package/dist/src/device-flow.js +0 -173
  51. package/dist/src/doctor.d.ts +0 -26
  52. package/dist/src/doctor.js +0 -146
  53. package/dist/src/draw.d.ts +0 -18
  54. package/dist/src/draw.js +0 -156
  55. package/dist/src/endpoint.d.ts +0 -2
  56. package/dist/src/endpoint.js +0 -250
  57. package/dist/src/env.d.ts +0 -3
  58. package/dist/src/env.js +0 -37
  59. package/dist/src/eval.d.ts +0 -2
  60. package/dist/src/eval.js +0 -43
  61. package/dist/src/fn.d.ts +0 -2
  62. package/dist/src/fn.js +0 -70
  63. package/dist/src/group.d.ts +0 -2
  64. package/dist/src/group.js +0 -117
  65. package/dist/src/hl-run.d.ts +0 -119
  66. package/dist/src/hl-run.js +0 -480
  67. package/dist/src/hl.d.ts +0 -17
  68. package/dist/src/hl.js +0 -148
  69. package/dist/src/index.d.ts +0 -2
  70. package/dist/src/init.d.ts +0 -76
  71. package/dist/src/init.js +0 -278
  72. package/dist/src/join.d.ts +0 -11
  73. package/dist/src/join.js +0 -293
  74. package/dist/src/key-publish.d.ts +0 -40
  75. package/dist/src/key-publish.js +0 -232
  76. package/dist/src/key-seal.d.ts +0 -21
  77. package/dist/src/key-seal.js +0 -142
  78. package/dist/src/key-sweep.d.ts +0 -93
  79. package/dist/src/key-sweep.js +0 -263
  80. package/dist/src/key.d.ts +0 -26
  81. package/dist/src/key.js +0 -338
  82. package/dist/src/lib/age-plugin.d.ts +0 -51
  83. package/dist/src/lib/age-plugin.js +0 -130
  84. package/dist/src/lib/agent-env.d.ts +0 -12
  85. package/dist/src/lib/agent-env.js +0 -48
  86. package/dist/src/lib/api-path.d.ts +0 -2
  87. package/dist/src/lib/api-path.js +0 -40
  88. package/dist/src/lib/asker.d.ts +0 -34
  89. package/dist/src/lib/asker.js +0 -126
  90. package/dist/src/lib/client.d.ts +0 -20
  91. package/dist/src/lib/client.js +0 -71
  92. package/dist/src/lib/env-sealed.d.ts +0 -53
  93. package/dist/src/lib/env-sealed.js +0 -184
  94. package/dist/src/lib/flow-tag.d.ts +0 -86
  95. package/dist/src/lib/flow-tag.js +0 -230
  96. package/dist/src/lib/hl-core/actions.d.ts +0 -99
  97. package/dist/src/lib/hl-core/actions.js +0 -69
  98. package/dist/src/lib/hl-core/eip712.d.ts +0 -33
  99. package/dist/src/lib/hl-core/eip712.js +0 -107
  100. package/dist/src/lib/hl-core/errors.d.ts +0 -10
  101. package/dist/src/lib/hl-core/errors.js +0 -15
  102. package/dist/src/lib/hl-core/exchange.d.ts +0 -24
  103. package/dist/src/lib/hl-core/exchange.js +0 -47
  104. package/dist/src/lib/hl-core/index.d.ts +0 -13
  105. package/dist/src/lib/hl-core/index.js +0 -14
  106. package/dist/src/lib/hl-core/meta.d.ts +0 -57
  107. package/dist/src/lib/hl-core/meta.js +0 -110
  108. package/dist/src/lib/hl-core/msgpack.d.ts +0 -18
  109. package/dist/src/lib/hl-core/msgpack.js +0 -136
  110. package/dist/src/lib/hl-core/net.d.ts +0 -2
  111. package/dist/src/lib/hl-core/net.js +0 -7
  112. package/dist/src/lib/hl-core/signing.d.ts +0 -103
  113. package/dist/src/lib/hl-core/signing.js +0 -295
  114. package/dist/src/lib/hl-core/wire.d.ts +0 -34
  115. package/dist/src/lib/hl-core/wire.js +0 -81
  116. package/dist/src/lib/invoked-as.d.ts +0 -2
  117. package/dist/src/lib/invoked-as.js +0 -24
  118. package/dist/src/lib/journey-words.d.ts +0 -84
  119. package/dist/src/lib/journey-words.js +0 -360
  120. package/dist/src/lib/journey.d.ts +0 -148
  121. package/dist/src/lib/journey.js +0 -245
  122. package/dist/src/lib/key-receipt.d.ts +0 -48
  123. package/dist/src/lib/key-receipt.js +0 -116
  124. package/dist/src/lib/key-source.d.ts +0 -9
  125. package/dist/src/lib/key-source.js +0 -33
  126. package/dist/src/lib/keyfile.d.ts +0 -136
  127. package/dist/src/lib/keyfile.js +0 -397
  128. package/dist/src/lib/launch-claude.d.ts +0 -5
  129. package/dist/src/lib/launch-claude.js +0 -45
  130. package/dist/src/lib/lock-lookup.d.ts +0 -40
  131. package/dist/src/lib/lock-lookup.js +0 -92
  132. package/dist/src/lib/message-seal.d.ts +0 -63
  133. package/dist/src/lib/message-seal.js +0 -150
  134. package/dist/src/lib/network.d.ts +0 -15
  135. package/dist/src/lib/network.js +0 -41
  136. package/dist/src/lib/paths.d.ts +0 -41
  137. package/dist/src/lib/paths.js +0 -91
  138. package/dist/src/lib/plan-draw.d.ts +0 -56
  139. package/dist/src/lib/plan-draw.js +0 -219
  140. package/dist/src/lib/plan-live.d.ts +0 -20
  141. package/dist/src/lib/plan-live.js +0 -192
  142. package/dist/src/lib/qr.d.ts +0 -21
  143. package/dist/src/lib/qr.js +0 -402
  144. package/dist/src/lib/roster.d.ts +0 -20
  145. package/dist/src/lib/roster.js +0 -79
  146. package/dist/src/lib/sale-card.d.ts +0 -117
  147. package/dist/src/lib/sale-card.js +0 -261
  148. package/dist/src/lib/shop-init.d.ts +0 -62
  149. package/dist/src/lib/shop-init.js +0 -63
  150. package/dist/src/lib/sui-grpc-send.d.ts +0 -50
  151. package/dist/src/lib/sui-grpc-send.js +0 -89
  152. package/dist/src/lib/swap-core.d.ts +0 -163
  153. package/dist/src/lib/swap-core.js +0 -405
  154. package/dist/src/lib/tasks-digest.d.ts +0 -66
  155. package/dist/src/lib/tasks-digest.js +0 -200
  156. package/dist/src/lib/tasks-graph.d.ts +0 -79
  157. package/dist/src/lib/tasks-graph.js +0 -463
  158. package/dist/src/lib/tasks-lens.d.ts +0 -31
  159. package/dist/src/lib/tasks-lens.js +0 -47
  160. package/dist/src/lib/tasks-next.d.ts +0 -25
  161. package/dist/src/lib/tasks-next.js +0 -103
  162. package/dist/src/lib/tasks-prove.d.ts +0 -15
  163. package/dist/src/lib/tasks-prove.js +0 -68
  164. package/dist/src/lib/tasks-route.d.ts +0 -29
  165. package/dist/src/lib/tasks-route.js +0 -151
  166. package/dist/src/lib/tasks-score.d.ts +0 -36
  167. package/dist/src/lib/tasks-score.js +0 -152
  168. package/dist/src/lib/tasks-workspace.d.ts +0 -18
  169. package/dist/src/lib/tasks-workspace.js +0 -73
  170. package/dist/src/lib/vault-read.d.ts +0 -24
  171. package/dist/src/lib/vault-read.js +0 -77
  172. package/dist/src/lib/vaultfile.d.ts +0 -88
  173. package/dist/src/lib/vaultfile.js +0 -222
  174. package/dist/src/lib/wallet-money.d.ts +0 -222
  175. package/dist/src/lib/wallet-money.js +0 -578
  176. package/dist/src/lib/wallet-request.d.ts +0 -50
  177. package/dist/src/lib/wallet-request.js +0 -86
  178. package/dist/src/links.d.ts +0 -5
  179. package/dist/src/links.js +0 -45
  180. package/dist/src/media.d.ts +0 -29
  181. package/dist/src/media.js +0 -487
  182. package/dist/src/message-receipt.d.ts +0 -25
  183. package/dist/src/message-receipt.js +0 -71
  184. package/dist/src/message.d.ts +0 -13
  185. package/dist/src/message.js +0 -92
  186. package/dist/src/onboard.d.ts +0 -16
  187. package/dist/src/onboard.js +0 -149
  188. package/dist/src/plugin.d.ts +0 -2
  189. package/dist/src/plugin.js +0 -193
  190. package/dist/src/push.d.ts +0 -2
  191. package/dist/src/push.js +0 -115
  192. package/dist/src/render.d.ts +0 -21
  193. package/dist/src/render.js +0 -32
  194. package/dist/src/secrets-device.d.ts +0 -32
  195. package/dist/src/secrets-device.js +0 -127
  196. package/dist/src/secrets-give.d.ts +0 -125
  197. package/dist/src/secrets-give.js +0 -236
  198. package/dist/src/secrets-list.d.ts +0 -27
  199. package/dist/src/secrets-list.js +0 -84
  200. package/dist/src/secrets-run.d.ts +0 -31
  201. package/dist/src/secrets-run.js +0 -182
  202. package/dist/src/secrets.d.ts +0 -33
  203. package/dist/src/secrets.js +0 -200
  204. package/dist/src/setup.d.ts +0 -6
  205. package/dist/src/setup.js +0 -127
  206. package/dist/src/ship.d.ts +0 -2
  207. package/dist/src/ship.js +0 -18
  208. package/dist/src/shop.d.ts +0 -10
  209. package/dist/src/shop.js +0 -110
  210. package/dist/src/skill-parser.d.ts +0 -14
  211. package/dist/src/skill-parser.js +0 -113
  212. package/dist/src/skill.d.ts +0 -2
  213. package/dist/src/skill.js +0 -493
  214. package/dist/src/slug.d.ts +0 -2
  215. package/dist/src/slug.js +0 -6
  216. package/dist/src/social.d.ts +0 -2
  217. package/dist/src/social.js +0 -106
  218. package/dist/src/staff.d.ts +0 -2
  219. package/dist/src/staff.js +0 -104
  220. package/dist/src/start.d.ts +0 -15
  221. package/dist/src/start.js +0 -203
  222. package/dist/src/status.d.ts +0 -2
  223. package/dist/src/status.js +0 -52
  224. package/dist/src/substrate.d.ts +0 -2
  225. package/dist/src/substrate.js +0 -258
  226. package/dist/src/swap.d.ts +0 -93
  227. package/dist/src/swap.js +0 -622
  228. package/dist/src/tasks.d.ts +0 -2
  229. package/dist/src/tasks.js +0 -743
  230. package/dist/src/templates.d.ts +0 -1
  231. package/dist/src/templates.js +0 -213
  232. package/dist/src/trade.d.ts +0 -2
  233. package/dist/src/trade.js +0 -91
  234. package/dist/src/trail.d.ts +0 -2
  235. package/dist/src/trail.js +0 -41
  236. package/dist/src/validate.d.ts +0 -13
  237. package/dist/src/validate.js +0 -35
  238. package/dist/src/wallet-money.d.ts +0 -152
  239. package/dist/src/wallet-money.js +0 -564
  240. package/dist/src/wallet.d.ts +0 -167
  241. package/dist/src/wallet.js +0 -855
  242. package/dist/src/workflow.d.ts +0 -2
  243. package/dist/src/workflow.js +0 -166
  244. package/dist/src/write.d.ts +0 -43
  245. package/dist/src/write.js +0 -180
@@ -1,480 +0,0 @@
1
- /**
2
- * hl-run — the logic behind `one hl` (src/hl.ts is the commander wiring and loads this module
3
- * LAZILY, because this one imports @noble at module top: a monorepo tree whose shared node_modules
4
- * lacks @noble must still run every other `one` command). `one hl` — trade a Hyperliquid account from the terminal, signed by the sealed vault on THIS
5
- * machine (text/hyperliquid-plan.md § The signer seam, CLI row).
6
- *
7
- * one hl balance [0x…] perps + spot (swap.ts, unchanged)
8
- * one hl positions [0x…] open perps positions (keyless read)
9
- * one hl orders [0x…] resting orders, each with its cancel line
10
- * one hl transfer <amount> --to perps|spot usdClassTransfer, same account
11
- * one hl order <buy|sell> <size> <coin> [--limit px] [--tif Gtc|Ioc|Alo] [--reduce-only]
12
- * one hl cancel <coin> <oid>
13
- * one hl withdraw <amount> [--to 0x…] withdraw3 to Arbitrum USDC, default your own address
14
- *
15
- * DRY BY DEFAULT. Every action prints the exact `action`, the EIP-712 typed data and digest the
16
- * core's dryRun builds, and what it does in plain words — then stops. `--live` opens the vault
17
- * (`--dir`, Touch ID for a keychain wallet), prints the signer and its balance, asks [y/N] at a
18
- * terminal (`--yes` skips it), signs through the core's Signer seam (signAction recovers the
19
- * signature to the vault's address and binds the digest that was printed), posts DIRECTLY to
20
- * Hyperliquid with postExchange — never through ONE (H8) — prints the exchange's answer verbatim,
21
- * and reads the balance again.
22
- *
23
- * AN AGENT SHELL IS REFUSED before any vault opens, unless the vault folder is the agent's OWN
24
- * (its real path is under ~/.one/agents/) and `--yes` is passed. A person's vault is never opened
25
- * from an agent shell. An agent may not withdraw to an address other than its own (H12 / R17).
26
- *
27
- * The core is a generated copy of one.ie/web/src/lib/hyperliquid (src/lib/hl-core/, H11). The key
28
- * stays inside vaultSigner: no private key reaches out(), a refusal string or a log.
29
- */
30
- import { join, sep } from 'node:path';
31
- import { secp256k1 } from '@noble/curves/secp256k1.js';
32
- import { agentType } from './lib/agent-env.js';
33
- import * as hl from './lib/hl-core/index.js';
34
- import { EIP712_DOMAIN_FIELDS, hexToBytes, toHex } from './lib/hl-core/eip712.js';
35
- const ADDRESS = /^0x[0-9a-fA-F]{40}$/;
36
- const netOf = (a) => (a.testnet ? 'testnet' : 'mainnet');
37
- function refusal(error, detail, extra = {}) {
38
- return { data: { ok: false, error, detail, ...extra } };
39
- }
40
- class CliRefusal extends Error {
41
- code;
42
- constructor(code, message) {
43
- super(message);
44
- this.code = code;
45
- }
46
- }
47
- function fromThrown(e, extra = {}) {
48
- if (e instanceof hl.HlRefusal)
49
- return refusal(e.code, e.detail ?? e.message, extra);
50
- const code = e?.code;
51
- return refusal(typeof code === 'string' ? code : 'hl_error', e?.message ?? String(e), extra);
52
- }
53
- // ─── decimals, for the plain-words line only (never for an action) ─────────────
54
- function mulDec(a, b) {
55
- const da = hl.decimalsOf(a);
56
- const db = hl.decimalsOf(b);
57
- const s = (BigInt(a.replace('.', '')) * BigInt(b.replace('.', ''))).toString().padStart(da + db + 1, '0');
58
- const cut = s.length - (da + db);
59
- const frac = s.slice(cut).replace(/0+$/, '');
60
- return frac ? `${s.slice(0, cut)}.${frac}` : s.slice(0, cut);
61
- }
62
- // ─── the vault signer ─────────────────────────────────────────────────────────
63
- /**
64
- * A Signer over one secp256k1 key from the vault. It rebuilds the digest from (domain, types,
65
- * message) itself — the seam hands it no digest — and answers r ‖ s ‖ v, v = 27 + recovery.
66
- */
67
- export function vaultSigner(key) {
68
- const secret = hexToBytes(key.privateKeyHex);
69
- return {
70
- address: key.address,
71
- async signTypedData(domain, types, message) {
72
- const names = Object.keys(types);
73
- if (names.length !== 1)
74
- throw new hl.HlRefusal('eip712_type', `expected one primary type, got ${names.length}`);
75
- const digest = hl.typedDataDigest({ domain, types: { ...types, EIP712Domain: EIP712_DOMAIN_FIELDS }, primaryType: names[0], message });
76
- const sig = secp256k1.sign(digest, secret, { prehash: false, format: 'recovered' });
77
- const rsv = new Uint8Array(65);
78
- rsv.set(sig.slice(1, 65), 0);
79
- rsv[64] = sig[0] + 27;
80
- return `0x${toHex(rsv)}`;
81
- },
82
- };
83
- }
84
- const isObj = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
85
- const decOrNull = (v) => (typeof v === 'string' && /^-?\d+(\.\d+)?$/.test(v) ? v : null);
86
- /** perps + spot, or null when either read failed — a failed read is never a zero balance. */
87
- export async function readBalance(address, net, deps) {
88
- const [ch, sp] = await Promise.all([
89
- hl.readInfo({ type: 'clearinghouseState', user: address }, net, { fetchImpl: deps.fetchImpl }),
90
- hl.readInfo({ type: 'spotClearinghouseState', user: address }, net, { fetchImpl: deps.fetchImpl }),
91
- ]);
92
- if (!ch.ok || !sp.ok)
93
- return null;
94
- const c = isObj(ch.data) ? ch.data : {};
95
- const ms = isObj(c['marginSummary']) ? c['marginSummary'] : {};
96
- const balances = isObj(sp.data) && Array.isArray(sp.data['balances']) ? sp.data['balances'] : [];
97
- return {
98
- perps: { accountValue: decOrNull(ms['accountValue']), withdrawable: decOrNull(c['withdrawable']) },
99
- spot: balances.filter(isObj).map((b) => ({ coin: String(b['coin'] ?? '?'), total: String(b['total'] ?? '?'), hold: String(b['hold'] ?? '?') })),
100
- };
101
- }
102
- function balanceLines(label, b) {
103
- if (!b)
104
- return [`${label} not read — Hyperliquid did not answer (never shown as 0)`];
105
- const spot = b.spot.length ? b.spot.map((s) => `${s.total} ${s.coin}${s.hold !== '0' && s.hold !== '0.0' ? ` (${s.hold} held)` : ''}`).join(' · ') : 'empty';
106
- return [`${label} perps ${b.perps.accountValue ?? '—'} USDC (withdrawable ${b.perps.withdrawable ?? '—'}) · spot ${spot} — never summed`];
107
- }
108
- /** The account a keyless read is about: the address named, else the workspace's one EVM address. */
109
- export async function resolveAccount(address, actor, deps) {
110
- const a = address?.trim();
111
- if (a)
112
- return ADDRESS.test(a) ? { ok: true, address: a } : refusal('bad_address', 'A Hyperliquid account is a 0x address of 40 hex characters.');
113
- const w = await deps.ask('wallet:get', {});
114
- if (typeof w['error'] === 'string' || w['ok'] === false)
115
- return refusal(String(w['error'] ?? 'wallet_read_failed'), 'Could not read your workspace wallet — pass an address.');
116
- const rows = Array.isArray(w['addresses']) ? w['addresses'] : [];
117
- const evm = rows.filter((x) => x.chain === 'evm' && typeof x.address === 'string' && ADDRESS.test(x.address) && (!actor || x.actor === actor));
118
- const distinct = [...new Map(evm.map((x) => [x.address.toLowerCase(), x])).values()];
119
- if (distinct.length === 0)
120
- return refusal('no_evm_address', 'Your workspace has no EVM address registered — pass one.');
121
- if (distinct.length > 1)
122
- return refusal('ambiguous_address', `Several EVM addresses — pass one, or --actor <id>: ${distinct.map((x) => `${x.actor ?? '?'} ${x.address}`).join(' · ')}`);
123
- return { ok: true, address: distinct[0].address };
124
- }
125
- // ─── positions · orders ───────────────────────────────────────────────────────
126
- export async function runPositions(args, deps) {
127
- const net = netOf(args);
128
- const acct = await resolveAccount(args.address, args.actor, deps);
129
- if (!('ok' in acct && acct.ok === true))
130
- return acct;
131
- const r = await hl.readInfo({ type: 'clearinghouseState', user: acct.address }, net, { fetchImpl: deps.fetchImpl });
132
- if (!r.ok)
133
- return refusal(r.error, r.detail, { network: net });
134
- const c = isObj(r.data) ? r.data : {};
135
- const ms = isObj(c['marginSummary']) ? c['marginSummary'] : {};
136
- const positions = (Array.isArray(c['assetPositions']) ? c['assetPositions'] : [])
137
- .map((p) => (isObj(p) && isObj(p['position']) ? p['position'] : null))
138
- .filter((p) => p !== null)
139
- .map((p) => ({
140
- coin: String(p['coin'] ?? '?'),
141
- size: String(p['szi'] ?? '?'),
142
- entryPx: p['entryPx'] ?? null,
143
- positionValue: p['positionValue'] ?? null,
144
- unrealizedPnl: p['unrealizedPnl'] ?? null,
145
- liquidationPx: p['liquidationPx'] ?? null,
146
- leverage: isObj(p['leverage']) ? p['leverage'] : null,
147
- }));
148
- deps.say([
149
- `${acct.address} on ${net} — perps account ${decOrNull(ms['accountValue']) ?? '—'} USDC, withdrawable ${decOrNull(c['withdrawable']) ?? '—'}`,
150
- ...(positions.length
151
- ? positions.map((p) => ` ${p.coin.padEnd(8)} ${p.size.startsWith('-') ? 'short' : 'long '} ${p.size.replace(/^-/, '')} @ ${String(p.entryPx ?? '—')} value ${String(p.positionValue ?? '—')} pnl ${String(p.unrealizedPnl ?? '—')} liq ${String(p.liquidationPx ?? '—')}`)
152
- : [' no open perps positions (spot holdings: one hl balance)']),
153
- ]);
154
- return { data: { ok: true, network: net, address: acct.address, accountValue: decOrNull(ms['accountValue']), withdrawable: decOrNull(c['withdrawable']), positions } };
155
- }
156
- export async function runOrders(args, deps) {
157
- const net = netOf(args);
158
- const acct = await resolveAccount(args.address, args.actor, deps);
159
- if (!('ok' in acct && acct.ok === true))
160
- return acct;
161
- const r = await hl.readInfo({ type: 'openOrders', user: acct.address }, net, { fetchImpl: deps.fetchImpl });
162
- if (!r.ok)
163
- return refusal(r.error, r.detail, { network: net });
164
- if (!Array.isArray(r.data))
165
- return refusal('hyperliquid_unavailable', 'openOrders did not answer a list', { network: net });
166
- const orders = r.data.filter(isObj).map((o) => ({
167
- coin: String(o['coin'] ?? '?'),
168
- side: o['side'] === 'B' ? 'buy' : o['side'] === 'A' ? 'sell' : String(o['side'] ?? '?'),
169
- size: String(o['sz'] ?? '?'),
170
- limitPx: String(o['limitPx'] ?? '?'),
171
- oid: o['oid'] ?? null,
172
- timestamp: o['timestamp'] ?? null,
173
- }));
174
- deps.say([
175
- `${acct.address} on ${net} — ${orders.length} resting order${orders.length === 1 ? '' : 's'}`,
176
- ...orders.map((o) => ` ${o.side.padEnd(4)} ${o.size} ${o.coin} @ ${o.limitPx} oid ${String(o.oid)} cancel: one hl cancel ${o.coin} ${String(o.oid)}${net === 'testnet' ? ' --testnet' : ''}`),
177
- ]);
178
- return { data: { ok: true, network: net, address: acct.address, count: orders.length, orders } };
179
- }
180
- const FEE_TRADE = 'Hyperliquid takes its own trading fee on a fill (maker or taker, by your fee tier); ONE computes none and takes none.';
181
- export async function prepareOrder(a, deps) {
182
- const net = netOf(a);
183
- const side = a.side.toLowerCase();
184
- if (side !== 'buy' && side !== 'sell')
185
- return refusal('bad_side', 'The side is buy or sell.');
186
- if (a.tif !== undefined && a.limit === undefined && a.tif !== 'Ioc')
187
- return refusal('bad_tif', 'A market order is IOC by construction — --tif needs --limit.');
188
- let slip = 0.05;
189
- if (a.slippage !== undefined) {
190
- if (!/^\d{1,4}$/.test(a.slippage) || Number(a.slippage) < 1 || Number(a.slippage) > 2000)
191
- return refusal('bad_slippage', '--slippage is basis points, 1–2000 (default 500 = 5%, the python SDK default).');
192
- slip = Number(a.slippage) / 10_000;
193
- }
194
- const table = await hl.readAssetTable(net, { fetchImpl: deps.fetchImpl });
195
- if (!table.ok)
196
- return refusal(table.error, table.detail, { network: net });
197
- let info;
198
- try {
199
- info = hl.resolveCoin(table.data, a.coin);
200
- }
201
- catch (e) {
202
- return fromThrown(e, { network: net, next: 'A perp is its name (BTC, ETH, HYPE); a spot pair is BASE/QUOTE (HYPE/USDC, UBTC/USDC) or its @index.' });
203
- }
204
- let mid = null;
205
- if (a.limit === undefined) {
206
- const mids = await hl.readMids(net, { fetchImpl: deps.fetchImpl });
207
- if (!mids.ok)
208
- return refusal(mids.error, mids.detail, { network: net });
209
- mid = mids.data[info.coin] ?? null;
210
- if (mid === null)
211
- return refusal('mid_unavailable', `allMids has no price for ${info.coin} (${info.label}) — a market order needs one; pass --limit <px>.`, { network: net });
212
- }
213
- const isBuy = side === 'buy';
214
- const reduce = a.reduceOnly === true;
215
- const flags = [a.limit !== undefined ? `--limit ${a.limit}` : '', a.tif ? `--tif ${a.tif}` : '', reduce ? '--reduce-only' : '', a.slippage ? `--slippage ${a.slippage}` : ''].filter(Boolean).join(' ');
216
- return {
217
- cmdline: `one hl order ${side} ${a.size} ${a.coin}${flags ? ` ${flags}` : ''}`,
218
- build(nonce) {
219
- const action = a.limit !== undefined
220
- ? hl.buildOrder({ asset: info, isBuy, sz: a.size, px: a.limit, tif: (a.tif ?? 'Gtc'), reduceOnly: reduce })
221
- : hl.buildMarketOrder({ asset: info, isBuy, sz: a.size, mid: mid, slippage: slip, reduceOnly: reduce });
222
- const w = action.orders[0];
223
- const where = info.kind === 'spot' ? 'spot' : 'perps';
224
- const notional = mulDec(w.s, w.p);
225
- const tif = w.t.limit.tif;
226
- const how = a.limit === undefined
227
- ? `now, at ${isBuy ? 'up to' : 'no less than'} ${w.p} (mid ${mid} ${isBuy ? '+' : '−'} ${slip * 100}%) — IOC: fills what it can at that cap, cancels the rest`
228
- : tif === 'Gtc' ? `at ${w.p} or better — Gtc: rests on the book until filled or cancelled`
229
- : tif === 'Ioc' ? `at ${w.p} or better — IOC: fills what it can now, cancels the rest`
230
- : `at ${w.p} — Alo (post-only): refused if it would take liquidity`;
231
- const words = [
232
- `${isBuy ? 'Buy' : 'Sell'} ${w.s} ${info.label} (${where}, asset ${w.a}) ${how}.`,
233
- `${isBuy ? 'At most' : 'About'} ${notional} USDC notional before fees.`,
234
- info.kind === 'spot'
235
- ? (isBuy ? 'Pays USDC from your SPOT balance.' : `Sells ${info.label.split('/')[0]} you hold in SPOT for USDC.`)
236
- : `${reduce ? 'Reduce-only: it can only shrink a position you already hold.' : 'Opens or adds to a perps position; margin comes from your PERPS balance — spot USDC backs it only if the account is in unified mode (move it first: one hl transfer <amount> --to perps).'}`,
237
- FEE_TRADE,
238
- ];
239
- return { action, opts: { net, nonce, assets: table.data }, words, facts: { coin: info.coin, label: info.label, kind: info.kind, asset: w.a, side, size: w.s, price: w.p, tif, reduceOnly: reduce, notionalUsdc: notional, ...(mid ? { mid, slippageBps: Math.round(slip * 10_000) } : {}) } };
240
- },
241
- };
242
- }
243
- export async function prepareCancel(a, deps) {
244
- const net = netOf(a);
245
- if (!/^\d{1,16}$/.test(a.oid) || !Number.isSafeInteger(Number(a.oid)))
246
- return refusal('bad_oid', 'The order id is the whole number `one hl orders` prints.');
247
- const table = await hl.readAssetTable(net, { fetchImpl: deps.fetchImpl });
248
- if (!table.ok)
249
- return refusal(table.error, table.detail, { network: net });
250
- let info;
251
- try {
252
- info = hl.resolveCoin(table.data, a.coin);
253
- }
254
- catch (e) {
255
- return fromThrown(e, { network: net });
256
- }
257
- const oid = Number(a.oid);
258
- return {
259
- cmdline: `one hl cancel ${a.coin} ${a.oid}`,
260
- build(nonce) {
261
- return {
262
- action: hl.buildCancel({ asset: info, oid }),
263
- opts: { net, nonce, assets: table.data },
264
- words: [`Cancel resting order ${oid} on ${info.label} (asset ${info.asset}). Nothing is bought or sold; an order already filled cannot be cancelled and Hyperliquid will say so.`],
265
- facts: { coin: info.coin, label: info.label, asset: info.asset, oid },
266
- };
267
- },
268
- };
269
- }
270
- export async function prepareTransfer(a, deps) {
271
- const net = netOf(a);
272
- const to = (a.to ?? '').toLowerCase();
273
- if (to !== 'perps' && to !== 'spot')
274
- return refusal('bad_to', '--to perps (spot → perps) or --to spot (perps → spot).');
275
- const toPerp = to === 'perps';
276
- try {
277
- hl.checkUsd(a.amount);
278
- }
279
- catch (e) {
280
- return fromThrown(e, { network: net });
281
- }
282
- return {
283
- cmdline: `one hl transfer ${a.amount} --to ${to}`,
284
- build(nonce) {
285
- const action = hl.buildUsdClassTransfer({ amount: a.amount, toPerp, nonce });
286
- return {
287
- action,
288
- opts: { net },
289
- words: [
290
- `Move ${action.amount} USDC from ${toPerp ? 'SPOT to PERPS' : 'PERPS to SPOT'} on the same Hyperliquid account. Nothing leaves Hyperliquid; ONE takes nothing.`,
291
- toPerp ? 'Perps USDC can margin a position and is what `one hl withdraw` sends out.' : 'Spot USDC can buy spot pairs; it no longer margins perps positions.',
292
- 'Whether the account needs this depends on its mode — read the `abstraction` line.',
293
- ],
294
- facts: { amount: action.amount, toPerp },
295
- };
296
- },
297
- };
298
- }
299
- export async function prepareWithdraw(a, deps, agentShell) {
300
- const net = netOf(a);
301
- if (a.to !== undefined && !ADDRESS.test(a.to))
302
- return refusal('bad_address', '--to is an Arbitrum 0x address of 40 hex characters.');
303
- try {
304
- hl.checkUsd(a.amount);
305
- }
306
- catch (e) {
307
- return fromThrown(e, { network: net });
308
- }
309
- // Dry with no --to: the destination is the account's own address, the one `hl balance` reads.
310
- let dryOwn = null;
311
- if (!a.live && a.to === undefined) {
312
- const acct = await resolveAccount(a.address, a.actor, deps);
313
- if (!('ok' in acct && acct.ok === true)) {
314
- const r = acct;
315
- return { data: { ...r.data, next: 'Name the destination: --to 0x… (a live withdraw defaults to the vault\'s own address)' } };
316
- }
317
- dryOwn = acct.address;
318
- }
319
- return {
320
- cmdline: `one hl withdraw ${a.amount}${a.to ? ` --to ${a.to}` : ''}`,
321
- build(nonce, signer) {
322
- const own = signer ?? dryOwn;
323
- const destination = a.to ?? own;
324
- if (!destination)
325
- throw new hl.HlRefusal('bad_address', 'no destination');
326
- const toOther = own === null || destination.toLowerCase() !== own.toLowerCase();
327
- // H12 / R17: an agent key never sends Hyperliquid money anywhere but its own address.
328
- if (agentShell && signer !== null && toOther)
329
- throw new CliRefusal('to_other_refused', `An agent withdraws only to its own address (${signer}); ${destination} is another. A person signs that one.`);
330
- const action = hl.buildWithdraw3({ destination, amount: a.amount, time: nonce });
331
- return {
332
- action,
333
- opts: { net },
334
- words: [
335
- `Send ${action.amount} USDC from the PERPS balance${own ? ` of ${own}` : ''} to ${destination} on Arbitrum.${toOther ? ' THIS IS SOMEONE ELSE\'S ADDRESS (toOther) — a withdrawal cannot be undone.' : ' That is the same key on Arbitrum — your own address.'}`,
336
- 'Hyperliquid documents a 1 USDC withdrawal fee (unverified here): what lands is in its answer and the Arbitrum receipt, not computed by ONE.',
337
- 'Withdrawals leave from PERPS on a split account (move spot USDC first: one hl transfer <amount> --to perps); a unified account may withdraw from its one balance — unverified, the exchange\'s answer is the record.',
338
- 'ONE\'s Arbitrum signer is external: ONE cannot send it on from Arbitrum. Open that address in MetaMask or Rabby (same key).',
339
- ],
340
- facts: { amount: action.amount, destination: action.destination, toOther },
341
- };
342
- },
343
- };
344
- }
345
- // ─── the runner: dry, or live through the vault ───────────────────────────────
346
- /** Refuse BEFORE any vault opens — no Touch ID prompt for a run that cannot go on. */
347
- export function liveGate(a, deps) {
348
- const dir = a.dir ?? '.';
349
- const agent = agentType(deps.env);
350
- if (agent) {
351
- const real = deps.realpath(dir);
352
- const root = deps.realpath(join(deps.home, '.one', 'agents'));
353
- const own = real !== null && root !== null && real.startsWith(root + sep);
354
- if (!own)
355
- return refusal('agent_shell', `This shell is driven by ${agent}. A live Hyperliquid action here may sign only with the agent's OWN vault (a folder under ~/.one/agents/), and ${dir} is not one. Run it yourself in a terminal no agent drives.`);
356
- if (!a.yes)
357
- return refusal('agent_shell_needs_yes', `This shell is driven by ${agent}. Signing with the agent's own vault (${dir}) needs --yes — no one is here to answer a prompt.`);
358
- return null;
359
- }
360
- if (!deps.interactive && !a.yes)
361
- return refusal('confirm_required', 'Not at a terminal (or --json), so no one can answer [y/N] — pass --yes to sign without the prompt.');
362
- return null;
363
- }
364
- function dryLines(d) {
365
- return [
366
- `action ${JSON.stringify(d.action)}`,
367
- `typed data ${JSON.stringify(d.typedData)}`,
368
- `digest ${d.digest}`,
369
- ...(d.connectionId ? [`connectionId ${d.connectionId}`, `msgpack ${d.msgpackHex}`] : []),
370
- `nonce ${d.nonce}${d.vaultAddress ? ` vault ${d.vaultAddress}` : ''}`,
371
- `posts to ${d.exchangeUrl} (from this machine, never through ONE)`,
372
- ];
373
- }
374
- function dryData(d) {
375
- return { kind: d.kind, action: d.action, typedData: d.typedData, digest: d.digest, connectionId: d.connectionId, msgpackHex: d.msgpackHex, nonce: d.nonce, exchangeUrl: d.exchangeUrl };
376
- }
377
- /** The plain-words line for userAbstraction: unified / portfolio accounts margin perps from spot. */
378
- export function abstractionWords(ab) {
379
- if (typeof ab !== 'string')
380
- return 'abstraction not read — whether this account is unified is unknown';
381
- if (/unified|portfolio/i.test(ab))
382
- return `abstraction ${JSON.stringify(ab)} — spot USDC already backs perps on this account, so Hyperliquid may REFUSE this transfer or not need it (unverified: its answer is the record)`;
383
- return `abstraction ${JSON.stringify(ab)} — spot and perps are separate balances; the transfer is how USDC moves between them`;
384
- }
385
- async function abstractionOf(address, net, deps) {
386
- if (!address)
387
- return null;
388
- const r = await hl.readInfo({ type: 'userAbstraction', user: address }, net, { fetchImpl: deps.fetchImpl });
389
- return r.ok ? r.data : null;
390
- }
391
- export async function runAction(verb, a, prepare, deps, o = {}) {
392
- const net = netOf(a);
393
- // A live run is refused BEFORE any read and before any vault opens — no Touch ID for nothing.
394
- const gate = a.live ? liveGate(a, deps) : null;
395
- if (gate)
396
- return { data: { network: net, ...gate.data } };
397
- const prep = await prepare();
398
- if ('data' in prep)
399
- return { data: { network: net, ...prep.data } };
400
- if (!a.live) {
401
- let built;
402
- let d;
403
- try {
404
- built = prep.build(deps.now(), null);
405
- d = hl.dryRun(built.action, built.opts);
406
- }
407
- catch (e) {
408
- return fromThrown(e, { network: net });
409
- }
410
- let who = o.abstractionFor ?? null;
411
- if (verb === 'transfer' && !who) {
412
- const acct = await resolveAccount(undefined, undefined, deps);
413
- if ('ok' in acct && acct.ok === true)
414
- who = acct.address;
415
- }
416
- const abstraction = verb === 'transfer' ? await abstractionOf(who, net, deps) : undefined;
417
- const next = `${prep.cmdline}${net === 'testnet' ? ' --testnet' : ''} --live --dir <your vault folder>`;
418
- deps.say([
419
- `DRY RUN — nothing signed, nothing sent · ${verb} on ${net}`,
420
- ...built.words.map((w) => ` ${w}`),
421
- ...(verb === 'transfer' ? [abstractionWords(abstraction), ...(who ? [`account ${who}`] : [])] : []),
422
- ...dryLines(d),
423
- `next ${next}`,
424
- ]);
425
- return { data: { ok: true, live: false, posted: false, network: net, verb, consequence: built.words, ...built.facts, ...(verb === 'transfer' ? { abstraction: abstraction ?? null, account: who } : {}), ...dryData(d), next } };
426
- }
427
- const opened = await deps.unlock(a.dir ?? '.');
428
- if ('error' in opened)
429
- return refusal('vault_unavailable', opened.error, { network: net, next: 'Name the folder that holds .one/wallet.json: --dir ~/.one/<you>' });
430
- const key = opened.keys.find((k) => k.chain === 'evm');
431
- if (!key)
432
- return refusal('no_evm_key', `The vault at ${a.dir ?? '.'} holds no EVM key.`, { network: net });
433
- const signer = vaultSigner(key);
434
- let built;
435
- let d;
436
- try {
437
- built = prep.build(deps.now(), signer.address);
438
- d = hl.dryRun(built.action, built.opts);
439
- }
440
- catch (e) {
441
- return fromThrown(e, { network: net, signer: signer.address });
442
- }
443
- const before = await readBalance(signer.address, net, deps);
444
- const abstraction = verb === 'transfer' ? await abstractionOf(signer.address, net, deps) : undefined;
445
- deps.say([
446
- `LIVE · ${verb} on ${net} · signer ${signer.address} (the vault's EVM key)`,
447
- ...balanceLines('before', before),
448
- ...built.words.map((w) => ` ${w}`),
449
- ...(verb === 'transfer' ? [abstractionWords(abstraction)] : []),
450
- ...dryLines(d),
451
- ]);
452
- if (!a.yes) {
453
- const yes = await deps.confirm(`Sign this digest with ${signer.address} and post it to Hyperliquid ${net}? [y/N] `);
454
- if (!yes)
455
- return { data: { ok: false, error: 'declined', network: net, signer: signer.address, posted: false, detail: 'Nothing signed, nothing sent.' } };
456
- }
457
- let request;
458
- try {
459
- ;
460
- ({ request } = await hl.signAction(built.action, built.opts, signer, { expectDigest: d.digest }));
461
- }
462
- catch (e) {
463
- return fromThrown(e, { network: net, signer: signer.address, posted: false });
464
- }
465
- const res = await hl.postExchange(request, net, { fetchImpl: deps.fetchImpl });
466
- const after = await readBalance(signer.address, net, deps);
467
- deps.say([
468
- `exchange ${JSON.stringify(res.ok ? res.response : { error: res.error, detail: res.detail, response: res.response ?? null })}`,
469
- ...balanceLines('after ', after),
470
- ]);
471
- return {
472
- data: {
473
- ok: res.ok, ...(res.ok ? {} : { error: res.error, detail: res.detail }),
474
- live: true, posted: true, network: net, verb, signer: signer.address, ...built.facts,
475
- ...(verb === 'transfer' ? { abstraction: abstraction ?? null } : {}),
476
- ...dryData(d), signature: request.signature, exchange: res.ok ? res.response : (res.response ?? null),
477
- balanceBefore: before, balanceAfter: after,
478
- },
479
- };
480
- }
package/dist/src/hl.d.ts DELETED
@@ -1,17 +0,0 @@
1
- /**
2
- * `one hl` — the commander wiring for Hyperliquid trading. Everything that signs, reads or builds
3
- * an action lives in ./hl-run.ts and is loaded with `await import` when an action runs, so the
4
- * @noble imports never sit on the CLI's startup path (key-sweep.ts does the same for the SDK's
5
- * sweep-runner). `one hl --help` and `one hl balance` work without @noble; an action without it
6
- * answers `hl_signer_unavailable` by name. What each verb does: ./hl-run.ts header ·
7
- * text/cli-commands.md § hl.
8
- */
9
- import { Command } from 'commander';
10
- import type { HlDeps } from './hl-run.js';
11
- interface Common {
12
- api?: string;
13
- key?: string;
14
- }
15
- /** `one hl` — balance from swap.ts, plus the reads and the four signed actions. */
16
- export declare function hlCmd(deps?: (cmd: Command, o: Common) => HlDeps): Command;
17
- export {};
package/dist/src/hl.js DELETED
@@ -1,148 +0,0 @@
1
- import { createInterface } from 'node:readline';
2
- import { realpathSync } from 'node:fs';
3
- import { homedir } from 'node:os';
4
- import { hlCmd as hlReadCmd, emit } from './swap.js';
5
- import { agentType } from './lib/agent-env.js';
6
- import { askPath } from './lib/api-path.js';
7
- import { authHeaders, jsonMode, resolveBase, resolveKey } from './lib/client.js';
8
- import { mergeEnv } from './env.js';
9
- import { unlock } from './wallet.js';
10
- const DEFAULT_API = 'https://api.one.ie';
11
- /** The logic module, or a named refusal when @noble does not resolve in this tree. */
12
- async function loadRun() {
13
- try {
14
- return await import('./hl-run.js');
15
- }
16
- catch (e) {
17
- return { data: { ok: false, error: 'hl_signer_unavailable', detail: `the hl signer needs @noble/hashes + @noble/curves (${e.message.split('\n')[0]})`, next: 'cd packages && bun install (or: npm i @oneie/cli)' } };
18
- }
19
- }
20
- // ─── wiring ───────────────────────────────────────────────────────────────────
21
- function ttyConfirm(question) {
22
- return new Promise((resolve) => {
23
- const rl = createInterface({ input: process.stdin, output: process.stderr });
24
- rl.question(question, (ans) => { rl.close(); resolve(/^y(es)?$/i.test(ans.trim())); });
25
- });
26
- }
27
- async function askOnce(base, key, receiver, data) {
28
- try {
29
- const res = await fetch(askPath(base, receiver), { method: 'POST', headers: authHeaders(key ? { key } : {}), body: JSON.stringify({ data }) });
30
- const body = (await res.json().catch(() => ({})));
31
- if (body['outcome'] !== undefined && body['outcome'] !== 'result')
32
- return { ok: false, error: String(body['result']?.['error'] ?? body['error'] ?? `${receiver}_${String(body['outcome'])}`) };
33
- return (body['result'] ?? body);
34
- }
35
- catch {
36
- return { ok: false, error: 'api_unreachable' };
37
- }
38
- }
39
- function liveDeps(cmd, o) {
40
- const base = resolveBase({ api: o.api }, DEFAULT_API);
41
- const env = mergeEnv(process.cwd());
42
- const key = o.key ?? env.ONEIE_API_KEY ?? env.ONE_API_KEY ?? (resolveKey() || undefined);
43
- const json = jsonMode(cmd);
44
- return {
45
- fetchImpl: fetch,
46
- now: () => Date.now(),
47
- env: process.env,
48
- interactive: !json && !!process.stdin.isTTY && !!process.stdout.isTTY,
49
- home: homedir(),
50
- realpath: (p) => { try {
51
- return realpathSync(p);
52
- }
53
- catch {
54
- return null;
55
- } },
56
- unlock: (dir) => unlock(dir),
57
- confirm: ttyConfirm,
58
- say: (lines) => { if (!json)
59
- for (const l of lines)
60
- process.stdout.write(l + '\n'); },
61
- ask: (receiver, data) => askOnce(base, key, receiver, data),
62
- };
63
- }
64
- /** Human mode printed its lines through say(); a refusal and --json go through out(). */
65
- function close(cmd, res) {
66
- if (jsonMode(cmd) || res.data['ok'] === false)
67
- emit(cmd, res);
68
- else if (res.exitCode !== undefined)
69
- process.exitCode = res.exitCode;
70
- }
71
- function liveOpts(c) {
72
- return c
73
- .option('--testnet', 'Hyperliquid testnet (the default is mainnet — named on every call, never inherited)')
74
- .option('--live', 'Open the vault, sign, and post to Hyperliquid. Without it nothing is signed or sent')
75
- .option('--dir <path>', 'The folder whose sealed vault (.one/wallet.json) holds the EVM key — e.g. ~/.one/tony', '.')
76
- .option('--yes', 'Sign without the [y/N] prompt (required off a terminal; an agent shell also needs its OWN vault)')
77
- .option('--api <url>', 'API base URL (only to find your EVM address when none is named)', DEFAULT_API)
78
- .option('--key <key>', 'API key (only for that lookup)');
79
- }
80
- /** `one hl` — balance from swap.ts, plus the reads and the four signed actions. */
81
- export function hlCmd(deps) {
82
- const make = deps ?? liveDeps;
83
- const cmd = hlReadCmd();
84
- cmd.description('Hyperliquid — balances, positions and orders; trade, move and withdraw signed by YOUR vault (dry by default, --live signs)');
85
- for (const [name, run, what] of [
86
- ['positions', 'runPositions', 'Open perps positions of a Hyperliquid account (keyless read). No address = your workspace\'s EVM address'],
87
- ['orders', 'runOrders', 'Resting orders of a Hyperliquid account, each with its cancel line (keyless read)'],
88
- ]) {
89
- cmd.command(`${name} [address]`)
90
- .description(what)
91
- .option('--testnet', 'Read Hyperliquid testnet')
92
- .option('--actor <id>', 'Pick this actor\'s EVM address when the workspace has several')
93
- .option('--api <url>', 'API base URL', DEFAULT_API)
94
- .option('--key <key>', 'API key (needed only without an address)')
95
- .action(async function (address, o) {
96
- const m = await loadRun();
97
- if ('data' in m)
98
- return close(this, m);
99
- close(this, await m[run]({ address, actor: o.actor, testnet: o.testnet }, make(this, o)));
100
- });
101
- }
102
- liveOpts(cmd.command('transfer <amount>'))
103
- .description('Move USDC between your spot and perps balances (usdClassTransfer). Dry by default')
104
- .requiredOption('--to <side>', 'perps (spot → perps) | spot (perps → spot)')
105
- .option('--address <0x>', 'Dry run only: the account whose unified/portfolio mode to read')
106
- .action(async function (amount, o) {
107
- const m = await loadRun();
108
- if ('data' in m)
109
- return close(this, m);
110
- const d = make(this, o);
111
- close(this, await m.runAction('transfer', o, () => m.prepareTransfer({ ...o, amount }, d), d, { abstractionFor: o.address ?? null }));
112
- });
113
- liveOpts(cmd.command('order <side> <size> <coin>'))
114
- .description('Buy or sell — market (IOC at mid ± slippage) unless --limit. Perps by name (BTC), spot by pair (HYPE/USDC). Dry by default')
115
- .option('--limit <px>', 'Limit price (decimal); without it the order is a market IOC')
116
- .option('--tif <tif>', 'Gtc | Ioc | Alo (with --limit; default Gtc)')
117
- .option('--reduce-only', 'Only shrink an existing position')
118
- .option('--slippage <bps>', 'Market only: the price cap from mid, basis points (default 500 = 5%)')
119
- .action(async function (side, size, coin, o) {
120
- const m = await loadRun();
121
- if ('data' in m)
122
- return close(this, m);
123
- const d = make(this, o);
124
- close(this, await m.runAction('order', o, () => m.prepareOrder({ ...o, side, size, coin }, d), d));
125
- });
126
- liveOpts(cmd.command('cancel <coin> <oid>'))
127
- .description('Cancel a resting order (the coin and oid `one hl orders` prints). Dry by default')
128
- .action(async function (coin, oid, o) {
129
- const m = await loadRun();
130
- if ('data' in m)
131
- return close(this, m);
132
- const d = make(this, o);
133
- close(this, await m.runAction('cancel', o, () => m.prepareCancel({ ...o, coin, oid }, d), d));
134
- });
135
- liveOpts(cmd.command('withdraw <amount>'))
136
- .description('Withdraw USDC from perps to Arbitrum (withdraw3) — to your own address unless --to. Dry by default')
137
- .option('--to <0x>', 'Destination on Arbitrum (default: the vault\'s own address; an agent may not name another)')
138
- .option('--address <0x>', 'Dry run only: whose own address the default destination is')
139
- .option('--actor <id>', 'Dry run only: pick this actor\'s EVM address')
140
- .action(async function (amount, o) {
141
- const m = await loadRun();
142
- if ('data' in m)
143
- return close(this, m);
144
- const d = make(this, o);
145
- close(this, await m.runAction('withdraw', o, () => m.prepareWithdraw({ ...o, amount }, d, Boolean(agentType(d.env))), d));
146
- });
147
- return cmd;
148
- }
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};