-
Notifications
You must be signed in to change notification settings - Fork 4
/
ACloneable.sol
40 lines (33 loc) · 1.91 KB
/
ACloneable.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
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.24;
import {Initializable} from "@solady/utils/Initializable.sol";
import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
/// @title ACloneable
/// @notice A contract that can be cloned and initialized only once
abstract contract ACloneable is Initializable, ERC165 {
/// @notice Thrown when an inheriting contract does not implement the initializer function
error InitializerNotImplemented();
/// @notice Thrown when the provided initialization data is invalid
/// @dev This error indicates that the given data is not valid for the implementation (i.e. does not decode to the expected types)
error InvalidInitializationData();
/// @notice Thrown when the contract has already been initialized
error CloneAlreadyInitialized();
/// @notice Initialize the clone with the given arbitrary data
/// @param - The compressed initialization data (if required)
/// @dev The data is expected to be ABI encoded bytes compressed using {LibZip-cdCompress}
/// @dev All implementations must override this function to initialize the contract
function initialize(bytes calldata) public virtual initializer {
revert InitializerNotImplemented();
}
/// @notice
/// @param - Return a cloneable's unique identifier for downstream consumers to differentiate various targets
/// @dev All implementations must override this function
function getComponentInterface() public pure virtual returns (bytes4);
/// @inheritdoc ERC165
/// @notice Check if the contract supports the given interface
/// @param interfaceId The interface identifier
/// @return True if the contract supports the interface
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(ACloneable).interfaceId || super.supportsInterface(interfaceId);
}
}