Skip to content

Commit

Permalink
chore: reuse time since rotation function
Browse files Browse the repository at this point in the history
  • Loading branch information
ahramy committed Oct 31, 2024
1 parent b5d0b7b commit 1b27703
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions contracts/governance/BaseWeightedMultisig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,16 @@ abstract contract BaseWeightedMultisig is IBaseWeightedMultisig {
* @notice This function returns the timestamp for the last signer rotation
* @return uint256 The last rotation timestamp
*/
function lastRotationTimestamp() external view returns (uint256) {
function lastRotationTimestamp() public view returns (uint256) {
return _baseWeightedMultisigStorage().lastRotationTimestamp;
}

/**
* @notice This function returns the time elapsed (in secs) since the last rotation
* @return uint256 The time since the last rotation
*/
function timeSinceRotation() external view returns (uint256) {
return block.timestamp - _baseWeightedMultisigStorage().lastRotationTimestamp;
function timeSinceRotation() public view returns (uint256) {
return block.timestamp - lastRotationTimestamp();
}

/*************************\
Expand Down Expand Up @@ -168,18 +168,13 @@ abstract contract BaseWeightedMultisig is IBaseWeightedMultisig {
* @dev Updates the last rotation timestamp, and enforces the minimum rotation delay if specified
*/
function _updateRotationTimestamp(bool enforceRotationDelay) internal {
uint256 lastRotationTimestamp_ = _baseWeightedMultisigStorage().lastRotationTimestamp;
uint256 currentTimestamp = block.timestamp;

if (enforceRotationDelay && (currentTimestamp - lastRotationTimestamp_) < minimumRotationDelay) {
revert InsufficientRotationDelay(
minimumRotationDelay,
lastRotationTimestamp_,
currentTimestamp - lastRotationTimestamp_
);
uint256 timeSinceRotation_ = timeSinceRotation();

if (enforceRotationDelay && timeSinceRotation_ < minimumRotationDelay) {
revert InsufficientRotationDelay(minimumRotationDelay, lastRotationTimestamp(), timeSinceRotation_);
}

_baseWeightedMultisigStorage().lastRotationTimestamp = currentTimestamp;
_baseWeightedMultisigStorage().lastRotationTimestamp = block.timestamp;
}

/**
Expand Down

0 comments on commit 1b27703

Please sign in to comment.