Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore encapsulation of distributions layout, broken by gas optimisa… #13

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/BaseRewardStreams.sol
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,7 @@ abstract contract BaseRewardStreams is IRewardStreams, EVCUtil, ReentrancyGuard
address reward,
uint48 epoch
) public view virtual override returns (uint256) {
DistributionStorage storage distributionStorage = distributions[rewarded][reward];
return distributionStorage.amounts[epoch / EPOCHS_PER_SLOT][epoch % EPOCHS_PER_SLOT];
return rewardAmount(distributions[rewarded][reward], epoch);
}

/// @notice Returns the current epoch based on the block timestamp.
Expand Down Expand Up @@ -444,6 +443,17 @@ abstract contract BaseRewardStreams is IRewardStreams, EVCUtil, ReentrancyGuard
}
}

/// @notice Returns the reward token amount for an epoch, given a pre-computed distribution storage pointer.
/// @param distributionStorage Pre-computed distribution storage pointer.
/// @param epoch The epoch to get the reward token amount for.
/// @return The reward token amount.
function rewardAmount(
DistributionStorage storage distributionStorage,
uint48 epoch
) internal view returns (uint256) {
return distributionStorage.amounts[epoch / EPOCHS_PER_SLOT][epoch % EPOCHS_PER_SLOT];
}

/// @notice Increases the reward token amounts for a specific rewarded token.
/// @param rewarded The address of the rewarded token.
/// @param reward The address of the reward token.
Expand Down Expand Up @@ -574,7 +584,7 @@ abstract contract BaseRewardStreams is IRewardStreams, EVCUtil, ReentrancyGuard
for (uint48 epoch = epochStart; epoch < epochEnd; ++epoch) {
// Overflow safe because `totalRegistered * SCALER <= type(uint144).max < type(uint256).max`.
unchecked {
uint256 amount = distributionStorage.amounts[epoch / EPOCHS_PER_SLOT][epoch % EPOCHS_PER_SLOT];
uint256 amount = rewardAmount(distributionStorage, epoch);
delta += SCALER * timeElapsedInEpoch(epoch, lastUpdated) * amount / EPOCH_DURATION;
}
}
Expand Down
Loading