@artblocks/contracts 1.0.0 → 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 (106) hide show
  1. package/.env.example +8 -1
  2. package/README.md +44 -165
  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/MinterDAExpV0.sol/MinterDAExpV0.json +2 -2
  9. package/artifacts/contracts/archive/minter-suite/Minters/MinterDAExp/MinterDAExpV1.sol/MinterDAExpV1.json +2 -2
  10. package/artifacts/contracts/archive/minter-suite/Minters/MinterDAExp/MinterDAExpV2.sol/MinterDAExpV2.json +2 -2
  11. package/artifacts/contracts/archive/minter-suite/Minters/MinterDAExp/MinterDAExpV3.sol/MinterDAExpV3.json +2 -2
  12. package/artifacts/contracts/archive/minter-suite/Minters/MinterDAExpSettlement/MinterDAExpSettlementV0.sol/MinterDAExpSettlementV0.json +2 -2
  13. package/artifacts/contracts/{minter-suite/Minters → archive/minter-suite/Minters/MinterDAExpSettlement}/MinterDAExpSettlementV1.sol/MinterDAExpSettlementV1.json +3 -3
  14. package/artifacts/contracts/archive/minter-suite/Minters/MinterDALin/MinterDALinV0.sol/MinterDALinV0.json +2 -2
  15. package/artifacts/contracts/archive/minter-suite/Minters/MinterDALin/MinterDALinV1.sol/MinterDALinV1.json +2 -2
  16. package/artifacts/contracts/archive/minter-suite/Minters/MinterDALin/MinterDALinV2.sol/MinterDALinV2.json +2 -2
  17. package/artifacts/contracts/archive/minter-suite/Minters/MinterDALin/MinterDALinV3.sol/MinterDALinV3.json +2 -2
  18. package/artifacts/contracts/archive/minter-suite/Minters/MinterHolder/MinterHolderV0.sol/MinterHolderV0.json +2 -2
  19. package/artifacts/contracts/archive/minter-suite/Minters/MinterHolder/MinterHolderV1.sol/MinterHolderV1.json +2 -2
  20. package/artifacts/contracts/archive/minter-suite/Minters/MinterHolder/MinterHolderV2.sol/MinterHolderV2.json +2 -2
  21. package/artifacts/contracts/archive/minter-suite/Minters/MinterHolder/MinterHolderV3.sol/MinterHolderV3.json +2 -2
  22. package/artifacts/contracts/archive/minter-suite/Minters/MinterMerkle/MinterMerkleV0.sol/MinterMerkleV0.json +2 -2
  23. package/artifacts/contracts/archive/minter-suite/Minters/MinterMerkle/MinterMerkleV1.sol/MinterMerkleV1.json +2 -2
  24. package/artifacts/contracts/archive/minter-suite/Minters/MinterMerkle/MinterMerkleV2.sol/MinterMerkleV2.json +2 -2
  25. package/artifacts/contracts/archive/minter-suite/Minters/MinterMerkle/MinterMerkleV3.sol/MinterMerkleV3.json +2 -2
  26. package/artifacts/contracts/archive/minter-suite/Minters/MinterMerkle/MinterMerkleV4.sol/MinterMerkleV4.json +2 -2
  27. package/artifacts/contracts/archive/minter-suite/Minters/MinterSetPrice/MinterSetPriceV0.sol/MinterSetPriceV0.json +2 -2
  28. package/artifacts/contracts/archive/minter-suite/Minters/MinterSetPrice/MinterSetPriceV1.sol/MinterSetPriceV1.json +2 -2
  29. package/artifacts/contracts/archive/minter-suite/Minters/MinterSetPrice/MinterSetPriceV2.sol/MinterSetPriceV2.json +2 -2
  30. package/artifacts/contracts/archive/minter-suite/Minters/MinterSetPrice/MinterSetPriceV3.sol/MinterSetPriceV3.json +2 -2
  31. package/artifacts/contracts/archive/minter-suite/Minters/MinterSetPriceERC20/MinterSetPriceERC20V0.sol/MinterSetPriceERC20V0.json +2 -2
  32. package/artifacts/contracts/archive/minter-suite/Minters/MinterSetPriceERC20/MinterSetPriceERC20V1.sol/MinterSetPriceERC20V1.json +2 -2
  33. package/artifacts/contracts/archive/minter-suite/Minters/MinterSetPriceERC20/MinterSetPriceERC20V2.sol/MinterSetPriceERC20V2.json +2 -2
  34. package/artifacts/contracts/archive/minter-suite/Minters/MinterSetPriceERC20/MinterSetPriceERC20V3.sol/MinterSetPriceERC20V3.json +2 -2
  35. package/artifacts/contracts/explorations/GenArt721CoreV3_Explorations.sol/GenArt721CoreV3_Explorations.json +2 -2
  36. package/artifacts/contracts/interfaces/0.8.x/IFilteredMinterDAExpSettlementV1.sol/IFilteredMinterDAExpSettlementV1.json +767 -0
  37. package/artifacts/contracts/interfaces/0.8.x/IFilteredMinterSEAV0.sol/IFilteredMinterSEAV0.json +1032 -0
  38. package/artifacts/contracts/interfaces/0.8.x/IGenArt721CoreContractV3.sol/IGenArt721CoreContractV3.json +149 -0
  39. package/artifacts/contracts/interfaces/0.8.x/IGenArt721CoreContractV3_Base.sol/IGenArt721CoreContractV3_Base.json +149 -0
  40. package/artifacts/contracts/interfaces/0.8.x/IGenArt721CoreContractV3_Engine.sol/IGenArt721CoreContractV3_Engine.json +130 -0
  41. package/artifacts/contracts/interfaces/0.8.x/IGenArt721CoreContractV3_Engine_Flex.sol/IGenArt721CoreContractV3_Engine_Flex.json +1066 -0
  42. package/artifacts/contracts/interfaces/0.8.x/IMinterFilterV0.sol/IMinterFilterV0.json +6 -0
  43. package/artifacts/contracts/interfaces/0.8.x/IRandomizerPolyptychV0.sol/IRandomizerPolyptychV0.json +87 -0
  44. package/artifacts/contracts/interfaces/0.8.x/IRandomizerV2.sol/IRandomizerV2.json +1 -1
  45. package/artifacts/contracts/interfaces/0.8.x/IWETH.sol/IWETH.json +55 -0
  46. package/artifacts/contracts/libs/integration-refs/weth9/weth9.sol/WETH9_.json +295 -0
  47. package/artifacts/contracts/minter-suite/MinterFilter/MinterFilterV0.sol/MinterFilterV0.json +8 -2
  48. package/artifacts/contracts/minter-suite/MinterFilter/MinterFilterV1.sol/MinterFilterV1.json +34 -2
  49. package/artifacts/contracts/minter-suite/Minters/MinterDAExpSettlementV2.sol/MinterDAExpSettlementV2.json +1127 -0
  50. package/artifacts/contracts/minter-suite/Minters/MinterDAExpV4.sol/MinterDAExpV4.json +15 -2
  51. package/artifacts/contracts/minter-suite/Minters/MinterDALinV4.sol/MinterDALinV4.json +15 -2
  52. package/artifacts/contracts/minter-suite/Minters/MinterHolderV4.sol/MinterHolderV4.json +15 -2
  53. package/artifacts/contracts/minter-suite/Minters/MinterMerkleV5.sol/MinterMerkleV5.json +15 -2
  54. package/artifacts/contracts/minter-suite/Minters/MinterPolyptychV0.sol/IGenArt721CoreContractV3WithRandomizer.json +792 -0
  55. package/artifacts/contracts/minter-suite/Minters/MinterPolyptychV0.sol/MinterPolyptychV0.json +1268 -0
  56. package/artifacts/contracts/minter-suite/Minters/MinterSEAV0.sol/MinterSEAV0.json +1310 -0
  57. package/artifacts/contracts/minter-suite/Minters/MinterSetPriceERC20V4.sol/MinterSetPriceERC20V4.json +15 -2
  58. package/artifacts/contracts/minter-suite/Minters/MinterSetPriceV4.sol/MinterSetPriceV4.json +15 -2
  59. package/artifacts/contracts/mock/DeadReceiverBidderMock.sol/DeadReceiverBidderMock.json +33 -0
  60. package/artifacts/contracts/mock/GasLimitReceiverBidderMock.sol/GasLimitReceiverBidderMock.json +46 -0
  61. package/artifacts/contracts/mock/GasLimitReceiverMock.sol/GasLimitReceiverMock.json +28 -0
  62. package/artifacts/contracts/mock/GenArt721CoreV3_Engine_IncorrectCoreType.sol/GenArt721CoreV3_Engine_IncorrectCoreType.json +2 -2
  63. package/artifacts/contracts/mock/RandomizerV2_NoAssignMock.sol/RandomizerV2_NoAssignMock.json +3 -3
  64. package/artifacts/contracts/mock/ReentrancySEAMock.sol/ReentrancySEAAutoBidderMock.json +51 -0
  65. package/artifacts/contracts/{BasicRandomizer.sol → randomizer/BasicRandomizer.sol}/BasicRandomizer.json +3 -3
  66. package/artifacts/contracts/randomizer/BasicRandomizerBase_v0_0_0.sol/RandomizerBase.json +10 -0
  67. package/artifacts/contracts/randomizer/PolyptychRandomizerV0.sol/BasicPolyptychRandomizerV0.json +229 -0
  68. package/artifacts/contracts/randomizer/RandomizerV2.sol/BasicRandomizerV2.json +102 -0
  69. package/artifacts/contracts/royalty-registry/GenArt721RoyaltyOverride.sol/GenArt721RoyaltyOverride.json +2 -2
  70. package/contracts/DependencyRegistryV0.sol +74 -113
  71. package/contracts/GenArt721CoreV3.sol +124 -171
  72. package/contracts/GenArt721CoreV3_Engine.sol +136 -198
  73. package/contracts/GenArt721CoreV3_Engine_Flex.sol +2274 -0
  74. package/contracts/{minter-suite/Minters → archive/minter-suite/Minters/MinterDAExpSettlement}/MinterDAExpSettlementV1.sol +4 -4
  75. package/contracts/explorations/GenArt721CoreV3_Explorations.sol +147 -176
  76. package/contracts/interfaces/0.8.x/IFilteredMinterDAExpSettlementV1.sol +21 -0
  77. package/contracts/interfaces/0.8.x/IFilteredMinterSEAV0.sol +145 -0
  78. package/contracts/interfaces/0.8.x/IGenArt721CoreContractV3_Base.sol +39 -0
  79. package/contracts/interfaces/0.8.x/IGenArt721CoreContractV3_Engine.sol +0 -3
  80. package/contracts/interfaces/0.8.x/IGenArt721CoreContractV3_Engine_Flex.sol +132 -0
  81. package/contracts/interfaces/0.8.x/IMinterFilterV0.sol +6 -0
  82. package/contracts/interfaces/0.8.x/IRandomizerPolyptychV0.sol +31 -0
  83. package/contracts/interfaces/0.8.x/IRandomizerV2.sol +5 -2
  84. package/contracts/interfaces/0.8.x/IWETH.sol +11 -0
  85. package/contracts/libs/integration-refs/weth9/weth9.sol +763 -0
  86. package/contracts/minter-suite/MinterFilter/MinterFilterV1.sol +53 -47
  87. package/contracts/minter-suite/Minters/MinterDAExpSettlementV2.sol +1304 -0
  88. package/contracts/minter-suite/Minters/MinterDAExpV4.sol +47 -24
  89. package/contracts/minter-suite/Minters/MinterDALinV4.sol +46 -21
  90. package/contracts/minter-suite/Minters/MinterHolderV4.sol +54 -25
  91. package/contracts/minter-suite/Minters/MinterMerkleV5.sol +47 -20
  92. package/contracts/minter-suite/Minters/MinterPolyptychV0.sol +998 -0
  93. package/contracts/minter-suite/Minters/MinterSEAV0.sol +1224 -0
  94. package/contracts/minter-suite/Minters/MinterSetPriceERC20V4.sol +45 -16
  95. package/contracts/minter-suite/Minters/MinterSetPriceV4.sol +40 -13
  96. package/contracts/mock/DeadReceiverBidderMock.sol +23 -0
  97. package/contracts/mock/GasLimitReceiverBidderMock.sol +23 -0
  98. package/contracts/mock/GasLimitReceiverMock.sol +19 -0
  99. package/contracts/mock/RandomizerV2_NoAssignMock.sol +2 -11
  100. package/contracts/mock/ReentrancySEAMock.sol +36 -0
  101. package/contracts/{BasicRandomizer.sol → randomizer/BasicRandomizer.sol} +1 -1
  102. package/contracts/randomizer/BasicRandomizerBase_v0_0_0.sol +23 -0
  103. package/contracts/randomizer/PolyptychRandomizerV0.sol +117 -0
  104. package/contracts/{BasicRandomizerV2.sol → randomizer/RandomizerV2.sol} +7 -15
  105. package/package.json +32 -13
  106. package/artifacts/contracts/BasicRandomizerV2.sol/BasicRandomizerV2.json +0 -102
