commit2897abccc9Author: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Fri Jul 14 15:31:29 2023 +0200 Update ERC721.sol commite26d5c0951Author: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Fri Jul 14 08:46:48 2023 +0200 Update IERC721.sol commita475ffae0aAuthor: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Fri Jul 14 08:45:25 2023 +0200 Update ERC721.sol commit20bb47f439Author: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Fri Jul 14 08:43:14 2023 +0200 Update contracts/token/ERC721/ERC721.sol commitf404802d55Author: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Fri Jul 14 08:41:30 2023 +0200 Update ERC721.sol commitb982e2a808Author: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Fri Jul 14 08:38:46 2023 +0200 Update ERC721.behavior.js commitca32b459ecAuthor: Francisco Giordano <fg@frang.io> Date: Thu Jul 13 19:14:15 2023 -0300 fix _safeTransfer docs commitcaabbf3c46Author: Francisco Giordano <fg@frang.io> Date: Thu Jul 13 19:08:36 2023 -0300 improve warnings and notes commita023cad591Author: Francisco Giordano <fg@frang.io> Date: Thu Jul 13 18:21:27 2023 -0300 wrap long line commit5ce49a45fdAuthor: Francisco Giordano <fg@frang.io> Date: Thu Jul 13 18:19:30 2023 -0300 remove unnecessary solhint annotation commitd0375301f1Author: Francisco <fg@frang.io> Date: Thu Jul 13 18:17:24 2023 -0300 Apply suggestions from code review Co-authored-by: Ernesto García <ernestognw@gmail.com> commit81aca96467Author: Francisco <fg@frang.io> Date: Thu Jul 13 18:16:42 2023 -0300 Update CHANGELOG.md Co-authored-by: Ernesto García <ernestognw@gmail.com> commit12f63b3b1bAuthor: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Thu Jul 13 17:28:04 2023 +0200 add test commit08da709ba7Author: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Thu Jul 13 16:45:30 2023 +0200 refactor _checkAuhtorized commit328b16bf8cAuthor: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Thu Jul 13 16:29:05 2023 +0200 Authorised → Authorized commitb29e573383Author: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Thu Jul 13 16:14:57 2023 +0200 rename from → previousOwner commite996ba49d8Author: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Thu Jul 13 16:00:38 2023 +0200 add ERC721 specific details in the 'How to upgrade from 4.x' section of the CHANGELOG commit20048ca3b9Author: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Thu Jul 13 11:00:11 2023 +0200 Changes suggested in the PR discussions commit4c25b48803Merge:d7a6aaf4fb4d9510Author: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Thu Jul 13 10:00:55 2023 +0200 Merge branch 'refactor/erc721-update-fnPointer' of https://github.com/Amxx/openzeppelin-contracts into refactor/erc721-update-fnPointer commitd7a6aaf41fAuthor: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Thu Jul 13 10:00:50 2023 +0200 remove _exists commitfb4d9510deAuthor: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Thu Jul 13 10:00:39 2023 +0200 Apply suggestions from code review Co-authored-by: Francisco <fg@frang.io> Co-authored-by: Ernesto García <ernestognw@gmail.com> commit10815081f7Author: ernestognw <ernestognw@gmail.com> Date: Wed Jul 12 21:09:18 2023 -0600 Lint commit9ba012005fAuthor: ernestognw <ernestognw@gmail.com> Date: Wed Jul 12 20:28:50 2023 -0600 Format _increaseBalance NatSpec commit7c3f1615b0Author: Francisco <fg@frang.io> Date: Wed Jul 12 20:29:11 2023 -0300 Update .changeset/eighty-lemons-shake.md Co-authored-by: Ernesto García <ernestognw@gmail.com> commit4516803058Author: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Wed Jul 12 17:15:48 2023 +0200 make the safe function without a data field non virtual commite4b0e725dfAuthor: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Wed Jul 12 16:56:07 2023 +0200 use whenNotPaused in ERC721Pausable commitb973d985a4Author: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Wed Jul 12 14:11:59 2023 +0200 changesets commit7121ff7c5fMerge:2558c8fade570d0dAuthor: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Wed Jul 12 13:46:07 2023 +0200 Merge branch 'erc721-approve-0' into refactor/erc721-update-fnPointer commitde570d0d14Author: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Wed Jul 12 13:42:46 2023 +0200 allow using approve/_approve to clean approval commit2558c8fac8Author: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Wed Jul 12 10:16:55 2023 +0200 change _increaseBalance type to uint128 commit16f2f15673Author: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Wed Jul 12 10:01:30 2023 +0200 remove _isApproedOrOwner in favor of _isApproved + refactor _checkOnERC721Received commit7e9d024d08Author: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Wed Jul 12 09:31:18 2023 +0200 Apply suggestions from code review Co-authored-by: Ernesto García <ernestognw@gmail.com> commit1a9552009bAuthor: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Tue Jul 11 21:47:23 2023 +0200 replace constraints with a simple operator check commitbd0c52e34aAuthor: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Tue Jul 11 18:06:29 2023 +0200 refactor constraint into an optionalChecks bitmap commit5ab254cf95Author: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Fri Jul 7 16:13:17 2023 +0200 lint commit0bb98cb8c6Merge:562ddf567ccea54dAuthor: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Fri Jul 7 16:11:40 2023 +0200 Merge branch 'master' into feature/Governor-storage commit562ddf566aAuthor: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Wed Jul 5 18:45:42 2023 +0200 implement hybrid _update commit54cb3ca05fMerge:c7303ec2bb644589Author: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Mon Jul 3 21:09:30 2023 +0200 Merge branch 'master' into refactor/erc721-update-fnPointer commitc7303ec2aeAuthor: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Mon Jul 3 09:37:53 2023 +0200 fix lint commit1cc7f54ab5Merge:78c280b506861dceAuthor: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Mon Jul 3 09:35:35 2023 +0200 Merge remote-tracking branch 'upstream' into refactor/erc721-update-fnPointer commit78c280b537Merge:e2fdbacd04342118Author: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Fri Jun 30 18:40:55 2023 +0200 Merge branch 'master' into refactor/erc721-update-fnPointer commite9f03bd211Author: Francisco Giordano <fg@frang.io> Date: Fri Jun 30 12:09:15 2023 -0300 Exclude address(0) in ERC721._isApprovedOrOwner commite2fdbacd63Author: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Wed Jun 21 22:09:50 2023 +0200 fix lint commit7ec34355aeAuthor: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Wed Jun 21 17:59:22 2023 +0200 Apply suggestions from code review commit1ed8f9ef2cAuthor: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Wed Jun 21 17:56:00 2023 +0200 use __unsafe_increaseBalance to react to batch minting commita3526acdf2Author: Hadrien Croubois <hadrien.croubois@gmail.com> Date: Thu Apr 27 16:37:40 2023 +0200 Rebase ERC721._update on top of next-v5
103 lines
4.2 KiB
Solidity
103 lines
4.2 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/extensions/ERC721Wrapper.sol)
|
|
|
|
pragma solidity ^0.8.19;
|
|
|
|
import {IERC721, ERC721} from "../ERC721.sol";
|
|
import {IERC721Receiver} from "../IERC721Receiver.sol";
|
|
|
|
/**
|
|
* @dev Extension of the ERC721 token contract to support token wrapping.
|
|
*
|
|
* Users can deposit and withdraw an "underlying token" and receive a "wrapped token" with a matching tokenId. This is useful
|
|
* in conjunction with other modules. For example, combining this wrapping mechanism with {ERC721Votes} will allow the
|
|
* wrapping of an existing "basic" ERC721 into a governance token.
|
|
*/
|
|
abstract contract ERC721Wrapper is ERC721, IERC721Receiver {
|
|
IERC721 private immutable _underlying;
|
|
|
|
/**
|
|
* @dev The received ERC721 token couldn't be wrapped.
|
|
*/
|
|
error ERC721UnsupportedToken(address token);
|
|
|
|
constructor(IERC721 underlyingToken) {
|
|
_underlying = underlyingToken;
|
|
}
|
|
|
|
/**
|
|
* @dev Allow a user to deposit underlying tokens and mint the corresponding tokenIds.
|
|
*/
|
|
function depositFor(address account, uint256[] memory tokenIds) public virtual returns (bool) {
|
|
uint256 length = tokenIds.length;
|
|
for (uint256 i = 0; i < length; ++i) {
|
|
uint256 tokenId = tokenIds[i];
|
|
|
|
// This is an "unsafe" transfer that doesn't call any hook on the receiver. With underlying() being trusted
|
|
// (by design of this contract) and no other contracts expected to be called from there, we are safe.
|
|
// slither-disable-next-line reentrancy-no-eth
|
|
underlying().transferFrom(_msgSender(), address(this), tokenId);
|
|
_safeMint(account, tokenId);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @dev Allow a user to burn wrapped tokens and withdraw the corresponding tokenIds of the underlying tokens.
|
|
*/
|
|
function withdrawTo(address account, uint256[] memory tokenIds) public virtual returns (bool) {
|
|
uint256 length = tokenIds.length;
|
|
for (uint256 i = 0; i < length; ++i) {
|
|
uint256 tokenId = tokenIds[i];
|
|
// Setting an "auth" arguments enables the `_isApproved` check which verifies that the token exists
|
|
// (from != 0). Therefore, it is not needed to verify that the return value is not 0 here.
|
|
_update(address(0), tokenId, _msgSender());
|
|
// Checks were already performed at this point, and there's no way to retake ownership or approval from
|
|
// the wrapped tokenId after this point, so it's safe to remove the reentrancy check for the next line.
|
|
// slither-disable-next-line reentrancy-no-eth
|
|
underlying().safeTransferFrom(address(this), account, tokenId);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @dev Overrides {IERC721Receiver-onERC721Received} to allow minting on direct ERC721 transfers to
|
|
* this contract.
|
|
*
|
|
* In case there's data attached, it validates that the operator is this contract, so only trusted data
|
|
* is accepted from {depositFor}.
|
|
*
|
|
* WARNING: Doesn't work with unsafe transfers (eg. {IERC721-transferFrom}). Use {ERC721Wrapper-_recover}
|
|
* for recovering in that scenario.
|
|
*/
|
|
function onERC721Received(address, address from, uint256 tokenId, bytes memory) public virtual returns (bytes4) {
|
|
if (address(underlying()) != _msgSender()) {
|
|
revert ERC721UnsupportedToken(_msgSender());
|
|
}
|
|
_safeMint(from, tokenId);
|
|
return IERC721Receiver.onERC721Received.selector;
|
|
}
|
|
|
|
/**
|
|
* @dev Mint a wrapped token to cover any underlyingToken that would have been transferred by mistake. Internal
|
|
* function that can be exposed with access control if desired.
|
|
*/
|
|
function _recover(address account, uint256 tokenId) internal virtual returns (uint256) {
|
|
address owner = underlying().ownerOf(tokenId);
|
|
if (owner != address(this)) {
|
|
revert ERC721IncorrectOwner(address(this), tokenId, owner);
|
|
}
|
|
_safeMint(account, tokenId);
|
|
return tokenId;
|
|
}
|
|
|
|
/**
|
|
* @dev Returns the underlying token.
|
|
*/
|
|
function underlying() public view virtual returns (IERC721) {
|
|
return _underlying;
|
|
}
|
|
}
|