-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathInitializable.sol
33 lines (26 loc) · 1.1 KB
/
Initializable.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {s as erc1967ds} from "../proxy/ERC1967Proxy.sol";
// ------------- errors
error ProxyCallRequired();
error AlreadyInitialized();
/// @title Initializable
/// @author phaze (https://github.com/0xPhaze/UDS)
/// @dev functions using the `initializer` modifier are only callable during proxy deployment
/// @dev functions using the `reinitializer` modifier are only callable through a proxy
/// @dev and only before a proxy upgrade migration has completed
/// @dev (only when `upgradeToAndCall`'s `initCalldata` is being executed)
/// @dev allows re-initialization during upgrades
abstract contract Initializable {
address private immutable __implementation = address(this);
/* ------------- modifier ------------- */
modifier initializer() {
if (address(this).code.length != 0) revert AlreadyInitialized();
_;
}
modifier reinitializer() {
if (address(this) == __implementation) revert ProxyCallRequired();
if (erc1967ds().implementation == __implementation) revert AlreadyInitialized();
_;
}
}