Skip to content

Commit c1ad18b

Browse files
committed
Optimize
1 parent b4b1326 commit c1ad18b

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/ClustersMarketV1.sol

+8-9
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ contract ClustersMarketV1 is UUPSUpgradeable, Initializable, Ownable, Reentrancy
297297
} else {
298298
uint256 newBidAmount = F.rawSub(oldBidAmount, delta);
299299
if (newBidAmount < _minAnnualPrice(contracts)) revert Insufficient();
300-
b.bidAmount = SafeCastLib.toUint88(newBidAmount);
300+
b.bidAmount = uint88(newBidAmount);
301301
b.bidUpdated = uint40(block.timestamp);
302302
emit BidReduced(clusterName, sender, oldBidAmount, newBidAmount);
303303
}
@@ -379,25 +379,24 @@ contract ClustersMarketV1 is UUPSUpgradeable, Initializable, Ownable, Reentrancy
379379

380380
/// @dev Allows the owner to set the minimum bid increment.
381381
function setMinBidIncrement(uint256 newMinBidIncrement) public onlyOwner {
382-
ClustersMarketStorage storage $ = _getClustersMarketStorage();
383-
$.minBidIncrement = SafeCastLib.toUint88(newMinBidIncrement);
382+
_getClustersMarketStorage().minBidIncrement = SafeCastLib.toUint88(newMinBidIncrement);
384383
emit MinBidIncrementSet(newMinBidIncrement);
385384
}
386385

387386
/// @dev Allows the owner to set the bid timelock.
388387
function setBidTimelock(uint256 newBidTimelock) public onlyOwner {
389-
ClustersMarketStorage storage $ = _getClustersMarketStorage();
390-
$.bidTimelock = SafeCastLib.toUint32(newBidTimelock);
388+
_getClustersMarketStorage().bidTimelock = SafeCastLib.toUint32(newBidTimelock);
391389
emit BidTimelockSet(newBidTimelock);
392390
}
393391

394392
/// @dev Allows the owner to withdraw the protocol accrual.
395393
function withdrawProtocolAccural(address to, uint256 amount) public onlyOwner {
396394
ClustersMarketStorage storage $ = _getClustersMarketStorage();
397-
// Will revert if `amount > $.protocolAccural`.
398-
$.protocolAccural -= SafeCastLib.toUint88(amount);
399-
SafeTransferLib.forceSafeTransferETH(to, amount);
400-
emit ProtocolAccuralWithdrawn(to, amount);
395+
uint256 accrual = $.protocolAccural;
396+
uint256 clampedAmount = F.min(amount, accrual);
397+
$.protocolAccural = uint88(F.rawSub(accrual, clampedAmount));
398+
SafeTransferLib.forceSafeTransferETH(to, clampedAmount);
399+
emit ProtocolAccuralWithdrawn(to, clampedAmount);
401400
}
402401

403402
/*«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-*/

0 commit comments

Comments
 (0)