-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
61076f9
commit 5b0a5cc
Showing
2 changed files
with
25 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,39 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
pragma solidity 0.8.16; | ||
pragma solidity ^0.8.16; | ||
|
||
import "./interfaces/IPenalty.sol"; | ||
import "./interfaces/IStaderConfig.sol"; | ||
import "./interfaces/IBatchReader.sol"; | ||
|
||
/// @title Batch Reader Contract | ||
/// @notice Provides batch operations for reading penalties and balances | ||
contract BatchReader is IBatchReader { | ||
IPenalty public penaltyContract; | ||
IStaderConfig immutable staderConfig; | ||
IPenalty public immutable PENALTY_CONTRACT; | ||
|
||
/// @param _staderConfig Address of the StaderConfig contract | ||
constructor(address _staderConfig) { | ||
require(_staderConfig != address(0), "Invalid StaderConfig address"); | ||
require(_staderConfig != address(0), "BatchReader: invalid StaderConfig address"); | ||
|
||
staderConfig = IStaderConfig(_staderConfig); | ||
penaltyContract = IPenalty(staderConfig.getPenaltyContract()); | ||
PENALTY_CONTRACT = IPenalty(IStaderConfig(_staderConfig).getPenaltyContract()); | ||
} | ||
|
||
/// @notice Reads the total penalty amounts for a batch of validators. | ||
function getTotalPenaltyAmounts(bytes[] calldata _pubkeys) external view override returns (uint256[] memory) { | ||
uint256[] memory penalties = new uint256[](_pubkeys.length); | ||
/// @notice Reads the total penalty amounts for a batch of validators | ||
/// @param _pubkeys Public keys of the validators | ||
/// @return penalties Array of total penalty amounts for each validator | ||
function getTotalPenaltyAmounts(bytes[] calldata _pubkeys) external view override returns (uint256[] memory penalties) { | ||
penalties = new uint256[](_pubkeys.length); | ||
for (uint256 i = 0; i < _pubkeys.length; i++) { | ||
penalties[i] = penaltyContract.totalPenaltyAmount(_pubkeys[i]); | ||
penalties[i] = PENALTY_CONTRACT.totalPenaltyAmount(_pubkeys[i]); | ||
} | ||
} | ||
|
||
/// @notice Gets balances for multiple addresses | ||
/// @param _addresses Array of Ethereum addresses | ||
/// @return balances Array of balances for the provided addresses | ||
function getBalances(address[] calldata _addresses) external view override returns (uint256[] memory balances) { | ||
balances = new uint256[](_addresses.length); | ||
for (uint256 i = 0; i < _addresses.length; i++) { | ||
balances[i] = _addresses[i].balance; | ||
} | ||
return penalties; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters