* 4.6.0-rc.0 * Fix release script to only release @openzeppelin/contracts (cherry picked from commit2bd75a44bb) * make ERC2981:royaltyInfo public (#3305) (cherry picked from commitd2832ca7a9) Signed-off-by: Hadrien Croubois <hadrien.croubois@gmail.com> * add transpilation guards to the crosschain mocks (#3306) (cherry picked from commit9af5af8fff) Signed-off-by: Hadrien Croubois <hadrien.croubois@gmail.com> * Fix tests on upgradeable contracts after transpilation (cherry picked from commit0762479dd5) Signed-off-by: Hadrien Croubois <hadrien.croubois@gmail.com> * Remove unused constructor argument (cherry picked from commit69c3781043) Signed-off-by: Hadrien Croubois <hadrien.croubois@gmail.com> * Bump minimum Solidity version for Initializable.sol to 0.8.2 (#3328) (cherry picked from commitcb14ea3c5c) * Fix update-comment script to ignore invalid tags (cherry picked from commit848fef5b6c) Signed-off-by: Hadrien Croubois <hadrien.croubois@gmail.com> * 4.6.0 Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
65 lines
2.0 KiB
Solidity
65 lines
2.0 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC1155/extensions/ERC1155Supply.sol)
|
|
|
|
pragma solidity ^0.8.0;
|
|
|
|
import "../ERC1155.sol";
|
|
|
|
/**
|
|
* @dev Extension of ERC1155 that adds tracking of total supply per id.
|
|
*
|
|
* Useful for scenarios where Fungible and Non-fungible tokens have to be
|
|
* clearly identified. Note: While a totalSupply of 1 might mean the
|
|
* corresponding is an NFT, there is no guarantees that no other token with the
|
|
* same id are not going to be minted.
|
|
*/
|
|
abstract contract ERC1155Supply is ERC1155 {
|
|
mapping(uint256 => uint256) private _totalSupply;
|
|
|
|
/**
|
|
* @dev Total amount of tokens in with a given id.
|
|
*/
|
|
function totalSupply(uint256 id) public view virtual returns (uint256) {
|
|
return _totalSupply[id];
|
|
}
|
|
|
|
/**
|
|
* @dev Indicates whether any token exist with a given id, or not.
|
|
*/
|
|
function exists(uint256 id) public view virtual returns (bool) {
|
|
return ERC1155Supply.totalSupply(id) > 0;
|
|
}
|
|
|
|
/**
|
|
* @dev See {ERC1155-_beforeTokenTransfer}.
|
|
*/
|
|
function _beforeTokenTransfer(
|
|
address operator,
|
|
address from,
|
|
address to,
|
|
uint256[] memory ids,
|
|
uint256[] memory amounts,
|
|
bytes memory data
|
|
) internal virtual override {
|
|
super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
|
|
|
|
if (from == address(0)) {
|
|
for (uint256 i = 0; i < ids.length; ++i) {
|
|
_totalSupply[ids[i]] += amounts[i];
|
|
}
|
|
}
|
|
|
|
if (to == address(0)) {
|
|
for (uint256 i = 0; i < ids.length; ++i) {
|
|
uint256 id = ids[i];
|
|
uint256 amount = amounts[i];
|
|
uint256 supply = _totalSupply[id];
|
|
require(supply >= amount, "ERC1155: burn amount exceeds totalSupply");
|
|
unchecked {
|
|
_totalSupply[id] = supply - amount;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|