Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Rayerleier committed Dec 5, 2024
1 parent 6543666 commit 6222fe8
Showing 1 changed file with 14 additions and 42 deletions.
56 changes: 14 additions & 42 deletions src/iBTC_NetworkMiddleware.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ contract NetworkMiddleware is SimpleKeyRegistry32, Ownable {
EnumerableMap.AddressToUintMap private operators;
EnumerableMap.AddressToUintMap private vaults;

modifier updateStakeCache(
uint48 epoch
) {
modifier updateStakeCache(uint48 epoch) {
if (!totalStakeCached[epoch]) {
calcAndCacheStakes(epoch);
}
Expand Down Expand Up @@ -109,15 +107,11 @@ contract NetworkMiddleware is SimpleKeyRegistry32, Ownable {
subnetworksCnt = 1;
}

function getEpochStartTs(
uint48 epoch
) public view returns (uint48 timestamp) {
function getEpochStartTs(uint48 epoch) public view returns (uint48 timestamp) {
return START_TIME + epoch * EPOCH_DURATION;
}

function getEpochAtTs(
uint48 timestamp
) public view returns (uint48 epoch) {
function getEpochAtTs(uint48 timestamp) public view returns (uint48 epoch) {
return (timestamp - START_TIME) / EPOCH_DURATION;
}

Expand Down Expand Up @@ -177,21 +171,15 @@ contract NetworkMiddleware is SimpleKeyRegistry32, Ownable {
updateKey(operator, key);
}

function pauseOperator(
address operator
) external onlyOwner {
function pauseOperator(address operator) external onlyOwner {
operators.disable(operator);
}

function unpauseOperator(
address operator
) external onlyOwner {
function unpauseOperator(address operator) external onlyOwner {
operators.enable(operator);
}

function unregisterOperator(
address operator
) external onlyOwner {
function unregisterOperator(address operator) external onlyOwner {
(, uint48 disabledTime) = operators.getTimes(operator);

if (disabledTime == 0 || disabledTime + SLASHING_WINDOW > Time.timestamp()) {
Expand All @@ -201,9 +189,7 @@ contract NetworkMiddleware is SimpleKeyRegistry32, Ownable {
operators.remove(operator);
}

function registerVault(
address vault
) external onlyOwner {
function registerVault(address vault) external onlyOwner {
if (vaults.contains(vault)) {
revert VaultAlreadyRegistred();
}
Expand All @@ -227,21 +213,15 @@ contract NetworkMiddleware is SimpleKeyRegistry32, Ownable {
vaults.enable(vault);
}

function pauseVault(
address vault
) external onlyOwner {
function pauseVault(address vault) external onlyOwner {
vaults.disable(vault);
}

function unpauseVault(
address vault
) external onlyOwner {
function unpauseVault(address vault) external onlyOwner {
vaults.enable(vault);
}

function unregisterVault(
address vault
) external onlyOwner {
function unregisterVault(address vault) external onlyOwner {
(, uint48 disabledTime) = vaults.getTimes(vault);

if (disabledTime == 0 || disabledTime + SLASHING_WINDOW > Time.timestamp()) {
Expand Down Expand Up @@ -286,18 +266,14 @@ contract NetworkMiddleware is SimpleKeyRegistry32, Ownable {
return stake;
}

function getTotalStake(
uint48 epoch
) public view returns (uint256) {
function getTotalStake(uint48 epoch) public view returns (uint256) {
if (totalStakeCached[epoch]) {
return totalStakeCache[epoch];
}
return _calcTotalStake(epoch);
}

function getValidatorSet(
uint48 epoch
) public view returns (ValidatorData[] memory validatorsData) {
function getValidatorSet(uint48 epoch) public view returns (ValidatorData[] memory validatorsData) {
uint48 epochStartTs = getEpochStartTs(epoch);

validatorsData = new ValidatorData[](operators.length());
Expand Down Expand Up @@ -364,9 +340,7 @@ contract NetworkMiddleware is SimpleKeyRegistry32, Ownable {
}
}

function calcAndCacheStakes(
uint48 epoch
) public returns (uint256 totalStake) {
function calcAndCacheStakes(uint48 epoch) public returns (uint256 totalStake) {
uint48 epochStartTs = getEpochStartTs(epoch);

// for epoch older than SLASHING_WINDOW total stake can be invalidated (use cache)
Expand Down Expand Up @@ -396,9 +370,7 @@ contract NetworkMiddleware is SimpleKeyRegistry32, Ownable {
totalStakeCache[epoch] = totalStake;
}

function _calcTotalStake(
uint48 epoch
) private view returns (uint256 totalStake) {
function _calcTotalStake(uint48 epoch) private view returns (uint256 totalStake) {
uint48 epochStartTs = getEpochStartTs(epoch);

// for epoch older than SLASHING_WINDOW total stake can be invalidated (use cache)
Expand Down

0 comments on commit 6222fe8

Please sign in to comment.