Skip to content

Commit 86d2ddd

Browse files
committed
fix(grouping): fix stack too deep
1 parent 9c827e7 commit 86d2ddd

File tree

5 files changed

+178
-195
lines changed

5 files changed

+178
-195
lines changed

contracts/interfaces/workflows/IGroupingWorkflows.sol

+8-18
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ interface IGroupingWorkflows {
1212
/// @param spgNftContract The address of the SPGNFT collection.
1313
/// @param groupId The ID of the group IP to add the newly registered IP.
1414
/// @param recipient The address of the recipient of the minted NFT.
15-
/// @param licenseTemplates The addresses of the license templates to be attached to the new IP.
16-
/// @param licenseTermsIds The IDs of the registered license terms that will be attached to the new IP.
17-
/// The i th license terms ID must be a valid license terms that was registered in the i th license template.
15+
/// @param licenseTermsInfo The information of the license terms that will be attached to the new IP.
1816
/// @param ipMetadata OPTIONAL. The desired metadata for the newly minted NFT and registered IP.
1917
/// @param sigAddToGroup Signature data for addIp to the group IP via the Grouping Module.
2018
/// @param allowDuplicates Set to true to allow minting an NFT with a duplicate metadata hash.
@@ -24,8 +22,7 @@ interface IGroupingWorkflows {
2422
address spgNftContract,
2523
address groupId,
2624
address recipient,
27-
address[] calldata licenseTemplates,
28-
uint256[] calldata licenseTermsIds,
25+
WorkflowStructs.LicenseTermsInfo[] calldata licenseTermsInfo,
2926
WorkflowStructs.IPMetadata calldata ipMetadata,
3027
WorkflowStructs.SignatureData calldata sigAddToGroup,
3128
bool allowDuplicates
@@ -36,9 +33,7 @@ interface IGroupingWorkflows {
3633
/// @param nftContract The address of the NFT collection.
3734
/// @param tokenId The ID of the NFT.
3835
/// @param groupId The ID of the group IP to add the newly registered IP.
39-
/// @param licenseTemplates The addresses of the license templates to be attached to the new IP.
40-
/// @param licenseTermsIds The IDs of the registered license terms that will be attached to the new IP.
41-
/// The i th license terms ID must be a valid license terms that was registered in the i th license template.
36+
/// @param licenseTermsInfo The information of the license terms that will be attached to the new IP.
4237
/// @param ipMetadata OPTIONAL. The desired metadata for the newly registered IP.
4338
/// @param sigMetadata OPTIONAL. Signature data for setAll (metadata).
4439
/// @param sigsAttach Signature data for attachLicenseTerms to the IP via the Licensing Module.
@@ -50,8 +45,7 @@ interface IGroupingWorkflows {
5045
address nftContract,
5146
uint256 tokenId,
5247
address groupId,
53-
address[] calldata licenseTemplates,
54-
uint256[] calldata licenseTermsIds,
48+
WorkflowStructs.LicenseTermsInfo[] calldata licenseTermsInfo,
5549
WorkflowStructs.IPMetadata calldata ipMetadata,
5650
WorkflowStructs.SignatureData calldata sigMetadata,
5751
WorkflowStructs.SignatureData[] calldata sigsAttach,
@@ -60,28 +54,24 @@ interface IGroupingWorkflows {
6054

6155
/// @notice Register a group IP with a group reward pool and attach license terms to the group IP
6256
/// @param groupPool The address of the group reward pool.
63-
/// @param licenseTemplate The address of the license template to be attached to the new group IP.
64-
/// @param licenseTermsId The ID of the registered license terms that will be attached to the new group IP.
57+
/// @param licenseTermsInfo The information of the license terms that will be attached to the new group IP.
6558
/// @return groupId The ID of the newly registered group IP.
6659
function registerGroupAndAttachLicense(
6760
address groupPool,
68-
address licenseTemplate,
69-
uint256 licenseTermsId
61+
WorkflowStructs.LicenseTermsInfo calldata licenseTermsInfo
7062
) external returns (address groupId);
7163

7264
/// @notice Register a group IP with a group reward pool, attach license terms to the group IP,
7365
/// and add individual IPs to the group IP.
7466
/// @dev ipIds must be have the same license terms as the group IP.
7567
/// @param groupPool The address of the group reward pool.
7668
/// @param ipIds The IDs of the IPs to add to the newly registered group IP.
77-
/// @param licenseTemplate The address of the license template to be attached to the new group IP.
78-
/// @param licenseTermsId The ID of the registered license terms that will be attached to the new group IP.
69+
/// @param licenseTermsInfo The information of the license terms that will be attached to the new group IP.
7970
/// @return groupId The ID of the newly registered group IP.
8071
function registerGroupAndAttachLicenseAndAddIps(
8172
address groupPool,
8273
address[] calldata ipIds,
83-
address licenseTemplate,
84-
uint256 licenseTermsId
74+
WorkflowStructs.LicenseTermsInfo calldata licenseTermsInfo
8575
) external returns (address groupId);
8676

8777
/// @notice Collect royalties for the entire group and distribute the rewards to each member IP's royalty vault

contracts/lib/WorkflowStructs.sol

+8
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,12 @@ library WorkflowStructs {
4040
bytes royaltyContext;
4141
uint256 maxMintingFee;
4242
}
43+
44+
/// @notice Struct for license terms information.
45+
/// @param licenseTemplate The address of the license template.
46+
/// @param licenseTermsId The ID of the license terms which was registered in the license template.
47+
struct LicenseTermsInfo {
48+
address licenseTemplate;
49+
uint256 licenseTermsId;
50+
}
4351
}

contracts/workflows/GroupingWorkflows.sol

+26-34
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,7 @@ contract GroupingWorkflows is
118118
/// @param spgNftContract The address of the SPGNFT collection.
119119
/// @param groupId The ID of the group IP to add the newly registered IP.
120120
/// @param recipient The address of the recipient of the minted NFT.
121-
/// @param licenseTemplates The addresses of the license templates to be attached to the new IP.
122-
/// @param licenseTermsIds The IDs of the registered license terms that will be attached to the new IP.
123-
/// The i th license terms ID must be a valid license terms that was registered in the i th license template.
121+
/// @param licenseTermsInfo The information of the license terms that will be attached to the new IP.
124122
/// @param ipMetadata OPTIONAL. The desired metadata for the newly minted NFT and registered IP.
125123
/// @param sigAddToGroup Signature data for addIp to the group IP via the Grouping Module.
126124
/// @param allowDuplicates Set to true to allow minting an NFT with a duplicate metadata hash.
@@ -130,8 +128,7 @@ contract GroupingWorkflows is
130128
address spgNftContract,
131129
address groupId,
132130
address recipient,
133-
address[] calldata licenseTemplates,
134-
uint256[] calldata licenseTermsIds,
131+
WorkflowStructs.LicenseTermsInfo[] calldata licenseTermsInfo,
135132
WorkflowStructs.IPMetadata calldata ipMetadata,
136133
WorkflowStructs.SignatureData calldata sigAddToGroup,
137134
bool allowDuplicates
@@ -148,12 +145,12 @@ contract GroupingWorkflows is
148145
MetadataHelper.setMetadata(ipId, address(CORE_METADATA_MODULE), ipMetadata);
149146

150147
// attach license terms to the IP, do nothing if already attached
151-
for (uint256 i = 0; i < licenseTermsIds.length; i++) {
148+
for (uint256 i = 0; i < licenseTermsInfo.length; i++) {
152149
LicensingHelper.attachLicenseTerms(
153150
ipId,
154151
address(LICENSING_MODULE),
155-
licenseTemplates[i],
156-
licenseTermsIds[i]
152+
licenseTermsInfo[i].licenseTemplate,
153+
licenseTermsInfo[i].licenseTermsId
157154
);
158155
}
159156

@@ -189,9 +186,7 @@ contract GroupingWorkflows is
189186
/// @param nftContract The address of the NFT collection.
190187
/// @param tokenId The ID of the NFT.
191188
/// @param groupId The ID of the group IP to add the newly registered IP.
192-
/// @param licenseTemplates The addresses of the license templates to be attached to the new IP.
193-
/// @param licenseTermsIds The IDs of the registered license terms that will be attached to the new IP.
194-
/// The i th license terms ID must be a valid license terms that was registered in the i th license template.
189+
/// @param licenseTermsInfo The information of the license terms that will be attached to the new IP.
195190
/// @param ipMetadata OPTIONAL. The desired metadata for the newly registered IP.
196191
/// @param sigMetadata OPTIONAL. Signature data for setAll (metadata) for the IP via the Core Metadata Module.
197192
/// @param sigsAttach Signature data for attachLicenseTerms to the IP via the Licensing Module.
@@ -203,31 +198,22 @@ contract GroupingWorkflows is
203198
address nftContract,
204199
uint256 tokenId,
205200
address groupId,
206-
address[] calldata licenseTemplates,
207-
uint256[] calldata licenseTermsIds,
201+
WorkflowStructs.LicenseTermsInfo[] calldata licenseTermsInfo,
208202
WorkflowStructs.IPMetadata calldata ipMetadata,
209203
WorkflowStructs.SignatureData calldata sigMetadata,
210204
WorkflowStructs.SignatureData[] calldata sigsAttach,
211205
WorkflowStructs.SignatureData calldata sigAddToGroup
212206
) external returns (address ipId) {
213207
ipId = IP_ASSET_REGISTRY.register(block.chainid, nftContract, tokenId);
214-
215-
address[] memory modules = new address[](2);
216-
bytes4[] memory selectors = new bytes4[](2);
217-
modules[0] = address(CORE_METADATA_MODULE);
218-
modules[1] = address(LICENSING_MODULE);
219-
selectors[0] = ICoreMetadataModule.setAll.selector;
220-
selectors[1] = ILicensingModule.attachLicenseTerms.selector;
221-
222208
MetadataHelper.setMetadataWithSig(ipId, address(CORE_METADATA_MODULE), ipMetadata, sigMetadata);
223209

224210
// attach license terms to the IP, do nothing if already attached
225-
for (uint256 i = 0; i < licenseTermsIds.length; i++) {
211+
for (uint256 i = 0; i < licenseTermsInfo.length; i++) {
226212
LicensingHelper.attachLicenseTermsWithSig(
227213
ipId,
228214
address(LICENSING_MODULE),
229-
licenseTemplates[i],
230-
licenseTermsIds[i],
215+
licenseTermsInfo[i].licenseTemplate,
216+
licenseTermsInfo[i].licenseTermsId,
231217
sigsAttach[i]
232218
);
233219
}
@@ -249,18 +235,21 @@ contract GroupingWorkflows is
249235

250236
/// @notice Register a group IP with a group reward pool and attach license terms to the group IP
251237
/// @param groupPool The address of the group reward pool.
252-
/// @param licenseTemplate The address of the license template to be attached to the new group IP.
253-
/// @param licenseTermsId The ID of the registered license terms that will be attached to the new group IP.
238+
/// @param licenseTermsInfo The information of the license terms that will be attached to the new group IP.
254239
/// @return groupId The ID of the newly registered group IP.
255240
function registerGroupAndAttachLicense(
256241
address groupPool,
257-
address licenseTemplate,
258-
uint256 licenseTermsId
242+
WorkflowStructs.LicenseTermsInfo calldata licenseTermsInfo
259243
) external returns (address groupId) {
260244
groupId = GROUPING_MODULE.registerGroup(groupPool);
261245

262246
// attach license terms to the group IP, do nothing if already attached
263-
LicensingHelper.attachLicenseTerms(groupId, address(LICENSING_MODULE), licenseTemplate, licenseTermsId);
247+
LicensingHelper.attachLicenseTerms(
248+
groupId,
249+
address(LICENSING_MODULE),
250+
licenseTermsInfo.licenseTemplate,
251+
licenseTermsInfo.licenseTermsId
252+
);
264253

265254
GROUP_NFT.safeTransferFrom(address(this), msg.sender, GROUP_NFT.totalSupply() - 1);
266255
}
@@ -270,19 +259,22 @@ contract GroupingWorkflows is
270259
/// @dev ipIds must have the same PIL terms as the group IP.
271260
/// @param groupPool The address of the group reward pool.
272261
/// @param ipIds The IDs of the IPs to add to the newly registered group IP.
273-
/// @param licenseTemplate The address of the license template to be attached to the new group IP.
274-
/// @param licenseTermsId The ID of the registered license terms that will be attached to the new group IP.
262+
/// @param licenseTermsInfo The information of the license terms that will be attached to the new group IP.
275263
/// @return groupId The ID of the newly registered group IP.
276264
function registerGroupAndAttachLicenseAndAddIps(
277265
address groupPool,
278266
address[] calldata ipIds,
279-
address licenseTemplate,
280-
uint256 licenseTermsId
267+
WorkflowStructs.LicenseTermsInfo calldata licenseTermsInfo
281268
) external returns (address groupId) {
282269
groupId = GROUPING_MODULE.registerGroup(groupPool);
283270

284271
// attach license terms to the group IP, do nothing if already attached
285-
LicensingHelper.attachLicenseTerms(groupId, address(LICENSING_MODULE), licenseTemplate, licenseTermsId);
272+
LicensingHelper.attachLicenseTerms(
273+
groupId,
274+
address(LICENSING_MODULE),
275+
licenseTermsInfo.licenseTemplate,
276+
licenseTermsInfo.licenseTermsId
277+
);
286278

287279
GROUPING_MODULE.addIp(groupId, ipIds);
288280

0 commit comments

Comments
 (0)