-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPartyFactory.sol
84 lines (73 loc) · 2.81 KB
/
PartyFactory.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.20;
import { Clones } from "openzeppelin/contracts/proxy/Clones.sol";
import { IERC721 } from "../tokens/IERC721.sol";
import { Party } from "./Party.sol";
import { IPartyFactory } from "./IPartyFactory.sol";
import { IGlobals } from "../globals/IGlobals.sol";
import { LibGlobals } from "../globals/LibGlobals.sol";
import { MetadataRegistry } from "../renderers/MetadataRegistry.sol";
import { MetadataProvider } from "../renderers/MetadataProvider.sol";
/// @notice Factory used to deploy new proxified `Party` instances.
contract PartyFactory is IPartyFactory {
using Clones for address;
error NoAuthorityError();
// The `Globals` contract storing global configuration values. This contract
// is immutable and it’s address will never change.
IGlobals private immutable _GLOBALS;
// Set immutables.
constructor(IGlobals globals) {
_GLOBALS = globals;
}
/// @inheritdoc IPartyFactory
function createParty(
Party partyImpl,
address[] memory authorities,
Party.PartyOptions memory opts,
IERC721[] memory preciousTokens,
uint256[] memory preciousTokenIds,
uint40 rageQuitTimestamp
) public returns (Party party) {
// Ensure an authority is set to mint governance NFTs.
if (authorities.length == 0) {
revert NoAuthorityError();
}
// Deploy a new proxified `Party` instance.
Party.PartyInitData memory initData = Party.PartyInitData({
options: opts,
preciousTokens: preciousTokens,
preciousTokenIds: preciousTokenIds,
authorities: authorities,
rageQuitTimestamp: rageQuitTimestamp
});
party = Party(payable(address(partyImpl).clone()));
party.initialize(initData);
emit PartyCreated(party, opts, preciousTokens, preciousTokenIds, msg.sender);
}
/// @inheritdoc IPartyFactory
function createPartyWithMetadata(
Party partyImpl,
address[] memory authorities,
Party.PartyOptions memory opts,
IERC721[] memory preciousTokens,
uint256[] memory preciousTokenIds,
uint40 rageQuitTimestamp,
MetadataProvider provider,
bytes memory metadata
) external returns (Party party) {
party = createParty(
partyImpl,
authorities,
opts,
preciousTokens,
preciousTokenIds,
rageQuitTimestamp
);
MetadataRegistry registry = MetadataRegistry(
_GLOBALS.getAddress(LibGlobals.GLOBAL_METADATA_REGISTRY)
);
// Set the metadata for the Party.
registry.setProvider(address(party), provider);
if (metadata.length > 0) provider.setMetadata(address(party), metadata);
}
}