-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMemeTokenERC20Factory.sol
113 lines (93 loc) · 3.54 KB
/
MemeTokenERC20Factory.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// SPDX-License-Identifier: MIT
// Compatible with OpenZeppelin Contracts ^5.0.0
pragma solidity ^0.8.20;
import "@openzeppelin/[email protected]/token/ERC20/ERC20.sol";
import "@openzeppelin/[email protected]/access/Ownable.sol";
contract DeflationaryToken is ERC20, Ownable {
uint256 public maxSupply;
string public uri;
constructor(string memory _name, string memory _symbol, uint256 _initialSupply, uint256 _maxSupply, address _initialOwner, string memory _uri)
ERC20(_name, _symbol)
Ownable(_initialOwner)
{
require(_initialSupply <= _maxSupply, "Initial supply cannot exceed max supply");
maxSupply = _maxSupply;
uri = _uri;
_mint(_initialOwner, _initialSupply);
}
function setUri(string memory _uri) public onlyOwner{
uri = _uri;
}
function getUri() public view returns (string memory) {
return uri;
}
function mint(address to, uint256 amount) public onlyOwner {
require(totalSupply() + amount <= maxSupply, "Minting would exceed max supply");
_mint(to, amount);
}
}
contract InflationaryToken is ERC20, Ownable {
string public uri;
constructor(string memory _name, string memory _symbol, uint256 _initialSupply, address _initialOwner, string memory _uri)
ERC20(_name, _symbol)
Ownable(_initialOwner)
{
uri = _uri;
_mint(_initialOwner, _initialSupply);
}
function setUri(string memory _uri) public onlyOwner{
uri = _uri;
}
function getUri() public view returns (string memory) {
return uri;
}
function mint(address to, uint256 amount) public onlyOwner {
_mint(to, amount);
}
}
contract MemeTokenFactory {
event TokenCreated(address tokenAddress);
enum Strategy {
Inflationary,
Deflationary
}
struct ContractInfo {
string name;
string symbol;
uint256 initialSupply;
uint256 maxSupply;
string uri;
Strategy strategy;
}
mapping(address => address[]) public ownerToTokens;
mapping(address => ContractInfo) public tokenToContractInfo;
function createInflationaryToken(string memory name, string memory symbol, uint256 initialSupply, address initialOwner, string memory uri) public {
InflationaryToken newToken = new InflationaryToken(name, symbol, initialSupply, initialOwner, uri);
ownerToTokens[initialOwner].push(address(newToken));
tokenToContractInfo[address(newToken)] = ContractInfo({
name: name,
symbol: symbol,
initialSupply: initialSupply,
maxSupply: 0,
uri: uri,
strategy: Strategy.Inflationary
});
emit TokenCreated(address(newToken));
}
function createDeflationaryToken(string memory name, string memory symbol, uint256 initialSupply, uint256 maxSupply, address initialOwner, string memory uri) public {
DeflationaryToken newToken = new DeflationaryToken(name, symbol, initialSupply, maxSupply, initialOwner, uri);
ownerToTokens[initialOwner].push(address(newToken));
tokenToContractInfo[address(newToken)] = ContractInfo({
name: name,
symbol: symbol,
initialSupply: initialSupply,
maxSupply: maxSupply,
uri: uri,
strategy: Strategy.Deflationary
});
emit TokenCreated(address(newToken));
}
function getTokensForOwner(address owner) public view returns (address[] memory) {
return ownerToTokens[owner];
}
}