Skip to content

Commit

Permalink
fix tier odds
Browse files Browse the repository at this point in the history
  • Loading branch information
trmid committed Mar 26, 2024
1 parent a7ae682 commit 4805080
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 63 deletions.
81 changes: 41 additions & 40 deletions src/abstract/TieredLiquidityDistributor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -169,43 +169,43 @@ contract TieredLiquidityDistributor {

TIER_ODDS_0 = sd(1).div(sd(int24(_grandPrizePeriodDraws)));
TIER_ODDS_EVERY_DRAW = SD59x18.wrap(1000000000000000000);
TIER_ODDS_1_5 = TierCalculationLib.getTierOdds(1, 4, _grandPrizePeriodDraws);
TIER_ODDS_1_6 = TierCalculationLib.getTierOdds(1, 5, _grandPrizePeriodDraws);
TIER_ODDS_2_6 = TierCalculationLib.getTierOdds(2, 5, _grandPrizePeriodDraws);
TIER_ODDS_1_7 = TierCalculationLib.getTierOdds(1, 6, _grandPrizePeriodDraws);
TIER_ODDS_2_7 = TierCalculationLib.getTierOdds(2, 6, _grandPrizePeriodDraws);
TIER_ODDS_3_7 = TierCalculationLib.getTierOdds(3, 6, _grandPrizePeriodDraws);
TIER_ODDS_1_8 = TierCalculationLib.getTierOdds(1, 7, _grandPrizePeriodDraws);
TIER_ODDS_2_8 = TierCalculationLib.getTierOdds(2, 7, _grandPrizePeriodDraws);
TIER_ODDS_3_8 = TierCalculationLib.getTierOdds(3, 7, _grandPrizePeriodDraws);
TIER_ODDS_4_8 = TierCalculationLib.getTierOdds(4, 7, _grandPrizePeriodDraws);
TIER_ODDS_1_9 = TierCalculationLib.getTierOdds(1, 8, _grandPrizePeriodDraws);
TIER_ODDS_2_9 = TierCalculationLib.getTierOdds(2, 8, _grandPrizePeriodDraws);
TIER_ODDS_3_9 = TierCalculationLib.getTierOdds(3, 8, _grandPrizePeriodDraws);
TIER_ODDS_4_9 = TierCalculationLib.getTierOdds(4, 8, _grandPrizePeriodDraws);
TIER_ODDS_5_9 = TierCalculationLib.getTierOdds(5, 8, _grandPrizePeriodDraws);
TIER_ODDS_1_10 = TierCalculationLib.getTierOdds(1, 9, _grandPrizePeriodDraws);
TIER_ODDS_2_10 = TierCalculationLib.getTierOdds(2, 9, _grandPrizePeriodDraws);
TIER_ODDS_3_10 = TierCalculationLib.getTierOdds(3, 9, _grandPrizePeriodDraws);
TIER_ODDS_4_10 = TierCalculationLib.getTierOdds(4, 9, _grandPrizePeriodDraws);
TIER_ODDS_5_10 = TierCalculationLib.getTierOdds(5, 9, _grandPrizePeriodDraws);
TIER_ODDS_6_10 = TierCalculationLib.getTierOdds(6, 9, _grandPrizePeriodDraws);
TIER_ODDS_1_11 = TierCalculationLib.getTierOdds(1, 10, _grandPrizePeriodDraws);
TIER_ODDS_2_11 = TierCalculationLib.getTierOdds(2, 10, _grandPrizePeriodDraws);
TIER_ODDS_3_11 = TierCalculationLib.getTierOdds(3, 10, _grandPrizePeriodDraws);
TIER_ODDS_4_11 = TierCalculationLib.getTierOdds(4, 10, _grandPrizePeriodDraws);
TIER_ODDS_5_11 = TierCalculationLib.getTierOdds(5, 10, _grandPrizePeriodDraws);
TIER_ODDS_6_11 = TierCalculationLib.getTierOdds(6, 10, _grandPrizePeriodDraws);
TIER_ODDS_7_11 = TierCalculationLib.getTierOdds(7, 10, _grandPrizePeriodDraws);

ESTIMATED_PRIZES_PER_DRAW_FOR_4_TIERS = _sumTierPrizeCounts(3);
ESTIMATED_PRIZES_PER_DRAW_FOR_5_TIERS = _sumTierPrizeCounts(4);
ESTIMATED_PRIZES_PER_DRAW_FOR_6_TIERS = _sumTierPrizeCounts(5);
ESTIMATED_PRIZES_PER_DRAW_FOR_7_TIERS = _sumTierPrizeCounts(6);
ESTIMATED_PRIZES_PER_DRAW_FOR_8_TIERS = _sumTierPrizeCounts(7);
ESTIMATED_PRIZES_PER_DRAW_FOR_9_TIERS = _sumTierPrizeCounts(8);
ESTIMATED_PRIZES_PER_DRAW_FOR_10_TIERS = _sumTierPrizeCounts(9);
ESTIMATED_PRIZES_PER_DRAW_FOR_11_TIERS = _sumTierPrizeCounts(10);
TIER_ODDS_1_5 = TierCalculationLib.getTierOdds(1, 3, _grandPrizePeriodDraws);
TIER_ODDS_1_6 = TierCalculationLib.getTierOdds(1, 4, _grandPrizePeriodDraws);
TIER_ODDS_2_6 = TierCalculationLib.getTierOdds(2, 4, _grandPrizePeriodDraws);
TIER_ODDS_1_7 = TierCalculationLib.getTierOdds(1, 5, _grandPrizePeriodDraws);
TIER_ODDS_2_7 = TierCalculationLib.getTierOdds(2, 5, _grandPrizePeriodDraws);
TIER_ODDS_3_7 = TierCalculationLib.getTierOdds(3, 5, _grandPrizePeriodDraws);
TIER_ODDS_1_8 = TierCalculationLib.getTierOdds(1, 6, _grandPrizePeriodDraws);
TIER_ODDS_2_8 = TierCalculationLib.getTierOdds(2, 6, _grandPrizePeriodDraws);
TIER_ODDS_3_8 = TierCalculationLib.getTierOdds(3, 6, _grandPrizePeriodDraws);
TIER_ODDS_4_8 = TierCalculationLib.getTierOdds(4, 6, _grandPrizePeriodDraws);
TIER_ODDS_1_9 = TierCalculationLib.getTierOdds(1, 7, _grandPrizePeriodDraws);
TIER_ODDS_2_9 = TierCalculationLib.getTierOdds(2, 7, _grandPrizePeriodDraws);
TIER_ODDS_3_9 = TierCalculationLib.getTierOdds(3, 7, _grandPrizePeriodDraws);
TIER_ODDS_4_9 = TierCalculationLib.getTierOdds(4, 7, _grandPrizePeriodDraws);
TIER_ODDS_5_9 = TierCalculationLib.getTierOdds(5, 7, _grandPrizePeriodDraws);
TIER_ODDS_1_10 = TierCalculationLib.getTierOdds(1, 8, _grandPrizePeriodDraws);
TIER_ODDS_2_10 = TierCalculationLib.getTierOdds(2, 8, _grandPrizePeriodDraws);
TIER_ODDS_3_10 = TierCalculationLib.getTierOdds(3, 8, _grandPrizePeriodDraws);
TIER_ODDS_4_10 = TierCalculationLib.getTierOdds(4, 8, _grandPrizePeriodDraws);
TIER_ODDS_5_10 = TierCalculationLib.getTierOdds(5, 8, _grandPrizePeriodDraws);
TIER_ODDS_6_10 = TierCalculationLib.getTierOdds(6, 8, _grandPrizePeriodDraws);
TIER_ODDS_1_11 = TierCalculationLib.getTierOdds(1, 9, _grandPrizePeriodDraws);
TIER_ODDS_2_11 = TierCalculationLib.getTierOdds(2, 9, _grandPrizePeriodDraws);
TIER_ODDS_3_11 = TierCalculationLib.getTierOdds(3, 9, _grandPrizePeriodDraws);
TIER_ODDS_4_11 = TierCalculationLib.getTierOdds(4, 9, _grandPrizePeriodDraws);
TIER_ODDS_5_11 = TierCalculationLib.getTierOdds(5, 9, _grandPrizePeriodDraws);
TIER_ODDS_6_11 = TierCalculationLib.getTierOdds(6, 9, _grandPrizePeriodDraws);
TIER_ODDS_7_11 = TierCalculationLib.getTierOdds(7, 9, _grandPrizePeriodDraws);

ESTIMATED_PRIZES_PER_DRAW_FOR_4_TIERS = _sumTierPrizeCounts(4);
ESTIMATED_PRIZES_PER_DRAW_FOR_5_TIERS = _sumTierPrizeCounts(5);
ESTIMATED_PRIZES_PER_DRAW_FOR_6_TIERS = _sumTierPrizeCounts(6);
ESTIMATED_PRIZES_PER_DRAW_FOR_7_TIERS = _sumTierPrizeCounts(7);
ESTIMATED_PRIZES_PER_DRAW_FOR_8_TIERS = _sumTierPrizeCounts(8);
ESTIMATED_PRIZES_PER_DRAW_FOR_9_TIERS = _sumTierPrizeCounts(9);
ESTIMATED_PRIZES_PER_DRAW_FOR_10_TIERS = _sumTierPrizeCounts(10);
ESTIMATED_PRIZES_PER_DRAW_FOR_11_TIERS = _sumTierPrizeCounts(11);
}

