Skip to content
Verified contractExactMIT

ResolverListings

Address0x153fa3486f2898e22c05dd739f2a3dd084a8faaa
Balance

0 ETH

 

Transactions

8

 

Compiler

solc 0.8.38

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.38+commit.1835d247
Language
solidity
Optimization
Yes, 200 runs
EVM version
osaka
Via IR
yes
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,361,964
Creation transaction
0x0049201813…163c8703ee

3 files

ResolverListings.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.38;

import {
    OfferItem,
    ConsiderationItem,
    OrderComponents,
    OrderParameters,
    Order,
    ZoneParameters,
    Schema,
    IMarketZone,
    ISeaport
} from "./Seaport.sol";
import {ICollection} from "./ICollection.sol";

/// @title cc0py listings: an immutable Seaport 1.6 zone and on-chain registry.
/// @notice Sellers publish a signed, FULL_RESTRICTED Seaport order for one
/// cc0py token against native ETH. Publication validates the order on Seaport
/// and records it here in the same transaction, so the ABX resolver can serve
/// every active listing from chain state with no off-chain order book. Only a
/// published, current-revision order can fill: the zone callbacks reject
/// anything else.
/// @dev Trust model:
///  - No owner, no upgrade path, no funds ever held.
///  - `guardian` (immutable) has one power: `disable()`, which permanently
///    stops publication and fulfilment through this zone. It cannot re-enable,
///    alter orders, or move tokens. Owners keep `invalidateListings` and may
///    still cancel on Seaport.
///  - A token owner can invalidate every signed attempt for their token by
///    bumping its revision; orders carry the revision in `zoneHash`.
///  - `publishing` guards against re-entrancy during `seaport.validate`, which
///    runs external code (ERC-1271 signers).
contract ResolverListings is IMarketZone {
    /// @notice A registered listing. `revision` ties it to the owner's
    /// invalidation counter; `hash` is the Seaport order hash.
    struct Listing {
        address seller;
        uint256 price;
        uint256 start;
        uint256 end;
        uint256 salt;
        uint256 counter;
        bytes32 hash;
        uint256 revision;
    }

    /// @dev Seaport `OrderType.FULL_RESTRICTED`: only this zone may approve fills.
    uint8 internal constant ORDER_TYPE_FULL_RESTRICTED = 2;
    /// @dev Seaport `ItemType.NATIVE` and `ItemType.ERC721`.
    uint8 internal constant ITEM_NATIVE = 0;
    uint8 internal constant ITEM_ERC721 = 2;
    /// @dev ERC-165 `supportsInterface` selector.
    bytes4 internal constant ERC165_ID = 0x01ffc9a7;

    ICollection public immutable collection;
    ISeaport public immutable seaport;
    /// @notice The only privileged address; see `disable()`.
    address public immutable guardian;
    /// @notice Set once by the guardian; never cleared.
    bool public disabled;
    /// @notice Current listing per cc0py token ID (zero-valued when none).
    mapping(uint256 => Listing) public listings;
    /// @notice Owner invalidation counter per token; the next listing must use `revision + 1`.
    mapping(uint256 => uint256) public revisions;
    bool private publishing;

    event Registered(
        uint256 indexed tokenId,
        bytes32 indexed hash,
        address indexed seller
    );
    event Invalidated(
        uint256 indexed tokenId,
        address indexed owner,
        uint256 revision
    );
    event Disabled(address indexed guardian);

    /// @param nft The cc0py collection.
    /// @param market Seaport 1.6.
    /// @param emergencyGuardian Holder of the one-way emergency stop.
    constructor(address nft, address market, address emergencyGuardian) {
        require(emergencyGuardian != address(0), "Guardian required");
        collection = ICollection(nft);
        seaport = ISeaport(market);
        guardian = emergencyGuardian;
    }

    // ---- guardian --------------------------------------------------------

    /// @notice Permanently stop publication and fulfilment through this zone.
    /// @dev Idempotent. Nothing can undo it; a new deployment is the only way
    /// to resume trading, and existing registered orders become unfillable.
    function disable() external {
        require(msg.sender == guardian, "Only guardian");
        if (!disabled) {
            disabled = true;
            emit Disabled(msg.sender);
        }
    }

    // ---- owner -------------------------------------------------------------

    /// @notice Invalidate every listing and every signed-but-unpublished order
    /// for a token the caller owns, by advancing its revision.
    /// @dev Needs no saved order or signature. Works after `disable()`, so
    /// owners can always clean up.
    function invalidateListings(uint256 id) external {
        require(!publishing, "Reentrant publication");
        require(collection.ownerOf(id) == msg.sender, "Not token owner");
        uint256 revision = ++revisions[id];
        delete listings[id];
        emit Invalidated(id, msg.sender, revision);
    }

    // ---- views -------------------------------------------------------------

    /// @notice Whether a listing can never fill again (expired, cancelled,
    /// filled, counter bumped, or the zone is disabled).
    function closed(Listing memory l) public view returns (bool) {
        if (
            disabled ||
            l.seller == address(0) ||
            block.timestamp >= l.end ||
            seaport.getCounter(l.seller) != l.counter
        ) return true;
        (, bool cancelled, uint256 filled, uint256 size) = seaport
            .getOrderStatus(l.hash);
        return cancelled || (size != 0 && filled >= size);
    }

    /// @notice Whether a listing is fillable right now: in its time window,
    /// still owned by the seller, validated and unfilled on Seaport, and the
    /// token approved to Seaport.
    function active(
        uint256 id,
        Listing memory l,
        address owner
    ) public view returns (bool) {
        if (
            disabled ||
            l.seller == address(0) ||
            l.seller != owner ||
            block.timestamp < l.start ||
            block.timestamp >= l.end
        ) return false;
        if (seaport.getCounter(l.seller) != l.counter) return false;
        (bool validated, bool cancelled, uint256 filled, uint256 size) = seaport
            .getOrderStatus(l.hash);
        if (!validated || cancelled || (size != 0 && filled >= size))
            return false;
        return
            collection.getApproved(id) == address(seaport) ||
            collection.isApprovedForAll(l.seller, address(seaport));
    }

    /// @notice The registered listing for a token with its live status.
    function listing(
        uint256 id
    ) external view returns (Listing memory l, bool isActive, bool isClosed) {
        l = listings[id];
        isActive = active(id, l, collection.ownerOf(id));
        isClosed = closed(l);
    }

    // ---- publication -------------------------------------------------------

    /// @notice Validate a signed order on Seaport and register it here, atomically.
    /// @dev Accepted shape: one ERC-721 from this collection for one native-ETH
    /// consideration paid to the seller, FULL_RESTRICTED, zone = this, no
    /// conduit, `zoneHash` = the token's next revision. Re-publishing the
    /// identical order is a safe no-op (idempotent retry of an uncertain
    /// transaction). A still-active different listing must be cancelled or
    /// invalidated first.
    function publish(
        OrderComponents calldata o,
        bytes calldata signature
    ) external {
        require(!disabled, "Marketplace disabled");
        require(!publishing, "Reentrant publication");
        publishing = true;
        require(
            o.offerer == msg.sender &&
                o.zone == address(this) &&
                o.orderType == ORDER_TYPE_FULL_RESTRICTED &&
                o.conduitKey == bytes32(0),
            "Unsupported seller/order"
        );
        require(
            o.offer.length == 1 && o.consideration.length == 1,
            "One NFT for ETH"
        );
        OfferItem calldata a = o.offer[0];
        ConsiderationItem calldata b = o.consideration[0];
        require(
            a.itemType == ITEM_ERC721 &&
                a.token == address(collection) &&
                a.startAmount == 1 &&
                a.endAmount == 1,
            "Wrong NFT"
        );
        require(
            b.itemType == ITEM_NATIVE &&
                b.token == address(0) &&
                b.identifierOrCriteria == 0 &&
                b.startAmount > 0 &&
                b.startAmount == b.endAmount &&
                b.recipient == msg.sender,
            "Wrong payment"
        );
        uint256 id = a.identifierOrCriteria;
        address owner = collection.ownerOf(id);
        require(owner == msg.sender, "Not token owner");
        bytes32 hash = seaport.getOrderHash(o);
        Listing memory previous = listings[id];
        // Retrying an uncertain transaction with the identical order is safe.
        if (previous.hash == hash) {
            require(active(id, previous, owner), "Order no longer active");
            publishing = false;
            return;
        }
        require(!active(id, previous, owner), "Cancel previous listing first");
        uint256 revision = revisions[id] + 1;
        require(o.zoneHash == bytes32(revision), "Stale listing revision");
        Order[] memory orders = new Order[](1);
        orders[0] = Order(
            OrderParameters(
                o.offerer,
                o.zone,
                o.offer,
                o.consideration,
                o.orderType,
                o.startTime,
                o.endTime,
                o.zoneHash,
                o.salt,
                o.conduitKey,
                1
            ),
            signature
        );
        require(seaport.validate(orders), "Signature validation failed");
        Listing memory next = Listing(
            msg.sender,
            b.startAmount,
            o.startTime,
            o.endTime,
            o.salt,
            o.counter,
            hash,
            revision
        );
        // A failure here rolls back the preceding Seaport validation as well.
        require(active(id, next, owner), "Order not active/approved");
        listings[id] = next;
        revisions[id] = revision;
        publishing = false;
        emit Registered(id, hash, msg.sender);
    }

    // ---- Seaport zone callbacks -------------------------------------------

    /// @dev Shared checks for both callbacks: caller is Seaport, the offered
    /// item is one of this collection's tokens, and the order being filled is
    /// exactly the registered, current-revision listing for that token.
    function _current(
        ZoneParameters calldata z
    ) internal view returns (uint256 id) {
        require(!disabled, "Marketplace disabled");
        require(msg.sender == address(seaport), "Only Seaport");
        require(
            z.offer.length == 1 &&
                z.offer[0].itemType == ITEM_ERC721 &&
                z.offer[0].token == address(collection),
            "Wrong offered NFT"
        );
        id = z.offer[0].identifier;
        Listing memory l = listings[id];
        require(
            l.hash != 0 &&
                l.hash == z.orderHash &&
                l.seller == z.offerer &&
                bytes32(l.revision) == z.zoneHash,
            "Order unpublished or superseded"
        );
    }

    /// @notice Pre-fulfilment check (Seaport 1.6): the seller must still own the token.
    function authorizeOrder(
        ZoneParameters calldata z
    ) external view returns (bytes4) {
        uint256 id = _current(z);
        require(collection.ownerOf(id) == z.offerer, "Owner changed");
        return this.authorizeOrder.selector;
    }

    /// @notice Post-fulfilment check: ownership and fill status have changed by
    /// now, so only the registration is re-checked.
    function validateOrder(
        ZoneParameters calldata z
    ) external view returns (bytes4) {
        _current(z);
        return this.validateOrder.selector;
    }

    /// @notice SIP-5 metadata.
    function getSeaportMetadata()
        external
        pure
        returns (string memory, Schema[] memory)
    {
        return ("cc0py registered listings", new Schema[](0));
    }

    function supportsInterface(bytes4 id) external pure returns (bool) {
        return id == ERC165_ID || id == type(IMarketZone).interfaceId;
    }
}

