Skip to content

SeraBatcher.sol

SeraBatcher is the executor wrapper for batched matching and batched SOR execution.

Mainnet: 0x1f4b366f4145A92978df4bEeb6BdE71bC652F034 Source: src/SeraBatcher.sol

Constants

uint256 public constant MAX_BATCH_SIZE = 20;
uint256 public constant MAX_INTENT_SIZE = 10;
uint256 public constant VERSION = 2;

Data Structures

AtomicBatch

struct AtomicBatch {
    MatchData[] matches;  // All-or-nothing order pairs
}

IntentExecution

struct IntentExecution {
    MatchData[] matches;           // Route legs
    bytes intentSignature;         // Taker's SOR signature
    IntentParams intent;           // SOR parameters
    uint8 uniqueTokenCount;        // Transient hash table size hint
    uint256 permitDeadline;        // ERC-2612 permit deadline
    bytes permitSignature;         // ERC-2612 permit signature
}

Functions

batchMatchOrders

Best-effort batch matching. Individual failures don't stop subsequent matches.

function batchMatchOrders(
    MatchData[] calldata _matches,
    uint256 deadline
) external returns (uint256 failedMask)
Parameter Type Description
_matches MatchData[] Array of order pairs (max 20)
deadline uint256 Match expiration timestamp

Returns: failedMask — Bitmask where bit i = 1 if match i failed.

Events:

event MatchFailed(bytes32 indexed orderHash0, bytes32 indexed orderHash1, bytes reason, uint256 indexed batchIndex);
event BatchExecuted(uint256 attempted, uint256 failedMask);

batchMatchOrdersAtomic

All-or-nothing batch matching. If any match fails, the entire transaction reverts.

function batchMatchOrdersAtomic(
    MatchData[] calldata _matches,
    uint256 deadline
) external
Parameter Type Description
_matches MatchData[] Array of order pairs (max 20)
deadline uint256 Match expiration timestamp

Use this when matches are dependent on each other and partial execution would be incorrect.

Events:

event AtomicBatchExecuted(uint256 matchCount);

batchMatchMixed

Execute atomic batches, independent matches, and SOR intents in one transaction.

function batchMatchMixed(
    AtomicBatch[] calldata _atomicBatches,
    MatchData[] calldata _singleMatches,
    IntentExecution[] calldata _intents,
    uint256 deadline
) external returns (uint256 failedMask)
Parameter Type Description
_atomicBatches AtomicBatch[] All-or-nothing sub-batches (max 20)
_singleMatches MatchData[] Independent order pairs (max 20, best-effort)
_intents IntentExecution[] SOR executions (max 10, best-effort)
deadline uint256 Match expiration timestamp

Returns: failedMask — Bitmask covering all three groups sequentially.

Execution order:

  1. Atomic batches (each independently atomic, isolated via try-catch)
  2. Single matches (best-effort, continue on failure)
  3. SOR intents (each independently atomic, continue on failure)

The mixed batch failedMask is sequential across all three sections: atomic batches first, then single matches, then routed intents.

Events:

event AtomicBatchFailed(uint256 batchIndex, bytes reason);
event IntentFailed(uint256 indexed intentIndex, bytes reason);
event MatchFailed(bytes32 indexed orderHash0, bytes32 indexed orderHash1, bytes reason, uint256 indexed batchIndex);
event BatchExecuted(uint256 attempted, uint256 failedMask);

Errors

Error Cause
TooManyOrders More than 20 order pairs
TooManyBatches More than 20 atomic batches
TooManyIntents More than 10 SOR intents
InvalidSORAddress SOR contract not configured