special handling for token 1

This commit is contained in:
Moon Man 2023-02-05 16:35:43 -05:00
parent f3e292bec2
commit 3a15bf1145
2 changed files with 30 additions and 1 deletions

View File

@ -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");

View File

@ -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;
}