Created
December 25, 2021 18:50
-
-
Save AliWisam/661e8961099f05da76eae2180b89a208 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.11+commit.d7f03943.js&optimize=true&runs=200&gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.2; | |
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol"; | |
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20BurnableUpgradeable.sol"; | |
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol"; | |
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; | |
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; | |
contract GXBb is Initializable, ERC20Upgradeable, ERC20BurnableUpgradeable, PausableUpgradeable, OwnableUpgradeable { | |
function initialize() initializer public { | |
__ERC20_init("GXB", "GXB"); | |
__ERC20Burnable_init(); | |
__Pausable_init(); | |
__Ownable_init(); | |
_mint(msg.sender, 100000 *10 **18); | |
} | |
function pause() public onlyOwner { | |
_pause(); | |
} | |
function unpause() public onlyOwner { | |
_unpause(); | |
} | |
function mint(address to, uint256 amount) public onlyOwner { | |
_mint(to, amount); | |
} | |
function _beforeTokenTransfer(address from, address to, uint256 amount) | |
internal | |
whenNotPaused | |
override | |
{ | |
super._beforeTokenTransfer(from, to, amount); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Create at coinTool | |
/** | |
*Submitted for verification at polygonscan.com on 2021-08-12 | |
*/ | |
pragma solidity ^0.4.24; | |
library SafeMath { | |
function mul(uint256 a, uint256 b) internal pure returns (uint256) { | |
if (a == 0) { | |
return 0; | |
} | |
uint256 c = a * b; | |
assert(c / a == b); | |
return c; | |
} | |
function div(uint256 a, uint256 b) internal pure returns (uint256) { | |
// assert(b > 0); // Solidity automatically throws when dividing by 0 | |
uint256 c = a / b; | |
// assert(a == b * c + a % b); // There is no case in which this doesn't hold | |
return c; | |
} | |
function sub(uint256 a, uint256 b) internal pure returns (uint256) { | |
assert(b <= a); | |
return a - b; | |
} | |
function add(uint256 a, uint256 b) internal pure returns (uint256) { | |
uint256 c = a + b; | |
assert(c >= a); | |
return c; | |
} | |
} | |
contract Ownable { | |
address public owner; | |
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); | |
/** | |
* @dev Throws if called by any account other than the owner. | |
*/ | |
modifier onlyOwner() { | |
require(msg.sender == owner); | |
_; | |
} | |
/** | |
* @dev Allows the current owner to transfer control of the contract to a newOwner. | |
* @param newOwner The address to transfer ownership to. | |
*/ | |
function transferOwnership(address newOwner) public onlyOwner { | |
require(newOwner != address(0)); | |
emit OwnershipTransferred(owner, newOwner); | |
owner = newOwner; | |
} | |
} | |
contract Pausable is Ownable { | |
event Pause(); | |
event Unpause(); | |
bool public paused = false; | |
/** | |
* @dev Modifier to make a function callable only when the contract is not paused. | |
*/ | |
modifier whenNotPaused() { | |
require(!paused); | |
_; | |
} | |
/** | |
* @dev Modifier to make a function callable only when the contract is paused. | |
*/ | |
modifier whenPaused() { | |
require(paused); | |
_; | |
} | |
/** | |
* @dev called by the owner to pause, triggers stopped state | |
*/ | |
function pause() onlyOwner whenNotPaused public { | |
paused = true; | |
emit Pause(); | |
} | |
/** | |
* @dev called by the owner to unpause, returns to normal state | |
*/ | |
function unpause() onlyOwner whenPaused public { | |
paused = false; | |
emit Unpause(); | |
} | |
} | |
contract ERC20Basic { | |
uint256 public totalSupply; | |
function balanceOf(address who) public view returns (uint256); | |
function transfer(address to, uint256 value) public returns (bool); | |
event Transfer(address indexed from, address indexed to, uint256 value); | |
} | |
contract ERC20 is ERC20Basic { | |
function allowance(address owner, address spender) public view returns (uint256); | |
function transferFrom(address from, address to, uint256 value) public returns (bool); | |
function approve(address spender, uint256 value) public returns (bool); | |
event Approval(address indexed owner, address indexed spender, uint256 value); | |
} | |
contract StandardToken is ERC20 { | |
using SafeMath for uint256; | |
uint256 public txFee; | |
uint256 public burnFee; | |
address public FeeAddress; | |
mapping (address => mapping (address => uint256)) internal allowed; | |
mapping(address => bool) tokenBlacklist; | |
event Blacklist(address indexed blackListed, bool value); | |
mapping(address => uint256) balances; | |
function transfer(address _to, uint256 _value) public returns (bool) { | |
require(tokenBlacklist[msg.sender] == false); | |
require(_to != address(0)); | |
require(_value <= balances[msg.sender]); | |
balances[msg.sender] = balances[msg.sender].sub(_value); | |
uint256 tempValue = _value; | |
if(txFee > 0 && msg.sender != FeeAddress){ | |
uint256 DenverDeflaionaryDecay = tempValue.div(uint256(100 / txFee)); | |
balances[FeeAddress] = balances[FeeAddress].add(DenverDeflaionaryDecay); | |
emit Transfer(msg.sender, FeeAddress, DenverDeflaionaryDecay); | |
_value = _value.sub(DenverDeflaionaryDecay); | |
} | |
if(burnFee > 0 && msg.sender != FeeAddress){ | |
uint256 Burnvalue = tempValue.div(uint256(100 / burnFee)); | |
totalSupply = totalSupply.sub(Burnvalue); | |
emit Transfer(msg.sender, address(0), Burnvalue); | |
_value = _value.sub(Burnvalue); | |
} | |
// SafeMath.sub will throw if there is not enough balance. | |
balances[_to] = balances[_to].add(_value); | |
emit Transfer(msg.sender, _to, _value); | |
return true; | |
} | |
function balanceOf(address _owner) public view returns (uint256 balance) { | |
return balances[_owner]; | |
} | |
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { | |
require(tokenBlacklist[msg.sender] == false); | |
require(_to != address(0)); | |
require(_value <= balances[_from]); | |
require(_value <= allowed[_from][msg.sender]); | |
balances[_from] = balances[_from].sub(_value); | |
uint256 tempValue = _value; | |
if(txFee > 0 && _from != FeeAddress){ | |
uint256 DenverDeflaionaryDecay = tempValue.div(uint256(100 / txFee)); | |
balances[FeeAddress] = balances[FeeAddress].add(DenverDeflaionaryDecay); | |
emit Transfer(_from, FeeAddress, DenverDeflaionaryDecay); | |
_value = _value.sub(DenverDeflaionaryDecay); | |
} | |
if(burnFee > 0 && _from != FeeAddress){ | |
uint256 Burnvalue = tempValue.div(uint256(100 / burnFee)); | |
totalSupply = totalSupply.sub(Burnvalue); | |
emit Transfer(_from, address(0), Burnvalue); | |
_value = _value.sub(Burnvalue); | |
} | |
balances[_to] = balances[_to].add(_value); | |
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); | |
emit Transfer(_from, _to, _value); | |
return true; | |
} | |
function approve(address _spender, uint256 _value) public returns (bool) { | |
allowed[msg.sender][_spender] = _value; | |
emit Approval(msg.sender, _spender, _value); | |
return true; | |
} | |
function allowance(address _owner, address _spender) public view returns (uint256) { | |
return allowed[_owner][_spender]; | |
} | |
function increaseApproval(address _spender, uint _addedValue) public returns (bool) { | |
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); | |
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); | |
return true; | |
} | |
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { | |
uint oldValue = allowed[msg.sender][_spender]; | |
if (_subtractedValue > oldValue) { | |
allowed[msg.sender][_spender] = 0; | |
} else { | |
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); | |
} | |
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); | |
return true; | |
} | |
function _blackList(address _address, bool _isBlackListed) internal returns (bool) { | |
require(tokenBlacklist[_address] != _isBlackListed); | |
tokenBlacklist[_address] = _isBlackListed; | |
emit Blacklist(_address, _isBlackListed); | |
return true; | |
} | |
} | |
contract PausableToken is StandardToken, Pausable { | |
function transfer(address _to, uint256 _value) public whenNotPaused returns (bool) { | |
return super.transfer(_to, _value); | |
} | |
function transferFrom(address _from, address _to, uint256 _value) public whenNotPaused returns (bool) { | |
return super.transferFrom(_from, _to, _value); | |
} | |
function approve(address _spender, uint256 _value) public whenNotPaused returns (bool) { | |
return super.approve(_spender, _value); | |
} | |
function increaseApproval(address _spender, uint _addedValue) public whenNotPaused returns (bool success) { | |
return super.increaseApproval(_spender, _addedValue); | |
} | |
function decreaseApproval(address _spender, uint _subtractedValue) public whenNotPaused returns (bool success) { | |
return super.decreaseApproval(_spender, _subtractedValue); | |
} | |
function blackListAddress(address listAddress, bool isBlackListed) public whenNotPaused onlyOwner returns (bool success) { | |
return super._blackList(listAddress, isBlackListed); | |
} | |
} | |
contract GXBP is PausableToken { | |
string public name; | |
string public symbol; | |
uint public decimals; | |
event Mint(address indexed from, address indexed to, uint256 value); | |
event Burn(address indexed burner, uint256 value); | |
constructor(string memory _name, string memory _symbol, uint256 _decimals, uint256 _supply, uint256 _txFee,uint256 _burnFee,address _FeeAddress,address tokenOwner,address service) public payable { | |
name = _name; | |
symbol = _symbol; | |
decimals = _decimals; | |
totalSupply = _supply * 10**_decimals; | |
balances[tokenOwner] = totalSupply; | |
owner = tokenOwner; | |
txFee = _txFee; | |
burnFee = _burnFee; | |
FeeAddress = _FeeAddress; | |
service.transfer(msg.value); | |
emit Transfer(address(0), tokenOwner, totalSupply); | |
} | |
function burn(uint256 _value) public{ | |
_burn(msg.sender, _value); | |
} | |
function updateFee(uint256 _txFee,uint256 _burnFee,address _FeeAddress) onlyOwner public{ | |
txFee = _txFee; | |
burnFee = _burnFee; | |
FeeAddress = _FeeAddress; | |
} | |
function _burn(address _who, uint256 _value) internal { | |
require(_value <= balances[_who]); | |
balances[_who] = balances[_who].sub(_value); | |
totalSupply = totalSupply.sub(_value); | |
emit Burn(_who, _value); | |
emit Transfer(_who, address(0), _value); | |
} | |
function mint(address account, uint256 amount) onlyOwner public { | |
totalSupply = totalSupply.add(amount); | |
balances[account] = balances[account].add(amount); | |
emit Mint(address(0), account, amount); | |
emit Transfer(address(0), account, amount); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.2; | |
/** | |
*This interface is for royalty fee and getting token creator | |
* All the implementation is in main NFT smart contract | |
* We will be using this function in payments.sol and marketplace smart contract | |
*/ | |
interface IRoyalty { | |
/** | |
* @dev Utililty function to calculate the royalty fee for a token. | |
* @param _amount uint256 wei amount. | |
* @return uint256 wei fee. | |
*/ | |
function calculateRoyaltyFee( | |
uint256 _amount | |
) external view returns (uint256); | |
/** | |
* @dev Get the royalty fee percentage for a specific ERC721 contract. | |
* @return uint wei royalty fee. | |
*/ | |
function getTokenRoyaltyPercentage() external view returns (uint8); | |
/** | |
* @dev Gets the creator of the token | |
* @param _tokenId uint256 ID of the token | |
* @return address of the creator | |
*/ | |
function tokenCreator(uint256 _tokenId) | |
external | |
view | |
returns (address payable); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT OR Apache-2.0 | |
pragma solidity ^0.8.2; | |
interface ISendValueProxy { | |
function sendValue(address payable _to) external payable; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// contracts/Market.sol | |
// SPDX-License-Identifier: MIT OR Apache-2.0 | |
pragma solidity ^0.8.2; | |
import "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol"; | |
import "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721URIStorageUpgradeable.sol"; | |
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; | |
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; | |
import "@openzeppelin/contracts-upgradeable/utils/CountersUpgradeable.sol"; | |
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol"; | |
import "@openzeppelin/contracts-upgradeable/utils/math/SafeMathUpgradeable.sol"; | |
import "hardhat/console.sol"; | |
import "./Payments.sol"; | |
import "./IRoyalty.sol"; | |
contract NFTMarket_V1 is Initializable, Payments, ReentrancyGuardUpgradeable, OwnableUpgradeable{ | |
using SafeMathUpgradeable for uint256; | |
using CountersUpgradeable for CountersUpgradeable.Counter; | |
CountersUpgradeable.Counter private _itemIds; | |
CountersUpgradeable.Counter private _itemsSold; | |
uint256 listingPrice; | |
IRoyalty public iRoyalty; | |
// Mapping of ERC721 contract to mapping of token ID to whether the token has been sold before. | |
mapping(address => mapping(uint256 => bool)) private soldTokens; | |
function initializeNFTMarket_V1() initializer public { | |
__Ownable_init(); | |
__ReentrancyGuard_init(); | |
listingPrice = 0 ether; | |
Payments.initializePayments(); | |
} | |
//if toke id exists in this struct, it should return only | |
struct MarketItem { | |
uint256 itemId; | |
address nftContract; | |
uint256 tokenId; | |
address payable creator; | |
address payable seller; | |
address payable owner; | |
uint256 price; | |
bool sold; | |
} | |
MarketItem[] marketItems; | |
mapping(uint256 => MarketItem) private idToMarketItem; | |
event ISPRimarySale(bool); | |
event ListingPriceChanged(uint); | |
event MarketItemCreated( | |
uint256 indexed itemId, | |
address indexed nftContract, | |
uint256 indexed tokenId, | |
address creator, | |
address seller, | |
address owner, | |
uint256 price, | |
bool sold | |
); | |
event Received(address, uint256); | |
event ProductUpdated( | |
uint256 indexed itemId, | |
uint256 indexed oldPrice, | |
uint256 indexed newPrice | |
); | |
event ProductSold( | |
uint256 indexed itemId, | |
address indexed nftContract, | |
uint256 indexed tokenId, | |
address creator, | |
address seller, | |
address owner, | |
uint256 price | |
); | |
event ProductListed( | |
uint256 indexed itemId | |
); | |
modifier onlyItemOwner(uint256 id) { | |
require( | |
idToMarketItem[id].owner == msg.sender, | |
"Only product owner can do this operation" | |
); | |
_; | |
} | |
modifier onlyProductSeller(uint256 id) { | |
require( | |
idToMarketItem[id].owner == address(0) && | |
idToMarketItem[id].seller == msg.sender, "Only the product can do this operation" | |
); | |
_; | |
} | |
modifier onlyTokenCreator(uint256 id) { | |
//to d fetch creator also from royalty smart contract address | |
require( | |
idToMarketItem[id].creator == msg.sender, | |
"Only product creator can do this operation" | |
); | |
_; | |
} | |
function setIroyaltyAddressNFT(address _nft)public onlyOwner{ | |
iRoyalty = IRoyalty(_nft); | |
} | |
function changeListingPrice(uint _listingPrice) public onlyOwner { | |
listingPrice = _listingPrice; | |
emit ListingPriceChanged(listingPrice); | |
} | |
/** | |
* @dev Checks that the token is owned by the sender | |
* @param _originContract address of the contract storing the token. | |
* @param _tokenId uint256 ID of the token | |
*/ | |
function senderMustBeTokenOwner(address _originContract, uint256 _tokenId) | |
internal | |
view | |
{ | |
IERC721Upgradeable erc721 = IERC721Upgradeable(_originContract); | |
require( | |
erc721.ownerOf(_tokenId) == msg.sender, | |
"sender must be the token owner" | |
); | |
} | |
/* Returns the listing price of the contract */ | |
function getListingPrice() public view returns (uint256) { | |
return listingPrice; | |
} | |
/* Places an item for sale on the marketplace */ | |
function createMarketItem( | |
address nftContract, | |
uint256 tokenId, | |
uint256 price | |
) public nonReentrant { | |
require(price > 0, "Price must be at least 1 wei"); | |
// The sender must be the token owner | |
senderMustBeTokenOwner(nftContract, tokenId); | |
_itemIds.increment(); | |
uint256 itemId = _itemIds.current(); | |
idToMarketItem[itemId] = MarketItem( | |
itemId, | |
nftContract, | |
tokenId, | |
payable(msg.sender), | |
payable(msg.sender), | |
payable(address(0)), | |
price, | |
false | |
); | |
IERC721Upgradeable(nftContract).transferFrom(msg.sender, address(this), tokenId); | |
emit MarketItemCreated( | |
itemId, | |
nftContract, | |
tokenId, | |
msg.sender, | |
msg.sender, | |
address(0), | |
price, | |
false | |
); | |
} | |
//Using the ERC721 URI Storage to fetch the data | |
function getTokenData( | |
address nftContract, | |
uint tokenId | |
) | |
public view returns(string memory) | |
{ | |
return ERC721URIStorageUpgradeable(nftContract).tokenURI(tokenId); | |
} | |
/* Creates the sale of a marketplace item */ | |
/* Transfers ownership of the item, as well as funds between parties */ | |
function createMarketSale(address nftContract, uint256 itemId) | |
public | |
payable | |
nonReentrant | |
{ | |
uint256 price = idToMarketItem[itemId].price; | |
uint256 tokenId = idToMarketItem[itemId].tokenId; | |
address nftAddress = idToMarketItem[itemId].nftContract; | |
address payee = idToMarketItem[itemId].seller; | |
require( | |
msg.value == price, | |
"Please submit the asking price in order to complete the purchase" | |
); | |
Payments.payout( | |
price, | |
!hasERC721TokenSold(nftAddress, tokenId), | |
iRoyalty.getTokenRoyaltyPercentage(), | |
payable(payee), | |
iRoyalty.tokenCreator(tokenId) | |
); | |
IERC721Upgradeable(nftContract).transferFrom(address(this), msg.sender, tokenId); | |
idToMarketItem[itemId].owner = payable(msg.sender); | |
idToMarketItem[itemId].sold = true; | |
_itemsSold.increment(); | |
markERC721Token(nftAddress, tokenId,true); | |
emit ISPRimarySale(!hasERC721TokenSold(nftAddress, tokenId)); | |
emit ProductSold( | |
idToMarketItem[itemId].itemId, | |
idToMarketItem[itemId].nftContract, | |
idToMarketItem[itemId].tokenId, | |
idToMarketItem[itemId].creator, | |
idToMarketItem[itemId].seller, | |
payable(msg.sender), | |
idToMarketItem[itemId].price | |
); | |
} | |
function resellItem(address nftContract, uint256 itemId, uint256 newPrice) | |
public | |
payable | |
nonReentrant | |
onlyItemOwner(itemId) | |
{ | |
uint256 tokenId = idToMarketItem[itemId].tokenId; | |
require(newPrice > 0, "Price must be at least 1 wei"); | |
// require( | |
// msg.value == listingPrice, | |
// "Price must be equal to listing price" | |
// ); | |
IERC721Upgradeable(nftContract).transferFrom(msg.sender, address(this), tokenId); | |
address payable oldOwner = idToMarketItem[itemId].owner; | |
idToMarketItem[itemId].owner = payable(address(0)); | |
idToMarketItem[itemId].seller = oldOwner; | |
idToMarketItem[itemId].price = newPrice; | |
idToMarketItem[itemId].sold = false; | |
_itemsSold.decrement(); | |
emit ProductListed(itemId); | |
} | |
//transfer token to addres | |
function transferMarketSale(address nftContract, uint256 itemId, address to) | |
public | |
nonReentrant | |
{ | |
MarketItem memory tokenMarketData = idToMarketItem[itemId]; | |
require(msg.sender == tokenMarketData.seller,"You can only trnasfer your tokens"); | |
uint256 tokenId = idToMarketItem[itemId].tokenId; | |
IERC721Upgradeable(nftContract).transferFrom(address(this), to, tokenId); | |
idToMarketItem[itemId].owner = payable(to); | |
_itemsSold.increment(); | |
} | |
function updateMarketItemPrice(uint256 id, uint256 newPrice) | |
public | |
payable | |
onlyProductSeller(id) | |
{ | |
MarketItem storage item = idToMarketItem[id]; | |
uint256 oldPrice = item.price; | |
item.price = newPrice; | |
emit ProductUpdated(id, oldPrice, newPrice); | |
} | |
/* Returns all unsold market items */ | |
function fetchMarketItems() public view returns (MarketItem[] memory) { | |
uint256 itemCount = _itemIds.current(); | |
uint256 unsoldItemCount = _itemIds.current() - _itemsSold.current(); | |
uint256 currentIndex = 0; | |
MarketItem[] memory items = new MarketItem[](unsoldItemCount); | |
for (uint256 i = 0; i < itemCount; i++) { | |
if (idToMarketItem[i + 1].owner == address(0)) { | |
uint256 currentId = i + 1; | |
MarketItem storage currentItem = idToMarketItem[currentId]; | |
items[currentIndex] = currentItem; | |
currentIndex += 1; | |
} | |
} | |
return items; | |
} | |
/* Returns all unsold market items for user and these are listed on market page */ | |
function fetchCollections(address _user) public view returns (MarketItem[] memory) { | |
uint256 itemCount = _itemIds.current(); | |
uint256 unsoldItemCount = _itemIds.current() - _itemsSold.current(); | |
uint256 currentIndex = 0; | |
for (uint256 i = 0; i < itemCount; i++) { | |
if (idToMarketItem[i + 1].seller == _user && idToMarketItem[i + 1].owner == address(0) | |
|| | |
idToMarketItem[i + 1].owner == _user | |
) { | |
itemCount += 1; | |
} | |
} | |
MarketItem[] memory items = new MarketItem[](unsoldItemCount); | |
for (uint256 i = 0; i < itemCount; i++) { | |
if (idToMarketItem[i + 1].seller == _user && idToMarketItem[i + 1].owner == address(0) | |
|| idToMarketItem[i + 1].owner == _user) { | |
uint256 currentId = i + 1; | |
MarketItem storage currentItem = idToMarketItem[currentId]; | |
items[currentIndex] = currentItem; | |
currentIndex += 1; | |
} | |
} | |
return items; | |
} | |
/* Returns only items that a user has purchased */ | |
function fetchMyNFTs() public view returns (MarketItem[] memory) { | |
uint256 totalItemCount = _itemIds.current(); | |
uint256 itemCount = 0; | |
uint256 currentIndex = 0; | |
for (uint256 i = 0; i < totalItemCount; i++) { | |
if (idToMarketItem[i + 1].owner == msg.sender) { | |
itemCount += 1; | |
} | |
} | |
MarketItem[] memory items = new MarketItem[](itemCount); | |
for (uint256 i = 0; i < totalItemCount; i++) { | |
if (idToMarketItem[i + 1].owner == msg.sender) { | |
uint256 currentId = i + 1; | |
MarketItem storage currentItem = idToMarketItem[currentId]; | |
items[currentIndex] = currentItem; | |
currentIndex += 1; | |
} | |
} | |
return items; | |
} | |
/* Returns only items a user has created */ | |
function fetchItemsCreated() public view returns (MarketItem[] memory) { | |
uint256 totalItemCount = _itemIds.current(); | |
uint256 itemCount = 0; | |
uint256 currentIndex = 0; | |
for (uint256 i = 0; i < totalItemCount; i++) { | |
if (idToMarketItem[i + 1].seller == msg.sender) { | |
itemCount += 1; | |
} | |
} | |
MarketItem[] memory items = new MarketItem[](itemCount); | |
for (uint256 i = 0; i < totalItemCount; i++) { | |
if (idToMarketItem[i + 1].seller == msg.sender) { | |
uint256 currentId = i + 1; | |
MarketItem storage currentItem = idToMarketItem[currentId]; | |
items[currentIndex] = currentItem; | |
currentIndex += 1; | |
} | |
} | |
return items; | |
} | |
function fetchTokeByID(uint _tokenID) public view returns ( | |
uint256 itemId, | |
address nftContract, | |
address payable seller, | |
uint256 price, | |
bool sold, | |
address owner | |
) { | |
uint256 totalItemCount = _itemIds.current(); | |
uint256 itemCount = 0; | |
uint256 currentIndex = 0; | |
for (uint256 i = 0; i < totalItemCount; i++) { | |
if (idToMarketItem[i + 1].tokenId == _tokenID) { | |
itemCount += 1; | |
} | |
} | |
MarketItem[] memory items = new MarketItem[](itemCount); | |
for (uint256 i = 0; i < totalItemCount; i++) { | |
if (idToMarketItem[i + 1].tokenId == _tokenID) { | |
uint256 currentId = i + 1; | |
MarketItem storage currentItem = idToMarketItem[currentId]; | |
items[currentIndex] = currentItem; | |
currentIndex += 1; | |
return (currentItem.itemId, currentItem.nftContract, currentItem.seller, currentItem.price, currentItem.sold, currentItem.owner); | |
} | |
} | |
} | |
///////////////////////////////////////////////////////////////////////// | |
// hasERC721TokenSold | |
///////////////////////////////////////////////////////////////////////// | |
/** | |
* @dev Check whether the ERC721 token has sold at least once. | |
* @param _contractAddress address ERC721Contract address. | |
* @param _tokenId uint256 token ID. | |
* @return bool of whether the token has sold. | |
*/ | |
function hasERC721TokenSold(address _contractAddress, uint256 _tokenId) | |
internal | |
view | |
returns (bool) | |
{ | |
return soldTokens[_contractAddress][_tokenId]; | |
} | |
///////////////////////////////////////////////////////////////////////// | |
// markERC721TokenAsSold | |
///////////////////////////////////////////////////////////////////////// | |
/** | |
* @dev Mark a token as sold. | |
* Requirements: | |
* | |
* - `_contractAddress` cannot be the zero address. | |
* @param _contractAddress address ERC721Contract address. | |
* @param _tokenId uint256 token ID. | |
* @param _hasSold bool of whether the token should be marked sold or not. | |
*/ | |
function markERC721Token( | |
address _contractAddress, | |
uint256 _tokenId, | |
bool _hasSold | |
) internal { | |
soldTokens[_contractAddress][_tokenId] = _hasSold; | |
} | |
function checkContractBalance() onlyOwner private view returns(uint balanceEth) | |
{ | |
return address(this).balance; | |
} | |
receive() external payable { | |
emit Received(msg.sender, msg.value); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT OR Apache-2.0 | |
pragma solidity ^0.8.2; | |
import "./SendValueProxy.sol"; | |
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; | |
/** | |
* @dev Contract with a ISendValueProxy that will catch reverts when attempting to transfer funds. | |
*/ | |
contract MaybeSendValue is Initializable{ | |
SendValueProxy proxy; | |
/// @custom:oz-upgrades-unsafe-allow constructor | |
function initializeMaybeSendValue() public { | |
proxy = new SendValueProxy(); | |
} | |
/** | |
* @dev Maybe send some wei to the address via a proxy. Returns true on success and false if transfer fails. | |
* @param _to address to send some value to. | |
* @param _value uint256 amount to send. | |
*/ | |
function maybeSendValue(address payable _to, uint256 _value) | |
internal | |
returns (bool) | |
{ | |
// Call sendValue on the proxy contract and forward the mesg.value. | |
/* solium-disable-next-line */ | |
(bool success, ) = address(proxy).call{value: _value}( | |
abi.encodeWithSignature("sendValue(address)", _to) | |
); | |
// (bool success, bytes memory _) = address(proxy).call.value(_value)( | |
// abi.encodeWithSignature("sendValue(address)", _to) | |
// ); | |
return success; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.2; | |
import "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol"; | |
import "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721URIStorageUpgradeable.sol"; | |
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; | |
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; | |
import "@openzeppelin/contracts-upgradeable/utils/CountersUpgradeable.sol"; | |
import "@openzeppelin/contracts-upgradeable/utils/math/SafeMathUpgradeable.sol"; | |
contract NFT_V1 is Initializable, ERC721Upgradeable, ERC721URIStorageUpgradeable, OwnableUpgradeable { | |
using SafeMathUpgradeable for uint256; | |
using CountersUpgradeable for CountersUpgradeable.Counter; | |
CountersUpgradeable.Counter private _tokenIds; | |
address contractAddress; | |
event MarketplaceAddress(address); | |
function initialize() initializer public { | |
__Ownable_init(); | |
__ERC721_init("MOWSSE", "MWSSE"); | |
__ERC721URIStorage_init(); | |
} | |
function setMarketPlaceAddress(address marketplaceAddress) public onlyOwner{ | |
contractAddress = marketplaceAddress; | |
emit MarketplaceAddress(marketplaceAddress); | |
} | |
function createToken(string memory _tokenURI) public returns (uint) { | |
_tokenIds.increment(); | |
uint256 newItemId = _tokenIds.current(); | |
_mint(msg.sender, newItemId); | |
_setTokenURI(newItemId, _tokenURI); | |
setApprovalForAll(contractAddress, true); | |
return newItemId; | |
} | |
// The following functions are overrides required by Solidity. | |
function _burn(uint256 tokenId) | |
internal | |
override(ERC721Upgradeable, ERC721URIStorageUpgradeable) | |
{ | |
super._burn(tokenId); | |
} | |
function tokenURI(uint256 tokenId) | |
public | |
view | |
override(ERC721Upgradeable, ERC721URIStorageUpgradeable) | |
returns (string memory) | |
{ | |
return super.tokenURI(tokenId); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.2; | |
import "@openzeppelin/contracts-upgradeable/utils/math/SafeMathUpgradeable.sol"; | |
import "./SendValueOrEscrow.sol"; | |
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; | |
/** | |
* @title Payments contract for SuperRare Marketplaces. | |
*/ | |
contract Payments is Initializable , SendValueOrEscrow { | |
using SafeMathUpgradeable for uint256; | |
using SafeMathUpgradeable for uint8; | |
event payment1(uint payment1); | |
event payment0(uint payment0); | |
function initializePayments() public { | |
SendValueOrEscrow.initializeSendValueOrEscrow(); | |
} | |
///////////////////////////////////////////////////////////////////////// | |
// refund | |
///////////////////////////////////////////////////////////////////////// | |
/** | |
* @dev Internal function to refund an address. Typically for canceled bids or offers. | |
* Requirements: | |
* | |
* - _payee cannot be the zero address | |
* | |
* @param _marketplacePercentage uint8 percentage of the fee for the marketplace. | |
* @param _amount uint256 value to be split. | |
* @param _payee address seller of the token. | |
*/ | |
function refund( | |
uint8 _marketplacePercentage, | |
address payable _payee, | |
uint256 _amount | |
) internal { | |
require( | |
_payee != address(0), | |
"refund::no payees can be the zero address" | |
); | |
if (_amount > 0) { | |
SendValueOrEscrow.sendValueOrEscrow( | |
_payee, | |
_amount.add( | |
calcPercentagePayment(_amount, _marketplacePercentage) | |
) | |
); | |
} | |
} | |
///////////////////////////////////////////////////////////////////////// | |
// payout | |
///////////////////////////////////////////////////////////////////////// | |
/** | |
* @dev Internal function to pay the seller, creator, and maintainer. | |
* Requirements: | |
* | |
* - _marketplacePercentage + _royaltyPercentage + _primarySalePercentage <= 100 | |
* - no payees can be the zero address | |
* | |
* @param _amount uint256 value to be split. | |
* @param _isPrimarySale bool of whether this is a primary sale. | |
* @param _royaltyPercentage uint8 percentage of the fee for the royalty. | |
* @param _payee address seller of the token. | |
* @param _royaltyPayee address seller of the token. | |
*/ | |
function payout( | |
uint256 _amount, | |
bool _isPrimarySale, | |
uint8 _royaltyPercentage, | |
address payable _payee, | |
address payable _royaltyPayee | |
) internal { | |
require( | |
_royaltyPercentage <= 100, | |
"payout::percentages cannot go beyond 100" | |
); | |
require( | |
_payee != address(0) && | |
_royaltyPayee != address(0), | |
"payout::no payees can be the zero address" | |
); | |
// Note:: Solidity is kind of terrible in that there is a limit to local | |
// variables that can be put into the stack. The real pain is that | |
// one can put structs, arrays, or mappings into memory but not basic | |
// data types. Hence our payments array that stores these values. | |
uint256[4] memory payments; | |
// uint256 royaltyPayment | |
payments[0] = calcRoyaltyPayment( | |
_isPrimarySale, | |
_amount, | |
_royaltyPercentage | |
); | |
emit payment0(payments[0]); | |
// uint256 payeePayment | |
payments[1] = _amount.sub(payments[0]); | |
emit payment1(payments[1]); | |
// royaltyPayment | |
if (payments[0] > 0) { | |
SendValueOrEscrow.sendValueOrEscrow(_royaltyPayee, payments[0]); | |
} | |
// payeePayment | |
if (payments[1] > 0) { | |
SendValueOrEscrow.sendValueOrEscrow(_payee, payments[1]); | |
} | |
} | |
///////////////////////////////////////////////////////////////////////// | |
// calcRoyaltyPayment | |
///////////////////////////////////////////////////////////////////////// | |
/** | |
* @dev Private function to calculate Royalty amount. | |
* If primary sale: 0 | |
* If no royalty percentage: 0 | |
* otherwise: royalty in wei | |
* @param _isPrimarySale bool of whether this is a primary sale | |
* @param _amount uint256 value to be split | |
* @param _percentage uint8 royalty percentage | |
* @return uint256 wei value owed for royalty | |
*/ | |
function calcRoyaltyPayment( | |
bool _isPrimarySale, | |
uint256 _amount, | |
uint8 _percentage | |
) private pure returns (uint256) { | |
if (_isPrimarySale) { | |
return 0; | |
} | |
return calcPercentagePayment(_amount, _percentage); | |
} | |
///////////////////////////////////////////////////////////////////////// | |
// calcPercentagePayment | |
///////////////////////////////////////////////////////////////////////// | |
/** | |
* @dev Internal function to calculate percentage value. | |
* @param _amount uint256 wei value | |
* @param _percentage uint8 percentage | |
* @return uint256 wei value based on percentage. | |
*/ | |
function calcPercentagePayment(uint256 _amount, uint8 _percentage) | |
internal | |
pure | |
returns (uint256) | |
{ | |
return _amount.mul(_percentage).div(100); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.2; | |
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; | |
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; | |
import "@openzeppelin/contracts-upgradeable/utils/math/SafeMathUpgradeable.sol"; | |
import "./IRoyalty.sol"; | |
contract Royalty is Initializable,OwnableUpgradeable, IRoyalty { | |
using SafeMathUpgradeable for uint256; | |
uint8 creatorRoyaltyPercentage; | |
event TokenCreator(address creator, uint256 creatorRoyaltyPercentage); | |
// Mapping of token id to it's creator. | |
mapping(uint256 => address payable) private tokenCreators; | |
function initialize() initializer public { | |
__Ownable_init(); | |
creatorRoyaltyPercentage = 10; | |
} | |
///////////////////////////////////////////////////////////////////////// | |
// calculateRoyaltyFee | |
///////////////////////////////////////////////////////////////////////// | |
/** | |
* @dev Utililty function to calculate the royalty fee for a token. | |
* @param _amount uint256 wei amount. | |
* @return uint256 wei fee. | |
*/ | |
function calculateRoyaltyFee( | |
uint256 _amount | |
) external override view returns (uint256) { | |
return | |
_amount | |
.mul( | |
creatorRoyaltyPercentage | |
).div(100); | |
} | |
function setTokenRoyaltyPercentage(uint8 _creatorRoyaltyPercentage) public onlyOwner returns (uint8) { | |
require( | |
_creatorRoyaltyPercentage <= 100, | |
"setTokenRoyaltyPercentage::_percentage must be <= 100" | |
); | |
creatorRoyaltyPercentage = _creatorRoyaltyPercentage; | |
return creatorRoyaltyPercentage; | |
} | |
///////////////////////////////////////////////////////////////////////// | |
// getTokenRoyaltyPercentage | |
///////////////////////////////////////////////////////////////////////// | |
/** | |
* @dev Get the royalty fee percentage for a specific ERC721 contract. | |
* @return uint wei royalty fee. | |
*/ | |
function getTokenRoyaltyPercentage() public override view returns (uint8) { | |
return creatorRoyaltyPercentage; | |
} | |
///////////////////////////////////////////////////////////////////////// | |
// tokenCreator | |
///////////////////////////////////////////////////////////////////////// | |
/** | |
* @dev Gets the creator of the token | |
* @param _tokenId uint256 ID of the token | |
* @return address of the creator | |
*/ | |
function tokenCreator(uint256 _tokenId) | |
external | |
override | |
view | |
returns (address payable) | |
{ | |
if (tokenCreators[_tokenId] != address(0)) { | |
return tokenCreators[_tokenId]; | |
} | |
return payable(address(0)); | |
} | |
///////////////////////////////////////////////////////////////////////// | |
// setTokenCreator | |
///////////////////////////////////////////////////////////////////////// | |
/** | |
* @dev Sets the creator of the token | |
* @param _tokenId uint256 ID of the token | |
* @param _creator address of the creator for the token | |
*/ | |
function setTokenCreator( | |
uint256 _tokenId, | |
address payable _creator | |
) private { | |
require( | |
_creator != address(0), | |
"setTokenCreator::Cannot set null address as creator" | |
); | |
tokenCreators[_tokenId] = _creator; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT OR Apache-2.0 | |
pragma solidity ^0.8.2; | |
// import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/security/PullPayment.sol"; | |
import "@openzeppelin/contracts-upgradeable/security/PullPaymentUpgradeable.sol"; | |
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; | |
import "./MaybeSendValue.sol"; | |
/** | |
* @dev Contract to make payments. If a direct transfer fails, it will store the payment in escrow until the address decides to pull the payment. | |
*/ | |
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; | |
contract SendValueOrEscrow is Initializable, MaybeSendValue, PullPaymentUpgradeable { | |
///////////////////////////////////////////////////////////////////////// | |
// Events | |
///////////////////////////////////////////////////////////////////////// | |
event SendValue(address indexed _payee, uint256 amount); | |
function initializeSendValueOrEscrow() public { | |
MaybeSendValue.initializeMaybeSendValue(); | |
__PullPayment_init(); | |
} | |
///////////////////////////////////////////////////////////////////////// | |
// sendValueOrEscrow | |
///////////////////////////////////////////////////////////////////////// | |
/** | |
* @dev Send some value to an address. | |
* @param _to address to send some value to. | |
* @param _value uint256 amount to send. | |
*/ | |
function sendValueOrEscrow(address payable _to, uint256 _value) internal { | |
// attempt to make the transfer | |
bool successfulTransfer = MaybeSendValue.maybeSendValue(_to, _value); | |
// if it fails, transfer it into escrow for them to redeem at their will. | |
if (!successfulTransfer) { | |
_asyncTransfer(_to, _value); | |
} | |
emit SendValue(_to, _value); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT OR Apache-2.0 | |
pragma solidity ^0.8.2; | |
import "./ISendValueProxy.sol"; | |
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; | |
/** | |
* @dev Contract that attempts to send value to an address. | |
*/ | |
contract SendValueProxy is Initializable, ISendValueProxy { | |
/** | |
* @dev Send some wei to the address. | |
* @param _to address to send some value to. | |
*/ | |
function sendValue(address payable _to) external override payable { | |
// Note that `<address>.transfer` limits gas sent to receiver. It may | |
// not support complex contract operations in the future. | |
_to.transfer(msg.value); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// contracts/Market.sol | |
// SPDX-License-Identifier: MIT OR Apache-2.0 | |
pragma solidity ^0.8.2; | |
import "./SignatureNFT.sol"; | |
import "@openzeppelin/contracts-upgradeable/token/ERC1155/utils/ERC1155HolderUpgradeable.sol"; | |
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; | |
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; | |
import "@openzeppelin/contracts-upgradeable/utils/CountersUpgradeable.sol"; | |
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol"; | |
import "hardhat/console.sol"; | |
contract SignatureMarketPlace is | |
ReentrancyGuardUpgradeable, | |
OwnableUpgradeable, | |
ERC1155HolderUpgradeable | |
{ | |
using CountersUpgradeable for CountersUpgradeable.Counter; | |
CountersUpgradeable.Counter private _itemIds; | |
CountersUpgradeable.Counter private _itemsSold; | |
CountersUpgradeable.Counter private _itemsDeleted; | |
//owner | |
uint256 listingPrice; | |
//events | |
event ListingPriceChanged(uint256); | |
event MarketItemCreated( | |
uint256 indexed itemId, | |
address indexed nftContract, | |
uint256 indexed tokenId, | |
address creator, | |
uint256 amount, | |
address seller, | |
address owner, | |
uint256 price, | |
bool sold | |
); | |
event ProductUpdated( | |
uint256 indexed itemId, | |
uint256 indexed oldPrice, | |
uint256 indexed newPrice | |
); | |
event ProductSold( | |
uint256 indexed itemId, | |
address indexed nftContract, | |
uint256 indexed tokenId, | |
address creator, | |
address seller, | |
address owner, | |
uint256 price | |
); | |
event ProductListed( | |
uint256 indexed itemId | |
); | |
//if toke id exists in this struct, it should return only | |
struct MarketItem { | |
uint256 itemId; | |
address nftContract; | |
uint256 tokenId; | |
address payable creator; | |
uint256 amount; | |
address payable seller; | |
address payable firstBuyer; | |
address payable owner; | |
uint256 price; | |
bool sold; | |
} | |
MarketItem[] marketItems; | |
mapping(uint256 => MarketItem) private idToMarketItem; | |
//start mappings for hoodies | |
//mapping of user address to token id to hoodie size in string | |
mapping(address => mapping(uint256 => string)) private hoodieSizeForToken; | |
//address to tokenId to hoodies submitted | |
mapping(address => mapping(uint256 => bool)) private isHoodieSizeSubmittedForTokenId; | |
function initialize() public initializer { | |
__ReentrancyGuard_init(); | |
__Ownable_init(); | |
__ERC1155Holder_init(); | |
listingPrice = 0.025 ether; | |
} | |
modifier onlyItemOwner(uint256 id) { | |
require( | |
idToMarketItem[id].owner == msg.sender, | |
"Only product owner can do this operation" | |
); | |
_; | |
} | |
modifier onlyProductSeller(uint256 id) { | |
require( | |
idToMarketItem[id].owner == address(0) && | |
idToMarketItem[id].seller == msg.sender, "Only the product can do this operation" | |
); | |
_; | |
} | |
modifier onlyFirstBuyer(uint256 id) { | |
require( | |
idToMarketItem[id].firstBuyer == msg.sender, | |
"Only product first Buyer can do this operation" | |
); | |
_; | |
} | |
//minting projectTokens admin | |
function listPTokens( | |
address nftContract, | |
uint256 _BronzePrice, | |
uint256 _SilverPrice, | |
uint256 _GoldPrice, | |
uint256 _PlatinumPrice, | |
uint256 _LegendaryPrice | |
) external payable onlyOwner{ | |
uint Bronze = SignatureNFT(payable(address(nftContract))).Bronze(); | |
uint Silver = SignatureNFT(payable(address(nftContract))).Silver(); | |
uint Gold = SignatureNFT(payable(address(nftContract))).Gold(); | |
uint Platinum = SignatureNFT(payable(address(nftContract))).Platinum(); | |
uint Legendary = SignatureNFT(payable(address(nftContract))).Legendary(); | |
createMarketItem(nftContract, Bronze,SignatureNFT(payable(address(nftContract))).balanceOf(owner(),Bronze), _BronzePrice); | |
createMarketItem(nftContract, Silver,SignatureNFT(payable(address(nftContract))).balanceOf(owner(),Silver), _SilverPrice); | |
createMarketItem(nftContract, Gold,SignatureNFT(payable(address(nftContract))).balanceOf(owner(),Gold), _GoldPrice); | |
createMarketItem(nftContract, Platinum,SignatureNFT(payable(address(nftContract))).balanceOf(owner(),Platinum), _PlatinumPrice); | |
createMarketItem(nftContract, Legendary,SignatureNFT(payable(address(nftContract))).balanceOf(owner(),Legendary), _LegendaryPrice); | |
} | |
//submit hoodie size for token(only one) id | |
function submitHoodieSizeForTokenId( | |
address nftContract, | |
uint256 tokenId, | |
uint256 itemId, | |
string memory size | |
) external onlyFirstBuyer(itemId) { | |
require( | |
tokenId == SignatureNFT(payable(address(nftContract))).Gold() || | |
tokenId == SignatureNFT(payable(address(nftContract))).Platinum() || | |
tokenId == SignatureNFT(payable(address(nftContract))).Legendary(), | |
"submitHoodieSize: only Gold, Platinum and Legendary tokens buyers can submit hoodie size" | |
); | |
require(isHoodieSizeSubmittedForTokenId[msg.sender][tokenId] != true,"you have already submited hoodie size"); | |
require( | |
keccak256(bytes(size)) == keccak256(bytes("Small")) | |
|| keccak256(bytes(size)) == keccak256(bytes("Medium")) | |
|| keccak256(bytes(size)) == keccak256(bytes("Large")) | |
|| keccak256(bytes(size)) == keccak256(bytes("XL")) | |
|| keccak256(bytes(size)) == keccak256(bytes("XXL")) , | |
"submitHoodieSize: You can only submit Small, Medium, Large , XL and XXL as sized in string" | |
); | |
hoodieSizeForToken[msg.sender][tokenId] = size; | |
isHoodieSizeSubmittedForTokenId[msg.sender][tokenId] = true; | |
} | |
/* Places an item for sale on the marketplace | |
* for reselling, user should do setApproval for all first | |
*/ | |
function createMarketItem( | |
address nftContract, | |
uint256 tokenId, | |
uint256 amount, | |
uint256 price | |
) public payable nonReentrant { | |
require( | |
SignatureNFT(payable(address(nftContract))).exists(tokenId) != | |
false, | |
"createMarketItem: token id not exists" | |
); | |
require( | |
SignatureNFT(payable(address(nftContract))).totalSupply(tokenId) >= | |
amount, | |
"createMarketItem: wrong amount, totalSupply is less than amount" | |
); | |
require( | |
SignatureNFT(payable(address(nftContract))).balanceOf( | |
msg.sender, | |
tokenId | |
) >= amount, | |
"createMarketItem: not enough tokens" | |
); | |
require(price > 0, "Price must be at least 1 wei"); | |
if(msg.sender == owner()){ | |
require(msg.value == 0,"Listing Fee is 0 for admin"); | |
} | |
else{ | |
require( | |
msg.value == listingPrice, | |
"Price must be equal to listing price" | |
); | |
} | |
require(amount != 0, "token amount should not be equal to zero"); | |
_itemIds.increment(); | |
uint256 itemId = _itemIds.current(); | |
idToMarketItem[itemId] = MarketItem( | |
itemId, | |
nftContract, | |
tokenId, | |
payable(msg.sender), | |
amount, | |
payable(msg.sender), | |
payable(address(0)), | |
payable(address(0)), | |
price, | |
false | |
); | |
SignatureNFT(payable(address(nftContract))).safeTransferFrom( | |
msg.sender, | |
address(this), | |
tokenId, | |
amount, | |
"" | |
); | |
} | |
/* Creates the sale of a marketplace item */ | |
/* Transfers ownership of the item, as well as funds between parties */ | |
function createMarketSale( | |
address nftContract, | |
uint256 itemId, | |
uint256 amount | |
) public payable nonReentrant { | |
uint256 price = idToMarketItem[itemId].price; | |
uint256 finalPrice = price * amount; | |
uint256 tokenId = idToMarketItem[itemId].tokenId; | |
require( | |
msg.value == finalPrice, | |
"Please submit the asking price in order to complete the purchase" | |
); | |
idToMarketItem[itemId].seller.transfer(finalPrice); | |
SignatureNFT(payable(address(nftContract))).safeTransferFrom( | |
address(this), | |
msg.sender, | |
tokenId, | |
amount, | |
"" | |
); | |
idToMarketItem[itemId].firstBuyer = payable(msg.sender); | |
idToMarketItem[itemId].owner = payable(msg.sender); | |
idToMarketItem[itemId].sold = true; | |
_itemsSold.increment(); | |
if( idToMarketItem[itemId].seller != owner()){ | |
payable(owner()).transfer(listingPrice); | |
} | |
emit ProductSold( | |
idToMarketItem[itemId].itemId, | |
idToMarketItem[itemId].nftContract, | |
idToMarketItem[itemId].tokenId, | |
idToMarketItem[itemId].creator, | |
idToMarketItem[itemId].seller, | |
payable(msg.sender), | |
idToMarketItem[itemId].price | |
); | |
} | |
function putItemToResell(address nftContract, uint256 itemId,uint256 amount, uint256 newPrice) | |
public | |
payable | |
nonReentrant | |
onlyItemOwner(itemId) | |
{ | |
uint256 tokenId = idToMarketItem[itemId].tokenId; | |
require(newPrice > 0, "Price must be at least 1 wei"); | |
if(msg.sender == owner()){ | |
require(msg.value == 0,"Listing Fee is 0 for admin"); | |
} | |
else{ | |
require( | |
msg.value == listingPrice, | |
"Price must be equal to listing price" | |
); | |
} | |
SignatureNFT(payable(address(nftContract))).safeTransferFrom( | |
msg.sender, | |
address(this), | |
tokenId, | |
amount, | |
"" | |
); | |
address payable oldOwner = idToMarketItem[itemId].owner; | |
idToMarketItem[itemId].owner = payable(address(0)); | |
idToMarketItem[itemId].seller = oldOwner; | |
idToMarketItem[itemId].price = newPrice; | |
idToMarketItem[itemId].sold = false; | |
_itemsSold.decrement(); | |
emit ProductListed(itemId); | |
} | |
function updateMarketItemPrice(uint256 id, uint256 newPrice) | |
public | |
payable | |
onlyProductSeller(id) | |
{ | |
MarketItem storage item = idToMarketItem[id]; | |
uint256 oldPrice = item.price; | |
item.price = newPrice; | |
emit ProductUpdated(id, oldPrice, newPrice); | |
} | |
function changeListingPrice(uint256 _listingPrice) public onlyOwner { | |
listingPrice = _listingPrice; | |
emit ListingPriceChanged(listingPrice); | |
} | |
/* Returns the listing price of the contract */ | |
function getListingPrice() public view returns (uint256) { | |
return listingPrice; | |
} | |
function getTokenData(address nftContract, uint256 tokenId) | |
public | |
view | |
returns (string memory) | |
{ | |
return SignatureNFT(payable(address(nftContract))).uri(tokenId); | |
} | |
/* Returns all unsold market items */ | |
function fetchMarketItems() public view returns (MarketItem[] memory) { | |
uint256 itemCount = _itemIds.current(); | |
uint256 unsoldItemCount = _itemIds.current() - _itemsSold.current(); | |
uint256 currentIndex = 0; | |
MarketItem[] memory items = new MarketItem[](unsoldItemCount); | |
for (uint256 i = 0; i < itemCount; i++) { | |
if (idToMarketItem[i + 1].owner == address(0)) { | |
uint256 currentId = i + 1; | |
MarketItem storage currentItem = idToMarketItem[currentId]; | |
items[currentIndex] = currentItem; | |
currentIndex += 1; | |
} | |
} | |
return items; | |
} | |
/* Returns only items that a user has purchased */ | |
function fetchMyNFTs() public view returns (MarketItem[] memory) { | |
uint256 totalItemCount = _itemIds.current(); | |
uint256 itemCount = 0; | |
uint256 currentIndex = 0; | |
for (uint256 i = 0; i < totalItemCount; i++) { | |
if (idToMarketItem[i + 1].owner == msg.sender) { | |
itemCount += 1; | |
} | |
} | |
MarketItem[] memory items = new MarketItem[](itemCount); | |
for (uint256 i = 0; i < totalItemCount; i++) { | |
if (idToMarketItem[i + 1].owner == msg.sender) { | |
uint256 currentId = i + 1; | |
MarketItem storage currentItem = idToMarketItem[currentId]; | |
items[currentIndex] = currentItem; | |
currentIndex += 1; | |
} | |
} | |
return items; | |
} | |
/* Returns only items a user has created */ | |
function fetchItemsCreated() public view returns (MarketItem[] memory) { | |
uint256 totalItemCount = _itemIds.current(); | |
uint256 itemCount = 0; | |
uint256 currentIndex = 0; | |
for (uint256 i = 0; i < totalItemCount; i++) { | |
if (idToMarketItem[i + 1].seller == msg.sender) { | |
itemCount += 1; | |
} | |
} | |
MarketItem[] memory items = new MarketItem[](itemCount); | |
for (uint256 i = 0; i < totalItemCount; i++) { | |
if (idToMarketItem[i + 1].seller == msg.sender) { | |
uint256 currentId = i + 1; | |
MarketItem storage currentItem = idToMarketItem[currentId]; | |
items[currentIndex] = currentItem; | |
currentIndex += 1; | |
} | |
} | |
return items; | |
} | |
function fetchTokeByID(uint256 _tokenID) | |
public | |
view | |
returns ( | |
uint256 itemId, | |
address nftContract, | |
uint256 tokenId, | |
uint256 amount, | |
address payable seller, | |
address owner, | |
uint256 price, | |
bool sold | |
) | |
{ | |
uint256 totalItemCount = _itemIds.current(); | |
uint256 itemCount = 0; | |
uint256 currentIndex = 0; | |
for (uint256 i = 0; i < totalItemCount; i++) { | |
if (idToMarketItem[i + 1].tokenId == _tokenID) { | |
itemCount += 1; | |
} | |
} | |
MarketItem[] memory items = new MarketItem[](itemCount); | |
for (uint256 i = 0; i < totalItemCount; i++) { | |
if (idToMarketItem[i + 1].tokenId == _tokenID) { | |
uint256 currentId = i + 1; | |
MarketItem storage currentItem = idToMarketItem[currentId]; | |
items[currentIndex] = currentItem; | |
currentIndex += 1; | |
return ( | |
currentItem.itemId, | |
currentItem.nftContract, | |
currentItem.tokenId, | |
currentItem.amount, | |
currentItem.seller, | |
currentItem.owner, | |
currentItem.price, | |
currentItem.sold | |
); | |
} | |
} | |
} | |
function checkTotalTokensListed() | |
public | |
view | |
onlyOwner | |
returns (uint256 totalIds, uint256 soldItems) | |
{ | |
return (_itemIds.current(), _itemsSold.current()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.2; | |
import "@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol"; | |
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; | |
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol"; | |
import "@openzeppelin/contracts-upgradeable/token/ERC1155/extensions/ERC1155SupplyUpgradeable.sol"; | |
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; | |
import "@openzeppelin/contracts-upgradeable/utils/CountersUpgradeable.sol"; | |
import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol"; | |
contract SignatureNFT is Initializable, ERC1155Upgradeable, OwnableUpgradeable, PausableUpgradeable, ERC1155SupplyUpgradeable { | |
using CountersUpgradeable for CountersUpgradeable.Counter; | |
using StringsUpgradeable for string; | |
CountersUpgradeable.Counter private _tokenIds; | |
uint256 public constant Bronze = 0; | |
uint256 public constant Silver = 1; | |
uint256 public constant Gold = 2; | |
uint256 public constant Platinum = 3; | |
uint256 public constant Legendary = 4; | |
address marketPlaceAddress; | |
uint minterCopyAmount; | |
event MarketplaceAddress(address); | |
mapping (uint256 => string) private _uris; | |
event Received(address, uint256); | |
function initialize(address _marketPlaceAddress) initializer public { | |
__ERC1155_init("https://gateway.pinata.cloud/ipfs/QmeH8CLgu1xEWjeiVmyNV4McPEbfwCSRAbb3qaTgFVQXNk/{id}.json"); | |
__Ownable_init(); | |
__Pausable_init(); | |
__ERC1155Supply_init(); | |
createToken(owner(),200); | |
createToken(owner(),100); | |
createToken(owner(),50); | |
createToken(owner(),15); | |
createToken(owner(),1); | |
setTokenURIsForPtokens(); | |
minterCopyAmount = 1; | |
marketPlaceAddress = _marketPlaceAddress; | |
setApprovalForAll(marketPlaceAddress,true); | |
} | |
function createToken(address _to, uint _copies) public returns (uint) { | |
uint256 newItemId = _tokenIds.current(); | |
if (msg.sender == owner()) { | |
_mint(_to, newItemId, _copies, ""); | |
_tokenIds.increment(); | |
return newItemId; | |
} | |
else{ | |
require(msg.sender != owner(),"error: admin cannot mint this"); | |
_mint(_to, newItemId, minterCopyAmount, ""); | |
_tokenIds.increment(); | |
setApprovalForAll(marketPlaceAddress,true); | |
return newItemId; | |
} | |
} | |
function setTokenURIsForPtokens() private onlyOwner { | |
_uris[Bronze] = "https://gateway.pinata.cloud/ipfs/QmeH8CLgu1xEWjeiVmyNV4McPEbfwCSRAbb3qaTgFVQXNk/0.json"; | |
_uris[Silver] = "https://gateway.pinata.cloud/ipfs/QmeH8CLgu1xEWjeiVmyNV4McPEbfwCSRAbb3qaTgFVQXNk/1.json"; | |
_uris[Gold] = "https://gateway.pinata.cloud/ipfs/QmeH8CLgu1xEWjeiVmyNV4McPEbfwCSRAbb3qaTgFVQXNk/2.json"; | |
_uris[Platinum] = "https://gateway.pinata.cloud/ipfs/QmeH8CLgu1xEWjeiVmyNV4McPEbfwCSRAbb3qaTgFVQXNk/3.json"; | |
_uris[Legendary] = "https://gateway.pinata.cloud/ipfs/QmeH8CLgu1xEWjeiVmyNV4McPEbfwCSRAbb3qaTgFVQXNk/4.json"; | |
} | |
function changeMarketPlaceAddress(address _marketPlaceAddress) public onlyOwner{ | |
marketPlaceAddress = _marketPlaceAddress; | |
emit MarketplaceAddress(marketPlaceAddress); | |
} | |
function getMarketPlaceAddress() public view returns(address mp){ | |
return marketPlaceAddress; | |
} | |
function setTokenUri(uint256 _tokenId, string memory newuri) public { | |
require(bytes(_uris[_tokenId]).length == 0, "Cannot set uri twice"); | |
_uris[_tokenId] = newuri; | |
} | |
function uri(uint256 _tokenId) public view override returns(string memory){ | |
string memory hexstringtokenID; | |
hexstringtokenID = StringsUpgradeable.toString(_tokenId); | |
if (_tokenId < 5) { | |
return string( abi.encodePacked( "https://ipfs.io/ipfs/QmbzjepqPb2hCy7NV7RJ5C5V1R3i68RcH5eXN5ZyJkW42t/",hexstringtokenID,".json") ); | |
} else { | |
return(_uris[_tokenId]); | |
} | |
} | |
function pause() public onlyOwner { | |
_pause(); | |
} | |
function unpause() public onlyOwner { | |
_unpause(); | |
} | |
function mint(address account, uint256 id, uint256 amount, bytes memory data) | |
public | |
onlyOwner | |
{ | |
require(id <=_tokenIds.current(),""); | |
_mint(account, id, amount, data); | |
} | |
function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data) | |
public | |
onlyOwner | |
{ | |
_mintBatch(to, ids, amounts, data); | |
} | |
function _beforeTokenTransfer(address operator, address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data) | |
internal | |
whenNotPaused | |
override(ERC1155Upgradeable, ERC1155SupplyUpgradeable) | |
{ | |
super._beforeTokenTransfer(operator, from, to, ids, amounts, data); | |
} | |
function setMinterCopyAmount(uint _minterCopyAmount) public onlyOwner { | |
minterCopyAmount = _minterCopyAmount; | |
} | |
function getMinterCopyAmount() public view returns (uint) { | |
return minterCopyAmount; | |
} | |
function checkTotalTokensIdsMinted() public view returns (uint) { | |
return _tokenIds.current(); | |
} | |
function getContractAddress() public view returns (address){ | |
return marketPlaceAddress; | |
} | |
receive() external payable { | |
emit Received(msg.sender, msg.value); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.2; | |
import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol"; | |
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20WrapperUpgradeable.sol"; | |
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; | |
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; | |
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol"; | |
contract WGXB is Initializable, ERC20WrapperUpgradeable,OwnableUpgradeable, PausableUpgradeable { | |
function initialize( | |
IERC20Upgradeable _underlyingToken, | |
string memory name, | |
string memory symbol | |
) | |
initializer public { | |
__Ownable_init(); | |
__Pausable_init(); | |
__Context_init_unchained(); | |
__ERC20_init_unchained(name, symbol); | |
__ERC20Wrapper_init_unchained(_underlyingToken); | |
} | |
// @dev Mint wrapped token to cover any underlyingTokens that would have been transfered by mistake. Internal | |
function recover(address account) public returns (uint256) { | |
return _recover(account); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment