Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update contract
  • Loading branch information
JulissaDantes committed Jan 17, 2023
commit 39025145931e762c17f443509bd391c488168d1d
13 changes: 13 additions & 0 deletions contracts/token/ERC1155/extensions/ERC1155Supply.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import "../ERC1155.sol";
*/
abstract contract ERC1155Supply is ERC1155 {
mapping(uint256 => uint256) private _totalSupply;
uint256 private _totalSupplyAll;

/**
* @dev Total amount of tokens in with a given id.
Expand All @@ -23,6 +24,13 @@ abstract contract ERC1155Supply is ERC1155 {
return _totalSupply[id];
}

/**
* @dev Total amount of tokens.
*/
function totalSupply() public view virtual returns (uint256) {
return _totalSupplyAll;
}

/**
* @dev Indicates whether any token exist with a given id, or not.
*/
Expand All @@ -40,10 +48,13 @@ abstract contract ERC1155Supply is ERC1155 {
uint256[] memory amounts,
bytes memory data
) internal virtual override {
uint256 totalAmount;
if (from == address(0)) {
for (uint256 i = 0; i < ids.length; ++i) {
_totalSupply[ids[i]] += amounts[i];
totalAmount += amounts[i];
}
_totalSupplyAll += totalAmount;
}

if (to == address(0)) {
Expand All @@ -54,8 +65,10 @@ abstract contract ERC1155Supply is ERC1155 {
require(supply >= amount, "ERC1155: burn amount exceeds totalSupply");
unchecked {
_totalSupply[id] = supply - amount;
totalAmount += amount;
}
}
_totalSupplyAll -= totalAmount;
}
super._update(from, to, ids, amounts, data);
}
Expand Down