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

[WIP] Shrink Contract Size #42

Closed
wants to merge 1 commit into from
Closed
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
19 changes: 17 additions & 2 deletions script/generateConstants.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ contract GenerateConstants is Script {
uint8 MAX_TIERS = 14;
// Precompute the prizes per draw
for (uint8 numTiers = MIN_TIERS; numTiers <= MAX_TIERS; numTiers++) {
// console.log(
// "uint32 internal constant ESTIMATED_PRIZES_PER_DRAW_FOR_%d_TIERS = %d;",
// uint256(numTiers),
// uint256(TierCalculationLib.estimatedClaimCount(numTiers, GRAND_PRIZE_PERIOD_DRAWS))
// );
console.log(
"uint32 internal constant ESTIMATED_PRIZES_PER_DRAW_FOR_%d_TIERS = %d;",
"function e%d() external pure returns (uint256) { return %d; }",
uint256(numTiers),
uint256(TierCalculationLib.estimatedClaimCount(numTiers, GRAND_PRIZE_PERIOD_DRAWS))
);
Expand All @@ -36,11 +41,21 @@ contract GenerateConstants is Script {
console.log("/// @notice The odds for each tier and number of tiers pair.");
MIN_TIERS = 3;
MAX_TIERS = 16;

bytes memory test = "test";
// Precompute the odds for each tier
for (uint8 numTiers = MIN_TIERS; numTiers <= MAX_TIERS; numTiers++) {
for (uint8 tier = 0; tier < numTiers; tier++) {
// console.log(
// "SD59x18 internal constant TIER_ODDS_%d_%d = SD59x18.wrap(%d);",
// uint256(tier),
// uint256(numTiers),
// uint256(
// SD59x18.unwrap(TierCalculationLib.getTierOdds(tier, numTiers, GRAND_PRIZE_PERIOD_DRAWS))
// )
// );
console.log(
"SD59x18 internal constant TIER_ODDS_%d_%d = SD59x18.wrap(%d);",
"function t%d%d() external pure returns (uint256) { return %d; }",
uint256(tier),
uint256(numTiers),
uint256(
Expand Down
12 changes: 6 additions & 6 deletions src/PrizePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ contract PrizePool is TieredLiquidityDistributor {

/// @notice Returns the
/// @return The number of draws
function getTierAccrualDurationInDraws(uint8 _tier) external view returns (uint16) {
function getTierAccrualDurationInDraws(uint8 _tier) external returns (uint16) {
return
uint16(TierCalculationLib.estimatePrizeFrequencyInDraws(_tierOdds(_tier, numberOfTiers)));
}
Expand Down Expand Up @@ -595,7 +595,7 @@ contract PrizePool is TieredLiquidityDistributor {
/// @notice Returns the amount of tokens that will be added to the reserve when the open draw closes.
/// @dev Intended for Draw manager to use after the draw has ended but not yet been closed.
/// @return The amount of prize tokens that will be added to the reserve
function reserveForOpenDraw() external view returns (uint256) {
function reserveForOpenDraw() external returns (uint256) {
uint8 _numTiers = numberOfTiers;
uint8 _nextNumberOfTiers = _numTiers;

Expand Down Expand Up @@ -650,7 +650,7 @@ contract PrizePool is TieredLiquidityDistributor {
address _user,
uint8 _tier,
uint32 _prizeIndex
) external view returns (bool) {
) external returns (bool) {
(SD59x18 vaultPortion, SD59x18 tierOdds, uint16 drawDuration) = _computeVaultTierDetails(
_vault,
_tier,
Expand All @@ -667,7 +667,7 @@ contract PrizePool is TieredLiquidityDistributor {
*/
function calculateTierTwabTimestamps(
uint8 _tier
) external view returns (uint64 startTimestamp, uint64 endTimestamp) {
) external returns (uint64 startTimestamp, uint64 endTimestamp) {
endTimestamp = _lastClosedDrawStartedAt + drawPeriodSeconds;

startTimestamp = uint64(
Expand Down Expand Up @@ -749,7 +749,7 @@ contract PrizePool is TieredLiquidityDistributor {
/// @notice Calculates the number of tiers for the next draw
/// @param _numTiers The current number of tiers
/// @return The number of tiers for the next draw
function _computeNextNumberOfTiers(uint8 _numTiers) internal view returns (uint8) {
function _computeNextNumberOfTiers(uint8 _numTiers) internal returns (uint8) {
UD2x18 _claimExpansionThreshold = claimExpansionThreshold;

uint8 _nextNumberOfTiers = largestTierClaimed + 2; // canary tier, then length
Expand Down Expand Up @@ -860,7 +860,7 @@ contract PrizePool is TieredLiquidityDistributor {
uint8 _tier,
uint8 _numberOfTiers,
uint16 _lastClosedDrawId
) internal view returns (SD59x18 vaultPortion, SD59x18 tierOdds, uint16 drawDuration) {
) internal returns (SD59x18 vaultPortion, SD59x18 tierOdds, uint16 drawDuration) {
if (_lastClosedDrawId == 0) {
revert NoClosedDraw();
}
Expand Down
Loading
Loading