/// @notice Adjusts the number of tiers and distributes new liquidity.
Expand Down Expand Up @@ -563,16 +563,17 @@ contract TieredLiquidityDistributor {
}

/// @notice Computes the expected number of prizes for a given number of tiers.
/// @dev Includes the canary tier
/// @param _numTiers The number of tiers
/// @dev Includes the first canary tier prizes, but not the second since the first is expected to
/// be claimed.
/// @param _numTiers The number of tiers, including canaries
/// @return The expected number of prizes, canary included.
function _sumTierPrizeCounts(uint8 _numTiers) internal view returns (uint32) {
uint32 prizeCount;
uint8 i = 0;
do {
prizeCount += TierCalculationLib.tierPrizeCountPerDraw(i, getTierOdds(i, _numTiers));
i++;
} while (i < _numTiers);
} while (i < _numTiers - 1);
return prizeCount;
}

Expand Down
41 changes: 18 additions & 23 deletions test/abstract/TieredLiquidityDistributor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -400,34 +400,29 @@ contract TieredLiquidityDistributorTest is Test {
}

function testEstimatedPrizeCount_allTiers() public {
// 4 daily + 16 canary 1 daily + 64 canary 2 daily = 84
assertEq(distributor.estimatedPrizeCount(4), 20, "num tiers 4");
assertEq(distributor.estimatedPrizeCount(5), 84, "num tiers 5");
// 16 + 64 + 256 = ~336
assertEq(distributor.estimatedPrizeCount(6), 336, "num tiers 6");
// 64 + 256 + 1024 = ~1344
assertEq(distributor.estimatedPrizeCount(7), 1344, "num tiers 7");
// 256 + 1024 + 4096 = ~5376 (plus a few prizes from non-daily tiers)
assertEq(distributor.estimatedPrizeCount(8), 5382, "num tiers 8");
assertEq(distributor.estimatedPrizeCount(9), 21542, "num tiers 9");
assertEq(distributor.estimatedPrizeCount(10), 86227, "num tiers 10");
assertEq(distributor.estimatedPrizeCount(11), 345127, "num tiers 11");
assertEq(distributor.estimatedPrizeCount(5), 80, "num tiers 5");
assertEq(distributor.estimatedPrizeCount(6), 322, "num tiers 6");
assertEq(distributor.estimatedPrizeCount(7), 1294, "num tiers 7");
assertEq(distributor.estimatedPrizeCount(8), 5204, "num tiers 8");
assertEq(distributor.estimatedPrizeCount(9), 20901, "num tiers 9");
assertEq(distributor.estimatedPrizeCount(10), 83894, "num tiers 10");
assertEq(distributor.estimatedPrizeCount(11), 336579, "num tiers 11");
assertEq(distributor.estimatedPrizeCount(12), 0, "num tiers 12");
}

