-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathHashflowFactory.sol
More file actions
122 lines (101 loc) · 3.5 KB
/
Copy pathHashflowFactory.sol
File metadata and controls
122 lines (101 loc) · 3.5 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**
* SPDX-License-Identifier: UNLICENSED
*/
pragma solidity 0.8.18;
import '@openzeppelin/contracts/utils/Address.sol';
import '@openzeppelin/contracts/access/Ownable2Step.sol';
import '@openzeppelin/contracts/proxy/Clones.sol';
import '@openzeppelin/contracts/proxy/utils/Initializable.sol';
import './interfaces/IHashflowFactory.sol';
import './interfaces/IHashflowPool.sol';
import './interfaces/IHashflowRouter.sol';
/// @title HashflowFactory
/// @author Victor Ionescu
/// @notice Implementation of IHashflowFactory.
contract HashflowFactory is IHashflowFactory, Ownable2Step, Initializable {
using Address for address;
address public router;
address public _poolImpl;
mapping(address => bool) public allowedPoolCreators;
/// @inheritdoc IHashflowFactory
function initialize(address _router)
external
override
initializer
onlyOwner
{
require(
_router != address(0),
'HashflowFactory::initialize Router cannot be 0 address.'
);
router = _router;
}
/// @inheritdoc IHashflowFactory
function updatePoolCreatorAuthorization(address poolCreator, bool status)
external
override
onlyOwner
{
require(
poolCreator != address(0),
'HashflowFactory::updatePoolCreatorAuthorization Pool creator cannot be 0 address.'
);
allowedPoolCreators[poolCreator] = status;
emit UpdatePoolCreatorAuthorization(poolCreator, status);
}
/// @inheritdoc IHashflowFactory
function createPool(string calldata name, address signer)
external
override
{
require(
allowedPoolCreators[_msgSender()],
'HashflowFactory::createPool Not authorized.'
);
require(
router != address(0),
'HashflowFactory::createPool Router has not been initialized.'
);
address newPool = _createPoolInternal(name, signer, _msgSender());
IHashflowRouter(router).updatePoolAuthorization(newPool, true);
emit CreatePool(newPool, _msgSender());
}
function _createPoolInternal(
string memory name,
address signer,
address operations
) internal virtual returns (address) {
require(
bytes(name).length > 0,
'HashflowFactory::_createPoolInternal Name cannot be empty.'
);
require(
_poolImpl != address(0),
'HasflowFactory::_createPoolInternal Pool implementation not set.'
);
address newPool = Clones.clone(_poolImpl);
IHashflowPool(newPool).initialize(name, signer, operations, router);
require(
newPool != address(0),
'HashflowFactory: new pool is 0 address'
);
return newPool;
}
/// @inheritdoc IHashflowFactory
function updatePoolImpl(address poolImpl) external override onlyOwner {
require(
poolImpl.isContract(),
'HashflowFactory::updatePoolImpl Pool Implementation must be a contract.'
);
require(
_poolImpl == address(0),
'HashflowFactory::updatePoolImpl Pool Implementation cannot be re-initialized.'
);
emit UpdatePoolImplementation(poolImpl, _poolImpl);
_poolImpl = poolImpl;
}
/// @dev We do not allow owner to renounce ownership.
function renounceOwnership() public view override onlyOwner {
revert('HashflowFactory: Renouncing ownership not allowed.');
}
}