Skip to content

Commit

Permalink
refactor(vault): use custom error for paused contract check
Browse files Browse the repository at this point in the history
Improved readability and gas efficiency by using `revert` with `ContractPaused` instead of `require`.
  • Loading branch information
nekofar committed Aug 10, 2024
1 parent 45eb443 commit 45efb7d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/LilNounsVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ contract LilNounsVault is
PausableUpgradeable,
IERC721Receiver
{
/// @notice Custom error for paused contract during upgrade attempt
error ContractPaused();

/// @notice Initializer function to replace the constructor for upgradeable contracts
function initialize() public initializer {
__Ownable_init(msg.sender);
Expand All @@ -34,9 +37,13 @@ contract LilNounsVault is
*/
function _authorizeUpgrade(
address newImplementation
) internal override onlyOwner {
require(!paused(), "Contract is paused, upgrade not allowed");
// Proceed with the upgrade if the contract is not paused
) internal view override onlyOwner {
if (paused()) {
revert ContractPaused();
}

// Suppress unused variable warning
(newImplementation);
}

/**
Expand Down

0 comments on commit 45efb7d

Please sign in to comment.