function testSumTierPrizeCounts() public {
// 4 daily + 16 canary 1 daily + 64 canary 2 daily = 84
assertEq(distributor.sumTierPrizeCounts(4), 84, "num tiers 4");
// 16 + 64 + 256 = ~336
assertEq(distributor.sumTierPrizeCounts(5), 336, "num tiers 5");
// 64 + 256 + 1024 = ~1344
assertEq(distributor.sumTierPrizeCounts(6), 1344, "num tiers 6");
// 256 + 1024 + 4096 = ~5376 (plus a few prizes from non-daily tiers)
assertEq(distributor.sumTierPrizeCounts(7), 5382, "num tiers 7");
assertEq(distributor.sumTierPrizeCounts(8), 21542, "num tiers 8");
assertEq(distributor.sumTierPrizeCounts(9), 86227, "num tiers 9");
assertEq(distributor.sumTierPrizeCounts(10), 345127, "num tiers 10");
assertEq(distributor.sumTierPrizeCounts(11), 1381328, "num tiers 11");
// 16 canary 1 daily + 64 canary 2 daily = 80
assertEq(distributor.sumTierPrizeCounts(5), 80, "num tiers 5");
// 64 + 256 = ~320
assertEq(distributor.sumTierPrizeCounts(6), 322, "num tiers 6");
// 256 + 1024 = ~1280
assertEq(distributor.sumTierPrizeCounts(7), 1294, "num tiers 7");
// 1024 + 4096 = ~5120 (plus a few prizes from non-daily tiers)
assertEq(distributor.sumTierPrizeCounts(8), 5204, "num tiers 8");
assertEq(distributor.sumTierPrizeCounts(9), 20901, "num tiers 9");
assertEq(distributor.sumTierPrizeCounts(10), 83894, "num tiers 10");
assertEq(distributor.sumTierPrizeCounts(11), 336579, "num tiers 11");
assertEq(distributor.sumTierPrizeCounts(12), 0, "num tiers 12");
}

Expand Down

0 comments on commit 4805080

Please sign in to comment.