OrderBook ABI¶
Contract name on-chain: OrderBook (implements the SeraOrderBook interface). Each trading pair has its own OrderBook contract (also called a "market"). Use these view functions to query market state.
Note
Market addresses can be found via the Markets GraphQL Query or the Tokens page.
Market Info¶
[
{
"name": "quoteToken",
"type": "function",
"stateMutability": "view",
"inputs": [],
"outputs": [{ "name": "", "type": "address" }]
},
{
"name": "baseToken",
"type": "function",
"stateMutability": "view",
"inputs": [],
"outputs": [{ "name": "", "type": "address" }]
},
{
"name": "quoteUnit",
"type": "function",
"stateMutability": "view",
"inputs": [],
"outputs": [{ "name": "", "type": "uint256" }]
},
{
"name": "makerFee",
"type": "function",
"stateMutability": "view",
"inputs": [],
"outputs": [{ "name": "", "type": "int24" }]
},
{
"name": "takerFee",
"type": "function",
"stateMutability": "view",
"inputs": [],
"outputs": [{ "name": "", "type": "uint24" }]
},
{
"name": "orderToken",
"type": "function",
"stateMutability": "view",
"inputs": [],
"outputs": [{ "name": "", "type": "address" }]
},
{
"name": "priceBook",
"type": "function",
"stateMutability": "view",
"inputs": [],
"outputs": [{ "name": "", "type": "address" }]
}
]
| Function | Returns | Description |
|---|---|---|
quoteToken | address | The quote token contract address |
baseToken | address | The base token contract address |
quoteUnit | uint256 | Amount that one raw unit represents in quote tokens |
makerFee | int24 | Maker fee (100 = 1bp). Negative = rebate |
takerFee | uint24 | Taker fee (100 = 1bp) |
orderToken | address | The Order NFT contract address |
priceBook | address | The PriceBook contract address |
Order Book State¶
[
{
"name": "isEmpty",
"type": "function",
"stateMutability": "view",
"inputs": [{ "name": "isBid", "type": "bool" }],
"outputs": [{ "name": "", "type": "bool" }]
},
{
"name": "bestPriceIndex",
"type": "function",
"stateMutability": "view",
"inputs": [{ "name": "isBid", "type": "bool" }],
"outputs": [{ "name": "", "type": "uint16" }]
},
{
"name": "getDepth",
"type": "function",
"stateMutability": "view",
"inputs": [
{ "name": "isBid", "type": "bool" },
{ "name": "priceIndex", "type": "uint16" }
],
"outputs": [{ "name": "", "type": "uint64" }]
},
{
"name": "getOrder",
"type": "function",
"stateMutability": "view",
"inputs": [{
"name": "orderKey",
"type": "tuple",
"components": [
{ "name": "isBid", "type": "bool" },
{ "name": "priceIndex", "type": "uint16" },
{ "name": "orderIndex", "type": "uint256" }
]
}],
"outputs": [{
"name": "",
"type": "tuple",
"components": [
{ "name": "amount", "type": "uint64" },
{ "name": "claimBounty", "type": "uint32" },
{ "name": "owner", "type": "address" }
]
}]
},
{
"name": "getClaimable",
"type": "function",
"stateMutability": "view",
"inputs": [{
"name": "orderKey",
"type": "tuple",
"components": [
{ "name": "isBid", "type": "bool" },
{ "name": "priceIndex", "type": "uint16" },
{ "name": "orderIndex", "type": "uint256" }
]
}],
"outputs": [
{ "name": "claimableRawAmount", "type": "uint64" },
{ "name": "claimableAmount", "type": "uint256" },
{ "name": "feeAmount", "type": "uint256" },
{ "name": "rebateAmount", "type": "uint256" }
]
}
]
| Function | Description |
|---|---|
isEmpty(isBid) | Returns true if the specified side has no orders |
bestPriceIndex(isBid) | Returns the best price index (highest bid or lowest ask) |
getDepth(isBid, priceIndex) | Returns total open amount at a price level |
getOrder(orderKey) | Returns order details (amount, claimBounty, owner) |
getClaimable(orderKey) | Returns claimable amounts and fees for a filled order |
Price Conversion¶
[
{
"name": "indexToPrice",
"type": "function",
"stateMutability": "view",
"inputs": [{ "name": "priceIndex", "type": "uint16" }],
"outputs": [{ "name": "price", "type": "uint256" }]
},
{
"name": "priceToIndex",
"type": "function",
"stateMutability": "view",
"inputs": [
{ "name": "price", "type": "uint256" },
{ "name": "roundingUp", "type": "bool" }
],
"outputs": [
{ "name": "index", "type": "uint16" },
{ "name": "correctedPrice", "type": "uint256" }
]
},
{
"name": "rawToBase",
"type": "function",
"stateMutability": "view",
"inputs": [
{ "name": "rawAmount", "type": "uint64" },
{ "name": "priceIndex", "type": "uint16" },
{ "name": "roundingUp", "type": "bool" }
],
"outputs": [{ "name": "", "type": "uint256" }]
},
{
"name": "rawToQuote",
"type": "function",
"stateMutability": "view",
"inputs": [{ "name": "rawAmount", "type": "uint64" }],
"outputs": [{ "name": "", "type": "uint256" }]
},
{
"name": "baseToRaw",
"type": "function",
"stateMutability": "view",
"inputs": [
{ "name": "baseAmount", "type": "uint256" },
{ "name": "priceIndex", "type": "uint16" },
{ "name": "roundingUp", "type": "bool" }
],
"outputs": [{ "name": "", "type": "uint64" }]
},
{
"name": "quoteToRaw",
"type": "function",
"stateMutability": "view",
"inputs": [
{ "name": "quoteAmount", "type": "uint256" },
{ "name": "roundingUp", "type": "bool" }
],
"outputs": [{ "name": "", "type": "uint64" }]
}
]
| Function | Description |
|---|---|
indexToPrice(priceIndex) | Converts a price index to the actual price |
priceToIndex(price, roundingUp) | Converts a price to the nearest index |
rawToBase(rawAmount, priceIndex, roundingUp) | Converts raw amount to base token amount |
rawToQuote(rawAmount) | Converts raw amount to quote token amount |
baseToRaw(baseAmount, priceIndex, roundingUp) | Converts base token amount to raw amount |
quoteToRaw(quoteAmount, roundingUp) | Converts quote token amount to raw amount |
Usage Example¶
import { ethers } from 'ethers';
const ORDERBOOK_ABI = [
{
"name": "bestPriceIndex",
"type": "function",
"stateMutability": "view",
"inputs": [{ "name": "isBid", "type": "bool" }],
"outputs": [{ "name": "", "type": "uint16" }]
},
{
"name": "indexToPrice",
"type": "function",
"stateMutability": "view",
"inputs": [{ "name": "priceIndex", "type": "uint16" }],
"outputs": [{ "name": "price", "type": "uint256" }]
},
{
"name": "getDepth",
"type": "function",
"stateMutability": "view",
"inputs": [
{ "name": "isBid", "type": "bool" },
{ "name": "priceIndex", "type": "uint16" }
],
"outputs": [{ "name": "", "type": "uint64" }]
}
];
const MARKET_ADDRESS = '0x2e4a11c7711c6a69ac973cbc40a9b16d14f9aa7e'; // EURC/XSGD
const provider = new ethers.JsonRpcProvider('https://0xrpc.io/sep');
const market = new ethers.Contract(MARKET_ADDRESS, ORDERBOOK_ABI, provider);
// Get best bid price
const bestBidIndex = await market.bestPriceIndex(true);
const bestBidPrice = await market.indexToPrice(bestBidIndex);
console.log(`Best bid: ${ethers.formatUnits(bestBidPrice, 18)}`);
// Get depth at best bid
const depth = await market.getDepth(true, bestBidIndex);
console.log(`Depth at best bid: ${depth}`);
Tip
For most use cases, the GraphQL API provides an easier way to query order book depth.
Full ABI Artifact¶
Use the complete ABI when you need every event/function:
- Interface:
sera-protocol/src/interfaces/SeraOrderBook.sol - JSON artifact:
core-subgraph/abis/SeraOrderBook.json(generated from the interface)
The minimal ABI above is a convenience set for common read calls.