ICollection.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.38;

/// @title The original cc0py collection, as read by the marketplace contracts.
/// @notice Only the views used here. `collectionData(i)` describes source
/// collection `i` (0 Nouns … 7 mfers) as recorded in the manifesto; a cc0py
/// token ID is `sourceId * 1e12 + originalTokenId`.
interface ICollection {
    struct Source {
        address token;
        string name;
        string proof;
        uint128 count;
        uint64 testMints;
        bool open;
    }
    function totalSupply() external view returns (uint256);
    function maxNFTs() external view returns (uint256);
    function maxPerCollection() external view returns (uint256);
    function maxPerAddress() external view returns (uint256);
    function manifesto() external view returns (string memory);
    function collectionData(uint256) external view returns (Source memory);
    function tokenByIndex(uint256) external view returns (uint256);
    function tokenURI(uint256) external view returns (string memory);
    function ownerOf(uint256) external view returns (address);
    function getApproved(uint256) external view returns (address);
    function isApprovedForAll(address, address) external view returns (bool);
}

/// @notice XCOPY's original contract publishes each token's image CID
/// separately from `tokenURI`; the reader uses it so the browser can load the
/// image from an IPFS gateway instead of the metadata host (no CORS there).
interface ICanonicalArtwork {
    function tokenIPFSHash(
        uint256 tokenId
    ) external view returns (string memory);
}

