-
Notifications
You must be signed in to change notification settings - Fork 6
/
DeploySpace.s.sol
317 lines (294 loc) · 12.3 KB
/
DeploySpace.s.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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;
//interfaces
import {IDiamond, Diamond} from "@river-build/diamond/src/Diamond.sol";
import {IERC721A} from "contracts/src/diamond/facets/token/ERC721A/IERC721A.sol";
//libraries
//contracts
import {DiamondHelper} from "contracts/test/diamond/Diamond.t.sol";
import {Deployer} from "contracts/scripts/common/Deployer.s.sol";
// Facets
import {MultiInit} from "@river-build/diamond/src/initializers/MultiInit.sol";
import {DeployDiamondCut} from "contracts/scripts/deployments/facets/DeployDiamondCut.s.sol";
import {DeployDiamondLoupe} from "contracts/scripts/deployments/facets/DeployDiamondLoupe.s.sol";
import {DeployIntrospection} from "contracts/scripts/deployments/facets/DeployIntrospection.s.sol";
import {DeployERC721AQueryable} from "contracts/scripts/deployments/facets/DeployERC721AQueryable.s.sol";
import {DeployBanning} from "contracts/scripts/deployments/facets/DeployBanning.s.sol";
import {DeployMembershipMetadata} from "contracts/scripts/deployments/facets/DeployMembershipMetadata.s.sol";
import {DeployMembership} from "contracts/scripts/deployments/facets/DeployMembership.s.sol";
import {DeployEntitlementDataQueryable} from "contracts/scripts/deployments/facets/DeployEntitlementDataQueryable.s.sol";
import {DeployOwnablePendingFacet} from "contracts/scripts/deployments/facets/DeployOwnablePendingFacet.s.sol";
import {DeployTokenOwnable} from "contracts/scripts/deployments/facets/DeployTokenOwnable.s.sol";
import {DeployEntitlementsManager} from "contracts/scripts/deployments/facets/DeployEntitlementsManager.s.sol";
import {DeployRoles} from "contracts/scripts/deployments/facets/DeployRoles.s.sol";
import {DeployChannels} from "contracts/scripts/deployments/facets/DeployChannels.s.sol";
import {DeployTokenPausable} from "contracts/scripts/deployments/facets/DeployTokenPausable.s.sol";
import {DeployPrepayFacet} from "contracts/scripts/deployments/facets/DeployPrepayFacet.s.sol";
import {DeployReferrals} from "contracts/scripts/deployments/facets/DeployReferrals.s.sol";
import {DeployMembershipToken} from "contracts/scripts/deployments/facets/DeployMembershipToken.s.sol";
import {DeploySpaceEntitlementGated} from "contracts/scripts/deployments/facets/DeploySpaceEntitlementGated.s.sol";
import {DeployTipping} from "contracts/scripts/deployments/facets/DeployTipping.s.sol";
import {DeployMultiInit} from "contracts/scripts/deployments/utils/DeployMultiInit.s.sol";
contract DeploySpace is DiamondHelper, Deployer {
DeployDiamondCut diamondCutHelper = new DeployDiamondCut();
DeployDiamondLoupe diamondLoupeHelper = new DeployDiamondLoupe();
DeployIntrospection introspectionHelper = new DeployIntrospection();
DeployERC721AQueryable erc721aQueryableHelper = new DeployERC721AQueryable();
DeployBanning banningHelper = new DeployBanning();
DeployMembership membershipHelper = new DeployMembership();
DeployMembershipMetadata membershipMetadataHelper =
new DeployMembershipMetadata();
DeployEntitlementDataQueryable entitlementDataQueryableHelper =
new DeployEntitlementDataQueryable();
DeployOwnablePendingFacet ownablePendingHelper =
new DeployOwnablePendingFacet();
DeployTokenOwnable tokenOwnableHelper = new DeployTokenOwnable();
DeployEntitlementsManager entitlementsHelper =
new DeployEntitlementsManager();
DeployRoles rolesHelper = new DeployRoles();
DeployChannels channelsHelper = new DeployChannels();
DeployTokenPausable tokenPausableHelper = new DeployTokenPausable();
DeployPrepayFacet prepayHelper = new DeployPrepayFacet();
DeployReferrals referralsHelper = new DeployReferrals();
DeployMembershipToken membershipTokenHelper = new DeployMembershipToken();
DeploySpaceEntitlementGated entitlementGatedHelper =
new DeploySpaceEntitlementGated();
DeployMultiInit deployMultiInit = new DeployMultiInit();
DeployTipping tippingHelper = new DeployTipping();
address tokenOwnable;
address diamondCut;
address diamondLoupe;
address entitlements;
address channels;
address roles;
address tokenPausable;
address introspection;
address membership;
address membershipReferral;
address banning;
address entitlementGated;
address membershipToken;
address erc721aQueryable;
address membershipMetadata;
address entitlementDataQueryable;
address ownablePending;
address prepay;
address referrals;
address tipping;
address multiInit;
function versionName() public pure override returns (string memory) {
return "space";
}
function addImmutableCuts(address deployer) internal {
multiInit = deployMultiInit.deploy(deployer);
diamondCut = diamondCutHelper.deploy(deployer);
diamondLoupe = diamondLoupeHelper.deploy(deployer);
introspection = introspectionHelper.deploy(deployer);
ownablePending = ownablePendingHelper.deploy(deployer);
tokenOwnable = tokenOwnableHelper.deploy(deployer);
addCut(diamondCutHelper.makeCut(diamondCut, IDiamond.FacetCutAction.Add));
addCut(
diamondLoupeHelper.makeCut(diamondLoupe, IDiamond.FacetCutAction.Add)
);
addCut(
introspectionHelper.makeCut(introspection, IDiamond.FacetCutAction.Add)
);
addCut(
ownablePendingHelper.makeCut(ownablePending, IDiamond.FacetCutAction.Add)
);
addCut(
tokenOwnableHelper.makeCut(tokenOwnable, IDiamond.FacetCutAction.Add)
);
addInit(diamondCut, diamondCutHelper.makeInitData(""));
addInit(diamondLoupe, diamondLoupeHelper.makeInitData(""));
addInit(introspection, introspectionHelper.makeInitData(""));
addInit(ownablePending, ownablePendingHelper.makeInitData(deployer));
}
function diamondInitParams(
address deployer
) public returns (Diamond.InitParams memory) {
membershipToken = membershipTokenHelper.deploy(deployer);
erc721aQueryable = erc721aQueryableHelper.deploy(deployer);
banning = banningHelper.deploy(deployer);
membership = membershipHelper.deploy(deployer);
membershipMetadata = membershipMetadataHelper.deploy(deployer);
entitlementDataQueryable = entitlementDataQueryableHelper.deploy(deployer);
entitlements = entitlementsHelper.deploy(deployer);
roles = rolesHelper.deploy(deployer);
channels = channelsHelper.deploy(deployer);
tokenPausable = tokenPausableHelper.deploy(deployer);
prepay = prepayHelper.deploy(deployer);
referrals = referralsHelper.deploy(deployer);
entitlementGated = entitlementGatedHelper.deploy(deployer);
tipping = tippingHelper.deploy(deployer);
membershipTokenHelper.removeSelector(IERC721A.tokenURI.selector);
addCut(
entitlementsHelper.makeCut(entitlements, IDiamond.FacetCutAction.Add)
);
addCut(rolesHelper.makeCut(roles, IDiamond.FacetCutAction.Add));
addCut(
tokenPausableHelper.makeCut(tokenPausable, IDiamond.FacetCutAction.Add)
);
addCut(channelsHelper.makeCut(channels, IDiamond.FacetCutAction.Add));
addCut(
membershipTokenHelper.makeCut(
membershipToken,
IDiamond.FacetCutAction.Add
)
);
addCut(membershipHelper.makeCut(membership, IDiamond.FacetCutAction.Add));
addCut(banningHelper.makeCut(banning, IDiamond.FacetCutAction.Add));
addCut(
membershipMetadataHelper.makeCut(
membershipMetadata,
IDiamond.FacetCutAction.Add
)
);
addCut(
entitlementGatedHelper.makeCut(
entitlementGated,
IDiamond.FacetCutAction.Add
)
);
addCut(
erc721aQueryableHelper.makeCut(
erc721aQueryable,
IDiamond.FacetCutAction.Add
)
);
addCut(
entitlementDataQueryableHelper.makeCut(
entitlementDataQueryable,
IDiamond.FacetCutAction.Add
)
);
addCut(prepayHelper.makeCut(prepay, IDiamond.FacetCutAction.Add));
addCut(referralsHelper.makeCut(referrals, IDiamond.FacetCutAction.Add));
addCut(tippingHelper.makeCut(tipping, IDiamond.FacetCutAction.Add));
return
Diamond.InitParams({
baseFacets: baseFacets(),
init: multiInit,
initData: abi.encodeWithSelector(
MultiInit.multiInit.selector,
_initAddresses,
_initDatas
)
});
}
function diamondInitParamsFromFacets(
address deployer,
string[] memory facets
) public {
for (uint256 i = 0; i < facets.length; i++) {
bytes32 facetNameHash = keccak256(abi.encodePacked(facets[i]));
if (facetNameHash == keccak256(abi.encodePacked("MembershipToken"))) {
membershipToken = membershipTokenHelper.deploy(deployer);
membershipTokenHelper.removeSelector(IERC721A.tokenURI.selector);
addCut(
membershipTokenHelper.makeCut(
membershipToken,
IDiamond.FacetCutAction.Add
)
);
} else if (
facetNameHash == keccak256(abi.encodePacked("ERC721AQueryable"))
) {
erc721aQueryable = erc721aQueryableHelper.deploy(deployer);
addCut(
erc721aQueryableHelper.makeCut(
erc721aQueryable,
IDiamond.FacetCutAction.Add
)
);
} else if (facetNameHash == keccak256(abi.encodePacked("Banning"))) {
banning = banningHelper.deploy(deployer);
addCut(banningHelper.makeCut(banning, IDiamond.FacetCutAction.Add));
} else if (
facetNameHash == keccak256(abi.encodePacked("MembershipFacet"))
) {
membership = membershipHelper.deploy(deployer);
addCut(
membershipHelper.makeCut(membership, IDiamond.FacetCutAction.Add)
);
} else if (
facetNameHash == keccak256(abi.encodePacked("MembershipMetadata"))
) {
membershipMetadata = membershipMetadataHelper.deploy(deployer);
addCut(
membershipMetadataHelper.makeCut(
membershipMetadata,
IDiamond.FacetCutAction.Add
)
);
} else if (
facetNameHash == keccak256(abi.encodePacked("EntitlementDataQueryable"))
) {
entitlementDataQueryable = entitlementDataQueryableHelper.deploy(
deployer
);
addCut(
entitlementDataQueryableHelper.makeCut(
entitlementDataQueryable,
IDiamond.FacetCutAction.Add
)
);
} else if (
facetNameHash == keccak256(abi.encodePacked("EntitlementsManager"))
) {
entitlements = entitlementsHelper.deploy(deployer);
addCut(
entitlementsHelper.makeCut(entitlements, IDiamond.FacetCutAction.Add)
);
} else if (facetNameHash == keccak256(abi.encodePacked("Roles"))) {
roles = rolesHelper.deploy(deployer);
addCut(rolesHelper.makeCut(roles, IDiamond.FacetCutAction.Add));
} else if (facetNameHash == keccak256(abi.encodePacked("Channels"))) {
channels = channelsHelper.deploy(deployer);
addCut(channelsHelper.makeCut(channels, IDiamond.FacetCutAction.Add));
} else if (
facetNameHash == keccak256(abi.encodePacked("TokenPausableFacet"))
) {
tokenPausable = tokenPausableHelper.deploy(deployer);
addCut(
tokenPausableHelper.makeCut(
tokenPausable,
IDiamond.FacetCutAction.Add
)
);
} else if (facetNameHash == keccak256(abi.encodePacked("PrepayFacet"))) {
prepay = prepayHelper.deploy(deployer);
addCut(prepayHelper.makeCut(prepay, IDiamond.FacetCutAction.Add));
} else if (
facetNameHash == keccak256(abi.encodePacked("ReferralsFacet"))
) {
referrals = referralsHelper.deploy(deployer);
addCut(referralsHelper.makeCut(referrals, IDiamond.FacetCutAction.Add));
} else if (
facetNameHash == keccak256(abi.encodePacked("SpaceEntitlementGated"))
) {
entitlementGated = entitlementGatedHelper.deploy(deployer);
addCut(
entitlementGatedHelper.makeCut(
entitlementGated,
IDiamond.FacetCutAction.Add
)
);
}
}
}
function diamondInitHelper(
address deployer,
string[] memory facetNames
) external override returns (FacetCut[] memory) {
diamondInitParamsFromFacets(deployer, facetNames);
return this.getCuts();
}
function __deploy(address deployer) public override returns (address) {
addImmutableCuts(deployer);
Diamond.InitParams memory initDiamondCut = diamondInitParams(deployer);
vm.broadcast(deployer);
Diamond diamond = new Diamond(initDiamondCut);
return address(diamond);
}
}