@artblocks/contracts 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/.env.example +8 -1
  2. package/README.md +42 -157
  3. package/artifacts/contracts/AdminACLV1.sol/AdminACLV1.json +2 -2
  4. package/artifacts/contracts/DependencyRegistryV0.sol/DependencyRegistryV0.json +2 -2
  5. package/artifacts/contracts/GenArt721CoreV3.sol/GenArt721CoreV3.json +2 -2
  6. package/artifacts/contracts/GenArt721CoreV3_Engine.sol/GenArt721CoreV3_Engine.json +2 -2
  7. package/artifacts/contracts/GenArt721CoreV3_Engine_Flex.sol/GenArt721CoreV3_Engine_Flex.json +2229 -0
  8. package/artifacts/contracts/archive/minter-suite/Minters/MinterDAExp/MinterDAExpV2.sol/MinterDAExpV2.json +2 -2
  9. package/artifacts/contracts/archive/minter-suite/Minters/MinterDAExp/MinterDAExpV3.sol/MinterDAExpV3.json +2 -2
  10. package/artifacts/contracts/archive/minter-suite/Minters/MinterDAExpSettlement/MinterDAExpSettlementV0.sol/MinterDAExpSettlementV0.json +2 -2
  11. package/artifacts/contracts/archive/minter-suite/Minters/MinterDAExpSettlement/MinterDAExpSettlementV1.sol/MinterDAExpSettlementV1.json +2 -2
  12. package/artifacts/contracts/archive/minter-suite/Minters/MinterDALin/MinterDALinV2.sol/MinterDALinV2.json +2 -2
  13. package/artifacts/contracts/archive/minter-suite/Minters/MinterDALin/MinterDALinV3.sol/MinterDALinV3.json +2 -2
  14. package/artifacts/contracts/archive/minter-suite/Minters/MinterHolder/MinterHolderV1.sol/MinterHolderV1.json +2 -2
  15. package/artifacts/contracts/archive/minter-suite/Minters/MinterHolder/MinterHolderV2.sol/MinterHolderV2.json +2 -2
  16. package/artifacts/contracts/archive/minter-suite/Minters/MinterHolder/MinterHolderV3.sol/MinterHolderV3.json +2 -2
  17. package/artifacts/contracts/archive/minter-suite/Minters/MinterMerkle/MinterMerkleV1.sol/MinterMerkleV1.json +2 -2
  18. package/artifacts/contracts/archive/minter-suite/Minters/MinterMerkle/MinterMerkleV2.sol/MinterMerkleV2.json +2 -2
  19. package/artifacts/contracts/archive/minter-suite/Minters/MinterMerkle/MinterMerkleV3.sol/MinterMerkleV3.json +2 -2
  20. package/artifacts/contracts/archive/minter-suite/Minters/MinterMerkle/MinterMerkleV4.sol/MinterMerkleV4.json +2 -2
  21. package/artifacts/contracts/archive/minter-suite/Minters/MinterSetPrice/MinterSetPriceV2.sol/MinterSetPriceV2.json +2 -2
  22. package/artifacts/contracts/archive/minter-suite/Minters/MinterSetPrice/MinterSetPriceV3.sol/MinterSetPriceV3.json +2 -2
  23. package/artifacts/contracts/archive/minter-suite/Minters/MinterSetPriceERC20/MinterSetPriceERC20V2.sol/MinterSetPriceERC20V2.json +2 -2
  24. package/artifacts/contracts/archive/minter-suite/Minters/MinterSetPriceERC20/MinterSetPriceERC20V3.sol/MinterSetPriceERC20V3.json +2 -2
  25. package/artifacts/contracts/explorations/GenArt721CoreV3_Explorations.sol/GenArt721CoreV3_Explorations.json +2 -2
  26. package/artifacts/contracts/interfaces/0.8.x/IFilteredMinterSEAV0.sol/IFilteredMinterSEAV0.json +1032 -0
  27. package/artifacts/contracts/interfaces/0.8.x/IGenArt721CoreContractV3.sol/IGenArt721CoreContractV3.json +149 -0
  28. package/artifacts/contracts/interfaces/0.8.x/IGenArt721CoreContractV3_Base.sol/IGenArt721CoreContractV3_Base.json +149 -0
  29. package/artifacts/contracts/interfaces/0.8.x/IGenArt721CoreContractV3_Engine.sol/IGenArt721CoreContractV3_Engine.json +130 -0
  30. package/artifacts/contracts/interfaces/0.8.x/IGenArt721CoreContractV3_Engine_Flex.sol/IGenArt721CoreContractV3_Engine_Flex.json +1066 -0
  31. package/artifacts/contracts/interfaces/0.8.x/IWETH.sol/IWETH.json +55 -0
  32. package/artifacts/contracts/libs/integration-refs/weth9/weth9.sol/WETH9_.json +295 -0
  33. package/artifacts/contracts/minter-suite/MinterFilter/MinterFilterV1.sol/MinterFilterV1.json +2 -2
  34. package/artifacts/contracts/minter-suite/Minters/MinterDAExpSettlementV2.sol/MinterDAExpSettlementV2.json +2 -2
  35. package/artifacts/contracts/minter-suite/Minters/MinterDAExpV4.sol/MinterDAExpV4.json +2 -2
  36. package/artifacts/contracts/minter-suite/Minters/MinterDALinV4.sol/MinterDALinV4.json +2 -2
  37. package/artifacts/contracts/minter-suite/Minters/MinterHolderV4.sol/MinterHolderV4.json +2 -2
  38. package/artifacts/contracts/minter-suite/Minters/MinterMerkleV5.sol/MinterMerkleV5.json +2 -2
  39. package/artifacts/contracts/minter-suite/Minters/MinterPolyptychV0.sol/IGenArt721CoreContractV3WithRandomizer.json +130 -0
  40. package/artifacts/contracts/minter-suite/Minters/MinterPolyptychV0.sol/MinterPolyptychV0.json +2 -2
  41. package/artifacts/contracts/minter-suite/Minters/MinterSEAV0.sol/MinterSEAV0.json +1310 -0
  42. package/artifacts/contracts/minter-suite/Minters/MinterSetPriceERC20V4.sol/MinterSetPriceERC20V4.json +2 -2
  43. package/artifacts/contracts/minter-suite/Minters/MinterSetPriceV4.sol/MinterSetPriceV4.json +2 -2
  44. package/artifacts/contracts/mock/DeadReceiverBidderMock.sol/DeadReceiverBidderMock.json +33 -0
  45. package/artifacts/contracts/mock/GasLimitReceiverBidderMock.sol/GasLimitReceiverBidderMock.json +46 -0
  46. package/artifacts/contracts/mock/GasLimitReceiverMock.sol/GasLimitReceiverMock.json +28 -0
  47. package/artifacts/contracts/mock/GenArt721CoreV3_Engine_IncorrectCoreType.sol/GenArt721CoreV3_Engine_IncorrectCoreType.json +2 -2
  48. package/artifacts/contracts/mock/RandomizerV2_NoAssignMock.sol/RandomizerV2_NoAssignMock.json +2 -2
  49. package/artifacts/contracts/mock/ReentrancySEAMock.sol/ReentrancySEAAutoBidderMock.json +51 -0
  50. package/artifacts/contracts/{BasicRandomizer.sol → randomizer/BasicRandomizer.sol}/BasicRandomizer.json +3 -3
  51. package/artifacts/contracts/randomizer/BasicRandomizerBase_v0_0_0.sol/RandomizerBase.json +10 -0
  52. package/artifacts/contracts/randomizer/PolyptychRandomizerV0.sol/BasicPolyptychRandomizerV0.json +229 -0
  53. package/artifacts/contracts/randomizer/RandomizerV2.sol/BasicRandomizerV2.json +102 -0
  54. package/artifacts/contracts/royalty-registry/GenArt721RoyaltyOverride.sol/GenArt721RoyaltyOverride.json +2 -2
  55. package/contracts/DependencyRegistryV0.sol +74 -113
  56. package/contracts/GenArt721CoreV3.sol +124 -171
  57. package/contracts/GenArt721CoreV3_Engine.sol +136 -198
  58. package/contracts/GenArt721CoreV3_Engine_Flex.sol +2274 -0
  59. package/contracts/explorations/GenArt721CoreV3_Explorations.sol +147 -176
  60. package/contracts/interfaces/0.8.x/IFilteredMinterSEAV0.sol +145 -0
  61. package/contracts/interfaces/0.8.x/IGenArt721CoreContractV3_Base.sol +39 -0
  62. package/contracts/interfaces/0.8.x/IGenArt721CoreContractV3_Engine.sol +0 -3
  63. package/contracts/interfaces/0.8.x/IGenArt721CoreContractV3_Engine_Flex.sol +132 -0
  64. package/contracts/interfaces/0.8.x/IWETH.sol +11 -0
  65. package/contracts/libs/integration-refs/weth9/weth9.sol +763 -0
  66. package/contracts/minter-suite/MinterFilter/MinterFilterV1.sol +35 -47
  67. package/contracts/minter-suite/Minters/MinterDAExpSettlementV2.sol +26 -34
  68. package/contracts/minter-suite/Minters/MinterDAExpV4.sol +16 -21
  69. package/contracts/minter-suite/Minters/MinterDALinV4.sol +15 -17
  70. package/contracts/minter-suite/Minters/MinterHolderV4.sol +19 -19
  71. package/contracts/minter-suite/Minters/MinterMerkleV5.sol +13 -15
  72. package/contracts/minter-suite/Minters/MinterPolyptychV0.sol +23 -23
  73. package/contracts/minter-suite/Minters/MinterSEAV0.sol +1224 -0
  74. package/contracts/minter-suite/Minters/MinterSetPriceERC20V4.sol +11 -11
  75. package/contracts/minter-suite/Minters/MinterSetPriceV4.sol +9 -10
  76. package/contracts/mock/DeadReceiverBidderMock.sol +23 -0
  77. package/contracts/mock/GasLimitReceiverBidderMock.sol +23 -0
  78. package/contracts/mock/GasLimitReceiverMock.sol +19 -0
  79. package/contracts/mock/RandomizerV2_NoAssignMock.sol +2 -11
  80. package/contracts/mock/ReentrancySEAMock.sol +36 -0
  81. package/contracts/{BasicRandomizer.sol → randomizer/BasicRandomizer.sol} +1 -1
  82. package/contracts/randomizer/BasicRandomizerBase_v0_0_0.sol +23 -0
  83. package/contracts/{BasicPolyptychRandomizerV0.sol → randomizer/PolyptychRandomizerV0.sol} +19 -28
  84. package/contracts/{BasicRandomizerV2.sol → randomizer/RandomizerV2.sol} +5 -13
  85. package/package.json +27 -14
  86. package/artifacts/contracts/BasicPolyptychRandomizerV0.sol/BasicPolyptychRandomizerV0.json +0 -229
  87. package/artifacts/contracts/BasicRandomizerV2.sol/BasicRandomizerV2.json +0 -102
