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

Updated solhint with new rules, cleared errors. #112

Merged
merged 4 commits into from
Sep 29, 2023
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
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ env:
FOUNDRY_PROFILE: ci

jobs:

foundry-test:
strategy:
fail-fast: true
Expand Down
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"trailingComma": "es5",
"tabWidth": 4,
"semi": false,
"singleQuote": false
"singleQuote": false,
"bracketSpacing": true
}
16 changes: 8 additions & 8 deletions .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
"plugins": ["prettier"],
"rules": {
"code-complexity": ["error", 8],
"compiler-version": ["error", ">=0.5.8"],
"compiler-version": ["error", ">=0.8.0"],
"const-name-snakecase": "off",
"constructor-syntax": "error",
"func-visibility": ["error", { "ignoreConstructors": true }],
"max-line-length": ["error", 120],
"not-rely-on-time": "off",
"prettier/prettier": [
"error",
{
"endOfLine": "auto"
}
],
"reason-string": ["warn", { "maxLength": 64 }]
"reason-string": ["warn", { "maxLength": 64 }],
"no-unused-import": "error",
"no-unused-vars": "error",
"no-inline-assembly": "off",
"avoid-low-level-calls": "off",
"no-global-import": "error",
"prettier/prettier": "error"
}
}
6 changes: 1 addition & 5 deletions contracts/FranchiseRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.13;

import { IPAsset } from "./IPAsset.sol";
import { IPAssetRegistryFactory } from "./ip-assets/IPAssetRegistryFactory.sol";
import { AccessControlledUpgradeable } from "./access-control/AccessControlledUpgradeable.sol";
import { UPGRADER_ROLE } from "./access-control/ProtocolRoles.sol";
import { ZeroAddress, Unauthorized } from "./errors/General.sol";
import { ZeroAddress } from "./errors/General.sol";
import { IVersioned } from "./utils/IVersioned.sol";
import { IIPAssetRegistry } from "./ip-assets/IIPAssetRegistry.sol";
import { LibIPAssetId } from "./ip-assets/LibIPAssetId.sol";
import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import { ERC721Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
import { IERC721 } from "@openzeppelin/contracts/token/ERC721/IERC721.sol";

contract FranchiseRegistry is
UUPSUpgradeable,
Expand Down Expand Up @@ -113,7 +110,6 @@ contract FranchiseRegistry is
}
}


function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
_requireMinted(tokenId);
FranchiseStorage storage $ = _getFranchiseStorage();
Expand Down
7 changes: 6 additions & 1 deletion contracts/access-control/AccessControlSingleton.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils

