genlayer 0.32.6 → 0.32.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/CHANGELOG.md +1 -1
- package/README.md +10 -7
- package/dist/index.js +27 -5
- package/package.json +1 -1
- package/src/commands/staking/index.ts +5 -2
- package/src/commands/staking/validatorHistory.ts +42 -3
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -399,16 +399,19 @@ EXAMPLES:
|
|
|
399
399
|
genlayer staking validators
|
|
400
400
|
genlayer staking validators --all # Include banned validators
|
|
401
401
|
|
|
402
|
-
# Show validator slash/reward history (testnet only)
|
|
402
|
+
# Show validator slash/reward history (testnet only, default: last 10 epochs)
|
|
403
403
|
genlayer staking validator-history 0x...
|
|
404
|
+
genlayer staking validator-history 0x... --epochs 5 # Last 5 epochs
|
|
405
|
+
genlayer staking validator-history 0x... --from-epoch 3 # From epoch 3
|
|
406
|
+
genlayer staking validator-history 0x... --all # Complete history (slow)
|
|
404
407
|
genlayer staking validator-history 0x... --limit 20
|
|
405
408
|
# Output:
|
|
406
|
-
#
|
|
407
|
-
# │ Time │ Epoch │ Type │ Details
|
|
408
|
-
#
|
|
409
|
-
# │ 12-11 14:20 │ 5 │ REWARD │ Val:
|
|
410
|
-
# │ 12-10 18:39 │ 4 │ SLASH │ 1.00%
|
|
411
|
-
#
|
|
409
|
+
# ┌─────────────┬───────┬────────┬────────┬────────────────────────────────────┐
|
|
410
|
+
# │ Time │ Epoch │ Type │ Details│ GL TxId / Block │
|
|
411
|
+
# ├─────────────┼───────┼────────┼────────┼────────────────────────────────────┤
|
|
412
|
+
# │ 12-11 14:20 │ 5 │ REWARD │ Val: …│ block 4725136 │
|
|
413
|
+
# │ 12-10 18:39 │ 4 │ SLASH │ 1.00% │ 0x52db90a9... │
|
|
414
|
+
# └─────────────┴───────┴────────┴────────┴────────────────────────────────────┘
|
|
412
415
|
|
|
413
416
|
# Exit and claim (requires validator wallet address)
|
|
414
417
|
genlayer staking validator-exit --validator 0x... --shares 100
|
package/dist/index.js
CHANGED
|
@@ -20078,7 +20078,7 @@ var require_cli_table3 = __commonJS({
|
|
|
20078
20078
|
import { program } from "commander";
|
|
20079
20079
|
|
|
20080
20080
|
// package.json
|
|
20081
|
-
var version = "0.32.
|
|
20081
|
+
var version = "0.32.8";
|
|
20082
20082
|
var package_default = {
|
|
20083
20083
|
name: "genlayer",
|
|
20084
20084
|
version,
|
|
@@ -52281,7 +52281,22 @@ var ValidatorHistoryAction = class extends StakingAction {
|
|
|
52281
52281
|
chain,
|
|
52282
52282
|
transport: http3(chain.rpcUrls.default.http[0])
|
|
52283
52283
|
});
|
|
52284
|
-
const
|
|
52284
|
+
const epochInfo = await client.getEpochInfo();
|
|
52285
|
+
const currentEpoch = epochInfo.currentEpoch;
|
|
52286
|
+
const defaultEpochs = 10n;
|
|
52287
|
+
let minEpoch = null;
|
|
52288
|
+
let fromBlock = "earliest";
|
|
52289
|
+
if (options.fromBlock) {
|
|
52290
|
+
fromBlock = BigInt(options.fromBlock);
|
|
52291
|
+
} else if (options.fromEpoch) {
|
|
52292
|
+
minEpoch = BigInt(options.fromEpoch);
|
|
52293
|
+
} else if (options.all) {
|
|
52294
|
+
console.log(source_default.yellow("Warning: Fetching all history from genesis. This may be slow for long-lived validators."));
|
|
52295
|
+
console.log(source_default.yellow("Consider using --epochs <n> or --from-epoch <n> for faster queries.\n"));
|
|
52296
|
+
} else {
|
|
52297
|
+
const numEpochs = options.epochs ? BigInt(options.epochs) : defaultEpochs;
|
|
52298
|
+
minEpoch = currentEpoch > numEpochs ? currentEpoch - numEpochs : 0n;
|
|
52299
|
+
}
|
|
52285
52300
|
const limit = options.limit ? parseInt(options.limit) : 50;
|
|
52286
52301
|
this.setSpinnerText("Fetching slash events...");
|
|
52287
52302
|
const slashLogs = await publicClient.getLogs({
|
|
@@ -52315,7 +52330,7 @@ var ValidatorHistoryAction = class extends StakingAction {
|
|
|
52315
52330
|
blockTimestamps.set(block.number, new Date(Number(block.timestamp) * 1e3));
|
|
52316
52331
|
});
|
|
52317
52332
|
}
|
|
52318
|
-
|
|
52333
|
+
let slashEvents = slashLogs.map((log) => ({
|
|
52319
52334
|
type: "slash",
|
|
52320
52335
|
epoch: log.args.epoch,
|
|
52321
52336
|
txId: log.args.txId,
|
|
@@ -52323,7 +52338,7 @@ var ValidatorHistoryAction = class extends StakingAction {
|
|
|
52323
52338
|
blockNumber: log.blockNumber,
|
|
52324
52339
|
timestamp: blockTimestamps.get(log.blockNumber) || /* @__PURE__ */ new Date(0)
|
|
52325
52340
|
}));
|
|
52326
|
-
|
|
52341
|
+
let rewardEvents = filteredRewardLogs.map((log) => ({
|
|
52327
52342
|
type: "reward",
|
|
52328
52343
|
epoch: log.args.epoch,
|
|
52329
52344
|
validatorRewards: log.args.validatorRewards,
|
|
@@ -52331,6 +52346,10 @@ var ValidatorHistoryAction = class extends StakingAction {
|
|
|
52331
52346
|
blockNumber: log.blockNumber,
|
|
52332
52347
|
timestamp: blockTimestamps.get(log.blockNumber) || /* @__PURE__ */ new Date(0)
|
|
52333
52348
|
}));
|
|
52349
|
+
if (minEpoch !== null) {
|
|
52350
|
+
slashEvents = slashEvents.filter((e2) => e2.epoch >= minEpoch);
|
|
52351
|
+
rewardEvents = rewardEvents.filter((e2) => e2.epoch >= minEpoch);
|
|
52352
|
+
}
|
|
52334
52353
|
const allEvents = [...slashEvents, ...rewardEvents];
|
|
52335
52354
|
allEvents.sort((a, b) => Number(b.blockNumber - a.blockNumber));
|
|
52336
52355
|
const limitedEvents = allEvents.slice(0, limit);
|
|
@@ -52384,7 +52403,9 @@ var ValidatorHistoryAction = class extends StakingAction {
|
|
|
52384
52403
|
console.log(source_default.bold(`History for ${validatorAddress}`));
|
|
52385
52404
|
console.log(table.toString());
|
|
52386
52405
|
console.log("");
|
|
52406
|
+
const epochRangeInfo = minEpoch !== null ? `epochs ${minEpoch}-${currentEpoch}` : options.fromBlock ? `from block ${options.fromBlock}` : "all epochs";
|
|
52387
52407
|
console.log(source_default.gray("Summary:"));
|
|
52408
|
+
console.log(source_default.gray(` Range: ${epochRangeInfo}`));
|
|
52388
52409
|
console.log(source_default.gray(` Slash events: ${slashEvents.length}`));
|
|
52389
52410
|
console.log(source_default.gray(` Reward events: ${rewardEvents.length}`));
|
|
52390
52411
|
console.log(source_default.gray(` Total validator rewards: ${client.formatStakingAmount(totalValidatorRewards)}`));
|
|
@@ -52392,6 +52413,7 @@ var ValidatorHistoryAction = class extends StakingAction {
|
|
|
52392
52413
|
if (allEvents.length > limit) {
|
|
52393
52414
|
console.log(source_default.gray(` (showing ${limit} of ${allEvents.length} events)`));
|
|
52394
52415
|
}
|
|
52416
|
+
console.log(source_default.gray(` Use --all to fetch complete history, --epochs <n> for last N epochs`));
|
|
52395
52417
|
console.log("");
|
|
52396
52418
|
} catch (error) {
|
|
52397
52419
|
this.failSpinner("Failed to get validator history", error.message || error);
|
|
@@ -53164,7 +53186,7 @@ function initializeStakingCommands(program2) {
|
|
|
53164
53186
|
const action = new StakingInfoAction();
|
|
53165
53187
|
await action.listValidators(options);
|
|
53166
53188
|
});
|
|
53167
|
-
staking.command("validator-history [validator]").description("Show slash and reward history for a validator").option("--validator <address>", "Validator address (deprecated, use positional arg)").option("--from-block <block>", "Start from this block number").option("--limit <count>", "Maximum number of events to show (default: 50)").option("--account <name>", "Account to use (for default validator address)").option("--network <network>", "Network to use (localnet, testnet-asimov)").option("--rpc <rpcUrl>", "RPC URL for the network").option("--staking-address <address>", "Staking contract address (overrides chain config)").action(async (validatorArg, options) => {
|
|
53189
|
+
staking.command("validator-history [validator]").description("Show slash and reward history for a validator (default: last 10 epochs)").option("--validator <address>", "Validator address (deprecated, use positional arg)").option("--epochs <count>", "Number of recent epochs to fetch (default: 10)").option("--from-epoch <epoch>", "Start from this epoch number").option("--from-block <block>", "Start from this block number (advanced)").option("--all", "Fetch complete history from genesis (slow)").option("--limit <count>", "Maximum number of events to show (default: 50)").option("--account <name>", "Account to use (for default validator address)").option("--network <network>", "Network to use (localnet, testnet-asimov)").option("--rpc <rpcUrl>", "RPC URL for the network").option("--staking-address <address>", "Staking contract address (overrides chain config)").action(async (validatorArg, options) => {
|
|
53168
53190
|
const validator = validatorArg || options.validator;
|
|
53169
53191
|
const action = new ValidatorHistoryAction();
|
|
53170
53192
|
await action.execute({ ...options, validator });
|
package/package.json
CHANGED
|
@@ -312,9 +312,12 @@ export function initializeStakingCommands(program: Command) {
|
|
|
312
312
|
|
|
313
313
|
staking
|
|
314
314
|
.command("validator-history [validator]")
|
|
315
|
-
.description("Show slash and reward history for a validator")
|
|
315
|
+
.description("Show slash and reward history for a validator (default: last 10 epochs)")
|
|
316
316
|
.option("--validator <address>", "Validator address (deprecated, use positional arg)")
|
|
317
|
-
.option("--
|
|
317
|
+
.option("--epochs <count>", "Number of recent epochs to fetch (default: 10)")
|
|
318
|
+
.option("--from-epoch <epoch>", "Start from this epoch number")
|
|
319
|
+
.option("--from-block <block>", "Start from this block number (advanced)")
|
|
320
|
+
.option("--all", "Fetch complete history from genesis (slow)")
|
|
318
321
|
.option("--limit <count>", "Maximum number of events to show (default: 50)")
|
|
319
322
|
.option("--account <name>", "Account to use (for default validator address)")
|
|
320
323
|
.option("--network <network>", "Network to use (localnet, testnet-asimov)")
|
|
@@ -30,7 +30,10 @@ const REWARD_EVENT_ABI = {
|
|
|
30
30
|
export interface ValidatorHistoryOptions extends StakingConfig {
|
|
31
31
|
validator?: string;
|
|
32
32
|
fromBlock?: string;
|
|
33
|
+
fromEpoch?: string;
|
|
34
|
+
epochs?: string;
|
|
33
35
|
limit?: string;
|
|
36
|
+
all?: boolean;
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
interface SlashEvent {
|
|
@@ -107,7 +110,30 @@ export class ValidatorHistoryAction extends StakingAction {
|
|
|
107
110
|
transport: http(chain.rpcUrls.default.http[0]),
|
|
108
111
|
});
|
|
109
112
|
|
|
110
|
-
|
|
113
|
+
// Determine epoch range for filtering
|
|
114
|
+
const epochInfo = await client.getEpochInfo();
|
|
115
|
+
const currentEpoch = epochInfo.currentEpoch;
|
|
116
|
+
const defaultEpochs = 10n;
|
|
117
|
+
|
|
118
|
+
let minEpoch: bigint | null = null;
|
|
119
|
+
let fromBlock: bigint | "earliest" = "earliest";
|
|
120
|
+
|
|
121
|
+
if (options.fromBlock) {
|
|
122
|
+
// Explicit block takes precedence
|
|
123
|
+
fromBlock = BigInt(options.fromBlock);
|
|
124
|
+
} else if (options.fromEpoch) {
|
|
125
|
+
// Filter by starting epoch
|
|
126
|
+
minEpoch = BigInt(options.fromEpoch);
|
|
127
|
+
} else if (options.all) {
|
|
128
|
+
// Fetch all history (warn user)
|
|
129
|
+
console.log(chalk.yellow("Warning: Fetching all history from genesis. This may be slow for long-lived validators."));
|
|
130
|
+
console.log(chalk.yellow("Consider using --epochs <n> or --from-epoch <n> for faster queries.\n"));
|
|
131
|
+
} else {
|
|
132
|
+
// Default: last N epochs
|
|
133
|
+
const numEpochs = options.epochs ? BigInt(options.epochs) : defaultEpochs;
|
|
134
|
+
minEpoch = currentEpoch > numEpochs ? currentEpoch - numEpochs : 0n;
|
|
135
|
+
}
|
|
136
|
+
|
|
111
137
|
const limit = options.limit ? parseInt(options.limit) : 50;
|
|
112
138
|
|
|
113
139
|
this.setSpinnerText("Fetching slash events...");
|
|
@@ -156,7 +182,7 @@ export class ValidatorHistoryAction extends StakingAction {
|
|
|
156
182
|
}
|
|
157
183
|
|
|
158
184
|
// Transform to typed events
|
|
159
|
-
|
|
185
|
+
let slashEvents: SlashEvent[] = slashLogs.map(log => ({
|
|
160
186
|
type: "slash" as const,
|
|
161
187
|
epoch: (log.args as any).epoch as bigint,
|
|
162
188
|
txId: (log.args as any).txId as string,
|
|
@@ -165,7 +191,7 @@ export class ValidatorHistoryAction extends StakingAction {
|
|
|
165
191
|
timestamp: blockTimestamps.get(log.blockNumber) || new Date(0),
|
|
166
192
|
}));
|
|
167
193
|
|
|
168
|
-
|
|
194
|
+
let rewardEvents: RewardEvent[] = filteredRewardLogs.map(log => ({
|
|
169
195
|
type: "reward" as const,
|
|
170
196
|
epoch: (log.args as any).epoch as bigint,
|
|
171
197
|
validatorRewards: (log.args as any).validatorRewards as bigint,
|
|
@@ -174,6 +200,12 @@ export class ValidatorHistoryAction extends StakingAction {
|
|
|
174
200
|
timestamp: blockTimestamps.get(log.blockNumber) || new Date(0),
|
|
175
201
|
}));
|
|
176
202
|
|
|
203
|
+
// Filter by epoch if specified
|
|
204
|
+
if (minEpoch !== null) {
|
|
205
|
+
slashEvents = slashEvents.filter(e => e.epoch >= minEpoch!);
|
|
206
|
+
rewardEvents = rewardEvents.filter(e => e.epoch >= minEpoch!);
|
|
207
|
+
}
|
|
208
|
+
|
|
177
209
|
// Combine and sort by block number descending
|
|
178
210
|
const allEvents: HistoryEvent[] = [...slashEvents, ...rewardEvents];
|
|
179
211
|
allEvents.sort((a, b) => Number(b.blockNumber - a.blockNumber));
|
|
@@ -243,7 +275,13 @@ export class ValidatorHistoryAction extends StakingAction {
|
|
|
243
275
|
console.log("");
|
|
244
276
|
|
|
245
277
|
// Summary
|
|
278
|
+
const epochRangeInfo = minEpoch !== null
|
|
279
|
+
? `epochs ${minEpoch}-${currentEpoch}`
|
|
280
|
+
: options.fromBlock
|
|
281
|
+
? `from block ${options.fromBlock}`
|
|
282
|
+
: "all epochs";
|
|
246
283
|
console.log(chalk.gray("Summary:"));
|
|
284
|
+
console.log(chalk.gray(` Range: ${epochRangeInfo}`));
|
|
247
285
|
console.log(chalk.gray(` Slash events: ${slashEvents.length}`));
|
|
248
286
|
console.log(chalk.gray(` Reward events: ${rewardEvents.length}`));
|
|
249
287
|
console.log(chalk.gray(` Total validator rewards: ${client.formatStakingAmount(totalValidatorRewards)}`));
|
|
@@ -251,6 +289,7 @@ export class ValidatorHistoryAction extends StakingAction {
|
|
|
251
289
|
if (allEvents.length > limit) {
|
|
252
290
|
console.log(chalk.gray(` (showing ${limit} of ${allEvents.length} events)`));
|
|
253
291
|
}
|
|
292
|
+
console.log(chalk.gray(` Use --all to fetch complete history, --epochs <n> for last N epochs`));
|
|
254
293
|
console.log("");
|
|
255
294
|
} catch (error: any) {
|
|
256
295
|
this.failSpinner("Failed to get validator history", error.message || error);
|