Skip to content

Instantly share code, notes, and snippets.

@shipunyc
Last active July 23, 2021 09:06
Show Gist options
  • Select an option

  • Save shipunyc/a70187d29be4553b8aab8d5b676dd640 to your computer and use it in GitHub Desktop.

Select an option

Save shipunyc/a70187d29be4553b8aab8d5b676dd640 to your computer and use it in GitHub Desktop.
Wrapper class for BlockchainCuties NFT
// SPDX-License-Identifier: MIT
pragma solidity 0.8.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
interface NonStandardERC721TokenReceiver {
function onERC721Received(address _from, uint256 _tokenId, bytes calldata data) external returns(bytes4);
}
interface IBlockchainCuties is IERC721 {
function tokenURI(uint256 _tokenId) external view returns (string memory infoUrl);
}
contract BlockchainCutiesNFTWrapper is ERC721, NonStandardERC721TokenReceiver {
IBlockchainCuties public inner;
address public owner;
constructor (IBlockchainCuties inner_, string memory name_, string memory symbol_) ERC721(name_, symbol_) {
inner = inner_;
owner = msg.sender;
}
function onERC721Received(address, uint256, bytes calldata) public virtual override returns (bytes4) {
return this.onERC721Received.selector;
}
function deposit(uint256 tokenId_) external {
inner.safeTransferFrom(_msgSender(), address(this), tokenId_);
_mint(_msgSender(), tokenId_);
}
function depositInBatch(uint256[] calldata tokenIdArray_) external {
for (uint256 i = 0; i < tokenIdArray_.length; ++i) {
uint256 tokenId = tokenIdArray_[i];
inner.safeTransferFrom(_msgSender(), address(this), tokenId);
_mint(_msgSender(), tokenId);
}
}
// Can be called by a script to help user withdraw secretly.
function withdraw(uint256 tokenId_) external {
address who = ownerOf(tokenId_);
require(_msgSender() == owner || _msgSender() == who, "Only contract owner or NFT owner can call");
require(!_isContract(who), "who should not be contract");
_burn(tokenId_);
inner.safeTransferFrom(address(this), who, tokenId_);
}
function tokenURI(uint256 _tokenId) public override view returns (string memory infoUrl) {
return inner.tokenURI(_tokenId);
}
function _isContract(address _account) internal view returns (bool) {
uint256 size;
// solhint-disable-next-line no-inline-assembly
assembly { size := extcodesize(_account) }
return size > 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment