@oneie/cli 5.7.5 → 5.8.0

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 (87) hide show
  1. package/README.md +19 -0
  2. package/dist/package.json +5 -2
  3. package/dist/src/balances.d.ts +89 -0
  4. package/dist/src/balances.js +202 -0
  5. package/dist/src/ceiling.d.ts +36 -0
  6. package/dist/src/ceiling.js +189 -0
  7. package/dist/src/check.d.ts +11 -0
  8. package/dist/src/check.js +53 -0
  9. package/dist/src/credits.d.ts +29 -0
  10. package/dist/src/credits.js +88 -0
  11. package/dist/src/hl-run.d.ts +119 -0
  12. package/dist/src/hl-run.js +480 -0
  13. package/dist/src/hl.d.ts +17 -0
  14. package/dist/src/hl.js +148 -0
  15. package/dist/src/index.js +15 -1
  16. package/dist/src/join.js +4 -0
  17. package/dist/src/key-sweep.d.ts +19 -3
  18. package/dist/src/key-sweep.js +70 -20
  19. package/dist/src/lib/check-words.d.ts +57 -0
  20. package/dist/src/lib/check-words.js +144 -0
  21. package/dist/src/lib/hl-core/actions.d.ts +99 -0
  22. package/dist/src/lib/hl-core/actions.js +69 -0
  23. package/dist/src/lib/hl-core/eip712.d.ts +33 -0
  24. package/dist/src/lib/hl-core/eip712.js +107 -0
  25. package/dist/src/lib/hl-core/errors.d.ts +10 -0
  26. package/dist/src/lib/hl-core/errors.js +15 -0
  27. package/dist/src/lib/hl-core/exchange.d.ts +24 -0
  28. package/dist/src/lib/hl-core/exchange.js +47 -0
  29. package/dist/src/lib/hl-core/index.d.ts +13 -0
  30. package/dist/src/lib/hl-core/index.js +14 -0
  31. package/dist/src/lib/hl-core/meta.d.ts +57 -0
  32. package/dist/src/lib/hl-core/meta.js +110 -0
  33. package/dist/src/lib/hl-core/msgpack.d.ts +18 -0
  34. package/dist/src/lib/hl-core/msgpack.js +136 -0
  35. package/dist/src/lib/hl-core/net.d.ts +2 -0
  36. package/dist/src/lib/hl-core/net.js +7 -0
  37. package/dist/src/lib/hl-core/signing.d.ts +103 -0
  38. package/dist/src/lib/hl-core/signing.js +295 -0
  39. package/dist/src/lib/hl-core/wire.d.ts +34 -0
  40. package/dist/src/lib/hl-core/wire.js +81 -0
  41. package/dist/src/lib/journey-words.d.ts +54 -3
  42. package/dist/src/lib/journey-words.js +162 -20
  43. package/dist/src/lib/journey.d.ts +2 -0
  44. package/dist/src/lib/journey.js +21 -2
  45. package/dist/src/lib/key-source.d.ts +9 -0
  46. package/dist/src/lib/key-source.js +33 -0
  47. package/dist/src/lib/net-choice.d.ts +28 -0
  48. package/dist/src/lib/net-choice.js +72 -0
  49. package/dist/src/lib/network.d.ts +22 -0
  50. package/dist/src/lib/network.js +50 -0
  51. package/dist/src/lib/next-words.d.ts +105 -0
  52. package/dist/src/lib/next-words.js +298 -0
  53. package/dist/src/lib/qr.d.ts +21 -0
  54. package/dist/src/lib/qr.js +402 -0
  55. package/dist/src/lib/sale-card.d.ts +117 -0
  56. package/dist/src/lib/sale-card.js +261 -0
  57. package/dist/src/lib/sui-grpc-send.d.ts +90 -0
  58. package/dist/src/lib/sui-grpc-send.js +128 -0
  59. package/dist/src/lib/timed-fetch.d.ts +33 -0
  60. package/dist/src/lib/timed-fetch.js +59 -0
  61. package/dist/src/lib/vaultfile.d.ts +15 -0
  62. package/dist/src/lib/vaultfile.js +28 -1
  63. package/dist/src/lib/wallet-money.d.ts +222 -0
  64. package/dist/src/lib/wallet-money.js +578 -0
  65. package/dist/src/lib/wallet-request.d.ts +50 -0
  66. package/dist/src/lib/wallet-request.js +86 -0
  67. package/dist/src/move.d.ts +36 -0
  68. package/dist/src/move.js +152 -0
  69. package/dist/src/network-cmd.d.ts +17 -0
  70. package/dist/src/network-cmd.js +74 -0
  71. package/dist/src/next.d.ts +12 -0
  72. package/dist/src/next.js +67 -0
  73. package/dist/src/onboard.js +4 -3
  74. package/dist/src/shop-buy.d.ts +16 -0
  75. package/dist/src/shop-buy.js +101 -0
  76. package/dist/src/shop.js +40 -1
  77. package/dist/src/staff.js +10 -0
  78. package/dist/src/start.d.ts +12 -0
  79. package/dist/src/start.js +51 -21
  80. package/dist/src/thread.d.ts +2 -0
  81. package/dist/src/thread.js +52 -0
  82. package/dist/src/wallet-money.d.ts +158 -0
  83. package/dist/src/wallet-money.js +664 -0
  84. package/dist/src/wallet.d.ts +2 -0
  85. package/dist/src/wallet.js +290 -27
  86. package/dist/src/workflow.js +4 -1
  87. package/package.json +5 -2
