oneie 5.7.5 → 5.7.6
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 +1 -0
- package/dist/package.json +5 -2
- package/dist/src/balances.d.ts +89 -0
- package/dist/src/balances.js +202 -0
- package/dist/src/hl-run.d.ts +119 -0
- package/dist/src/hl-run.js +480 -0
- package/dist/src/hl.d.ts +17 -0
- package/dist/src/hl.js +148 -0
- package/dist/src/index.js +2 -1
- package/dist/src/key-sweep.d.ts +19 -3
- package/dist/src/key-sweep.js +63 -20
- package/dist/src/lib/hl-core/actions.d.ts +99 -0
- package/dist/src/lib/hl-core/actions.js +69 -0
- package/dist/src/lib/hl-core/eip712.d.ts +33 -0
- package/dist/src/lib/hl-core/eip712.js +107 -0
- package/dist/src/lib/hl-core/errors.d.ts +10 -0
- package/dist/src/lib/hl-core/errors.js +15 -0
- package/dist/src/lib/hl-core/exchange.d.ts +24 -0
- package/dist/src/lib/hl-core/exchange.js +47 -0
- package/dist/src/lib/hl-core/index.d.ts +13 -0
- package/dist/src/lib/hl-core/index.js +14 -0
- package/dist/src/lib/hl-core/meta.d.ts +57 -0
- package/dist/src/lib/hl-core/meta.js +110 -0
- package/dist/src/lib/hl-core/msgpack.d.ts +18 -0
- package/dist/src/lib/hl-core/msgpack.js +136 -0
- package/dist/src/lib/hl-core/net.d.ts +2 -0
- package/dist/src/lib/hl-core/net.js +7 -0
- package/dist/src/lib/hl-core/signing.d.ts +103 -0
- package/dist/src/lib/hl-core/signing.js +295 -0
- package/dist/src/lib/hl-core/wire.d.ts +34 -0
- package/dist/src/lib/hl-core/wire.js +81 -0
- package/dist/src/lib/journey-words.d.ts +54 -3
- package/dist/src/lib/journey-words.js +159 -20
- package/dist/src/lib/journey.js +1 -1
- package/dist/src/lib/key-source.d.ts +9 -0
- package/dist/src/lib/key-source.js +33 -0
- package/dist/src/lib/network.d.ts +15 -0
- package/dist/src/lib/network.js +41 -0
- package/dist/src/lib/qr.d.ts +21 -0
- package/dist/src/lib/qr.js +402 -0
- package/dist/src/lib/sale-card.d.ts +117 -0
- package/dist/src/lib/sale-card.js +261 -0
- package/dist/src/lib/sui-grpc-send.d.ts +50 -0
- package/dist/src/lib/sui-grpc-send.js +89 -0
- package/dist/src/lib/wallet-money.d.ts +222 -0
- package/dist/src/lib/wallet-money.js +578 -0
- package/dist/src/lib/wallet-request.d.ts +50 -0
- package/dist/src/lib/wallet-request.js +86 -0
- package/dist/src/onboard.js +4 -3
- package/dist/src/shop.js +38 -1
- package/dist/src/staff.js +10 -0
- package/dist/src/start.js +14 -6
- package/dist/src/wallet-money.d.ts +152 -0
- package/dist/src/wallet-money.js +564 -0
- package/dist/src/wallet.js +169 -24
- package/package.json +5 -2
|
@@ -0,0 +1,480 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
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
|
+
}
|
package/dist/src/index.js
CHANGED
|
@@ -19,7 +19,8 @@ import { evalCmd } from './eval.js';
|
|
|
19
19
|
import { setupCmd } from './setup.js';
|
|
20
20
|
import { clientCmd } from './client.js';
|
|
21
21
|
import { walletCmd } from './wallet.js';
|
|
22
|
-
import { swapCmd
|
|
22
|
+
import { swapCmd } from './swap.js';
|
|
23
|
+
import { hlCmd } from './hl.js';
|
|
23
24
|
import { keyCmd } from './key.js';
|
|
24
25
|
import { secretsCmd } from './secrets.js';
|
|
25
26
|
import { runCmd } from './secrets-run.js';
|