@agentgrant.cash/cli 1.0.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 (45) hide show
  1. package/.env.example +21 -0
  2. package/README.md +48 -0
  3. package/dist/cli/commands/agent.js +139 -0
  4. package/dist/cli/commands/auth.js +248 -0
  5. package/dist/cli/commands/meta.js +77 -0
  6. package/dist/cli/commands/money.js +85 -0
  7. package/dist/cli/commands/portfolio.js +224 -0
  8. package/dist/cli/index.js +94 -0
  9. package/dist/cli/money-helpers.js +189 -0
  10. package/dist/cli/perfolio-commands/account.js +272 -0
  11. package/dist/cli/perfolio-commands/borrow.js +75 -0
  12. package/dist/cli/perfolio-commands/discover.js +30 -0
  13. package/dist/cli/perfolio-commands/earn.js +193 -0
  14. package/dist/cli/perfolio-commands/hyperliquid.js +408 -0
  15. package/dist/cli/perfolio-commands/loans.js +34 -0
  16. package/dist/cli/perfolio-commands/market.js +76 -0
  17. package/dist/cli/perfolio-commands/polymarket.js +304 -0
  18. package/dist/cli/perfolio-commands/session.js +19 -0
  19. package/dist/cli/perfolio-commands/trade.js +94 -0
  20. package/dist/cli/perfolio-commands/tx.js +22 -0
  21. package/dist/lib/agent-client.js +166 -0
  22. package/dist/lib/agent-device.js +173 -0
  23. package/dist/lib/amounts.js +45 -0
  24. package/dist/lib/assets.js +47 -0
  25. package/dist/lib/client.js +284 -0
  26. package/dist/lib/config.js +46 -0
  27. package/dist/lib/context.js +35 -0
  28. package/dist/lib/currency.js +91 -0
  29. package/dist/lib/device.js +163 -0
  30. package/dist/lib/errors.js +59 -0
  31. package/dist/lib/format.js +22 -0
  32. package/dist/lib/index.js +24 -0
  33. package/dist/lib/kyc-status.js +28 -0
  34. package/dist/lib/money-client.js +157 -0
  35. package/dist/lib/money-input.js +176 -0
  36. package/dist/lib/output.js +45 -0
  37. package/dist/lib/polygon-balance.js +125 -0
  38. package/dist/lib/portfolio-format.js +224 -0
  39. package/dist/lib/relay.js +19 -0
  40. package/dist/lib/sign.js +29 -0
  41. package/dist/lib/tx-wait.js +35 -0
  42. package/dist/lib/types.js +10 -0
  43. package/dist/lib/verify.js +38 -0
  44. package/package.json +37 -0
  45. package/skills/grant-cash/SKILL.md +152 -0
