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

Add Offchain URI Field to PILTerms #94

Merged
merged 3 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions contracts/interfaces/modules/licensing/ILicenseTemplate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ interface ILicenseTemplate is IERC165 {
/// @return The metadata URI of the license template.
function getMetadataURI() external view returns (string memory);

/// @notice Returns the URI of the license terms.
/// @param licenseTermsId The ID of the license terms.
/// @return The URI of the license terms.
function getLicenseTermsURI(uint256 licenseTermsId) external view returns (string memory);

/// @notice Returns the total number of registered license terms.
/// @return The total number of registered license terms.
function totalRegisteredLicenseTerms() external view returns (uint256);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { ILicenseTemplate } from "../../../interfaces/modules/licensing/ILicense
/// same terms or not.
/// @param derivativeRevCelling The maximum revenue that can be generated from the derivative use of the work.
/// @param currency The ERC20 token to be used to pay the minting fee. the token must be registered in story protocol.
/// @param uri The URI of the license terms, which can be used to fetch the offchain license terms.
struct PILTerms {
bool transferable;
address royaltyPolicy;
Expand All @@ -41,6 +42,7 @@ struct PILTerms {
bool derivativesReciprocal;
uint256 derivativeRevCelling;
address currency;
string uri;
}

/// @title IPILicenseTemplate
Expand Down
12 changes: 8 additions & 4 deletions contracts/lib/PILFlavors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ library PILFlavors {
derivativesApproval: false,
derivativesReciprocal: false,
derivativeRevCelling: 0,
currency: address(0)
currency: address(0),
uri: ""
});
}

Expand All @@ -138,7 +139,8 @@ library PILFlavors {
derivativesApproval: false,
derivativesReciprocal: true,
derivativeRevCelling: 0,
currency: address(0)
currency: address(0),
uri: ""
});
}

Expand All @@ -165,7 +167,8 @@ library PILFlavors {
derivativesApproval: false,
derivativesReciprocal: false,
derivativeRevCelling: 0,
currency: currencyToken
currency: currencyToken,
uri: ""
});
}

Expand Down Expand Up @@ -193,7 +196,8 @@ library PILFlavors {
derivativesApproval: false,
derivativesReciprocal: true,
derivativeRevCelling: 0,
currency: currencyToken
currency: currencyToken,
uri: ""
});
}
}
10 changes: 10 additions & 0 deletions contracts/modules/licensing/PILicenseTemplate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,13 @@ contract PILicenseTemplate is
return $.licenseTerms[selectedLicenseTermsId];
}

/// @notice Returns the URI of the license terms.
/// @param licenseTermsId The ID of the license terms.
/// @return The URI of the license terms.
function getLicenseTermsURI(uint256 licenseTermsId) external view returns (string memory) {
return _getPILicenseTemplateStorage().licenseTerms[licenseTermsId].uri;
}

/// @notice Returns the total number of registered license terms.
/// @return The total number of registered license terms.
function totalRegisteredLicenseTerms() external view returns (uint256) {
Expand Down Expand Up @@ -312,6 +319,9 @@ contract PILicenseTemplate is
'{"trait_type": "Currency", "value": "',
terms.currency.toHexString(),
'"},',
'{"trait_type": "URI", "value": "',
terms.uri,
'"},',
// Skip transferable, it's already added in the common attributes by the LicenseRegistry.
_policyCommercialTraitsToJson(terms),
_policyDerivativeTraitsToJson(terms)
Expand Down
2 changes: 1 addition & 1 deletion test/foundry/access/AccessController.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1646,7 +1646,7 @@ contract AccessControllerTest is BaseTest {
bytes4(0),
AccessPermission.ALLOW
);

vm.stopPrank();
vm.expectRevert(abi.encodeWithSelector(PausableUpgradeable.EnforcedPause.selector));
vm.prank(owner);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ contract BigBang_Integration_SingleNftCollection is BaseIntegration {
derivativesApproval: false,
derivativesReciprocal: false,
derivativeRevCelling: 0,
currency: address(erc20)
currency: address(erc20),
uri: ""
})
);
}
Expand Down
7 changes: 7 additions & 0 deletions test/foundry/mocks/module/MockLicenseTemplate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,11 @@ contract MockLicenseTemplate is BaseLicenseTemplateUpgradeable {
function toJson(uint256 licenseTermsId) public view returns (string memory) {
return "";
}

/// @notice Returns the URI of the license terms.
/// @param licenseTermsId The ID of the license terms.
/// @return The URI of the license terms.
function getLicenseTermsURI(uint256 licenseTermsId) external view returns (string memory) {
return "";
}
}
18 changes: 12 additions & 6 deletions test/foundry/modules/licensing/LicensingModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ contract LicensingModuleTest is BaseTest {
derivativesApproval: false,
derivativesReciprocal: true,
derivativeRevCelling: 0,
currency: address(0x123)
currency: address(0x123),
uri: ""
});

uint256 termsId = pilTemplate.registerLicenseTerms(terms);
Expand Down Expand Up @@ -434,7 +435,8 @@ contract LicensingModuleTest is BaseTest {
derivativesApproval: false,
derivativesReciprocal: true,
derivativeRevCelling: 0,
currency: address(0x123)
currency: address(0x123),
uri: ""
});

uint256 termsId = pilTemplate.registerLicenseTerms(terms);
Expand Down Expand Up @@ -758,7 +760,8 @@ contract LicensingModuleTest is BaseTest {
derivativesApproval: false,
derivativesReciprocal: true,
derivativeRevCelling: 0,
currency: address(0x123)
currency: address(0x123),
uri: ""
});

