forked from OpenZeppelin/openzeppelin-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into modular-exponentiation-precompile-wrapper-O…
- Loading branch information
Showing
15 changed files
with
744 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'openzeppelin-solidity': minor | ||
--- | ||
|
||
`Arrays`: deprecate `findUpperBound` in favor of the new `lowerBound`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'openzeppelin-solidity': minor | ||
--- | ||
|
||
`ERC721Utils` and `ERC1155Utils`: Add reusable libraries with functions to perform acceptance checks on `IERC721Receiver` and `IERC1155Receiver` implementers. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'openzeppelin-solidity': minor | ||
--- | ||
|
||
`Arrays`: add new functions `lowerBound`, `upperBound`, `lowerBoundMemory` and `upperBoundMemory` for lookups in sorted arrays with potential duplicates. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.20; | ||
|
||
import {IERC1155Receiver} from "../IERC1155Receiver.sol"; | ||
import {IERC1155Errors} from "../../../interfaces/draft-IERC6093.sol"; | ||
|
||
/** | ||
* @dev Library that provide common ERC-1155 utility functions. | ||
* | ||
* See https://eips.ethereum.org/EIPS/eip-1155[ERC-1155]. | ||
*/ | ||
library ERC1155Utils { | ||
/** | ||
* @dev Performs an acceptance check for the provided `operator` by calling {IERC1155-onERC1155Received} | ||
* on the `to` address. The `operator` is generally the address that initiated the token transfer (i.e. `msg.sender`). | ||
* | ||
* The acceptance call is not executed and treated as a no-op if the target address is doesn't contain code (i.e. an EOA). | ||
* Otherwise, the recipient must implement {IERC1155Receiver-onERC1155Received} and return the acceptance magic value to accept | ||
* the transfer. | ||
*/ | ||
function checkOnERC1155Received( | ||
address operator, | ||
address from, | ||
address to, | ||
uint256 id, | ||
uint256 value, | ||
bytes memory data | ||
) internal { | ||
if (to.code.length > 0) { | ||
try IERC1155Receiver(to).onERC1155Received(operator, from, id, value, data) returns (bytes4 response) { | ||
if (response != IERC1155Receiver.onERC1155Received.selector) { | ||
// Tokens rejected | ||
revert IERC1155Errors.ERC1155InvalidReceiver(to); | ||
} | ||
} catch (bytes memory reason) { | ||
if (reason.length == 0) { | ||
// non-IERC1155Receiver implementer | ||
revert IERC1155Errors.ERC1155InvalidReceiver(to); | ||
} else { | ||
/// @solidity memory-safe-assembly | ||
assembly { | ||
revert(add(32, reason), mload(reason)) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @dev Performs a batch acceptance check for the provided `operator` by calling {IERC1155-onERC1155BatchReceived} | ||
* on the `to` address. The `operator` is generally the address that initiated the token transfer (i.e. `msg.sender`). | ||
* | ||
* The acceptance call is not executed and treated as a no-op if the target address is doesn't contain code (i.e. an EOA). | ||
* Otherwise, the recipient must implement {IERC1155Receiver-onERC1155Received} and return the acceptance magic value to accept | ||
* the transfer. | ||
*/ | ||
function checkOnERC1155BatchReceived( | ||
address operator, | ||
address from, | ||
address to, | ||
uint256[] memory ids, | ||
uint256[] memory values, | ||
bytes memory data | ||
) internal { | ||
if (to.code.length > 0) { | ||
try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, values, data) returns ( | ||
bytes4 response | ||
) { | ||
if (response != IERC1155Receiver.onERC1155BatchReceived.selector) { | ||
// Tokens rejected | ||
revert IERC1155Errors.ERC1155InvalidReceiver(to); | ||
} | ||
} catch (bytes memory reason) { | ||
if (reason.length == 0) { | ||
// non-IERC1155Receiver implementer | ||
revert IERC1155Errors.ERC1155InvalidReceiver(to); | ||
} else { | ||
/// @solidity memory-safe-assembly | ||
assembly { | ||
revert(add(32, reason), mload(reason)) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.20; | ||
|
||
import {IERC721Receiver} from "../IERC721Receiver.sol"; | ||
import {IERC721Errors} from "../../../interfaces/draft-IERC6093.sol"; | ||
|
||
/** | ||
* @dev Library that provide common ERC-721 utility functions. | ||
* | ||
* See https://eips.ethereum.org/EIPS/eip-721[ERC-721]. | ||
*/ | ||
library ERC721Utils { | ||
/** | ||
* @dev Performs an acceptance check for the provided `operator` by calling {IERC721-onERC721Received} | ||
* on the `to` address. The `operator` is generally the address that initiated the token transfer (i.e. `msg.sender`). | ||
* | ||
* The acceptance call is not executed and treated as a no-op if the target address is doesn't contain code (i.e. an EOA). | ||
* Otherwise, the recipient must implement {IERC721Receiver-onERC721Received} and return the acceptance magic value to accept | ||
* the transfer. | ||
*/ | ||
function checkOnERC721Received( | ||
address operator, | ||
address from, | ||
address to, | ||
uint256 tokenId, | ||
bytes memory data | ||
) internal { | ||
if (to.code.length > 0) { | ||
try IERC721Receiver(to).onERC721Received(operator, from, tokenId, data) returns (bytes4 retval) { | ||
if (retval != IERC721Receiver.onERC721Received.selector) { | ||
// Token rejected | ||
revert IERC721Errors.ERC721InvalidReceiver(to); | ||
} | ||
} catch (bytes memory reason) { | ||
if (reason.length == 0) { | ||
// non-IERC721Receiver implementer | ||
revert IERC721Errors.ERC721InvalidReceiver(to); | ||
} else { | ||
/// @solidity memory-safe-assembly | ||
assembly { | ||
revert(add(32, reason), mload(reason)) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.