Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(grouping): make license attachment idempotent #59

Merged
merged 3 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions contracts/GroupingWorkflows.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Errors } from "./lib/Errors.sol";
import { BaseWorkflow } from "./BaseWorkflow.sol";
import { ISPGNFT } from "./interfaces/ISPGNFT.sol";
import { MetadataHelper } from "./lib/MetadataHelper.sol";
import { LicensingHelper } from "./lib/LicensingHelper.sol";
import { PermissionHelper } from "./lib/PermissionHelper.sol";
import { IGroupingWorkflows } from "./interfaces/IGroupingWorkflows.sol";
import { IStoryProtocolGateway as ISPG } from "./interfaces/IStoryProtocolGateway.sol";
Expand Down Expand Up @@ -132,7 +133,14 @@ contract GroupingWorkflows is
ipId = IP_ASSET_REGISTRY.register(block.chainid, spgNftContract, tokenId);
MetadataHelper.setMetadata(ipId, address(CORE_METADATA_MODULE), ipMetadata);

LICENSING_MODULE.attachLicenseTerms(ipId, licenseTemplate, licenseTermsId);
// attach license terms to the IP, do nothing if already attached
LicensingHelper.attachLicenseTerms(
ipId,
address(LICENSING_MODULE),
address(LICENSE_REGISTRY),
licenseTemplate,
licenseTermsId
);

