From 3a15bf11456f96f874a3216cc8ea0691a997109a Mon Sep 17 00:00:00 2001 From: Moon Date: Sun, 5 Feb 2023 16:35:43 -0500 Subject: [PATCH] special handling for token 1 --- contracts/CurioERC1155Wrapper.sol | 25 ++++++++++++++++++++++++- contracts/IERC223ReceivingContract.sol | 6 ++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 contracts/IERC223ReceivingContract.sol diff --git a/contracts/CurioERC1155Wrapper.sol b/contracts/CurioERC1155Wrapper.sol index 4d1686b..6398954 100644 --- a/contracts/CurioERC1155Wrapper.sol +++ b/contracts/CurioERC1155Wrapper.sol @@ -6,13 +6,14 @@ import "./IMastersFedi.sol"; import "./Address.sol"; import "./IERC1155Metadata.sol"; import "./ERC1155Metadata.sol"; +import "./IERC223ReceivingContract.sol"; import "@openzeppelin/contracts/utils/Strings.sol"; import "@openzeppelin/contracts/utils/Base64.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/security/Pausable.sol"; import "@openzeppelin/contracts/token/common/ERC2981.sol"; -contract CurioERC1155Wrapper is ERC1155, ERC1155Metadata_URI, ERC1155Metadata, ERC2981, Ownable, Pausable { +contract CurioERC1155Wrapper is ERC1155, ERC1155Metadata_URI, ERC1155Metadata, ERC2981, IERC223ReceivingContract, Ownable, Pausable { using Address for address; mapping (uint256 => address) public contracts; @@ -139,6 +140,24 @@ contract CurioERC1155Wrapper is ERC1155, ERC1155Metadata_URI, ERC1155Metadata, E destroyable = false; } + /** + @dev called by token 1 contract after transfer, this is the only method to wrap 1. + */ + function tokenFallback(address _from, uint256 _value, bytes memory) override external { + require(_from == owner(), "Only owner can wrap token 1"); + require(msg.sender == contracts[1] , "Can only transfer from token 1 owner"); + IMastersFedi curio = IMastersFedi(contracts[1]); + require (curio.balanceOf(address(this)) <= 450, "Sanity transfer exceeded"); + // no balance check is done because an overflow would fail the sanity check anyway + + balances[1][_from] += _value; + + // mint + emit TransferSingle(msg.sender, address(0), _from, 1, _value); + + // safe transfer acceptance check not necessary because locked to a known contract + } + /** @notice Converts old-style NFT to new-style @dev For an NFT ID, queries and transfers tokens from the appropriate @@ -150,6 +169,7 @@ contract CurioERC1155Wrapper is ERC1155, ERC1155Metadata_URI, ERC1155Metadata, E function wrap(uint256 _id, uint256 _quantity) external whenNotPaused { address tokenContract = contracts[_id]; require(tokenContract != address(0), "invalid id"); + require(_id != 1, "cannot wrap token 1 this way"); IMastersFedi curio = IMastersFedi(tokenContract); // these are here for convenience because curio contract doesn't throw meaningful exceptions @@ -186,6 +206,7 @@ contract CurioERC1155Wrapper is ERC1155, ERC1155Metadata_URI, ERC1155Metadata, E address tokenContract = contracts[_id]; require(tokenContract != address(0), "invalid id"); + require(_id != 1, "cannot wrap token 1 this way"); IMastersFedi curio = IMastersFedi(tokenContract); require(curio.balanceOf(msg.sender) >= _quantity, "insufficient curio balance"); @@ -214,6 +235,7 @@ contract CurioERC1155Wrapper is ERC1155, ERC1155Metadata_URI, ERC1155Metadata, E function unwrap(uint256 _id, uint256 _quantity) external whenNotPaused { address tokenContract = contracts[_id]; require(tokenContract != address(0), "invalid id"); + require(_id != 1, "token 1 cannot be unwrapped"); IMastersFedi curio = IMastersFedi(tokenContract); require(balances[_id][msg.sender] >= _quantity, "insufficient balance"); @@ -241,6 +263,7 @@ contract CurioERC1155Wrapper is ERC1155, ERC1155Metadata_URI, ERC1155Metadata, E address tokenContract = contracts[_id]; require(tokenContract != address(0), "invalid id"); + require(_id != 1, "token 1 cannot be unwrapped"); IMastersFedi curio = IMastersFedi(tokenContract); require(balances[_id][msg.sender] >= _quantity, "insufficient balance"); diff --git a/contracts/IERC223ReceivingContract.sol b/contracts/IERC223ReceivingContract.sol new file mode 100644 index 0000000..f8288bc --- /dev/null +++ b/contracts/IERC223ReceivingContract.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: AGPL-3.0-or-later +pragma solidity ^0.8.17; + +interface IERC223ReceivingContract { + function tokenFallback(address _from, uint256 _value, bytes memory _data) external; +}