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

Commit

Permalink
Fixes linting
Browse files Browse the repository at this point in the history
  • Loading branch information
leeren committed Jan 20, 2024
1 parent 32dbdde commit eafd446
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 170 deletions.
9 changes: 0 additions & 9 deletions contracts/interfaces/resolvers/IIPMetadataResolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ interface IIPMetadataResolver is IResolver {
/// @param ipId The canonical ID of the specified IP.
function name(address ipId) external view returns (string memory);

/// @notice Fetches the category associated with the specified IP.
/// @param ipId The canonical ID of the specified IP.
function category(address ipId) external view returns (IP.Category);

/// @notice Fetches the description associated with the specified IP.
/// @param ipId The canonical ID of the specified IP.
/// @return The string descriptor of the IP.
Expand Down Expand Up @@ -55,11 +51,6 @@ interface IIPMetadataResolver is IResolver {
/// @param name The string name to associate with the IP.
function setName(address ipId, string calldata name) external;

/// @notice Sets the category associated with an IP.
/// @param ipId The canonical ID of the specified IP.
/// @param category The IP category to associate with the IP.
function setCategory(address ipId, IP.Category category) external;

/// @notice Sets the description associated with an IP.
/// @param ipId The canonical ID of the specified IP.
/// @param description The string description to associate with the IP.
Expand Down
4 changes: 1 addition & 3 deletions contracts/lib/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ pragma solidity ^0.8.19;
/// @title Errors Library
/// @notice Library for all Story Protocol contract errors.
library Errors {

////////////////////////////////////////////////////////////////////////////
// IPRecordRegistry //
////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -38,7 +37,7 @@ library Errors {
////////////////////////////////////////////////////////////////////////////
// LicenseRegistry //
////////////////////////////////////////////////////////////////////////////

/// @notice Error thrown when a policy is already set for an IP ID.
error LicenseRegistry__PolicyAlreadySetForIpId();
error LicenseRegistry__FrameworkNotFound();
Expand Down Expand Up @@ -71,5 +70,4 @@ library Errors {
error AccessController__SignerIsZeroAddress();
error AccessController__CallerIsNotIPAccount();
error AccessController__PermissionIsNotValid();

}
64 changes: 26 additions & 38 deletions contracts/lib/IP.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,39 @@ pragma solidity ^0.8.21;
/// @title IP Library
/// @notice Library for constants, structs, and helper functions used for IP.
library IP {

/// @notice List of IP categories currently declared in Story Protocol..
/// @custom:note Later on this may be canonicalized in the licensing module.
enum Category {
PATENT,
TRADEMARK,
COPYRIGHT
}

/// @notice Core metadata associated with an IP.
struct Metadata {
address owner; // The current owner of the IP.
string name; // The name associated with the IP.
Category category; // The overarching category the IP belongs to.
string description; // A description associated with the IP.
bytes32 hash; // A keccak-256 hash of the IP content.
uint64 registrationDate; // The date which the IP was registered.
address registrant; // The address of the initial IP registrant.
string uri; // The token URI associated with the IP.
// The current owner of the IP.
address owner;
// The name associated with the IP.
string name;
// A description associated with the IP.
string description;
// A keccak-256 hash of the IP content.
bytes32 hash;
// The date which the IP was registered.
uint64 registrationDate;
// The address of the initial IP registrant.
address registrant;
// The token URI associated with the IP.
string uri;
}

/// @notice Core metadata exclusively saved by the IP resolver.
/// @dev Resolved attributes not referenced here are processed through
/// their corresponding data modules (e.g. licensing for license data).
struct MetadataRecord {
string name; // The name associated with the IP.
Category category; // The overarching category the IP belongs to.
string description; // A description associated with the IP.
bytes32 hash; // A keccak-256 hash of the IP content.
uint64 registrationDate; // The date which the IP was registered.
address registrant; // The address of the initial IP registrant.
string uri; // The token URI associated with the IP.
// The name associated with the IP.
string name;
// A description associated with the IP.
string description;
// A keccak-256 hash of the IP content.
bytes32 hash;
// The date which the IP was registered.
uint64 registrationDate;
// The address of the initial IP registrant.
address registrant;
// The token URI associated with the IP.
string uri;
}


/// @notice Converts a custom IP category type to its string representation.
/// @param category The category of the IP.
function toString(Category category) internal pure returns (string memory) {
if (category == Category.PATENT) {
return "Patent";
} else if (category == Category.TRADEMARK) {
return "Trademark";
} else {
return "Copyright";
}
}

}
1 change: 0 additions & 1 deletion contracts/registries/IPAccountRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { IERC6551Registry } from "lib/reference/src/interfaces/IERC6551Registry.
/// @notice This contract is responsible for managing the registration and tracking of IP Accounts.
/// It leverages a public ERC6551 registry to deploy IPAccount contracts.
contract IPAccountRegistry is IIPAccountRegistry {

address public immutable IP_ACCOUNT_IMPL;
bytes32 public immutable IP_ACCOUNT_SALT;
address public immutable ERC6551_PUBLIC_REGISTRY;
Expand Down
52 changes: 12 additions & 40 deletions contracts/registries/IPRecordRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@ import { IModuleRegistry } from "contracts/interfaces/registries/IModuleRegistry
import { Errors } from "contracts/lib/Errors.sol";

/// @title IP Record Registry
/// @notice This contract acts as the source of truth for all IP registered in
/// @notice This contract acts as the source of truth for all IP registered in
/// Story Protocol. An IP is identified by its contract address, token
/// id, and coin type, meaning any NFT may be conceptualized as an IP.
/// Once an IP is registered into the protocol, a corresponding IP
/// record is generated, which references an IP resolver for metadata
/// attribution and an IP account for protocol authorization. Only
/// attribution and an IP account for protocol authorization. Only
/// approved registration modules may register IP into this registry.
/// IMPORTANT: The IP account address, besides being used for protocol
/// auth, is also the canonical IP identifier for the IP NFT.
contract IPRecordRegistry is IIPRecordRegistry {

/// @notice Gets the factory contract used for IP account creation.
IIPAccountRegistry public immutable IP_ACCOUNT_REGISTRY;

Expand All @@ -34,7 +33,7 @@ contract IPRecordRegistry is IIPRecordRegistry {

/// @notice Restricts calls to only originate from the registration module.
modifier onlyRegistrationModule() {
if (address(MODULE_REGISTRY.protocolModule(REGISTRATION_MODULE_KEY)) != msg.sender) {
if (address(MODULE_REGISTRY.getModule(REGISTRATION_MODULE_KEY)) != msg.sender) {
revert Errors.IPRecordRegistry_Unauthorized();
}
_;
Expand All @@ -54,20 +53,14 @@ contract IPRecordRegistry is IIPRecordRegistry {
/// @param tokenContract The address of the IP.
/// @param tokenId The token identifier of the IP.
/// @return The IP's canonical address identifier.
function ipId(
uint256 chainId,
address tokenContract,
uint256 tokenId
) public view returns (address) {
function ipId(uint256 chainId, address tokenContract, uint256 tokenId) public view returns (address) {
return IP_ACCOUNT_REGISTRY.ipAccount(chainId, tokenContract, tokenId);
}

/// @notice Checks whether an IP was registered based on its ID.
/// @param id The canonical identifier for the IP.
/// @return Whether the IP was registered into the protocol.
function isRegistered(
address id
) external view returns (bool) {
function isRegistered(address id) external view returns (bool) {
return _resolvers[id] != address(0);
}

Expand All @@ -76,21 +69,15 @@ contract IPRecordRegistry is IIPRecordRegistry {
/// @param tokenContract The address of the NFT.
/// @param tokenId The token identifier of the NFT.
/// @return Whether the NFT was registered into the protocol as IP.
function isRegistered(
uint256 chainId,
address tokenContract,
uint256 tokenId
) external view returns (bool) {
function isRegistered(uint256 chainId, address tokenContract, uint256 tokenId) external view returns (bool) {
address id = ipId(chainId, tokenContract, tokenId);
return _resolvers[id] != address(0);
}

/// @notice Gets the resolver bound to an IP based on its ID.
/// @param id The canonical identifier for the IP.
/// @return The IP resolver address if registered, else the zero address.
function resolver(
address id
) external view returns (address) {
function resolver(address id) external view returns (address) {
return _resolvers[id];
}

Expand All @@ -99,11 +86,7 @@ contract IPRecordRegistry is IIPRecordRegistry {
/// @param tokenContract The address of the NFT.
/// @param tokenId The token identifier of the NFT.
/// @return The IP resolver address if registered, else the zero address.
function resolver(
uint256 chainId,
address tokenContract,
uint256 tokenId
) external view returns (address) {
function resolver(uint256 chainId, address tokenContract, uint256 tokenId) external view returns (address) {
address id = ipId(chainId, tokenContract, tokenId);
return _resolvers[id];
}
Expand All @@ -125,7 +108,7 @@ contract IPRecordRegistry is IIPRecordRegistry {
revert Errors.IPRecordRegistry_AlreadyRegistered();
}

// This is to emphasize the semantic differences between utilizing the
// This is to emphasize the semantic differences between utilizing the
// IP account as an identifier versus as an account used for auth.
address account = id;

Expand All @@ -145,11 +128,7 @@ contract IPRecordRegistry is IIPRecordRegistry {
/// @param chainId The chain identifier of where the NFT resides.
/// @param tokenContract The address of the NFT.
/// @param tokenId The token identifier of the NFT.
function createIPAccount(
uint256 chainId,
address tokenContract,
uint256 tokenId
) external returns (address) {
function createIPAccount(uint256 chainId, address tokenContract, uint256 tokenId) external returns (address) {
address account = IP_ACCOUNT_REGISTRY.ipAccount(chainId, tokenContract, tokenId);
if (account.code.length != 0) {
revert Errors.IPRecordRegistry_IPAccountAlreadyCreated();
Expand All @@ -175,10 +154,7 @@ contract IPRecordRegistry is IIPRecordRegistry {
/// @notice Sets the resolver for an IP based on its canonical ID.
/// @param id The canonical ID of the IP.
/// @param resolverAddr The address of the resolver being set.
function setResolver(
address id,
address resolverAddr
) public onlyRegistrationModule {
function setResolver(address id, address resolverAddr) public onlyRegistrationModule {
if (resolverAddr == address(0)) {
revert Errors.IPRecordRegistry_ResolverInvalid();
}
Expand All @@ -204,12 +180,8 @@ contract IPRecordRegistry is IIPRecordRegistry {
/// @dev Sets the resolver for the specified IP.
/// @param id The canonical identifier for the specified IP.
/// @param resolverAddr The address of the IP resolver.
function _setResolver(
address id,
address resolverAddr
) internal {
function _setResolver(address id, address resolverAddr) internal {
_resolvers[id] = resolverAddr;
emit IPResolverSet(id, resolverAddr);
}

}
44 changes: 12 additions & 32 deletions contracts/resolvers/IPMetadataResolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { IP } from "contracts/lib/IP.sol";
/// likely change to a separate contract that extends IPMetadataResolver
/// in the near future.
contract IPMetadataResolver is IIPMetadataResolver, ResolverBase {

/// @dev Maps IP to their metadata records based on their canonical IDs.
mapping(address => IP.MetadataRecord) public _records;

Expand All @@ -34,16 +33,16 @@ contract IPMetadataResolver is IIPMetadataResolver, ResolverBase {
/// @param ipId The canonical ID of the specified IP.
function metadata(address ipId) public view returns (IP.Metadata memory) {
IP.MetadataRecord memory record = _records[ipId];
return IP.Metadata({
owner: owner(ipId),
name: record.name,
category: record.category,
description: record.description,
hash: record.hash,
registrationDate: record.registrationDate,
registrant: record.registrant,
uri: tokenURI(ipId)
});
return
IP.Metadata({
owner: owner(ipId),
name: record.name,
description: record.description,
hash: record.hash,
registrationDate: record.registrationDate,
registrant: record.registrant,
uri: tokenURI(ipId)
});
}

/// @notice Fetches the canonical name associated with the specified IP.
Expand All @@ -52,12 +51,6 @@ contract IPMetadataResolver is IIPMetadataResolver, ResolverBase {
return _records[ipId].name;
}

/// @notice Fetches the category associated with an IP.
/// @param ipId The canonical ID of the specified IP.
function category(address ipId) external view returns (IP.Category) {
return _records[ipId].category;
}

/// @notice Fetches the description associated with the specified IP.
/// @param ipId The canonical ID of the specified IP.
/// @return The string descriptor of the IP.
Expand Down Expand Up @@ -103,7 +96,7 @@ contract IPMetadataResolver is IIPMetadataResolver, ResolverBase {
IP.MetadataRecord memory record = _records[ipId];
string memory uri = record.uri;

if (bytes(uri).length > 0) {
if (bytes(uri).length > 0) {
return uri;
}

Expand All @@ -124,13 +117,6 @@ contract IPMetadataResolver is IIPMetadataResolver, ResolverBase {
_records[ipId].name = newName;
}

/// @notice Sets the category associated with an IP.
/// @param ipId The canonical ID of the specified IP.
/// @param newCategory The IP category to associate with the IP.
function setCategory(address ipId, IP.Category newCategory) external onlyAuthorized(ipId) {
_records[ipId].category = newCategory;
}

/// @notice Sets the description associated with an IP.
/// @param ipId The canonical ID of the specified IP.
/// @param newDescription The string description to associate with the IP.
Expand All @@ -156,8 +142,7 @@ contract IPMetadataResolver is IIPMetadataResolver, ResolverBase {
/// @param id The resolver interface identifier.
/// @return Whether the resolver interface is supported.
function supportsInterface(bytes4 id) public view virtual override(IResolver, ResolverBase) returns (bool) {
return id == type(IIPMetadataResolver).interfaceId ||
super.supportsInterface(id);
return id == type(IIPMetadataResolver).interfaceId || super.supportsInterface(id);
}

/// @dev Internal function for generating a default IP URI if not provided.
Expand Down Expand Up @@ -185,9 +170,6 @@ contract IPMetadataResolver is IIPMetadataResolver, ResolverBase {
'{"trait_type": "Owner", "value": "',
Strings.toHexString(uint160(owner(ipId)), 20),
'"},'
'{"trait_type": "Category", "value": "',
IP.toString(record.category),
'"},',
'{"trait_type": "Registrant", "value": "',
Strings.toHexString(uint160(record.registrant), 20),
'"},',
Expand All @@ -208,7 +190,5 @@ contract IPMetadataResolver is IIPMetadataResolver, ResolverBase {
Base64.encode(bytes(string(abi.encodePacked(baseJson, ipAttributes, "]}"))))
)
);

}

}
4 changes: 1 addition & 3 deletions contracts/resolvers/ResolverBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { Errors } from "contracts/lib/Errors.sol";

/// @notice IP Resolver Base Contract
abstract contract ResolverBase is IResolver {

/// @notice Gets the protocol-wide module access controller.
IAccessController public immutable ACCESS_CONTROLLER;

Expand All @@ -23,7 +22,7 @@ abstract contract ResolverBase is IResolver {
/// @notice Checks if IP identified by ipId is authorized to perform a call.
/// @param ipId The identifier for the IP being authorized.
modifier onlyAuthorized(address ipId) {
if (!ACCESS_CONTROLLER.checkPolicy(ipId, msg.sender, address(this), msg.sig)) {
if (!ACCESS_CONTROLLER.checkPermission(ipId, msg.sender, address(this), msg.sig)) {
revert Errors.IPResolver_Unauthorized();
}
_;
Expand Down Expand Up @@ -51,5 +50,4 @@ abstract contract ResolverBase is IResolver {
function supportsInterface(bytes4 id) public view virtual override returns (bool) {
return id == type(IResolver).interfaceId;
}

}
Loading

0 comments on commit eafd446

Please sign in to comment.