@@ -0,0 +1,29 @@
1
+ /**
2
+ * credits.ts — `one credits buy <usd>`: an agent buys ONE credits with its own coins, through
3
+ * x402, with no person in the loop. The same three calls text/agent-path.md walk 8 made by hand:
4
+ *
5
+ * 1. quote POST /api/x402 {slug, amount} → 402 with payOptions (address + exact amount per chain)
6
+ * 2. pay the vault in --dir sends EXACTLY amountAtomic to the quoted address (suiSendGrpc,
7
+ * the CLI's one Sui signer). The amount identifies the quote, so it is never rounded.
8
+ * 3. settle POST /api/x402 {slug, amount, tx_digest, chain} → credits granted, or a named refusal.
9
+ *
10
+ * The quote names the PLATFORM treasury pay verifies (Tony's key since Release 2). Dry by default:
11
+ * without --live it prints the quote and signs nothing. Sui only today — pay's x402 verifies
12
+ * native SUI there (USDC on Sui settles through the /credits escrow, a signed-in person's rail).
13
+ */
14
+ import { Command } from 'commander';
15
+ interface PayOption {
16
+ quoteId?: string;
17
+ chain: string;
18
+ asset: string;
19
+ currency: string;
20
+ amountExact: string;
21
+ amountAtomic: string;
22
+ decimals: number;
23
+ address: string;
24
+ expiresAt: number;
25
+ }
26
+ /** The one option this verb pays: Sui, native coin. Anything else is refused by name. */
27
+ export declare function pickSuiOption(options: PayOption[]): PayOption | null;
28
+ export declare function creditsCmd(): Command;
29
+ export {};
@@ -0,0 +1,88 @@
1
+ /**
2
+ * credits.ts — `one credits buy <usd>`: an agent buys ONE credits with its own coins, through
3
+ * x402, with no person in the loop. The same three calls text/agent-path.md walk 8 made by hand:
4
+ *
5
+ * 1. quote POST /api/x402 {slug, amount} → 402 with payOptions (address + exact amount per chain)
6
+ * 2. pay the vault in --dir sends EXACTLY amountAtomic to the quoted address (suiSendGrpc,
7
+ * the CLI's one Sui signer). The amount identifies the quote, so it is never rounded.
8
+ * 3. settle POST /api/x402 {slug, amount, tx_digest, chain} → credits granted, or a named refusal.
9
+ *
10
+ * The quote names the PLATFORM treasury pay verifies (Tony's key since Release 2). Dry by default:
11
+ * without --live it prints the quote and signs nothing. Sui only today — pay's x402 verifies
12
+ * native SUI there (USDC on Sui settles through the /credits escrow, a signed-in person's rail).
13
+ */
14
+ import { Command } from 'commander';
15
+ import { authHeaders, out, resolveBase } from './lib/client.js';
16
+ import { suiSendGrpc } from './lib/sui-grpc-send.js';
17
+ import { SUI_NATIVE } from './lib/wallet-money.js';
18
+ import { unlock } from './wallet.js';
19
+ import { netLine, resolveNet } from './lib/net-choice.js';
20
+ const SUI_ADDR = /^0x[0-9a-f]{64}$/i;
21
+ /** The one option this verb pays: Sui, native coin. Anything else is refused by name. */
22
+ export function pickSuiOption(options) {
23
+ const o = options.find((x) => x.chain === 'SUI' && x.asset === 'NATIVE');
24
+ return o && SUI_ADDR.test(o.address) && /^\d+$/.test(o.amountAtomic) && BigInt(o.amountAtomic) > 0n ? o : null;
25
+ }
26
+ async function x402(base, body) {
27
+ const res = await fetch(`${base.replace(/\/$/, '')}/api/x402`, { method: 'POST', headers: { ...authHeaders(), 'content-type': 'application/json' }, body: JSON.stringify(body) });
28
+ return { status: res.status, json: (await res.json().catch(() => ({}))) };
29
+ }
30
+ export function creditsCmd() {
31
+ const cmd = new Command('credits').description('Buy ONE credits with your own coins (x402) — the agent pays, no person in the loop');
32
+ cmd.command('buy <usd>')
33
+ .description('Quote, pay the exact quoted SUI from the vault in --dir, settle — credits land on --slug. Dry unless --live')
34
+ .requiredOption('--slug <slug>', 'The workspace the credits land on (an agent: its own id)')
35
+ .option('--dir <vault>', 'The sealed vault that pays', '.')
36
+ .option('--net <network>', 'mainnet | testnet (default: ONE_NETWORK, then `one network`, then the deploy)')
37
+ .option('--api <url>', 'one.ie base URL')
38
+ .option('--rpc <url>', 'Sui gRPC base URL override')
39
+ .option('--live', 'Pay and settle. Without it: the quote only')
40
+ .action(async (usd, o, sub) => {
41
+ const t0 = Date.now();
42
+ const amount = Number(usd);
43
+ if (!/^\d+(\.\d{1,2})?$/.test(usd) || !(amount > 0))
44
+ return out(sub, { ok: false, error: 'bad_amount', detail: 'dollars, e.g. 1 or 0.50' });
45
+ const nc = await resolveNet(o.net, o.api);
46
+ if (!nc.ok)
47
+ return out(sub, nc);
48
+ const net = nc.net;
49
+ const base = resolveBase({ api: o.api }, 'https://one.ie');
50
+ const q = await x402(base, { slug: o.slug, amount });
51
+ if (q.status !== 402 || q.json.status !== 'payment_required')
52
+ return out(sub, { ok: false, error: 'no_quote', status: q.status, detail: q.json.error ?? q.json });
53
+ const opt = pickSuiOption(q.json.payOptions ?? []);
54
+ if (!opt)
55
+ return out(sub, { ok: false, error: 'no_sui_option', chains: (q.json.payOptions ?? []).map((x) => `${x.chain}/${x.asset}`) });
56
+ const quote = { usd: amount, pay: `${opt.amountExact} SUI`, to: opt.address, quoteId: opt.quoteId, expiresAt: opt.expiresAt, net, networkFrom: nc.from, says: netLine(nc) };
57
+ if (!o.live)
58
+ return out(sub, { ok: true, dry: true, quote, next: 'add --live to pay it from the vault in --dir and settle' });
59
+ const opened = await unlock(o.dir);
60
+ if ('error' in opened)
61
+ return out(sub, { ok: false, error: 'vault_locked', detail: opened.error });
62
+ const key = opened.keys.find((k) => k.chain === 'sui');
63
+ if (!key)
64
+ return out(sub, { ok: false, error: 'no_sui_key_in_vault' });
65
+ let digest;
66
+ let finalMs;
67
+ try {
68
+ const sent = await suiSendGrpc({ asset: 'SUI', coinType: SUI_NATIVE, from: key.address, to: opt.address, amountUnits: BigInt(opt.amountAtomic), privateKeyHex: key.privateKeyHex, rpc: o.rpc, net });
69
+ digest = sent.digest;
70
+ finalMs = sent.finalMs;
71
+ }
72
+ catch (e) {
73
+ const err = e;
74
+ return out(sub, { ok: false, error: err.code ?? 'send_failed', detail: err.message, ...(err.digest ? { digest: err.digest } : {}), quote });
75
+ }
76
+ // Settle. The verifier reads the chain; a just-final tx may need a moment to index.
77
+ let s = { status: 0, json: {} };
78
+ for (let i = 0; i < 5; i++) {
79
+ s = await x402(base, { slug: o.slug, amount, tx_digest: digest, chain: 'SUI' });
80
+ if (s.status === 200 || (s.status !== 402 && s.status < 500))
81
+ break;
82
+ await new Promise((r) => setTimeout(r, 2000));
83
+ }
84
+ const ok = s.status === 200;
85
+ return out(sub, { ok, ...(ok ? {} : { error: 'not_settled', status: s.status }), digest, explorer: `https://suiscan.xyz/${net}/tx/${digest}`, payer: key.address, quote, settled: s.json, finalMs, wallMs: Date.now() - t0 });
86
+ });
87
+ return cmd;
88
+ }
@@ -0,0 +1,119 @@
1
+ import * as hl from './lib/hl-core/index.js';
2
+ import type { HlNet } from './lib/hl-core/net.js';
3
+ type Obj = Record<string, unknown>;
4
+ export interface VaultKey {
5
+ chain: string;
6
+ address: string;
7
+ privateKeyHex: string;
8
+ }
9
+ export interface HlDeps {
10
+ /** Every Hyperliquid read and the one /exchange post go through this. */
11
+ fetchImpl: typeof fetch;
12
+ /** The signing machine's ms clock — the nonce (H13). */
13
+ now(): number;
14
+ env: NodeJS.ProcessEnv;
15
+ /** A person at a terminal: stdin and stdout are TTYs and --json is off. */
16
+ interactive: boolean;
17
+ home: string;
18
+ realpath(p: string): string | null;
19
+ unlock(dir: string): Promise<{
20
+ keys: VaultKey[];
21
+ } | {
22
+ error: string;
23
+ }>;
24
+ confirm(question: string): Promise<boolean>;
25
+ say(lines: string[]): void;
26
+ /** A ONE receiver (wallet:get only — to find the workspace's EVM address when none is named). */
27
+ ask(receiver: string, data: Obj): Promise<Obj>;
28
+ }
29
+ export interface Result {
30
+ data: Obj;
31
+ exitCode?: number;
32
+ }
33
+ export interface LiveArgs {
34
+ testnet?: boolean;
35
+ live?: boolean;
36
+ dir?: string;
37
+ yes?: boolean;
38
+ }
39
+ /**
40
+ * A Signer over one secp256k1 key from the vault. It rebuilds the digest from (domain, types,
41
+ * message) itself — the seam hands it no digest — and answers r ‖ s ‖ v, v = 27 + recovery.
42
+ */
43
+ export declare function vaultSigner(key: {
44
+ address: string;
45
+ privateKeyHex: string;
46
+ }): hl.Signer;
47
+ export interface HlBalance {
48
+ perps: {
49
+ accountValue: string | null;
50
+ withdrawable: string | null;
51
+ };
52
+ spot: Array<{
53
+ coin: string;
54
+ total: string;
55
+ hold: string;
56
+ }>;
57
+ }
58
+ /** perps + spot, or null when either read failed — a failed read is never a zero balance. */
59
+ export declare function readBalance(address: string, net: HlNet, deps: HlDeps): Promise<HlBalance | null>;
60
+ /** The account a keyless read is about: the address named, else the workspace's one EVM address. */
61
+ export declare function resolveAccount(address: string | undefined, actor: string | undefined, deps: HlDeps): Promise<{
62
+ ok: true;
63
+ address: string;
64
+ } | Result>;
65
+ export declare function runPositions(args: {
66
+ address?: string;
67
+ actor?: string;
68
+ testnet?: boolean;
69
+ }, deps: HlDeps): Promise<Result>;
70
+ export declare function runOrders(args: {
71
+ address?: string;
72
+ actor?: string;
73
+ testnet?: boolean;
74
+ }, deps: HlDeps): Promise<Result>;
75
+ /** What a verb hands the runner: its action for a nonce + signer, and the words for a person. */
76
+ interface Built {
77
+ action: hl.HlAction;
78
+ opts: hl.DryRunOpts;
79
+ words: string[];
80
+ facts: Obj;
81
+ }
82
+ interface Prepared {
83
+ cmdline: string;
84
+ build(nonce: number, signer: string | null): Built;
85
+ }
86
+ export interface OrderArgs extends LiveArgs {
87
+ side: string;
88
+ size: string;
89
+ coin: string;
90
+ limit?: string;
91
+ tif?: string;
92
+ reduceOnly?: boolean;
93
+ slippage?: string;
94
+ }
95
+ export declare function prepareOrder(a: OrderArgs, deps: HlDeps): Promise<Prepared | Result>;
96
+ export declare function prepareCancel(a: LiveArgs & {
97
+ coin: string;
98
+ oid: string;
99
+ }, deps: HlDeps): Promise<Prepared | Result>;
100
+ export declare function prepareTransfer(a: LiveArgs & {
101
+ amount: string;
102
+ to?: string;
103
+ address?: string;
104
+ actor?: string;
105
+ }, deps: HlDeps): Promise<Prepared | Result>;
106
+ export declare function prepareWithdraw(a: LiveArgs & {
107
+ amount: string;
108
+ to?: string;
109
+ address?: string;
110
+ actor?: string;
111
+ }, deps: HlDeps, agentShell: boolean): Promise<Prepared | Result>;
112
+ /** Refuse BEFORE any vault opens — no Touch ID prompt for a run that cannot go on. */
113
+ export declare function liveGate(a: LiveArgs, deps: HlDeps): Result | null;
114
+ /** The plain-words line for userAbstraction: unified / portfolio accounts margin perps from spot. */
115
+ export declare function abstractionWords(ab: unknown): string;
116
+ export declare function runAction(verb: string, a: LiveArgs, prepare: () => Promise<Prepared | Result>, deps: HlDeps, o?: {
117
+ abstractionFor?: string | null;
118
+ }): Promise<Result>;
119
+ export {};