-
Notifications
You must be signed in to change notification settings - Fork 33
/
Implementation.sol
43 lines (33 loc) · 1.14 KB
/
Implementation.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
34
35
36
37
38
39
40
41
42
43
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.20;
// Base contract for all contracts intended to be delegatecalled into.
abstract contract Implementation {
event Initialized();
error AlreadyInitialized();
error OnlyDelegateCallError();
/// @notice The address of the implementation contract.
address public immutable implementation;
/// @notice Whether or not the implementation has been initialized.
bool public initialized;
constructor() {
implementation = address(this);
}
// Reverts if the current function context is not inside of a delegatecall.
modifier onlyDelegateCall() virtual {
if (address(this) == implementation) {
revert OnlyDelegateCallError();
}
_;
}
modifier onlyInitialize() {
if (initialized) revert AlreadyInitialized();
initialized = true;
emit Initialized();
_;
}
/// @notice The address of the implementation contract.
/// @dev This is an alias for `implementation` for backwards compatibility.
function IMPL() external view returns (address) {
return implementation;
}
}