Skip to content

Commit

Permalink
Connected IPOrg asset types to relationship module and removed IP Ass…
Browse files Browse the repository at this point in the history
…et Type (#188)

* ip org types and elimination of ip asset type

* fixing tests

* refactor registration tests

* fixed existing tests

* test iporg

* test protocol relationship types configuration

* test relationship setting

* remove unused struct

* removed commented out code

* refactor tokenURI

* fix

---------

Co-authored-by: Raul <[email protected]>
  • Loading branch information
Ramarti and Raul authored Nov 27, 2023
1 parent 26c94df commit f6d9079
Show file tree
Hide file tree
Showing 24 changed files with 508 additions and 149 deletions.
5 changes: 0 additions & 5 deletions contracts/IPAssetRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ contract IPAssetRegistry is IIPAssetRegistry {
/// @notice Core attributes that make up an IP Asset.
struct IPA {
string name; // Human-readable identifier for the IP asset.
uint64 ipAssetType; // Numerical code corresponding to IP type (e.g. patent, copyright, etc.)
address registrant; // Address of the initial registrant of the IP asset.
uint8 status; // Current status of the IP asset (e.g. active, expired, etc.)
address ipOrg; // Address of the governing entity of the IP asset.
Expand Down Expand Up @@ -57,13 +56,11 @@ contract IPAssetRegistry is IIPAssetRegistry {
/// @notice Registers a new IP asset.
/// @param registrant_ The initial registrant for the IP asset.
/// @param name_ A name given to describe the IP asset.
/// @param ipAssetType_ A numerical code corresponding to IP asset type.
/// @param hash_ A content hash used for verifyign provenance of the asset.
function register(
address ipOrg_,
address registrant_,
string memory name_,
uint64 ipAssetType_,
bytes32 hash_
) public onlyRegistrationModule returns (uint256 ipAssetId) {

Expand All @@ -76,7 +73,6 @@ contract IPAssetRegistry is IIPAssetRegistry {
uint64 registrationDate = uint64(block.timestamp);
_ipAssets[ipAssetId] = IPA({
name: name_,
ipAssetType: ipAssetType_,
// For now, let's assume 0 == unset, 1 is OK. TODO: Add status enum and synch with License status
status: 1,
registrant: registrant_,
Expand All @@ -87,7 +83,6 @@ contract IPAssetRegistry is IIPAssetRegistry {
emit Registered(
ipAssetId,
name_,
ipAssetType_,
ipOrg_,
registrant_,
hash_
Expand Down
2 changes: 1 addition & 1 deletion contracts/StoryProtocol.sol
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ contract StoryProtocol is Multicall {
Registration.TRANSFER_IP_ASSET,
abi.encode(from_, to_, ipAssetId_)
);
bytes memory result = MODULE_REGISTRY.execute(
MODULE_REGISTRY.execute(
IIPOrg(ipOrg_),
msg.sender,
ModuleRegistryKeys.REGISTRATION_MODULE,
Expand Down
2 changes: 0 additions & 2 deletions contracts/interfaces/IIPAssetRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ interface IIPAssetRegistry {
/// @notice Emits when a new IP asset is registered.
/// @param ipAssetId_ The global IP asset identifier.
/// @param name_ The assigned name for the IP asset.
/// @param ipAssetType_ The status indicator for the IP asset.
/// @param ipOrg_ The registering governing body for the IP asset.
/// @param registrant_ The initial individual registrant of the IP asset.
/// @param hash_ The content hash associated with the IP asset.
event Registered(
uint256 ipAssetId_,
string name_,
uint64 indexed ipAssetType_,
address indexed ipOrg_,
address indexed registrant_,
bytes32 hash_
Expand Down
6 changes: 5 additions & 1 deletion contracts/interfaces/ip-org/IIPOrg.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ interface IIPOrg {
/// @notice Mints an IP Asset wrapper for the IP Org.
/// @dev This function is only callable by the IP Org registration module.
/// @param owner Address of the current owner of the local IP Org asset.
/// @param assetType The IP Org asset type.
/// @return id The local identifier of the minted IP Org wrapped asset.
function mint(address owner) external returns (uint256 id);
function mint(address owner, uint8 assetType) external returns (uint256 id);

/// @notice Gets the current owner of the IP Org.
function owner() external view returns (address);

/// @notice Returns contract-level metadata for the IP Org.
function contractURI() external view returns (string memory);

/// @notice Returns the Ip Org asset type for a given IP Org asset.
function ipOrgAssetType(uint256 id_) external view returns (uint8);

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface IRegistrationModule {
/// @param ipOrgAssetId_ The IP Org localized id of the IP asset.
/// @param owner_ The address of the new IP asset owner.
/// @param name_ The name of the IP asset being registered.
/// @param ipAssetType_ The numerical id of the IP asset type.
/// @param ipOrgAssetType_ The numerical id of the IP asset type.
/// @param hash_ The content hash of the registered IP asset.
/// @param mediaUrl_ The media URL of the registered IP asset.
event IPAssetRegistered(
Expand All @@ -31,7 +31,7 @@ interface IRegistrationModule {
uint256 ipOrgAssetId_,
address indexed owner_,
string name_,
uint64 indexed ipAssetType_,
uint8 indexed ipOrgAssetType_,
bytes32 hash_,
string mediaUrl_
);
Expand Down Expand Up @@ -62,12 +62,18 @@ interface IRegistrationModule {
/// @notice Renders metadata of an IP Asset localized for an IP Org.
/// @param ipOrg_ The address of the IP Org of the IP asset.
/// @param ipOrgAssetId_ The local id of the IP asset within the IP Org.
/// @param ipOrgAssetType_ The IP Org asset type.
/// @return The token URI associated with the IP Org.
function tokenURI(address ipOrg_, uint256 ipOrgAssetId_) external view returns (string memory);
function tokenURI(address ipOrg_, uint256 ipOrgAssetId_, uint8 ipOrgAssetType_) external view returns (string memory);

/// @notice Gets the contract URI for an IP Org.
/// @param ipOrg_ The address of the IP Org.
/// @return The contract URI associated with the IP Org.
function contractURI(address ipOrg_) external view returns (string memory);

/// @notice get the ip Asset types of an ipOrg
function getIpOrgAssetTypes(address ipOrg_) external view returns (string[] memory);

/// @notice Returns true if the index for an IP Org asset type is supported.
function isValidIpOrgAssetType(address ipOrg_, uint8 index) external view returns (bool);
}
22 changes: 18 additions & 4 deletions contracts/ip-org/IPOrg.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,20 @@ contract IPOrg is
{

/// @notice Tracks the last index of the IP asset wrapper.
uint256 lastIndex = 0;
uint256 public lastIndex;

/// @notice Tracks the total number of IP Assets owned by the IP org.
uint256 totalSupply = 0;
uint256 public totalSupply;

// Address of the module registry.
IModuleRegistry public immutable MODULE_REGISTRY;

// Address of the IP Org Controller.
address public immutable CONTROLLER;

/// @notice Tracks the IP asset types associated with the each IP asset wrapper.
mapping(uint256 => uint8) private _ipOrgAssetTypes;

/// @notice Restricts calls to being through the registration module.
modifier onlyRegistrationModule() {
if (IModuleRegistry(MODULE_REGISTRY).protocolModule(ModuleRegistryKeys.REGISTRATION_MODULE) != msg.sender) {
Expand Down Expand Up @@ -67,7 +70,7 @@ contract IPOrg is
uint256 tokenId_
) public view override returns (string memory) {
address registrationModule = IModuleRegistry(MODULE_REGISTRY).protocolModule(ModuleRegistryKeys.REGISTRATION_MODULE);
return IRegistrationModule(registrationModule).tokenURI(address(this), tokenId_);
return IRegistrationModule(registrationModule).tokenURI(address(this), tokenId_, ipOrgAssetType(tokenId_));
}

/// @notice Retrieves the contract URI for the IP Org collection.
Expand Down Expand Up @@ -100,9 +103,10 @@ contract IPOrg is
}

/// @notice Registers a new IP Asset wrapper for the IP Org.
function mint(address owner_) public onlyRegistrationModule returns (uint256 id) {
function mint(address owner_, uint8 assetType_) public onlyRegistrationModule returns (uint256 id) {
totalSupply++;
id = ++lastIndex;
_ipOrgAssetTypes[id] = assetType_;
_mint(owner_, id);
}

Expand All @@ -125,4 +129,14 @@ contract IPOrg is
_transfer(from_, to_, id_);
}

/// Returns the IP Org asset type for a given IP Org asset.
/// @dev reverts if id does not exist.
function ipOrgAssetType(uint256 id_) public view returns (uint8) {
if (!_exists(id_)) {
revert Errors.IPOrg_IdDoesNotExist();
}
return _ipOrgAssetTypes[id_];
}


}
36 changes: 32 additions & 4 deletions contracts/lib/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,6 @@ library Errors {
////////////////////////////////////////////////////////////////////////////

error LibUintArrayMask_EmptyArray();
error LibUintArrayMask_UndefinedArrayElement();
/// @notice IP asset is invalid.
error LibUintArrayMask_InvalidType(IPAsset.IPAssetType ipAsset);

////////////////////////////////////////////////////////////////////////////
// IPOrg //
Expand All @@ -205,6 +202,9 @@ library Errors {
/// @notice Licensing is not configured.
error IPOrg_LicensingNotConfigured();

/// @notice IP Org wrapper id does not exist.
error IPOrg_IdDoesNotExist();

////////////////////////////////////////////////////////////////////////////
// IPOrgController //
////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -308,6 +308,13 @@ library Errors {
/// @notice The registration execution action is not valid.
error RegistrationModule_InvalidExecutionOperation();

/// @notice IP asset type is not in the list of supported types for
/// the IP Org.
error RegistrationModule_InvalidIPAssetType();

/// @notice IPAsset types provided are more than the maximum allowed.
error RegistrationModule_TooManyAssetTypes();

////////////////////////////////////////////////////////////////////////////
// RelationshipModule //
////////////////////////////////////////////////////////////////////////////
Expand All @@ -333,16 +340,37 @@ library Errors {
/// @notice The relationship destination IP type is not supported.
error RelationshipModule_UnsupportedRelationshipDst();

/// @notice Trying an unsupported config action
error RelationshipModule_InvalidConfigOperation();


/// @notice Unauthorized caller
error RelationshipModule_CallerNotIpOrgOwner();

/// @notice Value not on Relatable enum
error RelationshipModule_InvalidRelatable();

/// @notice Getting an invalid relationship type
error RelationshipModule_RelTypeNotSet(string relType);

/// @notice Relating invalid src addresss
error RelationshipModule_InvalidSrcAddress();

/// @notice Relating invalid dst addresss
error RelationshipModule_InvalidDstAddress();

/// @notice Relating unsupported src ipOrg asset type
error RelationshipModule_InvalidSrcId();

/// @notice Relating unsupported dst ipOrg asset type
error RelationshipModule_InvalidDstId();

/// @notice For IPORG_ENTRY - IPORG_ENTRY relationships,
/// ipOrg address must be set
error RelationshipModule_IpOrgRelatableCannotBeProtocolLevel();

/// @notice Index is not found for the asset types of that IP Org.
error RelationshipModule_UnsupportedIpOrgIndexType();

////////////////////////////////////////////////////////////////////////////
// RoyaltyNFT //
////////////////////////////////////////////////////////////////////////////
Expand Down
26 changes: 1 addition & 25 deletions contracts/lib/IPAsset.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,23 @@ import { Errors } from "./Errors.sol";
/// @title IP Asset Library
/// @notice Library for constants, structs, and helper functions for IP assets.
library IPAsset {
uint8 public constant EXTERNAL_ASSET = type(uint8).max;

uint256 private constant _ID_RANGE = 10 ** 12;

/// @notice Core attributes that make up an IP Asset.
struct IPA {
string name; // Human-readable identifier for the IP asset.
uint64 ipAssetType; // Numerical code corresponding to IP type (e.g. patent, copyright, etc.)
address registrant; // Address of the initial registrant of the IP asset.
uint8 status; // Current status of the IP asset (e.g. active, expired, etc.)
address ipOrg; // Address of the governing entity of the IP asset.
bytes32 hash; // A unique content hash of the IP asset for preserving integrity.
uint64 registrationDate; // Timestamp for which the IP asset was first registered.
}

enum IPAssetType {
UNDEFINED,
STORY,
CHARACTER,
ART,
GROUP,
LOCATION,
ITEM
}

/// @notice Struct for packing parameters related to IP asset registration.
struct RegisterIpAssetParams {
string name;
uint64 ipAssetType;
uint8 ipOrgAssetType;
address owner;
bytes32 hash;
string mediaUrl;
}

struct CreateIpAssetParams {
IPAsset.IPAssetType ipOrgAssetType;
uint64 ipAssetType;
string name;
bytes32 hash;
string mediaUrl;
bytes ipData;
}

}
3 changes: 1 addition & 2 deletions contracts/lib/LibUintArrayMask.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Errors } from "contracts/lib/Errors.sol";
/// @dev Gives tools to check if the "endpoints" of a relationship are valid, according to the allowed asset types set in the relationship config.
library LibUintArrayMask {

uint8 public constant UNDEFINED = 0;
// uint8 public constant UNDEFINED = 0;

/// @dev converts an array of types and the allows external flag to a mask, by setting the bits corresponding
/// to the uint8 equivalent of the IPAsset types to 1.
Expand All @@ -20,7 +20,6 @@ library LibUintArrayMask {
if (assetTypes_.length == 0) revert Errors.LibUintArrayMask_EmptyArray();
uint256 mask = 0;
for (uint256 i = 0; i < assetTypes_.length;) {
if (assetTypes_[i] == UNDEFINED) revert Errors.LibUintArrayMask_UndefinedArrayElement();
mask |= 1 << (uint256(assetTypes_[i]) & 0xff);
unchecked {
i++;
Expand Down
2 changes: 0 additions & 2 deletions contracts/lib/modules/LibRelationship.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ library LibRelationship {
string relType;
address srcAddress;
uint srcId;
uint8 srcType;
address dstAddress;
uint dstId;
uint8 dstType;
}

address public constant PROTOCOL_LEVEL_RELATIONSHIP = address(0);
Expand Down
2 changes: 1 addition & 1 deletion contracts/lib/modules/Registration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ library Registration {
/// @notice Struct used for IP asset registration.
struct RegisterIPAssetParams {
address owner;
uint8 ipOrgAssetType;
string name;
uint64 ipAssetType;
bytes32 hash;
string mediaUrl;
}
Expand Down
Loading

0 comments on commit f6d9079

Please sign in to comment.