// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.0; import "@openzeppelin/contracts/utils/Strings.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol"; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; contract EQTradable is Initializable, ERC1155Upgradeable, UUPSUpgradeable, OwnableUpgradeable { using Strings for uint256; address private _marketAddress; address private _ownerAddress; uint256 private _currentTokenID; mapping(uint256 => uint256) public tokenSupply; ///@dev Only allows the stored market contract address modifier onlyMarket() { require( _marketAddress == _msgSender(), "EQTradable: caller is not the market" ); _; } ///@dev Initializes the contract function initialize() public initializer { __Ownable_init(); __ERC1155_init("https://api.eqexchangedev.com/assets/{id}"); __UUPSUpgradeable_init(); _currentTokenID = 0; } /// @custom:oz-upgrades-unsafe-allow constructor /* solium-disable-next-line no-empty-blocks*/ constructor() initializer {} /// @dev Set the market address /// @param marketAddress Market Address function setMarketAddress(address marketAddress) external onlyOwner { _marketAddress = marketAddress; } /// @dev Set the base URI /// @param newuri base uri function setURI(string calldata newuri) external onlyOwner { _setURI(newuri); } ///@dev Returns the URI of the tokenId function uri(uint256 tokenId) public view virtual override returns (string memory) { return string( abi.encodePacked(super.uri(tokenId), Strings.toString(tokenId)) ); } /// @dev Create a new token Id /// @param recipient Receiving Address /// @param numTokens Number of tokens to be minted function create(address recipient, uint256 numTokens) public onlyMarket returns (uint256) { uint256 id = _currentTokenID; _currentTokenID++; mint(recipient, id, numTokens); return id; } /// @dev Modified mint that allows the market to mint tokens /// @param recipient Receiving Address /// @param tokenId The ID of the token /// @param numTokens Number of tokens to be minted function mint( address recipient, uint256 tokenId, uint256 numTokens ) public onlyMarket { require( tokenId < _currentTokenID, "EQTradable: minting a non existing token" ); _mint(recipient, tokenId, numTokens, ""); tokenSupply[tokenId] += numTokens; } ///@dev get the total token supply of the tokenId function getTokenTotalSupply(uint256 tokenId) public view returns (uint256) { return tokenSupply[tokenId]; } /// @dev Modified safeTransferFrom that allows the market to transfer ownership of tokens /// @param source Source Address /// @param recipient Receiving Address /// @param tokenId The ID of the token /// @param numTokens Number of tokens to be transferred function marketSafeTransferFrom( address source, address recipient, uint256 tokenId, uint256 numTokens ) public onlyMarket { _safeTransferFrom(source, recipient, tokenId, numTokens, ""); } /* solium-disable-next-line no-empty-blocks*/ function _authorizeUpgrade(address) internal override onlyOwner {} }