// TODO: Evaluate making this contract AccessControlEnumerableUpgradeable so it could enforce unique roles
// (as in only 1 address can have a role at a time)
contract AccessControlSingleton is AccessControlUpgradeable, UUPSUpgradeable, Multicall, IVersioned {
contract AccessControlSingleton is
AccessControlUpgradeable,
UUPSUpgradeable,
Multicall,
IVersioned
{

string public constant version = "0.1.0";

Expand Down
9 changes: 6 additions & 3 deletions contracts/access-control/AccessControlled.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
pragma solidity ^0.8.9;

import { IAccessControl } from "@openzeppelin/contracts/access/IAccessControl.sol";
import { ERC165CheckerUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/introspection/ERC165CheckerUpgradeable.sol";
import { ERC165CheckerUpgradeable }
from "@openzeppelin/contracts-upgradeable/utils/introspection/ERC165CheckerUpgradeable.sol";
import { PROTOCOL_ADMIN_ROLE } from "./ProtocolRoles.sol";
import { UnsupportedInterface } from "../errors/General.sol";

Expand All @@ -28,7 +29,8 @@ abstract contract AccessControlled {
}

constructor(address accessControl) {
if (!accessControl.supportsInterface(type(IAccessControl).interfaceId)) revert UnsupportedInterface("IAccessControl");
if (!accessControl.supportsInterface(type(IAccessControl).interfaceId))
revert UnsupportedInterface("IAccessControl");
_accessControl = IAccessControl(accessControl);
emit AccessControlUpdated(accessControl);
}
Expand All @@ -48,7 +50,8 @@ abstract contract AccessControlled {
* @param accessControl address of the new instance of AccessControlSingleton.
*/
function setAccessControl(address accessControl) public onlyRole(PROTOCOL_ADMIN_ROLE) {
if (!accessControl.supportsInterface(type(IAccessControl).interfaceId)) revert UnsupportedInterface("IAccessControl");
if (!accessControl.supportsInterface(type(IAccessControl).interfaceId))
revert UnsupportedInterface("IAccessControl");
_accessControl = IAccessControl(accessControl);
emit AccessControlUpdated(accessControl);
}
Expand Down
9 changes: 6 additions & 3 deletions contracts/access-control/AccessControlledUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ pragma solidity ^0.8.9;

import { IAccessControl } from "@openzeppelin/contracts/access/IAccessControl.sol";
import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import { ERC165CheckerUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/introspection/ERC165CheckerUpgradeable.sol";
import { ERC165CheckerUpgradeable }
from "@openzeppelin/contracts-upgradeable/utils/introspection/ERC165CheckerUpgradeable.sol";
import { PROTOCOL_ADMIN_ROLE } from "./ProtocolRoles.sol";
import { UnsupportedInterface } from "../errors/General.sol";

Expand Down Expand Up @@ -39,7 +40,8 @@ abstract contract AccessControlledUpgradeable is UUPSUpgradeable {
* @param accessControl address of AccessManager.
*/
function __AccessControlledUpgradeable_init(address accessControl) internal initializer {
if (!accessControl.supportsInterface(type(IAccessControl).interfaceId)) revert UnsupportedInterface("IAccessControl");
if (!accessControl.supportsInterface(type(IAccessControl).interfaceId))
revert UnsupportedInterface("IAccessControl");
AccessControlledStorage storage $ = _getAccessControlledUpgradeable();
$.accessControl = IAccessControl(accessControl);
emit AccessControlUpdated(accessControl);
Expand Down Expand Up @@ -67,7 +69,8 @@ abstract contract AccessControlledUpgradeable is UUPSUpgradeable {
* @param accessControl address of the new instance of AccessControlSingleton.
*/
function setAccessControl(address accessControl) public onlyRole(PROTOCOL_ADMIN_ROLE) {
if (!accessControl.supportsInterface(type(IAccessControl).interfaceId)) revert UnsupportedInterface("IAccessControl");
if (!accessControl.supportsInterface(type(IAccessControl).interfaceId))
revert UnsupportedInterface("IAccessControl");
AccessControlledStorage storage $ = _getAccessControlledUpgradeable();
$.accessControl = IAccessControl(accessControl);
emit AccessControlUpdated(accessControl);
Expand Down
5 changes: 4 additions & 1 deletion contracts/interfaces/ICollectModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ interface ICollectModule is ICollectModuleEventsAndErrors {
/// collector address, and generic unformatted collect and NFT data.
/// @return collectNFT The address of the collected NFT.
/// @return collectNFTId The id of the collected collect NFT.
function collect(CollectParams calldata collectParams) external payable returns (address collectNFT, uint256 collectNFTId);
function collect(CollectParams calldata collectParams)
external
payable
returns (address collectNFT, uint256 collectNFTId);

/// @notice Returns the collect NFT address associated with an IP asset.
/// @param franchiseId The id of the franchise of the specified IP asset.
Expand Down
6 changes: 5 additions & 1 deletion contracts/interfaces/ICollectPaymentModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ interface ICollectPaymentModule is ICollectModule, ICollectPaymentModuleEventsAn
/// collector address, and collect payment module processing data.
/// @return collectNFT The address of the collected NFT.
/// @return collectNFTId The id of the collected collect NFT.
function collect(CollectParams calldata collectParams) external payable override(ICollectModule) returns (address collectNFT, uint256 collectNFTId);
function collect(CollectParams calldata collectParams)
external
payable
override(ICollectModule)
returns (address collectNFT, uint256 collectNFTId);

}
6 changes: 3 additions & 3 deletions contracts/ip-accounts/IIPAccount.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.13;

import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import "@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol";
import "./IERC6551Account.sol";
import { IERC721Receiver} from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import { IERC1155Receiver } from "@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol";
import { IERC6551Account } from "./IERC6551Account.sol";

interface IIPAccount is IERC6551Account, IERC721Receiver, IERC1155Receiver {
function safeTransferFrom(address nftContract, address from, address to, uint256 tokenId) external;
Expand Down
25 changes: 13 additions & 12 deletions contracts/ip-accounts/IPAccountImpl.sol
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.13;

import "@openzeppelin/contracts/interfaces/IERC1271.sol";
import "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol";
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import "@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "./IERC6551Account.sol";
import "./IIPAccount.sol";
import { IERC1271 } from "@openzeppelin/contracts/interfaces/IERC1271.sol";
import { SignatureChecker } from "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol";
import { IERC165 } from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IERC721 } from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import { IERC721Receiver } from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import { IERC1155Receiver } from "@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { IERC6551Account } from "./IERC6551Account.sol";
import { IIPAccount } from "./IIPAccount.sol";

/**
* @title IPAccountImpl
Expand All @@ -23,6 +22,8 @@ contract IPAccountImpl is
{
using SafeERC20 for IERC20;

error CalletNotOwner();

uint256 public state;
// ERC20 token => amount
mapping(address => uint256) public entitled;
Expand Down Expand Up @@ -106,7 +107,7 @@ contract IPAccountImpl is
* @dev {See IIPAccount-safeTransferFrom}
*/
function safeTransferFrom(address nftContract, address from, address to, uint256 tokenId) external {
require(_isValidSigner(msg.sender), "Caller is not owner");
if (!_isValidSigner(msg.sender)) revert CalletNotOwner();
++state;
IERC721(nftContract).safeTransferFrom(from, to, tokenId);
}
Expand Down
4 changes: 2 additions & 2 deletions contracts/ip-accounts/IPAccountRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.13;

import "@openzeppelin/contracts/utils/Create2.sol";
import "./IIPAccountRegistry.sol";
import { Create2} from "@openzeppelin/contracts/utils/Create2.sol";
import { IIPAccountRegistry } from "./IIPAccountRegistry.sol";

contract IPAccountRegistry is IIPAccountRegistry {
address internal immutable IP_ACCOUNT_IMPL;
Expand Down
61 changes: 51 additions & 10 deletions contracts/ip-assets/IPAssetRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.13;
import { IIPAssetRegistry } from "./IIPAssetRegistry.sol";
import { ICollectModule } from "contracts/interfaces/ICollectModule.sol";
import { LibIPAssetId } from "./LibIPAssetId.sol";
import { Unauthorized, ZeroAmount, ZeroAddress } from "../errors/General.sol";
import { ZeroAmount, ZeroAddress } from "../errors/General.sol";
import { IPAsset } from "contracts/IPAsset.sol";
import { InitCollectParams } from "contracts/lib/CollectModuleStructs.sol";
import { IIPAssetEventEmitter } from "./events/IIPAssetEventEmitter.sol";
Expand Down Expand Up @@ -41,7 +41,12 @@ contract IPAssetRegistry is
string private constant _VERSION = "0.1.0";
uint256 private constant _ROOT_IP_ASSET = 0;

constructor(address _eventEmitter, address _licensingModule, address _franchiseRegistry, address _collectModule) RightsManager(_franchiseRegistry) {
constructor(
address _eventEmitter,
address _licensingModule,
address _franchiseRegistry,
address _collectModule)
RightsManager(_franchiseRegistry) {
// TODO: should Franchise owner be able to change this?
if (_eventEmitter == address(0)) revert ZeroAddress();
EVENT_EMITTER = IIPAssetEventEmitter(_eventEmitter);
Expand Down Expand Up @@ -81,8 +86,10 @@ contract IPAssetRegistry is
}

/**
* Creates a new IPAsset, and assigns licenses (rights) to it, according to the Franchise config in LicensingModule.
* A Non commercial license is always assigned, and if the IPAsset is a root IPAsset, a commercial license may also be assigned.
* Creates a new IPAsset, and assigns licenses (rights) to it, according to the Franchise
* config in LicensingModule.
* A Non commercial license is always assigned, and if the IPAsset is a root IPAsset,
* a commercial license may also be assigned.
* @dev reverts if LicensingModule is not configured for the Franchise.
* Logs to IPAssetEventEmitter, common contract for all IPAsset registries.
* @param ipAssetType the type of IPAsset to create
Expand Down Expand Up @@ -117,12 +124,27 @@ contract IPAssetRegistry is
ILicensingModule.FranchiseConfig memory config = LICENSING_MODULE.getFranchiseConfig(_franchiseId);
if (config.revoker == address(0)) revert LicensingNotConfigured();

_setNonCommercialRights(ipAssetId, parentIpAssetId, to, config.revoker, config.nonCommercialConfig, config.nonCommercialTerms);
_setNonCommercialRights(
ipAssetId,
parentIpAssetId,
to,
config.revoker,
config.nonCommercialConfig,
config.nonCommercialTerms
);
// If non derivative IpAsset, then franchise config may dictate commercial rights
// Derivative works do not have commercial rights unless a deal with the relevant licensor is made
if (config.rootIpAssetHasCommercialRights && parentIpAssetId == 0) {
// Commercial
_setCommercialRights(ipAssetId, _ROOT_IP_ASSET, to, config.revoker, config.commercialLicenseUri, config.commercialConfig, config.commercialTerms);
_setCommercialRights(
ipAssetId,
_ROOT_IP_ASSET,
to,
config.revoker,
config.commercialLicenseUri,
config.commercialConfig,
config.commercialTerms
);
}
// TODO: Add collect NFT impl and data overrides
COLLECT_MODULE.initCollect(InitCollectParams({
Expand All @@ -144,8 +166,17 @@ contract IPAssetRegistry is
* @param config Franchise config
* @param terms for the license to be active
*/
function _setNonCommercialRights(uint256 ipAssetId, uint256 parentIpAssetId, address holder, address revoker, ILicensingModule.IpAssetConfig memory config, TermsProcessorConfig memory terms) internal {
uint256 parentLicenseId = parentIpAssetId == 0 ? config.franchiseRootLicenseId : getLicenseIdByTokenId(parentIpAssetId, false);
function _setNonCommercialRights(
uint256 ipAssetId,
uint256 parentIpAssetId,
address holder,
address revoker,
ILicensingModule.IpAssetConfig memory config,
TermsProcessorConfig memory terms
) internal {
uint256 parentLicenseId = parentIpAssetId == 0 ?
config.franchiseRootLicenseId :
getLicenseIdByTokenId(parentIpAssetId, false);
_createLicense(
ipAssetId,
parentLicenseId,
Expand All @@ -169,8 +200,18 @@ contract IPAssetRegistry is
* @param config Franchise config
* @param terms for the license to be active
*/
function _setCommercialRights(uint256 ipAssetId, uint256 parentIpAssetId, address holder, address revoker, string memory licenseUri, ILicensingModule.IpAssetConfig memory config, TermsProcessorConfig memory terms) internal {
uint256 parentLicenseId = parentIpAssetId == _ROOT_IP_ASSET ? config.franchiseRootLicenseId : getLicenseIdByTokenId(parentIpAssetId, true);
function _setCommercialRights(
uint256 ipAssetId,
uint256 parentIpAssetId,
address holder,
address revoker,
string memory licenseUri,
ILicensingModule.IpAssetConfig memory config,
TermsProcessorConfig memory terms
) internal {
uint256 parentLicenseId = parentIpAssetId == _ROOT_IP_ASSET ?
config.franchiseRootLicenseId :
getLicenseIdByTokenId(parentIpAssetId, true);
_createLicense(
ipAssetId,
parentLicenseId,
Expand Down
10 changes: 7 additions & 3 deletions contracts/ip-assets/IPAssetRegistryFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pragma solidity ^0.8.13;

import { IIPAssetRegistry } from "./IIPAssetRegistry.sol";
import { IPAssetRegistry } from "./IPAssetRegistry.sol";
import { ZeroAddress } from "../errors/General.sol";
import { IVersioned } from "../utils/IVersioned.sol";
import { UnsupportedInterface } from "../errors/General.sol";
import { LicenseRegistry } from "../modules/licensing/LicenseRegistry.sol";
Expand Down Expand Up @@ -41,15 +40,20 @@ contract IPAssetRegistryFactory is Ownable {
description
);
address proxy = address(new BeaconProxy(address(BEACON), data));
LicenseRegistry licenseRegistry = new LicenseRegistry(proxy, string.concat("Licenses for ", name), string.concat("sl", symbol));
LicenseRegistry licenseRegistry = new LicenseRegistry(
proxy,
string.concat("Licenses for ", name),
string.concat("sl", symbol)
);
IPAssetRegistry(proxy).setLicenseRegistry(address(licenseRegistry));

emit FranchiseCreated(proxy, name, symbol);
return proxy;
}

function upgradeFranchises(address newImplementation) external onlyOwner {
if (!newImplementation.supportsInterface(type(IIPAssetRegistry).interfaceId)) revert UnsupportedInterface("IIPAssetRegistry");
if (!newImplementation.supportsInterface(type(IIPAssetRegistry).interfaceId))
revert UnsupportedInterface("IIPAssetRegistry");
BEACON.upgradeTo(newImplementation);
emit FranchisesUpgraded(address(newImplementation), IVersioned(newImplementation).version());
}
Expand Down
4 changes: 1 addition & 3 deletions contracts/utils/IVersioned.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,5 @@
pragma solidity ^0.8.13;

interface IVersioned {

function version() external pure returns (string memory);

}
}
6 changes: 5 additions & 1 deletion contracts/utils/RevertingIPAssetRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ pragma solidity ^0.8.13;
* breaking a circular dependency on creation and keeping the beacon immutable
*/
contract RevertingIPAssetRegistry {
error DontUseThisContract();

}
function initialize() external pure {
revert DontUseThisContract();
}
}
Loading