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

TimeManagerV5 remove function pointer and add conditional logic #25

Merged
merged 1 commit into from
May 13, 2024
Merged
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
10 changes: 3 additions & 7 deletions contracts/TimeManagerV5.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@
/// @dev Sets true when contract is initialized
bool private isInitialized;

/**
* @dev Retrieves the current slot
* @return Current slot
*/
function() view returns (uint256) private _getCurrentSlot;
/// @notice Deprecated slot for _getCurrentSlot function pointer
bytes32 private __deprecatedSlot1;

/**
* @dev This empty reserved space is put in place to allow future versions to add new
Expand All @@ -32,7 +29,7 @@
* @return Current block number or block timestamp
*/
function getBlockNumberOrTimestamp() public view returns (uint256) {
return _getCurrentSlot();
return isTimeBased ? _getBlockTimestamp() : _getBlockNumber();
}

/**
Expand All @@ -42,18 +39,17 @@
* @param blocksPerYear_ The number of blocks per year
*/
function _initializeTimeManager(bool timeBased_, uint256 blocksPerYear_) internal {
if (isInitialized) revert("Already initialized TimeManager");

Check warning on line 42 in contracts/TimeManagerV5.sol

View workflow job for this annotation

GitHub Actions / Lint

Use Custom Errors instead of revert statements

if (!timeBased_ && blocksPerYear_ == 0) {
revert("Invalid blocks per year");

Check warning on line 45 in contracts/TimeManagerV5.sol

View workflow job for this annotation

GitHub Actions / Lint

Use Custom Errors instead of revert statements
}
if (timeBased_ && blocksPerYear_ != 0) {
revert("Invalid time based configuration");

Check warning on line 48 in contracts/TimeManagerV5.sol

View workflow job for this annotation

GitHub Actions / Lint

Use Custom Errors instead of revert statements
}

isTimeBased = timeBased_;
blocksOrSecondsPerYear = timeBased_ ? SECONDS_PER_YEAR : blocksPerYear_;
_getCurrentSlot = timeBased_ ? _getBlockTimestamp : _getBlockNumber;
isInitialized = true;
}

Expand Down
Loading