@@ -3,23 +3,40 @@ pragma solidity ^0.8.21;
33
44/**
55 * @title DeployerGuard
6- * @notice A utility contract that provides protected initialization capabilities for contracts
7- * that depend on each other. This contract ensures that contracts are never left in an
8- * unprotected state during deployment by allowing a second initialization phase that is
9- * restricted to the deployer only.
6+ * @notice A utility contract that provides protected initialization capabilities for other contracts.
7+ *
8+ * Generally speaking, the common "Initializer" approach is easily front-runnable and shouldn't be used on its own.
9+ *
10+ * This simple utility ensures that contracts are never left in an unprotected state during deployment by
11+ * integrating a second validation step restricted to the deployer only.
12+ *
13+ * ## Usage example:
14+ *
15+ * ```
16+ * contract ProtectedImpl is ADeployerGuard {
17+ * constructor() ADeployerGuard(msg.sender) {}
18+ *
19+ * function __ERC20_init(
20+ * string memory name_,
21+ * string memory symbol_,
22+ * ) external initializer onlyDeployer {
23+ * __ERC20_init(name_, symbol_);
24+ * }
25+ * }
26+ * ```
1027 */
11- contract DeployerGuard {
28+ abstract contract ADeployerGuard {
1229 /// @notice The address of the contract deployer
13- address private immutable __SOLARITY_GUARD_DEPLOYER ;
30+ address private immutable _GUARD_DEPLOYER ;
1431
1532 /// @notice Error thrown when a non-deployer address attempts to call deployer-only functions
1633 /// @param caller The address that attempted to call the function
1734 error OnlyDeployer (address caller );
1835
1936 /**
2037 * @dev Modifier that restricts function access to the deployer only
21- * @notice This modifier should be used on second initialization functions
22- * to ensure only the original deployer can establish cross-contract references
38+ * @notice This modifier should be used on the initialization functions
39+ * to ensure their non-frontrunability
2340 */
2441 modifier onlyDeployer () {
2542 _requireDeployer (msg .sender );
@@ -30,7 +47,7 @@ contract DeployerGuard {
3047 * @dev Constructor that sets the deployer address
3148 */
3249 constructor (address deployer_ ) {
33- __SOLARITY_GUARD_DEPLOYER = deployer_;
50+ _GUARD_DEPLOYER = deployer_;
3451 }
3552
3653 /**
@@ -53,6 +70,6 @@ contract DeployerGuard {
5370 * @dev Internal function to get the deployer address
5471 */
5572 function _deployer () internal view virtual returns (address ) {
56- return __SOLARITY_GUARD_DEPLOYER ;
73+ return _GUARD_DEPLOYER ;
5774 }
5875}
0 commit comments