Skip to content

Commit

Permalink
👷 Adjust compound rewards to newly non escrowed rewards
Browse files Browse the repository at this point in the history
  • Loading branch information
Flocqst committed Jul 8, 2024
1 parent 43300af commit 371f847
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions contracts/StakingRewardsV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,14 @@ contract StakingRewardsV2 is
///////////////////////////////////////////////////////////////*/

/// @inheritdoc IStakingRewardsV2
function stake(uint256 _amount) external whenNotPaused updateReward(msg.sender) {
function stake(uint256 _amount) external whenNotPaused {
_stake(_amount);

// transfer token to this contract from the caller
kwenta.transferFrom(msg.sender, address(this), _amount);
}

function _stake(uint256 _amount) external whenNotPaused updateReward(msg.sender) {
if (_amount == 0) revert AmountZero();

// update state
Expand All @@ -224,9 +231,6 @@ contract StakingRewardsV2 is

// emit staking event and index msg.sender
emit Staked(msg.sender, _amount);

// transfer token to this contract from the caller
kwenta.transferFrom(msg.sender, address(this), _amount);
}

/// @inheritdoc IStakingRewardsV2
Expand Down Expand Up @@ -350,6 +354,22 @@ contract StakingRewardsV2 is
}
}

function _getRewardCompounding(address _account)
internal
whenNotPaused
updateReward(_account)
returns (uint256 reward)
{
uint256 reward = rewards[_account];
if (reward > 0) {
// update state (first)
rewards[_account] = 0;

// emit reward claimed event and index account
emit RewardPaid(_account, reward);
}
}

/// @inheritdoc IStakingRewardsV2
function compound() external {
_compound(msg.sender);
Expand All @@ -358,8 +378,8 @@ contract StakingRewardsV2 is
/// @dev internal helper to compound for a given account
/// @param _account the account to compound for
function _compound(address _account) internal {
_getReward(_account);
_stakeEscrow(_account, unstakedEscrowedBalanceOf(_account));
uint256 reward = _getRewardCompounding(_account);
_stake(reward);
}

/*///////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 371f847

Please sign in to comment.