genlayer-js 0.18.7 → 0.18.9

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.
@@ -8,6 +8,7 @@ import {
8
8
  BannedValidatorInfo,
9
9
  StakeInfo,
10
10
  EpochInfo,
11
+ EpochData,
11
12
  StakingTransactionResult,
12
13
  ValidatorJoinResult,
13
14
  DelegatorJoinResult,
@@ -559,6 +560,7 @@ export const stakingActions = (
559
560
 
560
561
  const [
561
562
  epoch,
563
+ finalized,
562
564
  validatorMinStake,
563
565
  delegatorMinStake,
564
566
  activeCount,
@@ -568,6 +570,7 @@ export const stakingActions = (
568
570
  epochEven,
569
571
  ] = await Promise.all([
570
572
  contract.read.epoch() as Promise<bigint>,
573
+ contract.read.finalized() as Promise<bigint>,
571
574
  contract.read.validatorMinStake() as Promise<bigint>,
572
575
  contract.read.delegatorMinStake() as Promise<bigint>,
573
576
  contract.read.activeValidatorsCount() as Promise<bigint>,
@@ -577,13 +580,11 @@ export const stakingActions = (
577
580
  contract.read.epochEven() as Promise<any>,
578
581
  ]);
579
582
 
580
- // Current epoch data (even epochs use epochEven, odd use epochOdd)
583
+ // Current epoch data for next epoch estimate
581
584
  const currentEpochData = epoch % 2n === 0n ? epochEven : epochOdd;
582
- const currentEpochStart = new Date(Number(currentEpochData.start) * 1000);
583
- const currentEpochEnd = currentEpochData.end > 0n ? new Date(Number(currentEpochData.end) * 1000) : null;
585
+ const currentEpochEnd = currentEpochData.end > 0n;
584
586
 
585
587
  // Estimate next epoch: current start + min duration (if epoch hasn't ended)
586
- // Epoch 0 uses epochZeroMinDuration, all other epochs use epochMinDuration
587
588
  let nextEpochEstimate: Date | null = null;
588
589
  if (!currentEpochEnd) {
589
590
  const duration = epoch === 0n ? epochZeroMinDuration : epochMinDuration;
@@ -593,20 +594,50 @@ export const stakingActions = (
593
594
 
594
595
  return {
595
596
  currentEpoch: epoch,
597
+ lastFinalizedEpoch: finalized,
596
598
  validatorMinStake: formatStakingAmount(validatorMinStake),
597
599
  validatorMinStakeRaw: validatorMinStake,
598
600
  delegatorMinStake: formatStakingAmount(delegatorMinStake),
599
601
  delegatorMinStakeRaw: delegatorMinStake,
600
602
  activeValidatorsCount: activeCount,
601
603
  epochMinDuration,
602
- currentEpochStart,
603
- currentEpochEnd,
604
604
  nextEpochEstimate,
605
- inflation: formatStakingAmount(currentEpochData.inflation),
606
- inflationRaw: currentEpochData.inflation,
607
- totalWeight: currentEpochData.weight,
608
- totalClaimed: formatStakingAmount(currentEpochData.claimed),
609
- totalClaimedRaw: currentEpochData.claimed,
605
+ };
606
+ },
607
+
608
+ getEpochData: async (epochNumber: bigint): Promise<EpochData> => {
609
+ const contract = getReadOnlyStakingContract();
610
+
611
+ const [currentEpoch, epochOdd, epochEven] = await Promise.all([
612
+ contract.read.epoch() as Promise<bigint>,
613
+ contract.read.epochOdd() as Promise<any>,
614
+ contract.read.epochEven() as Promise<any>,
615
+ ]);
616
+
617
+ // Epochs alternate between odd/even storage slots
618
+ // Current epoch N uses: N % 2 === 0 ? epochEven : epochOdd
619
+ // We can only access current epoch and previous epoch (N-1)
620
+ if (epochNumber > currentEpoch) {
621
+ throw new Error(`Epoch ${epochNumber} has not started yet (current: ${currentEpoch})`);
622
+ }
623
+ if (epochNumber < currentEpoch - 1n && currentEpoch > 0n) {
624
+ throw new Error(`Epoch ${epochNumber} data no longer available (only current and previous epoch stored)`);
625
+ }
626
+
627
+ const epochData = epochNumber % 2n === 0n ? epochEven : epochOdd;
628
+
629
+ return {
630
+ start: epochData.start,
631
+ end: epochData.end,
632
+ inflation: epochData.inflation,
633
+ weight: epochData.weight,
634
+ weightDeposit: epochData.weightDeposit,
635
+ weightWithdrawal: epochData.weightWithdrawal,
636
+ vcount: epochData.vcount,
637
+ claimed: epochData.claimed,
638
+ stakeDeposit: epochData.stakeDeposit,
639
+ stakeWithdrawal: epochData.stakeWithdrawal,
640
+ slashed: epochData.slashed,
610
641
  };
611
642
  },
612
643
 
@@ -646,6 +677,13 @@ export const stakingActions = (
646
677
  }));
647
678
  },
648
679
 
680
+ getSlashingAddress: async (): Promise<Address> => {
681
+ const contract = getReadOnlyStakingContract();
682
+ // contracts() returns tuple: [gen, transactions, idleness, tribunal, slashing, consensus, validatorWalletFactory, nftMinter]
683
+ const externalContracts = (await contract.read.contracts()) as readonly ViemAddress[];
684
+ return externalContracts[4] as Address; // slashing is at index 4
685
+ },
686
+
649
687
  getStakingContract,
650
688
  parseStakingAmount,
651
689
  formatStakingAmount,
@@ -114,24 +114,19 @@ export interface EpochData {
114
114
  claimed: bigint;
115
115
  stakeDeposit: bigint;
116
116
  stakeWithdrawal: bigint;
117
+ slashed: bigint;
117
118
  }
118
119
 
119
120
  export interface EpochInfo {
120
121
  currentEpoch: bigint;
122
+ lastFinalizedEpoch: bigint;
121
123
  validatorMinStake: string;
122
124
  validatorMinStakeRaw: bigint;
123
125
  delegatorMinStake: string;
124
126
  delegatorMinStakeRaw: bigint;
125
127
  activeValidatorsCount: bigint;
126
128
  epochMinDuration: bigint;
127
- currentEpochStart: Date;
128
- currentEpochEnd: Date | null;
129
129
  nextEpochEstimate: Date | null;
130
- inflation: string;
131
- inflationRaw: bigint;
132
- totalWeight: bigint;
133
- totalClaimed: string;
134
- totalClaimedRaw: bigint;
135
130
  }
136
131
 
137
132
  export interface StakingTransactionResult {
@@ -220,8 +215,10 @@ export interface StakingActions {
220
215
  getValidatorInfo: (validator: Address) => Promise<ValidatorInfo>;
221
216
  getStakeInfo: (delegator: Address, validator: Address) => Promise<StakeInfo>;
222
217
  getEpochInfo: () => Promise<EpochInfo>;
218
+ getEpochData: (epochNumber: bigint) => Promise<EpochData>;
223
219
  getActiveValidators: () => Promise<Address[]>;
224
220
  getActiveValidatorsCount: () => Promise<bigint>;
221
+ getSlashingAddress: () => Promise<Address>;
225
222
  getStakingContract: () => StakingContract;
226
223
  parseStakingAmount: (amount: string | bigint) => bigint;
227
224
  formatStakingAmount: (amount: bigint) => string;
@@ -153,6 +153,21 @@ export type DecodedCallData = {
153
153
  type: TransactionType;
154
154
  };
155
155
 
156
+ export interface LeaderReceipt {
157
+ calldata: string;
158
+ class_name: string;
159
+ contract_state: string;
160
+ eq_outputs: Record<string, unknown>;
161
+ error: string | null;
162
+ execution_result: string;
163
+ gas_used: number;
164
+ mode: string;
165
+ node_config: Record<string, unknown>;
166
+ pending_transactions: unknown[];
167
+ vote: string;
168
+ result: string;
169
+ }
170
+
156
171
  // TODO: make localnet compatible with testnet and unify the types
157
172
  export type GenLayerTransaction = {
158
173
  // currentTimestamp: testnet
@@ -243,20 +258,7 @@ export type GenLayerTransaction = {
243
258
  // consensus_data: localnet // leader_receipt: testnet
244
259
  consensus_data?: {
245
260
  final: boolean;
246
- leader_receipt?: {
247
- calldata: string;
248
- class_name: string;
249
- contract_state: string;
250
- eq_outputs: Record<string, unknown>;
251
- error: string | null;
252
- execution_result: string;
253
- gas_used: number;
254
- mode: string;
255
- node_config: Record<string, unknown>;
256
- pending_transactions: unknown[];
257
- vote: string;
258
- result: string;
259
- }[];
261
+ leader_receipt?: LeaderReceipt[];
260
262
  validators?: Record<string, unknown>[];
261
263
  votes?: Record<string, string>;
262
264
  };