├── README.md ├── .gitattributes └── contracts ├── Migrations.sol ├── library └── Governance.sol ├── FeeManager.sol ├── interface ├── RoyaltyFactory.sol └── RoyaltyFactorySecondary.sol ├── INft_Marketplace.sol ├── CifiPowa.sol ├── ArtGallery.sol ├── ArtFactory.sol ├── TokenizedArt.sol ├── TokenizedArtFactory.sol └── Fixed_Marketplace.sol /README.md: -------------------------------------------------------------------------------- 1 | # Smartcontract_ERC721_ERC1155 2 | asd 3 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require( 10 | msg.sender == owner, 11 | "This function is restricted to the contract's owner" 12 | ); 13 | _; 14 | } 15 | 16 | function setCompleted(uint completed) public restricted { 17 | last_completed_migration = completed; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /contracts/library/Governance.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.8.4; 3 | 4 | contract Governance { 5 | address public _governance; 6 | 7 | constructor() { 8 | _governance = tx.origin; 9 | } 10 | 11 | event GovernanceTransferred( 12 | address indexed previousOwner, 13 | address indexed newOwner 14 | ); 15 | 16 | modifier onlyGovernance { 17 | require(msg.sender == _governance, "not governance"); 18 | _; 19 | } 20 | 21 | function setGovernance(address governance) public onlyGovernance { 22 | require(governance != address(0), "new governance the zero address"); 23 | emit GovernanceTransferred(_governance, governance); 24 | _governance = governance; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /contracts/FeeManager.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.4.22 <0.9.0; 4 | 5 | import "@openzeppelin/contracts/access/Ownable.sol"; 6 | 7 | contract FeeManager is Ownable { 8 | event ChangedFeePerMillion(uint256 cutPerMillion); 9 | 10 | // Market fee on sales 11 | uint256 public cutPerMillion = 30000; //3% cut 12 | uint256 public constant maxCutPerMillion = 100000; // 10% cut 13 | 14 | /** 15 | * Sets the share cut for the owner of the contract that's 16 | * charged to the seller on a successful sale 17 | * Share amount, from 0 to 99,999 18 | */ 19 | function setOwnerCutPerMillion(uint256 _cutPerMillion) external onlyOwner { 20 | require( 21 | _cutPerMillion < maxCutPerMillion, 22 | "The owner cut should be between 0 and maxCutPerMillion" 23 | ); 24 | 25 | cutPerMillion = _cutPerMillion; 26 | emit ChangedFeePerMillion(cutPerMillion); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /contracts/interface/RoyaltyFactory.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.8.4; 3 | import "@openzeppelin/contracts/introspection/ERC165.sol"; 4 | 5 | contract RoyaltyFactory is ERC165 { 6 | mapping(uint256 => address) _originalCreators; 7 | mapping(uint256 => uint256) _royaltyFees; // 100% = 1000000, 1% = 10000 8 | /* 9 | * bytes4(keccak256('setRoyaltyFee(uint256, uint256)')) == 0x4e30ff2d 10 | * bytes4(keccak256('setOriginalCreator(uint256, uint256)')) == 0x1db8209f 11 | * bytes4(keccak256('getRoyaltyFee(uint256)')) == 0x9e4c0141 12 | * bytes4(keccak256('getOriginalCreator(uint256)')) == 0xcaa47fbf 13 | * 14 | * => 0x4e30ff2d ^ 0x1db8209f ^ 0x9e4c0141 ^ 0xcaa47fbf == 0x0760a14c 15 | */ 16 | bytes4 private constant _INTERFACE_ID_ROYALTY = 0x0760a14c; 17 | 18 | constructor() { 19 | _registerInterface(_INTERFACE_ID_ROYALTY); 20 | } 21 | 22 | function setRoyaltyFee(uint256 tokenID, uint256 fee) internal { 23 | _royaltyFees[tokenID] = fee; 24 | } 25 | 26 | function setOriginalCreator(uint256 tokenID, address creator) internal { 27 | _originalCreators[tokenID] = creator; 28 | } 29 | 30 | function getRoyaltyFee(uint256 tokenID) 31 | public 32 | view 33 | virtual 34 | returns (uint256) 35 | { 36 | return _royaltyFees[tokenID]; 37 | } 38 | 39 | function getOriginalCreator(uint256 tokenID) 40 | public 41 | view 42 | virtual 43 | returns (address) 44 | { 45 | return _originalCreators[tokenID]; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /contracts/interface/RoyaltyFactorySecondary.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.8.4; 3 | import "@openzeppelin/contracts/introspection/ERC165.sol"; 4 | 5 | contract RoyaltyFactory is ERC165 { 6 | mapping(uint256 => address) _originalCreators; 7 | mapping(uint256 => uint256) _royaltyFees; // 100% = 1000000, 1% = 10000 8 | /* 9 | * bytes4(keccak256('setRoyaltyFee(uint256, uint256)')) == 0x4e30ff2d 10 | * bytes4(keccak256('setOriginalCreator(uint256, uint256)')) == 0x1db8209f 11 | * bytes4(keccak256('getRoyaltyFee(uint256)')) == 0x9e4c0141 12 | * bytes4(keccak256('getOriginalCreator(uint256)')) == 0xcaa47fbf 13 | * 14 | * => 0x4e30ff2d ^ 0x1db8209f ^ 0x9e4c0141 ^ 0xcaa47fbf == 0x0760a14c 15 | */ 16 | bytes4 private constant _INTERFACE_ID_ROYALTY = 0x0760a14c; 17 | 18 | constructor() { 19 | _registerInterface(_INTERFACE_ID_ROYALTY); 20 | } 21 | 22 | function setRoyaltyFee(uint256 tokenID, uint256 fee) internal { 23 | _royaltyFees[tokenID] = fee; 24 | } 25 | 26 | function setOriginalCreator(uint256 tokenID, address creator) internal { 27 | _originalCreators[tokenID] = creator; 28 | } 29 | 30 | function getRoyaltyFee(uint256 tokenID) 31 | public 32 | view 33 | virtual 34 | returns (uint256) 35 | { 36 | return _royaltyFees[tokenID]; 37 | } 38 | 39 | function getOriginalCreator(uint256 tokenID) 40 | public 41 | view 42 | virtual 43 | returns (address) 44 | { 45 | return _originalCreators[tokenID]; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /contracts/INft_Marketplace.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | interface INft_Marketplace { 5 | struct Order { 6 | // Order ID 7 | bytes32 id; 8 | // Owner of the NFT 9 | address seller; 10 | // NFT registry address 11 | address nftAddress; 12 | // NFT ID 13 | uint256 nftId; 14 | // accepted token 15 | string tokenSymbol; 16 | // Price for the published item 17 | uint256 price; 18 | // Fixed order and auction order true/false 19 | // Time when this sale ends 20 | uint256 expiresAt; 21 | } 22 | 23 | struct Bid { 24 | // Bid Id 25 | bytes32 id; 26 | // Bidder address 27 | address bidder; 28 | // accepted token 29 | string tokenSymbol; 30 | // Price for the bid 31 | uint256 price; 32 | // Time when this bid ends 33 | uint256 expiresAt; 34 | } 35 | 36 | // ORDER EVENTS 37 | event OrderCreated( 38 | bytes32 id, 39 | address indexed seller, 40 | address indexed nftAddress, 41 | string tokenSymbol, 42 | uint256 indexed assetId, 43 | uint256 priceInWei, 44 | uint256 expiresAt 45 | ); 46 | 47 | event OrderUpdated( 48 | bytes32 id, 49 | string tokenSymbol, 50 | uint256 price, 51 | uint256 expiresAt 52 | ); 53 | 54 | event OrderSuccessful( 55 | bytes32 id, 56 | address seller, 57 | address buyer, 58 | address indexed nftAddress, 59 | uint256 indexed assetId, 60 | string tokenSymbol, 61 | uint256 priceInWei, 62 | uint256 timestamp 63 | ); 64 | 65 | event OrderCancelled(bytes32 id); 66 | 67 | // BID EVENTS 68 | event BidCreated( 69 | bytes32 id, 70 | address seller, 71 | address indexed nftAddress, 72 | uint256 indexed assetId, 73 | address indexed bidder, 74 | string tokenSymbol, 75 | uint256 price, 76 | uint256 expiresAt 77 | ); 78 | 79 | event BidAccepted(bytes32 id); 80 | event BidCancelled(bytes32 id); 81 | } 82 | -------------------------------------------------------------------------------- /contracts/CifiPowa.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.8.4; 3 | 4 | import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; 5 | 6 | import "./library/Governance.sol"; 7 | import "./interface/RoyaltyFactory.sol"; 8 | 9 | contract CifiPowa is ERC721, Governance, RoyaltyFactory { 10 | using SafeMath for uint256; 11 | 12 | uint256 private _lastTokenID = 0; 13 | 14 | constructor() ERC721("Cifipowa", "POWA") { 15 | _setBaseURI("https://ipfs.io/ipfs/"); 16 | } 17 | 18 | function setURIPrefix(string memory baseURI) public onlyGovernance { 19 | _setBaseURI(baseURI); 20 | } 21 | 22 | /** 23 | * this function assignes the URI to automatically add the id number at the end of the URI 24 | */ 25 | function assignDataToToken(uint256 id, string memory uri) public { 26 | require(_msgSender() == ownerOf(id), "invalid token owner"); 27 | _setTokenURI(id, uri); 28 | } 29 | 30 | /** 31 | * this function helps with queries to Fetch all the tokens that the address owns by givine address 32 | */ 33 | function tokensOfOwner(address owner) 34 | public 35 | view 36 | returns (uint256[] memory) 37 | { 38 | require(owner != address(0), "invalid owner"); 39 | uint256 length = balanceOf(owner); 40 | uint256[] memory tokens = new uint256[](length); 41 | for (uint256 i = 0; i < length; i++) { 42 | tokens[i] = tokenOfOwnerByIndex(owner, i); 43 | } 44 | return tokens; 45 | } 46 | 47 | /** 48 | * this function allows to approve more than one token id at once 49 | */ 50 | function approveMany(address _to, uint256[] memory _tokenIds) public { 51 | /* Allows bulk-approval of many tokens. This function is useful for 52 | exchanges where users can make a single tx to enable the call of 53 | transferFrom for those tokens by an exchange contract. */ 54 | for (uint256 i = 0; i < _tokenIds.length; i++) { 55 | // approve handles the check for if one who is approving is the owner. 56 | approve(_to, _tokenIds[i]); 57 | } 58 | } 59 | 60 | /** 61 | * this function allows to approve all the tokens the address owns at once 62 | */ 63 | function approveAll(address _to) public { 64 | uint256[] memory tokens = tokensOfOwner(msg.sender); 65 | for (uint256 t = 0; t < tokens.length; t++) { 66 | approve(_to, tokens[t]); 67 | } 68 | } 69 | 70 | /** 71 | * this function allows to mint more of your ART 72 | */ 73 | function mint(string memory metadata, uint256 royaltyFee) 74 | external 75 | returns (bool) 76 | { 77 | _lastTokenID++; 78 | // The index of the newest token is at the # totalTokens. 79 | setOriginalCreator(_lastTokenID, _msgSender()); 80 | setRoyaltyFee(_lastTokenID, royaltyFee); 81 | _mint(msg.sender, _lastTokenID); 82 | _setTokenURI(_lastTokenID, metadata); 83 | return true; 84 | } 85 | 86 | /** 87 | * this function allows you burn your NFT 88 | */ 89 | function burn(uint256 _id) external { 90 | require( 91 | _isApprovedOrOwner(_msgSender(), _id), 92 | "caller is not owner nor approved" 93 | ); 94 | _burn(_id); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /contracts/ArtGallery.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.8.4; 3 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; 4 | import "./ArtFactory.sol"; 5 | 6 | contract ArtGallery { 7 | using SafeMath for uint256; 8 | // mapping to save the symbol to Gallery Address 9 | mapping(string => address) symbolToGalleryAddress; 10 | //mapping to save all the gallery addresses of an owner 11 | mapping(address => address[]) userToGalleries; 12 | 13 | address lastaddress; 14 | string lastUri; 15 | address public feeAccount = address(0x0000000000000000000000); 16 | address public _owner = address(0x0000000000000000000000); 17 | 18 | // ERC20 cifiTokenContract = ERC20(0xe56aB536c90E5A8f06524EA639bE9cB3589B8146); 19 | ERC20 cifiTokenContract = ERC20(0x89F2a5463eF4e4176E57EEf2b2fDD256Bf4bC2bD); 20 | 21 | uint256 FEE = 100; 22 | uint8 cifiDecimals = cifiTokenContract.decimals(); 23 | uint256 public feeAmount = FEE.mul(10**cifiDecimals).div(100); 24 | 25 | event GalleryCreated( 26 | string name, 27 | string symbol, 28 | string description, 29 | address caller, 30 | address galleryAddress 31 | ); 32 | 33 | constructor() { 34 | feeAccount = msg.sender; 35 | _owner = msg.sender; 36 | } 37 | 38 | function createGallery( 39 | string memory name, 40 | string memory symbol, 41 | string memory description 42 | ) public returns (address) { 43 | require(msg.sender != address(0), "Invalid address"); 44 | require(bytes(name).length != 0, "name can't be empty"); 45 | require(bytes(symbol).length != 0, "symbol can't be empty"); 46 | uniqueSymbol(symbol); 47 | cifiTokenContract.transferFrom(msg.sender, feeAccount, feeAmount); 48 | ArtFactory gallery = 49 | new ArtFactory(name, symbol, description, msg.sender); 50 | 51 | // adding the gallery address to the symbolToGalleryAddress 52 | symbolToGalleryAddress[symbol] = address(gallery); 53 | 54 | // saving the last gallery address 55 | lastaddress = address(gallery); 56 | 57 | // adding the gallery address to the uriToGalleryAddress 58 | 59 | // adding the address to address array for userToGalleries 60 | userToGalleries[msg.sender].push(address(gallery)); 61 | 62 | emit GalleryCreated( 63 | name, 64 | symbol, 65 | description, 66 | msg.sender, 67 | address(gallery) 68 | ); 69 | 70 | return address(gallery); 71 | } 72 | 73 | function uniqueSymbol(string memory symbol) public view returns (bool) { 74 | require( 75 | symbolToGalleryAddress[symbol] == address(0), 76 | "symbol already used" 77 | ); 78 | return true; 79 | } 80 | 81 | function getlastAddress() public view returns (address) { 82 | return lastaddress; 83 | } 84 | 85 | function getGalleries(address _user) 86 | public 87 | view 88 | returns (address[] memory) 89 | { 90 | return userToGalleries[_user]; 91 | } 92 | 93 | function getGallery(string memory _symbol) public view returns (address) { 94 | return symbolToGalleryAddress[_symbol]; 95 | } 96 | 97 | /** 98 | * this function allows you to change the address that is going to receive the fee amount 99 | */ 100 | function ChangeFeeAccount(address newFeeAccount) public returns (bool) { 101 | require(msg.sender == _owner); 102 | feeAccount = newFeeAccount; 103 | return true; 104 | } 105 | 106 | function ChangeFeeAmount(uint256 newFeeAmount) public returns (bool) { 107 | require(msg.sender == _owner); 108 | FEE = newFeeAmount; 109 | return true; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /contracts/ArtFactory.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.8.4; 3 | 4 | import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; 5 | import "./interface/RoyaltyFactory.sol"; 6 | 7 | contract ArtFactory is ERC721, RoyaltyFactory { 8 | using SafeMath for uint256; 9 | 10 | string public Artname; 11 | string public Artsymbol; 12 | string public Artdescription; 13 | 14 | address public Artcreator; 15 | 16 | uint256 private lastTokenID = 0; 17 | // Total tokens starts at 0 because each new token must be minted and the 18 | // _mint() call adds 1 to totalTokens 19 | 20 | event Mint(string url, uint256 tokenId); 21 | 22 | /** 23 | * a gallery function that is been called by the ART gallery smart contract 24 | */ 25 | 26 | constructor( 27 | string memory _name, 28 | string memory _symbol, 29 | string memory _description, 30 | address creator 31 | ) ERC721(_name, _symbol) { 32 | Artname = _name; 33 | Artsymbol = _symbol; 34 | Artdescription = _description; 35 | Artcreator = creator; 36 | _setBaseURI("https://ipfs.io/ipfs/"); 37 | } 38 | 39 | function setURIPrefix(string memory baseURI) public { 40 | require(msg.sender == Artcreator); 41 | _setBaseURI(baseURI); 42 | } 43 | 44 | /** 45 | * this function assignes the URI to automatically add the id number at the end of the URI 46 | */ 47 | function assignDataToToken(uint256 id, string memory uri) public { 48 | require(_msgSender() == ownerOf(id), "invalid token owner"); 49 | _setTokenURI(id, uri); 50 | } 51 | 52 | /** 53 | * this function helps with queries to Fetch all the tokens that the address owns by givine address 54 | */ 55 | function tokensOfOwner(address owner) 56 | public 57 | view 58 | returns (uint256[] memory) 59 | { 60 | require(owner != address(0), "invalid owner"); 61 | uint256 length = balanceOf(owner); 62 | uint256[] memory tokens = new uint256[](length); 63 | for (uint256 i = 0; i < length; i++) { 64 | tokens[i] = tokenOfOwnerByIndex(owner, i); 65 | } 66 | return tokens; 67 | } 68 | 69 | /** 70 | * this function allows to approve more than one token id at once 71 | */ 72 | function approveMany(address _to, uint256[] memory _tokenIds) public { 73 | /* Allows bulk-approval of many tokens. This function is useful for 74 | exchanges where users can make a single tx to enable the call of 75 | transferFrom for those tokens by an exchange contract. */ 76 | for (uint256 i = 0; i < _tokenIds.length; i++) { 77 | // approve handles the check for if one who is approving is the owner. 78 | approve(_to, _tokenIds[i]); 79 | } 80 | } 81 | 82 | /** 83 | * this function allows to approve all the tokens the address owns at once 84 | */ 85 | function approveAll(address _to) public { 86 | uint256[] memory tokens = tokensOfOwner(msg.sender); 87 | for (uint256 t = 0; t < tokens.length; t++) { 88 | approve(_to, tokens[t]); 89 | } 90 | } 91 | 92 | /** 93 | * this function allows to mint more of your Art 94 | */ 95 | function mint(string memory url, uint256 royaltyFee) 96 | external 97 | returns (bool) 98 | { 99 | require(msg.sender == Artcreator); 100 | lastTokenID++; 101 | setOriginalCreator(lastTokenID, _msgSender()); 102 | setRoyaltyFee(lastTokenID, royaltyFee); 103 | _mint(msg.sender, lastTokenID); 104 | _setTokenURI(lastTokenID, url); 105 | emit Mint(url, lastTokenID); 106 | return true; 107 | } 108 | 109 | /** 110 | * this function allows you burn your Art 111 | */ 112 | function burn(uint256 _id) public returns (bool) { 113 | require( 114 | _isApprovedOrOwner(_msgSender(), _id), 115 | "caller is not owner nor approved" 116 | ); 117 | _burn(_id); 118 | return true; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /contracts/TokenizedArt.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.8.4; 3 | pragma experimental ABIEncoderV2; 4 | 5 | import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; 6 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; 7 | import "@openzeppelin/contracts/math/SafeMath.sol"; 8 | import "./library/Governance.sol"; 9 | 10 | contract TokenizedArt is ERC721, Governance { 11 | using SafeMath for uint256; 12 | 13 | ERC20 cifiTokenContractTest = 14 | ERC20(0xe56aB536c90E5A8f06524EA639bE9cB3589B8146); 15 | uint256 FEE = 100; 16 | uint8 cifiDecimals = cifiTokenContractTest.decimals(); 17 | uint256 public feeAmount = FEE.mul(10**cifiDecimals).div(100); 18 | 19 | address feeWallet = address(0x000000000000000000000000); 20 | 21 | // Mapping from owner to list of owned token IDs 22 | 23 | // Metadata is a URL that points to a json dictionary 24 | mapping(uint256 => string) tokenID_symbol; 25 | mapping(uint256 => uint256) tokenID_amount; 26 | 27 | mapping(string => address) acceptedTokens; 28 | 29 | string[] public acceptedTokenSymbols; 30 | 31 | event Mint(string url, uint256 tokenId, string symbol, uint256 amount); 32 | 33 | /** 34 | * a gallery function that is been called by the ART gallery smart contract 35 | */ 36 | 37 | constructor() ERC721("TokenizedArt", "cPOWA") { 38 | feeWallet = _msgSender(); 39 | _setBaseURI("https://ipfs.io/ipfs/"); 40 | } 41 | 42 | function setURIPrefix(string memory baseURI) public onlyGovernance { 43 | _setBaseURI(baseURI); 44 | } 45 | 46 | /** 47 | * this function assignes the URI to automatically add the id number at the end of the URI 48 | */ 49 | function assignDataToToken(uint256 id, string memory uri) public { 50 | require(_msgSender() == ownerOf(id), "invalid token owner"); 51 | _setTokenURI(id, uri); 52 | } 53 | 54 | /** 55 | * this function helps with queries to Fetch all the tokens that the address owns by givine address 56 | */ 57 | function tokensOfOwner(address owner) 58 | public 59 | view 60 | returns (uint256[] memory) 61 | { 62 | require(owner != address(0), "invalid owner"); 63 | uint256 length = balanceOf(owner); 64 | uint256[] memory tokens = new uint256[](length); 65 | for (uint256 i = 0; i < length; i++) { 66 | tokens[i] = tokenOfOwnerByIndex(owner, i); 67 | } 68 | return tokens; 69 | } 70 | 71 | /** 72 | * this function allows to approve more than one token id at once 73 | */ 74 | function approveMany(address _to, uint256[] memory _tokenIds) public { 75 | /* Allows bulk-approval of many tokens. This function is useful for 76 | exchanges where users can make a single tx to enable the call of 77 | transferFrom for those tokens by an exchange contract. */ 78 | for (uint256 i = 0; i < _tokenIds.length; i++) { 79 | // approve handles the check for if one who is approving is the owner. 80 | approve(_to, _tokenIds[i]); 81 | } 82 | } 83 | 84 | /** 85 | * this function allows to approve all the tokens the address owns at once 86 | */ 87 | function approveAll(address _to) public { 88 | uint256[] memory tokens = tokensOfOwner(msg.sender); 89 | for (uint256 t = 0; t < tokens.length; t++) { 90 | approve(_to, tokens[t]); 91 | } 92 | } 93 | 94 | /** 95 | * this function allows to mint more of your ART 96 | */ 97 | function mint( 98 | string memory url, 99 | string memory tokenSymbol, 100 | uint256 amount 101 | ) public { 102 | uint256 currentTokenCount = totalSupply().add(1); 103 | // The index of the newest token is at the # totalTokens. 104 | _mint(msg.sender, currentTokenCount); 105 | _setTokenURI(currentTokenCount, url); 106 | ERC20 acceptedToken = ERC20(acceptedTokens[tokenSymbol]); 107 | if (acceptedToken != cifiTokenContractTest) { 108 | cifiTokenContractTest.transferFrom( 109 | msg.sender, 110 | feeWallet, 111 | feeAmount 112 | ); 113 | } 114 | acceptedToken.transferFrom(msg.sender, address(this), amount); 115 | tokenID_symbol[currentTokenCount] = tokenSymbol; 116 | tokenID_amount[currentTokenCount] = amount; 117 | emit Mint(url, currentTokenCount, tokenSymbol, amount); 118 | } 119 | 120 | /** 121 | * this function allows you burn your NFT 122 | */ 123 | function burn(uint256 _id) public returns (bool) { 124 | require( 125 | _isApprovedOrOwner(_msgSender(), _id), 126 | "caller is not owner nor approved" 127 | ); 128 | address owner = ownerOf(_id); 129 | string memory tokenSymbol = tokenID_symbol[_id]; 130 | uint256 amount = tokenID_amount[_id]; 131 | ERC20 acceptedToken = ERC20(acceptedTokens[tokenSymbol]); 132 | acceptedToken.transferFrom(address(this), owner, amount); 133 | _burn(_id); 134 | return true; 135 | } 136 | 137 | function addAcceptedToken( 138 | address acceptedTokenAddress, 139 | string memory acceptedTokenSymbol 140 | ) public onlyGovernance returns (bool) { 141 | acceptedTokens[acceptedTokenSymbol] = acceptedTokenAddress; 142 | acceptedTokenSymbols.push(acceptedTokenSymbol); 143 | return true; 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /contracts/TokenizedArtFactory.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.8.4; 3 | 4 | import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; 5 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; 6 | import "@openzeppelin/contracts/access/Ownable.sol"; 7 | 8 | contract TokenizedArtFactory is ERC721 { 9 | using SafeMath for uint256; 10 | 11 | ERC20 cifiTokenContractTest = 12 | ERC20(0xe56aB536c90E5A8f06524EA639bE9cB3589B8146); 13 | uint256 FEE = 100; 14 | uint8 cifiDecimals = cifiTokenContractTest.decimals(); 15 | uint256 public feeAmount = FEE.mul(10**cifiDecimals).div(100); 16 | 17 | address feeWallet = address(0x000000000000000000000000); 18 | 19 | string public Artname; 20 | string public Artsymbol; 21 | string public Artdescription; 22 | 23 | address public Artcreator; 24 | 25 | mapping(uint256 => string) tokenID_symbol; 26 | mapping(uint256 => uint256) tokenID_amount; 27 | 28 | mapping(string => address) acceptedTokens; 29 | 30 | string[] public acceptedTokenSymbols; 31 | 32 | event Mint(string url, uint256 tokenId, string symbol, uint256 amount); 33 | 34 | /** 35 | * a registry function that iis been called by the NFT registry smart contract 36 | */ 37 | 38 | constructor( 39 | string memory _name, 40 | string memory _symbol, 41 | string memory _description, 42 | address _caller 43 | ) ERC721(_name, _symbol) { 44 | Artname = _name; 45 | Artsymbol = _symbol; 46 | Artdescription = _description; 47 | Artcreator = _caller; 48 | } 49 | 50 | /** 51 | * this function helps with queries to Fetch the metadata for a givine token id 52 | */ 53 | function setURIPrefix(string memory baseURI) public { 54 | require(msg.sender == Artcreator); 55 | _setBaseURI(baseURI); 56 | } 57 | 58 | function assignDataToToken(uint256 id, string memory uri) public { 59 | require(_msgSender() == ownerOf(id), "invalid token owner"); 60 | _setTokenURI(id, uri); 61 | } 62 | 63 | /** 64 | * this function helps with queries to Fetch all the tokens that the address owns by givine address 65 | */ 66 | function tokensOfOwner(address owner) 67 | public 68 | view 69 | returns (uint256[] memory) 70 | { 71 | require(owner != address(0), "invalid owner"); 72 | uint256 length = balanceOf(owner); 73 | uint256[] memory tokens = new uint256[](length); 74 | for (uint256 i = 0; i < length; i++) { 75 | tokens[i] = tokenOfOwnerByIndex(owner, i); 76 | } 77 | return tokens; 78 | } 79 | 80 | /** 81 | * this function allows to approve more than one token id at once 82 | */ 83 | function approveMany(address _to, uint256[] memory _tokenIds) public { 84 | /* Allows bulk-approval of many tokens. This function is useful for 85 | exchanges where users can make a single tx to enable the call of 86 | transferFrom for those tokens by an exchange contract. */ 87 | for (uint256 i = 0; i < _tokenIds.length; i++) { 88 | // approve handles the check for if one who is approving is the owner. 89 | approve(_to, _tokenIds[i]); 90 | } 91 | } 92 | 93 | /** 94 | * this function allows to approve all the tokens the address owns at once 95 | */ 96 | function approveAll(address _to) public { 97 | uint256[] memory tokens = tokensOfOwner(msg.sender); 98 | for (uint256 t = 0; t < tokens.length; t++) { 99 | approve(_to, tokens[t]); 100 | } 101 | } 102 | 103 | /** 104 | * this function allows to mint more of your Art 105 | */ 106 | function mint( 107 | string memory url, 108 | string memory tokenSymbol, 109 | uint256 amount 110 | ) public { 111 | require(msg.sender == Artcreator); 112 | uint256 currentTokenCount = totalSupply().add(1); 113 | // The index of the newest token is at the # totalTokens. 114 | _mint(msg.sender, currentTokenCount); 115 | _setTokenURI(currentTokenCount, url); 116 | 117 | ERC20 acceptedToken = ERC20(acceptedTokens[tokenSymbol]); 118 | if (acceptedToken != cifiTokenContractTest) { 119 | cifiTokenContractTest.transferFrom( 120 | msg.sender, 121 | feeWallet, 122 | feeAmount 123 | ); 124 | } 125 | acceptedToken.transferFrom(msg.sender, address(this), amount); 126 | tokenID_symbol[currentTokenCount] = tokenSymbol; 127 | tokenID_amount[currentTokenCount] = amount; 128 | 129 | emit Mint(url, currentTokenCount, tokenSymbol, amount); 130 | } 131 | 132 | function burn(uint256 _id) public returns (bool) { 133 | require( 134 | _isApprovedOrOwner(_msgSender(), _id), 135 | "caller is not owner nor approved" 136 | ); 137 | address owner = ownerOf(_id); 138 | string memory tokenSymbol = tokenID_symbol[_id]; 139 | uint256 amount = tokenID_amount[_id]; 140 | ERC20 acceptedToken = ERC20(acceptedTokens[tokenSymbol]); 141 | acceptedToken.transferFrom(address(this), owner, amount); 142 | _burn(_id); 143 | return true; 144 | } 145 | 146 | function addAcceptedToken( 147 | address acceptedTokenAddress, 148 | string memory acceptedTokenSymbol 149 | ) public returns (bool) { 150 | require(msg.sender == Artcreator); 151 | acceptedTokens[acceptedTokenSymbol] = acceptedTokenAddress; 152 | acceptedTokenSymbols.push(acceptedTokenSymbol); 153 | return true; 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /contracts/Fixed_Marketplace.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | pragma experimental ABIEncoderV2; 4 | 5 | import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; 6 | import "@openzeppelin/contracts/introspection/IERC165.sol"; 7 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; 8 | import "@openzeppelin/contracts/math/SafeMath.sol"; 9 | import "@openzeppelin/contracts/utils/Address.sol"; 10 | import "@openzeppelin/contracts/access/Ownable.sol"; 11 | import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol"; 12 | import "./interface/RoyaltyFactorySecondary.sol"; 13 | import "./INft_Marketplace.sol"; 14 | import "./FeeManager.sol"; 15 | 16 | contract Fixed_Marketplace is INft_Marketplace, FeeManager, IERC721Receiver { 17 | using SafeMath for uint256; 18 | string internal cifi_Symbol = "CIFI"; 19 | string bnb_Symbol = "BNB"; 20 | 21 | // From ERC721 registry assetId to Order (to avoid asset collision) 22 | mapping(address => mapping(uint256 => Order)) orderByAssetId; 23 | 24 | mapping(string => address) acceptedTokens; 25 | 26 | // array that saves all the symbols of accepted tokens 27 | string[] public acceptedTokensSymbols; 28 | 29 | constructor() {} 30 | 31 | // 721 Interfaces 32 | bytes4 public constant _INTERFACE_ID_ERC721 = 0x80ac58cd; 33 | bytes4 private constant _INTERFACE_ID_ROYALTY = 0x0760a14c; 34 | 35 | /** 36 | * Creates a new order 37 | * _nftAddress - Non fungible contract address 38 | * _assetId - ID of the published NFT 39 | * _priceInAnyOfTheSupportedCurrencies - price In Any Of The Supported Currencies 40 | * _expiresAt - Duration of the order (in hours) 41 | */ 42 | 43 | function createOrder( 44 | address _nftAddress, 45 | uint256 _assetId, 46 | string memory _tokenSymbol, 47 | uint256 _price, 48 | uint256 _expiresAt 49 | ) public returns (bytes32) { 50 | return 51 | _createOrder( 52 | _nftAddress, 53 | _assetId, 54 | _tokenSymbol, 55 | _price, 56 | _expiresAt 57 | ); 58 | } 59 | 60 | /** 61 | * Cancel an already published order 62 | * can only be canceled by seller or the contract owner 63 | * nftAddress - Address of the NFT registry 64 | * assetId - ID of the published NFT 65 | */ 66 | function cancelOrder(address _nftAddress, uint256 _assetId) public { 67 | Order memory order = orderByAssetId[_nftAddress][_assetId]; 68 | 69 | require(order.seller == msg.sender, "Marketplace: unauthorized sender"); 70 | 71 | _cancelOrder(order.id, _nftAddress, _assetId, msg.sender); 72 | } 73 | 74 | /** 75 | * Executes the sale for a published NFT 76 | * nftAddress - Address of the NFT registry 77 | * assetId - ID of the published NFT 78 | * priceInAnyOfTheFourCurrencies - Order price 79 | */ 80 | 81 | function safeExecuteOrder(address _nftAddress, uint256 _assetId) 82 | public 83 | payable 84 | { 85 | // Get the current valid order for the asset or fail 86 | Order memory order = _getValidOrder(_nftAddress, _assetId); 87 | 88 | /// Check the execution price matches the order price 89 | require(order.seller != msg.sender, "Marketplace: unauthorized sender"); 90 | 91 | if (compareStrings(order.tokenSymbol, bnb_Symbol)) { 92 | require(order.price == msg.value, "Marketplace: invalid price"); 93 | } 94 | // market fee to cut 95 | uint256 saleShareAmount = 0; 96 | address tokenAddress = acceptedTokens[order.tokenSymbol]; 97 | ERC20 acceptedToken = ERC20(tokenAddress); 98 | uint256 royaltyFeeAmount = 0; 99 | if (IERC165(_nftAddress).supportsInterface(_INTERFACE_ID_ROYALTY)) { 100 | address orignalCreater = 101 | RoyaltyFactory(_nftAddress).getOriginalCreator(_assetId); 102 | uint256 royaltyFee = 103 | RoyaltyFactory(_nftAddress).getRoyaltyFee(_assetId); 104 | royaltyFeeAmount = order.price.mul(royaltyFee).div(1e6); 105 | if (compareStrings(order.tokenSymbol, bnb_Symbol)) { 106 | // Transfer share amount for marketplace Owner 107 | payable(orignalCreater).transfer(royaltyFeeAmount); 108 | } else { 109 | acceptedToken.transferFrom( 110 | msg.sender, //buyer 111 | orignalCreater, 112 | royaltyFeeAmount 113 | ); 114 | } 115 | } 116 | 117 | // Send market fees to owner 118 | if (FeeManager.cutPerMillion > 0) { 119 | // Calculate sale share 120 | saleShareAmount = order.price.mul(FeeManager.cutPerMillion).div( 121 | 1e6 122 | ); 123 | 124 | if (compareStrings(order.tokenSymbol, cifi_Symbol)) { 125 | // Transfer half of share amount for marketplace Owner 126 | acceptedToken.transferFrom( 127 | msg.sender, //buyer 128 | owner(), 129 | saleShareAmount.div(3) 130 | ); 131 | } else if (compareStrings(order.tokenSymbol, bnb_Symbol)) { 132 | // Transfer share amount for marketplace Owner 133 | payable(owner()).transfer(saleShareAmount); 134 | } else { 135 | acceptedToken.transferFrom( 136 | msg.sender, //buyer 137 | owner(), 138 | saleShareAmount 139 | ); 140 | } 141 | } 142 | 143 | if (compareStrings(order.tokenSymbol, cifi_Symbol)) { 144 | // Transfer accepted token amount minus market fee to seller 145 | uint256 amount = 146 | order.price.sub(saleShareAmount.div(3).mul(2)).sub( 147 | royaltyFeeAmount 148 | ); 149 | acceptedToken.transferFrom( 150 | msg.sender, // buyer 151 | order.seller, // seller 152 | amount 153 | ); 154 | } else if (compareStrings(order.tokenSymbol, bnb_Symbol)) { 155 | // Transfer share amount for marketplace Owner 156 | payable(order.seller).transfer( 157 | order.price.sub(saleShareAmount).sub(royaltyFeeAmount) 158 | ); 159 | } else { 160 | // Transfer accepted token amount minus market fee to seller 161 | acceptedToken.transferFrom( 162 | msg.sender, // buyer 163 | order.seller, // seller 164 | order.price.sub(saleShareAmount).sub(royaltyFeeAmount) 165 | ); 166 | } 167 | 168 | _executeOrder( 169 | order.id, 170 | msg.sender, // buyer 171 | _nftAddress, 172 | _assetId, 173 | order.tokenSymbol, 174 | order.price 175 | ); 176 | } 177 | 178 | /** 179 | * Internal function gets Order by nftRegistry and assetId. Checks for the order validity 180 | * nftAddress - Address of the NFT registry 181 | * assetId - ID of the published NFT 182 | */ 183 | function _getValidOrder(address _nftAddress, uint256 _assetId) 184 | internal 185 | view 186 | returns (Order memory order) 187 | { 188 | order = orderByAssetId[_nftAddress][_assetId]; 189 | 190 | require(order.id != 0, "Marketplace: asset not published"); 191 | require( 192 | order.expiresAt >= block.timestamp, 193 | "Marketplace: order expired" 194 | ); 195 | } 196 | 197 | /** 198 | * Executes the sale for a published NFT 199 | * orderId - Order Id to execute 200 | * buyer - address 201 | * nftAddress - Address of the NFT registry 202 | * assetId - NFT id 203 | * price - Order price 204 | */ 205 | function _executeOrder( 206 | bytes32 _orderId, 207 | address _buyer, 208 | address _nftAddress, 209 | uint256 _assetId, 210 | string memory _tokenSymbol, 211 | uint256 _price 212 | ) internal { 213 | // remove order 214 | Order memory order = orderByAssetId[_nftAddress][_assetId]; 215 | // Transfer NFT asset 216 | IERC721(_nftAddress).safeTransferFrom(address(this), _buyer, _assetId); 217 | 218 | delete orderByAssetId[_nftAddress][_assetId]; 219 | // Notify .. 220 | emit OrderSuccessful( 221 | order.id, 222 | order.seller, 223 | _buyer, 224 | order.nftAddress, 225 | order.nftId, 226 | order.tokenSymbol, 227 | _price, 228 | block.timestamp 229 | ); 230 | } 231 | 232 | /** 233 | * Creates a new order 234 | * nftAddress - Non fungible contract address 235 | * assetId - ID of the published NFT 236 | * priceInAnyOfTheSupportedCurrencies - price In Any Of The Supported Currencies 237 | * expiresAt - Expiration time for the order 238 | */ 239 | function _createOrder( 240 | address _nftAddress, 241 | uint256 _assetId, 242 | string memory _tokenSymbol, 243 | uint256 _price, 244 | uint256 _expiresAt 245 | ) internal returns (bytes32) { 246 | // Check nft registry 247 | IERC721 nftRegistry = _requireERC721(_nftAddress); 248 | 249 | // Check order creator is the asset owner 250 | address assetOwner = nftRegistry.ownerOf(_assetId); 251 | 252 | require( 253 | assetOwner == msg.sender, 254 | "Marketplace: Only the asset owner can create orders" 255 | ); 256 | 257 | require(_price > 0, "Marketplace: Price should be bigger than 0"); 258 | 259 | require( 260 | _expiresAt > block.timestamp.add(1 minutes), 261 | "Marketplace: Publication should be more than 1 minute in the future" 262 | ); 263 | 264 | // get NFT asset from seller 265 | nftRegistry.safeTransferFrom(assetOwner, address(this), _assetId); 266 | 267 | // create the orderId 268 | bytes32 orderId = 269 | keccak256( 270 | abi.encodePacked( 271 | block.timestamp, 272 | assetOwner, 273 | _nftAddress, 274 | _assetId, 275 | _tokenSymbol, 276 | _price 277 | ) 278 | ); 279 | 280 | // save order 281 | orderByAssetId[_nftAddress][_assetId] = Order({ 282 | id: orderId, 283 | seller: assetOwner, 284 | nftAddress: _nftAddress, 285 | nftId: _assetId, 286 | tokenSymbol: _tokenSymbol, 287 | price: _price, 288 | expiresAt: _expiresAt 289 | }); 290 | 291 | emit OrderCreated( 292 | orderId, 293 | assetOwner, 294 | _nftAddress, 295 | _tokenSymbol, 296 | _assetId, 297 | _price, 298 | _expiresAt 299 | ); 300 | return orderId; 301 | } 302 | 303 | /** 304 | * Cancel an already published order 305 | * can only be canceled by seller or the contract owner 306 | * orderId - Bid identifier 307 | * nftAddress - Address of the NFT registry 308 | * assetId - ID of the published NFT 309 | * seller - Address 310 | */ 311 | function _cancelOrder( 312 | bytes32 _orderId, 313 | address _nftAddress, 314 | uint256 _assetId, 315 | address _seller 316 | ) internal { 317 | delete orderByAssetId[_nftAddress][_assetId]; 318 | /// send asset back to seller 319 | IERC721(_nftAddress).safeTransferFrom(address(this), _seller, _assetId); 320 | emit OrderCancelled(_orderId); 321 | } 322 | 323 | function _requireERC721(address _nftAddress) 324 | internal 325 | view 326 | returns (IERC721) 327 | { 328 | require( 329 | IERC165(_nftAddress).supportsInterface(_INTERFACE_ID_ERC721), 330 | "The NFT contract has an invalid ERC721 implementation" 331 | ); 332 | return IERC721(_nftAddress); 333 | } 334 | 335 | function addAcceptedToken( 336 | address acceptedTokenAddress, 337 | string memory acceptedTokenSymbol 338 | ) public onlyOwner returns (bool) { 339 | acceptedTokens[acceptedTokenSymbol] = acceptedTokenAddress; 340 | acceptedTokensSymbols.push(acceptedTokenSymbol); 341 | return true; 342 | } 343 | 344 | function getTokenSymbols() public view returns (string[] memory) { 345 | return acceptedTokensSymbols; 346 | } 347 | 348 | function getTokenAddress(string memory tokenSymbol) 349 | public 350 | view 351 | returns (address) 352 | { 353 | return acceptedTokens[tokenSymbol]; 354 | } 355 | 356 | function onERC721Received( 357 | address, 358 | address, 359 | uint256, 360 | bytes memory 361 | ) public virtual override returns (bytes4) { 362 | return this.onERC721Received.selector; 363 | } 364 | 365 | function compareStrings(string memory a, string memory b) 366 | internal 367 | pure 368 | returns (bool) 369 | { 370 | return (keccak256(abi.encodePacked((a))) == 371 | keccak256(abi.encodePacked((b)))); 372 | } 373 | } 374 | --------------------------------------------------------------------------------