Verified contractExactMIT
FloorGuardTransferValidator
Address0xffa56ed239cda1d2c81107a1f19e5b4ee2dec23d
- Balance
0 ETH
- Transactions
4
- Compiler
solc 0.8.28
- Same code
Only this contract
Details
- Compiler
- solc 0.8.28+commit.7893614a
- 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,492,713
- Creation transaction
- 0x91a1ae3f18…1cc5b4fb86
src/FloorGuardTransferValidator.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
/// @title FloorGuardTransferValidator
/// @notice Distinguishes an owner-initiated gift from a protected sale.
/// @dev Sale authorization lives in transient storage and disappears at the end
/// of the transaction. A trusted adapter may authorize only itself as the
/// operator. The Seaport conduit can be authorized only by the pinned zone.
/// This contract cannot move tokens by itself.
contract FloorGuardTransferValidator {
bytes32 private constant AUTH_NAMESPACE = keccak256("flr.auth.v1");
bytes32 private constant SEAPORT_MARKER = keccak256("FLOORGARD_SEAPORT_OPERATOR");
address public immutable timelock;
address public immutable seaport;
address public immutable seaportConduit;
address public immutable deployer;
address public seaportZone;
bool public locked;
bool public initialMarketTrusted;
bool public seaportPathDisabled;
mapping(address adapter => bool trusted) public trustedAdapters;
error InvalidAddress();
error NotDeployer();
error NotReady();
error Sealed();
error NotTimelock();
error NotTrustedAdapter();
error NotZone();
error AuthorizationInProgress();
error TransferNotPermitted(address collection, uint256 tokenId, address operator);
error AdapterConflict();
error SeaportPathDisabled();
event TrustedAdapterUpdated(address indexed adapter, bool trusted);
event SeaportZoneSet(address indexed zone);
event SeaportPathClosed();
event ValidatorSealed();
modifier onlyTimelock() {
if (msg.sender != timelock) revert NotTimelock();
_;
}
constructor(address timelock_, address seaport_, address seaportConduit_) {
if (timelock_ == address(0) || seaport_ == address(0) || seaportConduit_ == address(0)) {
revert InvalidAddress();
}
if (seaport_ == seaportConduit_) revert InvalidAddress();
timelock = timelock_;
seaport = seaport_;
seaportConduit = seaportConduit_;
deployer = msg.sender;
}
function setSeaportZone(address zone) external {
if (msg.sender != deployer || locked) revert NotDeployer();
if (zone == address(0) || seaportZone != address(0)) revert InvalidAddress();
if (zone == seaport || zone == seaportConduit || trustedAdapters[zone]) revert AdapterConflict();
if (zone.code.length == 0) revert InvalidAddress();
seaportZone = zone;
emit SeaportZoneSet(zone);
}
function trustInitialAdapter(address adapter) external {
if (msg.sender != deployer || locked) revert NotDeployer();
if (initialMarketTrusted) revert Sealed();
initialMarketTrusted = true;
_trust(adapter);
}
function seal() external {
if (msg.sender != deployer) revert NotDeployer();
if (locked) revert Sealed();
if (seaportZone == address(0) || !initialMarketTrusted) revert NotReady();
locked = true;
emit ValidatorSealed();
}
/// @notice Later marketplace adapters may be trusted after the timelock delay.
/// They can authorize only themselves. They cannot authorize the Seaport conduit.
function addTrustedAdapter(address adapter) external onlyTimelock {
_trust(adapter);
}
function removeTrustedAdapter(address adapter) external onlyTimelock {
trustedAdapters[adapter] = false;
emit TrustedAdapterUpdated(adapter, false);
}
/// @notice Replaces the active Seaport zone after the timelock delay unless the Seaport path is disabled.
function updateSeaportZone(address newZone) external onlyTimelock {
if (seaportPathDisabled) revert SeaportPathDisabled();
if (newZone == address(0)) revert InvalidAddress();
if (newZone == seaport || newZone == seaportConduit || trustedAdapters[newZone]) revert AdapterConflict();
if (newZone.code.length == 0) revert InvalidAddress();
seaportZone = newZone;
emit SeaportZoneSet(newZone);
}
/// @notice Irreversible. Use it if the Seaport path must not be turned back on.
function disableSeaportPath() external onlyTimelock {
seaportPathDisabled = true;
emit SeaportPathClosed();
}
function authorizeSale(address collection, uint256 tokenId, address from, address to) external {
if (!trustedAdapters[msg.sender]) revert NotTrustedAdapter();
_set(collection, tokenId, keccak256(abi.encode(from, to, msg.sender)));
}
/// @notice Clears an unconsumed direct-market transient sale slot (e.g. for external collections
/// that do not invoke `validateTransfer`).
function clearSale(address collection, uint256 tokenId, address from, address to) external {
if (!trustedAdapters[msg.sender]) revert NotTrustedAdapter();
bytes32 key = _key(collection, tokenId);
if (_tload(key) == keccak256(abi.encode(from, to, msg.sender))) {
_tstore(key, bytes32(0));
}
}
/// @notice Authorizes a single Seaport transfer of `(collection, tokenId)` from `from` to any non-zero recipient.
function authorizeSeaportSale(address collection, uint256 tokenId, address from) external {
if (msg.sender != seaportZone) revert NotZone();
if (seaportPathDisabled) revert SeaportPathDisabled();
_set(collection, tokenId, keccak256(abi.encode(SEAPORT_MARKER, from)));
}
/// @notice Clears an unconsumed Seaport transient sale slot during `validateOrder`.
function clearSeaportSale(address collection, uint256 tokenId, address from) external {
if (msg.sender != seaportZone) revert NotZone();
bytes32 key = _key(collection, tokenId);
if (_tload(key) == keccak256(abi.encode(SEAPORT_MARKER, from))) {
_tstore(key, bytes32(0));
}
}
/// @notice Called by the NFT. Owner-initiated transfers are gifts. Every other
/// operator must match a sale authorization created earlier in this transaction.
function validateTransfer(address collection, address from, address to, uint256 tokenId, address operator)
external
{
if (msg.sender != collection) revert TransferNotPermitted(collection, tokenId, operator);
if (to == address(0)) revert TransferNotPermitted(collection, tokenId, operator);
if (operator == from) return;
bytes32 key = _key(collection, tokenId);
bytes32 stored = _tload(key);
bytes32 direct = keccak256(abi.encode(from, to, operator));
bytes32 seaportOk = keccak256(abi.encode(SEAPORT_MARKER, from));
bool seaportOperator = operator == seaport || operator == seaportConduit;
if (stored == bytes32(0) || (stored != direct && !(stored == seaportOk && seaportOperator))) {
revert TransferNotPermitted(collection, tokenId, operator);
}
_tstore(key, bytes32(0));
}
function _trust(address adapter) private {
if (adapter == address(0)) revert InvalidAddress();
if (adapter == seaport || adapter == seaportConduit || adapter == seaportZone) revert AdapterConflict();
if (adapter.code.length == 0) revert InvalidAddress();
trustedAdapters[adapter] = true;
emit TrustedAdapterUpdated(adapter, true);
}
function _set(address collection, uint256 tokenId, bytes32 value) private {
bytes32 key = _key(collection, tokenId);
if (_tload(key) != bytes32(0)) revert AuthorizationInProgress();
_tstore(key, value);
}
function _key(address collection, uint256 tokenId) private pure returns (bytes32) {
return keccak256(abi.encode(AUTH_NAMESPACE, collection, tokenId));
}
function _tstore(bytes32 key, bytes32 value) private {
assembly {
tstore(key, value)
}
}
function _tload(bytes32 key) private view returns (bytes32 value) {
assembly {
value := tload(key)
}
}
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"forge-std/=lib/forge-std/src/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.