-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCrowdfundFactory.sol
242 lines (230 loc) · 10.8 KB
/
CrowdfundFactory.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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.17;
import "../globals/IGlobals.sol";
import "../utils/LibRawResult.sol";
import "../utils/Proxy.sol";
import "../renderers/RendererStorage.sol";
import "./AuctionCrowdfund.sol";
import "./BuyCrowdfund.sol";
import "./CollectionBuyCrowdfund.sol";
import "./RollingAuctionCrowdfund.sol";
import "./CollectionBatchBuyCrowdfund.sol";
import "./InitialETHCrowdfund.sol";
import "./ReraiseETHCrowdfund.sol";
/// @notice Factory used to deploys new proxified `Crowdfund` instances.
contract CrowdfundFactory {
using LibRawResult for bytes;
event BuyCrowdfundCreated(BuyCrowdfund crowdfund, BuyCrowdfund.BuyCrowdfundOptions opts);
event AuctionCrowdfundCreated(
AuctionCrowdfund crowdfund,
AuctionCrowdfundBase.AuctionCrowdfundOptions opts
);
event CollectionBuyCrowdfundCreated(
CollectionBuyCrowdfund crowdfund,
CollectionBuyCrowdfund.CollectionBuyCrowdfundOptions opts
);
event RollingAuctionCrowdfundCreated(
RollingAuctionCrowdfund crowdfund,
AuctionCrowdfundBase.AuctionCrowdfundOptions opts,
bytes32 allowedAuctionsMerkleRoot
);
event CollectionBatchBuyCrowdfundCreated(
CollectionBatchBuyCrowdfund crowdfund,
CollectionBatchBuyCrowdfund.CollectionBatchBuyCrowdfundOptions opts
);
event InitialETHCrowdfundCreated(
InitialETHCrowdfund crowdfund,
InitialETHCrowdfund.InitialETHCrowdfundOptions crowdfundOpts,
InitialETHCrowdfund.ETHPartyOptions partyOpts
);
event ReraiseETHCrowdfundCreated(
ReraiseETHCrowdfund crowdfund,
ETHCrowdfundBase.ETHCrowdfundOptions opts
);
/// @notice Create a new crowdfund to purchase a specific NFT (i.e., with a
/// known token ID) listing for a known price.
/// @param crowdfundImpl The implementation contract of the crowdfund to create.
/// @param opts Options used to initialize the crowdfund. These are fixed
/// and cannot be changed later.
/// @param createGateCallData Encoded calldata used by `createGate()` to
/// create the crowdfund if one is specified in `opts`.
function createBuyCrowdfund(
BuyCrowdfund crowdfundImpl,
BuyCrowdfund.BuyCrowdfundOptions memory opts,
bytes memory createGateCallData
) public payable returns (BuyCrowdfund inst) {
opts.gateKeeperId = _prepareGate(opts.gateKeeper, opts.gateKeeperId, createGateCallData);
inst = BuyCrowdfund(
payable(
new Proxy{ value: msg.value }(
Implementation(address(crowdfundImpl)),
abi.encodeCall(BuyCrowdfund.initialize, (opts))
)
)
);
emit BuyCrowdfundCreated(inst, opts);
}
/// @notice Create a new crowdfund to bid on an auction for a specific NFT
/// (i.e. with a known token ID).
/// @param crowdfundImpl The implementation contract of the crowdfund to create.
/// @param opts Options used to initialize the crowdfund. These are fixed
/// and cannot be changed later.
/// @param createGateCallData Encoded calldata used by `createGate()` to create
/// the crowdfund if one is specified in `opts`.
function createAuctionCrowdfund(
AuctionCrowdfund crowdfundImpl,
AuctionCrowdfundBase.AuctionCrowdfundOptions memory opts,
bytes memory createGateCallData
) public payable returns (AuctionCrowdfund inst) {
opts.gateKeeperId = _prepareGate(opts.gateKeeper, opts.gateKeeperId, createGateCallData);
inst = AuctionCrowdfund(
payable(
new Proxy{ value: msg.value }(
Implementation(address(crowdfundImpl)),
abi.encodeCall(AuctionCrowdfund.initialize, (opts))
)
)
);
emit AuctionCrowdfundCreated(inst, opts);
}
/// @notice Create a new crowdfund to bid on an auctions for an NFT from a collection
/// on a market (e.g. Nouns).
/// @param crowdfundImpl The implementation contract of the crowdfund to create.
/// @param opts Options used to initialize the crowdfund. These are fixed
/// and cannot be changed later.
/// @param createGateCallData Encoded calldata used by `createGate()` to create
/// the crowdfund if one is specified in `opts`.
function createRollingAuctionCrowdfund(
RollingAuctionCrowdfund crowdfundImpl,
AuctionCrowdfundBase.AuctionCrowdfundOptions memory opts,
bytes32 allowedAuctionsMerkleRoot,
bytes memory createGateCallData
) public payable returns (RollingAuctionCrowdfund inst) {
opts.gateKeeperId = _prepareGate(opts.gateKeeper, opts.gateKeeperId, createGateCallData);
inst = RollingAuctionCrowdfund(
payable(
new Proxy{ value: msg.value }(
Implementation(address(crowdfundImpl)),
abi.encodeCall(
RollingAuctionCrowdfund.initialize,
(opts, allowedAuctionsMerkleRoot)
)
)
)
);
emit RollingAuctionCrowdfundCreated(inst, opts, allowedAuctionsMerkleRoot);
}
/// @notice Create a new crowdfund to purchases any NFT from a collection
/// (i.e. any token ID) from a collection for a known price.
/// @param opts Options used to initialize the crowdfund. These are fixed
/// and cannot be changed later.
/// @param createGateCallData Encoded calldata used by `createGate()` to create
/// the crowdfund if one is specified in `opts`.
function createCollectionBuyCrowdfund(
CollectionBuyCrowdfund crowdfundImpl,
CollectionBuyCrowdfund.CollectionBuyCrowdfundOptions memory opts,
bytes memory createGateCallData
) public payable returns (CollectionBuyCrowdfund inst) {
opts.gateKeeperId = _prepareGate(opts.gateKeeper, opts.gateKeeperId, createGateCallData);
inst = CollectionBuyCrowdfund(
payable(
new Proxy{ value: msg.value }(
Implementation(address(crowdfundImpl)),
abi.encodeCall(CollectionBuyCrowdfund.initialize, (opts))
)
)
);
emit CollectionBuyCrowdfundCreated(inst, opts);
}
/// @notice Create a new crowdfund to purchase multiple NFTs from a collection
/// (i.e. any token ID) from a collection for known prices.
/// @param opts Options used to initialize the crowdfund. These are fixed
/// and cannot be changed later.
/// @param createGateCallData Encoded calldata used by `createGate()` to create
/// the crowdfund if one is specified in `opts`.
function createCollectionBatchBuyCrowdfund(
CollectionBatchBuyCrowdfund crowdfundImpl,
CollectionBatchBuyCrowdfund.CollectionBatchBuyCrowdfundOptions memory opts,
bytes memory createGateCallData
) public payable returns (CollectionBatchBuyCrowdfund inst) {
opts.gateKeeperId = _prepareGate(opts.gateKeeper, opts.gateKeeperId, createGateCallData);
inst = CollectionBatchBuyCrowdfund(
payable(
new Proxy{ value: msg.value }(
Implementation(address(crowdfundImpl)),
abi.encodeCall(CollectionBatchBuyCrowdfund.initialize, (opts))
)
)
);
emit CollectionBatchBuyCrowdfundCreated(inst, opts);
}
/// @notice Create a new crowdfund to raise ETH for a new party.
/// @param crowdfundImpl The implementation contract of the crowdfund to create.
/// @param crowdfundOpts Options used to initialize the crowdfund. These are fixed
/// and cannot be changed later.
/// @param partyOpts Options used to initialize the party created by the crowdfund.
/// These are fixed and cannot be changed later.
/// @param createGateCallData Encoded calldata used by `createGate()` to create
/// the crowdfund if one is specified in `opts`.
function createInitialETHCrowdfund(
InitialETHCrowdfund crowdfundImpl,
InitialETHCrowdfund.InitialETHCrowdfundOptions memory crowdfundOpts,
InitialETHCrowdfund.ETHPartyOptions memory partyOpts,
bytes memory createGateCallData
) public payable returns (InitialETHCrowdfund inst) {
crowdfundOpts.gateKeeperId = _prepareGate(
crowdfundOpts.gateKeeper,
crowdfundOpts.gateKeeperId,
createGateCallData
);
inst = InitialETHCrowdfund(
payable(
new Proxy{ value: msg.value }(
Implementation(address(crowdfundImpl)),
abi.encodeCall(InitialETHCrowdfund.initialize, (crowdfundOpts, partyOpts))
)
)
);
emit InitialETHCrowdfundCreated(inst, crowdfundOpts, partyOpts);
}
/// @notice Create a new crowdfund to raise ETH for an existing party.
/// @param crowdfundImpl The implementation contract of the crowdfund to create.
/// @param opts Options used to initialize the crowdfund. These are fixed
/// and cannot be changed later.
/// @param createGateCallData Encoded calldata used by `createGate()` to create
/// the crowdfund if one is specified in `opts`.
function createReraiseETHCrowdfund(
ReraiseETHCrowdfund crowdfundImpl,
ETHCrowdfundBase.ETHCrowdfundOptions memory opts,
bytes memory createGateCallData
) public payable returns (ReraiseETHCrowdfund inst) {
opts.gateKeeperId = _prepareGate(opts.gateKeeper, opts.gateKeeperId, createGateCallData);
inst = ReraiseETHCrowdfund(
payable(
new Proxy{ value: msg.value }(
Implementation(address(crowdfundImpl)),
abi.encodeCall(ReraiseETHCrowdfund.initialize, (opts))
)
)
);
emit ReraiseETHCrowdfundCreated(inst, opts);
}
function _prepareGate(
IGateKeeper gateKeeper,
bytes12 gateKeeperId,
bytes memory createGateCallData
) private returns (bytes12 newGateKeeperId) {
if (address(gateKeeper) == address(0) || gateKeeperId != bytes12(0)) {
// Using an existing gate on the gatekeeper
// or not using a gate at all.
return gateKeeperId;
}
// Call the gate creation function on the gatekeeper.
(bool s, bytes memory r) = address(gateKeeper).call(createGateCallData);
if (!s) {
r.rawRevert();
}
// Result is always a bytes12.
return abi.decode(r, (bytes12));
}
}