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

refactor(SPG): refactor SPG into "workflow" contracts #68

Merged
merged 11 commits into from
Sep 17, 2024
Merged
6 changes: 3 additions & 3 deletions contracts/BaseWorkflow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ abstract contract BaseWorkflow {
address accessController,
address coreMetadataModule,
address ipAssetRegistry,
address licensingModule,
address licenseRegistry,
address licensingModule,
address pilTemplate
) {
// assumes 0 addresses are checked in the child contract
ACCESS_CONTROLLER = IAccessController(accessController);
CORE_METADATA_MODULE = ICoreMetadataModule(coreMetadataModule);
IP_ASSET_REGISTRY = IIPAssetRegistry(ipAssetRegistry);
LICENSING_MODULE = ILicensingModule(licensingModule);
LICENSE_REGISTRY = ILicenseRegistry(licenseRegistry);
LICENSING_MODULE = ILicensingModule(licensingModule);
PIL_TEMPLATE = IPILicenseTemplate(pilTemplate);
}

Expand All @@ -57,7 +57,7 @@ abstract contract BaseWorkflow {
if (
!ISPGNFT(spgNftContract).hasRole(SPGNFTLib.MINTER_ROLE, msg.sender) &&
!ISPGNFT(spgNftContract).publicMinting()
) revert Errors.SPG__CallerNotAuthorizedToMint();
) revert Errors.Workflow__CallerNotAuthorizedToMint();
_;
}
}
74 changes: 54 additions & 20 deletions contracts/SPGNFT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,47 @@ contract SPGNFT is ISPGNFT, ERC721URIStorageUpgradeable, AccessControlUpgradeabl
// keccak256(abi.encode(uint256(keccak256("story-protocol-periphery.SPGNFT")) - 1)) & ~bytes32(uint256(0xff));
bytes32 private constant SPGNFTStorageLocation = 0x66c08f80d8d0ae818983b725b864514cf274647be6eb06de58ff94d1defb6d00;

/// @dev The address of the SPG contract.
address public immutable SPG_ADDRESS;
/// @dev The address of the DerivativeWorkflows contract.
address public immutable DERIVATIVE_WORKFLOWS_ADDRESS;

///@dev The address of the GroupingWorkflows contract.
address public immutable GROUPING_ADDRESS;
/// @dev The address of the GroupingWorkflows contract.
address public immutable GROUPING_WORKFLOWS_ADDRESS;

/// @notice Modifier to restrict access to the SPG contract.
/// @dev The address of the LicenseAttachmentWorkflows contract.
address public immutable LICENSE_ATTACHMENT_WORKFLOWS_ADDRESS;

/// @dev The address of the RegistrationWorkflows contract.
address public immutable REGISTRATION_WORKFLOWS_ADDRESS;

/// @notice Modifier to restrict access to workflow contracts.
modifier onlyPeriphery() {
if (msg.sender != SPG_ADDRESS && msg.sender != GROUPING_ADDRESS)
revert Errors.SPGNFT__CallerNotPeripheryContract();
if (
msg.sender != DERIVATIVE_WORKFLOWS_ADDRESS &&
msg.sender != GROUPING_WORKFLOWS_ADDRESS &&
msg.sender != LICENSE_ATTACHMENT_WORKFLOWS_ADDRESS &&
msg.sender != REGISTRATION_WORKFLOWS_ADDRESS
) revert Errors.SPGNFT__CallerNotPeripheryContract();
_;
}

/// @custom:oz-upgrades-unsafe-allow constructor
constructor(address spg, address groupingWorkflows) {
if (spg == address(0) || groupingWorkflows == address(0)) revert Errors.SPGNFT__ZeroAddressParam();

SPG_ADDRESS = spg;
GROUPING_ADDRESS = groupingWorkflows;
constructor(
address derivativeWorkflows,
address groupingWorkflows,
address licenseAttachmentWorkflows,
address registrationWorkflows
) {
if (
derivativeWorkflows == address(0) ||
groupingWorkflows == address(0) ||
licenseAttachmentWorkflows == address(0) ||
registrationWorkflows == address(0)
) revert Errors.SPGNFT__ZeroAddressParam();

DERIVATIVE_WORKFLOWS_ADDRESS = derivativeWorkflows;
GROUPING_WORKFLOWS_ADDRESS = groupingWorkflows;
LICENSE_ATTACHMENT_WORKFLOWS_ADDRESS = licenseAttachmentWorkflows;
REGISTRATION_WORKFLOWS_ADDRESS = registrationWorkflows;

_disableInitializers();
}
Expand All @@ -67,14 +89,8 @@ contract SPGNFT is ISPGNFT, ERC721URIStorageUpgradeable, AccessControlUpgradeabl
if (initParams.mintFee > 0 && initParams.mintFeeToken == address(0)) revert Errors.SPGNFT__ZeroAddressParam();
if (initParams.maxSupply == 0) revert Errors.SPGNFT__ZeroMaxSupply();

_grantRole(SPGNFTLib.ADMIN_ROLE, initParams.owner);
_grantRole(SPGNFTLib.MINTER_ROLE, initParams.owner);

// grant roles to SPG
if (initParams.owner != SPG_ADDRESS) {
_grantRole(SPGNFTLib.ADMIN_ROLE, SPG_ADDRESS);
_grantRole(SPGNFTLib.MINTER_ROLE, SPG_ADDRESS);
}
// grant roles to owner and periphery workflow contracts
_grantRoles(initParams.owner);

SPGNFTStorage storage $ = _getSPGNFTStorage();
$._maxSupply = initParams.maxSupply;
Expand Down Expand Up @@ -237,6 +253,24 @@ contract SPGNFT is ISPGNFT, ERC721URIStorageUpgradeable, AccessControlUpgradeabl
return _getSPGNFTStorage()._baseURI;
}

/// @dev Grants minter and admin roles to the owner and periphery workflow contracts.
/// @param owner The address of the collection owner.
function _grantRoles(address owner) internal {
// grant roles to owner
_grantRole(SPGNFTLib.ADMIN_ROLE, owner);
_grantRole(SPGNFTLib.MINTER_ROLE, owner);

// grant roles to periphery workflow contracts
_grantRole(SPGNFTLib.ADMIN_ROLE, DERIVATIVE_WORKFLOWS_ADDRESS);
_grantRole(SPGNFTLib.MINTER_ROLE, DERIVATIVE_WORKFLOWS_ADDRESS);
_grantRole(SPGNFTLib.ADMIN_ROLE, GROUPING_WORKFLOWS_ADDRESS);
_grantRole(SPGNFTLib.MINTER_ROLE, GROUPING_WORKFLOWS_ADDRESS);
_grantRole(SPGNFTLib.ADMIN_ROLE, LICENSE_ATTACHMENT_WORKFLOWS_ADDRESS);
_grantRole(SPGNFTLib.MINTER_ROLE, LICENSE_ATTACHMENT_WORKFLOWS_ADDRESS);
_grantRole(SPGNFTLib.ADMIN_ROLE, REGISTRATION_WORKFLOWS_ADDRESS);
_grantRole(SPGNFTLib.MINTER_ROLE, REGISTRATION_WORKFLOWS_ADDRESS);
}

//
// Upgrade
//
Expand Down
190 changes: 0 additions & 190 deletions contracts/interfaces/IStoryProtocolGateway.sol

This file was deleted.

Loading
Loading