-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathInstance.sol
40 lines (33 loc) · 1.44 KB
/
Instance.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: Apache-2.0
pragma solidity ^0.8.13;
import "../storage/Storage.sol";
import "./interfaces/IInstance.sol";
import "./Initializable.sol";
/// @title Instance
/// @notice An abstract contract that is created and managed by a factory
abstract contract Instance is IInstance, Initializable {
/// @dev The factory address storage slot
AddressStorage private constant _factory = AddressStorage.wrap(keccak256("equilibria.root.Instance.factory"));
/// @notice Returns the factory that created this instance
/// @return The factory that created this instance
function factory() public view returns (IFactory) { return IFactory(_factory.read()); }
/// @notice Initializes the contract setting `msg.sender` as the factory
function __Instance__initialize() internal onlyInitializer {
_factory.store(msg.sender);
}
/// @notice Only allow the owner defined by the factory to call the function
modifier onlyOwner {
if (msg.sender != factory().owner()) revert InstanceNotOwnerError(msg.sender);
_;
}
/// @notice Only allow the factory to call the function
modifier onlyFactory {
if (msg.sender != address(factory())) revert InstanceNotFactoryError(msg.sender);
_;
}
/// @notice Only allow the function to be called when the factory is not paused
modifier whenNotPaused {
if (factory().paused()) revert InstancePausedError();
_;
}
}