diff --git a/src/PrizePool.sol b/src/PrizePool.sol index 4cb2971..bad9bd0 100644 --- a/src/PrizePool.sol +++ b/src/PrizePool.sol @@ -692,7 +692,7 @@ contract PrizePool is TieredLiquidityDistributor { /// @return The number of draws function getTierAccrualDurationInDraws(uint8 _tier) external view returns (uint24) { return - uint24(TierCalculationLib.estimatePrizeFrequencyInDraws(getTierOdds(_tier, numberOfTiers))); + TierCalculationLib.estimatePrizeFrequencyInDraws(getTierOdds(_tier, numberOfTiers), grandPrizePeriodDraws); } /// @notice The total amount of prize tokens that have been withdrawn as fees or prizes @@ -1011,7 +1011,7 @@ contract PrizePool is TieredLiquidityDistributor { } SD59x18 tierOdds = getTierOdds(_tier, numberOfTiers); - uint24 startDrawIdInclusive = computeRangeStartDrawIdInclusive(lastAwardedDrawId_, uint24(TierCalculationLib.estimatePrizeFrequencyInDraws(tierOdds))); + uint24 startDrawIdInclusive = computeRangeStartDrawIdInclusive(lastAwardedDrawId_, TierCalculationLib.estimatePrizeFrequencyInDraws(tierOdds, grandPrizePeriodDraws)); uint32 tierPrizeCount = uint32(TierCalculationLib.prizeCount(_tier)); diff --git a/src/libraries/TierCalculationLib.sol b/src/libraries/TierCalculationLib.sol index 5dd7fb4..a614af3 100644 --- a/src/libraries/TierCalculationLib.sol +++ b/src/libraries/TierCalculationLib.sol @@ -27,10 +27,13 @@ library TierCalculationLib { } /// @notice Estimates the number of draws between a tier occurring. + /// @dev Limits the frequency to the grand prize period in draws. /// @param _tierOdds The odds for the tier to calculate the frequency of + /// @param _grandPrizePeriod The number of draws between grand prizes /// @return The estimated number of draws between the tier occurring - function estimatePrizeFrequencyInDraws(SD59x18 _tierOdds) internal pure returns (uint256) { - return uint256(convert(sd(1e18).div(_tierOdds).ceil())); + function estimatePrizeFrequencyInDraws(SD59x18 _tierOdds, uint24 _grandPrizePeriod) internal pure returns (uint24) { + uint256 _prizeFrequencyInDraws = uint256(convert(sd(1e18).div(_tierOdds).ceil())); + return _prizeFrequencyInDraws > _grandPrizePeriod ? _grandPrizePeriod : uint24(_prizeFrequencyInDraws); } /// @notice Computes the number of prizes for a given tier. diff --git a/test/PrizePool.t.sol b/test/PrizePool.t.sol index 100ab30..5932eac 100644 --- a/test/PrizePool.t.sol +++ b/test/PrizePool.t.sol @@ -377,7 +377,7 @@ contract PrizePoolTest is Test { } function testGetTierAccrualDurationInDraws() public { - assertEq(prizePool.getTierAccrualDurationInDraws(0), 366); + assertEq(prizePool.getTierAccrualDurationInDraws(0), 365); } function testContributePrizeTokens() public { diff --git a/test/libraries/TierCalculationLib.t.sol b/test/libraries/TierCalculationLib.t.sol index 24f9e95..ab3198e 100644 --- a/test/libraries/TierCalculationLib.t.sol +++ b/test/libraries/TierCalculationLib.t.sol @@ -32,19 +32,19 @@ contract TierCalculationLibTest is Test { function testEstimatePrizeFrequencyInDraws() public { assertEq( - TierCalculationLib.estimatePrizeFrequencyInDraws(TierCalculationLib.getTierOdds(0, 4, 365)), - 366 + TierCalculationLib.estimatePrizeFrequencyInDraws(TierCalculationLib.getTierOdds(0, 4, 365), 365), + 365 ); assertEq( - TierCalculationLib.estimatePrizeFrequencyInDraws(TierCalculationLib.getTierOdds(1, 4, 365)), + TierCalculationLib.estimatePrizeFrequencyInDraws(TierCalculationLib.getTierOdds(1, 4, 365), 365), 124 ); assertEq( - TierCalculationLib.estimatePrizeFrequencyInDraws(TierCalculationLib.getTierOdds(2, 4, 365)), + TierCalculationLib.estimatePrizeFrequencyInDraws(TierCalculationLib.getTierOdds(2, 4, 365), 365), 31 ); assertEq( - TierCalculationLib.estimatePrizeFrequencyInDraws(TierCalculationLib.getTierOdds(3, 4, 365)), + TierCalculationLib.estimatePrizeFrequencyInDraws(TierCalculationLib.getTierOdds(3, 4, 365), 365), 1 ); }