Skip to content
This repository has been archived by the owner on Apr 30, 2024. It is now read-only.

Commit

Permalink
rolled back license status
Browse files Browse the repository at this point in the history
  • Loading branch information
Raul committed Jan 24, 2024
1 parent e9564c2 commit a994cef
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 58 deletions.
14 changes: 0 additions & 14 deletions contracts/lib/Licensing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
pragma solidity ^0.8.20;
import { IParamVerifier } from "../interfaces/licensing/IParamVerifier.sol";
import { Errors } from "./Errors.sol";
import "forge-std/console2.sol";

library Licensing {

Expand Down Expand Up @@ -88,30 +87,17 @@ library Licensing {
} else if (pvt == ParamVerifierType.LinkParent) {
return policy.linkParentParamValues;
} else if (pvt == ParamVerifierType.Transfer) {
console2.log(policy.transferParamValues.length);
return policy.transferParamValues;
} else {
revert Errors.LicenseRegistry__InvalidParamVerifierType();
}
}

/// Describe the ability of the license to be linked to a parent IP
/// Burnt license NFT can still be set Inactive by expiration or Disputer module
enum LinkStatus {
/// License has been minted but not activated
NeedsActivation,
/// License has been activated and is active
Active

}

/// Data that define a License Agreement NFT
struct License {
/// the id for the Policy this License will set to the desired derivative IP after being burned.
uint256 policyId;
/// Ids for the licensors, meaning the Ip Ids of the parents of the derivative to be created
address[] licensorIpIds;
/// LinkStatus of the license
LinkStatus status;
}
}
76 changes: 33 additions & 43 deletions contracts/registries/LicenseRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import { ILicenseRegistry } from "contracts/interfaces/registries/ILicenseRegist
import { Errors } from "contracts/lib/Errors.sol";
import { Licensing } from "contracts/lib/Licensing.sol";

import "forge-std/console2.sol";