@@ -0,0 +1,998 @@
1
+ // SPDX-License-Identifier: LGPL-3.0-only
2
+ // Created By: Art Blocks Inc.
3
+
4
+ import "../../interfaces/0.8.x/IGenArt721CoreContractV3_Engine.sol";
5
+ import "../../interfaces/0.8.x/IMinterFilterV0.sol";
6
+ import "../../interfaces/0.8.x/IFilteredMinterHolderV2.sol";
7
+ import "../../interfaces/0.8.x/IRandomizerPolyptychV0.sol";
8
+ import "../../interfaces/0.8.x/IDelegationRegistry.sol";
9
+ import "./MinterBase_v0_1_1.sol";
10
+
11
+ import "@openzeppelin-4.5/contracts/token/ERC721/IERC721.sol";
12
+ import "@openzeppelin-4.5/contracts/security/ReentrancyGuard.sol";
13
+ import "@openzeppelin-4.5/contracts/utils/structs/EnumerableSet.sol";
14
+
15
+ pragma solidity 0.8.17;
16
+
17
+ /**
18
+ * @title Core contract interface for accessing the randomizer from the minter
19
+ * @notice This interface provides the minter with access to the randomizer, allowing the
20
+ * token hash seed for a newly-minted token to be assigned by the minter if the artist
21
+ * has enabled the project as a polyptych. Polytptych projects must use the V3 engine
22
+ * core contract, polyptych minter, and polyptych randomizer - this interface allows the
23
+ * minter to access the randomizer.
24
+ */
25
+ interface IGenArt721CoreContractV3WithRandomizer is
26
+ IGenArt721CoreContractV3_Engine
27
+ {
28
+ /// current randomizer contract
29
+ function randomizerContract() external returns (IRandomizerPolyptychV0);
30
+ }
31
+
32
+ /**
33
+ * @title Filtered Minter contract that allows tokens to be minted with ETH or ERC20 tokens
34
+ * when purchaser owns an allowlisted ERC-721 NFT. This contract must be used with
35
+ * an accompanying randomizer contract that is configured to copy the token hash seed
36
+ * from the allowlisted token to a corresponding newly-minted token.
37
+ * The source token may only be used to mint one additional polyptych "panel" if the token
38
+ * has not yet been used to mint a panel with the currently configured panel ID. To add
39
+ * an additional panel to a project, the panel ID may be incremented for the project
40
+ * using the `incrementPolyptychProjectPanelId` function. Panel IDs for a project may only
41
+ * be incremented such that panels must be minted in the order of their panel ID. Tokens
42
+ * of the same project and panel ID may be minted in any order.
43
+ * This is designed to be used with IGenArt721CoreContractV3_Engine contracts with an
44
+ * active IPolyptychRandomizerV0 randomizer available for this minter to use.
45
+ * This minter requires both a properly configured engine core contract and polyptych
46
+ * randomizer in order to mint polyptych tokens.
47
+ * @author Art Blocks Inc.
48
+ * @notice Privileged Roles and Ownership:
49
+ * This contract is designed to be managed, with limited powers.
50
+ * Privileged roles and abilities are controlled by the core contract's Admin
51
+ * ACL contract and a project's artist. Both of these roles hold extensive
52
+ * power and can modify minter details.
53
+ * Care must be taken to ensure that the admin ACL contract and artist
54
+ * addresses are secure behind a multi-sig or other access control mechanism.
55
+ * ----------------------------------------------------------------------------
56
+ * The following functions are restricted to the core contract's Admin ACL
57
+ * contract:
58
+ * - registerNFTAddress
59
+ * - unregisterNFTAddress
60
+ * ----------------------------------------------------------------------------
61
+ * The following functions are restricted to a project's artist:
62
+ * - allowHoldersOfProjects
63
+ * - removeHoldersOfProjects
64
+ * - allowRemoveHoldersOfProjects
65
+ * - updatePricePerTokenInWei
66
+ * - updateProjectCurrencyInfo
67
+ * - setProjectMaxInvocations
68
+ * - manuallyLimitProjectMaxInvocations
69
+ * ----------------------------------------------------------------------------
70
+ * Additional admin and artist privileged roles may be described on other
71
+ * contracts that this minter integrates with.
72
+ * ----------------------------------------------------------------------------
73
+ * This contract allows gated minting with support for vaults to delegate minting
74
+ * privileges via an external delegation registry. This means a vault holding an
75
+ * allowed token can delegate minting privileges to a wallet that is not holding an
76
+ * allowed token, enabling the vault to remain air-gapped while still allowing minting.
77
+ * The delegation registry contract is responsible for managing these delegations,
78
+ * and is available at the address returned by the public immutable
79
+ * `delegationRegistryAddress`. At the time of writing, the delegation
80
+ * registry enables easy delegation configuring at https://delegate.cash/.
81
+ * Art Blocks does not guarentee the security of the delegation registry, and
82
+ * users should take care to ensure that the delegation registry is secure.
83
+ * Delegations must be configured by the vault owner prior to purchase. Supported
84
+ * delegation types include token-level, contract-level (via genArt721CoreAddress), or
85
+ * wallet-level delegation. Contract-level delegations must be configured for the core
86
+ * token contract as returned by the owned token's core contract address.
87
+ */
88
+ contract MinterPolyptychV0 is
89
+ ReentrancyGuard,
90
+ MinterBase,
91
+ IFilteredMinterHolderV2
92
+ {
93
+ // add Enumerable Set methods
94
+ using EnumerableSet for EnumerableSet.AddressSet;
95
+
96
+ /// Delegation registry address
97
+ address public immutable delegationRegistryAddress;
98
+
99
+ /// Delegation registry address
100
+ IDelegationRegistry private immutable delegationRegistryContract;
101
+
102
+ /// Core contract address this minter interacts with
103
+ address public immutable genArt721CoreAddress;
104
+
105
+ /// This contract handles cores with interface IV3
106
+ IGenArt721CoreContractV3WithRandomizer private immutable genArtCoreContract;
107
+
108
+ /// Minter filter address this minter interacts with
109
+ address public immutable minterFilterAddress;
110
+
111
+ /// Minter filter this minter may interact with.
112
+ IMinterFilterV0 private immutable minterFilter;
113
+
114
+ // Stores whether a panel with an ID has been minted for a given token hash seed
115
+ // panelId => hashSeed => panelIsMinted
116
+ mapping(uint256 => mapping(bytes12 => bool))
117
+ public polyptychPanelHashSeedIsMinted;
118
+
119
+ /// minterType for this minter
120
+ string public constant minterType = "MinterPolyptychV0";
121
+
122
+ /// minter version for this minter
123
+ string public constant minterVersion = "v0.1.0";
124
+
125
+ uint256 constant ONE_MILLION = 1_000_000;
126
+
127
+ struct ProjectConfig {
128
+ bool maxHasBeenInvoked;
129
+ bool priceIsConfigured;
130
+ uint24 maxInvocations;
131
+ uint24 polyptychPanelId;
132
+ address currencyAddress;
133
+ uint256 pricePerTokenInWei;
134
+ string currencySymbol;
135
+ }
136
+
137
+ mapping(uint256 => ProjectConfig) public projectConfig;
138
+
139
+ /// Set of core contracts allowed to be queried for token holders
140
+ EnumerableSet.AddressSet private _registeredNFTAddresses;
141
+
142
+ /**
143
+ * projectId => ownedNFTAddress => ownedNFTProjectIds => bool
144
+ * projects whose holders are allowed to purchase a token on `projectId`
145
+ */
146
+ mapping(uint256 => mapping(address => mapping(uint256 => bool)))
147
+ public allowedProjectHolders;
148
+
149
+ // function to restrict access to only AdminACL allowed calls
150
+ // @dev defers which ACL contract is used to the core contract
151
+ function _onlyCoreAdminACL(bytes4 _selector) internal {
152
+ require(
153
+ genArtCoreContract.adminACLAllowed(
154
+ msg.sender,
155
+ address(this),
156
+ _selector
157
+ ),
158
+ "Only Core AdminACL allowed"
159
+ );
160
+ }
161
+
162
+ function _onlyArtist(uint256 _projectId) internal view {
163
+ require(
164
+ msg.sender ==
165
+ genArtCoreContract.projectIdToArtistAddress(_projectId),
166
+ "Only Artist"
167
+ );
168
+ }
169
+
170
+ /**
171
+ * @notice Initializes contract to be a Filtered Minter for
172
+ * `_minterFilter`, integrated with Art Blocks core contract
173
+ * at address `_genArt721Address`.
174
+ * @param _genArt721Address Art Blocks core contract for which this
175
+ * contract will be a minter.
176
+ * @param _minterFilter Minter filter for which
177
+ * this will a filtered minter.
178
+ * @param _delegationRegistryAddress Delegation registry contract address.
179
+ */
180
+ constructor(
181
+ address _genArt721Address,
182
+ address _minterFilter,
183
+ address _delegationRegistryAddress
184
+ ) ReentrancyGuard() MinterBase(_genArt721Address) {
185
+ genArt721CoreAddress = _genArt721Address;
186
+ genArtCoreContract = IGenArt721CoreContractV3WithRandomizer(
187
+ _genArt721Address
188
+ );
189
+ delegationRegistryAddress = _delegationRegistryAddress;
190
+ emit DelegationRegistryUpdated(_delegationRegistryAddress);
191
+ delegationRegistryContract = IDelegationRegistry(
192
+ _delegationRegistryAddress
193
+ );
194
+ minterFilterAddress = _minterFilter;
195
+ minterFilter = IMinterFilterV0(_minterFilter);
196
+ require(
197
+ minterFilter.genArt721CoreAddress() == _genArt721Address,
198
+ "Illegal contract pairing"
199
+ );
200
+ // currently, this minter only supports Engine V3 core contracts
201
+ require(MinterBase.isEngine, "Only supports V3 Engine core");
202
+ }
203
+
204
+ /**
205
+ * @notice Return whether or not a token has been used to mint a polyptych panel with the given ID
206
+ * @param _panelId The ID of the polyptych panel being checked
207
+ * @param _ownedNFTAddress ERC-721 NFT address holding the project token
208
+ * owned by msg.sender being used to prove right to purchase
209
+ * @param _ownedNFTTokenId ERC-721 NFT token ID owned by msg.sender being used
210
+ * to prove right to purchase
211
+ */
212
+ function polyptychPanelMintedWithToken(
213
+ uint24 _panelId,
214
+ address _ownedNFTAddress,
215
+ uint256 _ownedNFTTokenId
216
+ ) external view returns (bool panelMinted) {
217
+ bytes12 _tokenHash = IGenArt721CoreContractV3_Engine(_ownedNFTAddress)
218
+ .tokenIdToHashSeed(_ownedNFTTokenId);
219
+ require(_tokenHash != bytes32(0), "Invalid token hash seed");
220
+ return polyptychPanelHashSeedIsMinted[_panelId][_tokenHash];
221
+ }
222
+
223
+ /**
224
+ *
225
+ * @notice Registers holders of NFTs at address `_NFTAddress` to be
226
+ * considered for minting. New core address is assumed to follow syntax of:
227
+ * `projectId = tokenId / 1_000_000`
228
+ * @param _NFTAddress NFT core address to be registered.
229
+ */
230
+ function registerNFTAddress(address _NFTAddress) external {
231
+ _onlyCoreAdminACL(this.registerNFTAddress.selector);
232
+ // check that core contract implements the `tokenIdToHashSeed` function
233
+ IGenArt721CoreContractV3WithRandomizer(_NFTAddress).tokenIdToHashSeed(
234
+ 0
235
+ );
236
+ _registeredNFTAddresses.add(_NFTAddress);
237
+ emit RegisteredNFTAddress(_NFTAddress);
238
+ }
239
+
240
+ /**
241
+ *
242
+ * @notice Unregisters holders of NFTs at address `_NFTAddress` to be
243
+ * considered for adding to future allowlists.
244
+ * @param _NFTAddress NFT core address to be unregistered.
245
+ */
246
+ function unregisterNFTAddress(address _NFTAddress) external {
247
+ _onlyCoreAdminACL(this.unregisterNFTAddress.selector);
248
+ _registeredNFTAddresses.remove(_NFTAddress);
249
+ emit UnregisteredNFTAddress(_NFTAddress);
250
+ }
251
+
252
+ /**
253
+ * @notice Allows holders of NFTs at addresses `_ownedNFTAddressesAdd`,
254
+ * project IDs `_ownedNFTProjectIdsAdd` to mint on project `_projectId`.
255
+ * Also removes holders of NFTs at addresses `_ownedNFTAddressesRemove`,
256
+ * project IDs `_ownedNFTProjectIdsRemove` from minting on project
257
+ * `_projectId`.
258
+ * `_ownedNFTAddressesAdd` assumed to be aligned with
259
+ * `_ownedNFTProjectIdsAdd`.
260
+ * e.g. Allows holders of project `_ownedNFTProjectIdsAdd[0]` on token
261
+ * contract `_ownedNFTAddressesAdd[0]` to mint `_projectId`.
262
+ * `_ownedNFTAddressesRemove` also assumed to be aligned with
263
+ * `_ownedNFTProjectIdsRemove`.
264
+ * @param _projectId Project ID to enable minting on.
265
+ * @param _ownedNFTAddressesAdd NFT core addresses of projects to be
266
+ * allowlisted. Indexes must align with `_ownedNFTProjectIdsAdd`.
267
+ * @param _ownedNFTProjectIdsAdd Project IDs on `_ownedNFTAddressesAdd`
268
+ * whose holders shall be allowlisted to mint project `_projectId`. Indexes
269
+ * must align with `_ownedNFTAddressesAdd`.
270
+ * @param _ownedNFTAddressesRemove NFT core addresses of projects to be
271
+ * removed from allowlist. Indexes must align with
272
+ * `_ownedNFTProjectIdsRemove`.
273
+ * @param _ownedNFTProjectIdsRemove Project IDs on
274
+ * `_ownedNFTAddressesRemove` whose holders will be removed from allowlist
275
+ * to mint project `_projectId`. Indexes must align with
276
+ * `_ownedNFTAddressesRemove`.
277
+ * @dev if a project is included in both add and remove arrays, it will be
278
+ * removed.
279
+ */
280
+ function allowRemoveHoldersOfProjects(
281
+ uint256 _projectId,
282
+ address[] memory _ownedNFTAddressesAdd,
283
+ uint256[] memory _ownedNFTProjectIdsAdd,
284
+ address[] memory _ownedNFTAddressesRemove,
285
+ uint256[] memory _ownedNFTProjectIdsRemove
286
+ ) external {
287
+ _onlyArtist(_projectId);
288
+ allowHoldersOfProjects(
289
+ _projectId,
290
+ _ownedNFTAddressesAdd,
291
+ _ownedNFTProjectIdsAdd
292
+ );
293
+ removeHoldersOfProjects(
294
+ _projectId,
295
+ _ownedNFTAddressesRemove,
296
+ _ownedNFTProjectIdsRemove
297
+ );
298
+ }
299
+
300
+ /**
301
+ * @notice Syncs local maximum invocations of project `_projectId` based on
302
+ * the value currently defined in the core contract.
303
+ * @param _projectId Project ID to set the maximum invocations for.
304
+ * @dev this enables gas reduction after maxInvocations have been reached -
305
+ * core contracts shall still enforce a maxInvocation check during mint.
306
+ */
307
+ function setProjectMaxInvocations(uint256 _projectId) public {
308
+ uint256 maxInvocations;
309
+ uint256 invocations;
310
+ (invocations, maxInvocations, , , , ) = genArtCoreContract
311
+ .projectStateData(_projectId);
312
+ // update storage with results
313
+ projectConfig[_projectId].maxInvocations = uint24(maxInvocations);
314
+
315
+ // We need to ensure maxHasBeenInvoked is correctly set after manually syncing the
316
+ // local maxInvocations value with the core contract's maxInvocations value.
317
+ // This synced value of maxInvocations from the core contract will always be greater
318
+ // than or equal to the previous value of maxInvocations stored locally.
319
+ projectConfig[_projectId].maxHasBeenInvoked =
320
+ invocations == maxInvocations;
321
+
322
+ emit ProjectMaxInvocationsLimitUpdated(_projectId, maxInvocations);
323
+ }
324
+
325
+ /**
326
+ * @notice Manually sets the local maximum invocations of project `_projectId`
327
+ * with the provided `_maxInvocations`, checking that `_maxInvocations` is less
328
+ * than or equal to the value of project `_project_id`'s maximum invocations that is
329
+ * set on the core contract.
330
+ * @dev Note that a `_maxInvocations` of 0 can only be set if the current `invocations`
331
+ * value is also 0 and this would also set `maxHasBeenInvoked` to true, correctly short-circuiting
332
+ * this minter's purchase function, avoiding extra gas costs from the core contract's maxInvocations check.
333
+ * @param _projectId Project ID to set the maximum invocations for.
334
+ * @param _maxInvocations Maximum invocations to set for the project.
335
+ */
336
+ function manuallyLimitProjectMaxInvocations(
337
+ uint256 _projectId,
338
+ uint256 _maxInvocations
339
+ ) external {
340
+ _onlyArtist(_projectId);
341
+ // CHECKS
342
+ // ensure that the manually set maxInvocations is not greater than what is set on the core contract
343
+ uint256 maxInvocations;
344
+ uint256 invocations;
345
+ (invocations, maxInvocations, , , , ) = genArtCoreContract
346
+ .projectStateData(_projectId);
347
+ require(
348
+ _maxInvocations <= maxInvocations,
349
+ "Cannot increase project max invocations above core contract set project max invocations"
350
+ );
351
+ require(
352
+ _maxInvocations >= invocations,
353
+ "Cannot set project max invocations to less than current invocations"
354
+ );
355
+
356
+ // EFFECTS
357
+ // update storage with results
358
+ projectConfig[_projectId].maxInvocations = uint24(_maxInvocations);
359
+ // We need to ensure maxHasBeenInvoked is correctly set after manually setting the
360
+ // local maxInvocations value.
361
+ projectConfig[_projectId].maxHasBeenInvoked =
362
+ invocations == _maxInvocations;
363
+
364
+ emit ProjectMaxInvocationsLimitUpdated(_projectId, _maxInvocations);
365
+ }
366
+
367
+ /**
368
+ * @notice Updates this minter's price per token of project `_projectId`
369
+ * to be '_pricePerTokenInWei`, in Wei.
370
+ * This price supersedes any legacy core contract price per token value.
371
+ * @dev Note that it is intentionally supported here that the configured
372
+ * price may be explicitly set to `0`.
373
+ */
374
+ function updatePricePerTokenInWei(
375
+ uint256 _projectId,
376
+ uint256 _pricePerTokenInWei
377
+ ) external {
378
+ _onlyArtist(_projectId);
379
+ ProjectConfig storage _projectConfig = projectConfig[_projectId];
380
+ _projectConfig.pricePerTokenInWei = _pricePerTokenInWei;
381
+ _projectConfig.priceIsConfigured = true;
382
+ emit PricePerTokenInWeiUpdated(_projectId, _pricePerTokenInWei);
383
+
384
+ // sync local max invocations if not initially populated
385
+ // @dev if local max invocations and maxHasBeenInvoked are both
386
+ // initial values, we know they have not been populated.
387
+ if (
388
+ _projectConfig.maxInvocations == 0 &&
389
+ _projectConfig.maxHasBeenInvoked == false
390
+ ) {
391
+ setProjectMaxInvocations(_projectId);
392
+ }
393
+ }
394
+
395
+ /**
396
+ * @notice Updates payment currency of project `_projectId` to be
397
+ * `_currencySymbol` at address `_currencyAddress`.
398
+ * @param _projectId Project ID to update.
399
+ * @param _currencySymbol Currency symbol.
400
+ * @param _currencyAddress Currency address.
401
+ */
402
+ function updateProjectCurrencyInfo(
403
+ uint256 _projectId,
404
+ string memory _currencySymbol,
405
+ address _currencyAddress
406
+ ) external {
407
+ _onlyArtist(_projectId);
408
+ // require null address if symbol is "ETH"
409
+ require(
410
+ (keccak256(abi.encodePacked(_currencySymbol)) ==
411
+ keccak256(abi.encodePacked("ETH"))) ==
412
+ (_currencyAddress == address(0)),
413
+ "ETH is only null address"
414
+ );
415
+ projectConfig[_projectId].currencySymbol = _currencySymbol;
416
+ projectConfig[_projectId].currencyAddress = _currencyAddress;
417
+ emit ProjectCurrencyInfoUpdated(
418
+ _projectId,
419
+ _currencyAddress,
420
+ _currencySymbol
421
+ );
422
+ }
423
+
424
+ /**
425
+ * @notice Purchases a token from project `_projectId`.
426
+ * @param _projectId Project ID to mint a token on.
427
+ * @param _ownedNFTAddress ERC-721 NFT address holding the project token
428
+ * owned by msg.sender being used to prove right to purchase.
429
+ * @param _ownedNFTTokenId ERC-721 NFT token ID owned by msg.sender being used
430
+ * to prove right to purchase.
431
+ * @return tokenId Token ID of minted token
432
+ */
433
+ function purchase(
434
+ uint256 _projectId,
435
+ address _ownedNFTAddress,
436
+ uint256 _ownedNFTTokenId
437
+ ) external payable returns (uint256 tokenId) {
438
+ tokenId = purchaseTo_dlc(
439
+ msg.sender,
440
+ _projectId,
441
+ _ownedNFTAddress,
442
+ _ownedNFTTokenId,
443
+ address(0)
444
+ );
445
+ return tokenId;
446
+ }
447
+
448
+ /**
449
+ * @notice gas-optimized version of purchase(uint256,address,uint256).
450
+ */
451
+ function purchase_nnf(
452
+ uint256 _projectId,
453
+ address _ownedNFTAddress,
454
+ uint256 _ownedNFTTokenId
455
+ ) external payable returns (uint256 tokenId) {
456
+ tokenId = purchaseTo_dlc(
457
+ msg.sender,
458
+ _projectId,
459
+ _ownedNFTAddress,
460
+ _ownedNFTTokenId,
461
+ address(0)
462
+ );
463
+ return tokenId;
464
+ }
465
+
466
+ /**
467
+ * @notice Purchases a token from project `_projectId` and sets
468
+ * the token's owner to `_to`.
469
+ * @param _to Address to be the new token's owner.
470
+ * @param _projectId Project ID to mint a token on.
471
+ * @param _ownedNFTAddress ERC-721 NFT holding the project token owned by
472
+ * msg.sender being used to claim right to purchase.
473
+ * @param _ownedNFTTokenId ERC-721 NFT token ID owned by msg.sender being used
474
+ * to claim right to purchase.
475
+ * @return tokenId Token ID of minted token
476
+ */
477
+ function purchaseTo(
478
+ address _to,
479
+ uint256 _projectId,
480
+ address _ownedNFTAddress,
481
+ uint256 _ownedNFTTokenId
482
+ ) external payable returns (uint256 tokenId) {
483
+ return
484
+ purchaseTo_dlc(
485
+ _to,
486
+ _projectId,
487
+ _ownedNFTAddress,
488
+ _ownedNFTTokenId,
489
+ address(0)
490
+ );
491
+ }
492
+
493
+ /**
494
+ * @notice Purchases a token from project `_projectId` and sets
495
+ * the token's owner to `_to`, as a delegate, (the `msg.sender`)
496
+ * on behalf of an explicitly defined vault.
497
+ * @param _to Address to be the new token's owner.
498
+ * @param _projectId Project ID to mint a token on.
499
+ * @param _ownedNFTAddress ERC-721 NFT address holding the project token owned by
500
+ * _vault (or msg.sender if no _vault is provided) being used to claim right to purchase.
501
+ * @param _ownedNFTTokenId ERC-721 NFT token ID owned by _vault (or msg.sender if
502
+ * no _vault is provided) being used to claim right to purchase.
503
+ * @param _vault Vault being purchased on behalf of. Acceptable to be `address(0)` if no vault.
504
+ * @return tokenId Token ID of minted token
505
+ */
506
+ function purchaseTo(
507
+ address _to,
508
+ uint256 _projectId,
509
+ address _ownedNFTAddress,
510
+ uint256 _ownedNFTTokenId,
511
+ address _vault
512
+ ) external payable returns (uint256 tokenId) {
513
+ return
514
+ purchaseTo_dlc(
515
+ _to,
516
+ _projectId,
517
+ _ownedNFTAddress,
518
+ _ownedNFTTokenId,
519
+ _vault
520
+ );
521
+ }
522
+
523
+ /**
524
+ * @notice Inactive function - requires NFT ownership to purchase.
525
+ */
526
+ function purchase(uint256) external payable returns (uint256) {
527
+ revert("Must claim NFT ownership");
528
+ }
529
+
530
+ /**
531
+ * @notice Warning: Disabling purchaseTo is not supported on this minter.
532
+ * This method exists purely for interface-conformance purposes.
533
+ */
534
+ function togglePurchaseToDisabled(uint256 _projectId) external view {
535
+ _onlyArtist(_projectId);
536
+ revert("Action not supported");
537
+ }
538
+
539
+ /**
540
+ * @notice projectId => has project reached its maximum number of
541
+ * invocations? Note that this returns a local cache of the core contract's
542
+ * state, and may be out of sync with the core contract. This is
543
+ * intentional, as it only enables gas optimization of mints after a
544
+ * project's maximum invocations has been reached. A false negative will
545
+ * only result in a gas cost increase, since the core contract will still
546
+ * enforce a maxInvocation check during minting. A false positive is not
547
+ * possible because the V3 core contract only allows maximum invocations
548
+ * to be reduced, not increased. Based on this rationale, we intentionally
549
+ * do not do input validation in this method as to whether or not the input
550
+ * `_projectId` is an existing project ID.
551
+ */
552
+ function projectMaxHasBeenInvoked(
553
+ uint256 _projectId
554
+ ) external view returns (bool) {
555
+ return projectConfig[_projectId].maxHasBeenInvoked;
556
+ }
557
+
558
+ /**
559
+ * @notice projectId => project's maximum number of invocations.
560
+ * Optionally synced with core contract value, for gas optimization.
561
+ * Note that this returns a local cache of the core contract's
562
+ * state, and may be out of sync with the core contract. This is
563
+ * intentional, as it only enables gas optimization of mints after a
564
+ * project's maximum invocations has been reached.
565
+ * @dev A number greater than the core contract's project max invocations
566
+ * will only result in a gas cost increase, since the core contract will
567
+ * still enforce a maxInvocation check during minting. A number less than
568
+ * the core contract's project max invocations is only possible when the
569
+ * project's max invocations have not been synced on this minter, since the
570
+ * V3 core contract only allows maximum invocations to be reduced, not
571
+ * increased. When this happens, the minter will enable minting, allowing
572
+ * the core contract to enforce the max invocations check. Based on this
573
+ * rationale, we intentionally do not do input validation in this method as
574
+ * to whether or not the input `_projectId` is an existing project ID.
575
+ */
576
+ function projectMaxInvocations(
577
+ uint256 _projectId
578
+ ) external view returns (uint256) {
579
+ return uint256(projectConfig[_projectId].maxInvocations);
580
+ }
581
+
582
+ /**
583
+ * @notice Gets your balance of the ERC-20 token currently set
584
+ * as the payment currency for project `_projectId`.
585
+ * @param _projectId Project ID to be queried.
586
+ * @return balance Balance of ERC-20
587
+ */
588
+ function getYourBalanceOfProjectERC20(
589
+ uint256 _projectId
590
+ ) external view returns (uint256 balance) {
591
+ balance = IERC20(projectConfig[_projectId].currencyAddress).balanceOf(
592
+ msg.sender
593
+ );
594
+ return balance;
595
+ }
596
+
597
+ /**
598
+ * @notice Gets your allowance for this minter of the ERC-20
599
+ * token currently set as the payment currency for project
600
+ * `_projectId`.
601
+ * @param _projectId Project ID to be queried.
602
+ * @return remaining Remaining allowance of ERC-20
603
+ */
604
+ function checkYourAllowanceOfProjectERC20(
605
+ uint256 _projectId
606
+ ) external view returns (uint256 remaining) {
607
+ remaining = IERC20(projectConfig[_projectId].currencyAddress).allowance(
608
+ msg.sender,
609
+ address(this)
610
+ );
611
+ return remaining;
612
+ }
613
+
614
+ /**
615
+ * @notice Gets quantity of NFT addresses registered on this minter.
616
+ * @return uint256 quantity of NFT addresses registered
617
+ */
618
+ function getNumRegisteredNFTAddresses() external view returns (uint256) {
619
+ return _registeredNFTAddresses.length();
620
+ }
621
+
622
+ /**
623
+ * @notice Get registered NFT core contract address at index `_index` of
624
+ * enumerable set.
625
+ * @param _index enumerable set index to query.
626
+ * @return NFTAddress NFT core contract address at index `_index`
627
+ * @dev index must be < quantity of registered NFT addresses
628
+ */
629
+ function getRegisteredNFTAddressAt(
630
+ uint256 _index
631
+ ) external view returns (address NFTAddress) {
632
+ return _registeredNFTAddresses.at(_index);
633
+ }
634
+
635
+ /**
636
+ * @notice Gets if price of token is configured, price of minting a
637
+ * token on project `_projectId`, and currency symbol and address to be
638
+ * used as payment. Supersedes any core contract price information.
639
+ * @param _projectId Project ID to get price information for.
640
+ * @return isConfigured true only if token price has been configured on
641
+ * this minter
642
+ * @return tokenPriceInWei current price of token on this minter - invalid
643
+ * if price has not yet been configured
644
+ * @return currencySymbol currency symbol for purchases of project on this
645
+ * minter. This minter always returns "ETH"
646
+ * @return currencyAddress currency address for purchases of project on
647
+ * this minter. This minter always returns null address, reserved for ether
648
+ */
649
+ function getPriceInfo(
650
+ uint256 _projectId
651
+ )
652
+ external
653
+ view
654
+ returns (
655
+ bool isConfigured,
656
+ uint256 tokenPriceInWei,
657
+ string memory currencySymbol,
658
+ address currencyAddress
659
+ )
660
+ {
661
+ ProjectConfig storage _projectConfig = projectConfig[_projectId];
662
+ isConfigured = _projectConfig.priceIsConfigured;
663
+ tokenPriceInWei = _projectConfig.pricePerTokenInWei;
664
+ currencyAddress = _projectConfig.currencyAddress;
665
+ if (currencyAddress == address(0)) {
666
+ // defaults to ETH
667
+ currencySymbol = "ETH";
668
+ } else {
669
+ currencySymbol = _projectConfig.currencySymbol;
670
+ }
671
+ }
672
+
673
+ /**
674
+ * @notice Inactive function - requires NFT ownership to purchase.
675
+ */
676
+ function purchaseTo(address, uint256) public payable returns (uint256) {
677
+ revert("Must claim NFT ownership");
678
+ }
679
+
680
+ /**
681
+ * @notice gas-optimized version of purchaseTo(address,uint256,address,uint256,address).
682
+ * @param _to Address to be the new token's owner.
683
+ * @param _projectId Project ID to mint a token on.
684
+ * @param _ownedNFTAddress ERC-721 NFT address holding the project token owned by _vault
685
+ * (or msg.sender if no _vault is provided) being used to claim right to purchase.
686
+ * @param _ownedNFTTokenId ERC-721 NFT token ID owned by _vault (or msg.sender if
687
+ * no _vault is provided) being used to claim right to purchase.
688
+ * @param _vault Vault being purchased on behalf of. Acceptable to be `address(0)` if no vault.
689
+ * @return tokenId Token ID of minted token
690
+ */
691
+ function purchaseTo_dlc(
692
+ address _to,
693
+ uint256 _projectId,
694
+ address _ownedNFTAddress,
695
+ uint256 _ownedNFTTokenId,
696
+ address _vault
697
+ ) public payable nonReentrant returns (uint256 tokenId) {
698
+ // CHECKS
699
+ ProjectConfig storage _projectConfig = projectConfig[_projectId];
700
+
701
+ // Note that `maxHasBeenInvoked` is only checked here to reduce gas
702
+ // consumption after a project has been fully minted.
703
+ // `_projectConfig.maxHasBeenInvoked` is locally cached to reduce
704
+ // gas consumption, but if not in sync with the core contract's value,
705
+ // the core contract also enforces its own max invocation check during
706
+ // minting.
707
+ require(
708
+ !_projectConfig.maxHasBeenInvoked,
709
+ "Maximum number of invocations reached"
710
+ );
711
+
712
+ // require artist to have configured price of token on this minter
713
+ require(_projectConfig.priceIsConfigured, "Price not configured");
714
+
715
+ // require token used to claim to be in set of allowlisted NFTs
716
+ require(
717
+ isAllowlistedNFT(_projectId, _ownedNFTAddress, _ownedNFTTokenId),
718
+ "Only allowlisted NFTs"
719
+ );
720
+
721
+ // NOTE: delegate-vault handling **begins here**.
722
+
723
+ // handle that the vault may be either the `msg.sender` in the case
724
+ // that there is not a true vault, or may be `_vault` if one is
725
+ // provided explicitly (and it is valid).
726
+ address vault = msg.sender;
727
+ if (_vault != address(0)) {
728
+ // If a vault is provided, it must be valid, otherwise throw rather
729
+ // than optimistically-minting with original `msg.sender`.
730
+ // Note, we do not check `checkDelegateForAll` or `checkDelegateForContract` as well,
731
+ // as they are known to be implicitly checked by calling `checkDelegateForToken`.
732
+ bool isValidVault = delegationRegistryContract
733
+ .checkDelegateForToken(
734
+ msg.sender, // delegate
735
+ _vault, // vault
736
+ _ownedNFTAddress, // contract
737
+ _ownedNFTTokenId // tokenId
738
+ );
739
+ require(isValidVault, "Invalid delegate-vault pairing");
740
+ vault = _vault;
741
+ }
742
+
743
+ // we need the new token ID in advance of the randomizer setting a token hash
744
+ (uint256 _invocations, , , , , ) = genArtCoreContract.projectStateData(
745
+ _projectId
746
+ );
747
+
748
+ address _artist = genArtCoreContract.projectIdToArtistAddress(
749
+ _projectId
750
+ );
751
+
752
+ uint256 _newTokenId = (_projectId * ONE_MILLION) + _invocations;
753
+
754
+ // EFFECTS
755
+
756
+ // we need to store the new token ID before it is minted so the randomizer can query it
757
+ IGenArt721CoreContractV3WithRandomizer _ownedNFTCoreContract = IGenArt721CoreContractV3WithRandomizer(
758
+ _ownedNFTAddress
759
+ );
760
+ bytes12 _targetHashSeed = _ownedNFTCoreContract.tokenIdToHashSeed(
761
+ _ownedNFTTokenId
762
+ );
763
+
764
+ _requireCurrentPanelIsMintedOnce(_projectId, _targetHashSeed);
765
+
766
+ genArtCoreContract.randomizerContract().setPolyptychHashSeed(
767
+ _newTokenId,
768
+ _targetHashSeed
769
+ );
770
+
771
+ // once mint() is called, the polyptych randomizer will either:
772
+ // 1) assign a random token hash
773
+ // 2) if configured, obtain the token hash from the `polyptychSeedHashes` mapping
774
+ tokenId = minterFilter.mint(_to, _projectId, vault);
775
+
776
+ // NOTE: delegate-vault handling **ends here**.
777
+
778
+ // redundant check against reentrancy
779
+ bytes12 _assignedHashSeed = genArtCoreContract.tokenIdToHashSeed(
780
+ tokenId
781
+ );
782
+ require(
783
+ _assignedHashSeed == _targetHashSeed,
784
+ "Unexpected token hash seed"
785
+ );
786
+
787
+ // invocation is token number plus one, and will never overflow due to
788
+ // limit of 1e6 invocations per project. block scope for gas efficiency
789
+ // (i.e. avoid an unnecessary var initialization to 0).
790
+ unchecked {
791
+ uint256 tokenInvocation = (tokenId % ONE_MILLION) + 1;
792
+ uint256 localMaxInvocations = _projectConfig.maxInvocations;
793
+ // handle the case where the token invocation == minter local max
794
+ // invocations occurred on a different minter, and we have a stale
795
+ // local maxHasBeenInvoked value returning a false negative.
796
+ // @dev this is a CHECK after EFFECTS, so security was considered
797
+ // in detail here.
798
+ require(
799
+ tokenInvocation <= localMaxInvocations,
800
+ "Maximum invocations reached"
801
+ );
802
+ // in typical case, update the local maxHasBeenInvoked value
803
+ // to true if the token invocation == minter local max invocations
804
+ // (enables gas efficient reverts after sellout)
805
+ if (tokenInvocation == localMaxInvocations) {
806
+ _projectConfig.maxHasBeenInvoked = true;
807
+ }
808
+ }
809
+
810
+ // INTERACTIONS
811
+ // require sender to own NFT used to redeem
812
+ /**
813
+ * @dev Considered an interaction because calling ownerOf on an NFT
814
+ * contract. Plan is to only register AB/PBAB NFTs on the minter, but
815
+ * in case other NFTs are registered, better to check here. Also,
816
+ * function is non-reentrant, so being extra cautious.
817
+ */
818
+ if (msg.sender == _artist) {
819
+ require(
820
+ IERC721(_ownedNFTAddress).ownerOf(_ownedNFTTokenId) == _to,
821
+ "Only owner of NFT"
822
+ );
823
+ } else {
824
+ require(
825
+ IERC721(_ownedNFTAddress).ownerOf(_ownedNFTTokenId) == vault,
826
+ "Only owner of NFT"
827
+ );
828
+ }
829
+
830
+ // split funds
831
+ uint256 pricePerTokenInWei = _projectConfig.pricePerTokenInWei;
832
+ address currencyAddress = _projectConfig.currencyAddress;
833
+ if (currencyAddress != address(0)) {
834
+ require(
835
+ msg.value == 0,
836
+ "this project accepts a different currency and cannot accept ETH"
837
+ );
838
+ require(
839
+ IERC20(currencyAddress).allowance(msg.sender, address(this)) >=
840
+ pricePerTokenInWei,
841
+ "Insufficient Funds Approved for TX"
842
+ );
843
+ require(
844
+ IERC20(currencyAddress).balanceOf(msg.sender) >=
845
+ pricePerTokenInWei,
846
+ "Insufficient balance."
847
+ );
848
+ splitFundsERC20(
849
+ _projectId,
850
+ pricePerTokenInWei,
851
+ currencyAddress,
852
+ genArt721CoreAddress
853
+ );
854
+ } else {
855
+ require(
856
+ msg.value >= pricePerTokenInWei,
857
+ "Must send minimum value to mint!"
858
+ );
859
+ splitFundsETH(_projectId, pricePerTokenInWei, genArt721CoreAddress);
860
+ }
861
+
862
+ return tokenId;
863
+ }
864
+
865
+ /**
866
+ * @notice Allows holders of NFTs at addresses `_ownedNFTAddresses`,
867
+ * project IDs `_ownedNFTProjectIds` to mint on project `_projectId`.
868
+ * `_ownedNFTAddresses` assumed to be aligned with `_ownedNFTProjectIds`.
869
+ * e.g. Allows holders of project `_ownedNFTProjectIds[0]` on token
870
+ * contract `_ownedNFTAddresses[0]` to mint `_projectId`.
871
+ * @param _projectId Project ID to enable minting on.
872
+ * @param _ownedNFTAddresses NFT core addresses of projects to be
873
+ * allowlisted. Indexes must align with `_ownedNFTProjectIds`.
874
+ * @param _ownedNFTProjectIds Project IDs on `_ownedNFTAddresses` whose
875
+ * holders shall be allowlisted to mint project `_projectId`. Indexes must
876
+ * align with `_ownedNFTAddresses`.
877
+ */
878
+ function allowHoldersOfProjects(
879
+ uint256 _projectId,
880
+ address[] memory _ownedNFTAddresses,
881
+ uint256[] memory _ownedNFTProjectIds
882
+ ) public {
883
+ _onlyArtist(_projectId);
884
+ // require same length arrays
885
+ require(
886
+ _ownedNFTAddresses.length == _ownedNFTProjectIds.length,
887
+ "Length of add arrays must match"
888
+ );
889
+ // for each approved project
890
+ for (uint256 i = 0; i < _ownedNFTAddresses.length; i++) {
891
+ // ensure registered address
892
+ require(
893
+ _registeredNFTAddresses.contains(_ownedNFTAddresses[i]),
894
+ "Only Registered NFT Addresses"
895
+ );
896
+ // approve
897
+ allowedProjectHolders[_projectId][_ownedNFTAddresses[i]][
898
+ _ownedNFTProjectIds[i]
899
+ ] = true;
900
+ }
901
+ // emit approve event
902
+ emit AllowedHoldersOfProjects(
903
+ _projectId,
904
+ _ownedNFTAddresses,
905
+ _ownedNFTProjectIds
906
+ );
907
+ }
908
+
909
+ /**
910
+ * @notice Removes holders of NFTs at addresses `_ownedNFTAddresses`,
911
+ * project IDs `_ownedNFTProjectIds` to mint on project `_projectId`. If
912
+ * other projects owned by a holder are still allowed to mint, holder will
913
+ * maintain ability to purchase.
914
+ * `_ownedNFTAddresses` assumed to be aligned with `_ownedNFTProjectIds`.
915
+ * e.g. Removes holders of project `_ownedNFTProjectIds[0]` on token
916
+ * contract `_ownedNFTAddresses[0]` from mint allowlist of `_projectId`.
917
+ * @param _projectId Project ID to enable minting on.
918
+ * @param _ownedNFTAddresses NFT core addresses of projects to be removed
919
+ * from allowlist. Indexes must align with `_ownedNFTProjectIds`.
920
+ * @param _ownedNFTProjectIds Project IDs on `_ownedNFTAddresses` whose
921
+ * holders will be removed from allowlist to mint project `_projectId`.
922
+ * Indexes must align with `_ownedNFTAddresses`.
923
+ */
924
+ function removeHoldersOfProjects(
925
+ uint256 _projectId,
926
+ address[] memory _ownedNFTAddresses,
927
+ uint256[] memory _ownedNFTProjectIds
928
+ ) public {
929
+ _onlyArtist(_projectId);
930
+ // require same length arrays
931
+ require(
932
+ _ownedNFTAddresses.length == _ownedNFTProjectIds.length,
933
+ "Length of remove arrays must match"
934
+ );
935
+ // for each removed project
936
+ for (uint256 i = 0; i < _ownedNFTAddresses.length; i++) {
937
+ // revoke
938
+ allowedProjectHolders[_projectId][_ownedNFTAddresses[i]][
939
+ _ownedNFTProjectIds[i]
940
+ ] = false;
941
+ }
942
+ // emit removed event
943
+ emit RemovedHoldersOfProjects(
944
+ _projectId,
945
+ _ownedNFTAddresses,
946
+ _ownedNFTProjectIds
947
+ );
948
+ }
949
+
950
+ /**
951
+ * @notice Allows the artist to increment the minter to the next polyptych panel
952
+ * @param _projectId Project ID to increment to its next polyptych panel
953
+ */
954
+ function incrementPolyptychProjectPanelId(uint256 _projectId) public {
955
+ _onlyArtist(_projectId);
956
+ projectConfig[_projectId].polyptychPanelId++;
957
+ }
958
+
959
+ /**
960
+ * @notice Returns if token is an allowlisted NFT for project `_projectId`.
961
+ * @param _projectId Project ID to be checked.
962
+ * @param _ownedNFTAddress ERC-721 NFT token address to be checked.
963
+ * @param _ownedNFTTokenId ERC-721 NFT token ID to be checked.
964
+ * @return bool Token is allowlisted
965
+ * @dev does not check if token has been used to purchase
966
+ * @dev assumes project ID can be derived from tokenId / 1_000_000
967
+ */
968
+ function isAllowlistedNFT(
969
+ uint256 _projectId,
970
+ address _ownedNFTAddress,
971
+ uint256 _ownedNFTTokenId
972
+ ) public view returns (bool) {
973
+ uint256 ownedNFTProjectId = _ownedNFTTokenId / ONE_MILLION;
974
+ return
975
+ allowedProjectHolders[_projectId][_ownedNFTAddress][
976
+ ownedNFTProjectId
977
+ ];
978
+ }
979
+
980
+ function _requireCurrentPanelIsMintedOnce(
981
+ uint256 _projectId,
982
+ bytes12 _tokenHashSeed
983
+ ) private {
984
+ // mark the polyptych panel as minted so the same panel cannot be minted twice
985
+ uint256 _panelId = projectConfig[_projectId].polyptychPanelId;
986
+
987
+ require(
988
+ _tokenHashSeed != bytes12(0),
989
+ "Cannot have an empty hash seed to copy."
990
+ );
991
+
992
+ require(
993
+ !polyptychPanelHashSeedIsMinted[_panelId][_tokenHashSeed],
994
+ "Panel already minted"
995
+ );
996
+ polyptychPanelHashSeedIsMinted[_panelId][_tokenHashSeed] = true;
997
+ }
998
+ }