Skip to content

Commit

Permalink
create root license
Browse files Browse the repository at this point in the history
  • Loading branch information
Raul committed Nov 13, 2023
1 parent 7abe50e commit bdc5dac
Show file tree
Hide file tree
Showing 9 changed files with 223 additions and 222 deletions.
1 change: 0 additions & 1 deletion contracts/StoryProtocol.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ contract StoryProtocol {
// Licensing //
////////////////////////////////////////////////////////////////////////////


function configureIpOrgLicensing(
address ipOrg_,
Licensing.FrameworkConfig calldata framework_
Expand Down
4 changes: 2 additions & 2 deletions contracts/lib/modules/ProtocolRelationships.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ library ProtocolRelationships {
relType: IPA_LICENSE,
ipOrg: LibRelationship.PROTOCOL_LEVEL_RELATIONSHIP,
allowedElements: LibRelationship.RelatedElements({
src: LibRelationship.Relatables.IPA,
dst: LibRelationship.Relatables.LICENSE
src: LibRelationship.Relatables.LICENSE,
dst: LibRelationship.Relatables.IPA
}),
allowedSrcs: new uint8[](0),
allowedDsts: new uint8[](0)
Expand Down
122 changes: 58 additions & 64 deletions contracts/modules/licensing/LicenseCreatorModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ contract LicenseCreatorModule is BaseModule, TermsRepository, ProtocolTermsHelpe
}
}


function _hookRegistryAdmin()
internal
view
Expand Down Expand Up @@ -109,10 +108,10 @@ contract LicenseCreatorModule is BaseModule, TermsRepository, ProtocolTermsHelpe
// TODO: Check if parent license is active

}
if (_comIpOrgTermIds[address(ipOrg_)].length() == 0) {
// At least non commercial terms must be set
if (_nonComIpOrgTermData[address(ipOrg_)].length == 0) {
revert Errors.LicensingModule_IpOrgNotConfigured();
}

if (!ipOrgAllowsCommercial(address(ipOrg_)) && lParams.isCommercial) {
revert Errors.LicensingModule_CommercialLicenseNotAllowed();
}
Expand All @@ -134,20 +133,63 @@ contract LicenseCreatorModule is BaseModule, TermsRepository, ProtocolTermsHelpe
params_,
(Licensing.LicenseCreationParams)
);
// TODO: How do we distinguish which terms apply?
// Share alike and Remix IPA, posting the remixed IPA => copy parent license terms?
// License to make an remixed IPA in the future => ????
// License to commercialize IPA => ???
// Commerial license to use IPA in IPA => ???
IPAsset.IPA memory ipa = IPA_REGISTRY.getIpAsset(lParams.ipaId);

// Licensing.License memory license = Licensing.License({
// isCommercial: lParams.isCommercial,
// licensor: _getLicensor(
// ipOrg_.owner(),
// ipa.owner,
// LICENSE_REGISTRY.getLicenseOwner(lParams.parentLicenseId)
// ),
// revoker: _getRevoker(ipOrg_),
// termsConfig:
// });
// return LICENSE_REGISTRY.createLicense(license);
return "";
(ShortString[] memory termIds, bytes[] memory termsData) = getIpOrgTerms(
lParams.isCommercial,
address(ipOrg_)
);
Licensing.License memory license = Licensing.License({
isCommercial: lParams.isCommercial,
licensor: _getLicensor(
ipOrg_.owner(),
ipa.owner,
LICENSE_REGISTRY.getLicenseOwner(lParams.parentLicenseId)
),
revoker: _getRevoker(ipOrg_),
termIds: termIds,
termsData: termsData
});
uint256 licenseId = LICENSE_REGISTRY.addLicense(license);
if (lParams.ipaId != 0) {
_relateToIpa(lParams.ipaId, licenseId);
}
if (lParams.parentLicenseId != 0) {
_relateToParentLicense(lParams.parentLicenseId, licenseId);
}
return abi.encode(licenseId);
}

function _relateToIpa(uint256 ipaId, uint256 licenseId) private returns (uint256) {
return _createRelationship(
LibRelationship.CreateRelationshipParams({
relType: ProtocolRelationships.IPA_LICENSE,
srcAddress: address(LICENSE_REGISTRY),
srcId: licenseId,
srcType: 0,
dstAddress: address(IPA_REGISTRY),
dstId: ipaId,
dstType: 0
})
);
}

