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

Decimals offset fix 2 #122

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 7 additions & 3 deletions src/WrappedVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ contract WrappedVault is Owned, ERC20, IWrappedVault {

if (rate < rewardsInterval.rate) revert RateCannotDecrease();

rewardsAdded = (rate - rewardsInterval.rate) * (newEnd - newStart) + frontendFeeTaken + protocolFeeTaken;

rewardsInterval.start = newStart;
rewardsInterval.end = newEnd.toUint32();
rewardsInterval.rate = rate.toUint96();
Expand Down Expand Up @@ -290,6 +292,7 @@ contract WrappedVault is Owned, ERC20, IWrappedVault {
// Calculate the rate
uint256 rewardsAfterFee = totalRewards - frontendFeeTaken - protocolFeeTaken;
uint256 rate = rewardsAfterFee / (end - start);
totalRewards = rate * (end - start) + frontendFeeTaken + protocolFeeTaken;

if (rate == 0) revert NoZeroRateAllowed();

Expand Down Expand Up @@ -351,9 +354,10 @@ contract WrappedVault is Owned, ERC20, IWrappedVault {

uint256 elapsedWAD = elapsed * 1e18;
// Calculate and update the new value of the accumulator.
rewardsPerTokenOut.accumulated = (rewardsPerTokenIn.accumulated + (elapsedWAD.mulDivDown(rewardsInterval_.rate, totalSupply))); // The
rewardsPerTokenOut.accumulated = (rewardsPerTokenIn.accumulated + (elapsedWAD.mulDivDown(rewardsInterval_.rate, VAULT.convertToAssets(totalSupply)))); // The
// rewards per token are scaled up for precision


return rewardsPerTokenOut;
}

Expand Down Expand Up @@ -397,7 +401,7 @@ contract WrappedVault is Owned, ERC20, IWrappedVault {
if (userRewards_.checkpoint == rewardsPerToken_.accumulated) return userRewards_;

// Calculate and update the new value user reserves.
userRewards_.accumulated += _calculateUserRewards(balanceOf[user], userRewards_.checkpoint, rewardsPerToken_.accumulated).toUint128();
userRewards_.accumulated += _calculateUserRewards(VAULT.convertToAssets(balanceOf[user]), userRewards_.checkpoint, rewardsPerToken_.accumulated).toUint128();
userRewards_.checkpoint = rewardsPerToken_.accumulated;

rewardToUserToAR[reward][user] = userRewards_;
Expand Down Expand Up @@ -473,7 +477,7 @@ contract WrappedVault is Owned, ERC20, IWrappedVault {
function currentUserRewards(address reward, address user) public view returns (uint256) {
UserRewards memory accumulatedRewards_ = rewardToUserToAR[reward][user];
RewardsPerToken memory rewardsPerToken_ = _calculateRewardsPerToken(rewardToRPT[reward], rewardToInterval[reward]);
return accumulatedRewards_.accumulated + _calculateUserRewards(balanceOf[user], accumulatedRewards_.checkpoint, rewardsPerToken_.accumulated);
return accumulatedRewards_.accumulated + _calculateUserRewards(VAULT.convertToAssets(balanceOf[user]), accumulatedRewards_.checkpoint, rewardsPerToken_.accumulated);
}

/// @notice Calculates the rate a user would receive in rewards after depositing assets
Expand Down
Loading