ing
This commit is contained in:
61
contracts/Factory/ERC721Factory.sol
Normal file
61
contracts/Factory/ERC721Factory.sol
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
pragma solidity 0.6.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import {ICloneFactory} from "../lib/CloneFactory.sol";
|
||||
import {InitializableERC721} from "../external/ERC721/InitializableERC721.sol";
|
||||
|
||||
/**
|
||||
* @title DODO ERC721Factory
|
||||
* @author DODO Breeder
|
||||
*
|
||||
* @notice Help user to create erc721 token
|
||||
*/
|
||||
contract ERC721Facotry {
|
||||
// ============ Templates ============
|
||||
|
||||
address public immutable _CLONE_FACTORY_;
|
||||
address public immutable _ERC721_TEMPLATE_;
|
||||
|
||||
// ============ Events ============
|
||||
|
||||
event NewERC721(address erc721, address creator);
|
||||
|
||||
// ============ Registry ============
|
||||
mapping(address => address[]) public _USER_REGISTRY_;
|
||||
|
||||
// ============ Functions ============
|
||||
|
||||
constructor(
|
||||
address cloneFactory,
|
||||
address erc721Template
|
||||
) public {
|
||||
_CLONE_FACTORY_ = cloneFactory;
|
||||
_ERC721_TEMPLATE_ = erc721Template;
|
||||
}
|
||||
|
||||
function createERC721(
|
||||
string memory name,
|
||||
string memory symbol,
|
||||
string memory baseUrl
|
||||
) external returns (address newERC721) {
|
||||
newERC721 = ICloneFactory(_CLONE_FACTORY_).clone(_ERC721_TEMPLATE_);
|
||||
InitializableERC721(newERC721).init(msg.sender, name, symbol, baseUrl);
|
||||
_USER_REGISTRY_[msg.sender].push(newERC721);
|
||||
emit NewERC721(newERC721, msg.sender);
|
||||
}
|
||||
|
||||
|
||||
function getTokenByUser(address user)
|
||||
external
|
||||
view
|
||||
returns (address[] memory tokens)
|
||||
{
|
||||
return _USER_REGISTRY_[user];
|
||||
}
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
//TODO:
|
||||
pragma solidity 0.6.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import {ICloneFactory} from "../lib/CloneFactory.sol";
|
||||
import {InitializableERC20} from "../external/ERC20/InitializableERC20.sol";
|
||||
import {InitializableMintableERC20} from "../external/ERC20/InitializableMintableERC20.sol";
|
||||
|
||||
/**
|
||||
* @title DODO TokenFactory
|
||||
* @author DODO Breeder
|
||||
*
|
||||
* @notice Help user to create erc20 && erc721 && erc1155 token
|
||||
*/
|
||||
contract TokenFacotry {
|
||||
// ============ Templates ============
|
||||
|
||||
address public immutable _CLONE_FACTORY_;
|
||||
address public immutable _ERC20_TEMPLATE_;
|
||||
address public immutable _MINTABLE_ERC20_TEMPLATE_;
|
||||
|
||||
// ============ Events ============
|
||||
|
||||
event NewERC20(address erc20, address creator, bool isMintable);
|
||||
|
||||
// ============ Registry ============
|
||||
// creator -> token address list
|
||||
mapping(address => address[]) public _USER_STD_REGISTRY_;
|
||||
|
||||
// ============ Functions ============
|
||||
|
||||
constructor(
|
||||
address cloneFactory,
|
||||
address erc20Template,
|
||||
address mintableErc20Template
|
||||
) public {
|
||||
_CLONE_FACTORY_ = cloneFactory;
|
||||
_ERC20_TEMPLATE_ = erc20Template;
|
||||
_MINTABLE_ERC20_TEMPLATE_ = mintableErc20Template;
|
||||
}
|
||||
|
||||
function createStdERC20(
|
||||
uint256 totalSupply,
|
||||
string memory name,
|
||||
string memory symbol,
|
||||
uint256 decimals
|
||||
) external returns (address newERC20) {
|
||||
newERC20 = ICloneFactory(_CLONE_FACTORY_).clone(_ERC20_TEMPLATE_);
|
||||
InitializableERC20(newERC20).init(msg.sender, totalSupply, name, symbol, decimals);
|
||||
_USER_STD_REGISTRY_[msg.sender].push(newERC20);
|
||||
emit NewERC20(newERC20, msg.sender, false);
|
||||
}
|
||||
|
||||
function createMintableERC20(
|
||||
uint256 initSupply,
|
||||
string memory name,
|
||||
string memory symbol,
|
||||
uint256 decimals
|
||||
) external returns (address newMintableERC20) {
|
||||
newMintableERC20 = ICloneFactory(_CLONE_FACTORY_).clone(_MINTABLE_ERC20_TEMPLATE_);
|
||||
InitializableMintableERC20(newMintableERC20).init(
|
||||
msg.sender,
|
||||
initSupply,
|
||||
name,
|
||||
symbol,
|
||||
decimals
|
||||
);
|
||||
emit NewERC20(newMintableERC20, msg.sender, true);
|
||||
}
|
||||
|
||||
|
||||
function getTokenByUser(address user)
|
||||
external
|
||||
view
|
||||
returns (address[] memory tokens)
|
||||
{
|
||||
return _USER_STD_REGISTRY_[user];
|
||||
}
|
||||
}
|
||||
35
contracts/external/ERC721/InitializableERC721.sol
vendored
Normal file
35
contracts/external/ERC721/InitializableERC721.sol
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
|
||||
// import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
|
||||
import {InitializableOwnable} from "../../lib/InitializableOwnable.sol";
|
||||
|
||||
//TODO:
|
||||
contract InitializableERC721 is InitializableOwnable {
|
||||
|
||||
|
||||
function init(
|
||||
address creator,
|
||||
string memory name,
|
||||
string memory symbol,
|
||||
string memory baseUrl
|
||||
) public {
|
||||
initOwner(creator);
|
||||
// super(name,symbol);
|
||||
}
|
||||
|
||||
// baseUrl overide
|
||||
|
||||
// function mint(string memory _name, address _to) public {
|
||||
// require(msg.sender == gameOwner, "Only game owner can create new monsters");
|
||||
// uint id = monsters.length;
|
||||
// monsters.push(Monster(_name, 1));
|
||||
// _safeMint(_to, id);
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user