// TODO: consider disabling operators/approvals on creation
contract LicenseRegistry is ERC1155, ILicenseRegistry {
using EnumerableSet for EnumerableSet.UintSet;
Expand Down Expand Up @@ -87,10 +85,6 @@ contract LicenseRegistry is ERC1155, ILicenseRegistry {
fwCreation.transferVerifiers,
fwCreation.transferDefaultValues
);
console2.log("mint length", fw.parameters[Licensing.ParamVerifierType.Mint].length);
console2.log("transfer length", fw.parameters[Licensing.ParamVerifierType.Transfer].length);
console2.log("transfer default length", fwCreation.transferDefaultValues.length);
// Should we add a label?
emit LicenseFrameworkCreated(msg.sender, _totalFrameworks, fwCreation);
return _totalFrameworks;
}
Expand All @@ -108,7 +102,6 @@ contract LicenseRegistry is ERC1155, ILicenseRegistry {
IParamVerifier[] calldata paramVerifiers,
bytes[] calldata paramDefaultValues
) private {
console2.log("setting param array");
if (paramVerifiers.length != paramDefaultValues.length) {
revert Errors.LicenseRegistry__ParamVerifierLengthMismatch();
}
Expand All @@ -117,7 +110,6 @@ contract LicenseRegistry is ERC1155, ILicenseRegistry {
for (uint256 i = 0; i < paramVerifiers.length; i++) {
params.push(Licensing.Parameter({ verifier: paramVerifiers[i], defaultValue: paramDefaultValues[i] }));
}
console2.log("params length", params.length);
}

/// Gets total frameworks supported by LicenseRegistry
Expand Down Expand Up @@ -316,12 +308,9 @@ contract LicenseRegistry is ERC1155, ILicenseRegistry {
}
Licensing.Policy memory pol = policy(policyId);
_verifyParams(Licensing.ParamVerifierType.Mint, pol, receiver, amount);
// We don't check about `mintsActiveByDefault` because policy value always overrides.
Licensing.LinkStatus status = pol.mintsActive ? Licensing.LinkStatus.NeedsActivation : Licensing.LinkStatus.Active;
Licensing.License memory licenseData = Licensing.License({
policyId: policyId,
licensorIpIds: licensorIpIds,
status: status
licensorIpIds: licensorIpIds
});
(uint256 lId, bool isNew) = _addIdOrGetExisting(abi.encode(licenseData), _hashedLicenses, _totalLicenses);
licenseId = lId;
Expand All @@ -334,16 +323,17 @@ contract LicenseRegistry is ERC1155, ILicenseRegistry {
return licenseId;
}

function activateLicense(uint256 licenseId) external onlyLicensee(licenseId, msg.sender) {
Licensing.License storage licenseData = _licenses[licenseId];
if (licenseData.status != Licensing.LinkStatus.NeedsActivation) {
revert Errors.LicenseRegistry__LicenseAlreadyActivated();
}
Licensing.Policy memory pol = policy(licenseData.policyId);
_verifyParams(Licensing.ParamVerifierType.Activation, pol, msg.sender, 1);
licenseData.status = Licensing.LinkStatus.Active;
emit LicenseActivated(licenseId, msg.sender);
}
// TODO: activation must be done at the IP Id level
// function activateLicense(uint256 licenseId) external onlyLicensee(licenseId, msg.sender) {
// Licensing.License storage licenseData = _licenses[licenseId];
// if (licenseData.status != Licensing.LinkStatus.NeedsActivation) {
// revert Errors.LicenseRegistry__LicenseAlreadyActivated();
// }
// Licensing.Policy memory pol = policy(licenseData.policyId);
// _verifyParams(Licensing.ParamVerifierType.Activation, pol, msg.sender, 1);
// licenseData.status = Licensing.LinkStatus.Active;
// emit LicenseActivated(licenseId, msg.sender);
// }

/// Returns true if holder has positive balance for licenseId
function isLicensee(uint256 licenseId, address holder) external view returns (bool) {
Expand Down Expand Up @@ -375,9 +365,9 @@ contract LicenseRegistry is ERC1155, ILicenseRegistry {

// TODO: check if childIpId exists and is owned by holder
Licensing.License memory licenseData = _licenses[licenseId];
if (licenseData.status != Licensing.LinkStatus.Active) {
revert Errors.LicenseRegistry__LicenseNotActive();
}
// if (licenseData.status != Licensing.LinkStatus.Active) {
// revert Errors.LicenseRegistry__LicenseNotActive();
// }
address[] memory parents = licenseData.licensorIpIds;
for (uint256 i = 0; i < parents.length; i++) {
// TODO: check licensor exist
Expand Down Expand Up @@ -427,32 +417,32 @@ contract LicenseRegistry is ERC1155, ILicenseRegistry {

function _update(address from, address to, uint256[] memory ids, uint256[] memory values) virtual override internal {
// We are interested in transfers, minting and burning are checked in mintLicense and linkIpToParent respectively.
console2.log("updating");
console2.log("from", from);
console2.log("to", to);



if (from != address(0) && to != address(0)) {
uint256 length = ids.length;
for (uint256 i = 0; i < length; i++) {
console2.log("id", ids[i]);

_verifyParams(Licensing.ParamVerifierType.Transfer, policyForLicense(ids[i]), to, values[i]);
}
}
super._update(from, to, ids, values);
}

function _verifyParams(Licensing.ParamVerifierType pvt, Licensing.Policy memory pol, address holder, uint256 amount) internal {
console2.log("verifying params");
console2.log("pvt", uint8(pvt));
console2.log("frameworkId", pol.frameworkId);
console2.log("holder", holder);
console2.log("amount", amount);





Licensing.Framework storage fw = _framework(pol.frameworkId);

Licensing.Parameter[] storage params = fw.parameters[pvt];
uint256 paramsLength = params.length;
bytes[] memory values = pol.getValues(pvt);
console2.log("values length", values.length);
console2.log("params length", paramsLength);


for (uint256 i = 0; i < paramsLength; i++) {
Licensing.Parameter memory param = params[i];
// Empty bytes => use default value specified in license framework creation params.
Expand All @@ -465,13 +455,13 @@ contract LicenseRegistry is ERC1155, ILicenseRegistry {
} else if (pvt == Licensing.ParamVerifierType.LinkParent) {
verificationOk = param.verifier.verifyLinkParent(holder, data);
} else if (pvt == Licensing.ParamVerifierType.Transfer) {
console2.log("verifying transfer");
console2.log("values length", values[i].length);
console2.log("values");
console2.logBytes(values[i]);
console2.log("default value length", param.defaultValue.length);
console2.log("default value");
console2.logBytes(param.defaultValue);







verificationOk = param.verifier.verifyTransfer(holder, amount, data);
} else {
// This should never happen since getValues checks for pvt validity
Expand Down
2 changes: 1 addition & 1 deletion test/foundry/LicenseRegistry.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ contract LicenseRegistryTest is Test {
Licensing.License memory license = registry.license(licenseId);
assertEq(registry.balanceOf(licenseHolder, licenseId), 2);
assertEq(registry.isLicensee(licenseId, licenseHolder), true);
assertEq(uint8(license.status), uint8(Licensing.LinkStatus.Active));
// assertEq(uint8(license.status), uint8(Licensing.LinkStatus.Active));
assertEq(license.policyId, policyId);
assertEq(license.licensorIpIds.length, 1);
assertEq(license.licensorIpIds[0], ipId1);
Expand Down

0 comments on commit a994cef

Please sign in to comment.