-
Notifications
You must be signed in to change notification settings - Fork 0
/
wbc.sol
598 lines (519 loc) · 18.5 KB
/
wbc.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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Supply.sol";
contract WiseBuddhiClub is ERC1155, Ownable, ERC1155Supply, ReentrancyGuard {
using Strings for uint256;
string private _name;
string private _symbol;
uint256 private _totalNFTs;
uint256 private constant WBC_OG = 10001;
uint256 private constant WBC_WL = 10002;
mapping(address => uint256) private totalBalances;
string private uriSuffix = ".json";
string private uriPrefix;
string private hiddenMetadataUri;
string private identifierPrefix;
uint256 public OGPrice = 0.001 ether;
uint256 public WhitelistPrice = 0.001 ether;
uint256 public publicPrice = 0.001 ether;
uint256 public maxSupply = 10000;
uint256 public OGSupply = 1000;
uint256 public WhitelistSupply = 5000;
uint256 private totalOGSupplyMinted;
uint256 private totalWLSupplyMinted;
uint256 public maxMintAmountPerTx = 3;
uint256 public maxMintAmountPerAddress = 10;
mapping(address => uint256) private mintedAmount;
bool public revealed;
bool public paused;
uint8 private round; // 1 ~ OG mint, 2 ~ WL mint, 3 ~ public mint
/**
* @dev Initializes the contract with the given parameters.
* @param _tokenName Name of the token.
* @param _tokenSymbol Symbol of the token.
* @param _hiddenMetadataUri URI for hidden metadata.
* @param _identifierPrefix Prefix for the identifier.
*/
constructor(
string memory _tokenName,
string memory _tokenSymbol,
string memory _hiddenMetadataUri,
string memory _identifierPrefix
) ERC1155("") Ownable(_msgSender()) {
_name = _tokenName;
_symbol = _tokenSymbol;
setHiddenMetadataUri(_hiddenMetadataUri);
setIdentifierPrefix(_identifierPrefix);
_mint(owner(), WBC_OG, OGSupply, "");
_mint(owner(), WBC_WL, WhitelistSupply, "");
}
/** Modifiers **/
/**
* @dev Ensures minting complies with set rules.
* @param _mintAmount Amount to mint.
* @param user Address of the user minting.
*/
modifier mintCompliance(uint256 _mintAmount, address user) {
require(!paused || _msgSender() == owner(), "Contract Is Paused");
require( _mintAmount > 0 && _mintAmount <= maxMintAmountPerTx, "Invalid mint amount!");
require( mintedAmount[user] + _mintAmount <= maxMintAmountPerAddress, "Exceeds max mint amount");
require(totalSupply() + _mintAmount <= maxSupply, "Max supply exceeded!" );
_;
}
/**
* @dev Ensures compliance for public minting.
* @param _mintAmount Amount to mint.
*/
modifier publicCompliance(uint256 _mintAmount) {
require(round == 3, "Public mint has not started");
require(msg.value >= publicPrice * _mintAmount, "Insufficient funds!");
_;
}
/**
* @dev Ensures compliance for OG minting.
* @param _mintAmount Amount to mint.
*/
modifier OGCompliance(uint256 _mintAmount, address user) {
require( totalOGSupplyMinted + _mintAmount <= OGSupply, "OG supply exceeded!");
require(isUserOG(user), "Not OG");
require(round == 1, "The OG Mint has not started!");
require(msg.value >= OGPrice * _mintAmount, "Insufficient funds!");
_;
}
/**
* @dev Ensures compliance for whitelist minting.
* @param _mintAmount Amount to mint.
*/
modifier WLCompliance(uint256 _mintAmount, address user) {
require( totalWLSupplyMinted + _mintAmount <= WhitelistSupply, "WL supply exceeded!");
require(isUserWhitelist(user) || isUserOG(user), "Not Whitelist or OG");
require(round == 2, "The WL Mint has not started!");
require( msg.value >= WhitelistPrice * _mintAmount,"Insufficient funds!");
_;
}
/** Public Functions**/
/**
* @dev Allows whitelisted users to mint tokens.
* @param _mintAmount The number of tokens to mint.
*/
function whitelistMint(
uint256 _mintAmount
)
public
payable
WLCompliance(_mintAmount, _msgSender())
mintCompliance(_mintAmount, _msgSender())
{
mintedAmount[_msgSender()] += _mintAmount;
totalWLSupplyMinted += _mintAmount;
_mintNFT(_msgSender(), _mintAmount);
}
/**
* @dev Allows OG users to mint tokens.
* @param _mintAmount The number of tokens to mint.
*/
function OGMint(
uint256 _mintAmount
)
public
payable
OGCompliance(_mintAmount, _msgSender())
mintCompliance(_mintAmount, _msgSender())
{
mintedAmount[_msgSender()] += _mintAmount;
totalOGSupplyMinted += _mintAmount;
_mintNFT(_msgSender(), _mintAmount);
}
/**
* @dev Allows any user to mint tokens during the public sale.
* @param _mintAmount The number of tokens to mint.
*/
function mint(
uint256 _mintAmount
)
public
payable
publicCompliance(_mintAmount)
mintCompliance(_mintAmount, _msgSender())
{
mintedAmount[_msgSender()] += _mintAmount;
_mintNFT(_msgSender(), _mintAmount);
}
/**
* @dev Transfers a single token of a given ID from one address to another.
* @param from Address to transfer from.
* @param to Address to transfer to.
* @param id Token ID to transfer.
*/
function transferFrom(address from, address to, uint256 id) public {
super.safeTransferFrom(from, to, id, 1, "");
}
/** Public View Functions **/
/**
* @dev Returns the name of the token.
*/
function name() public view virtual returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token.
*/
function symbol() public view virtual returns (string memory) {
return _symbol;
}
/**
* @dev Returns the total supply of NFTs only.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalNFTs;
}
/**
* @dev Returns the total supply of all tokens, including NFTs and fungible tokens.
*/
function totalTokenSupply() public view virtual returns (uint256) {
return super.totalSupply();
}
/**
* @dev Returns the NFT balance of a specific address.
* @param account Address to check the balance of.
*/
function balanceOf(address account) public view virtual returns (uint256) {
return totalBalances[account];
}
/**
* @dev Returns the current minting round status.
*/
function getRoundStatus() public view returns (uint8) {
return round;
}
/**
* @dev Returns the URI for a given token ID.
* @param _tokenId ID of the token to retrieve its URI.
*/
function tokenURI(
uint256 _tokenId
) public view virtual returns (string memory) {
if (_tokenId == WBC_OG) {
return string(abi.encodePacked(identifierPrefix, "og", uriSuffix));
}
if (_tokenId == WBC_WL) {
return
string(
abi.encodePacked(identifierPrefix, "whitelist", uriSuffix)
);
}
if (revealed == false) {
return hiddenMetadataUri;
}
string memory currentBaseURI = _baseURI();
return
bytes(currentBaseURI).length > 0
? string(
abi.encodePacked(
currentBaseURI,
_tokenId.toString(),
uriSuffix
)
)
: "";
}
/**
* @dev Returns the URI for a given token ID.
* @param _tokenId ID of the token to retrieve its URI.
*/
function uri(
uint256 _tokenId
) public view virtual override returns (string memory) {
return tokenURI(_tokenId);
}
/**
* @dev Checks if a user is an OG user.
* @param user Address of the user to check.
* @return bool True if the user is an OG user, false otherwise.
*/
function isUserOG(address user) public view returns (bool) {
return getOGBalance(user) > 0;
}
/**
* @dev Checks if a user is a whitelisted user.
* @param user Address of the user to check.
* @return bool True if the user is a whitelisted user, false otherwise.
*/
function isUserWhitelist(address user) public view returns (bool) {
return getWLBalance(user) > 0;
}
/** Only Owner Functions **/
/**
* @dev Allows the owner to mint OG identifiers.
* @param amount Amount of OG identifiers to mint.
*/
function mintOGIdentifier(uint256 amount) public onlyOwner {
_mint(_msgSender(), WBC_OG, amount, "");
}
/**
* @dev Allows the owner to mint whitelist identifiers.
* @param amount Amount of whitelist identifiers to mint.
*/
function mintWLIdentifier(uint256 amount) public onlyOwner {
_mint(_msgSender(), WBC_WL, amount, "");
}
/**
* @dev Allows the owner to distribute OG identifiers to a list of recipients.
* @param recipients List of addresses to receive the OG identifiers.
*/
function distributeOGIdentifier(
address[] calldata recipients
) external onlyOwner {
uint256 numRecipients = recipients.length;
for (uint256 i = 0; i < numRecipients; i++) {
_safeTransferFrom(_msgSender(), recipients[i], WBC_OG, 1, "");
}
}
/**
* @dev Allows the owner to distribute whitelist identifiers to a list of recipients.
* @param recipients List of addresses to receive the whitelist identifiers.
*/
function distributeWLIdentifier(
address[] calldata recipients
) external onlyOwner {
uint256 numRecipients = recipients.length;
for (uint256 i = 0; i < numRecipients; i++) {
safeTransferFrom(_msgSender(), recipients[i], WBC_WL, 1, "");
}
}
/**
* @dev Allows the owner to airdrop NFTs to a specific address.
* @param _mintAmount Amount of NFTs to airdrop.
* @param _receiver Address to receive the airdropped NFTs.
*/
function airdropNFT(
uint256 _mintAmount,
address _receiver
) public mintCompliance(_mintAmount, _receiver) onlyOwner {
_mintNFT(_receiver, _mintAmount);
}
/**
* @dev Allows the owner to reveal the metadata.
*/
function setRevealed() public onlyOwner {
revealed = !revealed;
}
/**
* @dev Allows the owner to move to the next minting round.
* ranges from 1-3
*/
function moveRound() public onlyOwner {
require(round < 3, "In the last Round");
round++;
}
/**
* @dev Allows the owner to pause or unpause the contract.
*/
function setPaused() public onlyOwner {
paused = !paused;
}
/**
* @dev Allows the owner to set the price for public minting.
* @param price New price for public minting.
*/
function setPublicPrice(uint256 price) public onlyOwner {
publicPrice = price;
}
/**
* @dev Allows the owner to set the price for OG minting.
* @param price New price for OG minting.
*/
function setOGPrice(uint256 price) public onlyOwner {
OGPrice = price;
}
/**
* @dev Allows the owner to set the price for whitelist minting.
* @param price New price for whitelist minting.
*/
function setWhitelistPrice(uint256 price) public onlyOwner {
WhitelistPrice = price;
}
/**
* @dev Allows the owner to set the supply for whitelist minting.
* @param amount New supply for whitelist minting.
*/
function setWhitelistSupply(uint256 amount) public onlyOwner {
WhitelistSupply = amount;
}
/**
* @dev Allows the owner to set the supply for OG minting.
* @param amount New supply for OG minting.
*/
function setOGSupply(uint256 amount) public onlyOwner {
OGSupply = amount;
}
/**
* @dev Allows the owner to set the maximum mint amount per transaction.
* @param _maxMintAmountPerTx New maximum mint amount per transaction.
*/
function setMaxMintAmountPerTx(
uint256 _maxMintAmountPerTx
) public onlyOwner {
maxMintAmountPerTx = _maxMintAmountPerTx;
}
/**
* @dev Allows the owner to set the maximum mint amount per address.
* @param _maxMintAmountPerAddress New maximum mint amount per address.
*/
function setMaxMintAmountPerAddress(
uint256 _maxMintAmountPerAddress
) public onlyOwner {
maxMintAmountPerAddress = _maxMintAmountPerAddress;
}
/**
* @dev Allows the owner to set the hidden metadata URI.
* @param _hiddenMetadataUri New hidden metadata URI.
*/
function setHiddenMetadataUri(
string memory _hiddenMetadataUri
) public onlyOwner {
hiddenMetadataUri = _hiddenMetadataUri;
}
/**
* @dev Allows the owner to set the identifier prefix.
* @param _identifierPrefix New identifier prefix.
*/
function setIdentifierPrefix(
string memory _identifierPrefix
) public onlyOwner {
identifierPrefix = _identifierPrefix;
}
/**
* @dev Allows the owner to set the URI prefix.
* @param _uriPrefix New URI prefix.
*/
function setUriPrefix(string memory _uriPrefix) public onlyOwner {
uriPrefix = _uriPrefix;
}
/**
* @dev Allows the owner to set the URI Surfix.
* @param _uriSuffix New URI Surfix.
*/
function setUriSuffix(string memory _uriSuffix) public onlyOwner {
uriSuffix = _uriSuffix;
}
/**
* @dev Allows the owner to withdraw the contract balance.
*/
function withdraw() public onlyOwner nonReentrant {
// This will pay the developer 5% of the initial sale as a bonus.
// =============================================================================
(bool hs, ) = payable(0xb7804B2D70be8B599E871430d62Fb3BFeee3622D).call{
value: (address(this).balance * 5) / 100
}("");
require(hs);
// =============================================================================
// This will transfer the remaining contract balance to the owner.
// Do not remove this otherwise you will not be able to withdraw the funds.
// =============================================================================
(bool os, ) = payable(owner()).call{value: address(this).balance}("");
require(os);
// =============================================================================
}
/** Internal Functions **/
/**
* @dev Returns the balance of OG identifiers for a specific address.
* @param user Address to check the balance of OG identifiers.
*/
function getOGBalance(address user) internal view returns (uint256) {
return balanceOf(user, WBC_OG);
}
/**
* @dev Returns the balance of whitelist identifiers for a specific address.
* @param user Address to check the balance of whitelist identifiers.
*/
function getWLBalance(address user) internal view returns (uint256) {
return balanceOf(user, WBC_WL);
}
/**
* @dev Returns the base URI.
*/
function _baseURI() internal view virtual returns (string memory) {
return uriPrefix;
}
/**
* @dev Returns token ID start from.
*/
function startFrom() internal view virtual returns (uint256) {
return 1;
}
/**
* @dev Mints NFTs to a specific address.
* @param to Address to receive the minted NFTs.
* @param amount Amount of NFTs to mint.
*/
function _mintNFT(address to, uint256 amount) internal {
uint256[] memory ids = new uint256[](amount);
uint256[] memory amounts = new uint256[](amount);
for (uint256 i = 0; i < amount; i++) {
ids[i] = _totalNFTs + startFrom();
amounts[i] = 1;
_totalNFTs++;
}
_mintBatch(to, ids, amounts, "");
}
/**
* @dev Internal function that calculates the total transfer amount for NFTs.
* This function ensures that the fungible token supplies (like WBC_OG and WBC_WL) are excluded
* from the total NFT transfer amount, providing a clear distinction between fungible and non-fungible tokens.
*
* @param ids Array of token IDs involved in the transfer.
* @param values Array of amounts for each token ID being transferred.
* @return amount Total transfer amount for NFTs after excluding fungible tokens.
*/
function _getTransferAmount(
uint256[] memory ids,
uint256[] memory values
) internal pure virtual returns (uint256) {
uint256 amount = 0;
for (uint256 i = 0; i < ids.length; i++) {
// Exclude selected identifier IDs from total
if (ids[i] != WBC_OG && ids[i] != WBC_WL) {
amount += values[i];
}
}
return amount;
}
/**
* @dev Internal function that updates the balances of the sender and receiver during a transfer operation.
* This function is overridden from the ERC1155 and ERC1155Supply contracts.
* It ensures that the total balances are correctly updated based on the token IDs and their respective values.
* If the 'from' address is the zero address, it means tokens are being minted.
* If the 'to' address is the zero address, it means tokens are being burned.
*
* @param from Address of the sender.
* @param to Address of the receiver.
* @param ids Array of token IDs being transferred.
* @param values Array of amounts for each token ID being transferred.
*/
function _update(
address from,
address to,
uint256[] memory ids,
uint256[] memory values
) internal override(ERC1155, ERC1155Supply) {
if (from == address(0)) {
uint256 amount = _getTransferAmount(ids, values);
totalBalances[to] += amount;
} else {
uint256 amountTransfered = _getTransferAmount(ids, values);
totalBalances[from] -= amountTransfered;
if (to != address(0)) {
totalBalances[to] += amountTransfered;
} else {
_totalNFTs -= amountTransfered;
}
}
super._update(from, to, ids, values);
}
receive() external payable {}
}