function _relateToParentLicense(uint256 parentLicenseId, uint256 licenseId) private returns (uint256) {
return _createRelationship(
LibRelationship.CreateRelationshipParams({
relType: ProtocolRelationships.SUBLICENSE_OF,
srcAddress: address(LICENSE_REGISTRY),
srcId: licenseId,
srcType: 0,
dstAddress: address(LICENSE_REGISTRY),
dstId: parentLicenseId,
dstType: 0
})
);
}

function _getLicensor(
Expand All @@ -168,54 +210,6 @@ contract LicenseCreatorModule is BaseModule, TermsRepository, ProtocolTermsHelpe
return ipOrg.owner();
}

/*
(
uint256 parentLicenseId,
bytes[] memory additionalTerms,
uint256 newIpaId
) = abi.decode(params_, (uint256, bytes[], uint256));
uint256 licenseId = LICENSE_REGISTRY.createLicenseFrom(parentLicenseId);
// If we have commercial terms (this is a commercial sublicense or remix)
if (additionalTerms.length > 0) {
LICENSE_REGISTRY.addTerms(licenseId, additionalTerms);
}
uint256 sublicenseRelId = _createRelationship(
LibRelationship.CreateRelationshipParams({
relType: ProtocolRelationships.SUBLICENSE_OF,
srcAddress: address(LICENSE_REGISTRY),
srcId: parentLicenseId,
srcType: 0,
dstAddress: address(LICENSE_REGISTRY),
dstId: licenseId,
dstType: 0
})
);
if (newIpaId > 0) {
uint256 ipaI = _createRelationship(
LibRelationship.CreateRelationshipParams({
relType: ProtocolRelationships.IPA_LICENSE,
srcAddress: address(ipOrg_),
srcId: parentLicenseId,
srcType: 0,
dstAddress: address(LICENSE_REGISTRY),
dstId: licenseId,
dstType: 0
})
);
} else {
LICENSE_REGISTRY.makeTradeable(licenseId);
}
// If sublicense is to create work, we mint an IPA and relate it to the original IPA?
(LibRelationship.CreateRelationshipParams memory addRel) = abi.decode(
params_,
(LibRelationship.CreateRelationshipParams)
);
*/

////////////////////////////////////////////////////////////////////////////
// Config //
////////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions contracts/modules/licensing/LicenseRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ contract LicenseRegistry {
uint256 private _licenseCount = 0;


