Skip to content

Commit

Permalink
Merge pull request #99 from GenerationSoftware/gen-1169-prizepoolgetv…
Browse files Browse the repository at this point in the history
…aultportion-fails-if-only-donations-were-given

Fixed issue when only donations were given
  • Loading branch information
asselstine authored Mar 1, 2024
2 parents 9b7605e + 8c073ae commit 3344d3c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/PrizePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,11 @@ contract PrizePool is TieredLiquidityDistributor {

uint256 totalDonated = DrawAccumulatorLib.getDisbursedBetween(_vaultAccumulator[DONATOR], _startDrawIdInclusive, _endDrawIdInclusive);

// vaultContributed / totalContributed
uint256 total = totalContributed - totalDonated;

if (total == 0) {
return sd(0);
}
return
totalContributed != 0
? sd(
Expand All @@ -1030,7 +1034,7 @@ contract PrizePool is TieredLiquidityDistributor {
_endDrawIdInclusive
)
)
).div(sd(SafeCast.toInt256(totalContributed - totalDonated)))
).div(sd(SafeCast.toInt256(total)))
: sd(0);
}

Expand Down
8 changes: 8 additions & 0 deletions test/PrizePool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,14 @@ contract PrizePoolTest is Test {
assertEq(prizePool.getVaultPortion(address(vault2), 1, 1).unwrap(), 0.5e18);
}

function testGetVaultPortion_handlesOnlyDonation() public {
prizeToken.mint(address(this), 100);
prizeToken.approve(address(prizePool), 100);
prizePool.donatePrizeTokens(100);

assertEq(prizePool.getVaultPortion(address(vault2), 1, 1).unwrap(), 0);
}

function testGetOpenDrawId() public {
uint256 openDrawId = prizePool.getOpenDrawId();
assertEq(openDrawId, 1);
Expand Down

0 comments on commit 3344d3c

Please sign in to comment.