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 ordersmarketBid/marketAsk- Execute market ordersclaim- Claim proceeds from filled orders
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 levelgetOrder- Get order detailsbestPriceIndex- Get best bid/ask pricegetClaimable- Check claimable proceeds
PriceBook¶
Handles price calculations using the arithmetic price formula:
Key Functions:
indexToPrice- Convert price index to actual pricepriceToIndex- Convert price to nearest indexmaxPriceIndex- Get maximum supported index
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 callercancelTo(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).
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¶
- Always approve only what you need or use permit signatures
- Check the deadline parameter to prevent stale transactions
- Use postOnly for maker orders to avoid unexpected fills
- Set reasonable limitPriceIndex for market orders to prevent sandwich attacks