PermissionHelper.setPermissionForModule(
groupId,
Expand Down Expand Up @@ -190,7 +198,14 @@ contract GroupingWorkflows is

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

LICENSING_MODULE.attachLicenseTerms(ipId, licenseTemplate, licenseTermsId);
// attach license terms to the IP, do nothing if already attached
LicensingHelper.attachLicenseTerms(
ipId,
address(LICENSING_MODULE),
address(LICENSE_REGISTRY),
licenseTemplate,
licenseTermsId
);

PermissionHelper.setPermissionForModule(
groupId,
Expand Down Expand Up @@ -221,7 +236,14 @@ contract GroupingWorkflows is
) external returns (address groupId) {
groupId = GROUPING_MODULE.registerGroup(groupPool);

LICENSING_MODULE.attachLicenseTerms(groupId, licenseTemplate, licenseTermsId);
// attach license terms to the group IP, do nothing if already attached
LicensingHelper.attachLicenseTerms(
groupId,
address(LICENSING_MODULE),
address(LICENSE_REGISTRY),
licenseTemplate,
licenseTermsId
);

GROUPING_MODULE.addIp(groupId, ipIds);

Expand Down
24 changes: 20 additions & 4 deletions contracts/lib/LicensingHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,27 @@ library LicensingHelper {
) internal returns (uint256 licenseTermsId) {
licenseTermsId = IPILicenseTemplate(pilTemplate).registerLicenseTerms(terms);

// Returns the license terms ID if already attached.
if (ILicenseRegistry(licenseRegistry).hasIpAttachedLicenseTerms(ipId, pilTemplate, licenseTermsId))
return licenseTermsId;
attachLicenseTerms(ipId, licensingModule, licenseRegistry, pilTemplate, licenseTermsId);
}

/// @dev Attaches license terms to the given IP.
/// @param ipId The ID of the IP.
/// @param licensingModule The address of the Licensing Module.
/// @param licenseRegistry The address of the License Registry.
/// @param licenseTemplate The address of the license template.
/// @param licenseTermsId The ID of the license terms to be attached.
function attachLicenseTerms(
address ipId,
address licensingModule,
address licenseRegistry,
address licenseTemplate,
uint256 licenseTermsId
) internal {
// Returns if license terms are already attached.
if (ILicenseRegistry(licenseRegistry).hasIpAttachedLicenseTerms(ipId, licenseTemplate, licenseTermsId))
return;

ILicensingModule(licensingModule).attachLicenseTerms(ipId, pilTemplate, licenseTermsId);
ILicensingModule(licensingModule).attachLicenseTerms(ipId, licenseTemplate, licenseTermsId);
sebsadface marked this conversation as resolved.
Show resolved Hide resolved
}

/// @dev Collects license tokens from the caller. Assumes the periphery contract has permission to transfer the license tokens.
Expand Down
8 changes: 6 additions & 2 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
src = 'contracts'
out = 'out'
libs = ['node_modules', 'lib']
cache_path = 'forge-cache'
cache_path = 'forge-cache'
gas_reports = ["*"]
optimizer = true
optimizer_runs = 20000
test = 'test'
solc = '0.8.23'
fs_permissions = [{ access = 'read', path = './' }, { access = 'read-write', path = './deploy-out' }]
fs_permissions = [
{ access = 'read', path = './' },
{ access = 'read-write', path = './deploy-out' },
]
evm_version = 'cancun'

[rpc_endpoints]
# Comment out for local development (testing requires 0xSplit forks — will add Mock soon)
Expand Down
4 changes: 2 additions & 2 deletions remappings.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@openzeppelin/=node_modules/@openzeppelin/
@openzeppelin-foundry-upgrades/=lib/openzeppelin-foundry-upgrades
@openzeppelin-foundry-upgrades/=lib/openzeppelin-foundry-upgrades/
@storyprotocol/core/=node_modules/@story-protocol/protocol-core/contracts/
@storyprotocol/script/=node_modules/@story-protocol/protocol-core/script/foundry
@storyprotocol/script/=node_modules/@story-protocol/protocol-core/script/foundry/
@create3-deployer/=node_modules/@story-protocol/create3-deployer/
@solady/=node_modules/solady/
ds-test/=lib/forge-std/lib/ds-test/src/
Expand Down
25 changes: 10 additions & 15 deletions script/utils/DeployHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ pragma solidity ^0.8.23;
import { console2 } from "forge-std/console2.sol";
import { Script } from "forge-std/Script.sol";
import { stdJson } from "forge-std/StdJson.sol";
import { ICreate3Deployer } from "@create3-deployer/contracts/ICreate3Deployer.sol";
import { UpgradeableBeacon } from "@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol";
import { StorageLayoutChecker } from "@storyprotocol/script/utils/upgrades/StorageLayoutCheck.s.sol";

// contracts
import { SPGNFT } from "contracts/SPGNFT.sol";
import { GroupingWorkflows } from "contracts/GroupingWorkflows.sol";
import { StoryProtocolGateway } from "contracts/StoryProtocolGateway.sol";
import { SPGNFT } from "../../contracts/SPGNFT.sol";
import { GroupingWorkflows } from "../../contracts/GroupingWorkflows.sol";
import { StoryProtocolGateway } from "../../contracts/StoryProtocolGateway.sol";

// script
import { StringUtil } from "./StringUtil.sol";
import { BroadcastManager } from "./BroadcastManager.s.sol";
import { JsonDeploymentHandler } from "./JsonDeploymentHandler.s.sol";
import { StoryProtocolCoreAddressManager } from "./StoryProtocolCoreAddressManager.sol";
import { StorageLayoutChecker } from "@storyprotocol/script/utils/upgrades/StorageLayoutCheck.s.sol";

// test
import { TestProxyHelper } from "test/utils/TestProxyHelper.t.sol";
import { ICreate3Deployer } from "@create3-deployer/contracts/ICreate3Deployer.sol";
import { TestProxyHelper } from "../../test/utils/TestProxyHelper.t.sol";

contract DeployHelper is
Script,
Expand All @@ -44,17 +44,12 @@ contract DeployHelper is
uint256 internal create3SaltSeed;

// SPGNFT
SPGNFT private spgNftImpl;
UpgradeableBeacon private spgNftBeacon;
SPGNFT internal spgNftImpl;
UpgradeableBeacon internal spgNftBeacon;

// Periphery Workflows
StoryProtocolGateway private spg;
GroupingWorkflows private groupingWorkflows;

// keep private to avoid conflict with inheriting contracts
uint256 private immutable ARBITRATION_PRICE;
uint256 private immutable MAX_ROYALTY_APPROVAL;
address private immutable TREASURY_ADDRESS;
StoryProtocolGateway internal spg;
GroupingWorkflows internal groupingWorkflows;

// DeployHelper variable
bool private writeDeploys;
Expand Down
2 changes: 1 addition & 1 deletion test/utils/BaseTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ contract BaseTest is Test {
GroupingModule internal groupingModule;
GroupNFT internal groupNFT;
IPGraphACL internal ipGraphACL;
MockEvenSplitGroupPool public rewardPool;
MockEvenSplitGroupPool internal rewardPool;

StoryProtocolGateway internal spg;
SPGNFT internal spgNftImpl;
Expand Down
Loading