Pool depth does not affect price in Bolt. However, available inventory determines whether a trade can settle. Indexing pool state lets you pre-validate trades before submission and detect failed swaps in advance.
What to Index
The following table summarizes the critical pool state fields you should index:Querying Pool State by Blockchain
- Sui
- Archway
On Sui, query pool state using the Sui TypeScript SDK or JSON-RPC directly.Key points for Sui:
Sui Example
- Use
getObjectto fetch the pool object by its ID - Pool fields are nested under
content.fields - Parse inventory and fee rate from the field values
- Subscribe to events using
subscribeEventfor real-time updates
Setting Up a State Indexer
1
Connect to RPC
Establish a connection to a public or private RPC node for the blockchain where Bolt pools are deployed. Use a WebSocket connection for real-time updates if available.
2
Query Initial State
Fetch the initial pool state by querying each pool object or contract. Store the result in memory or a local database with a timestamp.
3
Subscribe to Events
Subscribe to swap events, rebalance events, and inventory updates emitted by Bolt pools. Events indicate when pool state changes.
4
Handle State Updates
When an event is received, parse it and update your local cache. Ensure your cache remains consistent with on-chain state.
5
Validate Before Quoting
Before quoting a trade, verify that your cached pool state is recent and that available inventory exceeds the requested amountOut. If inventory is insufficient, reject the quote.
Caching Strategy
Advanced Indexing Patterns
Event-Driven vs Polling
Event-Driven vs Polling
Event-driven indexing subscribes to on-chain events and updates state immediately when an event is received. This provides the lowest latency and most accurate state.
- Pros: Real-time updates, low computational overhead
- Cons: Requires WebSocket support, more complex event parsing
- Pros: Simple to implement, no WebSocket dependency
- Cons: Higher latency, higher RPC load, potential stale state
Handling Rebalance Events
Handling Rebalance Events
When a market maker rebalances a Bolt pool, inventory shifts significantly. Your indexer must detect and apply rebalance events immediately:
- Monitor for
PoolRebalanceor equivalent events - Parse the new inventory levels from the event
- Update your local cache synchronously
- If a pending quote was based on pre-rebalance inventory, consider it stale
Multi-Pool Indexing
Multi-Pool Indexing
If you’re integrating multiple Bolt pools, index all of them in parallel:
- Query all pool objects in a single batch RPC call to reduce latency
- Subscribe to events from all pools simultaneously
- Maintain a map of pool ID to cached state for O(1) lookup
- Periodically refresh all pools together to amortize RPC overhead
Detecting State Staleness
Monitor the timestamp or block height of your cached pool state. If your cache exceeds the staleness threshold:- Soft staleness (1-2 minutes old): Safe for most use cases; consider refreshing on the next RPC query window
- Hard staleness (5+ minutes old): Refresh immediately before submitting any trades
- Event-driven only: If you rely entirely on events and haven’t received an update in 10+ minutes, force a full state refresh as a sanity check
Related Documentation
Off-Chain Quoting
Use pool state to compute deterministic quotes off-chain.
Contract Math
Understand the pricing formulas that depend on pool parameters.