@upshiftfinance/cli 0.0.0-stage → 0.1.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 (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +185 -2
  3. package/lib/bin.d.ts +2 -0
  4. package/lib/bin.js +19 -0
  5. package/lib/commands/chain.d.ts +2 -0
  6. package/lib/commands/chain.js +42 -0
  7. package/lib/commands/config.d.ts +2 -0
  8. package/lib/commands/config.js +107 -0
  9. package/lib/commands/docs.d.ts +2 -0
  10. package/lib/commands/docs.js +407 -0
  11. package/lib/commands/init.d.ts +2 -0
  12. package/lib/commands/init.js +124 -0
  13. package/lib/commands/login.d.ts +2 -0
  14. package/lib/commands/login.js +57 -0
  15. package/lib/commands/ops.d.ts +2 -0
  16. package/lib/commands/ops.js +149 -0
  17. package/lib/commands/points.d.ts +2 -0
  18. package/lib/commands/points.js +52 -0
  19. package/lib/commands/profile.d.ts +2 -0
  20. package/lib/commands/profile.js +82 -0
  21. package/lib/commands/rpc.d.ts +11 -0
  22. package/lib/commands/rpc.js +93 -0
  23. package/lib/commands/skill.d.ts +2 -0
  24. package/lib/commands/skill.js +83 -0
  25. package/lib/commands/user.d.ts +2 -0
  26. package/lib/commands/user.js +93 -0
  27. package/lib/commands/vault.d.ts +2 -0
  28. package/lib/commands/vault.js +326 -0
  29. package/lib/commands/whoami.d.ts +2 -0
  30. package/lib/commands/whoami.js +45 -0
  31. package/lib/index.d.ts +2 -0
  32. package/lib/index.js +9 -0
  33. package/lib/lib/flags.d.ts +14 -0
  34. package/lib/lib/flags.js +46 -0
  35. package/lib/lib/output.d.ts +7 -0
  36. package/lib/lib/output.js +218 -0
  37. package/lib/lib/prompts.d.ts +24 -0
  38. package/lib/lib/prompts.js +51 -0
  39. package/lib/lib/resolve-vault.d.ts +10 -0
  40. package/lib/lib/resolve-vault.js +137 -0
  41. package/lib/lib/version.d.ts +2 -0
  42. package/lib/lib/version.js +27 -0
  43. package/lib/lib/watch.d.ts +4 -0
  44. package/lib/lib/watch.js +38 -0
  45. package/lib/main.d.ts +3 -0
  46. package/lib/main.js +55 -0
  47. package/lib/notify-update.d.ts +1 -0
  48. package/lib/notify-update.js +38 -0
  49. package/package.json +67 -3
  50. package/skills/upshift.md +212 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 August Digital
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,186 @@
1
- # Temporary Holding Version
1
+ # `@upshiftfinance/cli`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The `upshift` command — a read-only CLI over the Upshift SDK.
4
+ Inspect vault APY, TVL, positions, redemptions, and user points across
5
+ EVM, Solana, and Stellar without writing TypeScript.
6
+
7
+ Read-only by design. There are no signing or write commands.
8
+
9
+ ## Install
10
+
11
+ ```sh
12
+ npm install -g @upshiftfinance/cli
13
+ ```
14
+
15
+ Or run without installing:
16
+
17
+ ```sh
18
+ npx -y @upshiftfinance/cli --help
19
+ ```
20
+
21
+ ## Quickstart
22
+
23
+ ```sh
24
+ upshift init # one-time setup
25
+ upshift whoami # confirm config + API key status
26
+ upshift vault apy 0xVault --chain 8453 # current APY (human output)
27
+ upshift vault apy eth-coreusdc # same call, by name
28
+ upshift vault apy 0xVault --chain 8453 --json | jq .data.currentApy
29
+ ```
30
+
31
+ ## Config layout
32
+
33
+ `upshift init` writes:
34
+
35
+ ```
36
+ ~/.upshift/
37
+ ├── config.json # default chain, RPCs, profile, telemetry
38
+ ├── keystore.json # AES-256-GCM; holds your Upshift API key (optional)
39
+ ├── .session # mode 0600; decrypted API key + expiry
40
+ └── profiles/ # named overlays for chain + RPC sets
41
+ ```
42
+
43
+ Override the root with `UPSHIFT_CONFIG_DIR=…`.
44
+
45
+ ## Auth
46
+
47
+ If you stored an API key during `init`, run `upshift login` once per
48
+ shell to unlock the keystore. Subsequent commands read from `.session`
49
+ until it expires (default 1h, set `config.auth.sessionTtlSec`).
50
+ `upshift logout` clears it.
51
+
52
+ In CI, either set `UPSHIFT_PASSPHRASE` (so `login` runs non-interactively)
53
+ or skip the keystore entirely and use `UPSHIFT_API_KEY`. Env vars always
54
+ win over the session.
55
+
56
+ ## Global flags
57
+
58
+ | Flag | Purpose |
59
+ | --------------------- | ------------------------------------------ |
60
+ | `--json` | Stable JSON envelope on stdout. |
61
+ | `--csv` | CSV output (tabular commands only). |
62
+ | `--chain <id>` | Chain id for this call. |
63
+ | `--rpc <url>` | RPC URL override (pair with `--chain`). |
64
+ | `--profile <name>` | Named profile to activate. |
65
+ | `--no-color` | Disable ANSI colors. |
66
+ | `--verbose` | Diagnostics on stderr. |
67
+ | `--config-dir <path>` | Override `~/.upshift` for this call. |
68
+
69
+ ## Commands
70
+
71
+ | Group | Command |
72
+ | ----------- | ----------------------------------------------------------------------------------------- |
73
+ | Setup | `init`, `login`, `logout`, `whoami` |
74
+ | Config | `config get\|set\|list\|path` |
75
+ | Profiles | `profile create\|switch\|list\|delete` |
76
+ | Diagnostics | `chain list`, `rpc test [--chain <id>]` |
77
+ | Vault | `vault list\|get\|apy\|tvl\|positions\|loans\|allocations\|redemptions\|history\|summary` |
78
+ | User | `user points\|positions\|pnl --vault <addr-or-name>` |
79
+ | Skill | `skill install\|path` |
80
+
81
+ Run `upshift <command> --help` for per-command flags and examples.
82
+
83
+ ## Vault names
84
+
85
+ Every command that takes `<vault>` (and `user pnl --vault …`) accepts
86
+ either a raw address or a vault name:
87
+
88
+ ```sh
89
+ upshift vault list # discover known names per chain
90
+ upshift vault tvl coreusdc # bare symbol, chain inferred
91
+ upshift vault tvl eth-coreusdc # explicit chain prefix
92
+ upshift vault tvl 0xE9B7…32 --chain 1 # raw address (unchanged)
93
+ ```
94
+
95
+ Chain prefixes accepted: `eth`/`mainnet`, `base`, `arb`/`arbitrum`,
96
+ `op`/`optimism`, `avax`/`avalanche`, `bsc`/`bnb`, `polygon`/`matic`,
97
+ `hyperevm`/`hyper`, `monad`, `mezo`, `plasma`, `ink`, `flare`.
98
+
99
+ If a bare name matches multiple chains, the CLI returns
100
+ `VAULT_NAME_AMBIGUOUS`; either prefix the name or pass `--chain`.
101
+ Names come from the upshift metadata endpoint and are cached in-process
102
+ for 10 minutes — addresses always work without a network call.
103
+
104
+ ## Recipes
105
+
106
+ ```sh
107
+ # Inspect a vault
108
+ upshift vault summary 0xVault --chain 8453
109
+ upshift vault apy 0xVault --chain 8453 --json | jq .data.currentApy
110
+
111
+ # Wallet's positions across all Upshift vaults
112
+ upshift user positions 0xWallet --json \
113
+ | jq '.data.positions[] | {vault, chainId, shares}'
114
+
115
+ # Lifetime PnL for a wallet in one vault
116
+ upshift user pnl 0xWallet --vault 0xVault --chain 1
117
+
118
+ # Diagnose a flaky RPC
119
+ upshift rpc test --json
120
+
121
+ # Per-call RPC override (no config change)
122
+ UPSHIFT_RPC_8453=https://my-rpc.example/v1 upshift vault tvl 0xVault --chain 8453
123
+
124
+ # Environment-specific config
125
+ upshift profile create staging --chain 8453
126
+ upshift profile switch staging
127
+ upshift config set rpcs.8453 https://staging-rpc.example/v1
128
+ ```
129
+
130
+ ## Claude Code skill
131
+
132
+ Ships with a Claude Code skill that teaches Claude how to call the CLI
133
+ and the companion MCP server:
134
+
135
+ ```sh
136
+ upshift skill install
137
+ # → ~/.claude/skills/upshift.md
138
+ ```
139
+
140
+ Override the destination with `--dest <dir>` (or `CLAUDE_SKILLS_DIR`).
141
+ Pass `--force` to overwrite a divergent file.
142
+
143
+ ## JSON envelope
144
+
145
+ Every `--json` response uses the same envelope as
146
+ [`@upshiftfinance/mcp`](../mcp):
147
+
148
+ ```json
149
+ {
150
+ "schemaVersion": 1,
151
+ "command": "vault.apy",
152
+ "ok": true,
153
+ "data": { "address": "0x…", "chainId": 8453, "currentApy": 0.1234 },
154
+ "meta": { "chainId": 8453, "durationMs": 312, "generatedAt": "2026-05-17T…" }
155
+ }
156
+ ```
157
+
158
+ On failure: `ok: false`, `error: { code, message, remediation? }`. Match
159
+ on `error.code` — message text is not part of the contract.
160
+
161
+ ## Programmatic use
162
+
163
+ ```ts
164
+ import { buildProgram } from '@upshiftfinance/cli';
165
+
166
+ const program = buildProgram();
167
+ await program.parseAsync(['node', 'upshift', 'whoami', '--json']);
168
+ ```
169
+
170
+ `buildProgram()` returns the same commander tree the binary uses, so
171
+ embedders (tests, MCP servers, internal tooling) can drive the CLI
172
+ without spawning a child process.
173
+
174
+ ## Exit codes
175
+
176
+ | Code | Meaning |
177
+ | ---- | --------------------------------------------------------------------------------------------------------------------------- |
178
+ | 0 | Success — and for `ops` commands, no anomalies. |
179
+ | 1 | Execution error (bad input, network failure, unresolved vault). The `--json` envelope carries `error.code` + `remediation`. |
180
+ | 2 | `ops health` / `ops redemptions` completed but found anomalies (`data.anomalies > 0`). Cron on a non-zero exit to alert. |
181
+
182
+ ## Watch mode
183
+
184
+ `points leaderboard`, `vault pending-redemptions`, `ops health`, and
185
+ `ops redemptions` accept `--watch <seconds>`. Human output re-renders in
186
+ place; `--json` emits one envelope per tick (NDJSON) for piping.
package/lib/bin.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/lib/bin.js ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const config_1 = require("@upshiftfinance/config");
5
+ const sdk_1 = require("@upshiftfinance/sdk");
6
+ const main_1 = require("./main");
7
+ const notify_update_1 = require("./notify-update");
8
+ (0, notify_update_1.notifyOfUpdate)();
9
+ (0, sdk_1.initializeSentry)({ enabled: true, surface: 'cli' }, (0, config_1.resolveUpshiftEnv)(), 'upshift-cli');
10
+ (0, main_1.main)().catch(async (err) => {
11
+ const msg = err instanceof Error ? err.message : String(err);
12
+ process.stderr.write(`upshift: ${msg}\n`);
13
+ await (0, sdk_1.captureSdkException)(err, {
14
+ surface: 'cli',
15
+ flushTimeoutMs: 2000,
16
+ });
17
+ process.exit(1);
18
+ });
19
+ //# sourceMappingURL=bin.js.map
@@ -0,0 +1,2 @@
1
+ import type { Command } from 'commander';
2
+ export declare function registerChain(program: Command): void;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerChain = registerChain;
4
+ const config_1 = require("@upshiftfinance/config");
5
+ const flags_1 = require("../lib/flags");
6
+ const output_1 = require("../lib/output");
7
+ const SUPPORTED_CHAINS = [
8
+ { chainId: 1, name: 'Ethereum', explorer: 'https://etherscan.io' },
9
+ {
10
+ chainId: 10,
11
+ name: 'Optimism',
12
+ explorer: 'https://optimistic.etherscan.io',
13
+ },
14
+ { chainId: 56, name: 'BNB Smart Chain', explorer: 'https://bscscan.com' },
15
+ { chainId: 137, name: 'Polygon', explorer: 'https://polygonscan.com' },
16
+ { chainId: 999, name: 'HyperEVM', explorer: 'https://hyperevmscan.io' },
17
+ { chainId: 8453, name: 'Base', explorer: 'https://basescan.org' },
18
+ { chainId: 42161, name: 'Arbitrum One', explorer: 'https://arbiscan.io' },
19
+ { chainId: 43114, name: 'Avalanche', explorer: 'https://snowscan.xyz' },
20
+ ];
21
+ function registerChain(program) {
22
+ const chain = program.command('chain').description('Supported chains');
23
+ chain
24
+ .command('list')
25
+ .description('List supported chains and whether an RPC is configured')
26
+ .action(async function () {
27
+ const flags = (0, flags_1.readGlobalFlags)(this);
28
+ await (0, output_1.runCommand)('chain.list', config_1.schemas.ChainListSchema, flags, async () => {
29
+ const cfg = (0, config_1.loadConfig)();
30
+ const envSet = new Set(Object.keys((0, config_1.readRpcEnvEntries)()).map(Number));
31
+ return {
32
+ chains: SUPPORTED_CHAINS.map((c) => ({
33
+ chainId: c.chainId,
34
+ name: c.name,
35
+ explorer: c.explorer,
36
+ hasRpc: envSet.has(c.chainId) || Boolean(cfg.rpcs?.[String(c.chainId)]),
37
+ })),
38
+ };
39
+ });
40
+ });
41
+ }
42
+ //# sourceMappingURL=chain.js.map
@@ -0,0 +1,2 @@
1
+ import type { Command } from 'commander';
2
+ export declare function registerConfig(program: Command): void;
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerConfig = registerConfig;
4
+ const zod_1 = require("zod");
5
+ const config_1 = require("@upshiftfinance/config");
6
+ const flags_1 = require("../lib/flags");
7
+ const output_1 = require("../lib/output");
8
+ const ConfigGetOutput = zod_1.z.object({
9
+ key: zod_1.z.string(),
10
+ value: zod_1.z.unknown(),
11
+ });
12
+ const ConfigSetOutput = zod_1.z.object({
13
+ key: zod_1.z.string(),
14
+ value: zod_1.z.unknown(),
15
+ ok: zod_1.z.literal(true),
16
+ });
17
+ const ConfigListOutput = zod_1.z.object({
18
+ config: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()),
19
+ });
20
+ const ConfigPathOutput = zod_1.z.object({ path: zod_1.z.string() });
21
+ function getByPath(obj, path) {
22
+ const segments = path.split('.');
23
+ let cursor = obj;
24
+ for (const seg of segments) {
25
+ if (cursor === null || typeof cursor !== 'object')
26
+ return undefined;
27
+ cursor = cursor[seg];
28
+ }
29
+ return cursor;
30
+ }
31
+ function setByPath(base, path, value) {
32
+ const segments = path.split('.');
33
+ const out = { ...base };
34
+ let cursor = out;
35
+ for (let i = 0; i < segments.length - 1; i += 1) {
36
+ const seg = segments[i];
37
+ const next = cursor[seg];
38
+ cursor[seg] =
39
+ next && typeof next === 'object' ? { ...next } : {};
40
+ cursor = cursor[seg];
41
+ }
42
+ cursor[segments[segments.length - 1]] = value;
43
+ return out;
44
+ }
45
+ function coerce(raw) {
46
+ if (raw === 'true')
47
+ return true;
48
+ if (raw === 'false')
49
+ return false;
50
+ if (raw === 'null')
51
+ return null;
52
+ if (/^-?\d+(\.\d+)?$/.test(raw))
53
+ return Number(raw);
54
+ try {
55
+ return JSON.parse(raw);
56
+ }
57
+ catch {
58
+ return raw;
59
+ }
60
+ }
61
+ function registerConfig(program) {
62
+ const config = program
63
+ .command('config')
64
+ .description('Read or modify ~/.upshift/config.json');
65
+ config
66
+ .command('get <key>')
67
+ .description('Read a value by dot-path (e.g. `defaultChainId`, `rpcs.1`)')
68
+ .action(async function (key) {
69
+ const flags = (0, flags_1.readGlobalFlags)(this);
70
+ await (0, output_1.runCommand)('config.get', ConfigGetOutput, flags, async () => {
71
+ const cfg = (0, config_1.loadConfig)();
72
+ return { key, value: getByPath(cfg, key) };
73
+ });
74
+ });
75
+ config
76
+ .command('set <key> <value>')
77
+ .description('Write a value by dot-path (coerces JSON, numbers, booleans)')
78
+ .action(async function (key, raw) {
79
+ const flags = (0, flags_1.readGlobalFlags)(this);
80
+ await (0, output_1.runCommand)('config.set', ConfigSetOutput, flags, async () => {
81
+ const cfg = (0, config_1.loadConfig)();
82
+ const value = coerce(raw);
83
+ const merged = setByPath(cfg, key, value);
84
+ (0, config_1.saveConfig)(merged);
85
+ return { key, value, ok: true };
86
+ });
87
+ });
88
+ config
89
+ .command('list')
90
+ .description('Print the full config')
91
+ .action(async function () {
92
+ const flags = (0, flags_1.readGlobalFlags)(this);
93
+ await (0, output_1.runCommand)('config.list', ConfigListOutput, flags, async () => {
94
+ return { config: (0, config_1.loadConfig)() };
95
+ });
96
+ });
97
+ config
98
+ .command('path')
99
+ .description('Print the absolute path of the config file')
100
+ .action(async function () {
101
+ const flags = (0, flags_1.readGlobalFlags)(this);
102
+ await (0, output_1.runCommand)('config.path', ConfigPathOutput, flags, async () => ({
103
+ path: (0, config_1.configFile)(),
104
+ }));
105
+ });
106
+ }
107
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1,2 @@
1
+ import type { Command } from 'commander';
2
+ export declare function registerDocs(program: Command): void;