-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathcli.js
More file actions
60 lines (52 loc) · 1.61 KB
/
cli.js
File metadata and controls
60 lines (52 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// ───────────────────────────────────────────────
// ~/cli.js
// ───────────────────────────────────────────────
import 'dotenv/config';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import { main } from './main.js';
function loadEnv() {
const cfg = {
RPC_URL : process.env.RPC_URL,
WALLET_PATH : process.env.WALLET_PATH,
LOG_LEVEL : process.env.LOG_LEVEL ?? 'info'
};
if (!cfg.RPC_URL) throw new Error('RPC_URL is not set');
if (!cfg.WALLET_PATH) throw new Error('WALLET_PATH is not set');
return cfg;
}
function parseArgs() {
return yargs(hideBin(process.argv))
.command('run', 'start the liquidity bot', y =>
y.option('interval', {
alias : 'i',
type : 'number',
default : 5,
describe : 'Monitor tick interval in seconds'
})
)
.demandCommand(1)
.strict()
.help()
.parse();
}
async function runCli() {
try {
const env = loadEnv();
const argv = parseArgs();
const { interval } = argv;
await main({
...env,
MONITOR_INTERVAL_SECONDS : interval
});
} catch (err) {
// Always exit with non-zero so systemd / Kubernetes knows it failed
console.error('❌', err.message);
process.exit(1);
}
}
// Only run automatically if this file is invoked directly
if (import.meta.url === `file://${process.argv[1]}`) {
runCli();
}
export { loadEnv, parseArgs, runCli };