What is wrong with the math logic in the function? It shorts the supply of tokens and it distributes much less than expected.
if the contract owns 1000 tokens and the total ether fund size is 30 ether (accumulated by two contributions of 10 ether & 20 ether), then 33,33% of the 1000 tokens should be given to the contributor with a contribution of 10 ether and the rest to the contributor of 20 ether.
function distribute() external onlyOwner {
for (uint256 i = 0; i < contributors.length; i++) {
if (contributed[contributors[i]]) {
uint256 tokensToDistribute = ((token.balanceOf(environment)).mul(((contributions[contributors[i]].mul(100)).div(funds))).div(100));
token.transfer(contributors[i], tokensToDistribute);
tokensDistributed = tokensDistributed.add(tokensToDistribute);
emit TokensDistributed(contributors[i], environment, token.balanceOf(environment), tokensToDistribute, true);
}
}
}