@@ -0,0 +1,2274 @@
1
+ // SPDX-License-Identifier: LGPL-3.0-only
2
+ pragma solidity 0.8.17;
3
+
4
+ // Created By: Art Blocks Inc.
5
+
6
+ import "./interfaces/0.8.x/IRandomizerV2.sol";
7
+ import "./interfaces/0.8.x/IAdminACLV0.sol";
8
+ import "./interfaces/0.8.x/IEngineRegistryV0.sol";
9
+ import "./interfaces/0.8.x/IGenArt721CoreContractV3_Engine_Flex.sol";
10
+ import "./interfaces/0.8.x/IDependencyRegistryCompatibleV0.sol";
11
+ import "./interfaces/0.8.x/IManifold.sol";
12
+
13
+ import "@openzeppelin-4.7/contracts/access/Ownable.sol";
14
+ import "./libs/0.8.x/ERC721_PackedHashSeed.sol";
15
+ import "./libs/0.8.x/BytecodeStorage.sol";
16
+ import "./libs/0.8.x/Bytes32Strings.sol";
17
+
18
+ /**
19
+ * @title Art Blocks Engine Flex ERC-721 core contract, V3.
20
+ * @author Art Blocks Inc.
21
+ * @notice Privileged Roles and Ownership:
22
+ * This contract is designed to be managed, with progressively limited powers
23
+ * as a project progresses from active to locked.
24
+ * Privileged roles and abilities are controlled by the admin ACL contract and
25
+ * artists. Both of these roles hold extensive power and can arbitrarily
26
+ * control and modify portions of projects, dependent upon project state. After
27
+ * a project is locked, important project metadata fields are locked including
28
+ * the project name, artist name, and script and display details. Edition size
29
+ * can never be increased.
30
+ * Care must be taken to ensure that the admin ACL contract and artist
31
+ * addresses are secure behind a multi-sig or other access control mechanism.
32
+ * ----------------------------------------------------------------------------
33
+ * The following functions are restricted to the Admin ACL contract:
34
+ * - updateArtblocksDependencyRegistryAddress
35
+ * - updateProviderSalesAddresses
36
+ * - updateProviderPrimarySalesPercentages (up to 100%)
37
+ * - updateProviderSecondarySalesBPS (up to 100%)
38
+ * - updateMinterContract
39
+ * - updateRandomizerAddress
40
+ * - toggleProjectIsActive
41
+ * - addProject
42
+ * - forbidNewProjects (forever forbidding new projects)
43
+ * - updateDefaultBaseURI (used to initialize new project base URIs)
44
+ * - updateIPFSGateway
45
+ * - updateArweaveGateway
46
+ * ----------------------------------------------------------------------------
47
+ * The following functions are restricted to either the the Artist address or
48
+ * the Admin ACL contract, only when the project is not locked:
49
+ * - updateProjectName
50
+ * - updateProjectArtistName
51
+ * - updateProjectLicense
52
+ * - Change project script via addProjectScript, updateProjectScript,
53
+ * and removeProjectLastScript
54
+ * - updateProjectScriptType
55
+ * - updateProjectAspectRatio
56
+ * ----------------------------------------------------------------------------
57
+ * The following functions are restricted to only the Artist address:
58
+ * - proposeArtistPaymentAddressesAndSplits (Note that this has to be accepted
59
+ * by adminAcceptArtistAddressesAndSplits to take effect, which is restricted
60
+ * to the Admin ACL contract, or the artist if the core contract owner has
61
+ * renounced ownership. Also note that a proposal will be automatically
62
+ * accepted if the artist only proposes changed payee percentages without
63
+ * modifying any payee addresses, or is only removing payee addresses, or
64
+ * if the global config `autoApproveArtistSplitProposals` is set to `true`.)
65
+ * - toggleProjectIsPaused (note the artist can still mint while paused)
66
+ * - updateProjectSecondaryMarketRoyaltyPercentage (up to
67
+ ARTIST_MAX_SECONDARY_ROYALTY_PERCENTAGE percent)
68
+ * - updateProjectWebsite
69
+ * - updateProjectMaxInvocations (to a number greater than or equal to the
70
+ * current number of invocations, and less than current project maximum
71
+ * invocations)
72
+ * - updateProjectBaseURI (controlling the base URI for tokens in the project)
73
+ * ----------------------------------------------------------------------------
74
+ * The following function is restricted to either the Admin ACL contract, or
75
+ * the Artist address if the core contract owner has renounced ownership:
76
+ * - adminAcceptArtistAddressesAndSplits
77
+ * - updateProjectArtistAddress (owner ultimately controlling the project and
78
+ * its and-on revenue, unless owner has renounced ownership)
79
+ * ----------------------------------------------------------------------------
80
+ * The following function is restricted to the artist when a project is
81
+ * unlocked, and only callable by Admin ACL contract when a project is locked:
82
+ * - updateProjectDescription
83
+ * ----------------------------------------------------------------------------
84
+ * The following functions for managing external asset dependencies are restricted
85
+ * to projects with external asset dependencies that are unlocked:
86
+ * - lockProjectExternalAssetDependencies
87
+ * - updateProjectExternalAssetDependency
88
+ * - removeProjectExternalAssetDependency
89
+ * - addProjectExternalAssetDependency
90
+ * ----------------------------------------------------------------------------
91
+ * The following function is restricted to owner calling directly:
92
+ * - transferOwnership
93
+ * - renounceOwnership
94
+ * ----------------------------------------------------------------------------
95
+ * The following configuration variables are set at time of contract deployment,
96
+ * and not modifiable thereafter (immutable after the point of deployment):
97
+ * - (bool) autoApproveArtistSplitProposals
98
+ * ----------------------------------------------------------------------------
99
+ * Additional admin and artist privileged roles may be described on minters,
100
+ * registries, and other contracts that may interact with this core contract.
101
+ */
102
+ contract GenArt721CoreV3_Engine_Flex is
103
+ ERC721_PackedHashSeed,
104
+ Ownable,
105
+ IDependencyRegistryCompatibleV0,
106
+ IManifold,
107
+ IGenArt721CoreContractV3_Engine_Flex
108
+ {
109
+ using BytecodeStorage for string;
110
+ using BytecodeStorage for address;
111
+ using Bytes32Strings for bytes32;
112
+ uint256 constant ONE_HUNDRED = 100;
113
+ uint256 constant ONE_MILLION = 1_000_000;
114
+ uint24 constant ONE_MILLION_UINT24 = 1_000_000;
115
+ uint256 constant FOUR_WEEKS_IN_SECONDS = 2_419_200;
116
+ uint8 constant AT_CHARACTER_CODE = uint8(bytes1("@")); // 0x40
117
+
118
+ // numeric constants
119
+ uint256 constant MAX_PROVIDER_SECONDARY_SALES_BPS = 10000; // 10_000 BPS = 100%
120
+ uint256 constant ARTIST_MAX_SECONDARY_ROYALTY_PERCENTAGE = 95; // 95%
121
+
122
+ // This contract emits generic events that contain fields that indicate
123
+ // which parameter has been updated. This is sufficient for application
124
+ // state management, while also simplifying the contract and indexing code.
125
+ // This was done as an alternative to having custom events that emit what
126
+ // field-values have changed for each event, given that changed values can
127
+ // be introspected by indexers due to the design of this smart contract
128
+ // exposing these state changes via publicly viewable fields.
129
+ //
130
+ // The following fields are used to indicate which contract-level parameter
131
+ // has been updated in the `PlatformUpdated` event:
132
+ bytes32 constant FIELD_NEXT_PROJECT_ID = "nextProjectId";
133
+ bytes32 constant FIELD_NEW_PROJECTS_FORBIDDEN = "newProjectsForbidden";
134
+ bytes32 constant FIELD_DEFAULT_BASE_URI = "defaultBaseURI";
135
+ bytes32 constant FIELD_RANDOMIZER_ADDRESS = "randomizerAddress";
136
+ bytes32 constant FIELD_ARTBLOCKS_DEPENDENCY_REGISTRY_ADDRESS =
137
+ "dependencyRegistryAddress";
138
+ bytes32 constant FIELD_PROVIDER_SALES_ADDRESSES = "providerSalesAddresses";
139
+ bytes32 constant FIELD_PROVIDER_PRIMARY_SALES_PERCENTAGES =
140
+ "providerPrimaryPercentages";
141
+ bytes32 constant FIELD_PROVIDER_SECONDARY_SALES_BPS =
142
+ "providerSecondaryBPS";
143
+ // The following fields are used to indicate which project-level parameter
144
+ // has been updated in the `ProjectUpdated` event:
145
+ bytes32 constant FIELD_PROJECT_COMPLETED = "completed";
146
+ bytes32 constant FIELD_PROJECT_ACTIVE = "active";
147
+ bytes32 constant FIELD_PROJECT_ARTIST_ADDRESS = "artistAddress";
148
+ bytes32 constant FIELD_PROJECT_PAUSED = "paused";
149
+ bytes32 constant FIELD_PROJECT_CREATED = "created";
150
+ bytes32 constant FIELD_PROJECT_NAME = "name";
151
+ bytes32 constant FIELD_PROJECT_ARTIST_NAME = "artistName";
152
+ bytes32 constant FIELD_PROJECT_SECONDARY_MARKET_ROYALTY_PERCENTAGE =
153
+ "royaltyPercentage";
154
+ bytes32 constant FIELD_PROJECT_DESCRIPTION = "description";
155
+ bytes32 constant FIELD_PROJECT_WEBSITE = "website";
156
+ bytes32 constant FIELD_PROJECT_LICENSE = "license";
157
+ bytes32 constant FIELD_PROJECT_MAX_INVOCATIONS = "maxInvocations";
158
+ bytes32 constant FIELD_PROJECT_SCRIPT = "script";
159
+ bytes32 constant FIELD_PROJECT_SCRIPT_TYPE = "scriptType";
160
+ bytes32 constant FIELD_PROJECT_ASPECT_RATIO = "aspectRatio";
161
+ bytes32 constant FIELD_PROJECT_BASE_URI = "baseURI";
162
+
163
+ /// Dependency registry managed by Art Blocks
164
+ address public artblocksDependencyRegistryAddress;
165
+
166
+ /// current randomizer contract
167
+ IRandomizerV2 public randomizerContract;
168
+
169
+ /// append-only array of all randomizer contract addresses ever used by
170
+ /// this contract
171
+ address[] private _historicalRandomizerAddresses;
172
+
173
+ /// admin ACL contract
174
+ IAdminACLV0 public adminACLContract;
175
+
176
+ struct Project {
177
+ uint24 invocations;
178
+ uint24 maxInvocations;
179
+ uint24 scriptCount;
180
+ // max uint64 ~= 1.8e19 sec ~= 570 billion years
181
+ uint64 completedTimestamp;
182
+ bool active;
183
+ bool paused;
184
+ string name;
185
+ string artist;
186
+ string description;
187
+ string website;
188
+ string license;
189
+ string projectBaseURI;
190
+ bytes32 scriptTypeAndVersion;
191
+ string aspectRatio;
192
+ // mapping from script index to address storing script in bytecode
193
+ mapping(uint256 => address) scriptBytecodeAddresses;
194
+ bool externalAssetDependenciesLocked;
195
+ uint24 externalAssetDependencyCount;
196
+ mapping(uint256 => ExternalAssetDependency) externalAssetDependencies;
197
+ }
198
+
199
+ mapping(uint256 => Project) projects;
200
+
201
+ string public preferredIPFSGateway;
202
+ string public preferredArweaveGateway;
203
+
204
+ /// packed struct containing project financial information
205
+ struct ProjectFinance {
206
+ address payable additionalPayeePrimarySales;
207
+ // packed uint: max of 95, max uint8 = 255
208
+ uint8 secondaryMarketRoyaltyPercentage;
209
+ address payable additionalPayeeSecondarySales;
210
+ // packed uint: max of 100, max uint8 = 255
211
+ uint8 additionalPayeeSecondarySalesPercentage;
212
+ address payable artistAddress;
213
+ // packed uint: max of 100, max uint8 = 255
214
+ uint8 additionalPayeePrimarySalesPercentage;
215
+ }
216
+ // Project financials mapping
217
+ mapping(uint256 => ProjectFinance) projectIdToFinancials;
218
+
219
+ /// hash of artist's proposed payment updates to be approved by admin
220
+ mapping(uint256 => bytes32) public proposedArtistAddressesAndSplitsHash;
221
+
222
+ /// The render provider payment address for all primary sales revenues
223
+ /// (packed)
224
+ address payable public renderProviderPrimarySalesAddress;
225
+ /// Percentage of primary sales revenue allocated to the render provider
226
+ /// (packed)
227
+ // packed uint: max of 100, max uint8 = 255
228
+ uint8 private _renderProviderPrimarySalesPercentage = 10;
229
+ /// The platform provider payment address for all primary sales revenues
230
+ /// (packed)
231
+ address payable public platformProviderPrimarySalesAddress;
232
+ /// Percentage of primary sales revenue allocated to the platform provider
233
+ /// (packed)
234
+ // packed uint: max of 100, max uint8 = 255
235
+ uint8 private _platformProviderPrimarySalesPercentage = 10;
236
+
237
+ /// The render provider payment address for all secondary sales royalty
238
+ /// revenues
239
+ address payable public renderProviderSecondarySalesAddress;
240
+ /// Basis Points of secondary sales royalties allocated to the
241
+ /// render provider
242
+ uint256 public renderProviderSecondarySalesBPS = 250;
243
+ /// The platform provider payment address for all secondary sales royalty
244
+ /// revenues
245
+ address payable public platformProviderSecondarySalesAddress;
246
+ /// Basis Points of secondary sales royalties allocated to the
247
+ /// platform provider
248
+ uint256 public platformProviderSecondarySalesBPS = 250;
249
+
250
+ /// single minter allowed for this core contract
251
+ address public minterContract;
252
+
253
+ /// starting (initial) project ID on this contract
254
+ uint256 public immutable startingProjectId;
255
+
256
+ /// next project ID to be created
257
+ uint248 private _nextProjectId;
258
+
259
+ /// bool indicating if adding new projects is forbidden;
260
+ /// default behavior is to allow new projects
261
+ bool public newProjectsForbidden;
262
+
263
+ /// configuration variable (determined at time of deployment)
264
+ /// that determines whether or not admin approval^ should be required
265
+ /// to accept artist address change proposals, or if these proposals
266
+ /// should always auto-approve, as determined by the business process
267
+ /// requirements of the Engine partner using this contract.
268
+ ///
269
+ /// ^does not apply in the case where contract-ownership itself is revoked
270
+ bool public immutable autoApproveArtistSplitProposals;
271
+
272
+ /// version & type of this core contract
273
+ bytes32 constant CORE_VERSION = "v3.1.2";
274
+
275
+ function coreVersion() external pure returns (string memory) {
276
+ return CORE_VERSION.toString();
277
+ }
278
+
279
+ bytes32 constant CORE_TYPE = "GenArt721CoreV3_Engine_Flex";
280
+
281
+ function coreType() external pure returns (string memory) {
282
+ return CORE_TYPE.toString();
283
+ }
284
+
285
+ /// default base URI to initialize all new project projectBaseURI values to
286
+ string public defaultBaseURI;
287
+
288
+ function _onlyUnlockedProjectExternalAssetDependencies(
289
+ uint256 _projectId
290
+ ) internal view {
291
+ require(
292
+ !projects[_projectId].externalAssetDependenciesLocked,
293
+ "External dependencies locked"
294
+ );
295
+ }
296
+
297
+ function _onlyNonZeroAddress(address _address) internal pure {
298
+ require(_address != address(0), "Must input non-zero address");
299
+ }
300
+
301
+ function _onlyNonEmptyString(string memory _string) internal pure {
302
+ require(bytes(_string).length != 0, "Must input non-empty string");
303
+ }
304
+
305
+ function _onlyValidTokenId(uint256 _tokenId) internal view {
306
+ require(_exists(_tokenId), "Token ID does not exist");
307
+ }
308
+
309
+ function _onlyValidProjectId(uint256 _projectId) internal view {
310
+ require(
311
+ (_projectId >= startingProjectId) && (_projectId < _nextProjectId),
312
+ "Project ID does not exist"
313
+ );
314
+ }
315
+
316
+ function _onlyUnlocked(uint256 _projectId) internal view {
317
+ // Note: calling `_projectUnlocked` enforces that the `_projectId`
318
+ // passed in is valid.`
319
+ require(_projectUnlocked(_projectId), "Only if unlocked");
320
+ }
321
+
322
+ function _onlyAdminACL(bytes4 _selector) internal {
323
+ require(
324
+ adminACLAllowed(msg.sender, address(this), _selector),
325
+ "Only Admin ACL allowed"
326
+ );
327
+ }
328
+
329
+ function _onlyArtist(uint256 _projectId) internal view {
330
+ require(
331
+ msg.sender == projectIdToFinancials[_projectId].artistAddress,
332
+ "Only artist"
333
+ );
334
+ }
335
+
336
+ function _onlyArtistOrAdminACL(
337
+ uint256 _projectId,
338
+ bytes4 _selector
339
+ ) internal {
340
+ require(
341
+ msg.sender == projectIdToFinancials[_projectId].artistAddress ||
342
+ adminACLAllowed(msg.sender, address(this), _selector),
343
+ "Only artist or Admin ACL allowed"
344
+ );
345
+ }
346
+
347
+ /**
348
+ * This modifier allows the artist of a project to call a function if the
349
+ * owner of the contract has renounced ownership. This is to allow the
350
+ * contract to continue to function if the owner decides to renounce
351
+ * ownership.
352
+ */
353
+ function _onlyAdminACLOrRenouncedArtist(
354
+ uint256 _projectId,
355
+ bytes4 _selector
356
+ ) internal {
357
+ require(
358
+ adminACLAllowed(msg.sender, address(this), _selector) ||
359
+ (owner() == address(0) &&
360
+ msg.sender ==
361
+ projectIdToFinancials[_projectId].artistAddress),
362
+ "Only Admin ACL allowed, or artist if owner has renounced"
363
+ );
364
+ }
365
+
366
+ /**
367
+ * @notice Initializes contract.
368
+ * @param _tokenName Name of token.
369
+ * @param _tokenSymbol Token symbol.
370
+ * @param _randomizerContract Randomizer contract.
371
+ * @param _adminACLContract Address of admin access control contract, to be
372
+ * set as contract owner.
373
+ * @param _startingProjectId The initial next project ID.
374
+ * @param _autoApproveArtistSplitProposals Whether or not to always
375
+ * auto-approve proposed artist split updates.
376
+ * @dev _startingProjectId should be set to a value much, much less than
377
+ * max(uint248), but an explicit input type of `uint248` is used as it is
378
+ * safer to cast up to `uint256` than it is to cast down for the purposes
379
+ * of setting `_nextProjectId`.
380
+ */
381
+ constructor(
382
+ string memory _tokenName,
383
+ string memory _tokenSymbol,
384
+ address _renderProviderAddress,
385
+ address _platformProviderAddress,
386
+ address _randomizerContract,
387
+ address _adminACLContract,
388
+ uint248 _startingProjectId,
389
+ bool _autoApproveArtistSplitProposals,
390
+ address _engineRegistryContract
391
+ ) ERC721_PackedHashSeed(_tokenName, _tokenSymbol) {
392
+ _onlyNonZeroAddress(_renderProviderAddress);
393
+ _onlyNonZeroAddress(_platformProviderAddress);
394
+ _onlyNonZeroAddress(_randomizerContract);
395
+ _onlyNonZeroAddress(_adminACLContract);
396
+ // setup immutable `autoApproveArtistSplitProposals` config
397
+ autoApproveArtistSplitProposals = _autoApproveArtistSplitProposals;
398
+ // record contracts starting project ID
399
+ // casting-up is safe
400
+ startingProjectId = uint256(_startingProjectId);
401
+ _updateProviderSalesAddresses(
402
+ _renderProviderAddress,
403
+ _renderProviderAddress,
404
+ _platformProviderAddress,
405
+ _platformProviderAddress
406
+ );
407
+ _updateRandomizerAddress(_randomizerContract);
408
+ // set AdminACL management contract as owner
409
+ _transferOwnership(_adminACLContract);
410
+ // initialize default base URI
411
+ _updateDefaultBaseURI(
412
+ string.concat(
413
+ "https://token.artblocks.io/",
414
+ toHexString(address(this)),
415
+ "/"
416
+ )
417
+ );
418
+ // initialize next project ID
419
+ _nextProjectId = _startingProjectId;
420
+ emit PlatformUpdated(FIELD_NEXT_PROJECT_ID);
421
+ // register contract as an Engine contract
422
+ IEngineRegistryV0(_engineRegistryContract).registerContract(
423
+ address(this),
424
+ CORE_VERSION,
425
+ CORE_TYPE
426
+ );
427
+ }
428
+
429
+ /**
430
+ * @notice Updates preferredIPFSGateway to `_gateway`.
431
+ */
432
+ function updateIPFSGateway(string calldata _gateway) public {
433
+ _onlyAdminACL(this.updateIPFSGateway.selector);
434
+ preferredIPFSGateway = _gateway;
435
+ emit GatewayUpdated(ExternalAssetDependencyType.IPFS, _gateway);
436
+ }
437
+
438
+ /**
439
+ * @notice Updates preferredArweaveGateway to `_gateway`.
440
+ */
441
+ function updateArweaveGateway(string calldata _gateway) public {
442
+ _onlyAdminACL(this.updateArweaveGateway.selector);
443
+ preferredArweaveGateway = _gateway;
444
+ emit GatewayUpdated(ExternalAssetDependencyType.ARWEAVE, _gateway);
445
+ }
446
+
447
+ /**
448
+ * @notice Locks external asset dependencies for project `_projectId`.
449
+ */
450
+ function lockProjectExternalAssetDependencies(uint256 _projectId) external {
451
+ _onlyUnlockedProjectExternalAssetDependencies(_projectId);
452
+ _onlyArtistOrAdminACL(
453
+ _projectId,
454
+ this.lockProjectExternalAssetDependencies.selector
455
+ );
456
+ projects[_projectId].externalAssetDependenciesLocked = true;
457
+ emit ProjectExternalAssetDependenciesLocked(_projectId);
458
+ }
459
+
460
+ /**
461
+ * @notice Updates external asset dependency for project `_projectId`.
462
+ * @param _projectId Project to be updated.
463
+ * @param _index Asset index.
464
+ * @param _cidOrData Asset cid (Content identifier) or data string to be translated into bytecode.
465
+ * @param _dependencyType Asset dependency type.
466
+ * 0 - IPFS
467
+ * 1 - ARWEAVE
468
+ * 2 - ONCHAIN
469
+ */
470
+ function updateProjectExternalAssetDependency(
471
+ uint256 _projectId,
472
+ uint256 _index,
473
+ string memory _cidOrData,
474
+ ExternalAssetDependencyType _dependencyType
475
+ ) external {
476
+ _onlyUnlockedProjectExternalAssetDependencies(_projectId);
477
+ _onlyArtistOrAdminACL(
478
+ _projectId,
479
+ this.updateProjectExternalAssetDependency.selector
480
+ );
481
+ uint24 assetCount = projects[_projectId].externalAssetDependencyCount;
482
+ require(_index < assetCount, "Asset index out of range");
483
+ ExternalAssetDependency storage _oldDependency = projects[_projectId]
484
+ .externalAssetDependencies[_index];
485
+ ExternalAssetDependencyType _oldDependencyType = _oldDependency
486
+ .dependencyType;
487
+ projects[_projectId]
488
+ .externalAssetDependencies[_index]
489
+ .dependencyType = _dependencyType;
490
+ // if the incoming dependency type is onchain, we need to write the data to bytecode
491
+ if (_dependencyType == ExternalAssetDependencyType.ONCHAIN) {
492
+ if (_oldDependencyType != ExternalAssetDependencyType.ONCHAIN) {
493
+ // we only need to set the cid to an empty string if we are replacing an offchain asset
494
+ // an onchain asset will already have an empty cid
495
+ projects[_projectId].externalAssetDependencies[_index].cid = "";
496
+ }
497
+
498
+ projects[_projectId]
499
+ .externalAssetDependencies[_index]
500
+ .bytecodeAddress = _cidOrData.writeToBytecode();
501
+ // we don't want to emit data, so we emit the cid as an empty string
502
+ _cidOrData = "";
503
+ } else {
504
+ projects[_projectId]
505
+ .externalAssetDependencies[_index]
506
+ .cid = _cidOrData;
507
+ }
508
+ emit ExternalAssetDependencyUpdated(
509
+ _projectId,
510
+ _index,
511
+ _cidOrData,
512
+ _dependencyType,
513
+ assetCount
514
+ );
515
+ }
516
+
517
+ /**
518
+ * @notice Removes external asset dependency for project `_projectId` at index `_index`.
519
+ * Removal is done by swapping the element to be removed with the last element in the array, then deleting this last element.
520
+ * Assets with indices higher than `_index` can have their indices adjusted as a result of this operation.
521
+ * @param _projectId Project to be updated.
522
+ * @param _index Asset index
523
+ */
524
+ function removeProjectExternalAssetDependency(
525
+ uint256 _projectId,
526
+ uint256 _index
527
+ ) external {
528
+ _onlyUnlockedProjectExternalAssetDependencies(_projectId);
529
+ _onlyArtistOrAdminACL(
530
+ _projectId,
531
+ this.removeProjectExternalAssetDependency.selector
532
+ );
533
+ uint24 assetCount = projects[_projectId].externalAssetDependencyCount;
534
+ require(_index < assetCount, "Asset index out of range");
535
+
536
+ uint24 lastElementIndex = assetCount - 1;
537
+
538
+ // copy last element to index of element to be removed
539
+ projects[_projectId].externalAssetDependencies[_index] = projects[
540
+ _projectId
541
+ ].externalAssetDependencies[lastElementIndex];
542
+
543
+ delete projects[_projectId].externalAssetDependencies[lastElementIndex];
544
+
545
+ projects[_projectId].externalAssetDependencyCount = lastElementIndex;
546
+
547
+ emit ExternalAssetDependencyRemoved(_projectId, _index);
548
+ }
549
+
550
+ /**
551
+ * @notice Adds external asset dependency for project `_projectId`.
552
+ * @param _projectId Project to be updated.
553
+ * @param _cidOrData Asset cid (Content identifier) or data string to be translated into bytecode.
554
+ * @param _dependencyType Asset dependency type.
555
+ * 0 - IPFS
556
+ * 1 - ARWEAVE
557
+ * 2 - ONCHAIN
558
+ */
559
+ function addProjectExternalAssetDependency(
560
+ uint256 _projectId,
561
+ string memory _cidOrData,
562
+ ExternalAssetDependencyType _dependencyType
563
+ ) external {
564
+ _onlyUnlockedProjectExternalAssetDependencies(_projectId);
565
+ _onlyArtistOrAdminACL(
566
+ _projectId,
567
+ this.addProjectExternalAssetDependency.selector
568
+ );
569
+ uint24 assetCount = projects[_projectId].externalAssetDependencyCount;
570
+ address _bytecodeAddress = address(0);
571
+ // if the incoming dependency type is onchain, we need to write the data to bytecode
572
+ if (_dependencyType == ExternalAssetDependencyType.ONCHAIN) {
573
+ _bytecodeAddress = _cidOrData.writeToBytecode();
574
+ // we don't want to emit data, so we emit the cid as an empty string
575
+ _cidOrData = "";
576
+ }
577
+ ExternalAssetDependency memory asset = ExternalAssetDependency({
578
+ cid: _cidOrData,
579
+ dependencyType: _dependencyType,
580
+ bytecodeAddress: _bytecodeAddress
581
+ });
582
+ projects[_projectId].externalAssetDependencies[assetCount] = asset;
583
+ projects[_projectId].externalAssetDependencyCount = assetCount + 1;
584
+
585
+ emit ExternalAssetDependencyUpdated(
586
+ _projectId,
587
+ assetCount,
588
+ _cidOrData,
589
+ _dependencyType,
590
+ assetCount + 1
591
+ );
592
+ }
593
+
594
+ /**
595
+ * @notice Mints a token from project `_projectId` and sets the
596
+ * token's owner to `_to`. Hash may or may not be assigned to the token
597
+ * during the mint transaction, depending on the randomizer contract.
598
+ * @param _to Address to be the minted token's owner.
599
+ * @param _projectId Project ID to mint a token on.
600
+ * @param _by Purchaser of minted token.
601
+ * @return _tokenId The ID of the minted token.
602
+ * @dev sender must be the allowed minterContract
603
+ * @dev name of function is optimized for gas usage
604
+ */
605
+ function mint_Ecf(
606
+ address _to,
607
+ uint256 _projectId,
608
+ address _by
609
+ ) external returns (uint256 _tokenId) {
610
+ // CHECKS
611
+ require(msg.sender == minterContract, "Must mint from minter contract");
612
+ Project storage project = projects[_projectId];
613
+ // load invocations into memory
614
+ uint24 invocationsBefore = project.invocations;
615
+ uint24 invocationsAfter;
616
+ unchecked {
617
+ // invocationsBefore guaranteed <= maxInvocations <= 1_000_000,
618
+ // 1_000_000 << max uint24, so no possible overflow
619
+ invocationsAfter = invocationsBefore + 1;
620
+ }
621
+ uint24 maxInvocations = project.maxInvocations;
622
+
623
+ require(
624
+ invocationsBefore < maxInvocations,
625
+ "Must not exceed max invocations"
626
+ );
627
+ require(
628
+ project.active ||
629
+ _by == projectIdToFinancials[_projectId].artistAddress,
630
+ "Project must exist and be active"
631
+ );
632
+ require(
633
+ !project.paused ||
634
+ _by == projectIdToFinancials[_projectId].artistAddress,
635
+ "Purchases are paused."
636
+ );
637
+
638
+ // EFFECTS
639
+ // increment project's invocations
640
+ project.invocations = invocationsAfter;
641
+ uint256 thisTokenId;
642
+ unchecked {
643
+ // invocationsBefore is uint24 << max uint256. In production use,
644
+ // _projectId * ONE_MILLION must be << max uint256, otherwise
645
+ // tokenIdToProjectId function become invalid.
646
+ // Therefore, no risk of overflow
647
+ thisTokenId = (_projectId * ONE_MILLION) + invocationsBefore;
648
+ }
649
+
650
+ // mark project as completed if hit max invocations
651
+ if (invocationsAfter == maxInvocations) {
652
+ _completeProject(_projectId);
653
+ }
654
+
655
+ // INTERACTIONS
656
+ _mint(_to, thisTokenId);
657
+
658
+ // token hash is updated by the randomizer contract on V3
659
+ randomizerContract.assignTokenHash(thisTokenId);
660
+
661
+ // Do not need to also log `projectId` in event, as the `projectId` for
662
+ // a given token can be derived from the `tokenId` with:
663
+ // projectId = tokenId / 1_000_000
664
+ emit Mint(_to, thisTokenId);
665
+
666
+ return thisTokenId;
667
+ }
668
+
669
+ /**
670
+ * @notice Sets the hash seed for a given token ID `_tokenId`.
671
+ * May only be called by the current randomizer contract.
672
+ * May only be called for tokens that have not already been assigned a
673
+ * non-zero hash.
674
+ * @param _tokenId Token ID to set the hash for.
675
+ * @param _hashSeed Hash seed to set for the token ID. Only last 12 bytes
676
+ * will be used.
677
+ * @dev gas-optimized function name because called during mint sequence
678
+ * @dev if a separate event is required when the token hash is set, e.g.
679
+ * for indexing purposes, it must be emitted by the randomizer. This is to
680
+ * minimize gas when minting.
681
+ */
682
+ function setTokenHash_8PT(uint256 _tokenId, bytes32 _hashSeed) external {
683
+ _onlyValidTokenId(_tokenId);
684
+
685
+ OwnerAndHashSeed storage ownerAndHashSeed = _ownersAndHashSeeds[
686
+ _tokenId
687
+ ];
688
+ require(
689
+ msg.sender == address(randomizerContract),
690
+ "Only randomizer may set"
691
+ );
692
+ require(
693
+ ownerAndHashSeed.hashSeed == bytes12(0),
694
+ "Token hash already set"
695
+ );
696
+ require(_hashSeed != bytes12(0), "No zero hash seed");
697
+ ownerAndHashSeed.hashSeed = bytes12(_hashSeed);
698
+ }
699
+
700
+ /**
701
+ * @notice Allows owner (AdminACL) to revoke ownership of the contract.
702
+ * Note that the contract is intended to continue to function after the
703
+ * owner renounces ownership, but no new projects will be able to be added.
704
+ * Renouncing ownership will leave the contract without an owner,
705
+ * thereby removing any functionality that is only available to the
706
+ * owner/AdminACL contract. The same is true for any dependent contracts
707
+ * that also integrate with the owner/AdminACL contract (e.g. potentially
708
+ * minter suite contracts, registry contracts, etc.).
709
+ * After renouncing ownership, artists will be in control of updates to
710
+ * their payment addresses and splits (see modifier
711
+ * onlyAdminACLOrRenouncedArtist`).
712
+ * While there is no currently intended reason to call this method based on
713
+ * typical Engine partner business practices, this method exists to allow
714
+ * artists to continue to maintain the limited set of contract
715
+ * functionality that exists post-project-lock in an environment in which
716
+ * there is no longer an admin maintaining this smart contract.
717
+ * @dev This function is intended to be called directly by the AdminACL,
718
+ * not by an address allowed by the AdminACL contract.
719
+ */
720
+ function renounceOwnership() public override onlyOwner {
721
+ // broadcast that new projects are no longer allowed (if not already)
722
+ _forbidNewProjects();
723
+ // renounce ownership viw Ownable
724
+ Ownable.renounceOwnership();
725
+ }
726
+
727
+ /**
728
+ * @notice Updates reference to Art Blocks Dependency Registry contract.
729
+ * @param _artblocksDependencyRegistryAddress Address of new Dependency
730
+ * Registry.
731
+ */
732
+ function updateArtblocksDependencyRegistryAddress(
733
+ address _artblocksDependencyRegistryAddress
734
+ ) external {
735
+ _onlyAdminACL(this.updateArtblocksDependencyRegistryAddress.selector);
736
+ _onlyNonZeroAddress(_artblocksDependencyRegistryAddress);
737
+ artblocksDependencyRegistryAddress = _artblocksDependencyRegistryAddress;
738
+ emit PlatformUpdated(FIELD_ARTBLOCKS_DEPENDENCY_REGISTRY_ADDRESS);
739
+ }
740
+
741
+ /**
742
+ * @notice Updates sales addresses for the platform and render providers to
743
+ * the input parameters.
744
+ * @param _renderProviderPrimarySalesAddress Address of new primary sales
745
+ * payment address.
746
+ * @param _renderProviderSecondarySalesAddress Address of new secondary sales
747
+ * payment address.
748
+ * @param _platformProviderPrimarySalesAddress Address of new primary sales
749
+ * payment address.
750
+ * @param _platformProviderSecondarySalesAddress Address of new secondary sales
751
+ * payment address.
752
+ */
753
+ function updateProviderSalesAddresses(
754
+ address payable _renderProviderPrimarySalesAddress,
755
+ address payable _renderProviderSecondarySalesAddress,
756
+ address payable _platformProviderPrimarySalesAddress,
757
+ address payable _platformProviderSecondarySalesAddress
758
+ ) external {
759
+ _onlyAdminACL(this.updateProviderSalesAddresses.selector);
760
+ _onlyNonZeroAddress(_renderProviderPrimarySalesAddress);
761
+ _onlyNonZeroAddress(_renderProviderSecondarySalesAddress);
762
+ _onlyNonZeroAddress(_platformProviderPrimarySalesAddress);
763
+ _onlyNonZeroAddress(_platformProviderSecondarySalesAddress);
764
+ _updateProviderSalesAddresses(
765
+ _renderProviderPrimarySalesAddress,
766
+ _renderProviderSecondarySalesAddress,
767
+ _platformProviderPrimarySalesAddress,
768
+ _platformProviderSecondarySalesAddress
769
+ );
770
+ }
771
+
772
+ /**
773
+ * @notice Updates the render and platform provider primary sales revenue percentage to
774
+ * the provided inputs.
775
+ * @param renderProviderPrimarySalesPercentage_ New primary sales revenue % for the render provider
776
+ * @param platformProviderPrimarySalesPercentage_ New primary sales revenue % for the platform provider
777
+ * percentage.
778
+ */
779
+ function updateProviderPrimarySalesPercentages(
780
+ uint256 renderProviderPrimarySalesPercentage_,
781
+ uint256 platformProviderPrimarySalesPercentage_
782
+ ) external {
783
+ _onlyAdminACL(this.updateProviderPrimarySalesPercentages.selector);
784
+
785
+ // Validate that the sum of the proposed %s, does not exceed 100%.
786
+ require(
787
+ (renderProviderPrimarySalesPercentage_ +
788
+ platformProviderPrimarySalesPercentage_) <= ONE_HUNDRED,
789
+ "Max sum of ONE_HUNDRED %"
790
+ );
791
+ // Casting to `uint8` here is safe due check above, which does not allow
792
+ // overflow as of solidity version ^0.8.0.
793
+ _renderProviderPrimarySalesPercentage = uint8(
794
+ renderProviderPrimarySalesPercentage_
795
+ );
796
+ _platformProviderPrimarySalesPercentage = uint8(
797
+ platformProviderPrimarySalesPercentage_
798
+ );
799
+ emit PlatformUpdated(FIELD_PROVIDER_PRIMARY_SALES_PERCENTAGES);
800
+ }
801
+
802
+ /**
803
+ * @notice Updates render and platform provider secondary sales royalty Basis Points to
804
+ * the provided inputs.
805
+ * @param _renderProviderSecondarySalesBPS New secondary sales royalty Basis
806
+ * points.
807
+ * @param _platformProviderSecondarySalesBPS New secondary sales royalty Basis
808
+ * points.
809
+ * @dev Due to secondary royalties being ultimately enforced via social
810
+ * consensus, no hard upper limit is imposed on the BPS value, other than
811
+ * <= 100% royalty, which would not make mathematical sense. Realistically,
812
+ * changing this value is expected to either never occur, or be a rare
813
+ * occurrence.
814
+ */
815
+ function updateProviderSecondarySalesBPS(
816
+ uint256 _renderProviderSecondarySalesBPS,
817
+ uint256 _platformProviderSecondarySalesBPS
818
+ ) external {
819
+ _onlyAdminACL(this.updateProviderSecondarySalesBPS.selector);
820
+ // Validate that the sum of the proposed provider BPS, does not exceed 10_000 BPS.
821
+ require(
822
+ (_renderProviderSecondarySalesBPS +
823
+ _platformProviderSecondarySalesBPS) <=
824
+ MAX_PROVIDER_SECONDARY_SALES_BPS,
825
+ "Over max sum of BPS"
826
+ );
827
+ renderProviderSecondarySalesBPS = _renderProviderSecondarySalesBPS;
828
+ platformProviderSecondarySalesBPS = _platformProviderSecondarySalesBPS;
829
+ emit PlatformUpdated(FIELD_PROVIDER_SECONDARY_SALES_BPS);
830
+ }
831
+
832
+ /**
833
+ * @notice Updates minter to `_address`.
834
+ * @param _address Address of new minter.
835
+ */
836
+ function updateMinterContract(address _address) external {
837
+ _onlyAdminACL(this.updateMinterContract.selector);
838
+ _onlyNonZeroAddress(_address);
839
+ minterContract = _address;
840
+ emit MinterUpdated(_address);
841
+ }
842
+
843
+ /**
844
+ * @notice Updates randomizer to `_randomizerAddress`.
845
+ * @param _randomizerAddress Address of new randomizer.
846
+ */
847
+ function updateRandomizerAddress(address _randomizerAddress) external {
848
+ _onlyAdminACL(this.updateRandomizerAddress.selector);
849
+ _onlyNonZeroAddress(_randomizerAddress);
850
+ _updateRandomizerAddress(_randomizerAddress);
851
+ }
852
+
853
+ /**
854
+ * @notice Toggles project `_projectId` as active/inactive.
855
+ * @param _projectId Project ID to be toggled.
856
+ */
857
+ function toggleProjectIsActive(uint256 _projectId) external {
858
+ _onlyAdminACL(this.toggleProjectIsActive.selector);
859
+ _onlyValidProjectId(_projectId);
860
+ projects[_projectId].active = !projects[_projectId].active;
861
+ emit ProjectUpdated(_projectId, FIELD_PROJECT_ACTIVE);
862
+ }
863
+
864
+ /**
865
+ * @notice Artist proposes updated set of artist address, additional payee
866
+ * addresses, and percentage splits for project `_projectId`. Addresses and
867
+ * percentages do not have to all be changed, but they must all be defined
868
+ * as a complete set.
869
+ * Note that if the artist is only proposing a change to the payee percentage
870
+ * splits, without modifying the payee addresses, the proposal will be
871
+ * automatically approved and the new splits will become active immediately.
872
+ * Automatic approval will also be granted if the artist is only removing
873
+ * additional payee addresses, without adding any new ones.
874
+ * Also note that if `autoApproveArtistSplitProposals` is true, proposals
875
+ * will always be auto-approved, regardless of what is being changed.
876
+ * Also note that if the artist is proposing sending funds to the zero
877
+ * address, this function will revert and the proposal will not be created.
878
+ * @param _projectId Project ID.
879
+ * @param _artistAddress Artist address that controls the project, and may
880
+ * receive payments.
881
+ * @param _additionalPayeePrimarySales Address that may receive a
882
+ * percentage split of the artist's primary sales revenue.
883
+ * @param _additionalPayeePrimarySalesPercentage Percent of artist's
884
+ * portion of primary sale revenue that will be split to address
885
+ * `_additionalPayeePrimarySales`.
886
+ * @param _additionalPayeeSecondarySales Address that may receive a percentage
887
+ * split of the secondary sales royalties.
888
+ * @param _additionalPayeeSecondarySalesPercentage Percent of artist's portion
889
+ * of secondary sale royalties that will be split to address
890
+ * `_additionalPayeeSecondarySales`.
891
+ * @dev `_artistAddress` must be a valid address (non-zero-address), but it
892
+ * is intentionally allowable for `_additionalPayee{Primary,Secondaary}Sales`
893
+ * and their associated percentages to be zero'd out by the controlling artist.
894
+ */
895
+ function proposeArtistPaymentAddressesAndSplits(
896
+ uint256 _projectId,
897
+ address payable _artistAddress,
898
+ address payable _additionalPayeePrimarySales,
899
+ uint256 _additionalPayeePrimarySalesPercentage,
900
+ address payable _additionalPayeeSecondarySales,
901
+ uint256 _additionalPayeeSecondarySalesPercentage
902
+ ) external {
903
+ _onlyValidProjectId(_projectId);
904
+ _onlyArtist(_projectId);
905
+ _onlyNonZeroAddress(_artistAddress);
906
+ ProjectFinance storage projectFinance = projectIdToFinancials[
907
+ _projectId
908
+ ];
909
+ // checks
910
+ require(
911
+ _additionalPayeePrimarySalesPercentage <= ONE_HUNDRED &&
912
+ _additionalPayeeSecondarySalesPercentage <= ONE_HUNDRED,
913
+ "Max of 100%"
914
+ );
915
+ require(
916
+ _additionalPayeePrimarySalesPercentage == 0 ||
917
+ _additionalPayeePrimarySales != address(0),
918
+ "Primary payee is zero address"
919
+ );
920
+ require(
921
+ _additionalPayeeSecondarySalesPercentage == 0 ||
922
+ _additionalPayeeSecondarySales != address(0),
923
+ "Secondary payee is zero address"
924
+ );
925
+ // effects
926
+ // emit event for off-chain indexing
927
+ // note: always emit a proposal event, even in the pathway of
928
+ // automatic approval, to simplify indexing expectations
929
+ emit ProposedArtistAddressesAndSplits(
930
+ _projectId,
931
+ _artistAddress,
932
+ _additionalPayeePrimarySales,
933
+ _additionalPayeePrimarySalesPercentage,
934
+ _additionalPayeeSecondarySales,
935
+ _additionalPayeeSecondarySalesPercentage
936
+ );
937
+ // automatically accept if no proposed addresses modifications, or if
938
+ // the proposal only removes payee addresses, or if contract is set to
939
+ // always auto-approve.
940
+ // store proposal hash on-chain, only if not automatic accept
941
+ bool automaticAccept = autoApproveArtistSplitProposals;
942
+ if (!automaticAccept) {
943
+ // block scope to avoid stack too deep error
944
+ bool artistUnchanged = _artistAddress ==
945
+ projectFinance.artistAddress;
946
+ bool additionalPrimaryUnchangedOrRemoved = (_additionalPayeePrimarySales ==
947
+ projectFinance.additionalPayeePrimarySales) ||
948
+ (_additionalPayeePrimarySales == address(0));
949
+ bool additionalSecondaryUnchangedOrRemoved = (_additionalPayeeSecondarySales ==
950
+ projectFinance.additionalPayeeSecondarySales) ||
951
+ (_additionalPayeeSecondarySales == address(0));
952
+ automaticAccept =
953
+ artistUnchanged &&
954
+ additionalPrimaryUnchangedOrRemoved &&
955
+ additionalSecondaryUnchangedOrRemoved;
956
+ }
957
+ if (automaticAccept) {
958
+ // clear any previously proposed values
959
+ proposedArtistAddressesAndSplitsHash[_projectId] = bytes32(0);
960
+ // update storage
961
+ // artist address can change during automatic accept if
962
+ // autoApproveArtistSplitProposals is true
963
+ projectFinance.artistAddress = _artistAddress;
964
+ projectFinance
965
+ .additionalPayeePrimarySales = _additionalPayeePrimarySales;
966
+ // safe to cast as uint8 as max is 100%, max uint8 is 255
967
+ projectFinance.additionalPayeePrimarySalesPercentage = uint8(
968
+ _additionalPayeePrimarySalesPercentage
969
+ );
970
+ projectFinance
971
+ .additionalPayeeSecondarySales = _additionalPayeeSecondarySales;
972
+ // safe to cast as uint8 as max is 100%, max uint8 is 255
973
+ projectFinance.additionalPayeeSecondarySalesPercentage = uint8(
974
+ _additionalPayeeSecondarySalesPercentage
975
+ );
976
+ // emit event for off-chain indexing
977
+ emit AcceptedArtistAddressesAndSplits(_projectId);
978
+ } else {
979
+ proposedArtistAddressesAndSplitsHash[_projectId] = keccak256(
980
+ abi.encode(
981
+ _artistAddress,
982
+ _additionalPayeePrimarySales,
983
+ _additionalPayeePrimarySalesPercentage,
984
+ _additionalPayeeSecondarySales,
985
+ _additionalPayeeSecondarySalesPercentage
986
+ )
987
+ );
988
+ }
989
+ }
990
+
991
+ /**
992
+ * @notice Admin accepts a proposed set of updated artist address,
993
+ * additional payee addresses, and percentage splits for project
994
+ * `_projectId`. Addresses and percentages do not have to all be changed,
995
+ * but they must all be defined as a complete set.
996
+ * @param _projectId Project ID.
997
+ * @param _artistAddress Artist address that controls the project, and may
998
+ * receive payments.
999
+ * @param _additionalPayeePrimarySales Address that may receive a
1000
+ * percentage split of the artist's primary sales revenue.
1001
+ * @param _additionalPayeePrimarySalesPercentage Percent of artist's
1002
+ * portion of primary sale revenue that will be split to address
1003
+ * `_additionalPayeePrimarySales`.
1004
+ * @param _additionalPayeeSecondarySales Address that may receive a percentage
1005
+ * split of the secondary sales royalties.
1006
+ * @param _additionalPayeeSecondarySalesPercentage Percent of artist's portion
1007
+ * of secondary sale royalties that will be split to address
1008
+ * `_additionalPayeeSecondarySales`.
1009
+ * @dev this must be called by the Admin ACL contract, and must only accept
1010
+ * the most recent proposed values for a given project (validated on-chain
1011
+ * by comparing the hash of the proposed and accepted values).
1012
+ * @dev `_artistAddress` must be a valid address (non-zero-address), but it
1013
+ * is intentionally allowable for `_additionalPayee{Primary,Secondaary}Sales`
1014
+ * and their associated percentages to be zero'd out by the controlling artist.
1015
+ */
1016
+ function adminAcceptArtistAddressesAndSplits(
1017
+ uint256 _projectId,
1018
+ address payable _artistAddress,
1019
+ address payable _additionalPayeePrimarySales,
1020
+ uint256 _additionalPayeePrimarySalesPercentage,
1021
+ address payable _additionalPayeeSecondarySales,
1022
+ uint256 _additionalPayeeSecondarySalesPercentage
1023
+ ) external {
1024
+ _onlyValidProjectId(_projectId);
1025
+ _onlyAdminACLOrRenouncedArtist(
1026
+ _projectId,
1027
+ this.adminAcceptArtistAddressesAndSplits.selector
1028
+ );
1029
+ _onlyNonZeroAddress(_artistAddress);
1030
+ // checks
1031
+ require(
1032
+ proposedArtistAddressesAndSplitsHash[_projectId] ==
1033
+ keccak256(
1034
+ abi.encode(
1035
+ _artistAddress,
1036
+ _additionalPayeePrimarySales,
1037
+ _additionalPayeePrimarySalesPercentage,
1038
+ _additionalPayeeSecondarySales,
1039
+ _additionalPayeeSecondarySalesPercentage
1040
+ )
1041
+ ),
1042
+ "Must match artist proposal"
1043
+ );
1044
+ // effects
1045
+ ProjectFinance storage projectFinance = projectIdToFinancials[
1046
+ _projectId
1047
+ ];
1048
+ projectFinance.artistAddress = _artistAddress;
1049
+ projectFinance
1050
+ .additionalPayeePrimarySales = _additionalPayeePrimarySales;
1051
+ projectFinance.additionalPayeePrimarySalesPercentage = uint8(
1052
+ _additionalPayeePrimarySalesPercentage
1053
+ );
1054
+ projectFinance
1055
+ .additionalPayeeSecondarySales = _additionalPayeeSecondarySales;
1056
+ projectFinance.additionalPayeeSecondarySalesPercentage = uint8(
1057
+ _additionalPayeeSecondarySalesPercentage
1058
+ );
1059
+ // clear proposed values
1060
+ proposedArtistAddressesAndSplitsHash[_projectId] = bytes32(0);
1061
+ // emit event for off-chain indexing
1062
+ emit AcceptedArtistAddressesAndSplits(_projectId);
1063
+ }
1064
+
1065
+ /**
1066
+ * @notice Updates artist of project `_projectId` to `_artistAddress`.
1067
+ * This is to only be used in the event that the artist address is
1068
+ * compromised or sanctioned.
1069
+ * @param _projectId Project ID.
1070
+ * @param _artistAddress New artist address.
1071
+ */
1072
+ function updateProjectArtistAddress(
1073
+ uint256 _projectId,
1074
+ address payable _artistAddress
1075
+ ) external {
1076
+ _onlyValidProjectId(_projectId);
1077
+ _onlyAdminACLOrRenouncedArtist(
1078
+ _projectId,
1079
+ this.updateProjectArtistAddress.selector
1080
+ );
1081
+ _onlyNonZeroAddress(_artistAddress);
1082
+ projectIdToFinancials[_projectId].artistAddress = _artistAddress;
1083
+ emit ProjectUpdated(_projectId, FIELD_PROJECT_ARTIST_ADDRESS);
1084
+ }
1085
+
1086
+ /**
1087
+ * @notice Toggles paused state of project `_projectId`.
1088
+ * @param _projectId Project ID to be toggled.
1089
+ */
1090
+ function toggleProjectIsPaused(uint256 _projectId) external {
1091
+ _onlyArtist(_projectId);
1092
+ projects[_projectId].paused = !projects[_projectId].paused;
1093
+ emit ProjectUpdated(_projectId, FIELD_PROJECT_PAUSED);
1094
+ }
1095
+
1096
+ /**
1097
+ * @notice Adds new project `_projectName` by `_artistAddress`.
1098
+ * @param _projectName Project name.
1099
+ * @param _artistAddress Artist's address.
1100
+ * @dev token price now stored on minter
1101
+ */
1102
+ function addProject(
1103
+ string memory _projectName,
1104
+ address payable _artistAddress
1105
+ ) external {
1106
+ _onlyAdminACL(this.addProject.selector);
1107
+ _onlyNonEmptyString(_projectName);
1108
+ _onlyNonZeroAddress(_artistAddress);
1109
+ require(!newProjectsForbidden, "New projects forbidden");
1110
+ uint256 projectId = _nextProjectId;
1111
+ projectIdToFinancials[projectId].artistAddress = _artistAddress;
1112
+ projects[projectId].name = _projectName;
1113
+ projects[projectId].paused = true;
1114
+ projects[projectId].maxInvocations = ONE_MILLION_UINT24;
1115
+ projects[projectId].projectBaseURI = defaultBaseURI;
1116
+
1117
+ _nextProjectId = uint248(projectId) + 1;
1118
+ emit ProjectUpdated(projectId, FIELD_PROJECT_CREATED);
1119
+ }
1120
+
1121
+ /**
1122
+ * @notice Forever forbids new projects from being added to this contract.
1123
+ */
1124
+ function forbidNewProjects() external {
1125
+ _onlyAdminACL(this.forbidNewProjects.selector);
1126
+ require(!newProjectsForbidden, "Already forbidden");
1127
+ _forbidNewProjects();
1128
+ }
1129
+
1130
+ /**
1131
+ * @notice Updates name of project `_projectId` to be `_projectName`.
1132
+ * @param _projectId Project ID.
1133
+ * @param _projectName New project name.
1134
+ */
1135
+ function updateProjectName(
1136
+ uint256 _projectId,
1137
+ string memory _projectName
1138
+ ) external {
1139
+ _onlyUnlocked(_projectId);
1140
+ _onlyArtistOrAdminACL(_projectId, this.updateProjectName.selector);
1141
+ _onlyNonEmptyString(_projectName);
1142
+ projects[_projectId].name = _projectName;
1143
+ emit ProjectUpdated(_projectId, FIELD_PROJECT_NAME);
1144
+ }
1145
+
1146
+ /**
1147
+ * @notice Updates artist name for project `_projectId` to be
1148
+ * `_projectArtistName`.
1149
+ * @param _projectId Project ID.
1150
+ * @param _projectArtistName New artist name.
1151
+ */
1152
+ function updateProjectArtistName(
1153
+ uint256 _projectId,
1154
+ string memory _projectArtistName
1155
+ ) external {
1156
+ _onlyUnlocked(_projectId);
1157
+ _onlyArtistOrAdminACL(
1158
+ _projectId,
1159
+ this.updateProjectArtistName.selector
1160
+ );
1161
+ _onlyNonEmptyString(_projectArtistName);
1162
+ projects[_projectId].artist = _projectArtistName;
1163
+ emit ProjectUpdated(_projectId, FIELD_PROJECT_ARTIST_NAME);
1164
+ }
1165
+
1166
+ /**
1167
+ * @notice Updates artist secondary market royalties for project
1168
+ * `_projectId` to be `_secondMarketRoyalty` percent.
1169
+ * This DOES NOT include the secondary market royalty percentages collected
1170
+ * by the issuing platform; it is only the total percentage of royalties
1171
+ * that will be split to artist and additionalSecondaryPayee.
1172
+ * @param _projectId Project ID.
1173
+ * @param _secondMarketRoyalty Percent of secondary sales revenue that will
1174
+ * be split to artist and additionalSecondaryPayee. This must be less than
1175
+ * or equal to ARTIST_MAX_SECONDARY_ROYALTY_PERCENTAGE percent.
1176
+ */
1177
+ function updateProjectSecondaryMarketRoyaltyPercentage(
1178
+ uint256 _projectId,
1179
+ uint256 _secondMarketRoyalty
1180
+ ) external {
1181
+ _onlyArtist(_projectId);
1182
+ require(
1183
+ _secondMarketRoyalty <= ARTIST_MAX_SECONDARY_ROYALTY_PERCENTAGE,
1184
+ "Over max percent"
1185
+ );
1186
+ projectIdToFinancials[_projectId]
1187
+ .secondaryMarketRoyaltyPercentage = uint8(_secondMarketRoyalty);
1188
+ emit ProjectUpdated(
1189
+ _projectId,
1190
+ FIELD_PROJECT_SECONDARY_MARKET_ROYALTY_PERCENTAGE
1191
+ );
1192
+ }
1193
+
1194
+ /**
1195
+ * @notice Updates description of project `_projectId`.
1196
+ * Only artist may call when unlocked, only admin may call when locked.
1197
+ * @param _projectId Project ID.
1198
+ * @param _projectDescription New project description.
1199
+ */
1200
+ function updateProjectDescription(
1201
+ uint256 _projectId,
1202
+ string memory _projectDescription
1203
+ ) external {
1204
+ // checks
1205
+ require(
1206
+ _projectUnlocked(_projectId)
1207
+ ? msg.sender == projectIdToFinancials[_projectId].artistAddress
1208
+ : adminACLAllowed(
1209
+ msg.sender,
1210
+ address(this),
1211
+ this.updateProjectDescription.selector
1212
+ ),
1213
+ "Only artist when unlocked, owner when locked"
1214
+ );
1215
+ // effects
1216
+ projects[_projectId].description = _projectDescription;
1217
+ emit ProjectUpdated(_projectId, FIELD_PROJECT_DESCRIPTION);
1218
+ }
1219
+
1220
+ /**
1221
+ * @notice Updates website of project `_projectId` to be `_projectWebsite`.
1222
+ * @param _projectId Project ID.
1223
+ * @param _projectWebsite New project website.
1224
+ * @dev It is intentionally allowed for this to be set to the empty string.
1225
+ */
1226
+ function updateProjectWebsite(
1227
+ uint256 _projectId,
1228
+ string memory _projectWebsite
1229
+ ) external {
1230
+ _onlyArtist(_projectId);
1231
+ projects[_projectId].website = _projectWebsite;
1232
+ emit ProjectUpdated(_projectId, FIELD_PROJECT_WEBSITE);
1233
+ }
1234
+
1235
+ /**
1236
+ * @notice Updates license for project `_projectId`.
1237
+ * @param _projectId Project ID.
1238
+ * @param _projectLicense New project license.
1239
+ */
1240
+ function updateProjectLicense(
1241
+ uint256 _projectId,
1242
+ string memory _projectLicense
1243
+ ) external {
1244
+ _onlyUnlocked(_projectId);
1245
+ _onlyArtistOrAdminACL(_projectId, this.updateProjectLicense.selector);
1246
+ _onlyNonEmptyString(_projectLicense);
1247
+ projects[_projectId].license = _projectLicense;
1248
+ emit ProjectUpdated(_projectId, FIELD_PROJECT_LICENSE);
1249
+ }
1250
+
1251
+ /**
1252
+ * @notice Updates maximum invocations for project `_projectId` to
1253
+ * `_maxInvocations`. Maximum invocations may only be decreased by the
1254
+ * artist, and must be greater than or equal to current invocations.
1255
+ * New projects are created with maximum invocations of 1 million by
1256
+ * default.
1257
+ * @param _projectId Project ID.
1258
+ * @param _maxInvocations New maximum invocations.
1259
+ */
1260
+ function updateProjectMaxInvocations(
1261
+ uint256 _projectId,
1262
+ uint24 _maxInvocations
1263
+ ) external {
1264
+ _onlyArtist(_projectId);
1265
+ // CHECKS
1266
+ Project storage project = projects[_projectId];
1267
+ uint256 _invocations = project.invocations;
1268
+ require(
1269
+ (_maxInvocations < project.maxInvocations),
1270
+ "Only maxInvocations decrease"
1271
+ );
1272
+ require(_maxInvocations >= _invocations, "Only gte invocations");
1273
+ // EFFECTS
1274
+ project.maxInvocations = _maxInvocations;
1275
+ emit ProjectUpdated(_projectId, FIELD_PROJECT_MAX_INVOCATIONS);
1276
+
1277
+ // register completed timestamp if action completed the project
1278
+ if (_maxInvocations == _invocations) {
1279
+ _completeProject(_projectId);
1280
+ }
1281
+ }
1282
+
1283
+ /**
1284
+ * @notice Adds a script to project `_projectId`.
1285
+ * @param _projectId Project to be updated.
1286
+ * @param _script Script to be added. Required to be a non-empty string,
1287
+ * but no further validation is performed.
1288
+ */
1289
+ function addProjectScript(
1290
+ uint256 _projectId,
1291
+ string memory _script
1292
+ ) external {
1293
+ _onlyUnlocked(_projectId);
1294
+ _onlyArtistOrAdminACL(_projectId, this.addProjectScript.selector);
1295
+ _onlyNonEmptyString(_script);
1296
+ Project storage project = projects[_projectId];
1297
+ // store script in contract bytecode
1298
+ project.scriptBytecodeAddresses[project.scriptCount] = _script
1299
+ .writeToBytecode();
1300
+ project.scriptCount = project.scriptCount + 1;
1301
+ emit ProjectUpdated(_projectId, FIELD_PROJECT_SCRIPT);
1302
+ }
1303
+
1304
+ /**
1305
+ * @notice Updates script for project `_projectId` at script ID `_scriptId`.
1306
+ * @param _projectId Project to be updated.
1307
+ * @param _scriptId Script ID to be updated.
1308
+ * @param _script The updated script value. Required to be a non-empty
1309
+ * string, but no further validation is performed.
1310
+ */
1311
+ function updateProjectScript(
1312
+ uint256 _projectId,
1313
+ uint256 _scriptId,
1314
+ string memory _script
1315
+ ) external {
1316
+ _onlyUnlocked(_projectId);
1317
+ _onlyArtistOrAdminACL(_projectId, this.updateProjectScript.selector);
1318
+ _onlyNonEmptyString(_script);
1319
+ Project storage project = projects[_projectId];
1320
+ require(_scriptId < project.scriptCount, "scriptId out of range");
1321
+
1322
+ // store script in contract bytecode, replacing reference address from
1323
+ // the contract that no longer exists with the newly created one
1324
+ project.scriptBytecodeAddresses[_scriptId] = _script.writeToBytecode();
1325
+ emit ProjectUpdated(_projectId, FIELD_PROJECT_SCRIPT);
1326
+ }
1327
+
1328
+ /**
1329
+ * @notice Removes last script from project `_projectId`.
1330
+ * @param _projectId Project to be updated.
1331
+ */
1332
+ function removeProjectLastScript(uint256 _projectId) external {
1333
+ _onlyUnlocked(_projectId);
1334
+ _onlyArtistOrAdminACL(
1335
+ _projectId,
1336
+ this.removeProjectLastScript.selector
1337
+ );
1338
+ Project storage project = projects[_projectId];
1339
+ require(project.scriptCount > 0, "No scripts to remove");
1340
+
1341
+ // delete reference to contract address that no longer exists
1342
+ delete project.scriptBytecodeAddresses[project.scriptCount - 1];
1343
+ unchecked {
1344
+ project.scriptCount = project.scriptCount - 1;
1345
+ }
1346
+ emit ProjectUpdated(_projectId, FIELD_PROJECT_SCRIPT);
1347
+ }
1348
+
1349
+ /**
1350
+ * @notice Updates script type for project `_projectId`.
1351
+ * @param _projectId Project to be updated.
1352
+ * @param _scriptTypeAndVersion Script type and version e.g. "p5js@1.0.0",
1353
+ * as bytes32 encoded string.
1354
+ */
1355
+ function updateProjectScriptType(
1356
+ uint256 _projectId,
1357
+ bytes32 _scriptTypeAndVersion
1358
+ ) external {
1359
+ _onlyUnlocked(_projectId);
1360
+ _onlyArtistOrAdminACL(
1361
+ _projectId,
1362
+ this.updateProjectScriptType.selector
1363
+ );
1364
+ Project storage project = projects[_projectId];
1365
+ // require exactly one @ symbol in _scriptTypeAndVersion
1366
+ require(
1367
+ _scriptTypeAndVersion.containsExactCharacterQty(
1368
+ AT_CHARACTER_CODE,
1369
+ uint8(1)
1370
+ ),
1371
+ "must contain exactly one @"
1372
+ );
1373
+ project.scriptTypeAndVersion = _scriptTypeAndVersion;
1374
+ emit ProjectUpdated(_projectId, FIELD_PROJECT_SCRIPT_TYPE);
1375
+ }
1376
+
1377
+ /**
1378
+ * @notice Updates project's aspect ratio.
1379
+ * @param _projectId Project to be updated.
1380
+ * @param _aspectRatio Aspect ratio to be set. Intended to be string in the
1381
+ * format of a decimal, e.g. "1" for square, "1.77777778" for 16:9, etc.,
1382
+ * allowing for a maximum of 10 digits and one (optional) decimal separator.
1383
+ */
1384
+ function updateProjectAspectRatio(
1385
+ uint256 _projectId,
1386
+ string memory _aspectRatio
1387
+ ) external {
1388
+ _onlyUnlocked(_projectId);
1389
+ _onlyArtistOrAdminACL(
1390
+ _projectId,
1391
+ this.updateProjectAspectRatio.selector
1392
+ );
1393
+ _onlyNonEmptyString(_aspectRatio);
1394
+ // Perform more detailed input validation for aspect ratio.
1395
+ bytes memory aspectRatioBytes = bytes(_aspectRatio);
1396
+ uint256 bytesLength = aspectRatioBytes.length;
1397
+ require(bytesLength <= 11, "Aspect ratio format too long");
1398
+ bool hasSeenDecimalSeparator = false;
1399
+ bool hasSeenNumber = false;
1400
+ for (uint256 i; i < bytesLength; i++) {
1401
+ bytes1 character = aspectRatioBytes[i];
1402
+ // Allow as many #s as desired.
1403
+ if (character >= 0x30 && character <= 0x39) {
1404
+ // 9-0
1405
+ // We need to ensure there is at least 1 `9-0` occurrence.
1406
+ hasSeenNumber = true;
1407
+ continue;
1408
+ }
1409
+ if (character == 0x2E) {
1410
+ // .
1411
+ // Allow no more than 1 `.` occurrence.
1412
+ if (!hasSeenDecimalSeparator) {
1413
+ hasSeenDecimalSeparator = true;
1414
+ continue;
1415
+ }
1416
+ }
1417
+ revert("Improperly formatted aspect ratio");
1418
+ }
1419
+ require(hasSeenNumber, "Aspect ratio has no numbers");
1420
+
1421
+ projects[_projectId].aspectRatio = _aspectRatio;
1422
+ emit ProjectUpdated(_projectId, FIELD_PROJECT_ASPECT_RATIO);
1423
+ }
1424
+
1425
+ /**
1426
+ * @notice Updates base URI for project `_projectId` to `_newBaseURI`.
1427
+ * This is the controlling base URI for all tokens in the project. The
1428
+ * contract-level defaultBaseURI is only used when initializing new
1429
+ * projects.
1430
+ * @param _projectId Project to be updated.
1431
+ * @param _newBaseURI New base URI.
1432
+ */
1433
+ function updateProjectBaseURI(
1434
+ uint256 _projectId,
1435
+ string memory _newBaseURI
1436
+ ) external {
1437
+ _onlyArtist(_projectId);
1438
+ _onlyNonEmptyString(_newBaseURI);
1439
+ projects[_projectId].projectBaseURI = _newBaseURI;
1440
+ emit ProjectUpdated(_projectId, FIELD_PROJECT_BASE_URI);
1441
+ }
1442
+
1443
+ /**
1444
+ * @notice Updates default base URI to `_defaultBaseURI`. The
1445
+ * contract-level defaultBaseURI is only used when initializing new
1446
+ * projects. Token URIs are determined by their project's `projectBaseURI`.
1447
+ * @param _defaultBaseURI New default base URI.
1448
+ */
1449
+ function updateDefaultBaseURI(string memory _defaultBaseURI) external {
1450
+ _onlyAdminACL(this.updateDefaultBaseURI.selector);
1451
+ _onlyNonEmptyString(_defaultBaseURI);
1452
+ _updateDefaultBaseURI(_defaultBaseURI);
1453
+ }
1454
+
1455
+ /**
1456
+ * @notice Next project ID to be created on this contract.
1457
+ * @return uint256 Next project ID.
1458
+ */
1459
+ function nextProjectId() external view returns (uint256) {
1460
+ return _nextProjectId;
1461
+ }
1462
+
1463
+ /**
1464
+ * @notice Returns token hash for token ID `_tokenId`. Returns null if hash
1465
+ * has not been set.
1466
+ * @param _tokenId Token ID to be queried.
1467
+ * @return bytes32 Token hash.
1468
+ * @dev token hash is the keccak256 hash of the stored hash seed
1469
+ */
1470
+ function tokenIdToHash(uint256 _tokenId) external view returns (bytes32) {
1471
+ bytes12 _hashSeed = _ownersAndHashSeeds[_tokenId].hashSeed;
1472
+ if (_hashSeed == 0) {
1473
+ return 0;
1474
+ }
1475
+ return keccak256(abi.encode(_hashSeed));
1476
+ }
1477
+
1478
+ /**
1479
+ * @notice Returns token hash **seed** for token ID `_tokenId`. Returns
1480
+ * null if hash seed has not been set. The hash seed id the bytes12 value
1481
+ * which is hashed to produce the token hash.
1482
+ * @param _tokenId Token ID to be queried.
1483
+ * @return bytes12 Token hash seed.
1484
+ * @dev token hash seed is keccak256 hashed to give the token hash
1485
+ */
1486
+ function tokenIdToHashSeed(
1487
+ uint256 _tokenId
1488
+ ) external view returns (bytes12) {
1489
+ return _ownersAndHashSeeds[_tokenId].hashSeed;
1490
+ }
1491
+
1492
+ /**
1493
+ * @notice View function returning the render provider portion of
1494
+ * primary sales, in percent.
1495
+ * @return uint256 The render provider portion of primary sales,
1496
+ * in percent.
1497
+ */
1498
+ function renderProviderPrimarySalesPercentage()
1499
+ external
1500
+ view
1501
+ returns (uint256)
1502
+ {
1503
+ return _renderProviderPrimarySalesPercentage;
1504
+ }
1505
+
1506
+ /**
1507
+ * @notice View function returning the platform provider portion of
1508
+ * primary sales, in percent.
1509
+ * @return uint256 The platform provider portion of primary sales,
1510
+ * in percent.
1511
+ */
1512
+ function platformProviderPrimarySalesPercentage()
1513
+ external
1514
+ view
1515
+ returns (uint256)
1516
+ {
1517
+ return _platformProviderPrimarySalesPercentage;
1518
+ }
1519
+
1520
+ /**
1521
+ * @notice View function returning Artist's address for project
1522
+ * `_projectId`.
1523
+ * @param _projectId Project ID to be queried.
1524
+ * @return address Artist's address.
1525
+ */
1526
+ function projectIdToArtistAddress(
1527
+ uint256 _projectId
1528
+ ) external view returns (address payable) {
1529
+ return projectIdToFinancials[_projectId].artistAddress;
1530
+ }
1531
+
1532
+ /**
1533
+ * @notice View function returning Artist's secondary market royalty
1534
+ * percentage for project `_projectId`.
1535
+ * This does not include render/platform providers portions of secondary
1536
+ * market royalties.
1537
+ * @param _projectId Project ID to be queried.
1538
+ * @return uint256 Artist's secondary market royalty percentage.
1539
+ */
1540
+ function projectIdToSecondaryMarketRoyaltyPercentage(
1541
+ uint256 _projectId
1542
+ ) external view returns (uint256) {
1543
+ return
1544
+ projectIdToFinancials[_projectId].secondaryMarketRoyaltyPercentage;
1545
+ }
1546
+
1547
+ /**
1548
+ * @notice View function returning Artist's additional payee address for
1549
+ * primary sales, for project `_projectId`.
1550
+ * @param _projectId Project ID to be queried.
1551
+ * @return address Artist's additional payee address for primary sales.
1552
+ */
1553
+ function projectIdToAdditionalPayeePrimarySales(
1554
+ uint256 _projectId
1555
+ ) external view returns (address payable) {
1556
+ return projectIdToFinancials[_projectId].additionalPayeePrimarySales;
1557
+ }
1558
+
1559
+ /**
1560
+ * @notice View function returning Artist's additional payee primary sales
1561
+ * percentage, for project `_projectId`.
1562
+ * @param _projectId Project ID to be queried.
1563
+ * @return uint256 Artist's additional payee primary sales percentage.
1564
+ */
1565
+ function projectIdToAdditionalPayeePrimarySalesPercentage(
1566
+ uint256 _projectId
1567
+ ) external view returns (uint256) {
1568
+ return
1569
+ projectIdToFinancials[_projectId]
1570
+ .additionalPayeePrimarySalesPercentage;
1571
+ }
1572
+
1573
+ /**
1574
+ * @notice View function returning Artist's additional payee address for
1575
+ * secondary sales, for project `_projectId`.
1576
+ * @param _projectId Project ID to be queried.
1577
+ * @return address payable Artist's additional payee address for secondary
1578
+ * sales.
1579
+ */
1580
+ function projectIdToAdditionalPayeeSecondarySales(
1581
+ uint256 _projectId
1582
+ ) external view returns (address payable) {
1583
+ return projectIdToFinancials[_projectId].additionalPayeeSecondarySales;
1584
+ }
1585
+
1586
+ /**
1587
+ * @notice View function returning Artist's additional payee secondary
1588
+ * sales percentage, for project `_projectId`.
1589
+ * @param _projectId Project ID to be queried.
1590
+ * @return uint256 Artist's additional payee secondary sales percentage.
1591
+ */
1592
+ function projectIdToAdditionalPayeeSecondarySalesPercentage(
1593
+ uint256 _projectId
1594
+ ) external view returns (uint256) {
1595
+ return
1596
+ projectIdToFinancials[_projectId]
1597
+ .additionalPayeeSecondarySalesPercentage;
1598
+ }
1599
+
1600
+ /**
1601
+ * @notice Returns project details for project `_projectId`.
1602
+ * @param _projectId Project to be queried.
1603
+ * @return projectName Name of project
1604
+ * @return artist Artist of project
1605
+ * @return description Project description
1606
+ * @return website Project website
1607
+ * @return license Project license
1608
+ * @dev this function was named projectDetails prior to V3 core contract.
1609
+ */
1610
+ function projectDetails(
1611
+ uint256 _projectId
1612
+ )
1613
+ external
1614
+ view
1615
+ returns (
1616
+ string memory projectName,
1617
+ string memory artist,
1618
+ string memory description,
1619
+ string memory website,
1620
+ string memory license
1621
+ )
1622
+ {
1623
+ Project storage project = projects[_projectId];
1624
+ projectName = project.name;
1625
+ artist = project.artist;
1626
+ description = project.description;
1627
+ website = project.website;
1628
+ license = project.license;
1629
+ }
1630
+
1631
+ /**
1632
+ * @notice Returns project state data for project `_projectId`.
1633
+ * @param _projectId Project to be queried
1634
+ * @return invocations Current number of invocations
1635
+ * @return maxInvocations Maximum allowed invocations
1636
+ * @return active Boolean representing if project is currently active
1637
+ * @return paused Boolean representing if project is paused
1638
+ * @return completedTimestamp zero if project not complete, otherwise
1639
+ * timestamp of project completion.
1640
+ * @return locked Boolean representing if project is locked
1641
+ * @dev price and currency info are located on minter contracts
1642
+ */
1643
+ function projectStateData(
1644
+ uint256 _projectId
1645
+ )
1646
+ external
1647
+ view
1648
+ returns (
1649
+ uint256 invocations,
1650
+ uint256 maxInvocations,
1651
+ bool active,
1652
+ bool paused,
1653
+ uint256 completedTimestamp,
1654
+ bool locked
1655
+ )
1656
+ {
1657
+ Project storage project = projects[_projectId];
1658
+ invocations = project.invocations;
1659
+ maxInvocations = project.maxInvocations;
1660
+ active = project.active;
1661
+ paused = project.paused;
1662
+ completedTimestamp = project.completedTimestamp;
1663
+ locked = !_projectUnlocked(_projectId);
1664
+ }
1665
+
1666
+ /**
1667
+ * @notice Returns artist payment information for project `_projectId`.
1668
+ * @param _projectId Project to be queried
1669
+ * @return artistAddress Project Artist's address
1670
+ * @return additionalPayeePrimarySales Additional payee address for primary
1671
+ * sales
1672
+ * @return additionalPayeePrimarySalesPercentage Percentage of artist revenue
1673
+ * to be sent to the additional payee address for primary sales
1674
+ * @return additionalPayeeSecondarySales Additional payee address for secondary
1675
+ * sales royalties
1676
+ * @return additionalPayeeSecondarySalesPercentage Percentage of artist revenue
1677
+ * to be sent to the additional payee address for secondary sales royalties
1678
+ * @return secondaryMarketRoyaltyPercentage Royalty percentage to be sent to
1679
+ * combination of artist and additional payee. This does not include the
1680
+ * platform's percentage of secondary sales royalties, which is defined as
1681
+ * the sum of `renderProviderSecondarySalesBPS`
1682
+ * and `platformProviderSecondarySalesBPS`.
1683
+ */
1684
+ function projectArtistPaymentInfo(
1685
+ uint256 _projectId
1686
+ )
1687
+ external
1688
+ view
1689
+ returns (
1690
+ address artistAddress,
1691
+ address additionalPayeePrimarySales,
1692
+ uint256 additionalPayeePrimarySalesPercentage,
1693
+ address additionalPayeeSecondarySales,
1694
+ uint256 additionalPayeeSecondarySalesPercentage,
1695
+ uint256 secondaryMarketRoyaltyPercentage
1696
+ )
1697
+ {
1698
+ ProjectFinance storage projectFinance = projectIdToFinancials[
1699
+ _projectId
1700
+ ];
1701
+ artistAddress = projectFinance.artistAddress;
1702
+ additionalPayeePrimarySales = projectFinance
1703
+ .additionalPayeePrimarySales;
1704
+ additionalPayeePrimarySalesPercentage = projectFinance
1705
+ .additionalPayeePrimarySalesPercentage;
1706
+ additionalPayeeSecondarySales = projectFinance
1707
+ .additionalPayeeSecondarySales;
1708
+ additionalPayeeSecondarySalesPercentage = projectFinance
1709
+ .additionalPayeeSecondarySalesPercentage;
1710
+ secondaryMarketRoyaltyPercentage = projectFinance
1711
+ .secondaryMarketRoyaltyPercentage;
1712
+ }
1713
+
1714
+ /**
1715
+ * @notice Returns script information for project `_projectId`.
1716
+ * @param _projectId Project to be queried.
1717
+ * @return scriptTypeAndVersion Project's script type and version
1718
+ * (e.g. "p5js(atSymbol)1.0.0")
1719
+ * @return aspectRatio Aspect ratio of project (e.g. "1" for square,
1720
+ * "1.77777778" for 16:9, etc.)
1721
+ * @return scriptCount Count of scripts for project
1722
+ */
1723
+ function projectScriptDetails(
1724
+ uint256 _projectId
1725
+ )
1726
+ external
1727
+ view
1728
+ override(IGenArt721CoreContractV3_Base, IDependencyRegistryCompatibleV0)
1729
+ returns (
1730
+ string memory scriptTypeAndVersion,
1731
+ string memory aspectRatio,
1732
+ uint256 scriptCount
1733
+ )
1734
+ {
1735
+ Project storage project = projects[_projectId];
1736
+ scriptTypeAndVersion = project.scriptTypeAndVersion.toString();
1737
+ aspectRatio = project.aspectRatio;
1738
+ scriptCount = project.scriptCount;
1739
+ }
1740
+
1741
+ /**
1742
+ * @notice Returns address with bytecode containing project script for
1743
+ * project `_projectId` at script index `_index`.
1744
+ */
1745
+ function projectScriptBytecodeAddressByIndex(
1746
+ uint256 _projectId,
1747
+ uint256 _index
1748
+ ) external view returns (address) {
1749
+ return projects[_projectId].scriptBytecodeAddresses[_index];
1750
+ }
1751
+
1752
+ /**
1753
+ * @notice Returns script for project `_projectId` at script index `_index`.
1754
+ * @param _projectId Project to be queried.
1755
+ * @param _index Index of script to be queried.
1756
+ */
1757
+ function projectScriptByIndex(
1758
+ uint256 _projectId,
1759
+ uint256 _index
1760
+ ) external view returns (string memory) {
1761
+ Project storage project = projects[_projectId];
1762
+ // If trying to access an out-of-index script, return the empty string.
1763
+ if (_index >= project.scriptCount) {
1764
+ return "";
1765
+ }
1766
+ return project.scriptBytecodeAddresses[_index].readFromBytecode();
1767
+ }
1768
+
1769
+ /**
1770
+ * @notice Returns base URI for project `_projectId`.
1771
+ * @param _projectId Project to be queried.
1772
+ * @return projectBaseURI Base URI for project
1773
+ */
1774
+ function projectURIInfo(
1775
+ uint256 _projectId
1776
+ ) external view returns (string memory projectBaseURI) {
1777
+ projectBaseURI = projects[_projectId].projectBaseURI;
1778
+ }
1779
+
1780
+ /**
1781
+ * @notice Backwards-compatible (pre-V3) function returning if `_minter` is
1782
+ * minterContract.
1783
+ * @param _minter Address to be queried.
1784
+ * @return bool Boolean representing if `_minter` is minterContract.
1785
+ */
1786
+ function isMintWhitelisted(address _minter) external view returns (bool) {
1787
+ return (minterContract == _minter);
1788
+ }
1789
+
1790
+ /**
1791
+ * @notice Gets qty of randomizers in history of all randomizers used by
1792
+ * this core contract. If a randomizer is switched away from then back to,
1793
+ * it will show up in the history twice.
1794
+ * @return randomizerHistoryCount Count of randomizers in history
1795
+ */
1796
+ function numHistoricalRandomizers() external view returns (uint256) {
1797
+ return _historicalRandomizerAddresses.length;
1798
+ }
1799
+
1800
+ /**
1801
+ * @notice Gets address of randomizer at index `_index` in history of all
1802
+ * randomizers used by this core contract. Index is zero-based.
1803
+ * @param _index Historical index of randomizer to be queried.
1804
+ * @return randomizerAddress Address of randomizer at index `_index`.
1805
+ * @dev If a randomizer is switched away from and then switched back to, it
1806
+ * will show up in the history twice.
1807
+ */
1808
+ function getHistoricalRandomizerAt(
1809
+ uint256 _index
1810
+ ) external view returns (address) {
1811
+ require(
1812
+ _index < _historicalRandomizerAddresses.length,
1813
+ "Index out of bounds"
1814
+ );
1815
+ return _historicalRandomizerAddresses[_index];
1816
+ }
1817
+
1818
+ /**
1819
+ * @notice Gets royalty Basis Points (BPS) for token ID `_tokenId`.
1820
+ * This conforms to the IManifold interface designated in the Royalty
1821
+ * Registry's RoyaltyEngineV1.sol contract.
1822
+ * ref: https://github.com/manifoldxyz/royalty-registry-solidity
1823
+ * @param _tokenId Token ID to be queried.
1824
+ * @return recipients Array of royalty payment recipients
1825
+ * @return bps Array of Basis Points (BPS) allocated to each recipient,
1826
+ * aligned by index.
1827
+ * @dev reverts if invalid _tokenId
1828
+ * @dev only returns recipients that have a non-zero BPS allocation
1829
+ */
1830
+ function getRoyalties(
1831
+ uint256 _tokenId
1832
+ )
1833
+ external
1834
+ view
1835
+ returns (address payable[] memory recipients, uint256[] memory bps)
1836
+ {
1837
+ _onlyValidTokenId(_tokenId);
1838
+ // initialize arrays with maximum potential length
1839
+ recipients = new address payable[](4);
1840
+ bps = new uint256[](4);
1841
+
1842
+ uint256 projectId = tokenIdToProjectId(_tokenId);
1843
+ ProjectFinance storage projectFinance = projectIdToFinancials[
1844
+ projectId
1845
+ ];
1846
+ // load values into memory
1847
+ uint256 royaltyPercentageForArtistAndAdditional = projectFinance
1848
+ .secondaryMarketRoyaltyPercentage;
1849
+ uint256 additionalPayeePercentage = projectFinance
1850
+ .additionalPayeeSecondarySalesPercentage;
1851
+ // calculate BPS = percentage * 100
1852
+ uint256 artistBPS = (ONE_HUNDRED - additionalPayeePercentage) *
1853
+ royaltyPercentageForArtistAndAdditional;
1854
+
1855
+ uint256 additionalBPS = additionalPayeePercentage *
1856
+ royaltyPercentageForArtistAndAdditional;
1857
+ uint256 renderProviderBPS = renderProviderSecondarySalesBPS;
1858
+ uint256 platformProviderBPS = platformProviderSecondarySalesBPS;
1859
+ // populate arrays
1860
+ uint256 payeeCount;
1861
+ if (artistBPS > 0) {
1862
+ recipients[payeeCount] = projectFinance.artistAddress;
1863
+ bps[payeeCount++] = artistBPS;
1864
+ }
1865
+ if (additionalBPS > 0) {
1866
+ recipients[payeeCount] = projectFinance
1867
+ .additionalPayeeSecondarySales;
1868
+ bps[payeeCount++] = additionalBPS;
1869
+ }
1870
+ if (renderProviderBPS > 0) {
1871
+ recipients[payeeCount] = renderProviderSecondarySalesAddress;
1872
+ bps[payeeCount++] = renderProviderBPS;
1873
+ }
1874
+ if (platformProviderBPS > 0) {
1875
+ recipients[payeeCount] = platformProviderSecondarySalesAddress;
1876
+ bps[payeeCount++] = platformProviderBPS;
1877
+ }
1878
+ // trim arrays if necessary
1879
+ if (4 > payeeCount) {
1880
+ assembly {
1881
+ let decrease := sub(4, payeeCount)
1882
+ mstore(recipients, sub(mload(recipients), decrease))
1883
+ mstore(bps, sub(mload(bps), decrease))
1884
+ }
1885
+ }
1886
+ return (recipients, bps);
1887
+ }
1888
+
1889
+ /**
1890
+ * @notice View function that returns appropriate revenue splits between
1891
+ * different render provider, platform provider, Artist, and Artist's
1892
+ * additional primary sales payee given a sale price of `_price` on
1893
+ * project `_projectId`.
1894
+ * This always returns four revenue amounts and four addresses, but if a
1895
+ * revenue is zero for either Artist or additional payee, the corresponding
1896
+ * address returned will also be null (for gas optimization).
1897
+ * Does not account for refund if user overpays for a token (minter should
1898
+ * handle a refund of the difference, if appropriate).
1899
+ * Some minters may have alternative methods of splitting payments, in
1900
+ * which case they should implement their own payment splitting logic.
1901
+ * @param _projectId Project ID to be queried.
1902
+ * @param _price Sale price of token.
1903
+ * @return renderProviderRevenue_ amount of revenue to be sent to the
1904
+ * render provider
1905
+ * @return renderProviderAddress_ address to send render provider revenue to
1906
+ * @return platformProviderRevenue_ amount of revenue to be sent to the
1907
+ * platform provider
1908
+ * @return platformProviderAddress_ address to send platform provider revenue to
1909
+ * @return artistRevenue_ amount of revenue to be sent to Artist
1910
+ * @return artistAddress_ address to send Artist revenue to. Will be null
1911
+ * if no revenue is due to artist (gas optimization).
1912
+ * @return additionalPayeePrimaryRevenue_ amount of revenue to be sent to
1913
+ * additional payee for primary sales
1914
+ * @return additionalPayeePrimaryAddress_ address to send Artist's
1915
+ * additional payee for primary sales revenue to. Will be null if no
1916
+ * revenue is due to additional payee for primary sales (gas optimization).
1917
+ * @dev this always returns four addresses and four revenues, but if the
1918
+ * revenue is zero, the corresponding address will be address(0). It is up
1919
+ * to the contract performing the revenue split to handle this
1920
+ * appropriately.
1921
+ */
1922
+ function getPrimaryRevenueSplits(
1923
+ uint256 _projectId,
1924
+ uint256 _price
1925
+ )
1926
+ external
1927
+ view
1928
+ returns (
1929
+ uint256 renderProviderRevenue_,
1930
+ address payable renderProviderAddress_,
1931
+ uint256 platformProviderRevenue_,
1932
+ address payable platformProviderAddress_,
1933
+ uint256 artistRevenue_,
1934
+ address payable artistAddress_,
1935
+ uint256 additionalPayeePrimaryRevenue_,
1936
+ address payable additionalPayeePrimaryAddress_
1937
+ )
1938
+ {
1939
+ ProjectFinance storage projectFinance = projectIdToFinancials[
1940
+ _projectId
1941
+ ];
1942
+ // calculate revenues – this is a three-way split between the
1943
+ // render provider, the platform provider, and the artist, and
1944
+ // is safe to perform this given that in the case of loss of
1945
+ // precision Solidity will round down.
1946
+ uint256 projectFunds = _price;
1947
+ renderProviderRevenue_ =
1948
+ (_price * uint256(_renderProviderPrimarySalesPercentage)) /
1949
+ ONE_HUNDRED;
1950
+ // renderProviderRevenue_ percentage is always <=100, so guaranteed to never underflow
1951
+ projectFunds -= renderProviderRevenue_;
1952
+ platformProviderRevenue_ =
1953
+ (_price * uint256(_platformProviderPrimarySalesPercentage)) /
1954
+ ONE_HUNDRED;
1955
+ // platformProviderRevenue_ percentage is always <=100, so guaranteed to never underflow
1956
+ projectFunds -= platformProviderRevenue_;
1957
+ additionalPayeePrimaryRevenue_ =
1958
+ (projectFunds *
1959
+ projectFinance.additionalPayeePrimarySalesPercentage) /
1960
+ ONE_HUNDRED;
1961
+ // projectIdToAdditionalPayeePrimarySalesPercentage is always
1962
+ // <=100, so guaranteed to never underflow
1963
+ artistRevenue_ = projectFunds - additionalPayeePrimaryRevenue_;
1964
+ // set addresses from storage
1965
+ renderProviderAddress_ = renderProviderPrimarySalesAddress;
1966
+ platformProviderAddress_ = platformProviderPrimarySalesAddress;
1967
+ if (artistRevenue_ > 0) {
1968
+ artistAddress_ = projectFinance.artistAddress;
1969
+ }
1970
+ if (additionalPayeePrimaryRevenue_ > 0) {
1971
+ additionalPayeePrimaryAddress_ = projectFinance
1972
+ .additionalPayeePrimarySales;
1973
+ }
1974
+ }
1975
+
1976
+ /**
1977
+ * @notice Returns external asset dependency for project `_projectId` at index `_index`.
1978
+ * If the dependencyType is ONCHAIN, the `data` field will contain the extrated bytecode data and `cid`
1979
+ * will be an empty string. Conversly, for any other dependencyType, the `data` field will be an empty string
1980
+ * and the `bytecodeAddress` will point to the zero address.
1981
+ */
1982
+ function projectExternalAssetDependencyByIndex(
1983
+ uint256 _projectId,
1984
+ uint256 _index
1985
+ ) external view returns (ExternalAssetDependencyWithData memory) {
1986
+ ExternalAssetDependency storage _dependency = projects[_projectId]
1987
+ .externalAssetDependencies[_index];
1988
+ address _bytecodeAddress = _dependency.bytecodeAddress;
1989
+
1990
+ return
1991
+ ExternalAssetDependencyWithData({
1992
+ dependencyType: _dependency.dependencyType,
1993
+ cid: _dependency.cid,
1994
+ bytecodeAddress: _bytecodeAddress,
1995
+ data: (_dependency.dependencyType ==
1996
+ ExternalAssetDependencyType.ONCHAIN)
1997
+ ? _bytecodeAddress.readFromBytecode()
1998
+ : ""
1999
+ });
2000
+ }
2001
+
2002
+ /**
2003
+ * @notice Returns external asset dependency count for project `_projectId` at index `_index`.
2004
+ */
2005
+ function projectExternalAssetDependencyCount(
2006
+ uint256 _projectId
2007
+ ) external view returns (uint256) {
2008
+ return uint256(projects[_projectId].externalAssetDependencyCount);
2009
+ }
2010
+
2011
+ /**
2012
+ * @notice Backwards-compatible (pre-V3) getter returning contract admin
2013
+ * @return address Address of contract admin (same as owner)
2014
+ */
2015
+ function admin() external view returns (address) {
2016
+ return owner();
2017
+ }
2018
+
2019
+ /**
2020
+ * @notice Gets the project ID for a given `_tokenId`.
2021
+ * @param _tokenId Token ID to be queried.
2022
+ * @return _projectId Project ID for given `_tokenId`.
2023
+ */
2024
+ function tokenIdToProjectId(
2025
+ uint256 _tokenId
2026
+ ) public pure returns (uint256 _projectId) {
2027
+ return _tokenId / ONE_MILLION;
2028
+ }
2029
+
2030
+ /**
2031
+ * @notice Convenience function that returns whether `_sender` is allowed
2032
+ * to call function with selector `_selector` on contract `_contract`, as
2033
+ * determined by this contract's current Admin ACL contract. Expected use
2034
+ * cases include minter contracts checking if caller is allowed to call
2035
+ * admin-gated functions on minter contracts.
2036
+ * @param _sender Address of the sender calling function with selector
2037
+ * `_selector` on contract `_contract`.
2038
+ * @param _contract Address of the contract being called by `_sender`.
2039
+ * @param _selector Function selector of the function being called by
2040
+ * `_sender`.
2041
+ * @return bool Whether `_sender` is allowed to call function with selector
2042
+ * `_selector` on contract `_contract`.
2043
+ * @dev assumes the Admin ACL contract is the owner of this contract, which
2044
+ * is expected to always be true.
2045
+ * @dev adminACLContract is expected to either be null address (if owner
2046
+ * has renounced ownership), or conform to IAdminACLV0 interface. Check for
2047
+ * null address first to avoid revert when admin has renounced ownership.
2048
+ */
2049
+ function adminACLAllowed(
2050
+ address _sender,
2051
+ address _contract,
2052
+ bytes4 _selector
2053
+ ) public returns (bool) {
2054
+ return
2055
+ owner() != address(0) &&
2056
+ adminACLContract.allowed(_sender, _contract, _selector);
2057
+ }
2058
+
2059
+ /**
2060
+ * @notice Returns contract owner. Set to deployer's address by default on
2061
+ * contract deployment.
2062
+ * @return address Address of contract owner.
2063
+ * @dev ref: https://docs.openzeppelin.com/contracts/4.x/api/access#Ownable
2064
+ * @dev owner role was called `admin` prior to V3 core contract
2065
+ */
2066
+ function owner()
2067
+ public
2068
+ view
2069
+ override(Ownable, IGenArt721CoreContractV3_Base)
2070
+ returns (address)
2071
+ {
2072
+ return Ownable.owner();
2073
+ }
2074
+
2075
+ /**
2076
+ * @notice Gets token URI for token ID `_tokenId`.
2077
+ * @param _tokenId Token ID to be queried.
2078
+ * @return string URI of token ID `_tokenId`.
2079
+ * @dev token URIs are the concatenation of the project base URI and the
2080
+ * token ID.
2081
+ */
2082
+ function tokenURI(
2083
+ uint256 _tokenId
2084
+ ) public view override returns (string memory) {
2085
+ _onlyValidTokenId(_tokenId);
2086
+ string memory _projectBaseURI = projects[tokenIdToProjectId(_tokenId)]
2087
+ .projectBaseURI;
2088
+ return string.concat(_projectBaseURI, toString(_tokenId));
2089
+ }
2090
+
2091
+ /**
2092
+ * @dev See {IERC165-supportsInterface}.
2093
+ */
2094
+ function supportsInterface(
2095
+ bytes4 interfaceId
2096
+ ) public view virtual override returns (bool) {
2097
+ return
2098
+ interfaceId == type(IManifold).interfaceId ||
2099
+ super.supportsInterface(interfaceId);
2100
+ }
2101
+
2102
+ /**
2103
+ * @notice Forbids new projects from being created
2104
+ * @dev only performs operation and emits event if contract is not already
2105
+ * forbidding new projects.
2106
+ */
2107
+ function _forbidNewProjects() internal {
2108
+ if (!newProjectsForbidden) {
2109
+ newProjectsForbidden = true;
2110
+ emit PlatformUpdated(FIELD_NEW_PROJECTS_FORBIDDEN);
2111
+ }
2112
+ }
2113
+
2114
+ /**
2115
+ * @notice Transfers ownership of the contract to a new account (`newOwner`).
2116
+ * Internal function without access restriction.
2117
+ * @param newOwner New owner.
2118
+ * @dev owner role was called `admin` prior to V3 core contract.
2119
+ * @dev Overrides and wraps OpenZeppelin's _transferOwnership function to
2120
+ * also update adminACLContract for improved introspection.
2121
+ */
2122
+ function _transferOwnership(address newOwner) internal override {
2123
+ Ownable._transferOwnership(newOwner);
2124
+ adminACLContract = IAdminACLV0(newOwner);
2125
+ }
2126
+
2127
+ /**
2128
+ * @notice Updates sales addresses for the platform and render providers to
2129
+ * the input parameters.
2130
+ * @param _renderProviderPrimarySalesAddress Address of new primary sales
2131
+ * payment address.
2132
+ * @param _renderProviderSecondarySalesAddress Address of new secondary sales
2133
+ * payment address.
2134
+ * @param _platformProviderPrimarySalesAddress Address of new primary sales
2135
+ * payment address.
2136
+ * @param _platformProviderSecondarySalesAddress Address of new secondary sales
2137
+ * payment address.
2138
+ * @dev Note that this method does not check that the input address is
2139
+ * not `address(0)`, as it is expected that callers of this method should
2140
+ * perform input validation where applicable.
2141
+ */
2142
+ function _updateProviderSalesAddresses(
2143
+ address _renderProviderPrimarySalesAddress,
2144
+ address _renderProviderSecondarySalesAddress,
2145
+ address _platformProviderPrimarySalesAddress,
2146
+ address _platformProviderSecondarySalesAddress
2147
+ ) internal {
2148
+ platformProviderPrimarySalesAddress = payable(
2149
+ _platformProviderPrimarySalesAddress
2150
+ );
2151
+ platformProviderSecondarySalesAddress = payable(
2152
+ _platformProviderSecondarySalesAddress
2153
+ );
2154
+ renderProviderPrimarySalesAddress = payable(
2155
+ _renderProviderPrimarySalesAddress
2156
+ );
2157
+ renderProviderSecondarySalesAddress = payable(
2158
+ _renderProviderSecondarySalesAddress
2159
+ );
2160
+ emit PlatformUpdated(FIELD_PROVIDER_SALES_ADDRESSES);
2161
+ }
2162
+
2163
+ /**
2164
+ * @notice Updates randomizer address to `_randomizerAddress`.
2165
+ * @param _randomizerAddress New randomizer address.
2166
+ * @dev Note that this method does not check that the input address is
2167
+ * not `address(0)`, as it is expected that callers of this method should
2168
+ * perform input validation where applicable.
2169
+ */
2170
+ function _updateRandomizerAddress(address _randomizerAddress) internal {
2171
+ randomizerContract = IRandomizerV2(_randomizerAddress);
2172
+ // populate historical randomizer array
2173
+ _historicalRandomizerAddresses.push(_randomizerAddress);
2174
+ emit PlatformUpdated(FIELD_RANDOMIZER_ADDRESS);
2175
+ }
2176
+
2177
+ /**
2178
+ * @notice Updates default base URI to `_defaultBaseURI`.
2179
+ * When new projects are added, their `projectBaseURI` is automatically
2180
+ * initialized to `_defaultBaseURI`.
2181
+ * @param _defaultBaseURI New default base URI.
2182
+ * @dev Note that this method does not check that the input string is not
2183
+ * the empty string, as it is expected that callers of this method should
2184
+ * perform input validation where applicable.
2185
+ */
2186
+ function _updateDefaultBaseURI(string memory _defaultBaseURI) internal {
2187
+ defaultBaseURI = _defaultBaseURI;
2188
+ emit PlatformUpdated(FIELD_DEFAULT_BASE_URI);
2189
+ }
2190
+
2191
+ /**
2192
+ * @notice Internal function to complete a project.
2193
+ * @param _projectId Project ID to be completed.
2194
+ */
2195
+ function _completeProject(uint256 _projectId) internal {
2196
+ projects[_projectId].completedTimestamp = uint64(block.timestamp);
2197
+ emit ProjectUpdated(_projectId, FIELD_PROJECT_COMPLETED);
2198
+ }
2199
+
2200
+ /**
2201
+ * @notice Internal function that returns whether a project is unlocked.
2202
+ * Projects automatically lock four weeks after they are completed.
2203
+ * Projects are considered completed when they have been invoked the
2204
+ * maximum number of times.
2205
+ * @param _projectId Project ID to be queried.
2206
+ * @return bool true if project is unlocked, false otherwise.
2207
+ * @dev This also enforces that the `_projectId` passed in is valid.
2208
+ */
2209
+ function _projectUnlocked(uint256 _projectId) internal view returns (bool) {
2210
+ _onlyValidProjectId(_projectId);
2211
+ uint256 projectCompletedTimestamp = projects[_projectId]
2212
+ .completedTimestamp;
2213
+ bool projectOpen = projectCompletedTimestamp == 0;
2214
+ return
2215
+ projectOpen ||
2216
+ (block.timestamp - projectCompletedTimestamp <
2217
+ FOUR_WEEKS_IN_SECONDS);
2218
+ }
2219
+
2220
+ // strings library from OpenZeppelin, modified for no constants
2221
+
2222
+ bytes16 private _HEX_SYMBOLS = "0123456789abcdef";
2223
+ uint8 private _ADDRESS_LENGTH = 20;
2224
+
2225
+ /**
2226
+ * @dev Converts a `uint256` to its ASCII `string` decimal representation.
2227
+ */
2228
+ function toString(uint256 value) internal pure returns (string memory) {
2229
+ // Inspired by OraclizeAPI's implementation - MIT licence
2230
+ // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
2231
+
2232
+ if (value == 0) {
2233
+ return "0";
2234
+ }
2235
+ uint256 temp = value;
2236
+ uint256 digits;
2237
+ while (temp != 0) {
2238
+ digits++;
2239
+ temp /= 10;
2240
+ }
2241
+ bytes memory buffer = new bytes(digits);
2242
+ while (value != 0) {
2243
+ digits -= 1;
2244
+ buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
2245
+ value /= 10;
2246
+ }
2247
+ return string(buffer);
2248
+ }
2249
+
2250
+ /**
2251
+ * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
2252
+ */
2253
+ function toHexString(
2254
+ uint256 value,
2255
+ uint256 length
2256
+ ) internal view returns (string memory) {
2257
+ bytes memory buffer = new bytes(2 * length + 2);
2258
+ buffer[0] = "0";
2259
+ buffer[1] = "x";
2260
+ for (uint256 i = 2 * length + 1; i > 1; --i) {
2261
+ buffer[i] = _HEX_SYMBOLS[value & 0xf];
2262
+ value >>= 4;
2263
+ }
2264
+ require(value == 0, "hex length insufficient");
2265
+ return string(buffer);
2266
+ }
2267
+
2268
+ /**
2269
+ * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
2270
+ */
2271
+ function toHexString(address addr) internal view returns (string memory) {
2272
+ return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
2273
+ }
2274
+ }