-
Notifications
You must be signed in to change notification settings - Fork 1
/
ERC721PsiAddressData.sol
82 lines (73 loc) · 2.65 KB
/
ERC721PsiAddressData.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
// SPDX-License-Identifier: MIT
/**
* ______ _____ _____ ______ ___ __ _ _ _
* | ____| __ \ / ____|____ |__ \/_ | || || |
* | |__ | |__) | | / / ) || | \| |/ |
* | __| | _ /| | / / / / | |\_ _/
* | |____| | \ \| |____ / / / /_ | | | |
* |______|_| \_\\_____|/_/ |____||_| |_|
*/
pragma solidity ^0.8.0;
import "../ERC721Psi.sol";
import "solidity-bits/contracts/BitMaps.sol";
/**
* @dev This extension follows the AddressData format of ERC721A, so
* it can be a dropped-in replacement for the contract that requires AddressData
*/
abstract contract ERC721PsiAddressData is ERC721Psi {
// Mapping owner address to address data
mapping(address => AddressData) _addressData;
// Compiler will pack this into a single 256bit word.
struct AddressData {
// Realistically, 2**64-1 is more than enough.
uint64 balance;
// Keeps track of mint count with minimal overhead for tokenomics.
uint64 numberMinted;
// Keeps track of burn count with minimal overhead for tokenomics.
uint64 numberBurned;
// For miscellaneous variable(s) pertaining to the address
// (e.g. number of whitelist mint slots used).
// If there are multiple variables, please pack them into a uint64.
uint64 aux;
}
/**
* @dev See {IERC721-balanceOf}.
*/
function balanceOf(address owner) public view virtual override returns (uint256) {
require(owner != address(0), "ERC721Psi: balance query for the zero address");
return uint256(_addressData[owner].balance);
}
/**
* @dev Hook that is called after a set of serially-ordered token ids have been transferred. This includes
* minting.
*
* startTokenId - the first token id to be transferred
* quantity - the amount to be transferred
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero.
* - `from` and `to` are never both zero.
*/
function _afterTokenTransfers(address from, address to, uint256 startTokenId, uint256 quantity)
internal
virtual
override
{
require(quantity < 2 ** 64);
uint64 _quantity = uint64(quantity);
if (from != address(0)) {
_addressData[from].balance -= _quantity;
} else {
// Mint
_addressData[to].numberMinted += _quantity;
}
if (to != address(0)) {
_addressData[to].balance += _quantity;
} else {
// Burn
_addressData[from].numberBurned += _quantity;
}
super._afterTokenTransfers(from, to, startTokenId, quantity);
}
}