Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion contracts/openzeppelin/access/AccessControl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ abstract contract AccessControl is Context, IAccessControl, ERC165 {
string(
abi.encodePacked(
"AccessControl: account ",
Strings.toHexString(uint160(account), 20),
Strings.toHexString(uint168(account), 20),
" is missing role ",
Strings.toHexString(uint256(role), 32)
)
Expand Down
8 changes: 4 additions & 4 deletions contracts/openzeppelin/mocks/ERC1155ReceiverMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ contract ERC1155ReceiverMock is ERC165, IERC1155Receiver {
bytes4 private _batRetval;
bool private _batReverts;

event Received(address operator, address from, uint256 id, uint256 value, bytes data, uint256 gas);
event BatchReceived(address operator, address from, uint256[] ids, uint256[] values, bytes data, uint256 gas);
event Received(address operator, address from, uint256 id, uint256 value, bytes data);
event BatchReceived(address operator, address from, uint256[] ids, uint256[] values, bytes data);

constructor(
bytes4 recRetval,
Expand All @@ -34,7 +34,7 @@ contract ERC1155ReceiverMock is ERC165, IERC1155Receiver {
bytes calldata data
) external override returns (bytes4) {
require(!_recReverts, "ERC1155ReceiverMock: reverting on receive");
emit Received(operator, from, id, value, data, gasleft());
emit Received(operator, from, id, value, data);
return _recRetval;
}

Expand All @@ -46,7 +46,7 @@ contract ERC1155ReceiverMock is ERC165, IERC1155Receiver {
bytes calldata data
) external override returns (bytes4) {
require(!_batReverts, "ERC1155ReceiverMock: reverting on batch receive");
emit BatchReceived(operator, from, ids, values, data, gasleft());
emit BatchReceived(operator, from, ids, values, data);
return _batRetval;
}
}
59 changes: 30 additions & 29 deletions contracts/openzeppelin/token/ERC1155/ERC1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// OpenZeppelin Contracts v4.4.1 (token/ERC1155/ERC1155.sol)

pragma solidity ^0.8.0;
pragma experimental Await;

import "./IERC1155.sol";
import "./IERC1155Receiver.sol";
Expand Down Expand Up @@ -170,6 +171,9 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {

_beforeTokenTransfer(operator, from, to, _asSingletonArray(id), _asSingletonArray(amount), data);

bool checkPassed = _doSafeTransferAcceptanceCheck(operator, from, to, id, amount, data);
require(checkPassed, "ERC1155: failed to pass the acceptance check");

uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: insufficient balance for transfer");
unchecked {
Expand All @@ -178,8 +182,6 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
_balances[id][to] += amount;

emit TransferSingle(operator, from, to, id, amount);

_doSafeTransferAcceptanceCheck(operator, from, to, id, amount, data);
}

/**
Expand All @@ -206,6 +208,9 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {

_beforeTokenTransfer(operator, from, to, ids, amounts, data);

bool checkPassed = _doSafeBatchTransferAcceptanceCheck(operator, from, to, ids, amounts, data);
require(checkPassed, "ERC1155: failed to pass the acceptance check");

for (uint256 i = 0; i < ids.length; ++i) {
uint256 id = ids[i];
uint256 amount = amounts[i];
Expand All @@ -219,8 +224,6 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
}

emit TransferBatch(operator, from, to, ids, amounts);

_doSafeBatchTransferAcceptanceCheck(operator, from, to, ids, amounts, data);
}

/**
Expand Down Expand Up @@ -269,10 +272,11 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {

_beforeTokenTransfer(operator, address(0), to, _asSingletonArray(id), _asSingletonArray(amount), data);

bool checkPassed = _doSafeTransferAcceptanceCheck(operator, address(0), to, id, amount, data);
require(checkPassed, "ERC1155: failed to pass the acceptance check");

_balances[id][to] += amount;
emit TransferSingle(operator, address(0), to, id, amount);

_doSafeTransferAcceptanceCheck(operator, address(0), to, id, amount, data);
}

/**
Expand All @@ -297,13 +301,14 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {

_beforeTokenTransfer(operator, address(0), to, ids, amounts, data);

for (uint256 i = 0; i < ids.length; i++) {
bool checkPassed = _doSafeBatchTransferAcceptanceCheck(operator, address(0), to, ids, amounts, data);
require(checkPassed, "ERC1155: failed to pass the acceptance check");

for (uint256 i = 0; i < ids.length; i++) {
_balances[ids[i]][to] += amounts[i];
}

emit TransferBatch(operator, address(0), to, ids, amounts);

_doSafeBatchTransferAcceptanceCheck(operator, address(0), to, ids, amounts, data);
}

/**
Expand Down Expand Up @@ -418,18 +423,17 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
uint256 id,
uint256 amount,
bytes memory data
) private {
) private returns (bool) {
if (to.isContract()) {
try IERC1155Receiver(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) {
if (response != IERC1155Receiver.onERC1155Received.selector) {
revert("ERC1155: ERC1155Receiver rejected tokens");
}
} catch Error(string memory reason) {
revert(reason);
} catch {
revert("ERC1155: transfer to non ERC1155Receiver implementer");
bytes4 response = await IERC1155Receiver(to).onERC1155Received(operator, from, id, amount, data);
if (response == IERC1155Receiver.onERC1155Received.selector) {
return true;
}
} else {
return true;
}

return false;
}

function _doSafeBatchTransferAcceptanceCheck(
Expand All @@ -439,20 +443,17 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) private {
) private returns (bool) {
if (to.isContract()) {
try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns (
bytes4 response
) {
if (response != IERC1155Receiver.onERC1155BatchReceived.selector) {
revert("ERC1155: ERC1155Receiver rejected tokens");
}
} catch Error(string memory reason) {
revert(reason);
} catch {
revert("ERC1155: transfer to non ERC1155Receiver implementer");
bytes4 response = await IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data);
if (response == IERC1155Receiver.onERC1155BatchReceived.selector) {
return true;
}
} else {
return true;
}

return false;
}

function _asSingletonArray(uint256 element) private pure returns (uint256[] memory) {
Expand Down
8 changes: 3 additions & 5 deletions contracts/openzeppelin/utils/Address.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ library Address {
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.

return account.code.length > 0;
// A Vite address can be converted to a bytes21 (An Ethereum address can be converted to a bytes20).
// The last byte of the bytes21 represents the address type, 0x00 for user address and 0x01 for contract address.
return bytes21(account)[20] == 0x01;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions contracts/openzeppelin/utils/structs/EnumerableSet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ library EnumerableSet {
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
return _add(set._inner, bytes32(uint256(uint168(value))));
}

/**
Expand All @@ -232,14 +232,14 @@ library EnumerableSet {
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
return _remove(set._inner, bytes32(uint256(uint168(value))));
}

/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
return _contains(set._inner, bytes32(uint256(uint168(value))));
}

/**
Expand All @@ -260,7 +260,7 @@ library EnumerableSet {
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
return address(uint168(uint256(_at(set._inner, index))));
}

/**
Expand Down
Loading