{ "language": "Solidity", "settings": { "evmVersion": "london", "libraries": {}, "metadata": { "bytecodeHash": "ipfs", "useLiteralContent": true }, "optimizer": { "enabled": true, "runs": 200 }, "remappings": [], "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } } }, "sources": { "contracts/UnitLondonMarketplace.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nimport \"./utils/Proxy.sol\";\nimport \"./utils/RoyaltySplitter.sol\";\nimport \"./utils/Vault.sol\";\nimport \"./utils/IOwnable.sol\";\n\ninterface INFT {\n function mint(\n uint256 tokenId,\n string calldata metadata,\n address user\n ) external;\n\n function mint(\n uint256 tokenId,\n uint256 amount,\n string calldata metadata,\n address user\n ) external;\n\n function transferFrom(\n address from,\n address to,\n uint256 tokenId\n ) external;\n\n function safeTransferFrom(\n address from,\n address to,\n uint256 id,\n uint256 amount,\n bytes memory data\n ) external;\n\n function ownerOf(uint256 tokenId) external view returns (address);\n\n function balanceOf(address account, uint256 id) external view returns (uint256);\n\n function initialize(string calldata _name, string calldata _symbol) external;\n\n function transferOwnership(address newOwner) external;\n}\n\ncontract UnitLondonMarketplace is Vault, IOwnable {\n struct CollectionData {\n address artist;\n address splitter;\n uint32 mintFeePlatform;\n uint32 royaltyCollection;\n uint32 royaltyPlatform;\n uint32 logicIndex;\n string contractURI;\n }\n\n struct TokenData {\n uint256 price;\n uint256 amount;\n uint256 startDate;\n string metadata;\n }\n\n event CollectionRegistered(address collection, CollectionData data);\n event TokenUpdated(address collection, uint256 tokenId, TokenData data);\n event TokenSold(address collection, uint256 tokenId, uint256 amount, uint256 value);\n event TokenAirdropped(address collection, uint256 tokenId, address[] redeemers);\n event TokenRedeemed(address collection, uint256 tokenId, address[] redeemers, uint256[] prices);\n\n uint256 constant RATIO = 10000;\n\n address implementation_;\n address public override owner;\n bool public initialized;\n\n address[2] public logics;\n\n uint32 public mintFeePlatform;\n uint32 public royaltyPlatform;\n\n mapping(address => bool) public artists;\n\n mapping(address => CollectionData) public collections;\n mapping(address => mapping(uint256 => TokenData)) public tokens;\n\n function initialize(address[2] memory _logics) external onlyOwner {\n require(!initialized);\n initialized = true;\n\n logics = _logics;\n mintFeePlatform = 3000; // 30.00%\n royaltyPlatform = 200; // 2.00%\n\n emit OwnershipTransferred(address(0), msg.sender);\n }\n\n modifier onlyOwner() {\n require(msg.sender == owner);\n _;\n }\n\n function transferOwnership(address newOwner) public virtual override {\n require(msg.sender == owner);\n owner = newOwner;\n emit OwnershipTransferred(msg.sender, newOwner);\n }\n\n function setMintFeePlatform(uint32 newMintFeePlatform) external onlyOwner {\n mintFeePlatform = newMintFeePlatform;\n }\n\n function setRoyaltyPlatform(uint32 newRoyaltyPlatform) external onlyOwner {\n royaltyPlatform = newRoyaltyPlatform;\n }\n\n function setLogic(uint256 index, address newLogic) external onlyOwner {\n logics[index] = newLogic;\n }\n\n function setArtists(address[] calldata _artists) external onlyOwner {\n for (uint256 i = 0; i < _artists.length; i++) {\n artists[_artists[i]] = true;\n }\n }\n\n function removeArtist(address artist) external onlyOwner {\n delete artists[artist];\n }\n\n function withdraw() external onlyOwner {\n payable(owner).transfer(address(this).balance);\n }\n\n function escapeTokens(address token, uint256 amount) external onlyOwner {\n INFT(token).transferFrom(address(this), owner, amount);\n }\n\n function escapeSafeTokens(\n address token,\n uint256 id,\n uint256 amount\n ) external onlyOwner {\n INFT(token).safeTransferFrom(address(this), owner, id, amount, \"\");\n }\n\n function registerCollection(\n uint32 logicIndex,\n string calldata name,\n string calldata symbol,\n address artist,\n uint32 royaltyArtist,\n string calldata contractURI\n ) external {\n require(owner == msg.sender || artist == msg.sender, \"Invalid permission\");\n require(artists[artist], \"Invalid artist\");\n Proxy proxy = new Proxy();\n proxy.setImplementation(logics[logicIndex]);\n\n address collection = address(proxy);\n CollectionData storage data = collections[collection];\n data.artist = artist;\n data.splitter = address(new RoyaltySplitter());\n data.mintFeePlatform = mintFeePlatform;\n data.royaltyCollection = royaltyArtist + royaltyPlatform;\n data.royaltyPlatform = royaltyPlatform;\n data.logicIndex = logicIndex;\n data.contractURI = contractURI;\n\n INFT(collection).initialize(name, symbol);\n INFT(collection).transferOwnership(artist);\n\n emit CollectionRegistered(collection, data);\n }\n\n function collectionURI(address collection) external view returns (string memory) {\n return collections[collection].contractURI;\n }\n\n function syncLogic(Proxy collection) external {\n collection.setImplementation(logics[collections[address(collection)].logicIndex]);\n }\n\n function registerManifold(\n uint32 logicIndex,\n address manifold,\n address artist,\n string calldata contractURI\n ) external {\n require(owner == msg.sender || artist == msg.sender, \"Invalid permission\");\n require(artists[artist], \"Invalid artist\");\n\n CollectionData storage data = collections[manifold];\n require(data.artist == address(0), \"Invalid collection\");\n data.artist = artist;\n data.logicIndex = logicIndex;\n data.mintFeePlatform = mintFeePlatform;\n data.contractURI = contractURI;\n\n emit CollectionRegistered(manifold, data);\n }\n\n function addToken(\n address collection,\n uint256 tokenId,\n uint256 tokenLogic, // amount - 0 for 721, N for 1155\n uint256 price,\n uint256 startDate,\n string calldata metadata\n ) external {\n require(owner == msg.sender || collections[collection].artist == msg.sender, \"Invalid artist\");\n TokenData storage data = tokens[collection][tokenId];\n require(data.price == 0, \"Invalid token\");\n\n if (collections[collection].splitter == address(0)) {\n // Manifolds\n if (tokenLogic == 0) {\n // ERC721\n require(INFT(collection).ownerOf(tokenId) == address(this), \"Invalid owner\");\n } else {\n // ERC1155\n require(INFT(collection).balanceOf(address(this), tokenId) == tokenLogic, \"Invalid owner\");\n }\n } else {\n data.metadata = metadata;\n }\n\n data.amount = tokenLogic;\n data.price = price;\n data.startDate = startDate;\n\n emit TokenUpdated(collection, tokenId, data);\n }\n\n function updateTokenPrice(\n address collection,\n uint256 tokenId,\n uint256 price\n ) external {\n require(owner == msg.sender || collections[collection].artist == msg.sender, \"Invalid artist\");\n TokenData storage data = tokens[collection][tokenId];\n require(data.price > 0, \"Invalid token\");\n\n data.price = price;\n\n emit TokenUpdated(collection, tokenId, data);\n }\n\n function updateTokenStartDate(\n address collection,\n uint256 tokenId,\n uint256 startDate\n ) external {\n require(owner == msg.sender || collections[collection].artist == msg.sender, \"Invalid artist\");\n TokenData storage data = tokens[collection][tokenId];\n require(data.startDate > 0, \"Invalid token\");\n\n data.startDate = startDate;\n\n emit TokenUpdated(collection, tokenId, data);\n }\n\n function updateTokenMetadata(\n address collection,\n uint256 tokenId,\n string calldata metadata\n ) external {\n require(owner == msg.sender || collections[collection].artist == msg.sender, \"Invalid artist\");\n TokenData storage data = tokens[collection][tokenId];\n\n data.metadata = metadata;\n\n emit TokenUpdated(collection, tokenId, data);\n }\n\n function buy(\n address collection,\n uint256 tokenId,\n uint256 tokenLogic // amount - 0 for 721, N for 1155\n ) external payable {\n address user = msg.sender;\n uint256 value = msg.value;\n TokenData storage tokenData = tokens[collection][tokenId];\n\n CollectionData memory collectionData = collections[collection];\n uint256 fee = (value * collectionData.mintFeePlatform) / RATIO;\n payable(owner).transfer(fee);\n payable(collectionData.artist).transfer(value - fee);\n\n require(tokenData.price > 0, \"Invalid token\");\n require(tokenData.startDate < block.timestamp, \"Invalid sale\");\n if (tokenLogic == 0) {\n // ERC721\n require(tokenData.price == value, \"Invalid price\");\n\n if (collections[collection].splitter == address(0)) {\n // Manifolds\n INFT(collection).transferFrom(address(this), user, tokenId);\n } else {\n INFT(collection).mint(tokenId, tokenData.metadata, user);\n }\n tokenLogic = 1;\n } else {\n // ERC1155\n require(tokenData.price * tokenLogic == value, \"Invalid price\");\n\n if (collections[collection].splitter == address(0)) {\n // Manifolds\n INFT(collection).safeTransferFrom(address(this), user, tokenId, tokenLogic, \"\");\n } else {\n tokenData.amount = tokenData.amount - tokenLogic;\n INFT(collection).mint(tokenId, tokenLogic, tokenData.metadata, user);\n }\n }\n emit TokenSold(collection, tokenId, tokenLogic, value);\n }\n\n function airdrop(\n address collection,\n uint256 tokenId,\n address[] calldata redeemers\n ) external {\n // Only for ERC1155\n require(owner == msg.sender || collections[collection].artist == msg.sender, \"Invalid artist\");\n TokenData storage data = tokens[collection][tokenId];\n require(data.price > 0, \"Invalid token\");\n\n // ERC1155\n uint256 tokenLogic = redeemers.length;\n data.amount = data.amount - tokenLogic;\n for (uint256 i = 0; i < tokenLogic; i++) {\n INFT(collection).mint(tokenId, 1, data.metadata, redeemers[i]);\n }\n emit TokenAirdropped(collection, tokenId, redeemers);\n }\n\n function redeem(\n address collection,\n uint256 tokenId,\n address[] calldata redeemers,\n uint256[] calldata prices\n ) external {\n // Only for ERC1155\n require(owner == msg.sender || collections[collection].artist == msg.sender, \"Invalid artist\");\n TokenData storage data = tokens[collection][tokenId];\n require(data.price > 0, \"Invalid token\");\n\n // ERC1155\n uint256 tokenLogic = redeemers.length;\n data.amount = data.amount - tokenLogic;\n for (uint256 i = 0; i < tokenLogic; i++) {\n INFT(collection).mint(tokenId, 1, data.metadata, redeemers[i]);\n }\n emit TokenRedeemed(collection, tokenId, redeemers, prices);\n }\n\n function royaltyInfo(\n address collection,\n uint256,\n uint256 value\n ) external view returns (address, uint256) {\n CollectionData memory data = collections[collection];\n return (data.splitter, (value * data.royaltyCollection) / RATIO);\n }\n\n function collectRoyalties(address collection, ICoin[] calldata coins) external {\n address artist = msg.sender;\n CollectionData memory data = collections[collection];\n require(data.artist == artist, \"Invalid artist\");\n (uint256 balance, uint256[] memory coinBalances) = RoyaltySplitter(payable(data.splitter)).claim(coins);\n\n uint256 royalties = balance;\n uint256 feePlatform = (royalties * data.royaltyPlatform) / data.royaltyCollection;\n payable(owner).transfer(feePlatform);\n payable(artist).transfer(royalties - feePlatform);\n\n for (uint256 i = 0; i < coinBalances.length; i++) {\n royalties = coinBalances[i];\n feePlatform = (royalties * data.royaltyPlatform) / data.royaltyCollection;\n coins[i].transfer(owner, feePlatform);\n coins[i].transfer(artist, royalties - feePlatform);\n }\n }\n}\n" }, "contracts/utils/IOwnable.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\ninterface IOwnable {\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n function owner() external view returns (address);\n\n function transferOwnership(address newOwner) external;\n\n // function renounceOwnership() external;\n}\n" }, "contracts/utils/Proxy.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nimport \"./ProxyData.sol\";\n\n/**\n * @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM\n * instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to\n * be specified by overriding the virtual {_implementation} function.\n *\n * Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a\n * different contract through the {_delegate} function.\n *\n * The success and return data of the delegated call will be returned back to the caller of the proxy.\n */\ncontract Proxy is ProxyData {\n receive() external payable {}\n\n function setImplementation(address newImpl) public {\n require(msg.sender == admin);\n implementation_ = newImpl;\n }\n\n function implementation() public view returns (address impl) {\n impl = implementation_;\n }\n\n /**\n * @dev Delegates the current call to `implementation`.\n *\n * This function does not return to its internall call site, it will return directly to the external caller.\n */\n function _delegate(address implementation__) internal virtual {\n assembly {\n // Copy msg.data. We take full control of memory in this inline assembly\n // block because it will not return to Solidity code. We overwrite the\n // Solidity scratch pad at memory position 0.\n calldatacopy(0, 0, calldatasize())\n\n // Call the implementation.\n // out and outsize are 0 because we don't know the size yet.\n let result := delegatecall(gas(), implementation__, 0, calldatasize(), 0, 0)\n\n // Copy the returned data.\n returndatacopy(0, 0, returndatasize())\n\n switch result\n // delegatecall returns 0 on error.\n case 0 {\n revert(0, returndatasize())\n }\n default {\n return(0, returndatasize())\n }\n }\n }\n\n /**\n * @dev This is a virtual function that should be overriden so it returns the address to which the fallback function\n * and {_fallback} should delegate.\n */\n function _implementation() internal view returns (address) {\n return implementation_;\n }\n\n /**\n * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other\n * function in the contract matches the call data.\n */\n fallback() external payable virtual {\n _delegate(_implementation());\n }\n}\n" }, "contracts/utils/ProxyData.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\ncontract ProxyData {\n address implementation_;\n address public admin;\n\n constructor() {\n admin = msg.sender;\n }\n}\n" }, "contracts/utils/RoyaltySplitter.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\ninterface ICoin {\n function balanceOf(address) external view returns (uint256);\n\n function transfer(address, uint256) external returns (bool);\n}\n\ncontract RoyaltySplitter {\n address owner;\n\n constructor() {\n owner = msg.sender;\n }\n\n function claim(ICoin[] calldata coins) external returns (uint256 balance, uint256[] memory coinBalances) {\n require(owner == msg.sender);\n\n balance = address(this).balance;\n payable(owner).transfer(balance);\n\n uint256 coinCount = coins.length;\n coinBalances = new uint256[](coinCount);\n\n for (uint256 i = 0; i < coinCount; i++) {\n coinBalances[i] = coins[i].balanceOf(address(this));\n coins[i].transfer(owner, coinBalances[i]);\n }\n }\n\n fallback() external payable {}\n\n receive() external payable {}\n}\n" }, "contracts/utils/Vault.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\ncontract Vault {\n function onERC1155Received(\n address,\n address,\n uint256,\n uint256,\n bytes calldata\n ) public virtual returns (bytes4) {\n return this.onERC1155Received.selector;\n }\n\n function onERC1155BatchReceived(\n address,\n address,\n uint256[] calldata,\n uint256[] calldata,\n bytes calldata\n ) public virtual returns (bytes4) {\n return this.onERC1155BatchReceived.selector;\n }\n\n function onERC721Received(\n address,\n address,\n uint256,\n bytes calldata\n ) external virtual returns (bytes4) {\n return 0x150b7a02;\n }\n\n // Used by ERC721BasicToken.sol\n function onERC721Received(\n address,\n uint256,\n bytes calldata\n ) external virtual returns (bytes4) {\n return 0xf0b9e5ba;\n }\n\n receive() external payable {}\n}" } } }