-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.ts
More file actions
112 lines (101 loc) · 3.02 KB
/
index.ts
File metadata and controls
112 lines (101 loc) · 3.02 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#! /usr/bin/env node
import { getChain } from 'configs';
import { mainnet } from 'viem/chains';
import { program } from './command/index.js';
import { logError, logInfo } from './utils/logging/console.js';
import { withInterruptHandling } from './utils/interrupt-handler.js';
import './programs/index.js';
import {
closeJsonLogging,
disconnectWalletConnect,
logJson,
openJsonLogging,
} from './utils/index.js';
export * from './utils/index.js';
const showTestnetWarning = () => {
console.info('\nHOODI V3 application:');
console.info(
'- 📖 CLI Docs: https://lidofinance.github.io/lido-staking-vault-cli/',
);
console.info('- 🌐 Web UI: https://stvaults-hoodi.testnet.fi/vaults');
console.info(
'- 📄 Contracts info: https://docs.lido.fi/deployed-contracts/hoodi',
);
console.info(
'- 📖 stVaults Doc Center: https://docs.lido.fi/run-on-lido/stvaults\n',
);
};
const showMainnetWarning = () => {
const now = new Date();
const targetDate = new Date('2026-01-29');
const shouldShowLinks = now >= targetDate;
console.info('\nMainnet V3 application:');
console.info(
'- 📖 CLI Docs: https://lidofinance.github.io/lido-staking-vault-cli/',
);
if (shouldShowLinks) {
console.info('- 🌐 Web UI: https://stvaults.lido.fi/vaults');
}
console.info('- 📄 Contracts info: https://docs.lido.fi/deployed-contracts');
console.info(
'- 📖 stVaults Doc Center: https://docs.lido.fi/run-on-lido/stvaults\n',
);
};
program.addHelpText('afterAll', () => {
const chain = process.env.CHAIN_ID;
if (program.opts().json) return '';
if (chain === String(mainnet.id)) {
showMainnetWarning();
} else {
showTestnetWarning();
}
return '';
});
// Add interrupt handling to the CLI
const runCLI = withInterruptHandling(async () => {
// programm.opts is not init yet
const isJson = process.argv.includes('--json');
const chain = await getChain();
if (isJson) {
openJsonLogging();
} else {
logInfo(`${'-'.repeat(100)}`);
logInfo(`Using chain: Name: ${chain.name}, Chain ID: ${chain.id}`);
logInfo(`${'-'.repeat(100)}`);
}
await program.parseAsync(process.argv);
});
void runCLI()
.catch(async (error) => {
try {
await disconnectWalletConnect();
} catch {
// Ignore disconnection errors
}
if (program.opts().json) {
logJson({ error: error.message });
closeJsonLogging();
} else {
logError('CLI Error:', error.message);
}
process.exit(1);
})
.finally(async () => {
if (program.opts().json) {
closeJsonLogging();
} else {
const chain = await getChain();
if (chain.id === mainnet.id) {
showMainnetWarning();
} else {
showTestnetWarning();
}
}
await disconnectWalletConnect();
// If the command is not charts, exit
// It is necessary to keep the screen open for charts
const isCharts = ['charts', 'charts-apr', 'charts-rewards', 'metrics'].some(
(command) => process.argv.includes(command),
);
if (!isCharts) process.exit(0);
});