diff --git a/contracts/ContractDeployer.sol b/contracts/ContractDeployer.sol deleted file mode 100644 index a784fede9..000000000 --- a/contracts/ContractDeployer.sol +++ /dev/null @@ -1,154 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -pragma solidity ^0.8.0; - -// ========== External imports ========== -import "@openzeppelin/contracts/utils/Create2.sol"; -import "@openzeppelin/contracts/proxy/Clones.sol"; -import "@openzeppelin/contracts/utils/Address.sol"; -import "@openzeppelin/contracts/utils/Multicall.sol"; -import "@openzeppelin/contracts/access/AccessControlEnumerable.sol"; -import "@openzeppelin/contracts/metatx/ERC2771Context.sol"; - -// ========== Internal imports ========== -import { IContractDeployer } from "./interfaces/IContractDeployer.sol"; -import { TWRegistry } from "./TWRegistry.sol"; -import { IContractMetadataRegistry } from "./interfaces/IContractMetadataRegistry.sol"; -import { ThirdwebContract } from "./ThirdwebContract.sol"; - -contract ContractDeployer is IContractDeployer, ERC2771Context, Multicall, AccessControlEnumerable { - /*/////////////////////////////////////////////////////////////// - State variables - //////////////////////////////////////////////////////////////*/ - - /// @dev The main thirdweb registry. - TWRegistry private immutable registry; - /// @dev The contract metadta registry. - IContractMetadataRegistry private immutable metadataRegistry; - /// @dev contract address deployed through the factory => deployer - mapping(address => address) public getContractDeployer; - - /// @dev Whether the registry is paused. - bool public isPaused; - - /*/////////////////////////////////////////////////////////////// - Constructor + modifiers - //////////////////////////////////////////////////////////////*/ - - /// @dev Checks whether contract is unpaused or the caller is a contract admin. - modifier onlyUnpausedOrAdmin() { - require(!isPaused || hasRole(DEFAULT_ADMIN_ROLE, _msgSender()), "registry paused"); - - _; - } - - constructor( - address _twRegistry, - address _metadataRegistry, - address _trustedForwarder - ) ERC2771Context(_trustedForwarder) { - registry = TWRegistry(_twRegistry); - metadataRegistry = IContractMetadataRegistry(_metadataRegistry); - _setupRole(DEFAULT_ADMIN_ROLE, _msgSender()); - } - - /*/////////////////////////////////////////////////////////////// - Deploy logic - //////////////////////////////////////////////////////////////*/ - - /// @notice Deploys an instance of a published contract directly. - function deployInstance( - address _publisher, - bytes memory _contractBytecode, - bytes memory _constructorArgs, - bytes32 _salt, - uint256 _value, - string memory publishMetadataUri - ) external onlyUnpausedOrAdmin returns (address deployedAddress) { - require(bytes(publishMetadataUri).length > 0, "No publish metadata"); - - address caller = _msgSender(); - - bytes memory contractBytecode = abi.encodePacked(_contractBytecode, _constructorArgs); - bytes32 salt = _salt == "" - ? keccak256(abi.encodePacked(caller, block.number, keccak256(contractBytecode))) - : keccak256(abi.encodePacked(caller, _salt)); - - // compute the address of the clone and save it - address computedContractAddress = Create2.computeAddress(salt, keccak256(contractBytecode), address(this)); - getContractDeployer[computedContractAddress] = caller; - - // deploy the contract - deployedAddress = Create2.deploy(_value, salt, contractBytecode); - - // set the owner - ThirdwebContract(deployedAddress).tw_initializeOwner(caller); - - // register to metadata registry - metadataRegistry.registerMetadata(deployedAddress, publishMetadataUri); - - // register to TWRegistry - registry.add(caller, deployedAddress); - - emit ContractDeployed(caller, _publisher, deployedAddress); - } - - /// @notice Deploys a clone pointing to an implementation of a published contract. - function deployInstanceProxy( - address _publisher, - address _implementation, - bytes memory _initializeData, - bytes32 _salt, - uint256 _value, - string memory publishMetadataUri - ) external onlyUnpausedOrAdmin returns (address deployedAddress) { - require(bytes(publishMetadataUri).length > 0, "No publish metadata"); - - address caller = _msgSender(); - - bytes32 salt = _salt == "" - ? keccak256(abi.encodePacked(caller, block.number, _implementation, _initializeData)) - : keccak256(abi.encodePacked(caller, _salt)); - - // compute the address of the clone and save it - address computedContractAddress = Clones.predictDeterministicAddress(_implementation, salt, address(this)); - getContractDeployer[computedContractAddress] = caller; - - // deploy the clone - deployedAddress = Clones.cloneDeterministic(_implementation, salt); - - // set the owner - ThirdwebContract(deployedAddress).tw_initializeOwner(caller); - - // register to metadata registry - metadataRegistry.registerMetadata(deployedAddress, publishMetadataUri); - - // register to TWRegistry - registry.add(caller, deployedAddress); - - if (_initializeData.length > 0) { - // slither-disable-next-line unused-return - Address.functionCallWithValue(deployedAddress, _initializeData, _value); - } - - emit ContractDeployed(caller, _publisher, deployedAddress); - } - - /*/////////////////////////////////////////////////////////////// - Miscellaneous - //////////////////////////////////////////////////////////////*/ - - /// @dev Lets a contract admin pause the registry. - function setPause(bool _pause) external { - require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()), "unapproved caller"); - isPaused = _pause; - emit Paused(_pause); - } - - function _msgSender() internal view virtual override(Context, ERC2771Context) returns (address sender) { - return ERC2771Context._msgSender(); - } - - function _msgData() internal view virtual override(Context, ERC2771Context) returns (bytes calldata) { - return ERC2771Context._msgData(); - } -} diff --git a/contracts/ContractMetadataRegistry.sol b/contracts/ContractMetadataRegistry.sol deleted file mode 100644 index 135d8dcab..000000000 --- a/contracts/ContractMetadataRegistry.sol +++ /dev/null @@ -1,57 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -pragma solidity ^0.8.0; - -// ========== External imports ========== -import "@openzeppelin/contracts/utils/Multicall.sol"; -import "@openzeppelin/contracts/access/AccessControlEnumerable.sol"; -import "@openzeppelin/contracts/metatx/ERC2771Context.sol"; - -// ========== Internal imports ========== -import { IContractMetadataRegistry } from "./interfaces/IContractMetadataRegistry.sol"; - -contract ContractMetadataRegistry is IContractMetadataRegistry, ERC2771Context, Multicall, AccessControlEnumerable { - /// @dev Only accounts with OPERATOR_ROLE can register metadata for contracts. - bytes32 public constant OPERATOR_ROLE = keccak256("OPERATOR_ROLE"); - - /*/////////////////////////////////////////////////////////////// - Mappings - //////////////////////////////////////////////////////////////*/ - - /// @dev contract address deployed => metadata uri - mapping(address => string) public getMetadataUri; - - /*/////////////////////////////////////////////////////////////// - Constructor - //////////////////////////////////////////////////////////////*/ - - constructor(address _trustedForwarder) ERC2771Context(_trustedForwarder) { - _setupRole(DEFAULT_ADMIN_ROLE, _msgSender()); - } - - /*/////////////////////////////////////////////////////////////// - External functions - //////////////////////////////////////////////////////////////*/ - - /// @dev Records `metadataUri` as metadata for the contract at `contractAddress`. - function registerMetadata(address contractAddress, string memory metadataUri) external { - require(hasRole(OPERATOR_ROLE, _msgSender()), "Not operator."); - require(bytes(metadataUri).length > 0, "No metadata"); - require(bytes(getMetadataUri[contractAddress]).length == 0, "Metadata already registered"); - - getMetadataUri[contractAddress] = metadataUri; - - emit MetadataRegistered(contractAddress, metadataUri); - } - - /*/////////////////////////////////////////////////////////////// - Miscellaneous - //////////////////////////////////////////////////////////////*/ - - function _msgSender() internal view virtual override(Context, ERC2771Context) returns (address sender) { - return ERC2771Context._msgSender(); - } - - function _msgData() internal view virtual override(Context, ERC2771Context) returns (bytes calldata) { - return ERC2771Context._msgData(); - } -} diff --git a/contracts/ContractPublisher.sol b/contracts/ContractPublisher.sol index 660a82d4d..10b3432ff 100644 --- a/contracts/ContractPublisher.sol +++ b/contracts/ContractPublisher.sol @@ -17,9 +17,6 @@ contract ContractPublisher is IContractPublisher, ERC2771Context, AccessControlE State variables //////////////////////////////////////////////////////////////*/ - /// @dev The global Id for publicly published contracts. - uint256 public nextPublicId = 1; - /// @dev Whether the registry is paused. bool public isPaused; @@ -27,11 +24,12 @@ contract ContractPublisher is IContractPublisher, ERC2771Context, AccessControlE Mappings //////////////////////////////////////////////////////////////*/ - /// @dev Mapping from public Id => publicly published contract. - mapping(uint256 => PublicContract) private publicContracts; - /// @dev Mapping from publisher address => set of published contracts. mapping(address => CustomContractSet) private contractsOfPublisher; + /// @dev Mapping publisher address => profile uri + mapping(address => string) private profileUriOfPublisher; + /// @dev Mapping compilerMetadataUri => publishedMetadataUri + mapping(string => PublishedMetadataSet) private compilerMetadataUriToPublishedMetadataUris; /*/////////////////////////////////////////////////////////////// Constructor + modifiers @@ -59,29 +57,6 @@ contract ContractPublisher is IContractPublisher, ERC2771Context, AccessControlE Getter logic //////////////////////////////////////////////////////////////*/ - /// @notice Returns the latest version of all contracts published by a publisher. - function getAllPublicPublishedContracts() external view returns (CustomContractInstance[] memory published) { - uint256 net; - - for (uint256 i = 0; i < nextPublicId; i += 1) { - PublicContract memory publicContract = publicContracts[i]; - if (publicContract.publisher != address(0)) { - net += 1; - } - } - - published = new CustomContractInstance[](net); - - for (uint256 i = 0; i < net; i += 1) { - PublicContract memory publicContract = publicContracts[i]; - if (publicContract.publisher != address(0)) { - published[i] = contractsOfPublisher[publicContract.publisher] - .contracts[keccak256(bytes(publicContract.contractId))] - .latest; - } - } - } - /// @notice Returns the latest version of all contracts published by a publisher. function getAllPublishedContracts(address _publisher) external @@ -123,12 +98,6 @@ contract ContractPublisher is IContractPublisher, ERC2771Context, AccessControlE published = contractsOfPublisher[_publisher].contracts[keccak256(bytes(_contractId))].latest; } - /// @notice Returns the public id of a published contract, if it is public. - function getPublicId(address _publisher, string memory _contractId) external view returns (uint256 publicId) { - bytes32 contractIdInBytes = keccak256(bytes(_contractId)); - publicId = contractsOfPublisher[_publisher].contracts[contractIdInBytes].publicId; - } - /*/////////////////////////////////////////////////////////////// Publish logic //////////////////////////////////////////////////////////////*/ @@ -136,10 +105,11 @@ contract ContractPublisher is IContractPublisher, ERC2771Context, AccessControlE /// @notice Let's an account publish a contract. The account must be approved by the publisher, or be the publisher. function publishContract( address _publisher, + string memory _contractId, string memory _publishMetadataUri, + string memory _compilerMetadataUri, bytes32 _bytecodeHash, - address _implementation, - string memory _contractId + address _implementation ) external onlyPublisher(_publisher) onlyUnpausedOrAdmin { CustomContractInstance memory publishedContract = CustomContractInstance({ contractId: _contractId, @@ -156,9 +126,12 @@ contract ContractPublisher is IContractPublisher, ERC2771Context, AccessControlE uint256 index = contractsOfPublisher[_publisher].contracts[contractIdInBytes].total; contractsOfPublisher[_publisher].contracts[contractIdInBytes].total += 1; - contractsOfPublisher[_publisher].contracts[contractIdInBytes].instances[index] = publishedContract; + uint256 metadataIndex = compilerMetadataUriToPublishedMetadataUris[_compilerMetadataUri].index; + compilerMetadataUriToPublishedMetadataUris[_compilerMetadataUri].uris[index] = _publishMetadataUri; + compilerMetadataUriToPublishedMetadataUris[_compilerMetadataUri].index = metadataIndex + 1; + emit ContractPublished(_msgSender(), _publisher, publishedContract); } @@ -178,31 +151,27 @@ contract ContractPublisher is IContractPublisher, ERC2771Context, AccessControlE emit ContractUnpublished(_msgSender(), _publisher, _contractId); } - /// @notice Lets an account add a published contract (and all its versions). The account must be approved by the publisher, or be the publisher. - function addToPublicList(address _publisher, string memory _contractId) external { - uint256 publicId = nextPublicId; - nextPublicId += 1; - - bytes32 contractIdInBytes = keccak256(bytes(_contractId)); - - PublicContract memory publicContract = PublicContract({ publisher: _publisher, contractId: _contractId }); - - contractsOfPublisher[_publisher].contracts[contractIdInBytes].publicId = publicId; - publicContracts[publicId] = publicContract; - - emit AddedContractToPublicList(_publisher, _contractId); + /// @notice Lets an account set its own publisher profile uri + function setPublisherProfileUri(address publisher, string memory uri) public onlyPublisher(publisher) { + profileUriOfPublisher[publisher] = uri; } - /// @notice Lets an account remove a published contract (and all its versions). The account must be approved by the publisher, or be the publisher. - function removeFromPublicList(address _publisher, string memory _contractId) external { - bytes32 contractIdInBytes = keccak256(bytes(_contractId)); - uint256 publicId = contractsOfPublisher[_publisher].contracts[contractIdInBytes].publicId; - - delete contractsOfPublisher[_publisher].contracts[contractIdInBytes].publicId; - - delete publicContracts[publicId]; + // @notice Get a publisher profile uri + function getPublisherProfileUri(address publisher) public view returns (string memory uri) { + uri = profileUriOfPublisher[publisher]; + } - emit RemovedContractToPublicList(_publisher, _contractId); + /// @notice Retrieve the published metadata URI from a compiler metadata URI + function getPublishedUriFromCompilerUri(string memory compilerMetadataUri) + public + view + returns (string[] memory publishedMetadataUris) + { + uint256 length = compilerMetadataUriToPublishedMetadataUris[compilerMetadataUri].index; + publishedMetadataUris = new string[](length); + for (uint256 i = 0; i < length; i += 1) { + publishedMetadataUris[i] = compilerMetadataUriToPublishedMetadataUris[compilerMetadataUri].uris[i]; + } } /*/////////////////////////////////////////////////////////////// diff --git a/contracts/ThirdwebContract.sol b/contracts/ThirdwebContract.sol deleted file mode 100644 index 1c52b55b8..000000000 --- a/contracts/ThirdwebContract.sol +++ /dev/null @@ -1,33 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -pragma solidity ^0.8.0; - -import "./feature/Ownable.sol"; -import "./interfaces/IContractDeployer.sol"; - -contract ThirdwebContract is Ownable { - uint256 private hasSetOwner; - - /// @dev Initializes the owner of the contract. - function tw_initializeOwner(address deployer) external { - require(hasSetOwner == 0, "Owner already initialized"); - hasSetOwner = 1; - owner = deployer; - } - - /// @dev Returns whether owner can be set - function _canSetOwner() internal virtual override returns (bool) { - return msg.sender == owner; - } - - /// @dev Enable access to the original contract deployer in the constructor. If this function is called outside of a constructor, it will return address(0) instead. - function _contractDeployer() internal view returns (address) { - if (address(this).code.length == 0) { - try IContractDeployer(msg.sender).getContractDeployer(address(this)) returns (address deployer) { - return deployer; - } catch { - return address(0); - } - } - return address(0); - } -} diff --git a/contracts/feature/interface/IPermissions.sol b/contracts/feature/interface/IPermissions.sol index 74ff3f108..9349d602c 100644 --- a/contracts/feature/interface/IPermissions.sol +++ b/contracts/feature/interface/IPermissions.sol @@ -43,12 +43,6 @@ interface IPermissions { */ function hasRole(bytes32 role, address account) external view returns (bool); - /** - * @dev Returns `true` if either (1) `account` has been granted `role`, or (2) the relevant role restrictions - * do not apply at the time of calling this function. - */ - function hasRoleWithSwitch(bytes32 role, address account) external view returns (bool); - /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. diff --git a/contracts/interfaces/IContractPublisher.sol b/contracts/interfaces/IContractPublisher.sol index fe4e6879b..d4e57a0e6 100644 --- a/contracts/interfaces/IContractPublisher.sol +++ b/contracts/interfaces/IContractPublisher.sol @@ -13,7 +13,6 @@ interface IContractPublisher { } struct CustomContract { - uint256 publicId; uint256 total; CustomContractInstance latest; mapping(uint256 => CustomContractInstance) instances; @@ -24,9 +23,9 @@ interface IContractPublisher { mapping(bytes32 => CustomContract) contracts; } - struct PublicContract { - address publisher; - string contractId; + struct PublishedMetadataSet { + uint256 index; + mapping(uint256 => string) uris; } /// @dev Emitted when the registry is paused. @@ -42,19 +41,6 @@ interface IContractPublisher { /// @dev Emitted when a contract is unpublished. event ContractUnpublished(address indexed operator, address indexed publisher, string indexed contractId); - /// @dev Emitted when a published contract is added to the public list. - event AddedContractToPublicList(address indexed publisher, string indexed contractId); - - /// @dev Emitted when a published contract is removed from the public list. - event RemovedContractToPublicList(address indexed publisher, string indexed contractId); - - /** - * @notice Returns the latest version of all contracts published by a publisher. - * - * @return published An array of all contracts published by the publisher. - */ - function getAllPublicPublishedContracts() external view returns (CustomContractInstance[] memory published); - /** * @notice Returns the latest version of all contracts published by a publisher. * @@ -93,33 +79,24 @@ interface IContractPublisher { view returns (CustomContractInstance memory published); - /** - * @notice Returns the public id of a published contract, if it is public. - * - * @param publisher The address of the publisher. - * @param contractId The identifier for a published contract (that can have multiple verisons). - * - * @return publicId the public id of a published contract. - */ - function getPublicId(address publisher, string memory contractId) external returns (uint256 publicId); - /** * @notice Let's an account publish a contract. The account must be approved by the publisher, or be the publisher. * - * @param publisher The address of the publisher. - * @param publishMetadataUri The IPFS URI of the publish metadata. - * @param bytecodeHash The keccak256 hash of the contract bytecode. - * @param implementation (Optional) An implementation address that proxy contracts / clones can point to. Default value - * if such an implementation does not exist - address(0); - * @param contractId The identifier for a published contract (that can have multiple verisons). - * + * @param publisher The address of the publisher. + * @param contractId The identifier for a published contract (that can have multiple verisons). + * @param publishMetadataUri The IPFS URI of the publish metadata. + * @param compilerMetadataUri The IPFS URI of the compiler metadata. + * @param bytecodeHash The keccak256 hash of the contract bytecode. + * @param implementation (Optional) An implementation address that proxy contracts / clones can point to. Default value + * if such an implementation does not exist - address(0); */ function publishContract( address publisher, + string memory contractId, string memory publishMetadataUri, + string memory compilerMetadataUri, bytes32 bytecodeHash, - address implementation, - string memory contractId + address implementation ) external; /** @@ -131,18 +108,20 @@ interface IContractPublisher { function unpublishContract(address publisher, string memory contractId) external; /** - * @notice Lets an account add a published contract (and all its versions). The account must be approved by the publisher, or be the publisher. - * - * @param publisher The address of the publisher. - * @param contractId The identifier for a published contract (that can have multiple verisons). + * @notice Lets an account set its publisher profile uri */ - function addToPublicList(address publisher, string memory contractId) external; + function setPublisherProfileUri(address publisher, string memory uri) external; /** - * @notice Lets an account remove a published contract (and all its versions). The account must be approved by the publisher, or be the publisher. - * - * @param publisher The address of the publisher. - * @param contractId The identifier for a published contract (that can have multiple verisons). + * @notice get the publisher profile uri */ - function removeFromPublicList(address publisher, string memory contractId) external; + function getPublisherProfileUri(address publisher) external view returns (string memory uri); + + /** + * @notice Retrieve the published metadata URI from a compiler metadata URI + */ + function getPublishedUriFromCompilerUri(string memory compilerMetadataUri) + external + view + returns (string[] memory publishedMetadataUris); } diff --git a/docs/ContractPublisher.md b/docs/ContractPublisher.md index 2e47ba51b..c290a6582 100644 --- a/docs/ContractPublisher.md +++ b/docs/ContractPublisher.md @@ -27,13 +27,13 @@ function DEFAULT_ADMIN_ROLE() external view returns (bytes32) |---|---|---| | _0 | bytes32 | undefined -### addToPublicList +### getAllPublishedContracts ```solidity -function addToPublicList(address _publisher, string _contractId) external nonpayable +function getAllPublishedContracts(address _publisher) external view returns (struct IContractPublisher.CustomContractInstance[] published) ``` -Lets an account add a published contract (and all its versions). The account must be approved by the publisher, or be the publisher. +Returns the latest version of all contracts published by a publisher. @@ -42,18 +42,6 @@ Lets an account add a published contract (and all its versions). The account mus | Name | Type | Description | |---|---|---| | _publisher | address | undefined -| _contractId | string | undefined - -### getAllPublicPublishedContracts - -```solidity -function getAllPublicPublishedContracts() external view returns (struct IContractPublisher.CustomContractInstance[] published) -``` - -Returns the latest version of all contracts published by a publisher. - - - #### Returns @@ -61,13 +49,13 @@ Returns the latest version of all contracts published by a publisher. |---|---|---| | published | IContractPublisher.CustomContractInstance[] | undefined -### getAllPublishedContracts +### getPublishedContract ```solidity -function getAllPublishedContracts(address _publisher) external view returns (struct IContractPublisher.CustomContractInstance[] published) +function getPublishedContract(address _publisher, string _contractId) external view returns (struct IContractPublisher.CustomContractInstance published) ``` -Returns the latest version of all contracts published by a publisher. +Returns the latest version of a contract published by a publisher. @@ -76,20 +64,21 @@ Returns the latest version of all contracts published by a publisher. | Name | Type | Description | |---|---|---| | _publisher | address | undefined +| _contractId | string | undefined #### Returns | Name | Type | Description | |---|---|---| -| published | IContractPublisher.CustomContractInstance[] | undefined +| published | IContractPublisher.CustomContractInstance | undefined -### getPublicId +### getPublishedContractVersions ```solidity -function getPublicId(address _publisher, string _contractId) external view returns (uint256 publicId) +function getPublishedContractVersions(address _publisher, string _contractId) external view returns (struct IContractPublisher.CustomContractInstance[] published) ``` -Returns the public id of a published contract, if it is public. +Returns all versions of a published contract. @@ -104,15 +93,15 @@ Returns the public id of a published contract, if it is public. | Name | Type | Description | |---|---|---| -| publicId | uint256 | undefined +| published | IContractPublisher.CustomContractInstance[] | undefined -### getPublishedContract +### getPublishedUriFromCompilerUri ```solidity -function getPublishedContract(address _publisher, string _contractId) external view returns (struct IContractPublisher.CustomContractInstance published) +function getPublishedUriFromCompilerUri(string compilerMetadataUri) external view returns (string[] publishedMetadataUris) ``` -Returns the latest version of a contract published by a publisher. +Retrieve the published metadata URI from a compiler metadata URI @@ -120,22 +109,21 @@ Returns the latest version of a contract published by a publisher. | Name | Type | Description | |---|---|---| -| _publisher | address | undefined -| _contractId | string | undefined +| compilerMetadataUri | string | undefined #### Returns | Name | Type | Description | |---|---|---| -| published | IContractPublisher.CustomContractInstance | undefined +| publishedMetadataUris | string[] | undefined -### getPublishedContractVersions +### getPublisherProfileUri ```solidity -function getPublishedContractVersions(address _publisher, string _contractId) external view returns (struct IContractPublisher.CustomContractInstance[] published) +function getPublisherProfileUri(address publisher) external view returns (string uri) ``` -Returns all versions of a published contract. +get the publisher profile uri @@ -143,14 +131,13 @@ Returns all versions of a published contract. | Name | Type | Description | |---|---|---| -| _publisher | address | undefined -| _contractId | string | undefined +| publisher | address | undefined #### Returns | Name | Type | Description | |---|---|---| -| published | IContractPublisher.CustomContractInstance[] | undefined +| uri | string | undefined ### getRoleAdmin @@ -320,27 +307,10 @@ function multicall(bytes[] data) external nonpayable returns (bytes[] results) |---|---|---| | results | bytes[] | undefined -### nextPublicId - -```solidity -function nextPublicId() external view returns (uint256) -``` - - - -*The global Id for publicly published contracts.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined - ### publishContract ```solidity -function publishContract(address _publisher, string _publishMetadataUri, bytes32 _bytecodeHash, address _implementation, string _contractId) external nonpayable +function publishContract(address _publisher, string _contractId, string _publishMetadataUri, string _compilerMetadataUri, bytes32 _bytecodeHash, address _implementation) external nonpayable ``` Let's an account publish a contract. The account must be approved by the publisher, or be the publisher. @@ -352,27 +322,11 @@ Let's an account publish a contract. The account must be approved by the pub | Name | Type | Description | |---|---|---| | _publisher | address | undefined +| _contractId | string | undefined | _publishMetadataUri | string | undefined +| _compilerMetadataUri | string | undefined | _bytecodeHash | bytes32 | undefined | _implementation | address | undefined -| _contractId | string | undefined - -### removeFromPublicList - -```solidity -function removeFromPublicList(address _publisher, string _contractId) external nonpayable -``` - -Lets an account remove a published contract (and all its versions). The account must be approved by the publisher, or be the publisher. - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| _publisher | address | undefined -| _contractId | string | undefined ### renounceRole @@ -424,6 +378,23 @@ function setPause(bool _pause) external nonpayable |---|---|---| | _pause | bool | undefined +### setPublisherProfileUri + +```solidity +function setPublisherProfileUri(address publisher, string uri) external nonpayable +``` + +Lets an account set its own publisher profile uri + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| publisher | address | undefined +| uri | string | undefined + ### supportsInterface ```solidity @@ -467,23 +438,6 @@ Lets an account unpublish a contract and all its versions. The account must be a ## Events -### AddedContractToPublicList - -```solidity -event AddedContractToPublicList(address indexed publisher, string indexed contractId) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| publisher `indexed` | address | undefined | -| contractId `indexed` | string | undefined | - ### ContractPublished ```solidity @@ -536,23 +490,6 @@ event Paused(bool isPaused) |---|---|---| | isPaused | bool | undefined | -### RemovedContractToPublicList - -```solidity -event RemovedContractToPublicList(address indexed publisher, string indexed contractId) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| publisher `indexed` | address | undefined | -| contractId `indexed` | string | undefined | - ### RoleAdminChanged ```solidity diff --git a/docs/IContractPublisher.md b/docs/IContractPublisher.md index 9362e3b38..8c174b009 100644 --- a/docs/IContractPublisher.md +++ b/docs/IContractPublisher.md @@ -10,13 +10,13 @@ ## Methods -### addToPublicList +### getAllPublishedContracts ```solidity -function addToPublicList(address publisher, string contractId) external nonpayable +function getAllPublishedContracts(address publisher) external view returns (struct IContractPublisher.CustomContractInstance[] published) ``` -Lets an account add a published contract (and all its versions). The account must be approved by the publisher, or be the publisher. +Returns the latest version of all contracts published by a publisher. @@ -25,18 +25,6 @@ Lets an account add a published contract (and all its versions). The account mus | Name | Type | Description | |---|---|---| | publisher | address | The address of the publisher. -| contractId | string | The identifier for a published contract (that can have multiple verisons). - -### getAllPublicPublishedContracts - -```solidity -function getAllPublicPublishedContracts() external view returns (struct IContractPublisher.CustomContractInstance[] published) -``` - -Returns the latest version of all contracts published by a publisher. - - - #### Returns @@ -44,13 +32,13 @@ Returns the latest version of all contracts published by a publisher. |---|---|---| | published | IContractPublisher.CustomContractInstance[] | An array of all contracts published by the publisher. -### getAllPublishedContracts +### getPublishedContract ```solidity -function getAllPublishedContracts(address publisher) external view returns (struct IContractPublisher.CustomContractInstance[] published) +function getPublishedContract(address publisher, string contractId) external view returns (struct IContractPublisher.CustomContractInstance published) ``` -Returns the latest version of all contracts published by a publisher. +Returns the latest version of a contract published by a publisher. @@ -59,20 +47,21 @@ Returns the latest version of all contracts published by a publisher. | Name | Type | Description | |---|---|---| | publisher | address | The address of the publisher. +| contractId | string | The identifier for a published contract (that can have multiple verisons). #### Returns | Name | Type | Description | |---|---|---| -| published | IContractPublisher.CustomContractInstance[] | An array of all contracts published by the publisher. +| published | IContractPublisher.CustomContractInstance | The desired contract published by the publisher. -### getPublicId +### getPublishedContractVersions ```solidity -function getPublicId(address publisher, string contractId) external nonpayable returns (uint256 publicId) +function getPublishedContractVersions(address publisher, string contractId) external view returns (struct IContractPublisher.CustomContractInstance[] published) ``` -Returns the public id of a published contract, if it is public. +Returns all versions of a published contract. @@ -87,15 +76,15 @@ Returns the public id of a published contract, if it is public. | Name | Type | Description | |---|---|---| -| publicId | uint256 | the public id of a published contract. +| published | IContractPublisher.CustomContractInstance[] | The desired contracts published by the publisher. -### getPublishedContract +### getPublishedUriFromCompilerUri ```solidity -function getPublishedContract(address publisher, string contractId) external view returns (struct IContractPublisher.CustomContractInstance published) +function getPublishedUriFromCompilerUri(string compilerMetadataUri) external view returns (string[] publishedMetadataUris) ``` -Returns the latest version of a contract published by a publisher. +Retrieve the published metadata URI from a compiler metadata URI @@ -103,22 +92,21 @@ Returns the latest version of a contract published by a publisher. | Name | Type | Description | |---|---|---| -| publisher | address | The address of the publisher. -| contractId | string | The identifier for a published contract (that can have multiple verisons). +| compilerMetadataUri | string | undefined #### Returns | Name | Type | Description | |---|---|---| -| published | IContractPublisher.CustomContractInstance | The desired contract published by the publisher. +| publishedMetadataUris | string[] | undefined -### getPublishedContractVersions +### getPublisherProfileUri ```solidity -function getPublishedContractVersions(address publisher, string contractId) external view returns (struct IContractPublisher.CustomContractInstance[] published) +function getPublisherProfileUri(address publisher) external view returns (string uri) ``` -Returns all versions of a published contract. +get the publisher profile uri @@ -126,19 +114,18 @@ Returns all versions of a published contract. | Name | Type | Description | |---|---|---| -| publisher | address | The address of the publisher. -| contractId | string | The identifier for a published contract (that can have multiple verisons). +| publisher | address | undefined #### Returns | Name | Type | Description | |---|---|---| -| published | IContractPublisher.CustomContractInstance[] | The desired contracts published by the publisher. +| uri | string | undefined ### publishContract ```solidity -function publishContract(address publisher, string publishMetadataUri, bytes32 bytecodeHash, address implementation, string contractId) external nonpayable +function publishContract(address publisher, string contractId, string publishMetadataUri, string compilerMetadataUri, bytes32 bytecodeHash, address implementation) external nonpayable ``` Let's an account publish a contract. The account must be approved by the publisher, or be the publisher. @@ -150,18 +137,19 @@ Let's an account publish a contract. The account must be approved by the pub | Name | Type | Description | |---|---|---| | publisher | address | The address of the publisher. +| contractId | string | The identifier for a published contract (that can have multiple verisons). | publishMetadataUri | string | The IPFS URI of the publish metadata. +| compilerMetadataUri | string | The IPFS URI of the compiler metadata. | bytecodeHash | bytes32 | The keccak256 hash of the contract bytecode. -| implementation | address | (Optional) An implementation address that proxy contracts / clones can point to. Default value if such an implementation does not exist - address(0); -| contractId | string | The identifier for a published contract (that can have multiple verisons). +| implementation | address | (Optional) An implementation address that proxy contracts / clones can point to. Default value if such an implementation does not exist - address(0); -### removeFromPublicList +### setPublisherProfileUri ```solidity -function removeFromPublicList(address publisher, string contractId) external nonpayable +function setPublisherProfileUri(address publisher, string uri) external nonpayable ``` -Lets an account remove a published contract (and all its versions). The account must be approved by the publisher, or be the publisher. +Lets an account set its publisher profile uri @@ -169,8 +157,8 @@ Lets an account remove a published contract (and all its versions). The account | Name | Type | Description | |---|---|---| -| publisher | address | The address of the publisher. -| contractId | string | The identifier for a published contract (that can have multiple verisons). +| publisher | address | undefined +| uri | string | undefined ### unpublishContract @@ -193,23 +181,6 @@ Lets an account unpublish a contract and all its versions. The account must be a ## Events -### AddedContractToPublicList - -```solidity -event AddedContractToPublicList(address indexed publisher, string indexed contractId) -``` - - - -*Emitted when a published contract is added to the public list.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| publisher `indexed` | address | undefined | -| contractId `indexed` | string | undefined | - ### ContractPublished ```solidity @@ -262,22 +233,5 @@ event Paused(bool isPaused) |---|---|---| | isPaused | bool | undefined | -### RemovedContractToPublicList - -```solidity -event RemovedContractToPublicList(address indexed publisher, string indexed contractId) -``` - - - -*Emitted when a published contract is removed from the public list.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| publisher `indexed` | address | undefined | -| contractId `indexed` | string | undefined | - diff --git a/docs/IPermissions.md b/docs/IPermissions.md index 50a5a426a..53354534f 100644 --- a/docs/IPermissions.md +++ b/docs/IPermissions.md @@ -72,29 +72,6 @@ function hasRole(bytes32 role, address account) external view returns (bool) |---|---|---| | _0 | bool | undefined -### hasRoleWithSwitch - -```solidity -function hasRoleWithSwitch(bytes32 role, address account) external view returns (bool) -``` - - - -*Returns `true` if either (1) `account` has been granted `role`, or (2) the relevant role restrictions do not apply at the time of calling this function.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| role | bytes32 | undefined -| account | address | undefined - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | bool | undefined - ### renounceRole ```solidity diff --git a/docs/IPermissionsEnumerable.md b/docs/IPermissionsEnumerable.md index 50bba4a37..1ff75fd42 100644 --- a/docs/IPermissionsEnumerable.md +++ b/docs/IPermissionsEnumerable.md @@ -117,29 +117,6 @@ function hasRole(bytes32 role, address account) external view returns (bool) |---|---|---| | _0 | bool | undefined -### hasRoleWithSwitch - -```solidity -function hasRoleWithSwitch(bytes32 role, address account) external view returns (bool) -``` - - - -*Returns `true` if either (1) `account` has been granted `role`, or (2) the relevant role restrictions do not apply at the time of calling this function.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| role | bytes32 | undefined -| account | address | undefined - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | bool | undefined - ### renounceRole ```solidity diff --git a/docs/Multiwrap.md b/docs/Multiwrap.md index 06f1685fc..341b6dc0b 100644 --- a/docs/Multiwrap.md +++ b/docs/Multiwrap.md @@ -401,7 +401,7 @@ function hasRoleWithSwitch(bytes32 role, address account) external view returns -*Returns `true` if either (1) `account` has been granted `role`, or (2) the relevant role restrictions do not apply at the time of calling this function.* + #### Parameters diff --git a/docs/Pack.md b/docs/Pack.md index 38846b1c7..b84070868 100644 --- a/docs/Pack.md +++ b/docs/Pack.md @@ -415,7 +415,7 @@ function hasRoleWithSwitch(bytes32 role, address account) external view returns -*Returns `true` if either (1) `account` has been granted `role`, or (2) the relevant role restrictions do not apply at the time of calling this function.* + #### Parameters diff --git a/docs/Permissions.md b/docs/Permissions.md index 09b3600cf..4daf95192 100644 --- a/docs/Permissions.md +++ b/docs/Permissions.md @@ -97,7 +97,7 @@ function hasRoleWithSwitch(bytes32 role, address account) external view returns -*Returns `true` if either (1) `account` has been granted `role`, or (2) the relevant role restrictions do not apply at the time of calling this function.* + #### Parameters diff --git a/docs/PermissionsEnumerable.md b/docs/PermissionsEnumerable.md index c093ca26c..1e5c2768a 100644 --- a/docs/PermissionsEnumerable.md +++ b/docs/PermissionsEnumerable.md @@ -142,7 +142,7 @@ function hasRoleWithSwitch(bytes32 role, address account) external view returns -*Returns `true` if either (1) `account` has been granted `role`, or (2) the relevant role restrictions do not apply at the time of calling this function.* + #### Parameters diff --git a/docs/SignatureDrop.md b/docs/SignatureDrop.md index 10c47c753..021c773db 100644 --- a/docs/SignatureDrop.md +++ b/docs/SignatureDrop.md @@ -504,7 +504,7 @@ function hasRoleWithSwitch(bytes32 role, address account) external view returns -*Returns `true` if either (1) `account` has been granted `role`, or (2) the relevant role restrictions do not apply at the time of calling this function.* + #### Parameters diff --git a/src/test/ContractPublisher.t.sol b/src/test/ContractPublisher.t.sol index 2bb7b4048..e227925f8 100644 --- a/src/test/ContractPublisher.t.sol +++ b/src/test/ContractPublisher.t.sol @@ -51,6 +51,7 @@ contract ContractPublisherTest is BaseTest, IContractPublisherData { address internal deployerOfPublished; string internal publishMetadataUri = "ipfs://QmeXyz"; + string internal compilerMetadataUri = "ipfs://QmeXyz"; function setUp() public override { super.setUp(); @@ -68,10 +69,11 @@ contract ContractPublisherTest is BaseTest, IContractPublisherData { vm.prank(publisher); byoc.publishContract( publisher, + contractId, publishMetadataUri, + compilerMetadataUri, keccak256(type(MockCustomContract).creationCode), - address(0), - contractId + address(0) ); IContractPublisher.CustomContractInstance memory customContract = byoc.getPublishedContract( @@ -120,10 +122,11 @@ contract ContractPublisherTest is BaseTest, IContractPublisherData { vm.prank(operator); byoc.publishContract( publisher, + contractId, publishMetadataUri, + compilerMetadataUri, keccak256(type(MockCustomContract).creationCode), - address(0), - contractId + address(0) ); } @@ -138,10 +141,11 @@ contract ContractPublisherTest is BaseTest, IContractPublisherData { vm.prank(publisher); byoc.publishContract( publisher, + contractId, publishMetadataUri, + compilerMetadataUri, keccak256(type(MockCustomContract).creationCode), - address(0), - contractId + address(0) ); } @@ -181,10 +185,11 @@ contract ContractPublisherTest is BaseTest, IContractPublisherData { vm.prank(publisher); byoc.publishContract( publisher, + contractId, publishMetadataUri, + compilerMetadataUri, keccak256(type(MockCustomContract).creationCode), - address(0), - contractId + address(0) ); vm.prank(publisher); @@ -237,10 +242,11 @@ contract ContractPublisherTest is BaseTest, IContractPublisherData { vm.prank(publisher); byoc.publishContract( publisher, + contractId, publishMetadataUri, + compilerMetadataUri, keccak256(type(MockCustomContract).creationCode), - address(0), - contractId + address(0) ); vm.expectRevert("unapproved caller"); @@ -255,10 +261,11 @@ contract ContractPublisherTest is BaseTest, IContractPublisherData { vm.prank(publisher); byoc.publishContract( publisher, + contractId, publishMetadataUri, + compilerMetadataUri, keccak256(type(MockCustomContract).creationCode), - address(0), - contractId + address(0) ); vm.prank(factoryAdmin); diff --git a/src/test/ThirdwebContract.t.sol b/src/test/ThirdwebContract.t.sol deleted file mode 100644 index f61a5b144..000000000 --- a/src/test/ThirdwebContract.t.sol +++ /dev/null @@ -1,48 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -pragma solidity ^0.8.11; - -// Test imports -import "./utils/BaseTest.sol"; -import "contracts/TWFactory.sol"; -import "contracts/TWRegistry.sol"; - -// Helpers -import "@openzeppelin/contracts/utils/Create2.sol"; -import "@openzeppelin/contracts/proxy/Clones.sol"; -import "contracts/TWProxy.sol"; -import "contracts/ThirdwebContract.sol"; - -contract MyThirdwebContract is ThirdwebContract { - address public contractDeployerFromConstructor; - - constructor() { - contractDeployerFromConstructor = _contractDeployer(); - } - - function getContractDeployerOutsideFromConstructor() public view returns (address) { - return _contractDeployer(); - } -} - -contract ThirdwebContractTest is BaseTest { - function setUp() public override { - super.setUp(); - } - - function getContractDeployer(address) public pure returns (address) { - return address(42); - } - - function deployContract() public returns (address) { - return Create2.deploy(0, keccak256(abi.encode(0)), type(MyThirdwebContract).creationCode); - } - - function test_ThirdwebContract_ContractDeployerConstructor() external { - address addy = deployContract(); - address contractDeployer = MyThirdwebContract(addy).contractDeployerFromConstructor(); - address contractDeployerNotConstructor = MyThirdwebContract(addy).getContractDeployerOutsideFromConstructor(); - - assertEq(contractDeployer, getContractDeployer(addy)); - assertEq(contractDeployerNotConstructor, address(0)); - } -} diff --git a/src/test/utils/BaseTest.sol b/src/test/utils/BaseTest.sol index b2facfe52..eb55c1c49 100644 --- a/src/test/utils/BaseTest.sol +++ b/src/test/utils/BaseTest.sol @@ -26,7 +26,6 @@ import "contracts/marketplace/Marketplace.sol"; import "contracts/vote/VoteERC20.sol"; import { SignatureDrop } from "contracts/signature-drop/SignatureDrop.sol"; import { ContractPublisher } from "contracts/ContractPublisher.sol"; -import { ContractDeployer } from "contracts/ContractDeployer.sol"; import "contracts/mock/Mock.sol"; abstract contract BaseTest is DSTest, Test {