Skip to content

Commit

Permalink
Merge pull request #209 from pooltogether/pool-1749-drawcalculator-de…
Browse files Browse the repository at this point in the history
…termine-if-the

Removed totalSupply = 0 revert
  • Loading branch information
aodhgan committed Oct 8, 2021
2 parents 5ab9123 + 73f25eb commit 201b9a0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
8 changes: 6 additions & 2 deletions contracts/DrawCalculator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,12 @@ contract DrawCalculator is IDrawCalculator, Ownable {

// divide balances by total supplies (normalize)
for (uint256 i = 0; i < _draws.length; i++) {
require(totalSupplies[i] > 0, "DrawCalc/total-supply-zero");
normalizedBalances[i] = (balances[i] * 1 ether) / totalSupplies[i];
if(totalSupplies[i] == 0){
normalizedBalances[i] = 0;
}
else {
normalizedBalances[i] = (balances[i] * 1 ether) / totalSupplies[i];
}
}

return normalizedBalances;
Expand Down
9 changes: 5 additions & 4 deletions test/DrawCalculator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ describe('DrawCalculator', () => {
expect(userNormalizedBalances[1]).to.eq(utils.parseEther('0.05'));
});

it('reverts when totalSupply is zero', async () => {
it('returns 0 when totalSupply is zero', async () => {
const timestamps = [42, 77];

const prizeDistribution: PrizeDistribution = {
Expand Down Expand Up @@ -671,9 +671,10 @@ describe('DrawCalculator', () => {
.withArgs(offsetStartTimestamps, offsetEndTimestamps)
.returns([utils.parseEther('0'), utils.parseEther('600')]);

await expect(
drawCalculator.getNormalizedBalancesForDrawIds(wallet1.address, [1, 2]),
).to.be.revertedWith('DrawCalc/total-supply-zero');

const balancesResult = await drawCalculator.getNormalizedBalancesForDrawIds(wallet1.address, [1, 2])
expect(balancesResult[0]).to.equal(0)

});

it('returns zero when the balance is very small', async () => {
Expand Down

0 comments on commit 201b9a0

Please sign in to comment.