0

I am trying to calculate a proportional reward by using the percentage of a wallet balance compared to a token's total supply.

uint256 reward = walletBalance / totalSupply * rewardPool

However, the result is always 0 because anything below 1 is seen as 0 in solidity (no point number support)?

Is there a 'correct' way in doing division to find percentage in this case. All above variables are uint256 and with decimal 18.

2 Answers 2

1

seems like the easy solution is by moving the rewardPool to the numerator so

reward = walletBalance * rewardPool / totalSupply

0

Look into Solmate libraries to help you with this.

One exemple could be https://github.com/transmissions11/solmate/blob/main/src/utils/FixedPointMathLib.sol

Hope this helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.