Skip to content

Commit 9f4a11e

Browse files
committed
fix: rename dedup param & revert inside SPGNFT
1 parent 0c6e930 commit 9f4a11e

21 files changed

+220
-307
lines changed

contracts/SPGNFT.sol

+19-23
Original file line numberDiff line numberDiff line change
@@ -219,25 +219,23 @@ contract SPGNFT is ISPGNFT, ERC721URIStorageUpgradeable, AccessControlUpgradeabl
219219
/// @param nftMetadataURI OPTIONAL. The URI of the desired metadata for the newly minted NFT.
220220
/// @param nftMetadataHash OPTIONAL. A bytes32 hash of the NFT's metadata.
221221
/// This metadata is accessible via the NFT's tokenURI.
222-
/// @param dedup Set to true to enable checking for duplicate metadata hashes.
223-
/// If a duplicate is found, the function will return the existing token ID instead of minting a new one.
222+
/// @param allowDuplicates Set to true to allow minting an NFT with a duplicate metadata hash.
224223
/// @return tokenId The token ID of the minted NFT with the given metadata hash.
225-
/// @return deduped true if dedup is enabled and the metadata hash is already used, false otherwise.
226224
function mint(
227225
address to,
228226
string calldata nftMetadataURI,
229227
bytes32 nftMetadataHash,
230-
bool dedup
231-
) public virtual returns (uint256 tokenId, bool deduped) {
228+
bool allowDuplicates
229+
) public virtual returns (uint256 tokenId) {
232230
if (!_getSPGNFTStorage()._publicMinting && !hasRole(SPGNFTLib.MINTER_ROLE, msg.sender)) {
233231
revert Errors.SPGNFT__MintingDenied();
234232
}
235-
(tokenId, deduped) = _mintToken({
233+
tokenId = _mintToken({
236234
to: to,
237235
payer: msg.sender,
238236
nftMetadataURI: nftMetadataURI,
239237
nftMetadataHash: nftMetadataHash,
240-
dedup: dedup
238+
allowDuplicates: allowDuplicates
241239
});
242240
}
243241

@@ -247,23 +245,21 @@ contract SPGNFT is ISPGNFT, ERC721URIStorageUpgradeable, AccessControlUpgradeabl
247245
/// @param nftMetadataURI OPTIONAL. The URI of the desired metadata for the newly minted NFT.
248246
/// @param nftMetadataHash OPTIONAL. A bytes32 hash of the NFT's metadata.
249247
/// This metadata is accessible via the NFT's tokenURI.
250-
/// @param dedup Set to true to enable checking for duplicate metadata hashes.
251-
/// If a duplicate is found, the function will return the existing token ID instead of minting a new one.
248+
/// @param allowDuplicates Set to true to allow minting an NFT with a duplicate metadata hash.
252249
/// @return tokenId The token ID of the minted NFT with the given metadata hash.
253-
/// @return deduped true if dedup is enabled and the metadata hash is already used, false otherwise.
254250
function mintByPeriphery(
255251
address to,
256252
address payer,
257253
string calldata nftMetadataURI,
258254
bytes32 nftMetadataHash,
259-
bool dedup
260-
) public virtual onlyPeriphery returns (uint256 tokenId, bool deduped) {
261-
(tokenId, deduped) = _mintToken({
255+
bool allowDuplicates
256+
) public virtual onlyPeriphery returns (uint256 tokenId) {
257+
tokenId = _mintToken({
262258
to: to,
263259
payer: payer,
264260
nftMetadataURI: nftMetadataURI,
265261
nftMetadataHash: nftMetadataHash,
266-
dedup: dedup
262+
allowDuplicates: allowDuplicates
267263
});
268264
}
269265

@@ -287,24 +283,26 @@ contract SPGNFT is ISPGNFT, ERC721URIStorageUpgradeable, AccessControlUpgradeabl
287283
/// @param nftMetadataURI OPTIONAL. The URI of the desired metadata for the newly minted NFT.
288284
/// @param nftMetadataHash OPTIONAL. A bytes32 hash of the NFT's metadata.
289285
/// This metadata is accessible via the NFT's tokenURI.
290-
/// @param dedup Set to true to enable checking for duplicate metadata hashes.
291-
/// If a duplicate is found, the function will return the existing token ID instead of minting a new one.
286+
/// @param allowDuplicates Set to true to allow minting an NFT with a duplicate metadata hash.
292287
/// @return tokenId The token ID of the minted NFT with the given metadata hash.
293-
/// @return deduped true if dedup is enabled and the metadata hash is already used, false otherwise.
294288
function _mintToken(
295289
address to,
296290
address payer,
297291
string calldata nftMetadataURI,
298292
bytes32 nftMetadataHash,
299-
bool dedup
300-
) internal returns (uint256 tokenId, bool deduped) {
293+
bool allowDuplicates
294+
) internal returns (uint256 tokenId) {
301295
SPGNFTStorage storage $ = _getSPGNFTStorage();
302296
if (!$._mintOpen) revert Errors.SPGNFT__MintingClosed();
303297
if ($._totalSupply + 1 > $._maxSupply) revert Errors.SPGNFT__MaxSupplyReached();
304298

305299
tokenId = $._nftMetadataHashToTokenId[nftMetadataHash];
306-
if (dedup && tokenId != 0) {
307-
return (tokenId, true);
300+
if (!allowDuplicates && tokenId != 0) {
301+
revert Errors.SPGNFT__DuplicatedNFTMetadataHash({
302+
spgNftContract: address(this),
303+
tokenId: tokenId,
304+
nftMetadataHash: nftMetadataHash
305+
});
308306
}
309307

310308
if ($._mintFeeToken != address(0) && $._mintFee > 0) {
@@ -320,8 +318,6 @@ contract SPGNFT is ISPGNFT, ERC721URIStorageUpgradeable, AccessControlUpgradeabl
320318
_mint(to, tokenId);
321319

322320
if (bytes(nftMetadataURI).length > 0) _setTokenURI(tokenId, nftMetadataURI);
323-
324-
return (tokenId, false);
325321
}
326322

327323
/// @dev Base URI for computing tokenURI.

contracts/interfaces/ISPGNFT.sol

+6-10
Original file line numberDiff line numberDiff line change
@@ -114,34 +114,30 @@ interface ISPGNFT is IAccessControl, IERC721Metadata, IERC7572 {
114114
/// @param nftMetadataURI OPTIONAL. The desired metadata for the newly minted NFT.
115115
/// @param nftMetadataHash OPTIONAL. A bytes32 hash of the NFT's metadata.
116116
/// This metadata is accessible via the NFT's tokenURI.
117-
/// @param dedup Set to true to enable checking for duplicate metadata hashes.
118-
/// If a duplicate is found, the function will return the existing token ID instead of minting a new one.
117+
/// @param allowDuplicates Set to true to allow minting an NFT with a duplicate metadata hash.
119118
/// @return tokenId The token ID of the minted NFT with the given metadata hash.
120-
/// @return deduped true if dedup is enabled and the metadata hash is already used, false otherwise.
121119
function mint(
122120
address to,
123121
string calldata nftMetadataURI,
124122
bytes32 nftMetadataHash,
125-
bool dedup
126-
) external returns (uint256 tokenId, bool deduped);
123+
bool allowDuplicates
124+
) external returns (uint256 tokenId);
127125

128126
/// @notice Mints an NFT from the collection. Only callable by Periphery contracts.
129127
/// @param to The address of the recipient of the minted NFT.
130128
/// @param payer The address of the payer for the mint fee.
131129
/// @param nftMetadataURI OPTIONAL. The desired metadata for the newly minted NFT.
132130
/// @param nftMetadataHash OPTIONAL. A bytes32 hash of the NFT's metadata.
133131
/// This metadata is accessible via the NFT's tokenURI.
134-
/// @param dedup Set to true to enable checking for duplicate metadata hashes.
135-
/// If a duplicate is found, the function will return the existing token ID instead of minting a new one.
132+
/// @param allowDuplicates Set to true to allow minting an NFT with a duplicate metadata hash.
136133
/// @return tokenId The token ID of the minted NFT with the given metadata hash.
137-
/// @return deduped true if dedup is enabled and the metadata hash is already used, false otherwise.
138134
function mintByPeriphery(
139135
address to,
140136
address payer,
141137
string calldata nftMetadataURI,
142138
bytes32 nftMetadataHash,
143-
bool dedup
144-
) external returns (uint256 tokenId, bool deduped);
139+
bool allowDuplicates
140+
) external returns (uint256 tokenId);
145141

146142
/// @dev Withdraws the contract's token balance to the fee recipient.
147143
/// @param token The token to withdraw.

contracts/interfaces/workflows/IDerivativeWorkflows.sol

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ interface IDerivativeWorkflows {
1212
/// @param derivData The derivative data to be used for registerDerivative.
1313
/// @param ipMetadata OPTIONAL. The desired metadata for the newly minted NFT and registered IP.
1414
/// @param recipient The address to receive the minted NFT.
15-
/// @param dedup Set to true to enable checking for duplicate metadata hashes in the SPGNFT collection.
15+
/// @param allowDuplicates Set to true to allow minting an NFT with a duplicate metadata hash.
1616
/// @return ipId The ID of the newly registered IP.
1717
/// @return tokenId The ID of the newly minted NFT.
1818
function mintAndRegisterIpAndMakeDerivative(
1919
address spgNftContract,
2020
WorkflowStructs.MakeDerivative calldata derivData,
2121
WorkflowStructs.IPMetadata calldata ipMetadata,
2222
address recipient,
23-
bool dedup
23+
bool allowDuplicates
2424
) external returns (address ipId, uint256 tokenId);
2525

2626
/// @notice Register the given NFT as a derivative IP with metadata without license tokens.
@@ -48,7 +48,7 @@ interface IDerivativeWorkflows {
4848
/// @param royaltyContext The context for royalty module, should be empty for Royalty Policy LAP.
4949
/// @param ipMetadata OPTIONAL. The desired metadata for the newly minted NFT and registered IP.
5050
/// @param recipient The address to receive the minted NFT.
51-
/// @param dedup Set to true to enable checking for duplicate metadata hashes in the SPGNFT collection.
51+
/// @param allowDuplicates Set to true to allow minting an NFT with a duplicate metadata hash.
5252
/// @return ipId The ID of the newly registered IP.
5353
/// @return tokenId The ID of the newly minted NFT.
5454
function mintAndRegisterIpAndMakeDerivativeWithLicenseTokens(
@@ -57,7 +57,7 @@ interface IDerivativeWorkflows {
5757
bytes calldata royaltyContext,
5858
WorkflowStructs.IPMetadata calldata ipMetadata,
5959
address recipient,
60-
bool dedup
60+
bool allowDuplicates
6161
) external returns (address ipId, uint256 tokenId);
6262

6363
/// @notice Register the given NFT as a derivative IP using license tokens.

contracts/interfaces/workflows/IGroupingWorkflows.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface IGroupingWorkflows {
1616
/// @param licenseTermsId The ID of the registered license terms that will be attached to the new IP.
1717
/// @param ipMetadata OPTIONAL. The desired metadata for the newly minted NFT and registered IP.
1818
/// @param sigAddToGroup Signature data for addIp to the group IP via the Grouping Module.
19-
/// @param dedup Set to true to enable checking for duplicate metadata hashes in the SPGNFT collection.
19+
/// @param allowDuplicates Set to true to allow minting an NFT with a duplicate metadata hash.
2020
/// @return ipId The ID of the newly registered IP.
2121
/// @return tokenId The ID of the newly minted NFT.
2222
function mintAndRegisterIpAndAttachLicenseAndAddToGroup(
@@ -27,7 +27,7 @@ interface IGroupingWorkflows {
2727
uint256 licenseTermsId,
2828
WorkflowStructs.IPMetadata calldata ipMetadata,
2929
WorkflowStructs.SignatureData calldata sigAddToGroup,
30-
bool dedup
30+
bool allowDuplicates
3131
) external returns (address ipId, uint256 tokenId);
3232

3333
/// @notice Register an NFT as IP with metadata, attach license terms to the registered IP,

contracts/interfaces/workflows/ILicenseAttachmentWorkflows.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ interface ILicenseAttachmentWorkflows {
2727
/// @param recipient The address of the recipient of the minted NFT.
2828
/// @param ipMetadata OPTIONAL. The desired metadata for the newly minted NFT and registered IP.
2929
/// @param terms The PIL terms to be registered.
30-
/// @param dedup Set to true to enable checking for duplicate metadata hashes in the SPGNFT collection.
30+
/// @param allowDuplicates Set to true to allow minting an NFT with a duplicate metadata hash.
3131
/// @return ipId The ID of the newly registered IP.
3232
/// @return tokenId The ID of the newly minted NFT.
3333
/// @return licenseTermsId The ID of the newly registered PIL terms.
@@ -36,7 +36,7 @@ interface ILicenseAttachmentWorkflows {
3636
address recipient,
3737
WorkflowStructs.IPMetadata calldata ipMetadata,
3838
PILTerms calldata terms,
39-
bool dedup
39+
bool allowDuplicates
4040
) external returns (address ipId, uint256 tokenId, uint256 licenseTermsId);
4141

4242
/// @notice Register a given NFT as an IP and attach Programmable IP License Terms.

contracts/interfaces/workflows/IRegistrationWorkflows.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ interface IRegistrationWorkflows {
2121
/// @param spgNftContract The address of the SPGNFT collection.
2222
/// @param recipient The address of the recipient of the minted NFT.
2323
/// @param ipMetadata OPTIONAL. The desired metadata for the newly minted NFT and registered IP.
24-
/// @param dedup Set to true to enable checking for duplicate metadata hashes in the SPGNFT collection.
24+
/// @param allowDuplicates Set to true to allow minting an NFT with a duplicate metadata hash.
2525
/// If a duplicate is found, returns existing token Id and IP Id instead of minting/registering a new one.
2626
/// @return ipId The ID of the registered IP.
2727
/// @return tokenId The ID of the newly minted NFT.
2828
function mintAndRegisterIp(
2929
address spgNftContract,
3030
address recipient,
3131
WorkflowStructs.IPMetadata calldata ipMetadata,
32-
bool dedup
32+
bool allowDuplicates
3333
) external returns (address ipId, uint256 tokenId);
3434

3535
/// @notice Registers an NFT as IP with metadata.

contracts/lib/Errors.sol

+6-48
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,13 @@ library Errors {
1414
/// @notice Zero address provided as a param to the RegistrationWorkflows.
1515
error RegistrationWorkflows__ZeroAddressParam();
1616

17-
/// @notice Error thrown when attempting to mint an NFT with a metadata hash that already exists.
18-
/// @param spgNftContract The address of the SPGNFT collection contract where the duplicate was detected.
19-
/// @param tokenId The ID of the original NFT that was first minted with this metadata hash.
20-
/// @param ipId The identifier of the registered IP associated with this NFT.
21-
/// @param nftMetadataHash The hash of the NFT metadata that caused the duplication error.
22-
error RegistrationWorkflows__DuplicatedNFTMetadataHash(
23-
address spgNftContract,
24-
uint256 tokenId,
25-
address ipId,
26-
bytes32 nftMetadataHash
27-
);
28-
2917
////////////////////////////////////////////////////////////////////////////
3018
// LicenseAttachmentWorkflows //
3119
////////////////////////////////////////////////////////////////////////////
3220

3321
/// @notice Zero address provided as a param to the LicenseAttachmentWorkflows.
3422
error LicenseAttachmentWorkflows__ZeroAddressParam();
3523

36-
/// @notice Error thrown when attempting to mint an NFT with a metadata hash that already exists.
37-
/// @param spgNftContract The address of the SPGNFT collection contract where the duplicate was detected.
38-
/// @param tokenId The ID of the original NFT that was first minted with this metadata hash.
39-
/// @param ipId The identifier of the registered IP associated with this NFT.
40-
/// @param nftMetadataHash The hash of the NFT metadata that caused the duplication error.
41-
error LicenseAttachmentWorkflows__DuplicatedNFTMetadataHash(
42-
address spgNftContract,
43-
uint256 tokenId,
44-
address ipId,
45-
bytes32 nftMetadataHash
46-
);
47-
4824
////////////////////////////////////////////////////////////////////////////
4925
// DerivativeWorkflows //
5026
////////////////////////////////////////////////////////////////////////////
@@ -58,37 +34,13 @@ library Errors {
5834
/// @notice Caller is not the owner of the license token.
5935
error DerivativeWorkflows__CallerAndNotTokenOwner(uint256 tokenId, address caller, address actualTokenOwner);
6036

61-
/// @notice Error thrown when attempting to mint an NFT with a metadata hash that already exists.
62-
/// @param spgNftContract The address of the SPGNFT collection contract where the duplicate was detected.
63-
/// @param tokenId The ID of the original NFT that was first minted with this metadata hash.
64-
/// @param ipId The identifier of the registered IP associated with this NFT.
65-
/// @param nftMetadataHash The hash of the NFT metadata that caused the duplication error.
66-
error DerivativeWorkflows__DuplicatedNFTMetadataHash(
67-
address spgNftContract,
68-
uint256 tokenId,
69-
address ipId,
70-
bytes32 nftMetadataHash
71-
);
72-
7337
////////////////////////////////////////////////////////////////////////////
7438
// Grouping Workflows //
7539
////////////////////////////////////////////////////////////////////////////
7640

7741
/// @notice Zero address provided as a param to the GroupingWorkflows.
7842
error GroupingWorkflows__ZeroAddressParam();
7943

80-
/// @notice Error thrown when attempting to mint an NFT with a metadata hash that already exists.
81-
/// @param spgNftContract The address of the SPGNFT collection contract where the duplicate was detected.
82-
/// @param tokenId The ID of the original NFT that was first minted with this metadata hash.
83-
/// @param ipId The identifier of the registered IP associated with this NFT.
84-
/// @param nftMetadataHash The hash of the NFT metadata that caused the duplication error.
85-
error GroupingWorkflows__DuplicatedNFTMetadataHash(
86-
address spgNftContract,
87-
uint256 tokenId,
88-
address ipId,
89-
bytes32 nftMetadataHash
90-
);
91-
9244
////////////////////////////////////////////////////////////////////////////
9345
// Royalty Workflows //
9446
////////////////////////////////////////////////////////////////////////////
@@ -119,4 +71,10 @@ library Errors {
11971

12072
/// @notice Caller is not one of the periphery contracts.
12173
error SPGNFT__CallerNotPeripheryContract();
74+
75+
/// @notice Error thrown when attempting to mint an NFT with a metadata hash that already exists.
76+
/// @param spgNftContract The address of the SPGNFT collection contract where the duplicate was detected.
77+
/// @param tokenId The ID of the original NFT that was first minted with this metadata hash.
78+
/// @param nftMetadataHash The hash of the NFT metadata that caused the duplication error.
79+
error SPGNFT__DuplicatedNFTMetadataHash(address spgNftContract, uint256 tokenId, bytes32 nftMetadataHash);
12280
}

0 commit comments

Comments
 (0)