Skip to content

Smart Contract Overview

Sera Protocol consists of several interconnected smart contracts deployed on Ethereum.

Contract Addresses (Sepolia Testnet)

Contract Address
Market Router 0x82bfe1b31b6c1c3d201a0256416a18d93331d99e
Market Factory 0xe54648526027e236604f0d91413a6aad3a80c01e
Order Canceller 0x53ad1ffcd7afb1b14c5f18be8f256606efb11b1b

Warning

These are Sepolia testnet addresses. Mainnet addresses will be different.

Architecture

flowchart TD
    Router["Market Router<br/><i>Entry point for all trading</i>"] --> OB1["OrderBook A<br/>EURC/USDC"]
    Router --> OB2["OrderBook B<br/>XSGD/USDC"]
    Router --> OB3["OrderBook C<br/>XSGD/USDT"]
    OB1 --> PB1["PriceBook A"]
    OB2 --> PB2["PriceBook B"]
    OB3 --> PB3["PriceBook C"]

Core Contracts

Market Router

The primary entry point for all trading operations. Users should interact with the Router rather than OrderBooks directly.

Key Functions:

  • limitBid / limitAsk - Place limit orders
  • marketBid / marketAsk - Execute market orders
  • claim - Claim proceeds from filled orders

View Router Reference →

OrderBook

Each trading pair has its own OrderBook contract that:

  • Stores all open orders
  • Matches incoming orders against the book
  • Tracks order fills and claimable amounts

Key Functions:

  • getDepth - Get order depth at a price level
  • getOrder - Get order details
  • bestPriceIndex - Get best bid/ask price
  • getClaimable - Check claimable proceeds

View OrderBook Reference →

PriceBook

Handles price calculations using the arithmetic price formula:

price = minPrice + (tickSpace × priceIndex)

Key Functions:

  • indexToPrice - Convert price index to actual price
  • priceToIndex - Convert price to nearest index
  • maxPriceIndex - Get maximum supported index

View PriceBook Reference →

Order Canceller

A utility contract for batch cancelling orders across multiple markets.

Address (Sepolia): 0x53ad1ffcd7afb1b14c5f18be8f256606efb11b1b

Key Functions:

  • cancel(params[]) - Cancel orders and return tokens to caller
  • cancelTo(params[], to) - Cancel orders and send tokens to specified address

Orders are identified by their NFT token ID, which you can get from the Orders GraphQL query (nftId field).

View Order Canceler ABI →

Token Flow

Placing a Bid (Buy Order)

sequenceDiagram
    participant User
    participant Router
    participant OrderBook

    User->>Router: approve(router, amount)
    User->>Router: limitBid(params)
    Router->>OrderBook: transferFrom(user)
    Router->>OrderBook: limitOrder(...)
    OrderBook-->>Router: orderId
    Router-->>User: orderId

Claiming Proceeds

sequenceDiagram
    participant User
    participant Router
    participant OrderBook

    User->>Router: claim(params)
    Router->>OrderBook: claim(orderKeys)
    OrderBook-->>Router: transfer(user, tokens)
    Router-->>User: tokens

Gas Optimization

Sera is optimized for gas efficiency:

Operation Typical Gas
Limit Order (make only) ~150,000
Limit Order (take + make) ~200,000
Market Order ~120,000
Claim Single Order ~80,000
Cancel Order ~60,000

Tip

Use claim with multiple orders in a single transaction to save gas on batch claiming.

Security Considerations

  1. Always approve only what you need or use permit signatures
  2. Check the deadline parameter to prevent stale transactions
  3. Use postOnly for maker orders to avoid unexpected fills
  4. Set reasonable limitPriceIndex for market orders to prevent sandwich attacks

Next Steps