Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #348 from maticnetwork/fixes-v2
Browse files Browse the repository at this point in the history
Fixes v2
  • Loading branch information
jdkanani authored Mar 2, 2021
2 parents 357ae25 + 4f63c14 commit 6f755fb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 3 additions & 1 deletion contracts/staking/stakeManager/StakeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,9 @@ contract StakeManager is
}
}

validators[validatorId].initialRewardPerStake = newRewardPerStake;
if (newRewardPerStake > initialRewardPerStake) {
validators[validatorId].initialRewardPerStake = newRewardPerStake;
}
}

function _updateRewards(uint256 validatorId) private {
Expand Down
7 changes: 5 additions & 2 deletions contracts/staking/stakeManager/StakeManagerExtension.sol
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,15 @@ contract StakeManagerExtension is StakeManagerStorage, Initializable, StakeManag
for (uint256 i = validatorIdFrom; i < validatorIdTo; ++i) {
ValidatorShare contractAddress = ValidatorShare(validators[i].contractAddress);
if (contractAddress != ValidatorShare(0)) {
validators[i].delegatorsReward = contractAddress.validatorRewards_deprecated().add(INITIALIZED_AMOUNT);
// move validator rewards out from ValidatorShare contract
validators[i].reward = contractAddress.validatorRewards_deprecated().add(INITIALIZED_AMOUNT);
validators[i].delegatedAmount = contractAddress.activeAmount();
validators[i].commissionRate = contractAddress.commissionRate_deprecated();
} else {
validators[i].reward = validators[i].reward.add(INITIALIZED_AMOUNT);
}

validators[i].reward = validators[i].reward.add(INITIALIZED_AMOUNT);
validators[i].delegatorsReward = INITIALIZED_AMOUNT;
}
}

Expand Down
7 changes: 6 additions & 1 deletion contracts/staking/validatorShare/ValidatorShare.sol
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ contract ValidatorShare is IValidatorShare, ERC20NonTradable, OwnableLockable, I
}

function migrateIn(address user, uint256 amount) external onlyOwner {
_withdrawAndTransferReward(user);
_buyShares(amount, 0, user);
}

Expand Down Expand Up @@ -317,7 +318,11 @@ contract ValidatorShare is IValidatorShare, ERC20NonTradable, OwnableLockable, I
function _calculateRewardPerShareWithRewards(uint256 accumulatedReward) private view returns (uint256) {
uint256 _rewardPerShare = rewardPerShare;
if (accumulatedReward != 0) {
_rewardPerShare = _rewardPerShare.add(accumulatedReward.mul(_getRatePrecision()).div(totalSupply()));
uint256 totalShares = totalSupply();

if (totalShares != 0) {
_rewardPerShare = _rewardPerShare.add(accumulatedReward.mul(_getRatePrecision()).div(totalShares));
}
}

return _rewardPerShare;
Expand Down

0 comments on commit 6f755fb

Please sign in to comment.