Fix ERC1155 supply tracking (#2956)
Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
(cherry picked from commit 4088540aef)
This commit is contained in:
committed by
Francisco Giordano
parent
3db4393b58
commit
70138680cf
@ -17,6 +17,10 @@
|
|||||||
* `Governor`: enable receiving Ether when a Timelock contract is not used. ([#2748](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2849))
|
* `Governor`: enable receiving Ether when a Timelock contract is not used. ([#2748](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2849))
|
||||||
* `GovernorTimelockCompound`: fix ability to use Ether stored in the Timelock contract. ([#2748](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2849))
|
* `GovernorTimelockCompound`: fix ability to use Ether stored in the Timelock contract. ([#2748](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2849))
|
||||||
|
|
||||||
|
## 4.3.3
|
||||||
|
|
||||||
|
* `ERC1155Supply`: Handle `totalSupply` changes by hooking into `_beforeTokenTransfer` to ensure consistency of balances and supply during `IERC1155Receiver.onERC1155Received` calls.
|
||||||
|
|
||||||
## 4.3.2 (2021-09-14)
|
## 4.3.2 (2021-09-14)
|
||||||
|
|
||||||
* `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.
|
* `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.
|
||||||
|
|||||||
@ -8,37 +8,14 @@ import "../token/ERC1155/extensions/ERC1155Supply.sol";
|
|||||||
contract ERC1155SupplyMock is ERC1155Mock, ERC1155Supply {
|
contract ERC1155SupplyMock is ERC1155Mock, ERC1155Supply {
|
||||||
constructor(string memory uri) ERC1155Mock(uri) {}
|
constructor(string memory uri) ERC1155Mock(uri) {}
|
||||||
|
|
||||||
function _mint(
|
function _beforeTokenTransfer(
|
||||||
address account,
|
address operator,
|
||||||
uint256 id,
|
address from,
|
||||||
uint256 amount,
|
|
||||||
bytes memory data
|
|
||||||
) internal virtual override(ERC1155, ERC1155Supply) {
|
|
||||||
super._mint(account, id, amount, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
function _mintBatch(
|
|
||||||
address to,
|
address to,
|
||||||
uint256[] memory ids,
|
uint256[] memory ids,
|
||||||
uint256[] memory amounts,
|
uint256[] memory amounts,
|
||||||
bytes memory data
|
bytes memory data
|
||||||
) internal virtual override(ERC1155, ERC1155Supply) {
|
) internal virtual override(ERC1155, ERC1155Supply) {
|
||||||
super._mintBatch(to, ids, amounts, data);
|
super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
|
||||||
}
|
|
||||||
|
|
||||||
function _burn(
|
|
||||||
address account,
|
|
||||||
uint256 id,
|
|
||||||
uint256 amount
|
|
||||||
) internal virtual override(ERC1155, ERC1155Supply) {
|
|
||||||
super._burn(account, id, amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
function _burnBatch(
|
|
||||||
address account,
|
|
||||||
uint256[] memory ids,
|
|
||||||
uint256[] memory amounts
|
|
||||||
) internal virtual override(ERC1155, ERC1155Supply) {
|
|
||||||
super._burnBatch(account, ids, amounts);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,56 +31,28 @@ abstract contract ERC1155Supply is ERC1155 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev See {ERC1155-_mint}.
|
* @dev See {ERC1155-_beforeTokenTransfer}.
|
||||||
*/
|
*/
|
||||||
function _mint(
|
function _beforeTokenTransfer(
|
||||||
address account,
|
address operator,
|
||||||
uint256 id,
|
address from,
|
||||||
uint256 amount,
|
|
||||||
bytes memory data
|
|
||||||
) internal virtual override {
|
|
||||||
super._mint(account, id, amount, data);
|
|
||||||
_totalSupply[id] += amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @dev See {ERC1155-_mintBatch}.
|
|
||||||
*/
|
|
||||||
function _mintBatch(
|
|
||||||
address to,
|
address to,
|
||||||
uint256[] memory ids,
|
uint256[] memory ids,
|
||||||
uint256[] memory amounts,
|
uint256[] memory amounts,
|
||||||
bytes memory data
|
bytes memory data
|
||||||
) internal virtual override {
|
) internal virtual override {
|
||||||
super._mintBatch(to, ids, amounts, data);
|
super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
|
||||||
for (uint256 i = 0; i < ids.length; ++i) {
|
|
||||||
_totalSupply[ids[i]] += amounts[i];
|
if (from == address(0)) {
|
||||||
|
for (uint256 i = 0; i < ids.length; ++i) {
|
||||||
|
_totalSupply[ids[i]] += amounts[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
if (to == address(0)) {
|
||||||
* @dev See {ERC1155-_burn}.
|
for (uint256 i = 0; i < ids.length; ++i) {
|
||||||
*/
|
_totalSupply[ids[i]] -= amounts[i];
|
||||||
function _burn(
|
}
|
||||||
address account,
|
|
||||||
uint256 id,
|
|
||||||
uint256 amount
|
|
||||||
) internal virtual override {
|
|
||||||
super._burn(account, id, amount);
|
|
||||||
_totalSupply[id] -= amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @dev See {ERC1155-_burnBatch}.
|
|
||||||
*/
|
|
||||||
function _burnBatch(
|
|
||||||
address account,
|
|
||||||
uint256[] memory ids,
|
|
||||||
uint256[] memory amounts
|
|
||||||
) internal virtual override {
|
|
||||||
super._burnBatch(account, ids, amounts);
|
|
||||||
for (uint256 i = 0; i < ids.length; ++i) {
|
|
||||||
_totalSupply[ids[i]] -= amounts[i];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user