Skip to content

Commit

Permalink
Merge pull request #71 from kphed/update-set-flywheelrewards
Browse files Browse the repository at this point in the history
Transfer balance from old the FlywheelRewards only if it's not the zero address
  • Loading branch information
Joeysantoro authored Nov 13, 2023
2 parents c9b4003 + ebb7d36 commit 379c738
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/FlywheelCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ contract FlywheelCore is Auth {
/// @notice optional booster module for calculating virtual balances on strategies
IFlywheelBooster public flywheelBooster;

error InvalidAddress();

constructor(
ERC20 _rewardToken,
IFlywheelRewards _flywheelRewards,
Expand Down Expand Up @@ -163,9 +165,12 @@ contract FlywheelCore is Auth {

/// @notice swap out the flywheel rewards contract
function setFlywheelRewards(IFlywheelRewards newFlywheelRewards) external requiresAuth {
uint256 oldRewardBalance = rewardToken.balanceOf(address(flywheelRewards));
if (oldRewardBalance > 0) {
rewardToken.safeTransferFrom(address(flywheelRewards), address(newFlywheelRewards), oldRewardBalance);
if (address(newFlywheelRewards) == address(0)) revert InvalidAddress();
if (address(flywheelRewards) != address(0)) {
uint256 oldRewardBalance = rewardToken.balanceOf(address(flywheelRewards));

if (oldRewardBalance != 0)
rewardToken.safeTransferFrom(address(flywheelRewards), address(newFlywheelRewards), oldRewardBalance);
}

flywheelRewards = newFlywheelRewards;
Expand Down

0 comments on commit 379c738

Please sign in to comment.