-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathSyndicateFactory.sol
65 lines (54 loc) · 2.39 KB
/
SyndicateFactory.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
pragma solidity 0.8.13;
// SPDX-License-Identifier: MIT
import { Clones } from "@openzeppelin/contracts/proxy/Clones.sol";
import { ISyndicateFactory } from "../interfaces/ISyndicateFactory.sol";
import { ISyndicateInit } from "../interfaces/ISyndicateInit.sol";
/// @notice Contract for deploying a new KNOT syndicate
contract SyndicateFactory is ISyndicateFactory {
/// @notice Address of syndicate implementation that is cloned on each syndicate deployment
address public syndicateImplementation;
/// @param _syndicateImpl Address of syndicate implementation that is cloned on each syndicate deployment
constructor(address _syndicateImpl) {
syndicateImplementation = _syndicateImpl;
}
/// @inheritdoc ISyndicateFactory
function deploySyndicate(
address _contractOwner,
uint256 _priorityStakingEndBlock,
address[] calldata _priorityStakers,
bytes[] calldata _blsPubKeysForSyndicateKnots
) public override returns (address) {
// Use CREATE2 to deploy the new instance of the syndicate
address newInstance = Clones.cloneDeterministic(
syndicateImplementation,
calculateDeploymentSalt(msg.sender, _contractOwner, _blsPubKeysForSyndicateKnots.length)
);
// Initialize the new syndicate instance with the params from the deployer
ISyndicateInit(newInstance).initialize(
_contractOwner,
_priorityStakingEndBlock,
_priorityStakers,
_blsPubKeysForSyndicateKnots
);
// Off chain logging of all deployed instances from this factory
emit SyndicateDeployed(newInstance);
return newInstance;
}
/// @inheritdoc ISyndicateFactory
function calculateSyndicateDeploymentAddress(
address _deployer,
address _contractOwner,
uint256 _numberOfInitialKnots
) external override view returns (address) {
bytes32 salt = calculateDeploymentSalt(_deployer, _contractOwner, _numberOfInitialKnots);
return Clones.predictDeterministicAddress(syndicateImplementation, salt);
}
/// @inheritdoc ISyndicateFactory
function calculateDeploymentSalt(
address _deployer,
address _contractOwner,
uint256 _numberOfInitialKnots
) public override pure returns (bytes32) {
return keccak256(abi.encode(_deployer, _contractOwner, _numberOfInitialKnots));
}
}