Skip to main content

Smart Contract Overview

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

Contract Addresses (Sepolia Testnet)

ContractAddress
Market Router0x82bfe1b31b6c1c3d201a0256416a18d93331d99e
Market Factory0xe54648526027e236604f0d91413a6aad3a80c01e
Order Canceller0x53ad1ffcd7afb1b14c5f18be8f256606efb11b1b
These are Sepolia testnet addresses. Mainnet addresses will be different.

Architecture

                    ┌─────────────────────┐
                    │    Market Router    │
                    │                     │
                    │  Entry point for    │
                    │  all trading ops    │
                    └──────────┬──────────┘

              ┌────────────────┼────────────────┐
              ▼                ▼                ▼
    ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
    │   OrderBook A   │ │   OrderBook B   │ │   OrderBook C   │
    │  (EURC/USDC)    │ │  (XSGD/USDC)    │ │  (XSGD/USDT)    │
    └────────┬────────┘ └────────┬────────┘ └────────┬────────┘
             │                   │                   │
             ▼                   ▼                   ▼
    ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
    │   PriceBook A   │ │   PriceBook B   │ │   PriceBook C   │
    │                 │ │                 │ │                 │
    │  minPrice: X    │ │  minPrice: Y    │ │  minPrice: Z    │
    │  tickSpace: A   │ │  tickSpace: B   │ │  tickSpace: 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)

User                     Router                   OrderBook
  │                        │                          │
  │  approve(router, amt)  │                          │
  │───────────────────────▶│                          │
  │                        │                          │
  │  limitBid(params)      │                          │
  │───────────────────────▶│  transferFrom(user)     │
  │                        │─────────────────────────▶│
  │                        │                          │
  │                        │  limitOrder(...)        │
  │                        │─────────────────────────▶│
  │                        │                          │
  │  ◀─────────────────────│  orderId               │
  │                        │◀─────────────────────────│

Claiming Proceeds

User                     Router                   OrderBook
  │                        │                          │
  │  claim(params)         │                          │
  │───────────────────────▶│  claim(orderKeys)       │
  │                        │─────────────────────────▶│
  │                        │                          │
  │                        │  transfer(user, tokens) │
  │                        │◀─────────────────────────│
  │  ◀─────────────────────│                          │

Gas Optimization

Sera is optimized for gas efficiency:
OperationTypical 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
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