Verified contractExactMIT
FleeceNewHome
Address0xf3869e91c3f0f8bc937f2dece1e22c7b645494e7
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.30
- Same code
Only this contract
Details
- Compiler
- solc 0.8.30+commit.73712a01
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- cancun
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,487,747
- Creation transaction
- 0xdb88351754…eb4c328299
src/FleeceNewHome.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.30;
/// @notice The subset of the Fleece ERC-721 that custody uses.
interface IFleece {
function ownerOf(uint256 tokenId) external view returns (address);
function transferFrom(address from, address to, uint256 tokenId) external;
function safeTransferFrom(address from, address to, uint256 tokenId) external;
}
/// @title Fleece — A New Home
/// @notice Custody for Fleece artworks that collectors voluntarily return.
///
/// Deposit — send a Fleece to this contract.
/// * safeTransferFrom by the holder: recorded as depositor; may take the work
/// back at any time with `withdraw`. Safe transfers started by an approved
/// operator (marketplace, other contract) are rejected.
/// * transferFrom: accepted by the collection without notifying this
/// contract; no depositor is recorded and only the owner can move it.
/// Withdraw — the recorded depositor takes the work back to their own wallet.
/// Send — the owner sends any held work to a chosen wallet (redistribution or
/// manual return), stating the depositor record it acts on.
/// Whichever of withdraw / send happens first wins.
///
/// @dev Design notes
/// * Immutable: no proxy, no admin setters, no fees. `owner` and `fleece` cannot change;
/// the owner may be any account type.
/// * Rescue: the owner can recover other NFTs / ERC-20 tokens sent here by mistake. Rescue
/// can never touch the Fleece collection — Fleece works leave only via withdraw / send.
/// * Custody truth is `fleece.ownerOf`. Invariant: depositor[id] != 0 ⇒ ownerOf(id) == this.
/// * Checks-effects-interactions: every state write and event happens before the single
/// external transfer call, so a recipient that re-enters (e.g. re-deposits in its
/// receiver hook) produces a correct state and a correctly ordered event log.
/// A reentrancy lock is deliberately not used: it would add nothing to safety here and
/// would make a recipient contract that immediately re-deposits revert.
/// * Withdraw uses transferFrom: the work returns to the address that just held it, so
/// the receiver check adds no safety and would strand depositors whose wallet cannot
/// accept safe transfers (e.g. a Safe without fallback handler, some smart wallets).
/// * Send uses safeTransferFrom: a new recipient contract must prove it can hold the work.
/// * Assumes the deployed Fleece collection (0x705A379E5b559Ec3a01A892438f55bBaEeb2AeC1):
/// standard ownership, approvals cleared on transfer, receiver hook called after the
/// ownership update, no admin path that moves tokens. Verified against its source.
contract FleeceNewHome {
/// @notice The only collection this contract holds.
IFleece public immutable fleece;
/// @notice The only account that can `send`. Cannot be changed.
address public immutable owner;
/// @notice Recorded depositor per held token (zero = not recorded).
mapping(uint256 tokenId => address) public depositor;
error InvalidAddress();
error WrongCollection();
error InvalidDeposit();
error OperatorDeposit();
error NotHeld();
error NotDepositor();
error NotOwner();
/// @param current the depositor actually recorded now
error DepositorChanged(address current);
error CannotRescueFleece();
error RescueFailed();
/// @param from holder who deposited (operator deposits are rejected)
event Deposited(uint256 indexed tokenId, address indexed from);
event Withdrawn(uint256 indexed tokenId, address indexed depositor);
/// @param previousDepositor recorded depositor at the time of sending (zero if none)
event Sent(uint256 indexed tokenId, address indexed to, address indexed previousDepositor);
/// @param idOrAmount token id (ERC-721) or amount (ERC-20)
event Rescued(address indexed token, address indexed to, uint256 idOrAmount);
constructor(address collection_, address owner_) {
if (collection_.code.length == 0 || owner_ == address(0) || owner_ == collection_) {
revert InvalidAddress();
}
fleece = IFleece(collection_);
owner = owner_;
}
/// @notice ERC-721 receiver hook. Called by Fleece after a safe transfer to this contract.
function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata)
external
returns (bytes4)
{
if (msg.sender != address(fleece)) revert WrongCollection();
if (from == address(0) || from == address(this)) revert InvalidDeposit();
// Only the holder may deposit with a safe transfer: a safe transfer started by an approved
// operator (marketplace, helper contract) is rejected. A plain transferFrom by an operator
// cannot be blocked (it never calls this hook); it lands unrecorded, owner-only.
if (operator != from) revert OperatorDeposit();
if (fleece.ownerOf(tokenId) != address(this)) revert NotHeld();
depositor[tokenId] = from;
emit Deposited(tokenId, from);
return this.onERC721Received.selector;
}
/// @notice Take back a work you deposited with safeTransferFrom. Always to your own wallet.
function withdraw(uint256 tokenId) external {
if (msg.sender != depositor[tokenId]) revert NotDepositor(); // unrecorded (zero) never matches a caller
if (fleece.ownerOf(tokenId) != address(this)) revert NotHeld();
delete depositor[tokenId];
emit Withdrawn(tokenId, msg.sender);
fleece.transferFrom(address(this), msg.sender, tokenId);
}
/// @notice Owner only: send a held work to `to`. Covers redistribution and manual returns.
/// @param expectedDepositor the depositor record the owner authorised this send against
/// (zero for an unrecorded plain deposit). If the record changed since the transaction
/// was prepared (e.g. a pending Safe transaction after the work was withdrawn and
/// re-deposited by someone else), the send reverts instead of moving the newer deposit.
/// A plain deposit replaced by another plain deposit cannot be told apart on-chain:
/// execute or reject queued sends promptly.
function send(uint256 tokenId, address to, address expectedDepositor) external {
if (msg.sender != owner) revert NotOwner();
if (to == address(0) || to == address(this)) revert InvalidAddress();
if (fleece.ownerOf(tokenId) != address(this)) revert NotHeld();
address previous = depositor[tokenId];
if (previous != expectedDepositor) revert DepositorChanged(previous);
delete depositor[tokenId];
emit Sent(tokenId, to, previous);
fleece.safeTransferFrom(address(this), to, tokenId);
}
/// @notice Owner only: recover a non-Fleece ERC-721 sent here by mistake (plain transfer).
function rescueERC721(address token, uint256 tokenId, address to) external {
_checkRescue(token, to);
emit Rescued(token, to, tokenId);
(bool ok,) = token.call(
abi.encodeWithSignature("transferFrom(address,address,uint256)", address(this), to, tokenId)
);
if (!ok) revert RescueFailed();
}
/// @notice Owner only: recover ERC-20 tokens sent here by mistake. Supports tokens that
/// return no value on transfer (e.g. USDT).
function rescueERC20(address token, uint256 amount, address to) external {
_checkRescue(token, to);
emit Rescued(token, to, amount);
(bool ok, bytes memory ret) =
token.call(abi.encodeWithSignature("transfer(address,uint256)", to, amount));
if (!ok || (ret.length != 0 && !abi.decode(ret, (bool)))) revert RescueFailed();
}
function _checkRescue(address token, address to) private view {
if (msg.sender != owner) revert NotOwner();
if (token == address(fleece)) revert CannotRescueFleece();
if (to == address(0) || to == address(this) || token.code.length == 0) revert InvalidAddress();
}
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"forge-std/=lib/forge-std/src/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.