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

Added function to estimate prizes for both canary tiers #105

Merged
merged 2 commits into from
Apr 2, 2024
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
23 changes: 21 additions & 2 deletions src/abstract/TieredLiquidityDistributor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -495,19 +495,25 @@ contract TieredLiquidityDistributor {
return result;
}

/// @notice Estimates the number of prizes for the current number of tiers, including the canary tier
/// @notice Estimates the number of prizes for the current number of tiers, including the first canary tier
/// @return The estimated number of prizes including the canary tier
function estimatedPrizeCount() external view returns (uint32) {
return estimatedPrizeCount(numberOfTiers);
}

/// @notice Estimates the number of prizes for the current number of tiers, including both canary tiers
/// @return The estimated number of prizes including both canary tiers
function estimatedPrizeCountWithBothCanaries() external view returns (uint32) {
return estimatedPrizeCountWithBothCanaries(numberOfTiers);
}

/// @notice Returns the balance of the reserve.
/// @return The amount of tokens that have been reserved.
function reserve() external view returns (uint96) {
return _reserve;
}

/// @notice Estimates the prize count for the given tier. It expects no prizes are claimed for the last canary tier
/// @notice Estimates the prize count for the given number of tiers, including the first canary tier. It expects no prizes are claimed for the last canary tier
/// @param numTiers The number of prize tiers
/// @return The estimated total number of prizes
function estimatedPrizeCount(
Expand All @@ -533,6 +539,19 @@ contract TieredLiquidityDistributor {
return 0;
}

/// @notice Estimates the prize count for the given tier, including BOTH canary tiers
/// @param numTiers The number of tiers
/// @return The estimated prize count across all tiers, including both canary tiers.
function estimatedPrizeCountWithBothCanaries(
uint8 numTiers
) public view returns (uint32) {
if (numTiers >= MINIMUM_NUMBER_OF_TIERS && numTiers <= MAXIMUM_NUMBER_OF_TIERS) {
return estimatedPrizeCount(numTiers) + uint32(TierCalculationLib.prizeCount(numTiers - 1));
} else {
return 0;
}
}

/// @notice Estimates the number of tiers for the given prize count.
/// @dev Can return lower than the minimum, so that minimum can be detected
/// @param _prizeCount The number of prizes that were claimed
Expand Down
13 changes: 13 additions & 0 deletions test/abstract/TieredLiquidityDistributor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,19 @@ contract TieredLiquidityDistributorTest is Test {
assertEq(distributor.estimatedPrizeCount(12), 0, "num tiers 12");
}

function testEstimatedPrizeCountWithBothCanaries_allTiers() public {
assertEq(distributor.estimatedPrizeCountWithBothCanaries(3), 0, "num tiers 3");
assertEq(distributor.estimatedPrizeCountWithBothCanaries(4), 20 + 4**3, "num tiers 4");
assertEq(distributor.estimatedPrizeCountWithBothCanaries(5), 80 + 4**4, "num tiers 5");
assertEq(distributor.estimatedPrizeCountWithBothCanaries(6), 320 + 4**5, "num tiers 6");
assertEq(distributor.estimatedPrizeCountWithBothCanaries(7), 1283 + 4**6, "num tiers 7");
assertEq(distributor.estimatedPrizeCountWithBothCanaries(12), 0, "num tiers 12");
}

function testEstimatedPrizeCountWithBothCanaries() public {
assertEq(distributor.estimatedPrizeCountWithBothCanaries(), 20 + 4**3, "num tiers 4");
}

function testSumTierPrizeCounts() public {
// 16 canary 1 daily + 64 canary 2 daily = 80
assertEq(distributor.sumTierPrizeCounts(5), 80, "num tiers 5");
Expand Down
Loading