-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce
UUPSExtUpgradeable
base contract (#23)
* chore: update UUPSupgradable * chore: remove extra errors * chore: update comment * chore: move uups mock to base folder * chore: change error names * fix: remove redundant internal validation functions * style: reorder errors alphabetically * test: remove redundant tests that duplicate the base contract ones * feat: update version --------- Co-authored-by: Evgenii Zaitsev <[email protected]>
- Loading branch information
1 parent
76b6adf
commit b8a0083
Showing
9 changed files
with
167 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.20; | ||
|
||
import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; | ||
|
||
/** | ||
* @title UUPSExtUpgradeable base contract | ||
* @author CloudWalk Inc. (See https://www.cloudwalk.io) | ||
* @dev Extends the OpenZeppelin's {UUPSUpgradeable} contract by adding additional checks for | ||
* the new implementation address. | ||
* | ||
* This contract is used through inheritance. It introduces the virtual `_validateUpgrade()` function that must be | ||
* implemented in the parent contract. | ||
*/ | ||
abstract contract UUPSExtUpgradeable is UUPSUpgradeable { | ||
// ------------------ Errors ---------------------------------- // | ||
|
||
/// @dev Thrown if the provided new implementation address is not a contract. | ||
error UUPSExtUpgradeable_ImplementationAddressNotContract(); | ||
|
||
/// @dev Thrown if the provided new implementation contract address is zero. | ||
error UUPSExtUpgradeable_ImplementationAddressZero(); | ||
|
||
// ------------------ Internal functions ---------------------- // | ||
|
||
/** | ||
* @dev The upgrade authorization function for UUPSProxy. | ||
* @param newImplementation The address of the new implementation. | ||
*/ | ||
function _authorizeUpgrade(address newImplementation) internal override { | ||
if (newImplementation == address(0)) { | ||
revert UUPSExtUpgradeable_ImplementationAddressZero(); | ||
} | ||
|
||
if (newImplementation.code.length == 0) { | ||
revert UUPSExtUpgradeable_ImplementationAddressNotContract(); | ||
} | ||
|
||
_validateUpgrade(newImplementation); | ||
} | ||
|
||
/** | ||
* @dev Executes further validation steps of the upgrade including authorization and implementation address checks. | ||
* @param newImplementation The address of the new implementation. | ||
*/ | ||
function _validateUpgrade(address newImplementation) internal virtual; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.20; | ||
|
||
import { UUPSExtUpgradeable } from "../../base/UUPSExtUpgradeable.sol"; | ||
|
||
/** | ||
* @title UUPSExtUpgradableMock contract | ||
* @author CloudWalk Inc. (See https://www.cloudwalk.io) | ||
* @dev An implementation of the {UUPSExtUpgradable} contract for test purposes. | ||
*/ | ||
contract UUPSExtUpgradeableMock is UUPSExtUpgradeable { | ||
/// @dev Emitted when the internal `_validateUpgrade()` function is called with the parameters of the function. | ||
event MockValidateUpgradeCall(address newImplementation); | ||
|
||
/** | ||
* @dev Executes further validation steps of the upgrade including authorization and implementation address checks. | ||
* @param newImplementation The address of the new implementation. | ||
*/ | ||
function _validateUpgrade(address newImplementation) internal virtual override { | ||
emit MockValidateUpgradeCall(newImplementation); | ||
} | ||
} |
Oops, something went wrong.