Seaport Marketplace Protocol

repository·main·Indexed 25 days ago

https://github.com/projectopensea/seaport

A marketplace protocol for safely and efficiently buying and selling NFTs, utilizing an 'offer' and 'consideration' model to enable complex, multi-item trades. Version 1.6.0 includes core protocol logic, type definitions, and Solidity implementations across modular repositories (seaport-core, seaport-types, seaport-sol) with deployments across various EVM-compatible chains.

Tokens
18.8K
Snippets
25
Records
75
Agent score
80%

What's inside Seaport

  1. What is Seaport?

    main

    Seaport is a marketplace protocol designed for the safe and efficient buying and selling of NFTs.

    At its core, a Seaport listing is composed of two main parts:

    1. Offer: An arbitrary number of items that the offerer is willing to give.
    2. Consideration: An arbitrary number of items that must be received in exchange, along with their respective receivers.
  2. Overview of the Seaport protocol

    main

    Seaport is a marketplace protocol designed for the safe and efficient buying and selling of NFTs. The protocol operates on a model where each listing consists of two main components:

    1. Offer: An arbitrary number of items that the offerer is willing to provide.
    2. Consideration: An arbitrary number of items that must be received in exchange, including their respective receivers.

    For deep technical details, developers should refer to the official interface documentation and the ConsiderationInterface.sol.

  3. Manage dynamic consideration items via Zones

    main

    Seaport does not support dynamic adjustment of recipients or amounts (e.g., for royalties) after an order is created.

    However, a zone can enforce the inclusion of new, dynamically computed consideration items by:

    1. Deriving the items within the zone.
    2. Supplying them manually or ensuring they are present via validateOrder.

    Constraint: No more than the original offer item amounts can be spent.

  4. Seaport modular repository structure

    main

    The Seaport project is modularized into smaller repositories to facilitate easier integration and use. Depending on your needs, you may want to interact with these specific components:

    • seaport-core: Core protocol logic.
    • seaport-types: Type definitions and interfaces.
    • seaport-sol: Solidity-specific implementations and components.
  5. Use partial fills in Seaport orders

    main

    If an order is constructed with an appropriate order type to enable partial fills, it can be fulfilled for a fraction of the total amount. This allows subsequent fills to bypass signature verification.

    Key Rules for Partial Fills:

    • Divisibility: All items (offer and consideration) must be cleanly divisible by the supplied fraction (no remainder).
    • Overflow Protection: If a requested fraction exceeds the remaining amount, the fill is automatically reduced to the amount remaining. To enforce "all or none," use a basic order method or a match order with explicit amounts.
    • Ascending/Descending Amounts: For items with different startAmount and endAmount, the fraction is applied to both amounts before determining the price. This ensures consistency regardless of when the order is fulfilled.
    • Criteria-based Items: Partial fills can be combined with criteria-based items to allow partial fulfillment of items like ERC721s.
  6. The sequence of events for fulfilling an order

    main

    When using fulfillOrder or fulfillAdvancedOrder, Seaport executes a specific sequence of operations to ensure the order is valid, signed, and correctly filled. The process follows these stages:

    1. Hashing: Derives hashes for offer and consideration items, retrieves the current counter for the offerer, and derives the final order hash.
    2. Initial Validation: Checks that the current time is within the order's valid range and verifies that the caller is authorized for the specific order type (potentially querying a zone for restricted order types).
    3. Status Update: Verifies the order is not cancelled or fully filled, validates the signature, determines the fill fraction based on user preference and available amount, and updates the order status.
    4. Amount Determination: Calculates the amount for each item. If start and end amounts are equal, it applies the fill fraction. If they differ, it applies the fraction to both and performs a linear fit based on the current time.
    5. Criteria Resolution: Applies criteria resolvers to ensure item identifiers are valid via inclusion proofs (if a non-zero criteria root exists) and updates item types and identifiers.
    6. Event Emission: Emits the OrderFulfilled event with the updated item details.
    7. Transfers: Executes transfers of offer items (from offerer to caller) and consideration items (from caller to recipients) using either conduit or Seaport directly, depending on the order type and preference.
  7. Handle native Ether and transfer hook risks during fulfillment

    main

    Fulfilling orders involving native Ether or tokens with transfer hooks (e.g., ERC1155, ERC777) can lead to increased gas costs or blocked fulfillments if the recipient's account behaves maliciously (e.g., via a payable fallback or spending excess gas).

    Remediations:

    • WETH Fallback: Wrap Ether as WETH if the initial transfer fails.
    • Gas Limits: Allow submitters to specify the amount of gas allocated for a fulfillment.
    • Explicit Fulfillments: Use orders that support explicit fulfillments to leave problematic or unwanted offer items unspent, provided all consideration items are received in full.
  8. Mitigate fee-on-transfer and post-fulfillment state risks with Restricted Orders and Zones

    main

    Because Seaport allocates offer and consideration items in memory, items with fee-on-transfer mechanics or post-fulfillment state requirements (like transfer hooks) may result in received amounts differing from the order specification.

    To ensure correctness for these items:

    1. Use "restricted" order types.
    2. Route order fulfillment through a zone contract.
    3. Perform necessary checks (e.g., verifying the actual amount received) within the zone contract after fulfillment is completed.
  9. The sequence of events for matching orders

    main

    When matching a group of orders via matchOrders or matchAdvancedOrders, the first six steps (Hashing, Validation, Status Update, Amount Determination, Criteria Resolution, and Event Emission) are performed for each supplied order. The process then diverges into specific matching logic:

    1. Apply Fulfillments:
      • Ensures each fulfillment refers to offer and consideration items with matching types, tokens, approval sources, and recipients.
      • Reduces amounts on items to zero and tracks totals.
      • Balances the amounts by adding any remaining amount back to the first item on the appropriate side of the order.
      • Returns a single execution for each fulfillment.
    2. Scan Consideration Items: Ensures no consideration item has a non-zero amount remaining.
    3. Perform Transfers: Executes transfers using conduit or Seaport directly. Note that executions where to == from are ignored.
  10. Deviations in contract orders from standard Seaport orders

    main

    Contract orders follow different rules than standard off-chain orders in several key areas:

    Criteria-based Items

    When a collection-wide criteria-based item (identifierOrCriteria = 0) is used in a contract order, the Seaport app has full latitude to choose the identifier mid-flight. Unlike standard orders, Seaport does not expect a CriteriaResolver for contract orders; providing one will cause a revert.

    Native Token (ETH) Support

    Contract orders allow for the use of native tokens (e.g., Ether) as offer items.

    • Direct Transfer: Order generator contracts can send native tokens directly to Seaport during the generateOrder call.
    • Reentrancy: Seaport makes exceptions to its normal reentrancy policies for order generators, allowing them to call the receive hook and provide native tokens.
    • Availability: Any native tokens sent to Seaport are immediately spendable by the current or next caller.

    Security Warning

    Because contract orders can modify state during generateOrder, they can potentially lower the value of an offered NFT (e.g., by transferring out attached tokens). To mitigate this, consider using a mirrored order that allows for post-transfer validation.

  11. Core Invariants of the Seaport Protocol

    main

    When auditing or interacting with Seaport, the following core invariants must be upheld. Any violation that puts user funds at risk is considered a High/Critical severity issue:

    1. Controlled Transfers: Only items explicitly offered in a valid order may be transferred from an offerer's account, provided they have set token approvals on Seaport directly or on a conduit that only has Seaport set as a channel.
    2. Offer Limits: No order fulfillment may spend more than the offer items explicitly set for that order (though not all offered items must be spent).
    3. Consideration Fulfillment: All consideration items (or fractions thereof for partial fills) must be received in full by the named recipients before the corresponding offer items are spent.
      • Note: Additional consideration items (e.g., "tips") may be added during fulfillment.
      • Note: When using fulfillment methods other than matchOrders or matchAdvancedOrders, an implied "mirror" order is created for the fulfiller. In these cases, offer items on fulfilled orders should be treated as consideration items for the fulfiller (except in fulfillBasicOrder where specific ERC721/ERC1155 to ERC20 routes use a portion of the offered item to pay consideration).
  12. How `fulfillBasicOrder` differs from standard fulfillment

    main

    The fulfillBasicOrder method follows a similar sequence to fulfillOrder but includes several optimizations and constraints:

    • Reconstruction: It reconstructs the order from a subset of order elements.
    • Simplified Logic: It skips linear fit amount adjustment and criteria resolution.
    • Strict Amounts: It requires that the full order amount be fillable.
    • Minimal Transfers: It performs a more minimal set of transfers by default when the offer item shares the same type and token as additional consideration items.