The withdrawal amount will be counted as part of the surplus asset balance mistakenly if block.timestamp >= rewardsCycleEnd.
function beforeWithdraw(uint256 assets, uint256 shares) internal override {
super.beforeWithdraw(assets, shares); // call xERC4626's beforeWithdraw first
if (block.timestamp >= rewardsCycleEnd) { syncRewards(); }
}
storedTotalAssets will be deducted by the withdrawal amount in xERC4626.sol#beforeWithdraw().
At sfrxETH.sol#L50, when block.timestamp >= rewardsCycleEnd, syncRewards() will be called AFTER storedTotalAssets -= amount; (xERC4626.sol#L67).
In syncRewards(), storedTotalAssets will be used to calculate the rewards.
> All surplus asset balance of the contract over the internal balance becomes queued for the next cycle.
uint256 storedTotalAssets_ = storedTotalAssets;
uint256 nextRewards = asset.balanceOf(address(this)) - storedTotalAssets_ - lastRewardAmount_;
storedTotalAssets = storedTotalAssets_ + lastRewardAmount_; // SSTORE
Consider calling syncRewards() before call xERC4626’s beforeWithdraw.
The text was updated successfully, but these errors were encountered:
All reactions