forked from josephmartinmoran/ERC721_Factory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNFTA_Factory
170 lines (142 loc) · 5.67 KB
/
NFTA_Factory
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import './ERC721A.sol';
import '@openzeppelin/contracts/access/Ownable.sol';
import '@openzeppelin/contracts/security/ReentrancyGuard.sol';
import '@openzeppelin/contracts/utils/Strings.sol';
// contract Factory{
// NFTA[] public nftas;
// uint disabledCount;
// event NFTACreated(address NFTAAddress, string _name, string _symbol, uint256 _maxBatchSize, uint256 _collectionSize, uint256 _amountForDevs, uint256 _PRICE_PER_TOKEN);
// function createNFTA(string memory _name, string memory _symbol, uint256 _maxBatchSize, uint256 _collectionSize, uint256 _amountForDevs, uint256 _PRICE_PER_TOKEN) external{
// NFTA nfta = new NFTA(_name, _symbol, _maxBatchSize, _collectionSize, _amountForDevs, _PRICE_PER_TOKEN);
// nftas.push(nfta);
// emit NFTACreated(address(nfta), _name, _symbol, _maxBatchSize, _collectionSize, _amountForDevs, _PRICE_PER_TOKEN);
// }
// function getNFTAs() external view returns(NFTA[] memory _nftas){
// _nftas = new NFTA[](nftas.length- disabledCount);
// uint count;
// for(uint i=0;i<nftas.length; i++){
// if(nftas[i].isEnabled()){
// _nftas[count] = nftas[i];
// count++;
// }
// }
// }
// function disable(NFTA nfta) external {
// nftas[nfta.index()].disable();
// disabledCount++;
// }
// }
contract NFTA is ERC721A, Ownable {
string public PROVENANCE;
bool public saleIsActive = false;
string private _baseURIextended;
bool public isAllowListActive = false;
uint256 public collectionsize;
uint256 public maxBatchsize;
uint256 public PRICE_PER_TOKEN;
string name_;
string symbol_;
uint256 public amountForDevs;
// bool public isEnabled;
// uint public index;
mapping(address => uint8) private _allowList;
constructor(string memory _name, string memory _symbol, uint256 _maxBatchSize, uint256 _collectionSize, uint256 _amountForDevs, uint256 _PRICE_PER_TOKEN)
ERC721A(name_, symbol_, maxBatchsize, collectionsize, amountForDevs, PRICE_PER_TOKEN) {
name_ = _name;
symbol_ = _symbol;
maxBatchsize = _maxBatchSize;
collectionsize = _collectionSize;
amountForDevs = _amountForDevs;
PRICE_PER_TOKEN = _PRICE_PER_TOKEN;
// isEnabled = true;
// index = _index;
}
// function disable() external{
// isEnabled = false;
// }
function setIsAllowListActive(bool _isAllowListActive) external onlyOwner {
isAllowListActive = _isAllowListActive;
}
function setAllowList(address[] calldata addresses, uint8 numAllowedToMint) external onlyOwner {
for (uint256 i = 0; i < addresses.length; i++) {
_allowList[addresses[i]] = numAllowedToMint;
}
}
function numAvailableToMint(address addr) external view returns (uint8) {
return _allowList[addr];
}
function mintAllowList(uint8 numberOfTokens) external payable {
uint256 ts = totalSupply();
require(isAllowListActive, "Allow list is not active");
require(numberOfTokens <= _allowList[msg.sender], "Exceeded max available to purchase");
require(ts + numberOfTokens <= collectionsize, "Purchase would exceed max tokens");
require(PRICE_PER_TOKEN * numberOfTokens <= msg.value, "Ether value sent is not correct");
_allowList[msg.sender] -= numberOfTokens;
for (uint256 i = 0; i < numberOfTokens; i++) {
_safeMint(msg.sender, ts + i);
}
}
// For marketing etc.
function devMint(uint256 quantity) external onlyOwner {
require(
totalSupply() + quantity <= amountForDevs,
"too many already minted before dev mint"
);
require(
quantity % maxBatchsize == 0,
"can only mint a multiple of the maxBatchsize"
);
uint256 numChunks = quantity / maxBatchsize;
for (uint256 i = 0; i < numChunks; i++) {
_safeMint(msg.sender, maxBatchsize);
}
}
function setBaseURI(string memory baseURI_) external onlyOwner() {
_baseURIextended = baseURI_;
}
function _baseURI() internal view virtual override returns (string memory) {
return _baseURIextended;
}
function setProvenance(string memory provenance) public onlyOwner {
PROVENANCE = provenance;
}
function reserve(uint256 n) public onlyOwner {
uint supply = totalSupply();
uint i;
for (i = 0; i < n; i++) {
_safeMint(msg.sender, supply + i);
}
}
function setSaleState(bool newState) public onlyOwner {
saleIsActive = newState;
}
function mint(uint numberOfTokens) public payable {
uint256 ts = totalSupply();
require(saleIsActive, "Sale must be active to mint tokens");
require(numberOfTokens <= maxBatchsize, "Exceeded max token purchase");
require(ts + numberOfTokens <= collectionsize, "Purchase would exceed max tokens");
require(PRICE_PER_TOKEN * numberOfTokens <= msg.value, "Ether value sent is not correct");
for (uint256 i = 0; i < numberOfTokens; i++) {
_safeMint(msg.sender, ts + i);
}
}
function withdraw() external onlyOwner{
(bool success, ) = msg.sender.call{value: address(this).balance}("");
require(success, "Transfer failed.");
}
function setOwnersExplicit(uint256 quantity) external onlyOwner {
_setOwnersExplicit(quantity);
}
function numberMinted(address owner) public view returns (uint256) {
return _numberMinted(owner);
}
function getOwnershipData(uint256 tokenId)
external
view
returns (TokenOwnership memory)
{
return ownershipOf(tokenId);
}
}