@@ -0,0 +1,38 @@
1
+ /** Terminal backend states. (Source: backend TxStatus = submitted|processing|executing|success|failed.) */
2
+ const TERMINAL = new Set(['success', 'failed']);
3
+ /**
4
+ * After a session-key write, never trust "submitted". Poll the authoritative
5
+ * per-tx status endpoint (which re-checks the MEE explorer for non-terminal
6
+ * states) for THIS exact txHash until it reaches success/failed or we time out.
7
+ *
8
+ * Correlating by txHash is essential: reading "the latest history row" can
9
+ * confirm a different transaction. MEE/cross-chain settlement can take a while,
10
+ * so the timeout is generous.
11
+ */
12
+ export async function waitForTx(client, txHash, opts = {}) {
13
+ if (!txHash)
14
+ return { status: 'timeout' };
15
+ const timeout = opts.timeoutMs ?? 180_000; // 3 min — MEE/cross-chain headroom
16
+ const interval = opts.intervalMs ?? 4_000;
17
+ // A just-submitted tx isn't queryable for a beat (the DB row commits slightly
18
+ // after the submit response). Wait once up front so the FIRST poll doesn't 404
19
+ // — the backend logs every 404 as a client-error warning otherwise.
20
+ const initialDelay = opts.initialDelayMs ?? 2_500;
21
+ const start = Date.now();
22
+ let last;
23
+ if (initialDelay > 0)
24
+ await new Promise((r) => setTimeout(r, initialDelay));
25
+ while (Date.now() - start < timeout) {
26
+ try {
27
+ last = await client.getTxStatus(txHash);
28
+ if (last && TERMINAL.has(last.status)) {
29
+ return { status: last.status, txHash, receipt: last.receipt };
30
+ }
31
+ }
32
+ catch {
33
+ // 404 right after submit (row not indexed yet) or a transient blip — keep polling.
34
+ }
35
+ await new Promise((r) => setTimeout(r, interval));
36
+ }
37
+ return { status: last?.status === 'failed' ? 'failed' : 'timeout', txHash, receipt: last?.receipt };
38
+ }
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@agentgrant.cash/cli",
3
+ "version": "1.0.0",
4
+ "description": "Grant Cash — one CLI for your money (gold) and your agent (pay-per-use services). Routes to the Perfolio backend and the Agent-mode backend behind a single, plain-language surface.",
5
+ "type": "module",
6
+ "bin": {
7
+ "grant": "./dist/cli/index.js"
8
+ },
9
+ "files": [
10
+ "dist",
11
+ "skills",
12
+ ".env.example",
13
+ "README.md"
14
+ ],
15
+ "scripts": {
16
+ "build": "rm -rf dist && tsc",
17
+ "dev": "tsx src/cli/index.ts",
18
+ "start": "node dist/cli/index.js",
19
+ "typecheck": "tsc --noEmit",
20
+ "test": "vitest run",
21
+ "test:watch": "vitest",
22
+ "prepublishOnly": "npm run build"
23
+ },
24
+ "engines": {
25
+ "node": ">=20"
26
+ },
27
+ "dependencies": {
28
+ "commander": "^12.1.0",
29
+ "picocolors": "^1.1.1"
30
+ },
31
+ "devDependencies": {
32
+ "@types/node": "^22.10.0",
33
+ "tsx": "^4.19.2",
34
+ "typescript": "^5.7.2",
35
+ "vitest": "^2.1.8"
36
+ }
37
+ }
@@ -0,0 +1,152 @@
1
+ ---
2
+ name: grant-cash
3
+ description: One assistant for your money — Grant Cash. Grow and hold money (gold, bitcoin, ethereum, cash, borrowing, earning yield, leveraged trading, prediction markets) and spend it (have your agent find and pay for live services, send money) — all in plain language, one sign-in. Check your worth, invest, cash out, and manage spending limits without any jargon, keys, or addresses.
4
+ ---
5
+
6
+ # Grant Cash
7
+
8
+ Grant Cash is **one** assistant for your money. There is only ever one Grant Cash — one sign-in, one combined worth, one history. Inside it, money does two things:
9
+
10
+ - **Investments** — grow and hold money. Hold gold, bitcoin, ethereum and cash; borrow cash against what you hold; earn yield; trade with leverage; and bet on real-world outcomes (prediction markets). All valued in your own currency.
11
+ - **Spending** — get things done. Your agent finds and pays for live services on demand (search the web, read the news, research a company, generate images, and more), and you can send money. It pays a few cents only when it actually does something, inside the limits you set.
12
+
13
+ These are **two sides of the same Grant Cash account**, not two separate apps or services. `grant portfolio` shows both together: an **Investments** section and a **Spending** section. The user never deals with anything technical — no jargon, no keys, no addresses, no chains. **Money can only ever come back to the user.** `grant revoke` stops all agent spending instantly.
14
+
15
+ > Note for assistants: do **not** describe this as a "portfolio service" plus an "agent service", and never mention internal system names. It is one product — Grant Cash — with an Investments side and a Spending side. Speak plainly: gold, cash, bitcoin, ethereum, "your worth", "spending money".
16
+
17
+ ## Output (for assistants driving this CLI)
18
+
19
+ - Output is **JSON** when stdout is not a TTY (you captured it) or with `--json`; pretty for people otherwise.
20
+ - Success → `{"ok":true, ...}`. Failure → `{"ok":false,"error":{"code","message","recoverable"}}`.
21
+ - `recoverable:true` → safe to retry. `recoverable:false` → STOP; don't retry blindly.
22
+
23
+ ## Money amounts (important)
24
+
25
+ Every **cash** amount is in the user's display currency — a bare `50` means ₹50 for an INR user, $50 for a USD user. Force a currency by prefixing: `"$50"`, `"₹100"`, `"100 EUR"`. This applies everywhere cash is entered: `buy --amount`, `borrow --amount`, prediction bets/deposits, `withdraw`, and so on. Asset *quantities* (e.g. `sell bitcoin --amount 0.1`) are not currency.
26
+
27
+ ## Workflow
28
+
29
+ 1. `grant status` — confirm you're connected (both Investments and Spending).
30
+ 2. `grant portfolio` — combined worth: the Investments side (gold, cash, bitcoin, ethereum, leveraged positions, prediction balance, earnings) and the Spending side, in one place.
31
+ 3. Invest: `grant prices`, then `grant buy <asset> --amount <cash>` / `grant sell <asset> --for <cash>`.
32
+ 4. Spend: `grant search "<q>"` → `grant check <url>` (no charge) → `grant fetch <url> -b '<json>'`.
33
+ 5. `grant activity` — one feed of everything that's happened, newest first.
34
+ 6. `grant revoke` — stop all agent spending immediately.
35
+
36
+ ## Commands
37
+
38
+ ### Connect (one sign-in for the whole account)
39
+ - `grant login` — sign in and approve your spending limits in the browser; connects both Investments and Spending in one step.
40
+ - `grant logout` — sign out and clear what's stored on this machine.
41
+ - `grant status` (alias `whoami`) — show what's connected and where.
42
+ - `grant devices list` — list the agents/devices connected to your account.
43
+ - `grant devices revoke <deviceId>` — disconnect one device.
44
+
45
+ ### Your worth
46
+ - `grant portfolio` (alias `balance`) — combined worth: Investments + Spending, in your currency. Includes gold, cash, bitcoin, ethereum, leveraged positions, your prediction balance and open bets, and anything you're earning.
47
+ - `grant prices` — current prices for gold, bitcoin, ethereum, cash.
48
+ - `grant price` (alias `gold`) — today's gold price.
49
+ - `grant assets` — what you can hold. `grant markets` — what you can borrow against. `grant rate [--against <asset>]` — the current borrow rate.
50
+ - `grant activity` (alias `history`) — everything that's happened, newest first.
51
+
52
+ ### Investments — buy, sell, convert
53
+ - `grant buy <asset> --amount <cash>` — buy gold, bitcoin or ethereum with cash. (e.g. `grant buy gold --amount 50`)
54
+ - `grant sell <asset> --amount <qty>` or `--for <cash>` — sell by quantity or by cash value.
55
+ - `grant convert --from <asset> --to <asset> --amount <qty>|--for <cash>` — move directly between assets.
56
+ - `grant quote --from <asset> --to <asset> --amount <qty>|--for <cash>` — preview a trade, no execution.
57
+
58
+ ### Investments — borrow cash against what you hold
59
+ - `grant borrow --against <asset> --amount <cash>` — borrow cash against an asset.
60
+ - `grant repay --against <asset> --amount <cash>` — repay borrowed cash.
61
+ - `grant add-collateral --asset <asset> --amount <qty>` / `grant remove-collateral --asset <asset> --amount <qty>`.
62
+ - `grant leverage --asset <asset> --deposit <qty> --borrow <cash>` — add collateral and borrow in one step.
63
+ - `grant close --against <asset>` — repay everything and withdraw the collateral.
64
+ - `grant loans` — your open "cash borrowed against X" positions. `grant position --against <asset>` — detail for one.
65
+
66
+ ### Investments — earn yield
67
+ - `grant earn list [--asset <asset>]` — vaults with current rates and size.
68
+ - `grant earn position --asset <asset>` — what you have staked, plus earnings.
69
+ - `grant earn deposit --asset <asset> --amount <n>` (alias `open`) — start or add to an earning position.
70
+ - `grant earn withdraw --asset <asset> [--amount <n> | --all]` — take money back out.
71
+
72
+ ### Investments — trade with leverage (long or short, many markets)
73
+ - `grant hl markets [--search <q>]` — discover what you can trade (stocks, crypto, commodities, fx, indices).
74
+ - `grant hl status` / `grant hl positions` / `grant hl orders` / `grant hl history` — your trading state.
75
+ - `grant hl price [--asset <symbol>]` — live price for a market.
76
+ - `grant hl setup [--fund <cash>]` — turn on leveraged trading (one-time, funds first if needed).
77
+ - `grant hl deposit --amount <cash>` / `grant hl withdraw --amount <cash>` — move cash in and out of trading.
78
+ - `grant hl open --side <long|short> --size <usd> --leverage <n> [--asset <symbol>]` — open a position.
79
+ - `grant hl close [--asset <symbol>]` — close a position.
80
+ - `grant hl leverage --set <n> [--isolated]` — set leverage.
81
+ - `grant hl tpsl --asset <symbol> --side <long|short> --size <n> [--tp <price>] [--sl <price>]` — take-profit / stop-loss.
82
+ - `grant hl cancel <orderId> [--asset <symbol>]` — cancel an order.
83
+
84
+ ### Investments — prediction markets (bet on real-world outcomes)
85
+ - `grant polymarket markets [--search <q>] [--limit <n>]` — browse or search markets.
86
+ - `grant polymarket wallet` — your **prediction balance** (cash available to bet) and readiness.
87
+ - `grant polymarket provision` — set up your prediction account (one-time, no signing).
88
+ - `grant polymarket deposit <cash>` — add cash to your prediction balance.
89
+ - `grant polymarket bet <marketId> --side <yes|no> --amount <cash> [--limit <price>]` — place a bet.
90
+ - `grant polymarket cashout <marketId> [--shares <n>]` — sell your shares before the market resolves.
91
+ - `grant polymarket redeem <marketId>` — claim winnings on a resolved market.
92
+ - `grant polymarket positions` — your open bets and totals. `grant polymarket history` — your prediction trades.
93
+ - `grant polymarket withdraw <cash>` — move cash from your prediction balance back to your account.
94
+ - `grant polymarket fund-status <requestId>` — check whether added funds have landed.
95
+
96
+ ### Investments — cash, identity, gifts
97
+ - `grant deposit` — your address for adding funds to your account.
98
+ - `grant kyc status` / `grant kyc start` — verify your identity (opens the browser).
99
+ - `grant fiat deposit [--currency <code>]` — bank-transfer details for adding cash. `grant fiat quote --amount <cash> --currency <code>` — a cash-out quote.
100
+ - `grant withdraw --to <address> --amount <cash>` — withdraw cash to an external wallet (browser approval).
101
+ - `grant gift send --to <email|phone> --amount <gold> [--message <text>]` — send a gold gift. `grant gifts` — gifts sent and received.
102
+ - `grant beneficiaries` — your payout bank accounts.
103
+ - `grant settings set [--currency <code>] [--country <code>] [--display <usd|local>] [--gold-unit <oz|g>] [--mode <simple|advanced>]` — preferences.
104
+
105
+ ### Spending — your agent gets things done
106
+ - `grant search "<query>" [--limit <n>]` (alias `marketplace`) — find a live service your agent can use.
107
+ - `grant discover <origin>` (alias `add`) — add any new service origin so its endpoints become findable.
108
+ - `grant check <url>` — see exactly what a service costs and needs, before paying (no charge).
109
+ - `grant schema <slug>` — the exact pay contract for a catalogued service (no charge).
110
+ - `grant fetch <url> [-m POST] [-b '<json>'] [--price <amount>] [--asset USDC|USDT]` (alias `pay`) — pay for and run a service.
111
+ - `grant transfer <recipient> <amount>` — send money to an address.
112
+ - `grant redeem <code>` — claim an invite or bonus credit toward spending.
113
+ - `grant upgrade` — get a one-time link to secure a full account and add spending funds.
114
+ - `grant revoke` (alias `stop`) — stop all agent spending immediately.
115
+
116
+ ### Transactions & self-orientation
117
+ - `grant tx status <txHash>` — check whether a transaction confirmed. `grant tx history [--limit <n>]` — recent transactions.
118
+ - `grant session status` / `grant session grant` — your agent-access (session) status and how to enable it.
119
+ - `grant instructions` — this workflow + how to recover from errors (machine-readable with `--json`).
120
+ - `grant config show` — where things route and what's connected. `grant install` — connect this to an AI assistant you already use.
121
+
122
+ ## When something goes wrong
123
+
124
+ | code | retry? | what to do |
125
+ |---|---|---|
126
+ | `NOT_CONNECTED` | no | Run `grant login`. |
127
+ | `NO_SESSION` | no | No spending permission set — `grant login` and approve your limits. |
128
+ | `GUARDRAIL_DENIED` | no | STOP. This is outside the limits the user set — don't retry. Tell the user. |
129
+ | `SIGNER_REVOKED` | no | STOP. Spending was stopped — re-authorize with `grant login`. |
130
+ | `SCHEMA_VALIDATION_FAILED` | yes | Free reject. Run `grant check <url>`, fix the `--body`, then retry. |
131
+ | `BACKEND_UNREACHABLE` | no | Wrong or unreachable address — check the connection with `grant config show`. |
132
+ | `NETWORK` | yes | Temporary — retry once. |
133
+
134
+ ## Examples
135
+
136
+ ```
137
+ grant status # are we connected?
138
+ grant portfolio # combined worth — Investments + Spending
139
+ grant prices # gold, bitcoin, ethereum, cash
140
+ grant buy gold --amount 50 # invest $50 in gold
141
+ grant sell bitcoin --for 100 # sell $100 of bitcoin
142
+ grant borrow --against gold --amount 200 # borrow $200 against gold
143
+ grant earn deposit --asset cash --amount 500 # earn yield on cash
144
+ grant hl open --side long --size 100 --leverage 3 --asset BTC # leveraged trade
145
+ grant polymarket markets --search election # browse prediction markets
146
+ grant polymarket bet 0x1234 --side yes --amount 25 # bet $25 on "yes"
147
+ grant search "web search" --limit 5 # find a live service (Spending)
148
+ grant check https://api.example.com/run # what it costs + needs, no charge
149
+ grant fetch https://api.example.com/run -b '{"q":"gold news today"}' # pay + run
150
+ grant activity --json # full combined history
151
+ grant revoke # stop all agent spending
152
+ ```