Skip to content

Commit bdb63d1

Browse files
committed
fix(grouping): make license attachment idempotent
1 parent 44a4aa7 commit bdb63d1

File tree

2 files changed

+45
-7
lines changed

2 files changed

+45
-7
lines changed

contracts/GroupingWorkflows.sol

+25-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { Errors } from "./lib/Errors.sol";
1717
import { BaseWorkflow } from "./BaseWorkflow.sol";
1818
import { ISPGNFT } from "./interfaces/ISPGNFT.sol";
1919
import { MetadataHelper } from "./lib/MetadataHelper.sol";
20+
import { LicensingHelper } from "./lib/LicensingHelper.sol";
2021
import { PermissionHelper } from "./lib/PermissionHelper.sol";
2122
import { IGroupingWorkflows } from "./interfaces/IGroupingWorkflows.sol";
2223
import { IStoryProtocolGateway as ISPG } from "./interfaces/IStoryProtocolGateway.sol";
@@ -132,7 +133,14 @@ contract GroupingWorkflows is
132133
ipId = IP_ASSET_REGISTRY.register(block.chainid, spgNftContract, tokenId);
133134
MetadataHelper.setMetadata(ipId, address(CORE_METADATA_MODULE), ipMetadata);
134135

135-
LICENSING_MODULE.attachLicenseTerms(ipId, licenseTemplate, licenseTermsId);
136+
// attach license terms to the IP, do nothing if already attached
137+
LicensingHelper.attachLicenseTerms(
138+
ipId,
139+
address(LICENSING_MODULE),
140+
address(LICENSE_REGISTRY),
141+
licenseTemplate,
142+
licenseTermsId
143+
);
136144

137145
PermissionHelper.setPermissionForModule(
138146
groupId,
@@ -190,7 +198,14 @@ contract GroupingWorkflows is
190198

191199
MetadataHelper.setMetadata(ipId, address(CORE_METADATA_MODULE), ipMetadata);
192200

193-
LICENSING_MODULE.attachLicenseTerms(ipId, licenseTemplate, licenseTermsId);
201+
// attach license terms to the IP, do nothing if already attached
202+
LicensingHelper.attachLicenseTerms(
203+
ipId,
204+
address(LICENSING_MODULE),
205+
address(LICENSE_REGISTRY),
206+
licenseTemplate,
207+
licenseTermsId
208+
);
194209

195210
PermissionHelper.setPermissionForModule(
196211
groupId,
@@ -221,7 +236,14 @@ contract GroupingWorkflows is
221236
) external returns (address groupId) {
222237
groupId = GROUPING_MODULE.registerGroup(groupPool);
223238

224-
LICENSING_MODULE.attachLicenseTerms(groupId, licenseTemplate, licenseTermsId);
239+
// attach license terms to the group IP, do nothing if already attached
240+
LicensingHelper.attachLicenseTerms(
241+
groupId,
242+
address(LICENSING_MODULE),
243+
address(LICENSE_REGISTRY),
244+
licenseTemplate,
245+
licenseTermsId
246+
);
225247

226248
GROUPING_MODULE.addIp(groupId, ipIds);
227249

contracts/lib/LicensingHelper.sol

+20-4
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,27 @@ library LicensingHelper {
3535
) internal returns (uint256 licenseTermsId) {
3636
licenseTermsId = IPILicenseTemplate(pilTemplate).registerLicenseTerms(terms);
3737

38-
// Returns the license terms ID if already attached.
39-
if (ILicenseRegistry(licenseRegistry).hasIpAttachedLicenseTerms(ipId, pilTemplate, licenseTermsId))
40-
return licenseTermsId;
38+
attachLicenseTerms(ipId, licensingModule, licenseRegistry, pilTemplate, licenseTermsId);
39+
}
40+
41+
/// @dev Attaches license terms to the given IP.
42+
/// @param ipId The ID of the IP.
43+
/// @param licensingModule The address of the Licensing Module.
44+
/// @param licenseRegistry The address of the License Registry.
45+
/// @param licenseTemplate The address of the license template.
46+
/// @param licenseTermsId The ID of the license terms to be attached.
47+
function attachLicenseTerms(
48+
address ipId,
49+
address licensingModule,
50+
address licenseRegistry,
51+
address licenseTemplate,
52+
uint256 licenseTermsId
53+
) internal {
54+
// Returns if license terms are already attached.
55+
if (ILicenseRegistry(licenseRegistry).hasIpAttachedLicenseTerms(ipId, licenseTemplate, licenseTermsId))
56+
return;
4157

42-
ILicensingModule(licensingModule).attachLicenseTerms(ipId, pilTemplate, licenseTermsId);
58+
ILicensingModule(licensingModule).attachLicenseTerms(ipId, licenseTemplate, licenseTermsId);
4359
}
4460

4561
/// @dev Collects license tokens from the caller. Assumes the periphery contract has permission to transfer the license tokens.

0 commit comments

Comments
 (0)