aether-hub 1.2.7 → 1.2.8
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/commands/account.js +280 -280
- package/commands/apy.js +480 -480
- package/commands/balance.js +276 -276
- package/commands/claim.js +292 -292
- package/commands/delegations.js +45 -95
- package/commands/emergency.js +14 -4
- package/commands/epoch.js +275 -275
- package/commands/fees.js +276 -276
- package/commands/info.js +495 -495
- package/commands/monitor.js +431 -431
- package/commands/multisig.js +726 -726
- package/commands/network.js +429 -429
- package/commands/ping.js +266 -266
- package/commands/sdk-test.js +477 -477
- package/commands/sdk.js +537 -537
- package/commands/slot.js +155 -0
- package/commands/snapshot.js +509 -509
- package/commands/stake-positions.js +31 -46
- package/commands/stats.js +418 -418
- package/commands/status.js +326 -326
- package/commands/supply.js +3 -1
- package/commands/tps.js +238 -238
- package/commands/tx-history.js +346 -462
- package/commands/wallet.js +3 -0
- package/index.js +11 -2
- package/package.json +1 -1
package/commands/epoch.js
CHANGED
|
@@ -1,275 +1,275 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* aether-cli epoch
|
|
4
|
-
*
|
|
5
|
-
* Display current epoch information including timing, schedule,
|
|
6
|
-
* slots per epoch, and estimated staking rewards rate.
|
|
7
|
-
*
|
|
8
|
-
* Usage:
|
|
9
|
-
* aether epoch Show current epoch with timing breakdown
|
|
10
|
-
* aether epoch --json JSON output for scripting/monitoring
|
|
11
|
-
* aether epoch --rpc <url> Query a specific RPC endpoint
|
|
12
|
-
* aether epoch --schedule Show upcoming epoch schedule
|
|
13
|
-
*
|
|
14
|
-
* Requires AETHER_RPC env var (default: http://127.0.0.1:8899)
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
const path = require('path');
|
|
18
|
-
|
|
19
|
-
// ANSI colours
|
|
20
|
-
const C = {
|
|
21
|
-
reset: '\x1b[0m',
|
|
22
|
-
bright: '\x1b[1m',
|
|
23
|
-
dim: '\x1b[2m',
|
|
24
|
-
red: '\x1b[31m',
|
|
25
|
-
green: '\x1b[32m',
|
|
26
|
-
yellow: '\x1b[33m',
|
|
27
|
-
cyan: '\x1b[36m',
|
|
28
|
-
magenta: '\x1b[35m',
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const CLI_VERSION = '1.0.0';
|
|
32
|
-
|
|
33
|
-
// ---------------------------------------------------------------------------
|
|
34
|
-
// SDK Import - Real blockchain RPC calls via @jellylegsai/aether-sdk
|
|
35
|
-
// ---------------------------------------------------------------------------
|
|
36
|
-
|
|
37
|
-
const sdkPath = path.join(__dirname, '..', 'sdk', 'index.js');
|
|
38
|
-
const aether = require(sdkPath);
|
|
39
|
-
|
|
40
|
-
function getDefaultRpc() {
|
|
41
|
-
return process.env.AETHER_RPC || aether.DEFAULT_RPC_URL || 'http://127.0.0.1:8899';
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// ---------------------------------------------------------------------------
|
|
45
|
-
// Argument parsing
|
|
46
|
-
// ---------------------------------------------------------------------------
|
|
47
|
-
|
|
48
|
-
function parseArgs() {
|
|
49
|
-
const args = process.argv.slice(3); // [node, index.js, epoch, ...]
|
|
50
|
-
return {
|
|
51
|
-
rpc: getDefaultRpc(),
|
|
52
|
-
asJson: args.indexOf('--json') !== -1 || args.indexOf('-j') !== -1,
|
|
53
|
-
showSchedule: args.indexOf('--schedule') !== -1 || args.indexOf('-s') !== -1,
|
|
54
|
-
rpcUrl: getDefaultRpc(),
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// ---------------------------------------------------------------------------
|
|
59
|
-
// Fetch epoch info from RPC using SDK
|
|
60
|
-
// ---------------------------------------------------------------------------
|
|
61
|
-
|
|
62
|
-
async function fetchEpochInfo(rpc) {
|
|
63
|
-
// Use SDK for real blockchain RPC calls
|
|
64
|
-
const client = new aether.AetherClient({ rpcUrl: rpc });
|
|
65
|
-
try {
|
|
66
|
-
const epochInfo = await client.getEpochInfo();
|
|
67
|
-
if (epochInfo && (epochInfo.epoch !== undefined || epochInfo.current_epoch)) {
|
|
68
|
-
return { data: epochInfo, source: 'aether-sdk' };
|
|
69
|
-
}
|
|
70
|
-
} catch(e) {
|
|
71
|
-
throw new Error('Failed to fetch epoch info from RPC. Is your validator running?');
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
throw new Error('Failed to fetch epoch info from RPC. Is your validator running?');
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// ---------------------------------------------------------------------------
|
|
78
|
-
// Format helpers
|
|
79
|
-
// ---------------------------------------------------------------------------
|
|
80
|
-
|
|
81
|
-
function formatAether(lamports) {
|
|
82
|
-
const aeth = lamports / 1e9;
|
|
83
|
-
if (aeth === 0) return '0 AETH';
|
|
84
|
-
return aeth.toFixed(4).replace(/\.?0+$/, '') + ' AETH';
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function formatDuration(seconds) {
|
|
88
|
-
if (seconds < 0) return '\u2014';
|
|
89
|
-
const h = Math.floor(seconds / 3600);
|
|
90
|
-
const m = Math.floor((seconds % 3600) / 60);
|
|
91
|
-
const s = Math.floor(seconds % 60);
|
|
92
|
-
if (h > 24) {
|
|
93
|
-
const d = Math.floor(h / 24);
|
|
94
|
-
return d + 'd ' + (h % 24) + 'h';
|
|
95
|
-
}
|
|
96
|
-
if (h > 0) return h + 'h ' + m + 'm';
|
|
97
|
-
if (m > 0) return m + 'm ' + s + 's';
|
|
98
|
-
return s + 's';
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function fmtPct(value, decimals) {
|
|
102
|
-
decimals = decimals || 1;
|
|
103
|
-
return (value || 0).toFixed(decimals) + '%';
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// ---------------------------------------------------------------------------
|
|
107
|
-
// Box drawing helpers
|
|
108
|
-
// ---------------------------------------------------------------------------
|
|
109
|
-
|
|
110
|
-
// Box drawing characters
|
|
111
|
-
const BOX_H = '\u2500'; // ─
|
|
112
|
-
const BOX_V = '\u2502'; // │
|
|
113
|
-
const BOX_TL = '\u256d'; // ╭
|
|
114
|
-
const BOX_TR = '\u256e'; // ╮
|
|
115
|
-
const BOX_BL = '\u2570'; // ╰
|
|
116
|
-
const BOX_BR = '\u256f'; // ╯
|
|
117
|
-
const BOX_Cross = '\u253c'; // ┼
|
|
118
|
-
|
|
119
|
-
function makeBoxLine(chars, width) {
|
|
120
|
-
let s = '';
|
|
121
|
-
for (let i = 0; i < width; i++) s += chars;
|
|
122
|
-
return s;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function makeSectionHeader(label) {
|
|
126
|
-
const total = 62;
|
|
127
|
-
const labelWithSpaces = ' ' + label + ' ';
|
|
128
|
-
const remaining = total - 4 - labelWithSpaces.length; // 4 for ╼ on each side
|
|
129
|
-
const half = Math.floor(remaining / 2);
|
|
130
|
-
const left = makeBoxLine('\u2550', half);
|
|
131
|
-
const right = makeBoxLine('\u2550', remaining - half);
|
|
132
|
-
return C.bright + C.cyan + '\u256e' + left + '\u2554' + labelWithSpaces + '\u2557' + right + '\u256f' + C.reset;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// ---------------------------------------------------------------------------
|
|
136
|
-
// Main display
|
|
137
|
-
// ---------------------------------------------------------------------------
|
|
138
|
-
|
|
139
|
-
async function showEpochInfo(opts) {
|
|
140
|
-
const rpc = opts.rpcUrl;
|
|
141
|
-
const { data, source } = await fetchEpochInfo(rpc);
|
|
142
|
-
|
|
143
|
-
// Normalise fields across different RPC response formats
|
|
144
|
-
const epoch = data.epoch ?? data.current_epoch ?? 0;
|
|
145
|
-
const slotIndex = data.slotIndex ?? data.current_slot ?? 0;
|
|
146
|
-
const slotsInEpoch = data.slotsInEpoch ?? data.slots_per_epoch ?? 8192;
|
|
147
|
-
const epochProgress = slotsInEpoch > 0 ? (slotIndex / slotsInEpoch) * 100 : 0;
|
|
148
|
-
const absoluteSlot = data.absoluteSlot ?? data.slot ?? 0;
|
|
149
|
-
const totalStaked = BigInt(data.totalStaked ?? data.total_staked ?? data.stake ?? 0);
|
|
150
|
-
const rewardsPerEpoch = BigInt(data.rewardsPerEpoch ?? data.rewards_per_epoch ?? data.rewards ?? 0);
|
|
151
|
-
|
|
152
|
-
// Estimate seconds per slot from slot data
|
|
153
|
-
const epochDurationSecs = data.epochDurationSecs ?? (slotsInEpoch * 0.4); // ~400ms/slot default
|
|
154
|
-
const secsPerSlot = epochDurationSecs / slotsInEpoch;
|
|
155
|
-
const secondsIntoEpoch = slotIndex * secsPerSlot;
|
|
156
|
-
const secondsRemaining = (slotsInEpoch - slotIndex) * secsPerSlot;
|
|
157
|
-
|
|
158
|
-
// APY estimate: rewards per epoch / total staked * epochs per year
|
|
159
|
-
const epochsPerYear = 365 * 24 * 3600 / epochDurationSecs;
|
|
160
|
-
const apyRate = totalStaked > 0n
|
|
161
|
-
? (Number(rewardsPerEpoch) / Number(totalStaked)) * epochsPerYear
|
|
162
|
-
: 0;
|
|
163
|
-
const apyBps = Math.round(apyRate * 10000);
|
|
164
|
-
|
|
165
|
-
if (opts.asJson) {
|
|
166
|
-
const out = {
|
|
167
|
-
epoch: epoch,
|
|
168
|
-
slotIndex: slotIndex,
|
|
169
|
-
slotsInEpoch: slotsInEpoch,
|
|
170
|
-
absoluteSlot: absoluteSlot,
|
|
171
|
-
epochProgress: epochProgress,
|
|
172
|
-
secondsIntoEpoch: Math.round(secondsIntoEpoch),
|
|
173
|
-
secondsRemaining: Math.round(secondsRemaining),
|
|
174
|
-
totalStaked: totalStaked.toString(),
|
|
175
|
-
totalStakedFormatted: formatAether(totalStaked),
|
|
176
|
-
rewardsPerEpoch: rewardsPerEpoch.toString(),
|
|
177
|
-
rewardsPerEpochFormatted: formatAether(rewardsPerEpoch),
|
|
178
|
-
estimatedApyBps: apyBps,
|
|
179
|
-
estimatedApy: fmtPct(apyRate),
|
|
180
|
-
source: source,
|
|
181
|
-
fetchedAt: new Date().toISOString(),
|
|
182
|
-
};
|
|
183
|
-
console.log(JSON.stringify(out, null, 2));
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// ASCII art header
|
|
188
|
-
console.log('');
|
|
189
|
-
const line1 = C.bright + C.cyan + BOX_TL + makeBoxLine(BOX_H, 60) + BOX_TR + C.reset;
|
|
190
|
-
console.log(line1);
|
|
191
|
-
const line2 = C.bright + C.cyan + BOX_V + ' AeTHer Epoch ' + epoch + ' Info ' + BOX_V + C.reset;
|
|
192
|
-
console.log(line2);
|
|
193
|
-
const line3 = C.bright + C.cyan + BOX_BL + makeBoxLine(BOX_H, 60) + BOX_BR + C.reset;
|
|
194
|
-
console.log(line3);
|
|
195
|
-
console.log('');
|
|
196
|
-
|
|
197
|
-
console.log(' ' + C.dim + 'RPC: ' + rpc + C.reset);
|
|
198
|
-
console.log('');
|
|
199
|
-
|
|
200
|
-
// ── Epoch timing ───────────────────────────────────────────────────────
|
|
201
|
-
console.log(makeSectionHeader('Epoch Timing'));
|
|
202
|
-
|
|
203
|
-
const progressBars = 40;
|
|
204
|
-
const filled = Math.round((epochProgress / 100) * progressBars);
|
|
205
|
-
const empty = progressBars - filled;
|
|
206
|
-
const bar = C.green + '#'.repeat(filled) + C.dim + '\u2500'.repeat(empty) + C.reset;
|
|
207
|
-
|
|
208
|
-
console.log(' ' + C.dim + ' Progress: [' + bar + '] ' + C.bright + fmtPct(epochProgress) + C.reset);
|
|
209
|
-
console.log(' ' + C.dim + ' Slot: ' + C.reset + C.bright + slotIndex.toLocaleString() + C.reset + ' / ' + slotsInEpoch.toLocaleString() + ' slots into epoch');
|
|
210
|
-
console.log(' ' + C.dim + ' Abs slot: ' + C.reset + absoluteSlot.toLocaleString());
|
|
211
|
-
console.log(' ' + C.dim + ' Elapsed: ' + C.reset + formatDuration(Math.round(secondsIntoEpoch)));
|
|
212
|
-
console.log(' ' + C.dim + ' Remaining: ' + C.reset + C.yellow + formatDuration(Math.round(secondsRemaining)) + C.reset);
|
|
213
|
-
console.log(' ' + C.dim + ' Duration: ' + C.reset + '~' + formatDuration(Math.round(epochDurationSecs)) + ' per epoch');
|
|
214
|
-
console.log('');
|
|
215
|
-
|
|
216
|
-
// ── Staking rewards ─────────────────────────────────────────────────────
|
|
217
|
-
console.log(makeSectionHeader('Staking Rewards'));
|
|
218
|
-
|
|
219
|
-
console.log(' ' + C.dim + ' Network stake: ' + C.reset + C.bright + formatAether(totalStaked) + C.reset);
|
|
220
|
-
console.log(' ' + C.dim + ' Rewards/epoch: ' + C.reset + C.green + formatAether(rewardsPerEpoch) + C.reset);
|
|
221
|
-
console.log(' ' + C.dim + ' Estimated APY: ' + C.reset + C.green + C.bright + fmtPct(apyRate) + C.reset + ' ' + C.dim + '(~' + (apyBps / 100).toFixed(0) + ' bps)' + C.reset);
|
|
222
|
-
console.log('');
|
|
223
|
-
|
|
224
|
-
// ── Epoch schedule ──────────────────────────────────────────────────────
|
|
225
|
-
if (opts.showSchedule) {
|
|
226
|
-
console.log(makeSectionHeader('Upcoming Epochs'));
|
|
227
|
-
const startSlotNext = absoluteSlot + (slotsInEpoch - slotIndex);
|
|
228
|
-
for (let i = 0; i < 5; i++) {
|
|
229
|
-
const e = epoch + i;
|
|
230
|
-
const start = startSlotNext + i * slotsInEpoch;
|
|
231
|
-
const end = start + slotsInEpoch - 1;
|
|
232
|
-
const isNext = i === 0 ? ' ' + C.green + '(next)' + C.reset : '';
|
|
233
|
-
console.log(' ' + C.dim + ' Epoch ' + String(e).padStart(4) + ': slots ' + start.toLocaleString() + ' \u2013 ' + end.toLocaleString() + isNext + C.reset);
|
|
234
|
-
}
|
|
235
|
-
console.log('');
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// ── Raw data ─────────────────────────────────────────────────────────────
|
|
239
|
-
console.log(makeSectionHeader('Raw RPC Data'));
|
|
240
|
-
console.log(' ' + C.dim + ' Source: ' + source + C.reset);
|
|
241
|
-
const rawPreview = JSON.stringify(data).substring(0, 80);
|
|
242
|
-
console.log(' ' + C.dim + ' ' + rawPreview + C.reset);
|
|
243
|
-
console.log('');
|
|
244
|
-
|
|
245
|
-
console.log(' ' + C.dim + 'Run "aether validators list" to see validator performance for epoch ' + epoch + '.' + C.reset);
|
|
246
|
-
console.log(' ' + C.dim + 'Run "aether rewards list --address <addr>" to check your staking rewards.' + C.reset);
|
|
247
|
-
console.log('');
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// ---------------------------------------------------------------------------
|
|
251
|
-
// Main entry point
|
|
252
|
-
// ---------------------------------------------------------------------------
|
|
253
|
-
|
|
254
|
-
async function epochCommand() {
|
|
255
|
-
const opts = parseArgs();
|
|
256
|
-
try {
|
|
257
|
-
await showEpochInfo(opts);
|
|
258
|
-
} catch (err) {
|
|
259
|
-
if (opts.asJson) {
|
|
260
|
-
console.log(JSON.stringify({ error: err.message }, null, 2));
|
|
261
|
-
} else {
|
|
262
|
-
console.log('');
|
|
263
|
-
console.log(' ' + C.red + '\u2514 Error: ' + C.reset + ' ' + err.message);
|
|
264
|
-
console.log(' ' + C.dim + 'Set a custom RPC: AETHER_RPC=https://your-rpc-url' + C.reset);
|
|
265
|
-
console.log('');
|
|
266
|
-
}
|
|
267
|
-
process.exit(1);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
module.exports = { epochCommand };
|
|
272
|
-
|
|
273
|
-
if (require.main === module) {
|
|
274
|
-
epochCommand();
|
|
275
|
-
}
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* aether-cli epoch
|
|
4
|
+
*
|
|
5
|
+
* Display current epoch information including timing, schedule,
|
|
6
|
+
* slots per epoch, and estimated staking rewards rate.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* aether epoch Show current epoch with timing breakdown
|
|
10
|
+
* aether epoch --json JSON output for scripting/monitoring
|
|
11
|
+
* aether epoch --rpc <url> Query a specific RPC endpoint
|
|
12
|
+
* aether epoch --schedule Show upcoming epoch schedule
|
|
13
|
+
*
|
|
14
|
+
* Requires AETHER_RPC env var (default: http://127.0.0.1:8899)
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const path = require('path');
|
|
18
|
+
|
|
19
|
+
// ANSI colours
|
|
20
|
+
const C = {
|
|
21
|
+
reset: '\x1b[0m',
|
|
22
|
+
bright: '\x1b[1m',
|
|
23
|
+
dim: '\x1b[2m',
|
|
24
|
+
red: '\x1b[31m',
|
|
25
|
+
green: '\x1b[32m',
|
|
26
|
+
yellow: '\x1b[33m',
|
|
27
|
+
cyan: '\x1b[36m',
|
|
28
|
+
magenta: '\x1b[35m',
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const CLI_VERSION = '1.0.0';
|
|
32
|
+
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
// SDK Import - Real blockchain RPC calls via @jellylegsai/aether-sdk
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
|
|
37
|
+
const sdkPath = path.join(__dirname, '..', 'sdk', 'index.js');
|
|
38
|
+
const aether = require(sdkPath);
|
|
39
|
+
|
|
40
|
+
function getDefaultRpc() {
|
|
41
|
+
return process.env.AETHER_RPC || aether.DEFAULT_RPC_URL || 'http://127.0.0.1:8899';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// ---------------------------------------------------------------------------
|
|
45
|
+
// Argument parsing
|
|
46
|
+
// ---------------------------------------------------------------------------
|
|
47
|
+
|
|
48
|
+
function parseArgs() {
|
|
49
|
+
const args = process.argv.slice(3); // [node, index.js, epoch, ...]
|
|
50
|
+
return {
|
|
51
|
+
rpc: getDefaultRpc(),
|
|
52
|
+
asJson: args.indexOf('--json') !== -1 || args.indexOf('-j') !== -1,
|
|
53
|
+
showSchedule: args.indexOf('--schedule') !== -1 || args.indexOf('-s') !== -1,
|
|
54
|
+
rpcUrl: getDefaultRpc(),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// ---------------------------------------------------------------------------
|
|
59
|
+
// Fetch epoch info from RPC using SDK
|
|
60
|
+
// ---------------------------------------------------------------------------
|
|
61
|
+
|
|
62
|
+
async function fetchEpochInfo(rpc) {
|
|
63
|
+
// Use SDK for real blockchain RPC calls
|
|
64
|
+
const client = new aether.AetherClient({ rpcUrl: rpc });
|
|
65
|
+
try {
|
|
66
|
+
const epochInfo = await client.getEpochInfo();
|
|
67
|
+
if (epochInfo && (epochInfo.epoch !== undefined || epochInfo.current_epoch)) {
|
|
68
|
+
return { data: epochInfo, source: 'aether-sdk' };
|
|
69
|
+
}
|
|
70
|
+
} catch(e) {
|
|
71
|
+
throw new Error('Failed to fetch epoch info from RPC. Is your validator running?');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
throw new Error('Failed to fetch epoch info from RPC. Is your validator running?');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
// Format helpers
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
|
|
81
|
+
function formatAether(lamports) {
|
|
82
|
+
const aeth = lamports / 1e9;
|
|
83
|
+
if (aeth === 0) return '0 AETH';
|
|
84
|
+
return aeth.toFixed(4).replace(/\.?0+$/, '') + ' AETH';
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function formatDuration(seconds) {
|
|
88
|
+
if (seconds < 0) return '\u2014';
|
|
89
|
+
const h = Math.floor(seconds / 3600);
|
|
90
|
+
const m = Math.floor((seconds % 3600) / 60);
|
|
91
|
+
const s = Math.floor(seconds % 60);
|
|
92
|
+
if (h > 24) {
|
|
93
|
+
const d = Math.floor(h / 24);
|
|
94
|
+
return d + 'd ' + (h % 24) + 'h';
|
|
95
|
+
}
|
|
96
|
+
if (h > 0) return h + 'h ' + m + 'm';
|
|
97
|
+
if (m > 0) return m + 'm ' + s + 's';
|
|
98
|
+
return s + 's';
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function fmtPct(value, decimals) {
|
|
102
|
+
decimals = decimals || 1;
|
|
103
|
+
return (value || 0).toFixed(decimals) + '%';
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// ---------------------------------------------------------------------------
|
|
107
|
+
// Box drawing helpers
|
|
108
|
+
// ---------------------------------------------------------------------------
|
|
109
|
+
|
|
110
|
+
// Box drawing characters
|
|
111
|
+
const BOX_H = '\u2500'; // ─
|
|
112
|
+
const BOX_V = '\u2502'; // │
|
|
113
|
+
const BOX_TL = '\u256d'; // ╭
|
|
114
|
+
const BOX_TR = '\u256e'; // ╮
|
|
115
|
+
const BOX_BL = '\u2570'; // ╰
|
|
116
|
+
const BOX_BR = '\u256f'; // ╯
|
|
117
|
+
const BOX_Cross = '\u253c'; // ┼
|
|
118
|
+
|
|
119
|
+
function makeBoxLine(chars, width) {
|
|
120
|
+
let s = '';
|
|
121
|
+
for (let i = 0; i < width; i++) s += chars;
|
|
122
|
+
return s;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function makeSectionHeader(label) {
|
|
126
|
+
const total = 62;
|
|
127
|
+
const labelWithSpaces = ' ' + label + ' ';
|
|
128
|
+
const remaining = total - 4 - labelWithSpaces.length; // 4 for ╼ on each side
|
|
129
|
+
const half = Math.floor(remaining / 2);
|
|
130
|
+
const left = makeBoxLine('\u2550', half);
|
|
131
|
+
const right = makeBoxLine('\u2550', remaining - half);
|
|
132
|
+
return C.bright + C.cyan + '\u256e' + left + '\u2554' + labelWithSpaces + '\u2557' + right + '\u256f' + C.reset;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// ---------------------------------------------------------------------------
|
|
136
|
+
// Main display
|
|
137
|
+
// ---------------------------------------------------------------------------
|
|
138
|
+
|
|
139
|
+
async function showEpochInfo(opts) {
|
|
140
|
+
const rpc = opts.rpcUrl;
|
|
141
|
+
const { data, source } = await fetchEpochInfo(rpc);
|
|
142
|
+
|
|
143
|
+
// Normalise fields across different RPC response formats
|
|
144
|
+
const epoch = data.epoch ?? data.current_epoch ?? 0;
|
|
145
|
+
const slotIndex = data.slotIndex ?? data.current_slot ?? 0;
|
|
146
|
+
const slotsInEpoch = data.slotsInEpoch ?? data.slots_per_epoch ?? 8192;
|
|
147
|
+
const epochProgress = slotsInEpoch > 0 ? (slotIndex / slotsInEpoch) * 100 : 0;
|
|
148
|
+
const absoluteSlot = data.absoluteSlot ?? data.slot ?? 0;
|
|
149
|
+
const totalStaked = BigInt(data.totalStaked ?? data.total_staked ?? data.stake ?? 0);
|
|
150
|
+
const rewardsPerEpoch = BigInt(data.rewardsPerEpoch ?? data.rewards_per_epoch ?? data.rewards ?? 0);
|
|
151
|
+
|
|
152
|
+
// Estimate seconds per slot from slot data
|
|
153
|
+
const epochDurationSecs = data.epochDurationSecs ?? (slotsInEpoch * 0.4); // ~400ms/slot default
|
|
154
|
+
const secsPerSlot = epochDurationSecs / slotsInEpoch;
|
|
155
|
+
const secondsIntoEpoch = slotIndex * secsPerSlot;
|
|
156
|
+
const secondsRemaining = (slotsInEpoch - slotIndex) * secsPerSlot;
|
|
157
|
+
|
|
158
|
+
// APY estimate: rewards per epoch / total staked * epochs per year
|
|
159
|
+
const epochsPerYear = 365 * 24 * 3600 / epochDurationSecs;
|
|
160
|
+
const apyRate = totalStaked > 0n
|
|
161
|
+
? (Number(rewardsPerEpoch) / Number(totalStaked)) * epochsPerYear
|
|
162
|
+
: 0;
|
|
163
|
+
const apyBps = Math.round(apyRate * 10000);
|
|
164
|
+
|
|
165
|
+
if (opts.asJson) {
|
|
166
|
+
const out = {
|
|
167
|
+
epoch: epoch,
|
|
168
|
+
slotIndex: slotIndex,
|
|
169
|
+
slotsInEpoch: slotsInEpoch,
|
|
170
|
+
absoluteSlot: absoluteSlot,
|
|
171
|
+
epochProgress: epochProgress,
|
|
172
|
+
secondsIntoEpoch: Math.round(secondsIntoEpoch),
|
|
173
|
+
secondsRemaining: Math.round(secondsRemaining),
|
|
174
|
+
totalStaked: totalStaked.toString(),
|
|
175
|
+
totalStakedFormatted: formatAether(totalStaked),
|
|
176
|
+
rewardsPerEpoch: rewardsPerEpoch.toString(),
|
|
177
|
+
rewardsPerEpochFormatted: formatAether(rewardsPerEpoch),
|
|
178
|
+
estimatedApyBps: apyBps,
|
|
179
|
+
estimatedApy: fmtPct(apyRate),
|
|
180
|
+
source: source,
|
|
181
|
+
fetchedAt: new Date().toISOString(),
|
|
182
|
+
};
|
|
183
|
+
console.log(JSON.stringify(out, null, 2));
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// ASCII art header
|
|
188
|
+
console.log('');
|
|
189
|
+
const line1 = C.bright + C.cyan + BOX_TL + makeBoxLine(BOX_H, 60) + BOX_TR + C.reset;
|
|
190
|
+
console.log(line1);
|
|
191
|
+
const line2 = C.bright + C.cyan + BOX_V + ' AeTHer Epoch ' + epoch + ' Info ' + BOX_V + C.reset;
|
|
192
|
+
console.log(line2);
|
|
193
|
+
const line3 = C.bright + C.cyan + BOX_BL + makeBoxLine(BOX_H, 60) + BOX_BR + C.reset;
|
|
194
|
+
console.log(line3);
|
|
195
|
+
console.log('');
|
|
196
|
+
|
|
197
|
+
console.log(' ' + C.dim + 'RPC: ' + rpc + C.reset);
|
|
198
|
+
console.log('');
|
|
199
|
+
|
|
200
|
+
// ── Epoch timing ───────────────────────────────────────────────────────
|
|
201
|
+
console.log(makeSectionHeader('Epoch Timing'));
|
|
202
|
+
|
|
203
|
+
const progressBars = 40;
|
|
204
|
+
const filled = Math.round((epochProgress / 100) * progressBars);
|
|
205
|
+
const empty = progressBars - filled;
|
|
206
|
+
const bar = C.green + '#'.repeat(filled) + C.dim + '\u2500'.repeat(empty) + C.reset;
|
|
207
|
+
|
|
208
|
+
console.log(' ' + C.dim + ' Progress: [' + bar + '] ' + C.bright + fmtPct(epochProgress) + C.reset);
|
|
209
|
+
console.log(' ' + C.dim + ' Slot: ' + C.reset + C.bright + slotIndex.toLocaleString() + C.reset + ' / ' + slotsInEpoch.toLocaleString() + ' slots into epoch');
|
|
210
|
+
console.log(' ' + C.dim + ' Abs slot: ' + C.reset + absoluteSlot.toLocaleString());
|
|
211
|
+
console.log(' ' + C.dim + ' Elapsed: ' + C.reset + formatDuration(Math.round(secondsIntoEpoch)));
|
|
212
|
+
console.log(' ' + C.dim + ' Remaining: ' + C.reset + C.yellow + formatDuration(Math.round(secondsRemaining)) + C.reset);
|
|
213
|
+
console.log(' ' + C.dim + ' Duration: ' + C.reset + '~' + formatDuration(Math.round(epochDurationSecs)) + ' per epoch');
|
|
214
|
+
console.log('');
|
|
215
|
+
|
|
216
|
+
// ── Staking rewards ─────────────────────────────────────────────────────
|
|
217
|
+
console.log(makeSectionHeader('Staking Rewards'));
|
|
218
|
+
|
|
219
|
+
console.log(' ' + C.dim + ' Network stake: ' + C.reset + C.bright + formatAether(totalStaked) + C.reset);
|
|
220
|
+
console.log(' ' + C.dim + ' Rewards/epoch: ' + C.reset + C.green + formatAether(rewardsPerEpoch) + C.reset);
|
|
221
|
+
console.log(' ' + C.dim + ' Estimated APY: ' + C.reset + C.green + C.bright + fmtPct(apyRate) + C.reset + ' ' + C.dim + '(~' + (apyBps / 100).toFixed(0) + ' bps)' + C.reset);
|
|
222
|
+
console.log('');
|
|
223
|
+
|
|
224
|
+
// ── Epoch schedule ──────────────────────────────────────────────────────
|
|
225
|
+
if (opts.showSchedule) {
|
|
226
|
+
console.log(makeSectionHeader('Upcoming Epochs'));
|
|
227
|
+
const startSlotNext = absoluteSlot + (slotsInEpoch - slotIndex);
|
|
228
|
+
for (let i = 0; i < 5; i++) {
|
|
229
|
+
const e = epoch + i;
|
|
230
|
+
const start = startSlotNext + i * slotsInEpoch;
|
|
231
|
+
const end = start + slotsInEpoch - 1;
|
|
232
|
+
const isNext = i === 0 ? ' ' + C.green + '(next)' + C.reset : '';
|
|
233
|
+
console.log(' ' + C.dim + ' Epoch ' + String(e).padStart(4) + ': slots ' + start.toLocaleString() + ' \u2013 ' + end.toLocaleString() + isNext + C.reset);
|
|
234
|
+
}
|
|
235
|
+
console.log('');
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// ── Raw data ─────────────────────────────────────────────────────────────
|
|
239
|
+
console.log(makeSectionHeader('Raw RPC Data'));
|
|
240
|
+
console.log(' ' + C.dim + ' Source: ' + source + C.reset);
|
|
241
|
+
const rawPreview = JSON.stringify(data).substring(0, 80);
|
|
242
|
+
console.log(' ' + C.dim + ' ' + rawPreview + C.reset);
|
|
243
|
+
console.log('');
|
|
244
|
+
|
|
245
|
+
console.log(' ' + C.dim + 'Run "aether validators list" to see validator performance for epoch ' + epoch + '.' + C.reset);
|
|
246
|
+
console.log(' ' + C.dim + 'Run "aether rewards list --address <addr>" to check your staking rewards.' + C.reset);
|
|
247
|
+
console.log('');
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// ---------------------------------------------------------------------------
|
|
251
|
+
// Main entry point
|
|
252
|
+
// ---------------------------------------------------------------------------
|
|
253
|
+
|
|
254
|
+
async function epochCommand() {
|
|
255
|
+
const opts = parseArgs();
|
|
256
|
+
try {
|
|
257
|
+
await showEpochInfo(opts);
|
|
258
|
+
} catch (err) {
|
|
259
|
+
if (opts.asJson) {
|
|
260
|
+
console.log(JSON.stringify({ error: err.message }, null, 2));
|
|
261
|
+
} else {
|
|
262
|
+
console.log('');
|
|
263
|
+
console.log(' ' + C.red + '\u2514 Error: ' + C.reset + ' ' + err.message);
|
|
264
|
+
console.log(' ' + C.dim + 'Set a custom RPC: AETHER_RPC=https://your-rpc-url' + C.reset);
|
|
265
|
+
console.log('');
|
|
266
|
+
}
|
|
267
|
+
process.exit(1);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
module.exports = { epochCommand };
|
|
272
|
+
|
|
273
|
+
if (require.main === module) {
|
|
274
|
+
epochCommand();
|
|
275
|
+
}
|