From 294c691d1a314a0aa0b9bc25fe95c0409af8b4a6 Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Thu, 22 Feb 2024 19:28:12 -0300 Subject: [PATCH] chore(StakeManager): mark TODOs on division precision loss --- contracts/StakeManager.sol | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/contracts/StakeManager.sol b/contracts/StakeManager.sol index 120b97c..d93fbad 100644 --- a/contracts/StakeManager.sol +++ b/contracts/StakeManager.sol @@ -162,8 +162,8 @@ contract StakeManager is Ownable { } _processAccount(account, currentEpoch); - uint256 reducedMP = (_amount * account.currentMP) / account.balance; - uint256 reducedInitialMP = (_amount * account.initialMP) / account.balance; + uint256 reducedMP = ((_amount * account.currentMP) / account.balance); //TODO: fix precision loss + uint256 reducedInitialMP = ((_amount * account.initialMP) / account.balance); //TODO: fix precision loss //update storage account.balance -= _amount; @@ -324,8 +324,8 @@ contract StakeManager is Ownable { //mint multiplier points to that epoch _mintMP(account, iEpoch.startTime + EPOCH_SIZE, iEpoch); uint256 userSupply = account.balance + account.currentMP; - uint256 userShare = (userSupply / iEpoch.totalSupply) * 100; - uint256 userEpochReward = (userShare * iEpoch.epochReward) / 100; + uint256 userShare = userSupply / iEpoch.totalSupply; //TODO: fix precision loss; + uint256 userEpochReward = userShare * iEpoch.epochReward; userReward += userEpochReward; iEpoch.epochReward -= userEpochReward; iEpoch.totalSupply -= userSupply; @@ -432,7 +432,7 @@ contract StakeManager is Ownable { * @return _increasedMP increased multiplier points */ function _getIncreasedMP(uint256 _balance, uint256 _deltaTime) private pure returns (uint256 _increasedMP) { - return _balance * ((_deltaTime / YEAR) * MP_APY); + return _balance * ((_deltaTime / YEAR) * MP_APY); //TODO: fix precision loss } /**