Skip to content

Commit

Permalink
Nft and Token Factory
Browse files Browse the repository at this point in the history
  • Loading branch information
Ifechukwudaniel committed Dec 13, 2023
1 parent dd9a154 commit 3f0b5ff
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 0 deletions.
42 changes: 42 additions & 0 deletions packages/hardhat/contracts/Factories/NftFactory/ERC721Token.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract ERC721Token is Ownable,ERC721 {

uint256 public nextId = 1;
string public uri;
uint256 public maxSupply;
uint256 public mintPrice;

constructor(
string memory _name,
string memory _symbol,
string memory _uri,
uint256 _maxSupply ,
uint256 _mintPrice,
address _owner
) Ownable(_owner) ERC721(_name, _symbol) {
uri = _uri;
maxSupply = _maxSupply;
mintPrice = _mintPrice;
}

function mint() external payable {
require(msg.value == mintPrice, "!mintPrice");
require(nextId <= maxSupply, "Max Supply Reached");
_mint(msg.sender, nextId++);
}

function _baseURI() internal view override returns (string memory) {
return uri;
}

function withdraw() external onlyOwner {
(bool success, ) = payable(msg.sender).call{value: address(this).balance}("");
require(success);
}

}
31 changes: 31 additions & 0 deletions packages/hardhat/contracts/Factories/NftFactory/FactoryERC721.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;


import "./ERC721Token.sol";

contract FactoryERC721 {

address[] public colections;
mapping(address => address) colectionToOwner;

event DeployedCollection( address indexed colection, uint256 date);

function deploy(
string memory _name,string memory _symbol, string memory _uri, uint256 _maxSupply, uint256 _mintPrice
) external {
ERC721Token newCollection = new ERC721Token(_name,_symbol,_uri, _maxSupply, _mintPrice, msg.sender);
newCollection.transferOwnership(msg.sender);
colections.push(address(newCollection));
colectionToOwner[msg.sender] = address(newCollection);
emit DeployedCollection(address(newCollection),block.timestamp);
}

function collectionCount() external view returns(uint256) {
return colections.length;
}

function getCollectionOwner(address userAddress) external view returns(address) {
return colectionToOwner[userAddress];
}
}
50 changes: 50 additions & 0 deletions packages/hardhat/contracts/Factories/TokenFactory/ERC20Token.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";


contract ERC20Token is ERC20,Ownable {
bool public limited;
uint256 public maxHoldingAmount;
uint256 public minHoldingAmount;
address public pairPool;
mapping(address => bool) public blacklists;

constructor(string memory _name, string memory _symbol,uint256 _totalSupply, address _owner) Ownable(_owner) ERC20(_name, _symbol) {
_mint(msg.sender, _totalSupply);
}

function blacklist(address _address, bool _isBlacklisting) external onlyOwner {
blacklists[_address] = _isBlacklisting;
}

function setRule(bool _limited, address _pairPool, uint256 _maxHoldingAmount, uint256 _minHoldingAmount) external onlyOwner {
limited = _limited;
pairPool = _pairPool;
maxHoldingAmount = _maxHoldingAmount;
minHoldingAmount = _minHoldingAmount;
}

function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {
require(!blacklists[to] && !blacklists[from], "Blacklisted");

if (pairPool == address(0)) {
require(from == owner() || to == owner(), "trading is not started");
return;
}

if (limited && from == pairPool) {
require(super.balanceOf(to) + amount <= maxHoldingAmount && super.balanceOf(to) + amount >= minHoldingAmount, "Forbid");
}
}

function burn(uint256 value) external onlyOwner {
_burn(msg.sender, value);
}
}
31 changes: 31 additions & 0 deletions packages/hardhat/contracts/Factories/TokenFactory/FactoryERC20.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;


import "./ERC20Token.sol";

contract FactoryERC20 {

address[] public deployedTokens;
mapping(address => address) tokenToOwner;

event DeployedToken( address indexed tokenAddress, uint256 date );

function deploy(
string memory _name,string memory _symbol, uint256 _totalSupply
) external {
ERC20Token newToken = new ERC20Token(_name,_symbol,_totalSupply, msg.sender);
newToken.transferOwnership(msg.sender);
deployedTokens.push(address(newToken));
tokenToOwner[msg.sender] = address(newToken);
emit DeployedToken(address(newToken),block.timestamp);
}

function collectionCount() external view returns(uint256) {
return deployedTokens.length;
}

function getTokenOwner(address tokenOwnerAddress) external view returns(address) {
return tokenToOwner[tokenOwnerAddress];
}
}

0 comments on commit 3f0b5ff

Please sign in to comment.