Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cap prize draw range at GP period #115

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/PrizePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));

Expand Down
7 changes: 5 additions & 2 deletions src/libraries/TierCalculationLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion test/PrizePool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ contract PrizePoolTest is Test {
}

function testGetTierAccrualDurationInDraws() public {
assertEq(prizePool.getTierAccrualDurationInDraws(0), 366);
assertEq(prizePool.getTierAccrualDurationInDraws(0), 365);
}

function testContributePrizeTokens() public {
Expand Down
10 changes: 5 additions & 5 deletions test/libraries/TierCalculationLib.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
Expand Down
Loading