@upshiftfinance/cli 0.0.0-stage → 0.1.2
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/LICENSE +21 -0
- package/README.md +185 -2
- package/lib/bin.d.ts +2 -0
- package/lib/bin.js +19 -0
- package/lib/commands/chain.d.ts +2 -0
- package/lib/commands/chain.js +42 -0
- package/lib/commands/config.d.ts +2 -0
- package/lib/commands/config.js +107 -0
- package/lib/commands/docs.d.ts +2 -0
- package/lib/commands/docs.js +407 -0
- package/lib/commands/init.d.ts +2 -0
- package/lib/commands/init.js +124 -0
- package/lib/commands/login.d.ts +2 -0
- package/lib/commands/login.js +57 -0
- package/lib/commands/ops.d.ts +2 -0
- package/lib/commands/ops.js +149 -0
- package/lib/commands/points.d.ts +2 -0
- package/lib/commands/points.js +52 -0
- package/lib/commands/profile.d.ts +2 -0
- package/lib/commands/profile.js +82 -0
- package/lib/commands/rpc.d.ts +11 -0
- package/lib/commands/rpc.js +93 -0
- package/lib/commands/skill.d.ts +2 -0
- package/lib/commands/skill.js +83 -0
- package/lib/commands/user.d.ts +2 -0
- package/lib/commands/user.js +93 -0
- package/lib/commands/vault.d.ts +2 -0
- package/lib/commands/vault.js +326 -0
- package/lib/commands/whoami.d.ts +2 -0
- package/lib/commands/whoami.js +45 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +9 -0
- package/lib/lib/flags.d.ts +14 -0
- package/lib/lib/flags.js +46 -0
- package/lib/lib/output.d.ts +7 -0
- package/lib/lib/output.js +218 -0
- package/lib/lib/prompts.d.ts +24 -0
- package/lib/lib/prompts.js +51 -0
- package/lib/lib/resolve-vault.d.ts +10 -0
- package/lib/lib/resolve-vault.js +137 -0
- package/lib/lib/version.d.ts +2 -0
- package/lib/lib/version.js +27 -0
- package/lib/lib/watch.d.ts +4 -0
- package/lib/lib/watch.js +38 -0
- package/lib/main.d.ts +3 -0
- package/lib/main.js +55 -0
- package/lib/notify-update.d.ts +1 -0
- package/lib/notify-update.js +38 -0
- package/package.json +66 -3
- package/skills/upshift.md +212 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerOps = registerOps;
|
|
4
|
+
const config_1 = require("@upshiftfinance/config");
|
|
5
|
+
const flags_1 = require("../lib/flags");
|
|
6
|
+
const resolve_vault_1 = require("../lib/resolve-vault");
|
|
7
|
+
const watch_1 = require("../lib/watch");
|
|
8
|
+
const rpc_1 = require("./rpc");
|
|
9
|
+
const RPC_TIMEOUT_MS = 5000;
|
|
10
|
+
function resolveChain(flags) {
|
|
11
|
+
return (0, config_1.getDefaultChainId)({
|
|
12
|
+
cliRpcChainId: flags.chain,
|
|
13
|
+
profileName: flags.profile,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
async function buildSdk(flags, chainId) {
|
|
17
|
+
return (0, config_1.createSDK)({
|
|
18
|
+
profileName: flags.profile,
|
|
19
|
+
chainId,
|
|
20
|
+
cliRpcUrl: flags.rpc,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
function errMessage(err) {
|
|
24
|
+
return err instanceof Error ? err.message : String(err);
|
|
25
|
+
}
|
|
26
|
+
function redemptionFlags(summary) {
|
|
27
|
+
const flags = [];
|
|
28
|
+
if (summary.isOverdue)
|
|
29
|
+
flags.push('overdue');
|
|
30
|
+
if (!summary.isLiquiditySufficient)
|
|
31
|
+
flags.push('insufficient-liquidity');
|
|
32
|
+
return flags;
|
|
33
|
+
}
|
|
34
|
+
async function runVaultChecks(flags, vaultInputs) {
|
|
35
|
+
if (vaultInputs.length === 0)
|
|
36
|
+
return [];
|
|
37
|
+
const checks = [];
|
|
38
|
+
for (const input of vaultInputs) {
|
|
39
|
+
const resolved = await (0, resolve_vault_1.resolveVault)(input, resolveChain(flags));
|
|
40
|
+
const sdk = await buildSdk(flags, resolved.chainId);
|
|
41
|
+
try {
|
|
42
|
+
sdk.switchNetwork(resolved.chainId);
|
|
43
|
+
await sdk.vaultsModule.getVaultSummary(resolved.address);
|
|
44
|
+
checks.push({
|
|
45
|
+
kind: 'vault_summary',
|
|
46
|
+
target: resolved.address,
|
|
47
|
+
ok: true,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
checks.push({
|
|
52
|
+
kind: 'vault_summary',
|
|
53
|
+
target: resolved.address,
|
|
54
|
+
ok: false,
|
|
55
|
+
detail: errMessage(err),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
const queue = await sdk.vaultsModule.getVaultPendingRedemptions({
|
|
60
|
+
vault: resolved.address,
|
|
61
|
+
});
|
|
62
|
+
const anomalyFlags = redemptionFlags(queue.summary);
|
|
63
|
+
checks.push({
|
|
64
|
+
kind: 'redemptions',
|
|
65
|
+
target: resolved.address,
|
|
66
|
+
ok: anomalyFlags.length === 0,
|
|
67
|
+
detail: anomalyFlags.length > 0 ? anomalyFlags.join('; ') : undefined,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
checks.push({
|
|
72
|
+
kind: 'redemptions',
|
|
73
|
+
target: resolved.address,
|
|
74
|
+
ok: false,
|
|
75
|
+
detail: errMessage(err),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return checks;
|
|
80
|
+
}
|
|
81
|
+
function registerOps(program) {
|
|
82
|
+
const ops = program
|
|
83
|
+
.command('ops')
|
|
84
|
+
.description('Operational health checks. Exit code: 0 all clear, 1 execution error, 2 anomalies found.');
|
|
85
|
+
ops
|
|
86
|
+
.command('health')
|
|
87
|
+
.description('Cross-chain sweep: RPC reachability for every configured chain, plus vault summary availability and redemption-queue health for each --vault')
|
|
88
|
+
.option('--vault <address-or-name...>', 'vault(s) to check (address or name)')
|
|
89
|
+
.option('--watch <seconds>', 'poll and re-render every N seconds')
|
|
90
|
+
.action(async function () {
|
|
91
|
+
const flags = (0, flags_1.readGlobalFlags)(this);
|
|
92
|
+
const opts = this.opts();
|
|
93
|
+
let lastAnomalies = 0;
|
|
94
|
+
await (0, watch_1.runWatched)('ops.health', config_1.schemas.OpsHealthSchema, flags, opts.watch, async () => {
|
|
95
|
+
const targets = (0, rpc_1.collectTargets)(flags.chain);
|
|
96
|
+
const rpcChecks = await Promise.all(targets.map(async ({ chainId, url }) => {
|
|
97
|
+
const probed = await (0, rpc_1.probeRpc)(chainId, url, RPC_TIMEOUT_MS);
|
|
98
|
+
return {
|
|
99
|
+
kind: 'rpc',
|
|
100
|
+
target: `chain ${chainId}`,
|
|
101
|
+
ok: probed.ok,
|
|
102
|
+
detail: probed.error,
|
|
103
|
+
latencyMs: probed.latencyMs,
|
|
104
|
+
};
|
|
105
|
+
}));
|
|
106
|
+
const vaultChecks = await runVaultChecks(flags, opts.vault ?? []);
|
|
107
|
+
const checks = [...rpcChecks, ...vaultChecks];
|
|
108
|
+
const anomalies = checks.filter((c) => !c.ok).length;
|
|
109
|
+
lastAnomalies = anomalies;
|
|
110
|
+
return { checks, anomalies };
|
|
111
|
+
});
|
|
112
|
+
if (lastAnomalies > 0 && process.exitCode === undefined) {
|
|
113
|
+
process.exitCode = 2;
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
ops
|
|
117
|
+
.command('redemptions <vault>')
|
|
118
|
+
.description('Redemption-queue health for one vault — flags overdue queues and insufficient liquidity')
|
|
119
|
+
.option('--watch <seconds>', 'poll and re-render every N seconds')
|
|
120
|
+
.action(async function (vaultInput) {
|
|
121
|
+
const flags = (0, flags_1.readGlobalFlags)(this);
|
|
122
|
+
const opts = this.opts();
|
|
123
|
+
let lastAnomalies = 0;
|
|
124
|
+
await (0, watch_1.runWatched)('ops.redemptions', config_1.schemas.OpsRedemptionsSchema, flags, opts.watch, async () => {
|
|
125
|
+
const resolved = await (0, resolve_vault_1.resolveVault)(vaultInput, resolveChain(flags));
|
|
126
|
+
const sdk = await buildSdk(flags, resolved.chainId);
|
|
127
|
+
sdk.switchNetwork(resolved.chainId);
|
|
128
|
+
const queue = await sdk.vaultsModule.getVaultPendingRedemptions({
|
|
129
|
+
vault: resolved.address,
|
|
130
|
+
});
|
|
131
|
+
const anomalyFlags = redemptionFlags(queue.summary);
|
|
132
|
+
lastAnomalies = anomalyFlags.length;
|
|
133
|
+
return {
|
|
134
|
+
address: resolved.address,
|
|
135
|
+
chainId: resolved.chainId,
|
|
136
|
+
pendingCount: queue.summary.pendingCount,
|
|
137
|
+
totalPending: queue.summary.totalPending,
|
|
138
|
+
isLiquiditySufficient: queue.summary.isLiquiditySufficient,
|
|
139
|
+
isOverdue: queue.summary.isOverdue,
|
|
140
|
+
flags: anomalyFlags,
|
|
141
|
+
anomalies: anomalyFlags.length,
|
|
142
|
+
};
|
|
143
|
+
});
|
|
144
|
+
if (lastAnomalies > 0 && process.exitCode === undefined) {
|
|
145
|
+
process.exitCode = 2;
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=ops.js.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerPoints = registerPoints;
|
|
4
|
+
const config_1 = require("@upshiftfinance/config");
|
|
5
|
+
const flags_1 = require("../lib/flags");
|
|
6
|
+
const watch_1 = require("../lib/watch");
|
|
7
|
+
const SORT_FIELDS = ['streakDays', 'totalPoints'];
|
|
8
|
+
async function buildSdk(flags) {
|
|
9
|
+
return (0, config_1.createSDK)({
|
|
10
|
+
profileName: flags.profile,
|
|
11
|
+
chainId: (0, config_1.getDefaultChainId)({
|
|
12
|
+
cliRpcChainId: flags.chain,
|
|
13
|
+
profileName: flags.profile,
|
|
14
|
+
}),
|
|
15
|
+
cliRpcUrl: flags.rpc,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function registerPoints(program) {
|
|
19
|
+
const points = program
|
|
20
|
+
.command('points')
|
|
21
|
+
.description('Upshift points program');
|
|
22
|
+
points
|
|
23
|
+
.command('leaderboard')
|
|
24
|
+
.description('Points leaderboard, paginated')
|
|
25
|
+
.option('--page <n>', 'page number (1-based)', (v) => Number(v))
|
|
26
|
+
.option('--per-page <n>', 'items per page', (v) => Number(v))
|
|
27
|
+
.option('--sort-by <field>', 'streakDays or totalPoints')
|
|
28
|
+
.option('--watch <seconds>', 'poll and re-render every N seconds')
|
|
29
|
+
.action(async function () {
|
|
30
|
+
const flags = (0, flags_1.readGlobalFlags)(this);
|
|
31
|
+
const opts = this.opts();
|
|
32
|
+
await (0, watch_1.runWatched)('points.leaderboard', config_1.schemas.PointsLeaderboardSchema, flags, opts.watch, async () => {
|
|
33
|
+
if (opts.sortBy !== undefined &&
|
|
34
|
+
!SORT_FIELDS.includes(opts.sortBy)) {
|
|
35
|
+
throw new config_1.UpshiftConfigError('INVALID_INPUT', `--sort-by must be one of ${SORT_FIELDS.join(', ')}, got "${opts.sortBy}".`);
|
|
36
|
+
}
|
|
37
|
+
const chainId = (0, config_1.getDefaultChainId)({
|
|
38
|
+
cliRpcChainId: flags.chain,
|
|
39
|
+
profileName: flags.profile,
|
|
40
|
+
});
|
|
41
|
+
const sdk = await buildSdk(flags);
|
|
42
|
+
sdk.switchNetwork(chainId);
|
|
43
|
+
const raw = (await sdk.fetchPointsLeaderboard({
|
|
44
|
+
page: opts.page,
|
|
45
|
+
perPage: opts.perPage,
|
|
46
|
+
sortBy: opts.sortBy,
|
|
47
|
+
}));
|
|
48
|
+
return raw;
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=points.js.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerProfile = registerProfile;
|
|
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 ProfileListOutput = zod_1.z.object({
|
|
9
|
+
active: zod_1.z.string(),
|
|
10
|
+
profiles: zod_1.z.array(zod_1.z.string()),
|
|
11
|
+
});
|
|
12
|
+
const ProfileMutationOutput = zod_1.z.object({
|
|
13
|
+
name: zod_1.z.string(),
|
|
14
|
+
active: zod_1.z.string(),
|
|
15
|
+
ok: zod_1.z.literal(true),
|
|
16
|
+
});
|
|
17
|
+
function registerProfile(program) {
|
|
18
|
+
const profile = program
|
|
19
|
+
.command('profile')
|
|
20
|
+
.description('Switch between named config overlays');
|
|
21
|
+
profile
|
|
22
|
+
.command('create <name>')
|
|
23
|
+
.description('Create an empty profile')
|
|
24
|
+
.option('--chain <id>', 'default chain for the profile', (v) => Number(v))
|
|
25
|
+
.action(async function (name) {
|
|
26
|
+
const flags = (0, flags_1.readGlobalFlags)(this);
|
|
27
|
+
const opts = this.opts();
|
|
28
|
+
await (0, output_1.runCommand)('profile.create', ProfileMutationOutput, flags, async () => {
|
|
29
|
+
(0, config_1.saveProfile)({
|
|
30
|
+
schemaVersion: 1,
|
|
31
|
+
name,
|
|
32
|
+
defaultChainId: opts.chain,
|
|
33
|
+
rpcs: {},
|
|
34
|
+
});
|
|
35
|
+
const cfg = (0, config_1.loadConfig)();
|
|
36
|
+
return {
|
|
37
|
+
name,
|
|
38
|
+
active: cfg.defaultProfile,
|
|
39
|
+
ok: true,
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
profile
|
|
44
|
+
.command('switch <name>')
|
|
45
|
+
.description('Activate a profile')
|
|
46
|
+
.action(async function (name) {
|
|
47
|
+
const flags = (0, flags_1.readGlobalFlags)(this);
|
|
48
|
+
await (0, output_1.runCommand)('profile.switch', ProfileMutationOutput, flags, async () => {
|
|
49
|
+
(0, config_1.loadProfile)(name);
|
|
50
|
+
(0, config_1.saveConfig)({ defaultProfile: name });
|
|
51
|
+
return { name, active: name, ok: true };
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
profile
|
|
55
|
+
.command('list')
|
|
56
|
+
.description('List profiles')
|
|
57
|
+
.action(async function () {
|
|
58
|
+
const flags = (0, flags_1.readGlobalFlags)(this);
|
|
59
|
+
await (0, output_1.runCommand)('profile.list', ProfileListOutput, flags, async () => {
|
|
60
|
+
const cfg = (0, config_1.loadConfig)();
|
|
61
|
+
return {
|
|
62
|
+
active: cfg.defaultProfile,
|
|
63
|
+
profiles: (0, config_1.listProfiles)(),
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
profile
|
|
68
|
+
.command('delete <name>')
|
|
69
|
+
.description('Delete a profile (cannot delete the active one)')
|
|
70
|
+
.action(async function (name) {
|
|
71
|
+
const flags = (0, flags_1.readGlobalFlags)(this);
|
|
72
|
+
await (0, output_1.runCommand)('profile.delete', ProfileMutationOutput, flags, async () => {
|
|
73
|
+
const cfg = (0, config_1.loadConfig)();
|
|
74
|
+
if (cfg.defaultProfile === name) {
|
|
75
|
+
throw new Error(`Cannot delete the active profile "${name}". Run \`upshift profile switch <other>\` first.`);
|
|
76
|
+
}
|
|
77
|
+
(0, config_1.deleteProfile)(name);
|
|
78
|
+
return { name, active: cfg.defaultProfile, ok: true };
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=profile.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Command } from 'commander';
|
|
2
|
+
export declare function probeRpc(chainId: number, url: string, timeoutMs: number): Promise<{
|
|
3
|
+
ok: boolean;
|
|
4
|
+
latencyMs: number;
|
|
5
|
+
error?: string;
|
|
6
|
+
}>;
|
|
7
|
+
export declare function collectTargets(filterChain: number | undefined): {
|
|
8
|
+
chainId: number;
|
|
9
|
+
url: string;
|
|
10
|
+
}[];
|
|
11
|
+
export declare function registerRpc(program: Command): void;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.probeRpc = probeRpc;
|
|
4
|
+
exports.collectTargets = collectTargets;
|
|
5
|
+
exports.registerRpc = registerRpc;
|
|
6
|
+
const config_1 = require("@upshiftfinance/config");
|
|
7
|
+
const flags_1 = require("../lib/flags");
|
|
8
|
+
const output_1 = require("../lib/output");
|
|
9
|
+
const EVM_PROBE_BODY = JSON.stringify({
|
|
10
|
+
jsonrpc: '2.0',
|
|
11
|
+
id: 1,
|
|
12
|
+
method: 'eth_blockNumber',
|
|
13
|
+
params: [],
|
|
14
|
+
});
|
|
15
|
+
const SOLANA_PROBE_BODY = JSON.stringify({
|
|
16
|
+
jsonrpc: '2.0',
|
|
17
|
+
id: 1,
|
|
18
|
+
method: 'getSlot',
|
|
19
|
+
params: [],
|
|
20
|
+
});
|
|
21
|
+
const SOLANA_CHAIN_ID = -1;
|
|
22
|
+
async function probeRpc(chainId, url, timeoutMs) {
|
|
23
|
+
const start = Date.now();
|
|
24
|
+
const controller = new AbortController();
|
|
25
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
26
|
+
try {
|
|
27
|
+
const body = chainId === SOLANA_CHAIN_ID ? SOLANA_PROBE_BODY : EVM_PROBE_BODY;
|
|
28
|
+
const res = await fetch(url, {
|
|
29
|
+
method: 'POST',
|
|
30
|
+
headers: { 'content-type': 'application/json' },
|
|
31
|
+
body,
|
|
32
|
+
signal: controller.signal,
|
|
33
|
+
});
|
|
34
|
+
if (!res.ok) {
|
|
35
|
+
return {
|
|
36
|
+
ok: false,
|
|
37
|
+
latencyMs: Date.now() - start,
|
|
38
|
+
error: `HTTP ${res.status}`,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const json = (await res.json());
|
|
42
|
+
if (json.error) {
|
|
43
|
+
return {
|
|
44
|
+
ok: false,
|
|
45
|
+
latencyMs: Date.now() - start,
|
|
46
|
+
error: JSON.stringify(json.error),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return { ok: true, latencyMs: Date.now() - start };
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
return {
|
|
53
|
+
ok: false,
|
|
54
|
+
latencyMs: Date.now() - start,
|
|
55
|
+
error: err instanceof Error ? err.message : String(err),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
clearTimeout(timer);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function collectTargets(filterChain) {
|
|
63
|
+
const cfg = (0, config_1.loadConfig)();
|
|
64
|
+
const merged = {
|
|
65
|
+
...cfg.rpcs,
|
|
66
|
+
...(0, config_1.readRpcEnvEntries)(),
|
|
67
|
+
};
|
|
68
|
+
return Object.entries(merged)
|
|
69
|
+
.map(([id, url]) => ({ chainId: Number(id), url }))
|
|
70
|
+
.filter(({ chainId }) => Number.isFinite(chainId))
|
|
71
|
+
.filter(({ chainId }) => filterChain === undefined ? true : chainId === filterChain);
|
|
72
|
+
}
|
|
73
|
+
function registerRpc(program) {
|
|
74
|
+
const rpc = program.command('rpc').description('RPC diagnostics');
|
|
75
|
+
rpc
|
|
76
|
+
.command('test')
|
|
77
|
+
.description('Probe configured RPCs and report latency')
|
|
78
|
+
.option('--chain <id>', 'limit to one chain', (v) => Number(v))
|
|
79
|
+
.option('--timeout <ms>', 'per-RPC timeout in ms', (v) => Number(v), 5000)
|
|
80
|
+
.action(async function () {
|
|
81
|
+
const flags = (0, flags_1.readGlobalFlags)(this);
|
|
82
|
+
const opts = this.opts();
|
|
83
|
+
await (0, output_1.runCommand)('rpc.test', config_1.schemas.RpcTestSchema, flags, async () => {
|
|
84
|
+
const targets = collectTargets(opts.chain ?? flags.chain);
|
|
85
|
+
const results = await Promise.all(targets.map(async ({ chainId, url }) => {
|
|
86
|
+
const probed = await probeRpc(chainId, url, opts.timeout);
|
|
87
|
+
return { chainId, url, ...probed };
|
|
88
|
+
}));
|
|
89
|
+
return { results };
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=rpc.js.map
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerSkill = registerSkill;
|
|
4
|
+
const node_fs_1 = require("node:fs");
|
|
5
|
+
const node_os_1 = require("node:os");
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
7
|
+
const zod_1 = require("zod");
|
|
8
|
+
const flags_1 = require("../lib/flags");
|
|
9
|
+
const output_1 = require("../lib/output");
|
|
10
|
+
const SkillInstallOutput = zod_1.z.object({
|
|
11
|
+
source: zod_1.z.string(),
|
|
12
|
+
destination: zod_1.z.string(),
|
|
13
|
+
installed: zod_1.z.boolean(),
|
|
14
|
+
overwritten: zod_1.z.boolean(),
|
|
15
|
+
});
|
|
16
|
+
const SkillPathOutput = zod_1.z.object({ path: zod_1.z.string() });
|
|
17
|
+
function bundledSkillPath() {
|
|
18
|
+
return (0, node_path_1.resolve)((0, node_path_1.join)(__dirname, '..', '..', 'skills', 'upshift.md'));
|
|
19
|
+
}
|
|
20
|
+
function defaultSkillsDir() {
|
|
21
|
+
return process.env.CLAUDE_SKILLS_DIR
|
|
22
|
+
? (0, node_path_1.resolve)(process.env.CLAUDE_SKILLS_DIR)
|
|
23
|
+
: (0, node_path_1.join)((0, node_os_1.homedir)(), '.claude', 'skills');
|
|
24
|
+
}
|
|
25
|
+
function registerSkill(program) {
|
|
26
|
+
const skill = program
|
|
27
|
+
.command('skill')
|
|
28
|
+
.description('Install the Upshift Claude Code skill');
|
|
29
|
+
skill
|
|
30
|
+
.command('install')
|
|
31
|
+
.description('Copy upshift.md into ~/.claude/skills/')
|
|
32
|
+
.option('--dest <dir>', 'override the destination directory')
|
|
33
|
+
.option('--force', 'overwrite an existing upshift.md')
|
|
34
|
+
.action(async function () {
|
|
35
|
+
const flags = (0, flags_1.readGlobalFlags)(this);
|
|
36
|
+
const opts = this.opts();
|
|
37
|
+
await (0, output_1.runCommand)('skill.install', SkillInstallOutput, flags, async () => {
|
|
38
|
+
const source = bundledSkillPath();
|
|
39
|
+
if (!(0, node_fs_1.existsSync)(source)) {
|
|
40
|
+
throw new Error(`Bundled skill not found at ${source}. Reinstall @upshiftfinance/cli.`);
|
|
41
|
+
}
|
|
42
|
+
const destDir = opts.dest ? (0, node_path_1.resolve)(opts.dest) : defaultSkillsDir();
|
|
43
|
+
if (!(0, node_fs_1.existsSync)(destDir)) {
|
|
44
|
+
(0, node_fs_1.mkdirSync)(destDir, { recursive: true });
|
|
45
|
+
}
|
|
46
|
+
if (!(0, node_fs_1.statSync)(destDir).isDirectory()) {
|
|
47
|
+
throw new Error(`Destination ${destDir} exists but is not a directory.`);
|
|
48
|
+
}
|
|
49
|
+
const destination = (0, node_path_1.join)(destDir, 'upshift.md');
|
|
50
|
+
const existed = (0, node_fs_1.existsSync)(destination);
|
|
51
|
+
if (existed && !opts.force) {
|
|
52
|
+
const incoming = (0, node_fs_1.readFileSync)(source, 'utf8');
|
|
53
|
+
const current = (0, node_fs_1.readFileSync)(destination, 'utf8');
|
|
54
|
+
if (incoming === current) {
|
|
55
|
+
return {
|
|
56
|
+
source,
|
|
57
|
+
destination,
|
|
58
|
+
installed: true,
|
|
59
|
+
overwritten: false,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
throw new Error(`A different upshift.md already exists at ${destination}. Re-run with --force to overwrite.`);
|
|
63
|
+
}
|
|
64
|
+
(0, node_fs_1.copyFileSync)(source, destination);
|
|
65
|
+
return {
|
|
66
|
+
source,
|
|
67
|
+
destination,
|
|
68
|
+
installed: true,
|
|
69
|
+
overwritten: existed,
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
skill
|
|
74
|
+
.command('path')
|
|
75
|
+
.description('Print the absolute path of the bundled skill')
|
|
76
|
+
.action(async function () {
|
|
77
|
+
const flags = (0, flags_1.readGlobalFlags)(this);
|
|
78
|
+
await (0, output_1.runCommand)('skill.path', SkillPathOutput, flags, async () => ({
|
|
79
|
+
path: bundledSkillPath(),
|
|
80
|
+
}));
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=skill.js.map
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerUser = registerUser;
|
|
4
|
+
const config_1 = require("@upshiftfinance/config");
|
|
5
|
+
const flags_1 = require("../lib/flags");
|
|
6
|
+
const output_1 = require("../lib/output");
|
|
7
|
+
const resolve_vault_1 = require("../lib/resolve-vault");
|
|
8
|
+
function resolveChain(flags) {
|
|
9
|
+
return (0, config_1.getDefaultChainId)({
|
|
10
|
+
cliRpcChainId: flags.chain,
|
|
11
|
+
profileName: flags.profile,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
async function buildSdk(flags) {
|
|
15
|
+
return (0, config_1.createSDK)({
|
|
16
|
+
profileName: flags.profile,
|
|
17
|
+
chainId: flags.chain,
|
|
18
|
+
cliRpcUrl: flags.rpc,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function registerUser(program) {
|
|
22
|
+
const user = program
|
|
23
|
+
.command('user')
|
|
24
|
+
.description('Wallet-keyed read commands');
|
|
25
|
+
user
|
|
26
|
+
.command('points <wallet>')
|
|
27
|
+
.description('Points balance and rank')
|
|
28
|
+
.action(async function (wallet) {
|
|
29
|
+
const flags = (0, flags_1.readGlobalFlags)(this);
|
|
30
|
+
await (0, output_1.runCommand)('user.points', config_1.schemas.UserPointsSchema, flags, async () => {
|
|
31
|
+
const chainId = resolveChain(flags);
|
|
32
|
+
const sdk = await buildSdk(flags);
|
|
33
|
+
sdk.switchNetwork(chainId);
|
|
34
|
+
const raw = (await sdk.vaultsModule.getUserPoints(wallet));
|
|
35
|
+
return { user: wallet, ...raw };
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
user
|
|
39
|
+
.command('positions <wallet>')
|
|
40
|
+
.description('Every vault position held by a wallet')
|
|
41
|
+
.action(async function (wallet) {
|
|
42
|
+
const flags = (0, flags_1.readGlobalFlags)(this);
|
|
43
|
+
await (0, output_1.runCommand)('user.positions', config_1.schemas.UserPositionsSchema, flags, async () => {
|
|
44
|
+
const chainId = resolveChain(flags);
|
|
45
|
+
const sdk = await buildSdk(flags);
|
|
46
|
+
const raw = (await sdk.vaultsModule.getVaultPositions({
|
|
47
|
+
wallet: wallet,
|
|
48
|
+
chainId,
|
|
49
|
+
showAllVaults: true,
|
|
50
|
+
}));
|
|
51
|
+
return {
|
|
52
|
+
user: wallet,
|
|
53
|
+
positions: Array.isArray(raw) ? raw : raw ? [raw] : [],
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
user
|
|
58
|
+
.command('pnl <wallet>')
|
|
59
|
+
.description('Lifetime PnL for a wallet in one vault')
|
|
60
|
+
.requiredOption('--vault <address-or-name>', 'vault address or name (e.g. eth-coreusdc)')
|
|
61
|
+
.action(async function (wallet) {
|
|
62
|
+
const flags = (0, flags_1.readGlobalFlags)(this);
|
|
63
|
+
const opts = this.opts();
|
|
64
|
+
await (0, output_1.runCommand)('user.pnl', config_1.schemas.UserPnlSchema, flags, async () => {
|
|
65
|
+
const resolved = await (0, resolve_vault_1.resolveVault)(opts.vault, resolveChain(flags));
|
|
66
|
+
const sdk = await buildSdk(flags);
|
|
67
|
+
const lifetime = (await sdk.vaultsModule.getVaultUserLifetimePnl({
|
|
68
|
+
vault: resolved.address,
|
|
69
|
+
wallet: wallet,
|
|
70
|
+
chainId: resolved.chainId,
|
|
71
|
+
}));
|
|
72
|
+
const lifetimeValue = typeof lifetime === 'string' || typeof lifetime === 'number'
|
|
73
|
+
? lifetime
|
|
74
|
+
: lifetime !== null &&
|
|
75
|
+
typeof lifetime === 'object' &&
|
|
76
|
+
'pnl' in lifetime
|
|
77
|
+
? lifetime.pnl
|
|
78
|
+
: undefined;
|
|
79
|
+
return {
|
|
80
|
+
user: wallet,
|
|
81
|
+
lifetime: lifetimeValue,
|
|
82
|
+
perVault: [
|
|
83
|
+
{
|
|
84
|
+
vault: resolved.address,
|
|
85
|
+
chainId: resolved.chainId,
|
|
86
|
+
pnl: lifetimeValue,
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=user.js.map
|