Seaport.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.38;

/// @title Seaport 1.6 types and the two interfaces this marketplace needs.
/// @notice Mirrors the subset of Seaport's `ConsiderationStructs` used by
/// `ResolverListings`: order components for hashing and validation, and the
/// zone callback parameters. Field order and types must match Seaport exactly;
/// `getOrderHash` is computed by Seaport over these structs.

/// @dev `itemType`: 0 = native ETH, 2 = ERC-721 (Seaport `ItemType`).
struct OfferItem {
    uint8 itemType;
    address token;
    uint256 identifierOrCriteria;
    uint256 startAmount;
    uint256 endAmount;
}
struct ConsiderationItem {
    uint8 itemType;
    address token;
    uint256 identifierOrCriteria;
    uint256 startAmount;
    uint256 endAmount;
    address payable recipient;
}
/// @dev The signed order: `OrderParameters` plus the offerer's Seaport counter.
struct OrderComponents {
    address offerer;
    address zone;
    OfferItem[] offer;
    ConsiderationItem[] consideration;
    uint8 orderType;
    uint256 startTime;
    uint256 endTime;
    bytes32 zoneHash;
    uint256 salt;
    bytes32 conduitKey;
    uint256 counter;
}
struct OrderParameters {
    address offerer;
    address zone;
    OfferItem[] offer;
    ConsiderationItem[] consideration;
    uint8 orderType;
    uint256 startTime;
    uint256 endTime;
    bytes32 zoneHash;
    uint256 salt;
    bytes32 conduitKey;
    uint256 totalOriginalConsiderationItems;
}
struct Order {
    OrderParameters parameters;
    bytes signature;
}
struct SpentItem {
    uint8 itemType;
    address token;
    uint256 identifier;
    uint256 amount;
}
struct ReceivedItem {
    uint8 itemType;
    address token;
    uint256 identifier;
    uint256 amount;
    address payable recipient;
}
/// @dev What Seaport hands a zone before (`authorizeOrder`) and after
/// (`validateOrder`) a restricted order is fulfilled.
struct ZoneParameters {
    bytes32 orderHash;
    address fulfiller;
    address offerer;
    SpentItem[] offer;
    ReceivedItem[] consideration;
    bytes extraData;
    bytes32[] orderHashes;
    uint256 startTime;
    uint256 endTime;
    bytes32 zoneHash;
}
struct Schema {
    uint256 id;
    bytes metadata;
}

/// @notice The Seaport zone interface (SIP-5 metadata included).
interface IMarketZone {
    function authorizeOrder(ZoneParameters calldata) external returns (bytes4);
    function validateOrder(ZoneParameters calldata) external returns (bytes4);
    function getSeaportMetadata()
        external
        view
        returns (string memory, Schema[] memory);
}

/// @notice The Seaport calls the listings zone makes.
interface ISeaport {
    function getOrderHash(
        OrderComponents calldata order
    ) external view returns (bytes32);
    function getCounter(address seller) external view returns (uint256);
    /// @return validated, cancelled, totalFilled, totalSize
    function getOrderStatus(
        bytes32 hash
    ) external view returns (bool, bool, uint256, uint256);
    function validate(Order[] calldata orders) external returns (bool);
}
Compiler settingsShow
{
  "viaIR": true,
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "osaka"
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.