uint256 termsId = pilTemplate.registerLicenseTerms(terms);
Expand Down Expand Up @@ -1055,7 +1058,8 @@ contract LicensingModuleTest is BaseTest {
derivativesApproval: false,
derivativesReciprocal: true,
derivativeRevCelling: 0,
currency: address(0x123)
currency: address(0x123),
uri: ""
});

uint256 termsId = pilTemplate.registerLicenseTerms(terms);
Expand Down Expand Up @@ -1104,7 +1108,8 @@ contract LicensingModuleTest is BaseTest {
derivativesApproval: false,
derivativesReciprocal: true,
derivativeRevCelling: 0,
currency: address(0x123)
currency: address(0x123),
uri: ""
});

uint256 termsId = pilTemplate.registerLicenseTerms(terms);
Expand Down Expand Up @@ -1150,7 +1155,8 @@ contract LicensingModuleTest is BaseTest {
derivativesApproval: false,
derivativesReciprocal: true,
derivativeRevCelling: 0,
currency: address(0x123)
currency: address(0x123),
uri: ""
});

uint256 termsId = pilTemplate.registerLicenseTerms(terms);
Expand Down
37 changes: 36 additions & 1 deletion test/foundry/modules/licensing/PILicenseTemplate.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,41 @@ contract PILicenseTemplateTest is BaseTest {
assertFalse(pilTemplate.isLicenseTransferable(nonTransferableTermsId));
}

function test_PILicenseTemplate_getLicenseURI() public {
PILTerms memory terms = PILFlavors.commercialUse({
mintingFee: 100,
currencyToken: address(erc20),
royaltyPolicy: address(royaltyPolicyLAP)
});
terms.uri = "license.url";
uint256 termsId = pilTemplate.registerLicenseTerms(terms);
assertEq(pilTemplate.getLicenseTermsURI(termsId), "license.url");
}

function test_PILicenseTemplate_differentLicenseURI() public {
PILTerms memory terms = PILFlavors.commercialUse({
mintingFee: 100,
currencyToken: address(erc20),
royaltyPolicy: address(royaltyPolicyLAP)
});
terms.uri = "license.url";
uint256 termsId = pilTemplate.registerLicenseTerms(terms);
assertEq(pilTemplate.getLicenseTermsURI(termsId), "license.url");

PILTerms memory terms1 = PILFlavors.commercialUse({
mintingFee: 100,
currencyToken: address(erc20),
royaltyPolicy: address(royaltyPolicyLAP)
});
terms1.uri = "another.license.url";
uint256 termsId1 = pilTemplate.registerLicenseTerms(terms1);

assertEq(pilTemplate.getLicenseTermsURI(termsId1), "another.license.url");
assertEq(pilTemplate.getLicenseTermsURI(termsId), "license.url");
assertEq(pilTemplate.getLicenseTermsId(terms1), termsId1);
assertEq(pilTemplate.getLicenseTermsId(terms), termsId);
}

function test_PILicenseTemplate_getEarlierExpiredTime_WithEmptyLicenseTerms() public {
uint256[] memory licenseTermsIds = new uint256[](0);
assertEq(pilTemplate.getEarlierExpireTime(licenseTermsIds, block.timestamp), 0);
Expand All @@ -520,7 +555,7 @@ contract PILicenseTemplateTest is BaseTest {
function _DefaultToJson() internal pure returns (string memory) {
/* solhint-disable */
return
'{"trait_type": "Expiration", "value": "never"},{"trait_type": "Currency", "value": "0x0000000000000000000000000000000000000000"},{"trait_type": "Commercial Use", "value": "false"},{"trait_type": "Commercial Attribution", "value": "false"},{"trait_type": "Commercial Revenue Share", "max_value": 1000, "value": 0},{"trait_type": "Commercial Revenue Celling", "value": 0},{"trait_type": "Commercializer Check", "value": "0x0000000000000000000000000000000000000000"},{"trait_type": "Derivatives Allowed", "value": "false"},{"trait_type": "Derivatives Attribution", "value": "false"},{"trait_type": "Derivatives Revenue Celling", "value": 0},{"trait_type": "Derivatives Approval", "value": "false"},{"trait_type": "Derivatives Reciprocal", "value": "false"},';
'{"trait_type": "Expiration", "value": "never"},{"trait_type": "Currency", "value": "0x0000000000000000000000000000000000000000"},{"trait_type": "URI", "value": ""},{"trait_type": "Commercial Use", "value": "false"},{"trait_type": "Commercial Attribution", "value": "false"},{"trait_type": "Commercial Revenue Share", "max_value": 1000, "value": 0},{"trait_type": "Commercial Revenue Celling", "value": 0},{"trait_type": "Commercializer Check", "value": "0x0000000000000000000000000000000000000000"},{"trait_type": "Derivatives Allowed", "value": "false"},{"trait_type": "Derivatives Attribution", "value": "false"},{"trait_type": "Derivatives Revenue Celling", "value": 0},{"trait_type": "Derivatives Approval", "value": "false"},{"trait_type": "Derivatives Reciprocal", "value": "false"},';
/* solhint-enable */
}
}
6 changes: 4 additions & 2 deletions test/foundry/utils/LicensingHelper.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ contract LicensingHelper {
derivativesApproval: false,
derivativesReciprocal: reciprocal,
derivativeRevCelling: 0,
currency: address(erc20)
currency: address(erc20),
uri: ""
});
}

Expand All @@ -124,7 +125,8 @@ contract LicensingHelper {
derivativesApproval: false,
derivativesReciprocal: reciprocal,
derivativeRevCelling: 0,
currency: address(0)
currency: address(0),
uri: ""
});
}

Expand Down
Loading