function addLicense(Licensing.License calldata license_) external returns (uint256) {
function addLicense(Licensing.License memory license_) external returns (uint256) {
// TOOD: Add authorization
_licenseCount++;
_licenses[_licenseCount] = license_;
Expand All @@ -21,7 +21,7 @@ contract LicenseRegistry {
}

function getLicenseOwner(uint256 id_) external view returns (address) {
return address(123);
return address(0);
}

function addTerms(uint256 licenseId, bytes[] memory terms) external {
Expand Down
84 changes: 71 additions & 13 deletions test/foundry/modules/licensing/BaseLicensingTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,32 @@ contract BaseLicensingTest is BaseTest {
ShortString public nonCommTextTermId = "non_comm_text_term_id".toShortString();
ShortString public commTextTermId = "comm_text_term_id".toShortString();

modifier withNonCommFramework() {
vm.prank(ipOrg.owner());
spg.configureIpOrgLicensing(
address(ipOrg),
getNonCommFramework(
nonCommTextTermId,
bytes("")
)
);
_;
}

modifier withCommFramework() {
vm.prank(ipOrg.owner());
spg.configureIpOrgLicensing(
address(ipOrg),
getCommFramework(
commTextTermId,
bytes(""),
nonCommTextTermId,
bytes("")
)
);
_;
}

function setUp() virtual override public {
super.setUp();
licensingModule.addTermCategory("test_category");
Expand Down Expand Up @@ -53,7 +79,7 @@ contract BaseLicensingTest is BaseTest {
));
}

function getEmptyLicensingFramework() public pure returns (Licensing.FrameworkConfig memory) {
function getEmptyFramework() public pure returns (Licensing.FrameworkConfig memory) {
return
Licensing.FrameworkConfig({
comTermsConfig: Licensing.TermsConfig({
Expand All @@ -67,7 +93,7 @@ contract BaseLicensingTest is BaseTest {
});
}

function getNonCommLicensingFramework(
function getNonCommFramework(
ShortString termId,
bytes memory data
) public pure returns (Licensing.FrameworkConfig memory) {
Expand All @@ -88,24 +114,56 @@ contract BaseLicensingTest is BaseTest {
});
}

function getCommLicensingFramework(
ShortString termId,
bytes memory data
function getCommFramework(
ShortString cId,
bytes memory cData,
ShortString ncId,
bytes memory ncData
) public pure returns (Licensing.FrameworkConfig memory) {
ShortString[] memory termIds = new ShortString[](1);
termIds[0] = termId;
bytes[] memory termData = new bytes[](1);
termData[0] = data;
ShortString[] memory comTermsId = new ShortString[](1);
comTermsId[0] = cId;
bytes[] memory comTermsData = new bytes[](1);
comTermsData[0] = cData;
ShortString[] memory nonComTermsId = new ShortString[](1);
nonComTermsId[0] = ncId;
bytes[] memory nonComTermsData = new bytes[](1);
nonComTermsData[0] = ncData;
return
Licensing.FrameworkConfig({
comTermsConfig: Licensing.TermsConfig({
termIds: termIds,
termData: termData
termIds: comTermsId,
termData: comTermsData
}),
nonComTermsConfig: Licensing.TermsConfig({
termIds: termIds,
termData: termData
termIds: nonComTermsId,
termData: nonComTermsData
})
});
}


function assertTerms(Licensing.License memory license) public {
(ShortString[] memory ipOrgTermsId, bytes[] memory ipOrgTermsData) = licensingModule.getIpOrgTerms(
license.isCommercial, address(ipOrg)
);
assertEq(license.termIds.length, ipOrgTermsId.length);
assertEq(license.termsData.length, ipOrgTermsData.length);
for (uint256 i = 0; i < license.termIds.length; i++) {
assertTrue(ShortStringOps._equal(license.termIds[i], ipOrgTermsId[i]));
assertTrue(keccak256(license.termsData[i]) == keccak256(ipOrgTermsData[i]));
Licensing.LicensingTerm memory term = licensingModule.getTerm(ipOrgTermsId[i]);
if (license.isCommercial) {
assertTrue(
term.comStatus == Licensing.CommercialStatus.Commercial ||
term.comStatus == Licensing.CommercialStatus.Both
);
} else {
assertTrue(
term.comStatus == Licensing.CommercialStatus.NonCommercial ||
term.comStatus == Licensing.CommercialStatus.Both
);
}
}
}

}
44 changes: 5 additions & 39 deletions test/foundry/modules/licensing/LicenseCreatorModule.Terms.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@ contract LicensingCreatorModuleConfigTest is BaseLicensingTest {

function setUp() override public {
super.setUp();
vm.prank(ipOrg.owner());
spg.configureIpOrgLicensing(
address(ipOrg),
getCommLicensingFramework(
textTermId,
bytes("")
)
);
registry.register(IPAsset.RegisterIpAssetParams({
name: "test",
ipAssetType: 2,
Expand All @@ -53,37 +45,11 @@ contract LicensingCreatorModuleConfigTest is BaseLicensingTest {
function test_LicensingModule_licensing_createsNonCommercialLicense() public {
}

function test_LicensingModule_licensing_createRootLicense() public {
vm.prank(ipOrg.owner());
uint256 lId = spg.createLicense(
address(ipOrg),
Licensing.LicenseCreationParams({
parentLicenseId: 0,
isCommercial: false,
ipaId: 1
}),
new bytes[](0),
new bytes[](0)
);
// Non Commercial
Licensing.License memory license = licenseRegistry.getLicense(lId);
assertFalse(license.isCommercial);
assertEq(license.revoker, ipOrg.owner());
assertEq(license.licensor, ipOrg.owner());

assertTrue(
relationshipModule.relationshipExists(
LibRelationship.Relationship({
relType: ProtocolRelationships.IPA_LICENSE,
srcAddress: address(registry),
dstAddress: address(licenseRegistry),
srcId: 1,
dstId: 1
})
)
);
//Licensing.License memory license = licenseReg
// Commercial
function test_LicensingModule_licensing_createsCommerciaSublLicense() public {

}

function test_LicensingModule_licensing_createsNonCommercialSubLicense() public {

}

Expand Down
Loading

0 comments on commit bdc5dac

Please sign in to comment.