Skip to content

Commit ebf264c

Browse files
Transpile 5548ce0
1 parent 5c21639 commit ebf264c

File tree

6 files changed

+26
-73
lines changed

6 files changed

+26
-73
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 4.3.3 (2021-11-11)
4+
5+
* `ERC1155Supply`: Handle `totalSupply` changes by hooking into `_beforeTokenTransfer` to ensure consistency of balances and supply during `IERC1155Receiver.onERC1155Received` calls.
6+
37
## 4.3.2 (2021-09-14)
48

59
* `UUPSUpgradeable`: Add modifiers to prevent `upgradeTo` and `upgradeToAndCall` being executed on any contract that is not the active ERC1967 proxy. This prevents these functions being called on implementation contracts or minimal ERC1167 clones, in particular.

contracts/mocks/ERC1155SupplyMockUpgradeable.sol

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,38 +18,15 @@ contract ERC1155SupplyMockUpgradeable is Initializable, ERC1155MockUpgradeable,
1818

1919
function __ERC1155SupplyMock_init_unchained(string memory uri) internal initializer {}
2020

21-
function _mint(
22-
address account,
23-
uint256 id,
24-
uint256 amount,
25-
bytes memory data
26-
) internal virtual override(ERC1155Upgradeable, ERC1155SupplyUpgradeable) {
27-
super._mint(account, id, amount, data);
28-
}
29-
30-
function _mintBatch(
21+
function _beforeTokenTransfer(
22+
address operator,
23+
address from,
3124
address to,
3225
uint256[] memory ids,
3326
uint256[] memory amounts,
3427
bytes memory data
3528
) internal virtual override(ERC1155Upgradeable, ERC1155SupplyUpgradeable) {
36-
super._mintBatch(to, ids, amounts, data);
37-
}
38-
39-
function _burn(
40-
address account,
41-
uint256 id,
42-
uint256 amount
43-
) internal virtual override(ERC1155Upgradeable, ERC1155SupplyUpgradeable) {
44-
super._burn(account, id, amount);
45-
}
46-
47-
function _burnBatch(
48-
address account,
49-
uint256[] memory ids,
50-
uint256[] memory amounts
51-
) internal virtual override(ERC1155Upgradeable, ERC1155SupplyUpgradeable) {
52-
super._burnBatch(account, ids, amounts);
29+
super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
5330
}
5431
uint256[50] private __gap;
5532
}

contracts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@openzeppelin/contracts-upgradeable",
33
"description": "Secure Smart Contract library for Solidity",
4-
"version": "4.3.2",
4+
"version": "4.3.3",
55
"files": [
66
"**/*.sol",
77
"/build/contracts/*.json",

contracts/token/ERC1155/extensions/ERC1155SupplyUpgradeable.sol

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -39,56 +39,28 @@ abstract contract ERC1155SupplyUpgradeable is Initializable, ERC1155Upgradeable
3939
}
4040

4141
/**
42-
* @dev See {ERC1155-_mint}.
42+
* @dev See {ERC1155-_beforeTokenTransfer}.
4343
*/
44-
function _mint(
45-
address account,
46-
uint256 id,
47-
uint256 amount,
48-
bytes memory data
49-
) internal virtual override {
50-
super._mint(account, id, amount, data);
51-
_totalSupply[id] += amount;
52-
}
53-
54-
/**
55-
* @dev See {ERC1155-_mintBatch}.
56-
*/
57-
function _mintBatch(
44+
function _beforeTokenTransfer(
45+
address operator,
46+
address from,
5847
address to,
5948
uint256[] memory ids,
6049
uint256[] memory amounts,
6150
bytes memory data
6251
) internal virtual override {
63-
super._mintBatch(to, ids, amounts, data);
64-
for (uint256 i = 0; i < ids.length; ++i) {
65-
_totalSupply[ids[i]] += amounts[i];
66-
}
67-
}
52+
super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
6853

69-
/**
70-
* @dev See {ERC1155-_burn}.
71-
*/
72-
function _burn(
73-
address account,
74-
uint256 id,
75-
uint256 amount
76-
) internal virtual override {
77-
super._burn(account, id, amount);
78-
_totalSupply[id] -= amount;
79-
}
54+
if (from == address(0)) {
55+
for (uint256 i = 0; i < ids.length; ++i) {
56+
_totalSupply[ids[i]] += amounts[i];
57+
}
58+
}
8059

81-
/**
82-
* @dev See {ERC1155-_burnBatch}.
83-
*/
84-
function _burnBatch(
85-
address account,
86-
uint256[] memory ids,
87-
uint256[] memory amounts
88-
) internal virtual override {
89-
super._burnBatch(account, ids, amounts);
90-
for (uint256 i = 0; i < ids.length; ++i) {
91-
_totalSupply[ids[i]] -= amounts[i];
60+
if (to == address(0)) {
61+
for (uint256 i = 0; i < ids.length; ++i) {
62+
_totalSupply[ids[i]] -= amounts[i];
63+
}
9264
}
9365
}
9466
uint256[49] private __gap;

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"private": true,
33
"name": "openzeppelin-solidity",
44
"description": "Secure Smart Contract library for Solidity",
5-
"version": "4.3.2",
5+
"version": "4.3.3",
66
"files": [
77
"/contracts/**/*.sol",
88
"/build/contracts/*.json",

0 commit comments

Comments
 (0)